xref: /nrf52832-nimble/packages/NimBLE-latest/nimble/host/src/ble_l2cap_coc_priv.h (revision 042d53a763ad75cb1465103098bb88c245d95138)
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_L2CAP_COC_PRIV_
21 #define H_L2CAP_COC_PRIV_
22 
23 #include <inttypes.h>
24 #include "syscfg/syscfg.h"
25 #include "os/queue.h"
26 #include "os/os_mbuf.h"
27 #include "host/ble_l2cap.h"
28 #include "ble_l2cap_sig_priv.h"
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 #define BLE_L2CAP_COC_MTU                       100
34 #define BLE_L2CAP_COC_CID_START                 0x0040
35 #define BLE_L2CAP_COC_CID_END                   0x007F
36 
37 struct ble_l2cap_chan;
38 
39 struct ble_l2cap_coc_endpoint {
40     uint16_t mtu;
41     uint16_t credits;
42     uint16_t data_offset;
43     struct os_mbuf *sdu;
44 };
45 
46 struct ble_l2cap_coc_srv {
47     STAILQ_ENTRY(ble_l2cap_coc_srv) next;
48     uint16_t psm;
49     uint16_t mtu;
50     ble_l2cap_event_fn *cb;
51     void *cb_arg;
52 };
53 
54 #if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) != 0
55 int ble_l2cap_coc_init(void);
56 int ble_l2cap_coc_create_server(uint16_t psm, uint16_t mtu,
57                                 ble_l2cap_event_fn *cb, void *cb_arg);
58 int ble_l2cap_coc_create_srv_chan(uint16_t conn_handle, uint16_t psm,
59                                   struct ble_l2cap_chan **chan);
60 struct ble_l2cap_chan * ble_l2cap_coc_chan_alloc(uint16_t conn_handle,
61                                                  uint16_t psm, uint16_t mtu,
62                                                  struct os_mbuf *sdu_rx,
63                                                  ble_l2cap_event_fn *cb,
64                                                  void *cb_arg);
65 void ble_l2cap_coc_cleanup_chan(struct ble_l2cap_chan *chan);
66 void ble_l2cap_coc_le_credits_update(uint16_t conn_handle, uint16_t dcid,
67                                     uint16_t credits);
68 void ble_l2cap_coc_recv_ready(struct ble_l2cap_chan *chan,
69                               struct os_mbuf *sdu_rx);
70 int ble_l2cap_coc_send(struct ble_l2cap_chan *chan, struct os_mbuf *sdu_tx);
71 #else
72 #define ble_l2cap_coc_init()                                    0
73 #define ble_l2cap_coc_create_server(psm, mtu, cb, cb_arg)       BLE_HS_ENOTSUP
74 #define ble_l2cap_coc_recv_ready(chan, sdu_rx)
75 #define ble_l2cap_coc_cleanup_chan(chan)
76 #define ble_l2cap_coc_send(chan, sdu_tx)                        BLE_HS_ENOTSUP
77 #endif
78 
79 #ifdef __cplusplus
80 }
81 #endif
82 
83 #endif /* H_L2CAP_COC_PRIV_ */
84