Skip to content

Commit

Permalink
add: FPC connector skeleton usart. Not working but if will be a start…
Browse files Browse the repository at this point in the history
…ing point for those who might want to help out with it.
  • Loading branch information
Chris committed Jul 30, 2018
1 parent 08d9d9d commit bacf8af
Show file tree
Hide file tree
Showing 8 changed files with 384 additions and 32 deletions.
24 changes: 17 additions & 7 deletions armsrc/appmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,21 @@ void UsbPacketReceived(uint8_t *packet, int len) {
}
#endif

#ifdef WITH_FPC
case CMD_FPC_SEND: {
// char header[] = {"*** Iceman Usart ***"};
// uint32_t res = usart_writebuffer((uint8_t *)header, sizeof(header), 10000);

//temp++;
uint8_t got = usart_read(10000);
if ( got > 0 ) {
Dbprintf("got %02x", got);
usart_write(got, 10000);
}
cmd_send(CMD_ACK,0,0,0,0,0);
break;
}
#endif
case CMD_BUFF_CLEAR:
BigBuf_Clear();
break;
Expand Down Expand Up @@ -1292,7 +1307,7 @@ void UsbPacketReceived(uint8_t *packet, int len) {
switch(c->arg[0]) {
case 0: SetAdcMuxFor(GPIO_MUXSEL_LOPKD); break;
case 2: SetAdcMuxFor(GPIO_MUXSEL_HIPKD); break;
#ifndef WITH_FPC
#ifndef WITH_FPC
case 1: SetAdcMuxFor(GPIO_MUXSEL_LORAW); break;
case 3: SetAdcMuxFor(GPIO_MUXSEL_HIRAW); break;
#endif
Expand All @@ -1307,12 +1322,6 @@ void UsbPacketReceived(uint8_t *packet, int len) {
break;
case CMD_PING:
cmd_send(CMD_ACK,0,0,0,0,0);

#ifdef WITH_FPC
char header[] = {"*** Iceman Usart ***"};
uint32_t res = usart_writebuffer((uint8_t *)header, sizeof(header), 100000);
Dbprintf("after sending FPC [%x]", res);
#endif
break;
#ifdef WITH_LCD
case CMD_LCD_RESET:
Expand Down Expand Up @@ -1406,6 +1415,7 @@ void __attribute__((noreturn)) AppMain(void) {
#ifdef WITH_SMARTCARD
I2C_init();
#endif

#ifdef WITH_FPC
usart_init();
#endif
Expand Down
6 changes: 4 additions & 2 deletions armsrc/fpgaloader.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ void FpgaSetupSscExt(uint8_t clearPCER) {

// clock comes from TK pin, no clock output, outputs change on falling
// edge of TK, sample on rising edge of TK, start on positive-going edge of sync
AT91C_BASE_SSC->SSC_TCMR = SSC_CLOCK_MODE_SELECT(2) | SSC_CLOCK_MODE_START(5);
AT91C_BASE_SSC->SSC_TCMR = SSC_CLOCK_MODE_SELECT(2) | SSC_CLOCK_MODE_START(5);

// tx framing is the same as the rx framing
AT91C_BASE_SSC->SSC_TFMR = AT91C_BASE_SSC->SSC_RFMR;
Expand Down Expand Up @@ -462,9 +462,11 @@ void SetAdcMuxFor(uint32_t whichGpio) {
GPIO_MUXSEL_HIRAW;

LOW(GPIO_MUXSEL_HIPKD);
LOW(GPIO_MUXSEL_LOPKD);
#ifndef WITH_FPC
LOW(GPIO_MUXSEL_HIRAW);
LOW(GPIO_MUXSEL_LORAW);
LOW(GPIO_MUXSEL_LOPKD);
#endif

HIGH(whichGpio);
}
Expand Down
28 changes: 25 additions & 3 deletions client/cmdanalyse.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ int usage_analyse_crc(void){
PrintAndLogEx(NORMAL, " analyse crc 137AF00A0A0D");
return 0;
}

int usage_analyse_nuid(void){
PrintAndLogEx(NORMAL, "Generate 4byte NUID from 7byte UID");
PrintAndLogEx(NORMAL, "");
Expand All @@ -66,6 +65,18 @@ int usage_analyse_nuid(void){
PrintAndLogEx(NORMAL, " analyse nuid 11223344556677");
return 0;
}
int usage_analyse_a(void) {
PrintAndLogEx(NORMAL, "my personal garbage test command");
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "Usage: analyse a [h] d <bytes>");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " h This help");
PrintAndLogEx(NORMAL, " d <bytes> bytes to send to device");
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "Examples:");
PrintAndLogEx(NORMAL, " analyse a d 137AF00A0A0D");
return 0;
}

static uint8_t calculateLRC( uint8_t* bytes, uint8_t len) {
uint8_t LRC = 0;
Expand Down Expand Up @@ -484,17 +495,28 @@ int CmdAnalyseA(const char *Cmd){
cmdp += 2;
break;
case 'h':
return usage_analyse_checksum();
return usage_analyse_a();
default:
PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp));
errors = true;
break;
}
}
//Validations
if (errors || cmdp == 0 ) return usage_analyse_checksum();
if (errors || cmdp == 0 ) return usage_analyse_a();


UsbCommand c = {CMD_FPC_SEND, {0, 0, 0}};
clearCommandBuffer();
SendCommand(&c);

UsbCommand resp;
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2500)) {
return 1;
}
PrintAndLogEx(NORMAL, "got ack");
return 0;

PrintAndLogEx(NORMAL, "-- " _BLUE_(its my message) "\n");
PrintAndLogEx(NORMAL, "-- " _RED_(its my message) "\n");
PrintAndLogEx(NORMAL, "-- " _YELLOW_(its my message) "\n");
Expand Down
49 changes: 29 additions & 20 deletions common/cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,30 @@
*/
#include "cmd.h"

// (iceman 2017) this method is not used anymore. uart_win32 /uart_posix is used instead
bool cmd_receive(UsbCommand* cmd) {

// Check if there is a usb packet available
if (!usb_poll_validate_length()) return false;

// Try to retrieve the available command frame
size_t rxlen = usb_read((byte_t*)cmd, sizeof(UsbCommand));

// (iceman) this check is wrong. Since USB can send packages which is not sizeof(usbcommand) 544 bytes.
// hence, I comment it out

// Check if the transfer was complete
//if (rxlen != sizeof(UsbCommand)) return false;
// Received command successfully
//return true;
return (rxlen);
// check if there is a FPC USART1 message?
/*
size_t fpc_rxlen = usart_read((uint8_t*)cmd, sizeof(UsbCommand));
if ( fpc_rxlen )
return true;
*/

// Check if there is a usb packet available
if (!usb_poll_validate_length()) return false;

// Try to retrieve the available command frame
usb_read((uint8_t*)cmd, sizeof(UsbCommand));

// (iceman) this check is wrong. Since USB can send packages which is not sizeof(usbcommand) 544 bytes.
// hence, I comment it out

// Check if the transfer was complete
//if (rxlen != sizeof(UsbCommand)) return false;
// Received command successfully
//return true;
return true;
}

bool cmd_send(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void* data, size_t len) {
Expand All @@ -56,7 +63,7 @@ bool cmd_send(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void* d

// 0x00 the whole command.
for (size_t i=0; i < sizeof(UsbCommand); i++)
((byte_t*)&txcmd)[i] = 0x00;
((uint8_t*)&txcmd)[i] = 0x00;

// Compose the outgoing command frame
txcmd.cmd = cmd;
Expand All @@ -68,13 +75,15 @@ bool cmd_send(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void* d
if (data && len) {
len = MIN(len, USB_CMD_DATA_SIZE);
for (size_t i=0; i<len; i++) {
txcmd.d.asBytes[i] = ((byte_t*)data)[i];
txcmd.d.asBytes[i] = ((uint8_t*)data)[i];
}
}

//usart_send( (uint8_t*)&txcmd, sizeof(UsbCommand));

// Send frame and make sure all bytes are transmitted
if ( usb_write( (byte_t*)&txcmd, sizeof(UsbCommand)) != 0)
return false;

if ( usb_write( (uint8_t*)&txcmd, sizeof(UsbCommand)) != 0)
return false;
return true;
}
1 change: 1 addition & 0 deletions common/cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "common.h"
#include "usb_cmd.h"
#include "usb_cdc.h"
#include "usart.h"
#include "proxmark3.h"

bool cmd_receive(UsbCommand* cmd);
Expand Down
Loading

0 comments on commit bacf8af

Please sign in to comment.