Esempio n. 1
0
static bt_status_t
opcode_listen(const struct pdu* cmd)
{
  uint8_t type;
  int8_t service_name[256];
  uint8_t uuid[16];
  uint16_t channel;
  uint8_t flags;
  int sock_fd;
  struct pdu_wbuf* wbuf;
  bt_status_t status;

  if (read_pdu_at(cmd, 0, "CmmSC", &type,
                                   service_name, (size_t)sizeof(service_name),
                                   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_listen(type, (char*)service_name, 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;
}
static bt_status_t
opcode_listen(const struct pdu* cmd)
{
  uint8_t type;
  int8_t service_name[256];
  uint8_t uuid[16];
  uint16_t channel;
  uint8_t flags;
  struct pdu_wbuf* wbuf;
  struct ancillary_data* data;
  bt_status_t status;

  if (read_pdu_at(cmd, 0, "CmmSC", &type,
                                   service_name, (size_t)sizeof(service_name),
                                   uuid, (size_t)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_listen(type, (char*)service_name, 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;
}