您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

4148 行
146 KiB

  1. /*******************************************************************************
  2. File Name:
  3. m2m_wifi.h
  4. Summary:
  5. WINC3400 WLAN Application Interface
  6. Description:
  7. WINC3400 WLAN Application Interface
  8. *******************************************************************************/
  9. //DOM-IGNORE-BEGIN
  10. /*******************************************************************************
  11. * Copyright (C) 2021 Microchip Technology Inc. and its subsidiaries.
  12. *
  13. * Subject to your compliance with these terms, you may use Microchip software
  14. * and any derivatives exclusively with Microchip products. It is your
  15. * responsibility to comply with third party license terms applicable to your
  16. * use of third party software (including open source software) that may
  17. * accompany Microchip software.
  18. *
  19. * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
  20. * EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
  21. * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
  22. * PARTICULAR PURPOSE.
  23. *
  24. * IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
  25. * INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
  26. * WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
  27. * BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
  28. * FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
  29. * ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
  30. * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
  31. *******************************************************************************/
  32. //DOM-IGNORE-END
  33. /** @defgroup m2m_wifi WLAN
  34. @{
  35. @defgroup WLANCallbacks Callbacks
  36. @brief
  37. Provides detail on the available callbacks for the Wlan APIs.
  38. @defgroup WlanDefines Defines
  39. @brief
  40. Specifies the macros and defines used by the Wlan APIs.
  41. @defgroup WlanEnums Enumerations and Typedefs
  42. @brief
  43. Specifies the enums and Data Structures used by the Wlan APIs.
  44. @defgroup WLANAPI Functions
  45. @brief
  46. Here are listed all the functions that implement the Wlan APIs.
  47. @{
  48. @defgroup WLANINIT Initialization
  49. @brief
  50. Here are listed all the functions that implement the Wlan Initialization APIs.
  51. @defgroup WLANEVTS Wlan Events
  52. @brief
  53. Here are listed all the functions that implement the Wlan Events APIs.
  54. @defgroup WLANCONNECT Connection
  55. @brief
  56. Here are listed all the functions that implement the Wifi Connection APIs.
  57. @defgroup WLANSCAN Scanning
  58. @brief
  59. Here are listed all the functions that implement the Wifi Scanning APIs.
  60. @defgroup WLANAP Hot-Spot (Access-Point)
  61. @brief
  62. Here are listed all the functions that implement the Wifi Hot-Spot (Access-Point) APIs.
  63. @defgroup WLANETH Bypass Mode
  64. @brief
  65. Here are listed all the functions that implement the Bypass Mode APIs.
  66. @defgroup WLANROAMING Roaming
  67. @brief
  68. Here are listed all the functions that implement the Wifi Roaming APIs.
  69. @defgroup WLANPS Power Save
  70. @brief
  71. Here are listed all the functions that implement the Power-Save APIs.
  72. @defgroup WLANCONF Configuration
  73. @brief
  74. Here are listed all the functions that implement the Wlan Configuration APIs.
  75. @defgroup WLANTIME System Time
  76. @brief
  77. Here are listed all the functions that implement the System Time APIs.
  78. @defgroup WLANPROVISION Provisioning
  79. @brief
  80. Here are listed all the functions that implement the Wifi Provisioning APIs.
  81. @defgroup WLANCRYPTO Crypto
  82. @brief
  83. Here are listed all the functions that implement the Wifi Crypto APIs.
  84. @cond P2P_DOC
  85. @defgroup WLANP2P P2P
  86. @brief
  87. Here are listed all the functions that implement the Wifi P2P APIs.
  88. @endcond
  89. @cond MON_DOC
  90. @defgroup WLANMON Monitoring Mode
  91. @brief
  92. Here are listed all the functions that implement the Wifi Monitoring Mode APIs.
  93. @endcond
  94. @defgroup BLEAPI BLE
  95. @brief
  96. Here are listed all the functions that implement the BLE APIs.
  97. @}
  98. @}
  99. */
  100. #ifndef __M2M_WIFI_H__
  101. #define __M2M_WIFI_H__
  102. /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
  103. INCLUDES
  104. *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
  105. #include "nm_common.h"
  106. #include "m2m_types.h"
  107. #include "nmdrv.h"
  108. /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
  109. Callbacks
  110. *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
  111. /**@addtogroup WLANCallbacks
  112. * @{
  113. */
  114. /*!
  115. @typedef void (*tpfAppWifiCb)(uint8_t u8MsgType, void* pvMsg);
  116. @brief
  117. This is the main callback function for the Wi-Fi driver and is responsible for processing
  118. any M2M_WIFI events that are received on the Wi-Fi interface.
  119. These events (notifications) are usually received in response to earlier Wi-Fi requests such
  120. as @ref m2m_wifi_request_scan, @ref m2m_wifi_connect_open, @ref m2m_wifi_get_connection_info
  121. @ref m2m_wifi_req_curr_rssi, @ref m2m_wifi_get_system_time, etc.
  122. Most Wi-Fi APIs are implemented in an asynchronous mode and calling them generates information
  123. that is then passed back to the application via this callback. For instance, a set of detected
  124. networks to be passed back as a result to a call to @ref m2m_wifi_request_scan.
  125. Applications must ensure a callback function is registered with the Wi-Fi driver by
  126. calling @ref m2m_wifi_init.
  127. @param[in] u8MsgType
  128. Type of notification. Possible types are:
  129. - @ref M2M_WIFI_RESP_CON_STATE_CHANGED
  130. - @ref M2M_WIFI_RESP_CONN_INFO
  131. - @ref M2M_WIFI_REQ_DHCP_CONF
  132. - @ref M2M_WIFI_REQ_WPS
  133. - @ref M2M_WIFI_RESP_IP_CONFLICT
  134. - @ref M2M_WIFI_RESP_SCAN_DONE
  135. - @ref M2M_WIFI_RESP_SCAN_RESULT
  136. - @ref M2M_WIFI_RESP_CURRENT_RSSI
  137. - @ref M2M_WIFI_RESP_CLIENT_INFO
  138. - @ref M2M_WIFI_RESP_PROVISION_INFO
  139. - @ref M2M_WIFI_RESP_DEFAULT_CONNECT
  140. - @ref M2M_WIFI_RESP_ETHERNET_RX_PACKET (If Bypass mode is active)
  141. - @ref M2M_WIFI_RESP_WIFI_RX_PACKET (If monitoring mode is active)
  142. @param[in] pvMsg
  143. A pointer to a buffer containing the notification parameters (if any).
  144. It should be cast to the correct data type corresponding to the notification type.
  145. @see
  146. tstrM2mWifiStateChanged
  147. tstrM2MWPSInfo
  148. tstrM2mScanDone
  149. tstrM2mWifiscanResult
  150. m2m_wifi_init
  151. */
  152. typedef void (*tpfAppWifiCb)(uint8_t u8MsgType, const void *const pvMsg);
  153. /*!
  154. @typedef void (*tpfAppEthCb)(uint8_t u8MsgType, void* pvMsg, void* pvCtrlBuf);
  155. @brief
  156. Ethernet (Bypass mode) notification callback function receiving Bypass mode events as
  157. defined in the Wi-Fi responses enumeration @ref tenuM2mStaCmd.
  158. If bypass mode is enabled, applications must ensure this callback function is registered
  159. with the Wi-Fi driver by calling @ref m2m_wifi_init.
  160. @param[in] u8MsgType
  161. Type of notification. Possible types are:
  162. - @ref M2M_WIFI_RESP_ETHERNET_RX_PACKET
  163. @param[in] pvMsg
  164. A pointer to a buffer containing the notification parameters (if any).
  165. It should be cast to the correct data type corresponding to the notification type.
  166. For example, it could be a pointer to the buffer holding the received frame in case
  167. a @ref M2M_WIFI_RESP_ETHERNET_RX_PACKET event is received.
  168. @param[in] pvControlBuf
  169. A pointer to control buffer describing the accompanied message.
  170. This must be cast to the data type @ref tstrM2mIpCtrlBuf in case of @ref M2M_WIFI_RESP_ETHERNET_RX_PACKET event.
  171. @warning
  172. Make sure that the application defines ETH_MODE.
  173. @see
  174. m2m_wifi_init
  175. */
  176. typedef void (*tpfAppEthCb) (uint8_t u8MsgType, const void *const pvMsg,const void *const pvCtrlBuf);
  177. /**@cond MON_DOC
  178. */
  179. /*!
  180. @typedef void (*tpfAppMonCb)(tstrM2MWifiRxPacketInfo* pstrWifiRxPacket, uint8_t* pu8Payload, uint16_t u16PayloadSize);
  181. @brief
  182. Wi-Fi monitoring mode callback function. This function delivers all received wi-Fi packets
  183. to the application. Applications requiring to operate in monitoring mode need to call the
  184. function @ref m2m_wifi_enable_monitoring_mode, in which, each Wi-Fi frame received will invoke
  185. a single call to this callback function.
  186. Monitoring mode may be disabled by calling @ref m2m_wifi_disable_monitoring_mode.
  187. @param[in] pstrWifiRxPacket
  188. Pointer to a structure holding the Wi-Fi packet header parameters.
  189. @param[in] pu8Payload
  190. Pointer to the buffer holding the Wi-Fi packet payload information required by the application
  191. starting from the defined OFFSET by the application (when calling @ref m2m_wifi_enable_monitoring_mode).
  192. Could hold a value of NULL, if the application does not need any data from the payload.
  193. @param[in] u16PayloadSize
  194. The size of the payload in bytes.
  195. @see
  196. m2m_wifi_enable_monitoring_mode,
  197. m2m_wifi_init
  198. @warning
  199. u16PayloadSize should not exceed the buffer size given through m2m_wifi_enable_monitoring_mode.
  200. */
  201. typedef void (*tpfAppMonCb)(tstrM2MWifiRxPacketInfo *pstrWifiRxPacket, uint8_t *pu8Payload, uint16_t u16PayloadSize);
  202. /**@endcond*/ //MON_DOC
  203. /**@}*/ //WLANCallbacks
  204. /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
  205. Enums and Data structures
  206. *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
  207. /**@addtogroup WlanEnums
  208. * @{
  209. */
  210. /*!
  211. @enum \
  212. tenuWifiState
  213. @brief
  214. Enumeration for Wi-Fi state
  215. The following is used to track the state of the wifi (not initialized, initialized or started)
  216. @remarks
  217. This is useful when putting the WINC in "download mode" to access the flash via SPI. By using
  218. @ref m2m_wifi_get_state and checking against the desired state, it is possible to validate if
  219. the Application can proceed with the WINC flash access or not.
  220. */
  221. typedef enum {
  222. WIFI_STATE_DEINIT,
  223. /*!< Wifi is not initialized */
  224. WIFI_STATE_INIT,
  225. /*!< Wifi has been initialized. WINC flash access is possible via m2m_flash APIs. */
  226. WIFI_STATE_START,
  227. /*!< Wifi has started */
  228. } tenuWifiState;
  229. /*!
  230. @enum \
  231. tenuCredStoreOption
  232. @brief
  233. @remarks
  234. */
  235. typedef enum {
  236. WIFI_CRED_DONTSAVE,
  237. /*!< Credentials will not be stored in WINC flash. */
  238. WIFI_CRED_SAVE_UNENCRYPTED,
  239. /*!< Credentials will be stored unencrypted in WINC flash. */
  240. WIFI_CRED_SAVE_ENCRYPTED
  241. /*!< Credentials will be stored encrypted in WINC flash.
  242. The encryption is not secure; it is merely intended to prevent sensitive information
  243. being leaked by an opportunistic read of WINC flash contents.
  244. The encryption keys involve WINC efuse contents, so WINC efuses should not be written
  245. while this option is in use. */
  246. } tenuCredStoreOption;
  247. /*!
  248. @enum \
  249. tenuTlsCertExpSettings
  250. @brief TLS Certificate Expiry Validation Options
  251. @remarks
  252. */
  253. typedef enum {
  254. TLS_CERT_EXP_CHECK_DISABLE,
  255. /*!<
  256. Certificate expiry is not checked.
  257. Server authentication does not depend on expiry of certificates.
  258. */
  259. TLS_CERT_EXP_CHECK_ENABLE,
  260. /*!<
  261. Certificate expiry is checked and current time is required.
  262. Server authentication fails if a certificate has expired or the current time is unknown.
  263. */
  264. TLS_CERT_EXP_CHECK_EN_IF_SYS_TIME
  265. /*!<
  266. Certificate expiry is only checked if current time is known.
  267. Server authentication fails if a certificate has expired; passes if the current time is unknown.
  268. */
  269. } tenuTlsCertExpSettings;
  270. /*!
  271. @enum \
  272. tenu1xOption
  273. @brief
  274. @remarks
  275. */
  276. typedef enum {
  277. WIFI_1X_BYPASS_SERVER_AUTH,
  278. /*!< Server authentication for 802.1x connections. Values are of type int.\n
  279. 0: Authenticate server; Default, Recommended.\n
  280. 1: Bypass server authentication.\n
  281. */
  282. WIFI_1X_TIME_VERIF_MODE,
  283. /*!< Mode for checking expiry of server certificate chain.
  284. Values are of type @ref tenuTlsCertExpSettings.
  285. Default is @ref TLS_CERT_EXP_CHECK_EN_IF_SYS_TIME.
  286. */
  287. WIFI_1X_SESSION_CACHING,
  288. /*!< TLS session caching on/off for 802.1x connections. Values are of type int.\n
  289. 0: Session caching off.\n
  290. 1: Session caching on; Default.\n
  291. Note that the WINC implementation of PEAPv0 does not support session caching; this setting is ignored for PEAPv0 methods.
  292. */
  293. WIFI_1X_SPECIFIC_ROOTCERT,
  294. /*!< SHA1 digest of subject name of the root certificate to be used during server authentication. Values are:\n
  295. 20-byte arrays: authentication is limited to this particular root certificate; Recommended\n
  296. 0-byte array: authentication can succeed with any certificate in the WINC root certificate store; Default.\n
  297. */
  298. } tenu1xOption;
  299. /*!
  300. @struct \
  301. tstrEthInitParam
  302. @brief
  303. Structure to hold Ethernet interface parameters.
  304. Structure is to be defined and have its attributes set, based on the application's functionality
  305. before a call is made to initialize the wi-fi operations by calling the
  306. @ref m2m_wifi_init function.
  307. Part of the wi-fi configuration structure @ref tstrWifiInitParam.
  308. Applications shouldn't need to define this structure, if the bypass mode is not defined.
  309. @see
  310. tpfAppEthCb
  311. tpfAppWifiCb
  312. m2m_wifi_init
  313. @warning
  314. Make sure that application defines ETH_MODE before using @ref tstrEthInitParam.
  315. */
  316. typedef struct {
  317. tpfAppEthCb pfAppEthCb; /*!< Callback for Ethernet interface. */
  318. uint8_t *au8ethRcvBuf; /*!< Pointer to Receive Buffer of Ethernet Packet */
  319. uint16_t u16ethRcvBufSize; /*!< Size of Receive Buffer for Ethernet Packet */
  320. uint8_t u8EthernetEnable; /*!< Enable Ethernet mode flag */
  321. } tstrEthInitParam;
  322. /*!
  323. @struct \
  324. tstrM2mIpCtrlBuf
  325. @brief
  326. Structure holding the incoming buffer's data size information, indicating the data size of the
  327. buffer and the remaining buffer's data size. The data of the buffer which holds the packet sent
  328. to the host when in the bypass mode, is placed in the @ref tstrEthInitParam::au8ethRcvBuf attribute.
  329. This following information is retrieved in the host when an event
  330. @ref M2M_WIFI_RESP_ETHERNET_RX_PACKET is received in the Wi-Fi callback function
  331. @ref tpfAppWifiCb.
  332. The application is expected to use this structure's information to determine if there is still incoming data to be received from the firmware.
  333. @see
  334. tpfAppWifiCb
  335. tpfAppEthCb
  336. tstrEthInitParam
  337. @warning
  338. Make sure that ETHERNET/bypass mode is defined before using @ref tstrM2mIpCtrlBuf
  339. */
  340. typedef struct {
  341. uint16_t u16DataSize; /*!< Size of the received data in bytes. */
  342. uint16_t u16RemainingDataSize; /*!< Size of the remaining data bytes to be delivered to host. */
  343. } tstrM2mIpCtrlBuf;
  344. /**
  345. @struct \
  346. tstrWifiInitParam
  347. @brief
  348. Structure, holding the Wi-fi configuration attributes such as the wi-fi callback , monitoring mode callback and Ethernet parameter initialization structure.
  349. Such configuration parameters are required to be set before calling the wi-fi initialization function @ref m2m_wifi_init.
  350. @ref pfAppWifiCb attribute must be set to handle the wi-fi callback operations.
  351. @ref pfAppMonCb attribute, is optional based on whether the application requires the monitoring mode configuration, and can there not
  352. be set before the initialization.
  353. @ref strEthInitParam structure, is another optional configuration based on whether the bypass mode is set.
  354. @see
  355. tpfAppEthCb
  356. tpfAppMonCb
  357. tstrEthInitParam
  358. */
  359. typedef struct {
  360. tpfAppWifiCb pfAppWifiCb; /*!< Callback for Wi-Fi notifications. */
  361. tpfAppMonCb pfAppMonCb; /*!< Callback for monitoring interface. */
  362. tstrEthInitParam strEthInitParam ; /*!< Structure to hold Ethernet interface parameters. */
  363. uint8_t GainTableIndex; /*!< Gain Table index to be used to configure the WiFi and BLE gains. */
  364. } tstrWifiInitParam;
  365. typedef struct {
  366. uint8_t *pu8Bssid;
  367. /*!< Pointer to BSSID (6 bytes). Optional (may be NULL).
  368. If present, this restricts the connection attempt to APs that have a matching BSSID. */
  369. uint8_t *pu8Ssid;
  370. /*!< Pointer to SSID. Required. */
  371. uint8_t u8SsidLen;
  372. /*!< Length of SSID in bytes. Permitted values are between 0 and 32. */
  373. tenuM2mScanCh enuChannel;
  374. /*!< Wi-Fi channel to connect on.
  375. If an appropriate AP cannot be found on this channel then connection fails.
  376. @ref M2M_WIFI_CH_ALL may be used to allow scanning of all channels. */
  377. } tstrNetworkId;
  378. /* Legacy Wep param structure. */
  379. typedef struct {
  380. uint8_t u8KeyIndx;
  381. uint8_t u8KeySz;
  382. uint8_t au8WepKey[WEP_104_KEY_STRING_SIZE + 1]; // NULL terminated
  383. uint8_t __PAD24__[3];
  384. } tstrM2mWifiWepParams;
  385. /* Legacy 802.1x MsChapv2 param structure. */
  386. typedef struct {
  387. uint8_t au8UserName[21]; // NULL terminated
  388. uint8_t au8Passwd[41]; // NULL terminated
  389. } tstr1xAuthCredentials;
  390. typedef struct {
  391. uint8_t *pu8Psk;
  392. /*!< Pointer to PSK, represented as an ASCII string (64 characters, representing 32 bytes).
  393. Must be NULL if Passphrase is provided instead. */
  394. uint8_t *pu8Passphrase;
  395. /*!< Pointer to Passphrase (Printable ASCII).
  396. Must be NULL if PSK is provided instead. */
  397. uint8_t u8PassphraseLen;
  398. /*!< Length of Passphrase. Permitted values are between 8 and 63.
  399. This field is ignored if pu8Passphrase == NULL. */
  400. } tstrAuthPsk;
  401. typedef struct {
  402. uint8_t *pu8WepKey;
  403. /*!< Pointer to WEP Key, represented as an ASCII string.
  404. (10 or 26 characters, representing 5 or 13 bytes.) */
  405. uint8_t u8KeySz;
  406. /*!< Size of WEP Key string.
  407. Permitted values are @ref WEP_40_KEY_STRING_SIZE or @ref WEP_104_KEY_STRING_SIZE. */
  408. uint8_t u8KeyIndx;
  409. /*!< WEP Key Index in the range 1 to 4. */
  410. } tstrAuthWep;
  411. typedef struct {
  412. uint8_t *pu8Domain;
  413. /*!< Pointer to Domain of authentication server (printable ASCII), including '@' or '\'
  414. separator character as appropriate. Use NULL if there is no domain information.
  415. The Domain will be either prepended or appended to the UserName, depending on the
  416. setting of field bPrependDomain. \n
  417. Example 1: if [Domain] is "@my_domain" and bPrependDomain is false, then the EAP
  418. identity response is "[UserName]@my_domain". \n
  419. Example 2: if [Domain] is "my_domain\" and bPrependDomain is true, then the EAP
  420. identity response is "my_domain\[UserName]". */
  421. uint8_t *pu8UserName;
  422. /*!< Pointer to UserName (ASCII).
  423. This will be sent (encrypted) in the tunneled EAP identity response (if applicable)
  424. and used during MSCHAPv2 authentication. If bUnencryptedUserName is true then it will
  425. also be sent (unencrypted) in the initial EAP identity response. */
  426. uint8_t *pu8Password;
  427. /*!< Pointer to MSCHAPv2 Password (ASCII).
  428. This will be used during MSCHAPv2 authentication. */
  429. uint16_t u16DomainLen;
  430. /*!< Length of Domain (in ASCII characters), including '@' or '\' separator character as
  431. appropriate.
  432. Permitted values are such that u16DomainLen + u16UserNameLen is between 0 and
  433. @ref M2M_AUTH_1X_USER_LEN_MAX. */
  434. uint16_t u16UserNameLen;
  435. /*!< Length of UserName (in ASCII characters).
  436. Permitted values are such that u16DomainLen + u16UserNameLen is between 0 and
  437. @ref M2M_AUTH_1X_USER_LEN_MAX. */
  438. uint16_t u16PasswordLen;
  439. /*!< Length of Password (in ASCII characters).
  440. Permitted values are between 0 and @ref M2M_AUTH_1X_PASSWORD_LEN_MAX. */
  441. bool bUnencryptedUserName;
  442. /*!< Determines whether UserName or "anonymous" is sent (unencrypted) in the initial EAP
  443. identity response. Domain is sent in both cases. \n
  444. true: UserName is sent in the initial EAP identity response (not recommended).
  445. false: "anonymous" is sent in the initial EAP identity response. This setting is
  446. recommended for tunneled methods. MSCHAPv2 is always a tunneled method. */
  447. bool bPrependDomain;
  448. /*!< Determines whether Domain is prepended or appended to UserName in EAP identity responses.
  449. true: Domain is prepended to UserName - [Domain][UserName].
  450. false: Domain is appended to UserName - [UserName][Domain]. */
  451. } tstrAuth1xMschap2;
  452. typedef struct {
  453. uint8_t *pu8Domain;
  454. /*!< Pointer to Domain of authentication server (printable ASCII), including '@' or '\'
  455. separator character as appropriate. Use NULL if there is no domain information.
  456. The Domain will be either prepended or appended to the UserName, depending on the
  457. setting of field bPrependDomain. \n
  458. Example 1: if [Domain] is "@my_domain" and bPrependDomain is false, then the EAP
  459. identity response is "[UserName]@my_domain". \n
  460. Example 2: if [Domain] is "my_domain\" and bPrependDomain is true, then the EAP
  461. identity response is "my_domain\[UserName]". */
  462. uint8_t *pu8UserName;
  463. /*!< Pointer to UserName (ASCII).
  464. This will be sent (encrypted) in the tunneled EAP identity response.
  465. If bUnencryptedUserName is true then it will also be sent (unencrypted) in the initial
  466. EAP identity response. */
  467. uint8_t *pu8PrivateKey_Mod;
  468. /*!< Pointer to PrivateKey modulus (raw data).
  469. This will be used during TLS client authentication. */
  470. uint8_t *pu8PrivateKey_Exp;
  471. /*!< Pointer to PrivateKey exponent (raw data).
  472. This will be used during TLS client authentication. */
  473. uint8_t *pu8Certificate;
  474. /*!< Pointer to TLS client certificate corresponding to PrivateKey.
  475. This will be used during TLS client authentication. */
  476. uint16_t u16DomainLen;
  477. /*!< Length of Domain (in ASCII characters), including '@' or '\' separator character as
  478. appropriate.
  479. Permitted values are such that u16DomainLen + u16UserNameLen is between 0 and
  480. @ref M2M_AUTH_1X_USER_LEN_MAX. */
  481. uint16_t u16UserNameLen;
  482. /*!< Length of UserName (in ASCII characters).
  483. Permitted values are such that u16DomainLen + u16UserNameLen is between 0 and
  484. @ref M2M_AUTH_1X_USER_LEN_MAX. */
  485. uint16_t u16PrivateKeyLen;
  486. /*!< Length of PrivateKey_Mod (in bytes).
  487. Permitted values are between 0 and @ref M2M_AUTH_1X_PRIVATEKEY_LEN_MAX, typically 128 or 256.
  488. PrivateKey_Exp must be the same length as modulus, pre-padded with 0s if necessary. */
  489. uint16_t u16CertificateLen;
  490. /*!< Length of Certificate (in bytes).
  491. Permitted values are between 0 and @ref M2M_AUTH_1X_CERT_LEN_MAX. */
  492. bool bUnencryptedUserName;
  493. /*!< Determines whether UserName or "anonymous" is sent (unencrypted) in the initial EAP
  494. identity response. Domain is sent in both cases. \n
  495. true: UserName is sent in the initial EAP identity response (required for EAP-TLS).
  496. false: "anonymous" is sent in the initial EAP identity response. This setting is
  497. recommended for tunneled methods such as EAP-PEAP/TLS. */
  498. bool bPrependDomain;
  499. /*!< Determines whether Domain is prepended or appended to UserName in EAP identity responses.
  500. true: Domain is prepended to UserName - [Domain][UserName].
  501. false: Domain is appended to UserName - [UserName][Domain]. */
  502. } tstrAuth1xTls;
  503. /**@}*/ //WlanEnums
  504. /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
  505. FUNCTION PROTOTYPES
  506. *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
  507. #ifdef __cplusplus
  508. extern "C" {
  509. #endif
  510. /*!
  511. @ingroup WLANINIT
  512. @fn \
  513. void m2m_wifi_download_mode(void);
  514. @brief
  515. Prepares the WINC before downloading any data (Firmware, Certificates, etc).
  516. @details
  517. This function should be called before attempting to download any data to the WINC.
  518. Performs the appropriate WINC driver initialization, this includes bus initialization,
  519. interrupt enabling and it halts the chip to allow for the firmware downloads. Firmware
  520. can be downloaded through a number of interfaces, UART, I2C and SPI.
  521. @pre
  522. Prior to call m2m_wifi_download_mode, the Application should ensure that the wifi is not
  523. initialized. This can be done by calling @ref m2m_wifi_get_state and in case the wifi state
  524. differs from @ref WIFI_STATE_DEINIT, a @ref m2m_wifi_deinit needs to be issued.
  525. @return
  526. The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  527. */
  528. int8_t m2m_wifi_download_mode(void);
  529. /*!
  530. @ingroup WLANINIT
  531. @fn \
  532. int8_t m2m_wifi_init(tstrWifiInitParam * pWifiInitParam);
  533. @brief
  534. Synchronous API to initialize the WINC driver.
  535. @details
  536. This function initializes the WINC driver by registering the callback function for the M2M_WIFI layer
  537. (also the callback function for bypass mode/monitoring mode if defined), initializing the host
  538. interface layer and the bus interfaces. Wi-Fi callback registering is essential to allow the
  539. handling of the events received, in response to the asynchronous Wi-Fi operations.
  540. The possible Wi-Fi events that are expected to be received through the callback
  541. function (provided by the application) to the M2M_WIFI layer are listed below:
  542. - @ref M2M_WIFI_RESP_CON_STATE_CHANGED
  543. - @ref M2M_WIFI_RESP_CONN_INFO
  544. - @ref M2M_WIFI_REQ_DHCP_CONF
  545. - @ref M2M_WIFI_REQ_WPS
  546. - @ref M2M_WIFI_RESP_IP_CONFLICT
  547. - @ref M2M_WIFI_RESP_SCAN_DONE
  548. - @ref M2M_WIFI_RESP_SCAN_RESULT
  549. - @ref M2M_WIFI_RESP_CURRENT_RSSI
  550. - @ref M2M_WIFI_RESP_CLIENT_INFO
  551. - @ref M2M_WIFI_RESP_PROVISION_INFO
  552. - @ref M2M_WIFI_RESP_DEFAULT_CONNECT
  553. - @ref M2M_WIFI_RESP_ETHERNET_RX_PACKET (if bypass mode is enabled)
  554. - @ref M2M_WIFI_RESP_WIFI_RX_PACKET (if monitoring mode is enabled)
  555. Any application using the WINC driver must call this function at the start of its main function.
  556. @param[in] pWifiInitParam
  557. This is a pointer to a variable of type @ref tstrWifiInitParam which contains pointers to the
  558. application WIFI layer callback function, monitoring mode callback and @ref tstrEthInitParam
  559. structure (which contains initialization settings for bypass mode).
  560. @return
  561. The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  562. @pre
  563. Prior to this function call, the application should initialize the BSP using @ref nm_bsp_init.
  564. Also, the application must provide a callback function responsible for receiving all the
  565. wi-fi events that are received on the M2M_WIFI layer.
  566. @warning
  567. Failure to successfully complete indicates that the driver could not be initialized and
  568. a fatal error will prevent the application from proceeding, proper error handling should be
  569. implemented by the application.
  570. @see
  571. m2m_wifi_deinit
  572. m2m_wifi_init_hold
  573. m2m_wifi_init_start
  574. m2m_wifi_reinit
  575. m2m_wifi_reinit_hold
  576. m2m_wifi_reinit_start
  577. m2m_wifi_download_mode
  578. tstrWifiInitParam
  579. tenuM2mStaCmd
  580. */
  581. int8_t m2m_wifi_init(tstrWifiInitParam *pWifiInitParam);
  582. /*!
  583. @ingroup WLANINIT
  584. @fn \
  585. int8_t m2m_wifi_deinit(void * arg);
  586. @brief
  587. Synchronous API to de-initialize the WINC driver and host interface.
  588. @details
  589. De-initialization function for the WINC driver.
  590. De-initializes the host interface and frees any resources used by the M2M_WIFI layer.
  591. This function must be called in the application closing phase to ensure that all
  592. resources have been correctly released.
  593. @param[in] arg
  594. Opaque argument, not used in current implementation. Application should use null.
  595. @return
  596. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC,
  597. and a negative value otherwise.
  598. @note
  599. This function must be called at the de-initialization stage of the application.
  600. Generally this function should be the last function before switching off the chip
  601. and it should be followed only by @ref nm_bsp_deinit function call.
  602. Every function call of @ref m2m_wifi_init should be matched with a call to m2m_wifi_deinit.
  603. @see
  604. nm_bsp_deinit
  605. m2m_wifi_init
  606. m2m_wifi_init_hold
  607. m2m_wifi_init_start
  608. m2m_wifi_reinit
  609. m2m_wifi_reinit_hold
  610. m2m_wifi_reinit_start
  611. m2m_wifi_download_mode
  612. m2m_wifi_download_mode
  613. */
  614. int8_t m2m_wifi_deinit(void *arg);
  615. /*!
  616. @ingroup WLANINIT
  617. @fn \
  618. int8_t m2m_wifi_init_hold(void);
  619. @brief
  620. First part of @ref m2m_wifi_init, up to the point of initializing SPI for flash access.
  621. @see
  622. m2m_wifi_init
  623. m2m_wifi_deinit
  624. m2m_wifi_init_start
  625. m2m_wifi_reinit
  626. m2m_wifi_reinit_hold
  627. m2m_wifi_reinit_start
  628. m2m_wifi_download_mode
  629. */
  630. int8_t m2m_wifi_init_hold(void);
  631. /*!
  632. @ingroup WLANINIT
  633. @fn \
  634. int8_t m2m_wifi_init_start(tstrWifiInitParam *pWifiInitParam);
  635. @brief
  636. Second part of @ref m2m_wifi_init, continuing from where @ref m2m_wifi_init_hold left off.
  637. @param[in] pWifiInitParam
  638. This is a pointer to a variable of type @ref tstrWifiInitParam which contains pointers to the
  639. application WIFI layer callback function (see @ref tpfAppWifiCb), monitoring mode callback
  640. (see @ref tpfAppEthCb) and @ref tstrEthInitParam structure (which contains initialization
  641. settings for bypass mode).
  642. @see
  643. m2m_wifi_init
  644. m2m_wifi_deinit
  645. m2m_wifi_init_hold
  646. m2m_wifi_reinit
  647. m2m_wifi_reinit_hold
  648. m2m_wifi_reinit_start
  649. m2m_wifi_download_mode
  650. tstrWifiInitParam
  651. */
  652. int8_t m2m_wifi_init_start(tstrWifiInitParam *pWifiInitParam);
  653. /*!
  654. @ingroup WLANINIT
  655. @fn \
  656. int8_t m2m_wifi_reinit(tstrWifiInitParam *pWifiInitParam);
  657. @brief
  658. De-initialize and then initialize wifi. Resets the WINC.
  659. @param[in] pWifiInitParam
  660. This is a pointer to a variable of type @ref tstrWifiInitParam which contains pointers to the
  661. application WIFI layer callback function (see @ref tpfAppWifiCb), monitoring mode callback
  662. (see @ref tpfAppEthCb) and @ref tstrEthInitParam structure (which contains initialization
  663. settings for bypass mode).
  664. @note
  665. m2m_wifi_reinit wraps a call to @ref m2m_wifi_deinit and to @ref m2m_wifi_init.
  666. @see
  667. m2m_wifi_init
  668. m2m_wifi_deinit
  669. m2m_wifi_init_hold
  670. m2m_wifi_init_start
  671. m2m_wifi_reinit_hold
  672. m2m_wifi_reinit_start
  673. m2m_wifi_download_mode
  674. tstrWifiInitParam
  675. */
  676. int8_t m2m_wifi_reinit(tstrWifiInitParam *pWifiInitParam);
  677. /*!
  678. @ingroup WLANINIT
  679. @fn \
  680. int8_t m2m_wifi_reinit_hold(void);
  681. @brief
  682. First part of @ref m2m_wifi_reinit, up to the point of initializing SPI for flash access.
  683. @note
  684. m2m_wifi_reinit_hold wraps a call to @ref m2m_wifi_deinit and to @ref m2m_wifi_init_hold.
  685. @see
  686. m2m_wifi_init
  687. m2m_wifi_deinit
  688. m2m_wifi_init_hold
  689. m2m_wifi_init_start
  690. m2m_wifi_reinit
  691. m2m_wifi_reinit_start
  692. m2m_wifi_download_mode
  693. */
  694. int8_t m2m_wifi_reinit_hold(void);
  695. /*!
  696. @ingroup WLANINIT
  697. @fn \
  698. int8_t m2m_wifi_reinit_start(tstrWifiInitParam *pWifiInitParam);
  699. @brief
  700. Second part of @ref m2m_wifi_reinit, continuing from where m2m_wifi_reinit_hold left off.
  701. @param[in] pWifiInitParam
  702. This is a pointer to the @ref tstrWifiInitParam structure which contains pointers to the
  703. application WIFI layer callback function (see @ref tpfAppWifiCb), monitoring mode callback
  704. (see @ref tpfAppEthCb) and @ref tstrEthInitParam structure (which contains initialization
  705. settings for bypass mode).
  706. @see
  707. m2m_wifi_init
  708. m2m_wifi_deinit
  709. m2m_wifi_init_hold
  710. m2m_wifi_init_start
  711. m2m_wifi_reinit
  712. m2m_wifi_reinit_hold
  713. m2m_wifi_download_mode
  714. tstrWifiInitParam
  715. */
  716. int8_t m2m_wifi_reinit_start(tstrWifiInitParam *pWifiInitParam);
  717. /*!
  718. @ingroup WLANEVTS
  719. @fn \
  720. int8_t m2m_wifi_handle_events(void);
  721. @brief
  722. Synchronous M2M event handler function.
  723. @details
  724. This function is responsible for handling interrupts received from the WINC firmware.
  725. Applications should call this function periodically in-order to receive the events that are to
  726. be handled by the callback functions implemented by the application.
  727. Handle the various events received from the WINC.
  728. Whenever an event happens in the WINC (e.g. Connection, Disconnection, DHCP, etc),
  729. the WINC will interrupt the host to let it know that a new event has occurred. The host driver
  730. will attempt to handle these events whenever the application decides to do so by calling
  731. the m2m_wifi_handle_events function.
  732. It is mandatory to call this function periodically and independently of any other condition.
  733. It is ideal to include this function in the main and the most frequent loop of the
  734. host application.
  735. @pre
  736. Prior to receiving events, the WINC driver should have been successfully initialized by calling the @ref m2m_wifi_init function.
  737. @warning
  738. Failure to successfully complete this function indicates bus errors and hence a fatal error that will prevent the application from proceeding.
  739. @return
  740. The function returns @ref M2M_SUCCESS for successful interrupt handling and a negative value otherwise.
  741. */
  742. int8_t m2m_wifi_handle_events(void);
  743. /*!
  744. @ingroup WLANCONNECT
  745. @fn \
  746. int8_t m2m_wifi_delete_sc(char *pcSsid, uint8_t u8SsidLen);
  747. @brief
  748. Asynchronous API that deletes connection credentials (PSK, WEP key, 802.1X password) from WINC
  749. flash. Either deletes all credentials, or for a specific SSID.
  750. @details
  751. Causes WINC to delete connection credentials. If the parameter is NULL, then WINC will delete
  752. all credentials from flash. Otherwise WINC will only delete credentials for matching SSID.
  753. Callback will report the status of the operation (success or not).
  754. @param[in] pcSsid
  755. SSID to match on when deleting credentials.
  756. SSID must not contain '\0'.
  757. NULL is a valid argument here, in which case all credentials are deleted.
  758. @param[in] u8SsidLen
  759. Length of SSID provided in pcSsid. Must be less than @ref M2M_MAX_SSID_LEN.
  760. This parameter is ignored if pcSsid is NULL.
  761. @pre
  762. Prior to deleting credentials, the WINC driver should have been successfully initialized by calling the
  763. @ref m2m_wifi_init function.
  764. @warning
  765. The option to delete for a specific SSID is currently not supported; all credentials are
  766. deleted regardless of the input parameters.
  767. @return
  768. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC and a negative value otherwise.
  769. */
  770. int8_t m2m_wifi_delete_sc(char *pcSsid, uint8_t u8SsidLen);
  771. /*!
  772. @ingroup WLANCONNECT
  773. @fn \
  774. int8_t m2m_wifi_default_connect(void);
  775. @brief
  776. Asynchronous API that attempts to reconnect to the last-associated access point.
  777. @details
  778. Asynchronous Wi-Fi connection function. An application calling this function will cause
  779. the firmware to attempt to reconnect to the access point with which it had last successfully connected.
  780. A failure to connect will result in a response of @ref M2M_WIFI_RESP_DEFAULT_CONNECT
  781. indicating a connection error as defined in the structure @ref tstrM2MDefaultConnResp.
  782. Possible errors are:
  783. @ref M2M_DEFAULT_CONN_EMPTY_LIST indicating that the connection list is empty, or
  784. @ref M2M_DEFAULT_CONN_SCAN_MISMATCH indicating a mismatch for the saved AP name.
  785. @pre
  786. Prior to connecting, the WINC driver should have been successfully initialized by calling the
  787. @ref m2m_wifi_init function.
  788. @warning
  789. This function must be called in station mode only.
  790. It is important to note that successful completion of a call to m2m_wifi_default_connect
  791. does not guarantee success of the WIFI connection; a negative return value indicates only
  792. locally-detected errors.
  793. @see
  794. m2m_wifi_connect
  795. @return
  796. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC and a negative value otherwise.
  797. */
  798. int8_t m2m_wifi_default_connect(void);
  799. /*!
  800. @ingroup WLANCONNECT
  801. @fn \
  802. int8_t m2m_wifi_connect_open(tenuCredStoreOption enuCredStoreOption, tstrNetworkId *pstrNetworkId);
  803. @brief
  804. Asynchronous API to connect to an access point using open authentication.
  805. @details
  806. Asynchronous Wi-Fi connection function. An application calling this function will cause the
  807. firmware to attempt to connect to an access point matching the details in pstrNetworkId, with
  808. open authentication.
  809. On successful connection, the connection details may be saved in WINC flash, according to
  810. the option selected in enuCredStoreOption.
  811. Once connection has been attempted (whether successful or otherwise), a response event
  812. @ref M2M_WIFI_RESP_CON_STATE_CHANGED will be sent to the callback function @ref tpfAppWifiCb
  813. provided during initialization @ref m2m_wifi_init.
  814. Possible results indicated by the response event are:
  815. - @ref M2M_WIFI_DISCONNECTED if the connection attempt failed.
  816. - @ref M2M_WIFI_CONNECTED if the connection attempt succeeded.
  817. @pre
  818. Prior to attempting connection, the WINC driver must have been initialized by calling the
  819. @ref m2m_wifi_init function.
  820. @warning
  821. This function is handled in station mode only.
  822. @param[in] enuCredStoreOption
  823. Option to specify whether connection details (i.e. the contents of pstrNetworkId) are stored in
  824. WINC flash and, if so, whether they are encrypted before storing.
  825. @param[in] pstrNetworkId
  826. Structure specifying SSID/BSSID and Wi-Fi channel.
  827. @return
  828. The function returns @ref M2M_SUCCESS if the connect request has been successfully passed to the firmware and a negative value otherwise.
  829. */
  830. int8_t m2m_wifi_connect_open(tenuCredStoreOption enuCredStoreOption, tstrNetworkId *pstrNetworkId);
  831. /*!
  832. @ingroup WLANCONNECT
  833. @fn \
  834. int8_t m2m_wifi_connect_wep(tenuCredStoreOption enuCredStoreOption, tstrNetworkId *pstrNetworkId, tstrAuthWep *pstrAuthWep);
  835. @brief
  836. Asynchronous API to connect to an access point using WEP authentication.
  837. @details
  838. Asynchronous Wi-Fi connection function. An application calling this function will cause the
  839. firmware to attempt to connect to an access point matching the details in pstrNetworkId, with
  840. the WEP key provided in pstrAuthWep.
  841. On successful connection, the connection details may be saved in WINC flash, according to
  842. the option selected in enuCredStoreOption.
  843. Once connection has been attempted (whether successful or otherwise), a response event
  844. @ref M2M_WIFI_RESP_CON_STATE_CHANGED will be sent to the callback function @ref tpfAppWifiCb
  845. provided during initialization @ref m2m_wifi_init.
  846. Possible results indicated by the response event are:
  847. - @ref M2M_WIFI_DISCONNECTED if the connection attempt failed.
  848. - @ref M2M_WIFI_CONNECTED if the connection attempt succeeded.
  849. @pre
  850. Prior to attempting connection, the WINC driver must have been initialized by calling the
  851. @ref m2m_wifi_init function.
  852. @warning
  853. This function is handled in station mode only.
  854. @param[in] enuCredStoreOption
  855. Option to specify whether connection details (i.e. the contents of pstrNetworkId and pstrAuthWep) are stored in
  856. WINC flash and, if so, whether they are encrypted before storing.
  857. @param[in] pstrNetworkId
  858. Structure specifying SSID/BSSID and Wi-Fi channel.
  859. @param[in] pstrAuthWep
  860. Structure specifying the WEP key.
  861. @return
  862. The function returns @ref M2M_SUCCESS if the connect request has been successfully passed to the firmware and a negative value otherwise.
  863. */
  864. int8_t m2m_wifi_connect_wep(tenuCredStoreOption enuCredStoreOption, tstrNetworkId *pstrNetworkId, tstrAuthWep *pstrAuthWep);
  865. /*!
  866. @ingroup WLANCONNECT
  867. @fn \
  868. int8_t m2m_wifi_connect_psk(tenuCredStoreOption enuCredStoreOption, tstrNetworkId *pstrNetworkId, tstrAuthPsk *pstrAuthPsk);
  869. @brief
  870. Asynchronous API to connect to an access point using WPA(2) PSK authentication.
  871. @details
  872. Asynchronous Wi-Fi connection function. An application calling this function will cause the
  873. firmware to attempt to connect to an access point matching the details in pstrNetworkId, with
  874. the PSK passphrase provided in pstrAuthPsk.
  875. On successful connection, the connection details may be saved in WINC flash, according to
  876. the option selected in enuCredStoreOption.
  877. Once connection has been attempted (whether successful or otherwise), a response event
  878. @ref M2M_WIFI_RESP_CON_STATE_CHANGED will be sent to the callback function @ref tpfAppWifiCb
  879. provided during initialization @ref m2m_wifi_init.
  880. Possible results indicated by the response event are:
  881. - @ref M2M_WIFI_DISCONNECTED if the connection attempt failed.
  882. - @ref M2M_WIFI_CONNECTED if the connection attempt succeeded.
  883. @pre
  884. Prior to attempting connection, the WINC driver must have been initialized by calling the
  885. @ref m2m_wifi_init function.
  886. @warning
  887. This function is handled in station mode only.
  888. @param[in] enuCredStoreOption
  889. Option to specify whether connection details (i.e. the contents of pstrNetworkId and pstrAuthPsk) are stored in
  890. WINC flash and, if so, whether they are encrypted before storing.
  891. @param[in] pstrNetworkId
  892. Structure specifying SSID/BSSID and Wi-Fi channel.
  893. @param[in] pstrAuthPsk
  894. Structure specifying the Passphrase/PSK.
  895. @return
  896. The function returns @ref M2M_SUCCESS if the connect request has been successfully passed to the firmware and a negative value otherwise.
  897. */
  898. int8_t m2m_wifi_connect_psk(tenuCredStoreOption enuCredStoreOption, tstrNetworkId *pstrNetworkId, tstrAuthPsk *pstrAuthPsk);
  899. /*!
  900. @ingroup WLANCONNECT
  901. @fn \
  902. int8_t m2m_wifi_1x_set_option(tenu1xOption enuOptionName, const void *pOptionValue, size_t OptionLen);
  903. @brief
  904. API to set (write) options relating to Wi-Fi connection using WPA(2) Enterprise authentication.
  905. @details
  906. The following options can be set:\n
  907. @ref WIFI_1X_BYPASS_SERVER_AUTH\n
  908. @ref WIFI_1X_TIME_VERIF_MODE\n
  909. @ref WIFI_1X_SESSION_CACHING\n
  910. @ref WIFI_1X_SPECIFIC_ROOTCERT\n
  911. The setting applies to all subsequent connection attempts via @ref m2m_wifi_connect_1x_mschap2
  912. or @ref m2m_wifi_connect_1x_tls.\n
  913. Connection attempts via @ref m2m_wifi_default_connect use the
  914. settings which were in place at the time of the original connection.
  915. @param[in] enuOptionName
  916. The option to set.
  917. @param[in] pOptionValue
  918. Pointer to a buffer containing the value to set. The buffer must be at least as long as OptionLen.
  919. If OptionLen is 0, then pOptionValue may be NULL.
  920. @param[in] OptionLen
  921. The length of the option value being set.
  922. @return
  923. The function returns @ref M2M_SUCCESS if the parameters are valid and @ref M2M_ERR_INVALID_ARG otherwise.
  924. */
  925. int8_t m2m_wifi_1x_set_option(tenu1xOption enuOptionName, const void *pOptionValue, size_t OptionLen);
  926. /*!
  927. @ingroup WLANCONNECT
  928. @fn \
  929. int8_t m2m_wifi_1x_get_option(tenu1xOption enuOptionName, void *pOptionValue, size_t *pOptionLen);
  930. @brief
  931. API to get (read) options relating to Wi-Fi connection using WPA(2) Enterprise authentication.
  932. @details
  933. The following options can be read:\n
  934. @ref WIFI_1X_BYPASS_SERVER_AUTH\n
  935. @ref WIFI_1X_TIME_VERIF_MODE\n
  936. @ref WIFI_1X_SESSION_CACHING\n
  937. @ref WIFI_1X_SPECIFIC_ROOTCERT\n
  938. @param[in] enuOptionName
  939. The option to get.
  940. @param[out] pOptionValue
  941. Pointer to a buffer to be filled with the value being read. The buffer must be at least as long as the length in pOptionLen
  942. @param[inout] pOptionLen
  943. Pointer to a length.
  944. When calling the function, this length must be the length of the buffer available for reading the option value.
  945. When the function returns, this length is the length of the data that has been populated by the function.
  946. @return
  947. The function returns @ref M2M_SUCCESS if the parameters are valid and @ref M2M_ERR_INVALID_ARG otherwise.
  948. */
  949. int8_t m2m_wifi_1x_get_option(tenu1xOption enuOptionName, void *pOptionValue, size_t *pOptionLen);
  950. /*!
  951. @ingroup WLANCONNECT
  952. @fn \
  953. int8_t m2m_wifi_connect_1x_mschap2(tenuCredStoreOption enuCredStoreOption, tstrNetworkId *pstrNetworkId, tstrAuth1xMschap2 *pstrAuth1xMschap2);
  954. @brief
  955. Asynchronous API to connect to an access point using WPA(2) Enterprise authentication with
  956. MS-CHAP-V2 credentials.
  957. @details
  958. Asynchronous Wi-Fi connection function. An application calling this function will cause the
  959. firmware to attempt to connect to an access point matching the details in pstrNetworkId, with
  960. the Enterprise MS-CHAP-V2 credentials provided in pstrAuth1xMschap2.
  961. On successful connection, the connection details may be saved in WINC flash, according to
  962. the option selected in enuCredStoreOption.
  963. Once connection has been attempted (whether successful or otherwise), a response event
  964. @ref M2M_WIFI_RESP_CON_STATE_CHANGED will be sent to the callback function tpfAppWifiCb
  965. provided during initialization @ref m2m_wifi_init.
  966. Possible results indicated by the response event are:
  967. - @ref M2M_WIFI_DISCONNECTED if the connection attempt failed.
  968. - @ref M2M_WIFI_CONNECTED if the connection attempt succeeded.
  969. @pre
  970. Prior to attempting connection, the WINC driver must have been initialized by calling the
  971. @ref m2m_wifi_init function.
  972. @warning
  973. This function is handled in station mode only.
  974. @param[in] enuCredStoreOption
  975. Option to specify whether connection details (i.e. the contents of pstrNetworkId and pstrAuth1xMschap2) are stored
  976. in WINC flash and, if so, whether they are encrypted before storing.
  977. @param[in] pstrNetworkId
  978. Structure specifying SSID/BSSID and Wi-Fi channel.
  979. @param[in] pstrAuth1xMschap2
  980. Structure specifying the MS-CHAP-V2 credentials.
  981. @return
  982. The function returns @ref M2M_SUCCESS if the connect request has been successfully passed to the firmware and a negative value otherwise.
  983. */
  984. int8_t m2m_wifi_connect_1x_mschap2(tenuCredStoreOption enuCredStoreOption, tstrNetworkId *pstrNetworkId, tstrAuth1xMschap2 *pstrAuth1xMschap2);
  985. /*!
  986. @ingroup WLANCONNECT
  987. @fn \
  988. int8_t m2m_wifi_connect_1x_tls(tenuCredStoreOption enuCredStoreOption, tstrNetworkId *pstrNetworkId, tstrAuth1xTls *pstrAuth1xTls);
  989. @brief
  990. Asynchronous API to connect to an access point using WPA(2) Enterprise authentication with
  991. MS-CHAP-V2 credentials.
  992. @details
  993. Asynchronous Wi-Fi connection function. An application calling this function will cause the
  994. firmware to attempt to connect to an access point matching the details in pstrNetworkId, with
  995. the Enterprise TLS credentials provided in pstrAuth1xTls.
  996. On successful connection, the connection details may be saved in WINC flash, according to
  997. the option selected in enuCredStoreOption.
  998. Once connection has been attempted (whether successful or otherwise), a response event
  999. @ref M2M_WIFI_RESP_CON_STATE_CHANGED will be sent to the callback function @ref tpfAppWifiCb
  1000. provided during initialization @ref m2m_wifi_init.
  1001. Possible results indicated by the response event are:
  1002. - @ref M2M_WIFI_DISCONNECTED if the connection attempt failed.
  1003. - @ref M2M_WIFI_CONNECTED if the connection attempt succeeded.
  1004. @pre
  1005. Prior to attempting connection, the WINC driver must have been initialized by calling the
  1006. @ref m2m_wifi_init function.
  1007. @warning
  1008. This function is handled in station mode only.
  1009. @param[in] enuCredStoreOption
  1010. Option to specify whether connection details (i.e. the contents of pstrNetworkId and pstrAuth1xTls) are stored in
  1011. WINC flash and, if so, whether they are encrypted before storing.
  1012. @param[in] pstrNetworkId
  1013. Structure specifying SSID/BSSID and Wi-Fi channel.
  1014. @param[in] pstrAuth1xTls
  1015. Structure specifying the EAP-TLS credentials.
  1016. @return
  1017. The function returns @ref M2M_SUCCESS if the connect request has been successfully passed to the firmware and a negative value otherwise.
  1018. */
  1019. int8_t m2m_wifi_connect_1x_tls(tenuCredStoreOption enuCredStoreOption, tstrNetworkId *pstrNetworkId, tstrAuth1xTls *pstrAuth1xTls);
  1020. /*!
  1021. @ingroup WLANCONNECT
  1022. @fn \
  1023. int8_t m2m_wifi_connect(char *pcSsid, uint8_t u8SsidLen, uint8_t u8SecType, void *pvAuthInfo, uint16_t u16Ch);
  1024. @brief
  1025. Legacy asynchronous API to request connection to a specified access point.
  1026. @details
  1027. This API is maintained for purposes of compatibility with legacy applications. It is
  1028. implemented as a wrapper for the following new APIs:
  1029. @ref m2m_wifi_connect_open
  1030. @ref m2m_wifi_connect_wep
  1031. @ref m2m_wifi_connect_psk
  1032. @ref m2m_wifi_connect_1x_mschap2
  1033. @ref m2m_wifi_connect_1x_tls
  1034. These new APIs allow more flexibility and it is recommended that applications use them instead.
  1035. @param[in] pcSsid
  1036. A buffer holding the SSID corresponding to the requested AP.
  1037. SSID must not contain '\0'.
  1038. @param[in] u8SsidLen
  1039. Length of the given SSID (not including any NULL termination).
  1040. A length greater than or equal to @ref M2M_MAX_SSID_LEN will result in a negative error
  1041. @ref M2M_ERR_FAIL.
  1042. @param[in] u8SecType
  1043. Wi-Fi security type security for the network. It can be one of the following types:
  1044. -@ref M2M_WIFI_SEC_OPEN
  1045. -@ref M2M_WIFI_SEC_WEP
  1046. -@ref M2M_WIFI_SEC_WPA_PSK
  1047. -@ref M2M_WIFI_SEC_802_1X
  1048. A value outside these possible values will result in a negative return error @ref M2M_ERR_FAIL.
  1049. @param[in] pvAuthInfo
  1050. Authentication parameters required for completing the connection. Its type is based on the
  1051. security type. If the authentication parameters are NULL or are greater than the maximum length
  1052. of the authentication parameters length as defined by @ref M2M_MAX_PSK_LEN a negative error will
  1053. return @ref M2M_ERR_FAIL indicating connection failure.
  1054. @param[in] u16Ch
  1055. Wi-Fi channel number as defined in @ref tenuM2mScanCh enumeration. Specifying a channel number
  1056. greater than @ref M2M_WIFI_CH_14 returns a negative error @ref M2M_ERR_FAIL, unless
  1057. the value is @ref M2M_WIFI_CH_ALL, since this indicates that the firmware should scan all channels
  1058. to find the SSID specified in parameter pcSsid.
  1059. Failure to find the connection match will return a negative error
  1060. @ref M2M_DEFAULT_CONN_SCAN_MISMATCH.
  1061. @pre
  1062. Prior to a successful connection request, the wi-fi driver must have been successfully initialized
  1063. through the call of the @ref m2m_wifi_init function.
  1064. @warning
  1065. If there is a '\0' character within the first u8SsidLen characters, then this function will assume
  1066. that the input u8SsidLen was incorrect, set length to strlen(pcSsid) and continue.\n
  1067. It is recommended that the following Wi-Fi connect APIs are used instead:
  1068. @ref m2m_wifi_connect_open
  1069. @ref m2m_wifi_connect_wep
  1070. @ref m2m_wifi_connect_psk
  1071. @ref m2m_wifi_connect_1x_mschap2
  1072. @ref m2m_wifi_connect_1x_tls
  1073. Additionally:
  1074. - This function must be called in station mode only.
  1075. - Successful completion of this function does not guarantee success of the WIFI connection, and
  1076. a negative return value indicates only locally-detected errors.
  1077. @return
  1078. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC and a negative value otherwise.
  1079. @see
  1080. tuniM2MWifiAuth
  1081. tstr1xAuthCredentials
  1082. tstrM2mWifiWepParams
  1083. */
  1084. int8_t m2m_wifi_connect(char *pcSsid, uint8_t u8SsidLen, uint8_t u8SecType, void *pvAuthInfo, uint16_t u16Ch);
  1085. /*!
  1086. @ingroup WLANCONNECT
  1087. @fn \
  1088. int8_t m2m_wifi_connect_sc(char *pcSsid, uint8_t u8SsidLen, uint8_t u8SecType, void *pvAuthInfo, uint16_t u16Ch, uint8_t u8NoSaveCred);
  1089. @brief
  1090. Legacy asynchronous API to request connection to a specific AP with the option to save credentials in Flash.
  1091. @details
  1092. This API is maintained for purposes of compatibility with legacy applications. It is
  1093. implemented as a wrapper for the following new APIs:
  1094. @ref m2m_wifi_connect_open
  1095. @ref m2m_wifi_connect_wep
  1096. @ref m2m_wifi_connect_psk
  1097. @ref m2m_wifi_connect_1x_mschap2
  1098. @ref m2m_wifi_connect_1x_tls
  1099. These new APIs allow more flexibility and it is recommended that applications use them instead.
  1100. @param[in] pcSsid
  1101. A buffer holding the SSID corresponding to the requested AP.
  1102. SSID must not contain '\0'.
  1103. @param[in] u8SsidLen
  1104. Length of the given SSID (not including any NULL termination).
  1105. A length greater than or equal to @ref M2M_MAX_SSID_LEN will result in a negative error
  1106. @ref M2M_ERR_FAIL.
  1107. @param[in] u8SecType
  1108. Wi-Fi security type security for the network (see @ref tenuM2mSecType). It can be one of the following types:
  1109. -@ref M2M_WIFI_SEC_OPEN
  1110. -@ref M2M_WIFI_SEC_WEP
  1111. -@ref M2M_WIFI_SEC_WPA_PSK
  1112. -@ref M2M_WIFI_SEC_802_1X
  1113. A value outside these possible values will result in a negative return error @ref M2M_ERR_FAIL.
  1114. @param[in] pvAuthInfo
  1115. Authentication parameters required for completing the connection. Its type is based on the
  1116. security type. If the authentication parameters are NULL or are greater than the maximum length
  1117. of the authentication parameters length as defined by @ref M2M_MAX_PSK_LEN a negative error will
  1118. return @ref M2M_ERR_FAIL indicating connection failure.
  1119. @param[in] u16Ch
  1120. Wi-Fi channel number as defined in @ref tenuM2mScanCh enumeration. Specification of a channel
  1121. number greater than @ref M2M_WIFI_CH_14 returns a negative error @ref M2M_ERR_FAIL unless
  1122. the value is @ref M2M_WIFI_CH_ALL. A channel number of @ref M2M_WIFI_CH_ALL indicates that the
  1123. firmware should scan all channels to find the SSID specified in parameter pcSsid.
  1124. Failure to find the connection match will return a negative error
  1125. @ref M2M_DEFAULT_CONN_SCAN_MISMATCH.
  1126. @param[in] u8SaveCred
  1127. Option to store the access point SSID and password into the WINC flash memory or not.
  1128. @pre
  1129. Prior to a successful connection request, the wi-fi driver must have been successfully initialized through the call of the @ref m2m_wifi_init function.
  1130. @warning
  1131. If there is a '\0' character within the first u8SsidLen characters, then this function will assume
  1132. that the input u8SsidLen was incorrect, set length to strlen(pcSsid) and continue.\n
  1133. It is recommended that the following Wi-Fi connect APIs are used instead:
  1134. @ref m2m_wifi_connect_open
  1135. @ref m2m_wifi_connect_wep
  1136. @ref m2m_wifi_connect_psk
  1137. @ref m2m_wifi_connect_1x_mschap2
  1138. @ref m2m_wifi_connect_1x_tls
  1139. Additionally:
  1140. - This function must be called in station mode only.
  1141. - Successful completion of this function does not guarantee success of the WIFI connection, and
  1142. a negative return value indicates only locally-detected errors.
  1143. @see
  1144. tuniM2MWifiAuth
  1145. tenuM2mSecType
  1146. tstr1xAuthCredentials
  1147. tstrM2mWifiWepParams
  1148. @return
  1149. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC and a negative value otherwise.
  1150. */
  1151. int8_t m2m_wifi_connect_sc(char *pcSsid, uint8_t u8SsidLen, uint8_t u8SecType, void *pvAuthInfo, uint16_t u16Ch, uint8_t u8NoSaveCred);
  1152. /*!
  1153. @ingroup WLANCONNECT
  1154. @fn \
  1155. int8_t m2m_wifi_disconnect(void);
  1156. @brief
  1157. Synchronous API to request disconnection from a network.
  1158. @details
  1159. Request a Wi-Fi disconnect from the currently connected AP.
  1160. The connection status will be indicated to the application via a @ref M2M_WIFI_RESP_CON_STATE_CHANGED event.
  1161. The status will be one of those defined in @ref tenuM2mConnState, with @ref M2M_WIFI_DISCONNECTED indicating
  1162. a successful disconnection.
  1163. @return
  1164. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC and a negative value otherwise.
  1165. @pre
  1166. Disconnection request must be made to a successfully connected AP. If the WINC is not in the connected state, a call to this function will hold insignificant.
  1167. @warning
  1168. This function must be called in station mode only.
  1169. @see
  1170. m2m_wifi_connect
  1171. m2m_wifi_connect_sc
  1172. m2m_wifi_default_connect
  1173. m2m_wifi_connect_open
  1174. m2m_wifi_connect_wep
  1175. m2m_wifi_connect_psk
  1176. m2m_wifi_connect_1x_mschap2
  1177. m2m_wifi_connect_1x_tls
  1178. */
  1179. int8_t m2m_wifi_disconnect(void);
  1180. /*!
  1181. @ingroup WLANPROVISION
  1182. @fn \
  1183. int8_t m2m_wifi_start_provision_mode(tstrM2MAPConfig *pstrAPConfig, char *pcHttpServerDomainName, uint8_t bEnableHttpRedirect);
  1184. @brief
  1185. Asynchronous API for control of Wi-Fi provisioning functionality.
  1186. @details
  1187. This function allows the application to start the WINC in 'provisioning mode', a special mode
  1188. that triggers the WINC to create a Wi-Fi access point, DHCP server, and HTTP server.
  1189. The HTTP server presents a provisioning page to a connected client which lists the access points
  1190. detected in the vicinity of the WINC, and allows one of these to be selected and any appropriate
  1191. credentials to be entered. This allows a headless system to be provisioned (configured to
  1192. connect with an access point).
  1193. Provisioning status is returned in an event @ref M2M_WIFI_RESP_PROVISION_INFO.
  1194. @param[in] pstrAPConfig
  1195. AP configuration parameters as defined in @ref tstrM2MAPConfig configuration structure.
  1196. If a NULL value is passed in, the call will result in a negative error @ref M2M_ERR_FAIL.
  1197. @param[in] pcHttpServerDomainName
  1198. Domain name of the HTTP Provision WEB server which others will use to load the provisioning Home page.
  1199. The domain name can have one of the following 3 forms:
  1200. - 1. "wincprov.com"
  1201. - 2. "http://wincprov.com"
  1202. - 3. "https://wincprov.com"
  1203. Forms 1 and 2 are equivalent, they will both start a plain http server, while form 3
  1204. will start a secure HTTP provisioning Session (HTTP over SSL connection).
  1205. @param[in] bEnableHttpRedirect
  1206. A flag to enable/disable the HTTP redirect feature. If Secure provisioning is enabled (i.e. the server
  1207. domain name uses "https" prefix) this flag is ignored (no meaning for redirect in HTTPS).
  1208. Possible values are:
  1209. - Zero: DO NOT use HTTP Redirect. In this case, the associated device could open the provisioning
  1210. page ONLY when the HTTP Provision URL of the WINC HTTP Server is correctly written on the browser.
  1211. - Non-Zero: Use HTTP Redirect. In this case, all http traffic (http://URL) from the associated
  1212. device (Phone, PC, etc) will be redirected to the WINC HTTP Provisioning Home page.
  1213. @pre
  1214. - A Wi-Fi notification callback of type @ref tpfAppWifiCb MUST be implemented and registered at startup.
  1215. Registering the callback is done through passing it to the initialization @ref m2m_wifi_init function.
  1216. - The event @ref M2M_WIFI_RESP_CONN_INFO must be handled in the callback to receive the requested connection info.
  1217. @warning
  1218. Do not use ".local" in the pcHttpServerDomainName.
  1219. @return
  1220. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC and a negative value otherwise.
  1221. @see
  1222. tpfAppWifiCb
  1223. m2m_wifi_init
  1224. M2M_WIFI_RESP_PROVISION_INFO
  1225. m2m_wifi_stop_provision_mode
  1226. tstrM2MAPConfig
  1227. @section WIFIExample1 Example
  1228. The example demonstrates a code snippet for how provisioning is triggered and the response event
  1229. received accordingly.
  1230. @code
  1231. #include "m2m_wifi.h"
  1232. #include "m2m_types.h"
  1233. void wifi_event_cb(uint8_t u8WiFiEvent, void * pvMsg)
  1234. {
  1235. switch(u8WiFiEvent)
  1236. {
  1237. case M2M_WIFI_RESP_PROVISION_INFO:
  1238. {
  1239. tstrM2MProvisionInfo *pstrProvInfo = (tstrM2MProvisionInfo*)pvMsg;
  1240. if(pstrProvInfo->u8Status == M2M_SUCCESS)
  1241. {
  1242. tstrNetworkId strNetworkId = {NULL, pstrProvInfo->au8SSID, (uint8_t)strlen((char*)(pstrProvInfo->au8SSID)), M2M_WIFI_CH_ALL};
  1243. tstrAuthPsk strAuthPsk = {NULL, pstrProvInfo->au8Password, (uint8_t)strlen((char*)(pstrProvInfo->au8Password))};
  1244. m2m_wifi_connect_psk(WIFI_CRED_SAVE_ENCRYPTED, &strNetworkId, &strAuthPsk);
  1245. printf("PROV SSID : %s\n",pstrProvInfo->au8SSID);
  1246. printf("PROV PSK : %s\n",pstrProvInfo->au8Password);
  1247. }
  1248. else
  1249. {
  1250. printf("(ERR) Provisioning Failed\n");
  1251. }
  1252. }
  1253. break;
  1254. default:
  1255. break;
  1256. }
  1257. }
  1258. int main()
  1259. {
  1260. tstrWifiInitParam param;
  1261. param.pfAppWifiCb = wifi_event_cb;
  1262. if(!m2m_wifi_init(&param))
  1263. {
  1264. tstrM2MAPConfig apConfig;
  1265. uint8_t bEnableRedirect = 1;
  1266. strcpy(apConfig.au8SSID, "WINC_SSID");
  1267. apConfig.u8ListenChannel = 1;
  1268. apConfig.u8SecType = M2M_WIFI_SEC_OPEN;
  1269. apConfig.u8SsidHide = 0;
  1270. // IP Address
  1271. apConfig.au8DHCPServerIP[0] = 192;
  1272. apConfig.au8DHCPServerIP[1] = 168;
  1273. apConfig.au8DHCPServerIP[2] = 1;
  1274. apConfig.au8DHCPServerIP[3] = 1;
  1275. m2m_wifi_start_provision_mode(&apConfig, "atmelwincconf.com", bEnableRedirect);
  1276. while(1)
  1277. {
  1278. m2m_wifi_handle_events(NULL);
  1279. }
  1280. }
  1281. }
  1282. @endcode
  1283. */
  1284. int8_t m2m_wifi_start_provision_mode(tstrM2MAPConfig *pstrAPConfig, char *pcHttpServerDomainName, uint8_t bEnableHttpRedirect);
  1285. /*!
  1286. @ingroup WLANPROVISION
  1287. @fn \
  1288. int8_t m2m_wifi_start_provision_mode_ext(tstrM2MAPModeConfig *pstrAPModeConfig, char *pcHttpServerDomainName, uint8_t bEnableHttpRedirect);
  1289. @brief
  1290. Asynchronous API for control of Wi-Fi provisioning functionality with extended options.
  1291. @details
  1292. This function allows the application to start the WINC in 'provisioning mode', a special mode
  1293. that triggers the WINC to create a Wi-Fi access point, DHCP server, and HTTP server.
  1294. The HTTP server presents a provisioning page to a connected client which lists the access points
  1295. detected in the vicinity of the WINC, and allows one of these to be selected and any appropriate
  1296. credentials to be entered. This allows a headless system to be provisioned (configured to
  1297. connect with an access point).
  1298. Provisioning status is returned in an event @ref M2M_WIFI_RESP_PROVISION_INFO.
  1299. @param[in] pstrAPModeConfig
  1300. AP configuration parameters as defined in @ref tstrM2MAPModeConfig configuration structure.
  1301. A NULL value passed in, will result in a negative error @ref M2M_ERR_FAIL.
  1302. @param[in] pcHttpServerDomainName
  1303. Domain name of the HTTP Provision WEB server which others will use to load the provisioning Home page.
  1304. The domain name can have one of the following 3 forms:
  1305. - 1. "wincprov.com"
  1306. - 2. "http://wincprov.com"
  1307. - 3. "https://wincprov.com"
  1308. The forms 1 and 2 are equivalent, they both will start a plain http server, while form 3
  1309. will start a secure HTTP provisioning Session (HTTP over SSL connection).
  1310. @param[in] bEnableHttpRedirect
  1311. A flag to enable/disable the HTTP redirect feature. If Secure provisioning is enabled (i.e. the server
  1312. domain name uses "https" prefix) this flag is ignored (no meaning for redirect in HTTPS).
  1313. Possible values are:
  1314. - Zero: DO NOT use HTTP Redirect. In this case the associated device could open the
  1315. provisioning page ONLY when the HTTP Provision URL of the WINC HTTP Server is
  1316. correctly written on the browser.
  1317. - Non-Zero: Use HTTP Redirect. In this case, all http traffic (http://URL) from the
  1318. associated device (Phone, PC, ...etc) will be redirected to the WINC HTTP
  1319. Provisioning Home page.
  1320. @return
  1321. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC and a negative value otherwise.
  1322. @pre
  1323. - A Wi-Fi notification callback of type @ref tpfAppWifiCb MUST be implemented and registered at startup.
  1324. Registering the callback is done through passing it to the initialization @ref m2m_wifi_init function.
  1325. - The event @ref M2M_WIFI_RESP_CONN_INFO must be handled in the callback to receive the requested connection info.
  1326. @warning
  1327. Do not use ".local" in the pcHttpServerDomainName.
  1328. @see
  1329. tpfAppWifiCb
  1330. m2m_wifi_init
  1331. M2M_WIFI_RESP_PROVISION_INFO
  1332. m2m_wifi_stop_provision_mode
  1333. tstrM2MAPModeConfig
  1334. @section WIFIExample12 Example
  1335. The example demonstrates a code snippet for how provisioning is triggered and the response event
  1336. received accordingly.
  1337. @code
  1338. #include "m2m_wifi.h"
  1339. #include "m2m_types.h"
  1340. void wifi_event_cb(uint8_t u8WiFiEvent, void * pvMsg)
  1341. {
  1342. switch(u8WiFiEvent)
  1343. {
  1344. case M2M_WIFI_RESP_PROVISION_INFO:
  1345. {
  1346. tstrM2MProvisionInfo *pstrProvInfo = (tstrM2MProvisionInfo*)pvMsg;
  1347. if(pstrProvInfo->u8Status == M2M_SUCCESS)
  1348. {
  1349. tstrNetworkId strNetworkId = {NULL, pstrProvInfo->au8SSID, (uint8_t)strlen((char*)(pstrProvInfo->au8SSID)), M2M_WIFI_CH_ALL};
  1350. tstrAuthPsk strAuthPsk = {NULL, pstrProvInfo->au8Password, (uint8_t)strlen((char*)(pstrProvInfo->au8Password))};
  1351. m2m_wifi_connect_psk(WIFI_CRED_SAVE_ENCRYPTED, &strNetworkId, &strAuthPsk);
  1352. printf("PROV SSID : %s\n",pstrProvInfo->au8SSID);
  1353. printf("PROV PSK : %s\n",pstrProvInfo->au8Password);
  1354. }
  1355. else
  1356. {
  1357. printf("(ERR) Provisioning Failed\n");
  1358. }
  1359. }
  1360. break;
  1361. default:
  1362. break;
  1363. }
  1364. }
  1365. int main()
  1366. {
  1367. tstrWifiInitParam param;
  1368. param.pfAppWifiCb = wifi_event_cb;
  1369. if(!m2m_wifi_init(&param))
  1370. {
  1371. tstrM2MAPModeConfig apModeConfig;
  1372. uint8_t bEnableRedirect = 1;
  1373. strcpy(apModeConfig.au8SSID, "WINC_SSID");
  1374. apModeConfig.strApConfig.u8ListenChannel = 1;
  1375. apModeConfig.strApConfig.u8SecType = M2M_WIFI_SEC_OPEN;
  1376. apModeConfig.strApConfig.u8SsidHide = 0;
  1377. // IP Address
  1378. apModeConfig.strApConfig.au8DHCPServerIP[0] = 192;
  1379. apModeConfig.strApConfig.au8DHCPServerIP[1] = 168;
  1380. apModeConfig.strApConfig.au8DHCPServerIP[2] = 1;
  1381. apModeConfig.strApConfig.au8DHCPServerIP[3] = 1;
  1382. // Default router IP
  1383. memcpy(apModeConfig.strApConfigExt.au8DefRouterIP, apModeConfig.strApConfig.au8DHCPServerIP, 4);
  1384. // DNS Server IP
  1385. memcpy(apModeConfig.strApConfigExt.au8DNSServerIP, apModeConfig.strApConfig.au8DHCPServerIP, 4);
  1386. // Subnet mask
  1387. apModeConfig.strApConfigExt.au8SubnetMask[0] = 255;
  1388. apModeConfig.strApConfigExt.au8SubnetMask[1] = 255;
  1389. apModeConfig.strApConfigExt.au8SubnetMask[2] = 255;
  1390. apModeConfig.strApConfigExt.au8SubnetMask[3] = 0;
  1391. m2m_wifi_start_provision_mode_ext(&apModeConfig, "atmelwincconf.com", bEnableRedirect);
  1392. while(1)
  1393. {
  1394. m2m_wifi_handle_events(NULL);
  1395. }
  1396. }
  1397. }
  1398. @endcode
  1399. */
  1400. int8_t m2m_wifi_start_provision_mode_ext(tstrM2MAPModeConfig *pstrAPModeConfig, char *pcHttpServerDomainName, uint8_t bEnableHttpRedirect);
  1401. /*!
  1402. @ingroup WLANPROVISION
  1403. @fn \
  1404. int8_t m2m_wifi_stop_provision_mode(void);
  1405. @brief
  1406. Synchronous API for terminating provisioning mode on the WINC.
  1407. @details
  1408. This function will terminate any currently active provisioning mode on the WINC, returning the WINC to idle.
  1409. @pre
  1410. An active provisioning session must be active before it is terminated through this function.
  1411. @return
  1412. The function returns @ref M2M_SUCCESS for success and a negative value otherwise.
  1413. @see
  1414. m2m_wifi_start_provision_mode
  1415. */
  1416. int8_t m2m_wifi_stop_provision_mode(void);
  1417. /*!
  1418. @ingroup WLANCONNECT
  1419. @fn \
  1420. int8_t m2m_wifi_get_connection_info(void);
  1421. @brief
  1422. Asynchronous API for retrieving the WINC connection status.
  1423. @details
  1424. Requests the connection status from the WINC including information regarding any access
  1425. point to which it is currently connected, or any non-AP station that is connected to the WINC.
  1426. All information will be returned to the application via the Wi-Fi notification callback through
  1427. the event @ref M2M_WIFI_RESP_CONN_INFO.
  1428. The connection info can be retrieved using the structure @ref tstrM2MConnInfo which contains:
  1429. - Connection Security
  1430. - Connection RSSI
  1431. - Remote MAC address
  1432. - Remote IP address
  1433. - SSID of the network (in cases where the WINC is in non-AP mode)
  1434. @pre
  1435. - A Wi-Fi notification callback of type @ref tpfAppWifiCb MUST be implemented and registered at
  1436. startup. Registering the callback is done through passing it to the initialization
  1437. @ref m2m_wifi_init function.
  1438. - The event @ref M2M_WIFI_RESP_CONN_INFO must be handled in the callback to receive the
  1439. requested connection info.
  1440. @warning
  1441. - In case the WINC is operating in AP mode or P2P mode, the SSID field will be returned as a NULL string.
  1442. @return
  1443. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC and a negative value otherwise.
  1444. @see
  1445. M2M_WIFI_RESP_CONN_INFO,
  1446. tstrM2MConnInfo
  1447. @section WIFIExample2 Example
  1448. The code snippet shows an example of how wi-fi connection information is retrieved .
  1449. @code
  1450. #include "m2m_wifi.h"
  1451. #include "m2m_types.h"
  1452. void wifi_event_cb(uint8_t u8WiFiEvent, void * pvMsg)
  1453. {
  1454. switch(u8WiFiEvent)
  1455. {
  1456. case M2M_WIFI_RESP_CONN_INFO:
  1457. {
  1458. tstrM2MConnInfo *pstrConnInfo = (tstrM2MConnInfo*)pvMsg;
  1459. printf("CONNECTED AP INFO\n");
  1460. printf("SSID : %s\n",pstrConnInfo->acSSID);
  1461. printf("SEC TYPE : %d\n",pstrConnInfo->u8SecType);
  1462. printf("Signal Strength : %d\n", pstrConnInfo->s8RSSI);
  1463. printf("Local IP Address : %d.%d.%d.%d\n",
  1464. pstrConnInfo->au8IPAddr[0] , pstrConnInfo->au8IPAddr[1], pstrConnInfo->au8IPAddr[2], pstrConnInfo->au8IPAddr[3]);
  1465. }
  1466. break;
  1467. case M2M_WIFI_REQ_DHCP_CONF:
  1468. {
  1469. // Get the current AP information.
  1470. m2m_wifi_get_connection_info();
  1471. }
  1472. break;
  1473. default:
  1474. break;
  1475. }
  1476. }
  1477. int main()
  1478. {
  1479. tstrWifiInitParam param;
  1480. param.pfAppWifiCb = wifi_event_cb;
  1481. if(!m2m_wifi_init(&param))
  1482. {
  1483. // connect to the default AP
  1484. m2m_wifi_default_connect();
  1485. while(1)
  1486. {
  1487. m2m_wifi_handle_events(NULL);
  1488. }
  1489. }
  1490. }
  1491. @endcode
  1492. */
  1493. int8_t m2m_wifi_get_connection_info(void);
  1494. /*!
  1495. @ingroup WLANCONF
  1496. @fn \
  1497. int8_t m2m_wifi_set_mac_address(uint8_t au8MacAddress[6]);
  1498. @brief
  1499. Asynchronous API for assigning a MAC address to the WINC.
  1500. @details
  1501. This function is intended to allow non-production software to assign a MAC address to the WINC.
  1502. @warning
  1503. This function is intended for development use only and not for use in production software.
  1504. @param[in] au8MacAddress
  1505. MAC Address to be provisioned to the WINC.
  1506. @return
  1507. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC and a negative value otherwise.
  1508. */
  1509. int8_t m2m_wifi_set_mac_address(uint8_t au8MacAddress[6]);
  1510. /*!
  1511. @ingroup WLANWPS
  1512. @fn \
  1513. int8_t m2m_wifi_wps(uint8_t u8TriggerType,const char * pcPinNumber);
  1514. @brief
  1515. Asynchronous API to engage the WINC Wi-Fi Protected Setup (enrollee) function.
  1516. @details
  1517. This function can be called to make the WINC enter WPS (Wi-Fi Protected Setup) mode. The result
  1518. is passed to the Wi-Fi notification callback with the event @ref M2M_WIFI_REQ_WPS.
  1519. @param[in] u8TriggerType
  1520. WPS Trigger method. This may be:
  1521. - @ref WPS_PIN_TRIGGER Push button method
  1522. - @ref WPS_PBC_TRIGGER Pin method
  1523. @param[in] pcPinNumber
  1524. Valid only if the u8TriggerType is @ref WPS_PIN_TRIGGER, this parameter contains the PIN number.
  1525. The number must follow the format as given in the WSC1.0 specification.
  1526. @return
  1527. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC and a negative value otherwise.
  1528. @warning
  1529. This function is not allowed in AP or P2P modes.
  1530. @pre
  1531. - A Wi-Fi notification callback of type (@ref tpfAppWifiCb MUST be implemented and registered at
  1532. startup. Registering the callback is done through passing it to @ref m2m_wifi_init.
  1533. - The event @ref M2M_WIFI_REQ_WPS must be handled in the callback to receive the WPS status.
  1534. - The WINC device MUST be in IDLE or STA mode. If AP or P2P mode is active, the WPS will not be performed.
  1535. - The @ref m2m_wifi_handle_events MUST be called periodically to receive
  1536. the responses in the callback.
  1537. @see
  1538. tpfAppWifiCb
  1539. m2m_wifi_init
  1540. M2M_WIFI_REQ_WPS
  1541. tenuWPSTrigger
  1542. tstrM2MWPSInfo
  1543. @section WIFIExample3 Example
  1544. The code snippet shows an example of how wi-fi WPS is triggered .
  1545. @code
  1546. #include "m2m_wifi.h"
  1547. #include "m2m_types.h"
  1548. void wifi_event_cb(uint8_t u8WiFiEvent, void * pvMsg)
  1549. {
  1550. switch(u8WiFiEvent)
  1551. {
  1552. case M2M_WIFI_REQ_WPS:
  1553. {
  1554. tstrM2MWPSInfo *pstrWPS = (tstrM2MWPSInfo*)pvMsg;
  1555. if(pstrWPS->u8AuthType != 0)
  1556. {
  1557. // establish Wi-Fi connection
  1558. tstrNetworkId strNetworkId = {NULL, pstrWPS->au8SSID, (uint8_t)strlen((char*)(pstrWPS->au8SSID)), pstrWPS->u8Ch};
  1559. if(pstrWPS->u8AuthType == M2M_WIFI_SEC_OPEN)
  1560. {
  1561. m2m_wifi_connect_open(WIFI_CRED_SAVE_ENCRYPTED, &strNetworkId);
  1562. }
  1563. else
  1564. {
  1565. tstrAuthPsk strAuthPsk = {NULL, pstrWPS->au8PSK, (uint8_t)strlen((char*)(pstrWPS->au8PSK))};
  1566. m2m_wifi_connect_psk(WIFI_CRED_SAVE_ENCRYPTED, &strNetworkId, &strAuthPsk);
  1567. }
  1568. printf("WPS SSID : %s\n",pstrWPS->au8SSID);
  1569. printf("WPS PSK : %s\n",pstrWPS->au8PSK);
  1570. printf("WPS SSID Auth Type : %s\n",pstrWPS->u8AuthType == M2M_WIFI_SEC_OPEN ? "OPEN" : "WPA/WPA2");
  1571. printf("WPS Channel : %d\n",pstrWPS->u8Ch);
  1572. }
  1573. else
  1574. {
  1575. printf("(ERR) WPS Is not enabled OR Timed out\n");
  1576. }
  1577. }
  1578. break;
  1579. default:
  1580. break;
  1581. }
  1582. }
  1583. int main()
  1584. {
  1585. tstrWifiInitParam param;
  1586. param.pfAppWifiCb = wifi_event_cb;
  1587. if(!m2m_wifi_init(&param))
  1588. {
  1589. // Trigger WPS in Push button mode.
  1590. m2m_wifi_wps(WPS_PBC_TRIGGER, NULL);
  1591. while(1)
  1592. {
  1593. m2m_wifi_handle_events(NULL);
  1594. }
  1595. }
  1596. }
  1597. @endcode
  1598. */
  1599. int8_t m2m_wifi_wps(uint8_t u8TriggerType, const char *pcPinNumber);
  1600. /*!
  1601. @ingroup WLANWPS
  1602. @fn \
  1603. int8_t m2m_wifi_wps_disable(void);
  1604. @brief
  1605. Asynchronous API that disables Wi-Fi Protected Setup mode in the WINC.
  1606. @pre
  1607. WINC should be already in WPS mode using @ref m2m_wifi_wps.
  1608. @return
  1609. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC and a negative value otherwise.
  1610. @see
  1611. m2m_wifi_wps
  1612. */
  1613. int8_t m2m_wifi_wps_disable(void);
  1614. /**@cond P2P_DOC
  1615. */
  1616. /*!
  1617. @ingroup WLANP2P
  1618. @fn \
  1619. int8_t m2m_wifi_p2p(uint8_t u8Channel);
  1620. @brief
  1621. Asynchronous API for enabling Wi-Fi Direct (P2P) mode in the WINC.
  1622. @param[in] u8Channel
  1623. P2P Listen RF channel. According to the P2P standard, it must hold only one of the following values 1, 6 or 11.
  1624. @pre
  1625. - A Wi-Fi notification callback of type @ref tpfAppWifiCb MUST be implemented and registered at
  1626. initialization. Registering the callback is done through passing it to the @ref m2m_wifi_init.
  1627. - The events @ref M2M_WIFI_RESP_CON_STATE_CHANGED and @ref M2M_WIFI_REQ_DHCP_CONF must be handled in the callback.
  1628. - The @ref m2m_wifi_handle_events MUST be called to receive the responses in the callback.
  1629. @warning
  1630. - This function is not available in the WINC 3400
  1631. - This function is not allowed in AP or STA modes.
  1632. @return
  1633. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC and a negative value otherwise.
  1634. @see
  1635. tpfAppWifiCb
  1636. m2m_wifi_init
  1637. M2M_WIFI_RESP_CON_STATE_CHANGED
  1638. M2M_WIFI_REQ_DHCP_CONF
  1639. tstrM2mWifiStateChanged
  1640. @section WIFIExample4 Example
  1641. The code snippet shows an example of how the p2p mode operates.
  1642. @code
  1643. #include "m2m_wifi.h"
  1644. #include "m2m_types.h"
  1645. void wifi_event_cb(uint8_t u8WiFiEvent, void * pvMsg)
  1646. {
  1647. switch(u8WiFiEvent)
  1648. {
  1649. case M2M_WIFI_RESP_CON_STATE_CHANGED:
  1650. {
  1651. tstrM2mWifiStateChanged *pstrWifiState = (tstrM2mWifiStateChanged*)pvMsg;
  1652. M2M_INFO("Wifi State :: %s :: ErrCode %d\n", pstrWifiState->u8CurrState? "CONNECTED":"DISCONNECTED",pstrWifiState->u8ErrCode);
  1653. // Do something
  1654. }
  1655. break;
  1656. case M2M_WIFI_REQ_DHCP_CONF:
  1657. {
  1658. uint8_t *pu8IPAddress = (uint8_t*)pvMsg;
  1659. printf("P2P IP Address \"%u.%u.%u.%u\"\n",pu8IPAddress[0],pu8IPAddress[1],pu8IPAddress[2],pu8IPAddress[3]);
  1660. }
  1661. break;
  1662. default:
  1663. break;
  1664. }
  1665. }
  1666. int main()
  1667. {
  1668. tstrWifiInitParam param;
  1669. param.pfAppWifiCb = wifi_event_cb;
  1670. if(!m2m_wifi_init(&param))
  1671. {
  1672. // Trigger P2P
  1673. m2m_wifi_p2p(M2M_WIFI_CH_1);
  1674. while(1)
  1675. {
  1676. m2m_wifi_handle_events(NULL);
  1677. }
  1678. }
  1679. }
  1680. @endcode
  1681. */
  1682. int8_t m2m_wifi_p2p(uint8_t u8Channel);
  1683. /*!
  1684. @ingroup WLANP2P
  1685. @fn \
  1686. int8_t m2m_wifi_p2p_disconnect(void);
  1687. @brief
  1688. Synchronous API to disable Wi-Fi Direct (P2P) Mode on the WINC.
  1689. @pre
  1690. The p2p mode must be enabled and active before a disconnect can be called.
  1691. @return
  1692. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC and a negative value otherwise.
  1693. @see
  1694. m2m_wifi_p2p
  1695. */
  1696. int8_t m2m_wifi_p2p_disconnect(void);
  1697. /**@endcond*/ //P2P_DOC
  1698. /*!
  1699. @ingroup WLANAP
  1700. @fn \
  1701. int8_t m2m_wifi_enable_ap(const tstrM2MAPConfig* pstrM2MAPConfig);
  1702. @brief
  1703. Asynchronous API to enable access point (AKA "hot-spot") mode on the WINC.
  1704. @details
  1705. The WINC supports the ability to operate as an access point with the following limitations:
  1706. - Only 1 station may be associated at any given time.
  1707. - Open system and WEP are the only security suites supported.
  1708. @param[in] pstrM2MAPConfig
  1709. A structure holding the AP configurations.
  1710. @return
  1711. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC and a negative value otherwise.
  1712. @warning
  1713. This function is not allowed in P2P or STA modes.
  1714. @pre
  1715. - A Wi-Fi notification callback of type @ref tpfAppWifiCb MUST be implemented and registered at initialization. Registering the callback
  1716. is done through passing it to the @ref m2m_wifi_init.
  1717. - The event @ref M2M_WIFI_REQ_DHCP_CONF must be handled in the callback.
  1718. - The @ref m2m_wifi_handle_events MUST be called to receive the responses in the callback.
  1719. @see
  1720. tpfAppWifiCb
  1721. tenuM2mSecType
  1722. m2m_wifi_init
  1723. M2M_WIFI_REQ_DHCP_CONF
  1724. tstrM2mWifiStateChanged
  1725. tstrM2MAPConfig
  1726. @section WIFIExample5 Example
  1727. The code snippet demonstrates how the AP mode is enabled after the driver is initialized in the application's main function and the handling
  1728. of the event @ref M2M_WIFI_REQ_DHCP_CONF, to indicate successful connection.
  1729. @code
  1730. #include "m2m_wifi.h"
  1731. #include "m2m_types.h"
  1732. void wifi_event_cb(uint8_t u8WiFiEvent, void * pvMsg)
  1733. {
  1734. switch(u8WiFiEvent)
  1735. {
  1736. case M2M_WIFI_REQ_DHCP_CONF:
  1737. {
  1738. uint8_t *pu8IPAddress = (uint8_t*)pvMsg;
  1739. printf("Associated STA has IP Address \"%u.%u.%u.%u\"\n",pu8IPAddress[0],pu8IPAddress[1],pu8IPAddress[2],pu8IPAddress[3]);
  1740. }
  1741. break;
  1742. default:
  1743. break;
  1744. }
  1745. }
  1746. int main()
  1747. {
  1748. tstrWifiInitParam param;
  1749. param.pfAppWifiCb = wifi_event_cb;
  1750. if(!m2m_wifi_init(&param))
  1751. {
  1752. tstrM2MAPConfig apConfig;
  1753. strcpy(apConfig.au8SSID, "WINC_SSID");
  1754. apConfig.u8ListenChannel = 1;
  1755. apConfig.u8SecType = M2M_WIFI_SEC_OPEN;
  1756. apConfig.u8SsidHide = 0;
  1757. // IP Address
  1758. apConfig.au8DHCPServerIP[0] = 192;
  1759. apConfig.au8DHCPServerIP[1] = 168;
  1760. apConfig.au8DHCPServerIP[2] = 1;
  1761. apConfig.au8DHCPServerIP[3] = 1;
  1762. // Trigger AP
  1763. m2m_wifi_enable_ap(&apConfig);
  1764. while(1)
  1765. {
  1766. m2m_wifi_handle_events(NULL);
  1767. }
  1768. }
  1769. }
  1770. @endcode
  1771. */
  1772. int8_t m2m_wifi_enable_ap(const tstrM2MAPConfig *pstrM2MAPConfig);
  1773. /*!
  1774. @ingroup WLANAP
  1775. @fn \
  1776. int8_t m2m_wifi_enable_ap_ext(const tstrM2MAPModeConfig *pstrM2MAPModeConfig);
  1777. @brief
  1778. Asynchronous API to enable access point (AKA "hot-spot") mode on the WINC with extended options.
  1779. @details
  1780. The WINC supports the ability to operate as an access point with the following limitations:
  1781. - Only 1 station may be associated at any given time.
  1782. - Open system and WEP are the only security suites supported.
  1783. @param[in] pstrM2MAPModeConfig
  1784. A structure holding the AP configurations.
  1785. @return
  1786. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC and a negative value otherwise.
  1787. @warning
  1788. This function is not allowed in P2P or STA modes.
  1789. @pre
  1790. - A Wi-Fi notification callback of type @ref tpfAppWifiCb MUST be implemented and registered at initialization. Registering the callback
  1791. is done through passing it to the @ref m2m_wifi_init.
  1792. - The event @ref M2M_WIFI_REQ_DHCP_CONF must be handled in the callback.
  1793. - The @ref m2m_wifi_handle_events MUST be called to receive the responses in the callback.
  1794. @see
  1795. tpfAppWifiCb
  1796. tenuM2mSecType
  1797. m2m_wifi_init
  1798. M2M_WIFI_REQ_DHCP_CONF
  1799. tstrM2mWifiStateChanged
  1800. tstrM2MAPModeConfig
  1801. @section WIFIExample13 Example
  1802. The code snippet demonstrates how the AP mode is enabled after the driver is initialized in the application's main function and the handling
  1803. of the event @ref M2M_WIFI_REQ_DHCP_CONF, to indicate successful connection.
  1804. @code
  1805. #include "m2m_wifi.h"
  1806. #include "m2m_types.h"
  1807. void wifi_event_cb(uint8_t u8WiFiEvent, void * pvMsg)
  1808. {
  1809. switch(u8WiFiEvent)
  1810. {
  1811. case M2M_WIFI_REQ_DHCP_CONF:
  1812. {
  1813. uint8_t *pu8IPAddress = (uint8_t*)pvMsg;
  1814. printf("Associated STA has IP Address \"%u.%u.%u.%u\"\n",pu8IPAddress[0],pu8IPAddress[1],pu8IPAddress[2],pu8IPAddress[3]);
  1815. }
  1816. break;
  1817. default:
  1818. break;
  1819. }
  1820. }
  1821. int main()
  1822. {
  1823. tstrWifiInitParam param;
  1824. param.pfAppWifiCb = wifi_event_cb;
  1825. if(!m2m_wifi_init(&param))
  1826. {
  1827. tstrM2MAPModeConfig apModeConfig;
  1828. strcpy(apModeConfig.strApConfig.au8SSID, "WINC_SSID");
  1829. apModeConfig.strApConfig.u8ListenChannel = 1;
  1830. apModeConfig.strApConfig.u8SecType = M2M_WIFI_SEC_OPEN;
  1831. apModeConfig.strApConfig.u8SsidHide = 0;
  1832. // IP Address
  1833. apModeConfig.strApConfig.au8DHCPServerIP[0] = 192;
  1834. apModeConfig.strApConfig.au8DHCPServerIP[1] = 168;
  1835. apModeConfig.strApConfig.au8DHCPServerIP[2] = 1;
  1836. apModeConfig.strApConfig.au8DHCPServerIP[3] = 1;
  1837. // Default router IP
  1838. memcpy(apModeConfig.strApConfigExt.au8DefRouterIP, apModeConfig.strApConfig.au8DHCPServerIP, 4);
  1839. // DNS Server IP
  1840. memcpy(apModeConfig.strApConfigExt.au8DNSServerIP, apModeConfig.strApConfig.au8DHCPServerIP, 4);
  1841. // Subnet mask
  1842. apModeConfig.strApConfigExt.au8SubnetMask[0] = 255;
  1843. apModeConfig.strApConfigExt.au8SubnetMask[1] = 255;
  1844. apModeConfig.strApConfigExt.au8SubnetMask[2] = 255;
  1845. apModeConfig.strApConfigExt.au8SubnetMask[3] = 0;
  1846. // Trigger AP
  1847. m2m_wifi_enable_ap_ext(&apModeConfig);
  1848. while(1)
  1849. {
  1850. m2m_wifi_handle_events(NULL);
  1851. }
  1852. }
  1853. }
  1854. @endcode
  1855. */
  1856. int8_t m2m_wifi_enable_ap_ext(const tstrM2MAPModeConfig *pstrM2MAPModeConfig);
  1857. /*!
  1858. @ingroup WLANAP
  1859. @fn \
  1860. int8_t m2m_wifi_disable_ap(void);
  1861. @brief
  1862. Synchronous API to disable access point mode on the WINC.
  1863. @details
  1864. Must be called only when the AP is enabled through the @ref m2m_wifi_enable_ap
  1865. function. Otherwise the call to this function will not be useful.
  1866. @return
  1867. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC and a negative value otherwise.
  1868. @see
  1869. m2m_wifi_enable_ap
  1870. */
  1871. int8_t m2m_wifi_disable_ap(void);
  1872. /*!
  1873. @ingroup WLANCONNECT
  1874. @fn \
  1875. int8_t m2m_wifi_set_static_ip(tstrM2MIPConfig * pstrStaticIPConf);
  1876. @brief
  1877. Asynchronous API to manually assign a (static) IP address to the WINC.
  1878. @details
  1879. Assigns a static IP address to the WINC.
  1880. Typically an infrastructure access point will be able to provide an IP address to all clients
  1881. after they associate. The WINC will request configuration via DHCP automatically after
  1882. successfully connecting to an access point.
  1883. This function should only be called in the event that the network has no DHCP server or in case the application
  1884. wants to assign a predefined known IP address and the application.
  1885. This function can be used to assign a static IP address in case the application knows the specifics of the network.
  1886. The user must keep in mind that assigning a static IP address might
  1887. result in an IP address conflict. In case of an IP address conflict observed
  1888. by the WINC the user will get a response of @ref M2M_WIFI_RESP_IP_CONFLICT
  1889. in the wifi callback. The application is then responsible to either solve the
  1890. conflict or assign another IP address.
  1891. @pre
  1892. The application must first call @ref m2m_wifi_enable_dhcp to request that DHCP functionality is
  1893. disabled prior to calling this function.
  1894. @warning
  1895. Exercise caution using this function.
  1896. DHCP is the preferred method for configuring IP addresses.
  1897. @param[in] pstrStaticIPConf
  1898. Pointer to a structure holding the static IP configuration (IP, Gateway, subnet mask and DNS address).
  1899. @return
  1900. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC and a negative value otherwise.
  1901. @see
  1902. tstrM2MIPConfig
  1903. */
  1904. int8_t m2m_wifi_set_static_ip(tstrM2MIPConfig *pstrStaticIPConf);
  1905. /*!
  1906. @ingroup WLANCONNECT
  1907. @fn \
  1908. int8_t m2m_wifi_request_dhcp_client(void);
  1909. @brief
  1910. Legacy (deprecated) Asynchronous API for starting a DHCP client on the WINC.
  1911. @details
  1912. This is a legacy API and is no longer supported. Calls to this API will not result in any
  1913. changes being made to the state of the WINC.
  1914. @warning
  1915. This function has been deprecated. DHCP is used automatically when the WINC connects.
  1916. @return
  1917. This function always returns @ref M2M_SUCCESS.
  1918. */
  1919. int8_t m2m_wifi_request_dhcp_client(void);
  1920. /*!
  1921. @ingroup WLANCONNECT
  1922. @fn \
  1923. int8_t m2m_wifi_request_dhcp_server(uint8_t* addr);
  1924. @brief
  1925. Legacy (deprecated) asynchronous function to start a DHCP client on the WINC.
  1926. @details
  1927. This is a legacy API and is no longer supported. Calls to this API will not result in any
  1928. changes being made to the state of the WINC.
  1929. @param[in] addr
  1930. The address to issue to a connected client (only one client is supported)
  1931. @warning
  1932. This function is legacy and exists only for compatibility with older applications.
  1933. DHCP server is started automatically when enabling the AP mode.
  1934. @return
  1935. This function always returns @ref M2M_SUCCESS.
  1936. */
  1937. int8_t m2m_wifi_request_dhcp_server(uint8_t *addr);
  1938. /*!
  1939. @ingroup WLANCONNECT
  1940. @fn \
  1941. int8_t m2m_wifi_enable_dhcp(uint8_t u8DhcpEn);
  1942. @brief
  1943. Asynchronous function to control the DHCP client functionality within the WINC.
  1944. @details
  1945. This function allows the application to control the behaviour of the DHCP client function within
  1946. the WINC once it has associated with an access point. DHCP client functionality is enabled by
  1947. default.
  1948. @param[in] u8DhcpEn
  1949. The state of the DHCP client feature after successful association with an access point:
  1950. - 1: Enables DHCP client after connection.
  1951. - 0: Disables DHCP client after connection.
  1952. @return
  1953. The function returns @ref M2M_SUCCESS for successful operation and a negative value otherwise.
  1954. @warning
  1955. DHCP client is enabled by default.
  1956. This Function should be called to disable DHCP client operation before using @ref m2m_wifi_set_static_ip.
  1957. @see
  1958. m2m_wifi_set_static_ip
  1959. */
  1960. int8_t m2m_wifi_enable_dhcp(uint8_t u8DhcpEn);
  1961. /*!
  1962. @ingroup WLANSCAN
  1963. @fn \
  1964. int8_t m2m_wifi_set_scan_options(tstrM2MScanOption* ptstrM2MScanOption);
  1965. @brief
  1966. Synchronous API for configuring the behaviour of the WINC network scanning functions.
  1967. @details
  1968. This function allows the application to tune the scanning behaviour of the WINC using the
  1969. parameters described in @ref tstrM2MScanOption.
  1970. @param[in] ptstrM2MScanOption;
  1971. Pointer to the structure holding the Scan Parameters.
  1972. @return
  1973. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC and a negative value otherwise.
  1974. @see
  1975. tenuM2mScanCh
  1976. m2m_wifi_request_scan
  1977. tstrM2MScanOption
  1978. */
  1979. int8_t m2m_wifi_set_scan_options(tstrM2MScanOption *ptstrM2MScanOption);
  1980. /*!
  1981. @ingroup WLANSCAN
  1982. @fn \
  1983. int8_t m2m_wifi_set_stop_scan_on_first(uint8_t u8StopScanOption);
  1984. @brief
  1985. Synchronous API for enabling/disabling the stop scan on first result of the WINC IC's network scanning functions.
  1986. @details
  1987. Allows for enabling/disabling of stop scan on first result. When enabled, the WINC will stop the scan as soon as
  1988. it detects a network and return the results to the host. Setting is persistent and will need to be explicitly
  1989. reverted back by the application if it no longer wishes for it to be enabled.
  1990. @param[in] u8StopScanOption;
  1991. Setting for enabling or disabling Stopping Scan on first result.
  1992. 1 = Enabled, 0 = Disabled (Default)
  1993. @return
  1994. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC and a negative value otherwise.
  1995. @see
  1996. tenuM2mScanCh
  1997. tstrM2MScanOption
  1998. tstrM2MStopScanOption
  1999. m2m_wifi_request_scan
  2000. m2m_wifi_set_scan_options
  2001. */
  2002. int8_t m2m_wifi_set_stop_scan_on_first(uint8_t u8StopScanOption);
  2003. /*!
  2004. @ingroup WLANSCAN
  2005. @fn \
  2006. int8_t m2m_wifi_set_scan_region(uint16_t ScanRegion);
  2007. @brief
  2008. Synchronous API for configuring the regulatory restrictions that may affect the WINC scanning behaviour.
  2009. @details
  2010. This function sets a property called the scan region, a parameter that affects the range of
  2011. channels that the WINC may legally scan given a geographic region.
  2012. For 2.4GHz, supported in the current release, the requested scan region cannot exceed the
  2013. maximum number of channels (14).
  2014. @param[in] ScanRegion
  2015. @ref ASIA
  2016. @ref EUROPE
  2017. @ref NORTH_AMERICA
  2018. @return
  2019. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC and a negative value otherwise.
  2020. @see
  2021. tenuM2mScanRegion
  2022. m2m_wifi_request_scan
  2023. */
  2024. int8_t m2m_wifi_set_scan_region(uint16_t ScanRegion);
  2025. /*!
  2026. @ingroup WLANSCAN
  2027. @fn \
  2028. int8_t m2m_wifi_request_scan(uint8_t ch);
  2029. @brief
  2030. Asynchronous API to request the WINC to scan for networks.
  2031. @details
  2032. Scan statuses are delivered to the application via the Wi-Fi event callback (@ref tpfAppWifiCb) in
  2033. three stages. The first step involves the event @ref M2M_WIFI_RESP_SCAN_DONE which, if successful,
  2034. provides the number of detected networks (access points). The application must then read the list
  2035. of access points via multiple calls to the asynchronous @ref m2m_wifi_req_scan_result API. For
  2036. each call to this function, the application will receive (step three) the event
  2037. @ref M2M_WIFI_RESP_SCAN_RESULT.
  2038. @param[in] ch
  2039. RF Channel ID for SCAN operation. It should be set according to @ref tenuM2mScanCh, with a
  2040. value of @ref M2M_WIFI_CH_ALL to scan all channels.
  2041. @return
  2042. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC and a negative value otherwise.
  2043. @pre
  2044. - A Wi-Fi notification callback of type @ref tpfAppWifiCb MUST be implemented and registered at
  2045. initialization. Registration of the callback is done via @ref m2m_wifi_init.
  2046. - The events @ref M2M_WIFI_RESP_SCAN_DONE and @ref M2M_WIFI_RESP_SCAN_RESULT must be handled in
  2047. the (@ref tpfAppWifiCb) callback.
  2048. - The @ref m2m_wifi_handle_events function MUST be called to receive the responses in the
  2049. callback.
  2050. @warning
  2051. This API is valid only for STA mode, it may be called regardless of connection state (connected or disconnected states).
  2052. @see
  2053. M2M_WIFI_RESP_SCAN_DONE
  2054. M2M_WIFI_RESP_SCAN_RESULT
  2055. tpfAppWifiCb
  2056. tstrM2mWifiscanResult
  2057. tenuM2mScanCh
  2058. m2m_wifi_init
  2059. m2m_wifi_handle_events
  2060. m2m_wifi_req_scan_result
  2061. @section WIFIExample6 Example
  2062. The code snippet demonstrates an example of how the scan request is called from the application's main function and the handling of
  2063. the events received in response.
  2064. @code
  2065. #include "m2m_wifi.h"
  2066. #include "m2m_types.h"
  2067. void wifi_event_cb(uint8_t u8WiFiEvent, void * pvMsg)
  2068. {
  2069. static uint8_t u8ScanResultIdx = 0;
  2070. switch(u8WiFiEvent)
  2071. {
  2072. case M2M_WIFI_RESP_SCAN_DONE:
  2073. {
  2074. tstrM2mScanDone *pstrInfo = (tstrM2mScanDone*)pvMsg;
  2075. printf("Num of AP found %d\n",pstrInfo->u8NumofCh);
  2076. if(pstrInfo->s8ScanState == M2M_SUCCESS)
  2077. {
  2078. u8ScanResultIdx = 0;
  2079. if(pstrInfo->u8NumofCh >= 1)
  2080. {
  2081. m2m_wifi_req_scan_result(u8ScanResultIdx);
  2082. u8ScanResultIdx ++;
  2083. }
  2084. else
  2085. {
  2086. printf("No AP Found Rescan\n");
  2087. m2m_wifi_request_scan(M2M_WIFI_CH_ALL);
  2088. }
  2089. }
  2090. else
  2091. {
  2092. printf("(ERR) Scan fail with error <%d>\n",pstrInfo->s8ScanState);
  2093. }
  2094. }
  2095. break;
  2096. case M2M_WIFI_RESP_SCAN_RESULT:
  2097. {
  2098. tstrM2mWifiscanResult *pstrScanResult = (tstrM2mWifiscanResult*)pvMsg;
  2099. uint8_t u8NumFoundAPs = m2m_wifi_get_num_ap_found();
  2100. printf(">>%02d RI %d SEC %s CH %02d BSSID %02X:%02X:%02X:%02X:%02X:%02X SSID %s\n",
  2101. pstrScanResult->u8index,pstrScanResult->s8rssi,
  2102. pstrScanResult->u8AuthType,
  2103. pstrScanResult->u8ch,
  2104. pstrScanResult->au8BSSID[0], pstrScanResult->au8BSSID[1], pstrScanResult->au8BSSID[2],
  2105. pstrScanResult->au8BSSID[3], pstrScanResult->au8BSSID[4], pstrScanResult->au8BSSID[5],
  2106. pstrScanResult->au8SSID);
  2107. if(u8ScanResultIdx < u8NumFoundAPs)
  2108. {
  2109. // Read the next scan result
  2110. m2m_wifi_req_scan_result(index);
  2111. u8ScanResultIdx ++;
  2112. }
  2113. }
  2114. break;
  2115. default:
  2116. break;
  2117. }
  2118. }
  2119. int main()
  2120. {
  2121. tstrWifiInitParam param;
  2122. param.pfAppWifiCb = wifi_event_cb;
  2123. if(!m2m_wifi_init(&param))
  2124. {
  2125. // Scan all channels
  2126. m2m_wifi_request_scan(M2M_WIFI_CH_ALL);
  2127. while(1)
  2128. {
  2129. m2m_wifi_handle_events(NULL);
  2130. }
  2131. }
  2132. }
  2133. @endcode
  2134. */
  2135. int8_t m2m_wifi_request_scan(uint8_t ch);
  2136. /*!
  2137. @ingroup WLANSCAN
  2138. @fn \
  2139. int8_t m2m_wifi_request_scan_passive(uint8_t ch);
  2140. @brief
  2141. Similar to @ref m2m_wifi_request_scan but performs passive scanning instead of active scanning.
  2142. @param[in] ch
  2143. RF Channel ID for SCAN operation. It should be set according to @ref tenuM2mScanCh.
  2144. With a value of @ref M2M_WIFI_CH_ALL, means to scan all channels.
  2145. @warning
  2146. This function is not allowed in P2P or AP modes. It works only for STA mode (both connected or disconnected states).
  2147. @pre
  2148. - A Wi-Fi notification callback of type @ref tpfAppWifiCb MUST be implemented and registered at initialization. Registering the callback
  2149. is done through passing it to the @ref m2m_wifi_init.
  2150. - The events @ref M2M_WIFI_RESP_SCAN_DONE and @ref M2M_WIFI_RESP_SCAN_RESULT.
  2151. must be handled in the callback.
  2152. - The @ref m2m_wifi_handle_events function MUST be called to receive the responses in the callback.
  2153. @see
  2154. M2M_WIFI_RESP_SCAN_DONE
  2155. M2M_WIFI_RESP_SCAN_RESULT
  2156. tpfAppWifiCb
  2157. tstrM2MScanOption
  2158. tstrM2mWifiscanResult
  2159. tenuM2mScanCh
  2160. m2m_wifi_init
  2161. m2m_wifi_request_scan
  2162. m2m_wifi_handle_events
  2163. m2m_wifi_req_scan_result
  2164. @return
  2165. The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  2166. */
  2167. int8_t m2m_wifi_request_scan_passive(uint8_t ch);
  2168. /*!
  2169. @ingroup WLANSCAN
  2170. @fn \
  2171. int8_t m2m_wifi_request_scan_ssid_list(uint8_t ch, uint8_t *u8SsidList);
  2172. @brief
  2173. Asynchronous wi-fi scan request on the given channel and the hidden scan list.
  2174. @details
  2175. The scan status is delivered in the wi-fi event callback and then the application
  2176. is to read the scan results sequentially.
  2177. The number of APs found (N) is returned in event @ref M2M_WIFI_RESP_SCAN_DONE with the number of found
  2178. APs.
  2179. The application could read the list of APs by calling the function @ref m2m_wifi_req_scan_result N times.
  2180. @param[in] ch
  2181. RF Channel ID for SCAN operation. It should be set according to @ref tenuM2mScanCh.
  2182. With a value of @ref M2M_WIFI_CH_ALL, means to scan all channels.
  2183. @param[in] u8SsidList
  2184. u8SsidList is a buffer containing a list of hidden SSIDs to
  2185. include during the scan. The first byte in the buffer, u8SsidList[0],
  2186. is the number of SSIDs encoded in the string. The number of hidden SSIDs
  2187. cannot exceed @ref MAX_HIDDEN_SITES. All SSIDs are concatenated in the following
  2188. bytes and each SSID is prefixed with a one-byte header containing its length.
  2189. The total number of bytes in u8SsidList buffer, including length byte, cannot
  2190. exceed 133 bytes (MAX_HIDDEN_SITES SSIDs x 32 bytes each, which is max SSID length).
  2191. For instance, encoding the two hidden SSIDs "DEMO_AP" and "TEST"
  2192. results in the following buffer content:
  2193. @code
  2194. uint8_t u8SsidList[14];
  2195. u8SsidList[0] = 2; // Number of SSIDs is 2
  2196. u8SsidList[1] = 7; // Length of the string "DEMO_AP" without NULL termination
  2197. memcpy(&u8SsidList[2], "DEMO_AP", 7); // Bytes index 2-9 containing the string DEMO_AP
  2198. u8SsidList[9] = 4; // Length of the string "TEST" without NULL termination
  2199. memcpy(&u8SsidList[10], "TEST", 4); // Bytes index 10-13 containing the string TEST
  2200. @endcode
  2201. @note
  2202. It works with STA/AP mode (connected or disconnected).
  2203. @pre
  2204. - A Wi-Fi notification callback of type @ref tpfAppWifiCb MUST be implemented and registered at initialization. Registering the callback
  2205. is done through passing it to the @ref m2m_wifi_init.
  2206. - The events @ref M2M_WIFI_RESP_SCAN_DONE and @ref M2M_WIFI_RESP_SCAN_RESULT.
  2207. must be handled in the callback.
  2208. - The @ref m2m_wifi_handle_events function MUST be called to receive the responses in the callback.
  2209. @see
  2210. M2M_WIFI_RESP_SCAN_DONE
  2211. M2M_WIFI_RESP_SCAN_RESULT
  2212. tpfAppWifiCb
  2213. tstrM2mWifiscanResult
  2214. tenuM2mScanCh
  2215. m2m_wifi_init
  2216. m2m_wifi_handle_events
  2217. m2m_wifi_req_scan_result
  2218. @return
  2219. The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  2220. \section WIFIExample6b Example
  2221. The code snippet demonstrates an example of how the scan request is called from the application's main function and the handling of
  2222. the events received in response.
  2223. @code
  2224. #include "m2m_wifi.h"
  2225. #include "m2m_types.h"
  2226. static void request_scan_hidden_demo_ap(void);
  2227. void wifi_event_cb(uint8_t u8WiFiEvent, void * pvMsg)
  2228. {
  2229. static uint8_t u8ScanResultIdx = 0;
  2230. switch(u8WiFiEvent)
  2231. {
  2232. case M2M_WIFI_RESP_SCAN_DONE:
  2233. {
  2234. tstrM2mScanDone *pstrInfo = (tstrM2mScanDone*)pvMsg;
  2235. printf("Num of AP found %d\n",pstrInfo->u8NumofCh);
  2236. if(pstrInfo->s8ScanState == M2M_SUCCESS)
  2237. {
  2238. u8ScanResultIdx = 0;
  2239. if(pstrInfo->u8NumofCh >= 1)
  2240. {
  2241. m2m_wifi_req_scan_result(u8ScanResultIdx);
  2242. u8ScanResultIdx ++;
  2243. }
  2244. else
  2245. {
  2246. printf("No AP Found Rescan\n");
  2247. request_scan_hidden_demo_ap();
  2248. }
  2249. }
  2250. else
  2251. {
  2252. printf("(ERR) Scan fail with error <%d>\n",pstrInfo->s8ScanState);
  2253. }
  2254. }
  2255. break;
  2256. case M2M_WIFI_RESP_SCAN_RESULT:
  2257. {
  2258. tstrM2mWifiscanResult *pstrScanResult =(tstrM2mWifiscanResult*)pvMsg;
  2259. uint8_t u8NumFoundAPs = m2m_wifi_get_num_ap_found();
  2260. printf(">>%02d RI %d SEC %s CH %02d BSSID %02X:%02X:%02X:%02X:%02X:%02X SSID %s\n",
  2261. pstrScanResult->u8index,pstrScanResult->s8rssi,
  2262. pstrScanResult->u8AuthType,
  2263. pstrScanResult->u8ch,
  2264. pstrScanResult->au8BSSID[0], pstrScanResult->au8BSSID[1], pstrScanResult->au8BSSID[2],
  2265. pstrScanResult->au8BSSID[3], pstrScanResult->au8BSSID[4], pstrScanResult->au8BSSID[5],
  2266. pstrScanResult->au8SSID);
  2267. if(u8ScanResultIdx < u8NumFoundAPs)
  2268. {
  2269. // Read the next scan result
  2270. m2m_wifi_req_scan_result(index);
  2271. u8ScanResultIdx ++;
  2272. }
  2273. }
  2274. break;
  2275. default:
  2276. break;
  2277. }
  2278. }
  2279. static void request_scan_hidden_demo_ap(void)
  2280. {
  2281. uint8_t list[9];
  2282. char ssid[] = "DEMO_AP";
  2283. uint8 len = (uint8_t)(sizeof(ssid)-1);
  2284. list[0] = 1;
  2285. list[1] = len;
  2286. memcpy(&list[2], ssid, len); // copy 7 bytes
  2287. // Scan all channels
  2288. m2m_wifi_request_scan_ssid_list(M2M_WIFI_CH_ALL, list);
  2289. }
  2290. int main()
  2291. {
  2292. tstrWifiInitParam param;
  2293. param.pfAppWifiCb = wifi_event_cb;
  2294. if(!m2m_wifi_init(&param))
  2295. {
  2296. request_scan_hidden_demo_ap();
  2297. while(1)
  2298. {
  2299. m2m_wifi_handle_events(NULL);
  2300. }
  2301. }
  2302. }
  2303. @endcode
  2304. */
  2305. int8_t m2m_wifi_request_scan_ssid_list(uint8_t ch, uint8_t *u8Ssidlist);
  2306. /*!
  2307. @ingroup WLANSCAN
  2308. @fn \
  2309. uint8_t m2m_wifi_get_num_ap_found(void);
  2310. @brief
  2311. Synchronous function to retrieve the number of AP's found during the last scan operation.
  2312. @details
  2313. This function allows the application to recover the number of access points discovered during
  2314. the most recent scan activity. This is achieved via a global variable in the WINC driver that
  2315. is populated when receiving the @ref M2M_WIFI_RESP_SCAN_DONE event.
  2316. Function to be used in STA mode only.
  2317. @see
  2318. m2m_wifi_request_scan
  2319. M2M_WIFI_RESP_SCAN_DONE
  2320. M2M_WIFI_RESP_SCAN_RESULT
  2321. @pre
  2322. m2m_wifi_request_scan must be called first to ensure up to date results are available.
  2323. - A Wi-Fi notification callback of type @ref tpfAppWifiCb MUST be implemented and registered at initialization. Registering the callback
  2324. is done through passing it to the @ref m2m_wifi_init.
  2325. - The event @ref M2M_WIFI_RESP_SCAN_DONE must be handled in the callback to receive the requested scan information.
  2326. @warning
  2327. This function must be called only in the wi-fi callback function when the events
  2328. @ref M2M_WIFI_RESP_SCAN_DONE or @ref M2M_WIFI_RESP_SCAN_RESULT are received.
  2329. Calling this function in any other place will result in undefined/outdated numbers.
  2330. @return
  2331. Returns the number of AP's found in the last Scan Request.
  2332. @section WIFIExample7 Example
  2333. The code snippet demonstrates an example of how the scan request is called from the application's main function and the handling of
  2334. the events received in response.
  2335. @code
  2336. #include "m2m_wifi.h"
  2337. #include "m2m_types.h"
  2338. void wifi_event_cb(uint8_t u8WiFiEvent, void * pvMsg)
  2339. {
  2340. static uint8_t u8ScanResultIdx = 0;
  2341. switch(u8WiFiEvent)
  2342. {
  2343. case M2M_WIFI_RESP_SCAN_DONE:
  2344. {
  2345. tstrM2mScanDone *pstrInfo = (tstrM2mScanDone*)pvMsg;
  2346. printf("Num of AP found %d\n",pstrInfo->u8NumofCh);
  2347. if(pstrInfo->s8ScanState == M2M_SUCCESS)
  2348. {
  2349. u8ScanResultIdx = 0;
  2350. if(pstrInfo->u8NumofCh >= 1)
  2351. {
  2352. m2m_wifi_req_scan_result(u8ScanResultIdx);
  2353. u8ScanResultIdx ++;
  2354. }
  2355. else
  2356. {
  2357. printf("No AP Found Rescan\n");
  2358. m2m_wifi_request_scan(M2M_WIFI_CH_ALL);
  2359. }
  2360. }
  2361. else
  2362. {
  2363. printf("(ERR) Scan fail with error <%d>\n",pstrInfo->s8ScanState);
  2364. }
  2365. }
  2366. break;
  2367. case M2M_WIFI_RESP_SCAN_RESULT:
  2368. {
  2369. tstrM2mWifiscanResult *pstrScanResult =(tstrM2mWifiscanResult*)pvMsg;
  2370. uint8_t u8NumFoundAPs = m2m_wifi_get_num_ap_found();
  2371. printf(">>%02d RI %d SEC %s CH %02d BSSID %02X:%02X:%02X:%02X:%02X:%02X SSID %s\n",
  2372. pstrScanResult->u8index,pstrScanResult->s8rssi,
  2373. pstrScanResult->u8AuthType,
  2374. pstrScanResult->u8ch,
  2375. pstrScanResult->au8BSSID[0], pstrScanResult->au8BSSID[1], pstrScanResult->au8BSSID[2],
  2376. pstrScanResult->au8BSSID[3], pstrScanResult->au8BSSID[4], pstrScanResult->au8BSSID[5],
  2377. pstrScanResult->au8SSID);
  2378. if(u8ScanResultIdx < u8NumFoundAPs)
  2379. {
  2380. // Read the next scan result
  2381. m2m_wifi_req_scan_result(index);
  2382. u8ScanResultIdx ++;
  2383. }
  2384. }
  2385. break;
  2386. default:
  2387. break;
  2388. }
  2389. }
  2390. int main()
  2391. {
  2392. tstrWifiInitParam param;
  2393. param.pfAppWifiCb = wifi_event_cb;
  2394. if(!m2m_wifi_init(&param))
  2395. {
  2396. // Scan all channels
  2397. m2m_wifi_request_scan(M2M_WIFI_CH_ALL);
  2398. while(1)
  2399. {
  2400. m2m_wifi_handle_events(NULL);
  2401. }
  2402. }
  2403. }
  2404. @endcode
  2405. */
  2406. uint8_t m2m_wifi_get_num_ap_found(void);
  2407. /*!
  2408. @ingroup WLANSCAN
  2409. @fn \
  2410. int8_t m2m_wifi_req_scan_result(uint8_t index);
  2411. @brief
  2412. Asynchronous API to request the information of an access point discovered via scanning.
  2413. @details
  2414. This function allows the information of any discovered access point to be retrieved. When a
  2415. scan is completed, the application is informed of the number of networks (access points)
  2416. discovered. Calling this function with an index, N, will return the information for the Nth
  2417. access point. The information will be returned to the application via a
  2418. @ref M2M_WIFI_RESP_SCAN_RESULT event, and the response data may be obtained through casting
  2419. the pointer (pvMsg) to @ref tstrM2mWifiscanResult.
  2420. @param[in] index
  2421. Index for the requested result, the index range start from 0 till number of AP's found.
  2422. @return
  2423. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC and a negative value otherwise.
  2424. @see
  2425. tstrM2mWifiscanResult
  2426. m2m_wifi_get_num_ap_found
  2427. m2m_wifi_request_scan
  2428. @pre
  2429. - @ref m2m_wifi_request_scan must be called first to ensure up to date results are available.
  2430. - A Wi-Fi notification callback of type @ref tpfAppWifiCb MUST be implemented and registered
  2431. in order to receive scan data after calling this function. Registration of the callback
  2432. is done via the @ref m2m_wifi_init function.
  2433. - The event @ref M2M_WIFI_RESP_SCAN_RESULT must be handled in the callback to receive the
  2434. requested scan information.
  2435. @warning
  2436. - This API is valid only for STA mode, it may be called regardless of the connection state (connected or disconnected).
  2437. - Calling this function without first issuing a scan request may lead to stale data being recovered.
  2438. - Application code should refrain from introducing significant delays between issuing the scan
  2439. request and scan result requests.
  2440. @section WIFIExample8 Example
  2441. The code snippet demonstrates an example of how the scan request is called from the application's main function and
  2442. the handling of the events received in the response.
  2443. @code
  2444. #include "m2m_wifi.h"
  2445. #include "m2m_types.h"
  2446. void wifi_event_cb(uint8_t u8WiFiEvent, void * pvMsg)
  2447. {
  2448. static uint8_t u8ScanResultIdx = 0;
  2449. switch(u8WiFiEvent)
  2450. {
  2451. case M2M_WIFI_RESP_SCAN_DONE:
  2452. {
  2453. tstrM2mScanDone *pstrInfo = (tstrM2mScanDone*)pvMsg;
  2454. printf("Num of AP found %d\n",pstrInfo->u8NumofCh);
  2455. if(pstrInfo->s8ScanState == M2M_SUCCESS)
  2456. {
  2457. u8ScanResultIdx = 0;
  2458. if(pstrInfo->u8NumofCh >= 1)
  2459. {
  2460. m2m_wifi_req_scan_result(u8ScanResultIdx);
  2461. u8ScanResultIdx ++;
  2462. }
  2463. else
  2464. {
  2465. printf("No AP Found Rescan\n");
  2466. m2m_wifi_request_scan(M2M_WIFI_CH_ALL);
  2467. }
  2468. }
  2469. else
  2470. {
  2471. printf("(ERR) Scan fail with error <%d>\n",pstrInfo->s8ScanState);
  2472. }
  2473. }
  2474. break;
  2475. case M2M_WIFI_RESP_SCAN_RESULT:
  2476. {
  2477. tstrM2mWifiscanResult *pstrScanResult =(tstrM2mWifiscanResult*)pvMsg;
  2478. uint8_t u8NumFoundAPs = m2m_wifi_get_num_ap_found();
  2479. printf(">>%02d RI %d SEC %s CH %02d BSSID %02X:%02X:%02X:%02X:%02X:%02X SSID %s\n",
  2480. pstrScanResult->u8index,pstrScanResult->s8rssi,
  2481. pstrScanResult->u8AuthType,
  2482. pstrScanResult->u8ch,
  2483. pstrScanResult->au8BSSID[0], pstrScanResult->au8BSSID[1], pstrScanResult->au8BSSID[2],
  2484. pstrScanResult->au8BSSID[3], pstrScanResult->au8BSSID[4], pstrScanResult->au8BSSID[5],
  2485. pstrScanResult->au8SSID);
  2486. if(u8ScanResultIdx < u8NumFoundAPs)
  2487. {
  2488. // Read the next scan result
  2489. m2m_wifi_req_scan_result(index);
  2490. u8ScanResultIdx ++;
  2491. }
  2492. }
  2493. break;
  2494. default:
  2495. break;
  2496. }
  2497. }
  2498. int main()
  2499. {
  2500. tstrWifiInitParam param;
  2501. param.pfAppWifiCb = wifi_event_cb;
  2502. if(!m2m_wifi_init(&param))
  2503. {
  2504. // Scan all channels
  2505. m2m_wifi_request_scan(M2M_WIFI_CH_ALL);
  2506. while(1)
  2507. {
  2508. m2m_wifi_handle_events(NULL);
  2509. }
  2510. }
  2511. }
  2512. @endcode
  2513. */
  2514. int8_t m2m_wifi_req_scan_result(uint8_t index);
  2515. /*!
  2516. @ingroup WLANCONNECT
  2517. @fn \
  2518. int8_t m2m_wifi_req_curr_rssi(void);
  2519. @brief
  2520. Asynchronous API to request the current Receive Signal Strength (RSSI) of the current connection.
  2521. @details
  2522. This function will result in the application receiving the RSSI via a
  2523. @ref M2M_WIFI_RESP_CURRENT_RSSI event.
  2524. @pre
  2525. - A Wi-Fi notification callback of type @ref tpfAppWifiCb MUST be implemented and registered
  2526. during initialization. Registration of the callback is done through passing it to @ref m2m_wifi_init
  2527. via the @ref tstrWifiInitParam initialization structure.
  2528. - The event @ref M2M_WIFI_RESP_CURRENT_RSSI must be handled in the callback to receive the requested Rssi information.
  2529. @return
  2530. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC and a negative value otherwise.
  2531. @section WIFIExample9 Example
  2532. The code snippet demonstrates how the RSSI request is called in the application's main function and the handling of the event received in the callback.
  2533. @code
  2534. #include "m2m_wifi.h"
  2535. #include "m2m_types.h"
  2536. void wifi_event_cb(uint8_t u8WiFiEvent, void * pvMsg)
  2537. {
  2538. static uint8_t u8ScanResultIdx = 0;
  2539. switch(u8WiFiEvent)
  2540. {
  2541. case M2M_WIFI_RESP_CURRENT_RSSI:
  2542. {
  2543. int8_t *rssi = (int8_t*)pvMsg;
  2544. M2M_INFO("ch rssi %d\n",*rssi);
  2545. }
  2546. break;
  2547. default:
  2548. break;
  2549. }
  2550. }
  2551. int main()
  2552. {
  2553. tstrWifiInitParam param;
  2554. param.pfAppWifiCb = wifi_event_cb;
  2555. if(!m2m_wifi_init(&param))
  2556. {
  2557. // Scan all channels
  2558. m2m_wifi_req_curr_rssi();
  2559. while(1)
  2560. {
  2561. m2m_wifi_handle_events(NULL);
  2562. }
  2563. }
  2564. }
  2565. @endcode
  2566. */
  2567. int8_t m2m_wifi_req_curr_rssi(void);
  2568. /*!
  2569. @ingroup WLANCONF
  2570. @fn \
  2571. int8_t m2m_wifi_get_otp_mac_address(uint8_t *pu8MacAddr, uint8_t * pu8IsValid);
  2572. @brief
  2573. Synchronous API to query the MAC address programmed into the WINC OTP memory.
  2574. @details
  2575. This function attempts to read the device's MAC address from the One Time Programmable (OTP)
  2576. memory on the WINC. The presence (yes or no) of a MAC address in the OTP memory and, in the case
  2577. of it being present, its value is returned via RAM pointed to by the input arguments.
  2578. Request the MAC address stored on the One Time Programmable(OTP) memory of the device.
  2579. The function is blocking until the response is received.
  2580. @pre
  2581. Prior call to @ref m2m_wifi_init is required before any WIFI/socket function.
  2582. @param[out] pu8MacAddr
  2583. Output MAC address buffer 6 bytes in size. Valid only if *pu8Valid=1.
  2584. @param[out] pu8IsValid
  2585. A boolean value set by the callee to indicate the validity of pu8MacAddr in OTP. If no MAC has
  2586. been programmed in the OTP the value of this parameter will be zero; otherwise it will be non-zero.
  2587. @return
  2588. The function returns @ref M2M_SUCCESS for success and a negative value otherwise.
  2589. @see
  2590. m2m_wifi_get_mac_address
  2591. */
  2592. int8_t m2m_wifi_get_otp_mac_address(uint8_t *pu8MacAddr, uint8_t *pu8IsValid);
  2593. /*!
  2594. @ingroup WLANCONF
  2595. @fn \
  2596. int8_t m2m_wifi_get_mac_address(uint8_t *pu8MacAddr)
  2597. @brief
  2598. Synchronous API to retrieve the MAC address currently in use by the device.
  2599. @details
  2600. This function obtains the MAC address that is currently in use by the device. If the function
  2601. returns with @ref M2M_SUCCESS then the content of the memory referenced by pu8MacAddr will be
  2602. populated with the 6 byte MAC address; otherwise, that memory will be left unchanged.
  2603. @pre
  2604. Prior call to @ref m2m_wifi_init is required before any WIFI/socket function.
  2605. @param[out] pu8MacAddr
  2606. Pointer to a buffer in memory containing a 6-byte MAC address (provided function returns @ref M2M_SUCCESS).
  2607. @return
  2608. The function returns @ref M2M_SUCCESS for successful operation and a negative value otherwise.
  2609. @see
  2610. m2m_wifi_get_otp_mac_address
  2611. */
  2612. int8_t m2m_wifi_get_mac_address(uint8_t *pu8MacAddr);
  2613. /*!
  2614. @ingroup WLANPS
  2615. @fn \
  2616. int8_t m2m_wifi_set_sleep_mode(uint8_t PsTyp, uint8_t BcastEn);
  2617. @brief
  2618. Synchronous API to set the power-save mode of the WINC.
  2619. @details
  2620. This is one of the two synchronous power-save setting functions that allow the host MCU application
  2621. to tweak the system power consumption. Such tweaking can be done through one of two ways:
  2622. - 1) Changing the power save mode, to one of the allowed power save modes (see @ref tenuPowerSaveModes). This is done by setting the first parameter.
  2623. - 2) Configuring DTIM monitoring: Configuring beacon monitoring parameters by enabling or disabling the reception of broadcast/multicast data.
  2624. This is done by setting the second parameter.
  2625. @param[in] PsTyp
  2626. Desired power saving mode. Supported types are enumerated in @ref tenuPowerSaveModes.
  2627. @param[in] BcastEn
  2628. Broadcast reception enable flag.
  2629. If set to 1, the WINC will wake for each DTIM beacon to ensure broadcast traffic can be received.
  2630. If set to 0, the WINC will not wakeup at the DTIM beacon, ignoring broadcast traffic, instead it will
  2631. wake every N beacon periods, as per the negotiated Listen Interval.
  2632. @warning
  2633. The function called once after initialization.
  2634. @return
  2635. The function returns @ref M2M_SUCCESS for successful operation and a negative value otherwise.
  2636. @see
  2637. tenuPowerSaveModes
  2638. m2m_wifi_get_sleep_mode
  2639. m2m_wifi_set_lsn_int
  2640. */
  2641. int8_t m2m_wifi_set_sleep_mode(uint8_t PsTyp, uint8_t BcastEn);
  2642. /*!
  2643. @ingroup WLANPS
  2644. @fn \
  2645. int8_t m2m_wifi_request_sleep(uint32_t u32SlpReqTime);
  2646. @brief
  2647. Asynchronous API to place the WINC into sleep mode for a specified period of time.
  2648. @details
  2649. Power-save sleep request function, which requests the WINC device to sleep in the currently configured
  2650. power save mode, as set using @ref m2m_wifi_set_sleep_mode, for a specific time as defined by the parameter
  2651. u32SlpReqTime (measured in milliseconds).
  2652. This function should be used when the WINC is running in @ref M2M_PS_MANUAL power save mode only.
  2653. A wake up request is automatically performed by the WINC device when any host driver API function, e.g. Wi-Fi or socket operation is called.
  2654. @param[in] u32SlpReqTime
  2655. Request sleep time in ms.\n
  2656. The best recommended sleep duration is left to be determined by the application.
  2657. Taking into account that if the application sends notifications very rarely,
  2658. sleeping for a long time can be a power-efficient decision.
  2659. In contrast, applications that are sensitive for long periods of absence can experience
  2660. performance degradation in the connection if long sleeping times are used.
  2661. @return
  2662. The function returns @ref M2M_SUCCESS for successful operation and a negative value otherwise.
  2663. @warning
  2664. - This API is currently unsupported on the WINC3400
  2665. @see
  2666. tenuPowerSaveModes
  2667. m2m_wifi_set_sleep_mode
  2668. */
  2669. int8_t m2m_wifi_request_sleep(uint32_t u32SlpReqTime);
  2670. /*!
  2671. @ingroup WLANPS
  2672. @fn \
  2673. uint8_t m2m_wifi_get_sleep_mode(void);
  2674. @brief
  2675. Synchronous API to retrieve the current power save mode of the WINC.
  2676. @return
  2677. The current operating power saving mode. The value will be one of those from the enumerated type @ref tenuPowerSaveModes.
  2678. @see
  2679. tenuPowerSaveModes
  2680. m2m_wifi_set_sleep_mode
  2681. */
  2682. uint8_t m2m_wifi_get_sleep_mode(void);
  2683. /*!
  2684. @ingroup WLANCONF
  2685. @fn \
  2686. int8_t m2m_wifi_set_device_name(uint8_t *pu8DeviceName, uint8_t u8DeviceNameLength);
  2687. @brief
  2688. Asynchronous API to set the Wi-Fi Direct "Device Name" of the WINC.
  2689. @details
  2690. Sets the WINC device name. The name string is used as a device name in DHCP
  2691. hostname (option 12).
  2692. If a device is not set through this function a default name is assigned.
  2693. The default name is WINC-XX-YY, where XX and YY are the last 2 octets of the OTP
  2694. MAC address. If OTP (eFuse) is programmed, then the default name is WINC-00-00.
  2695. @warning
  2696. The function called once after initialization.\n
  2697. Used for DHCP client hostname option (12).\n
  2698. Device name shall contain only characters allowed in valid internet host name as
  2699. defined in RFC 952 and 1123.
  2700. @param[in] pu8DeviceName
  2701. Buffer holding the device name. Device name is a null terminated C string.
  2702. @param[in] u8DeviceNameLength
  2703. Length of the device name. Should not exceed the maximum device name's
  2704. length @ref M2M_DEVICE_NAME_MAX (including null character).
  2705. @return
  2706. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC and a negative value otherwise.
  2707. */
  2708. int8_t m2m_wifi_set_device_name(uint8_t *pu8DeviceName, uint8_t u8DeviceNameLength);
  2709. /*!
  2710. @ingroup WLANTIME
  2711. @fn \
  2712. int8_t m2m_wifi_configure_sntp(uint8_t *pu8NTPServerName, uint8_t u8NTPServerNameLength, tenuSNTPUseDHCP useDHCP);
  2713. @brief
  2714. Configures what NTP server the SNTP client should use.
  2715. @details
  2716. Configures what NTP server the SNTP client should use. Only 1 server name can be provided, if the configured server name begins with an asterisk then it will be treated as a server pool.
  2717. The SNTP client can also use the NTP server provided by the DHCP server through option 42.
  2718. By default the NTP server provided by DHCP will be tried first, then the built-in default NTP server (time.nist.gov) will be used.
  2719. @param[in] pu8NTPServerName
  2720. Buffer holding the NTP server name. If the first character is an asterisk (*) then it will be treated as a server pool, where the asterisk will
  2721. be replaced with an incrementing value from 0 to 3 each time a server fails (example: *.pool.ntp.org).
  2722. @param[in] u8NTPServerNameLength
  2723. Length of the NTP server name. Should not exceed the maximum NTP server name length of @ref M2M_NTP_MAX_SERVER_NAME_LENGTH.
  2724. @param[in] useDHCP
  2725. Explicity tell the WINC if it should use the NTP server provided by the DHCP server or not.
  2726. @warning
  2727. SNTP should be configured before the connection takes place. If SNTP is configured after the device connects to a
  2728. network, the new configuration can take a minimum of 24h to be applied. However, it can take even longer since it is
  2729. triggered by DHCP renewal.
  2730. Currently there is also a known issue in which if the WINC obtains the NTP server from DHCP and then connects to a
  2731. different network, it will still use the NTP from the previous network.
  2732. Configuring a server name will overwrite the built-in default server until next reboot.
  2733. @return
  2734. The function returns @ref M2M_SUCCESS for success and a negative value otherwise.
  2735. */
  2736. int8_t m2m_wifi_configure_sntp(uint8_t *pu8NTPServerName, uint8_t u8NTPServerNameLength, tenuSNTPUseDHCP useDHCP);
  2737. /*!
  2738. @ingroup WLANPS
  2739. @fn \
  2740. int8_t m2m_wifi_set_lsn_int(tstrM2mLsnInt * pstrM2mLsnInt);
  2741. @brief
  2742. Asynchronous API to set Wi-Fi listen interval for power save operation.
  2743. @details
  2744. This is one of the two synchronous power-save setting functions that
  2745. allow the host MCU application to tweak the system power consumption. Such tweaking can be done by modifying the
  2746. Wi-Fi listen interval. The listen interval is how many beacon periods the station can sleep before it wakes up to receive data buffered in the AP.
  2747. It is represented in units of AP beacon periods(100ms).
  2748. @warning
  2749. The function should be called once after initialization.
  2750. @param[in] pstrM2mLsnInt
  2751. Structure holding the listen interval configuration.
  2752. @pre
  2753. The function @ref m2m_wifi_set_sleep_mode shall be called first, to set the power saving mode required.
  2754. @return
  2755. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC and a negative value otherwise.
  2756. @see
  2757. tstrM2mLsnInt
  2758. m2m_wifi_set_sleep_mode
  2759. */
  2760. int8_t m2m_wifi_set_lsn_int(tstrM2mLsnInt *pstrM2mLsnInt);
  2761. /**@cond MON_DOC
  2762. */
  2763. /*!
  2764. @ingroup WLANMON
  2765. @fn \
  2766. int8_t m2m_wifi_enable_monitoring_mode(tstrM2MWifiMonitorModeCtrl *, uint8_t *, uint16_t , uint16_t);
  2767. @brief
  2768. Asynchronous call to enable Wi-Fi monitoring (promiscuous receive) mode.
  2769. @details
  2770. Wi-Fi monitoring mode (Promiscuous mode) enabling function.
  2771. This function enables the monitoring mode, thus allowing two operations to be
  2772. performed:
  2773. 1) Transmission of manually configured frames, through using the
  2774. @ref m2m_wifi_send_wlan_pkt function.
  2775. 2) Reception of frames based on a defined filtering criteria.
  2776. Enabling monitoring mode allows for reception of all frames that satisfy the filter criteria in the input parameter and are received on the current wireless channel.
  2777. All packets that meet the filtering criteria are passed to the application layer, to
  2778. be handled by the assigned monitoring callback function.
  2779. The monitoring callback function must be implemented before starting the monitoring mode,
  2780. in-order to handle the packets received.
  2781. A dedicated callback function, @ref tpfAppMonCb, must be registered to handle frames received in
  2782. promiscuous mode. This is done via an instance of a @ref tstrWifiInitParam structure and a call to
  2783. the @ref m2m_wifi_init function.
  2784. @param[in] pstrMtrCtrl
  2785. Pointer to @ref tstrM2MWifiMonitorModeCtrl structure holding the filtering parameters.
  2786. @param[in] pu8PayloadBuffer
  2787. Pointer to a Buffer allocated by the application. The buffer SHALL hold the Data field of
  2788. the WIFI RX Packet (Or a part from it). If it is set to NULL, the WIFI data payload will
  2789. be discarded by the monitoring driver.
  2790. @param[in] u16BufferSize
  2791. The total size of the pu8PayloadBuffer in bytes.
  2792. @param[in] u16DataOffset
  2793. Starting offset in the DATA FIELD of the received WIFI packet. The application may be interested
  2794. in reading specific information from the received packet. It must assign the offset to the starting
  2795. position of it relative to the DATA payload start.\n
  2796. \e Example, \e if \e the \e SSID \e is \e needed \e to \e be \e read \e from \e a \e PROBE \e REQ
  2797. \e packet, \e the \e u16Offset \e MUST \e be \e set \e to \e 0.
  2798. @warning
  2799. This mode is available as sniffer ONLY, the WINC cannot be connected in any modes (Station, Access Point or P2P).
  2800. @return
  2801. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC and a negative value otherwise.
  2802. @see
  2803. tstrM2MWifiMonitorModeCtrl
  2804. tstrM2MWifiRxPacketInfo
  2805. tstrWifiInitParam
  2806. tenuM2mScanCh
  2807. m2m_wifi_disable_monitoring_mode
  2808. m2m_wifi_send_wlan_pkt
  2809. m2m_wifi_send_ethernet_pkt
  2810. @section WIFIExample10 Example
  2811. The example demonstrates the main function where-by the monitoring enable function is called after
  2812. the initialization of the driver and the packets are handled in the callback function.
  2813. @code
  2814. #include "m2m_wifi.h"
  2815. #include "m2m_types.h"
  2816. //Declare receive buffer
  2817. uint8_t gmgmt[1600];
  2818. //Callback functions
  2819. void wifi_cb(uint8_t u8WiFiEvent, void * pvMsg)
  2820. {
  2821. ;
  2822. }
  2823. void wifi_monitoring_cb(tstrM2MWifiRxPacketInfo *pstrWifiRxPacket, uint8_t *pu8Payload, uint16_t u16PayloadSize)
  2824. {
  2825. if((NULL != pstrWifiRxPacket) && (0 != u16PayloadSize)) {
  2826. if(MANAGEMENT == pstrWifiRxPacket->u8FrameType) {
  2827. M2M_INFO("***# MGMT PACKET #***\n");
  2828. } else if(DATA_BASICTYPE == pstrWifiRxPacket->u8FrameType) {
  2829. M2M_INFO("***# DATA PACKET #***\n");
  2830. } else if(CONTROL == pstrWifiRxPacket->u8FrameType) {
  2831. M2M_INFO("***# CONTROL PACKET #***\n");
  2832. }
  2833. }
  2834. }
  2835. int main()
  2836. {
  2837. //Register wifi_monitoring_cb
  2838. tstrWifiInitParam param;
  2839. param.pfAppWifiCb = wifi_cb;
  2840. param.pfAppMonCb = wifi_monitoring_cb;
  2841. nm_bsp_init();
  2842. if(!m2m_wifi_init(&param)) {
  2843. //Enable Monitor Mode with filter to receive all data frames on channel 1
  2844. tstrM2MWifiMonitorModeCtrl strMonitorCtrl = {0};
  2845. strMonitorCtrl.u8ChannelID = M2M_WIFI_CH_1;
  2846. strMonitorCtrl.u8FrameType = DATA_BASICTYPE;
  2847. strMonitorCtrl.u8FrameSubtype = M2M_WIFI_FRAME_SUB_TYPE_ANY; //Receive any subtype of data frame
  2848. m2m_wifi_enable_monitoring_mode(&strMonitorCtrl, gmgmt, sizeof(gmgmt), 0);
  2849. while(1) {
  2850. m2m_wifi_handle_events(NULL);
  2851. }
  2852. }
  2853. return 0;
  2854. }
  2855. @endcode
  2856. */
  2857. int8_t m2m_wifi_enable_monitoring_mode(tstrM2MWifiMonitorModeCtrl *pstrMtrCtrl, uint8_t *pu8PayloadBuffer,
  2858. uint16_t u16BufferSize, uint16_t u16DataOffset);
  2859. /*!
  2860. @ingroup WLANMON
  2861. @fn \
  2862. int8_t m2m_wifi_disable_monitoring_mode(void);
  2863. @brief
  2864. Asynchronous API to disable Wi-Fi monitoring (promiscuous receive) mode.
  2865. @details
  2866. Disable Wi-Fi monitoring mode (Promiscuous mode). Expected to be called if the monitoring mode is already enabled,
  2867. but if it was called without enabling it, no negative impact will reside.
  2868. @return
  2869. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC and a negative value otherwise.
  2870. @see
  2871. m2m_wifi_enable_monitoring_mode
  2872. */
  2873. int8_t m2m_wifi_disable_monitoring_mode(void);
  2874. /*!
  2875. @ingroup WLANMON
  2876. @fn \
  2877. int8_t m2m_wifi_send_wlan_pkt(uint8_t *, uint16_t, uint16_t);
  2878. @brief
  2879. Asynchronous API to queue a raw Wi-Fi packet for transmission by the WINC.
  2880. @pre
  2881. Enable Monitoring mode first using @ref m2m_wifi_enable_monitoring_mode
  2882. @note
  2883. The application is responsible for the packets.
  2884. @warning
  2885. This function is only useful when operating in monitoring mode.
  2886. @param[in] pu8WlanPacket
  2887. Pointer to a buffer holding the whole WIFI frame.
  2888. @param[in] u16WlanHeaderLength
  2889. The size of the WIFI packet header ONLY.
  2890. @param[in] u16WlanPktSize
  2891. The size of the whole packet in bytes.
  2892. @return
  2893. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC and a negative value otherwise.
  2894. @see
  2895. m2m_wifi_enable_monitoring_mode
  2896. m2m_wifi_disable_monitoring_mode
  2897. */
  2898. int8_t m2m_wifi_send_wlan_pkt(uint8_t *pu8WlanPacket, uint16_t u16WlanHeaderLength, uint16_t u16WlanPktSize);
  2899. /**@endcond*/ //MON_DOC
  2900. /*!
  2901. @ingroup WLANETH
  2902. @fn \
  2903. int8_t m2m_wifi_send_ethernet_pkt(uint8_t* pu8Packet,uint16_t u16PacketSize);
  2904. @brief
  2905. Asynchronous API to queue an Ethernet packet for transmission by the WINC.
  2906. @details
  2907. Transmit a packet directly in ETHERNET/bypass mode where the TCP/IP stack is disabled
  2908. and the implementation of this packet is left to the application developer.
  2909. The Ethernet packet composition is left to the application developer.
  2910. @note
  2911. Packets are the user's responsibility.
  2912. @warning
  2913. This function available in ETHERNET/Bypass mode ONLY. Make sure that application defines ETH_MODE.
  2914. @param[in] pu8Packet
  2915. Pointer to a buffer holding the whole Ethernet frame.
  2916. @param[in] u16PacketSize
  2917. The size of the whole packet in bytes.
  2918. @return
  2919. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC and a negative value otherwise.
  2920. @see
  2921. m2m_wifi_enable_mac_mcast
  2922. m2m_wifi_set_receive_buffer
  2923. */
  2924. int8_t m2m_wifi_send_ethernet_pkt(uint8_t *pu8Packet, uint16_t u16PacketSize);
  2925. /*!
  2926. @ingroup WLANTIME
  2927. @fn \
  2928. int8_t m2m_wifi_enable_sntp(uint8_t);
  2929. @brief
  2930. Asynchronous API to enable or disable the native Simple Network Time Protocol(SNTP) client running on the WINC.
  2931. @details
  2932. The SNTP client is enabled by default during chip initialization. This function can be used to
  2933. disable or subsequently re-enable the service.
  2934. The service is capable of synchronizing the WINC system clock to the UTC time from a well-known
  2935. (and trusted) time server, for example "time.nist.gov". By default the SNTP client will update the
  2936. system time once every 24 hours. The ability to track the time accurately is important for various
  2937. applications such as checking expiry of X509 certificates during TLS (Transport Layer Security)
  2938. session establishment.
  2939. It is highly recommended to leave SNTP enabled if there is no alternative source of timing
  2940. information. For systems including an RTC device, SNTP may not be needed and the WINC's time
  2941. may be set using the @ref m2m_wifi_set_system_time function.
  2942. @param[in] bEnable
  2943. Enables or disables the SNTP service
  2944. '0' :disable SNTP
  2945. '1' :enable SNTP
  2946. @return
  2947. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC and a negative value otherwise.
  2948. @see
  2949. m2m_wifi_set_system_time
  2950. */
  2951. int8_t m2m_wifi_enable_sntp(uint8_t bEnable);
  2952. /*!
  2953. @ingroup WLANTIME
  2954. @fn \
  2955. int8_t m2m_wifi_set_system_time(uint32_t);
  2956. @brief
  2957. Asynchronous function for setting the system time within the WINC.
  2958. @details
  2959. Function for setting the system time in time/date format (@ref uint32_t).
  2960. The @ref tstrSystemTime structure can be used as a reference to the time values that
  2961. should be set and pass its value as @ref uint32_t.
  2962. @param[in] u32UTCSeconds
  2963. Seconds elapsed since January 1, 1900 (NTP Timestamp).
  2964. @return
  2965. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC and a negative value otherwise.
  2966. @see
  2967. m2m_wifi_enable_sntp
  2968. tstrSystemTime
  2969. @note
  2970. If there is an RTC on the host MCU, the SNTP may be disabled and the host may set the system
  2971. time within the firmware using the API @ref m2m_wifi_set_system_time.
  2972. */
  2973. int8_t m2m_wifi_set_system_time(uint32_t u32UTCSeconds);
  2974. /*!
  2975. @ingroup WLANTIME
  2976. @fn \
  2977. int8_t m2m_wifi_get_system_time(void);
  2978. @brief
  2979. Asynchronous API to obtain the system time in use by the WINC.
  2980. @details
  2981. This function will request the WINC to report its current system time to the application. The
  2982. information will arrive at the application via the @ref tpfAppWifiCb and event @ref M2M_WIFI_RESP_GET_SYS_TIME.
  2983. Response time retrieved is parsed into the members defined in the structure @ref tstrSystemTime.
  2984. @note
  2985. - A Wi-Fi notification callback of type @ref tpfAppWifiCb MUST be implemented and registered
  2986. during initialization. Registration of the callback is done via the @ref m2m_wifi_init API.
  2987. - The event @ref M2M_WIFI_RESP_GET_SYS_TIME must be handled in the callback.
  2988. @return
  2989. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC and a negative value otherwise.
  2990. @see
  2991. m2m_wifi_enable_sntp
  2992. tstrSystemTime
  2993. */
  2994. int8_t m2m_wifi_get_system_time(void);
  2995. /*!
  2996. @ingroup WLANCONF
  2997. @fn \
  2998. int8_t m2m_wifi_set_cust_InfoElement(uint8_t*);
  2999. @brief
  3000. Asynchronous API to add or remove a user-defined Information Element.
  3001. @details
  3002. This function allows the application to provide a custom Information Element to the
  3003. WINC that will be included in all beacon and probe response frames, while in Access Point mode.
  3004. If it is required to delete these IEs, fill the buffer with zeros.
  3005. @param[in] pau8M2mCustInfoElement
  3006. Pointer to Buffer containing the IE to be used. It is the application developer's
  3007. responsibility to ensure on the correctness of the information element's ordering
  3008. passed in.
  3009. If the pointer is null, this removes any current custom IE. If non-null, the pointer
  3010. must reference data in the following format:
  3011. @verbatim
  3012. --------------- ---------- ---------- ------------------- -------- -------- ----------- -----------------------
  3013. | Byte[0] | Byte[1] | Byte[2] | Byte[3:length1+2] | ..... | Byte[n] | Byte[n+1] | Byte[n+2:lengthx+2] |
  3014. |---------------|----------|----------|-------------------|-------- --------|-----------|---------------------|
  3015. | #of all Bytes | IE1 ID | Length1 | Data1(Hex Coded) | ..... | IEx ID | Lengthx | Datax(Hex Coded) |
  3016. --------------- ---------- ---------- ------------------- -------- -------- ----------- -----------------------
  3017. @endverbatim
  3018. @warning
  3019. Size of All elements combined must not exceed 255 byte.
  3020. Used in Access Point Mode.
  3021. @note
  3022. IEs Format will follow the above format.
  3023. @return
  3024. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC and a negative value otherwise.
  3025. @see
  3026. m2m_wifi_enable_sntp
  3027. @section WIFIExample11 Example
  3028. The example demonstrates how the information elements are set using this function.
  3029. @code
  3030. char elementData[21];
  3031. static char state = 0; // To Add, Append, and Delete
  3032. if(0 == state) { //Add 3 IEs
  3033. state = 1;
  3034. //Total Number of Bytes
  3035. elementData[0]=12;
  3036. //First IE
  3037. elementData[1]=200; elementData[2]=1; elementData[3]='A';
  3038. //Second IE
  3039. elementData[4]=201; elementData[5]=2; elementData[6]='B'; elementData[7]='C';
  3040. //Third IE
  3041. elementData[8]=202; elementData[9]=3; elementData[10]='D'; elementData[11]=0; elementData[12]='F';
  3042. } else if(1 == state) {
  3043. //Append 2 IEs to others, Notice that we keep old data in array starting with\n
  3044. //element 13 and total number of bytes increased to 20
  3045. state = 2;
  3046. //Total Number of Bytes
  3047. elementData[0]=20;
  3048. //Fourth IE
  3049. elementData[13]=203; elementData[14]=1; elementData[15]='G';
  3050. //Fifth IE
  3051. elementData[16]=204; elementData[17]=3; elementData[18]='X'; elementData[19]=5; elementData[20]='Z';
  3052. } else if(2 == state) { //Delete All IEs
  3053. state = 0;
  3054. //Total Number of Bytes
  3055. elementData[0]=0;
  3056. }
  3057. m2m_wifi_set_cust_InfoElement(elementData);
  3058. @endcode
  3059. */
  3060. int8_t m2m_wifi_set_cust_InfoElement(uint8_t *pau8M2mCustInfoElement);
  3061. /*!
  3062. @ingroup WLANPS
  3063. @fn \
  3064. int8_t m2m_wifi_set_power_profile(uint8_t u8PwrMode);
  3065. @brief
  3066. Change the power profile mode.
  3067. @param[in] u8PwrMode
  3068. Change the WINC power profile to different mode based on the enumeration @ref tenuM2mPwrMode.\n
  3069. Not implemented in WINC3400 firmware.
  3070. @warning
  3071. May only be called after initialization, before any connection request, and may not be used to change
  3072. the power mode thereafter.
  3073. @return
  3074. The function returns @ref M2M_SUCCESS for success and a negative value otherwise.
  3075. @see
  3076. tenuM2mPwrMode
  3077. m2m_wifi_init
  3078. */
  3079. int8_t m2m_wifi_set_power_profile(uint8_t u8PwrMode);
  3080. /*!
  3081. @ingroup WLANCONF
  3082. @fn \
  3083. int8_t m2m_wifi_set_tx_power(uint8_t u8TxPwrLevel);
  3084. @brief
  3085. Set the TX power tenuM2mTxPwrLevel.
  3086. @param[in] u8TxPwrLevel
  3087. Change the TX power based on the enumeration @ref tenuM2mTxPwrLevel.
  3088. @pre
  3089. Must be called after the initialization and before any connection request and can't be changed in runtime.
  3090. @return
  3091. The function returns @ref M2M_SUCCESS for success and a negative value otherwise.
  3092. @see
  3093. tenuM2mTxPwrLevel
  3094. m2m_wifi_init
  3095. */
  3096. int8_t m2m_wifi_set_tx_power(uint8_t u8TxPwrLevel);
  3097. /*!
  3098. @ingroup WLANLOG
  3099. @fn \
  3100. int8_t m2m_wifi_enable_firmware_logs(uint8_t u8Enable);
  3101. @brief
  3102. Enable or Disable logs in run time.
  3103. @details
  3104. Enable or Disable logs in run time (Disable Firmware logs will enhance the firmware start-up time and performance).
  3105. @param[in] u8Enable
  3106. Set 1 to enable the logs, 0 for disable.
  3107. @pre
  3108. Must be called after initialization through the following function @ref m2m_wifi_init.
  3109. @return
  3110. The function returns @ref M2M_SUCCESS for success and a negative value otherwise.
  3111. @see
  3112. __DISABLE_FIRMWARE_LOGS__ (build option to disable logs from initializations)
  3113. m2m_wifi_init
  3114. */
  3115. int8_t m2m_wifi_enable_firmware_logs(uint8_t u8Enable);
  3116. /*!
  3117. @ingroup WLANCONF
  3118. @fn \
  3119. int8_t m2m_wifi_set_battery_voltage(uint16_t u16BattVoltx100);
  3120. @brief
  3121. Set the battery voltage to update the firmware calculations.\n
  3122. Not implemented in WINC3400 firmware.
  3123. @pre
  3124. Must be called after initialization through the following function @ref m2m_wifi_init.
  3125. @param [in] u16BattVoltx100
  3126. Battery voltage multiplied by 100
  3127. @return
  3128. The function returns @ref M2M_SUCCESS for success and a negative value otherwise.
  3129. @see
  3130. m2m_wifi_init
  3131. */
  3132. int8_t m2m_wifi_set_battery_voltage(uint16_t u16BattVoltx100);
  3133. /*!
  3134. @ingroup WLANETH
  3135. @fn \
  3136. int8_t m2m_wifi_enable_mac_mcast(uint8_t *pu8MulticastMacAddress, uint8_t u8AddRemove);
  3137. @brief
  3138. Asynchronous API to add or remove MAC addresses to the multicast filter.
  3139. @details
  3140. This function will configure the WINC to receive/ignore multicast packets from certain
  3141. MAC address groups when operating in bypass mode.
  3142. This function requests the given MAC addresses to be added/removed from the multicast filter.
  3143. @param[in] pu8MulticastMacAddress
  3144. Pointer to MAC address
  3145. @param[in] u8AddRemove
  3146. A flag to add or remove the MAC ADDRESS, based on the following values:
  3147. - 0 : remove MAC address
  3148. - 1 : add MAC address
  3149. @note
  3150. Maximum number of MAC addresses that could be added is 8.
  3151. @warning
  3152. This function is available in ETHERNET/bypass mode ONLY.
  3153. Make sure that the application defines ETH_MODE.
  3154. @return
  3155. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC and a negative value otherwise.
  3156. @see
  3157. m2m_wifi_set_receive_buffer
  3158. m2m_wifi_send_ethernet_pkt
  3159. */
  3160. int8_t m2m_wifi_enable_mac_mcast(uint8_t *pu8MulticastMacAddress, uint8_t u8AddRemove);
  3161. /*!
  3162. @ingroup WLANETH
  3163. @fn \
  3164. int8_t m2m_wifi_set_receive_buffer(void *pvBuffer, uint16_t u16BufferLen);
  3165. @brief
  3166. Synchronous function for setting or modifying the receiver buffer's length.
  3167. @details
  3168. Synchronous function for setting or modifying the receiver buffer's length.
  3169. In the ETHERNET/bypass mode the application should define a callback of type
  3170. @ref tpfAppEthCb, through which the application handles the received
  3171. ethernet frames. It is through this callback function that the user can
  3172. dynamically modify the length of the currently used receiver buffer.
  3173. @param[in] pvBuffer
  3174. Pointer to Buffer to receive data.
  3175. NULL pointer causes a negative error @ref M2M_ERR_FAIL.
  3176. @param[in] u16BufferLen
  3177. Length of data to be received. Maximum length of data should not exceed the size defined by TCP/IP
  3178. defined as @ref SOCKET_BUFFER_MAX_LENGTH
  3179. @warning
  3180. This function is available in the Ethernet/bypass mode ONLY. Make sure that the application defines ETH_MODE.
  3181. @return
  3182. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC and a negative value otherwise.
  3183. @see
  3184. m2m_wifi_enable_mac_mcast
  3185. m2m_wifi_send_ethernet_pkt
  3186. */
  3187. int8_t m2m_wifi_set_receive_buffer(void *pvBuffer, uint16_t u16BufferLen);
  3188. /*!
  3189. @ingroup WLANCRYPTO
  3190. @fn \
  3191. int8_t m2m_wifi_prng_get_random_bytes(uint8_t* pu8PrngBuff,uint16_t u16PrngSize);
  3192. @brief
  3193. Asynchronous function for retrieving from the firmware a pseudo-random set of bytes.
  3194. @details
  3195. Asynchronous function for retrieving from the firmware a pseudo-random set of bytes as specified in the size passed in as a parameter.
  3196. The registered wifi-cb function retrieves the random bytes through the response @ref M2M_WIFI_RESP_GET_PRNG
  3197. @param[in] pu8PrngBuff
  3198. Pointer to a buffer to receive data.
  3199. @param[in] u16PrngSize
  3200. Request size in bytes
  3201. @warning
  3202. Size greater than the maximum specified (@ref M2M_BUFFER_MAX_SIZE - sizeof(tstrPrng))
  3203. causes a negative error @ref M2M_ERR_FAIL.
  3204. @return
  3205. The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  3206. */
  3207. int8_t m2m_wifi_prng_get_random_bytes(uint8_t *pu8PrngBuff, uint16_t u16PrngSize);
  3208. /*!
  3209. @ingroup WLANROAMING
  3210. @fn \
  3211. int8_t m2m_wifi_enable_roaming(uint8_t bEnableDhcp);
  3212. @brief
  3213. Enable WiFi STA roaming.
  3214. @details
  3215. m2m_wifi_enable_roaming enables the firmware to trigger the roaming algorithm/steps on link loss with the current AP.
  3216. If roaming is successful, the @ref M2M_WIFI_RESP_CON_STATE_CHANGED message with state as @ref M2M_WIFI_ROAMED is sent to the host.
  3217. Additionally a @ref M2M_WIFI_REQ_DHCP_CONF message with new DHCP lease details is sent to host (only if bEnableDhcp=1).
  3218. If roaming is unsuccessful, a @ref M2M_WIFI_RESP_CON_STATE_CHANGED message with state as @ref M2M_WIFI_DISCONNECTED is sent to host.
  3219. @param[in] bEnableDhcp
  3220. 0 : Disables DHCP client execution after roaming to new AP
  3221. 1 : Enables DHCP client execution after roaming to new AP
  3222. @pre
  3223. Must be called after the initialization.
  3224. The roaming algorithm/procedure is internal to the firmware.
  3225. @return
  3226. The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  3227. @see
  3228. m2m_wifi_init
  3229. */
  3230. int8_t m2m_wifi_enable_roaming(uint8_t bEnableDhcp);
  3231. /*!
  3232. @ingroup WLANROAMING
  3233. @fn \
  3234. int8_t m2m_wifi_disable_roaming(void);
  3235. @brief
  3236. Disable WiFi STA roaming.
  3237. @pre
  3238. Must be called after the initialization.
  3239. @return
  3240. The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  3241. @see
  3242. m2m_wifi_init
  3243. */
  3244. int8_t m2m_wifi_disable_roaming(void);
  3245. /*!
  3246. @ingroup WLANINIT
  3247. @fn \
  3248. uint8_t m2m_wifi_get_state(void);
  3249. @brief
  3250. Get the wifi state.
  3251. @return
  3252. The function returns the current wifi state (see @ref tenuWifiState for the possible states).
  3253. @note
  3254. Check the WINC state. See @ref tenuWifiState for possible states.\n
  3255. @ref WIFI_STATE_INIT state represents WINC initialized but not started, this is a suitable state
  3256. for safe flash access.
  3257. @sa
  3258. m2m_wifi_init
  3259. m2m_wifi_download_mode
  3260. */
  3261. uint8_t m2m_wifi_get_state(void);
  3262. /*!
  3263. @ingroup BLEAPI
  3264. @fn \
  3265. int8_t m2m_wifi_ble_api_send(const uint8_t* const msg, const uint32_t len);
  3266. @brief
  3267. Asynchronous API to send an encapsulated Atmel BLE message over the Wifi Host Interface.
  3268. @param[in] msg
  3269. Pointer to the start of the BLE message to transfer down to the WINC.
  3270. @param[in] len
  3271. The length of the message in octets.
  3272. @return
  3273. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC,
  3274. and a negative value otherwise.
  3275. */
  3276. int8_t m2m_wifi_ble_api_send(uint8_t *msg, uint32_t len);
  3277. /*!
  3278. @ingroup BLEAPI
  3279. @fn \
  3280. int8_t m2m_wifi_ble_set_gain_table(uint8_t table_idx);
  3281. @brief
  3282. Asynchronous API that notifies the WINC with the Gain Table index from Flash that should use to configure the WiFi and BLE gains.
  3283. @return
  3284. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC,
  3285. and a negative value otherwise.
  3286. */
  3287. int8_t m2m_wifi_ble_set_gain_table(uint8_t table_idx);
  3288. /*!
  3289. @ingroup BLEAPI
  3290. @fn \
  3291. int8_t m2m_wifi_req_restrict_ble(void);
  3292. @brief
  3293. Asynchronous API to request restricting of BLE functionality by placing the BLE processor in a low power state.
  3294. It is recommended to do this if it is known that BLE functionality will not be used for any significant length of time.
  3295. @return
  3296. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC,
  3297. and a negative value otherwise.
  3298. @pre
  3299. - A Wi-Fi notification callback of type @ref tpfAppWifiCb MUST be implemented and registered
  3300. during initialization. Registration of the callback is done via the @ref m2m_wifi_init API.
  3301. */
  3302. int8_t m2m_wifi_req_restrict_ble(void);
  3303. /*!
  3304. @ingroup BLEAPI
  3305. @fn \
  3306. int8_t m2m_wifi_req_unrestrict_ble(void);
  3307. @brief
  3308. Asynchronous API to request un-restricting of BLE functionality by reverting the BLE processor to full power mode.
  3309. @return
  3310. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC,
  3311. and a negative value otherwise.
  3312. @pre
  3313. - A Wi-Fi notification callback of type @ref tpfAppWifiCb MUST be implemented and registered
  3314. during initialization. Registration of the callback is done via the @ref m2m_wifi_init API.
  3315. */
  3316. int8_t m2m_wifi_req_unrestrict_ble(void);
  3317. /** @defgroup VERSION Version
  3318. @brief
  3319. Describes the APIs for reading the version information of the WINC firmware.
  3320. @{
  3321. @defgroup VERSIONDEF Defines
  3322. @brief
  3323. Specifies the macros and defines used by the version APIs.
  3324. @defgroup VERSIONAPI Functions
  3325. @brief
  3326. Lists the APIs for reading the version information of the WINC firmware.
  3327. @}
  3328. */
  3329. /*!
  3330. @ingroup VERSIONAPI
  3331. @fn \
  3332. int8_t m2m_wifi_get_firmware_version(tstrM2mRev* pstrRev);
  3333. @brief
  3334. Synchronous API to obtain the firmware version currently running on the WINC.
  3335. @details
  3336. Get the Firmware version info from the active partition, as defined in the structure @ref tstrM2mRev.
  3337. @param[out] pstrRev
  3338. Pointer to a variable of type @ref tstrM2mRev, which contains the firmware version parameters.
  3339. @return
  3340. The function returns @ref M2M_SUCCESS for success and a negative value otherwise.
  3341. @pre
  3342. Must be called after initialization through the following function @ref m2m_wifi_init.
  3343. @sa
  3344. m2m_wifi_init
  3345. */
  3346. int8_t m2m_wifi_get_firmware_version(tstrM2mRev *pstrRev);
  3347. /*!
  3348. @ingroup VERSIONAPI
  3349. @fn \
  3350. int8_t m2m_ota_get_firmware_version(tstrM2mRev *pstrRev);
  3351. @brief
  3352. Synchronous API to obtain the firmware version of the WINC image that is stored in the inactive flash partition.
  3353. This is the image that would run on the WINC if @ref m2m_ota_switch_firmware or @ref m2m_ota_rollback were called,
  3354. followed by a reset of the WINC.
  3355. @param[out] pstrRev
  3356. Pointer to variable of type @ref tstrM2mRev which contains the ota fw version parameters.
  3357. @return
  3358. The function returns @ref M2M_SUCCESS for success and a negative value otherwise.
  3359. */
  3360. int8_t m2m_ota_get_firmware_version(tstrM2mRev *pstrRev);
  3361. /*!
  3362. @fn \
  3363. uint32_t m2m_wifi_get_chipId(void)
  3364. @brief
  3365. Synchronous API to obtain the firmware WINC chip ID.
  3366. @return
  3367. The function returns chipID > 0 or 0 for failure.
  3368. */
  3369. uint32_t m2m_wifi_get_chipId(void);
  3370. /*!
  3371. @ingroup OTAFUNCTIONS
  3372. @fn int8_t m2m_wifi_check_ota_rb(void);
  3373. @brief
  3374. Synchronous API to check presence and compatibility of the WINC image that is stored in the inactive flash partition.
  3375. This is the image that would run on the WINC if @ref m2m_ota_switch_firmware or @ref m2m_ota_rollback were called,
  3376. followed by a reset of the WINC.
  3377. @return
  3378. The function returns @ref M2M_SUCCESS for compatible image and a negative value otherwise.
  3379. */
  3380. int8_t m2m_wifi_check_ota_rb(void);
  3381. #ifdef __cplusplus
  3382. }
  3383. #endif
  3384. #endif /* __M2M_WIFI_H__ */