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 1280
77#endif
78
79/* the max. supported L2CAP fragment length */
80#ifdef BLE_L2CAP_CONF_NODE_FRAG_LEN
81#define BLE_L2CAP_NODE_FRAG_LEN BLE_L2CAP_CONF_NODE_FRAG_LEN
82#else
83#ifdef BLE_MODE_CONF_CONN_MAX_PACKET_SIZE
84#define BLE_L2CAP_NODE_FRAG_LEN BLE_MODE_CONF_CONN_MAX_PACKET_SIZE
85#else
86#define BLE_L2CAP_NODE_FRAG_LEN 256
87#endif
88#endif
89
90#define L2CAP_CREDIT_NEW (BLE_L2CAP_NODE_MTU / BLE_L2CAP_NODE_FRAG_LEN)
91#define L2CAP_CREDIT_THRESHOLD 2
92
93#define L2CAP_INIT_INTERVAL (2 * CLOCK_SECOND)
94
95/* BLE connection interval in milliseconds */
96#ifdef BLE_CONF_CONNECTION_INTERVAL
97#define CONNECTION_INTERVAL_MS BLE_CONF_CONNECTION_INTERVAL
98#else
99#define CONNECTION_INTERVAL_MS 125
100#endif
101
102/* BLE slave latency */
103#ifdef BLE_CONF_CONNECTION_SLAVE_LATENCY
104#define CONNECTION_SLAVE_LATENCY BLE_CONF_CONNECTION_SLAVE_LATENCY
105#else
106#define CONNECTION_SLAVE_LATENCY 0
107#endif
108
109/* BLE supervision timeout */
110#define CONNECTION_TIMEOUT 42
111
112#define L2CAP_FIRST_HEADER_SIZE 6
113#define L2CAP_SUBSEQ_HEADER_SIZE 4
114
115#if UIP_CONF_ROUTER
116#ifdef BLE_MODE_CONF_MAX_CONNECTIONS
117#define L2CAP_CHANNELS BLE_MODE_CONF_MAX_CONNECTIONS
118#else
119#define L2CAP_CHANNELS 1
120#endif
121#else
122#define L2CAP_CHANNELS 1
123#endif
124
125extern const struct mac_driver ble_l2cap_driver;
126
127#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