antfs_client_interface.hpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. /*
  2. This software is subject to the license described in the License.txt file
  3. included with this software distribution. You may not use this file except in compliance
  4. with this license.
  5. Copyright (c) Dynastream Innovations Inc. 2013
  6. All rights reserved.
  7. */
  8. #if !defined(ANTFS_CLIENT_INTERFACE_H)
  9. #define ANTFS_CLIENT_INTERFACE_H
  10. #include "types.h"
  11. #include "antfs_interface.h"
  12. //////////////////////////////////////////////////////////////////////////////////
  13. // Public Definitions
  14. //////////////////////////////////////////////////////////////////////////////////
  15. // ANT-FS Client Responses
  16. typedef enum
  17. {
  18. ANTFS_CLIENT_RESPONSE_NONE = 0,
  19. ANTFS_CLIENT_RESPONSE_INIT_PASS,
  20. ANTFS_CLIENT_RESPONSE_SERIAL_FAIL,
  21. ANTFS_CLIENT_RESPONSE_BEACON_OPEN,
  22. ANTFS_CLIENT_RESPONSE_BEACON_CLOSED,
  23. ANTFS_CLIENT_RESPONSE_CONNECT_PASS,
  24. ANTFS_CLIENT_RESPONSE_DISCONNECT_PASS,
  25. ANTFS_CLIENT_RESPONSE_CONNECTION_LOST,
  26. ANTFS_CLIENT_RESPONSE_AUTHENTICATE_NA,
  27. ANTFS_CLIENT_RESPONSE_AUTHENTICATE_PASS,
  28. ANTFS_CLIENT_RESPONSE_AUTHENTICATE_REJECT,
  29. ANTFS_CLIENT_RESPONSE_PAIRING_REQUEST,
  30. ANTFS_CLIENT_RESPONSE_PAIRING_TIMEOUT,
  31. ANTFS_CLIENT_RESPONSE_DOWNLOAD_REQUEST,
  32. ANTFS_CLIENT_RESPONSE_DOWNLOAD_PASS,
  33. ANTFS_CLIENT_RESPONSE_DOWNLOAD_REJECT,
  34. ANTFS_CLIENT_RESPONSE_DOWNLOAD_INVALID_INDEX,
  35. ANTFS_CLIENT_RESPONSE_DOWNLOAD_FILE_NOT_READABLE,
  36. ANTFS_CLIENT_RESPONSE_DOWNLOAD_NOT_READY,
  37. ANTFS_CLIENT_RESPONSE_DOWNLOAD_FAIL,
  38. ANTFS_CLIENT_RESPONSE_UPLOAD_REQUEST,
  39. ANTFS_CLIENT_RESPONSE_UPLOAD_PASS,
  40. ANTFS_CLIENT_RESPONSE_UPLOAD_REJECT,
  41. ANTFS_CLIENT_RESPONSE_UPLOAD_INVALID_INDEX,
  42. ANTFS_CLIENT_RESPONSE_UPLOAD_FILE_NOT_WRITEABLE,
  43. ANTFS_CLIENT_RESPONSE_UPLOAD_INSUFFICIENT_SPACE,
  44. ANTFS_CLIENT_RESPONSE_UPLOAD_FAIL,
  45. ANTFS_CLIENT_RESPONSE_ERASE_REQUEST,
  46. ANTFS_CLIENT_RESPONSE_ERASE_PASS,
  47. ANTFS_CLIENT_RESPONSE_ERASE_REJECT,
  48. ANTFS_CLIENT_RESPONSE_ERASE_FAIL,
  49. ANTFS_CLIENT_RESPONSE_CANCEL_DONE
  50. } ANTFS_CLIENT_RESPONSE;
  51. // ANT-FS Client States
  52. typedef enum
  53. {
  54. ANTFS_CLIENT_STATE_OFF = 0, // Object created, but not initialized (e.g. no threads running)
  55. ANTFS_CLIENT_STATE_IDLE, // Object initialized (e.g. threads running), but not processing messages
  56. ANTFS_CLIENT_STATE_OPENING,
  57. ANTFS_CLIENT_STATE_DISCONNECTING,
  58. ANTFS_CLIENT_STATE_BEACONING, // LINK
  59. ANTFS_CLIENT_STATE_CONNECTED, // AUTH
  60. ANTFS_CLIENT_STATE_AUTHENTICATING,
  61. ANTFS_CLIENT_STATE_PAIRING_WAIT_FOR_RESPONSE,
  62. ANTFS_CLIENT_STATE_TRANSPORT,
  63. ANTFS_CLIENT_STATE_DOWNLOADING,
  64. ANTFS_CLIENT_STATE_DOWNLOADING_WAIT_FOR_DATA,
  65. ANTFS_CLIENT_STATE_UPLOADING,
  66. ANTFS_CLIENT_STATE_UPLOADING_WAIT_FOR_RESPONSE,
  67. ANTFS_CLIENT_STATE_ERASING,
  68. } ANTFS_CLIENT_STATE;
  69. // ANT-FS Client Parameters
  70. typedef struct
  71. {
  72. ULONG ulSerialNumber; // Client serial number. Set to zero to use the serial number of the USB device.
  73. USHORT usBeaconDeviceType; // Client device type (in beacon)
  74. USHORT usBeaconDeviceManufID; // Client manufacturing ID (in beacon)
  75. UCHAR ucBeaconFrequency; // Link Radio Frequency
  76. UCHAR ucLinkPeriod; // Link Channel Period
  77. BOOL bPairingEnabled; // Pairing is enabled/disabled
  78. BOOL bUploadEnabled; // Upload is enabled/disabled
  79. BOOL bDataAvailable; // Data is available/not available for download
  80. UCHAR ucAuthType; // Authentication type to include in beacon
  81. UCHAR ucBeaconTimeout; // In seconds. Timeout disabled = 0xFF.
  82. UCHAR ucPairingTimeout; // In seconds. Timeout disabled = 0xFF.
  83. } ANTFS_CLIENT_PARAMS;
  84. // Parameters received from host for the requested download/upload/erase
  85. typedef struct
  86. {
  87. USHORT usFileIndex; // (Download/Upload/Erase) File index
  88. ULONG ulOffset; // (Download/Upload) Current offset
  89. ULONG ulBlockSize; // (Download) Maximum number of bytes in download block
  90. ULONG ulMaxSize; // (Upload) Offset + total remaining bytes.
  91. USHORT usCRCSeed; // (Download) CRC seed for the current download
  92. BOOL bInitialRequest; // (Download) Flag indicating this is an initial request
  93. } ANTFS_REQUEST_PARAMS;
  94. // Parameters received from host for disconnect command
  95. typedef struct
  96. {
  97. UCHAR ucCommandType; // Disconnect command type
  98. UCHAR ucTimeDuration; // Requested amount in time (in 30 s increments) to become undiscoverable
  99. UCHAR ucAppSpecificDuration; // Requested application specific undiscoverable time
  100. } ANTFS_DISCONNECT_PARAMS;
  101. // Client defined parameters for a download response
  102. typedef struct
  103. {
  104. USHORT usFileIndex; // File index
  105. ULONG ulMaxBlockSize; // Maximum burst block size that can be sent by the client
  106. } ANTFS_DOWNLOAD_PARAMS;
  107. // Client defined parameters for an upload response
  108. typedef struct
  109. {
  110. USHORT usFileIndex; // File index
  111. ULONG ulMaxSize; // Maximum number of bytes that can be written to the file
  112. ULONG ulMaxBlockSize; // Maximum burst block size that can be received by the client
  113. } ANTFS_UPLOAD_PARAMS;
  114. //////////////////////////////////////////////////////////////////////////////////
  115. // Public Function Prototypes
  116. //////////////////////////////////////////////////////////////////////////////////
  117. // TODO: Is this class used for anything? Do we need it?
  118. class ANTFSClientInterface
  119. {
  120. public:
  121. virtual ~ANTFSClientInterface(){}
  122. virtual void Close(void) = 0;
  123. /////////////////////////////////////////////////////////////////
  124. // Stops any pending actions, and cleans up any dynamic memory
  125. // being used by the library.
  126. /////////////////////////////////////////////////////////////////
  127. virtual ANTFS_RETURN ConfigureClientParameters(ANTFS_CLIENT_PARAMS* pstInitParams_) = 0;
  128. /////////////////////////////////////////////////////////////////
  129. // Set up ANTFSClient configuration parameters.
  130. // Returns ANTFS_RETURN_PASS if successful. Otherwise, it returns
  131. // ANTFS_RETURN_FAIL if the library is in the wrong state, or
  132. // ANTFS_RETURN_BUSY if the library is busy with another request.
  133. // Parameters:
  134. // *pstInitParams_: A pointer to an
  135. // ANTFS_PARAMS structure that defines the
  136. // configuration parameters of the client
  137. // device
  138. /////////////////////////////////////////////////////////////////
  139. virtual ANTFS_RETURN OpenBeacon() = 0;
  140. /////////////////////////////////////////////////////////////////
  141. // Begins the channel configuration to transmit the ANT-FS beacon
  142. // Returns ANTFS_RETURN_PASS if successful. Otherwise, it returns
  143. // ANTFS_RETURN_FAIL if the library is in the wrong state, or
  144. // ANTFS_RETURN_BUSY if the library is busy with another request.
  145. // Operation:
  146. // Once the channel is successfully configured and opened,
  147. // a response of ANTFS_RESPONSE_BEACON_OPEN will be sent.
  148. /////////////////////////////////////////////////////////////////
  149. virtual ANTFS_RETURN CloseBeacon(BOOL bReturnToBroadcast_ = FALSE) = 0;
  150. /////////////////////////////////////////////////////////////////
  151. // Closes the ANT-FS beacon.
  152. // Returns ANTFS_RETURN_PASS if successful. Otherwise, it returns
  153. // ANTFS_RETURN_FAIL if the library is in the wrong state, or
  154. // ANTFS_RETURN_BUSY if the library is busy with another request.
  155. // Parameters:
  156. // bReturnToBroadcast_: If TRUE, the channel will remain
  157. // open, and the application can continue
  158. // to process messages. If FALSE,
  159. // the channel will be closed.
  160. // Operation:
  161. // Once the channel is successfully closed, a response of
  162. // ANTFS_CLIENT_RESPONSE_BEACON_CLOSED will be sent,
  163. // and the ANTFSClient will be in the ANTFS_STATE_IDLE state.
  164. // If the ReturnToBroadcast parameter is not used, the default
  165. // behavior will be to close the channel and stop broadcasting.
  166. /////////////////////////////////////////////////////////////////
  167. virtual ANTFS_CLIENT_STATE GetStatus(void) = 0;
  168. /////////////////////////////////////////////////////////////////
  169. // Returns the current library status.
  170. /////////////////////////////////////////////////////////////////
  171. virtual BOOL GetHostName(UCHAR *aucHostFriendlyName_, UCHAR *pucBufferSize_) = 0;
  172. /////////////////////////////////////////////////////////////////
  173. // Copies at most ucBufferSize_ characters from the host's
  174. // friendly name string (for the most recent session) into the
  175. // supplied pucHostFriendlyName_ buffer.
  176. // Parameters:
  177. // *aucFriendlyName_: A pointer to a buffer where the remote
  178. // device friendly name will be copied.
  179. // *pucBufferSize_: Pointer to a UCHAR variable that should contain the
  180. // maximum size of the buffer pointed to by
  181. // aucHostFriendlyName_.
  182. // After the function returns, the UCHAR variable
  183. // will be set to reflect the size of the friendly
  184. // name string that has been copied to the buffer.
  185. // Returns TRUE if successful. Otherwise, it returns FALSE.
  186. // Operation:
  187. // If the host's friendly name string has fewer than ucBufferSize_
  188. // characters, the *aucFriendlyName_ buffer will be padded with
  189. // zeroes.
  190. /////////////////////////////////////////////////////////////////
  191. virtual BOOL GetRequestParameters(ANTFS_REQUEST_PARAMS* stRequestParams_) = 0;
  192. /////////////////////////////////////////////////////////////////
  193. // Gets the parameters for a download, upload or erase request
  194. // received from the host
  195. //
  196. // Parameters:
  197. // *pstRequestParams_: Pointer to an ANTFS_REQUEST_PARAMS
  198. // structure that will receive the details
  199. // of the download, upload or erase request.
  200. // Returns TRUE if successful. Otherwise, it returns FALSE.
  201. /////////////////////////////////////////////////////////////////
  202. virtual BOOL GetDownloadStatus(ULONG *pulByteProgress_, ULONG *pulTotalLength_) = 0;
  203. /////////////////////////////////////////////////////////////////
  204. // Gets the transfer progress of a pending or a complete
  205. // download.
  206. // Parameters:
  207. // *pulByteProgress_: Pointer to a ULONG that will receive
  208. // the current byte progress of a pending or
  209. // complete download.
  210. // *pulTotalLength_: Pointer to a ULONG that will receive the
  211. // total expected length of the download.
  212. // Returns TRUE if successful. Otherwise, it returns FALSE.
  213. // Operation:
  214. // A data download occurs when information is requested from a
  215. // remote device. This function may be called at any point
  216. // during a download as a progress indicator. After the transfer
  217. // is complete, this information is valid until another request
  218. // for a data transfer is made.
  219. /////////////////////////////////////////////////////////////////
  220. virtual BOOL GetTransferData(ULONG *pulDataSize_ , void *pvData_ = NULL) = 0;
  221. /////////////////////////////////////////////////////////////////
  222. // Gets the received data from a transfer (upload).
  223. //
  224. // Parameters:
  225. // *ulDataSize_: Pointer to a ULONG that will receive
  226. // the size of the data available in bytes.
  227. // *pvData_: Pointer to a buffer where the received data
  228. // will be copied. NULL can be passed to this
  229. // parameter so that the size can be retrieved
  230. // without copying any data. The application
  231. // can then call this function again to after it
  232. // has allocated a buffer of sufficient size to
  233. // handle the data.
  234. // Returns TRUE if successful. Otherwise, it returns FALSE.
  235. /////////////////////////////////////////////////////////////////
  236. virtual ANTFS_RETURN SendPairingResponse(BOOL bAccept_) = 0;
  237. /////////////////////////////////////////////////////////////////
  238. // Sends a response to a pairing request.
  239. // Parameters:
  240. // bAccept_: Set this value to TRUE to accept the
  241. // pairing request, and FALSE to reject it.
  242. // Returns ANTFS_RETURN_PASS if successful. Otherwise, it returns
  243. // ANTFS_RETURN_FAIL if the library is in the wrong state, or
  244. // ANTFS_RETURN_BUSY if the library is busy with another request.
  245. // Operation:
  246. // A pairing request will automatically be rejected if no
  247. // response is sent within the pairing timeout, and the
  248. // application will receive an ANTFS_RESPONSE_PAIRING_TIMEOUT
  249. // response.
  250. /////////////////////////////////////////////////////////////////
  251. virtual ANTFS_RETURN SendDownloadResponse(UCHAR ucResponse_, ANTFS_DOWNLOAD_PARAMS* stDownloadInfo_, ULONG ulDataLength_, void *pvData_) = 0;
  252. /////////////////////////////////////////////////////////////////
  253. // Sends the response to a download request from an authenticated
  254. // device.
  255. // Parameters:
  256. // ucResponse_: The response to the download request.
  257. // stDownloadInfo_: Pointer to an ANTFS_DOWNLOAD_PARAMS
  258. // structure holding the parameters of the
  259. // download response.
  260. // ulDataLength_: The byte length of the data block to be
  261. // downloaded to the host device. This is the
  262. // size of the entire file, as specified in
  263. // the directory. Set to zero if no data
  264. // is to be downloaded.
  265. // *pvData_: Pointer to the location where the data
  266. // to be downloaded is stored. The pointer
  267. // should correspond with the beginning of the
  268. // file, without applying any offsets.
  269. // Set to NULL if no data is to be
  270. // downloaded (response rejected).
  271. // Returns ANTFS_RETURN_PASS if successful. Otherwise, it returns
  272. // ANTFS_RETURN_FAIL if the library is in the wrong state, or
  273. // ANTFS_RETURN_BUSY if the library is busy with another request.
  274. // Operation:
  275. // The data block provided to this function should be the entire
  276. // file. Handling of offsets and CRC calculations is done
  277. // internally within the library.
  278. // Once the request is posted, the application must wait for the
  279. // response from the library. Possible responses are:
  280. // ANTFS_CLIENT_RESPONSE_DOWNLOAD_PASS
  281. // ANTFS_CLIENT_RESPONSE_DOwNLOAD_REJECT
  282. // ANTFS_CLIENT_RESPONSE_DOWNLOAD_FAIL
  283. // ANTFS_CLIENT_RESPONSE_SERIAL_FAIL
  284. /////////////////////////////////////////////////////////////////
  285. virtual ANTFS_RETURN SendUploadResponse(UCHAR ucResponse_, ANTFS_UPLOAD_PARAMS* stUploadInfo_, ULONG ulDataLength_, void *pvData_) = 0;
  286. /////////////////////////////////////////////////////////////////
  287. // Sends the response to an upload request from an authenticated
  288. // device.
  289. // Parameters:
  290. // ucResponse_: The response to the upload request.
  291. // pstUploadInfo_: Pointer to an ANTFS_UPLOAD_PARAMS
  292. // structure holding the parameters of the
  293. // upload response.
  294. // ulDataLength_: The byte length of the data that is
  295. // currently stored at the requested upload
  296. // location. Set to zero if uploading to a
  297. // new index or if the uploaded data will
  298. // overwrite all existing data
  299. // *pvData_: Pointer to the location of the data at the
  300. // requested upload index. Set to NULL
  301. // if no data is available or if the uploaded
  302. // data will overwrite the existing file.
  303. // Returns ANTFS_RETURN_PASS if successful. Otherwise, it returns
  304. // ANTFS_RETURN_FAIL if the library is in the wrong state, or
  305. // ANTFS_RETURN_BUSY if the library is busy with another request.
  306. // Operation:
  307. // The data block provided to this function should be the entire
  308. // file. Handling of offsets and CRC calculations is done
  309. // internally within the library.
  310. // Once the request is posted, the application must wait for the
  311. // response from the ANTFSClient object. Possible responses are:
  312. // ANTFS_CLIENT_RESPONSE_UPLOAD_PASS
  313. // ANTFS_CLIENT_RESPONSE_UPLOAD_REJECT
  314. // ANTFS_CLIENT_RESPONSE_UPLOAD_FAIL
  315. // ANTFS_CLIENT_RESPONSE_SERIAL_FAIL
  316. // Upon receiving ANTFS_CLIENT_RESPONSE_UPLOAD_PASS the uploaded data
  317. // will be available in the transfer buffer. See GetTransferData().
  318. /////////////////////////////////////////////////////////////////
  319. virtual ANTFS_RETURN SendEraseResponse(UCHAR ucResponse_) = 0;
  320. /////////////////////////////////////////////////////////////////
  321. // Sends a response to a request to erase a file from an
  322. // authenticated remote device
  323. // Parameters:
  324. // ucResponse_: The response to the erase request.
  325. // Returns ANTFS_RETURN_PASS if successful. Otherwise, it returns
  326. // ANTFS_RETURN_FAIL if the library is in the wrong state, or
  327. // ANTFS_RETURN_BUSY if the library is busy with another request.
  328. /////////////////////////////////////////////////////////////////
  329. virtual ANTFS_CLIENT_RESPONSE WaitForResponse(ULONG ulMilliseconds_) = 0;
  330. /////////////////////////////////////////////////////////////////
  331. // Wait for a response from the ANTFS client library
  332. // Parameters:
  333. // ulMilliseconds_: Set this value to the minimum time to
  334. // wait before returning. If the value is
  335. // 0, the function will return immediately.
  336. // If the value is DSI_THREAD_INFINITE, the
  337. // function will not time out.
  338. // If one or more responses are pending before the timeout
  339. // expires the function will return the first response that
  340. // occurred. If no response is pending at the time the timeout
  341. // expires, ANTFS_CLIENT_RESPONSE_NONE is returned.
  342. // Operation:
  343. // Some of the events return parameters associated with the event.
  344. // Possible events and parameters:
  345. // ANTFS_CLIENT_RESPONSE_PAIRING_REQUEST - GetHostName()
  346. // ANTFS_CLIENT_RESPONSE_DOWNLOAD_REQUEST - GetRequestParameters()
  347. // ANTFS_CLIENT_RESPONSE_UPLOAD_REQUEST - GetRequestParameters()
  348. // ANTFS_CLIENT_RESPONSE_ERASE_REQUEST - GetRequestParameters()
  349. // ANTFS_CLIENT_RESPONSE_UPLOAD_PASS - GetTransferData()
  350. /////////////////////////////////////////////////////////////////
  351. };
  352. #endif // ANTFS_CLIENT_INTERFACE_H