BLE wrong GAP advertisement packet using raw data
I'm creating a new application, using latest sources of esp-idf.
We're setting raw GAP advertising data, in order to have full control on adv packet.
This is raw binary adv passed to function "esp_ble_gap_config_adv_data_raw":
0x0201060302FEFF0CFFE5027D240AC403B01C00A509094861726477697265
with a size of 30 bytes (less than max allowed value). Using both App "BLE Scanner" on Android and "LightBlue" on iOS, they detect an advertisement packet different, partially malformed.
Moreover, on App "BLE Scanner" I can print out raw adv data, and this is what I get:
0x0201060302FEFF0CFFE5027D240AC403B01C00A5090948617264776972650201060302FEFF0CFFE5027D240AC403B01C00A509094861726477697265
It looks like packet is doubled (don't know how because 31 should be the maximum size), but also App "LightBlue", that doesn't show raw data but can print manufacturer data, has a double size on manufacturer data field.
It looks like there's a sort of issue with raw data, because if I use esp_ble_gap_config_adv_data there's no such problem (but I'm not able to specify 16bit UUID services on adv packet)
Found an interesting thing. This is my code:
esp_ble_gap_config_adv_data_raw(raw_adv_data, raw_adv_data_size); esp_ble_gap_config_scan_rsp_data_raw(raw_adv_data, raw_adv_data_size);
Issue seems to disapper if I comment the secondo line, related to scan response data. Shouldn't they be independent?
Hi HardwireIO,
There are actually two packets that can be sent by BLE peripheral during advertising, each with up to 31 bytes of data. Hence you finding twice the data with the mentioned apps.
The first packet is the advertising data. this is set by esp_ble_gap_config_adv_data_raw(raw_adv_data, raw_adv_data_size);
The second packet is the scan response data. This is sent as a response to BLE Central devices (phones etc) when they perform an active scan. This is so that a peripheral can send more data to the phone before connection. This is set using esp_ble_gap_config_adv_data_raw(raw_adv_data, raw_adv_data_size);
Hi lucashutchinson,
thanks for the explanation, but those 2 messages are independent each other (once send by device that advertises and once as an answer from a scan request).
In my case, if I set both the two messages (pointing to the same raw binary buffer), the advertising packet is corrupted and malformed.
Simply removing the esp_ble_gap_config_scan_rsp_data_raw call, I can get correct adv packet again.
Hi HardwareIO,
Can you provide an example of what the data is set to in the esp32, then the data that you receive on the phone?
HI HardwareIO,
If you got a linux machine which supports BLE (use a BLE dongle), you can use wireshark to capture HCI event and do raw data compare.
- capture on bluetooth device in wireshark and then send
hcitool lescanto trigger local scan. - find HCIEvent with opcode LEMeta, sub event code LE Adv Report, BT address is your ESP32 address.
- compare the
datafield with your raw data.
HI HardwareIO, For each advertising event type, a corresponding Advertising Channel PDU is used. An advertising event can be one of the following types:
- a connectable undirected event (ADV_IND)
- a connectable directed event (ADV_DIRECT)
- a non-connectedable undirected event (ADV_NONCONN_IND)
- a scannable undirected event (ADV_SCAN_IND)
The advertising event type determines the allowable response PDUs:
- ADV_IND ------ Allowable SCAN_REQ:YES
- ADV_DIRECT_IND ------ Allowable SCAN_REQ:NO
- ADV_NONCONN_IND ------ Allowable SCAN_REQ:NO
- ADV_SCAN_IND ------ Allowable SCAN_REQ:YES
If ADV TYPE is ADV_IND or ADV_SCAN_IND, The advertiser will send Scan Rsp DATA after it received a SCAN_REQ .
There are two types of scanning ,determined by the Host:passive and active
- Passive Scanning:When in passive scanning , the Link Layer will only receive packets;it shall not send any packets(SCAN_REQ).
- Active Scanning:When in active scanning, the Link Layer shall listen for advertising PDUs and depending on the advertising PDU type it may request an advertier to send additional information(SCAN_RSP_DATA).
So, the packet you geted by "BLE Scanner" and "LightBlue" is ADV_DATA+SCAN_RSP_DATA . The premise condition that can get ADV_DATA+SCAN_RSP_DATA:
- ADV type : ADV_IND or ADV_SCAN_IND;
- SCAN type : Active SCAN
- Configuration SCAN RSP DATA(esp_ble_gap_config_scan_rsp_data_raw)
If you do not meet the above conditions,only the ADV_DATA will be geted.
Hi HardwireIO, is this problem solved? Can we close this issue?