1 /**
2 *
3 * \file
4 *
5 * \brief This module contains M2M Wi-Fi APIs implementation.
6 *
7 * Copyright (c) 2016-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
42 #include "driver/include/m2m_wifi.h"
43 #include "driver/source/m2m_hif.h"
44 #include "driver/source/nmasic.h"
45
46 /**
47 * \defgroup winc1500_group WINC1500 (Wi-Fi)
48 *
49 * \{
50 */
51
52 static volatile uint8 gu8ChNum;
53 static volatile uint8 gu8scanInProgress = 0;
54 static tpfAppWifiCb gpfAppWifiCb = NULL;
55
56
57 #ifdef ETH_MODE
58 static tpfAppEthCb gpfAppEthCb = NULL;
59 static uint8* gau8ethRcvBuf=NULL;
60 static uint16 gu16ethRcvBufSize ;
61 #endif
62
63
64 //#define CONF_MGMT
65 #ifdef CONF_MGMT
66 static tpfAppMonCb gpfAppMonCb = NULL;
67 static struct _tstrMgmtCtrl
68 {
69 uint8* pu8Buf;
70 uint16 u16Offset;
71 uint16 u16Sz;
72 }
73 gstrMgmtCtrl = {NULL, 0 , 0};
74 #endif
75 /**
76 * @fn m2m_wifi_cb(uint8 u8OpCode, uint16 u16DataSize, uint32 u32Addr, uint8 grp)
77 * @brief WiFi call back function
78 * @param [in] u8OpCode
79 * HIF Opcode type.
80 * @param [in] u16DataSize
81 * HIF data length.
82 * @param [in] u32Addr
83 * HIF address.
84 * @param [in] grp
85 * HIF group type.
86 * @author
87 * @date
88 * @version 1.0
89 */
m2m_wifi_cb(uint8 u8OpCode,uint16 u16DataSize,uint32 u32Addr)90 static void m2m_wifi_cb(uint8 u8OpCode, uint16 u16DataSize, uint32 u32Addr)
91 {
92 uint8 rx_buf[8];
93 if (u8OpCode == M2M_WIFI_RESP_CON_STATE_CHANGED)
94 {
95 tstrM2mWifiStateChanged strState;
96 if (hif_receive(u32Addr, (uint8*) &strState,sizeof(tstrM2mWifiStateChanged), 0) == M2M_SUCCESS)
97 {
98 if (gpfAppWifiCb)
99 gpfAppWifiCb(M2M_WIFI_RESP_CON_STATE_CHANGED, &strState);
100 }
101 }
102 else if (u8OpCode == M2M_WIFI_RESP_GET_SYS_TIME)
103 {
104 tstrSystemTime strSysTime;
105 if (hif_receive(u32Addr, (uint8*) &strSysTime,sizeof(tstrSystemTime), 0) == M2M_SUCCESS)
106 {
107 if (gpfAppWifiCb)
108 gpfAppWifiCb(M2M_WIFI_RESP_GET_SYS_TIME, &strSysTime);
109 }
110 }
111 else if(u8OpCode == M2M_WIFI_RESP_CONN_INFO)
112 {
113 tstrM2MConnInfo strConnInfo;
114 if(hif_receive(u32Addr, (uint8*)&strConnInfo, sizeof(tstrM2MConnInfo), 1) == M2M_SUCCESS)
115 {
116 if(gpfAppWifiCb)
117 gpfAppWifiCb(M2M_WIFI_RESP_CONN_INFO, &strConnInfo);
118 }
119 }
120 else if (u8OpCode == M2M_WIFI_RESP_MEMORY_RECOVER)
121 {
122 #if 0
123 if (hif_receive(u32Addr, rx_buf, 4, 1) == M2M_SUCCESS)
124 {
125 tstrM2mWifiStateChanged strState;
126 m2m_memcpy((uint8*) &strState, rx_buf,sizeof(tstrM2mWifiStateChanged));
127 if (app_wifi_recover_cb)
128 app_wifi_recover_cb(strState.u8CurrState);
129 }
130 #endif
131 }
132 else if (u8OpCode == M2M_WIFI_REQ_DHCP_CONF)
133 {
134 tstrM2MIPConfig strIpConfig;
135 if (hif_receive(u32Addr, (uint8 *)&strIpConfig, sizeof(tstrM2MIPConfig), 0) == M2M_SUCCESS)
136 {
137 if (gpfAppWifiCb)
138 gpfAppWifiCb(M2M_WIFI_REQ_DHCP_CONF, (uint8 *)&strIpConfig);
139 }
140 }
141 else if (u8OpCode == M2M_WIFI_REQ_WPS)
142 {
143 tstrM2MWPSInfo strWps;
144 m2m_memset((uint8*)&strWps,0,sizeof(tstrM2MWPSInfo));
145 if(hif_receive(u32Addr, (uint8*)&strWps, sizeof(tstrM2MWPSInfo), 0) == M2M_SUCCESS)
146 {
147 if (gpfAppWifiCb)
148 gpfAppWifiCb(M2M_WIFI_REQ_WPS, &strWps);
149 }
150 }
151 else if (u8OpCode == M2M_WIFI_RESP_IP_CONFLICT)
152 {
153 uint32 u32ConflictedIP;
154 if(hif_receive(u32Addr, (uint8 *)&u32ConflictedIP, sizeof(u32ConflictedIP), 0) == M2M_SUCCESS)
155 {
156 M2M_INFO("Conflicted IP \" %u.%u.%u.%u \" \n",
157 BYTE_0(u32ConflictedIP),BYTE_1(u32ConflictedIP),BYTE_2(u32ConflictedIP),BYTE_3(u32ConflictedIP));
158 if (gpfAppWifiCb)
159 gpfAppWifiCb(M2M_WIFI_RESP_IP_CONFLICT, NULL);
160
161 }
162 }
163 else if (u8OpCode == M2M_WIFI_RESP_SCAN_DONE)
164 {
165 tstrM2mScanDone strState;
166 gu8scanInProgress = 0;
167 if(hif_receive(u32Addr, (uint8*)&strState, sizeof(tstrM2mScanDone), 0) == M2M_SUCCESS)
168 {
169 gu8ChNum = strState.u8NumofCh;
170 if (gpfAppWifiCb)
171 gpfAppWifiCb(M2M_WIFI_RESP_SCAN_DONE, &strState);
172 }
173 }
174 else if (u8OpCode == M2M_WIFI_RESP_SCAN_RESULT)
175 {
176 tstrM2mWifiscanResult strScanResult;
177 if(hif_receive(u32Addr, (uint8*)&strScanResult, sizeof(tstrM2mWifiscanResult), 0) == M2M_SUCCESS)
178 {
179 if (gpfAppWifiCb)
180 gpfAppWifiCb(M2M_WIFI_RESP_SCAN_RESULT, &strScanResult);
181 }
182 }
183 else if (u8OpCode == M2M_WIFI_RESP_CURRENT_RSSI)
184 {
185 if (hif_receive(u32Addr, rx_buf, 4, 0) == M2M_SUCCESS)
186 {
187 if (gpfAppWifiCb)
188 gpfAppWifiCb(M2M_WIFI_RESP_CURRENT_RSSI, rx_buf);
189 }
190 }
191 else if (u8OpCode == M2M_WIFI_RESP_CLIENT_INFO)
192 {
193 if (hif_receive(u32Addr, rx_buf, 4, 0) == M2M_SUCCESS)
194 {
195 if (gpfAppWifiCb)
196 gpfAppWifiCb(M2M_WIFI_RESP_CLIENT_INFO, rx_buf);
197 }
198 }
199 else if(u8OpCode == M2M_WIFI_RESP_PROVISION_INFO)
200 {
201 tstrM2MProvisionInfo strProvInfo;
202 if(hif_receive(u32Addr, (uint8*)&strProvInfo, sizeof(tstrM2MProvisionInfo), 1) == M2M_SUCCESS)
203 {
204 if(gpfAppWifiCb)
205 gpfAppWifiCb(M2M_WIFI_RESP_PROVISION_INFO, &strProvInfo);
206 }
207 }
208 else if(u8OpCode == M2M_WIFI_RESP_DEFAULT_CONNECT)
209 {
210 tstrM2MDefaultConnResp strResp;
211 if(hif_receive(u32Addr, (uint8*)&strResp, sizeof(tstrM2MDefaultConnResp), 1) == M2M_SUCCESS)
212 {
213 if(gpfAppWifiCb)
214 gpfAppWifiCb(M2M_WIFI_RESP_DEFAULT_CONNECT, &strResp);
215 }
216 }
217
218 else if(u8OpCode == M2M_WIFI_RESP_GET_PRNG)
219 {
220 tstrPrng strPrng;
221 if(hif_receive(u32Addr, (uint8*)&strPrng,sizeof(tstrPrng), 0) == M2M_SUCCESS)
222 {
223 if(hif_receive(u32Addr + sizeof(tstrPrng),strPrng.pu8RngBuff,strPrng.u16PrngSize, 1) == M2M_SUCCESS)
224 {
225 if(gpfAppWifiCb)
226 gpfAppWifiCb(M2M_WIFI_RESP_GET_PRNG,&strPrng);
227 }
228 }
229 }
230 #ifdef ETH_MODE
231 else if(u8OpCode == M2M_WIFI_RESP_ETHERNET_RX_PACKET)
232 {
233 uint8 u8SetRxDone;
234 tstrM2mIpRsvdPkt strM2mRsvd;
235 if(hif_receive(u32Addr, &strM2mRsvd ,sizeof(tstrM2mIpRsvdPkt), 0) == M2M_SUCCESS)
236 {
237 tstrM2mIpCtrlBuf strM2mIpCtrlBuf;
238 uint16 u16Offset = strM2mRsvd.u16PktOffset;
239 strM2mIpCtrlBuf.u16RemainigDataSize = strM2mRsvd.u16PktSz;
240 if((gpfAppEthCb) && (gau8ethRcvBuf) && (gu16ethRcvBufSize > 0))
241 {
242 do
243 {
244 u8SetRxDone = 1;
245 if(strM2mIpCtrlBuf.u16RemainigDataSize > gu16ethRcvBufSize)
246 {
247 u8SetRxDone = 0;
248 strM2mIpCtrlBuf.u16DataSize = gu16ethRcvBufSize;
249 }
250 else
251 {
252 strM2mIpCtrlBuf.u16DataSize = strM2mIpCtrlBuf.u16RemainigDataSize;
253 }
254
255 if(hif_receive(u32Addr + u16Offset, gau8ethRcvBuf, strM2mIpCtrlBuf.u16DataSize, u8SetRxDone) == M2M_SUCCESS)
256 {
257 strM2mIpCtrlBuf.u16RemainigDataSize -= strM2mIpCtrlBuf.u16DataSize;
258 u16Offset += strM2mIpCtrlBuf.u16DataSize;
259 gpfAppEthCb(M2M_WIFI_RESP_ETHERNET_RX_PACKET, gau8ethRcvBuf, &(strM2mIpCtrlBuf));
260 }
261 else
262 {
263 break;
264 }
265 }while (strM2mIpCtrlBuf.u16RemainigDataSize > 0);
266 }
267 }
268 }
269 #endif /* ETH_MODE */
270 #ifdef CONF_MGMT
271 else if(u8OpCode == M2M_WIFI_RESP_WIFI_RX_PACKET)
272 {
273
274 tstrM2MWifiRxPacketInfo strRxPacketInfo;
275 if(u16DataSize >= sizeof(tstrM2MWifiRxPacketInfo)) {
276 if(hif_receive(u32Addr, (uint8*)&strRxPacketInfo, sizeof(tstrM2MWifiRxPacketInfo), 0) == M2M_SUCCESS)
277 {
278 u16DataSize -= sizeof(tstrM2MWifiRxPacketInfo);
279 if(u16DataSize > 0 && gstrMgmtCtrl.pu8Buf != NULL)
280 {
281 if(u16DataSize > (gstrMgmtCtrl.u16Sz + gstrMgmtCtrl.u16Offset))
282 {
283 u16DataSize = gstrMgmtCtrl.u16Sz;
284 }
285 u32Addr += sizeof(tstrM2MWifiRxPacketInfo) + gstrMgmtCtrl.u16Offset;
286 if(hif_receive(u32Addr , gstrMgmtCtrl.pu8Buf, u16DataSize, 1) != M2M_SUCCESS) return;
287 }
288 if(gpfAppMonCb)
289 gpfAppMonCb(&strRxPacketInfo, gstrMgmtCtrl.pu8Buf,u16DataSize);
290 }
291 } else {
292 M2M_ERR("Incorrect mon data size %u\n", u16DataSize);
293 }
294 }
295 #endif
296 else
297 {
298 M2M_ERR("REQ Not defined %d\n",u8OpCode);
299 }
300 }
301
m2m_wifi_download_mode()302 sint8 m2m_wifi_download_mode()
303 {
304 sint8 ret = M2M_SUCCESS;
305 /* Apply device specific initialization. */
306 ret = nm_drv_init_download_mode();
307 if(ret != M2M_SUCCESS) goto _EXIT0;
308
309
310
311 enable_interrupts();
312
313 _EXIT0:
314 return ret;
315 }
316
m2m_validate_ap_parameters(CONST tstrM2MAPConfig * pstrM2MAPConfig)317 static sint8 m2m_validate_ap_parameters(CONST tstrM2MAPConfig* pstrM2MAPConfig)
318 {
319 sint8 s8Ret = M2M_SUCCESS;
320 /* Check for incoming pointer */
321 if(pstrM2MAPConfig == NULL)
322 {
323 M2M_ERR("INVALID POINTER\n");
324 s8Ret = M2M_ERR_FAIL;
325 goto ERR1;
326 }
327 /* Check for SSID */
328 if((m2m_strlen((uint8 *)pstrM2MAPConfig->au8SSID) <= 0) || (m2m_strlen((uint8 *)pstrM2MAPConfig->au8SSID) >= M2M_MAX_SSID_LEN))
329 {
330 M2M_ERR("INVALID SSID\n");
331 s8Ret = M2M_ERR_FAIL;
332 goto ERR1;
333 }
334 /* Check for Channel */
335 if(pstrM2MAPConfig->u8ListenChannel > M2M_WIFI_CH_14 || pstrM2MAPConfig->u8ListenChannel < M2M_WIFI_CH_1)
336 {
337 M2M_ERR("INVALID CH\n");
338 s8Ret = M2M_ERR_FAIL;
339 goto ERR1;
340 }
341 /* Check for DHCP Server IP address */
342 if(!(pstrM2MAPConfig->au8DHCPServerIP[0] || pstrM2MAPConfig->au8DHCPServerIP[1]))
343 {
344 if(!(pstrM2MAPConfig->au8DHCPServerIP[2]))
345 {
346 M2M_ERR("INVALID DHCP SERVER IP\n");
347 s8Ret = M2M_ERR_FAIL;
348 goto ERR1;
349 }
350 }
351 /* Check for Security */
352 if(pstrM2MAPConfig->u8SecType == M2M_WIFI_SEC_OPEN)
353 {
354 goto ERR1;
355 }
356 else if(pstrM2MAPConfig->u8SecType == M2M_WIFI_SEC_WEP)
357 {
358 /* Check for WEP Key index */
359 if((pstrM2MAPConfig->u8KeyIndx <= 0) || (pstrM2MAPConfig->u8KeyIndx > WEP_KEY_MAX_INDEX))
360 {
361 M2M_ERR("INVALID KEY INDEX\n");
362 s8Ret = M2M_ERR_FAIL;
363 goto ERR1;
364 }
365 /* Check for WEP Key size */
366 if( (pstrM2MAPConfig->u8KeySz != WEP_40_KEY_STRING_SIZE) &&
367 (pstrM2MAPConfig->u8KeySz != WEP_104_KEY_STRING_SIZE)
368 )
369 {
370 M2M_ERR("INVALID KEY STRING SIZE\n");
371 s8Ret = M2M_ERR_FAIL;
372 goto ERR1;
373 }
374
375 if((m2m_strlen((uint8 *)pstrM2MAPConfig->au8WepKey) <= 0) || (m2m_strlen((uint8 *)pstrM2MAPConfig->au8WepKey) > WEP_104_KEY_STRING_SIZE))
376 {
377 M2M_ERR("INVALID KEY SIZE\n");
378 s8Ret = M2M_ERR_FAIL;
379 goto ERR1;
380 }
381 }
382 else if(pstrM2MAPConfig->u8SecType == M2M_WIFI_SEC_WPA_PSK)
383 {
384 /* Check for WPA Key size */
385 if( ((pstrM2MAPConfig->u8KeySz + 1) < M2M_MIN_PSK_LEN) || ((pstrM2MAPConfig->u8KeySz + 1) > M2M_MAX_PSK_LEN))
386 {
387 M2M_ERR("INVALID WPA KEY SIZE\n");
388 s8Ret = M2M_ERR_FAIL;
389 goto ERR1;
390 }
391 }
392 else
393 {
394 M2M_ERR("INVALID AUTHENTICATION MODE\n");
395 s8Ret = M2M_ERR_FAIL;
396 goto ERR1;
397 }
398
399 ERR1:
400 return s8Ret;
401 }
m2m_validate_scan_options(tstrM2MScanOption * ptstrM2MScanOption)402 static sint8 m2m_validate_scan_options(tstrM2MScanOption* ptstrM2MScanOption)
403 {
404 sint8 s8Ret = M2M_SUCCESS;
405 /* Check for incoming pointer */
406 if(ptstrM2MScanOption == NULL)
407 {
408 M2M_ERR("INVALID POINTER\n");
409 s8Ret = M2M_ERR_FAIL;
410 goto ERR;
411 }
412 /* Check for valid No of slots */
413 if(ptstrM2MScanOption->u8NumOfSlot == 0)
414 {
415 M2M_ERR("INVALID No of scan slots! %d\n",ptstrM2MScanOption->u8NumOfSlot);
416 s8Ret = M2M_ERR_FAIL;
417 goto ERR;
418 }
419 /* Check for valid time of slots */
420 if(ptstrM2MScanOption->u8SlotTime < 10 || ptstrM2MScanOption->u8SlotTime > 250)
421 {
422 M2M_ERR("INVALID scan slot time! %d\n",ptstrM2MScanOption->u8SlotTime);
423 s8Ret = M2M_ERR_FAIL;
424 goto ERR;
425 }
426 /* Check for valid No of probe requests per slot */
427 if((ptstrM2MScanOption->u8ProbesPerSlot == 0)||(ptstrM2MScanOption->u8ProbesPerSlot > M2M_SCAN_DEFAULT_NUM_PROBE))
428 {
429 M2M_ERR("INVALID No of probe requests per scan slot %d\n",ptstrM2MScanOption->u8ProbesPerSlot);
430 s8Ret = M2M_ERR_FAIL;
431 goto ERR;
432 }
433 /* Check for valid RSSI threshold */
434 if((ptstrM2MScanOption->s8RssiThresh < -99) || (ptstrM2MScanOption->s8RssiThresh >= 0))
435 {
436 M2M_ERR("INVALID RSSI threshold %d \n",ptstrM2MScanOption->s8RssiThresh);
437 s8Ret = M2M_ERR_FAIL;
438 }
439
440 ERR:
441 return s8Ret;
442 }
443
m2m_wifi_send_crl(tstrTlsCrlInfo * pCRL)444 sint8 m2m_wifi_send_crl(tstrTlsCrlInfo* pCRL)
445 {
446 sint8 s8Ret = M2M_ERR_FAIL;
447 s8Ret = hif_send(M2M_REQ_GROUP_SSL, M2M_SSL_IND_CRL|M2M_REQ_DATA_PKT, NULL, 0, (uint8*)pCRL, sizeof(tstrTlsCrlInfo), 0);
448 return s8Ret;
449 }
450
m2m_wifi_init(tstrWifiInitParam * param)451 sint8 m2m_wifi_init(tstrWifiInitParam * param)
452 {
453 tstrM2mRev strtmp;
454 sint8 ret = M2M_SUCCESS;
455 uint8 u8WifiMode = M2M_WIFI_MODE_NORMAL;
456
457 if(param == NULL) {
458 ret = M2M_ERR_FAIL;
459 goto _EXIT0;
460 }
461
462 gpfAppWifiCb = param->pfAppWifiCb;
463
464 #ifdef ETH_MODE
465 gpfAppEthCb = param->strEthInitParam.pfAppEthCb;
466 gau8ethRcvBuf = param->strEthInitParam.au8ethRcvBuf;
467 gu16ethRcvBufSize = param->strEthInitParam.u16ethRcvBufSize;
468 u8WifiMode = param->strEthInitParam.u8EthernetEnable;
469 #endif /* ETH_MODE */
470
471 #ifdef CONF_MGMT
472 gpfAppMonCb = param->pfAppMonCb;
473 #endif
474 gu8scanInProgress = 0;
475 /* Apply device specific initialization. */
476 ret = nm_drv_init(&u8WifiMode);
477 if(ret != M2M_SUCCESS) goto _EXIT0;
478 /* Initialize host interface module */
479 ret = hif_init(NULL);
480 if(ret != M2M_SUCCESS) goto _EXIT1;
481
482 hif_register_cb(M2M_REQ_GROUP_WIFI,m2m_wifi_cb);
483
484 ret = nm_get_firmware_full_info(&strtmp);
485
486 M2M_INFO("Firmware ver : %u.%u.%u Svnrev %u\n", strtmp.u8FirmwareMajor, strtmp.u8FirmwareMinor, strtmp.u8FirmwarePatch,strtmp.u16FirmwareSvnNum);
487 M2M_INFO("Firmware Build %s Time %s\n",strtmp.BuildDate,strtmp.BuildTime);
488 M2M_INFO("Firmware Min driver ver : %u.%u.%u\n", strtmp.u8DriverMajor, strtmp.u8DriverMinor, strtmp.u8DriverPatch);
489 M2M_INFO("Driver ver: %u.%u.%u\n", M2M_RELEASE_VERSION_MAJOR_NO, M2M_RELEASE_VERSION_MINOR_NO, M2M_RELEASE_VERSION_PATCH_NO);
490 M2M_INFO("Driver built at %s\t%s\n",__DATE__,__TIME__);
491 if(M2M_ERR_FW_VER_MISMATCH == ret)
492 {
493 M2M_ERR("Mismatch Firmawre Version\n");
494 }
495
496 goto _EXIT0;
497
498 _EXIT1:
499 nm_drv_deinit(NULL);
500 _EXIT0:
501 return ret;
502 }
503
m2m_wifi_deinit(void * arg)504 sint8 m2m_wifi_deinit(void * arg)
505 {
506
507 hif_deinit(NULL);
508
509 nm_drv_deinit(NULL);
510
511 return M2M_SUCCESS;
512 }
513
514
m2m_wifi_handle_events(void * arg)515 sint8 m2m_wifi_handle_events(void * arg)
516 {
517 return hif_handle_isr();
518 }
519
m2m_wifi_default_connect(void)520 sint8 m2m_wifi_default_connect(void)
521 {
522 return hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_DEFAULT_CONNECT, NULL, 0,NULL, 0,0);
523 }
524
m2m_wifi_connect(char * pcSsid,uint8 u8SsidLen,uint8 u8SecType,void * pvAuthInfo,uint16 u16Ch)525 sint8 m2m_wifi_connect(char *pcSsid, uint8 u8SsidLen, uint8 u8SecType, void *pvAuthInfo, uint16 u16Ch)
526 {
527 return m2m_wifi_connect_sc(pcSsid, u8SsidLen, u8SecType, pvAuthInfo, u16Ch,0);
528 }
m2m_wifi_connect_sc(char * pcSsid,uint8 u8SsidLen,uint8 u8SecType,void * pvAuthInfo,uint16 u16Ch,uint8 u8NoSaveCred)529 sint8 m2m_wifi_connect_sc(char *pcSsid, uint8 u8SsidLen, uint8 u8SecType, void *pvAuthInfo, uint16 u16Ch, uint8 u8NoSaveCred)
530 {
531 sint8 ret = M2M_SUCCESS;
532 tstrM2mWifiConnect strConnect;
533 tstrM2MWifiSecInfo *pstrAuthInfo;
534
535 if(u8SecType != M2M_WIFI_SEC_OPEN)
536 {
537 if(pvAuthInfo == NULL)
538 {
539 M2M_ERR("Key is not valid\n");
540 ret = M2M_ERR_FAIL;
541 goto ERR1;
542 }
543 if((u8SecType == M2M_WIFI_SEC_WPA_PSK) && (m2m_strlen(pvAuthInfo) == (M2M_MAX_PSK_LEN-1)))
544 {
545 uint8 i = 0;
546 uint8* pu8Psk = (uint8*)pvAuthInfo;
547 while(i < (M2M_MAX_PSK_LEN-1))
548 {
549 if(pu8Psk[i]<'0' || (pu8Psk[i]>'9' && pu8Psk[i] < 'A')|| (pu8Psk[i]>'F' && pu8Psk[i] < 'a') || pu8Psk[i] > 'f')
550 {
551 M2M_ERR("Invalid Key\n");
552 ret = M2M_ERR_FAIL;
553 goto ERR1;
554 }
555 i++;
556 }
557 }
558 }
559 if((u8SsidLen<=0)||(u8SsidLen>=M2M_MAX_SSID_LEN))
560 {
561 M2M_ERR("SSID LEN INVALID\n");
562 ret = M2M_ERR_FAIL;
563 goto ERR1;
564 }
565
566 if(u16Ch < M2M_WIFI_CH_1|| u16Ch > M2M_WIFI_CH_14)
567 {
568 if(u16Ch!=M2M_WIFI_CH_ALL)
569 {
570 M2M_ERR("CH INVALID\n");
571 ret = M2M_ERR_FAIL;
572 goto ERR1;
573 }
574 }
575
576
577 m2m_memcpy(strConnect.au8SSID, (uint8*)pcSsid, u8SsidLen);
578 strConnect.au8SSID[u8SsidLen] = 0;
579 strConnect.u16Ch = NM_BSP_B_L_16(u16Ch);
580 /* Credentials will be Not be saved if u8NoSaveCred is set */
581 strConnect.u8NoSaveCred = u8NoSaveCred ? 1:0;
582 pstrAuthInfo = &strConnect.strSec;
583 pstrAuthInfo->u8SecType = u8SecType;
584
585 if(u8SecType == M2M_WIFI_SEC_WEP)
586 {
587 tstrM2mWifiWepParams * pstrWepParams = (tstrM2mWifiWepParams*)pvAuthInfo;
588 tstrM2mWifiWepParams *pstrWep = &pstrAuthInfo->uniAuth.strWepInfo;
589 pstrWep->u8KeyIndx =pstrWepParams->u8KeyIndx-1;
590
591 if(pstrWep->u8KeyIndx >= WEP_KEY_MAX_INDEX)
592 {
593 M2M_ERR("Invalid Wep key index %d\n", pstrWep->u8KeyIndx);
594 ret = M2M_ERR_FAIL;
595 goto ERR1;
596 }
597 pstrWep->u8KeySz = pstrWepParams->u8KeySz-1;
598 if ((pstrWep->u8KeySz != WEP_40_KEY_STRING_SIZE)&& (pstrWep->u8KeySz != WEP_104_KEY_STRING_SIZE))
599 {
600 M2M_ERR("Invalid Wep key length %d\n", pstrWep->u8KeySz);
601 ret = M2M_ERR_FAIL;
602 goto ERR1;
603 }
604 m2m_memcpy((uint8*)pstrWep->au8WepKey,(uint8*)pstrWepParams->au8WepKey, pstrWepParams->u8KeySz);
605 pstrWep->au8WepKey[pstrWepParams->u8KeySz] = 0;
606
607 }
608
609
610 else if(u8SecType == M2M_WIFI_SEC_WPA_PSK)
611 {
612 uint16 u16KeyLen = m2m_strlen((uint8*)pvAuthInfo);
613 if((u16KeyLen <= 0)||(u16KeyLen >= M2M_MAX_PSK_LEN))
614 {
615 M2M_ERR("Incorrect PSK key length\n");
616 ret = M2M_ERR_FAIL;
617 goto ERR1;
618 }
619 m2m_memcpy(pstrAuthInfo->uniAuth.au8PSK, (uint8*)pvAuthInfo, u16KeyLen + 1);
620 }
621 else if(u8SecType == M2M_WIFI_SEC_802_1X)
622 {
623 m2m_memcpy((uint8*)&pstrAuthInfo->uniAuth.strCred1x, (uint8*)pvAuthInfo, sizeof(tstr1xAuthCredentials));
624 }
625 else if(u8SecType == M2M_WIFI_SEC_OPEN)
626 {
627
628 }
629 else
630 {
631 M2M_ERR("undefined sec type\n");
632 ret = M2M_ERR_FAIL;
633 goto ERR1;
634 }
635
636 ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_CONNECT, (uint8*)&strConnect, sizeof(tstrM2mWifiConnect),NULL, 0,0);
637
638 ERR1:
639 return ret;
640 }
641
m2m_wifi_disconnect(void)642 sint8 m2m_wifi_disconnect(void)
643 {
644 return hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_DISCONNECT, NULL, 0, NULL, 0,0);
645 }
m2m_wifi_set_mac_address(uint8 au8MacAddress[6])646 sint8 m2m_wifi_set_mac_address(uint8 au8MacAddress[6])
647 {
648 tstrM2mSetMacAddress strTmp;
649 m2m_memcpy((uint8*) strTmp.au8Mac, (uint8*) au8MacAddress, 6);
650 return hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_SET_MAC_ADDRESS,
651 (uint8*) &strTmp, sizeof(tstrM2mSetMacAddress), NULL, 0,0);
652 }
653
m2m_wifi_set_static_ip(tstrM2MIPConfig * pstrStaticIPConf)654 sint8 m2m_wifi_set_static_ip(tstrM2MIPConfig * pstrStaticIPConf)
655 {
656 pstrStaticIPConf->u32DNS = NM_BSP_B_L_32(pstrStaticIPConf->u32DNS);
657 pstrStaticIPConf->u32Gateway = NM_BSP_B_L_32(pstrStaticIPConf->u32Gateway);
658 pstrStaticIPConf->u32StaticIP = NM_BSP_B_L_32(
659 pstrStaticIPConf->u32StaticIP);
660 pstrStaticIPConf->u32SubnetMask = NM_BSP_B_L_32(
661 pstrStaticIPConf->u32SubnetMask);
662 return hif_send(M2M_REQ_GROUP_IP, M2M_IP_REQ_STATIC_IP_CONF,
663 (uint8*) pstrStaticIPConf, sizeof(tstrM2MIPConfig), NULL, 0,0);
664 }
665
m2m_wifi_request_dhcp_client(void)666 sint8 m2m_wifi_request_dhcp_client(void)
667 {
668 /*legacy API should be removed */
669 return 0;
670 }
m2m_wifi_request_dhcp_server(uint8 * addr)671 sint8 m2m_wifi_request_dhcp_server(uint8* addr)
672 {
673 /*legacy API should be removed */
674 return 0;
675 }
676 /*!
677 @fn NMI_API sint8 m2m_wifi_set_lsn_int(tstrM2mLsnInt * pstrM2mLsnInt);
678 @brief Set the Wi-Fi listen interval for power save operation. It is represented in units
679 of AP Beacon periods.
680 @param [in] pstrM2mLsnInt
681 Structure holding the listen interval configurations.
682 @return The function SHALL return 0 for success and a negative value otherwise.
683 @sa tstrM2mLsnInt , m2m_wifi_set_sleep_mode
684 @pre m2m_wifi_set_sleep_mode shall be called first
685 @warning The Function called once after initialization.
686 */
m2m_wifi_enable_dhcp(uint8 u8DhcpEn)687 sint8 m2m_wifi_enable_dhcp(uint8 u8DhcpEn )
688 {
689
690 uint8 u8Req;
691 u8Req = u8DhcpEn ? M2M_IP_REQ_ENABLE_DHCP : M2M_IP_REQ_DISABLE_DHCP;
692 return hif_send(M2M_REQ_GROUP_IP, u8Req, NULL, 0, NULL, 0, 0);
693
694
695 }
696
m2m_wifi_set_lsn_int(tstrM2mLsnInt * pstrM2mLsnInt)697 sint8 m2m_wifi_set_lsn_int(tstrM2mLsnInt* pstrM2mLsnInt)
698 {
699 return hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_LSN_INT, (uint8*)pstrM2mLsnInt, sizeof(tstrM2mLsnInt), NULL, 0, 0);
700 }
701
m2m_wifi_set_cust_InfoElement(uint8 * pau8M2mCustInfoElement)702 sint8 m2m_wifi_set_cust_InfoElement(uint8* pau8M2mCustInfoElement)
703 {
704
705 sint8 ret = M2M_ERR_FAIL;
706 if(pau8M2mCustInfoElement != NULL)
707 {
708 if((pau8M2mCustInfoElement[0] + 1) < M2M_CUST_IE_LEN_MAX)
709 {
710 ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_CUST_INFO_ELEMENT|M2M_REQ_DATA_PKT, (uint8*)pau8M2mCustInfoElement, pau8M2mCustInfoElement[0]+1, NULL, 0, 0);
711 }
712 }
713 return ret;
714 }
715
m2m_wifi_set_scan_options(tstrM2MScanOption * ptstrM2MScanOption)716 sint8 m2m_wifi_set_scan_options(tstrM2MScanOption* ptstrM2MScanOption)
717 {
718 sint8 s8Ret = M2M_ERR_FAIL;
719 if(m2m_validate_scan_options (ptstrM2MScanOption) == M2M_SUCCESS)
720 {
721 s8Ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_SET_SCAN_OPTION, (uint8*)ptstrM2MScanOption, sizeof(tstrM2MScanOption),NULL, 0,0);
722 }
723 return s8Ret;
724 }
m2m_wifi_set_scan_region(uint16 ScanRegion)725 sint8 m2m_wifi_set_scan_region(uint16 ScanRegion)
726 {
727 sint8 s8Ret = M2M_ERR_FAIL;
728 tstrM2MScanRegion strScanRegion;
729 strScanRegion.u16ScanRegion = ScanRegion;
730 s8Ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_SET_SCAN_REGION, (uint8*)&strScanRegion, sizeof(tstrM2MScanRegion),NULL, 0,0);
731 return s8Ret;
732 }
m2m_wifi_request_scan(uint8 ch)733 sint8 m2m_wifi_request_scan(uint8 ch)
734 {
735 sint8 s8Ret = M2M_SUCCESS;
736
737 if(!gu8scanInProgress)
738 {
739 if(((ch >= M2M_WIFI_CH_1) && (ch <= M2M_WIFI_CH_14)) || (ch == M2M_WIFI_CH_ALL))
740 {
741 tstrM2MScan strtmp;
742 strtmp.u8ChNum = ch;
743 s8Ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_SCAN, (uint8*)&strtmp, sizeof(tstrM2MScan),NULL, 0,0);
744 if(s8Ret == M2M_SUCCESS)
745 {
746 gu8scanInProgress = 1;
747 }
748 }
749 else
750 {
751 s8Ret = M2M_ERR_INVALID_ARG;
752 }
753 }
754 else
755 {
756 s8Ret = M2M_ERR_SCAN_IN_PROGRESS;
757 }
758 return s8Ret;
759 }
760
m2m_wifi_request_scan_passive(uint8 ch,uint16 scan_time)761 sint8 m2m_wifi_request_scan_passive(uint8 ch, uint16 scan_time)
762 {
763 sint8 s8Ret = M2M_SUCCESS;
764
765 if(!gu8scanInProgress)
766 {
767 if(((ch >= M2M_WIFI_CH_1) && (ch <= M2M_WIFI_CH_14)) || (ch == M2M_WIFI_CH_ALL))
768 {
769 tstrM2MScan strtmp;
770 strtmp.u8ChNum = ch;
771
772 strtmp.u16PassiveScanTime = scan_time;
773
774 s8Ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_PASSIVE_SCAN, (uint8*)&strtmp, sizeof(tstrM2MScan),NULL, 0,0);
775 if(s8Ret == M2M_SUCCESS)
776 {
777 gu8scanInProgress = 1;
778 }
779 }
780 else
781 {
782 s8Ret = M2M_ERR_INVALID_ARG;
783 }
784 }
785 else
786 {
787 s8Ret = M2M_ERR_SCAN_IN_PROGRESS;
788 }
789 return s8Ret;
790 }
791
m2m_wifi_request_scan_ssid_list(uint8 ch,uint8 * u8Ssidlist)792 sint8 m2m_wifi_request_scan_ssid_list(uint8 ch,uint8 * u8Ssidlist)
793 {
794 sint8 s8Ret = M2M_ERR_INVALID_ARG;
795
796 if(!gu8scanInProgress)
797 {
798 if((((ch >= M2M_WIFI_CH_1) && (ch <= M2M_WIFI_CH_14)) || (ch == M2M_WIFI_CH_ALL))&&(u8Ssidlist != NULL))
799 {
800 tstrM2MScan strtmp;
801 uint16 u16Lsize = 0;
802 uint8 u8Apnum = u8Ssidlist[u16Lsize];
803 if(u8Apnum <= MAX_HIDDEN_SITES)
804 {
805 u16Lsize++;
806 while(u8Apnum)
807 {
808 if(u8Ssidlist[u16Lsize] >= M2M_MAX_SSID_LEN){
809 goto EXIT;
810 }else {
811 u16Lsize += u8Ssidlist[u16Lsize] + 1;
812 u8Apnum--;
813 }
814 }
815 strtmp.u8ChNum = ch;
816 s8Ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_SCAN_SSID_LIST|M2M_REQ_DATA_PKT, (uint8*)&strtmp, sizeof(tstrM2MScan),u8Ssidlist, u16Lsize,sizeof(tstrM2MScan));
817 if(s8Ret == M2M_SUCCESS)
818 {
819 gu8scanInProgress = 1;
820 }
821 }
822 }
823 }
824 else
825 {
826 s8Ret = M2M_ERR_SCAN_IN_PROGRESS;
827 }
828 EXIT:
829 return s8Ret;
830 }
m2m_wifi_wps(uint8 u8TriggerType,const char * pcPinNumber)831 sint8 m2m_wifi_wps(uint8 u8TriggerType,const char *pcPinNumber)
832 {
833 tstrM2MWPSConnect strtmp;
834
835 /* Stop Scan if it is ongoing.
836 */
837 gu8scanInProgress = 0;
838 strtmp.u8TriggerType = u8TriggerType;
839 /*If WPS is using PIN METHOD*/
840 if (u8TriggerType == WPS_PIN_TRIGGER)
841 m2m_memcpy ((uint8*)strtmp.acPinNumber,(uint8*) pcPinNumber,8);
842 return hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_WPS, (uint8*)&strtmp,sizeof(tstrM2MWPSConnect), NULL, 0,0);
843 }
m2m_wifi_wps_disable(void)844 sint8 m2m_wifi_wps_disable(void)
845 {
846 sint8 ret = M2M_SUCCESS;
847 ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_DISABLE_WPS, NULL,0, NULL, 0, 0);
848 return ret;
849 }
850 /*!
851 @fn NMI_API sint8 m2m_wifi_req_client_ctrl(uint8 cmd);
852 @brief Send a command to the PS Client (An WINC1500 board running the ps_firmware),
853 if the PS client send any commands it will be received in wifi_cb M2M_WIFI_RESP_CLIENT_INFO
854 @param [in] cmd
855 Control command sent from PS Server to PS Client (command values defined by the application)
856 @return The function SHALL return M2M_SUCCESE for success and a negative value otherwise.
857 @sa m2m_wifi_req_server_init, M2M_WIFI_RESP_CLIENT_INFO
858 @pre m2m_wifi_req_server_init should be called first
859 @warning
860 */
m2m_wifi_req_client_ctrl(uint8 u8Cmd)861 sint8 m2m_wifi_req_client_ctrl(uint8 u8Cmd)
862 {
863
864 sint8 ret = M2M_SUCCESS;
865 #ifdef _PS_SERVER_
866 tstrM2Mservercmd strCmd;
867 strCmd.u8cmd = u8Cmd;
868 ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_CLIENT_CTRL, (uint8*)&strCmd, sizeof(tstrM2Mservercmd), NULL, 0, 0);
869 #else
870 M2M_ERR("_PS_SERVER_ is not defined\n");
871 #endif
872 return ret;
873 }
874 /*!
875 @fn NMI_API sint8 m2m_wifi_req_server_init(uint8 ch);
876 @brief Initialize the PS Server, The WINC1500 support Non secure communication with another WINC1500,
877 (SERVER/CLIENT) through one byte command (probe request and probe response) without any connection setup
878 @param [in] ch
879 Server listening channel
880 @return The function SHALL return M2M_SUCCESE for success and a negative value otherwise
881 @sa m2m_wifi_req_client_ctrl
882 @warning The server mode can't be used with any other modes (STA/P2P/AP)
883 */
m2m_wifi_req_server_init(uint8 ch)884 sint8 m2m_wifi_req_server_init(uint8 ch)
885 {
886 sint8 ret = M2M_SUCCESS;
887 #ifdef _PS_SERVER_
888 tstrM2mServerInit strServer;
889 strServer.u8Channel = ch;
890 ret = hif_send(M2M_REQ_GROUP_WIFI,M2M_WIFI_REQ_SERVER_INIT, (uint8*)&strServer, sizeof(tstrM2mServerInit), NULL, 0, 0);
891 #else
892 M2M_ERR("_PS_SERVER_ is not defined\n");
893 #endif
894 return ret;
895 }
m2m_wifi_p2p(uint8 u8Channel)896 sint8 m2m_wifi_p2p(uint8 u8Channel)
897 {
898 sint8 ret = M2M_SUCCESS;
899 if((u8Channel == M2M_WIFI_CH_1) || (u8Channel == M2M_WIFI_CH_6) || (u8Channel == M2M_WIFI_CH_11))
900 {
901 tstrM2MP2PConnect strtmp;
902 strtmp.u8ListenChannel = u8Channel;
903 ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_ENABLE_P2P, (uint8*)&strtmp, sizeof(tstrM2MP2PConnect), NULL, 0,0);
904 }
905 else
906 {
907 M2M_ERR("Listen channel should only be M2M_WIFI_CH_1/6/11 \n");
908 ret = M2M_ERR_FAIL;
909 }
910 return ret;
911 }
m2m_wifi_p2p_disconnect(void)912 sint8 m2m_wifi_p2p_disconnect(void)
913 {
914 sint8 ret = M2M_SUCCESS;
915 ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_DISABLE_P2P, NULL, 0, NULL, 0, 0);
916 return ret;
917 }
m2m_wifi_enable_ap(CONST tstrM2MAPConfig * pstrM2MAPConfig)918 sint8 m2m_wifi_enable_ap(CONST tstrM2MAPConfig* pstrM2MAPConfig)
919 {
920 sint8 ret = M2M_ERR_FAIL;
921 if(M2M_SUCCESS == m2m_validate_ap_parameters(pstrM2MAPConfig))
922 {
923 ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_ENABLE_AP, (uint8 *)pstrM2MAPConfig, sizeof(tstrM2MAPConfig), NULL, 0, 0);
924 }
925 return ret;
926 }
927
m2m_wifi_set_gains(tstrM2mWifiGainsParams * pstrM2mGain)928 sint8 m2m_wifi_set_gains(tstrM2mWifiGainsParams* pstrM2mGain)
929 {
930 sint8 ret = M2M_ERR_FAIL;
931 if(pstrM2mGain != NULL)
932 {
933 ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_SET_GAINS, (uint8 *)pstrM2mGain, sizeof(tstrM2mWifiGainsParams), NULL, 0, 0);
934 }
935 return ret;
936 }
m2m_wifi_disable_ap(void)937 sint8 m2m_wifi_disable_ap(void)
938 {
939 sint8 ret = M2M_SUCCESS;
940 ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_DISABLE_AP, NULL, 0, NULL, 0, 0);
941 return ret;
942 }
943 /*!
944 @fn NMI_API sint8 m2m_wifi_req_curr_rssi(void);
945 @brief Request the current RSSI for the current connected AP,
946 the response received in wifi_cb M2M_WIFI_RESP_CURRENT_RSSI
947 @sa M2M_WIFI_RESP_CURRENT_RSSI
948 @return The function shall return M2M_SUCCESS for success and a negative value otherwise.
949 */
m2m_wifi_req_curr_rssi(void)950 sint8 m2m_wifi_req_curr_rssi(void)
951 {
952 sint8 ret = M2M_SUCCESS;
953 ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_CURRENT_RSSI, NULL, 0, NULL,0, 0);
954 return ret;
955 }
m2m_wifi_send_ethernet_pkt(uint8 * pu8Packet,uint16 u16PacketSize)956 sint8 m2m_wifi_send_ethernet_pkt(uint8* pu8Packet,uint16 u16PacketSize)
957 {
958 sint8 s8Ret = -1;
959 if((pu8Packet != NULL)&&(u16PacketSize>0))
960 {
961 tstrM2MWifiTxPacketInfo strTxPkt;
962
963 strTxPkt.u16PacketSize = u16PacketSize;
964 strTxPkt.u16HeaderLength = M2M_ETHERNET_HDR_LEN;
965 s8Ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_SEND_ETHERNET_PACKET | M2M_REQ_DATA_PKT,
966 (uint8*)&strTxPkt, sizeof(tstrM2MWifiTxPacketInfo), pu8Packet, u16PacketSize, M2M_ETHERNET_HDR_OFFSET - M2M_HIF_HDR_OFFSET);
967 }
968 return s8Ret;
969 }
970 /*!
971 @fn NMI_API sint8 m2m_wifi_get_otp_mac_address(uint8 *pu8MacAddr, uint8 * pu8IsValid);
972 @brief Request the MAC address stored on the OTP (one time programmable) memory of the device.
973 (the function is Blocking until response received)
974 @param [out] pu8MacAddr
975 Output MAC address buffer of 6 bytes size. Valid only if *pu8Valid=1.
976 @param [out] pu8IsValid
977 A output boolean value to indicate the validity of pu8MacAddr in OTP.
978 Output zero if the OTP memory is not programmed, non-zero otherwise.
979 @return The function shall return M2M_SUCCESS for success and a negative value otherwise.
980 @sa m2m_wifi_get_mac_address
981 @pre m2m_wifi_init required to call any WIFI/socket function
982 */
m2m_wifi_get_otp_mac_address(uint8 * pu8MacAddr,uint8 * pu8IsValid)983 sint8 m2m_wifi_get_otp_mac_address(uint8 *pu8MacAddr, uint8* pu8IsValid)
984 {
985 sint8 ret = M2M_SUCCESS;
986 ret = hif_chip_wake();
987 if(ret == M2M_SUCCESS)
988 {
989 ret = nmi_get_otp_mac_address(pu8MacAddr, pu8IsValid);
990 if(ret == M2M_SUCCESS)
991 {
992 ret = hif_chip_sleep();
993 }
994 }
995 return ret;
996 }
997 /*!
998 @fn NMI_API sint8 m2m_wifi_get_mac_address(uint8 *pu8MacAddr)
999 @brief Request the current MAC address of the device (the working mac address).
1000 (the function is Blocking until response received)
1001 @param [out] pu8MacAddr
1002 Output MAC address buffer of 6 bytes size.
1003 @return The function shall return M2M_SUCCESS for success and a negative value otherwise.
1004 @sa m2m_wifi_get_otp_mac_address
1005 @pre m2m_wifi_init required to call any WIFI/socket function
1006 */
m2m_wifi_get_mac_address(uint8 * pu8MacAddr)1007 sint8 m2m_wifi_get_mac_address(uint8 *pu8MacAddr)
1008 {
1009 sint8 ret = M2M_SUCCESS;
1010 ret = hif_chip_wake();
1011 if(ret == M2M_SUCCESS)
1012 {
1013 ret = nmi_get_mac_address(pu8MacAddr);
1014 if(ret == M2M_SUCCESS)
1015 {
1016 ret = hif_chip_sleep();
1017 }
1018 }
1019
1020 return ret;
1021 }
1022 /*!
1023 @fn NMI_API sint8 m2m_wifi_req_scan_result(uint8 index);
1024 @brief Reads the AP information from the Scan Result list with the given index,
1025 the response received in wifi_cb M2M_WIFI_RESP_SCAN_RESULT,
1026 the response pointer should be casted with tstrM2mWifiscanResult structure
1027 @param [in] index
1028 Index for the requested result, the index range start from 0 till number of AP's found
1029 @sa tstrM2mWifiscanResult,m2m_wifi_get_num_ap_found,m2m_wifi_request_scan
1030 @return The function shall return M2M_SUCCESE for success and a negative value otherwise
1031 @pre m2m_wifi_request_scan need to be called first, then m2m_wifi_get_num_ap_found
1032 to get the number of AP's found
1033 @warning Function used only in STA mode only. the scan result updated only if scan request called,
1034 else it will be cashed in firmware for the host scan request result,
1035 which mean if large delay occur between the scan request and the scan result request,
1036 the result will not be up-to-date
1037 */
1038
m2m_wifi_req_scan_result(uint8 index)1039 sint8 m2m_wifi_req_scan_result(uint8 index)
1040 {
1041 sint8 ret = M2M_SUCCESS;
1042 tstrM2mReqScanResult strReqScanRlt;
1043 strReqScanRlt.u8Index = index;
1044 ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_SCAN_RESULT, (uint8*) &strReqScanRlt, sizeof(tstrM2mReqScanResult), NULL, 0, 0);
1045 return ret;
1046 }
1047 /*!
1048 @fn NMI_API uint8 m2m_wifi_get_num_ap_found(void);
1049 @brief Reads the number of AP's found in the last Scan Request,
1050 The function read the number of AP's from global variable which updated in the
1051 wifi_cb in M2M_WIFI_RESP_SCAN_DONE.
1052 @sa m2m_wifi_request_scan
1053 @return Return the number of AP's found in the last Scan Request.
1054 @pre m2m_wifi_request_scan need to be called first
1055 @warning That function need to be called in the wifi_cb in M2M_WIFI_RESP_SCAN_DONE,
1056 calling that function in any other place will return undefined/undated numbers.
1057 Function used only in STA mode only.
1058 */
m2m_wifi_get_num_ap_found(void)1059 uint8 m2m_wifi_get_num_ap_found(void)
1060 {
1061 return gu8ChNum;
1062 }
1063 /*!
1064 @fn NMI_API uint8 m2m_wifi_get_sleep_mode(void);
1065 @brief Get the current Power save mode.
1066 @return The current operating power saving mode.
1067 @sa tenuPowerSaveModes , m2m_wifi_set_sleep_mode
1068 */
m2m_wifi_get_sleep_mode(void)1069 uint8 m2m_wifi_get_sleep_mode(void)
1070 {
1071 return hif_get_sleep_mode();
1072 }
1073 /*!
1074 @fn NMI_API sint8 m2m_wifi_set_sleep_mode(uint8 PsTyp, uint8 BcastEn);
1075 @brief Set the power saving mode for the WINC1500.
1076 @param [in] PsTyp
1077 Desired power saving mode. Supported types are defined in tenuPowerSaveModes.
1078 @param [in] BcastEn
1079 Broadcast reception enable flag.
1080 If it is 1, the WINC1500 must be awake each DTIM Beacon for receiving Broadcast traffic.
1081 If it is 0, the WINC1500 will not wakeup at the DTIM Beacon, but its wakeup depends only
1082 on the the configured Listen Interval.
1083 @return The function SHALL return 0 for success and a negative value otherwise.
1084 @sa tenuPowerSaveModes
1085 @warning The function called once after initialization.
1086 */
m2m_wifi_set_sleep_mode(uint8 PsTyp,uint8 BcastEn)1087 sint8 m2m_wifi_set_sleep_mode(uint8 PsTyp, uint8 BcastEn)
1088 {
1089 sint8 ret = M2M_SUCCESS;
1090 tstrM2mPsType strPs;
1091 strPs.u8PsType = PsTyp;
1092 strPs.u8BcastEn = BcastEn;
1093 ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_SLEEP, (uint8*) &strPs,sizeof(tstrM2mPsType), NULL, 0, 0);
1094 M2M_INFO("POWER SAVE %d\n",PsTyp);
1095 hif_set_sleep_mode(PsTyp);
1096 return ret;
1097 }
1098 /*!
1099 @fn NMI_API sint8 m2m_wifi_request_sleep(void)
1100 @brief Request from WINC1500 device to Sleep for specific time in the M2M_PS_MANUAL Power save mode (only).
1101 @param [in] u32SlpReqTime
1102 Request Sleep in ms
1103 @return The function SHALL return M2M_SUCCESS for success and a negative value otherwise.
1104 @sa tenuPowerSaveModes , m2m_wifi_set_sleep_mode
1105 @warning the Function should be called in M2M_PS_MANUAL power save only
1106 */
m2m_wifi_request_sleep(uint32 u32SlpReqTime)1107 sint8 m2m_wifi_request_sleep(uint32 u32SlpReqTime)
1108 {
1109 sint8 ret = M2M_SUCCESS;
1110 uint8 psType;
1111 psType = hif_get_sleep_mode();
1112 if(psType == M2M_PS_MANUAL)
1113 {
1114 tstrM2mSlpReqTime strPs;
1115 strPs.u32SleepTime = u32SlpReqTime;
1116 ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_DOZE, (uint8*) &strPs,sizeof(tstrM2mSlpReqTime), NULL, 0, 0);
1117 }
1118 return ret;
1119 }
1120 /*!
1121 @fn NMI_API sint8 m2m_wifi_set_device_name(uint8 *pu8DeviceName, uint8 u8DeviceNameLength);
1122 @brief Set the WINC1500 device name which is used as P2P device name.
1123 @param [in] pu8DeviceName
1124 Buffer holding the device name.
1125 @param [in] u8DeviceNameLength
1126 Length of the device name.
1127 @return The function SHALL return M2M_SUCCESS for success and a negative value otherwise.
1128 @warning The Function called once after initialization.
1129 */
m2m_wifi_set_device_name(uint8 * pu8DeviceName,uint8 u8DeviceNameLength)1130 sint8 m2m_wifi_set_device_name(uint8 *pu8DeviceName, uint8 u8DeviceNameLength)
1131 {
1132 tstrM2MDeviceNameConfig strDeviceName;
1133 if(u8DeviceNameLength >= M2M_DEVICE_NAME_MAX)
1134 {
1135 u8DeviceNameLength = M2M_DEVICE_NAME_MAX;
1136 }
1137 //pu8DeviceName[u8DeviceNameLength] = '\0';
1138 u8DeviceNameLength ++;
1139 m2m_memcpy(strDeviceName.au8DeviceName, pu8DeviceName, u8DeviceNameLength);
1140 return hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_SET_DEVICE_NAME,
1141 (uint8*)&strDeviceName, sizeof(tstrM2MDeviceNameConfig), NULL, 0,0);
1142 }
m2m_wifi_get_firmware_version(tstrM2mRev * pstrRev)1143 sint8 m2m_wifi_get_firmware_version(tstrM2mRev *pstrRev)
1144 {
1145 sint8 ret = M2M_SUCCESS;
1146 ret = hif_chip_wake();
1147 if(ret == M2M_SUCCESS)
1148 {
1149 ret = nm_get_firmware_full_info(pstrRev);
1150 hif_chip_sleep();
1151 }
1152 return ret;
1153 }
1154 #ifdef CONF_MGMT
m2m_wifi_enable_monitoring_mode(tstrM2MWifiMonitorModeCtrl * pstrMtrCtrl,uint8 * pu8PayloadBuffer,uint16 u16BufferSize,uint16 u16DataOffset)1155 sint8 m2m_wifi_enable_monitoring_mode(tstrM2MWifiMonitorModeCtrl *pstrMtrCtrl, uint8 *pu8PayloadBuffer,
1156 uint16 u16BufferSize, uint16 u16DataOffset)
1157 {
1158 sint8 s8Ret = -1;
1159 if((pstrMtrCtrl->u8ChannelID >= M2M_WIFI_CH_1) && (pstrMtrCtrl->u8ChannelID <= M2M_WIFI_CH_14))
1160 {
1161 gstrMgmtCtrl.pu8Buf = pu8PayloadBuffer;
1162 gstrMgmtCtrl.u16Sz = u16BufferSize;
1163 gstrMgmtCtrl.u16Offset = u16DataOffset;
1164 s8Ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_ENABLE_MONITORING,
1165 (uint8*)pstrMtrCtrl, sizeof(tstrM2MWifiMonitorModeCtrl), NULL, 0,0);
1166 }
1167 return s8Ret;
1168 }
1169
m2m_wifi_disable_monitoring_mode(void)1170 sint8 m2m_wifi_disable_monitoring_mode(void)
1171 {
1172 return hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_DISABLE_MONITORING, NULL, 0, NULL, 0,0);
1173 }
1174
m2m_wifi_send_wlan_pkt(uint8 * pu8WlanPacket,uint16 u16WlanHeaderLength,uint16 u16WlanPktSize)1175 sint8 m2m_wifi_send_wlan_pkt(uint8 *pu8WlanPacket, uint16 u16WlanHeaderLength, uint16 u16WlanPktSize)
1176 {
1177 sint8 s8Ret = -1;
1178 if(pu8WlanPacket != NULL)
1179 {
1180 tstrM2MWifiTxPacketInfo strTxPkt;
1181
1182 strTxPkt.u16PacketSize = u16WlanPktSize;
1183 strTxPkt.u16HeaderLength = u16WlanHeaderLength;
1184 s8Ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_SEND_WIFI_PACKET | M2M_REQ_DATA_PKT,
1185 (uint8*)&strTxPkt, sizeof(tstrM2MWifiTxPacketInfo), pu8WlanPacket, u16WlanPktSize, sizeof(tstrM2MWifiTxPacketInfo));
1186 }
1187 return s8Ret;
1188 }
1189 #endif
1190
m2m_wifi_start_provision_mode(tstrM2MAPConfig * pstrAPConfig,char * pcHttpServerDomainName,uint8 bEnableHttpRedirect)1191 sint8 m2m_wifi_start_provision_mode(tstrM2MAPConfig *pstrAPConfig, char *pcHttpServerDomainName, uint8 bEnableHttpRedirect)
1192 {
1193 sint8 s8Ret = M2M_ERR_FAIL;
1194
1195 if((pstrAPConfig != NULL))
1196 {
1197 tstrM2MProvisionModeConfig strProvConfig;
1198 if(M2M_SUCCESS == m2m_validate_ap_parameters(pstrAPConfig))
1199 {
1200 m2m_memcpy((uint8*)&strProvConfig.strApConfig, (uint8*)pstrAPConfig, sizeof(tstrM2MAPConfig));
1201 if((m2m_strlen((uint8 *)pcHttpServerDomainName) <= 0) || (NULL == pcHttpServerDomainName))
1202 {
1203 M2M_ERR("INVALID DOMAIN NAME\n");
1204 goto ERR1;
1205 }
1206 m2m_memcpy((uint8*)strProvConfig.acHttpServerDomainName, (uint8*)pcHttpServerDomainName, 64);
1207 strProvConfig.u8EnableRedirect = bEnableHttpRedirect;
1208
1209 /* Stop Scan if it is ongoing.
1210 */
1211 gu8scanInProgress = 0;
1212 s8Ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_START_PROVISION_MODE | M2M_REQ_DATA_PKT,
1213 (uint8*)&strProvConfig, sizeof(tstrM2MProvisionModeConfig), NULL, 0, 0);
1214 }
1215 else
1216 {
1217 /*goto ERR1;*/
1218 }
1219 }
1220 ERR1:
1221 return s8Ret;
1222 }
1223
m2m_wifi_stop_provision_mode(void)1224 sint8 m2m_wifi_stop_provision_mode(void)
1225 {
1226 return hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_STOP_PROVISION_MODE, NULL, 0, NULL, 0, 0);
1227 }
1228
m2m_wifi_get_connection_info(void)1229 sint8 m2m_wifi_get_connection_info(void)
1230 {
1231 return hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_GET_CONN_INFO, NULL, 0, NULL, 0, 0);
1232 }
1233
m2m_wifi_set_sytem_time(uint32 u32UTCSeconds)1234 sint8 m2m_wifi_set_sytem_time(uint32 u32UTCSeconds)
1235 {
1236 /*
1237 The firmware accepts timestamps relative to 1900 like NTP Timestamp.
1238 */
1239 return hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_SET_SYS_TIME, (uint8*)&u32UTCSeconds, sizeof(tstrSystemTime), NULL, 0, 0);
1240 }
1241 /*!
1242 * @fn NMI_API sint8 m2m_wifi_get_sytem_time(void);
1243 * @see m2m_wifi_enable_sntp
1244 tstrSystemTime
1245 * @note get the system time from the sntp client
1246 * using the API \ref m2m_wifi_get_sytem_time.
1247 * @return The function returns @ref M2M_SUCCESS for successful operations and a negative value otherwise.
1248 */
m2m_wifi_get_sytem_time(void)1249 sint8 m2m_wifi_get_sytem_time(void)
1250 {
1251 return hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_GET_SYS_TIME, NULL,0, NULL, 0, 0);
1252 }
1253
m2m_wifi_enable_sntp(uint8 bEnable)1254 sint8 m2m_wifi_enable_sntp(uint8 bEnable)
1255 {
1256 uint8 u8Req;
1257
1258 u8Req = bEnable ? M2M_WIFI_REQ_ENABLE_SNTP_CLIENT : M2M_WIFI_REQ_DISABLE_SNTP_CLIENT;
1259 return hif_send(M2M_REQ_GROUP_WIFI, u8Req, NULL, 0, NULL, 0, 0);
1260 }
1261 /*!
1262 @fn NMI_API sint8 m2m_wifi_set_power_profile(uint8 u8PwrMode);
1263 @brief Change the power profile mode
1264 @param [in] u8PwrMode
1265 Change the WINC power profile to different mode
1266 PWR_LOW1/PWR_LOW2/PWR_HIGH/PWR_AUTO (tenuM2mPwrMode)
1267 @return The function SHALL return M2M_SUCCESE for success and a negative value otherwise.
1268 @sa tenuM2mPwrMode
1269 @pre m2m_wifi_init
1270 @warning must be called after the initializations and before any connection request and can't be changed in run time,
1271 */
m2m_wifi_set_power_profile(uint8 u8PwrMode)1272 sint8 m2m_wifi_set_power_profile(uint8 u8PwrMode)
1273 {
1274 sint8 ret = M2M_SUCCESS;
1275 tstrM2mPwrMode strM2mPwrMode;
1276 strM2mPwrMode.u8PwrMode = u8PwrMode;
1277 ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_SET_POWER_PROFILE, (uint8*)&strM2mPwrMode,sizeof(tstrM2mPwrMode), NULL, 0, 0);
1278 return ret;
1279 }
1280 /*!
1281 @fn NMI_API sint8 m2m_wifi_set_tx_power(uint8 u8TxPwrLevel);
1282 @brief set the TX power tenuM2mTxPwrLevel
1283 @param [in] u8TxPwrLevel
1284 change the TX power tenuM2mTxPwrLevel
1285 @return The function SHALL return M2M_SUCCESE for success and a negative value otherwise.
1286 @sa tenuM2mTxPwrLevel
1287 @pre m2m_wifi_init
1288 @warning
1289 */
m2m_wifi_set_tx_power(uint8 u8TxPwrLevel)1290 sint8 m2m_wifi_set_tx_power(uint8 u8TxPwrLevel)
1291 {
1292 sint8 ret = M2M_SUCCESS;
1293 tstrM2mTxPwrLevel strM2mTxPwrLevel;
1294 strM2mTxPwrLevel.u8TxPwrLevel = u8TxPwrLevel;
1295 ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_SET_TX_POWER, (uint8*)&strM2mTxPwrLevel,sizeof(tstrM2mTxPwrLevel), NULL, 0, 0);
1296 return ret;
1297 }
1298
1299 /*!
1300 @fn NMI_API sint8 m2m_wifi_enable_firmware_logs(uint8 u8Enable);
1301 @brief Enable or Disable logs in run time (Disable Firmware logs will
1302 enhance the firmware start-up time and performance)
1303 @param [in] u8Enable
1304 Set 1 to enable the logs 0 for disable
1305 @return The function SHALL return M2M_SUCCESE for success and a negative value otherwise.
1306 @sa __DISABLE_FIRMWARE_LOGS__ (build option to disable logs from initializations)
1307 @pre m2m_wifi_init
1308 @warning
1309 */
m2m_wifi_enable_firmware_logs(uint8 u8Enable)1310 sint8 m2m_wifi_enable_firmware_logs(uint8 u8Enable)
1311 {
1312 sint8 ret = M2M_SUCCESS;
1313 tstrM2mEnableLogs strM2mEnableLogs;
1314 strM2mEnableLogs.u8Enable = u8Enable;
1315 ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_SET_ENABLE_LOGS, (uint8*)&strM2mEnableLogs,sizeof(tstrM2mEnableLogs), NULL, 0, 0);
1316 return ret;
1317 }
1318
1319 /*!
1320 @fn NMI_API sint8 m2m_wifi_set_battery_voltage(uint16 u16BattVoltx100);
1321 @brief Enable or Disable logs in run time (Disable Firmware logs will
1322 enhance the firmware start-up time and performance)
1323 @param [in] u16BattVoltx100
1324 battery voltage multiplied by 100
1325 @return The function SHALL return M2M_SUCCESE for success and a negative value otherwise.
1326 @sa __DISABLE_FIRMWARE_LOGS__ (build option to disable logs from initializations)
1327 @pre m2m_wifi_init
1328 @warning
1329 */
m2m_wifi_set_battery_voltage(uint16 u16BattVoltx100)1330 sint8 m2m_wifi_set_battery_voltage(uint16 u16BattVoltx100)
1331 {
1332 sint8 ret = M2M_SUCCESS;
1333 tstrM2mBatteryVoltage strM2mBattVol = {0};
1334 strM2mBattVol.u16BattVolt = u16BattVoltx100;
1335 ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_SET_BATTERY_VOLTAGE, (uint8*)&strM2mBattVol,sizeof(tstrM2mBatteryVoltage), NULL, 0, 0);
1336 return ret;
1337 }
1338 /*!
1339 @fn sint8 m2m_wifi_prng_get_random_bytes(uint8 * pu8PrngBuff,uint16 u16PrngSize)
1340 @brief Get random bytes using the PRNG bytes.
1341 @param [in] u16PrngSize
1342 Size of the required random bytes to be generated.
1343 @param [in] pu8PrngBuff
1344 Pointer to user allocated buffer.
1345 @return The function SHALL return M2M_SUCCESE for success and a negative value otherwise.
1346 */
m2m_wifi_prng_get_random_bytes(uint8 * pu8PrngBuff,uint16 u16PrngSize)1347 sint8 m2m_wifi_prng_get_random_bytes(uint8 * pu8PrngBuff,uint16 u16PrngSize)
1348 {
1349 sint8 ret = M2M_ERR_FAIL;
1350 tstrPrng strRng = {0};
1351 if((u16PrngSize < (M2M_BUFFER_MAX_SIZE - sizeof(tstrPrng)))&&(pu8PrngBuff != NULL))
1352 {
1353 strRng.u16PrngSize = u16PrngSize;
1354 strRng.pu8RngBuff = pu8PrngBuff;
1355 ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_GET_PRNG|M2M_REQ_DATA_PKT,(uint8 *)&strRng, sizeof(tstrPrng),NULL,0, 0);
1356 }
1357 else
1358 {
1359 M2M_ERR("PRNG Buffer exceeded maximum size %d or NULL Buffer\n",u16PrngSize);
1360 }
1361 return ret;
1362 }
1363 #ifdef ETH_MODE
1364 /*!
1365 @fn \
1366 NMI_API sint8 m2m_wifi_enable_mac_mcast(uint8* pu8MulticastMacAddress, uint8 u8AddRemove)
1367
1368 @brief
1369 Add MAC filter to receive Multicast packets.
1370
1371 @param [in] pu8MulticastMacAddress
1372 Pointer to the MAC address.
1373 @param [in] u8AddRemove
1374 Flag to Add/Remove MAC address.
1375 @return
1376 The function SHALL return 0 for success and a negative value otherwise.
1377 */
1378
m2m_wifi_enable_mac_mcast(uint8 * pu8MulticastMacAddress,uint8 u8AddRemove)1379 NMI_API sint8 m2m_wifi_enable_mac_mcast(uint8* pu8MulticastMacAddress, uint8 u8AddRemove)
1380 {
1381 sint8 s8ret = M2M_ERR_FAIL;
1382 tstrM2MMulticastMac strMulticastMac;
1383
1384 if(pu8MulticastMacAddress != NULL )
1385 {
1386 strMulticastMac.u8AddRemove = u8AddRemove;
1387 m2m_memcpy(strMulticastMac.au8macaddress,pu8MulticastMacAddress,M2M_MAC_ADDRES_LEN);
1388 M2M_DBG("mac multicast: %x:%x:%x:%x:%x:%x\r\n",strMulticastMac.au8macaddress[0],strMulticastMac.au8macaddress[1],strMulticastMac.au8macaddress[2],strMulticastMac.au8macaddress[3],strMulticastMac.au8macaddress[4],strMulticastMac.au8macaddress[5]);
1389 s8ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_SET_MAC_MCAST, (uint8 *)&strMulticastMac,sizeof(tstrM2MMulticastMac),NULL,0,0);
1390 }
1391
1392 return s8ret;
1393
1394 }
1395
1396 /*!
1397 @fn \
1398 NMI_API sint8 m2m_wifi_set_receive_buffer(void* pvBuffer,uint16 u16BufferLen);
1399
1400 @brief
1401 set the ethernet receive buffer, should be called in the receive call back.
1402
1403 @param [in] pvBuffer
1404 Pointer to the ethernet receive buffer.
1405 @param [in] u16BufferLen
1406 Length of the buffer.
1407
1408 @return
1409 The function SHALL return 0 for success and a negative value otherwise.
1410 */
m2m_wifi_set_receive_buffer(void * pvBuffer,uint16 u16BufferLen)1411 NMI_API sint8 m2m_wifi_set_receive_buffer(void* pvBuffer,uint16 u16BufferLen)
1412 {
1413 sint8 s8ret = M2M_SUCCESS;
1414 if(pvBuffer != NULL)
1415 {
1416 gau8ethRcvBuf = pvBuffer;
1417 gu16ethRcvBufSize= u16BufferLen;
1418 }
1419 else
1420 {
1421 s8ret = M2M_ERR_FAIL;
1422 M2M_ERR("Buffer NULL pointer\r\n");
1423 }
1424 return s8ret;
1425 }
1426 #endif /* ETH_MODE */
1427