OpenCV中文网站

 找回密码
 立即注册
搜索
热搜: 安装 配置
查看: 3276|回复: 0

各位前辈 想问问你们ic卡4442的密码检验问题

[复制链接]
发表于 2018-12-26 13:38:34 | 显示全部楼层 |阅读模式
我用的是stm32l053的单片机读写ic卡,读取错误计数器和读取操作返回值都是正确的,但是遇到的问题就是密码校验不过。
下面是密码校验的函数  ReadPsw读出来的值是计数器的值,我读出来是0x7  但是在校验之后在46行的ReadPsw函数读出来就变成了0x3
不知道在哪里出了问题 卡了我两天了。
  1. uint8_t Check_Pass(uint8_t *password)
  2. {
  3.         int i=0;
  4.         uint8_t ReadBuf[4]={0};

  5.         ReadPsw(ReadBuf);
  6.        
  7.        
  8.         for(i=0;i<10;i++)
  9.         {
  10.   if(IC_Reset())
  11.         {
  12.           break;
  13.         }
  14.         }
  15.         if(i==10)
  16.         {
  17.         return -1;
  18.         }
  19.         if(ReadBuf[0]==0x07)                       
  20.         {
  21.                 Send_Comand(WRITE_SAFE_MEM,0,0x03);                //½«ECдΪ0x03
  22.                 IC_Wait();                                              //·¢ËͲÙ×÷Âö³å
  23.         }
  24.         else if(ReadBuf[0]==0x06 || ReadBuf[0]==0x05 || ReadBuf[0]==0x03)
  25.         {
  26.                 Send_Comand(WRITE_SAFE_MEM,0,0x01);          //½«ECдΪ0x01
  27.                 IC_Wait();                                              //·¢ËͲÙ×÷Âö³å
  28.         }
  29.         else if(ReadBuf[0]==0x01 || ReadBuf[0]==0x02 || ReadBuf[0]==0x04)
  30.         {
  31.                 Send_Comand(WRITE_SAFE_MEM,0,0x00);                //½«ECдΪ0x00
  32.            IC_Wait();                                              //·¢ËͲÙ×÷Âö³å
  33.         }
  34.                        
  35.         Send_Comand(SLE_PSC_CHK,1,password[0]);//УÑéÃÜÂëµÄµÚÒ»¸ö×Ö½Ú
  36.         IC_Wait();                                                 //·¢ËͲÙ×÷Âö³å                                                       
  37.         Send_Comand(SLE_PSC_CHK,2,password[1]);//УÑéÃÜÂëµÄµÚ¶þ¸ö×Ö½Ú
  38.         IC_Wait();                                                //·¢ËͲÙ×÷Âö³å
  39.         Send_Comand(SLE_PSC_CHK,3,password[2]);//УÑéÃÜÂëµÄµÚÈý¸ö×Ö½Ú
  40.         IC_Wait();                                                //·¢ËͲÙ×÷Âö³å

  41.         Send_Comand(WRITE_SAFE_MEM,0,0xff);                        //²Á³ý´íÎó¼ÆÊýÆ÷
  42.         IC_Wait();                                                //·¢ËͲÙ×÷Âö³å

  43.   ReadPsw([ReadBuf]);

  44.        
  45.         if(ReadBuf[0] == 0x07)
  46.         {
  47.                 return 3;        //Ê£ÏÂ3´ÎУÑé»ú»á,УÑéÃÜÂë³É¹
  48.         }
  49.         else if(ReadBuf[0] == 0x06 || ReadBuf[0] == 0x05 || ReadBuf[0] == 0x03)
  50.         {               
  51.                 return 2;//Ê£ÏÂ2´ÎУÑé»ú»á,УÑéÃÜÂëʧ°
  52.         }                                                               
  53.         else if(ReadBuf[0] == 0x04 || ReadBuf[0] == 0x02 || ReadBuf[0] == 0x01)
  54.         {
  55.         return 1;//Ê£ÏÂ1´ÎУÑé»ú»á,УÑéÃÜÂëʧ°Ü
  56.         }               
  57.         else return 0;                //Ê£ÏÂ0´ÎУÑé»ú»á,¿¨±¨·Ï

  58. }
复制代码




调用过程
  1. uint8_t test(uint8_t *password)
  2. {
  3.         uint8_t ReadBuf[8]={0};
  4.   int i=0;
  5.         for(i=0;i<10;i++)
  6.         {
  7.   if(IC_Reset())
  8.         {
  9.           break;
  10.         }
  11.         }
  12.         if(i==10)
  13.         {
  14.         return -1;
  15.         }
  16.         i=Check_Pass(password);
  17.         if(i!=3)
  18.         {
  19.           return -1;
  20.         }
  21. //        Send_Comand(WRITE_SAFE_MEM,0x10,0x11);          //½«ECдΪ0x01
  22.         ////Read(READ_PSCR,20,0x11);
  23. }
复制代码





回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|OpenCV中文网站

GMT+8, 2024-3-29 03:36 , Processed in 0.008280 second(s), 15 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表