Explorar o código

Merge branch 'bugfix/btdm_respond_error_when_receives_unsupported_request' into 'master'

component/bt: Fix bug: Respond with the Error Response when receiving a request…

See merge request idf/esp-idf!2591
Jiang Jiang Jian %!s(int64=7) %!d(string=hai) anos
pai
achega
34797d8d52

+ 7 - 2
components/bt/bluedroid/stack/gatt/gatt_main.c

@@ -179,7 +179,7 @@ void gatt_free(void)
 
         btu_free_timer(&gatt_cb.tcb[i].ind_ack_timer_ent);
         memset(&gatt_cb.tcb[i].ind_ack_timer_ent, 0, sizeof(TIMER_LIST_ENT));
-    
+
 #if (GATTS_INCLUDED == TRUE)
         fixed_queue_free(gatt_cb.tcb[i].sr_cmd.multi_rsp_q, NULL);
         gatt_cb.tcb[i].sr_cmd.multi_rsp_q = NULL;
@@ -979,7 +979,12 @@ void gatt_data_process (tGATT_TCB *p_tcb, BT_HDR *p_buf)
                 }
             }
         } else {
-            GATT_TRACE_ERROR ("ATT - Rcvd L2CAP data, unknown cmd: 0x%x\n", op_code);
+            if (op_code & GATT_COMMAND_FLAG) {
+                GATT_TRACE_ERROR ("ATT - Rcvd L2CAP data, unknown cmd: 0x%x\n", op_code);
+            } else {
+                GATT_TRACE_ERROR ("ATT - Rcvd L2CAP data, unknown req: 0x%x\n", op_code);
+                gatt_send_error_rsp (p_tcb, GATT_REQ_NOT_SUPPORTED, op_code, 0, FALSE);
+            }
         }
     } else {
         GATT_TRACE_ERROR ("invalid data length, ignore\n");

+ 3 - 2
components/bt/bluedroid/stack/include/stack/gatt_api.h

@@ -64,7 +64,7 @@
 #define  GATT_NOT_ENCRYPTED                  0x8e
 #define  GATT_CONGESTED                      0x8f
 
-#define  GATT_DUP_REG                        0x90 
+#define  GATT_DUP_REG                        0x90
 #define  GATT_ALREADY_OPEN                   0x91
 #define  GATT_CANCEL                         0x92
 
@@ -111,6 +111,7 @@ typedef UINT8 tGATT_STATUS;
 #define  GATT_SIGN_CMD_WRITE                 0xD2 /* changed in V4.0 1101-0010 (signed write)  see write cmd above*/
 #define  GATT_OP_CODE_MAX                    GATT_HANDLE_VALUE_CONF + 1 /* 0x1E = 30 + 1 = 31*/
 
+#define  GATT_COMMAND_FLAG                   0x40 /* Command Flag: set to one means commond */
 
 #define  GATT_HANDLE_IS_VALID(x) ((x) != 0)
 
@@ -766,7 +767,7 @@ extern UINT16 GATTS_AddIncludeService (UINT16 service_handle,
 **
 *******************************************************************************/
 extern UINT16 GATTS_AddCharacteristic (UINT16 service_handle, tBT_UUID *p_char_uuid,
-                                tGATT_PERM perm, tGATT_CHAR_PROP property, 
+                                tGATT_PERM perm, tGATT_CHAR_PROP property,
                                 tGATT_ATTR_VAL *attr_val, tGATTS_ATTR_CONTROL *control);
 
 /*******************************************************************************