Harald Welte | 964cda3 | 2019-11-24 22:27:10 +0100 | [diff] [blame] | 1 | |
| 2 | /* simtrace2-protocol - USB protocol library code for SIMtrace2 |
| 3 | * |
| 4 | * (C) 2016-2019 by Harald Welte <hwelte@hmw-consulting.de> |
| 5 | * (C) 2018, sysmocom -s.f.m.c. GmbH, Author: Kevin Redon <kredon@sysmocom.de> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * as published by the Free Software Foundation; either version 2 |
| 10 | * of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 20 | */ |
| 21 | |
| 22 | #include <errno.h> |
| 23 | #include <unistd.h> |
| 24 | #include <stdio.h> |
| 25 | #include <stdlib.h> |
| 26 | #include <string.h> |
| 27 | #include <stdint.h> |
| 28 | #include <signal.h> |
| 29 | #include <time.h> |
| 30 | #define _GNU_SOURCE |
| 31 | #include <getopt.h> |
| 32 | |
| 33 | #include <sys/time.h> |
| 34 | #include <sys/types.h> |
| 35 | #include <sys/socket.h> |
| 36 | #include <netinet/in.h> |
| 37 | #include <arpa/inet.h> |
| 38 | |
| 39 | #include <libusb.h> |
| 40 | |
Harald Welte | 964cda3 | 2019-11-24 22:27:10 +0100 | [diff] [blame] | 41 | #include <osmocom/simtrace2/simtrace_prot.h> |
| 42 | #include <osmocom/simtrace2/simtrace2_api.h> |
Harald Welte | 964cda3 | 2019-11-24 22:27:10 +0100 | [diff] [blame] | 43 | |
| 44 | #include <osmocom/core/utils.h> |
| 45 | #include <osmocom/core/socket.h> |
| 46 | #include <osmocom/core/msgb.h> |
Harald Welte | dcfea28 | 2021-06-02 09:26:21 +0200 | [diff] [blame] | 47 | #include <osmocom/core/logging.h> |
Harald Welte | 964cda3 | 2019-11-24 22:27:10 +0100 | [diff] [blame] | 48 | #include <osmocom/sim/class_tables.h> |
| 49 | #include <osmocom/sim/sim.h> |
| 50 | |
Harald Welte | dcfea28 | 2021-06-02 09:26:21 +0200 | [diff] [blame] | 51 | #define LOGSLOT(slot, lvl, fmt, args...) \ |
| 52 | LOGP(DLINP, lvl, "[%u] " fmt, (slot)->slot_nr, ## args) |
| 53 | |
Harald Welte | 964cda3 | 2019-11-24 22:27:10 +0100 | [diff] [blame] | 54 | /*********************************************************************** |
| 55 | * SIMTRACE core protocol |
| 56 | ***********************************************************************/ |
| 57 | |
| 58 | /*! \brief allocate a message buffer for simtrace use */ |
| 59 | static struct msgb *st_msgb_alloc(void) |
| 60 | { |
| 61 | return msgb_alloc_headroom(1024+32, 32, "SIMtrace"); |
| 62 | } |
| 63 | |
Harald Welte | 859f1b0 | 2020-02-22 16:45:05 +0100 | [diff] [blame] | 64 | |
| 65 | static void usb_out_xfer_cb(struct libusb_transfer *xfer) |
Harald Welte | 964cda3 | 2019-11-24 22:27:10 +0100 | [diff] [blame] | 66 | { |
Harald Welte | 859f1b0 | 2020-02-22 16:45:05 +0100 | [diff] [blame] | 67 | struct msgb *msg = xfer->user_data; |
Harald Welte | 964cda3 | 2019-11-24 22:27:10 +0100 | [diff] [blame] | 68 | |
Harald Welte | 859f1b0 | 2020-02-22 16:45:05 +0100 | [diff] [blame] | 69 | switch (xfer->status) { |
| 70 | case LIBUSB_TRANSFER_COMPLETED: |
| 71 | break; |
| 72 | case LIBUSB_TRANSFER_NO_DEVICE: |
| 73 | fprintf(stderr, "USB device disappeared\n"); |
| 74 | exit(1); |
| 75 | break; |
| 76 | default: |
| 77 | fprintf(stderr, "USB OUT transfer failed, status=%u\n", xfer->status); |
| 78 | exit(1); |
| 79 | break; |
Harald Welte | 964cda3 | 2019-11-24 22:27:10 +0100 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | msgb_free(msg); |
Harald Welte | 859f1b0 | 2020-02-22 16:45:05 +0100 | [diff] [blame] | 83 | libusb_free_transfer(xfer); |
| 84 | } |
| 85 | |
| 86 | |
| 87 | static int st2_transp_tx_msg_usb_async(struct osmo_st2_transport *transp, struct msgb *msg) |
| 88 | { |
| 89 | struct libusb_transfer *xfer; |
| 90 | int rc; |
| 91 | |
| 92 | xfer = libusb_alloc_transfer(0); |
| 93 | OSMO_ASSERT(xfer); |
| 94 | xfer->dev_handle = transp->usb_devh; |
| 95 | xfer->flags = 0; |
| 96 | xfer->type = LIBUSB_TRANSFER_TYPE_BULK; |
| 97 | xfer->endpoint = transp->usb_ep.out; |
| 98 | xfer->timeout = 100000; |
| 99 | xfer->user_data = msg; |
| 100 | xfer->length = msgb_length(msg); |
| 101 | xfer->buffer = msgb_data(msg); |
| 102 | xfer->callback = usb_out_xfer_cb; |
| 103 | |
| 104 | rc = libusb_submit_transfer(xfer); |
| 105 | OSMO_ASSERT(rc == 0); |
| 106 | |
| 107 | return rc; |
| 108 | } |
| 109 | |
| 110 | /*! \brief Transmit a given command to the SIMtrace2 device */ |
| 111 | static int st2_transp_tx_msg_usb_sync(struct osmo_st2_transport *transp, struct msgb *msg) |
| 112 | { |
| 113 | int rc; |
| 114 | int xfer_len; |
| 115 | rc = libusb_bulk_transfer(transp->usb_devh, transp->usb_ep.out, |
| 116 | msgb_data(msg), msgb_length(msg), |
| 117 | &xfer_len, 100000); |
| 118 | msgb_free(msg); |
Harald Welte | 964cda3 | 2019-11-24 22:27:10 +0100 | [diff] [blame] | 119 | return rc; |
| 120 | } |
| 121 | |
| 122 | static struct simtrace_msg_hdr *st_push_hdr(struct msgb *msg, uint8_t msg_class, uint8_t msg_type, |
| 123 | uint8_t slot_nr) |
| 124 | { |
| 125 | struct simtrace_msg_hdr *sh; |
| 126 | |
| 127 | sh = (struct simtrace_msg_hdr *) msgb_push(msg, sizeof(*sh)); |
| 128 | memset(sh, 0, sizeof(*sh)); |
| 129 | sh->msg_class = msg_class; |
| 130 | sh->msg_type = msg_type; |
| 131 | sh->slot_nr = slot_nr; |
| 132 | sh->msg_len = msgb_length(msg); |
| 133 | |
| 134 | return sh; |
| 135 | } |
| 136 | |
| 137 | /* transmit a given message to a specified slot. Expects all headers |
| 138 | * present before calling the function */ |
Harald Welte | 208890a | 2019-11-24 22:46:51 +0100 | [diff] [blame] | 139 | int osmo_st2_slot_tx_msg(struct osmo_st2_slot *slot, struct msgb *msg, |
| 140 | uint8_t msg_class, uint8_t msg_type) |
Harald Welte | 964cda3 | 2019-11-24 22:27:10 +0100 | [diff] [blame] | 141 | { |
Harald Welte | 859f1b0 | 2020-02-22 16:45:05 +0100 | [diff] [blame] | 142 | struct osmo_st2_transport *transp = slot->transp; |
| 143 | int rc; |
Harald Welte | 964cda3 | 2019-11-24 22:27:10 +0100 | [diff] [blame] | 144 | |
Harald Welte | 859f1b0 | 2020-02-22 16:45:05 +0100 | [diff] [blame] | 145 | OSMO_ASSERT(transp); |
| 146 | |
| 147 | st_push_hdr(msg, msg_class, msg_type, slot->slot_nr); |
Harald Welte | 859f1b0 | 2020-02-22 16:45:05 +0100 | [diff] [blame] | 148 | |
| 149 | if (transp->udp_fd < 0) { |
| 150 | if (transp->usb_async) |
| 151 | rc = st2_transp_tx_msg_usb_async(transp, msg); |
| 152 | else |
| 153 | rc = st2_transp_tx_msg_usb_sync(transp, msg); |
| 154 | } else { |
| 155 | rc = write(transp->udp_fd, msgb_data(msg), msgb_length(msg)); |
| 156 | msgb_free(msg); |
| 157 | } |
| 158 | return rc; |
Harald Welte | 964cda3 | 2019-11-24 22:27:10 +0100 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | /*********************************************************************** |
| 162 | * Card Emulation protocol |
| 163 | ***********************************************************************/ |
| 164 | |
| 165 | |
| 166 | /*! \brief Request the SIMtrace2 to generate a card-insert signal */ |
Harald Welte | 208890a | 2019-11-24 22:46:51 +0100 | [diff] [blame] | 167 | int osmo_st2_cardem_request_card_insert(struct osmo_st2_cardem_inst *ci, bool inserted) |
Harald Welte | 964cda3 | 2019-11-24 22:27:10 +0100 | [diff] [blame] | 168 | { |
| 169 | struct msgb *msg = st_msgb_alloc(); |
| 170 | struct cardemu_usb_msg_cardinsert *cins; |
| 171 | |
Harald Welte | dcfea28 | 2021-06-02 09:26:21 +0200 | [diff] [blame] | 172 | LOGSLOT(ci->slot, LOGL_NOTICE, "<= %s(inserted=%d)\n", __func__, inserted); |
| 173 | |
Harald Welte | 964cda3 | 2019-11-24 22:27:10 +0100 | [diff] [blame] | 174 | cins = (struct cardemu_usb_msg_cardinsert *) msgb_put(msg, sizeof(*cins)); |
| 175 | memset(cins, 0, sizeof(*cins)); |
| 176 | if (inserted) |
| 177 | cins->card_insert = 1; |
| 178 | |
Harald Welte | 208890a | 2019-11-24 22:46:51 +0100 | [diff] [blame] | 179 | return osmo_st2_slot_tx_msg(ci->slot, msg, SIMTRACE_MSGC_CARDEM, SIMTRACE_MSGT_DT_CEMU_CARDINSERT); |
Harald Welte | 964cda3 | 2019-11-24 22:27:10 +0100 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | /*! \brief Request the SIMtrace2 to transmit a Procedure Byte, then Rx */ |
Harald Welte | 208890a | 2019-11-24 22:46:51 +0100 | [diff] [blame] | 183 | int osmo_st2_cardem_request_pb_and_rx(struct osmo_st2_cardem_inst *ci, uint8_t pb, uint8_t le) |
Harald Welte | 964cda3 | 2019-11-24 22:27:10 +0100 | [diff] [blame] | 184 | { |
| 185 | struct msgb *msg = st_msgb_alloc(); |
| 186 | struct cardemu_usb_msg_tx_data *txd; |
| 187 | txd = (struct cardemu_usb_msg_tx_data *) msgb_put(msg, sizeof(*txd)); |
| 188 | |
Harald Welte | dcfea28 | 2021-06-02 09:26:21 +0200 | [diff] [blame] | 189 | LOGSLOT(ci->slot, LOGL_DEBUG, "<= %s(pb=%02x, le=%u)\n", __func__, pb, le); |
Harald Welte | 964cda3 | 2019-11-24 22:27:10 +0100 | [diff] [blame] | 190 | |
| 191 | memset(txd, 0, sizeof(*txd)); |
| 192 | txd->data_len = 1; |
| 193 | txd->flags = CEMU_DATA_F_PB_AND_RX; |
| 194 | /* one data byte */ |
| 195 | msgb_put_u8(msg, pb); |
| 196 | |
Harald Welte | 208890a | 2019-11-24 22:46:51 +0100 | [diff] [blame] | 197 | return osmo_st2_slot_tx_msg(ci->slot, msg, SIMTRACE_MSGC_CARDEM, SIMTRACE_MSGT_DT_CEMU_TX_DATA); |
Harald Welte | 964cda3 | 2019-11-24 22:27:10 +0100 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | /*! \brief Request the SIMtrace2 to transmit a Procedure Byte, then Tx */ |
Harald Welte | 208890a | 2019-11-24 22:46:51 +0100 | [diff] [blame] | 201 | int osmo_st2_cardem_request_pb_and_tx(struct osmo_st2_cardem_inst *ci, uint8_t pb, |
| 202 | const uint8_t *data, uint16_t data_len_in) |
Harald Welte | 964cda3 | 2019-11-24 22:27:10 +0100 | [diff] [blame] | 203 | { |
| 204 | struct msgb *msg = st_msgb_alloc(); |
| 205 | struct cardemu_usb_msg_tx_data *txd; |
| 206 | uint8_t *cur; |
| 207 | |
| 208 | txd = (struct cardemu_usb_msg_tx_data *) msgb_put(msg, sizeof(*txd)); |
| 209 | |
Harald Welte | dcfea28 | 2021-06-02 09:26:21 +0200 | [diff] [blame] | 210 | LOGSLOT(ci->slot, LOGL_DEBUG, "<= %s(pb=%02x, tx=%s, len=%d)\n", __func__, pb, |
Harald Welte | 964cda3 | 2019-11-24 22:27:10 +0100 | [diff] [blame] | 211 | osmo_hexdump(data, data_len_in), data_len_in); |
| 212 | |
| 213 | memset(txd, 0, sizeof(*txd)); |
| 214 | txd->data_len = 1 + data_len_in; |
| 215 | txd->flags = CEMU_DATA_F_PB_AND_TX; |
| 216 | /* procedure byte */ |
| 217 | msgb_put_u8(msg, pb); |
| 218 | /* data */ |
| 219 | cur = msgb_put(msg, data_len_in); |
| 220 | memcpy(cur, data, data_len_in); |
| 221 | |
Harald Welte | 208890a | 2019-11-24 22:46:51 +0100 | [diff] [blame] | 222 | return osmo_st2_slot_tx_msg(ci->slot, msg, SIMTRACE_MSGC_CARDEM, SIMTRACE_MSGT_DT_CEMU_TX_DATA); |
Harald Welte | 964cda3 | 2019-11-24 22:27:10 +0100 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | /*! \brief Request the SIMtrace2 to send a Status Word */ |
Harald Welte | 208890a | 2019-11-24 22:46:51 +0100 | [diff] [blame] | 226 | int osmo_st2_cardem_request_sw_tx(struct osmo_st2_cardem_inst *ci, const uint8_t *sw) |
Harald Welte | 964cda3 | 2019-11-24 22:27:10 +0100 | [diff] [blame] | 227 | { |
| 228 | struct msgb *msg = st_msgb_alloc(); |
| 229 | struct cardemu_usb_msg_tx_data *txd; |
| 230 | uint8_t *cur; |
| 231 | |
| 232 | txd = (struct cardemu_usb_msg_tx_data *) msgb_put(msg, sizeof(*txd)); |
| 233 | |
Harald Welte | dcfea28 | 2021-06-02 09:26:21 +0200 | [diff] [blame] | 234 | LOGSLOT(ci->slot, LOGL_DEBUG, "<= %s(sw=%02x%02x)\n", __func__, sw[0], sw[1]); |
Harald Welte | 964cda3 | 2019-11-24 22:27:10 +0100 | [diff] [blame] | 235 | |
| 236 | memset(txd, 0, sizeof(*txd)); |
| 237 | txd->data_len = 2; |
| 238 | txd->flags = CEMU_DATA_F_PB_AND_TX | CEMU_DATA_F_FINAL; |
| 239 | cur = msgb_put(msg, 2); |
| 240 | cur[0] = sw[0]; |
| 241 | cur[1] = sw[1]; |
| 242 | |
Harald Welte | 208890a | 2019-11-24 22:46:51 +0100 | [diff] [blame] | 243 | return osmo_st2_slot_tx_msg(ci->slot, msg, SIMTRACE_MSGC_CARDEM, SIMTRACE_MSGT_DT_CEMU_TX_DATA); |
Harald Welte | 964cda3 | 2019-11-24 22:27:10 +0100 | [diff] [blame] | 244 | } |
| 245 | |
Harald Welte | 208890a | 2019-11-24 22:46:51 +0100 | [diff] [blame] | 246 | int osmo_st2_cardem_request_set_atr(struct osmo_st2_cardem_inst *ci, const uint8_t *atr, unsigned int atr_len) |
Harald Welte | 964cda3 | 2019-11-24 22:27:10 +0100 | [diff] [blame] | 247 | { |
| 248 | struct msgb *msg = st_msgb_alloc(); |
| 249 | struct cardemu_usb_msg_set_atr *satr; |
| 250 | uint8_t *cur; |
| 251 | |
| 252 | satr = (struct cardemu_usb_msg_set_atr *) msgb_put(msg, sizeof(*satr)); |
| 253 | |
Harald Welte | dcfea28 | 2021-06-02 09:26:21 +0200 | [diff] [blame] | 254 | LOGSLOT(ci->slot, LOGL_NOTICE, "<= %s(%s)\n", __func__, osmo_hexdump(atr, atr_len)); |
Harald Welte | 964cda3 | 2019-11-24 22:27:10 +0100 | [diff] [blame] | 255 | |
| 256 | memset(satr, 0, sizeof(*satr)); |
| 257 | satr->atr_len = atr_len; |
| 258 | cur = msgb_put(msg, atr_len); |
| 259 | memcpy(cur, atr, atr_len); |
| 260 | |
Harald Welte | 208890a | 2019-11-24 22:46:51 +0100 | [diff] [blame] | 261 | return osmo_st2_slot_tx_msg(ci->slot, msg, SIMTRACE_MSGC_CARDEM, SIMTRACE_MSGT_DT_CEMU_SET_ATR); |
Harald Welte | 964cda3 | 2019-11-24 22:27:10 +0100 | [diff] [blame] | 262 | } |
| 263 | |
Harald Welte | 0271237 | 2020-02-22 21:53:50 +0100 | [diff] [blame] | 264 | int osmo_st2_cardem_request_config(struct osmo_st2_cardem_inst *ci, uint32_t features) |
| 265 | { |
| 266 | struct msgb *msg = st_msgb_alloc(); |
| 267 | struct cardemu_usb_msg_config *cfg; |
| 268 | |
| 269 | cfg = (struct cardemu_usb_msg_config *) msgb_put(msg, sizeof(*cfg)); |
| 270 | |
Harald Welte | dcfea28 | 2021-06-02 09:26:21 +0200 | [diff] [blame] | 271 | LOGSLOT(ci->slot, LOGL_NOTICE, "<= %s(features=%08x)\n", __func__, features); |
Harald Welte | 0271237 | 2020-02-22 21:53:50 +0100 | [diff] [blame] | 272 | |
| 273 | memset(cfg, 0, sizeof(*cfg)); |
| 274 | cfg->features = features; |
| 275 | |
| 276 | return osmo_st2_slot_tx_msg(ci->slot, msg, SIMTRACE_MSGC_CARDEM, SIMTRACE_MSGT_BD_CEMU_CONFIG); |
| 277 | } |
| 278 | |
Harald Welte | 964cda3 | 2019-11-24 22:27:10 +0100 | [diff] [blame] | 279 | /*********************************************************************** |
| 280 | * Modem Control protocol |
| 281 | ***********************************************************************/ |
| 282 | |
Harald Welte | 208890a | 2019-11-24 22:46:51 +0100 | [diff] [blame] | 283 | static int _modem_reset(struct osmo_st2_slot *slot, uint8_t asserted, uint16_t pulse_ms) |
Harald Welte | 964cda3 | 2019-11-24 22:27:10 +0100 | [diff] [blame] | 284 | { |
| 285 | struct msgb *msg = st_msgb_alloc(); |
| 286 | struct st_modem_reset *sr ; |
| 287 | |
Harald Welte | dcfea28 | 2021-06-02 09:26:21 +0200 | [diff] [blame] | 288 | LOGSLOT(slot, LOGL_NOTICE, "<= %s(asserted=%u, pulse_ms=%u)\n", __func__, |
| 289 | asserted, pulse_ms); |
| 290 | |
Harald Welte | 964cda3 | 2019-11-24 22:27:10 +0100 | [diff] [blame] | 291 | sr = (struct st_modem_reset *) msgb_put(msg, sizeof(*sr)); |
| 292 | sr->asserted = asserted; |
| 293 | sr->pulse_duration_msec = pulse_ms; |
| 294 | |
Harald Welte | 208890a | 2019-11-24 22:46:51 +0100 | [diff] [blame] | 295 | return osmo_st2_slot_tx_msg(slot, msg, SIMTRACE_MSGC_MODEM, SIMTRACE_MSGT_DT_MODEM_RESET); |
Harald Welte | 964cda3 | 2019-11-24 22:27:10 +0100 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | /*! \brief pulse the RESET line of the modem for \a duration_ms milli-seconds*/ |
Harald Welte | 208890a | 2019-11-24 22:46:51 +0100 | [diff] [blame] | 299 | int osmo_st2_modem_reset_pulse(struct osmo_st2_slot *slot, uint16_t duration_ms) |
Harald Welte | 964cda3 | 2019-11-24 22:27:10 +0100 | [diff] [blame] | 300 | { |
| 301 | return _modem_reset(slot, 2, duration_ms); |
| 302 | } |
| 303 | |
| 304 | /*! \brief assert the RESET line of the modem */ |
Harald Welte | 208890a | 2019-11-24 22:46:51 +0100 | [diff] [blame] | 305 | int osmo_st2_modem_reset_active(struct osmo_st2_slot *slot) |
Harald Welte | 964cda3 | 2019-11-24 22:27:10 +0100 | [diff] [blame] | 306 | { |
| 307 | return _modem_reset(slot, 1, 0); |
| 308 | } |
| 309 | |
| 310 | /*! \brief de-assert the RESET line of the modem */ |
Harald Welte | 208890a | 2019-11-24 22:46:51 +0100 | [diff] [blame] | 311 | int osmo_st2_modem_reset_inactive(struct osmo_st2_slot *slot) |
Harald Welte | 964cda3 | 2019-11-24 22:27:10 +0100 | [diff] [blame] | 312 | { |
| 313 | return _modem_reset(slot, 0, 0); |
| 314 | } |
| 315 | |
Harald Welte | 208890a | 2019-11-24 22:46:51 +0100 | [diff] [blame] | 316 | static int _modem_sim_select(struct osmo_st2_slot *slot, uint8_t remote_sim) |
Harald Welte | 964cda3 | 2019-11-24 22:27:10 +0100 | [diff] [blame] | 317 | { |
| 318 | struct msgb *msg = st_msgb_alloc(); |
| 319 | struct st_modem_sim_select *ss; |
| 320 | |
Harald Welte | dcfea28 | 2021-06-02 09:26:21 +0200 | [diff] [blame] | 321 | LOGSLOT(slot, LOGL_NOTICE, "<= %s(remote_sim=%u)\n", __func__, remote_sim); |
| 322 | |
Harald Welte | 964cda3 | 2019-11-24 22:27:10 +0100 | [diff] [blame] | 323 | ss = (struct st_modem_sim_select *) msgb_put(msg, sizeof(*ss)); |
| 324 | ss->remote_sim = remote_sim; |
| 325 | |
Harald Welte | 208890a | 2019-11-24 22:46:51 +0100 | [diff] [blame] | 326 | return osmo_st2_slot_tx_msg(slot, msg, SIMTRACE_MSGC_MODEM, SIMTRACE_MSGT_DT_MODEM_SIM_SELECT); |
Harald Welte | 964cda3 | 2019-11-24 22:27:10 +0100 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | /*! \brief select local (physical) SIM for given slot */ |
Harald Welte | 208890a | 2019-11-24 22:46:51 +0100 | [diff] [blame] | 330 | int osmo_st2_modem_sim_select_local(struct osmo_st2_slot *slot) |
Harald Welte | 964cda3 | 2019-11-24 22:27:10 +0100 | [diff] [blame] | 331 | { |
| 332 | return _modem_sim_select(slot, 0); |
| 333 | } |
| 334 | |
| 335 | /*! \brief select remote (emulated/forwarded) SIM for given slot */ |
Harald Welte | 208890a | 2019-11-24 22:46:51 +0100 | [diff] [blame] | 336 | int osmo_st2_modem_sim_select_remote(struct osmo_st2_slot *slot) |
Harald Welte | 964cda3 | 2019-11-24 22:27:10 +0100 | [diff] [blame] | 337 | { |
| 338 | return _modem_sim_select(slot, 1); |
| 339 | } |
| 340 | |
| 341 | /*! \brief Request slot to send us status information about the modem */ |
Harald Welte | 208890a | 2019-11-24 22:46:51 +0100 | [diff] [blame] | 342 | int osmo_st2_modem_get_status(struct osmo_st2_slot *slot) |
Harald Welte | 964cda3 | 2019-11-24 22:27:10 +0100 | [diff] [blame] | 343 | { |
| 344 | struct msgb *msg = st_msgb_alloc(); |
| 345 | |
Harald Welte | 208890a | 2019-11-24 22:46:51 +0100 | [diff] [blame] | 346 | return osmo_st2_slot_tx_msg(slot, msg, SIMTRACE_MSGC_MODEM, SIMTRACE_MSGT_BD_MODEM_STATUS); |
Harald Welte | 964cda3 | 2019-11-24 22:27:10 +0100 | [diff] [blame] | 347 | } |