📄 commtran.lst
字号:
512 3 }
513 2
514 2 for(i=0;i<temp[0];i++)
515 2 {
516 3 if(flag1)
517 3 {
518 4 Status=MF1_read_key(key_type,block_n+i,buf,key);
519 4 }
520 3 else Status=MF1_read(key_type,block_n+i,buf);
521 3 if(Status!=MI_OK) break;
C51 COMPILER V4.01, COMMTRAN 19/08/04 14:33:24 PAGE 9
522 3 else memcpy(ComBuffer+9+(i<<4),buf,16);
523 3 }
524 2 if(Status==MI_OK)
525 2 {
526 3 SendResponse(0x01,(temp[0]<<4)+18,buf); /* OK */
527 3 }
528 2 else
529 2 {
530 3 SendResponse(0x80,1,buf); /* read file error */
531 3 }
532 2
533 2 flag1=0;
534 2 break;
535 2
536 2
537 2 case 0xF9: /* write file */
538 2 //"格式 60 xx F9 (文件标识2字节)(密钥类型1字节)(起始块号)(偏移地址)(数据长度)(数据)
539 2 // 0 1 2 3 4 5 6 7 8 9 10--
540 2
541 2 Status=CheckMad2(buf2); /*get sector no.*/
542 2 if(Status!=MI_OK) return;
543 2
544 2 temp[0]=ComBuffer[8]; //"偏移地址
545 2 temp[1]=ComBuffer[9]; //"数据长度
546 2
547 2 LEN1=buf2[0]+buf2[0]+buf2[0];//"块数
548 2 LEN1=(LEN1<<4); //"字节数
549 2 if(((ComBuffer[7]<<4)+temp[0]+temp[1])>LEN1)
550 2 {
551 3 SendResponse(0x82,1,buf);
552 3 return;
553 3 }
554 2
555 2 LEN1=0;
556 2 LEN2=0;
557 2 for(j=1;j<=buf2[0];j++) //"一个文件多个扇区
558 2 {
559 3 sector_n=buf2[j];
560 3 block_n=(sector_n<<2);
561 3 keytest=ComBuffer[6]; //"密钥类型2(认证码标识和KEYA KEYB)
562 3 Status=Creat_key2(keytest,sector_n,ComBuffer[5],key);
563 3 if(Status!=MI_OK)
564 3 {
565 4 SendResponse(0x01,CREAT_KEY_ERROR,buf);
566 4 return ;
567 4 }
568 3 flag1=1;
569 3 if((keytest&0x0F)==0)
570 3 {
571 4 keytest=PICC_AUTHENT1A;
572 4 }
573 3 else keytest=PICC_AUTHENT1B;
574 3 if(flag1)
575 3 {
576 4 Status=MF1_authkey(keytest,key,block_n);
577 4 }
578 3 else Status=MF1_auth(keytest,sector_n,block_n);
579 3 if(Status!=MI_OK)
580 3 {
581 4 SendResponse(0x81,1,buf);
582 4 return;
583 4 }
584 3
585 3 for(i=0;i<3;i++)
586 3 {
587 4 if(flag1)
C51 COMPILER V4.01, COMMTRAN 19/08/04 14:33:24 PAGE 10
588 4 {
589 5 Status=MF1_read_key(keytest,block_n+i,TempBuffer+LEN2,key);
590 5 }
591 4 else Status=MF1_read(keytest,block_n+i,TempBuffer+LEN2);
592 4 if(Status!=MI_OK) break;
593 4 LEN2+=16;
594 4 }
595 3 if(Status!=MI_OK) break;
596 3 }
597 2
598 2 if(Status==MI_OK)
599 2 {
600 3 LEN1=(ComBuffer[7]<<4)+temp[0];//"绝对偏移地址
601 3
602 3 memcpy(TempBuffer+LEN1,ComBuffer+10,temp[1]);
603 3 LEN2=0;
604 3 for(j=1;j<=buf2[0];j++)
605 3 {
606 4 sector_n=buf2[j];
607 4 block_n=(sector_n<<2);
608 4 keytest=ComBuffer[6]; //"密钥类型2(认证码标识和KEYA KEYB )
609 4 Status=Creat_key2(keytest,sector_n,ComBuffer[5],key);//
610 4 if(Status!=MI_OK)
611 4 {
612 5 SendResponse(0x01,CREAT_KEY_ERROR,buf);
613 5 return ;
614 5 } //
615 4 flag1=1; //
616 4 keytest=(ComBuffer[6]&0x0F);
617 4 if(keytest==0)
618 4 {
619 5 keytest=PICC_AUTHENT1A;
620 5 }
621 4 else keytest=PICC_AUTHENT1B;
622 4
623 4 for(i=0;i<3;i++)
624 4 {
625 5 if(flag1)
626 5 {
627 6 Status=MF1_write_key(keytest,block_n+i,TempBuffer+LEN2,key);
628 6 }
629 5 else Status=MF1_write(keytest,block_n+i,TempBuffer+LEN2);
630 5 if(Status!=MI_OK) break;
631 5 LEN2+=16;
632 5 }
633 4 if(Status!=MI_OK) break;
634 4 }
635 3 }
636 2 if(Status==MI_OK) SendResponse(0x01,1,buf);
637 2 else SendResponse(0x80,1,buf);
638 2 flag1=0;
639 2 break;
640 2
641 2 case 0xFb: /* read file */
642 2 //"格式:要求支持一个文件占多个扇区(现在支持4个扇区)
643 2 //" 60 xx fb 文件标识(2) 密钥标识(2)开始块地址(1) 要读的块数(1)
644 2 //"现在0 1 2 3 4 5 6 7 8
645 2 //"原来0 1 2 3 4 5 6 7
646 2 Status=CheckMad2(buf2); /*get sector no.*/
647 2 if(Status!=MI_OK) return;
648 2
649 2 temp[0]=ComBuffer[7]; //"偏移地址
650 2 temp[1]=ComBuffer[8]; //"数据长度
651 2 LEN1=buf2[0]+buf2[0]+buf2[0];//"块数
652 2
653 2 if((temp[0]+temp[1])>LEN1)
C51 COMPILER V4.01, COMMTRAN 19/08/04 14:33:24 PAGE 11
654 2 {
655 3 SendResponse(0x82,1,buf);
656 3 return;
657 3 }
658 2
659 2 LEN1=0;
660 2 LEN2=0;
661 2 for(j=1;j<=buf2[0];j++) //"一个文件多个扇区
662 2 {
663 3 sector_n=buf2[j];
664 3 block_n=(sector_n<<2);
665 3 keytest=ComBuffer[6]; //"密钥类型2(认证码标识和KEYA KEYB)
666 3 Status=Creat_key2(keytest,sector_n,ComBuffer[5],key);
667 3 if(Status!=MI_OK) return;
668 3 flag1=1;
669 3 if((keytest&0x0F)==0)
670 3 {
671 4 keytest=PICC_AUTHENT1A;
672 4 }
673 3 else keytest=PICC_AUTHENT1B;
674 3 if(flag1)
675 3 {
676 4 Status=MF1_authkey(keytest,key,block_n);
677 4 }
678 3 else Status=MF1_auth(keytest,sector_n,block_n);
679 3 if(Status!=MI_OK)
680 3 {
681 4 SendResponse(0x81,1,buf);
682 4 return;
683 4 }
684 3
685 3 for(i=0;i<3;i++)
686 3 {
687 4 if(flag1)
688 4 {
689 5 Status=MF1_read_key(keytest,block_n+i,TempBuffer+LEN2,key);
690 5 }
691 4 else Status=MF1_read(keytest,block_n+i,TempBuffer+LEN2);
692 4 if(Status!=MI_OK) break;
693 4 LEN2+=16;
694 4 }
695 3 if(Status!=MI_OK) break;
696 3 }
697 2
698 2 LEN1=(temp[0]<<4);//"绝对地址
699 2 LEN2=(temp[1]<<4);//"长度
700 2 if(Status==MI_OK)
701 2 {
702 3 memcpy(ComBuffer+9,TempBuffer+LEN1,LEN2);
703 3 SendResponse(0x01,LEN2+18,buf);
704 3 }
705 2
706 2 else SendResponse(0x80,1,buf);
707 2 flag1=0;
708 2 break;
709 2
710 2
711 2 case 0x34: /* load_key */
712 2
713 2
714 2 if(ComBuffer[3]==0x01)
715 2 {
716 3 keytest=PICC_AUTHENT1B; /* KEYB */
717 3 }
718 2 else keytest=PICC_AUTHENT1A;
719 2 sector_n=ComBuffer[4]&0x0f; // so the sector is 0~15 for thr rc500
C51 COMPILER V4.01, COMMTRAN 19/08/04 14:33:24 PAGE 12
720 2
721 2 if((ComBuffer[4]==0x10)&(keytest==PICC_AUTHENT1A))
722 2 {
723 3 Status=Write_Ram_byte(0x0000,ComBuffer+5,6);
724 3 }
725 2 else if((ComBuffer[4]==0x10)&(keytest==PICC_AUTHENT1B))
726 2 {
727 3 Status=Write_Ram_byte(0x0006,ComBuffer+5,6);
728 3 }
729 2
730 2 else if((ComBuffer[4]>=0x20)&(ComBuffer[4]<=0x2f))
731 2 {
732 3 if(keytest==PICC_AUTHENT1A)
733 3 {
734 4 Status=Write_Ram_byte(0x0010,ComBuffer+5,6);
735 4 }
736 3 if(keytest==PICC_AUTHENT1B)
737 3 {
738 4 Status=Write_Ram_byte(0x0016,ComBuffer+5,6);
739 4 }
740 3 }
741 2
742 2 else Status=Mf500PcdLoadKeyE2(keytest,sector_n,ComBuffer+5);
743 2
744 2 if(Status==MI_OK)
745 2 {
746 3 SendResponse(0x01,1,buf);
747 3 }
748 2 else
749 2 {
750 3 SendResponse(0x80,1,buf);
751 3 }
752 2
753 2
754 2 break;
755 2
756 2
757 2 /******************************TIME COS COMMAND************************/
758 2 case 0x88: //T=CL;for mifare pro
759 2
760 2
761 2 switch(ComBuffer[3])//check message's head //2refrence TimeCos command
762 2 {
763 3 case 0x00: // 2 the first byte
764 3 case 0x04:
765 3 case 0x80:
766 3 case 0x84:
767 3 case 0xe0:
768 3 key_index=1; break;
769 3 default:
770 3 key_index=0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -