Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 

3001 рядки
110 KiB

  1. /**
  2. *
  3. * \file
  4. *
  5. * \brief WINC WLAN Application Interface.
  6. *
  7. * Copyright (c) 2015 - 2017 Atmel Corporation. All rights reserved.
  8. *
  9. * \asf_license_start
  10. *
  11. * \page License
  12. *
  13. * Redistribution and use in source and binary forms, with or without
  14. * modification, are permitted provided that the following conditions are met:
  15. *
  16. * 1. Redistributions of source code must retain the above copyright notice,
  17. * this list of conditions and the following disclaimer.
  18. *
  19. * 2. Redistributions in binary form must reproduce the above copyright notice,
  20. * this list of conditions and the following disclaimer in the documentation
  21. * and/or other materials provided with the distribution.
  22. *
  23. * 3. The name of Atmel may not be used to endorse or promote products derived
  24. * from this software without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
  27. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  28. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
  29. * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
  30. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  31. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  32. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  33. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  34. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  35. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  36. * POSSIBILITY OF SUCH DAMAGE.
  37. *
  38. * \asf_license_stop
  39. *
  40. */
  41. #ifndef __M2M_WIFI_H__
  42. #define __M2M_WIFI_H__
  43. /** \defgroup m2m_wifi WLAN
  44. *
  45. */
  46. /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
  47. INCLUDES
  48. *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
  49. #include "common/include/nm_common.h"
  50. #include "driver/include/m2m_types.h"
  51. #include "driver/source/nmdrv.h"
  52. #ifdef CONF_MGMT
  53. /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
  54. MACROS
  55. *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
  56. /**@defgroup WlanEnums DataTypes
  57. * @ingroup m2m_wifi
  58. * @{*/
  59. /*!
  60. @enum \
  61. tenuWifiFrameType
  62. @brief
  63. Enumeration for Wi-Fi MAC frame type codes (2-bit)
  64. The following types are used to identify the type of frame sent or received.
  65. Each frame type constitutes a number of frame subtypes as defined in @ref tenuSubTypes to specify the exact type of
  66. frame. Values are defined as per the IEEE 802.11 standard.
  67. @remarks
  68. The following frame types are useful for advanced user usage when monitoring mode is used (defining @ref CONF_MGMT)
  69. and the user application requires to monitor the frame transmission and reception.
  70. @see
  71. tenuSubTypes
  72. */
  73. typedef enum {
  74. MANAGEMENT = 0x00,
  75. /*!< Wi-Fi Management frame (Probe Req/Resp, Beacon, Association Req/Resp ...etc).
  76. */
  77. CONTROL = 0x04,
  78. /*!< Wi-Fi Control frame (eg. ACK frame).
  79. */
  80. DATA_BASICTYPE = 0x08,
  81. /*!< Wi-Fi Data frame.
  82. */
  83. RESERVED = 0x0C,
  84. M2M_WIFI_FRAME_TYPE_ANY = 0xFF
  85. /*!< Set monitor mode to receive any of the frames types
  86. */
  87. } tenuWifiFrameType;
  88. /*!
  89. @enum \
  90. tenuSubTypes
  91. @brief
  92. Enumeration for Wi-Fi MAC Frame subtype code (6-bit).
  93. The frame subtypes fall into one of the three frame type groups as defined in @ref tenuWifiFrameType
  94. (MANAGEMENT, CONTROL & DATA).
  95. Values are defined as per the IEEE 802.11 standard.
  96. @remarks
  97. The following sub-frame types are useful for advanced user usage when @ref CONF_MGMT is defined
  98. and the application developer requires to monitor the frame transmission and reception.
  99. @see
  100. tenuWifiFrameType
  101. tstrM2MWifiMonitorModeCtrl
  102. */
  103. typedef enum {
  104. /*!< Sub-Types related to Management Sub-Types */
  105. ASSOC_REQ = 0x00,
  106. ASSOC_RSP = 0x10,
  107. REASSOC_REQ = 0x20,
  108. REASSOC_RSP = 0x30,
  109. PROBE_REQ = 0x40,
  110. PROBE_RSP = 0x50,
  111. BEACON = 0x80,
  112. ATIM = 0x90,
  113. DISASOC = 0xA0,
  114. AUTH = 0xB0,
  115. DEAUTH = 0xC0,
  116. ACTION = 0xD0,
  117. /**@{*/
  118. /* Sub-Types related to Control */
  119. PS_POLL = 0xA4,
  120. RTS = 0xB4,
  121. CTS = 0xC4,
  122. ACK = 0xD4,
  123. CFEND = 0xE4,
  124. CFEND_ACK = 0xF4,
  125. BLOCKACK_REQ = 0x84,
  126. BLOCKACK = 0x94,
  127. /**@{*/
  128. /* Sub-Types related to Data */
  129. DATA = 0x08,
  130. DATA_ACK = 0x18,
  131. DATA_POLL = 0x28,
  132. DATA_POLL_ACK = 0x38,
  133. NULL_FRAME = 0x48,
  134. CFACK = 0x58,
  135. CFPOLL = 0x68,
  136. CFPOLL_ACK = 0x78,
  137. QOS_DATA = 0x88,
  138. QOS_DATA_ACK = 0x98,
  139. QOS_DATA_POLL = 0xA8,
  140. QOS_DATA_POLL_ACK = 0xB8,
  141. QOS_NULL_FRAME = 0xC8,
  142. QOS_CFPOLL = 0xE8,
  143. QOS_CFPOLL_ACK = 0xF8,
  144. M2M_WIFI_FRAME_SUB_TYPE_ANY = 0xFF
  145. /*!< Set monitor mode to receive any of the frames types
  146. */
  147. } tenuSubTypes;
  148. /*!
  149. @enum \
  150. tenuInfoElementId
  151. @brief
  152. Enumeration for the Wi-Fi Information Element(IE) IDs, which indicates the specific type of IEs.
  153. IEs are management frame information included in management frames.
  154. Values are defined as per the IEEE 802.11 standard.
  155. */
  156. typedef enum {
  157. ISSID = 0,
  158. /*!< Service Set Identifier (SSID)
  159. */
  160. ISUPRATES = 1,
  161. /*!< Supported Rates
  162. */
  163. IFHPARMS = 2,
  164. /*!< FH parameter set
  165. */
  166. IDSPARMS = 3,
  167. /*!< DS parameter set
  168. */
  169. ICFPARMS = 4,
  170. /*!< CF parameter set
  171. */
  172. ITIM = 5,
  173. /*!< Traffic Information Map
  174. */
  175. IIBPARMS = 6,
  176. /*!< IBSS parameter set
  177. */
  178. ICOUNTRY = 7,
  179. /*!< Country element.
  180. */
  181. IEDCAPARAMS = 12,
  182. /*!< EDCA parameter set
  183. */
  184. ITSPEC = 13,
  185. /*!< Traffic Specification
  186. */
  187. ITCLAS = 14,
  188. /*!< Traffic Classification
  189. */
  190. ISCHED = 15,
  191. /*!< Schedule.
  192. */
  193. ICTEXT = 16,
  194. /*!< Challenge Text
  195. */
  196. IPOWERCONSTRAINT = 32,
  197. /*!< Power Constraint.
  198. */
  199. IPOWERCAPABILITY = 33,
  200. /*!< Power Capability
  201. */
  202. ITPCREQUEST = 34,
  203. /*!< TPC Request
  204. */
  205. ITPCREPORT = 35,
  206. /*!< TPC Report
  207. */
  208. ISUPCHANNEL = 36,
  209. /* Supported channel list
  210. */
  211. ICHSWANNOUNC = 37,
  212. /*!< Channel Switch Announcement
  213. */
  214. IMEASUREMENTREQUEST = 38,
  215. /*!< Measurement request
  216. */
  217. IMEASUREMENTREPORT = 39,
  218. /*!< Measurement report
  219. */
  220. IQUIET = 40,
  221. /*!< Quiet element Info
  222. */
  223. IIBSSDFS = 41,
  224. /*!< IBSS DFS
  225. */
  226. IERPINFO = 42,
  227. /*!< ERP Information
  228. */
  229. ITSDELAY = 43,
  230. /*!< TS Delay
  231. */
  232. ITCLASPROCESS = 44,
  233. /*!< TCLAS Processing
  234. */
  235. IHTCAP = 45,
  236. /*!< HT Capabilities
  237. */
  238. IQOSCAP = 46,
  239. /*!< QoS Capability
  240. */
  241. IRSNELEMENT = 48,
  242. /*!< RSN Information Element
  243. */
  244. IEXSUPRATES = 50,
  245. /*!< Extended Supported Rates
  246. */
  247. IEXCHSWANNOUNC = 60,
  248. /*!< Extended Ch Switch Announcement
  249. */
  250. IHTOPERATION = 61,
  251. /*!< HT Information
  252. */
  253. ISECCHOFF = 62,
  254. /*!< Secondary Channel Offset
  255. */
  256. I2040COEX = 72,
  257. /*!< 20/40 Coexistence IE
  258. */
  259. I2040INTOLCHREPORT = 73,
  260. /*!< 20/40 Intolerant channel report
  261. */
  262. IOBSSSCAN = 74,
  263. /*!< OBSS Scan parameters
  264. */
  265. IEXTCAP = 127,
  266. /*!< Extended capability
  267. */
  268. IWMM = 221,
  269. /*!< WMM parameters
  270. */
  271. IWPAELEMENT = 221
  272. /*!< WPA Information Element
  273. */
  274. } tenuInfoElementId;
  275. /*!
  276. @struct \
  277. tenuWifiCapability
  278. @brief
  279. Enumeration for capability Information field bit.
  280. The value of the capability information field from the 802.11 management frames received by the wireless LAN
  281. interface. Defining the capabilities of the Wi-Fi system. Values are defined as per the IEEE 802.11 standard.
  282. @details
  283. Capabilities:-
  284. ESS/IBSS : Defines whether a frame is coming from an AP or not.
  285. POLLABLE : CF Poll-able
  286. POLLREQ : Request to be polled
  287. PRIVACY : WEP encryption supported
  288. SHORTPREAMBLE : Short Preamble is supported
  289. SHORTSLOT : Short Slot is supported
  290. PBCC :PBCC
  291. CHANNELAGILITY :Channel Agility
  292. SPECTRUM_MGMT :Spectrum Management
  293. DSSS_OFDM : DSSS-OFDM
  294. */
  295. typedef enum {
  296. ESS = 0x01,
  297. /*!< ESS capability
  298. */
  299. IBSS = 0x02,
  300. /*!< IBSS mode
  301. */
  302. POLLABLE = 0x04,
  303. /*!< CF Pollable
  304. */
  305. POLLREQ = 0x08,
  306. /*!< Request to be polled
  307. */
  308. PRIVACY = 0x10,
  309. /*!< WEP encryption supported
  310. */
  311. SHORTPREAMBLE = 0x20,
  312. /*!< Short Preamble is supported
  313. */
  314. SHORTSLOT = 0x400,
  315. /*!< Short Slot is supported
  316. */
  317. PBCC = 0x40,
  318. /*!< PBCC
  319. */
  320. CHANNELAGILITY = 0x80,
  321. /*!< Channel Agility
  322. */
  323. SPECTRUM_MGMT = 0x100,
  324. /*!< Spectrum Management
  325. */
  326. DSSS_OFDM = 0x2000
  327. /*!< DSSS-OFDM
  328. */
  329. } tenuWifiCapability;
  330. #endif
  331. /*!
  332. @typedef \
  333. tpfAppWifiCb
  334. @brief
  335. Wi-Fi's main callback function handler, for handling the M2M_WIFI events received on the Wi-Fi
  336. interface. Such notifications are received in response to Wi-Fi/P2P operations such as @ref m2m_wifi_request_scan,
  337. @ref m2m_wifi_connect.
  338. Wi-Fi/P2P operations are implemented in an asynchronous mode, and all incoming information/status
  339. are to be handled through this callback function when the corresponding notification is received.
  340. Applications are expected to assign this wi-fi callback function by calling @ref m2m_wifi_init
  341. @param [in] u8MsgType
  342. Type of notifications. Possible types are:
  343. /ref M2M_WIFI_RESP_CON_STATE_CHANGED
  344. /ref M2M_WIFI_RESP_CONN_INFO
  345. /ref M2M_WIFI_REQ_DHCP_CONF
  346. /ref M2M_WIFI_REQ_WPS
  347. /ref M2M_WIFI_RESP_IP_CONFLICT
  348. /ref M2M_WIFI_RESP_SCAN_DONE
  349. /ref M2M_WIFI_RESP_SCAN_RESULT
  350. /ref M2M_WIFI_RESP_CURRENT_RSSI
  351. /ref M2M_WIFI_RESP_CLIENT_INFO
  352. /ref M2M_WIFI_RESP_PROVISION_INFO
  353. /ref M2M_WIFI_RESP_DEFAULT_CONNECT
  354. In case Ethernet/Bypass mode is defined :
  355. @ref M2M_WIFI_RESP_ETHERNET_RX_PACKET
  356. In case monitoring mode is used:
  357. @ref M2M_WIFI_RESP_WIFI_RX_PACKET
  358. @param [in] pvMsg
  359. A pointer to a buffer containing the notification parameters (if any). It should be
  360. casted to the correct data type corresponding to the notification type.
  361. @see
  362. tstrM2mWifiStateChanged
  363. tstrM2MWPSInfo
  364. tstrM2mScanDone
  365. tstrM2mWifiscanResult
  366. */
  367. typedef void (*tpfAppWifiCb)(uint8 u8MsgType, void *pvMsg);
  368. /*!
  369. @typedef \
  370. tpfAppEthCb
  371. @brief
  372. ETHERNET (bypass mode) notification callback function receiving Bypass mode events as defined in
  373. the Wi-Fi responses enumeration @ref tenuM2mStaCmd.
  374. @param [in] u8MsgType
  375. Type of notification. Possible types are:
  376. - [M2M_WIFI_RESP_ETHERNET_RX_PACKET](@ref M2M_WIFI_RESP_ETHERNET_RX_PACKET)
  377. @param [in] pvMsg
  378. A pointer to a buffer containing the notification parameters (if any). It should be
  379. casted to the correct data type corresponding to the notification type.
  380. For example, it could be a pointer to the buffer holding the received frame in case of @ref
  381. M2M_WIFI_RESP_ETHERNET_RX_PACKET event.
  382. @param [in] pvControlBuf
  383. A pointer to control buffer describing the accompanied message.
  384. To be casted to @ref tstrM2mIpCtrlBuf in case of @ref M2M_WIFI_RESP_ETHERNET_RX_PACKET event.
  385. @warning
  386. Make sure that the application defines @ref ETH_MODE.
  387. @see
  388. m2m_wifi_init
  389. */
  390. typedef void (*tpfAppEthCb)(uint8 u8MsgType, void *pvMsg, void *pvCtrlBuf);
  391. /*!
  392. @typedef \
  393. tpfAppMonCb
  394. @brief
  395. Wi-Fi monitoring mode callback function. This function delivers all received wi-Fi packets through the Wi-Fi
  396. interface. Applications requiring to operate in the monitoring should call the asynchronous function
  397. m2m_wifi_enable_monitoring_mode and expect to receive the Wi-Fi packets through this callback function, when the event
  398. is received. To disable the monitoring mode a call to @ref m2m_wifi_disable_monitoring_mode should be made.
  399. @param [in] pstrWifiRxPacket
  400. Pointer to a structure holding the Wi-Fi packet header parameters.
  401. @param [in] pu8Payload
  402. Pointer to the buffer holding the Wi-Fi packet payload information required by the application starting
  403. from the defined OFFSET by the application (when calling m2m_wifi_enable_monitoring_mode). Could hold a value of NULL,
  404. if the application does not need any data from the payload.
  405. @param [in] u16PayloadSize
  406. The size of the payload in bytes.
  407. @see
  408. m2m_wifi_enable_monitoring_mode,m2m_wifi_init
  409. @warning
  410. u16PayloadSize should not exceed the buffer size given through m2m_wifi_enable_monitoring_mode.
  411. */
  412. typedef void (*tpfAppMonCb)(tstrM2MWifiRxPacketInfo *pstrWifiRxPacket, uint8 *pu8Payload, uint16 u16PayloadSize);
  413. /**
  414. @struct \
  415. tstrEthInitParam
  416. @brief
  417. Structure to hold Ethernet interface parameters.
  418. Structure is to be defined and have its attributes set,based on the application's functionality before
  419. a call is made to initialize the Wi-Fi operations by calling the @ref m2m_wifi_init function.
  420. This structure is part of the Wi-Fi configuration structure @ref tstrWifiInitParam.
  421. Applications shouldn't need to define this structure, if the bypass mode is not defined.
  422. @see
  423. tpfAppEthCb
  424. tpfAppWifiCb
  425. m2m_wifi_init
  426. @warning
  427. Make sure that application defines @ref ETH_MODE before using @ref tstrEthInitParam.
  428. */
  429. typedef struct {
  430. tpfAppWifiCb pfAppWifiCb;
  431. /*!<
  432. Callback for wifi notifications.
  433. */
  434. tpfAppEthCb pfAppEthCb;
  435. /*!<
  436. Callback for Ethernet interface.
  437. */
  438. uint8 *au8ethRcvBuf;
  439. /*!<
  440. Pointer to Receive Buffer of Ethernet Packet
  441. */
  442. uint16 u16ethRcvBufSize;
  443. /*!<
  444. Size of Receive Buffer for Ethernet Packet
  445. */
  446. uint8 u8EthernetEnable;
  447. /*!<
  448. Enable Ethernet mode flag
  449. */
  450. uint8 __PAD8__;
  451. /*!<
  452. Padding
  453. */
  454. } tstrEthInitParam;
  455. /*!
  456. @struct \
  457. tstrM2mIpCtrlBuf
  458. @brief
  459. Structure holding the incoming buffer's data size information, indicating the data size of the buffer and the
  460. remaining buffer's data size . The data of the buffer which holds the packet sent to the host when in the bypass mode,
  461. is placed in the @ref tstrEthInitParam structure in the
  462. @ref au8ethRcvBuf attribute. This following information is retrieved in the host when an event @ref
  463. M2M_WIFI_RESP_ETHERNET_RX_PACKET is received in the Wi-Fi callback function @ref tpfAppWifiCb.
  464. The application is expected to use this structure's information to determine if there is still incoming data to be
  465. received from the firmware.
  466. @see
  467. tpfAppEthCb
  468. tstrEthInitParam
  469. @warning
  470. Make sure that ETHERNET/bypass mode is defined before using @ref tstrM2mIpCtrlBuf
  471. */
  472. typedef struct {
  473. uint16 u16DataSize;
  474. /*!<
  475. Size of the received data in bytes.
  476. */
  477. uint16 u16RemainigDataSize;
  478. /*!<
  479. Size of the remaining data bytes to be delivered to host.
  480. */
  481. } tstrM2mIpCtrlBuf;
  482. /**
  483. @struct \
  484. tstrWifiInitParam
  485. @brief
  486. Structure, holding the Wi-fi configuration attributes such as the wi-fi callback , monitoring mode callback and
  487. Ethernet parameter initialization structure. Such configuration parameters are required to be set before calling the
  488. wi-fi initialization function @ref m2m_wifi_init.
  489. @ref pfAppWifiCb attribute must be set to handle the wi-fi callback operations.
  490. @ref pfAppMonCb attribute, is optional based on whether the application requires the monitoring mode configuration,
  491. and can there not be set before the initialization.
  492. @ref strEthInitParam structure, is another optional configuration based on whether the bypass mode is set.
  493. @see
  494. tpfAppEthCb
  495. tpfAppMonCb
  496. tstrEthInitParam
  497. */
  498. typedef struct {
  499. tpfAppWifiCb pfAppWifiCb;
  500. /*!<
  501. Callback for Wi-Fi notifications.
  502. */
  503. tpfAppMonCb pfAppMonCb;
  504. /*!<
  505. Callback for monitoring interface.
  506. */
  507. tstrEthInitParam strEthInitParam;
  508. /*!<
  509. Structure to hold Ethernet interface parameters.
  510. */
  511. } tstrWifiInitParam;
  512. //@}
  513. /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
  514. FUNCTION PROTOTYPES
  515. *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
  516. /** \defgroup WLANAPI Function
  517. * @ingroup m2m_wifi
  518. */
  519. #ifdef __cplusplus
  520. extern "C" {
  521. #endif
  522. /** @defgroup WiFiDownloadFn m2m_wifi_download_mode
  523. * @ingroup WLANAPI
  524. * Synchronous download mode entry function that prepares the WINC board to enter the download mode, ready for the
  525. *firmware or certificate download. The WINC board is prepared for download, through initializations for the WINC driver
  526. *including bus initializations and interrupt enabling, it also halts the chip, to allow for the firmware downloads.
  527. * Firmware can be downloaded through a number of interfaces, UART, I2C and SPI.
  528. */
  529. /**@{*/
  530. /*!
  531. @fn \
  532. NMI_API void m2m_wifi_download_mode(void);
  533. @brief Prepares the WINC broard before downloading any data (Firmware, Certificates .. etc)
  534. This function should called before starting to download any data to the WINC board. The WINC board is prepared
  535. for download, through initializations for the WINC driver including bus initializations and interrupt enabling, it also
  536. halts the chip, to allow for the firmware downloads Firmware can be downloaded through a number of interfaces, UART, I2C
  537. and SPI.
  538. @return
  539. The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  540. */
  541. NMI_API sint8 m2m_wifi_download_mode(void);
  542. /**@}*/
  543. /** @defgroup WifiInitFn m2m_wifi_init
  544. * @ingroup WLANAPI
  545. * Synchronous initialization function for the WINC driver. This function initializes the driver by, registering the
  546. call back function for M2M_WIFI layer(also the call back function for bypass mode/monitoring mode if defined),
  547. * initializing the host interface layer and the bus interfaces.
  548. * Wi-Fi callback registering is essential to allow the handling of the events received, in response to the asynchronous
  549. Wi-Fi operations.
  550. Following are the possible Wi-Fi events that are expected to be received through the call back function(provided by the
  551. application) to the M2M_WIFI layer are :
  552. @ref M2M_WIFI_RESP_CON_STATE_CHANGED \n
  553. @ref M2M_WIFI_RESP_CONN_INFO \n
  554. @ref M2M_WIFI_REQ_DHCP_CONF \n
  555. @ref M2M_WIFI_REQ_WPS \n
  556. @ref M2M_WIFI_RESP_IP_CONFLICT \n
  557. @ref M2M_WIFI_RESP_SCAN_DONE \n
  558. @ref M2M_WIFI_RESP_SCAN_RESULT \n
  559. @ref M2M_WIFI_RESP_CURRENT_RSSI \n
  560. @ref M2M_WIFI_RESP_CLIENT_INFO \n
  561. @ref M2M_WIFI_RESP_PROVISION_INFO \n
  562. @ref M2M_WIFI_RESP_DEFAULT_CONNECT \n
  563. Example: \n
  564. In case Bypass mode is defined : \n
  565. @ref M2M_WIFI_RESP_ETHERNET_RX_PACKET
  566. In case Monitoring mode is used: \n
  567. @ref M2M_WIFI_RESP_WIFI_RX_PACKET
  568. Any application using the WINC driver must call this function at the start of its main function.
  569. */
  570. /**@{*/
  571. /*!
  572. @fn \
  573. NMI_API sint8 m2m_wifi_init(tstrWifiInitParam * pWifiInitParam);
  574. @param [in] pWifiInitParam
  575. This is a pointer to the @ref tstrWifiInitParam structure which holds the pointer to the application WIFI layer call
  576. back function, monitoring mode call back and @ref tstrEthInitParam structure containing bypass mode parameters.
  577. @brief Initialize the WINC host driver.
  578. This function initializes the driver by, registering the call back function for M2M_WIFI layer(also the call back
  579. function for bypass mode/monitoring mode if defined), initializing the host interface layer and the bus interfaces.
  580. @pre
  581. Prior to this function call, The application should initialize the BSP using "nm_bsp_init".
  582. Also,application users must provide a call back function responsible for receiving all the WI-FI events that are
  583. received on the M2M_WIFI layer.
  584. @warning
  585. Failure to successfully complete function indicates that the driver couldn't be initialized and a fatal error will
  586. prevent the application from proceeding.
  587. @see
  588. nm_bsp_init
  589. m2m_wifi_deinit
  590. tenuM2mStaCmd
  591. @return
  592. The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  593. */
  594. NMI_API sint8 m2m_wifi_init(tstrWifiInitParam *pWifiInitParam);
  595. /**@}*/
  596. /** @defgroup WifiDeinitFn m2m_wifi_deinit
  597. * @ingroup WLANAPI
  598. * Synchronous de-initialization function to the WINC1500 driver. De-initializes the host interface and frees any
  599. * resources used by the M2M_WIFI layer. This function must be called in the application closing phase to ensure that
  600. * all resources have been correctly released. No arguments are expected to be passed in.
  601. */
  602. /**@{*/
  603. /*!
  604. @fn \
  605. NMI_API sint8 m2m_wifi_deinit(void * arg);
  606. @param [in] arg
  607. Generic argument. Not used in the current implementation.
  608. @brief Deinitilize the WINC driver and host enterface.
  609. This function must be called at the De-initilization stage of the application. Generally This function should be
  610. the last function before switching off the chip and it should be followed only by "nm_bsp_deinit" function call. Every
  611. function call of "nm_wifi_init" should be matched with a call to nm_wifi_deinit.
  612. @see
  613. nm_bsp_deinit
  614. nm_wifi_init
  615. @return
  616. The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  617. */
  618. NMI_API sint8 m2m_wifi_deinit(void *arg);
  619. /*!
  620. @fn \
  621. NMI_API void m2m_wifi_yield(void);
  622. @brief
  623. Yield from processing more synchronous M2M events
  624. @details
  625. This function causes the synchronous M2M event handler function to yield from processing further
  626. events and return control to the caller.
  627. @param [in] arg
  628. Opaque argument, not used in current implementation.
  629. @return
  630. The function returns @ref M2M_SUCCESS for successful interrupt handling and a negative value
  631. otherwise.
  632. @pre
  633. Prior to receiving Wi-Fi interrupts, the WINC driver should have been successfully initialized
  634. by calling the @ref m2m_wifi_init function.
  635. @warning
  636. Failure to successfully complete this function indicates bus errors and hence a fatal error that will prevent the
  637. application from proceeding.
  638. */
  639. NMI_API void m2m_wifi_yield(void);
  640. /**@}*/
  641. /** @defgroup WifiHandleEventsFn m2m_wifi_handle_events
  642. * @ingroup WLANAPI
  643. * Synchronous M2M event handler function, responsible for handling interrupts received from the WINC firmware.
  644. * Application developers should call this function periodically in-order to receive the events that are to be
  645. handled by the
  646. * callback functions implemented by the application.
  647. */
  648. /**@{*/
  649. /*!
  650. @fn \
  651. NMI_API sint8 m2m_wifi_handle_events(void * arg);
  652. @pre
  653. Prior to receiving events, the WINC driver should have been successfully initialized by calling the @ref
  654. m2m_wifi_init function.
  655. @brief Handle the varios events received from the WINC board.
  656. Whenever an event happen in the WINC board (e.g. Connection, Disconnection , DHCP .. etc), WINC will interrupt
  657. the host to let it know that a new event has occured. The host driver will attempt to handle these events whenever the
  658. host driver decides to do that by calling the "m2m_wifi_handle_events" function. It's mandatory to call this function
  659. periodically and independantly of any other condition. It's ideal to include this function in the main and the most
  660. frequent loop of the host application.
  661. @warning
  662. Failure to successfully complete this function indicates bus errors and hence a fatal error that will prevent the
  663. application from proceeding.
  664. @return
  665. The function returns @ref M2M_SUCCESS for successful interrupt handling and a negative value otherwise.
  666. */
  667. NMI_API sint8 m2m_wifi_handle_events(void *arg);
  668. /**@}*/
  669. /** @defgroup WifiSendCRLFn m2m_wifi_send_crl
  670. * @ingroup WLANAPI
  671. * Asynchronous API that notifies the WINC with the Certificate Revocation List to be used for TLS.
  672. */
  673. /**@{*/
  674. /*!
  675. @fn \
  676. sint8 m2m_wifi_send_crl(tstrTlsCrlInfo* pCRL);
  677. @brief
  678. Asynchronous API that notifies the WINC with the Certificate Revocation List.
  679. @param [in] pCRL
  680. Pointer to the structure containing certificate revocation list details.
  681. @return
  682. The function returns @ref M2M_SUCCESS if the command has been successfully queued to the WINC,
  683. and a negative value otherwise.
  684. */
  685. sint8 m2m_wifi_send_crl(tstrTlsCrlInfo *pCRL);
  686. /**@}*/
  687. /** @defgroup WifiDefaultConnectFn m2m_wifi_default_connect
  688. * @ingroup WLANAPI
  689. * Asynchronous Wi-Fi connection function. An application calling this function will cause the firmware to
  690. correspondingly connect to the last successfully connected AP from the cached connections.
  691. * A failure to connect will result in a response of @ref M2M_WIFI_RESP_DEFAULT_CONNECT indicating the connection
  692. error as defined in the structure @ref tstrM2MDefaultConnResp.
  693. * Possible errors are:
  694. * The connection list is empty @ref M2M_DEFAULT_CONN_EMPTY_LIST or a mismatch for the saved AP name @ref
  695. M2M_DEFAULT_CONN_SCAN_MISMATCH.
  696. * only difference between this function and @ref m2m_wifi_connect, is the connection parameters.
  697. * Connection using this function is expected to connect using cached connection parameters.
  698. */
  699. /**@{*/
  700. /*!
  701. @fn \
  702. NMI_API sint8 m2m_wifi_default_connect(void);
  703. @pre
  704. Prior to connecting, the WINC driver should have been successfully initialized by calling the @ref m2m_wifi_init
  705. function.
  706. @brief Connect to the last successfully connected AP from the cached connections.
  707. @warning
  708. This function must be called in station mode only.
  709. It's important to note that successful completion of a call to m2m_wifi_default_connect() does not guarantee success of
  710. the WIFI connection, and a negative return value indicates only locally-detected errors.
  711. @see
  712. m2m_wifi_connect
  713. @return
  714. The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  715. */
  716. NMI_API sint8 m2m_wifi_default_connect(void);
  717. /**@}*/
  718. /** @defgroup WifiConnectFn m2m_wifi_connect
  719. * @ingroup WLANAPI
  720. * Asynchronous wi-fi connection function to a specific AP. Prior to a successful connection, the application must
  721. * define the SSID of the AP, the security type, the authentication information parameters and the channel number to
  722. * which the connection will be established. The connection status is known when a response of @ref
  723. * M2M_WIFI_RESP_CON_STATE_CHANGED is received based on the states defined in @ref tenuM2mConnState, successful
  724. * connection is defined by @ref M2M_WIFI_CONNECTED
  725. *
  726. * The only difference between this function and @ref m2m_wifi_default_connect, is the connection parameters.
  727. * Connection using this function is expected to be made to a specific AP and to a specified channel.
  728. */
  729. /**@{*/
  730. /*!
  731. @fn \
  732. NMI_API sint8 m2m_wifi_connect(char *pcSsid, uint8 u8SsidLen, uint8 u8SecType, void *pvAuthInfo, uint16 u16Ch);
  733. @param [in] pcSsid
  734. A buffer holding the SSID corresponding to the requested AP.
  735. @param [in] u8SsidLen
  736. Length of the given SSID (not including the NULL termination).
  737. A length less than ZERO or greater than the maximum defined SSID @ref M2M_MAX_SSID_LEN will result in a
  738. negative error
  739. @ref M2M_ERR_FAIL.
  740. @param [in] u8SecType
  741. Wi-Fi security type security for the network. It can be one of the following types:
  742. -@ref M2M_WIFI_SEC_OPEN
  743. -@ref M2M_WIFI_SEC_WEP
  744. -@ref M2M_WIFI_SEC_WPA_PSK
  745. -@ref M2M_WIFI_SEC_802_1X
  746. A value outside these possible values will result in a negative return error @ref M2M_ERR_FAIL.
  747. @param [in] pvAuthInfo
  748. Authentication parameters required for completing the connection. It is type is based on the Security
  749. type. If the authentication parameters are NULL or are greater than the maximum length of the authentication parameters
  750. length as defined by
  751. @ref M2M_MAX_PSK_LEN a negative error will return @ref M2M_ERR_FAIL(-12) indicating connection failure.
  752. @param [in] u16Ch
  753. Wi-Fi channel number as defined in @ref tenuM2mScanCh enumeration.
  754. Channel number greater than @ref M2M_WIFI_CH_14 returns a negative error @ref M2M_ERR_FAIL(-12).
  755. Except if the value is M2M_WIFI_CH_ALL(255), since this indicates that the firmware should scan all
  756. channels to find the SSID requested to connect to. Failure to find the connection match will return a negative error
  757. @ref M2M_DEFAULT_CONN_SCAN_MISMATCH.
  758. @pre
  759. Prior to a successful connection request, the Wi-Fi driver must have been successfully initialized through the
  760. call of the @ref @m2m_wifi_init function
  761. @see
  762. tuniM2MWifiAuth
  763. tstr1xAuthCredentials
  764. tstrM2mWifiWepParams
  765. @warning
  766. -This function must be called in station mode only.
  767. -Successful completion of this function does not guarantee success of the WIFI connection, and
  768. a negative return value indicates only locally-detected errors.
  769. @return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  770. */
  771. NMI_API sint8 m2m_wifi_connect(char *pcSsid, uint8 u8SsidLen, uint8 u8SecType, void *pvAuthInfo, uint16 u16Ch);
  772. /**@}*/
  773. /** @defgroup WifiConnectFn m2m_wifi_connect_sc
  774. * @ingroup WLANAPI
  775. * Asynchronous wi-fi connection function to a specific AP. Prior to a successful connection, the application
  776. * developers must know the SSID of the AP, the security type, the authentication information parameters and the channel
  777. * number to which the connection will be established.this API allows the user to choose whether to The connection
  778. * status is known when a response of @ref M2M_WIFI_RESP_CON_STATE_CHANGED is received based on the states defined in
  779. * @ref tenuM2mConnState, successful connection is defined by @ref M2M_WIFI_CONNECTED The only difference between this
  780. * function and @ref m2m_wifi_connect, is the option to save the acess point info ( SSID, password...etc) or not.
  781. * Connection using this function is expected to be made to a specific AP and to a specified channel.
  782. */
  783. /**@{*/
  784. /*!
  785. @fn \
  786. NMI_API sint8 m2m_wifi_connect_sc(char *pcSsid, uint8 u8SsidLen, uint8 u8SecType, void *pvAuthInfo, uint16
  787. u16Ch,uint8 u8SaveCred);
  788. @param [in] pcSsid
  789. A buffer holding the SSID corresponding to the requested AP.
  790. @param [in] u8SsidLen
  791. Length of the given SSID (not including the NULL termination).
  792. A length less than ZERO or greater than the maximum defined SSID @ref M2M_MAX_SSID_LEN will result in a
  793. negative error
  794. @ref M2M_ERR_FAIL.
  795. @param [in] u8SecType
  796. Wi-Fi security type security for the network. It can be one of the following types:
  797. -@ref M2M_WIFI_SEC_OPEN
  798. -@ref M2M_WIFI_SEC_WEP
  799. -@ref M2M_WIFI_SEC_WPA_PSK
  800. -@ref M2M_WIFI_SEC_802_1X
  801. A value outside these possible values will result in a negative return error @ref M2M_ERR_FAIL.
  802. @param [in] pvAuthInfo
  803. Authentication parameters required for completing the connection. It is type is based on the Security
  804. type. If the authentication parameters are NULL or are greater than the maximum length of the authentication parameters
  805. length as defined by
  806. @ref M2M_MAX_PSK_LEN a negative error will return @ref M2M_ERR_FAIL(-12) indicating connection failure.
  807. @param [in] u16Ch
  808. Wi-Fi channel number as defined in @ref tenuM2mScanCh enumeration.
  809. Channel number greater than @ref M2M_WIFI_CH_14 returns a negative error @ref M2M_ERR_FAIL(-12).
  810. Except if the value is M2M_WIFI_CH_ALL(255), since this indicates that the firmware should scan all
  811. channels to find the SSID requested to connect to. Failure to find the connection match will return a negative error
  812. @ref M2M_DEFAULT_CONN_SCAN_MISMATCH.
  813. @param [in] u8NoSaveCred
  814. Option to store the acess point SSID and password into the WINC flash memory or not.
  815. @pre
  816. Prior to a successful connection request, the wi-fi driver must have been successfully initialized through the
  817. call of the @ref @m2m_wifi_init function
  818. @see
  819. tuniM2MWifiAuth
  820. tstr1xAuthCredentials
  821. tstrM2mWifiWepParams
  822. @warning
  823. -This function must be called in station mode only.
  824. -Successful completion of this function does not guarantee success of the WIFI connection, and
  825. a negative return value indicates only locally-detected errors.
  826. @return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  827. */
  828. NMI_API sint8 m2m_wifi_connect_sc(char *pcSsid, uint8 u8SsidLen, uint8 u8SecType, void *pvAuthInfo, uint16 u16Ch,
  829. uint8 u8NoSaveCred);
  830. /**@}*/
  831. /** @defgroup WifiDisconnectFn m2m_wifi_disconnect
  832. * @ingroup WLANAPI
  833. * Synchronous wi-fi disconnection function, requesting a Wi-Fi disconnection from the currently connected AP.
  834. */
  835. /**@{*/
  836. /*!
  837. @fn \
  838. NMI_API sint8 m2m_wifi_disconnect(void);
  839. @pre
  840. Disconnection request must be made to a successfully connected AP. If the WINC is not in the connected state, a call
  841. to this function will hold insignificant.
  842. @brief Request a Wi-Fi disconnect from the currently connected AP.
  843. After the Disconnect is complete the driver should recieve a response of @ref M2M_WIFI_RESP_CON_STATE_CHANGED
  844. based on the states defined in @ref tenuM2mConnState, successful disconnection is defined by @ref M2M_WIFI_DISCONNECTED
  845. .
  846. @warning
  847. This function must be called in station mode only.
  848. @see
  849. m2m_wifi_connect
  850. m2m_wifi_default_connect
  851. @return
  852. The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  853. */
  854. NMI_API sint8 m2m_wifi_disconnect(void);
  855. /**@}*/
  856. /** @defgroup StartProvisionModeFn m2m_wifi_start_provision_mode
  857. * @ingroup WLANAPI
  858. * Asynchronous Wi-Fi provisioning function, which starts the WINC HTTP PROVISIONING mode.
  859. The function triggers the WINC to activate the Wi-Fi AP (HOTSPOT) mode with the passed configuration parameters and
  860. then starts the HTTP Provision WEB Server. The provisioning status is returned in an event @ref
  861. M2M_WIFI_RESP_PROVISION_INFO
  862. */
  863. /**@{*/
  864. /*!
  865. @fn \
  866. NMI_API sint8 m2m_wifi_start_provision_mode(tstrM2MAPConfig *pstrAPConfig, char *pcHttpServerDomainName, uint8
  867. bEnableHttpRedirect);
  868. @param [in] pstrAPConfig
  869. AP configuration parameters as defined in @ref tstrM2MAPConfig configuration structure.
  870. A NULL value passed in, will result in a negative error @ref M2M_ERR_FAIL.
  871. @param [in] pcHttpServerDomainName
  872. Domain name of the HTTP Provision WEB server which others will use to load the provisioning Home page.
  873. The domain name can have one of the following 3 forms:
  874. 1- "wincprov.com"
  875. 2- "http://wincprov.com"
  876. 3- "https://wincprov.com"
  877. The forms 1 and 2 are equivalent, they both will start a plain http server, while form 3
  878. will start a secure HTTP provisioning Session (HTTP over SSL connection).
  879. @param [in] bEnableHttpRedirect
  880. A flag to enable/disable the HTTP redirect feature. If Secure provisioning is enabled (i.e. the server
  881. domain name uses "https" prefix) this flag is ignored (no meaning for redirect in HTTPS).
  882. Possible values are:
  883. - ZERO DO NOT Use HTTP Redirect. In this case the associated device could open the
  884. provisioning page ONLY when the HTTP Provision URL of the WINC HTTP Server is correctly written on the browser.
  885. - Non-Zero value Use HTTP Redirect. In this case, all http traffic (http://URL) from the associated
  886. device (Phone, PC, ...etc) will be redirected to the WINC HTTP Provisioning Home
  887. page.
  888. @pre
  889. - A Wi-Fi notification callback of type @ref tpfAppWifiCb MUST be implemented and registered at startup. Registering
  890. the callback is done through passing it to the initialization @ref m2m_wifi_init function.
  891. - The event @ref M2M_WIFI_RESP_CONN_INFO must be handled in the callback to receive the requested connection info.
  892. @see
  893. tpfAppWifiCb
  894. m2m_wifi_init
  895. M2M_WIFI_RESP_PROVISION_INFO
  896. m2m_wifi_stop_provision_mode
  897. tstrM2MAPConfig
  898. @warning
  899. DO Not use ".local" in the pcHttpServerDomainName.
  900. @return
  901. The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  902. \section Example
  903. The example demonstrates a code snippet for how provisioning is triggered and the response event received accordingly.
  904. @code
  905. #include "m2m_wifi.h"
  906. #include "m2m_types.h"
  907. void wifi_event_cb(uint8 u8WiFiEvent, void * pvMsg)
  908. {
  909. switch(u8WiFiEvent)
  910. {
  911. case M2M_WIFI_RESP_PROVISION_INFO:
  912. {
  913. tstrM2MProvisionInfo *pstrProvInfo = (tstrM2MProvisionInfo*)pvMsg;
  914. if(pstrProvInfo->u8Status == M2M_SUCCESS)
  915. {
  916. m2m_wifi_connect((char*)pstrProvInfo->au8SSID, (uint8)strlen(pstrProvInfo->au8SSID),
  917. pstrProvInfo->u8SecType, pstrProvInfo->au8Password, M2M_WIFI_CH_ALL);
  918. printf("PROV SSID : %s\n",pstrProvInfo->au8SSID);
  919. printf("PROV PSK : %s\n",pstrProvInfo->au8Password);
  920. }
  921. else
  922. {
  923. printf("(ERR) Provisioning Failed\n");
  924. }
  925. }
  926. break;
  927. default:
  928. break;
  929. }
  930. }
  931. int main()
  932. {
  933. tstrWifiInitParam param;
  934. param.pfAppWifiCb = wifi_event_cb;
  935. if(!m2m_wifi_init(&param))
  936. {
  937. tstrM2MAPConfig apConfig;
  938. uint8 bEnableRedirect = 1;
  939. strcpy(apConfig.au8SSID, "WINC_SSID");
  940. apConfig.u8ListenChannel = 1;
  941. apConfig.u8SecType = M2M_WIFI_SEC_OPEN;
  942. apConfig.u8SsidHide = 0;
  943. // IP Address
  944. apConfig.au8DHCPServerIP[0] = 192;
  945. apConfig.au8DHCPServerIP[1] = 168;
  946. apConfig.au8DHCPServerIP[2] = 1;
  947. apConfig.au8DHCPServerIP[0] = 1;
  948. m2m_wifi_start_provision_mode(&apConfig, "atmelwincconf.com", bEnableRedirect);
  949. while(1)
  950. {
  951. m2m_wifi_handle_events(NULL);
  952. }
  953. }
  954. }
  955. @endcode
  956. */
  957. NMI_API sint8 m2m_wifi_start_provision_mode(tstrM2MAPConfig *pstrAPConfig, char *pcHttpServerDomainName,
  958. uint8 bEnableHttpRedirect);
  959. /**@}*/
  960. /** @defgroup StopProvisioningModeFn m2m_wifi_stop_provision_mode
  961. * @ingroup WLANAPI
  962. * Synchronous provision termination function which stops the provision mode if it is active.
  963. */
  964. /**@{*/
  965. /*!
  966. @fn \
  967. sint8 m2m_wifi_stop_provision_mode(void);
  968. @pre
  969. An active provisioning session must be active before it is terminated through this function.
  970. @see
  971. m2m_wifi_start_provision_mode
  972. @return
  973. The function returns ZERO for success and a negative value otherwise.
  974. */
  975. NMI_API sint8 m2m_wifi_stop_provision_mode(void);
  976. /**@}*/
  977. /** @defgroup GetConnectionInfoFn m2m_wifi_get_connection_info
  978. * @ingroup WLANAPI
  979. * Asynchronous connection status retrieval function, retrieves the status information of the currently connected AP.
  980. * The result is passed to the Wi-Fi notification callback through the event @ref M2M_WIFI_RESP_CONN_INFO. Connection
  981. * information is retrieved from the structure @ref tstrM2MConnInfo.
  982. */
  983. /**@{*/
  984. /*!
  985. @fn \
  986. sint8 m2m_wifi_get_connection_info(void);
  987. @brief
  988. Retrieve the current Connection information. The result is passed to the Wi-Fi notification callback
  989. with [M2M_WIFI_RESP_CONN_INFO](@ref M2M_WIFI_RESP_CONN_INFO).
  990. @pre
  991. - A Wi-Fi notification callback of type @ref tpfAppWifiCb MUST be implemented and registered at startup. Registering
  992. the callback is done through passing it to the initialization @ref m2m_wifi_init function.
  993. - The event @ref M2M_WIFI_RESP_CONN_INFO must be handled in the callback to receive the requested connection info.
  994. Connection Information retrieved:
  995. -Connection Security
  996. -Connection RSSI
  997. -Remote MAC address
  998. -Remote IP address
  999. and in case of WINC station mode the SSID of the AP is also retrieved.
  1000. @warning
  1001. -In case of WINC AP mode or P2P mode, ignore the SSID field (NULL string).
  1002. @sa
  1003. M2M_WIFI_RESP_CONN_INFO,
  1004. tstrM2MConnInfo
  1005. @return
  1006. The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  1007. \section Example
  1008. The code snippet shows an example of how wi-fi connection information is retrieved .
  1009. @code
  1010. #include "m2m_wifi.h"
  1011. #include "m2m_types.h"
  1012. void wifi_event_cb(uint8 u8WiFiEvent, void * pvMsg)
  1013. {
  1014. switch(u8WiFiEvent)
  1015. {
  1016. case M2M_WIFI_RESP_CONN_INFO:
  1017. {
  1018. tstrM2MConnInfo *pstrConnInfo = (tstrM2MConnInfo*)pvMsg;
  1019. printf("CONNECTED AP INFO\n");
  1020. printf("SSID : %s\n",pstrConnInfo->acSSID);
  1021. printf("SEC TYPE : %d\n",pstrConnInfo->u8SecType);
  1022. printf("Signal Strength : %d\n", pstrConnInfo->s8RSSI);
  1023. printf("Local IP Address : %d.%d.%d.%d\n",
  1024. pstrConnInfo->au8IPAddr[0] , pstrConnInfo->au8IPAddr[1], pstrConnInfo->au8IPAddr[2],
  1025. pstrConnInfo->au8IPAddr[3]);
  1026. }
  1027. break;
  1028. case M2M_WIFI_REQ_DHCP_CONF:
  1029. {
  1030. // Get the current AP information.
  1031. m2m_wifi_get_connection_info();
  1032. }
  1033. break;
  1034. default:
  1035. break;
  1036. }
  1037. }
  1038. int main()
  1039. {
  1040. tstrWifiInitParam param;
  1041. param.pfAppWifiCb = wifi_event_cb;
  1042. if(!m2m_wifi_init(&param))
  1043. {
  1044. // connect to the default AP
  1045. m2m_wifi_default_connect();
  1046. while(1)
  1047. {
  1048. m2m_wifi_handle_events(NULL);
  1049. }
  1050. }
  1051. }
  1052. @endcode
  1053. */
  1054. NMI_API sint8 m2m_wifi_get_connection_info(void);
  1055. /**@}*/
  1056. /** @defgroup WifiSetMacAddFn m2m_wifi_set_mac_address
  1057. * @ingroup WLANAPI
  1058. * Synchronous MAC address assigning to the NMC1500. It is used for non-production SW. Assign MAC address to the WINC
  1059. * device.
  1060. */
  1061. /**@{*/
  1062. /*!
  1063. @fn \
  1064. NMI_API sint8 m2m_wifi_set_mac_address(uint8 au8MacAddress[6]);
  1065. @brief Assign a MAC address to the WINC board.
  1066. This function override the already assigned MAC address of the WINC board with a user provided one. This is for
  1067. experimental use only and should never be used in the production SW.
  1068. @param [in] au8MacAddress
  1069. MAC Address to be set to the WINC.
  1070. @return
  1071. The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  1072. */
  1073. NMI_API sint8 m2m_wifi_set_mac_address(uint8 au8MacAddress[6]);
  1074. /**@}*/
  1075. /** @defgroup WifiWpsFn m2m_wifi_wps
  1076. * @ingroup WLANAPI
  1077. * Asynchronous WPS triggering function.
  1078. * This function is called for the WINC to enter the WPS (Wi-Fi Protected Setup) mode. The result is passed to the
  1079. *Wi-Fi notification callback with the event @ref M2M_WIFI_REQ_WPS.
  1080. */
  1081. /**@{*/
  1082. /*!
  1083. @fn \
  1084. NMI_API sint8 m2m_wifi_wps(uint8 u8TriggerType,const char * pcPinNumber);
  1085. @param [in] u8TriggerType
  1086. WPS Trigger method. Could be:
  1087. - [WPS_PIN_TRIGGER](@ref WPS_PIN_TRIGGER) Push button method
  1088. - [WPS_PBC_TRIGGER](@ref WPS_PBC_TRIGGER) Pin method
  1089. @param [in] pcPinNumber
  1090. PIN number for WPS PIN method. It is not used if the trigger type is WPS_PBC_TRIGGER. It must follow the
  1091. rules stated by the WPS standard.
  1092. @warning
  1093. This function is not allowed in AP or P2P modes.
  1094. @pre
  1095. - A Wi-Fi notification callback of type (@ref tpfAppWifiCb MUST be implemented and registered at startup.
  1096. Registering the callback is done through passing it to the [m2m_wifi_init](@ref m2m_wifi_init).
  1097. - The event [M2M_WIFI_REQ_WPS](@ref M2M_WIFI_REQ_WPS) must be handled in the callback to receive the WPS status.
  1098. - The WINC device MUST be in IDLE or STA mode. If AP or P2P mode is active, the WPS will not be performed.
  1099. - The [m2m_wifi_handle_events](@ref m2m_wifi_handle_events) MUST be called periodically to receive the responses in
  1100. the callback.
  1101. @see
  1102. tpfAppWifiCb
  1103. m2m_wifi_init
  1104. M2M_WIFI_REQ_WPS
  1105. tenuWPSTrigger
  1106. tstrM2MWPSInfo
  1107. @return
  1108. The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  1109. \section Example
  1110. The code snippet shows an example of how Wi-Fi WPS is triggered .
  1111. @code
  1112. #include "m2m_wifi.h"
  1113. #include "m2m_types.h"
  1114. void wifi_event_cb(uint8 u8WiFiEvent, void * pvMsg)
  1115. {
  1116. switch(u8WiFiEvent)
  1117. {
  1118. case M2M_WIFI_REQ_WPS:
  1119. {
  1120. tstrM2MWPSInfo *pstrWPS = (tstrM2MWPSInfo*)pvMsg;
  1121. if(pstrWPS->u8AuthType != 0)
  1122. {
  1123. printf("WPS SSID : %s\n",pstrWPS->au8SSID);
  1124. printf("WPS PSK : %s\n",pstrWPS->au8PSK);
  1125. printf("WPS SSID Auth Type : %s\n",pstrWPS->u8AuthType == M2M_WIFI_SEC_OPEN ? "OPEN" : "WPA/WPA2");
  1126. printf("WPS Channel : %d\n",pstrWPS->u8Ch + 1);
  1127. // establish Wi-Fi connection
  1128. m2m_wifi_connect((char*)pstrWPS->au8SSID, (uint8)m2m_strlen(pstrWPS->au8SSID),
  1129. pstrWPS->u8AuthType, pstrWPS->au8PSK, pstrWPS->u8Ch);
  1130. }
  1131. else
  1132. {
  1133. printf("(ERR) WPS Is not enabled OR Timed out\n");
  1134. }
  1135. }
  1136. break;
  1137. default:
  1138. break;
  1139. }
  1140. }
  1141. int main()
  1142. {
  1143. tstrWifiInitParam param;
  1144. param.pfAppWifiCb = wifi_event_cb;
  1145. if(!m2m_wifi_init(&param))
  1146. {
  1147. // Trigger WPS in Push button mode.
  1148. m2m_wifi_wps(WPS_PBC_TRIGGER, NULL);
  1149. while(1)
  1150. {
  1151. m2m_wifi_handle_events(NULL);
  1152. }
  1153. }
  1154. }
  1155. @endcode
  1156. */
  1157. NMI_API sint8 m2m_wifi_wps(uint8 u8TriggerType, const char *pcPinNumber);
  1158. /**@}*/
  1159. /** @defgroup WifiWpsDisableFn m2m_wifi_wps_disable
  1160. * @ingroup WLANAPI
  1161. * Disable the WINC1500 WPS operation.
  1162. */
  1163. /**@{*/
  1164. /*!
  1165. @fn \
  1166. NMI_API sint8 m2m_wifi_wps_disable(void);
  1167. @pre WINC should be already in WPS mode using @ref m2m_wifi_wps
  1168. @brief Stops the WPS ongoing session.
  1169. @see
  1170. m2m_wifi_wps
  1171. @return
  1172. The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  1173. */
  1174. NMI_API sint8 m2m_wifi_wps_disable(void);
  1175. /**@}*/
  1176. /** @defgroup WifiP2PFn m2m_wifi_p2p
  1177. * @ingroup WLANAPI
  1178. * Asynchronous Wi-Fi direct (P2P) enabling mode function.
  1179. The WINC supports P2P in device listening mode ONLY (intent is ZERO).
  1180. The WINC P2P implementation does not support P2P GO (Group Owner) mode.
  1181. Active P2P devices (e.g. phones) could find the WINC in the search list. When a device is connected to WINC, a Wi-Fi
  1182. notification event
  1183. @ref M2M_WIFI_RESP_CON_STATE_CHANGED is triggered. After a short while, the DHCP IP Address is obtained
  1184. and an event @ref M2M_WIFI_REQ_DHCP_CONF is triggered. Refer to the code examples for a more illustrative example.
  1185. */
  1186. /**@{*/
  1187. /*!
  1188. @fn \
  1189. NMI_API sint8 m2m_wifi_p2p(uint8 u8Channel);
  1190. @param [in] u8Channel
  1191. P2P Listen RF channel. According to the P2P standard It must hold only one of the following values 1, 6
  1192. or 11.
  1193. @pre
  1194. - A Wi-Fi notification callback of type @ref tpfAppWifiCb MUST be implemented and registered at initialization.
  1195. Registering the callback is done through passing it to the @ref m2m_wifi_init.
  1196. - The events @ref M2M_WIFI_RESP_CON_STATE_CHANGED and @ref M2M_WIFI_REQ_DHCP_CONF
  1197. must be handled in the callback.
  1198. - The @ref m2m_wifi_handle_events MUST be called to receive the responses in the callback.
  1199. @warning
  1200. This function is not allowed in AP or STA modes.
  1201. @see
  1202. tpfAppWifiCb
  1203. m2m_wifi_init
  1204. M2M_WIFI_RESP_CON_STATE_CHANGED
  1205. M2M_WIFI_REQ_DHCP_CONF
  1206. tstrM2mWifiStateChanged
  1207. @return
  1208. The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  1209. \section Example
  1210. The code snippet shown an example of how the p2p mode operates.
  1211. @code
  1212. #include "m2m_wifi.h"
  1213. #include "m2m_types.h"
  1214. void wifi_event_cb(uint8 u8WiFiEvent, void * pvMsg)
  1215. {
  1216. switch(u8WiFiEvent)
  1217. {
  1218. case M2M_WIFI_RESP_CON_STATE_CHANGED:
  1219. {
  1220. tstrM2mWifiStateChanged *pstrWifiState = (tstrM2mWifiStateChanged*)pvMsg;
  1221. M2M_INFO("Wifi State :: %s :: ErrCode %d\n", pstrWifiState->u8CurrState?
  1222. "CONNECTED":"DISCONNECTED",pstrWifiState->u8ErrCode);
  1223. // Do something
  1224. }
  1225. break;
  1226. case M2M_WIFI_REQ_DHCP_CONF:
  1227. {
  1228. uint8 *pu8IPAddress = (uint8*)pvMsg;
  1229. printf("P2P IP Address
  1230. \"%u.%u.%u.%u\"\n",pu8IPAddress[0],pu8IPAddress[1],pu8IPAddress[2],pu8IPAddress[3]);
  1231. }
  1232. break;
  1233. default:
  1234. break;
  1235. }
  1236. }
  1237. int main()
  1238. {
  1239. tstrWifiInitParam param;
  1240. param.pfAppWifiCb = wifi_event_cb;
  1241. if(!m2m_wifi_init(&param))
  1242. {
  1243. // Trigger P2P
  1244. m2m_wifi_p2p(M2M_WIFI_CH_1);
  1245. while(1)
  1246. {
  1247. m2m_wifi_handle_events(NULL);
  1248. }
  1249. }
  1250. }
  1251. @endcode
  1252. */
  1253. NMI_API sint8 m2m_wifi_p2p(uint8 u8Channel);
  1254. /**@}*/
  1255. /** @defgroup WifiP2PDisconnectFn m2m_wifi_p2p_disconnect
  1256. * @ingroup WLANAPI
  1257. * Disable the WINC1500 device Wi-Fi direct mode (P2P).
  1258. */
  1259. /**@{*/
  1260. /*!
  1261. @fn \
  1262. NMI_API sint8 m2m_wifi_p2p_disconnect(void);
  1263. @pre
  1264. The p2p mode must have be enabled and active before a disconnect can be called.
  1265. @see
  1266. m2m_wifi_p2p
  1267. @return
  1268. The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  1269. */
  1270. NMI_API sint8 m2m_wifi_p2p_disconnect(void);
  1271. /**@}*/
  1272. /** @defgroup WifiEnableApFn m2m_wifi_enable_ap
  1273. * @ingroup WLANAPI
  1274. * Asynchronous Wi-FI hot-spot enabling function.
  1275. * The WINC supports AP mode operation with the following limitations:
  1276. - Only 1 STA could be associated at a time.
  1277. - Open and WEP are the only supported security types
  1278. */
  1279. /**@{*/
  1280. /*!
  1281. @fn \
  1282. NMI_API sint8 m2m_wifi_enable_ap(CONST tstrM2MAPConfig* pstrM2MAPConfig);
  1283. @param [in] pstrM2MAPConfig
  1284. A structure holding the AP configurations.
  1285. @warning
  1286. This function is not allowed in P2P or STA modes.
  1287. @pre
  1288. - A Wi-Fi notification callback of type @ref tpfAppWifiCb MUST be implemented and registered at initialization.
  1289. Registering the callback is done through passing it to the [m2m_wifi_init](@ref m2m_wifi_init).
  1290. - The event @ref M2M_WIFI_REQ_DHCP_CONF must be handled in the callback.
  1291. - The @ref m2m_wifi_handle_events MUST be called to receive the responses in the callback.
  1292. @see
  1293. tpfAppWifiCb
  1294. tenuM2mSecType
  1295. m2m_wifi_init
  1296. M2M_WIFI_REQ_DHCP_CONF
  1297. tstrM2mWifiStateChanged
  1298. tstrM2MAPConfig
  1299. @return
  1300. The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  1301. \section Example
  1302. The code snippet demonstrates how the AP mode is enabled after the driver is initialized in the application's main
  1303. function and the handling of the event @ref M2M_WIFI_REQ_DHCP_CONF, to indicate successful connection.
  1304. @code
  1305. #include "m2m_wifi.h"
  1306. #include "m2m_types.h"
  1307. void wifi_event_cb(uint8 u8WiFiEvent, void * pvMsg)
  1308. {
  1309. switch(u8WiFiEvent)
  1310. {
  1311. case M2M_WIFI_REQ_DHCP_CONF:
  1312. {
  1313. uint8 *pu8IPAddress = (uint8*)pvMsg;
  1314. printf("Associated STA has IP Address
  1315. \"%u.%u.%u.%u\"\n",pu8IPAddress[0],pu8IPAddress[1],pu8IPAddress[2],pu8IPAddress[3]);
  1316. }
  1317. break;
  1318. default:
  1319. break;
  1320. }
  1321. }
  1322. int main()
  1323. {
  1324. tstrWifiInitParam param;
  1325. param.pfAppWifiCb = wifi_event_cb;
  1326. if(!m2m_wifi_init(&param))
  1327. {
  1328. tstrM2MAPConfig apConfig;
  1329. strcpy(apConfig.au8SSID, "WINC_SSID");
  1330. apConfig.u8ListenChannel = 1;
  1331. apConfig.u8SecType = M2M_WIFI_SEC_OPEN;
  1332. apConfig.u8SsidHide = 0;
  1333. // IP Address
  1334. apConfig.au8DHCPServerIP[0] = 192;
  1335. apConfig.au8DHCPServerIP[1] = 168;
  1336. apConfig.au8DHCPServerIP[2] = 1;
  1337. apConfig.au8DHCPServerIP[0] = 1;
  1338. // Trigger AP
  1339. m2m_wifi_enable_ap(&apConfig);
  1340. while(1)
  1341. {
  1342. m2m_wifi_handle_events(NULL);
  1343. }
  1344. }
  1345. }
  1346. @endcode
  1347. */
  1348. NMI_API sint8 m2m_wifi_enable_ap(CONST tstrM2MAPConfig *pstrM2MAPConfig);
  1349. /**@}*/
  1350. /** @defgroup WifiDisableApFn m2m_wifi_disable_ap
  1351. * @ingroup WLANAPI
  1352. * Synchronous Wi-Fi hot-spot disabling function. Must be called only when the AP is enabled through the @ref
  1353. * m2m_wifi_enable_ap function. Otherwise the call to this function will not be useful.
  1354. */
  1355. /**@{*/
  1356. /*!
  1357. @fn \
  1358. NMI_API sint8 m2m_wifi_disable_ap(void);
  1359. @see
  1360. m2m_wifi_enable_ap
  1361. @return
  1362. The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  1363. */
  1364. NMI_API sint8 m2m_wifi_disable_ap(void);
  1365. /**@}*/
  1366. /** @defgroup SetStaticIPFn m2m_wifi_set_static_ip
  1367. * @ingroup WLANAPI
  1368. * Synchronous static IP Address configuration function.
  1369. */
  1370. /**@{*/
  1371. /*!
  1372. @fn \
  1373. NMI_API sint8 m2m_wifi_set_static_ip(tstrM2MIPConfig * pstrStaticIPConf);
  1374. @param [in] pstrStaticIPConf
  1375. Pointer to a structure holding the static IP Configurations (IP,
  1376. Gateway, subnet mask and DNS address).
  1377. @pre The application must disable auto DHCP using @ref m2m_wifi_enable_dhcp before assigning a static IP address.
  1378. @brief Assign a static IP address to the WINC board.
  1379. This function assigns a static IP address in case the AP doesn't have a DHCP server or in case the application
  1380. wants to assign a predefined known IP address. The user must take in mind that assigning a static IP address might
  1381. result in an IP address conflict. In case of an IP address conflict observed by the WINC board the user will get a
  1382. response of @ref M2M_WIFI_RESP_IP_CONFLICT in the wifi callback. The application is then responsible to either solve the
  1383. conflict or assign another IP address.
  1384. @warning
  1385. Normally this function normally should not be used. DHCP configuration is requested automatically after successful
  1386. Wi-Fi connection is established.
  1387. @see
  1388. tstrM2MIPConfig
  1389. @return
  1390. The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  1391. */
  1392. NMI_API sint8 m2m_wifi_set_static_ip(tstrM2MIPConfig *pstrStaticIPConf);
  1393. /**@}*/
  1394. /** @defgroup RequestDHCPClientFn m2m_wifi_request_dhcp_client
  1395. * @ingroup WLANAPI
  1396. * Starts the DHCP client operation(DHCP requested by the firmware automatically in STA/AP/P2P mode).
  1397. *
  1398. */
  1399. /**@{*/
  1400. /*!
  1401. @fn \
  1402. NMI_API sint8 m2m_wifi_request_dhcp_client(void);
  1403. @warning
  1404. This function is legacy and exists only for compatability with older applications. DHCP configuration is requested
  1405. automatically after successful Wi-Fi connection is established.
  1406. @return
  1407. The function returns @ref M2M_SUCCESS always.
  1408. */
  1409. NMI_API sint8 m2m_wifi_request_dhcp_client(void);
  1410. /**@}*/
  1411. /** @defgroup RequestDHCPServerFn m2m_wifi_request_dhcp_server
  1412. * @ingroup WLANAPI
  1413. * Dhcp requested by the firmware automatically in STA/AP/P2P mode).
  1414. */
  1415. /**@{*/
  1416. /*!
  1417. @fn \
  1418. NMI_API sint8 m2m_wifi_request_dhcp_server(uint8* addr);
  1419. @warning
  1420. This function is legacy and exists only for compatability with older applications. DHCP server is started
  1421. automatically when enabling the AP mode.
  1422. @return
  1423. The function returns @ref M2M_SUCCESS always.
  1424. */
  1425. NMI_API sint8 m2m_wifi_request_dhcp_server(uint8 *addr);
  1426. /**@}*/
  1427. /** @defgroup WifiDHCPEnableFn m2m_wifi_enable_dhcp
  1428. * @ingroup WLANAPI
  1429. * Synchronous Wi-Fi DHCP enable function. This function Enable/Disable DHCP protocol.
  1430. */
  1431. /**@{*/
  1432. /*!
  1433. @fn \
  1434. NMI_API sint8 m2m_wifi_enable_dhcp(uint8 u8DhcpEn );
  1435. @brief
  1436. Enable/Disable the DHCP client after connection.
  1437. @param [in] u8DhcpEn
  1438. Possible values:
  1439. 1: Enable DHCP client after connection.
  1440. 0: Disable DHCP client after connection.
  1441. @warnings
  1442. -DHCP client is enabled by default
  1443. -This Function should be called before using m2m_wifi_set_static_ip()
  1444. @sa
  1445. m2m_wifi_set_static_ip()
  1446. @return
  1447. The function SHALL return @ref M2M_SUCCESS for successful operation and a negative value otherwise.
  1448. */
  1449. NMI_API sint8 m2m_wifi_enable_dhcp(uint8 u8DhcpEn);
  1450. /**@}*/
  1451. /** @defgroup WifiSetScanOptionFn m2m_wifi_set_scan_options
  1452. * @ingroup WLANAPI
  1453. * Synchronous Wi-Fi scan settings function. This function sets the time configuration parameters for the scan
  1454. * operation.
  1455. */
  1456. /*!
  1457. @fn \
  1458. sint8 m2m_wifi_set_scan_options(tstrM2MScanOption* ptstrM2MScanOption)
  1459. @param [in] ptstrM2MScanOption;
  1460. Pointer to the structure holding the Scan Parameters.
  1461. @see
  1462. tenuM2mScanCh
  1463. m2m_wifi_request_scan
  1464. tstrM2MScanOption
  1465. @return
  1466. The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  1467. */
  1468. NMI_API sint8 m2m_wifi_set_scan_options(tstrM2MScanOption *ptstrM2MScanOption);
  1469. /**@}*/
  1470. /** @defgroup WifiSetScanRegionFn m2m_wifi_set_scan_region
  1471. * @ingroup WLANAPI
  1472. * Synchronous wi-fi scan region setting function.
  1473. * This function sets the scan region, which will affect the range of possible scan channels.
  1474. * For 2.5GHz supported in the current release, the requested scan region can't exceed the maximum number of channels
  1475. *(14).
  1476. *@{*/
  1477. /*!
  1478. @fn \
  1479. sint8 m2m_wifi_set_scan_region(uint16 ScanRegion)
  1480. @param [in] ScanRegion;
  1481. ASIA
  1482. NORTH_AMERICA
  1483. @see
  1484. tenuM2mScanCh
  1485. m2m_wifi_request_scan
  1486. @return
  1487. The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  1488. */
  1489. NMI_API sint8 m2m_wifi_set_scan_region(uint16 ScanRegion);
  1490. /**@}*/
  1491. /** @defgroup WifiRequestScanFn m2m_wifi_request_scan
  1492. * @ingroup WLANAPI
  1493. * Asynchronous Wi-FI scan request on the given channel. The scan status is delivered in the wifi event callback and
  1494. *then the application is supposed to read the scan results sequentially. The number of APs found (N) is returned in
  1495. *event @ref M2M_WIFI_RESP_SCAN_DONE with the number of found APs. The application reads the list of APs by calling
  1496. *the function @ref m2m_wifi_req_scan_result N times.
  1497. *
  1498. *@{*/
  1499. /*!
  1500. @fn \
  1501. NMI_API sint8 m2m_wifi_request_scan(uint8 ch);
  1502. @param [in] ch
  1503. RF Channel ID for SCAN operation. It should be set according to tenuM2mScanCh.
  1504. With a value of M2M_WIFI_CH_ALL(255)), means to scan all channels.
  1505. @warning
  1506. This function is not allowed in P2P or AP modes. It works only for STA mode (both connected or disconnected states).
  1507. @pre
  1508. - A Wi-Fi notification callback of type @ref tpfAppWifiCb MUST be implemented and registered at initialization.
  1509. Registering the callback is done through passing it to the @ref m2m_wifi_init.
  1510. - The events @ref M2M_WIFI_RESP_SCAN_DONE and @ref M2M_WIFI_RESP_SCAN_RESULT.
  1511. must be handled in the callback.
  1512. - The @ref m2m_wifi_handle_events function MUST be called to receive the responses in the callback.
  1513. @see
  1514. M2M_WIFI_RESP_SCAN_DONE
  1515. M2M_WIFI_RESP_SCAN_RESULT
  1516. tpfAppWifiCb
  1517. tstrM2mWifiscanResult
  1518. tenuM2mScanCh
  1519. m2m_wifi_init
  1520. m2m_wifi_handle_events
  1521. m2m_wifi_req_scan_result
  1522. @return
  1523. The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  1524. \section Example
  1525. The code snippet demonstrates an example of how the scan request is called from the application's main function and
  1526. the handling of the events received in response.
  1527. @code
  1528. #include "m2m_wifi.h"
  1529. #include "m2m_types.h"
  1530. void wifi_event_cb(uint8 u8WiFiEvent, void * pvMsg)
  1531. {
  1532. static uint8 u8ScanResultIdx = 0;
  1533. switch(u8WiFiEvent)
  1534. {
  1535. case M2M_WIFI_RESP_SCAN_DONE:
  1536. {
  1537. tstrM2mScanDone *pstrInfo = (tstrM2mScanDone*)pvMsg;
  1538. printf("Num of AP found %d\n",pstrInfo->u8NumofCh);
  1539. if(pstrInfo->s8ScanState == M2M_SUCCESS)
  1540. {
  1541. u8ScanResultIdx = 0;
  1542. if(pstrInfo->u8NumofCh >= 1)
  1543. {
  1544. m2m_wifi_req_scan_result(u8ScanResultIdx);
  1545. u8ScanResultIdx ++;
  1546. }
  1547. else
  1548. {
  1549. printf("No AP Found Rescan\n");
  1550. m2m_wifi_request_scan(M2M_WIFI_CH_ALL);
  1551. }
  1552. }
  1553. else
  1554. {
  1555. printf("(ERR) Scan fail with error <%d>\n",pstrInfo->s8ScanState);
  1556. }
  1557. }
  1558. break;
  1559. case M2M_WIFI_RESP_SCAN_RESULT:
  1560. {
  1561. tstrM2mWifiscanResult *pstrScanResult =(tstrM2mWifiscanResult*)pvMsg;
  1562. uint8 u8NumFoundAPs = m2m_wifi_get_num_ap_found();
  1563. printf(">>%02d RI %d SEC %s CH %02d BSSID %02X:%02X:%02X:%02X:%02X:%02X SSID %s\n",
  1564. pstrScanResult->u8index,pstrScanResult->s8rssi,
  1565. pstrScanResult->u8AuthType,
  1566. pstrScanResult->u8ch,
  1567. pstrScanResult->au8BSSID[0], pstrScanResult->au8BSSID[1], pstrScanResult->au8BSSID[2],
  1568. pstrScanResult->au8BSSID[3], pstrScanResult->au8BSSID[4], pstrScanResult->au8BSSID[5],
  1569. pstrScanResult->au8SSID);
  1570. if(u8ScanResultIdx < u8NumFoundAPs)
  1571. {
  1572. // Read the next scan result
  1573. m2m_wifi_req_scan_result(index);
  1574. u8ScanResultIdx ++;
  1575. }
  1576. }
  1577. break;
  1578. default:
  1579. break;
  1580. }
  1581. }
  1582. int main()
  1583. {
  1584. tstrWifiInitParam param;
  1585. param.pfAppWifiCb = wifi_event_cb;
  1586. if(!m2m_wifi_init(&param))
  1587. {
  1588. // Scan all channels
  1589. m2m_wifi_request_scan(M2M_WIFI_CH_ALL);
  1590. while(1)
  1591. {
  1592. m2m_wifi_handle_events(NULL);
  1593. }
  1594. }
  1595. }
  1596. @endcode
  1597. */
  1598. NMI_API sint8 m2m_wifi_request_scan(uint8 ch);
  1599. /**@}*/
  1600. /** @defgroup WifiRequestScanFn m2m_wifi_request_scan_passive
  1601. * @ingroup WLANAPI
  1602. * Same as m2m_wifi_request_scan but perform passive scanning while the other one perform active scanning.
  1603. *
  1604. *@{*/
  1605. /*!
  1606. @fn \
  1607. NMI_API sint8 m2m_wifi_request_scan_passive(uint8 ch, uint16 scan_time);
  1608. @param [in] ch
  1609. RF Channel ID for SCAN operation. It should be set according to tenuM2mScanCh.
  1610. With a value of M2M_WIFI_CH_ALL(255)), means to scan all channels.
  1611. @param [in] scan_time
  1612. The time in ms that passive scan is listening to beacons on each channel per one slot, enter 0 for deafult
  1613. setting.
  1614. @warning
  1615. This function is not allowed in P2P or AP modes. It works only for STA mode (both connected or disconnected states).
  1616. @pre
  1617. - A Wi-Fi notification callback of type @ref tpfAppWifiCb MUST be implemented and registered at initialization.
  1618. Registering the callback is done through passing it to the @ref m2m_wifi_init.
  1619. - The events @ref M2M_WIFI_RESP_SCAN_DONE and @ref M2M_WIFI_RESP_SCAN_RESULT.
  1620. must be handled in the callback.
  1621. - The @ref m2m_wifi_handle_events function MUST be called to receive the responses in the callback.
  1622. @see
  1623. m2m_wifi_request_scan
  1624. M2M_WIFI_RESP_SCAN_DONE
  1625. M2M_WIFI_RESP_SCAN_RESULT
  1626. tpfAppWifiCb
  1627. tstrM2mWifiscanResult
  1628. tenuM2mScanCh
  1629. m2m_wifi_init
  1630. m2m_wifi_handle_events
  1631. m2m_wifi_req_scan_result
  1632. @return
  1633. The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  1634. */
  1635. NMI_API sint8 m2m_wifi_request_scan_passive(uint8 ch, uint16 scan_time);
  1636. /**@}*/
  1637. /** @defgroup WifiRequestScanFn m2m_wifi_request_scan_ssid_list
  1638. * @ingroup WLANAPI
  1639. * Asynchronous wi-fi scan request on the given channel and the hidden scan list. The scan status is delivered in the
  1640. *wi-fi event callback and then the application is to read the scan results sequentially. The number of APs found (N)
  1641. *is returned in event @ref M2M_WIFI_RESP_SCAN_DONE with the number of found APs. The application could read the
  1642. *list of APs by calling the function @ref m2m_wifi_req_scan_result N times.
  1643. *
  1644. *@{*/
  1645. /*!
  1646. @fn \
  1647. NMI_API sint8 m2m_wifi_request_scan_ssid_list(uint8 ch,uint8 * u8SsidList);
  1648. @param [in] ch
  1649. RF Channel ID for SCAN operation. It should be set according to tenuM2mScanCh.
  1650. With a value of M2M_WIFI_CH_ALL(255)), means to scan all channels.
  1651. @param [in] u8SsidList
  1652. u8SsidList is a buffer containing a list of hidden SSIDs to
  1653. include during the scan. The first byte in the buffer, u8SsidList[0],
  1654. is the number of SSIDs encoded in the string. The number of hidden SSIDs
  1655. cannot exceed MAX_HIDDEN_SITES. All SSIDs are concatenated in the following
  1656. bytes and each SSID is prefixed with a one-byte header containing its length.
  1657. The total number of bytes in u8SsidList buffer, including length byte, cannot
  1658. exceed 133 bytes (MAX_HIDDEN_SITES SSIDs x 32 bytes each, which is max SSID length).
  1659. For instance, encoding the two hidden SSIDs "DEMO_AP" and "TEST"
  1660. results in the following buffer content:
  1661. @code
  1662. uint8 u8SsidList[14];
  1663. u8SsidList[0] = 2; // Number of SSIDs is 2
  1664. u8SsidList[1] = 7; // Length of the string "DEMO_AP" without NULL termination
  1665. memcpy(&u8SsidList[2], "DEMO_AP", 7); // Bytes index 2-9 containing the string DEMO_AP
  1666. u8SsidList[9] = 4; // Length of the string "TEST" without NULL termination
  1667. memcpy(&u8SsidList[10], "TEST", 4); // Bytes index 10-13 containing the string TEST
  1668. @endcode
  1669. @warning
  1670. This function is not allowed in P2P. It works only for STA/AP mode (connected or disconnected).
  1671. @pre
  1672. - A Wi-Fi notification callback of type @ref tpfAppWifiCb MUST be implemented and registered at initialization.
  1673. Registering the callback is done through passing it to the @ref m2m_wifi_init.
  1674. - The events @ref M2M_WIFI_RESP_SCAN_DONE and @ref M2M_WIFI_RESP_SCAN_RESULT.
  1675. must be handled in the callback.
  1676. - The @ref m2m_wifi_handle_events function MUST be called to receive the responses in the callback.
  1677. @see
  1678. M2M_WIFI_RESP_SCAN_DONE
  1679. M2M_WIFI_RESP_SCAN_RESULT
  1680. tpfAppWifiCb
  1681. tstrM2mWifiscanResult
  1682. tenuM2mScanCh
  1683. m2m_wifi_init
  1684. m2m_wifi_handle_events
  1685. m2m_wifi_req_scan_result
  1686. @return
  1687. The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  1688. \section Example
  1689. The code snippet demonstrates an example of how the scan request is called from the application's main function and
  1690. the handling of the events received in response.
  1691. @code
  1692. #include "m2m_wifi.h"
  1693. #include "m2m_types.h"
  1694. static void request_scan_hidden_demo_ap(void);
  1695. void wifi_event_cb(uint8 u8WiFiEvent, void * pvMsg)
  1696. {
  1697. static uint8 u8ScanResultIdx = 0;
  1698. switch(u8WiFiEvent)
  1699. {
  1700. case M2M_WIFI_RESP_SCAN_DONE:
  1701. {
  1702. tstrM2mScanDone *pstrInfo = (tstrM2mScanDone*)pvMsg;
  1703. printf("Num of AP found %d\n",pstrInfo->u8NumofCh);
  1704. if(pstrInfo->s8ScanState == M2M_SUCCESS)
  1705. {
  1706. u8ScanResultIdx = 0;
  1707. if(pstrInfo->u8NumofCh >= 1)
  1708. {
  1709. m2m_wifi_req_scan_result(u8ScanResultIdx);
  1710. u8ScanResultIdx ++;
  1711. }
  1712. else
  1713. {
  1714. printf("No AP Found Rescan\n");
  1715. request_scan_hidden_demo_ap();
  1716. }
  1717. }
  1718. else
  1719. {
  1720. printf("(ERR) Scan fail with error <%d>\n",pstrInfo->s8ScanState);
  1721. }
  1722. }
  1723. break;
  1724. case M2M_WIFI_RESP_SCAN_RESULT:
  1725. {
  1726. tstrM2mWifiscanResult *pstrScanResult =(tstrM2mWifiscanResult*)pvMsg;
  1727. uint8 u8NumFoundAPs = m2m_wifi_get_num_ap_found();
  1728. printf(">>%02d RI %d SEC %s CH %02d BSSID %02X:%02X:%02X:%02X:%02X:%02X SSID %s\n",
  1729. pstrScanResult->u8index,pstrScanResult->s8rssi,
  1730. pstrScanResult->u8AuthType,
  1731. pstrScanResult->u8ch,
  1732. pstrScanResult->au8BSSID[0], pstrScanResult->au8BSSID[1], pstrScanResult->au8BSSID[2],
  1733. pstrScanResult->au8BSSID[3], pstrScanResult->au8BSSID[4], pstrScanResult->au8BSSID[5],
  1734. pstrScanResult->au8SSID);
  1735. if(u8ScanResultIdx < u8NumFoundAPs)
  1736. {
  1737. // Read the next scan result
  1738. m2m_wifi_req_scan_result(index);
  1739. u8ScanResultIdx ++;
  1740. }
  1741. }
  1742. break;
  1743. default:
  1744. break;
  1745. }
  1746. }
  1747. static void request_scan_hidden_demo_ap(void)
  1748. {
  1749. uint8 list[9];
  1750. char ssid[] = "DEMO_AP";
  1751. uint8 len = (uint8)(sizeof(ssid)-1);
  1752. list[0] = 1;
  1753. list[1] = len;
  1754. memcpy(&list[2], ssid, len); // copy 7 bytes
  1755. // Scan all channels
  1756. m2m_wifi_request_scan_ssid_list(M2M_WIFI_CH_ALL, list);
  1757. }
  1758. int main()
  1759. {
  1760. tstrWifiInitParam param;
  1761. param.pfAppWifiCb = wifi_event_cb;
  1762. if(!m2m_wifi_init(&param))
  1763. {
  1764. request_scan_hidden_demo_ap();
  1765. while(1)
  1766. {
  1767. m2m_wifi_handle_events(NULL);
  1768. }
  1769. }
  1770. }
  1771. @endcode
  1772. */
  1773. NMI_API sint8 m2m_wifi_request_scan_ssid_list(uint8 ch, uint8 *u8Ssidlist);
  1774. /**@}*/
  1775. /** @defgroup WifiGetNumAPFoundFn m2m_wifi_get_num_ap_found
  1776. * @ingroup WLANAPI
  1777. * Synchronous function to retrieve the number of AP's found in the last scan request, The function reads the number of
  1778. * APs from global variable which was updated in the Wi-Fi callback function through the M2M_WIFI_RESP_SCAN_DONE event.
  1779. * Function used only in STA mode only.
  1780. */
  1781. /**@{*/
  1782. /*!
  1783. @fn NMI_API uint8 m2m_wifi_get_num_ap_found(void);
  1784. @see m2m_wifi_request_scan
  1785. M2M_WIFI_RESP_SCAN_DONE
  1786. M2M_WIFI_RESP_SCAN_RESULT
  1787. @pre m2m_wifi_request_scan need to be called first
  1788. - A Wi-Fi notification callback of type @ref tpfAppWifiCb MUST be implemented and registered at initialization.
  1789. Registering the callback is done through passing it to the @ref m2m_wifi_init.
  1790. - The event @ref M2M_WIFI_RESP_SCAN_DONE must be handled in the callback to receive the requested scan
  1791. information.
  1792. @warning This function must be called only in the wi-fi callback function when the events @ref M2M_WIFI_RESP_SCAN_DONE
  1793. or @ref M2M_WIFI_RESP_SCAN_RESULT are received. Calling this function in any other place will result in
  1794. undefined/outdated numbers.
  1795. @return Return the number of AP's found in the last Scan Request.
  1796. \section Example
  1797. The code snippet demonstrates an example of how the scan request is called from the application's main function and
  1798. the handling of the events received in response.
  1799. @code
  1800. #include "m2m_wifi.h"
  1801. #include "m2m_types.h"
  1802. void wifi_event_cb(uint8 u8WiFiEvent, void * pvMsg)
  1803. {
  1804. static uint8 u8ScanResultIdx = 0;
  1805. switch(u8WiFiEvent)
  1806. {
  1807. case M2M_WIFI_RESP_SCAN_DONE:
  1808. {
  1809. tstrM2mScanDone *pstrInfo = (tstrM2mScanDone*)pvMsg;
  1810. printf("Num of AP found %d\n",pstrInfo->u8NumofCh);
  1811. if(pstrInfo->s8ScanState == M2M_SUCCESS)
  1812. {
  1813. u8ScanResultIdx = 0;
  1814. if(pstrInfo->u8NumofCh >= 1)
  1815. {
  1816. m2m_wifi_req_scan_result(u8ScanResultIdx);
  1817. u8ScanResultIdx ++;
  1818. }
  1819. else
  1820. {
  1821. printf("No AP Found Rescan\n");
  1822. m2m_wifi_request_scan(M2M_WIFI_CH_ALL);
  1823. }
  1824. }
  1825. else
  1826. {
  1827. printf("(ERR) Scan fail with error <%d>\n",pstrInfo->s8ScanState);
  1828. }
  1829. }
  1830. break;
  1831. case M2M_WIFI_RESP_SCAN_RESULT:
  1832. {
  1833. tstrM2mWifiscanResult *pstrScanResult =(tstrM2mWifiscanResult*)pvMsg;
  1834. uint8 u8NumFoundAPs = m2m_wifi_get_num_ap_found();
  1835. printf(">>%02d RI %d SEC %s CH %02d BSSID %02X:%02X:%02X:%02X:%02X:%02X SSID %s\n",
  1836. pstrScanResult->u8index,pstrScanResult->s8rssi,
  1837. pstrScanResult->u8AuthType,
  1838. pstrScanResult->u8ch,
  1839. pstrScanResult->au8BSSID[0], pstrScanResult->au8BSSID[1], pstrScanResult->au8BSSID[2],
  1840. pstrScanResult->au8BSSID[3], pstrScanResult->au8BSSID[4], pstrScanResult->au8BSSID[5],
  1841. pstrScanResult->au8SSID);
  1842. if(u8ScanResultIdx < u8NumFoundAPs)
  1843. {
  1844. // Read the next scan result
  1845. m2m_wifi_req_scan_result(index);
  1846. u8ScanResultIdx ++;
  1847. }
  1848. }
  1849. break;
  1850. default:
  1851. break;
  1852. }
  1853. }
  1854. int main()
  1855. {
  1856. tstrWifiInitParam param;
  1857. param.pfAppWifiCb = wifi_event_cb;
  1858. if(!m2m_wifi_init(&param))
  1859. {
  1860. // Scan all channels
  1861. m2m_wifi_request_scan(M2M_WIFI_CH_ALL);
  1862. while(1)
  1863. {
  1864. m2m_wifi_handle_events(NULL);
  1865. }
  1866. }
  1867. }
  1868. @endcode
  1869. */
  1870. NMI_API uint8 m2m_wifi_get_num_ap_found(void);
  1871. /**@}*/
  1872. /** @defgroup WifiReqScanResult m2m_wifi_req_scan_result
  1873. * @ingroup WLANAPI
  1874. * Synchronous call to read the AP information from the SCAN Result list with the given index.
  1875. * This function is expected to be called when the response events M2M_WIFI_RESP_SCAN_RESULT or
  1876. * M2M_WIFI_RESP_SCAN_DONE are received in the wi-fi callback function.
  1877. * The response information received can be obtained through the casting to the @ref tstrM2mWifiscanResult structure
  1878. */
  1879. /**@{*/
  1880. /*!
  1881. @fn NMI_API sint8 m2m_wifi_req_scan_result(uint8 index);
  1882. @param [in] index
  1883. Index for the requested result, the index range start from 0 till number of AP's found
  1884. @see tstrM2mWifiscanResult
  1885. m2m_wifi_get_num_ap_found
  1886. m2m_wifi_request_scan
  1887. @pre @ref m2m_wifi_request_scan needs to be called first, then m2m_wifi_get_num_ap_found
  1888. to get the number of AP's found
  1889. - A Wi-Fi notification callback of type @ref tpfAppWifiCb MUST be implemented and registered at startup.
  1890. Registering the callback is done through passing it to the @ref m2m_wifi_init function.
  1891. - The event @ref M2M_WIFI_RESP_SCAN_RESULT must be handled in the callback to receive the requested scan
  1892. information.
  1893. @warning Function used in STA mode only. the scan results are updated only if the scan request is called.
  1894. Calling this function only without a scan request will lead to firmware errors.
  1895. Refrain from introducing a large delay between the scan request and the scan result request, to prevent
  1896. errors occurring.
  1897. @return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  1898. \section Example
  1899. The code snippet demonstrates an example of how the scan request is called from the application's main function and
  1900. the handling of the events received in response.
  1901. @code
  1902. #include "m2m_wifi.h"
  1903. #include "m2m_types.h"
  1904. void wifi_event_cb(uint8 u8WiFiEvent, void * pvMsg)
  1905. {
  1906. static uint8 u8ScanResultIdx = 0;
  1907. switch(u8WiFiEvent)
  1908. {
  1909. case M2M_WIFI_RESP_SCAN_DONE:
  1910. {
  1911. tstrM2mScanDone *pstrInfo = (tstrM2mScanDone*)pvMsg;
  1912. printf("Num of AP found %d\n",pstrInfo->u8NumofCh);
  1913. if(pstrInfo->s8ScanState == M2M_SUCCESS)
  1914. {
  1915. u8ScanResultIdx = 0;
  1916. if(pstrInfo->u8NumofCh >= 1)
  1917. {
  1918. m2m_wifi_req_scan_result(u8ScanResultIdx);
  1919. u8ScanResultIdx ++;
  1920. }
  1921. else
  1922. {
  1923. printf("No AP Found Rescan\n");
  1924. m2m_wifi_request_scan(M2M_WIFI_CH_ALL);
  1925. }
  1926. }
  1927. else
  1928. {
  1929. printf("(ERR) Scan fail with error <%d>\n",pstrInfo->s8ScanState);
  1930. }
  1931. }
  1932. break;
  1933. case M2M_WIFI_RESP_SCAN_RESULT:
  1934. {
  1935. tstrM2mWifiscanResult *pstrScanResult =(tstrM2mWifiscanResult*)pvMsg;
  1936. uint8 u8NumFoundAPs = m2m_wifi_get_num_ap_found();
  1937. printf(">>%02d RI %d SEC %s CH %02d BSSID %02X:%02X:%02X:%02X:%02X:%02X SSID %s\n",
  1938. pstrScanResult->u8index,pstrScanResult->s8rssi,
  1939. pstrScanResult->u8AuthType,
  1940. pstrScanResult->u8ch,
  1941. pstrScanResult->au8BSSID[0], pstrScanResult->au8BSSID[1], pstrScanResult->au8BSSID[2],
  1942. pstrScanResult->au8BSSID[3], pstrScanResult->au8BSSID[4], pstrScanResult->au8BSSID[5],
  1943. pstrScanResult->au8SSID);
  1944. if(u8ScanResultIdx < u8NumFoundAPs)
  1945. {
  1946. // Read the next scan result
  1947. m2m_wifi_req_scan_result(index);
  1948. u8ScanResultIdx ++;
  1949. }
  1950. }
  1951. break;
  1952. default:
  1953. break;
  1954. }
  1955. }
  1956. int main()
  1957. {
  1958. tstrWifiInitParam param;
  1959. param.pfAppWifiCb = wifi_event_cb;
  1960. if(!m2m_wifi_init(&param))
  1961. {
  1962. // Scan all channels
  1963. m2m_wifi_request_scan(M2M_WIFI_CH_ALL);
  1964. while(1)
  1965. {
  1966. m2m_wifi_handle_events(NULL);
  1967. }
  1968. }
  1969. }
  1970. @endcode
  1971. */
  1972. NMI_API sint8 m2m_wifi_req_scan_result(uint8 index);
  1973. /**@}*/
  1974. /** @defgroup WifiReqCurrentRssiFn m2m_wifi_req_curr_rssi
  1975. * @ingroup WLANAPI
  1976. * Asynchronous request for the current RSSI of the connected AP.
  1977. * The response received in through the @ref M2M_WIFI_RESP_CURRENT_RSSI event.
  1978. */
  1979. /**@{*/
  1980. /*!
  1981. @fn NMI_API sint8 m2m_wifi_req_curr_rssi(void);
  1982. @pre - A Wi-Fi notification callback of type @ref tpfAppWifiCb MUST be implemented and registered before
  1983. initialization. Registering the callback is done through passing it to the [m2m_wifi_init](@ref m2m_wifi_init) through
  1984. the @ref tstrWifiInitParam initialization structure.
  1985. - The event @ref M2M_WIFI_RESP_CURRENT_RSSI must be handled in the callback to receive the requested Rssi
  1986. information.
  1987. @return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  1988. \section Example
  1989. The code snippet demonstrates how the RSSI request is called in the application's main function and the handling of
  1990. the event received in the callback.
  1991. @code
  1992. #include "m2m_wifi.h"
  1993. #include "m2m_types.h"
  1994. void wifi_event_cb(uint8 u8WiFiEvent, void * pvMsg)
  1995. {
  1996. static uint8 u8ScanResultIdx = 0;
  1997. switch(u8WiFiEvent)
  1998. {
  1999. case M2M_WIFI_RESP_CURRENT_RSSI:
  2000. {
  2001. sint8 *rssi = (sint8*)pvMsg;
  2002. M2M_INFO("ch rssi %d\n",*rssi);
  2003. }
  2004. break;
  2005. default:
  2006. break;
  2007. }
  2008. }
  2009. int main()
  2010. {
  2011. tstrWifiInitParam param;
  2012. param.pfAppWifiCb = wifi_event_cb;
  2013. if(!m2m_wifi_init(&param))
  2014. {
  2015. // Scan all channels
  2016. m2m_wifi_req_curr_rssi();
  2017. while(1)
  2018. {
  2019. m2m_wifi_handle_events(NULL);
  2020. }
  2021. }
  2022. }
  2023. @endcode
  2024. */
  2025. NMI_API sint8 m2m_wifi_req_curr_rssi(void);
  2026. /**@}*/
  2027. /** @defgroup WifiGetOtpMacAddFn m2m_wifi_get_otp_mac_address
  2028. * @ingroup WLANAPI
  2029. * Request the MAC address stored on the One Time Programmable(OTP) memory of the device.
  2030. * The function is blocking until the response is received.
  2031. */
  2032. /**@{*/
  2033. /*!
  2034. @fn NMI_API sint8 m2m_wifi_get_otp_mac_address(uint8 *pu8MacAddr, uint8 * pu8IsValid);
  2035. @param [out] pu8MacAddr
  2036. Output MAC address buffer of 6 bytes size. Valid only if *pu8Valid=1.
  2037. @param [out] pu8IsValid
  2038. Output boolean value to indicate the validity of pu8MacAddr in OTP.
  2039. Output zero if the OTP memory is not programmed, non-zero otherwise.
  2040. @pre m2m_wifi_init required to be called before any WIFI/socket function
  2041. @see m2m_wifi_get_mac_address
  2042. @return The function returns @ref M2M_SUCCESS for success and a negative value otherwise.
  2043. */
  2044. NMI_API sint8 m2m_wifi_get_otp_mac_address(uint8 *pu8MacAddr, uint8 *pu8IsValid);
  2045. /**@}*/
  2046. /** @defgroup WifiGetMacAddFn m2m_wifi_get_mac_address
  2047. * @ingroup WLANAPI
  2048. * Function to retrieve the current MAC address. The function is blocking until the response is received.
  2049. */
  2050. /**@{*/
  2051. /*!
  2052. @fn NMI_API sint8 m2m_wifi_get_mac_address(uint8 *pu8MacAddr)
  2053. @param [out] pu8MacAddr
  2054. Output MAC address buffer of 6 bytes size.
  2055. @pre m2m_wifi_init required to be called before any WIFI/socket function
  2056. @see m2m_wifi_get_otp_mac_address
  2057. @return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  2058. */
  2059. NMI_API sint8 m2m_wifi_get_mac_address(uint8 *pu8MacAddr);
  2060. /**@}*/
  2061. /** @defgroup SetSleepModeFn m2m_wifi_set_sleep_mode
  2062. * @ingroup WLANAPI
  2063. * This is one of the two synchronous power-save setting functions that
  2064. * allow the host MCU application to tweak the system power consumption. Such tweaking can be done through one of two
  2065. * ways: 1) Changing the power save mode, to one of the allowed power save modes @ref tenuPowerSaveModes. This is done
  2066. * by setting the first parameter 2) Configuring DTIM monitoring: Configuring beacon monitoring parameters by enabling
  2067. * or disabling the reception of broadcast/multicast data. this is done by setting the second parameter.
  2068. */
  2069. /**@{*/
  2070. /*!
  2071. @fn NMI_API sint8 m2m_wifi_set_sleep_mode(uint8 PsTyp, uint8 BcastEn);
  2072. @param [in] PsTyp
  2073. Desired power saving mode. Supported types are enumerated in @ref tenuPowerSaveModes.
  2074. @param [in] BcastEn
  2075. Broadcast reception enable flag.
  2076. If it is 1, the WINC1500 will be awake each DTIM beacon for receiving broadcast traffic.
  2077. If it is 0, the WINC1500: disable broadcast traffic. Through this flag the WINC1500 will not wakeup at the
  2078. DTIM beacon, but it will wakeup depends only on the the configured Listen Interval.
  2079. @warning The function called once after initialization.
  2080. @see tenuPowerSaveModes
  2081. m2m_wifi_get_sleep_mode
  2082. m2m_wifi_set_lsn_int
  2083. @return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  2084. */
  2085. NMI_API sint8 m2m_wifi_set_sleep_mode(uint8 PsTyp, uint8 BcastEn);
  2086. /**@}*/
  2087. /** @defgroup WifiRequestSleepFn m2m_wifi_request_sleep
  2088. * @ingroup WLANAPI
  2089. * Synchronous power-save sleep request function, which requests from the WINC1500 device to sleep in the currenlty
  2090. * configured power save mode as defined by the @ref m2m_wifi_set_sleep_mode, for a specific time as defined by the
  2091. * passed in parameter. This function should be used in the @ref M2M_PS_MANUAL power save mode only. A wake up
  2092. * request is automatically performed by the WINC1500 device when any host driver API function, e.g. Wi-Fi or socket
  2093. * operation is called.
  2094. */
  2095. /**@{*/
  2096. /*!
  2097. @fn NMI_API sint8 m2m_wifi_request_sleep(uint32 u32SlpReqTime);
  2098. @param [in] u32SlpReqTime
  2099. Request sleep time in ms
  2100. The best recommended sleep duration is left to be determined by the application. Taking into account that if
  2101. the application sends notifications very rarely, sleeping for a long time can be a power-efficient decision. In contrast
  2102. applications that are senstive for long periods of absence can experience performance degradation in the connection if
  2103. long sleeping times are used.
  2104. @warning The function should be called in @ref M2M_PS_MANUAL power save mode only. As enumerated in @ref
  2105. tenuPowerSaveModes It's also important to note that during the sleeping time while in the M2M_PS_MANUAL mode, AP beacon
  2106. monitoring is bypassed and the wifi-connection may drop if the sleep period is enlongated.
  2107. @see tenuPowerSaveModes
  2108. m2m_wifi_set_sleep_mode
  2109. @return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  2110. */
  2111. NMI_API sint8 m2m_wifi_request_sleep(uint32 u32SlpReqTime);
  2112. /**@}*/
  2113. /** @defgroup GetSleepModeFn m2m_wifi_get_sleep_mode
  2114. * @ingroup WLANAPI
  2115. * Synchronous power save mode retrieval function.
  2116. */
  2117. /**@{*/
  2118. /*!
  2119. @fn NMI_API uint8 m2m_wifi_get_sleep_mode(void);
  2120. @see tenuPowerSaveModes
  2121. m2m_wifi_set_sleep_mode
  2122. @return The current operating power saving mode based on the enumerated sleep modes @ref tenuPowerSaveModes.
  2123. */
  2124. NMI_API uint8 m2m_wifi_get_sleep_mode(void);
  2125. /**@}*/
  2126. /** @defgroup WifiReqClientCtrlFn m2m_wifi_req_client_ctrl
  2127. * @ingroup WLANAPI
  2128. * Asynchronous command sending function to the PS Client (An WINC1500 board running the ps_firmware)
  2129. * if the PS client send any command it will be received through the @ref M2M_WIFI_RESP_CLIENT_INFO event
  2130. */
  2131. /**@{*/
  2132. /*!
  2133. @fn NMI_API sint8 m2m_wifi_req_client_ctrl(uint8 cmd);
  2134. @brief
  2135. @param [in] cmd
  2136. Control command sent from PS Server to PS Client (command values defined by the application)
  2137. @pre @ref m2m_wifi_req_server_init should be called first
  2138. @warning This mode is not supported in the current release.
  2139. @see m2m_wifi_req_server_init
  2140. M2M_WIFI_RESP_CLIENT_INFO
  2141. @return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  2142. */
  2143. NMI_API sint8 m2m_wifi_req_client_ctrl(uint8 cmd);
  2144. /**@}*/
  2145. /** @defgroup WifiReqServerInit m2m_wifi_req_server_init
  2146. * @ingroup WLANAPI
  2147. * Synchronous function to initialize the PS Server.
  2148. * The WINC1500 supports non secure communication with another WINC1500,
  2149. * (SERVER/CLIENT) through one byte command (probe request and probe response) without any connection setup.
  2150. * The server mode can't be used with any other modes (STA/P2P/AP)
  2151. */
  2152. /**@{*/
  2153. /*!
  2154. @fn NMI_API sint8 m2m_wifi_req_server_init(uint8 ch);
  2155. @param [in] ch
  2156. Server listening channel
  2157. @see m2m_wifi_req_client_ctrl
  2158. @warning This mode is not supported in the current release.
  2159. @return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  2160. */
  2161. NMI_API sint8 m2m_wifi_req_server_init(uint8 ch);
  2162. /**@}*/
  2163. /** @defgroup WifiSetDeviceNameFn m2m_wifi_set_device_name
  2164. * @ingroup WLANAPI
  2165. * Sets the WINC device name. The name string is used as a device name in both (P2P) WiFi-Direct mode as well as DHCP
  2166. * hostname (option 12). For P2P devices to communicate a device name must be present. If it is not set through this
  2167. * function a default name is assigned. The default name is WINC-XX-YY, where XX and YY are the last 2 octets of the
  2168. * OTP MAC address. If OTP (eFuse) is programmed, then the default name is WINC-00-00.
  2169. */
  2170. /**@{*/
  2171. /*!
  2172. @fn NMI_API sint8 m2m_wifi_set_device_name(uint8 *pu8DeviceName, uint8 u8DeviceNameLength);
  2173. @param [in] pu8DeviceName
  2174. A Buffer holding the device name. Device name is a null terminated C string.
  2175. @param [in] u8DeviceNameLength
  2176. The length of the device name. Should not exceed the maximum device name's length @ref M2M_DEVICE_NAME_MAX
  2177. (including null character).
  2178. @warning The function called once after initialization.
  2179. Used for the Wi-Fi Direct (P2P) as well as DHCP client hostname option (12).
  2180. @warning Device name shall contain only characters allowed in valid internet host name as defined in RFC 952 and
  2181. 1123.
  2182. @return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  2183. */
  2184. NMI_API sint8 m2m_wifi_set_device_name(uint8 *pu8DeviceName, uint8 u8DeviceNameLength);
  2185. /**@}*/
  2186. /** @defgroup WifiSetLsnIntFn m2m_wifi_set_lsn_int
  2187. * @ingroup WLANAPI
  2188. * This is one of the two synchronous power-save setting functions that
  2189. * allow the host MCU application to tweak the system power consumption. Such tweaking can be done by modifying the
  2190. * the Wi-Fi listen interval. The listen interval is how many beacon periods the station can sleep before it wakes up
  2191. *to receive data buffer in AP. It is represented in units of AP beacon periods(100ms).
  2192. */
  2193. /**@{*/
  2194. /*!
  2195. @fn NMI_API sint8 m2m_wifi_set_lsn_int(tstrM2mLsnInt * pstrM2mLsnInt);
  2196. @param [in] pstrM2mLsnInt
  2197. Structure holding the listen interval configurations.
  2198. @pre Function @m2m_wifi_set_sleep_mode shall be called first, to set the power saving mode required.
  2199. @warning The function should be called once after initialization.
  2200. @see tstrM2mLsnInt
  2201. m2m_wifi_set_sleep_mode
  2202. @return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  2203. */
  2204. NMI_API sint8 m2m_wifi_set_lsn_int(tstrM2mLsnInt *pstrM2mLsnInt);
  2205. /**@}*/
  2206. /** @defgroup WifiEnableMonitorModeFn m2m_wifi_enable_monitoring_mode
  2207. * @ingroup WLANAPI
  2208. * Asynchronous Wi-Fi monitoring mode (Promiscuous mode) enabling function. This function enables the monitoring
  2209. * mode, thus allowing two operations to be performed: 1) Transmission of manually configured frames, through using the
  2210. * @ref m2m_wifi_send_wlan_pkt function. 2) Reception of frames based on a defined filtering criteria When the
  2211. * monitoring mode is enabled, reception of all frames that satisfy the filter criteria passed in as a parameter is
  2212. * allowed, on the current wireless channel \n. All packets that meet the filtering criteria are passed to the
  2213. * application layer, to be handled by the assigned monitoring callback function \n. The monitoring callback function
  2214. * must be implemented before starting the monitoring mode, in-order to handle the packets received \n. Registering
  2215. * of the implemented callback function is through the callback pointer @ref tpfAppMonCb in the @ref
  2216. * tstrWifiInitParam structure\n. passed to @ref m2m_wifi_init function at initialization.
  2217. *
  2218. */
  2219. /**@{*/
  2220. /*!
  2221. * @fn NMI_API sint8 m2m_wifi_enable_monitoring_mode(tstrM2MWifiMonitorModeCtrl *, uint8 *, uint16 ,
  2222. uint16);
  2223. * @param [in] pstrMtrCtrl
  2224. * Pointer to @ref tstrM2MWifiMonitorModeCtrl structure holding the filtering parameters.
  2225. * @param [in] pu8PayloadBuffer
  2226. * Pointer to a buffer allocated by the application. The buffer SHALL hold the Data field of
  2227. * the WIFI RX Packet (Or a part from it). If it is set to NULL, the WIFI data payload will
  2228. * be discarded by the monitoring driver.
  2229. * @param [in] u16BufferSize
  2230. * The total size of the pu8PayloadBuffer in bytes.
  2231. * @param [in] u16DataOffset
  2232. * Starting offset in the DATA FIELD of the received WIFI packet. The application may be interested
  2233. * in reading specific information from the received packet. It must assign the offset to the starting
  2234. * position of it relative to the DATA payload start.\n
  2235. * \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 \e
  2236. packet, \e the \e u16Offset \e MUST \e be \e set \e to \e 0.
  2237. * @warning When This mode is enabled, you can not be connected in any mode (Station, Access Point, or P2P).\n
  2238. * @see tstrM2MWifiMonitorModeCtrl
  2239. tstrM2MWifiRxPacketInfo
  2240. tstrWifiInitParam
  2241. tenuM2mScanCh
  2242. m2m_wifi_disable_monitoring_mode
  2243. m2m_wifi_send_wlan_pkt
  2244. m2m_wifi_send_ethernet_pkt
  2245. * @return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  2246. *\section Example
  2247. * The example demonstrates the main function where-by the monitoring enable function is called after the initialization
  2248. of the driver and the packets are
  2249. * handled in the callback function.
  2250. * @code
  2251. #include "m2m_wifi.h"
  2252. #include "m2m_types.h"
  2253. //Declare receive buffer
  2254. uint8 gmgmt[1600];
  2255. //Callback functions
  2256. void wifi_cb(uint8 u8WiFiEvent, void * pvMsg)
  2257. {
  2258. ;
  2259. }
  2260. void wifi_monitoring_cb(tstrM2MWifiRxPacketInfo *pstrWifiRxPacket, uint8 *pu8Payload, uint16 u16PayloadSize)
  2261. {
  2262. if((NULL != pstrWifiRxPacket) && (0 != u16PayloadSize)) {
  2263. if(MANAGEMENT == pstrWifiRxPacket->u8FrameType) {
  2264. M2M_INFO("***# MGMT PACKET #***\n");
  2265. } else if(DATA_BASICTYPE == pstrWifiRxPacket->u8FrameType) {
  2266. M2M_INFO("***# DATA PACKET #***\n");
  2267. } else if(CONTROL == pstrWifiRxPacket->u8FrameType) {
  2268. M2M_INFO("***# CONTROL PACKET #***\n");
  2269. }
  2270. }
  2271. }
  2272. int main()
  2273. {
  2274. //Register wifi_monitoring_cb
  2275. tstrWifiInitParam param;
  2276. param.pfAppWifiCb = wifi_cb;
  2277. param.pfAppMonCb = wifi_monitoring_cb;
  2278. nm_bsp_init();
  2279. if(!m2m_wifi_init(&param)) {
  2280. //Enable Monitor Mode with filter to receive all data frames on channel 1
  2281. tstrM2MWifiMonitorModeCtrl strMonitorCtrl = {0};
  2282. strMonitorCtrl.u8ChannelID = M2M_WIFI_CH_1;
  2283. strMonitorCtrl.u8FrameType = DATA_BASICTYPE;
  2284. strMonitorCtrl.u8FrameSubtype = M2M_WIFI_FRAME_SUB_TYPE_ANY; //Receive any subtype of data frame
  2285. m2m_wifi_enable_monitoring_mode(&strMonitorCtrl, gmgmt, sizeof(gmgmt), 0);
  2286. while(1) {
  2287. m2m_wifi_handle_events(NULL);
  2288. }
  2289. }
  2290. return 0;
  2291. }
  2292. * @endcode
  2293. */
  2294. NMI_API sint8 m2m_wifi_enable_monitoring_mode(tstrM2MWifiMonitorModeCtrl *pstrMtrCtrl, uint8 *pu8PayloadBuffer,
  2295. uint16 u16BufferSize, uint16 u16DataOffset);
  2296. /**@}*/
  2297. /** @defgroup WifiDisableMonitorModeFn m2m_wifi_disable_monitoring_mode
  2298. * @ingroup WLANAPI
  2299. * Synchronous function to disable Wi-Fi monitoring mode (Promiscuous mode). Expected to be called, if the enable
  2300. * monitoring mode is set, but if it was called without enabling no negative impact will reside.
  2301. */
  2302. /**@{*/
  2303. /*!
  2304. * @fn NMI_API sint8 m2m_wifi_disable_monitoring_mode(void);
  2305. * @see m2m_wifi_enable_monitoring_mode
  2306. * @return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  2307. */
  2308. NMI_API sint8 m2m_wifi_disable_monitoring_mode(void);
  2309. /**@}*/
  2310. /** @defgroup SendWlanPktFn m2m_wifi_send_wlan_pkt
  2311. * @ingroup WLANAPI
  2312. * Synchronous function to transmit a WIFI RAW packet while the implementation of this packet is left to the
  2313. * application developer.
  2314. */
  2315. /**@{*/
  2316. /*!
  2317. * @fn NMI_API sint8 m2m_wifi_send_wlan_pkt(uint8 *, uint16, uint16);
  2318. * @param [in] pu8WlanPacket
  2319. * Pointer to a buffer holding the whole WIFI frame.
  2320. * @param [in] u16WlanHeaderLength
  2321. * The size of the WIFI packet header ONLY.
  2322. * @param [in] u16WlanPktSize
  2323. * The size of the whole bytes in packet.
  2324. * @see m2m_wifi_enable_monitoring_mode
  2325. m2m_wifi_disable_monitoring_mode
  2326. * @pre Enable Monitoring mode first using @ref m2m_wifi_enable_monitoring_mode
  2327. * @warning This function available in monitoring mode ONLY.\n
  2328. * @note Packets are user's responsibility.
  2329. * @return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  2330. */
  2331. NMI_API sint8 m2m_wifi_send_wlan_pkt(uint8 *pu8WlanPacket, uint16 u16WlanHeaderLength, uint16 u16WlanPktSize);
  2332. /**@}*/
  2333. /** @defgroup WifiSendEthernetPktFn m2m_wifi_send_ethernet_pkt
  2334. * @ingroup WLANAPI
  2335. * Synchronous function to transmit an Ethernet packet. Transmit a packet directly in ETHERNET/bypass mode where the
  2336. * TCP/IP stack is disabled and the implementation of this packet is left to the application developer. The Ethernet
  2337. * packet composition is left to the application developer.
  2338. */
  2339. /**@{*/
  2340. /*!
  2341. * @fn NMI_API sint8 m2m_wifi_send_ethernet_pkt(uint8* pu8Packet,uint16 u16PacketSize)
  2342. * @param [in] pu8Packet
  2343. * Pointer to a buffer holding the whole Ethernet frame.
  2344. * @param [in] u16PacketSize
  2345. * The size of the whole bytes in packet.
  2346. * @warning This function available in ETHERNET/Bypass mode ONLY. Make sure that application defines @ref
  2347. ETH_MODE.\n
  2348. * @note Packets are the user's responsibility.
  2349. * @sa m2m_wifi_enable_mac_mcast,m2m_wifi_set_receive_buffer
  2350. * @return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  2351. */
  2352. NMI_API sint8 m2m_wifi_send_ethernet_pkt(uint8 *pu8Packet, uint16 u16PacketSize);
  2353. /**@}*/
  2354. /** @defgroup WifiEnableSntpFn m2m_wifi_enable_sntp
  2355. * @ingroup WLANAPI
  2356. * Synchronous function to enable/disable the native Simple Network Time Protocol(SNTP) client in the WINC1500
  2357. * firmware.\n The SNTP is enabled by default at start-up.The SNTP client at firmware is used to synchronize the system
  2358. * clock to the UTC time from the well known time servers (e.g. "time-c.nist.gov"). The SNTP client uses a default
  2359. * update cycle of 1 day. The UTC is important for checking the expiration date of X509 certificates used while
  2360. * establishing TLS (Transport Layer Security) connections. It is highly recommended to use it if there is no other
  2361. * means to get the UTC time. If there is a RTC on the host MCU, the SNTP could be disabled and the host should set
  2362. * the system time to the firmware using the @ref m2m_wifi_set_system_time function.
  2363. */
  2364. /**@{*/
  2365. /*!
  2366. * @fn NMI_API sint8 m2m_wifi_enable_sntp(uint8);
  2367. * @param [in] bEnable
  2368. * Enabling/Disabling flag
  2369. * '0' :disable SNTP
  2370. * '1' :enable SNTP
  2371. * @see m2m_wifi_set_sytem_time
  2372. * @return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  2373. */
  2374. NMI_API sint8 m2m_wifi_enable_sntp(uint8 bEnable);
  2375. /**@}*/
  2376. /** @defgroup WifiSetSystemTime m2m_wifi_set_sytem_time
  2377. * @ingroup WLANAPI
  2378. * Synchronous function for setting the system time in time/date format (@ref uint32).\n
  2379. * The @ref tstrSystemTime structure can be used as a reference to the time values that should be set and pass its
  2380. * value as @ref uint32
  2381. */
  2382. /**@{*/
  2383. /*!
  2384. * @fn NMI_API sint8 m2m_wifi_set_sytem_time(uint32);
  2385. * @param [in] u32UTCSeconds
  2386. * Seconds elapsed since January 1, 1900 (NTP Timestamp).
  2387. * @see m2m_wifi_enable_sntp
  2388. * tstrSystemTime
  2389. * @note If there is an RTC on the host MCU, the SNTP could be disabled and the host should set the system time
  2390. *to the firmware using the API @ref m2m_wifi_set_sytem_time.
  2391. * @return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  2392. */
  2393. NMI_API sint8 m2m_wifi_set_sytem_time(uint32 u32UTCSeconds);
  2394. /**@}*/
  2395. /** @defgroup WifiGetSystemTime m2m_wifi_get_sytem_time
  2396. * @ingroup WLANAPI
  2397. * Asynchronous function used to retrieve the system time through the use of the response @ref
  2398. * M2M_WIFI_RESP_GET_SYS_TIME. Response time retrieved is parsed into the members defined in the structure @ref
  2399. * tstrSystemTime.
  2400. */
  2401. /**@{*/
  2402. /*!
  2403. * @fn NMI_API sint8 m2m_wifi_get_sytem_time(void);
  2404. * @see m2m_wifi_enable_sntp
  2405. tstrSystemTime
  2406. * @note Get the system time from the SNTP client
  2407. * using the API @ref m2m_wifi_get_sytem_time.
  2408. * @return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  2409. */
  2410. NMI_API sint8 m2m_wifi_get_sytem_time(void);
  2411. /**@}*/
  2412. /** @defgroup WifiSetCustInfoElementFn m2m_wifi_set_cust_InfoElement
  2413. * @ingroup WLANAPI
  2414. * Synchronous function to Add/Remove user-defined Information Element to the WIFIBeacon and Probe Response frames
  2415. * while chip mode is Access Point Mode.\n According to the information element layout shown bellow, if it is required
  2416. * to set new data for the information elements, pass in the buffer with the information according to the sizes and
  2417. * ordering defined bellow. However, if it's required to delete these IEs, fill the buffer with zeros.
  2418. */
  2419. /**@{*/
  2420. /*!
  2421. * @fn NMI_API sint8 m2m_wifi_set_cust_InfoElement(uint8*);
  2422. * @param [in] pau8M2mCustInfoElement
  2423. * Pointer to Buffer containing the IE to be sent. It is the application developer's
  2424. responsibility to ensure on the correctness of the information element's ordering passed in.
  2425. * @warning - Size of All elements combined must not exceed 255 byte.\n
  2426. * - Used in Access Point Mode \n
  2427. * @note IEs Format will be follow the following layout:\n
  2428. * @verbatim
  2429. --------------- ---------- ---------- ------------------- -------- -------- -----------
  2430. ---------------------- | Byte[0] | Byte[1] | Byte[2] | Byte[3:length1+2] | ..... | Byte[n] | Byte[n+1] |
  2431. Byte[n+2:lengthx+2] |
  2432. |---------------|----------|----------|-------------------|--------
  2433. --------|-----------|------------------| | #of all Bytes | IE1 ID | Length1 | Data1(Hex Coded) | ..... | IEx ID |
  2434. Lengthx | Datax(Hex Coded) |
  2435. --------------- ---------- ---------- ------------------- -------- -------- -----------
  2436. ----------------------
  2437. * @endverbatim
  2438. * @see m2m_wifi_enable_sntp
  2439. * tstrSystemTime
  2440. * @return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  2441. \section Example
  2442. The example demonstrates how the information elements are set using this function.
  2443. *@code
  2444. *
  2445. char elementData[21];
  2446. static char state = 0; // To Add, Append, and Delete
  2447. if(0 == state) { //Add 3 IEs
  2448. state = 1;
  2449. //Total Number of Bytes
  2450. elementData[0]=12;
  2451. //First IE
  2452. elementData[1]=200; elementData[2]=1; elementData[3]='A';
  2453. //Second IE
  2454. elementData[4]=201; elementData[5]=2; elementData[6]='B'; elementData[7]='C';
  2455. //Third IE
  2456. elementData[8]=202; elementData[9]=3; elementData[10]='D'; elementData[11]=0; elementData[12]='F';
  2457. } else if(1 == state) {
  2458. //Append 2 IEs to others, Notice that we keep old data in array starting with\n
  2459. //element 13 and total number of bytes increased to 20
  2460. state = 2;
  2461. //Total Number of Bytes
  2462. elementData[0]=20;
  2463. //Fourth IE
  2464. elementData[13]=203; elementData[14]=1; elementData[15]='G';
  2465. //Fifth IE
  2466. elementData[16]=204; elementData[17]=3; elementData[18]='X'; elementData[19]=5; elementData[20]='Z';
  2467. } else if(2 == state) { //Delete All IEs
  2468. state = 0;
  2469. //Total Number of Bytes
  2470. elementData[0]=0;
  2471. }
  2472. m2m_wifi_set_cust_InfoElement(elementData);
  2473. * @endcode
  2474. */
  2475. NMI_API sint8 m2m_wifi_set_cust_InfoElement(uint8 *pau8M2mCustInfoElement);
  2476. /**@}*/
  2477. /** @defgroup WifiSetPowerProfile m2m_wifi_set_power_profile
  2478. * @ingroup WLANAPI
  2479. * Change the power profile mode
  2480. */
  2481. /**@{*/
  2482. /*!
  2483. @fn NMI_API sint8 m2m_wifi_set_power_profile(uint8 u8PwrMode);
  2484. @brief
  2485. @param [in] u8PwrMode
  2486. Change the WINC1500 power profile to different mode based on the enumeration
  2487. @ref tenuM2mPwrMode
  2488. @pre Must be called after the initializations and before any connection request and can't be changed in run time.
  2489. @sa tenuM2mPwrMode
  2490. m2m_wifi_init
  2491. @return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  2492. */
  2493. sint8 m2m_wifi_set_power_profile(uint8 u8PwrMode);
  2494. /**@}*/
  2495. /** @defgroup WifiSetTxPower m2m_wifi_set_tx_power
  2496. * @ingroup WLANAPI
  2497. * Set the TX power tenuM2mTxPwrLevel
  2498. */
  2499. /**@{*/
  2500. /*!
  2501. @fn NMI_API sint8 m2m_wifi_set_tx_power(uint8 u8TxPwrLevel);
  2502. @param [in] u8TxPwrLevel
  2503. change the TX power based on the enumeration tenuM2mTxPwrLevel
  2504. @pre Must be called after the initialization and before any connection request and can't be changed in runtime.
  2505. @sa tenuM2mTxPwrLevel
  2506. m2m_wifi_init
  2507. @return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  2508. */
  2509. sint8 m2m_wifi_set_tx_power(uint8 u8TxPwrLevel);
  2510. /**@}*/
  2511. /** @defgroup WifiEnableFirmware m2m_wifi_enable_firmware_logs
  2512. * @ingroup WLANAPI
  2513. * Enable or Disable logs in run time (Disabling Firmware logs will
  2514. * enhance the firmware start-up time and performance)
  2515. */
  2516. /**@{*/
  2517. /*!
  2518. @fn NMI_API sint8 m2m_wifi_enable_firmware_logs(uint8 u8Enable);
  2519. @param [in] u8Enable
  2520. Set 1 to enable the logs, 0 for disable
  2521. @pre Must be called after intialization through the following function @ref m2m_wifi_init
  2522. @sa __DISABLE_FIRMWARE_LOGS__ (build option to disable logs from initializations)
  2523. m2m_wifi_init
  2524. @return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  2525. */
  2526. sint8 m2m_wifi_enable_firmware_logs(uint8 u8Enable);
  2527. /**@}*/
  2528. /** @defgroup WifiSetBatteryVoltage m2m_wifi_set_battery_voltage
  2529. * @ingroup WLANAPI
  2530. * Set the battery voltage to update the firmware calculations
  2531. */
  2532. /**@{*/
  2533. /*!
  2534. @fn NMI_API sint8 m2m_wifi_set_battery_voltage(uint8 u8BattVolt)
  2535. @brief Set the battery voltage to update the firmware calculations
  2536. @param [in] dbBattVolt
  2537. Battery Volt in double
  2538. @pre Must be called after intialization through the following function @ref m2m_wifi_init
  2539. @sa m2m_wifi_init
  2540. @return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  2541. */
  2542. sint8 m2m_wifi_set_battery_voltage(uint16 u16BattVoltx100);
  2543. /**@}*/
  2544. /** @defgroup WifiSetGains m2m_wifi_set_gains
  2545. * @ingroup WLANAPI
  2546. * Set the chip gains mainly (PPA for 11b/11gn)
  2547. */
  2548. /**@{*/
  2549. /*!
  2550. @fn sint8 m2m_wifi_set_gains(tstrM2mWifiGainsParams* pstrM2mGain);
  2551. @brief Set the chip PPA gain for 11b/11gn
  2552. @param [in] pstrM2mGain
  2553. tstrM2mWifiGainsParams contain gain parmaters as implemnted in rf document
  2554. @pre Must be called after intialization through the following function @ref m2m_wifi_init
  2555. @sa m2m_wifi_init
  2556. @return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  2557. */
  2558. sint8 m2m_wifi_set_gains(tstrM2mWifiGainsParams *pstrM2mGain);
  2559. /**@}*/
  2560. /** @defgroup WifiGetFirmwareVersion m2m_wifi_get_firmware_version
  2561. * @ingroup WLANAPI
  2562. * Get Firmware version info as defined in the structure @ref tstrM2mRev.
  2563. */
  2564. /**@{*/
  2565. /*!
  2566. @fn m2m_wifi_get_firmware_version(tstrM2mRev* pstrRev)
  2567. @param [out] M2mRev
  2568. Pointer to the structure @ref tstrM2mRev that contains the firmware version parameters
  2569. @pre Must be called after intialization through the following function @ref m2m_wifi_init
  2570. @sa m2m_wifi_init
  2571. @return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  2572. */
  2573. sint8 m2m_wifi_get_firmware_version(tstrM2mRev *pstrRev);
  2574. /**@}*/
  2575. #ifdef ETH_MODE
  2576. /** @defgroup WifiEnableMacMcastFn m2m_wifi_enable_mac_mcast
  2577. * @ingroup WLANAPI
  2578. * Synchronous function for filtering received MAC addresses from certain MAC address groups.
  2579. * This function allows the addtion/removal of certain MAC addresses, used in the multicast filter.
  2580. */
  2581. /**@{*/
  2582. /*!
  2583. * @fn NMI_API sint8 m2m_wifi_enable_mac_mcast(uint8 *, uint8);
  2584. * @brief
  2585. * @param [in] pu8MulticastMacAddress
  2586. * Pointer to MAC address
  2587. * @param [in] u8AddRemove
  2588. * A flag to add or remove the MAC ADDRESS, based on the following values:
  2589. * - 0 : remove MAC address
  2590. * - 1 : add MAC address
  2591. * @warning This function is available in ETHERNET/bypass mode ONLY. Make sure that the application defines @ref
  2592. * ETH_MODE.\n
  2593. * @note Maximum number of MAC addresses that could be added is 8.
  2594. * @sa m2m_wifi_set_receive_buffer, m2m_wifi_send_ethernet_pkt
  2595. * @return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  2596. */
  2597. NMI_API sint8 m2m_wifi_enable_mac_mcast(uint8 *pu8MulticastMacAddress, uint8 u8AddRemove);
  2598. /**@}*/
  2599. /** @defgroup SetReceiveBufferFn m2m_wifi_set_receive_buffer
  2600. * @ingroup WLANAPI
  2601. * Synchronous function for setting or modifying the receiver buffer's length.
  2602. * In the ETHERNET/bypass mode the application should define a callback of type @ref tpfAppEthCb, through which the
  2603. *application handles the received ethernet frames. It is through this callback function that the user can dynamically
  2604. *modify the length of the currently used receiver buffer.
  2605. *@{*/
  2606. /*!
  2607. * @fn NMI_API sint8 m2m_wifi_set_receive_buffer(void *, uint16);
  2608. * @param [in] pvBuffer
  2609. * Pointer to Buffer to receive data.
  2610. * NULL pointer causes a negative error @ref M2M_ERR_FAIL.
  2611. *
  2612. * @param [in] u16BufferLen
  2613. * Length of data to be received. Maximum length of data should not exceed the size defined by TCP/IP
  2614. * defined as @ref SOCKET_BUFFER_MAX_LENGTH
  2615. *
  2616. * @warning This function is available in the Ethernet/bypass mode ONLY. Make sure that the application defines
  2617. @ref ETH_MODE.\n
  2618. * @sa m2m_wifi_enable_mac_mcast,m2m_wifi_send_ethernet_pkt
  2619. * @return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  2620. */
  2621. NMI_API sint8 m2m_wifi_set_receive_buffer(void *pvBuffer, uint16 u16BufferLen);
  2622. /**@}*/
  2623. #endif /* ETH_MODE */
  2624. /** @defgroup GetPrngBytes m2m_wifi_prng_get_random_bytes
  2625. * @ingroup WLANAPI
  2626. * Asynchronous function for retrieving from the firmware a pseudo-random set of bytes as specifed in the size passed
  2627. *in as a parameter. The registered wifi-cb function retrieves the random bytes through the response @ref
  2628. *M2M_WIFI_RESP_GET_PRNG
  2629. *@{*/
  2630. /*!
  2631. * @fn sint8 m2m_wifi_prng_get_random_bytes(uint8 * pu8PRNGBuff,uint16 u16PRNGSize)
  2632. * @param [out] pu8PrngBuff
  2633. * Pointer to a buffer to receive data.
  2634. * @param [in] u16PrngSize
  2635. * Request size in bytes
  2636. *@warning Size greater than the maximum specified (@ref M2M_BUFFER_MAX_SIZE - sizeof(tstrPrng))
  2637. * causes a negative error @ref M2M_ERR_FAIL.
  2638. *@see tstrPrng
  2639. * @return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
  2640. */
  2641. sint8 m2m_wifi_prng_get_random_bytes(uint8 *pu8PrngBuff, uint16 u16PrngSize);
  2642. /**@}*/
  2643. /** @defgroup WifiConfAutRate m2m_wifi_conf_auto_rate
  2644. * @ingroup WLANAPI
  2645. * Configures WLAN automatic TX rate adaptation algorithm.
  2646. */
  2647. /**@{*/
  2648. /*!
  2649. @fn \
  2650. NMI_API sint8 m2m_wifi_conf_auto_rate(tstrConfAutoRate * pstrConfAutoRate)
  2651. @brief
  2652. Allow the host MCU app to configure auto TX rate selection algorithm. The application can use this
  2653. API to tweak the algorithm performance. Moreover, it allows the application to force a specific WLAN
  2654. PHY rate for transmitted data packets to favor range vs. throughput needs.
  2655. @param [in] pstrConfAutoRate
  2656. The Auto rate configuration parameters as listed in tstrConfAutoRate.
  2657. @sa
  2658. tstrConfAutoRate
  2659. @return
  2660. The function SHALL return 0 for success and a negative value otherwise.
  2661. */
  2662. NMI_API sint8 m2m_wifi_conf_auto_rate(tstrConfAutoRate *pstrConfAutoRate);
  2663. /**@}*/
  2664. #ifdef __cplusplus
  2665. }
  2666. #endif
  2667. #endif /* __M2M_WIFI_H__ */