예제 #1
0
static void ICACHE_FLASH_ATTR ost_wifi_setup(os_event_t *events){
	os_printf("WiFi Setup...\n");
	uint8_t stationStatus = wifi_station_get_connect_status();
	//Handle status
	wifi_station_set_auto_connect(TRUE);
	wifi_setup(&ssid,&pass, STATION_MODE);
}
예제 #2
0
int WirelessNetworkInit()
{
	int ret = -1;
	int nDhcpFlag = -1;
	SYS_INFO sysInfo;
	WIFI_PARAM wifiParam;
	NET_PARAM netParam;
	char ip[16];
	char mac_addr[32] = {0};
	char command_buffer[256]= {0};
	char buffer_cache[128]= {0};
	
	ret = getWifiParam(&wifiParam);
	if (ret < 0)
	{
		return -1;
	}
			
	ret = getNetParam(&netParam);
	if (ret < 0)
	{
		return -1;
	}

	system("ifconfig ra0 192.168.5.5 up");
	memset(mac_addr, 0, 32);
	if (get_net_phyaddr_ext(ETH_WIRELESS_DEV, mac_addr) == 0)
	{
		memcpy(wifiParam.strPhyAddr, mac_addr, 6);
	}
	ret = setWifiParam(&wifiParam);
	if (ret < 0)
	{
		return -1;
	}
	
	if (wifiParam.nOnFlag == 1) 	// 启用无线
	{
		//增加wifi 状态指示
		if(wifi_setup(wifiParam) == 0)
		{
			wifiParam.Reserve = 1;
			ret = setWifiParam(&wifiParam);
			if (ret < 0)
			{
				return -1;
			}
		}
		
#if 1		
		// DHCP设置
		if (wifiParam.nDhcpOnFlag == 1)
		{
			getSysInfoParam(&sysInfo);
			nDhcpFlag = dhcp_setup(ETH_WIRELESS_DEV, sysInfo.strDeviceName);
		}
		else
		{
			nDhcpFlag = -1;
		}
		
		// 固定IP设置
		memset(ip, 0, 16);
		get_ip_addr(ETH_WIRELESS_DEV, ip);
		
		printf("dhcp_setup(WIRELESS): %d %s\n", nDhcpFlag, ip);

		if (nDhcpFlag != 0 || strlen(ip)<=0 || wifiParam.nDhcpOnFlag==0)
		{
			// Add the code by lvjh, 2008-03-22
			unsigned int add1 = 0;
			unsigned int add2 = 0;
			unsigned int add3 = 0;
			unsigned int add4 = 0;
	
			unsigned int add5 = 0;
			unsigned int add6 = 0;
			unsigned int add7 = 0;
			unsigned int add8 = 0;
				
			//判断是不是用户输入的wifi
			sleep(10);
			printf("wifiParam.pReserve[0]  = %d\n", wifiParam.pReserve[0]);
			if(wifiParam.pReserve[0] == 1){
				strcpy(wifiParam.byServerIp, netParam.byServerIp);
				strcpy(wifiParam.byDnsAddr, netParam.byDnsAddr);
				strcpy(wifiParam.byGateway, netParam.byGateway);
				strcpy(wifiParam.byServerMask, netParam.byServerMask);
				
				ret = setWifiParam(&wifiParam);
				if (ret < 0)
				{
					return -1;
				}
			}
			
			printf("DVS IP(WIRELESS): %s\n", wifiParam.byServerIp);
			

			#if 0
			if (set_ip_addr(ETH_WIRELESS_DEV, wifiParam.byServerIp) < 0)
			{
				printf("set_ip_addr(%s) Failed!\n", wifiParam.byServerIp);
	
				set_ip_addr(ETH_WIRELESS_DEV, DEFAULT_WIRELESS_IP);
				set_mask_addr(ETH_WIRELESS_DEV, DEFAULT_WIRELESS_MASK);
				//set_gateway_addr(DEFAULT_WIRELESS_GATEWAY);
				set_gateway_addr_ext(ETH_WIRELESS_DEV, DEFAULT_WIRELESS_GATEWAY);
				//return -1;
			}
			#endif
			
			sprintf(buffer_cache, "%s %s %s", "ifconfig",  ETH_WIRELESS_DEV, wifiParam.byServerIp);
			system(buffer_cache);
			
		
			if (set_mask_addr(ETH_WIRELESS_DEV, wifiParam.byServerMask) < 0)
			{
				printf("set_mask_addr(%s) Failed!\n", wifiParam.byServerMask);
		
				set_mask_addr(ETH_WIRELESS_DEV, DEFAULT_WIRELESS_MASK);
				//set_gateway_addr(DEFAULT_WIRELESS_GATEWAY);
				set_gateway_addr_ext(ETH_WIRELESS_DEV, DEFAULT_WIRELESS_GATEWAY);
				//return -1;
			}
	
			//printf("Old GateWay: %s\n", wifiParam.byGateway);
			//sscanf(wifiParam.byServerIp, "%d.%d.%d.%d", &add1, &add2, &add3, &add4);
			//sscanf(wifiParam.byGateway, "%d.%d.%d.%d", &add5, &add6, &add7, &add8);
			//sprintf(wifiParam.byGateway, "%d.%d.%d.%d", add1, add2, add3, add8);
			//printf("New GateWay: %s\n", wifiParam.byGateway);
				
			//if (set_gateway_addr(wifiParam.byGateway) < 0)
			if (set_gateway_addr_ext(ETH_WIRELESS_DEV, wifiParam.byGateway) < 0)
			{
				printf("set_gateway_addr(%s) Failed!\n", wifiParam.byGateway);
				//set_gateway_addr(DEFAULT_WIRELESS_GATEWAY);
				set_gateway_addr_ext(ETH_WIRELESS_DEV, DEFAULT_WIRELESS_GATEWAY);
				//return -1;
			}
		}

		// DNS设置
		if (wifiParam.nDhcpOnFlag == 1)
		{
			char localIP[16];
			char gateway[16];
			
			memset(localIP, 0, 16);
			memset(gateway, 0, 16);
	
			//ret = get_gateway_addr(gateway);
			ret = get_gateway_addr_ext(ETH_WIRELESS_DEV, gateway);
			if (ret == 0)
			{
				printf("GateWay(WIRELESS): %s\n", gateway);

				set_dns_addr(gateway);
				//add_dns_addr(gateway);
				
				strcpy(wifiParam.byGateway, gateway);
				strcpy(wifiParam.byDnsAddr, gateway);
			}
			ret = get_ip_addr(ETH_WIRELESS_DEV, localIP);
			if (ret == 0)
			{
				printf("DHCP: get_ip_addr: %s\n", localIP);
				strcpy(wifiParam.byServerIp, localIP);
			}
			printf("DHCP: %s %s\n", ETH_WIRELESS_DEV, localIP);
			
		
			wifiParam.Reserve = 1;
			setWifiParam(&wifiParam);
		}
		else
		{
			wifiParam.Reserve = 1;
			set_dns_addr(wifiParam.byGateway);
			
			
			//add_dns_addr(wifiParam.byGateway);
		}
#endif	
	}
	else
	{
		wifiParam.Reserve = 1;
		setWifiParam(&wifiParam);
	}
	return 0;
}