bt component: code style update
This commit is contained in:
parent
3543d8170c
commit
a74f3f9fd7
3 changed files with 15 additions and 28 deletions
|
@ -148,8 +148,7 @@ esp_err_t esp_ble_gatts_add_char(uint16_t service_handle, esp_bt_uuid_t *char_
|
||||||
LOG_ERROR("Error in %s, line=%d, for stack respond attribute, char_val should not be NULL here\n",\
|
LOG_ERROR("Error in %s, line=%d, for stack respond attribute, char_val should not be NULL here\n",\
|
||||||
__func__, __LINE__);
|
__func__, __LINE__);
|
||||||
return ESP_ERR_INVALID_ARG;
|
return ESP_ERR_INVALID_ARG;
|
||||||
}
|
} else if (char_val->attr_max_len == 0){
|
||||||
else if (char_val->attr_max_len == 0){
|
|
||||||
LOG_ERROR("Error in %s, line=%d, for stack respond attribute, attribute max length should not be 0\n",\
|
LOG_ERROR("Error in %s, line=%d, for stack respond attribute, attribute max length should not be 0\n",\
|
||||||
__func__, __LINE__);
|
__func__, __LINE__);
|
||||||
return ESP_ERR_INVALID_ARG;
|
return ESP_ERR_INVALID_ARG;
|
||||||
|
|
|
@ -272,9 +272,9 @@ static tGATT_STATUS read_attr_value (void *p_attr,
|
||||||
if (p_attr16->p_value == NULL || p_attr16->p_value->attr_val.attr_val == NULL) {
|
if (p_attr16->p_value == NULL || p_attr16->p_value->attr_val.attr_val == NULL) {
|
||||||
status = GATT_ESP_ERROR;
|
status = GATT_ESP_ERROR;
|
||||||
}
|
}
|
||||||
/*if offset equal to max_len, should respond with zero byte value
|
|
||||||
//if offset is greater than max_len, should respond with an error*/
|
|
||||||
else if (offset > p_attr16->p_value->attr_val.attr_len){
|
else if (offset > p_attr16->p_value->attr_val.attr_len){
|
||||||
|
/*if offset equal to max_len, should respond with zero byte value
|
||||||
|
//if offset is greater than max_len, should respond with an error*/
|
||||||
status = GATT_INVALID_OFFSET;
|
status = GATT_INVALID_OFFSET;
|
||||||
} else {
|
} else {
|
||||||
UINT8 *value = (UINT8 *)(p_attr16->p_value->attr_val.attr_val) + offset;
|
UINT8 *value = (UINT8 *)(p_attr16->p_value->attr_val.attr_val) + offset;
|
||||||
|
@ -476,8 +476,7 @@ UINT16 gatts_add_characteristic (tGATT_SVC_DB *p_db, tGATT_PERM perm,
|
||||||
GATT_TRACE_ERROR("Error in %s, line=%d, for stack respond attribute, attr_val should not be NULL here\n",\
|
GATT_TRACE_ERROR("Error in %s, line=%d, for stack respond attribute, attr_val should not be NULL here\n",\
|
||||||
__func__, __LINE__);
|
__func__, __LINE__);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
} else if (attr_val->attr_max_len == 0){
|
||||||
else if (attr_val->attr_max_len == 0){
|
|
||||||
GATT_TRACE_ERROR("Error in %s, line=%d, for stack respond attribute, attribute max length should not be 0\n",\
|
GATT_TRACE_ERROR("Error in %s, line=%d, for stack respond attribute, attribute max length should not be 0\n",\
|
||||||
__func__, __LINE__);
|
__func__, __LINE__);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -627,8 +626,7 @@ UINT16 gatts_add_char_descr (tGATT_SVC_DB *p_db, tGATT_PERM perm,
|
||||||
GATT_TRACE_ERROR("Error in %s, line=%d, for stack respond attribute, attr_val should not be NULL here\n",\
|
GATT_TRACE_ERROR("Error in %s, line=%d, for stack respond attribute, attr_val should not be NULL here\n",\
|
||||||
__func__, __LINE__);
|
__func__, __LINE__);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
} else if (attr_val->attr_max_len == 0){
|
||||||
else if (attr_val->attr_max_len == 0){
|
|
||||||
GATT_TRACE_ERROR("Error in %s, line=%d, for stack respond attribute, attribute max length should not be 0\n",\
|
GATT_TRACE_ERROR("Error in %s, line=%d, for stack respond attribute, attribute max length should not be 0\n",\
|
||||||
__func__, __LINE__);
|
__func__, __LINE__);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -730,8 +728,7 @@ tGATT_STATUS gatts_set_attribute_value(tGATT_SVC_DB *p_db, UINT16 attr_handle,
|
||||||
|| (p_cur->p_value->attr_val.attr_max_len == 0)){
|
|| (p_cur->p_value->attr_val.attr_max_len == 0)){
|
||||||
GATT_TRACE_ERROR("Error in %s, line=%d, attribute value should not be NULL here\n", __func__, __LINE__);
|
GATT_TRACE_ERROR("Error in %s, line=%d, attribute value should not be NULL here\n", __func__, __LINE__);
|
||||||
return GATT_NOT_FOUND;
|
return GATT_NOT_FOUND;
|
||||||
}
|
} else if (p_cur->p_value->attr_val.attr_max_len < length) {
|
||||||
else if (p_cur->p_value->attr_val.attr_max_len < length) {
|
|
||||||
GATT_TRACE_ERROR("gatts_set_attribute_value failed:Invalid value length");
|
GATT_TRACE_ERROR("gatts_set_attribute_value failed:Invalid value length");
|
||||||
return GATT_INVALID_ATTR_LEN;
|
return GATT_INVALID_ATTR_LEN;
|
||||||
} else{
|
} else{
|
||||||
|
@ -942,12 +939,10 @@ tGATT_STATUS gatts_write_attr_value_by_handle(tGATT_SVC_DB *p_db,
|
||||||
memcpy(p_attr->p_value->attr_val.attr_val + offset, p_value, len);
|
memcpy(p_attr->p_value->attr_val.attr_val + offset, p_value, len);
|
||||||
p_attr->p_value->attr_val.attr_len = len + offset;
|
p_attr->p_value->attr_val.attr_len = len + offset;
|
||||||
return GATT_SUCCESS;
|
return GATT_SUCCESS;
|
||||||
}
|
} else if (p_attr->p_value->attr_val.attr_max_len < offset + len){
|
||||||
else if (p_attr->p_value->attr_val.attr_max_len < offset + len){
|
|
||||||
GATT_TRACE_DEBUG("Remote device try to write with a length larger then attribute's max length\n");
|
GATT_TRACE_DEBUG("Remote device try to write with a length larger then attribute's max length\n");
|
||||||
return GATT_INVALID_ATTR_LEN;
|
return GATT_INVALID_ATTR_LEN;
|
||||||
}
|
} else if ((p_attr->p_value == NULL) || (p_attr->p_value->attr_val.attr_val == NULL)){
|
||||||
else if ((p_attr->p_value == NULL) || (p_attr->p_value->attr_val.attr_val == NULL)){
|
|
||||||
GATT_TRACE_ERROR("Error in %s, line=%d, %s should not be NULL here\n", __func__, __LINE__, \
|
GATT_TRACE_ERROR("Error in %s, line=%d, %s should not be NULL here\n", __func__, __LINE__, \
|
||||||
(p_attr->p_value == NULL) ? "p_value" : "attr_val.attr_val");
|
(p_attr->p_value == NULL) ? "p_value" : "attr_val.attr_val");
|
||||||
return GATT_ESP_ERROR;
|
return GATT_ESP_ERROR;
|
||||||
|
|
|
@ -378,20 +378,17 @@ void gatt_process_exec_write_req (tGATT_TCB *p_tcb, UINT8 op_code, UINT16 len, U
|
||||||
is_prepare_write_valid = TRUE;
|
is_prepare_write_valid = TRUE;
|
||||||
}
|
}
|
||||||
GATT_TRACE_DEBUG("Send execute_write_rsp\n");
|
GATT_TRACE_DEBUG("Send execute_write_rsp\n");
|
||||||
}
|
} else if ((prepare_record->error_code_app == GATT_SUCCESS) &&
|
||||||
else if ((prepare_record->error_code_app == GATT_SUCCESS) &&
|
|
||||||
(prepare_record->total_num > queue_num)){
|
(prepare_record->total_num > queue_num)){
|
||||||
//No error for stack_rsp's handles and there exist some app_rsp's handles,
|
//No error for stack_rsp's handles and there exist some app_rsp's handles,
|
||||||
//so exec_write_rsp depends to app's response; but stack_rsp's data is valid
|
//so exec_write_rsp depends to app's response; but stack_rsp's data is valid
|
||||||
//TODO: there exist problem if stack_rsp's data is valid but app_rsp's data is not valid.
|
//TODO: there exist problem if stack_rsp's data is valid but app_rsp's data is not valid.
|
||||||
is_prepare_write_valid = TRUE;
|
is_prepare_write_valid = TRUE;
|
||||||
}
|
} else if(prepare_record->total_num < queue_num) {
|
||||||
else if(prepare_record->total_num < queue_num) {
|
|
||||||
GATT_TRACE_ERROR("Error in %s, line=%d, prepare write total number (%d) \
|
GATT_TRACE_ERROR("Error in %s, line=%d, prepare write total number (%d) \
|
||||||
should not smaller than prepare queue number (%d)\n", \
|
should not smaller than prepare queue number (%d)\n", \
|
||||||
__func__, __LINE__,prepare_record->total_num, queue_num);
|
__func__, __LINE__,prepare_record->total_num, queue_num);
|
||||||
}
|
} else if (prepare_record->error_code_app != GATT_SUCCESS){
|
||||||
else if (prepare_record->error_code_app != GATT_SUCCESS){
|
|
||||||
GATT_TRACE_DEBUG("Send error code for execute_write, code=0x%x\n", prepare_record->error_code_app);
|
GATT_TRACE_DEBUG("Send error code for execute_write, code=0x%x\n", prepare_record->error_code_app);
|
||||||
is_need_dequeue_sr_cmd = (prepare_record->total_num == queue_num) ? TRUE : FALSE;
|
is_need_dequeue_sr_cmd = (prepare_record->total_num == queue_num) ? TRUE : FALSE;
|
||||||
gatt_send_error_rsp(p_tcb, prepare_record->error_code_app, GATT_REQ_EXEC_WRITE, 0, is_need_dequeue_sr_cmd);
|
gatt_send_error_rsp(p_tcb, prepare_record->error_code_app, GATT_REQ_EXEC_WRITE, 0, is_need_dequeue_sr_cmd);
|
||||||
|
@ -1148,8 +1145,7 @@ void gatts_process_write_req (tGATT_TCB *p_tcb, UINT8 i_rcb, UINT16 handle,
|
||||||
gatt_write_req_rsp.op_code = GATT_RSP_WRITE;
|
gatt_write_req_rsp.op_code = GATT_RSP_WRITE;
|
||||||
gatt_send_packet(p_tcb, (UINT8 *)(&gatt_write_req_rsp), sizeof(gatt_write_req_rsp));
|
gatt_send_packet(p_tcb, (UINT8 *)(&gatt_write_req_rsp), sizeof(gatt_write_req_rsp));
|
||||||
gatt_dequeue_sr_cmd(p_tcb);
|
gatt_dequeue_sr_cmd(p_tcb);
|
||||||
}
|
} else if (status != GATT_PENDING){
|
||||||
else if (status != GATT_PENDING){
|
|
||||||
/* note: in case of GATT_BUSY, will respond this application error to remote device */
|
/* note: in case of GATT_BUSY, will respond this application error to remote device */
|
||||||
gatt_send_error_rsp (p_tcb, status, op_code, handle, TRUE);
|
gatt_send_error_rsp (p_tcb, status, op_code, handle, TRUE);
|
||||||
}
|
}
|
||||||
|
@ -1219,20 +1215,17 @@ void gatt_attr_process_prepare_write (tGATT_TCB *p_tcb, UINT8 i_rcb, UINT16 hand
|
||||||
p_attr_temp = p_attr;
|
p_attr_temp = p_attr;
|
||||||
if (p_attr->control.auto_rsp == GATT_RSP_BY_APP) {
|
if (p_attr->control.auto_rsp == GATT_RSP_BY_APP) {
|
||||||
status = GATT_APP_RSP;
|
status = GATT_APP_RSP;
|
||||||
}
|
} else if (p_attr->p_value != NULL &&
|
||||||
else if (p_attr->p_value != NULL &&
|
|
||||||
offset > p_attr->p_value->attr_val.attr_max_len) {
|
offset > p_attr->p_value->attr_val.attr_max_len) {
|
||||||
status = GATT_INVALID_OFFSET;
|
status = GATT_INVALID_OFFSET;
|
||||||
is_need_prepare_write_rsp = TRUE;
|
is_need_prepare_write_rsp = TRUE;
|
||||||
is_need_queue_data = TRUE;
|
is_need_queue_data = TRUE;
|
||||||
}
|
} else if (p_attr->p_value != NULL &&
|
||||||
else if (p_attr->p_value != NULL &&
|
|
||||||
((offset + len) > p_attr->p_value->attr_val.attr_max_len)){
|
((offset + len) > p_attr->p_value->attr_val.attr_max_len)){
|
||||||
status = GATT_INVALID_ATTR_LEN;
|
status = GATT_INVALID_ATTR_LEN;
|
||||||
is_need_prepare_write_rsp = TRUE;
|
is_need_prepare_write_rsp = TRUE;
|
||||||
is_need_queue_data = TRUE;
|
is_need_queue_data = TRUE;
|
||||||
}
|
} else if (p_attr->p_value == NULL) {
|
||||||
else if (p_attr->p_value == NULL) {
|
|
||||||
LOG_ERROR("Error in %s, attribute of handle 0x%x not allocate value buffer\n",
|
LOG_ERROR("Error in %s, attribute of handle 0x%x not allocate value buffer\n",
|
||||||
__func__, handle);
|
__func__, handle);
|
||||||
status = GATT_ESP_ERROR;
|
status = GATT_ESP_ERROR;
|
||||||
|
|
Loading…
Reference in a new issue