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_disc_req { 78 uint16_t dcid; 79 uint16_t scid; 80 } __attribute__((packed)); 81 82 struct ble_l2cap_sig_disc_rsp { 83 uint16_t dcid; 84 uint16_t scid; 85 } __attribute__((packed)); 86 87 struct ble_l2cap_sig_le_credits { 88 uint16_t scid; 89 uint16_t credits; 90 } __attribute__((packed)); 91 92 void ble_l2cap_sig_hdr_parse(void *payload, uint16_t len, 93 struct ble_l2cap_sig_hdr *hdr); 94 int ble_l2cap_sig_reject_tx(uint16_t conn_handle, 95 uint8_t id, uint16_t reason, 96 void *data, int data_len); 97 int ble_l2cap_sig_reject_invalid_cid_tx(uint16_t conn_handle, uint8_t id, 98 uint16_t src_cid, uint16_t dst_cid); 99 int ble_l2cap_sig_tx(uint16_t conn_handle, struct os_mbuf *txom); 100 void *ble_l2cap_sig_cmd_get(uint8_t opcode, uint8_t id, uint16_t len, 101 struct os_mbuf **txom); 102 #if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) != 0 103 int ble_l2cap_sig_coc_connect(uint16_t conn_handle, uint16_t psm, uint16_t mtu, 104 struct os_mbuf *sdu_rx, 105 ble_l2cap_event_fn *cb, void *cb_arg); 106 int ble_l2cap_sig_disconnect(struct ble_l2cap_chan *chan); 107 int ble_l2cap_sig_le_credits(uint16_t conn_handle, uint16_t scid, 108 uint16_t credits); 109 #else 110 #define ble_l2cap_sig_coc_connect(conn_handle, psm, mtu, sdu_rx, cb, cb_arg) \ 111 BLE_HS_ENOTSUP 112 #define ble_l2cap_sig_disconnect(chan) BLE_HS_ENOTSUP 113 #endif 114 115 void ble_l2cap_sig_conn_broken(uint16_t conn_handle, int reason); 116 int32_t ble_l2cap_sig_timer(void); 117 struct ble_l2cap_chan *ble_l2cap_sig_create_chan(uint16_t conn_handle); 118 int ble_l2cap_sig_init(void); 119 120 #ifdef __cplusplus 121 } 122 #endif 123 124 #endif 125