do_card.c
上传用户:shyuanyi
上传日期:2008-05-24
资源大小:69k
文件大小:2k
- #include "My_head.h"
- #include "carddef.h"
- #include "rfic.h"
- #include "sendcard.h"
- //==============================================
- #define SEND_CARD_LED P1_1
- /***********************************************/
- void Count_Sector_PWD(BYTE pbuf[],BYTE card_snr[4],BYTE sector)
- {
- memcpy(pbuf,Nkey_a,6);
- pbuf[0] *= card_snr[0]+sector*1;
- pbuf[1] *= card_snr[1]+sector*2;
- pbuf[2] *= card_snr[2]+sector*3;
- pbuf[3] *= card_snr[3]+sector*4;
- pbuf[4] *= pbuf[0]+sector*5;
- pbuf[5] *= pbuf[1]+sector*6;
- }
- BYTE GetSEEDCardTest(SeedCard_Info *card)
- {
- BYTE idata tt[2];
- BYTE idata card_snr[4];
- BYTE idata bankdata[16];
- BYTE size,err;
- int i=0;
- //Init_Rfic();
- mifs_reset(20);
- for(i=45;--i;)
- {
- if(!mifs_request(ALL_CARD,tt))break;
- }
- if(!i)return(CARD_NO_FINED);
- for(i=45;--i;)
- {
- if((mifs_request(IDLE_CARD,tt))!=MI_OK)continue;
- if((mifs_anticoll(0,card_snr))!=MI_OK)continue;
- if((mifs_select(card_snr,&size))!=MI_OK)continue;
- break;
- }
- if(!i)return(CARD_ERR_CODE);//return(40+err);
- Count_Sector_PWD(bankdata,card_snr,SEEDCARD_SECTOR);
- err=mifs_load_key(KEYA,SEEDCARD_SECTOR,bankdata);
- //err=mifs_load_key(KEYA,SEEDCARD_SECTOR,Nkey_b);
- if(err!=MI_OK)return(50+err);
- for(i=15;--i;)
- {
- if((mifs_authentication(KEYA,SEEDCARD_SECTOR))!=MI_OK)continue;
- //if((mifs_authKey(KEYA,SEEDCARD_SECTOR,Nkey_b))!=MI_OK)continue;
- if((mifs_read(SEED_CARD_SECT,bankdata))!=MI_OK)continue;
- break;
- }
- if(!i)return(CARD_ERR_CODE);//return(40+err);
- //do_buzzer(1);
- mifs_halt();
- //mifs_close();
- if(bankdata[CARD_LEVEL_DDR] != SEED_CARD)
- {
- return(CARD_NO_SEED);
- }
- memcpy(card->unit_code,&bankdata[UNIT_CODE_ADDR],3);
- memcpy(card->unit_password,&bankdata[UNIT_PWD_ADDR],3);
- card->fuc_type=bankdata[FUC_TYPE_ADDR];
- card->fuc_sector=bankdata[FUC_SECTOR_ADDR];
- card->public_sector=bankdata[PUBLIC_SECTOR_ADDR];
- memcpy(card->date,&bankdata[SEED_DATE_ADDR],3); //6
- return(SUCCESS);
- }