summaryrefslogtreecommitdiff
path: root/sensor/patchedBLE/src/BLESecurity.cpp
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2018-08-03 12:23:17 +0100
committerdakkar <dakkar@thenautilus.net>2018-08-03 12:23:17 +0100
commitbb00c2da73b6ab8837f50c9f889ee151f8abc036 (patch)
tree3922eb826386260568ccaa1da7056c141f752a97 /sensor/patchedBLE/src/BLESecurity.cpp
parentdon't print from callback, there's races (diff)
parentUpload of 0.4.16 (diff)
downloadthermostat-bb00c2da73b6ab8837f50c9f889ee151f8abc036.tar.gz
thermostat-bb00c2da73b6ab8837f50c9f889ee151f8abc036.tar.bz2
thermostat-bb00c2da73b6ab8837f50c9f889ee151f8abc036.zip
Add 'sensor/patchedBLE/' from commit '7951347ed68313d75c367e1f2cce763cb56d1eb2'
git-subtree-dir: sensor/patchedBLE git-subtree-mainline: 27e209cf58abeda1dc110777f99a98804a13fdbf git-subtree-split: 7951347ed68313d75c367e1f2cce763cb56d1eb2
Diffstat (limited to 'sensor/patchedBLE/src/BLESecurity.cpp')
-rw-r--r--sensor/patchedBLE/src/BLESecurity.cpp105
1 files changed, 105 insertions, 0 deletions
diff --git a/sensor/patchedBLE/src/BLESecurity.cpp b/sensor/patchedBLE/src/BLESecurity.cpp
new file mode 100644
index 0000000..4cf964a
--- /dev/null
+++ b/sensor/patchedBLE/src/BLESecurity.cpp
@@ -0,0 +1,105 @@
+/*
+ * BLESecurity.cpp
+ *
+ * Created on: Dec 17, 2017
+ * Author: chegewara
+ */
+
+#include <BLESecurity.h>
+#include "sdkconfig.h"
+#if defined(CONFIG_BT_ENABLED)
+
+BLESecurity::BLESecurity() {
+}
+
+BLESecurity::~BLESecurity() {
+}
+/*
+ * @brief Set requested authentication mode
+ */
+void BLESecurity::setAuthenticationMode(esp_ble_auth_req_t auth_req) {
+ m_authReq = auth_req;
+ esp_ble_gap_set_security_param(ESP_BLE_SM_AUTHEN_REQ_MODE, &m_authReq, sizeof(uint8_t)); // <--- setup requested authentication mode
+}
+
+/**
+ * @brief Set our device IO capability to let end user perform authorization
+ * either by displaying or entering generated 6-digits pin code
+ */
+void BLESecurity::setCapability(esp_ble_io_cap_t iocap) {
+ m_iocap = iocap;
+ esp_ble_gap_set_security_param(ESP_BLE_SM_IOCAP_MODE, &iocap, sizeof(uint8_t));
+} // setCapability
+
+
+/**
+ * @brief Init encryption key by server
+ * @param key_size is value between 7 and 16
+ */
+void BLESecurity::setInitEncryptionKey(uint8_t init_key) {
+ m_initKey = init_key;
+ esp_ble_gap_set_security_param(ESP_BLE_SM_SET_INIT_KEY, &m_initKey, sizeof(uint8_t));
+} // setInitEncryptionKey
+
+
+/**
+ * @brief Init encryption key by client
+ * @param key_size is value between 7 and 16
+ */
+void BLESecurity::setRespEncryptionKey(uint8_t resp_key) {
+ m_respKey = resp_key;
+ esp_ble_gap_set_security_param(ESP_BLE_SM_SET_RSP_KEY, &m_respKey, sizeof(uint8_t));
+} // setRespEncryptionKey
+
+
+/**
+ *
+ *
+ */
+void BLESecurity::setKeySize(uint8_t key_size) {
+ m_keySize = key_size;
+ esp_ble_gap_set_security_param(ESP_BLE_SM_MAX_KEY_SIZE, &m_keySize, sizeof(uint8_t));
+} //setKeySize
+
+
+/**
+ * @brief Debug function to display what keys are exchanged by peers
+ */
+char* BLESecurity::esp_key_type_to_str(esp_ble_key_type_t key_type)
+{
+ char* key_str = nullptr;
+ switch(key_type) {
+ case ESP_LE_KEY_NONE:
+ key_str = (char*)"ESP_LE_KEY_NONE";
+ break;
+ case ESP_LE_KEY_PENC:
+ key_str = (char*)"ESP_LE_KEY_PENC";
+ break;
+ case ESP_LE_KEY_PID:
+ key_str = (char*)"ESP_LE_KEY_PID";
+ break;
+ case ESP_LE_KEY_PCSRK:
+ key_str = (char*)"ESP_LE_KEY_PCSRK";
+ break;
+ case ESP_LE_KEY_PLK:
+ key_str = (char*)"ESP_LE_KEY_PLK";
+ break;
+ case ESP_LE_KEY_LLK:
+ key_str = (char*)"ESP_LE_KEY_LLK";
+ break;
+ case ESP_LE_KEY_LENC:
+ key_str = (char*)"ESP_LE_KEY_LENC";
+ break;
+ case ESP_LE_KEY_LID:
+ key_str = (char*)"ESP_LE_KEY_LID";
+ break;
+ case ESP_LE_KEY_LCSRK:
+ key_str = (char*)"ESP_LE_KEY_LCSRK";
+ break;
+ default:
+ key_str = (char*)"INVALID BLE KEY TYPE";
+ break;
+ }
+ return key_str;
+} // esp_key_type_to_str
+#endif // CONFIG_BT_ENABLED