Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 

431 řádky
14 KiB

  1. /**
  2. *
  3. * \file
  4. *
  5. * \brief WINC OTA Upgrade API Interface.
  6. *
  7. * Copyright (c) 2015 - 2017 Atmel Corporation. All rights reserved.
  8. *
  9. * \asf_license_start
  10. *
  11. * \page License
  12. *
  13. * Redistribution and use in source and binary forms, with or without
  14. * modification, are permitted provided that the following conditions are met:
  15. *
  16. * 1. Redistributions of source code must retain the above copyright notice,
  17. * this list of conditions and the following disclaimer.
  18. *
  19. * 2. Redistributions in binary form must reproduce the above copyright notice,
  20. * this list of conditions and the following disclaimer in the documentation
  21. * and/or other materials provided with the distribution.
  22. *
  23. * 3. The name of Atmel may not be used to endorse or promote products derived
  24. * from this software without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
  27. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  28. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
  29. * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
  30. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  31. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  32. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  33. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  34. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  35. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  36. * POSSIBILITY OF SUCH DAMAGE.
  37. *
  38. * \asf_license_stop
  39. *
  40. */
  41. #ifndef __M2M_OTA_H__
  42. #define __M2M_OTA_H__
  43. /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
  44. INCLUDES
  45. *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
  46. #include "common/include/nm_common.h"
  47. #include "driver/include/m2m_types.h"
  48. #include "driver/source/nmdrv.h"
  49. /**@addtogroup WlanEnums DataTypes
  50. * @ingroup m2m_wifi
  51. */
  52. /* @{ */
  53. /*!
  54. @typedef void (*tpfOtaNotifCb) (tstrOtaUpdateInfo *);
  55. @brief
  56. A callback to get notification about a potential OTA update.
  57. @param[in] pstrOtaUpdateInfo
  58. A structure to provide notification payload.
  59. @sa
  60. tstrOtaUpdateInfo
  61. @warning
  62. The notification is not supported (Not implemented yet)
  63. */
  64. typedef void (*tpfOtaNotifCb)(tstrOtaUpdateInfo *pstrOtaUpdateInfo);
  65. /*!
  66. @typedef void (*tpfOtaUpdateCb) (uint8 u8OtaUpdateStatusType ,uint8 u8OtaUpdateStatus);
  67. @brief
  68. A callback to get OTA status update, the callback provide the status type and its status.
  69. The OTA callback provides the download status, the switch to the downloaded firmware status and roll-back status.
  70. @param[in] u8OtaUpdateStatusType Possible values are listed in tenuOtaUpdateStatusType.
  71. @param[in] u8OtaUpdateStatus Possible values are listed as enumerated by @ref tenuOtaUpdateStatus.
  72. @see
  73. tenuOtaUpdateStatusType
  74. tenuOtaUpdateStatus
  75. */
  76. typedef void (*tpfOtaUpdateCb)(uint8 u8OtaUpdateStatusType, uint8 u8OtaUpdateStatus);
  77. /**@}*/
  78. /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
  79. FUNCTION PROTOTYPES
  80. *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
  81. #ifdef __cplusplus
  82. extern "C" {
  83. #endif
  84. /** @defgroup OtaInitFn m2m_ota_init
  85. * @ingroup WLANAPI
  86. * Synchronous initialization function for the OTA layer by registering the update callback.
  87. * The notification callback is not supported at the current version. Calling this API is a
  88. * MUST for all the OTA API's.
  89. */
  90. /**@{*/
  91. /*!
  92. @fn \
  93. NMI_API sint8 m2m_ota_init(tpfOtaUpdateCb pfOtaUpdateCb,tpfOtaNotifCb pfOtaNotifCb)
  94. @param [in] pfOtaUpdateCb
  95. OTA Update callback function
  96. @param [in] pfOtaNotifCb
  97. OTA notify callback function
  98. @return
  99. The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  100. */
  101. NMI_API sint8 m2m_ota_init(tpfOtaUpdateCb pfOtaUpdateCb, tpfOtaNotifCb pfOtaNotifCb);
  102. /**@}*/
  103. /** @defgroup OtaNotifStFn m2m_ota_notif_set_url
  104. * @ingroup WLANAPI
  105. * Set the OTA notification server URL, the functions need to be called before any check for update
  106. */
  107. /**@{*/
  108. /*!
  109. @fn \
  110. NMI_API sint8 m2m_ota_notif_set_url(uint8 * u8Url);
  111. @param [in] u8Url
  112. Set the OTA notification server URL, the functions need to be called before any check for update.
  113. @warning
  114. Calling m2m_ota_init is required
  115. Notification Server is not supported in the current version (function is not implemented)
  116. @see
  117. m2m_ota_init
  118. @return
  119. The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  120. */
  121. NMI_API sint8 m2m_ota_notif_set_url(uint8 *u8Url);
  122. /**@}*/
  123. /** @defgroup OtaNotifCheckFn m2m_ota_notif_check_for_update
  124. * @ingroup WLANAPI
  125. * Synchronous function to check for the OTA update using the Notification Server
  126. * URL. Function is not implemented (not supported at the current version)
  127. *
  128. */
  129. /**@{*/
  130. /*!
  131. @fn \
  132. NMI_API sint8 m2m_ota_notif_check_for_update(void);
  133. @warning
  134. Function is not implemented (not supported at the current version)
  135. @sa
  136. m2m_ota_init
  137. m2m_ota_notif_set_url
  138. @return
  139. The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  140. */
  141. NMI_API sint8 m2m_ota_notif_check_for_update(void);
  142. /**@}*/
  143. /** @defgroup OtaSched m2m_ota_notif_sched
  144. * @ingroup WLANAPI
  145. * Schedule OTA notification Server check for update request after specific number of days
  146. */
  147. /**@{*/
  148. /*!
  149. @fn \
  150. NMI_API sint8 m2m_ota_notif_sched(uint32 u32Period);
  151. @param [in] u32Period
  152. Period in days
  153. @sa
  154. m2m_ota_init
  155. m2m_ota_notif_check_for_update
  156. m2m_ota_notif_set_url
  157. @return
  158. The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  159. */
  160. NMI_API sint8 m2m_ota_notif_sched(uint32 u32Period);
  161. /**@}*/
  162. /** @defgroup OtaStartUpdatefn m2m_ota_start_update
  163. * @ingroup WLANAPI
  164. * Request OTA start update using the downloaded URL, the OTA module will download the OTA image and ensure integrity
  165. *of the image, and update the validity of the image in control structure. Switching to that image requires calling @ref
  166. *m2m_ota_switch_firmware API. As a prerequisite @ref m2m_ota_init should be called before using @ref
  167. *m2m_ota_start().
  168. */
  169. /**@{*/
  170. /*!
  171. @fn \
  172. NMI_API sint8 m2m_ota_start_update(uint8 * u8DownloadUrl);
  173. @param [in] u8DownloadUrl
  174. The download firmware URL, you get it from device info according to the application server
  175. @warning
  176. Calling this API does not guarantee OTA WINC image update, It depends on the connection with the download server and
  177. the validity of the image. If the API response is failure this may invalidate the roll-back image if it was previously
  178. valid, since the WINC does not have any internal memory except the flash roll-back image location to validate the
  179. downloaded image from
  180. @see
  181. m2m_ota_init
  182. tpfOtaUpdateCb
  183. @return
  184. The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  185. \section Example
  186. The example shows an example of how the OTA image update is carried out.
  187. @code
  188. static void OtaUpdateCb(uint8 u8OtaUpdateStatusType ,uint8 u8OtaUpdateStatus)
  189. {
  190. if(u8OtaUpdateStatusType == DL_STATUS) {
  191. if(u8OtaUpdateStatus == OTA_STATUS_SUCSESS) {
  192. //switch to the upgraded firmware
  193. m2m_ota_switch_firmware();
  194. }
  195. }
  196. else if(u8OtaUpdateStatusType == SW_STATUS) {
  197. if(u8OtaUpdateStatus == OTA_STATUS_SUCSESS) {
  198. M2M_INFO("Now OTA successfully done");
  199. //start the host SW upgrade then system reset is required (Reinitialize the driver)
  200. }
  201. }
  202. }
  203. void wifi_event_cb(uint8 u8WiFiEvent, void * pvMsg)
  204. {
  205. case M2M_WIFI_REQ_DHCP_CONF:
  206. {
  207. //after successfully connection, start the over air upgrade
  208. m2m_ota_start_update(OTA_URL);
  209. }
  210. break;
  211. default:
  212. break;
  213. }
  214. int main (void)
  215. {
  216. tstrWifiInitParam param;
  217. tstr1xAuthCredentials gstrCred1x = AUTH_CREDENTIALS;
  218. nm_bsp_init();
  219. m2m_memset((uint8*)&param, 0, sizeof(param));
  220. param.pfAppWifiCb = wifi_event_cb;
  221. //Initialize the WINC Driver
  222. ret = m2m_wifi_init(&param);
  223. if (M2M_SUCCESS != ret)
  224. {
  225. M2M_ERR("Driver Init Failed <%d>\n",ret);
  226. while(1);
  227. }
  228. //Initialize the OTA module
  229. m2m_ota_init(OtaUpdateCb,NULL);
  230. //connect to AP that provide connection to the OTA server
  231. m2m_wifi_default_connect();
  232. while(1)
  233. {
  234. //Handle the app state machine plus the WINC event handler
  235. while(m2m_wifi_handle_events(NULL) != M2M_SUCCESS) {
  236. }
  237. }
  238. }
  239. @endcode
  240. */
  241. NMI_API sint8 m2m_ota_start_update(uint8 *u8DownloadUrl);
  242. /**@}*/
  243. /** @defgroup OtaStartUpdatefn m2m_ota_start_update_crt
  244. * @ingroup WLANAPI
  245. * Request OTA start for cortus application image using the downloaded URL, the OTA module will download the OTA image
  246. *and ensure integrity of the image, and update the validity of the image in control structure. Switching to that image
  247. *requires calling @ref m2m_ota_switch_crt API. As a prerequisite @ref m2m_ota_init should be called before using
  248. *@ref m2m_ota_start_update_crt().
  249. */
  250. /**@{*/
  251. /*!
  252. @fn \
  253. NMI_API sint8 m2m_ota_start_update_crt(uint8 * u8DownloadUrl);
  254. @param [in] u8DownloadUrl
  255. The cortus application image url.
  256. @warning
  257. Calling this API does not guarantee cortus application image update, It depends on the connection with the download
  258. server and the validity of the image. If the API response is failure this may invalidate the roll-back image if it was
  259. previously valid, since the WINC does not have any internal memory except the flash roll-back image location to validate
  260. the downloaded image from
  261. @see
  262. m2m_ota_init
  263. tpfOtaUpdateCb
  264. @return
  265. The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  266. */
  267. NMI_API sint8 m2m_ota_start_update_crt(uint8 *u8DownloadUrl);
  268. /**@}*/
  269. /** @defgroup OtaRollbackfn m2m_ota_rollback
  270. * @ingroup WLANAPI
  271. Request OTA Roll-back to the old (other) WINC image, the WINC firmware will check the validation of the Roll-back
  272. image and switch to it if it is valid. If the API response is success, system restart is required (re-initialize the
  273. driver with hardware rest) update the host driver version may be required if it is did not match the minimum version
  274. supported by the WINC firmware.
  275. */
  276. /**@{*/
  277. /*!
  278. @fn \
  279. NMI_API sint8 m2m_ota_rollback(void);
  280. @sa
  281. m2m_ota_init
  282. m2m_ota_start_update
  283. @return
  284. The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  285. */
  286. NMI_API sint8 m2m_ota_rollback(void);
  287. /**@}*/
  288. /** @defgroup OtaRollbackfn m2m_ota_rollback_crt
  289. * @ingroup WLANAPI
  290. Request Cortus application OTA Roll-back to the old (other) cortus application image, the WINC firmware will check
  291. the validation of the Roll-back image and switch to it if it is valid. If the API response is success, system restart is
  292. required (re-initialize the driver with hardware rest) update the host driver version may be required.
  293. */
  294. /**@{*/
  295. /*!
  296. @fn \
  297. NMI_API sint8 m2m_ota_rollback_crt(void);
  298. @sa
  299. m2m_ota_init
  300. m2m_ota_start_update_crt
  301. @return
  302. The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  303. */
  304. NMI_API sint8 m2m_ota_rollback_crt(void);
  305. /**@}*/
  306. /** @defgroup OtaAbortfn m2m_ota_abort
  307. * @ingroup WLANAPI
  308. Request abort of current OTA download.
  309. The WINC firmware will terminate the OTA download if one is in progress.
  310. If no download is in progress, the API will respond with failure.
  311. */
  312. /**@{*/
  313. /*!
  314. @fn \
  315. NMI_API sint8 m2m_ota_abort(void);
  316. @return
  317. The function returns @ref M2M_SUCCESS for successful operation and a negative value otherwise.
  318. */
  319. NMI_API sint8 m2m_ota_abort(void);
  320. /**@}*/
  321. /**@}*/
  322. /** @defgroup OtaSwitchFirmware m2m_ota_switch_firmware
  323. * @ingroup WLANAPI
  324. * Switch to the upgraded Firmware, that API will update the control structure working image to the upgraded image
  325. take effect will be on the next system restart
  326. */
  327. /**@{*/
  328. /*!
  329. @fn \
  330. NMI_API sint8 m2m_ota_switch_firmware(void);
  331. @warning
  332. It is important to note that if the API succeeds, system restart is required (re-initializing the driver with
  333. hardware reset) updating the host driver version may be required if it does not match the minimum driver version
  334. supported by the WINC's firmware.
  335. @sa
  336. m2m_ota_init
  337. m2m_ota_start_update
  338. @return
  339. The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  340. */
  341. NMI_API sint8 m2m_ota_switch_firmware(void);
  342. /**@}*/
  343. /**@}*/
  344. /** @defgroup OtaSwitchFirmware m2m_ota_switch_crt
  345. * @ingroup WLANAPI
  346. * Switch to the upgraded cortus application, that API will update the control structure working image to the upgraded
  347. image take effect will be on the next system restart
  348. */
  349. /**@{*/
  350. /*!
  351. @fn \
  352. NMI_API sint8 m2m_ota_switch_firmware(void);
  353. @warning
  354. It is important to note that if the API succeeds, system restart is required (re-initializing the driver with
  355. hardware reset) updating the host driver version may be required if it does not match the minimum driver version
  356. supported by the WINC's firmware.
  357. @sa
  358. m2m_ota_init
  359. m2m_ota_start_update_crt
  360. @return
  361. The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  362. */
  363. NMI_API sint8 m2m_ota_switch_crt(void);
  364. /*!
  365. @fn \
  366. NMI_API sint8 m2m_ota_get_firmware_version(void);
  367. @brief
  368. Get the OTA Firmware version.
  369. @return
  370. The function SHALL return 0 for success and a negative value otherwise.
  371. */
  372. NMI_API sint8 m2m_ota_get_firmware_version(tstrM2mRev *pstrRev);
  373. /**@}*/
  374. NMI_API sint8 m2m_ota_test(void);
  375. #ifdef __cplusplus
  376. }
  377. #endif
  378. #endif /* __M2M_OTA_H__ */