Skip to content

Commit bf7dfc5

Browse files
kedMertenskartben
authored andcommitted
bluetooth: tester: btp: refactors privacy selection
Takes in use IS_ENABLED as preferred way of guarding Kconfig option for enabling privacy, CONFIG_BT_PRIVACY. It enables compiling guarded code get warning/errors and not link it if not used. Signed-off-by: Evgenii Kosenko <[email protected]>
1 parent fed5561 commit bf7dfc5

File tree

1 file changed

+23
-29
lines changed

1 file changed

+23
-29
lines changed

tests/bluetooth/tester/src/btp_gap.c

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,11 @@ static struct bt_le_oob oob_sc_remote = { 0 };
5454
#define REJECT_LATENCY 0x0000
5555
#define REJECT_SUPERVISION_TIMEOUT 0x0C80
5656

57-
#if defined(CONFIG_BT_PRIVACY)
5857
static struct {
5958
bt_addr_le_t addr;
6059
bool supported;
6160
} cars[CONFIG_BT_MAX_PAIRED];
6261

63-
static uint8_t read_car_cb(struct bt_conn *conn, uint8_t err,
64-
struct bt_gatt_read_params *params, const void *data,
65-
uint16_t length);
66-
67-
static struct bt_gatt_read_params read_car_params = {
68-
.func = read_car_cb,
69-
.by_uuid.uuid = BT_UUID_CENTRAL_ADDR_RES,
70-
.by_uuid.start_handle = BT_ATT_FIRST_ATTRIBUTE_HANDLE,
71-
.by_uuid.end_handle = BT_ATT_LAST_ATTRIBUTE_HANDLE,
72-
};
73-
7462
static uint8_t read_car_cb(struct bt_conn *conn, uint8_t err,
7563
struct bt_gatt_read_params *params, const void *data,
7664
uint16_t length)
@@ -98,7 +86,13 @@ static uint8_t read_car_cb(struct bt_conn *conn, uint8_t err,
9886

9987
return BT_GATT_ITER_STOP;
10088
}
101-
#endif
89+
90+
static struct bt_gatt_read_params read_car_params = {
91+
.func = read_car_cb,
92+
.by_uuid.uuid = BT_UUID_CENTRAL_ADDR_RES,
93+
.by_uuid.start_handle = BT_ATT_FIRST_ATTRIBUTE_HANDLE,
94+
.by_uuid.end_handle = BT_ATT_LAST_ATTRIBUTE_HANDLE,
95+
};
10296

10397
static void le_connected(struct bt_conn *conn, uint8_t err)
10498
{
@@ -314,11 +308,11 @@ static uint8_t controller_info(const void *cmd, uint16_t cmd_len,
314308
* If privacy is used, the device uses random type address, otherwise
315309
* static random or public type address is used.
316310
*/
317-
#if !defined(CONFIG_BT_PRIVACY)
318-
if (oob_local.addr.type == BT_ADDR_LE_RANDOM) {
319-
atomic_set_bit(&current_settings, BTP_GAP_SETTINGS_STATIC_ADDRESS);
311+
if (!IS_ENABLED(CONFIG_BT_PRIVACY)) {
312+
if (oob_local.addr.type == BT_ADDR_LE_RANDOM) {
313+
atomic_set_bit(&current_settings, BTP_GAP_SETTINGS_STATIC_ADDRESS);
314+
}
320315
}
321-
#endif /* CONFIG_BT_PRIVACY */
322316

323317
supported_settings = BIT(BTP_GAP_SETTINGS_POWERED);
324318
supported_settings |= BIT(BTP_GAP_SETTINGS_CONNECTABLE);
@@ -642,20 +636,24 @@ int tester_gap_create_adv_instance(struct bt_le_adv_param *param, uint8_t own_ad
642636
case BTP_GAP_ADDR_TYPE_IDENTITY:
643637
param->options |= BT_LE_ADV_OPT_USE_IDENTITY;
644638
break;
645-
#if defined(CONFIG_BT_PRIVACY)
646639
case BTP_GAP_ADDR_TYPE_RESOLVABLE_PRIVATE:
640+
if (!IS_ENABLED(CONFIG_BT_PRIVACY)) {
641+
return -EINVAL;
642+
}
647643
/* RPA usage is controlled via privacy settings */
648644
if (!atomic_test_bit(&current_settings, BTP_GAP_SETTINGS_PRIVACY)) {
649645
return -EINVAL;
650646
}
651647
break;
652648
case BTP_GAP_ADDR_TYPE_NON_RESOLVABLE_PRIVATE:
649+
if (!IS_ENABLED(CONFIG_BT_PRIVACY)) {
650+
return -EINVAL;
651+
}
653652
/* NRPA is used only for non-connectable advertising */
654653
if (atomic_test_bit(&current_settings, BTP_GAP_SETTINGS_CONNECTABLE)) {
655654
return -EINVAL;
656655
}
657656
break;
658-
#endif
659657
default:
660658
return -EINVAL;
661659
}
@@ -786,8 +784,7 @@ static uint8_t start_directed_advertising(const void *cmd, uint16_t cmd_len,
786784
adv_param.interval_min = BT_GAP_ADV_FAST_INT_MIN_2;
787785
}
788786

789-
if (options & BTP_GAP_START_DIRECTED_ADV_PEER_RPA) {
790-
#if defined(CONFIG_BT_PRIVACY)
787+
if (IS_ENABLED(CONFIG_BT_PRIVACY) && (options & BTP_GAP_START_DIRECTED_ADV_PEER_RPA)) {
791788
/* check if peer supports Central Address Resolution */
792789
for (int i = 0; i < CONFIG_BT_MAX_PAIRED; i++) {
793790
if (bt_addr_le_eq(&cp->address, &cars[i].addr)) {
@@ -796,7 +793,6 @@ static uint8_t start_directed_advertising(const void *cmd, uint16_t cmd_len,
796793
}
797794
}
798795
}
799-
#endif
800796
}
801797

802798
if (bt_le_adv_start(&adv_param, NULL, 0, NULL, 0) < 0) {
@@ -1127,12 +1123,10 @@ void auth_pairing_failed(struct bt_conn *conn, enum bt_security_err reason)
11271123

11281124
static void auth_pairing_complete(struct bt_conn *conn, bool bonded)
11291125
{
1130-
#if defined(CONFIG_BT_PRIVACY)
1131-
/* Read peer's Central Address Resolution if bonded */
1132-
if (bonded) {
1126+
if (IS_ENABLED(CONFIG_BT_PRIVACY) && bonded) {
1127+
/* Read peer's Central Address Resolution if bonded */
11331128
bt_gatt_read(conn, &read_car_params);
11341129
}
1135-
#endif
11361130
}
11371131

11381132
static struct bt_conn_auth_info_cb auth_info_cb = {
@@ -1918,9 +1912,9 @@ uint8_t tester_init_gap(void)
19181912
atomic_set_bit(&current_settings, BTP_GAP_SETTINGS_CONNECTABLE);
19191913
atomic_set_bit(&current_settings, BTP_GAP_SETTINGS_BONDABLE);
19201914
atomic_set_bit(&current_settings, BTP_GAP_SETTINGS_LE);
1921-
#if defined(CONFIG_BT_PRIVACY)
1922-
atomic_set_bit(&current_settings, BTP_GAP_SETTINGS_PRIVACY);
1923-
#endif /* CONFIG_BT_PRIVACY */
1915+
if (IS_ENABLED(CONFIG_BT_PRIVACY)) {
1916+
atomic_set_bit(&current_settings, BTP_GAP_SETTINGS_PRIVACY);
1917+
}
19241918

19251919
bt_conn_cb_register(&conn_callbacks);
19261920
bt_conn_auth_info_cb_register(&auth_info_cb);

0 commit comments

Comments
 (0)