📄 sim.lst
字号:
525 void SelectFile(uchar xp1,uchar xp2,uchar lc,uchar *dat,uchar card)
526 {//lc=0x02 or 0x10; *dat:文件标识符或名称
527 1 uchar i;
528 1 uint statecode;
529 1
530 1 TxdBuf[0]=0x00;
531 1 TxdBuf[1]=0xA4;
532 1 TxdBuf[2]=xp1;
533 1 TxdBuf[3]=xp2;
534 1 TxdBuf[4]=lc;
535 1 for(i=0;i<lc;i++)
536 1 TxdBuf[5+i]=dat[i];
537 1 statecode=SimCmd(lc+5,card);
538 1 if(statecode == 0x9000)return;
539 1 if((statecode & 0xFF00)!=0x6100)
540 1 {
541 2 if(card==0)ErrorHint("选择税控卡文件出错!",statecode);
542 2 if(card==1)ErrorHint("选择用户卡文件出错!",statecode);
543 2 else ErrorHint("选择管理卡文件出错!",statecode);
544 2 }
545 1 i= statecode&0x00FF;
546 1 statecode=GetResponse(i,card);
547 1 if(statecode != 0x9000)
548 1 {
549 2 if(card==0)ErrorHint("读税控卡文件数据出错!",statecode);
550 2 if(card==1)ErrorHint("读用户卡文件数据出错!",statecode);
C51 COMPILER V8.01 SIM 03/28/2006 09:48:50 PAGE 10
551 2 else ErrorHint("读管理卡文件数据出错!",statecode);
552 2 }
553 1
554 1 }
555
556 void AppBlockHint(uchar card,uchar state)
557 {
558 1 uchar str[30];
559 1 uint k;
560 1
561 1 memset(str,0,sizeof(str));
562 1 switch(card)
563 1 {
564 2 case 0: strcpy(str,"税控");
565 2 case 1: strcpy(str,"用户");
566 2 default:strcpy(str,"管理");
567 2 }
568 1 if(state!=0)
569 1 {
570 2 k=0x9303;
571 2 strcpy(&str[4],"卡应用被永久锁定!");
572 2 }
573 1 else
574 1 {
575 2 strcpy(&str[4],"卡认证方法(PIN)锁定!");
576 2 k=0x6983;
577 2 }
578 1 ErrorHint(str,k);
579 1 }
580
581 void VerifyFiscalPin()
582 {//效验税控机使用口令,执行成功后得到新的使用口令
583 1 uchar i,flg,k,dat[10];
584 1 uint statecode;
585 1
586 1 I2cRead(MacState,1,&k);
587 1 if(k==3)
588 1 statecode=OriginalPwd; //锁机时使用税控卡注册时得到的使用口令进行校验
589 1 else
590 1 statecode=FiscalPwd;
591 1 I2cRead(statecode,8,dat);
592 1 //----------------------------------
593 1 TxdBuf[0]=0xC0;
594 1 TxdBuf[1]=0xF9; //VerifyFiscalPin
595 1 TxdBuf[2]=0x00;
596 1 TxdBuf[3]=0x00;
597 1 TxdBuf[4]=0x08;
598 1 for(i=0;i<8;i++)
599 1 TxdBuf[5+i] = dat[i];
600 1 TxdBuf[13]=0x08;
601 1 statecode=SimCmd(14,0); //向税控卡发送
602 1 if(statecode != 0x6108)
603 1 {
604 2 if(statecode == 0x6983)
605 2 {
606 3 dat[0]=3;
607 3 I2cWrite(MacState,1,dat);
608 3 AppBlockHint(0,0);
609 3 }
610 2 else
611 2 ErrorHint("使用口令效验出错!",statecode);
612 2 }
C51 COMPILER V8.01 SIM 03/28/2006 09:48:50 PAGE 11
613 1 statecode=GetResponse(8,0);
614 1 if(statecode != 0x9000)
615 1 {
616 2 ErrorHint("返回使用口令出错!",statecode);
617 2 }
618 1 for(i=0;i<8;i++)
619 1 dat[i] = RxdBuf[i];
620 1 //.......................................................
621 1 ReadBinary(0x82,102,1,0); //读取税控卡使用口令标志
622 1 flg=RxdBuf[0];
623 1 if(flg) //根据使用口令标志确定是否保存新的口令
624 1 I2cWrite(FiscalPwd,8,dat);
625 1 if(k==3)
626 1 {
627 2 dat[0]=4;
628 2 I2cWrite(MacState,1,dat);
629 2 }
630 1 //.......................................................
631 1 }
632
633 void GetChallenge(uchar le,uchar *dat,uchar card)
634 {//得到一个用于相关过程的随机数,le=4 or 8
635 1 uint statecode;
636 1 uchar i;
637 1
638 1 if(le!=4)le=8;
639 1 TxdBuf[0]=0x00;
640 1 TxdBuf[1]=0x84;
641 1 TxdBuf[2]=0x00;
642 1 TxdBuf[3]=0x00;
643 1 TxdBuf[4]=le;
644 1 statecode=SimCmd(5,card);
645 1 if(statecode != 0x9000)
646 1 {
647 2 ErrorHint("取随机数出错!",statecode);
648 2 }
649 1 for(i=0;i<le;i++)
650 1 dat[i]=RxdBuf[i];
651 1 }
652
653 uint ReadRecord(uchar m,uchar xp1,uchar xp2,uchar le,uchar card)
654 {
655 1 uint statecode;
656 1
657 1 TxdBuf[0]=0x00;
658 1 TxdBuf[1]=0xB2; //ReadRecord
659 1 TxdBuf[2]=xp1; //记录号
660 1 TxdBuf[3]=xp2; //低3位是100,若高5位不是00000就表示短文件标识符,否则表示当前文件
661 1 TxdBuf[4]=le;
662 1 statecode=SimCmd(5,card);
663 1 if(statecode == 0x9000)return 1;
664 1 if(statecode == 0x6A83 && m==0)return statecode;
665 1 if(card==0)ErrorHint("读税控卡记录文件出错!",statecode);
666 1 if(card==1)ErrorHint("读用户卡记录文件出错!",statecode);
667 1 else ErrorHint("读管理卡记录文件出错!",statecode);
668 1 }
669
670
671 void UpdateRecord(uchar xp1,uchar lc,uchar *dat,uchar card)
672 {//本函数无线路加密和保护
673 1 uint statecode;
674 1 uchar i;
C51 COMPILER V8.01 SIM 03/28/2006 09:48:50 PAGE 12
675 1
676 1 TxdBuf[0]=0x00;
677 1 TxdBuf[1]=0xDC;
678 1 TxdBuf[2]=xp1;
679 1 TxdBuf[3]=0x04;
680 1 TxdBuf[4]=lc;
681 1 for(i=0;i<lc;i++)
682 1 TxdBuf[5+i]=dat[i];
683 1 statecode=SimCmd(lc+5,card); //向税控卡发送
684 1 if(statecode != 0x9000)
685 1 {
686 2 if(card==0)ErrorHint("更新税控卡记录文件出错!",statecode);
687 2 if(card==1)ErrorHint("更新用户卡记录文件出错!",statecode);
688 2 else ErrorHint("更新管理卡记录文件出错!",statecode);
689 2 }
690 1 }
691
692 /*
693 //MAC 如何取得????
694 void AppendRecord(uchar cla,uchar xp2,uchar lc,uchar *dat,uchar card)
695 {//用于对变长记录文件和循环文件追加记录,
696 //lc是否加4应该在调用本程序前赋值确定
697 uint statecode;
698 uchar i;
699
700 TxdBuf[0]=cla;
701 TxdBuf[1]=0xE2;
702 TxdBuf[2]=0x00;
703 TxdBuf[3]=xp2;
704 // if(cla==0x04)lc+=4;
705 TxdBuf[4]=lc;
706 for(i=0;i<lc;i++)
707 TxdBuf[5+i]=dat[i];
708 statecode=SimCmd(lc+5,card); //向税控卡发送
709 if(statecode != 0x9000)
710 {
711 ErrorHint("追加记录出错!",statecode);
712 }
713 }
714
715
716
717 //MAC 如何取得????
718 void UpdateBinary(uchar cla,uchar xp1,uchar xp2,uchar lc,uchar *dat,uchar card)
719 {//lc是否加4应该在调用本程序前赋值确定
720 uint statecode;
721 uchar i;
722
723 TxdBuf[0]=cla;
724 TxdBuf[1]=0xD6;
725 TxdBuf[2]=xp1;
726 TxdBuf[3]=xp2;
727 // if(cla==0x04)lc+=4;
728 TxdBuf[4]=lc;
729 for(i=0;i<lc;i++)
730 TxdBuf[5+i]=dat[i];
731 statecode=SimCmd(lc+5,card); //向税控卡发送
732 if(statecode != 0x9000)
733 {
734 ErrorHint("更新二进制文件出错!",statecode);
735 }
736 }
C51 COMPILER V8.01 SIM 03/28/2006 09:48:50 PAGE 13
737 */
738 void ReadBinary(uchar xp1,uchar xp2,uchar le,uchar card)
739 {
740 1 uint statecode;
741 1
742 1 TxdBuf[0]=0x00;
743 1 TxdBuf[1]=0xB0;
744 1 TxdBuf[2]=xp1;
745 1 TxdBuf[3]=xp2;
746 1 TxdBuf[4]=le;
747 1 statecode=SimCmd(5,card);
748 1 if(statecode != 0x9000)
749 1 {
750 2 if(card==0)ErrorHint("读税控卡二进制文件出错!",statecode);
751 2 if(card==1)ErrorHint("读用户卡二进制文件出错!",statecode);
752 2 else ErrorHint("读管理卡二进制文件出错!",statecode);
753 2 }
754 1 }
755
756 void ExternalAuthentication(uchar xp2,uchar *dat,uchar card)
757 {
758 1 uint statecode;
759 1 uchar i;
760 1
761 1 TxdBuf[0]=0x00;
762 1 TxdBuf[1]=0x82;
763 1 TxdBuf[2]=0x00;
764 1 TxdBuf[3]=xp2;
765 1 TxdBuf[4]=0x08;
766 1 for(i=0;i<8;i++)
767 1 TxdBuf[5+i]=dat[i];
768 1 statecode=SimCmd(13,card);
769 1 if(statecode != 0x9000)
770 1 {
771 2 ErrorHint("外部认证出错!",statecode);
772 2 }
773 1 }
774
775 void InternalAtuhntication(uchar xp2,uchar *dat,uchar card)
776 {
777 1 uint statecode;
778 1 uchar i;
779 1
780 1 TxdBuf[0]=0x00;
781 1 TxdBuf[1]=0x88;
782 1 TxdBuf[2]=0x00;
783 1 TxdBuf[3]=xp2;
784 1 TxdBuf[4]=0x08;
785 1 for(i=0;i<8;i++)
786 1 TxdBuf[5+i]=dat[i];
787 1 i=13;
788 1 statecode=SimCmd(i,card); //向税控卡发送
789 1 if(statecode != 0x6108)
790 1 {
791 2 ErrorHint("内部认证出错1!",statecode);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -