int MainIdleProc(void) { // should not let POS go into sleep mode when running simulator int iRet; if (POWER_BATTERY == OsCheckPowerSupply()) { if (glSysParam.stEdcInfo.ucIdleShutdown) { PowerOff(); } else { // Modified by Kim_LinHB 2014-7-8 Gui_ClearScr(); Gui_ShowMsgBox(_T("POWER SAVING"), gl_stTitleAttr, NULL, _T("PRESS ANY KEY\nTO RECOVER"), gl_stCenterAttr, GUI_BUTTON_NONE, 0, NULL); do { iRet = SysSleep("00"); } while((iRet==-3) && (kbhit()!=0)); // 很奇怪的现象:除非在上次SysSleep返回之后调用DelayMs(3000),否则即使间隔1分钟,调用SysSleep仍会直接返回-3。 // 因此我在这里加了判断,如果返回-3而且没有按键则继续重复SysSleep // 在外部已经保证了进入MainIdleProc的间隔>=1分钟 // it needs to delay 3 seconds after return from SysSleep, otherwise SysSleep will return -3 even the period of calling SysSleep is over 1 min, // so here is a special processing, if return -3 from SysSleep and no key was pressed then continue calling SysSleep. DelayMs(100); kbflush(); Gui_ClearScr(); // Added by Kim_LinHB 2014-08-13 v1.01.0003 } return 0; } return -1; }
int main(void) { uchar ucKey; ushort ret; uchar *data="\x12\x34\x56\x78"; int len=strlen(data); SystemInit(); while(1) { ScrCls(); kbflush(); ScrPrint(0,0,0x01|0x80,"CRC-16 "); do{ ucKey=getkey(); }while(ucKey!=KEY1 && ucKey!=KEYENTER && ucKey!=KEYCANCEL); if(ucKey==KEY1 || ucKey==KEYENTER) { ScrCls(); ret=get_crc16(data,len); Lcdprintf("0x%x\n",ret); getkey(); } if(ucKey==KEYCANCEL) return 1; } return 0; }
//选择WIFI打开模式, 是扫描周围的热点,还是手工输入SSID int SelectWifiMode(void) { int iRet = 0; uchar ucKey; while(1) { kbflush(); ScrCls(); PubDispString(_T("WIFI"), DISP_LINE_CENTER|0); ScrPrint(0, 1, 0, _T("1 - SEARCH NETWORK")); ScrPrint(0, 2, 0, _T("2 - MANUAL")); ucKey = PubWaitKey(USER_OPER_TIMEOUT); if (ucKey == KEY1) { iRet = ScanWifiAps(); if (iRet) { //add by wuc 2014.3.24 if(WIFI_ERR_SCAN == iRet) { WifiClose(); iRet = WifiOpen(); if(iRet) { ScrClrBelow(1); ScrPrint(0, 2, 0, "OpenWifi err=%d", iRet); PubWaitKey(5); break; } } continue; } break; } if (ucKey == KEY2) { iRet = ManualWifiAps(); if (iRet) { continue; } break; } if (ucKey == KEYCANCEL || ucKey == NOKEY) { return ucKey; } } return iRet; }
//设置WIFI 本地IP参数 int SetWifiLocalIpPara(void) { int iRet = 0; uchar ucKey; while(1) { kbflush(); ScrCls(); PubDispString(_T("PROTOCOL"), DISP_LINE_CENTER|0); ScrPrint(0, 1, 0, _T("1 - DHCP")); ScrPrint(0, 2, 0, _T("2 - MANUAL")); ucKey = PubWaitKey(USER_OPER_TIMEOUT); if (ucKey == KEY1) { glSysCtrl.stAppWifiPara.DhcpEnable= 1; glConfiged = 1; break; } if (ucKey == KEY2) { glSysCtrl.stAppWifiPara.DhcpEnable = 0; iRet = ManualWifiIps(); if (iRet) { return iRet; } iRet = ConfirmConfig(); if(iRet) { return iRet; } break; } if (ucKey == KEYCANCEL || ucKey == NOKEY) { return ucKey; } /*if(ucKey == KEYENTER) { break; }*/ } return iRet; }
//扫描周围的热点 int ScanWifiAps(void) { int i, iRet, iApCount; uchar ucKey, ucTempBuf[100]; ST_WIFI_AP stWifiAps[16]; ScrClrBelow(1); ScrPrint(0, 1, 0, _T("SCANNING AP...")); //scanning ap if(strlen(glSysCtrl.stAppWifiPara.Ssid) != 0) { WifiDisconAp(); } iApCount = 8; memset(&stWifiAps, 0, sizeof(stWifiAps)); iRet = WifiScanAps(&stWifiAps[0], iApCount); if(iRet == 0) { ScrClrBelow(1); ScrPrint(0, 2, 0, _T("NO AVAILABLE AP")); getkey(); return WIFI_ERR_NULL; } if(iRet < 0) { ScrClrBelow(1); ScrPrint(0, 2, 0, "ScanAps err=%d", iRet); getkey(); return WIFI_ERR_SCAN; } ScrCls(); PubDispString(_T("SEARCH NETWORK"), DISP_LINE_CENTER|0); //please select //显示搜索到的热点 for (i=0; i<iRet; i++) { ScrPrint(0, (uchar)(i + 1), 0, "%d - %s",i, stWifiAps[i].Ssid); } while (1) { kbflush(); ucKey = PubWaitKey(USER_OPER_TIMEOUT); if (ucKey == KEYCANCEL || ucKey == NOKEY) { return ucKey; //modify by wuc 2014.4.1 } i = ucKey - 0x30; if(i<0 || i>iRet) { continue; } break; } strcpy(glSysCtrl.stAppWifiPara.Ssid, stWifiAps[i].Ssid); //判断是否需要密码 if(stWifiAps[i].SecMode == 0) //无加密 { glSysCtrl.stAppWifiPara.SecMode = 0; } else if(stWifiAps[i].SecMode == 1) //WEP加密 { glSysCtrl.stAppWifiPara.SecMode = 1; memset(ucTempBuf, 0, sizeof(ucTempBuf)); iRet = GetWifiKey(stWifiAps[i].Ssid, stWifiAps[i].SecMode, ucTempBuf); if(iRet) { return iRet; } strcpy(glSysCtrl.stAppWifiPara.Wep, ucTempBuf); } else if(stWifiAps[i].SecMode == 2) //WPA/WPA2加密 TKIP { glSysCtrl.stAppWifiPara.SecMode = 2; memset(ucTempBuf, 0, sizeof(ucTempBuf)); iRet = GetWifiKey(stWifiAps[i].Ssid, stWifiAps[i].SecMode, ucTempBuf); if(iRet) { return iRet; } strcpy(glSysCtrl.stAppWifiPara.Wpa, ucTempBuf); } else if(stWifiAps[i].SecMode == 3) //WPA-PSK/WPA2-PSK加密 AES { glSysCtrl.stAppWifiPara.SecMode = 3; memset(ucTempBuf, 0, sizeof(ucTempBuf)); iRet = GetWifiKey(stWifiAps[i].Ssid, stWifiAps[i].SecMode, ucTempBuf); if(iRet) { return iRet; } strcpy(glSysCtrl.stAppWifiPara.Wpa, ucTempBuf); } else { ScrClrRect(0, 24, 319, 215); ScrGotoxyEx(0, 24); Lcdprintf("%s\n", stWifiAps[i].Ssid); Lcdprintf(_T("UNSUPPORTED MODE\n")); getkey(); return WIFI_ERR_CANCEL; } return 0; }
int ShowLastAP(void) //add by wuc 2014.9.9 { int iRet; //读取参数并显示 kbflush(); ScrCls(); //add by wuc 2014.1.10 PubDispString(_T("CONFIGURATIONS"), DISP_LINE_CENTER|0); if(strlen(glSysCtrl.stAppWifiPara.Ssid) == 0) { ScrPrint(0, 1, 0, _T("NO AP CONNECTED")); } else { ScrPrint(0, 1, 0, _T("NETWORK: %s\n"), glSysCtrl.stAppWifiPara.Ssid); if (glSysCtrl.stAppWifiPara.SecMode == 1) { if(glSysCtrl.ucWepMode == 0) { ScrPrint(0, 2, 0, _T("MODE:WEP(ASCII)")); ScrPrint(0, 3, 0, _T("PASSWORD:%s\n"), glSysCtrl.stAppWifiPara.Wep); } else { ScrPrint(0, 2, 0, _T("MODE:WEP(HEX)")); ScrPrint(0, 3, 0, _T("PASSWORD:%02x%02x%02x%02x%02x\n"), glSysCtrl.stAppWifiPara.Wep[0], glSysCtrl.stAppWifiPara.Wep[1], glSysCtrl.stAppWifiPara.Wep[2], glSysCtrl.stAppWifiPara.Wep[3], glSysCtrl.stAppWifiPara.Wep[4]); } } else if (glSysCtrl.stAppWifiPara.SecMode == 2) { ScrPrint(0, 2, 0, _T("MODE:WPA/WPA2")); ScrPrint(0, 3, 0, _T("PASSWORD:%s\n"), glSysCtrl.stAppWifiPara.Wpa); } else if (glSysCtrl.stAppWifiPara.SecMode == 3) { ScrPrint(0, 2, 0, _T("MODE:WPA-PSK/WPA2-PSK")); ScrPrint(0, 3, 0, _T("PASSWORD:%s\n"), glSysCtrl.stAppWifiPara.Wpa); } else { ScrPrint(0, 2, 0, _T("MODE:NONE")); } if (glSysCtrl.stAppWifiPara.DhcpEnable == 1) { ScrPrint(0, 4, 0, _T("DHCP: OPEN")); } else { ScrPrint(0, 4, 0, _T("DHCP: CLOSE")); } } PubDispString(_T("(PRESS ENTER TO CONTINUE)"), DISP_LINE_CENTER|6); while(1) { iRet = PubWaitKey(USER_OPER_TIMEOUT); if(iRet == KEYCANCEL || iRet == NOKEY) { return iRet; } if(iRet == KEYENTER) { break; } } return 0; }
void process_key(unsigned char ascii,struct WindRec *tw) { if (tw->litNext) { //do no processing on next key tw->litNext = FALSE; kbwrite(tw, &ascii, 1); if (tw->echo) { if (ascii>31 && ascii <127) { /* add these chars to buffer */ parse(tw, &ascii, 1); } return; } } if (tw->lmodeBits & 2) { // TRAPSIG mode active unsigned char toSend[2] = {IAC,0}; short whichSignal = 0; if (ascii == tw->slc[SLC_IP]) { whichSignal = SLC_IP; toSend[1] = TEL_IP; } else if (ascii == tw->slc[SLC_SUSP]) { whichSignal = SLC_SUSP; toSend[1] = TEL_SUSP; } // RAB BetterTelnet 2.0b1 // The defaults in parse.h are to send ABORT on ^\ which is usually correct, but // feel free to hack this (in parse.h, not here) if BRK is better in your configuration. else if (ascii == tw->slc[SLC_ABORT]) { whichSignal = SLC_ABORT; toSend[1] = TEL_ABORT; } else if (ascii == tw->slc[SLC_BRK]) // RAB BetterTelnet 2.0b1 { whichSignal = SLC_BRK; toSend[1] = TEL_BREAK; } if (toSend[1]) //if we have a signal to catch { // if (tw->echo) // parse(tw, &ascii, 1); // echo if we should tw->kblen=0; //zero out the buffer netpush(tw->port); netwrite(tw->port,toSend,2); //send IAC whatever if (tw->slcLevel[whichSignal] & SLC_FLUSHIN) { unsigned char dm[2] = {IAC,TEL_DM}; netpush(tw->port); netUrgent();//send next as urgent data netwrite(tw->port,dm,2);//send IAC DM } if (tw->slcLevel[whichSignal] & SLC_FLUSHOUT) { unsigned char tm[3] = {IAC,TEL_DOTEL,N_TIMING}; tw->timing = 1; //tell ourselves to wait for WILL TIMING netpush(tw->port); netwrite(tw->port,tm,3);//send DO TIMING } return; } } if ((tw->lmodeBits & L_SOFT_TAB)&&(ascii == 0x09)) // SOFT_TAB mode active; expand tab into spaces { short numSpaces = VSIgetNextTabDistance(); unsigned char spacechar = ' '; while (numSpaces-- > 0) { kbwrite(tw, &spacechar, 1); } if (tw->echo) parse(tw, &ascii, 1); return; } if (tw->lmodeBits & L_EDIT) //handle editing functions { if (ascii == '\015') //CR { //since we are in edit, send the buffer and CR-LF kbflush(tw); netpush(tw->port); netwrite(tw->port,"\015\012",2); if (tw->echo) parse(tw,(unsigned char *) "\012\015",2); return; } if (ascii == tw->slc[SLC_EC]) //kill the character { if (tw->echo) parse(tw,(unsigned char *) "\010 \010",3); tw->kblen--; return; } else if (ascii == tw->slc[SLC_AO]) //kill the line { while (tw->kblen >0) { if (tw->echo) parse(tw,(unsigned char *) "\010 \010",3); tw->kblen--; } return; } else if (ascii == tw->slc[SLC_EL]) //kill the line { while (tw->kblen >0) { if (tw->echo) parse(tw,(unsigned char *) "\010 \010",3); tw->kblen--; } return; } else if ((ascii == tw->slc[SLC_EOF]) && (tw->lmodeBits & 2)) { //push the buffer, send IAC EOF (RAB BetterTelnet 2.0b1 - only under TRAPSIG) char eofString[2] = { IAC, TEL_EOF }; kbflush(tw); // RAB BetterTelnet 2.0b1 - BAD! BAD! BAD! // Fix for *BSD (and probably others): // Putting ^D into Telnet's key buffer after sending an EOF could make it pop up later, so // hitting some keys (arrows seemed to do the trick) that flushed Telnet's key buffer // after a cat command which terminated with ^D caused a logout. Yuck. // tw->kbbuf[0]=ascii; // tw->kblen=1; netpush(tw->port); netwrite(tw->port,eofString, 2); return; } // RAB BetterTelnet 2.0b1 // We don't need to do this down here if we're already handling TRAPSIG mode // separately. The SUSP (usually ^Z) char is part of TRAPSIG, not EDIT. // else if (ascii == tw->slc[SLC_SUSP]) // { // char eofString[2] = { IAC, TEL_SUSP }; // if (tw->kblen > 0) // netwrite(tw->port, tw->kbbuf, tw->kblen); // tw->kblen = 0; // netpush(tw->port); // netwrite(tw->port,eofString, 2); // return; // } else if (ascii == tw->slc[SLC_EW]) { while ((tw->kbbuf[tw->kblen-1] != 0x20)&&(tw->kblen >= 0)) //while its not a space { if (tw->echo) parse(tw,(unsigned char *)"\010 \010",3); tw->kblen--; } } else if (ascii == tw->slc[SLC_RP]) { VSredrawLine(tw->vs); return; } else if (ascii == tw->slc[SLC_LNEXT]) { tw->litNext = TRUE; return; } else if (ascii == tw->slc[SLC_XON]) { if (tw->allow_flow) { //remote flow control can turn this off tw->enabled = 1; // oops small bug (RAB BetterTelnet 2.0b1) changeport(scrn, scrn); } return; } else if (ascii == tw->slc[SLC_XOFF]) { if (tw->allow_flow) { //remote flow control can turn this off tw->enabled = 0; changeport(scrn, scrn); } return; } else if ((ascii == tw->slc[SLC_FORW1])||(ascii == tw->slc[SLC_FORW1])) { kbflush(tw); netwrite(tw->port,&ascii,1); return; } //ok, at this point, we are past all local editing functions. Now, add the character to the buffer. else { kbwrite(tw, &ascii, 1); } } else if (ascii == '\015') //CR; map this to CR-LF { unsigned char toSend[2] = {0x0D,0x00}; netpush(tw->port); netwrite(tw->port,toSend,2); if (tw->echo) parse(tw,(unsigned char *) "\012\015",2); return; } else //not editing; send it { netpush(tw->port); netwrite( tw->port, &ascii, 1); // if full send buffer } if (tw->echo) /* Handle local ECHOs */ { if (ascii>31 && ascii <127) /* add these chars to buffer */ parse(tw, &ascii, 1); else /* not printable char */ { if (!(tw->lmodeBits & L_LIT_ECHO)) //don't echo if this is set { ascii='@'+ascii; parse(tw,(unsigned char *) "^",1); parse(tw, &ascii, 1); } } } }
void forwardLoginDetails(){ char url[600] = ""; char domain[100] = ""; char rsp[10240] = ""; char err_msg[200] = ""; char socketBody[2048] = ""; //char formatted_num[15]=""; char sample_rsp[200]=""; unsigned char keyPressed; uchar serial_num[32] = ""; APP_PARA stPara; ACTIVE_NETWORK network; SERVER_IP ip; SERVER_RESPONSE sResp; int iFile=0,iRet=0; memset(&network, 0, sizeof(network)); memset(&stPara, 0, sizeof(stPara)); memset(&ip, 0, sizeof(ip)); memset(&sResp, 0, sizeof(sResp)); iFile = open("network", O_RDWR|O_CREATE); iRet = read(iFile, (uchar *)&network, sizeof(network)); if(iRet==0){ strcpy(err_msg,"Please select \nSIM and network"); keyPressed = show_msg(err_msg); return; } loadPreferredSettings(network.szSim,network.szNetworkFilename); iFile = open("sim_para", O_RDWR|O_CREATE); iRet = read(iFile, (uchar *)&stPara, sizeof(stPara)); if(iRet==0){ sprintf(err_msg,"%s %s","Please configure\nsettings for\n",network.szNetworkFilename); keyPressed = show_msg(err_msg); return; } iFile = open("ip_add", O_RDWR|O_CREATE); iRet = read(iFile, (uchar *)&ip, sizeof(ip)); if(iRet==0){ sprintf(err_msg,"%s","IP address has\nnot been set"); keyPressed = show_msg(err_msg); return; } //reads the device's serial number ReadSN(serial_num); //we build up the socket body sprintf(url,"/myauthserver/login?username=%s&password=%s&serialNumber=%s","user1","user2",serial_num); strcpy(socketBody,"GET "); strcat(socketBody,url); strcat(socketBody," HTTP/1.1\r\n"); strcat(socketBody,"Host: "); strcat(socketBody,ip.szIp); strcat(socketBody,"\r\n"); strcat(socketBody,"User-Agent: SMSGH_PAX_httplib\r\n"); strcat(socketBody,"Connection: keep-alive\r\n"); strcat(socketBody,"Cache-Control: no-cache\r\n"); strcat(socketBody,"Accept: */*\r\n"); strcat(socketBody,"\r\n"); ScrCls(); ScrGotoxy(0, 0); ScrAttrSet(0); Lcdprintf("Processing...\nplease wait..."); if(dwnld_string(ip.szIp,socketBody,rsp,err_msg,stPara)<0){ //todo: check for each int returned from method, whether -1,-2, etc kbflush(); keyPressed = show_msg(err_msg); } else{ sResp = parse_http_headers(rsp); processLoginResponse(sResp); } }
// event processing int main_sub(const ST_EVENT_MSG *pstEventMsg) { int iRet; SystemInit(); #ifdef ENABLE_EMV iRet = EMVCoreInit(); if( iRet==EMV_KEY_EXP ) { EraseExpireCAPK(); } #endif SetOffBase(NULL); CheckTermSatus(pstEventMsg); #ifndef APP_MANAGER_VER // Process manager attached administrative message. // Not implemented #endif iRet = ERR_NO_DISP; switch( pstEventMsg->MsgType ) { case USER_MSG: ProcUserMsg(); break; case EDCAPP_AUTOUPDATE: AutoDownParam(); break; case EDCAPP_GETPARA: GetAutoDownParam(); break; case EDC_ECR_MSG: iRet = ProcEcrMsg(); break; case MAGCARD_MSG: iRet = ProcMagMsg(); break; case ICCARD_MSG: iRet = ProcICCMsg(); PromptRemoveICC(); break; case EPSAPP_FUNCKEYMSG: ProcFuncKeyMsg(); break; case KEYBOARD_MSG: iRet = ProcKeyMsg(); break; case APPMSG_SYNC: break; default: break; } if( iRet!=0 ) { DispResult(iRet); Gui_ClearScr(); // Added by Kim_LinHB 2014-08-13 v1.01.0003 bug512 } SetOffBase(NULL); kbflush(); CheckInitTerminal(); UnLockTerminal(); if (iRet==ERR_EXIT_APP) { return ERR_EXIT_APP; } #ifndef APP_MANAGER_VER // Response to manager admin msg #endif return iRet; // Modified by Kim_LinHB 2014-08-13 v1.01.0003 bug 512 }