static void num_completed_pkts(struct vhci_conn *conn) { uint8_t buf[HCI_MAX_FRAME_SIZE], *ptr = buf; evt_num_comp_pkts *np; hci_event_hdr *he; /* Packet type */ *ptr++ = HCI_EVENT_PKT; /* Event header */ he = (void *) ptr; ptr += HCI_EVENT_HDR_SIZE; he->evt = EVT_NUM_COMP_PKTS; he->plen = EVT_NUM_COMP_PKTS_SIZE; np = (void *) ptr; ptr += EVT_NUM_COMP_PKTS_SIZE; np->num_hndl = 1; bt_put_le16(conn->handle, ptr); ptr += 2; bt_put_le16(vdev.acl_cnt, ptr); ptr += 2; write_snoop(vdev.dd, HCI_EVENT_PKT, 1, buf, ptr - buf); if (write(vdev.dev_fd, buf, ptr - buf) < 0) syslog(LOG_ERR, "Can't send event: %s (%d)", strerror(errno), errno); }
static void send_mode(char *svr) { struct sco_options so; socklen_t len; uint32_t seq; int i, sk; if ((sk = do_connect(svr)) < 0) { syslog(LOG_ERR, "Can't connect to the server: %s (%d)", strerror(errno), errno); exit(1); } len = sizeof(so); if (getsockopt(sk, SOL_SCO, SCO_OPTIONS, &so, &len) < 0) { syslog(LOG_ERR, "Can't get SCO options: %s (%d)", strerror(errno), errno); exit(1); } syslog(LOG_INFO,"Sending ..."); for (i = 6; i < so.mtu; i++) buf[i] = 0x7f; seq = 0; while (1) { bt_put_le32(seq, buf); bt_put_le16(data_size, buf + 4); seq++; if (send(sk, buf, so.mtu, 0) <= 0) { syslog(LOG_ERR, "Send failed: %s (%d)", strerror(errno), errno); exit(1); } usleep(1); } }
int bt_uuid_to_le(const bt_uuid_t *src, void *dst) { bt_uuid_t uuid; switch (src->type) { case BT_UUID16: bt_put_le16(src->value.u16, dst); return 0; case BT_UUID32: bt_uuid32_to_uuid128(src, &uuid); src = &uuid; /* Fallthrough */ case BT_UUID128: /* Convert from 128-bit BE to LE */ bswap_128(&src->value.u128, dst); return 0; case BT_UUID_UNSPEC: default: return -EINVAL; } }
static void bt_hid_get_report(const void *buf, uint16_t len) { const struct hal_cmd_hidhost_get_report *cmd = buf; struct hid_device *dev; GSList *l; bdaddr_t dst; int fd; uint8_t *req; uint8_t req_size; uint8_t status; DBG(""); switch (cmd->type) { case HAL_HIDHOST_INPUT_REPORT: case HAL_HIDHOST_OUTPUT_REPORT: case HAL_HIDHOST_FEATURE_REPORT: break; default: status = HAL_STATUS_INVALID; goto failed; } android2bdaddr(&cmd->bdaddr, &dst); l = g_slist_find_custom(devices, &dst, device_cmp); if (!l) { status = HAL_STATUS_FAILED; goto failed; } dev = l->data; req_size = (cmd->buf_size > 0) ? 4 : 2; req = g_try_malloc0(req_size); if (!req) { status = HAL_STATUS_NOMEM; goto failed; } req[0] = HID_MSG_GET_REPORT | cmd->type; req[1] = cmd->id; if (cmd->buf_size > 0) { req[0] = req[0] | HID_GET_REPORT_SIZE_FIELD; bt_put_le16(cmd->buf_size, &req[2]); } fd = g_io_channel_unix_get_fd(dev->ctrl_io); if (write(fd, req, req_size) < 0) { error("error writing hid_get_report: %s (%d)", strerror(errno), errno); g_free(req); status = HAL_STATUS_FAILED; goto failed; } dev->last_hid_msg = HID_MSG_GET_REPORT; g_free(req); status = HAL_STATUS_SUCCESS; failed: ipc_send_rsp(HAL_SERVICE_ID_HIDHOST, HAL_OP_HIDHOST_GET_REPORT, status); }