Bluetooth: Make use of BT_UUID_DECLARE_16 for services

This makes it simpler to add the services directly into GATT services
table.

Change-Id: I090c7f9396329cf524947dd6647230c663a55f60
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This commit is contained in:
Luiz Augusto von Dentz 2015-12-08 15:27:43 -02:00 committed by Anas Nashif
commit 4a20bc14a7
9 changed files with 107 additions and 254 deletions

View file

@ -324,7 +324,7 @@ int bt_gatt_attr_read_service(struct bt_conn *conn,
*/
#define BT_GATT_PRIMARY_SERVICE(_service) \
{ \
.uuid = BT_UUID_DECLARE_16(BT_UUID_GATT_PRIMARY), \
.uuid = BT_UUID_GATT_PRIMARY, \
.perm = BT_GATT_PERM_READ, \
.read = bt_gatt_attr_read_service, \
.user_data = _service, \
@ -339,7 +339,7 @@ int bt_gatt_attr_read_service(struct bt_conn *conn,
*/
#define BT_GATT_SECONDARY_SERVICE(_service) \
{ \
.uuid = BT_UUID_DECLARE_16(BT_UUID_GATT_SECONDARY), \
.uuid = BT_UUID_GATT_SECONDARY, \
.perm = BT_GATT_PERM_READ, \
.read = bt_gatt_attr_read_service, \
.user_data = _service, \
@ -373,7 +373,7 @@ int bt_gatt_attr_read_included(struct bt_conn *conn,
*/
#define BT_GATT_INCLUDE_SERVICE(_service) \
{ \
.uuid = BT_UUID_DECLARE_16(BT_UUID_GATT_INCLUDE), \
.uuid = BT_UUID_GATT_INCLUDE, \
.perm = BT_GATT_PERM_READ, \
.read = bt_gatt_attr_read_included, \
.user_data = _service, \
@ -408,7 +408,7 @@ int bt_gatt_attr_read_chrc(struct bt_conn *conn,
*/
#define BT_GATT_CHARACTERISTIC(_uuid, _props) \
{ \
.uuid = BT_UUID_DECLARE_16(BT_UUID_GATT_CHRC), \
.uuid = BT_UUID_GATT_CHRC, \
.perm = BT_GATT_PERM_READ, \
.read = bt_gatt_attr_read_chrc, \
.user_data = (&(struct bt_gatt_chrc) { .uuid = _uuid, \
@ -480,7 +480,7 @@ int bt_gatt_attr_write_ccc(struct bt_conn *conn,
*/
#define BT_GATT_CCC(_cfg, _cfg_changed) \
{ \
.uuid = BT_UUID_DECLARE_16(BT_UUID_GATT_CCC), \
.uuid = BT_UUID_GATT_CCC, \
.perm = BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, \
.read = bt_gatt_attr_read_ccc, \
.write = bt_gatt_attr_write_ccc, \
@ -517,7 +517,7 @@ int bt_gatt_attr_read_cep(struct bt_conn *conn,
*/
#define BT_GATT_CEP(_value) \
{ \
.uuid = BT_UUID_DECLARE_16(BT_UUID_GATT_CEP), \
.uuid = BT_UUID_GATT_CEP, \
.perm = BT_GATT_PERM_READ, \
.read = bt_gatt_attr_read_cep, \
.user_data = _value, \

View file

@ -23,119 +23,119 @@
/** @def BBT_UUID_GAP
* @brief Generic Access
*/
#define BT_UUID_GAP 0x1800
#define BT_UUID_GAP BT_UUID_DECLARE_16(0x1800)
/** @def BBT_UUID_GATT
* @brief Generic Attribute
*/
#define BT_UUID_GATT 0x1801
#define BT_UUID_GATT BT_UUID_DECLARE_16(0x1801)
/** @def BBT_UUID_CTS
* @brief Current Time Service
*/
#define BT_UUID_CTS 0x1805
#define BT_UUID_CTS BT_UUID_DECLARE_16(0x1805)
/** @def BBT_UUID_DIS
* @brief Device Information Service
*/
#define BT_UUID_DIS 0x180a
#define BT_UUID_DIS BT_UUID_DECLARE_16(0x180a)
/** @def BBT_UUID_HRS
* @brief Heart Rate Service
*/
#define BT_UUID_HRS 0x180d
#define BT_UUID_HRS BT_UUID_DECLARE_16(0x180d)
/** @def BBT_UUID_BAS
* @brief Battery Service
*/
#define BT_UUID_BAS 0x180f
#define BT_UUID_BAS BT_UUID_DECLARE_16(0x180f)
/** @def BT_UUID_IPSP
* @brief IP Support Service
*/
#define BT_UUID_IPSS 0x1820
#define BT_UUID_IPSS BT_UUID_DECLARE_16(0x1820)
/** @def BT_UUID_GATT_PRIMARY
* @brief GATT Primary Service
*/
#define BT_UUID_GATT_PRIMARY 0x2800
#define BT_UUID_GATT_PRIMARY BT_UUID_DECLARE_16(0x2800)
/** @def BT_UUID_GATT_SECONDARY
* @brief GATT Secondary Service
*/
#define BT_UUID_GATT_SECONDARY 0x2801
#define BT_UUID_GATT_SECONDARY BT_UUID_DECLARE_16(0x2801)
/** @def BT_UUID_GATT_INCLUDE
* @brief GATT Include Service
*/
#define BT_UUID_GATT_INCLUDE 0x2802
#define BT_UUID_GATT_INCLUDE BT_UUID_DECLARE_16(0x2802)
/** @def BT_UUID_GATT_CHRC
* @brief GATT Characteristic
*/
#define BT_UUID_GATT_CHRC 0x2803
#define BT_UUID_GATT_CHRC BT_UUID_DECLARE_16(0x2803)
/** @def BT_UUID_GATT_CEP
* @brief GATT Characteristic Extended Properties
*/
#define BT_UUID_GATT_CEP 0x2900
#define BT_UUID_GATT_CEP BT_UUID_DECLARE_16(0x2900)
/** @def BT_UUID_GATT_CUD
* @brief GATT Characteristic User Description
*/
#define BT_UUID_GATT_CUD 0x2901
#define BT_UUID_GATT_CUD BT_UUID_DECLARE_16(0x2901)
/** @def BT_UUID_GATT_CCC
* @brief GATT Client Characteristic Configuration
*/
#define BT_UUID_GATT_CCC 0x2902
#define BT_UUID_GATT_CCC BT_UUID_DECLARE_16(0x2902)
/** @def BT_UUID_GAP_DEVICE_NAME
* @brief GAP Characteristic Device Name
*/
#define BT_UUID_GAP_DEVICE_NAME 0x2a00
#define BT_UUID_GAP_DEVICE_NAME BT_UUID_DECLARE_16(0x2a00)
/** @def BT_UUID_GAP_APPEARANCE
* @brief GAP Characteristic Appearance
*/
#define BT_UUID_GAP_APPEARANCE 0x2a01
#define BT_UUID_GAP_APPEARANCE BT_UUID_DECLARE_16(0x2a01)
/** @def BT_UUID_BAS_BATTERY_LEVEL
* @brief BAS Characteristic Battery Level
*/
#define BT_UUID_BAS_BATTERY_LEVEL 0x2a19
#define BT_UUID_BAS_BATTERY_LEVEL BT_UUID_DECLARE_16(0x2a19)
/** @def BT_UUID_DIS_SYSTEM_ID
* @brief DIS Characteristic System ID
*/
#define BT_UUID_DIS_SYSTEM_ID 0x2a23
/** @def BT_UUID_DIS_MODEL_NUMBER_STRING
#define BT_UUID_DIS_SYSTEM_ID BT_UUID_DECLARE_16(0x2a23)
/** @def BT_UUID_DIS_MODEL_NUMBER
* @brief DIS Characteristic Model Number String
*/
#define BT_UUID_DIS_MODEL_NUMBER_STRING 0x2a24
/** @def BT_UUID_DIS_SERIAL_NUMBER_STRING
#define BT_UUID_DIS_MODEL_NUMBER BT_UUID_DECLARE_16(0x2a24)
/** @def BT_UUID_DIS_SERIAL_NUMBER
* @brief DIS Characteristic Serial Number String
*/
#define BT_UUID_DIS_SERIAL_NUMBER_STRING 0x2a25
/** @def BT_UUID_DIS_FIRMWARE_REVISION_STRING
#define BT_UUID_DIS_SERIAL_NUMBER BT_UUID_DECLARE_16(0x2a25)
/** @def BT_UUID_DIS_FIRMWARE_REVISION
* @brief DIS Characteristic Firmware Revision String
*/
#define BT_UUID_DIS_FIRMWARE_REVISION_STRING 0x2a26
/** @def BT_UUID_DIS_HARDWARE_REVISION_STRING
#define BT_UUID_DIS_FIRMWARE_REVISION BT_UUID_DECLARE_16(0x2a26)
/** @def BT_UUID_DIS_HARDWARE_REVISION
* @brief DIS Characteristic Hardware Revision String
*/
#define BT_UUID_DIS_HARDWARE_REVISION_STRING 0x2a27
/** @def BT_UUID_DIS_SOFTWARE_REVISION_STRING
#define BT_UUID_DIS_HARDWARE_REVISION BT_UUID_DECLARE_16(0x2a27)
/** @def BT_UUID_DIS_SOFTWARE_REVISION
* @brief DIS Characteristic Software Revision String
*/
#define BT_UUID_DIS_SOFTWARE_REVISION_STRING 0x2a28
/** @def BT_UUID_DIS_MANUFACTURER_NAME_STRING
#define BT_UUID_DIS_SOFTWARE_REVISION BT_UUID_DECLARE_16(0x2a28)
/** @def BT_UUID_DIS_MANUFACTURER_NAME
* @brief DIS Characteristic Manufacturer Name String
*/
#define BT_UUID_DIS_MANUFACTURER_NAME_STRING 0x2a29
#define BT_UUID_DIS_MANUFACTURER_NAME BT_UUID_DECLARE_16(0x2a29)
/** @def BT_UUID_DIS_PNP_ID
* @brief DIS Characteristic PnP ID
*/
#define BT_UUID_DIS_PNP_ID 0x2a50
#define BT_UUID_DIS_PNP_ID BT_UUID_DECLARE_16(0x2a50)
/** @def BT_UUID_CTS_CURRENT_TIME
* @brief CTS Characteristic Current Time
*/
#define BT_UUID_CTS_CURRENT_TIME 0x2a2b
#define BT_UUID_CTS_CURRENT_TIME BT_UUID_DECLARE_16(0x2a2b)
/** @def BT_UUID_HR_MEASUREMENT
* @brief HRS Characteristic Measurement Interval
*/
#define BT_UUID_HRS_MEASUREMENT 0x2a37
#define BT_UUID_HRS_MEASUREMENT BT_UUID_DECLARE_16(0x2a37)
/** @def BT_UUID_HRS_BODY_SENSOR
* @brief HRS Characteristic Body Sensor Location
*/
#define BT_UUID_HRS_BODY_SENSOR 0x2a38
#define BT_UUID_HRS_BODY_SENSOR BT_UUID_DECLARE_16(0x2a38)
/** @def BT_UUID_HR_CONTROL_POINT
* @brief HRS Characteristic Control Point
*/
#define BT_UUID_HRS_CONTROL_POINT 0x2a39
#define BT_UUID_HRS_CONTROL_POINT BT_UUID_DECLARE_16(0x2a39)
/** @brief Bluetooth UUID types */
enum bt_uuid_type {

View file

@ -89,16 +89,6 @@ static NET_BUF_POOL(att_pool, CONFIG_BLUETOOTH_MAX_CONN + 1,
BT_L2CAP_BUF_SIZE(CONFIG_BLUETOOTH_ATT_MTU),
&att_buf, NULL, 0);
static const struct bt_uuid primary_uuid = {
.type = BT_UUID_16,
.u16 = BT_UUID_GATT_PRIMARY,
};
static const struct bt_uuid secondary_uuid = {
.type = BT_UUID_16,
.u16 = BT_UUID_GATT_SECONDARY,
};
static void att_req_destroy(struct bt_att_req *req)
{
if (req->buf) {
@ -391,7 +381,7 @@ static uint8_t find_type_cb(const struct bt_gatt_attr *attr, void *user_data)
uint8_t uuid[16];
/* Skip if not a primary service */
if (bt_uuid_cmp(attr->uuid, &primary_uuid)) {
if (bt_uuid_cmp(attr->uuid, BT_UUID_GATT_PRIMARY)) {
if (data->group && attr->handle > data->group->end_handle) {
data->group->end_handle = sys_cpu_to_le16(attr->handle);
}
@ -485,7 +475,7 @@ static uint8_t att_find_type_req(struct bt_att *att, struct net_buf *buf)
* and the Attribute Value set to the 16-bit Bluetooth UUID or 128-bit
* UUID for the specific primary service.
*/
if (type != BT_UUID_GATT_PRIMARY) {
if (type != BT_UUID_GATT_PRIMARY->u16) {
send_err_rsp(conn, BT_ATT_OP_FIND_TYPE_REQ, start_handle,
BT_ATT_ERR_ATTRIBUTE_NOT_FOUND);
return 0;
@ -1014,8 +1004,8 @@ static uint8_t att_read_group_req(struct bt_att *att, struct net_buf *buf)
* Request. The «Characteristic» grouping type shall not be used in
* the ATT Read By Group Type Request.
*/
if (bt_uuid_cmp(&uuid, &primary_uuid) &&
bt_uuid_cmp(&uuid, &secondary_uuid)) {
if (bt_uuid_cmp(&uuid, BT_UUID_GATT_PRIMARY) &&
bt_uuid_cmp(&uuid, BT_UUID_GATT_SECONDARY)) {
send_err_rsp(conn, BT_ATT_OP_READ_GROUP_REQ, start_handle,
BT_ATT_ERR_UNSUPPORTED_GROUP_TYPE);
return 0;

View file

@ -383,14 +383,12 @@ static int att_notify(struct bt_conn *conn, uint16_t handle, const void *data,
static uint8_t notify_cb(const struct bt_gatt_attr *attr, void *user_data)
{
struct notify_data *data = user_data;
struct bt_uuid uuid = { .type = BT_UUID_16, .u16 = BT_UUID_GATT_CCC };
struct bt_uuid chrc = { .type = BT_UUID_16, .u16 = BT_UUID_GATT_CHRC };
struct _bt_gatt_ccc *ccc;
size_t i;
if (bt_uuid_cmp(attr->uuid, &uuid)) {
if (bt_uuid_cmp(attr->uuid, BT_UUID_GATT_CCC)) {
/* Stop if we reach the next characteristic */
if (!bt_uuid_cmp(attr->uuid, &chrc)) {
if (!bt_uuid_cmp(attr->uuid, BT_UUID_GATT_CHRC)) {
return BT_GATT_ITER_STOP;
}
return BT_GATT_ITER_CONTINUE;
@ -711,9 +709,9 @@ static int att_find_type(struct bt_conn *conn,
req->end_handle = sys_cpu_to_le16(params->end_handle);
if (params->type == BT_GATT_DISCOVER_PRIMARY) {
req->type = sys_cpu_to_le16(BT_UUID_GATT_PRIMARY);
req->type = sys_cpu_to_le16(BT_UUID_GATT_PRIMARY->u16);
} else {
req->type = sys_cpu_to_le16(BT_UUID_GATT_SECONDARY);
req->type = sys_cpu_to_le16(BT_UUID_GATT_SECONDARY->u16);
}
BT_DBG("uuid %s start_handle 0x%04x end_handle 0x%04x",
@ -955,9 +953,9 @@ static int att_read_type(struct bt_conn *conn,
value = net_buf_add(buf, sizeof(*value));
if (params->type == BT_GATT_DISCOVER_INCLUDE)
*value = sys_cpu_to_le16(BT_UUID_GATT_INCLUDE);
*value = sys_cpu_to_le16(BT_UUID_GATT_INCLUDE->u16);
else
*value = sys_cpu_to_le16(BT_UUID_GATT_CHRC);
*value = sys_cpu_to_le16(BT_UUID_GATT_CHRC->u16);
BT_DBG("start_handle 0x%04x end_handle 0x%04x", params->start_handle,
params->end_handle);

View file

@ -157,15 +157,9 @@ static struct bt_l2cap_server server = {
.accept = ipsp_accept,
};
/* IP Support Service Variables */
static struct bt_uuid ipss_uuid = {
.type = BT_UUID_16,
.u16 = BT_UUID_IPSS,
};
static struct bt_gatt_attr attrs[] = {
/* IPSS Service Declaration */
BT_GATT_PRIMARY_SERVICE(&ipss_uuid),
BT_GATT_PRIMARY_SERVICE(BT_UUID_IPSS),
};
static int net_driver_bt_open(void)

View file

@ -34,21 +34,6 @@
static struct bt_conn *default_conn;
static struct bt_uuid hrs = {
.type = BT_UUID_16,
.u16 = BT_UUID_HRS,
};
static struct bt_uuid hrm = {
.type = BT_UUID_16,
.u16 = BT_UUID_HRS_MEASUREMENT,
};
static struct bt_uuid ccc = {
.type = BT_UUID_16,
.u16 = BT_UUID_GATT_CCC,
};
static struct bt_gatt_discover_params discover_params;
static struct bt_gatt_subscribe_params subscribe_params;
@ -68,8 +53,8 @@ static uint8_t discover_func(const struct bt_gatt_attr *attr, void *user_data)
printk("[ATTRIBUTE] handle %u\n", attr->handle);
if (discover_params.uuid == &hrs) {
discover_params.uuid = &hrm;
if (!bt_uuid_cmp(discover_params.uuid, BT_UUID_HRS)) {
discover_params.uuid = BT_UUID_HRS_MEASUREMENT;
discover_params.start_handle = attr->handle + 1;
discover_params.type = BT_GATT_DISCOVER_CHARACTERISTIC;
@ -77,8 +62,9 @@ static uint8_t discover_func(const struct bt_gatt_attr *attr, void *user_data)
if (err) {
printk("Discover failed (err %d)\n", err);
}
} else if (discover_params.uuid == &hrm) {
discover_params.uuid = &ccc;
} else if (!bt_uuid_cmp(discover_params.uuid,
BT_UUID_HRS_MEASUREMENT)) {
discover_params.uuid = BT_UUID_GATT_CCC;
discover_params.start_handle = attr->handle + 2;
discover_params.type = BT_GATT_DISCOVER_DESCRIPTOR;
subscribe_params.value_handle = attr->handle + 1;
@ -113,7 +99,7 @@ static void connected(struct bt_conn *conn)
printk("Connected: %s\n", addr);
if (conn == default_conn) {
discover_params.uuid = &hrs;
discover_params.uuid = BT_UUID_HRS;
discover_params.func = discover_func;
discover_params.start_handle = 0x0001;
discover_params.end_handle = 0xffff;
@ -147,7 +133,7 @@ static bool eir_found(const struct bt_eir *eir, void *user_data)
int err;
memcpy(&u16, &eir->data[i], sizeof(u16));
if (sys_le16_to_cpu(u16) != BT_UUID_HRS) {
if (sys_le16_to_cpu(u16) != BT_UUID_HRS->u16) {
continue;
}

View file

@ -47,16 +47,6 @@
#define UDP_PORT 4242
static struct bt_uuid gap_uuid = {
.type = BT_UUID_16,
.u16 = BT_UUID_GAP,
};
static struct bt_uuid device_name_uuid = {
.type = BT_UUID_16,
.u16 = BT_UUID_GAP_DEVICE_NAME,
};
static int read_name(struct bt_conn *conn, const struct bt_gatt_attr *attr,
void *buf, uint16_t len, uint16_t offset)
{
@ -66,11 +56,6 @@ static int read_name(struct bt_conn *conn, const struct bt_gatt_attr *attr,
strlen(name));
}
static struct bt_uuid appeareance_uuid = {
.type = BT_UUID_16,
.u16 = BT_UUID_GAP_APPEARANCE,
};
static int read_appearance(struct bt_conn *conn,
const struct bt_gatt_attr *attr, void *buf,
uint16_t len, uint16_t offset)
@ -81,17 +66,6 @@ static int read_appearance(struct bt_conn *conn,
sizeof(appearance));
}
/* Device Information Service Variables */
static struct bt_uuid dis_uuid = {
.type = BT_UUID_16,
.u16 = BT_UUID_DIS,
};
static struct bt_uuid model_uuid = {
.type = BT_UUID_16,
.u16 = BT_UUID_DIS_MODEL_NUMBER_STRING,
};
static int read_model(struct bt_conn *conn, const struct bt_gatt_attr *attr,
void *buf, uint16_t len, uint16_t offset)
{
@ -101,11 +75,6 @@ static int read_model(struct bt_conn *conn, const struct bt_gatt_attr *attr,
strlen(value));
}
static struct bt_uuid manuf_uuid = {
.type = BT_UUID_16,
.u16 = BT_UUID_DIS_MANUFACTURER_NAME_STRING,
};
static int read_manuf(struct bt_conn *conn, const struct bt_gatt_attr *attr,
void *buf, uint16_t len, uint16_t offset)
{
@ -116,20 +85,21 @@ static int read_manuf(struct bt_conn *conn, const struct bt_gatt_attr *attr,
}
static struct bt_gatt_attr attrs[] = {
BT_GATT_PRIMARY_SERVICE(&gap_uuid),
BT_GATT_CHARACTERISTIC(&device_name_uuid, BT_GATT_CHRC_READ),
BT_GATT_DESCRIPTOR(&device_name_uuid, BT_GATT_PERM_READ,
BT_GATT_PRIMARY_SERVICE(BT_UUID_GAP),
BT_GATT_CHARACTERISTIC(BT_UUID_GAP_DEVICE_NAME, BT_GATT_CHRC_READ),
BT_GATT_DESCRIPTOR(BT_UUID_GAP_DEVICE_NAME, BT_GATT_PERM_READ,
read_name, NULL, DEVICE_NAME),
BT_GATT_CHARACTERISTIC(&appeareance_uuid, BT_GATT_CHRC_READ),
BT_GATT_DESCRIPTOR(&appeareance_uuid, BT_GATT_PERM_READ,
BT_GATT_CHARACTERISTIC(BT_UUID_GAP_APPEARANCE, BT_GATT_CHRC_READ),
BT_GATT_DESCRIPTOR(BT_UUID_GAP_APPEARANCE, BT_GATT_PERM_READ,
read_appearance, NULL, NULL),
/* Device Information Service Declaration */
BT_GATT_PRIMARY_SERVICE(&dis_uuid),
BT_GATT_CHARACTERISTIC(&model_uuid, BT_GATT_CHRC_READ),
BT_GATT_DESCRIPTOR(&model_uuid, BT_GATT_PERM_READ,
BT_GATT_PRIMARY_SERVICE(BT_UUID_DIS),
BT_GATT_CHARACTERISTIC(BT_UUID_DIS_MODEL_NUMBER, BT_GATT_CHRC_READ),
BT_GATT_DESCRIPTOR(BT_UUID_DIS_MODEL_NUMBER, BT_GATT_PERM_READ,
read_model, NULL, CONFIG_PLATFORM),
BT_GATT_CHARACTERISTIC(&manuf_uuid, BT_GATT_CHRC_READ),
BT_GATT_DESCRIPTOR(&manuf_uuid, BT_GATT_PERM_READ,
BT_GATT_CHARACTERISTIC(BT_UUID_DIS_MANUFACTURER_NAME,
BT_GATT_CHRC_READ),
BT_GATT_DESCRIPTOR(BT_UUID_DIS_MANUFACTURER_NAME, BT_GATT_PERM_READ,
read_manuf, NULL, "Manufacturer"),
};

View file

@ -33,16 +33,6 @@
#define DEVICE_NAME "Test peripheral"
#define HEART_RATE_APPEARANCE 0x0341
static struct bt_uuid gap_uuid = {
.type = BT_UUID_16,
.u16 = BT_UUID_GAP,
};
static struct bt_uuid device_name_uuid = {
.type = BT_UUID_16,
.u16 = BT_UUID_GAP_DEVICE_NAME,
};
static int read_name(struct bt_conn *conn, const struct bt_gatt_attr *attr,
void *buf, uint16_t len, uint16_t offset)
{
@ -52,11 +42,6 @@ static int read_name(struct bt_conn *conn, const struct bt_gatt_attr *attr,
strlen(name));
}
static struct bt_uuid appeareance_uuid = {
.type = BT_UUID_16,
.u16 = BT_UUID_GAP_APPEARANCE,
};
static int read_appearance(struct bt_conn *conn,
const struct bt_gatt_attr *attr, void *buf,
uint16_t len, uint16_t offset)
@ -67,26 +52,6 @@ static int read_appearance(struct bt_conn *conn,
sizeof(appearance));
}
static struct bt_uuid hrs_uuid = {
.type = BT_UUID_16,
.u16 = BT_UUID_HRS,
};
static struct bt_uuid hrmc_uuid = {
.type = BT_UUID_16,
.u16 = BT_UUID_HRS_MEASUREMENT,
};
static struct bt_uuid bslc_uuid = {
.type = BT_UUID_16,
.u16 = BT_UUID_HRS_BODY_SENSOR,
};
static struct bt_uuid hrcpc_uuid = {
.type = BT_UUID_16,
.u16 = BT_UUID_HRS_CONTROL_POINT,
};
static struct bt_gatt_ccc_cfg hrmc_ccc_cfg[CONFIG_BLUETOOTH_MAX_PAIRED] = {};
static uint8_t simulate_hrm = 0;
@ -104,17 +69,6 @@ static int read_blsc(struct bt_conn *conn, const struct bt_gatt_attr *attr,
sizeof(value));
}
/* Battery Service Variables */
static struct bt_uuid bas_uuid = {
.type = BT_UUID_16,
.u16 = BT_UUID_BAS,
};
static struct bt_uuid blvl_uuid = {
.type = BT_UUID_16,
.u16 = BT_UUID_BAS_BATTERY_LEVEL,
};
static struct bt_gatt_ccc_cfg blvl_ccc_cfg[CONFIG_BLUETOOTH_MAX_PAIRED] = {};
static uint8_t simulate_blvl = 0;
static uint8_t battery = 100;
@ -133,17 +87,6 @@ static int read_blvl(struct bt_conn *conn, const struct bt_gatt_attr *attr,
sizeof(*value));
}
/* Current Time Service Variables */
static struct bt_uuid cts_uuid = {
.type = BT_UUID_16,
.u16 = BT_UUID_CTS,
};
static struct bt_uuid ct_uuid = {
.type = BT_UUID_16,
.u16 = BT_UUID_CTS_CURRENT_TIME,
};
static void generate_current_time(uint8_t *buf)
{
uint16_t year;
@ -205,17 +148,6 @@ static int write_ct(struct bt_conn *conn, const struct bt_gatt_attr *attr,
return len;
}
/* Device Information Service Variables */
static struct bt_uuid dis_uuid = {
.type = BT_UUID_16,
.u16 = BT_UUID_DIS,
};
static struct bt_uuid model_uuid = {
.type = BT_UUID_16,
.u16 = BT_UUID_DIS_MODEL_NUMBER_STRING,
};
static int read_model(struct bt_conn *conn, const struct bt_gatt_attr *attr,
void *buf, uint16_t len, uint16_t offset)
{
@ -225,11 +157,6 @@ static int read_model(struct bt_conn *conn, const struct bt_gatt_attr *attr,
strlen(value));
}
static struct bt_uuid manuf_uuid = {
.type = BT_UUID_16,
.u16 = BT_UUID_DIS_MANUFACTURER_NAME_STRING,
};
static int read_manuf(struct bt_conn *conn, const struct bt_gatt_attr *attr,
void *buf, uint16_t len, uint16_t offset)
{
@ -380,45 +307,49 @@ static const struct bt_uuid vnd_signed_uuid = {
};
static struct bt_gatt_attr attrs[] = {
BT_GATT_PRIMARY_SERVICE(&gap_uuid),
BT_GATT_CHARACTERISTIC(&device_name_uuid, BT_GATT_CHRC_READ),
BT_GATT_DESCRIPTOR(&device_name_uuid, BT_GATT_PERM_READ,
BT_GATT_PRIMARY_SERVICE(BT_UUID_GAP),
BT_GATT_CHARACTERISTIC(BT_UUID_GAP_DEVICE_NAME, BT_GATT_CHRC_READ),
BT_GATT_DESCRIPTOR(BT_UUID_GAP_DEVICE_NAME, BT_GATT_PERM_READ,
read_name, NULL, DEVICE_NAME),
BT_GATT_CHARACTERISTIC(&appeareance_uuid, BT_GATT_CHRC_READ),
BT_GATT_DESCRIPTOR(&appeareance_uuid, BT_GATT_PERM_READ,
BT_GATT_CHARACTERISTIC(BT_UUID_GAP_APPEARANCE, BT_GATT_CHRC_READ),
BT_GATT_DESCRIPTOR(BT_UUID_GAP_APPEARANCE, BT_GATT_PERM_READ,
read_appearance, NULL, NULL),
/* Heart Rate Service Declaration */
BT_GATT_PRIMARY_SERVICE(&hrs_uuid),
BT_GATT_CHARACTERISTIC(&hrmc_uuid, BT_GATT_CHRC_NOTIFY),
BT_GATT_DESCRIPTOR(&hrmc_uuid, BT_GATT_PERM_READ, NULL, NULL, NULL),
BT_GATT_PRIMARY_SERVICE(BT_UUID_HRS),
BT_GATT_CHARACTERISTIC(BT_UUID_HRS_MEASUREMENT, BT_GATT_CHRC_NOTIFY),
BT_GATT_DESCRIPTOR(BT_UUID_HRS_MEASUREMENT, BT_GATT_PERM_READ, NULL,
NULL, NULL),
BT_GATT_CCC(hrmc_ccc_cfg, hrmc_ccc_cfg_changed),
BT_GATT_CHARACTERISTIC(&bslc_uuid, BT_GATT_CHRC_READ),
BT_GATT_DESCRIPTOR(&bslc_uuid, BT_GATT_PERM_READ, read_blsc, NULL,
NULL),
BT_GATT_CHARACTERISTIC(&hrcpc_uuid, BT_GATT_CHRC_WRITE),
BT_GATT_CHARACTERISTIC(BT_UUID_HRS_BODY_SENSOR, BT_GATT_CHRC_READ),
BT_GATT_DESCRIPTOR(BT_UUID_HRS_BODY_SENSOR, BT_GATT_PERM_READ,
read_blsc, NULL, NULL),
BT_GATT_CHARACTERISTIC(BT_UUID_HRS_CONTROL_POINT, BT_GATT_CHRC_WRITE),
/* TODO: Add write permission and callback */
BT_GATT_DESCRIPTOR(&hrcpc_uuid, BT_GATT_PERM_READ, NULL, NULL, NULL),
BT_GATT_DESCRIPTOR(BT_UUID_HRS_CONTROL_POINT, BT_GATT_PERM_READ, NULL,
NULL, NULL),
/* Battery Service Declaration */
BT_GATT_PRIMARY_SERVICE(&bas_uuid),
BT_GATT_CHARACTERISTIC(&blvl_uuid,
BT_GATT_PRIMARY_SERVICE(BT_UUID_BAS),
BT_GATT_CHARACTERISTIC(BT_UUID_BAS_BATTERY_LEVEL,
BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY),
BT_GATT_DESCRIPTOR(&blvl_uuid, BT_GATT_PERM_READ, read_blvl, NULL,
&battery),
BT_GATT_DESCRIPTOR(BT_UUID_BAS_BATTERY_LEVEL, BT_GATT_PERM_READ,
read_blvl, NULL, &battery),
BT_GATT_CCC(blvl_ccc_cfg, blvl_ccc_cfg_changed),
/* Current Time Service Declaration */
BT_GATT_PRIMARY_SERVICE(&cts_uuid),
BT_GATT_CHARACTERISTIC(&ct_uuid, BT_GATT_CHRC_READ |
BT_GATT_PRIMARY_SERVICE(BT_UUID_CTS),
BT_GATT_CHARACTERISTIC(BT_UUID_CTS_CURRENT_TIME, BT_GATT_CHRC_READ |
BT_GATT_CHRC_NOTIFY | BT_GATT_CHRC_WRITE),
BT_GATT_DESCRIPTOR(&ct_uuid, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE,
BT_GATT_DESCRIPTOR(BT_UUID_CTS_CURRENT_TIME,
BT_GATT_PERM_READ | BT_GATT_PERM_WRITE,
read_ct, write_ct, ct),
BT_GATT_CCC(ct_ccc_cfg, ct_ccc_cfg_changed),
/* Device Information Service Declaration */
BT_GATT_PRIMARY_SERVICE(&dis_uuid),
BT_GATT_CHARACTERISTIC(&model_uuid, BT_GATT_CHRC_READ),
BT_GATT_DESCRIPTOR(&model_uuid, BT_GATT_PERM_READ,
BT_GATT_PRIMARY_SERVICE(BT_UUID_DIS),
BT_GATT_CHARACTERISTIC(BT_UUID_DIS_MODEL_NUMBER, BT_GATT_CHRC_READ),
BT_GATT_DESCRIPTOR(BT_UUID_DIS_MODEL_NUMBER, BT_GATT_PERM_READ,
read_model, NULL, CONFIG_PLATFORM),
BT_GATT_CHARACTERISTIC(&manuf_uuid, BT_GATT_CHRC_READ),
BT_GATT_DESCRIPTOR(&manuf_uuid, BT_GATT_PERM_READ,
BT_GATT_CHARACTERISTIC(BT_UUID_DIS_MANUFACTURER_NAME,
BT_GATT_CHRC_READ),
BT_GATT_DESCRIPTOR(BT_UUID_DIS_MANUFACTURER_NAME, BT_GATT_PERM_READ,
read_manuf, NULL, "Manufacturer"),
/* Vendor Primary Service Declaration */
BT_GATT_PRIMARY_SERVICE(&vnd_uuid),

View file

@ -998,29 +998,13 @@ static int read_appearance(struct bt_conn *conn,
sizeof(appearance));
}
/* GAP SERVICE (0x1800) */
static struct bt_uuid gap_uuid = {
.type = BT_UUID_16,
.u16 = BT_UUID_GAP,
};
static struct bt_uuid device_name_uuid = {
.type = BT_UUID_16,
.u16 = BT_UUID_GAP_DEVICE_NAME,
};
static struct bt_uuid appeareance_uuid = {
.type = BT_UUID_16,
.u16 = BT_UUID_GAP_APPEARANCE,
};
static struct bt_gatt_attr attrs[] = {
BT_GATT_PRIMARY_SERVICE(&gap_uuid),
BT_GATT_CHARACTERISTIC(&device_name_uuid, BT_GATT_CHRC_READ),
BT_GATT_DESCRIPTOR(&device_name_uuid, BT_GATT_PERM_READ, read_string,
NULL, DEVICE_NAME),
BT_GATT_CHARACTERISTIC(&appeareance_uuid, BT_GATT_CHRC_READ),
BT_GATT_DESCRIPTOR(&appeareance_uuid, BT_GATT_PERM_READ,
BT_GATT_PRIMARY_SERVICE(BT_UUID_GAP),
BT_GATT_CHARACTERISTIC(BT_UUID_GAP_DEVICE_NAME, BT_GATT_CHRC_READ),
BT_GATT_DESCRIPTOR(BT_UUID_GAP_DEVICE_NAME, BT_GATT_PERM_READ,
read_string, NULL, DEVICE_NAME),
BT_GATT_CHARACTERISTIC(BT_UUID_GAP_APPEARANCE, BT_GATT_CHRC_READ),
BT_GATT_DESCRIPTOR(BT_UUID_GAP_APPEARANCE, BT_GATT_PERM_READ,
read_appearance, NULL, NULL),
};