Bluetooth: Create separate bt_recv_prio() API
Since callers of bt_recv() have so far anyway been required to know in which context to call it (based on e.g. bt_hci_evt_is_prio) it's cleaner to have two separate APIs: bt_recv and bt_recv_prio. Change-Id: Icd0d9aed9c51ffd2def31432c4ffcc16a9f13ccd Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
parent
3341d7d2b5
commit
d64f47d956
6 changed files with 55 additions and 39 deletions
|
@ -251,8 +251,8 @@ static inline void read_payload(void)
|
||||||
rx.have_hdr = false;
|
rx.have_hdr = false;
|
||||||
|
|
||||||
if (prio) {
|
if (prio) {
|
||||||
BT_DBG("Calling bt_recv(%p)", buf);
|
BT_DBG("Calling bt_recv_prio(%p)", buf);
|
||||||
bt_recv(buf);
|
bt_recv_prio(buf);
|
||||||
} else {
|
} else {
|
||||||
BT_DBG("Putting buf %p to rx fifo", buf);
|
BT_DBG("Putting buf %p to rx fifo", buf);
|
||||||
net_buf_put(&rx.fifo, buf);
|
net_buf_put(&rx.fifo, buf);
|
||||||
|
|
|
@ -35,7 +35,6 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CONFIG_BLUETOOTH_RECV_IS_RX_THREAD)
|
|
||||||
/** Helper for the HCI driver to know which events are ok to be passed
|
/** Helper for the HCI driver to know which events are ok to be passed
|
||||||
* through the RX thread and which must be given to bt_recv() from another
|
* through the RX thread and which must be given to bt_recv() from another
|
||||||
* context. If this function returns true it's safe to pass the event
|
* context. If this function returns true it's safe to pass the event
|
||||||
|
@ -60,11 +59,13 @@ static inline bool bt_hci_evt_is_prio(uint8_t evt)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Receive data from the controller/HCI driver */
|
/* Receive data from the controller/HCI driver */
|
||||||
int bt_recv(struct net_buf *buf);
|
int bt_recv(struct net_buf *buf);
|
||||||
|
|
||||||
|
/* Receive priority event from the controller/HCI driver */
|
||||||
|
int bt_recv_prio(struct net_buf *buf);
|
||||||
|
|
||||||
enum bt_hci_driver_bus {
|
enum bt_hci_driver_bus {
|
||||||
BT_HCI_DRIVER_BUS_VIRTUAL = 0,
|
BT_HCI_DRIVER_BUS_VIRTUAL = 0,
|
||||||
BT_HCI_DRIVER_BUS_USB = 1,
|
BT_HCI_DRIVER_BUS_USB = 1,
|
||||||
|
|
|
@ -222,7 +222,7 @@ static void recv_thread(void *p1, void *p2, void *p3)
|
||||||
bt_buf_set_type(buf, BT_BUF_EVT);
|
bt_buf_set_type(buf, BT_BUF_EVT);
|
||||||
hci_num_cmplt_encode(buf, handle, num_cmplt);
|
hci_num_cmplt_encode(buf, handle, num_cmplt);
|
||||||
BT_DBG("Num Complete: 0x%04x:%u", handle, num_cmplt);
|
BT_DBG("Num Complete: 0x%04x:%u", handle, num_cmplt);
|
||||||
bt_recv(buf);
|
bt_recv_prio(buf);
|
||||||
|
|
||||||
k_yield();
|
k_yield();
|
||||||
}
|
}
|
||||||
|
@ -294,7 +294,7 @@ static int cmd_handle(struct net_buf *buf)
|
||||||
err = hci_cmd_handle(buf, evt);
|
err = hci_cmd_handle(buf, evt);
|
||||||
if (!err && evt->len) {
|
if (!err && evt->len) {
|
||||||
BT_DBG("Replying with event of %u bytes", evt->len);
|
BT_DBG("Replying with event of %u bytes", evt->len);
|
||||||
bt_recv(evt);
|
bt_recv_prio(evt);
|
||||||
} else {
|
} else {
|
||||||
net_buf_unref(evt);
|
net_buf_unref(evt);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2605,6 +2605,8 @@ static void hci_event(struct net_buf *buf)
|
||||||
|
|
||||||
BT_DBG("event 0x%02x", hdr->evt);
|
BT_DBG("event 0x%02x", hdr->evt);
|
||||||
|
|
||||||
|
BT_ASSERT(!bt_hci_evt_is_prio(hdr->evt));
|
||||||
|
|
||||||
net_buf_pull(buf, sizeof(*hdr));
|
net_buf_pull(buf, sizeof(*hdr));
|
||||||
|
|
||||||
switch (hdr->evt) {
|
switch (hdr->evt) {
|
||||||
|
@ -3412,37 +3414,6 @@ int bt_send(struct net_buf *buf)
|
||||||
return bt_dev.drv->send(buf);
|
return bt_dev.drv->send(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void handle_event(struct net_buf *buf)
|
|
||||||
{
|
|
||||||
struct bt_hci_evt_hdr *hdr = (void *)buf->data;
|
|
||||||
|
|
||||||
switch (hdr->evt) {
|
|
||||||
case BT_HCI_EVT_CMD_COMPLETE:
|
|
||||||
net_buf_pull(buf, sizeof(*hdr));
|
|
||||||
hci_cmd_complete(buf);
|
|
||||||
break;
|
|
||||||
case BT_HCI_EVT_CMD_STATUS:
|
|
||||||
net_buf_pull(buf, sizeof(*hdr));
|
|
||||||
hci_cmd_status(buf);
|
|
||||||
break;
|
|
||||||
#if defined(CONFIG_BLUETOOTH_CONN)
|
|
||||||
case BT_HCI_EVT_NUM_COMPLETED_PACKETS:
|
|
||||||
net_buf_pull(buf, sizeof(*hdr));
|
|
||||||
hci_num_completed_packets(buf);
|
|
||||||
break;
|
|
||||||
#endif /* CONFIG_BLUETOOTH_CONN */
|
|
||||||
default:
|
|
||||||
#if defined(CONFIG_BLUETOOTH_RECV_IS_RX_THREAD)
|
|
||||||
hci_event(net_buf_ref(buf));
|
|
||||||
#else
|
|
||||||
net_buf_put(&bt_dev.rx_queue, net_buf_ref(buf));
|
|
||||||
#endif
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
net_buf_unref(buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
int bt_recv(struct net_buf *buf)
|
int bt_recv(struct net_buf *buf)
|
||||||
{
|
{
|
||||||
bt_monitor_send(bt_monitor_opcode(buf), buf->data, buf->len);
|
bt_monitor_send(bt_monitor_opcode(buf), buf->data, buf->len);
|
||||||
|
@ -3466,7 +3437,11 @@ int bt_recv(struct net_buf *buf)
|
||||||
return 0;
|
return 0;
|
||||||
#endif /* BLUETOOTH_CONN */
|
#endif /* BLUETOOTH_CONN */
|
||||||
case BT_BUF_EVT:
|
case BT_BUF_EVT:
|
||||||
handle_event(buf);
|
#if defined(CONFIG_BLUETOOTH_RECV_IS_RX_THREAD)
|
||||||
|
hci_event(buf);
|
||||||
|
#else
|
||||||
|
net_buf_put(&bt_dev.rx_queue, buf);
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
default:
|
default:
|
||||||
BT_ERR("Invalid buf type %u", bt_buf_get_type(buf));
|
BT_ERR("Invalid buf type %u", bt_buf_get_type(buf));
|
||||||
|
@ -3475,6 +3450,41 @@ int bt_recv(struct net_buf *buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int bt_recv_prio(struct net_buf *buf)
|
||||||
|
{
|
||||||
|
struct bt_hci_evt_hdr *hdr = (void *)buf->data;
|
||||||
|
|
||||||
|
bt_monitor_send(bt_monitor_opcode(buf), buf->data, buf->len);
|
||||||
|
|
||||||
|
BT_ASSERT(bt_buf_get_type(buf) == BT_BUF_EVT);
|
||||||
|
BT_ASSERT(buf->len >= sizeof(*hdr));
|
||||||
|
BT_ASSERT(bt_hci_evt_is_prio(hdr->evt));
|
||||||
|
|
||||||
|
net_buf_pull(buf, sizeof(*hdr));
|
||||||
|
|
||||||
|
switch (hdr->evt) {
|
||||||
|
case BT_HCI_EVT_CMD_COMPLETE:
|
||||||
|
hci_cmd_complete(buf);
|
||||||
|
break;
|
||||||
|
case BT_HCI_EVT_CMD_STATUS:
|
||||||
|
hci_cmd_status(buf);
|
||||||
|
break;
|
||||||
|
#if defined(CONFIG_BLUETOOTH_CONN)
|
||||||
|
case BT_HCI_EVT_NUM_COMPLETED_PACKETS:
|
||||||
|
hci_num_completed_packets(buf);
|
||||||
|
break;
|
||||||
|
#endif /* CONFIG_BLUETOOTH_CONN */
|
||||||
|
default:
|
||||||
|
net_buf_unref(buf);
|
||||||
|
BT_ASSERT(0);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
net_buf_unref(buf);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int bt_hci_driver_register(struct bt_hci_driver *drv)
|
int bt_hci_driver_register(struct bt_hci_driver *drv)
|
||||||
{
|
{
|
||||||
if (bt_dev.drv) {
|
if (bt_dev.drv) {
|
||||||
|
|
|
@ -87,7 +87,7 @@ static void send_cmd_status(uint16_t opcode, uint8_t status)
|
||||||
evt->opcode = sys_cpu_to_le16(opcode);
|
evt->opcode = sys_cpu_to_le16(opcode);
|
||||||
evt->status = status;
|
evt->status = status;
|
||||||
|
|
||||||
bt_recv(buf);
|
bt_recv_prio(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t generate_keys(EccPoint *pkey, uint32_t private_key[8])
|
static uint8_t generate_keys(EccPoint *pkey, uint32_t private_key[8])
|
||||||
|
|
|
@ -100,6 +100,11 @@ int bt_recv(struct net_buf *buf)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int bt_recv_prio(struct net_buf *buf)
|
||||||
|
{
|
||||||
|
return bt_recv(buf);
|
||||||
|
}
|
||||||
|
|
||||||
int bt_send(struct net_buf *buf)
|
int bt_send(struct net_buf *buf)
|
||||||
{
|
{
|
||||||
BT_DBG("buf %p len %u", buf, buf->len);
|
BT_DBG("buf %p len %u", buf, buf->len);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue