mirror of
https://gitea.osmocom.org/sim-card/simtrace2.git
synced 2026-03-18 14:28:33 +03:00
Compare commits
8 Commits
osmith/wip
...
laforge/to
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eb8fbc0296 | ||
|
|
9292d22726 | ||
|
|
d2bc858ddf | ||
|
|
29de264d6e | ||
|
|
07fda1e706 | ||
|
|
ed4ca25730 | ||
|
|
69c32f2e38 | ||
|
|
53dfaa0aab |
@@ -221,6 +221,7 @@ extern int main(void)
|
|||||||
}
|
}
|
||||||
last_simtrace_config = simtrace_config;
|
last_simtrace_config = simtrace_config;
|
||||||
} else {
|
} else {
|
||||||
|
//FIXME: usb_proces() for every interface in this configuration?
|
||||||
if (config_func_ptrs[simtrace_config].run) {
|
if (config_func_ptrs[simtrace_config].run) {
|
||||||
config_func_ptrs[simtrace_config].run();
|
config_func_ptrs[simtrace_config].run();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1672,6 +1672,10 @@ uint8_t USBD_HAL_Halt(uint8_t bEndpoint, uint8_t ctl)
|
|||||||
UDP->UDP_RST_EP |= 1 << bEndpoint;
|
UDP->UDP_RST_EP |= 1 << bEndpoint;
|
||||||
UDP->UDP_RST_EP &= ~(1 << bEndpoint);
|
UDP->UDP_RST_EP &= ~(1 << bEndpoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* This fixes a weird bug with regard to ping-pong OUT endpoints */
|
||||||
|
UDP->UDP_RST_EP |= 1 << bEndpoint;
|
||||||
|
UDP->UDP_RST_EP &= ~(1 << bEndpoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return Halt status */
|
/* Return Halt status */
|
||||||
|
|||||||
@@ -91,8 +91,8 @@
|
|||||||
#define PINS_WWAN_IN { PIN_WWAN1, PIN_WWAN2 }
|
#define PINS_WWAN_IN { PIN_WWAN1, PIN_WWAN2 }
|
||||||
|
|
||||||
/* outputs controlling RESET input of modems */
|
/* outputs controlling RESET input of modems */
|
||||||
#define PIN_PERST1 {PIO_PA25, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_PULLUP}
|
#define PIN_PERST1 {PIO_PA25, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_PULLUP}
|
||||||
#define PIN_PERST2 {PIO_PA26, PIOA, ID_PIOA, PIO_OUTPUT_0, PIO_PULLUP}
|
#define PIN_PERST2 {PIO_PA26, PIOA, ID_PIOA, PIO_OUTPUT_1, PIO_PULLUP}
|
||||||
#define PINS_PERST { PIN_PERST1, PIN_PERST2 }
|
#define PINS_PERST { PIN_PERST1, PIN_PERST2 }
|
||||||
|
|
||||||
#define PIN_VERSION_DET {PIO_PA19, PIOA, ID_PIOA, PIO_PERIPH_D, PIO_DEFAULT}
|
#define PIN_VERSION_DET {PIO_PA19, PIOA, ID_PIOA, PIO_PERIPH_D, PIO_DEFAULT}
|
||||||
|
|||||||
@@ -42,5 +42,15 @@ int usb_drain_queue(uint8_t ep);
|
|||||||
void usb_buf_init(void);
|
void usb_buf_init(void);
|
||||||
struct usb_buffered_ep *usb_get_buf_ep(uint8_t ep);
|
struct usb_buffered_ep *usb_get_buf_ep(uint8_t ep);
|
||||||
|
|
||||||
int usb_refill_to_host(uint8_t ep);
|
struct usb_if {
|
||||||
int usb_refill_from_host(uint8_t ep);
|
uint8_t if_num; /* interface number */
|
||||||
|
uint8_t ep_out; /* OUT endpoint (0 if none) */
|
||||||
|
uint8_t ep_in; /* IN endpint (0 if none) */
|
||||||
|
uint8_t ep_int; /* INT endpoint (0 if none) */
|
||||||
|
void *data; /* opaque data, passed through */
|
||||||
|
struct {
|
||||||
|
/* call-back to be called for inclming messages on OUT EP */
|
||||||
|
void (*rx_out)(struct msgb *msg, const struct usb_if *usb_if);
|
||||||
|
} ops;
|
||||||
|
};
|
||||||
|
void usb_process(const struct usb_if *usb_if);
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ static void usb_write_cb(uint8_t *arg, uint8_t status, uint32_t transferred,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* check if the spcified IN endpoint is idle and submit the next buffer from queue */
|
/* check if the spcified IN endpoint is idle and submit the next buffer from queue */
|
||||||
int usb_refill_to_host(uint8_t ep)
|
static int usb_refill_to_host(uint8_t ep)
|
||||||
{
|
{
|
||||||
struct usb_buffered_ep *bep = usb_get_buf_ep(ep);
|
struct usb_buffered_ep *bep = usb_get_buf_ep(ep);
|
||||||
struct msgb *msg;
|
struct msgb *msg;
|
||||||
@@ -130,7 +130,7 @@ static void usb_read_cb(uint8_t *arg, uint8_t status, uint32_t transferred,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* refill the read queue for data received from host PC on OUT EP, if needed */
|
/* refill the read queue for data received from host PC on OUT EP, if needed */
|
||||||
int usb_refill_from_host(uint8_t ep)
|
static int usb_refill_from_host(uint8_t ep)
|
||||||
{
|
{
|
||||||
struct usb_buffered_ep *bep = usb_get_buf_ep(ep);
|
struct usb_buffered_ep *bep = usb_get_buf_ep(ep);
|
||||||
struct msgb *msg;
|
struct msgb *msg;
|
||||||
@@ -198,3 +198,45 @@ int usb_drain_queue(uint8_t ep)
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* iterate over the queue of incoming USB commands and dispatch/execute
|
||||||
|
* them */
|
||||||
|
static void process_any_usb_commands(const struct usb_if *usb_if)
|
||||||
|
{
|
||||||
|
struct llist_head *queue = usb_get_queue(usb_if->ep_out);
|
||||||
|
struct llist_head *lh;
|
||||||
|
struct msgb *msg;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
/* limit the number of iterations to 10, to ensure we don't get
|
||||||
|
* stuck here without returning to main loop processing */
|
||||||
|
for (i = 0; i < 10; i++) {
|
||||||
|
/* de-queue the list head in an irq-safe way */
|
||||||
|
lh = llist_head_dequeue_irqsafe(queue);
|
||||||
|
if (!lh)
|
||||||
|
break;
|
||||||
|
msg = llist_entry(lh, struct msgb, list);
|
||||||
|
usb_if->ops.rx_out(msg, usb_if);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* perform any action related to USB processing (IRQ/INT/OUT EP refill, handling OUT) */
|
||||||
|
void usb_process(const struct usb_if *usb_if)
|
||||||
|
{
|
||||||
|
/* first try to send any pending messages on IRQ */
|
||||||
|
if (usb_if->ep_int)
|
||||||
|
usb_refill_to_host(usb_if->ep_int);
|
||||||
|
|
||||||
|
/* then try to send any pending messages on IN */
|
||||||
|
if (usb_if->ep_in)
|
||||||
|
usb_refill_to_host(usb_if->ep_in);
|
||||||
|
|
||||||
|
/* ensure we can handle incoming USB messages from the
|
||||||
|
* host */
|
||||||
|
if (usb_if->ep_out) {
|
||||||
|
usb_refill_from_host(usb_if->ep_out);
|
||||||
|
process_any_usb_commands(usb_if);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -34,6 +34,8 @@
|
|||||||
|
|
||||||
#define TRACE_ENTRY() TRACE_DEBUG("%s entering\r\n", __func__)
|
#define TRACE_ENTRY() TRACE_DEBUG("%s entering\r\n", __func__)
|
||||||
|
|
||||||
|
static void dispatch_received_usb_msg(struct msgb *msg, const struct usb_if *usb_if);
|
||||||
|
|
||||||
#ifdef PINS_CARDSIM
|
#ifdef PINS_CARDSIM
|
||||||
static const Pin pins_cardsim[] = PINS_CARDSIM;
|
static const Pin pins_cardsim[] = PINS_CARDSIM;
|
||||||
#endif
|
#endif
|
||||||
@@ -68,12 +70,11 @@ struct cardem_inst {
|
|||||||
bool half_time_notified;
|
bool half_time_notified;
|
||||||
} wt;
|
} wt;
|
||||||
int usb_pending_old;
|
int usb_pending_old;
|
||||||
uint8_t ep_out;
|
struct usb_if usb_if;
|
||||||
uint8_t ep_in;
|
|
||||||
uint8_t ep_int;
|
|
||||||
const Pin pin_insert;
|
const Pin pin_insert;
|
||||||
#ifdef DETECT_VCC_BY_ADC
|
#ifdef DETECT_VCC_BY_ADC
|
||||||
uint32_t vcc_uv;
|
uint32_t vcc_uv;
|
||||||
|
uint32_t vcc_uv_last;
|
||||||
#endif
|
#endif
|
||||||
bool vcc_active;
|
bool vcc_active;
|
||||||
bool vcc_active_last;
|
bool vcc_active_last;
|
||||||
@@ -89,9 +90,16 @@ struct cardem_inst cardem_inst[] = {
|
|||||||
.id = ID_USART1,
|
.id = ID_USART1,
|
||||||
.state = USART_RCV
|
.state = USART_RCV
|
||||||
},
|
},
|
||||||
.ep_out = SIMTRACE_CARDEM_USB_EP_USIM1_DATAOUT,
|
.usb_if = {
|
||||||
.ep_in = SIMTRACE_CARDEM_USB_EP_USIM1_DATAIN,
|
.if_num = 0,
|
||||||
.ep_int = SIMTRACE_CARDEM_USB_EP_USIM1_INT,
|
.ep_out = SIMTRACE_CARDEM_USB_EP_USIM1_DATAOUT,
|
||||||
|
.ep_in = SIMTRACE_CARDEM_USB_EP_USIM1_DATAIN,
|
||||||
|
.ep_int = SIMTRACE_CARDEM_USB_EP_USIM1_INT,
|
||||||
|
.data = &cardem_inst[0],
|
||||||
|
.ops = {
|
||||||
|
.rx_out = dispatch_received_usb_msg,
|
||||||
|
},
|
||||||
|
},
|
||||||
#ifdef PIN_SET_USIM1_PRES
|
#ifdef PIN_SET_USIM1_PRES
|
||||||
.pin_insert = PIN_SET_USIM1_PRES,
|
.pin_insert = PIN_SET_USIM1_PRES,
|
||||||
#endif
|
#endif
|
||||||
@@ -104,9 +112,16 @@ struct cardem_inst cardem_inst[] = {
|
|||||||
.id = ID_USART0,
|
.id = ID_USART0,
|
||||||
.state = USART_RCV
|
.state = USART_RCV
|
||||||
},
|
},
|
||||||
.ep_out = SIMTRACE_CARDEM_USB_EP_USIM2_DATAOUT,
|
.usb_if = {
|
||||||
.ep_in = SIMTRACE_CARDEM_USB_EP_USIM2_DATAIN,
|
.if_num = 1,
|
||||||
.ep_int = SIMTRACE_CARDEM_USB_EP_USIM2_INT,
|
.ep_out = SIMTRACE_CARDEM_USB_EP_USIM2_DATAOUT,
|
||||||
|
.ep_in = SIMTRACE_CARDEM_USB_EP_USIM2_DATAIN,
|
||||||
|
.ep_int = SIMTRACE_CARDEM_USB_EP_USIM2_INT,
|
||||||
|
.data = &cardem_inst[1],
|
||||||
|
.ops = {
|
||||||
|
.rx_out = dispatch_received_usb_msg,
|
||||||
|
},
|
||||||
|
},
|
||||||
#ifdef PIN_SET_USIM2_PRES
|
#ifdef PIN_SET_USIM2_PRES
|
||||||
.pin_insert = PIN_SET_USIM2_PRES,
|
.pin_insert = PIN_SET_USIM2_PRES,
|
||||||
#endif
|
#endif
|
||||||
@@ -253,6 +268,7 @@ static uint16_t compute_next_timeout(struct cardem_inst *ci)
|
|||||||
* \param[in] inst_num Instance number, range 0..1 (some boards only '0' permitted) */
|
* \param[in] inst_num Instance number, range 0..1 (some boards only '0' permitted) */
|
||||||
static void usart_irq_rx(uint8_t inst_num)
|
static void usart_irq_rx(uint8_t inst_num)
|
||||||
{
|
{
|
||||||
|
OSMO_ASSERT(inst_num < ARRAY_SIZE(cardem_inst));
|
||||||
Usart *usart = get_usart_by_chan(inst_num);
|
Usart *usart = get_usart_by_chan(inst_num);
|
||||||
struct cardem_inst *ci = &cardem_inst[inst_num];
|
struct cardem_inst *ci = &cardem_inst[inst_num];
|
||||||
uint32_t csr;
|
uint32_t csr;
|
||||||
@@ -461,10 +477,14 @@ static int card_vcc_adc_init(void)
|
|||||||
|
|
||||||
static void process_vcc_adc(struct cardem_inst *ci)
|
static void process_vcc_adc(struct cardem_inst *ci)
|
||||||
{
|
{
|
||||||
if (ci->vcc_uv >= VCC_UV_THRESH_3V)
|
if (ci->vcc_uv >= VCC_UV_THRESH_3V &&
|
||||||
|
ci->vcc_uv_last < VCC_UV_THRESH_3V) {
|
||||||
ci->vcc_active = true;
|
ci->vcc_active = true;
|
||||||
else
|
} else if (ci->vcc_uv < VCC_UV_THRESH_3V &&
|
||||||
|
ci->vcc_uv_last >= VCC_UV_THRESH_3V) {
|
||||||
ci->vcc_active = false;
|
ci->vcc_active = false;
|
||||||
|
}
|
||||||
|
ci->vcc_uv_last = ci->vcc_uv;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ADC_IrqHandler(void)
|
void ADC_IrqHandler(void)
|
||||||
@@ -781,8 +801,9 @@ static void dispatch_usb_command_modem(struct msgb *msg, struct cardem_inst *ci)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* handle a single USB command as received from the USB host */
|
/* handle a single USB command as received from the USB host */
|
||||||
static void dispatch_usb_command(struct msgb *msg, struct cardem_inst *ci)
|
static void dispatch_usb_command(struct msgb *msg, const struct usb_if *usb_if)
|
||||||
{
|
{
|
||||||
|
struct cardem_inst *ci = usb_if->data;
|
||||||
struct simtrace_msg_hdr *sh = (struct simtrace_msg_hdr *) msg->l1h;
|
struct simtrace_msg_hdr *sh = (struct simtrace_msg_hdr *) msg->l1h;
|
||||||
|
|
||||||
if (msgb_length(msg) < sizeof(*sh)) {
|
if (msgb_length(msg) < sizeof(*sh)) {
|
||||||
@@ -811,7 +832,8 @@ static void dispatch_usb_command(struct msgb *msg, struct cardem_inst *ci)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dispatch_received_msg(struct msgb *msg, struct cardem_inst *ci)
|
/* handle a single USB transfer as received from the USB host */
|
||||||
|
static void dispatch_received_usb_msg(struct msgb *msg, const struct usb_if *usb_if)
|
||||||
{
|
{
|
||||||
struct msgb *segm;
|
struct msgb *segm;
|
||||||
struct simtrace_msg_hdr *mh;
|
struct simtrace_msg_hdr *mh;
|
||||||
@@ -822,7 +844,7 @@ static void dispatch_received_msg(struct msgb *msg, struct cardem_inst *ci)
|
|||||||
mh = (struct simtrace_msg_hdr *) msg->data;
|
mh = (struct simtrace_msg_hdr *) msg->data;
|
||||||
if (mh->msg_len == msgb_length(msg)) {
|
if (mh->msg_len == msgb_length(msg)) {
|
||||||
/* fast path: only one message in buffer */
|
/* fast path: only one message in buffer */
|
||||||
dispatch_usb_command(msg, ci);
|
dispatch_usb_command(msg, usb_if);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -831,23 +853,23 @@ static void dispatch_received_msg(struct msgb *msg, struct cardem_inst *ci)
|
|||||||
while (1) {
|
while (1) {
|
||||||
mh = (struct simtrace_msg_hdr *) msg->data;
|
mh = (struct simtrace_msg_hdr *) msg->data;
|
||||||
|
|
||||||
segm = usb_buf_alloc(ci->ep_out);
|
segm = usb_buf_alloc(usb_if->ep_out);
|
||||||
if (!segm) {
|
if (!segm) {
|
||||||
TRACE_ERROR("%u: ENOMEM during msg segmentation\r\n",
|
TRACE_ERROR("%u: ENOMEM during msg segmentation\r\n",
|
||||||
ci->num);
|
usb_if->if_num);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mh->msg_len > msgb_length(msg)) {
|
if (mh->msg_len > msgb_length(msg)) {
|
||||||
TRACE_ERROR("%u: Unexpected large message (%u bytes)\r\n",
|
TRACE_ERROR("%u: Unexpected large message (%u bytes)\r\n",
|
||||||
ci->num, mh->msg_len);
|
usb_if->if_num, mh->msg_len);
|
||||||
usb_buf_free(segm);
|
usb_buf_free(segm);
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
uint8_t *cur = msgb_put(segm, mh->msg_len);
|
uint8_t *cur = msgb_put(segm, mh->msg_len);
|
||||||
segm->l1h = segm->head;
|
segm->l1h = segm->head;
|
||||||
memcpy(cur, mh, mh->msg_len);
|
memcpy(cur, mh, mh->msg_len);
|
||||||
dispatch_usb_command(segm, ci);
|
dispatch_usb_command(segm, usb_if);
|
||||||
}
|
}
|
||||||
/* pull this message */
|
/* pull this message */
|
||||||
msgb_pull(msg, mh->msg_len);
|
msgb_pull(msg, mh->msg_len);
|
||||||
@@ -859,35 +881,14 @@ static void dispatch_received_msg(struct msgb *msg, struct cardem_inst *ci)
|
|||||||
usb_buf_free(msg);
|
usb_buf_free(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* iterate over the queue of incoming USB commands and dispatch/execute
|
|
||||||
* them */
|
|
||||||
static void process_any_usb_commands(struct llist_head *main_q,
|
|
||||||
struct cardem_inst *ci)
|
|
||||||
{
|
|
||||||
struct llist_head *lh;
|
|
||||||
struct msgb *msg;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
/* limit the number of iterations to 10, to ensure we don't get
|
|
||||||
* stuck here without returning to main loop processing */
|
|
||||||
for (i = 0; i < 10; i++) {
|
|
||||||
/* de-queue the list head in an irq-safe way */
|
|
||||||
lh = llist_head_dequeue_irqsafe(main_q);
|
|
||||||
if (!lh)
|
|
||||||
break;
|
|
||||||
msg = llist_entry(lh, struct msgb, list);
|
|
||||||
dispatch_received_msg(msg, ci);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* main loop function, called repeatedly */
|
/* main loop function, called repeatedly */
|
||||||
void mode_cardemu_run(void)
|
void mode_cardemu_run(void)
|
||||||
{
|
{
|
||||||
struct llist_head *queue;
|
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(cardem_inst); i++) {
|
for (i = 0; i < ARRAY_SIZE(cardem_inst); i++) {
|
||||||
struct cardem_inst *ci = &cardem_inst[i];
|
struct cardem_inst *ci = &cardem_inst[i];
|
||||||
|
struct usb_if *usb_if = &ci->usb_if;
|
||||||
|
|
||||||
/* drain the ring buffer from UART into card_emu */
|
/* drain the ring buffer from UART into card_emu */
|
||||||
while (1) {
|
while (1) {
|
||||||
@@ -904,16 +905,6 @@ void mode_cardemu_run(void)
|
|||||||
|
|
||||||
process_io_statechg(ci);
|
process_io_statechg(ci);
|
||||||
|
|
||||||
/* first try to send any pending messages on IRQ */
|
usb_process(&ci->usb_if);
|
||||||
usb_refill_to_host(ci->ep_int);
|
|
||||||
|
|
||||||
/* then try to send any pending messages on IN */
|
|
||||||
usb_refill_to_host(ci->ep_in);
|
|
||||||
|
|
||||||
/* ensure we can handle incoming USB messages from the
|
|
||||||
* host */
|
|
||||||
usb_refill_from_host(ci->ep_out);
|
|
||||||
queue = usb_get_queue(ci->ep_out);
|
|
||||||
process_any_usb_commands(queue, ci);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -975,20 +975,42 @@ static void usb_send_change(uint32_t flags)
|
|||||||
usb_msg_upd_len_and_submit(usb_msg);
|
usb_msg_upd_len_and_submit(usb_msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* handle incoming message from USB OUT EP */
|
||||||
|
static void dispatch_usb_out(struct msgb *msg, const struct usb_if *usb_if)
|
||||||
|
{
|
||||||
|
struct simtrace_msg_hdr *sh = (struct simtrace_msg_hdr *) msg->l1h;
|
||||||
|
|
||||||
|
if (msgb_length(msg) < sizeof(*sh)) {
|
||||||
|
usb_buf_free(msg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
msg->l2h = msg->l1h + sizeof(*sh);
|
||||||
|
|
||||||
|
switch (sh->msg_class) {
|
||||||
|
case SIMTRACE_MSGC_GENERIC:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
usb_buf_free(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct usb_if sniffer_usb_if = {
|
||||||
|
.if_num = 0,
|
||||||
|
.ep_in = SIMTRACE_USB_EP_CARD_DATAIN,
|
||||||
|
.ep_int = SIMTRACE_USB_EP_CARD_INT,
|
||||||
|
.ep_out = SIMTRACE_USB_EP_CARD_DATAOUT,
|
||||||
|
.ops = {
|
||||||
|
.rx_out = dispatch_usb_out,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/* Main (idle/busy) loop of this USB configuration */
|
/* Main (idle/busy) loop of this USB configuration */
|
||||||
void Sniffer_run(void)
|
void Sniffer_run(void)
|
||||||
{
|
{
|
||||||
/* Handle USB queue */
|
/* Handle USB queue */
|
||||||
/* first try to send any pending messages on INT */
|
usb_process(&sniffer_usb_if);
|
||||||
usb_refill_to_host(SIMTRACE_USB_EP_CARD_INT);
|
|
||||||
/* then try to send any pending messages on IN */
|
|
||||||
usb_refill_to_host(SIMTRACE_USB_EP_CARD_DATAIN);
|
|
||||||
/* ensure we can handle incoming USB messages from the host */
|
|
||||||
/* currently we don't need any incoming data
|
|
||||||
usb_refill_from_host(SIMTRACE_USB_EP_CARD_DATAOUT);
|
|
||||||
struct llist_head *queue = usb_get_queue(SIMTRACE_USB_EP_CARD_DATAOUT);
|
|
||||||
process_any_usb_commands(queue);
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* WARNING: the signal data and flags are not synchronized. We have to hope
|
/* WARNING: the signal data and flags are not synchronized. We have to hope
|
||||||
* the processing is fast enough to not land in the wrong state while data
|
* the processing is fast enough to not land in the wrong state while data
|
||||||
|
|||||||
@@ -44,9 +44,13 @@
|
|||||||
#include <osmocom/core/utils.h>
|
#include <osmocom/core/utils.h>
|
||||||
#include <osmocom/core/socket.h>
|
#include <osmocom/core/socket.h>
|
||||||
#include <osmocom/core/msgb.h>
|
#include <osmocom/core/msgb.h>
|
||||||
|
#include <osmocom/core/logging.h>
|
||||||
#include <osmocom/sim/class_tables.h>
|
#include <osmocom/sim/class_tables.h>
|
||||||
#include <osmocom/sim/sim.h>
|
#include <osmocom/sim/sim.h>
|
||||||
|
|
||||||
|
#define LOGSLOT(slot, lvl, fmt, args...) \
|
||||||
|
LOGP(DLINP, lvl, "[%u] " fmt, (slot)->slot_nr, ## args)
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
* SIMTRACE core protocol
|
* SIMTRACE core protocol
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
@@ -141,7 +145,6 @@ int osmo_st2_slot_tx_msg(struct osmo_st2_slot *slot, struct msgb *msg,
|
|||||||
OSMO_ASSERT(transp);
|
OSMO_ASSERT(transp);
|
||||||
|
|
||||||
st_push_hdr(msg, msg_class, msg_type, slot->slot_nr);
|
st_push_hdr(msg, msg_class, msg_type, slot->slot_nr);
|
||||||
printf("SIMtrace <- %s\n", msgb_hexdump(msg));
|
|
||||||
|
|
||||||
if (transp->udp_fd < 0) {
|
if (transp->udp_fd < 0) {
|
||||||
if (transp->usb_async)
|
if (transp->usb_async)
|
||||||
@@ -166,6 +169,8 @@ int osmo_st2_cardem_request_card_insert(struct osmo_st2_cardem_inst *ci, bool in
|
|||||||
struct msgb *msg = st_msgb_alloc();
|
struct msgb *msg = st_msgb_alloc();
|
||||||
struct cardemu_usb_msg_cardinsert *cins;
|
struct cardemu_usb_msg_cardinsert *cins;
|
||||||
|
|
||||||
|
LOGSLOT(ci->slot, LOGL_NOTICE, "<= %s(inserted=%d)\n", __func__, inserted);
|
||||||
|
|
||||||
cins = (struct cardemu_usb_msg_cardinsert *) msgb_put(msg, sizeof(*cins));
|
cins = (struct cardemu_usb_msg_cardinsert *) msgb_put(msg, sizeof(*cins));
|
||||||
memset(cins, 0, sizeof(*cins));
|
memset(cins, 0, sizeof(*cins));
|
||||||
if (inserted)
|
if (inserted)
|
||||||
@@ -181,7 +186,7 @@ int osmo_st2_cardem_request_pb_and_rx(struct osmo_st2_cardem_inst *ci, uint8_t p
|
|||||||
struct cardemu_usb_msg_tx_data *txd;
|
struct cardemu_usb_msg_tx_data *txd;
|
||||||
txd = (struct cardemu_usb_msg_tx_data *) msgb_put(msg, sizeof(*txd));
|
txd = (struct cardemu_usb_msg_tx_data *) msgb_put(msg, sizeof(*txd));
|
||||||
|
|
||||||
printf("<= %s(%02x, %d)\n", __func__, pb, le);
|
LOGSLOT(ci->slot, LOGL_DEBUG, "<= %s(pb=%02x, le=%u)\n", __func__, pb, le);
|
||||||
|
|
||||||
memset(txd, 0, sizeof(*txd));
|
memset(txd, 0, sizeof(*txd));
|
||||||
txd->data_len = 1;
|
txd->data_len = 1;
|
||||||
@@ -202,7 +207,7 @@ int osmo_st2_cardem_request_pb_and_tx(struct osmo_st2_cardem_inst *ci, uint8_t p
|
|||||||
|
|
||||||
txd = (struct cardemu_usb_msg_tx_data *) msgb_put(msg, sizeof(*txd));
|
txd = (struct cardemu_usb_msg_tx_data *) msgb_put(msg, sizeof(*txd));
|
||||||
|
|
||||||
printf("<= %s(%02x, %s, %d)\n", __func__, pb,
|
LOGSLOT(ci->slot, LOGL_DEBUG, "<= %s(pb=%02x, tx=%s, len=%d)\n", __func__, pb,
|
||||||
osmo_hexdump(data, data_len_in), data_len_in);
|
osmo_hexdump(data, data_len_in), data_len_in);
|
||||||
|
|
||||||
memset(txd, 0, sizeof(*txd));
|
memset(txd, 0, sizeof(*txd));
|
||||||
@@ -226,7 +231,7 @@ int osmo_st2_cardem_request_sw_tx(struct osmo_st2_cardem_inst *ci, const uint8_t
|
|||||||
|
|
||||||
txd = (struct cardemu_usb_msg_tx_data *) msgb_put(msg, sizeof(*txd));
|
txd = (struct cardemu_usb_msg_tx_data *) msgb_put(msg, sizeof(*txd));
|
||||||
|
|
||||||
printf("<= %s(%02x %02x)\n", __func__, sw[0], sw[1]);
|
LOGSLOT(ci->slot, LOGL_DEBUG, "<= %s(sw=%02x%02x)\n", __func__, sw[0], sw[1]);
|
||||||
|
|
||||||
memset(txd, 0, sizeof(*txd));
|
memset(txd, 0, sizeof(*txd));
|
||||||
txd->data_len = 2;
|
txd->data_len = 2;
|
||||||
@@ -246,7 +251,7 @@ int osmo_st2_cardem_request_set_atr(struct osmo_st2_cardem_inst *ci, const uint8
|
|||||||
|
|
||||||
satr = (struct cardemu_usb_msg_set_atr *) msgb_put(msg, sizeof(*satr));
|
satr = (struct cardemu_usb_msg_set_atr *) msgb_put(msg, sizeof(*satr));
|
||||||
|
|
||||||
printf("<= %s(%s)\n", __func__, osmo_hexdump(atr, atr_len));
|
LOGSLOT(ci->slot, LOGL_NOTICE, "<= %s(%s)\n", __func__, osmo_hexdump(atr, atr_len));
|
||||||
|
|
||||||
memset(satr, 0, sizeof(*satr));
|
memset(satr, 0, sizeof(*satr));
|
||||||
satr->atr_len = atr_len;
|
satr->atr_len = atr_len;
|
||||||
@@ -263,7 +268,7 @@ int osmo_st2_cardem_request_config(struct osmo_st2_cardem_inst *ci, uint32_t fea
|
|||||||
|
|
||||||
cfg = (struct cardemu_usb_msg_config *) msgb_put(msg, sizeof(*cfg));
|
cfg = (struct cardemu_usb_msg_config *) msgb_put(msg, sizeof(*cfg));
|
||||||
|
|
||||||
printf("<= %s(%08x)\n", __func__, features);
|
LOGSLOT(ci->slot, LOGL_NOTICE, "<= %s(features=%08x)\n", __func__, features);
|
||||||
|
|
||||||
memset(cfg, 0, sizeof(*cfg));
|
memset(cfg, 0, sizeof(*cfg));
|
||||||
cfg->features = features;
|
cfg->features = features;
|
||||||
@@ -280,6 +285,9 @@ static int _modem_reset(struct osmo_st2_slot *slot, uint8_t asserted, uint16_t p
|
|||||||
struct msgb *msg = st_msgb_alloc();
|
struct msgb *msg = st_msgb_alloc();
|
||||||
struct st_modem_reset *sr ;
|
struct st_modem_reset *sr ;
|
||||||
|
|
||||||
|
LOGSLOT(slot, LOGL_NOTICE, "<= %s(asserted=%u, pulse_ms=%u)\n", __func__,
|
||||||
|
asserted, pulse_ms);
|
||||||
|
|
||||||
sr = (struct st_modem_reset *) msgb_put(msg, sizeof(*sr));
|
sr = (struct st_modem_reset *) msgb_put(msg, sizeof(*sr));
|
||||||
sr->asserted = asserted;
|
sr->asserted = asserted;
|
||||||
sr->pulse_duration_msec = pulse_ms;
|
sr->pulse_duration_msec = pulse_ms;
|
||||||
@@ -310,6 +318,8 @@ static int _modem_sim_select(struct osmo_st2_slot *slot, uint8_t remote_sim)
|
|||||||
struct msgb *msg = st_msgb_alloc();
|
struct msgb *msg = st_msgb_alloc();
|
||||||
struct st_modem_sim_select *ss;
|
struct st_modem_sim_select *ss;
|
||||||
|
|
||||||
|
LOGSLOT(slot, LOGL_NOTICE, "<= %s(remote_sim=%u)\n", __func__, remote_sim);
|
||||||
|
|
||||||
ss = (struct st_modem_sim_select *) msgb_put(msg, sizeof(*ss));
|
ss = (struct st_modem_sim_select *) msgb_put(msg, sizeof(*ss));
|
||||||
ss->remote_sim = remote_sim;
|
ss->remote_sim = remote_sim;
|
||||||
|
|
||||||
|
|||||||
@@ -5,10 +5,12 @@ AM_LDFLAGS=$(COVERAGE_LDFLAGS)
|
|||||||
LDADD= $(top_builddir)/lib/libosmo-simtrace2.la \
|
LDADD= $(top_builddir)/lib/libosmo-simtrace2.la \
|
||||||
$(LIBOSMOCORE_LIBS) $(LIBOSMOSIM_LIBS) $(LIBOSMOUSB_LIBS) $(LIBUSB_LIBS)
|
$(LIBOSMOCORE_LIBS) $(LIBOSMOSIM_LIBS) $(LIBOSMOUSB_LIBS) $(LIBUSB_LIBS)
|
||||||
|
|
||||||
bin_PROGRAMS = simtrace2-cardem-pcsc simtrace2-list simtrace2-sniff
|
bin_PROGRAMS = simtrace2-cardem-pcsc simtrace2-list simtrace2-sniff simtrace2-tool
|
||||||
|
|
||||||
simtrace2_cardem_pcsc_SOURCES = simtrace2-cardem-pcsc.c
|
simtrace2_cardem_pcsc_SOURCES = simtrace2-cardem-pcsc.c
|
||||||
|
|
||||||
simtrace2_list_SOURCES = simtrace2_usb.c
|
simtrace2_list_SOURCES = simtrace2_usb.c
|
||||||
|
|
||||||
simtrace2_sniff_SOURCES = simtrace2-sniff.c
|
simtrace2_sniff_SOURCES = simtrace2-sniff.c
|
||||||
|
|
||||||
|
simtrace2_tool_SOURCES = simtrace2-tool.c
|
||||||
|
|||||||
338
host/src/simtrace2-tool.c
Normal file
338
host/src/simtrace2-tool.c
Normal file
@@ -0,0 +1,338 @@
|
|||||||
|
/* simtrace2-tool - main program for the host PC to provide a remote SIM
|
||||||
|
* using the SIMtrace 2 firmware in card emulation mode
|
||||||
|
*
|
||||||
|
* (C) 2019 by Harald Welte <hwelte@hmw-consulting.de>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#define _GNU_SOURCE
|
||||||
|
#include <getopt.h>
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <libusb.h>
|
||||||
|
|
||||||
|
#include <osmocom/usb/libusb.h>
|
||||||
|
#include <osmocom/simtrace2/simtrace2_api.h>
|
||||||
|
#include <osmocom/simtrace2/simtrace_prot.h>
|
||||||
|
#include <osmocom/simtrace2/gsmtap.h>
|
||||||
|
|
||||||
|
#include <osmocom/core/utils.h>
|
||||||
|
#include <osmocom/core/msgb.h>
|
||||||
|
|
||||||
|
/***********************************************************************
|
||||||
|
* Incoming Messages
|
||||||
|
***********************************************************************/
|
||||||
|
|
||||||
|
static void print_welcome(void)
|
||||||
|
{
|
||||||
|
printf("simtrace2-tool\n"
|
||||||
|
"(C) 2019 Harald Welte <laforge@gnumonks.org>\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void print_help(void)
|
||||||
|
{
|
||||||
|
printf( "simtrace2-tool [OPTIONS] COMMAND\n\n");
|
||||||
|
printf( "Options:\n"
|
||||||
|
"\t-h\t--help\n"
|
||||||
|
"\t-V\t--usb-vendor\tVENDOR_ID\n"
|
||||||
|
"\t-P\t--usb-product\tPRODUCT_ID\n"
|
||||||
|
"\t-C\t--usb-config\tCONFIG_ID\n"
|
||||||
|
"\t-I\t--usb-interface\tINTERFACE_ID\n"
|
||||||
|
"\t-S\t--usb-altsetting ALTSETTING_ID\n"
|
||||||
|
"\t-A\t--usb-address\tADDRESS\n"
|
||||||
|
"\t-H\t--usb-path\tPATH\n"
|
||||||
|
"\n"
|
||||||
|
);
|
||||||
|
printf( "Commands:\n"
|
||||||
|
"\tmodem reset (enable|disable|cycle)\n"
|
||||||
|
"\tmodem sim-switch (local|remote)\n"
|
||||||
|
"\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct option opts[] = {
|
||||||
|
{ "help", 0, 0, 'h' },
|
||||||
|
{ "usb-vendor", 1, 0, 'V' },
|
||||||
|
{ "usb-product", 1, 0, 'P' },
|
||||||
|
{ "usb-config", 1, 0, 'C' },
|
||||||
|
{ "usb-interface", 1, 0, 'I' },
|
||||||
|
{ "usb-altsetting", 1, 0, 'S' },
|
||||||
|
{ "usb-address", 1, 0, 'A' },
|
||||||
|
{ "usb-path", 1, 0, 'H' },
|
||||||
|
{ NULL, 0, 0, 0 }
|
||||||
|
};
|
||||||
|
|
||||||
|
static void run_mainloop(struct osmo_st2_cardem_inst *ci)
|
||||||
|
{
|
||||||
|
struct osmo_st2_transport *transp = ci->slot->transp;
|
||||||
|
uint8_t buf[16*265];
|
||||||
|
int xfer_len;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
/* read data from SIMtrace2 device */
|
||||||
|
rc = libusb_bulk_transfer(transp->usb_devh, transp->usb_ep.in,
|
||||||
|
buf, sizeof(buf), &xfer_len, 100);
|
||||||
|
if (rc < 0 && rc != LIBUSB_ERROR_TIMEOUT &&
|
||||||
|
rc != LIBUSB_ERROR_INTERRUPTED &&
|
||||||
|
rc != LIBUSB_ERROR_IO) {
|
||||||
|
fprintf(stderr, "BULK IN transfer error; rc=%d\n", rc);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
/* break the loop if no new messages arrive within 100ms */
|
||||||
|
if (rc == LIBUSB_ERROR_TIMEOUT)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct osmo_st2_transport _transp;
|
||||||
|
|
||||||
|
static struct osmo_st2_slot _slot = {
|
||||||
|
.transp = &_transp,
|
||||||
|
.slot_nr = 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct osmo_st2_cardem_inst _ci = {
|
||||||
|
.slot = &_slot,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct osmo_st2_cardem_inst *ci = &_ci;
|
||||||
|
|
||||||
|
/* perform a modem reset */
|
||||||
|
static int do_modem_reset(int argc, char **argv)
|
||||||
|
{
|
||||||
|
char *command;
|
||||||
|
if (argc < 1)
|
||||||
|
command = "cycle";
|
||||||
|
else {
|
||||||
|
command = argv[0];
|
||||||
|
argc--;
|
||||||
|
argv++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!strcmp(command, "enable")) {
|
||||||
|
printf("Activating Modem RESET\n");
|
||||||
|
return osmo_st2_modem_reset_active(ci->slot);
|
||||||
|
} else if (!strcmp(command, "disable")) {
|
||||||
|
printf("Deactivating Modem RESET\n");
|
||||||
|
return osmo_st2_modem_reset_inactive(ci->slot);
|
||||||
|
} else if (!strcmp(command, "cycle")) {
|
||||||
|
printf("Pulsing Modem RESET (1s)\n");
|
||||||
|
return osmo_st2_modem_reset_pulse(ci->slot, 1000);
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "Unsupported modem reset command: '%s'\n", command);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* switch between local and remote (emulated) SIM */
|
||||||
|
static int do_modem_sim_switch(int argc, char **argv)
|
||||||
|
{
|
||||||
|
char *command;
|
||||||
|
if (argc < 1)
|
||||||
|
return -EINVAL;
|
||||||
|
command = argv[0];
|
||||||
|
argc--;
|
||||||
|
argv++;
|
||||||
|
|
||||||
|
if (!strcmp(command, "local")) {
|
||||||
|
printf("Setting SIM=LOCAL; Modem reset recommended\n");
|
||||||
|
return osmo_st2_modem_sim_select_local(ci->slot);
|
||||||
|
} else if (!strcmp(command, "remote")) {
|
||||||
|
printf("Setting SIM=REMOTE; Modem reset recommended\n");
|
||||||
|
return osmo_st2_modem_sim_select_remote(ci->slot);
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "Unsupported modem sim-switch command: '%s'\n", command);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int do_subsys_modem(int argc, char **argv)
|
||||||
|
{
|
||||||
|
char *command;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
if (argc < 1)
|
||||||
|
return -EINVAL;
|
||||||
|
command = argv[0];
|
||||||
|
argc--;
|
||||||
|
argv++;
|
||||||
|
|
||||||
|
if (!strcmp(command, "reset")) {
|
||||||
|
rc = do_modem_reset(argc, argv);
|
||||||
|
} else if (!strcmp(command, "sim-switch")) {
|
||||||
|
rc = do_modem_sim_switch(argc, argv);
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "Unsupported command for subsystem modem: '%s'\n", command);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int do_command(int argc, char **argv)
|
||||||
|
{
|
||||||
|
char *subsys;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
if (argc < 1)
|
||||||
|
return -EINVAL;
|
||||||
|
subsys = argv[0];
|
||||||
|
argc--;
|
||||||
|
argv++;
|
||||||
|
|
||||||
|
if (!strcmp(subsys, "modem"))
|
||||||
|
rc = do_subsys_modem(argc, argv);
|
||||||
|
else {
|
||||||
|
fprintf(stderr, "Unsupported subsystem '%s'\n", subsys);
|
||||||
|
rc = -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
struct osmo_st2_transport *transp = ci->slot->transp;
|
||||||
|
int rc;
|
||||||
|
int c, ret = 1;
|
||||||
|
int if_num = 0, vendor_id = -1, product_id = -1;
|
||||||
|
int config_id = -1, altsetting = 0, addr = -1;
|
||||||
|
char *path = NULL;
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
int option_index = 0;
|
||||||
|
|
||||||
|
c = getopt_long(argc, argv, "hV:P:C:I:S:A:H:", opts, &option_index);
|
||||||
|
if (c == -1)
|
||||||
|
break;
|
||||||
|
switch (c) {
|
||||||
|
case 'h':
|
||||||
|
print_help();
|
||||||
|
exit(0);
|
||||||
|
break;
|
||||||
|
case 'V':
|
||||||
|
vendor_id = strtol(optarg, NULL, 16);
|
||||||
|
break;
|
||||||
|
case 'P':
|
||||||
|
product_id = strtol(optarg, NULL, 16);
|
||||||
|
break;
|
||||||
|
case 'C':
|
||||||
|
config_id = atoi(optarg);
|
||||||
|
break;
|
||||||
|
case 'I':
|
||||||
|
if_num = atoi(optarg);
|
||||||
|
break;
|
||||||
|
case 'S':
|
||||||
|
altsetting = atoi(optarg);
|
||||||
|
break;
|
||||||
|
case 'A':
|
||||||
|
addr = atoi(optarg);
|
||||||
|
break;
|
||||||
|
case 'H':
|
||||||
|
path = optarg;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((vendor_id < 0 || product_id < 0)) {
|
||||||
|
fprintf(stderr, "You have to specify the vendor and product ID\n");
|
||||||
|
goto do_exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
transp->udp_fd = -1;
|
||||||
|
|
||||||
|
rc = libusb_init(NULL);
|
||||||
|
if (rc < 0) {
|
||||||
|
fprintf(stderr, "libusb initialization failed\n");
|
||||||
|
goto do_exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
print_welcome();
|
||||||
|
|
||||||
|
do {
|
||||||
|
if (transp->udp_fd < 0) {
|
||||||
|
struct usb_interface_match _ifm, *ifm = &_ifm;
|
||||||
|
ifm->vendor = vendor_id;
|
||||||
|
ifm->product = product_id;
|
||||||
|
ifm->configuration = config_id;
|
||||||
|
ifm->interface = if_num;
|
||||||
|
ifm->altsetting = altsetting;
|
||||||
|
ifm->addr = addr;
|
||||||
|
if (path)
|
||||||
|
osmo_strlcpy(ifm->path, path, sizeof(ifm->path));
|
||||||
|
transp->usb_devh = osmo_libusb_open_claim_interface(NULL, NULL, ifm);
|
||||||
|
if (!transp->usb_devh) {
|
||||||
|
fprintf(stderr, "can't open USB device\n");
|
||||||
|
goto close_exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
rc = libusb_claim_interface(transp->usb_devh, if_num);
|
||||||
|
if (rc < 0) {
|
||||||
|
fprintf(stderr, "can't claim interface %d; rc=%d\n", if_num, rc);
|
||||||
|
goto close_exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
rc = osmo_libusb_get_ep_addrs(transp->usb_devh, if_num, &transp->usb_ep.out,
|
||||||
|
&transp->usb_ep.in, &transp->usb_ep.irq_in);
|
||||||
|
if (rc < 0) {
|
||||||
|
fprintf(stderr, "can't obtain EP addrs; rc=%d\n", rc);
|
||||||
|
goto close_exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argc - optind <= 0) {
|
||||||
|
fprintf(stderr, "You have to specify a command to execute\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
rc = do_command(argc-optind, argv+optind);
|
||||||
|
switch (rc) {
|
||||||
|
case 0:
|
||||||
|
break;
|
||||||
|
case -EINVAL:
|
||||||
|
fprintf(stderr, "Error: Invalid command/syntax\n");
|
||||||
|
exit(1);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fprintf(stderr, "Error executing command: %d\n", rc);
|
||||||
|
exit(1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
run_mainloop(ci);
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
|
libusb_release_interface(transp->usb_devh, 0);
|
||||||
|
close_exit:
|
||||||
|
if (transp->usb_devh)
|
||||||
|
libusb_close(transp->usb_devh);
|
||||||
|
} while (0);
|
||||||
|
|
||||||
|
libusb_exit(NULL);
|
||||||
|
do_exit:
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
@@ -25,13 +25,7 @@
|
|||||||
|
|
||||||
#include <osmocom/usb/libusb.h>
|
#include <osmocom/usb/libusb.h>
|
||||||
#include <osmocom/simtrace2/simtrace_usb.h>
|
#include <osmocom/simtrace2/simtrace_usb.h>
|
||||||
|
#include <osmocom/simtrace2/usb_util.h>
|
||||||
static const struct dev_id compatible_dev_ids[] = {
|
|
||||||
{ USB_VENDOR_OPENMOKO, USB_PRODUCT_OWHW_SAM3 },
|
|
||||||
{ USB_VENDOR_OPENMOKO, USB_PRODUCT_QMOD_SAM3 },
|
|
||||||
{ USB_VENDOR_OPENMOKO, USB_PRODUCT_SIMTRACE2 },
|
|
||||||
{ 0, 0 }
|
|
||||||
};
|
|
||||||
|
|
||||||
static int find_devices(void)
|
static int find_devices(void)
|
||||||
{
|
{
|
||||||
@@ -39,7 +33,7 @@ static int find_devices(void)
|
|||||||
int rc, i, num_interfaces;
|
int rc, i, num_interfaces;
|
||||||
|
|
||||||
/* scan for USB devices matching SIMtrace USB ID with proprietary class */
|
/* scan for USB devices matching SIMtrace USB ID with proprietary class */
|
||||||
rc = osmo_libusb_find_matching_interfaces(NULL, compatible_dev_ids,
|
rc = osmo_libusb_find_matching_interfaces(NULL, osmo_st2_compatible_dev_ids,
|
||||||
USB_CLASS_PROPRIETARY, -1, -1, ifm, ARRAY_SIZE(ifm));
|
USB_CLASS_PROPRIETARY, -1, -1, ifm, ARRAY_SIZE(ifm));
|
||||||
printf("USB matches: %d\n", rc);
|
printf("USB matches: %d\n", rc);
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user