host: use autotools and split shared code to libosmo-simtrace2

Change-Id: I57e77f927ee9e169cc794c5dc6b128a2d590201b
This commit is contained in:
Harald Welte
2019-11-24 22:27:10 +01:00
parent 331fa5a237
commit 964cda309d
31 changed files with 791 additions and 382 deletions

7
host/include/Makefile.am Normal file
View File

@@ -0,0 +1,7 @@
nobase_include_HEADERS = \
osmocom/simtrace2/apdu_dispatch.h \
osmocom/simtrace2/libusb_util.h \
osmocom/simtrace2/simtrace2_api.h \
osmocom/simtrace2/simtrace_usb.h \
osmocom/simtrace2/simtrace_prot.h \
osmocom/simtrace2/gsmtap.h

View File

@@ -0,0 +1,49 @@
/* apdu_dispatch - State machine to determine Rx/Tx phases of APDU
*
* (C) 2016 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.
*/
#pragma once
#include <stdint.h>
#include <stdbool.h>
#include <osmocom/sim/sim.h>
struct apdu_context {
struct osim_apdu_cmd_hdr hdr;
uint8_t dc[256];
uint8_t de[256];
uint8_t sw[2];
uint8_t apdu_case;
struct {
uint8_t tot;
uint8_t cur;
} lc;
struct {
uint8_t tot;
uint8_t cur;
} le;
};
enum apdu_action {
APDU_ACT_TX_CAPDU_TO_CARD = 0x0001,
APDU_ACT_RX_MORE_CAPDU_FROM_READER = 0x0002,
};
int apdu_segment_in(struct apdu_context *ac, const uint8_t *apdu_buf,
unsigned int apdu_len, bool new_apdu);

View File

@@ -0,0 +1,6 @@
#pragma once
#include <stdint.h>
#include <osmocom/core/gsmtap.h>
int osmo_st2_gsmtap_init(const char *gsmtap_host);
int osmo_st2_gsmtap_send_apdu(uint8_t sub_type, const uint8_t *apdu, unsigned int len);

View File

@@ -0,0 +1,70 @@
/* libisb utilities
*
* (C) 2010-2016 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.
*/
#pragma once
#include <libusb.h>
#define USB_MAX_PATH_LEN 20
struct dev_id {
uint16_t vendor_id;
uint16_t product_id;
};
/* Find any USB devices in the system matching the given Vendor and
* Product ID */
libusb_device **find_matching_usb_devs(const struct dev_id *dev_ids);
/* structure describing a single matching interface found */
struct usb_interface_match {
/* libusb device E*/
libusb_device *usb_dev;
/* Vendor ID of the device running matching interface */
uint16_t vendor;
/* Product ID of the device running matching interface */
uint16_t product;
/* USB Bus Address */
uint8_t addr;
/* physical path */
char path[USB_MAX_PATH_LEN];
/* configuration of matching interface */
uint8_t configuration;
/* interface number of matching interface */
uint8_t interface;
/* altsetting of matching interface */
uint8_t altsetting;
/* bInterfaceClass of matching interface */
uint8_t class;
/* bInterfaceSubClass of matching interface */
uint8_t sub_class;
/* bInterfaceProtocol of matching interface */
uint8_t protocol;
/* index of string descriptor of matching interface */
uint8_t string_idx;
};
int dev_find_matching_interfaces(libusb_device *dev, int class, int sub_class, int protocol,
struct usb_interface_match *out, unsigned int out_len);
int usb_match_interfaces(libusb_context *ctx, const struct dev_id *dev_ids,
int class, int sub_class, int protocol,
struct usb_interface_match *out, unsigned int out_len);
libusb_device_handle *usb_open_claim_interface(libusb_context *ctx,
const struct usb_interface_match *ifm);

View File

@@ -0,0 +1,52 @@
#pragma once
#include <stdint.h>
#include <osmocom/sim/sim.h>
/* transport to a SIMtrace device */
struct st_transport {
/* USB */
struct libusb_device_handle *usb_devh;
struct {
uint8_t in;
uint8_t out;
uint8_t irq_in;
} usb_ep;
/* UDP */
int udp_fd;
};
/* a SIMtrace slot; communicates over a transport */
struct st_slot {
/* transport through which the slot can be reached */
struct st_transport *transp;
/* number of the slot within the transport */
uint8_t slot_nr;
};
/* One istance of card emulation */
struct cardem_inst {
/* slot on which this card emulation instance runs */
struct st_slot *slot;
/* libosmosim SIM card profile */
const struct osim_cla_ins_card_profile *card_prof;
/* libosmosim SIM card channel */
struct osim_chan_hdl *chan;
};
int cardem_request_card_insert(struct cardem_inst *ci, bool inserted);
int cardem_request_pb_and_rx(struct cardem_inst *ci, uint8_t pb, uint8_t le);
int cardem_request_pb_and_tx(struct cardem_inst *ci, uint8_t pb,
const uint8_t *data, uint16_t data_len_in);
int cardem_request_sw_tx(struct cardem_inst *ci, const uint8_t *sw);
int cardem_request_set_atr(struct cardem_inst *ci, const uint8_t *atr, unsigned int atr_len);
int st_modem_reset_pulse(struct st_slot *slot, uint16_t duration_ms);
int st_modem_reset_active(struct st_slot *slot);
int st_modem_reset_inactive(struct st_slot *slot);
int st_modem_sim_select_local(struct st_slot *slot);
int st_modem_sim_select_remote(struct st_slot *slot);
int st_modem_get_status(struct st_slot *slot);

View File

@@ -0,0 +1 @@
../../../../firmware/libcommon/include/simtrace_prot.h

View File

@@ -0,0 +1 @@
../../../../firmware/libcommon/include/simtrace_usb.h