ZComDef.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. /**************************************************************************************************
  2. Filename: ZComDef.h
  3. Revised: $Date: 2012-01-12 17:54:52 -0800 (Thu, 12 Jan 2012) $
  4. Revision: $Revision: 28926 $
  5. Description: Type definitions and macros.
  6. Copyright 2004-2011 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 ZCOMDEF_H
  34. #define ZCOMDEF_H
  35. #ifdef __cplusplus
  36. extern "C"
  37. {
  38. #endif
  39. /*********************************************************************
  40. * INCLUDES
  41. */
  42. #include "comdef.h"
  43. #include "saddr.h"
  44. /*********************************************************************
  45. * CONSTANTS
  46. */
  47. #define osal_cpyExtAddr(a, b) sAddrExtCpy((a), (const uint8 *)(b))
  48. #define osal_ExtAddrEqual(a, b) sAddrExtCmp((const uint8 *)(a), (const uint8 *)(b))
  49. #define osal_copyAddress(a, b) sAddrCpy( (sAddr_t *)(a), (const sAddr_t *)(b) )
  50. /*********************************************************************
  51. * CONSTANTS
  52. */
  53. // Build Device Types - Used during compilation
  54. // These are the types of devices to build
  55. // Bit masked into ZSTACK_DEVICE_BUILD
  56. #define DEVICE_BUILD_COORDINATOR 0x01
  57. #define DEVICE_BUILD_ROUTER 0x02
  58. #define DEVICE_BUILD_ENDDEVICE 0x04
  59. /*** Return Values ***/
  60. #define ZSUCCESS SUCCESS
  61. /*** Component IDs ***/
  62. #define COMPID_OSAL 0
  63. #define COMPID_MTEL 1
  64. #define COMPID_MTSPCI 2
  65. #define COMPID_NWK 3
  66. #define COMPID_NWKIF 4
  67. #define COMPID_MACCB 5
  68. #define COMPID_MAC 6
  69. #define COMPID_APP 7
  70. #define COMPID_TEST 8
  71. #define COMPID_RTG 9
  72. #define COMPID_DATA 11
  73. /* Temp CompIDs for testing */
  74. #define COMPID_TEST_NWK_STARTUP 20
  75. #define COMPID_TEST_SCAN_CONFIRM 21
  76. #define COMPID_TEST_ASSOC_CONFIRM 22
  77. #define COMPID_TEST_REMOTE_DATA_CONFIRM 23
  78. // OSAL NV item IDs
  79. #define ZCD_NV_EXTADDR 0x0001
  80. #define ZCD_NV_BOOTCOUNTER 0x0002
  81. #define ZCD_NV_STARTUP_OPTION 0x0003
  82. #define ZCD_NV_START_DELAY 0x0004
  83. // NWK Layer NV item IDs
  84. #define ZCD_NV_NIB 0x0021
  85. #define ZCD_NV_DEVICE_LIST 0x0022
  86. #define ZCD_NV_ADDRMGR 0x0023
  87. #define ZCD_NV_POLL_RATE 0x0024
  88. #define ZCD_NV_QUEUED_POLL_RATE 0x0025
  89. #define ZCD_NV_RESPONSE_POLL_RATE 0x0026
  90. #define ZCD_NV_REJOIN_POLL_RATE 0x0027
  91. #define ZCD_NV_DATA_RETRIES 0x0028
  92. #define ZCD_NV_POLL_FAILURE_RETRIES 0x0029
  93. #define ZCD_NV_STACK_PROFILE 0x002A
  94. #define ZCD_NV_INDIRECT_MSG_TIMEOUT 0x002B
  95. #define ZCD_NV_ROUTE_EXPIRY_TIME 0x002C
  96. #define ZCD_NV_EXTENDED_PAN_ID 0x002D
  97. #define ZCD_NV_BCAST_RETRIES 0x002E
  98. #define ZCD_NV_PASSIVE_ACK_TIMEOUT 0x002F
  99. #define ZCD_NV_BCAST_DELIVERY_TIME 0x0030
  100. #define ZCD_NV_NWK_MODE 0x0031
  101. #define ZCD_NV_CONCENTRATOR_ENABLE 0x0032
  102. #define ZCD_NV_CONCENTRATOR_DISCOVERY 0x0033
  103. #define ZCD_NV_CONCENTRATOR_RADIUS 0x0034
  104. #define ZCD_NV_CONCENTRATOR_RC 0x0036
  105. #define ZCD_NV_NWK_MGR_MODE 0x0037
  106. #define ZCD_NV_SRC_RTG_EXPIRY_TIME 0x0038
  107. #define ZCD_NV_ROUTE_DISCOVERY_TIME 0x0039
  108. #define ZCD_NV_NWK_ACTIVE_KEY_INFO 0x003A
  109. #define ZCD_NV_NWK_ALTERN_KEY_INFO 0x003B
  110. #define ZCD_NV_ROUTER_OFF_ASSOC_CLEANUP 0x003C
  111. // APS Layer NV item IDs
  112. #define ZCD_NV_BINDING_TABLE 0x0041
  113. #define ZCD_NV_GROUP_TABLE 0x0042
  114. #define ZCD_NV_APS_FRAME_RETRIES 0x0043
  115. #define ZCD_NV_APS_ACK_WAIT_DURATION 0x0044
  116. #define ZCD_NV_APS_ACK_WAIT_MULTIPLIER 0x0045
  117. #define ZCD_NV_BINDING_TIME 0x0046
  118. #define ZCD_NV_APS_USE_EXT_PANID 0x0047
  119. #define ZCD_NV_APS_USE_INSECURE_JOIN 0x0048
  120. #define ZCD_NV_APS_NONMEMBER_RADIUS 0x004B // Multicast non_member radius
  121. #define ZCD_NV_APS_LINK_KEY_TABLE 0x004C
  122. // Security NV Item IDs
  123. #define ZCD_NV_SECURITY_LEVEL 0x0061
  124. #define ZCD_NV_PRECFGKEY 0x0062
  125. #define ZCD_NV_PRECFGKEYS_ENABLE 0x0063
  126. #define ZCD_NV_SECURITY_MODE 0x0064
  127. #define ZCD_NV_SECURE_PERMIT_JOIN 0x0065
  128. #define ZCD_NV_IMPLICIT_CERTIFICATE 0x0069
  129. #define ZCD_NV_DEVICE_PRIVATE_KEY 0x006A
  130. #define ZCD_NV_CA_PUBLIC_KEY 0x006B
  131. #define ZCD_NV_USE_DEFAULT_TCLK 0x006D
  132. #define ZCD_NV_TRUSTCENTER_ADDR 0x006E
  133. #define ZCD_NV_RNG_COUNTER 0x006F
  134. #define ZCD_NV_RANDOM_SEED 0x0070
  135. // ZDO NV Item IDs
  136. #define ZCD_NV_USERDESC 0x0081
  137. #define ZCD_NV_NWKKEY 0x0082
  138. #define ZCD_NV_PANID 0x0083
  139. #define ZCD_NV_CHANLIST 0x0084
  140. #define ZCD_NV_LEAVE_CTRL 0x0085
  141. #define ZCD_NV_SCAN_DURATION 0x0086
  142. #define ZCD_NV_LOGICAL_TYPE 0x0087
  143. #define ZCD_NV_NWKMGR_MIN_TX 0x0088
  144. #define ZCD_NV_NWKMGR_ADDR 0x0089
  145. #define ZCD_NV_ZDO_DIRECT_CB 0x008F
  146. // ZCL NV item IDs
  147. #define ZCD_NV_SCENE_TABLE 0x0091
  148. // Non-standard NV item IDs
  149. #define ZCD_NV_SAPI_ENDPOINT 0x00A1
  150. // NV Items Reserved for Commissioning Cluster Startup Attribute Set (SAS):
  151. // 0x00B1 - 0x00BF: Parameters related to APS and NWK layers
  152. // 0x00C1 - 0x00CF: Parameters related to Security
  153. // 0x00D1 - 0x00DF: Current key parameters
  154. #define ZCD_NV_SAS_SHORT_ADDR 0x00B1
  155. #define ZCD_NV_SAS_EXT_PANID 0x00B2
  156. #define ZCD_NV_SAS_PANID 0x00B3
  157. #define ZCD_NV_SAS_CHANNEL_MASK 0x00B4
  158. #define ZCD_NV_SAS_PROTOCOL_VER 0x00B5
  159. #define ZCD_NV_SAS_STACK_PROFILE 0x00B6
  160. #define ZCD_NV_SAS_STARTUP_CTRL 0x00B7
  161. #define ZCD_NV_SAS_TC_ADDR 0x00C1
  162. #define ZCD_NV_SAS_TC_MASTER_KEY 0x00C2
  163. #define ZCD_NV_SAS_NWK_KEY 0x00C3
  164. #define ZCD_NV_SAS_USE_INSEC_JOIN 0x00C4
  165. #define ZCD_NV_SAS_PRECFG_LINK_KEY 0x00C5
  166. #define ZCD_NV_SAS_NWK_KEY_SEQ_NUM 0x00C6
  167. #define ZCD_NV_SAS_NWK_KEY_TYPE 0x00C7
  168. #define ZCD_NV_SAS_NWK_MGR_ADDR 0x00C8
  169. #define ZCD_NV_SAS_CURR_TC_MASTER_KEY 0x00D1
  170. #define ZCD_NV_SAS_CURR_NWK_KEY 0x00D2
  171. #define ZCD_NV_SAS_CURR_PRECFG_LINK_KEY 0x00D3
  172. // NV Items Reserved for Trust Center Link Key Table entries
  173. // 0x0101 - 0x01FF
  174. #define ZCD_NV_TCLK_TABLE_START 0x0101
  175. #define ZCD_NV_TCLK_TABLE_END 0x01FF
  176. // NV Items Reserved for APS Link Key Table entries
  177. // 0x0201 - 0x02FF
  178. #define ZCD_NV_APS_LINK_KEY_DATA_START 0x0201 // APS key data
  179. #define ZCD_NV_APS_LINK_KEY_DATA_END 0x02FF
  180. // NV Items Reserved for Master Key Table entries
  181. // 0x0301 - 0x03FF
  182. #define ZCD_NV_MASTER_KEY_DATA_START 0x0301 // Master key data
  183. #define ZCD_NV_MASTER_KEY_DATA_END 0x03FF
  184. // NV Items Reserved for applications (user applications)
  185. // 0x0401 – 0x0FFF
  186. // ZCD_NV_STARTUP_OPTION values
  187. // These are bit weighted - you can OR these together.
  188. // Setting one of these bits will set their associated NV items
  189. // to code initialized values.
  190. #define ZCD_STARTOPT_DEFAULT_CONFIG_STATE 0x01
  191. #define ZCD_STARTOPT_DEFAULT_NETWORK_STATE 0x02
  192. #define ZCD_STARTOPT_AUTO_START 0x04
  193. #define ZCD_STARTOPT_CLEAR_CONFIG ZCD_STARTOPT_DEFAULT_CONFIG_STATE
  194. #define ZCD_STARTOPT_CLEAR_STATE ZCD_STARTOPT_DEFAULT_NETWORK_STATE
  195. #define ZCL_KE_IMPLICIT_CERTIFICATE_LEN 48
  196. #define ZCL_KE_CA_PUBLIC_KEY_LEN 22
  197. #define ZCL_KE_DEVICE_PRIVATE_KEY_LEN 21
  198. /*********************************************************************
  199. * TYPEDEFS
  200. */
  201. /*** Data Types ***/
  202. typedef uint8 byte;
  203. typedef uint16 UINT16;
  204. typedef int16 INT16;
  205. enum
  206. {
  207. AddrNotPresent = 0,
  208. AddrGroup = 1,
  209. Addr16Bit = 2,
  210. Addr64Bit = 3,
  211. AddrBroadcast = 15
  212. };
  213. #define Z_EXTADDR_LEN 8
  214. typedef byte ZLongAddr_t[Z_EXTADDR_LEN];
  215. typedef struct
  216. {
  217. union
  218. {
  219. uint16 shortAddr;
  220. ZLongAddr_t extAddr;
  221. } addr;
  222. byte addrMode;
  223. } zAddrType_t;
  224. // Redefined Generic Status Return Values for code backwards compatibility
  225. #define ZSuccess SUCCESS
  226. #define ZFailure FAILURE
  227. #define ZInvalidParameter INVALIDPARAMETER
  228. // ZStack status values must start at 0x10, after the generic status values (defined in comdef.h)
  229. #define ZMemError 0x10
  230. #define ZBufferFull 0x11
  231. #define ZUnsupportedMode 0x12
  232. #define ZMacMemError 0x13
  233. #define ZSapiInProgress 0x20
  234. #define ZSapiTimeout 0x21
  235. #define ZSapiInit 0x22
  236. #define ZNotAuthorized 0x7E
  237. #define ZMalformedCmd 0x80
  238. #define ZUnsupClusterCmd 0x81
  239. // OTA Status values
  240. #define ZOtaAbort 0x95
  241. #define ZOtaImageInvalid 0x96
  242. #define ZOtaWaitForData 0x97
  243. #define ZOtaNoImageAvailable 0x98
  244. #define ZOtaRequireMoreImage 0x99
  245. // APS status values
  246. #define ZApsFail 0xb1
  247. #define ZApsTableFull 0xb2
  248. #define ZApsIllegalRequest 0xb3
  249. #define ZApsInvalidBinding 0xb4
  250. #define ZApsUnsupportedAttrib 0xb5
  251. #define ZApsNotSupported 0xb6
  252. #define ZApsNoAck 0xb7
  253. #define ZApsDuplicateEntry 0xb8
  254. #define ZApsNoBoundDevice 0xb9
  255. #define ZApsNotAllowed 0xba
  256. #define ZApsNotAuthenticated 0xbb
  257. // Security status values
  258. #define ZSecNoKey 0xa1
  259. #define ZSecOldFrmCount 0xa2
  260. #define ZSecMaxFrmCount 0xa3
  261. #define ZSecCcmFail 0xa4
  262. // NWK status values
  263. #define ZNwkInvalidParam 0xc1
  264. #define ZNwkInvalidRequest 0xc2
  265. #define ZNwkNotPermitted 0xc3
  266. #define ZNwkStartupFailure 0xc4
  267. #define ZNwkAlreadyPresent 0xc5
  268. #define ZNwkSyncFailure 0xc6
  269. #define ZNwkTableFull 0xc7
  270. #define ZNwkUnknownDevice 0xc8
  271. #define ZNwkUnsupportedAttribute 0xc9
  272. #define ZNwkNoNetworks 0xca
  273. #define ZNwkLeaveUnconfirmed 0xcb
  274. #define ZNwkNoAck 0xcc // not in spec
  275. #define ZNwkNoRoute 0xcd
  276. // MAC status values
  277. #define ZMacSuccess 0x00
  278. #define ZMacBeaconLoss 0xe0
  279. #define ZMacChannelAccessFailure 0xe1
  280. #define ZMacDenied 0xe2
  281. #define ZMacDisableTrxFailure 0xe3
  282. #define ZMacFailedSecurityCheck 0xe4
  283. #define ZMacFrameTooLong 0xe5
  284. #define ZMacInvalidGTS 0xe6
  285. #define ZMacInvalidHandle 0xe7
  286. #define ZMacInvalidParameter 0xe8
  287. #define ZMacNoACK 0xe9
  288. #define ZMacNoBeacon 0xea
  289. #define ZMacNoData 0xeb
  290. #define ZMacNoShortAddr 0xec
  291. #define ZMacOutOfCap 0xed
  292. #define ZMacPANIDConflict 0xee
  293. #define ZMacRealignment 0xef
  294. #define ZMacTransactionExpired 0xf0
  295. #define ZMacTransactionOverFlow 0xf1
  296. #define ZMacTxActive 0xf2
  297. #define ZMacUnAvailableKey 0xf3
  298. #define ZMacUnsupportedAttribute 0xf4
  299. #define ZMacUnsupported 0xf5
  300. #define ZMacSrcMatchInvalidIndex 0xff
  301. typedef Status_t ZStatus_t;
  302. typedef struct
  303. {
  304. uint8 txCounter; // Counter of transmission success/failures
  305. uint8 txCost; // Average of sending rssi values if link staus is enabled
  306. // i.e. NWK_LINK_STATUS_PERIOD is defined as non zero
  307. uint8 rxLqi; // average of received rssi values
  308. // needs to be converted to link cost (1-7) before used
  309. uint8 inKeySeqNum; // security key sequence number
  310. uint32 inFrmCntr; // security frame counter..
  311. uint16 txFailure; // higher values indicate more failures
  312. } linkInfo_t;
  313. /*********************************************************************
  314. * Global System Messages
  315. */
  316. #define SPI_INCOMING_ZTOOL_PORT 0x21 // Raw data from ZTool Port (not implemented)
  317. #define SPI_INCOMING_ZAPP_DATA 0x22 // Raw data from the ZAPP port (see serialApp.c)
  318. #define MT_SYS_APP_MSG 0x23 // Raw data from an MT Sys message
  319. #define MT_SYS_APP_RSP_MSG 0x24 // Raw data output for an MT Sys message
  320. #define MT_SYS_OTA_MSG 0x25 // Raw data output for an MT OTA Rsp
  321. #define AF_DATA_CONFIRM_CMD 0xFD // Data confirmation
  322. #define AF_INCOMING_MSG_CMD 0x1A // Incoming MSG type message
  323. #define AF_INCOMING_KVP_CMD 0x1B // Incoming KVP type message
  324. #define AF_INCOMING_GRP_KVP_CMD 0x1C // Incoming Group KVP type message
  325. //#define KEY_CHANGE 0xC0 // Key Events
  326. #define ZDO_NEW_DSTADDR 0xD0 // ZDO has received a new DstAddr for this app
  327. #define ZDO_STATE_CHANGE 0xD1 // ZDO has changed the device's network state
  328. #define ZDO_MATCH_DESC_RSP_SENT 0xD2 // ZDO match descriptor response was sent
  329. #define ZDO_CB_MSG 0xD3 // ZDO incoming message callback
  330. #define ZDO_NETWORK_REPORT 0xD4 // ZDO received a Network Report message
  331. #define ZDO_NETWORK_UPDATE 0xD5 // ZDO received a Network Update message
  332. #define ZDO_ADDR_CHANGE_IND 0xD6 // ZDO was informed of device address change
  333. #define NM_CHANNEL_INTERFERE 0x31 // NwkMgr received a Channel Interference message
  334. #define NM_ED_SCAN_CONFIRM 0x32 // NwkMgr received an ED Scan Confirm message
  335. #define SAPS_CHANNEL_CHANGE 0x33 // Stub APS has changed the device's channel
  336. #define ZCL_INCOMING_MSG 0x34 // Incoming ZCL foundation message
  337. #define ZCL_KEY_ESTABLISH_IND 0x35 // ZCL Key Establishment Completion Indication
  338. #define ZCL_OTA_CALLBACK_IND 0x36 // ZCL OTA Completion Indication
  339. // OSAL System Message IDs/Events Reserved for applications (user applications)
  340. // 0xE0 – 0xFC
  341. /*********************************************************************
  342. * GLOBAL VARIABLES
  343. */
  344. /*********************************************************************
  345. * FUNCTIONS
  346. */
  347. /*********************************************************************
  348. *********************************************************************/
  349. #ifdef __cplusplus
  350. }
  351. #endif
  352. #endif /* ZCOMDEF_H */