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 NOERROR = 0; 59 constexpr int BADPARAM = -1000; 60 constexpr int BADSTATUS = -1001; 61 constexpr int TIMEOUT = -1002; 62 constexpr int OS_ERROR = -1003; 63 constexpr int NOMEMORY = -1004; 64 constexpr int NOSPACE = -1005; 65 constexpr int CREATE_FILE = -1006; 66 constexpr int CONFIG_ERROR = -1007; 67 constexpr int DEVICE_ERROR = -1008; 68 69 constexpr int CONNECTION_STATE_DISCONNECTED = 0x00; 70 constexpr int CONNECTION_STATE_CONNECTED = 0x01; 71 constexpr int CONNECTION_STATE_ENCRYPTED_BREDR = 0x02; 72 constexpr int CONNECTION_STATE_ENCRYPTED_LE = 0x04; 73 74 constexpr int MAC_ADDRESS_LENGTH = 6; 75 76 constexpr int SDP_UUDIID_NUM = 1; 77 constexpr int HEX_FORMAT_SIZE = 3; 78 79 constexpr int UUID128_BYTES_TYPE = 16; 80 constexpr int UUID32_BYTES_TYPE = 4; 81 constexpr int UUID16_BYTES_TYPE = 2; 82 83 /// Bluetooth Properties 84 constexpr int BT_PROPERTY_BDNAME = 0x01; 85 constexpr int BT_PROPERTY_BDADDR = 0x02; 86 constexpr int BT_PROPERTY_CLASS_OF_DEVICE = 0x03; 87 constexpr int BT_PROPERTY_ADAPTER_BONDED_MODE = 0x04; 88 constexpr int BT_PROPERTY_ADAPTER_DISCOVERABLE_TIMEOUT = 0x05; 89 90 /// Bluetooth device name's max length 91 constexpr int MAX_LOC_BT_NAME_LEN = 248; 92 93 /// Extend inquiry response max length 94 constexpr int MAX_EXTEND_INQUIRY_RESPONSE_LEN = 240; 95 96 constexpr int EXTEND_INQUIRY_RESPONSE_LENGTH_SIZE = 1; 97 constexpr int EXTEND_INQUIRY_RESPONSE_TYPE_SIZE = 1; 98 99 constexpr int BTM_ACL_DISCONNECT_REASON = 0x13; 100 constexpr int BTM_ACL_CONNECT_PAGE_TIMEOUT = 0x04; 101 constexpr int BTM_ACL_CONNECTION_TIMEOUT = 0x08; 102 103 /// Service class UUID 104 constexpr uint16_t PNP_SERVICE_CLASS_UUID = 0x1200; 105 106 /// The value range of Class of Device 107 constexpr int CLASS_OF_DEVICE_RANGE = 0xFFFFFF; 108 109 /// Class of Device defines 110 constexpr uint32_t CLASS_OF_DEVICE_MASK = 0x07FF; 111 constexpr uint32_t CLASS_OF_DEVICE_UNCLASSIFIED = ((0x1F) << 8); 112 constexpr uint32_t CLASS_OF_DEVICE_HID_KEYBOARD = 0x0540; 113 constexpr uint32_t CLASS_OF_DEVICE_HID_POINTING = 0x0580; 114 constexpr uint32_t CLASS_OF_DEVICE_HID_COMBO = 0x05C0; 115 constexpr uint32_t CLASS_OF_DEVICE_HID_MAJOR = 0x0700; 116 constexpr uint32_t CLASS_OF_DEVICE_AV_HEADSETS = 0x0404; 117 constexpr uint32_t CLASS_OF_DEVICE_AV_HANDSFREE = 0x0408; 118 constexpr uint32_t CLASS_OF_DEVICE_AV_HEADPHONES = 0x0418; 119 constexpr uint32_t CLASS_OF_DEVICE_AV_PORTABLE_AUDIO = 0x041C; 120 constexpr uint32_t CLASS_OF_DEVICE_AV_HIFI_AUDIO = 0x0428; 121 122 /// GAP callback event type 123 typedef enum { 124 GAP_INQUIRY_RESULT_EVT, 125 GAP_INQUIRY_RESULT_RSSI_EVT, 126 GAP_EXTENDED_INQUIRY_RESULT_EVT, 127 GAP_INQUIRY_COMPLETE_EVT, 128 GAP_REMOTE_NAME_CALLBACK_EVT, 129 GAP_SSP_CONFIRM_REQ_EVT, 130 GAP_PIN_CODE_REQ_EVT, 131 GAP_REMOTE_OOB_REQ_EVT, 132 GAP_LINK_KEY_REQ_EVT, 133 GAP_LINK_KEY_NOTIFICATION_EVT, 134 GAP_SIMPLE_PAIR_COMPLETE_EVT, 135 GAP_IO_CAPABILITY_REQ_EVT, 136 GAP_IO_CAPABILITY_RSP_EVT, 137 GAP_AUTHENTICATION_COMPLETE_EVT, 138 GAP_ENCRYPTION_CHANGE_CALLBACK_EVT, 139 GAP_AUTHORIZE_IND_CALLBACK_EVT, 140 } GAP_CB_EVENT; 141 142 typedef union { 143 struct InquiryResultParam { 144 const BtAddr addr; 145 uint32_t classOfDevice; 146 } iniquiryResultParam_; 147 148 struct InquiryResultRssiParam { 149 const BtAddr addr; 150 uint32_t classOfDevice; 151 int8_t rssi; 152 } iniquiryResultRssiParam_; 153 154 struct ExtendedInquiryResultParam { 155 const BtAddr addr; 156 uint32_t classOfDevice; 157 int8_t rssi; 158 uint8_t eir[MAX_EXTEND_INQUIRY_RESPONSE_LEN]; 159 } extendedInquiryResultParam_; 160 161 struct InquiryCompleteParam { 162 uint8_t status; 163 } inquiryCompleteParam_; 164 165 struct RemoteNameCallbackParam { 166 uint8_t status; 167 const BtAddr addr; 168 const uint8_t name[248]; 169 } remoteNameCallbackParam_; 170 171 struct UserConfirmReqParam { 172 const BtAddr addr; 173 uint32_t number; 174 int reqType; 175 } userConfirmReqParam_; 176 177 struct RemoteOobReqParam { 178 const BtAddr addr; 179 } remoteOobReqParam_; 180 181 struct PinCodeReqParam { 182 const BtAddr addr; 183 } pinCodeReqParam_; 184 185 struct LinkKeyReqParam { 186 const BtAddr addr; 187 } linkKeyReqParam_; 188 189 struct LinkKeyNotificationParam { 190 const BtAddr addr; 191 const uint8_t linkKey[PAIR_LINK_KEY_SIZE]; 192 uint8_t keyType; 193 } linkKeyNotificationParam_; 194 195 struct SimplePairCompleteParam { 196 const BtAddr addr; 197 uint8_t status; 198 } simplePairCompleteParam_; 199 200 struct IoCapabilityReqParam { 201 const BtAddr addr; 202 } ioCapabilityReqParam_; 203 204 struct IoCapabilityRspParam { 205 const BtAddr addr; 206 uint8_t ioCapability; 207 } ioCapabilityRspParam_; 208 209 struct AuthenticationCompleteParam { 210 const BtAddr addr; 211 uint8_t status; 212 } authenticationCompleteParam_; 213 214 struct EncryptionChangeCallbackParam { 215 const BtAddr addr; 216 uint8_t status; 217 } encryptionChangeCallbackParam_; 218 219 struct AuthorizeIndParam { 220 const BtAddr addr; 221 GAP_Service service; 222 } authorizeIndParam_; 223 } GapCallbackParam; 224 } // namespace bluetooth 225 } // namespace OHOS 226 #endif // CLASSIC_DEFS_H