📄 disk3.lst
字号:
557 2 }
558 1
559 1 memset(package,0,len);
560 1
561 1
562 1 if(!DoComunication(package, len, 0))
563 1 {
564 2 errcode=ReceiveFromT8Err;
565 2 return false;
566 2 }
567 1 if(!ChkRn(package,len)) //check CRC
568 1 {
569 2 errcode=CRCERR;
570 2 return false;
571 2
572 2 }
573 1
574 1 DoXX(package, package, len-2, 0);
575 1 return true;
576 1 }
577
578 // SendPlainTextOpr,SendEncryptedDigestOpr 共用
579
580 /*
581 *************************************************************
582 * check whether the receive package is " receive
583 * ready" command,
584 * it return true if it is and modify MCU_SN value;
585 * it return false if it is not .
586 ***********************************************************
587 */
588 BOOL IsReceiveReadyCmd(){
589 1
590 1 if(package[0]==0xa1)
591 1 {
592 2 return true;
593 2 }
594 1 else
595 1 return false;
596 1 }
597
598 /*
599 *************************************************************
600 * check whether the receive package is " receive not
601 * ready" command,
602 * it return true if it is and modify MCU_SN value;
603 * it return false if it is not .
604 ***********************************************************
605 */
606 BOOL IsReceiveNotReadyCmd(){
607 1 if(package[0]==0xa2)
608 1 {
C51 COMPILER V7.02b DISK3 03/16/2006 13:52:41 PAGE 11
609 2 return true;
610 2 }
611 1 else
612 1 return false;
613 1 }
614
615 /*
616 *************************************************************
617 * check whether the receive package is "Power down command
618 * receive ready" command,
619 * it return true if it is; it return false if it is not .
620 ***********************************************************
621 */
622 BOOL IsPowerDownReadyCmd(){
623 1 if(*package==0xa3)
624 1 return true;
625 1 else
626 1 return false;
627 1 }
628
629 /*
630 *************************************************************
631 * check whether the receive package is "Power down command
632 * receive not ready" command,
633 * it return true if it is; it return false if it is not .
634 ***********************************************************
635 */
636 BOOL IsPowerDownNotReadyCmd(){
637 1 if(*package==0xa4)
638 1 return true;
639 1 else
640 1 return false;
641 1 }
642
643 /*
644 ***************************************************************
645 * check whether the receive package is "Reset command receive
646 * ready" command,
647 * it return true if it is; it return false if it is not .
648 ***********************************************************
649 */
650 BOOL IsResetReadyCmd(){
651 1 if(*package==0xa5)
652 1 return true;
653 1 else
654 1 return false;
655 1 }
656
657 /*
658 ***********************************************************
659 * check whether the receive package is "Reset command receive
660 * not ready" command,
661 * it return true if it is; it return false if it is not .
662 ***********************************************************
663 */
664 BOOL IsResetNotReadyCmd(){
665 1 if(*package==0xa6)
666 1 return true;
667 1 else
668 1 return false;
669 1 }
670
C51 COMPILER V7.02b DISK3 03/16/2006 13:52:41 PAGE 12
671 /*
672 ***********************************************************
673 * check whether the receive package is "Chip ID" command,
674 * it return true if it is,and copy 3 bytes ID data
675 * to the "pID" address if it is valid ;
676 * it return false if it is not .and it has no effect on
677 * the "pID" address.
678 ***********************************************************
679 */
680
681 BOOL IsChipIdCmd(BYTE *pID){
682 1 if(pID==NULL)
683 1 {
684 2 errcode=PRAMWRONG;
685 2 return false;
686 2 }
687 1 if(*package==0xa7)
688 1 {
689 2 memcpy(pID,package+2,3);
690 2 return TRUE;
691 2 }
692 1 else
693 1 return false;
694 1 }
695
696 /*
697 **************************************************
698 * prototype : BOOL GetResponseCmd()
699 * Des: send "Challenge" command on SPI or I2C bus
700 * here "text" is the poniter of 8 bytes array.
701 * If comunication succeed,it return true;
702 * If input parametre is error,it return false and errcode is 1.
703 *If comunication is not success,it return false and errcode is 2.
704 * Use GetLastError to determine.
705 ***************************************************
706 */
707 BOOL ChallengeCmd(BYTE *text){
708 1 // BYTE package[8+8+2];
709 1 if(text==NULL) //check input parametre
710 1 {
711 2 errcode=PRAMWRONG;
712 2 return false;
713 2 }
714 1
715 1 memset(package,0,18);
716 1 package[0]=0xb1;
717 1 package[1]=MCU_SN;
718 1 memcpy(package+8,text,8); //fill data to package
719 1
720 1 DoXX(package,package,16,1);
721 1
722 1 GetSn(package,8+8); //do CRC
723 1
724 1 return(DoComunication(package, 16+2, 1));
725 1 }
726
727 /*
728 ***********************************************************
729 * check whether the receive package is "Response" command,
730 * it return true if it is,and copy 8 bytes responds data
731 * to the "text" address if it is valid ;
732 * it return false if it is not .and it has no effect on
C51 COMPILER V7.02b DISK3 03/16/2006 13:52:41 PAGE 13
733 * the "text" address.
734 ***********************************************************
735 */
736 BOOL IsReponseCmd(BYTE *text){
737 1 if(text==NULL){ //check input parameter
738 2 errcode=PRAMWRONG;
739 2 return false;
740 2 }
741 1 if(*package==0xb2){
742 2 memcpy(text,package+8,8);
743 2 return true;
744 2 }
745 1 else
746 1 return false;
747 1 }
748
749 /*
750 **************************************************
751 * prototype : BOOL GetResponseCmd(BYTE * CId,BYTE len,BYTE Nvmoffset)
752 * Des: send "Challenge" command on SPI or I2C bus
753 * here "CId" is the poniter of len bytes array.
754 * If comunication succeed,it return true;
755 * If input parametre is error,it return false and errcode is 1.
756 *If comunication is not success,it return false and errcode is 2.
757 * Use GetLastError to determine.
758 ***************************************************
759 */
760 BOOL ChallengeCustomIdCmd(BYTE * CId,BYTE len,BYTE Nvmoffset) //add
761 {
762 1
763 1 if(CId==NULL||len>8||((Nvmoffset<0x20)||(Nvmoffset>0x7f))) //check input parame
-tre
764 1 {
765 2 errcode=PRAMWRONG;
766 2 return false;
767 2 }
768 1
769 1 memset(package,0,16);
770 1 package[0]=0xb3;
771 1 package[1]=MCU_SN;
772 1 package[6]=Nvmoffset;
773 1 package[7]=len;
774 1
775 1 memcpy(package+8,CId,len); //fill data to package
776 1
777 1 DoXX(package, package,8+8,1);
778 1
779 1 GetSn(package,8+8); //do CRC
780 1
781 1 DoComunication(package, 8+8+2,1);
782 1
783 1 }
784 /*
785 ***********************************************************
786 * check whether the receive package is "Response" command,
787 * it return true if it is,and copy 8 bytes responds data
788 * to the "text" address if it is valid ;
789 * it return false if it is not .and it has no effect on
790 * the "text" address.
791 ***********************************************************
792 */
793 BOOL IsCustomIdResponseCmd(BYTE *text) //add
C51 COMPILER V7.02b DISK3 03/16/2006 13:52:41 PAGE 14
794 {
795 1 if(text==NULL){ //check input parameter
796 2 errcode=PRAMWRONG;
797 2 return false;
798 2 }
799 1 if(*package==0xb4){
800 2 memcpy(text,package+8,8);
801 2 return true;
802 2 }
803 1 else
804 1 return false;
805 1 }
806
807 /*
808 **************************************************
809 * prototype : BOOL WriteKeyCmd(BYTE *nId,BYTE adr,BYTE * KEY)
810 * Des: send "Write Key" command on SPI or I2C bus
811 * here "KEY" is the poniter of 24 bytes array.
812 * If comunication succeed,it return true;
813 * If input parametre is error,it return false and errcode is 1.
814 *If comunication is not success,it return false and errcode is 2.
815 * Use GetLastError to determine.
816 ***************************************************
817 */
818
819
820 BOOL WriteKeyCmd(BYTE *nId,BYTE adr,BYTE * KEY)
821 {
822 1 // BYTE package[8+24+2];
823 1 static const BYTE t8SlvAdr=0x62; //default T8 device slave address for "Write Key" cmd
824 1 static const BYTE t8ID[3]={0,0,0}; //default T8 device ID for "Write Key" cmd
825 1
826 1 if(KEY==NULL)
827 1 {
828 2 errcode=PRAMWRONG;
829 2 return false;
830 2 }
831 1
832 1 memset(package,0,8+24);
833 1 package[0]=0xc1;
834 1 package[1]=RN;
835 1 if(adr!=(BYTE)NULL)
836 1 package[4]=adr;
837 1 else
838 1 package[4]=t8SlvAdr;
839 1
840 1
841 1 if(nId!=NULL)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -