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