+ if (response->cmd & CMD_VARIABLE_SIZE_FLAG) { // new style response with variable size
+#ifdef COMMS_DEBUG
+ PrintAndLog("received new style response %04" PRIx16 ", datalen = %zd, arg[0] = %08" PRIx32 ", arg[1] = %08" PRIx32 ", arg[2] = %08" PRIx32,
+ response->cmd, response->datalen, response->arg[0], response->arg[1], response->arg[2]);
+#endif
+ bytes_to_read = response->datalen;
+ if (receive_from_serial(sp, prx, bytes_to_read, &rxlen)) {
+ UsbCommand resp;
+ resp.cmd = response->cmd & ~CMD_VARIABLE_SIZE_FLAG; // remove the flag
+ resp.arg[0] = response->arg[0];
+ resp.arg[1] = response->arg[1];
+ resp.arg[2] = response->arg[2];
+ memcpy(&resp.d.asBytes, &response->d.asBytes, response->datalen);
+ UsbCommandReceived(&resp);
+ if (resp.cmd == CMD_ACK) {
+ ACK_received = true;
+ }
+ }
+ } else { // old style response uses same data structure as commands. Fixed size.
+#ifdef COMMS_DEBUG
+ PrintAndLog("received old style response %016" PRIx64 ", arg[0] = %016" PRIx64, command->cmd, command->arg[0]);
+#endif
+ bytes_to_read = sizeof(UsbCommand) - bytes_to_read;
+ if (receive_from_serial(sp, prx, bytes_to_read, &rxlen)) {
+ UsbCommandReceived(command);
+ if (command->cmd == CMD_ACK) {
+ ACK_received = true;
+ }
+ }