]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - armsrc/cmd.c
usb communication (device side) housekeeping
[proxmark3-svn] / armsrc / cmd.c
index c414bc39c8cbb2cac075a05e1d20791d0d545e3c..712025223de04171224796488ff3aac46aca7cc3 100644 (file)
@@ -1,7 +1,7 @@
 /*\r
  * Proxmark send and receive commands\r
  *\r
- * Copyright (c) 2010, Roel Verdult\r
+ * Copyright (c) 2012, Roel Verdult\r
  * All rights reserved.\r
  *\r
  * Redistribution and use in source and binary forms, with or without\r
  */\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
-}\r
+       // Check if there is a usb packet available\r
+       if (!usb_poll())\r
+               return false;\r
 \r
-bool cmd_send(uint32_t cmd, uint32_t arg0, uint32_t arg1, uint32_t arg2, byte_t* data, size_t len) {\r
-  UsbCommand txcmd;\r
+       // Try to retrieve the available command frame\r
+       size_t rxlen = usb_read((uint8_t*)cmd, sizeof(UsbCommand));\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
+       // Check if the transfer was complete\r
+       if (rxlen != sizeof(UsbCommand))\r
+               return false;\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,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
+       // 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
+\r
+       for (size_t i = 0; i < sizeof(UsbCommand); i++) {\r
+               ((uint8_t*)&txcmd)[i] = 0x00;\r
+       }\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