+int CmdAWIDBrute(const char *Cmd){
+
+ bool errors = false;
+ uint32_t fc = 0, cn = 0, delay = 1000;
+ uint8_t fmtlen = 0;
+ uint8_t bits[96];
+ uint8_t *bs = bits;
+ size_t size = sizeof(bits);
+ memset(bs, 0x00, size);
+ uint8_t cmdp = 0;
+
+ while(param_getchar(Cmd, cmdp) != 0x00 && !errors) {
+ switch(param_getchar(Cmd, cmdp)) {
+ case 'h':
+ case 'H':
+ return usage_lf_awid_brute();
+ case 'f':
+ case 'F':
+ fc = param_get32ex(Cmd ,cmdp+1, 0, 10);
+ if ( !fc )
+ errors = true;
+ cmdp += 2;
+ break;
+ case 'd':
+ case 'D':
+ // delay between attemps, defaults to 1000ms.
+ delay = param_get32ex(Cmd, cmdp+1, 1000, 10);
+ cmdp += 2;
+ break;
+ case 'c':
+ case 'C':
+ cn = param_get32ex(Cmd, cmdp+1, 0, 10);
+ // truncate cardnumber.
+ cn &= 0xFFFF;
+ cmdp += 2;
+ break;
+ case 'a':
+ case 'A':
+ fmtlen = param_get8(Cmd, cmdp+1);
+ cmdp += 2;
+ break;
+ default:
+ PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));
+ errors = true;
+ break;
+ }
+ }
+ if ( fc == 0 )errors = true;
+ if ( errors ) return usage_lf_awid_brute();
+
+ // limit fc according to selected format
+ switch(fmtlen) {
+ case 50:
+ if ((fc & 0xFFFF) != fc) {
+ fc &= 0xFFFF;
+ PrintAndLog("Facility-code truncated to 16-bits (AWID50): %u", fc);
+ }
+ break;
+ default:
+ if ((fc & 0xFF) != fc) {
+ fc &= 0xFF;
+ PrintAndLog("Facility-code truncated to 8-bits (AWID26): %u", fc);
+ }
+ break;
+ }
+
+ PrintAndLog("Bruteforceing AWID %d Reader", fmtlen);
+ PrintAndLog("Press pm3-button to abort simulation or press key");
+
+ uint16_t up = cn;
+ uint16_t down = cn;
+
+ for (;;){
+
+ if ( offline ) {
+ printf("Device offline\n");
+ return 2;
+ }
+ if (ukbhit()) {
+ PrintAndLog("aborted via keyboard!");
+ return sendPing();
+ }
+
+ // Do one up
+ if ( up < 0xFFFF )
+ if ( !sendTry(fmtlen, fc, up++, delay, bs, size)) return 1;
+
+ // Do one down (if cardnumber is given)
+ if ( cn > 1 )
+ if ( down > 1 )
+ if ( !sendTry(fmtlen, fc, --down, delay, bs, size)) return 1;
+ }
+ return 0;
+}
+