ssp.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /**************************************************************************************************
  2. Filename: ssp.h
  3. Revised: $Date: 2007-10-28 18:41:49 -0700 (Sun, 28 Oct 2007) $
  4. Revision: $Revision: 15799 $
  5. Description: Security Service Provider (SSP) interface
  6. Copyright 2004-2007 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. /*********************************************************************
  94. * TYPEDEFS
  95. */
  96. typedef struct
  97. {
  98. byte keySeqNum;
  99. byte key[SEC_KEY_LEN];
  100. } nwkKeyDesc;
  101. typedef struct
  102. {
  103. nwkKeyDesc active;
  104. uint32 frameCounter;
  105. } nwkActiveKeyItems;
  106. typedef struct
  107. {
  108. uint32 inFrmCntr;
  109. uint32 outFrmCntr;
  110. byte masterKey[SEC_KEY_LEN]; // optional!!
  111. byte linkKey[SEC_KEY_LEN];
  112. byte partnerDevice[Z_EXTADDR_LEN];
  113. } linkKeyDesc;
  114. typedef struct
  115. {
  116. byte hdrLen;
  117. byte auxLen;
  118. byte msgLen;
  119. byte secLevel;
  120. byte keyId;
  121. uint32 frameCtr;
  122. byte *key;
  123. } ssp_ctx;
  124. typedef struct
  125. {
  126. uint8* initExtAddr;
  127. uint8* rspExtAddr;
  128. uint8* key;
  129. uint8* qeu;
  130. uint8* qev;
  131. uint8* text1;
  132. uint8* text2;
  133. uint8* tag1;
  134. uint8* tag2;
  135. uint8* linkKey;
  136. uint8 type;
  137. } SSP_MacTagData_t;
  138. typedef struct
  139. {
  140. uint8 dir;
  141. uint8 secLevel;
  142. uint8 hdrLen;
  143. uint8 sduLen; //service data unit length
  144. uint8* pdu; //protocol data unit
  145. uint8 extAddr[Z_EXTADDR_LEN];
  146. uint8 keyID;
  147. uint8* key;
  148. uint8 keySeqNum;
  149. uint32 frmCntr;
  150. uint8 auxLen;
  151. uint8 micLen;
  152. } SSP_Info_t;
  153. /*********************************************************************
  154. * GLOBAL VARIABLES
  155. */
  156. //extern uint8 nwkKeyLoaded;
  157. //extern nwkKeyDesc nwkActiveKey;
  158. extern uint32 nwkFrameCounter;
  159. extern byte zgPreConfigKey[SEC_KEY_LEN];
  160. /*********************************************************************
  161. * FUNCTIONS
  162. */
  163. /*
  164. * SSP Initialization
  165. */
  166. extern void SSP_Init( void );
  167. /*
  168. * Parse Auxillary Header
  169. */
  170. extern void SSP_ParseAuxHdr( SSP_Info_t* si );
  171. /*
  172. * Process Security Information
  173. */
  174. extern ZStatus_t SSP_Process( SSP_Info_t* si );
  175. /*
  176. * Process MAC TAG Data - Generate Tags
  177. */
  178. extern ZStatus_t SSP_GetMacTags( SSP_MacTagData_t* data );
  179. /*
  180. * Returns Random Bits
  181. */
  182. extern void SSP_GetTrueRand( byte len, byte *rand );
  183. /*
  184. * Read the network active key information
  185. */
  186. extern void SSP_ReadNwkActiveKey( nwkActiveKeyItems *items );
  187. /*
  188. * Write the network active key information
  189. */
  190. extern void SSP_WriteNwkActiveKey( nwkActiveKeyItems *items );
  191. /*
  192. * Get the selected network key
  193. */
  194. extern byte *SSP_GetNwkKey( byte seqNum );
  195. /*
  196. * Secure/Unsecure a network PDU
  197. */
  198. extern ZStatus_t SSP_NwkSecurity(byte ed_flag, byte *msg, byte hdrLen, byte nsduLen);
  199. /*
  200. * Set the alternate network key
  201. */
  202. extern void SSP_UpdateNwkKey( byte *key, byte keySeqNum );
  203. /*
  204. * Make the alternate network key as active
  205. */
  206. extern void SSP_SwitchNwkKey( byte seqNum );
  207. extern void SSP_BuildNonce( byte *addr, uint32 frameCntr, byte secCtrl, byte *nonce );
  208. extern byte SSP_GetMicLen( byte securityLevel );
  209. /*********************************************************************
  210. *********************************************************************/
  211. #ifdef __cplusplus
  212. }
  213. #endif
  214. #endif /* SSP_H */