blob: 0024f52dc533fc0ebb46f45d5cbafd188d9863e8 [file] [log] [blame]
Harald Welte24173fb2018-08-24 20:37:28 +02001#pragma once
2
Harald Welte8e46ab62020-02-14 12:55:43 +01003#include <osmocom/core/linuxlist.h>
Harald Welte24173fb2018-08-24 20:37:28 +02004#include <osmocom/core/fsm.h>
5#include <osmocom/abis/ipa.h>
Harald Weltef9995a32018-10-14 20:40:05 +02006#include <osmocom/rspro/RsproPDU.h>
Harald Welte24173fb2018-08-24 20:37:28 +02007
8#include "rspro_util.h"
Harald Welte3cded632019-03-09 12:59:41 +01009#include "rspro_client_fsm.h"
Harald Welte9cf013a2019-03-11 22:19:19 +010010#include "slotmap.h"
Harald Weltea4e0a232018-10-14 17:44:25 +020011#include "debug.h"
Harald Welte24173fb2018-08-24 20:37:28 +020012
Harald Welte0e968cc2020-02-22 18:16:16 +010013/***********************************************************************
14 * frontend interface
15 ***********************************************************************/
16
17struct bankd_client;
18
19struct frontend_phys_status {
20 struct {
21 /* all members can be 0 (inactive), 1 (active) or -1 (not supported/known) */
22 int reset_active;
23 int vcc_present;
24 int clk_active;
25 int card_present;
26 } flags;
27 uint16_t voltage_mv;
28 uint8_t fi;
29 uint8_t di;
30 uint8_t wi;
31 uint8_t waiting_time;
32};
33
34struct frontend_pts {
35 const uint8_t *buf;
36 size_t len;
37};
38
39struct frontend_tpdu {
40 const uint8_t *buf;
41 size_t len;
42};
43
44/* API from generic core to frontend (modem/cardem) */
45int frontend_request_card_insert(struct bankd_client *bc);
46int frontend_request_sim_remote(struct bankd_client *bc);
47int frontend_request_modem_reset(struct bankd_client *bc);
48int frontend_handle_card2modem(struct bankd_client *bc, const uint8_t *data, size_t len);
49int frontend_handle_set_atr(struct bankd_client *bc, const uint8_t *data, size_t len);
50int frontend_handle_slot_status(struct bankd_client *bc, const SlotPhysStatus_t *sts);
Harald Weltee580c932020-05-24 16:03:56 +020051int frontend_append_script_env(struct bankd_client *bc, char **env, int idx, size_t max_env);
Harald Welte0e968cc2020-02-22 18:16:16 +010052
Harald Welte24173fb2018-08-24 20:37:28 +020053/* main.c */
54
Harald Welte0e968cc2020-02-22 18:16:16 +010055struct osmo_st2_cardem_inst;
Harald Welte5ed46932019-12-17 00:02:36 +010056
Harald Welte6a0248b2019-12-17 01:11:24 +010057#define ATR_SIZE_MAX 55
58struct client_config {
59 char *server_host;
60 int server_port;
61
62 int client_id;
63 int client_slot;
64
65 char *gsmtap_host;
66 bool keep_running;
67
68 char *event_script;
69
70 struct {
71 uint8_t data[ATR_SIZE_MAX];
72 uint8_t len;
73 } atr;
74
75 struct {
76 int vendor_id;
77 int product_id;
78 int config_id;
79 int if_num;
80 int altsetting;
81 int addr;
82 char *path;
83 } usb;
84};
85
Harald Welte24173fb2018-08-24 20:37:28 +020086struct bankd_client {
87 /* connection to the remsim-server (control) */
Harald Weltee56f2b92019-03-02 17:02:13 +010088 struct rspro_server_conn srv_conn;
Harald Welte3e9860b2019-12-02 23:04:54 +010089 /* connection to the remsim-bankd (data) */
90 struct rspro_server_conn bankd_conn;
Harald Welte0e968cc2020-02-22 18:16:16 +010091 /* CLIENT_MAIN fsm */
92 struct osmo_fsm_inst *main_fi;
Harald Welte24173fb2018-08-24 20:37:28 +020093
Harald Weltee56f2b92019-03-02 17:02:13 +010094 /* remote component ID */
95 struct app_comp_id peer_comp_id;
Harald Welte24173fb2018-08-24 20:37:28 +020096
Harald Welte9cf013a2019-03-11 22:19:19 +010097 struct bank_slot bankd_slot;
Harald Welte5ed46932019-12-17 00:02:36 +010098
Harald Welte6a0248b2019-12-17 01:11:24 +010099 struct client_config *cfg;
Harald Welte0e968cc2020-02-22 18:16:16 +0100100 struct osmo_st2_cardem_inst *cardem;
101 struct frontend_phys_status last_status;
Harald Welte9fac4962020-02-14 21:01:23 +0100102 void *data;
Harald Welte24173fb2018-08-24 20:37:28 +0200103};
Harald Welte1200c822020-02-13 20:43:27 +0100104
Harald Welte8e46ab62020-02-14 12:55:43 +0100105#define srvc2bankd_client(srvc) container_of(srvc, struct bankd_client, srv_conn)
106#define bankdc2bankd_client(bdc) container_of(bdc, struct bankd_client, bankd_conn)
Harald Welte1200c822020-02-13 20:43:27 +0100107
Harald Welte0e968cc2020-02-22 18:16:16 +0100108struct client_config *client_config_init(void *ctx);
109struct bankd_client *remsim_client_create(void *ctx, const char *name, const char *software,
110 struct client_config *cfg);
Harald Welte879ee412020-02-14 14:21:33 +0100111void remsim_client_set_clslot(struct bankd_client *bc, int client_id, int slot_nr);
112
Harald Welte1200c822020-02-13 20:43:27 +0100113extern int client_user_main(struct bankd_client *g_client);
Harald Welte0e968cc2020-02-22 18:16:16 +0100114
115
116/***********************************************************************
117 * main FSM
118 ***********************************************************************/
119
120enum main_fsm_event {
121 MF_E_SRVC_CONNECTED, /* connection to server established (TCP + RSPRO level) */
122 MF_E_SRVC_LOST, /* connection to server was lost */
123 MF_E_SRVC_CONFIG_BANK, /* server instructs us to connect to bankd/slot */
124 MF_E_SRVC_RESET_REQ, /* RsproPDUchoice_PR_ResetStateReq */
125
126 MF_E_BANKD_CONNECTED, /* connection to bankd established (TCP + RSPRO level) */
127 MF_E_BANKD_LOST, /* connection to bankd was lost */
128 MF_E_BANKD_TPDU, /* RsproPDUchoice_PR_tpduCardToModem */
129 MF_E_BANKD_ATR, /* RsproPDUchoice_PR_setAtrReq */
130 MF_E_BANKD_SLOT_STATUS, /* bankSlotStatusInd */
131
132 MF_E_MDM_STATUS_IND, /* status from modem/cardem */
133 MF_E_MDM_PTS_IND, /* PTS indication from modem/cardem */
134 MF_E_MDM_TPDU, /* TPDU from modem/cardem */
135};
136struct osmo_fsm_inst *main_fsm_alloc(void *ctx, struct bankd_client *bc);
137
138
139