-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcy_ble_stack_gap.h
1935 lines (1683 loc) · 80.2 KB
/
cy_ble_stack_gap.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*******************************************************************************
* \file cy_ble_stack_gap.h
* \version 3.60
*
* \brief
* This file contains declarations of public BLE APIs of the Generic Access Profile.
* It also specifies the defines, constants, and data structures required for the APIs.
*
*
* Related Document:
* BLE Standard Spec - CoreV5.0, CSS, CSAs, ESR05, ESR06
*
********************************************************************************
* \copyright
* Copyright 2017-2021, Cypress Semiconductor Corporation. All rights reserved.
* You may use this file only in accordance with the license, terms, conditions,
* disclaimers, and limitations in the end user license agreement accompanying
* the software package with which this file was provided.
*******************************************************************************/
#ifndef CY_BLE_STACK_GAP_H_
#define CY_BLE_STACK_GAP_H_
/***************************************
* Common BLE Stack includes
***************************************/
#ifdef CY_PSOC_CREATOR_USED
#include "syslib/cy_syslib.h"
#else
#include "cy_syslib.h"
#endif/* CY_PSOC_CREATOR_USED */
#include "cy_ble_stack_host_main.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/***************************************
** GAP Constants
***************************************/
/** Bluetooth Device Address size */
#define CY_BLE_GAP_BD_ADDR_SIZE 0x06u
/** BD Address type flag*/
/** Public Device Address */
#define CY_BLE_GAP_ADDR_TYPE_PUBLIC 0x00u
/** Random Device Address */
#define CY_BLE_GAP_ADDR_TYPE_RANDOM 0x01u
/** Controller generates the Resolvable Private Address based on the local
* IRK from the resolving list. If the resolving list contains no matching entry,
* uses the public address. */
#define CY_BLE_GAP_ADDR_TYPE_PUBLIC_RPA 0x02u
/** Controller generates the Resolvable Private Address based on the local
* IRK from the resolving list. If the resolving list contains no matching entry,
* uses random address. */
#define CY_BLE_GAP_ADDR_TYPE_RANDOM_RPA 0x03u
/** Max data length size */
#define CY_BLE_GAP_MAX_ADV_DATA_LEN 0x1Fu
/** Max data length size */
#define CY_BLE_GAP_MAX_SCAN_RSP_DATA_LEN 0x1Fu
/** Security modes */
#define CY_BLE_GAP_SEC_MODE_1 0x10u /**< security mode 1 */
#define CY_BLE_GAP_SEC_MODE_2 0x20u /**< security mode 2 */
#define CY_BLE_GAP_SEC_MODE_MASK 0xF0u /**< security mode bit mask */
/** Pairing properties MASK for cy_stc_ble_gap_auth_info_t */
/**
* MASK to set MITM in pairing properties for Secure connections.
*/
#define CY_BLE_GAP_SMP_SC_PAIR_PROP_MITM_MASK 0x01u
/**
* MASK to set keypress in pairing properties for Secure connections.
*/
#define CY_BLE_GAP_SMP_SC_PAIR_PROP_KP_MASK 0x02u
/** Maximum number of Bonded Devices */
#define CY_BLE_GAP_MAX_BONDED_DEVICE 0x10u
/** Out Of Band (OOB) flag*/
#define CY_BLE_GAP_OOB_ENABLE 0x01u /**< oob enable */
#define CY_BLE_GAP_OOB_DISABLE 0x00u /**< oob disable */
/** SMP Key size */
#define CY_BLE_GAP_SMP_LTK_SIZE 0x10u /**< LTK size */
#define CY_BLE_GAP_SMP_IRK_SIZE 0x10u /**< IRK size */
#define CY_BLE_GAP_SMP_CSRK_SIZE 0x10u /**< CSRK size */
#define CY_BLE_GAP_SMP_IDADDR_DATA_SIZE 0x07u /**< ID Address data size */
#define CY_BLE_GAP_SMP_MID_INFO_SIZE 0x0Au /**< Mid info size */
/** Key Distribution Flags */
#define CY_BLE_GAP_SMP_INIT_ENC_KEY_DIST 0x01u /**< Initiator enc key */
#define CY_BLE_GAP_SMP_INIT_IRK_KEY_DIST 0x02u /**< Initiator IRK */
#define CY_BLE_GAP_SMP_INIT_CSRK_KEY_DIST 0x04u /**< Initiator CSRK */
#define CY_BLE_GAP_SMP_RESP_ENC_KEY_DIST 0x10u /**< Peer enc key */
#define CY_BLE_GAP_SMP_RESP_IRK_KEY_DIST 0x20u /**< Peer IRK */
#define CY_BLE_GAP_SMP_RESP_CSRK_KEY_DIST 0x40u /**< Peer CSRK */
/** SMP P256 Public-Private Key Size */
#define CY_BLE_GAP_SMP_P256_PUBLIC_KEY_SIZE 0x40u /**< P256 public key size */
#define CY_BLE_GAP_SMP_P256_PRIVATE_KEY_SIZE 0x20u /**< P256 private key size */
/** Passkey Response */
#define CY_BLE_GAP_REJECT_PASSKEY_REQ 0x00u /**< Reject passkey request */
#define CY_BLE_GAP_ACCEPT_PASSKEY_REQ 0x01u /**< Accept passkey request */
/** Fixed Passkey */
#define CY_BLE_GAP_PASSKEY_FIXED 0x01u /**< Fixed passkey */
#define CY_BLE_GAP_PASSKEY_NOT_FIXED 0x00u /**< Non-fixed passkey */
/***************************************
** Bonding definitions
***************************************/
/** No Bonding support */
#define CY_BLE_GAP_BONDING_NONE 0x00u
/** Bonding support */
#define CY_BLE_GAP_BONDING 0x01u
/** Encryption key size */
#define CY_BLE_GAP_ENCRYP_KEY_MIN 0x07u /**< Min Enc key size */
#define CY_BLE_GAP_ENCRYP_KEY_MAX 0x10u /**< Max Enc key size */
/** User Passkey size */
#define CY_BLE_GAP_USER_PASSKEY_SIZE 0x06u /**< user passkey size */
/** Address Masks */
/** random private resolvable addr mask */
#define CY_BLE_GAP_RANDOM_PRIV_RESOLVABLE_ADDR_MASK 0x40u
/** random private non-resolvable addr mask */
#define CY_BLE_GAP_RANDOM_PRIV_NON_RESOLVABLE_ADDR_MASK 0x00u
/** public addr mask */
#define CY_BLE_GAP_PUBLIC_ADDR_MASK 0x80u
/** random static addr mask */
#define CY_BLE_GAP_RANDOM_STATIC_ADDR_MASK 0xC0u
/** Address Masks */
#define CY_BLE_GAP_RANDOM_NUMBER_SIZE 0x10u
/** Device Connected as Role. */
#define CY_BLE_GAP_LL_ROLE_SLAVE 0x01u /**< Slave role */
#define CY_BLE_GAP_LL_ROLE_MASTER 0x00u /**< Master role */
/** Link Level Encryption status */
#define CY_BLE_GAP_ENCRYPT_ON 0x01u /**< Encryption on */
#define CY_BLE_GAP_ENCRYPT_OFF 0x00u /**< Encryption off */
/** Security Requirements for strict pairing */
/** No security requirement */
#define CY_BLE_GAP_NO_SECURITY_REQUIREMENTS (0x00u)
/** Unauthenticated legacy pairing */
#define CY_BLE_GAP_SEC_UNAUTH_PAIRING (0x01u)
/** Authenticated legacy pairing */
#define CY_BLE_GAP_SEC_AUTH_PAIRING (0x02u)
/** Unauthenticated SC pairing */
#define CY_BLE_GAP_SEC_SC_PAIRING_WITH_NO_MITM (0x04u)
/** Authenticated SC pairing */
#define CY_BLE_GAP_SEC_SC_PAIRING_WITH_MITM (0x08u)
/** Legacy with OOB pairing */
#define CY_BLE_GAP_SEC_OOB_IN_LEGACY_PAIRING (0x10u)
/** SC with oob pairing */
#define CY_BLE_GAP_SEC_OOB_IN_SC_PAIRING (0x20u)
/** Security requirement bit mask */
#define CY_BLE_GAP_SEC_REQ_BIT_MASK (0x3Fu)
/***************************************
** Enumerated Types
***************************************/
/**
\addtogroup group_ble_common_api_gap_definitions
@{
*/
/** Security Levels */
typedef enum
{
/** Level 1
* Mode 1 - No security (No authentication and no encryption)
*/
CY_BLE_GAP_SEC_LEVEL_1 = 0x00u,
/** Level 2
* Mode 1 - Unauthenticated pairing with encryption (No MITM)
* Mode 2 - Unauthenticated pairing with data signing (No MITM)
*/
CY_BLE_GAP_SEC_LEVEL_2,
/** Level 3
* Mode 1 - Authenticated pairing with encryption (With MITM)
* Mode 2 - Authenticated pairing with data signing (With MITM)
*/
CY_BLE_GAP_SEC_LEVEL_3,
/** Level 4
* Secured Connection
*/
CY_BLE_GAP_SEC_LEVEL_4,
/** LE Security Level Mask */
CY_BLE_GAP_SEC_LEVEL_MASK = 0x0Fu
}cy_en_ble_gap_sec_level_t;
/** IO capability */
typedef enum
{
/** Platform supports only a mechanism to display or convey only a 6-digit number to the user.*/
CY_BLE_GAP_IOCAP_DISPLAY_ONLY = 0x00u,
/** The device has a mechanism whereby the user can indicate 'yes' or 'no'.*/
CY_BLE_GAP_IOCAP_DISPLAY_YESNO,
/** Platform supports a numeric keyboard that can input the numbers '0' through '9'
and a confirmation key(s) for 'yes' and 'no'. */
CY_BLE_GAP_IOCAP_KEYBOARD_ONLY,
/** Platform does not have the ability to display or communicate a 6 digit decimal number.*/
CY_BLE_GAP_IOCAP_NOINPUT_NOOUTPUT,
/** Platform supports a mechanism through which 6 digit numeric value can be displayed
and numeric keyboard that can input the numbers '0' through '9'. */
CY_BLE_GAP_IOCAP_KEYBOARD_DISPLAY
} cy_en_ble_gap_iocap_t;
/** Authentication Failed Error Codes */
typedef enum
{
/** No Error */
CY_BLE_GAP_AUTH_ERROR_NONE = 0x00u,
/** User input of passkey failed. For example, the user cancelled the operation. */
CY_BLE_GAP_AUTH_ERROR_PASSKEY_ENTRY_FAILED,
/** Out Of Band data is not available. Applicable if NFC is supported. */
CY_BLE_GAP_AUTH_ERROR_OOB_DATA_NOT_AVAILABLE,
/** Pairing procedure cannot be performed as authentication
requirements cannot be met due to IO capabilities of one or both devices. */
CY_BLE_GAP_AUTH_ERROR_AUTHENTICATION_REQ_NOT_MET,
/** Confirm value does not match the calculated compare value. */
CY_BLE_GAP_AUTH_ERROR_CONFIRM_VALUE_NOT_MATCH,
/** Pairing is not supported by the device. */
CY_BLE_GAP_AUTH_ERROR_PAIRING_NOT_SUPPORTED,
/** Insufficient key size for the security requirements of this device,
or if LTK is lost. */
CY_BLE_GAP_AUTH_ERROR_INSUFFICIENT_ENCRYPTION_KEY_SIZE,
/** Command received is not supported. */
CY_BLE_GAP_AUTH_ERROR_COMMAND_NOT_SUPPORTED,
/** Pairing failed due to an unspecified reason. */
CY_BLE_GAP_AUTH_ERROR_UNSPECIFIED_REASON,
/** Pairing or authentication procedure is disallowed because too little time
has elapsed since the last pairing request or security request. */
CY_BLE_GAP_AUTH_ERROR_REPEATED_ATTEMPTS,
/** Invalid Parameters in Request - Invalid Command length and Parameter value outside range. */
CY_BLE_GAP_AUTH_ERROR_INVALID_PARAMETERS ,
/** Indicates to the remote device that the DHKey Check value received does not
match the one calculated by the local device. */
CY_BLE_GAP_AUTH_ERROR_DHKEY_CHECK_FAILED,
/** Indicates that the confirm values in the numeric comparison protocol
do not match. */
CY_BLE_GAP_AUTH_ERROR_NUMERIC_COMPARISON_FAILED,
/** Indicates that the pairing over the LE transport failed due to a Pairing
Request sent over the BR/EDR transport is in process. */
CY_BLE_GAP_AUTH_ERROR_BR_EDR_PAIRING_IN_PROGRESS,
/** Indicates that the BR/EDR Link Key generated on the BR/EDR transport cannot
be used to derive and distribute keys for LE transport. */
CY_BLE_GAP_AUTH_ERROR_CROSS_TRANSPORT_KEY_GEN_DER_NOT_ALLOWED,
/** Authentication process timeout - if pairing timeout happens for the first time,
the application can choose to re-initiate the pairing procedure. If timeout occurs again,
the application may choose to disconnect the peer device. */
CY_BLE_GAP_AUTH_ERROR_AUTHENTICATION_TIMEOUT = 0x15u,
/** Link disconnected. */
CY_BLE_GAP_AUTH_ERROR_LINK_DISCONNECTED = 0x18u
}cy_en_ble_gap_auth_failed_reason_t;
/** GAP address type */
typedef enum
{
/** Random private non-resolvable address */
CY_BLE_GAP_RANDOM_PRIV_NON_RESOLVABLE_ADDR = 0x00u,
/** Random private resolvable address */
CY_BLE_GAP_RANDOM_PRIV_RESOLVABLE_ADDR = 0x01u,
/** Public address */
CY_BLE_GAP_PUBLIC_ADDR = 0x02u,
/** Random static address */
CY_BLE_GAP_RANDOM_STATIC_ADDR = 0x03u,
} cy_en_ble_gap_addr_type_t;
/** Passkey entry notification types.
These are sent to application with the CY_BLE_EVT_GAP_KEYPRESS_NOTIFICATION event parameter. */
typedef enum
{
/** Passkey entry started */
CY_BLE_GAP_PASSKEY_ENTRY_STARTED = 0x00u,
/** One digit entered */
CY_BLE_GAP_PASSKEY_DIGIT_ENTERED = 0x01u,
/** One digit erased */
CY_BLE_GAP_PASSKEY_DIGIT_ERASED = 0x02u,
/** All digits cleared */
CY_BLE_GAP_PASSKEY_CLEARED = 0x03u,
/** Passkey entry completed */
CY_BLE_GAP_PASSKEY_ENTRY_COMPLETED = 0x04u
} cy_en_ble_gap_keypress_notify_type_t;
/** GAP Direct advertiser address type */
typedef enum
{
/** Public device address type */
CY_BLE_GAP_PUBLIC_ADDR_TYPE,
/** Random private resolvable address type*/
CY_BLE_GAP_RANDOM_RESOLVABLE_ADDR_TYPE,
/** Public Identity address type*/
CY_BLE_GAP_PUBLIC_IDENTITY_ADDR_TYPE,
/** Random static Identity Address */
CY_BLE_GAP_RANDOM_IDENTITY_ADDR_TYPE
} cy_en_ble_gap_adv_addr_type_t;
/***************************************
** Exported structures and unions
***************************************/
/** BD Address of device */
typedef cy_stc_ble_bd_addr_t cy_stc_ble_gap_bd_addr_t;
/** Out of Band Parameters Information */
typedef struct
{
/** bd handle of the remote device */
uint8_t bdHandle;
/** OOB data presence flag. Allowed value are:
* CY_BLE_GAP_OOB_DISABLE
* CY_BLE_GAP_OOB_ENABLE
*/
uint8_t oobFlag;
/** 16 Octet Temporary Key to be used for OOB authentication */
uint8_t * key;
/** Pointer to OOB data */
uint8_t * oobData;
/** Length of OOB data */
uint8_t oobDataLen;
} cy_stc_ble_gap_oob_info_t;
/** Security requirement of local device used in strict pairing */
typedef struct
{
/** Security requirement */
uint8_t secReq;
/** Encryption key size */
uint8_t encKeySize;
} cy_stc_ble_gap_sec_req_t;
/** Disconnect command information */
typedef struct
{
/** Reason for disconnection. */
uint8_t reason;
/** bd handle of the remote device */
uint8_t bdHandle;
}cy_stc_ble_gap_disconnect_info_t;
/** Peer Bluetooth Device Address information */
typedef struct
{
/** Bluetooth device address */
cy_stc_ble_gap_bd_addr_t bdAddr;
/** bd handle of the remote device */
uint8_t bdHandle;
}cy_stc_ble_gap_peer_addr_info_t;
/** Security keys information */
typedef struct
{
/** Long Term Key */
uint8_t ltkInfo[CY_BLE_GAP_SMP_LTK_SIZE];
/** Encrypted Diversifier and Random Number */
uint8_t midInfo[CY_BLE_GAP_SMP_MID_INFO_SIZE];
/** Identity Resolving Key */
uint8_t irkInfo[CY_BLE_GAP_SMP_IRK_SIZE];
/**
* Public device/Static Random address type
* idAddrInfo[0] - Address Type
* idAddrInfo[1] to idAddrInfo[6] - Address
*/
uint8_t idAddrInfo[CY_BLE_GAP_SMP_IDADDR_DATA_SIZE];
/** Connection Signature Resolving Key */
uint8_t csrkInfo[CY_BLE_GAP_SMP_CSRK_SIZE];
/** bd handle of the remote device */
uint8_t bdHandle;
} cy_stc_ble_gap_sec_key_param_t;
/** Security information */
typedef struct
{
/** Security keys information parameter */
cy_stc_ble_gap_sec_key_param_t SecKeyParam;
/**This parameter indicates which keys get exchanged with a peer device.
* The following is the bit field mapping for the keys.
* Bit 0: Local Encryption information
* Bit 1: Local Identity information
* Bit 2: Local Signature Key
* Bit 3: Reserved
* Bit 4: Remote Encryption information
* Bit 5: Remote Identity information
* Bit 6: Remote Signature Key
* Bit 7: Reserved
*/
uint8_t exchangeKeysFlag;
/**This parameter indicates which keys are to be set/generated in the BLE Stack.
* The following is the bit field mapping for the keys.
* Bit 0: Local Encryption information
* Bit 1: Local Identity information
* Bit 2: Local Signature Key
* Bits 3-7: Reserved
*/
uint8_t localKeysFlag;
} cy_stc_ble_gap_sec_key_info_t;
/** Bluetooth Device Address information */
typedef struct
{
/** Identity Resolving Key */
uint8_t irkInfo[CY_BLE_GAP_SMP_IRK_SIZE];
/** Memory for gapBdAddr. Completion event will
* use this memory as output parameter.
*/
cy_stc_ble_gap_bd_addr_t gapBdAddr;
/** Device address type */
cy_en_ble_gap_addr_type_t addrType;
}cy_stc_ble_gap_bd_addr_info_t;
/** Authentication Parameters Information */
typedef struct
{
/** Security Mode setting will be value of enum cy_en_ble_gap_sec_level_t as follows:
* (CY_BLE_GAP_SEC_MODE_1 | CY_BLE_GAP_SEC_LEVEL_2)
* (CY_BLE_GAP_SEC_MODE_1 | CY_BLE_GAP_SEC_LEVEL_3)
* (CY_BLE_GAP_SEC_MODE_1 | CY_BLE_GAP_SEC_LEVEL_4)
* (CY_BLE_GAP_SEC_MODE_2 | CY_BLE_GAP_SEC_LEVEL_2)
* (CY_BLE_GAP_SEC_MODE_2 | CY_BLE_GAP_SEC_LEVEL_3)
*/
uint8_t security;
/** Bonding type setting:
* CY_BLE_GAP_BONDING_NONE
* CY_BLE_GAP_BONDING
*/
uint8_t bonding;
/** Encryption Key Size (octets)
* Minimum = 7
* maximum = 16
For a slave initiated security request, this parameter must be ignored.
*/
uint8_t ekeySize;
/** Parameter to say whether authentication is accepted or rejected with a reason.
accepted = CY_BLE_GAP_AUTH_ERROR_NONE or error code cy_en_ble_gap_auth_failed_reason_t. */
cy_en_ble_gap_auth_failed_reason_t authErr;
/**
* Bit 0: MITM (Applicable only if Secure connections)
* Use CY_BLE_GAP_SMP_SC_PAIR_PROP_MITM_MASK
* Bit 1: Key press (sets Key press bit in authentication requirements flags of
* pairing request/response. Applicable only for secure connections)
* Use CY_BLE_GAP_SMP_SC_PAIR_PROP_KP_MASK
* Bit [2-7]: RFU
*/
uint8_t pairingProperties;
/** Peer bdHandle */
uint8_t bdHandle;
} cy_stc_ble_gap_auth_info_t;
/** Authentication Passkey Information */
typedef struct
{
/** 6-digit decimal number (authentication passkey) */
uint32_t passkey;
/** Accept or reject passkey entry request. Allowed values are,
* CY_BLE_GAP_REJECT_PASSKEY_REQ
* CY_BLE_GAP_ACCEPT_PASSKEY_REQ
*/
uint8_t accept;
/** bdHandle */
uint8_t bdHandle;
}cy_stc_ble_gap_auth_pk_info_t;
/** Fixed Passkey Parameters Information */
typedef struct
{
/** 6-digit decimal number (<=999999). This is used only if isFixed is
set to CY_BLE_GAP_PASSKEY_FIXED, else ignored */
uint32_t fixedPassKey;
/** Peer bdHandle */
uint8_t bdHandle;
/** Passkey is fixed application,
* CY_BLE_GAP_PASSKEY_FIXED: 'fixedPassKey' will be used by the BLE Stack that is provided by the application.
* CY_BLE_GAP_PASSKEY_NOT_FIXED: 'fixedPassKey' will be ignored and the BLE Stack will generate as per
security procedure.
*/
uint8_t isFixed;
}cy_stc_ble_gap_auth_fix_pk_info_t;
/** GAP Connection Update parameters */
typedef struct
{
/** Minimum value for the connection event interval. This shall be less than
or equal to conn_Interval_Max. Minimum connection interval will be
connIntvMin * 1.25 ms
* Time Range: 7.5 ms to 4 sec
*/
uint16_t connIntvMin;
/** Maximum value for the connection event interval. This shall be greater
than or equal to conn_Interval_Min. Maximum connection interval will be
connIntvMax * 1.25 ms
* Time Range: 7.5 ms to 4 sec
*/
uint16_t connIntvMax;
/** Slave latency for the connection in number of connection events.
* Range: 0x0000 to 0x01F3
*/
uint16_t connLatency;
/** Supervision timeout for the LE Link. Supervision timeout will be
supervisionTO * 10 ms
* Time Range: 100 msec to 32 secs
*/
uint16_t supervisionTO;
/** Peer bdHandle */
uint8_t bdHandle;
/** connection length */
uint16_t ceLength;
}cy_stc_ble_gap_conn_update_param_info_t;
/** Secure connection only mode parameters */
typedef struct
{
/** state: 0 - Disable (Device not in secure connections only mode) \n
1 - Enable (Device is in secure connections only mode) */
uint8_t state;
}cy_stc_ble_gap_sc_mode_info_t;
/** Secure connection key press notification parameters */
typedef struct
{
/** Peer bdHandle */
uint8_t bdHandle;
/** notification type to be sent to remote identified by bdHandle */
cy_en_ble_gap_keypress_notify_type_t notificationType;
}cy_stc_ble_gap_sc_kp_notif_info_t;
/** Secure connection key press notification parameters */
typedef struct
{
/** 16 Bytes Random number to be used for generating OOB data */
uint8_t *rand;
/** Peer bdHandle */
uint8_t bdHandle;
}cy_stc_ble_gap_sc_oob_info_t;
/** Bluetooth Bonded Device Address list */
typedef struct
{
/** Pointer to list of Bluetooth device addresses and corresponding bdHandle of bonded devices */
cy_stc_ble_gap_peer_addr_info_t * bdHandleAddrList;
/** Number of bonded devices */
uint8_t noOfDevices;
}cy_stc_ble_gap_bonded_device_list_info_t;
/** SMP P-256 public-private key pair */
typedef struct
{
/** P-256 public key */
uint8_t publicKey[CY_BLE_GAP_SMP_P256_PUBLIC_KEY_SIZE];
/** P-256 private key */
uint8_t privateKey[CY_BLE_GAP_SMP_P256_PRIVATE_KEY_SIZE];
/** If it is set to 1, the public key is validated. If it is set to 0,
public key is not validated. This parameter is not applicable for
CY_BLE_EVT_GAP_GEN_SET_LOCAL_P256_KEYS_COMPLETE event. */
uint8_t isValidateKeys;
} cy_stc_ble_gap_smp_local_p256_keys_t;
/** GAP Connection Update parameters */
typedef struct
{
/** connection length */
uint16_t ceLength;
/** Peer bdHandle */
uint8_t bdHandle;
}cy_stc_ble_gap_ce_length_param_info_t;
/** GAP Connection Update parameters */
typedef struct
{
/** Priority of the connection compared to other connection */
/** 0x00 Highest and 0xFF lowest and default for all the connections */
uint8_t connPriority;
/** Peer bdHandle */
uint8_t bdHandle;
}cy_stc_ble_gap_set_conn_priority_param_t;
/* --------------------------Structure corresponding to events-------------------- */
/** Current Connection Parameters used by controller */
typedef struct
{
/** Status corresponding to this event will be the HCI error code
as defined in BLE spec 4.1 */
uint8_t status;
/** Connection interval used on this connection.
* Range: 0x0006 to 0x0C80
* Time Range: 7.5 ms to 4 sec
*/
uint16_t connIntv;
/** Slave latency for the connection in a number of connection events.
* Range: 0x0000 to 0x01F3
*/
uint16_t connLatency;
/** Supervision timeout for the LE Link. Supervision timeout will be
supervisionTO * 10 ms
* Time Range: 100 msec to 32 secs
*/
uint16_t supervisionTO;
/** bd handle of the remote device */
uint8_t bdHandle;
}cy_stc_ble_gap_conn_param_updated_in_controller_t;
/** Gap Connected Parameters */
typedef struct
{
/** status corresponding to this event will be HCI error code
as defined in BLE spec 4.1 */
uint8_t status;
/** bd handle of the remote device */
uint8_t bdHandle;
/** Connected as - master = CY_BLE_GAP_LL_ROLE_MASTER,
Slave = CY_BLE_GAP_LL_ROLE_SLAVE */
uint8_t role;
/** Address type of the Bluetooth device address
- CY_BLE_GAP_ADDR_TYPE_PUBLIC (Public device address)
- CY_BLE_GAP_ADDR_TYPE_RANDOM (Random device address) */
uint8_t peerAddrType;
/** Peer Bluetooth device address of size CY_BLE_BD_ADDR_SIZE*/
uint8_t * peerAddr;
/** Connection interval used on this connection.
* Range: 0x0006 to 0x0C80
* Time Range: 7.5 ms to 4 sec
*/
uint16_t connIntv;
/** Slave latency for the connection in number of connection events.
* Range: 0x0000 to 0x01F3
*/
uint16_t connLatency;
/** Supervision timeout for the LE Link. Supervision timeout will be
supervisionTO * 10 ms
Time Range: 100 msec to 32 secs
*/
uint16_t supervisionTO;
/** Master Clock Accuracy parameter is only valid for a slave. On a master,
this parameter shall be set to 0x00.*/
uint8_t masterClockAccuracy;
}cy_stc_ble_gap_connected_param_t;
/** OOB data */
typedef struct
{
/** Peer bdHandle */
uint8_t bdHandle;
/** Status corresponding to this event will be HCI error code
as defined in BLE spec 4.2 */
uint8_t status;
/** Rand for OOB. This is also stored in BLE Stack */
uint8_t * key;
/** OOB Data using 'key' and local Public Key */
uint8_t * oobData;
/** Length of OOB data which is 16 Bytes for Secure connections */
uint8_t oobDataLen;
}cy_stc_ble_gap_oob_data_param_t;
/** Current Connection Parameters used by controller */
typedef struct
{
/** Connection interval used on this connection.
* Range: 0x0006 to 0x0C80
* Time Range: 7.5 ms to 4 sec
*/
uint16_t connIntv;
/** Slave latency for the connection in number of connection events.
* Range: 0x0000 to 0x01F3
*/
uint16_t connLatency;
/** Supervision timeout for the LE Link. Supervision timeout will be
* supervisionTO * 10 ms
* Time Range: 100 msec to 32 secs
*/
uint16_t supervisionTo;
/** Peer Device Address */
uint8_t * peerBdAddr;
/** Peer Device Address type */
cy_en_ble_gap_adv_addr_type_t peerBdAddrType;
/** Local Resolvable Private Address
* Resolvable Private Address being used by the local device
* for this connection.
* This is valid only when the Own_Address_Type in
* connection/advertisement parameters
* is set to 0x02 or 0x03. For other Own_Address_Type values,
* this will be all zeros.
*/
uint8_t * localResolvablePvtAddr;
/** Peer Resolvable Private Address
* Resolvable Private Address being used by the peer device
* for this connection.
* This is valid only for the Peer_Address_Type
* 0x02 or 0x03. For other Peer_Address_Type values,
* this will be all zeros.
*/
uint8_t * peerResolvablePvtAddr;
/** Connected as - master = CY_BLE_GAP_LL_ROLE_MASTER,
Slave = CY_BLE_GAP_LL_ROLE_SLAVE */
uint8_t role;
/** Master clock accuracy
* 0x00 -> 500 ppm
* 0x01 -> 250 ppm
* 0x02 -> 150 ppm
* 0x03 -> 100 ppm
* 0x04 -> 75 ppm
* 0x05 -> 50 ppm
* 0x06 -> 30 ppm
* 0x07 -> 20 ppm
*/
uint8_t masterClockAccuracy;
/** Status corresponding to this event will be HCI error code.
* Values of 0 indicates connection successfully completed.
* Refer BLE spec 4.2,Vol2, Part D for Error codes.
*/
uint8_t status;
/** bd handle of the remote device */
uint8_t bdHandle;
}cy_stc_ble_gap_enhance_conn_complete_param_t;
/** Disconnection Parameters */
typedef struct
{
/** HCI error code as defined in Bluetooth 4.1 core specification, Volume 2,
Part D, section 1.3 */
uint8_t status;
/** Peer bdHandle */
uint8_t bdHandle;
/** Reason for disconnection */
uint8_t reason;
}cy_stc_ble_gap_disconnect_param_t;
/** Encryption Change Parameters */
typedef struct
{
/** Peer bdHandle */
uint8_t bdHandle;
/** Encryption change event for active connection. 'evParam' can be decoded as
encryption = CY_BLE_GAP_ENCRYPT_OFF -> Encryption OFF
encryption = CY_BLE_GAP_ENCRYPT_ON -> Encryption ON */
uint8_t encryption;
}cy_stc_ble_gap_encrypt_change_param_t;
/** @} */
/***************************************
** Exported APIs
***************************************/
/**
\addtogroup group_ble_common_api_gap_functions
@{
*/
/******************************************************************************
* Function Name: Cy_BLE_GAP_SetIoCap
***************************************************************************//**
*
* This function sets the IO capability that is used during pairing procedure.
* This is a blocking function. No event is generated on calling this function.
*
* The input capabilities are described in the following table:
*
* Capability | Description
* ----------- | -----------
* No input | Device does not have the ability to indicate "yes" or "no".
* Yes/No | Device has at least two buttons that can be easily mapped to "yes" and "no" or the device has a mechanism whereby the user can indicate either "yes" or "no".
* Keyboard | Device has a numeric keyboard that can input the numbers "0" through "9" and a confirmation. Device also has at least two buttons that can be easily mapped to "yes" and "no" or the device has a mechanism whereby the user can indicate either "yes" or "no".
*
* The output capabilities are described in the following table:
*
* Capability | Description
* ----------- | -----------
* No output | Device does not have the ability to display or communicate a 6-digit decimal number.
* Numeric output | Device has the ability to display or communicate a 6-digit decimal number.
*
* The combined capability is defined in the following table:
*
* Input Capability | No Output | Numeric Output
* ----------- | ----------- | ------------
* No input | NoInputNoOutput | DisplayOnly
* Yes/No | NoInputNoOutput | DisplayYesNo
* Keyboard | KeyboardOnly | KeyboardDisplay
*
* For more details, refer to Bluetooth Core Spec 5.0, Vol 3, Part C, 5.2.2.4
*
* \param param: IO parameter is of type cy_en_ble_gap_iocap_t.
*
* \return
* cy_en_ble_api_result_t : Return value indicates if the function succeeded or
* failed. Following are the possible error codes.
*
* Errors codes | Description
* ------------ | -----------
* CY_BLE_SUCCESS | On successful operation
* CY_BLE_ERROR_INVALID_PARAMETER | On specifying invalid input parameter
*
******************************************************************************/
cy_en_ble_api_result_t Cy_BLE_GAP_SetIoCap
(
const cy_en_ble_gap_iocap_t * param
);
/******************************************************************************
* Function Name: Cy_BLE_GAP_SetSecurityRequirements
***************************************************************************//**
*
* This function sets the security requirements of local device and encryption
* key size requirement of the local device. This is a blocking function. No event
* is generated on calling this function. Application should call this function on receiving 'CY_BLE_EVT_STACK_ON' event.
* The Security requirements are defined in the following table:
*
* Security Requirement | Description
* ---------------------- | -----------
* CY_BLE_GAP_NO_SECURITY_REQUIREMENTS | Default:Security requirement specifies there are no security requirements
* CY_BLE_GAP_SEC_UNAUTH_PAIRING | Bit 0: Legacy pairing with NO MITM protection
* CY_BLE_GAP_SEC_AUTH_PAIRING | Bit 1: Legacy pairing with MITM protection
* CY_BLE_GAP_SEC_SC_PAIRING_WITH_NO_MITM | Bit 2: Secured Connection pairing with NO MITM protection
* CY_BLE_GAP_SEC_SC_PAIRING_WITH_MITM | Bit 3: Secured Connection pairing with MITM protection
* CY_BLE_GAP_SEC_OOB_IN_LEGACY_PAIRING | Bit 4: Legacy pairing with OOB method
* CY_BLE_GAP_SEC_OOB_IN_SC_PAIRING | Bit 5: Secured Connection pairing with OOB method
*
* The BLE Stack will check the received security request against the set security requirements during the pairing procedure.
* If the security requirements are not met, then pairing is rejected by the BLE Stack.
*
* For example: Cy_BLE_GAP_SetSecurityRequirements() is called with secReq as CY_BLE_GAP_SEC_SC_PAIRING_WITH_MITM.
* If the BLE Stack receives any pairing request with Secured Connection (SC) bit and MITM bit not set,
* then that pairing request will be rejected by the BLE stack.
*
* Note: If the 'Secured Connection (SC) Only' mode is set, then these security requirements are not
* considered during pairing procedure. This is to maintain Backward Compatibility for SC Only mode.
*
* \param param: Parameter is a pointer to type cy_stc_ble_gap_sec_req_t.
*
* secReq: The application can set
* multiple security requirements by ORing them in this parameter.
* For example: If secReq is (CY_BLE_GAP_SEC_UNAUTH_PAIRING | CY_BLE_GAP_SEC_SC_PAIRING_WITH_NO_MITM),
* then the BLE Stack allows pairing only if the received pairing request is either Legacy
* pairing with NO MITM or Secured Connection pairing with NO MITM.
*
* encKeySize: Encryption key size requirement of the local device.
* This parameter does not affect pairing procedure on the central side.
* At the peripheral side, if the negotiated key size is less than the key size set by this function, then the BLE Stack will
* reject the pairing request.
*
* \return
* cy_en_ble_api_result_t : Return value indicates if the function succeeded or
* failed. Following are the possible error codes.
*
* Errors codes | Description
* ------------ | -----------
* CY_BLE_SUCCESS | On successful operation
* CY_BLE_ERROR_INVALID_PARAMETER | On specifying invalid input parameter
*
******************************************************************************/
cy_en_ble_api_result_t Cy_BLE_GAP_SetSecurityRequirements
(
cy_stc_ble_gap_sec_req_t * param