]> git.zerfleddert.de Git - proxmark3-svn/commitdiff
CHG: Minor code clean up.
authoriceman1001 <iceman@iuse.se>
Wed, 7 Jan 2015 19:40:22 +0000 (20:40 +0100)
committericeman1001 <iceman@iuse.se>
Wed, 7 Jan 2015 19:40:22 +0000 (20:40 +0100)
ADD: crc16.c - new crc16_ccitt calc.

common/Makefile.common
common/cmd.c
common/crc16.c
common/crc16.h
common/usb_cdc.c
include/usb_cmd.h

index 2befd456d5c4df28718982babc08debba1586395..2b2bb2fbd7c47fa514d5d2c05dadd890b9a69400 100644 (file)
@@ -54,7 +54,8 @@ DELETE=del /q
 MOVE=ren
 COPY=copy
 PATHSEP=\\#
-FLASH_TOOL=winsrc\\prox.exe
+#FLASH_TOOL=winsrc\\prox.exe
+FLASH_TOOL=winsrc\\flash.exe
 DETECTED_OS=Windows
 
 endif
@@ -67,6 +68,7 @@ INCLUDES = ../include/proxmark3.h ../include/at91sam7s512.h ../include/config_gp
 
 CFLAGS =  -c $(INCLUDE) -Wall -Werror -pedantic -std=c99 $(APP_CFLAGS) -Os
 LDFLAGS = -nostartfiles -nodefaultlibs -Wl,-gc-sections -n
+
 LIBS = -lgcc
 
 THUMBOBJ = $(patsubst %.c,$(OBJDIR)/%.o,$(THUMBSRC))
index 49d9d9424792638fcf1bbb514dd85c3429bdadae..0c3ecc1fee83f9e60a2c82d4d9711e2aab78c46c 100644 (file)
@@ -34,8 +34,6 @@
 #include "string.h"\r
 #include "proxmark3.h"\r
 \r
-//static UsbCommand txcmd;\r
-\r
 bool cmd_receive(UsbCommand* cmd) {\r
  \r
   // Check if there is a usb packet available\r
index d181bb2a7f8a649d6fa2795be1251606e80589bd..973cd103c009b16697b7523b1cbf60b107500f7a 100644 (file)
@@ -8,6 +8,7 @@
 
 #include "crc16.h"
 
+
 unsigned short update_crc16( unsigned short crc, unsigned char c )
 {
   unsigned short i, v, tcrc = 0;
@@ -20,3 +21,25 @@ unsigned short update_crc16( unsigned short crc, unsigned char c )
 
   return ((crc >> 8) ^ tcrc)&0xffff;
 }
+
+uint16_t crc16(uint8_t const *message, int length, uint16_t remainder, uint16_t polynomial) {
+    
+       if (length == 0)
+        return (~remainder);
+                       
+    for (int byte = 0; byte < length; ++byte) {
+        remainder ^= (message[byte] << 8);
+        for (uint8_t bit = 8; bit > 0; --bit) {
+            if (remainder & 0x8000) {
+                remainder = (remainder << 1) ^ polynomial;
+            } else {
+                remainder = (remainder << 1);
+            }
+        }
+    }
+    return remainder;
+}
+
+uint16_t crc16_ccitt(uint8_t const *message, int length) {
+    return crc16(message, length, 0xffff, 0x1021);
+}
index 055a60bcd257592884455e3c7949810a88182ada..d16d83b5afdb162c088e35e4a01aee33e2760e3d 100644 (file)
@@ -5,10 +5,11 @@
 //-----------------------------------------------------------------------------
 // CRC16
 //-----------------------------------------------------------------------------
+#include <stdint.h>
 
 #ifndef __CRC16_H
 #define __CRC16_H
-
 unsigned short update_crc16(unsigned short crc, unsigned char c);
-
+uint16_t crc16(uint8_t const *message, int length, uint16_t remainder, uint16_t polynomial);
+uint16_t crc16_ccitt(uint8_t const *message, int length);
 #endif
index e2787fb65a4feb4d1e8b18595f4abce238ad83ac..54f6a8e81bbacd2c8c6825f7a02c478c5935f096 100644 (file)
@@ -223,7 +223,6 @@ byte_t btReceiveBank   = AT91C_UDP_RX_DATA_BK0;
 void usb_disable() {\r
   // Disconnect the USB device\r
   AT91C_BASE_PIOA->PIO_ODR = GPIO_USB_PU;\r
-//  SpinDelay(100);\r
   \r
   // Clear all lingering interrupts\r
   if(pUdp->UDP_ISR & AT91C_UDP_ENDBUSRES) {\r
@@ -257,7 +256,6 @@ void usb_enable() {
   \r
   // Wait for a short while\r
   for (volatile size_t i=0; i<0x100000; i++);\r
-//  SpinDelay(100);\r
 \r
   // Reconnect USB reconnect\r
   AT91C_BASE_PIOA->PIO_SODR = GPIO_USB_PU;\r
@@ -304,8 +302,7 @@ uint32_t usb_read(byte_t* data, size_t len) {
        uint32_t packetSize, nbBytesRcv = 0;\r
   uint32_t time_out = 0;\r
   \r
-       while (len)\r
-  {\r
+       while (len)  {\r
                if (!usb_check()) break;\r
 \r
                if ( pUdp->UDP_CSR[AT91C_EP_OUT] & bank ) {\r
@@ -314,8 +311,7 @@ uint32_t usb_read(byte_t* data, size_t len) {
                        while(packetSize--)\r
                                data[nbBytesRcv++] = pUdp->UDP_FDR[AT91C_EP_OUT];\r
                        pUdp->UDP_CSR[AT91C_EP_OUT] &= ~(bank);\r
-                       if (bank == AT91C_UDP_RX_DATA_BK0)\r
-      {\r
+                       if (bank == AT91C_UDP_RX_DATA_BK0) {\r
                                bank = AT91C_UDP_RX_DATA_BK1;\r
       } else {\r
                                bank = AT91C_UDP_RX_DATA_BK0;\r
index 69c3c1b6a0920a388650265a892e281b9e348977..c2e0b95bda0d4ff30d856914414cf9a17edc52cb 100644 (file)
@@ -150,8 +150,10 @@ typedef struct {
 
 #define CMD_MIFARE_READBL                                                 0x0620
 #define CMD_MIFAREU_READBL                                               0x0720
+
 #define CMD_MIFARE_READSC                                                 0x0621
 #define CMD_MIFAREU_READCARD                                             0x0721
+
 #define CMD_MIFARE_WRITEBL                                                0x0622
 #define CMD_MIFAREU_WRITEBL                                                                      0x0722
 #define CMD_MIFAREU_WRITEBL_COMPAT                                                           0x0723
Impressum, Datenschutz