ssp.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. /**************************************************************************************************
  2. Filename: ssp.h
  3. Revised: $Date: 2010-05-11 18:37:17 -0700 (Tue, 11 May 2010) $
  4. Revision: $Revision: 22455 $
  5. Description: Security Service Provider (SSP) interface
  6. Copyright 2004-2010 Texas Instruments Incorporated. All rights reserved.
  7. IMPORTANT: Your use of this Software is limited to those specific rights
  8. granted under the terms of a software license agreement between the user
  9. who downloaded the software, his/her employer (which must be your employer)
  10. and Texas Instruments Incorporated (the "License"). You may not use this
  11. Software unless you agree to abide by the terms of the License. The License
  12. limits your use, and you acknowledge, that the Software may not be modified,
  13. copied or distributed unless embedded on a Texas Instruments microcontroller
  14. or used solely and exclusively in conjunction with a Texas Instruments radio
  15. frequency transceiver, which is integrated into your product. Other than for
  16. the foregoing purpose, you may not use, reproduce, copy, prepare derivative
  17. works of, modify, distribute, perform, display or sell this Software and/or
  18. its documentation for any purpose.
  19. YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
  20. PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
  21. INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
  22. NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
  23. TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
  24. NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
  25. LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
  26. INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
  27. OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
  28. OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
  29. (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
  30. Should you have any questions regarding your right to use this Software,
  31. contact Texas Instruments Incorporated at www.TI.com.
  32. **************************************************************************************************/
  33. #ifndef SSP_H
  34. #define SSP_H
  35. #ifdef __cplusplus
  36. extern "C"
  37. {
  38. #endif
  39. /*********************************************************************
  40. * INCLUDES
  41. */
  42. #include "ZComDef.h"
  43. /*********************************************************************
  44. * MACROS
  45. */
  46. /*********************************************************************
  47. * CONSTANTS
  48. */
  49. #define SSP_APPLY 0
  50. #define SSP_REMOVE 1
  51. // Auxiliary header field lengths
  52. #define FRAME_COUNTER_LEN 4
  53. #define SEC_KEY_LEN 16 // 128/8 octets (128-bit key is standard for ZigBee)
  54. // Security Key Indentifiers
  55. #define SEC_KEYID_LINK 0x00
  56. #define SEC_KEYID_NWK 0x01
  57. #define SEC_KEYID_TRANSPORT 0x02
  58. #define SEC_KEYID_LOAD 0x03
  59. // Security Levels
  60. #define SEC_MASK 0x07
  61. #define SEC_NONE 0x00
  62. #define SEC_MIC_32 0x01
  63. #define SEC_MIC_64 0x02
  64. #define SEC_MIC_128 0x03
  65. #define SEC_ENC 0x04
  66. #define SEC_ENC_MIC_32 0x05
  67. #define SEC_ENC_MIC_64 0x06
  68. #define SEC_ENC_MIC_128 0x07
  69. // Key types
  70. #define KEY_TYPE_TC_MASTER 0 // Trust Center Master Key
  71. #define KEY_TYPE_NWK 1 // Standard Network Key
  72. #define KEY_TYPE_APP_MASTER 2 // Application Master Key
  73. #define KEY_TYPE_APP_LINK 3 // Application Link Key
  74. #define KEY_TYPE_TC_LINK 4 // Trust Center Link Key
  75. #define KEY_TYPE_NWK_HIGH 5 // High Security Network Key
  76. #define SSP_AUXHDR_CTRL 0
  77. #define SSP_AUXHDR_FRAMECNTR 1
  78. #define SSP_AUXHDR_KEYID_MASK 0x03
  79. #define SSP_AUXHDR_KEYID_SHIFT 3
  80. #define SSP_AUXHDR_EXTNONCE_SHIFT 5
  81. #define SSP_AUXHDR_EXTNONCE_BIT 0x01
  82. #define SSP_AUXHDR_LEVEL_MASK 0x07
  83. #define SSP_AUXHDR_MIN_LEN 5
  84. #define SSP_AUXHDR_SEQNUM_LEN 1
  85. #define SSP_AUXHDR_EXT_LEN ( SSP_AUXHDR_MIN_LEN + Z_EXTADDR_LEN )
  86. #define SSP_AUXHDR_NWK_LEN ( SSP_AUXHDR_EXT_LEN + SSP_AUXHDR_SEQNUM_LEN )
  87. #define SSP_MIC_LEN_MAX 16
  88. #define SSP_NONCE_LEN 13
  89. #define SSP_TEXT_LEN 4
  90. // SSP_MacTagData_t::type
  91. #define SSP_MAC_TAGS_SKKE 0
  92. #define SSP_MAC_TAGS_EA 1
  93. // Error value used when security key NV ID is not available
  94. #define SEC_NO_KEY_NV_ID 0
  95. /*********************************************************************
  96. * TYPEDEFS
  97. */
  98. typedef struct
  99. {
  100. uint8 keySeqNum;
  101. uint8 key[SEC_KEY_LEN];
  102. } nwkKeyDesc;
  103. typedef struct
  104. {
  105. nwkKeyDesc active;
  106. uint32 frameCounter;
  107. } nwkActiveKeyItems;
  108. typedef struct
  109. {
  110. uint32 inFrmCntr;
  111. uint32 outFrmCntr;
  112. uint8 masterKey[SEC_KEY_LEN]; // optional!!
  113. uint8 linkKey[SEC_KEY_LEN];
  114. uint8 partnerDevice[Z_EXTADDR_LEN];
  115. } linkKeyDesc;
  116. typedef struct
  117. {
  118. uint8 hdrLen;
  119. uint8 auxLen;
  120. uint8 msgLen;
  121. uint8 secLevel;
  122. uint8 keyId;
  123. uint32 frameCtr;
  124. uint8 *key;
  125. } ssp_ctx;
  126. typedef struct
  127. {
  128. uint8* initExtAddr;
  129. uint8* rspExtAddr;
  130. uint8* key;
  131. uint8* qeu;
  132. uint8* qev;
  133. uint8* text1;
  134. uint8* text2;
  135. uint8* tag1;
  136. uint8* tag2;
  137. uint8* linkKey;
  138. uint8 type;
  139. } SSP_MacTagData_t;
  140. typedef struct
  141. {
  142. uint8 dir;
  143. uint8 secLevel;
  144. uint8 hdrLen;
  145. uint8 sduLen; //service data unit length
  146. uint8* pdu; //protocol data unit
  147. uint8 extAddr[Z_EXTADDR_LEN];
  148. uint8 keyID;
  149. uint16 keyNvId; // NV ID of key: NWK, TCLK or APS
  150. uint8 keySeqNum;
  151. uint32 frmCntr;
  152. uint8 auxLen;
  153. uint8 micLen;
  154. } SSP_Info_t;
  155. /*********************************************************************
  156. * GLOBAL VARIABLES
  157. */
  158. extern uint32 nwkFrameCounter;
  159. /*********************************************************************
  160. * FUNCTIONS
  161. */
  162. /*
  163. * SSP Initialization
  164. */
  165. extern void SSP_Init( void );
  166. /*
  167. * Parse Auxillary Header
  168. */
  169. extern void SSP_ParseAuxHdr( SSP_Info_t* si );
  170. /*
  171. * Process Security Information
  172. */
  173. extern ZStatus_t SSP_Process( SSP_Info_t* si );
  174. /*
  175. * Process MAC TAG Data - Generate Tags
  176. */
  177. extern ZStatus_t SSP_GetMacTags( SSP_MacTagData_t* data );
  178. /*
  179. * Returns Random Bits
  180. */
  181. extern void SSP_GetTrueRand( uint8 len, uint8 *rand );
  182. /*
  183. * Returns 8*len random bits using AES based mechanism
  184. * ( currently less than 128 bits )
  185. */
  186. extern ZStatus_t SSP_GetTrueRandAES( uint8 len, uint8 *rand );
  187. /*
  188. * Store the 16 byte random seed in NV
  189. */
  190. extern void SSP_StoreRandomSeedNV( uint8 *pSeed );
  191. /*
  192. * Read the network active key information
  193. */
  194. extern void SSP_ReadNwkActiveKey( nwkActiveKeyItems *items );
  195. /*
  196. * Get the index for the selected network key in NV
  197. */
  198. extern uint16 SSP_GetNwkKey( uint8 seqNum );
  199. /*
  200. * Secure/Unsecure a network PDU
  201. */
  202. extern ZStatus_t SSP_NwkSecurity(uint8 ed_flag, uint8 *msg, uint8 hdrLen, uint8 nsduLen);
  203. /*
  204. * Set the alternate network key
  205. */
  206. extern void SSP_UpdateNwkKey( uint8 *key, uint8 keySeqNum );
  207. /*
  208. * Make the alternate network key as active
  209. */
  210. extern void SSP_SwitchNwkKey( uint8 seqNum );
  211. extern void SSP_BuildNonce( uint8 *addr, uint32 frameCntr, uint8 secCtrl, uint8 *nonce );
  212. extern uint8 SSP_GetMicLen( uint8 securityLevel );
  213. /*********************************************************************
  214. *********************************************************************/
  215. #ifdef __cplusplus
  216. }
  217. #endif
  218. #endif /* SSP_H */