Skip to content

Commit

Permalink
Bluetooth: hci_raw: Fix pushing H4 headers in bt_buf_get_rx
Browse files Browse the repository at this point in the history
User of bt_buf_get_rx may attempt to push their own headers, e.g. ACL
headers, so move the H4 header logic to bt_recv after logging into the
monitor since otherwise the buffer would contain H4 headers which is
not expected by the monitor.

Fixes zephyrproject-rtos#24646

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
  • Loading branch information
Vudentz authored and hakehuang committed Jun 20, 2020
1 parent 6565398 commit b8b37a9
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions subsys/bluetooth/host/hci_raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,6 @@ struct net_buf *bt_buf_get_rx(enum bt_buf_type type, s32_t timeout)
net_buf_reserve(buf, BT_BUF_RESERVE);
bt_buf_set_type(buf, type);

if (IS_ENABLED(CONFIG_BT_HCI_RAW_H4) &&
raw_mode == BT_HCI_RAW_MODE_H4) {
switch (type) {
case BT_BUF_EVT:
net_buf_push_u8(buf, H4_EVT);
break;
case BT_BUF_ACL_IN:
net_buf_push_u8(buf, H4_ACL);
break;
default:
LOG_ERR("Invalid H4 type %u", type);
return NULL;
}
}

return buf;
}

Expand Down Expand Up @@ -170,6 +155,21 @@ int bt_recv(struct net_buf *buf)

bt_monitor_send(bt_monitor_opcode(buf), buf->data, buf->len);

if (IS_ENABLED(CONFIG_BT_HCI_RAW_H4) &&
raw_mode == BT_HCI_RAW_MODE_H4) {
switch (bt_buf_get_type(buf)) {
case BT_BUF_EVT:
net_buf_push_u8(buf, H4_EVT);
break;
case BT_BUF_ACL_IN:
net_buf_push_u8(buf, H4_ACL);
break;
default:
BT_ERR("Unknown type %u", bt_buf_get_type(buf));
return -EINVAL;
}
}

/* Queue to RAW rx queue */
net_buf_put(raw_rx, buf);

Expand Down

0 comments on commit b8b37a9

Please sign in to comment.