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 att_connect.h
18  *
19  * @brief declare connect function to be called.
20  *
21  */
22 
23 #ifndef ATT_CONNECT_H
24 #define ATT_CONNECT_H
25 
26 #include <stdint.h>
27 
28 #include "btstack.h"
29 #include "list.h"
30 #include "packet.h"
31 
32 #include "att_common.h"
33 #include "gap_if.h"
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 // connect and disconnect flag
40 #define CONNECTFLAG 1
41 #define DISCONNECTFLAG 2
42 
43 // connect status
44 #define DISCONNECTED 0
45 #define CONNECTING 1
46 #define CONFIGING 2
47 #define CONFIGED 3
48 #define CONNECTED 4
49 #define CONNECTIND 5
50 
51 // connect result
52 #define CONNECTIONSUCCESSFUL 0
53 #define CONNECTIONPENDING 1
54 
55 // pending status
56 #define AUTHENTICATIONPENDING 1
57 #define AUTHORIZATIONPENDING 2
58 
59 // le connect role
60 #define LEROLEMASTER 0
61 #define LEROLESLAVE 1
62 
63 enum { BR_EDR_BASIC_MODE, BR_EDR_ENHANCED_RETRANSMISSION_MODE = 3, BR_EDR_STREAMING_MODE };
64 
65 /**
66  * @brief received Le connect response.
67  *
68  * @param1 addr Indicates the pointer to BtAddr.
69  * @param2 aclHandle Indicates the aclHandle.
70  * @param3 role Indicates the role.
71  * @param4 status Indicates the status.
72  */
73 void AttLeConnected(const BtAddr *addr, uint16_t aclHandle, uint8_t role, uint8_t status);
74 
75 /**
76  * @brief received Le disconnect response.
77  *
78  * @param1 aclHandle Indicates the aclHandle.
79  * @param2 status Indicates the status.
80  * @param3 reason Indicates the reason.
81  */
82 void AttLeDisconnected(uint16_t aclHandle, uint8_t status, uint8_t reason);
83 
84 /**
85  * @brief received bredr connect request.
86  *
87  * @param1 lcid Indicates the lcid.
88  * @param2 id Indicates the id.
89  * @param3 info Indicates the pointer to L2capConnectionInfo.
90  * @param4 lpsm Indicates the lpsm.
91  * @param5 ctx Indicates the pointer to context.
92  */
93 void AttReceiveConnectionReq(
94     uint16_t lcid, uint8_t id, const L2capConnectionInfo *info, uint16_t lpsm, const void *ctx);
95 
96 /**
97  * @brief received bredr connect response.
98  *
99  * @param1 lcid Indicates the lcid.
100  * @param2 info Indicates the pointer to L2capConnectionInfo.
101  * @param3 result Indicates the result.
102  * @param4 status Indicates the status.
103  * @param5 ctx Indicates the pointer to context.
104  */
105 void AttReceiveConnectionRsp(
106     uint16_t lcid, const L2capConnectionInfo *info, uint16_t result, uint16_t status, const void *ctx);
107 
108 /**
109  * @brief received bredr config request.
110  *
111  * @param1 lcid Indicates the lcid.
112  * @param2 id Indicates the id.
113  * @param3 cfg Indicates the pointer to L2capConfigInfo.
114  * @param4 ctx Indicates the pointer to context.
115  */
116 void AttReceiveConfigReq(uint16_t lcid, uint8_t id, const L2capConfigInfo *cfg, const void *ctx);
117 
118 /**
119  * @brief received bredr config response.
120  *
121  * @param1 lcid Indicates the lcid.
122  * @param2 cfg Indicates the pointer to L2capConfigInfo.
123  * @param3 result Indicates the result.
124  * @param4 ctx Indicates the pointer to context.
125  */
126 void AttReceiveConfigRsp(uint16_t lcid, const L2capConfigInfo *cfg, uint16_t result, const void *ctx);
127 
128 /**
129  * @brief received bredr disconnect request.
130  *
131  * @param1 lcid Indicates the lcid.
132  * @param2 id Indicates the id.
133  * @param3 ctx Indicates the pointer to context.
134  */
135 void AttReceiveDisconnectionReq(uint16_t lcid, uint8_t id, const void *ctx);
136 
137 /**
138  * @brief received bredr disconnect abnormal.
139  *
140  * @param1 lcid Indicates the lcid.
141  * @param2 reason Indicates the reason.
142  * @param3 ctx Indicates the pointer to context.
143  */
144 void AttDisconnectAbnormal(uint16_t lcid, uint8_t reason, const void *ctx);
145 
146 /**
147  * @brief received bredr disconnect response.
148  *
149  * @param1 lcid Indicates the lcid.
150  * @param2 ctx Indicates the pointer to context.
151  */
152 void AttRecvDisconnectionRsp(uint16_t lcid, const void *ctx);
153 
154 /**
155  * @brief Initiatiove disconnect.
156  *
157  * @param1 connect Handle.
158  */
159 void InitiativeDisconnect(uint16_t connectHandle);
160 
161 #ifdef __cplusplus
162 }
163 #endif
164 
165 #endif  // ATT_CONNECT_H
166