Component/bt: add check value and length for esp_ble_gatts_get_attr_value(uint16_t attr_handle, uint16_t *length, const uint8_t **value);

This commit is contained in:
zhiweijian 2017-08-14 17:39:11 +08:00
parent bb7d5fc10f
commit 6276e71fc1
9 changed files with 25 additions and 16 deletions

View file

@ -327,13 +327,13 @@ esp_err_t esp_ble_gatts_set_attr_value(uint16_t attr_handle, uint16_t length, co
btc_gatts_arg_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); btc_gatts_arg_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
} }
esp_err_t esp_ble_gatts_get_attr_value(uint16_t attr_handle, uint16_t *length, const uint8_t **value) esp_gatt_status_t esp_ble_gatts_get_attr_value(uint16_t attr_handle, uint16_t *length, const uint8_t **value)
{ {
if (attr_handle == ESP_GATT_ILLEGAL_HANDLE) { if (attr_handle == ESP_GATT_ILLEGAL_HANDLE) {
return ESP_FAIL; return ESP_GATT_INVALID_HANDLE;
} }
btc_gatts_get_attr_value(attr_handle, length, (uint8_t **)value);
return ESP_OK; return btc_gatts_get_attr_value(attr_handle, length, (uint8_t **)value);
} }
esp_err_t esp_ble_gatts_open(esp_gatt_if_t gatts_if, esp_bd_addr_t remote_bda, bool is_direct) esp_err_t esp_ble_gatts_open(esp_gatt_if_t gatts_if, esp_bd_addr_t remote_bda, bool is_direct)

View file

@ -514,11 +514,11 @@ esp_err_t esp_ble_gatts_set_attr_value(uint16_t attr_handle, uint16_t length, co
* @param[out] value: Pointer to attribute value payload, the value cannot be modified by user * @param[out] value: Pointer to attribute value payload, the value cannot be modified by user
* *
* @return * @return
* - ESP_OK : success * - ESP_GATT_OK : success
* - other : failed * - other : failed
* *
*/ */
esp_err_t esp_ble_gatts_get_attr_value(uint16_t attr_handle, uint16_t *length, const uint8_t **value); esp_gatt_status_t esp_ble_gatts_get_attr_value(uint16_t attr_handle, uint16_t *length, const uint8_t **value);
/** /**

View file

@ -524,9 +524,10 @@ void bta_gatts_set_attr_value(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_
} }
} }
void bta_gatts_get_attr_value(UINT16 attr_handle, UINT16 *length, UINT8 **value) tGATT_STATUS bta_gatts_get_attr_value(UINT16 attr_handle, UINT16 *length, UINT8 **value)
{ {
GATTS_GetAttributeValue(attr_handle, length, value);
return GATTS_GetAttributeValue(attr_handle, length, value);
} }
/******************************************************************************* /*******************************************************************************

View file

@ -490,9 +490,9 @@ void BTA_SetAttributeValue(UINT16 attr_handle, UINT16 length, UINT8 *value)
} }
void BTA_GetAttributeValue(UINT16 attr_handle, UINT16 *length, UINT8 **value) tBTA_GATT_STATUS BTA_GetAttributeValue(UINT16 attr_handle, UINT16 *length, UINT8 **value)
{ {
bta_gatts_get_attr_value(attr_handle, length, value); return bta_gatts_get_attr_value(attr_handle, length, value);
} }
/******************************************************************************* /*******************************************************************************

View file

@ -1409,10 +1409,10 @@ extern void BTA_SetAttributeValue(UINT16 attr_handle, UINT16 length, UINT8 *valu
** length - the value length which has been set to the attribute. ** length - the value length which has been set to the attribute.
** value - the pointer to the value ** value - the pointer to the value
** **
** Returns None ** Returns tBTA_GATT_STATUS
** **
*******************************************************************************/ *******************************************************************************/
extern void BTA_GetAttributeValue(UINT16 attr_handle, UINT16 *length, UINT8 **value); extern tBTA_GATT_STATUS BTA_GetAttributeValue(UINT16 attr_handle, UINT16 *length, UINT8 **value);
/******************************************************************************* /*******************************************************************************
** **

View file

@ -230,7 +230,7 @@ extern void bta_gatts_add_include_srvc(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS
extern void bta_gatts_add_char(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_msg); extern void bta_gatts_add_char(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_msg);
extern void bta_gatts_add_char_descr(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_msg); extern void bta_gatts_add_char_descr(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_msg);
extern void bta_gatts_set_attr_value(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_msg); extern void bta_gatts_set_attr_value(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_msg);
extern void bta_gatts_get_attr_value(UINT16 attr_handle, UINT16 *length, UINT8 **value); extern tGATT_STATUS bta_gatts_get_attr_value(UINT16 attr_handle, UINT16 *length, UINT8 **value);
extern void bta_gatts_delete_service(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_msg); extern void bta_gatts_delete_service(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_msg);
extern void bta_gatts_start_service(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_msg); extern void bta_gatts_start_service(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_msg);
extern void bta_gatts_stop_service(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_msg); extern void bta_gatts_stop_service(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_msg);

View file

@ -474,10 +474,10 @@ static esp_gatt_status_t btc_gatts_check_valid_attr_tab(esp_gatts_attr_db_t *gat
return ESP_GATT_OK; return ESP_GATT_OK;
} }
void btc_gatts_get_attr_value(uint16_t attr_handle, uint16_t *length, uint8_t **value) esp_gatt_status_t btc_gatts_get_attr_value(uint16_t attr_handle, uint16_t *length, uint8_t **value)
{ {
BTA_GetAttributeValue(attr_handle, length, value); return BTA_GetAttributeValue(attr_handle, length, value);
} }

View file

@ -147,7 +147,7 @@ typedef union {
void btc_gatts_call_handler(btc_msg_t *msg); void btc_gatts_call_handler(btc_msg_t *msg);
void btc_gatts_cb_handler(btc_msg_t *msg); void btc_gatts_cb_handler(btc_msg_t *msg);
void btc_gatts_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src); void btc_gatts_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
void btc_gatts_get_attr_value(uint16_t attr_handle, uint16_t *length, uint8_t **value); esp_gatt_status_t btc_gatts_get_attr_value(uint16_t attr_handle, uint16_t *length, uint8_t **value);
#endif /* __BTC_GATTS_H__ */ #endif /* __BTC_GATTS_H__ */

View file

@ -752,6 +752,14 @@ tGATT_STATUS gatts_get_attribute_value(tGATT_SVC_DB *p_db, UINT16 attr_handle,
GATT_TRACE_ERROR("gatts_get_attribute_value Fail:p_db->p_attr_list is NULL.\n"); GATT_TRACE_ERROR("gatts_get_attribute_value Fail:p_db->p_attr_list is NULL.\n");
return GATT_INVALID_PDU; return GATT_INVALID_PDU;
} }
if (length == NULL){
GATT_TRACE_ERROR("gatts_get_attribute_value Fail:length is NULL.\n");
return GATT_INVALID_PDU;
}
if (value == NULL){
GATT_TRACE_ERROR("gatts_get_attribute_value Fail:value is NULL.\n");
return GATT_INVALID_PDU;
}
p_cur = (tGATT_ATTR16 *) p_db->p_attr_list; p_cur = (tGATT_ATTR16 *) p_db->p_attr_list;