📄 wrrc500.lst
字号:
373 char Mf500PiccCascSelect(unsigned char *snr)
374 {
375 1 char status;// = MI_OK;
376 1 PcdSetTmo(106);
377 1
378 1 RegChannelRedundancy=0x0F; // RxCRC,TxCRC, Parity enable
379 1 RegControl = RegControl & (~0x08); // disable crypto 1 unit
380 1
381 1 RegInterruptEn=0x7F; // disable all interrupts
382 1 RegInterruptRq=0x7F; // reset interrupt requests
383 1 RegCommand=0x00; //PCD_IDLE; // terminate probably running command
384 1
385 1 RegControl=RegControl | 0x01;//clear FIFO
386 1
387 1 RegFIFOData=0x93; //write code "SEL"
388 1 RegFIFOData=0x70; //write code "NVB"
389 1 for(status=0;status<4;status++) RegFIFOData= snr[status]; //write snr
390 1 status=snr[0]^snr[1]^snr[2]^snr[3]; //BCC
391 1 RegFIFOData=status; //write BCC
392 1
393 1 RegInterruptEn=0xA4; //enable TimerIRq and IdleIRq
394 1
395 1 RegCommand=PCD_TRANSCEIVE; //0x1e; //start command
396 1
397 1 MRC500_CNT=0x00;
398 1
399 1 while( (!(RegPrimaryStatus & 0x08)) && (MRC500_CNT<=20000) ) {MRC500_CNT+=1;} // wait for completion or
- timeout
400 1 if(MRC500_CNT>10000) // access mrc500 timeout
401 1 {
402 2 RegCommand=0x00; //PCD_IDLE; // terminate running command
403 2 status= MI_ACCESSTIMEOUT;
404 2 return status;
405 2 }
406 1
407 1 status=RegInterruptRq; //read interrupt request source
408 1
409 1 if( status & 0x20) status = MI_NOTAGERR; // timeout error
410 1
411 1 else
412 1 {
413 2 //====================================================
414 2 delay_1ms(1);
415 2 //====================================================
416 2 RegControl=RegControl | 0x04; // stop timer now
417 2 status=RegErrorFlag & 0x1F;//read error flag
418 2 if(status)
419 2 {
420 3 if (status & 0x01) status = MI_COLLERR; // collision detected
421 3 else if(status & 0x02) status = MI_PARITYERR; // parity error
422 3 else if(status & 0x04) status = MI_FRAMINGERR; // framing error
423 3 else if(status & 0x10) status = MI_OVFLERR; // FIFO overflow
424 3 else status = MI_CRCERR; //CRC error
425 3 }
C51 COMPILER V8.01 WRRC500 03/29/2008 15:10:44 PAGE 8
426 2 else
427 2 {
428 3 if(RegFIFOLength==0x01) //received data length
429 3 {
430 4 //status = RegFIFOData & 0x04; //read SAK
431 4 if (RegFIFOData & 0x04) status = MI_SAKERR; //SAK error
432 4 else status=MI_OK;
433 4 }
434 3 else status=MI_BITCOUNTERR;
435 3 }
436 2 }
437 1
438 1 RegCommand=0x00; //PCD_IDLE; // terminate running command
439 1 return status;
440 1 }
441
442
443 ///////////////////////////////////////////////////////////////////////
444 ///////////////////////////////////////////////////////////////////////
445 // C O D E K E Y S
446 ///////////////////////////////////////////////////////////////////////
447 void CodeKey( unsigned char *uncoded, // 6 bytes key value uncoded
448 unsigned char *coded) // 12 bytes key value coded
449 {
450 1 unsigned char xdata cnt = 0;
451 1 unsigned char xdata ln = 0; // low nibble
452 1 unsigned char xdata hn = 0; // high nibble
453 1
454 1 for (cnt = 0; cnt < 6; cnt++)
455 1 {
456 2 ln = uncoded[cnt] & 0x0F;
457 2 hn = uncoded[cnt] >> 4;
458 2 coded[cnt * 2 + 1] = (~ln << 4) | ln;
459 2 coded[cnt * 2 ] = (~hn << 4) | hn;
460 2
461 2 }
462 1 }
463 ///////////////////////////////////////////////////////////////////////
464 // LOAD KEY TO MRC500 MASTER KEY BUFFER (WITH PROVIDED KEYS)
465 ///////////////////////////////////////////////////////////////////////
466 char MRC500LoadKey1(unsigned char *keys) //6 bytes key value uncoded
467 {
468 1 char status;// = MI_OK;
469 1 unsigned char idata coded_keys[12];
470 1 CodeKey(keys,coded_keys); //code keys to 12 bytes
471 1
472 1 PcdSetTmo(106);
473 1
474 1 RegInterruptEn=0x7F; // disable all interrupts
475 1 RegInterruptRq=0x7F; // reset interrupt requests
476 1 RegCommand=0x00; //PCD_IDLE; // terminate probably running command
477 1 RegControl=RegControl | 0x01;//clear FIFO
478 1
479 1 for(status=0;status<12;status++) RegFIFOData=coded_keys[status]; //write 12bytes key to fifo
480 1
481 1 RegInterruptEn=0xA4; //enable TimerIRq and IdleIRq
482 1
483 1 RegCommand=PCD_LOADKEY; //0x19; //start command
484 1
485 1 MRC500_CNT=0x00; //reset u-controller timeout
486 1
487 1 while( (!(RegPrimaryStatus & 0x08)) && (MRC500_CNT<20000) ) {MRC500_CNT+=1;} // wait for completion or
C51 COMPILER V8.01 WRRC500 03/29/2008 15:10:44 PAGE 9
- timeout
488 1 if(MRC500_CNT>10000) // access mrc500 timeout
489 1 {
490 2 RegCommand=0x00; //PCD_IDLE; // terminate running command
491 2 status= MI_ACCESSTIMEOUT;
492 2 return status;
493 2 }
494 1
495 1 status=RegInterruptRq; //read interrupt request source
496 1
497 1 if( status & 0x20) status = MI_NOTAGERR; // timeout error
498 1
499 1 else
500 1 {
501 2 RegControl=RegControl | 0x04; // stop timer now
502 2 status=RegErrorFlag;//read error flag
503 2 if(status)
504 2 {
505 3 if (status & 0x40) status = MI_KEYERR; // key error flag set
506 3 else status = MI_AUTHERR; // generic authentication error
507 3 }
508 2 else
509 2 {
510 3 status=MI_OK;
511 3 }
512 2 }
513 1
514 1 RegCommand=0x00; //PCD_IDLE; // terminate running command
515 1 return status;
516 1 }
517
518 ///////////////////////////////////////////////////////////////////////
519 // A U T H E N T I C A T I O N
520 ///////////////////////////////////////////////////////////////////////
521 char MRC500PiccAuthentication( unsigned char auth_mode, // PICC_AUTHENT1A or PICC_AUTHENT1B
522 unsigned char *snr, // 4 bytes card serial number
523 unsigned char block) // 0 <= block <= 64
524 {
525 1 char status; // = MI_OK;
526 1 PcdSetTmo(106);
527 1
528 1 RegInterruptEn=0x7F; // disable all interrupts
529 1 RegInterruptRq=0x7F; // reset interrupt requests
530 1 RegCommand=0x00; //PCD_IDLE; // terminate probably running command
531 1 RegControl=RegControl | 0x01;//clear FIFO
532 1
533 1 RegFIFOData=auth_mode; // write authentication command
534 1 RegFIFOData=block; // write block number for authentication
535 1 for(status=0;status<4;status++) RegFIFOData=snr[status]; //write snr
536 1
537 1 RegInterruptEn=0xA4;//0xA4; //enable TimerIRq and IdleIRq
538 1
539 1 RegCommand=PCD_AUTHENT1; //PCD_AUTHENT1; //start command
540 1
541 1 MRC500_CNT=0x00; //reset u-controller timeout
542 1 while( (!(RegPrimaryStatus & 0x08)) && (MRC500_CNT<20000) ) {MRC500_CNT+=1;} // wait for completion or
-timeout
543 1
544 1 if(MRC500_CNT>10000) // access mrc500 timeout
545 1 {
546 2 RegCommand=0x00; //PCD_IDLE; // terminate running command
547 2 status= MI_ACCESSTIMEOUT;
C51 COMPILER V8.01 WRRC500 03/29/2008 15:10:44 PAGE 10
548 2 return status;
549 2 }
550 1
551 1 status=RegInterruptRq; //read interrupt request source
552 1 if( !(status & 0x04)) status= MI_NOTAGERR; // timeout error
553 1 else
554 1 {
555 2
556 2 delay_1ms(1);
557 2
558 2 if(RegSecondaryStatus & 0x07) status=MI_BITCOUNTERR; // RxLastBits mu
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -