Commit Graph

128 Commits

Author SHA1 Message Date
Jan Engelhardt 9ffeb9756a build: remove unused all_includes and use AM_CPPFLAGS
Preprocessor flags are best placed in AM_CPPFLAGS. Remove use of the
unused all_includes variable, which is never set.
2014-10-03 08:48:31 +02:00
Holger Hans Peter Freyther 8d950eac9e msgfile: Fix memleak in the test and release the list 2014-08-29 14:21:14 +02:00
Sylvain Munaut 26ea7068e7 tests/bits: Make sure all 'inline' are also static
Not doing so seems to break the BSD build

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2014-06-16 15:57:36 +02:00
Sylvain Munaut 579a7103a1 gsm: Add Kasumi cipher implementation
Submitted-by: Max <max.suraev@fairwaves.co>
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2014-06-16 14:59:30 +02:00
Max 5377701746 core: Add generic LE/BE load/store uint type convertors and use them in msgb
Submitted-by: Max <max.suraev@fairwaves.co>
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2014-06-16 14:33:27 +02:00
Daniel Willmann 3dc4e16786 gsm/lapdm: Prevent LAPD tx_queue from filling up in polling mode
If LAPDm receives an I-Frame while there already is an I-Frame in the
tx_queue the code generates an additional RR (to acknowledge the
received I-Frame). Instead, N(R) of the I-Frame in the tx_queue should
be updated to ACK the data.
2014-03-26 18:11:07 +01:00
Daniel Willmann 09129352f9 tests/lapd: Add a testcase to check for LAPDm sync issues
Regression test for LAPDm recording the current state
2014-03-26 14:53:29 +01:00
Alexander Chemeris e4c50d5a43 sms_test: Do not crash on logging. 2014-03-20 22:02:46 +01:00
Jacob Erlbeck 8dac4159ad ladpm: Fix msgb handling and SAPI=3 establishment delay
Currently it takes 3s to establish a SAPI 3 SACCH connection with
osmo-bts. This is due to the fact, that a broken SABME request is
sent first and and is ignored by the MS. Then, after a T200 timeout
(2s) the SABME command is sent again (this time correctly) and
answered by the MS.

The first SABME message is broken (it has a length field of 3 and
ends with 3 bytes from the tail of the original RSL message),
because of it is expected throughout lapdm.c that msg buffers
containing RSL have msg->l2h == msg->data. Some abis input drivers
fulfill this but IPA doesn't, thus the 3 bytes of the IPA header
are still part of the msg and confuse length computation.

Since internal fields of the msg are modified directly, this is
difficult to see.

This patch adds a new function msgb_pull_to_l3() that explicitely
skips over all headers prepending L3 and therefore resets l1h and
l2h. This function is then used instead of msgb_pull_l2h() which
only worked correctly when msg->l2h == msg->data. In addition,
code manipulating msg->tail and msg->len directly has been replaced
by calls to msgb_trim().

Note that this patch does not fix all issues of this case in the LADP
related code.

Ticket: SYS#192
Sponsored-by: On-Waves ehf
2014-03-10 14:57:26 +01:00
Jacob Erlbeck 7d5f17aa21 lapd/test: Check for empty ACCH queue, too
This just adds a single test to verify that the ACCH queue is
actually empty.

Sponsored-by: On-Waves ehf
2014-03-04 13:34:38 +01:00
Jacob Erlbeck c893c2233a lapd/test: Extend test case to test msgs having data before l2h
Since e.g. the IPA input driver leaves it's specific header in front
of msg->l2h, so that msg->l2h != msg->data. The lapdm code does not expect this at least in
rslms_rx_rll_est_req().

This patch modifies the test program to add a dummy L1 header to
generated messages (unless the test would abort when doing so).

Note that the ok file reflects the current state which is not
correct.

Sponsored-by: On-Waves ehf
2014-03-04 13:34:38 +01:00
Jacob Erlbeck 2462cf6ee1 lapd/test: Show dequeued messages
This adds and uses a wrapper for lapdm_phsap_dequeue_prim() that
prints information about the message that has been taken from the
queue.
2014-03-04 13:34:38 +01:00
Jacob Erlbeck 90937fe2c5 lapd/test: Add test case for RSL EST REQ -> LAPD
This test case processes RSL establish requests for SMS (SAPI 3)
on the SDCCH and the SACCH channels. The TX queues are checked
after processing each message.

Ticket: SYS#192
Sponsored-by: On-Waves ehf
2014-01-26 08:39:20 +01:00
Jacob Erlbeck 26cbd459fc sms: Fix gsm_7bit legacy functions return value
The legacy 7bit conversion functions (those without the '_n_' in the
name) gave wrong return values on 64 bit platforms due to unproper
signed/unsigned conversions and the usage of SIZE_MAX.

This patch fixes this by using a smaller max size (see
GSM_7BIT_LEGACY_MAX_BUFFER_SIZE, currently set to 64k) for the legacy
wrappers and by using unsigned int for max_septets.
In addition, there are tests now that check the return values of
legacy encoding and decoding.

Sponsored-by: On-Waves ehf
2014-01-09 08:22:14 +01:00
Nils O. Selåsdal 3244702058 utils: Greatly improve performance of osmo_hexdump routines
In the osmo-bts and libosmo-abis code the hexdump routine is used
for every incoming/outgoing packet (including voice frames) and the
usage of snprintf showed up inside profiles.

There is a semantic change when more than 4096 characters are used.
The code will now truncate at byte boundaries (and not nibbles).

Code:
 static const int lengths[] = { 23, 1000, 52 };
 char buf[4096];
 int i;

 for (i = 0; i < 30000; ++i)
     char *res = osmo_hexdump(buf, lengths[i & 3]);

Results:

before:					after:
real    0m3.233s			real    0m0.085s
user    0m3.212s			user    0m0.084s
sys     0m0.000s			sys     0m0.000s
2014-01-02 14:08:11 +01:00
Holger Hans Peter Freyther b79a148eca utils: Add a simple testcase for osmo_hexdump
This code makes a simple dump and tests for the corner case
2014-01-02 13:59:10 +01:00
Holger Hans Peter Freyther b7d0f4686b logging: Copy the filter_fn and fix the IMSI filter in OpenBSC
The filter_fn has not been copied into the new structure breaking
the imsi and other filters in OpenBSC. Looking at the code we should
also introduce a callback for the reset of the context so we could
use subscr_get/subscr_put on the subscriber structure.
2013-12-29 19:38:01 +01:00
Max 4f0abc0e3e Refactor COMP128v23 implementation and add test suit 2013-12-07 18:10:38 +01:00
Jacob Erlbeck 3d557b18d0 gprs: Ignore NS RESET_ACK and ALIVE_ACK without RESET
Currently those messages are answered by a NS_STATUS message when
received on an uninitialised (no NS_RESET hat been seen yet) NS_VC
which violates GPP TS 08.16 7.3.1 and 7.4.1.

This patch adds checks to gprs_ns_vc_create() and eventually returns
before the error NS_STATUS message is generated.

Sponsored-by: On-Waves ehf
2013-10-30 15:23:18 +01:00
Jacob Erlbeck e7c427165f grps: Add test for NS messages that shall be ignored
Several messages shall not be answered when a RESET hasn't been
received on a NS-VC:
- NS_RESET_ACK (see 3GPP TS 08.16, 7.3.1)
- NS_ALIVE_ACK (see 3GPP TS 08.16, 7.4.1)
- NS_STATUS (see 3GPP TS 08.16, 7.5.1)

Sponsored-by: On-Waves ehf
2013-10-30 15:23:15 +01:00
Holger Hans Peter Freyther ce397dee70 lapd: Extend the test to check if lapdm_channel_exit is idempotent
I have a crash with an older libosmocore and the sysmobts. I
am not sure how we can have a release for a channel where the
lapdm_channel has not gone through lapdm_channel_init. But to
prevent the crash we can promise lapdm_channel_exit to be idempotent.

It has been idempotent since f5a079f739
2013-10-26 13:35:15 +02:00
Jacob Erlbeck 54b8b2dfef gb: Create new NSVC object instead of patching the NSVCI
When a RESET is received on the same link with a different NSVCI from
a BSS on a dynamically created NS connection do not patch the nsvc
object but create a new one instead. Thus the NSVCI is never modified
at a nsvc object after the NS-VC has been established.

Sponsored-by: On-Waves ehf
2013-10-24 10:01:18 +02:00
Jacob Erlbeck ab852ee234 gb: Fix RESET handling with changing NSEI
This modifies the NS stack's behavior to accept RESET and RESET_ACK
NSEI changes for NS-VC dynamically created by RESET messages from
BSSes. This feature is not used for NS-VC configured via VTY or NS-VC
to a SGSN.

Sponsored-by: On-Waves ehf
2013-10-24 10:01:18 +02:00
Jacob Erlbeck 5405a104bb gb: Fix NS RESET/RESET_ACK abnormal cases
This changes the implementations for the reception of RESET and
RESET_ACK to be compatible with 3GPP TS 08.16, 7.3.1:

- Just send a RESET_ACK with correct values back to the SGSN when a
  RESET with an invalid NSVCI or NSEI has been received.
- Check RESET_ACK for matching NSEI and NSVCI.
- Ignore unexpected RESET_ACKs.

In addition, use RESET_ACK from a BSS to update the BSS source
address based on the NSVCI to be tolerant with changing UDP source
addresses/ports.

Sponsored-by: On-Waves ehf
2013-10-24 10:01:18 +02:00
Jacob Erlbeck 81d7c14756 gb: Add test cases for NS RESET procedures
Add a test handling proper and mismatching RESETs. The latter may
occur, when ports change within a NS-VC without the SGSN getting
notice.

This tests for the behavior of the NS protocol stack for RESET and
RESET_ACK messages which changing/invalid NSEI and NSVCI like it is
being described in 3GPP TS 08.16, 7.3.1.

Sponsored-by: On-Waves ehf
2013-10-24 10:01:18 +02:00
Jacob Erlbeck a52ba0175f gb: Fix gprs_nsvc_delete() to free ctr group
This fixes a SEGV error that happens the next time the statistics
are updated.

Addresses:
 Program terminated with signal 11, Segmentation fault.
 #0  0xb7711fa5 in rate_ctr_group_intv (grp=<optimized out>) at
 rate_ctr.c:107
 107             for (i = 0; i < grp->desc->num_ctr; i++) {
 #0  0xb7711fa5 in rate_ctr_group_intv (grp=<optimized out>) at
     rate_ctr.c:107
 #1  rate_ctr_timer_cb (data=0x0) at rate_ctr.c:129
 #2  0xb770ec59 in osmo_timers_update () at timer.c:243
 #3  0xb770ef7a in osmo_select_main (polling=0) at select.c:133
 #4  0x08049987 in main (argc=3, argv=0xbfba8084) at
     gb_proxy_main.c:306

Sponsored-by: On-Waves ehf
2013-10-24 10:01:18 +02:00
Jacob Erlbeck bf0219654b gb: Fix gprs_active_nsvc_by_nsei()
The state matching condition is inverted. This is corrected by this
fix.

Sponsored-by: On-Waves ehf
2013-10-17 14:45:27 +02:00
Jacob Erlbeck 0d4e949e22 gb: Test sending messages to the SGSN
This adds tests for the gprs_ns_sendmsg() function. For this it
merges back functions from the gbproxy test.

Sponsored-by: On-Waves ehf
2013-10-17 14:45:27 +02:00
Jacob Erlbeck 5e6d679df3 gb: Fix gprs_ns_rx_reset to not create NS-VC duplicates
Under special circumstances (see below) receiving a NS-RESET leads to
duplicated NS-VC entries.

This happens when the source port of a NS-VC changes to a new one
that has already been used by another NS-VC.

This patch changes gprs_ns_rx_reset() to check for this case and to
use the existing NS-VC object. The NS-VC object that was associated
with the source address before is detached from this source but kept
in the NS-VC list so that it can be reattached when a correspondent
NS-RESET is received later on. Meanwhile it will have a cleared link
layer address which will not match a real link info.

A new counter NS_CTR_REPLACED is incremented each time when the NS-VC
object is replacing another one. A new signal S_NS_REPLACED is added
which gets dispatched in this case, too.

Another new counter NS_CTR_NSEI_CHG is incremented each time when the
NSEI of a NS-VC object (with fixed NSVCI) changes.

Ticket: OW#874
Sponsored-by: On-Waves ehf
2013-10-15 10:20:34 +02:00
Jacob Erlbeck 96550e0321 gb: Add functions to access the LL part of the NS-VC objects
Adds the functions gprs_ns_ll_copy() and gprs_ns_ll_clear(). Renames
gprs_ns_format_peer() to gprs_ns_ll_str(). All of these functions
uniformly access the link layer part within the NS-VC objects.

Sponsored-by: On-Waves ehf
2013-10-15 09:48:41 +02:00
Jacob Erlbeck 34fc4701c7 tests/gb: Show invoked signals in test output
Register an osmo signal handler to print a short notice about every
SS_L_NS signal that is generated while processing the tests.

Sponsored-by: On-Waves ehf
2013-10-11 14:41:40 +02:00
Holger Hans Peter Freyther 2c9168cf34 vty: Make vty_event dispatch signals and use it in the testcase
The testcase didn't work on Ubuntu 12.04 because vty_create will
directly call vty_event (e.g. not through the plt). This means
that the approach to override vty_event in the testcase failed.

Use the signal interface of libosmocore and make the testcase
use it. The signals can be generally useful as well.
2013-10-10 20:21:33 +02:00
Jacob Erlbeck b6390f9bd8 gb: Use the NS-VCI to find an existing NS-VC
Currently when a NS-RESET is recevied over a link that has not yet
been associated with a NS-VC, the NSEI is used to find an existing
NS-VC. If one is found, the reset procedure is initiated.

This behaviour is not conformant with 3GPP TS 08.16 (see chapter
4.2.3) which allows to use several NS-VC between two endpoints in
parallel.

The patch changes the implementation to use the NSVCI instead
of the NSEI to search for an existing NS-VC object.

Ticket: OW#874
Sponsored-by: On-Waves ehf
2013-10-08 14:51:17 +02:00
Jacob Erlbeck 05395a63b7 gb: Fix NS-RESET response message order
According to 3GPP TS 08.16, 7.3 "Reset procedure" the entity
receiving a NS-RESET PDU responds with a NS-RESET-ACK and 'then'
starts the test procedure which essentially means, that a NS-ALIVE
gets sent and a timer is started.

Currently the NS-ALIVE is sent before the NS-RESET-ACK.

This patch fixes the implementation by reversing the order in which
these messages are sent.

Sponsored-by: On-Waves ehf
2013-10-08 14:51:13 +02:00
Jacob Erlbeck dcce196be9 tests/gb: Add test for GPRS NS protocol
This tests the connection establishment by directly calling
gprs_ns_rcvmsg() and printing the resulting messages and the
NS-VC list.
2013-10-08 14:00:24 +02:00
Jacob Erlbeck 73ae7a9ca0 tests: Fix warnings
This fixes warnings that are raised by missing includes, missing casts,
missing return statements, using printf %lu with uint64_t, and unused
symbols.
2013-10-08 14:00:24 +02:00
Holger Hans Peter Freyther bb9f89745a tests: Fix the sms_test and use the right array
It started to behave weird on Debian Testing (GCC 4.8), I compiled it
with address sanitizer support and set a breakpoint in
__asan_report_error to get a backtrace.
2013-10-08 13:57:51 +02:00
Holger Hans Peter Freyther 5b6416a729 bssgp: Address various compiler warnings in the bssgp code
gb/bssgp_fc_test.c: In function ‘fc_out_cb’:
gb/bssgp_fc_test.c:46:1: warning: no return statement in function returning non-void [-Wreturn-type]
gb/bssgp_fc_test.c: In function ‘fc_in’:
gb/bssgp_fc_test.c:56:1: warning: no return statement in function returning non-void [-Wreturn-type]
gb/bssgp_fc_test.c: In function ‘test_fc’:
gb/bssgp_fc_test.c:79:3: warning: implicit declaration of function ‘usleep’ [-Wimplicit-function-declaration]
2013-09-16 14:13:25 +02:00
Holger Hans Peter Freyther 6ef71b062b vty: Fix compiler warning in the test 2013-09-10 11:17:46 +02:00
Jacob Erlbeck 0c987bd83b vty: Add vty_install_default() and use for the vty nodes
This adds the vty_install_default() function that is basically the
install_default() function plus the registration of the commands
'exit' and 'end'. The latter is only provided in subnodes of
ENABLED_NODE and CONFIG_NONE.

The VTY test program is extended to check these commands.

Ticket: OW#952
2013-09-08 10:49:52 +02:00
Holger Hans Peter Freyther 4d7e49bc0a sms: Implement encoding the address as alphanumeric type
The number of digits is the number of used octets times two (two
digits per octet). The result has been successfully dissected by
wireshark. It has not been tested with real phones.
2013-09-04 10:41:07 +02:00
Jacob Erlbeck 3c761c8d8a conv: Fix main() of conv_test to compile with clang.
Fix type of argument 'argv'.

Addresses:
conv/conv_test.c:358:5: error: second parameter of 'main' (argument
array) must
      be of type 'char **'
int main(int argc, char argv[])
2013-08-14 18:22:54 +02:00
Jacob Erlbeck 30fbcf5a41 tests: Move expensive tests to the end of the list
This lets make check fail earlier (in average) to shorten the
debugging cycle time.
2013-08-13 07:20:13 +02:00
Jacob Erlbeck 1d7f3b5eb2 sms: Added result buffer size parameter to 7bit conv funs
The 7bit<->8bit encoding/decoding functions didn't check whether
there is still enough space in the destination buffer. Therefore a
buffer size parameter has been added to each of the functions which
is used to truncate the output if the buffer is too small.

In addition, the return value of the decoding functions has been
changed to number of characters written (excluding \0), so this
value is always equal to strlen(decoded).

The old functions are still available as wrapper functions.
2013-08-12 17:22:27 +02:00
Jacob Erlbeck 8a1666b1bf ussd: Changed 7bit test to check spec conformance directly
Renamed gsm_7bit_ussd() to test_7bit_ussd() and extended the function
to take the expected binary encoding and eventually added trailing
bytes in the re-decoded text as arguments. These are used to check
assertions of the right behaviour instead of solely relying on
regression data, because the value are determined by the spec and
fixed and it is more obvious this way. Especially concerning the case
with the duplicated \r which can easily be overlooked when it's only
present in the ok file.
2013-08-08 14:29:17 +02:00
Andreas Eversberg 9597555a36 Add special 7-bit encoding and decoding functions for USSD coding
Handling 7-bit coding is a little different for USSD, as TS 03.38
states:

To avoid the situation where the receiving entity confuses 7 binary
zero pad bits as the @ character, the carriage return or <CR>
character shall be used for padding in this situation [...].

If <CR> is intended to be the last character and the message
(including the wanted <CR>) ends on an octet boundary, then another
<CR> must be added together with a padding bit 0. The receiving entity
will perform the carriage return function twice, but this will not
result in misoperation as the definition of <CR> [...] is identical to
the definition of <CR><CR>.

The receiving entity shall remove the final <CR> character where the
message ends on an octet boundary with <CR> as the last character.

Jacob has verified the fix with fakeBTS and the wireshark dissector.

Fixes: OW#947
Reviewed-by: Jacob Erlbeck <jerlbeck@sysmocom.de>
2013-08-08 14:27:13 +02:00
Holger Hans Peter Freyther 6bfa7445fc encoding: Provide an overload for the gsm_7bit_encode and a simple test
This is required for encoding the SMS header using the alpha numeric
rules.

Reviewed-by: Jacob Erlbeck <jerlbeck@sysmocom.de>
2013-08-08 14:25:09 +02:00
Jacob Erlbeck cd195fa267 vty: Support multi-char separators and end strings
In vty_cmd_string_from_valstr() include the real string lengths of
the sep and end arguments into the buffer size calculation.
2013-08-06 14:56:35 +02:00
Jacob Erlbeck ae15a2cac1 vty: Fix misusage of snprintf in vty/utils.c
Compiled with ubuntu 1204 (precise), where -Wformat-security is enabled by
-Wall.

Test yields ok, but the current implementation doesn't properly support
multi-character separators and end strings. So the test output is truncated.

Addresses:
utils.c: In function 'vty_cmd_string_from_valstr':
utils.c:84:2: warning: format not a string literal and no format arguments [-Wformat-security]
utils.c:84:2: warning: format not a string literal and no format arguments [-Wformat-security]
utils.c:108:2: warning: format not a string literal and no format arguments [-Wformat-security]
utils.c:108:2: warning: format not a string literal and no format arguments [-Wformat-security]
2013-08-06 14:56:30 +02:00
Harald Welte 98de27a187 make lapd_test compile again.
For whatever reason two functions were present twice in the code,
probably some git merge/rebase artefact?
2013-07-06 23:54:09 +02:00