예제 #1
0
SCardInfo SGAlgorithm::GetNextAction(SGUser *pUser)
{
	int iPass = CheckPassCard(pUser);
	if( iPass == CARD_PASS_OK ) 
	{
		SCardInfo sCardPass;
		sCardPass.iCardNum = -1;
		sCardPass.iCardType = -1;
		return sCardPass;
	}	
	return SelectCard(pUser);
}
예제 #2
0
int main(int argc, char* argv[])
{
	long status;
	unsigned long cardType;
	unsigned long cardSN;
	BYTE userID;

	status = OpenPort(1, 9600);
	if (!status) {
		status = LinkRW();
		if (status) {
			ClosePort();
			fprintf(stderr, "Connect Fail\n");
			return -1;
		}
		fprintf(stderr, "Connect Succeed\n");
		//beepOn();

		//card polling
		while (1) {
			status = GetCardType(&cardType);
			if (!status) {
				delayMS(5);
				if (cardType == 4) { //Mifare 1
					status = mfGetCardSnr(&cardSN);
					if (status) { 
						status = mfTransKey();
						if (status) {
							status = SelectCard(cardSN);
							if (!status) {
								fprintf(stderr, "Activate Succeed\n");
								userID = getUserID(cardSN);
								fprintf(stdout, "%x", userID);
								HaltCard();
								//delayMS(3000);
								break;
							}
						}
					}
				}
			}
		}		
	}
	else {
		fprintf(stderr, "Connect Fail\n");
		return -1;
	}

	ClosePort();
	return 0;
}
예제 #3
0
UINT8 app_brushCard(void)
{
	UINT8 Sector;
	UINT8 CardIndex;
    UINT8 i;
	for (CardIndex = MEM_CARD; CardIndex <= PWD_CARD; CardIndex++)
	{
		if (b_FactorySystem)
		{
			CardIndex = PWD_CARD;
		}
		if (CardIndex == MEM_CARD)
		{
			Load_Key(&s_System.MGM_Card);
		}
		else if (CardIndex == USER_CARD)
		{
			Load_Key(&s_System.USER_Card);
		}
		else if (CardIndex == PWD_CARD)
		{
			Load_Key(PWD_Card);
		}
		MIF_Halt();
		if (Request(RF_CMD_REQUEST_STD) != FM1702_OK)
		{
			continue;
		}
        for(i=0; i<2; i++)
        {
            if (AntiColl() == FM1702_OK && SelectCard() == FM1702_OK)
            {
                if (CardIndex == USER_CARD)     //用户卡验证钱所在扇区
                {
                    Sector = s_System.Sector;
                }
                else                            //管理和密码卡验证1扇区
                {
                    Sector = 1;
                }
                if (Authentication(gCard_UID, Sector, 0x60) == FM1702_OK)
                {
                    return CardIndex;
                }
            }
        }
	}
	return NONE_CARD;
}
예제 #4
0
	//等待刷卡	
void WaitingBrush(void)
{
	unsigned char i,j;
	do
	{
		WDT_CONTR = 0x3E;
		MIF_Halt();
		Request(RF_CMD_REQUEST_STD);
		AntiColl();
		if(SelectCard()==FM1702_OK)
			return;
		else if(Brushed ==1)
		{
			Brushed = 0;
			Show(0,0);
		}
		else
		{
			if(RxD_Buffer == 0x55)	 //0x55表示指令代码
			{
				RxD_Buffer = 0;
				SendData(0x00);		 //在没有刷卡的状态下,发送给主机0x00;
			}
			else if((RxD_Buffer>>4) == 6) //RxD_Buffer高4位为6,底4位是通道号,记忆卡的ID号
			{
				if((RxD_Buffer!=0x6f)&&(RxD_Buffer!=0x6e)) Channel = RxD_Buffer&0x0f;
				else
				{
					if(RxD_Buffer==0x6f)
					{
						for(i=0;i<5;i++){USER_Card_ID[Channel][i]=gCard_UID[i];}//Last_gCard_UID[i]=0;
						Write_E2PROM8_CardID();	 //每开通某个通道,就写E2PROM一次,记录下该卡号的id
						Delay_1ms(200);
						Delay_1ms(200);
						Delay_1ms(200);
						Delay_1ms(200);
					}
					Channel = 0x0f;
				}
			}
			else if(RxD_Buffer == 0x77)		 //0x77功能代码表示,刷卡单位时间的发送
			{
				Delay_1ms(100);
				SendData(0x33);	//无效指令
				Delay_1ms(100);
				SK_Timer = RxD_Buffer*100;
				RxD_Buffer = 0;
				SendData(0x33);	//无效指令
				Delay_1ms(100);
				SK_Timer += RxD_Buffer;
				RxD_Buffer = 0;
				SendData(0x33);	//无效指令
				Delay_1ms(100);

				//Show(SK_Timer,0);
				SectorErase(0x600);
				ByteProgram(0x600,(SK_Timer/100));
				ByteProgram(0x601,(SK_Timer%100));
				IAP_Disable();
			}
			else if((RxD_Buffer>>4) == 8)
			{
				Delay_1ms(100);
				SendData(0x33);	//无效指令
				for(i=0;i<5;i++){USER_Card_ID[RxD_Buffer&0x0f][i]=0;} 
				Write_E2PROM8_CardID();	 
				Delay_1ms(200);
				Delay_1ms(200);
				Delay_1ms(200);
				Delay_1ms(200);
			}
			else if(RxD_Buffer == 0x99)
			{
				for(j=0;j<10;j++){for(i=0;i<5;i++){USER_Card_ID[j][i]=0;}}
				Write_E2PROM8_CardID();	 
				Delay_1ms(200);
				Delay_1ms(200);
				Delay_1ms(200);
				Delay_1ms(200);
			}
		}
예제 #5
0
	void KeyControl(int key)
	{
		// 모든 상태에서

		// START 상태에서
		if (GameStatus == START)
		{
			if (key == SPACE)
			{
				GameStatus = INIT;
			}
		}

		// RUNNING 상태에서
		if (GameStatus == RUNNING)
		{
			switch (key)
			{
			case UP:
				if (Choice.select > 4)
					Choice.select -= 4;
				break;

			case DOWN:
				if (Choice.select < Stage.CardCount - 3)
					Choice.select += 4;
				break;

			case LEFT:
				if ((Choice.select != 1) && (Choice.select != 5) && (Choice.select != 9) && (Choice.select != 13))
					Choice.select--;
				break;

			case RIGHT:
				if ((Choice.select != 4) && (Choice.select != 8) && (Choice.select != 12))
					Choice.select++;
				break;

			case SPACE:
				if (ViewCard[1] == -1) // Card가 둘 다 Open이 아니라면
				{
					SelectCard();
				}
				break;

			default:
				break;
			}
		}

		// SUCCESS 상태에서
		if (GameStatus == SUCCESS)
		{
			switch (key)
			{
			case 'Y': case 'y':
				if (Stage.Level < 2)
				{
					Stage.Level++;
					GameStatus = INIT;
				}
				else
				{
					GameStatus = RESULT;
				}
				break;

			case 'N': case 'n':
				GameStatus = RESULT;
				break;
			}
		}

		// FAILED 상태에서
		if (GameStatus == FAILED)
		{
			switch (key)
			{
			case 'Y': case 'y':
				GameStatus = INIT;
				break;

			case 'N': case 'n':
				GameStatus = RESULT;
				break;
			}
		}
	}