summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2017-07-19 13:53:30 +0200
committerHarald Welte <laforge@gnumonks.org>2017-07-19 13:53:30 +0200
commitf122d4cd364a6ba0c3d73ff017c3cc598ebf10f1 (patch)
tree69f0059dfb82f276508caecaa01b842a3536d69d
parentc0fba7a298fc8c7fada32b24f71aa27e0ec90cd6 (diff)
VIRT-PHY: Properly destroy l1_model_ms after disconnect
If a MS disconnects, we need to clean up all related state Change-Id: Ib7adef61150b5a4338483019e4dd75d7279d1f5d
-rw-r--r--src/host/virt_phy/include/virtphy/l1ctl_sap.h2
-rw-r--r--src/host/virt_phy/include/virtphy/l1ctl_sock.h3
-rw-r--r--src/host/virt_phy/src/l1ctl_sap.c6
-rw-r--r--src/host/virt_phy/src/l1ctl_sock.c5
-rw-r--r--src/host/virt_phy/src/virt_l1_model.c1
-rw-r--r--src/host/virt_phy/src/virt_prim_pm.c9
-rw-r--r--src/host/virt_phy/src/virtphy.c8
7 files changed, 33 insertions, 1 deletions
diff --git a/src/host/virt_phy/include/virtphy/l1ctl_sap.h b/src/host/virt_phy/include/virtphy/l1ctl_sap.h
index 5903a02d..94174da4 100644
--- a/src/host/virt_phy/include/virtphy/l1ctl_sap.h
+++ b/src/host/virt_phy/include/virtphy/l1ctl_sap.h
@@ -27,7 +27,9 @@
void l1ctl_sap_init(struct l1_model_ms *model);
+void l1ctl_sap_exit(struct l1_model_ms *model);
void prim_pm_init(struct l1_model_ms *model);
+void prim_pm_exit(struct l1_model_ms *model);
void l1ctl_sap_tx_to_l23_inst(struct l1_model_ms *model, struct msgb *msg);
void l1ctl_sap_rx_from_l23_inst_cb(struct l1ctl_sock_client *lsc, struct msgb *msg);
void l1ctl_sap_rx_from_l23(struct msgb *msg);
diff --git a/src/host/virt_phy/include/virtphy/l1ctl_sock.h b/src/host/virt_phy/include/virtphy/l1ctl_sock.h
index 82ee5caf..2c98fa58 100644
--- a/src/host/virt_phy/include/virtphy/l1ctl_sock.h
+++ b/src/host/virt_phy/include/virtphy/l1ctl_sock.h
@@ -28,6 +28,8 @@ struct l1ctl_sock_inst {
void (*recv_cb)(struct l1ctl_sock_client *lsc, struct msgb *msg); /* Callback function called for incoming data from l2 app. */
/* Callback function called for new client after accept() */
int (*accept_cb)(struct l1ctl_sock_client *lsc);
+ /* Callback function called when client disappeared */
+ void (*close_cb)(struct l1ctl_sock_client *lsc);
};
/**
@@ -37,6 +39,7 @@ struct l1ctl_sock_inst *l1ctl_sock_init(
void *ctx,
void (*recv_cb)(struct l1ctl_sock_client *lsc, struct msgb *msg),
int (*accept_cb)(struct l1ctl_sock_client *lsc),
+ void (*close_cb)(struct l1ctl_sock_client *lsc),
char *path);
/**
diff --git a/src/host/virt_phy/src/l1ctl_sap.c b/src/host/virt_phy/src/l1ctl_sap.c
index c7c8e3e0..d4b33f12 100644
--- a/src/host/virt_phy/src/l1ctl_sap.c
+++ b/src/host/virt_phy/src/l1ctl_sap.c
@@ -58,6 +58,12 @@ void l1ctl_sap_init(struct l1_model_ms *model)
prim_pm_init(model);
}
+void l1ctl_sap_exit(struct l1_model_ms *model)
+{
+ virt_l1_sched_stop(model);
+ prim_pm_exit(model);
+}
+
/**
* @brief L1CTL handler called for received messages from L23.
*
diff --git a/src/host/virt_phy/src/l1ctl_sock.c b/src/host/virt_phy/src/l1ctl_sock.c
index 00f25a6b..bf28895f 100644
--- a/src/host/virt_phy/src/l1ctl_sock.c
+++ b/src/host/virt_phy/src/l1ctl_sock.c
@@ -47,6 +47,9 @@
static void l1ctl_client_destroy(struct l1ctl_sock_client *lsc)
{
+ struct l1ctl_sock_inst *lsi = lsc->l1ctl_sock;
+ if (lsi->close_cb)
+ lsi->close_cb(lsc);
osmo_fd_close(&lsc->ofd);
llist_del(&lsc->list);
talloc_free(lsc);
@@ -149,6 +152,7 @@ struct l1ctl_sock_inst *l1ctl_sock_init(
void *ctx,
void (*recv_cb)(struct l1ctl_sock_client *lsc, struct msgb *msg),
int (*accept_cb)(struct l1ctl_sock_client *lsc),
+ void (*close_cb)(struct l1ctl_sock_client *lsc),
char *path)
{
struct l1ctl_sock_inst *lsi;
@@ -172,6 +176,7 @@ struct l1ctl_sock_inst *l1ctl_sock_init(
lsi->recv_cb = recv_cb;
lsi->accept_cb = accept_cb;
+ lsi->close_cb = close_cb;
lsi->l1ctl_sock_path = path;
INIT_LLIST_HEAD(&lsi->clients);
diff --git a/src/host/virt_phy/src/virt_l1_model.c b/src/host/virt_phy/src/virt_l1_model.c
index 14676b01..6a9fa994 100644
--- a/src/host/virt_phy/src/virt_l1_model.c
+++ b/src/host/virt_phy/src/virt_l1_model.c
@@ -46,5 +46,6 @@ struct l1_model_ms *l1_model_ms_init(void *ctx, struct l1ctl_sock_client *lsc, s
void l1_model_ms_destroy(struct l1_model_ms *model)
{
LOGPMS(DMAIN, LOGL_INFO, model, "destryed\n");
+ l1ctl_sap_exit(model);
talloc_free(model);
}
diff --git a/src/host/virt_phy/src/virt_prim_pm.c b/src/host/virt_phy/src/virt_prim_pm.c
index 1cd3c03e..46370138 100644
--- a/src/host/virt_phy/src/virt_prim_pm.c
+++ b/src/host/virt_phy/src/virt_prim_pm.c
@@ -138,3 +138,12 @@ void prim_pm_init(struct l1_model_ms *model)
l1s->pm.meas.arfcn_sig_lev_timers[i].data = &l1s->pm.meas.arfcn_sig_lev_dbm[i];
}
}
+
+void prim_pm_exit(struct l1_model_ms *model)
+{
+ struct l1_state_ms *l1s = &model->state;
+ int i;
+
+ for (i = 0; i < 1024; ++i)
+ osmo_timer_del(&l1s->pm.meas.arfcn_sig_lev_timers[i]);
+}
diff --git a/src/host/virt_phy/src/virtphy.c b/src/host/virt_phy/src/virtphy.c
index b6f4f0cf..23811c2e 100644
--- a/src/host/virt_phy/src/virtphy.c
+++ b/src/host/virt_phy/src/virtphy.c
@@ -162,6 +162,12 @@ static int l1ctl_accept_cb(struct l1ctl_sock_client *lsc)
return 0;
}
+static void l1ctl_close_cb(struct l1ctl_sock_client *lsc)
+{
+ struct l1_model_ms *ms = lsc->priv;
+ l1_model_ms_destroy(ms);
+}
+
int main(int argc, char *argv[])
{
/* init loginfo */
@@ -175,7 +181,7 @@ int main(int argc, char *argv[])
gsmtapl1_rx_from_virt_um_inst_cb);
g_vphy.l1ctl_sock = l1ctl_sock_init(NULL, l1ctl_sap_rx_from_l23_inst_cb,
- l1ctl_accept_cb, l1ctl_sock_path);
+ l1ctl_accept_cb, l1ctl_close_cb, l1ctl_sock_path);
g_vphy.virt_um->priv = g_vphy.l1ctl_sock;
LOGP(DVIRPHY, LOGL_INFO,