Split "RSPRO client FSM" from "BANKD client FSM"

This allows the RSPRO client FSM to be used by both remsim-client
as well as remsim-bankd -- both of which connect as RSPRO client to
remsim-server.

Change-Id: I57b5f8dc9de522b6ae8ceb030e639b5b8001b55a
This commit is contained in:
Harald Welte 2019-03-09 12:56:35 +01:00
parent 228af8a19b
commit 707c85a49b
7 changed files with 336 additions and 258 deletions

View File

@ -12,7 +12,7 @@ libosmo_rspro_la_LIBADD = $(OSMOCORE_LIBS) $(OSMOGSM_LIBS) $(OSMOABIS_LIBS) \
rspro/libosmo-asn1-rspro.la
libosmo_rspro_la_SOURCES = rspro_util.c
noinst_HEADERS = debug.h bankd.h client.h internal.h rspro_util.h slotmap.h \
noinst_HEADERS = debug.h bankd.h client.h internal.h rspro_util.h slotmap.h remsim_client_fsm.h \
simtrace2/apdu_dispatch.h \
simtrace2/libusb_util.h \
simtrace2/simtrace2-discovery.h \
@ -25,15 +25,16 @@ pcsc_test_SOURCES = driver_core.c driver_pcsc.c main.c
pcsc_test_LDADD = $(OSMOCORE_LIBS) \
$(PCSC_LIBS) libosmo-rspro.la
remsim_bankd_SOURCES = slotmap.c bankd_main.c bankd_pcsc.c debug.c
remsim_bankd_LDADD = $(OSMOCORE_LIBS) $(OSMOGSM_LIBS) \
remsim_bankd_SOURCES = slotmap.c bankd_main.c bankd_pcsc.c remsim_client_fsm.c debug.c
remsim_bankd_LDADD = $(OSMOCORE_LIBS) $(OSMOGSM_LIBS) $(OSMOABIS_LIBS) \
$(PCSC_LIBS) libosmo-rspro.la -lcsv
remsim_client_SOURCES = remsim_client.c remsim_client_fsm.c debug.c
remsim_client_SOURCES = remsim_client.c remsim_client_fsm.c bankd_client_fsm.c debug.c
remsim_client_LDADD = $(OSMOCORE_LIBS) $(OSMOGSM_LIBS) $(OSMOABIS_LIBS) \
libosmo-rspro.la
simtrace2_remsim_client_SOURCES = simtrace2-remsim_client.c remsim_client_fsm.c debug.c \
simtrace2_remsim_client_SOURCES = simtrace2-remsim_client.c \
bankd_client_fsm.c remsim_client_fsm.c debug.c \
simtrace2/apdu_dispatch.c \
simtrace2/simtrace2-discovery.c \
simtrace2/libusb_util.c

View File

@ -14,6 +14,7 @@
#include "rspro_util.h"
#include "slotmap.h"
#include "client.h"
#include "debug.h"
struct bankd;
@ -85,6 +86,8 @@ struct bankd {
} cfg;
struct app_comp_id comp_id;
/* RSPRO connection to the remsim-server */
struct rspro_server_conn srvc;
/* TCP socket at which we are listening */
int accept_fd;

230
src/bankd_client_fsm.c Normal file
View File

@ -0,0 +1,230 @@
#include <stdint.h>
#include <string.h>
#include <errno.h>
#include <talloc.h>
#include <osmocom/core/logging.h>
#include <osmocom/core/utils.h>
#include <osmocom/core/msgb.h>
#include <osmocom/core/fsm.h>
#include <osmocom/abis/ipa.h>
#include <osmocom/gsm/protocol/ipaccess.h>
#include "client.h"
#include "rspro_util.h"
#define S(x) (1 << (x))
static void bankd_updown_cb(struct ipa_client_conn *conn, int up)
{
struct bankd_client *bc = conn->data;
printf("RSPRO link to %s:%d %s\n", conn->addr, conn->port, up ? "UP" : "DOWN");
osmo_fsm_inst_dispatch(bc->bankd_fi, up ? BDC_E_TCP_UP: BDC_E_TCP_DOWN, 0);
}
/***********************************************************************
* bankd connection FSM: Remsim Client connection to Bankd
***********************************************************************/
enum bankd_conn_fsm_state {
/* waiting for initial connectiong to remsim-bankd */
BDC_ST_INIT,
/* bankd connection established, waiting for ClientConnectRes */
BDC_ST_ESTABLISHED,
/* bankd connection etsablished, ClientConnect succeeded */
BDC_ST_CONNECTED,
/* connection lost, we're waiting for a re-establish */
BDC_ST_REESTABLISH,
};
static const struct value_string remsim_client_bankd_fsm_event_names[] = {
OSMO_VALUE_STRING(BDC_E_ESTABLISH),
OSMO_VALUE_STRING(BDC_E_TCP_UP),
OSMO_VALUE_STRING(BDC_E_TCP_DOWN),
OSMO_VALUE_STRING(BDC_E_CLIENT_CONN_RES),
{ 0, NULL }
};
#define T1_WAIT_CLIENT_CONN_RES 10
#define T2_RECONNECT 10
static void bdc_st_init(struct osmo_fsm_inst *fi, uint32_t event, void *data)
{
switch (event) {
case BDC_E_ESTABLISH:
osmo_fsm_inst_state_chg(fi, BDC_ST_REESTABLISH, T2_RECONNECT, 2);
break;
default:
OSMO_ASSERT(0);
}
}
static void bdc_st_established_onenter(struct osmo_fsm_inst *fi, uint32_t prev_state)
{
struct bankd_client *bc = (struct bankd_client *) fi->priv;
RsproPDU_t *pdu;
/* FIXME: Send ClientConnReq */
pdu = rspro_gen_ConnectClientReq(&bc->srv_conn.own_comp_id, bc->srv_conn.clslot);
ipa_client_conn_send_rspro(bc->bankd_conn, pdu);
}
static void bdc_st_established(struct osmo_fsm_inst *fi, uint32_t event, void *data)
{
switch (event) {
case BDC_E_TCP_DOWN:
osmo_fsm_inst_state_chg(fi, BDC_ST_REESTABLISH, T2_RECONNECT, 2);
break;
case BDC_E_CLIENT_CONN_RES:
/* somehow notify the main code? */
osmo_fsm_inst_state_chg(fi, BDC_ST_CONNECTED, 0, 0);
break;
default:
OSMO_ASSERT(0);
}
}
static void bdc_st_connected(struct osmo_fsm_inst *fi, uint32_t event, void *data)
{
switch (event) {
case BDC_E_TCP_DOWN:
osmo_fsm_inst_state_chg(fi, BDC_ST_REESTABLISH, T2_RECONNECT, 2);
break;
default:
OSMO_ASSERT(0);
}
}
static void bdc_st_reestablish_onenter(struct osmo_fsm_inst *fi, uint32_t prev_state)
{
struct bankd_client *bc = (struct bankd_client *) fi->priv;
int rc;
/* re-create bankd_conn */
if (bc->bankd_conn) {
LOGPFSML(fi, LOGL_INFO, "Destroying existing connection to bankd\n");
ipa_client_conn_destroy(bc->bankd_conn);
bc->bankd_conn = NULL;
}
LOGPFSML(fi, LOGL_INFO, "Creating TCP connection to bankd at %s:%u\n",
bc->bankd_host, bc->bankd_port);
bc->bankd_conn = ipa_client_conn_create(bc, NULL, 0, bc->bankd_host, bc->bankd_port,
bankd_updown_cb, bankd_read_cb, NULL, bc);
if (!bc->bankd_conn) {
fprintf(stderr, "Unable to create socket: %s\n", strerror(errno));
exit(1);
}
/* Attempt to connect TCP socket */
rc = ipa_client_conn_open(bc->bankd_conn);
if (rc < 0) {
fprintf(stderr, "Unable to connect RSPRO to %s:%d - %s\n",
bc->bankd_conn->addr, bc->bankd_conn->port, strerror(errno));
/* FIXME: retry? Timer? Abort? */
OSMO_ASSERT(0);
}
}
static void bdc_st_reestablish(struct osmo_fsm_inst *fi, uint32_t event, void *data)
{
switch (event) {
case BDC_E_TCP_UP:
osmo_fsm_inst_state_chg(fi, BDC_ST_ESTABLISHED, T1_WAIT_CLIENT_CONN_RES, 1);
break;
case BDC_E_TCP_DOWN:
/* wait for normal T2 timeout */
break;
default:
OSMO_ASSERT(0);
}
}
static void bdc_allstate_action(struct osmo_fsm_inst *fi, uint32_t event, void *data)
{
switch (event) {
case BDC_ST_REESTABLISH:
osmo_fsm_inst_state_chg(fi, BDC_ST_REESTABLISH, T2_RECONNECT, 2);
break;
default:
OSMO_ASSERT(0);
}
}
static int remsim_client_bankd_fsm_timer_cb(struct osmo_fsm_inst *fi)
{
switch (fi->T) {
case 2:
/* TCP reconnect failed: retry */
osmo_fsm_inst_state_chg(fi, BDC_ST_REESTABLISH, T2_RECONNECT, 2);
break;
case 1:
/* no ClientConnectRes received: disconnect + reconnect */
osmo_fsm_inst_state_chg(fi, BDC_ST_REESTABLISH, T2_RECONNECT, 2);
break;
default:
OSMO_ASSERT(0);
}
return 0;
}
static const struct osmo_fsm_state bankd_conn_fsm_states[] = {
[BDC_ST_INIT] = {
.name = "INIT",
.in_event_mask = 0, /* S(BDC_E_ESTABLISH) via allstate */
.out_state_mask = S(BDC_ST_REESTABLISH),
.action = bdc_st_init,
},
[BDC_ST_ESTABLISHED] = {
.name = "ESTABLISHED",
.in_event_mask = S(BDC_E_TCP_DOWN) | S(BDC_E_CLIENT_CONN_RES),
.out_state_mask = S(BDC_ST_CONNECTED) | S(BDC_ST_REESTABLISH),
.action = bdc_st_established,
.onenter = bdc_st_established_onenter,
},
[BDC_ST_CONNECTED] = {
.name = "CONNECTED",
.in_event_mask = S(BDC_E_TCP_DOWN),
.out_state_mask = S(BDC_ST_REESTABLISH),
.action = bdc_st_connected,
},
[BDC_ST_REESTABLISH] = {
.name = "REESTABLISH",
.in_event_mask = S(BDC_E_TCP_UP) | S(BDC_E_TCP_DOWN),
.out_state_mask = S(BDC_ST_ESTABLISHED) | S(BDC_ST_REESTABLISH),
.action = bdc_st_reestablish,
.onenter = bdc_st_reestablish_onenter,
},
};
struct osmo_fsm remsim_client_bankd_fsm = {
.name = "BANKD_CONN",
.states = bankd_conn_fsm_states,
.num_states = ARRAY_SIZE(bankd_conn_fsm_states),
.allstate_event_mask = S(BDC_E_ESTABLISH),
.allstate_action = bdc_allstate_action,
.timer_cb = remsim_client_bankd_fsm_timer_cb,
.log_subsys = DMAIN,
.event_names = remsim_client_bankd_fsm_event_names,
};
int bankd_conn_fsm_alloc(struct bankd_client *bc)
{
struct osmo_fsm_inst *fi;
fi = osmo_fsm_inst_alloc(&remsim_client_bankd_fsm, bc, bc, LOGL_DEBUG, "bankd");
if (!fi)
return -1;
bc->bankd_fi = fi;
return 0;
}
static __attribute__((constructor)) void on_dso_load(void)
{
osmo_fsm_register(&remsim_client_bankd_fsm);
}

View File

@ -4,6 +4,7 @@
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <errno.h>
#include <pthread.h>
@ -26,6 +27,7 @@
#include <osmocom/rspro/RsproPDU.h>
#include "bankd.h"
#include "remsim_client_fsm.h"
#include "debug.h"
#include "rspro_util.h"
@ -105,15 +107,56 @@ static struct bankd_worker *bankd_create_worker(struct bankd *bankd, unsigned in
static bool terminate = false;
/* handle incoming messages from server */
static int bankd_srvc_handle_rx(struct rspro_server_conn *srvc, const RsproPDU_t *pdu)
{
struct RsproPDU_t *resp;
switch (pdu->msg.present) {
case RsproPDUchoice_PR_connectBankRes:
/* Store 'identity' of server in srvc->peer_comp_id */
rspro_comp_id_retrieve(&srvc->peer_comp_id, &pdu->msg.choice.connectBankRes.identity);
osmo_fsm_inst_dispatch(srvc->fi, SRVC_E_CLIENT_CONN_RES, (void *) pdu);
break;
default:
fprintf(stderr, "Unknown/Unsupported RSPRO PDU type: %u\n", pdu->msg.present);
return -1;
}
return 0;
}
void handle_options(int argc, char **argv)
{
}
int main(int argc, char **argv)
{
struct bankd *bankd = talloc_zero(NULL, struct bankd);
struct rspro_server_conn *srvc = &bankd->srvc;
int i, rc;
OSMO_ASSERT(bankd);
bankd_init(bankd);
/* create listening socket */
srvc->server_host = "localhost";
srvc->server_port = 9998;
srvc->handle_rx = bankd_srvc_handle_rx;
srvc->own_comp_id.type = ComponentType_remsimBankd;
OSMO_STRLCPY_ARRAY(srvc->own_comp_id.name, "fixme-name");
OSMO_STRLCPY_ARRAY(srvc->own_comp_id.software, "remsim-bankd");
OSMO_STRLCPY_ARRAY(srvc->own_comp_id.sw_version, PACKAGE_VERSION);
handle_options(argc, argv);
/* Connection towards remsim-server */
rc = server_conn_fsm_alloc(bankd, srvc);
if (rc < 0) {
fprintf(stderr, "Unable to create Server conn FSM: %s\n", strerror(errno));
exit(1);
}
/* create listening socket for inbound client connections */
rc = osmo_sock_init(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 9999, OSMO_SOCK_F_BIND);
if (rc < 0)
exit(1);
@ -133,11 +176,8 @@ int main(int argc, char **argv)
/* FIXME: Connect to remsim-server from the main thread, register with
* it and await + process any slot mapping or other configuration commands.
* Ensure to re-connect as needed. */
/* we should generalize the SRVC (server connection) FSM from remsim-client
* and use it here. As long as only the main thread is using osmo_fsm, things
* are safe with regard to other threads */
sleep(1);
osmo_select_main(0);
}
talloc_free(bankd);

View File

@ -5,6 +5,7 @@
#include <osmocom/rspro/RsproPDU.h>
#include "rspro_util.h"
#include "remsim_client_fsm.h"
#include "debug.h"
/* fsm.c */
@ -19,41 +20,6 @@ enum bankd_conn_fsm_event {
extern struct osmo_fsm remsim_client_bankd_fsm;
enum server_conn_fsm_event {
SRVC_E_TCP_UP,
SRVC_E_TCP_DOWN,
SRVC_E_KA_TIMEOUT,
SRVC_E_CLIENT_CONN_RES,
};
struct rspro_server_conn;
/* representing a client-side connection to a RSPRO server */
struct rspro_server_conn {
/* state */
struct ipa_client_conn *conn;
struct osmo_fsm_inst *fi;
struct osmo_fsm_inst *keepalive_fi;
int (*handle_rx)(struct rspro_server_conn *conn, const RsproPDU_t *pdu);
/* IPA protocol identity */
struct ipaccess_unit ipa_dev;
/* our own component ID */
struct app_comp_id own_comp_id;
/* remote component ID */
struct app_comp_id peer_comp_id;
/* client id and slot number */
ClientSlot_t *clslot;
/* configuration */
char *server_host;
uint16_t server_port;
};
int server_conn_fsm_alloc(void *ctx, struct rspro_server_conn *srvc);
extern struct osmo_fsm remsim_client_server_fsm;
/* main.c */
struct bankd_client {

View File

@ -17,6 +17,13 @@
#define S(x) (1 << (x))
#define T1_WAIT_CLIENT_CONN_RES 10
#define T2_RECONNECT 10
/***********************************************************************
* server connection FSM: remsim-{client,bankd} to remsim-server
***********************************************************************/
static void push_and_send(struct ipa_client_conn *ipa, struct msgb *msg_tx)
{
ipa_prepend_header_ext(msg_tx, IPAC_PROTO_EXT_RSPRO);
@ -32,217 +39,6 @@ void ipa_client_conn_send_rspro(struct ipa_client_conn *ipa, RsproPDU_t *rspro)
push_and_send(ipa, msg);
}
static void bankd_updown_cb(struct ipa_client_conn *conn, int up)
{
struct bankd_client *bc = conn->data;
printf("RSPRO link to %s:%d %s\n", conn->addr, conn->port, up ? "UP" : "DOWN");
osmo_fsm_inst_dispatch(bc->bankd_fi, up ? BDC_E_TCP_UP: BDC_E_TCP_DOWN, 0);
}
/***********************************************************************
* bankd connection FSM
***********************************************************************/
enum bankd_conn_fsm_state {
/* waiting for initial connectiong to remsim-bankd */
BDC_ST_INIT,
/* bankd connection established, waiting for ClientConnectRes */
BDC_ST_ESTABLISHED,
/* bankd connection etsablished, ClientConnect succeeded */
BDC_ST_CONNECTED,
/* connection lost, we're waiting for a re-establish */
BDC_ST_REESTABLISH,
};
static const struct value_string remsim_client_bankd_fsm_event_names[] = {
OSMO_VALUE_STRING(BDC_E_ESTABLISH),
OSMO_VALUE_STRING(BDC_E_TCP_UP),
OSMO_VALUE_STRING(BDC_E_TCP_DOWN),
OSMO_VALUE_STRING(BDC_E_CLIENT_CONN_RES),
{ 0, NULL }
};
#define T1_WAIT_CLIENT_CONN_RES 10
#define T2_RECONNECT 10
static void bdc_st_init(struct osmo_fsm_inst *fi, uint32_t event, void *data)
{
switch (event) {
case BDC_E_ESTABLISH:
osmo_fsm_inst_state_chg(fi, BDC_ST_REESTABLISH, T2_RECONNECT, 2);
break;
default:
OSMO_ASSERT(0);
}
}
static void bdc_st_established_onenter(struct osmo_fsm_inst *fi, uint32_t prev_state)
{
struct bankd_client *bc = (struct bankd_client *) fi->priv;
RsproPDU_t *pdu;
/* FIXME: Send ClientConnReq */
pdu = rspro_gen_ConnectClientReq(&bc->srv_conn.own_comp_id, bc->srv_conn.clslot);
ipa_client_conn_send_rspro(bc->bankd_conn, pdu);
}
static void bdc_st_established(struct osmo_fsm_inst *fi, uint32_t event, void *data)
{
switch (event) {
case BDC_E_TCP_DOWN:
osmo_fsm_inst_state_chg(fi, BDC_ST_REESTABLISH, T2_RECONNECT, 2);
break;
case BDC_E_CLIENT_CONN_RES:
/* somehow notify the main code? */
osmo_fsm_inst_state_chg(fi, BDC_ST_CONNECTED, 0, 0);
break;
default:
OSMO_ASSERT(0);
}
}
static void bdc_st_connected(struct osmo_fsm_inst *fi, uint32_t event, void *data)
{
switch (event) {
case BDC_E_TCP_DOWN:
osmo_fsm_inst_state_chg(fi, BDC_ST_REESTABLISH, T2_RECONNECT, 2);
break;
default:
OSMO_ASSERT(0);
}
}
static void bdc_st_reestablish_onenter(struct osmo_fsm_inst *fi, uint32_t prev_state)
{
struct bankd_client *bc = (struct bankd_client *) fi->priv;
int rc;
/* re-create bankd_conn */
if (bc->bankd_conn) {
LOGPFSML(fi, LOGL_INFO, "Destroying existing connection to bankd\n");
ipa_client_conn_destroy(bc->bankd_conn);
bc->bankd_conn = NULL;
}
LOGPFSML(fi, LOGL_INFO, "Creating TCP connection to bankd at %s:%u\n",
bc->bankd_host, bc->bankd_port);
bc->bankd_conn = ipa_client_conn_create(bc, NULL, 0, bc->bankd_host, bc->bankd_port,
bankd_updown_cb, bankd_read_cb, NULL, bc);
if (!bc->bankd_conn) {
fprintf(stderr, "Unable to create socket: %s\n", strerror(errno));
exit(1);
}
/* Attempt to connect TCP socket */
rc = ipa_client_conn_open(bc->bankd_conn);
if (rc < 0) {
fprintf(stderr, "Unable to connect RSPRO to %s:%d - %s\n",
bc->bankd_conn->addr, bc->bankd_conn->port, strerror(errno));
/* FIXME: retry? Timer? Abort? */
OSMO_ASSERT(0);
}
}
static void bdc_st_reestablish(struct osmo_fsm_inst *fi, uint32_t event, void *data)
{
switch (event) {
case BDC_E_TCP_UP:
osmo_fsm_inst_state_chg(fi, BDC_ST_ESTABLISHED, T1_WAIT_CLIENT_CONN_RES, 1);
break;
case BDC_E_TCP_DOWN:
/* wait for normal T2 timeout */
break;
default:
OSMO_ASSERT(0);
}
}
static void bdc_allstate_action(struct osmo_fsm_inst *fi, uint32_t event, void *data)
{
switch (event) {
case BDC_ST_REESTABLISH:
osmo_fsm_inst_state_chg(fi, BDC_ST_REESTABLISH, T2_RECONNECT, 2);
break;
default:
OSMO_ASSERT(0);
}
}
static int remsim_client_bankd_fsm_timer_cb(struct osmo_fsm_inst *fi)
{
switch (fi->T) {
case 2:
/* TCP reconnect failed: retry */
osmo_fsm_inst_state_chg(fi, BDC_ST_REESTABLISH, T2_RECONNECT, 2);
break;
case 1:
/* no ClientConnectRes received: disconnect + reconnect */
osmo_fsm_inst_state_chg(fi, BDC_ST_REESTABLISH, T2_RECONNECT, 2);
break;
default:
OSMO_ASSERT(0);
}
return 0;
}
static const struct osmo_fsm_state bankd_conn_fsm_states[] = {
[BDC_ST_INIT] = {
.name = "INIT",
.in_event_mask = 0, /* S(BDC_E_ESTABLISH) via allstate */
.out_state_mask = S(BDC_ST_REESTABLISH),
.action = bdc_st_init,
},
[BDC_ST_ESTABLISHED] = {
.name = "ESTABLISHED",
.in_event_mask = S(BDC_E_TCP_DOWN) | S(BDC_E_CLIENT_CONN_RES),
.out_state_mask = S(BDC_ST_CONNECTED) | S(BDC_ST_REESTABLISH),
.action = bdc_st_established,
.onenter = bdc_st_established_onenter,
},
[BDC_ST_CONNECTED] = {
.name = "CONNECTED",
.in_event_mask = S(BDC_E_TCP_DOWN),
.out_state_mask = S(BDC_ST_REESTABLISH),
.action = bdc_st_connected,
},
[BDC_ST_REESTABLISH] = {
.name = "REESTABLISH",
.in_event_mask = S(BDC_E_TCP_UP) | S(BDC_E_TCP_DOWN),
.out_state_mask = S(BDC_ST_ESTABLISHED) | S(BDC_ST_REESTABLISH),
.action = bdc_st_reestablish,
.onenter = bdc_st_reestablish_onenter,
},
};
struct osmo_fsm remsim_client_bankd_fsm = {
.name = "BANKD_CONN",
.states = bankd_conn_fsm_states,
.num_states = ARRAY_SIZE(bankd_conn_fsm_states),
.allstate_event_mask = S(BDC_E_ESTABLISH),
.allstate_action = bdc_allstate_action,
.timer_cb = remsim_client_bankd_fsm_timer_cb,
.log_subsys = DMAIN,
.event_names = remsim_client_bankd_fsm_event_names,
};
int bankd_conn_fsm_alloc(struct bankd_client *bc)
{
struct osmo_fsm_inst *fi;
fi = osmo_fsm_inst_alloc(&remsim_client_bankd_fsm, bc, bc, LOGL_DEBUG, "bankd");
if (!fi)
return -1;
bc->bankd_fi = fi;
return 0;
}
/***********************************************************************
* server connection FSM
***********************************************************************/
enum server_conn_fsm_state {
/* waiting for initial connectiong to remsim-server */
SRVC_ST_INIT,
@ -387,7 +183,10 @@ static void srvc_st_established_onenter(struct osmo_fsm_inst *fi, uint32_t prev_
ipa_keepalive_fsm_start(srvc->keepalive_fi);
if (srvc->own_comp_id.type == ComponentType_remsimClient)
pdu = rspro_gen_ConnectClientReq(&srvc->own_comp_id, srvc->clslot);
else
pdu = rspro_gen_ConnectBankReq(&srvc->own_comp_id, 1, 8 /* FIXME */);
ipa_client_conn_send_rspro(srvc->conn, pdu);
}
@ -521,6 +320,5 @@ int server_conn_fsm_alloc(void *ctx, struct rspro_server_conn *srvc)
static __attribute__((constructor)) void on_dso_load(void)
{
osmo_fsm_register(&remsim_client_bankd_fsm);
osmo_fsm_register(&remsim_client_server_fsm);
}

40
src/remsim_client_fsm.h Normal file
View File

@ -0,0 +1,40 @@
#pragma once
#include <osmocom/core/fsm.h>
#include <osmocom/abis/ipa.h>
#include <osmocom/rspro/RsproPDU.h>
enum server_conn_fsm_event {
SRVC_E_TCP_UP,
SRVC_E_TCP_DOWN,
SRVC_E_KA_TIMEOUT,
SRVC_E_CLIENT_CONN_RES,
};
struct rspro_server_conn;
/* representing a client-side connection to a RSPRO server */
struct rspro_server_conn {
/* state */
struct ipa_client_conn *conn;
struct osmo_fsm_inst *fi;
struct osmo_fsm_inst *keepalive_fi;
int (*handle_rx)(struct rspro_server_conn *conn, const RsproPDU_t *pdu);
/* IPA protocol identity */
struct ipaccess_unit ipa_dev;
/* our own component ID */
struct app_comp_id own_comp_id;
/* remote component ID */
struct app_comp_id peer_comp_id;
/* client id and slot number */
ClientSlot_t *clslot;
/* configuration */
char *server_host;
uint16_t server_port;
};
int server_conn_fsm_alloc(void *ctx, struct rspro_server_conn *srvc);
extern struct osmo_fsm remsim_client_server_fsm;