Skip to content

Commit d42294d

Browse files
lylezhu2012kartben
authored andcommitted
Bluetooth: SMP_BR: Use macros instead of hard code
Define macros for encryption value, #define BT_HCI_ENCRYPTION_OFF 0x00 #define BT_HCI_ENCRYPTION_ON_LE_AES_CCM 0x01 #define BT_HCI_ENCRYPTION_ON_BR_E0 0x01 #define BT_HCI_ENCRYPTION_ON_BR_AES_CCM 0x02 Use the macros to replace the hard code. Signed-off-by: Lyle Zhu <[email protected]>
1 parent af86a35 commit d42294d

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

include/zephyr/bluetooth/hci_types.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2804,6 +2804,12 @@ struct bt_hci_evt_remote_name_req_complete {
28042804
uint8_t name[248];
28052805
} __packed;
28062806

2807+
/* Encryption Value */
2808+
#define BT_HCI_ENCRYPTION_OFF 0x00
2809+
#define BT_HCI_ENCRYPTION_ON_LE_AES_CCM 0x01
2810+
#define BT_HCI_ENCRYPTION_ON_BR_E0 0x01
2811+
#define BT_HCI_ENCRYPTION_ON_BR_AES_CCM 0x02
2812+
28072813
#define BT_HCI_EVT_ENCRYPT_CHANGE 0x08
28082814
struct bt_hci_evt_encrypt_change {
28092815
uint8_t status;

subsys/bluetooth/host/classic/br.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ bool bt_br_update_sec_level(struct bt_conn *conn)
155155

156156
if (conn->br.link_key) {
157157
if (conn->br.link_key->flags & BT_LINK_KEY_AUTHENTICATED) {
158-
if (conn->encrypt == 0x02) {
158+
if (conn->encrypt == BT_HCI_ENCRYPTION_ON_BR_AES_CCM) {
159159
conn->sec_level = BT_SECURITY_L4;
160160
} else {
161161
conn->sec_level = BT_SECURITY_L3;

subsys/bluetooth/host/smp.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,8 @@ static void smp_br_derive_ltk(struct bt_smp_br *smp)
958958
return;
959959
}
960960

961-
if (IS_ENABLED(CONFIG_BT_SMP_FORCE_BREDR) && conn->encrypt != 0x02) {
961+
if (IS_ENABLED(CONFIG_BT_SMP_FORCE_BREDR) &&
962+
conn->encrypt != BT_HCI_ENCRYPTION_ON_BR_AES_CCM) {
962963
LOG_WRN("Using P192 Link Key for P256 LTK derivation");
963964
}
964965

@@ -1164,11 +1165,11 @@ static bool smp_br_pairing_allowed(struct bt_smp_br *smp)
11641165
return false;
11651166
}
11661167

1167-
if (conn->encrypt == 0x02) {
1168+
if (conn->encrypt == BT_HCI_ENCRYPTION_ON_BR_AES_CCM) {
11681169
return true;
11691170
}
11701171

1171-
if (IS_ENABLED(CONFIG_BT_SMP_FORCE_BREDR) && conn->encrypt == 0x01) {
1172+
if (IS_ENABLED(CONFIG_BT_SMP_FORCE_BREDR) && conn->encrypt == BT_HCI_ENCRYPTION_ON_BR_E0) {
11721173
LOG_WRN("Allowing BR/EDR SMP with P-192 key");
11731174
return true;
11741175
}

0 commit comments

Comments
 (0)