mirror of
https://github.com/Proxmark/proxmark3.git
synced 2025-08-14 02:26:59 -07:00
Merge remote-tracking branch 'upstream/master'
Conflicts: client/cmdlf.c
This commit is contained in:
commit
ae6ead3dc8
54 changed files with 8139 additions and 2647 deletions
|
@ -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))
|
||||
|
|
|
@ -34,8 +34,6 @@
|
|||
#include "string.h"
|
||||
#include "proxmark3.h"
|
||||
|
||||
//static UsbCommand txcmd;
|
||||
|
||||
bool cmd_receive(UsbCommand* cmd) {
|
||||
|
||||
// Check if there is a usb packet available
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
35
common/crc32.c
Normal file
35
common/crc32.c
Normal file
|
@ -0,0 +1,35 @@
|
|||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include "crc32.h"
|
||||
|
||||
#define htole32(x) (x)
|
||||
#define CRC32_PRESET 0xFFFFFFFF
|
||||
|
||||
|
||||
static void crc32_byte (uint32_t *crc, const uint8_t value);
|
||||
|
||||
static void crc32_byte (uint32_t *crc, const uint8_t value) {
|
||||
/* x32 + x26 + x23 + x22 + x16 + x12 + x11 + x10 + x8 + x7 + x5 + x4 + x2 + x + 1 */
|
||||
const uint32_t poly = 0xEDB88320;
|
||||
|
||||
*crc ^= value;
|
||||
for (int current_bit = 7; current_bit >= 0; current_bit--) {
|
||||
int bit_out = (*crc) & 0x00000001;
|
||||
*crc >>= 1;
|
||||
if (bit_out)
|
||||
*crc ^= poly;
|
||||
}
|
||||
}
|
||||
|
||||
void crc32 (const uint8_t *data, const size_t len, uint8_t *crc) {
|
||||
uint32_t desfire_crc = CRC32_PRESET;
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
crc32_byte (&desfire_crc, data[i]);
|
||||
}
|
||||
|
||||
*((uint32_t *)(crc)) = htole32 (desfire_crc);
|
||||
}
|
||||
|
||||
void crc32_append (uint8_t *data, const size_t len) {
|
||||
crc32 (data, len, data + len);
|
||||
}
|
15
common/crc32.h
Normal file
15
common/crc32.h
Normal file
|
@ -0,0 +1,15 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
||||
// at your option, any later version. See the LICENSE.txt file for the text of
|
||||
// the license.
|
||||
//-----------------------------------------------------------------------------
|
||||
// CRC32
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef __CRC32_H
|
||||
#define __CRC32_H
|
||||
|
||||
void crc32 (const uint8_t *data, const size_t len, uint8_t *crc);
|
||||
void crc32_append (uint8_t *data, const size_t len);
|
||||
|
||||
#endif
|
|
@ -223,7 +223,6 @@ byte_t btReceiveBank = AT91C_UDP_RX_DATA_BK0;
|
|||
void usb_disable() {
|
||||
// Disconnect the USB device
|
||||
AT91C_BASE_PIOA->PIO_ODR = GPIO_USB_PU;
|
||||
// SpinDelay(100);
|
||||
|
||||
// Clear all lingering interrupts
|
||||
if(pUdp->UDP_ISR & AT91C_UDP_ENDBUSRES) {
|
||||
|
@ -257,7 +256,6 @@ void usb_enable() {
|
|||
|
||||
// Wait for a short while
|
||||
for (volatile size_t i=0; i<0x100000; i++);
|
||||
// SpinDelay(100);
|
||||
|
||||
// Reconnect USB reconnect
|
||||
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 time_out = 0;
|
||||
|
||||
while (len)
|
||||
{
|
||||
while (len) {
|
||||
if (!usb_check()) break;
|
||||
|
||||
if ( pUdp->UDP_CSR[AT91C_EP_OUT] & bank ) {
|
||||
|
@ -314,8 +311,7 @@ uint32_t usb_read(byte_t* data, size_t len) {
|
|||
while(packetSize--)
|
||||
data[nbBytesRcv++] = pUdp->UDP_FDR[AT91C_EP_OUT];
|
||||
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;
|
||||
} else {
|
||||
bank = AT91C_UDP_RX_DATA_BK0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue