• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  * @addtogroup Bluetooth
18  * @{
19  *
20  * @brief Provides basic Bluetooth capabilities.
21  *
22  * This module allows you to enable and disable Bluetooth, and access basic Bluetooth capabilities.\n
23  * Bluetooth uses profiles such as BT-GAP, BLE, BLE-GATT, BT-data transmission, HFP, A2DP, AVRCP, MAP, and PBAP.
24  *
25  * @since 6
26  */
27 
28 /**
29  * @file ohos_bt_def.h
30  *
31  * @brief Declares basic data structures, macros, enumerations, and structures for Bluetooth services.
32  *
33  * @since 6
34  */
35 
36 #ifndef OHOS_BT_DEF_H
37 #define OHOS_BT_DEF_H
38 
39 /**
40  * @brief Defines the address length of a Bluetooth device.
41  *
42  */
43 #define OHOS_BD_ADDR_LEN 6
44 
45 /**
46  * @brief Defines the maximum length of a Bluetooth UUID, in bytes.
47  *
48  */
49 #define OHOS_BLE_UUID_MAX_LEN 16
50 
51 /**
52  * @brief Enumerates characteristic properties.
53  *
54  * Characteristic properties determine how characteristic values are used and\n
55  * how characteristic descriptors are accessed. If there are multiple properties,\n
56  * their values can be connected using the logical operator OR.\n
57  * For example, <b>0x01 | 0x02</b> indicates that the characteristic value can be broadcast and read.
58  *
59  * @since 6
60  */
61 typedef enum {
62     /** The characteristic value can be broadcast. */
63     OHOS_GATT_CHARACTER_PROPERTY_BIT_BROADCAST = 0x01,
64     /** The characteristic value can be read. */
65     OHOS_GATT_CHARACTER_PROPERTY_BIT_READ = 0x02,
66     /** The characteristic value can be written, and no response needs to be sent to the client. */
67     OHOS_GATT_CHARACTER_PROPERTY_BIT_WRITE_NO_RSP = 0x04,
68     /** The characteristic value can be written, and a response needs to be sent to the client. */
69     OHOS_GATT_CHARACTER_PROPERTY_BIT_WRITE = 0x08,
70     /**
71      * The characteristic value can be sent to the client through a notification, and the client does not need to
72      * reply with a confirmation message.
73      */
74     OHOS_GATT_CHARACTER_PROPERTY_BIT_NOTIFY = 0x10,
75     /**
76      * The characteristic value can be sent to the client through an indication, and the client does not need to
77      * reply with a confirmation message.
78      */
79     OHOS_GATT_CHARACTER_PROPERTY_BIT_INDICATE = 0x20,
80     /** The characteristic value can be written with a signature. */
81     OHOS_GATT_CHARACTER_PROPERTY_BIT_SIGNED_WRITE = 0x40,
82     /** The characteristic has extended properties. */
83     OHOS_GATT_CHARACTER_PROPERTY_BIT_EXTENDED_PROPERTY = 0x80
84 } GattCharacteristicProperty;
85 
86 /**
87  * @brief Enumerates permissions for an attribute.
88  *
89  * If there are multiple permissions, their values can be connected using the logical operator OR.\n
90  * For example, <b>0x01 | 0x02</b> indicates the reading and encrypted reading permissions.
91  *
92  * @since 6
93  */
94 typedef enum {
95     /** Reading */
96     OHOS_GATT_PERMISSION_READ = 0x01,
97     /** Encrypted reading */
98     OHOS_GATT_PERMISSION_READ_ENCRYPTED = 0x02,
99     /** Encrypted reading with man-in-the-middle (MITM) protection */
100     OHOS_GATT_PERMISSION_READ_ENCRYPTED_MITM = 0x04,
101     /** Writing */
102     OHOS_GATT_PERMISSION_WRITE = 0x10,
103     /** Encrypted writing */
104     OHOS_GATT_PERMISSION_WRITE_ENCRYPTED = 0x20,
105     /** Encrypted writing with MITM protection */
106     OHOS_GATT_PERMISSION_WRITE_ENCRYPTED_MITM = 0x40,
107     /** Signed writing */
108     OHOS_GATT_PERMISSION_WRITE_SIGNED = 0x80,
109     /** Signed writing with MITM protection */
110     OHOS_GATT_PERMISSION_WRITE_SIGNED_MITM = 0x100
111 } GattAttributePermission;
112 
113 /**
114  * @brief Enumerates transport IDs.
115  *
116  * @since 6
117  */
118 typedef enum {
119     /** Invalid transport ID */
120     OHOS_BT_TRANSPORT_INVALID = 0x00,
121     /** BR/EDR */
122     OHOS_BT_TRANSPORT_BR_EDR = 0x01,
123     /** LE */
124     OHOS_BT_TRANSPORT_LE = 0x02
125 } BtTransportId;
126 
127 /**
128  * @brief Enumerates Bluetooth statuses.
129  *
130  * @since 6
131  */
132 typedef enum {
133     /** Success */
134     OHOS_BT_STATUS_SUCCESS = 0x00,
135     /** Failure */
136     OHOS_BT_STATUS_FAIL,
137     /** Bluetooth not ready */
138     OHOS_BT_STATUS_NOT_READY,
139     /** Insufficient memory */
140     OHOS_BT_STATUS_NOMEM,
141     /** System busy */
142     OHOS_BT_STATUS_BUSY,
143     /** Operation completed */
144     OHOS_BT_STATUS_DONE,
145     /** Bluetooth not supported by the current version or device */
146     OHOS_BT_STATUS_UNSUPPORTED,
147     /** Invalid parameters */
148     OHOS_BT_STATUS_PARM_INVALID,
149     /** Request unhandled */
150     OHOS_BT_STATUS_UNHANDLED,
151     /** Authentication failure */
152     OHOS_BT_STATUS_AUTH_FAILURE,
153     /** Remote device shut down */
154     OHOS_BT_STATUS_RMT_DEV_DOWN,
155     /** Authentication rejected */
156     OHOS_BT_STATUS_AUTH_REJECTED
157 } BtStatus;
158 
159 /**
160  * @brief Enumerates result codes for GATT attribute operations.
161  *
162  * The error codes are based on Bluetooth Core Specification Version 5.2 | Vol 3, Part F, Table 3.4.
163  *
164  * @since 6
165  */
166 typedef enum {
167     /** Success */
168     OHOS_GATT_SUCCESS = 0x00,
169     /** Invalid attribute handle */
170     OHOS_GATT_INVALID_HANDLE = 0x01,
171     /** Attribute unreadable */
172     OHOS_GATT_READ_NOT_PERMITTED = 0x02,
173     /** Attribute unwritable */
174     OHOS_GATT_WRITE_NOT_PERMITTED = 0x03,
175     /** Invalid attribute PDU */
176     OHOS_GATT_INVALID_PDU = 0x04,
177     /** Authentication required for reading or writing the attribute */
178     OHOS_GATT_INSUFFICIENT_AUTHENTICATION = 0x05,
179     /** Request not supported */
180     OHOS_GATT_REQUEST_NOT_SUPPORTED = 0x06,
181     /** Invalid offset */
182     OHOS_GATT_INVALID_OFFSET = 0x07,
183     /** Authorization required for reading or writing the attribute */
184     OHOS_GATT_INSUFFICIENT_AUTHORIZATION = 0x08,
185     /** The queue is full of prepare writes. */
186     OHOS_GATT_PREPARE_QUEUE_FULL = 0x09,
187     /** Attribute not found in the specified attribute handle */
188     OHOS_GATT_ATTRIBUTE_NOT_FOUND = 0x0A,
189     /** The attribute is not a long attribute and cannot use the <b>ATT_READ_BLOB_REQ</b> PDU. */
190     OHOS_GATT_ATTRIBUTE_NOT_LONG = 0x0B,
191     /** Insufficient size for the encryption key */
192     OHOS_GATT_INSUFFICIENT_ENCRYPTION_KEY_SIZE = 0x0C,
193     /** Invalid attribute value length */
194     OHOS_GATT_INVALID_ATTRIBUTE_VALUE_LENGTH = 0x0D,
195     /** Unlikely error */
196     OHOS_GATT_UNLIKELY_ERROR = 0x0E,
197     /** Encryption required for reading or writing the attribute */
198     OHOS_GATT_INSUFFICIENT_ENCRYPTION = 0x0F,
199     /** Unsupported grouping attribute */
200     OHOS_GATT_UNSUPPORTED_GROUP_TYPE = 0x10,
201     /** Insufficient resources */
202     OHOS_GATT_INSUFFICIENT_RESOURCES = 0x11,
203     /** The server needs to request the client to rediscover the database. */
204     OHOS_GATT_DATABASE_OUT_OF_SYNC = 0x12,
205     /** Attribute value not allowed */
206     OHOS_GATT_VALUE_NOT_ALLOWED = 0x13,
207 } GattStatus;
208 
209 /**
210  * @brief Enumerates attribute types.
211  *
212  * @since 6
213  */
214 typedef enum {
215     /** Service */
216     OHOS_BLE_ATTRIB_TYPE_SERVICE = 0x00,
217     /** Characteristic */
218     OHOS_BLE_ATTRIB_TYPE_CHAR,
219     /** Characteristic value */
220     OHOS_BLE_ATTRIB_TYPE_CHAR_VALUE,
221     /** Client characteristic configuration */
222     OHOS_BLE_ATTRIB_TYPE_CHAR_CLIENT_CONFIG,
223     /** Characteristic user description */
224     OHOS_BLE_ATTRIB_TYPE_CHAR_USER_DESCR,
225 } BleAttribType;
226 
227 /**
228  * @brief Enumerates UUID types.
229  *
230  * @since 6
231  */
232 typedef enum {
233     /** Invalid UUID */
234     OHOS_UUID_TYPE_NULL = 0x00,
235     /** 16-bit UUID */
236     OHOS_UUID_TYPE_16_BIT,
237     /** 32-bit UUID */
238     OHOS_UUID_TYPE_32_BIT,
239     /** 128-bit UUID */
240     OHOS_UUID_TYPE_128_BIT,
241 } UuidType;
242 
243 /**
244  * @brief Enumerates types of characteristic and descriptor write operations performed by the GATT client.
245  *
246  * @since 6
247  */
248 typedef enum {
249     /** Write operation without requiring a response from the server */
250     OHOS_GATT_WRITE_NO_RSP = 0x01,
251     /** Write operation requiring a response from the server */
252     OHOS_GATT_WRITE_DEFAULT = 0x02,
253     /** Prepare write requiring a response from the server */
254     OHOS_GATT_WRITE_PREPARE = 0x03,
255     /** Write operation with an authentication signature */
256     OHOS_GATT_WRITE_SIGNED = 0x04
257 } BtGattWriteType;
258 
259 /**
260  * @brief Enumerates profile connection statuses.
261  *
262  * @since 6
263  */
264 typedef enum {
265     /** Connecting */
266     OHOS_PROFILE_STATE_CONNECTING = 0x01,
267     /** Connected */
268     OHOS_PROFILE_STATE_CONNECTED = 0x02,
269     /** Disconnecting */
270     OHOS_PROFILE_STATE_DISCONNECTING = 0x03,
271     /** Disconnected */
272     OHOS_PROFILE_STATE_DISCONNECTED = 0x04
273 } BtProfileConnectState;
274 
275 /**
276  * @brief Enumerates connection strategies.
277  *
278  * @since 6
279  */
280 typedef enum {
281     /** Unknown strategy */
282     OHOS_CONNECTION_UNKNOWN = 0x00,
283     /** Allowing connections */
284     OHOS_CONNECTION_ALLOWED,
285     /** Forbidding connections */
286     OHOS_CONNECTION_FORBIDDEN
287 } BtConnectStrategyType;
288 
289 /**
290  * @brief Enumerates A2DP playing states of the device.
291  *
292  * @since 6
293  */
294 typedef enum {
295     /** Not playing */
296     OHOS_A2DP_NOT_PLAYING = 0x00,
297     /** Playing */
298     OHOS_A2DP_IS_PLAYING
299 } BtA2dpPlayingState;
300 
301 typedef enum {
302     OHOS_STATE_CONNECTING = 0x00,
303     OHOS_STATE_CONNECTED,
304     OHOS_STATE_DISCONNECTING,
305     OHOS_STATE_DISCONNECTED,
306 } BtConnectState;
307 
308 /**
309  * @brief Defines the Bluetooth address of the device.
310  *
311  * @since 6
312  */
313 typedef struct {
314     /** Bluetooth address */
315     unsigned char addr[OHOS_BD_ADDR_LEN];
316 } BdAddr;
317 
318 /**
319  * @brief Defines the UUID.
320  *
321  * @since 6
322  */
323 typedef struct {
324     /** UUID length */
325     unsigned char uuidLen;
326     /** UUID field */
327     char *uuid;
328 } BtUuid;
329 #endif
330 /** @} */
331