]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - armsrc/cmd.c
usb communication (device side) housekeeping
[proxmark3-svn] / armsrc / cmd.c
index ff5c4f8169ad69b60338af25cbf1b4488d1041a5..712025223de04171224796488ff3aac46aca7cc3 100644 (file)
  */\r
 \r
 #include "cmd.h"\r
-#include "string.h"\r
-#include "util.h"\r
-#include "proxmark3.h"\r
 \r
-//static UsbCommand txcmd;\r
+#include <stddef.h>\r
+#include <stdint.h>\r
+#include <stdbool.h>\r
+#include "common.h"\r
+#include "usb_cmd.h"\r
+#include "usb_cdc.h"\r
+\r
 \r
 bool cmd_receive(UsbCommand* cmd) {\r
\r
-  // Check if there is a usb packet available\r
-  if (!usb_poll()) return false;\r
-  \r
-  // Try to retrieve the available command frame\r
-  size_t rxlen = usb_read((byte_t*)cmd,sizeof(UsbCommand));\r
 \r
-  // Check if the transfer was complete\r
-  if (rxlen != sizeof(UsbCommand)) return false;\r
-  \r
-  // Received command successfully\r
-  return true;\r
+       // Check if there is a usb packet available\r
+       if (!usb_poll())\r
+               return false;\r
+\r
+       // Try to retrieve the available command frame\r
+       size_t rxlen = usb_read((uint8_t*)cmd, sizeof(UsbCommand));\r
+\r
+       // Check if the transfer was complete\r
+       if (rxlen != sizeof(UsbCommand))\r
+               return false;\r
+\r
+       // Received command successfully\r
+       return true;\r
 }\r
 \r
+\r
 bool cmd_send(uint32_t cmd, uint32_t arg0, uint32_t arg1, uint32_t arg2, void* data, size_t len) {\r
-  UsbCommand txcmd;\r
+       UsbCommand txcmd;\r
 \r
-  // Compose the outgoing command frame\r
-  txcmd.cmd = cmd;\r
-  txcmd.arg[0] = arg0;\r
-  txcmd.arg[1] = arg1; \r
-  txcmd.arg[2] = arg2;\r
+       for (size_t i = 0; i < sizeof(UsbCommand); i++) {\r
+               ((uint8_t*)&txcmd)[i] = 0x00;\r
+       }\r
 \r
-  // Add the (optional) content to the frame, with a maximum size of USB_CMD_DATA_SIZE\r
-  if (data && len) {\r
-    memcpy(txcmd.d.asBytes,(byte_t*)data,MIN(len,USB_CMD_DATA_SIZE));\r
-         }\r
-  \r
-  // Send frame and make sure all bytes are transmitted\r
-  if (usb_write((byte_t*)&txcmd,sizeof(UsbCommand)) != 0) return false;\r
-  \r
-  return true;\r
-}\r
+       // Compose the outgoing command frame\r
+       txcmd.cmd = cmd;\r
+       txcmd.arg[0] = arg0;\r
+       txcmd.arg[1] = arg1;\r
+       txcmd.arg[2] = arg2;\r
 \r
+       // Add the (optional) content to the frame, with a maximum size of USB_CMD_DATA_SIZE\r
+       if (data && len) {\r
+               len = MIN(len, USB_CMD_DATA_SIZE);\r
+               for (size_t i = 0; i < len; i++) {\r
+                       txcmd.d.asBytes[i] = ((uint8_t*)data)[i];\r
+               }\r
+       }\r
 \r
+       // Send frame and make sure all bytes are transmitted\r
+       if (usb_write((uint8_t*)&txcmd, sizeof(UsbCommand)) != 0) return false;\r
+\r
+       return true;\r
+}\r
Impressum, Datenschutz