BLE L2CAP moved to the other MAC implementations

This commit is contained in:
spoerk 2018-01-03 14:36:14 +01:00
parent 5a28133452
commit 35c08597e6
16 changed files with 199 additions and 113 deletions

View File

@ -86,7 +86,8 @@ endif
MAKE_MAC_NULLMAC = 0
MAKE_MAC_CSMA = 1
MAKE_MAC_TSCH = 2
MAKE_MAC_OTHER = 3
MAKE_MAC_BLE = 3
MAKE_MAC_OTHER = 4
# Make CSMA the default MAC
MAKE_MAC ?= MAKE_MAC_CSMA
@ -106,6 +107,11 @@ ifeq ($(MAKE_MAC),MAKE_MAC_TSCH)
CFLAGS += -DMAC_CONF_WITH_TSCH=1
endif
ifeq ($(MAKE_MAC),MAKE_MAC_BLE)
MODULES += os/net/mac/ble
CFLAGS += -DMAC_CONF_WITH_BLE=1
endif
ifeq ($(MAKE_MAC),MAKE_MAC_OTHER)
CFLAGS += -DMAC_CONF_WITH_OTHER=1
endif

View File

@ -35,7 +35,6 @@ CONTIKI_CPU_SOURCEFILES += slip-arch.c slip.c cc26xx-uart.c lpm.c
CONTIKI_CPU_SOURCEFILES += gpio-interrupt.c oscillators.c
CONTIKI_CPU_SOURCEFILES += rf-core.c rf-ble.c ieee-mode.c
CONTIKI_CPU_SOURCEFILES += ble-cc2650.c ble-hal-cc26xx.c ble-addr.c rf-ble-cmd.c
CONTIKI_CPU_SOURCEFILES += ble-l2cap.c
CONTIKI_CPU_SOURCEFILES += random.c soc-trng.c int-master.c
DEBUG_IO_SOURCEFILES += dbg-printf.c dbg-snprintf.c dbg-sprintf.c strformat.c

View File

@ -27,16 +27,21 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Author: Michael Spoerk <mi.spoerk@gmail.com>
*/
/**
* \file
* Driver for the retrieval of an BLE address from flash
*
* \author
* Michael Spoerk <mi.spoerk@gmail.com>
*/
/*---------------------------------------------------------------------------*/
#include "../ble-addr.h"
#include "contiki-conf.h"
#include "net/linkaddr.h"
#include <string.h>
#include "ble-addr.h"
#include "os/dev/ble-hal.h"
/*---------------------------------------------------------------------------*/
void
ble_addr_cpy_to(uint8_t *dst)

View File

@ -27,8 +27,13 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Author: Michael Spoerk <mi.spoerk@gmail.com>
*/
/**
* \file
* Driver for the retrieval of an BLE address from flash
*
* \author
* Michael Spoerk <mi.spoerk@gmail.com>
*/
/*---------------------------------------------------------------------------*/
#ifndef BLE_ADDR_H_
@ -40,21 +45,35 @@
/* primary BLE address location */
#define BLE_ADDR_LOCATION 0x500012E8
/* BLE device address size */
#define BLE_ADDR_SIZE 6
/*---------------------------------------------------------------------------*/
/* Type of BLE device address */
typedef enum {
BLE_ADDR_TYPE_PUBLIC,
BLE_ADDR_TYPE_RANDOM
} ble_addr_type_t;
/*---------------------------------------------------------------------------*/
/**
* \brief Copy the node's factory BLE address to a destination memory area
* \param dst A pointer to the destination area where the BLE address is to be
* written
*
* This function will copy 6 bytes and it will invert byte order in
* the process. The factory address on devices is normally little-endian,
* therefore you should expect dst to store the address in a big-endian order.
*/
void ble_addr_cpy_to(uint8_t *dst);
/*---------------------------------------------------------------------------*/
/**
* \brief Copy the node's BLE address to a destination memory area and converts
* it into a EUI64 address in the process
* \param dst A pointer to the destination area where the EUI64 address is to be
* written
* \param src A pointer to the BLE address that is to be copied
*/
void ble_addr_to_eui64(uint8_t *dst, uint8_t *src);
/*---------------------------------------------------------------------------*/
/**
* \brief Copy the node's EUI64 address that is based on its factory BLE address
* to a destination memory area
* \param dst A pointer to the destination area where the EUI64 address is to be
* written
*/
void ble_eui64_addr_cpy_to(uint8_t *dst);
/*---------------------------------------------------------------------------*/

View File

@ -50,7 +50,6 @@ To enable IPv6 over BLE, the project conf needs to contain:
#define QUEUEBUF_CONF_NUM 1
#define UIP_CONF_BUFFER_SIZE 1280
#define CC26XX_CONF_RADIO_MODE CC26XX_RADIO_MODE_BLE
#define NETSTACK_CONF_RADIO ble_cc2650_driver
#define NETSTACK_CONF_MAC ble_l2cap_driver

View File

@ -36,11 +36,10 @@
* Michael Spoerk <michael.spoerk@tugraz.at>
*/
/*---------------------------------------------------------------------------*/
#include <ble-hal.h>
#include <rf-core/ble-hal/ble-hal-cc26xx.h>
#include "contiki.h"
#include "dev/radio.h"
#include "os/dev/ble-hal.h"
#include "rf-core/ble-hal/ble-hal-cc26xx.h"
/*---------------------------------------------------------------------------*/
#include "sys/log.h"
#define LOG_MODULE "RADIO"

View File

@ -36,13 +36,13 @@
* Michael Spoerk <michael.spoerk@tugraz.at>
*/
/*---------------------------------------------------------------------------*/
#include "ble-hal.h"
#include "rf-core/ble-hal/rf-ble-cmd.h"
#include "lpm.h"
#include "sys/rtimer.h"
#include "sys/process.h"
#include "os/dev/ble-hal.h"
#include "dev/oscillators.h"
#include "ble-addr.h"
@ -62,6 +62,7 @@
#include <string.h>
#include "rf-core/ble-hal/rf-ble-cmd.h"
/*---------------------------------------------------------------------------*/
#include "sys/log.h"
#define LOG_MODULE "BLE-RADIO"

View File

@ -40,7 +40,7 @@
#ifndef BLE_HAL_CC26XX_H_
#define BLE_HAL_CC26XX_H_
#include "ble-hal.h"
#include "os/dev/ble-hal.h"
extern const struct ble_hal_driver ble_hal;

View File

@ -40,8 +40,8 @@
#ifndef RF_BLE_CMD_H_
#define RF_BLE_CMD_H_
#include "os/dev/ble-hal.h"
#include "../../ble-addr.h"
#include "ble-hal.h"
#include "rf_common_cmd.h"
#define RF_BLE_CMD_OK 1

View File

@ -6,5 +6,7 @@ all: $(CONTIKI_PROJECT)
upload:
srfprog -t 'soc(XDS-L1000130)' -e all -p 'epfw(0)' -v rb -f $(CONTIKI_PROJECT).hex -a 0x0
MAKE_MAC = MAKE_MAC_BLE
MAKE_NET = MAKE_NET_IPV6
CONTIKI = ../../..
include $(CONTIKI)/Makefile.include

View File

@ -42,10 +42,10 @@
#include "net/ipv6/uip-icmp6.h"
#include "ble-hal.h"
#include <string.h>
#include <stdio.h>
#include "os/dev/ble-hal.h"
/*---------------------------------------------------------------------------*/
//#define SERVER_IP "::"
#define SERVER_IP "fe80::ba27:ebff:fe40:9b06"

View File

@ -47,10 +47,7 @@
#define QUEUEBUF_CONF_NUM 1
#define UIP_CONF_BUFFER_SIZE 1280
#define CC26XX_CONF_RADIO_MODE RADIO_MODE_BLE
#define NETSTACK_CONF_RADIO ble_cc2650_driver
#define MAKE_MAC MAKE_MAC_OTHER
#define NETSTACK_CONF_MAC ble_l2cap_driver
#define LOG_CONF_LEVEL_MAC LOG_LEVEL_INFO
#define LOG_CONF_LEVEL_6LOWPAN LOG_LEVEL_WARN
@ -61,9 +58,6 @@
#define BLE_CONF_DEVICE_NAME "TI CC26xx device"
#define BLE_CONF_ADV_INTERVAL 25
#define MAKE_NET MAKE_NET_IPV6
#define MAKE_ROUTING MAKE_ROUTING_NONE
/*/ * 6LoWPAN settings * / */
#define SICSLOWPAN_CONF_MAC_MAX_PAYLOAD 1280
#define SICSLOWPAN_CONF_COMPRESSION SICSLOWPAN_COMPRESSION_6LORH

View File

@ -41,8 +41,10 @@
#define BLE_HAL_H_
#include <stddef.h>
#include "ble-addr.h"
/*---------------------------------------------------------------------------*/
/* BLE device address size */
#define BLE_ADDR_SIZE 6
/*---------------------------------------------------------------------------*/
/* Advertisement channel definitions */
#define BLE_ADV_DATA_LEN 31
@ -101,6 +103,13 @@ typedef enum {
BLE_RESULT_ERROR
} ble_result_t;
/*---------------------------------------------------------------------------*/
/* Type of BLE device address */
typedef enum {
BLE_ADDR_TYPE_PUBLIC,
BLE_ADDR_TYPE_RANDOM
} ble_addr_type_t;
/*---------------------------------------------------------------------------*/
/* Advertising modes of BLE */
typedef enum {

View File

@ -38,103 +38,27 @@
*/
/*---------------------------------------------------------------------------*/
#include "ble-hal.h"
#include "net/mac/ble/ble-l2cap.h"
#include "net/packetbuf.h"
#include "net/netstack.h"
#include "lib/memb.h"
#include "lib/list.h"
#include <string.h>
#include "../../../dev/ble-hal.h"
/*---------------------------------------------------------------------------*/
#include "sys/log.h"
#define LOG_MODULE "L2CAP"
#define LOG_LEVEL LOG_LEVEL_MAC
/*---------------------------------------------------------------------------*/
/* device name used for BLE advertisement */
#ifdef BLE_CONF_DEVICE_NAME
#define BLE_DEVICE_NAME BLE_CONF_DEVICE_NAME
#else
#define BLE_DEVICE_NAME "BLE device name"
#endif
/* BLE advertisement in milliseconds */
#ifdef BLE_CONF_ADV_INTERVAL
#define BLE_ADV_INTERVAL BLE_CONF_ADV_INTERVAL
#else
#define BLE_ADV_INTERVAL 50
#endif
#define BLE_SLAVE_CONN_INTERVAL_MIN 0x0150
#define BLE_SLAVE_CONN_INTERVAL_MAX 0x01F0
#define L2CAP_SIGNAL_CHANNEL 0x0005
#define L2CAP_FLOW_CHANNEL 0x0041
#define L2CAP_CODE_CONN_UPDATE_REQ 0x12
#define L2CAP_CODE_CONN_UPDATE_RSP 0x13
#define L2CAP_CODE_CONN_REQ 0x14
#define L2CAP_CODE_CONN_RSP 0x15
#define L2CAP_CODE_CREDIT 0x16
#define L2CAP_IPSP_PSM 0x0023
/* the maximum MTU size of the L2CAP channel */
#ifdef BLE_L2CAP_CONF_NODE_MTU
#define BLE_L2CAP_NODE_MTU BLE_L2CAP_CONF_NODE_MTU
#else
#define BLE_L2CAP_NODE_MTU 1280
#endif
/* the max. supported L2CAP fragment length */
#ifdef BLE_L2CAP_CONF_NODE_FRAG_LEN
#define BLE_L2CAP_NODE_FRAG_LEN BLE_L2CAP_CONF_NODE_FRAG_LEN
#else
#ifdef BLE_MODE_CONF_CONN_MAX_PACKET_SIZE
#define BLE_L2CAP_NODE_FRAG_LEN BLE_MODE_CONF_CONN_MAX_PACKET_SIZE
#else
#define BLE_L2CAP_NODE_FRAG_LEN 256
#endif
#endif
#define L2CAP_CREDIT_NEW (BLE_L2CAP_NODE_MTU / BLE_L2CAP_NODE_FRAG_LEN)
#define L2CAP_CREDIT_THRESHOLD 2
#define L2CAP_INIT_INTERVAL (2 * CLOCK_SECOND)
/* BLE connection interval in milliseconds */
#ifdef BLE_CONF_CONNECTION_INTERVAL
#define CONNECTION_INTERVAL_MS BLE_CONF_CONNECTION_INTERVAL
#else
#define CONNECTION_INTERVAL_MS 125
#endif
/* BLE slave latency */
#ifdef BLE_CONF_CONNECTION_SLAVE_LATENCY
#define CONNECTION_SLAVE_LATENCY BLE_CONF_CONNECTION_SLAVE_LATENCY
#else
#define CONNECTION_SLAVE_LATENCY 0
#endif
/* BLE supervision timeout */
#define CONNECTION_TIMEOUT 42
#define MS_TO_CLOCK_SECONDS(X) ((int)(((double)((X)*CLOCK_SECOND)) / 1000.0))
#define L2CAP_FIRST_HEADER_SIZE 6
#define L2CAP_SUBSEQ_HEADER_SIZE 4
/*---------------------------------------------------------------------------*/
/* BLE controller */
/* public device address of BLE controller */
static uint8_t ble_addr[BLE_ADDR_SIZE];
/*---------------------------------------------------------------------------*/
#if UIP_CONF_ROUTER
#ifdef BLE_MODE_CONF_MAX_CONNECTIONS
#define L2CAP_CHANNELS BLE_MODE_CONF_MAX_CONNECTIONS
#else
#define L2CAP_CHANNELS 1
#endif
#else
#define L2CAP_CHANNELS 1
#endif
/*---------------------------------------------------------------------------*/
/* L2CAP fragmentation buffers and utilities */
typedef struct {
/* L2CAP Service Data Unit (SDU) (= packet data)*/

127
os/net/mac/ble/ble-l2cap.h Normal file
View File

@ -0,0 +1,127 @@
/*
* Copyright (c) 2017, Graz University of Technology
* 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 copyright holder 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 COPYRIGHT HOLDERS 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
* COPYRIGHT HOLDER 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.
*/
/**
* \file
* MAC layer that implements BLE L2CAP credit-based flow control
* channels to support IPv6 over BLE (RFC 7668)
*
* \author
* Michael Spoerk <michael.spoerk@tugraz.at>
*/
/*---------------------------------------------------------------------------*/
#ifndef BLE_L2CAP_H_
#define BLE_L2CAP_H_
#include "contiki.h"
#include "net/mac/mac.h"
#include "dev/radio.h"
/*---------------------------------------------------------------------------*/
/* device name used for BLE advertisement */
#ifdef BLE_CONF_DEVICE_NAME
#define BLE_DEVICE_NAME BLE_CONF_DEVICE_NAME
#else
#define BLE_DEVICE_NAME "BLE device name"
#endif
/* BLE advertisement in milliseconds */
#ifdef BLE_CONF_ADV_INTERVAL
#define BLE_ADV_INTERVAL BLE_CONF_ADV_INTERVAL
#else
#define BLE_ADV_INTERVAL 50
#endif
#define BLE_SLAVE_CONN_INTERVAL_MIN 0x0150
#define BLE_SLAVE_CONN_INTERVAL_MAX 0x01F0
#define L2CAP_SIGNAL_CHANNEL 0x0005
#define L2CAP_FLOW_CHANNEL 0x0041
#define L2CAP_CODE_CONN_UPDATE_REQ 0x12
#define L2CAP_CODE_CONN_UPDATE_RSP 0x13
#define L2CAP_CODE_CONN_REQ 0x14
#define L2CAP_CODE_CONN_RSP 0x15
#define L2CAP_CODE_CREDIT 0x16
#define L2CAP_IPSP_PSM 0x0023
/* the maximum MTU size of the L2CAP channel */
#ifdef BLE_L2CAP_CONF_NODE_MTU
#define BLE_L2CAP_NODE_MTU BLE_L2CAP_CONF_NODE_MTU
#else
#define BLE_L2CAP_NODE_MTU 1280
#endif
/* the max. supported L2CAP fragment length */
#ifdef BLE_L2CAP_CONF_NODE_FRAG_LEN
#define BLE_L2CAP_NODE_FRAG_LEN BLE_L2CAP_CONF_NODE_FRAG_LEN
#else
#ifdef BLE_MODE_CONF_CONN_MAX_PACKET_SIZE
#define BLE_L2CAP_NODE_FRAG_LEN BLE_MODE_CONF_CONN_MAX_PACKET_SIZE
#else
#define BLE_L2CAP_NODE_FRAG_LEN 256
#endif
#endif
#define L2CAP_CREDIT_NEW (BLE_L2CAP_NODE_MTU / BLE_L2CAP_NODE_FRAG_LEN)
#define L2CAP_CREDIT_THRESHOLD 2
#define L2CAP_INIT_INTERVAL (2 * CLOCK_SECOND)
/* BLE connection interval in milliseconds */
#ifdef BLE_CONF_CONNECTION_INTERVAL
#define CONNECTION_INTERVAL_MS BLE_CONF_CONNECTION_INTERVAL
#else
#define CONNECTION_INTERVAL_MS 125
#endif
/* BLE slave latency */
#ifdef BLE_CONF_CONNECTION_SLAVE_LATENCY
#define CONNECTION_SLAVE_LATENCY BLE_CONF_CONNECTION_SLAVE_LATENCY
#else
#define CONNECTION_SLAVE_LATENCY 0
#endif
/* BLE supervision timeout */
#define CONNECTION_TIMEOUT 42
#define L2CAP_FIRST_HEADER_SIZE 6
#define L2CAP_SUBSEQ_HEADER_SIZE 4
#if UIP_CONF_ROUTER
#ifdef BLE_MODE_CONF_MAX_CONNECTIONS
#define L2CAP_CHANNELS BLE_MODE_CONF_MAX_CONNECTIONS
#else
#define L2CAP_CHANNELS 1
#endif
#else
#define L2CAP_CHANNELS 1
#endif
extern const struct mac_driver ble_l2cap_driver;
#endif /* BLE_L2CAP_H_ */

View File

@ -68,6 +68,8 @@
#define NETSTACK_MAC csma_driver
#elif MAC_CONF_WITH_TSCH
#define NETSTACK_MAC tschmac_driver
#elif MAC_CONF_WITH_BLE
#define NETSTACK_MAC ble_l2cap_driver
#else
#error Unknown MAC configuration
#endif