NimBLE-Arduino 2.1.2
Loading...
Searching...
No Matches
ble_l2cap_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_L2CAP_PRIV_
21#define H_L2CAP_PRIV_
22
23#include "ble_l2cap_coc_priv.h"
24#include "nimble/nimble/host/include/host/ble_l2cap.h"
25#include <inttypes.h>
26#include "nimble/porting/nimble/include/stats/stats.h"
27#include "nimble/porting/nimble/include/os/queue.h"
28#include "nimble/porting/nimble/include/os/os_mbuf.h"
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33struct ble_hs_conn;
34struct hci_data_hdr;
35
36STATS_SECT_START(ble_l2cap_stats)
37 STATS_SECT_ENTRY(chan_create)
38 STATS_SECT_ENTRY(chan_delete)
39 STATS_SECT_ENTRY(update_init)
40 STATS_SECT_ENTRY(update_rx)
41 STATS_SECT_ENTRY(update_fail)
42 STATS_SECT_ENTRY(proc_timeout)
43 STATS_SECT_ENTRY(sig_tx)
44 STATS_SECT_ENTRY(sig_rx)
45 STATS_SECT_ENTRY(sm_tx)
46 STATS_SECT_ENTRY(sm_rx)
47STATS_SECT_END
48extern STATS_SECT_DECL(ble_l2cap_stats) ble_l2cap_stats;
49
50extern struct os_mempool ble_l2cap_chan_pool;
51
52/* This is nimble specific; packets sent to the black hole CID do not elicit
53 * an "invalid CID" response.
54 */
55#define BLE_L2CAP_CID_BLACK_HOLE 0xffff
56
57#define BLE_L2CAP_HDR_SZ 4
58
59typedef uint8_t ble_l2cap_chan_flags;
60
61typedef int ble_l2cap_rx_fn(struct ble_l2cap_chan *chan);
62
63struct ble_l2cap_chan {
64 SLIST_ENTRY(ble_l2cap_chan) next;
65 uint16_t conn_handle;
66 uint16_t dcid;
67 uint16_t scid;
68
69 /* Unions just to avoid confusion on MPS/MTU.
70 * In CoC context, L2CAP MTU is MPS
71 */
72 union {
73 uint16_t my_mtu;
74 uint16_t my_coc_mps;
75 };
76
77 union {
78 uint16_t peer_mtu;
79 uint16_t peer_coc_mps;
80 };
81
82 ble_l2cap_chan_flags flags;
83
84 struct os_mbuf *rx_buf;
85 uint16_t rx_len; /* Length of current reassembled rx packet. */
86
87 ble_l2cap_rx_fn *rx_fn;
88
89#if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) != 0
90 uint16_t psm;
91 struct ble_l2cap_coc_endpoint coc_rx;
92 struct ble_l2cap_coc_endpoint coc_tx;
93 uint16_t initial_credits;
94 ble_l2cap_event_fn *cb;
95 void *cb_arg;
96#endif
97};
98
99struct ble_l2cap_hdr {
100 uint16_t len;
101 uint16_t cid;
102};
103
104typedef int ble_l2cap_tx_fn(struct ble_hs_conn *conn,
105 struct ble_l2cap_chan *chan);
106
107#define BLE_L2CAP_CHAN_F_TXED_MTU 0x01 /* We have sent our MTU. */
108#define BLE_L2CAP_CHAN_F_DISCONNECTING 0x02 /* We have sent L2CAP Disconnect. */
109
110SLIST_HEAD(ble_l2cap_chan_list, ble_l2cap_chan);
111
112int ble_l2cap_parse_hdr(struct os_mbuf *om, int off,
113 struct ble_l2cap_hdr *l2cap_hdr);
114struct os_mbuf *ble_l2cap_prepend_hdr(struct os_mbuf *om, uint16_t cid,
115 uint16_t len);
116
117struct ble_l2cap_chan *ble_l2cap_chan_alloc(uint16_t conn_handle);
118void ble_l2cap_chan_free(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan);
119
120bool ble_l2cap_is_mtu_req_sent(const struct ble_l2cap_chan *chan);
121
122int ble_l2cap_rx(struct ble_hs_conn *conn,
123 struct hci_data_hdr *hci_hdr,
124 struct os_mbuf *om,
125 ble_l2cap_rx_fn **out_rx_cb,
126 int *out_reject_cid);
127int ble_l2cap_tx(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
128 struct os_mbuf *txom);
129
130void ble_l2cap_remove_rx(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan);
131
132int ble_l2cap_init(void);
133
134/* Below experimental API is available when BLE_VERSION >= 52 */
135int ble_l2cap_enhanced_connect(uint16_t conn_handle,
136 uint16_t psm, uint16_t mtu,
137 uint8_t num, struct os_mbuf *sdu_rx[],
138 ble_l2cap_event_fn *cb, void *cb_arg);
139int ble_l2cap_reconfig(struct ble_l2cap_chan *chans[], uint8_t num, uint16_t new_mtu);
140
141#ifdef __cplusplus
142}
143#endif
144
145#endif
Definition os_mbuf.h:86
Definition os_mempool.h:57