+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;
+}
+
+int CmdLFPCF7931BruteForce(const char *Cmd){
+
+ uint8_t ctmp = param_getchar(Cmd, 0);
+ if (strlen(Cmd) < 1 || ctmp == 'h' || ctmp == 'H') return usage_pcf7931_bruteforce();
+
+ uint64_t start_password = 0;
+ uint8_t tries = 3;
+
+ if (param_gethex(Cmd, 0, (uint8_t*)(&start_password), 14)) return usage_pcf7931_bruteforce();
+ if (param_getdec(Cmd, 1, &tries)) return usage_pcf7931_bruteforce();
+
+ PrintAndLog("Bruteforcing from password: %02x %02x %02x %02x %02x %02x %02x",
+ start_password & 0xFF,
+ (start_password >> 8) & 0xFF,
+ (start_password >> 16) & 0xFF,
+ (start_password >> 24) & 0xFF,
+ (start_password >> 32) & 0xFF,
+ (start_password >> 48) & 0xFF,
+ (start_password >> 56) & 0xFF);
+
+ PrintAndLog("Trying each password %d times", tries);
+
+ UsbCommand c = {CMD_PCF7931_BRUTEFORCE, {start_password, tries} };
+
+ 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;
+}