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 "syscfg/syscfg.h"
24
25 #ifdef __cplusplus
26 extern "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
32 struct 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
40 struct 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
46 struct 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
54 struct 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
61 struct 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
69 struct 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
77 struct 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
85 struct 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
93 struct ble_l2cap_sig_credit_base_reconfig_req {
94 uint16_t mtu;
95 uint16_t mps;
96 uint16_t dcids[0];
97 } __attribute__((packed));
98
99 struct ble_l2cap_sig_credit_base_reconfig_rsp {
100 uint16_t result;
101 } __attribute__((packed));
102
103 struct ble_l2cap_sig_disc_req {
104 uint16_t dcid;
105 uint16_t scid;
106 } __attribute__((packed));
107
108 struct ble_l2cap_sig_disc_rsp {
109 uint16_t dcid;
110 uint16_t scid;
111 } __attribute__((packed));
112
113 struct ble_l2cap_sig_le_credits {
114 uint16_t scid;
115 uint16_t credits;
116 } __attribute__((packed));
117
118 void ble_l2cap_sig_hdr_parse(void *payload, uint16_t len,
119 struct ble_l2cap_sig_hdr *hdr);
120 int ble_l2cap_sig_reject_tx(uint16_t conn_handle,
121 uint8_t id, uint16_t reason,
122 void *data, int data_len);
123 int ble_l2cap_sig_reject_invalid_cid_tx(uint16_t conn_handle, uint8_t id,
124 uint16_t src_cid, uint16_t dst_cid);
125 int ble_l2cap_sig_tx(uint16_t conn_handle, struct os_mbuf *txom);
126 void *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
129 int 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);
132 int ble_l2cap_sig_disconnect(struct ble_l2cap_chan *chan);
133 int ble_l2cap_sig_le_credits(uint16_t conn_handle, uint16_t scid,
134 uint16_t credits);
135 #else
ble_l2cap_sig_coc_connect(uint16_t conn_handle,uint16_t psm,uint16_t mtu,struct os_mbuf * sdu_rx,ble_l2cap_event_fn * cb,void * cb_arg)136 static inline int ble_l2cap_sig_coc_connect(uint16_t conn_handle, uint16_t psm, uint16_t mtu,
137 struct os_mbuf *sdu_rx,
138 ble_l2cap_event_fn *cb, void *cb_arg)
139 {
140 return BLE_HS_ENOTSUP;
141 }
142
ble_l2cap_sig_disconnect(struct ble_l2cap_chan * chan)143 static inline int ble_l2cap_sig_disconnect(struct ble_l2cap_chan *chan)
144 {
145 return BLE_HS_ENOTSUP;
146 }
147 #endif
148
149 #if MYNEWT_VAL(BLE_L2CAP_ENHANCED_COC)
150 int ble_l2cap_sig_ecoc_connect(uint16_t conn_handle,
151 uint16_t psm, uint16_t mtu,
152 uint8_t num, struct os_mbuf *sdu_rx[],
153 ble_l2cap_event_fn *cb, void *cb_arg);
154 int ble_l2cap_sig_coc_reconfig(uint16_t conn_handle, struct ble_l2cap_chan *chans[],
155 uint8_t num, uint16_t new_mtu);
156 #else
ble_l2cap_sig_ecoc_connect(uint16_t conn_handle,uint16_t psm,uint16_t mtu,uint8_t num,struct os_mbuf * sdu_rx[],ble_l2cap_event_fn * cb,void * cb_arg)157 static inline int ble_l2cap_sig_ecoc_connect(uint16_t conn_handle,
158 uint16_t psm, uint16_t mtu,
159 uint8_t num, struct os_mbuf *sdu_rx[],
160 ble_l2cap_event_fn *cb, void *cb_arg)
161 {
162 return BLE_HS_ENOTSUP;
163 }
ble_l2cap_sig_coc_reconfig(uint16_t conn_handle,struct ble_l2cap_chan * chans[],uint8_t num,uint16_t new_mtu)164 static inline int ble_l2cap_sig_coc_reconfig(uint16_t conn_handle, struct ble_l2cap_chan *chans[],
165 uint8_t num, uint16_t new_mtu)
166 {
167 return BLE_HS_ENOTSUP;
168 }
169 #endif
170
171 void ble_l2cap_sig_conn_broken(uint16_t conn_handle, int reason);
172 int32_t ble_l2cap_sig_timer(void);
173 struct ble_l2cap_chan *ble_l2cap_sig_create_chan(uint16_t conn_handle);
174 int ble_l2cap_sig_init(void);
175
176 #ifdef __cplusplus
177 }
178 #endif
179
180 #endif