TI BLE5-Stack API Documentation  9.14.00
gapbondmgr.h
Go to the documentation of this file.
1 /******************************************************************************
2 
3  Group: WCS, BTS
4  $Target Device: DEVICES $
5 
6  ******************************************************************************
7  $License: TI_TEXT 2010 $
8  ******************************************************************************
9  $Release Name: PACKAGE NAME $
10  $Release Date: PACKAGE RELEASE DATE $
11  *****************************************************************************/
12 
21 #ifndef GAPBONDMGR_H
22 #define GAPBONDMGR_H
23 
24 #ifdef __cplusplus
25 extern "C"
26 {
27 #endif
28 
29 /*-------------------------------------------------------------------
30  * INCLUDES
31  */
32 #include "ti/ble/host/gap/gap.h"
33 
34 /*-------------------------------------------------------------------
35  * CONSTANTS
36  */
37 
43 // This is a common file for the legacy and sysconfig examples,
44 // the parameters under ifndef SYSCFG are defined in this file for
45 // the legacy examples and generated using the sysconfig tool for
46 // the sysconfig examples
47 #ifndef SYSCFG
48 #if !defined ( GAP_BONDINGS_MAX )
49 #ifdef CC23X0
51 #define GAP_BONDINGS_MAX 5
52 #else
53 #define GAP_BONDINGS_MAX 10
54 #endif // CC23X0
55 #endif
56 
57 #if GAP_BONDINGS_MAX < 1
58 #error "GAP_BONDINGS_MAX must be greater than 0"
59 #endif
60 
61 
62 #if !defined ( GAP_CHAR_CFG_MAX )
63 #define GAP_CHAR_CFG_MAX 4
65 #endif
66 #endif //SYSCFG
67 
87 #define GAPBOND_PAIRING_MODE 0x400
88 
98 #define GAPBOND_MITM_PROTECTION 0x402
99 
109 #define GAPBOND_IO_CAPABILITIES 0x403
110 
120 #define GAPBOND_OOB_ENABLED 0x404
121 
132 #define GAPBOND_OOB_DATA 0x405
133 
143 #define GAPBOND_BONDING_ENABLED 0x406
144 
157 #define GAPBOND_KEY_DIST_LIST 0x407
158 
164 #define GAPBOND_ERASE_ALLBONDS 0x409
165 
167 #define GAPBOND_AUTO_FAIL_PAIRING 0x40A
168 #define GAPBOND_AUTO_FAIL_REASON 0x40B
169 
180 #define GAPBOND_KEYSIZE 0x40C
181 
195 #define GAPBOND_AUTO_SYNC_AL 0x40D
196 
204 #define GAPBOND_BOND_COUNT 0x40E
205 
216 #define GAPBOND_BOND_FAIL_ACTION 0x40F
217 
230 #define GAPBOND_ERASE_SINGLEBOND 0x410
231 
245 #define GAPBOND_SECURE_CONNECTION 0x411
246 
265 #define GAPBOND_ECCKEY_REGEN_POLICY 0x412
266 
288 #define GAPBOND_ECC_KEYS 0x413
289 
299 #define GAPBOND_SC_HOST_DEBUG 0x414
300 
317 #define GAPBOND_ERASE_BOND_IN_CONN 0x415
318 
336 #define GAPBOND_ALLOW_DEBUG_KEYS 0x416
337 
351 #define GAPBOND_LRU_BOND_REPLACEMENT 0x418
352 
361 #define GAPBOND_ERASE_LOCAL_INFO 0x41A
362 
372 #define GAPBOND_AUTHEN_PAIRING_ONLY 0x41B
373 
384 #define GAPBOND_SAME_IRK_OPTION 0x41C
385 
395 #define GAPBOND_ERASE_BONDS_ON_ADDRESS_CHANGE 0x41D
396 
408 #define GAPBOND_PAIRING_MODE_NO_PAIRING 0x00
410 #define GAPBOND_PAIRING_MODE_WAIT_FOR_REQ 0x01
412 #define GAPBOND_PAIRING_MODE_INITIATE 0x02
414 
420 #define GAPBOND_IO_CAP_DISPLAY_ONLY 0x00
422 #define GAPBOND_IO_CAP_DISPLAY_YES_NO 0x01
424 #define GAPBOND_IO_CAP_KEYBOARD_ONLY 0x02
426 #define GAPBOND_IO_CAP_NO_INPUT_NO_OUTPUT 0x03
428 #define GAPBOND_IO_CAP_KEYBOARD_DISPLAY 0x04
430 
436 #define GAPBOND_KEYDIST_PENCKEY 0x01
438 #define GAPBOND_KEYDIST_PIDKEY 0x02
440 #define GAPBOND_KEYDIST_PSIGN 0x04
442 #define GAPBOND_KEYDIST_PLINK 0x08
444 #define GAPBOND_KEYDIST_CENCKEY 0x10
446 #define GAPBOND_KEYDIST_CIDKEY 0x20
448 #define GAPBOND_KEYDIST_CSIGN 0x40
450 #define GAPBOND_KEYDIST_CLINK 0x80
452 
458 #define GAPBOND_SAME_IRK_UPDATE_BOND_REC 0x00
460 #define GAPBOND_SAME_IRK_TERMINATE_LINK 0x01
462 
498 #define GAP_BOND_REC_ID_OFFSET 0
499 #define GAP_BOND_LOCAL_LTK_OFFSET 1
500 #define GAP_BOND_DEV_LTK_OFFSET 2
501 #define GAP_BOND_DEV_IRK_OFFSET 3
502 #define GAP_BOND_DEV_CSRK_OFFSET 4
503 #define GAP_BOND_DEV_SIGN_COUNTER_OFFSET 5
504 #define GAP_BOND_REC_IDS 6
505 
506 // Bonded State Flags
507 #define GAP_BONDED_STATE_NO_RECORD 0xFF
508 #define GAP_BONDED_STATE_UNAUTHENTICATED 0x00
509 #define GAP_BONDED_STATE_AUTHENTICATED 0x01
510 #define GAP_BONDED_STATE_SERVICE_CHANGED 0x02
511 #define GAP_BONDED_STATE_CAR 0x04
512 #define GAP_BONDED_STATE_SECURECONNECTION 0x08
513 #define GAP_BONDED_STATE_RPA_ONLY 0x10
514 
532 #define GAPBOND_PAIRING_STATE_STARTED 0x00
533 
553 #define GAPBOND_PAIRING_STATE_COMPLETE 0x01
554 
572 #define GAPBOND_PAIRING_STATE_ENCRYPTED 0x02
573 #define GAPBOND_PAIRING_STATE_BOND_SAVED 0x03
575 #define GAPBOND_PAIRING_STATE_CAR_READ 0x04
577 #define GAPBOND_PAIRING_STATE_RPAO_READ 0x05
579 #define GAPBOND_GENERATE_ECC_DONE 0x06
581 
596 #define SMP_PAIRING_FAILED_PASSKEY_ENTRY_FAILED 0x01
597 #define SMP_PAIRING_FAILED_OOB_NOT_AVAIL 0x02
599 
603 #define SMP_PAIRING_FAILED_AUTH_REQ 0x03
604 #define SMP_PAIRING_FAILED_CONFIRM_VALUE 0x04
606 #define SMP_PAIRING_FAILED_NOT_SUPPORTED 0x05
608 
612 #define SMP_PAIRING_FAILED_ENC_KEY_SIZE 0x06
613 #define SMP_PAIRING_FAILED_CMD_NOT_SUPPORTED 0x07
615 #define SMP_PAIRING_FAILED_UNSPECIFIED 0x08
617 
621 #define SMP_PAIRING_FAILED_REPEATED_ATTEMPTS 0x09
622 
626 #define SMP_PAIRING_FAILED_INVALID_PARAMETERS 0x0A
627 
631 #define SMP_PAIRING_FAILED_DHKEY_CHECK_FAILED 0x0B
632 
636 #define SMP_PAIRING_FAILED_NUM_COMPARISON_FAILED 0x0C
637 
643 #define GAPBOND_FAIL_NO_ACTION 0x00
645 #define GAPBOND_FAIL_INITIATE_PAIRING 0x01
647 #define GAPBOND_FAIL_TERMINATE_LINK 0x02
649 
653 #define GAPBOND_FAIL_TERMINATE_ERASE_BONDS 0x03
654 
658 #define GAPBOND_FAIL_TERMINATE_ERASE_SINGLE_BOND 0x04
659 
665 #define GAPBOND_SECURE_CONNECTION_NONE 0x00
667 #define GAPBOND_SECURE_CONNECTION_ALLOW 0x01
669 #define GAPBOND_SECURE_CONNECTION_ONLY 0x02
671 
681 #define GAPBOND_REGENERATE_ALWAYS 0x00
683 #define GAPBOND_REGENERATE_NEVER 0xFF
685 
687 #define ECC_KEYLEN 32
689 
695 #define GAPBOND_READ_BY_ADDR 0
697 #define GAPBOND_READ_BY_IDX 1
699 
703 /*-------------------------------------------------------------------
704  * TYPEDEFS
705  */
706 
730 typedef void (*pfnPasscodeCB_t)
731 (
732  uint8_t *deviceAddr,
733  uint16_t connectionHandle,
734  uint8_t uiInputs,
735  uint8_t uiOutputs,
736  uint32_t numComparison
737 );
738 
750 typedef void (*pfnPairStateCB_t)
751 (
752  uint16_t connectionHandle,
753  uint8_t state,
754  uint8_t status
755 );
756 
763 typedef struct
764 {
767 } gapBondCBs_t;
768 
776 typedef struct
778 {
779  uint8_t privateKey[ECC_KEYLEN];
780  uint8_t publicKeyX[ECC_KEYLEN];
781  uint8_t publicKeyY[ECC_KEYLEN];
783 
784 //structure of OOB data
785 typedef struct gapBondOOBData
786 {
787  uint8 confirm[KEYLEN]; //calculated/received confirm value
788  uint8 rand[KEYLEN]; //calculated/received random number
790 
792 typedef struct
793 {
794  uint8_t LTK[KEYLEN]; // Long Term Key (LTK)
795  uint16_t div; //lint -e754 // LTK eDiv
796  uint8_t rand[B_RANDOM_NUM_SIZE]; // LTK random number
797  uint8_t keySize; // LTK key size
798 } gapBondLTK_t;
799 
801 typedef struct
802 {
809  uint8_t addr[B_ADDR_LEN];
819  uint8_t stateFlags;
820 } gapBondRec_t;
821 
823 typedef struct
824 {
825  uint16_t attrHandle; // attribute handle
826  uint8_t value; // attribute value for this device
828 
830 typedef struct
831 {
832  uint8_t pairMode;
833  uint8_t mitm;
834  uint8_t ioCap;
835  uint8_t bonding;
838  uint8_t autoSyncAL;
839  uint8_t eccReGenPolicy;
840  uint8_t KeySize;
841  uint8_t removeLRUBond;
842  uint8_t KeyDistList;
843  uint8_t eccDebugKeys;
845  uint8_t bondFailAction;
846  uint8_t sameIrkAction;
848 
850 typedef struct
851 {
852  gapBondRec_t *pBondRec; // pBondRec - basic bond record
853  gapBondLTK_t *pLocalLtk; // localLTK - LTK used by this device during pairing
854  gapBondLTK_t *pDevLtk; // devLTK - LTK used by the peer device during pairing
855  uint8_t *pIRK; // pIRK - IRK used by the peer device during pairing
856  uint8_t *pSRK; // pSRK - SRK used by the peer device during pairing
857  uint32_t *pSignCount; // signCounter - Sign counter used by the peer device during pairing
858  gapBondCharCfg_t *pCharCfg; // charCfg - GATT characteristic configuration
860 
862 /*-------------------------------------------------------------------
863  * API's
864  */
865 
871 extern void GAPBondMgr_Register(gapBondCBs_t *pCB);
872 
882 uint8_t GAPBondMgr_GetAuthTaskID( void );
883 
895 void GAPBondMgr_ReadIRKFromNV( uint8_t* keyBuff );
896 
904 void GAPBondMgr_ReadCSRKFromNV( uint8_t* keyBuff );
905 
922 extern bStatus_t GAPBondMgr_SetParameter(uint16_t param, uint8_t len,
923  void *pValue);
924 
939 extern bStatus_t GAPBondMgr_GetParameter(uint16_t param, void *pValue);
940 
959 extern bStatus_t GAPBondMgr_Pair(uint16_t connHandle);
960 
989 extern bStatus_t GAPBondMgr_FindAddr(uint8_t *pDevAddr,
990  GAP_Peer_Addr_Types_t addrType,
991  uint8_t *pIdx,
992  GAP_Peer_Addr_Types_t *pIdentityAddrType,
993  uint8_t *pIdentityAddr);
994 
1007 extern bStatus_t GAPBondMgr_ServiceChangeInd(uint16_t connectionHandle,
1008  uint8_t setParam);
1009 
1024 extern bStatus_t GAPBondMgr_PasscodeRsp(uint16_t connectionHandle,
1025  uint8_t status, uint32_t passcode);
1026 
1038 
1052  uint8 OOBDataFlag);
1053 
1062 extern bStatus_t GAPBondMgr_GenerateEccKeys( void );
1063 
1064 /*********************************************************************
1065  * @fn GAPBondMgr_ReadLocalLTK
1066  *
1067  * @brief Read LTK from an existing bond using the device address
1068  * This API is intended to be used by the BLE stack only
1069  *
1070  * @param addrType - peer's address type
1071  * @param pDevAddr - peer's address
1072  * @param pLocalLTK - LTK used by this device during pairing
1073  *
1074  * @return SUCCESS if bond was extracted
1075  * bleGAPNotFound if there is no bond record
1076  */
1078  uint8_t *pDevAddr,
1079  gapBondLTK_t *pLocalLtk);
1080 
1096 uint8_t GapBondMgr_readBondFromNV(uint8_t mode,
1097  uint8_t *pIdentifier,
1098  GAP_Peer_Addr_Types_t addrType,
1099  gapBondNvRecord_t *pBondRecord);
1100 
1115 extern uint8_t GapBondMgr_writeBondToNv(gapBondRec_t *pBondRec,
1116  gapBondLTK_t *pLocalLtk,
1117  gapBondLTK_t *pDevLtk,
1118  uint8_t *pIRK,
1119  uint8_t *pSRK,
1120  uint32_t signCount,
1121  gapBondCharCfg_t *charCfg);
1122 
1139 extern uint8_t GapBondMgr_GetPrevAuth(uint16_t connHandle, uint8_t *pMitmReq, uint8_t *pKeySize);
1140 
1155 extern uint8_t GapBondMgr_StartEnc(uint16_t connHandle);
1156 
1157 bool GAPBondMgr_isEnable( void );
1158 /*-------------------------------------------------------------------
1159 -------------------------------------------------------------------*/
1160 #ifdef __cplusplus
1161 }
1162 #endif
1163 
1164 #endif /* GAPBONDMGR_H */
1165 
GAP_Peer_Addr_Types_t
Address types used for specifying peer address type.
Definition: gap.h:745
Public and Private ECC Keys.
Definition: gapbondmgr.h:777
bStatus_t GAPBondMgr_Pair(uint16_t connHandle)
uint8_t mitm
Definition: gapbondmgr.h:833
#define B_RANDOM_NUM_SIZE
BLE Random Number Size.
Definition: bcomdef.h:98
uint8_t bondFailAction
Definition: gapbondmgr.h:845
uint8_t autoSyncAL
Definition: gapbondmgr.h:838
uint8_t removeLRUBond
Definition: gapbondmgr.h:841
gapBondLTK_t * pLocalLtk
Definition: gapbondmgr.h:853
Structure of NV data for the connected device&#39;s encryption information.
Definition: gapbondmgr.h:792
bStatus_t GAPBondMgr_GenerateEccKeys(void)
Generates ECC keys.
uint8_t GapBondMgr_StartEnc(uint16_t connHandle)
uint8_t pairMode
Definition: gapbondmgr.h:832
bStatus_t GAPBondMgr_GetParameter(uint16_t param, void *pValue)
bStatus_t GAPBondMgr_PasscodeRsp(uint16_t connectionHandle, uint8_t status, uint32_t passcode)
void(* pfnPairStateCB_t)(uint16_t connectionHandle, uint8_t state, uint8_t status)
Definition: gapbondmgr.h:751
bStatus_t GAPBondMgr_SCGetLocalOOBParameters(gapBondOOBData_t *localOobData)
Get local Random number and confirm value for secure connection.
uint8_t secureConnection
Definition: gapbondmgr.h:836
uint8_t GAPBondMgr_GetAuthTaskID(void)
Retrieves the Task ID associated with the GAP Bond Manager for authentication purposes.
uint16_t div
Definition: gapbondmgr.h:795
Structure of NV data for the connected device&#39;s address information.
Definition: gapbondmgr.h:801
uint8_t eccReGenPolicy
Definition: gapbondmgr.h:839
uint8_t bonding
Definition: gapbondmgr.h:835
uint8_t KeySize
Definition: gapbondmgr.h:840
void GAPBondMgr_ReadCSRKFromNV(uint8_t *keyBuff)
Reads the stored CSRK (Connection Signature Resolving Key) from non-volatile memory into the provided...
gapBondLTK_t * pDevLtk
Definition: gapbondmgr.h:854
uint8_t eccDebugKeys
Definition: gapbondmgr.h:843
uint8 confirm[KEYLEN]
Definition: gapbondmgr.h:787
pfnPasscodeCB_t passcodeCB
Passcode callback.
Definition: gapbondmgr.h:765
bStatus_t GAPBondMgr_FindAddr(uint8_t *pDevAddr, GAP_Peer_Addr_Types_t addrType, uint8_t *pIdx, GAP_Peer_Addr_Types_t *pIdentityAddrType, uint8_t *pIdentityAddr)
Search for an address in the bonding table. If the address is a random private resolvable address...
void GAPBondMgr_Register(gapBondCBs_t *pCB)
Definition: gapbondmgr.h:763
uint32_t * pSignCount
Definition: gapbondmgr.h:857
uint8_t eraseBondWhileInConn
Definition: gapbondmgr.h:844
uint8_t * pSRK
Definition: gapbondmgr.h:856
void(* pfnPasscodeCB_t)(uint8_t *deviceAddr, uint16_t connectionHandle, uint8_t uiInputs, uint8_t uiOutputs, uint32_t numComparison)
Definition: gapbondmgr.h:731
uint8_t GapBondMgr_readBondFromNV(uint8_t mode, uint8_t *pIdentifier, GAP_Peer_Addr_Types_t addrType, gapBondNvRecord_t *pBondRecord)
uint8_t keySize
Definition: gapbondmgr.h:797
Aggregation of values relevant for reading a bond from NV.
Definition: gapbondmgr.h:850
gapBondCharCfg_t * pCharCfg
Definition: gapbondmgr.h:858
uint16_t attrHandle
Definition: gapbondmgr.h:825
Contains part of the GAP Bond Manager Parameters values.
Definition: gapbondmgr.h:830
struct gapBondOOBData gapBondOOBData_t
uint8_t value
Definition: gapbondmgr.h:826
uint8_t GapBondMgr_GetPrevAuth(uint16_t connHandle, uint8_t *pMitmReq, uint8_t *pKeySize)
uint8_t stateFlags
Definition: gapbondmgr.h:819
GAP layer interface.
bStatus_t GAPBondMgr_ServiceChangeInd(uint16_t connectionHandle, uint8_t setParam)
void GAPBondMgr_ReadIRKFromNV(uint8_t *keyBuff)
Reads the Identity Resolving Key (IRK) from non-volatile storage.
GAP_Peer_Addr_Types_t addrType
Definition: gapbondmgr.h:813
#define B_ADDR_LEN
Default Public and Random Address Length.
Definition: bcomdef.h:73
bStatus_t GAPBondMgr_SetParameter(uint16_t param, uint8_t len, void *pValue)
gapBondRec_t * pBondRec
Definition: gapbondmgr.h:852
uint8_t GapBondMgr_writeBondToNv(gapBondRec_t *pBondRec, gapBondLTK_t *pLocalLtk, gapBondLTK_t *pDevLtk, uint8_t *pIRK, uint8_t *pSRK, uint32_t signCount, gapBondCharCfg_t *charCfg)
Write bond record to NV.
uint8_t sameIrkAction
Definition: gapbondmgr.h:846
uint8_t KeyDistList
Definition: gapbondmgr.h:842
uint8_t authenPairingOnly
Definition: gapbondmgr.h:837
#define ECC_KEYLEN
ECC Key Length: 256 bit keys.
Definition: gapbondmgr.h:688
bool GAPBondMgr_isEnable(void)
uint8_t bStatus_t
BLE Generic Status return.
Definition: bcomdef.h:220
uint8 rand[KEYLEN]
Definition: gapbondmgr.h:788
Definition: gapbondmgr.h:785
bStatus_t GAPBondMgr_SCSetRemoteOOBParameters(gapBondOOBData_t *remoteOobData, uint8 OOBDataFlag)
Set remote&#39;s OOB parameters for secure connection.
uint8_t ioCap
Definition: gapbondmgr.h:834
bStatus_t GAPBondMgr_ReadLocalLTK(GAP_Peer_Addr_Types_t addrType, uint8_t *pDevAddr, gapBondLTK_t *pLocalLtk)
uint8_t * pIRK
Definition: gapbondmgr.h:855
#define KEYLEN
Default key length.
Definition: bcomdef.h:76
pfnPairStateCB_t pairStateCB
Pairing state callback.
Definition: gapbondmgr.h:766
Structure of NV data for the connected device&#39;s characteristic configuration.
Definition: gapbondmgr.h:823
© Copyright 1995-2025, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale