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; }
int Config_SetPPP(HTTPCONNECTION hConnection, LIST *pParamList, int iAction, XML *pReturnXML) { BOOL bConfigChanged = FALSE; BOOL bPPPEnable; const char *apcPPPServer[ sizeof(g_ConfigParam.aacPPPServer) / sizeof(g_ConfigParam.aacPPPServer[0])]; int aiPPPPort[ sizeof(g_ConfigParam.aiPPPPort) / sizeof(g_ConfigParam.aiPPPPort[0])]; const char *pcPPPUser; const char *pcPPPPass; int i; switch (iAction) { case CA_AUTH: return AUTH_ADMIN; case CA_CONFIG: if (httpIsExistParam(pParamList, "Enable")) bPPPEnable = httpGetBool(pParamList, "Enable"); else bPPPEnable = g_ConfigParam.bPPPEnable; if (bPPPEnable != g_ConfigParam.bPPPEnable) bConfigChanged = TRUE; for (i = 0; i < sizeof(g_ConfigParam.aacPPPServer) / sizeof(g_ConfigParam.aacPPPServer[0]); ++i) { char acName[32]; snprintf(acName, sizeof(acName), "Server%d", i); apcPPPServer[i] = g_ConfigParam.aacPPPServer[i]; if (httpIsExistParam(pParamList, acName)) { apcPPPServer[i] = httpGetString(pParamList, acName); if (strcmp(apcPPPServer[i], g_ConfigParam.aacPPPServer[i]) != 0) bConfigChanged = TRUE; } } if (httpIsExistParam(pParamList, "Server")) { apcPPPServer[0] = httpGetString(pParamList, "Server"); if (strcmp(apcPPPServer[0], g_ConfigParam.aacPPPServer[0]) != 0) bConfigChanged = TRUE; } for (i = 0; i < sizeof(g_ConfigParam.aiPPPPort) / sizeof(g_ConfigParam.aiPPPPort[0]); ++i) { char acName[32]; snprintf(acName, sizeof(acName), "Port%d", i); aiPPPPort[i] = g_ConfigParam.aiPPPPort[i]; if (httpIsExistParam(pParamList, acName)) { aiPPPPort[i] = httpGetLong(pParamList, acName); if (aiPPPPort[i] != g_ConfigParam.aiPPPPort[i]) bConfigChanged = TRUE; } } if (httpIsExistParam(pParamList, "Port")) { aiPPPPort[0] = httpGetLong(pParamList, "Port"); if (aiPPPPort[0] != g_ConfigParam.aiPPPPort[0]) bConfigChanged = TRUE; } if (httpIsExistParam(pParamList, "User")) pcPPPUser = httpGetString(pParamList, "User"); else pcPPPUser = g_ConfigParam.acPPPUser; if (strcmp(pcPPPUser, g_ConfigParam.acPPPUser) != 0) bConfigChanged = TRUE; if (httpIsExistParam(pParamList, "Pass")) pcPPPPass = httpGetString(pParamList, "Pass"); else pcPPPPass = g_ConfigParam.acPPPPass; if (strcmp(pcPPPPass, g_ConfigParam.acPPPPass) != 0) bConfigChanged = TRUE; if (bConfigChanged) { tt_rmutex_lock(&g_rmutex); g_ConfigParam.bPPPEnable = bPPPEnable; for (i = 0; i < sizeof(g_ConfigParam.aacPPPServer) / sizeof(g_ConfigParam.aacPPPServer[0]); ++i) httpMyStrncpy(g_ConfigParam.aacPPPServer[i], apcPPPServer[i], sizeof(g_ConfigParam.aacPPPServer[i])); for (i = 0; i < sizeof(g_ConfigParam.aiPPPPort) / sizeof(g_ConfigParam.aiPPPPort[0]); ++i) g_ConfigParam.aiPPPPort[i] = aiPPPPort[i]; httpMyStrncpy(g_ConfigParam.acPPPUser, pcPPPUser, sizeof(g_ConfigParam.acPPPUser)); httpMyStrncpy(g_ConfigParam.acPPPPass, pcPPPPass, sizeof(g_ConfigParam.acPPPPass)); tt_rmutex_unlock(&g_rmutex); WriteFlashMemory(&g_ConfigParam); } if (!bPPPEnable) { /* Disconnect if possible */ //if (ppot_is_connecting()) ppot_disconnect(); } if(bPPPEnable && bConfigChanged) //&& !ppot_is_connecting()) { ppot_connect(apcPPPServer, aiPPPPort, sizeof(apcPPPServer) / sizeof(apcPPPServer[0]), pcPPPUser, pcPPPPass); } return 0; break; } return -1; }