Commit Graph

806 Commits

Author SHA1 Message Date
Neels Hofmeyr 063a802d46 gtphub: review log levels, add level arg to LOG().
For maintenance, it is convenient to have the log level explicit at each
log statement.

Tweak some log levels / message formatting while at it.

Sponsored-by: On-Waves ehi
2015-11-16 15:17:20 +01:00
Neels Hofmeyr 390e910125 gtphub: add logging labels to bind struct.
Allow logging the plane (Ctrl/User) and side (SGSN/GGSN) in functions that only
have a gtphub_bind* to work with, by adding a constant label to each bind.

Sponsored-by: On-Waves ehi
2015-11-16 15:17:00 +01:00
Neels Hofmeyr a208c734a2 gtphub: don't always try to do GGSN resolution.
If a GGSN is already known from unmapping, don't invoke a host resolution.
In a live working environment, it wouldn't hurt, because the lookups would
mostly return from the cache. But in a testing environment without a name
server, it barfs on every packet.

Sponsored-by: On-Waves ehi
2015-11-16 15:16:52 +01:00
Neels Hofmeyr 16c3f57ed6 gtphub: fix numerous segfaults, and other stupidities.
Initialize llist_heads to empty (2 were missing). Move those for struct gtphub
instances to gtphub_zero() (one moved, one added).

In from_[gs]gsns_read_cb(), use a return type that can actually reflect
negative return values.

resolved_addr.buf: no need to take the address of a byte array var
(cosmetic).

Pass the proper user data address to sgsn_ares_query(), not the address of
the pointer holding the user data address.

Initialize ggsn_lookup->expiry_entry (was missing). Publish the function for that
in gtphub.h so gtphub_ext.c can use it.

Sponsored-by: On-Waves ehi
2015-11-16 15:16:47 +01:00
Neels Hofmeyr 3317c84c16 gtphub: Add logging for ares queries.
Looking for a segfault, I added a lot of logging. This may be useful for
live testing ares, leaving it in there for now.

Note: I still want to clean up the logging concerning log levels etc. once
we're out of alpha.

Sponsored-by: On-Waves ehi
2015-11-16 15:16:44 +01:00
Neels Hofmeyr c83cd898ef gtphub: fix handling of sender from nonstandard port.
Allow a peer sending from an unknown port but a known address, and just
create the port (and unmap the seq nr back to this port later to return
the response to the sender).

Only an SGSN on the Ctrl plane is allowed to make the very first contact
from an unknown address.

Sponsored-by: On-Waves ehi
2015-11-16 15:16:39 +01:00
Neels Hofmeyr e921e32c82 gtphub: fix User plane decoding, add unit test.
Split decoding return code GTP_RC_PDU in GTP_RC_PDU_C and GTP_RC_PDU_U.
Don't do IEs in GTP_RC_PDU_U.

Add a unit test for User plane data, expected to fail (nonstandard port case).

In gtphub_test.c, tweak logging so that it is easily visible which test
produced which output. Also add the global resolved_sgsn_addr and ggsn_sender,
symmetrically to resolved_ggsn_add and sgsn_sender.

Sponsored-by: On-Waves ehi
2015-11-16 15:16:37 +01:00
Neels Hofmeyr c227594394 gtphub: make test code reusable for future tests.
Generalize to make the PDP ctx message definitions and "sending" of messages
from SGSN->gtphub->GGSN and back reusable in future tests.

Publish gsn_addr_from_sockaddr() in gtphub.h for use in gtphub_test.c.

Use an osmo_sockaddr for resolved_ggsn_addr, because one is needed for
comparison in probably every future test.

Add LVL2_ASSERT() to print assertion message and return instead of abort,
so that functions can be called from several tests without losing the
info of which test caused it from which line.

Use globals for struct gtphub and time_t now, to reduce nr of args that need to
be passed around when writing tests. Add a default test setup function.

Sponsored-by: On-Waves ehi
2015-11-16 15:16:36 +01:00
Neels Hofmeyr 5b664f4b9b gtphub: add/fix IMSI and APN IE error handling
Sponsored-by: On-Waves ehi
2015-11-16 15:16:34 +01:00
Neels Hofmeyr bb3d6785e1 gtphub: fix Echo behavior: respond directly.
Up to now I used the Echo as a test for sequence nr mappings. But Echos
should be handled differently: they are scoped on the link and an Echo
response should be sent right back to the requester.

Sponsored-by: On-Waves ehi
2015-11-16 15:16:32 +01:00
Neels Hofmeyr 30f7bcbd79 gtphub: add first bits of GRX ares
For the resolving function, change the function signature to return a
gtphub_peer_port. In consequence, publish two functions concerned with
gtphub_peer_port instances for use in test and gtphub_ext.c.

Add GGSN resolution queue, callback and cache. Simple implementation: if an
SGSN asks for a GGSN, it will first get no answer, and I hope it will ask again
once the GGSN is in the cache.

Within gtphub_ext.c, have a dummy sgsn struct, as the sgsn_ares code currently
depends on it (half the functions pass an sgsn instance pointer around, but the
other half use the global one).

In the unit tests, wrap away the ares initialization so that they can work
without a DNS server around. The netcat test breaks because of this, will
remove it.

Using sgsn_ares, implement the gtphub_resolve_ggsn_addr() function, I hope:
untested.

Minor cosmetics just to see if you're paying attention... ;)

Sponsored-by: On-Waves ehi
2015-11-16 15:16:30 +01:00
Neels Hofmeyr c8a614d2e9 Add GTP hub initial code base.
First steps towards a new GTP hub. The aim is to mux GTP connections, so that
multiple SGSN <--> GGSN links can pass through a single point. Background:
allow having more than one SGSN, possibly in various remote locations.

The recent addition of OAP to GSUP is related to the same background idea.

(This is a collapsed patch of various changes that do not make sense to review
in chronological order anymore, since a lot of it has thorougly transmorphed
after it was first committed.)

Sponsored-by: On-Waves ehf
2015-11-16 15:16:26 +01:00
Neels Hofmeyr 65482c919f sgsn_vty.c: fix typo 2015-11-10 22:53:15 +01:00
Holger Hans Peter Freyther 98fa3dc1c6 gbproxy: Count more GSM 04.08 messages
Extend the ul/dl counting to count the usual messages on the
Gb interface. Add counters for the attach, routing area update,
pdp context activation and deactivation procedures. Update the
test result with the new counters.
2015-11-10 09:35:30 +01:00
Jacob Erlbeck 46caed8fc4 stats: Set class_id in rate_ctr group descriptions
This commit adds the class_id initialiser to all rate_ctr_group_desc
definitions.

Sponsored-by: On-Waves ehf
2015-11-02 16:04:16 +01:00
Jacob Erlbeck 64630cccc7 stats: Enable stats for sgsn, gbproxy, nitb, bsc, nat
This commit initialises and enables the stats subsystem for the given
binaries.

Sponsored-by: On-Waves ehf
2015-11-02 16:01:27 +01:00
Neels Hofmeyr 568a727550 oap: add OAP config to VTY
Sponsored-by: On-Waves ehf
2015-11-02 12:56:49 +01:00
Neels Hofmeyr 9c534fdbe8 gsup/oap: add OAP to GSUP client.
Trigger an OAP registration upon IPA connect. Feed incoming OAP messages to
oap_handle() and send replies returned by it.

Add oap_config to sgsn_config (todo: vty).

Sponsored-by: On-Waves ehf

[hfreyther: Fix coding style]
2015-11-02 12:56:47 +01:00
Neels Hofmeyr d739f092be oap: implement initial OAP API.
Add oap.[hc] and oap_messages.[hc].

Sponsored-by: On-Waves ehf
2015-11-02 12:56:41 +01:00
Neels Hofmeyr d48f057328 libcommon: soak up three static functions.
Add new kitchen sink openbsc/utils.h and libcommon/utils.c to make three so far
static functions public (so I can use them in the upcoming OAP code).

A place to put them could have been the gprs_utils.h, but all general functions
in there have a gprs_ prefix, and todo markings to move them away. All other
libcommon headers are too specific, so I opened up this kitchen sink header.

Replace the implementation of encode_big_endian() with a call to
osmo_store64be_ext(). See comments.

Apply the change in Makefiles and C files.
2015-11-02 12:56:40 +01:00
Holger Hans Peter Freyther fe60cfb1d6 sgsn: Fix up the VTY doc strings
The documentation needs to end with a \n and T3316
needs to have some text. I think it is the T3316
timer that has no action on the network side.

<command id='timer t3312 &lt;0-65535&gt;'>
        <param name='&lt;0-65535&gt;' doc='(null)' />

Documentation error (missing docs):
<command id='timer t3322 &lt;0-65535&gt;'>
        <param name='&lt;0-65535&gt;' doc='(null)' />

Documentation error (missing docs):
<command id='timer t3350 &lt;0-65535&gt;'>
        <param name='&lt;0-65535&gt;' doc='(null)' />

Documentation error (missing docs):
<command id='timer t3360 &lt;0-65535&gt;'>
        <param name='&lt;0-65535&gt;' doc='(null)' />

Documentation error (missing docs):
<command id='timer t3370 &lt;0-65535&gt;'>
        <param name='&lt;0-65535&gt;' doc='(null)' />

Documentation error (missing docs):
<command id='timer t3313 &lt;0-65535&gt;'>
        <param name='&lt;0-65535&gt;' doc='(null)' />

Documentation error (missing docs):
<command id='timer t3314 &lt;0-65535&gt;'>
        <param name='&lt;0-65535&gt;' doc='(null)' />

Documentation error (missing docs):
<command id='timer t3316 &lt;0-65535&gt;'>
        <param name='&lt;0-65535&gt;' doc='(null)' />

Documentation error (missing docs):
<command id='timer t3385 &lt;0-65535&gt;'>
        <param name='&lt;0-65535&gt;' doc='(null)' />

Documentation error (missing docs):
<command id='timer t3386 &lt;0-65535&gt;'>
        <param name='&lt;0-65535&gt;' doc='(null)' />

Documentation error (missing docs):
<command id='timer t3395 &lt;0-65535&gt;'>
        <param name='&lt;0-65535&gt;' doc='(null)' />

Documentation error (missing docs):
<command id='timer t3397 &lt;0-65535&gt;'>
        <param name='&lt;0-65535&gt;' doc='(null)' />
2015-11-02 12:56:37 +01:00
Harald Welte 69ca8f01ec SGSN: Fix typo in VTY license statement.
It mentioned AGPLv3+ and refers to the hyperlink of v3, but still
stated "Version 2 or later".  That was a typo at the time.
2015-10-29 10:36:28 +01:00
Daniel Willmann 537d480f39 gprs/gb_proxy: Use RAND_bytes for gbproxy TLLI/TMSI allocation
This change has some implications for the test case. It manipulated
bss_ptmsi_state and sgsn_tlli_state variables to make the output of
rand_r() and thus the TLLI/TMSI used predictable.
This possibility is gone when using RAND_bytes() so instead it is
overridden by a function that returns a deterministic sequence of values
(0x00dead00, 0x00dead01, ...). The test cases are adapted to expect
these values instead of the pseudo random values before.

The gbproxy_test stdout file changes as well, but only where the
TLLI/TMSI is displayed (in the hex dumps as well as the TLLI cache
entries).  All other output is the same.
2015-10-13 10:20:26 +02:00
Daniel Willmann 044ce5fb84 gprs: Use RAND_bytes for p-tmsi
[hfreyther: Link to libcrypto, include header, add uint8_t* cast]
2015-10-13 10:00:16 +02:00
Holger Hans Peter Freyther 9861c122dd sgsn: Fix pattern for too long msisdn
We don't care how many bytes the length has but the
destination we want to copy to.

Fixes: CID#1296813
2015-10-12 11:06:34 +02:00
Holger Hans Peter Freyther fa07b489dc Revert "gprs: Use RAND_bytes for p-tmsi"
The commit not compiling/linking should have been a strong
indicator that it has not been tested either.

This reverts commit 6cf0249dac.
2015-10-12 09:55:59 +02:00
Daniel Willmann 6cf0249dac gprs: Use RAND_bytes for p-tmsi
[hfreyther: Link to libcrypto, include header, add uint8_t* cast]
2015-10-12 09:05:48 +02:00
Neels Hofmeyr 06cfe00c71 gsup: factor out header composition & sending.
Move IPA header composition and sending to new static gsup_client_send() (so I
can use it in the upcoming OAP code).

Sponsored-by: On-Waves ehf
2015-10-07 18:59:01 +02:00
Neels Hofmeyr 130be40c3e sgsn_main: in -h, print default config file 2015-09-24 17:29:08 +02:00
Holger Hans Peter Freyther 3e4e8cfb74 vty: Change the return type from enum to int
clang complained that different enums are mixed with the
return type and we actually want this to be an int now.
2015-09-24 15:39:30 +02:00
Holger Hans Peter Freyther 925504bfe0 gbproxy: Add quirk commands to allow upgrade from pre-release
The pre-release didn't add a newline after the apn and the patching
pattern command. Create a quirk command that combines both. The
pre-release didn't include a differentation between routing and
patching.

The TLLI handling has a different and more generic name now. Make
it handle the old one that is actively used.

Add a file with the broken format and the standard config file
test should pick it up.
2015-09-24 10:28:43 +02:00
Harald Welte ecff2424e5 Use 'ROUTING AREA' consistently, not 'ROUTEING AREA'
The spec unfortuantely uses both terms and has no consistent spelling,
but in our logging output we can at least try to be consistent.
2015-08-18 19:35:02 +02:00
Harald Welte b9845f937e GSM/GPRS 04.08: Don't print numeric mobile identity types
I guess none of our users knows what a mi_type=0x02 is, but most would
know what an IMSI or a TMSI is.  So let's use the newly introduced
gsm48_mi_type_name() function to fix this.
2015-08-18 19:35:02 +02:00
Harald Welte 6b39feedc7 GMM: fix format string compiler warning 2015-08-18 19:35:02 +02:00
Harald Welte 601cf12f81 GMM: Don't use DGPRS logging category from GMM 2015-08-18 19:35:02 +02:00
Harald Welte eb98c74fb1 GMM: use MMCTXP whenever possible to include MS identity in log output 2015-08-18 19:35:01 +02:00
Harald Welte 22df4ac848 LLC: Don't dispatch XID frames into GMM
For some odd reasons the XID is not a separate SAPI but has been kludged into
the GMM SAPI.  This means we ahve to be careful not to dispatch XID frames into
GMM.  We do this by introducing an explicit check for UI frames before the
dispatch to GMM.

The previous code already was doing "the right thing" but printed occasional
messages like "gprs_gmm.c:2082 Unknown GSM 04.08 discriminator 0x01: 01 00 0e
00 32 11 03 16 01 90 63 28 0b".  Those should be gone after this patch.
2015-08-18 19:35:01 +02:00
Harald Welte 78fa99103d LLC: Don't feed length=0 frames to SNDCP / GMM 2015-08-18 19:35:01 +02:00
Harald Welte 6a19dd0d31 GMM: add hexdump in case of unknown pdisc/msgtype 2015-08-18 19:35:01 +02:00
Harald Welte 9450882901 sgsn: make all SGSN timers configurable via the VTY 2015-08-18 19:35:01 +02:00
Holger Hans Peter Freyther 0958938d4e sgsn: Simplify finding/using the first address of the result
The loop was used to print all returned addresses but we can
simply pick the first one. This is fixing a coverity issue that
the loop will be executed eaxactly once (and that was on
purpose).

Simplify the code and just take the first element (which might
be NULL).

Fixes: Coverity CID#1302852
2015-06-02 09:51:32 +02:00
Holger Hans Peter Freyther f2e114ac85 sgsn: seleted_apn_str might be NULL do not strcpy
The subscriber might simply not be allowed to use the APN
that was specified. So selected_apn_str might very well be
NULL.

Fixes: Coverity CID#1302853
2015-06-02 09:46:32 +02:00
Holger Hans Peter Freyther 65b0efe56e sgsn: Check the return value of osmo_fd_register
We can't do much in case the fd is failing to be registered.
There should be a timeout that is catching this and it might
be able to repair it self.

Fixes: Coverity CID#1302854
2015-06-02 09:46:11 +02:00
Holger Hans Peter Freyther 9cb249bf84 sgsn: Do not search the name with the "domain" name attached to it
In case the query for "hostname" will fail c-ares will append the
domain name of /etc/resolv.conf and query again. We don't want that
so claim we provide a list of domain names and then don't provide
any.

I didn't intend to have pushed the c-ares code to master yet.
2015-06-01 18:46:12 +02:00
Holger Hans Peter Freyther b7ae0b34f9 ggsn: The id is a uint32_t don't print it as signed
This was noticed as I started to use UINT32_MAX for
dynamically created GGSNs.
2015-05-29 15:11:55 +02:00
Holger Hans Peter Freyther a5a6da46a0 sgsn: Allow to specify the DNS servers that should be used
If no server is specified the default list will be used. This
allows to separate the servers for the local network and GRX
from each other.
2015-05-25 15:58:02 +08:00
Holger Hans Peter Freyther 39c430ee29 sgsn: Allow to resolve the IPv4 address of a GGSN through DNS
For real networks we need to check if the requested APN string
is allowed and then resolve the GGSN address through DNS. There
are countries with two or three digit MNCs and one could either
try to keep a list of countries that have two/three digits or
just try both of them. I have opted for the later for the ease
of the implementation.

C-Ares doesn't allow to cancel a request so we will need to
have the MMCTX and the Lookup have different lifetimes. We simply
set ->mmctx to NULL in case the MMCTX dies more early.

The selected and verified apn_str will be copied into the out
parameter. In case no static APN/GGSN config is present and the
dynamic mode is enabled a request will be made.
2015-05-25 15:57:57 +08:00
Holger Hans Peter Freyther 66e7106d39 sgsn: Integrate c-ares with the osmocom event loop
c-ares is an asynchronous DNS resolver and we need it to
resolve the GGSN address. This is integrating the library
into our infrastructure. We will create and maintain a list
of registered FDs (c-ares is currently only using one of
them) and (re-)schedule the timer after events occurred.
2015-05-25 15:39:59 +08:00
Holger Hans Peter Freyther ccd2312d10 sgsn: Create a copy of the msgb for later usage
When needing to do an asynchronous DNS query we need
to keep the TLV data around. So create a wrapper that
takes a copy of it and frees it after the call. I can
change the code to add an out parameter to decide if
the msgb should be freed or not.

Pick network failure in case the msgb could not be
cloned in the hope the MS will retry then.
2015-05-25 15:39:59 +08:00
Holger Hans Peter Freyther 7605bdc02c sgsn: Re-factor the activate PDP code for future changes
A real SGSN will dynamically resolve the APN name into the
GGSN IP Address. This means that after we have collected all
information we need to start to resolve the GGSN and then
can continue.
2015-05-25 14:38:02 +08:00
Holger Hans Peter Freyther 08bb84b04e sgsn: Deal with no static ggsn being configured at all
In case no static ggsn is configured the code would crash
with the assumption that there is always such a GGSN.
2015-05-25 14:38:01 +08:00
Holger Hans Peter Freyther 9270d99f3d sgsn: If there is a subscr don't allow an empty list
This is a left-over from the initial system where no PDP
was provided by the system. For now if there is a subscr
attached and no PDP context provisioned. He is not allowed
to have a data connection.

Update the testcase to create the pdp list entry more
early with a wildcard and then change it to a specific
match.
2015-05-25 14:38:01 +08:00
Holger Hans Peter Freyther 8ee13e2937 sgsn: Extract the hlr Number into the mm context
Include the hlr-Number of the subscriber in the CDR. This is useful
for debugging and understanding which equipment was used during the
test. In contrast to the MSISDN the '+' is emitted as the number
must be in international format already.
2015-05-24 12:32:23 +08:00
Holger Hans Peter Freyther 10c0f56a0e gsup: Copy the hlr-Number and use it during purge
Copy the hlr-Number into the sgsn_data and use it during
the purgeMS. There is no unit test that looks at the data
we send so I manually verified this by looking at the output.
Below is the output of the test that purges the subscriber.

<000f> gprs_subscriber.c:170 SUBSCR(123456789012345) Sending GSUP, will send: 0c 01 08 21 43 65 87 09 21 43 f5 09 07 91 83 61 26 31 23 f3
2015-05-24 12:32:23 +08:00
Holger Hans Peter Freyther 0bb5674cde gsup: Decode/Encode the hlr-Number in the GSUP message
Implement it similar to the msisdn_enc/msisdn_enc_len and
extend the testcase to include it as well.
2015-05-24 12:32:23 +08:00
Holger Hans Peter Freyther 0f7a279a06 sgsn: Change the selection mode to verified
We have verified/selected the APN. Either based on the subscriber
data, a global APN match. But at least this SGSN has looked at
what the MS has asked for and then selected a matching GGSN.
2015-05-22 10:05:56 +08:00
Holger Hans Peter Freyther c1c6a28c8d sgsn: Reserved bits should be set to 1
Bits 3 to 8 are spare bits and should be set to 1 in etsi
specifications. Do that.
2015-05-22 10:05:49 +08:00
Holger Hans Peter Freyther 072bee5c85 sgsn: Clear LAC/RAC value for the routing area identity
Clear LAC/RAC with pre-defined value in the RAI.

3GPP 29.060 v7.17.0 section 7.3.1 page 23:

"The SGSN may include the Routeing Area Identity (RAI) of the
SGSN where the MS is registered. The MCC and MNC components shall
be populated with the MCC and MNC, respectively, of the SGSN
where the MS is registered. The LAC and RAC components shall be
populated by the SGSN with the value of 'FFFE' and 'FF',
respectively.”
2015-05-17 17:36:23 +02:00
Holger Hans Peter Freyther d6900dfba4 sgsn: Give the IMEI to the GGSN for analysis
Most SGSNs pass the IMEI(SV). We currently only enquire about
the IMEI and then pad the 'SV' with 1111b (thanks to the encoding
routine). Sadly it insists on always writing the length which
means we have to memmove the data around by a single octet.

Manually verified using the pcu-emu and looking at the trace
using wireshark.
2015-05-17 17:23:57 +02:00
Holger Hans Peter Freyther 6ddb6ac028 sgsn: Encode the ULI for the PDP context creation ack
Give the GGSN another opportunity to determine which tarif
to apply for the SGSN/subscriber. This code assumes tha the
RAN is a GERAN system but the assumption has been made in
other places as well.
2015-05-17 17:23:57 +02:00
Holger Hans Peter Freyther 22093ef964 sgsn: Always include the routing area identity
For PDP context creation we always want to include the RAI
for the current mmctx. This might help commercial GGSNs to
determine which charging to apply.
2015-05-17 17:23:57 +02:00
Holger Hans Peter Freyther 77ff1c40e2 cdr: Remember the charging id supplied by the GGSN
The charging_id is provided by the GGSN. Copy it into the CDR
part of the data structure so it will remain present until after
the pdp context has been deleted.
2015-05-17 17:23:57 +02:00
Holger Hans Peter Freyther c15c61c401 sgsn: Add VTY configuration for the CDR module
Make it possible to set a filename to use for the CDR. By
default no CDR will be generated. Forbid to set the interval
of 0 seconds as this will cause a lot of work. Add a very
basic VTY test.
2015-05-06 17:46:08 +02:00
Holger Hans Peter Freyther 4f5b8237ec sgsn: Create an initial and limited CDR module
This is consuming the new signals and allows to install several
different CDR/observing/event/audit modules in the future. For
getting the bytes in/out the code would have had to undo what the
rate counter is doing and at the same time adding a "total" to
the ratecounter didn't look like a good idea, the same went for
making it a plain counter.

Begin writing the values one by one and open/closing a new FILE
for every log messages. This is not efficient but easily deals
with external truncation/rotation of the file (no fstat for and
checking the links and size). As usual we will wait and see if
this is an issue.

Add some new members to our PDP context structure to see what it
is about.
2015-05-06 17:43:15 +02:00
Holger Hans Peter Freyther b100895557 sgsn: Add various signals consumed by CDR or other client code 2015-05-06 17:14:51 +02:00
Holger Hans Peter Freyther 20de3ae17c sgsn: Extract the MSISDN from the subscr data structure
In case there is a subscr attached to the MM context and there
is an encoded MSISDN we will attempt to decode it and in case
of an international number prepend a '+'. Assume that the array
size of gsm_mmcc_called->number is as big as ctx->msisdn for the
strncpy.
2015-05-06 17:14:51 +02:00
Holger Hans Peter Freyther b448dd849a sgsn: Make the free function internal
All calls should and do go through the
sgsn_mm_ctx_cleanup_free function.
2015-05-06 17:14:51 +02:00
Holger Hans Peter Freyther d05e06989d sgsn: Show the QoS that has been assigned 2015-05-05 21:15:55 +02:00
Holger Hans Peter Freyther f7b3826f03 sgsn: Dump the E164 (encoded) assigned to the subscriber 2015-05-05 21:15:44 +02:00
Holger Hans Peter Freyther 4bd931f96d sgsn: Handle different levels of QoS
If QoS is only three bytes it does not include the allocation/
retention policy. Otherwise it does. Copy it depending on that.
We should have a macro for the clamping to reduce code duplication.

The insanity does come from the MAP data and this seems to be
the easiest in terms of complexity. It is an array of bytes that
is transported from MAPProxy to the SGSN and then simply forwarded.

The case of more than three bytes is neither unit nor manually
tested so far.
2015-05-05 21:15:20 +02:00
Holger Hans Peter Freyther 8cedded88c sgsn: Store subscribed QoS and attempt to use it
sgsn_create_pdp_ctx should use the subscribed QoS. When selecting
the PDP context we inject the QoS to be used into the TLV structure
and use it during the request. Assume a "qos-Subscribed" structure
only with three bytes and prepend the Allocation/Retention policy
to the request.
2015-05-05 21:11:16 +02:00
Holger Hans Peter Freyther 9ba273d365 sgsn: Copy the msisdn to the sgsn_data and use it in PDP activation
The MSISDN should be present for "security" reasons in the first
activation of a PDP context. Take the encoded MSISDN, store it for
future use and then put it into the PDP activation request.

The MM Context contains a field for a decoded MSISDN already. As
we need to forward the data to the GGSN I want to avoid having to
store TON and NPI in another place. Simply store the data in the
encoded form.
2015-05-05 21:09:53 +02:00
Holger Hans Peter Freyther 49c1a7156c gsup: Extract the QoS field
Add roundtrip test for the new QoS IE. It will be consumed in
later commits.
2015-05-05 21:09:20 +02:00
Holger Hans Peter Freyther b927f1c319 gsup: Extract the new MSISDN string
Extract the new MSISDN IE from the GSUP message and verify that
it is read/written to the message.
2015-05-05 21:08:00 +02:00
Holger Hans Peter Freyther d4b03187c6 sgsn/gtp: Fill out the optional RAT type
Assume we are always a GERAN network right now.
2015-04-23 17:01:17 -04:00
Holger Hans Peter Freyther 8e6ecc9667 misc: Fix warnings about size of size_t in printf
Fixes warnings like:

warning: format '%d' expects argument of type 'int', but argument 3 has type 'long int' [-Wformat]
2015-04-23 17:01:09 -04:00
Jacob Erlbeck 5b51205187 gprs: Fix GSUP cancel_type handling (Coverity)
When handling an incoming GSUP cancellation request, the cancel_type
if effectively ignored, such that is always handled as
GPRS_GSUP_CANCEL_TYPE_UPDATE and never as WITHDRAW.

This commit fixes the expression used to set the variable
is_update_procedure.

Fixes: Coverity CID 1267739
Sponsored-by: On-Waves ehf
2015-04-07 20:13:43 +02:00
Holger Hans Peter Freyther 9c20a5f45c sgsn: Add easy APN commands with just the name
For most configurations we don't address multiple GGSNs but
only want to enforce a list of APNs. In the future we might
add a special global GGSN context but not right now.

Fixes: SYS#593
2015-02-06 16:44:58 +01:00
Jacob Erlbeck ca69b0f68d Revert "gprs: Block other GSUP procedures during PURGE_MS"
This reverts commit f81cacc681.

Since the PURGE MS retry mechanism had been removed, this feature
is not used anymore. It just makes the code more complex.

Conflicts:
	openbsc/include/openbsc/gprs_sgsn.h
	openbsc/src/gprs/gprs_subscriber.c
	openbsc/tests/sgsn/sgsn_test.c
2015-02-06 13:22:24 +01:00
Jacob Erlbeck 277b71e0d8 sgsn: Select GGSN based on APN
Currently the APN IE in the Activate PDP Contex Request and the PDP
data that is stored with the subscriber is ignored completely.

This commit adds the sgsn_mm_ctx_find_ggsn_ctx that checks the APN IE
against the subscriber's PDP data entries if both are present. If
there is no match, the request is rejected.

If an APN IE has not been included but PDP data entries are present,
the function checks all of these entries against the static 'apn'
configuration to find a suitable entry.

If an APN has not been determined so far and any APN is allowed, the
configuration is checked with an empty APN string, to allow for
default configurations based on the IMSI prefix only.

If nothing of this succeeded but the request wasn't rejected either,
and there is no 'apn' configuration at all or if any APN is allowed
but a default configuration ist not present, the GGSN with id 0 is
used (if present).

Otherwise the request is rejected ('missing APN').

Ticket: OW#1334
Sponsored-by: On-Waves ehf
2015-02-06 13:00:29 +01:00
Jacob Erlbeck f345612654 sgsn: Add sgsn_ggsn_ctx_free function
This function will be needed for testing, since the leak check would
fail if the GGSN context are not cleaned up after use.

Sponsored-by: On-Waves ehf
2015-02-06 10:00:03 +01:00
Jacob Erlbeck cb1db8b6d5 sgsn: Add functions to handle APN contexts
This commit adds the exported functions apn_ctx_find_alloc,
apn_ctx_free, apn_ctx_by_name, and apn_ctx_match to manage and
retrieve APN to GGSN mappings.

The following VTY commands are added to 'config-sgsn':

 - apn APN ggsn <0-255>
 - apn APN imsi-prefix PREFIX ggsn <0-255>

which maps an APN gateway string to an SGSN id. The SGSN must be
configured in advance. When matching an APN string, entries with a
leading '*' are used for suffix matching, otherwise an exact match is
done.  When a prefix is given, it is matched against the IMSI. If
several entries match, a longer matching IMSI prefix has precedence.
If there are several matching entries with the same PREFIX, the entry
with longest matching APN is returned.

Ticket: OW#1334
Sponsored-by: On-Waves ehf
2015-02-06 09:56:17 +01:00
Jacob Erlbeck 0e8add601d sgsn: Add PDP info to subscriber data
Currently the PDP info that is transmitted via GSUP is just parsed
and then discarded.

This commit adds a new data structure sgsn_subscriber_pdp_data and
maintains a list of those in sgsn_subscriber_data. The PDP data is
copied from an incoming GSUP UpdateLocationResult message. If that
message contains the PDPInfoComplete flag, the list is cleared before
new entries are added.  The 'show subscriber cache' output now also
shows the PDP data entries.

Note that the InsertSubscriberData message is still not supported.

[hfreyther: Added talloc_free in gprs_subscr_pdp_data_clear]

Sponsored-by: On-Waves ehf
2015-02-06 09:55:39 +01:00
Jacob Erlbeck 9ff82892da gprs: Use 'Network failure' as default cause
This commit adds a check after a GSUP message has been decoded
whether it is an error message and does not contain a cause value.
If his is the case, the cause value is set to 'Network failure', so
that this cause if effectively the default value for error messages.

Sponsored-by: On-Waves ehf
2015-01-30 21:32:26 +01:00
Jacob Erlbeck 07f6e36ab4 gprs: Send GSUP error reply for requests without IMSI
Currently gprs_subscr_rx_gsup_message returns immediately after it
detects that an IMSI has not been given in the received GSUP message.
While this is ok for responses (result or error), a request should
always be answered.

This commit adds code to reply with a corresponding error message
("Invalid mandatory information") when it receives a request without
an IMSI.

Note that the generated error message will not contain an IMSI either.

Sponsored-by: On-Waves ehf
2015-01-30 21:28:07 +01:00
Jacob Erlbeck 8000e0ea50 gprs: Support cancellation type
The cancellation type that is part of the UpdateCancellation message
is currently ignored.

This patch adds the missing glue between the existing GSUP and GMM
support. If the type is not present or has the value updateProcedure
the subcriber and MM context are siliently removed. Otherwise, a
message with cause 'implicitly detached' is sent to the MS. Since the
real cause is not known (the specification neither added a cause IE
nor defined a static cause value), the MS may get the real cause in
the following AttachRej.

Added VTY commands:

- update-subscriber imsi IMSI cancel update-procedure
- update-subscriber imsi IMSI cancel subscription-withdraw

the old form without the cause is no longer supported.

Sponsored-by: On-Waves ehf
2015-01-30 21:27:07 +01:00
Jacob Erlbeck 929acdf6bf gprs: Handle PURGE MS ERR/RES without subscr
Currently the subscr entry is no longer present, when PURGE MS
ERROR/RESULT arrives. In this case, an unspecific notice is logged
('unknown IMSI'). This clutters up the logfile with notices even in
perfectly normal operation.

This commit changes the code path that is used when a subscr cannot
be found for an incoming GSUP message. A check for PURGE MS RESULT
and ERROR is added and gprs_subscr_handle_gsup_purge_no_subscr is
called for these messages instead of gprs_subscr_handle_unknown_imsi.

Sponsored-by: On-Waves ehf
2015-01-28 20:44:40 +01:00
Jacob Erlbeck e988ae471d gprs: Don't use subscr->keep_in_ram in normal operation
Currently the keep_in_ram flag is explicitely reset in
gprs_subscr_cleanup to cover the case, that the VTY 'create'
sub-command has been used to create the subscriber entry.

This commit completely removes keep_in_ram handling from
gprs_subscriber.c and adds a VTY 'destroy' sub-command to reset the
flag and remove the entry. So 'create' and 'destroy' can be used to
manager sticky entries that are kept even when a location
cancellation is done.

Added VTY command:

- update-subscriber imsi IMSI destroy

Sponsored-by: On-Waves ehf
2015-01-28 20:42:58 +01:00
Jacob Erlbeck e671d254cb sgsn: Add sgsn_mm_ctx_cleanup_free for safe shutdown
Currently the MM context cleanup code is distributed over several
functions. sgsn_mm_ctx_free not only frees data structure but also
eventually stops the timer and does the subscriber clean-up.
mm_ctx_cleanup_free (gprs_gmm.c) cleans up the PDP contexts and
unassign the TLLI.

This commit moves the cleanup code from both functions into a new
unifying function sgsn_mm_ctx_cleanup_free that cares about the
clean-up of all related sub-systems.

Sponsored-by: On-Waves ehf
2015-01-28 20:42:52 +01:00
Jacob Erlbeck 555b2e5ac1 sgsn: Don't allow mmctx == NULL in sgsn_update_subscriber_data
Currently, sgsn_update_subscriber_data can be called with mmctx ==
NULL and will find and associate the right context (if present) based
on the subscriber's IMSI. This will not happen in regular use
any more, since sgsn_update_subscriber_data will only be called when
subscribers are used (auth mode 'remote') and in this case
gprs_subscr_get_or_create_by_mmctx will already be called by
sgsn_auth_request. Therefore, MM context and subscriber are always
associated except for some test cases and experimental VTY usage.
The current implementation of sgsn_update_subscriber_data also causes
additional complexity for the deletion on MM contexts to avoid a
ipossible double-free MM contexts.

This commit removes the MM context <-> subscriber association code
from sgsn_update_subscriber_data. That function must always be called
with mmctx != NULL, now. To avoid problems with VTY and test usage,
the calling subscriber function now only call
sgsn_update_subscriber_data when mmctx != NULL, since the purpose of
that function is to update that state of an existing MM context after
subscriber data has been changed.

Sponsored-by: On-Waves ehf
2015-01-28 20:42:52 +01:00
Jacob Erlbeck 120250ad6f gbproxy: Remove dummy definition of subscr_put
The definition of subscr_put in gb_proxy_main.c will break linking if
symbols from libcommon are used. Since subscr_put is in libcommon,
there is no need for this dummy definition anymore.

This patch removes the dummy definition.

Adresses:
../../src/libcommon/libcommon.a(gsm_subscriber_base.o): In function `subscr_put':
/home/jerlbeck/git/build/openbsc/openbsc/src/libcommon/gsm_subscriber_base.c:90: multiple definition of `subscr_put'
gb_proxy_main.o:/home/jerlbeck/git/build/openbsc/openbsc/src/gprs/gb_proxy_main.c:56: first defined here

Sponsored-by: On-Waves ehf
2015-01-27 08:35:18 +01:00
Jacob Erlbeck 306bb993aa sgsn: Don't reset mm->subscr manually in sgsn_mm_ctx_free
Currently the sgsn_mm_ctx_free contains code to reset the mm->subscr
field that is also present in gprs_subscr_cleanup, which is called
directly afterwards.

This commit modifies the code path, so that the cleanup is done by
the gprs_subscr_cleanup function. The additional reference counter
increment is needed, since mm->subscr->mm->subscr (which is the same
like mm->subscr) will be reset (and unref'd) within
gprs_subscr_cleanup. Because the local variable subscr in
sgsn_mm_ctx_free is an additional pointer to the subscriber object,
it is consequent to adjust the reference counter when the assignment
is done.

Sponsored-by: On-Waves ehf
2015-01-27 08:31:36 +01:00
Jacob Erlbeck 3e4e58f349 gprs: Rename gprs_subscr_delete to gprs_subscr_cleanup
The old name is somewhat misleading. The function is rather preparing
the subscriber for a subsequent subscr_free, that is possibly invoked
by a subscr_put. It detaches the subscriber from the MM context and
optionally invokes a PURGE_MS procedure. Therefore the _cleanup
suffix is chosen (see mm_ctx_cleanup_free).

Sponsored-by: On-Waves ehf
2015-01-27 08:31:03 +01:00
Jacob Erlbeck 3ee67ff5c2 gprs: Don't check for EINPROGRESS in gprs_gsup_client_create
Currently, the return value of gsup_client_connect is checked whether
it is < 0 and != -EINPROGESS. Since gsup_client_connect will only
return a negative value on a few permanent errors (not including
EINPROGRESS), rc is always != EINPROGRESS.

This patch removes the explicit check againt -EINPROGRESS and just
leaves the check rc < 0.

Sponsored-by: On-Waves ehf
2015-01-27 08:30:49 +01:00
Holger Hans Peter Freyther abb3478533 gb_proxy: No need to copy optarg
Fixes: Coverity CID 1206578
2015-01-27 08:30:37 +01:00
Jacob Erlbeck 496aee7cb8 sgsn: Ensure 0-terminated imsi strings (Coverity)
Currently the size argument of strncpy is set to sizeof(mm->imsi) in
some places. If the source IMSI string is too long, the terminating
NUL byte in the static mm->imsi field gets overwritten.

This patch limits the size to sizeof(mm->imsi)-1, so that the last
byte of the buffer (that has been initialized to 0) is not
overwritten.

Fixes: Coverity CID 12065751, 12065754, 1206575

Sponsored-by: On-Waves ehf
2015-01-26 10:59:49 +01:00
Jacob Erlbeck 37139e5933 gprs: Do not put the subscr in gprs_subscr_delete
Currently gprs_subscr_delete implicitely calls subscr_put, which
makes the code more complex than necessary (additional subscr_get) in
a few places. It also makes it more difficult to see, whether get/put
are balanced within a function. In addition, the functions are not
named consistently (gprs_subscr_delete vs.
gprs_subscr_put_and_cancel).

This commit changes the semantics of gprs_subscr_delete and
indirectly of gprs_subscr_put_and_cancel to not call subscr_put on
their argument, but to leave that for the caller to do it
explicitely.

It renames gprs_subscr_put_and_cancel to gprs_subscr_cancel to
reflect that change in the name, too.

Sponsored-by: On-Waves ehf
2015-01-26 09:10:06 +01:00
Holger Hans Peter Freyther 1d778fdce3 sgsn: Remove the "permanent" subscriber cache
The subscriber cache would help in case:

  * GPRS DETACH, GPRS ATTACH. In that case we might still
  have some cached authentication tuples we avoid another
  sendAuthenticationInfo request.

  * After a detach the cache expiry would make sure to
  eventually send a purgeMS to the HLR (which might be
  ignored).

At the same time to make the cache work we will need to
make sure to start and stop timers. In case we don't
start we might accumulate subscribers. I am afraid that
the above two benefits do not outweight the complexity
of this implementation.
2015-01-26 09:09:12 +01:00
Holger Hans Peter Freyther e47d4f6d11 sgsn: Remove MM from the list before gprs_subscr_delete is called
Modify sgsn_mm_ctx_free to remove the entry from the
list as otherwise we might double free the context from
within gprs_subscriber_delete.
2015-01-26 09:08:57 +01:00
Jacob Erlbeck 81ffb740f7 sgsn: Remove inactive LLME/MM after inactivity timeout
Currently old LLMEs and MM contexts that haven't been explicitly
detached or cancelled are not removed until another request with the
same IMSI is made. These stale entries may accumulate over time and
severely compromise the operation of the SGSN.

This patch implements age based LLME expiry, when the maximum age has
been reached, the corresponding MM context is cancelled. If such an MM
context doesn't exist, the LLME is unassigned directly.

The implementation works as follows.
 - llme->age_timestamp is reset on each received PTP LLC message
 - sgsn_llme_check_cb is invoked periodically (each 30s)
 - sgsn_llme_check_cb sets the age_timestamp to the current time if
   it has been reset
 - sgsn_llme_check_cb computes the age and expires the LLME if
   it exceeds gprs_max_time_to_idle()

Ticket: OW#1364
Sponsored-by: On-Waves ehf

[hfreyther: Fix typo in comment LMME -> LLME]
2015-01-26 08:51:50 +01:00
Jacob Erlbeck 841d95f867 gprs: Use a macro value to set the 'Periodic RA update timer'
Currently the T3312 timer is directly set as encoded value when
generating the Attach/RAU Accept messages.

This patch adds GSM0408_T3312_SECS and uses it to set the
information element's value.

Sponsored-by: On-Waves ehf
2015-01-26 08:44:27 +01:00
Jacob Erlbeck 8de9c48c99 gprs: Add 'Negotiated READY timer value' IE to Attach/RAU Accept
Currently this optional IE is omitted, so that the optional
'Requested READY timer value' of the corresponding Request message
is used by the MS (or the default value if this IE is not used).

This patch extends gsm48_tx_gmm_att_ack and gsm48_tx_gmm_ra_upd_ack
to always include the IE set to the default value of T3312 (44s,
see GSM 04.08, table 11.4a).

Ticket: OW#1364
Sponsored-by: On-Waves ehf
2015-01-26 08:42:43 +01:00
Jacob Erlbeck 79af67d7c0 gprs: Add GPRS timer conversion functions
Currently, all GPRS timer values are hard-coded. To make these values
configurable in seconds and to show them, conversion functions from
and to seconds are needed.

This patch adds gprs_tmr_to_secs and gprs_secs_to_tmr_floor. Due to
the limited number of bits used to encode GPRS timer values, only a
few durations can be represented. gprs_secs_to_tmr_floor therefore
always returns the timer value that represents either the exact
number (if an exact representation exists) or the next lower number
for that an exact representation exists.

Sponsored-by: On-Waves ehf
2015-01-26 08:41:52 +01:00
Jacob Erlbeck 37184900e7 gprs: Return 0 from gsup_client_connect if ok or retry timer enabled
Currently the gsup_client_connect return 0 if the call to
ipa_client_conn_open was successful and -errno otherwise. This makes
it difficult for the caller to determine, whether the the whole
operation has been cancelled (currently on EBADF, ENOTSOCK,
EAFNOSUPPORT, EINVAL) or whether the GSUP client will retry to
connect after a timeout. This will cause gprs_gsup_client_create to
destroy the GSUP client object, even if the error might be temporary.

This patch changes the function to return 0 if (and only if)
ipa_client_conn_open was successful or the retry timer has been
started. Since the return value 0 doesn't guarantee, that a
subsequent call to gprs_gsup_client_send will succeed, this shouldn't
break anything.

Sponsored-by: On-Waves ehf
2015-01-26 08:41:52 +01:00
Jacob Erlbeck d91934357f sgsn: Restructure the 'update-subscriber' command
This patch drops the following commands:

 - update-subscriber imsi IMSI insert authorized <0-1>
 - update-subscriber imsi IMSI commit

since they are already covered by the 'update-location-result'
sub-command, except that this command doesn't create an new entry if
none is found with the given IMSI.

It adds the following command:

 - update-subscriber imsi IMSI create

which can be used to create a new entry.

Sponsored-by: On-Waves ehf
2015-01-20 16:14:01 +01:00
Jacob Erlbeck 15cc8c8125 sgsn: Fix vty_out newlines
Currently '\n' is used to end lines in the VTY output string
constants instead of inserting VTY_NEWLINE. This leads to incorrect
line starts in error messages.

This patch fixes that accordingly.

Sponsored-by: On-Waves ehf
2015-01-20 16:13:55 +01:00
Jacob Erlbeck d6267d12d8 sgsn: Add SGSN_ERROR_CAUSE_NONE and use it instead of 0
Currently an error_cause of 0 is being used to indicate normal
operation. Albeit this is not a defined GMM cause, the value is not
explicitly reserved.

This commit adds the macro SGSN_ERROR_CAUSE_NONE and uses it for
initialisation (instead of relying on talloc_zero) and comparisons.
The value is set to -1 to be on the safe side. The VTY code is
updated to set the error_cause when using the
'update-subscriber imsi IMSI update-location-result CAUSE' command.

Sponsored-by: On-Waves ehf
2015-01-20 16:13:48 +01:00
Jacob Erlbeck 2585620857 sgsn: Fix access to subscr in sgsn_auth_update (Coverity)
Currently the access to subscr->sgsn_data->error_cause is not
protected against subscr == NULL like it is done in other code paths
of sgsn_auth_update.

This commit adds a conditional to avoid a NULL-dereference.

Fixes: Coverity CID 1264589

Sponsored-by: On-Waves ehf
2015-01-20 16:13:17 +01:00
Jacob Erlbeck d8a65536ec sgsn: Fix P-TMSI generator's distance of equal values
Currently sgsn_alloc_ptmsi uses rand() to get a new P-TMSI and then
sets to upper 2 MSB. Therefore there is no lower limit of the
distance between 2 identical P-TMSI.

This patch changes the implementation to discard any random value
above 2^30 and to generate a new random number in that case until a
fitting number is found (or a repetition limit is reached). This way,
all number below 2^30 within the PRNG's period are used.

Ticket: OW#1362
Sponsored-by: On-Waves ehf
2015-01-20 16:13:01 +01:00
Jacob Erlbeck 87c7ffccea gprs: Support the full cancellation procedure
Currently no GSUP LocationCancellationResult message is sent back to
the peer (HLR), if the procedure succeeded at the SGSN's side.

This patch adds the missing message and put the whole request
handling of this procedure into a separate function.

Ticket: OW#1338
Sponsored-by: On-Waves ehf
2015-01-20 16:12:52 +01:00
Jacob Erlbeck 4dedb27d7e gprs: Don't create a subscr entry on InsertSubscriberData
Currently gprs_subscr_rx_gsup_message creates a subscriber entry if
such an entry doesn't exist for the IMSI within an
InsertSubscriberData GSUP message. This behaviour is not compliant to
GSM 09.02, 20.3.3.2 (Subscriber data management/SGSN) where it is
defined, that an error ("Unidentified subscriber") shall be returned.

This patch removes the case distinction, so that an existing
subscriber entry is required for all incoming GSUP messages.

Sponsored-by: On-Waves ehf
2015-01-20 16:12:45 +01:00
Jacob Erlbeck 9999fd9026 gprs: Add replies for all GSUP requests
Currently, an incoming GSUP request message isn't answered at all if
it is not handled due to an error or missing implementation.

This patch adds GSUP error replies for these requests (and only for
requests). It also adds tests for these cases.

Note that several of these tests check for
GMM_CAUSE_MSGT_NOTEXIST_NOTIMPL, which will have to be changed, when
the features are implemented.

Sponsored-by: On-Waves ehf
2015-01-20 16:12:39 +01:00
Jacob Erlbeck f81cacc681 gprs: Block other GSUP procedures during PURGE_MS
GSM 09.02, 19.4.1.4 mandates that no other MAP procedures shall be
started until the PURGE_MS procedure has been completed.

This patch implements this by adding corresponding state and checks
to gprs_subscr_purge, gprs_subscr_location_update, and
gprs_subscr_update_auth_info. If an Update Location or a Send Auth
Info Req procedure is not started because of blocking, the retry
mechanism is aborted to shorten the blocking time. The outstanding
Purge MS procedure itself is not aborted.

Sponsored-by: On-Waves ehf
2015-01-20 16:12:33 +01:00
Jacob Erlbeck 743dec4c0c gprs: Retry PURGE_MS procedure after timeout
Currently, when the PURGE_MS_REQ to the HLR gets lost (e.g. by a
connection or peer failure), the expired subscriber entry will not get
deleted.

This commit adds a retry mechanism then restarts the procedure after
a timeout (currently 10s). The maximum number of retries is limited
(currently to 3 PURGE_MS messages). If none of these procedures is
completed (either with success or error), the subscriber data is
deleted.

Sponsored-by: On-Waves ehf
2015-01-18 18:37:36 +01:00
Jacob Erlbeck 65fa3f73a1 gprs: Use PURGE MS messages
When a subscriber entry is going to be deleted by SGSN and when the
subscriber info has been obtained from a remote peer via GSUP, the
peer should be informed before the entry is really deleted. For this
purpose, MAP defines the PURGE MS procedure (see GSM 09.02, 19.1.4).

This patch adds support for the PURGE_MS_REQ/_ERR/_RES messages and
invokes the procedure when the subscriber entry is going to be
removed. This only applies if GSUP is being used, the Update
Location procedure has been completed successfully, and the
subscriber has not been cancelled. The removal of the entry is
delayed until a PURGE_MS_RES or PURGE_MS_ERR message is received.

Note that GSM 09.02, 19.1.4.4 implies that the subscriber data is not
to be removed when the procedure fails which is not the way the
feature has been implemented.

Note that handling 'P-TMSI freezing' is not implemented.

Ticket: OW#1338
Sponsored-by: On-Waves ehf
2015-01-18 18:33:31 +01:00
Jacob Erlbeck 69d271376c gprs: Implement PURGE_MS GSUP messages
This commit implements the encoding and decoding of the messages

  - Purge MS Request
  - Purge MS Error
  - Purge MS Result

and adds corresponding tests.

Sponsored-by: On-Waves ehf
2015-01-18 18:33:13 +01:00
Jacob Erlbeck 0f47b8fae7 gprs: Add expiry timeout for subscriber entries
Set the expiry delay after the subscriber has been deleted (e.g. by
freeing the MM context). If cancelled, the subscriber will be deleted
immediately and no timeout will be set. If the expiry time is set to
SGSN_TIMEOUT_NEVER, no timer will be started and the subscriber entry
will be kept until it is cancelled.

The following VTY command is added to the sgsn node:

  - subscriber-expiry-time <0-999999>    set expiry time in seconds
  - no subscriber-expiry-time            set to SGSN_TIMEOUT_NEVER

The default is an expiry time of 0 seconds, which means that the
subscriber entries are wiped out immediately after an MM context is
destroyed.

Note that unused MM contexts are not expired yet. Therefore the
subscriber will only be expired after a successful MM detach.

Sponsored-by: On-Waves ehf
2015-01-18 18:27:19 +01:00
Jacob Erlbeck f06fe29f61 gprs: Pass GMM causes related to the MSC connection
Currently the error causes MSC_TEMP_NOTREACH, NET_FAIL, and
CONGESTION are silently dropped to force the MS to continue. On the
other hand, GSM 04.08/24.008, 4.7.3.1.4 in combination with 4.7.3.1.5,
require the MS to retry the attachment procedure for cause codes
above 15 instead of disabling GPRS. All of the mentioned GMM causes
have codes above 15, so using a REJECT message including the cause
code is a better choice. This way, the retry algorithm based on T3311
(15s, 5 times) and T3302 (default 12min) could be used.

This patch modifies gprs_subscr_handle_gsup_auth_err and
gprs_subscr_handle_gsup_upd_loc_err to proceed like when the access
has beed denied, except that the corresponding subscriber's
information fields are not cleared.

This has been successfully tested which an iphone which enters a
retry loop as it is being described in the specification.

Sponsored-by: On-Waves ehf
2015-01-18 18:23:51 +01:00
Jacob Erlbeck bf34c67f3f gprs: Use LOGGSUBSCRP and LOGMMCTX for logging in gprs_susbcriber.c
To unify the layout of the logging messages in gprs_subscriber.c,
this patch replaces each LOGP by LOGGSUBSCRP, unless a non-NULL
pointer to a subscr is not available. In those cases, it uses
LOGMMCTXP if a pointer to an MM context is available or LOGP
otherwise.

Sponsored-by: On-Waves ehf
2015-01-18 18:23:21 +01:00
Jacob Erlbeck bce2061b43 gprs: Let GSUP parser functions return GMM causes on errors
Currently the GSUP message handling function in gprs_subscriber.c and
the functions in gprs_gsup_messages.c are not consistent with respect
to the return codes if an error happens. Albeit all error return
codes are negative, the semantics of the absolute value are not
clearly defined. In addition, some return codes are not passed to the
calling function.

This path changes these functions to always return a negated GMM
cause value in case of errors. Return values of called parser
functions are not longer ignored.

Sponsored-by: On-Waves ehf
2015-01-18 18:22:47 +01:00
Jacob Erlbeck 9aa9991efe gprs: Use the cause value in GSUP error messages
Currently always a cause with the meaning of 'access denied' is
assumed. gprs_subscr_handle_gsup_auth_err just clears the auth
triplets and the authorized flag before calling the update function.
gprs_subscr_handle_gsup_upd_loc_err only clears the authorized flag
and calls the update function. This means, that an MS will not retry
to attach even on temporary network errors.

This patch changes these functions to use the GSUP error cause value
to decide, whether to clear the corresponding subscriber fields, to
just continue with the corresponding update function, or to log,
ignore and not pass the cause to the MS in case the error is directly
related to the GSUP protocol. The subscriber's error_cause field is
updated, if the update function is going to be called. The
error_cause fielt is reset on non-error GSUP messages.

Sponsored-by: On-Waves ehf
2015-01-18 18:20:41 +01:00
Jacob Erlbeck af3d5c508c sgsn: Pass subscriber error causes to the GMM layer
This patch extends gsm0408_gprs_access_denied and
gsm0408_gprs_access_cancelled to accept GMM cause codes. These are
then passed to the MS, unless gsm0408_gprs_access_cancelled is called
with cause 0 (no error -> updateProcedure).

Since gsm0408_gprs_access_denied uses GMM_CAUSE_GPRS_NOTALLOWED if
the cause is not set, and the subscriber's error_cause is never set
(and thus always 0), the SGSN's behaviour does not change with this
patch.

Sponsored-by: On-Waves ehf

Conflicts:
	openbsc/include/openbsc/gprs_sgsn.h

[hfreyther: Conflict due the removal of the unused
authenticate flag]
2015-01-18 18:14:49 +01:00
Jacob Erlbeck afcf23001e gprs: Move protocol value_strings to gsm_04_08_gprs.c
Currently the mapping between GSM 04.08 (GPRS) protocol specific
numbers and their textual description was put into gprs_gmm.c and not
exported.

This commit moves the mappings to a new file gsm_04_08_gprs.c,
renames some of them, and exports them via gsm_04_08_gprs.h.

The following identifiers are renamed to match the corresponding type
names:

  - gmm_cause_names -> gsm48_gmm_cause_names
  - gsm_cause_names -> gsm48_gsm_cause_names

Sponsored-by: On-Waves ehf
2015-01-18 18:13:06 +01:00
Jacob Erlbeck 8054799963 sgsn: Show GSUP client info on 'show sgsn'
This commit adds a line to the output of 'show sgsn' if the GSUP
client has been initialized:

  - Remote authorization: [not] connected to HOST:PORT via GSUP

Sponsored-by: On-Waves ehf
2015-01-18 18:12:06 +01:00
Jacob Erlbeck 03b4630348 gprs: Send PING and eventually reconnect
Currently, the reconnect mechanism relies on gsup_client_updown_cb
which in turn gets called based on the OS' view of connection state.

This patch adds a timer based PING mechanism that regularly sends
PING messages and forces a reconnect if a PONG message won't be
received until the next PING message is scheduled. The current ping
interval is 20s.

Sponsored-by: On-Waves ehf

Conflicts:
	openbsc/src/gprs/gprs_gsup_client.c

[hfreyther: Conflicts due the potential memleak fix by me. Removed
another TODO from the code as we stop the ping/pong timer]
2015-01-18 18:11:08 +01:00
Jacob Erlbeck e154d8bdd4 gprs: Handle incoming IPA CCM message in gsup_client_read_cb
Currently the IPA CCM messages are not handled by the GSUP client.
This means, that the client doesn't answer to PING and ID_GET and
logs notices when receiving PONG or ID_ACK. At least the PING
functionality (remotely originated PING) shall be supported.

This patch extends gsup_client_read_cb by a call to
ipaccess_bts_handle_ccm. Only when the return code is 0, the message
is processed further and checked for an OSMO/GSUP message. ID_GET
messages are answered by a dummy description, where only the
unit_name is set to 'SGSN'.

Sponsored-by: On-Waves ehf
2015-01-18 18:02:09 +01:00
Jacob Erlbeck 69e16b9ea5 gprs: Handle return code of ipa_client_conn_open correctly
The ipa_client_conn_open function does not distinguish between a
connection being already established or waiting for establishment.
In either case, the application gets informed about the connection
state via the updown_cb. The 'up' parameter is only set, if
poll/select consider the socket as writable.

This patch handles both cases equally and fully relies on the
updown_cb to adjust the gsupc obejct state.

Sponsored-by: On-Waves ehf
2015-01-18 17:59:18 +01:00
Jacob Erlbeck 4188c30c4a gprs: Avoid sending stale GSUP requests after reconnect
Currently, messages are added to the tx queue even if the connection
is down for some reason and all of these messages are eventually sent
after a re-connect.  The MS has probably sent several Attach Requests
while the connection was down and will continue doing so. Therefore
these stored messages could be dropped.

This patch clears the queue before re-connecting and also extends
gprs_gsup_client_send to return immediately, when the connection is
not established instead of calling ipa_client_conn_send.

Sponsored-by: On-Waves ehf

[hfreyther: Replaced
	while (!llist_empty(&gsupc->link->tx_queue))
		llist_del(gsupc->link->tx_queue.next);
with new libosmo-abis API]
2015-01-18 17:58:56 +01:00
Jacob Erlbeck 849d0a83e8 gprs: Add automatic re-connect if the GSUP connection is down
Currently the GSUP connection to a server is not restarted if the
connection cannot be established or is terminated during operation.

This commit adds a timer based connection mechanism, basically
consisting of a timer callback that calls gsup_client_connect. The
timer is eventually triggered (up == 0) or cleared (up != 0) by
gsup_client_updown_cb. It adds calls to osmo_timer_del() to
gsup_client_connect and gprs_gsup_client_destroy. The latter is now
called instead of talloc_free in gprs_gsup_client_create on error to
be on the safe side.

Sponsored-by: On-Waves ehf
2015-01-18 17:24:37 +01:00
Jacob Erlbeck 771573c535 sgsn: Add global require_update_location flag
This flag is used to determine, whether the Update Location procedure
shall be invoked. This is currently only set, when the 'remote'
authorization policy is set. When the flag is set, sgsn_auth_update
will not never be called directly by sgsn_auth_request, if an Attach
Request procedure is pending, even if the remote connection fails for
some reason.

Sponsored-by: On-Waves ehf
2015-01-18 13:23:13 +01:00
Jacob Erlbeck 9d4f46c975 sgsn: Replace subscr.authenticate by global require_authentication flag
Currently the flag 'authenticate' is managed per subscriber.

This patch replaces that flag by a global cfg.require_authentication
flag that enables/disables the use of the Auth & Ciph procedure for
every subscriber. The flag is set by the VTY, if and only if the
authorization policy is 'remote'.

The VTY command

  - update-subscriber imsi IMSI insert authenticate <0-1>

is removed.

Sponsored-by: On-Waves ehf
2015-01-18 13:18:35 +01:00
Jacob Erlbeck 39f040d62b sgsn: Integrate the GSUP client into the SGSN
This commit adds GSUP client configuration (via VTY), connection set
up, and real message sending.

The following configuration commands are added:

 - gsup remote-ip A.B.C.D            set server IP address
 - gsup remote-port PORT             set server TCP port

Ticket: OW#1338
Sponsored-by: On-Waves ehf
2015-01-18 13:17:50 +01:00
Jacob Erlbeck bb23dc17f8 gprs: Add GSUP client
This commit adds the client code to get subscriber information from a
remote server. It provides an IPA over TCP connection to transmit and
receive GSUP messages.

Sponsored-by: On-Waves ehf
2015-01-18 13:17:11 +01:00
Jacob Erlbeck 1610626fe9 gprs: Clear GSUP message structures before decoding
Currently the message structure is not cleared before the message is
parsed which can cause information leaking between messages if the
same gprs_gsup_message object is used. Especially list elements (auth
tuples and pdp info) are not replaced by an IE, but the IE is
appended.

This patch uses the assignment operator to clear gprs_gsup_message,
gsm_auth_tuple, and gprs_gsup_pdp_info before using them. This also
replaces the use of memcpy of the latter.

Sponsored-by: On-Waves ehf
2015-01-18 13:17:09 +01:00
Jacob Erlbeck a2315eebf9 gprs: Always reset auth tuples/pdp infos in gprs_gsup_decode
Currently auth tuples are always appended to the lists when
gprs_gsup_decode is called with a gsup_msg structure. This makes a
test case fail, where the same gsup_msg is used again and again
without clearing it after each use.
Sponsored-by: On-Waves ehf
2015-01-18 13:17:09 +01:00
Jacob Erlbeck 424ffa4806 gprs: Handle empty GSUP messages correctly
Currently, the gprs_gsup_decode function doesn't check the return
value of gprs_shift_v_fixed before using the value pointer. The
function fails, if the GSUP message length (not including IPA
headers) is 0. In this case, a segfault can happen, depending on the
value of the uninitialized 'value' pointer. The test case doesn't
trigger a segfault, but valgrind complains about reading
uninitialized data.

This patch adds a check for the return value that would return with
an error code if the shift function failed.

Sponsored-by: On-Waves ehf
2015-01-18 13:17:09 +01:00
Jacob Erlbeck a6ddc2d99f gprs: Add subscriber functions to create/handle GSUP messages
This patch extends gprs_subscr_query_auth_info and
gprs_subscr_location_update to create GSUP messages with the help of
a static gprs_subscr_tx_gsup_message function. A corresponding
gprs_subscr_rx_gsup_message is added which takes a messages, gets the
subscr, and updates it accordingly.

Sponsored-by: On-Waves ehf

[hfreyther: Added a msgb_free gprs_subscr_tx_gsup_message]
2015-01-10 21:26:18 +01:00
Jacob Erlbeck f3a271fa73 gprs: Add encoder/decoder for the Subscriber Update Protocol
This patch adds functions to encode and decode GSUP messages. This
does not include the layer 1 framing (IPA). The messages so far
supported are: send_auth_info_*, update_location_*,
location_cancellation_*.

Sponsored-by: On-Waves ehf
2015-01-10 21:26:18 +01:00
Jacob Erlbeck 17fb3d46ff sgsn: Fix VTY command error handling (Coverity)
Currently the result of the osmo_hexparse function in
update_subscr_insert_auth_triplet is not handled correctly. There is
a misplaced leading exclamation mark in a few conditional
expressions. This effectively disables the error checks, as it is
noticed by Coverity ("Missing parentheses" followed by "Logically
dead code").

This patch removes the exclamation marks.

Fixes: Coverity CID 1260435 and CID 1260434
Sponsored-by: On-Waves ehf
2015-01-10 20:55:04 +01:00
Jacob Erlbeck 98a95ac17f sgsn: Add a subscriber based authentication phase
This implements the MAP way of subscriber validation when the MS
tries to perform an Attach Request:

  1. perform authentication (optionally invoke the sendAuthInfo
     procedure), starts the Auth & Ciph procedure
  2. perform update location
  3. insert subscriber data
  4. finish the update location
  5. Attach Accept / Attach Reject

The authentication triplets are used and eventually updated if all of
them have been used.

This is currently accessible via the VTY interface by the following
commands:

  - update-subscriber imsi IMSI update-auth-info
  - update-subscriber imsi IMSI update-location-result (ok|ERR-CAUSE)

Sponsored-by: On-Waves ehf
2014-12-24 16:50:30 +01:00
Jacob Erlbeck 7921ab1593 sgsn: Add support for authentication triplets
This commit add data structures, functions, initialization, and VTY
commands for per subscriber authentication triplets.

The following VTY command is added:

  - update-subscriber imsi IMSI \
    insert auth-triplet <1-5> sres SRES rand RAND kc KC

Note that the triplets are not really used by the SGSN yet.

Sponsored-by: On-Waves ehf
2014-12-24 16:50:16 +01:00
Jacob Erlbeck 7dba11fe32 sgsn: Be more tolerant with state and SUSPEND/RESUME
Currently, when a BSSGP SUSPEND is received and the corresponding MM
context is already in the state GMM_REGISTERED_SUSPENDED, a
SUSPEND_NACK is returned which is not covered by GSM 08.18, 7.4.1.
The same goes for RESUME in the state GMM_REGISTERED_NORMAL.

This commit changes gprs_gmm_rx_suspend and gprs_gmm_rx_resume to not
complain (and thus answer a NACK) when the MM context is either in
GMM_REGISTERED_SUSPENDED or GMM_REGISTERED_NORMAL.

Note that GSM 08.18, 7.4.1 and 7.5.1 only mention to send an NACK if
the MS is not known. Even with this patch, the SGSN returns a NACK if
either the MS is unknown _or_ the MM context ist not in one of the
state GMM_REGISTERED_SUSPENDED and GMM_REGISTERED_NORMAL.

Sponsored-by: On-Waves ehf
2014-12-23 15:15:13 +01:00
Jacob Erlbeck 3ea2260d00 sgsn: Log requested state change in sgsn_auth_update
Sponsored-by: On-Waves ehf
2014-12-23 15:14:36 +01:00
Jacob Erlbeck 697a534ed6 gprs: Add gprs_shift_tlv function
This function is similar to gprs_match_tlv with the exception, that
the tag is not compared but returned in *tag instead.

Sponsored-by: On-Waves ehf
2014-12-23 15:10:24 +01:00
Jacob Erlbeck dcfd456640 gprs: Move TLV parser functions to gprs_utils.c and rename them
Currently the parser functions for single information elements are
defined within gprs_gb_parse.c and not exported explicitely. In
addition they are named like libosmocore's TLV parser functions and
do not have a proper name prefix. Since it is planned to use them for
other protocols, they need to be globally accessible.

This patch moves them to gprs_utils.c and renames them.

The new names are:
    lv_shift             -> gprs_shift_lv
    v_fixed_shift        -> gprs_shift_v_fixed
    lv_shift             -> gprs_shift_lv
    v_fixed_shift        -> gprs_shift_v_fixed

In the long term, these functions should be moved to libosmocore (and
renamed again).

Sponsored-by: On-Waves ehf
2014-12-23 15:08:52 +01:00
Jacob Erlbeck c939196557 sgsn: Add missing LF in log message
Sponsored-by: On-Waves ehf
2014-12-23 15:07:54 +01:00
Jacob Erlbeck 2e5e94c328 sgsn: Support subscriber based authentication
This commit mainly extends sgsn_auth.c to use and support the
auth_state SGSN_AUTH_AUTHENTICATE. It will be activated when IMSI and
IMEI are available, authentication is required
(subscr->sgsn_data->authenticate is set), but the MM context is not
marked as authenticated. If the state has been set to
SGSN_AUTH_AUTHENTICATE and sgsn_auth_update() is called, the GMM
layer will be informed by invoking gsm0408_gprs_authenticate().

Sponsored-by: On-Waves ehf
2014-12-10 12:45:22 +01:00
Jacob Erlbeck 4adb136da6 sgsn: Integrate Auth & Ciph into gsm48_gmm_authorize
Currently the Authentication and Ciphering procedure is not yet
invoked by the GMM layer.

This patch starts this procedure from within gsm48_gmm_authorize when
the mm->auth_state has been set to SGSN_AUTH_AUTHENTICATE and a call
to gsm0408_gprs_authenticate has been issued directly or indirectly
by the call to sgsn_auth_request.

Sponsored-by: On-Waves ehf
2014-12-10 12:44:05 +01:00
Jacob Erlbeck 665acd1dbd sgsn: Do not 'commit' implicitely when executing 'insert'
Currently the gprs_subscr_update function is called when the
'update-subscriber ... insert ...' command is executed. This will
eventually notify the GMM layer which is rather the purpose of the
'commit' command.

This patch removes the call from update_subscr_insert.

Sponsored-by: On-Waves ehf
2014-12-10 12:42:36 +01:00
Jacob Erlbeck a1e0373224 sgsn: Put SGSN related subscriber data into separate struct
There will be an increasing number of SGSN related fields per
subscriber. Instead of extending gsm_subscriber accordingly, a single
struct sgsn_subscriber_data object is assigned to it. The talloc
context used to allocated that object is the subscr object itself.
Therefore it will be freed automatically along with the subscr
object.

Sponsored-by: On-Waves ehf
2014-12-09 10:01:08 +01:00
Jacob Erlbeck 207f4a5deb sgsn: Add VTY commands to manage subscriber cache
This adds the following commands to the ENABLE node:
  - show subscriber cache
  - update-subscriber imsi IMSI insert authorized (0|1)
  - update-subscriber imsi IMSI cancel
  - update-subscriber imsi IMSI commit

These commands are mainly testing tools and maintenance helpers. The
update commands work asynchronously and can be used to complete a
pending update request or to terminate an existing connection. The
'insert' command just update the subscriber records but does not
notify the GMM layer. Invoke the 'commit' command to continue with
pending procedures.

Note that the subscriber cache is not stored persistently and will
always be empty after an SGSN restart.

Sponsored-by: On-Waves ehf
2014-12-09 10:00:41 +01:00
Jacob Erlbeck 98647ca0ef sgsn: Add gsm0408_gprs_access_cancelled
This function is called to delete an established MM context
silently without invoking a detach procedure.

It is called when a subscriber is cancelled by the HLR. This
generally happens, when an MS has moved to another routing area and
has to use another SGSN.

Sponsored-by: On-Waves ehf
2014-12-09 09:48:25 +01:00
Jacob Erlbeck be2c8d9358 sgsn: Integrate subscriber handling into the SGSN
This commit adds a new authorization policy 'remote' and uses
the subscriber cache for authorization when this policy is being used.

Note that there is no remote backend implemented yet. After the
IMSI/IMEI have been acquired, a request would be sent to the remote
peer. The attach/auth-ciph procedure continues when authorization
info has been received from the peer. This means, that
gprs_subscr_update() must be called then to tell the GMM layer
that it can proceed. A later commit will add VTY commands to do this
manually.

Sponsored-by: On-Waves ehf
2014-12-09 09:27:20 +01:00
Jacob Erlbeck 33b6dadc88 sgsn: Add gprs_subscriber.c
This patch adds GPRS specific functions for gsm_subscriber objects
(allocation, retrieval, deletion) and subscriber data
requests/updates. The sgsn_update_subscriber_data callback is used to
notify the sgsn about updates and is extended by a parameter that
passes a reference to a gsm_subscriber.

Sponsored-by: On-Waves ehf
2014-12-09 09:23:11 +01:00
Jacob Erlbeck 8ff3fb04f2 sgsn: Do authentication based on SRES values
Currently the SRES value in the Auth & Ciph Response is ignored.

This patch checks the SRES value in response against the value stored
in mm->auth_triplet.sres. If they don't match, an Auth & Ciph Reject
message is sent to the MS. If they match, the mm->is_authenticated
flag is set.

Note that the procedure will not be started yet.

Sponsored-by: On-Waves ehf
2014-12-08 10:51:38 +01:00
Jacob Erlbeck bd0cf1190a sgsn: Change Auth&Ciph timer handling
Currently mmctx_timer_start is called from within
gsm48_tx_gmm_auth_ciph_req which differs from the way e.g. the
identification procedure is implemented. It also makes it more
difficult to restart the procedure after timeout, which is not
implemented yet. In addition, the timer is not properly stopped when
an AUTH & CIPH response is received.

This patch removes this timer start from gsm48_tx_gmm_auth_ciph_req,
adds the retransmission of Auth & Ciph requests to the timer callback
function, and properly stops the timer in
gsm48_rx_gmm_auth_ciph_resp.

Sponsored-by: On-Waves ehf
2014-12-08 10:50:52 +01:00
Jacob Erlbeck 65d8273bf3 sgsn: Fix and enable auth/ciph message generation
Currently gsm48_tx_gmm_auth_ciph_req/_rej are commented out. In
addition, gsm48_tx_gmm_auth_ciph_req uses a wrong encoding (two byte TV instead of two nibbles TV) of the CKSN information element.

This patch fixes the encoding of the CKSN IE and enables the
functions mentioned above.

Sponsored-by: On-Waves ehf
2014-12-08 10:49:17 +01:00
Jacob Erlbeck 59ac49dc1f gbproxy: Reset TLLIs when the link_info is found by IMSI/P-TMSI
Currently when the MS does a re-attach without doing a proper detach
first, the gbproxy uses the old local TLLI if patching and the keep
mode are enabled. This leads to a failing attachment procedure when
TLLI patching is also enabled.

This patch changes gbproxy_update_link_state_ul to reset all TLLIs
within the link_info if the message contains an unknown TLLI and an
MI. This is generally the case with Attach Request messages.

The gbproxy_get_link_info_ul gets an additional tlli_is_valid
output parameter that is set, when a TLLI was present and found.
This flag is then used instead of checking tlli.current == 0 to
set TLLI/P-TMSI e.g. Attach Requests when a link_info was already
present for the P-TMSI/IMSI used in such a request.

Ticket: OW#1324
Sponsored-by: On-Waves ehf
2014-12-02 09:00:09 +01:00
Jacob Erlbeck a0b6efb368 sgsn: Remove explicit sgsn_instance parameters
Currently the function in sgsn_auth.c either have an sgsn_config or
an sgsn_instance parameter. Since then global sgsn variable is
already being used in that file and since other parts of the SGSN
related code also rely on a global sgsn singleton, these parameters
pretend to provide a flexibility that is not really supported.

Therefore this patch removes these parameters except for the ACL
related functions, which do not call code that uses the sgsn
variable.

Sponsored-by: On-Waves ehf
2014-11-14 10:26:06 +01:00
Jacob Erlbeck f951a01bb2 sgsn: Refactor sgsn_auth to separate request and authorization
Currently the authorization is done in sgsn_auth_request for ACL
based authorization. This doesn't match the way remote authorization
would work, so that there is a second call to sgsn_auth_state already
present in sgsn_auth_update.

This patch removes the autorization check completely from
sgsn_auth_request which in turn calls sgsn_auth_update directly now.

Sponsored-by: On-Waves ehf
2014-11-14 10:23:54 +01:00
Jacob Erlbeck f6e7d99d54 sgsn: Don't assign a new P-TMSI if one is pending
Currently every time an RA Update Req or an Attach Req is processed, a
new P-TMSI is allocated. When an MS issues another of these messages
before it has completed the first procedure, old_ptmsi is replaced by
ptmsi (and thus lost) and ptmsi is replaced by the newly allocated
P-TMSI. This can confuse the gbproxy, which can loose track of the
logical link then. At least a Blackberry emits a double set of RA Upd
Req messages from time to time which may be just 20ms apart.

This patch adds a check whether mm->ptmsi or mm->old_ptmsi are set.
If both are set, the P-TMSI is not re-allocated. This is only the
case, when the Complete message has not been received yet, since that
message will reset old_ptmsi.

Sponsored-by: On-Waves ehf
2014-11-14 10:19:29 +01:00
Jacob Erlbeck c4f9bf3142 sgsn: Don't send XID reset after Detach Accept
Currently when a Detach Accept is received for an unknown TLLI (which
is in general the case afer the SGSN has requested the detachment),
an XID reset is sent to the BSS, causing a BSSGP Status message. This
happens in gsm0408_rcv_gmm.

This patch moves the corresponding call to gprs_llgmm_reset downwards
so that it is not being called in that case.

Addresses:
SGSN->BSS TLLI: 0xd75b91d9 SAPI: LLGMM, UI (DTAP) (GMM) Detach Request
BSS->SGSN TLLI: 0xd75b91d9 SAPI: LLGMM, UI (DTAP) (GMM) Detach Accept
SGSN->BSS TLLI: 0xd75b91d9 SAPI: LLGMM, U, XID (Reset, IOV-UI)
BSS->SGSN TLLI: ---        BSSGP STATUS (Unknown MS)

Sponsored-by: On-Waves ehf
2014-11-14 10:12:32 +01:00
Jacob Erlbeck 80d07e30c7 sgsn: Cleanup after RA Update Reject / Attach Reject
Currently, the LLME is not cleaned up after sending an RA Update
Reject. This happens after entering a routing area from outside,
since in that case the SGSN sends an RA Update Reject (implicitly
detached) which causes the MS to restart the attach procedure.
The LLME is also not updated if an Attach Request with message errors
(encoding, invalid MI type) is received or if an MM context cannot be
allocated.

This patch changes gsm48_rx_gmm_ra_upd_req and gsm48_rx_gmm_att_req
to unassign the LLME or free the MM context (if available) after a
Reject message has been sent.

Ticket: OW#1324
Sponsored-by: On-Waves ehf
2014-11-14 10:07:42 +01:00
Jacob Erlbeck 106f547733 sgsn: Add 'acl-only' authentication policy
Currently the VTY 'auth-policy' command results in setting or clearing
the acl_enabled flag. This also enables the matching of the MCC/MNC
prefix of the IMSI.

This patch adds an additional policy 'acl-only' which disables the
MCC/MNC matching and relies on the ACL only.

Sponsored-by: On-Waves ehf
2014-11-14 10:07:28 +01:00
Jacob Erlbeck 423f8bfa02 sgsn: Make authorization asynchronous
Currently the authorization of an IMSI is done by checking ACLs
synchronously which is not feasible when the subscriber data has to
be retrieved from an external source.

This patch changes this by using a callback when the information is
available. This is also done when only ACL are checked, in this case
the callback is invoked from within sgsn_auth_request(). The callback
function sgsn_update_subscriber_data calls sgsn_auth_update which
in turn calls either gsm0408_gprs_access_granted or
gsm0408_gprs_access_denied. gsm48_gmm_authorize is extended by a call
to sgsn_auth_request when IMSI and IMEI are available but the
auth_state is unknown.

The change has been successfully tested with single phones (E71 and
IPhone 5c).

Sponsored-by: On-Waves ehf
2014-11-14 09:58:28 +01:00
Jacob Erlbeck 0c06f98ced sgsn: Move IMSI authorization to gsm48_gmm_authorize
Currently the IMSI is only checked immediately when an Attach Request
is received that contains an IMSI IE. If it contains a P-TMSI
instead, access is always granted.

This commit moves the IMSI check to gsm48_gmm_authorize where it is
applied when IMSI and IMEI have been acquired. This fixes the
authorization when the Attach Accept doesn't contain an IMSI.

Sponsored-by: On-Waves ehf
2014-11-14 09:27:23 +01:00
Jacob Erlbeck b1c074f62c sgsn: Fix LLME leak when forcing a reattach
Currently when forceing a reattach by sending a Detach
Request (reattach), the SGSN waits for the Detach Accept until it
frees the MM context (if present) and the LLME. If that message gets
lost or isn't sent by the MS, the LLME is never freed if it isn't
bound to an MM context.

This patch adds code to free the MM context/LLME when forcing a
reattachment.

Sponsored-by: On-Waves ehf
2014-11-14 09:26:27 +01:00
Jacob Erlbeck abdf02b9b9 sgsn: Split gsm0408_gprs_force_reattach into 2 functions
This patch replaces gsm0408_gprs_force_reattach(msg, mmctx) by two
functions
  - gsm0408_gprs_force_reattach(mmctx)
  - gsm0408_gprs_force_reattach_oldmsg(msg)

The old function basically consists of the code of the two new
functions, where the code path selected depends on mmctx == NULL,
which is harder to maintain, less obvious to use, and not consistent
with many other SGSN functions.

Sponsored-by: On-Waves ehf
2014-11-14 09:23:38 +01:00
Jacob Erlbeck a790456f1b sgsn: Call mm_ctx_cleanup_free to deregister MM context
Currently the MM context isn't always removed when it is
de-registered (mmctx_timer_cb), mm_state is set to GMM_DEREGISTERED
instead. This can lead to left-over MM contexts which are only
cleaned up if the MS reattaches.

This patch replaces all of these assignments by a call to
mm_ctx_cleanup_free.

Ticket: OW#1324
Sponsored-by: On-Waves ehf
2014-11-14 09:16:58 +01:00
Jacob Erlbeck 0074a77424 sgsn: Cleanup GMM state transitions
Currently the GMM state is set to GMM-REGISTERED when an Attach
Accept or a RA Update Accept message is sent, even if a new P-TMSI is
included. In this case 04.08 requires (see 4.7.3.1.3 and 4.7.5.1.3),
that the state is set to GMM-COMMON-PROCEDURE-INITIATED when the
Accept is sent. When the Complete is received, the SGSN shall set
the state to GMM-REGISTERED.

This patch modifies the state updates accordingly.

Sponsored-by: On-Waves ehf
2014-11-14 09:12:10 +01:00
Jacob Erlbeck 93eae8ec78 sgsn: Reorganize and fix gsm48_gmm_authorize
Currently the order of the 'if' clauses in gsm48_gmm_authorize
doesn't match the order in which the conditional parts are entered.
This makes it difficult to maintain. In addition the t3350_mode is
not stored in every path, so that this information is lost when the
identification procedure is started. Since the default value
coincidentally is GMM_T3350_MODE_ATT, this doesn't hurt for Attach
Requests which are the only messages that initially trigger the
authentication yet.

This patch changes the order of the 'if' clause to match the
processing order, it removes the t3350_mode parameter entirely and
introduces a mm->pending_req field. The latter must be set when the
request that causes the authorization before calling
gsm48_gmm_authorize. The gprs_t3350_mode enum is extended by
GMM_T3350_MODE_NONE (value 0, which is the default) to make it
possible to detect related initialisation errors or race conditions.

Sponsored-by: On-Waves ehf
2014-11-14 08:57:50 +01:00
Jacob Erlbeck 4110868029 gbproxy: Honour the BSS TLLI type when creating an SGSN TLLI
Currently gbproxy_make_sgsn_tlli always returns a foreign TLLI when
it uses the (SGSN) P-TMSI to generate one.

This patch changes the implementation to return a SGSN TLLI of the
same type like the BSS TLLI in that case.

Sponsored-by: On-Waves ehf
2014-11-11 22:44:32 +01:00
Jacob Erlbeck de74e721b2 gbproxy: Fixed VTY doc for delete-gbproxy-link
The command definition delete_gb_link_by_id_cmd lacks a description
for the sgsn-nsei token.

This patch adds the missing description.

Addresses:
Verifying src/gprs/osmo-gbproxy -c doc/examples/osmo-gbproxy/osmo-gbproxy.cfg, test verify_doc
Documentation error (missing docs):
<command id='delete-gbproxy-link &lt;0-65534&gt; (tlli|imsi|sgsn-nsei) IDENT'>
        <param name='IDENT' doc='(null)' />

Sponsored-by: On-Waves ehf
2014-11-05 00:24:13 +01:00
Jacob Erlbeck 14ae582064 sgsn: Unassign the LLME after GMM Status without mmctx
Currently the LLME is not deleted when a GMM Status message is
received for which a mmctx cannot be found. This can fill the LLME
list with unneeded entries.

This patch adds code to unassign the LLME in that case.

Ticket: OW#1324
Sponsored-by: On-Waves ehf
2014-11-05 00:24:02 +01:00
Jacob Erlbeck 7067142100 sgsn: Remove unused static functions from gprs_gmm.c
The following functions are not being used:
 - gsm48_tx_gmm_status_oldmsg
 - gsm48_tx_sm_status_oldmsg

This patch removes the function definitions.

Sponsored-by: On-Waves ehf
2014-11-05 00:23:44 +01:00
Jacob Erlbeck 5a38f6470e sgsn: Handle Detach Requests even when there is no mmctx
Currently, when a Detach Request is received with an unknown TLLI,
it is answered by another Detach Request (!), even when a power_off
Type is used.

This patch uses gsm48_rx_gmm_det_req to handle the message instead.
So this function is changed to cope with a NULL mmctx. In that case
it doesn't unassign the llme, so this must be done manually
afterwards.

Sponsored-by: On-Waves ehf
2014-10-27 15:34:14 +01:00
Jacob Erlbeck b9ab0d4f39 sgsn: Only send Detach Accept (MO) if power_off isn't set
Currently, every time the SGSN received a Detach Request from the MS
via an established logical link, it is answered by a Detach Accept.
This violates the specification (GSM 04.08, 4.7.4.1.2 and .3), which
states, that it should only be sent, if "the detach type IE value
indicates that the detach request has not been sent due to switching
off".

This patch adds a conditional to limit the sending of Detach Accept
accordingly.

Sponsored-by: On-Waves ehf
2014-10-27 15:21:31 +01:00
Jacob Erlbeck 3b5d407203 sgsn: Moved IMSI ACL management to sgsn_auth.c
Currently the ACL code is located in sgsn_vty.c.

This commit moves this to a new file sgsn_auth.c as a first step to
make authorization more flexible in order to implement remote
acquisition on subsciber data.

Sponsored-by: On-Waves ehf
2014-10-27 13:06:55 +01:00
Jacob Erlbeck fb26c60a2f sgsn: Avoid duplicated Attach Accept messages
Currently each received Ident Resp triggers an Attach Accept/Reject
if IMSI and IMEI are known. This has led to duplicated Attach Accept
messages when used with the gbproxy (IMSI acquisition active) and
with certain mobile equipment (iOS).

This patch modifies gsm48_rx_gmm_id_resp to discard Ident Resp messages
if all required information (IMEI and IMSI) has been gathered.

Ticket: OW#1322
Sponsored-by: On-Waves ehf
2014-10-27 13:06:55 +01:00
Jacob Erlbeck c37ef6cd0e gbproxy: Patch BSSGP P-TMSI in PAGING PS messages
Currently the P-TMSI IE in PAGING_PS is not patched.

This commit adds code to patch BSSGP P-TMSI IE in
gbproxy_patch_bssgp independently from the P-TMSI patching at the LLC
layer. It also extends gbproxy_update_link_state_dl to use the IMSI
to find the link_info if the TLLI is not present in the message.

Note that the spec (GSM 08.18, 7.2) requires to use of the P-TMSI
instead of the IMSI to select the MS if that IE is available.
Nevertheless as long as the IMSI is always present in downlink BSSGP
messages and as long as the optional P-TMSI refers to the same MS
(which is the case currently), this is not an issue.

Sponsored-by: On-Waves ehf
2014-10-27 11:59:28 +01:00
Jacob Erlbeck 91e9f555b6 gbproxy: Fix P-TMSI generation for repeated Attach Accept messages
Currently, when P-TMSI patching is enabled, a new BSS P-TMSI is
generated for each Attach Accept. So two duplicated, subsequent
Attach Accept messages will be mapped to different BSS side P-TMSI.
Because the last one will replace former ones in the link_info
struct, the MS will fail to access the SGSN if it uses the former
P-TMSI to derive the new TLLI.

This patch checks the SGSN P-TMSI already assigned to the link_info
and only generates a new BSS P-TMSI on mismatch (or if the BSS P-TMSI
hasn't been set yet).

Ticket: OW#1322
Sponsored-by: On-Waves ehf
2014-10-27 11:17:11 +01:00
Jacob Erlbeck 78ecaf0561 sgsn: Send detach(re-attach) instead of gmm status if TLLI unknown
The osmo-sgsn sends Status messages (or nothing in case of non
GMM/GSM) when the TLLI is unknown. This prevents the MS from
reconnecting.

This patch adds the initiation of an MT detach procedure to force a
re-attach to set up a valid LLE context if an LLE or an MM context
cannot be found. Since this can also be triggered by non-GMM SAPI
messages, a GPRS application callback sgsn_force_reattach_oldmsg is
added which in turn calls the GMM layer to generate the GSM 04.08
specific messages.

Note that the MS can be left in REGISTERED state after initially
wanting to detach itself, since it will receive a Detach Req
(re-attach) when sending a DEACT PDP CTX REQ after the SGSN or
gbproxy (P-TMSI patching enabled) has been restarted. This same
behaviour has been observed with another SGSN.

Sponsored-by: On-Waves ehf
2014-10-27 10:50:36 +01:00
Jacob Erlbeck 99985b5ea8 sgsn: Delete PDP contexts properly
Currently the PDP contexts are hard freed (via sgsn_pdp_ctx_free)
at some places in gprs_gmm.c on the reception of a Detach Req and on
re-use of an IMSI that is already associated with an MM context. This
can lead to segfaults when there is a pending request or a data
indication at libgtp.

This patch add a new function sgsn_pdp_ctx_terminate that de-associates
the PTP context from the MM context, deactivates SNDCP, sets pdp->mm
to NULL and then calls sgsn_delete_pdp_ctx. sgsn_libgtp is updated to
check for pdp->mm being non-NULL before dereferencing it. The
sgsn_pdp_ctx_terminate function will be called for each PDP context of
an MM context before this context is going to be deleted via
sgsn_mm_ctx_free. To ensure, that the ctx->llme (which is accessed
during the deactivation of SNDCP) remains valid, the call to
gprs_llgmm_assign is moved after the call to sgsn_mm_ctx_free. The
handling of re-used IMSIs is changed to mimic the processing of a
Detach Req.

Addresses:
<0002> gprs_gmm.c:654 MM(/f6b31ab0) Deleting old MM Context for same
    IMSI p_tmsi_old=0xc6f19134
<000f> gprs_sgsn.c:259 PDP freeing PDP context that still has a
    libgtp handle attached to it, this shouldn't happen!
[...]
SEGFAULT

Ticket: OW#1311
Sponsored-by: On-Waves ehf
2014-10-27 10:25:13 +01:00
Jacob Erlbeck ae20b4b31b sgsn: Cancel pending timer in sgsn_mm_ctx_free
Currently the timer is not stopped before the MM context is freed
which can lead to failure if sgsn_mm_ctx_free is called while timer
protected procedures are active.

This patch add code to cancel the timer if necessary from within
sgsn_mm_ctx_free.

Ticket: OW#1322
Sponsored-by: On-Waves ehf
2014-10-27 10:25:03 +01:00
Holger Hans Peter Freyther 19e990d6a7 gprs: Fix typo in the comment 2014-10-27 10:25:03 +01:00
Jacob Erlbeck 6a1d428f56 gbproxy: Fix segfault for VTY delete-gbproxy-link
Currently the code segfaults when the link shall be deleted by IMSI
when the IMSI has not been set yet.

This patch adds a NULL check to skip the entry before calling
gsm48_mi_to_string,

Adresses:
Program received signal SIGSEGV, Segmentation fault.
0xb693af77 in gsm48_mi_to_string (string=0xbfffe020 "", str_len=200,
mi=0x0, mi_len=0) at gsm48.c:360
    360         mi_type = mi[0] & GSM_MI_TYPE_MASK;
    str_len=200, mi=0x0, mi_len=0) at gsm48.c:360
    self=0x807c9a0 <delete_gb_link_by_id_cmd>, vty=0xb4303c70,
     argc=3, argv=0xbfffe1c0) at gb_proxy_vty.c:670
...

Sponsored-by: On-Waves ehf
2014-10-27 09:47:00 +01:00
Jacob Erlbeck 058ae12135 gbproxy: Discard UL PTP messages with an unknown BVCI
Currently all PTP messages are in general forwarded to the SGSN even
when the BVCI is not known to the gbproxy. Only if message patching
is active and the peer cannot be determined, a log message is
generated, a STATUS message returned, and the message discarded.
The intention for this was to keep the old gbproxy's behaviour if
patching is disabled. But the code gets much more complex this way.
Another drawback is that when the SGSN returns a corresponding STATUS
message, it cannot be routed to the BSS where the original message
came from.

This patch therefore changes the behaviour to reject BSSGP PTP uplink
messages immediately if the BVCI is not known.

Fixes: Coverity CID 1244240
Ticket: OW#1317
Sponsored-by: On-Waves ehf
2014-10-27 09:44:29 +01:00
Holger Hans Peter Freyther f9ffd1fa18 sgsn: Prevent memory leak and double free
This has been re-produced using the "osmo-pcu emulator" code
and a ping to force segmented SNDCP messages. When the NS link
enters the DEAD/BLOCKED state the msgb would be freed twice.
Once inside gprs_ns_sendmsg and once by the caller. Based on the
return one can not see if the parameter has been deleted.

I changed libosmocore/libosmogb to always free the msgb in case
of an error on the way to gprs_ns_sendmsg. Catch up, avoid the
double free and fix some memory leaks. In case the sending fails
assume the entire segmented message is at end and free the
original input data.

This has been tested by posix suspending/resuming the emulator
process to have the GPRS-NS link go to dead/blocked to alive
and unblocked. The ping recovers and "SIGUSR1" to the SGSN does
not show active memory allocations.

The SGSN calls bssgp_tx_dl_ud at the lowest level and has the
following callchains. Most of them allocate the msgb and have
no early return and transfer ownership already:

<- gprs_llc_tx_u
<- gprs_llc_tx_ui
	<- gsm48_gmm_sendmsg (all callers sane)
		<- _tx_status
		<- _tx_detach_req
	<- gprs_llc_tx_xid (all callers sane)
	<- sndcp_unitdata_req
		<- sndcp_send_ud_frag
2014-10-10 17:43:40 +02:00
Jacob Erlbeck b4f0e8089d gbproxy: Log more information on parse errors
To get a clue which message caused the error without having to enable
LOGL_DEBUG, information about how far the parser came (message name,
parsed fields) is logged with LOGL_NOTICE along with a full hexdump
of the message.

Ticket: OW#1307
Sponsored-by: On-Waves ehf
2014-10-09 18:17:06 +02:00
Jacob Erlbeck 1c407aa993 gbproxy: Pass the log level as argument to gprs_gb_log_parse_context
Currently, the log level is always LOGL_DEBUG. In case of errors it
would be helpful to use a higher log level.

This patch adds a log_level parameter to gprs_gb_log_parse_context to
let the caller decide about the level.

Ticket: OW#1307
Sponsored-by: On-Waves ehf
2014-10-09 18:16:22 +02:00
Jacob Erlbeck 9b07135b92 gbproxy: Add gprs_gb_message_name function
This function tries to get an accurate name for the message even if
the parsing has been aborted due to message errors.

The patch also moves the settings of the BSSGP related fields in
parse_ctx from behind to the front of bssgp_tlv_parse, to get more
information in the case of failure. This is now consistent with the
handling of the llc and g48_hdr fields.

Id addition, gprs_gb_log_parse_context now uses the new function to
derive a more accurate message name.

Ticket: OW#1307
Sponsored-by: On-Waves ehf
2014-10-09 18:15:31 +02:00
Jacob Erlbeck cc8856f9d3 gbproxy: Refuse to configure conflicting NSEIs
Currently it is possible to set the secondary SGSN NSEI to the same
value like the (primary) SGSN NSEI. This leads to undefined behaviour
and is hard to recognize.

This patch adds checks to either NSEI configuration command to refuse
conflicting values.

Ticket: OW#1306
Sponsored-by: On-Waves ehf
2014-10-09 18:14:09 +02:00
Jacob Erlbeck 49389178cc gbproxy: Use pointer to PTMSI value instead of MI
Currently, ptmsi_enc and new_ptmsi_enc point to the beginning of the
mobile identity. Since all P-TMSI in 04.08 (MM) are encoded this way (1
byte header + 4 byte P-TMSI value). This is different to the P-TMSI
encoding in 08.18 (BSSGP), where the P-TMSI is encoded into 4 byte
without MI header.

This patch changes the code to use pointers to the P-TMSI value,
which is encoded in the same way in both specifications.

Sponsored-by: On-Waves ehf
2014-10-09 18:12:27 +02:00
Jacob Erlbeck 43b8f9f8a1 gbproxy: Send STATUS(BVCI unknown) to BSS on unknown PTP BVCI
Currently BSSGP PTP messages are silently dropped when the BVCI is
not known and patching is enabled. The nanoBTS will not recognize
this and continue to send messages on the BVCI. If it receives a
STATUS(BVCI unknown) instead, it will start a BVC reset procedure
instead.

This patch modifies gbprox_rx_ptp_from_bss() to return a
STATUS(BVCI unknown) to the BSS instead of dropping the message.

Sponsored-by: On-Waves ehf
2014-10-09 18:09:54 +02:00
Jacob Erlbeck f349baeec8 gbproxy: Replace ';;' by ';'
This patch removes some superfluous ';' from the code.

Sponsored-by: On-Waves ehf
2014-10-09 18:09:27 +02:00
Jacob Erlbeck c9cd15fbc9 gbproxy: Fix parser to accept GSM 24.008 Attach Req messages
Currently the parse expects a 'MS network capability' IE with
2 <= length <= 3 which is compliant to GSM 04.08, 9.4.1  but not to
GSM 24.008, 9.4.1 which specifies 3 <= length <= 9. Thus the parser
rejects messages with a length >= 4 (including length field).

This patch relaxes the length check to accept either range by
requiring 2 <= length <= 9.

Ticket: OW#1258
Sponsored-by: On-Waves ehf
2014-10-09 18:07:10 +02:00
Jacob Erlbeck b36032cb27 gbproxy: Use a separate regexp for routing
Currently one regexp ('patching') is used for all matching.

This patch adds a second category 'routing' which is exclusively used
for SGSN selection. It also adds a corresponding VTY command:

  - match-imsi patching RE : MS related patching (currently APN)
  - match-imsi routing RE  : Select secondary SGSN on match only
  - no match-imsi          : Clear all filter expressions

Ticket: OW#1258
Sponsored-by: On-Waves ehf
2014-10-09 18:06:30 +02:00
Jacob Erlbeck 6c3fdc1091 gbproxy: Extend the match-imsi VTY command to support categories
This patch modifies the match-imsi command to allow for different
match categories (currently only 'patching' is provided).

  - match-imsi patching RE : Filter APN patching and routing
  - no match-imsi          : Clear all filter expressions

Sponsored-by: On-Waves ehf
2014-10-09 18:05:17 +02:00
Jacob Erlbeck 9a83d7af55 gbproxy: Refactor IMSI matching
The current implementation makes it difficult to add further match
expressions.

This patch adds a new struct gbproxy_match that contains the fields
needed for each match expression. The matches (config) and the
results (link_info) are stored in arrays. All related functions are
updated to use them. The old fields in the config structure are
removed.

Sponsored-by: On-Waves ehf
2014-10-09 18:02:33 +02:00
Jacob Erlbeck 7e31f847af gprs: Fix gprs_msgb_copy pointer computation
Currently the pointers are computed by adding an offset to the new
message's _data pointer even when the original pointer is NULL.
This leads to invalid pointers in the copied msgb.

This patch adds a NULL check to each computation such that NULL
pointers are not adjusted.

Sponsored-by: On-Waves ehf
2014-10-09 18:00:55 +02:00