sint8 m2m_wifi_request_scan(uint8 ch) { sint8 s8Ret = M2M_ERR_SCAN_IN_PROGRESS; if(!gu8scanInProgress) { tstrM2MScan strtmp; strtmp.u8ChNum = ch; s8Ret = hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_SCAN, (uint8*)&strtmp, sizeof(tstrM2MScan),NULL, 0,0); if(s8Ret == M2M_SUCCESS) { gu8scanInProgress = 1; } else { M2M_ERR("SCAN Failed Ret = %d\n",s8Ret); } } else { M2M_ERR("SCAN In Progress\n"); } return s8Ret; }
sint8 m2m_wifi_set_sytem_time(uint32 u32UTCSeconds) { /* The firmware accepts timestamps relative to 1900 like NTP Timestamp. */ return hif_send(M2M_REQ_GROUP_WIFI, M2M_WIFI_REQ_SET_SYS_TIME, (uint8*)&u32UTCSeconds, sizeof(tstrSystemTime), NULL, 0, 0); }
sint8 m2m_wifi_enable_ap(CONST tstrM2MAPConfig* pstrM2MAPConfig) { sint8 ret = M2M_SUCCESS; #if defined(M2M_WILC1000) && defined(COMPUTE_PMK_IN_HOST) if(pstrM2MAPConfig->u8SecType == M2M_WIFI_SEC_WPA_PSK) { tstrM2MAPConfig strTempM2MAPConfig; m2m_memcpy((uint8 *)&strTempM2MAPConfig, (uint8 *)pstrM2MAPConfig, sizeof(tstrM2MAPConfig)); strTempM2MAPConfig.u8IsPMKUsed = 1; pbkdf2_sha1((uint8 *)pstrM2MAPConfig->au8PSK,m2m_strlen((uint8 *)pstrM2MAPConfig->au8PSK), (uint8 *)pstrM2MAPConfig->au8SSID,m2m_strlen((uint8 *)pstrM2MAPConfig->au8SSID),strTempM2MAPConfig.au8PMK); pstrM2MAPConfig = &strTempM2MAPConfig; } #elif defined(M2M_WILC1000) && !defined(COMPUTE_PMK_IN_HOST) if(pstrM2MAPConfig->u8SecType == M2M_WIFI_SEC_WPA_PSK) { tstrM2MAPConfig strTempM2MAPConfig; strTempM2MAPConfig.u8IsPMKUsed = 0; m2m_memcpy((uint8*)&strTempM2MAPConfig,(uint8*)pstrM2MAPConfig,sizeof(tstrM2MAPConfig)); pstrM2MAPConfig = &strTempM2MAPConfig; } #endif ret = hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_ENABLE_AP, (uint8 *)pstrM2MAPConfig, sizeof(tstrM2MAPConfig), NULL, 0, 0); return ret; }
sint8 m2m_wifi_request_scan(uint8 ch) { sint8 s8Ret = M2M_SUCCESS; if(!gu8scanInProgress) { if(((ch >= M2M_WIFI_CH_1) && (ch <= M2M_WIFI_CH_14)) || (ch == M2M_WIFI_CH_ALL)) { tstrM2MScan strtmp; strtmp.u8ChNum = ch; s8Ret = hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_SCAN, (uint8*)&strtmp, sizeof(tstrM2MScan),NULL, 0,0); if(s8Ret == M2M_SUCCESS) { gu8scanInProgress = 1; } } else { s8Ret = M2M_ERR_INVALID_ARG; } } else { s8Ret = M2M_ERR_SCAN_IN_PROGRESS; } return s8Ret; }
sint8 m2m_wifi_start_provision_mode(tstrM2MAPConfig *pstrAPConfig, char *pcHttpServerDomainName, uint8 bEnableHttpRedirect) { sint8 s8Ret = M2M_ERR_FAIL; if((pstrAPConfig != NULL)) { tstrM2MProvisionModeConfig strProvConfig; if(M2M_SUCCESS == m2m_validate_ap_parameters(pstrAPConfig)) { m2m_memcpy((uint8*)&strProvConfig.strApConfig, (uint8*)pstrAPConfig, sizeof(tstrM2MAPConfig)); if((m2m_strlen((uint8 *)pcHttpServerDomainName) <= 0) || (NULL == pcHttpServerDomainName)) { M2M_ERR("INVALID DOMAIN NAME\n"); goto ERR1; } m2m_memcpy((uint8*)strProvConfig.acHttpServerDomainName, (uint8*)pcHttpServerDomainName, 64); strProvConfig.u8EnableRedirect = bEnableHttpRedirect; /* Stop Scan if it is ongoing. */ gu8scanInProgress = 0; s8Ret = hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_START_PROVISION_MODE | M2M_REQ_DATA_PKT, (uint8*)&strProvConfig, sizeof(tstrM2MProvisionModeConfig), NULL, 0, 0); } else { /*goto ERR1;*/ } } ERR1: return s8Ret; }
sint8 m2m_wifi_set_mac_address(uint8 au8MacAddress[6]) { tstrM2mSetMacAddress strTmp; m2m_memcpy((uint8*) strTmp.au8Mac, (uint8*) au8MacAddress, 6); return hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_SET_MAC_ADDRESS, (uint8*) &strTmp, sizeof(tstrM2mSetMacAddress), NULL, 0,0); }
sint8 m2m_wifi_enable_sntp(uint8 bEnable) { uint8 u8Req; u8Req = bEnable ? M2M_WIFI_REQ_ENABLE_SNTP_CLIENT : M2M_WIFI_REQ_DISABLE_SNTP_CLIENT; return hif_send(M2M_REQ_GRP_WIFI, u8Req, NULL, 0, NULL, 0, 0); }
sint8 m2m_wifi_request_scan_ssid(uint8 ch,char* pcssid) { sint8 s8Ret = M2M_ERR_SCAN_IN_PROGRESS; if(!gu8scanInProgress) { tstrM2MScan strtmp; m2m_memset((uint8*)&strtmp,0,sizeof(tstrM2MScan)); strtmp.u8ChNum = ch; if(pcssid) { uint8 len = m2m_strlen((uint8 *)pcssid); m2m_memcpy(strtmp.au8SSID,(uint8 *)pcssid,len+1); } s8Ret = hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_SCAN, (uint8*)&strtmp, sizeof(tstrM2MScan),NULL, 0,0); if(s8Ret == M2M_SUCCESS) { gu8scanInProgress = 1; } else { M2M_ERR("SCAN Failed Ret = %d\n",s8Ret); } } else { M2M_ERR("SCAN In Progress\n"); } return s8Ret; }
/*! @fn NMI_API sint8 m2m_wifi_enable_firmware_logs(uint8 u8Enable); @brief Enable or Disable logs in run time (Disable Firmware logs will enhance the firmware start-up time and performance) @param [in] u8Enable Set 1 to enable the logs 0 for disable @return The function SHALL return M2M_SUCCESE for success and a negative value otherwise. @sa __DISABLE_FIRMWARE_LOGS__ (build option to disable logs from initializations) @pre m2m_wifi_init @warning */ sint8 m2m_wifi_enable_firmware_logs(uint8 u8Enable) { sint8 ret = M2M_SUCCESS; tstrM2mEnableLogs strM2mEnableLogs; strM2mEnableLogs.u8Enable = u8Enable; ret = hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_SET_ENABLE_LOGS, (uint8*)&strM2mEnableLogs,sizeof(tstrM2mEnableLogs), NULL, 0, 0); return ret; }
sint8 m2m_wifi_req_scan_result(uint8 index) { sint8 ret = M2M_SUCCESS; tstrM2mReqScanResult strReqScanRlt; strReqScanRlt.u8Index = index; ret = hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_SCAN_RESULT, (uint8*) &strReqScanRlt, sizeof(tstrM2mReqScanResult), NULL, 0, 0); return ret; }
/*! @fn NMI_API sint8 m2m_wifi_set_battery_voltage(uint16 u16BattVoltx100); @brief Enable or Disable logs in run time (Disable Firmware logs will enhance the firmware start-up time and performance) @param [in] u16BattVoltx100 battery voltage multiplied by 100 @return The function SHALL return M2M_SUCCESE for success and a negative value otherwise. @sa __DISABLE_FIRMWARE_LOGS__ (build option to disable logs from initializations) @pre m2m_wifi_init @warning */ sint8 m2m_wifi_set_battery_voltage(uint16 u16BattVoltx100) { sint8 ret = M2M_SUCCESS; tstrM2mBatteryVoltage strM2mBattVol = {0}; strM2mBattVol.u16BattVolt = u16BattVoltx100; ret = hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_SET_BATTERY_VOLTAGE, (uint8*)&strM2mBattVol,sizeof(tstrM2mBatteryVoltage), NULL, 0, 0); return ret; }
/*! @fn NMI_API sint8 m2m_wifi_set_tx_power(uint8 u8TxPwrLevel); @brief set the TX power tenuM2mTxPwrLevel @param [in] u8TxPwrLevel change the TX power tenuM2mTxPwrLevel @return The function SHALL return M2M_SUCCESE for success and a negative value otherwise. @sa tenuM2mTxPwrLevel @pre m2m_wifi_init @warning */ sint8 m2m_wifi_set_tx_power(uint8 u8TxPwrLevel) { sint8 ret = M2M_SUCCESS; tstrM2mTxPwrLevel strM2mTxPwrLevel; strM2mTxPwrLevel.u8TxPwrLevel = u8TxPwrLevel; ret = hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_SET_TX_POWER, (uint8*)&strM2mTxPwrLevel,sizeof(tstrM2mTxPwrLevel), NULL, 0, 0); return ret; }
/*! @fn NMI_API sint8 m2m_wifi_set_power_profile(uint8 u8PwrMode); @brief Change the power profile mode @param [in] u8PwrMode Change the WINC power profile to different mode PWR_LOW1/PWR_LOW2/PWR_HIGH/PWR_AUTO (tenuM2mPwrMode) @return The function SHALL return M2M_SUCCESE for success and a negative value otherwise. @sa tenuM2mPwrMode @pre m2m_wifi_init @warning must be called after the initializations and before any connection request and can't be changed in run time, */ sint8 m2m_wifi_set_power_profile(uint8 u8PwrMode) { sint8 ret = M2M_SUCCESS; tstrM2mPwrMode strM2mPwrMode; strM2mPwrMode.u8PwrMode = u8PwrMode; ret = hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_SET_POWER_PROFILE, (uint8*)&strM2mPwrMode,sizeof(tstrM2mPwrMode), NULL, 0, 0); return ret; }
sint8 m2m_wifi_set_scan_region(uint8 ScanRegion) { sint8 s8Ret = M2M_ERR_FAIL; tstrM2MScanRegion strScanRegion; strScanRegion.u8ScanRegion = ScanRegion; s8Ret = hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_SET_SCAN_REGION, (uint8*)&strScanRegion, sizeof(tstrM2MScanRegion),NULL, 0,0); return s8Ret; }
/*! @fn \ sint8 m2m_sha256_hash_init(tstrM2mSha256Ctxt *psha256Ctxt); @brief SHA256 hash initialization @param[in] psha256Ctxt Pointer to a sha256 context allocated by the caller. */ sint8 m2m_crypto_sha256_hash_init(tstrM2mSha256Ctxt *psha256Ctxt) { sint8 ret = M2M_ERR_FAIL; if((psha256Ctxt != NULL)&&(!gstrCryptoCtxt.u8CryptoBusy)) { ret = hif_send(M2M_REQ_GROUP_CRYPTO,M2M_CRYPTO_REQ_SHA256_INIT|M2M_REQ_DATA_PKT,(uint8*)psha256Ctxt,sizeof(tstrM2mSha256Ctxt),NULL,0,0); } return ret; }
/*! @fn NMI_API sint8 m2m_wifi_set_lsn_int(tstrM2mLsnInt * pstrM2mLsnInt); @brief Set the Wi-Fi listen interval for power save operation. It is represented in units of AP Beacon periods. @param [in] pstrM2mLsnInt Structure holding the listen interval configurations. @return The function SHALL return 0 for success and a negative value otherwise. @sa tstrM2mLsnInt , m2m_wifi_set_sleep_mode @pre m2m_wifi_set_sleep_mode shall be called first @warning The Function called once after initialization. */ sint8 m2m_wifi_enable_dhcp(uint8 u8DhcpEn ) { uint8 u8Req; u8Req = u8DhcpEn ? M2M_IP_REQ_ENABLE_DHCP : M2M_IP_REQ_DISABLE_DHCP; return hif_send(M2M_REQ_GRP_IP, u8Req, NULL, 0, NULL, 0, 0); }
sint8 m2m_wifi_set_scan_options(tstrM2MScanOption* ptstrM2MScanOption) { sint8 s8Ret = M2M_ERR_FAIL; if(m2m_validate_scan_options (ptstrM2MScanOption) == M2M_SUCCESS) { s8Ret = hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_SET_SCAN_OPTION, (uint8*)ptstrM2MScanOption, sizeof(tstrM2MScanOption),NULL, 0,0); } return s8Ret; }
sint8 m2m_wifi_enable_ap(CONST tstrM2MAPConfig* pstrM2MAPConfig) { sint8 ret = M2M_ERR_FAIL; if(M2M_SUCCESS == m2m_validate_ap_parameters(pstrM2MAPConfig)) { ret = hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_ENABLE_AP, (uint8 *)pstrM2MAPConfig, sizeof(tstrM2MAPConfig), NULL, 0, 0); } return ret; }
/*! @fn \ NMI_API sint8 m2m_ota_start_update(uint8 * u8DownloadUrl); @brief Request OTA start update using the downloaded url @param [in] u8DownloadUrl The download firmware url, you get it from device info @return The function SHALL return 0 for success and a negative value otherwise. */ NMI_API sint8 m2m_ota_start_update(uint8 * u8DownloadUrl) { sint8 ret = M2M_SUCCESS; uint16 u16DurlSize = m2m_strlen(u8DownloadUrl) + 1; /*Todo: we may change it to data pkt but we need to give it higer priority but the priorty is not implemnted yet in data pkt */ ret = hif_send(M2M_REQ_GROUP_OTA,M2M_OTA_REQ_START_UPDATE,u8DownloadUrl,u16DurlSize,NULL,0,0); return ret; }
sint8 m2m_wifi_change_monitoring_channel(uint8 u8ChannelID) { sint8 s8Ret = -1; if((u8ChannelID >= M2M_WIFI_CH_1) && (u8ChannelID <= M2M_WIFI_CH_14)) { s8Ret = hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_CHG_MONITORING_CHNL | M2M_REQ_DATA_PKT, (uint8*)&u8ChannelID, sizeof(u8ChannelID), NULL, 0,0); } return s8Ret; }
sint8 m2m_wifi_set_scan_list(tstrM2MScanList* pstrScanList) { sint8 s8Ret = M2M_ERR_FAIL; s8Ret = hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_SET_SCAN_LIST, (uint8*)pstrScanList, sizeof(tstrM2MScanList),NULL, 0,0); if(s8Ret != M2M_SUCCESS) { M2M_ERR("SCAN List Ret = %d\n",s8Ret); } return s8Ret; }
/*! @fn \ sint8 m2m_sha256_hash_finish(tstrM2mSha256Ctxt *psha256Ctxt, uint8 *pu8Sha256Digest); @brief SHA256 hash finalization @param[in] psha256Ctxt Pointer to a sha256 context allocated by the caller. @param [in] pu8Sha256Digest Buffer allocated by the caller which will hold the resultant SHA256 Digest. It must be allocated no less than M2M_SHA256_DIGEST_LEN. */ sint8 m2m_crypto_sha256_hash_finish(tstrM2mSha256Ctxt *psha256Ctxt, uint8 *pu8Sha256Digest) { sint8 ret = M2M_ERR_FAIL; if((!gstrCryptoCtxt.u8CryptoBusy) && (psha256Ctxt != NULL) && (pu8Sha256Digest != NULL)) { gstrCryptoCtxt.pu8Digest = pu8Sha256Digest; ret = hif_send(M2M_REQ_GROUP_CRYPTO,M2M_CRYPTO_REQ_SHA256_FINSIH|M2M_REQ_DATA_PKT,(uint8*)psha256Ctxt,sizeof(tstrM2mSha256Ctxt),NULL,0,0); } return ret; }
sint8 m2m_wifi_ap_add_black_list(uint8 bAddNewEntry,uint8* mac_addr) { uint8 u8BlackListRequest[7]; u8BlackListRequest[0] = bAddNewEntry; m2m_memcpy(&u8BlackListRequest[1],mac_addr,6); sint8 ret = M2M_SUCCESS; ret = hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_AP_BLACK_LIST,u8BlackListRequest, sizeof(u8BlackListRequest), NULL, 0, 0); return ret; }
/*! @fn \ sint8 m2m_sha256_hash_update(tstrM2mSha256Ctxt *psha256Ctxt, uint8 *pu8Data, uint16 u16DataLength); @brief SHA256 hash update @param [in] psha256Ctxt Pointer to the sha256 context. @param [in] pu8Data Buffer holding the data submitted to the hash. @param [in] u16DataLength Size of the data bufefr in bytes. */ sint8 m2m_crypto_sha256_hash_update(tstrM2mSha256Ctxt *psha256Ctxt, uint8 *pu8Data, uint16 u16DataLength) { sint8 ret = M2M_ERR_FAIL; if((!gstrCryptoCtxt.u8CryptoBusy) && (psha256Ctxt != NULL) && (pu8Data != NULL) && (u16DataLength < M2M_SHA256_MAX_DATA)) { ret = hif_send(M2M_REQ_GROUP_CRYPTO,M2M_CRYPTO_REQ_SHA256_UPDATE|M2M_REQ_DATA_PKT,(uint8*)psha256Ctxt,sizeof(tstrM2mSha256Ctxt),pu8Data,u16DataLength,sizeof(tstrM2mSha256Ctxt) + sizeof(tstrCyptoResp)); } return ret; }
sint8 m2m_wifi_set_control_ifc(uint8 u8IfcId) { sint8 s8Ret = -1; tstrM2MIfId strIfId; strIfId.u8IfcId=u8IfcId; if(u8IfcId == INTERFACE_1 || u8IfcId == INTERFACE_2) { s8Ret = hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_SET_IFC_ID, (uint8*)&strIfId, sizeof(tstrM2MIfId), NULL, 0, 0); } return s8Ret; }
sint8 m2m_wifi_set_static_ip(tstrM2MIPConfig * pstrStaticIPConf) { pstrStaticIPConf->u32DNS = NM_BSP_B_L_32(pstrStaticIPConf->u32DNS); pstrStaticIPConf->u32Gateway = NM_BSP_B_L_32(pstrStaticIPConf->u32Gateway); pstrStaticIPConf->u32StaticIP = NM_BSP_B_L_32( pstrStaticIPConf->u32StaticIP); pstrStaticIPConf->u32SubnetMask = NM_BSP_B_L_32( pstrStaticIPConf->u32SubnetMask); return hif_send(M2M_REQ_GRP_IP, M2M_IP_REQ_STATIC_IP_CONF, (uint8*) pstrStaticIPConf, sizeof(tstrM2MIPConfig), NULL, 0,0); }
sint8 m2m_wifi_set_sleep_mode(uint8 PsTyp, uint8 BcastEn) { sint8 ret = M2M_SUCCESS; tstrM2mPsType strPs; strPs.u8PsType = PsTyp; strPs.u8BcastEn = BcastEn; ret = hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_SLEEP, (uint8*) &strPs,sizeof(tstrM2mPsType), NULL, 0, 0); M2M_INFO("POWER SAVE %d\n",PsTyp); hif_set_sleep_mode(PsTyp); return ret; }
sint8 m2m_wifi_req_server_init(uint8 ch) { sint8 ret = M2M_SUCCESS; #ifdef _PS_SERVER_ tstrM2mServerInit strServer; strServer.u8Channel = ch; ret = hif_send(M2M_REQ_GRP_WIFI,M2M_WIFI_REQ_SERVER_INIT, (uint8*)&strServer, sizeof(tstrM2mServerInit), NULL, 0, 0); #else M2M_ERR("_PS_SERVER_ is not defined\n"); #endif return ret; }
sint8 m2m_wifi_set_device_name(uint8 *pu8DeviceName, uint8 u8DeviceNameLength) { tstrM2MDeviceNameConfig strDeviceName; if(u8DeviceNameLength >= M2M_DEVICE_NAME_MAX) { u8DeviceNameLength = M2M_DEVICE_NAME_MAX; } //pu8DeviceName[u8DeviceNameLength] = '\0'; u8DeviceNameLength ++; m2m_memcpy(strDeviceName.au8DeviceName, pu8DeviceName, u8DeviceNameLength); return hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_SET_DEVICE_NAME, (uint8*)&strDeviceName, sizeof(tstrM2MDeviceNameConfig), NULL, 0,0); }
sint8 m2m_wifi_req_client_ctrl(uint8 u8Cmd) { sint8 ret = M2M_SUCCESS; #ifdef _PS_SERVER_ tstrM2Mservercmd strCmd; strCmd.u8cmd = u8Cmd; ret = hif_send(M2M_REQ_GRP_WIFI, M2M_WIFI_REQ_CLIENT_CTRL, (uint8*)&strCmd, sizeof(tstrM2Mservercmd), NULL, 0, 0); #else M2M_ERR("_PS_SERVER_ is not defined\n"); #endif return ret; }