• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2022 Beken Corporation
2 //
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 #pragma once
16 #include "modules/ble.h"
17 
18 // no used
19 //#define BK_BLE_MAX_SCAN_NUM               (15)
20 //#define BK_BLE_ABIT(n) (1 << n)
21 
22 
23 
24 /**
25  * @brief for hci raw data callback.
26  *
27  * stack report type to upper
28  *
29  * @param
30  * - buf: payload, see BK_BLE_HCI_TYPE as buf[0]
31  * - len: buf's len
32  *
33  * @return
34  * - BK_ERR_BLE_SUCCESS: succeed
35 **/
36 typedef ble_err_t (*ble_hci_raw_to_host_cb)(uint8_t *buf, uint16_t len);
37 
38 
39 
40 //bluetooth new api for ethermind
41 
42 #ifndef _H_APPL_SERVICE_ // ethermind api, avoid redefine
43 #define _H_APPL_SERVICE_
44 
45 
46 //copy from BT_gatt_db_api.h
47 
48 //#include "ethermind_export/BT_gatt_db_api.h"
49 #include "ethermind_export/gatt_defines.h"
50 
51 
52 
53 
54 typedef uint16_t    API_RESULT;
55 
56 /** ATT Default MTU */
57 //#define ATT_DEFAULT_MTU                   23U
58 
59 /** ATT Signature Size in Signed Write */
60 #define ATT_AUTH_SIGNATURE_SIZE           12U
61 
62 /** ATT Execute Write Cancel Flag */
63 #define ATT_EXECUTE_WRITE_CANCEL_FLAG   0x00U
64 
65 /** ATT Execute Write Execute Flag */
66 #define ATT_EXECUTE_WRITE_EXEC_FLAG     0x01U
67 
68 /** ATT Identification for 16-bit UUID Format */
69 #define ATT_16_BIT_UUID_FORMAT          0x01U
70 
71 /** ATT Identification for 128-bit UUID Format */
72 #define ATT_128_BIT_UUID_FORMAT         0x02U
73 
74 /** ATT 16-bit UUID Size */
75 #define ATT_16_BIT_UUID_SIZE               2U
76 
77 /** ATT 128-bit UUID Size */
78 #define ATT_128_BIT_UUID_SIZE             16U
79 
80 /** ATT Connection Instance Initialization Value. */
81 #define ATT_CON_ID_INIT_VAL             0xFFU
82 
83 /** ATT Application Callback Initialization Value. */
84 #define ATT_APPL_CB_INIT_VAL               NULL
85 
86 /** ATT Invalid Attribute Handle Value */
87 #define ATT_INVALID_ATTR_HANDLE_VAL      0x0000U
88 
89 /** ATT Attribute Handle Start Range */
90 #define ATT_ATTR_HANDLE_START_RANGE      0x0001U
91 
92 /** ATT Attribute Handle End Range */
93 #define ATT_ATTR_HANDLE_END_RANGE        0xFFFFU
94 
95 
96 
97 
98 
99 
100 
101 
102 typedef uint32_t GATT_DB_SERVICE_DESC;
103 
104 /** Abstracts 16 Bit UUID */
105 typedef uint16_t ATT_UUID16;
106 
107 /** Abstracts 128 Bit UUID */
108 typedef struct
109 {
110     uint8_t   value[ATT_128_BIT_UUID_SIZE];
111 } ATT_UUID128;
112 
113 
114 typedef union
115 {
116     ATT_UUID16    uuid_16;
117     ATT_UUID128   uuid_128;
118 
119 } ATT_UUID;
120 
121 typedef struct
122 {
123     /** Value to be packed */
124     uint8_t     *val;
125 
126     /** Length of Value */
127     uint16_t   len;
128 
129     /** Out Parameter Indicating Actual Length Packed */
130     uint16_t   actual_len;
131 
132 } ATT_VALUE;
133 
134 
135 typedef struct _GATT_DB_UUID_TYPE
136 {
137     /** Format indicating, 16 bit or 128 bit UUIDs */
138     uint8_t              uuid_format;
139 
140     /** Attribute UUID */
141     ATT_UUID           uuid;
142 
143 } GATT_DB_UUID_TYPE;
144 
145 /** Service Information */
146 typedef struct _GATT_DB_SERVICE_INFO
147 {
148     /** UUID */
149     GATT_DB_UUID_TYPE    uuid;
150 
151     /** If this service is primary or not */
152     uint8_t                is_primary;
153 
154     /**
155      * Security Requrirements for the Service
156      * Logical OR of desired combinations of
157      * 1. Security Mode
158      * 2. Security Level
159      * 3. Encryption Key Size
160      *
161      * Acceptable values for Security Mode are:
162      * \ref GATT_DB_SER_SECURITY_MODE1
163      * \ref GATT_DB_SER_SECURITY_MODE2
164      *
165      * Acceptable values for Security Level are:
166      * \ref GATT_DB_SER_SECURITY_LEVEL1
167      * \ref GATT_DB_SER_SECURITY_LEVEL2
168      * \ref GATT_DB_SER_SECURITY_LEVEL3
169      *
170      * Acceptable values for Encryption Key Size are:
171      * \ref GATT_DB_SER_ENCRYPT_KEY_SIZE_7
172      * \ref GATT_DB_SER_ENCRYPT_KEY_SIZE_8
173      * \ref GATT_DB_SER_ENCRYPT_KEY_SIZE_9
174      * \ref GATT_DB_SER_ENCRYPT_KEY_SIZE_10
175      * \ref GATT_DB_SER_ENCRYPT_KEY_SIZE_11
176      * \ref GATT_DB_SER_ENCRYPT_KEY_SIZE_12
177      * \ref GATT_DB_SER_ENCRYPT_KEY_SIZE_13
178      * \ref GATT_DB_SER_ENCRYPT_KEY_SIZE_14
179      * \ref GATT_DB_SER_ENCRYPT_KEY_SIZE_15
180      * \ref GATT_DB_SER_ENCRYPT_KEY_SIZE_16
181      * When the Service does not mandate any specific Key size
182      * \ref GATT_DB_SER_ENC_KEY_SIZE_DONT_CARE shall be used.
183      *
184      * When No Security is mandated for the service
185      * Value \ref GATT_DB_SER_NO_SECURITY_PROPERTY shall be used.
186      */
187     GATT_DB_SERVICE_DESC sec_req;
188 
189     /**
190      * Transport Requrirements for the Service.
191      * This describes the Transport on which this required
192      * to be operational.
193      * \ref GATT_DB_SER_SUPPORT_ANY_LINK_TYPE
194      * \ref GATT_DB_SER_SUPPORT_LE_LINK_TYPE
195      * \ref GATT_DB_SER_SUPPORT_BR_LINK_TYPE
196      */
197     GATT_DB_SERVICE_DESC link_req;
198 
199 } GATT_DB_SERVICE_INFO;
200 
201 
202 
203 /** Read operation for Attribute  */
204 #define GATT_DB_READ                            0x01U
205 
206 /** Write operation for Attribute */
207 #define GATT_DB_WRITE                           0x02U
208 
209 /** Read blob operation for Attribute */
210 #define GATT_DB_READ_BLOB                       0x03U
211 
212 /** Write Without Response operation for Attribute */
213 #define GATT_DB_WRITE_WITHOUT_RSP               0x04U
214 
215 /** Read by UUID/Type operation for Attribute */
216 #define GATT_DB_READ_BY_TYPE                    0x05U
217 
218 /** Signed Write operation for Attribute */
219 #define GATT_DB_SIGNED_WRITE                    0x06U
220 
221 /** Execute Write operation for Attribute */
222 #define GATT_DB_EXECUTE                         0x07U
223 
224 /** Prepare Write operation for Attribute */
225 #define GATT_DB_PREPARE                         0x08U
226 
227 /**
228  *  Local update of a Readable Attribute Value using \ref GATT_DB_HANDLE instead
229  *  of Attribute Handle. See \ref BT_gatt_db_set_char_val for more details.
230  */
231 #define GATT_DB_UPDATE                          0x10U
232 
233 /* 128 Bit Attribute UUID  */
234 #define GATT_DB_128_BIT_UUID_FORMAT             0x20U
235 
236 /**
237  *  Peer initiated operation, needed when Peer is Reading or Writing Values
238  *  either using GATT Read Procedures for Value and Descriptors.
239  */
240 #define GATT_DB_PEER_INITIATED                  0x80U
241 
242 /**
243  *  Locally initiated operation, needed for local updates based on Attribute
244  *  Handles. In case \ref GATT_DB_HANDLE is known, use of access through
245  *  \ref GATT_DB_UPDATE is recommended.
246  */
247 #define GATT_DB_LOCALLY_INITIATED               0x00U
248 
249 /** \} */
250 
251 /**
252  *  \defgroup gatt_db_operations Operations Notified In Characteristic Callback
253  *  \{
254  *  This section describes the operations notified by the module to the
255  *  application through the callback registered by the application.
256  */
257 
258 /** Characteristic Value Local Read Operation */
259 #define GATT_DB_CHAR_VALUE_READ_REQ             0x01U
260 
261 /** Characteristic Value Local Write Operation */
262 #define GATT_DB_CHAR_VALUE_WRITE_REQ            0x02U
263 
264 /** Characteristic Value Local Write Without Response Operation */
265 #define GATT_DB_CHAR_VALUE_WRITE_WITHOUT_REQ    0x03U
266 
267 /** Characteristic Client Configuration Local Read Operation */
268 #define GATT_DB_CHAR_CLI_CNFG_READ_REQ          0x11U
269 
270 /** Characteristic Client Configuration Local Write Operation */
271 #define GATT_DB_CHAR_CLI_CNFG_WRITE_REQ         0x12U
272 
273 /** Characteristic Server Configuration Local Read Operation */
274 #define GATT_DB_CHAR_SER_CNFG_READ_REQ          0x21U
275 
276 /** Characteristic Server Configuration Local Write Operation */
277 #define GATT_DB_CHAR_SER_CNFG_WRITE_REQ         0x22U
278 
279 /** Characteristic Value Peer Read Operation */
280 #define GATT_DB_CHAR_PEER_READ_REQ              (GATT_DB_PEER_INITIATED | GATT_DB_READ)
281 
282 /** Characteristic Value Peer Write Operation */
283 #define GATT_DB_CHAR_PEER_WRITE_REQ             (GATT_DB_PEER_INITIATED | GATT_DB_WRITE)
284 
285 /** Characteristic Value Peer Read Blob Operation */
286 #define GATT_DB_CHAR_PEER_READ_BLOB_REQ         (GATT_DB_PEER_INITIATED | GATT_DB_READ_BLOB)
287 
288 /** Characteristic Value Peer Write Command */
289 #define GATT_DB_CHAR_PEER_WRITE_CMD             (GATT_DB_PEER_INITIATED | GATT_DB_WRITE_WITHOUT_RSP)
290 
291 /** Characteristic Value Peer Read by Type Operation */
292 #define GATT_DB_CHAR_PEER_READ_BY_TYPE_REQ      (GATT_DB_PEER_INITIATED | GATT_DB_READ_BY_TYPE)
293 
294 /** Characteristic Value Peer Signed Write Operation */
295 #define GATT_DB_CHAR_PEER_SIGNED_WRITE_CMD      (GATT_DB_PEER_INITIATED | GATT_DB_SIGNED_WRITE)
296 
297 /** Characteristic Value Peer Execute Write Req */
298 #define GATT_DB_CHAR_PEER_EXECUTE_WRITE_REQ     (GATT_DB_PEER_INITIATED | GATT_DB_EXECUTE)
299 
300 /** Characteristic Value Peer Prepare Write Req */
301 #define GATT_DB_CHAR_PEER_PREPARE_WRITE_REQ     (GATT_DB_PEER_INITIATED | GATT_DB_PREPARE)
302 
303 /** Characteristic Client Configuration Peer Read Operation */
304 #define GATT_DB_CHAR_PEER_CLI_CNFG_READ_REQ     0x91U
305 
306 /** Characteristic Client Configuration Peer Write Operation */
307 #define GATT_DB_CHAR_PEER_CLI_CNFG_WRITE_REQ    0x92U
308 
309 /** Characteristic Server Configuration Peer Read Operation */
310 #define GATT_DB_CHAR_PEER_SER_CNFG_READ_REQ     0xA1U
311 
312 /** Characteristic Server Configuration Peer Write Operation */
313 #define GATT_DB_CHAR_PEER_SER_CNFG_WRITE_REQ    0xA2U
314 
315 /** Characteristic User Description Peer Read Operation */
316 #define GATT_DB_CHAR_PEER_USR_DESC_READ_REQ     0xB1U
317 
318 /** Characteristic User Description Peer Write Operation */
319 #define GATT_DB_CHAR_PEER_USR_DESC_WRITE_REQ    0xB2U
320 
321 /** Characteristic Higher Layer Defined Descriptor Peer Read Operation */
322 #define GATT_DB_CHAR_PEER_HLD_DESC_READ_REQ     0xF1U
323 
324 /** Characteristic Higher Layer Defined Descriptor Peer Write Operation */
325 #define GATT_DB_CHAR_PEER_HLD_DESC_WRITE_REQ    0xF2U
326 
327 /** \} */
328 
329 /**
330  *  \defgroup gatt_characteristic_properties Characteristic Properties
331  *  \{
332  *  Characteristic Properties - Combination of these properties (combined
333  *  using bitwise OR) describe properties of the Characteristic. Also
334  *  see \ref GATT_DB_ATTR_LIST.
335  */
336 
337 /**
338  *  Characteristic support Broadcast of its value to the peer.
339  *  Setting this property automatically includes Characteristic Server
340  *  Configuration Descriptor to the Characteristic
341  */
342 #define GATT_DB_CHAR_BROADCAST_PROPERTY                0x00000001U
343 
344 /** Characteristic support Reading its value by peer */
345 #define GATT_DB_CHAR_READ_PROPERTY                     0x00000002U
346 
347 /** Characteristic support Writing its value by peer Without Response  */
348 #define GATT_DB_CHAR_WRITE_WITHOUT_RSP_PROPERTY        0x00000004U
349 
350 /** Characteristic supports Writing its value by peer */
351 #define GATT_DB_CHAR_WRITE_PROPERTY                    0x00000008U
352 
353 /**
354  *  Characteristic supports Notifying its value to the peer.
355  *  Setting this property automatically includes Characteristic Server
356  *  Configuration Descriptor to the Characteristic
357  */
358 #define GATT_DB_CHAR_NOTIFY_PROPERTY                   0x00000010U
359 
360 /** Characteristic supports Indicating its value to the peer */
361 #define GATT_DB_CHAR_INDICATE_PROPERTY                 0x00000020U
362 
363 /** Characteristic supports Signed Write on its value */
364 #define GATT_DB_CHAR_SIGNED_WRITE_PROPERTY             0x00000040U
365 
366 /** Characteristic supports write on its User Description Descriptor */
367 #define GATT_DB_CHAR_WRIEABLE_AUX_PROPERTY             0x00000200U
368 
369 /** No Auxillary Property */
370 #define GATT_DB_NO_AUXILLARY_PROPERTY                  0x00U
371 
372 /** Characteristic Value is Fixed Length */
373 #define GATT_DB_FIXED_LENGTH_PROPERTY                  0x01U
374 
375 #define GATT_DB_AUTHORIZATION_PROPERTY                 0x02U
376 
377 #define GATT_DB_PEER_SPECIFIC_VAL_PROPERTY             0x40U
378 
379 #define GATT_DB_CONST_ATTR_VAL_PROPERTY                0x80U
380 
381 /** \} */
382 
383 /**
384  *  \defgroup gatt_service_properties Service Properties
385  *  \{
386  *  Service Properties - Combination of these properties (combined
387  *  using bitwise OR) describe properties of the Service. Also
388  *  see \ref GATT_DB_SERVICE_DESC.
389  */
390 
391 /**
392  *  Security related - combination of Level, Mode and Encryption Key Size
393  *  (if applicable) describes complete security needs
394  */
395 /** Service employs Level 0 */
396 #define GATT_DB_SER_SECURITY_LEVEL0                    0x00000000U
397 
398 /** Service employs Level 1 */
399 #define GATT_DB_SER_SECURITY_LEVEL1                    0x00000001U
400 
401 /** Service employs Level 2 */
402 #define GATT_DB_SER_SECURITY_LEVEL2                    0x00000002U
403 
404 /** Service employs Level 3 */
405 #define GATT_DB_SER_SECURITY_LEVEL3                    0x00000004U
406 
407 /** Service employs Mode 1 */
408 #define GATT_DB_SER_SECURITY_MODE1                     0x00000010U
409 
410 /** Service employs Mode 2 */
411 #define GATT_DB_SER_SECURITY_MODE2                     0x00000020U
412 
413 /** \cond ignore_this Unused right now */
414 #define GATT_DB_SER_MULTIPLE_CLIENTS_SUPPORT           0x00000040U
415 /** \endcond */
416 
417 /**
418  *  Service is a Secondary Service. If this not used, Service is by default
419  *  considered to be Primary
420  */
421 #define GATT_DB_SER_SECONDARY_SERVICE_PROPERTY         0x00000080U
422 
423 #if 1//def GATT_DB_SUPPORT_128_BIT_UUID
424 
425     /** Service UUID is 128-bit */
426     #define GATT_DB_SER_128_BIT_UUID_FORMAT                0x00008000U
427 
428 #endif /* GATT_DB_SUPPORT_128_BIT_UUID */
429 
430 /** Set this property to relax all Security on the Service */
431 #define GATT_DB_SER_NO_SECURITY_PROPERTY               0x00000000U
432 
433 /**
434  *  This is employed to describe Service is not rigid on any Encryption
435  *  Key Size. Any Size used by other Services or on the whole by the device
436  *  will do
437  */
438 #define GATT_DB_SER_ENC_KEY_SIZE_DONT_CARE             0x00000000U
439 
440 /** Encyrption Key Size 7 Needed for the Service */
441 #define GATT_DB_SER_ENCRYPT_KEY_SIZE_7                 0x01000000U
442 
443 /** Encyrption Key Size 8 Needed for the Service */
444 #define GATT_DB_SER_ENCRYPT_KEY_SIZE_8                 0x02000000U
445 
446 /** Encyrption Key Size 9 Needed for the Service */
447 #define GATT_DB_SER_ENCRYPT_KEY_SIZE_9                 0x03000000U
448 
449 /** Encyrption Key Size 10 Needed for the Service */
450 #define GATT_DB_SER_ENCRYPT_KEY_SIZE_10                0x04000000U
451 
452 /** Encyrption Key Size 11 Needed for the Service */
453 #define GATT_DB_SER_ENCRYPT_KEY_SIZE_11                0x05000000U
454 
455 /** Encryption Key Size 12 Needed for the Service */
456 #define GATT_DB_SER_ENCRYPT_KEY_SIZE_12                0x06000000U
457 
458 /** Encryption Key Size 13 Needed for the Service */
459 #define GATT_DB_SER_ENCRYPT_KEY_SIZE_13                0x07000000U
460 
461 /** Encryption Key Size 14 Needed for the Service */
462 #define GATT_DB_SER_ENCRYPT_KEY_SIZE_14                0x08000000U
463 
464 /** Encryption Key Size 15 Needed for the Service */
465 #define GATT_DB_SER_ENCRYPT_KEY_SIZE_15                0x09000000U
466 
467 /** Encryption Key Size 16 Needed for the Service */
468 #define GATT_DB_SER_ENCRYPT_KEY_SIZE_16                0x0A000000U
469 
470 /** \cond ignore_this unused */
471 #define GATT_DB_SER_NO_ENCRYPT_PROPERTY                0x00000000U
472 
473 /**
474  *  Macros to describe the Transport access of the Service over BR/EDR only,
475  *  LE only or Any Transport.
476  */
477 /** Service accessible over BR/EDR Link Only */
478 #define GATT_DB_SER_SUPPORT_BR_LINK_TYPE               0x10000000U
479 
480 /** Service accessible over LE Link Only */
481 #define GATT_DB_SER_SUPPORT_LE_LINK_TYPE               0x20000000U
482 
483 /** Service accessible over Any Link */
484 #define GATT_DB_SER_SUPPORT_ANY_LINK_TYPE              0xF0000000U
485 
486 /** GATT Characteristic and Descriptor permissions */
487 #define    GATT_DB_PERM_NONE                    0x0000U
488 #define    GATT_DB_PERM_READ                    0x0001U
489 #define    GATT_DB_PERM_READ_ENCRYPTED          0x0002U
490 #define    GATT_DB_PERM_READ_ENCRYPTED_MITM     0x0004U
491 #define    GATT_DB_PERM_WRITE                   0x0010U
492 #define    GATT_DB_PERM_WRITE_ENCRYPTED         0x0020U
493 #define    GATT_DB_PERM_WRITE_ENCRYPTED_MIMT    0x0040U
494 #define    GATT_DB_PERM_WRITE_SIGNED            0x0080U
495 #define    GATT_DB_PERM_WRITE_SIGNED_MITM       0x0100U
496 
497 #define GATT_DB_ERR_ID                          0x6B00U
498 /* Not an error code. More of a status code */
499 #define GATT_DB_DELAYED_RESPONSE                 (0x0060U | GATT_DB_ERR_ID)
500 #define GATT_DB_DONOT_RESPOND                    (0x0061U | GATT_DB_ERR_ID)
501 #define GATT_DB_ALREADY_RESPONDED                (0x0062U | GATT_DB_ERR_ID)
502 
503 typedef uint8_t DEVICE_HANDLE;
504 typedef uint8_t ATT_CON_ID;
505 
506 typedef struct
507 {
508     /** Identifies the peer accessing the database */
509     DEVICE_HANDLE    device_id;
510 
511     /** Identifies the Service being Accessed */
512     uint8_t            service_id;
513 
514     /** Identifies the Characteristic being Accessed */
515     uint8_t            char_id;
516 
517 } GATT_DB_HANDLE;
518 
519 typedef uint16_t ATT_ATTR_HANDLE;
520 typedef uint8_t GATT_DB_OPERATION;
521 
522 /* Abstracts Application Instance Identifier */
523 typedef uint8_t APPL_HANDLE;
524 
525 typedef struct
526 {
527     /** Abstracts Value to get/set the Attribute Value */
528     ATT_VALUE            value;
529 
530     /** Abstracts the handle information */
531     ATT_ATTR_HANDLE      handle;
532 
533     /** Abstracts the Access Operation */
534     GATT_DB_OPERATION    db_op;
535 
536 #if 1//def GATT_DB_HAVE_OFFSET_IN_PARAMS_SUPPORT
537     uint16_t               offset;
538 #endif /* GATT_DB_HAVE_OFFSET_IN_PARAMS_SUPPORT */
539 
540 } GATT_DB_PARAMS;
541 
542 
543 /**
544  *  Abstracts Handle Value Pair
545  *  This is used in multiple PDUs - see \ref ATT_WRITE_REQ_PARAM,
546  *  \ref ATT_WRITE_CMD_PARAM etc.
547  */
548 typedef struct
549 {
550     /** Attribute Value  */
551     ATT_VALUE          value;
552 
553     /** Attribute Handle */
554     ATT_ATTR_HANDLE    handle;
555 
556 } ATT_HANDLE_VALUE_PAIR;
557 
558 
559 /** ATT Handle */
560 typedef struct
561 {
562     /** Identifies the peer instance */
563     DEVICE_HANDLE     device_id;
564 
565     /** Identifies the ATT Instance */
566     ATT_CON_ID        att_id;
567 
568 } ATT_HANDLE;
569 
570 
571 
572 
573 /**
574  * GATT DB PL extension, GATT DB Handler Callback.
575  * The GATT DB PL extension calls the registered callback
576  * to indicate any ongoing GATT DB Operation.
577  * The Upper Layer can implement specific handling for any Characterisitc
578  * or Characteritistic Descriptor depending on its requirement.
579  *
580  * \param [in] handle Pointer to GATT DB identifier \ref GATT_DB_HANDLE
581  * \param [in] param  Pointer to GATT DB Parameters \ref GATT_DB_PARAMS
582  *
583  * \return API_SUCCESS if ATT/GATT response for the incoming request to be sent
584  *         from the below layer
585  *         GATT_DB_DELAYED_RESPONSE if ATT/GATT response will be sent at a
586  *         later point by the application
587  *         GATT_DB_DONOT_RESPOND if ATT/GATT response will be sent at a
588  *         later point by the application
589  *         GATT_DB_ALREADY_RESPONDED if ATT/GATT response is already sent
590  *         the application
591  *         else and Error code describing cause of failure.
592  */
593 typedef API_RESULT (* GATT_DB_PL_EXT_HANDLER_CB)
594 (
595     /* IN */ GATT_DB_HANDLE *handle,
596     /* IN */ GATT_DB_PARAMS *param
597 );
598 
599 
600 
601 #endif
602 
603 
604 #ifndef _H_BT_ATT_API_
605 #define _H_BT_ATT_API_
606 
607 #define GATT_MAX_CHAR_DESCRIPTORS 6U //todo: remove, use drnay array
608 
609 typedef struct
610 {
611     /** Start Handle */
612     ATT_ATTR_HANDLE    start_handle;
613 
614     /** End Handle */
615     ATT_ATTR_HANDLE    end_handle;
616 
617 }ATT_HANDLE_RANGE;
618 
619 /* Service Information */
620 typedef struct
621 {
622     /* Service UUID */
623     ATT_UUID uuid;
624 
625 #if 1//def ATT_128_BIT_UUID_FORMAT
626     /* Service UUID Type */
627     uint8_t uuid_type;
628 #endif /* ATT_128_BIT_UUID_FORMAT */
629 
630     /* Service Range */
631     ATT_HANDLE_RANGE range;
632 
633 } GATT_SERVICE_PARAM;
634 
635 /* Characteristic Descriptor Information */
636 typedef struct
637 {
638     /* Descriptor handle */
639     ATT_ATTR_HANDLE handle;
640 
641     /* Descriptor UUID */
642     ATT_UUID uuid;
643 
644 #if 1//def ATT_128_BIT_UUID_FORMAT
645     /* Descriptor UUID Type */
646     uint8_t uuid_type;
647 #endif /* ATT_128_BIT_UUID_FORMAT */
648 
649 } GATT_CHAR_DESC_PARAM;
650 
651 
652 
653 /* Characteristic Information */
654 typedef struct
655 {
656     /* Characteristic Range */
657     ATT_HANDLE_RANGE range;
658 
659     /* Characteristic Property */
660     uint8_t cproperty;
661 
662     /* Characteristic Value Handle */
663     ATT_ATTR_HANDLE value_handle;
664 
665     /* Characteristic UUID */
666     ATT_UUID uuid;
667 
668 #if 1//def ATT_128_BIT_UUID_FORMAT
669     /* Characteristic UUID Type */
670     uint8_t uuid_type;
671 #endif /* ATT_128_BIT_UUID_FORMAT */
672 
673     /* Characteristic desciptor index*/
674     uint8_t desc_index;
675 
676     /* Characteristics Value Offset */
677     uint16_t val_offset;
678 
679     /* Characteristic Value Length */
680     uint16_t val_length;
681 
682     /* Characteristic descriptor array */
683     GATT_CHAR_DESC_PARAM descriptor[GATT_MAX_CHAR_DESCRIPTORS];
684 } GATT_CHARACTERISTIC_PARAM;
685 
686 
687 #endif
688 
689 
690 
691 /* Characteristic Information */
692 typedef struct
693 {
694     /* Characteristic Range */
695     ATT_HANDLE_RANGE range;
696 
697     /* Characteristic Property */
698     uint8_t cproperty;
699 
700     /* Characteristic Value Handle */
701     ATT_ATTR_HANDLE value_handle;
702 
703     /* Characteristic UUID */
704     ATT_UUID uuid;
705 
706 #if 1//def ATT_128_BIT_UUID_FORMAT
707     /* Characteristic UUID Type */
708     uint8_t uuid_type;
709 #endif /* ATT_128_BIT_UUID_FORMAT */
710 
711     /* Characteristic desciptor index*/
712     uint8_t desc_index;
713 
714     /* Characteristics Value Offset */
715     uint16_t val_offset;
716 
717     /* Characteristic Value Length */
718     uint16_t val_length;
719 
720     /* Characteristic descriptor array */
721     GATT_CHAR_DESC_PARAM *descriptor; //GATT_MAX_CHAR_DESCRIPTORS
722 } ble_gatt_characteristic_param_t; //change from GATT_CHARACTERISTIC_PARAM
723 
724 
725 
726 
727 
728 typedef struct
729 {
730     API_RESULT event_result;
731     //ATT_HANDLE att_handle;
732     uint8_t conn_handle;
733     GATT_SERVICE_PARAM *service;
734     uint16_t count;
735 } ble_discovery_primary_service_t;
736 
737 
738 typedef struct
739 {
740     API_RESULT event_result;
741 //    ATT_HANDLE att_handle;
742     uint8_t conn_handle;
743     //ble_gatt_characteristic_param_t *character;
744     GATT_CHARACTERISTIC_PARAM *character;
745     uint16_t count;
746 } ble_discovery_char_t;
747 
748 
749 
750 //new api
751 typedef struct
752 {
753     uint8_t    peer_address_type;
754     bd_addr_t  peer_address;
755     uint8_t    initiating_phys;
756 
757     uint16_t conn_interval_min;
758     uint16_t conn_interval_max;
759     uint16_t conn_latency;
760     uint16_t supervision_timeout;
761 } ble_conn_param_normal_t;
762 
763 typedef struct
764 {
765     uint8_t    initiator_filter_policy;
766     uint8_t    own_address_type;
767     uint8_t    peer_address_type;
768     bd_addr_t  peer_address;
769     uint8_t    initiating_phys;
770     uint16_t *scan_interval;
771     uint16_t *scan_window;
772     uint16_t *conn_interval_min;
773     uint16_t *conn_interval_max;
774     uint16_t *conn_latency;
775     uint16_t *supervision_timeout;
776     uint16_t *minimum_ce_length;
777     uint16_t *maximum_ce_length;
778 } ble_conn_param_ex_t;
779 
780 typedef struct
781 {
782     uint8_t    peer_address_type;
783     bd_addr_t  peer_address;
784     uint16_t conn_interval_min;
785     uint16_t conn_interval_max;
786     uint16_t conn_latency;
787     uint16_t supervision_timeout;
788     uint16_t minimum_ce_length;
789     uint16_t maximum_ce_length;
790 } ble_update_conn_param_t;
791 
792 
793 typedef struct
794 {
795     API_RESULT event_result;
796     //ATT_HANDLE att_handle;
797     uint8_t conn_handle;
798     /// Peer address type
799     uint8_t peer_addr_type;
800     /// Peer BT address
801     uint8_t peer_addr[6];
802 } ble_conn_att_t;
803 
804 typedef struct
805 {
806     API_RESULT event_result;
807 //    ATT_HANDLE att_handle;
808     uint8_t conn_handle;
809     ATT_ATTR_HANDLE attr_handle;
810 } ble_att_tx_compl_t;
811 
812 typedef struct
813 {
814     API_RESULT event_result;
815 //    ATT_HANDLE att_handle;
816     uint8_t conn_handle;
817     ATT_ATTR_HANDLE attr_handle;
818 
819     uint8_t *data;
820     uint16_t len;
821 } ble_att_notify_t;
822 
823 typedef struct
824 {
825     uint16_t evt_type;
826     uint8_t    peer_address_type;
827     bd_addr_t  peer_address;
828     uint8_t rssi;
829     uint8_t *data;
830     uint8_t data_len;
831     uint8_t *name;
832 } ble_adv_report_t;
833 
834 
835 typedef struct
836 {
837     bd_addr_t peer_address;
838 
839     uint16_t conn_interval_min;
840     uint16_t conn_interval_max;
841     uint16_t conn_latency;
842     uint16_t supervision_timeout;
843 
844     uint8_t is_agree;   ///0:is not agree,1:is agree
845 } ble_conn_update_param_ind_t;
846 
847 typedef struct
848 {
849     bd_addr_t peer_address;
850 
851     uint8_t status;
852     uint16_t conn_interval;
853     uint16_t conn_latency;
854     uint16_t supervision_timeout;
855 } ble_conn_update_param_compl_ind_t;
856 
857 typedef struct
858 {
859     API_RESULT event_result;
860     //ATT_HANDLE att_handle;
861     uint8_t conn_handle;
862     ATT_ATTR_HANDLE attr_handle;
863 
864     uint8_t *data;
865     uint16_t len;
866 }ble_att_rw_t;
867