Skip to content

Commit c2b37d9

Browse files
cipherzme-no-dev
authored andcommitted
Updated BLERemoteCharacteristic to exposre esp_gatt_auth_req_t parame… (#3531)
* Updated BLERemoteCharacteristic to exposre esp_gatt_auth_req_t parameter for readValue and writeValue. * Updated BLERemoteCharacteristic/Descriptor to expose a setAuth method to allow tweaking the authentication request type for that remotecharacteristic/descriptor without the need to add auth on each read/write.
1 parent 2f13a96 commit c2b37d9

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

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

+11-2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ BLERemoteCharacteristic::BLERemoteCharacteristic(
4040
m_pRemoteService = pRemoteService;
4141
m_notifyCallback = nullptr;
4242
m_rawData = nullptr;
43+
m_auth = ESP_GATT_AUTH_REQ_NONE;
4344

4445
retrieveDescriptors(); // Get the descriptors for this characteristic
4546
log_v("<< BLERemoteCharacteristic");
@@ -423,7 +424,7 @@ std::string BLERemoteCharacteristic::readValue() {
423424
m_pRemoteService->getClient()->getGattcIf(),
424425
m_pRemoteService->getClient()->getConnId(), // The connection ID to the BLE server
425426
getHandle(), // The handle of this characteristic
426-
ESP_GATT_AUTH_REQ_NONE); // Security
427+
m_auth); // Security
427428

428429
if (errRc != ESP_OK) {
429430
log_e("esp_ble_gattc_read_char: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
@@ -574,7 +575,7 @@ void BLERemoteCharacteristic::writeValue(uint8_t* data, size_t length, bool resp
574575
length,
575576
data,
576577
response?ESP_GATT_WRITE_TYPE_RSP:ESP_GATT_WRITE_TYPE_NO_RSP,
577-
ESP_GATT_AUTH_REQ_NONE
578+
m_auth
578579
);
579580

580581
if (errRc != ESP_OK) {
@@ -595,4 +596,12 @@ uint8_t* BLERemoteCharacteristic::readRawData() {
595596
return m_rawData;
596597
}
597598

599+
/**
600+
* @brief Set authentication request type for characteristic
601+
* @param [in] auth Authentication request type.
602+
*/
603+
void BLERemoteCharacteristic::setAuth(esp_gatt_auth_req_t auth) {
604+
m_auth = auth;
605+
}
606+
598607
#endif /* CONFIG_BT_ENABLED */

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

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class BLERemoteCharacteristic {
5252
void writeValue(uint8_t newValue, bool response = false);
5353
std::string toString();
5454
uint8_t* readRawData();
55+
void setAuth(esp_gatt_auth_req_t auth);
5556

5657
private:
5758
BLERemoteCharacteristic(uint16_t handle, BLEUUID uuid, esp_gatt_char_prop_t charProp, BLERemoteService* pRemoteService);
@@ -69,6 +70,7 @@ class BLERemoteCharacteristic {
6970
// Private properties
7071
BLEUUID m_uuid;
7172
esp_gatt_char_prop_t m_charProp;
73+
esp_gatt_auth_req_t m_auth;
7274
uint16_t m_handle;
7375
BLERemoteService* m_pRemoteService;
7476
FreeRTOS::Semaphore m_semaphoreReadCharEvt = FreeRTOS::Semaphore("ReadCharEvt");

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

+10-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ BLERemoteDescriptor::BLERemoteDescriptor(
1919
m_handle = handle;
2020
m_uuid = uuid;
2121
m_pRemoteCharacteristic = pRemoteCharacteristic;
22+
m_auth = ESP_GATT_AUTH_REQ_NONE;
2223
}
2324

2425

@@ -65,7 +66,7 @@ std::string BLERemoteDescriptor::readValue() {
6566
m_pRemoteCharacteristic->getRemoteService()->getClient()->getGattcIf(),
6667
m_pRemoteCharacteristic->getRemoteService()->getClient()->getConnId(), // The connection ID to the BLE server
6768
getHandle(), // The handle of this characteristic
68-
ESP_GATT_AUTH_REQ_NONE); // Security
69+
m_auth); // Security
6970

7071
if (errRc != ESP_OK) {
7172
log_e("esp_ble_gattc_read_char: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
@@ -143,7 +144,7 @@ void BLERemoteDescriptor::writeValue(uint8_t* data, size_t length, bool response
143144
length, // Data length
144145
data, // Data
145146
response ? ESP_GATT_WRITE_TYPE_RSP : ESP_GATT_WRITE_TYPE_NO_RSP,
146-
ESP_GATT_AUTH_REQ_NONE
147+
m_auth
147148
);
148149
if (errRc != ESP_OK) {
149150
log_e("esp_ble_gattc_write_char_descr: %d", errRc);
@@ -171,5 +172,12 @@ void BLERemoteDescriptor::writeValue(uint8_t newValue, bool response) {
171172
writeValue(&newValue, 1, response);
172173
} // writeValue
173174

175+
/**
176+
* @brief Set authentication request type for characteristic
177+
* @param [in] auth Authentication request type.
178+
*/
179+
void BLERemoteDescriptor::setAuth(esp_gatt_auth_req_t auth) {
180+
m_auth = auth;
181+
}
174182

175183
#endif /* CONFIG_BT_ENABLED */

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

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class BLERemoteDescriptor {
3434
void writeValue(uint8_t* data, size_t length, bool response = false);
3535
void writeValue(std::string newValue, bool response = false);
3636
void writeValue(uint8_t newValue, bool response = false);
37+
void setAuth(esp_gatt_auth_req_t auth);
3738

3839

3940
private:
@@ -48,6 +49,7 @@ class BLERemoteDescriptor {
4849
std::string m_value; // Last received value of the descriptor.
4950
BLERemoteCharacteristic* m_pRemoteCharacteristic; // Reference to the Remote characteristic of which this descriptor is associated.
5051
FreeRTOS::Semaphore m_semaphoreReadDescrEvt = FreeRTOS::Semaphore("ReadDescrEvt");
52+
esp_gatt_auth_req_t m_auth;
5153

5254

5355
};

0 commit comments

Comments
 (0)