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.
This commit is contained in:
parent
2f13a960ac
commit
c2b37d95e0
@ -40,6 +40,7 @@ BLERemoteCharacteristic::BLERemoteCharacteristic(
|
|||||||
m_pRemoteService = pRemoteService;
|
m_pRemoteService = pRemoteService;
|
||||||
m_notifyCallback = nullptr;
|
m_notifyCallback = nullptr;
|
||||||
m_rawData = nullptr;
|
m_rawData = nullptr;
|
||||||
|
m_auth = ESP_GATT_AUTH_REQ_NONE;
|
||||||
|
|
||||||
retrieveDescriptors(); // Get the descriptors for this characteristic
|
retrieveDescriptors(); // Get the descriptors for this characteristic
|
||||||
log_v("<< BLERemoteCharacteristic");
|
log_v("<< BLERemoteCharacteristic");
|
||||||
@ -423,7 +424,7 @@ std::string BLERemoteCharacteristic::readValue() {
|
|||||||
m_pRemoteService->getClient()->getGattcIf(),
|
m_pRemoteService->getClient()->getGattcIf(),
|
||||||
m_pRemoteService->getClient()->getConnId(), // The connection ID to the BLE server
|
m_pRemoteService->getClient()->getConnId(), // The connection ID to the BLE server
|
||||||
getHandle(), // The handle of this characteristic
|
getHandle(), // The handle of this characteristic
|
||||||
ESP_GATT_AUTH_REQ_NONE); // Security
|
m_auth); // Security
|
||||||
|
|
||||||
if (errRc != ESP_OK) {
|
if (errRc != ESP_OK) {
|
||||||
log_e("esp_ble_gattc_read_char: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
|
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
|
|||||||
length,
|
length,
|
||||||
data,
|
data,
|
||||||
response?ESP_GATT_WRITE_TYPE_RSP:ESP_GATT_WRITE_TYPE_NO_RSP,
|
response?ESP_GATT_WRITE_TYPE_RSP:ESP_GATT_WRITE_TYPE_NO_RSP,
|
||||||
ESP_GATT_AUTH_REQ_NONE
|
m_auth
|
||||||
);
|
);
|
||||||
|
|
||||||
if (errRc != ESP_OK) {
|
if (errRc != ESP_OK) {
|
||||||
@ -595,4 +596,12 @@ uint8_t* BLERemoteCharacteristic::readRawData() {
|
|||||||
return m_rawData;
|
return m_rawData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set authentication request type for characteristic
|
||||||
|
* @param [in] auth Authentication request type.
|
||||||
|
*/
|
||||||
|
void BLERemoteCharacteristic::setAuth(esp_gatt_auth_req_t auth) {
|
||||||
|
m_auth = auth;
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* CONFIG_BT_ENABLED */
|
#endif /* CONFIG_BT_ENABLED */
|
||||||
|
@ -52,6 +52,7 @@ public:
|
|||||||
void writeValue(uint8_t newValue, bool response = false);
|
void writeValue(uint8_t newValue, bool response = false);
|
||||||
std::string toString();
|
std::string toString();
|
||||||
uint8_t* readRawData();
|
uint8_t* readRawData();
|
||||||
|
void setAuth(esp_gatt_auth_req_t auth);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BLERemoteCharacteristic(uint16_t handle, BLEUUID uuid, esp_gatt_char_prop_t charProp, BLERemoteService* pRemoteService);
|
BLERemoteCharacteristic(uint16_t handle, BLEUUID uuid, esp_gatt_char_prop_t charProp, BLERemoteService* pRemoteService);
|
||||||
@ -69,6 +70,7 @@ private:
|
|||||||
// Private properties
|
// Private properties
|
||||||
BLEUUID m_uuid;
|
BLEUUID m_uuid;
|
||||||
esp_gatt_char_prop_t m_charProp;
|
esp_gatt_char_prop_t m_charProp;
|
||||||
|
esp_gatt_auth_req_t m_auth;
|
||||||
uint16_t m_handle;
|
uint16_t m_handle;
|
||||||
BLERemoteService* m_pRemoteService;
|
BLERemoteService* m_pRemoteService;
|
||||||
FreeRTOS::Semaphore m_semaphoreReadCharEvt = FreeRTOS::Semaphore("ReadCharEvt");
|
FreeRTOS::Semaphore m_semaphoreReadCharEvt = FreeRTOS::Semaphore("ReadCharEvt");
|
||||||
|
@ -19,6 +19,7 @@ BLERemoteDescriptor::BLERemoteDescriptor(
|
|||||||
m_handle = handle;
|
m_handle = handle;
|
||||||
m_uuid = uuid;
|
m_uuid = uuid;
|
||||||
m_pRemoteCharacteristic = pRemoteCharacteristic;
|
m_pRemoteCharacteristic = pRemoteCharacteristic;
|
||||||
|
m_auth = ESP_GATT_AUTH_REQ_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -65,7 +66,7 @@ std::string BLERemoteDescriptor::readValue() {
|
|||||||
m_pRemoteCharacteristic->getRemoteService()->getClient()->getGattcIf(),
|
m_pRemoteCharacteristic->getRemoteService()->getClient()->getGattcIf(),
|
||||||
m_pRemoteCharacteristic->getRemoteService()->getClient()->getConnId(), // The connection ID to the BLE server
|
m_pRemoteCharacteristic->getRemoteService()->getClient()->getConnId(), // The connection ID to the BLE server
|
||||||
getHandle(), // The handle of this characteristic
|
getHandle(), // The handle of this characteristic
|
||||||
ESP_GATT_AUTH_REQ_NONE); // Security
|
m_auth); // Security
|
||||||
|
|
||||||
if (errRc != ESP_OK) {
|
if (errRc != ESP_OK) {
|
||||||
log_e("esp_ble_gattc_read_char: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
|
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
|
|||||||
length, // Data length
|
length, // Data length
|
||||||
data, // Data
|
data, // Data
|
||||||
response ? ESP_GATT_WRITE_TYPE_RSP : ESP_GATT_WRITE_TYPE_NO_RSP,
|
response ? ESP_GATT_WRITE_TYPE_RSP : ESP_GATT_WRITE_TYPE_NO_RSP,
|
||||||
ESP_GATT_AUTH_REQ_NONE
|
m_auth
|
||||||
);
|
);
|
||||||
if (errRc != ESP_OK) {
|
if (errRc != ESP_OK) {
|
||||||
log_e("esp_ble_gattc_write_char_descr: %d", errRc);
|
log_e("esp_ble_gattc_write_char_descr: %d", errRc);
|
||||||
@ -171,5 +172,12 @@ void BLERemoteDescriptor::writeValue(uint8_t newValue, bool response) {
|
|||||||
writeValue(&newValue, 1, response);
|
writeValue(&newValue, 1, response);
|
||||||
} // writeValue
|
} // writeValue
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set authentication request type for characteristic
|
||||||
|
* @param [in] auth Authentication request type.
|
||||||
|
*/
|
||||||
|
void BLERemoteDescriptor::setAuth(esp_gatt_auth_req_t auth) {
|
||||||
|
m_auth = auth;
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* CONFIG_BT_ENABLED */
|
#endif /* CONFIG_BT_ENABLED */
|
||||||
|
@ -34,6 +34,7 @@ public:
|
|||||||
void writeValue(uint8_t* data, size_t length, bool response = false);
|
void writeValue(uint8_t* data, size_t length, bool response = false);
|
||||||
void writeValue(std::string newValue, bool response = false);
|
void writeValue(std::string newValue, bool response = false);
|
||||||
void writeValue(uint8_t newValue, bool response = false);
|
void writeValue(uint8_t newValue, bool response = false);
|
||||||
|
void setAuth(esp_gatt_auth_req_t auth);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -48,6 +49,7 @@ private:
|
|||||||
std::string m_value; // Last received value of the descriptor.
|
std::string m_value; // Last received value of the descriptor.
|
||||||
BLERemoteCharacteristic* m_pRemoteCharacteristic; // Reference to the Remote characteristic of which this descriptor is associated.
|
BLERemoteCharacteristic* m_pRemoteCharacteristic; // Reference to the Remote characteristic of which this descriptor is associated.
|
||||||
FreeRTOS::Semaphore m_semaphoreReadDescrEvt = FreeRTOS::Semaphore("ReadDescrEvt");
|
FreeRTOS::Semaphore m_semaphoreReadDescrEvt = FreeRTOS::Semaphore("ReadDescrEvt");
|
||||||
|
esp_gatt_auth_req_t m_auth;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user