From 9516d63836948c61b0570cc2d68b25ac07c94f89 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Wed, 24 May 2017 18:09:15 -0700 Subject: [PATCH] Bluetooth: Remove support for NBLE NBLE has been deprecated for a few releases now and can be removed. Signed-off-by: Johan Hedberg --- arch/x86/soc/ia32/Kconfig.defconfig | 7 - .../quark_se/Kconfig.defconfig.series | 4 +- boards/x86/arduino_101/Kconfig.defconfig | 13 - .../quark_se_c1000_devboard/Kconfig.defconfig | 19 - drivers/bluetooth/Kconfig | 4 +- drivers/bluetooth/Makefile | 1 - drivers/bluetooth/nble/Kconfig | 117 -- drivers/bluetooth/nble/Makefile | 5 - drivers/bluetooth/nble/conn.c | 535 ------ drivers/bluetooth/nble/conn.h | 7 - drivers/bluetooth/nble/conn_internal.h | 33 - drivers/bluetooth/nble/gap.c | 380 ---- drivers/bluetooth/nble/gap_internal.h | 614 ------- drivers/bluetooth/nble/gatt.c | 1614 ----------------- drivers/bluetooth/nble/gatt_internal.h | 286 --- drivers/bluetooth/nble/rpc.h | 187 -- drivers/bluetooth/nble/rpc_deserialize.c | 639 ------- .../nble/rpc_functions_to_ble_core.h | 93 - .../bluetooth/nble/rpc_functions_to_quark.h | 112 -- drivers/bluetooth/nble/rpc_serialize.c | 417 ----- drivers/bluetooth/nble/smp.c | 590 ------ drivers/bluetooth/nble/smp.h | 16 - drivers/bluetooth/nble/stubs.c | 76 - drivers/bluetooth/nble/uart.c | 244 --- drivers/bluetooth/nble/uart.h | 131 -- samples/bluetooth/beacon/prj_nble.conf | 5 - samples/bluetooth/beacon/testcase.ini | 7 - samples/bluetooth/eddystone/prj_nble.conf | 5 - samples/bluetooth/eddystone/src/main.c | 4 - samples/bluetooth/eddystone/testcase.ini | 7 - samples/bluetooth/peripheral/prj_nble.conf | 6 - samples/bluetooth/peripheral/testcase.ini | 8 - .../bluetooth/peripheral_csc/prj_nble.conf | 7 - .../bluetooth/peripheral_esp/prj_nble.conf | 5 - samples/bluetooth/peripheral_esp/testcase.ini | 8 - .../bluetooth/peripheral_hids/prj_nble.conf | 5 - .../bluetooth/peripheral_hids/testcase.ini | 7 - samples/bluetooth/peripheral_hr/prj_nble.conf | 5 - samples/bluetooth/peripheral_hr/testcase.ini | 8 - scripts/sanity_chk/sanity_last_release.csv | 11 - tests/bluetooth/shell/prj_nble.conf | 9 - tests/bluetooth/shell/testcase.ini | 6 - tests/bluetooth/tester/nble.conf | 7 - tests/bluetooth/tester/testcase.ini | 8 - 44 files changed, 4 insertions(+), 6268 deletions(-) delete mode 100644 drivers/bluetooth/nble/Kconfig delete mode 100644 drivers/bluetooth/nble/Makefile delete mode 100644 drivers/bluetooth/nble/conn.c delete mode 100644 drivers/bluetooth/nble/conn.h delete mode 100644 drivers/bluetooth/nble/conn_internal.h delete mode 100644 drivers/bluetooth/nble/gap.c delete mode 100644 drivers/bluetooth/nble/gap_internal.h delete mode 100644 drivers/bluetooth/nble/gatt.c delete mode 100644 drivers/bluetooth/nble/gatt_internal.h delete mode 100644 drivers/bluetooth/nble/rpc.h delete mode 100644 drivers/bluetooth/nble/rpc_deserialize.c delete mode 100644 drivers/bluetooth/nble/rpc_functions_to_ble_core.h delete mode 100644 drivers/bluetooth/nble/rpc_functions_to_quark.h delete mode 100644 drivers/bluetooth/nble/rpc_serialize.c delete mode 100644 drivers/bluetooth/nble/smp.c delete mode 100644 drivers/bluetooth/nble/smp.h delete mode 100644 drivers/bluetooth/nble/stubs.c delete mode 100644 drivers/bluetooth/nble/uart.c delete mode 100644 drivers/bluetooth/nble/uart.h delete mode 100644 samples/bluetooth/beacon/prj_nble.conf delete mode 100644 samples/bluetooth/eddystone/prj_nble.conf delete mode 100644 samples/bluetooth/peripheral/prj_nble.conf delete mode 100644 samples/bluetooth/peripheral_csc/prj_nble.conf delete mode 100644 samples/bluetooth/peripheral_esp/prj_nble.conf delete mode 100644 samples/bluetooth/peripheral_hids/prj_nble.conf delete mode 100644 samples/bluetooth/peripheral_hr/prj_nble.conf delete mode 100644 tests/bluetooth/shell/prj_nble.conf delete mode 100644 tests/bluetooth/tester/nble.conf diff --git a/arch/x86/soc/ia32/Kconfig.defconfig b/arch/x86/soc/ia32/Kconfig.defconfig index b1e5281aaf..92319349f5 100644 --- a/arch/x86/soc/ia32/Kconfig.defconfig +++ b/arch/x86/soc/ia32/Kconfig.defconfig @@ -77,13 +77,6 @@ config BLUETOOTH_UART_ON_DEV_NAME endif -if NBLE - -config NBLE_UART_ON_DEV_NAME - default "UART_1" - -endif - if UART_PIPE config UART_PIPE_ON_DEV_NAME diff --git a/arch/x86/soc/intel_quark/quark_se/Kconfig.defconfig.series b/arch/x86/soc/intel_quark/quark_se/Kconfig.defconfig.series index 92a204508f..e8f57fdc45 100644 --- a/arch/x86/soc/intel_quark/quark_se/Kconfig.defconfig.series +++ b/arch/x86/soc/intel_quark/quark_se/Kconfig.defconfig.series @@ -192,7 +192,7 @@ config RTC_0_IRQ_PRI default 2 endif # RTC -if BLUETOOTH_H4 || NBLE +if BLUETOOTH_H4 config BLUETOOTH_UART_ON_DEV_NAME default UART_QMSI_0_NAME @@ -206,7 +206,7 @@ config UART_QMSI_0_BAUDRATE config UART_QMSI_0_HW_FC def_bool y -endif # BLUETOOTH_H4 || NBLE +endif # BLUETOOTH_H4 if UART_QMSI diff --git a/boards/x86/arduino_101/Kconfig.defconfig b/boards/x86/arduino_101/Kconfig.defconfig index 029b638a49..ebe635d850 100644 --- a/boards/x86/arduino_101/Kconfig.defconfig +++ b/boards/x86/arduino_101/Kconfig.defconfig @@ -16,19 +16,6 @@ config ROM_SIZE config PHYS_LOAD_ADDR default 0x40010000 -if NBLE - -config GPIO - def_bool y - -config BLUETOOTH_NRF51_PM - def_bool y - -config NBLE_UART_ON_DEV_NAME - default UART_QMSI_0_NAME - -endif - if BLUETOOTH_H4 config BLUETOOTH_UART_ON_DEV_NAME diff --git a/boards/x86/quark_se_c1000_devboard/Kconfig.defconfig b/boards/x86/quark_se_c1000_devboard/Kconfig.defconfig index 48542f850f..fb2e201299 100644 --- a/boards/x86/quark_se_c1000_devboard/Kconfig.defconfig +++ b/boards/x86/quark_se_c1000_devboard/Kconfig.defconfig @@ -4,25 +4,6 @@ if BOARD_QUARK_SE_C1000_DEVBOARD config BOARD default "quark_se_c1000_devboard" -if NBLE - -config GPIO - def_bool y - -config BLUETOOTH_NRF51_PM - def_bool y - -config NBLE_UART_ON_DEV_NAME - default UART_QMSI_0_NAME - -config UART_QMSI_0_BAUDRATE - default 1000000 - -config UART_QMSI_0_HW_FC - def_bool y - -endif - if BLUETOOTH_H4 config BLUETOOTH_UART_ON_DEV_NAME diff --git a/drivers/bluetooth/Kconfig b/drivers/bluetooth/Kconfig index 9929984979..4c0697a44b 100644 --- a/drivers/bluetooth/Kconfig +++ b/drivers/bluetooth/Kconfig @@ -19,12 +19,12 @@ source "drivers/bluetooth/hci/Kconfig" endif if BLUETOOTH_CUSTOM -source "drivers/bluetooth/nble/Kconfig" +# Insert here any custom (non-HCI) offload drives endif config BLUETOOTH_NRF51_PM bool "nRF51 Power Management [EXPERIMENTAL]" - depends on BLUETOOTH_H4 || NBLE + depends on BLUETOOTH_H4 help Power Management support for Nordic BLE nRF51 chip. Allows to enable, disable the chip and handle wakeups. diff --git a/drivers/bluetooth/Makefile b/drivers/bluetooth/Makefile index c576b36248..df408816ec 100644 --- a/drivers/bluetooth/Makefile +++ b/drivers/bluetooth/Makefile @@ -1,5 +1,4 @@ ccflags-y += -I$(srctree)/subsys/bluetooth obj-y += hci/ -obj-$(CONFIG_NBLE) += nble/ obj-$(CONFIG_BLUETOOTH_NRF51_PM) += nrf51_pm.o diff --git a/drivers/bluetooth/nble/Kconfig b/drivers/bluetooth/nble/Kconfig deleted file mode 100644 index 651a2d51c9..0000000000 --- a/drivers/bluetooth/nble/Kconfig +++ /dev/null @@ -1,117 +0,0 @@ -# Kconfig - NBLE configuration options - -# -# Copyright (c) 2016 Intel Corporation -# -# SPDX-License-Identifier: Apache-2.0 -# - -config NBLE - bool "Support for custom non-HCI nRF51 firmware [DEPRECATED]" - select UART_INTERRUPT_DRIVEN - select NET_BUF - depends on SERIAL - help - Note: This feature is deprecated and will be removed in a - future Zephyr version. - - Enables support for using Nordic Semiconductor nRF51 Bluetooth - LE chips with a custom firmware. The API for this is a subset of - the normal Bluetooth API (include/bluetooth/). This driver can - only be enabled if CONFIG_BLUETOOTH has not been enabled. - - A fundamental assumption that the driver makes is that it is - run on an architecture with the same ABI (e.g. struct packing - & endianness) as the nRF51 chip. The driver cannot be used on - any architecture that doesn't fulfill this requirement. - -if NBLE -config BLUETOOTH_PERIPHERAL - bool - default y - -config BLUETOOTH_CENTRAL - bool - default y - -config BLUETOOTH_ATT_PREPARE_COUNT - int "Number of ATT prepare write buffers" - default 2 - range 0 64 - help - Number of buffers available for ATT prepare write, setting - this to 0 disables GATT long/reliable writes. - -config BLUETOOTH_GATT_CLIENT - bool - default y - -config BLUETOOTH_SMP - bool - default y - -config BLUETOOTH_MAX_CONN - int - default 6 - -config BLUETOOTH_MAX_PAIRED - int - default 7 - -config BLUETOOTH_RX_STACK_SIZE - int "Size of the receiving thread stack" - default 1024 - range 1024 65536 - help - Size of the receiving thread stack. This is the context from - which all event callbacks to the application occur. The - default value is sufficient for basic operation, but if the - application needs to do advanced things in its callbacks that - require extra stack space, this value can be increased to - accommodate for that. - -config BLUETOOTH_DEVICE_NAME - string "Bluetooth device name" - default "Zephyr" - help - Bluetooth device name. Name can be up to 248 bytes long (excluding - NULL termination). Can be empty string. - -if BLUETOOTH_DEBUG - -config BLUETOOTH_DEBUG_GATT - bool "Bluetooth Generic Attribute Profile (GATT) debug" - help - This option enables debug support for the Bluetooth - Generic Attribute Profile (GATT). - -config NBLE_DEBUG_GAP - bool "NBLE Generic Access Profile (GAP) debug" - help - This option enables debug support for the Bluetooth - Generic Access Profile (GAP) in the interfaces to the - Nordic chip. - -config NBLE_DEBUG_CONN - bool "NBLE connection debug" - help - This option enables debug support for Bluetooth - connections in the nble driver. - -config NBLE_DEBUG_RPC - bool "NBLE RPC debug" - help - This option enables debug for RPC interface to the Nordic - Bluetooth LE chip. - -endif # BLUETOOTH_DEBUG - -config NBLE_UART_ON_DEV_NAME - string "Device Name of UART Device for Nordic BLE" - default "UART_0" - depends on NBLE - help - This option specifies the name of UART device to be used - for Nordic BLE. - -endif diff --git a/drivers/bluetooth/nble/Makefile b/drivers/bluetooth/nble/Makefile deleted file mode 100644 index a1bc8e86ea..0000000000 --- a/drivers/bluetooth/nble/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -ccflags-y += -I$(srctree)/subsys/bluetooth - -obj-$(CONFIG_NBLE) += gap.o conn.o gatt.o uart.o rpc_serialize.o \ - rpc_deserialize.o stubs.o smp.o \ - ../../../subsys/bluetooth/host/uuid.o diff --git a/drivers/bluetooth/nble/conn.c b/drivers/bluetooth/nble/conn.c deleted file mode 100644 index c7f630d8ea..0000000000 --- a/drivers/bluetooth/nble/conn.c +++ /dev/null @@ -1,535 +0,0 @@ -/* - * Copyright (c) 2016 Intel Corporation - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -#include -#include - -#include -#include -#include - -#define BT_DBG_ENABLED IS_ENABLED(CONFIG_NBLE_DEBUG_CONN) -#include "common/log.h" - -#include "gap_internal.h" -#include "gatt_internal.h" -#include "conn_internal.h" -#include "smp.h" - -/* Peripheral timeout to initialize Connection Parameter Update procedure */ -#define CONN_UPDATE_TIMEOUT K_SECONDS(5) - -static struct bt_conn conns[CONFIG_BLUETOOTH_MAX_CONN]; -static struct bt_conn_cb *callback_list; - -static struct bt_conn *conn_new(void) -{ - struct bt_conn *conn = NULL; - int i; - - for (i = 0; i < ARRAY_SIZE(conns); i++) { - if (!atomic_get(&conns[i].ref)) { - conn = &conns[i]; - break; - } - } - - if (!conn) { - return NULL; - } - - memset(conn, 0, sizeof(*conn)); - - atomic_set(&conn->ref, 1); - - return conn; -} - -static struct bt_conn *conn_get(const bt_addr_le_t *peer) -{ - struct bt_conn *conn; - - if (peer) { - conn = bt_conn_lookup_addr_le(peer); - if (conn) { - return conn; - } - } - - return conn_new(); -} - -struct bt_conn *bt_conn_ref(struct bt_conn *conn) -{ - atomic_inc(&conn->ref); - - BT_DBG("handle %u ref %u", conn->handle, atomic_get(&conn->ref)); - - return conn; -} - -void bt_conn_unref(struct bt_conn *conn) -{ - atomic_dec(&conn->ref); - - BT_DBG("handle %u ref %u", conn->handle, atomic_get(&conn->ref)); -} - -struct bt_conn *bt_conn_lookup_handle(u16_t handle) -{ - int i; - - for (i = 0; i < ARRAY_SIZE(conns); i++) { - if (!atomic_get(&conns[i].ref)) { - continue; - } - - if (conns[i].handle == handle) { - return bt_conn_ref(&conns[i]); - } - } - - return NULL; -} - -struct bt_conn *bt_conn_lookup_addr_le(const bt_addr_le_t *peer) -{ - int i; - - for (i = 0; i < ARRAY_SIZE(conns); i++) { - if (!atomic_get(&conns[i].ref)) { - continue; - } - - if (!bt_addr_le_cmp(peer, &conns[i].dst)) { - return bt_conn_ref(&conns[i]); - } - } - - return NULL; -} - -const bt_addr_le_t *bt_conn_get_dst(const struct bt_conn *conn) -{ - return &conn->dst; -} - -int bt_conn_get_info(const struct bt_conn *conn, struct bt_conn_info *info) -{ - memset(info, 0, sizeof(*info)); - - info->type = BT_CONN_TYPE_LE; - info->role = conn->role; - info->le.dst = &conn->dst; - info->le.src = &nble.addr; - info->le.interval = conn->interval; - info->le.latency = conn->latency; - info->le.timeout = conn->timeout; - - return 0; -} - -static inline bool bt_le_conn_params_valid(u16_t min, u16_t max, - u16_t latency, u16_t timeout) -{ - if (min > max || min < 6 || max > 3200) { - return false; - } - - /* Limits according to BT Core spec 4.2 [Vol 2, Part E, 7.8.12] */ - if (timeout < 10 || timeout > 3200 || - (2 * timeout) < ((1 + latency) * max * 5)) { - return false; - } - - /* Limits according to BT Core spec 4.2 [Vol 6, Part B, 4.5.1] */ - if (latency > 499 || ((latency + 1) * max) > (timeout * 4)) { - return false; - } - - return true; -} - -int bt_conn_le_param_update(struct bt_conn *conn, - const struct bt_le_conn_param *param) -{ - struct nble_gap_conn_update_req req; - - /* Check if there's a need to update conn params */ - if (conn->interval >= param->interval_min && - conn->interval <= param->interval_max) { - return -EALREADY; - } - - /* Cancel any pending update */ - k_delayed_work_cancel(&conn->update_work); - - if (!bt_le_conn_params_valid(param->interval_min, param->interval_max, - param->latency, param->timeout)) { - return -EINVAL; - } - - req.conn_handle = conn->handle; - req.params.interval_min = param->interval_min; - req.params.interval_max = param->interval_max; - req.params.slave_latency = param->latency; - req.params.link_sup_to = param->timeout; - - nble_gap_conn_update_req(&req); - - return 0; -} - -int bt_conn_disconnect(struct bt_conn *conn, u8_t reason) -{ - struct nble_gap_disconnect_req req; - - switch (conn->state) { - case BT_CONN_CONNECT: - nble_gap_cancel_connect_req(conn); - return 0; - case BT_CONN_CONNECTED: - break; - case BT_CONN_DISCONNECT: - BT_ERR("Disconnecting already"); - return -EBUSY; - default: - return -ENOTCONN; - } - - /* Handle disconnect */ - req.conn_handle = conn->handle; - req.reason = reason; - - conn->state = BT_CONN_DISCONNECT; - - nble_gap_disconnect_req(&req); - - return 0; -} - -void on_nble_gap_disconnect_rsp(const struct nble_common_rsp *rsp) -{ - if (rsp->status) { - BT_ERR("Disconnect failed, status %d", rsp->status); - return; - } - - BT_DBG("conn %p", rsp->user_data); -} - -void on_nble_gap_cancel_connect_rsp(const struct nble_common_rsp *rsp) -{ - if (rsp->status) { - BT_ERR("Cancel connect failed, status %d", rsp->status); - return; - } - - BT_DBG("conn %p", rsp->user_data); -} - -struct bt_conn *bt_conn_create_le(const bt_addr_le_t *peer, - const struct bt_le_conn_param *param) -{ - struct nble_gap_connect_req req; - struct bt_conn *conn; - - BT_DBG(""); - - if (!bt_le_conn_params_valid(param->interval_min, param->interval_max, - param->latency, param->timeout)) { - return NULL; - } - - conn = conn_get(peer); - if (!conn) { - BT_ERR("Unable to get bt_conn object"); - return NULL; - } - - /* Update connection parameters */ - bt_addr_le_copy(&conn->dst, peer); - conn->latency = param->latency; - conn->timeout = param->timeout; - - memset(&req, 0, sizeof(req)); - - /* Construct parameters to NBLE */ - bt_addr_le_copy(&req.bda, peer); - - req.conn_params.interval_min = param->interval_min; - req.conn_params.interval_max = param->interval_max; - req.conn_params.slave_latency = param->latency; - req.conn_params.link_sup_to = param->timeout; - - req.scan_params.interval = BT_GAP_SCAN_FAST_INTERVAL; - req.scan_params.window = BT_GAP_SCAN_FAST_WINDOW; - - conn->state = BT_CONN_CONNECT; - - nble_gap_connect_req(&req, conn); - - return conn; -} - -void on_nble_gap_connect_rsp(const struct nble_common_rsp *rsp) -{ - if (rsp->status) { - BT_ERR("Connect failed, status %d", rsp->status); - return; - } - - BT_DBG("conn %p", rsp->user_data); -} - -static int start_security(struct bt_conn *conn) -{ - switch (conn->role) { - case BT_HCI_ROLE_MASTER: - return bt_smp_send_pairing_req(conn); - case BT_HCI_ROLE_SLAVE: - return bt_smp_send_security_req(conn); - default: - return -EINVAL; - } -} - -int bt_conn_security(struct bt_conn *conn, bt_security_t sec) -{ - int err; - - BT_DBG("conn %p sec %u", conn, sec); - - if (conn->state != BT_CONN_CONNECTED) { - return -ENOTCONN; - } - - /* nothing to do */ - if (conn->sec_level >= sec || conn->required_sec_level >= sec) { - return 0; - } - - conn->required_sec_level = sec; - - err = start_security(conn); - if (err) { - conn->required_sec_level = conn->sec_level; - } - - return err; -} - -u8_t bt_conn_enc_key_size(struct bt_conn *conn) -{ - return 0; -} - -void bt_conn_cb_register(struct bt_conn_cb *cb) -{ - cb->_next = callback_list; - callback_list = cb; -} - -int bt_le_set_auto_conn(bt_addr_le_t *addr, - const struct bt_le_conn_param *param) -{ - return -ENOSYS; -} - -struct bt_conn *bt_conn_create_slave_le(const bt_addr_le_t *peer, - const struct bt_le_adv_param *param) -{ - return NULL; -} - -int bt_conn_auth_cb_register(const struct bt_conn_auth_cb *cb) -{ - if (!cb) { - nble.auth = NULL; - return 0; - } - - /* cancel callback should always be provided */ - if (!cb->cancel) { - return -EINVAL; - } - - if (nble.auth) { - return -EALREADY; - } - - nble.auth = cb; - - return 0; -} - -int bt_conn_auth_passkey_entry(struct bt_conn *conn, unsigned int passkey) -{ - return bt_smp_auth_passkey_entry(conn, passkey); -} - -int bt_conn_auth_cancel(struct bt_conn *conn) -{ - BT_DBG(""); - - return bt_smp_auth_cancel(conn); -} - -int bt_conn_auth_passkey_confirm(struct bt_conn *conn) -{ - return -ENOSYS; -} - -int bt_conn_auth_pairing_confirm(struct bt_conn *conn) -{ - BT_DBG(""); - - return bt_smp_auth_pairing_confirm(conn); -} - -/* Connection related events */ - -static void notify_connected(struct bt_conn *conn) -{ - struct bt_conn_cb *cb; - - /* TODO: Add l2cap_connected callback if needed */ - - bt_smp_connected(conn); - bt_gatt_connected(conn); - - for (cb = callback_list; cb; cb = cb->_next) { - if (cb->connected) { - cb->connected(conn, 0); - } - } -} - -static void notify_disconnected(struct bt_conn *conn) -{ - struct bt_conn_cb *cb; - - bt_gatt_disconnected(conn); - bt_smp_disconnected(conn); - - /* - * FIXME: When disconnected NBLE stops advertising, this should - * be fixed in the NBLE firmware, use this hack for now - */ - if (atomic_test_bit(&nble.flags, NBLE_FLAG_KEEP_ADVERTISING)) { - BT_WARN("Re-enable advertising on disconnect"); - nble_gap_start_adv_req(); - } - - for (cb = callback_list; cb; cb = cb->_next) { - if (cb->disconnected) { - cb->disconnected(conn, 0); - } - } -} - -static void le_conn_update(struct k_work *work) -{ - struct bt_conn *conn = CONTAINER_OF(work, struct bt_conn, update_work); - - bt_conn_le_param_update(conn, BT_LE_CONN_PARAM_DEFAULT); -} - -void on_nble_gap_connect_evt(const struct nble_gap_connect_evt *ev) -{ - struct bt_conn *conn; - - BT_DBG("handle %u role %u", ev->conn_handle, ev->role_slave); - - conn = conn_get(&ev->peer_bda); - if (!conn) { - BT_ERR("Unable to get bt_conn object"); - return; - } - - conn->handle = ev->conn_handle; - conn->role = ev->role_slave ? BT_CONN_ROLE_SLAVE : BT_CONN_ROLE_MASTER; - conn->interval = ev->conn_values.interval; - conn->latency = ev->conn_values.latency; - conn->timeout = ev->conn_values.supervision_to; - bt_addr_le_copy(&conn->dst, &ev->peer_bda); - k_delayed_work_init(&conn->update_work, le_conn_update); - - conn->state = BT_CONN_CONNECTED; - - notify_connected(conn); - - /* - * Core 4.2 Vol 3, Part C, 9.3.12.2 - * The Peripheral device should not perform a Connection Parameter - * Update procedure within 5 s after establishing a connection. - */ - k_delayed_work_submit(&conn->update_work, - conn->role == BT_HCI_ROLE_MASTER ? K_NO_WAIT : - CONN_UPDATE_TIMEOUT); -} - -void on_nble_gap_disconnect_evt(const struct nble_gap_disconnect_evt *ev) -{ - struct bt_conn *conn; - - conn = bt_conn_lookup_handle(ev->conn_handle); - if (!conn) { - BT_ERR("Unable to find conn for handle %u", ev->conn_handle); - return; - } - - BT_DBG("conn %p handle %u", conn, ev->conn_handle); - - conn->state = BT_CONN_DISCONNECTED; - - notify_disconnected(conn); - - /* Cancel Connection Update if it is pending */ - k_delayed_work_cancel(&conn->update_work); - - /* Drop the reference given by lookup_handle() */ - bt_conn_unref(conn); - /* Drop the initial reference from conn_new() */ - bt_conn_unref(conn); -} - -static void notify_le_param_updated(struct bt_conn *conn) -{ - struct bt_conn_cb *cb; - - for (cb = callback_list; cb; cb = cb->_next) { - if (cb->le_param_updated) { - cb->le_param_updated(conn, conn->interval, - conn->latency, conn->timeout); - } - } -} - -void on_nble_gap_conn_update_evt(const struct nble_gap_conn_update_evt *ev) -{ - struct bt_conn *conn; - - conn = bt_conn_lookup_handle(ev->conn_handle); - if (!conn) { - BT_ERR("Unable to find conn for handle %u", ev->conn_handle); - return; - } - - BT_DBG("conn %p handle %u interval %u latency %u to %u", - conn, ev->conn_handle, ev->conn_values.interval, - ev->conn_values.latency, ev->conn_values.supervision_to); - - conn->interval = ev->conn_values.interval; - conn->latency = ev->conn_values.latency; - conn->timeout = ev->conn_values.supervision_to; - - notify_le_param_updated(conn); - - bt_conn_unref(conn); -} diff --git a/drivers/bluetooth/nble/conn.h b/drivers/bluetooth/nble/conn.h deleted file mode 100644 index 6fcf5457cb..0000000000 --- a/drivers/bluetooth/nble/conn.h +++ /dev/null @@ -1,7 +0,0 @@ -/* - * Copyright (c) 2016 Intel Corporation - * - * SPDX-License-Identifier: Apache-2.0 - */ - -struct bt_conn *bt_conn_lookup_handle(u16_t handle); diff --git a/drivers/bluetooth/nble/conn_internal.h b/drivers/bluetooth/nble/conn_internal.h deleted file mode 100644 index 403bbcfecf..0000000000 --- a/drivers/bluetooth/nble/conn_internal.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2016 Intel Corporation - * - * SPDX-License-Identifier: Apache-2.0 - */ - -struct bt_conn { - u16_t handle; - u8_t role; - atomic_t ref; - - bt_addr_le_t dst; - - bt_security_t sec_level; - bt_security_t required_sec_level; - - u16_t interval; - u16_t latency; - u16_t timeout; - - enum { - BT_CONN_DISCONNECTED, - BT_CONN_CONNECT, - BT_CONN_CONNECTED, - BT_CONN_DISCONNECT, - } state; - - /* Delayed work used to update connection parameters */ - struct k_delayed_work update_work; - - void *gatt_private; - struct k_sem gatt_notif_sem; -}; diff --git a/drivers/bluetooth/nble/gap.c b/drivers/bluetooth/nble/gap.c deleted file mode 100644 index 3af8296c98..0000000000 --- a/drivers/bluetooth/nble/gap.c +++ /dev/null @@ -1,380 +0,0 @@ -/* - * Copyright (c) 2016 Intel Corporation - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include - -#include -#include - -#include -#include -#include -#include - -#define BT_DBG_ENABLED IS_ENABLED(CONFIG_NBLE_DEBUG_GAP) -#include "common/log.h" - -#include "gap_internal.h" -#include "conn_internal.h" -#include "gatt_internal.h" -#include "uart.h" -#include "conn.h" -#include "rpc.h" -#include "smp.h" - -#define NBLE_VERSION(a, b, c) \ - ((((a) & 0xFF) << 16) | (((b) & 0xFF) << 8) | ((c) & 0xFF)) - -#define NBLE_VERSION_MAJOR(v) (((v) >> 16) & 0xFF) -#define NBLE_VERSION_MINOR(v) (((v) >> 8) & 0xFF) -#define NBLE_VERSION_PATCH(v) (((v) >> 0) & 0xFF) - -/* Set the firmware compatible with Nordic BLE RPC */ -static const u32_t compatible_firmware = NBLE_VERSION(4, 0, 31); - -static bt_ready_cb_t bt_ready_cb; -static bt_le_scan_cb_t *scan_dev_found_cb; - -struct nble nble; - -static const struct bt_storage *storage; - -static void clear_bonds(const bt_addr_le_t *addr) -{ - struct nble_sm_clear_bonds_req params = { { 0 }, }; - - bt_addr_le_copy(¶ms.addr, addr); - - nble_sm_clear_bonds_req(¶ms); -} - -int bt_enable(bt_ready_cb_t cb) -{ - int ret; - - BT_DBG(""); - - if (!cb) { - /* With nble the callback is mandatory */ - return -EINVAL; - } - - if (atomic_test_and_set_bit(&nble.flags, NBLE_FLAG_ENABLE)) { - return -EALREADY; - } - - ret = nble_open(); - if (ret) { - return ret; - } - - bt_ready_cb = cb; - - return 0; -} - -static bool valid_adv_param(const struct bt_le_adv_param *param) -{ - if (!(param->options & BT_LE_ADV_OPT_CONNECTABLE)) { - /* - * BT Core 4.2 [Vol 2, Part E, 7.8.5] - * The Advertising_Interval_Min and Advertising_Interval_Max - * shall not be set to less than 0x00A0 (100 ms) if the - * Advertising_Type is set to ADV_SCAN_IND or ADV_NONCONN_IND. - */ - - if (param->interval_min < 0x00a0) { - return false; - } - } - - if (param->interval_min > param->interval_max || - param->interval_min < 0x0020 || param->interval_max > 0x4000) { - return false; - } - - return true; -} - -static int set_ad(struct nble_eir_data *eir, const struct bt_data *ad, - size_t ad_len) -{ - int i; - - for (i = 0; i < ad_len; i++) { - u8_t *p; - - /* Check if ad fit in the remaining buffer */ - if (eir->len + ad[i].data_len + 2 > 31) { - return -ENOMEM; - } - - p = &eir->data[eir->len]; - *p++ = ad[i].data_len + 1; - *p++ = ad[i].type; - memcpy(p, ad[i].data, ad[i].data_len); - eir->len += ad[i].data_len + 2; - } - - return 0; -} - -int bt_le_adv_start(const struct bt_le_adv_param *param, - const struct bt_data *ad, size_t ad_len, - const struct bt_data *sd, size_t sd_len) -{ - struct nble_gap_set_adv_params_req params = { 0 }; - struct nble_gap_set_adv_data_req data = { 0 }; - int err; - - if (!valid_adv_param(param)) { - return -EINVAL; - } - - err = set_ad(&data.ad, ad, ad_len); - if (err) { - BT_ERR("Error setting ad data %d", err); - return err; - } - - err = set_ad(&data.sd, sd, sd_len); - if (err) { - BT_ERR("Error setting scan response data %d", err); - return err; - } - - /* Set advertising data */ - nble_gap_set_adv_data_req(&data); - - /* TODO: Timeout is handled by application timer */ - params.timeout = 0; - /* forced to none currently (no whitelist support) */ - params.filter_policy = 0; - params.interval_max = param->interval_max; - params.interval_min = param->interval_min; - - if (param->options & BT_LE_ADV_OPT_CONNECTABLE) { - params.type = BT_LE_ADV_IND; - } else { - if (sd) { - params.type = BT_LE_ADV_SCAN_IND; - } else { - params.type = BT_LE_ADV_NONCONN_IND; - } - } - - /* Set advertising parameters */ - nble_gap_set_adv_params_req(¶ms); - - /* Start advertising */ - nble_gap_start_adv_req(); - - return 0; -} - -void on_nble_gap_start_adv_rsp(const struct nble_common_rsp *rsp) -{ - if (rsp->status) { - BT_ERR("Start advertise falied, status %d", rsp->status); - return; - } - - atomic_set_bit(&nble.flags, NBLE_FLAG_KEEP_ADVERTISING); - - BT_DBG("status %u", rsp->status); -} - -int bt_le_adv_stop(void) -{ - BT_DBG(""); - - nble_gap_stop_adv_req(NULL); - - return 0; -} - -void on_nble_gap_stop_advertise_rsp(const struct nble_common_rsp *rsp) -{ - if (rsp->status) { - BT_ERR("Stop advertise failed, status %d", rsp->status); - return; - } - - atomic_clear_bit(&nble.flags, NBLE_FLAG_KEEP_ADVERTISING); - - BT_DBG("status %d", rsp->status); -} - -static bool valid_le_scan_param(const struct bt_le_scan_param *param) -{ - if (param->type != BT_HCI_LE_SCAN_PASSIVE && - param->type != BT_HCI_LE_SCAN_ACTIVE) { - return false; - } - - if (param->filter_dup != BT_HCI_LE_SCAN_FILTER_DUP_DISABLE && - param->filter_dup != BT_HCI_LE_SCAN_FILTER_DUP_ENABLE) { - return false; - } - - if (param->interval < 0x0004 || param->interval > 0x4000) { - return false; - } - - if (param->window < 0x0004 || param->window > 0x4000) { - return false; - } - - if (param->window > param->interval) { - return false; - } - - return true; -} - -int bt_le_scan_start(const struct bt_le_scan_param *param, bt_le_scan_cb_t cb) -{ - struct nble_gap_start_scan_req nble_params; - - BT_DBG(""); - - /* Check that the parameters have valid values */ - if (!valid_le_scan_param(param)) { - return -EINVAL; - } - - nble_params.scan_params.interval = param->interval; - nble_params.scan_params.window = param->window; - nble_params.scan_params.scan_type = param->type; - nble_params.scan_params.use_whitelist = 0; - - /* Check is scan already enabled */ - - scan_dev_found_cb = cb; - - nble_gap_start_scan_req(&nble_params); - - return 0; -} - -void on_nble_gap_adv_report_evt(const struct nble_gap_adv_report_evt *evt, - const u8_t *buf, u8_t len) -{ - BT_DBG(""); - - if (scan_dev_found_cb) { - struct net_buf_simple *data = NET_BUF_SIMPLE(31); - - net_buf_simple_init(data, 0); - memcpy(net_buf_simple_add(data, len), buf, len); - - scan_dev_found_cb(&evt->addr, evt->rssi, evt->adv_type, data); - } -} - -int bt_le_scan_stop(void) -{ - BT_DBG(""); - - scan_dev_found_cb = NULL; - - nble_gap_stop_scan_req(); - - return 0; -} - -void on_nble_gap_scan_start_stop_rsp(const struct nble_common_rsp *rsp) -{ - if (rsp->status) { - BT_ERR("Unable to stop scan, status %d", rsp->status); - return; - } - - BT_DBG(""); -} - -void nble_log(const struct nble_log_s *param, char *format, u8_t len) -{ -#if defined(CONFIG_BLUETOOTH_DEBUG) - /* Build meaningful output */ - printf("nble: "); - printf(format, param->param0, param->param1, param->param2, - param->param3); - printf("\n"); -#endif -} - -void on_nble_get_bda_rsp(const struct nble_get_bda_rsp *rsp) -{ - bt_addr_le_copy(&nble.addr, &rsp->bda); - - BT_DBG("Local bdaddr: %s", bt_addr_le_str(&nble.addr)); - - /* Make sure the nRF51 persistent memory is cleared */ - clear_bonds(BT_ADDR_LE_ANY); - - if (bt_ready_cb) { - bt_ready_cb(0); - bt_ready_cb = NULL; - } -} - -void on_nble_common_rsp(const struct nble_common_rsp *rsp) -{ - if (rsp->status) { - BT_ERR("Last request failed, error %d", rsp->status); - return; - } - - BT_DBG("status %d", rsp->status); -} - -void rpc_init_cb(u32_t version, bool compatible) -{ - BT_DBG(""); - - if (!compatible) { - BT_ERR("\n\n" - "RPC reported incompatible firmware" - "\n\n"); - } - if (version != compatible_firmware) { - BT_ERR("\n\n" - "Incompatible firmware: %d.%d.%d, " - "please use version %d.%d.%d" - "\n\n", - NBLE_VERSION_MAJOR(version), - NBLE_VERSION_MINOR(version), - NBLE_VERSION_PATCH(version), - NBLE_VERSION_MAJOR(compatible_firmware), - NBLE_VERSION_MINOR(compatible_firmware), - NBLE_VERSION_PATCH(compatible_firmware)); - /* TODO: shall we allow to continue */ - } - - bt_smp_init(); - bt_gatt_init(); -} - -void bt_storage_register(const struct bt_storage *bt_storage) -{ - storage = bt_storage; -} - -int bt_storage_clear(const bt_addr_le_t *addr) -{ - clear_bonds(addr); - /* FIXME: make the necessary storage callbacks too. */ - return 0; -} - -int bt_le_oob_get_local(struct bt_le_oob *oob) -{ - bt_addr_le_copy(&oob->addr, &nble.addr); - - return 0; -} diff --git a/drivers/bluetooth/nble/gap_internal.h b/drivers/bluetooth/nble/gap_internal.h deleted file mode 100644 index 7589219a05..0000000000 --- a/drivers/bluetooth/nble/gap_internal.h +++ /dev/null @@ -1,614 +0,0 @@ -/** @file - * @brief Internal API for Generic Access Profile. - */ - -/* - * Copyright (c) 2016 Intel Corporation - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/* Maximum security key len (LTK, CSRK) */ -#define BLE_GAP_SEC_MAX_KEY_LEN 16 - -#define BT_SMP_AUTH_NONE 0x00 -#define BT_SMP_AUTH_BONDING 0x01 -#define BT_SMP_AUTH_MITM 0x04 -#define BT_SMP_AUTH_SC 0x08 - -#define BT_SMP_ERR_PASSKEY_ENTRY_FAILED 0x01 -#define BT_SMP_ERR_OOB_NOT_AVAIL 0x02 -#define BT_SMP_ERR_AUTH_REQUIREMENTS 0x03 -#define BT_SMP_ERR_CONFIRM_FAILED 0x04 -#define BT_SMP_ERR_PAIRING_NOTSUPP 0x05 -#define BT_SMP_ERR_ENC_KEY_SIZE 0x06 -#define BT_SMP_ERR_CMD_NOTSUPP 0x07 -#define BT_SMP_ERR_UNSPECIFIED 0x08 -#define BT_SMP_ERR_REPEATED_ATTEMPTS 0x09 -#define BT_SMP_ERR_INVALID_PARAMS 0x0a -#define BT_SMP_ERR_DHKEY_CHECK_FAILED 0x0b -#define BT_SMP_ERR_NUMERIC_COMP_FAILED 0x0c -#define BT_SMP_ERR_BREDR_PAIRING_IN_PROGRESS 0x0d -#define BT_SMP_ERR_CROSS_TRANSP_NOT_ALLOWED 0x0e - -enum NBLE_GAP_SM_PASSKEY_TYPE { - NBLE_GAP_SM_REJECT = 0, - NBLE_GAP_SM_PK_PASSKEY, - NBLE_GAP_SM_PK_OOB, -}; - -enum NBLE_GAP_SM_EVT { - NBLE_GAP_SM_EVT_START_PAIRING, - NBLE_GAP_SM_EVT_BONDING_COMPLETE, - NBLE_GAP_SM_EVT_LINK_ENCRYPTED, - NBLE_GAP_SM_EVT_LINK_SECURITY_CHANGE, -}; - -struct nble_log_s { - u8_t param0; - u8_t param1; - u8_t param2; - u8_t param3; -}; - -void nble_log(const struct nble_log_s *par, char *data, u8_t len); - -struct nble_common_rsp { - int status; - void *user_data; -}; - -struct bt_local_addr { - bt_addr_le_t id_addr; -#if defined(CONFIG_BLUETOOTH_PRIVACY) - bt_addr_le_t rpa; -#endif -}; - -void on_nble_common_rsp(const struct nble_common_rsp *rsp); - -void nble_panic_req(void); - -struct nble_version { - u8_t version; - u8_t major; - u8_t minor; - u8_t patch; - char version_string[20]; - u8_t build_hash[4]; - u8_t hash[4]; -}; - -typedef void (*ble_get_version_cb_t)(const struct nble_version *ver); - -void nble_get_version_req(ble_get_version_cb_t cb); - -struct nble_get_version_rsp { - ble_get_version_cb_t cb; - struct nble_version ver; -}; - -void on_nble_get_version_rsp(const struct nble_get_version_rsp *rsp); - -enum NBLE_GAP_SVC_ATTR_TYPE { - /* Device Name, UUID 0x2a00 */ - NBLE_GAP_SVC_ATTR_NAME = 0, - /* Appearance, UUID 0x2a01 */ - NBLE_GAP_SVC_ATTR_APPEARANCE, - /* Peripheral Preferred Connection Parameters (PPCP), UUID 0x2a04 */ - NBLE_GAP_SVC_ATTR_PPCP = 4, - /* Central Address Resolution (CAR), UUID 0x2aa6, BT 4.2 */ - NBLE_GAP_SVC_ATTR_CAR = 0xa6, -}; - -struct nble_gap_device_name { - /* Security mode for writing device name, see BLE_GAP_SEC_MODES */ - u8_t sec_mode; - /* 0: no authorization, 1: authorization required */ - u8_t authorization; - /* Device name length (0-248) */ - u8_t len; - u8_t name_array[20]; -}; - -struct nble_conn_param { - /* minimal connection interval: range 0x0006 to 0x0c80 (unit 1.25ms) */ - u16_t interval_min; - /* maximum connection interval: range 0x0006 to 0x0c80 must be bigger then min! */ - u16_t interval_max; - /* maximum connection slave latency: 0x0000 to 0x01f3 */ - u16_t slave_latency; - /* link supervision timeout: 0x000a to 0x0c80 (unit 10ms) */ - u16_t link_sup_to; -}; - -struct nble_gap_service_req { - /* GAP Characteristics attribute type see NBLE_GAP_SVC_ATTR_TYPE */ - u16_t attr_type; - union { - struct nble_gap_device_name name; - /* Appearance UUID */ - u16_t appearance; - /* Preferred Peripheral Connection Parameters */ - struct nble_conn_param ppcp; - /* Central Address Resolution support 0: no, 1: yes */ - u8_t car; - }; -}; - -void nble_gap_service_req(const struct nble_gap_service_req *req); - -struct nble_dbg_req { - u32_t u0; - u32_t u1; - void *user_data; -}; - -void nble_dbg_req(const struct nble_dbg_req *req); - -struct nble_dbg_rsp { - int status; - u32_t u0; - u32_t u1; - void *user_data; -}; - -void on_nble_dbg_rsp(const struct nble_dbg_rsp *rsp); - -typedef void (*nble_set_bda_cb_t)(int status, void *user_data, const bt_addr_le_t *bda); - -struct nble_set_bda_req { - nble_set_bda_cb_t cb; - void *user_data; - bt_addr_le_t bda; -}; - -void nble_set_bda_req(const struct nble_set_bda_req *req); - -struct nble_set_bda_rsp { - nble_set_bda_cb_t cb; - void *user_data; - int status; - bt_addr_le_t bda; -}; - -void on_nble_set_bda_rsp(const struct nble_set_bda_rsp *rsp); - -typedef void (*nble_get_bda_cb_t)(const bt_addr_le_t *bda, void *user_data); - -struct nble_get_bda_req { - nble_get_bda_cb_t cb; - void *user_data; -}; - -void nble_get_bda_req(const struct nble_get_bda_req *req); - -struct nble_get_bda_rsp { - nble_get_bda_cb_t cb; - void *user_data; - bt_addr_le_t bda; -}; - -void on_nble_get_bda_rsp(const struct nble_get_bda_rsp *rsp); - -struct nble_eir_data { - u8_t len; - u8_t data[31]; -}; - -struct nble_gap_set_adv_data_req { - /* Advertisement data, maybe 0 (length) */ - struct nble_eir_data ad; - /* Scan response data, maybe 0 (length) */ - struct nble_eir_data sd; -}; - -void nble_gap_set_adv_data_req(struct nble_gap_set_adv_data_req *req); - -struct nble_gap_set_adv_params_req { - u16_t timeout; - /* min interval 0xffff: use default 0x0800 */ - u16_t interval_min; - /* max interval 0xffff: use default 0x0800 */ - u16_t interval_max; - /* advertisement types see GAP_ADV_TYPES */ - u8_t type; - /* filter policy to apply with white list */ - u8_t filter_policy; - /* bd address of peer device in case of directed advertisement */ - bt_addr_le_t peer_bda; -}; - -void nble_gap_set_adv_params_req(struct nble_gap_set_adv_params_req *req); - -void nble_gap_start_adv_req(void); - -void on_nble_gap_start_adv_rsp(const struct nble_common_rsp *rsp); - -void nble_gap_stop_adv_req(void *user_data); - -struct nble_gap_conn_update_req { - u16_t conn_handle; - struct nble_conn_param params; -}; - -void nble_gap_conn_update_req(const struct nble_gap_conn_update_req *req); - -void on_nble_gap_conn_update_rsp(const struct nble_common_rsp *rsp); - -struct nble_gap_disconnect_req { - u16_t conn_handle; - u8_t reason; -}; - -void nble_gap_disconnect_req(const struct nble_gap_disconnect_req *req); - -struct nble_sm_config_rsp { - void *user_data; - int status; - bool sm_bond_dev_avail; -}; - -void on_nble_sm_config_rsp(struct nble_sm_config_rsp *rsp); - -struct nble_sm_pairing_param { - /* authentication level see BLE_GAP_SM_OPTIONS */ - u8_t auth; - u8_t io_capabilities; - u8_t max_key_size; - u8_t min_key_size; - u8_t oob_flag; -}; - -struct nble_sm_security_req { - struct bt_conn *conn; - u16_t conn_handle; - /* Local authentication/bonding parameters */ - struct nble_sm_pairing_param params; -}; - -void nble_sm_security_req(const struct nble_sm_security_req *req); - -enum NBLE_SM_PASSKEY_TYPE { - NBLE_SM_PK_PASSKEY, - NBLE_SM_PK_OOB, -}; - -struct nble_sm_passkey { - u8_t type; /* see NBLE_SM_PASSKEY_TYPE */ - union { - u32_t passkey; - u8_t oob[16]; - u8_t reason; - }; -}; - -struct nble_sm_passkey_reply_req { - struct bt_conn *conn; - u16_t conn_handle; - struct nble_sm_passkey params; -}; - -void nble_sm_passkey_reply_req(const struct nble_sm_passkey_reply_req *req); - -struct nble_sm_clear_bonds_req { - bt_addr_le_t addr; -}; - -void nble_sm_clear_bonds_req(const struct nble_sm_clear_bonds_req *req); - -struct nble_sm_common_rsp { - int status; - struct bt_conn *conn; -}; - -void on_nble_sm_common_rsp(const struct nble_sm_common_rsp *rsp); - -struct nble_sm_pairing_response_req { - struct bt_conn *conn; - u16_t conn_handle; - struct nble_sm_pairing_param params; -}; - -void nble_sm_pairing_response_req(const struct nble_sm_pairing_response_req *req); - -struct nble_sm_error_req { - struct bt_conn *conn; - u16_t conn_handle; - u8_t reason; -}; - -void nble_sm_error_req(const struct nble_sm_error_req *req); - -struct nble_gap_set_rssi_report_req { - u16_t conn_handle; - /* RSSI operation see NBLE_GAP_RSSI_OPS */ - u8_t op; - /* Channel for RSSI enabling */ - u8_t channel; - /* minimum RSSI dBm change to report a new RSSI value */ - u8_t delta_dBm; - /* number of delta_dBm changes before sending a new RSSI report */ - u8_t min_count; -}; - -void nble_gap_set_rssi_report_req(const struct nble_gap_set_rssi_report_req *req, - void *user_data); - -void on_nble_gap_set_rssi_report_rsp(const struct nble_common_rsp *rsp); - -struct nble_scan_param { - u16_t interval; - u16_t window; - /* Unused for the connection request */ - u8_t scan_type; - /* Unused for the connection request */ - u8_t use_whitelist; -}; - -struct nble_gap_start_scan_req { - struct nble_scan_param scan_params; -}; - -void nble_gap_start_scan_req(const struct nble_gap_start_scan_req *req); - -void nble_gap_stop_scan_req(void); - -void on_nble_gap_scan_start_stop_rsp(const struct nble_common_rsp *rsp); - -struct nble_gap_connect_req { - bt_addr_le_t bda; - struct nble_conn_param conn_params; - struct nble_scan_param scan_params; -}; - -void nble_gap_connect_req(const struct nble_gap_connect_req *req, - void *user_data); - -void on_nble_gap_connect_rsp(const struct nble_common_rsp *rsp); - -void nble_gap_cancel_connect_req(void *user_data); - -void on_nble_gap_cancel_connect_rsp(const struct nble_common_rsp *rsp); - -/* Temporary patch: RSSI processing for UAS */ -struct nble_uas_rssi_calibrate_req { - float distance; -}; -void nble_uas_rssi_calibrate_req(const struct nble_uas_rssi_calibrate_req *req); - -/* Temporary patch: RSSI processing for UAS */ -struct nble_uas_bucket_change { - u8_t distance; -}; - -void on_nble_uas_bucket_change(const struct nble_uas_bucket_change *par); - -void nble_gap_dtm_init_req(void *user_data); - -void on_nble_gap_dtm_init_rsp(void *user_data); - -struct nble_gap_set_tx_power_req { - s8_t tx_power; -}; - -void nble_gap_set_tx_power_req(const struct nble_gap_set_tx_power_req *req); - -void on_nble_gap_set_tx_power_rsp(const struct nble_common_rsp *rsp); - -struct nble_conn_values { - /* Connection interval (unit 1.25 ms) */ - u16_t interval; - /* Connection latency (unit interval) */ - u16_t latency; - /* Connection supervision timeout (unit 10ms)*/ - u16_t supervision_to; -}; - -struct nble_gap_connect_evt { - u16_t conn_handle; - struct nble_conn_values conn_values; - /* 0 if connected as master, otherwise as slave */ - u8_t role_slave; - /* Address of peer device */ - bt_addr_le_t peer_bda; -}; - -void on_nble_gap_connect_evt(const struct nble_gap_connect_evt *evt); - -struct nble_gap_disconnect_evt { - u16_t conn_handle; - u8_t hci_reason; -}; - -void on_nble_gap_disconnect_evt(const struct nble_gap_disconnect_evt *evt); - -struct nble_gap_conn_update_evt { - u16_t conn_handle; - struct nble_conn_values conn_values; -}; - -void on_nble_gap_conn_update_evt(const struct nble_gap_conn_update_evt *evt); - -struct nble_gap_adv_report_evt { - bt_addr_le_t addr; - s8_t rssi; - u8_t adv_type; -}; - -void on_nble_gap_adv_report_evt(const struct nble_gap_adv_report_evt *evt, - const u8_t *data, u8_t len); - -struct nble_gap_dir_adv_timeout_evt { - u16_t conn_handle; - u16_t error; -}; - -void on_nble_gap_dir_adv_timeout_evt(const struct nble_gap_dir_adv_timeout_evt *evt); - -#define BLE_GAP_RSSI_EVT_SIZE 32 - -struct nble_gap_rssi_evt { - u16_t conn_handle; - s8_t rssi_data[BLE_GAP_RSSI_EVT_SIZE]; -}; - -void on_nble_gap_rssi_evt(const struct nble_gap_rssi_evt *evt); - -struct nble_sm_passkey_req_evt { - u16_t conn_handle; - u8_t key_type; -}; - -void on_nble_sm_passkey_req_evt(const struct nble_sm_passkey_req_evt *evt); - -struct nble_sm_passkey_disp_evt { - u16_t conn_handle; - u32_t passkey; -}; - -void on_nble_sm_passkey_disp_evt(const struct nble_sm_passkey_disp_evt *evt); - -enum NBLE_SM_STATUS_EVT { - NBLE_SM_STATUS_START_PAIRING, - NBLE_SM_STATUS_BONDING_COMPLETE, - NBLE_SM_STATUS_LINK_ENCRYPTED, - NBLE_SM_STATUS_LINK_SECURITY_CHANGE, -}; - -struct nble_link_sec { - bt_security_t sec_level; - u8_t enc_size; -}; - -struct nble_sm_status_evt { - u16_t conn_handle; - u8_t evt_type; /* see NBLE_SM_STATUS_EVT */ - int status; - union { - struct nble_link_sec enc_link_sec; - bt_addr_le_t addr; - }; -}; - -void on_nble_sm_status_evt(const struct nble_sm_status_evt *evt); - -struct nble_sec_param { - u8_t auth; - u8_t io_capabilities; - u8_t min_key_size; - u8_t max_key_size; -}; - -struct nble_sm_pairing_request_evt { - u16_t conn_handle; - struct nble_sec_param sec_param; -}; - -void on_nble_sm_pairing_request_evt(const struct nble_sm_pairing_request_evt *evt); - -struct nble_sm_security_request_evt { - u16_t conn_handle; - struct nble_sec_param sec_param; -}; - -void on_nble_sm_security_request_evt(const struct nble_sm_security_request_evt *evt); - -struct nble_sm_bond_info; -typedef void (*ble_bond_info_cb_t)(const struct nble_sm_bond_info *info, - const bt_addr_le_t *addr, u16_t len, - void *user_data); - -struct nble_sm_bond_info_req { - ble_bond_info_cb_t cb; - void *user_data; - bool include_bonded_addrs; -}; - -void nble_sm_bond_info_req(const struct nble_sm_bond_info_req *req); - -struct nble_sm_bond_info { - int err; - u8_t addr_count; - u8_t irk_count; -}; - -struct nble_sm_bond_info_rsp { - ble_bond_info_cb_t cb; - void *user_data; - struct nble_sm_bond_info info; -}; - -void on_nble_sm_bond_info_rsp(const struct nble_sm_bond_info_rsp *rsp, - const bt_addr_le_t *peer_addr, u16_t len); - -struct nble_uart_test_req { - /* Test type: 1 = start peer test, 2 = loopback test */ - u16_t test_type; - /* Test type 1: Number of test events packets sent from peer to host */ - u16_t nb_loops; - /* Test type 1: The maximum delay between packets (in ms) */ - u16_t max_delay; - /* Test type 1: The maximum length of packets (in bytes) */ - u16_t max_len; -}; - -void nble_uart_test_req(const struct nble_uart_test_req *req, - const u8_t *data, u8_t len); - -struct nble_uart_test_evt { - /* Number of loops executed */ - u16_t nb_loops; -}; - -void on_nble_uart_test_evt(const struct nble_uart_test_evt *evt, - const u8_t *data, u8_t len); - -/* - * The following functions are NOT RPC functions - */ - -void ble_gap_get_bonding_info(ble_bond_info_cb_t func, void *user_data, - bool include_bonded_addrs); - -void ble_gap_get_version(ble_get_version_cb_t func); - -void ble_gap_get_bda_info(struct bt_local_addr *addr); - -enum NBLE_GAP_RSSI_OPS { - NBLE_GAP_RSSI_DISABLE_REPORT = 0, - NBLE_GAP_RSSI_ENABLE_REPORT -}; - -typedef void (*rssi_report_t)(const s8_t *rssi_data); - -typedef void (*rssi_report_resp_t)(int status); - -struct ble_rssi_report_params { - /* RSSI operation see NBLE_GAP_RSSI_OPS */ - u8_t op; - /* Channel for RSSI enabling */ - u8_t channel; - /* minimum RSSI dBm change to report a new RSSI value */ - u8_t delta_dBm; - /* number of delta_dBm changes before sending a new RSSI report */ - u8_t min_count; -}; - -void ble_gap_set_rssi_report(struct ble_rssi_report_params *par, - struct bt_conn *conn, - rssi_report_resp_t resp_cb, rssi_report_t evt_cb); - -enum { - NBLE_FLAG_ENABLE, - NBLE_FLAG_KEEP_ADVERTISING, -}; - -struct nble { - /* Local Bluetooth LE Device Address */ - bt_addr_le_t addr; - const struct bt_conn_auth_cb *auth; - atomic_t flags; -}; - -extern struct nble nble; diff --git a/drivers/bluetooth/nble/gatt.c b/drivers/bluetooth/nble/gatt.c deleted file mode 100644 index d4b1ad5bc0..0000000000 --- a/drivers/bluetooth/nble/gatt.c +++ /dev/null @@ -1,1614 +0,0 @@ -/* - * Copyright (c) 2016 Intel Corporation - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include - -#include -#include -#include - -#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BLUETOOTH_DEBUG_GATT) -#include "common/log.h" - -#include "conn.h" -#include "conn_internal.h" -#include "gatt_internal.h" - -#define NBLE_BUF_SIZE 384 - -/* TODO: Get this value during negotiation */ -#define BLE_GATT_MTU_SIZE 23 - -#if CONFIG_BLUETOOTH_ATT_PREPARE_COUNT > 0 -/* Pool for incoming ATT packets */ -NET_BUF_POOL_DEFINE(prep_pool, CONFIG_BLUETOOTH_ATT_PREPARE_COUNT, - BLE_GATT_MTU_SIZE, sizeof(struct nble_gatts_write_evt), - NULL); - -static K_FIFO_DEFINE(queue); -#endif - -struct nble_gatt_service { - const struct bt_gatt_attr *attrs; - u16_t attr_count; -}; - -static struct nble_gatt_service svc_db[BLE_GATTS_MAX_SERVICES]; -static u8_t svc_count; - -static sys_slist_t subscriptions; - -/** - * Copy a UUID in a buffer using the smallest memory length - * @param buf Pointer to the memory where the UUID shall be copied - * @param uuid Pointer to the UUID to copy - * @return The length required to store the UUID in the memory - */ -static u8_t bt_gatt_uuid_memcpy(u8_t *buf, const struct bt_uuid *uuid) -{ - u8_t *ptr = buf; - - /* Store the type of the UUID */ - *ptr = uuid->type; - ptr++; - - /* Store the UUID data */ - if (uuid->type == BT_UUID_TYPE_16) { - u16_t le16; - - le16 = sys_cpu_to_le16(BT_UUID_16(uuid)->val); - memcpy(ptr, &le16, sizeof(le16)); - ptr += sizeof(le16); - } else { - memcpy(ptr, BT_UUID_128(uuid)->val, 16); - ptr += 16; - } - - return ptr - buf; -} - -/* These attributes need the value to be read */ -static struct bt_uuid *whitelist[] = { - BT_UUID_GATT_PRIMARY, - BT_UUID_GATT_SECONDARY, - BT_UUID_GATT_INCLUDE, - BT_UUID_GATT_CHRC, - BT_UUID_GATT_CEP, - BT_UUID_GATT_CUD, - BT_UUID_GATT_CPF, - BT_UUID_GAP_DEVICE_NAME, - BT_UUID_GAP_APPEARANCE, - BT_UUID_GAP_PPCP -}; - -static int attr_read(struct bt_gatt_attr *attr, u8_t *data, size_t len) -{ - u8_t i; - int data_size; - - if (!data) { - return -ENOMEM; - } - - data_size = bt_gatt_uuid_memcpy(data, attr->uuid); - - for (i = 0; i < ARRAY_SIZE(whitelist); i++) { - if (!bt_uuid_cmp(attr->uuid, whitelist[i])) { - int read; - - read = attr->read(NULL, attr, data + data_size, len, 0); - if (read < 0) { - return read; - } - - data_size += read; - break; - } - } - - return data_size; -} - -int bt_gatt_register(struct bt_gatt_attr *attrs, size_t count) -{ - struct nble_gatts_register_req param; - size_t i; - /* TODO: Replace the following with net_buf */ - u8_t attr_table[NBLE_BUF_SIZE]; - u8_t attr_table_size; - - if (!attrs || !count) { - return -EINVAL; - } - BT_ASSERT(svc_count < BLE_GATTS_MAX_SERVICES); - - svc_db[svc_count].attrs = attrs; - svc_db[svc_count].attr_count = count; - svc_count++; - param.attr_base = attrs; - param.attr_count = count; - param.attr_size = sizeof(struct bt_gatt_attr); - - attr_table_size = 0; - - for (i = 0; i < count; i++) { - struct bt_gatt_attr *attr = &attrs[i]; - struct nble_gatts_attr *att; - int err; - - if (attr_table_size + sizeof(*att) > sizeof(attr_table)) { - return -ENOMEM; - } - - att = (void *)&attr_table[attr_table_size]; - att->perm = attr->perm; - - attr_table_size += sizeof(*att); - - /* Read attribute data */ - err = attr_read(attr, att->data, - sizeof(attr_table) - attr_table_size); - if (err < 0) { - BT_ERR("Failed to read attr: %d", err); - return err; - } - - att->data_size = err; - - /* Compute the new element size and align it on upper 4 bytes - * boundary. - */ - attr_table_size += (att->data_size + 3) & ~3; - - BT_DBG("table size = %u attr data_size = %u", attr_table_size, - att->data_size); - } - - nble_gatts_register_req(¶m, attr_table, attr_table_size); - return 0; -} - -void on_nble_gatts_register_rsp(const struct nble_gatts_register_rsp *rsp, - const struct nble_gatt_attr_handles *handles, - u8_t len) -{ - int i; - struct bt_gatt_attr *head_svc_attr; - - BT_DBG("status %u", rsp->status); - - if (rsp->status != 0) { - return; - } - - head_svc_attr = rsp->attr_base; - - for (i = 0; i < rsp->attr_count; i++, head_svc_attr++) { - head_svc_attr->handle = handles[i].handle; - } -#if defined(CONFIG_BLUETOOTH_DEBUG_GATT) - { - int idx; - - for (idx = 0; idx < rsp->attr_count; idx++) { - /* The following order of declaration is assumed for - * this to work (otherwise idx-2 will fail!): - * BT_GATT_CHARACTERISTIC -> ble core returns invalid - * handle. - * BT_GATT_DESCRIPTOR -> value handle of characteristic - * BT_GATT_CCC -> cccd handle is ignored as no storage - * but reference value is updated in CCC with value - * handle from descriptor. - */ - if (handles[idx].handle != 0) { - char uuid[37]; - - bt_uuid_to_str(rsp->attr_base[idx].uuid, - uuid, sizeof(uuid)); - BT_DBG("handle 0x%04x uuid %s", - handles[idx].handle, uuid); - } - } - } -#endif -} - -void bt_gatt_foreach_attr(u16_t start_handle, u16_t end_handle, - bt_gatt_attr_func_t func, void *user_data) -{ - int i; - - for (i = 0; i < svc_count; i++) { - u16_t attr_count = svc_db[i].attr_count; - const struct bt_gatt_attr *attr; - int j; - - for (j = 0; j < attr_count; j++) { - attr = &svc_db[i].attrs[j]; - - /* Check if attribute handle is within range */ - if (attr->handle < start_handle || - attr->handle > end_handle) { - continue; - } - - if (func(attr, user_data) == BT_GATT_ITER_STOP) { - break; - } - } - } -} - -struct bt_gatt_attr *bt_gatt_attr_next(const struct bt_gatt_attr *attr) -{ - u16_t i; - - for (i = 0; i < svc_count; i++) { - if (attr >= svc_db[i].attrs && - attr < svc_db[i].attrs + svc_db[i].attr_count) { - u8_t attr_i; - - attr_i = (attr - svc_db[i].attrs) + 1; - - /* Return next element of current service */ - if (attr_i < svc_db[i].attr_count) { - return (struct bt_gatt_attr *)&attr[1]; - } - - /* Return next service as next attribute */ - if (i < (svc_count - 1)) { - return (struct bt_gatt_attr *)svc_db[i+1].attrs; - } - } - } - - return NULL; -} - -ssize_t bt_gatt_attr_read(struct bt_conn *conn, const struct bt_gatt_attr *attr, - void *buf, u16_t buf_len, u16_t offset, - const void *value, u16_t value_len) -{ - u16_t len; - - BT_DBG("handle 0x%04x offset %u", attr->handle, offset); - - /* simply return the value length. used as max_value. */ - if (buf == NULL) { - return value_len; - } - - if (offset > value_len) { - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - } - - len = min(buf_len, value_len - offset); - - memcpy(buf, value + offset, len); - - return len; -} - -ssize_t bt_gatt_attr_read_service(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - void *buf, u16_t len, u16_t offset) -{ - struct bt_uuid *uuid = attr->user_data; - - if (uuid->type == BT_UUID_TYPE_16) { - u16_t uuid16 = sys_cpu_to_le16(BT_UUID_16(uuid)->val); - - return bt_gatt_attr_read(conn, attr, buf, len, offset, - &uuid16, 2); - } - - return bt_gatt_attr_read(conn, attr, buf, len, offset, - BT_UUID_128(uuid)->val, 16); -} - -ssize_t bt_gatt_attr_read_included(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - void *buf, u16_t len, u16_t offset) -{ - /* - * bt_gatt_attr_read uses memcpy to copy the address of the attr - * to the buf, so pointer to pointer is needed here. - */ - struct bt_gatt_attr **incl = (struct bt_gatt_attr **)&attr->user_data; - - /* nble gatt register case reading user_data. */ - if (!conn) { - return bt_gatt_attr_read(conn, attr, buf, len, offset, incl, - sizeof(*incl)); - } - - /* nble handles gattc reads internally */ - return -EINVAL; -} - -struct gatt_chrc { - u8_t properties; - u16_t value_handle; - union { - u16_t uuid16; - u8_t uuid[16]; - }; -} __packed; - -ssize_t bt_gatt_attr_read_chrc(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - u16_t len, u16_t offset) -{ - struct bt_gatt_chrc *chrc = attr->user_data; - struct gatt_chrc pdu; - u8_t value_len; - - pdu.properties = chrc->properties; - - /* Handle cannot be read at this point */ - pdu.value_handle = 0x0000; - - value_len = sizeof(pdu.properties) + sizeof(pdu.value_handle); - - if (chrc->uuid->type == BT_UUID_TYPE_16) { - pdu.uuid16 = sys_cpu_to_le16(BT_UUID_16(chrc->uuid)->val); - value_len += 2; - } else { - memcpy(pdu.uuid, BT_UUID_128(chrc->uuid)->val, 16); - value_len += 16; - } - - return bt_gatt_attr_read(conn, attr, buf, len, offset, &pdu, value_len); -} - -ssize_t bt_gatt_attr_read_ccc(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - u16_t len, u16_t offset) -{ - return BT_GATT_ERR(BT_ATT_ERR_NOT_SUPPORTED); -} - -static void gatt_ccc_changed(const struct bt_gatt_attr *attr, - struct _bt_gatt_ccc *ccc) -{ - int i; - u16_t value = 0x0000; - - for (i = 0; i < ccc->cfg_len; i++) { - if (ccc->cfg[i].value > value) { - value = ccc->cfg[i].value; - } - } - - BT_DBG("ccc %p value 0x%04x", ccc, value); - - if (value != ccc->value) { - ccc->value = value; - ccc->cfg_changed(attr, value); - } -} - -ssize_t bt_gatt_attr_write_ccc(struct bt_conn *conn, - const struct bt_gatt_attr *attr, const void *buf, - u16_t len, u16_t offset, u8_t flags) -{ - struct _bt_gatt_ccc *ccc = attr->user_data; - const u16_t *data = buf; - size_t i; - - if (offset > sizeof(*data)) { - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); - } - - if (offset + len > sizeof(*data)) { - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); - } - - for (i = 0; i < ccc->cfg_len; i++) { - /* Check for existing configuration */ - if (!bt_addr_le_cmp(&ccc->cfg[i].peer, &conn->dst)) { - break; - } - } - - if (i == ccc->cfg_len) { - for (i = 0; i < ccc->cfg_len; i++) { - /* Check for unused configuration */ - if (ccc->cfg[i].valid) { - continue; - } - - bt_addr_le_copy(&ccc->cfg[i].peer, &conn->dst); - /* TODO: Only set valid if bonded */ - ccc->cfg[i].valid = true; - break; - } - - if (i == ccc->cfg_len) { - BT_WARN("No space to store CCC cfg"); - return BT_GATT_ERR(BT_ATT_ERR_INSUFFICIENT_RESOURCES); - } - } - - ccc->cfg[i].value = sys_le16_to_cpu(*data); - - BT_DBG("handle 0x%04x value %u", attr->handle, ccc->cfg[i].value); - - /* Update cfg if don't match */ - if (ccc->cfg[i].value != ccc->value) { - gatt_ccc_changed(attr, ccc); - } - - return len; -} - -ssize_t bt_gatt_attr_read_cep(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - u16_t len, u16_t offset) -{ - struct bt_gatt_cep *value = attr->user_data; - u16_t props = sys_cpu_to_le16(value->properties); - - return bt_gatt_attr_read(conn, attr, buf, len, offset, &props, - sizeof(props)); -} - -ssize_t bt_gatt_attr_read_cud(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - u16_t len, u16_t offset) -{ - char *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - strlen(value)); -} - -ssize_t bt_gatt_attr_read_cpf(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, - u16_t len, u16_t offset) -{ - struct bt_gatt_cpf *value = attr->user_data; - - return bt_gatt_attr_read(conn, attr, buf, len, offset, value, - sizeof(*value)); -} - -static int notify(struct bt_conn *conn, const struct bt_gatt_attr *attr, - const void *data, size_t len) -{ - struct nble_gatts_notify_req notif; - - BT_DBG(""); - - k_sem_take(&conn->gatt_notif_sem, K_FOREVER); - - notif.params.conn_handle = conn->handle; - notif.params.attr = attr; - notif.params.offset = 0; - notif.cback = NULL; - - nble_gatts_notify_req(¬if, (u8_t *)data, len); - - return 0; -} - -void on_nble_gatts_notify_tx_evt(const struct nble_gatts_notify_tx_evt *evt) -{ - struct bt_conn *conn; - - if (evt->status) { - BT_ERR("status %d", evt->status); - /** - * Continue since we get non zero status shen we - * unsubscribe from notifications - */ - } - - BT_DBG("conn handle %u status %d attr %p", evt->conn_handle, - evt->status, evt->attr); - - conn = bt_conn_lookup_handle(evt->conn_handle); - if (!conn) { - BT_ERR("Unable to find conn, handle 0x%04x", evt->conn_handle); - return; - } - - k_sem_give(&conn->gatt_notif_sem); - - bt_conn_unref(conn); -} - -static int indicate(struct bt_conn *conn, - struct bt_gatt_indicate_params *params) -{ - struct nble_gatts_indicate_req ind; - - BT_DBG("conn %p", conn); - - if (!params) { - return -EINVAL; - } - - ind.params.conn_handle = conn->handle; - ind.params.attr = (void *)params->attr; - ind.params.offset = 0; - ind.cback = params->func; - - nble_gatts_indicate_req(&ind, (void *)params->data, params->len); - - return 0; -} - -struct notify_data { - u16_t type; - const struct bt_gatt_attr *attr; - const void *data; - u16_t len; - struct bt_gatt_indicate_params *params; -}; - -static u8_t notify_cb(const struct bt_gatt_attr *attr, void *user_data) -{ - struct notify_data *data = user_data; - struct _bt_gatt_ccc *ccc; - size_t i; - - if (bt_uuid_cmp(attr->uuid, BT_UUID_GATT_CCC)) { - return BT_GATT_ITER_CONTINUE; - } - - /* Check attribute user_data must be of type struct _bt_gatt_ccc */ - if (attr->write != bt_gatt_attr_write_ccc) { - return BT_GATT_ITER_CONTINUE; - } - - ccc = attr->user_data; - - /* Notify all peers configured */ - for (i = 0; i < ccc->cfg_len; i++) { - struct bt_conn *conn; - int err; - - if (!ccc->value || ccc->value != data->type) - continue; - - conn = bt_conn_lookup_addr_le(&ccc->cfg[i].peer); - if (!conn) { - continue; - } - - if (conn->state != BT_CONN_CONNECTED) { - bt_conn_unref(conn); - continue; - } - - if (data->type == BT_GATT_CCC_INDICATE) { - err = indicate(conn, data->params); - } else { - err = notify(conn, data->attr, data->data, data->len); - } - - bt_conn_unref(conn); - - if (err < 0) { - return BT_GATT_ITER_STOP; - } - } - - return BT_GATT_ITER_CONTINUE; -} - -int bt_gatt_notify(struct bt_conn *conn, const struct bt_gatt_attr *attr, - const void *data, u16_t len) -{ - struct notify_data nfy; - - BT_DBG("conn %p", conn); - - if (!attr) { - return -EINVAL; - } - - if (conn) { - return notify(conn, attr, data, len); - } - - nfy.attr = attr; - nfy.type = BT_GATT_CCC_NOTIFY; - nfy.data = data; - nfy.len = len; - - bt_gatt_foreach_attr(1, 0xffff, notify_cb, &nfy); - - return 0; -} - -int bt_gatt_indicate(struct bt_conn *conn, - struct bt_gatt_indicate_params *params) -{ - struct notify_data nfy; - - BT_DBG("conn %p", conn); - - if (!params || !params->attr || !params->attr->handle) { - return -EINVAL; - } - - if (conn) { - return indicate(conn, params); - } - - nfy.type = BT_GATT_CCC_INDICATE; - nfy.params = params; - - bt_gatt_foreach_attr(1, 0xffff, notify_cb, &nfy); - - return 0; -} - -/* Response to bt_gatt_indicate() */ -void on_nble_gatts_indicate_rsp(const struct nble_gatts_indicate_rsp *rsp) -{ - struct bt_conn *conn; - - if (rsp->status) { - BT_ERR("Send indication failed, status %d", rsp->status); - return; - } - - conn = bt_conn_lookup_handle(rsp->conn_handle); - if (!conn) { - BT_ERR("Unable to find conn, handle 0x%04x", rsp->conn_handle); - return; - } - - if (rsp->cback) { - rsp->cback(conn, rsp->attr, rsp->status); - } - - bt_conn_unref(conn); -} - -int bt_gatt_exchange_mtu(struct bt_conn *conn, - struct bt_gatt_exchange_params *params) -{ - return -ENOSYS; -} - -int bt_gatt_discover(struct bt_conn *conn, - struct bt_gatt_discover_params *params) -{ - struct nble_gattc_discover_req discover_params; - - if (!conn || !params || !params->func || !params->start_handle || - !params->end_handle || params->start_handle > params->end_handle) { - return -EINVAL; - } - - if (conn->state != BT_CONN_CONNECTED) { - return -ENOTCONN; - } - - if (conn->gatt_private) { - return -EBUSY; - } - - BT_DBG("conn %p start 0x%04x end 0x%04x uuid %s", conn, - params->start_handle, params->end_handle, - bt_uuid_str(params->uuid)); - - memset(&discover_params, 0, sizeof(discover_params)); - - switch (params->type) { - case BT_GATT_DISCOVER_PRIMARY: - case BT_GATT_DISCOVER_CHARACTERISTIC: - if (params->uuid) { - /* Always copy a full 128 bit UUID */ - memcpy(&discover_params.uuid, BT_UUID_128(params->uuid), - sizeof(discover_params.uuid)); - discover_params.flags = DISCOVER_FLAGS_UUID_PRESENT; - } - - break; - case BT_GATT_DISCOVER_INCLUDE: - case BT_GATT_DISCOVER_DESCRIPTOR: - break; - default: - BT_ERR("Unknown params type %u", params->type); - return -EINVAL; - } - - discover_params.conn_handle = conn->handle; - discover_params.type = params->type; - discover_params.handle_range.start_handle = params->start_handle; - discover_params.handle_range.end_handle = params->end_handle; - - conn->gatt_private = params; - - nble_gattc_discover_req(&discover_params); - - return 0; -} - -static u16_t parse_include(struct bt_conn *conn, - struct bt_gatt_discover_params *params, - const u8_t *data, u8_t len) -{ - u16_t end_handle = 0; - int i; - - for (i = 0; len > 0; i++) { - const struct nble_gattc_included *att = (void *)data; - struct bt_gatt_attr *attr = NULL; - struct bt_gatt_include gatt_include; - - gatt_include.start_handle = att->range.start_handle; - gatt_include.end_handle = att->range.end_handle; - end_handle = att->handle; - - BT_DBG("start 0x%04x end 0x%04x", att->range.start_handle, - att->range.end_handle); - - /* - * 4.5.1 If the service UUID is a 16-bit Bluetooth UUID - * it is also returned in the response. - */ - switch (att->uuid.uuid.type) { - case BT_UUID_TYPE_16: - gatt_include.uuid = &att->uuid.uuid; - break; - case BT_UUID_TYPE_128: - /* Data is not available at this point */ - break; - } - - attr = (&(struct bt_gatt_attr) { - .uuid = BT_UUID_GATT_INCLUDE, - .user_data = &gatt_include, }); - attr->handle = att->handle; - - data += sizeof(*att); - len -= sizeof(*att); - - if (params->func(conn, attr, params) == BT_GATT_ITER_STOP) { - return 0; - } - } - - return end_handle; -} - -static u16_t parse_service(struct bt_conn *conn, - struct bt_gatt_discover_params *params, - const u8_t *data, u8_t len) -{ - u16_t end_handle = 0; - int i; - - for (i = 0; len > 0; i++) { - const struct nble_gattc_primary *att = (void *)data; - struct bt_gatt_service gatt_service; - struct bt_gatt_attr *attr = NULL; - - gatt_service.end_handle = att->range.end_handle; - gatt_service.uuid = params->uuid; - end_handle = gatt_service.end_handle; - - attr = (&(struct bt_gatt_attr) - BT_GATT_PRIMARY_SERVICE(&gatt_service)); - attr->handle = att->handle; - - data += sizeof(*att); - len -= sizeof(*att); - - if (params->func(conn, attr, params) == BT_GATT_ITER_STOP) { - return 0; - } - } - - return end_handle; -} - -static u16_t parse_characteristic(struct bt_conn *conn, - struct bt_gatt_discover_params *params, - const u8_t *data, u8_t len) -{ - u16_t end_handle = 0; - int i; - - for (i = 0; len > 0; i++) { - const struct nble_gattc_characteristic *att = (void *)data; - struct bt_gatt_attr *attr = NULL; - - attr = (&(struct bt_gatt_attr) - BT_GATT_CHARACTERISTIC(&att->uuid.uuid, att->prop)); - attr->handle = att->handle; - end_handle = att->handle; - - data += sizeof(*att); - len -= sizeof(*att); - - /* Skip if UUID is set but doesn't match */ - if (params->uuid && - bt_uuid_cmp(&att->uuid.uuid, params->uuid)) { - continue; - } - - if (params->func(conn, attr, params) == BT_GATT_ITER_STOP) { - return 0; - } - } - - return end_handle; -} - -static u16_t parse_descriptor(struct bt_conn *conn, - struct bt_gatt_discover_params *params, - const u8_t *data, u8_t len) -{ - u16_t end_handle = 0; - int i; - - for (i = 0; len > 0; i++) { - const struct nble_gattc_descriptor *att = (void *)data; - struct bt_gatt_attr *attr = NULL; - - attr = (&(struct bt_gatt_attr) - BT_GATT_DESCRIPTOR(&att->uuid.uuid, 0, NULL, NULL, NULL)); - attr->handle = att->handle; - end_handle = att->handle; - - data += sizeof(*att); - len -= sizeof(*att); - - if (params->func(conn, attr, params) == BT_GATT_ITER_STOP) { - return 0; - } - } - - return end_handle; -} - -static void *gatt_get_private(struct bt_conn *conn) -{ - void *private; - - private = conn->gatt_private; - /* Reset so it can be reused */ - conn->gatt_private = NULL; - - return private; -} - -void on_nble_gattc_discover_rsp(const struct nble_gattc_discover_rsp *rsp, - const u8_t *data, u8_t data_len) -{ - u16_t end_handle = 0; - struct bt_gatt_discover_params *params; - struct bt_conn *conn; - int status; - - conn = bt_conn_lookup_handle(rsp->conn_handle); - if (!conn) { - BT_ERR("Unable to find conn, handle 0x%04x", rsp->conn_handle); - return; - } - - /* This pointer would keep new params set in the function below */ - params = gatt_get_private(conn); - - /* Status maybe error or indicate end of discovery */ - if (rsp->status) { - BT_DBG("status %d", rsp->status); - goto done; - } - - BT_DBG("conn %p conn handle 0x%04x status %d len %u", conn, - conn->handle, rsp->status, data_len); - - switch (rsp->type) { - case BT_GATT_DISCOVER_INCLUDE: - end_handle = parse_include(conn, params, data, data_len); - break; - case BT_GATT_DISCOVER_PRIMARY: - end_handle = parse_service(conn, params, data, data_len); - break; - case BT_GATT_DISCOVER_CHARACTERISTIC: - end_handle = parse_characteristic(conn, params, data, data_len); - break; - case BT_GATT_DISCOVER_DESCRIPTOR: - end_handle = parse_descriptor(conn, params, data, data_len); - break; - default: - BT_ERR("Wrong discover type %d", rsp->type); - bt_conn_unref(conn); - return; - } - - if (!end_handle) { - goto stop; - } - - /* Stop if end_handle is over the range */ - if (end_handle >= params->end_handle) { - BT_WARN("Handle goes over the range: 0x%04x >= 0x%04x", - end_handle, params->end_handle); - goto done; - } - - /* Continue discovery from last found handle */ - params->start_handle = end_handle; - if (params->start_handle < UINT16_MAX) { - params->start_handle++; - } - - status = bt_gatt_discover(conn, params); - if (status) { - BT_ERR("Unable to continue discovering, status %d", status); - goto done; - } - - bt_conn_unref(conn); - return; - -done: - /* End of discovery */ - params->func(conn, NULL, params); - -stop: - bt_conn_unref(conn); -} - -static int gatt_read_multiple(struct bt_conn *conn, - struct bt_gatt_read_params *params) -{ - struct nble_gattc_read_multi_req req; - - req.conn_handle = conn->handle; - req.user_data = params; - - nble_gattc_read_multi_req(&req, params->handles, - 2 * params->handle_count); - - return 0; -} - -int bt_gatt_read(struct bt_conn *conn, struct bt_gatt_read_params *params) -{ - struct nble_gattc_read_req req; - - if (!conn || !params || !params->handle_count || !params->func) { - return -EINVAL; - } - - if (conn->state != BT_CONN_CONNECTED) { - return -ENOTCONN; - } - - if (params->handle_count > 1) { - return gatt_read_multiple(conn, params); - } - - BT_DBG("conn %p params %p", conn, params); - - req.conn_handle = conn->handle; - req.handle = params->single.handle; - req.offset = params->single.offset; - req.user_data = params; - - nble_gattc_read_req(&req); - - return 0; -} - -void on_nble_gattc_read_rsp(const struct nble_gattc_read_rsp *rsp, - u8_t *data, u8_t len) -{ - struct bt_gatt_read_params *params = rsp->user_data; - struct bt_conn *conn; - - conn = bt_conn_lookup_handle(rsp->conn_handle); - if (!conn) { - BT_ERR("Unable to find conn, handle 0x%04x", rsp->conn_handle); - return; - } - - BT_DBG("status %d conn %p params %p", rsp->status, conn, params); - - if (rsp->status) { - params->func(conn, rsp->status, params, NULL, 0); - goto done; - } - - if (params->func(conn, 0, params, data, len) == BT_GATT_ITER_STOP) { - goto done; - } - - /* - * Core Spec 4.2, Vol. 3, Part G, 4.8.1 - * If the Characteristic Value is greater than (ATT_MTU - 1) octets - * in length, the Read Long Characteristic Value procedure may be used - * if the rest of the Characteristic Value is required. - * The data contain only (ATT_MTU - 1) octets. - */ - if (len < (BLE_GATT_MTU_SIZE - 1)) { - params->func(conn, 0, params, NULL, 0); - goto done; - } - - params->single.offset += len; - - /* Continue reading the attribute */ - if (bt_gatt_read(conn, params)) { - params->func(conn, BT_ATT_ERR_UNLIKELY, params, NULL, 0); - } - -done: - bt_conn_unref(conn); -} - -void on_nble_gattc_read_multi_rsp(const struct nble_gattc_read_rsp *rsp, - u8_t *data, u8_t len) -{ - struct bt_gatt_read_params *params = rsp->user_data; - struct bt_conn *conn; - - conn = bt_conn_lookup_handle(rsp->conn_handle); - if (!conn) { - BT_ERR("Unable to find conn, handle 0x%04x", rsp->conn_handle); - return; - } - - BT_DBG("conn %p params %p status 0x%02x", conn, params, rsp->status); - - if (rsp->status) { - params->func(conn, rsp->status, params, NULL, 0); - goto done; - } - - params->func(conn, 0, params, data, len); - - /* mark read as complete since read multiple is single response */ - params->func(conn, 0, params, NULL, 0); - -done: - bt_conn_unref(conn); -} - -int bt_gatt_write(struct bt_conn *conn, struct bt_gatt_write_params *params) -{ - struct nble_gattc_write_req req; - - if (!conn || !params || !params->handle || !params->func) { - return -EINVAL; - } - - if (conn->state != BT_CONN_CONNECTED) { - return -ENOTCONN; - } - - if (conn->gatt_private) { - return -EBUSY; - } - - BT_DBG("conn %p handle 0x%04x offset 0x%04x len %u data %p", - conn, params->handle, params->offset, params->length, - params->data); - - memset(&req, 0, sizeof(req)); - - req.conn_handle = conn->handle; - req.handle = params->handle; - req.offset = params->offset; - req.with_resp = 1; - - conn->gatt_private = params; - - nble_gattc_write_req(&req, params->data, params->length); - - return 0; -} - -static void gatt_write_ccc_rsp(struct bt_conn *conn, u8_t err, - struct bt_gatt_write_params *params) -{ - BT_DBG("conn %p err %u", conn, err); - - /* TODO: Remove failed subscription */ -} - -void on_nble_gattc_write_rsp(const struct nble_gattc_write_rsp *rsp) -{ - struct bt_conn *conn; - void *private; - bt_gatt_write_func_t func; - - conn = bt_conn_lookup_handle(rsp->conn_handle); - if (!conn) { - BT_ERR("Unable to find conn, handle 0x%04x", rsp->conn_handle); - return; - } - - BT_DBG("conn %p status %d", conn, rsp->status); - - private = gatt_get_private(conn); - if (private == gatt_write_ccc_rsp) { - func = gatt_write_ccc_rsp; - } else { - func = ((struct bt_gatt_write_params *)private)->func; - } - - if (func) { - func(conn, rsp->status, private); - } - - bt_conn_unref(conn); -} - -int bt_gatt_write_without_response(struct bt_conn *conn, u16_t handle, - const void *data, u16_t length, - bool sign) -{ - struct nble_gattc_write_req req; - - if (!conn || !handle) { - return -EINVAL; - } - - if (conn->state != BT_CONN_CONNECTED) { - return -ENOTCONN; - } - - if (conn->gatt_private) { - return -EBUSY; - } - - BT_DBG("conn %p handle 0x%04x len %u data %p sign %d", - conn, handle, length, data, sign); - - /* TODO: Handle signing */ - - memset(&req, 0, sizeof(req)); - - req.conn_handle = conn->handle; - req.handle = handle; - req.offset = 0; - req.with_resp = 0; - - nble_gattc_write_req(&req, data, length); - - return 0; -} - -static void gatt_subscription_add(struct bt_conn *conn, - struct bt_gatt_subscribe_params *params) -{ - bt_addr_le_copy(¶ms->_peer, &conn->dst); - - /* Prepend subscription */ - sys_slist_prepend(&subscriptions, ¶ms->node); -} - -static void gatt_subscription_remove(struct bt_conn *conn, sys_snode_t *prev, - struct bt_gatt_subscribe_params *params) -{ - /* Remove subscription from the list*/ - sys_slist_remove(&subscriptions, prev, ¶ms->node); - - params->notify(conn, params, NULL, 0); -} - -static void remove_subscriptions(struct bt_conn *conn) -{ - sys_snode_t *node, *tmp, *prev = NULL; - - /* Lookup existing subscriptions */ - SYS_SLIST_FOR_EACH_NODE_SAFE(&subscriptions, node, tmp) { - struct bt_gatt_subscribe_params *params; - - params = CONTAINER_OF(node, struct bt_gatt_subscribe_params, - node); - - if (bt_addr_le_cmp(¶ms->_peer, &conn->dst)) { - prev = node; - continue; - } - - if (params->flags & BT_GATT_SUBSCRIBE_FLAG_VOLATILE) { - /* Remove subscription */ - params->value = 0; - gatt_subscription_remove(conn, prev, params); - } - } -} - -static int gatt_write_ccc(struct bt_conn *conn, - struct bt_gatt_subscribe_params *params) -{ - struct nble_gattc_write_req req; - - memset(&req, 0, sizeof(req)); - - req.conn_handle = conn->handle; - req.handle = params->ccc_handle; - req.offset = 0; - req.with_resp = 1; - - conn->gatt_private = gatt_write_ccc_rsp; - - nble_gattc_write_req(&req, (void *)¶ms->value, - sizeof(params->value)); - - return 0; -} - -int bt_gatt_subscribe(struct bt_conn *conn, - struct bt_gatt_subscribe_params *params) -{ - sys_snode_t *node; - bool has_subscription = false; - - if (!conn || !params || !params->notify || - !params->value || !params->ccc_handle) { - return -EINVAL; - } - - if (conn->state != BT_CONN_CONNECTED) { - return -ENOTCONN; - } - - BT_DBG("conn %p value_handle 0x%04x ccc_handle 0x%04x value 0x%04x", - conn, params->value_handle, params->ccc_handle, params->value); - - /* Lookup existing subscriptions */ - SYS_SLIST_FOR_EACH_NODE(&subscriptions, node) { - struct bt_gatt_subscribe_params *tmp; - - tmp = CONTAINER_OF(node, struct bt_gatt_subscribe_params, - node); - - /* Fail if entry already exists */ - if (tmp == params) { - return -EALREADY; - } - - /* Check if another subscription exists */ - if (!bt_addr_le_cmp(&tmp->_peer, &conn->dst) && - tmp->value_handle == params->value_handle && - tmp->value >= params->value) { - has_subscription = true; - } - } - - /* Skip write if already subscribed */ - if (!has_subscription) { - int err; - - err = gatt_write_ccc(conn, params); - if (err) { - return err; - } - } - - /* - * Add subscription before write complete as some implementation were - * reported to send notification before reply to CCC write. - */ - gatt_subscription_add(conn, params); - - return 0; -} - -void on_nble_gattc_value_evt(const struct nble_gattc_value_evt *ev, - u8_t *data, u8_t length) -{ - sys_snode_t *node, *tmp, *prev = NULL; - struct bt_conn *conn; - - conn = bt_conn_lookup_handle(ev->conn_handle); - if (!conn) { - BT_ERR("Unable to find conn, handle 0x%04x", ev->conn_handle); - return; - } - - BT_DBG("conn %p value handle 0x%04x status %d data len %u", - conn, ev->handle, ev->status, length); - - SYS_SLIST_FOR_EACH_NODE_SAFE(&subscriptions, node, tmp) { - struct bt_gatt_subscribe_params *params; - - params = CONTAINER_OF(node, struct bt_gatt_subscribe_params, - node); - - if (ev->handle != params->value_handle) { - prev = node; - continue; - } - - if (params->notify(conn, params, data, length) == - BT_GATT_ITER_STOP) { - bt_gatt_unsubscribe(conn, params); - } else { - prev = node; - } - } - - bt_conn_unref(conn); -} - -int bt_gatt_unsubscribe(struct bt_conn *conn, - struct bt_gatt_subscribe_params *params) -{ - sys_snode_t *node, *next, *prev = NULL; - struct bt_gatt_subscribe_params *found = NULL; - bool has_subscription = false; - - if (!conn || !params) { - return -EINVAL; - } - - if (conn->state != BT_CONN_CONNECTED) { - return -ENOTCONN; - } - - BT_DBG("conn %p value_handle 0x%04x ccc_handle 0x%04x value 0x%04x", - conn, params->value_handle, params->ccc_handle, params->value); - - /* Lookup existing subscriptions */ - SYS_SLIST_FOR_EACH_NODE_SAFE(&subscriptions, node, next) { - struct bt_gatt_subscribe_params *tmp; - - tmp = CONTAINER_OF(node, struct bt_gatt_subscribe_params, - node); - - /* Remove subscription */ - if (params == tmp) { - found = params; - sys_slist_remove(&subscriptions, prev, node); - continue; - } else { - prev = node; - } - - /* Check if there still remains any other subscription */ - if (!bt_addr_le_cmp(&tmp->_peer, &conn->dst) && - tmp->value_handle == params->value_handle) { - has_subscription = true; - } - } - - if (!found) { - return -EINVAL; - } - - if (has_subscription) { - return 0; - } - - BT_DBG("Current subscription %p value_handle 0x%04x value 0x%04x", - found, found->value_handle, found->value); - - /* Remove subscription bit */ - params->value = found->value & ~params->value; - - return gatt_write_ccc(conn, params); -} - -void bt_gatt_cancel(struct bt_conn *conn, void *params) -{ - BT_DBG(""); -} - -static s32_t prep_write_evt(const struct nble_gatts_write_evt *ev, - const u8_t *data, u8_t len) -{ -#if CONFIG_BLUETOOTH_ATT_PREPARE_COUNT > 0 - const struct bt_gatt_attr *attr = ev->attr; - struct bt_conn *conn = bt_conn_lookup_handle(ev->conn_handle); - struct net_buf *buf; - ssize_t ret; - - BT_DBG("handle 0x%04x flag %d len %u", ev->attr->handle, ev->flag, len); - - if (!(attr->perm & BT_GATT_PERM_PREPARE_WRITE)) { - return BT_GATT_ERR(BT_ATT_ERR_WRITE_NOT_PERMITTED); - } - - /* Write attribute value to check if device is authorired */ - ret = attr->write(conn, attr, data, len, ev->offset, - BT_GATT_WRITE_FLAG_PREPARE); - if (ret != 0) { - return ret; - } - - buf = net_buf_alloc(&prep_pool, K_NO_WAIT); - if (!buf) { - BT_ERR("No more buffers for prepare write"); - return BT_GATT_ERR(BT_ATT_ERR_PREPARE_QUEUE_FULL); - } - - /* Copy data into the outstanding queue */ - memcpy(net_buf_user_data(buf), ev, sizeof(*ev)); - net_buf_add_mem(buf, data, len); - - k_fifo_put(&queue, buf); - - return 0; -#else - return BT_GATT_ERR(BT_ATT_ERR_NOT_SUPPORTED); -#endif -} - -static s32_t write_evt(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - u16_t offset, const u8_t *data, u8_t len) -{ - s32_t status; - - status = attr->write(conn, attr, data, len, offset, 0); - if (status < 0) { - return status; - } - - /* Return an error if not all data has been written */ - if (status != len) { - return BT_GATT_ERR(BT_ATT_ERR_UNLIKELY); - } - - return status; -} - -void on_nble_gatts_write_evt(const struct nble_gatts_write_evt *ev, - const u8_t *buf, u8_t buflen) -{ - const struct bt_gatt_attr *attr = ev->attr; - struct bt_conn *conn = bt_conn_lookup_handle(ev->conn_handle); - struct nble_gatts_write_reply_req reply_data; - - BT_DBG("attr handle 0x%04x flag %d len %u", attr->handle, ev->flag, - buflen); - - /* Check for write support and flush support in case of prepare */ - if (!attr->write) { - reply_data.status = BT_GATT_ERR(BT_ATT_ERR_WRITE_NOT_PERMITTED); - - goto reply; - } - - if (ev->flag & NBLE_GATT_WR_FLAG_PREP) { - reply_data.status = prep_write_evt(ev, buf, buflen); - goto reply; - } - - reply_data.status = write_evt(conn, attr, ev->offset, buf, buflen); - -reply: - if (ev->flag & NBLE_GATT_WR_FLAG_REPLY) { - reply_data.conn_handle = ev->conn_handle; - reply_data.offset = ev->offset; - - nble_gatts_write_reply_req(&reply_data, buf, buflen); - } - - if (conn) { - bt_conn_unref(conn); - } -} - -void on_nble_gatts_write_exec_evt(const struct nble_gatts_write_exec_evt *evt) -{ - struct bt_conn *conn; - struct net_buf *buf; - struct nble_gatts_write_reply_req rsp = { - .conn_handle = evt->conn_handle, - .status = 0, - }; - - BT_DBG("handle 0x%04x flag %u", evt->conn_handle, evt->flag); - - conn = bt_conn_lookup_handle(evt->conn_handle); - if (!conn) { - BT_ERR("Unable to find conn, handle 0x%04x", evt->conn_handle); - return; - } - - while ((buf = k_fifo_get(&queue, K_NO_WAIT))) { - struct nble_gatts_write_evt *ev = net_buf_user_data(buf); - const struct bt_gatt_attr *attr = ev->attr; - - /* Skip buffer for other connections */ - if (ev->conn_handle != evt->conn_handle) { - k_fifo_put(&queue, buf); - continue; - } - - /* - * Dispatch the callback in case of success (status >= 0). - * Ignore in case of error (status < 0). - */ - if (rsp.status >= 0 && evt->flag == 1) { - rsp.status = write_evt(conn, attr, ev->offset, - buf->data, buf->len); - } - - net_buf_unref(buf); - } - - nble_gatts_write_reply_req(&rsp, NULL, 0); - - bt_conn_unref(conn); -} - -void on_nble_gatts_read_evt(const struct nble_gatts_read_evt *ev) -{ - struct nble_gatts_read_reply_req reply_data; - const struct bt_gatt_attr *attr; - /* TODO: Replace the following with net_buf */ - u8_t data[BLE_GATT_MTU_SIZE] = { 0 }; - int len; - - attr = ev->attr; - - BT_DBG("attr %p offset %u", attr, ev->offset); - - memset(&reply_data, 0, sizeof(reply_data)); - - if (attr->read) { - struct bt_conn *conn = bt_conn_lookup_handle(ev->conn_handle); - - len = attr->read(conn, attr, data, sizeof(data), ev->offset); - - if (conn) { - bt_conn_unref(conn); - } - } else { - len = BT_GATT_ERR(BT_ATT_ERR_NOT_SUPPORTED); - } - - if (len >= 0) { - reply_data.status = 0; - reply_data.offset = ev->offset; - } else { - reply_data.status = len; - len = 0; - } - - reply_data.conn_handle = ev->conn_handle; - - nble_gatts_read_reply_req(&reply_data, data, len); -} - -void bt_gatt_init(void) -{ - BT_DBG(""); -} - -void bt_gatt_connected(struct bt_conn *conn) -{ - /* Allow to send first notification */ - k_sem_init(&conn->gatt_notif_sem, 1, UINT_MAX); -} - -void bt_gatt_disconnected(struct bt_conn *conn) -{ - struct net_buf *buf; - - BT_DBG("conn %p", conn); - -#if CONFIG_BLUETOOTH_ATT_PREPARE_COUNT > 0 - /* Discard queued buffers */ - while ((buf = k_fifo_get(&queue, K_NO_WAIT))) { - net_buf_unref(buf); - } -#endif - - conn->gatt_private = NULL; - - /* TODO: If bonded don't remove subscriptions */ - remove_subscriptions(conn); -} diff --git a/drivers/bluetooth/nble/gatt_internal.h b/drivers/bluetooth/nble/gatt_internal.h deleted file mode 100644 index 6a1280307f..0000000000 --- a/drivers/bluetooth/nble/gatt_internal.h +++ /dev/null @@ -1,286 +0,0 @@ -/** @file - * @brief Internal API for Generic Attribute Profile handling. - */ - -/* - * Copyright (c) 2016 Intel Corporation - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/* Max number of service supported, if changed update BLE core needs to be - * updated too! - */ -#define BLE_GATTS_MAX_SERVICES 10 - -void bt_gatt_init(void); - -/* - * GATT Attribute stream structure. - * - * This structure is a "compressed" copy of bt_gatt_attr. - * UUID pointer and user_data pointer are used as offset into buffer itself. - * The offset is from the beginning of the buffer. therefore a value of 0 - * means that UUID or user_data is not present. - */ -struct nble_gatts_attr { - /* Attribute permissions */ - u16_t perm; - /* Attribute variable data size */ - u16_t data_size; - /* Attribute variable data: always starts with the UUID and data follows */ - u8_t data[]; -}; - -struct nble_gatts_register_req { - /* Base address of the attribute table in the Quark mem space */ - struct bt_gatt_attr *attr_base; - /* Number of of attributes in this service */ - u8_t attr_count; - /* Size of struct bt_gatt_attr */ - u8_t attr_size; -}; - -void nble_gatts_register_req(const struct nble_gatts_register_req *req, - u8_t *data, u16_t len); - -struct nble_gatts_register_rsp { - int status; - struct bt_gatt_attr *attr_base; - /* Number of attributes successfully added */ - u8_t attr_count; -}; - -struct nble_gatt_attr_handles { - u16_t handle; -}; - -void on_nble_gatts_register_rsp(const struct nble_gatts_register_rsp *rsp, - const struct nble_gatt_attr_handles *attrs, - u8_t len); - -enum nble_gatt_wr_flag { - NBLE_GATT_WR_FLAG_REPLY = 1, - NBLE_GATT_WR_FLAG_PREP = 2, -}; - -struct nble_gatts_write_evt { - struct bt_gatt_attr *attr; - u16_t conn_handle; - u16_t offset; - /* see nble_gatt_wr_flag */ - u8_t flag; -}; - -void on_nble_gatts_write_evt(const struct nble_gatts_write_evt *evt, - const u8_t *data, u8_t len); - -struct nble_gatts_write_reply_req { - u16_t conn_handle; - u16_t offset; - s32_t status; -}; - -void nble_gatts_write_reply_req(const struct nble_gatts_write_reply_req *req, - const u8_t *data, u8_t len); - -struct nble_gatts_write_exec_evt { - u16_t conn_handle; - u8_t flag; -}; - -void on_nble_gatts_write_exec_evt(const struct nble_gatts_write_exec_evt *evt); - -struct nble_gatts_read_evt { - struct bt_gatt_attr *attr; - u16_t conn_handle; - u16_t offset; -}; - -void on_nble_gatts_read_evt(const struct nble_gatts_read_evt *evt); - -struct nble_gatts_read_reply_req { - u16_t conn_handle; - u16_t offset; - s32_t status; -}; - -void nble_gatts_read_reply_req(const struct nble_gatts_read_reply_req *req, - u8_t *data, u16_t len); - -struct nble_gatts_value_change_param { - const struct bt_gatt_attr *attr; - u16_t conn_handle; - u16_t offset; -}; - -struct nble_gatts_notify_req { - /* Function to be invoked when buffer is freed */ - bt_gatt_notify_func_t cback; - struct nble_gatts_value_change_param params; -}; - -void nble_gatts_notify_req(const struct nble_gatts_notify_req *req, - const u8_t *data, u16_t len); - -struct nble_gatts_notify_tx_evt { - bt_gatt_notify_func_t cback; - int status; - u16_t conn_handle; - struct bt_gatt_attr *attr; -}; - -void on_nble_gatts_notify_tx_evt(const struct nble_gatts_notify_tx_evt *evt); - -struct nble_gatts_indicate_req { - /* Function to be invoked when buffer is freed */ - bt_gatt_indicate_func_t cback; - struct nble_gatts_value_change_param params; -}; - -void nble_gatts_indicate_req(const struct nble_gatts_indicate_req *req, - const u8_t *data, u8_t len); - -struct nble_gatts_indicate_rsp { - bt_gatt_indicate_func_t cback; - struct bt_gatt_attr *attr; - int status; - u16_t conn_handle; -}; - -void on_nble_gatts_indicate_rsp(const struct nble_gatts_indicate_rsp *rsp); - -#define DISCOVER_FLAGS_UUID_PRESENT 1 - -struct nble_gatt_handle_range { - u16_t start_handle; - u16_t end_handle; -}; - -struct nble_gattc_discover_req { - void *user_data; - struct bt_uuid_128 uuid; - struct nble_gatt_handle_range handle_range; - u16_t conn_handle; - u8_t type; - u8_t flags; -}; - -void nble_gattc_discover_req(const struct nble_gattc_discover_req *req); - -struct nble_gattc_primary { - u16_t handle; - struct nble_gatt_handle_range range; - struct bt_uuid_128 uuid; -}; - -struct nble_gattc_included { - u16_t handle; - struct nble_gatt_handle_range range; - struct bt_uuid_128 uuid; -}; - -struct nble_gattc_characteristic { - u16_t handle; - u8_t prop; - u16_t value_handle; - struct bt_uuid_128 uuid; -}; - -struct nble_gattc_descriptor { - u16_t handle; - struct bt_uuid_128 uuid; -}; - -struct nble_gattc_discover_rsp { - s32_t status; - void *user_data; - u16_t conn_handle; - u8_t type; -}; - -void on_nble_gattc_discover_rsp(const struct nble_gattc_discover_rsp *rsp, - const u8_t *data, u8_t len); - -struct nble_gattc_read_req { - void *user_data; - u16_t conn_handle; - u16_t handle; - u16_t offset; -}; - -void nble_gattc_read_req(const struct nble_gattc_read_req *req); - -struct nble_gattc_read_rsp { - int status; - void *user_data; - u16_t conn_handle; - u16_t handle; - u16_t offset; -}; - -void on_nble_gattc_read_rsp(const struct nble_gattc_read_rsp *rsp, - u8_t *data, u8_t len); - -struct nble_gattc_read_multi_req { - void *user_data; - u16_t conn_handle; -}; - -void nble_gattc_read_multi_req(const struct nble_gattc_read_multi_req *req, - const u16_t *handles, u16_t len); - -void on_nble_gattc_read_multi_rsp(const struct nble_gattc_read_rsp *rsp, - u8_t *data, u8_t len); - -struct nble_gattc_write_param; - -typedef void (*nble_att_func_t)(struct bt_conn *conn, u8_t err, - const struct nble_gattc_write_param *par); - -struct nble_gattc_write_param { - /* Function invoked upon write response */ - nble_att_func_t func; - /* User specific data */ - void *user_data[2]; -}; - -struct nble_gattc_write_req { - u16_t conn_handle; - u16_t handle; - u16_t offset; - /* different than 0 if response required */ - u8_t with_resp; - struct nble_gattc_write_param wr_params; -}; - -void nble_gattc_write_req(const struct nble_gattc_write_req *req, - const u8_t *data, u16_t len); - -struct nble_gattc_write_rsp { - int status; - u16_t conn_handle; - u16_t handle; - struct nble_gattc_write_param wr_params; -}; - -void on_nble_gattc_write_rsp(const struct nble_gattc_write_rsp *rsp); - -void bt_gatt_connected(struct bt_conn *conn); -void bt_gatt_disconnected(struct bt_conn *conn); - -enum NBLE_GATTC_EVT { - NBLE_GATTC_EVT_NOTIFICATION, - NBLE_GATTC_EVT_INDICATION, -}; - -struct nble_gattc_value_evt { - int status; - u16_t conn_handle; - u16_t handle; - /* see NBLE_GATTC_VALUE_EVT */ - u8_t type; -}; - -void on_nble_gattc_value_evt(const struct nble_gattc_value_evt *evt, - u8_t *data, u8_t len); diff --git a/drivers/bluetooth/nble/rpc.h b/drivers/bluetooth/nble/rpc.h deleted file mode 100644 index 99eba657c0..0000000000 --- a/drivers/bluetooth/nble/rpc.h +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Copyright (c) 2016 Intel Corporation - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include - -/** Identifiers of the signature supported by the RPC */ -enum { - SIG_TYPE_NONE = 1, - SIG_TYPE_S, - SIG_TYPE_P, - SIG_TYPE_S_B, - SIG_TYPE_B_B_P, - SIG_TYPE_S_P, - SIG_TYPE_S_B_P, - SIG_TYPE_S_B_B_P, - SIG_TYPE_CONTROL = 0xFF -}; - -/** - * RPC memory allocation function, must be implemented by the user of the RPC. - * - * This function is called by the RPC mechanism to allocate a buffer for - * transmission of a serialized function. The function should not fail. - * - * @param length Length of the buffer to allocate. - * - * @return Pointer to the allocated buffer, the allocation shall not fail, - * error must be handled internally - */ -struct net_buf *rpc_alloc_cb(u16_t length); - -/** - * RPC transmission function, must be implemented by the user of the RPC. - * - * @param buf Pointer to the buffer allocated for transmission - * by @ref rpc_alloc_cb - */ -void rpc_transmit_cb(struct net_buf *buf); - -/** - * RPC initialization function that notifies the peer with an initialization - * packet containing the information to check the compatibility of the - * frameworks. - * - * @param version Local version to send to the peer. - */ -void rpc_init(u32_t version); - -/** - * RPC initialization packet reception function, can optionally be implemented - * by the user of the RPC. If this function is not implemented, it will default - * to an empty function. - * - * This function is called by the RPC mechanism when an initialization packet is - * received from the connected peer. - * - * @param version Peer advertised version. - * @param compatible True if the peer runs a compatible RPC framework. - */ -void rpc_init_cb(u32_t version, bool compatible); - -/** RPC serialize hash number generation. - * - * @return The unique identifier of the RPC deserialization. - */ -u32_t rpc_serialize_hash(void); - -/** - * RPC serialization function to serialize a function that does not require any - * parameter. - * - * @param fn_index Index of the function - */ -void rpc_serialize_none(u8_t fn_index); - -/** - * RPC serialization function to serialize a function that expects a structure - * as parameter. - * - * @param fn_index Index of the function - * @param struct_data Pointer to the structure to serialize - * @param struct_length Length of the structure to serialize - */ -void rpc_serialize_s(u8_t fn_index, const void *struct_data, - u8_t struct_length); - -/** - * RPC serialization function to serialize a function that expects a structure - * and a pointer as parameters. - * - * @param fn_index Index of the function - * @param struct_data Pointer to the structure to serialize - * @param struct_length Length of the structure to serialize - * @param p_priv Pointer to serialize - */ -void rpc_serialize_s_p(u8_t fn_index, const void *struct_data, - u8_t struct_length, void *p_priv); - -/** - * RPC serialization function to serialize a function that expects a pointer as - * parameter. - * - * @param fn_index Index of the function - * @param p_priv Pointer to serialize - */ -void rpc_serialize_p(u8_t fn_index, void *p_priv); - -/** - * RPC serialization function to serialize a function that expects a structure - * and a buffer as parameters. - * - * @param fn_index Index of the function - * @param struct_data Pointer to the structure to serialize - * @param struct_length Length of the structure to serialize - * @param vbuf Pointer to the buffer to serialize - * @param vbuf_length Length of the buffer to serialize - */ -void rpc_serialize_s_b(u8_t fn_index, const void *struct_data, - u8_t struct_length, const void *vbuf, - u16_t vbuf_length); - -/** - * RPC serialization function to serialize a function that expects a structure - * and a buffer as parameters. - * - * @param fn_index Index of the function - * @param vbuf1 Pointer to the buffer1 to serialize - * @param vbuf1_length Length of the buffer1 to serialize - * @param vbuf2 Pointer to the buffer2 to serialize - * @param vbuf2_length Length of the buffer2 to serialize - * @param p_priv Pointer to serialize - */ -void rpc_serialize_b_b_p(u8_t fn_index, const void *vbuf1, - u16_t vbuf1_length, const void *vbuf2, - u16_t vbuf2_length, void *p_priv); - -/** - * RPC serialization function to serialize a function that expects a structure - * and a buffer as parameters. - * - * @param fn_index Index of the function - * @param struct_data Pointer to the structure to serialize - * @param struct_length Length of the structure to serialize - * @param vbuf Pointer to the buffer to serialize - * @param vbuf_length Length of the buffer to serialize - * @param p_priv Pointer to serialize - */ -void rpc_serialize_s_b_p(u8_t fn_index, const void *struct_data, - u8_t struct_length, const void *vbuf, - u16_t vbuf_length, void *p_priv); - -/** - * RPC serialization function to serialize a function that expects a structure - * and a buffer as parameters. - * - * @param fn_index Index of the function - * @param struct_data Pointer to the structure to serialize - * @param struct_length Length of the structure to serialize - * @param vbuf1 Pointer to the buffer1 to serialize - * @param vbuf1_length Length of the buffer1 to serialize - * @param vbuf2 Pointer to the buffer2 to serialize - * @param vbuf2_length2 Length of the buffer2 to serialize - * @param p_priv Pointer to serialize - */ -void rpc_serialize_s_b_b_p(u8_t fn_index, const void *struct_data, - u8_t struct_length, const void *vbuf1, - u16_t vbuf1_length, const void *vbuf2, - u16_t vbuf2_length, void *p_priv); - -/** - * RPC deserialization function, shall be invoked when a buffer is received - * over the transport interface. - * - * @param buf Pointer to the received buffer - */ -void rpc_deserialize(struct net_buf *buf); - -/** RPC deserialize hash number generation. - * - * @return The unique identifier of the RPC deserialization. - */ -u32_t rpc_deserialize_hash(void); - diff --git a/drivers/bluetooth/nble/rpc_deserialize.c b/drivers/bluetooth/nble/rpc_deserialize.c deleted file mode 100644 index 262be496c0..0000000000 --- a/drivers/bluetooth/nble/rpc_deserialize.c +++ /dev/null @@ -1,639 +0,0 @@ -/* - * Copyright (c) 2016 Intel Corporation - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include - -#include -/* for bt_security_t */ -#include - -#ifdef CONFIG_PRINTK -#include -#define PRINTK(...) printk(__VA_ARGS__) -#else -#define PRINTK(...) -#endif /* CONFIG_PRINTK */ - -#define BT_DBG_ENABLED IS_ENABLED(CONFIG_NBLE_DEBUG_RPC) -#include "common/log.h" - -#include "rpc.h" -#include "gap_internal.h" -#include "gatt_internal.h" - -#include "rpc_functions_to_quark.h" - -/* Build the list of prototypes and check that list are made only of matching - * signatures - */ -#define FN_SIG_NONE(__fn) void __fn(void); -LIST_FN_SIG_NONE -#undef FN_SIG_NONE - -#define FN_SIG_S(__fn, __s) void __fn(__s p_s); -LIST_FN_SIG_S -#undef FN_SIG_S - -#define FN_SIG_P(__fn, __type) void __fn(__type priv); -LIST_FN_SIG_P -#undef FN_SIG_P - -#define FN_SIG_S_B(__fn, __s, __type, __length) \ - void __fn(__s p_s, __type buf, __length length); -LIST_FN_SIG_S_B -#undef FN_SIG_S_B - -#define FN_SIG_B_B_P(__fn, __type1, __length1, __type2, __length2, \ - __type3) \ - void __fn(__type1 p_buf1, __length1 length1, __type2 p_buf2, \ - __length2 length2, __type3 priv); -LIST_FN_SIG_B_B_P -#undef FN_SIG_B_B_P - -#define FN_SIG_S_P(__fn, __s, __type) void __fn(__s p_s, __type priv); -LIST_FN_SIG_S_P -#undef FN_SIG_S_P - -#define FN_SIG_S_B_P(__fn, __s, __type, __length, __type_ptr) \ - void __fn(__s p_s, __type buf, __length length, __type_ptr priv); -LIST_FN_SIG_S_B_P -#undef FN_SIG_S_B_P - -#define FN_SIG_S_B_B_P(__fn, __s, __type1, __length1, __type2, \ - __length2, __type_ptr) \ - void __fn(__s p_s, __type1 p_buf1, __length1 length1, \ - __type2 p_buf2, __length2 length2, __type_ptr priv); -LIST_FN_SIG_S_B_B_P -#undef FN_SIG_S_B_B_P - -/* 1 - define the size check arrays */ -#define FN_SIG_NONE(__fn) - -#define FN_SIG_S(__fn, __s) sizeof(*((__s)0)), - -#define FN_SIG_P(__fn, __type) - -#define FN_SIG_S_B(__fn, __s, __type, __length) sizeof(*((__s)0)), - -#define FN_SIG_B_B_P(__fn, __type1, __length1, __type2, __length2, \ - __type3) sizeof(*((__s)0)), - -#define FN_SIG_S_P(__fn, __s, __type) sizeof(*((__s)0)), - -#define FN_SIG_S_B_P(__fn, __s, __type, __length, __type_ptr) \ - sizeof(*((__s)0)), - -#define FN_SIG_S_B_B_P(__fn, __s, __type1, __length1, __type2, \ - __length2, __type3) sizeof(*((__s)0)), - -static u8_t m_size_s[] = { LIST_FN_SIG_S }; -static u8_t m_size_s_b[] = { LIST_FN_SIG_S_B }; -static u8_t m_size_s_p[] = { LIST_FN_SIG_S_P }; -static u8_t m_size_s_b_p[] = { LIST_FN_SIG_S_B_P }; -static u8_t m_size_s_b_b_p[] = { LIST_FN_SIG_S_B_B_P }; - -#undef FN_SIG_NONE -#undef FN_SIG_S -#undef FN_SIG_P -#undef FN_SIG_S_B -#undef FN_SIG_B_B_P -#undef FN_SIG_S_P -#undef FN_SIG_S_B_P -#undef FN_SIG_S_B_B_P - -/* 2- build the enumerations list */ -#define FN_SIG_NONE(__fn) fn_index_##__fn, -#define FN_SIG_S(__fn, __s) FN_SIG_NONE(__fn) -#define FN_SIG_P(__fn, __type) FN_SIG_NONE(__fn) -#define FN_SIG_S_B(__fn, __s, __type, __length) FN_SIG_NONE(__fn) -#define FN_SIG_B_B_P(__fn, __type1, __length1, __type2, __length2, \ - __type3) FN_SIG_NONE(__fn) -#define FN_SIG_S_P(__fn, __s, __type) FN_SIG_NONE(__fn) -#define FN_SIG_S_B_P(__fn, __s, __type, __length, __type_ptr) \ - FN_SIG_NONE(__fn) -#define FN_SIG_S_B_B_P(__fn, __s, __type1, __length1, __type2, \ - __length2, __type3) FN_SIG_NONE(__fn) - -/* Build the list of function indexes in the deserialization array */ -enum { LIST_FN_SIG_NONE fn_none_index_max }; -enum { LIST_FN_SIG_S fn_s_index_max }; -enum { LIST_FN_SIG_P fn_p_index_max }; -enum { LIST_FN_SIG_S_B fn_s_b_index_max }; -enum { LIST_FN_SIG_B_B_P fn_b_b_p_index_max }; -enum { LIST_FN_SIG_S_P fn_s_p_index_max }; -enum { LIST_FN_SIG_S_B_P fn_s_b_p_index_max }; -enum { LIST_FN_SIG_S_B_B_P fn_s_b_b_p_index_max }; - -#undef FN_SIG_NONE -#undef FN_SIG_S -#undef FN_SIG_P -#undef FN_SIG_S_B -#undef FN_SIG_B_B_P -#undef FN_SIG_S_P -#undef FN_SIG_S_B_P -#undef FN_SIG_S_B_B_P - -/* 3- build the array */ -#define FN_SIG_NONE(__fn) [fn_index_##__fn] = \ - (void *)__fn, -#define FN_SIG_S(__fn, __s) FN_SIG_NONE(__fn) -#define FN_SIG_P(__fn, __type) FN_SIG_NONE(__fn) -#define FN_SIG_S_B(__fn, __s, __type, __length) \ - FN_SIG_NONE(__fn) -#define FN_SIG_B_B_P(__fn, __type1, __length1, __type2, __length2, \ - __type3) FN_SIG_NONE(__fn) -#define FN_SIG_S_P(__fn, __s, __type) FN_SIG_NONE(__fn) -#define FN_SIG_S_B_P(__fn, __s, __type, __length, __type_ptr) \ - FN_SIG_NONE(__fn) -#define FN_SIG_S_B_B_P(__fn, __s, __type1, __length1, __type2, \ - __length2, __type3) FN_SIG_NONE(__fn) - -static void (*m_fct_none[])(void) = { LIST_FN_SIG_NONE }; -static void (*m_fct_s[])(void *structure) = { LIST_FN_SIG_S }; -static void (*m_fct_p[])(void *pointer) = { LIST_FN_SIG_P }; -static void (*m_fct_s_b[])(void *structure, void *buffer, - u8_t length) = { LIST_FN_SIG_S_B }; -static void (*m_fct_b_b_p[])(void *buffer1, u8_t length1, - void *buffer2, u8_t length2, - void *pointer) = { LIST_FN_SIG_B_B_P }; -static void (*m_fct_s_p[])(void *structure, - void *pointer) = { LIST_FN_SIG_S_P }; -static void (*m_fct_s_b_p[])(void *structure, void *buffer, u8_t length, - void *pointer) = { LIST_FN_SIG_S_B_P }; -static void (*m_fct_s_b_b_p[])(void *structure, void *buffer1, u8_t length1, - void *buffer2, u8_t length2, - void *pointer) = { LIST_FN_SIG_S_B_B_P }; - -/* Build debug table to help development with this "robust" macro stuff */ - -#if defined(CONFIG_NBLE_DEBUG_RPC) - -#undef FN_SIG_NONE -#undef FN_SIG_S -#undef FN_SIG_P -#undef FN_SIG_S_B -#undef FN_SIG_B_B_P -#undef FN_SIG_S_P -#undef FN_SIG_S_B_P -#undef FN_SIG_S_B_B_P - -#define FN_SIG_NONE(__fn) #__fn, -#define FN_SIG_S(__fn, __s) FN_SIG_NONE(__fn) -#define FN_SIG_P(__fn, __type) FN_SIG_NONE(__fn) -#define FN_SIG_S_B(__fn, __s, __type, __length) \ - FN_SIG_NONE(__fn) -#define FN_SIG_B_B_P(__fn, __type1, __length1, __type2, __length2, \ - __type3) FN_SIG_NONE(__fn) -#define FN_SIG_S_P(__fn, __s, __type) FN_SIG_NONE(__fn) -#define FN_SIG_S_B_P(__fn, __s, __type, __length, __type_ptr) \ - FN_SIG_NONE(__fn) -#define FN_SIG_S_B_B_P(__fn, __s, __type1, __length1, __type2, \ - __length2, __type3) FN_SIG_NONE(__fn) - -static char *debug_func_none[] = { LIST_FN_SIG_NONE }; -static char *debug_func_s[] = { LIST_FN_SIG_S }; -static char *debug_func_p[] = { LIST_FN_SIG_P }; -static char *debug_func_s_b[] = { LIST_FN_SIG_S_B }; -static char *debug_func_b_b_p[] = { LIST_FN_SIG_B_B_P }; -static char *debug_func_s_p[] = { LIST_FN_SIG_S_P }; -static char *debug_func_s_b_p[] = { LIST_FN_SIG_S_B_P }; -static char *debug_func_s_b_b_p[] = { LIST_FN_SIG_S_B_B_P}; - -#define DBG_FUNC(name) BT_DBG("%s", name) -#else -#define DBG_FUNC(name) -#endif - -#undef FN_SIG_NONE -#undef FN_SIG_S -#undef FN_SIG_P -#undef FN_SIG_S_B -#undef FN_SIG_B_B_P -#undef FN_SIG_S_P -#undef FN_SIG_S_B_P -#undef FN_SIG_S_B_B_P - -#define DJB2_HASH(__h, __v) ((((__h) << 5) + (__h)) + (__v)) - -#define FN_SIG_NONE(__fn) \ - hash = DJB2_HASH(hash, 1); - -#define FN_SIG_S(__fn, __s) \ - do { \ - hash = DJB2_HASH(hash, 2); \ - hash = DJB2_HASH(hash, sizeof(*((__s)0))); \ - } while (0); - -#define FN_SIG_P(__fn, __type) \ - hash = DJB2_HASH(hash, 3); - -#define FN_SIG_S_B(__fn, __s, __type, __length) \ - do { \ - hash = DJB2_HASH(hash, 4); \ - hash = DJB2_HASH(hash, sizeof(*((__s)0))); \ - } while (0); - -#define FN_SIG_B_B_P(__fn, __type1, __length1, __type2, __length2, \ - __type3) \ - do { \ - hash = DJB2_HASH(hash, 5); \ - hash = DJB2_HASH(hash, sizeof(*((__s)0))); \ - } while (0); - -#define FN_SIG_S_P(__fn, __s, __type) \ - do { \ - hash = DJB2_HASH(hash, 6); \ - hash = DJB2_HASH(hash, sizeof(*((__s)0))); \ - } while (0); - -#define FN_SIG_S_B_P(__fn, __s, __type, __length, __type_ptr) \ - do { \ - hash = DJB2_HASH(hash, 7); \ - hash = DJB2_HASH(hash, sizeof(*((__s)0))); \ - } while (0); - -#define FN_SIG_S_B_B_P(__fn, __s, __type1, __length1, __type2, \ - __length2, __type3) \ - do { \ - hash = DJB2_HASH(hash, 8); \ - hash = DJB2_HASH(hash, sizeof(*((__s)0))); \ - } while (0); - -u32_t rpc_deserialize_hash(void) -{ - u32_t hash = 5381; - - LIST_FN_SIG_NONE; - LIST_FN_SIG_S; - LIST_FN_SIG_P; - LIST_FN_SIG_S_B; - LIST_FN_SIG_B_B_P; - LIST_FN_SIG_S_P; - LIST_FN_SIG_S_B_P; - LIST_FN_SIG_S_B_B_P; - - return hash; -} - -static void panic(int err) -{ - PRINTK("panic: errcode %d", err); - - while (true) { - } -} - -static void deserialize_struct(struct net_buf *buf, const u8_t **struct_ptr, - u8_t *struct_length) -{ - *struct_length = net_buf_pull_u8(buf); - *struct_ptr = buf->data; - net_buf_pull(buf, *struct_length); -} - -static void deserialize_buf(struct net_buf *buf, const u8_t **buf_ptr, - u16_t *buf_len) -{ - u8_t b; - - /* Get the current byte */ - b = net_buf_pull_u8(buf); - *buf_len = b & 0x7F; - if (b & 0x80) { - /* Get the current byte */ - b = net_buf_pull_u8(buf); - *buf_len += (u16_t)b << 7; - } - - /* Return the values */ - *buf_ptr = buf->data; - - net_buf_pull(buf, *buf_len); -} - -static void deserialize_ptr(struct net_buf *buf, uintptr_t *priv) -{ - memcpy(priv, buf->data, sizeof(*priv)); - net_buf_pull(buf, sizeof(*priv)); -} - -static void deserialize_none(u8_t fn_index, struct net_buf *buf) -{ - (void)buf; - - if (buf->len != 0) { - panic(-1); - } - - m_fct_none[fn_index](); -} - -static void deserialize_s(u8_t fn_index, struct net_buf *buf) -{ - const u8_t *struct_ptr; - u8_t struct_length; - - deserialize_struct(buf, &struct_ptr, &struct_length); - - if (struct_length != m_size_s[fn_index]) { - panic(-1); - } else { - /* Always align structures on word boundary */ - uintptr_t struct_data[(struct_length + - (sizeof(uintptr_t) - 1))/(sizeof(uintptr_t))]; - - memcpy(struct_data, struct_ptr, struct_length); - - m_fct_s[fn_index](struct_data); - } -} - -static void deserialize_p(u8_t fn_index, struct net_buf *buf) -{ - uintptr_t priv; - - if (buf->len != sizeof(priv)) { - panic(-1); - } - - deserialize_ptr(buf, &priv); - - m_fct_p[fn_index]((void *)priv); -} - -static void deserialize_s_b(u8_t fn_index, struct net_buf *buf) -{ - const u8_t *p_struct_data; - u8_t struct_length; - const u8_t *p_vbuf; - u16_t vbuf_length; - - deserialize_struct(buf, &p_struct_data, &struct_length); - deserialize_buf(buf, &p_vbuf, &vbuf_length); - - if (struct_length != m_size_s_b[fn_index]) { - panic(-1); - } else { - /* Always align structures on word boundary */ - uintptr_t struct_data[(struct_length + - (sizeof(uintptr_t) - 1))/(sizeof(uintptr_t))]; - uintptr_t vbuf[(vbuf_length + - (sizeof(uintptr_t) - 1))/(sizeof(uintptr_t))]; - void *buf = NULL; - - memcpy(struct_data, p_struct_data, struct_length); - - if (vbuf_length) { - memcpy(vbuf, p_vbuf, vbuf_length); - buf = vbuf; - } - - m_fct_s_b[fn_index](struct_data, buf, vbuf_length); - } -} - -static void deserialize_b_b_p(u8_t fn_index, struct net_buf *buf) -{ - const u8_t *p_vbuf1; - u16_t vbuf1_length; - const u8_t *p_vbuf2; - u16_t vbuf2_length; - uintptr_t priv; - - deserialize_buf(buf, &p_vbuf1, &vbuf1_length); - deserialize_buf(buf, &p_vbuf2, &vbuf2_length); - deserialize_ptr(buf, &priv); - - { - /* Always align structures on word boundary */ - uintptr_t vbuf1[(vbuf1_length + - (sizeof(uintptr_t) - 1))/(sizeof(uintptr_t))]; - uintptr_t vbuf2[(vbuf2_length + - (sizeof(uintptr_t) - 1))/(sizeof(uintptr_t))]; - void *buf1 = NULL; - void *buf2 = NULL; - - if (vbuf1_length) { - memcpy(vbuf1, p_vbuf1, vbuf1_length); - buf1 = vbuf1; - } - - if (vbuf2_length) { - memcpy(vbuf2, p_vbuf2, vbuf2_length); - buf2 = vbuf2; - } - - m_fct_b_b_p[fn_index](buf1, vbuf1_length, buf2, vbuf2_length, - (void *)priv); - } -} - -static void deserialize_s_p(u8_t fn_index, struct net_buf *buf) -{ - const u8_t *p_struct_data; - u8_t struct_length; - uintptr_t priv; - - deserialize_struct(buf, &p_struct_data, &struct_length); - deserialize_ptr(buf, &priv); - - if (struct_length != m_size_s_p[fn_index]) { - panic(-1); - } else { - /* Always align structures on word boundary */ - uintptr_t struct_data[(struct_length + - (sizeof(uintptr_t) - 1))/(sizeof(uintptr_t))]; - - memcpy(struct_data, p_struct_data, struct_length); - - m_fct_s_p[fn_index](struct_data, (void *)priv); - } -} - -static void deserialize_s_b_p(u8_t fn_index, struct net_buf *buf) -{ - const u8_t *p_struct_data; - u8_t struct_length; - const u8_t *p_vbuf; - u16_t vbuf_length; - uintptr_t priv; - - deserialize_struct(buf, &p_struct_data, &struct_length); - deserialize_buf(buf, &p_vbuf, &vbuf_length); - deserialize_ptr(buf, &priv); - - if (struct_length != m_size_s_b_p[fn_index]) { - panic(-1); - } else { - /* Always align structures on word boundary */ - uintptr_t struct_data[(struct_length + - (sizeof(uintptr_t) - 1))/(sizeof(uintptr_t))]; - uintptr_t vbuf[(vbuf_length + - (sizeof(uintptr_t) - 1))/(sizeof(uintptr_t))]; - void *buf = NULL; - - memcpy(struct_data, p_struct_data, struct_length); - - if (vbuf_length) { - memcpy(vbuf, p_vbuf, vbuf_length); - buf = vbuf; - } - - m_fct_s_b_p[fn_index](struct_data, buf, vbuf_length, - (void *)priv); - } -} - -static void deserialize_s_b_b_p(u8_t fn_index, struct net_buf *buf) -{ - const u8_t *p_struct_data; - u8_t struct_length; - const u8_t *p_vbuf1; - u16_t vbuf1_length; - const u8_t *p_vbuf2; - u16_t vbuf2_length; - uintptr_t priv; - - deserialize_struct(buf, &p_struct_data, &struct_length); - deserialize_buf(buf, &p_vbuf1, &vbuf1_length); - deserialize_buf(buf, &p_vbuf2, &vbuf2_length); - deserialize_ptr(buf, &priv); - - if (struct_length != m_size_s_b_b_p[fn_index]) { - panic(-1); - } else { - /* Always align structures on word boundary */ - uintptr_t struct_data[(struct_length + - (sizeof(uintptr_t) - 1))/(sizeof(uintptr_t))]; - uintptr_t vbuf1[(vbuf1_length + - (sizeof(uintptr_t) - 1))/(sizeof(uintptr_t))]; - uintptr_t vbuf2[(vbuf2_length + - (sizeof(uintptr_t) - 1))/(sizeof(uintptr_t))]; - void *buf1 = NULL; - void *buf2 = NULL; - - memcpy(struct_data, p_struct_data, struct_length); - - if (vbuf1_length) { - memcpy(vbuf1, p_vbuf1, vbuf1_length); - buf1 = vbuf1; - } - - if (vbuf2_length) { - memcpy(vbuf2, p_vbuf2, vbuf2_length); - buf2 = vbuf2; - } - - m_fct_s_b_b_p[fn_index](struct_data, buf1, vbuf1_length, buf2, - vbuf2_length, (void *)priv); - } -} - -static void deserialize_control(u8_t fn_index, struct net_buf *buf) -{ - const u8_t *p_struct_data; - u8_t struct_length; - struct { - u32_t version; - u32_t ser_hash; - u32_t des_hash; - } struct_data; - - switch (fn_index) { - case 0: - deserialize_struct(buf, &p_struct_data, &struct_length); - - if (struct_length != sizeof(struct_data)) - panic(-1); - memcpy(&struct_data, p_struct_data, struct_length); - if (struct_data.ser_hash != rpc_deserialize_hash() || - struct_data.des_hash != rpc_serialize_hash()) { - rpc_init_cb(struct_data.version, false); - } else { - rpc_init_cb(struct_data.version, true); - } - break; - default: - panic(-1); - break; - } -} - -void rpc_deserialize(struct net_buf *buf) -{ - - u8_t fn_index; - u8_t sig_type; - - sig_type = buf->data[0]; - fn_index = buf->data[1]; - - net_buf_pull(buf, 2); - - switch (sig_type) { - case SIG_TYPE_NONE: - if (fn_index < ARRAY_SIZE(m_fct_none)) { - DBG_FUNC(debug_func_none[fn_index]); - deserialize_none(fn_index, buf); - } - break; - case SIG_TYPE_S: - if (fn_index < ARRAY_SIZE(m_fct_s)) { - DBG_FUNC(debug_func_s[fn_index]); - deserialize_s(fn_index, buf); - } - break; - case SIG_TYPE_P: - if (fn_index < ARRAY_SIZE(m_fct_p)) { - DBG_FUNC(debug_func_p[fn_index]); - deserialize_p(fn_index, buf); - } - break; - case SIG_TYPE_S_B: - if (fn_index < ARRAY_SIZE(m_fct_s_b)) { - DBG_FUNC(debug_func_s_b[fn_index]); - deserialize_s_b(fn_index, buf); - } - break; - case SIG_TYPE_B_B_P: - if (fn_index < ARRAY_SIZE(m_fct_b_b_p)) { - DBG_FUNC(debug_func_b_b_p[fn_index]); - deserialize_b_b_p(fn_index, buf); - } - break; - case SIG_TYPE_S_P: - if (fn_index < ARRAY_SIZE(m_fct_s_p)) { - DBG_FUNC(debug_func_s_p[fn_index]); - deserialize_s_p(fn_index, buf); - } - break; - case SIG_TYPE_S_B_P: - if (fn_index < ARRAY_SIZE(m_fct_s_b_p)) { - DBG_FUNC(debug_func_s_b_p[fn_index]); - deserialize_s_b_p(fn_index, buf); - } - break; - case SIG_TYPE_S_B_B_P: - if (fn_index < ARRAY_SIZE(m_fct_s_b_b_p)) { - DBG_FUNC(debug_func_s_b_b_p[fn_index]); - deserialize_s_b_b_p(fn_index, buf); - } - break; - case SIG_TYPE_CONTROL: - deserialize_control(fn_index, buf); - break; - default: - panic(-1); - break; - } -} - -__weak -void rpc_init_cb(u32_t version, bool compatible) -{ -} diff --git a/drivers/bluetooth/nble/rpc_functions_to_ble_core.h b/drivers/bluetooth/nble/rpc_functions_to_ble_core.h deleted file mode 100644 index d19f302377..0000000000 --- a/drivers/bluetooth/nble/rpc_functions_to_ble_core.h +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (c) 2016 Intel Corporation - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/* declare the list of functions sorted by signature */ -#define LIST_FN_SIG_NONE \ - FN_SIG_NONE(nble_gap_start_adv_req) \ - FN_SIG_NONE(nble_gap_stop_scan_req) \ - FN_SIG_NONE(nble_panic_req) - -#define LIST_FN_SIG_S \ - FN_SIG_S(nble_gap_set_adv_data_req, \ - struct nble_gap_set_adv_data_req *) \ - FN_SIG_S(nble_gap_set_adv_params_req, \ - struct nble_gap_set_adv_params_req *) \ - FN_SIG_S(nble_gap_start_scan_req, \ - const struct nble_gap_start_scan_req *) \ - FN_SIG_S(nble_sm_passkey_reply_req, \ - const struct nble_sm_passkey_reply_req *) \ - FN_SIG_S(nble_sm_bond_info_req, \ - const struct nble_sm_bond_info_req *) \ - FN_SIG_S(nble_sm_security_req, \ - const struct nble_sm_security_req *) \ - FN_SIG_S(nble_sm_clear_bonds_req, \ - const struct nble_sm_clear_bonds_req *) \ - FN_SIG_S(nble_set_bda_req, const struct nble_set_bda_req *) \ - FN_SIG_S(nble_get_bda_req, const struct nble_get_bda_req *) \ - FN_SIG_S(nble_gap_conn_update_req, \ - const struct nble_gap_conn_update_req *) \ - FN_SIG_S(nble_gattc_discover_req, \ - const struct nble_gattc_discover_req *) \ - FN_SIG_S(nble_uas_rssi_calibrate_req, \ - const struct nble_uas_rssi_calibrate_req *) \ - FN_SIG_S(nble_gap_service_req, \ - const struct nble_gap_service_req *) \ - FN_SIG_S(nble_gap_disconnect_req, \ - const struct nble_gap_disconnect_req *) \ - FN_SIG_S(nble_gattc_read_req, \ - const struct nble_gattc_read_req *) \ - FN_SIG_S(nble_gap_set_tx_power_req, \ - const struct nble_gap_set_tx_power_req *) \ - FN_SIG_S(nble_dbg_req, const struct nble_dbg_req *) \ - FN_SIG_S(nble_sm_pairing_response_req, \ - const struct nble_sm_pairing_response_req *) \ - FN_SIG_S(nble_sm_error_req, \ - const struct nble_sm_error_req *) - - -#define LIST_FN_SIG_P \ - FN_SIG_P(nble_gap_dtm_init_req, void *) \ - FN_SIG_P(nble_gap_stop_adv_req, void *) \ - FN_SIG_P(nble_get_version_req, ble_get_version_cb_t) \ - FN_SIG_P(nble_gap_cancel_connect_req, void *) - -#define LIST_FN_SIG_S_B \ - FN_SIG_S_B(nble_gatts_register_req, \ - const struct nble_gatts_register_req *, \ - u8_t *, u16_t) \ - FN_SIG_S_B(nble_gatts_notify_req, \ - const struct nble_gatts_notify_req *, \ - const u8_t *, u16_t) \ - FN_SIG_S_B(nble_gatts_indicate_req, \ - const struct nble_gatts_indicate_req *, \ - const u8_t *, u8_t) \ - FN_SIG_S_B(nble_gatts_read_reply_req, \ - const struct nble_gatts_read_reply_req *, \ - u8_t *, u16_t) \ - FN_SIG_S_B(nble_gattc_write_req, \ - const struct nble_gattc_write_req *, \ - const u8_t *, u16_t) \ - FN_SIG_S_B(nble_gattc_read_multi_req, \ - const struct nble_gattc_read_multi_req *, \ - const u16_t *, u16_t) \ - FN_SIG_S_B(nble_uart_test_req, \ - const struct nble_uart_test_req *, \ - const u8_t *, u8_t) \ - FN_SIG_S_B(nble_gatts_write_reply_req, \ - const struct nble_gatts_write_reply_req *, \ - const u8_t *, u8_t) - -#define LIST_FN_SIG_B_B_P - -#define LIST_FN_SIG_S_P \ - FN_SIG_S_P(nble_gap_connect_req, \ - const struct nble_gap_connect_req *, void *) \ - FN_SIG_S_P(nble_gap_set_rssi_report_req, \ - const struct nble_gap_set_rssi_report_req *, void *) - -#define LIST_FN_SIG_S_B_P - -#define LIST_FN_SIG_S_B_B_P diff --git a/drivers/bluetooth/nble/rpc_functions_to_quark.h b/drivers/bluetooth/nble/rpc_functions_to_quark.h deleted file mode 100644 index 2cda5e1e52..0000000000 --- a/drivers/bluetooth/nble/rpc_functions_to_quark.h +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2016 Intel Corporation - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/* declare the list of functions sorted by signature */ -#define LIST_FN_SIG_NONE - -#define LIST_FN_SIG_S \ - FN_SIG_S(on_nble_get_version_rsp, \ - const struct nble_get_version_rsp *) \ - FN_SIG_S(on_nble_gap_connect_evt, \ - const struct nble_gap_connect_evt *) \ - FN_SIG_S(on_nble_gap_disconnect_evt, \ - const struct nble_gap_disconnect_evt *) \ - FN_SIG_S(on_nble_gap_conn_update_evt, \ - const struct nble_gap_conn_update_evt *) \ - FN_SIG_S(on_nble_sm_status_evt, \ - const struct nble_sm_status_evt *) \ - FN_SIG_S(on_nble_sm_passkey_disp_evt, \ - const struct nble_sm_passkey_disp_evt *) \ - FN_SIG_S(on_nble_sm_passkey_req_evt, \ - const struct nble_sm_passkey_req_evt *) \ - FN_SIG_S(on_nble_gap_rssi_evt, \ - const struct nble_gap_rssi_evt *) \ - FN_SIG_S(on_nble_common_rsp, \ - const struct nble_common_rsp *) \ - FN_SIG_S(on_nble_gap_connect_rsp, \ - const struct nble_common_rsp *) \ - FN_SIG_S(on_nble_gap_cancel_connect_rsp, \ - const struct nble_common_rsp *) \ - FN_SIG_S(on_nble_get_bda_rsp, \ - const struct nble_get_bda_rsp *) \ - FN_SIG_S(on_nble_sm_config_rsp, \ - struct nble_sm_config_rsp *) \ - FN_SIG_S(on_nble_sm_common_rsp, \ - const struct nble_sm_common_rsp *) \ - FN_SIG_S(on_nble_set_bda_rsp, \ - const struct nble_set_bda_rsp *) \ - FN_SIG_S(on_nble_gap_set_rssi_report_rsp, \ - const struct nble_common_rsp *) \ - FN_SIG_S(on_nble_dbg_rsp, \ - const struct nble_dbg_rsp *) \ - FN_SIG_S(on_nble_gap_dir_adv_timeout_evt, \ - const struct nble_gap_dir_adv_timeout_evt *) \ - FN_SIG_S(on_nble_gatts_notify_tx_evt, \ - const struct nble_gatts_notify_tx_evt *) \ - FN_SIG_S(on_nble_gatts_indicate_rsp, \ - const struct nble_gatts_indicate_rsp *) \ - FN_SIG_S(on_nble_gap_start_adv_rsp, \ - const struct nble_common_rsp *) \ - FN_SIG_S(on_nble_gap_scan_start_stop_rsp, \ - const struct nble_common_rsp *) \ - FN_SIG_S(on_nble_gatts_read_evt, \ - const struct nble_gatts_read_evt *) \ - FN_SIG_S(on_nble_gatts_write_exec_evt, \ - const struct nble_gatts_write_exec_evt *) \ - FN_SIG_S(on_nble_uas_bucket_change, \ - const struct nble_uas_bucket_change *) \ - FN_SIG_S(on_nble_gattc_write_rsp, \ - const struct nble_gattc_write_rsp *) \ - FN_SIG_S(on_nble_gap_set_tx_power_rsp, \ - const struct nble_common_rsp *) \ - FN_SIG_S(on_nble_sm_pairing_request_evt, \ - const struct nble_sm_pairing_request_evt *) \ - FN_SIG_S(on_nble_sm_security_request_evt, \ - const struct nble_sm_security_request_evt *) - - -#define LIST_FN_SIG_P \ - FN_SIG_P(on_nble_gap_dtm_init_rsp, void *) - -#define LIST_FN_SIG_S_B \ - FN_SIG_S_B(nble_log, const struct nble_log_s *, char *, \ - u8_t) \ - FN_SIG_S_B(on_nble_gattc_value_evt, \ - const struct nble_gattc_value_evt *, \ - u8_t *, u8_t) \ - FN_SIG_S_B(on_nble_gatts_write_evt, \ - const struct nble_gatts_write_evt *, \ - const u8_t *, u8_t) \ - FN_SIG_S_B(on_nble_gatts_register_rsp, \ - const struct nble_gatts_register_rsp *, \ - const struct nble_gatt_attr_handles *, \ - u8_t) \ - FN_SIG_S_B(on_nble_gattc_discover_rsp, \ - const struct nble_gattc_discover_rsp *, \ - const u8_t *, u8_t) \ - FN_SIG_S_B(on_nble_gap_adv_report_evt, \ - const struct nble_gap_adv_report_evt *, \ - const u8_t *, u8_t) \ - FN_SIG_S_B(on_nble_sm_bond_info_rsp, \ - const struct nble_sm_bond_info_rsp *, \ - const bt_addr_le_t *, u16_t) \ - FN_SIG_S_B(on_nble_gattc_read_rsp, \ - const struct nble_gattc_read_rsp *, \ - u8_t *, u8_t) \ - FN_SIG_S_B(on_nble_gattc_read_multi_rsp, \ - const struct nble_gattc_read_rsp *, \ - u8_t *, u8_t) \ - FN_SIG_S_B(on_nble_uart_test_evt, \ - const struct nble_uart_test_evt *, \ - const u8_t *, u8_t) - -#define LIST_FN_SIG_B_B_P - -#define LIST_FN_SIG_S_P - -#define LIST_FN_SIG_S_B_P - -#define LIST_FN_SIG_S_B_B_P diff --git a/drivers/bluetooth/nble/rpc_serialize.c b/drivers/bluetooth/nble/rpc_serialize.c deleted file mode 100644 index d05544323d..0000000000 --- a/drivers/bluetooth/nble/rpc_serialize.c +++ /dev/null @@ -1,417 +0,0 @@ -/* - * Copyright (c) 2016 Intel Corporation - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include - -#include -#include - -#include "rpc.h" -#include "gap_internal.h" -#include "gatt_internal.h" - -#include "rpc_functions_to_ble_core.h" - -/* Build the functions exposed */ -/* Define the functions identifiers per signature */ -#define FN_SIG_NONE(__fn) fn_index_##__fn, -#define FN_SIG_S(__fn, __s) FN_SIG_NONE(__fn) -#define FN_SIG_P(__fn, __type) FN_SIG_NONE(__fn) -#define FN_SIG_S_B(__fn, __s, __type, __length) FN_SIG_NONE(__fn) -#define FN_SIG_B_B_P(__fn, __type1, __length1, __type2, __length2, __type3) \ - FN_SIG_NONE(__fn) -#define FN_SIG_S_P(__fn, __s, __type) FN_SIG_NONE(__fn) -#define FN_SIG_S_B_P(__fn, __s, __type, __length, __type_ptr) \ - FN_SIG_NONE(__fn) -#define FN_SIG_S_B_B_P(__fn, __s, __type1, __length1, __type2, __length2, \ - __type3) FN_SIG_NONE(__fn) - -/* Build the list of function indexes -> this should match the array at - * deserialization - */ -enum { LIST_FN_SIG_NONE fn_none_index_max }; -enum { LIST_FN_SIG_S fn_s_index_max }; -enum { LIST_FN_SIG_P fn_p_index_max }; -enum { LIST_FN_SIG_S_B fn_s_b_index_max }; -enum { LIST_FN_SIG_B_B_P fn_b_b_p_index_max }; -enum { LIST_FN_SIG_S_P fn_s_p_index_max }; -enum { LIST_FN_SIG_S_B_P fn_s_b_p_index_max }; -enum { LIST_FN_SIG_S_B_B_P fn_s_b_b_p_index_max }; - -/* Implement the functions using serialization API */ -#undef FN_SIG_NONE -#undef FN_SIG_S -#undef FN_SIG_P -#undef FN_SIG_S_B -#undef FN_SIG_B_B_P -#undef FN_SIG_S_P -#undef FN_SIG_S_B_P -#undef FN_SIG_S_B_B_P - -#define FN_SIG_NONE(__fn) \ - void __fn(void) \ - { \ - rpc_serialize_none(fn_index_##__fn); \ - } - -#define FN_SIG_S(__fn, __s) \ - void __fn(__s p_s) \ - { \ - rpc_serialize_s(fn_index_##__fn, p_s, sizeof(*p_s)); \ - } - -#define FN_SIG_P(__fn, __type) \ - void __fn(__type p_priv) \ - { \ - rpc_serialize_p(fn_index_##__fn, p_priv); \ - } - -#define FN_SIG_S_B(__fn, __s, __type, __length) \ - void __fn(__s p_s, __type p_buf, __length length) \ - { \ - rpc_serialize_s_b(fn_index_##__fn, p_s, sizeof(*p_s), \ - p_buf, length); \ - } - -#define FN_SIG_B_B_P(__fn, __type1, __length1, __type2, __length2, \ - __type3) \ - void __fn(__type1 p_buf1, __length1 length1, __type2 p_buf2, \ - __length2 length2, __type3 p_priv) \ - { \ - rpc_serialize_b_b_p(fn_index_##__fn, p_buf1, length1, \ - p_buf2, length2, p_priv); \ - } - -#define FN_SIG_S_P(__fn, __s, __type) \ - void __fn(__s p_s, __type p_priv) \ - { \ - rpc_serialize_s_p(fn_index_##__fn, p_s, sizeof(*p_s), \ - p_priv); \ - } - -#define FN_SIG_S_B_P(__fn, __s, __type, __length, __type_ptr) \ - void __fn(__s p_s, __type p_buf, __length length, \ - __type_ptr p_priv) \ - { \ - rpc_serialize_s_b_p(fn_index_##__fn, p_s, sizeof(*p_s), \ - p_buf, length, p_priv); \ - } - -#define FN_SIG_S_B_B_P(__fn, __s, __type1, __length1, __type2, \ - __length2, __type3) \ - void __fn(__s p_s, __type1 p_buf1, __length1 length1, \ - __type2 p_buf2, __length2 length2, __type3 p_priv) \ - { \ - rpc_serialize_s_b_b_p(fn_index_##__fn, p_s, \ - sizeof(*p_s), p_buf1, length1, \ - p_buf2, length2, p_priv); \ - } - - -/* Build the functions */ -LIST_FN_SIG_NONE -LIST_FN_SIG_S -LIST_FN_SIG_P -LIST_FN_SIG_S_B -LIST_FN_SIG_B_B_P -LIST_FN_SIG_S_P -LIST_FN_SIG_S_B_P -LIST_FN_SIG_S_B_B_P - -#undef FN_SIG_NONE -#undef FN_SIG_S -#undef FN_SIG_P -#undef FN_SIG_S_B -#undef FN_SIG_B_B_P -#undef FN_SIG_S_P -#undef FN_SIG_S_B_P -#undef FN_SIG_S_B_B_P - -#define DJB2_HASH(__h, __v) ((((__h) << 5) + (__h)) + (__v)) - -#define FN_SIG_NONE(__fn) \ - hash = DJB2_HASH(hash, 1); - -#define FN_SIG_S(__fn, __s) \ - do { \ - hash = DJB2_HASH(hash, 2); \ - hash = DJB2_HASH(hash, sizeof(*((__s)0))); \ - } while (0); - -#define FN_SIG_P(__fn, __type) \ - hash = DJB2_HASH(hash, 3); - -#define FN_SIG_S_B(__fn, __s, __type, __length) \ - do { \ - hash = DJB2_HASH(hash, 4); \ - hash = DJB2_HASH(hash, sizeof(*((__s)0))); \ - } while (0); - -#define FN_SIG_B_B_P(__fn, __type1, __length1, __type2, __length2, \ - __type3) \ - do { \ - hash = DJB2_HASH(hash, 5); \ - hash = DJB2_HASH(hash, sizeof(*((__s)0))); \ - } while (0); - -#define FN_SIG_S_P(__fn, __s, __type) \ - do { \ - hash = DJB2_HASH(hash, 6); \ - hash = DJB2_HASH(hash, sizeof(*((__s)0))); \ - } while (0); - -#define FN_SIG_S_B_P(__fn, __s, __type, __length, __type_ptr) \ - do { \ - hash = DJB2_HASH(hash, 7); \ - hash = DJB2_HASH(hash, sizeof(*((__s)0))); \ - } while (0); - -#define FN_SIG_S_B_B_P(__fn, __s, __type1, __length1, __type2, \ - __length2, __type3) \ - do { \ - hash = DJB2_HASH(hash, 8); \ - hash = DJB2_HASH(hash, sizeof(*((__s)0))); \ - } while (0); - -u32_t rpc_serialize_hash(void) -{ - u32_t hash = 5381; - - LIST_FN_SIG_NONE; - LIST_FN_SIG_S; - LIST_FN_SIG_P; - LIST_FN_SIG_S_B; - LIST_FN_SIG_B_B_P; - LIST_FN_SIG_S_P; - LIST_FN_SIG_S_B_P; - LIST_FN_SIG_S_B_B_P; - - return hash; -} - -#define SIG_TYPE_SIZE 1 -#define FN_INDEX_SIZE 1 -#define POINTER_SIZE 4 - -static void _send(struct net_buf *buf) -{ - rpc_transmit_cb(buf); -} - -static u16_t encoded_structlen(u8_t structlen) -{ - return 1 + structlen; -} - -static void serialize_struct(struct net_buf *buf, const u8_t *struct_data, - u8_t struct_length) -{ - net_buf_add_u8(buf, struct_length); - net_buf_add_mem(buf, struct_data, struct_length); -} - -static u16_t encoded_buflen(const u8_t *buf, u16_t buflen) -{ - if (!buf) { - return 1; - } - - if (buflen < (1 << 7)) { - return 1 + buflen; - } else { - return 2 + buflen; - } -} - -static void serialize_buf(struct net_buf *buf, const u8_t *data, - u16_t len) -{ - u16_t varint; - u8_t *p; - - if (!data) { - len = 0; - } - - varint = len; - - p = net_buf_add_u8(buf, (varint & 0x7f)); - if (varint >= (1 << 7)) { - *p |= 0x80; - net_buf_add_u8(buf, (varint >> 7)); - } - - net_buf_add_mem(buf, data, len); -} - -static void serialize_p(struct net_buf *buf, void *ptr) -{ - uintptr_t val = (uintptr_t)ptr; - - net_buf_add_mem(buf, &val, sizeof(val)); -} - -void rpc_serialize_none(u8_t fn_index) -{ - struct net_buf *buf; - - buf = rpc_alloc_cb(SIG_TYPE_SIZE + FN_INDEX_SIZE); - - net_buf_add_u8(buf, SIG_TYPE_NONE); - net_buf_add_u8(buf, fn_index); - - _send(buf); -} - -void rpc_serialize_s(u8_t fn_index, const void *struct_data, - u8_t struct_length) -{ - struct net_buf *buf; - - buf = rpc_alloc_cb(SIG_TYPE_SIZE + FN_INDEX_SIZE + - encoded_structlen(struct_length)); - - net_buf_add_u8(buf, SIG_TYPE_S); - net_buf_add_u8(buf, fn_index); - - serialize_struct(buf, struct_data, struct_length); - - _send(buf); -} - -void rpc_serialize_p(u8_t fn_index, void *priv) -{ - struct net_buf *buf; - - buf = rpc_alloc_cb(SIG_TYPE_SIZE + FN_INDEX_SIZE + POINTER_SIZE); - - net_buf_add_u8(buf, SIG_TYPE_P); - net_buf_add_u8(buf, fn_index); - serialize_p(buf, priv); - - _send(buf); -} - -void rpc_serialize_s_b(u8_t fn_index, const void *struct_data, - u8_t struct_length, const void *vbuf, - u16_t vbuf_length) -{ - struct net_buf *buf; - - buf = rpc_alloc_cb(SIG_TYPE_SIZE + FN_INDEX_SIZE + - encoded_structlen(struct_length) + - encoded_buflen(vbuf, vbuf_length)); - - net_buf_add_u8(buf, SIG_TYPE_S_B); - net_buf_add_u8(buf, fn_index); - - serialize_struct(buf, struct_data, struct_length); - serialize_buf(buf, vbuf, vbuf_length); - - _send(buf); -} - -void rpc_serialize_b_b_p(u8_t fn_index, const void *vbuf1, - u16_t vbuf1_length, const void *vbuf2, - u16_t vbuf2_length, void *priv) -{ - struct net_buf *buf; - - buf = rpc_alloc_cb(SIG_TYPE_SIZE + FN_INDEX_SIZE + - encoded_buflen(vbuf1, vbuf1_length) + - encoded_buflen(vbuf2, vbuf2_length) + POINTER_SIZE); - - net_buf_add_u8(buf, SIG_TYPE_B_B_P); - net_buf_add_u8(buf, fn_index); - - serialize_buf(buf, vbuf1, vbuf1_length); - serialize_buf(buf, vbuf2, vbuf2_length); - serialize_p(buf, priv); - - _send(buf); -} - -void rpc_serialize_s_p(u8_t fn_index, const void *struct_data, - u8_t struct_length, void *priv) -{ - struct net_buf *buf; - - buf = rpc_alloc_cb(SIG_TYPE_SIZE + FN_INDEX_SIZE + - encoded_structlen(struct_length) + POINTER_SIZE); - - net_buf_add_u8(buf, SIG_TYPE_S_P); - net_buf_add_u8(buf, fn_index); - - serialize_struct(buf, struct_data, struct_length); - serialize_p(buf, priv); - - _send(buf); -} - -void rpc_serialize_s_b_p(u8_t fn_index, const void *struct_data, - u8_t struct_length, const void *vbuf, - u16_t vbuf_length, void *priv) -{ - struct net_buf *buf; - - buf = rpc_alloc_cb(SIG_TYPE_SIZE + FN_INDEX_SIZE + - encoded_structlen(struct_length) + - encoded_buflen(vbuf, vbuf_length) + POINTER_SIZE); - - net_buf_add_u8(buf, SIG_TYPE_S_B_P); - net_buf_add_u8(buf, fn_index); - - serialize_struct(buf, struct_data, struct_length); - serialize_buf(buf, vbuf, vbuf_length); - serialize_p(buf, priv); - - _send(buf); -} - -void rpc_serialize_s_b_b_p(u8_t fn_index, const void *struct_data, - u8_t struct_length, const void *vbuf1, - u16_t vbuf1_length, const void *vbuf2, - u16_t vbuf2_length, void *priv) -{ - struct net_buf *buf; - - buf = rpc_alloc_cb(SIG_TYPE_SIZE + FN_INDEX_SIZE + - encoded_structlen(struct_length) + - encoded_buflen(vbuf1, vbuf1_length) + - encoded_buflen(vbuf2, vbuf2_length) + POINTER_SIZE); - - net_buf_add_u8(buf, SIG_TYPE_S_B_B_P); - net_buf_add_u8(buf, fn_index); - - serialize_struct(buf, struct_data, struct_length); - serialize_buf(buf, vbuf1, vbuf1_length); - serialize_buf(buf, vbuf2, vbuf2_length); - serialize_p(buf, priv); - - _send(buf); -} - -void rpc_init(u32_t version) -{ - struct net_buf *buf; - struct { - u32_t version; - u32_t ser_hash; - u32_t des_hash; - } struct_data; - - struct_data.version = version; - struct_data.ser_hash = rpc_serialize_hash(); - struct_data.des_hash = rpc_deserialize_hash(); - buf = rpc_alloc_cb(SIG_TYPE_SIZE + FN_INDEX_SIZE + - encoded_structlen(sizeof(struct_data))); - - net_buf_add_u8(buf, SIG_TYPE_CONTROL); - net_buf_add_u8(buf, 0); - serialize_struct(buf, (u8_t *)&struct_data, sizeof(struct_data)); - _send(buf); -} diff --git a/drivers/bluetooth/nble/smp.c b/drivers/bluetooth/nble/smp.c deleted file mode 100644 index f7ba3a0a3a..0000000000 --- a/drivers/bluetooth/nble/smp.c +++ /dev/null @@ -1,590 +0,0 @@ -/* - * Copyright (c) 2016 Intel Corporation - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include - -#include -#include - -#include -#include - -#include - -#define BT_DBG_ENABLED IS_ENABLED(NBLE_DEBUG_GAP) -#include "common/log.h" - -#include "gap_internal.h" -#include "conn_internal.h" -#include "conn.h" - -#define BT_SMP_IO_DISPLAY_ONLY 0x00 -#define BT_SMP_IO_DISPLAY_YESNO 0x01 -#define BT_SMP_IO_KEYBOARD_ONLY 0x02 -#define BT_SMP_IO_NO_INPUT_OUTPUT 0x03 -#define BT_SMP_IO_KEYBOARD_DISPLAY 0x04 - -#define BT_SMP_OOB_NOT_PRESENT 0x00 -#define BT_SMP_OOB_PRESENT 0x01 - -#define BT_SMP_MIN_ENC_KEY_SIZE 7 -#define BT_SMP_MAX_ENC_KEY_SIZE 16 - -enum { - SMP_FLAG_CFM_DELAYED, /* if confirm should be send when TK is valid */ - SMP_FLAG_ENC_PENDING, /* if waiting for an encryption change event */ - SMP_FLAG_KEYS_DISTR, /* if keys distribution phase is in progress */ - SMP_FLAG_PAIRING, /* if pairing is in progress */ - SMP_FLAG_TIMEOUT, /* if SMP timeout occurred */ - SMP_FLAG_SC, /* if LE Secure Connections is used */ - SMP_FLAG_PKEY_SEND, /* if should send Public Key when available */ - SMP_FLAG_DHKEY_PENDING, /* if waiting for local DHKey */ - SMP_FLAG_DHKEY_SEND, /* if should generate and send DHKey Check */ - SMP_FLAG_USER, /* if waiting for user input */ - SMP_FLAG_BOND, /* if bonding */ - SMP_FLAG_SC_DEBUG_KEY, /* if Secure Connection are using debug key */ - SMP_FLAG_SEC_REQ, /* if Security Request was sent/received */ -}; - -enum pairing_method { - JUST_WORKS, /* JustWorks pairing */ - PASSKEY_INPUT, /* Passkey Entry input */ - PASSKEY_DISPLAY, /* Passkey Entry display */ - PASSKEY_CONFIRM, /* Passkey confirm */ - PASSKEY_ROLE, /* Passkey Entry depends on role */ -}; - -struct bt_smp { - /* The channel this context is associated with (nble conn object)*/ - struct bt_conn *conn; - - /* Flags for SMP state machine */ - atomic_t flags; - - /* Type of method used for pairing */ - u8_t method; -}; - -static struct bt_smp bt_smp_pool[CONFIG_BLUETOOTH_MAX_CONN]; - -static struct bt_smp *smp_chan_get(struct bt_conn *conn) -{ - int i; - - for (i = 0; i < ARRAY_SIZE(bt_smp_pool); i++) { - struct bt_smp *smp = &bt_smp_pool[i]; - - if (smp->conn == conn) { - return smp; - } - } - - return NULL; -} - -static void smp_reset(struct bt_smp *smp) -{ - smp->flags = 0; - smp->method = 0; - smp->conn = NULL; -} - -void bt_smp_connected(struct bt_conn *conn) -{ - struct bt_smp *smp = NULL; - int i; - - for (i = 0; i < ARRAY_SIZE(bt_smp_pool); i++) { - smp = &bt_smp_pool[i]; - - if (!smp->conn) { - break; - } - } - - /* Reset flags and states */ - smp_reset(smp); - - smp->conn = conn; -} - -void bt_smp_disconnected(struct bt_conn *conn) -{ - struct bt_smp *smp = smp_chan_get(conn); - - if (smp) { - smp_reset(smp); - } -} - -/* based on table 2.8 Core Spec 2.3.5.1 Vol. 3 Part H */ -static const u8_t gen_method_legacy[5 /* remote */][5 /* local */] = { - { JUST_WORKS, JUST_WORKS, PASSKEY_INPUT, JUST_WORKS, PASSKEY_INPUT }, - { JUST_WORKS, JUST_WORKS, PASSKEY_INPUT, JUST_WORKS, PASSKEY_INPUT }, - { PASSKEY_DISPLAY, PASSKEY_DISPLAY, PASSKEY_INPUT, JUST_WORKS, - PASSKEY_DISPLAY }, - { JUST_WORKS, JUST_WORKS, JUST_WORKS, JUST_WORKS, JUST_WORKS }, - { PASSKEY_DISPLAY, PASSKEY_DISPLAY, PASSKEY_INPUT, JUST_WORKS, - PASSKEY_ROLE }, -}; - -static u8_t get_io_capa(void) -{ - if (!nble.auth) { - return BT_SMP_IO_NO_INPUT_OUTPUT; - } - - /* Passkey Confirmation is valid only for LE SC */ - if (nble.auth->passkey_display && nble.auth->passkey_entry && - nble.auth->passkey_confirm) { - return BT_SMP_IO_KEYBOARD_DISPLAY; - } - - /* DisplayYesNo is useful only for LE SC */ - if (nble.auth->passkey_display && - nble.auth->passkey_confirm) { - return BT_SMP_IO_DISPLAY_YESNO; - } - - if (nble.auth->passkey_entry) { - return BT_SMP_IO_KEYBOARD_ONLY; - } - - if (nble.auth->passkey_display) { - return BT_SMP_IO_DISPLAY_ONLY; - } - - return BT_SMP_IO_NO_INPUT_OUTPUT; -} - -static u8_t legacy_get_pair_method(struct bt_smp *smp, u8_t remote_io) -{ - u8_t local_io = get_io_capa(); - u8_t method; - - if (remote_io > BT_SMP_IO_KEYBOARD_DISPLAY) - return JUST_WORKS; - - method = gen_method_legacy[remote_io][local_io]; - - /* if both sides have KeyboardDisplay capabilities, initiator displays - * and responder inputs - */ - if (method == PASSKEY_ROLE) { - if (smp->conn->role == BT_HCI_ROLE_MASTER) { - method = PASSKEY_DISPLAY; - } else { - method = PASSKEY_INPUT; - } - } - - BT_DBG("local_io %u remote_io %u method %u", local_io, remote_io, - method); - - return method; -} - -static u8_t get_auth(u8_t auth) -{ - if (get_io_capa() == BT_SMP_IO_NO_INPUT_OUTPUT) { - auth &= ~(BT_SMP_AUTH_MITM); - } else { - auth |= BT_SMP_AUTH_MITM; - } - - return auth; -} - -static u8_t legacy_pairing_req(struct bt_smp *smp, - const struct nble_sec_param *par) -{ - struct nble_sm_pairing_response_req req; - - smp->method = legacy_get_pair_method(smp, par->io_capabilities); - - BT_DBG("method %u io_caps %u", smp->method, par->io_capabilities); - - /* ask for consent if pairing is not due to sending SecReq*/ - if (smp->method == JUST_WORKS && - !atomic_test_bit(&smp->flags, SMP_FLAG_SEC_REQ) && - nble.auth && nble.auth->pairing_confirm) { - atomic_set_bit(&smp->flags, SMP_FLAG_USER); - nble.auth->pairing_confirm(smp->conn); - return 0; - } - - req.conn = smp->conn; - req.conn_handle = smp->conn->handle; - req.params.auth = get_auth(par->auth); - req.params.io_capabilities = get_io_capa(); - req.params.max_key_size = par->max_key_size; - req.params.min_key_size = par->min_key_size; - req.params.oob_flag = BT_SMP_OOB_NOT_PRESENT; - - nble_sm_pairing_response_req(&req); - - return 0; -} - -void on_nble_sm_pairing_request_evt(const struct nble_sm_pairing_request_evt *evt) -{ - struct bt_conn *conn; - struct bt_smp *smp; - - BT_DBG(""); - - conn = bt_conn_lookup_handle(evt->conn_handle); - if (!conn) { - BT_ERR("Unable to find conn for handle %u", evt->conn_handle); - return; - } - - smp = smp_chan_get(conn); - if (!smp) { - BT_ERR("No smp"); - bt_conn_unref(conn); - return; - } - - atomic_set_bit(&smp->flags, SMP_FLAG_PAIRING); - - legacy_pairing_req(smp, &evt->sec_param); - - bt_conn_unref(conn); -} - -static void nble_start_security(struct bt_conn *conn) -{ - struct nble_sm_security_req req = { 0 }; - - req.conn = conn, - req.conn_handle = conn->handle, - req.params.auth = get_auth(BT_SMP_AUTH_BONDING | BT_SMP_AUTH_MITM); - req.params.io_capabilities = get_io_capa(); - req.params.max_key_size = BT_SMP_MAX_ENC_KEY_SIZE; - req.params.min_key_size = BT_SMP_MIN_ENC_KEY_SIZE; - req.params.oob_flag = BT_SMP_OOB_NOT_PRESENT; - - /** - * nble stack generates either a smp security or pairing request - * depending on role. - */ - nble_sm_security_req(&req); -} - -int bt_smp_send_pairing_req(struct bt_conn *conn) -{ - struct bt_smp *smp; - - BT_DBG(""); - - smp = smp_chan_get(conn); - if (!smp) { - return -ENOTCONN; - } - - /* pairing is in progress */ - if (atomic_test_bit(&smp->flags, SMP_FLAG_PAIRING)) { - return -EBUSY; - } - - /* TODO: Verify sec level reachable */ - - nble_start_security(conn); - - atomic_set_bit(&smp->flags, SMP_FLAG_PAIRING); - - return 0; -} -int bt_smp_send_security_req(struct bt_conn *conn) -{ - struct bt_smp *smp; - - BT_DBG(""); - - smp = smp_chan_get(conn); - if (!smp) { - return -ENOTCONN; - } - - /* pairing is in progress */ - if (atomic_test_bit(&smp->flags, SMP_FLAG_PAIRING)) { - return -EBUSY; - } - - /* TODO: Verify sec level reachable */ - - nble_start_security(conn); - - atomic_set_bit(&smp->flags, SMP_FLAG_SEC_REQ); - - return 0; -} - -void on_nble_sm_security_request_evt(const struct nble_sm_security_request_evt *evt) -{ - struct bt_conn *conn; - struct bt_smp *smp; - - BT_DBG(""); - - conn = bt_conn_lookup_handle(evt->conn_handle); - if (!conn) { - BT_ERR("Unable to find conn for handle %u", evt->conn_handle); - return; - } - - smp = smp_chan_get(conn); - if (!smp) { - BT_ERR("No smp"); - bt_conn_unref(conn); - return; - } - - BT_DBG("conn %p remote_io %u auth %u", conn, - evt->sec_param.io_capabilities, evt->sec_param.auth); - - smp->method = legacy_get_pair_method(smp, - evt->sec_param.io_capabilities); - - if (smp->method == JUST_WORKS && - nble.auth && nble.auth->pairing_confirm) { - atomic_set_bit(&smp->flags, SMP_FLAG_USER); - nble.auth->pairing_confirm(smp->conn); - goto done; - } - - bt_smp_send_pairing_req(conn); - -done: - atomic_set_bit(&smp->flags, SMP_FLAG_SEC_REQ); - bt_conn_unref(conn); -} - -void on_nble_sm_common_rsp(const struct nble_sm_common_rsp *rsp) -{ - if (rsp->status) { - BT_ERR("GAP SM request failed: conn %p err %d", rsp->conn, - rsp->status); - - /* TODO: Handle error */ - return; - } -} - -void on_nble_sm_status_evt(const struct nble_sm_status_evt *ev) -{ - struct bt_conn *conn; - struct bt_smp *smp; - - conn = bt_conn_lookup_handle(ev->conn_handle); - if (!conn) { - BT_ERR("Unable to find conn for handle %u", ev->conn_handle); - return; - } - - smp = smp_chan_get(conn); - if (!smp) { - BT_ERR("No smp for conn %p", conn); - return; - } - - BT_DBG("conn %p status %d evt_type %d sec_level %d enc_size %u", - conn, ev->status, ev->evt_type, ev->enc_link_sec.sec_level, - ev->enc_link_sec.enc_size); - - switch (ev->evt_type) { - case NBLE_GAP_SM_EVT_BONDING_COMPLETE: - BT_DBG("Bonding complete"); - if (ev->status) { - if (nble.auth && nble.auth->cancel) { - nble.auth->cancel(conn); - } - } - smp_reset(smp); - break; - case NBLE_GAP_SM_EVT_LINK_ENCRYPTED: - BT_DBG("Link encrypted"); - break; - case NBLE_GAP_SM_EVT_LINK_SECURITY_CHANGE: - BT_DBG("Security change"); - break; - default: - BT_ERR("Unknown event %d", ev->evt_type); - break; - } - - bt_conn_unref(conn); -} - -void on_nble_sm_passkey_disp_evt(const struct nble_sm_passkey_disp_evt *ev) -{ - struct bt_conn *conn; - - conn = bt_conn_lookup_handle(ev->conn_handle); - if (!conn) { - BT_ERR("Unable to find conn for handle %u", ev->conn_handle); - return; - } - - BT_DBG("conn %p passkey %u", conn, ev->passkey); - - /* TODO: Check shall we store io_caps globally */ - if (get_io_capa() == BT_SMP_IO_DISPLAY_YESNO) { - if (nble.auth && nble.auth->passkey_confirm) { - nble.auth->passkey_confirm(conn, ev->passkey); - } - } else { - if (nble.auth && nble.auth->passkey_display) { - nble.auth->passkey_display(conn, ev->passkey); - } - } - - bt_conn_unref(conn); -} - -void on_nble_sm_passkey_req_evt(const struct nble_sm_passkey_req_evt *ev) -{ - struct bt_conn *conn; - struct bt_smp *smp; - - conn = bt_conn_lookup_handle(ev->conn_handle); - if (!conn) { - BT_ERR("Unable to find conn for handle %u", ev->conn_handle); - return; - } - - smp = smp_chan_get(conn); - if (!smp) { - bt_conn_unref(conn); - return; - } - - BT_DBG("conn %p key_type %u", conn, ev->key_type); - - /* Set user input expected flag */ - atomic_set_bit(&smp->flags, SMP_FLAG_USER); - - if (ev->key_type == NBLE_GAP_SM_PK_PASSKEY) { - if (nble.auth && nble.auth->passkey_entry) { - nble.auth->passkey_entry(conn); - } - } - - bt_conn_unref(conn); -} - -static void nble_security_reply(struct bt_conn *conn, - struct nble_sm_passkey *par) -{ - struct nble_sm_passkey_reply_req rsp = { - .conn = conn, - .conn_handle = conn->handle, - }; - - memcpy(&rsp.params, par, sizeof(*par)); - - nble_sm_passkey_reply_req(&rsp); -} - -static int sm_error(struct bt_conn *conn, u8_t reason) -{ - struct nble_sm_passkey params; - - params.type = NBLE_GAP_SM_REJECT; - params.reason = reason; - - nble_security_reply(conn, ¶ms); - - return 0; -} - -static void legacy_passkey_entry(struct bt_smp *smp, unsigned int passkey) -{ - struct nble_sm_passkey pkey = { - .type = NBLE_SM_PK_PASSKEY, - .passkey = passkey, - }; - - BT_DBG("passkey %u", passkey); - - nble_security_reply(smp->conn, &pkey); -} - -int bt_smp_auth_cancel(struct bt_conn *conn) -{ - BT_DBG(""); - - return sm_error(conn, BT_SMP_ERR_PASSKEY_ENTRY_FAILED); -} - -int bt_smp_auth_passkey_entry(struct bt_conn *conn, unsigned int passkey) -{ - struct bt_smp *smp; - - BT_DBG("passkey %u", passkey); - - smp = smp_chan_get(conn); - if (!smp) { - return -EINVAL; - } - - if (!atomic_test_and_clear_bit(&smp->flags, SMP_FLAG_USER)) { - BT_ERR("Not expected user input"); - return -EINVAL; - } - - if (!atomic_test_bit(&smp->flags, SMP_FLAG_SC)) { - legacy_passkey_entry(smp, passkey); - return 0; - } - - return 0; -} - -int bt_smp_auth_pairing_confirm(struct bt_conn *conn) -{ - struct bt_smp *smp; - struct nble_sm_pairing_response_req req; - - BT_DBG(""); - - smp = smp_chan_get(conn); - if (!smp) { - return -ENOTCONN; - } - - if (!atomic_test_and_clear_bit(&smp->flags, SMP_FLAG_USER)) { - BT_ERR("Not expected user input"); - return -EINVAL; - } - - if (conn->role == BT_CONN_ROLE_MASTER) { - bt_smp_send_pairing_req(conn); - } else { - req.conn = conn; - req.conn_handle = conn->handle; - req.params.auth = get_auth(BT_SMP_AUTH_BONDING); - req.params.io_capabilities = get_io_capa(); - req.params.max_key_size = BT_SMP_MAX_ENC_KEY_SIZE; - req.params.min_key_size = BT_SMP_MIN_ENC_KEY_SIZE; - req.params.oob_flag = BT_SMP_OOB_NOT_PRESENT; - - nble_sm_pairing_response_req(&req); - } - - return 0; -} - -int bt_smp_init(void) -{ - BT_DBG(""); - - nble_get_bda_req(NULL); - - return 0; -} diff --git a/drivers/bluetooth/nble/smp.h b/drivers/bluetooth/nble/smp.h deleted file mode 100644 index 4feaecb6d5..0000000000 --- a/drivers/bluetooth/nble/smp.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (c) 2016 Intel Corporation - * - * SPDX-License-Identifier: Apache-2.0 - */ - -void bt_smp_connected(struct bt_conn *conn); -void bt_smp_disconnected(struct bt_conn *conn); -int bt_smp_init(void); - -int bt_smp_auth_cancel(struct bt_conn *conn); -int bt_smp_auth_pairing_confirm(struct bt_conn *conn); -int bt_smp_auth_passkey_entry(struct bt_conn *conn, unsigned int passkey); - -int bt_smp_send_security_req(struct bt_conn *conn); -int bt_smp_send_pairing_req(struct bt_conn *conn); diff --git a/drivers/bluetooth/nble/stubs.c b/drivers/bluetooth/nble/stubs.c deleted file mode 100644 index d986c1d715..0000000000 --- a/drivers/bluetooth/nble/stubs.c +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2016 Intel Corporation - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -#include -#include -#include "common/log.h" - -#include "gap_internal.h" -#include "gatt_internal.h" - -#include "rpc_functions_to_quark.h" - -#ifndef __weak -#define __weak __attribute__((weak)) -#endif - -#define FN_SIG_NONE(n) \ - __weak void n(void) \ - { \ - BT_WARN("Not implemented"); \ - } -LIST_FN_SIG_NONE - -#define FN_SIG_S(n, s) \ - __weak void n(s _p) \ - { \ - BT_WARN("Not implemented"); \ - } -LIST_FN_SIG_S - -#define FN_SIG_P(n, p) \ - __weak void n(p _p) \ - { \ - BT_WARN("Not implemented"); \ - } -LIST_FN_SIG_P - -#define FN_SIG_S_B(n, s, b, l) \ - __weak void n(s _p, b _b, l _l) \ - { \ - BT_WARN("Not implemented"); \ - } -LIST_FN_SIG_S_B - -#define FN_SIG_B_B_P(n, b1, l1, b2, l2, p) \ - __weak void n(b1 _b1, l1 _l1, b2 _b2, l2 _l2, p _p) \ - { \ - BT_WARN("Not implemented"); \ - } -LIST_FN_SIG_B_B_P - -#define FN_SIG_S_P(n, s, p) \ - __weak void n(s _s, p _p) \ - { \ - BT_WARN("Not implemented"); \ - } -LIST_FN_SIG_S_P - -#define FN_SIG_S_B_P(n, s, b, l, p) \ - __weak void n(s _s, b _b, l _l, p _p) \ - { \ - BT_WARN("Not implemented"); \ - } -LIST_FN_SIG_S_B_P - -#define FN_SIG_S_B_B_P(n, s, b1, l1, b2, l2, p) \ - __weak void n(s _s, b1 _b1, l1 _l1, b2 _b2, l2 _l2, p _p) \ - { \ - BT_WARN("Not implemented"); \ - } -LIST_FN_SIG_S_B_B_P diff --git a/drivers/bluetooth/nble/uart.c b/drivers/bluetooth/nble/uart.c deleted file mode 100644 index 6928643dea..0000000000 --- a/drivers/bluetooth/nble/uart.c +++ /dev/null @@ -1,244 +0,0 @@ -/* uart.c - Nordic BLE UART based Bluetooth driver */ - -/* - * Copyright (c) 2016 Intel Corporation - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -#include -#include - -#include -#include -#include -#include -#include - -#include - -#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BLUETOOTH_DEBUG_HCI_DRIVER) -#include "common/log.h" - -#include "../util.h" -#include "rpc.h" - -#if defined(CONFIG_BLUETOOTH_NRF51_PM) -#include "../nrf51_pm.h" -#endif - -/** - * @note this structure must be self-aligned and self-packed - */ -struct ipc_uart_header { - u16_t len; /**< Length of IPC message. */ - u8_t channel; /**< Channel number of IPC message. */ - u8_t src_cpu_id; /**< CPU id of IPC sender. */ -} __packed; - -/* TODO: check size */ -#define NBLE_TX_BUF_COUNT 2 -#define NBLE_RX_BUF_COUNT 10 -#define NBLE_BUF_SIZE 384 - -NET_BUF_POOL_DEFINE(rx_pool, NBLE_RX_BUF_COUNT, NBLE_BUF_SIZE, 0, NULL); -NET_BUF_POOL_DEFINE(tx_pool, NBLE_TX_BUF_COUNT, NBLE_BUF_SIZE, 0, NULL); - -static BT_STACK_NOINIT(rx_thread_stack, CONFIG_BLUETOOTH_RX_STACK_SIZE); - -static struct k_thread rx_thread_data; - -static struct device *nble_dev; - -static K_FIFO_DEFINE(rx_queue); - -static void rx_thread(void) -{ - BT_DBG("Started"); - - while (true) { - struct net_buf *buf; - - buf = net_buf_get(&rx_queue, K_FOREVER); - BT_DBG("Got buf %p", buf); - - rpc_deserialize(buf); - - net_buf_unref(buf); - - /* Make sure we don't hog the CPU if the rx_queue never - * gets empty. - */ - k_yield(); - } -} - -struct net_buf *rpc_alloc_cb(u16_t length) -{ - struct net_buf *buf; - - BT_DBG("length %u", length); - - buf = net_buf_alloc(&tx_pool, K_FOREVER); - if (!buf) { - BT_ERR("Unable to get tx buffer"); - return NULL; - } - - net_buf_reserve(buf, sizeof(struct ipc_uart_header)); - - if (length > net_buf_tailroom(buf)) { - BT_ERR("Too big tx buffer requested"); - net_buf_unref(buf); - return NULL; - } - - return buf; -} - -void rpc_transmit_cb(struct net_buf *buf) -{ - struct ipc_uart_header *hdr; - - BT_DBG("buf %p length %u", buf, buf->len); - - hdr = net_buf_push(buf, sizeof(*hdr)); - hdr->len = buf->len - sizeof(*hdr); - hdr->channel = 0; - hdr->src_cpu_id = 0; -#if defined(CONFIG_BLUETOOTH_NRF51_PM) - /* Wake-up nble */ - nrf51_wakeup(); -#endif - while (buf->len) { - uart_poll_out(nble_dev, net_buf_pull_u8(buf)); - } - - net_buf_unref(buf); -#if defined(CONFIG_BLUETOOTH_NRF51_PM) - /* TODO check if FIFO is empty */ - /* Allow nble to go to deep sleep */ - nrf51_allow_sleep(); -#endif -} - -static size_t nble_discard(struct device *uart, size_t len) -{ - /* FIXME: correct size for nble */ - u8_t buf[33]; - - return uart_fifo_read(uart, buf, min(len, sizeof(buf))); -} - -static void bt_uart_isr(struct device *unused) -{ - static struct net_buf *buf; - - ARG_UNUSED(unused); - - while (uart_irq_update(nble_dev) && uart_irq_is_pending(nble_dev)) { - static struct ipc_uart_header hdr; - static u8_t hdr_bytes; - int read; - - if (!uart_irq_rx_ready(nble_dev)) { - if (uart_irq_tx_ready(nble_dev)) { - BT_DBG("transmit ready"); - /* - * Implementing ISR based transmit requires - * extra API for uart such as - * uart_line_status(), etc. The support was - * removed from the recent code, using polling - * for transmit for now. - */ - } else { - BT_DBG("spurious interrupt"); - } - continue; - } - - if (hdr_bytes < sizeof(hdr)) { - /* Get packet type */ - hdr_bytes += uart_fifo_read(nble_dev, - (u8_t *)&hdr + hdr_bytes, - sizeof(hdr) - hdr_bytes); - if (hdr_bytes < sizeof(hdr)) { - continue; - } - - if (hdr.len > NBLE_BUF_SIZE) { - BT_ERR("Too much data to fit buffer"); - buf = NULL; - } else { - buf = net_buf_alloc(&rx_pool, K_NO_WAIT); - if (!buf) { - BT_ERR("No available IPC buffers"); - } - } - } - - if (!buf) { - hdr.len -= nble_discard(nble_dev, hdr.len); - if (!hdr.len) { - hdr_bytes = 0; - } - continue; - } - - read = uart_fifo_read(nble_dev, net_buf_tail(buf), hdr.len); - - buf->len += read; - hdr.len -= read; - - if (!hdr.len) { - BT_DBG("full packet received"); - hdr_bytes = 0; - /* Pass buffer to the stack */ - net_buf_put(&rx_queue, buf); - } - } -} - -int nble_open(void) -{ - BT_DBG(""); - - /* Initialize receive queue and start rx_thread */ - k_thread_create(&rx_thread_data, rx_thread_stack, - sizeof(rx_thread_stack), (k_thread_entry_t)rx_thread, - NULL, NULL, NULL, K_PRIO_COOP(7), 0, K_NO_WAIT); - - uart_irq_rx_disable(nble_dev); - uart_irq_tx_disable(nble_dev); - -#if defined(CONFIG_BLUETOOTH_NRF51_PM) - if (nrf51_init(nble_dev) < 0) { - return -EIO; - } -#else - bt_uart_drain(nble_dev); -#endif - - uart_irq_callback_set(nble_dev, bt_uart_isr); - - uart_irq_rx_enable(nble_dev); - - return 0; -} - -static int _bt_nble_init(struct device *unused) -{ - ARG_UNUSED(unused); - - nble_dev = device_get_binding(CONFIG_NBLE_UART_ON_DEV_NAME); - if (!nble_dev) { - return -EINVAL; - } - - return 0; -} - -DEVICE_INIT(bt_nble, "", _bt_nble_init, NULL, NULL, POST_KERNEL, - CONFIG_KERNEL_INIT_PRIORITY_DEVICE); diff --git a/drivers/bluetooth/nble/uart.h b/drivers/bluetooth/nble/uart.h deleted file mode 100644 index 1583ee83e4..0000000000 --- a/drivers/bluetooth/nble/uart.h +++ /dev/null @@ -1,131 +0,0 @@ -/* uart.h - Nordic BLE UART based Bluetooth driver */ - -/* - * Copyright (c) 2015-2016 Intel Corporation - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/** - * IPC Uart power management driver. - */ -extern struct driver ipc_uart_ns16550_driver; - -int nble_open(void); - -/** - * This function triggers the sending of PDU buffer over UART. - * - * This constructs an IPC message header and triggers the sending of it and - * message buffer. If a transmission is already ongoing, it will fail. - * In this case upper layer needs to queue the message buffer. - * - * @param dev structure of the opened device - * @param handle structure of opened IPC uart channel - * @param len length of message to send - * @param p_data message buffer to send - * - * @return IPC_UART_ERROR_OK TX has been initiated, IPC_UART_TX_BUSY a - * transmission is already going, message needs to be queued - * - * @note This function needs to be executed with (UART) irq off to avoid - * preemption from uart_ipc_isr causing state variable corruption. - * It also called from uart_ipc_isr() to send the next IPC message. - */ -int ipc_uart_ns16550_send_pdu(struct device *dev, void *handle, int len, - void *p_data); - -/** - * This function registers a callback function being called on TX start/end. - * - * This constructs an IPC message header and triggers the sending of it and - * message buffer. If a transmission is already ongoing, it will fail. In - * this case upper layer needs to queue the message buffer. - * - * @param dev structure of the opened device - * @param cb callback function for OOB sleep mode handling called at tx start - * and end - * @param param parameter passed to cb when being called - */ -void ipc_uart_ns16550_set_tx_cb(struct device *dev, void (*cb)(bool, void*), - void *param); - -/** - * Opens a UART channel for QRK/BLE Core IPC, and defines the callback function - * for receiving IPC messages. - * - * @param channel IPC channel ID to use - * @param cb Callback to handle messages - * - * @return - * - Pointer to channel structure if success, - * - NULL if opening fails. - */ -void *ipc_uart_channel_open(int channel, int (*cb)(int chan, int request, - int len, void *data)); - -/** - * The frame is a message. - */ -#define IPC_MSG_TYPE_MESSAGE 0x1 - -/** - * Requests to free a message. - */ -#define IPC_MSG_TYPE_FREE 0x2 - -/** - * Sets the MessageBox as synchronized. - */ -#define IPC_MSG_TYPE_SYNC 0x3 - -/** - * Allocates a port. - * - * This request is always flowing from a slave to the master. - */ -#define IPC_REQUEST_ALLOC_PORT 0x10 - -/** - * Registers a service. - * - * This request is always flowing from a slave to the master. - */ -#define IPC_REQUEST_REGISTER_SERVICE 0x11 - -/** - * Unregisters a service. - */ -#define IPC_REQUEST_DEREGISTER_SERVICE 0x12 - -/** - * The message is for test commands engine. - */ -#define IPC_REQUEST_REG_TCMD_ENGINE 0x13 - -/** - * Registers a Service Manager Proxy to the Service Manager. - * - * This request always flow from a slave to the master. - */ -#define IPC_REQUEST_REGISTER_PROXY 0x14 - -/** - * Notifies a panic (for log dump). - */ -#define IPC_PANIC_NOTIFICATION 0x15 - -/** - * The message is for power management. - */ -#define IPC_REQUEST_POWER_MANAGEMENT 0x16 - -/** - * Sends the log of a slave to the master (for log aggregation). - */ -#define IPC_REQUEST_LOGGER 0x17 - -/** - * The message is for power management (deep sleep). - */ -#define IPC_REQUEST_INFRA_PM 0x18 diff --git a/samples/bluetooth/beacon/prj_nble.conf b/samples/bluetooth/beacon/prj_nble.conf deleted file mode 100644 index c564ced586..0000000000 --- a/samples/bluetooth/beacon/prj_nble.conf +++ /dev/null @@ -1,5 +0,0 @@ -CONFIG_BLUETOOTH=y -CONFIG_BLUETOOTH_CUSTOM=y -CONFIG_NBLE=y -CONFIG_BLUETOOTH_DEBUG_LOG=y -CONFIG_BLUETOOTH_DEVICE_NAME="Test beacon" diff --git a/samples/bluetooth/beacon/testcase.ini b/samples/bluetooth/beacon/testcase.ini index 39d29db030..150def455a 100644 --- a/samples/bluetooth/beacon/testcase.ini +++ b/samples/bluetooth/beacon/testcase.ini @@ -2,10 +2,3 @@ tags = bluetooth build_only = true platform_whitelist = qemu_cortex_m3 qemu_x86 - -[test_nble] -tags = bluetooth -build_only = true -extra_args = CONF_FILE="prj_nble.conf" -arch_whitelist = x86 -platform_whitelist = arduino_101 diff --git a/samples/bluetooth/eddystone/prj_nble.conf b/samples/bluetooth/eddystone/prj_nble.conf deleted file mode 100644 index a2e5c11cd3..0000000000 --- a/samples/bluetooth/eddystone/prj_nble.conf +++ /dev/null @@ -1,5 +0,0 @@ -CONFIG_BLUETOOTH=y -CONFIG_BLUETOOTH_CUSTOM=y -CONFIG_NBLE=y -CONFIG_BLUETOOTH_DEBUG_LOG=y -CONFIG_BLUETOOTH_DEVICE_NAME="Zephyr Eddystone" diff --git a/samples/bluetooth/eddystone/src/main.c b/samples/bluetooth/eddystone/src/main.c index 01e033bd93..dc8c7dc95e 100644 --- a/samples/bluetooth/eddystone/src/main.c +++ b/samples/bluetooth/eddystone/src/main.c @@ -358,7 +358,6 @@ static ssize_t read_unlock(struct bt_conn *conn, return BT_GATT_ERR(BT_ATT_ERR_READ_NOT_PERMITTED); } -#if !defined(CONFIG_NBLE) /* returns a 128-bit challenge token. This token is for one-time use * and cannot be replayed. */ @@ -368,9 +367,6 @@ static ssize_t read_unlock(struct bt_conn *conn, return bt_gatt_attr_read(conn, attr, buf, len, offset, slot->challenge, sizeof(slot->challenge)); -#else - return BT_GATT_ERR(BT_ATT_ERR_NOT_SUPPORTED); -#endif /* CONFIG_NBLE */ } static ssize_t write_unlock(struct bt_conn *conn, diff --git a/samples/bluetooth/eddystone/testcase.ini b/samples/bluetooth/eddystone/testcase.ini index 39d29db030..150def455a 100644 --- a/samples/bluetooth/eddystone/testcase.ini +++ b/samples/bluetooth/eddystone/testcase.ini @@ -2,10 +2,3 @@ tags = bluetooth build_only = true platform_whitelist = qemu_cortex_m3 qemu_x86 - -[test_nble] -tags = bluetooth -build_only = true -extra_args = CONF_FILE="prj_nble.conf" -arch_whitelist = x86 -platform_whitelist = arduino_101 diff --git a/samples/bluetooth/peripheral/prj_nble.conf b/samples/bluetooth/peripheral/prj_nble.conf deleted file mode 100644 index a1dd29d5ef..0000000000 --- a/samples/bluetooth/peripheral/prj_nble.conf +++ /dev/null @@ -1,6 +0,0 @@ -CONFIG_BLUETOOTH=y -CONFIG_BLUETOOTH_CUSTOM=y -CONFIG_NBLE=y -CONFIG_BLUETOOTH_DEBUG_LOG=y -CONFIG_BLUETOOTH_ATT_PREPARE_COUNT=2 -CONFIG_BLUETOOTH_DEVICE_NAME="Test peripheral" diff --git a/samples/bluetooth/peripheral/testcase.ini b/samples/bluetooth/peripheral/testcase.ini index a4b0e7e342..150def455a 100644 --- a/samples/bluetooth/peripheral/testcase.ini +++ b/samples/bluetooth/peripheral/testcase.ini @@ -2,11 +2,3 @@ tags = bluetooth build_only = true platform_whitelist = qemu_cortex_m3 qemu_x86 - -[test_nble] -tags = bluetooth -build_only = true -extra_args = CONF_FILE="prj_nble.conf" -arch_whitelist = x86 -filter = CONFIG_SOC_QUARK_SE_C1000 -platform_whitelist = arduino_101 diff --git a/samples/bluetooth/peripheral_csc/prj_nble.conf b/samples/bluetooth/peripheral_csc/prj_nble.conf deleted file mode 100644 index 3459bb8df8..0000000000 --- a/samples/bluetooth/peripheral_csc/prj_nble.conf +++ /dev/null @@ -1,7 +0,0 @@ -CONFIG_RANDOM_GENERATOR=y -CONFIG_TEST_RANDOM_GENERATOR=y -CONFIG_BLUETOOTH=y -CONFIG_BLUETOOTH_CUSTOM=y -CONFIG_NBLE=y -CONFIG_BLUETOOTH_DEBUG_STDOUT=y -CONFIG_BLUETOOTH_DEVICE_NAME="CSC peripheral" diff --git a/samples/bluetooth/peripheral_esp/prj_nble.conf b/samples/bluetooth/peripheral_esp/prj_nble.conf deleted file mode 100644 index d1df4580a9..0000000000 --- a/samples/bluetooth/peripheral_esp/prj_nble.conf +++ /dev/null @@ -1,5 +0,0 @@ -CONFIG_BLUETOOTH=y -CONFIG_BLUETOOTH_CUSTOM=y -CONFIG_NBLE=y -CONFIG_BLUETOOTH_DEBUG_LOG=y -CONFIG_BLUETOOTH_DEVICE_NAME="ESP peripheral" diff --git a/samples/bluetooth/peripheral_esp/testcase.ini b/samples/bluetooth/peripheral_esp/testcase.ini index a4b0e7e342..150def455a 100644 --- a/samples/bluetooth/peripheral_esp/testcase.ini +++ b/samples/bluetooth/peripheral_esp/testcase.ini @@ -2,11 +2,3 @@ tags = bluetooth build_only = true platform_whitelist = qemu_cortex_m3 qemu_x86 - -[test_nble] -tags = bluetooth -build_only = true -extra_args = CONF_FILE="prj_nble.conf" -arch_whitelist = x86 -filter = CONFIG_SOC_QUARK_SE_C1000 -platform_whitelist = arduino_101 diff --git a/samples/bluetooth/peripheral_hids/prj_nble.conf b/samples/bluetooth/peripheral_hids/prj_nble.conf deleted file mode 100644 index 7aaa8acbcf..0000000000 --- a/samples/bluetooth/peripheral_hids/prj_nble.conf +++ /dev/null @@ -1,5 +0,0 @@ -CONFIG_BLUETOOTH=y -CONFIG_BLUETOOTH_CUSTOM=y -CONFIG_NBLE=y -CONFIG_BLUETOOTH_DEBUG_LOG=y -CONFIG_BLUETOOTH_DEVICE_NAME="Test HoG mouse" diff --git a/samples/bluetooth/peripheral_hids/testcase.ini b/samples/bluetooth/peripheral_hids/testcase.ini index 39d29db030..150def455a 100644 --- a/samples/bluetooth/peripheral_hids/testcase.ini +++ b/samples/bluetooth/peripheral_hids/testcase.ini @@ -2,10 +2,3 @@ tags = bluetooth build_only = true platform_whitelist = qemu_cortex_m3 qemu_x86 - -[test_nble] -tags = bluetooth -build_only = true -extra_args = CONF_FILE="prj_nble.conf" -arch_whitelist = x86 -platform_whitelist = arduino_101 diff --git a/samples/bluetooth/peripheral_hr/prj_nble.conf b/samples/bluetooth/peripheral_hr/prj_nble.conf deleted file mode 100644 index cb30e41520..0000000000 --- a/samples/bluetooth/peripheral_hr/prj_nble.conf +++ /dev/null @@ -1,5 +0,0 @@ -CONFIG_BLUETOOTH=y -CONFIG_BLUETOOTH_CUSTOM=y -CONFIG_NBLE=y -CONFIG_BLUETOOTH_DEBUG_LOG=y -CONFIG_BLUETOOTH_DEVICE_NAME="Zephyr Heartrate Sensor" diff --git a/samples/bluetooth/peripheral_hr/testcase.ini b/samples/bluetooth/peripheral_hr/testcase.ini index 16c547ec56..9fcdb833a8 100644 --- a/samples/bluetooth/peripheral_hr/testcase.ini +++ b/samples/bluetooth/peripheral_hr/testcase.ini @@ -2,11 +2,3 @@ tags = bluetooth build_only = true platform_whitelist = qemu_cortex_m3 qemu_x86 frdm_k64f hexiwear_k64 - -[test_nble] -tags = bluetooth -build_only = true -extra_args = CONF_FILE="prj_nble.conf" -arch_whitelist = x86 -filter = CONFIG_SOC_QUARK_SE_C1000 -platform_whitelist = arduino_101 diff --git a/scripts/sanity_chk/sanity_last_release.csv b/scripts/sanity_chk/sanity_last_release.csv index 37f0583d7f..00700cb7e1 100644 --- a/scripts/sanity_chk/sanity_last_release.csv +++ b/scripts/sanity_chk/sanity_last_release.csv @@ -171,7 +171,6 @@ tests/legacy/kernel/test_stack/nanokernel/test,x86,qemu_x86_iamcu,True,,,True,1. tests/crypto/test_mbedtls/test,x86,quark_se_c1000_devboard,True,,,False,,23360,79568 tests/ztest/test/base/test_verbose_1,x86,quark_d2000_crb,True,,CONF_FILE=prj_verbose_1.conf,False,,2540,8461 tests/legacy/kernel/test_mem_safe/test,x86,qemu_x86,True,,,True,0.2202446460723877,18887,15079 -samples/bluetooth/peripheral/test_nble,x86,arduino_101,True,,"CONF_FILE=""prj_nble.conf""",False,,13872,36645 tests/drivers/build_all/test_build_ethernet,arm,nrf51_blenano,True,,CONF_FILE=ethernet.conf,False,,9896,50904 samples/legacy/synchronization/microkernel/test,arm,nucleo_f401re,True,,,False,,6212,12474 tests/legacy/kernel/test_stackprot/nanokernel/test,arm,nrf52_pca10040,True,,,False,,9628,55724 @@ -250,7 +249,6 @@ tests/legacy/benchmark/footprint/microkernel/footprint-min,arc,arduino_101_sss,T tests/legacy/kernel/test_map_priv/test,arm,arduino_101_ble,True,,,False,,14424,45558 samples/bluetooth/eddystone/test,x86,qemu_x86,True,,,True,,60323,50403 tests/legacy/kernel/test_context/test,arm,qemu_cortex_m3,True,,,True,6.080919981002808,7464,13334 -tests/bluetooth/shell/test_nble,x86,arduino_101,True,,"CONF_FILE=""prj_nble.conf""",False,,16420,50000 tests/legacy/kernel/test_sema_priv/test,x86,arduino_101,True,,,False,,14948,15475 tests/legacy/benchmark/footprint/nanokernel/footprint-reg,nios2,qemu_nios2,True,,TEST=reg,True,,4972,16916 tests/legacy/kernel/test_mutex/test,x86,quark_d2000_crb,True,,,False,,6028,11062 @@ -372,7 +370,6 @@ tests/crypto/test_ctr_prng/test,arc,em_starterkit,True,,,False,,26768,20804 tests/legacy/benchmark/footprint/nanokernel/footprint-reg,arm,v2m_beetle,True,,TEST=reg,False,,2352,9726 tests/ztest/test/base/test_verbose_0,x86,arduino_101,True,,CONF_FILE=prj_verbose_0.conf,False,,4876,10597 samples/net/echo_server/test_bt,x86,minnowboard,True,,"CONF_FILE=""prj_bt.conf""",False,,140574,119582 -samples/bluetooth/peripheral_hids/test_nble,x86,arduino_101,True,,"CONF_FILE=""prj_nble.conf""",False,,13072,34885 samples/legacy/synchronization/nanokernel/test,arm,cc3200_launchxl,True,,,False,,18852,13172 samples/legacy/philosophers/microkernel/test,arm,nucleo_f103rb,True,,,False,,11604,12138 tests/kernel/test_build/test_newlib,x86,galileo,True,,CONF_FILE=newlib.conf,False,,43851,35155 @@ -381,7 +378,6 @@ tests/legacy/kernel/test_task_priv/test,arm,96b_carbon,True,,,False,,8308,15232 samples/hello_world/test,arm,quark_se_c1000_ble,True,,,False,,8120,44590 samples/drivers/gpio/test,arc,arduino_101_sss,True,,,False,,4988,13024 tests/legacy/kernel/test_sema_priv/test,arm,stm32_mini_a15,True,,,False,,15044,16134 -samples/bluetooth/peripheral_hr/test_nble,x86,arduino_101,True,,"CONF_FILE=""prj_nble.conf""",False,,12948,35027 tests/legacy/kernel/test_fifo_priv/test,arm,hexiwear_k64,True,,,False,,8216,16250 tests/legacy/benchmark/latency_measure/test,arm,v2m_beetle,True,,,False,,10460,19822 tests/kernel/test_common/test,arm,cc3200_launchxl,True,,,False,,28954,22202 @@ -913,7 +909,6 @@ tests/net/zoap/test,arm,nrf52_pca10040,True,,,False,,10856,54910 tests/legacy/kernel/test_pipe/test,arc,quark_se_c1000_ss_devboard,True,,,False,,13600,21916 tests/legacy/kernel/test_errno/test,x86,galileo,True,,,False,,37666,30474 tests/kernel/test_build/test_newlib,x86,quark_se_c1000_devboard,True,,CONF_FILE=newlib.conf,False,,5944,12075 -samples/bluetooth/beacon/test_nble,x86,arduino_101,True,,"CONF_FILE=""prj_nble.conf""",False,,11824,27833 tests/legacy/kernel/test_task_priv/test,arm,nucleo_f401re,True,,,False,,8288,15196 tests/bluetooth/init/test_17,arm,qemu_cortex_m3,True,,CONF_FILE=prj_17.conf,True,,18580,110066 tests/legacy/kernel/test_task/test,arm,nucleo_f401re,True,,,False,,8288,15196 @@ -1082,7 +1077,6 @@ tests/kernel/test_multilib/test,arm,frdm_k64f,True,,,False,,3936,13742 tests/legacy/kernel/test_early_sleep/test,arm,arduino_due,True,,,False,,6488,10898 tests/kernel/test_sprintf/test,x86,minnowboard,True,,,False,,26251,22571 tests/legacy/kernel/test_nano_work/test,arm,nrf51_pca10028,True,,,False,,10508,49432 -samples/environmental_sensing/x86/test-nble,x86,quark_se_c1000_devboard,True,,"CONF_FILE=""prj_nble.conf""",False,,12384,29742 tests/kernel/test_build/test_newlib,arc,arduino_101_sss,True,,CONF_FILE=newlib.conf,False,,6968,13512 samples/legacy/philosophers/microkernel/test,arc,arduino_101_sss,True,,,False,,12464,11940 tests/bluetooth/init/test_19,arm,qemu_cortex_m3,True,,CONF_FILE=prj_19.conf,True,,14436,57250 @@ -1226,7 +1220,6 @@ samples/logger-hook/test,x86,arduino_101,True,,,False,,6072,14740 tests/legacy/kernel/test_stack/nanokernel/test,arm,stm32_mini_a15,True,,,False,,10272,15336 tests/legacy/kernel/test_tickless/microkernel/test,arm,frdm_k64f,True,,,False,,8128,12878 tests/crypto/test_mbedtls/test,arm,96b_nitrogen,True,,,False,,28104,104506 -samples/bluetooth/peripheral_esp/test_nble,x86,arduino_101,True,,"CONF_FILE=""prj_nble.conf""",False,,13392,36305 tests/legacy/kernel/test_libs/test,arm,nrf51_pca10028,True,,,False,,12400,48798 tests/legacy/kernel/test_map/test,arc,em_starterkit,True,,,False,,26096,15204 tests/kernel/test_build/test_runtime_nmi,arm,frdm_k64f,True,,CONF_FILE=runtime_nmi.conf,False,,6060,12386 @@ -1273,7 +1266,6 @@ tests/legacy/kernel/test_timer/nanokernel/test,arm,96b_carbon,True,,,False,,8324 tests/legacy/kernel/test_pool/test,x86,minnowboard,True,,,False,,33378,17122 tests/legacy/kernel/test_irq_offload/test,nios2,altera_max10,True,,,False,,4436,13516 samples/synchronization/test,arm,frdm_k64f,True,,,False,,6060,12182 -samples/bluetooth/eddystone/test_nble,x86,arduino_101,True,,"CONF_FILE=""prj_nble.conf""",False,,13144,31197 tests/kernel/test_common/test,arm,v2m_beetle,True,,,False,,7044,19586 samples/legacy/synchronization/nanokernel/test,arm,nrf51_pca10028,True,,,False,,10168,46944 samples/legacy/task_profiler/nanokernel/test,x86,qemu_x86,True,,,True,,28932,20252 @@ -1404,7 +1396,6 @@ tests/drivers/build_all/test_build_sensor_triggers,arm,stm32_mini_a15,True,,CONF samples/basic/button/test,arm,nucleo_f103rb,True,,,False,,3992,10690 tests/legacy/kernel/test_events/test,x86,arduino_101,True,,,False,,10240,13957 samples/bluetooth/peripheral_sc_only/test,arm,qemu_cortex_m3,True,,,True,,12204,45206 -tests/bluetooth/shell/test_nble,x86,quark_se_c1000_devboard,True,,"CONF_FILE=""prj_nble.conf""",False,,16420,49891 tests/drivers/build_all/test_build_ethernet,arm,nrf52_pca10040,True,,CONF_FILE=ethernet.conf,False,,10348,48906 tests/legacy/kernel/test_sema/microkernel/test,arm,nrf51_pca10028,True,,,False,,12872,51110 tests/crypto/test_ctr_prng/test,arc,arduino_101_sss,True,,,False,,6380,19840 @@ -1848,7 +1839,6 @@ tests/legacy/benchmark/footprint/nanokernel/footprint-min,arm,nrf51_blenano,True tests/legacy/benchmark/footprint/nanokernel/footprint-max,arc,quark_se_c1000_ss_devboard,True,,TEST=max,False,,5908,13852 tests/legacy/kernel/test_critical/test,x86,qemu_x86_iamcu,True,,,True,15.53974986076355,18415,11667 tests/legacy/kernel/test_mutex/test,arm,96b_carbon,True,,,False,,8616,15012 -tests/bluetooth/tester/test_nble,x86,arduino_101,True,,"CONF_FILE=""nble.conf""",False,,22244,40821 samples/logger-hook/test,arm,96b_carbon,True,,,False,,6260,15560 tests/legacy/kernel/test_arm_irq_vector_table/test,arm,hexiwear_k64,True,,,False,,3980,11422 tests/kernel/test_bitfield/test,nios2,qemu_nios2,True,,,True,0.0020706653594970703,4404,15792 @@ -2372,7 +2362,6 @@ tests/drivers/build_all/test_build_sensors_a_m,x86,qemu_x86_iamcu,True,,CONF_FIL tests/kernel/test_multilib/test,arm,arduino_101_ble,True,,,False,,8120,44626 tests/legacy/kernel/test_critical/test,arm,stm32_mini_a15,True,,,False,,7156,12846 tests/crypto/test_aes/test,arm,quark_se_c1000_ble,True,,,False,,12216,56118 -samples/environmental_sensing/x86/test-nble,x86,arduino_101,True,,"CONF_FILE=""prj_nble.conf""",False,,12384,29851 tests/legacy/kernel/test_mail_priv/test,arm,nucleo_f103rb,True,,,False,,11684,21386 tests/kernel/test_build/test_newlib,arm,96b_carbon,True,,CONF_FILE=newlib.conf,False,,6196,15140 tests/legacy/kernel/test_obj_tracing/microkernel/test,x86,minnowboard,True,,,False,,24252,12344 diff --git a/tests/bluetooth/shell/prj_nble.conf b/tests/bluetooth/shell/prj_nble.conf deleted file mode 100644 index 5ea9350ab9..0000000000 --- a/tests/bluetooth/shell/prj_nble.conf +++ /dev/null @@ -1,9 +0,0 @@ -CONFIG_TEST_RANDOM_GENERATOR=y -CONFIG_BLUETOOTH=y -CONFIG_BLUETOOTH_CUSTOM=y -CONFIG_NBLE=y -CONFIG_CONSOLE_HANDLER=y -CONFIG_CONSOLE_SHELL=y -CONFIG_BLUETOOTH_DEBUG_LOG=y -CONFIG_BLUETOOTH_ATT_PREPARE_COUNT=2 -CONFIG_BLUETOOTH_DEVICE_NAME="test shell" diff --git a/tests/bluetooth/shell/testcase.ini b/tests/bluetooth/shell/testcase.ini index 38e5367413..1415b41221 100644 --- a/tests/bluetooth/shell/testcase.ini +++ b/tests/bluetooth/shell/testcase.ini @@ -3,12 +3,6 @@ tags = bluetooth build_only = true platform_whitelist = qemu_cortex_m3 qemu_x86 arduino_101 -[test_nble] -tags = bluetooth -build_only = true -extra_args = CONF_FILE="prj_nble.conf" -filter = CONFIG_SOC_QUARK_SE_C1000 - [test_br] tags = bluetooth build_only = true diff --git a/tests/bluetooth/tester/nble.conf b/tests/bluetooth/tester/nble.conf deleted file mode 100644 index 0993e77a66..0000000000 --- a/tests/bluetooth/tester/nble.conf +++ /dev/null @@ -1,7 +0,0 @@ -CONFIG_UART_PIPE=y -CONFIG_CONSOLE_HANDLER=y -CONFIG_BLUETOOTH=y -CONFIG_BLUETOOTH_CUSTOM=y -CONFIG_NBLE=y -CONFIG_UART_CONSOLE=n -CONFIG_BLUETOOTH_ATT_PREPARE_COUNT=4 diff --git a/tests/bluetooth/tester/testcase.ini b/tests/bluetooth/tester/testcase.ini index 6b6196dba0..5e5bc6d456 100644 --- a/tests/bluetooth/tester/testcase.ini +++ b/tests/bluetooth/tester/testcase.ini @@ -3,11 +3,3 @@ tags = bluetooth build_only = true # FIXME: minnowboard using IRQ3 for both UART console and h4 platform_whitelist = minnowboard - -[test_nble] -tags = bluetooth -build_only = true -extra_args = CONF_FILE="nble.conf" -arch_whitelist = x86 -filter = CONFIG_SOC_QUARK_SE_C1000 -platform_whitelist = arduino_101