⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 iccapp.lst

📁 mifarea卡程序mifarea卡程序mifarea卡程序
💻 LST
📖 第 1 页 / 共 5 页
字号:
 283   2              #ifdef DEBUGICC
                      ComWrite(response.SW, 2);/////////////////////////
                      ComWrite((char *)&response.ISW, 2);///////////////
                      #endif
 287   2              return (response.ISW);
 288   2          }
 289   1      }
 290          
 291          /*****************************************
 292           * des计算                               *
 293           * 80 fa 计算标识 00 Lc data             *
 294           * flag:                                 *
 295           *  0: 无后续块加密                      *
 296           *  1: 最后一块mac计算                   *
 297           *  2: 有后续块加密                      *
 298           *  3: 下一块mac计算                     *
 299           *  5: 唯一一块mac计算                   *
 300           *     此情况inbuf的前8个字节为初始值    *
 301           *     若不需要,请将前8个字节填0        *
 302           *  7: 第一块mac计算                     *
C51 COMPILER V7.07   ICCAPP                                                                12/06/2003 18:49:10 PAGE 6   

 303           *****************************************/
 304          int ICC_sam_des_mac(char *inbuf, unsigned char len, char *outbuf, unsigned char flag)
 305          {
 306   1           
 307   1          command.CLA = 0x80;
 308   1          command.INS = 0xfa;
 309   1          command.P1 = flag;
 310   1          command.P2 = 0;
 311   1          command.Lc = len;
 312   1          command.DAT = inbuf;
 313   1          command.Le = 0;
 314   1          
 315   1          if(!SamSendCommand(&command, &response))
 316   1              return -1;
 317   1          else
 318   1          {
 319   2              memcpy(outbuf, response.DAT, response.len);
 320   2              return response.ISW;
 321   2          }
 322   1      }
 323          /*****************************************
 324           * Get Transaction Proof(取交易认证码) *
 325           * CLA: 80, INS: 5a                      *
 326           * Secret and protect mode: NO           *
 327           * Suport: TimeCOS /PBOC                 *
 328           *参数1:交易标识;参数2:联机/脱机交易序号(2字节);参数3:输出交易认证码 *
 329           *****************************************/
 330          int ICC_get_transaction_proof(unsigned char trans_flag,unsigned char *trans_sn,unsigned char *MAC_TAC )
 331          {  
 332   1          command.CLA = 0x80;
 333   1          command.INS = 0x5a;
 334   1          command.P1 = 0;
 335   1          command.P2 = trans_flag;
 336   1          command.Lc = 2;
 337   1          command.DAT = trans_sn;
 338   1          command.Le = 8;
 339   1          
 340   1          if(!SamSendCommand(&command, &response))
 341   1              return -1;
 342   1          else
 343   1          {
 344   2              memcpy(MAC_TAC, response.DAT, response.len);
 345   2              return response.ISW;
 346   2          }
 347   1          
 348   1       }
 349          /*****************************************
 350           * Decrease                              *
 351           * CLA: 80, INS: 30                      *
 352           * Secret and protect mode: YES          *
 353           * Suport: TimeCOS only                  *
 354            *参数1:文件标识;参数2:长度;参数3:金额+MAC;*
 355           *****************************************/
 356          int ICC_decrease(unsigned char file_flag,char len,unsigned char *cash)
 357          {   
 358   1              command.CLA = 0x80;
 359   1          command.INS = 0x30;
 360   1          command.P1 = 0;
 361   1          command.P2 = file_flag;
 362   1          command.Lc = len;
 363   1          command.DAT =cash;
 364   1          command.Le = 0;
C51 COMPILER V7.07   ICCAPP                                                                12/06/2003 18:49:10 PAGE 7   

 365   1          
 366   1          if(!SamSendCommand(&command, &response))
 367   1              return -1;
 368   1          else
 369   1          {
 370   2                  return response.ISW;
 371   2          }    
 372   1      }
 373          
 374          /*****************************************
 375           * Increase                              *
 376           * CLA: 80, INS: 32                      *
 377           * Secret and protect mode: YES          *
 378           * Suport: TimeCOS only                  *
 379            *参数1:文件标识;参数2:长度;参数3:金额+MAC;*
 380           *****************************************/
 381          int ICC_increase(unsigned char file_flag,char len,unsigned char *cash)
 382          {   
 383   1              command.CLA = 0x80;
 384   1          command.INS = 0x32;
 385   1          command.P1 = 0;
 386   1          command.P2 = file_flag;
 387   1          command.Lc = len;
 388   1          command.DAT = cash;
 389   1          command.Le = 00;
 390   1          
 391   1          if(!SamSendCommand(&command, &response))
 392   1              return -1;
 393   1          else
 394   1             {
 395   2              return response.ISW;
 396   2             }
 397   1      }
 398          
 399          /*****************************************
 400           * Verify pin                            *
 401           * CLA: 00, INS: 20                      *
 402           * Secret and protect mode: YES          *
 403           * Suport: ISO/PBOC                      *
 404           *****************************************/
 405          int ICC_verify_pin(char *pin, int pinlen, int id)
 406          {
 407   1          
 408   1           
 409   1          command.CLA = 0x00;
 410   1          command.INS = 0x20;
 411   1          command.P1 = 0x00;
 412   1          command.P2 = id;
 413   1          command.Lc = pinlen;
 414   1          command.Le = 0;
 415   1          command.DAT = pin;
 416   1          
 417   1          if(!SamSendCommand(&command, &response))
 418   1              return -1;
 419   1          else
 420   1              return response.ISW;
 421   1      }
 422          
 423          /*****************************************
 424           * External authentication               *
 425           * CLA: 00, INS: 82                      *
 426           * Secret and protect mode: NO           *
C51 COMPILER V7.07   ICCAPP                                                                12/06/2003 18:49:10 PAGE 8   

 427           * Suport: ISO/PBOC                      *
 428           *****************************************/
 429          int ICC_external_auth(unsigned char *buf, unsigned char len, unsigned char keyid)
 430          {
 431   1           
 432   1          command.CLA = 0x00;
 433   1          command.INS = 0x82;
 434   1          command.P1 = 0x00;
 435   1          command.P2 = keyid;
 436   1          command.Lc = len;
 437   1          command.DAT = buf;
 438   1          command.Le = 0;
 439   1          
 440   1          if(!SamSendCommand(&command, &response))
 441   1              return -1;
 442   1          else
 443   1              return response.ISW;
 444   1      }
 445          
 446          /*****************************************
 447           * Internal authentication               *
 448           * CLA: 00, INS: 88                      *
 449           * Secret and protect mode: NO           *
 450           * Suport: ISO/PBOC                      *
 451           ************************************************
 452           * flag: 00: des加密,01:des解密,02:计算mac  *
 453           * keyid: 密钥标识号                            *
 454           * len: 待认证数据长度                          *
 455           * buf: 待认证数据                              *
 456           ************************************************/
 457          int ICC_internal_auth(unsigned char *inbuf, unsigned char len, unsigned char *outbuf,
 458                                unsigned char keyid, unsigned char flag)
 459          {
 460   1           
 461   1          command.CLA = 0x00;
 462   1          command.INS = 0x88;
 463   1          command.P1 = flag;
 464   1          command.P2 = keyid;
 465   1          command.Lc = len;
 466   1          command.Le = 0;
 467   1          command.DAT = inbuf;
 468   1      
 469   1          if(!SamSendCommand(&command, &response))
 470   1              return -1;
 471   1          else
 472   1          {
 473   2              memcpy(outbuf, response.DAT, response.len);
 474   2              return response.ISW;
 475   2          }
 476   1      }
 477          
 478          /*****************************************
 479           * Get challenge                         *
 480           * CLA: 00, INS: 84                      *
 481           * Secret and protect mode: NO           *
 482           * Suport: ISO/PBOC                      *
 483           *****************************************/
 484          int ICC_get_challenge(char *buf, unsigned char len)
 485          {
 486   1          command.CLA = 0x00;
 487   1          command.INS = 0x84;
 488   1          command.P1 = 0;
C51 COMPILER V7.07   ICCAPP                                                                12/06/2003 18:49:10 PAGE 9   

 489   1          command.P2 = 0;
 490   1          command.Lc = 0;
 491   1          command.Le = len;
 492   1          
 493   1          if(!SamSendCommand(&command, &response))
 494   1              return -1;
 495   1          else
 496   1          {
 497   2              memcpy(buf, response.DAT, response.len);
 498   2                      return response.ISW;
 499   2              }
 500   1      }
 501          
 502          /*****************************************
 503           * Select file                           *
 504           * CLA: 00, INS: A4                      *
 505           * NOT suport secret and protect mode    *
 506           * Suport: ISO/PBOC                      *
 507           ********************************************************
 508           * flag: 0:通过表示符选择,1:通过文件名选择第一个     *
 509           *       2:通过文件名选择下一个                        *
 510           * filename_id: 文件名/标识                             *
 511           * len:         文件名称的长度                          *
 512           * fci:         文件控制信息(大于等于128字节)         *
 513           ********************************************************/
 514          int ICC_select_file(char *filename_id, unsigned char len, unsigned char flag, char *fci)
 515          {
 516   1           
 517   1          command.CLA = 0x00;
 518   1          command.INS = 0xA4;
 519   1          if(flag == 0)
 520   1          {
 521   2              command.P1 = 0x00;
 522   2              command.P2 = 0x00;
 523   2              command.Lc = 2;
 524   2          }
 525   1          else if(flag == 1)
 526   1          {
 527   2              command.P1 = 0x04;
 528   2              command.P2 = 0x00;
 529   2              command.Lc = len;
 530   2          }
 531   1          else if(flag == 2)
 532   1          {
 533   2              command.P1 = 0x04;
 534   2              command.P2 = 0x02;
 535   2              command.Lc = len;
 536   2          }
 537   1          else return -1;
 538   1          
 539   1          command.DAT = filename_id;
 540   1          
 541   1          command.Le = 0;
 542   1          
 543   1          if(!SamSendCommand(&command, &response))
 544   1              return -1;
 545   1          else
 546   1          {
 547   2              memcpy(fci, response.DAT, response.len);
 548   2              return response.ISW;
 549   2          }
 550   1      }
C51 COMPILER V7.07   ICCAPP                                                                12/06/2003 18:49:10 PAGE 10  

 551          
 552          /*****************************************
 553           * Read binary file                      *
 554           * CLA: 00, INS: B0                      *
 555           * Secret and protect mode: YES          *
 556           * Suport: ISO/PBOC                      *
 557           *****************************************
 558           * para1: 短文标识或偏移量高字节         *
 559           *      如果是偏移量高字节则读当前文件   *
 560           * para2: 偏移量低字节                   *
 561           * len: 欲读的长度                       *
 562           * buf: 输出,读到的内容                 *
 563           *****************************************/
 564          int ICC_read_binary(unsigned char para1, unsigned char para2, char *buf, unsigned char len)
 565          {   
 566   1              command.CLA = 00;
 567   1          command.INS = 0xb0;
 568   1          command.P1 = para1;
 569   1          command.P2 = para2;
 570   1          command.Lc = 0;
 571   1          command.Le = len;
 572   1      

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -