Skip to content

Commit b7c5e50

Browse files
authored
Add static pin support (#4078)
1 parent fa8a1c3 commit b7c5e50

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

Diff for: libraries/BLE/src/BLESecurity.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@ void BLESecurity::setKeySize(uint8_t key_size) {
6161
esp_ble_gap_set_security_param(ESP_BLE_SM_MAX_KEY_SIZE, &m_keySize, sizeof(uint8_t));
6262
} //setKeySize
6363

64+
/**
65+
* Setup for static PIN connection, call it first and then call setAuthenticationMode eventually to change it
66+
*/
67+
void BLESecurity::setStaticPIN(uint32_t pin){
68+
uint32_t passkey = pin;
69+
esp_ble_gap_set_security_param(ESP_BLE_SM_SET_STATIC_PASSKEY, &passkey, sizeof(uint32_t));
70+
setCapability(ESP_IO_CAP_OUT);
71+
setKeySize();
72+
setAuthenticationMode(ESP_LE_AUTH_REQ_SC_ONLY);
73+
setInitEncryptionKey(ESP_BLE_ENC_KEY_MASK | ESP_BLE_ID_KEY_MASK);
74+
}
6475

6576
/**
6677
* @brief Debug function to display what keys are exchanged by peers

Diff for: libraries/BLE/src/BLESecurity.h

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class BLESecurity {
2121
void setInitEncryptionKey(uint8_t init_key);
2222
void setRespEncryptionKey(uint8_t resp_key);
2323
void setKeySize(uint8_t key_size = 16);
24+
void setStaticPIN(uint32_t pin);
2425
static char* esp_key_type_to_str(esp_ble_key_type_t key_type);
2526

2627
private:

0 commit comments

Comments
 (0)