aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVadim Yanitskiy <axilirator@gmail.com>2018-11-29 01:49:57 +0700
committerVadim Yanitskiy <axilirator@gmail.com>2018-12-20 01:16:03 +0700
commitdf8d454919e9482e5eaa823df4b495cdcc620c1d (patch)
tree9f0193e2469a67219e413f83f8a3d5f39496720e
parent9ea9bbbc7f70f46c17b0c6563cc9c73d6455ec29 (diff)
gsupclient: introduce osmo_gsup_client_enc_send()
Several parts of OsmoMSC (e.g. GSM 04.11, 09.11, etc.) are dealing with GSUP message encoding and sending towards OsmoHLR. In order to avoid code duplication, let's have a shared function here. Change-Id: I0589ff27933e9bca2bcf93b8259004935778db8f
-rw-r--r--include/osmocom/gsupclient/gsup_client.h3
-rw-r--r--src/gsupclient/gsup_client.c36
2 files changed, 39 insertions, 0 deletions
diff --git a/include/osmocom/gsupclient/gsup_client.h b/include/osmocom/gsupclient/gsup_client.h
index 95163cd..154e3e0 100644
--- a/include/osmocom/gsupclient/gsup_client.h
+++ b/include/osmocom/gsupclient/gsup_client.h
@@ -24,6 +24,7 @@
#include <osmocom/core/timer.h>
#include <osmocom/gsm/oap_client.h>
#include <osmocom/gsm/ipa.h>
+#include <osmocom/gsm/gsup.h>
/* a loss of GSUP between MSC and HLR is considered quite serious, let's try to recover as quickly as
* possible. Even one new connection attempt per second should be quite acceptable until the link is
@@ -70,5 +71,7 @@ struct osmo_gsup_client *osmo_gsup_client_create(void *talloc_ctx,
void osmo_gsup_client_destroy(struct osmo_gsup_client *gsupc);
int osmo_gsup_client_send(struct osmo_gsup_client *gsupc, struct msgb *msg);
+int osmo_gsup_client_enc_send(struct osmo_gsup_client *gsupc,
+ const struct osmo_gsup_message *gsup_msg);
struct msgb *osmo_gsup_client_msgb_alloc(void);
diff --git a/src/gsupclient/gsup_client.c b/src/gsupclient/gsup_client.c
index f259bdc..c8408fd 100644
--- a/src/gsupclient/gsup_client.c
+++ b/src/gsupclient/gsup_client.c
@@ -360,6 +360,42 @@ int osmo_gsup_client_send(struct osmo_gsup_client *gsupc, struct msgb *msg)
return 0;
}
+/*! Encode and send a GSUP message.
+ * \param[in] gsupc GSUP client.
+ * \param[in] gsup_msg GSUP message to be sent.
+ * \returns 0 in case of success, negative on error.
+ */
+int osmo_gsup_client_enc_send(struct osmo_gsup_client *gsupc,
+ const struct osmo_gsup_message *gsup_msg)
+{
+ struct msgb *gsup_msgb;
+ int rc;
+
+ gsup_msgb = osmo_gsup_client_msgb_alloc();
+ if (!gsup_msgb) {
+ LOGP(DLGSUP, LOGL_ERROR, "Couldn't allocate GSUP message\n");
+ return -ENOMEM;
+ }
+
+ rc = osmo_gsup_encode(gsup_msgb, gsup_msg);
+ if (rc) {
+ LOGP(DLGSUP, LOGL_ERROR, "Couldn't encode GSUP message\n");
+ goto error;
+ }
+
+ rc = osmo_gsup_client_send(gsupc, gsup_msgb);
+ if (rc) {
+ LOGP(DLGSUP, LOGL_ERROR, "Couldn't send GSUP message\n");
+ goto error;
+ }
+
+ return 0;
+
+error:
+ talloc_free(gsup_msgb);
+ return rc;
+}
+
struct msgb *osmo_gsup_client_msgb_alloc(void)
{
return msgb_alloc_headroom(4000, 64, __func__);