• 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 #ifndef INCLUDE_MODULES_BK_BLE_TYPES_H_
16 #define INCLUDE_MODULES_BK_BLE_TYPES_H_
17 
18 #include <common/bk_typedef.h>
19 
20 /**
21  * @brief ble APIs Version 1.0
22  * @addtogroup bk_ble_api_v1 New ble API group
23  * @{
24  */
25 
26 
27 typedef enum
28 {
29     BK_BLE_CONTROLLER_STACK_TYPE_BLE_4,
30     BK_BLE_CONTROLLER_STACK_TYPE_BLE_5_X,
31     BK_BLE_CONTROLLER_STACK_TYPE_BTDM_5_2,
32 }BK_BLE_CONTROLLER_STACK_TYPE;
33 
34 
35 typedef enum
36 {
37     BK_BLE_HOST_STACK_TYPE_RW_4,
38     BK_BLE_HOST_STACK_TYPE_RW_5_X,
39     BK_BLE_HOST_STACK_TYPE_RW_5_2,
40     BK_BLE_HOST_STACK_TYPE_ETHERMIND,
41 }BK_BLE_HOST_STACK_TYPE;
42 
43 /**
44  * @brief hci type enum
45  */
46 typedef enum
47 {
48     BK_BLE_HCI_TYPE_CMD = 1,
49     BK_BLE_HCI_TYPE_ACL = 2,
50     BK_BLE_HCI_TYPE_SCO = 3,
51     BK_BLE_HCI_TYPE_EVT = 4,
52 }BK_BLE_HCI_TYPE;
53 
54 
55 /**
56  * @brief ble api return enum
57  */
58 typedef bk_err_t ble_err_t;
59 
60 #define BK_ERR_BLE_SUCCESS               BK_OK                      /**< success */
61 #define BK_ERR_BLE_FAIL                  BK_FAIL                    /**< fail        */
62 #define BK_ERR_BLE_NO_MEM                BK_ERR_NO_MEM              /**<  no mem       */
63 #define BK_ERR_BLE_PROFILE               (BK_ERR_BLE_BASE - 1)      /**<  profile err       */
64 #define BK_ERR_BLE_CREATE_DB             (BK_ERR_BLE_BASE - 2)      /**< bk_ble_create_db err        */
65 #define BK_ERR_BLE_CMD_NOT_SUPPORT       (BK_ERR_BLE_BASE - 3)      /**< unknow cmd err        */
66 #define BK_ERR_BLE_UNKNOW_IDX            (BK_ERR_BLE_BASE - 4)      /**< index err, suchas conn_ind        */
67 #define BK_ERR_BLE_BLE_STATUS            (BK_ERR_BLE_BASE - 5)      /**<  ble status not match       */
68 #define BK_ERR_BLE_ADV_DATA              (BK_ERR_BLE_BASE - 6)      /**<  adv data err, such as too long       */
69 #define BK_ERR_BLE_CMD_RUN               (BK_ERR_BLE_BASE - 7)      /**< cmd run err        */
70 #define BK_ERR_BLE_INIT_CREATE           (BK_ERR_BLE_BASE - 8)      /**< create init err, such as bk_ble_create_init        */
71 #define BK_ERR_BLE_INIT_STATE            (BK_ERR_BLE_BASE - 9)      /**<  current init status not match       */
72 #define BK_ERR_BLE_ATTC_WRITE            (BK_ERR_BLE_BASE - 10)     /**<  att write err       */
73 #define BK_ERR_BLE_ATTC_WRITE_UNREGISTER (BK_ERR_BLE_BASE - 11)     /**<  att handle is not regist       */
74 
75 
76 
77 
78 /// max ble adv data len
79 #define BK_BLE_MAX_ADV_DATA_LEN           (0x1F)
80 
81 /// BD address length
82 #define BK_BLE_GAP_BD_ADDR_LEN       (6)
83 /// Maximal length of the Device Name value
84 #define BK_BLE_APP_DEVICE_NAME_MAX_LEN      (18)
85 
86 
87 
88 /**
89  * @brief for ble_attm_desc_t, build database perm,
90  *
91  */
92 
93 #define BK_BLE_PERM_SET(access, right) \
94     (((BK_BLE_PERM_RIGHT_ ## right) << (BK_BLE_ ## access ## _POS)) & (BK_BLE_ ## access ## _MASK))
95 
96 #define BK_BLE_PERM_GET(perm, access)\
97     (((perm) & (BK_BLE_ ## access ## _MASK)) >> (BK_BLE_ ## access ## _POS))
98 
99 
100 
101 /**
102  * @brief normal perm, for BK_BLE_PERM_SET
103  * @attention you cant use this direct, use BK_BLE_PERM_SET(RD, ENABLE) instead
104  * @brief
105  *   15   14   13   12   11   10    9    8    7    6    5    4    3    2    1    0
106  * +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
107  * |EXT | WS | I  | N  | WR | WC | RD | B  |    NP   |    IP   |   WP    |    RP   |
108  * +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
109  *
110  * Bit [0-1]  : Read Permission         (0 = NO_AUTH, 1 = UNAUTH, 2 = AUTH, 3 = SEC_CON)
111  * Bit [2-3]  : Write Permission        (0 = NO_AUTH, 1 = UNAUTH, 2 = AUTH, 3 = SEC_CON)
112  * Bit [4-5]  : Indication Permission   (0 = NO_AUTH, 1 = UNAUTH, 2 = AUTH, 3 = SEC_CON)
113  * Bit [6-7]  : Notification Permission (0 = NO_AUTH, 1 = UNAUTH, 2 = AUTH, 3 = SEC_CON)
114  *
115  * Bit [8]    : Broadcast permission
116  * Bit [9]    : Read Command accepted
117  * Bit [10]   : Write Command accepted
118  * Bit [11]   : Write Request accepted
119  * Bit [12]   : Send Notification
120  * Bit [13]   : Send Indication
121  * Bit [14]   : Write Signed accepted
122  * Bit [15]   : Extended properties present
123  */
124 
125 typedef enum
126 {
127     /// Read Permission Mask
128     BK_BLE_RP_MASK             = 0x0003,
129     BK_BLE_RP_POS              = 0,
130     /// Write Permission Mask
131     BK_BLE_WP_MASK             = 0x000C,
132     BK_BLE_WP_POS              = 2,
133     /// Indication Access Mask
134     BK_BLE_IP_MASK            = 0x0030,
135     BK_BLE_IP_POS             = 4,
136     /// Notification Access Mask
137     BK_BLE_NP_MASK            = 0x00C0,
138     BK_BLE_NP_POS             = 6,
139     /// Broadcast descriptor present
140     BK_BLE_BROADCAST_MASK     = 0x0100,
141     BK_BLE_BROADCAST_POS      = 8,
142     /// Read Access Mask
143     BK_BLE_RD_MASK            = 0x0200,
144     BK_BLE_RD_POS             = 9,
145     /// Write Command Enabled attribute Mask
146     BK_BLE_WRITE_COMMAND_MASK = 0x0400,
147     BK_BLE_WRITE_COMMAND_POS  = 10,
148     /// Write Request Enabled attribute Mask
149     BK_BLE_WRITE_REQ_MASK     = 0x0800,
150     BK_BLE_WRITE_REQ_POS      = 11,
151     /// Notification Access Mask
152     BK_BLE_NTF_MASK           = 0x1000,
153     BK_BLE_NTF_POS            = 12,
154     /// Indication Access Mask
155     BK_BLE_IND_MASK           = 0x2000,
156     BK_BLE_IND_POS            = 13,
157     /// Write Signed Enabled attribute Mask
158     BK_BLE_WRITE_SIGNED_MASK  = 0x4000,
159     BK_BLE_WRITE_SIGNED_POS   = 14,
160     /// Extended properties descriptor present
161     BK_BLE_EXT_MASK           = 0x8000,
162     BK_BLE_EXT_POS            = 15,
163 } bk_ble_perm_mask;
164 
165 
166 /**
167  * @brief Attribute Extended permissions, for BK_BLE_PERM_SET
168  * @attention you cant use this direct, use BK_BLE_PERM_SET(EKS, ENABLE) instead
169  * @brief
170  *
171  * Extended Value permission bit field
172  *
173  *   15   14   13   12   11   10    9    8    7    6    5    4    3    2    1    0
174  * +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
175  * | RI |UUID_LEN |EKS |                       Reserved                            |
176  * +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
177  *
178  * Bit [0-11] : Reserved
179  * Bit [12]   : Encryption key Size must be 16 bytes
180  * Bit [13-14]: UUID Length             (0 = 16 bits, 1 = 32 bits, 2 = 128 bits, 3 = RFU)
181  * Bit [15]   : Trigger Read Indication (0 = Value present in Database, 1 = Value not present in Database)
182  */
183 typedef enum
184 {
185     /// Check Encryption key size Mask
186     BK_BLE_EKS_MASK         = 0x1000,
187     BK_BLE_EKS_POS          = 12,
188     /// UUID Length
189     BK_BLE_UUID_LEN_MASK    = 0x6000,
190     BK_BLE_UUID_LEN_POS     = 13,
191     /// Read trigger Indication
192     BK_BLE_RI_MASK          = 0x8000,
193     BK_BLE_RI_POS           = 15,
194 } bk_ble_ext_perm_mask;
195 
196 
197 /**
198  * @brief Service permissions, for BK_BLE_PERM_SET
199  * @attention you cant use this direct, use BK_BLE_PERM_SET(SVC_UUID_LEN, UUID_16) instead
200  * @brief
201  *
202  *    7    6    5    4    3    2    1    0
203  * +----+----+----+----+----+----+----+----+
204  * |SEC |UUID_LEN |DIS |  AUTH   |EKS | MI |
205  * +----+----+----+----+----+----+----+----+
206  *
207  * Bit [0]  : Task that manage service is multi-instantiated (Connection index is conveyed)
208  * Bit [1]  : Encryption key Size must be 16 bytes
209  * Bit [2-3]: Service Permission      (0 = NO_AUTH, 1 = UNAUTH, 2 = AUTH, 3 = Secure Connect)
210  * Bit [4]  : Disable the service
211  * Bit [5-6]: UUID Length             (0 = 16 bits, 1 = 32 bits, 2 = 128 bits, 3 = RFU)
212  * Bit [7]  : Secondary Service       (0 = Primary Service, 1 = Secondary Service)
213  */
214 typedef enum
215 {
216     /// Task that manage service is multi-instantiated
217     BK_BLE_SVC_MI_MASK        = 0x01,
218     BK_BLE_SVC_MI_POS         = 0,
219     /// Check Encryption key size for service Access
220     BK_BLE_SVC_EKS_MASK       = 0x02,
221     BK_BLE_SVC_EKS_POS        = 1,
222     /// Service Permission authentication
223     BK_BLE_SVC_AUTH_MASK      = 0x0C,
224     BK_BLE_SVC_AUTH_POS       = 2,
225     /// Disable the service
226     BK_BLE_SVC_DIS_MASK       = 0x10,
227     BK_BLE_SVC_DIS_POS        = 4,
228     /// Service UUID Length
229     BK_BLE_SVC_UUID_LEN_MASK  = 0x60,
230     BK_BLE_SVC_UUID_LEN_POS   = 5,
231     /// Service type Secondary
232     BK_BLE_SVC_SECONDARY_MASK = 0x80,
233     BK_BLE_SVC_SECONDARY_POS  = 7,
234 } bk_ble_svc_perm_mask;
235 
236 
237 /*
238  * @brief Attribute & Service access mode, for BK_BLE_PERM_SET
239  * @attention you cant use this direct, use BK_BLE_PERM_SET(RD, ENABLE) instead
240  *
241  */
242 
243 enum
244 {
245     /// Disable access
246     BK_BLE_PERM_RIGHT_DISABLE   = 0,
247     /// Enable access
248     BK_BLE_PERM_RIGHT_ENABLE   = 1,
249 };
250 
251 
252 /*
253  * @brief Attribute & Service access rights, for BK_BLE_PERM_SET
254  * @attention you cant use this direct, use BK_BLE_PERM_SET(SVC_AUTH, UNAUTH) instead
255  *
256  */
257 enum
258 {
259     /// No Authentication
260     BK_BLE_PERM_RIGHT_NO_AUTH  = 0,
261     /// Access Requires Unauthenticated link
262     BK_BLE_PERM_RIGHT_UNAUTH   = 1,
263     /// Access Requires Authenticated link
264     BK_BLE_PERM_RIGHT_AUTH     = 2,
265     /// Access Requires Secure Connection link
266     BK_BLE_PERM_RIGHT_SEC_CON  = 3,
267 };
268 
269 /*
270  * @brief Attribute & Service UUID Length, for BK_BLE_PERM_SET
271  * @attention you cant use this direct, use BK_BLE_PERM_SET(SVC_UUID_LEN, UUID_16) instead
272  *
273  */
274 enum
275 {
276     /// 16  bits UUID
277     BK_BLE_PERM_RIGHT_UUID_16         = 0,
278     /// 32  bits UUID
279     BK_BLE_PERM_RIGHT_UUID_32         = 1,
280     /// 128 bits UUID
281     BK_BLE_PERM_RIGHT_UUID_128        = 2,
282     /// Invalid
283     BK_BLE_PERM_RIGHT_UUID_RFU        = 3,
284 };
285 
286 /*
287  * @brief for ble api async call result in ble_at_cmd_cb's cmd
288  */
289 typedef enum
290 {
291     BLE_CMD_NONE,
292     /// ADV_CMD:FOR BLE 5.1
293     BLE_CREATE_ADV,
294     BLE_SET_ADV_DATA,
295     BLE_SET_RSP_DATA,
296     BLE_START_ADV,
297     BLE_STOP_ADV,
298     BLE_DELETE_ADV,
299     /// ADV_CMD:FOR BLE 4.2
300     BLE_INIT_ADV,
301     BLE_DEINIT_ADV,
302     /// SCAN_CMD:FOR BLE 5.1
303     BLE_CREATE_SCAN,
304     BLE_START_SCAN,
305     BLE_STOP_SCAN,
306     BLE_DELETE_SCAN,
307     /// SCAN_CMD:FOR BLE 4.2
308     BLE_INIT_SCAN,
309     BLE_DEINIT_SCAN,
310     /// conn
311     BLE_CONN_UPDATE_MTU,
312     BLE_CONN_UPDATE_PARAM,
313     BLE_CONN_DIS_CONN,
314     BLE_CONN_READ_PHY,
315     BLE_CONN_SET_PHY,
316 
317     /// init
318     BLE_INIT_CREATE,
319     BLE_INIT_START_CONN,
320     BLE_INIT_STOP_CONN,
321     BLE_INIT_DIS_CONN,
322     BLE_INIT_READ_CHAR,
323     BLE_INIT_WRITE_CHAR,
324     ///config
325     BLE_SET_MAX_MTU,
326 
327     // PERIODIC
328     BLE_CREATE_PERIODIC,
329     BLE_START_PERIODIC,
330     BLE_STOP_PERIODIC,
331     BLE_DELETE_PERIODIC,
332 
333     BLE_SET_LOCAL_NAME,
334     BLE_GET_LOCAL_NAME,
335 
336     BLE_READ_LOCAL_ADDR,
337     BLE_CMD_MAX,
338 } ble_cmd_t;
339 
340 
341 /*
342  * @brief used in bk_ble_set_notice_cb, this enum show as "notice", you must analyse param in same time
343  */
344 typedef enum
345 {
346     /// ble stack init ok, param null
347     BLE_5_STACK_OK,
348     /// peer write our, param ble_write_req_t
349     BLE_5_WRITE_EVENT,
350     /// peer read our, param ble_read_req_t
351     BLE_5_READ_EVENT,
352     /// scan peer adv report, param ble_recv_adv_t
353     BLE_5_REPORT_ADV,
354     /// mtu change event, param ble_mtu_change_t
355     BLE_5_MTU_CHANGE,
356     /// as slaver, recv connnect event, param ble_conn_ind_t
357     BLE_5_CONNECT_EVENT,
358     /// recv disconnect event, param ble_discon_ind_t
359     BLE_5_DISCONNECT_EVENT,
360     BLE_5_ATT_INFO_REQ,
361     /// create db event, param ble_create_db_t
362     BLE_5_CREATE_DB,
363     /// tx complete event, param null
364     BLE_5_TX_DONE,
365     ///smp report
366     BLE_5_PAIRING_REQ,
367     BLE_5_PAIRING_SUCCEED,
368     BLE_5_PAIRING_FAILED,
369     BLE_5_PARING_PASSKEY_REQ,
370     BLE_5_ENCRYPT_EVENT,
371 
372     /// as master, recv connect event
373     BLE_5_INIT_CONNECT_EVENT,
374     BLE_5_INIT_DISCONNECT_EVENT,
375     BLE_5_INIT_CONNECT_FAILED_EVENT,
376 
377     BLE_5_SDP_REGISTER_FAILED,
378     /// get current conn phy result, param ble_read_phy_t
379     BLE_5_READ_PHY_EVENT,
380     /// recv conn update event, param ble_conn_param_t
381     BLE_5_CONN_UPDATA_EVENT,
382 
383     BLE_5_PERIODIC_SYNC_CMPL_EVENT,
384 
385     BLE_5_DISCOVERY_PRIMARY_SERVICE_EVENT,
386     BLE_5_DISCOVERY_CHAR_EVENT,
387 
388     BLE_5_RECV_NOTIFY_EVENT,
389 
390     BLE_5_ATT_READ_RESPONSE,
391 
392     BLE_5_CONN_UPD_PAR_ASK,
393 } ble_notice_t;
394 
395 typedef enum{
396     CHARAC_NOTIFY,
397     CHARAC_INDICATE,
398     CHARAC_READ,
399     CHARAC_READ_DONE,
400     CHARAC_WRITE_DONE,
401 }CHAR_TYPE;
402 
403 typedef void (*app_sdp_callback)(unsigned char conidx,uint16_t chars_val_hdl,unsigned char uuid_len,unsigned char *uuid);
404 typedef void (*app_sdp_charac_callback)(CHAR_TYPE type,uint8 conidx,uint16_t hdl,uint16_t len,uint8 *data);
405 
406 struct ble_sdp_svc_ind
407 {
408     /// Service UUID Length
409     uint8_t  uuid_len;
410     /// Service UUID
411     uint8_t  uuid[16];
412     /// Service start handle
413     uint16_t start_hdl;
414     /// Service end handle
415     uint16_t end_hdl;
416 };
417 
418 /// characteristic info
419 struct ble_sdp_char_inf
420 {
421     /// Characteristic UUID Length
422     uint8_t uuid_len;
423     /// Characteristic UUID
424     uint8_t uuid[16];
425     /// Characteristic handle
426     uint16_t char_hdl;
427     /// Value handle
428     uint16_t val_hdl;
429     /// Characteristic properties
430     uint8_t prop;
431     /// End of characteristic offset
432     uint8_t char_ehdl_off;
433 };
434 
435 /// characteristic description
436 struct ble_sdp_char_desc_inf
437 {
438      /// UUID length
439     uint8_t uuid_len;
440     /// UUID
441     uint8_t uuid[16];
442 
443     uint8_t char_code;
444     /// Descriptor handle
445     uint16_t desc_hdl;
446 };
447 
448 typedef struct
449 {
450     uint8_t conn_idx;
451 	uint8_t status;
452 } ble_smp_ind_t;
453 
454 
455 typedef enum{
456 	MST_TYPE_SVR_UUID = 0,
457 	MST_TYPE_ATT_UUID,
458 	MST_TYPE_ATT_DESC,
459 	MST_TYPE_SDP_END,
460 
461 	MST_TYPE_ATTC_SVR_UUID,  ///Service the UUID
462 	MST_TYPE_ATTC_ATT_UUID,  ///ATT of a service
463 	MST_TYPE_ATTC_ATT_DESC,  ///ATT DESC of a service
464 	MST_TYPS_ATTC_PARAM_ERR,  ///The delivered parameter is abnormal or unknown
465 	MST_TYPE_ATTC_ERR,	 ///if appm_get_init_attc_info return is ok && ble is disconnect,so update the event
466 	MST_TYPE_ATTC_END,	 ///End of the operation
467 	MST_TYPE_ATTC_WRITE_RSP,
468 	MST_TYPE_ATTC_WRITE_NO_RESPONSE,
469 	MST_TYPE_ATTC_CHARAC_READ_DONE,
470 
471 	MST_TYPE_MTU_EXC = 0x10,
472 	MST_TYPE_MTU_EXC_DONE,
473 
474 	MST_TYPE_UPP_ASK = 0x20,   ///Ask if you agree to update the parameter
475 	MST_TYPE_UPDATA_STATUS,    ////updata param status
476 
477 
478 }MASTER_COMMON_TYPE;
479 typedef void (*app_sdp_comm_callback)(MASTER_COMMON_TYPE type,uint8 conidx,void *param);
480 
481 enum msg_attc{
482 	MST_ATTC_ALL = 0,
483 	MST_ATTC_GET_SVR_UUID_ALL,  ////Gets all the services for this connection
484 	MST_ATTC_GET_SVR_UUID_BY_SVR_UUID,
485 	MST_ATTC_GET_ATT_UUID_ALL,  ////Gets all the ATT's for this connection
486 	MST_ATTC_GET_ATT_DESC_UUID_ALL,  ////Gets all the ATT-DESC's for this connection
487 	MST_ATTC_SVR_ATT_BY_SVR_UUID, ////Gets all ATT's for this SVR-UUID for this connection
488 	MST_ATTC_SVR_ATT_DESC_BY_SVR_UUID, ///Gets all ATT-DESC's for this SVR-UUID for this connection
489 	MST_ATTC_SVR_ATT_AND_DESC_BY_SVR_UUID, ///Gets all ATT and ATT-DESC's for this SVR-UUID for this connection
490 };
491 
492 struct ble_attc_wr_rd_op
493 {
494     /// Status of the request
495     uint8_t status;
496     /// operation sequence number - provided when operation is started
497     uint16_t seq_num;
498 };
499 
500 struct ble_attc_event_ind
501 {
502     /// Event Type
503     enum msg_attc type;
504 
505     uint8_t uuid_len;
506     uint8_t uuid[16];
507 
508     ///if start_hdl = end_hdl = 0,it is invaild
509     uint16_t start_hdl;
510     uint16_t end_hdl;
511 };
512 
513 /**
514  * @defgroup bk_ble_api_v1_typedef struct
515  * @brief ble struct type
516  * @ingroup bk_ble_api_v1_typedef struct
517  * @{
518  */
519 
520 typedef struct
521 {
522     uint8_t cmd_idx;      /**< actv_idx */
523     ble_err_t status;     /**< The status for this command */
524 } ble_cmd_param_t;
525 
526 typedef struct
527 {
528     uint8_t conn_idx;     /**< The index of the connection */
529     uint16_t prf_id;      /**< The id of the profile */
530     uint16_t att_idx;     /**< The index of the attribute */
531     uint16_t length;      /**< The length of the attribute */
532     uint8_t status;       /**< Use to know if it's possible to modify the attribute ,can contains authorization or application error code */
533 } ble_att_info_req_t;
534 
535 typedef struct
536 {
537     uint8_t conn_idx;     /**< The index of the connection */
538     uint16_t prf_id;      /**< The id of the profile */
539     uint16_t att_idx;     /**< The index of the attribute */
540     uint8_t *value;       /**< The attribute value */
541     uint16_t len;         /**< The length of the attribute value */
542 } ble_write_req_t;
543 
544 typedef struct
545 {
546     uint8_t conn_idx;     /**< The index of the connection */
547     uint16_t prf_id;      /**< The id of the profile */
548     uint16_t att_idx;     /**< The index of the attribute */
549     uint8_t *value;       /**< The attribute value */
550     uint16_t size;        /**< The size of attribute value to read*/
551     uint16_t length;      /**< The data length read */
552 } ble_read_req_t;
553 
554 typedef struct
555 {
556     uint8_t actv_idx;     /**< The index of the activity */
557     uint8_t evt_type;     /**< Event type */
558     uint8_t adv_addr_type;/**< Advertising address type: public/random */
559     uint8_t adv_addr[6];  /**<Advertising address value */
560     uint8_t data_len;     /**< Data length in advertising packet */
561     uint8_t *data;        /**< Data of advertising packet */
562     uint8_t rssi;         /**< RSSI value for advertising packet (in dBm, between -127 and +20 dBm) */
563 } ble_recv_adv_t;
564 
565 typedef struct
566 {
567     uint8_t conn_idx;     /**< The index of connection */
568     uint16_t mtu_size;    /**< The MTU size to exchange */
569 } ble_mtu_change_t;
570 
571 typedef struct
572 {
573     /// The index of connection
574     uint8_t conn_idx;
575     /// Peer address type
576     uint8_t peer_addr_type;
577     /// Peer BT address
578     uint8_t peer_addr[6];
579     /// Clock accuracy
580     uint8_t clk_accuracy;
581     /// Connection interval
582     uint16_t con_interval;
583     /// Connection latency
584     uint16_t con_latency;
585     /// Link supervision timeout
586     uint16_t sup_to;
587 } ble_conn_ind_t;
588 
589 typedef struct
590 {
591     /// The index of connection
592     uint8_t conn_idx;
593     /// Reason of disconnection
594     uint8_t reason;
595 } ble_discon_ind_t;
596 
597 typedef struct
598 {
599     uint8_t status;      /**< The status for creating db */
600     uint8_t prf_id;      /**< The id of the profile */
601 } ble_create_db_t;
602 
603 typedef struct
604 {
605     /// 16 bits UUID LSB First
606     uint8_t uuid[16];
607     /// Attribute Permissions (see enum attm_perm_mask)
608     uint16_t perm;
609     /// Attribute Extended Permissions (see enum attm_value_perm_mask)
610     uint16_t ext_perm;
611     /// Attribute Max Size
612     /// note: for characteristic declaration contains handle offset
613     /// note: for included service, contains target service handle
614     uint16_t max_size;
615 } ble_attm_desc_t;
616 
617 struct bk_ble_db_cfg
618 {
619     uint16_t prf_task_id;
620     ///Service uuid
621     uint8_t uuid[16];
622     ///Number of db
623     uint8_t att_db_nb;
624     ///Start handler, 0 means autoalloc
625     uint16_t start_hdl;
626     ///Attribute database
627     ble_attm_desc_t *att_db;
628     ///Service config
629     uint8_t svc_perm;
630 };
631 
632 typedef struct
633 {
634     //TODO put customer specific init configuration here
635 } ble_init_config_t;
636 
637 typedef struct
638 {
639     uint8_t addr[BK_BLE_GAP_BD_ADDR_LEN];
640 } bd_addr_t;
641 
642 typedef struct
643 {
644     uint8_t  tx_phy;                       /**< The transmitter PHY */
645     uint8_t  rx_phy;                       /**< The receiver PHY */
646 } ble_read_phy_t;
647 
648 typedef struct
649 {
650     uint8_t  tx_phy;                       /**< The transmitter PHY */
651     uint8_t  rx_phy;                       /**< The receiver PHY */
652     uint8_t  phy_opt;                       /**< PHY options  */
653 } ble_set_phy_t;
654 
655 typedef struct
656 {
657     /// Own address type:  public=0 / random=1 / rpa_or_pub=2 / rpa_or_rnd=3
658     uint8_t own_addr_type;
659     /// Advertising type (@see enum gapm_adv_type)
660     uint8_t adv_type;
661     /// Bit field indicating the channel mapping
662     uint8_t chnl_map;
663     /// Bit field value provided advertising properties (@see enum gapm_adv_prop for bit signification)
664     uint16_t adv_prop;
665     /// Minimum advertising interval (in unit of 625us). Must be greater than 20ms
666     uint32_t adv_intv_min;
667     /// Maximum advertising interval (in unit of 625us). Must be greater than 20ms
668     uint32_t adv_intv_max;
669     /// Indicate on which PHY primary advertising has to be performed (@see enum gapm_phy_type)
670     /// Note that LE 2M PHY is not allowed and that legacy advertising only support LE 1M PHY
671     uint8_t prim_phy;
672     /// Indicate on which PHY secondary advertising has to be performed (@see enum gapm_phy_type)
673     uint8_t second_phy;
674 } ble_adv_param_t;
675 
676 typedef struct
677 {
678     /// Own address type (@see enum gapm_own_addr)
679     uint8_t own_addr_type;
680     /// on which the advertising packets should be received
681     uint8_t scan_phy;
682     /// Scan interval
683     uint16_t scan_intv;
684     /// Scan window
685     uint16_t scan_wd;
686 } ble_scan_param_t;
687 
688 typedef struct
689 {
690     /// Connection interval minimum
691     uint16_t intv_min;
692     /// Connection interval maximum
693     uint16_t intv_max;
694     /// Connection latency
695     uint16_t con_latency;
696     /// Link supervision timeout
697     uint16_t sup_to;
698     /// on which the advertising packets should be received on the primary advertising physical channel
699     uint8_t init_phys;
700 } ble_conn_param_t;
701 
702 
703 typedef struct
704 {
705 
706     /// Periodic synchronization type (@see enum gapm_per_sync_type)
707 //    uint8_t                         type;
708     /// Connection index used for periodic sync info reception (only valid for GAPM_PER_SYNC_TYPE_PAST)
709 //    uint8_t                         conidx;
710 
711     /// 1 to disable periodic advertising report, 0 to enable them by default
712     uint8_t                         report_disable;
713 
714 
715     /// adv sid of advertiser
716     uint8_t adv_sid;
717 
718     /// Address of advertiser with which synchronization has to be established (used only if use_pal is false)
719     bd_addr_t adv_addr;
720 
721     uint8_t adv_addr_type;
722 
723     /// Number of periodic advertising that can be skipped after a successful receive. Maximum authorized
724     /// value is 499
725     uint16_t                        skip;
726     /// Synchronization timeout for the periodic advertising (in unit of 10ms between 100ms and 163.84s)
727     uint16_t                        sync_to;
728     /// Type of Constant Tone Extension device should sync on (@see enum gapm_sync_cte_type).
729     uint8_t                         cte_type;
730 } ble_periodic_param_t;
731 
732 
733 typedef struct
734 {
735     uint8_t is_agree;   ///0:is not agree,1:is agree,0xFF;Let me think about it;other:is agree
736 
737     uint8_t conn_idx;
738 
739     /// Minimum Connection Event Duration
740     uint16_t ce_len_min;
741     /// Maximum Connection Event Duration
742     uint16_t ce_len_max;
743 
744     /// Connection interval minimum
745     uint16_t intv_min;
746     /// Connection interval maximum
747     uint16_t intv_max;
748     /// Latency
749     uint16_t latency;
750     /// Supervision timeout
751     uint16_t time_out;
752 } ble_conn_update_para_ind_t;
753 
754 
755 
756 struct mst_comm_updata_para
757 {
758     /// Status of the request
759     uint8_t is_agree;   ///0:is not agree,1:is agree,0xFF;Let me think about it;other:is agree
760     /// Minimum Connection Event Duration
761     uint16_t ce_len_min;
762     /// Maximum Connection Event Duration
763     uint16_t ce_len_max;
764 
765     /// Connection interval minimum
766     uint16_t intv_min;
767     /// Connection interval maximum
768     uint16_t intv_max;
769     /// Latency
770     uint16_t latency;
771     /// Supervision timeout
772     uint16_t time_out;
773 };
774 
775 /**
776  * @brief for sync ble api call return
777  *
778  * most ble api have ble_cmd_cb_t param, you must wait is callback.
779  *
780  * @param
781  * - cmd: cmd id.
782  * - param: param
783  *
784 **/
785 typedef void (*ble_cmd_cb_t)(ble_cmd_t cmd, ble_cmd_param_t *param);
786 
787 /**
788  * @brief for async ble api event.
789  *
790  * ble event report.
791  *
792  * @param
793  * - notice: event id.
794  * - param: param
795  *
796 **/
797 typedef void (*ble_notice_cb_t)(ble_notice_t notice, void *param);
798 
799 
800 
801 /**
802  * @brief for hci callback.
803  *
804  * stack report evt, acl to upper
805  *
806  * @param
807  * - buf: payload
808  * - len: buf's len
809  *
810  * @return
811  * - BK_ERR_BLE_SUCCESS: succeed
812 **/
813 typedef ble_err_t (*ble_hci_to_host_cb)(uint8_t *buf, uint16_t len);
814 
815 /// Authentication mask
816 enum gap_auth_mask
817 {
818     /// No Flag set
819     GAP_AUTH_NONE    = 0,
820     /// Bond authentication
821     GAP_AUTH_BOND    = (1 << 0),
822     /// Man In the middle protection
823     GAP_AUTH_MITM    = (1 << 2),
824     /// Secure Connection
825     GAP_AUTH_SEC_CON = (1 << 3),
826     /// Key Notification
827     GAP_AUTH_KEY_NOTIF = (1 << 4)
828 };
829 
830 enum gap_auth
831 {
832     /// No MITM No Bonding
833     GAP_AUTH_REQ_NO_MITM_NO_BOND  = (GAP_AUTH_NONE),
834     /// No MITM Bonding
835     GAP_AUTH_REQ_NO_MITM_BOND     = (GAP_AUTH_BOND),
836     /// MITM No Bonding
837     GAP_AUTH_REQ_MITM_NO_BOND     = (GAP_AUTH_MITM),
838     /// MITM and Bonding
839     GAP_AUTH_REQ_MITM_BOND        = (GAP_AUTH_MITM | GAP_AUTH_BOND),
840     /// SEC_CON and No Bonding
841     GAP_AUTH_REQ_SEC_CON_NO_BOND  = (GAP_AUTH_SEC_CON | GAP_AUTH_MITM),
842     /// SEC_CON and Bonding
843     GAP_AUTH_REQ_SEC_CON_BOND     = (GAP_AUTH_SEC_CON | GAP_AUTH_MITM | GAP_AUTH_BOND),
844 
845     GAP_AUTH_REQ_LAST,
846 
847     /// Mask of  authentication features without reserved flag
848     GAP_AUTH_REQ_MASK             = 0x1F,
849 };
850 
851 /// IO Capability Values
852 enum gap_io_cap
853 {
854     /// Display Only
855     GAP_IO_CAP_DISPLAY_ONLY = 0x00,
856     /// Display Yes No
857     GAP_IO_CAP_DISPLAY_YES_NO,
858     /// Keyboard Only
859     GAP_IO_CAP_KB_ONLY,
860     /// No Input No Output
861     GAP_IO_CAP_NO_INPUT_NO_OUTPUT,
862     /// Keyboard Display
863     GAP_IO_CAP_KB_DISPLAY,
864     GAP_IO_CAP_LAST
865 };
866 
867 /// Security Defines
868 enum gap_sec_req
869 {
870     /// No security (no authentication and encryption)
871     GAP_NO_SEC = 0x00,
872     /// Unauthenticated pairing with encryption
873     GAP_SEC1_NOAUTH_PAIR_ENC,
874     /// Authenticated pairing with encryption
875     GAP_SEC1_AUTH_PAIR_ENC,
876     /// Unauthenticated pairing with data signing
877     GAP_SEC2_NOAUTH_DATA_SGN,
878     /// Authentication pairing with data signing
879     GAP_SEC2_AUTH_DATA_SGN,
880     /// Secure Connection pairing with encryption
881     GAP_SEC1_SEC_CON_PAIR_ENC,
882 };
883 
884 /// OOB Data Present Flag Values
885 enum gap_oob
886 {
887     /// OOB Data not present
888     GAP_OOB_AUTH_DATA_NOT_PRESENT = 0x00,
889     /// OOB data present
890     GAP_OOB_AUTH_DATA_PRESENT,
891     GAP_OOB_AUTH_DATA_LAST
892 };
893 
894 /**
895  * @}
896  */
897 
898 
899 /**
900  * @}
901  */
902 
903 #endif /* INCLUDE_MODULES_BK_BLE_TYPES_H_ */
904