25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 

2770 satır
94 KiB

  1. /**
  2. *
  3. * \file
  4. *
  5. * \brief WINC3400 IoT Application Interface.
  6. *
  7. * Copyright (c) 2017-2018 Microchip Technology Inc. and its subsidiaries.
  8. *
  9. * \asf_license_start
  10. *
  11. * \page License
  12. *
  13. * Subject to your compliance with these terms, you may use Microchip
  14. * software and any derivatives exclusively with Microchip products.
  15. * It is your responsibility to comply with third party license terms applicable
  16. * to your use of third party software (including open source software) that
  17. * may accompany Microchip software.
  18. *
  19. * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
  20. * WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
  21. * INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
  22. * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
  23. * LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
  24. * LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
  25. * SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
  26. * POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
  27. * ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
  28. * RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
  29. * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
  30. *
  31. * \asf_license_stop
  32. *
  33. */
  34. /**@defgroup m2m_wifi WLAN
  35. */
  36. #ifndef __M2M_WIFI_H__
  37. #define __M2M_WIFI_H__
  38. /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
  39. INCLUDES
  40. *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
  41. #include "common/include/nm_common.h"
  42. #include "driver/include/m2m_types.h"
  43. #include "driver/source/nmdrv.h"
  44. /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
  45. MACROS
  46. *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
  47. /**@defgroup WlanEnums Enumeration/Typedefs
  48. * @ingroup m2m_wifi
  49. * @{*/
  50. /*!
  51. @enum \
  52. tenuWifiFrameType
  53. @brief
  54. Enumeration for Wi-Fi MAC frame type codes (2-bit)
  55. The following types are used to identify the type of frame sent or received.
  56. Each frame type constitutes a number of frame subtypes as defined in @ref tenuSubTypes to specify
  57. the exact type of frame.
  58. Values are defined as per the IEEE 802.11 standard.
  59. @remarks
  60. The following frame types are useful for advanced user usage when symbol CONF_MGMT is defined
  61. and the user application requires to monitor the frame transmission and reception.
  62. @warning
  63. This functionality is not supported by current WINC firmware.
  64. @see
  65. tenuSubTypes
  66. */
  67. typedef enum {
  68. MANAGEMENT = 0x00, /*!< Wi-Fi Management frame (Probe Req/Resp, Beacon, Association Req/Resp ...etc). */
  69. CONTROL = 0x04, /*!< Wi-Fi Control frame (eg. ACK frame). */
  70. DATA_BASICTYPE = 0x08, /*!< Wi-Fi Data frame. */
  71. RESERVED = 0x0C
  72. }tenuWifiFrameType;
  73. /*!
  74. @enum \
  75. tenuSubTypes
  76. @brief
  77. Enumeration for Wi-Fi MAC Frame subtype code (6-bit).
  78. The frame subtypes fall into one of the three frame type groups as defined in @ref tenuWifiFrameType
  79. (MANAGEMENT, CONTROL & DATA).
  80. Values are defined as per the IEEE 802.11 standard.
  81. @remarks
  82. The following sub-frame types are useful for advanced user usage when symbol CONF_MGMT is defined
  83. and the application developer requires to monitor the frame transmission and reception.
  84. @warning
  85. This functionality is not supported by current WINC firmware.
  86. @see
  87. tenuWifiFrameType
  88. */
  89. typedef enum {
  90. /* Sub-Types related to Management */
  91. ASSOC_REQ = 0x00, /*!< Management: Association Request */
  92. ASSOC_RSP = 0x10, /*!< Management: Association Response */
  93. REASSOC_REQ = 0x20, /*!< Management: Re-Association Request */
  94. REASSOC_RSP = 0x30, /*!< Management: Re-Association Response */
  95. PROBE_REQ = 0x40, /*!< Management: Probe Request */
  96. PROBE_RSP = 0x50, /*!< Management: Probe Response */
  97. BEACON = 0x80, /*!< Management: Beacon */
  98. ATIM = 0x90, /*!< Management: Announcement Traffic Information Map */
  99. DISASOC = 0xA0, /*!< Management: Disassociation */
  100. AUTH = 0xB0, /*!< Management: Authentication */
  101. DEAUTH = 0xC0, /*!< Management: Deauthentication */
  102. ACTION = 0xD0, /*!< Management: Action */
  103. /* Sub-Types related to Control */
  104. PS_POLL = 0xA4, /*!< Control: Power Save Poll*/
  105. RTS = 0xB4, /*!< Control: Request to Send */
  106. CTS = 0xC4, /*!< Control: Clear to Send */
  107. ACK = 0xD4, /*!< Control: Acknowledgement */
  108. CFEND = 0xE4, /*!< Control: End of Contention Free Period */
  109. CFEND_ACK = 0xF4, /*!< Control: ACK of data from STA + CFEND */
  110. BLOCKACK_REQ = 0x84, /*!< Control: Block Acknoweledgement Request */
  111. BLOCKACK = 0x94, /*!< Control: Block Acknowledgement */
  112. /* Sub-Types related to Data */
  113. DATA = 0x08, /*!< Data: A non-QoS data frame */
  114. DATA_ACK = 0x18, /*!< Data: Data + CF-Ack */
  115. DATA_POLL = 0x28, /*!< Data: Data + CF-Poll */
  116. DATA_POLL_ACK = 0x38, /*!< Data: Data + CF-Ack + CF-Poll*/
  117. NULL_FRAME = 0x48, /*!< Data: Null (no data) */
  118. CFACK = 0x58, /*!< Data: CF-Ack (no data) */
  119. CFPOLL = 0x68, /*!< Data: CF-Poll (no data) */
  120. CFPOLL_ACK = 0x78, /*!< Data: CF-Poll + CF-Ack (no data) */
  121. QOS_DATA = 0x88, /*!< Data: A QoS data frame */
  122. QOS_DATA_ACK = 0x98, /*!< Data: QoS data + CF-Ack */
  123. QOS_DATA_POLL = 0xA8, /*!< Data: QoS data + CF-Poll */
  124. QOS_DATA_POLL_ACK = 0xB8, /*!< Data: QoS data + CF-Ack + CF-Poll */
  125. QOS_NULL_FRAME = 0xC8, /*!< Data: QoS Null (no data) */
  126. QOS_CFPOLL = 0xE8, /*!< Data: Qos CF-Poll (no data) */
  127. QOS_CFPOLL_ACK = 0xF8 /*!< Data: QoS CF-Poll + CF-Ack (no data) */
  128. }tenuSubTypes;
  129. /*!
  130. @enum \
  131. tenuInfoElementId
  132. @brief
  133. Enumeration for the Wi-Fi Information Element(IE) IDs, which indicates the specific type of IEs.
  134. IEs are management frame information included in management frames.
  135. Values are defined as per the IEEE 802.11 standard.
  136. @warning
  137. This functionality is not supported by current WINC firmware.
  138. */
  139. typedef enum {
  140. ISSID = 0, /*!< Service Set Identifier (SSID) */
  141. ISUPRATES = 1, /*!< Supported Rates */
  142. IFHPARMS = 2, /*!< FH parameter set */
  143. IDSPARMS = 3, /*!< DS parameter set */
  144. ICFPARMS = 4, /*!< CF parameter set */
  145. ITIM = 5, /*!< Traffic Information Map */
  146. IIBPARMS = 6, /*!< IBSS parameter set */
  147. ICOUNTRY = 7, /*!< Country element. */
  148. IEDCAPARAMS = 12, /*!< EDCA parameter set */
  149. ITSPEC = 13, /*!< Traffic Specification */
  150. ITCLAS = 14, /*!< Traffic Classification */
  151. ISCHED = 15, /*!< Schedule. */
  152. ICTEXT = 16, /*!< Challenge Text */
  153. IPOWERCONSTRAINT = 32, /*!< Power Constraint. */
  154. IPOWERCAPABILITY = 33, /*!< Power Capability */
  155. ITPCREQUEST = 34, /*!< TPC Request */
  156. ITPCREPORT = 35, /*!< TPC Report */
  157. ISUPCHANNEL = 36, /*!< Supported channel list */
  158. ICHSWANNOUNC = 37, /*!< Channel Switch Announcement */
  159. IMEASUREMENTREQUEST = 38, /*!< Measurement request */
  160. IMEASUREMENTREPORT = 39, /*!< Measurement report */
  161. IQUIET = 40, /*!< Quiet element Info */
  162. IIBSSDFS = 41, /*!< IBSS DFS */
  163. IERPINFO = 42, /*!< ERP Information */
  164. ITSDELAY = 43, /*!< TS Delay */
  165. ITCLASPROCESS = 44, /*!< TCLAS Processing */
  166. IHTCAP = 45, /*!< HT Capabilities */
  167. IQOSCAP = 46, /*!< QoS Capability */
  168. IRSNELEMENT = 48, /*!< RSN Information Element */
  169. IEXSUPRATES = 50, /*!< Extended Supported Rates */
  170. IEXCHSWANNOUNC = 60, /*!< Extended Ch Switch Announcement */
  171. IHTOPERATION = 61, /*!< HT Information */
  172. ISECCHOFF = 62, /*!< Secondary Channel Offset */
  173. I2040COEX = 72, /*!< 20/40 Coexistence IE */
  174. I2040INTOLCHREPORT = 73, /*!< 20/40 Intolerant channel report */
  175. IOBSSSCAN = 74, /*!< OBSS Scan parameters */
  176. IEXTCAP = 127, /*!< Extended capability */
  177. IWMM = 221, /*!< WMM parameters */
  178. IWPAELEMENT = 221 /*!< WPA Information Element */
  179. }tenuInfoElementId;
  180. /*!
  181. @enum \
  182. tenuWifiCapability
  183. @brief
  184. Enumeration for capability Information field bit.
  185. The value of the capability information field from the 802.11 management frames received by the
  186. wireless LAN interface.
  187. Defining the capabilities of the Wi-Fi system.
  188. Values are defined as per the IEEE 802.11 standard.
  189. @warning
  190. This functionality is not supported by current WINC firmware.
  191. */
  192. typedef enum{
  193. ESS = 0x01, /*!< ESS capability */
  194. IBSS = 0x02, /*!< IBSS mode */
  195. POLLABLE = 0x04, /*!< CF Pollable */
  196. POLLREQ = 0x08, /*!< Request to be polled */
  197. PRIVACY = 0x10, /*!< WEP encryption supported */
  198. SHORTPREAMBLE = 0x20, /*!< Short Preamble is supported */
  199. SHORTSLOT = 0x400, /*!< Short Slot is supported */
  200. PBCC = 0x40, /*!< PBCC */
  201. CHANNELAGILITY = 0x80, /*!< Channel Agility */
  202. SPECTRUM_MGMT = 0x100, /*!< Spectrum Management */
  203. DSSS_OFDM = 0x2000 /*!< DSSS-OFDM */
  204. }tenuWifiCapability;
  205. /*!
  206. @typedef \
  207. tpfAppWifiCb
  208. @brief
  209. This is the main callback function for the Wi-Fi driver and is responsible for processing
  210. any M2M_WIFI events that are received on the Wi-Fi interface.
  211. These events (notifications) are usually received in response to earlier Wi-Fi requests such
  212. as @ref m2m_wifi_request_scan, and @ref m2m_wifi_connect.
  213. Most Wi-Fi APIs are asynchronous and calling them generates information that is passed back
  214. via this callback - for instance @ref m2m_wifi_request_scan will return a set of detected
  215. networks.
  216. Applications must ensure a callback function is registered with the Wi-Fi driver by
  217. calling @ref m2m_wifi_init.
  218. @param [in] u8MsgType
  219. Type of notification. Possible types are:
  220. - @ref M2M_WIFI_RESP_CON_STATE_CHANGED
  221. - @ref M2M_WIFI_RESP_CONN_INFO
  222. - @ref M2M_WIFI_REQ_DHCP_CONF
  223. - @ref M2M_WIFI_REQ_WPS
  224. - @ref M2M_WIFI_RESP_IP_CONFLICT
  225. - @ref M2M_WIFI_RESP_SCAN_DONE
  226. - @ref M2M_WIFI_RESP_SCAN_RESULT
  227. - @ref M2M_WIFI_RESP_CURRENT_RSSI
  228. - @ref M2M_WIFI_RESP_CLIENT_INFO
  229. - @ref M2M_WIFI_RESP_PROVISION_INFO
  230. - @ref M2M_WIFI_RESP_DEFAULT_CONNECT
  231. - @ref M2M_WIFI_RESP_ETHERNET_RX_PACKET (If Bypass mode is active)
  232. - @ref M2M_WIFI_RESP_WIFI_RX_PACKET (If monitoring mode is active)
  233. @param [in] pvMsg
  234. A pointer to a buffer containing the notification parameters (if any). It should be
  235. Casted to the data type associated with type of notification.
  236. @see
  237. tstrM2mWifiStateChanged
  238. tstrM2MWPSInfo
  239. tstrM2mScanDone
  240. tstrM2mWifiscanResult
  241. m2m_wifi_init
  242. */
  243. typedef void (*tpfAppWifiCb) (uint8 u8MsgType, void * pvMsg);
  244. /*!
  245. @typedef \
  246. tpfAppEthCb
  247. @brief
  248. Ethernet (Bypass mode) notification callback function receiving Bypass mode events as
  249. defined in the Wi-Fi responses enumeration @ref tenuM2mStaCmd.
  250. If bypass mode is enabled, applications must ensure this callback function is registered
  251. with the Wi-Fi driver by calling @ref m2m_wifi_init.
  252. @param [in] u8MsgType
  253. Type of notification. Possible types are:
  254. - @ref M2M_WIFI_RESP_ETHERNET_RX_PACKET
  255. @param [in] pvMsg
  256. A pointer to a buffer containing the notification parameters (if any). This must be
  257. casted to the data type uint8 *.
  258. @param [in] pvControlBuf
  259. A pointer to control buffer describing the accompanied message. This must be casted to
  260. the data type @ref tstrM2mIpCtrlBuf.
  261. @see
  262. m2m_wifi_init
  263. */
  264. typedef void (*tpfAppEthCb) (uint8 u8MsgType, void * pvMsg,void * pvCtrlBuf);
  265. /*!
  266. @typedef \
  267. tpfAppMonCb
  268. @brief
  269. Wi-Fi monitoring mode callback function. This function delivers all received wi-Fi packets
  270. to the application. Applications requiring to operate in the monitoring shall call the
  271. function m2m_wifi_enable_monitoring_mode, each frame received will invoke a single call to this
  272. callback function. Monitoring mode may be disabled by calling @ref m2m_wifi_disable_monitoring_mode.
  273. @param [in] pstrWifiRxPacket
  274. Pointer to a structure holding the Wi-Fi packet header parameters.
  275. @param [in] pu8Payload
  276. Pointer to the buffer holding the Wi-Fi packet payload information required by the application
  277. starting from the defined OFFSET by the application (when calling
  278. m2m_wifi_enable_monitoring_mode). Could hold a value of NULL, if the application does not need
  279. any data from the payload.
  280. @param [in] u16PayloadSize
  281. The size of the payload in bytes.
  282. @see
  283. m2m_wifi_enable_monitoring_mode
  284. @warning
  285. u16PayloadSize may not exceed the buffer size given through m2m_wifi_enable_monitoring_mode.
  286. */
  287. typedef void (*tpfAppMonCb) (tstrM2MWifiRxPacketInfo *pstrWifiRxPacket, uint8 * pu8Payload, uint16 u16PayloadSize);
  288. /**@}*/
  289. /*!
  290. @struct \
  291. tstrEthInitParam
  292. @brief
  293. Structure to hold Ethernet interface parameters.
  294. Structure is to be defined and have its attributes set, based on the application's functionality
  295. before a call is made to initialize the wi-fi operations by calling the
  296. @ref m2m_wifi_init function. Part of the wi-fi configuration structure @ref tstrWifiInitParam.
  297. Applications shouldn't need to define this structure, if the bypass mode is not defined.
  298. @see
  299. tpfAppEthCb
  300. tpfAppWifiCb
  301. m2m_wifi_init
  302. */
  303. typedef struct {
  304. tpfAppWifiCb pfAppWifiCb; /*!< Callback for wifi notifications. */
  305. tpfAppEthCb pfAppEthCb; /*!< Callback for Ethernet interface. */
  306. uint8 * au8ethRcvBuf; /*!< Pointer to Receive Buffer of Ethernet Packet */
  307. uint16 u16ethRcvBufSize; /*!< Size of Receive Buffer for Ethernet Packet */
  308. } tstrEthInitParam;
  309. /*!
  310. @struct \
  311. tstrM2mIpCtrlBuf
  312. @brief
  313. Structure holding the incoming buffer's data size information, indicating the data size of the
  314. buffer and the remaining buffer's data size. The data of the buffer which holds the packet sent
  315. to the host when in the bypass mode, is placed in the @ref tstrEthInitParam::au8ethRcvBuf attribute.
  316. This following information is retrieved in the host when an event
  317. @ref M2M_WIFI_RESP_ETHERNET_RX_PACKET is received in the Wi-Fi callback function
  318. @ref tpfAppWifiCb.
  319. The application is expected to use this structure's information to determine if there is still incoming data to be received from the firmware.
  320. @see
  321. tpfAppEthCb
  322. tstrEthInitParam
  323. @warning
  324. Make sure that bypass mode is defined before using @ref tstrM2mIpCtrlBuf
  325. */
  326. typedef struct{
  327. uint16 u16DataSize; /*!< Size of the received data in bytes. */
  328. uint16 u16RemainigDataSize; /*!< Size of the remaining data bytes to be delivered to host. */
  329. } tstrM2mIpCtrlBuf;
  330. /**
  331. @struct \
  332. tstrWifiInitParam
  333. @brief
  334. Structure, holding the Wi-fi configuration attributes such as the wi-fi callback , monitoring mode callback and Ethernet parameter initialization structure.
  335. Such configuration parameters are required to be set before calling the wi-fi initialization function @ref m2m_wifi_init.
  336. @ref pfAppWifiCb attribute must be set to handle the wi-fi callback operations.
  337. @ref pfAppMonCb attribute, is optional based on whether the application requires the monitoring mode configuration, and can there not
  338. be set before the initialization.
  339. @ref strEthInitParam structure, is another optional configuration based on whether the bypass mode is set.
  340. */
  341. typedef struct {
  342. tpfAppWifiCb pfAppWifiCb; /*!< Callback for Wi-Fi notifications. */
  343. tpfAppMonCb pfAppMonCb; /*!< Callback for monitoring interface. */
  344. tstrEthInitParam strEthInitParam ; /*!< Structure to hold Ethernet interface parameters. */
  345. uint8 GainTableIndex; /*!< Gain Table index to be used to configure the WiFi and BLE gains. */
  346. uint8 __PAD24__[3]; /*!< Padding bytes for forcing 4-byte alignment */
  347. } tstrWifiInitParam;
  348. /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
  349. FUNCTION PROTOTYPES
  350. *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
  351. /** \defgroup WLANAPI Functions
  352. * @ingroup m2m_wifi
  353. */
  354. #ifdef __cplusplus
  355. extern "C" {
  356. #endif
  357. /**@{*/
  358. /*!
  359. @fn \
  360. NMI_API void m2m_wifi_download_mode(void);
  361. @brief
  362. Synchronous API that prepares the WINC IC to enter firmware or certificate download mode.
  363. @details
  364. The WINC board is prepared for download, through initializations for the WINC driver including
  365. bus initializations and interrupt enabling, it also halts the chip, to allow for the firmware
  366. downloads. Firmware can be downloaded through a number of interfaces, UART, I2C and SPI.
  367. @return
  368. The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  369. */
  370. NMI_API sint8 m2m_wifi_download_mode(void);
  371. /*!
  372. @fn \
  373. NMI_API sint8 m2m_wifi_init(tstrWifiInitParam * pWifiInitParam);
  374. @brief
  375. Synchronous API that initialises the WINC driver.
  376. @details
  377. This function initializes the driver by registering the call back function for M2M_WIFI layer
  378. (also the call back function for bypass mode/monitoring mode if defined), initializing the host
  379. interface layer and the bus interfaces. Wi-Fi callback registering is essential to allow the
  380. handling of the events received, in response to the asynchronous Wi-Fi operations.
  381. Following are the possible Wi-Fi events that are expected to be received through the callback
  382. function (provided by the application):
  383. - @ref M2M_WIFI_RESP_CON_STATE_CHANGED
  384. - @ref M2M_WIFI_RESP_CONN_INFO
  385. - @ref M2M_WIFI_REQ_DHCP_CONF
  386. - @ref M2M_WIFI_REQ_WPS
  387. - @ref M2M_WIFI_RESP_IP_CONFLICT
  388. - @ref M2M_WIFI_RESP_SCAN_DONE
  389. - @ref M2M_WIFI_RESP_SCAN_RESULT
  390. - @ref M2M_WIFI_RESP_CURRENT_RSSI
  391. - @ref M2M_WIFI_RESP_CLIENT_INFO
  392. - @ref M2M_WIFI_RESP_PROVISION_INFO
  393. - @ref M2M_WIFI_RESP_DEFAULT_CONNECT
  394. - @ref M2M_WIFI_RESP_ETHERNET_RX_PACKET (if bypass mode is enabled)
  395. - @ref M2M_WIFI_RESP_WIFI_RX_PACKET (if monitoring mode is enabled)
  396. Any application using the WINC driver must call this function at the start of its main function.
  397. @param [in] pWifiInitParam
  398. This is a pointer to the @ref tstrWifiInitParam structure which contains pointers to the
  399. application WIFI layer callback, monitoring mode callback and @ref tstrEthInitParam
  400. structure (which contains initialisation settings for bypass mode).
  401. @return
  402. The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  403. @pre
  404. Prior to this function call, application users must provide a callback function responsible for
  405. receiving all the wi-fi events that are received on the M2M_WIFI layer.
  406. @warning
  407. Failure to successfully complete function indicates that the driver couldn't be initialized and
  408. a fatal error will prevent the application from proceeding.
  409. @see
  410. m2m_wifi_deinit
  411. tenuM2mStaCmd
  412. */
  413. NMI_API sint8 m2m_wifi_init(tstrWifiInitParam * pWifiInitParam);
  414. /*!
  415. @fn \
  416. NMI_API sint8 m2m_wifi_deinit(void * arg);
  417. @brief
  418. Synchronous API that de-initialises the WINC driver.
  419. @details
  420. This disables the host interface and frees any resources used by the M2M_WIFI layer.
  421. The function must be called in the during the final phases of closing the application to ensure
  422. that all resources have been correctly released.
  423. @param [in] arg
  424. Opaque argument, not used in current implementation. Application should use null.
  425. @return
  426. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC,
  427. and a negative value otherwise.
  428. */
  429. NMI_API sint8 m2m_wifi_deinit(void * arg);
  430. /*!
  431. @fn \
  432. sint8 m2m_wifi_init_hold(void);
  433. @brief
  434. First part of m2m_wifi_init, up to the point of initializing spi for flash access.
  435. @see
  436. m2m_wifi_init
  437. */
  438. sint8 m2m_wifi_init_hold(void);
  439. /*!
  440. @fn \
  441. sint8 m2m_wifi_init_start(tstrWifiInitParam * param);
  442. @brief
  443. Second part of m2m_wifi_init, continuing from where m2m_wifi_init_hold left off.
  444. @param [in] param
  445. Structure containing configration details
  446. @see
  447. m2m_wifi_init
  448. */
  449. sint8 m2m_wifi_init_start(tstrWifiInitParam * param);
  450. /*!
  451. @fn \
  452. sint8 m2m_wifi_reinit(tstrWifiInitParam * pWifiInitParam);
  453. @brief
  454. Deinitialize and reinitialize wifi. Resets the WINC.
  455. Parameter may be set to NULL, in which case there is no change to the parameters given at
  456. initialization.
  457. */
  458. sint8 m2m_wifi_reinit(tstrWifiInitParam * param);
  459. /*!
  460. @fn \
  461. sint8 m2m_wifi_reinit_hold(void);
  462. @brief
  463. First part of m2m_wifi_reinit, up to the point of initializing spi for flash access.
  464. @see
  465. m2m_wifi_reinit
  466. */
  467. sint8 m2m_wifi_reinit_hold(void);
  468. /*!
  469. @fn \
  470. sint8 m2m_wifi_reinit_start(tstrWifiInitParam * param);
  471. @brief
  472. Second part of m2m_wifi_reinit, continuing from where m2m_wifi_reinit_hold left off.
  473. @see
  474. m2m_wifi_reinit
  475. */
  476. sint8 m2m_wifi_reinit_start(tstrWifiInitParam * param);
  477. /*!
  478. @fn \
  479. NMI_API void m2m_wifi_yield(void);
  480. @brief
  481. Yield from processing more synchronous M2M events
  482. @details
  483. This function causes the synchronous M2M event handler function to yield from processing further
  484. events and return control to the caller.
  485. @return
  486. The function returns @ref M2M_SUCCESS for successful interrupt handling and a negative value
  487. otherwise.
  488. @pre
  489. Prior to receiving Wi-Fi interrupts, the WINC driver should have been successfully initialized
  490. by calling the @ref m2m_wifi_init function.
  491. @warning
  492. Failure to successfully complete this function indicates bus errors and hence a fatal error that will prevent the application from proceeding.
  493. */
  494. NMI_API void m2m_wifi_yield(void);
  495. /*!
  496. @fn \
  497. NMI_API sint8 m2m_wifi_handle_events(void * arg);
  498. @brief
  499. Synchronous M2M event handler function
  500. @details
  501. This function is responsible for handling interrupts received from the WINC firmware.
  502. Applications should call this function periodically in-order to receive the events that are to
  503. be handled by the callback functions implemented by the application.
  504. */
  505. NMI_API sint8 m2m_wifi_handle_events(void * arg);
  506. /*!
  507. @fn \
  508. NMI_API sint8 m2m_wifi_default_connect(void);
  509. @brief
  510. Asynchronous API that attempts to reconnect to the last-associated access point.
  511. @details
  512. An application calling this function will cause the firmware to attempt to reconnect to the
  513. access point with which it had last successfully connected. A failure to connect will result in
  514. a response of @ref M2M_WIFI_RESP_DEFAULT_CONNECT indicating a connection error as defined in the
  515. structure @ref tstrM2MDefaultConnResp.
  516. Possible errors are:
  517. - @ref M2M_DEFAULT_CONN_EMPTY_LIST indicating that the connection list is empty, or
  518. - @ref M2M_DEFAULT_CONN_SCAN_MISMATCH indicating a mismatch for the saved AP name.
  519. @return
  520. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC,
  521. and a negative value otherwise.
  522. @pre
  523. Prior to connecting, the WINC driver should have been successfully initialized by calling the
  524. @ref m2m_wifi_init function.
  525. @warning
  526. - This function maybe called in station mode only.
  527. - It is important to note that successful completion of a call to m2m_wifi_default_connect()
  528. does not guarantee success of the WIFI connection; a negative return value indicates only
  529. locally-detected errors.
  530. @see
  531. m2m_wifi_connect
  532. */
  533. NMI_API sint8 m2m_wifi_default_connect(void);
  534. /*!
  535. @fn \
  536. NMI_API sint8 m2m_wifi_connect(char *pcSsid, uint8 u8SsidLen, uint8 u8SecType, void *pvAuthInfo, uint16 u16Ch);
  537. @brief
  538. Asynchronous API to request connection to a specified access point
  539. @details
  540. Prior to a successful connection, the application developers must know the SSID, the security
  541. type, and the authentication parameters of the target access point; knowledge of the channel number
  542. is optional.
  543. The connection status will be indicated to the application via a
  544. @ref M2M_WIFI_RESP_CON_STATE_CHANGED event. The status will be one of those defined in
  545. @ref tenuM2mConnState withe @ref M2M_WIFI_CONNECTED indicating a successful connection.
  546. @param [in] pcSsid
  547. A buffer holding the SSID corresponding to the requested AP.
  548. @param [in] u8SsidLen
  549. Length of the given SSID (not including the NULL termination). A length less than ZERO or
  550. greater than the maximum defined SSID @ref M2M_MAX_SSID_LEN will result in a negative error
  551. @ref M2M_ERR_FAIL.
  552. @param [in] u8SecType
  553. Wi-Fi security type security for the network. It can be one of the following types:
  554. -@ref M2M_WIFI_SEC_OPEN
  555. -@ref M2M_WIFI_SEC_WEP
  556. -@ref M2M_WIFI_SEC_WPA_PSK
  557. -@ref M2M_WIFI_SEC_802_1X
  558. A value outside these possible values will result in a negative return error @ref M2M_ERR_FAIL.
  559. @param [in] pvAuthInfo
  560. Authentication parameters required for completing the connection. It is type is based on the
  561. security type. If the authentication parameters are NULL or are greater than the maximum length
  562. of the authentication parameters length as defined by @ref M2M_MAX_PSK_LEN a negative error will
  563. return @ref M2M_ERR_FAIL(-12) indicating connection failure.
  564. @param [in] u16Ch
  565. Wi-Fi channel number as defined in @ref tenuM2mScanCh enumeration. Specification of a channel
  566. number greater than @ref M2M_WIFI_CH_14 returns a negative error @ref M2M_ERR_FAIL(-12) unless
  567. the value is M2M_WIFI_CH_ALL (255). A channel number of M2M_WIFI_CH_ALL indicates that the
  568. firmware should scan all channels to find the SSID specified in parameter pcSsid.
  569. Failure to find the connection match will return a negative error
  570. @ref M2M_DEFAULT_CONN_SCAN_MISMATCH.
  571. @return
  572. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC,
  573. and a negative value otherwise.
  574. @pre
  575. 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
  576. @see
  577. tuniM2MWifiAuth
  578. tstr1xAuthCredentials
  579. tstrM2mWifiWepParams
  580. @warning
  581. - This function must be called in station mode only.
  582. - Successful completion of this function does not guarantee success of the WIFI connection, and
  583. a negative return value indicates only locally-detected errors.
  584. */
  585. NMI_API sint8 m2m_wifi_connect(char *pcSsid, uint8 u8SsidLen, uint8 u8SecType, void *pvAuthInfo, uint16 u16Ch);
  586. /*!
  587. @fn \
  588. NMI_API sint8 m2m_wifi_connect_sc(char *pcSsid, uint8 u8SsidLen, uint8 u8SecType, void *pvAuthInfo, uint16 u16Ch,uint8 u8SaveCred);
  589. @brief
  590. Asynchronous API to request connection to a specific AP with option to store credentials in
  591. flash.
  592. @details
  593. Prior to a successful connection, the application developers must know the SSID, the security
  594. type, and the authentication parameters of the target access point; knowledge of the channel number
  595. is optional.
  596. The connection status will be indicated to the application via a
  597. @ref M2M_WIFI_RESP_CON_STATE_CHANGED event. The status will be one of those defined in
  598. @ref tenuM2mConnState withe @ref M2M_WIFI_CONNECTED indicating a successful connection.
  599. The only difference between this function and @ref m2m_wifi_connect, is the option to save the
  600. acess point info ( SSID, password...etc) into flash.
  601. @param [in] pcSsid
  602. A buffer holding the SSID corresponding to the requested AP.
  603. @param [in] u8SsidLen
  604. Length of the given SSID (not including the NULL termination). A length less than ZERO or
  605. greater than the maximum defined SSID @ref M2M_MAX_SSID_LEN will result in a negative error
  606. @ref M2M_ERR_FAIL.
  607. @param [in] u8SecType
  608. Wi-Fi security type security for the network. It can be one of the following types:
  609. -@ref M2M_WIFI_SEC_OPEN
  610. -@ref M2M_WIFI_SEC_WEP
  611. -@ref M2M_WIFI_SEC_WPA_PSK
  612. -@ref M2M_WIFI_SEC_802_1X
  613. A value outside these possible values will result in a negative return error @ref M2M_ERR_FAIL.
  614. @param [in] pvAuthInfo
  615. Authentication parameters required for completing the connection. It is type is based on the
  616. security type. If the authentication parameters are NULL or are greater than the maximum length
  617. of the authentication parameters length as defined by @ref M2M_MAX_PSK_LEN a negative error will
  618. return @ref M2M_ERR_FAIL(-12) indicating connection failure.
  619. @param [in] u16Ch
  620. Wi-Fi channel number as defined in @ref tenuM2mScanCh enumeration. Specification of a channel
  621. number greater than @ref M2M_WIFI_CH_14 returns a negative error @ref M2M_ERR_FAIL(-12) unless
  622. the value is M2M_WIFI_CH_ALL (255). A channel number of M2M_WIFI_CH_ALL indicates that the
  623. firmware should scan all channels to find the SSID specified in parameter pcSsid.
  624. Failure to find the connection match will return a negative error
  625. @ref M2M_DEFAULT_CONN_SCAN_MISMATCH.
  626. @param [in] u8SaveCred
  627. Option to store the acess point SSID and password into the WINC flash memory or not.
  628. @pre
  629. 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
  630. @see
  631. tuniM2MWifiAuth
  632. tstr1xAuthCredentials
  633. tstrM2mWifiWepParams
  634. @warning
  635. - This function must be called in station mode only.
  636. - Successful completion of this function does not guarantee success of the WIFI connection, and
  637. a negative return value indicates only locally-detected errors.
  638. @return The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC,
  639. and a negative value otherwise.
  640. */
  641. NMI_API sint8 m2m_wifi_connect_sc(char *pcSsid, uint8 u8SsidLen, uint8 u8SecType, void *pvAuthInfo, uint16 u16Ch, uint8 u8SaveCred);
  642. /*!
  643. @fn \
  644. NMI_API sint8 m2m_wifi_disconnect(void);
  645. @brief
  646. Synchronous API to request disconnection from a network.
  647. @details
  648. This function will cause the WINC IC to disconnect from any currently connected access point.
  649. @return
  650. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC,
  651. and a negative value otherwise.
  652. @pre
  653. Disconnection 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.
  654. @warning
  655. This function must be called in station mode only.
  656. @see
  657. m2m_wifi_connect
  658. m2m_wifi_default_connect
  659. */
  660. NMI_API sint8 m2m_wifi_disconnect(void);
  661. /*!
  662. @fn \
  663. NMI_API sint8 m2m_wifi_start_provision_mode(tstrM2MAPConfig *pstrAPConfig, char *pcHttpServerDomainName, uint8 bEnableHttpRedirect);
  664. @brief
  665. Asynchronous API for control of Wi-Fi provisioning functionality.
  666. @details
  667. This function allows the application to start the WINC IC in 'provisioning mode', a special mode
  668. that triggers the WINC to create a Wi-Fi access point, DHCP server, and HTTP server.
  669. The HTTP server presents a provisioning page to a connected client which lists the access points
  670. detected in the vicinity of the WINC, and allows one of these to be selected and any appropriate
  671. credentials to be entered. This allows a headless system to be provisioned (configured to
  672. connect with an access point).
  673. Provisioning status is returned in a @ref M2M_WIFI_RESP_PROVISION_INFO event.
  674. @param [in] pstrAPConfig
  675. AP configuration parameters as defined in @ref tstrM2MAPConfig configuration structure.
  676. A NULL value passed in, will result in a negative error @ref M2M_ERR_FAIL.
  677. @param [in] pcHttpServerDomainName
  678. Domain name of the HTTP Provision WEB server which others will use to load the provisioning
  679. Home page. For example "wincconf.net".
  680. @param [in] bEnableHttpRedirect
  681. A flag to enable/disable the HTTP redirect feature. Possible values are:
  682. - Zero: DO NOT Use HTTP Redirect. In this case the associated device could open the
  683. provisioning page ONLY when the HTTP Provision URL of the WINC HTTP Server is
  684. correctly written on the browser.
  685. - Non-Zero: Use HTTP Redirect. In this case, all http traffic (http://URL) from the
  686. associated device (Phone, PC, ...etc) will be redirected to the WINC HTTP
  687. Provisioning Home page.
  688. @return
  689. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC,
  690. and a negative value otherwise.
  691. @pre
  692. - A Wi-Fi notification callback of type @ref tpfAppWifiCb MUST be implemented and registered at
  693. startup. Registering the callback is done through passing it to the initialization
  694. @ref m2m_wifi_init function.
  695. - The event @ref M2M_WIFI_RESP_CONN_INFO must be handled in the callback to receive the
  696. requested connection info.
  697. @see
  698. tpfAppWifiCb
  699. m2m_wifi_init
  700. M2M_WIFI_RESP_PROVISION_INFO
  701. m2m_wifi_stop_provision_mode
  702. tstrM2MAPConfig
  703. @warning
  704. DO Not use ".local" in the pcHttpServerDomainName.
  705. \section WIFIExample1 Example
  706. The example demonstrates a code snippet for how provisioning is triggered and the response event
  707. received accordingly.
  708. @code
  709. #include "m2m_wifi.h"
  710. #include "m2m_types.h"
  711. void wifi_event_cb(uint8 u8WiFiEvent, void * pvMsg)
  712. {
  713. switch(u8WiFiEvent)
  714. {
  715. case M2M_WIFI_RESP_PROVISION_INFO:
  716. {
  717. tstrM2MProvisionInfo *pstrProvInfo = (tstrM2MProvisionInfo*)pvMsg;
  718. if(pstrProvInfo->u8Status == M2M_SUCCESS)
  719. {
  720. m2m_wifi_connect((char*)pstrProvInfo->au8SSID, (uint8)strlen(pstrProvInfo->au8SSID), pstrProvInfo->u8SecType,
  721. pstrProvInfo->au8Password, M2M_WIFI_CH_ALL);
  722. printf("PROV SSID : %s\n",pstrProvInfo->au8SSID);
  723. printf("PROV PSK : %s\n",pstrProvInfo->au8Password);
  724. }
  725. else
  726. {
  727. printf("(ERR) Provisioning Failed\n");
  728. }
  729. }
  730. break;
  731. default:
  732. break;
  733. }
  734. }
  735. int main()
  736. {
  737. tstrWifiInitParam param;
  738. param.pfAppWifiCb = wifi_event_cb;
  739. if(!m2m_wifi_init(&param))
  740. {
  741. tstrM2MAPConfig apConfig;
  742. uint8 bEnableRedirect = 1;
  743. strcpy(apConfig.au8SSID, "WINC_SSID");
  744. apConfig.u8ListenChannel = 1;
  745. apConfig.u8SecType = M2M_WIFI_SEC_OPEN;
  746. apConfig.u8SsidHide = 0;
  747. // IP Address
  748. apConfig.au8DHCPServerIP[0] = 192;
  749. apConfig.au8DHCPServerIP[1] = 168;
  750. apConfig.au8DHCPServerIP[2] = 1;
  751. apConfig.au8DHCPServerIP[0] = 1;
  752. m2m_wifi_start_provision_mode(&apConfig, "atmelwincconf.com", bEnableRedirect);
  753. while(1)
  754. {
  755. m2m_wifi_handle_events(NULL);
  756. }
  757. }
  758. }
  759. @endcode
  760. */
  761. NMI_API sint8 m2m_wifi_start_provision_mode(tstrM2MAPConfig *pstrAPConfig, char *pcHttpServerDomainName, uint8 bEnableHttpRedirect);
  762. /*!
  763. @fn \
  764. sint8 m2m_wifi_stop_provision_mode(void);
  765. @brief
  766. Synchronous API for terminating provisioning mode on the WINC IC.
  767. @details
  768. This function will terminate any currently active provisioning mode on the WINC IC, returning the
  769. IC to idle.
  770. @return
  771. The function returns ZERO for success and a negative value otherwise.
  772. @pre
  773. An active provisioning session must be active before it is terminated through this function.
  774. @see
  775. m2m_wifi_start_provision_mode
  776. */
  777. NMI_API sint8 m2m_wifi_stop_provision_mode(void);
  778. /*!
  779. @fn \
  780. sint8 m2m_wifi_get_connection_info(void);
  781. @brief
  782. Asynchronous API for retrieving the WINC IC's connection status.
  783. @details
  784. Requests the connection status from the WINC IC including information regarding any access
  785. point to which it is currently connected, or any non-AP station that is connected to the WINC.
  786. All information will be returned to the application via the Wi-Fi notifiction callback and the
  787. event @ref M2M_WIFI_RESP_CONN_INFO.
  788. The connection info can be retrieved using the structure @ref tstrM2MConnInfo which contains:
  789. - Connection Security
  790. - Connection RSSI
  791. - Remote MAC address
  792. - Remote IP address
  793. - SSID of the network (in cases where the WINC is in non-AP mode)
  794. @return
  795. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC,
  796. and a negative value otherwise.
  797. @pre
  798. - A Wi-Fi notification callback of type @ref tpfAppWifiCb MUST be implemented and registered at
  799. startup. Registering the callback is done through passing it to the initialization
  800. @ref m2m_wifi_init function.
  801. - The event @ref M2M_WIFI_RESP_CONN_INFO must be handled in the callback to receive the
  802. requested connection info.
  803. @warning
  804. - In case of WINC AP mode or P2P mode, the SSID field shall be a NULL string.
  805. @see
  806. M2M_WIFI_RESP_CONN_INFO,
  807. tstrM2MConnInfo
  808. \section WIFIExample2 Example
  809. The code snippet shows an example of how wi-fi connection information is retrieved .
  810. @code
  811. #include "m2m_wifi.h"
  812. #include "m2m_types.h"
  813. void wifi_event_cb(uint8 u8WiFiEvent, void * pvMsg)
  814. {
  815. switch(u8WiFiEvent)
  816. {
  817. case M2M_WIFI_RESP_CONN_INFO:
  818. {
  819. tstrM2MConnInfo *pstrConnInfo = (tstrM2MConnInfo*)pvMsg;
  820. printf("CONNECTED AP INFO\n");
  821. printf("SSID : %s\n",pstrConnInfo->acSSID);
  822. printf("SEC TYPE : %d\n",pstrConnInfo->u8SecType);
  823. printf("Signal Strength : %d\n", pstrConnInfo->s8RSSI);
  824. printf("Local IP Address : %d.%d.%d.%d\n",
  825. pstrConnInfo->au8IPAddr[0] , pstrConnInfo->au8IPAddr[1], pstrConnInfo->au8IPAddr[2], pstrConnInfo->au8IPAddr[3]);
  826. }
  827. break;
  828. case M2M_WIFI_REQ_DHCP_CONF:
  829. {
  830. // Get the current AP information.
  831. m2m_wifi_get_connection_info();
  832. }
  833. break;
  834. default:
  835. break;
  836. }
  837. }
  838. int main()
  839. {
  840. tstrWifiInitParam param;
  841. param.pfAppWifiCb = wifi_event_cb;
  842. if(!m2m_wifi_init(&param))
  843. {
  844. // connect to the default AP
  845. m2m_wifi_default_connect();
  846. while(1)
  847. {
  848. m2m_wifi_handle_events(NULL);
  849. }
  850. }
  851. }
  852. @endcode
  853. */
  854. NMI_API sint8 m2m_wifi_get_connection_info(void);
  855. /*!
  856. @fn \
  857. NMI_API sint8 m2m_wifi_set_mac_address(uint8 au8MacAddress[6]);
  858. @brief
  859. Synchronous API for assigning a MAC address to the WINC IC.
  860. @details
  861. This function is intended to allow non-production software to assign a MAC address to the WINC IC.
  862. @param [in] au8MacAddress
  863. MAC Address to be provisioned to the WINC.
  864. @return
  865. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC,
  866. and a negative value otherwise.
  867. @warning
  868. This function is intended for development use only and not for use in production software.
  869. */
  870. NMI_API sint8 m2m_wifi_set_mac_address(uint8 au8MacAddress[6]);
  871. /*!
  872. @fn \
  873. NMI_API sint8 m2m_wifi_wps(uint8 u8TriggerType,const char * pcPinNumber);
  874. @brief
  875. Asynchronous API to engage the WINC IC's Wi-Fi Protected Setup (enrolee) function.
  876. @details
  877. This function can be called to make the WINC enter WPS (Wi-Fi Protected Setup) mode. The result
  878. is passed to the Wi-Fi notification callback with the event @ref M2M_WIFI_REQ_WPS.
  879. @param [in] u8TriggerType
  880. WPS Trigger method. This may be:
  881. - [WPS_PIN_TRIGGER](@ref WPS_PIN_TRIGGER) Push button method
  882. - [WPS_PBC_TRIGGER](@ref WPS_PBC_TRIGGER) Pin method
  883. @param [in] pcPinNumber
  884. Valid only if the u8TriggerType is WPS_PIN_TRIGGER, this parameter contains the PIN number.
  885. The number must follow the format as given in the WSC1.0 specification.
  886. @return
  887. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC,
  888. and a negative value otherwise.
  889. @warning
  890. This function is not supported in AP or P2P modes.
  891. @pre
  892. - A Wi-Fi notification callback of type (@ref tpfAppWifiCb MUST be implemented and registered at
  893. startup. Registering the callback is done through passing it to the
  894. [m2m_wifi_init](@ref m2m_wifi_init).
  895. - The event [M2M_WIFI_REQ_WPS](@ref M2M_WIFI_REQ_WPS) must be handled in the callback to receive
  896. the WPS status.
  897. - The WINC device MUST be in IDLE or STA mode. If AP or P2P mode is active, the WPS will not be
  898. performed.
  899. - The [m2m_wifi_handle_events](@ref m2m_wifi_handle_events) MUST be called to receive the responses
  900. in the callback.
  901. @see
  902. tpfAppWifiCb
  903. m2m_wifi_init
  904. M2M_WIFI_REQ_WPS
  905. tenuWPSTrigger
  906. tstrM2MWPSInfo
  907. \section WIFIExample3 Example
  908. The code snippet shows an example of how wifi WPS is triggered .
  909. @code
  910. #include "m2m_wifi.h"
  911. #include "m2m_types.h"
  912. void wifi_event_cb(uint8 u8WiFiEvent, void * pvMsg)
  913. {
  914. switch(u8WiFiEvent)
  915. {
  916. case M2M_WIFI_REQ_WPS:
  917. {
  918. tstrM2MWPSInfo *pstrWPS = (tstrM2MWPSInfo*)pvMsg;
  919. if(pstrWPS->u8AuthType != 0)
  920. {
  921. printf("WPS SSID : %s\n",pstrWPS->au8SSID);
  922. printf("WPS PSK : %s\n",pstrWPS->au8PSK);
  923. printf("WPS SSID Auth Type : %s\n",pstrWPS->u8AuthType == M2M_WIFI_SEC_OPEN ? "OPEN" : "WPA/WPA2");
  924. printf("WPS Channel : %d\n",pstrWPS->u8Ch + 1);
  925. // establish Wi-Fi connection
  926. m2m_wifi_connect((char*)pstrWPS->au8SSID, (uint8)m2m_strlen(pstrWPS->au8SSID),
  927. pstrWPS->u8AuthType, pstrWPS->au8PSK, pstrWPS->u8Ch);
  928. }
  929. else
  930. {
  931. printf("(ERR) WPS Is not enabled OR Timed out\n");
  932. }
  933. }
  934. break;
  935. default:
  936. break;
  937. }
  938. }
  939. int main()
  940. {
  941. tstrWifiInitParam param;
  942. param.pfAppWifiCb = wifi_event_cb;
  943. if(!m2m_wifi_init(&param))
  944. {
  945. // Trigger WPS in Push button mode.
  946. m2m_wifi_wps(WPS_PBC_TRIGGER, NULL);
  947. while(1)
  948. {
  949. m2m_wifi_handle_events(NULL);
  950. }
  951. }
  952. }
  953. @endcode
  954. */
  955. NMI_API sint8 m2m_wifi_ble_set_gain_table(uint8 table_idx);
  956. /*!
  957. @fn \
  958. NMI_API sint8 m2m_wifi_ble_set_gain_table(uint8 table_idx);
  959. @brief
  960. Asynchronous API that notifies the WINC with the Gain Table index from Flash that should use to configure the WiFi and BLE gains.
  961. @return
  962. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC,
  963. and a negative value otherwise.
  964. */
  965. NMI_API sint8 m2m_wifi_wps(uint8 u8TriggerType,const char *pcPinNumber);
  966. /*!
  967. @fn \
  968. NMI_API sint8 m2m_wifi_wps_disable(void);
  969. @brief
  970. Synchronous API that disables Wi-Fi Protected Setup mode in the WINC IC.
  971. @return
  972. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC,
  973. and a negative value otherwise.
  974. */
  975. NMI_API sint8 m2m_wifi_wps_disable(void);
  976. /*!
  977. @fn \
  978. NMI_API sint8 m2m_wifi_p2p(uint8 u8Channel);
  979. @brief
  980. Asynchronous API for enabling Wi-Fi Direct (P2P) mode in the WINC IC.
  981. @param [in] u8Channel
  982. P2P Listen RF channel.
  983. @return
  984. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC,
  985. and a negative value otherwise.
  986. @pre
  987. - A Wi-Fi notification callback of type @ref tpfAppWifiCb MUST be implemented and registered at
  988. initialization. Registering the callback
  989. is done through passing it to the @ref m2m_wifi_init.
  990. - The events @ref M2M_WIFI_RESP_CON_STATE_CHANGED and @ref M2M_WIFI_REQ_DHCP_CONF
  991. must be handled in the callback.
  992. - The @ref m2m_wifi_handle_events MUST be called to receive the responses in the callback.
  993. @warning
  994. - This function is not available in the WINC 3400
  995. - This function is not allowed in AP or STA modes.
  996. @see
  997. tpfAppWifiCb
  998. m2m_wifi_init
  999. M2M_WIFI_RESP_CON_STATE_CHANGED
  1000. M2M_WIFI_REQ_DHCP_CONF
  1001. tstrM2mWifiStateChanged
  1002. \section WIFIExample4 Example
  1003. The code snippet shows an example of how the p2p mode operates.
  1004. @code
  1005. #include "m2m_wifi.h"
  1006. #include "m2m_types.h"
  1007. void wifi_event_cb(uint8 u8WiFiEvent, void * pvMsg)
  1008. {
  1009. switch(u8WiFiEvent)
  1010. {
  1011. case M2M_WIFI_RESP_CON_STATE_CHANGED:
  1012. {
  1013. tstrM2mWifiStateChanged *pstrWifiState = (tstrM2mWifiStateChanged*)pvMsg;
  1014. M2M_INFO("Wifi State :: %s :: ErrCode %d\n", pstrWifiState->u8CurrState? "CONNECTED":"DISCONNECTED",pstrWifiState->u8ErrCode);
  1015. // Do something
  1016. }
  1017. break;
  1018. case M2M_WIFI_REQ_DHCP_CONF:
  1019. {
  1020. uint8 *pu8IPAddress = (uint8*)pvMsg;
  1021. printf("P2P IP Address \"%u.%u.%u.%u\"\n",pu8IPAddress[0],pu8IPAddress[1],pu8IPAddress[2],pu8IPAddress[3]);
  1022. }
  1023. break;
  1024. default:
  1025. break;
  1026. }
  1027. }
  1028. int main()
  1029. {
  1030. tstrWifiInitParam param;
  1031. param.pfAppWifiCb = wifi_event_cb;
  1032. if(!m2m_wifi_init(&param))
  1033. {
  1034. // Trigger P2P
  1035. m2m_wifi_p2p(M2M_WIFI_CH_1);
  1036. while(1)
  1037. {
  1038. m2m_wifi_handle_events(NULL);
  1039. }
  1040. }
  1041. }
  1042. @endcode
  1043. */
  1044. NMI_API sint8 m2m_wifi_p2p(uint8 u8Channel);
  1045. /*!
  1046. @fn \
  1047. NMI_API sint8 m2m_wifi_p2p_disconnect(void);
  1048. @brief
  1049. Synchronous API to disable Wi-Fi Direct (P2P) Mode on the WINC IC.
  1050. @return
  1051. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC,
  1052. and a negative value otherwise.
  1053. @see
  1054. m2m_wifi_p2p
  1055. */
  1056. NMI_API sint8 m2m_wifi_p2p_disconnect(void);
  1057. /*!
  1058. @fn \
  1059. NMI_API sint8 m2m_wifi_enable_ap(CONST tstrM2MAPConfig* pstrM2MAPConfig);
  1060. @brief
  1061. Asynchronous API to enable access point (AKA "hot-spot") mode on the WINC IC
  1062. @details
  1063. The WINC IC supports the ability to operate as an access point with the limitation that:
  1064. - only 1 station may be associated at any one time
  1065. - open system and WEP are the only security suites supported.
  1066. @param [in] pstrM2MAPConfig
  1067. A structure holding the AP configurations.
  1068. @return
  1069. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC,
  1070. and a negative value otherwise.
  1071. @warning
  1072. This function is not allowed in P2P or STA modes.
  1073. @pre
  1074. - A Wi-Fi notification callback of type @ref tpfAppWifiCb MUST be implemented and registered at initialization. Registering the callback
  1075. is done through passing it to the [m2m_wifi_init](@ref m2m_wifi_init).
  1076. - The event @ref M2M_WIFI_REQ_DHCP_CONF must be handled in the callback.
  1077. - The @ref m2m_wifi_handle_events MUST be called to receive the responses in the callback.
  1078. @see
  1079. tpfAppWifiCb
  1080. tenuM2mSecType
  1081. m2m_wifi_init
  1082. M2M_WIFI_REQ_DHCP_CONF
  1083. tstrM2mWifiStateChanged
  1084. tstrM2MAPConfig
  1085. \section WIFIExample5 Example
  1086. The code snippet demonstrates how the AP mode is enabled after the driver is initialized in the application's main function and the handling
  1087. of the event @ref M2M_WIFI_REQ_DHCP_CONF, to indicate successful connection.
  1088. @code
  1089. #include "m2m_wifi.h"
  1090. #include "m2m_types.h"
  1091. void wifi_event_cb(uint8 u8WiFiEvent, void * pvMsg)
  1092. {
  1093. switch(u8WiFiEvent)
  1094. {
  1095. case M2M_WIFI_REQ_DHCP_CONF:
  1096. {
  1097. uint8 *pu8IPAddress = (uint8*)pvMsg;
  1098. printf("Associated STA has IP Address \"%u.%u.%u.%u\"\n",pu8IPAddress[0],pu8IPAddress[1],pu8IPAddress[2],pu8IPAddress[3]);
  1099. }
  1100. break;
  1101. default:
  1102. break;
  1103. }
  1104. }
  1105. int main()
  1106. {
  1107. tstrWifiInitParam param;
  1108. param.pfAppWifiCb = wifi_event_cb;
  1109. if(!m2m_wifi_init(&param))
  1110. {
  1111. tstrM2MAPConfig apConfig;
  1112. strcpy(apConfig.au8SSID, "WINC_SSID");
  1113. apConfig.u8ListenChannel = 1;
  1114. apConfig.u8SecType = M2M_WIFI_SEC_OPEN;
  1115. apConfig.u8SsidHide = 0;
  1116. // IP Address
  1117. apConfig.au8DHCPServerIP[0] = 192;
  1118. apConfig.au8DHCPServerIP[1] = 168;
  1119. apConfig.au8DHCPServerIP[2] = 1;
  1120. apConfig.au8DHCPServerIP[0] = 1;
  1121. // Trigger AP
  1122. m2m_wifi_enable_ap(&apConfig);
  1123. while(1)
  1124. {
  1125. m2m_wifi_handle_events(NULL);
  1126. }
  1127. }
  1128. }
  1129. @endcode
  1130. */
  1131. NMI_API sint8 m2m_wifi_enable_ap(CONST tstrM2MAPConfig* pstrM2MAPConfig);
  1132. /*!
  1133. @fn \
  1134. NMI_API sint8 m2m_wifi_disable_ap(void);
  1135. @brief
  1136. Synchronous API to disable access point mode on the WINC IC.
  1137. @return
  1138. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC,
  1139. and a negative value otherwise.
  1140. @see
  1141. m2m_wifi_enable_ap
  1142. */
  1143. NMI_API sint8 m2m_wifi_disable_ap(void);
  1144. /*!
  1145. @fn \
  1146. NMI_API sint8 m2m_wifi_set_static_ip(tstrM2MIPConfig * pstrStaticIPConf);
  1147. @brief
  1148. Synchronous API to manually assign a (static) IP address to the WINC IC.
  1149. @details
  1150. Typically an infrastructure access point will be able to provide an IP address to all clients
  1151. after they associate. The WINC will request configuration via DHCP automatically after
  1152. successfully connecting to an access point. This function should only be called in the event
  1153. that the network has no DHCP server and the application knows the specifics of the network.
  1154. @param [in] pstrStaticIPConf
  1155. Pointer to a structure holding the static IP Configurations (IP, Gateway, subnet mask and
  1156. DNS address).
  1157. @return
  1158. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC,
  1159. and a negative value otherwise.
  1160. @pre
  1161. The application must first call @ref m2m_wifi_enable_dhcp to request that DHCP functionality is
  1162. disabled prior to calling this function.
  1163. @warning
  1164. Exercise caution using this function. DHCP is the preferred method for configuring IP addresses.
  1165. @see
  1166. tstrM2MIPConfig
  1167. */
  1168. NMI_API sint8 m2m_wifi_set_static_ip(tstrM2MIPConfig * pstrStaticIPConf);
  1169. /*!
  1170. @fn \
  1171. NMI_API sint8 m2m_wifi_request_dhcp_client(void);
  1172. @brief
  1173. Legacy (deprecated) Asynchronous API for starting a DHCP client on the WINC IC.
  1174. @details
  1175. This is a legacy API and is no longer supported. Calls to this API will not result in any
  1176. changes being made to the state of the WINC IC.
  1177. @return
  1178. This function always returns @ref M2M_SUCCESS.
  1179. @warning
  1180. - This function has been deprecated. DHCP is used automatically when the WINC IC connects.
  1181. */
  1182. NMI_API sint8 m2m_wifi_request_dhcp_client(void);
  1183. /*!
  1184. @fn \
  1185. NMI_API sint8 m2m_wifi_request_dhcp_server(uint8* addr);
  1186. @brief
  1187. Legacy (deprecated) Asynchronous function to start a DHCP client on the WINC IC.
  1188. @details
  1189. This is a legacy API and is no longer supported. Calls to this API will not result in any
  1190. changes being made to the state of the WINC IC.
  1191. @param [in] addr The address to issue to a connected client (only one client is supported)
  1192. @return
  1193. This function always returns @ref M2M_SUCCESS.
  1194. @warning
  1195. - This function has been deprecated. DHCP is used automatically when the WINC IC connects.
  1196. */
  1197. NMI_API sint8 m2m_wifi_request_dhcp_server(uint8* addr);
  1198. /*!
  1199. @fn \
  1200. NMI_API sint8 m2m_wifi_enable_dhcp(uint8 u8DhcpEn );
  1201. @brief
  1202. Asynchronous function to control the DHCP client functionality within the WINC IC.
  1203. @details
  1204. This function allows the application to control the behaviour of the DHCP client function within
  1205. the WINC IC once it has associated with an access point. DHCP client functionality is enabled by
  1206. default.
  1207. @param [in] u8DhcpEn
  1208. The state of the DHCP client feature after successful association with an access point:
  1209. - 0: DHCP client will be disabled after connection.
  1210. - 1: DHCP client will be enabled after connection.
  1211. @return
  1212. The function SHALL return 0 for success and a negative value otherwise.
  1213. @warning
  1214. - DHCP client is enabled by default
  1215. - This Function should be called to disable DHCP client operation before using @ref m2m_wifi_set_static_ip
  1216. @see
  1217. m2m_wifi_set_static_ip()
  1218. */
  1219. NMI_API sint8 m2m_wifi_enable_dhcp(uint8 u8DhcpEn );
  1220. /*!
  1221. @fn \
  1222. sint8 m2m_wifi_set_scan_options(tstrM2MScanOption* ptstrM2MScanOption)
  1223. @brief
  1224. Synchronous API for configuring the behaviour of the WINC IC's network scanning functions.
  1225. @details
  1226. This function allows the application to tune the scanning behaviour of the WINC IC using the
  1227. parameters described in @ref tstrM2MScanOption.
  1228. @param [in] ptstrM2MScanOption;
  1229. Pointer to the structure holding the Scan Parameters.
  1230. @return
  1231. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC,
  1232. and a negative value otherwise.
  1233. @see
  1234. tenuM2mScanCh
  1235. m2m_wifi_request_scan
  1236. tstrM2MScanOption
  1237. */
  1238. NMI_API sint8 m2m_wifi_set_scan_options(tstrM2MScanOption* ptstrM2MScanOption);
  1239. /*!
  1240. @fn \
  1241. sint8 m2m_wifi_set_scan_region(uint16 ScanRegion)
  1242. @brief
  1243. Synchronous API for configuring the regulatory restrictions that may affect the WINC ICs
  1244. scanning behaviour.
  1245. @details
  1246. This function sets a property called the scan region, a parameter that affects the range of
  1247. channels that the WINC IC may legally scan given a geographic region.
  1248. @param [in] ScanRegion
  1249. @return
  1250. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC,
  1251. and a negative value otherwise.
  1252. @see
  1253. tenuM2mScanRegion
  1254. m2m_wifi_request_scan
  1255. */
  1256. NMI_API sint8 m2m_wifi_set_scan_region(uint16 ScanRegion);
  1257. /*!
  1258. @fn \
  1259. NMI_API sint8 m2m_wifi_request_scan(uint8 ch);
  1260. @brief
  1261. Asynchronous API to request the WINC IC perform a scan for networks.
  1262. @details
  1263. Scan statuses are delivered to the application via the Wi-Fi event callback (@ref tpfAppWifiCb) in
  1264. three stages. The first step involves the event @ref M2M_WIFI_RESP_SCAN_DONE which, if successful,
  1265. provides the number of detected networks (access points). The application must then read the list
  1266. of access points via multiple calls to the asynchronous @ref m2m_wifi_req_scan_result API. For
  1267. each call to this function, the application will receive (step three) the event
  1268. @ref M2M_WIFI_RESP_SCAN_RESULT.
  1269. @param [in] ch
  1270. RF Channel ID for SCAN operation. It should be set according to tenuM2mScanCh, with a
  1271. value of @ref M2M_WIFI_CH_ALL to scan all channels.
  1272. @return
  1273. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC,
  1274. and a negative value otherwise.
  1275. @warning
  1276. This API is valid only for STA mode, it may be called regardless of connection state (connected
  1277. or disconnected).
  1278. @pre
  1279. - A Wi-Fi notification callback of type @ref tpfAppWifiCb MUST be implemented and registered at
  1280. initialization. Registration of the callback is done via @ref m2m_wifi_init.
  1281. - The events @ref M2M_WIFI_RESP_SCAN_DONE and @ref M2M_WIFI_RESP_SCAN_RESULT must be handled in
  1282. the (tpfAppWifiCb) callback.
  1283. - The @ref m2m_wifi_handle_events function must be called to receive the responses in the
  1284. callback.
  1285. @see M2M_WIFI_RESP_SCAN_DONE
  1286. @see M2M_WIFI_RESP_SCAN_RESULT
  1287. @see tpfAppWifiCb
  1288. @see tstrM2mWifiscanResult
  1289. @see tenuM2mScanCh
  1290. @see m2m_wifi_init
  1291. @see m2m_wifi_handle_events
  1292. @see m2m_wifi_req_scan_result
  1293. \section WIFIExample6 Example
  1294. The code snippet demonstrates an example of how the scan request is called from the application's main function and the handling of
  1295. the events received in response.
  1296. @code
  1297. #include "m2m_wifi.h"
  1298. #include "m2m_types.h"
  1299. void wifi_event_cb(uint8 u8WiFiEvent, void * pvMsg)
  1300. {
  1301. static uint8 u8ScanResultIdx = 0;
  1302. switch(u8WiFiEvent)
  1303. {
  1304. case M2M_WIFI_RESP_SCAN_DONE:
  1305. {
  1306. tstrM2mScanDone *pstrInfo = (tstrM2mScanDone*)pvMsg;
  1307. printf("Num of AP found %d\n",pstrInfo->u8NumofCh);
  1308. if(pstrInfo->s8ScanState == M2M_SUCCESS)
  1309. {
  1310. u8ScanResultIdx = 0;
  1311. if(pstrInfo->u8NumofCh >= 1)
  1312. {
  1313. m2m_wifi_req_scan_result(u8ScanResultIdx);
  1314. u8ScanResultIdx ++;
  1315. }
  1316. else
  1317. {
  1318. printf("No AP Found Rescan\n");
  1319. m2m_wifi_request_scan(M2M_WIFI_CH_ALL);
  1320. }
  1321. }
  1322. else
  1323. {
  1324. printf("(ERR) Scan fail with error <%d>\n",pstrInfo->s8ScanState);
  1325. }
  1326. }
  1327. break;
  1328. case M2M_WIFI_RESP_SCAN_RESULT:
  1329. {
  1330. tstrM2mWifiscanResult *pstrScanResult =(tstrM2mWifiscanResult*)pvMsg;
  1331. uint8 u8NumFoundAPs = m2m_wifi_get_num_ap_found();
  1332. printf(">>%02d RI %d SEC %s CH %02d BSSID %02X:%02X:%02X:%02X:%02X:%02X SSID %s\n",
  1333. pstrScanResult->u8index,pstrScanResult->s8rssi,
  1334. pstrScanResult->u8AuthType,
  1335. pstrScanResult->u8ch,
  1336. pstrScanResult->au8BSSID[0], pstrScanResult->au8BSSID[1], pstrScanResult->au8BSSID[2],
  1337. pstrScanResult->au8BSSID[3], pstrScanResult->au8BSSID[4], pstrScanResult->au8BSSID[5],
  1338. pstrScanResult->au8SSID);
  1339. if(u8ScanResultIdx < u8NumFoundAPs)
  1340. {
  1341. // Read the next scan result
  1342. m2m_wifi_req_scan_result(index);
  1343. u8ScanResultIdx ++;
  1344. }
  1345. }
  1346. break;
  1347. default:
  1348. break;
  1349. }
  1350. }
  1351. int main()
  1352. {
  1353. tstrWifiInitParam param;
  1354. param.pfAppWifiCb = wifi_event_cb;
  1355. if(!m2m_wifi_init(&param))
  1356. {
  1357. // Scan all channels
  1358. m2m_wifi_request_scan(M2M_WIFI_CH_ALL);
  1359. while(1)
  1360. {
  1361. m2m_wifi_handle_events(NULL);
  1362. }
  1363. }
  1364. }
  1365. @endcode
  1366. */
  1367. NMI_API sint8 m2m_wifi_request_scan(uint8 ch);
  1368. /*!
  1369. @fn \
  1370. sint8 m2m_wifi_request_scan_passive(uint8 ch);
  1371. @param [in] ch
  1372. RF Channel ID for SCAN operation. It should be set according to tenuM2mScanCh, with a
  1373. value of @ref M2M_WIFI_CH_ALL to scan all channels.
  1374. @warning
  1375. This function is not allowed in P2P or AP modes. It works only for STA mode (both connected or disconnected states).
  1376. @pre
  1377. - A Wi-Fi notification callback of type @ref tpfAppWifiCb MUST be implemented and registered at initialization. Registering the callback
  1378. is done through passing it to the @ref m2m_wifi_init.
  1379. - The events @ref M2M_WIFI_RESP_SCAN_DONE and @ref M2M_WIFI_RESP_SCAN_RESULT.
  1380. must be handled in the callback.
  1381. - The @ref m2m_wifi_handle_events function MUST be called to receive the responses in the callback.
  1382. @see m2m_wifi_request_scan
  1383. @see M2M_WIFI_RESP_SCAN_DONE
  1384. @see M2M_WIFI_RESP_SCAN_RESULT
  1385. @see tpfAppWifiCb
  1386. @see tstrM2MScanOption
  1387. @see tstrM2mWifiscanResult
  1388. @see tenuM2mScanCh
  1389. @see m2m_wifi_init
  1390. @see m2m_wifi_handle_events
  1391. @see m2m_wifi_req_scan_result
  1392. @return
  1393. The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  1394. */
  1395. sint8 m2m_wifi_request_scan_passive(uint8 ch);
  1396. /*!
  1397. @fn NMI_API uint8 m2m_wifi_get_num_ap_found(void);
  1398. @brief
  1399. Synchronous API to retrieve the number of AP's found during the last scan operation.
  1400. @details
  1401. This function allows the application to recover the number of access points discovered during
  1402. the most recent scan activity. This is achieved via a global variable in the WINC driver that
  1403. is populated when receiving the M2M_WIFI_RESP_SCAN_DONE event.
  1404. @return
  1405. Return the number of AP's found in the last Scan Request.
  1406. @see
  1407. m2m_wifi_request_scan
  1408. M2M_WIFI_RESP_SCAN_DONE
  1409. M2M_WIFI_RESP_SCAN_RESULT
  1410. @pre
  1411. - m2m_wifi_request_scan must be called first to ensure up to date results are available.
  1412. @warning
  1413. - This function must be called only in the wi-fi callback function when the events
  1414. @ref M2M_WIFI_RESP_SCAN_DONE or @ref M2M_WIFI_RESP_SCAN_RESULT are received. Calling this
  1415. function in any other place may result in undefined/outdated numbers.
  1416. \section WIFIExample7 Example
  1417. The code snippet demonstrates an example of how the scan request is called from the application's main function and the handling of
  1418. the events received in response.
  1419. @code
  1420. #include "m2m_wifi.h"
  1421. #include "m2m_types.h"
  1422. void wifi_event_cb(uint8 u8WiFiEvent, void * pvMsg)
  1423. {
  1424. static uint8 u8ScanResultIdx = 0;
  1425. switch(u8WiFiEvent)
  1426. {
  1427. case M2M_WIFI_RESP_SCAN_DONE:
  1428. {
  1429. tstrM2mScanDone *pstrInfo = (tstrM2mScanDone*)pvMsg;
  1430. printf("Num of AP found %d\n",pstrInfo->u8NumofCh);
  1431. if(pstrInfo->s8ScanState == M2M_SUCCESS)
  1432. {
  1433. u8ScanResultIdx = 0;
  1434. if(pstrInfo->u8NumofCh >= 1)
  1435. {
  1436. m2m_wifi_req_scan_result(u8ScanResultIdx);
  1437. u8ScanResultIdx ++;
  1438. }
  1439. else
  1440. {
  1441. printf("No AP Found Rescan\n");
  1442. m2m_wifi_request_scan(M2M_WIFI_CH_ALL);
  1443. }
  1444. }
  1445. else
  1446. {
  1447. printf("(ERR) Scan fail with error <%d>\n",pstrInfo->s8ScanState);
  1448. }
  1449. }
  1450. break;
  1451. case M2M_WIFI_RESP_SCAN_RESULT:
  1452. {
  1453. tstrM2mWifiscanResult *pstrScanResult =(tstrM2mWifiscanResult*)pvMsg;
  1454. uint8 u8NumFoundAPs = m2m_wifi_get_num_ap_found();
  1455. printf(">>%02d RI %d SEC %s CH %02d BSSID %02X:%02X:%02X:%02X:%02X:%02X SSID %s\n",
  1456. pstrScanResult->u8index,pstrScanResult->s8rssi,
  1457. pstrScanResult->u8AuthType,
  1458. pstrScanResult->u8ch,
  1459. pstrScanResult->au8BSSID[0], pstrScanResult->au8BSSID[1], pstrScanResult->au8BSSID[2],
  1460. pstrScanResult->au8BSSID[3], pstrScanResult->au8BSSID[4], pstrScanResult->au8BSSID[5],
  1461. pstrScanResult->au8SSID);
  1462. if(u8ScanResultIdx < u8NumFoundAPs)
  1463. {
  1464. // Read the next scan result
  1465. m2m_wifi_req_scan_result(index);
  1466. u8ScanResultIdx ++;
  1467. }
  1468. }
  1469. break;
  1470. default:
  1471. break;
  1472. }
  1473. }
  1474. int main()
  1475. {
  1476. tstrWifiInitParam param;
  1477. param.pfAppWifiCb = wifi_event_cb;
  1478. if(!m2m_wifi_init(&param))
  1479. {
  1480. // Scan all channels
  1481. m2m_wifi_request_scan(M2M_WIFI_CH_ALL);
  1482. while(1)
  1483. {
  1484. m2m_wifi_handle_events(NULL);
  1485. }
  1486. }
  1487. }
  1488. @endcode
  1489. */
  1490. NMI_API uint8 m2m_wifi_get_num_ap_found(void);
  1491. /*!
  1492. @fn NMI_API sint8 m2m_wifi_req_scan_result(uint8 index);
  1493. @brief
  1494. Asynchronous API to request the information of an access point discovered via scanning.
  1495. @details
  1496. This function allows the information of any discovered access point to be retrieved. When a
  1497. scan is completed, the application is informed of the number of networks (access points)
  1498. discovered. Calling this function with an index, N, will return the information for the Nth
  1499. access point. The information will be returned to the application via a
  1500. @ref M2M_WIFI_RESP_SCAN_RESULT event, and the response data may be obtained through casting
  1501. the pointer (pvMsg) to @ref tstrM2mWifiscanResult.
  1502. @param [in] index
  1503. Index for the requested result, the index range start from 0 till number of AP's found
  1504. @return
  1505. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC,
  1506. and a negative value otherwise.
  1507. @see
  1508. tstrM2mWifiscanResult
  1509. m2m_wifi_get_num_ap_found
  1510. m2m_wifi_request_scan
  1511. @pre
  1512. - @ref m2m_wifi_request_scan must be called first to ensure up to date results are available.
  1513. - A Wi-Fi notification callback of type @ref tpfAppWifiCb must be implemented and registered
  1514. in order to receive scan data after calling this function. Registration of the callback
  1515. is done via the @ref m2m_wifi_init function.
  1516. - The event @ref M2M_WIFI_RESP_SCAN_RESULT must be handled in the callback to receive the
  1517. requested connection information.
  1518. @warning
  1519. - This API is valid only for STA mode, it may be called regardless of connection state (connected
  1520. or disconnected).
  1521. - Calling this function without first issuing a scan request may lead to stale data being
  1522. recovered.
  1523. - Application code should refrain from introducing significant delays between issuing the scan
  1524. request and scan result requests.
  1525. \section WIFIExample8 Example
  1526. The code snippet demonstrates an example of how the scan request is called from the application's main function and the handling of
  1527. the events received in response.
  1528. @code
  1529. #include "m2m_wifi.h"
  1530. #include "m2m_types.h"
  1531. void wifi_event_cb(uint8 u8WiFiEvent, void * pvMsg)
  1532. {
  1533. static uint8 u8ScanResultIdx = 0;
  1534. switch(u8WiFiEvent)
  1535. {
  1536. case M2M_WIFI_RESP_SCAN_DONE:
  1537. {
  1538. tstrM2mScanDone *pstrInfo = (tstrM2mScanDone*)pvMsg;
  1539. printf("Num of AP found %d\n",pstrInfo->u8NumofCh);
  1540. if(pstrInfo->s8ScanState == M2M_SUCCESS)
  1541. {
  1542. u8ScanResultIdx = 0;
  1543. if(pstrInfo->u8NumofCh >= 1)
  1544. {
  1545. m2m_wifi_req_scan_result(u8ScanResultIdx);
  1546. u8ScanResultIdx ++;
  1547. }
  1548. else
  1549. {
  1550. printf("No AP Found Rescan\n");
  1551. m2m_wifi_request_scan(M2M_WIFI_CH_ALL);
  1552. }
  1553. }
  1554. else
  1555. {
  1556. printf("(ERR) Scan fail with error <%d>\n",pstrInfo->s8ScanState);
  1557. }
  1558. }
  1559. break;
  1560. case M2M_WIFI_RESP_SCAN_RESULT:
  1561. {
  1562. tstrM2mWifiscanResult *pstrScanResult =(tstrM2mWifiscanResult*)pvMsg;
  1563. uint8 u8NumFoundAPs = m2m_wifi_get_num_ap_found();
  1564. printf(">>%02d RI %d SEC %s CH %02d BSSID %02X:%02X:%02X:%02X:%02X:%02X SSID %s\n",
  1565. pstrScanResult->u8index,pstrScanResult->s8rssi,
  1566. pstrScanResult->u8AuthType,
  1567. pstrScanResult->u8ch,
  1568. pstrScanResult->au8BSSID[0], pstrScanResult->au8BSSID[1], pstrScanResult->au8BSSID[2],
  1569. pstrScanResult->au8BSSID[3], pstrScanResult->au8BSSID[4], pstrScanResult->au8BSSID[5],
  1570. pstrScanResult->au8SSID);
  1571. if(u8ScanResultIdx < u8NumFoundAPs)
  1572. {
  1573. // Read the next scan result
  1574. m2m_wifi_req_scan_result(index);
  1575. u8ScanResultIdx ++;
  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. // Scan all channels
  1590. m2m_wifi_request_scan(M2M_WIFI_CH_ALL);
  1591. while(1)
  1592. {
  1593. m2m_wifi_handle_events(NULL);
  1594. }
  1595. }
  1596. }
  1597. @endcode
  1598. */
  1599. NMI_API sint8 m2m_wifi_req_scan_result(uint8 index);
  1600. /*!
  1601. @fn NMI_API sint8 m2m_wifi_req_curr_rssi(void);
  1602. @brief
  1603. Asynchronous API to request the current Receive Signal Strength (RSSI) of the current connection.
  1604. @details
  1605. This function will result in the application receiving the RSSI via a
  1606. @ref M2M_WIFI_RESP_CURRENT_RSSI event.
  1607. @return
  1608. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC,
  1609. and a negative value otherwise.
  1610. @pre
  1611. - A Wi-Fi notification callback of type @ref tpfAppWifiCb MUST be implemented and registered
  1612. during initialization. Registration of the callback is done via the
  1613. [m2m_wifi_init](@ref m2m_wifi_init) API.
  1614. - The event @ref M2M_WIFI_RESP_CURRENT_RSSI must be handled in the callback.
  1615. \section WIFIExample9 Example
  1616. The code snippet demonstrates how the RSSI request is called in the application's main function and the handling of event received in the callback.
  1617. @code
  1618. #include "m2m_wifi.h"
  1619. #include "m2m_types.h"
  1620. void wifi_event_cb(uint8 u8WiFiEvent, void * pvMsg)
  1621. {
  1622. static uint8 u8ScanResultIdx = 0;
  1623. switch(u8WiFiEvent)
  1624. {
  1625. case M2M_WIFI_RESP_CURRENT_RSSI:
  1626. {
  1627. sint8 *rssi = (sint8*)pvMsg;
  1628. M2M_INFO("ch rssi %d\n",*rssi);
  1629. }
  1630. break;
  1631. default:
  1632. break;
  1633. }
  1634. }
  1635. int main()
  1636. {
  1637. tstrWifiInitParam param;
  1638. param.pfAppWifiCb = wifi_event_cb;
  1639. if(!m2m_wifi_init(&param))
  1640. {
  1641. // Scan all channels
  1642. m2m_wifi_req_curr_rssi();
  1643. while(1)
  1644. {
  1645. m2m_wifi_handle_events(NULL);
  1646. }
  1647. }
  1648. }
  1649. @endcode
  1650. */
  1651. NMI_API sint8 m2m_wifi_req_curr_rssi(void);
  1652. /*!
  1653. @fn NMI_API sint8 m2m_wifi_req_restrict_ble(void);
  1654. @brief
  1655. Asynchronous API to request restricting of BLE functionality by placing the BLE processor in a low power state.
  1656. It is recommended to do this if it is know that BLE functionality will not be used for any significant length of time.
  1657. @return
  1658. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC,
  1659. and a negative value otherwise.
  1660. @pre
  1661. - A Wi-Fi notification callback of type @ref tpfAppWifiCb MUST be implemented and registered
  1662. during initialization. Registration of the callback is done via the
  1663. [m2m_wifi_init](@ref m2m_wifi_init) API.
  1664. */
  1665. NMI_API sint8 m2m_wifi_req_restrict_ble(void);
  1666. /*!
  1667. @fn NMI_API sint8 m2m_wifi_req_unrestrict_ble(void);
  1668. @brief
  1669. Asynchronous API to request un-restricting of BLE functionality by reverting the BLE processor to full power mode.
  1670. @return
  1671. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC,
  1672. and a negative value otherwise.
  1673. @pre
  1674. - A Wi-Fi notification callback of type @ref tpfAppWifiCb MUST be implemented and registered
  1675. during initialization. Registration of the callback is done via the
  1676. [m2m_wifi_init](@ref m2m_wifi_init) API.
  1677. */
  1678. NMI_API sint8 m2m_wifi_req_unrestrict_ble(void);
  1679. /*!
  1680. @fn NMI_API sint8 m2m_wifi_get_otp_mac_address(uint8 *pu8MacAddr, uint8 * pu8IsValid);
  1681. @brief
  1682. Synchronous API to query the MAC address programmed into the WINC ICs OTP memory
  1683. @details
  1684. This function attempts to read the device's MAC address from the One Time Programmable (OTP)
  1685. memory on the IC. The presence (yes or no) of a MAC address in the OTP memory and, in the case
  1686. of it being present, its value are returned via RAM pointed to by the input arguments.
  1687. @param [out] pu8MacAddr
  1688. Output MAC address buffer 6 bytes in size. This is valid only if *pu8Valid equals 1.
  1689. @param [out] pu8IsValid
  1690. A boolean value set by the callee to indicate the validity of pu8MacAddr in OTP. If no MAC has
  1691. been programmed in the OTP the value of this parameter will be zero; otherwise it will be
  1692. non-zero.
  1693. @return
  1694. The function returns @ref M2M_SUCCESS for success and a negative value otherwise.
  1695. @see
  1696. m2m_wifi_get_mac_address
  1697. */
  1698. NMI_API sint8 m2m_wifi_get_otp_mac_address(uint8 *pu8MacAddr, uint8 * pu8IsValid);
  1699. /*!
  1700. @fn NMI_API sint8 m2m_wifi_get_mac_address(uint8 *pu8MacAddr)
  1701. @brief
  1702. Synchronous API to retrieve the MAC address currently in use on the device.
  1703. @details
  1704. This function obtains the MAC address that is currently in use by the device. If the function
  1705. returns with @ref M2M_SUCCESS then the content of the memory referenced by pu8MacAddr will be
  1706. populated with the 6 byte MAC address; otherwise, that memory will be left unchanged.
  1707. @param [out] pu8MacAddr
  1708. Pointer to a buffer in memory containing a 6-byte MAC address (provided function returns
  1709. MEM_SUCCESS)
  1710. @return
  1711. The function returns @ref M2M_SUCCESS for successful operation and a negative value otherwise.
  1712. @see
  1713. m2m_wifi_get_otp_mac_address
  1714. */
  1715. NMI_API sint8 m2m_wifi_get_mac_address(uint8 *pu8MacAddr);
  1716. /*!
  1717. @fn NMI_API sint8 m2m_wifi_set_sleep_mode(uint8 PsTyp, uint8 BcastEn);
  1718. @brief
  1719. Synchronous API to set the power-save mode of the WINC IC.
  1720. @param [in] PsTyp
  1721. Desired power saving mode. Supported types are defined in @ref tenuPowerSaveModes.
  1722. @param [in] BcastEn
  1723. Broadcast reception enable flag.
  1724. - If set to 1, the WINC IC will wake for each DTIM beacon to ensure broadcast traffic can be
  1725. received.
  1726. - If set to 0, the WINC IC will not wakeup at the DTIM beacon, instead it will wake every N
  1727. beacon periods as per the negotiated Listen Interval.
  1728. @return
  1729. The function returns @ref M2M_SUCCESS for successful operation and a negative value otherwise.
  1730. @see
  1731. tenuPowerSaveModes
  1732. m2m_wifi_get_sleep_mode
  1733. */
  1734. NMI_API sint8 m2m_wifi_set_sleep_mode(uint8 PsTyp, uint8 BcastEn);
  1735. /*!
  1736. @fn NMI_API sint8 m2m_wifi_request_sleep(uint32 u32SlpReqTime);
  1737. @brief
  1738. Asynchronous API to place the WINC IC into sleep mode for a specified period of time.
  1739. @details
  1740. This function allows a WINC IC that is running in M2M_PS_MANUAL mode to be placed into sleep
  1741. state for a specified period of time (measured in milliseconds).
  1742. @param [in] u32SlpReqTime
  1743. The time in ms that the WINC IC should sleep for
  1744. @return
  1745. The function returns @ref M2M_SUCCESS for successful operation and a negative value otherwise.
  1746. @warning
  1747. - This API is currently unsupported on the WINC3400
  1748. @see
  1749. tenuPowerSaveModes
  1750. m2m_wifi_set_sleep_mode
  1751. */
  1752. NMI_API sint8 m2m_wifi_request_sleep(uint32 u32SlpReqTime);
  1753. /*!
  1754. @fn NMI_API uint8 m2m_wifi_get_sleep_mode(void);
  1755. @brief
  1756. Synchronous API to retrieve the current power save mode of the WINC IC.
  1757. @return
  1758. The current operating power saving mode. The value will be one of those from the enumerated type
  1759. @ref tenuPowerSaveModes.
  1760. @see
  1761. tenuPowerSaveModes
  1762. m2m_wifi_set_sleep_mode
  1763. */
  1764. NMI_API uint8 m2m_wifi_get_sleep_mode(void);
  1765. #if 0
  1766. /*
  1767. * These two functions are for a mode in which two WINC ICs communicate with each other
  1768. * via probe request and probe response frames. This mode is not supported in WINC fw.
  1769. */
  1770. NMI_API sint8 m2m_wifi_req_client_ctrl(uint8 cmd);
  1771. NMI_API sint8 m2m_wifi_req_server_init(uint8 ch);
  1772. #endif
  1773. /*!
  1774. @fn NMI_API sint8 m2m_wifi_set_device_name(uint8 *pu8DeviceName, uint8 u8DeviceNameLength);
  1775. @brief
  1776. Asynchronous API to set the Wi-Fi Direct "Device Name" of the WINC IC
  1777. @param [in] pu8DeviceName
  1778. Buffer holding the device name.
  1779. @param [in] u8DeviceNameLength
  1780. Length of the device name. Should not exceed the maximum device name's length M2M_DEVICE_NAME_MAX.
  1781. @return
  1782. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC,
  1783. and a negative value otherwise.
  1784. */
  1785. NMI_API sint8 m2m_wifi_set_device_name(uint8 *pu8DeviceName, uint8 u8DeviceNameLength);
  1786. /*!
  1787. @fn NMI_API sint8 m2m_wifi_set_lsn_int(tstrM2mLsnInt * pstrM2mLsnInt);
  1788. @brief
  1789. Asynchronous API to set Wi-Fi listen interval for power save operation.
  1790. @param [in] pstrM2mLsnInt
  1791. Structure holding the listen interval configurations.
  1792. @return
  1793. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC,
  1794. and a negative value otherwise.
  1795. @pre
  1796. The function @ref m2m_wifi_set_sleep_mode shall be called first
  1797. @see
  1798. - tstrM2mLsnInt
  1799. - m2m_wifi_set_sleep_mode
  1800. */
  1801. NMI_API sint8 m2m_wifi_set_lsn_int(tstrM2mLsnInt *pstrM2mLsnInt);
  1802. /*!
  1803. @fn NMI_API sint8 m2m_wifi_enable_monitoring_mode(tstrM2MWifiMonitorModeCtrl *, uint8 *, uint16 , uint16);
  1804. @brief
  1805. Asynchronous call to enable Wi-Fi monitoring (promiscuous receive) mode.
  1806. @details
  1807. This function places the reciver into a mode where all frames (or those matching a set of filter
  1808. criteria) received on air are passed to the application.
  1809. A dedicated callback function, @ref tpfAppMonCb, must be registered to handle frames received in
  1810. promiscuous mode. This is done via an instance of a @ref tstrWifiInitParam structure and a call to
  1811. the @ref m2m_wifi_init function.
  1812. @param [in] pstrMtrCtrl
  1813. Pointer to @ref tstrM2MWifiMonitorModeCtrl structure holding the Filtering parameters.
  1814. @param [in] pu8PayloadBuffer
  1815. Pointer to a Buffer allocated by the application. The buffer SHALL hold the Data field of
  1816. the WIFI RX Packet (Or a part from it). If it is set to NULL, the WIFI data payload will
  1817. be discarded by the monitoring driver.
  1818. @param [in] u16BufferSize
  1819. The total size of the pu8PayloadBuffer in bytes.
  1820. @param [in] u16DataOffset
  1821. Starting offset in the DATA FIELD of the received WIFI packet. The application may be interested
  1822. in reading specific information from the received packet. It must assign the offset to the starting
  1823. position of it relative to the DATA payload start.\n
  1824. \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
  1825. \e packet, \e the \e u16Offset \e MUST \e be \e set \e to \e 0.
  1826. @return
  1827. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC,
  1828. and a negative value otherwise.
  1829. @warning
  1830. This mode available as sniffer ONLY, you can not be connected in any modes (Station, Access Point,
  1831. or P2P).
  1832. @see
  1833. - tstrM2MWifiMonitorModeCtrl
  1834. - tstrM2MWifiRxPacketInfo
  1835. - tstrWifiInitParam
  1836. - tenuM2mScanCh
  1837. - m2m_wifi_disable_monitoring_mode
  1838. \section WIFIExample10 Example
  1839. The example demonstrates the main function where-by the monitoring enable function is called after
  1840. the initialization of the driver and the packets are handled in the callback function.
  1841. @code
  1842. #include "m2m_wifi.h"
  1843. #include "m2m_types.h"
  1844. //Declare receive buffer
  1845. uint8 gmgmt[1600];
  1846. //Callback functions
  1847. void wifi_cb(uint8 u8WiFiEvent, void * pvMsg)
  1848. {
  1849. ;
  1850. }
  1851. void wifi_monitoring_cb(tstrM2MWifiRxPacketInfo *pstrWifiRxPacket, uint8 *pu8Payload, uint16 u16PayloadSize)
  1852. {
  1853. if((NULL != pstrWifiRxPacket) && (0 != u16PayloadSize)) {
  1854. if(MANAGEMENT == pstrWifiRxPacket->u8FrameType) {
  1855. M2M_INFO("***# MGMT PACKET #***\n");
  1856. } else if(DATA_BASICTYPE == pstrWifiRxPacket->u8FrameType) {
  1857. M2M_INFO("***# DATA PACKET #***\n");
  1858. } else if(CONTROL == pstrWifiRxPacket->u8FrameType) {
  1859. M2M_INFO("***# CONTROL PACKET #***\n");
  1860. }
  1861. }
  1862. }
  1863. int main()
  1864. {
  1865. //Register wifi_monitoring_cb
  1866. tstrWifiInitParam param;
  1867. param.pfAppWifiCb = wifi_cb;
  1868. param.pfAppMonCb = wifi_monitoring_cb;
  1869. nm_bsp_init();
  1870. if(!m2m_wifi_init(&param)) {
  1871. //Enable Monitor Mode with filter to receive all data frames on channel 1
  1872. tstrM2MWifiMonitorModeCtrl strMonitorCtrl = {0};
  1873. strMonitorCtrl.u8ChannelID = M2M_WIFI_CH_1;
  1874. strMonitorCtrl.u8FrameType = DATA_BASICTYPE;
  1875. strMonitorCtrl.u8FrameSubtype = M2M_WIFI_FRAME_SUB_TYPE_ANY; //Receive any subtype of data frame
  1876. m2m_wifi_enable_monitoring_mode(&strMonitorCtrl, gmgmt, sizeof(gmgmt), 0);
  1877. while(1) {
  1878. m2m_wifi_handle_events(NULL);
  1879. }
  1880. }
  1881. return 0;
  1882. }
  1883. @endcode
  1884. */
  1885. NMI_API sint8 m2m_wifi_enable_monitoring_mode(tstrM2MWifiMonitorModeCtrl *pstrMtrCtrl, uint8 *pu8PayloadBuffer,
  1886. uint16 u16BufferSize, uint16 u16DataOffset);
  1887. /*!
  1888. @fn NMI_API sint8 m2m_wifi_disable_monitoring_mode(void);
  1889. @brief
  1890. Asynchronous API to disable Wi-Fi monitoring (promiscuous receive) mode.
  1891. @return
  1892. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC,
  1893. and a negative value otherwise.
  1894. @see
  1895. m2m_wifi_enable_monitoring_mode
  1896. */
  1897. NMI_API sint8 m2m_wifi_disable_monitoring_mode(void);
  1898. /*!
  1899. @fn NMI_API sint8 m2m_wifi_send_wlan_pkt(uint8 *, uint16, uint16);
  1900. @brief
  1901. Asynchronous API to queue a raw Wi-Fi packet for transmission by the WINC IC.
  1902. @param [in] pu8WlanPacket
  1903. Pointer to a buffer holding the whole WIFI frame.
  1904. @param [in] u16WlanHeaderLength
  1905. The size of the WIFI packet header ONLY.
  1906. @param [in] u16WlanPktSize
  1907. The size of the whole bytes in packet.
  1908. @return
  1909. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC,
  1910. and a negative value otherwise.
  1911. @see
  1912. - m2m_wifi_enable_monitoring_mode
  1913. - m2m_wifi_disable_monitoring_mode
  1914. @warning
  1915. This function is only available in builds supporting monitoring mode.
  1916. */
  1917. NMI_API sint8 m2m_wifi_send_wlan_pkt(uint8 *pu8WlanPacket, uint16 u16WlanHeaderLength, uint16 u16WlanPktSize);
  1918. /*!
  1919. @fn NMI_API sint8 m2m_wifi_send_ethernet_pkt(uint8* pu8Packet,uint16 u16PacketSize)
  1920. @brief
  1921. Asynchronous API to queue an Ethernet packet for transmission by the WINC IC.
  1922. @param [in] pu8Packet
  1923. Pointer to a buffer holding the whole Ethernet frame.
  1924. @param [in] u16PacketSize
  1925. The size of the whole bytes in packet.
  1926. @return
  1927. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC,
  1928. and a negative value otherwise.
  1929. @see
  1930. - m2m_wifi_enable_monitoring_mode
  1931. - m2m_wifi_disable_monitoring_mode
  1932. @warning
  1933. This function is only available in builds supporting monitoring mode.
  1934. */
  1935. NMI_API sint8 m2m_wifi_send_ethernet_pkt(uint8* pu8Packet,uint16 u16PacketSize);
  1936. /*!
  1937. @fn NMI_API sint8 m2m_wifi_enable_sntp(uint8);
  1938. @brief
  1939. Asynchronous API to enable or disable the SNTP client running on the WINC IC.
  1940. @details
  1941. The SNTP client is enabled by default during chip initialisation. This function can be used to
  1942. disable or subsequently re-enable the service.
  1943. The service is capable of syncrhonising the WINC's system clock to the UTC time from a well-known
  1944. (and trusted) time server, for example "time.nist.gov". By default the SNTP client will update the
  1945. system time once every 24 hours. The ability to track the time accurately is important for various
  1946. applications such as checking expiry of X509 certificates during TLS session establishment.
  1947. It is highly recommended to leave SNTP enabled if there is no alternative source of timing
  1948. information. For systems including an RTC device, SNTP may not be needed and the WINC IC's time
  1949. may be set using the @ref m2m_wifi_set_sytem_time function.
  1950. @param [in] bEnable
  1951. Enables or disables the SNTP service
  1952. - '0' : disable SNTP
  1953. - '1' : enable SNTP
  1954. @return
  1955. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC,
  1956. and a negative value otherwise.
  1957. @see m2m_wifi_set_sytem_time
  1958. */
  1959. NMI_API sint8 m2m_wifi_enable_sntp(uint8 bEnable);
  1960. /*!
  1961. @fn NMI_API sint8 m2m_wifi_set_sytem_time(uint32);
  1962. @brief
  1963. Asynchronous function for setting the system time within the WINC IC.
  1964. @param [in] u32UTCSeconds
  1965. UTC value in seconds.
  1966. @return
  1967. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC,
  1968. and a negative value otherwise.
  1969. @see
  1970. - m2m_wifi_enable_sntp
  1971. - tstrSystemTime
  1972. @note
  1973. If there is an RTC on the host MCU, the SNTP may be disabled and the host may set the system
  1974. time within the firmware using the API @ref m2m_wifi_set_sytem_time.
  1975. */
  1976. NMI_API sint8 m2m_wifi_set_sytem_time(uint32 u32UTCSeconds);
  1977. /*!
  1978. @fn NMI_API sint8 m2m_wifi_get_sytem_time(void);
  1979. @brief
  1980. Asynchronous API to obtain the system time in use by the WINC IC.
  1981. @details
  1982. This function will request that the WINC IC send it's current system time to the application. The
  1983. information will arrive at the application via the @ref tpfAppWifiCb and event @ref
  1984. M2M_WIFI_RESP_GET_SYS_TIME.
  1985. @return
  1986. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC,
  1987. and a negative value otherwise.
  1988. @pre
  1989. - A Wi-Fi notification callback of type @ref tpfAppWifiCb MUST be implemented and registered
  1990. during initialization. Registration of the callback is done via the
  1991. [m2m_wifi_init](@ref m2m_wifi_init) API.
  1992. - The event @ref M2M_WIFI_RESP_GET_SYS_TIME must be handled in the callback.
  1993. @see
  1994. - m2m_wifi_enable_sntp
  1995. - tstrSystemTime
  1996. */
  1997. NMI_API sint8 m2m_wifi_get_sytem_time(void);
  1998. /*!
  1999. @fn NMI_API sint8 m2m_wifi_set_cust_InfoElement(uint8*);
  2000. @brief
  2001. Asynchronous API to add or remove a user-defined Information Element
  2002. @details
  2003. This function allows the application to provide a custom Information Element to the WINC IC that will
  2004. be included in all beacon and probe response frames.
  2005. @param [in] pau8M2mCustInfoElement
  2006. Pointer to Buffer containing the IE to be used. If null, this removes any current custom IE. If
  2007. non-null, the pointer must reference data in the following format:
  2008. @verbatim
  2009. --------------- ---------- ---------- ------------------- -------- -------- ----------- ----------------------
  2010. | Byte[0] | Byte[1] | Byte[2] | Byte[3:length1+2] | ..... | Byte[n] | Byte[n+1] | Byte[n+2:lengthx+2] |
  2011. |---------------|----------|----------|-------------------|-------- --------|-----------|------------------|
  2012. | #of all Bytes | IE1 ID | Length1 | Data1(Hex Coded) | ..... | IEx ID | Lengthx | Datax(Hex Coded) |
  2013. --------------- ---------- ---------- ------------------- -------- -------- ----------- ----------------------
  2014. @endverbatim
  2015. @return
  2016. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC,
  2017. and a negative value otherwise.
  2018. @warning
  2019. - Size of All elements combined must not exceed 255 byte.\n
  2020. - Used in Access Point Mode \n
  2021. \section WIFIExample11 Example
  2022. The example demonstrates how the information elements are set using this function.
  2023. @code
  2024. char elementData[21];
  2025. static char state = 0; // To Add, Append, and Delete
  2026. if(0 == state) { //Add 3 IEs
  2027. state = 1;
  2028. //Total Number of Bytes
  2029. elementData[0]=12;
  2030. //First IE
  2031. elementData[1]=200; elementData[2]=1; elementData[3]='A';
  2032. //Second IE
  2033. elementData[4]=201; elementData[5]=2; elementData[6]='B'; elementData[7]='C';
  2034. //Third IE
  2035. elementData[8]=202; elementData[9]=3; elementData[10]='D'; elementData[11]=0; elementData[12]='F';
  2036. } else if(1 == state) {
  2037. //Append 2 IEs to others, Notice that we keep old data in array starting with\n
  2038. //element 13 and total number of bytes increased to 20
  2039. state = 2;
  2040. //Total Number of Bytes
  2041. elementData[0]=20;
  2042. //Fourth IE
  2043. elementData[13]=203; elementData[14]=1; elementData[15]='G';
  2044. //Fifth IE
  2045. elementData[16]=204; elementData[17]=3; elementData[18]='X'; elementData[19]=5; elementData[20]='Z';
  2046. } else if(2 == state) { //Delete All IEs
  2047. state = 0;
  2048. //Total Number of Bytes
  2049. elementData[0]=0;
  2050. }
  2051. m2m_wifi_set_cust_InfoElement(elementData);
  2052. @endcode
  2053. */
  2054. NMI_API sint8 m2m_wifi_set_cust_InfoElement(uint8* pau8M2mCustInfoElement);
  2055. /*!
  2056. @fn NMI_API sint8 m2m_wifi_set_power_profile(uint8 u8PwrMode);
  2057. @brief Change the power profile mode
  2058. @param [in] u8PwrMode
  2059. Change the WINC power profile to one of the modes: PWR_LOW1, PWR_LOW2, PWR_HIGH, PWR_AUTO.
  2060. @return
  2061. The function SHALL return @ref M2M_SUCCESS for success and a negative value otherwise.
  2062. @see
  2063. tenuM2mPwrMode
  2064. @warning
  2065. May only be called after initialization, before any connection request, and may not be used to change
  2066. the power mode thereafter.
  2067. */
  2068. sint8 m2m_wifi_set_power_profile(uint8 u8PwrMode);
  2069. /*!
  2070. @fn NMI_API sint8 m2m_wifi_set_tx_power(uint8 u8TxPwrLevel);
  2071. @brief set the TX power tenuM2mTxPwrLevel
  2072. @param [in] u8TxPwrLevel
  2073. change the TX power tenuM2mTxPwrLevel
  2074. @return
  2075. The function SHALL return @ref M2M_SUCCESS for success and a negative value otherwise.
  2076. @sa tenuM2mTxPwrLevel
  2077. */
  2078. sint8 m2m_wifi_set_tx_power(uint8 u8TxPwrLevel);
  2079. /*!
  2080. @fn NMI_API sint8 m2m_wifi_enable_firmware_logs(uint8 u8Enable);
  2081. @brief
  2082. Enable or Disable logs in run time (Disable Firmware logs will enhance the firmware start-up time
  2083. and performance)
  2084. @param [in] u8Enable
  2085. Set 1 to enable the logs 0 for disable
  2086. @return
  2087. The function SHALL return @ref M2M_SUCCESS for success and a negative value otherwise.
  2088. @see
  2089. __DISABLE_FIRMWARE_LOGS__ (build option to disable logs from initializations)
  2090. */
  2091. sint8 m2m_wifi_enable_firmware_logs(uint8 u8Enable);
  2092. /*!
  2093. @fn NMI_API sint8 m2m_wifi_set_battery_voltage(uint8 u8BattVolt)
  2094. @brief
  2095. Set the battery voltage to update the firmware calculations
  2096. @param [in] dbBattVolt
  2097. Battery Voltage
  2098. @return
  2099. The function SHALL return @ref M2M_SUCCESS for success and a negative value otherwise.
  2100. */
  2101. sint8 m2m_wifi_set_battery_voltage(uint16 u16BattVoltx100);
  2102. /*!
  2103. @fn NMI_API sint8 m2m_wifi_ble_api_send(const uint8* const msg, const uint32 len);
  2104. @brief
  2105. Asynchronous API to send an encapsulated Atmel BLE message over the Wifi Host Interface
  2106. @param [in] msg
  2107. Pointer to the start of the BLE message to transfer down to the WINC
  2108. @param [in] len
  2109. The length of the message in octets
  2110. @return
  2111. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC,
  2112. and a negative value otherwise.
  2113. */
  2114. NMI_API sint8 m2m_wifi_ble_api_send(uint8* msg, uint32 len);
  2115. /*!
  2116. @fn NMI_API sint8 m2m_wifi_enable_mac_mcast(uint8 *, uint8);
  2117. @brief
  2118. Asynchronous API to add or remove MAC addresses in the multicast filter
  2119. @details
  2120. This function allows the application to configure the capability of the WINC IC to receive multicast
  2121. packets when operating in bypass mode.
  2122. @param [in] pu8MulticastMacAddress
  2123. Pointer to MAC address
  2124. @param [in] u8AddRemove
  2125. A flag to add or remove the MAC ADDRESS, based on the following values:
  2126. - 0 : remove MAC address
  2127. - 1 : add MAC address
  2128. @return
  2129. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC,
  2130. and a negative value otherwise.
  2131. @note
  2132. Maximum number of MAC addresses that could be added is 8.
  2133. @warning
  2134. This functionality is not supported by current WINC firmware.
  2135. */
  2136. NMI_API sint8 m2m_wifi_enable_mac_mcast(uint8* pu8MulticastMacAddress, uint8 u8AddRemove);
  2137. /*!
  2138. @fn NMI_API sint8 m2m_wifi_set_receive_buffer(void *, uint16);
  2139. @brief
  2140. Asynchronous API to set or change the size of the WINC IC's receive buffer
  2141. @param [in] pvBuffer
  2142. Pointer to Buffer to receive data. A NULL pointer causes a negative error @ref M2M_ERR_FAIL.
  2143. @param [in] u16BufferLen
  2144. Length of data to be received. Maximum length of data should not exceed the size defined by TCP/IP
  2145. defined as @ref SOCKET_BUFFER_MAX_LENGTH
  2146. @return
  2147. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC,
  2148. and a negative value otherwise.
  2149. @warning
  2150. This functionality is not supported by current WINC firmware.
  2151. */
  2152. NMI_API sint8 m2m_wifi_set_receive_buffer(void* pvBuffer,uint16 u16BufferLen);
  2153. /**@}*/
  2154. /**@defgroup VERSIONAPI Functions
  2155. @ingroup VERSION
  2156. */
  2157. /**@{*/
  2158. /*!
  2159. @fn uint32 m2m_wifi_get_chipId(void)
  2160. @brief
  2161. Synchronous API to obtain the firmware WINC chip ID
  2162. @return
  2163. The function SHALL return chipID > 0 or 0 for failure.
  2164. */
  2165. uint32 m2m_wifi_get_chipId(void);
  2166. /*!
  2167. @fn sint8 m2m_wifi_check_ota_rb(void);
  2168. @brief
  2169. Synchronous API to check presence and compatibility of the WINC image that is stored in the inactive flash partition.
  2170. This is the image that would run on the WINC IC if @ref m2m_ota_switch_firmware or @ref m2m_ota_rollback were called,
  2171. followed by a reset of the WINC IC.
  2172. @return
  2173. The function SHALL return @ref M2M_SUCCESS for compatible image and a negative value otherwise.
  2174. */
  2175. sint8 m2m_wifi_check_ota_rb(void);
  2176. /*!
  2177. @fn sint8 m2m_wifi_get_firmware_version(tstrM2mRev* pstrRev)
  2178. @brief
  2179. Synchronous API to obtain the firmware version currently running on the WINC IC
  2180. @param [out] pstrRev
  2181. pointer holds address of structure "tstrM2mRev" that contains the firmware version parameters
  2182. @return
  2183. The function SHALL return @ref M2M_SUCCESS for success and a negative value otherwise.
  2184. */
  2185. sint8 m2m_wifi_get_firmware_version(tstrM2mRev *pstrRev);
  2186. /*!
  2187. @fn \
  2188. NMI_API sint8 m2m_ota_get_firmware_version(tstrM2mRev *pstrRev);
  2189. @brief
  2190. Synchronous API to obtain the firmware version of the WINC image that is stored in the inactive flash partition.
  2191. This is the image that would run on the WINC IC if @ref m2m_ota_switch_firmware or @ref m2m_ota_rollback were called,
  2192. followed by a reset of the WINC IC.
  2193. @param [out] pstrRev
  2194. pointer holds address of structure "tstrM2mRev" that contains the ota fw version parameters
  2195. @return
  2196. The function SHALL return @ref M2M_SUCCESS for success and a negative value otherwise.
  2197. */
  2198. NMI_API sint8 m2m_ota_get_firmware_version(tstrM2mRev *pstrRev);
  2199. /**@}*/
  2200. /*!
  2201. * @fn sint8 m2m_wifi_prng_get_random_bytes(uint8 * pu8PRNGBuff,uint16 u16PRNGSize)
  2202. * @param [in] pu8PrngBuff
  2203. * Pointer to Buffer to receive data.
  2204. * Size greater than the maximum specified (@ref M2M_BUFFER_MAX_SIZE - sizeof(tstrPrng))
  2205. * causes a negative error @ref M2M_ERR_FAIL.
  2206. * @param [in] u16PrngSize
  2207. request size in bytes
  2208. * @return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  2209. */
  2210. sint8 m2m_wifi_prng_get_random_bytes(uint8 * pu8PrngBuff,uint16 u16PrngSize);
  2211. #ifdef __cplusplus
  2212. }
  2213. #endif
  2214. #endif /* __M2M_WIFI_H__ */