• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <stdint.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_CID_START                 0x0040
34 #define BLE_L2CAP_COC_CID_END                   0x007F
35 
36 struct ble_l2cap_chan;
37 
38 #define BLE_L2CAP_COC_FLAG_STALLED              0x01
39 
40 struct ble_l2cap_coc_endpoint {
41     struct os_mbuf *sdu;
42     uint16_t mtu;
43     uint16_t credits;
44     uint16_t data_offset;
45     uint8_t flags;
46 };
47 
48 struct ble_l2cap_coc_srv {
49     STAILQ_ENTRY(ble_l2cap_coc_srv) next;
50     uint16_t psm;
51     uint16_t mtu;
52     ble_l2cap_event_fn *cb;
53     void *cb_arg;
54 };
55 
56 #if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) != 0
57 int ble_l2cap_coc_init(void);
58 int ble_l2cap_coc_create_server(uint16_t psm, uint16_t mtu,
59                                 ble_l2cap_event_fn *cb, void *cb_arg);
60 int ble_l2cap_coc_create_srv_chan(struct ble_hs_conn *conn, uint16_t psm,
61                                   struct ble_l2cap_chan **chan);
62 struct ble_l2cap_chan *ble_l2cap_coc_chan_alloc(struct ble_hs_conn *conn,
63     uint16_t psm, uint16_t mtu,
64     struct os_mbuf *sdu_rx,
65     ble_l2cap_event_fn *cb,
66     void *cb_arg);
67 void ble_l2cap_coc_cleanup_chan(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan);
68 void ble_l2cap_coc_le_credits_update(uint16_t conn_handle, uint16_t dcid,
69                                      uint16_t credits);
70 int ble_l2cap_coc_recv_ready(struct ble_l2cap_chan *chan,
71                              struct os_mbuf *sdu_rx);
72 int ble_l2cap_coc_send(struct ble_l2cap_chan *chan, struct os_mbuf *sdu_tx);
73 void ble_l2cap_coc_set_new_mtu_mps(struct ble_l2cap_chan *chan, uint16_t mtu, uint16_t mps);
74 #else
ble_l2cap_coc_init(void)75 static inline int ble_l2cap_coc_init(void)
76 {
77     return 0;
78 }
79 
ble_l2cap_coc_create_server(uint16_t psm,uint16_t mtu,ble_l2cap_event_fn * cb,void * cb_arg)80 static inline int ble_l2cap_coc_create_server(uint16_t psm, uint16_t mtu, ble_l2cap_event_fn *cb, void *cb_arg)
81 {
82     return BLE_HS_ENOTSUP;
83 }
84 
ble_l2cap_coc_recv_ready(struct ble_l2cap_chan * chan,struct os_mbuf * sdu_rx)85 static inline int ble_l2cap_coc_recv_ready(struct ble_l2cap_chan *chan, struct os_mbuf *sdu_rx)
86 {
87     return BLE_HS_ENOTSUP;
88 }
89 
ble_l2cap_coc_cleanup_chan(struct ble_hs_conn * conn,struct ble_l2cap_chan * chan)90 static inline void ble_l2cap_coc_cleanup_chan(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan)
91 {
92 }
93 
ble_l2cap_coc_send(struct ble_l2cap_chan * chan,struct os_mbuf * sdu_tx)94 static inline int ble_l2cap_coc_send(struct ble_l2cap_chan *chan, struct os_mbuf *sdu_tx)
95 {
96     return BLE_HS_ENOTSUP;
97 }
98 #endif
99 
100 #ifdef __cplusplus
101 }
102 #endif
103 
104 #endif /* H_L2CAP_COC_PRIV_ */