119e95205Sopenharmony_ci/*
219e95205Sopenharmony_ci * Copyright (C) 2021 Huawei Device Co., Ltd.
319e95205Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
419e95205Sopenharmony_ci * you may not use this file except in compliance with the License.
519e95205Sopenharmony_ci * You may obtain a copy of the License at
619e95205Sopenharmony_ci *
719e95205Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
819e95205Sopenharmony_ci *
919e95205Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1019e95205Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1119e95205Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1219e95205Sopenharmony_ci * See the License for the specific language governing permissions and
1319e95205Sopenharmony_ci * limitations under the License.
1419e95205Sopenharmony_ci */
1519e95205Sopenharmony_ci
1619e95205Sopenharmony_ci/**
1719e95205Sopenharmony_ci * @file l2cap.h
1819e95205Sopenharmony_ci *
1919e95205Sopenharmony_ci * @brief Implement BDR part of bluetooth l2cap protocol
2019e95205Sopenharmony_ci *
2119e95205Sopenharmony_ci */
2219e95205Sopenharmony_ci
2319e95205Sopenharmony_ci#ifndef L2CAP_H
2419e95205Sopenharmony_ci#define L2CAP_H
2519e95205Sopenharmony_ci
2619e95205Sopenharmony_ci#include "l2cap_def.h"
2719e95205Sopenharmony_ci
2819e95205Sopenharmony_ci#ifdef __cplusplus
2919e95205Sopenharmony_ciextern "C" {
3019e95205Sopenharmony_ci#endif  // __cplusplus
3119e95205Sopenharmony_ci
3219e95205Sopenharmony_ci/**
3319e95205Sopenharmony_ci * @brief Initialize l2cap for BR/EDR
3419e95205Sopenharmony_ci *
3519e95205Sopenharmony_ci * @param traceLevel debug log level.
3619e95205Sopenharmony_ci */
3719e95205Sopenharmony_civoid L2CAP_Initialize(int traceLevel);
3819e95205Sopenharmony_ci
3919e95205Sopenharmony_ci/**
4019e95205Sopenharmony_ci * @brief Finalize l2cap for BR/EDR
4119e95205Sopenharmony_ci *
4219e95205Sopenharmony_ci */
4319e95205Sopenharmony_civoid L2CAP_Finalize();
4419e95205Sopenharmony_ci
4519e95205Sopenharmony_ci/**
4619e95205Sopenharmony_ci * @brief Register l2cap psm
4719e95205Sopenharmony_ci *
4819e95205Sopenharmony_ci * @param psm protocol psm
4919e95205Sopenharmony_ci * @param svc callback for protocol psm
5019e95205Sopenharmony_ci * @param context context for protocol psm
5119e95205Sopenharmony_ci * @return Returns <b>BT_SUCCESS</b> if the operation is successful, otherwise the operation fails.
5219e95205Sopenharmony_ci */
5319e95205Sopenharmony_ciint L2CAP_RegisterService(uint16_t lpsm, const L2capService *svc, void *context);
5419e95205Sopenharmony_ci
5519e95205Sopenharmony_ci/**
5619e95205Sopenharmony_ci * @brief Deregister l2cap psm
5719e95205Sopenharmony_ci *
5819e95205Sopenharmony_ci * @param psm protocol psm
5919e95205Sopenharmony_ci * @return Returns <b>BT_SUCCESS</b> if the operation is successful, otherwise the operation fails.
6019e95205Sopenharmony_ci */
6119e95205Sopenharmony_ciint L2CAP_DeregisterService(uint16_t lpsm);
6219e95205Sopenharmony_ci
6319e95205Sopenharmony_ci/**
6419e95205Sopenharmony_ci * @brief Send Connection Request packets
6519e95205Sopenharmony_ci *
6619e95205Sopenharmony_ci * @param addr remote bluetooth address
6719e95205Sopenharmony_ci * @param lpsm local protocol psm
6819e95205Sopenharmony_ci * @param rpsm remote protocol psm
6919e95205Sopenharmony_ci * @param lcid OUT parameter, local channel id
7019e95205Sopenharmony_ci * @return Returns <b>BT_SUCCESS</b> if the operation is successful, otherwise the operation fails.
7119e95205Sopenharmony_ci */
7219e95205Sopenharmony_ciint L2CAP_ConnectReq(const BtAddr *addr, uint16_t lpsm, uint16_t rpsm, uint16_t *lcid);
7319e95205Sopenharmony_ci
7419e95205Sopenharmony_ci/**
7519e95205Sopenharmony_ci * @brief Send Connection Response packet
7619e95205Sopenharmony_ci *
7719e95205Sopenharmony_ci * @param lcid local channel id
7819e95205Sopenharmony_ci * @param id identifier of l2cap command
7919e95205Sopenharmony_ci * @param result indicates the outcome of the connection request
8019e95205Sopenharmony_ci * @param status indicates the status of the connection
8119e95205Sopenharmony_ci * @return Returns <b>BT_SUCCESS</b> if the operation is successful, otherwise the operation fails.
8219e95205Sopenharmony_ci */
8319e95205Sopenharmony_ciint L2CAP_ConnectRsp(uint16_t lcid, uint8_t id, uint16_t result, uint16_t status);
8419e95205Sopenharmony_ci
8519e95205Sopenharmony_ci/**
8619e95205Sopenharmony_ci * @brief Send Configuration Request packet
8719e95205Sopenharmony_ci *
8819e95205Sopenharmony_ci * @param lcid local channel id
8919e95205Sopenharmony_ci * @param cfg config parameter
9019e95205Sopenharmony_ci * @return Returns <b>BT_SUCCESS</b> if the operation is successful, otherwise the operation fails.
9119e95205Sopenharmony_ci */
9219e95205Sopenharmony_ciint L2CAP_ConfigReq(uint16_t lcid, const L2capConfigInfo *cfg);
9319e95205Sopenharmony_ci
9419e95205Sopenharmony_ci/**
9519e95205Sopenharmony_ci * @brief Send Configuration Response packet
9619e95205Sopenharmony_ci *
9719e95205Sopenharmony_ci * @param lcid local channel id
9819e95205Sopenharmony_ci * @param id identifier of l2cap command
9919e95205Sopenharmony_ci * @param cfg config parameter
10019e95205Sopenharmony_ci * @param result config result
10119e95205Sopenharmony_ci * @return Returns <b>BT_SUCCESS</b> if the operation is successful, otherwise the operation fails.
10219e95205Sopenharmony_ci */
10319e95205Sopenharmony_ciint L2CAP_ConfigRsp(uint16_t lcid, uint8_t id, const L2capConfigInfo *cfg, uint16_t result);
10419e95205Sopenharmony_ci
10519e95205Sopenharmony_ci/**
10619e95205Sopenharmony_ci * @brief Send Disconnection Request packet
10719e95205Sopenharmony_ci *
10819e95205Sopenharmony_ci * @param lcid local channel id
10919e95205Sopenharmony_ci * @return Returns <b>BT_SUCCESS</b> if the operation is successful, otherwise the operation fails.
11019e95205Sopenharmony_ci */
11119e95205Sopenharmony_ciint L2CAP_DisconnectionReq(uint16_t lcid);
11219e95205Sopenharmony_ci
11319e95205Sopenharmony_ci/**
11419e95205Sopenharmony_ci * @brief Send Disconnection Response packet
11519e95205Sopenharmony_ci *
11619e95205Sopenharmony_ci * @param lcid local channel id
11719e95205Sopenharmony_ci * @param id identifier of l2cap command
11819e95205Sopenharmony_ci * @return Returns <b>BT_SUCCESS</b> if the operation is successful, otherwise the operation fails.
11919e95205Sopenharmony_ci */
12019e95205Sopenharmony_ciint L2CAP_DisconnectionRsp(uint16_t lcid, uint8_t id);
12119e95205Sopenharmony_ci
12219e95205Sopenharmony_ci/**
12319e95205Sopenharmony_ci * @brief In Enhanced Retransmission mode, send RNR to information remote to stop sending data
12419e95205Sopenharmony_ci *
12519e95205Sopenharmony_ci * @param lcid local channel id
12619e95205Sopenharmony_ci * @param isBusy flag to indicate busy state, 0 -- non busy, 1 -- busy
12719e95205Sopenharmony_ci * @return Returns <b>BT_SUCCESS</b> if the operation is successful, otherwise the operation fails.
12819e95205Sopenharmony_ci */
12919e95205Sopenharmony_ciint L2CAP_LocalBusy(uint16_t lcid, uint8_t isBusy);
13019e95205Sopenharmony_ci
13119e95205Sopenharmony_ci/**
13219e95205Sopenharmony_ci * @brief Send l2cap data packet
13319e95205Sopenharmony_ci *
13419e95205Sopenharmony_ci * @param lcid local channel id
13519e95205Sopenharmony_ci * @param pkt packet of data
13619e95205Sopenharmony_ci * @return Returns <b>BT_SUCCESS</b> if the operation is successful, otherwise the operation fails.
13719e95205Sopenharmony_ci */
13819e95205Sopenharmony_ciint L2CAP_SendData(uint16_t lcid, Packet *pkt);
13919e95205Sopenharmony_ci
14019e95205Sopenharmony_ci/**
14119e95205Sopenharmony_ci * @brief Register Echo callback
14219e95205Sopenharmony_ci *
14319e95205Sopenharmony_ci * @param echoCallback callback of echo
14419e95205Sopenharmony_ci * @param context context of caller
14519e95205Sopenharmony_ci * @return Returns <b>BT_SUCCESS</b> if the operation is successful, otherwise the operation fails.
14619e95205Sopenharmony_ci */
14719e95205Sopenharmony_ciint L2CAP_RegisterEcho(const L2capEcho *echoCallback, void *context);
14819e95205Sopenharmony_ci
14919e95205Sopenharmony_ci/**
15019e95205Sopenharmony_ci * @brief Deregister Echo callback
15119e95205Sopenharmony_ci *
15219e95205Sopenharmony_ci */
15319e95205Sopenharmony_ciint L2CAP_DeregisterEcho();
15419e95205Sopenharmony_ci
15519e95205Sopenharmony_ci/**
15619e95205Sopenharmony_ci * @brief Send Echo Request packet
15719e95205Sopenharmony_ci *
15819e95205Sopenharmony_ci * @param aclHandle ACL Handle
15919e95205Sopenharmony_ci * @param data data of echo
16019e95205Sopenharmony_ci * @param dataLen length of data
16119e95205Sopenharmony_ci * @return Returns <b>BT_SUCCESS</b> if the operation is successful, otherwise the operation fails.
16219e95205Sopenharmony_ci */
16319e95205Sopenharmony_ciint L2CAP_EchoReq(uint16_t aclHandle, const uint8_t *data, uint16_t dataLen);
16419e95205Sopenharmony_ci
16519e95205Sopenharmony_ci/**
16619e95205Sopenharmony_ci * @brief Send Echo Response packet received
16719e95205Sopenharmony_ci *
16819e95205Sopenharmony_ci * @param aclHandle ACL Handle
16919e95205Sopenharmony_ci * @param id identifier of l2cap command
17019e95205Sopenharmony_ci * @param data data of echo
17119e95205Sopenharmony_ci * @param dataLen length of data
17219e95205Sopenharmony_ci * @return Returns <b>BT_SUCCESS</b> if the operation is successful, otherwise the operation fails.
17319e95205Sopenharmony_ci */
17419e95205Sopenharmony_ciint L2CAP_EchoRsp(uint16_t aclHandle, uint8_t id, const uint8_t *data, uint16_t dataLen);
17519e95205Sopenharmony_ci
17619e95205Sopenharmony_ci#ifdef __cplusplus
17719e95205Sopenharmony_ci}
17819e95205Sopenharmony_ci#endif  // __cplusplus
17919e95205Sopenharmony_ci
18019e95205Sopenharmony_ci#endif  // L2CAP_H