Beispiel #1
0
static int bt_set_power(int on) 
{
    int sz;
    int fd = -1;
    int ret = -1;
    const char buf = (on ? '1' : '0');

    LOG_TRC();

    if (bt_rfkill_id == -1) {
        if (bt_init_rfkill()) goto out;
    }

    fd = open(bt_rfkill_state_path, O_WRONLY);
    if (fd < 0) {
        LOG_ERR("Open %s to set BT power fails: %s(%d)\n", bt_rfkill_state_path,
             strerror(errno), errno);
        goto out;
    }
    
    sz = write(fd, &buf, 1);
    if (sz < 0) {
        LOG_ERR("Write %s fails: %s(%d)\n", bt_rfkill_state_path, 
             strerror(errno), errno);
        goto out;
    }
    ret = 0;

out:
    if (fd >= 0) close(fd);
    return ret;
}
Beispiel #2
0
static int bt_set_power(int on) 
{
    int sz;
    int fd = -1;
    int ret = -1;
#ifdef  DONOT_USE_RFKILL
    const uint32_t buf = (on ? 1 : 0);   
#else
    const char buf = (on ? '1' : '0');
#endif

    TRC();

#ifdef DONOT_USE_RFKILL
    fd = open(BTWLAN_DEVNAME, O_RDWR);
    if (fd < 0) {
        ERR("Open %s to set BT power fails: %s(%d)", BTWLAN_DEVNAME,
             strerror(errno), errno);
        goto out;
    }
    
    ret = ioctl(fd, BTWLAN_EM_IOCTL_SET_BTPWR, &buf);
    if(ret < 0) {
        ERR("Set BT power %d fails: %s(%d)\n", buf, 
             strerror(errno), errno);
        goto out;
    }   
#else
    if (bt_rfkill_id == -1) {
        if (bt_init_rfkill()) goto out;
    }

    fd = open(bt_rfkill_state_path, O_WRONLY);
    if (fd < 0) {
        ERR("Open %s to set BT power fails: %s(%d)", bt_rfkill_state_path,
             strerror(errno), errno);
        goto out;
    }
    sz = write(fd, &buf, 1);
    if (sz < 0) {
        ERR("Write %s fails: %s(%d)", bt_rfkill_state_path, 
             strerror(errno), errno);
        goto out;
    }
    ret = 0;
#endif

out:
    if (fd >= 0) close(fd);
    return ret;
}