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 OHOS_BT_DEF_H 17 #define OHOS_BT_DEF_H 18 19 /* Device address length */ 20 #define OHOS_BD_ADDR_LEN 6 21 22 /* Bluetooth 16-byte UUID */ 23 #define OHOS_BLE_UUID_MAX_LEN 16 24 25 /* Characteristic Properties */ 26 #define OHOS_GATT_CHARACTER_PROPERTY_BIT_BROADCAST 0x01 /* Characteristic is broadcastable */ 27 #define OHOS_GATT_CHARACTER_PROPERTY_BIT_READ 0x02 /* Characteristic is readable */ 28 #define OHOS_GATT_CHARACTER_PROPERTY_BIT_WRITE_NO_RSP 0x04 /* Characteristic can be written without response */ 29 #define OHOS_GATT_CHARACTER_PROPERTY_BIT_WRITE 0x08 /* Characteristic can be written */ 30 #define OHOS_GATT_CHARACTER_PROPERTY_BIT_NOTIFY 0x10 /* Characteristic supports notification */ 31 #define OHOS_GATT_CHARACTER_PROPERTY_BIT_INDICATE 0x20 /* Characteristic supports indication */ 32 #define OHOS_GATT_CHARACTER_PROPERTY_BIT_SIGNED_WRITE 0x40 /* Characteristic supports write with signature */ 33 #define OHOS_GATT_CHARACTER_PROPERTY_BIT_EXTENDED_PROPERTY 0x80 /* Characteristic has extended properties */ 34 35 /* Attribute permissions */ 36 #define OHOS_GATT_PERMISSION_READ 0x01 /* read permission */ 37 #define OHOS_GATT_PERMISSION_READ_ENCRYPTED 0x02 /* Allow encrypted read operations */ 38 #define OHOS_GATT_PERMISSION_READ_ENCRYPTED_MITM 0x04 /* Allow reading with man-in-the-middle protection */ 39 #define OHOS_GATT_PERMISSION_WRITE 0x10 /* write permission */ 40 #define OHOS_GATT_PERMISSION_WRITE_ENCRYPTED 0x20 /* Allow encrypted writes */ 41 #define OHOS_GATT_PERMISSION_WRITE_ENCRYPTED_MITM 0x40 /* Allow encrypted writes with man-in-the-middle protection */ 42 #define OHOS_GATT_PERMISSION_WRITE_SIGNED 0x80 /* Allow signed write operations */ 43 /* Allow signed write operations with man-in-the-middle protection */ 44 #define OHOS_GATT_PERMISSION_WRITE_SIGNED_MITM = 0x100 45 46 typedef enum { 47 OHOS_BT_TRANSPORT_INVALID = 0x00, 48 OHOS_BT_TRANSPORT_BR_EDR = 0x01, 49 OHOS_BT_TRANSPORT_LE = 0x02 50 } BtTransportId; 51 52 typedef enum { 53 OHOS_BT_STATUS_SUCCESS, 54 OHOS_BT_STATUS_FAIL, 55 OHOS_BT_STATUS_NOT_READY, 56 OHOS_BT_STATUS_NOMEM, 57 OHOS_BT_STATUS_BUSY, 58 OHOS_BT_STATUS_DONE, 59 OHOS_BT_STATUS_UNSUPPORTED, 60 OHOS_BT_STATUS_PARM_INVALID, 61 OHOS_BT_STATUS_UNHANDLED, 62 OHOS_BT_STATUS_AUTH_FAILURE, 63 OHOS_BT_STATUS_RMT_DEV_DOWN, 64 OHOS_BT_STATUS_AUTH_REJECTED 65 } BtStatus; 66 67 /* Error Code, BLUETOOTH CORE SPECIFICATION Version 5.2 | Vol 3, Part F, table 3.4 */ 68 typedef enum { 69 OHOS_GATT_SUCCESS = 0x00, 70 OHOS_GATT_INVALID_HANDLE = 0x01, 71 OHOS_GATT_READ_NOT_PERMITTED = 0x02, 72 OHOS_GATT_WRITE_NOT_PERMITTED = 0x03, 73 OHOS_GATT_INVALID_PDU = 0x04, 74 OHOS_GATT_INSUFFICIENT_AUTHENTICATION = 0x05, 75 OHOS_GATT_REQUEST_NOT_SUPPORTED = 0x06, 76 OHOS_GATT_INVALID_OFFSET = 0x07, 77 OHOS_GATT_INSUFFICIENT_AUTHORIZATION = 0x08, 78 OHOS_GATT_PREPARE_QUEUE_FULL = 0x09, 79 OHOS_GATT_ATTRIBUTE_NOT_FOUND = 0x0A, 80 OHOS_GATT_ATTRIBUTE_NOT_LONG = 0x0B, 81 OHOS_GATT_INSUFFICIENT_ENCRYPTION_KEY_SIZE = 0x0C, 82 OHOS_GATT_INVALID_ATTRIBUTE_VALUE_LENGTH = 0x0D, 83 OHOS_GATT_UNLIKELY_ERROR = 0x0E, 84 OHOS_GATT_INSUFFICIENT_ENCRYPTION = 0x0F, 85 OHOS_GATT_UNSUPPORTED_GROUP_TYPE = 0x10, 86 OHOS_GATT_INSUFFICIENT_RESOURCES = 0x11, 87 OHOS_GATT_DATABASE_OUT_OF_SYNC = 0x12, 88 OHOS_GATT_VALUE_NOT_ALLOWED = 0x13, 89 } GattStatus; 90 91 typedef enum { 92 OHOS_BLE_ATTRIB_TYPE_SERVICE = 0x00, 93 OHOS_BLE_ATTRIB_TYPE_CHAR, 94 OHOS_BLE_ATTRIB_TYPE_CHAR_VALUE, 95 OHOS_BLE_ATTRIB_TYPE_CHAR_CLIENT_CONFIG, 96 OHOS_BLE_ATTRIB_TYPE_CHAR_USER_DESCR, 97 } BleAttribType; 98 99 typedef enum { 100 OHOS_UUID_TYPE_NULL = 0x00, 101 OHOS_UUID_TYPE_16_BIT, 102 OHOS_UUID_TYPE_32_BIT, 103 OHOS_UUID_TYPE_128_BIT, 104 } UuidType; 105 106 typedef enum { 107 OHOS_GATT_AUTH_REQ_NONE = 0x00, 108 OHOS_GATT_AUTH_REQ_NO_MITM = 0x01, /* unauthenticated encryption */ 109 OHOS_GATT_AUTH_REQ_MITM = 0x02, /* authenticated encryption */ 110 OHOS_GATT_AUTH_REQ_SIGNED_NO_MITM = 0x03, 111 OHOS_GATT_AUTH_REQ_SIGNED_MITM = 0x04 112 } BtGattAuthReq; 113 114 typedef enum { 115 OHOS_GATT_WRITE_NO_RSP = 0x01, /* Write only. "Write Command" */ 116 OHOS_GATT_WRITE_DEFAULT = 0x02, /* Write and need response from remote device. "Write Request" */ 117 OHOS_GATT_WRITE_PREPARE = 0x03, /* Request the server to prepare to write the value. "Prepare Write" */ 118 OHOS_GATT_WRITE_SIGNED = 0x04 /* Write including authentication signature. "Signed Write Command" */ 119 } BtGattWriteType; 120 121 /* Device address */ 122 typedef struct { 123 unsigned char addr[OHOS_BD_ADDR_LEN]; 124 } BdAddr; 125 126 /* uuid with len */ 127 typedef struct { 128 unsigned char uuidLen; 129 char *uuid; 130 } BtUuid; 131 #endif 132