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_le.h 18 * 19 * @brief Implement LE part of bluetooth l2cap protocol 20 * 21 */ 22 23 #ifndef L2CAP_LE_H 24 #define L2CAP_LE_H 25 26 #include "l2cap_def.h" 27 28 #ifdef __cplusplus 29 extern "C" { 30 #endif // __cplusplus 31 32 /** 33 * @brief Initialize l2cap for LE 34 * 35 * @param traceLevel debug log level. 36 */ 37 void L2CAP_LeInitialize(int traceLevel); 38 39 /** 40 * @brief Finalize l2cap for LE 41 * 42 */ 43 void L2CAP_LeFinalize(); 44 45 /** 46 * @brief Register l2cap le_psm for LE Credit Based Connection 47 * 48 * @param lpsm protocol psm 49 * @param svc callback for protocol psm 50 * @return Returns <b>BT_SUCCESS</b> if the operation is successful, otherwise the operation fails. 51 */ 52 int L2CAP_LeRegisterService(uint16_t lpsm, const L2capLeService *svc, void *context); 53 54 /** 55 * @brief Deregister l2cap le_psm for LE Credit Based Connection 56 * 57 * @param lpsm protocol psm 58 * @return Returns <b>BT_SUCCESS</b> if the operation is successful, otherwise the operation fails. 59 */ 60 int L2CAP_LeDeregisterService(uint16_t lpsm); 61 62 /** 63 * @brief Send LE Credit Based Connection Request packet 64 * 65 * @param addr remote bluetooth address 66 * @param cfg config parameter 67 * @param lcid OUT parameter, local channel id 68 * @return Returns <b>BT_SUCCESS</b> if the operation is successful, otherwise the operation fails. 69 */ 70 int L2CAP_LeCreditBasedConnectionReq( 71 const BtAddr *addr, uint16_t lpsm, uint16_t rpsm, const L2capLeConfigInfo *cfg, uint16_t *lcid); 72 73 /** 74 * @briefSend LE Credit Based Connection Response packet 75 * 76 * @param lcid local channel id 77 * @param id identifier of l2cap command 78 * @param cfg config parameter 79 * @param result result of connection 80 * @return Returns <b>BT_SUCCESS</b> if the operation is successful, otherwise the operation fails. 81 */ 82 int L2CAP_LeCreditBasedConnectionRsp(uint16_t lcid, uint8_t id, const L2capLeConfigInfo *cfg, uint16_t result); 83 84 /** 85 * @brief Send Disconnection Request packet 86 * 87 * @param lcid local channel id 88 * @return Returns <b>BT_SUCCESS</b> if the operation is successful, otherwise the operation fails. 89 */ 90 int L2CAP_LeDisconnectionReq(uint16_t lcid); 91 92 /** 93 * @brief Send Disconnection Response packet 94 * 95 * @param lcid local channel id 96 * @param id identifier of l2cap command 97 * @return Returns <b>BT_SUCCESS</b> if the operation is successful, otherwise the operation fails. 98 */ 99 int L2CAP_LeDisconnectionRsp(uint16_t lcid, uint8_t id); 100 101 /** 102 * @brief Send Le data packet for LE Credit Based Connection 103 * 104 * @param lcid local channel id 105 * @param pkt packet of data 106 * @return Returns <b>BT_SUCCESS</b> if the operation is successful, otherwise the operation fails. 107 */ 108 int L2CAP_LeSendData(uint16_t lcid, Packet *pkt); 109 110 /** 111 * @brief Register LE Fix Channel data callback 112 * 113 * @param cid fix channel id 114 * @param chan callback of fix channel 115 * @return Returns <b>BT_SUCCESS</b> if the operation is successful, otherwise the operation fails. 116 */ 117 int L2CAP_LeRegisterFixChannel(uint16_t cid, const L2capLeFixChannel *chan); 118 119 /** 120 * @brief Deregister LE Fix Channel data callback 121 * 122 * @param cid fix channel id 123 * @return Returns <b>BT_SUCCESS</b> if the operation is successful, otherwise the operation fails. 124 */ 125 int L2CAP_LeDeregisterFixChannel(uint16_t cid); 126 127 /** 128 * @brief Create Le ACL connection 129 * 130 * @param addr remote bluetooth address 131 * @param param connection parameter 132 * @return Returns <b>BT_SUCCESS</b> if the operation is successful, otherwise the operation fails. 133 */ 134 int L2CAP_LeConnect(const BtAddr *addr, const L2capLeConnectionParameter *param); 135 136 /** 137 * @brief Cancel Le ACL connection 138 * 139 * @return Returns <b>BT_SUCCESS</b> if the operation is successful, otherwise the operation fails. 140 */ 141 int L2CAP_LeConnectCancel(const BtAddr *addr); 142 143 /** 144 * @brief Destroy Le ACL connection 145 * 146 * @param aclHandle ACL handle 147 * @return Returns <b>BT_SUCCESS</b> if the operation is successful, otherwise the operation fails. 148 */ 149 int L2CAP_LeDisconnect(uint16_t aclHandle); 150 151 /** 152 * @brief Send LE Fix Channel data 153 * 154 * @param aclHandle ACL handle 155 * @param cid fix channel id 156 * @param pkt packet of data 157 * @return Returns <b>BT_SUCCESS</b> if the operation is successful, otherwise the operation fails. 158 */ 159 int L2CAP_LeSendFixChannelData(uint16_t aclHandle, uint16_t cid, const Packet *pkt); 160 161 /** 162 * @brief Register LE connection parameter update 163 * 164 * @param cb callback for connection parameter update 165 * @param context context of caller 166 * @return Returns <b>BT_SUCCESS</b> if the operation is successful, otherwise the operation fails. 167 */ 168 int L2CAP_LeRegisterConnectionParameterUpdate(const L2capLeConnectionParameterUpdate *cb, void *context); 169 170 /** 171 * @brief Deregister LE connection parameter update 172 * 173 * @return Returns <b>BT_SUCCESS</b> if the operation is successful, otherwise the operation fails. 174 */ 175 int L2CAP_LeDeregisterConnectionParameterUpdate(); 176 177 /** 178 * @brief Send Connection Parameter Update Request packet, 179 * This command shall only be sent from the LE peripheral device to the LE center. 180 * 181 * @param aclHandle ACL handle 182 * @param param connection parameter 183 * @return Returns <b>BT_SUCCESS</b> if the operation is successful, otherwise the operation fails. 184 */ 185 int L2CAP_LeConnectionParameterUpdateReq(uint16_t aclHandle, const L2capLeConnectionParameter *param); 186 187 /** 188 * @brief Send Connection Parameter Update Response packet 189 * 190 * @param aclHandle ACL handle 191 * @param id cidentifier of l2cap command 192 * @param result result of the request 193 * @return Returns <b>BT_SUCCESS</b> if the operation is successful, otherwise the operation fails. 194 */ 195 int L2CAP_LeConnectionParameterUpdateRsp(uint16_t aclHandle, uint8_t id, uint16_t result); 196 197 #ifdef __cplusplus 198 } 199 #endif // __cplusplus 200 201 #endif // L2CAP_LE_H 202