Skip to content

Updated BLERemoteCharacteristic to exposre esp_gatt_auth_req_t parame… #3531

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 3 commits into from
Jan 20, 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
13 changes: 11 additions & 2 deletions libraries/BLE/src/BLERemoteCharacteristic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ BLERemoteCharacteristic::BLERemoteCharacteristic(
m_pRemoteService = pRemoteService;
m_notifyCallback = nullptr;
m_rawData = nullptr;
m_auth = ESP_GATT_AUTH_REQ_NONE;

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

if (errRc != ESP_OK) {
log_e("esp_ble_gattc_read_char: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
Expand Down Expand Up @@ -574,7 +575,7 @@ void BLERemoteCharacteristic::writeValue(uint8_t* data, size_t length, bool resp
length,
data,
response?ESP_GATT_WRITE_TYPE_RSP:ESP_GATT_WRITE_TYPE_NO_RSP,
ESP_GATT_AUTH_REQ_NONE
m_auth
);

if (errRc != ESP_OK) {
Expand All @@ -595,4 +596,12 @@ uint8_t* BLERemoteCharacteristic::readRawData() {
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 */
2 changes: 2 additions & 0 deletions libraries/BLE/src/BLERemoteCharacteristic.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class BLERemoteCharacteristic {
void writeValue(uint8_t newValue, bool response = false);
std::string toString();
uint8_t* readRawData();
void setAuth(esp_gatt_auth_req_t auth);

private:
BLERemoteCharacteristic(uint16_t handle, BLEUUID uuid, esp_gatt_char_prop_t charProp, BLERemoteService* pRemoteService);
Expand All @@ -69,6 +70,7 @@ class BLERemoteCharacteristic {
// Private properties
BLEUUID m_uuid;
esp_gatt_char_prop_t m_charProp;
esp_gatt_auth_req_t m_auth;
uint16_t m_handle;
BLERemoteService* m_pRemoteService;
FreeRTOS::Semaphore m_semaphoreReadCharEvt = FreeRTOS::Semaphore("ReadCharEvt");
Expand Down
12 changes: 10 additions & 2 deletions libraries/BLE/src/BLERemoteDescriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ BLERemoteDescriptor::BLERemoteDescriptor(
m_handle = handle;
m_uuid = uuid;
m_pRemoteCharacteristic = pRemoteCharacteristic;
m_auth = ESP_GATT_AUTH_REQ_NONE;
}


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

if (errRc != ESP_OK) {
log_e("esp_ble_gattc_read_char: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
Expand Down Expand Up @@ -143,7 +144,7 @@ void BLERemoteDescriptor::writeValue(uint8_t* data, size_t length, bool response
length, // Data length
data, // Data
response ? ESP_GATT_WRITE_TYPE_RSP : ESP_GATT_WRITE_TYPE_NO_RSP,
ESP_GATT_AUTH_REQ_NONE
m_auth
);
if (errRc != ESP_OK) {
log_e("esp_ble_gattc_write_char_descr: %d", errRc);
Expand Down Expand Up @@ -171,5 +172,12 @@ void BLERemoteDescriptor::writeValue(uint8_t newValue, bool response) {
writeValue(&newValue, 1, response);
} // 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 */
2 changes: 2 additions & 0 deletions libraries/BLE/src/BLERemoteDescriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class BLERemoteDescriptor {
void writeValue(uint8_t* data, size_t length, bool response = false);
void writeValue(std::string newValue, bool response = false);
void writeValue(uint8_t newValue, bool response = false);
void setAuth(esp_gatt_auth_req_t auth);


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


};
Expand Down