• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_if.h
18  *
19  * @brief Interface of bluetooth l2cap protocol BR/EDR part
20  *
21  */
22 
23 #ifndef L2CAP_IF_H
24 #define L2CAP_IF_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 BTSTACK_API L2CIF_Initialize(int traceLevel);
38 
39 /**
40  * @brief Finalize l2cap for BR/EDR
41  *
42  */
43 void BTSTACK_API L2CIF_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 BTSTACK_API L2CIF_RegisterService(
54     uint16_t lpsm, const L2capService *svc, void *context, void (*cb)(uint16_t lpsm, int result));
55 
56 /**
57  * @brief Deregister l2cap psm
58  *
59  * @param psm protocol psm
60  */
61 void BTSTACK_API L2CIF_DeregisterService(uint16_t lpsm, void (*cb)(uint16_t lpsm, int result));
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 BTSTACK_API L2CIF_ConnectReq(const BtAddr *addr, uint16_t lpsm, uint16_t rpsm, void *context,
73     void (*cb)(const BtAddr *addr, uint16_t lcid, int result, void *context));
74 
75 /**
76  * @brief Send Connection Response packet
77  *
78  * @param lcid local channel id
79  * @param id identifier of l2cap command
80  * @param result indicates the outcome of the connection request
81  * @param status indicates the status of the connection
82  */
83 void BTSTACK_API L2CIF_ConnectRsp(
84     uint16_t lcid, uint8_t id, uint16_t result, uint16_t status, void (*cb)(uint16_t lcid, int result));
85 
86 /**
87  * @brief Send Configuration Request packet
88  *
89  * @param lcid local channel id
90  * @param cfg config parameter
91  * @return Returns <b>BT_SUCCESS</b> if the operation is successful, otherwise the operation fails.
92  */
93 int BTSTACK_API L2CIF_ConfigReq(uint16_t lcid, const L2capConfigInfo *cfg, void (*cb)(uint16_t lcid, int result));
94 
95 /**
96  * @brief Send Configuration Response packet
97  *
98  * @param lcid local channel id
99  * @param id identifier of l2cap command
100  * @param cfg config parameter
101  * @param result config result
102  * @return Returns <b>BT_SUCCESS</b> if the operation is successful, otherwise the operation fails.
103  */
104 int BTSTACK_API L2CIF_ConfigRsp(
105     uint16_t lcid, uint8_t id, const L2capConfigInfo *cfg, uint16_t result, void (*cb)(uint16_t lcid, int result));
106 
107 /**
108  * @brief Send Disconnection Request packet
109  *
110  * @param lcid local channel id
111  */
112 void BTSTACK_API L2CIF_DisconnectionReq(uint16_t lcid, void (*cb)(uint16_t lcid, int result));
113 
114 /**
115  * @brief Send Disconnection Response packet
116  *
117  * @param lcid local channel id
118  * @param id identifier of l2cap command
119  */
120 void BTSTACK_API L2CIF_DisconnectionRsp(uint16_t lcid, uint8_t id, void (*cb)(uint16_t lcid, int result));
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  */
128 void BTSTACK_API L2CIF_LocalBusy(uint16_t lcid, uint8_t isBusy, void (*cb)(uint16_t lcid, int result));
129 
130 /**
131  * @brief Send l2cap data packet
132  *
133  * @param lcid local channel id
134  * @param pkt packet of data
135  * @return Returns <b>BT_SUCCESS</b> if the operation is successful, otherwise the operation fails.
136  */
137 int BTSTACK_API L2CIF_SendData(uint16_t lcid, const Packet *pkt, void (*cb)(uint16_t lcid, int result));
138 
139 /**
140  * @brief Register Echo callback
141  *
142  * @param echoCallback callback of echo
143  * @param context context of caller
144  * @return Returns <b>BT_SUCCESS</b> if the operation is successful, otherwise the operation fails.
145  */
146 int BTSTACK_API L2CIF_RegisterEcho(const L2capEcho *echoCallback, void *context);
147 
148 /**
149  * @brief Deregister Echo callback
150  *
151  */
152 void BTSTACK_API L2CIF_DeregisterEcho();
153 
154 /**
155  * @brief Send Echo Request packet
156  *
157  * @param aclHandle ACL Handle
158  * @param data data of echo
159  * @param dataLen length of data
160  */
161 void BTSTACK_API L2CIF_EchoReq(
162     uint16_t aclHandle, const uint8_t *data, uint16_t dataLen, void (*cb)(uint16_t aclHandle, int result));
163 
164 /**
165  * @brief Send Echo Response packet received
166  *
167  * @param aclHandle ACL Handle
168  * @param id identifier of l2cap command
169  * @param data data of echo
170  * @param dataLen length of data
171  */
172 void BTSTACK_API L2CIF_EchoRsp(
173     uint16_t aclHandle, uint8_t id, const uint8_t *data, uint16_t dataLen, void (*cb)(uint16_t aclHandle, int result));
174 
175 #ifdef __cplusplus
176 }
177 #endif  // __cplusplus
178 
179 #endif  // L2CAP_IF_H