* [PATCH 1/3] Bluetooth: Fix local name in scan rsp @ 2016-10-05 10:28 Michał Narajowski 2016-10-05 10:28 ` [PATCH 2/3] Bluetooth: Add appearance to default scan rsp data Michał Narajowski ` (2 more replies) 0 siblings, 3 replies; 8+ messages in thread From: Michał Narajowski @ 2016-10-05 10:28 UTC (permalink / raw) To: linux-bluetooth; +Cc: Michał Narajowski Use complete name if it fits. If not and there is short name check if it fits. If not then use shortened name as prefix of complete name. Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl> --- net/bluetooth/hci_request.c | 47 +++++++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c index c813568..fd6406d 100644 --- a/net/bluetooth/hci_request.c +++ b/net/bluetooth/hci_request.c @@ -973,25 +973,48 @@ void __hci_req_enable_advertising(struct hci_request *req) static u8 append_local_name(struct hci_dev *hdev, u8 *ptr, u8 ad_len) { - size_t name_len; + size_t complete_len; + size_t short_len; int max_len; max_len = HCI_MAX_AD_LENGTH - ad_len - 2; - name_len = strlen(hdev->dev_name); - if (name_len > 0 && max_len > 0) { + complete_len = strlen(hdev->dev_name); + short_len = strlen(hdev->short_name); - if (name_len > max_len) { - name_len = max_len; - ptr[1] = EIR_NAME_SHORT; - } else - ptr[1] = EIR_NAME_COMPLETE; + /* no space left for name */ + if (max_len < 1) + return ad_len; - ptr[0] = name_len + 1; + /* no name set */ + if (!complete_len) + return ad_len; - memcpy(ptr + 2, hdev->dev_name, name_len); + /* complete name fits and is eq to max short name len or smaller */ + if (complete_len <= max_len && + complete_len <= HCI_MAX_SHORT_NAME_LENGTH) { + ptr[0] = complete_len + 1; + ptr[1] = EIR_NAME_COMPLETE; + memcpy(ptr + 2, hdev->dev_name, complete_len); - ad_len += (name_len + 2); - ptr += (name_len + 2); + return ad_len + complete_len + 2; + } + + /* short name set and fits */ + if (short_len && short_len <= max_len) { + ptr[0] = short_len + 1; + ptr[1] = EIR_NAME_SHORT; + memcpy(ptr + 2, hdev->short_name, short_len); + + return ad_len + short_len + 2; + } + + /* no short name set so shorten complete name */ + if (!short_len) { + ptr[0] = max_len + 1; + ptr[1] = EIR_NAME_SHORT; + memcpy(ptr + 2, hdev->dev_name, max_len); + + return ad_len + max_len + 2; } return ad_len; -- 2.7.4 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/3] Bluetooth: Add appearance to default scan rsp data 2016-10-05 10:28 [PATCH 1/3] Bluetooth: Fix local name in scan rsp Michał Narajowski @ 2016-10-05 10:28 ` Michał Narajowski 2016-10-05 10:28 ` [PATCH 3/3] Bluetooth: Refactor append name and appearance Michał Narajowski 2016-10-05 11:19 ` [PATCH 1/3] Bluetooth: Fix local name in scan rsp Marcel Holtmann 2 siblings, 0 replies; 8+ messages in thread From: Michał Narajowski @ 2016-10-05 10:28 UTC (permalink / raw) To: linux-bluetooth; +Cc: Michał Narajowski Add appearance value to beginning of scan rsp data for default advertising instance if the value is not 0. Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl> --- net/bluetooth/hci_request.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c index fd6406d..3c44c54 100644 --- a/net/bluetooth/hci_request.c +++ b/net/bluetooth/hci_request.c @@ -1022,7 +1022,16 @@ static u8 append_local_name(struct hci_dev *hdev, u8 *ptr, u8 ad_len) static u8 create_default_scan_rsp_data(struct hci_dev *hdev, u8 *ptr) { - return append_local_name(hdev, ptr, 0); + u8 scan_rsp_len = 0; + + if (hdev->appearance) { + ptr[0] = 3; + ptr[1] = EIR_APPEARANCE; + put_unaligned_le16(hdev->appearance, ptr + 2); + scan_rsp_len += 4; + } + + return append_local_name(hdev, ptr + scan_rsp_len, scan_rsp_len); } static u8 create_instance_scan_rsp_data(struct hci_dev *hdev, u8 instance, -- 2.7.4 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/3] Bluetooth: Refactor append name and appearance 2016-10-05 10:28 [PATCH 1/3] Bluetooth: Fix local name in scan rsp Michał Narajowski 2016-10-05 10:28 ` [PATCH 2/3] Bluetooth: Add appearance to default scan rsp data Michał Narajowski @ 2016-10-05 10:28 ` Michał Narajowski 2016-10-05 11:19 ` [PATCH 1/3] Bluetooth: Fix local name in scan rsp Marcel Holtmann 2 siblings, 0 replies; 8+ messages in thread From: Michał Narajowski @ 2016-10-05 10:28 UTC (permalink / raw) To: linux-bluetooth; +Cc: Michał Narajowski Use eir_append_data to remove code duplication. Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl> --- net/bluetooth/hci_request.c | 44 +++++++++++++++----------------------------- net/bluetooth/hci_request.h | 23 +++++++++++++++++++++++ net/bluetooth/mgmt.c | 21 --------------------- 3 files changed, 38 insertions(+), 50 deletions(-) diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c index 3c44c54..e228842 100644 --- a/net/bluetooth/hci_request.c +++ b/net/bluetooth/hci_request.c @@ -21,8 +21,6 @@ SOFTWARE IS DISCLAIMED. */ -#include <asm/unaligned.h> - #include <net/bluetooth/bluetooth.h> #include <net/bluetooth/hci_core.h> #include <net/bluetooth/mgmt.h> @@ -992,46 +990,39 @@ static u8 append_local_name(struct hci_dev *hdev, u8 *ptr, u8 ad_len) /* complete name fits and is eq to max short name len or smaller */ if (complete_len <= max_len && complete_len <= HCI_MAX_SHORT_NAME_LENGTH) { - ptr[0] = complete_len + 1; - ptr[1] = EIR_NAME_COMPLETE; - memcpy(ptr + 2, hdev->dev_name, complete_len); - - return ad_len + complete_len + 2; + return eir_append_data(ptr, ad_len, EIR_NAME_COMPLETE, + hdev->dev_name, complete_len); } /* short name set and fits */ if (short_len && short_len <= max_len) { - ptr[0] = short_len + 1; - ptr[1] = EIR_NAME_SHORT; - memcpy(ptr + 2, hdev->short_name, short_len); - - return ad_len + short_len + 2; + return eir_append_data(ptr, ad_len, EIR_NAME_SHORT, + hdev->short_name, short_len); } /* no short name set so shorten complete name */ if (!short_len) { - ptr[0] = max_len + 1; - ptr[1] = EIR_NAME_SHORT; - memcpy(ptr + 2, hdev->dev_name, max_len); - - return ad_len + max_len + 2; + return eir_append_data(ptr, ad_len, EIR_NAME_SHORT, + hdev->dev_name, max_len); } return ad_len; } +static u8 append_appearance(struct hci_dev *hdev, u8 *ptr, u8 ad_len) +{ + return eir_append_le16(ptr, ad_len, EIR_APPEARANCE, hdev->appearance); +} + static u8 create_default_scan_rsp_data(struct hci_dev *hdev, u8 *ptr) { u8 scan_rsp_len = 0; if (hdev->appearance) { - ptr[0] = 3; - ptr[1] = EIR_APPEARANCE; - put_unaligned_le16(hdev->appearance, ptr + 2); - scan_rsp_len += 4; + scan_rsp_len = append_appearance(hdev, ptr, scan_rsp_len); } - return append_local_name(hdev, ptr + scan_rsp_len, scan_rsp_len); + return append_local_name(hdev, ptr, scan_rsp_len); } static u8 create_instance_scan_rsp_data(struct hci_dev *hdev, u8 instance, @@ -1048,18 +1039,13 @@ static u8 create_instance_scan_rsp_data(struct hci_dev *hdev, u8 instance, instance_flags = adv_instance->flags; if ((instance_flags & MGMT_ADV_FLAG_APPEARANCE) && hdev->appearance) { - ptr[0] = 3; - ptr[1] = EIR_APPEARANCE; - put_unaligned_le16(hdev->appearance, ptr + 2); - scan_rsp_len += 4; - ptr += 4; + scan_rsp_len = append_appearance(hdev, ptr, scan_rsp_len); } - memcpy(ptr, adv_instance->scan_rsp_data, + memcpy(&ptr[scan_rsp_len], adv_instance->scan_rsp_data, adv_instance->scan_rsp_len); scan_rsp_len += adv_instance->scan_rsp_len; - ptr += adv_instance->scan_rsp_len; if (instance_flags & MGMT_ADV_FLAG_LOCAL_NAME) scan_rsp_len = append_local_name(hdev, ptr, scan_rsp_len); diff --git a/net/bluetooth/hci_request.h b/net/bluetooth/hci_request.h index ac1e110..6b06629 100644 --- a/net/bluetooth/hci_request.h +++ b/net/bluetooth/hci_request.h @@ -20,6 +20,8 @@ SOFTWARE IS DISCLAIMED. */ +#include <asm/unaligned.h> + #define hci_req_sync_lock(hdev) mutex_lock(&hdev->req_lock) #define hci_req_sync_unlock(hdev) mutex_unlock(&hdev->req_lock) @@ -103,3 +105,24 @@ static inline void hci_update_background_scan(struct hci_dev *hdev) void hci_request_setup(struct hci_dev *hdev); void hci_request_cancel_all(struct hci_dev *hdev); + +static inline u16 eir_append_data(u8 *eir, u16 eir_len, u8 type, + u8 *data, u8 data_len) +{ + eir[eir_len++] = sizeof(type) + data_len; + eir[eir_len++] = type; + memcpy(&eir[eir_len], data, data_len); + eir_len += data_len; + + return eir_len; +} + +static inline u16 eir_append_le16(u8 *eir, u16 eir_len, u8 type, u16 data) +{ + eir[eir_len++] = sizeof(type) + sizeof(data); + eir[eir_len++] = type; + put_unaligned_le16(data, &eir[eir_len]); + eir_len += sizeof(data); + + return eir_len; +} diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index 19b8a5e..7360380 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -867,27 +867,6 @@ static int read_controller_info(struct sock *sk, struct hci_dev *hdev, sizeof(rp)); } -static inline u16 eir_append_data(u8 *eir, u16 eir_len, u8 type, u8 *data, - u8 data_len) -{ - eir[eir_len++] = sizeof(type) + data_len; - eir[eir_len++] = type; - memcpy(&eir[eir_len], data, data_len); - eir_len += data_len; - - return eir_len; -} - -static inline u16 eir_append_le16(u8 *eir, u16 eir_len, u8 type, u16 data) -{ - eir[eir_len++] = sizeof(type) + sizeof(data); - eir[eir_len++] = type; - put_unaligned_le16(data, &eir[eir_len]); - eir_len += sizeof(data); - - return eir_len; -} - static u16 append_eir_data_to_buf(struct hci_dev *hdev, u8 *eir) { u16 eir_len = 0; -- 2.7.4 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 1/3] Bluetooth: Fix local name in scan rsp 2016-10-05 10:28 [PATCH 1/3] Bluetooth: Fix local name in scan rsp Michał Narajowski 2016-10-05 10:28 ` [PATCH 2/3] Bluetooth: Add appearance to default scan rsp data Michał Narajowski 2016-10-05 10:28 ` [PATCH 3/3] Bluetooth: Refactor append name and appearance Michał Narajowski @ 2016-10-05 11:19 ` Marcel Holtmann 2 siblings, 0 replies; 8+ messages in thread From: Marcel Holtmann @ 2016-10-05 11:19 UTC (permalink / raw) To: Michał Narajowski; +Cc: linux-bluetooth Hi Michal, > Use complete name if it fits. If not and there is short name > check if it fits. If not then use shortened name as prefix > of complete name. > > Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl> > --- > net/bluetooth/hci_request.c | 47 +++++++++++++++++++++++++++++++++------------ > 1 file changed, 35 insertions(+), 12 deletions(-) all 3 patches have been applied to bluetooth-next tree. Regards Marcel ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/3] Bluetooth: Fix local name in scan rsp @ 2016-09-22 14:01 Michał Narajowski 2016-09-22 15:47 ` Marcel Holtmann 0 siblings, 1 reply; 8+ messages in thread From: Michał Narajowski @ 2016-09-22 14:01 UTC (permalink / raw) To: linux-bluetooth; +Cc: Michał Narajowski Use complete name if it fits. If not and there is short name check if it fits. If not then use shortened name as prefix of complete name. Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl> --- net/bluetooth/hci_request.c | 46 +++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c index c813568..880758c 100644 --- a/net/bluetooth/hci_request.c +++ b/net/bluetooth/hci_request.c @@ -973,25 +973,47 @@ void __hci_req_enable_advertising(struct hci_request *req) static u8 append_local_name(struct hci_dev *hdev, u8 *ptr, u8 ad_len) { - size_t name_len; + size_t complete_len; + size_t short_len; int max_len; max_len = HCI_MAX_AD_LENGTH - ad_len - 2; - name_len = strlen(hdev->dev_name); - if (name_len > 0 && max_len > 0) { + complete_len = strlen(hdev->dev_name); + short_len = strlen(hdev->short_name); - if (name_len > max_len) { - name_len = max_len; - ptr[1] = EIR_NAME_SHORT; - } else - ptr[1] = EIR_NAME_COMPLETE; + /* no space left for name */ + if (max_len < 1) + return ad_len; - ptr[0] = name_len + 1; + /* no name set */ + if (!complete_len) + return ad_len; - memcpy(ptr + 2, hdev->dev_name, name_len); + /* complete name fits */ + if (complete_len <= max_len) { + ptr[0] = complete_len + 1; + ptr[1] = EIR_NAME_COMPLETE; + memcpy(ptr + 2, hdev->dev_name, complete_len); - ad_len += (name_len + 2); - ptr += (name_len + 2); + return ad_len + complete_len + 2; + } + + /* shortened name set and fits */ + if (short_len && short_len <= max_len) { + ptr[0] = short_len + 1; + ptr[1] = EIR_NAME_SHORT; + memcpy(ptr + 2, hdev->short_name, short_len); + + return ad_len + short_len + 2; + } + + /* no shortened name set so shorten complete name */ + if (!short_len) { + ptr[0] = max_len + 1; + ptr[1] = EIR_NAME_SHORT; + memcpy(ptr + 2, hdev->dev_name, max_len); + + return ad_len + max_len + 2; } return ad_len; -- 2.7.4 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 1/3] Bluetooth: Fix local name in scan rsp 2016-09-22 14:01 Michał Narajowski @ 2016-09-22 15:47 ` Marcel Holtmann 2016-09-22 19:07 ` Szymon Janc 0 siblings, 1 reply; 8+ messages in thread From: Marcel Holtmann @ 2016-09-22 15:47 UTC (permalink / raw) To: Michał Narajowski; +Cc: linux-bluetooth Hi Michal, > Use complete name if it fits. If not and there is short name > check if it fits. If not then use shortened name as prefix > of complete name. > > Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl> > --- > net/bluetooth/hci_request.c | 46 +++++++++++++++++++++++++++++++++------------ > 1 file changed, 34 insertions(+), 12 deletions(-) > > diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c > index c813568..880758c 100644 > --- a/net/bluetooth/hci_request.c > +++ b/net/bluetooth/hci_request.c > @@ -973,25 +973,47 @@ void __hci_req_enable_advertising(struct hci_request *req) > > static u8 append_local_name(struct hci_dev *hdev, u8 *ptr, u8 ad_len) > { > - size_t name_len; > + size_t complete_len; > + size_t short_len; > int max_len; > > max_len = HCI_MAX_AD_LENGTH - ad_len - 2; > - name_len = strlen(hdev->dev_name); > - if (name_len > 0 && max_len > 0) { > + complete_len = strlen(hdev->dev_name); > + short_len = strlen(hdev->short_name); > > - if (name_len > max_len) { > - name_len = max_len; > - ptr[1] = EIR_NAME_SHORT; > - } else > - ptr[1] = EIR_NAME_COMPLETE; > + /* no space left for name */ > + if (max_len < 1) > + return ad_len; > > - ptr[0] = name_len + 1; > + /* no name set */ > + if (!complete_len) > + return ad_len; > > - memcpy(ptr + 2, hdev->dev_name, name_len); > + /* complete name fits */ > + if (complete_len <= max_len) { > + ptr[0] = complete_len + 1; > + ptr[1] = EIR_NAME_COMPLETE; > + memcpy(ptr + 2, hdev->dev_name, complete_len); > > - ad_len += (name_len + 2); > - ptr += (name_len + 2); > + return ad_len + complete_len + 2; > + } so what we discussed is that at minimum 11 octets of name will be included into the scan response. That is the same size of the Short_name (which includes the nul-byte). If the full name is 11 octets or smaller, then that is included. If the full name is longer and a short name has been set, then the short name is used. If the short name is not set, then the full name is truncated to 11 octets. For the case where the full name is 11 octets or smaller, the complete tag is used. For the case where the short name is used or the full name is truncated, the partial tag is used. > + > + /* shortened name set and fits */ Just a note here, it is not called shortened name. It is the short name. We clearly separated the full name vs short name in the mgmt API. Regards Marcel ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/3] Bluetooth: Fix local name in scan rsp 2016-09-22 15:47 ` Marcel Holtmann @ 2016-09-22 19:07 ` Szymon Janc 2016-09-22 19:56 ` Marcel Holtmann 0 siblings, 1 reply; 8+ messages in thread From: Szymon Janc @ 2016-09-22 19:07 UTC (permalink / raw) To: Marcel Holtmann; +Cc: Michał Narajowski, linux-bluetooth Hi Marcel, On Thursday, 22 September 2016 17:47:15 CEST Marcel Holtmann wrote: > Hi Michal, >=20 > > Use complete name if it fits. If not and there is short name > > check if it fits. If not then use shortened name as prefix > > of complete name. > >=20 > > Signed-off-by: Micha=C5=82 Narajowski <michal.narajowski@codecoup.pl> > > --- > > net/bluetooth/hci_request.c | 46 > > +++++++++++++++++++++++++++++++++------------ 1 file changed, 34 > > insertions(+), 12 deletions(-) > >=20 > > diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c > > index c813568..880758c 100644 > > --- a/net/bluetooth/hci_request.c > > +++ b/net/bluetooth/hci_request.c > > @@ -973,25 +973,47 @@ void __hci_req_enable_advertising(struct hci_requ= est > > *req) > >=20 > > static u8 append_local_name(struct hci_dev *hdev, u8 *ptr, u8 ad_len) > > { > > - size_t name_len; > > + size_t complete_len; > > + size_t short_len; > >=20 > > int max_len; > > =09 > > max_len =3D HCI_MAX_AD_LENGTH - ad_len - 2; > >=20 > > - name_len =3D strlen(hdev->dev_name); > > - if (name_len > 0 && max_len > 0) { > > + complete_len =3D strlen(hdev->dev_name); > > + short_len =3D strlen(hdev->short_name); > >=20 > > - if (name_len > max_len) { > > - name_len =3D max_len; > > - ptr[1] =3D EIR_NAME_SHORT; > > - } else > > - ptr[1] =3D EIR_NAME_COMPLETE; > > + /* no space left for name */ > > + if (max_len < 1) > > + return ad_len; > >=20 > > - ptr[0] =3D name_len + 1; > > + /* no name set */ > > + if (!complete_len) > > + return ad_len; > >=20 > > - memcpy(ptr + 2, hdev->dev_name, name_len); > > + /* complete name fits */ > > + if (complete_len <=3D max_len) { > > + ptr[0] =3D complete_len + 1; > > + ptr[1] =3D EIR_NAME_COMPLETE; > > + memcpy(ptr + 2, hdev->dev_name, complete_len); > >=20 > > - ad_len +=3D (name_len + 2); > > - ptr +=3D (name_len + 2); > > + return ad_len + complete_len + 2; > > + } >=20 > so what we discussed is that at minimum 11 octets of name will be included > into the scan response. That is the same size of the Short_name (which > includes the nul-byte). minimum? And do we need to put null byte there? >=20 > If the full name is 11 octets or smaller, then that is included. If the f= ull > name is longer and a short name has been set, then the short name is used. > If the short name is not set, then the full name is truncated to 11 octet= s. >=20 > For the case where the full name is 11 octets or smaller, the complete tag > is used. For the case where the short name is used or the full name is > truncated, the partial tag is used. So we never include full name if it is longer then 11 octets (with null)? BTW where this 11 octets value came from? I cannot find such requirement in= =20 spec. Or this is just limited on mgmt interface level? I don't undertand why not to include complete name if it fits, even if long= er=20 than 11 octets. > > + > > + /* shortened name set and fits */ >=20 > Just a note here, it is not called shortened name. It is the short name. = We > clearly separated the full name vs short name in the mgmt API. It is called 'shortened' in both CoreSpec and CSS.=20 > Regards >=20 > Marcel >=20 > -- > To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" > in the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html =2D-=20 pozdrawiam Szymon Janc ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/3] Bluetooth: Fix local name in scan rsp 2016-09-22 19:07 ` Szymon Janc @ 2016-09-22 19:56 ` Marcel Holtmann 0 siblings, 0 replies; 8+ messages in thread From: Marcel Holtmann @ 2016-09-22 19:56 UTC (permalink / raw) To: Szymon Janc; +Cc: Michał Narajowski, linux-bluetooth Hi Szymon, >>> Use complete name if it fits. If not and there is short name >>> check if it fits. If not then use shortened name as prefix >>> of complete name. >>> >>> Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl> >>> --- >>> net/bluetooth/hci_request.c | 46 >>> +++++++++++++++++++++++++++++++++------------ 1 file changed, 34 >>> insertions(+), 12 deletions(-) >>> >>> diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c >>> index c813568..880758c 100644 >>> --- a/net/bluetooth/hci_request.c >>> +++ b/net/bluetooth/hci_request.c >>> @@ -973,25 +973,47 @@ void __hci_req_enable_advertising(struct hci_request >>> *req) >>> >>> static u8 append_local_name(struct hci_dev *hdev, u8 *ptr, u8 ad_len) >>> { >>> - size_t name_len; >>> + size_t complete_len; >>> + size_t short_len; >>> >>> int max_len; >>> >>> max_len = HCI_MAX_AD_LENGTH - ad_len - 2; >>> >>> - name_len = strlen(hdev->dev_name); >>> - if (name_len > 0 && max_len > 0) { >>> + complete_len = strlen(hdev->dev_name); >>> + short_len = strlen(hdev->short_name); >>> >>> - if (name_len > max_len) { >>> - name_len = max_len; >>> - ptr[1] = EIR_NAME_SHORT; >>> - } else >>> - ptr[1] = EIR_NAME_COMPLETE; >>> + /* no space left for name */ >>> + if (max_len < 1) >>> + return ad_len; >>> >>> - ptr[0] = name_len + 1; >>> + /* no name set */ >>> + if (!complete_len) >>> + return ad_len; >>> >>> - memcpy(ptr + 2, hdev->dev_name, name_len); >>> + /* complete name fits */ >>> + if (complete_len <= max_len) { >>> + ptr[0] = complete_len + 1; >>> + ptr[1] = EIR_NAME_COMPLETE; >>> + memcpy(ptr + 2, hdev->dev_name, complete_len); >>> >>> - ad_len += (name_len + 2); >>> - ptr += (name_len + 2); >>> + return ad_len + complete_len + 2; >>> + } >> >> so what we discussed is that at minimum 11 octets of name will be included >> into the scan response. That is the same size of the Short_name (which >> includes the nul-byte). > > minimum? And do we need to put null byte there? I think the term maximum would have been better. 1-11 octets of name should be included. For the nul-byte, we need to double check the spec., but I think it is required to be included. If not, then we can leave it out. >> If the full name is 11 octets or smaller, then that is included. If the full >> name is longer and a short name has been set, then the short name is used. >> If the short name is not set, then the full name is truncated to 11 octets. >> >> For the case where the full name is 11 octets or smaller, the complete tag >> is used. For the case where the short name is used or the full name is >> truncated, the partial tag is used. > > So we never include full name if it is longer then 11 octets (with null)? > BTW where this 11 octets value came from? I cannot find such requirement in > spec. Or this is just limited on mgmt interface level? Until we have longer advertising packets, I think the 11 octets sound like a good compromise. Userspace can always decide to drive scan response by itself. Or do you have a better idea for a policy? The 11 octets is a mgmt limit for the short name. We decided on that when inventing mgmt interface. > I don't undertand why not to include complete name if it fits, even if longer > than 11 octets. Feel free to define the policy then. It gets really complicated if userspace wants to include appearance, name and then its own data. If the name occupies the rest. Also when to decide when to use the short name vs long name. If we limit at the short name size, then the policy is simple. >>> + >>> + /* shortened name set and fits */ >> >> Just a note here, it is not called shortened name. It is the short name. We >> clearly separated the full name vs short name in the mgmt API. > > It is called 'shortened' in both CoreSpec and CSS. And short name in mgmt. Regards Marcel ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2016-10-05 11:19 UTC | newest] Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2016-10-05 10:28 [PATCH 1/3] Bluetooth: Fix local name in scan rsp Michał Narajowski 2016-10-05 10:28 ` [PATCH 2/3] Bluetooth: Add appearance to default scan rsp data Michał Narajowski 2016-10-05 10:28 ` [PATCH 3/3] Bluetooth: Refactor append name and appearance Michał Narajowski 2016-10-05 11:19 ` [PATCH 1/3] Bluetooth: Fix local name in scan rsp Marcel Holtmann -- strict thread matches above, loose matches on Subject: below -- 2016-09-22 14:01 Michał Narajowski 2016-09-22 15:47 ` Marcel Holtmann 2016-09-22 19:07 ` Szymon Janc 2016-09-22 19:56 ` Marcel Holtmann
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.