fix using an invalid cccd index

pull/8318/head
paul-szczepanek-arm 2018-10-03 16:16:41 +01:00
parent 8b623156e5
commit 366a5018b5
2 changed files with 11 additions and 11 deletions

View File

@ -222,8 +222,8 @@ private:
void add_generic_attribute_service();
void* alloc_block(size_t block_size);
GattCharacteristic* get_auth_char(uint16_t value_handle);
bool get_cccd_id(GattAttribute::Handle_t cccd_handle, uint8_t& idx) const;
bool has_cccd(GattAttribute::Handle_t char_handle) const;
bool get_cccd_index_by_cccd_handle(GattAttribute::Handle_t cccd_handle, uint8_t& idx) const;
bool get_cccd_index_by_value_handle(GattAttribute::Handle_t char_handle, uint8_t& idx) const;
bool is_update_authorized(Gap::Handle_t connection, GattAttribute::Handle_t value_handle);
struct alloc_block_t {

View File

@ -560,7 +560,7 @@ ble_error_t GattServer::read(
) {
// Check to see if this is a CCCD
uint8_t cccd_index;
if (get_cccd_id(att_handle, cccd_index)) {
if (get_cccd_index_by_cccd_handle(att_handle, cccd_index)) {
if (connection == DM_CONN_ID_NONE) {
return BLE_ERROR_PARAM_OUT_OF_RANGE;
}
@ -588,7 +588,7 @@ ble_error_t GattServer::write(
// Check to see if this is a CCCD, if it is the case update the value for all
// connections
uint8_t cccd_index;
if (get_cccd_id(att_handle, cccd_index)) {
if (get_cccd_index_by_cccd_handle(att_handle, cccd_index)) {
if (len != sizeof(uint16_t)) {
return BLE_ERROR_INVALID_PARAM;
}
@ -615,7 +615,7 @@ ble_error_t GattServer::write(
}
// return if the update does not have to be propagated to peers
if (local_only || !has_cccd(att_handle)) {
if (local_only || !get_cccd_index_by_value_handle(att_handle, cccd_index)) {
return BLE_ERROR_NONE;
}
@ -660,7 +660,7 @@ ble_error_t GattServer::write(
) {
// Check to see if this is a CCCD
uint8_t cccd_index;
if (get_cccd_id(att_handle, cccd_index)) {
if (get_cccd_index_by_cccd_handle(att_handle, cccd_index)) {
if ((connection == DM_CONN_ID_NONE) || (len != 2)) { // CCCDs are always 16 bits
return BLE_ERROR_PARAM_OUT_OF_RANGE;
}
@ -677,7 +677,7 @@ ble_error_t GattServer::write(
}
// return if the update does not have to be propagated to peers
if (local_only || !has_cccd(att_handle)) {
if (local_only || !get_cccd_index_by_value_handle(att_handle, cccd_index)) {
return BLE_ERROR_NONE;
}
@ -1211,7 +1211,7 @@ GattCharacteristic* GattServer::get_auth_char(uint16_t value_handle)
return NULL;
}
bool GattServer::get_cccd_id(GattAttribute::Handle_t cccd_handle, uint8_t& idx) const
bool GattServer::get_cccd_index_by_cccd_handle(GattAttribute::Handle_t cccd_handle, uint8_t& idx) const
{
for (idx = 0; idx < cccd_cnt; idx++) {
if (cccd_handle == cccds[idx].handle) {
@ -1221,10 +1221,10 @@ bool GattServer::get_cccd_id(GattAttribute::Handle_t cccd_handle, uint8_t& idx)
return false;
}
bool GattServer::has_cccd(GattAttribute::Handle_t char_handle) const
bool GattServer::get_cccd_index_by_value_handle(GattAttribute::Handle_t char_handle, uint8_t& idx) const
{
for (uint8_t cccd_index = 0; cccd_index < cccd_cnt; ++cccd_index) {
if (char_handle == cccd_handles[cccd_index]) {
for (idx = 0; idx < cccd_cnt; ++idx) {
if (char_handle == cccd_handles[idx]) {
return true;
}
}