From a7328a5642566bf7b07c6d0e58dfe5da018873a5 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Sat, 13 Jul 2013 17:09:56 +0200 Subject: smpp: Move the coding/mode detection into a utils file Make sure to not ever have issues with this code again, move the utility code to a new file and create a basic testcase. The method currently has 100% line and branch coverage. My initial patched missed the smpp_utils.c file and I re-did the copying (and verifying the branch coverage) --- openbsc/src/libmsc/Makefile.am | 2 +- openbsc/src/libmsc/smpp_openbsc.c | 36 +---------------------- openbsc/src/libmsc/smpp_smsc.h | 5 ++++ openbsc/src/libmsc/smpp_utils.c | 62 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 36 deletions(-) create mode 100644 openbsc/src/libmsc/smpp_utils.c (limited to 'openbsc/src') diff --git a/openbsc/src/libmsc/Makefile.am b/openbsc/src/libmsc/Makefile.am index 7faee430a..c36ba926b 100644 --- a/openbsc/src/libmsc/Makefile.am +++ b/openbsc/src/libmsc/Makefile.am @@ -19,5 +19,5 @@ libmsc_a_SOURCES = auth.c \ osmo_msc.c if BUILD_SMPP -libmsc_a_SOURCES += smpp_smsc.c smpp_openbsc.c smpp_vty.c +libmsc_a_SOURCES += smpp_smsc.c smpp_openbsc.c smpp_vty.c smpp_utils.c endif diff --git a/openbsc/src/libmsc/smpp_openbsc.c b/openbsc/src/libmsc/smpp_openbsc.c index f898cae6f..8e0085d0c 100644 --- a/openbsc/src/libmsc/smpp_openbsc.c +++ b/openbsc/src/libmsc/smpp_openbsc.c @@ -79,9 +79,6 @@ static struct tlv_t *find_tlv(struct tlv_t *head, uint16_t tag) return NULL; } -#define MODE_7BIT 7 -#define MODE_8BIT 8 - /*! \brief convert from submit_sm_t to gsm_sms */ static int submit_to_sms(struct gsm_sms **psms, struct gsm_network *net, const struct submit_sm_t *submit) @@ -469,39 +466,8 @@ static int deliver_to_esme(struct osmo_esme *esme, struct gsm_sms *sms, /* Figure out SMPP DCS from TP-DCS */ dcs = sms->data_coding_scheme; - if ((dcs & 0xF0) == 0xF0) { - if (dcs & 0x04) { - /* bit 2 == 1: 8bit data */ - deliver.data_coding = 0x02; - mode = MODE_8BIT; - } else { - /* bit 2 == 0: default alphabet */ - deliver.data_coding = 0x01; - mode = MODE_7BIT; - } - } else if ((dcs & 0xE0) == 0) { - switch (dcs & 0xC) { - case 0: - deliver.data_coding = 0x01; - mode = MODE_7BIT; - break; - case 4: - deliver.data_coding = 0x02; - mode = MODE_8BIT; - break; - case 8: - deliver.data_coding = 0x08; /* UCS-2 */ - mode = MODE_8BIT; - break; - default: - goto unknown_mo; - } - } else { -unknown_mo: - LOGP(DLSMS, LOGL_ERROR, "SMPP MO Unknown Data Coding 0x%02x\n", - dcs); + if (smpp_determine_scheme(dcs, &deliver.data_coding, &mode) == -1) return -1; - } /* Transparently pass on DCS via SMPP if requested */ if (esme->acl && esme->acl->dcs_transparent) diff --git a/openbsc/src/libmsc/smpp_smsc.h b/openbsc/src/libmsc/smpp_smsc.h index 747dc3a2c..21d28dda6 100644 --- a/openbsc/src/libmsc/smpp_smsc.h +++ b/openbsc/src/libmsc/smpp_smsc.h @@ -15,6 +15,9 @@ #define SMPP_SYS_ID_LEN 16 #define SMPP_PASSWD_LEN 16 +#define MODE_7BIT 7 +#define MODE_8BIT 8 + enum esme_read_state { READ_ST_IN_LEN = 0, READ_ST_IN_MSG = 1, @@ -126,4 +129,6 @@ int smpp_route_pfx_del(struct osmo_smpp_acl *acl, const struct osmo_smpp_addr *pfx); int smpp_vty_init(void); + +int smpp_determine_scheme(uint8_t dcs, uint8_t *data_coding, int *mode); #endif diff --git a/openbsc/src/libmsc/smpp_utils.c b/openbsc/src/libmsc/smpp_utils.c new file mode 100644 index 000000000..d0850d8c1 --- /dev/null +++ b/openbsc/src/libmsc/smpp_utils.c @@ -0,0 +1,62 @@ + +/* (C) 2012-2013 by Harald Welte + * + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + + +#include "smpp_smsc.h" +#include + + +int smpp_determine_scheme(uint8_t dcs, uint8_t *data_coding, int *mode) +{ + if ((dcs & 0xF0) == 0xF0) { + if (dcs & 0x04) { + /* bit 2 == 1: 8bit data */ + *data_coding = 0x02; + *mode = MODE_8BIT; + } else { + /* bit 2 == 0: default alphabet */ + *data_coding = 0x01; + *mode = MODE_7BIT; + } + } else if ((dcs & 0xE0) == 0) { + switch (dcs & 0xC) { + case 0: + *data_coding = 0x01; + *mode = MODE_7BIT; + break; + case 4: + *data_coding = 0x02; + *mode = MODE_8BIT; + break; + case 8: + *data_coding = 0x08; /* UCS-2 */ + *mode = MODE_8BIT; + break; + default: + goto unknown_mo; + } + } else { +unknown_mo: + LOGP(DLSMS, LOGL_ERROR, "SMPP MO Unknown Data Coding 0x%02x\n", dcs); + return -1; + } + + return 0; + +} -- cgit v1.2.3