blob: 9cfdc5d2bba58af1b77977eb5d875c5952fae0bd [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);
Harald Welte7b87ba12021-09-08 21:38:35 +020046int frontend_request_card_remove(struct bankd_client *bc);
Harald Welte0e968cc2020-02-22 18:16:16 +010047int frontend_request_sim_remote(struct bankd_client *bc);
Harald Welte7b87ba12021-09-08 21:38:35 +020048int frontend_request_sim_local(struct bankd_client *bc);
Harald Welte0e968cc2020-02-22 18:16:16 +010049int frontend_request_modem_reset(struct bankd_client *bc);
50int frontend_handle_card2modem(struct bankd_client *bc, const uint8_t *data, size_t len);
51int frontend_handle_set_atr(struct bankd_client *bc, const uint8_t *data, size_t len);
52int frontend_handle_slot_status(struct bankd_client *bc, const SlotPhysStatus_t *sts);
Harald Weltee580c932020-05-24 16:03:56 +020053int frontend_append_script_env(struct bankd_client *bc, char **env, int idx, size_t max_env);
Harald Welte0e968cc2020-02-22 18:16:16 +010054
Harald Welte24173fb2018-08-24 20:37:28 +020055/* main.c */
56
Harald Welte0e968cc2020-02-22 18:16:16 +010057struct osmo_st2_cardem_inst;
Harald Welte5ed46932019-12-17 00:02:36 +010058
Harald Welte6a0248b2019-12-17 01:11:24 +010059#define ATR_SIZE_MAX 55
60struct client_config {
61 char *server_host;
62 int server_port;
63
64 int client_id;
65 int client_slot;
66
67 char *gsmtap_host;
68 bool keep_running;
69
70 char *event_script;
71
72 struct {
73 uint8_t data[ATR_SIZE_MAX];
74 uint8_t len;
75 } atr;
76
77 struct {
78 int vendor_id;
79 int product_id;
80 int config_id;
81 int if_num;
82 int altsetting;
83 int addr;
84 char *path;
85 } usb;
86};
87
Harald Welte24173fb2018-08-24 20:37:28 +020088struct bankd_client {
89 /* connection to the remsim-server (control) */
Harald Weltee56f2b92019-03-02 17:02:13 +010090 struct rspro_server_conn srv_conn;
Harald Welte3e9860b2019-12-02 23:04:54 +010091 /* connection to the remsim-bankd (data) */
92 struct rspro_server_conn bankd_conn;
Harald Welte0e968cc2020-02-22 18:16:16 +010093 /* CLIENT_MAIN fsm */
94 struct osmo_fsm_inst *main_fi;
Harald Welte24173fb2018-08-24 20:37:28 +020095
Harald Weltee56f2b92019-03-02 17:02:13 +010096 /* remote component ID */
97 struct app_comp_id peer_comp_id;
Harald Welte24173fb2018-08-24 20:37:28 +020098
Harald Welte9cf013a2019-03-11 22:19:19 +010099 struct bank_slot bankd_slot;
Harald Welte5ed46932019-12-17 00:02:36 +0100100
Harald Welte6a0248b2019-12-17 01:11:24 +0100101 struct client_config *cfg;
Harald Welte0e968cc2020-02-22 18:16:16 +0100102 struct osmo_st2_cardem_inst *cardem;
103 struct frontend_phys_status last_status;
Harald Welte9fac4962020-02-14 21:01:23 +0100104 void *data;
Harald Welte24173fb2018-08-24 20:37:28 +0200105};
Harald Welte1200c822020-02-13 20:43:27 +0100106
Harald Welte8e46ab62020-02-14 12:55:43 +0100107#define srvc2bankd_client(srvc) container_of(srvc, struct bankd_client, srv_conn)
108#define bankdc2bankd_client(bdc) container_of(bdc, struct bankd_client, bankd_conn)
Harald Welte1200c822020-02-13 20:43:27 +0100109
Harald Welte0e968cc2020-02-22 18:16:16 +0100110struct client_config *client_config_init(void *ctx);
111struct bankd_client *remsim_client_create(void *ctx, const char *name, const char *software,
112 struct client_config *cfg);
Harald Welte879ee412020-02-14 14:21:33 +0100113void remsim_client_set_clslot(struct bankd_client *bc, int client_id, int slot_nr);
114
Harald Welte1200c822020-02-13 20:43:27 +0100115extern int client_user_main(struct bankd_client *g_client);
Harald Welte0e968cc2020-02-22 18:16:16 +0100116
117
118/***********************************************************************
119 * main FSM
120 ***********************************************************************/
121
122enum main_fsm_event {
123 MF_E_SRVC_CONNECTED, /* connection to server established (TCP + RSPRO level) */
124 MF_E_SRVC_LOST, /* connection to server was lost */
125 MF_E_SRVC_CONFIG_BANK, /* server instructs us to connect to bankd/slot */
126 MF_E_SRVC_RESET_REQ, /* RsproPDUchoice_PR_ResetStateReq */
127
128 MF_E_BANKD_CONNECTED, /* connection to bankd established (TCP + RSPRO level) */
129 MF_E_BANKD_LOST, /* connection to bankd was lost */
130 MF_E_BANKD_TPDU, /* RsproPDUchoice_PR_tpduCardToModem */
131 MF_E_BANKD_ATR, /* RsproPDUchoice_PR_setAtrReq */
132 MF_E_BANKD_SLOT_STATUS, /* bankSlotStatusInd */
133
134 MF_E_MDM_STATUS_IND, /* status from modem/cardem */
135 MF_E_MDM_PTS_IND, /* PTS indication from modem/cardem */
136 MF_E_MDM_TPDU, /* TPDU from modem/cardem */
137};
138struct osmo_fsm_inst *main_fsm_alloc(void *ctx, struct bankd_client *bc);
139
140
141