1 /* 2 * Copyright (C) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 /** 17 * @file l2cap.h 18 * 19 * @brief Implement BDR part of bluetooth l2cap protocol 20 * 21 */ 22 23 #ifndef L2CAP_H 24 #define L2CAP_H 25 26 #include "l2cap_def.h" 27 28 #ifdef __cplusplus 29 extern "C" { 30 #endif // __cplusplus 31 32 /** 33 * @brief Initialize l2cap for BR/EDR 34 * 35 * @param traceLevel debug log level. 36 */ 37 void L2CAP_Initialize(int traceLevel); 38 39 /** 40 * @brief Finalize l2cap for BR/EDR 41 * 42 */ 43 void L2CAP_Finalize(); 44 45 /** 46 * @brief Register l2cap psm 47 * 48 * @param psm protocol psm 49 * @param svc callback for protocol psm 50 * @param context context for protocol psm 51 * @return Returns <b>BT_SUCCESS</b> if the operation is successful, otherwise the operation fails. 52 */ 53 int L2CAP_RegisterService(uint16_t lpsm, const L2capService *svc, void *context); 54 55 /** 56 * @brief Deregister l2cap psm 57 * 58 * @param psm protocol psm 59 * @return Returns <b>BT_SUCCESS</b> if the operation is successful, otherwise the operation fails. 60 */ 61 int L2CAP_DeregisterService(uint16_t lpsm); 62 63 /** 64 * @brief Send Connection Request packets 65 * 66 * @param addr remote bluetooth address 67 * @param lpsm local protocol psm 68 * @param rpsm remote protocol psm 69 * @param lcid OUT parameter, local channel id 70 * @return Returns <b>BT_SUCCESS</b> if the operation is successful, otherwise the operation fails. 71 */ 72 int L2CAP_ConnectReq(const BtAddr *addr, uint16_t lpsm, uint16_t rpsm, uint16_t *lcid); 73 74 /** 75 * @brief Send Connection Response packet 76 * 77 * @param lcid local channel id 78 * @param id identifier of l2cap command 79 * @param result indicates the outcome of the connection request 80 * @param status indicates the status of the connection 81 * @return Returns <b>BT_SUCCESS</b> if the operation is successful, otherwise the operation fails. 82 */ 83 int L2CAP_ConnectRsp(uint16_t lcid, uint8_t id, uint16_t result, uint16_t status); 84 85 /** 86 * @brief Send Configuration Request packet 87 * 88 * @param lcid local channel id 89 * @param cfg config parameter 90 * @return Returns <b>BT_SUCCESS</b> if the operation is successful, otherwise the operation fails. 91 */ 92 int L2CAP_ConfigReq(uint16_t lcid, const L2capConfigInfo *cfg); 93 94 /** 95 * @brief Send Configuration Response packet 96 * 97 * @param lcid local channel id 98 * @param id identifier of l2cap command 99 * @param cfg config parameter 100 * @param result config result 101 * @return Returns <b>BT_SUCCESS</b> if the operation is successful, otherwise the operation fails. 102 */ 103 int L2CAP_ConfigRsp(uint16_t lcid, uint8_t id, const L2capConfigInfo *cfg, uint16_t result); 104 105 /** 106 * @brief Send Disconnection Request packet 107 * 108 * @param lcid local channel id 109 * @return Returns <b>BT_SUCCESS</b> if the operation is successful, otherwise the operation fails. 110 */ 111 int L2CAP_DisconnectionReq(uint16_t lcid); 112 113 /** 114 * @brief Send Disconnection Response packet 115 * 116 * @param lcid local channel id 117 * @param id identifier of l2cap command 118 * @return Returns <b>BT_SUCCESS</b> if the operation is successful, otherwise the operation fails. 119 */ 120 int L2CAP_DisconnectionRsp(uint16_t lcid, uint8_t id); 121 122 /** 123 * @brief In Enhanced Retransmission mode, send RNR to information remote to stop sending data 124 * 125 * @param lcid local channel id 126 * @param isBusy flag to indicate busy state, 0 -- non busy, 1 -- busy 127 * @return Returns <b>BT_SUCCESS</b> if the operation is successful, otherwise the operation fails. 128 */ 129 int L2CAP_LocalBusy(uint16_t lcid, uint8_t isBusy); 130 131 /** 132 * @brief Send l2cap data packet 133 * 134 * @param lcid local channel id 135 * @param pkt packet of data 136 * @return Returns <b>BT_SUCCESS</b> if the operation is successful, otherwise the operation fails. 137 */ 138 int L2CAP_SendData(uint16_t lcid, Packet *pkt); 139 140 /** 141 * @brief Register Echo callback 142 * 143 * @param echoCallback callback of echo 144 * @param context context of caller 145 * @return Returns <b>BT_SUCCESS</b> if the operation is successful, otherwise the operation fails. 146 */ 147 int L2CAP_RegisterEcho(const L2capEcho *echoCallback, void *context); 148 149 /** 150 * @brief Deregister Echo callback 151 * 152 */ 153 int L2CAP_DeregisterEcho(); 154 155 /** 156 * @brief Send Echo Request packet 157 * 158 * @param aclHandle ACL Handle 159 * @param data data of echo 160 * @param dataLen length of data 161 * @return Returns <b>BT_SUCCESS</b> if the operation is successful, otherwise the operation fails. 162 */ 163 int L2CAP_EchoReq(uint16_t aclHandle, const uint8_t *data, uint16_t dataLen); 164 165 /** 166 * @brief Send Echo Response packet received 167 * 168 * @param aclHandle ACL Handle 169 * @param id identifier of l2cap command 170 * @param data data of echo 171 * @param dataLen length of data 172 * @return Returns <b>BT_SUCCESS</b> if the operation is successful, otherwise the operation fails. 173 */ 174 int L2CAP_EchoRsp(uint16_t aclHandle, uint8_t id, const uint8_t *data, uint16_t dataLen); 175 176 #ifdef __cplusplus 177 } 178 #endif // __cplusplus 179 180 #endif // L2CAP_H