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