NimBLE-Arduino 2.1.2
Loading...
Searching...
No Matches
ble_l2cap_sig_priv.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_SIG_
21#define H_BLE_L2CAP_SIG_
22
23#include "nimble/porting/nimble/include/syscfg/syscfg.h"
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29#define BLE_L2CAP_SIG_MTU 100 /* This is our own default. */
30
31#define BLE_L2CAP_SIG_HDR_SZ 4
32struct ble_l2cap_sig_hdr {
33 uint8_t op;
34 uint8_t identifier;
35 uint16_t length;
36 uint8_t data[0];
37} __attribute__((packed));
38
39#define BLE_L2CAP_SIG_REJECT_MIN_SZ 2
40struct ble_l2cap_sig_reject {
41 uint16_t reason;
42 uint8_t data[0];
43} __attribute__((packed));
44
45#define BLE_L2CAP_SIG_UPDATE_REQ_SZ 8
46struct ble_l2cap_sig_update_req {
47 uint16_t itvl_min;
48 uint16_t itvl_max;
49 uint16_t slave_latency;
50 uint16_t timeout_multiplier;
51} __attribute__((packed));
52
53#define BLE_L2CAP_SIG_UPDATE_RSP_SZ 2
54struct ble_l2cap_sig_update_rsp {
55 uint16_t result;
56} __attribute__((packed));
57
58#define BLE_L2CAP_SIG_UPDATE_RSP_RESULT_ACCEPT 0x0000
59#define BLE_L2CAP_SIG_UPDATE_RSP_RESULT_REJECT 0x0001
60
61struct ble_l2cap_sig_le_con_req {
62 uint16_t psm;
63 uint16_t scid;
64 uint16_t mtu;
65 uint16_t mps;
66 uint16_t credits;
67} __attribute__((packed));
68
69struct ble_l2cap_sig_le_con_rsp {
70 uint16_t dcid;
71 uint16_t mtu;
72 uint16_t mps;
73 uint16_t credits;
74 uint16_t result;
75} __attribute__((packed));
76
77struct ble_l2cap_sig_credit_base_connect_req {
78 uint16_t psm;
79 uint16_t mtu;
80 uint16_t mps;
81 uint16_t credits;
82 uint16_t scids[0];
83} __attribute__((packed));
84
85struct ble_l2cap_sig_credit_base_connect_rsp {
86 uint16_t mtu;
87 uint16_t mps;
88 uint16_t credits;
89 uint16_t result;
90 uint16_t dcids[0];
91} __attribute__((packed));
92
93struct ble_l2cap_sig_credit_base_reconfig_req {
94 uint16_t mtu;
95 uint16_t mps;
96 uint16_t dcids[0];
97} __attribute__((packed));
98
99struct ble_l2cap_sig_credit_base_reconfig_rsp {
100 uint16_t result;
101} __attribute__((packed));
102
103struct ble_l2cap_sig_disc_req {
104 uint16_t dcid;
105 uint16_t scid;
106} __attribute__((packed));
107
108struct ble_l2cap_sig_disc_rsp {
109 uint16_t dcid;
110 uint16_t scid;
111} __attribute__((packed));
112
113struct ble_l2cap_sig_le_credits {
114 uint16_t scid;
115 uint16_t credits;
116} __attribute__((packed));
117
118void ble_l2cap_sig_hdr_parse(void *payload, uint16_t len,
119 struct ble_l2cap_sig_hdr *hdr);
120int ble_l2cap_sig_reject_tx(uint16_t conn_handle,
121 uint8_t id, uint16_t reason,
122 void *data, int data_len);
123int ble_l2cap_sig_reject_invalid_cid_tx(uint16_t conn_handle, uint8_t id,
124 uint16_t src_cid, uint16_t dst_cid);
125int ble_l2cap_sig_tx(uint16_t conn_handle, struct os_mbuf *txom);
126void *ble_l2cap_sig_cmd_get(uint8_t opcode, uint8_t id, uint16_t len,
127 struct os_mbuf **txom);
128#if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) != 0
129int ble_l2cap_sig_coc_connect(uint16_t conn_handle, uint16_t psm, uint16_t mtu,
130 struct os_mbuf *sdu_rx,
131 ble_l2cap_event_fn *cb, void *cb_arg);
132int ble_l2cap_sig_disconnect(struct ble_l2cap_chan *chan);
133int ble_l2cap_sig_le_credits(uint16_t conn_handle, uint16_t scid,
134 uint16_t credits);
135#else
136static inline int
137ble_l2cap_sig_coc_connect(uint16_t conn_handle, uint16_t psm, uint16_t mtu,
138 struct os_mbuf *sdu_rx,
139 ble_l2cap_event_fn *cb, void *cb_arg)
140{
141 return BLE_HS_ENOTSUP;
142}
143
144static inline int
145ble_l2cap_sig_disconnect(struct ble_l2cap_chan *chan)
146{
147 return BLE_HS_ENOTSUP;
148}
149#endif
150
151#if MYNEWT_VAL(BLE_L2CAP_ENHANCED_COC)
152int ble_l2cap_sig_ecoc_connect(uint16_t conn_handle,
153 uint16_t psm, uint16_t mtu,
154 uint8_t num, struct os_mbuf *sdu_rx[],
155 ble_l2cap_event_fn *cb, void *cb_arg);
156int ble_l2cap_sig_coc_reconfig(uint16_t conn_handle, struct ble_l2cap_chan *chans[],
157 uint8_t num, uint16_t new_mtu);
158#else
159static inline int
160ble_l2cap_sig_ecoc_connect(uint16_t conn_handle,
161 uint16_t psm, uint16_t mtu,
162 uint8_t num, struct os_mbuf *sdu_rx[],
163 ble_l2cap_event_fn *cb, void *cb_arg)
164{
165 return BLE_HS_ENOTSUP;
166}
167static inline int
168ble_l2cap_sig_coc_reconfig(uint16_t conn_handle, struct ble_l2cap_chan *chans[],
169 uint8_t num, uint16_t new_mtu)
170{
171 return BLE_HS_ENOTSUP;
172}
173#endif
174
175void ble_l2cap_sig_conn_broken(uint16_t conn_handle, int reason);
176int32_t ble_l2cap_sig_timer(void);
177struct ble_l2cap_chan *ble_l2cap_sig_create_chan(uint16_t conn_handle);
178int ble_l2cap_sig_init(void);
179
180#ifdef __cplusplus
181}
182#endif
183
184#endif
Definition os_mbuf.h:86