mirror of
https://gitea.osmocom.org/sim-card/simtrace2.git
synced 2026-03-24 01:08:32 +03:00
sniffer functionality fixed buffer
It is possible to use sniffer.py to sniff the phone-simcard-communication. To be fixed: The buffer size read is fixed and the data is only send over USB if the buffer max length is reached. which means we don not get the last bytes of the transaction. This should be changed in one of the next commits. Maybe the former simtrace code can give some inspiration on this topic.
This commit is contained in:
@@ -1,6 +1,19 @@
|
|||||||
#ifndef SIMTRACE_H
|
#ifndef SIMTRACE_H
|
||||||
#define SIMTRACE_H
|
#define SIMTRACE_H
|
||||||
|
|
||||||
|
/* Endpoint numbers */
|
||||||
|
#define DATAOUT 1
|
||||||
|
#define DATAIN 2
|
||||||
|
#define INT 3
|
||||||
|
|
||||||
|
#define BUFLEN 64
|
||||||
|
typedef struct ring_buffer
|
||||||
|
{
|
||||||
|
uint8_t buf[BUFLEN*2]; // data buffer
|
||||||
|
uint8_t idx; // number of items in the buffer
|
||||||
|
} ring_buffer;
|
||||||
|
|
||||||
|
|
||||||
enum confNum {
|
enum confNum {
|
||||||
CFG_NUM_SNIFF = 1, CFG_NUM_PHONE, CFG_NUM_MITM, NUM_CONF
|
CFG_NUM_SNIFF = 1, CFG_NUM_PHONE, CFG_NUM_MITM, NUM_CONF
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -38,11 +38,38 @@
|
|||||||
extern uint8_t rcvdChar;
|
extern uint8_t rcvdChar;
|
||||||
extern uint32_t char_stat;
|
extern uint32_t char_stat;
|
||||||
|
|
||||||
|
//#define BUFLEN 14
|
||||||
|
// FIXME: Remove:
|
||||||
|
#define PR TRACE_DEBUG
|
||||||
|
//#define PR printf
|
||||||
|
|
||||||
|
/*typedef struct ring_buffer
|
||||||
|
{
|
||||||
|
uint8_t buf[BUFLEN*2]; // data buffer
|
||||||
|
uint8_t idx; // number of items in the buffer
|
||||||
|
} ring_buffer;
|
||||||
|
*/
|
||||||
|
ring_buffer buf = { {0}, 0 };
|
||||||
|
|
||||||
|
void buf_push(uint8_t item)
|
||||||
|
{
|
||||||
|
buf.buf[buf.idx % (BUFLEN*2)] = item;
|
||||||
|
PR("----- Push: %x %x\n\r", buf.idx, buf.buf[buf.idx]);
|
||||||
|
buf.idx = (buf.idx+1) % (BUFLEN*2);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t get_buf_start(uint8_t *buf_start)
|
||||||
|
{
|
||||||
|
*buf_start = &(buf.buf[buf.idx]);
|
||||||
|
return 2*BUFLEN-buf.idx;
|
||||||
|
}
|
||||||
|
|
||||||
/** Initializes a ISO driver
|
/** Initializes a ISO driver
|
||||||
*/
|
*/
|
||||||
// FIXME: This function is implemented in iso7816_4.c !! Only MCK instead of SCK is always taken. Change that!
|
// FIXME: This function is implemented in iso7816_4.c !! Only MCK instead of SCK is always taken. Change that!
|
||||||
void _ISO7816_Init( void )
|
void _ISO7816_Init( void )
|
||||||
{
|
{
|
||||||
|
printf("ISO_Init\n\r");
|
||||||
TRACE_DEBUG("ISO_Init\n\r");
|
TRACE_DEBUG("ISO_Init\n\r");
|
||||||
|
|
||||||
USART_Configure( USART_PHONE,
|
USART_Configure( USART_PHONE,
|
||||||
@@ -98,20 +125,29 @@ void USART1_IrqHandler( void )
|
|||||||
*/
|
*/
|
||||||
uint32_t csr = USART_PHONE->US_CSR;
|
uint32_t csr = USART_PHONE->US_CSR;
|
||||||
|
|
||||||
|
PR("---- stat: %x\n\r", csr);
|
||||||
|
|
||||||
if (csr & US_CSR_TXRDY) {
|
if (csr & US_CSR_TXRDY) {
|
||||||
/* transmit buffer empty, nothing to transmit */
|
/* transmit buffer empty, nothing to transmit */
|
||||||
}
|
}
|
||||||
if (csr & US_CSR_RXRDY) {
|
if (csr & US_CSR_RXRDY) {
|
||||||
stat = (csr&(US_CSR_OVRE|US_CSR_FRAME|
|
stat = (csr&(US_CSR_OVRE|US_CSR_FRAME|
|
||||||
US_CSR_PARE|US_CSR_TIMEOUT|US_CSR_NACK|
|
US_CSR_PARE|US_CSR_TIMEOUT|US_CSR_NACK|
|
||||||
(1<<10)));
|
(1<<10)));
|
||||||
|
|
||||||
if (stat == 0 ) {
|
if (stat == 0 ) {
|
||||||
/* Get a char */
|
/* Fill char into buffer */
|
||||||
rcvdChar = ((USART_PHONE->US_RHR) & 0xFF);
|
PR("---- BUFLEN %x\n\r", buf.idx);
|
||||||
} /* else: error occured */
|
buf_push((USART_PHONE->US_RHR) & 0xFF);
|
||||||
char_stat = stat;
|
} else {
|
||||||
}
|
// buf_push((USART_PHONE->US_RHR) & 0xFF);
|
||||||
}
|
PR("%x\n\r", (USART_PHONE->US_RHR) & 0xFF);
|
||||||
|
} /* else: error occured */
|
||||||
|
|
||||||
|
if ((buf.idx % BUFLEN) == 0) {
|
||||||
|
rcvdChar = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
char_stat = stat;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -38,6 +38,8 @@
|
|||||||
/*------------------------------------------------------------------------------
|
/*------------------------------------------------------------------------------
|
||||||
* Internal definitions
|
* Internal definitions
|
||||||
*------------------------------------------------------------------------------*/
|
*------------------------------------------------------------------------------*/
|
||||||
|
// FIXME: Remove:
|
||||||
|
#define PR TRACE_DEBUG
|
||||||
|
|
||||||
/** Maximum ucSize in bytes of the smartcard answer to a command.*/
|
/** Maximum ucSize in bytes of the smartcard answer to a command.*/
|
||||||
#define MAX_ANSWER_SIZE 10
|
#define MAX_ANSWER_SIZE 10
|
||||||
@@ -60,6 +62,7 @@ static const Pin pPwr[] = {
|
|||||||
|
|
||||||
extern uint32_t char_stat;
|
extern uint32_t char_stat;
|
||||||
extern uint8_t rcvdChar;
|
extern uint8_t rcvdChar;
|
||||||
|
extern ring_buffer buf;
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------
|
||||||
* Initialization routine
|
* Initialization routine
|
||||||
@@ -80,8 +83,16 @@ void Sniffer_Init( void )
|
|||||||
|
|
||||||
void Sniffer_run( void )
|
void Sniffer_run( void )
|
||||||
{
|
{
|
||||||
|
uint8_t c = 0;
|
||||||
|
c++;
|
||||||
|
|
||||||
if (rcvdChar != 0) {
|
if (rcvdChar != 0) {
|
||||||
TRACE_DEBUG("Rcvd char _%x_ \n\r", rcvdChar);
|
/* DATA_IN for host side is data_out for simtrace side */
|
||||||
|
/* FIXME: Performancewise sending a USB packet for every byte is a disaster */
|
||||||
|
PR("----- %x %x %x ..\n\r", buf.buf[0], buf.buf[1],buf.buf[2] );
|
||||||
|
USBD_Write( DATAIN, buf.buf, BUFLEN, 0, 0 );
|
||||||
|
// USBD_Write( DATAIN, &c, 1, 0, 0 );
|
||||||
|
PR("----- Rcvd char\n\r");
|
||||||
rcvdChar = 0;
|
rcvdChar = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -154,11 +154,6 @@ const unsigned char *stringDescriptors[] = {
|
|||||||
MITMConfigStringDescriptor
|
MITMConfigStringDescriptor
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Endpoint numbers */
|
|
||||||
#define DATAOUT 1
|
|
||||||
#define DATAIN 2
|
|
||||||
#define INT 3
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------------------
|
/*------------------------------------------------------------------------------
|
||||||
* USB Device descriptors
|
* USB Device descriptors
|
||||||
*------------------------------------------------------------------------------*/
|
*------------------------------------------------------------------------------*/
|
||||||
|
|||||||
Reference in New Issue
Block a user