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 #ifndef CLASSIC_DEFS_H
17 #define CLASSIC_DEFS_H
18 
19 #include "gap_if.h"
20 #include "raw_address.h"
21 
22 /*
23  * @brief The bluetooth system.
24  */
25 namespace OHOS {
26 namespace bluetooth {
27 constexpr int SUCCESS = 0;
28 constexpr int FAILED = -1;
29 
30 constexpr int REMOTE_TYPE_BREDR = 0;
31 constexpr int REMOTE_TYPE_LE = 1;
32 constexpr int REMOTE_TYPE_BREDR_LE = 2;
33 
34 const std::string DEFAULT_DEVICE_NAME = "BluetoothDevice";
35 const std::string DEFAULT_PASSKEY = "12345678";
36 constexpr int DEFAULT_CLASS_OF_DEVICE = 0x2A0104;
37 constexpr int DEFAULT_SCANMODE_DURATION_MILLIS = 120000;
38 constexpr int DEFAULT_DISCOVERY_TIMEOUT_MS = 12800;
39 constexpr int DISCOVERY_DEVICE_LIST_MAX = 30;
40 constexpr int DEFAULT_INQ_MAX_DURATION = 10;
41 constexpr int DEFAULT_INQ_MIN_DURATION = 1;
42 
43 constexpr int DEFAULT_HW_TIMEOUT = 5000;
44 constexpr int MILLISECOND_UNIT = 1000;
45 constexpr int MOVE_ONE_BYTE = 8;
46 constexpr int COD_SIZE = 3;
47 
48 constexpr int PAIR_CANCELING = 0x04;
49 constexpr int PAIR_INVALID_LINK_KEY_TYPE = -1;
50 constexpr int PAIR_LINK_KEY_SIZE = 0x10;
51 constexpr int PAIR_PINCODE_SIZE = 0x10;
52 constexpr int PAIR_CONFIRM_TYPE_INVALID = 0x00;
53 constexpr int PAIR_CONFIRM_TYPE_OOB = 0x06;
54 constexpr int PAIR_CONFIRM_STATE_INVALID = 0x00;
55 constexpr int PAIR_CONFIRM_STATE_USER_CONFIRM = 0x01;
56 constexpr int PAIR_CONFIRM_STATE_USER_CONFIRM_REPLY = 0x02;
57 
58 constexpr int PAIR_CONFIRM_TYPE_NUMERIC = 0x04;
59 const int PAIR_CONFIRM_TYPE_PASSKEY_INPUT = 0x03;
60 const int PAIR_CONFIRM_TYPE_PASSKEY_DISPLAY = 0x02;
61 const int PAIR_CONFIRM_TYPE_PIN_CODE = 0x01;
62 const int PAIR_CONFIRM_TYPE_CONSENT = 0x05;
63 
64 constexpr int NOERROR = 0;
65 constexpr int BADPARAM = -1000;
66 constexpr int BADSTATUS = -1001;
67 constexpr int TIMEOUT = -1002;
68 constexpr int OS_ERROR = -1003;
69 constexpr int NOMEMORY = -1004;
70 constexpr int NOSPACE = -1005;
71 constexpr int CREATE_FILE = -1006;
72 constexpr int CONFIG_ERROR = -1007;
73 constexpr int DEVICE_ERROR = -1008;
74 
75 constexpr int CONNECTION_STATE_DISCONNECTED = 0x00;
76 constexpr int CONNECTION_STATE_CONNECTED = 0x01;
77 constexpr int CONNECTION_STATE_ENCRYPTED_BREDR = 0x02;
78 constexpr int CONNECTION_STATE_ENCRYPTED_LE = 0x04;
79 
80 constexpr int MAC_ADDRESS_LENGTH = 6;
81 
82 constexpr int SDP_UUDIID_NUM = 1;
83 constexpr int HEX_FORMAT_SIZE = 3;
84 
85 constexpr int UUID128_BYTES_TYPE = 16;
86 constexpr int UUID32_BYTES_TYPE = 4;
87 constexpr int UUID16_BYTES_TYPE = 2;
88 
89 /// Bluetooth Properties
90 constexpr int BT_PROPERTY_BDNAME = 0x01;
91 constexpr int BT_PROPERTY_BDADDR = 0x02;
92 constexpr int BT_PROPERTY_CLASS_OF_DEVICE = 0x03;
93 constexpr int BT_PROPERTY_ADAPTER_BONDED_MODE = 0x04;
94 constexpr int BT_PROPERTY_ADAPTER_DISCOVERABLE_TIMEOUT = 0x05;
95 
96 /// Bluetooth device name's max length
97 constexpr int MAX_LOC_BT_NAME_LEN = 248;
98 
99 /// Extend inquiry response max length
100 constexpr int MAX_EXTEND_INQUIRY_RESPONSE_LEN = 240;
101 
102 constexpr int EXTEND_INQUIRY_RESPONSE_LENGTH_SIZE = 1;
103 constexpr int EXTEND_INQUIRY_RESPONSE_TYPE_SIZE = 1;
104 
105 constexpr int BTM_ACL_DISCONNECT_REASON = 0x13;
106 constexpr int BTM_ACL_CONNECT_PAGE_TIMEOUT = 0x04;
107 constexpr int BTM_ACL_CONNECTION_TIMEOUT = 0x08;
108 
109 /// Service class UUID
110 constexpr uint16_t PNP_SERVICE_CLASS_UUID = 0x1200;
111 
112 /// The value range of Class of Device
113 constexpr int CLASS_OF_DEVICE_RANGE = 0xFFFFFF;
114 
115 /// Class of Device defines
116 constexpr uint32_t CLASS_OF_DEVICE_MASK = 0X1FFC;
117 constexpr uint32_t CLASS_OF_DEVICE_UNCLASSIFIED = ((0x1F) << 8);
118 constexpr uint32_t CLASS_OF_DEVICE_HID_KEYBOARD = 0x0540;
119 constexpr uint32_t CLASS_OF_DEVICE_HID_POINTING = 0x0580;
120 constexpr uint32_t CLASS_OF_DEVICE_HID_COMBO    = 0x05C0;
121 constexpr uint32_t CLASS_OF_DEVICE_HID_MAJOR    = 0x0700;
122 constexpr uint32_t CLASS_OF_DEVICE_AV_HEADSETS  = 0x0404;
123 constexpr uint32_t CLASS_OF_DEVICE_AV_HANDSFREE = 0x0408;
124 constexpr uint32_t CLASS_OF_DEVICE_AV_HEADPHONES = 0x0418;
125 constexpr uint32_t CLASS_OF_DEVICE_AV_PORTABLE_AUDIO = 0x041C;
126 constexpr uint32_t CLASS_OF_DEVICE_AV_HIFI_AUDIO = 0x0428;
127 
128 /// GAP callback event type
129 typedef enum {
130     GAP_INQUIRY_RESULT_EVT,
131     GAP_INQUIRY_RESULT_RSSI_EVT,
132     GAP_EXTENDED_INQUIRY_RESULT_EVT,
133     GAP_INQUIRY_COMPLETE_EVT,
134     GAP_REMOTE_NAME_CALLBACK_EVT,
135     GAP_SSP_CONFIRM_REQ_EVT,
136     GAP_PIN_CODE_REQ_EVT,
137     GAP_REMOTE_OOB_REQ_EVT,
138     GAP_LINK_KEY_REQ_EVT,
139     GAP_LINK_KEY_NOTIFICATION_EVT,
140     GAP_SIMPLE_PAIR_COMPLETE_EVT,
141     GAP_IO_CAPABILITY_REQ_EVT,
142     GAP_IO_CAPABILITY_RSP_EVT,
143     GAP_AUTHENTICATION_COMPLETE_EVT,
144     GAP_ENCRYPTION_CHANGE_CALLBACK_EVT,
145     GAP_AUTHORIZE_IND_CALLBACK_EVT,
146 } GAP_CB_EVENT;
147 
148 typedef union {
149     struct InquiryResultParam {
150         const BtAddr addr;
151         uint32_t classOfDevice;
152     } iniquiryResultParam_;
153 
154     struct InquiryResultRssiParam {
155         const BtAddr addr;
156         uint32_t classOfDevice;
157         int8_t rssi;
158     } iniquiryResultRssiParam_;
159 
160     struct ExtendedInquiryResultParam {
161         const BtAddr addr;
162         uint32_t classOfDevice;
163         int8_t rssi;
164         uint8_t eir[MAX_EXTEND_INQUIRY_RESPONSE_LEN];
165     } extendedInquiryResultParam_;
166 
167     struct InquiryCompleteParam {
168         uint8_t status;
169     } inquiryCompleteParam_;
170 
171     struct RemoteNameCallbackParam {
172         uint8_t status;
173         const BtAddr addr;
174         const uint8_t name[248];
175     } remoteNameCallbackParam_;
176 
177     struct UserConfirmReqParam {
178         const BtAddr addr;
179         uint32_t number;
180         int reqType;
181         int localMitmRequired;
182         int remoteMitmRequired;
183     } userConfirmReqParam_;
184 
185     struct RemoteOobReqParam {
186         const BtAddr addr;
187     } remoteOobReqParam_;
188 
189     struct PinCodeReqParam {
190         const BtAddr addr;
191     } pinCodeReqParam_;
192 
193     struct LinkKeyReqParam {
194         const BtAddr addr;
195     } linkKeyReqParam_;
196 
197     struct LinkKeyNotificationParam {
198         const BtAddr addr;
199         const uint8_t linkKey[PAIR_LINK_KEY_SIZE];
200         uint8_t keyType;
201     } linkKeyNotificationParam_;
202 
203     struct SimplePairCompleteParam {
204         const BtAddr addr;
205         uint8_t status;
206     } simplePairCompleteParam_;
207 
208     struct IoCapabilityReqParam {
209         const BtAddr addr;
210     } ioCapabilityReqParam_;
211 
212     struct IoCapabilityRspParam {
213         const BtAddr addr;
214         uint8_t ioCapability;
215     } ioCapabilityRspParam_;
216 
217     struct AuthenticationCompleteParam {
218         const BtAddr addr;
219         uint8_t status;
220     } authenticationCompleteParam_;
221 
222     struct EncryptionChangeCallbackParam {
223         const BtAddr addr;
224         uint8_t status;
225     } encryptionChangeCallbackParam_;
226 
227     struct AuthorizeIndParam {
228         const BtAddr addr;
229         GAP_Service service;
230     } authorizeIndParam_;
231 } GapCallbackParam;
232 }  // namespace bluetooth
233 }  // namespace OHOS
234 #endif  // CLASSIC_DEFS_H