static bt_status_t opcode_connect(const struct pdu* cmd) { long off; bt_bdaddr_t bd_addr; uint8_t type; uint8_t uuid[16]; uint16_t channel; uint8_t flags; struct pdu_wbuf* wbuf; struct ancillary_data* data; bt_status_t status; off = read_bt_bdaddr_t(cmd, 0, &bd_addr); if (off < 0) return BT_STATUS_PARM_INVALID; if (read_pdu_at(cmd, off, "CmsC", &type, uuid, sizeof(uuid), &channel, &flags) < 0) return BT_STATUS_PARM_INVALID; wbuf = create_pdu_wbuf(0, ALIGNMENT_PADDING + sizeof(*data), build_ancillary_data); if (!wbuf) return BT_STATUS_NOMEM; data = ceil_align(pdu_wbuf_tail(wbuf), ALIGNMENT_PADDING); status = bt_sock_connect(&bd_addr, type, uuid, channel, &data->sock_fd, flags); if (status != BT_STATUS_SUCCESS) goto err_bt_sock_listen; init_pdu(&wbuf->buf.pdu, cmd->service, cmd->opcode); send_pdu(wbuf); return BT_STATUS_SUCCESS; err_bt_sock_listen: cleanup_pdu_wbuf(wbuf); return status; }
static bt_status_t opcode_connect(const struct pdu* cmd) { long off; bt_bdaddr_t bd_addr; uint8_t type; uint8_t uuid[16]; uint16_t channel; uint8_t flags; int sock_fd; struct pdu_wbuf* wbuf; bt_status_t status; off = read_bt_bdaddr_t(cmd, 0, &bd_addr); if (off < 0) return BT_STATUS_PARM_INVALID; if (read_pdu_at(cmd, off, "CmSC", &type, uuid, (size_t)uuid, &channel, &flags) < 0) return BT_STATUS_PARM_INVALID; wbuf = create_pdu_wbuf(0, sizeof(*wbuf->msg.msg_iov)); if (!wbuf) return BT_STATUS_NOMEM; status = bt_sock_connect(&bd_addr, type, uuid, channel, &sock_fd, flags); if (status != BT_STATUS_SUCCESS) goto err_bt_sock_listen; init_pdu(&wbuf->buf.pdu, cmd->service, cmd->opcode); send_pdu(build_pdu_wbuf_msg_with_fd(wbuf, sock_fd)); return BT_STATUS_SUCCESS; err_bt_sock_listen: cleanup_pdu_wbuf(wbuf); return status; }