8000 Fixes for #335 · ViaMonkey/esp32-snippets@82ba6d7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 82ba6d7

Browse files
committed
Fixes for nkolban#335
1 parent 5afeced commit 82ba6d7

File tree

6 files changed

+80
-51
lines changed

6 files changed

+80
-51
lines changed

cpp_utils/BLEDevice.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,10 @@ uint16_t BLEDevice::m_localMTU = 23;
142142
switch(event) {
143143
case ESP_GATTC_CONNECT_EVT: {
144144
if(BLEDevice::getMTU() != 23){
145-
esp_err_t err = esp_ble_gattc_send_mtu_req(gattc_if, param->connect.conn_id);
145+
esp_err_t errRc = esp_ble_gattc_send_mtu_req(gattc_if, param->connect.conn_id);
146+
if (errRc != ESP_OK) {
147+
ESP_LOGE(LOG_TAG, "esp_ble_gattc_send_mtu_req: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
148+
}
146149
}
147150
if(BLEDevice::m_securityLevel){
148151
esp_ble_set_encryption(param->connect.remote_bda, BLEDevice::m_securityLevel);

cpp_utils/BLEHIDDevice.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
* Created on: Dec 18, 2017
55
* Author: chegewara
66
*/
7+
8+
#include "sdkconfig.h"
9+
#if defined(CONFIG_BT_ENABLED)
10+
711
//#include "BLEUUID.h"
812
#include "BLEHIDDevice.h"
913

@@ -152,3 +156,5 @@ BLEDescriptor* BLEHIDDevice::featureReport() {
152156
BLEDescriptor* BLEHIDDevice::batteryLevel() {
153157
return m_batteryLevelDescriptor;
154158
}
159+
160+
#endif // CONFIG_BT_ENABLED

cpp_utils/BLEHIDDevice.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88
#ifndef _BLEHIDDEVICE_H_
99
#define _BLEHIDDEVICE_H_
10+
11+
#include "sdkconfig.h"
12+
#if defined(CONFIG_BT_ENABLED)
13+
1014
#include "BLECharacteristic.h"
1115
#include "BLEService.h"
1216
#include "BLEDescriptor.h"
@@ -83,5 +87,5 @@ class BLEHIDDevice {
8387
BLE2902* m_batteryLevelNotifications; //0x2902
8488

8589
};
86-
90+
#endif // CONFIG_BT_ENABLED
8791
#endif /* _BLEHIDDEVICE_H_ */

cpp_utils/BLESecurity.cpp

Lines changed: 49 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
*/
77

88
#include <BLESecurity.h>
9+
#include "sdkconfig.h"
10+
#if defined(CONFIG_BT_ENABLED)
911

1012
BLESecurity::BLESecurity() {
1113
}
@@ -19,79 +21,85 @@ void BLESecurity::setAuthenticationMode(esp_ble_auth_req_t auth_req) {
1921
m_authReq = auth_req;
2022
esp_ble_gap_set_security_param(ESP_BLE_SM_AUTHEN_REQ_MODE, &m_authReq, sizeof(uint8_t)); // <--- setup requested authentication mode
2123
}
22-
/*
24+
25+
/**
2326
* @brief Set our device IO capability to let end user perform authorization
2427
* either by displaying or entering generated 6-digits pin code
2528
*/
2629
void BLESecurity::setCapability(esp_ble_io_cap_t iocap) {
2730
m_iocap = iocap;
2831
esp_ble_gap_set_security_param(ESP_BLE_SM_IOCAP_MODE, &iocap, sizeof(uint8_t));
29-
}
30-
/*
32+
} // setCapability
33+
34+
35+
/**
3136
* @brief Init encryption key by server
3237
* @param key_size is value between 7 and 16
3338
*/
3439
void BLESecurity::setInitEncryptionKey(uint8_t init_key) {
3540
m_initKey = init_key;
3641
esp_ble_gap_set_security_param(ESP_BLE_SM_SET_INIT_KEY, &m_initKey, sizeof(uint8_t));
37-
}
42+
} // setInitEncryptionKey
3843

39-
/*
44+
45+
/**
4046
* @brief Init encryption key by client
4147
* @param key_size is value between 7 and 16
4248
*/
4349
void BLESecurity::setRespEncryptionKey(uint8_t resp_key) {
4450
m_respKey = resp_key;
4551
esp_ble_gap_set_security_param(ESP_BLE_SM_SET_RSP_KEY, &m_respKey, sizeof(uint8_t));
46-
}
52+
} // setRespEncryptionKey
4753

48-
/*
54+
55+
/**
4956
*
5057
*
5158
*/
5259
void BLESecurity::setKeySize(uint8_t key_size) {
5360
m_keySize = key_size;
5461
esp_ble_gap_set_security_param(ESP_BLE_SM_MAX_KEY_SIZE, &m_keySize, sizeof(uint8_t));
55-
}
62+
} //setKeySize
5663

57-
/*
64+
65+
/**
5866
* @brief Debug function to display what keys are exchanged by peers
5967
*/
6068
char* BLESecurity::esp_key_type_to_str(esp_ble_key_type_t key_type)
6169
{
62-
char *key_str = NULL;
63-
switch(key_type) {
64-
case ESP_LE_KEY_NONE:
65-
key_str = (char*)"ESP_LE_KEY_NONE";
66-
break;
67-
case ESP_LE_KEY_PENC:
68-
key_str = (char*)"ESP_LE_KEY_PENC";
69-
break;
70-
case ESP_LE_KEY_PID:
71-
key_str = (char*)"ESP_LE_KEY_PID";
72-
break;
73-
case ESP_LE_KEY_PCSRK:
74-
key_str = (char*)"ESP_LE_KEY_PCSRK";
75-
break;
76-
case ESP_LE_KEY_PLK:
77-
key_str = (char*)"ESP_LE_KEY_PLK";
78-
break;
79-
case ESP_LE_KEY_LLK:
80-
key_str = (char*)"ESP_LE_KEY_LLK";
81-
break;
70+
char* key_str = nullptr;
71+
switch(key_type) {
72+
case ESP_LE_KEY_NONE:
73+
key_str = (char*)"ESP_LE_KEY_NONE";
74+
break;
75+
case ESP_LE_KEY_PENC:
76+
key_str = (char*)"ESP_LE_KEY_PENC";
77+
break;
78+
case ESP_LE_KEY_PID:
79+
key_str = (char*)"ESP_LE_KEY_PID";
80+
break;
81+
case ESP_LE_KEY_PCSRK:
82+
key_str = (char*)"ESP_LE_KEY_PCSRK";
83+
break;
84+
case ESP_LE_KEY_PLK:
85+
key_str = (char*)"ESP_LE_KEY_PLK";
86+
break;
87+
case ESP_LE_KEY_LLK:
88+
key_str = (char*)"ESP_LE_KEY_LLK";
89+
break;
8290
case ESP_LE_KEY_LENC:
83-
key_str = (char*)"ESP_LE_KEY_LENC";
84-
break;
91+
key_str = (char*)"ESP_LE_KEY_LENC";
92+
break;
8593
case ESP_LE_KEY_LID:
86-
key_str = (char*)"ESP_LE_KEY_LID";
87-
break;
94+
key_str = (char*)"ESP_LE_KEY_LID";
95+
break;
8896
case ESP_LE_KEY_LCSRK:
89-
key_str = (char*)"ESP_LE_KEY_LCSRK";
90-
break;
97+
key_str = (char*)"ESP_LE_KEY_LCSRK";
98+
break;
9199
default:
92-
key_str = (char*)"INVALID BLE KEY TYPE";
93-
break;
94-
95-
}
96-
return key_str;
97-
}
100+
key_str = (char*)"INVALID BLE KEY TYPE";
101+
break;
102+
}
103+
return key_str;
104+
} // esp_key_type_to_str
105+
#endif // CONFIG_BT_ENABLED

cpp_utils/BLESecurity.h

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
#ifndef COMPONENTS_CPP_UTILS_BLESECURITY_H_
99
#define COMPONENTS_CPP_UTILS_BLESECURITY_H_
10+
#include "sdkconfig.h"
11+
#if defined(CONFIG_BT_ENABLED)
12+
1013
#include <esp_gap_ble_api.h>
1114

1215
class BLESecurity {
@@ -26,7 +29,8 @@ class BLESecurity {
2629
uint8_t m_initKey;
2730
uint8_t m_respKey;
2831
uint8_t m_keySize;
29-
};
32+
}; // BLESecurity
33+
3034

3135
/*
3236
* @brief Callbacks to handle GAP events related to authorization
@@ -35,29 +39,33 @@ class BLESecurityCallbacks {
3539
public:
3640
virtual ~BLESecurityCallbacks() {};
3741

38-
/*
42+
/**
3943
* @brief Its request from peer device to input authentication pin code displayed on peer device.
4044
* It requires that our device is capable to input 6-digits code by end user
4145
* @return Return 6-digits integer value from input device
4246
*/
4347
virtual uint32_t onPassKeyRequest() = 0;
44-
/*
48+
49+
/**
4550
* @brief Provide us 6-digits code to perform authentication.
4651
* It requires that our device is capable to display this code to end user
4752
* @param
4853
*/
4954
virtual void onPassKeyNotify(uint32_t pass_key);
50-
/*
55+
56+
/**
5157
* @brief Here we can make decision if we want to let negotiate authorization with peer device or not
5258
* return Return true if we accept this peer device request
5359
*/
60+
5461
virtual bool onSecurityRequest();
55-
/*
62+
/**
5663
* Provide us information when authentication process is completed
5764
*/
5865
virtual void onAuthenticationComplete(esp_ble_auth_cmpl_t);
5966

6067
virtual bool onConfirmPIN(uint32_t pin);
61-
};
68+
}; // BLESecurityCallbacks
6269

63-
#endif /* COMPONENTS_CPP_UTILS_BLESECURITY_H_ */
70+
#endif // CONFIG_BT_ENABLED
71+
#endif // COMPONENTS_CPP_UTILS_BLESECURITY_H_

cpp_utils/Socket.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Socket Socket::accept() {
6363
struct sockaddr_in client_addr;
6464
socklen_t sin_size;
6565
int clientSockFD = ::lwip_accept_r(m_sock, (struct sockaddr *)&client_addr, &sin_size);
66-
printf("------> new connection client %s:%d\n", inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port));
66+
//printf("------> new connection client %s:%d\n", inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port));
6767
if (clientSockFD == -1) {
6868
SocketException se(errno);
6969
ESP_LOGE(LOG_TAG, "accept(): %s, m_sock=%d", strerror(errno), m_sock);

0 commit comments

Comments
 (0)
0