Commit Graph

580 Commits

Author SHA1 Message Date
Daniel Willmann 55405fb40b lapdm: Make lapdm_datalink_for_sapi public
This API allows you to get the lapdm_datalink for a SAPI. It's needed in
the lapdm_test, so make it public.
2014-03-26 13:52:27 +01:00
Holger Hans Peter Freyther 1512ea6452 lapd: Improve log message and mention the SAPI the dl is on
When debugging an issue that involves SAPI=0 and SAPI=3 the
log file does not have enough context. Add the SAPI to this
message so we at least understand which SAPI we are talking
about.
2014-03-16 23:59:58 +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 baa225ed86 msgb: Add msgb_hexdump() function
This function works like osmo_hexdump() and returns a static buffer
containing hex bytes along with markers for the layers.

Note that it uses osmo_hexdump() internally, thus a call to
msgb_hexdump() invalidates the buffer that has been returned by an
earlier call to osmo_hexdump(). In short: don't mix them in a single
call printf().

Sponsored-by: On-Waves ehf
2014-03-04 13:30:12 +01:00
Holger Hans Peter Freyther 10f0bdecad lapd: Use the right struct for the talloc_zero_array call
I saw this while playing with talloc pools and wondered why
lapd_core is creating a log_info. Use the right struct for
the array.
2014-02-09 20:05:17 +01:00
Holger Hans Peter Freyther f4f5a8489c sms: The msg_ref is passed from the outside so remove the wrong fixme 2014-02-08 15:15:40 +01:00
Holger Hans Peter Freyther c620604dfc lapdm: Fix typo in the comment 2014-01-23 15:00:55 +01:00
Jacob Erlbeck 85bc549ea5 gsm/gsm48ie: Fix range 256 W[i] decoding
Currently w[14]/w[15] and w[18]/w[19] are swapped in range 256 format
decoding in gsm48_decode_freq_list().

This patch fixes this.

Sponsored-by: On-Waves ehf
2014-01-13 15:15:11 +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
Holger Hans Peter Freyther d4d87c5427 abis: Use the right return value for abis_nm_pchan4chcomb
abis_nm_pchan4chcomb will return a pchan for a given channel
combination but returned a value of the channel combination.

Fix it to return the physical channel combination.

Fixes: Coverity CID 1040767
2014-01-02 14:10:25 +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 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
Holger Hans Peter Freyther 56cc60dc20 gb: Remove comment about ABI changes from the Makefile
Okay. this comment thing has not worked (I totally forgot about it).
I think either we try to find ABI breakages with tools or we use
 #error macros and check for a version...
2013-11-22 16:05:26 +01:00
Jacob Erlbeck 9b591b7da8 gprs: Fix VTY NSVC initialisation bug by changing gprs_nsvc_create()
Currently the field nsvci_is_valid is set to 0 in the NSVC object
returned by gprs_nsvc_create(). This was a semantic change probably
introduced by commit 5e6d679d. As a result, NSVC created via the VTY
have this flag set to 0 causing RESET_ACK messages to be rejected.

This patch changes the default behaviour of gprs_nsvc_create() to
always set this flag. So it must be set to 0 explicitely if needed
which is more intuitive and thus less error prone.

It fixes breaking connections from the Gbproxy to the SGSN.

Ticket: OW#874
Sponsored-by: On-Waves ehf
2013-11-11 13:04:17 +01:00
Kevin Redon be355cd78a implement COMP128 version 2 and 3 A3/A8 algorithm
simple copy into C from reversed code from www.hackingprojects.net
2013-11-03 15:05:25 +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
Holger Hans Peter Freyther 9e1cd5a5a5 gprs: Address coverity warning for gprs_ns_tx_status result
Add a #define for the check and use this in this path as well.

Fixes: Coverity CID 1103092
2013-10-25 11:11:51 +02:00
Holger Hans Peter Freyther 726e2729fa gprs: Address coverity warning on unchecked return of gprs_ns_tx_reset_ack
Fixes: Coverity CID 1111545
2013-10-25 11:05:10 +02:00
Holger Hans Peter Freyther 7c91bfdd4e gprs: Address coverity warning on unchecked return of gprs_ns_tx_status
We could consider creating a CHECK MACRO that will print a message
in case of a tx failure.

Fixes: Coverity CID 1111544
2013-10-25 11:02:51 +02:00
Holger Hans Peter Freyther 0cccf40860 gprs: Make sure that the buf is NULL terminated at the end
Fixes: Coverity CID 1107253
2013-10-25 11:00:23 +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 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 35fe87c686 gb/vty: Fix the VTY node string for L_NS_NODE
Use 'config-ns' instead of plain 'ns' and append a blank after the
'#' to make the vty python test script work.

Sponsored-by: On-Waves ehf
2013-10-24 10:01:18 +02:00
Jacob Erlbeck 687b690876 gb/vty: Perform NS-VC operations based on NS-VCI
This adds a 'nsvc nsvci <0-65535> (block|unblock|reset)' vty
command. It selects the NS-VC based on the nsvci instead of using the
first with a matching NSEI, like it is done when the 'nsei' keyword
is used instead.

Sponsored-by: On-Waves ehf
2013-10-24 10:00:42 +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
Holger Hans Peter Freyther f41e5e6c5d release: Prepare the 0.6.4 release of libosmocore
New interfaces and ABI incompatible changes in the GB library
2013-10-15 13:22:15 +02:00
Alexander Huemer 16ae51eb19 ussd: Fix text of RELEASE COMPLETE
Before the assigned value (0xFF) was truncated, reg->text[0] is of
type char. A corresponding test for the same value in openbsc could
only fail.
2013-10-15 11:50:34 +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 6901715124 gb: When sending on a NS-VC group use the first active NS-VC
Currently this first NS-VC with a matching NSEI is always used to
send a UNITDATA message via gprs_ns_sendmsg(). If the NS-VC found is
either dead or blocked, an error is returned.

This patch changes to code to skip blocked or dead NS-VCs while
searching and return the error if no usable NS-VC is found. This
makes it possible to have several NS-VCs per connection group.

Sponsored-by: On-Waves ehf
2013-10-14 13:35:43 +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 84cdc70e0b gb: Separate nsvc creation from NS message processing
This patch refactors gprs_ns_rcvmsg() by moving the parts relevant to
the NS messages into the new functions gprs_ns_vc_create() (nsvc
object creation) and gprs_ns_process_msg() (main NS automaton). These
do not contain code that directly depends on the link layer (they
call other functions that still do). This reduces the gprs_ns_rcvmsg()
function to calling these two functions and optionally setting up the
link layer specific fields of the nsvc.

Sponsored-by: On-Waves ehf
2013-10-08 14:50:46 +02:00
Jacob Erlbeck 1c3f088c1f gsm48: Added 'Network Daylight Saving Time' info element
This information element has been added to the MM Information
message in GSM24.008. This patch adds it to the tlv_definition
to keep the TLV parser from breaking.

Ticket: OW#978
2013-09-16 14:11:36 +02:00
Jacob Erlbeck b3657e1216 vty: Allow vty_go_parent() in all nodes.
This patch removes an assertion of node > CONFIG_NODE and changes
the function to handle all nodes properly.
For the sake of completeness, the generic 'exit' command
implementation is extended to work properly with all nodes, too.
2013-09-11 09:36:45 +02:00
Jacob Erlbeck 2349721d80 vty: Replace 'enum node_type' by 'int' for last_node
In this case the last_node variable may hold values that are not
in enum node_type, so int is used instead.
2013-09-10 11:04:00 +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
Jacob Erlbeck 7eed0538ae vty: Refactored vty_go_parent(), 'end' and 'exit'
Put all 'exit' logic into vty_go_parent() and replace the
implementations of 'exit' and 'end' by generic ones that use
vty_go_parent().
2013-09-08 10:49:03 +02:00
Jacob Erlbeck 2442e09658 vty: Rename is_config() to is_config_child()
The function is_config() returns 0 for CONFIG_NODE. Since that node
is a config node, the function is renamed to resolve this.
2013-09-08 10:33:24 +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 1810925dfb sms: Added comment about the gsm_7bit_alphabet table
The table structure is not intuitive, so this comment shall aid to
understand this.
2013-08-12 17:22:27 +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
Holger Hans Peter Freyther 9b037a6a7a lapd: Remove the double NULL check idiom with msgb_free
if (ptr)
  msgb_free(ptr)

extends to:

if (ptr)
  talloc_free(ptr)

And according to the talloc documentation a talloc_free(NULL)
will not crash: "... Likewise, if "ptr" is NULL, then the function
will make no modifications and returns -1."
2013-08-09 17:48:24 +02:00
Holger Hans Peter Freyther f136013f0d gsm: The LAPDm prim/structs changed, increment current version 2013-08-09 17:41:34 +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
Holger Hans Peter Freyther 6a75d16c6d vty: Fix logically dead code in the description handling
The code most likely wanted to check the result of argv_concat.
To do this we need to dereference the dptr.

Logically dead code (DEADCODE)
dead_error_line: Execution cannot reach this statement "return 1;

Fixes: Coverity CID 1040675
2013-07-14 09:14:37 +02:00
Dmitri Soloviev 2909942a9f gsm0808.c: Add TLV definition for LAYER3_HEADER_INFORMATION
This is required for osmo-bsc to parse Alcatel S-12 CIPHER MODE COMMAND
in osmo-bsc.
2013-07-11 09:25:37 +02:00
Andreas Eversberg cad54b8fb7 LAPD: Free resume/re-establishment msgb if it carries no content
lapdm.c takes the re-establishment message and forwards it to lapd_core.c,
so we can assume that msgb is set at primitive. In case there is data in
the re-establishment msg, it is moved into send_buffer. In case of no
data (0 length), it must be freed.

Fixes an issue spotted by Coverity Scan.
2013-07-10 20:30:56 +02:00
Holger Hans Peter Freyther 47aa482bb0 gsm: Revert the gsm_7bit_encode changes as they are wrong
This reverts commit f996b05dbd
and 2b0cac4ef8. A detailed
explanation can be found here:

  http://lists.osmocom.org/pipermail/openbsc/2013-July/004737.html

The short description is that:

1.) The API should return (as out parameter) the number of
    octets used.
2.) The handling for the <CR> encoding only applies to USSD
    and it is incomplete. On top of that it broke the SMS test.
2013-07-07 13:59:16 +02:00
Andreas Eversberg 2b0cac4ef8 Fix: Handle returned length by gsm_7bit_encode correctly 2013-07-06 23:36:16 +02:00
Andreas Eversberg f996b05dbd Fix encoding of last character at 7bit encoding function
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.
2013-07-06 23:36:16 +02:00
Holger Hans Peter Freyther c62a1bf4d5 libosmogb: Add function to close NS instance without destroying it 2013-07-06 23:36:16 +02:00
Andreas Eversberg 5977db0faf LAPDm: Allow sending unit data on DCCH
It is used to transfer PHYSICAL INFORMATION message to the MS.
2013-07-06 23:36:16 +02:00
Andreas Eversberg ccc463355d LAPDm: Fix re-establishment of datalink
If the datalink fails or if handover or assignment to a new channel fails,
it is re-establised by sending SABM again. The length of establish message
is 0 in this case. The length is used to differentiate between
re-establishment and contention resolution, which has to be handled
differently.

See TS 04.06 Chapter 5.4.2.1
2013-07-06 23:36:15 +02:00
Holger Hans Peter Freyther 8d50600d7d get_value_string: Null terminate after the call to snprintf
It is impossible that the snprintf will fill the entire namebuf
but just follow the idiom to make sure it is null terminated.

Related: Coverity CID 1040676
2013-07-04 20:14:10 +02:00
Holger Hans Peter Freyther 047213b01e vty: Attempt to fix various meam leaks in the VTY lookup code
These routines were not freeing vectors used for the lookup. On
review it is fixing another path not detected by coverity.

The danger is a double free in tab completion now. It is difficult
to test this.

Fixes: Coverity CID 23037, CID 23038
2013-07-03 10:00:06 +02:00
Holger Hans Peter Freyther cd252e3565 gsm0408: Avoid unaligned memory access in gsm48_generate_mid_from_tmsi
The &buf[3] is unlikely to be aligned properly. Use memcpy instead
of an assignment. Add a small testcase that verifies that I didn't
mess up the conversion.

Alignment trap: osmo-nitb (3293) PC=0x492b7094 Instr=0xe5803003 Address=0xbeb259db FSR 0x801
2013-07-03 10:00:06 +02:00
Holger Hans Peter Freyther 476cf3337d strrb: Remove a tautology from the code
This already came up during review but now that Coverity complains
about it as well, let us just remove it. The variable is unsigned
so it can never be < 0.

Fixes: Coverity CID 1040669.
2013-07-03 09:30:02 +02:00
Harald Welte 27b2bb7e92 BSSGP: prevent divide-by-zero in flow control
If the BTS tells us to not send any data at all anymore (bucket leak
rate of 0 bits per second), then we should respect this and not run into
a divide-by-zero.  However, as this indicates complete overload, we
print a log message to that regard.
2013-06-29 10:53:33 +02:00
Harald Welte a62fe31d69 introduce gsm0808_create_reset_ack() 2013-06-29 10:53:33 +02:00
Harald Welte 087116aca7 lapd_core: msgb_trim() the L2 padding from ESTABLISH.ind
When a SABM(E) frame arrives, we have to trim the L2 padding (0x2b for
gsm) before handing the data off to L3, just like we do with I frames.

Also, we should use mggb_trim() or even msgb_l3trim() instead of
manually fiddling with msgb->length and ->tail pointers.
2013-06-18 21:41:34 +02:00
Holger Hans Peter Freyther 9ac453759c misc: Fix the spelling of frame in the RLM cause strings 2013-06-11 17:55:55 +02:00
Bhaskar 6b30f925e2 gsm_utils: refer to ETSI TS 05.08 instead of TS 08.05 2013-05-23 07:53:57 +02:00
Holger Hans Peter Freyther f5a079f739 lapd: Set the tx_hist to NULL after freeing it
Make detecting use after free of the tx_hist easy and set the
variable to NULL after talloc_free has been freed.
2013-05-08 18:46:55 +02:00
Andreas Eversberg b36ad2debe Fix of potential memory leaks at lapdm.c 2013-04-06 23:24:10 +02:00
Andreas Eversberg 6e182087f4 Fix: LAPDm contention resoltion must acknowledge subsequent SABM
After reception of SABM, the network responds with UA and enters the
establised multiframe state. If UA is not received by mobile, the SABM
is transmitted again, and the network must respond with UA again, unless
it is from a different mobile.

Add LAPDm collision test (contention resolution on network side).
2013-04-06 23:23:52 +02:00
Holger Hans Peter Freyther 2c3393d9e3 gprs_ns: Allow to set the DSCP for the UDP socket.
Allow to tag the NS service with a custom DSCP.
2013-03-25 12:06:36 +01:00
Harald Welte 1a02cfc24d logging_vty: Fix segfault un unused entries in log_info_cat array of app 2013-03-19 10:37:39 +01:00
Harald Welte 54c5ed1518 Revert "Follow up fix for the log level "everything""
This reverts commit a6428d2376.
2013-03-19 09:55:42 +01:00
Harald Welte 9b1867093f Revert "Fix log level "everything" and make it equal to "debug""
This reverts commit cd6ed82d1f.
2013-03-19 09:55:28 +01:00
Harald Welte 8e878738d1 application: don't ignore SIGHUP but do config file reopen. 2013-03-18 19:06:13 +01:00
Harald Welte 4de854dcf0 logging: add new log_targets_reopen() function
This function will re-open all existing log files in the application,
praticularly useful for SIGHUP handlers in case of logrotate
2013-03-18 19:05:46 +01:00
Harald Welte ca69388be8 gsm_septets2octets(): Input parameter should be const 2013-03-13 15:16:47 +01:00
Harald Welte 6d2d4d688e logging_vty: Print 'log filter all' info in 'show logging vty'
When we print information about the current logging configuration,
it makes sense to also print information about the log filters.
2013-03-13 15:16:47 +01:00
Holger Hans Peter Freyther 45cdaa095a cygwin: Link many libraries with -no-undefined to create a dll
Only the Gb library relies on having undefined references to a
symbol that needs to be provided by the host application. For
all other libraries we can link with -no-undefined.
2013-03-03 10:10:07 +01:00
Sylvain Munaut ed8170ac67 codec: Fix the GSM 06.20 ordering tables
Seems the script I used to parse those had a bug where range of
bits in the 'decreasing' direction ( like 6..0 ) were not processed
properly.

Thanks to Andreas for noticing this !

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2013-03-01 16:35:46 +01:00
Holger Hans Peter Freyther a6428d2376 Follow up fix for the log level "everything"
Commit cd6ed82d1f made "EVERYTHING"
map to LOGL_DEBUG but when writing out the configuration the following
would be written:

  logging level all unknown 0x0

This happend because no string was found for the value 0. Address it
by adding a legacy check for 0 and write out the str from the index
0. Currently this is "EVERYTHING".
2013-02-27 15:32:51 +01:00
Katerina Barone-Adesi 3309a43ef5 Added a ring buffer log target to store the last N log messages.
The log target can be used via log alarms and show alarms.
Why? This feature was proposed/requested at
http://openbsc.osmocom.org/trac/wiki/Tasks/ErrorLogTarget
All messages use the same amount of space, prioritizing simplicity.
2013-02-27 15:13:45 +01:00
Holger Hans Peter Freyther efd2bd691f Revert "Added a ring buffer log target to store the last N log messages."
I noticed some more issues and it is the easiest to revert and include
the fixed version.

This reverts commit 73377229bb.
2013-02-27 14:51:33 +01:00
Katerina Barone-Adesi 73377229bb Added a ring buffer log target to store the last N log messages.
The log target can be used via log alarms and show alarms.
Why? This feature was proposed/requested at
http://openbsc.osmocom.org/trac/wiki/Tasks/ErrorLogTarget
All messages use the same amount of space, prioritizing simplicity.
2013-02-27 14:45:48 +01:00
Harald Welte cd6ed82d1f Fix log level "everything" and make it equal to "debug"
As Holger points out "logging level XXX everything" wasn't working, as
it sets category->loglevel to 0, which is checked in osmo_vlogp() and
will never get logged.
2013-02-19 11:57:14 +01:00
Katerina Barone-Adesi c28c6a02d2 misc: Doxygen tweaks: fixed some typos and minor errors
Doxygen generates quite a lot of warnings on libosmocore. Some of them
are obvious typos - this patch aims to fix such low-hanging fruit.
2013-02-15 13:27:59 +01:00
Harald Welte d17aa59c3e VTY: don't show HIDDEN or DEPRECATED vty commands in ? completion
This hides HIDDEN or DEPRECATED commands from showing up when the
full list of commands is inquired with '?' at any given point in the
command tree.  Only if the hidden/deprecated command is already typed
in partially, then it will still tab-complete.
2013-02-12 11:11:34 +01:00
Harald Welte 80d30fe803 vty/command.c: Cosmetic cleanup
this is just changing some of the code to reduce the way too high level
of indentation and thus improve readability.
2013-02-12 11:08:57 +01:00
Harald Welte 868a5c4782 turn abis_nm_debugp_foh() into a macro
this will avoid printing 'abis_nm.c' as the filename in the log, which
is pretty useless during debugging.  We want to know where
abis_nm_debugp_foh() is being used from, not where it is implemented.
2013-02-10 09:30:28 +01:00
Sylvain Munaut 9adfda2ca3 core/crc: Fix the 64 bits implementation
We used 1ULL at one place and not the other ... at the same time,
we now use (uintXX_t) so that the proper type is used each time.

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2013-02-01 20:37:03 +01:00
Pablo Neira Ayuso e04a14d9a2 socket: fix osmo_sock_init with SOCK_RAW and IPPROTO_RAW
getaddrinfo returns EAI_SERVICE (-8) if that combination is used.

More information available in here:

http://sourceware.org/bugzilla/show_bug.cgi?id=15015

Reported by Holger Hans Peter Freyther.

While at it, this patch also removes hints.ai_flags = 0 as memset
to zero already happened just a bit before that.
2013-01-15 20:06:39 +01:00
Evgeny Zverev 06ddf8bd24 Fix build on Cygwin 2013-01-12 15:10:58 +01:00
Harald Welte de6e4983e7 add some missing doxygen annotation for libosmocore functions 2013-01-11 09:43:32 +01:00
Sylvain Munaut 4d8eea48f2 vty: Do better filtering of arguments, optional args particularly
This is essentially http://patchwork.diac24.net/patch/271/ forward
ported to libosmovty

Original-by: Paul Jakma <paul@quagga.net>
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2013-01-03 22:34:26 +01:00
Sylvain Munaut 01e0604637 core/bits: Prevent osmo_revbytebits_buf stack trashing
The second loop in osmo_revbytebits_buf() in src/bits.c grabs
4 bytes each iteration, which can easily go past the supplied
input in some cases.

Compiled with -fstack-protector , I get a "stack smashing detected"
in the bits test.

From: Nils O. Selåsdal <noselasd@fiane.dyndns.org>
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2013-01-03 09:37:16 +01:00
Daniel Willmann e523392c2c lapd: Check in rslms_rx_rll() if lapdm context was initialized earlier
This was found while implementing handover on a sysmobts. When we
receive a channel release request for a channel that was never really
activated (set_lapdm_context() was not called) we segfault in
lapd_recv_dlsap().

We now return early with -EINVAL in rslms_rx_rll() if we receive a
message that assumes set_lapdm_context() was already called.

These are:
* RSL_MT_UNIT_DATA_REQ
* RSL_MT_DATA_REQ
* RSL_MT_SUSP_REQ
* RSL_MT_REL_REQ

A test case was added to trigger the issue.
2012-12-26 10:48:01 +01:00