Commit Graph

3763 Commits

Author SHA1 Message Date
Andreas Eversberg 035b874fdf MNCC: Add IMSI to CALL CONFIRM message
LCR requires IMSI to correlate calls for MPTY (multi party conference)
and ECT (call transfer).
2014-08-04 08:59:16 +02:00
Andreas Eversberg 723a751e5f dyn PDCH: Cleanup of rsl_chan_activate_lchan() and users
Timing advance is stored inside lchan structure, so it is removed from
arguments. This is useful, if other actions are required prior calling
rsl_chan_activate_lchan. (like deactivating PDCH first)

The "shifted TA value" that is required by BS11 is now calculated inside
rsl_chan_activate_lchan and not by each user.

[Rebased by Holger. So some hunks were skipped as the patch
depended on Jolly's HO code]
2014-08-04 08:59:16 +02:00
Harald Welte 1011d5b505 vty: Fix interactive VTY help for silent-sms transmission 2014-08-02 09:58:52 +02:00
Harald Welte c7548a116c DB: produce a backtrace in case of a DB error
This helps us to identify where exactly in our code the DB error
originates from.
2014-08-02 09:58:52 +02:00
Holger Hans Peter Freyther 9b62580595 openbsc: Add new fields for the osmo-bts software
For the osmo-bts software we want to be able to slowly change the
output power. The state is kept inside the trx structure.
2014-07-30 18:20:51 +02:00
Holger Hans Peter Freyther 652cdb4699 trau: Cast to remove compiler warning
rtp_proxy.c: In function ‘rtp_decode’:
rtp_proxy.c:199:8: warning: assignment from incompatible pointer type
  frame = msgb_put(new_msg, sizeof(struct gsm_data_frame));
2014-07-24 21:09:31 +02:00
Holger Hans Peter Freyther 922ef5dc86 bts: Remember the last AMR mode that we received
Not every air message contains the AMR mode so we need to remember
it to not confuse receiving equipment like AudioCodes Media Gateways.
2014-07-24 21:05:32 +02:00
Jacob Erlbeck 03551e5f3c gprs: Move LLC IE length fix to BSSGP level
This commit moves the fixing code of the length field of the LLC
information element to the BSSGP patching level since that is not a
part of LLC itself.

Sponsored-by: On-Waves ehf
2014-07-22 17:13:32 +02:00
Jacob Erlbeck 2e2650f8f3 gprs: Parse PTMSI and update TLLI accordingly
This commit adds code to parse the PTMSI in network originated
messages

  - Attach Accept,
  - Routing Area Update Accept, and
  - P-TMSI Reallocation Command (see below)

to keep track of the TLLI identifying the LLC connection.

The P_TMSI Realloc Command specific code is not being tested yet, so
a corresponding notice is logged when such a message will be
received.

NOTE:
  The gbproxy will lose the TLLI when the MS doesn't receive/use
  the message (normally the SGSN remembers the old TLLI for some time
  to avoid this kind of problem). If this happens the MS will
  probably restart the procedure and the network will have to answer
  again eventually using one of the above messages which will
  re-associate the IMSI with the TLLI before the MS can send a
  PDP Context Request message.

Ticket: OW#1192
Sponsored-by: On-Waves ehf
2014-07-22 17:11:57 +02:00
Jacob Erlbeck 35cc03f97d gprs: Use struct to pass context information
Add a struct containing context information from the parts of the
message that have been parsed already. A pointer to this (temporary)
struct is passed to parse/patch functions.

Sponsored-by: On-Waves ehf
2014-07-22 17:10:51 +02:00
Jacob Erlbeck aefaf92d1a gprs: Use shift functions instead of manual parsing
Currently the patching code directly accesses the single bytes to
parse the LLC/DTAP messages.

This patch uses the shift functions instead to parse tlv and similar
structures.

Sponsored-by: On-Waves ehf
2014-07-22 17:08:28 +02:00
Jacob Erlbeck b138106423 gprs: Add TLV parse functions
This adds a set of function that parse a single tlv, lv, tv, or v
encoded information element. They are complementary to the *_put
functions defined in libosmocore's tlv.h file. The functions update
the data and data_len fields unless they are a 'match' function and
the tag field doesn't match.

Sponsored-by: On-Waves ehf
2014-07-22 17:08:10 +02:00
Jacob Erlbeck 040b4012a7 gprs: Fix TLLI cache size computation
Currently the enabled_tllis_count field isn't always decremented when
an element is removed from the TLLI cache list.

This patch adds the missing update and also adjusts the counter
accordingly.

Sponsored-by: On-Waves ehf
2014-07-22 17:05:16 +02:00
Jacob Erlbeck aa3e334608 gprs/test: Rearrange for PTMSI parsing
Add TLLI cache output to gbprox_dump_peers() to include this info
into the test output.

Separate RA Update Req message handling from Attach Request handling.

Note: There is no test case for the P-TMSI Reallocation Command yet.

Sponsored-by: On-Waves ehf
2014-07-22 17:03:23 +02:00
Jacob Erlbeck 25049b93b1 gprs: Add counters related to LLC layer patching
This commit adds the following counters:

  - attach-reqs:   Number of Attach Request messages
  - attach-rejs:   Number of Attach Reject messages
  - tlli-cache:    Size of the TLLI cache

Sponsored-by: On-Waves ehf
2014-07-22 17:02:43 +02:00
Jacob Erlbeck 7dd498de64 gprs/vty: Add commands to manage the TLLI list
These commands manage the TLLI list used to decide whether an APN
shall be patched or not. Note that this list is (currently) only
maintained if IMSI matching is used.

VTY commands (enable node):
  show gbproxy tllis                   show all TLLI entries
  delete-gbproxy-tlli NSEI stale       purge all stale entries
  delete-gbproxy-tlli NSEI imsi IMSI   purge entry with the IMSI given
  delete-gbproxy-tlli NSEI tlli TLLI   purge entry with the TLLI given

Sponsored-by: On-Waves ehf
2014-07-22 17:02:34 +02:00
Jacob Erlbeck 7c101d922e gprs: Track IMSI/TLLI to control APN patching
This patch adds IMSI/TLLI connection tracking and uses it to control
APN patching based on the IMSI. TLLI entries can expire based on age
and/or by limiting the TLLI list size.

VTY config-gbproxy:
  no core-access-point-name                   disable APN patching
  core-access-point-name none                 remove APN if present
  core-access-point-name APN                  replace APN if present
  core-access-point-name none match-imsi RE   remove if IMSI matches
  core-access-point-name APN match-imsi RE    replace if IMSI matches
  tlli-list max-age SECONDS                   expire after SECONDS
  no tlli-list max-age                        don't expire by age
  tlli-list max-length N                      keep N entries only
  no tlli-list max-length                     don't limit list length

RE is an extended regular expression, e.g. ^12345|^23456

Ticket: OW#1192
Sponsored-by: On-Waves ehf
2014-07-22 16:56:33 +02:00
Jacob Erlbeck 006c038212 gprs: Store gbproxy patching state per peer
Currently, all patching state is stored globally in the gbproxy. Thus
the feature cannot be used safely with a concentrating gbproxy (NAT).

This patch moves the state and relevant counters to the gbprox_peer
structure. It adds code to resolve the corresponding peer when
packets are received by looking at BVCI, NSEI, and BSSGP IEs (BVCI,
RAI/LAI/LAC) when the peer is not passed to the
gbprox_patch_bssgp_message() function.

Test cases are also added for the SGSN->BSS case including test cases
with invalid identifiers.

Note that this patch should make it possible to use RAI patching at a
NAT gbproxy as long as the messages are not encrypted.

Ticket: OW#1185
Sponsored-by: On-Waves ehf
2014-07-22 16:53:41 +02:00
Jacob Erlbeck cf02eb1b20 gprs/test: Add Detach messages to test
This patch adds a Detach Request (MO) / Detach Accept sequence to the
test, followed by another (here invalid) Act PDP Context Req which
should be APN patched.

Sponsored-by: On-Waves ehf
2014-07-22 16:19:57 +02:00
Jacob Erlbeck 1166974bca gprs/test: Added GMM Info and fixed TLLI
Add a DTAP GMM Information message with an IMSI in the BSSGP header
to enable the association between IMSI and TLLI.

The TLLI of the Routing Area Update messages is set to foreign.

Sponsored-by: On-Waves ehf
2014-07-22 16:18:40 +02:00
Jacob Erlbeck 736852825a gprs: Add APN patch support for LLC/GSM messages
Patch the APN in every 'Activate PDP Context Request' message to the
value given by the 'core-access-point-name' command. If the command is
given without an APN, the whole APN IE will be removed. If the
command is being prefixed by a 'no', the APN IE remains unmodified.

The patch mode 'llc-gsm' is added to selectively enable the patching
of LLC session management messages. This is enabled implicitely by
the patch mode 'llc'.

Note that the patch mode should not be set to a value not enabling
the patching of LLC GSM messages ('llc-gsm', 'llc', and 'default' are
sufficient to patch 'Activate PDP Context Request' messages).

Ticket: OW#1192
Sponsored-by: On-Waves ehf
2014-07-22 16:07:01 +02:00
Jacob Erlbeck 91fb680236 gprs: Add MCC/MNC patch support for LLC/GMM messages
This patch extends the BSSGP patch code to also patch LLC information
elements along with MCC/MNC patching support for the following messages:

- Attach Request
- Attach Accept
- Routing Area Update Request
- Routing Area Update Accept
- P-TMSI reallocation command

Note that encrypted packets will not be patched.

Ticket: OW#1185
Sponsored-by: On-Waves ehf
2014-07-22 16:05:59 +02:00
Jacob Erlbeck 67a4445675 gprs: Implement BSSGP MCC/MNC patching
This adds a feature to patch the BSSGP MNC/MCC fields of messages going
to and coming from the SGSN. To enable this feature, the gbproxy's
VTY commands 'core-mobile-country-code' and/or
'core-mobile-network-code' must be used. All packets to the SGSN are
patched to match the configured values. Packets received from the
SGSN are patched to the corresponding values as last seen from the BSS
side.

Note that this will probably not work with a gbproxy used for several
BSS simultaneously.

Note also, that MCC/MNC contained in a LLC IE will not be patched.

Ticket: OW#1185
Sponsored-by: On-Waves ehf
2014-07-22 16:04:54 +02:00
Jacob Erlbeck fd636aed1e gprs: Use imsi field instead of imei
The wrong field has been use for the field length computation. This
hadn't any impact so far, since
  sizeof(ctx->imei) == sizeof(ctx->imsi)

This patch fixes the computation to use the right field.

Sponsored-by: On-Waves ehf
2014-07-22 15:51:55 +02:00
Jacob Erlbeck ff0d65aaf6 gprs/test: Make test output more readable
This patch makes a few changes to improve readability:

- change the sendto() hexdump to start with NS instead of BSSGP
- use more specific message descriptions instead of 'UNITDATA'
- add a title line per test

Sponsored-by: On-Waves ehf
2014-07-22 15:48:53 +02:00
Holger Hans Peter Freyther a563641d25 osmux: Drop the message in case we don't know the remote yet.
Avoid creating a bogus state that will never go away.
2014-07-22 15:15:13 +02:00
Holger Hans Peter Freyther ea7ef38734 osmux: Qualify the handle by IPv4 address _and_ port
For our usecase several different systems might be behind the
same firewall so we need to distinguish the remote by more than
the IPv4 address.
2014-07-22 15:15:13 +02:00
Holger Hans Peter Freyther 48a071e366 osmux: Extract the dummy message, find the endpoint and set rtp port
Set the remote port for the endpoint. Somehow this needs to propagate
all the way to the handle.
2014-07-22 15:15:13 +02:00
Holger Hans Peter Freyther 07ec8eebe0 osmux: Send the CI as part of the dummy to help to identify a client
We need to discover the remote port as we are likely behind a NAT.
Right now the NAT code will just send to port 1984 on the BSC but
this might not arrive at the BSC. Include the CI (in the future we
need to include the endpoint address or send the dummy to the net
port). This is just an interim solution.
2014-07-22 15:15:06 +02:00
Holger Hans Peter Freyther 25a2db018e osmux: Using the "CI" and calling it "CID" is plain wrong
The CI is a MGCP value that is counted from 0 upwards. The code
is comparing a uint8_t with a uint32_t. This will only work for
up to UINT8_MAX calls and then will silently break. The code should
probably work with the endpoint number and not the CI. For now
truncate things and hope things work.
2014-07-22 15:11:07 +02:00
Holger Hans Peter Freyther cb6ad70994 mgcp: Change API to remove memory management from the name
Jacob pointed out that "free_endp" refers to the memory of
the endpoint being freed. What we want is actually a way to
release an endpoint (and the resource it allocated) or in
the case of the testcase/testapp initialize the data structure
correctly. Introduce two names for that.
2014-07-22 15:00:52 +02:00
Holger Hans Peter Freyther b936278b2e mgcp: Fix/test the case of a time jump and the resync
In case the sender didn't send a couple of frames we will have
a time gap that is bigger than the accepted delta. Add a new
testcase for this and update the next_time.
2014-07-22 14:48:07 +02:00
Holger Hans Peter Freyther 4c18d79475 mgcp: Add a testcase for 160->80 ptime handling 2014-07-22 14:48:07 +02:00
Holger Hans Peter Freyther c8b29083d2 mgcp: Initialise next_time in case the initial timestamp is not 0. 2014-07-22 14:48:07 +02:00
Holger Hans Peter Freyther bd4109babc mgcp: Document transcoding semantic and follow it
Transcoding from GSM to PCMA can lead to the MGCP MGW sending
two PCMA packages with the same sequence number and timestamp.
Once with the encoded audio and once completely empty.

This is because "state->dst_packet_duration" is 0 in most cases
(unless a ptime is forced) and we attempt to encode audio even
if there are not enough samples. The encode_audio return will
return 0 in that case which is not trated as an error by the
mgcp network code.

Handle rc == 0 specially and document the semantic.
2014-07-22 14:42:53 +02:00
Holger Hans Peter Freyther 91eeeae312 mgcp: Fix/test reading/writing the sequence number
The sequence number was read from the wrong place and then
the wrong byte order conversion routine was used so we ended
up wirting 0x00, 0x00 into the patched sequence number. Add
a testcase for that.
2014-07-22 14:31:35 +02:00
Holger Hans Peter Freyther 1fc1ed23b2 mgcp: Patch and Count _after_ the transcoding
When going from a ptime of 10 to 20 a lot of alignment errors
are reported. In fact the alignment check should be done before
and after the transcoding. As this is not possible right now
only do it _after_ the patching.
2014-07-22 14:31:28 +02:00
Holger Hans Peter Freyther 77ceaaf7f5 mgcp: Add a comment about the return of the function 2014-07-22 13:51:39 +02:00
Holger Hans Peter Freyther dd1f81512d mgcp: Make the internal state of the transcoder accessible
For the unit tests we need to look at the internal state.
2014-07-22 13:12:19 +02:00
Holger Hans Peter Freyther 4fb7e64da2 mgcp: Capture the return value of the of the transcode function 2014-07-22 13:12:12 +02:00
Holger Hans Peter Freyther 6041c8db27 mgcp: Do not use errx as finding a test failure is too hard
It took me a long time to figure out that errx just exits and
the test output didn't indicate that the application was exited
early. Use a printf and good old abort in case of a failure.
2014-07-22 13:12:05 +02:00
Holger Hans Peter Freyther 83cbac2ac0 mgcp: Re-factor testcase to separate test and setup
Separate the test from the code necessary for the setup. This is
somehow inspired by the PhExample framework of Pharo.
2014-07-22 13:11:59 +02:00
Holger Hans Peter Freyther e52ca9aad1 mgcp: Warn when the buffer is being reset due a wrong seq number
When the sample buffer is being dropped write a warning so we can
see how often this event occurs.
2014-07-22 12:41:48 +02:00
Holger Hans Peter Freyther a7992e0389 mgcp: Mention the packet duration in the error message 2014-07-22 12:41:32 +02:00
Holger Hans Peter Freyther 3d93d35a93 mgcp: Provide more information about configured endpoints 2014-07-22 12:41:25 +02:00
Holger Hans Peter Freyther c5c239f361 mgcp: Fix memory leak in the transcoding code
The GSM handle was never released. This was found using valgrind
and the leak check.

==14933== 752 bytes in 1 blocks are definitely lost in loss record 15 of 19
==14933==    at 0x4028B4C: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==14933==    by 0x4130201: gsm_create (in /usr/lib/i386-linux-gnu/libgsm.so.1.0.12)
==14933==    by 0x80517AE: mgcp_transcoding_setup (mgcp_transcode.c:199)
==14933==    by 0x8049691: given_configured_endpoint.isra.1 (mgcp_transcoding_test.c:198)
==14933==    by 0x8049C11: test_transcode_result (mgcp_transcoding_test.c:328)
==14933==    by 0x8049418: main (mgcp_transcoding_test.c:582)
2014-07-22 12:40:59 +02:00
Holger Hans Peter Freyther 24fc435dad trau_mux.c: Prevent out-of-bounds read in trau_decode_fr()
Haralds patch in 9f109dfb99 only fixed
the trau_encode_fr part but the issue seems to exist in the decode
function as well. Apply the same fix.
2014-07-22 12:23:03 +02:00
Holger Hans Peter Freyther 94f83e1787 smpp: Fix small typo in the comment 2014-07-19 19:02:46 +02:00
Holger Hans Peter Freyther d29b8a4745 bsc: Implement a way to relay a message to the remote MSC
This is analogue to the notification that is relayed locally and
now we have a way to relay a message back to the network.
2014-07-09 15:22:21 +02:00
Holger Hans Peter Freyther c6e9049f9c osmux: Now that we have IPv4/port we might want to consider to expire handles 2014-07-09 13:51:29 +02:00
Holger Hans Peter Freyther 9d43cee88c osmux: Mention where the data was coming from 2014-07-09 13:51:04 +02:00
Holger Hans Peter Freyther 7239f574aa osmux: Be accurate. The label has been already created 2014-07-09 13:50:56 +02:00
Holger Hans Peter Freyther 6b0ba01bf3 osmux: Make sure to always use the right dummy sending method
Make sure to re-use the right method for nat traversal. Found
by Roch while looking at traces.
2014-07-08 13:08:00 +02:00
Holger Hans Peter Freyther 768580b3ec bsc: Use the word core network and not backbone. 2014-07-08 12:48:49 +02:00
Holger Hans Peter Freyther 891b0a857d osmux: Remove extra newline from the osmux log message
<000b> osmux.c:177 Cannot find endpoint with cid=7
!
<000b> osmux.c:253 Cannot find an endpoint for circuit_id=7

The extra newline and '!' do not provide any extra value and
make reading the output more difficult. Just remove it.
2014-07-08 09:08:34 +02:00
Jacob Erlbeck 627e7d9bfe gprs/test: Increase stderr log level
Enable the generation of more log messages.

Sponsored-by: On-Waves ehf
2014-07-07 20:07:34 +02:00
Holger Hans Peter Freyther 2840b3f6c3 gbproxy_test: Provide enough disabled categories to please valgrind
An empty log_info is not enough. We need to make sure that at least
DLGLOBAL is present. Instead of doing that make sure that we have
enough entries.

==26163== Conditional jump or move depends on uninitialised value(s)
==26163==    at 0x403B289: osmo_vlogp (logging.c:290)
==26163==    by 0x403B3DA: logp2 (logging.c:339)
==26163==    by 0x804D027: gbprox_relay2bvci (gb_proxy.c:347)
==26163==    by 0x804D3CF: gbprox_rx_sig_from_sgsn (gb_proxy.c:589)
==26163==    by 0x804DBFC: gbprox_rcvmsg (gb_proxy.c:685)
==26163==    by 0x4052CB0: gprs_ns_process_msg (gprs_ns.c:669)
==26163==    by 0x4052F70: gprs_ns_rcvmsg (gprs_ns.c:1053)
==26163==    by 0x804BB49: gprs_process_message (gbproxy_test.c:488)
==26163==    by 0x804BC4C: send_ns_unitdata (gbproxy_test.c:210)
==26163==    by 0x804BDE8: send_bssgp_reset_ack (gbproxy_test.c:243)
==26163==    by 0x804B54F: main (gbproxy_test.c:863)
==26163==
2014-07-07 19:48:14 +02:00
Holger Hans Peter Freyther 461966b8ef mgcp: Ignore the transcoding test 2014-07-07 19:24:43 +02:00
Holger Hans Peter Freyther 8d998a713e mgcp: Verify that the force-ptime is written back to the file
When the command was added it was not verified that. Add a very
basic MGCP VTY test and test that the string appears in the config.
2014-07-07 19:24:34 +02:00
Holger Hans Peter Freyther 2947411383 mgcp: Fix documentation issue in the force-ptime command
<command id='rtp force-ptime (10|20|40)'>
        <param name='10' doc='(null)' />
        <param name='20' doc='(null)' />
        <param name='40' doc='(null)' />
2014-07-07 19:24:28 +02:00
Holger Hans Peter Freyther 983c99113d rtp: Share the rtp header between the proxy and the mgcp code 2014-07-07 19:24:21 +02:00
Holger Hans Peter Freyther 6019b5a508 nat: Fix the documentation issue with the osmux command
Documentation error (missing docs):
<command id='osmux (on|off)'>
        <param name='off' doc='(null)' />
2014-07-07 19:24:14 +02:00
Holger Hans Peter Freyther 84db98fdbe gbproxy_test: Reset the gbproxy before we reset GPRS NS
The peers are (talloc) children of the GPRS NS. This means the
peers (and the rate counters) are currently being deleted twice.

==23446== Invalid write of size 4
==23446==    at 0x403C243: rate_ctr_group_alloc (linuxlist.h:66)
==23446==    by 0x4050974: gprs_nsvc_create (gprs_ns.c:209)
==23446==    by 0x405320D: gprs_ns_instantiate (gprs_ns.c:1330)
==23446==    by 0x804ABEB: main (gbproxy_test.c:666)
==23446==  Address 0x4300694 is 52 bytes inside a block of size 784 free'd
==23446==    at 0x4029DA8: free (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==23446==    by 0x4041B9D: _talloc_free (talloc.c:609)
==23446==    by 0x4043292: talloc_free (talloc.c:578)
==23446==    by 0x40532D3: gprs_ns_destroy (gprs_ns.c:1363)
==23446==    by 0x804ABD7: main (gbproxy_test.c:660)
2014-07-07 19:22:02 +02:00
Daniel Willmann 46d13268b8 gprs_llc: Prevent llme_alloc/lle_init from reading invalid memory
Make the llc_default_params structure from which data is initialized
large enough. Otherwise address sanitizer complains with out-of-bounds
reads.

Only SAPIs 1, 2, 3, 5, 7, 8, 9, 11 are defined for GPRS but the
struct gprs_llc_llme includes NUM_SAPIS lle's and they are populated
from the llc_default_params structure.
2014-07-07 19:17:54 +02:00
Daniel Willmann 8a485f0bec libbsc, osmo-bsc{, _nat}: Prevent unaligned access when casting TLVP_VAL
foo = *((uintXX_t *) TLVP_VAL(...) can lead to unaligned access. To
prevent that use tlvp_valXX_unal() to get the values.
2014-07-07 19:04:32 +02:00
Holger Hans Peter Freyther 99a20d6be1 gbproxy_test: Simplify the test setup by sharing code 2014-07-07 15:06:21 +02:00
Jacob Erlbeck 7fb42dbd27 gprs/test: Add additional gbproxy tests
This adds a test case with several messages to test BSSGP patching.
New messages:

- BSSGP/DTAP Attach Request
- BSSGP/DTAP Attach Accept
- BSSGP/DTAP Routing Area Update Request
- BSSGP/DTAP Routing Area Update Accept
- BSSGP/DTAP Activate PDP Context Request
- BSSGP SUSPEND
- BSSGP SUSPEND ACK

Sponsored-by: On-Waves ehf
2014-07-07 15:06:12 +02:00
Jacob Erlbeck 2e038f7336 gprs/test: Add connect_sgsn() function
This function abstracts identical code sequences that are used at
multiple places.

Sponsored-by: On-Waves ehf
2014-07-07 15:06:06 +02:00
Jacob Erlbeck b32d3c041b gprs/test: Remove verbose parameter of gbprox_dump_* functions
This parameter is not used (the methods are always called with an
argument of 1 in the third position). Thus the parameter is removed
completely.

Sponsored-by: On-Waves ehf
2014-07-07 15:05:59 +02:00
Holger Hans Peter Freyther b115cb6655 db: Use ulonglong to access the database for sqlite3
The type in the schema is integer but we need to use ulonglong to
read it as otherwise the read will fail.

DBI: -7: The requested variable type does not match what libdbi thinks it should be
2014-07-03 14:12:24 +02:00
Harald Welte 9f109dfb99 trau_mux.c: Prevent out-of-bounds read in trau_encode_fr()
found by -fsanitize=address the last iteration of the loop, where i ==
259 and o == 260.  It is read out-of-bounds but the content is never
used.
2014-06-23 09:49:29 +02:00
Holger Hans Peter Freyther db0caf239e nitb: Only print channel activations once in show statistics
openbsc_vty_print_statistics will already print these counters
for us. No need to print them again.
2014-06-18 08:34:54 +02:00
Holger Hans Peter Freyther 421365eeaa mgcp: Allow to batch more than four messages 2014-06-16 14:12:02 +02:00
Jacob Erlbeck 8f50359ebf gprs: Use area terms LAI/RAI as defined in GSM 03.03
Currently the terms 'Routing area code' (RAC) and 'Location area
code' (LAC) are used in several places where 'Routing area
identification' (RAI) or 'Location area identification' (LAI) are
meant in fact.

This patch replaces RAC/LAC by RAI/LAI and 'code' by 'identification'
at these places.

Note that RAI := MCC MNC LAC RAC, and LAI := MCC MNC LAC (see GSM
03.03, sections 4.1 and 4.2).

Sponsored-by: On-Waves ehf
2014-06-15 19:23:38 +02:00
Jacob Erlbeck cb04ca2fc3 mgcp: Fix SDP formatting of fmtp_extra (Coverity)
Currently when ftmp_extra is set, a doubled a=rtpmap line is emitted
instead of the fmtp_extra info.

This patch fixes replaces the formerly copied and pasted but not
modified snprintf parameters by the correct ones.

Fixes: Coverity CID 1220873
Sponsored-by: On-Waves ehf
2014-06-15 19:15:32 +02:00
Jacob Erlbeck bebf92d7f0 mgcp/test: Add test case using the fmtp_extra info
Add tests setting the fmtp_extra field to check the response
generation. This triggers a bug found by Coverity.

Addresses: Coverity CID 1220873
Sponsored-by: On-Waves ehf
2014-06-15 19:15:09 +02:00
Holger Hans Peter Freyther 4e5f93ccdc proxy: Annotate the switch/case/fall through
Use the same comment as some lines earlier in that file.

Fixes: Coverity CID 1040737
2014-06-12 11:32:25 +02:00
Holger Hans Peter Freyther b07df2bfd4 bsc: Do not use strdup on argv parameter
Fixes: Coverity CID 1206578
2014-06-12 11:19:38 +02:00
Jacob Erlbeck 452c183c5e mgcp: Set net_end audio params in recvonly mode
Currently, if there is no SDP data in the MGCP message received from
the net, the fields containing audio encoding information are not set
in net_end. So in recvonly mode transcoding would not be set up
correctly.

This patch changes the implementation of the code handling CRCX and
MDCX to use the codec signalled in the MGCP local connection options
(field 'a:') if there isn't any SDP data. This is only halfway
negotiation, because the codec is used blindly and not matched
against the supported ones.

Sponsored-by: On-Waves ehf
2014-06-05 14:09:52 +02:00
Jacob Erlbeck 909fac6689 mgcp: Move transcoding to libmgcp
This patch moves the files relevant to transcoding from
src/osmo-bsc_mgcp to src/libmgcp and src/include/openbsc. Makefiles
and include directives are being updated accordingly.

Sponsored-by: On-Waves ehf
2014-06-05 14:08:53 +02:00
Jacob Erlbeck 84a45cbf83 mgcp/test: Add test cases for transcoding and repacking
This patch adds test cases for transcoding and repacking.

Sponsored-by: On-Waves ehf
2014-06-05 14:08:53 +02:00
Jacob Erlbeck 07886d9b0a mgcp: Extend the CLI transcoding tool by ptime conversion
This modification allows it to set the number of samples per packet
that is written to the output.

Sponsored-by: On-Waves ehf
2014-06-05 14:08:53 +02:00
Jacob Erlbeck 42a833e89f mgcp: Add packet size (ptime) conversion
The current transcoder implemenation always does a 1:1 recoding
concerning the duration of a packet. So RTP timestamps and sequence
numbers are not modified.

This is not sufficient in some cases, e.g. when the BTS does only
allow for a single fixed ptime.

This patch decouples encoding from decoding and moves the decoded
samples to the state structure so that samples can be combined or
drain according to the packaging of incoming and outgoing packets.

This patch incorporates parts of Holger's experimental fixes in
0e669e05^..9eba68f9.

Ticket: OW#1111
Sponsored-by: On-Waves ehf
2014-06-05 14:08:45 +02:00
Jacob Erlbeck 136a319e91 mgcp: Add CLI tool to test audio conversion
This tool uses mgcp_transcode.c to convert audio data from stdin to
stdout.

Sponsored-by: On-Waves ehf
2014-06-05 14:00:47 +02:00
Jacob Erlbeck 239a853f40 mgcp: Add RTP audio transcoding
This patch implements audio transcoding between the formats GSM,
PCMA, L16, and optionally G.729.

The feature needs to be enabled by using the autoconf option
'--enable-mgcp-transcoding'. In this case mgcp_transcode.c will
be compiled and linked to osmo-bsc_mgcp, and the transcoding
functions provided will be registered as processing callbacks.

If G.729 support is required, libcg729 needs to be installed and
'--with-g729' must be passed to ./configure.

Ticket: OW#1111
Sponsored-by: On-Waves ehf
2014-06-05 14:00:47 +02:00
Jacob Erlbeck 997e1e8e9d mgcp: Only include SDP lines with valid content
Don't show media related lines if the payload type has not been set.
Don't show a 'a=rtpmap' line if the audio_name has not been set.

This patch unifies the SDP generation of create_response_with_sdp()
and send_msg().

Sponsored-by: On-Waves ehf
2014-06-05 14:00:46 +02:00
Jacob Erlbeck 168ca00b02 mgcp: Add a function to get media info for MGCP responses
This patch adds the get_net_downlink_format_cb() callback to provide
payload_type, subtype_name, and fmtp_extra suitable for use in a MGCP
response sent to the network. Per default, the BTS side values are
returned since these must be honoured by the net peer when sending
audio to the media gateway (unless transcoding is done).

Sponsored-by: On-Waves ehf
2014-06-05 14:00:46 +02:00
Jacob Erlbeck 845d0054b4 mgcp: Add audio info fields to struct mgcp_rtp_end
This patch adds the fields channels, subtype_name, and audio_name to
the struct. The field audio_name contains the full string that has
been used for the last part of a SDP a=rtpmap line. The others contain
decoded parts of that string. If no a=rtpmap line has been given
(e.g. because dynamic payload types are not used), values are
assigned when the payload type matches one of the predefined ones
(GSM, G729, PCMA).

The patch also moves the audio_name parsing code to a dedicated
set_audio_info() function.

Sponsored-by: On-Waves ehf
2014-06-05 14:00:41 +02:00
Jacob Erlbeck a0d64ce063 mgcp: Add callbacks for payload processing
This patch adds the callbacks rtp_processing_cb and
setup_rtp_processing_cb to mgcp_config to support arbitrary RTP
payload processing.

Sponsored-by: On-Waves ehf
2014-06-05 12:19:46 +02:00
Jacob Erlbeck b492d39177 gprs: Separate LLC parsing from LLC state handling
Currently LLC parsing is part of gprs_llc.c which needs large parts
of the SGSN code parsing to fulfill its link dependencies.

This patch moves the functions that just do plain parsing, dumping,
and FCS computation to a different file to avoid these dependencies
if LLC stateful processing is not needed. It also exposes
struct gprs_llc_hdr_parsed and enum gprs_llc_cmd publically.

Sponsored-by: On-Waves ehf
2014-06-04 16:29:30 +02:00
Jacob Erlbeck def0391ec5 gprs/test: Use valid MCC/MNC for BVC RESET
The code currently uses an encoded sequence of (hex) 10 20 30 40 50
60 as RAI, for which no bijective mapping to the set of
representations MCC-MNC-LAC-RAC exists.

This patch changes the hard-coded RAI to 11 22 33 40 50 60 which maps
to 112-332-16464-96 (and vice-versa).

Sponsored-by: On-Waves ehf
2014-06-04 16:20:46 +02:00
Holger Hans Peter Freyther cc84c9535c osmux: Fix the VTY online help in the osmux command
This should fix most of:

Documentation error (missing docs):
<command id='osmux (on|off)'>
        <param name='off' doc='(null)' />

Documentation error (missing docs):
<command id='osmux batch-factor &lt;1-4&gt;'>
        <param name='&lt;1-4&gt;' doc='(null)' />

Documentation error (missing docs):
<command id='osmux (on|off)'>
        <param name='off' doc='(null)' />

Documentation error (missing docs):
<command id='osmux (on|off)'>
        <param name='off' doc='(null)' />

Documentation error (missing docs):
<command id='osmux batch-factor &lt;1-4&gt;'>
        <param name='&lt;1-4&gt;' doc='(null)' />
2014-06-03 13:36:42 +02:00
Holger Hans Peter Freyther 889710c890 Merge branch 'hfreyther/fixes/channel-release-handling'
The patches were posted to the ML but didn't receive review
there. At the time I merge the change I did a Location Updating
Request and the channel was released in a successful way.
2014-06-03 13:25:02 +02:00
Holger Hans Peter Freyther 0e4e73a891 rsl: Check if the channel is active and then start the channel release
In case we receive ERROR INDICATION and CONNECTION FAILURE we only
want to RF Channel Release the lchan once. This code is more simple
and should work as reliable as the previous commit.
2014-06-03 12:51:16 +02:00
Holger Hans Peter Freyther 1e93b79cce rsl: Avoid double channel release procedure in error conditions
When we receive an ERROR INDICATION and CONNECTION FAILURE we
might call rsl_rf_chan_release multiple times. The channel release
handling is still a bit messy and there too many paths that lead
to the call.

1.) In case we receive an ERROR INDICATION for SAPI=3. A RLL
error signal will be emitted that leads to the release of the
channel through the SMS code in case of the NITB.  The call to
rsl_rf_chan_release might be a double release.

2.) In case a CONNECTION FAILURE is received when the release
process has already been started we would unconditionally
call rsl_rf_chan_release as well.

Because the lchan state is changed by the callers of the
rsl_rf_chan_release we can not move the state checking into this
code but need to do it in the caller. The issue was seen in a trace
from Rhizomatica and I created the DoubleRelease.st to re-produce
the issue and verified that we have no duplicate RF Channel Releses.

The other option would be to introduce a new state to track
the release process and see if we have already released SAPIs
deactivated the SACCH or such. We can not simply look at these
as for a channel that fails to activate they will be null already.
2014-06-03 12:51:16 +02:00
Holger Hans Peter Freyther f0405068d8 lchan: Speculative "fix" for error and late reply
Looking at the code it seemed possible that a channel would
transition from BROKEN to NONE. Or worse from NONE to BROKEN.
Start the timer _after_ the channel has been released.
2014-06-03 12:51:16 +02:00
Holger Hans Peter Freyther 5308fffc53 bsc: Introduce a local notification scheme for the CTRL interface
Make it possible to inform local CTRL connections about some state.
The TRAP will be only sent to local connections. The notification
text may not contain spaces.
2014-05-31 08:42:29 +02:00
Holger Hans Peter Freyther 4f0381b1c3 mgcp: Address scanf issue already found by cppcheck and now ASAN
Use the right size for scanf.

=================================================================
==6106== ERROR: AddressSanitizer: unknown-crash on address 0xbffff4b0 at pc 0xb69d87fd bp 0xbffff248 sp 0xbffff21c
WRITE of size 65 at 0xbffff4b0 thread T0
    #0 0xb69d87fc (/usr/lib/i386-linux-gnu/libasan.so.0.0.0+0xa7fc)
    #1 0xb69d9239 (/usr/lib/i386-linux-gnu/libasan.so.0.0.0+0xb239)
    #2 0xb69d92d6 (/usr/lib/i386-linux-gnu/libasan.so.0.0.0+0xb2d6)
    #3 0x804f151 (/home/ich/source/gsm/openbsc/openbsc/tests/mgcp/mgcp_test+0x804f151)
    #4 0x80531e8 (/home/ich/source/gsm/openbsc/openbsc/tests/mgcp/mgcp_test+0x80531e8)
    #5 0x8051e6f (/home/ich/source/gsm/openbsc/openbsc/tests/mgcp/mgcp_test+0x8051e6f)
    #6 0x8049b0a (/home/ich/source/gsm/openbsc/openbsc/tests/mgcp/mgcp_test+0x8049b0a)
    #7 0x804bd9e (/home/ich/source/gsm/openbsc/openbsc/tests/mgcp/mgcp_test+0x804bd9e)
    #8 0xb6778a62 (/lib/i386-linux-gnu/i686/cmov/libc-2.18.so+0x19a62)
    #9 0x8049330 (/home/ich/source/gsm/openbsc/openbsc/tests/mgcp/mgcp_test+0x8049330)
Address 0xbffff4b0 is located at offset 416 in frame <parse_sdp_data> of T0's stack:
  This frame has 8 object(s):
    [32, 36) 'audio_payload'
    [96, 100) 'payload'
    [160, 164) 'channels'
    [224, 228) 'ptime'
    [288, 292) 'port'
    [352, 368) 'ipv4'
    [416, 480) 'audio_name'
    [512, 576) 'audio_codec'
HINT: this may be a false positive if your program uses some custom stack unwind mechanism or swapcontext
      (longjmp and C++ exceptions *are*
2014-05-28 17:00:56 +02:00
Holger Hans Peter Freyther b691bf1d54 channel_test: Return a positive number to claim it was paged
This addresses an ASAN issue where the request was already deleted
by our callback function.

(gdb) where
 #0  0xb69e7810 in __asan_report_error () from /usr/lib/i386-linux-gnu/libasan.so.0
 #1  0xb69e0aff in __asan_report_store4 () from /usr/lib/i386-linux-gnu/libasan.so.0
 #2  0x0804ea64 in subscr_send_paging_request (subscr=subscr@entry=0xb5103cb0)
     at gsm_subscriber.c:212
 #3  0x0804edac in subscr_get_channel (subscr=subscr@entry=0xb5103cb0, type=type@entry=2,
     cbfn=cbfn@entry=0x804969d <subscr_cb>, param=param@entry=0x2342) at gsm_subscriber.c:246
 #4  0x080498f7 in main (argc=1, argv=0xbffff804) at channel_test.c:77

Breakpoint 3, subscr_paging_dispatch (hooknum=hooknum@entry=101, event=event@entry=200,
    msg=msg@entry=0x1323, data=<optimized out>, data@entry=0x8063900 <s_conn>,
    param=<optimized out>, param@entry=0xb5103cb0) at gsm_subscriber.c:126
126		llist_del(&request->entry);

 (gdb) b llist_del
 (gdb) bt
 #0  subscr_paging_dispatch (hooknum=hooknum@entry=101, event=event@entry=200,
     msg=msg@entry=0x1323, data=<optimized out>, data@entry=0x8063900 <s_conn>,
     param=<optimized out>, param@entry=0xb5103cb0) at gsm_subscriber.c:126
 #1  0x0804e8a9 in subscr_paging_cb (hooknum=101, event=200, msg=0x1323,
     data=0x8063900 <s_conn>, param=0xb5103cb0) at gsm_subscriber.c:187
 #2  0x080497e9 in paging_request (bts=0xb5b03e70, subscriber=subscriber@entry=0xb5103cb0,
     type=2, cbfn=cbfn@entry=0x804e881 <subscr_paging_cb>, data=data@entry=0xb5103cb0)
     at channel_test.c:51
 #3  0x0804ea39 in subscr_send_paging_request (subscr=subscr@entry=0xb5103cb0)
     at gsm_subscriber.c:207
 #4  0x0804edac in subscr_get_channel (subscr=subscr@entry=0xb5103cb0, type=type@entry=2,
     cbfn=cbfn@entry=0x804969d <subscr_cb>, param=param@entry=0x2342) at gsm_subscriber.c:246
 #5  0x080498f7 in main (argc=1, argv=0xbffff804) at channel_test.c:77
(gdb) q
2014-05-28 17:00:48 +02:00
Holger Hans Peter Freyther f6b61e6154 mgcp: Use #pragma once instead of a possible clashing #ifdef
The filename is mgcp_internal.h but the define refers to MGCP_DATA.
Avoid having a potential clash by using the #pragma once option.
2014-05-26 08:17:45 +02:00