Skip to content

Add static pin support #4078

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions libraries/BLE/src/BLESecurity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ void BLESecurity::setKeySize(uint8_t key_size) {
esp_ble_gap_set_security_param(ESP_BLE_SM_MAX_KEY_SIZE, &m_keySize, sizeof(uint8_t));
} //setKeySize

/**
* Setup for static PIN connection, call it first and then call setAuthenticationMode eventually to change it
*/
void BLESecurity::setStaticPIN(uint32_t pin){
uint32_t passkey = pin;
esp_ble_gap_set_security_param(ESP_BLE_SM_SET_STATIC_PASSKEY, &passkey, sizeof(uint32_t));
setCapability(ESP_IO_CAP_OUT);
setKeySize();
setAuthenticationMode(ESP_LE_AUTH_REQ_SC_ONLY);
setInitEncryptionKey(ESP_BLE_ENC_KEY_MASK | ESP_BLE_ID_KEY_MASK);
}

/**
* @brief Debug function to display what keys are exchanged by peers
Expand Down
1 change: 1 addition & 0 deletions libraries/BLE/src/BLESecurity.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class BLESecurity {
void setInitEncryptionKey(uint8_t init_key);
void setRespEncryptionKey(uint8_t resp_key);
void setKeySize(uint8_t key_size = 16);
void setStaticPIN(uint32_t pin);
static char* esp_key_type_to_str(esp_ble_key_type_t key_type);

private:
Expand Down