int Config_GetPPP(HTTPCONNECTION hConnection, LIST *pParamList, int iAction, XML *pReturnXML) { int i; switch (iAction) { case CA_AUTH: return AUTH_USER; case CA_CONFIG: tt_rmutex_lock(&g_rmutex); AddHttpNum(pReturnXML, "Enable", g_ConfigParam.bPPPEnable); for (i = 0; i < sizeof(g_ConfigParam.aacPPPServer) / sizeof(g_ConfigParam.aacPPPServer[0]); ++i) { char acName[32]; snprintf(acName, sizeof(acName), "Server%d", i); AddHttpValue(pReturnXML, acName, g_ConfigParam.aacPPPServer[i]); } for (i = 0; i < sizeof(g_ConfigParam.aiPPPPort) / sizeof(g_ConfigParam.aiPPPPort[0]); ++i) { char acName[32]; snprintf(acName, sizeof(acName), "Port%d", i); AddHttpNum(pReturnXML, acName, g_ConfigParam.aiPPPPort[i]); } AddHttpValue(pReturnXML, "User", g_ConfigParam.acPPPUser); AddHttpValue(pReturnXML, "Pass", g_ConfigParam.acPPPPass); AddHttpValue(pReturnXML, "Status", (ppot_is_online() ? "online" : "offline")); tt_rmutex_unlock(&g_rmutex); return 0; } return -1; }
int Config_ScanWlan(HTTPCONNECTION hConnection, LIST *pParamList, int iAction, XML *pReturnXML) { ApScanResult ScanAp[32]; int nLen = 0; int i; request *req = (request*)hConnection; switch (iAction) { case CA_AUTH: return AUTH_USER; case CA_CONFIG: // get wireless ap if (ictlScanAP((ICTL_HANDLE_T*)&req->httpPrivilege,ScanAp,&nLen,32) == ICTL_OK) { // get ap information for(i = 0; i < nLen; i++) { int nQuality; AddHttpValue(pReturnXML, G_PC_ESSID, ScanAp[i].ssid); AddHttpValue(pReturnXML, G_PC_MODE, g_apcWlanOperationMode[(ScanAp[i].mode >= 0 && ScanAp[i].mode < sizeof(g_apcWlanOperationMode) / sizeof(const char *)) ? ScanAp[i].mode : 0]); AddHttpNum(pReturnXML, "Encode", (ScanAp[i].encode == 0 ? 0 : 1)); //nQuality = ScanAp[i].noise + ScanAp[i].signal; //if (nQuality != 0) // nQuality = ScanAp[i].signal * 100 / nQuality; nQuality = (int)(signed char)ScanAp[i].signal; /* RSSI >= -55 ==> Excellent -65 <= RSSI < -55 ==> Very Good -75 <= RSSI < -65 ==> Good -85 <= RSSI < -75 ==> Low RSSI < -85 ==> Poor */ if (nQuality > 0) nQuality = 0; else if (nQuality >= -55) nQuality = 90 + 10 * (nQuality + 55) / 55; else if (nQuality >= -85) nQuality = 10 + 80 * (nQuality + 85) / (85 - 55); else nQuality = 10 * (nQuality + 128) / (128 - 85); AddHttpNum(pReturnXML, "Quality", nQuality); //AddHttpNum(pReturnXML, "Noise", (int)(signed char)ScanAp[i].noise); } } return 0; } return -1; }
int Config_GetMac(HTTPCONNECTION hConnection, LIST *pParamList, int iAction, XML *pReturnXML) { char ac[20]; int i; request *req = (request*)hConnection; switch (iAction) { case CA_AUTH: return AUTH_USER; case CA_CONFIG: ictlGetMac((ICTL_HANDLE_T*)&req->httpPrivilege,ac,sizeof(ac)); for (i = 5; i >= 0; --i) { httpChar2Hex(ac[i], &ac[i*3+0]); if (i != 5) ac[i*3+2] = ':'; else ac[i*3+2] = '\0'; } AddHttpValue(pReturnXML, G_PC_MAC, ac); return 0; } return -1; }
// Accept the SSTP connection bool AcceptSstp(CONNECTION *c) { SOCK *s; HTTP_HEADER *h; char date_str[MAX_SIZE]; bool ret; bool ret2 = false; SOCK_EVENT *se; // Validate arguments if (c == NULL) { return false; } s = c->FirstSock; GetHttpDateStr(date_str, sizeof(date_str), SystemTime64()); // Return a response h = NewHttpHeader("HTTP/1.1", "200", "OK"); AddHttpValue(h, NewHttpValue("Content-Length", "18446744073709551615")); AddHttpValue(h, NewHttpValue("Server", "Microsoft-HTTPAPI/2.0")); AddHttpValue(h, NewHttpValue("Date", date_str)); ret = PostHttp(s, h, NULL, 0); FreeHttpHeader(h); if (ret) { SetTimeout(s, INFINITE); se = NewSockEvent(); JoinSockToSockEvent(s, se); Debug("ProcessSstpHttps Start.\n"); ret2 = ProcessSstpHttps(c->Cedar, s, se); Debug("ProcessSstpHttps End.\n"); ReleaseSockEvent(se); } Disconnect(s); return ret2; }
int Config_EnableTestNet(HTTPCONNECTION hConnection, LIST *pParamList, int iAction, XML *pReturnXML) { unsigned short usPort; switch (iAction) { case CA_AUTH: return AUTH_ADMIN; case CA_CONFIG: usPort = httpGetLong(pParamList, "port"); if (usPort >= 100 && TestNet_ThreadInit(usPort)) AddHttpValue(pReturnXML, "Result", "true"); else AddHttpValue(pReturnXML, "Result", "false"); return 0; } return -1; }
int Config_GetLogo(HTTPCONNECTION hConnection, LIST *pParamList, int iAction, XML *pReturnXML) { char ac[128]; switch (iAction) { case CA_AUTH: return AUTH_USER; case CA_CONFIG: AddHttpValue(pReturnXML, G_PC_SHOWSTRING, g_ConfigParam.ShowString[0]); httpLong2String((int)g_ConfigParam.ShowPos[0], ac); AddHttpValue(pReturnXML, G_PC_SHOWPOS, ac); AddHttpValue(pReturnXML, G_PC_SHOWSTRING, g_ConfigParam.ShowString[1]); httpLong2String((int)g_ConfigParam.ShowPos[1], ac); AddHttpValue(pReturnXML, G_PC_SHOWPOS, ac); return 0; } return -1; }
int Config_GetVer(HTTPCONNECTION hConnection, LIST *pParamList, int iAction, XML *pReturnXML) { switch (iAction) { case CA_AUTH: return AUTH_USER; case CA_CONFIG: AddHttpValue(pReturnXML, "Version", WRGetProductVersion()); return 0; } return -1; }
int Config_GetUPnP(HTTPCONNECTION hConnection, LIST *pParamList, int iAction, XML *pReturnXML) { char acIP[32]; unsigned short ausPort[5]; int iSuccessNum; int i; switch (iAction) { case CA_AUTH: return AUTH_USER; case CA_CONFIG: iSuccessNum = upnp_get_port(0, ausPort); //AddHttpNum(pReturnXML, "Rt0", iSuccessNum); if (iSuccessNum < 0) iSuccessNum = 0; for (i = iSuccessNum; i < sizeof(ausPort) / sizeof(ausPort[0]); ++i) ausPort[i] = 0; if ((iSuccessNum = upnp_get_extip(0, acIP)) < 0) acIP[0] = 0; //AddHttpNum(pReturnXML, "Rt1", iSuccessNum); tt_rmutex_lock(&g_rmutex); AddHttpNum(pReturnXML, "Enable", g_ConfigParam.bEnableUPnP); AddHttpNum(pReturnXML, "Port", (int) (g_ConfigParam.usUPnPPort == 0 ? DEFAULT_UPNP_FIRST_EXT_PORT : g_ConfigParam.usUPnPPort)); AddHttpValue(pReturnXML, "WatchdogIP", g_ConfigParam.acWatchdogIP); tt_rmutex_unlock(&g_rmutex); AddHttpValue(pReturnXML, "IP", acIP); AddHttpNum(pReturnXML, "HTTP", (int)ausPort[0]); AddHttpNum(pReturnXML, "RTSP_TCP", (int)ausPort[1]); AddHttpNum(pReturnXML, "RTSP_UDP", (int)ausPort[2]); return 0; } return -1; }
int Config_ControlMCU(HTTPCONNECTION hConnection, LIST *pParamList, int iAction, XML *pReturnXML) { switch (iAction) { case CA_AUTH: return AUTH_USER; break; case CA_CONFIG: if (!httpIsExistParam(pParamList, "parameters")) AddHttpValue(pReturnXML, "responses", "error"); else { request *req = (request*)hConnection; const char *pcMCU; char acResponse[257 * 2 + 1]; pcMCU = httpGetString(pParamList, "parameters"); //diag_printf("MCU = %s\n", pcMCU); if (strlen(pcMCU) != ((int)(unsigned char)httpHex2Char(pcMCU) + 1)*2) AddHttpValue(pReturnXML, "responses", "error_length"); else if (ictlCtrlMCU((ICTL_HANDLE_T*)&req->httpPrivilege, pcMCU + 2, acResponse + 2, sizeof(acResponse) - 2) != ICTL_OK) AddHttpValue(pReturnXML, "responses", "error_response"); else { int nLength = strlen(acResponse + 2) / 2; char acHex[4]; httpChar2Hex(nLength, acHex); memcpy(acResponse, acHex, 2); AddHttpValue(pReturnXML, "responses", acResponse); } return 0; } break; } return -1; }
int Config_GetTime(HTTPCONNECTION hConnection, LIST *pParamList, int iAction, XML *pReturnXML) { char ac[128]; long lTime1970_InSec; long lTimeZone_InSec; switch (iAction) { case CA_AUTH: return AUTH_USER; case CA_CONFIG: GetCheckedTime(&lTime1970_InSec, &lTimeZone_InSec); httpLong2String(lTime1970_InSec, ac); AddHttpValue(pReturnXML, G_PC_SEC1970, ac); httpLong2String(lTimeZone_InSec / 60, ac); AddHttpValue(pReturnXML, G_PC_TIMEZONE, ac); AddHttpValue(pReturnXML, G_PC_NTPSERVER, g_ConfigParam.acNtpServer); httpLong2String((int)g_ConfigParam.bUseNtp, ac); AddHttpValue(pReturnXML, G_PC_USENTP, ac); return 0; } return -1; }
int Config_GetName(HTTPCONNECTION hConnection, LIST *pParamList, int iAction, XML *pReturnXML) { switch (iAction) { case CA_AUTH: return AUTH_USER; break; case CA_CONFIG: AddHttpValue(pReturnXML, G_PC_CAMERANAME, g_ConfigParam.acCameraName); return 0; break; } return -1; }
int Config_GetStatus(HTTPCONNECTION hConnection, LIST *pParamList, int iAction, XML *pReturnXML) { char pcBuf[128]; switch (iAction) { case CA_AUTH: return AUTH_USER; case CA_CONFIG: SetRunTimeState(hConnection); cyg_mutex_lock(&g_ptmState); GetWebCamStateString(&g_WebCamState, pcBuf); cyg_mutex_unlock(&g_ptmState); AddHttpValue(pReturnXML, "Status", pcBuf); return 0; } return -1; }
int Config_GetWlan(HTTPCONNECTION hConnection, LIST *pParamList, int iAction, XML *pReturnXML) { int iLen; char ac[128]; int i; int j; //prism_cnfDesireSSID_t *pESSIDList; //int iESSIDNum; switch (iAction) { case CA_AUTH: return AUTH_USER; case CA_CONFIG: AddHttpValue(pReturnXML, G_PC_ESSID, (char *)g_ConfigParam.acWlanESSID); httpLong2String((int)g_ConfigParam.ulWlanChannel, ac); AddHttpValue(pReturnXML, G_PC_CHANNEL, ac); AddHttpValue(pReturnXML, G_PC_MODE, g_apcWlanOperationMode[((int)g_ConfigParam.ucWlanOperationMode >= 0 && (int)g_ConfigParam.ucWlanOperationMode < sizeof(g_apcWlanOperationMode) / sizeof(const char *)) ? (int)g_ConfigParam.ucWlanOperationMode : 0]); AddHttpValue(pReturnXML, G_PC_WEPSET, (g_ConfigParam.ucWepSet == WEP_SET_K64 ? "K64" : (g_ConfigParam.ucWepSet == WEP_SET_K128 ? "K128" : (g_ConfigParam.ucWepSet == WEP_SET_ASC ? "Asc": "Disable")))); AddHttpValue(pReturnXML, G_PC_WEPASC,(char*) g_ConfigParam.acWepAsc); AddHttpNum(pReturnXML, G_PC_WEPGROUP, 0); for (iLen = 0, j = 0; j < 5; j++) { iLen += sprintf(ac + iLen, "%02x", (int)g_ConfigParam.aacWep64[j]); } AddHttpValue(pReturnXML, G_PC_WEP64, ac); for (iLen = 0, j = 0; j < 13; j++) { iLen += sprintf(ac + iLen, "%02x", (int)g_ConfigParam.acWep128[j]); } AddHttpValue(pReturnXML, G_PC_WEP128, ac); return 0; } return -1; }
int Config_Reboot(HTTPCONNECTION hConnection, LIST *pParamList, int iAction, XML *pReturnXML) { unsigned long ulClientIP = httpGetClientAddr(hConnection).s_addr; switch (iAction) { case CA_AUTH: diag_printf("CA_AUTH Config_Reboot!\n"); if (ulClientIP == 0x0100007f) return AUTH_ANY; else return AUTH_ADMIN; break; case CA_CONFIG: #if 1 diag_printf("CA_CONFIG Config_Reboot!\n"); AddHttpValue(pReturnXML, G_PC_RT, "OK"); RebootOnConnectionOver(hConnection); #endif return 0; break; } return -1; }
int Config_GetHttp(HTTPCONNECTION hConnection, LIST *pParamList, int iAction, XML *pReturnXML) { int i; switch (iAction) { case CA_AUTH: return AUTH_USER; break; case CA_CONFIG: for (i = 0; i < sizeof(g_ConfigParam.usHttpPort) / sizeof(unsigned short); i++) { char acName[16]; char ac[64]; sprintf(acName, G_PC_PORT_N, i); httpLong2String(g_ConfigParam.usHttpPort[i], ac); AddHttpValue(pReturnXML, acName, ac); } return 0; break; } return -1; }
int Config_GetFtp(HTTPCONNECTION hConnection, LIST *pParamList, int iAction, XML *pReturnXML) { char ac[384]; switch (iAction) { case CA_AUTH: return AUTH_ADMIN; break; case CA_CONFIG: AddHttpValue(pReturnXML, G_PC_FTPSERVER, g_ConfigParam.acFtpServer); AddHttpValue(pReturnXML, G_PC_USER, g_ConfigParam.acFtpUser); AddHttpValue(pReturnXML, G_PC_PASS, g_ConfigParam.acFtpPass); AddHttpValue(pReturnXML, G_PC_ACCOUNT, g_ConfigParam.acFtpAccount); AddHttpValue(pReturnXML, G_PC_UPLOADPATH, g_ConfigParam.acFtpUploadPath); httpLong2String((int)g_ConfigParam.bFtpEnable, ac); AddHttpValue(pReturnXML, G_PC_ENABLE, ac); return 0; break; } return -1; }
int Config_GetWlan(HTTPCONNECTION hConnection, LIST *pParamList, int iAction, XML *pReturnXML) { int iLen; char ac[128]; int j; //prism_cnfDesireSSID_t *pESSIDList; //int iESSIDNum; switch (iAction) { case CA_AUTH: return AUTH_ADMIN; case CA_CONFIG: tt_rmutex_lock(&g_rmutex); AddHttpValue(pReturnXML, G_PC_ESSID, (char *)g_ConfigParam.acWlanESSID); AddHttpValue(pReturnXML, G_PC_MODE, g_apcWlanOperationMode[((int)g_ConfigParam.ucWlanOperationMode >= 0 && (int)g_ConfigParam.ucWlanOperationMode < sizeof(g_apcWlanOperationMode) / sizeof(const char *)) ? (int)g_ConfigParam.ucWlanOperationMode : 0]); AddHttpValue(pReturnXML, G_PC_KEY, (strlen((char *)g_ConfigParam.acWlanKey) > 0 ? "*" : "")); AddHttpNum(pReturnXML, G_PC_CHANNEL, g_ConfigParam.ulWlanChannel); /* Useless items */ #if 0 AddHttpValue(pReturnXML, G_PC_WEPSET, "Disable"); AddHttpValue(pReturnXML, G_PC_WEPASC, ""); AddHttpValue(pReturnXML, G_PC_WEPGROUP, ""); //AddHttpValue(pReturnXML, G_PC_WEP64, ac); AddHttpValue(pReturnXML, G_PC_WEP64_TYPE, "Wep64ASC"); //AddHttpValue(pReturnXML, G_PC_WEP128, ac); AddHttpValue(pReturnXML, G_PC_WEP128_TYPE, "Wep128ASC"); #else AddHttpValue(pReturnXML, G_PC_WEPSET, (g_ConfigParam.ucWepSet == WEP_SET_K64 ? "K64" : (g_ConfigParam.ucWepSet == WEP_SET_K128 ? "K128" : (g_ConfigParam.ucWepSet == WEP_SET_ASC ? "Asc": "Disable")))); AddHttpValue(pReturnXML, G_PC_WEPASC, (strlen((char*) g_ConfigParam.acWepAsc) > 0 ? "*" : "")); AddHttpNum(pReturnXML, G_PC_WEPGROUP, 0); if (g_ConfigParam.bWep64UseAsc) { memcpy(ac, g_ConfigParam.acWep64, 5); ac[5] = '\0'; } else { for (iLen = 0, j = 0; j < 5; j++) { iLen += sprintf(ac + iLen, "%02x", (int)(unsigned char)g_ConfigParam.acWep64[j]); } } //AddHttpValue(pReturnXML, G_PC_WEP64, ac); AddHttpValue(pReturnXML, G_PC_WEP64_TYPE, (g_ConfigParam.bWep64UseAsc ? "Wep64ASC" : "Wep64HEX")); if (g_ConfigParam.bWep128UseAsc) { memcpy(ac, g_ConfigParam.acWep128, 13); ac[13] = '\0'; } else { for (iLen = 0, j = 0; j < 13; j++) { iLen += sprintf(ac + iLen, "%02x", (int)(unsigned char)g_ConfigParam.acWep128[j]); } } //AddHttpValue(pReturnXML, G_PC_WEP128, ac); AddHttpValue(pReturnXML, G_PC_WEP128_TYPE, (g_ConfigParam.bWep128UseAsc ? "Wep128ASC" : "Wep128HEX")); { enum SET_WIFI_STATE_E wifiState; wsp_get_config_state(&wifiState, NULL); switch(wifiState) { case SET_WIFI__TRYING: AddHttpValue(pReturnXML, "CurrentWiFiState", "TRYING"); break; case SET_WIFI__OK: AddHttpValue(pReturnXML, "CurrentWiFiState", "OK"); break; default: AddHttpValue(pReturnXML, "CurrentWiFiState", "NO_INIT"); } } #endif tt_rmutex_unlock(&g_rmutex); return 0; } return -1; }
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; }
void AddHttpNum(XML *pReturnXML, const char *pcName, long lNum) { char ac[64]; httpLong2String(lNum, ac); AddHttpValue(pReturnXML, pcName, ac); }
BUF *HttpRequestEx2(URL_DATA *data, INTERNET_SETTING *setting, UINT timeout_connect, UINT timeout_comm, UINT *error_code, bool check_ssl_trust, char *post_data, WPC_RECV_CALLBACK *recv_callback, void *recv_callback_param, void *sha1_cert_hash, bool *cancel, UINT max_recv_size, char *header_name, char *header_value) { WPC_CONNECT con; SOCK *s; HTTP_HEADER *h; bool use_http_proxy = false; char target[MAX_SIZE * 4]; char *send_str; BUF *send_buf; BUF *recv_buf; UINT http_error_code; char len_str[100]; UINT content_len; void *socket_buffer; UINT socket_buffer_size = WPC_RECV_BUF_SIZE; UINT num_continue = 0; INTERNET_SETTING wt_setting; // Validate arguments if (data == NULL) { return NULL; } if (setting == NULL) { Zero(&wt_setting, sizeof(wt_setting)); setting = &wt_setting; } if (error_code == NULL) { static UINT ret = 0; error_code = &ret; } if (timeout_comm == 0) { timeout_comm = WPC_TIMEOUT; } // Connection Zero(&con, sizeof(con)); StrCpy(con.HostName, sizeof(con.HostName), data->HostName); con.Port = data->Port; con.ProxyType = setting->ProxyType; StrCpy(con.ProxyHostName, sizeof(con.ProxyHostName), setting->ProxyHostName); con.ProxyPort = setting->ProxyPort; StrCpy(con.ProxyUsername, sizeof(con.ProxyUsername), setting->ProxyUsername); StrCpy(con.ProxyPassword, sizeof(con.ProxyPassword), setting->ProxyPassword); if (setting->ProxyType != PROXY_HTTP || data->Secure) { use_http_proxy = false; StrCpy(target, sizeof(target), data->Target); } else { use_http_proxy = true; CreateUrl(target, sizeof(target), data); } if (use_http_proxy == false) { // If the connection is not via HTTP Proxy, or is a SSL connection even via HTTP Proxy s = WpcSockConnectEx(&con, error_code, timeout_connect, cancel); } else { // If the connection is not SSL via HTTP Proxy s = TcpConnectEx3(con.ProxyHostName, con.ProxyPort, timeout_connect, cancel, NULL, true, NULL, false, false, NULL); if (s == NULL) { *error_code = ERR_PROXY_CONNECT_FAILED; } } if (s == NULL) { return NULL; } if (data->Secure) { // Start the SSL communication if (StartSSLEx(s, NULL, NULL, true, 0, NULL) == false) { // SSL connection failed *error_code = ERR_PROTOCOL_ERROR; Disconnect(s); ReleaseSock(s); return NULL; } if (sha1_cert_hash != NULL) { UCHAR hash[SHA1_SIZE]; Zero(hash, sizeof(hash)); GetXDigest(s->RemoteX, hash, true); if (Cmp(hash, sha1_cert_hash, SHA1_SIZE) != 0) { // Destination certificate hash mismatch *error_code = ERR_CERT_NOT_TRUSTED; Disconnect(s); ReleaseSock(s); return NULL; } } } // Timeout setting SetTimeout(s, timeout_comm); // Generate a request h = NewHttpHeader(data->Method, target, use_http_proxy ? "HTTP/1.0" : "HTTP/1.1"); AddHttpValue(h, NewHttpValue("Keep-Alive", HTTP_KEEP_ALIVE)); AddHttpValue(h, NewHttpValue("Connection", "Keep-Alive")); AddHttpValue(h, NewHttpValue("Accept-Language", "ja")); AddHttpValue(h, NewHttpValue("User-Agent", WPC_USER_AGENT)); AddHttpValue(h, NewHttpValue("Pragma", "no-cache")); AddHttpValue(h, NewHttpValue("Cache-Control", "no-cache")); AddHttpValue(h, NewHttpValue("Host", data->HeaderHostName)); if (IsEmptyStr(header_name) == false && IsEmptyStr(header_value) == false) { AddHttpValue(h, NewHttpValue(header_name, header_value)); } if (IsEmptyStr(data->Referer) == false) { AddHttpValue(h, NewHttpValue("Referer", data->Referer)); } if (StrCmpi(data->Method, WPC_HTTP_POST_NAME) == 0) { ToStr(len_str, StrLen(post_data)); AddHttpValue(h, NewHttpValue("Content-Type", "application/x-www-form-urlencoded")); AddHttpValue(h, NewHttpValue("Content-Length", len_str)); } if (IsEmptyStr(data->AdditionalHeaderName) == false && IsEmptyStr(data->AdditionalHeaderValue) == false) { AddHttpValue(h, NewHttpValue(data->AdditionalHeaderName, data->AdditionalHeaderValue)); } if (use_http_proxy) { AddHttpValue(h, NewHttpValue("Proxy-Connection", "Keep-Alive")); if (IsEmptyStr(setting->ProxyUsername) == false || IsEmptyStr(setting->ProxyPassword) == false) { char auth_tmp_str[MAX_SIZE], auth_b64_str[MAX_SIZE * 2]; char basic_str[MAX_SIZE * 2]; // Generate the authentication string Format(auth_tmp_str, sizeof(auth_tmp_str), "%s:%s", setting->ProxyUsername, setting->ProxyPassword); // Base64 encode Zero(auth_b64_str, sizeof(auth_b64_str)); Encode64(auth_b64_str, auth_tmp_str); Format(basic_str, sizeof(basic_str), "Basic %s", auth_b64_str); AddHttpValue(h, NewHttpValue("Proxy-Authorization", basic_str)); } } send_str = HttpHeaderToStr(h); FreeHttpHeader(h); send_buf = NewBuf(); WriteBuf(send_buf, send_str, StrLen(send_str)); Free(send_str); // Append to the sending data in the case of POST if (StrCmpi(data->Method, WPC_HTTP_POST_NAME) == 0) { WriteBuf(send_buf, post_data, StrLen(post_data)); } // Send if (SendAll(s, send_buf->Buf, send_buf->Size, s->SecureMode) == false) { Disconnect(s); ReleaseSock(s); FreeBuf(send_buf); *error_code = ERR_DISCONNECTED; return NULL; } FreeBuf(send_buf); CONT: // Receive h = RecvHttpHeader(s); if (h == NULL) { Disconnect(s); ReleaseSock(s); *error_code = ERR_DISCONNECTED; return NULL; } http_error_code = 0; if (StrLen(h->Method) == 8) { if (Cmp(h->Method, "HTTP/1.", 7) == 0) { http_error_code = ToInt(h->Target); } } *error_code = ERR_NO_ERROR; switch (http_error_code) { case 401: case 407: // Proxy authentication error *error_code = ERR_PROXY_AUTH_FAILED; break; case 404: // 404 File Not Found *error_code = ERR_OBJECT_NOT_FOUND; break; case 100: // Continue num_continue++; if (num_continue >= 10) { goto DEF; } FreeHttpHeader(h); goto CONT; case 200: // Success break; default: // Protocol error DEF: *error_code = ERR_PROTOCOL_ERROR; break; } if (*error_code != ERR_NO_ERROR) { // An error has occured Disconnect(s); ReleaseSock(s); FreeHttpHeader(h); return NULL; } // Get the length of the content content_len = GetContentLength(h); if (max_recv_size != 0) { content_len = MIN(content_len, max_recv_size); } FreeHttpHeader(h); socket_buffer = Malloc(socket_buffer_size); // Receive the content recv_buf = NewBuf(); while (true) { UINT recvsize = MIN(socket_buffer_size, content_len - recv_buf->Size); UINT size; if (recv_callback != NULL) { if (recv_callback(recv_callback_param, content_len, recv_buf->Size, recv_buf) == false) { // Cancel the reception *error_code = ERR_USER_CANCEL; goto RECV_CANCEL; } } if (recvsize == 0) { break; } size = Recv(s, socket_buffer, recvsize, s->SecureMode); if (size == 0) { // Disconnected *error_code = ERR_DISCONNECTED; RECV_CANCEL: FreeBuf(recv_buf); Free(socket_buffer); Disconnect(s); ReleaseSock(s); return NULL; } WriteBuf(recv_buf, socket_buffer, size); } SeekBuf(recv_buf, 0, 0); Free(socket_buffer); Disconnect(s); ReleaseSock(s); // Transmission return recv_buf; }
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; }