Bluetooth: HCI: Add helpers to create events
This adds bt_hci_evt_create and bt_hci_cmd_complete functions. Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This commit is contained in:
parent
634faf2b78
commit
f710b9be50
2 changed files with 79 additions and 18 deletions
|
@ -194,6 +194,47 @@ int bt_hci_driver_register(const struct bt_hci_driver *drv);
|
||||||
*/
|
*/
|
||||||
int bt_hci_transport_setup(struct device *dev);
|
int bt_hci_transport_setup(struct device *dev);
|
||||||
|
|
||||||
|
/** Allocate an HCI event buffer.
|
||||||
|
*
|
||||||
|
* This function allocates a new buffer for an HCI event. It is given the
|
||||||
|
* avent code and the total length of the parameters. Upon successful return
|
||||||
|
* the buffer is ready to have the parameters encoded into it.
|
||||||
|
*
|
||||||
|
* @param evt Event OpCode.
|
||||||
|
* @param len Length of event parameters.
|
||||||
|
*
|
||||||
|
* @return Newly allocated buffer.
|
||||||
|
*/
|
||||||
|
struct net_buf *bt_hci_evt_create(u8_t evt, u8_t len);
|
||||||
|
|
||||||
|
/** Allocate an HCI Command Complete event buffer.
|
||||||
|
*
|
||||||
|
* This function allocates a new buffer for HCI Command Complete event.
|
||||||
|
* It is given the OpCode (encoded e.g. using the BT_OP macro) and the total
|
||||||
|
* length of the parameters. Upon successful return the buffer is ready to have
|
||||||
|
* the parameters encoded into it.
|
||||||
|
*
|
||||||
|
* @param op Command OpCode.
|
||||||
|
* @param plen Length of command parameters.
|
||||||
|
*
|
||||||
|
* @return Newly allocated buffer.
|
||||||
|
*/
|
||||||
|
struct net_buf *bt_hci_cmd_complete_create(u16_t op, u8_t plen);
|
||||||
|
|
||||||
|
/** Allocate an HCI Command Status event buffer.
|
||||||
|
*
|
||||||
|
* This function allocates a new buffer for HCI Command Status event.
|
||||||
|
* It is given the OpCode (encoded e.g. using the BT_OP macro) and the status
|
||||||
|
* code. Upon successful return the buffer is ready to have the parameters
|
||||||
|
* encoded into it.
|
||||||
|
*
|
||||||
|
* @param op Command OpCode.
|
||||||
|
* @param status Status code.
|
||||||
|
*
|
||||||
|
* @return Newly allocated buffer.
|
||||||
|
*/
|
||||||
|
struct net_buf *bt_hci_cmd_status_create(u16_t op, u8_t status);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -121,35 +121,55 @@ void hci_evt_create(struct net_buf *buf, u8_t evt, u8_t len)
|
||||||
hdr->len = len;
|
hdr->len = len;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *hci_cmd_complete(struct net_buf **buf, u8_t plen)
|
struct net_buf *bt_hci_evt_create(u8_t evt, u8_t len)
|
||||||
{
|
{
|
||||||
|
struct net_buf *buf;
|
||||||
|
|
||||||
|
buf = bt_buf_get_evt(evt, false, K_FOREVER);
|
||||||
|
hci_evt_create(buf, evt, len);
|
||||||
|
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct net_buf *bt_hci_cmd_complete_create(u16_t op, u8_t plen)
|
||||||
|
{
|
||||||
|
struct net_buf *buf;
|
||||||
struct bt_hci_evt_cmd_complete *cc;
|
struct bt_hci_evt_cmd_complete *cc;
|
||||||
|
|
||||||
*buf = bt_buf_get_evt(BT_HCI_EVT_CMD_COMPLETE, false, K_FOREVER);
|
buf = bt_hci_evt_create(BT_HCI_EVT_CMD_COMPLETE, sizeof(*cc) + plen);
|
||||||
|
|
||||||
hci_evt_create(*buf, BT_HCI_EVT_CMD_COMPLETE, sizeof(*cc) + plen);
|
cc = net_buf_add(buf, sizeof(*cc));
|
||||||
|
|
||||||
cc = net_buf_add(*buf, sizeof(*cc));
|
|
||||||
cc->ncmd = 1U;
|
cc->ncmd = 1U;
|
||||||
cc->opcode = sys_cpu_to_le16(_opcode);
|
cc->opcode = sys_cpu_to_le16(op);
|
||||||
|
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct net_buf *bt_hci_cmd_status_create(u16_t op, u8_t status)
|
||||||
|
{
|
||||||
|
struct net_buf *buf;
|
||||||
|
struct bt_hci_evt_cmd_status *cs;
|
||||||
|
|
||||||
|
buf = bt_hci_evt_create(BT_HCI_EVT_CMD_STATUS, sizeof(*cs));
|
||||||
|
|
||||||
|
cs = net_buf_add(buf, sizeof(*cs));
|
||||||
|
cs->status = status;
|
||||||
|
cs->ncmd = 1U;
|
||||||
|
cs->opcode = sys_cpu_to_le16(op);
|
||||||
|
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *hci_cmd_complete(struct net_buf **buf, u8_t plen)
|
||||||
|
{
|
||||||
|
*buf = bt_hci_cmd_complete_create(_opcode, plen);
|
||||||
|
|
||||||
return net_buf_add(*buf, plen);
|
return net_buf_add(*buf, plen);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct net_buf *cmd_status(u8_t status)
|
static struct net_buf *cmd_status(u8_t status)
|
||||||
{
|
{
|
||||||
struct bt_hci_evt_cmd_status *cs;
|
return bt_hci_cmd_status_create(_opcode, status);
|
||||||
struct net_buf *buf;
|
|
||||||
|
|
||||||
buf = bt_buf_get_evt(BT_HCI_EVT_CMD_STATUS, false, K_FOREVER);
|
|
||||||
hci_evt_create(buf, BT_HCI_EVT_CMD_STATUS, sizeof(*cs));
|
|
||||||
|
|
||||||
cs = net_buf_add(buf, sizeof(*cs));
|
|
||||||
cs->status = status;
|
|
||||||
cs->ncmd = 1U;
|
|
||||||
cs->opcode = sys_cpu_to_le16(_opcode);
|
|
||||||
|
|
||||||
return buf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *meta_evt(struct net_buf *buf, u8_t subevt, u8_t melen)
|
static void *meta_evt(struct net_buf *buf, u8_t subevt, u8_t melen)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue