diff --git a/samples/bluetooth/gatt/dis.h b/include/bluetooth/services/dis.h similarity index 65% rename from samples/bluetooth/gatt/dis.h rename to include/bluetooth/services/dis.h index b3f5ce10ebd..8702f7c8f1e 100644 --- a/samples/bluetooth/gatt/dis.h +++ b/include/bluetooth/services/dis.h @@ -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 diff --git a/samples/bluetooth/gatt/dis.c b/samples/bluetooth/gatt/dis.c deleted file mode 100644 index 97f8481c4d2..00000000000 --- a/samples/bluetooth/gatt/dis.c +++ /dev/null @@ -1,62 +0,0 @@ -/** @file - * @brief DIS Service sample - */ - -/* - * Copyright (c) 2016 Intel Corporation - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -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); -} diff --git a/samples/bluetooth/peripheral/CMakeLists.txt b/samples/bluetooth/peripheral/CMakeLists.txt index fbe3133a012..b90e324bd20 100644 --- a/samples/bluetooth/peripheral/CMakeLists.txt +++ b/samples/bluetooth/peripheral/CMakeLists.txt @@ -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 ) diff --git a/samples/bluetooth/peripheral/prj.conf b/samples/bluetooth/peripheral/prj.conf index c13b2719585..8735e7fa64e 100644 --- a/samples/bluetooth/peripheral/prj.conf +++ b/samples/bluetooth/peripheral/prj.conf @@ -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" diff --git a/samples/bluetooth/peripheral/src/main.c b/samples/bluetooth/peripheral/src/main.c index b4ff71985b4..9cc22770ee4 100644 --- a/samples/bluetooth/peripheral/src/main.c +++ b/samples/bluetooth/peripheral/src/main.c @@ -23,7 +23,6 @@ #include #include -#include #include #include @@ -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)) { diff --git a/samples/bluetooth/peripheral_csc/CMakeLists.txt b/samples/bluetooth/peripheral_csc/CMakeLists.txt index 9d5fdd49549..cc56ea4322e 100644 --- a/samples/bluetooth/peripheral_csc/CMakeLists.txt +++ b/samples/bluetooth/peripheral_csc/CMakeLists.txt @@ -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 ) diff --git a/samples/bluetooth/peripheral_csc/prj.conf b/samples/bluetooth/peripheral_csc/prj.conf index 70c94ab553a..4f0eb5e7339 100644 --- a/samples/bluetooth/peripheral_csc/prj.conf +++ b/samples/bluetooth/peripheral_csc/prj.conf @@ -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 diff --git a/samples/bluetooth/peripheral_csc/src/main.c b/samples/bluetooth/peripheral_csc/src/main.c index 17678df35fb..82048766d09 100644 --- a/samples/bluetooth/peripheral_csc/src/main.c +++ b/samples/bluetooth/peripheral_csc/src/main.c @@ -21,7 +21,6 @@ #include #include -#include #include #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); diff --git a/samples/bluetooth/peripheral_dis/CMakeLists.txt b/samples/bluetooth/peripheral_dis/CMakeLists.txt index 69c60c8b986..218edef96c8 100644 --- a/samples/bluetooth/peripheral_dis/CMakeLists.txt +++ b/samples/bluetooth/peripheral_dis/CMakeLists.txt @@ -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) diff --git a/samples/bluetooth/peripheral_dis/prj.conf b/samples/bluetooth/peripheral_dis/prj.conf index 01e1a97ce1f..af565471703 100644 --- a/samples/bluetooth/peripheral_dis/prj.conf +++ b/samples/bluetooth/peripheral_dis/prj.conf @@ -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" diff --git a/samples/bluetooth/peripheral_dis/src/main.c b/samples/bluetooth/peripheral_dis/src/main.c index 900d457a051..4571d0df356 100644 --- a/samples/bluetooth/peripheral_dis/src/main.c +++ b/samples/bluetooth/peripheral_dis/src/main.c @@ -20,8 +20,6 @@ #include #include -#include - 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); diff --git a/samples/bluetooth/peripheral_esp/CMakeLists.txt b/samples/bluetooth/peripheral_esp/CMakeLists.txt index 442cd42049a..2d737935fea 100644 --- a/samples/bluetooth/peripheral_esp/CMakeLists.txt +++ b/samples/bluetooth/peripheral_esp/CMakeLists.txt @@ -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) diff --git a/samples/bluetooth/peripheral_esp/prj.conf b/samples/bluetooth/peripheral_esp/prj.conf index 3aa6c75221e..ce719b8b434 100644 --- a/samples/bluetooth/peripheral_esp/prj.conf +++ b/samples/bluetooth/peripheral_esp/prj.conf @@ -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 diff --git a/samples/bluetooth/peripheral_esp/src/main.c b/samples/bluetooth/peripheral_esp/src/main.c index d10d139cff9..09d71156bbd 100644 --- a/samples/bluetooth/peripheral_esp/src/main.c +++ b/samples/bluetooth/peripheral_esp/src/main.c @@ -21,7 +21,6 @@ #include #include -#include #include #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) { diff --git a/samples/bluetooth/peripheral_hids/CMakeLists.txt b/samples/bluetooth/peripheral_hids/CMakeLists.txt index 2382a73f7d8..25a67cc0290 100644 --- a/samples/bluetooth/peripheral_hids/CMakeLists.txt +++ b/samples/bluetooth/peripheral_hids/CMakeLists.txt @@ -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 ) diff --git a/samples/bluetooth/peripheral_hids/prj.conf b/samples/bluetooth/peripheral_hids/prj.conf index 349fbcc3b72..bf907c5b687 100644 --- a/samples/bluetooth/peripheral_hids/prj.conf +++ b/samples/bluetooth/peripheral_hids/prj.conf @@ -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 diff --git a/samples/bluetooth/peripheral_hids/src/main.c b/samples/bluetooth/peripheral_hids/src/main.c index be117734790..194a07103ab 100644 --- a/samples/bluetooth/peripheral_hids/src/main.c +++ b/samples/bluetooth/peripheral_hids/src/main.c @@ -22,7 +22,6 @@ #include #include -#include #include #include @@ -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)) { diff --git a/samples/bluetooth/peripheral_hr/CMakeLists.txt b/samples/bluetooth/peripheral_hr/CMakeLists.txt index f06bf872b07..ed46c91fc12 100644 --- a/samples/bluetooth/peripheral_hr/CMakeLists.txt +++ b/samples/bluetooth/peripheral_hr/CMakeLists.txt @@ -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 ) diff --git a/samples/bluetooth/peripheral_hr/prj.conf b/samples/bluetooth/peripheral_hr/prj.conf index 08ebfd7e41d..687cd696d4d 100644 --- a/samples/bluetooth/peripheral_hr/prj.conf +++ b/samples/bluetooth/peripheral_hr/prj.conf @@ -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 diff --git a/samples/bluetooth/peripheral_hr/src/main.c b/samples/bluetooth/peripheral_hr/src/main.c index 48dd5d8078c..70c276c8beb 100644 --- a/samples/bluetooth/peripheral_hr/src/main.c +++ b/samples/bluetooth/peripheral_hr/src/main.c @@ -21,7 +21,6 @@ #include #include -#include #include 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) { diff --git a/subsys/bluetooth/CMakeLists.txt b/subsys/bluetooth/CMakeLists.txt index 8650d86fcee..b4c24574dd1 100644 --- a/subsys/bluetooth/CMakeLists.txt +++ b/subsys/bluetooth/CMakeLists.txt @@ -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) diff --git a/subsys/bluetooth/Kconfig b/subsys/bluetooth/Kconfig index 3349722aa40..f9c59f1d41b 100644 --- a/subsys/bluetooth/Kconfig +++ b/subsys/bluetooth/Kconfig @@ -85,6 +85,8 @@ config BT_OBSERVER endmenu +source "subsys/bluetooth/services/Kconfig" + config BT_CONN # Virtual/hidden option bool diff --git a/subsys/bluetooth/services/CMakeLists.txt b/subsys/bluetooth/services/CMakeLists.txt new file mode 100644 index 00000000000..e9d752bea3b --- /dev/null +++ b/subsys/bluetooth/services/CMakeLists.txt @@ -0,0 +1,2 @@ + +zephyr_sources_ifdef(CONFIG_BT_GATT_DIS dis.c) diff --git a/subsys/bluetooth/services/Kconfig b/subsys/bluetooth/services/Kconfig new file mode 100644 index 00000000000..85fa9e8e731 --- /dev/null +++ b/subsys/bluetooth/services/Kconfig @@ -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 + diff --git a/subsys/bluetooth/services/Kconfig.dis b/subsys/bluetooth/services/Kconfig.dis new file mode 100644 index 00000000000..23d7d310084 --- /dev/null +++ b/subsys/bluetooth/services/Kconfig.dis @@ -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 diff --git a/subsys/bluetooth/services/dis.c b/subsys/bluetooth/services/dis.c new file mode 100644 index 00000000000..3ae50d67b22 --- /dev/null +++ b/subsys/bluetooth/services/dis.c @@ -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 +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#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);