Commit Graph

2684 Commits

Author SHA1 Message Date
Vadim Yanitskiy 0f2b894580 trxcon/sched_prim.c: properly handle both TCH/H and FACCH/H prims
Initially it was assumed that FACCH prioritization should be done
in the same way for both TCH/F and TCH/H. Moreover, it was not
possible to confirm this, because TCH/H was (and still) not
implemented yet. But according to the specs:

  - unlike FACCH/F, FACCH/H transmissions shall be aligned
    within a multiframe, i.e. can only be initiated on
    particular frame numbers (see GSM 05.02, clause 7);

  - unlike FACCH/F, a FACCH/H frame steals two TCH/F frames;

so the TCH/H (including FACCH/H) primitives should be handled
separately from the TCH/F (including FACCH/F) primitives.

Change-Id: I9b59f60e1cbac8fb8fd557b6c67b5e376c0a6bbb
2018-08-14 06:22:04 +07:00
Vadim Yanitskiy 799f26c075 trxcon/sched_prim.c: refactor prim dequeuing logic
The previous primitive dequeuing logic (especially for TCH/F
channels) was a bit complicated, and it could not be possible
to reuse the existing code parts in the upcoming implementation
of both TCH/H and FACCH/H channels without changing anything.

In particular, this change introduces two internal functions:

  - prim_dequeue_one(), which merely dequeues a primitive
    of a given channel type (e.g. TRXC_SDCCH4_0);

  - prim_dequeue_tch(), which dequeues either a FACCH,
    or a speech TCH primitive of a given channel
    type (Lm or Bm).

So the logic of the TCH/F prim dequeuing function has become
cleaner, and the upcoming TCH/H prim dequeuing function, where
FACCH/H prioritization is more complex than FACCH/F, will
reuse the introduced functions.

Change-Id: Ib82ad2480ab1bc6b1df9576eb2bf5acbd398bf66
2018-08-14 05:46:59 +07:00
Vadim Yanitskiy 8ae0c13fa9 trxcon/sched_trx.h: add missing parentheses to PRIM_IS_*
Change-Id: Ifa7d9f806b3f18f2dfec931252f5119441b30e8a
2018-08-14 05:00:00 +07:00
Harald Welte d4fb4fdea0 layer23: Replace all instances of strncpy() by osmo_strlcpy
This gives us working/safe zero termination without overflowing
the destination string size.

Change-Id: Ica6098ceba2bd01ce3b216085442cc5eed0ca507
2018-08-11 16:10:31 +02:00
Harald Welte 1d68468636 layer23: Fix possible buffer overflow writing NUL beyond end of string
settings.c: In function ‘gsm_random_imei’:
settings.c:188:26: warning: ‘sprintf’ may write a terminating nul past the end of the destination [-Wformat-overflow=]
  sprintf(rand + 8, "%07ld", random() % 10000000);
                          ^
settings.c:188:2: note: ‘sprintf’ output between 8 and 9 bytes into a destination of size 8
  sprintf(rand + 8, "%07ld", random() % 10000000);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Change-Id: Id949487111235cd4af5ff068f1dce2f4b0801480
2018-08-11 14:09:14 +00:00
Harald Welte d68833cd85 layer23: Use osmo_strlcpy() to avoid non-terminated strings
settings.c:191:2: warning: ‘strncpy’ output may be truncated copying 15 bytes from a string of length 15 -Wstringop-truncation]
  strncpy(set->imeisv, set->imei, 15);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  CC       subscriber.o
  CC       support.o
  CC       transaction.o
  CC       vty_interface.o
  CC       voice.o
  CC       mncc_sock.o
  CC       primitives.o
mncc_sock.c: In function ‘osmo_unixsock_listen’:
mncc_sock.c:318:2: warning: ‘strncpy’ specified bound 108 equals destination size [-Wstringop-truncation]
  strncpy(local.sun_path, path, sizeof(local.sun_path));
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  CC       script_lua.o
vty_interface.c: In function ‘cfg_gps_device’:
vty_interface.c:1144:2: warning: ‘strncpy’ specified bound 32 equals destination size [-Wstringop-truncation]
  strncpy(g.device, argv[0], sizeof(g.device));
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  AR       libmobile.a

Change-Id: Id52978f3bf7a8abea62237d7c32f8f87e1bb34a1
2018-08-11 12:59:30 +00:00
Harald Welte 2725309446 layer23: Fix compiler warnings about string operation truncation
This fixes the below warnings:

gsm322.c: In function ‘gsm322_cs_ba_range’:
gsm322.c:3480:3: warning: ‘strncpy’ specified bound 10 equals destination size [-Wstringop-truncation]
   strncpy(lower_text,  gsm_print_arfcn(index2arfcn(lower)),  ARFCN_TEXT_LEN);
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
gsm322.c:3480:3: warning: ‘strncpy’ specified bound 10 equals destination size [-Wstringop-truncation]
gsm322.c:3480:3: warning: ‘strncpy’ specified bound 10 equals destination size [-Wstringop-truncation]
gsm322.c:3480:3: warning: ‘strncpy’ specified bound 10 equals destination size [-Wstringop-truncation]
gsm322.c:3481:3: warning: ‘strncpy’ specified bound 10 equals destination size [-Wstringop-truncation]
   strncpy(higher_text, gsm_print_arfcn(index2arfcn(higher)), ARFCN_TEXT_LEN);
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
gsm322.c: In function ‘gsm322_cs_powerscan’:
gsm322.c:2862:2: warning: ‘strncpy’ specified bound 10 equals destination size [-Wstringop-truncation]
  strncpy(s_text, gsm_print_arfcn(index2arfcn(s)), ARFCN_TEXT_LEN);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
gsm322.c:2863:2: warning: ‘strncpy’ specified bound 10 equals destination size [-Wstringop-truncation]
  strncpy(e_text, gsm_print_arfcn(index2arfcn(e)), ARFCN_TEXT_LEN);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Change-Id: I08f938cfb2589574e90d5831a00c0140f71d5bfe
2018-08-11 12:59:30 +00:00
Harald Welte c3ce47deae layer23: Fix compiler warning about snprintf buffer too small
gsm322.c:366:22: warning: ‘sprintf’ may write a terminating nul past the end of the destination [-Wformat-overflow=]
  sprintf(string, "-%d", 110 - rxlev);
                      ^
gsm322.c:366:2: note: ‘sprintf’ output between 3 and 6 bytes into a destination of size 5
  sprintf(string, "-%d", 110 - rxlev);

Change-Id: I7b19fef89ba0cb0c1edbdd62c46ad8395e44145b
2018-08-11 12:59:30 +00:00
Harald Welte 82d8370f62 layer23: fix unaligned store in osmo_send_l1()
This fixes the following alignment issue uncovered by asan:

l1l2_interface.c:169:7: runtime error: store to misaligned address 0x61600001ab99 for type 'uint16_t', which requires 2 byte alignment
0x61600001ab99: note: pointer points here
 00 00 00  00 00 00 06 0a 01 19 19  40 18 00 07 00 01 03 49  06 15 00 40 01 c0 00 00  00 00 00 00 00
              ^

Change-Id: Ie65b428107d35bac99bc870fdbc4dc509ca2f33c
2018-08-11 12:59:30 +00:00
Harald Welte 4d07f40b94 layer23: Add --enable-sanitize and --enable-werror configure flags
We use this in the network-side Osmocom projects (CNI) and it's
useful to have the same flags also for the OsmocomBB host software.

Change-Id: I45800c937d665fdbd2dd6b0cee38408f587f1a9f
2018-08-11 12:59:30 +00:00
Vadim Yanitskiy a50d3fff72 trx_toolkit/fake_trx: introduce basic path loss simulation
This change introduces a couple of new CTRL commands for path loss
simulation, in particular a possibility to drop some amount of
bursts according to some TDMA frame period, separately for both
Uplink and Downlink directions.

Examples:

  FAKE_DROP 4 - drop 4 consistent (period=1) bursts,
  FAKE_DROP 16 2 - drop 16 even bursts (period=2).

Change-Id: Ib210138a03e2377c79875a4ff2f2bb58a43cfa46
Related: OS#3428
2018-08-02 05:30:49 +07:00
Vadim Yanitskiy b914cfd488 trx_toolkit/burst_fwd.py: separate burst preprocessing
This change separates burst preprocessing (i.e. both RSSI and ToA
calculation) from BurstForwarder.transform_msg() because it's not
actually related to the message transformation process.

Change-Id: Ia7ad970593f38d9a9401975eb6dae67cd0c94e11
2018-08-02 03:50:57 +07:00
Vadim Yanitskiy 488f92d8b8 trxcon: make both Valgrind and trxcon happy
Change-Id: If5c349082757bb30408477b1ef528934eded0232
2018-07-28 02:22:29 +07:00
Vadim Yanitskiy 8f6909a94f trxcon/scheduler: fix: check primitive len before encoding
We used to trust (and still doing this) the messages coming from
L1CTL interface too much, and not to check the primitive length
before passing the payload to the libosmocoding API. As was
discovered and described in OS#3415, sending a L1CTL message
(either DATA_REQ, or TRAFFIC_REQ) with an incorrect length
(lower than expected) may cause heap overflow.

Let's explicitly check a primitive before encoding, and drop it
if its length doesn't match the expected value(s).

Change-Id: I258ee9f6d0124b183b1db23a73f1e523fcea89a8
Fixes: OS#3415
2018-07-24 22:24:13 +07:00
Holger Hans Peter Freyther 812866daab Move from libc random() to osmo_get_rand_id (2nd attempt)
When starting multiple mobile in the same second, the libc random number
generator will be seeded to exactly the same value.

The random bits inside the RACH request(s) will be exactly the same
across multiple mobile and when the channel fails they all pick the same
randomized back-off timing.

Use stronger random numbers and replace all calls to random(2) with
osmo_get_rand_id. Add a fallback to try random().

[v2: Add helper to make sure the result is int and between 0 and
RAND_MAX]

Change-Id: Icdd4be88c62bba1e9d954568e48f0c12a67ac182
2018-07-23 20:55:45 +01:00
Vadim Yanitskiy fd33dcc202 trx_toolkit/trx_sniff.py: fix memleak: don't store packets
The Scapy itself was the actual cause of continuously growing
memory consumption. It was configured to store the captured
packets, what isn't required for this tool.

Change-Id: I0c6d9b76398e148b7febd94aa37aa2fa22d19b3f
2018-07-21 00:14:58 +07:00
Vadim Yanitskiy d3394d13f2 mobile: use osmo_init_logging2 with proper talloc context
Change-Id: I231ac9987ff3c13fafcd272b7d9aae3938ab5972
2018-07-17 05:14:56 +07:00
Vadim Yanitskiy a0eef8d2e8 Revert "Move from libc random() to osmo_get_rand_id"
It was decided to migrate to osmo_get_rand_id() and use random()
as a fall-back. But there is a critical difference between both
functions: osmo_get_rand_id() fills an input buffer with random
bytes (0x00 - 0xff), while *random() returns a value in range
between 0 and RAND_MAX.

osmo_get_rand_id() was used in a wrong way, so in some cases we
could get a negative value (how about IMEI starting from '-'?),
what isn't expected in many cases and could lead to unexpected
behaviour and segmentation faults...

This reverts commit 6d49b049ee.

Change-Id: I7b2a8a5c63cf64360a824926a2219fd7e419b1bb
2018-07-17 05:09:58 +07:00
Piotr Krysik 70a50a33cc trxcon: fix tail bits at the front of Access burst
Currently Access Burst generated by trxcon
has 8 zero bits at the beginning. According to
the 3GPP 05.02 specification (Chapter 5.2.7
Access burst) custom 8-bit extended tail bits
sequence should be used:
(BN0, BN1, BN2 ... BN7) = (0,0,1,1,1,0,1,0)

After this fix trxcon sets correct 8-bit
sequence at the front of Access burst.

Change-Id: I1f624e783de6c585d2e292965c9e5810b0a4f27d
2018-07-16 09:11:26 +02:00
Holger Hans Peter Freyther 6d49b049ee Move from libc random() to osmo_get_rand_id
When starting multiple mobile in the same second, the libc random number
generator will be seeded to exactly the same value.

The random bits inside the RACH request(s) will be exactly the same
across multiple mobile and when the channel fails they all pick the same
randomized back-off timing.

Use stronger random numbers and replace all calls to random(2) with
osmo_get_rand_id. Add a fallback to try random().

Change-Id: Ie0cc64663cd4b90c027b79545dc5d3ac9d87b9dd
2018-07-11 21:13:11 +00:00
Pau Espin c36dc29632 calypso: Print warning about unsupported encryption algorithms
Unfortunately current code architecture doesn't support a return path
with an error so tell the caller of L1CTL on the other side that
something's wrong.

Change-Id: Ib9b622dd5c9770c5e97fa58deee124a409544d3b
2018-07-06 19:11:00 +02:00
Holger Hans Peter Freyther ce772ce338 lua: Add API to enable passing credentials
This can be useful to have bidirectional communication between the
mobile lua script an external control script.

Change-Id: Ib4a5eef611f524f5d21cb6a7f4eace22b8ba60d0
2018-06-17 19:22:57 +01:00
Pau Espin ac37f55b1c osmoload: Set compiler attr to unused function
Function is not removed as documentation of the load process
capabilities.

Change-Id: I8e838cbb5ae7c9a2f4d0e249fc14f7cbcbc2cb07
2018-06-13 13:48:17 +02:00
Pau Espin f5481937a7 osmocon: Set compiler attr to unused variables
Variables are not removed as they document the commands of the
propietary romloader.

Let's mark them as unused to avoid compilation warnings.

Change-Id: If4c6814ada85956975e687eb43dcfd4ad70b8b94
2018-06-13 13:42:52 +02:00
Pau Espin 40d9d853e8 osmocon: Fix printf format
Fixes compilation warning:
osmocon.c:650:21: warning: format ‘%u’ expects argument of type ‘unsigned int’, but argument 3 has type ‘long int’ [-Wformat=]
  printf("%u bytes (%u/%u)\n", rc, dnload.write_ptr - dnload.data,
                    ~^             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                    %lu

Change-Id: I1e9e10e756d8a612425ee71f4ac0139b2293d3bb
2018-06-12 17:10:14 +02:00
Pau Espin 9941ebd519 osmoload: Remove duplicate const keyword
Fixes compilation warning:
warning: duplicate ‘const’ declaration specifier [-Wduplicate-decl-specifier]
  const uint8_t const *endptr = bufptr + len;
                ^~~~~

Change-Id: Ibafa439c9d7f7aab6d417eca5ff045766ac27b4f
2018-06-12 16:59:44 +02:00
Pau Espin 5c576686e2 osmocon: Call osmo_init_ignore_signals at startup
It disables undesirable signals such as SIGPIPE, which exits the program
if the client connected to osmocon closes the connection and osmocon
writes to the connection fd. After SIGPIPE is disabled, write returns
-EPIPE.

This is required to keep osmocon running for BTS_Tests.ttcn TTCN3 tests.

Change-Id: Id664ca0fadd3a8b3cf4b78bb868b3d78d2354544
2018-06-12 16:54:10 +02:00
Steve Markgraf e9e757f8f3 trf6151: Actually fix setting of uplink ARFCN
Some time ago a broken fix was committed which
then has been reverted again in commit
1724003737.

The purpose of this line is to clear the uplink
flag from the ARFCN. So far this worked because
both gsm_arfcn2band() and gsm_arfcn2freq10()
already do this internally.

Change-Id: Ie8a05ffc0ddec53d7fd6a25e03ea285fb216df29
Signed-off-by: Steve Markgraf <steve@steve-m.de>
2018-06-08 23:58:29 +02:00
Holger Hans Peter Freyther fcb420d50b mobile/sms: Make it optional to store the SMS on disk
Disable storing the SMS on disk. This is useful when scripting mobile.
Keep the default of attempting to store it to disk.

Change-Id: I6353447343d98ebaa5e12ab63f995750f81c8500
2018-06-04 06:50:25 +02:00
Holger Hans Peter Freyther a81c83fc2c mobile/sms: Simplify the string format routines
It seems the original code didn't allocate \0 for the string. Just use
talloc_asprintf and get a new string...

Change-Id: I8ffb50b04d2d6196caf0231711f3467abc8c5ea5
2018-06-02 11:14:51 +08:00
Holger Hans Peter Freyther 61fe379446 mobile/sms: Fix memory leak in case the storage can not be opened
Before jumping to the failure handling code free the sms_file.

Change-Id: Ifce2bc130fe3a5bd49ad457ee61002952dd496ba
2018-06-02 11:12:50 +08:00
Holger Hans Peter Freyther 5a3dd6eb1a mobile: Make time spent in c7 configurable
When no cell was found during the PLMN search the camp on any cell
state will be entered. LUs are prevented in this state and it will be
left after the start_any_timer has timedout. Even if camping on the
home network the state will not be left before the expiry of the timer.

For systematic tests this is producing a too high upper bound. Make it
configurable so we can succeed with a UL more quickly.

Change-Id: I25bc985cd4360d5e37d05a7b16b39eefb75ce20f
2018-06-01 23:32:23 +08:00
Pau Espin 9533aa7002 osmocon: Makefile.am: Fix build using different path
Change-Id: I1a322e364612976f3d797f25e57ccc7c2354bd5e
2018-05-22 16:04:06 +02:00
Vadim Yanitskiy c343d730f6 Remove the patches for Wireshark
GSMTAP support is already merged to the mainline, while the status
of SMSCB support is unknown. In any case, OsmocomBB is not a good
place for storing the patches for Wireshark, so let's remove them.

Change-Id: I448dc5a3dba3ecc6fc041861239dc23cca72b70b
2018-05-20 15:54:03 +03:00
Vadim Yanitskiy 7ffc478179 README.development: add brief info about the TRX Toolkit
Change-Id: I589a5e0a1b41439aabc59e97aca378d16f4e4cc5
2018-05-20 15:46:20 +03:00
Vadim Yanitskiy 034b1d4e63 README.development: cosmetic: correct/add wiki links
Change-Id: Ib17196044f276d05269dbdb5a5a1444202fa0e07
2018-05-20 15:42:34 +03:00
Vadim Yanitskiy 78f17e45ec README.building: cosmetic: correct wiki links
Change-Id: I0fd8fdc7aecdf04266898eaadd05f1f0c705bb5c
2018-05-20 15:34:16 +03:00
Vadim Yanitskiy 2d911d7842 include/osmocore: remove unused headers
Both removed headers are not used anywhere, and probably left
from the time when there was no libosmocore as a shared library.

Change-Id: I821e2958e07176c1031c636019dffd1cee62bb10
2018-05-20 15:26:40 +03:00
Vadim Yanitskiy 12b07883e7 VIRT_PHY: add missing L1CTL_BURST_IND to l1ctlPrimNames
Change-Id: I442305c034bbba5eaed080fb262a61895623eb4f
2018-04-15 20:36:03 +07:00
Harald Welte 9abc5f7982 trxcon: Prefix SACCH fill frame with L1 header
The main problem here is that the existing implementatin missing the L1
header in this message.  A SACCH message doesn't have a 23byte LAPDm
message, but only a 21 byte LAPDm message prefixed by a 2-byte Layer1
header. So on the receiver in the BTS, right now the first two bytes of
the UL SACCH frame are misinterpreted as L1 header.

This it what causes RLL ERROR INDICATION on the Abis side, which is why
our BTS_Tests fail.

Change-Id: Id7776bf3604d0e8a32e04547e01b8bd377903272
Related: OS#3170
2018-04-15 11:09:25 +02:00
Vadim Yanitskiy 9803a35a8a host/trxcon: track talloc NULL contexts by default
In order to be able to introspect not only the root application
context, but also all other contexts, e.g. allocated within
libosmocore or other libraries, let's enable tracking the
use of NULL contexts using the corresponding talloc API.

Change-Id: Id21cd5ee340def443f7a5d0b2b8f37f41188dd87
2018-04-09 08:26:23 +00:00
Vadim Yanitskiy 60bf444718 host/trxcon: don't free root talloc context
This is useless, and prevents us from finding potential memory
leaks at exit. Let's print talloc report instead of that.

Change-Id: Ibf04942070d654e97c3ed77d69ab19e44602758c
2018-04-09 08:26:22 +00:00
Vadim Yanitskiy fa0d7c0c4f host/trxcon: use osmo_init_logging2()
The osmo_init_logging() doesn't allow to specify a talloc context
for libosmocore logging subsystem, so this is why the new version
was introduced. Let's use it.

Change-Id: I06c4a1f7f839f774bc428e89cfac30132bae904d
2018-04-09 08:26:20 +00:00
Harald Welte 05d95a46fd Merge 'fixeria/trx' into master
Change-Id: I5586fd8c9eb281285f4a59e63cb17dbc3641e1c1
2018-04-07 19:35:24 +02:00
Pau Espin 00bfb39d6c trxcon/l1ctl.c: hexdump content of unhandled messages
Change-Id: Iec8fc6d49d1e35fe101960dd969de559e37a6a75
2018-04-04 17:14:26 +00:00
Pau Espin 55afe0072b trx_toolkit: Add cmdline arg to set bind addr
Previous hardcoded default of 0.0.0.0 was inappropiate in some
scenarios, as it sets the SRC addr of the packets sent through the
socket based on the routing.

For instance, if iface IF1 has assigned two IP addresses A and B,
A being the first addr of the interface, and osmo-bts-trx is
configured with "osmotrx ip local A" and "osmotrx ip remote B",
the following happens:

  CMD POWER OFF src=A:5801 dst=B:5701
  RSP POWER OFF src=A:5701 dst=A:5701 <-- A is assigned as src addr.

But osmo-bts-trx is waiting for packets from B:5701, and the packet
is dropped with ICMP Unreachable. If addr binding is forced in
fake_trx to B, then everthing's fine.

Let's extend the UDPLink in order to allow manual, but optional
setting of bind address, and add a corresponding cmdline
argument to all executables.

Change-Id: I7be18fef40967fb7551f4115f22cbbd9cdb0840d
2018-04-04 17:14:26 +00:00
Harald Welte 9d90d1907b trxcon: Respect the tch_mode field of DM_EST_REQ
the initial tch_mode is not always 0 (signalling) but can very well
be directly a codec mode, if the initial activation of the channel
is in speech mode as opposed to signalling

Change-Id: I96e4c89da1165e9c5287d863e0e65d811460c606
2018-04-02 19:57:55 +02:00
Vadim Yanitskiy 96a8f288c6 trxcon/scheduler: add CHAN_IS_SACCH macro
Change-Id: I2fc90d4732433f221c628058c9812815edf9c8cb
2018-03-22 23:04:16 +07:00
Vadim Yanitskiy e05f690102 trxcon/scheduler: share lchan link identifiers
Change-Id: Ie1632f274b2ae6147a8e918ebfea60eeeb6a234c
2018-03-22 23:02:25 +07:00
Vadim Yanitskiy 02abbe5420 trxcon/sched_prim.c: fix: correct the first padding byte
According to TS 144.006, section 5.2, the first octet containing
fill bits shall be set to the binary value "00101011" == 0x2b.

Change-Id: I8f0304bf84613a2dc07cb78aff0cb8bb4c5adf6c
2018-03-22 20:54:23 +07:00