Skip to content

Commit b0d5182

Browse files
committed
feat: align with repo example
1 parent 5c324e1 commit b0d5182

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

pgpemu-esp32/main/pgp_bluetooth.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ static const uint16_t ESP_APP_ID = 0x55;
2121
static uint8_t mac[6];
2222
uint8_t bt_mac[6];
2323

24-
// inspired by https://github.com/espressif/esp-idf/blob/master/examples/bluetooth/bluedroid/ble/gatt_security_server/main/example_ble_sec_gatts_demo.c
24+
// inspired by
25+
// https://github.com/espressif/esp-idf/blob/master/examples/bluetooth/bluedroid/ble/gatt_security_server/main/example_ble_sec_gatts_demo.c
2526
bool init_bluetooth() {
2627
init_handshake_multi();
2728

@@ -48,15 +49,16 @@ bool init_bluetooth() {
4849
return false;
4950
}
5051

51-
ret = esp_bluedroid_init();
52+
esp_bluedroid_config_t cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT();
53+
ret = esp_bluedroid_init_with_cfg(&cfg);
5254
if (ret) {
53-
ESP_LOGE(BT_TAG, "%s init bluetooth failed: %s", __func__, esp_err_to_name(ret));
55+
ESP_LOGE(BT_TAG, "%s init bluedroid failed: %s", __func__, esp_err_to_name(ret));
5456
return false;
5557
}
5658

5759
ret = esp_bluedroid_enable();
5860
if (ret) {
59-
ESP_LOGE(BT_TAG, "%s enable bluetooth failed: %s", __func__, esp_err_to_name(ret));
61+
ESP_LOGE(BT_TAG, "%s enable bluedroid failed: %s", __func__, esp_err_to_name(ret));
6062
return false;
6163
}
6264

@@ -82,15 +84,20 @@ bool init_bluetooth() {
8284
* stack*/
8385
esp_ble_auth_req_t auth_req = ESP_LE_AUTH_BOND;
8486
esp_ble_io_cap_t iocap = ESP_IO_CAP_IO;
85-
uint8_t key_size = 16;
87+
uint8_t key_size = 16; // the key size should be 7~16 bytes
8688
uint8_t init_key = ESP_BLE_ENC_KEY_MASK | ESP_BLE_ID_KEY_MASK;
8789
uint8_t rsp_key = ESP_BLE_ENC_KEY_MASK | ESP_BLE_ID_KEY_MASK;
88-
//set static passkey
90+
// set static passkey
8991
uint32_t passkey = 197666;
92+
uint8_t auth_option = ESP_BLE_ONLY_ACCEPT_SPECIFIED_AUTH_DISABLE;
93+
uint8_t oob_support = ESP_BLE_OOB_DISABLE;
9094
esp_ble_gap_set_security_param(ESP_BLE_SM_SET_STATIC_PASSKEY, &passkey, sizeof(uint32_t));
9195
esp_ble_gap_set_security_param(ESP_BLE_SM_AUTHEN_REQ_MODE, &auth_req, sizeof(uint8_t));
9296
esp_ble_gap_set_security_param(ESP_BLE_SM_IOCAP_MODE, &iocap, sizeof(uint8_t));
9397
esp_ble_gap_set_security_param(ESP_BLE_SM_MAX_KEY_SIZE, &key_size, sizeof(uint8_t));
98+
esp_ble_gap_set_security_param(
99+
ESP_BLE_SM_ONLY_ACCEPT_SPECIFIED_SEC_AUTH, &auth_option, sizeof(uint8_t));
100+
esp_ble_gap_set_security_param(ESP_BLE_SM_OOB_SUPPORT, &oob_support, sizeof(uint8_t));
94101
/* If your BLE device act as a Slave, the init_key means you hope which types of key of the
95102
master should distribut to you, and the response key means which key you can distribut to the
96103
Master; If your BLE device act as a master, the response key means you hope which types of key

pgpemu-esp32/main/pgp_gap.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t* par
8080
ESP_LOGI(BT_GAP_TAG, "Passkey requested");
8181
break;
8282
case ESP_GAP_BLE_PASSKEY_NOTIF_EVT:
83-
ESP_LOGI(BT_GAP_TAG, "Passkey notify with code %06" PRIu32, param->ble_security.key_notif.passkey);
83+
ESP_LOGI(BT_GAP_TAG,
84+
"Passkey notify with code %06" PRIu32,
85+
param->ble_security.key_notif.passkey);
8486
break;
8587
case ESP_GAP_BLE_SEC_REQ_EVT:
8688
ESP_LOGI(BT_GAP_TAG, "Security request received, accepting");

pgpemu-esp32/main/pgp_handshake_multi.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,9 @@ void dump_client_states() {
183183
}
184184

185185

186-
// align with https://github.com/espressif/esp-idf/blob/master/examples/bluetooth/bluedroid/ble/gatt_security_server/main/example_ble_sec_gatts_demo.c instead
186+
// align with
187+
// https://github.com/espressif/esp-idf/blob/master/examples/bluetooth/bluedroid/ble/gatt_security_server/main/example_ble_sec_gatts_demo.c
188+
// instead
187189
void reset_client_states() {
188190
ESP_LOGI(HANDSHAKE_TAG, "active_connections: %d", active_connections);
189191
for (int i = 0; i < MAX_CONNECTIONS; i++) {

0 commit comments

Comments
 (0)