From 5bf4d7844fc8da92008f6319d7c5a395de86cabe Mon Sep 17 00:00:00 2001 From: Miao-chen Chou Date: Mon, 17 Aug 2020 23:19:39 -0700 Subject: [PATCH] shared/ad: move MAX_ADV_DATA_LEN macro to the header This moves MAX_ADV_DATA_LEN macro to src/shared/ad.h and rename it to BT_AD_MAX_DATA_LEN. Signed-off-by: Anuj Jain Signed-off-by: Ayush Garg --- 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 e112393..223e8eb 100755 --- a/src/shared/ad.c +++ b/src/shared/ad.c @@ -27,8 +27,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; @@ -251,8 +249,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; } @@ -420,9 +418,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; @@ -472,7 +470,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); @@ -580,7 +578,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, @@ -717,7 +715,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); @@ -936,7 +934,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 19aa1d0..17e3b63 100755 --- 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.7.4