Re: how to add local name in scan response when setting MGMT_ADV_FLAG_LOCAL_NAME in Bluez

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Luiz

Thanks for your reply. I think kernel should support scan response
because I am able to set different local name in scan rsp using hci
socket instead of Dbus API. Have you ever post your patch or sample
code in this thread or any other place? May I have a try on your
patch? It would be doable and useful to put Local name change as
property, like include tx power, so that we can set it in scan rsp
when enabling advertisement.

Thanks
Best wishes
Yunhan

On Tue, Aug 1, 2017 at 5:24 AM, Luiz Augusto von Dentz
<luiz.dentz@xxxxxxxxx> wrote:
> Hi Yunhan,
>
> On Tue, Aug 1, 2017 at 1:48 PM, Luiz Augusto von Dentz
> <luiz.dentz@xxxxxxxxx> wrote:
>> Hi Yunhan,
>>
>> On Tue, Aug 1, 2017 at 1:21 PM, Luiz Augusto von Dentz
>> <luiz.dentz@xxxxxxxxx> wrote:
>>> Hi Yunhan,
>>>
>>> On Tue, Aug 1, 2017 at 10:37 AM, Yunhan Wang <yunhanw@xxxxxxxxxx> wrote:
>>>> Hi
>>>>
>>>> I am trying to do some small experiments that add local name in the
>>>> scan response,  should I use data[0] to store both adv_data and
>>>> scan_rsp?
>>>>
>>>> I tried to add local name(’TEST’) in data[0] under
>>>> mgmt_cp_add_advertising on
>>>> https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/src/advertising.c#n484,
>>>> it seems it does not work, any idea?
>>>
>>> Seems to be a limitation in the kernel, also setting the adapter name
>>> doesn't change anything either so it seems it simply does not include
>>> any scan response. I guess we would have to add support for that.
>>
>> Actually the kernel does seem to set the scan response data, but is empty:
>>
>> < HCI Command: LE Set Scan Response Data (0x08|0x0009) plen 32
>> #8499 13:40:40.663565
>>         Length: 0
>>> HCI Event: Command Complete (0x0e) plen 4                         #8500 13:40:40.664554
>>       LE Set Scan Response Data (0x08|0x0009) ncmd 1
>>         Status: Success (0x00)
>
> Ive sent some patches that should enable to use the local adapter name
> in the scan data, if you do intend to use a different name then we
> might gonna need to add a different property or rework the IncludeName
> to be a string and if empty use the local adapter name.
>
>>>> Thanks
>>>> Best wishes
>>>> Yunhan
>>>>
>>>> static DBusMessage *refresh_advertisement(struct btd_adv_client *client)
>>>> {
>>>> struct mgmt_cp_add_advertising *cp;
>>>> uint8_t param_len;
>>>> uint8_t *adv_data;
>>>> size_t adv_data_len;
>>>> uint32_t flags = 0;
>>>>
>>>> uint8_t scan_rsp[] = {
>>>> ’T’,
>>>> ’E’,
>>>> ’S’,
>>>> ’T’
>>>> };
>>>> size_t scan_rsp_len = sizeof(scan_rsp);
>
> This needs to be in raw scan data format aka TLV.
>
>>>> DBG("Refreshing advertisement: %s", client->path);
>>>>
>>>> if (client->type == AD_TYPE_PERIPHERAL)
>>>> flags = MGMT_ADV_FLAG_CONNECTABLE | MGMT_ADV_FLAG_DISCOV |
>>>> MGMT_ADV_FLAG_LOCAL_NAME;
>>>>
>>>> if (client->include_tx_power)
>>>> flags |= MGMT_ADV_FLAG_TX_POWER;
>>>>
>>>> adv_data = bt_ad_generate(client->data, &adv_data_len);
>>>>
>>>> if (!adv_data || (adv_data_len > calc_max_adv_len(client, flags))) {
>>>> error("Advertising data too long or couldn't be generated.");
>>>>
>>>> return g_dbus_create_error(client->reg, ERROR_INTERFACE
>>>> ".InvalidLength",
>>>> "Advertising data too long.");
>>>> }
>>>>
>>>> param_len = sizeof(struct mgmt_cp_add_advertising) + adv_data_len +
>>>> scan_rsp_len;
>>>>
>>>> cp = malloc0(param_len);
>>>>
>>>> if (!cp) {
>>>> error("Couldn't allocate for MGMT!");
>>>>
>>>> free(adv_data);
>>>>
>>>> return btd_error_failed(client->reg, "Failed");
>>>> }
>>>>
>>>> cp->flags = htobl(flags);
>>>> cp->instance = client->instance;
>>>> cp->adv_data_len = adv_data_len;
>>>> cp->scan_rsp_len = scan_rsp_len;
>>>> memcpy(cp->data, adv_data, adv_data_len);
>>>> memcpy(cp->data + adv_data_len, scan_rsp_data, scan_rsp_len);
>>>> free(adv_data);
>>>>
>>>> if (!mgmt_send(client->manager->mgmt, MGMT_OP_ADD_ADVERTISING,
>>>> client->manager->mgmt_index, param_len, cp,
>>>> add_adv_callback, client, NULL)) {
>>>> DBG("Failed to add Advertising Data");
>>>>
>>>> free(cp);
>>>>
>>>> return btd_error_failed(client->reg, "Failed");
>>>> }
>>>>
>>>> free(cp);
>>>>
>>>> return NULL;
>>>> }
>>>>
>>>> Reference:
>>>> In lib/mgmt.h,
>>>>
>>>> #define MGMT_OP_ADD_ADVERTISING 0x003E
>>>> struct mgmt_cp_add_advertising {
>>>> uint8_t  instance;
>>>> uint32_t flags;
>>>> uint16_t duration;
>>>> uint16_t timeout;
>>>> uint8_t  adv_data_len;
>>>> uint8_t  scan_rsp_len;
>>>> uint8_t  data[0];
>>>> } __packed;
>>>> From mgmt-api.txt, I am
>>>>
>>>> Add Advertising Command
>>>> =======================
>>>>
>>>> Command Code: 0x003e
>>>> Controller Index: <controller id>
>>>> Command Parameters: Instance (1 Octet)
>>>> Flags (4 Octets)
>>>> Duration (2 Octets)
>>>> Timeout (2 Octets)
>>>> Adv_Data_Len (1 Octet)
>>>> Scan_Rsp_len (1 Octet)
>>>> Adv_Data (0-255 Octets)
>>>> Scan_Rsp (0-255 Octets)
>>>> …...
>>>> With the Flags value the type of advertising is controlled and
>>>> the following flags are defined:
>>>>
>>>> 0 Switch into Connectable mode
>>>> 1 Advertise as Discoverable
>>>> 2 Advertise as Limited Discoverable
>>>> 3 Add Flags field to Adv_Data
>>>> 4 Add TX Power field to Adv_Data
>>>> 5 Add Appearance field to Scan_Rsp
>>>> 6 Add Local Name in Scan_Rsp
>>>> --
>>>> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
>>>> the body of a message to majordomo@xxxxxxxxxxxxxxx
>>>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>>>
>>>
>>>
>>> --
>>> Luiz Augusto von Dentz
>>
>>
>>
>> --
>> Luiz Augusto von Dentz
>
>
>
> --
> Luiz Augusto von Dentz
--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux