Skip to content

Commit f85d63a

Browse files
jhedbergkartben
authored andcommitted
Bluetooth: Remove USB H4 mode support
This non-standard feature never had any proper host side implementation (e.g. it was never upstreamed to BlueZ), and since it comes with notable maintenance overhead it's fair to just remove it. Signed-off-by: Johan Hedberg <[email protected]>
1 parent 6a24e6d commit f85d63a

File tree

5 files changed

+34
-184
lines changed

5 files changed

+34
-184
lines changed

samples/bluetooth/hci_usb/prj.conf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ CONFIG_BT_HCI_RAW=y
44
CONFIG_USB_DEVICE_STACK=y
55
CONFIG_USB_DEVICE_PID=0x000B
66
CONFIG_USB_DEVICE_BLUETOOTH=y
7-
CONFIG_USB_DEVICE_BLUETOOTH_VS_H4=n
87
CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=n
98

109
# We dont want any console or CDC ACM that may cause BlueZ to not detect hci_usb

subsys/bluetooth/controller/hci/hci.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5051,12 +5051,6 @@ static void vs_read_supported_commands(struct net_buf *buf,
50515051
/* Write Tx Power, Read Tx Power */
50525052
rp->commands[1] |= BIT(5) | BIT(6);
50535053
#endif /* CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL */
5054-
#if defined(CONFIG_USB_DEVICE_BLUETOOTH_VS_H4)
5055-
/* Read Supported USB Transport Modes */
5056-
rp->commands[1] |= BIT(7);
5057-
/* Set USB Transport Mode */
5058-
rp->commands[2] |= BIT(0);
5059-
#endif /* USB_DEVICE_BLUETOOTH_VS_H4 */
50605054
}
50615055

50625056
static void vs_read_supported_features(struct net_buf *buf,
@@ -5698,14 +5692,6 @@ int hci_vendor_cmd_handle_common(uint16_t ocf, struct net_buf *cmd,
56985692
vs_read_supported_features(cmd, evt);
56995693
break;
57005694

5701-
#if defined(CONFIG_USB_DEVICE_BLUETOOTH_VS_H4)
5702-
case BT_OCF(BT_HCI_OP_VS_READ_USB_TRANSPORT_MODE):
5703-
break;
5704-
case BT_OCF(BT_HCI_OP_VS_SET_USB_TRANSPORT_MODE):
5705-
reset(cmd, evt);
5706-
break;
5707-
#endif /* CONFIG_USB_DEVICE_BLUETOOTH_VS_H4 */
5708-
57095695
case BT_OCF(BT_HCI_OP_VS_READ_BUILD_INFO):
57105696
vs_read_build_info(cmd, evt);
57115697
break;

subsys/usb/device/class/Kconfig.bt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
11
# Copyright (c) 2016 Wind River Systems, Inc.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
menuconfig USB_DEVICE_BLUETOOTH
4+
config USB_DEVICE_BLUETOOTH
55
bool "USB Bluetooth Device Class support"
66
select BT
77
select BT_HCI_RAW
88
help
99
USB Bluetooth device class support
10-
11-
config USB_DEVICE_BLUETOOTH_VS_H4
12-
bool "USB Bluetooth H4 vendor command"
13-
depends on USB_DEVICE_BLUETOOTH
14-
select BT_HCI_RAW_H4
15-
select BT_HCI_RAW_CMD_EXT
16-
help
17-
Enables vendor command to switch to H:4 transport using the bulk
18-
endpoint.

subsys/usb/device/class/bluetooth.c

Lines changed: 19 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ static struct k_thread tx_thread_data;
4242

4343
/* HCI USB state flags */
4444
static bool configured;
45+
4546
/*
4647
* Shared variable between bluetooth_status_cb() and hci_tx_thread(),
4748
* where hci_tx_thread() has read-only access to it.
@@ -132,15 +133,10 @@ static void hci_tx_thread(void *p1, void *p2, void *p3)
132133

133134
while (true) {
134135
struct net_buf *buf;
136+
uint8_t type;
135137

136138
buf = k_fifo_get(&tx_queue, K_FOREVER);
137139

138-
if (IS_ENABLED(CONFIG_USB_DEVICE_BLUETOOTH_VS_H4) &&
139-
bt_hci_raw_get_mode() == BT_HCI_RAW_MODE_H4) {
140-
/* Force to sent over bulk if H4 is selected */
141-
bt_buf_set_type(buf, BT_BUF_ACL_IN);
142-
}
143-
144140
if (atomic_get(&suspended)) {
145141
if (usb_wakeup_request()) {
146142
LOG_DBG("Remote wakeup not enabled/supported");
@@ -156,7 +152,8 @@ static void hci_tx_thread(void *p1, void *p2, void *p3)
156152
}
157153
}
158154

159-
switch (bt_buf_get_type(buf)) {
155+
type = net_buf_pull_u8(buf);
156+
switch (type) {
160157
case BT_BUF_EVT:
161158
usb_transfer_sync(
162159
bluetooth_ep_data[HCI_INT_EP_IDX].ep_addr,
@@ -170,7 +167,7 @@ static void hci_tx_thread(void *p1, void *p2, void *p3)
170167
USB_TRANS_WRITE);
171168
break;
172169
default:
173-
LOG_ERR("Unknown type %u", bt_buf_get_type(buf));
170+
LOG_ERR("Unknown type %u", type);
174171
break;
175172
}
176173

@@ -198,43 +195,18 @@ static void hci_rx_thread(void *p1, void *p2, void *p3)
198195
}
199196
}
200197

201-
static uint16_t hci_pkt_get_len(struct net_buf *buf,
202-
const uint8_t *data, size_t size)
198+
static uint16_t hci_acl_pkt_len(const uint8_t *data, size_t data_len)
203199
{
204-
uint16_t len = 0;
205-
size_t hdr_len = 0;
206-
207-
switch (bt_buf_get_type(buf)) {
208-
case BT_BUF_CMD: {
209-
struct bt_hci_cmd_hdr *cmd_hdr;
210-
211-
hdr_len = sizeof(*cmd_hdr);
212-
cmd_hdr = (struct bt_hci_cmd_hdr *)data;
213-
len = cmd_hdr->param_len + hdr_len;
214-
break;
215-
}
216-
case BT_BUF_ACL_OUT: {
217-
struct bt_hci_acl_hdr *acl_hdr;
218-
219-
hdr_len = sizeof(*acl_hdr);
220-
acl_hdr = (struct bt_hci_acl_hdr *)data;
221-
len = sys_le16_to_cpu(acl_hdr->len) + hdr_len;
222-
break;
223-
}
224-
case BT_BUF_ISO_OUT: {
225-
struct bt_hci_iso_hdr *iso_hdr;
200+
struct bt_hci_acl_hdr *acl_hdr;
201+
size_t hdr_len = sizeof(*acl_hdr);
226202

227-
hdr_len = sizeof(*iso_hdr);
228-
iso_hdr = (struct bt_hci_iso_hdr *)data;
229-
len = bt_iso_hdr_len(sys_le16_to_cpu(iso_hdr->len)) + hdr_len;
230-
break;
231-
}
232-
default:
233-
LOG_ERR("Unknown bt buffer type");
203+
if (data_len - 1 < hdr_len) {
234204
return 0;
235205
}
236206

237-
return (size < hdr_len) ? 0 : len;
207+
acl_hdr = (struct bt_hci_acl_hdr *)(data + 1);
208+
209+
return sys_le16_to_cpu(acl_hdr->len) + hdr_len;
238210
}
239211

240212
static void acl_read_cb(uint8_t ep, int size, void *priv)
@@ -248,32 +220,15 @@ static void acl_read_cb(uint8_t ep, int size, void *priv)
248220
}
249221

250222
if (buf == NULL) {
251-
/*
252-
* Obtain the first chunk and determine the length
253-
* of the HCI packet.
254-
*/
255-
if (IS_ENABLED(CONFIG_USB_DEVICE_BLUETOOTH_VS_H4) &&
256-
bt_hci_raw_get_mode() == BT_HCI_RAW_MODE_H4) {
257-
buf = bt_buf_get_tx(BT_BUF_H4, K_FOREVER, data, size);
258-
if (!buf) {
259-
LOG_ERR("Failed to allocate buffer");
260-
goto restart_out_transfer;
261-
}
262-
263-
pkt_len = hci_pkt_get_len(buf, &data[1], size - 1);
264-
LOG_DBG("pkt_len %u, chunk %u", pkt_len, size);
265-
} else {
266-
buf = bt_buf_get_tx(BT_BUF_ACL_OUT, K_FOREVER,
267-
data, size);
268-
if (!buf) {
269-
LOG_ERR("Failed to allocate buffer");
270-
goto restart_out_transfer;
271-
}
272-
273-
pkt_len = hci_pkt_get_len(buf, data, size);
274-
LOG_DBG("pkt_len %u, chunk %u", pkt_len, size);
223+
buf = bt_buf_get_tx(BT_BUF_ACL_OUT, K_FOREVER, data, size);
224+
if (!buf) {
225+
LOG_ERR("Failed to allocate buffer");
226+
goto restart_out_transfer;
275227
}
276228

229+
pkt_len = hci_acl_pkt_len(data, size);
230+
LOG_DBG("pkt_len %u, chunk %u", pkt_len, size);
231+
277232
if (pkt_len == 0) {
278233
LOG_ERR("Failed to get packet length");
279234
net_buf_unref(buf);
@@ -359,59 +314,6 @@ static void bluetooth_status_cb(struct usb_cfg_data *cfg,
359314
}
360315
}
361316

362-
static uint8_t vs_read_usb_transport_mode(struct net_buf *buf)
363-
{
364-
struct net_buf *rsp;
365-
struct bt_hci_rp_vs_read_usb_transport_mode *rp;
366-
367-
rsp = bt_hci_cmd_complete_create(BT_HCI_OP_VS_READ_USB_TRANSPORT_MODE,
368-
sizeof(*rp) + 2);
369-
rp = net_buf_add(rsp, sizeof(*rp));
370-
rp->status = BT_HCI_ERR_SUCCESS;
371-
rp->num_supported_modes = 2;
372-
373-
net_buf_add_u8(rsp, BT_HCI_VS_USB_H2_MODE);
374-
net_buf_add_u8(rsp, BT_HCI_VS_USB_H4_MODE);
375-
376-
k_fifo_put(&tx_queue, rsp);
377-
378-
return BT_HCI_ERR_EXT_HANDLED;
379-
}
380-
381-
static uint8_t vs_set_usb_transport_mode(struct net_buf *buf)
382-
{
383-
struct bt_hci_cp_vs_set_usb_transport_mode *cp;
384-
uint8_t mode;
385-
386-
cp = net_buf_pull_mem(buf, sizeof(*cp));
387-
388-
switch (cp->mode) {
389-
case BT_HCI_VS_USB_H2_MODE:
390-
mode = BT_HCI_RAW_MODE_PASSTHROUGH;
391-
break;
392-
case BT_HCI_VS_USB_H4_MODE:
393-
mode = BT_HCI_RAW_MODE_H4;
394-
break;
395-
default:
396-
LOG_DBG("Invalid mode: %u", cp->mode);
397-
return BT_HCI_ERR_INVALID_PARAM;
398-
}
399-
400-
LOG_DBG("mode %u", mode);
401-
402-
bt_hci_raw_set_mode(mode);
403-
404-
return BT_HCI_ERR_SUCCESS;
405-
}
406-
407-
static struct bt_hci_raw_cmd_ext cmd_ext[] = {
408-
BT_HCI_RAW_CMD_EXT(BT_OCF(BT_HCI_OP_VS_READ_USB_TRANSPORT_MODE), 0,
409-
vs_read_usb_transport_mode),
410-
BT_HCI_RAW_CMD_EXT(BT_OCF(BT_HCI_OP_VS_SET_USB_TRANSPORT_MODE),
411-
sizeof(struct bt_hci_cp_vs_set_usb_transport_mode),
412-
vs_set_usb_transport_mode),
413-
};
414-
415317
static int bluetooth_class_handler(struct usb_setup_packet *setup,
416318
int32_t *len, uint8_t **data)
417319
{
@@ -469,10 +371,6 @@ static int bluetooth_init(void)
469371
return ret;
470372
}
471373

472-
if (IS_ENABLED(CONFIG_USB_DEVICE_BLUETOOTH_VS_H4)) {
473-
bt_hci_raw_cmd_ext_register(cmd_ext, ARRAY_SIZE(cmd_ext));
474-
}
475-
476374
k_thread_create(&rx_thread_data, rx_thread_stack,
477375
K_KERNEL_STACK_SIZEOF(rx_thread_stack),
478376
hci_rx_thread, NULL, NULL, NULL,

subsys/usb/device_next/class/bt_hci.c

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -203,23 +203,24 @@ static void bt_hci_tx_thread(void *p1, void *p2, void *p3)
203203

204204
while (true) {
205205
struct net_buf *bt_buf;
206+
uint8_t type;
206207
uint8_t ep;
207208

208209
bt_buf = k_fifo_get(&bt_hci_tx_queue, K_FOREVER);
210+
type = net_buf_pull_u8(bt_buf);
209211

210-
switch (bt_buf_get_type(bt_buf)) {
212+
switch (type) {
211213
case BT_BUF_EVT:
212214
ep = bt_hci_get_int_in(c_data);
213215
break;
214216
case BT_BUF_ACL_IN:
215217
ep = bt_hci_get_bulk_in(c_data);
216218
break;
217219
default:
218-
LOG_ERR("Unknown type %u", bt_buf_get_type(bt_buf));
220+
LOG_ERR("Unknown type %u", type);
219221
continue;
220222
}
221223

222-
223224
bt_hci_tx_sync_in(c_data, bt_buf, ep);
224225
net_buf_unref(bt_buf);
225226
}
@@ -272,43 +273,19 @@ static int bt_hci_acl_out_start(struct usbd_class_data *const c_data)
272273
return ret;
273274
}
274275

275-
static uint16_t hci_pkt_get_len(struct net_buf *const buf,
276-
const uint8_t *data, const size_t size)
276+
static uint16_t hci_acl_pkt_len(struct net_buf *const buf)
277277
{
278-
size_t hdr_len = 0;
279-
uint16_t len = 0;
280-
281-
switch (bt_buf_get_type(buf)) {
282-
case BT_BUF_CMD: {
283-
struct bt_hci_cmd_hdr *cmd_hdr;
278+
struct bt_hci_acl_hdr *acl_hdr;
279+
size_t hdr_len;
284280

285-
hdr_len = sizeof(*cmd_hdr);
286-
cmd_hdr = (struct bt_hci_cmd_hdr *)data;
287-
len = cmd_hdr->param_len + hdr_len;
288-
break;
289-
}
290-
case BT_BUF_ACL_OUT: {
291-
struct bt_hci_acl_hdr *acl_hdr;
292-
293-
hdr_len = sizeof(*acl_hdr);
294-
acl_hdr = (struct bt_hci_acl_hdr *)data;
295-
len = sys_le16_to_cpu(acl_hdr->len) + hdr_len;
296-
break;
297-
}
298-
case BT_BUF_ISO_OUT: {
299-
struct bt_hci_iso_hdr *iso_hdr;
300-
301-
hdr_len = sizeof(*iso_hdr);
302-
iso_hdr = (struct bt_hci_iso_hdr *)data;
303-
len = bt_iso_hdr_len(sys_le16_to_cpu(iso_hdr->len)) + hdr_len;
304-
break;
305-
}
306-
default:
307-
LOG_ERR("Unknown BT buffer type");
281+
hdr_len = sizeof(*acl_hdr);
282+
if (buf->len - 1 < hdr_len) {
308283
return 0;
309284
}
310285

311-
return (size < hdr_len) ? 0 : len;
286+
acl_hdr = (struct bt_hci_acl_hdr *)(buf->data + 1);
287+
288+
return sys_le16_to_cpu(acl_hdr->len) + hdr_len;
312289
}
313290

314291
static int bt_hci_acl_out_cb(struct usbd_class_data *const c_data,
@@ -328,9 +305,8 @@ static int bt_hci_acl_out_cb(struct usbd_class_data *const c_data,
328305
goto restart_out_transfer;
329306
}
330307

331-
hci_data->acl_len = hci_pkt_get_len(hci_data->acl_buf,
332-
buf->data,
333-
buf->len);
308+
hci_data->acl_len = hci_acl_pkt_len(hci_data->acl_buf);
309+
334310
LOG_DBG("acl_len %u, chunk %u", hci_data->acl_len, buf->len);
335311

336312
if (hci_data->acl_len == 0) {

0 commit comments

Comments
 (0)