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