?? rc500.lst
字號:
C51 COMPILER V7.06 RC500 12/15/2008 16:23:27 PAGE 11
614 }
615 return status;
616 }*/
617
618 ///////////////////////////////////////////////////////////////////////
619 // Write the MF RC500's EEPROM
620 //從FIFO 緩沖區(qū)獲得數(shù)據(jù)并寫入內(nèi)部 E2PROM
621 ///////////////////////////////////////////////////////////////////////
622 /*char PcdWriteE2(unsigned int startaddr,
623 unsigned char length,
624 unsigned char* _data)
625 {
626 char status = MI_OK;
627 ResetInfo(MInfo);
628 SerBuffer[0] = startaddr & 0xFF;
629 SerBuffer[1] = (startaddr >> 8) & 0xFF;
630 memcpy(SerBuffer + 2,_data,length);
631
632 MInfo.nBytesToSend = length + 2;
633
634 status = M500PcdCmd(PCD_WRITEE2,
635 SerBuffer,
636 &MInfo);
637 return status;
638 } */
639
640 ///////////////////////////////////////////////////////////////////////
641 // Select Command defined in ISO14443(MIFARE)
642 ///////////////////////////////////////////////////////////////////////
643 char M500PcdMfOutSelect(unsigned char type)
644 {
645 1 WriteIO(RegMfOutSelect,type&0x7);
646 1 return MI_OK;
647 1 }
648
649 ///////////////////////////////////////////////////////////////////////
650 // Request Command defined in ISO14443(MIFARE)
651 // Request,Anticoll,Select,return CardType(2 bytes)+CardSerialNo(4 bytes)
652 // 尋卡,防沖突,選擇卡 返回卡類型(2 bytes)+ 卡系列號(4 bytes)
653 ///////////////////////////////////////////////////////////////////////
654 char M500PiccCommonRequest(unsigned char req_code,unsigned char *atq)
655 {
656 1 char idata status = MI_OK;
657 1
658 1 M500PcdSetTmo(3);
659 1 WriteIO(RegChannelRedundancy,0x03);
660 1 ClearBitMask(RegControl,0x08);
661 1 WriteIO(RegBitFraming,0x07);
662 1 SetBitMask(RegTxControl,0x03);
663 1 ResetInfo(MInfo);
664 1 SerBuffer[0] = req_code;
665 1 MInfo.nBytesToSend = 1;
666 1
667 1 status = M500PcdCmd(PCD_TRANSCEIVE,SerBuffer,&MInfo);
668 1 if (status)
669 1 {
670 2 *atq = 0;
671 2 }
672 1 else
673 1 {
674 2 if (MInfo.nBitsReceived != 16)
675 2 {
C51 COMPILER V7.06 RC500 12/15/2008 16:23:27 PAGE 12
676 3 *atq = 0;
677 3 status = MI_BITCOUNTERR;
678 3 }
679 2 else
680 2 {
681 3 status = MI_OK;
682 3 memcpy(atq,SerBuffer,2);
683 3 }
684 2 }
685 1 return status;
686 1 }
687
688 ///////////////////////////////////////////////////////////////////
689 // Cascaded Anti-Collision Command defined in ISO14443(MIFARE)
690 // 防沖突 讀卡的系列號 MLastSelectedSnr
691 ///////////////////////////////////////////////////////////////////
692 char M500PiccCascAnticoll (unsigned char bcnt,unsigned char *snr)
693 {
694 1 char idata status = MI_OK;
695 1 char idata snr_in[4];
696 1 char idata nbytes = 0;
697 1 char idata nbits = 0;
698 1 char idata complete = 0;
699 1 char idata i = 0;
700 1 char idata byteOffset = 0;
701 1 unsigned char dummyShift1;
702 1 unsigned char dummyShift2;
703 1
704 1 M500PcdSetTmo(106);
705 1 memcpy(snr_in,snr,4);
706 1
707 1 WriteIO(RegDecoderControl,0x28);
708 1 ClearBitMask(RegControl,0x08);
709 1 complete = 0;
710 1 while (!complete && (status == MI_OK) )
711 1 {
712 2 ResetInfo(MInfo);
713 2 WriteIO(RegChannelRedundancy,0x03);
714 2 nbits = bcnt % 8;
715 2 if(nbits)
716 2 {
717 3 WriteIO(RegBitFraming,nbits << 4 | nbits);
718 3 nbytes = bcnt / 8 + 1;
719 3 if (nbits == 7)
720 3 {
721 4 MInfo.cmd = PICC_ANTICOLL1;
722 4 WriteIO(RegBitFraming,nbits);
723 4 }
724 3 }
725 2 else
726 2 {
727 3 nbytes = bcnt / 8;
728 3 }
729 2 SerBuffer[0] = 0x93;
730 2 SerBuffer[1] = 0x20 + ((bcnt/8) << 4) + nbits;
731 2
732 2 for (i = 0; i < nbytes; i++)
733 2 {
734 3 SerBuffer[i + 2] = snr_in[i];
735 3 }
736 2 MInfo.nBytesToSend = 2 + nbytes;
737 2
C51 COMPILER V7.06 RC500 12/15/2008 16:23:27 PAGE 13
738 2 status = M500PcdCmd(PCD_TRANSCEIVE,SerBuffer,&MInfo);
739 2 if (nbits == 7)
740 2 {
741 3 dummyShift1 = 0x00;
742 3 for (i = 0; i < MInfo.nBytesReceived; i++)
743 3 {
744 4 dummyShift2 = SerBuffer[i];
745 4 SerBuffer[i] = (dummyShift1 >> (i+1)) | (SerBuffer[i] << (7-i));
746 4 dummyShift1 = dummyShift2;
747 4 }
748 3 MInfo.nBitsReceived -= MInfo.nBytesReceived;
749 3 if ( MInfo.collPos ) MInfo.collPos += 7 - (MInfo.collPos + 6) / 9;
750 3 }
751 2 if ( status == MI_OK || status == MI_COLLERR)
752 2 {
753 3 if ( MInfo.nBitsReceived != (40 - bcnt) )
754 3 {
755 4 status = MI_BITCOUNTERR;
756 4 }
757 3 else
758 3 {
759 4 byteOffset = 0;
760 4 if( nbits != 0 )
761 4 {
762 5 snr_in[nbytes - 1] = snr_in[nbytes - 1] | SerBuffer[0];
763 5 byteOffset = 1;
764 5 }
765 4
766 4 for ( i =0; i < (4 - nbytes); i++)
767 4 {
768 5 snr_in[nbytes + i] = SerBuffer[i + byteOffset];
769 5 }
770 4
771 4 if (status != MI_COLLERR )
772 4 {
773 5 dummyShift2 = snr_in[0] ^ snr_in[1] ^ snr_in[2] ^ snr_in[3];
774 5 dummyShift1 = SerBuffer[MInfo.nBytesReceived - 1];
775 5 if (dummyShift2 != dummyShift1)
776 5 {
777 6 status = MI_SERNRERR;
778 6 }
779 5 else
780 5 {
781 6 complete = 1;
782 6 }
783 5 }
784 4 else
785 4 {
786 5 bcnt = bcnt + MInfo.collPos - nbits;
787 5 status = MI_OK;
788 5 }
789 4 }
790 3 }
791 2 }
792 1 if (status == MI_OK)
793 1 {
794 2 memcpy(snr,snr_in,4);
795 2 }
796 1 else
797 1 {
798 2 memcpy(snr,"0000",4);
799 2 }
C51 COMPILER V7.06 RC500 12/15/2008 16:23:27 PAGE 14
800 1 ClearBitMask(RegDecoderControl,0x20);
801 1
802 1 return status;
803 1 }
804
805 //////////////////////////////////////////////////////////////////
806 // Cascaded Select command defined in ISO14443(MIFARE)
807 // 選擇卡 Select Card
808 //////////////////////////////////////////////////////////////////
809 char M500PiccCascSelect(unsigned char *snr,unsigned char *sak)
810 {
811 1 char idata status = MI_OK;
812 1
813 1 M500PcdSetTmo(106);
814 1
815 1 WriteIO(RegChannelRedundancy,0x0F);
816 1 ClearBitMask(RegControl,0x08);
817 1 ResetInfo(MInfo);
818 1 SerBuffer[0] = 0x93;
819 1 SerBuffer[1] = 0x70;
820 1
821 1 memcpy(SerBuffer + 2,snr,4);
822 1 SerBuffer[6] = SerBuffer[2] ^ SerBuffer[3] ^ SerBuffer[4] ^ SerBuffer[5];
823 1 MInfo.nBytesToSend = 7;
824 1 status = M500PcdCmd(PCD_TRANSCEIVE,SerBuffer,&MInfo);
825 1
826 1 *sak = 0;
827 1 if (status == MI_OK)
828 1 {
829 2 if (MInfo.nBitsReceived != 8)
830 2 {
831 3 status = MI_BITCOUNTERR;
832 3 }
833 2 else
834 2 {
835 3 *sak = SerBuffer[0];
836 3 }
837 2 }
838 1 return status;
839 1 }
840
841 ///////////////////////////////////////////////////////////////////////
842 // Key loading into the MF RC500's EEPROM
843 // 校驗卡密碼(E2)
844 ///////////////////////////////////////////////////////////////////////
845 /*char M500PiccAuthE2( unsigned char auth_mode,unsigned char *snr,
846 unsigned char keynr,unsigned char block)
847
848 {
849 char idata status = MI_OK;
850 unsigned int e2addr = 0x80 + keynr * 0x18;
851 //unsigned char *e2addrbuf = (unsigned char*)&e2addr;
852 unsigned char *e2addrbuf;
853
854 e2addrbuf = (unsigned char *)&e2addr;
855 if (auth_mode == PICC_AUTHENT1B)
856 {
857 e2addr += 12;
858 }
859 FlushFIFO();
860 ResetInfo(MInfo);
861
C51 COMPILER V7.06 RC500 12/15/2008 16:23:27 PAGE 15
862 memcpy(SerBuffer,e2addrbuf,2);
863 SerBuffer[2] = SerBuffer[0];
864 SerBuffer[0] = SerBuffer[1];
865 SerBuffer[1] = SerBuffer[2];
866 MInfo.nBytesToSend = 2;
867 if ((status=M500PcdCmd(PCD_LOADKEYE2,SerBuffer,&MInfo)) == MI_OK)
868 {
869 status = M500PiccAuthState(auth_mode,snr,block); //11.9
870 }
871 return status;
872 }*/
873
874 ///////////////////////////////////////////////////////////////////////
875 // Authentication key coding
876 ///////////////////////////////////////////////////////////////////////
877 /*char M500HostCodeKey( unsigned char *uncoded, unsigned char *coded)
878 {
879 char idata status = MI_OK;
880 unsigned char idata cnt = 0;
881 unsigned char idata ln = 0;
882 unsigned char idata hn = 0;
883 for (cnt = 0; cnt < 6; cnt++)
884 {
885 ln = uncoded[cnt] & 0x0F;
886 hn = uncoded[cnt] >> 4;
887 coded[cnt * 2 + 1] = (~ln << 4) | ln;
888 coded[cnt * 2 ] = (~hn << 4) | hn;
889 }
890 return MI_OK;
891 }*/
892
893 ///////////////////////////////////////////////////////////////////
894 // Authentication with direct key loading from the uC
895 // 直接校驗密碼
896 //////////////////////////////////////////////////////////////////
897 /*char M500PiccAuthKey( unsigned char auth_mode,
898 unsigned char *snr,
899 unsigned char *keys,
900 unsigned char block)
901 {
902 char idata status = MI_OK;
903 //PcdSetTmo(2);
904 FlushFIFO();
905 ResetInfo(MInfo);
906 memcpy(SerBuffer,keys,12);
907 MInfo.nBytesToSend = 12;
908 if ((status=M500PcdCmd(PCD_LOADKEY,SerBuffer,&MInfo)) == MI_OK)
909 {
910 status = M500PiccAuthState(auth_mode,snr,block);
911 }
912 return status;
913 }*/
914
915 ///////////////////////////////////////////////////////////////////////
916 ///////////////////////////////////////////////////////////////////////
917 /*char M500PiccAuthState( unsigned char auth_mode,unsigned char *snr,unsigned char block)
918 {
919 char idata status = MI_OK;
920 unsigned char idata i = 0;
921
922 status = ReadIO(RegErrorFlag);
923 if (status != MI_OK)
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -