Bluetooth: Host: Add const prefix for UUID

Add const prefix for service uuid and char uuid.

Since Service UUID and Char UUID should not change in the service
definition, they are most reasonably defined as rodata, also for
save some ram footprint.

The field `attr->user_data` type is `void *`, as this PR change
all Service UUID to rodata, so there must add (void *) to avoid warning.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
This commit is contained in:
Lingao Meng 2023-12-05 17:52:21 +08:00 committed by Fabio Baltieri
commit 786b9a0ad4
35 changed files with 81 additions and 79 deletions

View file

@ -113,7 +113,7 @@ static bool eir_found(struct bt_data *data, void *user_data)
for (i = 0; i < data->data_len; i += sizeof(uint16_t)) {
struct bt_le_conn_param *param;
struct bt_uuid *uuid;
const struct bt_uuid *uuid;
uint16_t u16;
int err;

View file

@ -174,7 +174,7 @@ static bool eir_found(struct bt_data *data, void *user_data)
}
for (i = 0; i < data->data_len; i += sizeof(uint16_t)) {
struct bt_uuid *uuid;
const struct bt_uuid *uuid;
uint16_t u16;
int err;

View file

@ -237,7 +237,7 @@ static bool eir_found(struct bt_data *data, void *user_data)
for (i = 0; i < data->data_len; i += sizeof(uint16_t)) {
struct bt_le_conn_param *param;
struct bt_uuid *uuid;
const struct bt_uuid *uuid;
uint16_t u16;
int err;

View file

@ -23,13 +23,13 @@
#define BT_UUID_CUSTOM_SERVICE_VAL \
BT_UUID_128_ENCODE(0x12345678, 0x1234, 0x5678, 0x1234, 0x56789abcdef0)
static struct bt_uuid_128 primary_service_uuid = BT_UUID_INIT_128(
static const struct bt_uuid_128 primary_service_uuid = BT_UUID_INIT_128(
BT_UUID_CUSTOM_SERVICE_VAL);
static struct bt_uuid_128 read_characteristic_uuid = BT_UUID_INIT_128(
static const struct bt_uuid_128 read_characteristic_uuid = BT_UUID_INIT_128(
BT_UUID_128_ENCODE(0x12345678, 0x1234, 0x5678, 0x1234, 0x56789abcdef1));
static struct bt_uuid_128 write_characteristic_uuid = BT_UUID_INIT_128(
static const struct bt_uuid_128 write_characteristic_uuid = BT_UUID_INIT_128(
BT_UUID_128_ENCODE(0x12345678, 0x1234, 0x5678, 0x1234, 0x56789abcdef2));
static int signed_value;

View file

@ -40,55 +40,55 @@ static const struct bt_data ad[] = {
/* Eddystone Service Variables */
/* Service UUID a3c87500-8ed3-4bdf-8a39-a01bebede295 */
static struct bt_uuid_128 eds_uuid = BT_UUID_INIT_128(
static const struct bt_uuid_128 eds_uuid = BT_UUID_INIT_128(
BT_UUID_128_ENCODE(0xa3c87500, 0x8ed3, 0x4bdf, 0x8a39, 0xa01bebede295));
/* Characteristic UUID a3c87501-8ed3-4bdf-8a39-a01bebede295 */
static struct bt_uuid_128 eds_caps_uuid = BT_UUID_INIT_128(
static const struct bt_uuid_128 eds_caps_uuid = BT_UUID_INIT_128(
BT_UUID_128_ENCODE(0xa3c87501, 0x8ed3, 0x4bdf, 0x8a39, 0xa01bebede295));
/* Characteristic UUID a3c87502-8ed3-4bdf-8a39-a01bebede295 */
static struct bt_uuid_128 eds_slot_uuid = BT_UUID_INIT_128(
static const struct bt_uuid_128 eds_slot_uuid = BT_UUID_INIT_128(
BT_UUID_128_ENCODE(0xa3c87502, 0x8ed3, 0x4bdf, 0x8a39, 0xa01bebede295));
/* Characteristic UUID a3c87503-8ed3-4bdf-8a39-a01bebede295 */
static struct bt_uuid_128 eds_intv_uuid = BT_UUID_INIT_128(
static const struct bt_uuid_128 eds_intv_uuid = BT_UUID_INIT_128(
BT_UUID_128_ENCODE(0xa3c87503, 0x8ed3, 0x4bdf, 0x8a39, 0xa01bebede295));
/* Characteristic UUID a3c87504-8ed3-4bdf-8a39-a01bebede295 */
static struct bt_uuid_128 eds_tx_uuid = BT_UUID_INIT_128(
static const struct bt_uuid_128 eds_tx_uuid = BT_UUID_INIT_128(
BT_UUID_128_ENCODE(0xa3c87504, 0x8ed3, 0x4bdf, 0x8a39, 0xa01bebede295));
/* Characteristic UUID a3c87505-8ed3-4bdf-8a39-a01bebede295 */
static struct bt_uuid_128 eds_adv_tx_uuid = BT_UUID_INIT_128(
static const struct bt_uuid_128 eds_adv_tx_uuid = BT_UUID_INIT_128(
BT_UUID_128_ENCODE(0xa3c87505, 0x8ed3, 0x4bdf, 0x8a39, 0xa01bebede295));
/* Characteristic UUID a3c87506-8ed3-4bdf-8a39-a01bebede295 */
static struct bt_uuid_128 eds_lock_uuid = BT_UUID_INIT_128(
static const struct bt_uuid_128 eds_lock_uuid = BT_UUID_INIT_128(
BT_UUID_128_ENCODE(0xa3c87506, 0x8ed3, 0x4bdf, 0x8a39, 0xa01bebede295));
/* Characteristic UUID a3c87507-8ed3-4bdf-8a39-a01bebede295 */
static struct bt_uuid_128 eds_unlock_uuid = BT_UUID_INIT_128(
static const struct bt_uuid_128 eds_unlock_uuid = BT_UUID_INIT_128(
BT_UUID_128_ENCODE(0xa3c87507, 0x8ed3, 0x4bdf, 0x8a39, 0xa01bebede295));
/* Characteristic UUID a3c87508-8ed3-4bdf-8a39-a01bebede295 */
static struct bt_uuid_128 eds_ecdh_uuid = BT_UUID_INIT_128(
static const struct bt_uuid_128 eds_ecdh_uuid = BT_UUID_INIT_128(
BT_UUID_128_ENCODE(0xa3c87508, 0x8ed3, 0x4bdf, 0x8a39, 0xa01bebede295));
/* Characteristic UUID a3c87509-8ed3-4bdf-8a39-a01bebede295 */
static struct bt_uuid_128 eds_eid_uuid = BT_UUID_INIT_128(
static const struct bt_uuid_128 eds_eid_uuid = BT_UUID_INIT_128(
BT_UUID_128_ENCODE(0xa3c87509, 0x8ed3, 0x4bdf, 0x8a39, 0xa01bebede295));
/* Characteristic UUID a3c8750a-8ed3-4bdf-8a39-a01bebede295 */
static struct bt_uuid_128 eds_data_uuid = BT_UUID_INIT_128(
static const struct bt_uuid_128 eds_data_uuid = BT_UUID_INIT_128(
BT_UUID_128_ENCODE(0xa3c8750a, 0x8ed3, 0x4bdf, 0x8a39, 0xa01bebede295));
/* Characteristic UUID a3c8750b-8ed3-4bdf-8a39-a01bebede295 */
static struct bt_uuid_128 eds_reset_uuid = BT_UUID_INIT_128(
static const struct bt_uuid_128 eds_reset_uuid = BT_UUID_INIT_128(
BT_UUID_128_ENCODE(0xa3c8750b, 0x8ed3, 0x4bdf, 0x8a39, 0xa01bebede295));
/* Characteristic UUID a3c8750c-8ed3-4bdf-8a39-a01bebede295 */
static struct bt_uuid_128 eds_connectable_uuid = BT_UUID_INIT_128(
static const struct bt_uuid_128 eds_connectable_uuid = BT_UUID_INIT_128(
BT_UUID_128_ENCODE(0xa3c8750c, 0x8ed3, 0x4bdf, 0x8a39, 0xa01bebede295));
enum {

View file

@ -16,9 +16,9 @@
#define MTU_TEST_SERVICE_TYPE BT_UUID_128_ENCODE(0x2e2b8dc3, 0x06e0, 0x4f93, 0x9bb2, 0x734091c356f0)
static struct bt_uuid_128 mtu_test_service = BT_UUID_INIT_128(MTU_TEST_SERVICE_TYPE);
static const struct bt_uuid_128 mtu_test_service = BT_UUID_INIT_128(MTU_TEST_SERVICE_TYPE);
static struct bt_uuid_128 notify_characteristic_uuid =
static const struct bt_uuid_128 notify_characteristic_uuid =
BT_UUID_INIT_128(BT_UUID_128_ENCODE(0x2e2b8dc3, 0x06e0, 0x4f93, 0x9bb2, 0x734091c356f3));
static const struct bt_data adv_ad_data[] = {

View file

@ -122,9 +122,9 @@ static struct bt_le_per_adv_sync_cb sync_callbacks = {
.recv = recv_cb,
};
static struct bt_uuid_128 pawr_svc_uuid =
static const struct bt_uuid_128 pawr_svc_uuid =
BT_UUID_INIT_128(BT_UUID_128_ENCODE(0x12345678, 0x1234, 0x5678, 0x1234, 0x56789abcdef0));
static struct bt_uuid_128 pawr_char_uuid =
static const struct bt_uuid_128 pawr_char_uuid =
BT_UUID_INIT_128(BT_UUID_128_ENCODE(0x12345678, 0x1234, 0x5678, 0x1234, 0x56789abcdef1));
static ssize_t write_timing(struct bt_conn *conn, const struct bt_gatt_attr *attr, const void *buf,

View file

@ -31,13 +31,13 @@
#define BT_UUID_CUSTOM_SERVICE_VAL \
BT_UUID_128_ENCODE(0x12345678, 0x1234, 0x5678, 0x1234, 0x56789abcdef0)
static struct bt_uuid_128 vnd_uuid = BT_UUID_INIT_128(
static const struct bt_uuid_128 vnd_uuid = BT_UUID_INIT_128(
BT_UUID_CUSTOM_SERVICE_VAL);
static struct bt_uuid_128 vnd_enc_uuid = BT_UUID_INIT_128(
static const struct bt_uuid_128 vnd_enc_uuid = BT_UUID_INIT_128(
BT_UUID_128_ENCODE(0x12345678, 0x1234, 0x5678, 0x1234, 0x56789abcdef1));
static struct bt_uuid_128 vnd_auth_uuid = BT_UUID_INIT_128(
static const struct bt_uuid_128 vnd_auth_uuid = BT_UUID_INIT_128(
BT_UUID_128_ENCODE(0x12345678, 0x1234, 0x5678, 0x1234, 0x56789abcdef2));
#define VND_MAX_LEN 20

View file

@ -19,13 +19,13 @@
#define BT_UUID_CUSTOM_SERVICE_VAL \
BT_UUID_128_ENCODE(0x12345678, 0x1234, 0x5678, 0x1234, 0x56789abcdef0)
static struct bt_uuid_128 primary_service_uuid = BT_UUID_INIT_128(
static const struct bt_uuid_128 primary_service_uuid = BT_UUID_INIT_128(
BT_UUID_CUSTOM_SERVICE_VAL);
static struct bt_uuid_128 read_characteristic_uuid = BT_UUID_INIT_128(
static const struct bt_uuid_128 read_characteristic_uuid = BT_UUID_INIT_128(
BT_UUID_128_ENCODE(0x12345678, 0x1234, 0x5678, 0x1234, 0x56789abcdef1));
static struct bt_uuid_128 write_characteristic_uuid = BT_UUID_INIT_128(
static const struct bt_uuid_128 write_characteristic_uuid = BT_UUID_INIT_128(
BT_UUID_128_ENCODE(0x12345678, 0x1234, 0x5678, 0x1234, 0x56789abcdef2));
static int signed_value;

View file

@ -36,15 +36,15 @@ static ssize_t recv(struct bt_conn *conn,
uint16_t len, uint16_t offset, uint8_t flags);
/* ST Custom Service */
static struct bt_uuid_128 st_service_uuid = BT_UUID_INIT_128(
static const struct bt_uuid_128 st_service_uuid = BT_UUID_INIT_128(
BT_UUID_128_ENCODE(0x0000fe40, 0xcc7a, 0x482a, 0x984a, 0x7f2ed5b3e58f));
/* ST LED service */
static struct bt_uuid_128 led_char_uuid = BT_UUID_INIT_128(
static const struct bt_uuid_128 led_char_uuid = BT_UUID_INIT_128(
BT_UUID_128_ENCODE(0x0000fe41, 0x8e22, 0x4541, 0x9d4c, 0x21edae82ed19));
/* ST Notify button service */
static struct bt_uuid_128 but_notif_uuid = BT_UUID_INIT_128(
static const struct bt_uuid_128 but_notif_uuid = BT_UUID_INIT_128(
BT_UUID_128_ENCODE(0x0000fe42, 0x8e22, 0x4541, 0x9d4c, 0x21edae82ed19));
#define DEVICE_NAME CONFIG_BT_DEVICE_NAME

View file

@ -138,7 +138,7 @@ static bool check_audio_support_and_connect(struct bt_data *data, void *user_dat
{
bt_addr_le_t *addr = user_data;
struct net_buf_simple tmas_svc_data;
struct bt_uuid *uuid;
const struct bt_uuid *uuid;
uint16_t uuid_val;
uint16_t peer_tmap_role = 0;
int err;

View file

@ -402,7 +402,7 @@ static bool check_audio_support_and_connect(struct bt_data *data,
bt_addr_le_t *addr = user_data;
uint8_t announcement_type;
uint32_t audio_contexts;
struct bt_uuid *uuid;
const struct bt_uuid *uuid;
uint16_t uuid_val;
uint8_t meta_len;
size_t min_size;