From 66d6998347d2bd703951436fce6b3f5f65242991 Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 28 Jul 2022 14:19:22 +0700 Subject: [PATCH] Introduce libsmpputil As part of preparation for libosmo-netif migration let's move common SMPP code into separate build-time library and use it for both smpp_mirror and OsmoMSC. While at it we also fix id/password legth limits in smpp_mirror and drop unused fields from ESME struct. Related: OS#5568 Change-Id: I61910651bc7c188dc2fb67d96189a66a47e7e8fb --- include/osmocom/msc/smpp.h | 27 +++++++++++++++++++++++++++ src/libmsc/Makefile.am | 9 +++++++++ src/libmsc/smpp_smsc.c | 23 ----------------------- src/libmsc/smpp_smsc.h | 9 +-------- src/libmsc/smpp_utils.c | 7 +++++++ src/utils/Makefile.am | 7 +++++++ src/utils/smpp_mirror.c | 25 +------------------------ tests/smpp/Makefile.am | 2 ++ 8 files changed, 54 insertions(+), 55 deletions(-) diff --git a/include/osmocom/msc/smpp.h b/include/osmocom/msc/smpp.h index bcdac8f0b..cc0e8003a 100644 --- a/include/osmocom/msc/smpp.h +++ b/include/osmocom/msc/smpp.h @@ -1,4 +1,31 @@ #pragma once +#include + +/* Length limits according to SMPP 3.4 spec including NUL-byte: */ +#define SMPP_SYS_ID_LEN 15 +#define SMPP_PASSWD_LEN 8 + +enum esme_read_state { + READ_ST_IN_LEN = 0, + READ_ST_IN_MSG = 1, +}; + +/*! \brief Ugly wrapper. libsmpp34 should do this itself! */ +#define SMPP34_UNPACK(rc, type, str, data, len) { \ + memset(str, 0, sizeof(*str)); \ + rc = smpp34_unpack(type, str, data, len); } + +#define PACK_AND_SEND(esme, ptr) pack_and_send(esme, (ptr)->command_id, ptr) + +/*! \brief initialize the libsmpp34 data structure for a response */ +#define INIT_RESP(type, resp, req) { \ + memset((resp), 0, sizeof(*(resp))); \ + (resp)->command_length = 0; \ + (resp)->command_id = type; \ + (resp)->command_status = ESME_ROK; \ + (resp)->sequence_number = (req)->sequence_number; } + +uint32_t smpp_msgb_cmdid(struct msgb *msg); int smpp_openbsc_alloc_init(void *ctx); int smpp_openbsc_start(struct gsm_network *net); diff --git a/src/libmsc/Makefile.am b/src/libmsc/Makefile.am index d3b6035e2..b26c8c29f 100644 --- a/src/libmsc/Makefile.am +++ b/src/libmsc/Makefile.am @@ -93,4 +93,13 @@ libmsc_a_SOURCES += \ smpp_vty.c \ smpp_utils.c \ $(NULL) + +noinst_LIBRARIES += \ + libsmpputil.a \ + $(NULL) + +libsmpputil_a_SOURCES = \ + smpp_utils.c \ + $(NULL) + endif diff --git a/src/libmsc/smpp_smsc.c b/src/libmsc/smpp_smsc.c index da6607421..2862ea9df 100644 --- a/src/libmsc/smpp_smsc.c +++ b/src/libmsc/smpp_smsc.c @@ -45,11 +45,6 @@ #include #include -/*! \brief Ugly wrapper. libsmpp34 should do this itself! */ -#define SMPP34_UNPACK(rc, type, str, data, len) \ - memset(str, 0, sizeof(*str)); \ - rc = smpp34_unpack(type, str, data, len) - enum emse_bind { ESME_BIND_RX = 0x01, ESME_BIND_TX = 0x02, @@ -333,18 +328,7 @@ int smpp_route(const struct smsc *smsc, const struct osmo_smpp_addr *dest, struc return GSM411_RP_CAUSE_MO_NUM_UNASSIGNED; } - -/*! \brief initialize the libsmpp34 data structure for a response */ -#define INIT_RESP(type, resp, req) { \ - memset((resp), 0, sizeof(*(resp))); \ - (resp)->command_length = 0; \ - (resp)->command_id = type; \ - (resp)->command_status = ESME_ROK; \ - (resp)->sequence_number = (req)->sequence_number; \ -} - /*! \brief pack a libsmpp34 data strcutrure and send it to the ESME */ -#define PACK_AND_SEND(esme, ptr) pack_and_send(esme, (ptr)->command_id, ptr) static int pack_and_send(struct osmo_esme *esme, uint32_t type, void *ptr) { struct msgb *msg; @@ -394,13 +378,6 @@ static int smpp_tx_gen_nack(struct osmo_esme *esme, uint32_t seq, uint32_t statu return PACK_AND_SEND(esme, &nack); } -/*! \brief retrieve SMPP command ID from a msgb */ -static inline uint32_t smpp_msgb_cmdid(struct msgb *msg) -{ - uint8_t *tmp = msgb_data(msg) + 4; - return ntohl(*(uint32_t *)tmp); -} - /*! \brief retrieve SMPP sequence number from a msgb */ static inline uint32_t smpp_msgb_seq(struct msgb *msg) { diff --git a/src/libmsc/smpp_smsc.h b/src/libmsc/smpp_smsc.h index 76772a3ee..bb8fab1c2 100644 --- a/src/libmsc/smpp_smsc.h +++ b/src/libmsc/smpp_smsc.h @@ -8,24 +8,17 @@ #include #include #include +#include #include #include #include -#define SMPP_SYS_ID_LEN 15 -#define SMPP_PASSWD_LEN 8 - #define MODE_7BIT 7 #define MODE_8BIT 8 struct msc_a; -enum esme_read_state { - READ_ST_IN_LEN = 0, - READ_ST_IN_MSG = 1, -}; - struct osmo_smpp_acl; struct osmo_smpp_addr { diff --git a/src/libmsc/smpp_utils.c b/src/libmsc/smpp_utils.c index 3c7757b9a..094535471 100644 --- a/src/libmsc/smpp_utils.c +++ b/src/libmsc/smpp_utils.c @@ -24,6 +24,13 @@ #include "smpp_smsc.h" #include +/*! \brief retrieve SMPP command ID from a msgb */ +uint32_t smpp_msgb_cmdid(struct msgb *msg) +{ + uint8_t *tmp = msgb_data(msg) + 4; + return ntohl(*(uint32_t *)tmp); +} + int smpp_determine_scheme(uint8_t dcs, uint8_t *data_coding, int *mode) { if ((dcs & 0xF0) == 0xF0) { diff --git a/src/utils/Makefile.am b/src/utils/Makefile.am index cb0faf69f..3019f1e8b 100644 --- a/src/utils/Makefile.am +++ b/src/utils/Makefile.am @@ -28,16 +28,23 @@ noinst_PROGRAMS = \ smpp_mirror \ $(NULL) +noinst_HEADERS += \ + $(top_srcdir)/src/libmsc/smpp_smsc.h \ + $(NULL) + smpp_mirror_SOURCES = \ smpp_mirror.c \ $(NULL) smpp_mirror_CFLAGS = \ $(LIBOSMOCORE_CFLAGS) \ + $(LIBOSMOSCCP_CFLAGS) \ + $(LIBOSMOMGCPCLIENT_CFLAGS) \ $(LIBSMPP34_CFLAGS) \ $(NULL) smpp_mirror_LDADD = \ + $(top_builddir)/src/libmsc/libsmpputil.a \ $(LIBOSMOCORE_LIBS) \ $(LIBOSMOGSM_LIBS) \ $(LIBSMPP34_LIBS) \ diff --git a/src/utils/smpp_mirror.c b/src/utils/smpp_mirror.c index 72d15e39d..67ac5e24f 100644 --- a/src/utils/smpp_mirror.c +++ b/src/utils/smpp_mirror.c @@ -19,18 +19,11 @@ #include #include +#include -/* FIXME: merge with smpp_smsc.c */ -#define SMPP_SYS_ID_LEN 16 -enum esme_read_state { - READ_ST_IN_LEN = 0, - READ_ST_IN_MSG = 1, -}; /* FIXME: merge with smpp_smsc.c */ struct esme { - struct osmo_fd ofd; - uint32_t own_seq_nr; struct osmo_wqueue wqueue; @@ -45,22 +38,6 @@ struct esme { }; /* FIXME: merge with smpp_smsc.c */ -#define SMPP34_UNPACK(rc, type, str, data, len) \ - memset(str, 0, sizeof(*str)); \ - rc = smpp34_unpack(type, str, data, len) -#define INIT_RESP(type, resp, req) { \ - memset((resp), 0, sizeof(*(resp))); \ - (resp)->command_length = 0; \ - (resp)->command_id = type; \ - (resp)->command_status = ESME_ROK; \ - (resp)->sequence_number = (req)->sequence_number; \ -} -#define PACK_AND_SEND(esme, ptr) pack_and_send(esme, (ptr)->command_id, ptr) -static inline uint32_t smpp_msgb_cmdid(struct msgb *msg) -{ - uint8_t *tmp = msgb_data(msg) + 4; - return ntohl(*(uint32_t *)tmp); -} static uint32_t esme_inc_seq_nr(struct esme *esme) { esme->own_seq_nr++; diff --git a/tests/smpp/Makefile.am b/tests/smpp/Makefile.am index 00090daae..0e4834734 100644 --- a/tests/smpp/Makefile.am +++ b/tests/smpp/Makefile.am @@ -11,6 +11,8 @@ AM_CFLAGS = \ $(LIBOSMOGSM_CFLAGS) \ $(LIBOSMOSCCP_CFLAGS) \ $(LIBOSMOABIS_CFLAGS) \ + $(LIBOSMOSCCP_CFLAGS) \ + $(LIBOSMOMGCPCLIENT_CFLAGS) \ $(COVERAGE_CFLAGS) \ $(LIBSMPP34_CFLAGS) \ $(NULL)