subsys: bluetooth: services: dev. information service enhancements
This commit moves the BLE GATT Device Information service from /samples/bluetooth/gatt to /subsys/bluetooth/services and adds a Kconfig entry to enable and configure the service; when enabled, it will register itself automatically. Signed-off-by: Emanuele Di Santo <emdi@nordicsemi.no> Signed-off-by: Radoslaw Koppel <radoslaw.koppel@nordicsemi.no>
This commit is contained in:
parent
58781d5782
commit
7e8b44f774
26 changed files with 207 additions and 85 deletions
|
@ -1,8 +1,9 @@
|
|||
/** @file
|
||||
* @brief DIS Service sample
|
||||
* @brief GATT Device Information Service
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2018 Nordic Semiconductor ASA
|
||||
* Copyright (c) 2016 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
|
@ -12,8 +13,6 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
void dis_init(const char *model, const char *manuf);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -1,62 +0,0 @@
|
|||
/** @file
|
||||
* @brief DIS Service sample
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2016 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr/types.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <misc/printk.h>
|
||||
#include <misc/byteorder.h>
|
||||
#include <zephyr.h>
|
||||
|
||||
#include <bluetooth/bluetooth.h>
|
||||
#include <bluetooth/hci.h>
|
||||
#include <bluetooth/conn.h>
|
||||
#include <bluetooth/uuid.h>
|
||||
#include <bluetooth/gatt.h>
|
||||
|
||||
static const char *dis_model;
|
||||
static const char *dis_manuf;
|
||||
|
||||
static ssize_t read_model(struct bt_conn *conn,
|
||||
const struct bt_gatt_attr *attr, void *buf,
|
||||
u16_t len, u16_t offset)
|
||||
{
|
||||
return bt_gatt_attr_read(conn, attr, buf, len, offset, dis_model,
|
||||
strlen(dis_model));
|
||||
}
|
||||
|
||||
static ssize_t read_manuf(struct bt_conn *conn,
|
||||
const struct bt_gatt_attr *attr, void *buf,
|
||||
u16_t len, u16_t offset)
|
||||
{
|
||||
return bt_gatt_attr_read(conn, attr, buf, len, offset, dis_manuf,
|
||||
strlen(dis_manuf));
|
||||
}
|
||||
|
||||
/* Device Information Service Declaration */
|
||||
static struct bt_gatt_attr attrs[] = {
|
||||
BT_GATT_PRIMARY_SERVICE(BT_UUID_DIS),
|
||||
BT_GATT_CHARACTERISTIC(BT_UUID_DIS_MODEL_NUMBER, BT_GATT_CHRC_READ,
|
||||
BT_GATT_PERM_READ, read_model, NULL, NULL),
|
||||
BT_GATT_CHARACTERISTIC(BT_UUID_DIS_MANUFACTURER_NAME,
|
||||
BT_GATT_CHRC_READ, BT_GATT_PERM_READ,
|
||||
read_manuf, NULL, NULL),
|
||||
};
|
||||
|
||||
static struct bt_gatt_service dis_svc = BT_GATT_SERVICE(attrs);
|
||||
|
||||
void dis_init(const char *model, const char *manuf)
|
||||
{
|
||||
dis_model = model;
|
||||
dis_manuf = manuf;
|
||||
|
||||
bt_gatt_service_register(&dis_svc);
|
||||
}
|
|
@ -5,7 +5,6 @@ project(peripheral)
|
|||
target_sources(app PRIVATE
|
||||
src/main.c
|
||||
../gatt/hrs.c
|
||||
../gatt/dis.c
|
||||
../gatt/bas.c
|
||||
../gatt/cts.c
|
||||
)
|
||||
|
|
|
@ -6,6 +6,7 @@ CONFIG_BT_DEBUG_LOG=y
|
|||
CONFIG_BT_SMP=y
|
||||
CONFIG_BT_SIGNING=y
|
||||
CONFIG_BT_PERIPHERAL=y
|
||||
CONFIG_BT_GATT_DIS=y
|
||||
CONFIG_BT_ATT_PREPARE_COUNT=2
|
||||
CONFIG_BT_PRIVACY=y
|
||||
CONFIG_BT_DEVICE_NAME="Zephyr Peripheral Sample Long Name"
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
#include <bluetooth/gatt.h>
|
||||
|
||||
#include <gatt/hrs.h>
|
||||
#include <gatt/dis.h>
|
||||
#include <gatt/bas.h>
|
||||
#include <gatt/cts.h>
|
||||
|
||||
|
@ -230,7 +229,6 @@ static void bt_ready(int err)
|
|||
hrs_init(0x01);
|
||||
bas_init();
|
||||
cts_init();
|
||||
dis_init(CONFIG_SOC, "Manufacturer");
|
||||
bt_gatt_service_register(&vnd_svc);
|
||||
|
||||
if (IS_ENABLED(CONFIG_SETTINGS)) {
|
||||
|
|
|
@ -5,7 +5,6 @@ project(peripheral_csc)
|
|||
FILE(GLOB app_sources src/*.c)
|
||||
target_sources(app PRIVATE
|
||||
${app_sources}
|
||||
../gatt/dis.c
|
||||
../gatt/bas.c
|
||||
)
|
||||
|
||||
|
|
|
@ -2,5 +2,7 @@ CONFIG_ENTROPY_GENERATOR=y
|
|||
CONFIG_TEST_RANDOM_GENERATOR=y
|
||||
CONFIG_BT=y
|
||||
CONFIG_BT_PERIPHERAL=y
|
||||
CONFIG_BT_GATT_DIS=y
|
||||
CONFIG_BT_GATT_DIS_PNP=n
|
||||
CONFIG_BT_DEVICE_NAME="CSC peripheral"
|
||||
CONFIG_BT_DEVICE_APPEARANCE=1157
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
#include <bluetooth/uuid.h>
|
||||
#include <bluetooth/gatt.h>
|
||||
|
||||
#include <gatt/dis.h>
|
||||
#include <gatt/bas.h>
|
||||
|
||||
#define CSC_SUPPORTED_LOCATIONS { CSC_LOC_OTHER, \
|
||||
|
@ -379,7 +378,6 @@ static void bt_ready(int err)
|
|||
printk("Bluetooth initialized\n");
|
||||
|
||||
bas_init();
|
||||
dis_init(CONFIG_SOC, "ACME");
|
||||
bt_gatt_service_register(&csc_svc);
|
||||
|
||||
err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, ARRAY_SIZE(ad), NULL, 0);
|
||||
|
|
|
@ -5,7 +5,6 @@ project(peripheral_dis)
|
|||
FILE(GLOB app_sources src/*.c)
|
||||
target_sources(app PRIVATE
|
||||
${app_sources}
|
||||
../gatt/dis.c
|
||||
)
|
||||
|
||||
zephyr_library_include_directories($ENV{ZEPHYR_BASE}/samples/bluetooth)
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
CONFIG_BT=y
|
||||
CONFIG_BT_PERIPHERAL=y
|
||||
CONFIG_BT_GATT_DIS=y
|
||||
CONFIG_BT_GATT_DIS_PNP=n
|
||||
CONFIG_BT_DEVICE_NAME="DIS peripheral"
|
||||
|
|
|
@ -20,8 +20,6 @@
|
|||
#include <bluetooth/uuid.h>
|
||||
#include <bluetooth/gatt.h>
|
||||
|
||||
#include <gatt/dis.h>
|
||||
|
||||
static const struct bt_data ad[] = {
|
||||
BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
|
||||
BT_DATA_BYTES(BT_DATA_UUID16_ALL, 0x0a, 0x18),
|
||||
|
@ -58,8 +56,6 @@ void main(void)
|
|||
|
||||
printk("Bluetooth initialized\n");
|
||||
|
||||
dis_init(CONFIG_SOC, "Manufacturer");
|
||||
|
||||
bt_conn_cb_register(&conn_callbacks);
|
||||
|
||||
err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, ARRAY_SIZE(ad), NULL, 0);
|
||||
|
|
|
@ -5,7 +5,6 @@ project(peripheral_esp)
|
|||
target_sources(app PRIVATE
|
||||
src/main.c
|
||||
../gatt/bas.c
|
||||
../gatt/dis.c
|
||||
)
|
||||
|
||||
zephyr_library_include_directories($ENV{ZEPHYR_BASE}/samples/bluetooth)
|
||||
|
|
|
@ -3,4 +3,6 @@ CONFIG_BT_PERIPHERAL=y
|
|||
CONFIG_BT_SMP=y
|
||||
CONFIG_TINYCRYPT=y
|
||||
CONFIG_BT_DEVICE_NAME="ESP peripheral"
|
||||
CONFIG_BT_GATT_DIS=y
|
||||
CONFIG_BT_GATT_DIS_PNP=n
|
||||
CONFIG_BT_DEVICE_APPEARANCE=768
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
#include <bluetooth/uuid.h>
|
||||
#include <bluetooth/gatt.h>
|
||||
|
||||
#include <gatt/dis.h>
|
||||
#include <gatt/bas.h>
|
||||
|
||||
#define SENSOR_1_NAME "Temperature Sensor 1"
|
||||
|
@ -392,7 +391,6 @@ static void bt_ready(int err)
|
|||
|
||||
bt_gatt_service_register(&ess_svc);
|
||||
bas_init();
|
||||
dis_init(CONFIG_SOC, "ACME");
|
||||
|
||||
err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, ARRAY_SIZE(ad), NULL, 0);
|
||||
if (err) {
|
||||
|
|
|
@ -6,7 +6,6 @@ FILE(GLOB app_sources src/*.c)
|
|||
target_sources(app PRIVATE
|
||||
${app_sources}
|
||||
../gatt/hog.c
|
||||
../gatt/dis.c
|
||||
../gatt/bas.c
|
||||
)
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ CONFIG_BT=y
|
|||
CONFIG_BT_DEBUG_LOG=y
|
||||
CONFIG_BT_SMP=y
|
||||
CONFIG_BT_PERIPHERAL=y
|
||||
CONFIG_BT_GATT_DIS=y
|
||||
CONFIG_BT_DEVICE_NAME="Test HoG mouse"
|
||||
CONFIG_BT_DEVICE_APPEARANCE=962
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
#include <bluetooth/uuid.h>
|
||||
#include <bluetooth/gatt.h>
|
||||
|
||||
#include <gatt/dis.h>
|
||||
#include <gatt/bas.h>
|
||||
#include <gatt/hog.h>
|
||||
|
||||
|
@ -85,7 +84,6 @@ static void bt_ready(int err)
|
|||
printk("Bluetooth initialized\n");
|
||||
|
||||
bas_init();
|
||||
dis_init(CONFIG_SOC, "Manufacturer");
|
||||
hog_init();
|
||||
|
||||
if (IS_ENABLED(CONFIG_SETTINGS)) {
|
||||
|
|
|
@ -6,7 +6,6 @@ FILE(GLOB app_sources src/*.c)
|
|||
target_sources(app PRIVATE
|
||||
${app_sources}
|
||||
../gatt/hrs.c
|
||||
../gatt/dis.c
|
||||
../gatt/bas.c
|
||||
)
|
||||
|
||||
|
|
|
@ -2,5 +2,7 @@ CONFIG_BT=y
|
|||
CONFIG_BT_DEBUG_LOG=y
|
||||
CONFIG_BT_SMP=y
|
||||
CONFIG_BT_PERIPHERAL=y
|
||||
CONFIG_BT_GATT_DIS=y
|
||||
CONFIG_BT_GATT_DIS_PNP=n
|
||||
CONFIG_BT_DEVICE_NAME="Zephyr Heartrate Sensor"
|
||||
CONFIG_BT_DEVICE_APPEARANCE=833
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
#include <bluetooth/gatt.h>
|
||||
|
||||
#include <gatt/hrs.h>
|
||||
#include <gatt/dis.h>
|
||||
#include <gatt/bas.h>
|
||||
|
||||
struct bt_conn *default_conn;
|
||||
|
@ -67,7 +66,6 @@ static void bt_ready(int err)
|
|||
|
||||
hrs_init(0x01);
|
||||
bas_init();
|
||||
dis_init(CONFIG_SOC, "Manufacturer");
|
||||
|
||||
err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, ARRAY_SIZE(ad), NULL, 0);
|
||||
if (err) {
|
||||
|
|
|
@ -5,6 +5,7 @@ target_include_directories(subsys__bluetooth INTERFACE ${CMAKE_CURRENT_SOURCE_DI
|
|||
add_subdirectory(common)
|
||||
add_subdirectory_ifdef(CONFIG_BT_HCI host)
|
||||
add_subdirectory_ifdef(CONFIG_BT_SHELL shell)
|
||||
add_subdirectory_ifdef(CONFIG_BT_CONN services)
|
||||
|
||||
if(CONFIG_BT_CTLR)
|
||||
if(CONFIG_BT_LL_SW)
|
||||
|
|
|
@ -85,6 +85,8 @@ config BT_OBSERVER
|
|||
|
||||
endmenu
|
||||
|
||||
source "subsys/bluetooth/services/Kconfig"
|
||||
|
||||
config BT_CONN
|
||||
# Virtual/hidden option
|
||||
bool
|
||||
|
|
2
subsys/bluetooth/services/CMakeLists.txt
Normal file
2
subsys/bluetooth/services/CMakeLists.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
zephyr_sources_ifdef(CONFIG_BT_GATT_DIS dis.c)
|
17
subsys/bluetooth/services/Kconfig
Normal file
17
subsys/bluetooth/services/Kconfig
Normal file
|
@ -0,0 +1,17 @@
|
|||
# Kconfig - GATT Services
|
||||
#
|
||||
# Copyright (c) 2018 Nordic Semiconductor ASA
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
if BT_CONN
|
||||
|
||||
menu "GATT Services"
|
||||
|
||||
source "subsys/bluetooth/services/Kconfig.dis"
|
||||
|
||||
endmenu
|
||||
|
||||
endif # BT_CONN
|
||||
|
89
subsys/bluetooth/services/Kconfig.dis
Normal file
89
subsys/bluetooth/services/Kconfig.dis
Normal file
|
@ -0,0 +1,89 @@
|
|||
# Kconfig - GATT Device Information service
|
||||
#
|
||||
# Copyright (c) 2018 Nordic Semiconductor ASA
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
menuconfig BT_GATT_DIS
|
||||
bool "Enable GATT Device Information service"
|
||||
default n
|
||||
|
||||
if BT_GATT_DIS
|
||||
|
||||
config BT_GATT_DIS_MODEL
|
||||
string "Model name"
|
||||
default SOC
|
||||
help
|
||||
The device model inside Device Information Service.
|
||||
|
||||
config BT_GATT_DIS_MANUF
|
||||
string "Manufacturer name"
|
||||
default "Manufacturer"
|
||||
help
|
||||
The device manufacturer inside Device Information Service.
|
||||
|
||||
config BT_GATT_DIS_PNP
|
||||
bool "Enable PnP_ID characteristic"
|
||||
default y
|
||||
help
|
||||
Enable PnP_ID characteristic in Device Information Service.
|
||||
|
||||
if BT_GATT_DIS_PNP
|
||||
|
||||
config BT_GATT_DIS_PNP_VID_SRC
|
||||
int "Vendor ID source"
|
||||
range 1 2
|
||||
default 1
|
||||
help
|
||||
The Vendor ID Source field designates which organization assigned the
|
||||
value used in the Vendor ID field value.
|
||||
The possible values are:
|
||||
- 1 Bluetooth SIG, the Vendor ID was assigned by the Bluetooth SIG
|
||||
- 2 USB IF, the Vendor ID was assigned by the USB IF
|
||||
|
||||
config BT_GATT_DIS_PNP_VID
|
||||
hex "Vendor ID"
|
||||
range 0 0xFFFF
|
||||
default 0
|
||||
help
|
||||
The Vendor ID field is intended to uniquely identify the vendor of the
|
||||
device. This field is used in conjunction with Vendor ID Source field,
|
||||
which determines which organization assigned the Vendor ID field value.
|
||||
Note: The Bluetooth Special Interest Group assigns Device ID Vendor ID,
|
||||
and the USB Implementer’s Forum assigns Vendor IDs,
|
||||
either of which can be used for the Vendor ID field value.
|
||||
Device providers should procure the Vendor ID from the USB Implementer’s
|
||||
Forum or the Company Identifier from the Bluetooth SIG.
|
||||
|
||||
config BT_GATT_DIS_PNP_PID
|
||||
hex "Product ID"
|
||||
range 0 0xFFFF
|
||||
default 0
|
||||
help
|
||||
The Product ID field is intended to distinguish between different products
|
||||
made by the vendor identified with the Vendor ID field. The vendors
|
||||
themselves manage Product ID field values.
|
||||
|
||||
config BT_GATT_DIS_PNP_VER
|
||||
hex "Product Version"
|
||||
range 0 0xFFFF
|
||||
default 1
|
||||
help
|
||||
The Product Version field is a numeric expression identifying the device
|
||||
release number in Binary-Coded Decimal. This is a vendor-assigned value,
|
||||
which defines the version of the product identified by the Vendor ID and
|
||||
Product ID fields. This field is intended to differentiate between
|
||||
versions of products with identical Vendor IDs and Product IDs.
|
||||
The value of the field value is 0xJJMN for version JJ.M.N
|
||||
(JJ – major version number, M – minor version number,
|
||||
N – sub-minor version number); e.g., version 2.1.3 is represented with
|
||||
value 0x0213 and version 2.0.0 is represented with a value of 0x0200.
|
||||
When upward-compatible changes are made to the device, it is recommended
|
||||
that the minor version number be incremented. If incompatible changes are
|
||||
made to the device, it is recommended that the major version number be
|
||||
incremented. The sub-minor version is incremented for bug fixes.
|
||||
|
||||
endif #BT_GATT_DIS_PNP
|
||||
|
||||
endif #BT_GATT_DIS
|
84
subsys/bluetooth/services/dis.c
Normal file
84
subsys/bluetooth/services/dis.c
Normal file
|
@ -0,0 +1,84 @@
|
|||
/** @file
|
||||
* @brief GATT Device Infromation Service
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2018 Nordic Semiconductor ASA
|
||||
* Copyright (c) 2016 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr/types.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <zephyr.h>
|
||||
#include <init.h>
|
||||
|
||||
#include <bluetooth/bluetooth.h>
|
||||
#include <bluetooth/hci.h>
|
||||
#include <bluetooth/conn.h>
|
||||
#include <bluetooth/uuid.h>
|
||||
#include <bluetooth/gatt.h>
|
||||
|
||||
#if CONFIG_BT_GATT_DIS_PNP
|
||||
struct dis_pnp {
|
||||
u8_t pnp_vid_src;
|
||||
u16_t pnp_vid;
|
||||
u16_t pnp_pid;
|
||||
u16_t pnp_ver;
|
||||
} __packed;
|
||||
|
||||
static struct dis_pnp dis_pnp_id = {
|
||||
.pnp_vid_src = CONFIG_BT_GATT_DIS_PNP_VID_SRC,
|
||||
.pnp_vid = CONFIG_BT_GATT_DIS_PNP_VID,
|
||||
.pnp_pid = CONFIG_BT_GATT_DIS_PNP_PID,
|
||||
.pnp_ver = CONFIG_BT_GATT_DIS_PNP_VER,
|
||||
};
|
||||
#endif
|
||||
|
||||
static ssize_t read_str(struct bt_conn *conn,
|
||||
const struct bt_gatt_attr *attr, void *buf,
|
||||
u16_t len, u16_t offset)
|
||||
{
|
||||
return bt_gatt_attr_read(conn, attr, buf, len, offset, attr->user_data,
|
||||
strlen(attr->user_data));
|
||||
}
|
||||
|
||||
#if CONFIG_BT_GATT_DIS_PNP
|
||||
static ssize_t read_pnp_id(struct bt_conn *conn,
|
||||
const struct bt_gatt_attr *attr, void *buf,
|
||||
u16_t len, u16_t offset)
|
||||
{
|
||||
return bt_gatt_attr_read(conn, attr, buf, len, offset, &dis_pnp_id,
|
||||
sizeof(dis_pnp_id));
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Device Information Service Declaration */
|
||||
static struct bt_gatt_attr attrs[] = {
|
||||
BT_GATT_PRIMARY_SERVICE(BT_UUID_DIS),
|
||||
BT_GATT_CHARACTERISTIC(BT_UUID_DIS_MODEL_NUMBER,
|
||||
BT_GATT_CHRC_READ, BT_GATT_PERM_READ,
|
||||
read_str, NULL, CONFIG_BT_GATT_DIS_MODEL),
|
||||
BT_GATT_CHARACTERISTIC(BT_UUID_DIS_MANUFACTURER_NAME,
|
||||
BT_GATT_CHRC_READ, BT_GATT_PERM_READ,
|
||||
read_str, NULL, CONFIG_BT_GATT_DIS_MANUF),
|
||||
#if CONFIG_BT_GATT_DIS_PNP
|
||||
BT_GATT_CHARACTERISTIC(BT_UUID_DIS_PNP_ID,
|
||||
BT_GATT_CHRC_READ, BT_GATT_PERM_READ,
|
||||
read_pnp_id, NULL, &dis_pnp_id),
|
||||
#endif
|
||||
};
|
||||
|
||||
static struct bt_gatt_service dis_svc = BT_GATT_SERVICE(attrs);
|
||||
|
||||
static int dis_init(struct device *dev)
|
||||
{
|
||||
ARG_UNUSED(dev);
|
||||
|
||||
return bt_gatt_service_register(&dis_svc);
|
||||
}
|
||||
|
||||
SYS_INIT(dis_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY);
|
Loading…
Add table
Add a link
Reference in a new issue