void _ConnectToAP( mico_Context_t * const inContext) { mico_log_trace(); network_InitTypeDef_adv_st wNetConfig; mico_log("connect to %s.....", inContext->flashContentInRam.micoSystemConfig.ssid); memset(&wNetConfig, 0x0, sizeof(network_InitTypeDef_adv_st)); mico_rtos_lock_mutex(&inContext->flashContentInRam_mutex); strncpy((char*)wNetConfig.ap_info.ssid, inContext->flashContentInRam.micoSystemConfig.ssid, maxSsidLen); memcpy(wNetConfig.ap_info.bssid, inContext->flashContentInRam.micoSystemConfig.bssid, 6); wNetConfig.ap_info.channel = inContext->flashContentInRam.micoSystemConfig.channel; wNetConfig.ap_info.security = inContext->flashContentInRam.micoSystemConfig.security; memcpy(wNetConfig.key, inContext->flashContentInRam.micoSystemConfig.key, inContext->flashContentInRam.micoSystemConfig.keyLength); wNetConfig.key_len = inContext->flashContentInRam.micoSystemConfig.keyLength; if(inContext->flashContentInRam.micoSystemConfig.dhcpEnable == true) wNetConfig.dhcpMode = DHCP_Client; else wNetConfig.dhcpMode = DHCP_Disable; strncpy((char*)wNetConfig.local_ip_addr, inContext->flashContentInRam.micoSystemConfig.localIp, maxIpLen); strncpy((char*)wNetConfig.net_mask, inContext->flashContentInRam.micoSystemConfig.netMask, maxIpLen); strncpy((char*)wNetConfig.gateway_ip_addr, inContext->flashContentInRam.micoSystemConfig.gateWay, maxIpLen); strncpy((char*)wNetConfig.dnsServer_ip_addr, inContext->flashContentInRam.micoSystemConfig.dnsServer, maxIpLen); mico_rtos_unlock_mutex(&inContext->flashContentInRam_mutex); wNetConfig.wifi_retry_interval = 100; StartAdvNetwork(&wNetConfig); }
/* Sysytem initilize */ void mxchipWNet_HA_init(void) { network_InitTypeDef_st wNetConfig; network_InitTypeDef_adv_st wNetConfigAdv; int err = MXCHIP_FAILED; net_para_st para; device_info = (mxchipWNet_HA_st *)malloc(sizeof(mxchipWNet_HA_st)); memset(device_info, 0, sizeof(mxchipWNet_HA_st)); SystemCoreClockUpdate(); mxchipInit(); hal_uart_init(); getNetPara(¶, Station); formatMACAddr((void *)device_info->status.mac, ¶.mac); strcpy((char *)device_info->status.ip, (char *)¶.ip); strcpy((char *)device_info->status.mask, (char *)¶.mask); strcpy((char *)device_info->status.gw, (char *)¶.gate); strcpy((char *)device_info->status.dns, (char *)¶.dns); readConfiguration(device_info); device_info->tcpServer_fd = -1; device_info->tcpClient_fd = (int *)malloc(4 * MAX_CLIENT); device_info->cloud_fd = -1; device_info->udpSearch_fd = -1; memset(device_info->tcpClient_fd, -1, sizeof(4 * MAX_CLIENT)); if(device_info->conf.fastLinkConf.availableRecord){ //Try fast link memcpy(&wNetConfigAdv.ap_info, &device_info->conf.fastLinkConf.ap_info, sizeof(ApList_adv_t)); memcpy(&wNetConfigAdv.key, &device_info->conf.fastLinkConf.key, device_info->conf.fastLinkConf.key_len); wNetConfigAdv.key_len = device_info->conf.fastLinkConf.key_len; wNetConfigAdv.dhcpMode = DHCP_Client; strcpy(wNetConfigAdv.local_ip_addr, (char*)device_info->conf.ip); strcpy(wNetConfigAdv.net_mask, (char*)device_info->conf.mask); strcpy(wNetConfigAdv.gateway_ip_addr, (char*)device_info->conf.gw); strcpy(wNetConfigAdv.dnsServer_ip_addr, (char*)device_info->conf.dns); wNetConfigAdv.wifi_retry_interval = 100; err = StartAdvNetwork(&wNetConfigAdv); } if(err == MXCHIP_FAILED){ wNetConfig.wifi_mode = Station; strcpy(wNetConfig.wifi_ssid, device_info->conf.sta_ssid); strcpy(wNetConfig.wifi_key, device_info->conf.sta_key); wNetConfig.dhcpMode = DHCP_Client; strcpy(wNetConfig.local_ip_addr, (char*)device_info->conf.ip); strcpy(wNetConfig.net_mask, (char*)device_info->conf.mask); strcpy(wNetConfig.gateway_ip_addr, (char*)device_info->conf.gw); strcpy(wNetConfig.dnsServer_ip_addr, (char*)device_info->conf.dns); wNetConfig.wifi_retry_interval = 500; StartNetwork(&wNetConfig); } ps_enable(); }
void _easylinkConnectWiFi( mico_Context_t * const inContext) { easylink_log_trace(); network_InitTypeDef_adv_st wNetConfig; memset(&wNetConfig, 0x0, sizeof(network_InitTypeDef_adv_st)); mico_rtos_lock_mutex(&inContext->flashContentInRam_mutex); strncpy((char*)wNetConfig.ap_info.ssid, inContext->flashContentInRam.micoSystemConfig.ssid, maxSsidLen); wNetConfig.ap_info.security = SECURITY_TYPE_AUTO; memcpy(wNetConfig.key, inContext->flashContentInRam.micoSystemConfig.user_key, maxKeyLen); wNetConfig.key_len = inContext->flashContentInRam.micoSystemConfig.user_keyLength; wNetConfig.dhcpMode = inContext->flashContentInRam.micoSystemConfig.dhcpEnable; strncpy((char*)wNetConfig.local_ip_addr, inContext->flashContentInRam.micoSystemConfig.localIp, maxIpLen); strncpy((char*)wNetConfig.net_mask, inContext->flashContentInRam.micoSystemConfig.netMask, maxIpLen); strncpy((char*)wNetConfig.gateway_ip_addr, inContext->flashContentInRam.micoSystemConfig.gateWay, maxIpLen); strncpy((char*)wNetConfig.dnsServer_ip_addr, inContext->flashContentInRam.micoSystemConfig.dnsServer, maxIpLen); wNetConfig.wifi_retry_interval = 100; mico_rtos_unlock_mutex(&inContext->flashContentInRam_mutex); StartAdvNetwork(&wNetConfig); easylink_log("connect to %s.....", wNetConfig.ap_info.ssid); }