Commit Graph

4974 Commits

Author SHA1 Message Date
Jacob Erlbeck 7ffa7b095f nitb: Fix IMSI/IMEI buffer handling (Coverity)
Currently the handling of the buffers is not done consistently. Some
code assumes that the whole buffer may be used to store the string
while at other places, the last buffer byte is left untouched in the
assumption that it contains a terminating NUL-character. The latter
is the correct behaviour.

This commit changes to code to not touch the last byte in the buffers
and to rely on the last byte being NUL. So the maximum IMSI/IMEI
length is GSM_IMSI_LENGTH-1/GSM_IMEI_LENGTH-1.

For information: We assume that we allocate the structure with
talloc_zero. This means we have NULed the entire imsi array and then
only write sizeof - 1 characters to it. So the last byte remains NUL.

Fixes: Coverity CID 1206568, 1206567
Sponsored-by: On-Waves ehf
2015-04-10 08:47:00 +02:00
Jacob Erlbeck 322b1499cd nitb: Check source string length before calling strncpy (Coverity)
Currently some VTY command do neither check the length of the source
string before calling strncpy nor ensure NUL-termination afterwards.
This can to destination string buffers whose contents are not
NUL-teminated.

This commit adds checks and corresponding warnings to the VTY
commands 'subscriber TYPE ID name .NAME" and "subscriber TYPE ID
extension EXTENSION".

Fixes: Coverity CID 1206570, 1206569
Sponsored-by: On-Waves ehf
2015-04-07 20:13:53 +02: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
Jacob Erlbeck 9ed6fd25dd nat: Fix timeslot range in 'show bsc mgcp' VTY command
Currently the inner loop in show_bsc_mgcp iterates of the timeslot
interval [0, 31]. Timeslot 0 is not valid, which causes
mgcp_timeslot_to_endpoint to generate a corresponding warning and to
return an invalid endp value. That value causes an out-of-bound
read access, possibly hitting unallocated memory.

This patch fixes the loop range by starting with timeslot 1.

Note that this does not prevent mgcp_timeslot_to_endpoint from
returning an invalid endpoint index when called with arguments not
within its domain.

Addresses:
<000b> ../../include/openbsc/mgcp.h:250 Timeslot should not be 0
[...]
    vty=0xb4203db0, argc=1, argv=0xbfffebb0) at bsc_nat_vty.c:256
        max = 1
        con = 0xb4a004f0
        i = 0
        j = 0
[...]
==15700== ERROR: AddressSanitizer: heap-use-after-free on address
0xb520be4f at pc 0x8062a42 bp 0xbfffeb18 sp 0xbfffeb0c

Sponsored-by: On-Waves ehf
2015-04-07 20:13:28 +02:00
Holger Hans Peter Freyther 08ea4d87f6 nat: Check for the access list in set command as well
I omitted the check as this was already done by the verify
function for this command. Please Coverity and do the check
again even if it is not necessary. I begin to doubt the
usage of a "dedicated" verify method as well.

Silences: Coverity CID 1293150
2015-04-07 09:10:05 +02:00
Holger Hans Peter Freyther 0ac00c15b9 nat: Check the con->imsi for the tracked IMSI
On DT messages we directly write into the tracked SCCP
connection. This means "imsi" will always be NULL at
this check. Change the code to use con->imsi

Fixes: Coverity CID 1293151
2015-04-07 09:06:26 +02:00
Holger Hans Peter Freyther 8ccf06c58b nat: Add ctrl command to save the configuration
$ bsc_control.py -d localhost -p 4250 -s net.0.save-configuration 0
2015-04-05 15:42:32 +02:00
Holger Hans Peter Freyther ab94ca18f2 nat: Add a ctrl command to add to an existing ACC list
We want to have a program add entries to the allow list
this can be done using:

$ bsc_control.py -d localhost -p 4250 -s net.0.add.allow.access-list.NAME "^IMSI$"
2015-04-05 15:42:25 +02:00
Holger Hans Peter Freyther 7c00983275 nat: Inform others if an IMSI is rejected
In case one wants to monitor the access lists one
there is now a trap for the IMSI.
2015-04-05 14:06:16 +02:00
Holger Hans Peter Freyther fa1cba9e60 nat: The reject cause of "-1" has failure meaning, change it
bsc_stat_reject is treating -1 as parsing failure but for the
global barring. Change it to another return value so it is
not counted as parsing failure.
2015-04-05 11:44:47 +02:00
Holger Hans Peter Freyther 6f6cbf7c5d bts: "Repair" broken channels if we receive the release ack
We had issues with odd behavior on the nanoBTS which lead
to the introduction of the "broken" state. On busy multi
BTS cells (e.g. rhizomatica) with wifi backhaul the timeout
we set to wait for a RF Channe Release ACK is sometimes too
little and channels are marked broken that look to be okay
(besides the still to be determined delay).

In case of a sysmoBTS we now know that we can change the
state of a broken channel back to normal in case we do
receive the right response.

Manually verified using the Smalltalk BTS code

PackageLoader fileInPackage: 'FakeBTS'
bts := FakeBTS.BTS new.
bts btsId: '1903/0/0'.
bts connect: 'localhost'.
bts waitForBTSReady.
test := FakeBTS.OpenBSCTest new.
test bts: bts.

test requireAnyChannel

... wait for NITB output
<0004> abis_rsl.c:223 (bts=0,trx=0,ts=0,ss=0) Timeout during deactivation! Marked as broken.

... process pending messages
stdin next
<0004> abis_rsl.c:735 (bts=0,trx=0,ts=0,ss=0) CHAN REL ACK for broken channel. Releasing it.

So the channel went from broken to unallocated.
2015-04-04 19:58:50 +02:00
Holger Hans Peter Freyther 40407835b3 bsc: Change paging strategy based on override or not
Change the paging strategy based on on if a LAC override
is in place or not. In case we had changed the LAC we need
to page on all the BTS. Change the "grace" handling to
iterate over the BTS and filter out all non matching ones
LAC in case no LAC handling is active.

Manually verified all four cases with a single BTS:

* No LAC handling and grace period
* LAC handling and grace period
* No LAC handling and not lock
* LAC handling and lock.

Related: SYS#1398
2015-04-01 19:26:26 +02:00
Holger Hans Peter Freyther 067ce6dea5 bsc: In preparation to the MT lac/ci patching split the code
For MT we can't page per lac as we don't know which BTS was
the original one. Split the grace period and normal mode into
two methods so we can bloat both of them later.
2015-04-01 19:26:24 +02:00
Holger Hans Peter Freyther 32dd2f3f9b bsc: Allow to use different LAC/CI for the core-network
We need to use different LAC/CI towards the core network.
It is a bit problematic as LAC/CI is a per BTS attribute
so this feature only works if a BSC manages everything in
the same LAC.

Related: SYS#1398
2015-04-01 19:26:12 +02:00
Holger Hans Peter Freyther 7cce1d301a libmgcp: Fail if transcoding can't be configured
We want to fail theallocation of an endpoint in case the
transcoding can't be configured.

Manually verified with:

./src/osmo-bsc_mgcp/osmo-bsc_mgcp -c doc/examples/osmo-bsc_mgcp/mgcp.cfg

$ ./contrib/mgcp_server.py
0000   32 30 30 20 33 30 36 39    200 3069
0008   31 20 4F 4B 0D 0A          1 OK.. ('127.0.0.1', 2427)
0000   34 30 30 20 35 39 30 36    400 5906
0008   39 20 46 41 49 4C 0D 0A    9 FAIL.. ('127.0.0.1', 2427)
0000   34 30 30 20 33 35 34 36    400 3546
0008   33 20 46 41 49 4C 0D 0A    3 FAIL.. ('127.0.0.1', 2427)
0000   34 30 30 20 36 32 31 37    400 6217
0008   30 20 46 41 49 4C 0D 0A    0 FAIL.. ('127.0.0.1', 2427)

Verified by not sending L: in the CRCX and then failing on the
MDCX.
2015-03-29 11:46:45 +02:00
Holger Hans Peter Freyther fd603ed9e2 write_queue: Check the result of osmo_wqueue_enqueue and free
The write_queue is designed to have a maximum amount of pending
messages and will refuse to take new messages when it has been
reached. The caller can decide if it wants to flush the queue
and add the message again, create a log. But in all cases the
ownership of the msgb has not been transferred. Fix the potential
memory leak in the failure situation.
2015-03-28 18:13:37 +01:00
Andreas Eversberg cf7557a7e7 rtp: Fixed problem of mute audio on some calls
When reading from RTP socket, the first read() may fail right after
connecting to remote socket. Subsequent read() will work as it should.

If the remote socket does not open fast enough, the transmitted RTP
payload can cause an ICMP (connection refused) packet reply. This causes
the read to fail with errno=111. In all other error cases, the errno is
logged at debug level. In all error cases, reading is not disabled.

Conflicts:
	openbsc/src/libtrau/rtp_proxy.c

[hfreyther: Fix typo, stop reading in all cases but ECONNREFUSED]
2015-03-28 17:56:16 +01:00
Holger Hans Peter Freyther 37b5ce56a0 rtp: Fix memory leak fixed by Andreas without mentioning it
We allocate the msgb at entry of the method and we always need
to msgb_free it.
2015-03-28 17:56:16 +01:00
Andreas Eversberg 9967a57587 rtp: Add handling of BFI (Bad Frame Indicatior) of received TRAU frames
If a bad TRAU frame is received, it is forwarded to MNCC application
as GSM_BAD_FRAME. The application can now handle the GAP of missing
audio. (e.g. by extrapolation)

If TRAU frames are forwarded via RTP, bad frames are dropped, but frame
counter and timestamp of RTP sender state is incremented.

Conflicts:
	openbsc/src/libtrau/rtp_proxy.c

[hfreyther: Merge without testcase, fix typo]
2015-03-28 17:56:08 +01:00
Max cea35aecdc ignore debian build byproducts
Signed-off-by: Max <max.suraev@fairwaves.co>
2015-03-28 17:13:57 +01:00
Holger Hans Peter Freyther 7ce72c1be8 rtp: And really catch up and remove all occurences of openbsc/rtp.h 2015-03-22 14:43:19 +01:00
Holger Hans Peter Freyther 7c7358e91e rtp: Catch up with the removal of the rtp.h 2015-03-22 13:56:30 +01:00
Holger Hans Peter Freyther d0e171a9ff rtp: Use osmocom/netif/rtp.h for the rtp structure definition
We depend on libosmo-netif unconditionally. Let's use this
definition of rtp and have one portability issue less.
2015-03-22 09:51:43 +01:00
Holger Hans Peter Freyther 8deba01eda debian: We are at version 0.14 now 2015-03-14 20:33:43 +01:00
Holger Hans Peter Freyther 66105fd3dc ctrl: Implement a global result for rf_locked
Create a one stop command to give a statement for the
entire network. This can be used to check the policy
and the state of the entire network.
2015-02-10 23:03:25 +01:00
Holger Hans Peter Freyther ca4151984c ctrl: Add a command to check how many bts are configured
This can be used to query how many bts are configured to
check if all of them are locked or not.
2015-02-10 21:55:37 +01:00
Holger Hans Peter Freyther 349c40f47b nitb: Move the rf-lock commands from osmo-bsc to libbsc
The bts.0.rf-state and rf_locked command have been moved
from the osmo-bsc binary to libbsc. All tests continue to
pass.
2015-02-10 21:37:16 +01:00
Holger Hans Peter Freyther a0735ecab5 smpp: Fix potential crash in handling submitSM
In case:

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

The code would execute:

  ud_len = *sms_msg + 1;

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

Fixes: Coverity CID 1042373
2015-02-08 09:56:31 +01:00
Holger Hans Peter Freyther 60e073e28d nat: getopt returns "static" data no need to copy it
I used strdup in case the data would not be valid from after
the call to getopt and this creates a potential leak if a user
is specifying multiple configuration files. If I depend on the
fact that the string is a pointer into the argv[] array I can
kill the strdup and fix the unlikely leak.

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

Fixes: Coverity CID 1210594
2015-02-08 09:21:04 +01:00
Sipos Csaba 56e1766dba nokia: Allow to set the reset time for the nokia bts 2015-02-07 13:27:36 +01: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
Holger Hans Peter Freyther f6f86b0eec osmo-bts: Introduce new struct for a power loop in the BTS code
Keep track if the power level has been "fixed" by the BSC,
otherwise keep track of the currently ordered one. The ms_power
is the initial value set by the BSC and continues to be used.
2015-02-05 22:25:03 +01:00
Holger Hans Peter Freyther 4e13a8f9f9 bsc/nitb: Allow to set the GPRS mode through the ctrl command
Create a control command to read and modify the gprs mode. Use
the get_string_value to indicate if the value was found or not.
This is useful for the ctrl interface where I didn't want to
replicate "none", "gprs" and "egprs". Share code to verify that
a BTS supports the mode.

Related: SYS#591
2015-01-31 22:38:48 +01:00
Holger Hans Peter Freyther b8c204cb92 ctrl/bsc: Fix copy and paste error and update text
30f1f37638 introduced new channel
combinations but had a copy and paste error in the description.
The jenkins system didn't run the external tests so this issue
and others were not noticed until now.

Fix the copy and paste and update the test result.
2015-01-31 19:42:42 +01:00
Holger Hans Peter Freyther 7af5f8130f rsl: Remove unused code for channel activation
The code has been unused for a long time. Let's remove it.
2015-01-31 12:49:41 +01:00
Holger Hans Peter Freyther 8657326093 meas: Install the scenario command and test it 2015-01-31 12:49:41 +01:00
Holger Hans Peter Freyther a07e38d4bf meas: Add VTY documentation for the measurement commands
Document the parameters that can be passed on.
2015-01-31 09:48:18 +01:00
Jacob Erlbeck 4b2d02d037 sgsn/test: Fix memory leak in test_subscriber_gsup
Currently the MM context is not deleted when a GSUP location
cancellation message is processed, because the real
sgsn_update_subscriber_data function has been wrapped to a dummy
implementation.

This commit adds an explicit call to sgsn_mm_ctx_cleanup_free which
also unassigns the LLME, so the call to gprs_llgmm_assign is removed.

It also adds an assertion to check that there are no talloc'ed blocks
left in tall_bsc_ctx.

Addresses:
== 372 bytes in 1 blocks are possibly lost in loss record 7 of 9
==    at 0x402A17C: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==    by 0x4059FB8: _talloc_zero (talloc.c:354)
==    by 0x8055B82: sgsn_mm_ctx_alloc (gprs_sgsn.c:167)
==    by 0x804A336: alloc_mm_ctx (sgsn_test.c:140)
==    by 0x804B24D: test_subscriber_gsup (sgsn_test.c:503)
==    by 0x804EC99: main (sgsn_test.c:1853)

Sponsored-by: On-Waves ehf
2015-01-30 21:33:29 +01:00
Jacob Erlbeck baf0f94a7d sgsn/test: Add checks for subscr->error_cause
This commits adds a few asserts that check the value of
subscr->error_cause after a GSUP message has been received.

Sponsored-by: On-Waves ehf
2015-01-30 21:32:47 +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 85ba655788 gprs/test: Fix GSUP Purge MS response messages
Currently the message types for these message types are wrong.

This patch inserts the correct message types.

Sponsored-by: On-Waves ehf
2015-01-30 21:29:58 +01:00
Jacob Erlbeck 466cedd052 sgsn/test: Add tests for PurgeMs responses
Currently there are not any test cases for PurgeMS GSUP messages in
test_subscriber_gsup.

This commit adds tests for incoming PurgeMSResult and -Error
messages.

Sponsored-by: On-Waves ehf
2015-01-30 21:28:17 +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