mirror of
https://gitea.osmocom.org/sim-card/simtrace2.git
synced 2026-03-18 06:08:31 +03:00
Sniffer with ringbuf, works SOMETIMES
* Sniffer uses phone endpoints for communication and the ringbuffer
routines the phone communication uses
* Most times the Usart1 interrupt is not triggered, and therefore
no values are recorded
This commit is contained in:
42
firmware/src_simtrace/host_communication.c
Normal file
42
firmware/src_simtrace/host_communication.c
Normal file
@@ -0,0 +1,42 @@
|
||||
#include "board.h"
|
||||
|
||||
static volatile bool write_to_host_in_progress = false;
|
||||
|
||||
void USB_write_callback(uint8_t *pArg, uint8_t status, uint32_t transferred, uint32_t remaining)
|
||||
{
|
||||
if (status != USBD_STATUS_SUCCESS) {
|
||||
TRACE_ERROR("USB err status: %d (%s)\n", __FUNCTION__, status);
|
||||
}
|
||||
write_to_host_in_progress = false;
|
||||
printf("WR_CB\n");
|
||||
}
|
||||
|
||||
int send_to_host()
|
||||
{
|
||||
static uint8_t msg[RING_BUFLEN];
|
||||
int ret = 0;
|
||||
int i;
|
||||
|
||||
for(i = 0; !rbuf_is_empty(&sim_rcv_buf) && i < sizeof(msg); i++) {
|
||||
msg[i] = rbuf_read(&sim_rcv_buf);
|
||||
}
|
||||
printf("Wr %d\n", i);
|
||||
write_to_host_in_progress = true;
|
||||
ret = USBD_Write( PHONE_DATAIN, msg, i, (TransferCallback)&USB_write_callback, 0 );
|
||||
if (ret != USBD_STATUS_SUCCESS) {
|
||||
TRACE_ERROR("Error sending to host (%x)\n", ret);
|
||||
write_to_host_in_progress = false;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int check_data_from_phone()
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if((rbuf_is_empty(&sim_rcv_buf) || write_to_host_in_progress == true)) {
|
||||
return ret;
|
||||
}
|
||||
ret = send_to_host();
|
||||
return ret;
|
||||
}
|
||||
Reference in New Issue
Block a user