ESP32-C3 doesn't send back SCAN_RESP packets. with the scan response data

Demetrio Magrin
Posts: 15
Joined: Thu May 04, 2023 8:00 am

ESP32-C3 doesn't send back SCAN_RESP packets. with the scan response data

Postby Demetrio Magrin » Thu Nov 23, 2023 2:16 pm

Hello,

I compiled the for example project for "bleprph" from: "\esp-idf-v5.1.1\examples\bluetooth\nimble\bleprph\".
In the bleprph_advertise(void) function it is this:

/**
* Enables advertising with the following parameters:
* o General discoverable mode.
* o Undirected connectable mode.
*/
static void bleprph_advertise(void)
{
struct ble_gap_adv_params adv_params;
struct ble_hs_adv_fields fields;
const char *name;
int rc;

/**
* Set the advertisement data included in our advertisements:
* o Flags (indicates advertisement type and other general info).
* o Advertising tx power.
* o Device name.
* o 16-bit service UUIDs (alert notifications).
*/

memset(&fields, 0, sizeof fields);

/* Advertise two flags:
* o Discoverability in forthcoming advertisement (general)
* o BLE-only (BR/EDR unsupported).
*/
fields.flags = BLE_HS_ADV_F_DISC_GEN |
BLE_HS_ADV_F_BREDR_UNSUP;

/* Indicate that the TX power level field should be included; have the
* stack fill this value automatically. This is done by assigning the
* special value BLE_HS_ADV_TX_PWR_LVL_AUTO.
*/
fields.tx_pwr_lvl_is_present = 1;
fields.tx_pwr_lvl = BLE_HS_ADV_TX_PWR_LVL_AUTO;

name = ble_svc_gap_device_name();
fields.name = (uint8_t *)name;
fields.name_len = strlen(name);
fields.name_is_complete = 1;

fields.uuids16 = (ble_uuid16_t[]) {
BLE_UUID16_INIT(GATT_SVR_SVC_ALERT_UUID)
};
fields.num_uuids16 = 1;
fields.uuids16_is_complete = 1;

rc = ble_gap_adv_set_fields(&fields);
if (rc != 0) {
MODLOG_DFLT(ERROR, "error setting advertisement data; rc=%d\n", rc);
return;
}

/* Begin advertising. */
memset(&adv_params, 0, sizeof adv_params);
adv_params.conn_mode = BLE_GAP_CONN_MODE_UND;
adv_params.disc_mode = BLE_GAP_DISC_MODE_GEN;
rc = ble_gap_adv_start(own_addr_type, NULL, BLE_HS_FOREVER,
&adv_params, bleprph_gap_event, NULL);
if (rc != 0) {
MODLOG_DFLT(ERROR, "error enabling advertisement; rc=%d\n", rc);
return;
}
}

The wireshark displays the message of "SCAN_RESP" as in the attached file on the first page where the "Scan Response Data" = MISSING.
I need to add my UUID to "Scan Response Data" which is used by my APP to recognize if the BLE device is correct.
On the second page, as you can see, the value of my UUID appears with a Nordic BLE device.

How can I do this on my Espressif device ?
I tried adding other values present on the "ble_hs_adv_fields" structure without solving my problem.
Where can I find an example ?

Thanks.

Demetrio Magrin
Attachments
ESP32-C3 SCAN_RESP.pdf
(254.92 KiB) Downloaded 184 times

MicroController
Posts: 1552
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: ESP32-C3 doesn't send back SCAN_RESP packets. with the scan response data

Postby MicroController » Thu Nov 23, 2023 2:38 pm

I need to add my UUID to "Scan Response Data" which is used by my APP to recognize if the BLE device is correct.
Sounds redundant given

Code: Select all

fields.uuids16_is_complete = 1;
I.e., are you sure the app/central device is not making use of the data already present in the advertisement?

Demetrio Magrin
Posts: 15
Joined: Thu May 04, 2023 8:00 am

Re: ESP32-C3 doesn't send back SCAN_RESP packets. with the scan response data

Postby Demetrio Magrin » Thu Nov 23, 2023 3:32 pm

Hello "MicroController",
No,
the APP (BLE central) tries to read the UUID it should receive from my Espressif module but it is always MISSING.
If you look at the pdf file you can see that the "SCAN_RESP" frame of the Nordic module is 50 bytes while the "SCAN_RESP" frame of the espresso module is 32 bytes.
This is because the "Scan response data" buffer is MISSING.

What is missing from the "bleprph_advertise()" function ?

Thanks.

Demetrio Magrin

MicroController
Posts: 1552
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: ESP32-C3 doesn't send back SCAN_RESP packets. with the scan response data

Postby MicroController » Thu Nov 23, 2023 5:38 pm

Ok, from another angle: Why don't you include your service's UUID in the advertisement?

Demetrio Magrin
Posts: 15
Joined: Thu May 04, 2023 8:00 am

Re: ESP32-C3 doesn't send back SCAN_RESP packets. with the scan response data

Postby Demetrio Magrin » Sat Nov 25, 2023 9:47 am

Hello "MicroController",

I tried to do several tests by adding data in the structure below without solving my problem.
In fact I saw that, for example, if I add the part relating to:
/*** 0x06,0x07 - 128-bit service class UUIDs. */
const ble_uuid128_t *uuids128;
uint8_t num_uuids128;
unsigned uuids128_is_complete:1;

wireshark no longer recognizes the name of my device.
Can I find a working example with "name and service class UUID" afterwards ?

struct ble_hs_adv_fields {
/*** 0x01 - Flags. */
uint8_t flags;

/*** 0x02,0x03 - 16-bit service class UUIDs. */
const ble_uuid16_t *uuids16;
uint8_t num_uuids16;
unsigned uuids16_is_complete:1;

/*** 0x04,0x05 - 32-bit service class UUIDs. */
const ble_uuid32_t *uuids32;
uint8_t num_uuids32;
unsigned uuids32_is_complete:1;

/*** 0x06,0x07 - 128-bit service class UUIDs. */
const ble_uuid128_t *uuids128;
uint8_t num_uuids128;
unsigned uuids128_is_complete:1;

/*** 0x08,0x09 - Local name. */
const uint8_t *name;
uint8_t name_len;
unsigned name_is_complete:1;

/*** 0x0a - Tx power level. */
int8_t tx_pwr_lvl;
unsigned tx_pwr_lvl_is_present:1;

/*** 0x0d - Slave connection interval range. */
const uint8_t *slave_itvl_range;

/*** 0x16 - Service data - 16-bit UUID. */
const uint8_t *svc_data_uuid16;
uint8_t svc_data_uuid16_len;

/*** 0x17 - Public target address. */
const uint8_t *public_tgt_addr;
uint8_t num_public_tgt_addrs;

/*** 0x19 - Appearance. */
uint16_t appearance;
unsigned appearance_is_present:1;

/*** 0x1a - Advertising interval. */
uint16_t adv_itvl;
unsigned adv_itvl_is_present:1;

/*** 0x20 - Service data - 32-bit UUID. */
const uint8_t *svc_data_uuid32;
uint8_t svc_data_uuid32_len;

/*** 0x21 - Service data - 128-bit UUID. */
const uint8_t *svc_data_uuid128;
uint8_t svc_data_uuid128_len;

/*** 0x24 - URI. */
const uint8_t *uri;
uint8_t uri_len;

/*** 0xff - Manufacturer specific data. */
const uint8_t *mfg_data;
uint8_t mfg_data_len;
};

I thank you.

Demetrio Magrin

MicroController
Posts: 1552
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: ESP32-C3 doesn't send back SCAN_RESP packets. with the scan response data

Postby MicroController » Sat Nov 25, 2023 10:55 am

Demetrio Magrin wrote:
Sat Nov 25, 2023 9:47 am
...wireshark no longer recognizes the name of my device.
That's probably because a UUID128 and the device's name together are too long to fit into an advertisement packet.
You may have to choose if you want the service or the device's name in the advertisement. Both pieces of data can also be retrieved by a central later, but for selecting which peripheral to discover in the first place, the UUID may be more useful.

You can also set up your own scan response.

Who is online

Users browsing this forum: Google [Bot] and 218 guests