ZDSecMgr.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. /**************************************************************************************************
  2. Filename: ZDSecMgr.h
  3. Revised: $Date: 2012-02-16 13:22:48 -0800 (Thu, 16 Feb 2012) $
  4. Revision: $Revision: 29339 $
  5. Description: This file contains the interface to the ZigBee Device Security Manager.
  6. Copyright 2005-2012 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 ZDSECMGR_H
  34. #define ZDSECMGR_H
  35. #ifdef __cplusplus
  36. extern "C"
  37. {
  38. #endif
  39. /******************************************************************************
  40. * INCLUDES
  41. */
  42. #include "ZComDef.h"
  43. #include "ZDApp.h"
  44. /******************************************************************************
  45. * TYPEDEFS
  46. */
  47. // Authentication options
  48. typedef enum
  49. {
  50. ZDSecMgr_Not_Authenticated = 0, // The device has not been authenticated
  51. ZDSecMgr_Authenticated_CBCK, // The devcie has been authenticated using CBKE
  52. ZDSecMgr_Authenticated_EA // The device has been authenticated using EA
  53. }ZDSecMgr_Authentication_Option;
  54. /******************************************************************************
  55. * PUBLIC FUNCTIONS
  56. */
  57. /******************************************************************************
  58. * @fn ZDSecMgrInit
  59. *
  60. * @brief Initialize ZigBee Device Security Manager.
  61. *
  62. * @param state - device initialization state
  63. *
  64. * @return none
  65. */
  66. extern void ZDSecMgrInit(uint8 state);
  67. /******************************************************************************
  68. * @fn ZDSecMgrConfig
  69. *
  70. * @brief Configure ZigBee Device Security Manager.
  71. *
  72. * @param none
  73. *
  74. * @return none
  75. */
  76. extern void ZDSecMgrConfig( void );
  77. /******************************************************************************
  78. * @fn ZDSecMgrPermitJoining
  79. *
  80. * @brief Process request to change joining permissions.
  81. *
  82. * @param duration - [in] timed duration for join in seconds
  83. * - 0x00 not allowed
  84. * - 0xFF allowed without timeout
  85. *
  86. * @return uint8 - success(TRUE:FALSE)
  87. */
  88. extern uint8 ZDSecMgrPermitJoining( uint8 duration );
  89. /******************************************************************************
  90. * @fn ZDSecMgrPermitJoiningTimeout
  91. *
  92. * @brief Process permit joining timeout
  93. *
  94. * @param none
  95. *
  96. * @return none
  97. */
  98. extern void ZDSecMgrPermitJoiningTimeout( void );
  99. /******************************************************************************
  100. * @fn ZDSecMgrNewDeviceEvent
  101. *
  102. * @brief Process a the new device event, if found reset new device
  103. * event/timer.
  104. *
  105. * @param none
  106. *
  107. * @return uint8 - found(TRUE:FALSE)
  108. */
  109. extern uint8 ZDSecMgrNewDeviceEvent( void );
  110. /******************************************************************************
  111. * @fn ZDSecMgrEvent
  112. *
  113. * @brief Handle ZDO Security Manager event/timer(ZDO_SECMGR_EVENT).
  114. *
  115. * @param none
  116. *
  117. * @return none
  118. */
  119. extern void ZDSecMgrEvent( void );
  120. /******************************************************************************
  121. * @fn ZDSecMgrEstablishKeyCfm
  122. *
  123. * @brief Process the ZDO_EstablishKeyCfm_t message.
  124. *
  125. * @param cfm - [in] ZDO_EstablishKeyCfm_t confirmation
  126. *
  127. * @return none
  128. */
  129. extern void ZDSecMgrEstablishKeyCfm( ZDO_EstablishKeyCfm_t* cfm );
  130. /******************************************************************************
  131. * @fn ZDSecMgrEstablishKeyInd
  132. *
  133. * @brief Process the ZDO_EstablishKeyInd_t message.
  134. *
  135. * @param ind - [in] ZDO_EstablishKeyInd_t indication
  136. *
  137. * @return none
  138. */
  139. extern void ZDSecMgrEstablishKeyInd( ZDO_EstablishKeyInd_t* ind );
  140. /******************************************************************************
  141. * @fn ZDSecMgrTransportKeyInd
  142. *
  143. * @brief Process the ZDO_TransportKeyInd_t message.
  144. *
  145. * @param ind - [in] ZDO_TransportKeyInd_t indication
  146. *
  147. * @return none
  148. */
  149. extern void ZDSecMgrTransportKeyInd( ZDO_TransportKeyInd_t* ind );
  150. /******************************************************************************
  151. * @fn ZDSecMgrUpdateDeviceInd
  152. *
  153. * @brief Process the ZDO_UpdateDeviceInd_t message.
  154. *
  155. * @param ind - [in] ZDO_UpdateDeviceInd_t indication
  156. *
  157. * @return none
  158. */
  159. extern void ZDSecMgrUpdateDeviceInd( ZDO_UpdateDeviceInd_t* ind );
  160. /******************************************************************************
  161. * @fn ZDSecMgrRemoveDeviceInd
  162. *
  163. * @brief Process the ZDO_RemoveDeviceInd_t message.
  164. *
  165. * @param ind - [in] ZDO_RemoveDeviceInd_t indication
  166. *
  167. * @return none
  168. */
  169. extern void ZDSecMgrRemoveDeviceInd( ZDO_RemoveDeviceInd_t* ind );
  170. /******************************************************************************
  171. * @fn ZDSecMgrRequestKeyInd
  172. *
  173. * @brief Process the ZDO_RequestKeyInd_t message.
  174. *
  175. * @param ind - [in] ZDO_RequestKeyInd_t indication
  176. *
  177. * @return none
  178. */
  179. extern void ZDSecMgrRequestKeyInd( ZDO_RequestKeyInd_t* ind );
  180. /******************************************************************************
  181. * @fn ZDSecMgrSwitchKeyInd
  182. *
  183. * @brief Process the ZDO_SwitchKeyInd_t message.
  184. *
  185. * @param ind - [in] ZDO_SwitchKeyInd_t indication
  186. *
  187. * @return none
  188. */
  189. extern void ZDSecMgrSwitchKeyInd( ZDO_SwitchKeyInd_t* ind );
  190. /******************************************************************************
  191. * @fn ZDSecMgrAuthenticateInd
  192. *
  193. * @brief Process the ZDO_AuthenticateInd_t message.
  194. *
  195. * @param ind - [in] ZDO_AuthenticateInd_t indication
  196. *
  197. * @return none
  198. */
  199. extern void ZDSecMgrAuthenticateInd( ZDO_AuthenticateInd_t* ind );
  200. /******************************************************************************
  201. * @fn ZDSecMgrAuthenticateCfm
  202. *
  203. * @brief Process the ZDO_AuthenticateCfm_t message.
  204. *
  205. * @param cfm - [in] ZDO_AuthenticateCfm_t confirmation
  206. *
  207. * @return none
  208. */
  209. extern void ZDSecMgrAuthenticateCfm( ZDO_AuthenticateCfm_t* cfm );
  210. /******************************************************************************
  211. * @fn ZDSecMgrUpdateNwkKey
  212. *
  213. * @brief Load a new NWK key and trigger a network wide update.
  214. *
  215. * @param key - [in] new NWK key
  216. * @param keySeqNum - [in] new NWK key sequence number
  217. *
  218. * @return ZStatus_t
  219. */
  220. extern ZStatus_t ZDSecMgrUpdateNwkKey( uint8* key, uint8 keySeqNum, uint16 dstAddr );
  221. /******************************************************************************
  222. * @fn ZDSecMgrSwitchNwkKey
  223. *
  224. * @brief Causes the NWK key to switch via a network wide command.
  225. *
  226. * @param keySeqNum - [in] new NWK key sequence number
  227. *
  228. * @return ZStatus_t
  229. */
  230. extern ZStatus_t ZDSecMgrSwitchNwkKey( uint8 keySeqNum, uint16 dstAddr );
  231. /******************************************************************************
  232. * @fn ZDSecMgrRequestAppKey
  233. *
  234. * @brief Request an application key with partner.
  235. *
  236. * @param partExtAddr - [in] partner extended address
  237. *
  238. * @return ZStatus_t
  239. */
  240. extern ZStatus_t ZDSecMgrRequestAppKey( uint8 *partExtAddr );
  241. /******************************************************************************
  242. * @fn ZDSecMgrSetupPartner
  243. *
  244. * @brief Setup for application key partner.
  245. *
  246. * @param partNwkAddr - [in] partner network address
  247. * @param partExtAddr - [in] partner extended address
  248. *
  249. * @return ZStatus_t
  250. */
  251. ZStatus_t ZDSecMgrSetupPartner( uint16 partNwkAddr, uint8* partExtAddr );
  252. /******************************************************************************
  253. * @fn ZDSecMgrAppKeyTypeSet
  254. *
  255. * @brief Set application key type.
  256. *
  257. * @param keyType - [in] application key type (KEY_TYPE_APP_MASTER@2 or
  258. * KEY_TYPE_APP_LINK@3
  259. *
  260. * @return ZStatus_t
  261. */
  262. ZStatus_t ZDSecMgrAppKeyTypeSet( uint8 keyType );
  263. /******************************************************************************
  264. * @fn ZDSecMgrAddLinkKey
  265. *
  266. * @brief Add the application link key to ZDSecMgr.
  267. *
  268. * @param shortAddr - [in] short address of the partner device
  269. * @param extAddr - [in] extended address of the partner device
  270. * @param key - [in] link key
  271. *
  272. * @return none
  273. */
  274. extern ZStatus_t ZDSecMgrAddLinkKey( uint16 shortAddr, uint8 *extAddr, uint8 *key);
  275. /******************************************************************************
  276. * @fn ZDSecMgrDeviceRemoveByExtAddr
  277. *
  278. * @brief Remove device entry by its ext address.
  279. *
  280. * @param pAddr - pointer to the extended address
  281. *
  282. * @return ZStatus_t
  283. */
  284. extern ZStatus_t ZDSecMgrDeviceRemoveByExtAddr( uint8 *pAddr );
  285. /******************************************************************************
  286. * @fn ZDSecMgrAddrClear
  287. *
  288. * @brief Clear security bit from Address Manager for specific device.
  289. *
  290. * @param extAddr - [in] EXT address
  291. *
  292. * @return ZStatus_t
  293. */
  294. extern ZStatus_t ZDSecMgrAddrClear( uint8* extAddr );
  295. /******************************************************************************
  296. * @fn ZDSecMgrInitNV
  297. *
  298. * @brief Initialize the SecMgr entry data in NV with all values set to 0
  299. *
  300. * @param none
  301. *
  302. * @return uint8 - <osal_nv_item_init> return codes
  303. */
  304. extern uint8 ZDSecMgrInitNV( void );
  305. /*********************************************************************
  306. * @fn ZDSecMgrSetDefaultNV
  307. *
  308. * @brief Write the defaults to NV for Entry table and for APS key data table
  309. *
  310. * @param none
  311. *
  312. * @return none
  313. */
  314. extern void ZDSecMgrSetDefaultNV( void );
  315. /******************************************************************************
  316. * @fn ZDSecMgrAPSRemove
  317. *
  318. * @brief Remove device from network.
  319. *
  320. * @param nwkAddr - device's NWK address
  321. * @param extAddr - device's Extended address
  322. * @param parentAddr - parent's NWK address
  323. *
  324. * @return ZStatus_t
  325. */
  326. ZStatus_t ZDSecMgrAPSRemove( uint16 nwkAddr, uint8 *extAddr, uint16 parentAddr );
  327. /******************************************************************************
  328. * @fn ZDSecMgrAuthenticationCheck
  329. *
  330. * @brief Check if the specific device has been authenticated or not
  331. *
  332. * @param shortAddr - [in] short address
  333. *
  334. * @return uint8 - TRUE @ authenticated
  335. * FALSE @ not authenticated
  336. */
  337. uint8 ZDSecMgrAuthenticationCheck( uint16 shortAddr );
  338. /******************************************************************************
  339. * @fn APSME_TCLinkKeySync
  340. *
  341. * @brief Sync Trust Center LINK key data.
  342. *
  343. * @param srcAddr - [in] srcAddr
  344. * @param si - [in, out] SSP_Info_t
  345. *
  346. * @return ZStatus_t
  347. */
  348. extern ZStatus_t APSME_TCLinkKeySync( uint16 srcAddr, SSP_Info_t* si );
  349. /******************************************************************************
  350. * @fn APSME_TCLinkKeyLoad
  351. *
  352. * @brief Load Trust Center LINK key data.
  353. *
  354. * @param dstAddr - [in] dstAddr
  355. * @param si - [in, out] SSP_Info_t
  356. *
  357. * @return ZStatus_t
  358. */
  359. extern ZStatus_t APSME_TCLinkKeyLoad( uint16 dstAddr, SSP_Info_t* si );
  360. /*********************************************************************
  361. * @fn ZDSecMgrReadKeyFromNv
  362. *
  363. * @brief Looks for a specific key in NV based on Index value
  364. *
  365. * @param keyNvId - Index of key to look in NV
  366. * valid values are:
  367. * ZCD_NV_NWK_ACTIVE_KEY_INFO
  368. * ZCD_NV_NWK_ALTERN_KEY_INFO
  369. * ZCD_NV_TCLK_TABLE_START + <offset_in_table>
  370. * ZCD_NV_APS_LINK_KEY_DATA_START + <offset_in_table>
  371. * ZCD_NV_MASTER_KEY_DATA_START + <offset_in_table>
  372. * ZCD_NV_PRECFGKEY
  373. *
  374. * @param *keyinfo - Data is read into this buffer.
  375. *
  376. * @return SUCCESS if NV data was copied to the keyinfo parameter .
  377. * Otherwise, NV_OPER_FAILED for failure.
  378. */
  379. extern ZStatus_t ZDSecMgrReadKeyFromNv(uint16 keyNvId, void *keyinfo);
  380. /******************************************************************************
  381. * @fn ZDSecMgrInitNVKeyTables
  382. *
  383. * @brief Initialize the NV table for All keys: NWK, Master, TCLK and APS
  384. *
  385. * @param setDefault - TRUE to set default values
  386. *
  387. * @return none
  388. */
  389. extern void ZDSecMgrInitNVKeyTables(uint8 setDefault);
  390. /******************************************************************************
  391. * @fn ZDSecMgrSaveApsLinkKey
  392. *
  393. * @brief Save APS Link Key to NV. It will loop through all the keys
  394. * to see which one to save.
  395. *
  396. * @param none
  397. *
  398. * @return none
  399. */
  400. extern void ZDSecMgrSaveApsLinkKey(void);
  401. /******************************************************************************
  402. * @fn ZDSecMgrSaveTCLinkKey
  403. *
  404. * @brief Save TC Link Key to NV. It will loop through all the keys
  405. * to see which one to save.
  406. *
  407. * @param none
  408. *
  409. * @return none
  410. */
  411. extern void ZDSecMgrSaveTCLinkKey(void);
  412. /******************************************************************************
  413. * @fn ZDSecMgrClearNVKeyValues
  414. *
  415. * @brief If NV_RESTORE is enabled and the status of the network needs
  416. * default values this fuction clears ZCD_NV_NWKKEY,
  417. * ZCD_NV_NWK_ACTIVE_KEY_INFO and ZCD_NV_NWK_ALTERN_KEY_INFO link
  418. *
  419. * @param none
  420. *
  421. * @return none
  422. */
  423. extern void ZDSecMgrClearNVKeyValues(void);
  424. /******************************************************************************
  425. * @fn ZDSecMgrFallbackNwkKey
  426. *
  427. * @brief Use the ZBA fallback network key.
  428. *
  429. * @param none
  430. *
  431. * @return none
  432. */
  433. extern void ZDSecMgrFallbackNwkKey( void );
  434. /******************************************************************************
  435. ******************************************************************************/
  436. #ifdef __cplusplus
  437. }
  438. #endif
  439. #endif /* ZDSECMGR_H */