Skip to content

Commit 6a24e6d

Browse files
jhedbergkartben
authored andcommitted
Bluetooth: tests: Update to use new H:4 buffer encoding
Update the Bluetooth tests to assume the new H:4 encoding for data that's passing between HCI drivers and their users (normally the host stack). Signed-off-by: Johan Hedberg <[email protected]>
1 parent 6113230 commit 6a24e6d

File tree

12 files changed

+55
-57
lines changed

12 files changed

+55
-57
lines changed

tests/bluetooth/hci_prop_evt/src/main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,10 @@ static int driver_open(const struct device *dev, bt_hci_recv_t recv)
227227
/* HCI driver send. */
228228
static int driver_send(const struct device *dev, struct net_buf *buf)
229229
{
230+
uint8_t type = net_buf_pull_u8(buf);
231+
232+
zassert_true(type == BT_HCI_H4_CMD, "Expected command buffer, got %u", type);
233+
230234
zassert_true(cmd_handle(dev, buf, cmds, ARRAY_SIZE(cmds)) == 0,
231235
"Unknown HCI command");
232236

tests/bluetooth/hci_uart_async/src/test_hci_uart_async.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ static int drv_open(const struct device *dev, bt_hci_recv_t recv)
102102
K_FIFO_DEFINE(drv_send_fifo); /* elem T: net_buf */
103103
static int drv_send(const struct device *dev, struct net_buf *buf)
104104
{
105-
LOG_DBG("buf %p type %d len %u", buf, bt_buf_get_type(buf), buf->len);
105+
LOG_DBG("buf %p type %d len %u", buf, buf->data[0], buf->len);
106106
LOG_HEXDUMP_DBG(buf->data, buf->len, "buf");
107107

108108
__ASSERT_NO_MSG(buf);
@@ -216,9 +216,8 @@ ZTEST(hci_uart, test_h2c_cmd_flow_control)
216216
struct net_buf *buf = k_fifo_get(&drv_send_fifo, TIMEOUT_PRESUME_STUCK);
217217

218218
zassert_not_null(buf);
219-
zassert_equal(buf->len, sizeof(h4_msg_cmd_dummy1) - 1, "Wrong length");
220-
zassert_mem_equal(buf->data, &h4_msg_cmd_dummy1[1],
221-
sizeof(h4_msg_cmd_dummy1) - 1);
219+
zassert_equal(buf->len, sizeof(h4_msg_cmd_dummy1), "Wrong length");
220+
zassert_mem_equal(buf->data, h4_msg_cmd_dummy1, sizeof(h4_msg_cmd_dummy1));
222221
net_buf_unref(buf);
223222
}
224223

@@ -244,10 +243,10 @@ ZTEST(hci_uart, test_h2c_cmd_flow_control)
244243
struct net_buf *buf = k_fifo_get(&drv_send_fifo, TIMEOUT_PRESUME_STUCK);
245244

246245
zassert_not_null(buf);
247-
zassert_equal(buf->len, sizeof(h4_msg_cmd_host_num_complete) - 1,
246+
zassert_equal(buf->len, sizeof(h4_msg_cmd_host_num_complete),
248247
"Wrong length");
249-
zassert_mem_equal(buf->data, &h4_msg_cmd_host_num_complete[1],
250-
sizeof(h4_msg_cmd_dummy1) - 2);
248+
zassert_mem_equal(buf->data, h4_msg_cmd_host_num_complete,
249+
sizeof(h4_msg_cmd_dummy1) - 1);
251250
net_buf_unref(buf);
252251
}
253252

tests/bluetooth/host_long_adv_recv/src/main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ static int driver_open(const struct device *dev, bt_hci_recv_t recv)
242242
/* HCI driver send. */
243243
static int driver_send(const struct device *dev, struct net_buf *buf)
244244
{
245+
uint8_t type = net_buf_pull_u8(buf);
246+
247+
zassert_true(type == BT_HCI_H4_CMD, "Unexpected command buffer, got %u", type);
248+
245249
zassert_true(cmd_handle(dev, buf, cmds, ARRAY_SIZE(cmds)) == 0, "Unknown HCI command");
246250

247251
net_buf_unref(buf);

tests/bsim/bluetooth/host/att/pipeline/tester/src/main.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,7 @@ struct net_buf *bt_hci_cmd_create(uint16_t opcode, uint8_t param_len)
7878

7979
LOG_DBG("buf %p", buf);
8080

81-
net_buf_reserve(buf, BT_BUF_RESERVE);
82-
83-
bt_buf_set_type(buf, BT_BUF_CMD);
81+
net_buf_add_u8(buf, BT_HCI_H4_CMD);
8482

8583
hdr = net_buf_add(buf, sizeof(*hdr));
8684
hdr->opcode = sys_cpu_to_le16(opcode);
@@ -306,9 +304,10 @@ static void recv(struct net_buf *buf)
306304
{
307305
LOG_HEXDUMP_DBG(buf->data, buf->len, "HCI RX");
308306

307+
uint8_t type = net_buf_pull_u8(buf);
309308
uint8_t code = buf->data[0];
310309

311-
if (bt_buf_get_type(buf) == BT_BUF_EVT) {
310+
if (type == BT_HCI_H4_EVT) {
312311
switch (code) {
313312
case BT_HCI_EVT_CMD_COMPLETE:
314313
case BT_HCI_EVT_CMD_STATUS:
@@ -335,7 +334,7 @@ static void recv(struct net_buf *buf)
335334
return;
336335
}
337336

338-
if (bt_buf_get_type(buf) == BT_BUF_ACL_IN) {
337+
if (type == BT_HCI_H4_ACL) {
339338
handle_acl(buf);
340339
net_buf_unref(buf);
341340
return;
@@ -525,7 +524,7 @@ static int send_acl(struct net_buf *buf)
525524
hdr->handle = sys_cpu_to_le16(bt_acl_handle_pack(conn_handle, flags));
526525
hdr->len = sys_cpu_to_le16(buf->len - sizeof(*hdr));
527526

528-
bt_buf_set_type(buf, BT_BUF_ACL_OUT);
527+
net_buf_push_u8(buf, BT_HCI_H4_ACL);
529528

530529
k_sem_take(&acl_pkts, K_FOREVER);
531530

tests/bsim/bluetooth/host/att/sequential/tester/src/main.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ struct net_buf *bt_hci_cmd_create(uint16_t opcode, uint8_t param_len)
7373

7474
LOG_DBG("buf %p", buf);
7575

76-
net_buf_reserve(buf, BT_BUF_RESERVE);
77-
78-
bt_buf_set_type(buf, BT_BUF_CMD);
76+
net_buf_add_u8(buf, BT_HCI_H4_CMD);
7977

8078
hdr = net_buf_add(buf, sizeof(*hdr));
8179
hdr->opcode = sys_cpu_to_le16(opcode);
@@ -283,9 +281,10 @@ static void recv(struct net_buf *buf)
283281
{
284282
LOG_HEXDUMP_DBG(buf->data, buf->len, "HCI RX");
285283

284+
uint8_t type = net_buf_pull_u8(buf);
286285
uint8_t code = buf->data[0];
287286

288-
if (bt_buf_get_type(buf) == BT_BUF_EVT) {
287+
if (type == BT_HCI_H4_EVT) {
289288
switch (code) {
290289
case BT_HCI_EVT_CMD_COMPLETE:
291290
case BT_HCI_EVT_CMD_STATUS:
@@ -312,7 +311,7 @@ static void recv(struct net_buf *buf)
312311
return;
313312
}
314313

315-
if (bt_buf_get_type(buf) == BT_BUF_ACL_IN) {
314+
if (type == BT_HCI_H4_ACL) {
316315
handle_acl(buf);
317316
net_buf_unref(buf);
318317
return;
@@ -502,7 +501,7 @@ static int send_acl(struct net_buf *buf)
502501
hdr->handle = sys_cpu_to_le16(bt_acl_handle_pack(conn_handle, flags));
503502
hdr->len = sys_cpu_to_le16(buf->len - sizeof(*hdr));
504503

505-
bt_buf_set_type(buf, BT_BUF_ACL_OUT);
504+
net_buf_push_u8(buf, BT_HCI_H4_ACL);
506505

507506
k_sem_take(&acl_pkts, K_FOREVER);
508507

tests/bsim/bluetooth/host/iso/frag/src/broadcaster.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ void entrypoint_broadcaster(void)
232232

233233
void validate_no_iso_frag(struct net_buf *buf)
234234
{
235-
struct bt_hci_iso_hdr *hci_hdr = (void *)buf->data;
235+
struct bt_hci_iso_hdr *hci_hdr = (void *)(buf->data + 1);
236236

237237
uint16_t handle = sys_le16_to_cpu(hci_hdr->handle);
238238
uint8_t flags = bt_iso_flags(handle);
@@ -247,7 +247,7 @@ int __wrap_bt_send(struct net_buf *buf)
247247
{
248248
LOG_HEXDUMP_DBG(buf->data, buf->len, "h->c");
249249

250-
if (bt_buf_get_type(buf) == BT_BUF_ISO_OUT) {
250+
if (buf->data[0] == BT_HCI_H4_ISO) {
251251
validate_no_iso_frag(buf);
252252
}
253253

tests/bsim/bluetooth/host/iso/frag_2/src/broadcaster.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,9 @@ int __real_bt_send(struct net_buf *buf);
269269

270270
int __wrap_bt_send(struct net_buf *buf)
271271
{
272-
struct bt_hci_iso_hdr *hci_hdr = (void *)buf->data;
272+
if (buf->data[0] == BT_HCI_H4_ISO) {
273+
struct bt_hci_iso_hdr *hci_hdr = (void *)(buf->data + 1);
273274

274-
if (bt_buf_get_type(buf) == BT_BUF_ISO_OUT) {
275275
uint16_t handle = sys_le16_to_cpu(hci_hdr->handle);
276276
uint8_t flags = bt_iso_flags(handle);
277277
uint8_t pb_flag = bt_iso_flags_pb(flags);

tests/bsim/bluetooth/host/l2cap/reassembly/peer/src/peer.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,7 @@ struct net_buf *bt_hci_cmd_create(uint16_t opcode, uint8_t param_len)
6969

7070
LOG_DBG("buf %p", buf);
7171

72-
net_buf_reserve(buf, BT_BUF_RESERVE);
73-
74-
bt_buf_set_type(buf, BT_BUF_CMD);
72+
net_buf_add_u8(buf, BT_HCI_H4_CMD);
7573

7674
hdr = net_buf_add(buf, sizeof(*hdr));
7775
hdr->opcode = sys_cpu_to_le16(opcode);
@@ -236,9 +234,10 @@ static void recv(struct net_buf *buf)
236234
{
237235
LOG_HEXDUMP_DBG(buf->data, buf->len, "HCI RX");
238236

237+
uint8_t type = net_buf_pull_u8(buf);
239238
uint8_t code = buf->data[0];
240239

241-
if (bt_buf_get_type(buf) == BT_BUF_EVT) {
240+
if (type == BT_HCI_H4_EVT) {
242241
switch (code) {
243242
case BT_HCI_EVT_CMD_COMPLETE:
244243
case BT_HCI_EVT_CMD_STATUS:
@@ -265,7 +264,7 @@ static void recv(struct net_buf *buf)
265264
return;
266265
}
267266

268-
if (bt_buf_get_type(buf) == BT_BUF_ACL_IN) {
267+
if (type == BT_HCI_H4_ACL) {
269268
handle_acl(buf);
270269
net_buf_unref(buf);
271270
return;
@@ -467,7 +466,7 @@ static int send_acl(struct net_buf *buf, uint8_t flags)
467466
hdr->handle = sys_cpu_to_le16(bt_acl_handle_pack(conn_handle, flags));
468467
hdr->len = sys_cpu_to_le16(buf->len - sizeof(*hdr));
469468

470-
bt_buf_set_type(buf, BT_BUF_ACL_OUT);
469+
net_buf_push_u8(buf, BT_HCI_H4_ACL);
471470

472471
k_sem_take(&acl_pkts, K_FOREVER);
473472

tests/bsim/bluetooth/host/l2cap/split/tester/src/main.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ struct net_buf *bt_hci_cmd_create(uint16_t opcode, uint8_t param_len)
6161

6262
LOG_DBG("buf %p", buf);
6363

64-
net_buf_reserve(buf, BT_BUF_RESERVE);
65-
66-
bt_buf_set_type(buf, BT_BUF_CMD);
64+
net_buf_add_u8(buf, BT_HCI_H4_CMD);
6765

6866
hdr = net_buf_add(buf, sizeof(*hdr));
6967
hdr->opcode = sys_cpu_to_le16(opcode);
@@ -263,9 +261,10 @@ static void recv(struct net_buf *buf)
263261
{
264262
LOG_HEXDUMP_DBG(buf->data, buf->len, "HCI RX");
265263

264+
uint8_t type = net_buf_pull_u8(buf);
266265
uint8_t code = buf->data[0];
267266

268-
if (bt_buf_get_type(buf) == BT_BUF_EVT) {
267+
if (type == BT_HCI_H4_EVT) {
269268
switch (code) {
270269
case BT_HCI_EVT_CMD_COMPLETE:
271270
case BT_HCI_EVT_CMD_STATUS:
@@ -292,7 +291,7 @@ static void recv(struct net_buf *buf)
292291
return;
293292
}
294293

295-
if (bt_buf_get_type(buf) == BT_BUF_ACL_IN) {
294+
if (type == BT_HCI_H4_ACL) {
296295
handle_acl(buf);
297296
net_buf_unref(buf);
298297
return;
@@ -498,7 +497,7 @@ static int send_acl(struct net_buf *buf)
498497
hdr->handle = sys_cpu_to_le16(bt_acl_handle_pack(conn_handle, flags));
499498
hdr->len = sys_cpu_to_le16(buf->len - sizeof(*hdr));
500499

501-
bt_buf_set_type(buf, BT_BUF_ACL_OUT);
500+
net_buf_push_u8(buf, BT_HCI_H4_ACL);
502501

503502
k_sem_take(&acl_pkts, K_FOREVER);
504503

tests/bsim/bluetooth/host/misc/disconnect/tester/src/main.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ struct net_buf *bt_hci_cmd_create(uint16_t opcode, uint8_t param_len)
7171

7272
LOG_DBG("buf %p", buf);
7373

74-
net_buf_reserve(buf, BT_BUF_RESERVE);
75-
76-
bt_buf_set_type(buf, BT_BUF_CMD);
74+
net_buf_add_u8(buf, BT_HCI_H4_CMD);
7775

7876
hdr = net_buf_add(buf, sizeof(*hdr));
7977
hdr->opcode = sys_cpu_to_le16(opcode);
@@ -260,9 +258,10 @@ static void recv(struct net_buf *buf)
260258
{
261259
LOG_HEXDUMP_DBG(buf->data, buf->len, "HCI RX");
262260

261+
uint8_t type = net_buf_pull_u8(buf);
263262
uint8_t code = buf->data[0];
264263

265-
if (bt_buf_get_type(buf) == BT_BUF_EVT) {
264+
if (type == BT_HCI_H4_EVT) {
266265
switch (code) {
267266
case BT_HCI_EVT_CMD_COMPLETE:
268267
case BT_HCI_EVT_CMD_STATUS:
@@ -289,7 +288,7 @@ static void recv(struct net_buf *buf)
289288
return;
290289
}
291290

292-
if (bt_buf_get_type(buf) == BT_BUF_ACL_IN) {
291+
if (type == BT_HCI_H4_ACL) {
293292
handle_acl(buf);
294293
net_buf_unref(buf);
295294
return;
@@ -479,7 +478,7 @@ static int send_acl(struct net_buf *buf)
479478
hdr->handle = sys_cpu_to_le16(bt_acl_handle_pack(conn_handle, flags));
480479
hdr->len = sys_cpu_to_le16(buf->len - sizeof(*hdr));
481480

482-
bt_buf_set_type(buf, BT_BUF_ACL_OUT);
481+
net_buf_push_u8(buf, BT_HCI_H4_ACL);
483482

484483
k_sem_take(&acl_pkts, K_FOREVER);
485484

0 commit comments

Comments
 (0)