diff --git a/pkg/nordic_softdevice_ble/Makefile b/pkg/nordic_softdevice_ble/Makefile deleted file mode 100644 index 79f8bd89ca..0000000000 --- a/pkg/nordic_softdevice_ble/Makefile +++ /dev/null @@ -1,56 +0,0 @@ -PKG_NAME = nordic_softdevice_ble -PKG_VERSION = 3288530 -PKG_FILE = nrf5_iot_sdk_$(PKG_VERSION).zip -PKG_URL = https://developer.nordicsemi.com/nRF5_IoT_SDK/nRF5_IoT_SDK_v0.9.x/$(PKG_FILE) -PKG_MD5 = 291c875df69c51e22491e6112128bd9c -PKG_LICENSE = nordic-bsd - -PKG_DIR = $(CURDIR) -PKG_BUILD_DIR = $(BINDIR)/pkg/$(PKG_NAME) -PKG_SOURCE_DIR = $(PKGDIRBASE)/$(PKG_NAME) -PKG_SRCDIR = $(PKG_SOURCE_DIR)/src - -SOFTDEVICE := components/softdevice/s1xx_iot/s1xx-iot-prototype3_nrf52_softdevice.hex -BLE_6LOWPAN_LIB := components/iot/ble_6lowpan/lib/ble_6lowpan.a - -SOFTDEVICE_MODULES = $(filter softdevice_handler ble_common ble_ipsp,$(USEMODULE)) - -.PHONY: all prepare clean distclean $(SOFTDEVICE_MODULES) - -all: $(BINDIR)/ble_6lowpan.a $(BINDIR)/softdevice.hex $(SOFTDEVICE_MODULES) - -prepare: $(PKG_SRCDIR)/.extracted - -softdevice_handler: - "$(MAKE)" -C $(PKG_SRCDIR)/components/softdevice/common/softdevice_handler -f $(RIOTBASE)/Makefile.base - -ble_common: - "$(MAKE)" -C $(PKG_SRCDIR)/components/ble/common -f $(CURDIR)/ble_common.mk - -ble_ipsp: - "$(MAKE)" -C $(PKG_SRCDIR)/components/iot/ble_ipsp -f $(RIOTBASE)/Makefile.base - -$(BINDIR)/ble_6lowpan.a: $(PKG_SRCDIR)/.extracted - cp $(PKG_SRCDIR)/$(BLE_6LOWPAN_LIB) $@ - -# softdevice.hex has the `[0x8bc, 0x3000[` addresses not set. -# However, it requires that the value at `0x2000` is 0xFFFFFFFF -# We just put all the undefined memory to 0xff as it is the rom reset value anyway. -$(BINDIR)/softdevice.hex: $(PKG_SRCDIR)/.extracted - $(Q)$(OBJCOPY) $(OFLAGS) -Oihex --gap-fill 0xff $(PKG_SRCDIR)/$(SOFTDEVICE) $@ - -$(PKG_SRCDIR)/.extracted: $(PKG_SOURCE_DIR)/$(PKG_FILE) - rm -rf $(@D) - mkdir -p $(@D) - $(Q)cd $(@D) && $(UNZIP_HERE) $(PKG_SOURCE_DIR)/$(PKG_FILE) - touch $@ - -$(PKG_SOURCE_DIR)/$(PKG_FILE): - @mkdir -p $(@D) - $(Q)$(DLCACHE) $(PKG_URL) $(PKG_MD5) $@ - -clean:: - rm -rf $(PKG_SOURCE_DIR)/ - -distclean:: - rm -rf $(PKG_BUILD_DIR)/ diff --git a/pkg/nordic_softdevice_ble/Makefile.dep b/pkg/nordic_softdevice_ble/Makefile.dep deleted file mode 100644 index 65d8e56ee1..0000000000 --- a/pkg/nordic_softdevice_ble/Makefile.dep +++ /dev/null @@ -1,18 +0,0 @@ -FEATURES_REQUIRED += ble_nordic_softdevice -USEMODULE += softdevice_handler -USEMODULE += ble_common -USEMODULE += ble_6lowpan -USEMODULE += gnrc_sixlowpan -USEMODULE += gnrc_sixlowpan_iphc -USEMODULE += gnrc_ipv6_nib_6ln -USEMODULE += gnrc_ipv6_default - -# prevent application from being a router -# TODO: maybe find a nicer solution in future build system update -_ROUTER_MODULES = gnrc_ipv6_router% gnrc_rpl netstats_rpl auto_init_gnrc_rpl -ifneq (,$(filter $(_ROUTER_MODULES),$(USEMODULE))) - $(warning nordic_softdevice_ble: Disabling router modules:\ - $(filter $(_ROUTER_MODULES),$(USEMODULE))) -endif - -USEMODULE := $(filter-out $(_ROUTER_MODULES),$(USEMODULE)) diff --git a/pkg/nordic_softdevice_ble/Makefile.include b/pkg/nordic_softdevice_ble/Makefile.include deleted file mode 100644 index 1426ee11b3..0000000000 --- a/pkg/nordic_softdevice_ble/Makefile.include +++ /dev/null @@ -1,33 +0,0 @@ -NORDIC_SRCS := $(PKGDIRBASE)/nordic_softdevice_ble/src - -INCLUDES += \ - -I$(RIOTBASE)/pkg/nordic_softdevice_ble/src \ - -I$(NORDIC_SRCS)/components/ble/common \ - -I$(NORDIC_SRCS)/components/device \ - -I$(NORDIC_SRCS)/components/iot/ble_6lowpan \ - -I$(NORDIC_SRCS)/components/iot/ble_ipsp \ - -I$(NORDIC_SRCS)/components/iot/common \ - -I$(NORDIC_SRCS)/components/libraries/scheduler \ - -I$(NORDIC_SRCS)/components/libraries/util \ - -I$(NORDIC_SRCS)/components/softdevice/common/softdevice_handler \ - -I$(NORDIC_SRCS)/components/softdevice/s1xx_iot/headers \ - -I$(NORDIC_SRCS)/components/softdevice/s1xx_iot/headers/nrf52 \ - -I$(NORDIC_SRCS)/components/toolchain - -CFLAGS += -DNRF52 \ - -DBLE_STACK_SUPPORT_REQD \ - -DISR_STACKSIZE=8192 \ - -DSOFTDEVICE_PRESENT \ - -DS132 - -CFLAGS += -Wno-pedantic -Wno-unused-parameter -Wno-sign-compare - -# Nordic's ble_6lowpan.a is compiled with hard-float -# so set this, otherwise linking fails -CFLAGS_FPU := -mfloat-abi=hard -mfpu=fpv4-sp-d16 -ARCHIVES += $(BINDIR)/ble_6lowpan.a - -DIRS += $(RIOTBASE)/pkg/nordic_softdevice_ble/src - -# LLVM ARM assembler has massive problems digesting this -TOOLCHAINS_BLACKLIST += llvm diff --git a/pkg/nordic_softdevice_ble/README-BLE-6LoWPAN.md b/pkg/nordic_softdevice_ble/README-BLE-6LoWPAN.md deleted file mode 100644 index b4dd535c20..0000000000 --- a/pkg/nordic_softdevice_ble/README-BLE-6LoWPAN.md +++ /dev/null @@ -1,104 +0,0 @@ -This README contains information how to establish an IPv6 connection between -Linux BLE router and an IPSP enabled BLE device. - -Prerequisites -============= -In general, any device capable of running Linux operating system, can be used -as a BLE router provided the following conditions are met: - -* Linux Kernel >3.18 and <=4.12 is used - * The nRF IoT SDK version used in this package does not yet support the - `BLE_6LOWPAN_LEGACY_MODE` flag, which would remove the upper version bound. - See [the package documentation](https://riot-os.org/api/group__pkg__nordic-softdevice-ble.html) - for further directions. -* bluez, libcap-ng0, radvd tools are present. - -If a built-in Bluetooth device is not available then Bluetooth 4.0 compatible -USB dongle can be used. - -The following procedures have been tested on Ubuntu 15.10 and Ubuntu 16.04. - -Establishing an IPv6 connection -=============================== -Use the following procedure to establish a connection between an nRF52 device -and Linux router: - -First enable 6LoWPAN module. This is necessary only once per session: - - # Log in as a root user. - sudo su - - # Mount debugfs file system. - mount -t debugfs none /sys/kernel/debug - - # Load 6LoWPAN module. - modprobe bluetooth_6lowpan - - # Enable the bluetooth 6lowpan module. - echo 1 > /sys/kernel/debug/bluetooth/6lowpan_enable - - # Look for available HCI devices. - hciconfig - - # Reset HCI device - for example hci0 device. - hciconfig hci0 reset - - # Read 00:AA:BB:XX:YY:ZZ address of the nRF5x device. - hcitool lescan - -If you see device name and address in lescan output then you can connect to the -device: - - echo "connect 00:AA:BB:XX:YY:ZZ 1" > /sys/kernel/debug/bluetooth/6lowpan_control - -If above is successful then LED1 will stop blinking and LED2 will switch on. -You can then check the connection using the following commands: - - # Check if bt0 interface is present and up - ifconfig - - # Try to ping the device using its link-local address, for example, on bt0 interface. - ping6 fe80::2aa:bbff:fexx:yyzz%bt0 - -If you'd like to learn more about the procedure please refer to -[Connecting devices to the router]. - -Distributing routable IPv6 prefix -================================= -In Linux, Router Advertisement Daemon (RADVD) can be used to distribute prefixes -in the network, hance configure routable IPv6 address. - -To configure RADVD create `/etc/radvd.conf` file and paste the following contents: - - interface bt0 - { - AdvSendAdvert on; - prefix 2001:db8::/64 - { - AdvOnLink off; - AdvAutonomous on; - AdvRouterAddr on; - }; - }; - -Next, start RADVD daemon: - - # Set IPv6 forwarding (must be present). - sudo echo 1 > /proc/sys/net/ipv6/conf/all/forwarding - # Run radvd daemon. - sudo service radvd restart - -If successful then all devices connected to the host will receive -a routable `2001:db8` prefix. - -This can be verified by sending echo request to the full address: - - ping6 -I bt0 2001:db8::2aa:bbff:fexx:yyzz - -where `aa:bbff:fexx:yyzz` is device Bluetooth address. - -If you'd like to learn more about the procedure please refer to -[Distributing a global IPv6 prefix]. - -* [Connecting devices to the router]: http://developer.nordicsemi.com/nRF5_IoT_SDK/doc/0.9.0/html/a00089.html -* [Distributing a global IPv6 prefix]: http://developer.nordicsemi.com/nRF5_IoT_SDK/doc/0.9.0/html/a00090.html diff --git a/pkg/nordic_softdevice_ble/ble_common.mk b/pkg/nordic_softdevice_ble/ble_common.mk deleted file mode 100644 index e9b66f5640..0000000000 --- a/pkg/nordic_softdevice_ble/ble_common.mk +++ /dev/null @@ -1,5 +0,0 @@ -MODULE = ble_common - -SRC = ble_advdata.c - -include $(RIOTBASE)/Makefile.base diff --git a/pkg/nordic_softdevice_ble/doc.txt b/pkg/nordic_softdevice_ble/doc.txt deleted file mode 100644 index 2db7d46e1d..0000000000 --- a/pkg/nordic_softdevice_ble/doc.txt +++ /dev/null @@ -1,54 +0,0 @@ -/** - * @defgroup pkg_nordic-softdevice-ble Nordic Softdevice BLE - * @ingroup pkg - * @ingroup net - * @brief Provides a RIOT adaption for Nordic Softdevice BLE library - * @deprecated Will be removed after the 2020.10 release. Use nimble for BLE - * support instead. - -# Overview - -This package provides necessary Makefiles and glue code to use the Nordic S132 -SoftDevice as Bluetooth BLE transport for RIOT's 6lowpan stack. - -# Usage - -"gnrc_netdev_default" has a dependency to "nordic_softdevice_ble", so all -examples automatically download the SDK and compile / link / flash all needed -code. - -If you want to manually set up included modules, add "USEPKG += -nordic_softdevice_ble" to your application's Makefile. - -See README-BLE-6LoWPAN.md for instructions on how to set up 6lowpan over BLE on -Linux. - -# Known issues - -- floating point ABI mismatch - - The Nordic binaries are compiled using hard float ABI, which RIOT currently -doesn't support (RIOT's context switching code doesn't preserve the floating -point registers). If the softdevice is compiled in, RIOT will be compiled with -hard float ABI in order for the linking to succeed. This works for some -application, but will lead to serious and hard-to-find bugs for code using -floating point instructions. - - Hopefully, either the RIOT community adds hard-float support, or Nordic -releases a soft-float version of the used binaries. - -- Outdated - - This package uses version 0.9 of the nRF IoT SDK, which has been integrated - into the nRF5 SDK v14.1.0 in its 1.0 version, and the nRF5 SDK has since been - released in several new versions. - - A noteworthy shortcoming due to the old version is that the IPSP - implementation only interoperates with Linux kernels up to 4.12. - - Unless the [efforts to update the softedevice - integration](https://github.com/RIOT-OS/RIOT/pull/9473) are rekindled, this - module should not be used in new projects, and @ref pkg_nimble should be used - instead. - - */ diff --git a/pkg/nordic_softdevice_ble/src/Makefile b/pkg/nordic_softdevice_ble/src/Makefile deleted file mode 100644 index d8f0fd1b27..0000000000 --- a/pkg/nordic_softdevice_ble/src/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -MODULE = nordic_softdevice_ble -include $(RIOTBASE)/Makefile.base diff --git a/pkg/nordic_softdevice_ble/src/app_error.c b/pkg/nordic_softdevice_ble/src/app_error.c deleted file mode 100644 index 31e881e5c4..0000000000 --- a/pkg/nordic_softdevice_ble/src/app_error.c +++ /dev/null @@ -1,9 +0,0 @@ -#include "app_error.h" - -#define ENABLE_DEBUG 0 -#include "debug.h" - -void app_error_handler(uint32_t error_code, uint32_t line_num, const uint8_t *p_file_name) -{ - puts("nordic softdevice app_error_handler()"); -} diff --git a/pkg/nordic_softdevice_ble/src/ble-core.c b/pkg/nordic_softdevice_ble/src/ble-core.c deleted file mode 100644 index 8b4a28ef7e..0000000000 --- a/pkg/nordic_softdevice_ble/src/ble-core.c +++ /dev/null @@ -1,240 +0,0 @@ -/* - * Copyright (c) 2016, Nordic Semiconductor - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - */ -/** - * @addtogroup cpu - * @{ - * - * @addtogroup nrf52832 - * @{ - * - * @addtogroup nrf52832-ble Bluetooth Low Energy drivers - * @{ - * - * @file - * Basic BLE functions. - * @author - * Wojciech Bober - * Kaspar Schleiser - * - */ -#include -#include -#include - -//#include "boards.h" -//#include "nordic_common.h" -//#include "nrf_delay.h" -#include "nrf_sdm.h" -#include "ble_advdata.h" -#include "ble_srv_common.h" -#include "ble_ipsp.h" -#include "softdevice_handler.h" -#include "app_error.h" -#include "iot_defines.h" -#include "ble-core.h" - -#define ENABLE_DEBUG 0 -#include "debug.h" - -#define IS_SRVC_CHANGED_CHARACT_PRESENT 1 -#define APP_ADV_TIMEOUT 0 /**< Time for which the device must be advertising in non-connectable mode (in seconds). 0 disables timeout. */ -#define APP_ADV_ADV_INTERVAL MSEC_TO_UNITS(333, UNIT_0_625_MS) /**< The advertising interval. This value can vary between 100ms to 10.24s). */ - -static ble_gap_adv_params_t m_adv_params; /**< Parameters to be passed to the stack when starting advertising. */ - -static void -ble_evt_dispatch(ble_evt_t * p_ble_evt); -/*---------------------------------------------------------------------------*/ -/** - * @brief Initialize and enable the BLE stack. - */ -void -ble_stack_init(void) -{ - uint32_t err_code; - - // Enable BLE stack. - ble_enable_params_t ble_enable_params; - memset(&ble_enable_params, 0, sizeof(ble_enable_params)); - ble_enable_params.gatts_enable_params.attr_tab_size = - BLE_GATTS_ATTR_TAB_SIZE_DEFAULT; - ble_enable_params.gatts_enable_params.service_changed = - IS_SRVC_CHANGED_CHARACT_PRESENT; - err_code = sd_ble_enable(&ble_enable_params); - APP_ERROR_CHECK(err_code); - - // Register with the SoftDevice handler module for BLE events. - err_code = softdevice_ble_evt_handler_set(ble_evt_dispatch); - APP_ERROR_CHECK(err_code); - - // Setup address - ble_gap_addr_t ble_addr; - err_code = sd_ble_gap_address_get(&ble_addr); - APP_ERROR_CHECK(err_code); - - ble_addr.addr[5] = 0x00; - ble_addr.addr_type = BLE_GAP_ADDR_TYPE_PUBLIC; - - err_code = sd_ble_gap_address_set(BLE_GAP_ADDR_CYCLE_MODE_NONE, &ble_addr); - APP_ERROR_CHECK(err_code); -} -/*---------------------------------------------------------------------------*/ -/** - * @brief Return device EUI64 MAC address - * @param addr pointer to a buffer to store the address - */ -#include "ble-mac.h" -void -ble_get_mac(uint8_t addr[6]) -{ - uint32_t err_code; - ble_gap_addr_t ble_addr; - - err_code = sd_ble_gap_address_get(&ble_addr); - APP_ERROR_CHECK(err_code); - - ble_eui48(addr, ble_addr.addr, - ble_addr.addr_type == BLE_GAP_ADDR_TYPE_PUBLIC); -} -/*---------------------------------------------------------------------------*/ -/** - * @brief Initialize BLE advertising data. - * @param name Human readable device name that will be advertised - */ -void -ble_advertising_init(const char *name) -{ - uint32_t err_code; - ble_advdata_t advdata; - uint8_t flags = BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED; - ble_gap_conn_sec_mode_t sec_mode; - - BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode); - - err_code = sd_ble_gap_device_name_set(&sec_mode, (const uint8_t *)name, - strlen(name)); - APP_ERROR_CHECK(err_code); - - ble_uuid_t adv_uuids[] = {{BLE_UUID_IPSP_SERVICE, BLE_UUID_TYPE_BLE}}; - - // Build and set advertising data. - memset(&advdata, 0, sizeof(advdata)); - - advdata.name_type = BLE_ADVDATA_FULL_NAME; - advdata.flags = flags; - advdata.uuids_complete.uuid_cnt = ARRAY_SIZE(adv_uuids); - advdata.uuids_complete.p_uuids = adv_uuids; - - err_code = ble_advdata_set(&advdata, NULL); - APP_ERROR_CHECK(err_code); - - // Initialize advertising parameters (used when starting advertising). - memset(&m_adv_params, 0, sizeof(m_adv_params)); - - m_adv_params.type = BLE_GAP_ADV_TYPE_ADV_IND; - m_adv_params.p_peer_addr = NULL; // Undirected advertisement. - m_adv_params.fp = BLE_GAP_ADV_FP_ANY; - m_adv_params.interval = APP_ADV_ADV_INTERVAL; - m_adv_params.timeout = APP_ADV_TIMEOUT; -} -/*---------------------------------------------------------------------------*/ -/** - * @brief Start BLE advertising. - */ -void -ble_advertising_start(void) -{ - uint32_t err_code; - - err_code = sd_ble_gap_adv_start(&m_adv_params); - APP_ERROR_CHECK(err_code); - - DEBUG("ble-core: advertising started\n"); -} -/*---------------------------------------------------------------------------*/ -/** - * @brief Print GAP address. - * @param addr a pointer to address - */ -void -ble_gap_addr_print(const ble_gap_addr_t *addr) -{ - unsigned int i; - for(i = 0; i < sizeof(addr->addr); i++) { - if (i > 0) { - DEBUG(":"); - } - DEBUG("%02x", addr->addr[i]); - } - DEBUG(" (%d)\n", addr->addr_type); -} -/*---------------------------------------------------------------------------*/ -/** - * @brief Function for handling the Application's BLE Stack events. - * @param[in] p_ble_evt Bluetooth stack event. - */ -static void -on_ble_evt(ble_evt_t *p_ble_evt) -{ - switch(p_ble_evt->header.evt_id) { - case BLE_GAP_EVT_CONNECTED: - DEBUG("ble-core: connected [handle:%d, peer: ", p_ble_evt->evt.gap_evt.conn_handle); - ble_gap_addr_print(&(p_ble_evt->evt.gap_evt.params.connected.peer_addr)); - DEBUG("]\n"); - sd_ble_gap_rssi_start(p_ble_evt->evt.gap_evt.conn_handle, - BLE_GAP_RSSI_THRESHOLD_INVALID, - 0); - break; - - case BLE_GAP_EVT_DISCONNECTED: - DEBUG("ble-core: disconnected [handle:%d]\n", p_ble_evt->evt.gap_evt.conn_handle); - ble_advertising_start(); - break; - default: - break; - } -} -/*---------------------------------------------------------------------------*/ -/** - * @brief SoftDevice BLE event callback. - * @param[in] p_ble_evt Bluetooth stack event. - */ -static void -ble_evt_dispatch(ble_evt_t *p_ble_evt) -{ - ble_ipsp_evt_handler(p_ble_evt); - on_ble_evt(p_ble_evt); -} -/*---------------------------------------------------------------------------*/ -/** - * @} - * @} - * @} - */ diff --git a/pkg/nordic_softdevice_ble/src/ble-core.h b/pkg/nordic_softdevice_ble/src/ble-core.h deleted file mode 100644 index e72cd5d799..0000000000 --- a/pkg/nordic_softdevice_ble/src/ble-core.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2015, Nordic Semiconductor - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - */ -/** - * @addtogroup cpu - * @{ - * - * @addtogroup nrf52832 - * @{ - * - * @addtogroup nrf52832-ble Bluetooth Low Energy drivers - * @{ - * - * @file - * - * @brief Basic BLE functions. - * - * @author Wojciech Bober - */ -#ifndef BLE_CORE_H -#define BLE_CORE_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Initialize and enable the BLE stack. - */ -void ble_stack_init(void); - -/** - * @brief Initialize BLE advertising data. - * - * @param name Human readable device name that will be advertised - */ -void ble_advertising_init(const char *name); - -/** - * @brief Start BLE advertising. - */ -void ble_advertising_start(void); - -/** - * @brief Return device MAC address - * - * @param addr pointer to a buffer to store the address - */ -void ble_get_mac(uint8_t addr[6]); - -#ifdef __cplusplus -} -#endif - -#endif /* BLE_CORE_H */ - -/** - * @} - * @} - * @} - */ diff --git a/pkg/nordic_softdevice_ble/src/ble-mac.c b/pkg/nordic_softdevice_ble/src/ble-mac.c deleted file mode 100644 index 4139aa1284..0000000000 --- a/pkg/nordic_softdevice_ble/src/ble-mac.c +++ /dev/null @@ -1,306 +0,0 @@ -/* - * Copyright (c) 2016, Nordic Semiconductor - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - */ - -#include -#include -#include - -#define DONT_OVERRIDE_NVIC - -#include "ble-core.h" -#include "ble_ipsp.h" -#include "ble_gap.h" - -#include "ble-mac.h" - -#define ENABLE_DEBUG 0 -#include "debug.h" - -#if defined(MODULE_OD) && ENABLE_DEBUG -#include "od.h" -#endif - -#ifndef BLE_MAC_MAX_INTERFACE_NUM -#define BLE_MAC_MAX_INTERFACE_NUM (1U) /**< Maximum number of interfaces, i.e., - connection to master devices */ -#endif - -typedef struct { - uint8_t peer_addr[BLE_L2_ADDR_LEN]; - ble_ipsp_handle_t handle; -} ble_mac_interface_t; - -static ble_mac_interface_t interfaces[BLE_MAC_MAX_INTERFACE_NUM]; - -volatile int ble_mac_busy_tx; -volatile int ble_mac_busy_rx; - -static ble_mac_inbuf_t inbuf; -static ble_mac_callback_t _callback; - -/** - * @brief Lookup interface by IPSP connection. - * - * @param[in] handle a pointer to IPSP handle. - * @return a pointer to interface structure - * @return NULL if no interface has been found for a given handle - */ -static ble_mac_interface_t *ble_mac_interface_lookup(ble_ipsp_handle_t *handle) -{ - if (handle == NULL) { - return NULL; - } - for (int i = 0; i < BLE_MAC_MAX_INTERFACE_NUM; i++) { - if (interfaces[i].handle.conn_handle == handle->conn_handle && - interfaces[i].handle.cid == handle->cid) { - return &interfaces[i]; - } - } - return NULL; -} - -/** - * @brief Add IPSP connection to the interface table. - * - * This function binds IPSP connection with peer address. - * - * @param[in] peer a pointer to eui64 address - * @param[in] handle a pointer to IPSP handle - * - * @return a pointer to an interface structure on success - * @return NULL if interface table is full - */ -static ble_mac_interface_t *ble_mac_interface_add(uint8_t peer[BLE_L2_ADDR_LEN], - ble_ipsp_handle_t *handle) -{ - DEBUG("ble_mac_interface_add()\n"); - for (int i = 0; i < BLE_MAC_MAX_INTERFACE_NUM; i++) { - if (interfaces[i].handle.conn_handle == 0 && interfaces[i].handle.cid == 0) { - memcpy(&interfaces[i].handle, handle, sizeof(ble_ipsp_handle_t)); - memcpy(&interfaces[i].peer_addr, peer, BLE_L2_ADDR_LEN); - - /* notify handler thread */ - /* msg_t m = { .type = BLE_IFACE_ADDED, .content.ptr = &interfaces[i] }; */ - /* msg_send(&m, gnrc_nordic_ble_6lowpan_pid); */ - - return &interfaces[i]; - } - } - return NULL; -} - -/** - * @brief Remove interface from the interface table. - * @param[in] interface a pointer to interface - */ -static void ble_mac_interface_delete(ble_mac_interface_t *interface) -{ - DEBUG("ble_mac_interface_delete()\n"); - memset(interface, 0, sizeof(ble_mac_interface_t)); -} - -/** - * @brief Lookup IPSP handle by peer address. - * - * @param[in] addr a pointer to eui64 address. - * @retval a pointer to IPSP handle on success - * @retval NULL if an IPSP handle for given address haven't been found - */ -static ble_ipsp_handle_t *_find_handle(const uint8_t *addr) -{ - for (int i = 0; i < BLE_MAC_MAX_INTERFACE_NUM; i++) { - if (memcmp(interfaces[i].peer_addr, addr, BLE_L2_ADDR_LEN) == 0) { - return &interfaces[i].handle; - } - } - return NULL; -} - -/** - * @brief Send packet on a given IPSP handle. - * - * @param[in] handle a pointer to IPSP handle. - * @return 1 on success, 0 otherwise - */ -static int _send_to_peer(ble_ipsp_handle_t *handle, void *data, size_t len) -{ - DEBUG("ble-mac: sending packet[GAP handle:%d CID:0x%04X]\n", - handle->conn_handle, handle->cid); - return ble_ipsp_send(handle, data, len); -} - -static int _is_broadcast(uint8_t dest[BLE_L2_ADDR_LEN]) -{ - uint32_t *_dest = (uint32_t*)dest; - for (int i = 0; i < 2; i++) { - if (_dest[i]) { - return 0; - } - } - return 1; -} - -int ble_mac_send(uint8_t dest[BLE_L2_ADDR_LEN], void *data, size_t len) -{ - DEBUG("ble_mac_send(): sending pkt with len %u\n", (unsigned)len); - -#if defined(MODULE_OD) && ENABLE_DEBUG - od_hex_dump(dest, BLE_L2_ADDR_LEN, OD_WIDTH_DEFAULT); - od_hex_dump(data, len, OD_WIDTH_DEFAULT); -#endif - - ble_ipsp_handle_t *handle; - int ret = -1; - - if ((!dest) || _is_broadcast(dest)) { - DEBUG("broadcast\n"); - for (int i = 0; i < BLE_MAC_MAX_INTERFACE_NUM; i++) { - if (interfaces[i].handle.cid != 0 && interfaces[i].handle.conn_handle != 0) { - ret = _send_to_peer(&interfaces[i].handle, data, len); - DEBUG("ret=%i\n", ret); - } - } - } - else if ((handle = _find_handle(dest)) != NULL) { - DEBUG("unicast\n"); - ret = _send_to_peer(handle, data, len); - } - else { - DEBUG("ble-mac: no connection found for peer\n"); - } - - if (ret == NRF_SUCCESS) { - ble_mac_busy_tx = 1; - return 0; - } - else { - DEBUG("ble-mac: send error: %i\n", ret); - return -1; - } -} - -static uint32_t ble_mac_ipsp_evt_handler_irq(ble_ipsp_handle_t *p_handle, ble_ipsp_evt_t *p_evt) -{ - uint32_t retval = NRF_SUCCESS; - - ble_mac_interface_t *p_instance = ble_mac_interface_lookup(p_handle); - - if (p_handle) { - DEBUG("ble-mac: IPSP event [handle:%d CID 0x%04X]\n", p_handle->conn_handle, p_handle->cid); - } - - switch (p_evt->evt_id) { - case BLE_IPSP_EVT_CHANNEL_CONNECTED: { - uint8_t peer_addr[BLE_L2_ADDR_LEN]; - - DEBUG("ble-mac: channel connected\n"); - ble_eui48(peer_addr, - p_evt->evt_param->params.ch_conn_request.peer_addr.addr, - p_evt->evt_param->params.ch_conn_request.peer_addr.addr_type == - BLE_GAP_ADDR_TYPE_PUBLIC); - p_instance = ble_mac_interface_add(peer_addr, p_handle); - - if (p_instance != NULL) { - DEBUG("ble-mac: added new IPSP interface\n"); - } - else { - DEBUG("ble-mac: cannot add new interface. Table is full\n"); - ble_ipsp_disconnect(p_handle); - } - break; - } - - case BLE_IPSP_EVT_CHANNEL_DISCONNECTED: { - DEBUG("ble-mac: channel disconnected\n"); - if (p_instance != NULL) { - DEBUG("ble-mac: removed IPSP interface\n"); - ble_mac_interface_delete(p_instance); - } - break; - } - - case BLE_IPSP_EVT_CHANNEL_DATA_RX: { - DEBUG("ble-mac: data received\n"); - if (p_instance != NULL) { - if (ble_mac_busy_rx) { - DEBUG("ble-mac: packet dropped as input buffer is busy\n"); - break; - } - - if (p_evt->evt_param->params.ch_rx.len > BLE_SIXLOWPAN_MTU) { - DEBUG("ble-mac: packet buffer is too small!\n"); - break; - } - - ble_mac_busy_rx = 1; - - inbuf.len = p_evt->evt_param->params.ch_rx.len; - memcpy(inbuf.payload, p_evt->evt_param->params.ch_rx.p_data, inbuf.len); - memcpy(inbuf.src, p_instance->peer_addr, BLE_L2_ADDR_LEN); - sd_ble_gap_rssi_get(p_handle->conn_handle, &inbuf.rssi); - - _callback(BLE_EVENT_RX_DONE, &inbuf); - } - else { - DEBUG("ble-mac: got data to unknown interface!\n"); - } - break; - } - - case BLE_IPSP_EVT_CHANNEL_DATA_TX_COMPLETE: { - DEBUG("ble-mac: data transmitted\n"); - ble_mac_busy_tx = 0; - //_callback(BLE_EVENT_TX_DONE, NULL); - break; - } - } - - if (sched_context_switch_request) { - NVIC_SetPendingIRQ( SWI0_EGU0_IRQn ); - } - - return retval; -} - -void ble_mac_init(ble_mac_callback_t callback) -{ - assert(callback); - - uint32_t res; - ble_ipsp_init_t ipsp_init_params = { - .evt_handler = ble_mac_ipsp_evt_handler_irq - }; - - _callback = callback; - - res = ble_ipsp_init(&ipsp_init_params); - DEBUG("ble_ipsp_init() res = %" PRIu32 "\n", res); - (void)res; -} diff --git a/pkg/nordic_softdevice_ble/src/ble-mac.h b/pkg/nordic_softdevice_ble/src/ble-mac.h deleted file mode 100644 index ed120d4a98..0000000000 --- a/pkg/nordic_softdevice_ble/src/ble-mac.h +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (c) 2016, Nordic Semiconductor - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - */ - -/** - * @ingroup pkg_nordic-softdevice-ble - * @brief Public API and definitions of Nordic Softdevice BLE - * @{ - * - * @file - */ - - -#ifndef BLE_MAC_H -#define BLE_MAC_H - -#ifdef __cplusplus -extern "C" { -#endif - -typedef enum { - BLE_EVENT_RX_DONE = 20000, -} ble_mac_event_enum_t; - -#define BLE_IFACE_ADDED (10000) - -#define BLE_SIXLOWPAN_MTU (1280U) -#define BLE_L2_ADDR_LEN (6U) - -#ifndef IPV6_IID_FLIP_VALUE -#define IPV6_IID_FLIP_VALUE (0x02) -#endif - -/** - * @brief Get BLE EUI64 from EUI48 - * - * @param[out] eui48 The output EUI48 (big-endian, - * 6 bytes long) - * @param[in] ble_addr The input BLE address (little-endian, - * 6 bytes long) - * @param[in] _public True if public interface, false otherwise - */ -static inline void ble_eui48(uint8_t *eui48, const uint8_t *ble_addr, int _public) -{ - eui48[0] = ble_addr[5]; - eui48[1] = ble_addr[4]; - eui48[2] = ble_addr[3]; - eui48[3] = ble_addr[2]; - eui48[4] = ble_addr[1]; - eui48[5] = ble_addr[0]; - if (_public) { - eui48[0] &= ~(IPV6_IID_FLIP_VALUE); - } - else { - eui48[0] |= IPV6_IID_FLIP_VALUE; - } -} - -/** - * @brief Structure handling a received BLE mac packet - */ -typedef struct { - uint8_t payload[BLE_SIXLOWPAN_MTU]; /**< Payload of the packet */ - uint8_t src[BLE_L2_ADDR_LEN]; /**< Source address of the packet */ - uint16_t len; /**< Length of the packet */ - int8_t rssi; /**< RSSI of the received packet */ -} ble_mac_inbuf_t; - -/** - * @brief Mac event callback function definition - */ -typedef void (*ble_mac_callback_t)(ble_mac_event_enum_t event, void*arg); - -/** - * @brief Initialize the BLE mac - * - * @param[in] callback The callback function triggered on mac event - */ -void ble_mac_init(ble_mac_callback_t callback); - -/** - * @brief Send a BLE message - * - * @param[in] dest The destination address - * @param[in] data The data to send - * @param[in] len The length of the data to send - * - * @return 0 if send is successful - * @return <0 if send failed - */ -int ble_mac_send(uint8_t dest[BLE_L2_ADDR_LEN], void *data, - size_t len); - -extern volatile int ble_mac_busy_tx; /**< Flag is set to 1 when the driver - is busy transmitting a packet. */ -extern volatile int ble_mac_busy_rx; /**< Flag is set to 1 when there is a - received packet pending. */ - -#ifdef __cplusplus -} -#endif - -#endif /* BLE_MAC_H */ -/** @} */ diff --git a/pkg/nordic_softdevice_ble/src/gnrc_nordic_ble_6lowpan.c b/pkg/nordic_softdevice_ble/src/gnrc_nordic_ble_6lowpan.c deleted file mode 100644 index b23d6d2844..0000000000 --- a/pkg/nordic_softdevice_ble/src/gnrc_nordic_ble_6lowpan.c +++ /dev/null @@ -1,283 +0,0 @@ -/* - * Copyright (c) 2016, Nordic Semiconductor - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - */ - -/** - * @{ - * @ingroup net - * @file - * @brief Glue for Nordic's SoftDevice BLE 6lowpan blob to netapi - * - * @author Kaspar Schleiser - * @author Martine Lenders - * @} - */ - -#include -#include - -#include "msg.h" -#include "thread.h" - -#include "net/eui48.h" -#include "net/gnrc.h" -#include "net/gnrc/netif.h" -#include "net/gnrc/nettype.h" - -#include "ble-core.h" -#include "softdevice_handler.h" - -#include "ble-mac.h" - -#define ENABLE_DEBUG 0 -#include "debug.h" - -#if defined(MODULE_OD) && ENABLE_DEBUG -#include "od.h" -#endif - -#define BLE_PRIO (GNRC_NETIF_PRIO) - -/* XXX: netdev required by gnrc_netif, but not implemented fully for - * nordic_softdevice_ble for legacy reasons */ - -static char _stack[(THREAD_STACKSIZE_DEFAULT + DEBUG_EXTRA_STACKSIZE)]; - -static gnrc_netif_t *_ble_netif = NULL; -static gnrc_netif_t _netif; - -static uint8_t _sendbuf[BLE_SIXLOWPAN_MTU]; - -static void _ble_mac_callback(ble_mac_event_enum_t event, void* arg) -{ - msg_t m = { .type=event, .content.ptr=arg }; - - if ((_ble_netif == NULL) || !msg_send_int(&m, _ble_netif->pid)) { - puts("_ble_mac_callback(): possibly lost interrupt"); - } -} - -static void _handle_raw_sixlowpan(ble_mac_inbuf_t *inbuf) -{ - gnrc_pktsnip_t *pkt = gnrc_pktbuf_add(NULL, inbuf->payload, - inbuf->len, - GNRC_NETTYPE_SIXLOWPAN); - - if(!pkt) { - DEBUG("_handle_raw_sixlowpan(): no space left in packet buffer.\n"); - return; - } - - /* create netif header */ - gnrc_pktsnip_t *netif_hdr; - netif_hdr = gnrc_pktbuf_add(NULL, NULL, - sizeof(gnrc_netif_hdr_t) + (2 * sizeof(eui64_t)), - GNRC_NETTYPE_NETIF); - - if (netif_hdr == NULL) { - DEBUG("_handle_raw_sixlowpan(): no space left in packet buffer.\n"); - gnrc_pktbuf_release(pkt); - return; - } - - gnrc_netif_hdr_init(netif_hdr->data, BLE_L2_ADDR_LEN, BLE_L2_ADDR_LEN); - gnrc_netif_hdr_set_src_addr(netif_hdr->data, inbuf->src, BLE_L2_ADDR_LEN); - gnrc_netif_hdr_set_dst_addr(netif_hdr->data, _ble_netif->l2addr, BLE_L2_ADDR_LEN); - gnrc_netif_hdr_set_netif(netif_hdr->data, _ble_netif); - - DEBUG("_handle_raw_sixlowpan(): received packet from %02x:%02x:%02x:%02x:%02x:%02x " - "of length %d\n", - inbuf->src[0], inbuf->src[1], inbuf->src[2], - inbuf->src[3], inbuf->src[4], inbuf->src[5], inbuf->len); -#if defined(MODULE_OD) && ENABLE_DEBUG - od_hex_dump(inbuf->payload, inbuf->len, OD_WIDTH_DEFAULT); -#endif - - pkt = gnrc_pkt_append(pkt, netif_hdr); - - /* throw away packet if no one is interested */ - if (!gnrc_netapi_dispatch_receive(pkt->type, GNRC_NETREG_DEMUX_CTX_ALL, pkt)) { - DEBUG("_handle_raw_sixlowpan: unable to forward packet of type %i\n", pkt->type); - gnrc_pktbuf_release(pkt); - } -} - -static int _send(gnrc_pktsnip_t *pkt) -{ - if (pkt == NULL) { - DEBUG("_send_ble: pkt was NULL\n"); - return -EINVAL; - } - - gnrc_netif_hdr_t *netif_hdr; - gnrc_pktsnip_t *payload = pkt->next; - uint8_t *dst; - - if (ble_mac_busy_tx) { - DEBUG("_send(): ble_mac_busy_tx\n"); - return -EBUSY; - } - - uint8_t *buf = _sendbuf; - unsigned len = 0; - - if (pkt->type != GNRC_NETTYPE_NETIF) { - DEBUG("_send_ble: first header is not generic netif header\n"); - return -EBADMSG; - } - - netif_hdr = pkt->data; - - /* prepare destination address */ - if (netif_hdr->flags & - (GNRC_NETIF_HDR_FLAGS_BROADCAST | GNRC_NETIF_HDR_FLAGS_MULTICAST)) { - dst = NULL; - } - else { - dst = gnrc_netif_hdr_get_dst_addr(netif_hdr); - } - - /* prepare packet for sending */ - while (payload) { - memcpy(buf, payload->data, payload->size); - len += payload->size; - buf += payload->size; - payload = payload->next; - } - - gnrc_pktbuf_release(pkt); - - if (ble_mac_send(dst, _sendbuf, len) == -1) { - return -EBADMSG; - } - - return 0; -} - -static int _netdev_init(netdev_t *dev) -{ - _ble_netif = dev->context; - ble_stack_init(); - ble_mac_init(_ble_mac_callback); - _ble_netif->l2addr_len = BLE_L2_ADDR_LEN; - ble_get_mac(_ble_netif->l2addr); - ble_advertising_init("RIOT BLE"); - ble_advertising_start(); - return 0; -} - -static int _netdev_get(netdev_t *netdev, netopt_t opt, - void *v, size_t max_len) -{ - int res = -ENOTSUP; - uint8_t *value = v; - - (void)netdev; - switch (opt) { - case NETOPT_ADDRESS: - assert(max_len >= BLE_L2_ADDR_LEN); - memcpy(value, _ble_netif->l2addr, BLE_L2_ADDR_LEN); - res = BLE_L2_ADDR_LEN; - break; - case NETOPT_ADDR_LEN: - case NETOPT_SRC_LEN: - assert(max_len == sizeof(uint16_t)); - *((uint16_t *)value) = BLE_L2_ADDR_LEN; - res = sizeof(uint16_t); - break; - case NETOPT_PROTO: - assert(max_len == sizeof(gnrc_nettype_t)); - *((gnrc_nettype_t *)value) = GNRC_NETTYPE_SIXLOWPAN; - res = sizeof(gnrc_nettype_t); - break; - case NETOPT_DEVICE_TYPE: - assert(max_len == sizeof(uint16_t)); - *((uint16_t *)value) = NETDEV_TYPE_BLE; - res = sizeof(uint16_t); - break; - default: - break; - } - return res; -} - -static int _netif_send(gnrc_netif_t *netif, gnrc_pktsnip_t *pkt) -{ - (void)netif; - assert(netif == _ble_netif); - return _send(pkt); -} - -static gnrc_pktsnip_t *_netif_recv(gnrc_netif_t *netif) -{ - (void)netif; - /* not supported */ - return NULL; -} - -static void _netif_msg_handler(gnrc_netif_t *netif, msg_t *msg) -{ - switch (msg->type) { - case BLE_EVENT_RX_DONE: - { - DEBUG("ble rx:\n"); - _handle_raw_sixlowpan(msg->content.ptr); - ble_mac_busy_rx = 0; - break; - } - } -} - -static const gnrc_netif_ops_t _ble_ops = { - .init = gnrc_netif_default_init, - .send = _netif_send, - .recv = _netif_recv, - .get = gnrc_netif_get_from_netdev, - .set = gnrc_netif_set_from_netdev, - .msg_handler = _netif_msg_handler, -}; - -static const netdev_driver_t _ble_netdev_driver = { - .send = NULL, - .recv = NULL, - .init = _netdev_init, - .isr = NULL, - .get = _netdev_get, - .set = netdev_set_notsup, -}; - -static netdev_t _ble_dummy_dev = { - .driver = &_ble_netdev_driver, -}; - -void gnrc_nordic_ble_6lowpan_init(void) -{ - gnrc_netif_create(&_netif, _stack, sizeof(_stack), BLE_PRIO, - "ble", &_ble_dummy_dev, &_ble_ops); -} diff --git a/pkg/nordic_softdevice_ble/src/gnrc_nordic_ble_6lowpan.h b/pkg/nordic_softdevice_ble/src/gnrc_nordic_ble_6lowpan.h deleted file mode 100644 index 27dde2fd1a..0000000000 --- a/pkg/nordic_softdevice_ble/src/gnrc_nordic_ble_6lowpan.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2016, Nordic Semiconductor - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - */ -#ifndef GNRC_NORDIC_BLE_6LOWPAN_H -#define GNRC_NORDIC_BLE_6LOWPAN_H - -#ifdef __cplusplus -extern "C" { -#endif - -void gnrc_nordic_ble_6lowpan_init(void); - -#ifdef __cplusplus -} -#endif - -#endif /* GNRC_NORDIC_BLE_6LOWPAN_H */