Commit Graph

136 Commits (master)

Author SHA1 Message Date
wbokslag c0956b968f Added crypto support
Added TETRA cryptographic primitives (TEA1-3, TAA1 minus TA61).
If a keyfile is loaded (using -k flag), matching signalling frames
will be decrypted. No support for traffic or identity encryption
yet. Based on

Change-Id: I0c0227cf5b747bd5032602390175b898173f6ae6
2023-09-02 08:54:40 +00:00
sq5bpf c69d2318bd add the gnuradio 3.10 demodulator and receiver from telive
Change-Id: I81f20fa115822b3ad642b638f6414d8249a8ac6a
2023-08-27 21:55:10 +02:00
wbokslag e9c2df9085 Added functions that prepare for decryption
Added functions that will eventually allow for mac resource decryption,
voice/traffic decryption and identity decryption. Calls to the true TEA
keystream generator functions and TA61 identity decryption function
will need to be added in a later patch.

Change-Id: I4e6147f206ad6046f32e08015ec9721b64382ca1
2023-07-29 13:11:52 +02:00
wbokslag 86796c6c4a Fixups and clarifying comments for msgb tail modifications
Added fixups for msgb len field whenever the tail is modified
Also, added some clarifying comments

Change-Id: Ia725edbeafe26bd2ea9b5a1810d0b26bc79d84db
2023-07-29 11:48:22 +02:00
wbokslag b94430b03f Added keyfile loading
Added an additional command line flag -k to tetra-rx that allows for the
loading of a file containing network and key definitions.

Change-Id: I65b7ac8feb3c2a9a8cac95149f625e9ef534b66c
2023-07-28 17:04:28 +02:00
wbokslag 428f541f65 Added keyfile parsing code and various crypto improvements
Added keyfile parsing code, as well as various other improvements such as definition/enum updates and freeing the tetra_crypto_context when done

Change-Id: I1c7afeeb2dcf97ece44bb4b604f44ba88882b93f
2023-07-28 17:00:05 +02:00
wbokslag 6a95eae91e Fixed makefile to also clean crypto subdirectory
Change-Id: Ib2a404edece89d26d5369f4ff2ad7510611cac08
2023-07-28 15:10:34 +02:00
wbokslag e3f1aa97e1 Added calls to stub decryption functions for MAC resources
The tcs (Tetra Crypto State) struct now maintains information relevant for decryption, such as the current network, colour code, hyperframe, etcetera.
Also, the upper mac now calls a stub decryption function when receiving an encrypted resource.

Change-Id: I92d718789d6b7e84c1901d09165fce59cdf8c1ca
2023-07-27 20:51:10 +02:00
wbokslag 3f22796cae Added first steps towards tetra crypto support
A crypto folder has been added containing only a single c and h file at the moment. These files contain structs and high level functionality pertaining to TETRA crypto support which can be added in future patches.

Change-Id: I63bc712630ae5dbaa049c129d456f7aef5bda863
2023-07-27 20:38:31 +02:00
wbokslag affab933cf Added support for slot stealing
Slot stealing is how a traffic slot can be partially or fully "stolen" by a control channel. This patch adds support for that and maintains the stealing status in the tetra_mac_state. This can be used to prevent passing a signalling half slot to the voice decoder.

Change-Id: I01a112e6e74f75401649d358b8f98c6248d2522b
2023-07-26 17:37:52 +02:00
wbokslag 167c2d7e9a fixed import warnings for stdbool on some gcc versions
Change-Id: I979a95eae70d839e20434cc7f08c196c162671a8
2023-07-26 16:59:57 +02:00
wbokslag 615146270f More robust bounds checking on llc pdu parsing
We now have a list containing the lengths of the different llc pdu type minimum lengths
Before parsing the pdu, we validate the l2len is indeed sufficient to contain the pdu
This prevents out-of-bounds reads for corrupted packets.

Change-Id: I118ba2227a22afd295fffaa51aab3e45e85ff3d7
2022-09-22 11:46:35 +02:00
wbokslag 372b1b272c Reformatting to prevent linter warnings
Change-Id: I0dc35e7d536900b4beed19042183838857b7dac7
2022-09-22 11:46:35 +02:00
wbokslag 8a4542a77f added support for advanced link defragmentation
the rx_tm_sdu and rx_tl_sdu did not belong in tetra_upper_mac and are removed. Instead, we use rx_tm_sdu in tetra_llc.c, who in turn invokes rx_tl_sdu in tetra_mle.c. The llc can now also make use of the advanced link defragmentation code that was already there but unused.

Change-Id: I294c684e97c55876f1a207a7152a83dad4ebaa26
2022-09-22 11:46:35 +02:00
wbokslag 1056d5986b Added support for BL-ACK, work on advanced link, small improvements
BL-ACK with and without FCS are now supported
Various improvements for advanced link parsing
tetra_llc_pdu_parse now prevents further out-of-bounds reads by setting the tl sdu length to 0 whenever the tm sdu was too short for proper parsing

Change-Id: If31858a16611ab7853e3ab840704dd2d9657a2a8
2022-09-22 11:46:35 +02:00
wbokslag 6108c35f74 only compute filter when opt_afc is enabled
Change-Id: Icc42a70b07600267ccfad3969b738b3b4a606a61
2022-09-22 11:46:35 +02:00
wbokslag 79560cbf86 Support parsing of multiple mac resources in the same timeslot
Change-Id: Ic2956a5f10cffe296b76a290a0d16f45461eb2e7
2022-09-22 11:46:35 +02:00
wbokslag 1f48ec8627 added support for fill bits and basic link defragmentation (also thanks to SQ5BPF)
The upper mac now maintains a defragmentation buffer for each timeslot. Resources with length -1 (fragmentation start) are added to the buf for that slot, further mac/frag frames are appended. When a mac/end is encountered, the reconstructed l2 message is passed to rx_tm_sdu. The tetra_llc_pdu struct now uses a uint32_t for tl_sdu_len in order to account for the possibly longer sdus. Fill bits processing was required in order to reliably determine the end of a MAC PDU.

Change-Id: I41c9438b0b12c2fac9dff1b226eec5b33f30fbb4
2022-09-22 11:46:29 +02:00
wbokslag 1b7ebde55d Keep timeslot number in range 1-4 instead of 0-3 in parsing of SYNC frame
According to the tetra_tdma_time struct definition, the tn should be in range 1-4. Also, tetra_burst_sync_in increments the timeslot number when in a synchronized state. The timeslot is then normalized with normalize_tn which also expects the tn to be within the 1-4 range.

Change-Id: Ib0967fdeef3bf37c612124626a74d240aa571a66
2022-09-18 15:16:51 +02:00
wbokslag 16713cab01 when traffic dump directory is specified, now prints error message and exits instead of crashing when traffic file cannot be written
Change-Id: I273e07aefd9faea13662f6699a6f3b074c8efe88
2022-08-09 17:28:31 +02:00
sq5bpf f258b1d7d7 Added basic AFC as implemented by SQ5BPF into float_to_bits.c
The AFC implementation by SQ5BPF as used in his fork of osmo-tetra significantly increases reception quality. A simple test yields 14545 valid CRCs as opposed to 11934 when AFC is not used.
I added the AFC to float_to_bits, the functionality can be activated with the -a flag.

Change-Id: I1c9343b83739108a1e423c4880e1dc7964656529
2022-08-04 09:32:06 +02:00
wbokslag d5bfc8e74a keep track of which block of a downlink burst is being processed
tp_sap_udata_ind now accepts a parameter designating from which block
(first or second) of the downlink burst the bits originate (not
applicable for all downlink burst types). In some cases, the upper mac
needs this information, see ETSI EN 300 392-7 clause 6.4.1

Change-Id: I5ff316a773906328e19c3530b09d7412f9c731ec
2022-08-02 13:22:30 +02:00
wbokslag 3fba49ead4 Added basic link FCS validation in LLC
tetra_llc_pdu.c now parses the FCS (Frame Check Sequence) for basic link pdus
that use it. Some changes were made to the tetra_resrc_decoded struct
definition. The have_fcs field designates the FCS was present, while the FCS
field holds the extracted FCS, and FCS_invalid designates an FCS was present
but differs from the computed value.

Change-Id: I81941110801d00ca06bdafdcc0a7afaf7b7617d3
2022-08-02 12:49:39 +02:00
wbokslag a5bc24792b Improved parsing in macpdu_decode_resource
fill_bits and grant_position bits are now parsed and stored in the tetra_resrc_decoded struct
A flag is_encrypted is set to to true if resource was not encrypted or if the calling function
states that the frame has been decrypted successfully before passing it to tetra_resrc_decoded.
Lastly, the channel_alloc element is only parsed if the frame is unencrypted.

Change-Id: I6c85c93b70a34e01fd1a96a863f0e113be6424d3
2022-08-02 12:32:55 +02:00
wbokslag 6dfb41681c moved variable declaration to prevent compiler warnings
Change-Id: If9a83589b220ae7d937ef75c79de57be11858cd1
2022-07-29 12:42:10 +02:00
wbokslag 1feba505bb fixed out of bounds write to pdu_sync buffer
Change-Id: I414bf2d61dc1cb37d30dc84b401a75b918116bbb
2022-07-29 12:42:06 +02:00
wbokslag f0c5f795af added missing switch statements to suppress compiler warnings
Change-Id: I02f7b1875e5501f6977638130c8c5b8c8634fe4e
2022-07-11 15:10:59 +02:00
wbokslag 22b190ef5f Added missing return value
Change-Id: I53d0e75c14933fae30257f8a4cc76df0f3bcd642
2022-07-11 14:40:10 +02:00
wbokslag 627959b4ba added brackets; fprintf was erroneously not guarded by if statement
Change-Id: I2e8c365ee261bde998a69f0f3531dfe6f3ec49c7
2022-07-11 14:29:43 +02:00
wbokslag 8ab1283296 Created tuntap.h to allow for proper use of tun_alloc in tetra_llc.c
Change-Id: If920c15e4dafb48d5df70ce20532ecb19bd01ee3
2022-07-11 14:26:51 +02:00
wbokslag bdc9b28693 ensure zero termination of tun device name
Change-Id: I4b783c6b98ddfb30a4ca4532ef8cffa8e5f3a12f
2022-07-11 14:22:27 +02:00
Harald Welte 472260475b update git URLs (git -> https; gitea)
Change-Id: If7ebc0ef0d82cdad8094f4b6d17f4e477f3189ed
2022-06-18 13:50:02 +02:00
Harald Welte b94f26929f fix memory leak in tetra_gsmtap_sendmsg()
gsmtap_sendmsg() may return an error, and we need to free the msg.

Likewise, if we don't even call gsmtap_sendmsg, the msgb must be free'd.

Change-Id: I9b018165982996cafb2fd17e89646177462002c6
Depends: libosmocore I106b09f2a49bf24ce0e8d11fd4d4ee93e9cafdf5
Related: OS#5329
2021-11-25 15:58:29 +01:00
Martin Hauke d71027873e Fix typos
Change-Id: I1aae0a52fcf978900fa847a3f813beb2a5ad4a84
2019-07-17 22:50:49 +02:00
Jan Hrach 73e9e0e871 add traffic dumping patch, use getopt to parse arguments
Enable the user to specify a directory, where contents of traffic channel will
be saved. Together with this dump, a text file with SSIs of the engaged
stations is saved too.

Based on 0004-HACK-Quick-hack-to-save-the-speech-data-from-TCH.patch available at

Change-Id: I94135753a76cadfa373167ffca18e89bee5bcff8
2018-09-28 23:27:20 +00:00
Jan Hrach 22bb16dfa4 phy/tetra_burst.c: use bitwise operations to speed up synchronization
Finding synchronization sequence eats several times more CPU time than the
actual decoding. This is especially pronounced on channels with lots of errors
(where synchronization is lost frequently) and channels that are most of the
time empty (such as uplink channels, support for which is coming in following

Profiling shows that all the time is spent in memcmp calls.

A complicated and efficient algorithm, e.g. Aho-Corasick, turned out to be
not necessary. Compilers can optimize even a simple bit filter into fast code.

This provides only a modest (~25 %) performance gain, more fixes are coming.

Fixes: OS#1897
Change-Id: I3b90cc70c2ec67253a0fd2f00c6957a80971c38b
2018-08-06 12:21:19 +00:00
Jan Hrach 013ef6e8a1 update scrambling only if we have good CRC
When a bad frame is received, the scrambling should not be updated,
because setting scrambling to wrong values will completely break further
decoding (until another SYNC frame is received).

Change-Id: I5e88b52fcbb98532d7ab6ca85e4f956589a595ab
2018-07-31 06:58:51 +00:00
Jenda 05fa2d54bb Makefile: -O3 and debug build
Build standard builds with -O3.
Add a "debug" target with -Og and asan.

Change-Id: Ie943babb808ffdb1d807bcd7ce4ace54723b49a9
2018-07-30 21:41:08 +02:00
Jenda 9514389ef5 add script for testing performance and number of correctly decoded frames
Change-Id: I6d8030969eed4519520745207591ce4731939201
2018-07-30 21:38:07 +02:00
Jan Hrach 2c19f9856a Make viterbi decoder deterministic in case of bit errors / too few symbols
Running tetra-rx on a capture with lots of bit errors is not
deterministic. Investigation with Valgrind shows various errors about
uninitialised values in libosmocore's viterbi decoder.

The cause appears to lie in @lower_mac/viterbi.c@. The only function
there allocates space for 864 symbols and then fills it with the symbols
received. However, sym_count is sometimes less than 864, leaving the
rest of the array uninitialized.

Initializing it with @int8_t vit_inp[864*4] = {0};@ fixes the problem.

Change-Id: Ib745c387e21fb81afef69efcf7e46d5d49331c8f
Fixes: OS#3410
2018-07-21 10:29:20 +02:00
Neels Hofmeyr f51afec8fa jenkins: use common and
Since the gerrit build jobs no longer contain git clean workspace config (for
good reasons), it is important to use To make it work
best, this should follow the same structure as most others do.

Change-Id: I3eca957c52b2c018e4c784b29330a0d06c4e3595
2017-10-30 05:01:41 +01:00
André Boddenberg cb4bd6d45f Introduce contrib/ to align with other projects
This change will make jenkins' inline scripts obsolete,
so build testing and gerrit verification jobs [1][2] simply invoke:

  $ ./contrib/


Change-Id: I517e1be8b5680c3cc274fd5ad13ac7c920154e7f
2017-09-19 11:21:28 +00:00
Harald Welte 4f3adac31f Add general information about the project
Change-Id: I3e187676a2c1ceb305f97e95d906659609135068
2017-03-16 20:37:42 +01:00
Harald Welte fcbb5b7692 reformat README file as markdown
Change-Id: I7b2602fa1614cafcfb6e6c4fad0d15ba183b0d1d
2017-03-16 20:34:20 +01:00
Harald Welte 0ca867eda2 remove old gnuradio <= 3.6 demodulator code
keeps some of the device specific scripts in addition to the (supposedly

Also, update the README file to corresponding changes.

Change-Id: Icae93bb9a6a7219e14931fb6e04a4c6fffa0779d
2016-12-18 17:10:10 +01:00
Harald Welte 409d2985cb demod: Import the new GR 3.7 code
This adds demodulator code compatible with gnuradio 3.7 series.

Change-Id: Ibaf7f9c552cc1625210a75f2e9ec142ab47ce8d6
Signed-off-by: Sylvain Munaut <>
2016-12-18 17:06:32 +01:00
Antonio Eugenio Burriel 359ef6ba24 Fix ETSI reference codec's patch for building on 64 bit architectures.
merged/ported to osmocom master by Harald Welte

Change-Id: I6b16811d4a3030dfce0718f0b1d266ee1761bfef
2016-12-18 16:21:35 +01:00
sq5bpf 043cc0e506 Add patches for codec static linking and logging to stderr
Change-Id: I41b32e38c08152e608f20af44db4456ca59169eb
2016-12-18 16:11:22 +01:00
sq5bpf 44956fef8d Update the Codec Download instructions and include a shell script
Change-Id: Ia943a38e422e23e70f73d9672554633c014f6da7
2016-12-18 16:10:23 +01:00
sq5bpf 871782e445 Add, a simple demodulator without GUI
Change-Id: Ibad17350db1b00f87955684e4cc17e0a5e8ea6de
2016-12-18 15:37:33 +01:00