AF.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. /**************************************************************************************************
  2. Filename: AF.h
  3. Revised: $Date: 2009-03-19 13:45:23 -0700 (Thu, 19 Mar 2009) $
  4. Revision: $Revision: 19471 $
  5. Description: This file contains the Application Framework definitions.
  6. Copyright 2004-2009 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 AF_H
  34. #define AF_H
  35. #ifdef __cplusplus
  36. extern "C"
  37. {
  38. #endif
  39. /*********************************************************************
  40. * INCLUDES
  41. */
  42. #include "ZComDef.h"
  43. #include "nwk.h"
  44. #include "APSMEDE.h"
  45. /*********************************************************************
  46. * CONSTANTS
  47. */
  48. #define AF_BROADCAST_ENDPOINT 0xFF
  49. #define AF_ACK_REQUEST 0x10
  50. #define AF_DISCV_ROUTE 0x20
  51. #define AF_EN_SECURITY 0x40
  52. #define AF_SKIP_ROUTING 0x80
  53. // Backwards support for afAddOrSendMessage / afFillAndSendMessage.
  54. #define AF_TX_OPTIONS_NONE 0
  55. #define AF_MSG_ACK_REQUEST AF_ACK_REQUEST
  56. // Default Radius Count value
  57. #define AF_DEFAULT_RADIUS DEF_NWK_RADIUS
  58. /*********************************************************************
  59. * Node Descriptor
  60. */
  61. #define AF_MAX_USER_DESCRIPTOR_LEN 16
  62. #define AF_USER_DESCRIPTOR_FILL 0x20
  63. typedef struct
  64. {
  65. byte len; // Length of string descriptor
  66. byte desc[AF_MAX_USER_DESCRIPTOR_LEN];
  67. } UserDescriptorFormat_t;
  68. // Node Logical Types
  69. #define NODETYPE_COORDINATOR 0x00
  70. #define NODETYPE_ROUTER 0x01
  71. #define NODETYPE_DEVICE 0x02
  72. // Node Frequency Band - bit map
  73. #define NODEFREQ_800 0x01 // 868 - 868.6 MHz
  74. #define NODEFREQ_900 0x04 // 902 - 928 MHz
  75. #define NODEFREQ_2400 0x08 // 2400 - 2483.5 MHz
  76. // Node MAC Capabilities - bit map
  77. // Use CAPINFO_ALTPANCOORD, CAPINFO_DEVICETYPE_FFD,
  78. // CAPINFO_DEVICETYPE_RFD, CAPINFO_POWER_AC,
  79. // and CAPINFO_RCVR_ON_IDLE from NLMEDE.h
  80. // Node Descriptor format structure
  81. typedef struct
  82. {
  83. uint8 LogicalType:3;
  84. uint8 ComplexDescAvail:1; /* AF_V1_SUPPORT - reserved bit. */
  85. uint8 UserDescAvail:1; /* AF_V1_SUPPORT - reserved bit. */
  86. uint8 Reserved:3;
  87. uint8 APSFlags:3;
  88. uint8 FrequencyBand:5;
  89. uint8 CapabilityFlags;
  90. uint8 ManufacturerCode[2];
  91. uint8 MaxBufferSize;
  92. uint8 MaxInTransferSize[2];
  93. uint16 ServerMask;
  94. uint8 MaxOutTransferSize[2];
  95. uint8 DescriptorCapability;
  96. } NodeDescriptorFormat_t;
  97. // Bit masks for the ServerMask.
  98. #define PRIM_TRUST_CENTER 0x01
  99. #define BKUP_TRUST_CENTER 0x02
  100. #define PRIM_BIND_TABLE 0x04
  101. #define BKUP_BIND_TABLE 0x08
  102. #define PRIM_DISC_TABLE 0x10
  103. #define BKUP_DISC_TABLE 0x20
  104. #define NETWORK_MANAGER 0x40
  105. /*********************************************************************
  106. * Node Power Descriptor
  107. */
  108. // Node Current Power Modes (CURPWR)
  109. // Receiver permanently on or sync with coordinator beacon.
  110. #define NODECURPWR_RCVR_ALWAYS_ON 0x00
  111. // Receiver automatically comes on periodically as defined by the
  112. // Node Power Descriptor.
  113. #define NODECURPWR_RCVR_AUTO 0x01
  114. // Receiver comes on when simulated, eg by a user pressing a button.
  115. #define NODECURPWR_RCVR_STIM 0x02
  116. // Node Available Power Sources (AVAILPWR) - bit map
  117. // Can be used for AvailablePowerSources or CurrentPowerSource
  118. #define NODEAVAILPWR_MAINS 0x01 // Constant (Mains) power
  119. #define NODEAVAILPWR_RECHARGE 0x02 // Rechargeable Battery
  120. #define NODEAVAILPWR_DISPOSE 0x04 // Disposable Battery
  121. // Power Level
  122. #define NODEPOWER_LEVEL_CRITICAL 0x00 // Critical
  123. #define NODEPOWER_LEVEL_33 0x04 // 33%
  124. #define NODEPOWER_LEVEL_66 0x08 // 66%
  125. #define NODEPOWER_LEVEL_100 0x0C // 100%
  126. // Node Power Descriptor format structure
  127. typedef struct
  128. {
  129. unsigned int PowerMode:4;
  130. unsigned int AvailablePowerSources:4;
  131. unsigned int CurrentPowerSource:4;
  132. unsigned int CurrentPowerSourceLevel:4;
  133. } NodePowerDescriptorFormat_t;
  134. /*********************************************************************
  135. * Simple Descriptor
  136. */
  137. // AppDevVer values
  138. #define APPDEVVER_1 0x01
  139. // AF_V1_SUPPORT AppFlags - bit map
  140. #define APPFLAG_NONE 0x00 // Backwards compatibility to AF_V1.
  141. // AF-AppFlags - bit map
  142. #define AF_APPFLAG_NONE 0x00
  143. #define AF_APPFLAG_COMPLEXDESC 0x01 // Complex Descriptor Available
  144. #define AF_APPFLAG_USERDESC 0x02 // User Descriptor Available
  145. typedef uint16 cId_t;
  146. // Simple Description Format Structure
  147. typedef struct
  148. {
  149. byte EndPoint;
  150. uint16 AppProfId;
  151. uint16 AppDeviceId;
  152. byte AppDevVer:4;
  153. byte Reserved:4; // AF_V1_SUPPORT uses for AppFlags:4.
  154. byte AppNumInClusters;
  155. cId_t *pAppInClusterList;
  156. byte AppNumOutClusters;
  157. cId_t *pAppOutClusterList;
  158. } SimpleDescriptionFormat_t;
  159. /*********************************************************************
  160. * AF Message Format
  161. */
  162. // Frame Types
  163. #define FRAMETYPE_KVP 0x01 // 0001
  164. #define FRAMETYPE_MSG 0x02 // 0010
  165. #define ERRORCODE_SUCCESS 0x00
  166. #define AF_HDR_KVP_MAX_LEN 0x08 // Max possible AF KVP header.
  167. #define AF_HDR_V1_0_MAX_LEN 0x03 // Max possible AF Ver 1.0 header.
  168. #define AF_HDR_V1_1_MAX_LEN 0x00 // Max possible AF Ver 1.1 header.
  169. // Generalized MSG Command Format
  170. typedef struct
  171. {
  172. byte TransSeqNumber;
  173. uint16 DataLength; // Number of bytes in TransData
  174. byte *Data;
  175. } afMSGCommandFormat_t;
  176. typedef enum
  177. {
  178. noLatencyReqs,
  179. fastBeacons,
  180. slowBeacons
  181. } afNetworkLatencyReq_t;
  182. /*********************************************************************
  183. * Endpoint Descriptions
  184. */
  185. typedef enum
  186. {
  187. afAddrNotPresent = AddrNotPresent,
  188. afAddr16Bit = Addr16Bit,
  189. afAddr64Bit = Addr64Bit,
  190. afAddrGroup = AddrGroup,
  191. afAddrBroadcast = AddrBroadcast
  192. } afAddrMode_t;
  193. typedef struct
  194. {
  195. union
  196. {
  197. uint16 shortAddr;
  198. ZLongAddr_t extAddr;
  199. } addr;
  200. afAddrMode_t addrMode;
  201. byte endPoint;
  202. uint16 panId; // used for the INTER_PAN feature
  203. } afAddrType_t;
  204. typedef struct
  205. {
  206. osal_event_hdr_t hdr; /* OSAL Message header */
  207. uint16 groupId; /* Message's group ID - 0 if not set */
  208. uint16 clusterId; /* Message's cluster ID */
  209. afAddrType_t srcAddr; /* Source Address, if endpoint is STUBAPS_INTER_PAN_EP,
  210. it's an InterPAN message */
  211. uint16 macDestAddr; /* MAC header destination short address */
  212. uint8 endPoint; /* destination endpoint */
  213. uint8 wasBroadcast; /* TRUE if network destination was a broadcast address */
  214. uint8 LinkQuality; /* The link quality of the received data frame */
  215. uint8 correlation; /* The raw correlation value of the received data frame */
  216. int8 rssi; /* The received RF power in units dBm */
  217. uint8 SecurityUse; /* deprecated */
  218. uint32 timestamp; /* receipt timestamp from MAC */
  219. afMSGCommandFormat_t cmd; /* Application Data */
  220. } afIncomingMSGPacket_t;
  221. typedef struct
  222. {
  223. osal_event_hdr_t hdr;
  224. byte endpoint;
  225. byte transID;
  226. } afDataConfirm_t;
  227. // Endpoint Table - this table is the device description
  228. // or application registration.
  229. // There will be one entry in this table for every
  230. // endpoint defined.
  231. typedef struct
  232. {
  233. byte endPoint;
  234. byte *task_id; // Pointer to location of the Application task ID.
  235. SimpleDescriptionFormat_t *simpleDesc;
  236. afNetworkLatencyReq_t latencyReq;
  237. } endPointDesc_t;
  238. // Typedef for callback function to retrieve an endpoints
  239. // descriptors, contained in the endpoint descriptor.
  240. // This will allow an application to dynamically change
  241. // the descriptor and not use the RAM/ROM.
  242. typedef void *(*pDescCB)( uint8 type, uint8 endpoint );
  243. // Descriptor types used in the above callback
  244. #define AF_DESCRIPTOR_SIMPLE 1
  245. #define AF_DESCRIPTOR_PROFILE_ID 2
  246. // Bit definitions for epList_t flags.
  247. typedef enum
  248. {
  249. eEP_AllowMatch = 1,
  250. eEP_NotUsed
  251. } eEP_Flags;
  252. typedef struct
  253. {
  254. endPointDesc_t *epDesc;
  255. eEP_Flags flags;
  256. pDescCB pfnDescCB; // Don't use if this function pointer is NULL.
  257. void *nextDesc;
  258. } epList_t;
  259. /*********************************************************************
  260. * MACROS
  261. */
  262. /*********************************************************************
  263. * TYPEDEFS
  264. */
  265. #define afStatus_SUCCESS ZSuccess
  266. #define afStatus_FAILED ZFailure
  267. #define afStatus_MEM_FAIL ZMemError
  268. #define afStatus_INVALID_PARAMETER ZInvalidParameter
  269. typedef ZStatus_t afStatus_t;
  270. typedef struct
  271. {
  272. uint8 kvp;
  273. APSDE_DataReqMTU_t aps;
  274. } afDataReqMTU_t;
  275. /*********************************************************************
  276. * Globals
  277. */
  278. extern epList_t *epList;
  279. /*********************************************************************
  280. * FUNCTIONS
  281. */
  282. /*
  283. * afInit - Initialize the AF.
  284. */
  285. extern void afInit( void );
  286. /*
  287. * afRegisterExtended - Register an Application's EndPoint description
  288. * with a callback function for descriptors.
  289. *
  290. */
  291. extern epList_t *afRegisterExtended( endPointDesc_t *epDesc, pDescCB descFn );
  292. /*
  293. * afRegister - Register an Application's EndPoint description.
  294. *
  295. */
  296. extern afStatus_t afRegister( endPointDesc_t *epDesc );
  297. /*
  298. * afDataConfirm - APS will call this function after a data message
  299. * has been sent.
  300. */
  301. extern void afDataConfirm( uint8 endPoint, uint8 transID, ZStatus_t status );
  302. /*
  303. * afIncomingData - APS will call this function when an incoming
  304. * message is received.
  305. */
  306. extern void afIncomingData( aps_FrameFormat_t *aff, zAddrType_t *SrcAddress, uint16 SrcPanId,
  307. NLDE_Signal_t *sig, byte SecurityUse, uint32 timestamp );
  308. afStatus_t AF_DataRequest( afAddrType_t *dstAddr, endPointDesc_t *srcEP,
  309. uint16 cID, uint16 len, uint8 *buf, uint8 *transID,
  310. uint8 options, uint8 radius );
  311. /*********************************************************************
  312. * Direct Access Functions - ZigBee Device Object
  313. */
  314. /*
  315. * afFindEndPointDesc - Find the endpoint description entry from the
  316. * endpoint number.
  317. */
  318. extern endPointDesc_t *afFindEndPointDesc( byte endPoint );
  319. /*
  320. * afFindSimpleDesc - Find the Simple Descriptor from the endpoint number.
  321. * If return value is not zero, the descriptor memory must be freed.
  322. */
  323. extern byte afFindSimpleDesc( SimpleDescriptionFormat_t **ppDesc, byte EP );
  324. /*
  325. * afDataReqMTU - Get the Data Request MTU(Max Transport Unit)
  326. */
  327. extern uint8 afDataReqMTU( afDataReqMTU_t* fields );
  328. /*
  329. * afGetMatch - Get the action for the Match Descriptor Response
  330. * TRUE allow match descriptor response
  331. */
  332. extern uint8 afGetMatch( uint8 ep );
  333. /*
  334. * afSetMatch - Set the action for the Match Descriptor Response
  335. * TRUE allow match descriptor response
  336. */
  337. extern uint8 afSetMatch( uint8 ep, uint8 action );
  338. /*
  339. * afNumEndPoints - returns the number of endpoints defined.
  340. */
  341. extern byte afNumEndPoints( void );
  342. /*
  343. * afEndPoints - builds an array of endpoints.
  344. */
  345. extern void afEndPoints( byte *epBuf, byte skipZDO );
  346. /*
  347. * afCopyAddress
  348. *
  349. */
  350. extern void afCopyAddress (afAddrType_t *afAddr, zAddrType_t *zAddr);
  351. /*********************************************************************
  352. *********************************************************************/
  353. #ifdef __cplusplus
  354. }
  355. #endif
  356. #endif