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
This commit is contained in:
Max 2022-07-28 14:19:22 +07:00
parent 7ddc0658bd
commit 66d6998347
8 changed files with 54 additions and 55 deletions

View File

@ -1,4 +1,31 @@
#pragma once
#include <osmocom/msc/gsm_data.h>
/* 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);

View File

@ -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

View File

@ -45,11 +45,6 @@
#include <osmocom/msc/debug.h>
#include <osmocom/msc/gsm_data.h>
/*! \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)
{

View File

@ -8,24 +8,17 @@
#include <osmocom/core/msgb.h>
#include <osmocom/core/write_queue.h>
#include <osmocom/core/timer.h>
#include <osmocom/msc/smpp.h>
#include <smpp34.h>
#include <smpp34_structs.h>
#include <smpp34_params.h>
#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 {

View File

@ -24,6 +24,13 @@
#include "smpp_smsc.h"
#include <osmocom/core/logging.h>
/*! \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) {

View File

@ -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) \

View File

@ -19,18 +19,11 @@
#include <osmocom/core/write_queue.h>
#include <osmocom/msc/debug.h>
#include <osmocom/msc/smpp.h>
/* 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++;

View File

@ -11,6 +11,8 @@ AM_CFLAGS = \
$(LIBOSMOGSM_CFLAGS) \
$(LIBOSMOSCCP_CFLAGS) \
$(LIBOSMOABIS_CFLAGS) \
$(LIBOSMOSCCP_CFLAGS) \
$(LIBOSMOMGCPCLIENT_CFLAGS) \
$(COVERAGE_CFLAGS) \
$(LIBSMPP34_CFLAGS) \
$(NULL)