BLE/GATT doesn't send response error

User avatar
fly135
Posts: 14
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

BLE/GATT doesn't send response error

Postby fly135 » Mon Feb 12, 2018 8:25 pm

Can't seem to get my BLE app (ex. ble_spp_server) to send response errors. An "attribute not found" error response should be sent in response to a Read by Type request on handles 1-5 for GATT Include Declaration (0x2803). There are 5 bytes that should be sent.

01 - Error Response
08 - Op code in error
0001 - Handle in error
0A - Attribute not found

I see these 5 bytes all the way down to...

UINT16 L2CA_SendFixedChnlData (UINT16 fixed_cid, BD_ADDR rem_bda, BT_HDR *p_buf)

Which returns with success. But I never see them on the "air". I.E. a packet sniffer sees the request from the client, but I never see the packet from ble_spp_server with the error response.

Here's a snippet of a trace log....

E (22778) BT: gatt_send_error_rsp, err_code:0xa, op_code:8, handle:0x1

E (22788) BT: gatt_send_error_rsp, event:0xd050, len:5, ofs:13

E (22788) BT: attp_send_sr_msg, event:0xd050, len:5, ofs:13

E (22798) BT: attp_send_msg_to_l2cap, event:0xd050, len:5, ofs:13

E (22808) BT: [01 08 01 00 0a] //!!!!!!!! these are the five correct bytes to send !!!!!!!

E (22808) BT: L2CA_SendFixedChnlData() CID: 0x0004 BDA: 842e27662c94
E (22818) BT: l2c_link_check_send_pkts
E (22818) BT: partial_segment_being_sent=0,link_state=4,power_mode=0
E (22828) BT: l2c_link_send_to_lower
E (22828) BT: TotalWin=9,Hndl=0x0,Quota=10,Unack=1,RRQuota=0,RRUnack=0
E (22838) BT: L2CA_SendFixedChnlData() L2CAP_DW_SUCCESS

I'm getting near the end of my figuring this out. But I suspect it accounts for the reason I've been struggling to get the ESP32 to connect to any BLE app on the phone. The ESP BLE server connects, but it appears to disconnect when it goes to send the error response.

User avatar
fly135
Posts: 14
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: BLE/GATT doesn't send response error

Postby fly135 » Tue Feb 13, 2018 5:45 pm

More notes on this. This disconnect doesn't occur immediately. It occurs after about 7 sec, which I believe is the connection timeout.

I've included a pic of a wireshark ble sniff. The highlighted line is the last packet send by the server to the client. That explains the connection timeout as the client and server are exchanging LLC CONTROL PDU packets to keep things rolling. No idea why the server just clams up, but it's at the same time it should be sending an "Attribute not found" response. That was the 5 bytes I made mention to in my first post...

E (22808) BT: [01 08 01 00 0a] //!!!!!!!! these are the five correct bytes to send, but never seen by the sniffer !!!!!!!

ble_issue.jpg
ble_issue.jpg (158.22 KiB) Viewed 126 times

User avatar
fly135
Posts: 14
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: BLE/GATT doesn't send response error

Postby fly135 » Tue Feb 13, 2018 8:42 pm

More info...

I ran the GATT_SERVER and GATT_CLIENT on two ESP32 boards and they are communicating. The server didn't hang and stop responding when it recv'd the Read by Group GETT include declaration. It also responded with the Attribute not found response. That's the response that didn't go out as described above. Two differences. 1) I didn't use a phone (Android 4.4.2) to communicate. 2) The client sdk is esp-idf-v3.0-rc1 and the server sdk is the most recent git of esp-idf. (not sure how to read the version on that).

I'm going to flip the client and server sdks to see if this is a factor.

User avatar
fly135
Posts: 14
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: BLE/GATT doesn't send response error

Postby fly135 » Wed Feb 14, 2018 1:59 am

More info....

Starting to wonder if my Samsung Galaxy S5 is part of the problem. I've tried numerous apps like nRF Connect and Bluefruit LE that seem to have a problem. But if I run my code on the ESP32 as a server and then change gatt_client to connect to the name of my board it seems to query the characteristics and maintain the connection just fine.

Next step... find a newer phone to test with.

User avatar
fly135
Posts: 14
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: BLE/GATT doesn't send response error

Postby fly135 » Thu Feb 15, 2018 4:33 am

Update...

Picked up a iPhone 6 today for testing and it works . Apparently there is some issue between the ESP32 and Android 4.4.2 on my Samsung S5 that is preventing it from working.

Who is online

Users browsing this forum: Bing [Bot] and 1 guest