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 Defines the maximum duration of low power device advertise, *10 = 655350 ms(spec_5.3_7.8.56)
53   *
54   */
55  #define LPDEVICE_ADVERTISING_DURATION_MAX 65535
56  
57  /**
58   * @brief Defines the minmum duration of low power device advertise. no_duration(spec_5.3_7.8.56)
59   *
60   */
61  #define LPDEVICE_ADVERTISING_DURATION_MIN 0
62  
63  /**
64   * @brief Defines the maximum low power device advertise adv event, 1 octet(spec_5.3_7.8.56)
65   *
66   */
67  #define LPDEVICE_ADVERTISING_EXTADVEVENT_MAX 255
68  
69  /**
70   * @brief Defines the minmum low power device advertise adv event. no max number of adv events(spec_5.3_7.8.56)
71   *
72   */
73  #define LPDEVICE_ADVERTISING_EXTADVEVENT_MIN 0
74  
75  /**
76   * @brief Defines the maxmum low power device advertise interval. ms (1105 support)
77   *
78   */
79  #define LPDEVICE_ADVERTISING_INTERVAL_MAX 16777215
80  
81  /**
82   * @brief Defines the minmum low power device advertise interval. ms (1105 support)
83   *
84   */
85  #define LPDEVICE_ADVERTISING_INTERVAL_MIN 0
86  
87  /**
88   * @brief Defines the maxmum low power device advertise window. ms (1105 support)
89   *
90   */
91  #define LPDEVICE_ADVERTISING_WINDOW_MAX 16777215
92  
93  /**
94   * @brief Defines the minmum low power device advertise window. ms (1105 support)
95   *
96   */
97  #define LPDEVICE_ADVERTISING_WINDOW_MIN 0
98  
99  /**
100   * @brief Defines the device id length
101   *
102   */
103  #define OHOS_ACTIVE_DEVICE_ID_LEN 8
104  
105  /**
106   * @brief Enumerates characteristic properties.
107   *
108   * Characteristic properties determine how characteristic values are used and\n
109   * how characteristic descriptors are accessed. If there are multiple properties,\n
110   * their values can be connected using the logical operator OR.\n
111   * For example, <b>0x01 | 0x02</b> indicates that the characteristic value can be broadcast and read.
112   *
113   * @since 6
114   */
115  typedef enum {
116      /** The characteristic value can be broadcast. */
117      OHOS_GATT_CHARACTER_PROPERTY_BIT_BROADCAST = 0x01,
118      /** The characteristic value can be read. */
119      OHOS_GATT_CHARACTER_PROPERTY_BIT_READ = 0x02,
120      /** The characteristic value can be written, and no response needs to be sent to the client. */
121      OHOS_GATT_CHARACTER_PROPERTY_BIT_WRITE_NO_RSP = 0x04,
122      /** The characteristic value can be written, and a response needs to be sent to the client. */
123      OHOS_GATT_CHARACTER_PROPERTY_BIT_WRITE = 0x08,
124      /**
125       * The characteristic value can be sent to the client through a notification, and the client does not need to
126       * reply with a confirmation message.
127       */
128      OHOS_GATT_CHARACTER_PROPERTY_BIT_NOTIFY = 0x10,
129      /**
130       * The characteristic value can be sent to the client through an indication, and the client does not need to
131       * reply with a confirmation message.
132       */
133      OHOS_GATT_CHARACTER_PROPERTY_BIT_INDICATE = 0x20,
134      /** The characteristic value can be written with a signature. */
135      OHOS_GATT_CHARACTER_PROPERTY_BIT_SIGNED_WRITE = 0x40,
136      /** The characteristic has extended properties. */
137      OHOS_GATT_CHARACTER_PROPERTY_BIT_EXTENDED_PROPERTY = 0x80
138  } GattCharacteristicProperty;
139  
140  /**
141   * @brief Enumerates permissions for an attribute.
142   *
143   * If there are multiple permissions, their values can be connected using the logical operator OR.\n
144   * For example, <b>0x01 | 0x02</b> indicates the reading and encrypted reading permissions.
145   *
146   * @since 6
147   */
148  typedef enum {
149      /** Reading */
150      OHOS_GATT_PERMISSION_READ = 0x01,
151      /** Encrypted reading */
152      OHOS_GATT_PERMISSION_READ_ENCRYPTED = 0x02,
153      /** Encrypted reading with man-in-the-middle (MITM) protection */
154      OHOS_GATT_PERMISSION_READ_ENCRYPTED_MITM = 0x04,
155      /** Writing */
156      OHOS_GATT_PERMISSION_WRITE = 0x10,
157      /** Encrypted writing */
158      OHOS_GATT_PERMISSION_WRITE_ENCRYPTED = 0x20,
159      /** Encrypted writing with MITM protection */
160      OHOS_GATT_PERMISSION_WRITE_ENCRYPTED_MITM = 0x40,
161      /** Signed writing */
162      OHOS_GATT_PERMISSION_WRITE_SIGNED = 0x80,
163      /** Signed writing with MITM protection */
164      OHOS_GATT_PERMISSION_WRITE_SIGNED_MITM = 0x100
165  } GattAttributePermission;
166  
167  /**
168   * @brief Enumerates transport IDs.
169   *
170   * @since 6
171   */
172  typedef enum {
173      /** Invalid transport ID */
174      OHOS_BT_TRANSPORT_INVALID = 0x00,
175      /** BR/EDR */
176      OHOS_BT_TRANSPORT_BR_EDR = 0x01,
177      /** LE */
178      OHOS_BT_TRANSPORT_LE = 0x02
179  } BtTransportId;
180  
181  /**
182   * @brief Enumerates Bluetooth statuses.
183   *
184   * @since 6
185   */
186  typedef enum {
187      /** Success */
188      OHOS_BT_STATUS_SUCCESS = 0x00,
189      /** Failure */
190      OHOS_BT_STATUS_FAIL,
191      /** Bluetooth not ready */
192      OHOS_BT_STATUS_NOT_READY,
193      /** Insufficient memory */
194      OHOS_BT_STATUS_NOMEM,
195      /** System busy */
196      OHOS_BT_STATUS_BUSY,
197      /** Operation completed */
198      OHOS_BT_STATUS_DONE,
199      /** Bluetooth not supported by the current version or device */
200      OHOS_BT_STATUS_UNSUPPORTED,
201      /** Invalid parameters */
202      OHOS_BT_STATUS_PARM_INVALID,
203      /** Request unhandled */
204      OHOS_BT_STATUS_UNHANDLED,
205      /** Authentication failure */
206      OHOS_BT_STATUS_AUTH_FAILURE,
207      /** Remote device shut down */
208      OHOS_BT_STATUS_RMT_DEV_DOWN,
209      /** Authentication rejected */
210      OHOS_BT_STATUS_AUTH_REJECTED,
211      /** Duplicate advertising address */
212      OHOS_BT_STATUS_DUPLICATED_ADDR
213  } BtStatus;
214  
215  /**
216   * @brief Enumerates result codes for GATT attribute operations.
217   *
218   * The error codes are based on Bluetooth Core Specification Version 5.2 | Vol 3, Part F, Table 3.4.
219   *
220   * @since 6
221   */
222  typedef enum {
223      /** Success */
224      OHOS_GATT_SUCCESS = 0x00,
225      /** Invalid attribute handle */
226      OHOS_GATT_INVALID_HANDLE = 0x01,
227      /** Attribute unreadable */
228      OHOS_GATT_READ_NOT_PERMITTED = 0x02,
229      /** Attribute unwritable */
230      OHOS_GATT_WRITE_NOT_PERMITTED = 0x03,
231      /** Invalid attribute PDU */
232      OHOS_GATT_INVALID_PDU = 0x04,
233      /** Authentication required for reading or writing the attribute */
234      OHOS_GATT_INSUFFICIENT_AUTHENTICATION = 0x05,
235      /** Request not supported */
236      OHOS_GATT_REQUEST_NOT_SUPPORTED = 0x06,
237      /** Invalid offset */
238      OHOS_GATT_INVALID_OFFSET = 0x07,
239      /** Authorization required for reading or writing the attribute */
240      OHOS_GATT_INSUFFICIENT_AUTHORIZATION = 0x08,
241      /** The queue is full of prepare writes. */
242      OHOS_GATT_PREPARE_QUEUE_FULL = 0x09,
243      /** Attribute not found in the specified attribute handle */
244      OHOS_GATT_ATTRIBUTE_NOT_FOUND = 0x0A,
245      /** The attribute is not a long attribute and cannot use the <b>ATT_READ_BLOB_REQ</b> PDU. */
246      OHOS_GATT_ATTRIBUTE_NOT_LONG = 0x0B,
247      /** Insufficient size for the encryption key */
248      OHOS_GATT_INSUFFICIENT_ENCRYPTION_KEY_SIZE = 0x0C,
249      /** Invalid attribute value length */
250      OHOS_GATT_INVALID_ATTRIBUTE_VALUE_LENGTH = 0x0D,
251      /** Unlikely error */
252      OHOS_GATT_UNLIKELY_ERROR = 0x0E,
253      /** Encryption required for reading or writing the attribute */
254      OHOS_GATT_INSUFFICIENT_ENCRYPTION = 0x0F,
255      /** Unsupported grouping attribute */
256      OHOS_GATT_UNSUPPORTED_GROUP_TYPE = 0x10,
257      /** Insufficient resources */
258      OHOS_GATT_INSUFFICIENT_RESOURCES = 0x11,
259      /** The server needs to request the client to rediscover the database. */
260      OHOS_GATT_DATABASE_OUT_OF_SYNC = 0x12,
261      /** Attribute value not allowed */
262      OHOS_GATT_VALUE_NOT_ALLOWED = 0x13,
263  } GattStatus;
264  
265  /**
266   * @brief Enumerates attribute types.
267   *
268   * @since 6
269   */
270  typedef enum {
271      /** Service */
272      OHOS_BLE_ATTRIB_TYPE_SERVICE = 0x00,
273      /** Characteristic */
274      OHOS_BLE_ATTRIB_TYPE_CHAR,
275      /** Characteristic value */
276      OHOS_BLE_ATTRIB_TYPE_CHAR_VALUE,
277      /** Client characteristic configuration */
278      OHOS_BLE_ATTRIB_TYPE_CHAR_CLIENT_CONFIG,
279      /** Characteristic user description */
280      OHOS_BLE_ATTRIB_TYPE_CHAR_USER_DESCR,
281  } BleAttribType;
282  
283  /**
284   * @brief Enumerates UUID types.
285   *
286   * @since 6
287   */
288  typedef enum {
289      /** Invalid UUID */
290      OHOS_UUID_TYPE_NULL = 0x00,
291      /** 16-bit UUID */
292      OHOS_UUID_TYPE_16_BIT,
293      /** 32-bit UUID */
294      OHOS_UUID_TYPE_32_BIT,
295      /** 128-bit UUID */
296      OHOS_UUID_TYPE_128_BIT,
297  } UuidType;
298  
299  /**
300   * @brief Enumerates types of characteristic and descriptor write operations performed by the GATT client.
301   *
302   * @since 6
303   */
304  typedef enum {
305      /** Write operation without requiring a response from the server */
306      OHOS_GATT_WRITE_NO_RSP = 0x01,
307      /** Write operation requiring a response from the server */
308      OHOS_GATT_WRITE_DEFAULT = 0x02,
309      /** Prepare write requiring a response from the server */
310      OHOS_GATT_WRITE_PREPARE = 0x03,
311      /** Write operation with an authentication signature */
312      OHOS_GATT_WRITE_SIGNED = 0x04,
313      /** unknown type */
314      OHOS_GATT_WRITE_TYPE_UNKNOWN = 0xFF,
315  } BtGattWriteType;
316  
317  /**
318   * @brief Enumerates profile connection statuses.
319   *
320   * @since 6
321   */
322  typedef enum {
323      /** Connecting */
324      OHOS_PROFILE_STATE_CONNECTING = 0x01,
325      /** Connected */
326      OHOS_PROFILE_STATE_CONNECTED = 0x02,
327      /** Disconnecting */
328      OHOS_PROFILE_STATE_DISCONNECTING = 0x03,
329      /** Disconnected */
330      OHOS_PROFILE_STATE_DISCONNECTED = 0x04
331  } BtProfileConnectState;
332  
333  /**
334   * @brief Enumerates connection strategies.
335   *
336   * @since 6
337   */
338  typedef enum {
339      /** Unknown strategy */
340      OHOS_CONNECTION_UNKNOWN = 0x00,
341      /** Allowing connections */
342      OHOS_CONNECTION_ALLOWED,
343      /** Forbidding connections */
344      OHOS_CONNECTION_FORBIDDEN
345  } BtConnectStrategyType;
346  
347  /**
348   * @brief Enumerates A2DP playing states of the device.
349   *
350   * @since 6
351   */
352  typedef enum {
353      /** Not playing */
354      OHOS_A2DP_NOT_PLAYING = 0x00,
355      /** Playing */
356      OHOS_A2DP_IS_PLAYING
357  } BtA2dpPlayingState;
358  
359  typedef enum {
360      OHOS_STATE_CONNECTING = 0x00,
361      OHOS_STATE_CONNECTED,
362      OHOS_STATE_DISCONNECTING,
363      OHOS_STATE_DISCONNECTED,
364  } BtConnectState;
365  
366  /**
367   * @brief Enumerates Acl connection states of the device.
368   *
369   * @since 6
370   */
371  typedef enum {
372      ACL_CONNECTION_STATE_DISCONNECTED = 0x00,
373      ACL_CONNECTION_STATE_CONNECTED = 0x01,
374  } BtAclState;
375  
376  /**
377   * @brief Defines the Bluetooth address of the device.
378   *
379   * @since 6
380   */
381  typedef struct {
382      /** Bluetooth address */
383      unsigned char addr[OHOS_BD_ADDR_LEN];
384  } BdAddr;
385  
386  /**
387   * @brief Defines the UUID.
388   *
389   * @since 6
390   */
391  typedef struct {
392      /** UUID length */
393      unsigned char uuidLen;
394      /** UUID field */
395      char *uuid;
396  } BtUuid;
397  #endif
398  /** @} */
399