]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - armsrc/appmain.c
usb communication (device side) refactoring
[proxmark3-svn] / armsrc / appmain.c
index 6a3b6e8199e8339a4d3dec81c1a544e8d74b25de..38965c32ccf78305ac2886ea679cbda434a11e5b 100644 (file)
@@ -13,7 +13,6 @@
 #include <stdarg.h>
 
 #include "usb_cdc.h"
-#include "cmd.h"
 #include "proxmark3.h"
 #include "apps.h"
 #include "fpga.h"
@@ -936,9 +935,7 @@ void ListenReaderField(int limit) {
 }
 
 
-void UsbPacketReceived(uint8_t *packet, int len) {
-
-       UsbCommand *c = (UsbCommand *)packet;
+void UsbPacketReceived(UsbCommand *c) {
 
 //  Dbprintf("received %d bytes, with command: 0x%04x and args: %d %d %d",len,c->cmd,c->arg[0],c->arg[1],c->arg[2]);
 
@@ -1479,29 +1476,25 @@ void  __attribute__((noreturn)) AppMain(void) {
        LCDInit();
 #endif
 
-       uint8_t rx[sizeof(UsbCommand)];
-       size_t rx_len;
-
+       UsbCommand rx;
+  
        for(;;) {
-               if (usb_poll()) {
-                       rx_len = usb_read(rx, sizeof(UsbCommand));
-                       if (rx_len) {
-                               UsbPacketReceived(rx, rx_len);
-                       }
+               if (cmd_receive(&rx)) {
+                       UsbPacketReceived(&rx);
                }
-               WDT_HIT();
 
-#ifdef WITH_LF_StandAlone
-#ifndef WITH_ISO14443a_StandAlone
-               if (BUTTON_HELD(1000) > 0)
-                       SamyRun();
-#endif
-#endif
-#ifdef WITH_ISO14443a
-#ifdef WITH_ISO14443a_StandAlone
-               if (BUTTON_HELD(1000) > 0)
-                       StandAloneMode14a();
+               WDT_HIT();
+               if (usb_poll() && (rx_len = usb_read(rx, sizeof(rx)))) {
+                       UsbPacketReceived(rx, rx_len);
+               } else {
+#if defined(WITH_LF_StandAlone) && !defined(WITH_ISO14443a_StandAlone)
+                       if (BUTTON_HELD(1000) > 0)
+                               SamyRun();
 #endif
+#if defined(WITH_ISO14443a) && defined(WITH_ISO14443a_StandAlone)
+                       if (BUTTON_HELD(1000) > 0)
+                               StandAloneMode14a();
 #endif
+               }
        }
 }
Impressum, Datenschutz