m2m_wifi.c
Go to the documentation of this file.
1 
36 #include "driver/source/m2m_hif.h"
37 #include "driver/source/nmasic.h"
38 
39 #include "ISConstants.h"
40 #define malloc MALLOC
41 #define free FREE
42 
43 static volatile uint8 gu8ChNum;
45 
46 
47 #ifdef ETH_MODE
48 static tpfAppEthCb gpfAppEthCb = NULL;
49 static uint8* gau8ethRcvBuf=NULL;
50 static uint16 gu16ethRcvBufSize ;
51 #endif
52 
53 //#define CONF_MGMT
54 
55 #ifdef CONF_MGMT
56 static tpfAppMonCb gpfAppMonCb = NULL;
57 static struct _tstrMgmtCtrl
58 {
59  uint8* pu8Buf;
60  uint16 u16Offset;
61  uint16 u16Sz;
62 }
63 gstrMgmtCtrl = {NULL, 0 , 0};
64 #endif
65 
80 static void m2m_wifi_cb(uint8 u8OpCode, uint16 u16DataSize, uint32 u32Addr)
81 {
82  uint8 rx_buf[8];
83  if (u8OpCode == M2M_WIFI_RESP_CON_STATE_CHANGED)
84  {
85  tstrM2mWifiStateChanged strState;
86  if (hif_receive(u32Addr, (uint8*) &strState,sizeof(tstrM2mWifiStateChanged), 0) == M2M_SUCCESS)
87  {
88  if (gpfAppWifiCb)
90  }
91  }
92  else if (u8OpCode == M2M_WIFI_RESP_GET_SYS_TIME)
93  {
94  tstrSystemTime strSysTime;
95  if (hif_receive(u32Addr, (uint8*) &strSysTime,sizeof(tstrSystemTime), 0) == M2M_SUCCESS)
96  {
97  if (gpfAppWifiCb)
99  }
100  }
101  else if(u8OpCode == M2M_WIFI_RESP_CONN_INFO)
102  {
103  tstrM2MConnInfo strConnInfo;
104  if(hif_receive(u32Addr, (uint8*)&strConnInfo, sizeof(tstrM2MConnInfo), 1) == M2M_SUCCESS)
105  {
106  if(gpfAppWifiCb)
107  gpfAppWifiCb(M2M_WIFI_RESP_CONN_INFO, &strConnInfo);
108  }
109  }
110  else if (u8OpCode == M2M_WIFI_RESP_MEMORY_RECOVER)
111  {
112 #if 0
113  if (hif_receive(u32Addr, rx_buf, 4, 1) == M2M_SUCCESS)
114  {
115  tstrM2mWifiStateChanged strState;
116  m2m_memcpy((uint8*) &strState, rx_buf,sizeof(tstrM2mWifiStateChanged));
117  if (app_wifi_recover_cb)
118  app_wifi_recover_cb(strState.u8CurrState);
119  }
120 #endif
121  }
122  else if (u8OpCode == M2M_WIFI_REQ_DHCP_CONF)
123  {
124  tstrM2MIPConfig strIpConfig;
125  if (hif_receive(u32Addr, (uint8 *)&strIpConfig, sizeof(tstrM2MIPConfig), 0) == M2M_SUCCESS)
126  {
127  if (gpfAppWifiCb)
128  gpfAppWifiCb(M2M_WIFI_REQ_DHCP_CONF, (uint8 *)&strIpConfig);
129  }
130  }
131  else if (u8OpCode == M2M_WIFI_REQ_WPS)
132  {
133  tstrM2MWPSInfo strWps;
134  m2m_memset((uint8*)&strWps,0,sizeof(tstrM2MWPSInfo));
135  if(hif_receive(u32Addr, (uint8*)&strWps, sizeof(tstrM2MWPSInfo), 0) == M2M_SUCCESS)
136  {
137  if (gpfAppWifiCb)
138  gpfAppWifiCb(M2M_WIFI_REQ_WPS, &strWps);
139  }
140  }
141  else if (u8OpCode == M2M_WIFI_RESP_IP_CONFLICT)
142  {
143  uint32 u32ConflictedIP;
144  if(hif_receive(u32Addr, (uint8 *)&u32ConflictedIP, sizeof(u32ConflictedIP), 0) == M2M_SUCCESS)
145  {
146  M2M_INFO("Conflicted IP \" %u.%u.%u.%u \" \n",
147  BYTE_0(u32ConflictedIP),BYTE_1(u32ConflictedIP),BYTE_2(u32ConflictedIP),BYTE_3(u32ConflictedIP));
148  if (gpfAppWifiCb)
150 
151  }
152  }
153  else if (u8OpCode == M2M_WIFI_RESP_SCAN_DONE)
154  {
155  tstrM2mScanDone strState;
156  if(hif_receive(u32Addr, (uint8*)&strState, sizeof(tstrM2mScanDone), 0) == M2M_SUCCESS)
157  {
158  gu8ChNum = strState.u8NumofCh;
159  if (gpfAppWifiCb)
161  }
162  }
163  else if (u8OpCode == M2M_WIFI_RESP_SCAN_RESULT)
164  {
165  tstrM2mWifiscanResult strScanResult;
166  if(hif_receive(u32Addr, (uint8*)&strScanResult, sizeof(tstrM2mWifiscanResult), 0) == M2M_SUCCESS)
167  {
168  if (gpfAppWifiCb)
169  gpfAppWifiCb(M2M_WIFI_RESP_SCAN_RESULT, &strScanResult);
170  }
171  }
172  else if (u8OpCode == M2M_WIFI_RESP_CURRENT_RSSI)
173  {
174  if (hif_receive(u32Addr, rx_buf, 4, 0) == M2M_SUCCESS)
175  {
176  if (gpfAppWifiCb)
178  }
179  }
180  else if (u8OpCode == M2M_WIFI_RESP_CLIENT_INFO)
181  {
182  if (hif_receive(u32Addr, rx_buf, 4, 0) == M2M_SUCCESS)
183  {
184  if (gpfAppWifiCb)
186  }
187  }
188  else if(u8OpCode == M2M_WIFI_RESP_PROVISION_INFO)
189  {
190  tstrM2MProvisionInfo strProvInfo;
191  if(hif_receive(u32Addr, (uint8*)&strProvInfo, sizeof(tstrM2MProvisionInfo), 1) == M2M_SUCCESS)
192  {
193  if(gpfAppWifiCb)
195  }
196  }
197  else if(u8OpCode == M2M_WIFI_RESP_DEFAULT_CONNECT)
198  {
199  tstrM2MDefaultConnResp strResp;
200  if(hif_receive(u32Addr, (uint8*)&strResp, sizeof(tstrM2MDefaultConnResp), 1) == M2M_SUCCESS)
201  {
202  if(gpfAppWifiCb)
204  }
205  }
206  else if (u8OpCode == M2M_WIFI_RESP_BLE_API_RECV)
207  {
208  //Read the length
209  if(hif_receive(u32Addr, rx_buf, 2, 0) == M2M_SUCCESS)
210  {
211  uint16 u16BleMsgLen = (rx_buf[1] << 8) + rx_buf[0];
212  tstrM2mBleApiMsg* bleRx = (tstrM2mBleApiMsg*)malloc(u16BleMsgLen + sizeof(tstrM2mBleApiMsg));
213 
214  if(bleRx != NULL)
215  {
216  bleRx->u16Len = u16BleMsgLen;
217 
218  //Read the rest of the message
219  if (hif_receive(u32Addr+2, bleRx->data, bleRx->u16Len, 1)== M2M_SUCCESS)
220  {
221  if(gpfAppWifiCb)
223  }
224  free(bleRx);
225  }
226  }
227  }
228  else if(u8OpCode == M2M_WIFI_RESP_GET_PRNG)
229  {
230  tstrPrng strPrng;
231  if(hif_receive(u32Addr, (uint8*)&strPrng,sizeof(tstrPrng), 0) == M2M_SUCCESS)
232  {
233  if(hif_receive(u32Addr + sizeof(tstrPrng),strPrng.pu8RngBuff,strPrng.u16PrngSize, 1) == M2M_SUCCESS)
234  {
235  if(gpfAppWifiCb) {
237  }
238  }
239  }
240  }
241  else if (u8OpCode == M2M_WIFI_RESP_SET_GAIN_TABLE)
242  {
243  tstrM2MGainTableRsp strGainRsp;
244  if (hif_receive(u32Addr, (uint8*) &strGainRsp,sizeof(tstrM2MGainTableRsp), 0) == M2M_SUCCESS)
245  {
246  if (gpfAppWifiCb)
248  }
249  }
250 #ifdef ETH_MODE
251  else if(u8OpCode == M2M_WIFI_RESP_ETHERNET_RX_PACKET)
252  {
253  if(hif_receive(u32Addr, rx_buf ,sizeof(tstrM2mIpRsvdPkt), 0) == M2M_SUCCESS)
254  {
255  tstrM2mIpRsvdPkt * pstrM2MIpRxPkt = (tstrM2mIpRsvdPkt*)rx_buf;
256  tstrM2mIpCtrlBuf strM2mIpCtrlBuf;
257  uint16 u16Offset = pstrM2MIpRxPkt->u16PktOffset;
258 
259  strM2mIpCtrlBuf.u16RemainigDataSize = pstrM2MIpRxPkt->u16PktSz;
260  if((gpfAppEthCb) &&(gau8ethRcvBuf)&& (gu16ethRcvBufSize > 0))
261  {
262  while (strM2mIpCtrlBuf.u16RemainigDataSize > 0)
263  {
264  if(strM2mIpCtrlBuf.u16RemainigDataSize > gu16ethRcvBufSize)
265  {
266  strM2mIpCtrlBuf.u16DataSize = gu16ethRcvBufSize ;
267  }
268  else
269  {
270  strM2mIpCtrlBuf.u16DataSize = strM2mIpCtrlBuf.u16RemainigDataSize;
271  }
272  if(hif_receive(u32Addr+u16Offset, gau8ethRcvBuf, strM2mIpCtrlBuf.u16DataSize, 0) == M2M_SUCCESS)
273  {
274  strM2mIpCtrlBuf.u16RemainigDataSize -= strM2mIpCtrlBuf.u16DataSize;
275  u16Offset += strM2mIpCtrlBuf.u16DataSize;
276  gpfAppEthCb(M2M_WIFI_RESP_ETHERNET_RX_PACKET, gau8ethRcvBuf, &(strM2mIpCtrlBuf));
277  }
278  else
279  {
280  break;
281  }
282  }
283  }
284  }
285  }
286 #endif
287 
288 #ifdef CONF_MGMT
289  else if(u8OpCode == M2M_WIFI_RESP_WIFI_RX_PACKET)
290  {
291  tstrM2MWifiRxPacketInfo strRxPacketInfo;
292  if(u16DataSize >= sizeof(tstrM2MWifiRxPacketInfo)) {
293  if(hif_receive(u32Addr, (uint8*)&strRxPacketInfo, sizeof(tstrM2MWifiRxPacketInfo), 0) == M2M_SUCCESS)
294  {
295  u16DataSize -= sizeof(tstrM2MWifiRxPacketInfo);
296  if(u16DataSize > 0 && gstrMgmtCtrl.pu8Buf != NULL)
297  {
298  if(u16DataSize > (gstrMgmtCtrl.u16Sz + gstrMgmtCtrl.u16Offset))
299  {
300  u16DataSize = gstrMgmtCtrl.u16Sz;
301  }
302  u32Addr += sizeof(tstrM2MWifiRxPacketInfo) + gstrMgmtCtrl.u16Offset;
303  if(hif_receive(u32Addr , gstrMgmtCtrl.pu8Buf, u16DataSize, 1) != M2M_SUCCESS)
304  {
305  u16DataSize = 0;
306  }
307  }
308  if(gpfAppMonCb)
309  gpfAppMonCb(&strRxPacketInfo, gstrMgmtCtrl.pu8Buf,u16DataSize);
310  }
311  } else {
312  M2M_ERR("Incorrect mon data size %u\n", u16DataSize);
313  }
314  }
315 #endif
316  else
317  {
318  M2M_ERR("REQ Not defined %d\n",u8OpCode);
319  }
320 }
321 
323 {
324  sint8 ret = M2M_SUCCESS;
325  /* Apply device specific initialization. */
326  ret = nm_drv_init_download_mode(0);
327  if(ret != M2M_SUCCESS) goto _EXIT0;
328 
329 
330 
332 
333 _EXIT0:
334  return ret;
335 }
336 
338 {
339  sint8 s8Ret = M2M_SUCCESS;
340  /* Check for incoming pointer */
341  if(pstrM2MAPConfig == NULL)
342  {
343  M2M_ERR("INVALID POINTER\n");
344  s8Ret = M2M_ERR_FAIL;
345  goto ERR1;
346  }
347  /* Check for SSID */
348  if((m2m_strlen((uint8 *)pstrM2MAPConfig->au8SSID) <= 0) || (m2m_strlen((uint8 *)pstrM2MAPConfig->au8SSID) >= M2M_MAX_SSID_LEN))
349  {
350  M2M_ERR("INVALID SSID\n");
351  s8Ret = M2M_ERR_FAIL;
352  goto ERR1;
353  }
354  /* Check for Channel */
355  if(pstrM2MAPConfig->u8ListenChannel > M2M_WIFI_CH_14 || pstrM2MAPConfig->u8ListenChannel < M2M_WIFI_CH_1)
356  {
357  M2M_ERR("INVALID CH\n");
358  s8Ret = M2M_ERR_FAIL;
359  goto ERR1;
360  }
361  /* Check for DHCP Server IP address */
362  if(!(pstrM2MAPConfig->au8DHCPServerIP[0] || pstrM2MAPConfig->au8DHCPServerIP[1]))
363  {
364  if(!(pstrM2MAPConfig->au8DHCPServerIP[2]))
365  {
366  M2M_ERR("INVALID DHCP SERVER IP\n");
367  s8Ret = M2M_ERR_FAIL;
368  goto ERR1;
369  }
370  }
371  /* Check for Security */
372  if(pstrM2MAPConfig->u8SecType == M2M_WIFI_SEC_OPEN)
373  {
374  goto ERR1;
375  }
376  else if(pstrM2MAPConfig->u8SecType == M2M_WIFI_SEC_WEP)
377  {
378  /* Check for WEP Key index */
379  if((pstrM2MAPConfig->u8KeyIndx <= 0) || (pstrM2MAPConfig->u8KeyIndx > WEP_KEY_MAX_INDEX))
380  {
381  M2M_ERR("INVALID KEY INDEX\n");
382  s8Ret = M2M_ERR_FAIL;
383  goto ERR1;
384  }
385  /* Check for WEP Key size */
386  if( (pstrM2MAPConfig->u8KeySz != WEP_40_KEY_STRING_SIZE) &&
387  (pstrM2MAPConfig->u8KeySz != WEP_104_KEY_STRING_SIZE)
388  )
389  {
390  M2M_ERR("INVALID KEY SIZE\n");
391  s8Ret = M2M_ERR_FAIL;
392  goto ERR1;
393  }
394  /* Check for WEP Key */
395  if((pstrM2MAPConfig->au8WepKey == NULL) || (m2m_strlen((uint8 *)pstrM2MAPConfig->au8WepKey) <= 0) || (m2m_strlen((uint8 *)pstrM2MAPConfig->au8WepKey) > WEP_104_KEY_STRING_SIZE))
396  {
397  M2M_ERR("INVALID WEP KEY\n");
398  s8Ret = M2M_ERR_FAIL;
399  goto ERR1;
400  }
401  }
402  else
403  {
404  M2M_ERR("INVALID AUTHENTICATION MODE\n");
405  s8Ret = M2M_ERR_FAIL;
406  goto ERR1;
407  }
408 
409 ERR1:
410  return s8Ret;
411 }
413 {
414  sint8 s8Ret = M2M_SUCCESS;
415  /* Check for incoming pointer */
416  if(ptstrM2MScanOption == NULL)
417  {
418  M2M_ERR("INVALID POINTER\n");
419  s8Ret = M2M_ERR_FAIL;
420  }
421  else
422  {
423  /* Check for valid No of slots */
424  if(ptstrM2MScanOption->u8NumOfSlot == 0)
425  {
426  M2M_ERR("INVALID No of scan slots!\n");
427  s8Ret = M2M_ERR_FAIL;
428  }
429  /* Check for valid time of slots */
430  if((ptstrM2MScanOption->u8SlotTime < 10) || (ptstrM2MScanOption->u8SlotTime > 250))
431  {
432  M2M_ERR("INVALID scan slot time!\n");
433  s8Ret = M2M_ERR_FAIL;
434  }
435  /* Check for valid No of probe requests per slot */
436  if((ptstrM2MScanOption->u8ProbesPerSlot == 0) || (ptstrM2MScanOption->u8ProbesPerSlot > M2M_SCAN_DEFAULT_NUM_PROBE))
437  {
438  M2M_ERR("INVALID No of probe requests per scan slot\n");
439  s8Ret = M2M_ERR_FAIL;
440  }
441  /* Check for valid RSSI threshold */
442  if(ptstrM2MScanOption->s8RssiThresh >= 0)
443  {
444  M2M_ERR("INVALID RSSI threshold %d \n",ptstrM2MScanOption->s8RssiThresh);
445  s8Ret = M2M_ERR_FAIL;
446  }
447  }
448  return s8Ret;
449 }
450 
452 {
453  sint8 s8Ret = M2M_ERR_FAIL;
454  tstrM2MGainTable strGainTable = {0};
455 
456  strGainTable.u8GainTable = table_idx;
457 
458  s8Ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_SET_GAIN_TABLE, (uint8 *)&strGainTable, sizeof(tstrM2MGainTable), NULL, 0, 0);
459  return s8Ret;
460 }
461 
462 
464 {
465  sint8 ret = M2M_ERR_FAIL;
466 
467  /* Apply device specific initialization. */
468  ret = nm_drv_init_hold(0);
469 
470  return ret;
471 }
473 {
474  tstrM2mRev strtmp;
475  sint8 ret = M2M_SUCCESS;
476 
477  if(param == NULL) {
478  ret = M2M_ERR_FAIL;
479  goto _EXIT0;
480  }
481 
482  gpfAppWifiCb = param->pfAppWifiCb;
483 
484 #ifdef ETH_MODE
485  gpfAppEthCb = param->strEthInitParam.pfAppEthCb;
486  gau8ethRcvBuf = param->strEthInitParam.au8ethRcvBuf;
487  gu16ethRcvBufSize = param->strEthInitParam.u16ethRcvBufSize;
488 #endif
489 
490 #ifdef CONF_MGMT
491  gpfAppMonCb = param->pfAppMonCb;
492 #endif
493 
494  /* Apply device specific initialization. */
495  ret = nm_drv_init_start(NULL);
496  if(ret != M2M_SUCCESS) goto _EXIT0;
497  /* Initialize host interface module */
498  ret = hif_init(NULL);
499  if(ret != M2M_SUCCESS) goto _EXIT1;
500 
502 
504  M2M_INFO("Curr driver HIF Level: (%u) %u.%u\n", M2M_HIF_BLOCK_VALUE, M2M_HIF_MAJOR_VALUE, M2M_HIF_MINOR_VALUE);
505  ret = m2m_wifi_get_firmware_version(&strtmp);
507 
508  if(ret == M2M_SUCCESS)
509  {
510  ret = hif_enable_access();
511  if(ret == M2M_SUCCESS)
512  {
514  }
515  }
516  goto _EXIT0;
517 
518 _EXIT1:
520 _EXIT0:
521  return ret;
522 }
524 {
525  sint8 ret = M2M_SUCCESS;
526 
527  ret = m2m_wifi_init_hold();
528  if (ret == M2M_SUCCESS)
529  {
530  ret = m2m_wifi_init_start(param);
531  }
532  return ret;
533 }
535 {
536 
537  hif_deinit(NULL);
538 
540 
541  return M2M_SUCCESS;
542 }
544 {
546  return m2m_wifi_init_hold();
547 }
549 {
550  return m2m_wifi_init_start(param);
551 }
553 {
554  sint8 ret = M2M_ERR_FAIL;
555  ret = m2m_wifi_reinit_hold();
556  if(ret == M2M_SUCCESS) {
557  ret = m2m_wifi_reinit_start(param);
558  }
559  return ret;
560 }
561 
562 void m2m_wifi_yield(void)
563 {
564  hif_yield();
565 }
566 
568 {
569  return hif_handle_isr();
570 }
571 
573 {
575 }
576 
577 sint8 m2m_wifi_connect(char *pcSsid, uint8 u8SsidLen, uint8 u8SecType, void *pvAuthInfo, uint16 u16Ch)
578 {
579  return m2m_wifi_connect_sc(pcSsid, u8SsidLen, u8SecType, pvAuthInfo, u16Ch,0);
580 }
581 sint8 m2m_wifi_connect_sc(char *pcSsid, uint8 u8SsidLen, uint8 u8SecType, void *pvAuthInfo, uint16 u16Ch, uint8 u8NoSaveCred)
582 {
583  sint8 ret = M2M_SUCCESS;
584  tstrM2mWifiConnect strConnect;
585  tstrM2MWifiSecInfo *pstrAuthInfo;
586 
587  if(u8SecType != M2M_WIFI_SEC_OPEN)
588  {
589  if(pvAuthInfo == NULL)
590  {
591  M2M_ERR("Key is not valid\n");
592  ret = M2M_ERR_FAIL;
593  goto ERR1;
594  }
595  if((u8SecType == M2M_WIFI_SEC_WPA_PSK) && (m2m_strlen(pvAuthInfo) == (M2M_MAX_PSK_LEN-1)))
596  {
597  uint8 i = 0;
598  uint8* pu8Psk = (uint8*)pvAuthInfo;
599  while(i < (M2M_MAX_PSK_LEN-1))
600  {
601  if(pu8Psk[i]<'0' || (pu8Psk[i]>'9' && pu8Psk[i] < 'A')|| (pu8Psk[i]>'F' && pu8Psk[i] < 'a') || pu8Psk[i] > 'f')
602  {
603  M2M_ERR("Invalid Key\n");
604  ret = M2M_ERR_FAIL;
605  goto ERR1;
606  }
607  i++;
608  }
609  }
610  }
611  if((u8SsidLen<=0)||(u8SsidLen>=M2M_MAX_SSID_LEN))
612  {
613  M2M_ERR("SSID LEN INVALID\n");
614  ret = M2M_ERR_FAIL;
615  goto ERR1;
616  }
617 
618  if(u16Ch < M2M_WIFI_CH_1 || u16Ch > M2M_WIFI_CH_14)
619  {
620  if(u16Ch!=M2M_WIFI_CH_ALL)
621  {
622  M2M_ERR("CH INVALID\n");
623  ret = M2M_ERR_FAIL;
624  goto ERR1;
625  }
626  }
627 
628  m2m_memcpy(strConnect.au8SSID, (uint8*)pcSsid, u8SsidLen);
629  strConnect.au8SSID[u8SsidLen] = 0;
630  strConnect.u16Ch = NM_BSP_B_L_16(u16Ch);
631  /* Credentials will be Not be saved if u8NoSaveCred is set */
632  strConnect.u8NoSaveCred = u8NoSaveCred ? 1:0;
633  pstrAuthInfo = &strConnect.strSec;
634  pstrAuthInfo->u8SecType = u8SecType;
635 
636  if(u8SecType == M2M_WIFI_SEC_WEP)
637  {
638  tstrM2mWifiWepParams * pstrWepParams = (tstrM2mWifiWepParams*)pvAuthInfo;
639  tstrM2mWifiWepParams *pstrWep = &pstrAuthInfo->uniAuth.strWepInfo;
640  pstrWep->u8KeyIndx =pstrWepParams->u8KeyIndx-1;
641 
642  if(pstrWep->u8KeyIndx >= WEP_KEY_MAX_INDEX)
643  {
644  M2M_ERR("Invalid Wep key index %d\n", pstrWep->u8KeyIndx);
645  ret = M2M_ERR_FAIL;
646  goto ERR1;
647  }
648  pstrWep->u8KeySz = pstrWepParams->u8KeySz-1;
649  if ((pstrWep->u8KeySz != WEP_40_KEY_STRING_SIZE)&& (pstrWep->u8KeySz != WEP_104_KEY_STRING_SIZE))
650  {
651  M2M_ERR("Invalid Wep key length %d\n", pstrWep->u8KeySz);
652  ret = M2M_ERR_FAIL;
653  goto ERR1;
654  }
655  m2m_memcpy((uint8*)pstrWep->au8WepKey,(uint8*)pstrWepParams->au8WepKey, pstrWepParams->u8KeySz);
656  pstrWep->au8WepKey[pstrWepParams->u8KeySz] = 0;
657 
658  }
659 
660 
661  else if(u8SecType == M2M_WIFI_SEC_WPA_PSK)
662  {
663  uint16 u16KeyLen = m2m_strlen((uint8*)pvAuthInfo);
664  if((u16KeyLen <= 0)||(u16KeyLen >= M2M_MAX_PSK_LEN))
665  {
666  M2M_ERR("Incorrect PSK key length\n");
667  ret = M2M_ERR_FAIL;
668  goto ERR1;
669  }
670  m2m_memcpy(pstrAuthInfo->uniAuth.au8PSK, (uint8*)pvAuthInfo, u16KeyLen + 1);
671  }
672  else if(u8SecType == M2M_WIFI_SEC_802_1X)
673  {
674  m2m_memcpy((uint8*)&pstrAuthInfo->uniAuth.strCred1x, (uint8*)pvAuthInfo, sizeof(tstr1xAuthCredentials));
675  }
676  else if(u8SecType == M2M_WIFI_SEC_OPEN)
677  {
678 
679  }
680  else
681  {
682  M2M_ERR("undefined sec type\n");
683  ret = M2M_ERR_FAIL;
684  goto ERR1;
685  }
686 
687  ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_CONNECT, (uint8*)&strConnect, sizeof(tstrM2mWifiConnect),NULL, 0,0);
688 
689 ERR1:
690  return ret;
691 }
692 
694 {
696 }
698 {
699  tstrM2mSetMacAddress strTmp;
700  m2m_memcpy((uint8*) strTmp.au8Mac, (uint8*) au8MacAddress, 6);
702  (uint8*) &strTmp, sizeof(tstrM2mSetMacAddress), NULL, 0,0);
703 }
704 
706 {
707  pstrStaticIPConf->u32DNS = NM_BSP_B_L_32(pstrStaticIPConf->u32DNS);
708  pstrStaticIPConf->u32Gateway = NM_BSP_B_L_32(pstrStaticIPConf->u32Gateway);
709  pstrStaticIPConf->u32StaticIP = NM_BSP_B_L_32(
710  pstrStaticIPConf->u32StaticIP);
711  pstrStaticIPConf->u32SubnetMask = NM_BSP_B_L_32(
712  pstrStaticIPConf->u32SubnetMask);
714  (uint8*) pstrStaticIPConf, sizeof(tstrM2MIPConfig), NULL, 0,0);
715 }
716 
718 {
719  /*legacy API should be removed */
720  return 0;
721 }
723 {
724  /*legacy API should be removed */
725  return 0;
726 }
739 {
740 
741  uint8 u8Req;
742  u8Req = u8DhcpEn ? M2M_IP_REQ_ENABLE_DHCP : M2M_IP_REQ_DISABLE_DHCP;
743  return hif_send(M2M_REQ_GROUP_IP, u8Req, NULL, 0, NULL, 0, 0);
744 
745 
746 }
747 
749 {
750  return hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_LSN_INT, (uint8*)pstrM2mLsnInt, sizeof(tstrM2mLsnInt), NULL, 0, 0);
751 }
752 
753 sint8 m2m_wifi_set_cust_InfoElement(uint8* pau8M2mCustInfoElement)
754 {
755  return hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_CUST_INFO_ELEMENT, (uint8*)pau8M2mCustInfoElement, pau8M2mCustInfoElement[0]+1, NULL, 0, 0);
756 }
757 
759 {
760  sint8 s8Ret = M2M_ERR_FAIL;
761  if(m2m_validate_scan_options (ptstrM2MScanOption) == M2M_SUCCESS)
762  {
763  s8Ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_SET_SCAN_OPTION, (uint8*)ptstrM2MScanOption, sizeof(tstrM2MScanOption),NULL, 0,0);
764  }
765  return s8Ret;
766 }
768 {
769  sint8 s8Ret = M2M_ERR_FAIL;
770  tstrM2MScanRegion strScanRegion;
771  strScanRegion.u16ScanRegion = ScanRegion;
772  s8Ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_SET_SCAN_REGION, (uint8*)&strScanRegion, sizeof(tstrM2MScanRegion),NULL, 0,0);
773  return s8Ret;
774 }
776 {
777  sint8 s8Ret = M2M_SUCCESS;
778 
779  if(((ch >= M2M_WIFI_CH_1) && (ch <= M2M_WIFI_CH_14)) || (ch == M2M_WIFI_CH_ALL))
780  {
781  tstrM2MScan strtmp;
782  strtmp.u8ChNum = ch;
783  s8Ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_SCAN, (uint8*)&strtmp, sizeof(tstrM2MScan),NULL, 0,0);
784  }
785  else
786  {
787  s8Ret = M2M_ERR_INVALID_ARG;
788  }
789  return s8Ret;
790 }
791 
793 {
794  sint8 s8Ret = M2M_SUCCESS;
795 
796  if(((ch >= M2M_WIFI_CH_1) && (ch <= M2M_WIFI_CH_14)) || (ch == M2M_WIFI_CH_ALL))
797  {
798  tstrM2MScan strtmp;
799  strtmp.u8ChNum = ch;
800 
801  s8Ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_PASSIVE_SCAN, (uint8*)&strtmp, sizeof(tstrM2MScan),NULL, 0,0);
802  }
803  else
804  {
805  s8Ret = M2M_ERR_INVALID_ARG;
806  }
807  return s8Ret;
808 }
809 sint8 m2m_wifi_wps(uint8 u8TriggerType,const char *pcPinNumber)
810 {
811  tstrM2MWPSConnect strtmp;
812 
813  strtmp.u8TriggerType = u8TriggerType;
814  /*If WPS is using PIN METHOD*/
815  if (u8TriggerType == WPS_PIN_TRIGGER)
816  m2m_memcpy ((uint8*)strtmp.acPinNumber,(uint8*) pcPinNumber,8);
817  return hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_WPS, (uint8*)&strtmp,sizeof(tstrM2MWPSConnect), NULL, 0,0);
818 }
819 
821 {
822  sint8 ret = M2M_SUCCESS;
824  return ret;
825 }
826 
827 #if 0
828 /*
829  * These two functions m2m_wifi_req_client_ctrl and m2m_wifi_req_server_init are for a mode in which two WINC ICs
830  * communicate with each other via probe request and probe response frames. This mode is not supported in WINC fw.
831  */
832 sint8 m2m_wifi_req_client_ctrl(uint8 u8Cmd)
833 {
834 
835  sint8 ret = M2M_SUCCESS;
836 #ifdef _PS_SERVER_
837  tstrM2Mservercmd strCmd;
838  strCmd.u8cmd = u8Cmd;
840 #else
841  M2M_ERR("_PS_SERVER_ is not defined\n");
842 #endif
843  return ret;
844 }
845 sint8 m2m_wifi_req_server_init(uint8 ch)
846 {
847  sint8 ret = M2M_SUCCESS;
848 #ifdef _PS_SERVER_
849  tstrM2mServerInit strServer;
850  strServer.u8Channel = ch;
852 #else
853  M2M_ERR("_PS_SERVER_ is not defined\n");
854 #endif
855  return ret;
856 }
857 #endif
858 
860 {
861  sint8 ret = M2M_SUCCESS;
862  if((u8Channel == M2M_WIFI_CH_1) || (u8Channel == M2M_WIFI_CH_6) || (u8Channel == M2M_WIFI_CH_11))
863  {
864  tstrM2MP2PConnect strtmp;
865  strtmp.u8ListenChannel = u8Channel;
867  }
868  else
869  {
870  M2M_ERR("Listen channel should only be 1, 6 or 11\n");
871  ret = M2M_ERR_FAIL;
872  }
873  return ret;
874 }
876 {
877  sint8 ret = M2M_SUCCESS;
879  return ret;
880 }
882 {
883  sint8 ret = M2M_ERR_FAIL;
884  if(M2M_SUCCESS == m2m_validate_ap_parameters(pstrM2MAPConfig))
885  {
886  ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_ENABLE_AP, (uint8 *)pstrM2MAPConfig, sizeof(tstrM2MAPConfig), NULL, 0, 0);
887  }
888  return ret;
889 }
891 {
892  sint8 ret = M2M_SUCCESS;
894  return ret;
895 }
904 {
905  sint8 ret = M2M_SUCCESS;
907  return ret;
908 }
909 
911 {
912  sint8 ret = M2M_SUCCESS;
914  return ret;
915 }
916 
918 {
919  sint8 ret = M2M_SUCCESS;
921  return ret;
922 }
923 
924 sint8 m2m_wifi_send_ethernet_pkt(uint8* pu8Packet,uint16 u16PacketSize)
925 {
926  sint8 s8Ret = -1;
927  if((pu8Packet != NULL)&&(u16PacketSize>0))
928  {
929  tstrM2MWifiTxPacketInfo strTxPkt;
930 
931  strTxPkt.u16PacketSize = u16PacketSize;
934  (uint8*)&strTxPkt, sizeof(tstrM2MWifiTxPacketInfo), pu8Packet, u16PacketSize, M2M_ETHERNET_HDR_OFFSET - M2M_HIF_HDR_OFFSET);
935  }
936  return s8Ret;
937 }
952 {
953  sint8 ret = M2M_SUCCESS;
954  ret = hif_chip_wake();
955  if(ret == M2M_SUCCESS)
956  {
957  ret = nmi_get_otp_mac_address(pu8MacAddr, pu8IsValid);
958  if(ret == M2M_SUCCESS)
959  {
960  ret = hif_chip_sleep();
961  }
962  }
963  return ret;
964 }
976 {
977  sint8 ret = M2M_SUCCESS;
978  ret = hif_chip_wake();
979  if(ret == M2M_SUCCESS)
980  {
981  ret = nmi_get_mac_address(pu8MacAddr);
982  if(ret == M2M_SUCCESS)
983  {
984  ret = hif_chip_sleep();
985  }
986  }
987 
988  return ret;
989 }
1008 {
1009  sint8 ret = M2M_SUCCESS;
1010  tstrM2mReqScanResult strReqScanRlt;
1011  strReqScanRlt.u8Index = index;
1012  ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_SCAN_RESULT, (uint8*) &strReqScanRlt, sizeof(tstrM2mReqScanResult), NULL, 0, 0);
1013  return ret;
1014 }
1028 {
1029  return gu8ChNum;
1030 }
1038 {
1039  return hif_get_sleep_mode();
1040 }
1056 {
1057  sint8 ret = M2M_SUCCESS;
1058  tstrM2mPsType strPs;
1059  strPs.u8PsType = PsTyp;
1060  strPs.u8BcastEn = BcastEn;
1061  ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_SLEEP, (uint8*) &strPs,sizeof(tstrM2mPsType), NULL, 0, 0);
1062  M2M_INFO("POWER SAVE %d\n",PsTyp);
1063  hif_set_sleep_mode(PsTyp);
1064  return ret;
1065 }
1076 {
1077  sint8 ret = M2M_SUCCESS;
1078  uint8 psType;
1079  psType = hif_get_sleep_mode();
1080  if(psType == M2M_PS_MANUAL)
1081  {
1082  tstrM2mSlpReqTime strPs;
1083  strPs.u32SleepTime = u32SlpReqTime;
1084  ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_DOZE, (uint8*) &strPs,sizeof(tstrM2mSlpReqTime), NULL, 0, 0);
1085  }
1086  return ret;
1087 }
1098 sint8 m2m_wifi_set_device_name(uint8 *pu8DeviceName, uint8 u8DeviceNameLength)
1099 {
1100  tstrM2MDeviceNameConfig strDeviceName;
1101  if(u8DeviceNameLength >= M2M_DEVICE_NAME_MAX)
1102  {
1103  u8DeviceNameLength = M2M_DEVICE_NAME_MAX;
1104  }
1105  //pu8DeviceName[u8DeviceNameLength] = '\0';
1106  u8DeviceNameLength ++;
1107  m2m_memcpy(strDeviceName.au8DeviceName, pu8DeviceName, u8DeviceNameLength);
1109  (uint8*)&strDeviceName, sizeof(tstrM2MDeviceNameConfig), NULL, 0,0);
1110 }
1122 {
1123  return nmi_get_chipid();
1124 }
1138 {
1139  sint8 ret = M2M_SUCCESS;
1140  ret = hif_chip_wake();
1141  if(ret == M2M_SUCCESS)
1142  {
1143  ret = nm_get_firmware_full_info(pstrRev);
1144  hif_chip_sleep();
1145  }
1146  return ret;
1147 }
1160 {
1161  sint8 ret = M2M_SUCCESS;
1162  uint16 ota_hif_info = 0;
1163 
1164  ret = nm_get_hif_info(NULL, &ota_hif_info);
1165  if(ret == M2M_SUCCESS)
1166  {
1167  ret = hif_check_compatibility(ota_hif_info);
1168  }
1169  return ret;
1170 }
1187 {
1188  sint8 ret = M2M_SUCCESS;
1189  ret = hif_chip_wake();
1190  if(ret == M2M_SUCCESS)
1191  {
1192  ret = nm_get_ota_firmware_info(pstrRev);
1193  hif_chip_sleep();
1194  }
1195  return ret;
1196 }
1197 #ifdef CONF_MGMT
1199  uint16 u16BufferSize, uint16 u16DataOffset)
1200 {
1201  sint8 s8Ret = -1;
1202  if((pstrMtrCtrl->u8ChannelID >= M2M_WIFI_CH_1) && (pstrMtrCtrl->u8ChannelID <= M2M_WIFI_CH_14))
1203  {
1204  gstrMgmtCtrl.pu8Buf = pu8PayloadBuffer;
1205  gstrMgmtCtrl.u16Sz = u16BufferSize;
1206  gstrMgmtCtrl.u16Offset = u16DataOffset;
1208  (uint8*)pstrMtrCtrl, sizeof(tstrM2MWifiMonitorModeCtrl), NULL, 0,0);
1209  }
1210  return s8Ret;
1211 }
1213 {
1215 }
1216 
1217 sint8 m2m_wifi_send_wlan_pkt(uint8 *pu8WlanPacket, uint16 u16WlanHeaderLength, uint16 u16WlanPktSize)
1218 {
1219  sint8 s8Ret = -1;
1220  if(pu8WlanPacket != NULL)
1221  {
1222  tstrM2MWifiTxPacketInfo strTxPkt;
1223 
1224  strTxPkt.u16PacketSize = u16WlanPktSize;
1225  strTxPkt.u16HeaderLength = u16WlanHeaderLength;
1227  (uint8*)&strTxPkt, sizeof(tstrM2MWifiTxPacketInfo), pu8WlanPacket, u16WlanPktSize, sizeof(tstrM2MWifiTxPacketInfo));
1228  }
1229  return s8Ret;
1230 }
1231 #endif
1232 
1233 sint8 m2m_wifi_start_provision_mode(tstrM2MAPConfig *pstrAPConfig, char *pcHttpServerDomainName, uint8 bEnableHttpRedirect)
1234 {
1235  sint8 s8Ret = M2M_ERR_FAIL;
1236 
1237  if((pstrAPConfig != NULL))
1238  {
1239  tstrM2MProvisionModeConfig strProvConfig;
1240  if(M2M_SUCCESS == m2m_validate_ap_parameters(pstrAPConfig))
1241  {
1242  m2m_memcpy((uint8*)&strProvConfig.strApConfig, (uint8*)pstrAPConfig, sizeof(tstrM2MAPConfig));
1243  if((m2m_strlen((uint8 *)pcHttpServerDomainName) <= 0) || (NULL == pcHttpServerDomainName))
1244  {
1245  M2M_ERR("INVALID DOMAIN NAME\n");
1246  goto ERR1;
1247  }
1248  m2m_memcpy((uint8*)strProvConfig.acHttpServerDomainName, (uint8*)pcHttpServerDomainName, 64);
1249  strProvConfig.u8EnableRedirect = bEnableHttpRedirect;
1250 
1252  (uint8*)&strProvConfig, sizeof(tstrM2MProvisionModeConfig), NULL, 0, 0);
1253  }
1254  else
1255  {
1256  /*goto ERR1;*/
1257  }
1258  }
1259 ERR1:
1260  return s8Ret;
1261 }
1262 
1264 {
1266 }
1267 
1269 {
1271 }
1272 
1274 {
1275  return hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_SET_SYS_TIME, (uint8*)&u32UTCSeconds, sizeof(tstrSystemTime), NULL, 0, 0);
1276 }
1286 {
1288 }
1289 
1291 {
1292  uint8 u8Req;
1293 
1295  return hif_send(M2M_REQ_GROUP_WIFI, u8Req, NULL, 0, NULL, 0, 0);
1296 }
1309 {
1310  sint8 ret = M2M_SUCCESS;
1311  tstrM2mPwrMode strM2mPwrMode;
1312  strM2mPwrMode.u8PwrMode = u8PwrMode;
1313  ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_SET_POWER_PROFILE, (uint8*)&strM2mPwrMode,sizeof(tstrM2mPwrMode), NULL, 0, 0);
1314  return ret;
1315 }
1327 {
1328  sint8 ret = M2M_SUCCESS;
1329  tstrM2mTxPwrLevel strM2mTxPwrLevel;
1330  strM2mTxPwrLevel.u8TxPwrLevel = u8TxPwrLevel;
1331  ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_SET_TX_POWER, (uint8*)&strM2mTxPwrLevel,sizeof(tstrM2mTxPwrLevel), NULL, 0, 0);
1332  return ret;
1333 }
1334 
1347 {
1348  sint8 ret = M2M_SUCCESS;
1349  tstrM2mEnableLogs strM2mEnableLogs;
1350  strM2mEnableLogs.u8Enable = u8Enable;
1351  ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_SET_ENABLE_LOGS, (uint8*)&strM2mEnableLogs,sizeof(tstrM2mEnableLogs), NULL, 0, 0);
1352  return ret;
1353 }
1354 
1367 {
1368  sint8 ret = M2M_SUCCESS;
1369  tstrM2mBatteryVoltage strM2mBattVol = {0};
1370  strM2mBattVol.u16BattVolt = u16BattVoltx100;
1372  return ret;
1373 }
1384 {
1385  sint8 ret = M2M_ERR_FAIL;
1386  tstrPrng strRng = {0};
1387  if((u16PrngSize < (M2M_BUFFER_MAX_SIZE - sizeof(tstrPrng)))&&(pu8PrngBuff != NULL))
1388  {
1389  strRng.u16PrngSize = u16PrngSize;
1390  strRng.pu8RngBuff = pu8PrngBuff;
1392  }
1393  else
1394  {
1395  M2M_ERR("PRNG Buffer exceeded maximum size %d or NULL Buffer\n",u16PrngSize);
1396  }
1397  return ret;
1398 }
1399 #ifdef ETH_MODE
1400 
1415 NMI_API sint8 m2m_wifi_enable_mac_mcast(uint8* pu8MulticastMacAddress, uint8 u8AddRemove)
1416 {
1417  sint8 s8ret = M2M_ERR_FAIL;
1418  tstrM2MMulticastMac strMulticastMac;
1419 
1420  if(pu8MulticastMacAddress != NULL )
1421  {
1422  strMulticastMac.u8AddRemove = u8AddRemove;
1423  m2m_memcpy(strMulticastMac.au8macaddress,pu8MulticastMacAddress,M2M_MAC_ADDRES_LEN);
1424  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]);
1425  s8ret = hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_SET_MAC_MCAST, (uint8 *)&strMulticastMac,sizeof(tstrM2MMulticastMac),NULL,0,0);
1426  }
1427 
1428  return s8ret;
1429 
1430 }
1431 
1447 NMI_API sint8 m2m_wifi_set_receive_buffer(void* pvBuffer,uint16 u16BufferLen)
1448 {
1449  sint8 s8ret = M2M_SUCCESS;
1450  if(pvBuffer != NULL)
1451  {
1452  gau8ethRcvBuf = pvBuffer;
1453  gu16ethRcvBufSize= u16BufferLen;
1454  }
1455  else
1456  {
1457  s8ret = M2M_ERR_FAIL;
1458  M2M_ERR("Buffer NULL pointer\r\n");
1459  }
1460  return s8ret;
1461 }
1462 #endif
1463 
1480 {
1481  tstrM2mBleApiMsg bleTx;
1482  bleTx.u16Len = len;
1484  (uint8*)&bleTx, sizeof(tstrM2mBleApiMsg), msg, len, sizeof(tstrM2mBleApiMsg));
1485 }
sint8 enable_interrupts(void)
Definition: nmasic.c:213
sint8 nm_drv_init_download_mode(uint32 req_serial_number)
Definition: nmdrv.c:224
sint8 nm_drv_init_hold(uint32 req_serial_number)
Definition: nmdrv.c:249
NMI_API void m2m_memcpy(uint8 *pDst, uint8 *pSrc, uint32 sz)
Copy specified number of bytes from source buffer to destination buffer.
Definition: nm_common.c:36
M2M Request PRNG.
Definition: m2m_types.h:2206
This struct contains the Wi-Fi scan request.
Definition: m2m_types.h:1324
#define M2M_ERR_FAIL
Definition: nm_common.h:63
sint8 hif_chip_wake(void)
To Wakeup the chip.
Definition: m2m_hif.c:167
This struct contains the information for the PS Server command.
Definition: m2m_types.h:1622
sint8 m2m_wifi_reinit_start(tstrWifiInitParam *param)
Second part of m2m_wifi_reinit, continuing from where m2m_wifi_reinit_hold left off.
Definition: m2m_wifi.c:548
sint8 m2m_wifi_connect(char *pcSsid, uint8 u8SsidLen, uint8 u8SecType, void *pvAuthInfo, uint16 u16Ch)
Asynchronous API to request connection to a specified access point.
Definition: m2m_wifi.c:577
sint8 m2m_wifi_req_scan_result(uint8 index)
Asynchronous API to request the information of an access point discovered via scanning.
Definition: m2m_wifi.c:1007
sint8 nm_get_firmware_full_info(tstrM2mRev *pstrRev)
Get Firmware version info.
Definition: nmdrv.c:81
NMI_API sint8 m2m_wifi_ble_api_send(uint8 *msg, uint32 len)
Definition: m2m_wifi.c:1479
sint8 m2m_wifi_set_sleep_mode(uint8 PsTyp, uint8 BcastEn)
Synchronous API to set the power-save mode of the WINC IC.
Definition: m2m_wifi.c:1055
#define M2M_ETHERNET_HDR_OFFSET
Definition: m2m_types.h:179
This struct contains the Device Name of the WINC. It is used mainly for Wi-Fi Direct device discovery...
Definition: m2m_types.h:1656
#define WEP_KEY_MAX_INDEX
Definition: m2m_types.h:255
This struct contains the MAC address to be used. The WINC loads the mac address from the efuse by def...
Definition: m2m_types.h:1641
#define WEP_104_KEY_STRING_SIZE
Definition: m2m_types.h:252
sint8 nm_get_hif_info(uint16 *pu16FwHifInfo, uint16 *pu16OtaHifInfo)
Get Hif info of images in both partitions (Firmware and Ota).
Definition: nmdrv.c:55
#define M2M_HIF_BLOCK_VALUE
Definition: m2m_types.h:133
signed char sint8
Range of values between -128 to 127.
Definition: nm_bsp.h:111
sint8 nmi_get_otp_mac_address(uint8 *pu8MacAddr, uint8 *pu8IsValid)
Definition: nmasic.c:687
sint8 m2m_wifi_set_power_profile(uint8 u8PwrMode)
Change the power profile mode.
Definition: m2m_wifi.c:1308
sint8 m2m_wifi_set_battery_voltage(uint16 u16BattVoltx100)
Enable or Disable logs in run time (Disable Firmware logs will enhance the firmware start-up time and...
Definition: m2m_wifi.c:1366
sint8 m2m_wifi_disable_ap(void)
Synchronous API to disable access point mode on the WINC IC.
Definition: m2m_wifi.c:890
sint8 m2m_wifi_set_scan_options(tstrM2MScanOption *ptstrM2MScanOption)
Synchronous API for configuring the behaviour of the WINC IC&#39;s network scanning functions.
Definition: m2m_wifi.c:758
This struct contains the Wi-Fi TX Packet Info. The M2M Application has the ability to compose raw Wi-...
Definition: m2m_types.h:1534
This struct stores the WPS configuration parameters.
Definition: m2m_types.h:1168
uint8 u8PsType
Definition: m2m_types.h:1420
static void m2m_wifi_cb(uint8 u8OpCode, uint16 u16DataSize, uint32 u32Addr)
Definition: m2m_wifi.c:80
tstrEthInitParam strEthInitParam
Definition: m2m_wifi.h:401
sint8 m2m_wifi_start_provision_mode(tstrM2MAPConfig *pstrAPConfig, char *pcHttpServerDomainName, uint8 bEnableHttpRedirect)
Asynchronous API for control of Wi-Fi provisioning functionality.
Definition: m2m_wifi.c:1233
This struct contains the Wi-Fi scan result.
Definition: m2m_types.h:1339
#define BYTE_0(word)
Definition: nm_common.h:129
sint8 m2m_wifi_wps(uint8 u8TriggerType, const char *pcPinNumber)
Asynchronous API to engage the WINC IC&#39;s Wi-Fi Protected Setup (enrolee) function.
Definition: m2m_wifi.c:809
void hif_yield(void)
Yields control from interrupt event handler.
Definition: m2m_hif.c:711
This struct contains the information for the PS Server initialization.
Definition: m2m_types.h:1592
sint8 m2m_wifi_request_dhcp_client(void)
Legacy (deprecated) Asynchronous API for starting a DHCP client on the WINC IC.
Definition: m2m_wifi.c:717
sint8 hif_handle_isr(void)
Handle interrupt received from NMC1500 firmware.
Definition: m2m_hif.c:716
#define BYTE_3(word)
Definition: nm_common.h:135
uint32 u32Gateway
Definition: m2m_types.h:1675
#define malloc
Definition: m2m_wifi.c:40
sint8 m2m_wifi_deinit(void *arg)
Synchronous API that de-initialises the WINC driver.
Definition: m2m_wifi.c:534
This struct stores the credentials for the user to authenticate with the AAA server (WPA-Enterprise M...
Definition: m2m_types.h:1088
tpfAppMonCb pfAppMonCb
Definition: m2m_wifi.h:400
static sint8 m2m_validate_scan_options(tstrM2MScanOption *ptstrM2MScanOption)
Definition: m2m_wifi.c:412
uint32 u32SubnetMask
Definition: m2m_types.h:1679
Structure, holding the Wi-fi configuration attributes such as the wi-fi callback , monitoring mode callback and Ethernet parameter initialization structure. Such configuration parameters are required to be set before calling the wi-fi initialization function m2m_wifi_init. pfAppWifiCb attribute must be set to handle the wi-fi callback operations. pfAppMonCb attribute, is optional based on whether the application requires the monitoring mode configuration, and can there not be set before the initialization. strEthInitParam structure, is another optional configuration based on whether the bypass mode is set.
Definition: m2m_wifi.h:398
This struct contains the Wi-Fi RX Frame Header. The M2M application has the ability to allow Wi-Fi mo...
Definition: m2m_types.h:1494
This struct contains the information corresponding to an AP in the scan result list identified by its...
Definition: m2m_types.h:1371
#define M2M_HIF_HDR_OFFSET
Definition: m2m_hif.h:56
This struct contains the Wi-Fi information for the channel regions.
Definition: m2m_types.h:1306
#define M2M_SUCCESS
Definition: nm_common.h:51
uint16 u16PrngSize
Definition: m2m_types.h:2210
char acPinNumber[8]
Definition: m2m_types.h:1171
sint8 m2m_wifi_get_mac_address(uint8 *pu8MacAddr)
Synchronous API to retrieve the MAC address currently in use on the device.
Definition: m2m_wifi.c:975
#define NM_BSP_B_L_16(x)
Definition: nm_bsp.h:241
sint8 m2m_wifi_request_sleep(uint32 u32SlpReqTime)
Asynchronous API to place the WINC IC into sleep mode for a specified period of time.
Definition: m2m_wifi.c:1075
tstrM2MAPConfig strApConfig
Definition: m2m_types.h:1708
This struct contains a BLE message.
Definition: m2m_types.h:1775
sint8 m2m_wifi_set_device_name(uint8 *pu8DeviceName, uint8 u8DeviceNameLength)
Asynchronous API to set the Wi-Fi Direct "Device Name" of the WINC IC.
Definition: m2m_wifi.c:1098
#define CONST
Definition: nm_bsp.h:49
This struct contains the provisioning information obtained from the HTTP Provisioning server...
Definition: m2m_types.h:1730
tpfAppEthCb pfAppEthCb
Definition: m2m_wifi.h:352
#define NULL
Definition: nm_bsp.h:52
sint8 m2m_wifi_p2p_disconnect(void)
Synchronous API to disable Wi-Fi Direct (P2P) Mode on the WINC IC.
Definition: m2m_wifi.c:875
This struct contains the information from the Multicast filter.
Definition: m2m_types.h:1816
sint8 hif_init(void *arg)
To initialize HIF layer.
Definition: m2m_hif.c:266
sint8 m2m_wifi_req_curr_rssi(void)
Asynchronous API to request the current Receive Signal Strength (RSSI) of the current connection...
Definition: m2m_wifi.c:903
This struct contains the Wi-Fi Monitor Mode Filter. It sets the filtering criteria for WLAN packets w...
Definition: m2m_types.h:1465
This struct contains the Listen Interval. It is the value of the Wi-Fi StA Listen Interval when power...
Definition: m2m_types.h:1449
NMI_API sint8 m2m_wifi_enable_monitoring_mode(tstrM2MWifiMonitorModeCtrl *pstrMtrCtrl, uint8 *pu8PayloadBuffer, uint16 u16BufferSize, uint16 u16DataOffset)
Asynchronous call to enable Wi-Fi monitoring (promiscuous receive) mode.
unsigned short uint16
Range of values between 0 to 65535.
Definition: nm_bsp.h:96
void m2m_wifi_yield(void)
Yield from processing more synchronous M2M events.
Definition: m2m_wifi.c:562
#define M2M_MAX_PSK_LEN
Definition: m2m_types.h:194
uint8 au8WepKey[WEP_104_KEY_STRING_SIZE+1]
Definition: m2m_types.h:1074
sint8 m2m_wifi_init_hold(void)
First part of m2m_wifi_init, up to the point of initializing spi for flash access.
Definition: m2m_wifi.c:463
uint16 u16ScanRegion
Definition: m2m_types.h:1307
void(* tpfAppWifiCb)(uint8 u8MsgType, void *pvMsg)
This is the main callback function for the Wi-Fi driver and is responsible for processing any M2M_WIF...
Definition: m2m_wifi.h:271
sint8 hif_check_compatibility(uint16 u16HifInfo)
To check the compatibility of an image with the current driver.
Definition: m2m_hif.c:327
#define BYTE_1(word)
Definition: nm_common.h:131
WINC3400 IoT Application Interface.
This struct contains the sleep time for the Power Save request.
Definition: m2m_types.h:1436
This struct contains the provisioning mode configuration.
Definition: m2m_types.h:1707
uint16 u16DataSize
Definition: m2m_wifi.h:380
sint8 m2m_wifi_check_ota_rb(void)
Synchronous API to check presence and compatibility of the WINC image that is stored in the inactive ...
Definition: m2m_wifi.c:1159
This struct contains the Wi-Fi connection state.
Definition: m2m_types.h:1399
This struct stores logging information.
Definition: m2m_types.h:1040
#define NM_BSP_B_L_32(x)
Definition: nm_bsp.h:239
sint8 m2m_wifi_connect_sc(char *pcSsid, uint8 u8SsidLen, uint8 u8SecType, void *pvAuthInfo, uint16 u16Ch, uint8 u8NoSaveCred)
Asynchronous API to request connection to a specific AP with option to store credentials in flash...
Definition: m2m_wifi.c:581
uint8 * au8ethRcvBuf
Definition: m2m_wifi.h:353
This struct contains the connection information.
Definition: m2m_types.h:1753
This struct stores the authentication credentials to connect to a Wi-Fi network.
Definition: m2m_types.h:1126
sint8 m2m_wifi_enable_firmware_logs(uint8 u8Enable)
Enable or Disable logs in run time (Disable Firmware logs will enhance the firmware start-up time and...
Definition: m2m_wifi.c:1346
uint8 au8macaddress[M2M_MAC_ADDRES_LEN]
Definition: m2m_types.h:1817
#define M2M_DBG(...)
Definition: nm_debug.h:81
sint8 m2m_wifi_reinit_hold(void)
First part of m2m_wifi_reinit, up to the point of initializing spi for flash access.
Definition: m2m_wifi.c:543
sint8 hif_register_cb(uint8 u8Grp, tpfHifCallBack fn)
Definition: m2m_hif.c:839
sint8 m2m_wifi_get_firmware_version(tstrM2mRev *pstrRev)
Synchronous API to obtain the firmware version currently running on the WINC IC.
Definition: m2m_wifi.c:1137
sint8 m2m_wifi_send_ethernet_pkt(uint8 *pu8Packet, uint16 u16PacketSize)
Asynchronous API to queue an Ethernet packet for transmission by the WINC IC.
Definition: m2m_wifi.c:924
sint8 m2m_wifi_enable_dhcp(uint8 u8DhcpEn)
Asynchronous function to control the DHCP client functionality within the WINC IC.
Definition: m2m_wifi.c:738
tuniM2MWifiAuth uniAuth
Definition: m2m_types.h:1127
sint8 m2m_wifi_set_mac_address(uint8 au8MacAddress[6])
Synchronous API for assigning a MAC address to the WINC IC.
Definition: m2m_wifi.c:697
#define M2M_BUFFER_MAX_SIZE
Definition: m2m_types.h:170
#define M2M_SCAN_DEFAULT_NUM_PROBE
Definition: m2m_types.h:267
static tpfAppWifiCb gpfAppWifiCb
Definition: m2m_wifi.c:44
This module contains WINC3400 ASIC specific internal APIs.
This struct contains the response error of m2m_default_connect.
Definition: m2m_types.h:1243
uint32 m2m_wifi_get_chipId(void)
Synchronous API to obtain the firmware WINC chip ID.
Definition: m2m_wifi.c:1121
This struct contains the Power Save configuration.
Definition: m2m_types.h:1419
sint8 m2m_wifi_request_dhcp_server(uint8 *addr)
Legacy (deprecated) Asynchronous function to start a DHCP client on the WINC IC.
Definition: m2m_wifi.c:722
tpfAppWifiCb pfAppWifiCb
Definition: m2m_wifi.h:399
This struct contains the static IP configuration.
Definition: m2m_types.h:1672
sint8 m2m_wifi_request_scan(uint8 ch)
Asynchronous API to request the WINC IC perform a scan for networks.
Definition: m2m_wifi.c:775
sint8 nm_get_ota_firmware_info(tstrM2mRev *pstrRev)
Get Firmware version info.
Definition: nmdrv.c:151
NMI_API void m2m_memset(uint8 *pBuf, uint8 val, uint32 sz)
Set specified number of data bytes in specified data buffer to specified value.
Definition: nm_common.c:58
This struct stores the WEP security key parameters.
Definition: m2m_types.h:1069
tstrM2mWifiWepParams strWepInfo
Definition: m2m_types.h:1111
#define M2M_MAC_ADDRES_LEN
Definition: m2m_types.h:175
sint8 m2m_wifi_set_static_ip(tstrM2MIPConfig *pstrStaticIPConf)
Synchronous API to manually assign a (static) IP address to the WINC IC.
Definition: m2m_wifi.c:705
sint8 m2m_wifi_download_mode()
Synchronous API that prepares the WINC IC to enter firmware or certificate download mode...
Definition: m2m_wifi.c:322
uint16 u16RemainigDataSize
Definition: m2m_wifi.h:381
uint8 m2m_wifi_get_num_ap_found(void)
Synchronous API to retrieve the number of AP&#39;s found during the last scan operation.
Definition: m2m_wifi.c:1027
NMI_API uint16 m2m_strlen(uint8 *pcStr)
Returns the string length of a null terminated string buffer.
Definition: nm_common.c:68
#define BYTE_2(word)
Definition: nm_common.h:133
This struct contains the information of the gain table index from flash to be used.
Definition: m2m_types.h:1832
sint8 m2m_wifi_init_start(tstrWifiInitParam *param)
Second part of m2m_wifi_init, continuing from where m2m_wifi_init_hold left off.
Definition: m2m_wifi.c:472
sint8 m2m_wifi_handle_events(void *arg)
Synchronous M2M event handler function.
Definition: m2m_wifi.c:567
#define M2M_ERR(...)
Definition: nm_debug.h:80
sint8 m2m_wifi_req_unrestrict_ble(void)
Asynchronous API to request un-restricting of BLE functionality by reverting the BLE processor to ful...
Definition: m2m_wifi.c:917
#define M2M_DRIVER_VERSION_MAJOR_NO
Definition: m2m_types.h:153
Structure holding the incoming buffer&#39;s data size information, indicating the data size of the buff...
Definition: m2m_wifi.h:379
sint8 m2m_wifi_request_scan_passive(uint8 ch)
Definition: m2m_wifi.c:792
#define M2M_HIF_MAJOR_VALUE
Definition: m2m_types.h:136
sint8 m2m_wifi_default_connect(void)
Asynchronous API that attempts to reconnect to the last-associated access point.
Definition: m2m_wifi.c:572
sint8 m2m_wifi_set_tx_power(uint8 u8TxPwrLevel)
set the TX power tenuM2mTxPwrLevel
Definition: m2m_wifi.c:1326
uint8 u8ChNum
Definition: m2m_types.h:1325
sint8 m2m_wifi_prng_get_random_bytes(uint8 *pu8PrngBuff, uint16 u16PrngSize)
Get random bytes using the PRNG bytes.
Definition: m2m_wifi.c:1383
sint8 m2m_wifi_get_otp_mac_address(uint8 *pu8MacAddr, uint8 *pu8IsValid)
Synchronous API to query the MAC address programmed into the WINC ICs OTP memory. ...
Definition: m2m_wifi.c:951
NMI_API sint8 m2m_wifi_set_receive_buffer(void *pvBuffer, uint16 u16BufferLen)
Asynchronous API to set or change the size of the WINC IC&#39;s receive buffer.
uint8 au8DeviceName[M2M_DEVICE_NAME_MAX]
Definition: m2m_types.h:1657
This struct contains the system time.
Definition: m2m_types.h:1789
void(* tpfAppEthCb)(uint8 u8MsgType, void *pvMsg, void *pvCtrlBuf)
Ethernet (Bypass mode) notification callback function receiving Bypass mode events as defined in the ...
Definition: m2m_wifi.h:300
#define M2M_HIF_MINOR_VALUE
Definition: m2m_types.h:139
uint8 GainTableIndex
Definition: m2m_wifi.h:402
#define M2M_ERR_INVALID_ARG
Definition: nm_common.h:69
This struct contains the Listen Channel for P2P connect.
Definition: m2m_types.h:1549
static sint8 m2m_validate_ap_parameters(CONST tstrM2MAPConfig *pstrM2MAPConfig)
Definition: m2m_wifi.c:337
The Wi-Fi Scan results list is stored in firmware. This struct contains the index by which the applic...
Definition: m2m_types.h:1356
sint8 m2m_wifi_stop_provision_mode(void)
Synchronous API for terminating provisioning mode on the WINC IC.
Definition: m2m_wifi.c:1263
uint8 au8PSK[M2M_MAX_PSK_LEN]
Definition: m2m_types.h:1107
sint8 hif_enable_access(void)
To enable access to HIF layer, based on HIF level of Firmware. This function reads HIF level directly...
Definition: m2m_hif.c:343
sint8 hif_send(uint8 u8Gid, uint8 u8Opcode, uint8 *pu8CtrlBuf, uint16 u16CtrlBufSize, uint8 *pu8DataBuf, uint16 u16DataSize, uint16 u16DataOffset)
Send packet using host interface.
Definition: m2m_hif.c:439
NMI_API sint8 m2m_wifi_disable_monitoring_mode(void)
Asynchronous API to disable Wi-Fi monitoring (promiscuous receive) mode.
uint32 nmi_get_chipid(void)
Definition: nmasic.c:278
This struct stores the Wi-Fi connect request.
Definition: m2m_types.h:1144
sint8 m2m_wifi_set_scan_region(uint16 ScanRegion)
Synchronous API for configuring the regulatory restrictions that may affect the WINC ICs scanning beh...
Definition: m2m_wifi.c:767
tstrM2MWifiSecInfo strSec
Definition: m2m_types.h:1145
#define M2M_DRIVER_VERSION_MINOR_NO
Definition: m2m_types.h:156
sint8 nm_drv_deinit(void *arg)
Definition: nmdrv.c:370
This struct contains response when the firmware has failed to configure the gains from flash...
Definition: m2m_types.h:1846
uint16 u16ethRcvBufSize
Definition: m2m_wifi.h:354
WPS Result.
Definition: m2m_types.h:1191
This struct contains the configuration options for Wi-Fi scan.
Definition: m2m_types.h:1261
#define M2M_INFO(...)
Definition: nm_debug.h:83
void(* tpfAppMonCb)(tstrM2MWifiRxPacketInfo *pstrWifiRxPacket, uint8 *pu8Payload, uint16 u16PayloadSize)
Wi-Fi monitoring mode callback function. This function delivers all received wi-Fi packets to the app...
Definition: m2m_wifi.h:330
uint16 u16PktOffset
Definition: m2m_types.h:1694
uint8 hif_get_sleep_mode(void)
Get the sleep mode of the HIF layer.
Definition: m2m_hif.c:216
unsigned long uint32
Range of values between 0 to 4294967295.
Definition: nm_bsp.h:103
sint8 nm_drv_init_start(void *arg)
Definition: nmdrv.c:291
This struct contains the size and data offset for the received packet.
Definition: m2m_types.h:1691
sint8 m2m_wifi_req_restrict_ble(void)
Asynchronous API to request restricting of BLE functionality by placing the BLE processor in a low po...
Definition: m2m_wifi.c:910
static volatile uint8 gu8ChNum
Definition: m2m_wifi.c:43
#define M2M_MAX_SSID_LEN
Definition: m2m_types.h:189
sint8 m2m_wifi_get_connection_info(void)
Asynchronous API for retrieving the WINC IC&#39;s connection status.
Definition: m2m_wifi.c:1268
uint8 m2m_wifi_get_sleep_mode(void)
Synchronous API to retrieve the current power save mode of the WINC IC.
Definition: m2m_wifi.c:1037
sint8 m2m_wifi_init(tstrWifiInitParam *param)
Synchronous API that initialises the WINC driver.
Definition: m2m_wifi.c:523
#define free
Definition: m2m_wifi.c:41
sint8 nmi_get_mac_address(uint8 *pu8MacAddr)
Definition: nmasic.c:719
This struct stores the battery voltage.
Definition: m2m_types.h:1054
sint8 m2m_wifi_reinit(tstrWifiInitParam *param)
Deinitialize and reinitialize wifi. Resets the WINC. Parameter may be set to NULL, in which case there is no change to the parameters given at initialization.
Definition: m2m_wifi.c:552
unsigned char uint8
Range of values between 0 to 255.
Definition: nm_bsp.h:89
sint8 hif_chip_sleep(void)
To make the chip sleep.
Definition: m2m_hif.c:226
uint32 u32StaticIP
Definition: m2m_types.h:1673
sint8 m2m_wifi_enable_sntp(uint8 bEnable)
Asynchronous API to enable or disable the SNTP client running on the WINC IC.
Definition: m2m_wifi.c:1290
NMI_API sint8 m2m_wifi_enable_mac_mcast(uint8 *pu8MulticastMacAddress, uint8 u8AddRemove)
Asynchronous API to add or remove MAC addresses in the multicast filter.
#define M2M_DEVICE_NAME_MAX
Definition: m2m_types.h:198
NMI_API sint8 m2m_wifi_ble_set_gain_table(uint8 table_idx)
Asynchronous API that notifies the WINC with the Gain Table index from Flash that should use to confi...
Definition: m2m_wifi.c:451
#define WEP_40_KEY_STRING_SIZE
Definition: m2m_types.h:248
uint8 u8BcastEn
Definition: m2m_types.h:1422
uint8 au8SSID[M2M_MAX_SSID_LEN]
Definition: m2m_types.h:1149
sint8 m2m_wifi_set_cust_InfoElement(uint8 *pau8M2mCustInfoElement)
Asynchronous API to add or remove a user-defined Information Element.
Definition: m2m_wifi.c:753
sint8 m2m_wifi_set_lsn_int(tstrM2mLsnInt *pstrM2mLsnInt)
Asynchronous API to set Wi-Fi listen interval for power save operation.
Definition: m2m_wifi.c:748
This structure holds the configuration parameters for the AP mode. It should be set by the applicatio...
Definition: m2m_types.h:1564
void hif_set_sleep_mode(uint8 u8Pstype)
Set the sleep mode of the HIF layer.
Definition: m2m_hif.c:201
NMI_API sint8 m2m_ota_get_firmware_version(tstrM2mRev *pstrRev)
Synchronous API to obtain the firmware version of the WINC image that is stored in the inactive flash...
Definition: m2m_wifi.c:1186
sint8 m2m_wifi_p2p(uint8 u8Channel)
Asynchronous API for enabling Wi-Fi Direct (P2P) mode in the WINC IC.
Definition: m2m_wifi.c:859
uint8 * pu8RngBuff
Definition: m2m_types.h:2208
This module contains M2M host interface APIs implementation.
sint8 m2m_wifi_get_sytem_time(void)
Asynchronous API to obtain the system time in use by the WINC IC.
Definition: m2m_wifi.c:1285
NMI_API sint8 m2m_wifi_send_wlan_pkt(uint8 *pu8WlanPacket, uint16 u16WlanHeaderLength, uint16 u16WlanPktSize)
Asynchronous API to queue a raw Wi-Fi packet for transmission by the WINC IC.
sint8 m2m_wifi_enable_ap(CONST tstrM2MAPConfig *pstrM2MAPConfig)
Asynchronous API to enable access point (AKA "hot-spot") mode on the WINC IC.
Definition: m2m_wifi.c:881
#define M2M_ETHERNET_HDR_LEN
Definition: m2m_types.h:184
sint8 m2m_wifi_disconnect(void)
Synchronous API to request disconnection from a network.
Definition: m2m_wifi.c:693
This struct stores the Tx Power levels.
Definition: m2m_types.h:1026
sint8 m2m_wifi_wps_disable(void)
Synchronous API that disables Wi-Fi Protected Setup mode in the WINC IC.
Definition: m2m_wifi.c:820
Structure holding firmware version parameters and build date/time.
Definition: nmdrv.h:44
tstr1xAuthCredentials strCred1x
Definition: m2m_types.h:1109
#define M2M_DRIVER_VERSION_PATCH_NO
Definition: m2m_types.h:159
sint8 hif_receive(uint32 u32Addr, uint8 *pu8Buf, uint16 u16Sz, uint8 isDone)
Definition: m2m_hif.c:762
sint8 m2m_wifi_set_sytem_time(uint32 u32UTCSeconds)
Asynchronous function for setting the system time within the WINC IC.
Definition: m2m_wifi.c:1273
#define NMI_API
Definition: nm_bsp.h:45
sint8 hif_deinit(void *arg)
To Deinitialize HIF layer.
Definition: m2m_hif.c:289


inertial_sense_ros
Author(s):
autogenerated on Sat Sep 19 2020 03:19:04