diff --git a/net/bluetooth/Kconfig b/net/bluetooth/Kconfig index 96f4a461760..ed47fe58782 100644 --- a/net/bluetooth/Kconfig +++ b/net/bluetooth/Kconfig @@ -68,6 +68,11 @@ config BLUETOOTH_SIGNING This option enables data signing which is used for transferring authenticated data in an unencrypted connection. +config BLUETOOTH_GATT_CLIENT + bool + prompt "GATT client support" + default n + config BLUETOOTH_MAX_CONN int prompt "Maximum number of simultaneous connections" diff --git a/net/bluetooth/att.c b/net/bluetooth/att.c index f6dd2789c35..fc3db6e5351 100644 --- a/net/bluetooth/att.c +++ b/net/bluetooth/att.c @@ -1586,6 +1586,7 @@ void bt_att_init(void) #endif /* CONFIG_BLUETOOTH_SMP */ } +#if defined(CONFIG_BLUETOOTH_GATT_CLIENT) uint16_t bt_att_get_mtu(struct bt_conn *conn) { struct bt_att *att = conn->att; @@ -1654,3 +1655,4 @@ void bt_att_cancel(struct bt_conn *conn) att_req_destroy(&att->req); } +#endif /* CONFIG_BLUETOOTH_GATT_CLIENT */ diff --git a/net/bluetooth/gatt.c b/net/bluetooth/gatt.c index f2c31c01c97..1402380777b 100644 --- a/net/bluetooth/gatt.c +++ b/net/bluetooth/gatt.c @@ -62,7 +62,9 @@ static const struct bt_gatt_attr *db = NULL; static size_t attr_count = 0; +#if defined(CONFIG_BLUETOOTH_GATT_CLIENT) static struct bt_gatt_subscribe_params *subscriptions; +#endif /* CONFIG_BLUETOOTH_GATT_CLIENT */ void bt_gatt_register(const struct bt_gatt_attr *attrs, size_t count) { @@ -418,6 +420,7 @@ void bt_gatt_connected(struct bt_conn *conn) bt_gatt_foreach_attr(0x0001, 0xffff, connected_cb, conn); } +#if defined(CONFIG_BLUETOOTH_GATT_CLIENT) void bt_gatt_notification(struct bt_conn *conn, uint16_t handle, const void *data, uint16_t length) { @@ -431,6 +434,7 @@ void bt_gatt_notification(struct bt_conn *conn, uint16_t handle, } } } +#endif /* CONFIG_BLUETOOTH_GATT_CLIENT */ static uint8_t disconnected_cb(const struct bt_gatt_attr *attr, void *user_data) { @@ -477,6 +481,7 @@ static uint8_t disconnected_cb(const struct bt_gatt_attr *attr, void *user_data) return BT_GATT_ITER_CONTINUE; } +#if defined(CONFIG_BLUETOOTH_GATT_CLIENT) static void gatt_subscription_remove(struct bt_gatt_subscribe_params *prev, struct bt_gatt_subscribe_params *params) { @@ -491,18 +496,10 @@ static void gatt_subscription_remove(struct bt_gatt_subscribe_params *prev, params->destroy(params); } -void bt_gatt_disconnected(struct bt_conn *conn) +static void remove_subscribtions(struct bt_conn *conn) { struct bt_gatt_subscribe_params *params, *prev; - BT_DBG("conn %p\n", conn); - bt_gatt_foreach_attr(0x0001, 0xffff, disconnected_cb, conn); - - /* If paired don't remove subscriptions */ - if (bt_keys_find_addr(&conn->dst)) { - return; - } - /* Lookup existing subscriptions */ for (params = subscriptions, prev = NULL; params; prev = params, params = params->_next) { @@ -514,7 +511,24 @@ void bt_gatt_disconnected(struct bt_conn *conn) gatt_subscription_remove(prev, params); } } +#endif /* CONFIG_BLUETOOTH_GATT_CLIENT */ +void bt_gatt_disconnected(struct bt_conn *conn) +{ + BT_DBG("conn %p\n", conn); + bt_gatt_foreach_attr(0x0001, 0xffff, disconnected_cb, conn); + +#if defined(CONFIG_BLUETOOTH_GATT_CLIENT) + /* If paired don't remove subscriptions */ + if (bt_keys_find_addr(&conn->dst)) { + return; + } + + remove_subscribtions(conn); +#endif /* CONFIG_BLUETOOTH_GATT_CLIENT */ +} + +#if defined(CONFIG_BLUETOOTH_GATT_CLIENT) static void gatt_mtu_rsp(struct bt_conn *conn, uint8_t err, const void *pdu, uint16_t length, void *user_data) { @@ -1457,3 +1471,4 @@ int bt_gatt_read_multiple(struct bt_conn *conn, const uint16_t *handles, return gatt_send(conn, buf, att_read_rsp, func, NULL); } +#endif /* CONFIG_BLUETOOTH_GATT_CLIENT */ diff --git a/net/bluetooth/gatt_internal.h b/net/bluetooth/gatt_internal.h index 1badee6667c..819a8755407 100644 --- a/net/bluetooth/gatt_internal.h +++ b/net/bluetooth/gatt_internal.h @@ -34,5 +34,13 @@ void bt_gatt_connected(struct bt_conn *conn); void bt_gatt_disconnected(struct bt_conn *conn); + +#if defined(CONFIG_BLUETOOTH_GATT_CLIENT) void bt_gatt_notification(struct bt_conn *conn, uint16_t handle, const void *data, uint16_t length); +#else +static inline void bt_gatt_notification(struct bt_conn *conn, uint16_t handle, + const void *data, uint16_t length) +{ +} +#endif /* CONFIG_BLUETOOTH_GATT_CLIENT */ diff --git a/samples/bluetooth/central/prj_x86.conf b/samples/bluetooth/central/prj_x86.conf index bff3561dd69..c392b7e49db 100644 --- a/samples/bluetooth/central/prj_x86.conf +++ b/samples/bluetooth/central/prj_x86.conf @@ -4,3 +4,4 @@ CONFIG_BLUETOOTH_UART=y CONFIG_BLUETOOTH_DEBUG=y CONFIG_BLUETOOTH_CENTRAL=y CONFIG_BLUETOOTH_SMP=y +CONFIG_BLUETOOTH_GATT_CLIENT=y diff --git a/samples/bluetooth/shell/prj_arm.conf b/samples/bluetooth/shell/prj_arm.conf index ccbc64f466f..0c53ec0913a 100644 --- a/samples/bluetooth/shell/prj_arm.conf +++ b/samples/bluetooth/shell/prj_arm.conf @@ -8,3 +8,4 @@ CONFIG_BLUETOOTH_CENTRAL=y CONFIG_BLUETOOTH_PERIPHERAL=y CONFIG_BLUETOOTH_SMP=y CONFIG_BLUETOOTH_SIGNING=y +CONFIG_BLUETOOTH_GATT_CLIENT=y diff --git a/samples/bluetooth/shell/prj_x86.conf b/samples/bluetooth/shell/prj_x86.conf index b1db64e7be0..713d069e0f5 100644 --- a/samples/bluetooth/shell/prj_x86.conf +++ b/samples/bluetooth/shell/prj_x86.conf @@ -8,5 +8,6 @@ CONFIG_BLUETOOTH_CENTRAL=y CONFIG_BLUETOOTH_PERIPHERAL=y CONFIG_BLUETOOTH_SMP=y CONFIG_BLUETOOTH_SIGNING=y +CONFIG_BLUETOOTH_GATT_CLIENT=y CONFIG_TINYCRYPT=y CONFIG_TINYCRYPT_AES=y diff --git a/samples/bluetooth/tester/prj_arm.conf b/samples/bluetooth/tester/prj_arm.conf index 57a3667c672..b9239b2c4cd 100644 --- a/samples/bluetooth/tester/prj_arm.conf +++ b/samples/bluetooth/tester/prj_arm.conf @@ -7,6 +7,7 @@ CONFIG_BLUETOOTH_CENTRAL=y CONFIG_BLUETOOTH_PERIPHERAL=y CONFIG_BLUETOOTH_SMP=y CONFIG_BLUETOOTH_SIGNING=y +CONFIG_BLUETOOTH_GATT_CLIENT=y CONFIG_BLUETOOTH_DEBUG=y CONFIG_BLUETOOTH_DEBUG_HCI_CORE=y CONFIG_BLUETOOTH_DEBUG_BUF=y