All of lore.kernel.org
 help / color / mirror / Atom feed
* [BlueZ PATCH v3] shared/ad: move MAX_ADV_DATA_LEN macro to the header
@ 2020-08-18  6:19 Miao-chen Chou
  2020-08-18 23:52 ` Luiz Augusto von Dentz
  0 siblings, 1 reply; 2+ messages in thread
From: Miao-chen Chou @ 2020-08-18  6:19 UTC (permalink / raw)
  To: Bluetooth Kernel Mailing List
  Cc: Alain Michaud, Howard Chung, Luiz Augusto von Dentz,
	Manish Mandlik, Miao-chen Chou

This moves MAX_ADV_DATA_LEN macro to src/shared/ad.h and rename it to
BT_AD_MAX_DATA_LEN.
---
Hi Maintainers,

In order to avoid duplicate definition of the maximum data length of
advertisement for the following series of advertisement monitor API,
we'd like to reuse the one in shared/ad.

Thanks,
Miao

Changes in v3:
- Fix occurrences of MAX_ADV_DATA_LEN.

Changes in v2:
- Rename the macro to BT_AD_MAX_DATA_LEN.

 src/shared/ad.c | 18 ++++++++----------
 src/shared/ad.h |  2 ++
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/shared/ad.c b/src/shared/ad.c
index 8d276842e..14a2709b1 100644
--- a/src/shared/ad.c
+++ b/src/shared/ad.c
@@ -33,8 +33,6 @@
 #include "src/shared/queue.h"
 #include "src/shared/util.h"
 
-#define MAX_ADV_DATA_LEN 31
-
 struct bt_ad {
 	int ref_count;
 	char *name;
@@ -257,8 +255,8 @@ static size_t name_length(const char *name, size_t *pos)
 
 	len = 2 + strlen(name);
 
-	if (len > MAX_ADV_DATA_LEN - *pos)
-		len = MAX_ADV_DATA_LEN - *pos;
+	if (len > BT_AD_MAX_DATA_LEN - *pos)
+		len = BT_AD_MAX_DATA_LEN - *pos;
 
 	return len;
 }
@@ -426,9 +424,9 @@ static void serialize_name(const char *name, uint8_t *buf, uint8_t *pos)
 		return;
 
 	len = strlen(name);
-	if (len > MAX_ADV_DATA_LEN - (*pos + 2)) {
+	if (len > BT_AD_MAX_DATA_LEN - (*pos + 2)) {
 		type = BT_AD_NAME_SHORT;
-		len = MAX_ADV_DATA_LEN - (*pos + 2);
+		len = BT_AD_MAX_DATA_LEN - (*pos + 2);
 	}
 
 	buf[(*pos)++] = len + 1;
@@ -478,7 +476,7 @@ uint8_t *bt_ad_generate(struct bt_ad *ad, size_t *length)
 
 	*length = calculate_length(ad);
 
-	if (*length > MAX_ADV_DATA_LEN)
+	if (*length > BT_AD_MAX_DATA_LEN)
 		return NULL;
 
 	adv_data = malloc0(*length);
@@ -586,7 +584,7 @@ bool bt_ad_add_manufacturer_data(struct bt_ad *ad, uint16_t manufacturer_id,
 	if (!ad)
 		return false;
 
-	if (len > (MAX_ADV_DATA_LEN - 2 - sizeof(uint16_t)))
+	if (len > (BT_AD_MAX_DATA_LEN - 2 - sizeof(uint16_t)))
 		return false;
 
 	new_data = queue_find(ad->manufacturer_data, manufacturer_id_data_match,
@@ -723,7 +721,7 @@ bool bt_ad_add_service_data(struct bt_ad *ad, const bt_uuid_t *uuid, void *data,
 	if (!ad)
 		return false;
 
-	if (len > (MAX_ADV_DATA_LEN - 2 - (size_t)bt_uuid_len(uuid)))
+	if (len > (BT_AD_MAX_DATA_LEN - 2 - (size_t)bt_uuid_len(uuid)))
 		return false;
 
 	new_data = queue_find(ad->service_data, service_uuid_match, uuid);
@@ -942,7 +940,7 @@ bool bt_ad_add_data(struct bt_ad *ad, uint8_t type, void *data, size_t len)
 	if (!ad)
 		return false;
 
-	if (len > (MAX_ADV_DATA_LEN - 2))
+	if (len > (BT_AD_MAX_DATA_LEN - 2))
 		return false;
 
 	for (i = 0; i < sizeof(type_blacklist); i++) {
diff --git a/src/shared/ad.h b/src/shared/ad.h
index 19aa1d035..17e3b631b 100644
--- a/src/shared/ad.h
+++ b/src/shared/ad.h
@@ -27,6 +27,8 @@
 #include "lib/bluetooth.h"
 #include "lib/uuid.h"
 
+#define BT_AD_MAX_DATA_LEN		31
+
 #define BT_AD_FLAGS			0x01
 #define BT_AD_UUID16_SOME		0x02
 #define BT_AD_UUID16_ALL		0x03
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [BlueZ PATCH v3] shared/ad: move MAX_ADV_DATA_LEN macro to the header
  2020-08-18  6:19 [BlueZ PATCH v3] shared/ad: move MAX_ADV_DATA_LEN macro to the header Miao-chen Chou
@ 2020-08-18 23:52 ` Luiz Augusto von Dentz
  0 siblings, 0 replies; 2+ messages in thread
From: Luiz Augusto von Dentz @ 2020-08-18 23:52 UTC (permalink / raw)
  To: Miao-chen Chou
  Cc: Bluetooth Kernel Mailing List, Alain Michaud, Howard Chung,
	Luiz Augusto von Dentz, Manish Mandlik

Hi Miao-chen,

On Mon, Aug 17, 2020 at 11:23 PM Miao-chen Chou <mcchou@chromium.org> wrote:
>
> This moves MAX_ADV_DATA_LEN macro to src/shared/ad.h and rename it to
> BT_AD_MAX_DATA_LEN.
> ---
> Hi Maintainers,
>
> In order to avoid duplicate definition of the maximum data length of
> advertisement for the following series of advertisement monitor API,
> we'd like to reuse the one in shared/ad.
>
> Thanks,
> Miao
>
> Changes in v3:
> - Fix occurrences of MAX_ADV_DATA_LEN.
>
> Changes in v2:
> - Rename the macro to BT_AD_MAX_DATA_LEN.
>
>  src/shared/ad.c | 18 ++++++++----------
>  src/shared/ad.h |  2 ++
>  2 files changed, 10 insertions(+), 10 deletions(-)
>
> diff --git a/src/shared/ad.c b/src/shared/ad.c
> index 8d276842e..14a2709b1 100644
> --- a/src/shared/ad.c
> +++ b/src/shared/ad.c
> @@ -33,8 +33,6 @@
>  #include "src/shared/queue.h"
>  #include "src/shared/util.h"
>
> -#define MAX_ADV_DATA_LEN 31
> -
>  struct bt_ad {
>         int ref_count;
>         char *name;
> @@ -257,8 +255,8 @@ static size_t name_length(const char *name, size_t *pos)
>
>         len = 2 + strlen(name);
>
> -       if (len > MAX_ADV_DATA_LEN - *pos)
> -               len = MAX_ADV_DATA_LEN - *pos;
> +       if (len > BT_AD_MAX_DATA_LEN - *pos)
> +               len = BT_AD_MAX_DATA_LEN - *pos;
>
>         return len;
>  }
> @@ -426,9 +424,9 @@ static void serialize_name(const char *name, uint8_t *buf, uint8_t *pos)
>                 return;
>
>         len = strlen(name);
> -       if (len > MAX_ADV_DATA_LEN - (*pos + 2)) {
> +       if (len > BT_AD_MAX_DATA_LEN - (*pos + 2)) {
>                 type = BT_AD_NAME_SHORT;
> -               len = MAX_ADV_DATA_LEN - (*pos + 2);
> +               len = BT_AD_MAX_DATA_LEN - (*pos + 2);
>         }
>
>         buf[(*pos)++] = len + 1;
> @@ -478,7 +476,7 @@ uint8_t *bt_ad_generate(struct bt_ad *ad, size_t *length)
>
>         *length = calculate_length(ad);
>
> -       if (*length > MAX_ADV_DATA_LEN)
> +       if (*length > BT_AD_MAX_DATA_LEN)
>                 return NULL;
>
>         adv_data = malloc0(*length);
> @@ -586,7 +584,7 @@ bool bt_ad_add_manufacturer_data(struct bt_ad *ad, uint16_t manufacturer_id,
>         if (!ad)
>                 return false;
>
> -       if (len > (MAX_ADV_DATA_LEN - 2 - sizeof(uint16_t)))
> +       if (len > (BT_AD_MAX_DATA_LEN - 2 - sizeof(uint16_t)))
>                 return false;
>
>         new_data = queue_find(ad->manufacturer_data, manufacturer_id_data_match,
> @@ -723,7 +721,7 @@ bool bt_ad_add_service_data(struct bt_ad *ad, const bt_uuid_t *uuid, void *data,
>         if (!ad)
>                 return false;
>
> -       if (len > (MAX_ADV_DATA_LEN - 2 - (size_t)bt_uuid_len(uuid)))
> +       if (len > (BT_AD_MAX_DATA_LEN - 2 - (size_t)bt_uuid_len(uuid)))
>                 return false;
>
>         new_data = queue_find(ad->service_data, service_uuid_match, uuid);
> @@ -942,7 +940,7 @@ bool bt_ad_add_data(struct bt_ad *ad, uint8_t type, void *data, size_t len)
>         if (!ad)
>                 return false;
>
> -       if (len > (MAX_ADV_DATA_LEN - 2))
> +       if (len > (BT_AD_MAX_DATA_LEN - 2))
>                 return false;
>
>         for (i = 0; i < sizeof(type_blacklist); i++) {
> diff --git a/src/shared/ad.h b/src/shared/ad.h
> index 19aa1d035..17e3b631b 100644
> --- a/src/shared/ad.h
> +++ b/src/shared/ad.h
> @@ -27,6 +27,8 @@
>  #include "lib/bluetooth.h"
>  #include "lib/uuid.h"
>
> +#define BT_AD_MAX_DATA_LEN             31
> +
>  #define BT_AD_FLAGS                    0x01
>  #define BT_AD_UUID16_SOME              0x02
>  #define BT_AD_UUID16_ALL               0x03
> --
> 2.26.2

Applied, thanks.

-- 
Luiz Augusto von Dentz

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-08-18 23:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-18  6:19 [BlueZ PATCH v3] shared/ad: move MAX_ADV_DATA_LEN macro to the header Miao-chen Chou
2020-08-18 23:52 ` Luiz Augusto von Dentz

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.