sapi.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. /**************************************************************************************************
  2. Filename: sapi.h
  3. Revised: $Date: 2008-03-14 11:20:21 -0700 (Fri, 14 Mar 2008) $
  4. Revision: $Revision: 16590 $
  5. Description: Z-Stack Simple Application Interface.
  6. Copyright 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 SAPI_H
  34. #define SAPI_H
  35. /******************************************************************************
  36. * INCLUDES
  37. */
  38. #include "ZComDef.h"
  39. #include "af.h"
  40. /******************************************************************************
  41. * CONSTANTS
  42. */
  43. // Simple Task Events
  44. #define ZB_ALLOW_BIND_TIMER 0x4000 //0x0001
  45. #define ZB_BIND_TIMER 0x2000 //0x0002
  46. #define ZB_ENTRY_EVENT 0x1000 //0x0004
  47. #define ZB_USER_EVENTS 0x00FF
  48. // Find Device Search Types
  49. #define ZB_IEEE_SEARCH 1
  50. // Device Info Constants
  51. #define ZB_INFO_DEV_STATE 0
  52. #define ZB_INFO_IEEE_ADDR 1
  53. #define ZB_INFO_SHORT_ADDR 2
  54. #define ZB_INFO_PARENT_SHORT_ADDR 3
  55. #define ZB_INFO_PARENT_IEEE_ADDR 4
  56. #define ZB_INFO_CHANNEL 5
  57. #define ZB_INFO_PAN_ID 6
  58. #define ZB_INFO_EXT_PAN_ID 7
  59. // SAPI SendDataRequest destinations
  60. #define ZB_BINDING_ADDR INVALID_NODE_ADDR
  61. #define ZB_BROADCAST_ADDR 0xffff
  62. // SAPI Status Codes
  63. #define ZB_SUCCESS ZSuccess
  64. #define ZB_FAILURE ZFailure
  65. #define ZB_INVALID_PARAMETER ZInvalidParameter
  66. #define ZB_ALREADY_IN_PROGRESS ZSapiInProgress
  67. #define ZB_TIMEOUT ZSapiTimeout
  68. #define ZB_INIT ZSapiInit
  69. #define ZB_AF_FAILURE afStatus_FAILED
  70. #define ZB_AF_MEM_FAIL afStatus_MEM_FAIL
  71. #define ZB_AF_INVALID_PARAMETER afStatus_INVALID_PARAMETER
  72. // SAPI Scan Duration Values
  73. #define ZB_SCAN_DURATION_0 0 // 19.2 ms
  74. #define ZB_SCAN_DURATION_1 1 // 38.4 ms
  75. #define ZB_SCAN_DURATION_2 2 // 76.8 ms
  76. #define ZB_SCAN_DURATION_3 3 // 153.6 ms
  77. #define ZB_SCAN_DURATION_4 4 // 307.2 ms
  78. #define ZB_SCAN_DURATION_5 5 // 614.4 ms
  79. #define ZB_SCAN_DURATION_6 6 // 1.23 sec
  80. #define ZB_SCAN_DURATION_7 7 // 2.46 sec
  81. #define ZB_SCAN_DURATION_8 8 // 4.92 sec
  82. #define ZB_SCAN_DURATION_9 9 // 9.83 sec
  83. #define ZB_SCAN_DURATION_10 10 // 19.66 sec
  84. #define ZB_SCAN_DURATION_11 11 // 39.32 sec
  85. #define ZB_SCAN_DURATION_12 12 // 78.64 sec
  86. #define ZB_SCAN_DURATION_13 13 // 157.28 sec
  87. #define ZB_SCAN_DURATION_14 14 // 314.57 sec
  88. // Device types definitions ( from ZGlobals.h file )
  89. #define ZG_DEVICETYPE_COORDINATOR 0x00
  90. #define ZG_DEVICETYPE_ROUTER 0x01
  91. #define ZG_DEVICETYPE_ENDDEVICE 0x02
  92. /******************************************************************************
  93. * TYPEDEFS
  94. */
  95. typedef struct
  96. {
  97. uint16 panID;
  98. uint8 channel;
  99. } zb_NetworkList_t;
  100. typedef struct
  101. {
  102. osal_event_hdr_t hdr;
  103. uint16 data;
  104. } sapi_CbackEvent_t;
  105. /******************************************************************************
  106. * PUBLIC VARIABLES
  107. */
  108. extern uint8 sapi_TaskID;
  109. extern endPointDesc_t sapi_epDesc;
  110. /******************************************************************************
  111. * PUBLIC FUNCTIONS
  112. */
  113. #ifdef __cplusplus
  114. extern "C"
  115. {
  116. #endif
  117. extern const SimpleDescriptionFormat_t zb_SimpleDesc;
  118. /******************************************************************************
  119. * @fn zb_SystemReset
  120. *
  121. * @brief The zb_SystemReset function reboots the ZigBee Stack. The
  122. * zb_SystemReset function can be called after a call to
  123. * zb_WriteConfiguration to restart Z-Stack with the updated
  124. * configuration.
  125. *
  126. * @param none
  127. *
  128. * @return none
  129. */
  130. extern void zb_SystemReset ( void );
  131. /******************************************************************************
  132. * @fn zb_StartRequest
  133. *
  134. * @brief The zb_StartRequest function starts the ZigBee stack. When the
  135. * ZigBee stack starts, the device reads configuration parameters
  136. * from Nonvolatile memory and the device joins its network. The
  137. * ZigBee stack calls the zb_StartConrifm callback function when
  138. * the startup process completes.
  139. *
  140. * @param none
  141. *
  142. * @return none
  143. */
  144. extern void zb_StartRequest ( void );
  145. /******************************************************************************
  146. * @fn zb_PermitJoiningRequest
  147. *
  148. * @brief The zb_PermitJoiningRequest function is used to control the
  149. * joining permissions and thus allow or disallow new devices from
  150. * joining the network.
  151. *
  152. * @param destination - The destination parameter indicates the address
  153. * of the device for which the joining permissions
  154. * should be set. This is usually the local device
  155. * address or the special broadcast address that denotes
  156. * all routers and coordinator ( 0xFFFC ). This way
  157. * the joining permissions of a single device or the
  158. * whole network can be controlled.
  159. * timeout - Indicates the amount of time in seconds for which
  160. * the joining permissions should be turned on.
  161. * If timeout is set to 0x00, the device will turn off the
  162. * joining permissions indefinitely. If it is set to 0xFF,
  163. * the joining permissions will be turned on indefinitely.
  164. *
  165. *
  166. * @return ZB_SUCCESS or a failure code
  167. *
  168. */
  169. extern uint8 zb_PermitJoiningRequest ( uint16 destination, uint8 timeout );
  170. /******************************************************************************
  171. * @fn zb_BindDevice
  172. *
  173. * @brief The zb_BindDevice function establishes or removes a ‘binding’
  174. * between two devices. Once bound, an application can send
  175. * messages to a device by referencing the commandId for the
  176. * binding.
  177. *
  178. * @param create - TRUE to create a binding, FALSE to remove a binding
  179. * commandId - The identifier of the binding
  180. * pDestination - The 64-bit IEEE address of the device to bind to
  181. *
  182. * @return ZB_SUCCESS if the bind process started sucessfully, else
  183. * en error code is returned. If the return value is ZB_SUCCESS
  184. * then the status of the bind operation is returned in the
  185. * zb_BindConfirm callback.
  186. */
  187. extern void zb_BindDevice ( uint8 create, uint16 commandId, uint8 *pDestination );
  188. /******************************************************************************
  189. * @fn zb_AllowBind
  190. *
  191. * @brief The zb_AllowBind function puts the device into the
  192. * Allow Binding Mode for a given period of time. A peer device
  193. * can establish a binding to a device in the Allow Binding Mode
  194. * by calling zb_BindDevice with a destination address of NULL
  195. *
  196. * @param timeout - The number of seconds to remain in the allow binding
  197. * mode. Valid values range from 1 through 65.
  198. *
  199. * @return ZB_SUCCESS if the device entered the allow bind mode, else
  200. * an error code.
  201. */
  202. extern void zb_AllowBind ( uint8 timeout );
  203. /******************************************************************************
  204. * @fn zb_SendDataRequest
  205. *
  206. * @brief The zb_SendDataRequest function initiates transmission of data
  207. * to a peer device
  208. *
  209. * @param destination - The destination of the data. The destination can
  210. * be one of the following:
  211. * - 16-Bit short address of device [0-0xfffD]
  212. * - ZB_BROADCAST_ADDR sends the data to all devices
  213. * in the network.
  214. * - ZB_BINDING_ADDR sends the data to a previously
  215. * bound device.
  216. *
  217. * commandId - The command ID to send with the message. If the
  218. * ZB_BINDING_ADDR destination is used, this parameter
  219. * also indicates the binding to use.
  220. *
  221. * len - The size of the pData buffer in bytes
  222. * handle - A handle used to identify the send data request.
  223. * ack - TRUE if requesting acknowledgement from the destination.
  224. * radius - The max number of routers the data can travel through
  225. * before the data is dropped.
  226. *
  227. * @return none
  228. */
  229. extern void zb_SendDataRequest ( uint16 destination, uint16 commandId, uint8 len,
  230. uint8 *pData, uint8 handle, uint8 ack, uint8 radius );
  231. /******************************************************************************
  232. * @fn zb_ReadConfiguration
  233. *
  234. * @brief The zb_ReadConfiguration function is used to get a
  235. * Configuration Protperty from Nonvolatile memory.
  236. *
  237. * @param configId - The identifier for the configuration property
  238. * len - The size of the pValue buffer in bytes
  239. * pValue - A buffer to hold the configuration property
  240. *
  241. * @return none
  242. */
  243. extern uint8 zb_ReadConfiguration( uint8 configId, uint8 len, void *pValue );
  244. /******************************************************************************
  245. * @fn zb_WriteConfiguration
  246. *
  247. * @brief The zb_WriteConfiguration function is used to write a
  248. * Configuration Property to nonvolatile memory.
  249. *
  250. * @param configId - The identifier for the configuration property
  251. * len - The size of the pValue buffer in bytes
  252. * pValue - A buffer containing the new value of the
  253. * configuration property
  254. *
  255. * @return none
  256. */
  257. extern uint8 zb_WriteConfiguration( uint8 configId, uint8 len, void *pValue );
  258. /******************************************************************************
  259. * @fn zb_GetDeviceInfo
  260. *
  261. * @brief The zb_GetDeviceInfo function retrieves a Device Information
  262. * Property.
  263. *
  264. * @param param - The identifier for the device information
  265. * pValue - A buffer to hold the device information
  266. *
  267. * @return none
  268. */
  269. extern void zb_GetDeviceInfo ( uint8 param, void *pValue );
  270. /******************************************************************************
  271. * @fn zb_FindDeviceRequest
  272. *
  273. * @brief The zb_FindDeviceRequest function is used to determine the
  274. * short address for a device in the network. The device initiating
  275. * a call to zb_FindDeviceRequest and the device being discovered
  276. * must both be a member of the same network. When the search is
  277. * complete, the zv_FindDeviceConfirm callback function is called.
  278. *
  279. * @param searchType - The type of search to perform. Can be one of following:
  280. * ZB_IEEE_SEARCH - Search for 16-bit addr given IEEE addr.
  281. * searchKey - Value to search on.
  282. *
  283. * @return none
  284. */
  285. extern void zb_FindDeviceRequest( uint8 searchType, void *searchKey );
  286. /******************************************************************************
  287. * @fn zb_HandleOsalEvent
  288. *
  289. * @brief The zb_HandleOsalEvent function is called by the operating
  290. * system when a task event is set
  291. *
  292. * @param event - Bitmask containing the events that have been set
  293. *
  294. * @return none
  295. */
  296. extern void zb_HandleOsalEvent( uint16 event );
  297. /******************************************************************************
  298. * @fn zb_StartConfirm
  299. *
  300. * @brief The zb_StartConfirm callback is called by the ZigBee stack
  301. * after a start request operation completes
  302. *
  303. * @param status - The status of the start operation. Status of
  304. * ZB_SUCCESS indicates the start operation completed
  305. * successfully. Else the status is an error code.
  306. *
  307. * @return none
  308. */
  309. extern void zb_StartConfirm( uint8 status );
  310. /******************************************************************************
  311. * @fn zb_SendDataConfirm
  312. *
  313. * @brief The zb_SendDataConfirm callback function is called by the
  314. * ZigBee after a send data operation completes
  315. *
  316. * @param handle - The handle identifying the data transmission.
  317. * status - The status of the operation.
  318. *
  319. * @return none
  320. */
  321. extern void zb_SendDataConfirm( uint8 handle, uint8 status );
  322. /******************************************************************************
  323. * @fn zb_BindConfirm
  324. *
  325. * @brief The zb_BindConfirm callback is called by the ZigBee stack
  326. * after a bind operation completes.
  327. *
  328. * @param commandId - The command ID of the binding being confirmed.
  329. * status - The status of the bind operation.
  330. * allowBind - TRUE if the bind operation was initiated by a call
  331. * to zb_AllowBindRespones. FALSE if the operation
  332. * was initiated by a call to ZB_BindDevice
  333. *
  334. * @return none
  335. */
  336. extern void zb_BindConfirm( uint16 commandId, uint8 status );
  337. /******************************************************************************
  338. * @fn zb_FindDeviceConfirm
  339. *
  340. * @brief The zb_FindDeviceConfirm callback function is called by the
  341. * ZigBee stack when a find device operation completes.
  342. *
  343. * @param searchType - The type of search that was performed.
  344. * searchKey - Value that the search was executed on.
  345. * result - The result of the search.
  346. *
  347. * @return none
  348. */
  349. extern void zb_FindDeviceConfirm( uint8 searchType, uint8 *searchKey, uint8 *result );
  350. /******************************************************************************
  351. * @fn zb_ReceiveDataIndication
  352. *
  353. * @brief The zb_ReceiveDataIndication callback function is called
  354. * asynchronously by the ZigBee stack to notify the application
  355. * when data is received from a peer device.
  356. *
  357. * @param source - The short address of the peer device that sent the data
  358. * command - The commandId associated with the data
  359. * len - The number of bytes in the pData parameter
  360. * pData - The data sent by the peer device
  361. *
  362. * @return none
  363. */
  364. extern void zb_ReceiveDataIndication( uint16 source, uint16 command, uint16 len, uint8 *pData );
  365. extern void zb_AllowBindConfirm( uint16 source );
  366. extern void zb_HandleKeys( uint8 shift, uint8 keys );
  367. /* External declarations required by SAPI */
  368. extern UINT16 SAPI_ProcessEvent( byte task_id, UINT16 events );
  369. extern void SAPI_Init( byte task_id );
  370. extern void osalAddTasks( void );
  371. #ifdef __cplusplus
  372. }
  373. #endif
  374. #endif // SAPI_H