Advertisement
Guest User

Untitled

a guest
Oct 25th, 2019
1,224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.76 KB | None | 0 0
  1. #include <Wire.h>
  2. #include <SPI.h>
  3. #include <Adafruit_PN532.h>
  4. #define PN532_SCK  (13)
  5. #define PN532_MOSI (11)
  6. #define PN532_SS   (10)
  7. #define PN532_MISO (12)
  8. Adafruit_PN532 nfc(PN532_SCK, PN532_MISO, PN532_MOSI, PN532_SS);
  9.  
  10. void setup(void) {
  11.   Serial.begin(230400);
  12.   nfc.begin();
  13.   uint32_t versiondata = nfc.getFirmwareVersion();
  14.   if (! versiondata) {
  15.     Serial.print("Didn't find PN53x board");
  16.     while (1);
  17.   }
  18.   Serial.print("GET PN532");
  19.   Serial.println((versiondata>>24) & 0xFF, HEX);
  20.   nfc.SAMConfig();
  21.   }
  22.  
  23. void loop()
  24. {
  25.   bool success;
  26.   // set shield to inListPassiveTarget
  27.   success = nfc.inListPassiveTarget();
  28.   if(success) {
  29.         uint8_t selectApdu[] = {0x00, 0xA4, 0x04, 0x00, 0x0E, 0x32, 0x50, 0x41, 0x59, 0x2E, 0x53, 0x59, 0x53, 0x2E, 0x44, 0x44, 0x46, 0x30, 0x31, 0x00};
  30.         uint8_t response[255];
  31.         memset(response, 0, sizeof(response));
  32.         uint8_t responseLength = sizeof(response);  
  33.         success = nfc.inDataExchange(selectApdu, sizeof(selectApdu), response, &responseLength);
  34.         if(success) {
  35.               Serial.print("responseLength: "); Serial.println(responseLength);
  36.               nfc.PrintHexChar(response, responseLength);
  37.               uint8_t selectApdu[] = {0x00, 0xA4, 0x04, 0x00, 0x07, 0xA0, 0x00, 0x00, 0x00, 0x04, 0x10, 0x10, 0x00};
  38.               memset(response, 0, sizeof(response));
  39.               uint8_t responseLength = sizeof(response);
  40.               success = nfc.inDataExchange(selectApdu, sizeof(selectApdu), response, &responseLength);
  41.               if(success) {
  42.                     Serial.print("responseLength: "); Serial.println(responseLength);
  43.                     nfc.PrintHexChar(response, responseLength);
  44.                     uint8_t selectApdu[] = {0x80, 0xA8, 0x00, 0x00, 0x02, 0x83, 0x00, 0x00};
  45.                     memset(response, 0, sizeof(response));
  46.                     uint8_t responseLength = sizeof(response);
  47.                     success = nfc.inDataExchange(selectApdu, sizeof(selectApdu), response, &responseLength);
  48.                     if(success) {
  49.                           Serial.print("responseLength: "); Serial.println(responseLength);
  50.                           nfc.PrintHexChar(response, responseLength);
  51.                           uint8_t selectApdu[] = {0x00, 0xB2, 0x01, 0x0C, 0x00};
  52.                           memset(response, 0, sizeof(response));
  53.                           uint8_t responseLength = sizeof(response);
  54.                           success = nfc.inDataExchange(selectApdu, sizeof(selectApdu), response, &responseLength);
  55.                           if(success) {
  56.                             Serial.print("responseLength: "); Serial.println(responseLength);
  57.                             nfc.PrintHexChar(response, responseLength);
  58.                             uint8_t selectApdu[] = {0x00, 0xB2, 0x02, 0x14, 0x00};
  59.                             memset(response, 0, sizeof(response));
  60.                             uint8_t responseLength = sizeof(response);
  61.                             success = nfc.inDataExchange(selectApdu, sizeof(selectApdu), response, &responseLength);
  62.                             if(success) {
  63.                               Serial.print("responseLength: "); Serial.println(responseLength);
  64.                               nfc.PrintHexChar(response, responseLength);
  65.                               uint8_t selectApdu[] = {0x00, 0xB2, 0x03, 0x14, 0x00};
  66.                               memset(response, 0, sizeof(response));
  67.                               uint8_t responseLength = sizeof(response);
  68.                               success = nfc.inDataExchange(selectApdu, sizeof(selectApdu), response, &responseLength);
  69.                               if(success) {
  70.                                 Serial.print("responseLength: "); Serial.println(responseLength);
  71.                                 nfc.PrintHexChar(response, responseLength);
  72.                                 uint8_t selectApdu[] = {0x00, 0xB2, 0x04, 0x14, 0x00};
  73.                                 memset(response, 0, sizeof(response));
  74.                                 uint8_t responseLength = sizeof(response);
  75.                                 success = nfc.inDataExchange(selectApdu, sizeof(selectApdu), response, &responseLength);
  76.                                 if(success) {
  77.                                   Serial.print("responseLength: "); Serial.println(responseLength);
  78.                                   nfc.PrintHexChar(response, responseLength);
  79.                                   uint8_t selectApdu[] = {0x00, 0xB2, 0x05, 0x14, 0x00};
  80.                                   memset(response, 0, sizeof(response));
  81.                                   uint8_t responseLength = sizeof(response);
  82.                                   success = nfc.inDataExchange(selectApdu, sizeof(selectApdu), response, &responseLength);
  83.                                   if(success) {
  84.                                     Serial.print("responseLength: "); Serial.println(responseLength);
  85.                                     nfc.PrintHexChar(response, responseLength);
  86.                                     uint8_t selectApdu[] = {0x00, 0xB2, 0x06, 0x14, 0x00};
  87.                                     memset(response, 0, sizeof(response));
  88.                                     uint8_t responseLength = sizeof(response);
  89.                                     success = nfc.inDataExchange(selectApdu, sizeof(selectApdu), response, &responseLength);
  90.                                     if(success) {
  91.                                       Serial.print("responseLength: "); Serial.println(responseLength);
  92.                                       nfc.PrintHexChar(response, responseLength);
  93.                                       uint8_t selectApdu[] = {0x80, 0xAE, 0x90, 0x00, 0x42, 0x00, 0x00, 0x00, 0x01, 0x79, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x43, 0x00, 0x00, 0x00, 0x80, 0x00, 0x06, 0x43, 0x18, 0x01, 0x31, 0x00, 0x5E, 0x06, 0x39, 0xAE, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  94.                                       memset(response, 0, sizeof(response));
  95.                                       uint8_t responseLength = sizeof(response);
  96.                                       success = nfc.inDataExchange(selectApdu, sizeof(selectApdu), response, &responseLength);
  97.                                       if(success) {
  98.                                         Serial.print("responseLength: "); Serial.println(responseLength);
  99.                                         nfc.PrintHexChar(response, responseLength);
  100.       }
  101.       }
  102.       }
  103.       }
  104.       }
  105.       }
  106.                            
  107.       }
  108.                          
  109.       }
  110.       }
  111.       }
  112.       }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement