Commit Graph

45 Commits

Author SHA1 Message Date
Keith Whyte 320960cf9d libmsc: Map SMPP command status to GSM 04.11 cause
Send SMS RP ERROR with a failure cause that relates to
the status returned by the ESME in the deliver_sm_resp.

Actual mapping array is limited as most phones I tested
don't seem to care about the failure cause anyway,
although some will display a different notification for
GSM411_RP_CAUSE_MO_NUM_UNASSIGNED

Change-Id: I61fb2d9ef4f2d2eabdc49b53d9966ad328d15e51
2017-05-20 08:18:50 +00:00
Pablo Neira Ayuso 5121576b0c src: use osmo_timer_setup()
Use new function available in libosmocore to set up timers. Compile
tested only.

Change-Id: Ibcfd915688e97d370a888888a83a7c95cbe16819
2017-05-10 11:21:24 +02:00
Pablo Neira Ayuso 93ffbd0029 libmsc: send RP-ACK to MS after ESME sends SMPP DELIVER-SM-RESP
Hold on with the GSM 04.11 RP-ACK/RP-ERROR that we send to the MS until
we get a confirmation from the ESME, via SMPP DELIVER-SM-RESP, that we
can route this sms somewhere we can reach indeed.

After this change, the conversation looks like this:

    MS    GSM 03.40      SMSC   SMPP 3.4   ESME
     |                    |                 |
     |   SMS-SUBMIT       |                 |
     |------------------->|                 |
     |                    |    DELIVER-SM   |
     |                    |---------------->|
     |                    |                 |
     |                    | DELIVER-SM-RESP |
     |                    |<----------------|
     |  GSM 04.11 RP-ACK  |                 |
     |<-------------------|                 |
     |                    |                 |

Before this patch, the RP-ACK was sent back straight forward to the MS,
no matter if the sms can be route by the ESME or not. Thus, the user
ends up getting a misleading "message delivered" in their phone screen,
when the message may just be unroutable by the ESME hence silently
dropped.

If we get no reply from the ESME, there is a hardcoded timer that will
expire to send back an RP-ERROR to the MS indicating that network is
out-of-order. Currently this timer is arbitrarily set to 5 seconds. I
found no specific good default value on the SMPP 3.4 specs, section 7.2,
where the response_timer is described. There must be a place that
describes a better default value for this. We could also expose this
timer through VTY for configurability reasons, to be done later.

Given all this needs to happen asyncronously, ie. block the SMSC, this
patch extends the gsm_sms structure with two new fields to annotate
useful information to send the RP-ACK/RP-ERROR back to the MS of origin.
These new fields are:

* the GSM 04.07 transaction id, to look up for the gsm_trans object.

* the GSM 04.11 message reference so the MS of origin can correlate this
  response to its original request.

Tested here using python-libsmpp script that replies with
DELIVER_SM_RESP and status code 0x0b (Invalid Destination). I can see
here on my motorola C155 that message cannot be delivered. I have tested
with the success status code in the SMPP DELIVER_SM_RESP too.

Change-Id: I0d5bd5693fed6d4f4bd2951711c7888712507bfd
2017-05-08 17:15:12 +02:00
Pablo Neira Ayuso 638ad068e8 libmsc: use GSM411_RP_CAUSE_MO_NUM_UNASSIGNED as return value
Instead of hardcoded value of 1 plus comment of the right hand side of
the statement.

Change-Id: I865bdbd6da17a0389044a8e749deeeebcb9cae06
2017-05-08 14:45:17 +00:00
Max 11e4e41ffc Fix MS TO measurement representation
* set proper flag when saving MS Timing Offset
* use gsm_subscriber's IMSI or lchan's name if bsc_subscriber is unknown
* add comments with spec reference
* store/display MS Timing Offset instead of raw Timing Offset field from
  RSL
* Compute MS Timing Offset [-63; 192] from Timing Offset field [0; 255],
  adjust structure gsm_meas_rep with proper type to store it

Change-Id: I7e003d23a6edb714c5f17688fd6a8edac131161d
Related: OS#1574
2017-04-26 08:25:22 +00:00
Neels Hofmeyr 89a8e722ed logging fixup: shorter names for LOGGING_FILTER_* and LOGGING_CTX_*
In libosmocore, my patch was merged to master a bit too soon. To accomodate the
request for naming that matches the general "LOG" prefix instead of "LOGGING",
a fixup was committed to libosmocore. Adjust for that.

Original patch: change-id I5c343630020f4b108099696fd96c2111614c8067
The fixup: change-id I424fe3f12ea620338902b2bb8230544bde3f1a93

Change-Id: Ib2ec5e4884aa90f48051ee2f832af557aa525991
2017-02-23 18:11:57 +01:00
Neels Hofmeyr f13b3c968f logging: use central filter and ctx consts from libosmocore
The LCHAN and BTS filter contexts are actually never used, so drop them until
someone adds them properly.

For now use only LOGGING_{FILTER,CTX}_VLR_SUBSCR. Some of these will change to
_BSC_SUBSCR once struct bsc_subscriber is introduced, and later on, struct
gsm_subscriber will be replaced by vlr_subscriber so that the names will match.

Depends: libosmocore change-id I5c343630020f4b108099696fd96c2111614c8067
Change-Id: Ifa82f6a461ad4c0eeddb8a38fb3833460432d16b
2017-02-22 17:24:54 +01:00
Neels Hofmeyr 93bafb611a cosmetic: use osmo_strlcpy() everywhere
Shorten some code and make obvious to the reader that the string copy is done
in a safe way.

Change-Id: I900726cf06d34128db22a3d3d911ee0d1423b1bd
2017-01-23 11:59:01 +00:00
Keith Whyte 80abe522e2 Pass actual smpp_avail_status through to smpp in alert_all_esme()
Change-Id: I4b00d8821c1688ca0c990b6042607f4ded0f80e3
2016-12-24 17:12:34 +00:00
Neels Hofmeyr 1b0e5540db smpp: refactor initialization, add bind address
Make the SMPP bind address configurable (used to be harcoded as "0.0.0.0").

Add VTY command

    smpp
     local-tcp A.B.C.D <1-65535>

while keeping the old command 'local-tcp-port <1-65535>'. Both the old and the
new command immediately change the SMPP listening address and port.

Add a LOGL_NOTICE log when the SMPP listening address and/or port change.

However, to be useful, this patch has to go somewhat further: refactor the
initialization procedure, because it was impossible to run the VTY commands
without an already established connection.

The SMPP initialization procedure was weird. It would first open a connection
on the default port, and a subsequent VTY port reconfiguration while reading
the config file would try to re-establish a connection on a different port. If
that failed, smpp would switch back to the default port instead of failing the
program launch as the user would expect. If anything else ran on port 2775,
SMPP would thus refuse to launch despite the config file having a different
port: the first bind would always happen on 0.0.0.0:2775. Change that.

In the VTY commands, merely store address and port if no fd is established yet.

Introduce several SMPP initialization stages:

* allocate struct and initialize pointers,
* then read config file without immediately starting to listen,
* and once the main program is ready, start listening.

After that, the VTY command behaves as before: try to re-establish the old
connection if the newly supplied address and port don't work out. I'm not
actually sure why this switch-back behavior is needed, but fair enough.

In detail, replace the function
  smpp_smsc_init()
with the various steps
  smpp_smsc_alloc_init() -- prepare struct for VTY commands
  smpp_smsc_conf() -- set addr an port only, for reading the config file
  smpp_smsc_start() -- establish a first connection, for main()
  smpp_smsc_restart() -- switch running connection, for telnet VTY
  smpp_smsc_stop() -- tear down connection, used by _start() twice

And replace
  smpp_openbsc_init()
  smpp_openbsc_set_net()
with
  smpp_openbsc_alloc_init()
  smpp_openbsc_start()

I'd have picked function names like "_bind"/"_unbind", but in the SMPP protocol
there is also a bind/unbind process, so instead I chose the names "_start",
"_restart" and "_stop".

The smsc struct used to be talloc'd outside of smpp_smsc_init(). Since the smsc
code internally uses talloc anyway and employs the smsc struct as talloc
context, I decided to enforce talloc allocation within smpp_smsc_alloc_init().

Be stricter about osmo_signal_register_handler() return codes.
2016-02-25 12:18:04 +01:00
Holger Hans Peter Freyther 5425e5ea27 subscr: Fix subscr refcount issue in case of message error
In case the SMPP payload didn't include the right fields we
would leak the subscr reference count.
2015-08-08 20:46:50 +02:00
Holger Hans Peter Freyther 42cf2e03c9 sms: Add a way to always route SMS through SMPP systems
default-route would only be looked at after there has been
no subscriber in the local database. Depending on the setup
this is not what one wants. This has been discussed at the
OsmoDevCon and there have been hacks in some branches. Let's
introduce a VTY command to select if SMPP should be consulted
first and then fallback to the current behavior.
2015-07-06 16:50:19 +02:00
Holger Hans Peter Freyther a0735ecab5 smpp: Fix potential crash in handling submitSM
In case:

* No message_payload and a 0 sm_length was used
* esm_class indicates UDH being present
* 7bit encoding was requested

The code would execute:

  ud_len = *sms_msg + 1;

Which is a NULL pointer dereference and would lead
to a crash of the NITB. Enforce the limits of the
sm_length parameter and reject the messae otherwise.

Fixes: Coverity CID 1042373
2015-02-08 09:56:31 +01:00
Holger Hans Peter Freyther 019851a523 smpp: Do not check conn for being null
We are deferencing conn earlier in this function without doing
a null check. At the time deliver_to_esme is called the conn
will always exist and even the lchan is likely to be present.
Remove the null check for conn right now.

Fixes: Coverity CID 1210594
2015-02-08 09:21:04 +01:00
Jacob Erlbeck 1e30a28e51 msc: Add and use gsm_subscriber_group
Currently every subcriber object directly refers to the gsm_network
which contains a flag shared by every related subscriber
(keep_subscr). This adds a dependency on gsm_network even if only the
function defined in gsm_subscriber_base.c are used.

This patch adds a new struct gsm_subscriber_group which contains the
keep_subscr flag and a back reference to the network object. The
latter is not dereferenced in gsm_subscriber_base.c, so it can safely
be set to NULL when only that part of the gsm_subscriber API is being
used. It also changes that API to use gsm_subscriber_group instead of
gsm_network parameters.

Since there are some places where a pointer to the gsm_network is
needed but where only a gsm_subscriber is available, a 'net' back
pointer is added to the group struct, too. Nevertheless subscr group
and network could be separated completely, but this is not the topic
of this commit.

Sponsored-by: On-Waves ehf
2014-12-05 14:59:02 +01:00
Holger Hans Peter Freyther 94f83e1787 smpp: Fix small typo in the comment 2014-07-19 19:02:46 +02:00
Holger Hans Peter Freyther ca3c256579 sms: Kill the sms->sender and use addr/ton/npi throughout the code
This is an incompatible database schema change. Store the type of
the address in the database for both the sender and the receiver.

Currently it is possible to use SMPP to store a SMS and the NPI
and TON will be lost on the delivery of the SMS. The schema is
changed to make the delivery always use the right NPI/TON. This
patch is not ready for the master branch as there is no upgrade
path for the HLR yet.
2014-04-30 15:31:57 +02:00
Harald Welte 7e40be3949 SMPP: UCS2 data_coding is 0x08, not 0x80!
As can clearly be seen from SMPP Spec v3.4 Chapter 5.2.19,
a SUBMIT-SM with data_coding == 0x08 is UCS2, not with 0x80.

Thanks to ciaby@rhizomatica.org for reporting the bug.
2014-02-21 13:21:03 +01:00
Holger Hans Peter Freyther 095bd36627 smpp: In case we know the receiver set the context for logging 2013-12-29 20:30:02 +01:00
Harald Welte 045f402298 SMPP: use VTY setting for E212/E164 in ALERT NOTIFICATION
There's a VTY option by which for every ESME the user can specify if the
E.212 or E.164 number should be used in DELIVER-SM.  The ALERT
notifications generate by subscriber LU have so far always contained the
E.212 (IMSI) rather than E.164 (MSISDN) which is a bit inconsistent.

Rather than copying code, we create a new function that implements
ALERTing all ESMEs.
2013-08-03 19:20:37 +02:00
Harald Welte 99e273db00 SMPP: convert a SMMA to a SMPP ALERT NOTIFICATION 2013-08-03 19:20:36 +02:00
Harald Welte 1aeb2af75d SMPP: don't get stuck in case of SMS memory exceeded
If the MS memory for SMS is exceeded and we get an RP-layer error, we
need to report that back to the (transaction-mode) ESME.  Otherwise the
ESME will wait forever after sending a SUBMIT-SM without ever receiving
a response to it.

Thanks to Holger for catching this.
2013-08-03 19:20:36 +02:00
Holger Hans Peter Freyther a7328a5642 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)
2013-07-27 20:03:10 +02:00
Holger Hans Peter Freyther 921b2278df smpp: Fix possible NULL dereference of the emse->acl
The esme->acl is treated like it can be NULL in other places
of the code. Assume it can be NULL during this check as well.

Dereference after null check (FORWARD_NULL)
9. var_deref_op: Dereferencing null pointer "esme->acl".

Fixes: Coverity CID 1042374
2013-07-14 09:04:51 +02:00
Holger Hans Peter Freyther ae9d8d3131 smpp: Checking an array for NULL will always be false
The if (submit->short_message) and if (smsc->system_id) will
always be true.

Fixes: Coverity CID 1042371, CID 1042372
2013-07-14 09:04:50 +02:00
Harald Welte 995ff35f39 Fix license header at smpp_openbsc.c and smpp_smsc.c
As Holger pointed out, they contained a GPLv2+ disclaimer rather than
the AGPLv3+ which we use for OpenBSC.  This is not an incompaibility,
but was done unintentionally.  The code was always mean to be under
AGPLv3+.

Nevertheless, anyone using those two files in a version up to this
commit have the right to use it under GPLv2+ as well.  This is not
applicable for any versions after this commit.
2013-07-13 16:35:32 +02:00
Harald Welte 4c5babc06c smpp_openbsc: Fix parsing of 03.38 data coding scheme in MO case 2013-07-11 14:29:31 +02:00
Harald Welte c75ed6d593 SMPP: Add new 'dcs_transparent' ESME setting
If an ESME has the dcs_transparent config flag, then the TP-DCS
of MO-SMS is transparently passed to SMPP and not converted to SMPP
specific data_coding values.

This is needed in cases where ESMEs actually care about the exact
TP-DCS, as the conversion from TP-DCS to SMPP data_coding is not
bijective.
2013-05-28 20:59:25 +02:00
Harald Welte 27d5e65640 SMPP: Pass on 0xFx style DCS from SMPP to GSM
There are multiple ways how the TS 03.38 TP-DCS can indicate 8bit or
7bit messages.  SMPP has it's own data coding specification, which is
different from TS 03.38.

However, some SMPP ESMEs want to be able to have fine-grained control
over the TP-DCS indicated in the TPDU header.  If such values like 0xF6
are used in SMPP, we now transparently pass them on to the GSM side.
2013-05-28 20:37:07 +02:00
Harald Welte 3f78600346 SMPP: Implement SMPP Osmocom Estensions on MO-SMS
An ESME can now be configured in the VTY to enable osmocom-extensions,
which will add vendor-specific SMPP TLVs for RxLev/RxQual/ARFCN/IMEI and
transmit power to the SMPP DELIVER-SM message type.
2013-03-13 15:30:48 +01:00
Harald Welte 76afa16d04 SMPP: Fix crash on delivery of incoming SUBMIT-SM
As bsc_gsmnet is NULL at the time we call smpp_openbsc_init(),
we later run into segfaults with subscribers that don't have a
subscr->net set.

However, we cannot delay smpp_openbsc_init() until after
bsc_bootstrap_network(), as we then fail to parse the SMPP specific
VTY/config file options...
2013-03-13 15:30:48 +01:00
Holger Hans Peter Freyther 6a85c15eea smpp: Fix a memleak of the SMS on the submit path 2013-01-20 19:21:48 +01:00
Holger Hans Peter Freyther b5a4edd09b SMPP: Inform the SMS Queue that a SMS was submitted to kick the queue
Work on the 'forward' part.. tell the sms queue that something has been
submitted for it..

Conflicts:
	openbsc/src/libmsc/smpp_openbsc.c
2013-01-20 19:21:34 +01:00
Harald Welte 0d0c9ec5c5 use DLSMS and not DSMS in SMPP related code (merge with master) 2012-11-24 11:13:19 +01:00
Harald Welte b8a1f967c5 SMPP: fix handling of UDH / multi-part for 7-bit messages
... I would have never believed it is such a broken mindfuck.
2012-11-24 11:09:21 +01:00
Harald Welte c0de14da8f SMPP: add small utility program 'smpp_mirror'
This program binds as ESME transceiver to a SMSC and simply mirrors back
all SMS that it receives.
2012-11-24 11:09:21 +01:00
Harald Welte e07b6a77e5 SMPP: Implement support for MO SMS
Each ESME can have a number of prefix-matching routes, or it can
be a 'default route' to whcih all otherwise unknown SMS destinations
are routed.
2012-11-24 11:07:30 +01:00
Harald Welte 338e3b3b4b SMPP: VTY configuration of SMPP code, authentication support 2012-11-24 11:07:29 +01:00
Harald Welte 1a2993adb7 SMPP: fix subscriber reference leak.
subscr_get_by_* is already increasing the refcount, we shouldn't
do that a second time (thanks, Holger).
2012-11-16 22:00:10 +01:00
Harald Welte 9122c13933 SMPP: More logging in error cases, fix UDH in 7bit ASCII 2012-11-16 22:00:10 +01:00
Harald Welte 8a1b056bff SMPP: Implement ALERT NOTIFICATION on attach/detach of subscribers 2012-11-16 22:00:10 +01:00
Harald Welte 9ad0362429 SMPP: Deal with DCS according to 03.38 and respect TP-PID 2012-11-16 22:00:09 +01:00
Harald Welte e94db49698 SMPP: Introduce ESME reference coounting
In case a ESME disappears after SUBMIT-SM but before the MT-SMS
is delivered (transaction mode), we have to make sure the esme
structure still exists.
2012-11-16 22:00:09 +01:00
Harald Welte d4bdee79e9 SMPP: Implement transaction mode for SUBMIT-SM
WARNING: if the ESME disconnects, osmo_esme gets freed, and
sms->smpp.esme might point to invalid/unallocated memory!
2012-11-16 22:00:09 +01:00
Harald Welte f1033cc752 Initial support of SMPP interface for MT-SMS 2012-11-16 22:00:09 +01:00