Skip to content

Commit 0c40fc3

Browse files
jhedbergolivier-le-sage
authored andcommitted
[nrf fromtree] tests: bsim: bluetooth: Remove bt_hci_cmd_create() usage
These tests have some sort of simple host implementation, which reuses the bt_hci_cmd_create() API name, but the implementation is actually local and something that can be made static. Change the function to be static and rename it to be more in line with other internal functions. Signed-off-by: Johan Hedberg <[email protected]> (cherry picked from commit 978614a)
1 parent 8acf1dc commit 0c40fc3

File tree

6 files changed

+44
-44
lines changed
  • tests/bsim/bluetooth/host

6 files changed

+44
-44
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ static uint16_t conn_handle;
6666
static volatile uint16_t active_opcode = 0xFFFF;
6767
static struct net_buf *cmd_rsp;
6868

69-
struct net_buf *bt_hci_cmd_create(uint16_t opcode, uint8_t param_len)
69+
static struct net_buf *create_cmd(uint16_t opcode, uint8_t param_len)
7070
{
7171
struct bt_hci_cmd_hdr *hdr;
7272
struct net_buf *buf;
@@ -349,7 +349,7 @@ static void send_cmd(uint16_t opcode, struct net_buf *cmd, struct net_buf **rsp)
349349
LOG_DBG("opcode %x", opcode);
350350

351351
if (!cmd) {
352-
cmd = bt_hci_cmd_create(opcode, 0);
352+
cmd = create_cmd(opcode, 0);
353353
}
354354

355355
k_sem_take(&cmd_sem, K_FOREVER);
@@ -420,7 +420,7 @@ static void read_max_data_len(uint16_t *tx_octets, uint16_t *tx_time)
420420
static void write_default_data_len(uint16_t tx_octets, uint16_t tx_time)
421421
{
422422
struct bt_hci_cp_le_write_default_data_len *cp;
423-
struct net_buf *buf = bt_hci_cmd_create(BT_HCI_OP_LE_WRITE_DEFAULT_DATA_LEN, sizeof(*cp));
423+
struct net_buf *buf = create_cmd(BT_HCI_OP_LE_WRITE_DEFAULT_DATA_LEN, sizeof(*cp));
424424

425425
TEST_ASSERT_NO_MSG(buf);
426426

@@ -446,7 +446,7 @@ static void set_event_mask(uint16_t opcode)
446446
uint64_t mask = 0U;
447447

448448
/* The two commands have the same length/params */
449-
buf = bt_hci_cmd_create(opcode, sizeof(*cp_mask));
449+
buf = create_cmd(opcode, sizeof(*cp_mask));
450450
TEST_ASSERT_NO_MSG(buf);
451451

452452
/* Forward all events */
@@ -464,7 +464,7 @@ static void set_random_address(void)
464464

465465
LOG_DBG("%s", bt_addr_str(&addr.a));
466466

467-
buf = bt_hci_cmd_create(BT_HCI_OP_LE_SET_RANDOM_ADDRESS, sizeof(addr.a));
467+
buf = create_cmd(BT_HCI_OP_LE_SET_RANDOM_ADDRESS, sizeof(addr.a));
468468
TEST_ASSERT_NO_MSG(buf);
469469

470470
net_buf_add_mem(buf, &addr.a, sizeof(addr.a));
@@ -487,12 +487,12 @@ void start_adv(void)
487487
set_param.own_addr_type = BT_HCI_OWN_ADDR_RANDOM;
488488

489489
/* configure */
490-
buf = bt_hci_cmd_create(BT_HCI_OP_LE_SET_ADV_PARAM, sizeof(set_param));
490+
buf = create_cmd(BT_HCI_OP_LE_SET_ADV_PARAM, sizeof(set_param));
491491
net_buf_add_mem(buf, &set_param, sizeof(set_param));
492492
send_cmd(BT_HCI_OP_LE_SET_ADV_PARAM, buf, NULL);
493493

494494
/* start */
495-
buf = bt_hci_cmd_create(BT_HCI_OP_LE_SET_ADV_ENABLE, 1);
495+
buf = create_cmd(BT_HCI_OP_LE_SET_ADV_ENABLE, 1);
496496
net_buf_add_u8(buf, BT_HCI_LE_ADV_ENABLE);
497497
send_cmd(BT_HCI_OP_LE_SET_ADV_ENABLE, buf, NULL);
498498
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static uint16_t conn_handle;
6161
static volatile uint16_t active_opcode = 0xFFFF;
6262
static struct net_buf *cmd_rsp;
6363

64-
struct net_buf *bt_hci_cmd_create(uint16_t opcode, uint8_t param_len)
64+
static struct net_buf *create_cmd(uint16_t opcode, uint8_t param_len)
6565
{
6666
struct bt_hci_cmd_hdr *hdr;
6767
struct net_buf *buf;
@@ -326,7 +326,7 @@ static void send_cmd(uint16_t opcode, struct net_buf *cmd, struct net_buf **rsp)
326326
LOG_DBG("opcode %x", opcode);
327327

328328
if (!cmd) {
329-
cmd = bt_hci_cmd_create(opcode, 0);
329+
cmd = create_cmd(opcode, 0);
330330
}
331331

332332
k_sem_take(&cmd_sem, K_FOREVER);
@@ -397,7 +397,7 @@ static void read_max_data_len(uint16_t *tx_octets, uint16_t *tx_time)
397397
static void write_default_data_len(uint16_t tx_octets, uint16_t tx_time)
398398
{
399399
struct bt_hci_cp_le_write_default_data_len *cp;
400-
struct net_buf *buf = bt_hci_cmd_create(BT_HCI_OP_LE_WRITE_DEFAULT_DATA_LEN, sizeof(*cp));
400+
struct net_buf *buf = create_cmd(BT_HCI_OP_LE_WRITE_DEFAULT_DATA_LEN, sizeof(*cp));
401401

402402
TEST_ASSERT_NO_MSG(buf);
403403

@@ -423,7 +423,7 @@ static void set_event_mask(uint16_t opcode)
423423
uint64_t mask = 0U;
424424

425425
/* The two commands have the same length/params */
426-
buf = bt_hci_cmd_create(opcode, sizeof(*cp_mask));
426+
buf = create_cmd(opcode, sizeof(*cp_mask));
427427
TEST_ASSERT_NO_MSG(buf);
428428

429429
/* Forward all events */
@@ -441,7 +441,7 @@ static void set_random_address(void)
441441

442442
LOG_DBG("%s", bt_addr_str(&addr.a));
443443

444-
buf = bt_hci_cmd_create(BT_HCI_OP_LE_SET_RANDOM_ADDRESS, sizeof(addr.a));
444+
buf = create_cmd(BT_HCI_OP_LE_SET_RANDOM_ADDRESS, sizeof(addr.a));
445445
TEST_ASSERT_NO_MSG(buf);
446446

447447
net_buf_add_mem(buf, &addr.a, sizeof(addr.a));
@@ -464,12 +464,12 @@ void start_adv(void)
464464
set_param.own_addr_type = BT_HCI_OWN_ADDR_RANDOM;
465465

466466
/* configure */
467-
buf = bt_hci_cmd_create(BT_HCI_OP_LE_SET_ADV_PARAM, sizeof(set_param));
467+
buf = create_cmd(BT_HCI_OP_LE_SET_ADV_PARAM, sizeof(set_param));
468468
net_buf_add_mem(buf, &set_param, sizeof(set_param));
469469
send_cmd(BT_HCI_OP_LE_SET_ADV_PARAM, buf, NULL);
470470

471471
/* start */
472-
buf = bt_hci_cmd_create(BT_HCI_OP_LE_SET_ADV_ENABLE, 1);
472+
buf = create_cmd(BT_HCI_OP_LE_SET_ADV_ENABLE, 1);
473473
net_buf_add_u8(buf, BT_HCI_LE_ADV_ENABLE);
474474
send_cmd(BT_HCI_OP_LE_SET_ADV_ENABLE, buf, NULL);
475475
}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ static uint16_t conn_handle;
5757
static volatile uint16_t active_opcode = 0xFFFF;
5858
static struct net_buf *cmd_rsp;
5959

60-
struct net_buf *bt_hci_cmd_create(uint16_t opcode, uint8_t param_len)
60+
static struct net_buf *create_cmd(uint16_t opcode, uint8_t param_len)
6161
{
6262
struct bt_hci_cmd_hdr *hdr;
6363
struct net_buf *buf;
@@ -279,7 +279,7 @@ static void send_cmd(uint16_t opcode, struct net_buf *cmd, struct net_buf **rsp)
279279
LOG_DBG("opcode %x", opcode);
280280

281281
if (!cmd) {
282-
cmd = bt_hci_cmd_create(opcode, 0);
282+
cmd = create_cmd(opcode, 0);
283283
}
284284

285285
k_sem_take(&cmd_sem, K_FOREVER);
@@ -352,7 +352,7 @@ static void set_event_mask(uint16_t opcode)
352352
uint64_t mask = 0U;
353353

354354
/* The two commands have the same length/params */
355-
buf = bt_hci_cmd_create(opcode, sizeof(*cp_mask));
355+
buf = create_cmd(opcode, sizeof(*cp_mask));
356356
TEST_ASSERT_NO_MSG(buf);
357357

358358
/* Forward all events */
@@ -370,7 +370,7 @@ static void set_random_address(void)
370370

371371
LOG_DBG("%s", bt_addr_str(&addr.a));
372372

373-
buf = bt_hci_cmd_create(BT_HCI_OP_LE_SET_RANDOM_ADDRESS, sizeof(addr.a));
373+
buf = create_cmd(BT_HCI_OP_LE_SET_RANDOM_ADDRESS, sizeof(addr.a));
374374
TEST_ASSERT_NO_MSG(buf);
375375

376376
net_buf_add_mem(buf, &addr.a, sizeof(addr.a));
@@ -392,7 +392,7 @@ static void start_adv(uint16_t interval, const char *name, size_t name_len)
392392
data.data[1] = BT_DATA_NAME_COMPLETE;
393393
memcpy(&data.data[2], name, name_len);
394394

395-
buf = bt_hci_cmd_create(BT_HCI_OP_LE_SET_ADV_DATA, sizeof(data));
395+
buf = create_cmd(BT_HCI_OP_LE_SET_ADV_DATA, sizeof(data));
396396
__ASSERT_NO_MSG(buf);
397397
net_buf_add_mem(buf, &data, sizeof(data));
398398
send_cmd(BT_HCI_OP_LE_SET_ADV_DATA, buf, NULL);
@@ -405,13 +405,13 @@ static void start_adv(uint16_t interval, const char *name, size_t name_len)
405405
set_param.type = BT_HCI_ADV_IND;
406406
set_param.own_addr_type = BT_HCI_OWN_ADDR_RANDOM;
407407

408-
buf = bt_hci_cmd_create(BT_HCI_OP_LE_SET_ADV_PARAM, sizeof(set_param));
408+
buf = create_cmd(BT_HCI_OP_LE_SET_ADV_PARAM, sizeof(set_param));
409409
__ASSERT_NO_MSG(buf);
410410
net_buf_add_mem(buf, &set_param, sizeof(set_param));
411411

412412
send_cmd(BT_HCI_OP_LE_SET_ADV_PARAM, buf, NULL);
413413

414-
buf = bt_hci_cmd_create(BT_HCI_OP_LE_SET_ADV_ENABLE, 1);
414+
buf = create_cmd(BT_HCI_OP_LE_SET_ADV_ENABLE, 1);
415415
__ASSERT_NO_MSG(buf);
416416

417417
net_buf_add_u8(buf, BT_HCI_LE_ADV_ENABLE);
@@ -427,7 +427,7 @@ static void disconnect(void)
427427

428428
LOG_INF("Disconnecting");
429429

430-
buf = bt_hci_cmd_create(BT_HCI_OP_DISCONNECT, sizeof(*disconn));
430+
buf = create_cmd(BT_HCI_OP_DISCONNECT, sizeof(*disconn));
431431
TEST_ASSERT(buf);
432432

433433
disconn = net_buf_add(buf, sizeof(*disconn));

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static uint16_t conn_handle;
4949
static uint16_t active_opcode = 0xFFFF;
5050
static struct net_buf *cmd_rsp;
5151

52-
struct net_buf *bt_hci_cmd_create(uint16_t opcode, uint8_t param_len)
52+
static struct net_buf *create_cmd(uint16_t opcode, uint8_t param_len)
5353
{
5454
struct bt_hci_cmd_hdr *hdr;
5555
struct net_buf *buf;
@@ -306,7 +306,7 @@ static void send_cmd(uint16_t opcode, struct net_buf *cmd, struct net_buf **rsp)
306306
LOG_DBG("opcode %x", opcode);
307307

308308
if (!cmd) {
309-
cmd = bt_hci_cmd_create(opcode, 0);
309+
cmd = create_cmd(opcode, 0);
310310
}
311311

312312
k_sem_take(&cmd_sem, K_FOREVER);
@@ -377,7 +377,7 @@ static void read_max_data_len(uint16_t *tx_octets, uint16_t *tx_time)
377377
static void write_default_data_len(uint16_t tx_octets, uint16_t tx_time)
378378
{
379379
struct bt_hci_cp_le_write_default_data_len *cp;
380-
struct net_buf *buf = bt_hci_cmd_create(BT_HCI_OP_LE_WRITE_DEFAULT_DATA_LEN, sizeof(*cp));
380+
struct net_buf *buf = create_cmd(BT_HCI_OP_LE_WRITE_DEFAULT_DATA_LEN, sizeof(*cp));
381381

382382
__ASSERT_NO_MSG(buf);
383383

@@ -403,7 +403,7 @@ static void set_event_mask(uint16_t opcode)
403403
uint64_t mask = 0U;
404404

405405
/* The two commands have the same length/params */
406-
buf = bt_hci_cmd_create(opcode, sizeof(*cp_mask));
406+
buf = create_cmd(opcode, sizeof(*cp_mask));
407407
__ASSERT_NO_MSG(buf);
408408

409409
/* Forward all events */
@@ -421,7 +421,7 @@ static void set_random_address(void)
421421

422422
LOG_DBG("%s", bt_addr_str(&addr.a));
423423

424-
buf = bt_hci_cmd_create(BT_HCI_OP_LE_SET_RANDOM_ADDRESS, sizeof(addr.a));
424+
buf = create_cmd(BT_HCI_OP_LE_SET_RANDOM_ADDRESS, sizeof(addr.a));
425425
__ASSERT_NO_MSG(buf);
426426

427427
net_buf_add_mem(buf, &addr.a, sizeof(addr.a));
@@ -442,13 +442,13 @@ void start_adv(uint16_t interval)
442442
set_param.type = BT_HCI_ADV_IND;
443443
set_param.own_addr_type = BT_HCI_OWN_ADDR_RANDOM;
444444

445-
buf = bt_hci_cmd_create(BT_HCI_OP_LE_SET_ADV_PARAM, sizeof(set_param));
445+
buf = create_cmd(BT_HCI_OP_LE_SET_ADV_PARAM, sizeof(set_param));
446446
__ASSERT_NO_MSG(buf);
447447
net_buf_add_mem(buf, &set_param, sizeof(set_param));
448448

449449
send_cmd(BT_HCI_OP_LE_SET_ADV_PARAM, buf, NULL);
450450

451-
buf = bt_hci_cmd_create(BT_HCI_OP_LE_SET_ADV_ENABLE, 1);
451+
buf = create_cmd(BT_HCI_OP_LE_SET_ADV_ENABLE, 1);
452452
__ASSERT_NO_MSG(buf);
453453

454454
net_buf_add_u8(buf, BT_HCI_LE_ADV_ENABLE);

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static uint16_t conn_handle;
5959
static volatile uint16_t active_opcode = 0xFFFF;
6060
static struct net_buf *cmd_rsp;
6161

62-
struct net_buf *bt_hci_cmd_create(uint16_t opcode, uint8_t param_len)
62+
static struct net_buf *create_cmd(uint16_t opcode, uint8_t param_len)
6363
{
6464
struct bt_hci_cmd_hdr *hdr;
6565
struct net_buf *buf;
@@ -303,7 +303,7 @@ static void send_cmd(uint16_t opcode, struct net_buf *cmd, struct net_buf **rsp)
303303
LOG_DBG("opcode %x", opcode);
304304

305305
if (!cmd) {
306-
cmd = bt_hci_cmd_create(opcode, 0);
306+
cmd = create_cmd(opcode, 0);
307307
}
308308

309309
k_sem_take(&cmd_sem, K_FOREVER);
@@ -374,7 +374,7 @@ static void read_max_data_len(uint16_t *tx_octets, uint16_t *tx_time)
374374
static void write_default_data_len(uint16_t tx_octets, uint16_t tx_time)
375375
{
376376
struct bt_hci_cp_le_write_default_data_len *cp;
377-
struct net_buf *buf = bt_hci_cmd_create(BT_HCI_OP_LE_WRITE_DEFAULT_DATA_LEN, sizeof(*cp));
377+
struct net_buf *buf = create_cmd(BT_HCI_OP_LE_WRITE_DEFAULT_DATA_LEN, sizeof(*cp));
378378

379379
TEST_ASSERT_NO_MSG(buf);
380380

@@ -400,7 +400,7 @@ static void set_event_mask(uint16_t opcode)
400400
uint64_t mask = 0U;
401401

402402
/* The two commands have the same length/params */
403-
buf = bt_hci_cmd_create(opcode, sizeof(*cp_mask));
403+
buf = create_cmd(opcode, sizeof(*cp_mask));
404404
TEST_ASSERT_NO_MSG(buf);
405405

406406
/* Forward all events */
@@ -418,7 +418,7 @@ static void set_random_address(void)
418418

419419
LOG_DBG("%s", bt_addr_str(&addr.a));
420420

421-
buf = bt_hci_cmd_create(BT_HCI_OP_LE_SET_RANDOM_ADDRESS, sizeof(addr.a));
421+
buf = create_cmd(BT_HCI_OP_LE_SET_RANDOM_ADDRESS, sizeof(addr.a));
422422
TEST_ASSERT_NO_MSG(buf);
423423

424424
net_buf_add_mem(buf, &addr.a, sizeof(addr.a));
@@ -441,12 +441,12 @@ void start_adv(void)
441441
set_param.own_addr_type = BT_HCI_OWN_ADDR_RANDOM;
442442

443443
/* configure */
444-
buf = bt_hci_cmd_create(BT_HCI_OP_LE_SET_ADV_PARAM, sizeof(set_param));
444+
buf = create_cmd(BT_HCI_OP_LE_SET_ADV_PARAM, sizeof(set_param));
445445
net_buf_add_mem(buf, &set_param, sizeof(set_param));
446446
send_cmd(BT_HCI_OP_LE_SET_ADV_PARAM, buf, NULL);
447447

448448
/* start */
449-
buf = bt_hci_cmd_create(BT_HCI_OP_LE_SET_ADV_ENABLE, 1);
449+
buf = create_cmd(BT_HCI_OP_LE_SET_ADV_ENABLE, 1);
450450
net_buf_add_u8(buf, BT_HCI_LE_ADV_ENABLE);
451451
send_cmd(BT_HCI_OP_LE_SET_ADV_ENABLE, buf, NULL);
452452
}

tests/bsim/bluetooth/host/misc/hfc_multilink/tester/src/tester.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ static uint16_t conn_handle;
5050
static uint16_t active_opcode = 0xFFFF;
5151
static struct net_buf *cmd_rsp;
5252

53-
struct net_buf *bt_hci_cmd_create(uint16_t opcode, uint8_t param_len)
53+
static struct net_buf *create_cmd(uint16_t opcode, uint8_t param_len)
5454
{
5555
struct bt_hci_cmd_hdr *hdr;
5656
struct net_buf *buf;
@@ -317,7 +317,7 @@ static void send_cmd(uint16_t opcode, struct net_buf *cmd, struct net_buf **rsp)
317317
LOG_DBG("opcode %x", opcode);
318318

319319
if (!cmd) {
320-
cmd = bt_hci_cmd_create(opcode, 0);
320+
cmd = create_cmd(opcode, 0);
321321
}
322322

323323
k_sem_take(&cmd_sem, K_FOREVER);
@@ -388,7 +388,7 @@ static void read_max_data_len(uint16_t *tx_octets, uint16_t *tx_time)
388388
static void write_default_data_len(uint16_t tx_octets, uint16_t tx_time)
389389
{
390390
struct bt_hci_cp_le_write_default_data_len *cp;
391-
struct net_buf *buf = bt_hci_cmd_create(BT_HCI_OP_LE_WRITE_DEFAULT_DATA_LEN, sizeof(*cp));
391+
struct net_buf *buf = create_cmd(BT_HCI_OP_LE_WRITE_DEFAULT_DATA_LEN, sizeof(*cp));
392392

393393
__ASSERT_NO_MSG(buf);
394394

@@ -414,7 +414,7 @@ static void set_event_mask(uint16_t opcode)
414414
uint64_t mask = 0U;
415415

416416
/* The two commands have the same length/params */
417-
buf = bt_hci_cmd_create(opcode, sizeof(*cp_mask));
417+
buf = create_cmd(opcode, sizeof(*cp_mask));
418418
__ASSERT_NO_MSG(buf);
419419

420420
/* Forward all events */
@@ -435,7 +435,7 @@ static void set_random_address(void)
435435

436436
LOG_DBG("%s", bt_addr_str(&addr.a));
437437

438-
buf = bt_hci_cmd_create(BT_HCI_OP_LE_SET_RANDOM_ADDRESS, sizeof(addr.a));
438+
buf = create_cmd(BT_HCI_OP_LE_SET_RANDOM_ADDRESS, sizeof(addr.a));
439439
__ASSERT_NO_MSG(buf);
440440

441441
net_buf_add_mem(buf, &addr.a, sizeof(addr.a));
@@ -457,7 +457,7 @@ static void start_adv(uint16_t interval, const char *name, size_t name_len)
457457
data.data[1] = BT_DATA_NAME_COMPLETE;
458458
memcpy(&data.data[2], name, name_len);
459459

460-
buf = bt_hci_cmd_create(BT_HCI_OP_LE_SET_ADV_DATA, sizeof(data));
460+
buf = create_cmd(BT_HCI_OP_LE_SET_ADV_DATA, sizeof(data));
461461
__ASSERT_NO_MSG(buf);
462462
net_buf_add_mem(buf, &data, sizeof(data));
463463
send_cmd(BT_HCI_OP_LE_SET_ADV_DATA, buf, NULL);
@@ -470,13 +470,13 @@ static void start_adv(uint16_t interval, const char *name, size_t name_len)
470470
set_param.type = BT_HCI_ADV_IND;
471471
set_param.own_addr_type = BT_HCI_OWN_ADDR_RANDOM;
472472

473-
buf = bt_hci_cmd_create(BT_HCI_OP_LE_SET_ADV_PARAM, sizeof(set_param));
473+
buf = create_cmd(BT_HCI_OP_LE_SET_ADV_PARAM, sizeof(set_param));
474474
__ASSERT_NO_MSG(buf);
475475
net_buf_add_mem(buf, &set_param, sizeof(set_param));
476476

477477
send_cmd(BT_HCI_OP_LE_SET_ADV_PARAM, buf, NULL);
478478

479-
buf = bt_hci_cmd_create(BT_HCI_OP_LE_SET_ADV_ENABLE, 1);
479+
buf = create_cmd(BT_HCI_OP_LE_SET_ADV_ENABLE, 1);
480480
__ASSERT_NO_MSG(buf);
481481

482482
net_buf_add_u8(buf, BT_HCI_LE_ADV_ENABLE);

0 commit comments

Comments
 (0)