Esempio n. 1
0
void SetNullIP(const char *pcInterface)
{
	struct bootp wlan_bootp_data;
	int j = 0;
	char ipadd[16];
	char netmask[16] = "0.0.0.0";
	char gateway[16];
	char broadcast[16] = "255.255.255.255";
	
	unsigned long ulIP = 0;
	httpIP2String(ulIP, ipadd);
	strcpy(gateway, ipadd);

	DownInterface(pcInterface);
	diag_printf("IP is %s, NetMask is %s, Gateway is %s,Broadcast is %s\n",ipadd,netmask,gateway,broadcast);
	build_bootp_record(&wlan_bootp_data, pcInterface,
                           ipadd, netmask,broadcast,gateway,gateway);
	show_bootp(pcInterface, &wlan_bootp_data);

	if (!init_net(pcInterface, &wlan_bootp_data)) 
	{
		diag_printf("failed for %s\n",pcInterface);
	}
	for(;j<5;j++)
		init_loopback_interface(0);		
}
Esempio n. 2
0
void Do_TestSendIpMail(BOOL *bSendIpMail)
{
	unsigned long ulPublicIpAddress;
	unsigned long ulPublicSubnetMask;
	unsigned long ulDefaultGateway;
	unsigned long aulDNSServer[3];
	char acContent[256];
	int iLen;
	int i;
	MAIL_MEM* mail_mem = NULL;

	if (!(*bSendIpMail)) return;
	*bSendIpMail = FALSE;
	
	//if (!g_ConfigParam.bIfMailOnDialed) return;
	GetPubIPInfo(&ulPublicIpAddress,
				&ulPublicSubnetMask,
				&ulDefaultGateway,
				aulDNSServer);
	iLen = sprintf(acContent, "IP: ");
	iLen += httpIP2String(ulPublicIpAddress, acContent + iLen);
	iLen += sprintf(acContent + iLen, "\nNetmask: ");
	iLen += httpIP2String(ulPublicSubnetMask, acContent + iLen);
	iLen += sprintf(acContent + iLen, "\nGateway: ");
	iLen += httpIP2String(ulDefaultGateway, acContent + iLen);
	for (i = 0; i < 3; i++)
	{
		if (aulDNSServer[i] != 0)
		{
			iLen += sprintf(acContent + iLen, "\nDNS Server %d: ", i);
			iLen += httpIP2String(aulDNSServer[i], acContent + iLen);
		}
	}


	cyg_mutex_lock(&g_ptmConfigParam);
	//update dynamic DNS if possible
	diag_printf("proxy server is %s\n",g_ConfigParam.acProxy);
	if (g_ConfigParam.bEnableDDNS)
		Do_DNS(g_ConfigParam.acDDNSDomainName,
			ulPublicIpAddress,
			g_ConfigParam.acDDNSUserName,
			g_ConfigParam.acDDNSUserPass,
			g_ConfigParam.acProxy,
			g_ConfigParam.acProxyUser,
			g_ConfigParam.acProxyPass);


	if (g_ConfigParam.acDial_MailSender[0] != '\0'
		&& g_ConfigParam.acDial_MailReceiver[0] != '\0'
		&& g_ConfigParam.acDial_MailServer[0] != '\0')
	{		
		if(get_mail_mem(&mail_mem) == FALSE)
			diag_printf("Not enough mail memory!\n");
		else
		{
			sendMailMsg(
				g_ConfigParam.acDial_MailSender,
				g_ConfigParam.acDial_MailReceiver,"","",
				(g_ConfigParam.acDial_MailSubject[0]=='\0'?"Web Camera PPP Dialed!":g_ConfigParam.acDial_MailSubject),
				acContent,
				0,
				NULL,
				g_ConfigParam.acDial_MailServer,
				g_ConfigParam.acDial_MailUser,
				(g_ConfigParam.bDial_MailCheck?g_ConfigParam.acDial_MailPassword:NULL),
				MAIL_PPPOE_IP,
				mail_mem);
		}
	}
	cyg_mutex_unlock(&g_ptmConfigParam);
	//cyg_thread_yield();
}
Esempio n. 3
0
int Config_MemDebug(HTTPCONNECTION hConnection, LIST *pParamList, int iAction, XML *pReturnXML)
{
	switch (iAction)
	{
	case CA_AUTH:
		return AUTH_ADMIN;
	case CA_CONFIG:
		{
			UINT32 i;
			char acBuf[128];
			UINT32 nLen = 0;
			static cyg_ppp_handle_t ppp_handle;
			const char *pcAction = httpGetString(pParamList, "action");
			
			if(strcmp(pcAction, "net") == 0)
			{
				if(g_ptdNetDebug_stack == NULL)
				{
					g_ptdNetDebug_stack = (unsigned char *)malloc(STACKSIZE);
					if (g_ptdNetDebug_stack != NULL)
					{
						cyg_thread_create(PTD_PRIORITY, &NetTestThread, NULL, "ptdNetTest",
							g_ptdNetDebug_stack, STACKSIZE, &g_ptdNetDebug_handle, &g_ptdNetDebug);
						if (g_ptdNetDebug_handle == NULL)
							fprintf(stderr, "Thread for \"NetTest\" creation failed!\n");
						else
							cyg_thread_resume(g_ptdNetDebug_handle);
					}
				}
			}
			else if (strcmp(pcAction, "print") == 0)
			{
				while(1)
				{
					diag_printf("random%d", rand());
					if(rand()%12==0)
						diag_printf("\n");
				}
			}
			else if (strcmp(pcAction, "pppip") == 0)
			{
				int fd;
				struct ifreq ifr;
				UINT32 ulIP = 0;
				UINT32 ulNetmask = 0;
				char acIP[16];
				char acNetmask[16];
				
				fd = socket(AF_INET, SOCK_DGRAM, 0);
				strcpy(ifr.ifr_name, "ppp0");
				
				if (fd >= 0) 
				{
					if (ioctl(fd, SIOCGIFADDR, &ifr) >= 0)
						ulIP = (unsigned int)(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr);
						
					if (ioctl(fd, SIOCGIFNETMASK, &ifr) == 0)
						ulNetmask = (unsigned int)(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr);
					
					close(fd);
				}
				
				httpIP2String(ulIP, acIP);
				httpIP2String(ulNetmask, acNetmask);
				AddHttpValue(pReturnXML, "IP", acIP);
				AddHttpValue(pReturnXML, "Netmask", acNetmask);
			}
			else if (strcmp(pcAction, "dppp") == 0)
			{
				ppot_disconnect();
			}
			else if (strcmp(pcAction, "ppp") == 0)
			{
				bool ret;
				const char *pcUsername;
				const char *pcPassword;
				const char *pcServer;
				int iPort;
				
				pcUsername = httpGetString(pParamList, "User");
				pcPassword = httpGetString(pParamList, "Pass");
				pcServer = httpGetString(pParamList, "Server");
				iPort = httpGetLong(pParamList, "Port");

/*				
u: xiaohui      p: 0gogorovio0
u: xiaohui1    p: 1gogorovio1
u: xiaohui2    p: 2gogorovio2
*/

				//ppp user: blah password=blahing
				// ssh port:4239, user: xhchen, pass: aeV2ohTi
				

				// Start up PPP
				//ppot_connect("tools.pimpmyrovio.com", 21201);
				//ppot_connect("116.92.2.11", 21201);
				ret = ppot_connect(&pcServer, &iPort, 1, pcUsername, pcPassword);
				AddHttpValue(pReturnXML, "ppot_connect", (ret ? "true" : "false"));
#if 0		
				ppp_handle = cyg_ppp_up( "/dev/sert0", &options );


				// Wait for it to get running
				if( cyg_ppp_wait_up( ppp_handle ) == 0 )
				{
					// Make use of PPP
					//use_ppp();

					// Bring PPP link down
					//cyg_ppp_down( ppp_handle );

					// Wait for connection to go down.
					//cyg_ppp_wait_down( ppp_handle );
				}
#endif			
				//cyg_thread_delay(5000);
				//ppot_disconnect();
				//diag_printf("Disconnect=====================\n");
				//while(1);
			}
			else if (strcmp(pcAction, "rtsp") == 0)
			{
				g_ntp_add = httpGetLong(pParamList, "ntp");
				g_ts_video = httpGetLong(pParamList, "ts_video");
				g_ts_audio = httpGetLong(pParamList, "ts_audio");
				AddHttpNum(pReturnXML, "ntp", g_ntp_add);
				AddHttpNum(pReturnXML, "ts_video", g_ts_video);
				AddHttpNum(pReturnXML, "ts_audio", g_ts_audio);
				AddHttpNum(pReturnXML, "max_vd_ratio", (int)max_vd_ratio);
				AddHttpNum(pReturnXML, "max_ad_ratio", (int)max_vd_ratio);
			}
			else if (strcmp(pcAction, "dir") == 0)
			{
			}
			else if (strcmp(pcAction, "channel") == 0)
			{
				int ch;
				GetWlanChannel("wlan0", &ch);
				AddHttpNum(pReturnXML, "channel", ch);
			}
			else if (strcmp(pcAction, "upnp") == 0)
			{
				upnp_refresh();
				AddHttpValue(pReturnXML, "UPNP", "refresh");
			}
			else if (strcmp(pcAction, "malloc") == 0)
			{
				static unsigned long ulTotalSize = 0;
				unsigned long ulSize = httpGetLong(pParamList, "size");
				void *pAddr = malloc (ulSize);
				if (pAddr != NULL)
					ulTotalSize += ulSize;
				AddHttpNum(pReturnXML, "addr", (int)pAddr);
				AddHttpNum(pReturnXML, "total_size", ulTotalSize);
			}
			else if (strcmp(pcAction, "checkip") == 0)
			{
				DDNS_CheckIP();
			}
			else if (strcmp(pcAction, "ddns") == 0)
			{
				BOOL bEnable = g_ConfigParam.bEnableDDNS;
				g_ConfigParam.bEnableDDNS = TRUE;
				DDNS_Update();
				g_ConfigParam.bEnableDDNS = bEnable;
			}
			else if (strcmp(pcAction, "line") == 0)
			{
				int i;
				char name[16];
				int size = sizeof(dbg_line_copy) / sizeof(dbg_line_copy[0]);
				cyg_interrupt_disable();
				dbg_line_pos_copy = dbg_line_pos;
				memcpy(dbg_line_copy, dbg_line, sizeof(dbg_line));
				cyg_interrupt_enable();	
				
				for (i = 0; i < size; i += 16)
				{
					int j;
					char str[128];
					int len = 0;
					for (j = 0; j < 16; j++)
					{
						len += sprintf(str + len, "%5d", (int) dbg_line_copy[(i+j+dbg_line_pos)%(size)]);
					}
					sprintf(name, "%5d", i);
					AddHttpValue(pReturnXML, name, str);
				}
			}
#if 1	//xhchen - MCU debug
			else if (strcmp(pcAction, "uart") == 0)
			{
				char log[128];
				char name[16];
				int log_pos;
				int i;
				sysDisableIRQ();
				log_pos = uart_log_pos;
				memcpy(log, uart_log, sizeof(log));
				sysEnableIRQ();
				
				
				for (i = 0; i < sizeof(log); i += 16)
				{
					int j;
					char str[32];
					int len = 0;
					for (j = 0; j < 16; j += 2)
					{
						char ch = log[(log_pos + i + j) % sizeof(log)];
						len += sprintf(str + len, "%c", ( ch != '\0' ? ch : '-') );
						ch = log[(log_pos + i + j + 1) % sizeof(log)];
						len += sprintf(str + len, "%02x", (int)(unsigned char)ch);
					}
					
					sprintf(name, "%08x", i / 2);
					AddHttpValue(pReturnXML, name, str);
				}
			}
			else if (strcmp(pcAction, "mcu") == 0)
			{
				void mcuGetErrorStatus(UINT32 *puCmdNo, UINT32 *puCommandCount, BOOL *pbCrashedLock);
				UINT32 uCmdNo;
				UINT32 uCmdCount;
				BOOL bCrashedLock;
				
				mcuGetErrorStatus(&uCmdNo, &uCmdCount, &bCrashedLock);
				AddHttpNum(pReturnXML, "CmdNo", uCmdNo);			
				AddHttpNum(pReturnXML, "LockCrashed", bCrashedLock);
				AddHttpNum(pReturnXML, "CmdCount", uCmdCount);
			}
			else
#endif
			if (strcmp(pcAction, "break") == 0)
			{
				test_sus();
				AddHttpValue(pReturnXML, "break_after", "3 seconds");
			}
			else if (strcmp(pcAction, "ps") == 0)
			{
				outpw(REG_GPIO_IE, (inpw(REG_GPIO_IE)|0x00000010));
				
				SetWlanPSMode("wlan0", FALSE);
			
				AddHttpValue(pReturnXML, "SetWlanPSMode", "wlan0");
			}
			else if (strcmp(pcAction, "cfg") == 0)
			{
				
				SetWlanHostSleepCfg("wlan0", 5);
				AddHttpValue(pReturnXML, "SetWlanHostSleepCfg", "wlan0 5");
			}
			else if (strcmp(pcAction, "gpiob19") == 0)
			{
				/* Set GPIOB for MCU */
				outpw(REG_GPIOB_OE,inpw(REG_GPIOB_OE)&(~0x00080000));		//19 output;
				outpw(REG_GPIOB_DAT,inpw(REG_GPIOB_DAT)&(~0x00080000));	//19 low
				cyg_thread_delay(8);
				outpw(REG_GPIOB_OE,inpw(REG_GPIOB_OE)&(~0x00080000));		//19 output;
				outpw(REG_GPIOB_DAT,inpw(REG_GPIOB_DAT)|(0x00080000));	//19 high   				
				cyg_thread_delay(8);
				
				sprintf(acBuf, "%08x", inpw(REG_GPIOB_OE));
				AddHttpValue(pReturnXML, "REG_GPIOB_OE", acBuf);
				sprintf(acBuf, "%08x", inpw(REG_GPIOB_DAT));
				AddHttpValue(pReturnXML, "REG_GPIOB_DAT", acBuf);
			}
			else if (strcmp(pcAction, "mall") == 0)
			{
				struct mallinfo info = mallinfo();
				AddHttpNum(pReturnXML, "arena", info.arena);
				AddHttpNum(pReturnXML, "ordblks", info.ordblks);
				AddHttpNum(pReturnXML, "smblks", info.smblks);
				AddHttpNum(pReturnXML, "hblks", info.hblks);
				AddHttpNum(pReturnXML, "hblkhd", info.hblkhd);
				AddHttpNum(pReturnXML, "usmblks", info.usmblks);
				AddHttpNum(pReturnXML, "fsmblks", info.fsmblks);
				AddHttpNum(pReturnXML, "uordblks", info.uordblks);
				AddHttpNum(pReturnXML, "fordblks", info.fordblks);
				AddHttpNum(pReturnXML, "keepcost", info.keepcost);
				AddHttpNum(pReturnXML, "maxfree", info.maxfree);
			}
			else if (strcmp(pcAction, "write_mp4") == 0)
			{
				UINT32 uBitrate = httpGetLong(pParamList, "bitrate");
				wb702SetVideoDynamicBitrate(uBitrate);
				sprintf(acBuf, "%d", uBitrate);
				AddHttpValue(pReturnXML, "bitrate", acBuf);
			}
			else if (strcmp(pcAction, "read_flash") == 0)
			{
				UINT32 uAddr = httpGetLong(pParamList, "address");
				UINT32 uSize = httpGetLong(pParamList, "size");
				if (uSize == 0)
					uSize = 1;
				sprintf(acBuf, "%08x[->%08x]", uAddr, uSize);
				AddHttpValue(pReturnXML, "read_flash", acBuf);
				
				for (i = 0; i < uSize; i += 8)
				{
					int j;
					char acFlash[8];
					UINT32 uThisSize = uSize - i;
					if (uThisSize > sizeof(acFlash))
						uThisSize = sizeof(acFlash);
										
					usiMyRead(uAddr + i, uThisSize, (void *)acFlash);
					
					acBuf[0] = '\0';
					nLen = 0;
					for (j = 0; j < uThisSize; ++j)
						nLen += sprintf(acBuf + nLen, "%02x ", (int)(unsigned char)(acFlash[j]) );
					AddHttpValue(pReturnXML, "read_flash", acBuf);
				}
				return 0;				
			}
			else if (strcmp(pcAction, "read_mem") == 0)
			{
				UINT32 uAddr = httpGetLong(pParamList, "address");
				UINT32 uSize = httpGetLong(pParamList, "size");
				if (uSize == 0)
					uSize = 1;
				sprintf(acBuf, "%08x[->%08x]", uAddr, uSize);
				AddHttpValue(pReturnXML, "read_mem", acBuf);
				acBuf[0] = '\0';
				for (i = 0; i < uSize; ++i)
				{
					nLen += sprintf(acBuf + nLen, "%02x ", (int)*(unsigned char *)(uAddr + i) );
					if (( i + 1 ) % 8 == 0)
					{
						AddHttpValue(pReturnXML, "read_mem", acBuf);
						nLen = 0;
						acBuf[0] = '\0';
					}
				}
				if ( i % 8 != 0)
					AddHttpValue(pReturnXML, "read_mem", acBuf);
				return 0;				
			}
			else if (strcmp(pcAction, "write_mem") == 0)
			{
				UINT32 uAddr = httpGetLong(pParamList, "address");
				UINT32 uValue = httpGetLong(pParamList, "value");
				UINT32 uSize = httpGetLong(pParamList, "size");
				if (uSize == 0)
					uSize = 4;
				memcpy((char *)uAddr, &uValue, uSize);
				sprintf(acBuf, "%08x[->%08x]=%08x", uAddr,uSize,uValue);
				AddHttpValue(pReturnXML, "write_mem", acBuf);
				return 0;
			}
			else if (strcmp(pcAction, "write_register") == 0)
			{
				UINT32 uAddr = httpGetULong(pParamList, "address");
				UINT32 uValue = httpGetULong(pParamList, "value");
				UINT32 uSize = httpGetULong(pParamList, "size");
				if (uSize == 0)
					uSize = 4;
				//outpw(address, value);
				memcpy((char *)uAddr, &uValue, uSize);
				sprintf(acBuf, "%08x[->%08x]=%08x", uAddr,uSize,uValue);
				AddHttpValue(pReturnXML, "write_register", acBuf);
				return 0;
			}
#if 1			
			else if (strcmp(pcAction, "set_oe") == 0)
			{
				UINT32 out = httpGetULong(pParamList, "out");
				UINT32 dir = httpGetULong(pParamList, "dir");
				UINT32 uSize = httpGetULong(pParamList, "size");
				
				UINT32 read_oe=0;
				UINT32 read_dat=0;
				UINT32 read_sts=0;

				if (uSize == 0)
					uSize = 4;
				//outpw(address, value);
				if(out==5 || out==18|| out ==0||out==1 )   // gpio5 is out1, gpio18 is out2
				{
					if(dir==1)
						outpw(REG_GPIO_OE, inpw(REG_GPIO_OE)|(1<<out));
					else
						outpw(REG_GPIO_OE, inpw(REG_GPIO_OE)&~(1<<out));
				}
				
				read_oe = inpw(REG_GPIO_OE);
				read_dat = inpw(REG_GPIO_DAT);
				read_sts = inpw(REG_GPIO_STS);
					
				sprintf(acBuf, "%08xoe[%08xdat]%08xsts", read_oe,read_dat,read_sts);
				AddHttpValue(pReturnXML, "set_oe", acBuf);
				return 0;
			}
			
			else if (strcmp(pcAction, "set_dat") == 0)
			{
				UINT32 out = httpGetULong(pParamList, "out");
				UINT32 dat = httpGetULong(pParamList, "dat");
				UINT32 uSize = httpGetULong(pParamList, "size");
				
				UINT32 read_oe=0;
				UINT32 read_dat=0;
				UINT32 read_sts=0;

				if (uSize == 0)
					uSize = 4;
				//outpw(address, value);
				if(out==5 || out==18)   // gpio5 is out1, gpio18 is out2
				{
					if(dat==1)
						outpw(REG_GPIO_DAT, inpw(REG_GPIO_DAT)|(1<<out));
					else
						outpw(REG_GPIO_DAT, inpw(REG_GPIO_DAT)&~(1<<out));
				}
				
				read_oe = inpw(REG_GPIO_OE);
				read_dat = inpw(REG_GPIO_DAT);
				read_sts = inpw(REG_GPIO_STS);
					
				sprintf(acBuf, "%08xoe[%08xdat]%08xsts", read_oe,read_dat,read_sts);
				AddHttpValue(pReturnXML, "set_dat", acBuf);
				return 0;
			}
			
			else if (strcmp(pcAction, "get_oe") == 0)
			{
				UINT32 uAddr = httpGetULong(pParamList, "address");
				UINT32 uValue = httpGetULong(pParamList, "value");
				UINT32 uSize = httpGetULong(pParamList, "size");
				UINT32 read_oe=0;
				UINT32 read_dat=0;
				UINT32 read_sts=0;
	
				if (uSize == 0)
					uSize = 4;
				read_oe = inpw(REG_GPIO_OE);
				read_dat = inpw(REG_GPIO_DAT);
				read_sts = inpw(REG_GPIO_STS);
				sprintf(acBuf, "%08xoe[%08xdat]%08xsts", read_oe,read_dat,read_sts);
				AddHttpValue(pReturnXML, "get_oe", acBuf);
				return 0;
			}
#endif			
			else if (strcmp(pcAction, "read_i2c") == 0)
			{
				UINT32 uAddr = httpGetLong(pParamList, "address");
				UINT32 uValue = i2cReadI2C(uAddr);
				sprintf(acBuf, "%08x=%08x", uAddr, uValue);
				AddHttpValue(pReturnXML, "read_i2c", acBuf);
				return 0;
			}
			else if (strcmp(pcAction, "write_i2c") == 0)
			{
				UINT32 uAddr = httpGetLong(pParamList, "address");
				UINT32 uValue = httpGetLong(pParamList, "value");
				i2cWriteI2C (uAddr, uValue);
				sprintf(acBuf, "%08x=%08x", uAddr, uValue);
				AddHttpValue(pReturnXML, "write_i2c", acBuf);
				return 0;
			}
			else if (strcmp(pcAction, "debug") == 0)
			{
			}
			else
				AddHttpValue(pReturnXML, "action", "error");
			return 0;
		}		
	}
	return -1;
}
Esempio n. 4
0
int Config_GetIP(HTTPCONNECTION hConnection, LIST *pParamList, int iAction, XML *pReturnXML)
{
	char ac[128];
	int i;
	const char *pcInterface;
	int iInterface;
	unsigned long ulClientIP;
	ulClientIP = httpGetClientAddr(hConnection).s_addr;

	switch (iAction)
	{
	case CA_AUTH:
		if (ulClientIP == 0x0100007f) return AUTH_ANY;
		else return AUTH_USER;
		break;
	case CA_CONFIG:
		tt_rmutex_lock(&g_rmutex);
		AddHttpValue(pReturnXML, G_PC_CAMERANAME, g_ConfigParam.acCameraName);
		for (i = 0; i < 3; i++)
		{
			char acName[8];
			sprintf(acName, G_PC_DNS_N, i); 
			httpIP2String(g_ConfigParam.aulAsDNS[i], ac);
			AddHttpValue(pReturnXML, acName, ac);
		}
#ifndef WLAN
		if (!httpIsExistParam(pParamList, G_PC_INTERFACE))
			pcInterface = g_apcNetworkInterface[0];
#else
		if (!httpIsExistParam(pParamList, G_PC_INTERFACE))
			pcInterface = g_apcNetworkInterface[1];
#endif
		else pcInterface = httpGetString(pParamList, G_PC_INTERFACE);
		for (iInterface = 0;
			iInterface < sizeof(g_apcNetworkInterface) / sizeof(const char *);
			iInterface++)
			if (strcasecmp(g_apcNetworkInterface[iInterface], pcInterface) == 0)
				break;

		if (iInterface < sizeof(g_apcNetworkInterface) / sizeof(const char *))
		{
			httpLong2String(g_ConfigParam.abAsNetEnable[iInterface], ac);
			AddHttpValue(pReturnXML, G_PC_ENABLE, ac);
			AddHttpValue(pReturnXML, G_PC_IPWAY,
					(g_ConfigParam.aucIPAssignedWay[iInterface] == IP_ASSIGNMENT_MANUALLY?"manually":"dhcp")
				);
			httpIP2String(g_ConfigParam.ulAsIPAddress[iInterface], ac);				
			AddHttpValue(pReturnXML, G_PC_IP, ac);
			httpIP2String(g_ConfigParam.ulAsNetmask[iInterface], ac);
			AddHttpValue(pReturnXML, G_PC_NETMASK, ac);
			httpIP2String(g_ConfigParam.ulAsGateway[iInterface], ac);
			AddHttpValue(pReturnXML, G_PC_GATEWAY, ac);
		}
		
		
		{
			unsigned long ulCurrentIP;
			unsigned long ulCurrentSubnetMask;
			unsigned long ulCurrentGateway;
			unsigned long ulCurrentDNSServer[3];
			enum SET_IP_STATE_E ipState;
			GetPubIPInfo(&ulCurrentIP, &ulCurrentSubnetMask, &ulCurrentGateway, ulCurrentDNSServer);
			httpIP2String(ulCurrentIP, ac);
			AddHttpValue(pReturnXML, "CurrentIP", ac);
			httpIP2String(ulCurrentSubnetMask, ac);
			AddHttpValue(pReturnXML, "CurrentNetmask", ac);
			httpIP2String(ulCurrentGateway, ac);
			AddHttpValue(pReturnXML, "CurrentGateway", ac);
			
			for (i = 0; i < 3; i++)
			{
				char acName[16];
				sprintf(acName, "CurrentDNS%d", i);
				httpIP2String(ulCurrentDNSServer[i], ac);
				AddHttpValue(pReturnXML, acName, ac);
			}
			
			
			wsp_get_config_state(NULL, &ipState);
			switch(ipState)
			{
			case SET_IP__DHCP_TRYING:
				AddHttpValue(pReturnXML, "CurrentIPState", "DHCP_TRYING");
				break;
			case SET_IP__DHCP_FAILED:
				AddHttpValue(pReturnXML, "CurrentIPState", "DHCP_FAILED");
				break;
			case SET_IP__DHCP_OK:
				AddHttpValue(pReturnXML, "CurrentIPState", "DHCP_OK");
				break;
			case SET_IP__STATIC_IP_TRYING:
				AddHttpValue(pReturnXML, "CurrentIPState", "STATIC_IP_TRYING");
				break;
			case SET_IP__STATIC_IP_FAILED:
				AddHttpValue(pReturnXML, "CurrentIPState", "STATIC_IP_FAILED");
				break;
			case SET_IP__STATIC_IP_OK:
				AddHttpValue(pReturnXML, "CurrentIPState", "STATIC_IP_OK");
				break;
			default:
				AddHttpValue(pReturnXML, "CurrentIPState", "NO_INIT");		
			}
		}
		tt_rmutex_unlock(&g_rmutex);
		return 0;
		break;
	}
	return -1;
}
Esempio n. 5
0
BOOL SetIP(enum SET_IP_STATE_E *pIPState)
{
		enum SET_IP_STATE_E ipState;
		BOOL bOK = TRUE;
		int i;
		BOOL bEnable[2];
		
		if (pIPState == NULL)
			pIPState = &ipState;
		
		bEnable[0] = g_ConfigParam.abAsNetEnable[0];
		bEnable[1] = g_ConfigParam.abAsNetEnable[1];
#ifndef WLAN
		if (!bEnable[0] && !bEnable[1]) bEnable[0] = TRUE;
#else
		if (!bEnable[0] && !bEnable[1]) bEnable[1] = TRUE;
#endif
		for (i = sizeof(g_apcNetworkInterface) / sizeof(const char *) - 1; i >= 0; i--)
		{
			const char *pcInterface;
			if (!bEnable[i]) continue;
			pcInterface = g_apcNetworkInterface[i];
			
			if (g_ConfigParam.aucIPAssignedWay[i] == IP_ASSIGNMENT_MANUALLY)
			{	
				struct bootp wlan_bootp_data;
    			int j = 0;
				char ipadd[16];
				char netmask[16];
				char gateway[16];
				char broadcast[16];
				httpIP2String(g_ConfigParam.ulAsIPAddress[i],ipadd);
				httpIP2String(g_ConfigParam.ulAsNetmask[i],netmask);
				httpIP2String(g_ConfigParam.ulAsGateway[i],gateway);
				httpIP2String((~g_ConfigParam.ulAsNetmask[i])|g_ConfigParam.ulAsIPAddress[i],broadcast);
				
				*pIPState = SET_IP__STATIC_IP_TRYING;
				DownInterface(pcInterface);
				
				diag_printf("IP is %s, NetMask is %s, Gateway is %s,Broadcast is %s\n",ipadd,netmask,gateway,broadcast);
       			build_bootp_record(&wlan_bootp_data, pcInterface,
                           ipadd, netmask,broadcast,gateway,gateway);
    			show_bootp(pcInterface, &wlan_bootp_data);

    			if (!init_net(pcInterface, &wlan_bootp_data)) 
    			{
    				*pIPState = SET_IP__STATIC_IP_FAILED;
    				diag_printf("failed for %s\n",pcInterface);
    			}
    			else
	   				*pIPState = SET_IP__STATIC_IP_OK;
				/* Set DNS server */
				if (g_ConfigParam.aulAsDNS[0] != 0)
				{
					struct in_addr dns_server;
					dns_server.s_addr = (g_ConfigParam.aulAsDNS[0]);
					cyg_dns_res_init(&dns_server);
				}

    			for(;j<5;j++)
					init_loopback_interface(0);
				
				
			}
			else         
			{	
#ifndef WLAN
					//WRRunDHCPClient(pcInterface, TRUE);
#else				
					int j = 0;
					
					*pIPState = SET_IP__DHCP_TRYING;
					DownInterface(pcInterface);
					
					diag_printf("Set IP by dhcp\n");
					g_WebCamState.bDHCP_Finished = FALSE;
					init_all_network_interfaces();	
					for(;j<5;j++)
						init_loopback_interface(0);
					
					if (wlan0_dhcpstate != DHCPSTATE_BOOTP_FALLBACK
						&& wlan0_dhcpstate != DHCPSTATE_BOUND)
					{
						bOK = FALSE;
						SetRandomIP("wlan0");
						*pIPState = SET_IP__DHCP_FAILED;
					}
					else
						*pIPState = SET_IP__DHCP_OK;

					g_WebCamState.bDHCP_Finished = TRUE;
						
#endif
			}
		}
		/*display the ip address*/
		{
			unsigned long ulIP;
			
			
			GetPubIPInfo(&ulIP, NULL, NULL, NULL);
			diag_printf("******************ip Address====%x\n", ulIP); 
			if (bOK)
			{
				if (g_ConfigParam.ucWlanOperationMode == 1)	/* Disable suspend in Ad-hoc mode */
					g_netIsSuspendAllowed = FALSE;
				else
					g_netIsSuspendAllowed = TRUE;
			}

			diag_printf("bOK=%d\n", bOK);
			if (!bOK)
				return FALSE;
			else
				OnSetIP();
		}		

	return TRUE;
}