Exemple #1
0
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;
}
Exemple #2
0
//连接WIFI
int WifiConfig(void) //add by wuc 2014.9.9
{
	int iRet;
	
/*	iRet = SelectWifiMode();
	if(iRet)
	{
		return iRet;
	}
*/
	
	while(1)
	{
		//linzhao
		iRet = SelectWifiMode();
		if(iRet)
		{
			break;
		}

		iRet = SetWifiLocalIpPara();
		if(iRet)
		{
			break;
		}

		if(glConfiged)
		{
			glConfiged = 0;
		}
		else
		{
			iRet = ManualWifiAps();
			if (iRet) 
			{
				break;
			}
		}
		
		ScrCls();
		PubDispString(_T("CONNECT..."), DISP_LINE_CENTER|3);	//CONNECTING
		iRet = WifiApLogin();
		if(iRet == 0)
		{
			ScrCls();
			PubDispString(_T("WIFI CONNECTED"), DISP_LINE_CENTER|3);
			PubWaitKey(3);
			break;
		}
		else
		{
			ScrCls();
			PubDispString(_T("CONNECT FAIL"), DISP_LINE_CENTER|3);	//CONNECT FAIL
			PubWaitKey(3);
			continue;
		}
	}

	return iRet;
}
Exemple #3
0
int TmkActivation(void)
{
    int i, iRet;

    iRet = TransInit(LOGON);
    if( iRet!=0 )
    {
        return iRet;
    }

    ScrCls();
    PubDispString(_T("TMK ACTIVATION"), 0 | DISP_LINE_LEFT | DISP_LINE_REVER);

    //set common field for TMK Activation field
    SetKeyCommfield(KEY_TYPE_TMK2);

    iRet = SendRecvPacket();
    if(iRet!=0)
    {
        return iRet;
    }

    if( memcmp(glProcInfo.stTranLog.szRspCode, "00", 2)!=0 )
    {
        return -1;
    }

    return 0;
}
Exemple #4
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;
}
Exemple #5
0
//设置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;
}
Exemple #6
0
//connect wifi at the first fun. linzhao 2015.1.26
void WifiPrompt(void)
{
	ST_WIFI_AP WifiAp;

	while( WifiCheck(&WifiAp)<0 )	
	{
		ScrCls();
		PubDispString(_T("Configure WIFI network"), DISP_LINE_CENTER|3);
		PubDispString(_T("Press F2"), DISP_LINE_CENTER|4);
		if ( KEYF2==getkey() && 0==WifiConfig() )
		{
#ifdef _SSL_ONLY_
			glSysCtrl.ucCommType = SSL_USE;
#else
			glSysCtrl.ucCommType = WIFI_USE;
#endif
			break;
		}
	}
}
Exemple #7
0
//输入WIFI 加密方式
int GetWifiSecMode(uchar *psName, uchar *psOut)
{
	uchar ucKey;

	ScrCls();
	PubDispString(_T("ENCRYPTION"), DISP_LINE_CENTER|1);
	ScrPrint(0, 3, 0, _T("1 - NONE"));
	ScrPrint(0, 4, 0, _T("2 - WEP"));
	ScrPrint(0, 5, 0, _T("3 - WPA/WPA2"));
	ScrPrint(0, 6, 0, _T("4 - WPA-PSK/WPA2-PSK"));

	do {
		ucKey = PubWaitKey(USER_OPER_TIMEOUT);
	} while(ucKey!=KEY1 && ucKey!=KEY2 && ucKey!=KEY3 && ucKey!=KEY4 && ucKey!=KEYCANCEL);

	if (ucKey == KEY1) 
	{
		*psOut = 0;	
	}

	if (ucKey == KEY2) 
	{
		*psOut = 1;	
	}
	if (ucKey == KEY3) 
	{
		*psOut = 2;	
	}

	if (ucKey == KEY4) 
	{
		*psOut = 3;	
	}

	if (ucKey == KEYCANCEL || ucKey == NOKEY) 
	{
		return ucKey;
	}

	return 0;
}
Exemple #8
0
//输入WIFI SSID
int GetWifiSsid(uchar *psOut)
{
	uchar ucRet;
	uchar ucTempBuf[100];

	memset(ucTempBuf, 0, sizeof(ucTempBuf));
	strcpy(ucTempBuf, glSysCtrl.stAppWifiPara.Ssid);

	ScrCls();
	PubDispString(ucTempBuf, DISP_LINE_CENTER|1);
	PubDispString(_T("SSID:"), DISP_LINE_CENTER|2);
	ScrGotoxyEx (0, 96);
	ucRet = GetString(ucTempBuf, 0xF5, 0, KEY_WPA_MAXLEN);
	if (ucRet)
	{
		return ucRet;
	}

	memcpy(psOut, &ucTempBuf[1], ucTempBuf[0]);
	return 0;
}
Exemple #9
0
//输入WIFI 密码
int GetWifiKey(uchar *psName, int iSecMode, uchar *psOut)
{
	uchar ucRet;
	uchar ucTempBuf[100];
	uchar ucWEPMode;

	if (iSecMode < 1 || iSecMode > 3) 
	{
		return 0;
	}

	ScrCls();
	PubDispString(psName, DISP_LINE_CENTER|1);
	
	if(iSecMode == 1)
	{
		PubDispString(_T("SELECT WEP MODE"), DISP_LINE_CENTER|2);
		ScrPrint(0, 3, 0, _T("1. ASCII"));
		ScrPrint(0, 4, 0, _T("2. HEX"));
		while(1)
		{
			ucRet = PubWaitKey(USER_OPER_TIMEOUT);
			if(ucRet == KEY1)
			{
				ucWEPMode = 0;
				break;
			}
			else if(ucRet == KEY2)
			{
				ucWEPMode = 1;
				break;
			}
			else if(ucRet == KEYCANCEL || ucRet == NOKEY)
			{
				return ucRet;
			}
		}
		ScrClrBelow(2);
	}
	
	PubDispString(_T("TYPE PASSWORD:"), DISP_LINE_CENTER|2);
	ScrGotoxyEx (0, 96);
	memset(ucTempBuf, 0, sizeof(ucTempBuf));
	if (iSecMode == 1)	//WEP 
	{
		if(glSysCtrl.ucWepMode == 0)	//ascii
		{
			strcpy(ucTempBuf, glSysCtrl.stAppWifiPara.Wep);
		}
		else		//hex
		{
			PubBcd2Asc0(glSysCtrl.stAppWifiPara.Wep, 5, ucTempBuf);
		}
		ucRet = GetString(ucTempBuf, 0xF5, (uchar)(ucWEPMode==0 ? 5:10), (uchar)(ucWEPMode==0 ? 5:10));
		glSysCtrl.ucWepMode = ucWEPMode;
	}
	else	//WPA
	{
		strcpy(ucTempBuf, glSysCtrl.stAppWifiPara.Wpa);
		ucRet = GetString(ucTempBuf, 0xF5, 1, KEY_WPA_MAXLEN);
	}

	if (ucRet == 0x00)
	{
		if((iSecMode == 1) && (ucWEPMode == 1))
		{
			PubAsc2Bcd(&ucTempBuf[1], ucTempBuf[0], psOut);
		}
		else
		{
			memcpy(psOut, &ucTempBuf[1], ucTempBuf[0]);
		}
		return 0;
	}
	if (ucRet == 0x0D) 
	{
		return 0;
	}

	return ucRet;
}
Exemple #10
0
//扫描周围的热点
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;
}
Exemple #11
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;
}
Exemple #12
0
void TerminalSignOn(void)
{
    int iRet; 
    ST_KEY_INFO KeyInfoIn = {0};
    ST_KCV_INFO KcvInfoIn = {0};

    memcpy(&glCurAcq, &glSysParam.stAcqList[1], sizeof(ACQUIRER));  //set the default  Acq by richard 20170223

    iRet = TransInit(LOGON);
    if( iRet!=0 )
    {
        return iRet;
    }

    SaveRevInfo(FALSE); //for test, TODO need to delete, 

    ScrCls();
    PubDispString(_T("TERM SIGNON"), 0 | DISP_LINE_LEFT | DISP_LINE_REVER);

    SetKeyCommfield(KEY_TYPE_TPK);

    //set field63
    memcpy(glSendPack.sField63, "\x00\x03", 2);
    memcpy(glSendPack.sField63+2, "000", 3);

    iRet = SendRecvPacket();
    if(iRet!=0)
    {
        return iRet;
    }

    if( memcmp(glProcInfo.stTranLog.szRspCode, "00", 2)!=0 )
    {
        return -1;
    }
    
    //TODO , deal with other response field data.

    //get the TPK and check value
    KeyInfoIn.iDstKeyLen  = 16;
    KcvInfoIn.aucCheckBuf[0] = 0x04;
    memcpy(KeyInfoIn.aucDstKeyValue, glRecvPack.sField62+2, 16);
    memcpy(KcvInfoIn.aucCheckBuf+1, glRecvPack.sField62+18, 4);

    KeyInfoIn.ucSrcKeyType = PED_TMK;
    KeyInfoIn.ucSrcKeyIdx  = CUP_TMK_ID;
    KeyInfoIn.ucDstKeyType = PED_TPK;
    KeyInfoIn.ucDstKeyIdx  = CUP_TPK_ID;
    KcvInfoIn.iCheckMode = 0x01;

    iRet = PedWriteKey(&KeyInfoIn, &KcvInfoIn);
    if(iRet != 0)
    {
        ScrClrLine(2, 7);
        PubDispString(_T("SignOn Failed!"), 3 | DISP_LINE_CENTER);
        PubWaitKey(3);
    }
    else 
    {
        PubBeepOk();
        ScrClrLine(2, 7);
        PubDispString(_T("SignOn SUCCESS!"), 3 | DISP_LINE_CENTER);
        PubWaitKey(3);
    }
    
}
Exemple #13
0
int TmkDownload(void)
{
    int i, iRet, offset=0;
    uchar szBuff[32 + 1], TmpBuff[32 + 1], ck_value[8 + 1];
    uchar randomkeybuf[16 + 1];
    uchar TMKResult[16];
    uchar RSAData[256]={0};
    uchar szDataIn[256]={0};
    int mod_len = 2048, RSADataLen=0;
    //uchar dataIn_en[1024] = {0};
    //uchar inch[300], exp[4], modulch[300], outch[300];
    R_RSA_PUBLIC_KEY_CS publicKey = {0};
	R_RANDOM_STRUCT randomStruct = {0};
    ST_KEY_INFO KeyInfoIn = {0};
    ST_KCV_INFO KcvInfoIn = {0};
    
    iRet = TransInit(LOGON);
    if( iRet!=0 )
    {
        return iRet;
    }

    ScrCls();
    PubDispString(_T("TMK DOWNLOAD"), 0 | DISP_LINE_LEFT | DISP_LINE_REVER);

    for (i = 0; i < 16; i++)  //generating random data
    {
        szBuff[i] = (uchar)rand();    
    }

    memcpy(randomkeybuf, szBuff, 16);

    //encrypt 0 data with the random key, and get check value
    memset(TmpBuff, 0x00, sizeof(TmpBuff));
    PubDes(TRI_ENCRYPT, TmpBuff, randomkeybuf, ck_value);

    memset(szDataIn, 0xFF, 128);
    memcpy(szDataIn, "\x00\x02", 2);
    memcpy(szDataIn + 128 - 16 - 1, "\x00", 1);
    memcpy(szDataIn + 128 - 16, randomkeybuf, 16);

    
	iRet = PedRsaRecover(1, szDataIn, RSAData, NULL);
	if (0 != iRet)
		return iRet;

    //set common field for TMK Exchange field
    SetKeyCommfield(KEY_TYPE_TMK1);

    memcpy(rsa_down.RadomEncryptKey, RSAData, 128);
    memcpy(rsa_down.RadomEncryptKeyCheck, ck_value, 4);

    offset = 2; 
    offset += SetTlvData(glSendPack.sField62+offset, "\x9F\x06", rsa_down.PubKeyRID, 5);
    offset += SetTlvData(glSendPack.sField62+offset, "\x9F\x22", &rsa_down.PubKeyIndex, 1);
    /*if(ChkExistAcq("CUP_DSB"))
    {
        offset += SetTlvData(glSendPack.sField62+offset, "\xDF\x02", rsa_down.RadomEncryptKey, 128);
        offset += SetTlvData(glSendPack.sField62+offset, "\xDF\x04", rsa_down.RadomEncryptKeyCheck, 4);
    }
    else 
    {*/
        offset += SetTlvData(glSendPack.sField62+offset, "\xDF\x23", rsa_down.RadomEncryptKey, 128);
        offset += SetTlvData(glSendPack.sField62+offset, "\xDF\x24", rsa_down.RadomEncryptKeyCheck, 4);
    //}
    PubLong2Char((ulong)offset-2, 2, glSendPack.sField62);

    iRet = SendRecvPacket();
    if(iRet!=0)
    {
        return iRet;
    }

    if( memcmp(glProcInfo.stTranLog.szRspCode, "00", 2)!=0 )   //response code  incorrect
    {
        return -1;
    }

    iRet = GetTlvData(glRecvPack.sField62, "\xDF\x21", rsa_down.EncryptTMK);
    if(iRet<0)
    {
        return iRet;
    }
    
    iRet = GetTlvData(glRecvPack.sField62, "\xDF\x22", rsa_down.TMKCheckValue);
    if(iRet<0)
    {
        return iRet;
    }

    for (i = 0; i < 2; i++)
    {
        PubDes(TRI_DECRYPT, rsa_down.EncryptTMK + i * 8, randomkeybuf, TMKResult + i * 8);
    }

    memset(TmpBuff, 0x00, sizeof(TmpBuff));
    PubDes(TRI_ENCRYPT, TmpBuff, TMKResult, ck_value);

    //write TMK, and verify check value
    if(memcmp(rsa_down.TMKCheckValue, ck_value, 4) == 0)
    {
        PedErase();
        KeyInfoIn.ucSrcKeyType = PED_TMK;
        KeyInfoIn.ucSrcKeyIdx  = 0;
        KeyInfoIn.ucDstKeyType = PED_TMK;
        KeyInfoIn.ucDstKeyIdx  = CUP_TMK_ID;
        KeyInfoIn.iDstKeyLen  = 16;
        memcpy(KeyInfoIn.aucDstKeyValue, TMKResult, KeyInfoIn.iDstKeyLen);
        KcvInfoIn.iCheckMode = 0x00;

        iRet = PedWriteKey(&KeyInfoIn, &KcvInfoIn);
        return iRet;
    }
    else 
    {
        return -1;//check value incorrect
    }
}
Exemple #14
0
int RsaKeyDownload(void)
{
    int iRet; 
    ST_RSA_KEY stRsaKey={0};

     iRet = TransInit(LOGON);
    if( iRet!=0 )
    {
        return iRet;
    }

    ScrCls();
    PubDispString(_T("RSA KEY DOWNLOAD"), 0 | DISP_LINE_LEFT | DISP_LINE_REVER);
    
    //set Rsa request field
    SetKeyCommfield(KEY_TYPE_RSA);

    iRet = SendRecvPacket();
    PubDebugTx("SendRecvPacket:%d\n", iRet);
    if(iRet!=0)
    {
        return iRet;
    }

    PubDebugTx("glProcInfo.stTranLog.szRspCode:%s\n", glProcInfo.stTranLog.szRspCode);
    if( memcmp(glProcInfo.stTranLog.szRspCode, "00", 2)!=0 )   //response code  incorrect
    {
        return -1;
    }

    //field62, RSA information
    //memcpy(glRecvPack.sField62, "\x9F\x06\x05\x00\x00\x02\x77\xD6", 8);
    /*for(iRet=0; iRet<185; iRet++)
        PubDebugTx(" %02X", glRecvPack.sField62[iRet]);
    PubDebugTx("\n");*/
    iRet = GetTlvData((uchar *)glRecvPack.sField62, "\x9F\x06", rsa_down.PubKeyRID);
    //PubDebugTx("GetTlvData 9f06:%d %02X %02X\n", iRet, rsa_down.PubKeyRID[3], rsa_down.PubKeyRID[4]);
    if(iRet<0)
    {
        return iRet;
    }

    iRet = GetTlvData(glRecvPack.sField62, "\x9F\x22", &rsa_down.PubKeyIndex);
    //PubDebugTx("GetTlvData 9f22:%d %d\n", iRet, rsa_down.PubKeyIndex);
    if(iRet<0)
    {
        return iRet;
    }

    iRet = GetTlvData(glRecvPack.sField62, "\xDF\x02", rsa_down.PubKeyModule);
    if(iRet<0)
    {
        return iRet;
    }
    memmove(rsa_down.PubKeyModule, &rsa_down.PubKeyModule[29], 128);
    //PubDebugTx("GetTlvData DF02:%d %02X %02X\n", iRet, rsa_down.PubKeyModule[0], rsa_down.PubKeyModule[1]);

    iRet = GetTlvData(glRecvPack.sField62, "\xDF\x04", rsa_down.PubKeyExponential);
    s_expLen = iRet;
    //PubDebugTx("GetTlvData DF04:%d %02X %02X\n", iRet, rsa_down.PubKeyExponential[0], rsa_down.PubKeyExponential[1]);
    if(iRet<0)
    {
        return iRet;
    }

    stRsaKey.iModulusLen = 1024;
    memcpy(&stRsaKey.aucModulus[512-128], rsa_down.PubKeyModule, 128);
    stRsaKey.iExponentLen = s_expLen*8;
    memcpy(&stRsaKey.aucExponent[512-s_expLen], rsa_down.PubKeyExponential, s_expLen);
    
    iRet = PedWriteRsaKey(1, &stRsaKey);
	if(iRet!=0)
	{
    	PubDebugTx("PedWriteRsaKey: %d\n", iRet);
		return iRet;
	}
    
    return 0;
}
Exemple #15
0
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);
	}
	
}