Beispiel #1
0
void
net_test(cyg_addrword_t param)
{
    cyg_serial_baud_rate_t old;    
    cyg_ppp_options_t options;
    cyg_ppp_handle_t ppp_handle;

    CYG_TEST_INIT();
    
    diag_printf("Start TCP test - ECHO mode\n");
    init_all_network_interfaces();
    calibrate_load(DESIRED_BACKGROUND_LOAD);
#ifdef CYGPKG_SNMPAGENT
    {
        extern void cyg_net_snmp_init(void);
        cyg_net_snmp_init();
    }
#endif

    old = ppp_test_set_baud( CYGNUM_SERIAL_BAUD_115200 );

    ppp_test_announce( "TCP_ECHO" );
    
    cyg_ppp_options_init( &options );

//    options.debug = 1;
//    options.kdebugflag = 1;
//    options.flowctl = CYG_PPP_FLOWCTL_SOFTWARE;

    ppp_handle = cyg_ppp_up( CYGPKG_PPP_TEST_DEVICE, &options );

    CYG_TEST_INFO( "Waiting for PPP to come up");
    
    cyg_ppp_wait_up( ppp_handle );

    echo_test(param);

    CYG_TEST_INFO( "Bringing PPP down");

    cyg_ppp_down( ppp_handle );
    
    CYG_TEST_INFO( "Waiting for PPP to go down");

    cyg_ppp_wait_down( ppp_handle );

    cyg_thread_delay( 200 );
    
    ppp_test_set_baud( old );

    ppp_test_finish();
    
    CYG_TEST_PASS_FINISH("TCP ECHO test OK");
}
Beispiel #2
0
static void do_test( cyg_serial_baud_rate_t baud )
{
    cyg_ppp_options_t options;
    cyg_ppp_handle_t ppp_handle;
    int i = 0;

    ppp_test_announce( "PPP_UP" );
    
    cyg_ppp_options_init( &options );

//    options.debug = 1;
//    options.kdebugflag = 1;

    options.baud = baud;
    
    show_network_tables( diag_printf );
    
    ppp_handle = cyg_ppp_up( CYGPKG_PPP_TEST_DEVICE, &options );

    CYG_TEST_INFO( "Waiting for PPP to come up");
    
    cyg_ppp_wait_up( ppp_handle );

    CYG_TEST_INFO( "Waiting until remote end goes down");

    while( cyg_ppp_wait_up( ppp_handle ) == 0 )
    {
        i++;

        if( (i % 60) == 0 )
            show_network_tables( diag_printf );

        cyg_thread_delay(100);
    }
    
    cyg_ppp_wait_down( ppp_handle );
}
Beispiel #3
0
int main(int argc, char **argv)
{
     // Bring up the TCP/IP network
     init_all_network_interfaces();
     
     for (;;)
     {
          cyg_ppp_options_t options;
          cyg_ppp_handle_t ppp_handle;
          
          // Initialize the options
          cyg_ppp_options_init( &options );
          
          options.script=windows_script;
          options.baud = CYGNUM_SERIAL_BAUD_38400;
          options.flowctl = CYG_PPP_FLOWCTL_NONE;
          options.idle_time_limit = 0; // never shut down.      
          
          // Start up PPP
          ppp_handle = cyg_ppp_up( "/dev/ser0", &options );
          
          // Wait for it to get running
          if( cyg_ppp_wait_up( ppp_handle ) == 0 )
          {
               // Make use of PPP
               for (;;)
               {
                    telnet();
               }
               
               // never reached, but  for illustration:
               
               // Bring PPP link down
               cyg_ppp_down( ppp_handle );
               
               // Wait for connection to go down.
               cyg_ppp_wait_down( ppp_handle );
          }
     }
}
Beispiel #4
0
void
net_test(test_param_t param)
{
#ifdef __ECOS
    cyg_serial_baud_rate_t old;    
    cyg_ppp_options_t options;
    cyg_ppp_handle_t ppp_handle;

    CYG_TEST_INIT();
#endif

//    int i;
    if (param == 0) {
        test_printf("Start Network Characterization - SLAVE\n");
#ifdef __ECOS
        init_all_network_interfaces();
        calibrate_load(DESIRED_BACKGROUND_LOAD);
#if 0
// I can see what this is trying to do, but I get "bind: Address already in
// use" errors from the 2nd interface - and the parameter is not used
// anyway, so one thread does quite well enough (but only tests one i/f at
// once).

// Comment in the 'int i' above too.
        for (i = 1;  i < CYGHWR_NET_DRIVERS;  i++) {
            cyg_thread_resume(main_thread_handle[i]);   // Start other threads
        }
#endif
#endif
    }

#ifdef __ECOS

    old = ppp_test_set_baud( CYGNUM_SERIAL_BAUD_115200 );

    ppp_test_announce( "NC_TEST_SLAVE" );
    
    cyg_ppp_options_init( &options );

//    options.debug = 1;
//    options.kdebugflag = 1;

//    options.script = script;
//    options.flowctl = CYG_PPP_FLOWCTL_SOFTWARE;

    ppp_handle = cyg_ppp_up( CYGPKG_PPP_TEST_DEVICE, &options );

    CYG_TEST_INFO( "Waiting for PPP to come up");
    
    cyg_ppp_wait_up( ppp_handle );
#endif
    
    nc_slave(param);
#ifdef CYGDBG_NET_TIMING_STATS
    show_net_times();
#endif

#ifdef __ECOS
    CYG_TEST_INFO( "Bringing PPP down");

    cyg_ppp_down( ppp_handle );
    
    CYG_TEST_INFO( "Waiting for PPP to go down");

    cyg_ppp_wait_down( ppp_handle );

    cyg_thread_delay( 200 );

    ppp_test_set_baud( old );

    ppp_test_finish();

    CYG_TEST_PASS_FINISH( "Network Characterization - SLAVE" );
    
#endif
    
    cyg_test_exit();
}
Beispiel #5
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;
}