1
0

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
  4. in compliance with this license.
  5. Copyright (c) Dynastream Innovations Inc. 2016
  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 *pulOffset_ ,ULONG *pulDataSize_ , void *pvData_ = NULL) = 0;
  221. /////////////////////////////////////////////////////////////////
  222. // Gets the received data from a transfer (upload).
  223. //
  224. // Parameters:
  225. // *pulOffset_: Pointer to a ULONG that will receive
  226. // the offset for the client file
  227. // *ulDataSize_: Pointer to a ULONG that will receive
  228. // the size of the data available in bytes.
  229. // *pvData_: Pointer to a buffer where the received data
  230. // will be copied. NULL can be passed to this
  231. // parameter so that the size can be retrieved
  232. // without copying any data. The application
  233. // can then call this function again to after it
  234. // has allocated a buffer of sufficient size to
  235. // handle the data.
  236. // Returns TRUE if successful. Otherwise, it returns FALSE.
  237. /////////////////////////////////////////////////////////////////
  238. virtual ANTFS_RETURN SendPairingResponse(BOOL bAccept_) = 0;
  239. /////////////////////////////////////////////////////////////////
  240. // Sends a response to a pairing request.
  241. // Parameters:
  242. // bAccept_: Set this value to TRUE to accept the
  243. // pairing request, and FALSE to reject it.
  244. // Returns ANTFS_RETURN_PASS if successful. Otherwise, it returns
  245. // ANTFS_RETURN_FAIL if the library is in the wrong state, or
  246. // ANTFS_RETURN_BUSY if the library is busy with another request.
  247. // Operation:
  248. // A pairing request will automatically be rejected if no
  249. // response is sent within the pairing timeout, and the
  250. // application will receive an ANTFS_RESPONSE_PAIRING_TIMEOUT
  251. // response.
  252. /////////////////////////////////////////////////////////////////
  253. virtual ANTFS_RETURN SendDownloadResponse(UCHAR ucResponse_, ANTFS_DOWNLOAD_PARAMS* stDownloadInfo_, ULONG ulDataLength_, void *pvData_) = 0;
  254. /////////////////////////////////////////////////////////////////
  255. // Sends the response to a download request from an authenticated
  256. // device.
  257. // Parameters:
  258. // ucResponse_: The response to the download request.
  259. // stDownloadInfo_: Pointer to an ANTFS_DOWNLOAD_PARAMS
  260. // structure holding the parameters of the
  261. // download response.
  262. // ulDataLength_: The byte length of the data block to be
  263. // downloaded to the host device. This is the
  264. // size of the entire file, as specified in
  265. // the directory. Set to zero if no data
  266. // is to be downloaded.
  267. // *pvData_: Pointer to the location where the data
  268. // to be downloaded is stored. The pointer
  269. // should correspond with the beginning of the
  270. // file, without applying any offsets.
  271. // Set to NULL if no data is to be
  272. // downloaded (response rejected).
  273. // Returns ANTFS_RETURN_PASS if successful. Otherwise, it returns
  274. // ANTFS_RETURN_FAIL if the library is in the wrong state, or
  275. // ANTFS_RETURN_BUSY if the library is busy with another request.
  276. // Operation:
  277. // The data block provided to this function should be the entire
  278. // file. Handling of offsets and CRC calculations is done
  279. // internally within the library.
  280. // Once the request is posted, the application must wait for the
  281. // response from the library. Possible responses are:
  282. // ANTFS_CLIENT_RESPONSE_DOWNLOAD_PASS
  283. // ANTFS_CLIENT_RESPONSE_DOwNLOAD_REJECT
  284. // ANTFS_CLIENT_RESPONSE_DOWNLOAD_FAIL
  285. // ANTFS_CLIENT_RESPONSE_SERIAL_FAIL
  286. /////////////////////////////////////////////////////////////////
  287. virtual ANTFS_RETURN SendUploadResponse(UCHAR ucResponse_, ANTFS_UPLOAD_PARAMS* stUploadInfo_, ULONG ulDataLength_, void *pvData_) = 0;
  288. /////////////////////////////////////////////////////////////////
  289. // Sends the response to an upload request from an authenticated
  290. // device.
  291. // Parameters:
  292. // ucResponse_: The response to the upload request.
  293. // pstUploadInfo_: Pointer to an ANTFS_UPLOAD_PARAMS
  294. // structure holding the parameters of the
  295. // upload response.
  296. // ulDataLength_: The byte length of the data that is
  297. // currently stored at the requested upload
  298. // location. Set to zero if uploading to a
  299. // new index or if the uploaded data will
  300. // overwrite all existing data
  301. // *pvData_: Pointer to the location of the data at the
  302. // requested upload index. Set to NULL
  303. // if no data is available or if the uploaded
  304. // data will overwrite the existing file.
  305. // Returns ANTFS_RETURN_PASS if successful. Otherwise, it returns
  306. // ANTFS_RETURN_FAIL if the library is in the wrong state, or
  307. // ANTFS_RETURN_BUSY if the library is busy with another request.
  308. // Operation:
  309. // The data block provided to this function should be the entire
  310. // file. Handling of offsets and CRC calculations is done
  311. // internally within the library.
  312. // Once the request is posted, the application must wait for the
  313. // response from the ANTFSClient object. Possible responses are:
  314. // ANTFS_CLIENT_RESPONSE_UPLOAD_PASS
  315. // ANTFS_CLIENT_RESPONSE_UPLOAD_REJECT
  316. // ANTFS_CLIENT_RESPONSE_UPLOAD_FAIL
  317. // ANTFS_CLIENT_RESPONSE_SERIAL_FAIL
  318. // Upon receiving ANTFS_CLIENT_RESPONSE_UPLOAD_PASS the uploaded data
  319. // will be available in the transfer buffer. See GetTransferData().
  320. /////////////////////////////////////////////////////////////////
  321. virtual ANTFS_RETURN SendEraseResponse(UCHAR ucResponse_) = 0;
  322. /////////////////////////////////////////////////////////////////
  323. // Sends a response to a request to erase a file from an
  324. // authenticated remote device
  325. // Parameters:
  326. // ucResponse_: The response to the erase request.
  327. // Returns ANTFS_RETURN_PASS if successful. Otherwise, it returns
  328. // ANTFS_RETURN_FAIL if the library is in the wrong state, or
  329. // ANTFS_RETURN_BUSY if the library is busy with another request.
  330. /////////////////////////////////////////////////////////////////
  331. virtual ANTFS_CLIENT_RESPONSE WaitForResponse(ULONG ulMilliseconds_) = 0;
  332. /////////////////////////////////////////////////////////////////
  333. // Wait for a response from the ANTFS client library
  334. // Parameters:
  335. // ulMilliseconds_: Set this value to the minimum time to
  336. // wait before returning. If the value is
  337. // 0, the function will return immediately.
  338. // If the value is DSI_THREAD_INFINITE, the
  339. // function will not time out.
  340. // If one or more responses are pending before the timeout
  341. // expires the function will return the first response that
  342. // occurred. If no response is pending at the time the timeout
  343. // expires, ANTFS_CLIENT_RESPONSE_NONE is returned.
  344. // Operation:
  345. // Some of the events return parameters associated with the event.
  346. // Possible events and parameters:
  347. // ANTFS_CLIENT_RESPONSE_PAIRING_REQUEST - GetHostName()
  348. // ANTFS_CLIENT_RESPONSE_DOWNLOAD_REQUEST - GetRequestParameters()
  349. // ANTFS_CLIENT_RESPONSE_UPLOAD_REQUEST - GetRequestParameters()
  350. // ANTFS_CLIENT_RESPONSE_ERASE_REQUEST - GetRequestParameters()
  351. // ANTFS_CLIENT_RESPONSE_UPLOAD_PASS - GetTransferData()
  352. /////////////////////////////////////////////////////////////////
  353. };
  354. #endif // ANTFS_CLIENT_INTERFACE_H