Harald Welte | 24173fb | 2018-08-24 20:37:28 +0200 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Harald Welte | 8e46ab6 | 2020-02-14 12:55:43 +0100 | [diff] [blame] | 3 | #include <osmocom/core/linuxlist.h> |
Harald Welte | 24173fb | 2018-08-24 20:37:28 +0200 | [diff] [blame] | 4 | #include <osmocom/core/fsm.h> |
| 5 | #include <osmocom/abis/ipa.h> |
Harald Welte | f9995a3 | 2018-10-14 20:40:05 +0200 | [diff] [blame] | 6 | #include <osmocom/rspro/RsproPDU.h> |
Harald Welte | 24173fb | 2018-08-24 20:37:28 +0200 | [diff] [blame] | 7 | |
| 8 | #include "rspro_util.h" |
Harald Welte | 3cded63 | 2019-03-09 12:59:41 +0100 | [diff] [blame] | 9 | #include "rspro_client_fsm.h" |
Harald Welte | 9cf013a | 2019-03-11 22:19:19 +0100 | [diff] [blame] | 10 | #include "slotmap.h" |
Harald Welte | a4e0a23 | 2018-10-14 17:44:25 +0200 | [diff] [blame] | 11 | #include "debug.h" |
Harald Welte | 24173fb | 2018-08-24 20:37:28 +0200 | [diff] [blame] | 12 | |
Harald Welte | 0e968cc | 2020-02-22 18:16:16 +0100 | [diff] [blame] | 13 | /*********************************************************************** |
| 14 | * frontend interface |
| 15 | ***********************************************************************/ |
| 16 | |
| 17 | struct bankd_client; |
| 18 | |
| 19 | struct 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 | |
| 34 | struct frontend_pts { |
| 35 | const uint8_t *buf; |
| 36 | size_t len; |
| 37 | }; |
| 38 | |
| 39 | struct frontend_tpdu { |
| 40 | const uint8_t *buf; |
| 41 | size_t len; |
| 42 | }; |
| 43 | |
| 44 | /* API from generic core to frontend (modem/cardem) */ |
| 45 | int frontend_request_card_insert(struct bankd_client *bc); |
| 46 | int frontend_request_sim_remote(struct bankd_client *bc); |
| 47 | int frontend_request_modem_reset(struct bankd_client *bc); |
| 48 | int frontend_handle_card2modem(struct bankd_client *bc, const uint8_t *data, size_t len); |
| 49 | int frontend_handle_set_atr(struct bankd_client *bc, const uint8_t *data, size_t len); |
| 50 | int frontend_handle_slot_status(struct bankd_client *bc, const SlotPhysStatus_t *sts); |
| 51 | int frontend_append_script_env(struct bankd_client *bc, char **env, size_t max_env); |
| 52 | |
Harald Welte | 24173fb | 2018-08-24 20:37:28 +0200 | [diff] [blame] | 53 | /* main.c */ |
| 54 | |
Harald Welte | 0e968cc | 2020-02-22 18:16:16 +0100 | [diff] [blame] | 55 | struct osmo_st2_cardem_inst; |
Harald Welte | 5ed4693 | 2019-12-17 00:02:36 +0100 | [diff] [blame] | 56 | |
Harald Welte | 6a0248b | 2019-12-17 01:11:24 +0100 | [diff] [blame] | 57 | #define ATR_SIZE_MAX 55 |
| 58 | struct 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 Welte | 24173fb | 2018-08-24 20:37:28 +0200 | [diff] [blame] | 86 | struct bankd_client { |
| 87 | /* connection to the remsim-server (control) */ |
Harald Welte | e56f2b9 | 2019-03-02 17:02:13 +0100 | [diff] [blame] | 88 | struct rspro_server_conn srv_conn; |
Harald Welte | 3e9860b | 2019-12-02 23:04:54 +0100 | [diff] [blame] | 89 | /* connection to the remsim-bankd (data) */ |
| 90 | struct rspro_server_conn bankd_conn; |
Harald Welte | 0e968cc | 2020-02-22 18:16:16 +0100 | [diff] [blame] | 91 | /* CLIENT_MAIN fsm */ |
| 92 | struct osmo_fsm_inst *main_fi; |
Harald Welte | 24173fb | 2018-08-24 20:37:28 +0200 | [diff] [blame] | 93 | |
Harald Welte | e56f2b9 | 2019-03-02 17:02:13 +0100 | [diff] [blame] | 94 | /* remote component ID */ |
| 95 | struct app_comp_id peer_comp_id; |
Harald Welte | 24173fb | 2018-08-24 20:37:28 +0200 | [diff] [blame] | 96 | |
Harald Welte | 9cf013a | 2019-03-11 22:19:19 +0100 | [diff] [blame] | 97 | struct bank_slot bankd_slot; |
Harald Welte | 5ed4693 | 2019-12-17 00:02:36 +0100 | [diff] [blame] | 98 | |
Harald Welte | 6a0248b | 2019-12-17 01:11:24 +0100 | [diff] [blame] | 99 | struct client_config *cfg; |
Harald Welte | 0e968cc | 2020-02-22 18:16:16 +0100 | [diff] [blame] | 100 | struct osmo_st2_cardem_inst *cardem; |
| 101 | struct frontend_phys_status last_status; |
Harald Welte | 9fac496 | 2020-02-14 21:01:23 +0100 | [diff] [blame] | 102 | void *data; |
Harald Welte | 24173fb | 2018-08-24 20:37:28 +0200 | [diff] [blame] | 103 | }; |
Harald Welte | 1200c82 | 2020-02-13 20:43:27 +0100 | [diff] [blame] | 104 | |
Harald Welte | 8e46ab6 | 2020-02-14 12:55:43 +0100 | [diff] [blame] | 105 | #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 Welte | 1200c82 | 2020-02-13 20:43:27 +0100 | [diff] [blame] | 107 | |
Harald Welte | 0e968cc | 2020-02-22 18:16:16 +0100 | [diff] [blame] | 108 | struct client_config *client_config_init(void *ctx); |
| 109 | struct bankd_client *remsim_client_create(void *ctx, const char *name, const char *software, |
| 110 | struct client_config *cfg); |
Harald Welte | 879ee41 | 2020-02-14 14:21:33 +0100 | [diff] [blame] | 111 | void remsim_client_set_clslot(struct bankd_client *bc, int client_id, int slot_nr); |
| 112 | |
Harald Welte | 1200c82 | 2020-02-13 20:43:27 +0100 | [diff] [blame] | 113 | extern int client_user_main(struct bankd_client *g_client); |
Harald Welte | 0e968cc | 2020-02-22 18:16:16 +0100 | [diff] [blame] | 114 | |
| 115 | |
| 116 | /*********************************************************************** |
| 117 | * main FSM |
| 118 | ***********************************************************************/ |
| 119 | |
| 120 | enum 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 | }; |
| 136 | struct osmo_fsm_inst *main_fsm_alloc(void *ctx, struct bankd_client *bc); |
| 137 | |
| 138 | |
| 139 | |