I am new to Arduino programming. We have an RFID reader, comical purchased with not sure high end encryption. The RFID example DumpInfo does read the cards "aptiQ 9520" , exempt return wrong values. I am sure my knowledge of the whole card reader topic is apparent. I have read about authentication key and other decrypting card key, i honestly have no clue. I maybe going down a rabbit hole, I have added to the following example "DumpInfo" to see if any thing would make sense from other articles. I believe the term for what i am doing is spoofing card to return correct key, to return the correct value.
/*
* Typical pin layout used:
* -----------------------------------------------------------------------------------------
* MFRC522 **Arduino** Arduino Arduino Arduino Arduino
* Reader/PCD **Uno/101** Mega Nano v3 Leonardo/Micro Pro Micro
* Signal Pin Pin Pin Pin Pin Pin
* -----------------------------------------------------------------------------------------
* RST/Reset RST 9 5 D9 RESET/ICSP-5 RST
* SPI SS SDA(SS) 10 53 D10 10 10
* SPI MOSI MOSI 11 / ICSP-4 51 D11 ICSP-4 16
* SPI MISO MISO 12 / ICSP-1 50 D12 ICSP-1 14
* SPI SCK SCK 13 / ICSP-3 52 D13 ICSP-3 15
*
* More pin layouts for other boards can be found here: https://github.com/miguelbalboa/rfid#pin-layout
*/
#include <SPI.h>
#include <MFRC522.h>
#include <SoftwareSerial.h>
#include <SimpleTimer.h>
#define RST_PIN 9 // Configurable, see typical pin layout above
#define SS_PIN 10 // Configurable, see typical pin layout above
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
// the timer object
SimpleTimer HBtimer;
char tag[10];
int tagindex=0;
SoftwareSerial mySerial(2, 3); //pin3 Rx, pin2 Tx
byte readCard[]={0xFF,0x07,0x80,0xBC,0xFF,0xFF,0xFF,0xFF,0xFF};
int cardPresent=0;
int cardBytesRead;
int readComplete;
int CMD[64];
int comlen =0;
int out_flag =0;
boolean isReplyRead=0;
String strAuthResp;
String strTagID;
void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522
delay(4); // Optional delay. Some board do need more time after init to be ready, see Readme
mfrc522.PCD_DumpVersionToSerial(); // Show details of PCD - MFRC522 Card Reader details
Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
mySerial.begin(9600);
cardBytesRead=0;
readComplete=0;
delay(50);
mySerial.listen();
delay(10);
}
oid loop() {
// Reset the loop if no new card present on the sensor/reader. This saves the entire process when idle.
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
HBtimer.run();
readComplete=0;
cardPresent=digitalRead(5);
cardPresent=!cardPresent;
if((cardPresent)&&(!readComplete)){
readCardF();
delay(50);
// Dump debug info about the card; PICC_HaltA() is automatically called
mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
}
}
void readCardF(){
mySerial.write(readCard, sizeof(readCard));
while(mySerial.available()&&readComplete<1){
byte C = mySerial.read();
if (C<16) Serial.print("0");
Serial.print(C,HEX);
cardBytesRead++;
if ((cardBytesRead>16)&&(cardBytesRead<9)){
byte hinibble = (C >> 16) & 0x0f;
byte lonibble = C & 0x0f;
tag[tagindex++] = bintohexascii(hinibble);
tag[tagindex++] = bintohexascii(lonibble);
} //End If
if (cardBytesRead==9) {
tagindex=0;
cardBytesRead=0;
readComplete=1;
Serial.println("");
Serial.println("RFID tag value= ");
Serial.println(tag);
Serial.println("");
strTagID=tag;
isReplyRead=0;
if(strTagID.length()==8){
//Success
//Call our HTTP GET function
//For testing purposes we call the resetFunc here so we can re-scan to keep testing
delay(100);
resetFunc();
}
else
{
Serial.println("Invalid Length of RFID Card");
delay(100);
resetFunc();
}
return;
}//End If carybytesread==9
}//End While
} //End Function
char bintohexascii(byte x)
{
char hex[16] = {
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
};
return hex[x & 0x0f];
}
void resetFunc() // Restarts program from beginning but does not reset the peripherals and registers
{
asm volatile (" jmp 0");
}