-int CmdLFPCF7931Write(const char *Cmd)
-{
- UsbCommand c = {CMD_PCF7931_WRITE};
-
- int res = 0;
- res = sscanf(Cmd, "%x %x %x", &c.arg[0], &c.arg[1], &c.arg[2]);
-
- if(res < 1) {
- PrintAndLog("Please specify the block address in hex");
- return 0;
- }
- if (res == 1){
- PrintAndLog("Please specify the byte address in hex");
- return 0;
- }
- if(res == 2) {
- PrintAndLog("Please specify the data in hex (1 byte)");
- return 0;
- }
- if(res == 3) {
- uint8_t n=0;
- for(n=0;n<7;n++) c.d.asDwords[n] = configPcf.password[n];
- c.d.asDwords[7] = (configPcf.offset[0]+128);
- c.d.asDwords[8] = (configPcf.offset[1]+128);
- c.d.asDwords[9] = configPcf.init_delay;
- SendCommand(&c);
- return 0;
- }
-
- PrintAndLog("INCORRECT FORMAT");
- return 0;
+ UsbCommand resp;
+ UsbCommand c = {CMD_PCF7931_READ, {0, 0, 0}};
+ clearCommandBuffer();
+ SendCommand(&c);
+ if ( !WaitForResponseTimeout(CMD_ACK, &resp, 2500) ) {
+ PrintAndLog("command execution time out");
+ return 1;
+ }
+ return 0;
+}
+
+int CmdLFPCF7931Config(const char *Cmd){
+
+ uint8_t ctmp = param_getchar(Cmd, 0);
+ if ( ctmp == 0) return pcf7931_printConfig();
+ if ( ctmp == 'H' || ctmp == 'h' ) return usage_pcf7931_config();
+ if ( ctmp == 'R' || ctmp == 'r' ) return pcf7931_resetConfig();
+
+ if ( param_gethex(Cmd, 0, configPcf.Pwd, 14) ) return usage_pcf7931_config();
+
+ configPcf.InitDelay = (param_get32ex(Cmd,1,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;
+}
+
+int CmdLFPCF7931Write(const char *Cmd){
+
+ uint8_t ctmp = param_getchar(Cmd, 0);
+ if (strlen(Cmd) < 1 || ctmp == 'h' || ctmp == 'H') return usage_pcf7931_write();
+
+ 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();
+
+ 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();
+ SendCommand(&c);
+ //no ack?
+ return 0;