Commit Graph

2207 Commits

Author SHA1 Message Date
Vadim Yanitskiy 236dfd506d trxcon/l1ctl.c: print timeslot number from L1CTL_DM_EST_REQ
Change-Id: If092743c32b7a6f5da7c8339b0f7b92ccf8a7a8b
2018-09-06 01:15:26 +07:00
Vadim Yanitskiy 535a093726 trxcon/l1ctl.c: drop meaningless 'tn > 7' checks
There is no need to check the range of timeslot number, which is
decoded from GSM 08.58 channel number (9.3.1) by applying 0x07
mask, because any result of this operation is always within
the correct range.

Change-Id: Ib84417099d303bd3ae3557f48a5c40b812c6cdfc
2018-09-06 01:07:36 +07:00
Philipp Maier 1f578082e9 cosmetic: add commandline help
There is no helptext for the commandline options, which makes it
difficult for new users to use the program.

- Add commandline help

Change-Id: I8d04644342acd64432742f96e32dc9f2e0e91c20
2018-08-27 13:03:20 +02:00
Philipp Maier b7092b920e cosmetic: fix typo
Change-Id: Ib9c5cb1aa0aaf12b68f9d93f9ce9a27037b84a56
2018-08-27 13:03:15 +02:00
Holger Hans Peter Freyther 90a9ac410c Allow lua code to register a fd for reading with the runtime
To have bi-directional communication we can pass credentials to the
registry server and now we can register a callback when the registry
is sending data to us.

The callback needs to return if the fd should continue to be selected
as I found no way to push the userdata as parameter on the stack. Lua
code will look like:

  local host, port = "www.osmocom.org", 80
  local tcp = socket.tcp()
  tcp:connect(host, port);
  tcp:send("GET / HTTP/1.0\r\n\r\n");
  local cb = function()
    local s, status, partial = tcp:receive()
    print(s)
    if status == 'closed' then
     tcp:close()
     return 0
    end
    return 1
  end
  local foo = osmo.register_fd(tcp:getfd(), cb)

Change-Id: I8254bdda1df2f8fe0a5eac894b931e7de5b426df
2018-08-24 10:35:21 +00:00
Holger Hans Peter Freyther 4a466f5007 Forget about the callback after use and cancellation
Don't try to unref something else after we have given up our
spot in the table.

Change-Id: I4e8db297e816d3d07a46147d5d3bdc0e8fae6c9a
2018-08-24 10:34:02 +00:00
Stefan Sperling 9d6d9a6b3b osmocon: fix read buffer overrun in romload_prepare_block()
Address sanitizer triggered when trying to chainload firmware:

==18466==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x631000027850 at pc 0x7f5b94cfb733 bp 0x7ffe33e1ae30 sp 0x7ffe33e1a5d8
READ of size 1014 at 0x631000027850 thread T0
    #0 0x7f5b94cfb732  (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x79732)
    #1 0x563db4293e6e in memcpy /usr/include/x86_64-linux-gnu/bits/string_fortified.h:34
    #2 0x563db4293e6e in romload_prepare_block osmocom-bb/src/host/osmocon/osmocon.c:473
    #3 0x563db429541f in handle_read_romload osmocom-bb/src/host/osmocon/osmocon.c:959
    #4 0x563db429541f in serial_read osmocom-bb/src/host/osmocon/osmocon.c:1168
    #5 0x7f5b94722c83 in osmo_fd_disp_fds libosmocore/src/select.c:217
    #6 0x7f5b94722f84 in osmo_select_main libosmocore/src/select.c:257
    #7 0x563db4293b1c in main osmocom-bb/src/host/osmocon/osmocon.c:1525
    #8 0x7f5b942b9b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
    #9 0x563db4293c79 in _start (prefix/sbin/osmocon+0x1c79)

0x631000027850 is located 0 bytes to the right of 77904-byte region [0x631000014800,0x631000027850)
allocated by thread T0 here:
    #0 0x7f5b94d60b50 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb50)
    #1 0x563db4294d65 in read_file osmocom-bb/src/host/osmocon/osmocon.c:314

Change-Id: Ie2955e11dd1af75574536774ef7ddf88ddf1fe8b
2018-08-24 10:28:19 +00:00
Philipp Maier 072f04fea4 osmo_mcast_sock: make sure SO_REUSEADDR is applied
virtphy uses UDP multicast to communicate with its osmo-bts-virtual
counterpart. At the momemnt SO_REUSEADDR is not applied for those
multicast connections because OSMO_SOCK_F_UDP_REUSEADDR is not set. This
makes prevents the proper function of UDP multicast.

- Make sure OSMO_SOCK_F_UDP_REUSEADDR is set

Change-Id: Ia1014ac5e0522e77178249cdc6398dec2168bffe
Depends: libosmocore I1399a428467ca12f1564a14eb8ffb294d4f59874
Related: OS#3497
2018-08-24 06:48:52 +00:00
Stefan Sperling 677a0f8142 osmocon: fix use of an initialized variable
osmocon.c: In function ‘read_file’:
osmocon.c:317:3: warning: ‘fd’ may be used uninitialized in this function

Change-Id: If07c58d5b55c18c05345607064eace02748935f8
2018-08-23 14:52:56 +02:00
Stefan Sperling 316f22f057 trxcon/sched_clck.c: fix time delta calculations
Use osmo_clock_gettime() to read the monotonic clock instead
of gettimeofday() which could drift backwards.
This requires switching the scheduler clock from struct timeval
to struct timespec. Expand some variables to 64 bits in order
to keep types used in calculations compatible.

The previous implementation unconditionally subtracted microsecond
values from different time measurements, causing overflow if the
current measurement was taken in less of a fraction of a second
than the past measurement. Use timespecsub() for the subtraction
instead which accounts for fractions of a second correctly.

Change-Id: Ic93f90685c6d6dc28dfc4ad48c998e0eac113cf8
Related: OS#3467
2018-08-17 17:22:59 +00:00
Vadim Yanitskiy 347406cee7 trxcon/scheduler: get rid of useless lchan->rsl_mode
This field of the logical channel state structure was not used at
all as there is nothing related to A-bis / RSL in trxcon itself.

Change-Id: Iec1abf777a74cf57deadafa95e2337cba5d02842
2018-08-15 09:32:08 +07:00
Vadim Yanitskiy 7c4151ae52 trxcon/scheduler: fix: properly generate BFI for TCH/H
When relying on GSM 04.08 channel mode (GSM48_CMODE_*), one should
distinguish between Bm (full rate) and Lm (half rate) channels.

This change prevents the scheduler from generating TCH/F BFI
instead of TCH/H BFI on the corresponding channels.

Change-Id: I4547aa7f6d38637692fef8a0122e85fb52039a46
2018-08-15 08:22:14 +07:00
Vadim Yanitskiy 3cbbe81b63 trxcon/scheduler: pass lchan to sched_bad_frame_ind()
Instead of passing the information about a logical channel, it
makes sense to pass the pointer to its state where everything
is stored. This approach would allow to avoid adding more
arguments every time, e.g. in case of AMR.

Change-Id: I91fe86fef43aac68776a58c9acc37ef2a9ee8042
2018-08-15 08:20:41 +07:00
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 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
Pau Espin f9ac7eb36e virt_phy: Add missing gprs related entries to l1ctlPrimNames
Change-Id: Ia59e22cda9cf5e25b5e2b1fe38f8ec3937b16f80
2018-03-21 16:35:07 +00:00
Vadim Yanitskiy d49a748cbb common/l1ctl.c move TCH bit-ordering to the firmware
Previously, TCH frames coming from L1 were reordered to the RTP
format. Moreover, the implementation had a few problems:

  - L1CTL is not the best place for such manipulations;
  - payloads with other than FR codec were corrupted.

Let's use RTP-ordered payloads on the L1CTL interface,
performing TCH frame reordering at the firmware.

Please note, that actual FR reordering was moved to the firmware
as is, without any codec determination. This could be fixed in
a separate change.

Change-Id: I81ec8ed3c9e72a62b22c1720c299cdc68b733cf1
2018-03-14 22:22:43 +07:00
Vadim Yanitskiy a4d255269a L1CTL/L1CTL_CRYPTO_REQ: add key length and channel info
Previously, the L1CTL_CRYPTO_REQ message contained only a ciphering
algorithm and actual Kc key to be used. The key length was
calculated manually using the MSGB API.

Let's avoid manual calculations here, as it may cause unexpected
behavior if the message structure is changed. Also, let's fill
the UL header with minimal information about a channel, which
is going to be encrypted.

Change-Id: I5fab079907c5276322d3ec2b46cab81f10c7ed09
2018-03-14 22:22:39 +07:00
Vadim Yanitskiy 23914b9cf8 Rename 'fake_trx' to 'trx_toolkit'
This toolkit has branched out into several different tools for
TRX interface hacking, and creating a virtual Um-interface
(FakeTRX) is only one of its potential applications.

Change-Id: I56bcbc76b9c273d6b469a2bb68ddc46f3980e835
2018-03-13 02:10:02 +07:00
Vadim Yanitskiy c08ddc7383 fake_trx: unify the GPL license header
There is no need to manually put the license header as a variable
in each application in order to print it. Let's use a common one.

Change-Id: I1a6e8716a9069e7ade3ae15f2c04fd45d18e223c
2018-03-13 02:08:29 +07:00
Vadim Yanitskiy 4ccb2261b1 trxcon/sched_lchan_tchf.c: always send traffic indications
We shall always send traffic frame indications, even if received
frame is incomplete or decoding was failed. This is required
for proper Measurement Reporting.

Change-Id: I99e134699796c7075299459e96b2f2d462636619
2018-03-11 17:38:29 +07:00
Vadim Yanitskiy 40e71126ab trxcon/sched_lchan_xcch.c: always send data indications
We shall always send data frame indications, even if received
frame is incomplete or decoding was failed. This is required
for proper Measurement Reporting.

Change-Id: I7beee7e797f488d04c3b59bee9501ce823717092
2018-03-11 17:38:29 +07:00
Vadim Yanitskiy 47aaf962fb trxcon/scheduler: enforce lchan handlers to set message type
Since this change, each lchan handler shall manually indicate
a type of both message indications and confirmations.

Change-Id: I02e0b87d61c127d2f6f5b9532909af78332bf707
2018-03-11 17:38:29 +07:00
Vadim Yanitskiy caebbebd16 trxcon/sched_lchan_common.c: use static memory allocation
There is no need to allocate the DL header for each new message.

Change-Id: Id7ad815c6b403f5c3d15fc02022397188f1d87fd
2018-03-11 17:38:29 +07:00
Vadim Yanitskiy 633c806a2b trxcon: clean up DATA / TRAFFIC indication API
- change 'l1ctl_tx_data_ind' symbol to 'l1ctl_tx_dt_ind' in
    order to indicate that it's used for both DATA and TRAFFIC;

  - introduce a 'traffic' flag, which is used to define either
    TRAFFIC or DATA indication type;

  - pass L2 payload and its length separately from the
    Downlink info header.

Change-Id: I9fe65ee9b2d772576b86b7bc85d53518530d1579
2018-03-11 17:38:29 +07:00
Vadim Yanitskiy ddddf9e0c4 trxcon: clean up DATA / TRAFFIC confirmation API
- change 'l1ctl_tx_data_conf' symbol to 'l1ctl_tx_dt_conf' in
    order to indicate that it's used for both DATA and TRAFFIC;

  - introduce a 'traffic' flag, which is used to define either
    TRAFFIC or DATA confirmation type;

Change-Id: Iedd569086a264dc7d8740abea5c6e5ca21e299f6
2018-03-11 17:38:29 +07:00
Vadim Yanitskiy d316b84413 trxcon/l1ctl.c: combine both DATA and TRAFFIC REQ handlers
Both functions are almost identical, and the only difference is
the message type they set. Let's combine them into a single
function and introduce a 'traffic' flag, which can be
used to define a message type.

Change-Id: I288f5d7b6cd242c4793973dcb3d2b1b6925d61a7
2018-03-11 10:34:28 +00:00
Vadim Yanitskiy eb3a1cde8c trxcon/l1ctl_link.c: allocate msgb after its length is read
Change-Id: I2b941c5ed91097c4ed2d859634bbe89f44546061
2018-03-11 10:05:48 +00:00
Vadim Yanitskiy 2136891b7b trxcon: clarify L1CTL message length field
Each L1CTL message gets its own length pushed in front before
sending. This isn't specified in the 'l1ctl_proto.h', but
assumed in the code. Let's clarify this.

Change-Id: I118d00613aeaf5ff0bad1188fa5f7450d4ca8122
2018-03-11 10:05:48 +00:00
Vadim Yanitskiy a92fd3388c trxcon: use meaningful names for L1CTL messages
There are two types of L1CTL messages: received and to be
transmitted. Let's use proper names to indicate this.

Change-Id: I7c17687579282fa389bca35dc7edbc3582e55701
2018-03-11 10:05:46 +00:00
Vadim Yanitskiy 5eae19098a trxcon/scheduler: transmit dummy frames on CBTX lchans
If at the moment of transmission there are no frames in TX buffer,
then either a dummy LAPDm frame (0x01, 0x03, 0x01, 0x2b ...) or a
silence frame (depending on a codec in use) shall be transmitted.
This is required for proper measurements on the BTS side.

Change-Id: Ie590990f2274ea476678f6b2079f90eeadab6501
2018-03-11 15:03:35 +07:00
Vadim Yanitskiy 4cf722364b trxcon/scheduler: introduce a new CBTX lchan flag
This new flag is intended to indicate that continuous burst
transmission is assumed on particular logical channel. In other
words, if a logical channel has this flag, but there is nothing
to transmit in a TX buffer, then either a dummy LAPDm frame or
a silence frame shall be sent.

Change-Id: I25fcf9eeb787ffe5378d92532439e67d7d42fa65
2018-03-11 14:59:43 +07:00
Vadim Yanitskiy c00985bf99 trxcon/sched_trx.h: clarify lchan flags meaning
Change-Id: I51b663dd16e46a4523488c3d3000922a7c3640d1
2018-03-11 14:59:43 +07:00
Vadim Yanitskiy 2778e4ef43 trxcon/sched_trx.c: fix: omit inactive logical channels
The sched_frame_clck_cb() is responsible for UL burst transmission.
Iterating over each timeslot, it chooses a proper lchan handler
according to a current frame number and a multiframe layout in use,
takes a L2 UL frame from a TX buffer, and finally calls the chosen
handler in order to to encode and transmit a taken frame.

A handler should be called only for activated logical channels...
but for some long time, there was a bug, so each lchan was
processed, including inactive ones. It's time to fix this.

Change-Id: I33e3ecc14be3ae64dfd02789c7f0970c945582c9
2018-03-11 14:59:38 +07:00
Vadim Yanitskiy f06f31fdf7 trxcon/sched_trx.c: fix: properly deallocate lchans
The llist_for_each_entry_safe() should be used instead of the
llist_for_each_entry(), because it's safe against removal
of llist entry.

Found using Valgrind's memcheck tool.

Change-Id: I65234971ec152df038c5388da537a503060c215b
2018-03-11 14:18:22 +07:00
Vadim Yanitskiy cbf818d4dc trxcon/configure.ac: add --enable-sanitize option
Change-Id: I099de726f9d67213c56d996039b4207f80a727c6
2018-03-11 14:14:51 +07:00
Vadim Yanitskiy 7fd8ef2d3f fake_trx/ctrl_cmd.py: use a random bind port by default
Since it is not required to specify a bind port to the UDPLink
constructor manually, let's use a random one by default, and
also allow user to set it from command line.

Change-Id: Ib4965ebeec83d9a99b2f026156eb5f5cb20875bf
2018-03-06 22:54:21 +07:00
Vadim Yanitskiy 2812cb7f80 fake_trx/udp_link.py: use a random bind port by default
This allows one to obtain a random available port from the
OS, instead of enforcing to pick a static value manually.

Change-Id: Ie8b60134239c5447d0b4373c6cca2f3a6ee3ec73
2018-03-06 22:53:28 +07:00
Vadim Yanitskiy c20f9bb5cd fake_trx/ctrl_if.py: remove incorrect isdigit() check
Previously, we used to check if all arguments of a command are
numeric. This was done in a wrong way, so parsing a *valid*
command with at least one negative argument could fail.

Let's remove this check, allowing the command handlers to
deal with argument types themselves.

Change-Id: If31295274a09102c414b5a7aec5dd85d88b2e514
2018-03-06 02:28:37 +07:00
Vadim Yanitskiy 59d054906d fake_trx/ctrl_if.py: reduce code branch nasting
Let's use the inverted condition to avoid additional code nasting.

Change-Id: I8a62b39d9d9a597c612f9a576e98dc05e37cd25b
2018-03-06 02:28:37 +07:00
Vadim Yanitskiy f97e3cd788 fake_trx/ctrl_if.py: remove forgotten debug print
Change-Id: I4886828fb0f927c59c5eb1945a3c2873687de7b3
2018-03-06 02:28:37 +07:00
Vadim Yanitskiy c066787fd5 host/trxcon: use integer math for ToA (Timing of Arrival)
There's no need to express ToA value as a float. Let's turn it into
an int16_t with 1/256 symbol period accuracy throughout the code to
avoid both float arithmetic as well as loosing any precision.

Inspired by Idce4178e0b1f7e940ebc22b3e2f340fcd544d4ec.

Change-Id: I99c0f38db08a530d5846c474aba352aa0b68fe86
2018-03-02 21:24:57 +07:00
Harald Welte ff233256e1 fake_trx/ctrl_if_(bb|bts).py: log link info at start-up
Change-Id: I4ebeed7271d91ab2e45199e0fb59776c00ad833c
2018-03-02 05:04:59 +07:00
Harald Welte 0d3030c764 trxcon: Fix '-i' to specify the "TRX IP address"
The command line help states '-i' is for 'TRX IP address', which is
the remote IP address at which the TRX is to be found.  Hoewever, it
was used as the local (bind) IP address of the socket used towards
the TRX.  This is my attempt at fixing this.  A more complete solution
probably allows to specify both local (bind) and remote (connect)
address, just to be clear.

Change-Id: If0252b15e9c7942687c6dc470951d777f7af651c
2018-03-01 14:42:25 +01:00
Harald Welte 380dc7e768 fake_trx: Increase TOA256 value ranges
In theory, the maximum TA value is 63 symbols, i.e. 63*256 in this
context.  However, our test cases want to test the BTS behavior is
correct if ever a larger timing offset is reported from TRX to the BTS,
to ensure it is rejected in the BTS.  Let's hence increase the values
to rather large min/max limits.  We could also remove them completely.

Change-Id: I691d081256e8c6d18ef2836299ed8f7d502da3ee
2018-03-01 11:50:22 +01:00
Harald Welte cc447afe34 fake_trx: Send positive response to FAKE_TOA commands
Now that ctrl_if.py is capable of sending back the response to where
the command originated from, we can just as well send a positive
response back after executing the related commands.

Change-Id: Icba138835149a7264f4db3a6b05f54ca501c4d54
2018-03-01 11:49:15 +01:00
Harald Welte 4e74311b00 fake_trx: Always send control responses to where commands are from
fake_trx is using locally bound and not connected UDP sockets for
control commands.

When we receive a control command, we should not simply send the
response to the default destination, but send it back to the exact
ip+prt from which the command originated.  This ensures correct routing
of responses even in case multiple programs are interfacing concurrently
with a control socket.

Change-Id: I24a0bba6eed059b101af95dac7d059f34dd715fc
2018-03-01 11:49:15 +01:00
Harald Welte b1b1162019 trxcon: Define event names for osmo_fsm's
Change-Id: Id3279e99966a0ab236923c497ac0abbc9ed2c93c
2018-02-28 23:18:09 +01:00
Vadim Yanitskiy 6fa80f274e fake_trx/burst_fwd.py: FIX: apply TA value correctly
If field randomization is disabled, Timing Advance value
indicated by MS would be ignored. Let's fix this by
separating the TA calculation code.

Change-Id: If43d5823fc33efc2f1649ea941ab6f619bb6f5e7
2018-03-01 01:52:04 +07:00
Harald Welte 5ab622d2b7 fake_trx/ctrl_if_(bb|bts).py: add FAKE_TOA command
FAKE_TOA is an auxilary CTRL command, which may be used to update
the ToA (Timing of Arrival) value of forwarded bursts at runtime.
This is useful for testing the measurement processing
code in OsmoBTS.

The command is implemented for both BTS and BB CTRL interfaces
in two absolute and relative forms:

  CMD FAKE_TOA <BASE> <THRESH>
  CMD FAKE_TOA <+-BASE_DELTA>

The first form overwrites both ToA value and its treshold.
The second one is relative, and applies a delta
to the current ToA value.

The command affects Downlink bursts if sent on BTS CTRL
interface, and Uplink bursts if sent on the BB CTRL.

Change-Id: Ia23becec4104d47e7b22350db67b8834d6f1ad1b
2018-03-01 00:17:24 +07:00
Vadim Yanitskiy 7de70009f6 fake_trx/fake_trx.py: add options to enable field randomization
By default, both RSSI and ToA fields randomization is disabled.
Let's add command line options, which allow one to enable it.

Change-Id: Ieac63cc3aadef397906479a6179ba54a53a5311a
2018-02-28 22:39:01 +07:00
Vadim Yanitskiy 81896a8328 fake_trx/burst_fwd.py: disable field randomization by default
Both RSSI and ToA fields randomization is only required in some
specific test / use cases, so let's disable it by default.

Change-Id: I94835a840b6239f2c05197292825cb26977d0216
2018-02-28 22:37:41 +07:00
Vadim Yanitskiy 3da6166111 fake_trx/burst_fwd.py: calculate both RSSI and ToA separately
In order to be able to simulate and randomize both RSSI and ToA
values for Uplink and Downlink separately, let's calculate them
in separate methods of the BurstForwarder.

Change-Id: Ia2031f22f2b549c799c782d0c8c8d0691fb6f18c
2018-02-28 22:36:53 +07:00
Vadim Yanitskiy f09989b1fb fake_trx: handle SETTA (Timing Advance) indicated by MS
Timing Advance value is a timing correction value, indicated by
the network to MS, which is used to compensate UL signal delay.
In other words, the network instructs a phone to transmit bursts
N=TA symbol periods earlier than expected.

Since we are in virtual environment, let's use TA value to
calculate the ToA (Timing of Arrival) value for BTS.

Change-Id: Ie5833a9f221587bbcac10f0b223ead9c1cbda72b
2018-02-28 22:34:36 +07:00
Vadim Yanitskiy d9cb065417 fake_trx/data_msg.py: implement ToA parsing support
This change implements ToA (Timing of Arrival) parsing, which
was missing in the DATAMSG_TRX2L1. Since we use integer math,
a ToA value is represented in units of 1/256 symbol periods.

Change-Id: Ib11482c06b977c4cf01b0644f5845a2e49d059fb
2018-02-28 22:34:27 +07:00
Vadim Yanitskiy 9fc30a4102 fake_trx/data_msg.py: use integer math for ToA
In order to avoid both float arithmetic as well as loosing any
precision, let's use integer math fot ToA (Timing of Arrival),
i.e. let's express ToA values in units of 1/256 symbol periods.

Change-Id: I56b88740f4d782ac7591fc096d1969514784a4e1
2018-02-28 22:33:35 +07:00
Vadim Yanitskiy cbd3d76df9 fake_trx/burst_fwd.py: drop useless set_slot() method
Change-Id: I721c87758f04a1962427341eb1b2d47cfdd3f780
2018-02-28 22:33:35 +07:00
Vadim Yanitskiy 7881fd6001 fake_trx/data_msg.py: use a single unified constructor
There are no message specific initialization parts, excepting
the header specific fields setting. Let's us a common constructor,
dropping custom fields from its arguments.

Change-Id: I13a3e4b2f6a1f443ebe7d809df62736e3c43f56f
2018-02-28 15:18:16 +07:00
Vadim Yanitskiy d93c1debb0 fake_trx/data_dump.py: fix python3 compatibility
There is no 'file' type in Python3 anymore, so let's reverse the
condition in DATADumpFile constructor. Also, the tag definition
was incorrect: both '\x01' and b'\x01' aren't the same.

Change-Id: Ib00c7f0bd5871fcfce931a4bfa501ae5bf797c45
2018-02-28 15:08:58 +07:00
Vadim Yanitskiy 77492b7926 fake_trx/data_msg.py: fix python3 compatibility in tests
In Python3 a range has it's own type, so its comparasion with
a list is incorrect. Let's explicitly convert both bit ranges
to lists in the bit conversation tests.

Change-Id: I98c40d3d63cbcdc3e5dc840ebf8d7310c5c08e56
2018-02-28 02:47:54 +07:00
Vadim Yanitskiy f35413691d fake_trx/burst_fwd.py: use DATAMSG transformation API
As the DATAMSG classes were introduced, let's use them.
This approach abstracts one from dealing with raw bytes.

Also, now BurstForwarder randomizes both RSSI and ToA values,
as this feature is supported from-the-box by the DATAMSG_TRX2L1.

Change-Id: Ib15018eab749150e244914dab4b6e433ce0c9209
2018-02-27 07:08:47 +07:00
Vadim Yanitskiy 615faadcfb fake_trx/data_msg.py: implement message transformation API
This change introduces two new methods, which allow to perform
L12TRX <-> TRX2L1 message type transformations.

Change-Id: Ic99cf74baa1864bf20a8fc0fc025604bc160084c
2018-02-27 06:49:07 +07:00
Vadim Yanitskiy 24e30142aa fake_trx/udp_link.py: set SO_REUSEADDR socket option
Setting this option allows one to reuse existing connections,
for example, by injecting CTRL commands or DATA bursts into
existing connections between fake_trx.py and trxcon.

Change-Id: I0882c76affa9a668a12d10967081054d2b666ed1
2018-02-27 04:57:58 +07:00
Vadim Yanitskiy 23446011af fake_trx/udp_link.py: drop useless UDPLink.loop() API
So far, this API is not used anywhere. Let's drop it.

Change-Id: I87ea2436f0b6bbeb62fe17700af48a048be143bb
2018-02-27 04:50:28 +07:00
Vadim Yanitskiy e5480d2c2b fake_trx/udp_link.py: close socket in destructor
Previously it was required to call the UDPLink.shutdown() method
manually in order to close a socket. Let's do this automatically
using the destructor of UDPLink.

Change-Id: I59c3dc61ec58cd9effeb789947d28fd602ca91f4
2018-02-27 04:40:28 +07:00
Harald Welte 05ea7248f8 trxcon|fake_trx: change default TRX port number to 6700
In order to avoid clashes with OsmoTRX, which may be also
running on the same host, let's use a different port range
starting from 6700 by default.

This idea was introduced as a result of OS#2984.

Change-Id: I66b5f25aaba3b836448ed29839c39869b5622bed
Related: OS#2984
2018-02-23 17:02:20 +07:00
Holger Hans Peter Freyther 8b9d3170ff mobile: Fix memory leak when not using a LUA script
The primitives are still allocated and dispatched but there was
no script handler to delete them. Change the ownership to delete
it at the end of the dispatch.

Change-Id: I510af13bcbb46f73a0a289f26a4921cc90bd986a
Fixes: OS#2925
2018-02-23 08:43:21 +00:00
Vadim Yanitskiy 318f8b78aa fake_trx/data_dump.py: use 2 bytes to store message length
One byte may store a value in range [0x00, 0xff]. The maximal 0xff
value is 255 in dec, so a message length is limited to 255 bytes.
This is enough for GSM bursts, but not for EDGE.

Since this change, two bytes of header are used to store the
pending message length. All captures created before are not
supported anymore...

Change-Id: I5a69d5cf2914fe56b2f9acca6054c9470627f91e
2018-02-20 19:43:02 +07:00
Vadim Yanitskiy d406afd23e fake_trx/burst_send.py: implement DATA capture support
Previously, this tool was only able to read a hand-crafted text
file with bursts and send them via the DATA interface. This is
not so useful...

This change implements support of reading DATA capture files,
which can be generated e.g. by trx_sniff.py or burst_gen.py.
Both standart input (stdio) and text-files are not supported
anymore.

Usage example:

  ./burst_send.py -m L1 -i capture.bin --timeslot 2

Change-Id: I626662bd1897c874421ab5178970ec19325f8a47
2018-02-20 19:29:00 +07:00
Vadim Yanitskiy 711e2f256e fake_trx/burst_gen.py: add burst capture support
Now all generated bursts can be also written to a capture file,
using a new option called '--output-file'. If a file already
exists, bursts would be appended to the end. Otherwise a new
capture file is created.

Change-Id: I074ff7dbc4d6beecdecce20de9dade5939e707f2
2018-02-20 18:19:48 +07:00
Vadim Yanitskiy 3dfd6cbae5 fake_trx/trx_sniff.py: use DATADumpFile for capture writing
Since we have a separate class for DATA capture management now,
no need to implement the wheel - let's just use it!

Change-Id: I7c30bcea294ce7270bf905ae5420a06dbc2e46f1
2018-02-20 18:02:35 +07:00
Vadim Yanitskiy afd110a3b5 fake_trx: implement classes for DATA capture menagement
This change introduces the following classes:

  - DATADump - basic class, which contains methods to generate
    and parse the a message header, and some constants.

  - DATADumpFile - a child class, which contains methods to
    write and parse DATA messages from capture files.

Usage example:

  # Open a capture file
  ddf = DATADumpFile("capture.bin")

  # Parse the 10th message
  msg = ddf.parse_msg(10)
  msg.fn = 100
  msg.tn = 0

  # Append one to the end of the capture
  ddf.append_msg(msg)

Change-Id: I1b31183bd7bcca94de089847ee0b2f4ec88a7f1d
2018-02-20 17:48:29 +07:00
Vadim Yanitskiy af4bad3125 mobile/primitives.c: fix format string compiler warning
The recent LUA integration code introduced the following
compiler warnings (on GCC 4.8.5):

primitives.c: In function ‘create_timer’:
primitives.c:90:2: warning: format ‘%llu’ expects argument of
                   type ‘long long unsigned int’,
                   but argument 7 has type ‘uint64_t’ [-Wformat=]

primitives.c: In function ‘cancel_timer’:
primitives.c:166:3: warning: format ‘%llu’ expects argument of
                   type ‘long long unsigned int’,
                   but argument 7 has type ‘uint64_t’ [-Wformat=]

The recommended and portable way of printing an 'uint64_t'
is to use the corresponding macros 'PRIu64'.

Change-Id: Ic7f54063a35a89ad54dfa63868f43009cbe469bb
2018-02-10 19:36:20 +07:00
Vadim Yanitskiy f54ebb06b9 layer23/cell_log: set default logfile to /dev/null
When '/var/log/osmocom.log' does not exist the cell_log
app cannot start normally, because it has no permissions
to create a new file. Furthermore, logfile is optional now.

Change-Id: I2a9982f221871c78c5c9a73b7b7a1787ff07a86c
2018-02-08 10:20:02 +00:00
Luca Melette e357646ed7 Import gprsdecode utility from SRLabs
This change introduces a modified version of gprsdecode utility,
which is intended to decode the GPRS burst captures and forward
decoded packets to the GSMTAP sink.

The following modifications were made:

  - use shared libosmocoding library for GSM 05.03 coding;
  - use optget for command line options parsing;
  - use a single application select loop;
  - use GNU automake as the build system;
  - add regression tests (GNU autotest);
  - clean up and comment the code;
  - add license headers;

The code is based on work of SRLabs:

  https://srlabs.de/
  git://git.srlabs.de/gprsdecode.git

Related: OS#1672
Change-Id: I12234d37c66b83b8abd60f7511fa1d7837db1856
2018-02-06 14:05:17 +07:00
Vadim Yanitskiy 041bfc0b03 fake_trx/burst_send.py: handle both GSM and EDGE bursts
Previously, it was expected that burst length should be equal
to 148. Let's also handle EDGE bursts and use GSM constants.

Change-Id: Iab13dd06f175556137c5e25d2cbddb9bea403b09
2018-01-29 04:19:01 +07:00
Vadim Yanitskiy 630cc5a367 fake_trx/burst_send.py: also handle RSSI and ToA values
Change-Id: Idb9a5ae4a8980a320f6e620c66add7c7393d3ecb
2018-01-29 04:19:01 +07:00
Vadim Yanitskiy e3a23102b7 fake_trx/burst_gen.py: also handle RSSI and ToA values
Change-Id: I7c9441c1154c925dcb5c743e39445495233c123e
2018-01-29 04:19:01 +07:00
Vadim Yanitskiy d273ebf611 fake_trx: use DATAMSG classes for DATA messages
The DATAMSG API, that was introduced and extended a few commits
before, provides all required methods to create, validate,
generate and parse DATA messages. Let's use it now.

Change-Id: Ibc99126dc05d873c1ba538a5f4e74866de563f56
2018-01-29 04:19:01 +07:00
Vadim Yanitskiy 263ccef268 fake_trx/burst_gen.py: don't store RandBurstGen
No need to keep it as a class member.

Change-Id: I5bf5846c2b8fa1211cf5150545b9d001c17fa0eb
2018-01-29 04:19:01 +07:00
Vadim Yanitskiy b84699096a fake_trx/burst_gen.py: check argv separately
Change-Id: I35b5475d3b6df6dc92a1981c693afb63df866c87
2018-01-29 04:19:01 +07:00
Vadim Yanitskiy d9553faf62 fake_trx/data_msg.py: implement header description
This change introduces a new method for both types of messages
called 'desc_hdr', that generates human-readable header
description.

Examples:

  TRX -> L1: fn=571353 tn=1 rssi=-108 toa=-0.53
  L1 -> TRX: fn=1777477 tn=3 pwr=161

Change-Id: Iafe63e39ad68f4ff373ae098424d76ca9f83c8fc
2018-01-29 04:19:01 +07:00
Vadim Yanitskiy 475ece7182 fake_trx/data_msg.py: handle bursts properly
One L1 -> TRX message carries one to be transmitted burst encoded
as regular bits (0 or 1). One TRX -> L1 message carries one
received burst encoded as unsigned soft-bits (0..254).

This shall be noted during message encoding and decoding process.
Also, we shall distinguish between GSM and EDGE bursts.

Change-Id: I909b7a4dc70e8c632987bde07f00281a6595c4cb
2018-01-29 04:19:01 +07:00
Vadim Yanitskiy 8c79e2ce6b fake_trx/data_msg.py: implement header randomization
This feature could be used by both burst_gen.py and burst_send.py.

Change-Id: I724e267382ff32ef1f964b1ee6cbe99069139867
2018-01-29 04:18:56 +07:00
Vadim Yanitskiy f10a8d4c92 fake_trx: implement classes for DATA messages
This change introduces three new classes:

  - DATAMSG - abstract class, defines common fields and methods
    for any message on DATA interface, e.g. frame and timeslot
    numbers, bit conversation methods, etc.

  - DATAMSG_L12TRX - a child of DATAMSG, defines a message
    coming from L1 to TRX.

  - DATAMSG_TRX2L1 - a child of DATAMSG, defines a message
    coming from TRX to L1.

Both child classes could be used to generate DATA messages from
known fields (i.e. fn, tn, etc.), and parse them back from
already encoded DATA messages.

Change-Id: Id1c72f0b18fb128acc74d0cd899fb7aab7bd8790
2018-01-29 04:14:34 +07:00
Vadim Yanitskiy 5da2ac7197 fake_trx: share and use common GSM constants
Previously there were multiple definitions of some common GSM
constants in different modules. Let's share them.

Change-Id: Id6cdfbc6e8688755a0df7e44daa512c9afa7dad2
2018-01-29 03:49:35 +07:00
Max 75e11d1d44 Don't ignore top-level Makefile
Move corresponding .gitignore entry inside virt-phy to avoid interfering
with other subprojects still using hand-crafted Makefiles.

Change-Id: I19a8661b74ae0b28da51cf2e81f0ca40de76fcbd
2018-01-22 17:33:54 +01:00
Max 4ee98c9db6 cosmetic: fix Makefile whitespace
Change-Id: Ia55d54d7ec7ec04e122d2e5250037c2d166abeb5
2018-01-22 17:18:31 +01:00
Vadim Yanitskiy ab7eb390cb fake_trx: implement a new tool for TRX protocol sniffing
This change introduces a new tool, which could be used to sniff a
single connection between L1 and TRX in both directions, filter
captured bursts by direction, timeslot and/or frame number, and
finally write them to a binary file for further analysis.

Sniffing capability is based on Scapy framework, so it should
be installed in order to run this tool. Please also note,
that sniffing requires root access. For details, see:

https://github.com/secdev/scapy
https://scapy.readthedocs.io/en/latest/

Usage example:

  sudo ./trx_sniff --frame-count 30 --timeslot 2 -o /tmp/bursts

This command will capture 30 frames on timeslot number 2, and
write them to a binary file. The format of this file is based
on TLV (Tag Length Value), that wraps each burst:

  ... |-TAG (byte)-|-LEN (byte)-|-BURST (LEN bytes)-| ...

  TAG 0x01 - a message coming from L1 to TRX
  TAG 0x02 - a message coming from TRX to L1

Change-Id: I6e65e1d657574cc3e67bc7cdb1c01ef6bf08ecde
2018-01-21 02:13:47 +06:00
Vadim Yanitskiy 32462cfd62 fake_trx/burst_send.py: indicate actual burst source
Change-Id: I7e45996f4a7a2aacc962ff9b65107c6b04e7bf68
2018-01-20 16:44:19 +06:00
Stefan Sperling df1049f380 mobile: Print an error message if the VTY cannot be initialized
If we fail to initialize the VTY, print an error mesage instead of
failing silently. For example:
"Cannot init VTY on 127.0.0.1 port 4247: Address already in use"

Change-Id: I24161f53fa621ae1c8b1916bd0c8055c494b531e
2018-01-18 15:40:57 +01:00
Vadim Yanitskiy 0192c028e4 trxcon/scheduler: use TCH frame length defs from libosmocodec
Change-Id: I6439d3cadd2dc1fa8fe401eb61c977a12ec844f2
2018-01-05 15:06:48 +07:00
Vadim Yanitskiy f09be8a9af trxcon/scheduler: drop meaningless TODO comment
Since both TA and AGC loops should be implemented in transceiver,
this TODO is meaningless. Let's drop it.

Change-Id: I84979712e2a1b849acaee53d5cd50de4e1e357c2
2018-01-05 14:36:03 +07:00
Vadim Yanitskiy bd6e320c08 trxcon/scheduler: use linuxlist API for lchan management
As there is no any order relation between logical channels, it's
better to use the linuxlist API instead of talloc array.

Change-Id: I5a78582c77ed1ab33817d240e065dc4cd4708199
2018-01-05 14:35:37 +07:00
Vadim Yanitskiy 0c201abbff trxcon/scheduler: deactivate lchans when resetting / deleting TS
Previously, when resetting or deleting a timeslot, we did not
deactivate the logical channels, relaying on talloc hierarchical
nature. This approach may cause some problems, e.g. on embedded
systems with emulated talloc API.

Change-Id: I8c34c793df87bd8c79b7bf1f05b949faf10520e8
2018-01-05 14:35:37 +07:00
Vadim Yanitskiy 5c70e48077 trxcon/scheduler: reset lchan state after deactivation
Let's assume that a logical channel, which was already in use,
is activated again for a new connection. As we don't reset the
state variables, such as burst masks or ciphering data, it may
cause an unexpected behaviour.

In order to avoid this, let's always reset the logical channel
state after deactivation.

Change-Id: I91e736a97cb05b167614cb488a00d847a9a859e0
2018-01-05 14:35:29 +07:00
Vadim Yanitskiy 96da00d457 trxcon/scheduler: share chan / prim identification helpers
Because they would be also used outside.

Change-Id: Ic8af9d7c72fdb124caef82e35170f92b84e16eb9
2018-01-05 14:34:49 +07:00
Vadim Yanitskiy 6c0b1261a3 trxcon/scheduler: FIX: return NULL from TCH dequeue function
Initially it was expected that a TCH transmit queue could contain
TCH and FACCH primitives only. But there are also SACCH primitives,
which are also being stored there.

So, let's drop the assertations from the sched_prim_dequeue_tch(),
and return NULL if nothing was found.

Change-Id: Iae37057d35883c09a76f0612e52c2d14d9ff91cb
2018-01-04 00:10:18 +01:00
Holger Hans Peter Freyther ceb0875f1a mobile: Properly close the primitive interface on reload
When reloading a script go through script_lua_close. Get the
primitive first. Then destruct the lua environment which will
lead to GC (e.g. cancellation of timers) and then delete the
primitive code.

Change-Id: I5bb4fa9e7c5010f3ad50b258dcb14956eea8822a
2017-12-27 10:50:14 +08:00
Holger Hans Peter Freyther a8130aba91 mobile: Send SMS through the primitive interface
Make this symmetric and send the SMS through the primitive
interface. Construct and copy the sms into the prim, store
the SCA in the prim as well. In 04.11 we see we can store
2*10 digits in the destination address and a NUL.

Change-Id: I91d7537f4f6ce5ba00218c58f3456947ec7bc662
2017-12-27 10:07:17 +08:00
Vadim Yanitskiy feec102aea trxcon/scheduler: implement A5/X ciphering support
This change implements the A5/X ciphering support transparently
for the logical channel handlers. In other words, a DL burst is
deciphered before being passed to a handler, and an UL burst is
ciphered before being sent to transceiver.

The implementation mostly relays on the libosmocore's A5 API.

Change-Id: Ib53418d8c0f394fdece09cf5cc240887cb0bb5af
2017-12-18 06:17:50 +07:00
Vadim Yanitskiy 44838f79a2 trxcon/scheduler: preprocess UL bursts before sending
Having a possibility to preprocess UL burst before sending to
transceiver is required for the further ciphering support
integration and probably some other tasks.

Change-Id: Ia6eead5d4f51d7c0bf277b9d5ebb0a74676df567
2017-12-18 06:04:29 +07:00
Vadim Yanitskiy 255f25ef25 L1CTL/L1CTL_CRYPTO_REQ: add key length and channel info
Previously, the L1CTL_CRYPTO_REQ message contained only a ciphering
algorithm and actual Kc key to be used. The key length was
calculated manually using the MSGB API.

Let's avoid manual calculations here, as it may cause unexpected
behavior if the message structure is changed. Also, let's fill
the UL header with minimal information about a channel, which
is going to be encrypted.

Change-Id: I1813a188e755141241273479b17896415abcc3f1
2017-12-18 06:04:29 +07:00
Vadim Yanitskiy 32c2a1d74c trxcon/scheduler: prioritize FACCH correctly
Previously we used to compare two consecutive first primitives,
taken from a transmit queue. This approach may cause some delay,
which is critical for FACCH e.g. in case of handover.

Let's walk through a whole transmit queue to find a pair of
both FACCH frames, and only then decide what to do.

Change-Id: I925cca77bfaa255dd095bc882c901d41c9bc4633
2017-12-18 05:26:57 +07:00
Vadim Yanitskiy a403215bea trxcon/scheduler: move prim management outside lchan handlers
Previously, each lchan handler used to obtain and delete primitives
from a timeslot's tranmit queue itself. This approach entails many
potential problems and bugs:

  - The lchan handlers shall not do that by definition, they
    should encode and decode frames according to GSM 05.03.

  - In some cases (e.g. TCH), a single transmit queue may contain
    primitives of different types (e.g. TCH, FACCH and SACCH). At
    the same time, the lchan handlers don't care and don't even
    know about each other. So, this could cause an unexpected
    behaviour in some cases.

This change separates all primitive management routines,
providing a new API for obtaining and dropping them.

"Write programs that do one thing and do it well."

Change-Id: I29503ece51903784bc53541015285234471c8d15
2017-12-18 05:26:48 +07:00
Vadim Yanitskiy 15d512d301 trxcon/scheduler: separate primitive management code
It's good to write, keep and make the source code as much modular
as possible. So, Tte primitive management code was separated to
the 'sched_prim.c' and going to be extended in the near future.

Change-Id: Ifec8c9e4f2c95c72b00772688bcb5dc9c11d6de7
2017-12-18 05:20:25 +07:00
Vadim Yanitskiy e17bb11c3b trxcon/scheduler: BUGFIX: distinguish between SACCH and FACCH
Both SACCH and FACCH messages have the same 23-byte length, both
are being queued together within a single transimt queue. So,
previously a SACCH frame could be picked by TCH burst handler,
and then sent as a FACCH frame. Let's fix this.

A FACCH primitive may have one of the TRXC_TCH* logical channel
types, while SACCH primitives have one of the TRXC_SACCH*.

Change-Id: Ia7090384f3ff74c9d94997265135acbceffa0ffe
2017-12-18 05:18:07 +07:00
Vadim Yanitskiy 60ff614446 host/trxcon/scheduler: always print error messages
Some error messages previously had incorrect logging level 'debug'.
We aren't going to hide anything, right? Let's print them!

Change-Id: I85fb37292046b667386bfe26b9bbb000600e1c6f
2017-12-16 16:33:17 +07:00
Vadim Yanitskiy a9c2ef2638 host/trxcon/scheduler: inform L2&3 about decoding errors
Previously, we used to drop a frame if decoding wasn't successful.
This way, the higher layers didn't even know about that, so the
local counters and Measurement Reports were incomplete.

This change makes scheduler to forward L2 frames in any case,
setting the num_biterr for each of them. In case of decoding
error, a dummy (payload filled by 0x00) L2 frame will be sent.

Change-Id: I31011d8f3ca8b9a12474cd0bc653faed18391033
2017-12-16 16:21:05 +07:00
Vadim Yanitskiy 9b511668a4 host/trxcon/scheduler: add initial TCH/F channel support
This change implements basic TCH/F lchan handlers for both data
reception and transmission. Only FACCH (signaling), FR and EFR
payloads are supported at the moment.

Change-Id: If6b0eaede2b484484d2a824e7219ff04483266a1
2017-12-16 15:45:38 +07:00
Vadim Yanitskiy 21049e5fc4 host/trxcon/l1ctl.c: handle L1CTL_TRAFFIC_REQ
Change-Id: Ibdf2d4f6aa464250a4c6951af86c06eb3fd3b98b
2017-12-16 15:45:17 +07:00
Vadim Yanitskiy 0b5231bdb4 common/l1ctl.c move TCH bit-ordering to the firmware
Previously, TCH frames coming from L1 were reordered to the RTP
format. Moreover, the implementation had a few problems:

  - L1CTL is not the best place for such manipulations;
  - payloads with other than FR codec were corrupted.

Let's use RTP-ordered payloads on the L1CTL interface,
performing TCH frame reordering at the firmware.

Please note, that actual FR reordering was moved to the firmware
as is, without any codec determination. This could be fixed in
a separate change.

Change-Id: I235a9f535c39d8e57f5d2c6566daeaf883aeef9e
2017-12-16 15:45:17 +07:00
Vadim Yanitskiy d2c13e3d20 host/trxcon/scheduler: use GSM_MACBLOCK_LEN definition
Change-Id: Ie3b27ecb62d6f0e84f2e3ec0c1558e32bb213d33
2017-12-16 15:45:12 +07:00
Vadim Yanitskiy 3d872d0eae host/trxcon/scheduler: drop meaningless memset call
Change-Id: I18a938cef350632673cfc820beed5e42f40d89e7
2017-12-16 15:24:54 +07:00
Vadim Yanitskiy 2937cb4c16 host/trxcon/scheduler: clean up the trx_lchan_state
There were some BTS specific variables, which are meaningless.
This change cleans them up, and also groups some measurement,
encryption, and AMR specific variables into sub-structures.

Change-Id: Ie753a7e3e7fa2b433d8319b3a05b85b8583d7be2
2017-12-16 15:24:54 +07:00
Vadim Yanitskiy ab566a7aef host/trxcon/scheduler: use new libosmocoding API for RACH
Since the 32e5641d, the gsm0503_rach_encode() is deprecated, and
the library provides new API with extended (11-bit) RACH support.

Change-Id: I1955fe46eebd173d6eddd1d47ee9f7318b9b4e2d
2017-12-16 15:24:54 +07:00
Vadim Yanitskiy f02c04f444 mobile/vty_interface.c: fix 'channel-capability' description
Change-Id: I0c08e071ffaac9b8e7c4af6a7be2bd8125145842
2017-12-13 23:05:59 +07:00
Vadim Yanitskiy 68bd110717 mobile/gsm48_rr.c: cosmetic: drop wrong comment
Nothing is actually being skipped in this function.

Change-Id: I9d5a33cf3a1dd7a75f9769d3c5ba85c59594b8f4
2017-12-13 10:22:28 +00:00
Vadim Yanitskiy 1a8a80aeae mobile/gsm48_rr.c: fix ACCH System Information parsing
According to GSM 04.08, the System Information messages, such as
SI5, SI5ter, SI5bis and SI6 (described in sections 9.1.37-40),
have no the 'L2 Pseudo Length' (10.5.2.19) field, unlike others.

So, previously the ACCH SI messages were ignored due to an
implementation error - the gsm48_system_information_type_header
struct isn't applicable here, because it assumes the 'l2_plen'.

Since there is no (yet?) equivalent struct for the ACCH SI, this
change replaces the wrong struct by the 'gsm48_hdr', which
satisfies described requirements.

Moreover, this change cleans up some gsm48_rr_rx_sysinfo*
functions, getting rid of meaningless pionter shifting.

Change-Id: I9166996f146af7973bf02a8a1c965581dc58a4a5
2017-12-13 10:22:16 +00:00
Vadim Yanitskiy af217395cc fake_trx: don't sent clock indications until POWERON
Change-Id: I86ccc9d26fc54e6511f74f858afdaebb2b284c19
2017-12-09 01:25:52 +07:00
Vadim Yanitskiy 26ecb9460e fake_trx/clck_gen.py: reset the clck_src when calling stop()
Change-Id: I1043f71a2cbe856a0cb605db8a7feab9defa6afd
2017-12-09 01:24:05 +07:00
Vadim Yanitskiy 05ff6b0667 fake_trx/clck_gen.py: send the first indication immediately
Change-Id: I0132dd939b02db357d248abf65c9116d6a1802d0
2017-12-09 01:22:24 +07:00
Craig Comstock 2cac7e8cef target/firmware: fix Mediatek firmware compilation
The existing Makefile.mtk isn't compatible with the current
Makefile scheme, so nothing would happen when it was called.

This change updates the Makefile.mtk, so the Mediatek firmware
can be successfully compiled again.

Change-Id: Iecd619ed862f4d825095292ffde50544e647f6ff
2017-12-07 09:06:32 +07:00
Vadim Yanitskiy 8ed6f42772 host/trxcon: forward Timing Advance value to transceiver
The time at which the phone is allowed to transmit a burst of
traffic within a timeslot must be adjusted accordingly to prevent
collisions with adjacent users. Timing Advance (TA) is the
variable controlling this adjustment. The TA value is normally
between 0 and 63, with each step representing an advance of
one bit period (approximately 3.69 microseconds).

As trxcon doesn't perform actual burst transmission, this value
needs to be forwarded to the transceiver, which will take care
about the timings.

Change-Id: Ia8c0848827ab2b4cd7cf1efe128b28d5c06ec84e
2017-12-05 01:16:44 +07:00
Vadim Yanitskiy 0d9680e88a host/trxcon/trx_if.c: get rid of useless commands
The 'SETMAXDLY' command is used on the BTS side to limit maximal
Time of Arrival for access bursts. As we don't receive RACH
bursts on the MS side, the command is useless.

The 'SETRXGAIN' command is used on the BTS side to set initial
receive gain value for TRX. On the MS side it's possible to set
that parameter via command-line options of TRX.

Change-Id: I3e61b4b48193004cdcb241cefabb44c12db93120
2017-12-04 23:59:55 +07:00
Vadim Yanitskiy c5d9507b5d host/trxcon/trx_ic.c: use osmo_ubit2sbit() from libosmocore
No need to reimplement the existing functions...

Change-Id: Ic9b232c8561609d42dac10e6249a3e1c58c4edc1
2017-12-04 23:59:49 +07:00
Holger Hans Peter Freyther 238df986b9 mobile: Return the name of the configured "MS"
In lua osmo.ms():name() will print the name/number of the MS. This
can be used by scripting code to use in events and then be analyzed.

Change-Id: I881d3e87daa19f4e6f4f5bd30fe95906129e60ef
2017-12-03 22:01:50 +00:00
Holger Hans Peter Freyther a0fc36f859 mobile: Simplify code and check the cb ref in load_cb
Change parameters and check if the cb_ref is valid or not.

Change-Id: I74fbcd7e853e24b1225ecc4c19304134b8467c9b
2017-12-03 18:36:19 +00:00
Holger Hans Peter Freyther edb65f915f mobile: Use new LOGPSRCC macro to print multiple values
We need continuation to avoid printing the logging category
again. E.g. when print(one, two, three) is called.

Change-Id: Id8491fa949768f170a8c74ab554cb1166afda1b7
2017-12-03 12:58:53 +00:00
Holger Hans Peter Freyther 50869b9146 mobile: Create "ms" singleton for struct osmocom_ms
Make the MS the script is associated with accessible to lua. Provide
access to IMSI and IMEI. The IMSI might not be available at the given
time and just return an empty string.

Example lua usage:

 print(osmo.ms():imsi());
 print(osmo.ms():imei());
 print(osmo.ms():shutdown_state())
 print(osmo.ms():started())

 function ms_started_cb(started)
	print("MS started", started)
 end

 function ms_shutdown_cb(old_state, new_state)
	print("MS shutdown", old_state, "->", new_state)
 end

 function sms_cb(sms, cause, valid)
	print("SMS data cb", sms, cause, valid)
	for i, v in pairs(sms) do
		print(i, v)
	end
 end
 function mm_cb(new_state, new_substate, old_substate)
	if new_state == 19 and new_substate == 1 then
		osmo.ms():sms_send_simple("1234", "21321324", "fooooooo", 23)
	end
 end
 local cbs = {
	Started=ms_started_cb,
	Shutdown=ms_shutdown_cb,
	Sms=sms_cb,
	Mm=mm_cb
 }

 timer = osmo.timeout(20, function()
    print("Timeout occurred after 20s")
 end)

 osmo.ms():register(cbs)

 # Can fail. Best to wait for state changes...
 print(osmo.ms().start())
 print(osmo.ms().stop(true))

Change-Id: Ia3ace33d6ba4e904b1ff8e271a02d67777334a58
2017-12-03 12:58:53 +00:00
Holger Hans Peter Freyther 44c19326f3 mobile: Add osmo.timeout for lua code to have timeouts
Allow to callback into lua code after a user configured timeout. Make
it only work on seconds (truncate double to int).

Change-Id: I355d2f8d15aeaa13abb1c5e4a8e0c958e5faf7f3
2017-12-03 12:58:53 +00:00
Holger Hans Peter Freyther 4080e622b7 mobile: Add initial support for scripting support
Right now the script will be executed once it is loaded. Make sure
to write it into the config file last. Expose various log commands
for logging. Jump through some hoops and get the filename and line
number from lua.

Change-Id: I456f6b6b5e1a14ed6c8cb0dcc5140093d3c61ef6
2017-12-03 12:58:53 +00:00
Holger Hans Peter Freyther 32dec4236e mobile: Add LUA as debug category to the applications
Change-Id: Id2d266c48d30c06dfdc3b8c84d875038b43f2ad8
2017-12-03 12:58:52 +00:00
Holger Hans Peter Freyther 63100e308c mobile: Search for lua5.3 and link to it
I will be adding a high-level async scripting interface to the
mobile application. The initial implementation will use Lua 5.3.
This version was released in January 2015 and is the latest version
at the time the commit was made. Lua as extension and extensible
language seems well suited for scripting.

The plan is to attach a script to a ms and be able to trigger high
level operations (send SMS, attach to network, detach).

Change-Id: Ic649e49a22c878585a6c20b5b80108909f2374eb
2017-12-03 12:58:52 +00:00
Holger Hans Peter Freyther f976ad9dc4 mobile: Notify MM status changes and generate primitive op ind
Notify once the mm state has been changed. Unfortunaley one state
transition can immediately trigger more transitions (recursively).
In the mid-term it might be best to force all primitives to be
async to avoid unpredictable behavior (e.g. make a shutdown while
being a recursion down?)

Change-Id: I8e9dcf7fd9116985aa060ba027ba74107a19223a
2017-12-03 12:58:52 +00:00
Holger Hans Peter Freyther 714cb53282 mobile: Inform the primitive layer about status and new sms
Inform the layer about new SMS and inform about the cause of
it. In both cases pass the SMS.

Change-Id: Ib7ab34b1b85b62ef0e8fff347adccbc5dc414161
2017-12-03 12:58:52 +00:00
Holger Hans Peter Freyther 88060f462c mobile: Directly inform the primitive layer about an event
Forward started/shutdown changes to the primitive layer which will
turn them into indications. The other option might be to use the
signals but it seems primitives are a superset of the signals.

The notify will be done per MS and then the right primitive
instance will be searched and the indication be sent. The approach
will be applied to other systems as well.

The signal framework might be seen as
a subset of the primitives A signal mostly being a different form
of an indication.

Change-Id: I5df20a4ab79c06b515780675b6df2929aa976f0d
2017-12-03 12:58:52 +00:00
Holger Hans Peter Freyther a8726d977a mobile: Begin with a primitive interface on top of the code
We want the script interface to interface through a primitive
interface. This will allow to move it to a different thread or
a process in the future. The script interface will just use the
primitives.

It is not clear how "sap" will be used here. I am keeping it
at 0 right now. The first primitive is starting a timer with a
request and then getting an indication as a response.

Change-Id: Id2456b7fae35546553c4805f12a40c0812d9255c
2017-12-03 12:58:52 +00:00
Holger Hans Peter Freyther 04754e8889 mobile: Move starting/stopping a MS into a separate function
Move the check if within the mobile app there is no other active
MS using the same L1 socket. This way we can call this function
from the primitive code as well.

Change-Id: Ib4aa5ff212fa6bead8f620abaecc6a0b51a99fec
2017-12-03 12:58:52 +00:00
Holger Hans Peter Freyther d2cdf93b53 mobile: Declare struct osmocom/vty to be self includeable
In file included from settings.c:27:0:
../../include/osmocom/bb/mobile/app_mobile.h:10:42: warning: ‘struct osmocom_ms’ declared inside parameter list will not be visible outside of this definition or declaration
 int l23_app_init(int (*mncc_recv)(struct osmocom_ms *ms, int, void *),
                                          ^~~~~~~~~~
../../include/osmocom/bb/mobile/app_mobile.h:14:26: warning: ‘struct osmocom_ms’ declared inside parameter list will not be visible outside of this definition or declaration
 int mobile_delete(struct osmocom_ms *ms, int force);

Change-Id: I9348b3ed71a8490c03edda954402ab954f645b7c
2017-12-03 12:58:52 +00:00
Holger Hans Peter Freyther 229ea1ca5b mobile: Fix compiler warning on printing ptrdiff_t
The "msg->tail - msg->l4h" subtract two unsigned char*
pointers and should result in a ptrdiff_t. Fix the
compiler warning by using "%ti" in the printf.

Fixes:
gsm411_sms.c: In function ‘gsm411_rx_rp_ud’:
gsm411_sms.c:382:25: warning: format ‘%li’ expects argument of type ‘long int’, but argument 7 has type ‘int’ [-Wformat=]
  LOGP(DLSMS, LOGL_INFO, "TPDU(%li,%s)\n", msg->tail-msg->l4h,
                         ^
/home/ich/install/openbsc/include/osmocom/core/logging.h:93:54: note: in definition of macro ‘LOGPSRCC’
     logp2(ss, level, caller_file, caller_line, cont, fmt, ##args); \
                                                      ^~~
/home/ich/install/openbsc/include/osmocom/core/logging.h:47:2: note: in expansion of macro ‘LOGPSRC’
  LOGPSRC(ss, level, NULL, 0, fmt, ## args)
  ^~~~~~~
gsm411_sms.c:382:2: note: in expansion of macro ‘LOGP’
  LOGP(DLSMS, LOGL_INFO, "TPDU(%li,%s)\n", msg->tail-msg->l4h,
  ^~~~
gsm411_sms.c:382:25: warning: format ‘%li’ expects argument of type ‘long int’, but argument 7 has type ‘int’ [-Wformat=]
  LOGP(DLSMS, LOGL_INFO, "TPDU(%li,%s)\n", msg->tail-msg->l4h,
                         ^
/home/ich/install/openbsc/include/osmocom/core/logging.h:95:53: note: in definition of macro ‘LOGPSRCC’
     logp2(ss, level, __BASE_FILE__, __LINE__, cont, fmt, ##args); \
                                                     ^~~
/home/ich/install/openbsc/include/osmocom/core/logging.h:47:2: note: in expansion of macro ‘LOGPSRC’
  LOGPSRC(ss, level, NULL, 0, fmt, ## args)
  ^~~~~~~
gsm411_sms.c:382:2: note: in expansion of macro ‘LOGP’
  LOGP(DLSMS, LOGL_INFO, "TPDU(%li,%s)\n", msg->tail-msg->l4h,

Change-Id: Ia574fc7849bd00a94cf6651eb0d26fdc91ef1443
2017-12-03 12:58:52 +00:00
Holger Hans Peter Freyther 271cdad401 mobile: Use enum and not magic value in the VTY
Change-Id: I8a1d975997e592344327e6b0783bd0c5d2534b02
2017-11-30 17:03:25 +08:00
Holger Hans Peter Freyther ff43e1a1b3 mobile: Re-introduce msg_ref in struct gsm_sms
In I4bac5f06921b5fd85a98d97770d42d4858ca1c42 I have removed the
msg_ref field. But in case we delete a transaction with a pending
SMS we need to get the msg_ref from somewhere. This is a partial
revert but for RX SMS it makes sure that msg_ref will be set (it
wasn't set before).

Change-Id: I9b0f90f875de5f072565878861d38b0bb3bfbded
2017-11-30 17:03:25 +08:00
Holger Hans Peter Freyther d27d4354c3 mobile: ms->shutdown was not converted properly to enum
ms->shutdown is ms->shutdown != 0 which should have been
converted to ms->shutdown != MS_SHUTDOWN_NONE. This is fixing
sending SMS.

This was introduced in Iee1140e4848923c7270495c381bf87b7e3fddee1.

Change-Id: Ia74374dd9c0dd0ba9cf5725d66f4d2f2a2cfe9ef
2017-11-30 17:03:25 +08:00
Holger Hans Peter Freyther 517bda18b2 mobile: Speculative crash fix of the SI pointer
The SIs are kept per ARFCN and for the current cell the
cs->si alias will be assigned[1]. On mobile_exit all SIs
will be freed but the alias will not be set to NULL.

This is a speculative fix but it doesn't seem to make
things worse.

Related: OS#2690

[1] cs->si = cs->list[cs->arfci].sysinfo;

Change-Id: Icf20f9aa03dd26d4bee78772b7f3da034bb34b99
2017-11-30 17:03:25 +08:00
Holger Hans Peter Freyther 89009751ea mobile: Avoid msg_ref going out of sync
It seemed like msg_ref could go out of sync. In some places we are
using sms->msg_ref in other cases we pass it as parameter (e.g. when
sending the SMS) or we get it out of the gsm411_rp_hdr.

Instead of hardcoding 42 for all messages make it configurable and
pass the parameter from the caller.

Change-Id: I4bac5f06921b5fd85a98d97770d42d4858ca1c42
2017-11-27 17:54:23 +08:00
Holger Hans Peter Freyther 14598ac88d mobile: Change started and shutdown state through function
Instead of changing the field all over the place, do the state
change in a function. This will allow us to emit a notification
when things change. It is similar to the lchan_state.

Change-Id: I6a0591bb2785232681b23e41368323f16d3c960c
2017-11-27 17:54:23 +08:00
Holger Hans Peter Freyther eddf339871 mobile: Instead of putting semantic in a comment, use an enum
The enum was created to understand the different states during
the shutdown and find places where it is used. The normal
transitions are like.

	Idle -> Imsi Detach -> L1 Reset -> Done
	Idle -> L1 Reset -> Done

The shutdown can get stuck in case:

* Out of memory situation while handling IMSI detach (timeout)
* Never receiving l1 reset acknnowledgment.

The code could benefit from the move to osmo fsm to deal with
proper timeouts.

Change-Id: Iee1140e4848923c7270495c381bf87b7e3fddee1
2017-11-27 17:54:03 +08:00
Holger Hans Peter Freyther 65774d447d mobile: Use bool to show started can only be true or false
The state handling is complicated and maybe it gets better by
moving started to bool and then the rest to an enum.

Change-Id: I6aef22e7bf954a8a4ecda980c2c558eb8c9180b7
2017-11-27 09:49:03 +00:00
Holger Hans Peter Freyther 42888ed947 mobile: Switch from printf to LOGP statements
Add a mobile application logging category and replace printf with
a LOGP. The code is sadly still using exit in the middle of handling.

Change-Id: I71e7f6e6375a485b45bad76ada2be17b0901577d
2017-11-27 09:48:39 +00:00
Vadim Yanitskiy 7b64e7dbe9 mobile/vty_interface.c: fix Kc / Ki confusion
Change-Id: Ibbd1d080896b5cadc3d4281fe8f839a103a35088
2017-11-24 20:23:57 +07:00
Vadim Yanitskiy cd9b850ee4 host/trxcon/scheduler: process frames in advance
In order to get the transceiver more time to process bursts,
the L1 scheduler should process the frames and send the bursts
in advance (a few frames before), like OsmoBTS does. By default,
the advance value is 20 frames, but this can be adjusted using a
new command line option of trxcon '-f'.

Change-Id: Ic258a169f3554f931d6277e18ca060d029b77f32
2017-11-23 20:05:16 +07:00
Vadim Yanitskiy 04aecc7f8d fake_trx: correct brief descriptions of files
Change-Id: Ie76fee4a567681a5380be90e5744621c2aa3e5f0
2017-11-21 18:39:11 +07:00
Vadim Yanitskiy eb56da3743 fake_trx: implement a new tool for burst sending
This change introduces a new tool for sending existing bursts from
file or standard input either to L1 (OsmoBTS or OsmocomBB) or to
TRX (OsmoTRX and GR-GSM TRX).

Change-Id: I2c542583252d31daac466e6c7837317fda8a7020
2017-11-21 18:25:48 +07:00
Vadim Yanitskiy 3a395740d3 fake_trx/burst_gen.py: remove unused import
Change-Id: I407877e2025663f706d1a2f93e6228770bfc253c
2017-11-21 17:42:51 +07:00
Vadim Yanitskiy 826c515f4e fake_trx/README: correct the branch name
Change-Id: I9d65580570d9bced65a7bcc95ca073ecc3e130e5
2017-11-21 17:42:19 +07:00
Vadim Yanitskiy be7825d983 fake_trx/ctrl_cmd.py: add help and basic command line options
Sometimes it's important to use different CTRL port, for example
when OsmoTRX is running at the same time. This change adds the
corresponding command line options and help message.

Change-Id: Ic6eeb69d9a1fc151eab2e63f3708e3d70e2e558b
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy e8cf6c4eef host/trxcon: fix: use valid names for FSM instances
Since 8c4f5457 in libosmocore there are some limitations on FSM
and FSM instance names. This change adjusts the names of both
l1ctl_fsm and trx_fsm instances.

Change-Id: Icaaac3f51bdcfe4f7723060179b8730c3a06529b
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy ac764e78fd host/trxcon/scheduler: separate logging of data messages
Change-Id: I3a33687a688db2a183b546425f71c7a0a7030594
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy 5e9959cf6a host/trxcon/trx_if.c: separate logging of data messages
Change-Id: I74ebe0441aeb41c324eafb6b586b2edd9ef4fd1a
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy 3641fe6123 host/trxcon: use LOGP instead of fprintf
There is no (performance) reason to use fprintf instead of LOGP.
Second one provides more useful information, such as a file name
and a line number.

Change-Id: I86dda5b3d746c7802442e4226578a06c04941721
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy f979d44a72 host/trxcon/trx_if.c: fix wrong logging category
Change-Id: I0df0205e160fd9ea5811852077db7c49cddc7e8a
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy e38b500794 host/trxcon/scheduler: fix prim queue flushing function
For some reasons, the function, which is used to flush a queue of
transmit primitives, was intended to flush a list of msgb instances
instead of trx_ts_prim, so memory was being cleaned incorrectly.
Moreover, the items weren't actually removed from queue.

Change-Id: Ia84b57350a5c2eee0afebc65f62e30eaddb141d4
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy 863ccb7bd2 host/trxcon/scheduler: share common declarations of lchan handlers
The training sequences, data / traffic indication and confirmation
helpers are used by several lchan handlers, like xCCC and TCH. It
would be better to have them all declared within a shared header.

Change-Id: I71980f09a0c0e023370e1a651afc24fff2491552
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy fd9aaaf3d0 host/trxcon/l1ctl.c: handle L1CTL_TCH_MODE_REQ
Change-Id: Ib2332e1610fa873755cdfa745153c7b7d4a72a62
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy 28088c8910 host/trxcon/l1ctl.c: include DL frame info in L1CTL_DATA_CONF
The l1ctl_info_dl header is expected to be a part of a
L1CTL_DATA_CONF message, but was missing previously.

Change-Id: Ia8dfaed924fd84395ba9ae539164eaa94f52d30b
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy 3b1a03c310 host/trxcon/l1ctl.c: use primitive management API for RACH
Change-Id: I956ddfc4d1b47575715375c08f46c55953ec5fb6
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy 7d95f8821e host/trxcon/l1ctl.c: share primitive management code
This change introduces shared primitive management functions,
exposed from the l1ctl_rx_data_req() implementation:

  - sched_trx_init_prim() - allocates memory for a new primitive
    and its payload. Initializes primitive's header, setting
    the logical channel type and the payload length. After
    initialization, the talloc context of a primitive is
    a trx instance, which passed as the first argument.

  - sched_trx_push_prim() - decodes the timeslot index from
    chan_nr and pushes a primitive to its transimt queue.
    The talloc context of primitive is changed to the
    parent trx_ts instance after queuing.

Both functions will be used for handling both L1CTL_TRAFFIC_REQ
and L1CTL_RACH_REQ.

Change-Id: I8169a1ef4ef54d91b50f3e213e4842f54af8b499
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy 82b8c21b21 host/trxcon/l1ctl.c: don't fill l1ctl_info_ul into a primitive
The UL frame header isn't used by lchan handlers.

Change-Id: Ia1c63b6f17c3802b29f54299da1151a39edf3a03
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy 8e13093c88 host/trxcon/l1ctl.c: retune TRX only if current ARFCN differs
Change-Id: I797dc284bd92d07ad4859f851a44d048407db86d
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy 14d0f67064 host/trxcon/scheduler: send stored tx_power to transceiver
Previously a fixed fake value (10) was used.

Change-Id: I8ba70bbda6c8c9249f8eb4294aeb41ab8769a19a
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy 17a773c734 host/trxcon/l1ctl.c: fix wrong log level
Change-Id: I0ac65d94b0ae3dd370675318a26a65d11c49cbbe
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy f5bbe5ebfe host/trxcon: separate logging of L1 Control and L1 Data
L1 Data is quite verbose, while Control is typically limited.
And if you would need to debug some Control message handling,
the Data messages wont overflow your terminal anymore. This
change introduces a new logging category named 'DL1D'.

Change-Id: Id830c8bf913f7a8ddc87c47f70a337ee4623abd8
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy 2e062039b6 host/trxcon/l1ctl.c: do nothing if CCCH mode matches
When the L1CTL_CCCH_MODE_REQ is received, we don't need to
reconfigure anything if the current mode matches requested.

Change-Id: Ib8a511e4edd7210b1806f47e83f316be00a8cbb1
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy f28f0d343f fake_trx: whitespace fix
Change-Id: Iad2be36777e4a2454e181c856c7902574a4ab20c
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy a59edfbd40 fake_trx: separate DataInterface from burst_gen.py
Change-Id: I325cf2ae59ef8834c2ddfb67206eede44d1e0acf
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy 1e9501671a fake_trx: add options to specify fn, tn and pwr
Change-Id: Ifd4f4864707596a69fece11218a4800b98551c31
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy f9ab2a0b49 host/trxcon/scheduler: clean up some includes
Change-Id: I47e3b953b80f4f822d563579d15498181009ca80
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy 0dc5b233e6 host/trxcon/scheduler: share common code for lchan handlers
The training sequences array is currently used by xCCH handlers,
but will be also used for handling both TCH/F and TCH/H bursts.
Moreover the code that forwards decoded L2 payloads to L1CTL
protocol handlers was separated into a new shared function.

Change-Id: I34c3de351362ebd9a070f49bb78d7bd976784b04
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy f2179e6763 host/trxcon/l1ctl.c: make l1ctl_tx_data_ind flexible
Now this function can send both DATA and TRAFFIC indications.

Change-Id: I945c10c317155917b6e6ce9d663d9cb46f2e085c
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy c0100cd145 host/trxcon/scheduler: get rid of useless nbits argument
Change-Id: I8508676e2cb347396c6ca6b394f13113f3e63084
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy 8fd143ee5a host/trxcon/scheduler: pass trx_lchan_state to lchan handlers
It's better to pass a trx_lchan_state instance directly from
caller to lchan handler instead of passing trx_lchan_type. This
way a handler wouldn't need to find lchan itself.

Change-Id: I47a40542b03ab31da12b0abb1c263c83662ff018
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy 58c7faf5eb host/trxcon/scheduler: fix chan_nr parsing
Previously, the chan_nr, received from L2, was parsed in a wrong
way, so in some cases only one logical channel was activated or
some messages (such as Measurement Requests) were sent on
incorrect channel (e.g. on SDCCH instead of SACCH).

This change reimplements the sched_trx_chan_nr2lchan_type(), and
introduces a new function sched_trx_set_lchans(), whics will
parse chan_nr and (de)activate required channels.

Change-Id: I480311c65ef93bbc1644ec708dd2a68fd33091e0
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy 18bc7d5e06 host/trxcon/scheduler: ignore incomplete sets of bursts
To be able to decode one xCCH message, it's required to have
all set of bursts collected (4/4). Otherwise we should not
even try to decode an incomplete set.

Change-Id: Iaa63462efe19b8e96102fc8c8d8c968a2df2c70e
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy 5629699996 host/trxcon/scheduler: drop a meaningless FIXME label
Change-Id: If5497f4fdce22e986f46725cc1575a1e809ccdab
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy b4dd3ac9bb host/trxcon/scheduler: use 'tn' instead of 'ts_num'
The new timeslot index designation is more generic for
Osmocom projects, so let's use one.

Change-Id: I8c0118aad439816148490e57938d7e32b6e20877
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy 075c1ad738 host/trxcon/scheduler: git rid of sched_trx_find_ts()
After simplification of timeslot management API this
function does not make sense.

Change-Id: I2fc0c68d784c8f01e1452bc46f8e1eaac2917656
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy 6aa6690277 host/trxcon/scheduler: fix possible NULL deference
We should make sure that required timeslot is not only allocated,
but also configured, i.e. has a correct multiframe layout.

Change-Id: I1d0b870c389802b51c709d089b80ac3fb3565fa8
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy c045bc4fbe host/trxcon/scheduler: simplify timeslot management
As we know the count of timeslots per GSM TDMA frame, it would
be better to have an array of pointers to trx_ts instances instead
of linux list, which is more usable for lists with unknown length.

Change-Id: I9510a5cddde22950ceb8422e0990d59f05ed4d60
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy 539e9a1f18 fake_trx: add a new tool for burst generation
This change introduces a new tool named 'burst_gen.py'. One can
be used for sending GSM bursts either to L1 (OsmoBTS or OsmocomBB)
or to TRX (OsmoTRX and GR-GSM TRX). Currently it is only possible
to send random bursts of different types: NB, FB, SB, AB.

Change-Id: Ie14281222d29536b8690517e57af2a1007fcbc91
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy d497bc8288 fake_trx: add copyright message to clck_gen.py and ctrl_cmd.py
Change-Id: Ia79279dd9e85d131d66d790f1f3fd64fb1914f58
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy 026ed14c4b host/trxcon: adjust default verbosity level
Change-Id: I91258091b59e5cdd30b767364fb48c3d67980eb7
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy 2001221d75 host/trxcon/scheduler: optionally reset clock counter
Change-Id: I4565620fc0c5f64133c2674d2c972fc34245cf32
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy 00bb1d5a79 host/trxcon/scheduler: implement sched_clck_reset()
It's better to have the clock management API inside a single file.

Change-Id: I92772f3db404e70fdffd530779613196afec61c9
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy e6acd7bd07 host/trxcon: get rid of useless TRX_EVENT_RESET_IND
Change-Id: I2aa4c000b37f64c351a806711b2d19bf27ef82bd
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy 806e528bd1 host/trxcon: don't flush trx control messages on reset
Change-Id: I0851f168adeb012a933c796c4180ef507b1c57ec
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy b30031356c host/trxcon: get rid of useless trxcon fsm events
Both SCH_EVENT_CLCK_IND and SCH_EVENT_CLCK_LOSS were not handled,
moreover there is no purpose to keep them.

Change-Id: I8efac459a40f4287e3325890809991d5ef46e9b1
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy 10fd43e586 host/trxcon/l1ctl.c: reset FBSB expire timer on shutdown
Change-Id: If3c8a34f0c1105c6acbfe4f9233482a31f6558de
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy 6c3ce20d75 host/trxcon/l1ctl.c: handle L1CTL_PARAM_REQ
Change-Id: I5c23520dc0f19147b41ad2e13681bf0a62e9facd
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy 4fa6694006 fake_trx: don't send clock indications to mobile stations
Clock indications are only required for BTS, while MS can
obtain current frame number from messages on DATA interface.

Change-Id: Id2993847a3581cac0d355850ad09ceabc6116d3f
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy 17481e2b88 host/trxcon/trx_if.c: get rid of CLCK interface
Local clock counter can be corrected using frame number values,
obtained from burst header on DATA interface.

Change-Id: I5a813e3dc1b960831343b8ecb80718291f20e80d
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy 9760a84a6d host/trxcon: split sched_lchan_handlers.c
It would be better to have xCCH, SCH and RACH burst handlers
in separate files, because as much code we add to a single
file, as harder it becomes to read and understand one.

Change-Id: I456a60e68b32b792e63dd03ae97159dc101fd4bf
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy f604869944 host/trxcon: share trxcon fsm and talloc ctx via trxcon.h
Change-Id: I9ef558f84a6dc1c9b8fc394c48e108676fa169f8
2017-11-19 17:35:07 +07:00