NimBLE-Arduino 2.1.2
Loading...
Searching...
No Matches
ble_l2cap.h
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#ifndef H_BLE_L2CAP_
21#define H_BLE_L2CAP_
22
23#include "nimble/nimble/include/nimble/nimble_opt.h"
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28struct ble_l2cap_sig_update_req;
29struct ble_hs_conn;
30
31#define BLE_L2CAP_CID_ATT 4
32#define BLE_L2CAP_CID_SIG 5
33#define BLE_L2CAP_CID_SM 6
34
35#define BLE_L2CAP_SIG_OP_REJECT 0x01
36#define BLE_L2CAP_SIG_OP_CONNECT_REQ 0x02
37#define BLE_L2CAP_SIG_OP_CONNECT_RSP 0x03
38#define BLE_L2CAP_SIG_OP_CONFIG_REQ 0x04
39#define BLE_L2CAP_SIG_OP_CONFIG_RSP 0x05
40#define BLE_L2CAP_SIG_OP_DISCONN_REQ 0x06
41#define BLE_L2CAP_SIG_OP_DISCONN_RSP 0x07
42#define BLE_L2CAP_SIG_OP_ECHO_REQ 0x08
43#define BLE_L2CAP_SIG_OP_ECHO_RSP 0x09
44#define BLE_L2CAP_SIG_OP_INFO_REQ 0x0a
45#define BLE_L2CAP_SIG_OP_INFO_RSP 0x0b
46#define BLE_L2CAP_SIG_OP_CREATE_CHAN_REQ 0x0c
47#define BLE_L2CAP_SIG_OP_CREATE_CHAN_RSP 0x0d
48#define BLE_L2CAP_SIG_OP_MOVE_CHAN_REQ 0x0e
49#define BLE_L2CAP_SIG_OP_MOVE_CHAN_RSP 0x0f
50#define BLE_L2CAP_SIG_OP_MOVE_CHAN_CONF_REQ 0x10
51#define BLE_L2CAP_SIG_OP_MOVE_CHAN_CONF_RSP 0x11
52#define BLE_L2CAP_SIG_OP_UPDATE_REQ 0x12
53#define BLE_L2CAP_SIG_OP_UPDATE_RSP 0x13
54#define BLE_L2CAP_SIG_OP_LE_CREDIT_CONNECT_REQ 0x14
55#define BLE_L2CAP_SIG_OP_LE_CREDIT_CONNECT_RSP 0x15
56#define BLE_L2CAP_SIG_OP_FLOW_CTRL_CREDIT 0x16
57#define BLE_L2CAP_SIG_OP_CREDIT_CONNECT_REQ 0x17
58#define BLE_L2CAP_SIG_OP_CREDIT_CONNECT_RSP 0x18
59#define BLE_L2CAP_SIG_OP_CREDIT_RECONFIG_REQ 0x19
60#define BLE_L2CAP_SIG_OP_CREDIT_RECONFIG_RSP 0x1A
61#define BLE_L2CAP_SIG_OP_MAX 0x1B
62
63#define BLE_L2CAP_SIG_ERR_CMD_NOT_UNDERSTOOD 0x0000
64#define BLE_L2CAP_SIG_ERR_MTU_EXCEEDED 0x0001
65#define BLE_L2CAP_SIG_ERR_INVALID_CID 0x0002
66
67#define BLE_L2CAP_COC_ERR_CONNECTION_SUCCESS 0x0000
68#define BLE_L2CAP_COC_ERR_UNKNOWN_LE_PSM 0x0002
69#define BLE_L2CAP_COC_ERR_NO_RESOURCES 0x0004
70#define BLE_L2CAP_COC_ERR_INSUFFICIENT_AUTHEN 0x0005
71#define BLE_L2CAP_COC_ERR_INSUFFICIENT_AUTHOR 0x0006
72#define BLE_L2CAP_COC_ERR_INSUFFICIENT_KEY_SZ 0x0007
73#define BLE_L2CAP_COC_ERR_INSUFFICIENT_ENC 0x0008
74#define BLE_L2CAP_COC_ERR_INVALID_SOURCE_CID 0x0009
75#define BLE_L2CAP_COC_ERR_SOURCE_CID_ALREADY_USED 0x000A
76#define BLE_L2CAP_COC_ERR_UNACCEPTABLE_PARAMETERS 0x000B
77#define BLE_L2CAP_COC_ERR_INVALID_PARAMETERS 0x000C
78
79#define BLE_L2CAP_ERR_RECONFIG_SUCCEED 0x0000
80#define BLE_L2CAP_ERR_RECONFIG_REDUCTION_MTU_NOT_ALLOWED 0x0001
81#define BLE_L2CAP_ERR_RECONFIG_REDUCTION_MPS_NOT_ALLOWED 0x0002
82#define BLE_L2CAP_ERR_RECONFIG_INVALID_DCID 0x0003
83#define BLE_L2CAP_ERR_RECONFIG_UNACCAPTED_PARAM 0x0004
84
85#define BLE_L2CAP_EVENT_COC_CONNECTED 0
86#define BLE_L2CAP_EVENT_COC_DISCONNECTED 1
87#define BLE_L2CAP_EVENT_COC_ACCEPT 2
88#define BLE_L2CAP_EVENT_COC_DATA_RECEIVED 3
89#define BLE_L2CAP_EVENT_COC_TX_UNSTALLED 4
90#define BLE_L2CAP_EVENT_COC_RECONFIG_COMPLETED 5
91#define BLE_L2CAP_EVENT_COC_PEER_RECONFIGURED 6
92
93typedef void ble_l2cap_sig_update_fn(uint16_t conn_handle, int status,
94 void *arg);
95
96struct ble_l2cap_sig_update_params {
97 uint16_t itvl_min;
98 uint16_t itvl_max;
99 uint16_t slave_latency;
100 uint16_t timeout_multiplier;
101};
102
103int ble_l2cap_sig_update(uint16_t conn_handle,
104 struct ble_l2cap_sig_update_params *params,
105 ble_l2cap_sig_update_fn *cb, void *cb_arg);
106
107struct ble_l2cap_chan;
108
119 uint8_t type;
120
125 union {
130 struct {
138
140 uint16_t conn_handle;
141
143 struct ble_l2cap_chan *chan;
145
151 struct {
153 uint16_t conn_handle;
154
156 struct ble_l2cap_chan *chan;
158
164 struct {
166 uint16_t conn_handle;
167
170
172 struct ble_l2cap_chan *chan;
174
180 struct {
182 uint16_t conn_handle;
183
185 struct ble_l2cap_chan *chan;
186
190
196 struct {
198 uint16_t conn_handle;
199
201 struct ble_l2cap_chan *chan;
202
210 int status;
212
219 struct {
226 int status;
227
229 uint16_t conn_handle;
230
232 struct ble_l2cap_chan *chan;
234 };
235};
236
237struct ble_l2cap_chan_info {
238 uint16_t scid;
239 uint16_t dcid;
240 uint16_t our_l2cap_mtu;
241 uint16_t peer_l2cap_mtu;
242 uint16_t psm;
243 uint16_t our_coc_mtu;
244 uint16_t peer_coc_mtu;
245};
246
247typedef int ble_l2cap_event_fn(struct ble_l2cap_event *event, void *arg);
248
249
250uint16_t ble_l2cap_get_conn_handle(struct ble_l2cap_chan *chan);
251int ble_l2cap_create_server(uint16_t psm, uint16_t mtu,
252 ble_l2cap_event_fn *cb, void *cb_arg);
253
254int ble_l2cap_connect(uint16_t conn_handle, uint16_t psm, uint16_t mtu,
255 struct os_mbuf *sdu_rx,
256 ble_l2cap_event_fn *cb, void *cb_arg);
257int ble_l2cap_disconnect(struct ble_l2cap_chan *chan);
258int ble_l2cap_send(struct ble_l2cap_chan *chan, struct os_mbuf *sdu_tx);
259int ble_l2cap_recv_ready(struct ble_l2cap_chan *chan, struct os_mbuf *sdu_rx);
260int ble_l2cap_get_chan_info(struct ble_l2cap_chan *chan, struct ble_l2cap_chan_info *chan_info);
261
262#ifdef __cplusplus
263}
264#endif
265
266#endif
Definition ble_l2cap.h:114
int status
Definition ble_l2cap.h:137
struct ble_l2cap_event::@34::@41 reconfigured
uint16_t peer_sdu_size
Definition ble_l2cap.h:169
struct ble_l2cap_event::@34::@40 tx_unstalled
struct ble_l2cap_chan * chan
Definition ble_l2cap.h:143
uint16_t conn_handle
Definition ble_l2cap.h:140
uint8_t type
Definition ble_l2cap.h:119
struct ble_l2cap_event::@34::@37 disconnect
struct ble_l2cap_event::@34::@38 accept
struct ble_l2cap_event::@34::@39 receive
struct ble_l2cap_event::@34::@36 connect
struct os_mbuf * sdu_rx
Definition ble_l2cap.h:188
Definition os_mbuf.h:86