1*042d53a7SEvalZero /* 2*042d53a7SEvalZero * Licensed to the Apache Software Foundation (ASF) under one 3*042d53a7SEvalZero * or more contributor license agreements. See the NOTICE file 4*042d53a7SEvalZero * distributed with this work for additional information 5*042d53a7SEvalZero * regarding copyright ownership. The ASF licenses this file 6*042d53a7SEvalZero * to you under the Apache License, Version 2.0 (the 7*042d53a7SEvalZero * "License"); you may not use this file except in compliance 8*042d53a7SEvalZero * with the License. You may obtain a copy of the License at 9*042d53a7SEvalZero * 10*042d53a7SEvalZero * http://www.apache.org/licenses/LICENSE-2.0 11*042d53a7SEvalZero * 12*042d53a7SEvalZero * Unless required by applicable law or agreed to in writing, 13*042d53a7SEvalZero * software distributed under the License is distributed on an 14*042d53a7SEvalZero * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15*042d53a7SEvalZero * KIND, either express or implied. See the License for the 16*042d53a7SEvalZero * specific language governing permissions and limitations 17*042d53a7SEvalZero * under the License. 18*042d53a7SEvalZero */ 19*042d53a7SEvalZero 20*042d53a7SEvalZero #ifndef H_L2CAP_PRIV_ 21*042d53a7SEvalZero #define H_L2CAP_PRIV_ 22*042d53a7SEvalZero 23*042d53a7SEvalZero #include "ble_l2cap_coc_priv.h" 24*042d53a7SEvalZero #include "host/ble_l2cap.h" 25*042d53a7SEvalZero #include <inttypes.h> 26*042d53a7SEvalZero #include "stats/stats.h" 27*042d53a7SEvalZero #include "os/queue.h" 28*042d53a7SEvalZero #include "os/os_mbuf.h" 29*042d53a7SEvalZero #ifdef __cplusplus 30*042d53a7SEvalZero extern "C" { 31*042d53a7SEvalZero #endif 32*042d53a7SEvalZero 33*042d53a7SEvalZero struct ble_hs_conn; 34*042d53a7SEvalZero struct hci_data_hdr; 35*042d53a7SEvalZero 36*042d53a7SEvalZero STATS_SECT_START(ble_l2cap_stats) 37*042d53a7SEvalZero STATS_SECT_ENTRY(chan_create) 38*042d53a7SEvalZero STATS_SECT_ENTRY(chan_delete) 39*042d53a7SEvalZero STATS_SECT_ENTRY(update_init) 40*042d53a7SEvalZero STATS_SECT_ENTRY(update_rx) 41*042d53a7SEvalZero STATS_SECT_ENTRY(update_fail) 42*042d53a7SEvalZero STATS_SECT_ENTRY(proc_timeout) 43*042d53a7SEvalZero STATS_SECT_ENTRY(sig_tx) 44*042d53a7SEvalZero STATS_SECT_ENTRY(sig_rx) 45*042d53a7SEvalZero STATS_SECT_ENTRY(sm_tx) 46*042d53a7SEvalZero STATS_SECT_ENTRY(sm_rx) 47*042d53a7SEvalZero STATS_SECT_END 48*042d53a7SEvalZero extern STATS_SECT_DECL(ble_l2cap_stats) ble_l2cap_stats; 49*042d53a7SEvalZero 50*042d53a7SEvalZero extern struct os_mempool ble_l2cap_chan_pool; 51*042d53a7SEvalZero 52*042d53a7SEvalZero /* This is nimble specific; packets sent to the black hole CID do not elicit 53*042d53a7SEvalZero * an "invalid CID" response. 54*042d53a7SEvalZero */ 55*042d53a7SEvalZero #define BLE_L2CAP_CID_BLACK_HOLE 0xffff 56*042d53a7SEvalZero 57*042d53a7SEvalZero #define BLE_L2CAP_HDR_SZ 4 58*042d53a7SEvalZero 59*042d53a7SEvalZero typedef uint8_t ble_l2cap_chan_flags; 60*042d53a7SEvalZero 61*042d53a7SEvalZero typedef int ble_l2cap_rx_fn(struct ble_l2cap_chan *chan); 62*042d53a7SEvalZero 63*042d53a7SEvalZero struct ble_l2cap_chan { 64*042d53a7SEvalZero SLIST_ENTRY(ble_l2cap_chan) next; 65*042d53a7SEvalZero uint16_t conn_handle; 66*042d53a7SEvalZero uint16_t dcid; 67*042d53a7SEvalZero uint16_t scid; 68*042d53a7SEvalZero uint16_t my_mtu; 69*042d53a7SEvalZero uint16_t peer_mtu; /* 0 if not exchanged. */ 70*042d53a7SEvalZero ble_l2cap_chan_flags flags; 71*042d53a7SEvalZero 72*042d53a7SEvalZero struct os_mbuf *rx_buf; 73*042d53a7SEvalZero uint16_t rx_len; /* Length of current reassembled rx packet. */ 74*042d53a7SEvalZero 75*042d53a7SEvalZero ble_l2cap_rx_fn *rx_fn; 76*042d53a7SEvalZero 77*042d53a7SEvalZero #if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) != 0 78*042d53a7SEvalZero uint16_t psm; 79*042d53a7SEvalZero struct ble_l2cap_coc_endpoint coc_rx; 80*042d53a7SEvalZero struct ble_l2cap_coc_endpoint coc_tx; 81*042d53a7SEvalZero uint16_t initial_credits; 82*042d53a7SEvalZero ble_l2cap_event_fn *cb; 83*042d53a7SEvalZero void *cb_arg; 84*042d53a7SEvalZero #endif 85*042d53a7SEvalZero }; 86*042d53a7SEvalZero 87*042d53a7SEvalZero struct ble_l2cap_hdr { 88*042d53a7SEvalZero uint16_t len; 89*042d53a7SEvalZero uint16_t cid; 90*042d53a7SEvalZero }; 91*042d53a7SEvalZero 92*042d53a7SEvalZero typedef int ble_l2cap_tx_fn(struct ble_hs_conn *conn, 93*042d53a7SEvalZero struct ble_l2cap_chan *chan); 94*042d53a7SEvalZero 95*042d53a7SEvalZero #define BLE_L2CAP_CHAN_F_TXED_MTU 0x01 /* We have sent our MTU. */ 96*042d53a7SEvalZero 97*042d53a7SEvalZero SLIST_HEAD(ble_l2cap_chan_list, ble_l2cap_chan); 98*042d53a7SEvalZero 99*042d53a7SEvalZero int ble_l2cap_parse_hdr(struct os_mbuf *om, int off, 100*042d53a7SEvalZero struct ble_l2cap_hdr *l2cap_hdr); 101*042d53a7SEvalZero struct os_mbuf *ble_l2cap_prepend_hdr(struct os_mbuf *om, uint16_t cid, 102*042d53a7SEvalZero uint16_t len); 103*042d53a7SEvalZero 104*042d53a7SEvalZero struct ble_l2cap_chan *ble_l2cap_chan_alloc(uint16_t conn_handle); 105*042d53a7SEvalZero void ble_l2cap_chan_free(struct ble_l2cap_chan *chan); 106*042d53a7SEvalZero 107*042d53a7SEvalZero bool ble_l2cap_is_mtu_req_sent(const struct ble_l2cap_chan *chan); 108*042d53a7SEvalZero 109*042d53a7SEvalZero int ble_l2cap_rx(struct ble_hs_conn *conn, 110*042d53a7SEvalZero struct hci_data_hdr *hci_hdr, 111*042d53a7SEvalZero struct os_mbuf *om, 112*042d53a7SEvalZero ble_l2cap_rx_fn **out_rx_cb, 113*042d53a7SEvalZero int *out_reject_cid); 114*042d53a7SEvalZero int ble_l2cap_tx(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan, 115*042d53a7SEvalZero struct os_mbuf *txom); 116*042d53a7SEvalZero 117*042d53a7SEvalZero void ble_l2cap_remove_rx(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan); 118*042d53a7SEvalZero 119*042d53a7SEvalZero int ble_l2cap_init(void); 120*042d53a7SEvalZero 121*042d53a7SEvalZero #ifdef __cplusplus 122*042d53a7SEvalZero } 123*042d53a7SEvalZero #endif 124*042d53a7SEvalZero 125*042d53a7SEvalZero #endif 126