+ // transfer to device
+ size_t len = 0;
+ UsbCommand c = {CMD_WRITER_LEGIC_RF, {0, 0, 0x55}};
+ UsbCommand resp;
+ for(size_t i = 7; i < numofbytes; i += USB_CMD_DATA_SIZE) {
+
+ len = MIN((numofbytes - i), USB_CMD_DATA_SIZE);
+ c.arg[0] = i; // offset
+ c.arg[1] = len; // number of bytes
+ memcpy(c.d.asBytes, data+i, len);
+ PrintAndLog("offset %d | chunk %d | numofbytes %d", i, len, numofbytes);
+ clearCommandBuffer();
+ SendCommand(&c);
+
+ if (!WaitForResponseTimeout(CMD_ACK, &resp, 2000)) {
+ PrintAndLog("command execution time out");
+ free(data);
+ return 1;
+ }
+ uint8_t isOK = resp.arg[0] & 0xFF;
+ if ( !isOK ) {
+ PrintAndLog("failed writing tag [msg = %u]", resp.arg[1] & 0xFF);
+ free(data);
+ return 1;
+ }
+ PrintAndLog("Wrote chunk %d - %d", i, len);
+ }