MCPcopy Create free account
hub / github.com/Heltec-Aaron-Lee/WiFi_Kit_series / secureConnection

Method secureConnection

libraries/BLE/src/BLEClient.cpp:198–238  ·  view source on GitHub ↗

* @brief Initiate a secure connection (pair/bond) with the server.\n * Called automatically when a characteristic or descriptor requires encryption or authentication to access it. * @return True on success. */

Source from the content-addressed store, hash-verified

196 * @return True on success.
197 */
198bool BLEClient::secureConnection() {
199#if defined(CONFIG_BLUEDROID_ENABLED)
200 if (BLESecurity::m_authenticationComplete) {
201 return true;
202 }
203 if (!BLESecurity::m_securityEnabled) {
204 log_i("Security not enabled");
205 return true;
206 }
207 if (!BLESecurity::startSecurity(m_peerAddress.getNative())) {
208 log_e("Failed to start security");
209 return false;
210 }
211 BLESecurity::waitForAuthenticationComplete();
212 return BLESecurity::m_authenticationComplete;
213#endif
214
215#if defined(CONFIG_NIMBLE_ENABLED)
216 int retryCount = 1;
217 BLETaskData taskData(const_cast<BLEClient *>(this), BLE_HS_ENOTCONN);
218 m_pTaskData = &taskData;
219
220 do {
221 if (BLESecurity::startSecurity(m_conn_id)) {
222 BLEUtils::taskWait(taskData, BLE_NPL_TIME_FOREVER);
223 }
224
225 } while (taskData.m_flags == (BLE_HS_ERR_HCI_BASE + BLE_ERR_PINKEY_MISSING) && retryCount--);
226
227 m_pTaskData = nullptr;
228
229 if (taskData.m_flags == 0) {
230 log_d("<< secureConnection: success");
231 return true;
232 }
233
234 m_lastErr = taskData.m_flags;
235 log_e("secureConnection: failed rc=%d", taskData.m_flags);
236 return false;
237#endif
238} // secureConnection
239
240uint16_t BLEClient::getConnId() {
241 return m_conn_id;

Callers 4

readValueMethod · 0.80
writeValueMethod · 0.80
readValueMethod · 0.80
writeValueMethod · 0.80

Calls 1

getNativeMethod · 0.45

Tested by

no test coverage detected