CHG: Minor code clean up.

ADD: crc16.c - new crc16_ccitt calc.
This commit is contained in:
iceman1001 2015-01-07 20:40:22 +01:00
commit 23b598ee23
6 changed files with 33 additions and 11 deletions

View file

@ -54,7 +54,8 @@ DELETE=del /q
MOVE=ren MOVE=ren
COPY=copy COPY=copy
PATHSEP=\\# PATHSEP=\\#
FLASH_TOOL=winsrc\\prox.exe #FLASH_TOOL=winsrc\\prox.exe
FLASH_TOOL=winsrc\\flash.exe
DETECTED_OS=Windows DETECTED_OS=Windows
endif 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 CFLAGS = -c $(INCLUDE) -Wall -Werror -pedantic -std=c99 $(APP_CFLAGS) -Os
LDFLAGS = -nostartfiles -nodefaultlibs -Wl,-gc-sections -n LDFLAGS = -nostartfiles -nodefaultlibs -Wl,-gc-sections -n
LIBS = -lgcc LIBS = -lgcc
THUMBOBJ = $(patsubst %.c,$(OBJDIR)/%.o,$(THUMBSRC)) THUMBOBJ = $(patsubst %.c,$(OBJDIR)/%.o,$(THUMBSRC))

View file

@ -34,8 +34,6 @@
#include "string.h" #include "string.h"
#include "proxmark3.h" #include "proxmark3.h"
//static UsbCommand txcmd;
bool cmd_receive(UsbCommand* cmd) { bool cmd_receive(UsbCommand* cmd) {
// Check if there is a usb packet available // Check if there is a usb packet available

View file

@ -8,6 +8,7 @@
#include "crc16.h" #include "crc16.h"
unsigned short update_crc16( unsigned short crc, unsigned char c ) unsigned short update_crc16( unsigned short crc, unsigned char c )
{ {
unsigned short i, v, tcrc = 0; 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; 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);
}

View file

@ -5,10 +5,11 @@
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// CRC16 // CRC16
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#include <stdint.h>
#ifndef __CRC16_H #ifndef __CRC16_H
#define __CRC16_H #define __CRC16_H
unsigned short update_crc16(unsigned short crc, unsigned char c); 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 #endif

View file

@ -223,7 +223,6 @@ byte_t btReceiveBank = AT91C_UDP_RX_DATA_BK0;
void usb_disable() { void usb_disable() {
// Disconnect the USB device // Disconnect the USB device
AT91C_BASE_PIOA->PIO_ODR = GPIO_USB_PU; AT91C_BASE_PIOA->PIO_ODR = GPIO_USB_PU;
// SpinDelay(100);
// Clear all lingering interrupts // Clear all lingering interrupts
if(pUdp->UDP_ISR & AT91C_UDP_ENDBUSRES) { if(pUdp->UDP_ISR & AT91C_UDP_ENDBUSRES) {
@ -257,7 +256,6 @@ void usb_enable() {
// Wait for a short while // Wait for a short while
for (volatile size_t i=0; i<0x100000; i++); for (volatile size_t i=0; i<0x100000; i++);
// SpinDelay(100);
// Reconnect USB reconnect // Reconnect USB reconnect
AT91C_BASE_PIOA->PIO_SODR = GPIO_USB_PU; AT91C_BASE_PIOA->PIO_SODR = GPIO_USB_PU;
@ -304,8 +302,7 @@ uint32_t usb_read(byte_t* data, size_t len) {
uint32_t packetSize, nbBytesRcv = 0; uint32_t packetSize, nbBytesRcv = 0;
uint32_t time_out = 0; uint32_t time_out = 0;
while (len) while (len) {
{
if (!usb_check()) break; if (!usb_check()) break;
if ( pUdp->UDP_CSR[AT91C_EP_OUT] & bank ) { if ( pUdp->UDP_CSR[AT91C_EP_OUT] & bank ) {
@ -314,8 +311,7 @@ uint32_t usb_read(byte_t* data, size_t len) {
while(packetSize--) while(packetSize--)
data[nbBytesRcv++] = pUdp->UDP_FDR[AT91C_EP_OUT]; data[nbBytesRcv++] = pUdp->UDP_FDR[AT91C_EP_OUT];
pUdp->UDP_CSR[AT91C_EP_OUT] &= ~(bank); pUdp->UDP_CSR[AT91C_EP_OUT] &= ~(bank);
if (bank == AT91C_UDP_RX_DATA_BK0) if (bank == AT91C_UDP_RX_DATA_BK0) {
{
bank = AT91C_UDP_RX_DATA_BK1; bank = AT91C_UDP_RX_DATA_BK1;
} else { } else {
bank = AT91C_UDP_RX_DATA_BK0; bank = AT91C_UDP_RX_DATA_BK0;

View file

@ -150,8 +150,10 @@ typedef struct {
#define CMD_MIFARE_READBL 0x0620 #define CMD_MIFARE_READBL 0x0620
#define CMD_MIFAREU_READBL 0x0720 #define CMD_MIFAREU_READBL 0x0720
#define CMD_MIFARE_READSC 0x0621 #define CMD_MIFARE_READSC 0x0621
#define CMD_MIFAREU_READCARD 0x0721 #define CMD_MIFAREU_READCARD 0x0721
#define CMD_MIFARE_WRITEBL 0x0622 #define CMD_MIFARE_WRITEBL 0x0622
#define CMD_MIFAREU_WRITEBL 0x0722 #define CMD_MIFAREU_WRITEBL 0x0722
#define CMD_MIFAREU_WRITEBL_COMPAT 0x0723 #define CMD_MIFAREU_WRITEBL_COMPAT 0x0723