Contiki-NG
ble-l2cap.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017, Graz University of Technology
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the copyright holder nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28 * OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31/**
32 * \file
33 * MAC layer that implements BLE L2CAP credit-based flow control
34 * channels to support IPv6 over BLE (RFC 7668)
35 *
36 * \author
37 * Michael Spoerk <michael.spoerk@tugraz.at>
38 */
39/*---------------------------------------------------------------------------*/
40#ifndef BLE_L2CAP_H_
41#define BLE_L2CAP_H_
42
43#include "contiki.h"
44#include "net/mac/mac.h"
45#include "dev/radio.h"
46/*---------------------------------------------------------------------------*/
47/* device name used for BLE advertisement */
48#ifdef BLE_CONF_DEVICE_NAME
49#define BLE_DEVICE_NAME BLE_CONF_DEVICE_NAME
50#else
51#define BLE_DEVICE_NAME "BLE device name"
52#endif
53
54/* BLE advertisement in milliseconds */
55#ifdef BLE_CONF_ADV_INTERVAL
56#define BLE_ADV_INTERVAL BLE_CONF_ADV_INTERVAL
57#else
58#define BLE_ADV_INTERVAL 50
59#endif
60
61#define BLE_SLAVE_CONN_INTERVAL_MIN 0x0150
62#define BLE_SLAVE_CONN_INTERVAL_MAX 0x01F0
63#define L2CAP_SIGNAL_CHANNEL 0x0005
64#define L2CAP_FLOW_CHANNEL 0x0041
65#define L2CAP_CODE_CONN_UPDATE_REQ 0x12
66#define L2CAP_CODE_CONN_UPDATE_RSP 0x13
67#define L2CAP_CODE_CONN_REQ 0x14
68#define L2CAP_CODE_CONN_RSP 0x15
69#define L2CAP_CODE_CREDIT 0x16
70#define L2CAP_IPSP_PSM 0x0023
71
72/* the maximum MTU size of the L2CAP channel */
73#ifdef BLE_L2CAP_CONF_NODE_MTU
74#define BLE_L2CAP_NODE_MTU BLE_L2CAP_CONF_NODE_MTU
75#else
76#define BLE_L2CAP_NODE_MTU PACKETBUF_SIZE
77#endif
78
79#if BLE_L2CAP_NODE_MTU > PACKETBUF_SIZE
80#error BLE_L2CAP_NODE_MTU exceeds the PACKETBUF_SIZE
81#endif
82
83/* the max. supported L2CAP fragment length */
84#ifdef BLE_L2CAP_CONF_NODE_FRAG_LEN
85#define BLE_L2CAP_NODE_FRAG_LEN BLE_L2CAP_CONF_NODE_FRAG_LEN
86#else
87#ifdef BLE_MODE_CONF_CONN_MAX_PACKET_SIZE
88#define BLE_L2CAP_NODE_FRAG_LEN BLE_MODE_CONF_CONN_MAX_PACKET_SIZE
89#else
90#define BLE_L2CAP_NODE_FRAG_LEN 256
91#endif
92#endif
93
94#define L2CAP_CREDIT_NEW (BLE_L2CAP_NODE_MTU / BLE_L2CAP_NODE_FRAG_LEN)
95#define L2CAP_CREDIT_THRESHOLD 2
96
97#define L2CAP_INIT_INTERVAL (2 * CLOCK_SECOND)
98
99/* BLE connection interval in milliseconds */
100#ifdef BLE_CONF_CONNECTION_INTERVAL
101#define CONNECTION_INTERVAL_MS BLE_CONF_CONNECTION_INTERVAL
102#else
103#define CONNECTION_INTERVAL_MS 125
104#endif
105
106/* BLE slave latency */
107#ifdef BLE_CONF_CONNECTION_SLAVE_LATENCY
108#define CONNECTION_SLAVE_LATENCY BLE_CONF_CONNECTION_SLAVE_LATENCY
109#else
110#define CONNECTION_SLAVE_LATENCY 0
111#endif
112
113/* BLE supervision timeout */
114#define CONNECTION_TIMEOUT 42
115
116#define L2CAP_FIRST_HEADER_SIZE 6
117#define L2CAP_SUBSEQ_HEADER_SIZE 4
118
119#if UIP_CONF_ROUTER
120#ifdef BLE_MODE_CONF_MAX_CONNECTIONS
121#define L2CAP_CHANNELS BLE_MODE_CONF_MAX_CONNECTIONS
122#else
123#define L2CAP_CHANNELS 1
124#endif
125#else
126#define L2CAP_CHANNELS 1
127#endif
128
129extern const struct mac_driver ble_l2cap_driver;
130
131#endif /* BLE_L2CAP_H_ */
MAC driver header file.
Header file for the radio API.
The structure of a MAC protocol driver in Contiki.
Definition: mac.h:62