struct pcf7931_config configPcf = {
{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
PCF7931_DEFAULT_INITDELAY,
- {
- PCF7931_DEFAULT_OFFSET_WIDTH,
- PCF7931_DEFAULT_OFFSET_POSITION
- }
+ PCF7931_DEFAULT_OFFSET_WIDTH,
+ PCF7931_DEFAULT_OFFSET_POSITION
};
// Resets the configuration settings to default values.
int pcf7931_resetConfig(){
memset(configPcf.Pwd, 0xFF, sizeof(configPcf.Pwd) );
configPcf.InitDelay = PCF7931_DEFAULT_INITDELAY;
- configPcf.Offset[0] = PCF7931_DEFAULT_OFFSET_WIDTH;
- configPcf.Offset[1] = PCF7931_DEFAULT_OFFSET_POSITION;
+ configPcf.OffsetWidth = PCF7931_DEFAULT_OFFSET_WIDTH;
+ configPcf.OffsetPosition = PCF7931_DEFAULT_OFFSET_POSITION;
return 0;
}
int pcf7931_printConfig(){
PrintAndLog("Password (LSB first on bytes) : %s", sprint_hex( configPcf.Pwd, sizeof(configPcf.Pwd)));
PrintAndLog("Tag initialization delay : %d us", configPcf.InitDelay);
- PrintAndLog("Offset low pulses width : %d us", configPcf.Offset[0]);
- PrintAndLog("Offset low pulses position : %d us", configPcf.Offset[1]);
+ PrintAndLog("Offset low pulses width : %d us", configPcf.OffsetWidth);
+ PrintAndLog("Offset low pulses position : %d us", configPcf.OffsetPosition);
return 0;
}
PrintAndLog("This command tries to write a PCF7931 tag.");
PrintAndLog("Options:");
PrintAndLog(" h This help");
- PrintAndLog(" blockaddress Block to save");
- PrintAndLog(" byteaddress Index of byte inside block to overwrite");
- PrintAndLog(" data one byte of data");
+ PrintAndLog(" blockaddress Block to save [0-7]");
+ PrintAndLog(" byteaddress Index of byte inside block to write [0-15]");
+ PrintAndLog(" data one byte of data (hex)");
PrintAndLog("Examples:");
- PrintAndLog(" lf pcf7931 write 10 1 FF");
+ PrintAndLog(" lf pcf7931 write 2 1 FF");
return 0;
}
if ( param_gethex(Cmd, 0, configPcf.Pwd, 14) ) return usage_pcf7931_config();
configPcf.InitDelay = (param_get32ex(Cmd,1,0,10) & 0xFFFF);
- configPcf.Offset[0] = (int)(param_get32ex(Cmd,2,0,10) & 0xFFFF);
- configPcf.Offset[1] = (int)(param_get32ex(Cmd,3,0,10) & 0xFFFF);
+ configPcf.OffsetWidth = (int)(param_get32ex(Cmd,2,0,10) & 0xFFFF);
+ configPcf.OffsetPosition = (int)(param_get32ex(Cmd,3,0,10) & 0xFFFF);
pcf7931_printConfig();
return 0;
uint8_t ctmp = param_getchar(Cmd, 0);
if (strlen(Cmd) < 1 || ctmp == 'h' || ctmp == 'H') return usage_pcf7931_write();
- uint64_t blockaddress = param_get64ex(Cmd, 0, 0, 16);
- uint64_t byteaddress = param_get64ex(Cmd, 1, 0, 16);
- uint8_t data = param_get8ex(Cmd,2,0,16);
-
- PrintAndLog("Please specify the block address in hex");
- PrintAndLog("Please specify the byte address in hex");
- PrintAndLog("Please specify the data in hex (1 byte)");
-
- PrintAndLog("", blockaddress, byteaddress, data);
- return 3;
+ uint8_t block = 0, bytepos = 0, data = 0;
+
+ if ( param_getdec(Cmd, 0, &block) ) return usage_pcf7931_write();
+ if ( param_getdec(Cmd, 1, &bytepos) ) return usage_pcf7931_write();
+
+ if ( (block > 7) || (bytepos > 15) ) return usage_pcf7931_write();
- UsbCommand c = {CMD_PCF7931_WRITE, { blockaddress, byteaddress, data} };
- memcpy(c.d.asDwords, configPcf.Pwd, 7);
- c.d.asDwords[7] = (configPcf.Offset[0]+128);
- c.d.asDwords[8] = (configPcf.Offset[1]+128);
+ data = param_get8ex(Cmd, 2, 0, 16);
+
+ PrintAndLog("Writing block: %d", block);
+ PrintAndLog(" pos: %d", bytepos);
+ PrintAndLog(" data: 0x%02X", data);
+
+ UsbCommand c = {CMD_PCF7931_WRITE, { block, bytepos, data} };
+ memcpy(c.d.asDwords, configPcf.Pwd, sizeof(configPcf.Pwd) );
+ c.d.asDwords[7] = (configPcf.OffsetWidth + 128);
+ c.d.asDwords[8] = (configPcf.OffsetPosition + 128);
c.d.asDwords[9] = configPcf.InitDelay;
clearCommandBuffer();
static command_t CommandTable[] =
{
{"help", CmdHelp, 1, "This help"},
- {"read", CmdLFPCF7931Read, 1, "Read content of a PCF7931 transponder"},
- {"write", CmdLFPCF7931Write, 1, "Write data on a PCF7931 transponder."},
+ {"read", CmdLFPCF7931Read, 0, "Read content of a PCF7931 transponder"},
+ {"write", CmdLFPCF7931Write, 0, "Write data on a PCF7931 transponder."},
{"config", CmdLFPCF7931Config, 1, "Configure the password, the tags initialization delay and time offsets (optional)"},
{NULL, NULL, 0, NULL}
};
-int CmdLFPCF7931(const char *Cmd)
-{
+int CmdLFPCF7931(const char *Cmd) {
+ clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
-int CmdHelp(const char *Cmd)
-{
+int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}