Skip to content

Commit 7db429f

Browse files
authored
Merge pull request #1 from nkolban/master
Updating to latest version
2 parents d2f7e10 + 5222d21 commit 7db429f

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

cpp_utils/BLEDevice.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,11 @@ uint16_t BLEDevice::m_localMTU = 23;
9999
switch(event) {
100100
case ESP_GATTS_CONNECT_EVT: {
101101
BLEDevice::m_localMTU = 23;
102+
#ifdef CONFIG_BLE_SMP_ENABLE // Check that BLE SMP (security) is configured in make menuconfig
102103
if(BLEDevice::m_securityLevel){
103104
esp_ble_set_encryption(param->connect.remote_bda, BLEDevice::m_securityLevel);
104105
}
106+
#endif // CONFIG_BLE_SMP_ENABLE
105107
break;
106108
} // ESP_GATTS_CONNECT_EVT
107109

@@ -148,9 +150,11 @@ uint16_t BLEDevice::m_localMTU = 23;
148150
ESP_LOGE(LOG_TAG, "esp_ble_gattc_send_mtu_req: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
149151
}
150152
}
153+
#ifdef CONFIG_BLE_SMP_ENABLE // Check that BLE SMP (security) is configured in make menuconfig
151154
if(BLEDevice::m_securityLevel){
152155
esp_ble_set_encryption(param->connect.remote_bda, BLEDevice::m_securityLevel);
153156
}
157+
#endif // CONFIG_BLE_SMP_ENABLE
154158
break;
155159
} // ESP_GATTC_CONNECT_EVT
156160

@@ -190,16 +194,20 @@ uint16_t BLEDevice::m_localMTU = 23;
190194
break;
191195
case ESP_GAP_BLE_NC_REQ_EVT:
192196
ESP_LOGI(LOG_TAG, "ESP_GAP_BLE_NC_REQ_EVT");
197+
#ifdef CONFIG_BLE_SMP_ENABLE // Check that BLE SMP (security) is configured in make menuconfig
193198
if(BLEDevice::m_securityCallbacks!=nullptr){
194199
esp_ble_confirm_reply(param->ble_security.ble_req.bd_addr, BLEDevice::m_securityCallbacks->onConfirmPIN(param->ble_security.key_notif.passkey));
195200
}
201+
#endif // CONFIG_BLE_SMP_ENABLE
196202
break;
197203
case ESP_GAP_BLE_PASSKEY_REQ_EVT: /* passkey request event */
198204
ESP_LOGI(LOG_TAG, "ESP_GAP_BLE_PASSKEY_REQ_EVT: ");
199205
// esp_log_buffer_hex(LOG_TAG, m_remote_bda, sizeof(m_remote_bda));
206+
#ifdef CONFIG_BLE_SMP_ENABLE // Check that BLE SMP (security) is configured in make menuconfig
200207
if(BLEDevice::m_securityCallbacks!=nullptr){
201208
esp_ble_passkey_reply(param->ble_security.ble_req.bd_addr, true, BLEDevice::m_securityCallbacks->onPassKeyRequest());
202209
}
210+
#endif // CONFIG_BLE_SMP_ENABLE
203211
break;
204212
/*
205213
* TODO should we add white/black list comparison?
@@ -208,32 +216,42 @@ uint16_t BLEDevice::m_localMTU = 23;
208216
/* send the positive(true) security response to the peer device to accept the security request.
209217
If not accept the security request, should sent the security response with negative(false) accept value*/
210218
ESP_LOGI(LOG_TAG, "ESP_GAP_BLE_SEC_REQ_EVT");
219+
#ifdef CONFIG_BLE_SMP_ENABLE // Check that BLE SMP (security) is configured in make menuconfig
211220
if(BLEDevice::m_securityCallbacks!=nullptr){
212221
esp_ble_gap_security_rsp(param->ble_security.ble_req.bd_addr, BLEDevice::m_securityCallbacks->onSecurityRequest());
213222
}
214223
else{
215224
esp_ble_gap_security_rsp(param->ble_security.ble_req.bd_addr, true);
216225
}
226+
#endif // CONFIG_BLE_SMP_ENABLE
217227
break;
218228
/*
219229
*
220230
*/
221231
case ESP_GAP_BLE_PASSKEY_NOTIF_EVT: ///the app will receive this evt when the IO has Output capability and the peer device IO has Input capability.
222232
///show the passkey number to the user to input it in the peer deivce.
223233
ESP_LOGI(LOG_TAG, "ESP_GAP_BLE_PASSKEY_NOTIF_EVT");
234+
#ifdef CONFIG_BLE_SMP_ENABLE // Check that BLE SMP (security) is configured in make menuconfig
224235
if(BLEDevice::m_securityCallbacks!=nullptr){
225236
ESP_LOGI(LOG_TAG, "passKey = %d", param->ble_security.key_notif.passkey);
226237
BLEDevice::m_securityCallbacks->onPassKeyNotify(param->ble_security.key_notif.passkey);
227238
}
239+
#endif // CONFIG_BLE_SMP_ENABLE
228240
break;
229241
case ESP_GAP_BLE_KEY_EVT:
230242
//shows the ble key type info share with peer device to the user.
243+
ESP_LOGI(LOG_TAG, "ESP_GAP_BLE_KEY_EVT");
244+
#ifdef CONFIG_BLE_SMP_ENABLE // Check that BLE SMP (security) is configured in make menuconfig
231245
ESP_LOGI(LOG_TAG, "key type = %s", BLESecurity::esp_key_type_to_str(param->ble_security.ble_key.key_type));
246+
#endif // CONFIG_BLE_SMP_ENABLE
232247
break;
233248
case ESP_GAP_BLE_AUTH_CMPL_EVT:
249+
ESP_LOGI(LOG_TAG, "ESP_GAP_BLE_AUTH_CMPL_EVT");
250+
#ifdef CONFIG_BLE_SMP_ENABLE // Check that BLE SMP (security) is configured in make menuconfig
234251
if(BLEDevice::m_securityCallbacks!=nullptr){
235252
BLEDevice::m_securityCallbacks->onAuthenticationComplete(param->ble_security.auth_cmpl);
236253
}
254+
#endif // CONFIG_BLE_SMP_ENABLE
237255
break;
238256
default: {
239257
break;
@@ -382,12 +400,14 @@ uint16_t BLEDevice::m_localMTU = 23;
382400
return;
383401
};
384402

403+
#ifdef CONFIG_BLE_SMP_ENABLE // Check that BLE SMP (security) is configured in make menuconfig
385404
esp_ble_io_cap_t iocap = ESP_IO_CAP_NONE;
386405
errRc = ::esp_ble_gap_set_security_param(ESP_BLE_SM_IOCAP_MODE, &iocap, sizeof(uint8_t));
387406
if (errRc != ESP_OK) {
388407
ESP_LOGE(LOG_TAG, "esp_ble_gap_set_security_param: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
389408
return;
390409
};
410+
#endif // CONFIG_BLE_SMP_ENABLE
391411
}
392412
vTaskDelay(200/portTICK_PERIOD_MS); // Delay for 200 msecs as a workaround to an apparent Arduino environment issue.
393413
} // init

cpp_utils/BLEService.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ void BLEService::addCharacteristic(BLECharacteristic* pCharacteristic) {
192192

193193
// Check that we don't add the same characteristic twice.
194194
if (m_characteristicMap.getByUUID(pCharacteristic->getUUID()) != nullptr) {
195-
ESP_LOGE(LOG_TAG, "<< Attempt to add a characteristic but we already have one with this UUID");
195+
ESP_LOGW(LOG_TAG, "<< Adding a new characteristic with the same UUID as a previous one");
196196
//return;
197197
}
198198

0 commit comments

Comments
 (0)