Commit Graph

1459 Commits

Author SHA1 Message Date
Vadim Yanitskiy eb1e0fa859 bts: cosmetic: use DUMMY_VEC for padding where possible
Change-Id: I725a7bd1b0c4d2b0d73f1b6d1f16543bf3d9d9fe
2020-07-18 20:33:49 +07:00
Pau Espin 5935707489 pdch.cpp: Store TLLI promptly on newly created TLLI in rcv_resource_request
The TLLI is tried to be updated later anyway during tbf_alloc_ul(), but
this way it's clear that information is stored where it belongs as soon
as possible. The change already shows clearer log lines in TbfTest.err.

Change-Id: I20ce4eb94ecf85ce2835275d0056d9ecd1b558c3
2020-07-09 13:40:55 +02:00
Pau Espin 9e7361a8ba pdch.cpp: Fix wrong annoying log line about non-scheduled ResourceReq received
It's perfectly fine receiving a Resource Request message under some
circumstances (as stated in the comment added in the commit).

To print issues only under non-expected circumstances, the function
rcv_resource_request need to be refactored:
* Destroying older UL_TBF is delayed because it is needed further
  down.
* When the old UL_TBF is FINISHED, it's an acceptable time to receive a
  Resource request, so we check if that's the case and don't print a
  warning in that case.

Change-Id: I4b4367126d6a16055cd2f45afc4a6b9c15a7c980
2020-07-09 13:37:15 +02:00
Pau Espin bcb226d607 pdch.cpp: Avoid resetting (egprs_)ms_class to unknown if not found in MS RadioAccCap
If the information is not found in the message, 0 (unknown MS class)
will be returned. If the MS already had some previous information on the
MS class, let's not lose it by setting it back to 0.

Take the opportunity to drop related log lines which are no needed,
since set_(egprs_)ms_class() functions already log the value changes.

Change-Id: Icd52209fd4395d78dc770e7869d1b1fe45a18ca0
2020-07-09 13:37:15 +02:00
Pau Espin 85faa762c3 pdch.cpp: Avoid dropping existing DL TBF during rcv_resource_request
There's no real good explanation on why the DL TBF is dropped there,
since PKT RESOUCE REQUEST is used basically during UL TBF establishment.
Also, as decribed by TS 44.060 11.2.16 "Packet Resource Request":
"""
This message is sent on the PACCH by the mobile station to the network
to request a change in the uplink resources assigned.
"""

Change-Id: Iab4afb66f0d671f7ad54909d2685a1613e12ab4d
2020-07-09 13:37:15 +02:00
Pau Espin f2c6c83816 encoding.cpp: Fix missing spacing in function param
Change-Id: I4f30a0cea615d57cd7783a92ae782790c8075a6c
2020-07-09 13:37:15 +02:00
Pau Espin 732373d7b4 encoding: Encode TA as unsigned and check validty against GSM48_TA_INVALID
According to 3GPP TS 44.018 sec 10.5.2.40, Timing Advance value is 8 bit
and range is 0-63 (0-219 on GSM400). Unsigned value (uint8_t) is used
everywhere else, so avoid using a signed one here, and simply check for
GSM48_TA_INVALID here, which we use everywhere else to initialize when the
value is not known. Ideally we should check for value based on band, but
it makes more sense to check that when receiving the data and storing in
in set_ta().

Change-Id: I82b13561d0fe5ebafb5c3a8b9a501045c29809bc
2020-07-09 13:36:47 +02:00
Pau Espin 26743ac4f9 tbf_dl: uint8_t is enough to store a TA value
According to 3GPP TS 44.018 sec 10.5.2.40, Timing Advance value is 8 bit
and range is 0-63 (0-219 on GSM400). So there's no need for 16 bits to
store it. uint8_t is used in all other places in the code.

Change-Id: I38aa063ae30ca5680fef6252d2cef22cea98c123
2020-07-07 17:18:14 +02:00
Pau Espin f861d312fe decoding.cpp: Improve logging in malformed UL data parsing
Change-Id: Ic4ad14b88fddde8d9e62e0a2587b501d36821f01
2020-06-30 21:33:49 +02:00
Pau Espin 72e395656d Set correct GSMTAP channel type for PDTCH messages returning error
For instance, that may happen because the len of the message is not
filling the expect size (because padding is missing for example). Still,
in this case we know the channel type, so we set it so that wireshark
tries to decode the message as a data one.

Change-Id: Ifea94095d669b528874e64ca823a776cd6e22b4b
2020-06-30 18:34:58 +02:00
Pau Espin 259532fcf9 pdch.cpp: Fix logging line format in rcv_block wrong length
Change-Id: I2f818021cef41ab6f4569cd87026072811853352
2020-06-30 17:48:45 +02:00
Pau Espin d21e961a8b tbf: Drop unneeded method set_tlli_from_ul
Since commit 322456ed47 (and previous
one), it is expected that a tbf object ALWAYS has a MS object referend
to it, even if it's a temporary copy which will later be merged when
TLLI/IMSI is retrieved and it is found that several MS objects relate to
the same MS.

The purpose of set_tlli_from_ul was mainly to update TBF's ms() to
old_ms before going through usual tbf->update_ms() path. That's not
really needed since ms() is already always set and TBFs for old_ms are
already freed in update_ms() and children function.

Change-Id: Ie8795e7a02032336e53febb65c11f9150c36d2a0
2020-06-26 14:35:01 +02:00
Pau Espin cbf05f5146 gprs_ms: Transfer known EGPRS MS class when mergling old MS
Since not all the the information about the MS is known during TBF
creation in all scenrios, it may happen that when TBF is created it
creates a MS which later will end up being found a duplicate of an
already previously existing MS.
At that point, the old object is dropped and information retrieved from
both is merged into the new one.

The GPRS MS class was being transferred, but the EGPRS MS class was missing.

Change-Id: Ieb9929b60254b12f79392d6acb8b456d71cccb9e
2020-06-26 14:16:50 +02:00
Pau Espin 43f0bce253 gprs_ms: Small clean ups in IMSI storage related code
Change-Id: I987af0d33b79302c037d062c9d1c828a0e027147
2020-06-26 13:09:44 +02:00
Vadim Yanitskiy 81b610ea2c bts: fix send_gsmtap_rach(): properly pack 11 bit RA
According to 3GPP TS 44.004, section 7.4a, two alternative RACH
block formats are specified: 8 bit (1 octet) and 11 bit. The
bit order is LSB (right to left), byte order is MSB.

In PCUIF RACH.ind structure (see gsm_pcu_if_rach_ind) we use
a field of type uint16_t to store RA values regardles of the
block format. Thus when packing it to bytes, we cannot just
cast uint16_t* to uint8_t*, we need to do some bit shifting.

Change-Id: I08a0a908f855b0d8a002df732e02781126d27dfb
2020-06-11 01:29:40 +07:00
Vadim Yanitskiy 07b6487c5a bts: add send_gsmtap_rach(), also send PTCCH/U over GSMTAP
Change-Id: I5cc4c3d2522215a31924121f83fcc2ac9ac6fe9c
2020-06-11 01:29:12 +07:00
Vadim Yanitskiy b90d34b3d1 BTS::parse_rach_ind(): properly handle EGPRS Packet Channel Request
Let's finally use the API we introduced in [1].

[1] I96df3352856933c9140177b2801a2c71f4134183

Change-Id: Ia15761c33c8048d35c7f7bc93dbea781dd0894b7
Related: OS#1548
2020-06-03 12:49:40 +00:00
Vadim Yanitskiy a0a0b7fb0e bts: refactor handling and parsing of RACH.ind
This patch is a set of tightly related changes:

  - group all RACH.ind parameters into struct 'rach_ind_params';
  - group Channel Request parameters into struct 'chan_req_params';
  - get rid of egprs_mslot_class_from_ra(), priority_from_ra(),
    and is_single_block(), introduce unified parse_rach_ind();
  - improve logging, get rid of redundant information.

This is needed for proper EGPRS Packet Channel Request handling.

Change-Id: I5fe7e0f51bf5c9eac073935cc4f4edd667c67c6e
Related: OS#1548
2020-06-03 12:49:40 +00:00
Vadim Yanitskiy 4c593c8c8a encoding: fix write_ia_rest_egprs_uplink_sba(): add missing CHECK(rc)
Change-Id: I8e41c2912aaff689b0e311c8e2d3e961d2f1ac2c
2020-05-25 09:15:09 +00:00
Vadim Yanitskiy a2d972a38a RLC/MAC: implement decoding of EGPRS Packet Channel Request
According to 3GPP TS 44.004, section 7.4a, two alternative RACH block
formats are specified: 8 bit (1 octet) and 11 bit. This change adds
CSN.1 definitions for 11 bit EGPRS Packet Channel Request as per
3GPP TS 44.060, table 11.2.5a.2.

Change-Id: I96df3352856933c9140177b2801a2c71f4134183
Related: OS#1548
2020-05-23 19:38:35 +07:00
Vadim Yanitskiy 3f2022e2cb encoding: cosmetic: use RLC_MODE_ACKNOWLEDGED where possible
Change-Id: Ic69d120f622f512f05016596bfdd4a89b96e3e3b
2020-05-23 19:28:03 +07:00
Vadim Yanitskiy 93ad3fd9b9 csn1: fix: never use enumerated types in codec structures
I faced a problem while working on EGPRS Packet Channel Request
coding support: the unit test I wrote for it was passing when
compiled with AddressSanitizer, but failing when compiled
without it o_O. Somehow this was observed only with GCC 10.

Here is a part the standard output diff for that unit test:

   *** testEGPRSPktChReq ***
   decode_egprs_pkt_ch_req(0x2b5) returns 0
  - ==> One Phase Access
  + ==> unknown 0xdd5f4e00
   decode_egprs_pkt_ch_req(0x14a) returns 0
  - ==> One Phase Access
  + ==> unknown 0xdd5f4e00
   decode_egprs_pkt_ch_req(0x428) returns 0
  - ==> Short Access
  + ==> unknown 0xdd5f4e01

At the same time, debug output of the CSN.1 decoder looked fine.
So WYSINWYG (What You See Is *NOT* What You Get)! As it turned
out, this was happening because I used an enumerated type to
represent the sub-type of EGPRS Packet Channel Request.

  typedef struct
  {
    EGPRS_PacketChannelRequestType_t      Type; // <-- enum
    EGPRS_PacketChannelRequestContent_t	  Content;
  } EGPRS_PacketChannelRequest_t;

The problem is that length of an enumerated field, more precisely
the amount of bytes it takes in the memory, is compiler/machine
dependent. While the CSN.1 decoder assumes that the field holding
sequential number of the chosen element is one octet long, so its
address is getting casted to (guint8 *) and the value is written
to the first MSB.

  // csnStreamDecoder(), case CSN_CHOICE:
  pui8  = pui8DATA(data, pDescr->offset);
  *pui8 = i; // [ --> xx .. .. .. ]

Let's make sure that none of the existing RLC/MAC definitions is
using enumerated types, and add a warning comment to CSN_CHOICE.

Affected CSN.1 definitions (unit test output adjusted):

  - Additional_access_technologies_struct_t,
  - Channel_Request_Description_t.

Change-Id: I917a40647480c6f6f3b0e68674ce9894379a9e7f
2020-05-23 19:26:58 +07:00
Vadim Yanitskiy 0614e9333f csn1: fix csnStreamEncoder(): always check the choice index
It's so easy to pick an out of bounds value otherwise...

Change-Id: I12f5ab739b97f1f3b5d4bed1b5a4a661c879e89f
2020-05-23 18:00:53 +07:00
Vadim Yanitskiy fac8332649 csn1: fix csnStreamEncoder(): also check length of the choice list
Similar checks are done in csnStreamDecoder(), so better check than sorry.

Change-Id: I441c716975905a37264efc8a76df92194f39c1fb
2020-05-23 18:00:53 +07:00
Vadim Yanitskiy c9915660ff csn1: fix M_CHOICE: restirct maximum length of the choice list
The current implementation is not capable of handling more than
256 (UCHAR_MAX) selectors in the choice list. Let's document
this and add a guard check to the M_CHOICE handler.

Change-Id: I40c3c5b9be892804c6cd71cbb907af469ce5d769
2020-05-23 18:00:53 +07:00
Vadim Yanitskiy 6fd4733041 l1if: fix: s/pcu_rx_rach_ind_pdtch/pcu_rx_rach_ind_ptcch/g
This is not a functional change, just fixing misleading function
name. Access Bursts on PTCCH/U have nothing to do with PDTCH.

Change-Id: I4ab710ba026315301cc6970263967616401a9fc8
2020-05-22 21:09:22 +07:00
Pau Espin 0b0391ff66 gsmtap: Set signal level and SNR fields
lqual (containing C/I value) is passed instead of SNR, but let's have
that better than nothing.

Change-Id: Ibe9502d42c8bd1b984069e7fd805dde87ecbab0c
2020-05-20 14:20:56 +02:00
Pau Espin 2ae8337669 Get rid of class GprsCodingScheme
We have same kind of object splitted into two layers, in coding_scheme
and gprs_coding_scheme. Let's merge them together and get rid of the
class, which is not really useful because it's only a set of functions
operating on one enum value.

This change also fixes gcc 10.1.0 error about memseting a complex type
in rlc.h init().

Change-Id: Ie9ce2144ba9e8dbba9704d4e0000a2929e3e41df
2020-05-20 11:07:07 +00:00
Pau Espin c33a024d4a tbf_ul: Fix UL ACK not sent to MS if intermediate UL block is lost
In normal conditions ACKing of UL blocks is only sent every
SEND_ACK_AFTER_FRAMES (20) frames. Which means if CV=0 is received (and
hence no more packets are received) less than 20 frames before a lost,
the PCU won't ask for a retransmission and wait there until some timer
destroys the TBF.

This issue is shown by TTCN3 test PCU_Tests.ttcn
TC_ul_intermediate_retrans.

Unit tests triggering this condition are adapted. Some similar tests are
not triggering it because BSN/CV relation being used is totally wrong
(like CV=0 being sent on a BSN with previous value than others).

Change-Id: I9b4ef7b7277efa645bdb5becf2e9f6b32c99a9b1
2020-05-19 09:30:23 +00:00
Pau Espin 5bb87b83d1 rlc: Move prepare() function out of gprs_rlc_data struct
Newer gcc 10.1.0 is erroring due to memset being applied on a complex
type, so let's start by removing this only function outside of the
struct.

Change-Id: I20426557d9b3049ab275fadb92e10ea8a860a119
2020-05-18 11:07:03 +02:00
Pau Espin c68e97012c rlc: Drop unused function gprs_rlc_data::put_data
Change-Id: I10eb93a1aa6ac1eac15c8e64da300caf2e6ccc44
2020-05-18 11:07:03 +02:00
Pau Espin 7b9e56a500 sysmo: femtobts.h: Avoid redefining global variables
Change-Id: I0f04726ae608f499c557cedffb4d86625bccbd5a
2020-05-18 11:07:03 +02:00
Pau Espin 09afd6f230 pcu: tbf_ul: Clean up maybe_schedule_uplink_acknack()
Get rid of checking all conditions twice, and update one log message.

Change-Id: I95831991b01961e4b7faddb08d27133acb0ab4d4
2020-05-15 17:03:46 +02:00
Pau Espin 97e88fd35f bts: Drop specific functions to add values to stats
Change-Id: I877a9c9a35b6c94c3dd6b1ab3019bc57f6c8568a
2020-05-14 11:19:05 +00:00
Pau Espin a107f8f496 bts: Drop specific functions to add values to counters
It's super annoying seeing lots of functions being called everywhere
only to find out they are only incrementing a counter. Let's drop all
those functions and increment the counter so people looking at code
doesn't see dozens of code paths evyerwhere.

Most of the commit was generated by following sh snippet:
"""
 #!/bin/bash
define_pattern="^CREATE_COUNT_ADD_INLINE"
generic_func="do_rate_ctr_add"
grep -r -l "${define_pattern}" . | xargs cat | grep "${define_pattern}("| tr -d ",;" | tr "()" " " | awk '{ print $2 " " $3 }' >/tmp/hello

while read -r func_name ctr_name
do
 #echo "$func_name -> $ctr_name";
files="$(grep -r -l "${func_name}(" .)"
for f in $files; do
echo "$f: $func_name -> $ctr_name";
sed -i "s#${func_name}(#${generic_func}(${ctr_name}, #g" $f
done;
done < /tmp/hello

grep -r -l "void ${generic_func}" | xargs sed -i "/void ${generic_func}(CTR/d"
grep -r -l "$define_pattern" | xargs sed -i "/$define_pattern/d"
"""

Change-Id: I966221d6f9fb9bb4f6068bf45ca2978008a0efed
2020-05-14 11:19:05 +00:00
Pau Espin 2338e5318e bts: Drop specific functions to increase counters
It's super annoying seeing lots of functions being called everywhere
only to find out they are only incrementing a counter. Let's drop all
those functions and increment the counter so people looking at code
doesn't see dozens of code paths evyerwhere.

Most of the commit was generated by following sh snippet:
"""
 #!/bin/bash
grep -r -l ^CREATE_COUNT_INLINE . | xargs cat | grep "^CREATE_COUNT_INLINE("| tr -d ",;" | tr "()" " " | awk '{ print $2 " " $3 }' >/tmp/hello

while read -r func_name ctr_name
do
 #echo "$func_name -> $ctr_name"
files="$(grep -r -l "${func_name}()" .)"
for f in $files; do
echo "$f: $func_name -> $ctr_name";
sed -i "s#${func_name}()#do_rate_ctr_inc(${ctr_name})#g" $f
done;
done < /tmp/hello

grep -r -l "void do_rate_ctr_inc" | xargs sed -i "/void do_rate_ctr_inc(CTR/d"
grep -r -l "CREATE_COUNT_INLINE" | xargs sed -i "/^CREATE_COUNT_INLINE/d"
"""

Change-Id: I360e322a30edf639aefb3c0f0e4354d98c9035a3
2020-05-14 11:19:05 +00:00
Pau Espin 5dc6e465cb Drop unneeded arg 'ta' in tbf_alloc_ul()
The function is simply setting the ta on the ms, so simply make sure ta
is set on callers before passing the ms object.

Change-Id: Iebb9c57f458690e045ddc45c800209ad8cf621e0
2020-05-14 11:19:05 +00:00
Pau Espin ce60011e77 pdch: rcv_resource_request(): Clarify tbf_free only needed if MS used to exist beforehand
Variable found is used to always call Guard() on MS to avoid possible
unexpected freeing regressions.

Change-Id: I62f24fe04ca10fca19bedda288fe3ed3ce75413f
2020-05-14 11:19:05 +00:00
Philipp Maier de0e558baf gprs_debug: Use only LOGL_NOTICE as default loglevel
The default loglevels of some log categories are configured to
LOGL_INFO. This is still to verbose, lets use LOGL_NOTICE here.

Change-Id: Ibb1cd1a94fb4fdd0147e073f8c1c82562c2c14ef
Related: OS#2577
2020-05-13 16:41:55 +00:00
Pau Espin 322456ed47 Expect ms object to exist before calling tbf_alloc_dl_tbf()
Same as previous commit, this time for the DL counterpart.

Change-Id: I87f6cdf8288a688466020bda0874e68b57aa71c4
2020-05-12 17:09:20 +00:00
Pau Espin 17402a5902 Expect ms object to exist before calling tbf_alloc_ul_tbf()
It's really non-sense from architectural point of view to pass an
optional pointer to the MS holding the TBF and creating it otherwise.
TBFs shouldn't be creating MS they belong too.

This simple change requiring so many code line changes really exhibits
how badly entangled the object relationship is.

Another commit will follow doing the same for dl tbf.

Change-Id: I010aa5877902816ae246e09ad5ad87946f96855c
2020-05-12 17:09:20 +00:00
Vadim Yanitskiy f094b46d1c fix egprs_mslot_class_from_ra(): multislot class may not be present
For more details, see 3GPP TS 44.060, table 11.2.5a.2.

Change-Id: Iba0466b29afd26cff317ed4fb6749f8a3079f16a
Signed-off-by: Vadim Yanitskiy <axilirator@gmail.com>
Related: OS#1548
2020-05-11 20:06:39 +00:00
Pau Espin db9ea55c6e Use OSMO_FD_* instead of deprecated BSC_FD_*
New define is available since libosmocore 1.1.0, and we already require
1.3.0, so no need to update dependenices.
Let's change it to avoid people re-using old BSC_FD_* symbols when
copy-pasting somewhere else.

Change-Id: Ida8fd3bd7347163567acde34ad67aefee913b0ea
2020-05-09 19:18:06 +02:00
Pau Espin e6bca376aa bts: Return uint8_t in egprs_mslot_class_from_ra()
MultislotClass is 5 bit long, so an uint8_t is enough.
In most places we are already storing multislot class as uint8_t.

Change-Id: I1dcaff9d69379453a0b794e5f36b820f5f78531f
2020-05-08 16:37:25 +02:00
Pau Espin 98eb03c391 bts: Fix Decoding EGPRS MultislotClass from 11-bit EGPRS PACKET CHANNEL REQUEST
In osmo-pcu datatructures, the variables holding multislot classes
simply contain an integer referring to the multislot class number,
instead of coding from 3GPP TS 44.060 Table 11.2.5.3 and Table
11.2.5a.3.

So coding Multislot class 3 is stored as 0x03 in osmo-pcu variables,
while in 3GPP TS 44.060 coding it's coded as 0x02 (N-1).
This allows us using value 0x00 to designate a "yet unknown (EGPRS) Multislot
class".
Hence, we need to add 1 to the decoded value to match our data
structures.

Change-Id: Id3b121272bb7e84c0542ae9b4ce09598c6054edd
2020-05-08 16:35:51 +02:00
Pau Espin 9ee90d2323 bts: Rename mslot_class_from_ra
This function is actually returning an EGPRS multislot class, so let's
update naming. The variable using the return value was already being
passed as egprs_ms_class to tbf_alloc_ul_tbf().

Change-Id: Idb51836c8c9dd4e865bf2cb0b0c24155662f2ae8
2020-05-08 16:34:50 +02:00
Pau Espin acd67cbdf1 tbf: Avoid crash: don't set TBF window size if setup failed
Should fix assertion triggered due to the tbf not set up properly
beforehand.

Fixes: OS#4524
Change-Id: I267b147520ef5a50f40ad4bc19e7b5fb3e708127
2020-05-08 13:50:54 +02:00
Pau Espin 20331ae5f6 pdch: Avoid sending GSMTAP_CHANNEL_UNKOWN for rejected UL EGPRS data block
Even if we don't accept it, let's submit GSMTAP with correct channel.
We don't return error like in code below, because otherwise the generic
UNKNOWN gsmtap message will be sent.

Change-Id: I853679ce8907d46fcb84ae4127335c10623f09c9
2020-04-29 21:02:12 +02:00
Pau Espin 3301cc900e pcu_l1_if: Don't use GSMTAP_CHANNEL_PACCH when sending unknown gsmtap blocks
It's actually counter-productive when analyzing wireshark traces, since
one may not spot a decoding issue and assume PACCH is sent on the wrong
TS.

Change-Id: I7a96148f1ca1ebfa88a3ff714ea3bb8798866046
2020-04-29 20:56:31 +02:00
Vadim Yanitskiy 3f27fb56e4 TBF/UL: fix rcv_data_block_acknowledged(): print the actual TLLI
Change-Id: I71b5c656d4b318d11bd5fe2b5d163c3a06e09a6a
2020-04-20 13:18:49 +07:00
Vadim Yanitskiy 72ec18ce5a sba: fix possible memleak in SBAController::alloc()
Change-Id: I417eda155cd5b1e46dd0b05db3f507abd79121d1
2020-04-20 11:25:05 +07:00
Vadim Yanitskiy b30f28f38d l1if: fix pcu_rx_rach_ind(): use proper format string specifiers
Change-Id: If95362ef4cc203a60856d6b47d95d441813a5c19
2020-04-02 05:42:57 +07:00
Pau Espin c374ab00ac csn1: Remove code block from CSN_NEXT_EXIST_LH
It was removed in wireshark.git e8407dd6c1378427daee77e8de540d0b5f7a0b73
and it's not there anymore in current master.

Change-Id: I73f4eeca3fd4f00a5bc4f06ef7a9bb9b8a70e37b
2020-03-30 10:08:02 +00:00
Pau Espin c8280a538a csn1: Properly verify CSN_BITMAP length
Change-Id: I9f7672b534f9345caff99095504749eebad25adb
2020-03-30 10:08:02 +00:00
Pau Espin f5e275aec0 csn1: verify enough bits present to decode whole CSN_UINT_ARRAY
Change-Id: I4a762a8fec4153b53e10df1ec8ba3708c1f47649
2020-03-30 10:08:02 +00:00
Pau Espin 70a211747b csn1: Fix Several typos & whitespace
Change-Id: Ibe31d52d4a5a4015196d73681082f68b99a80c77
2020-03-30 10:08:02 +00:00
Pau Espin 99eb353337 rlcmac: add dissection of 2G->3G/4G PS handover
Port from wireshark.git 428ee66ae1c524b49f9043729b1f1e9b4f52f409, from
Pascal Quantin.

The original commit is also changing the RRC_Container field to
M_CALLBACK, but we leave them as M_VAR_ARRAY since the callback is
basically used to add more dissection information in wireshark.

Change-Id: I0f374e78300efddff00c4df26a401adcdee18a12
2020-03-30 10:08:02 +00:00
Pau Espin f3ac06bbaf rlcmac: support decode FDD_CELL_INFORMATION of "UTRAN FDD Description
Port of patch (+ later fixes squashed) of wireshark.git commit
dea5452b95dfaf18e38670a8e2b3b38f9175fdfd, from Lei Chen:
https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=6856

Squashed wireshark.git fix commits:
774be29de0b4d93d01aecb1518c41d7d551071a9
51c31cd7bd3d8fc196a9f90a8af466ad84e9e6a8
6aca10831f86c562970b13efa811f46e25ee3091
c1ceac58cdb77051e9bd14c1f6f7669cf5779a86

Change-Id: I08523bc1bbdffde479ef974b4c7b56cfa5639591
2020-03-30 10:08:02 +00:00
Pau Espin b2653fe619 Move gsm_rlcmac.cpp -> .c
Original file from wireshark.git (packet-gsm_csn1.c) is being built and
maintained as a C file. There's no real need for us to maintain it as a
C++, and doing so will make both files derive over time (as already
happened). Let's keep it as a C compiler (which btw seems to be more
strict) to make it easier to port patches back and forth wireshark.git.

Take the chance to move some declarations we added to csn1.h to be able
to build it out of wireshark. Let's keep those in a separate header file
to ease looking for differences.

Change-Id: I818a8ae947f002d35142f9f5473454cfd80e1830
2020-03-30 10:08:02 +00:00
Pau Espin 799cf8221a gsm_rlcmac: Disable unused CSN1 descriptors
When switching to C compiler, it will warn/error. Use #if 0 as in the
original wireshark.git epan/dissectors/packet-gsm_rlcmac.c code.

Change-Id: If1be50947c02208f15892d99edeb394fb4f52b75
2020-03-30 10:08:02 +00:00
Vadim Yanitskiy d2e50e7f21 fix: properly include pure C headers from C++ code
Header files included from libosmocore may potentially contain
some language constructions allowed in C but not in C++, such
as type casting. Let's add 'extern "C" { ... }' and be safe.

Change-Id: I7197f7b34f30b49d5397506ce9d67cbf0e2cc196
2020-03-29 01:46:36 +07:00
Pau Espin a0cbde700a tbf.cpp: Include c++ <new> header required for new operator's replacement type
Including the <new> header is required as explained by the c++ specs [1]

osmo-pcu/src/tbf.cpp: In function ‘gprs_rlcmac_ul_tbf* tbf_alloc_ul_tbf(gprs_rlcmac_bts*, GprsMs*, int8_t, uint8_t, uint8_t, bool)’:
osmo-pcu/src/tbf.cpp:1002:39: error: no matching function for call to ‘operator new(sizetype, gprs_rlcmac_ul_tbf*&)’
 1002 |  new (tbf) gprs_rlcmac_ul_tbf(bts->bts);
      |                                       ^

Most of the times this issue is not detected because other STL headers
are already including <new>.

[1] http://www.cplusplus.com/reference/new/operator%20new/

Change-Id: Ie5fb536ae29dcf40e2a0dbe67432bebd61b8c7aa
2020-03-27 15:06:41 +00:00
Vadim Yanitskiy ce160147f4 pdch: cosmetic: use GSM_MI_TYPE_* constants from libosmocore
Change-Id: I1d85c8eded68bc8aa8e90c33b36d335fa775ded2
2020-03-27 14:55:22 +00:00
Vadim Yanitskiy d71c566ee6 pdch: fix packet_paging_request(): properly print paging MI
This problem problem was discovered by the Undefined Behavior Sanitizer:

  pdch.cpp:210:4: runtime error: load of misaligned address
                  0x60c00002abf2 for type 'uint32_t',
                  which requires 4 byte alignment

Do not convert TMSI to number, use osmo_mi_name() from libosmocore.
Also use this function to print other MI types (IMSI or IMEISV).

Change-Id: Icf8836f216793e342b239c8e6645aac1e82bf324
2020-03-27 14:55:22 +00:00
Vadim Yanitskiy 0b25f693b3 BSSGP: fix: properly encode P-TMSI in RR Paging Request
The TMSI/P-TMSI IE in BSSGP PAGING-PS/CS comes without the MI type
header, that must be present in RR Paging Request. Prepend it.

TTCN-3 test case: I7fbec5b2c5c3943a7413417b623f55c135c152d7

Change-Id: I97fd5ffc15a4a58112d7c37c69b7ac42b0741a0e
2020-03-27 14:55:22 +00:00
Vadim Yanitskiy f497412f20 BSSGP: cosmetic use OSMO_IMSI_BUF_SIZE from libosmocore
Change-Id: I2079118100a3422e9c2ee63a5ac74e3ee81080b3
2020-03-27 14:55:22 +00:00
Keith Whyte 2b6acd8873 Don't check ul_control_block before decoding into it.
This patch corrects an error introduced in
6fd8ffb6fe
That commit allowed us to send the data over GSMTAP even
if the Uplink Control Block had invalid content,
that is to say, if decode_gsm_rlcmac_uplink() returned error.

However the check for ul_control_block->u.MESSAGE_TYPE
was place before decode_gsm_rlcmac_uplink()

Change-Id: Ic47602e5c6a13571b92c0a939fc3514110b82444
2020-03-26 23:32:49 +00:00
Pau Espin e5e2f747c3 csn1.h: Fix trailing whitespace
Change-Id: If17d36378fabeb7d22a513b93b0ecfde899df520
2020-03-26 16:03:56 +01:00
Pau Espin 24fa27453f gsm_rlcmac.cpp: Avoid declaring variable in for loop
That's only allowed under C++.

Change-Id: I0da8849a0fb7f9a7ee5e726edea87e91dc411ea8
2020-03-26 16:03:56 +01:00
Pau Espin 980ef1e38b cosmetic: Do not indent header includes inside extern C block
Change-Id: I3091d917a13e45b3aef8e52a53dcafa308581652
2020-03-26 16:03:56 +01:00
Pau Espin 007056e4ad gsm_rlcmac: Use 'struct bitvec' instead of 'bitvec'
The later is only accepted when compiling as c++.

Change-Id: Ib5004643d4eff3bc9d11b66ddaf262f1c0d2aef6
2020-03-26 16:03:27 +01:00
Pau Espin 754b093d16 pcu_l1_if.cpp: Add missing header ctype.h
The file uses the isdigit() function.

Change-Id: Id06ea25969ad9b964b3207479604132d25160f24
2020-03-26 14:49:04 +01:00
Pau Espin de63548f04 rlcmac: Rename field to MS RA Cap2 in Additional_MS_Rad_Access_Cap_t
This fix was spotted by wireshark.git developers while reviewing port of
osmo-pcu commit e50ce6e45c.

Related: https://code.wireshark.org/review/c/36574/
Fixes: e50ce6e45c

Change-Id: Ic5fc3252f61b6a042d9c3def7a6a32b311dd9d9e
2020-03-25 20:26:07 +01:00
Pau Espin 10ec506cc9 cosmetic: rlcmac: Fix comment typo and whitespace introduced recently
Change-Id: Ie56898e11e2c9426393af0f6558d340c454fe6c4
2020-03-25 14:32:30 +01:00
Pau Espin e50ce6e45c rlcmac: Introduce MS Radio Access Capabilities 2 to fix related spare bits
There's two variants for the Ms Radio Access Capabilities.
* The usual encoding with spare bits (usually to fill up to octet boundary)
as defined in TS 24.008 Table 10.5.146
And there's too:
* MS Radio Access Capabilities 2 IE from TS44.060 section 12.30, which is
the same but removing all spare bits, and which is used in messages like
Packet Resource Request and Additional MS RAC messages.

The later is used basically for messages having extra IEs after the MS
Radio Access capabilities IE, since they are encoded immediatelly
afterwards.

So this patch does:
* Adds the expected spare bits (M_PADDING) to MS_Radio_Access_capability_t
* Creates a new MS_Radio_Access_capability2_t without padding
* Updates code to use the new "2" version where needed.

Note RLCMACTest long de/encoding line logs change only because the name
of the struct changes (the "2" is added).

Change-Id: Ibd756f80a03452a651e2771dbc628d701e55ac4b
2020-03-23 19:02:01 +01:00
Pau Espin 20848c3ae5 rlcmac: Log names of de/encoded rlcmac packet types
Change-Id: I6a6e79d7e12cd5e8e969bf0eaa30ddac6b0aa7d3
2020-03-23 19:02:01 +01:00
Pau Espin 7faa5da209 rlcmac: Fix bug receiving RA cap
It seems the assumptions regarding maximum number of RA capabilitites
in one message were wrong. Doing some rough calculations, each RA
capabilitiy value (without extensions) can take around 20ish bits, which
means for a message containing up to 52 bytes that quite a lot of
different values could be theoretically fed in. Let's be safe and
increase the array size to be able to handle all different access
technologies listed in See TS 24.008 table 10.5.146 following
restrictions:
* "The MS Radio Access capability is a type 4 information element, with a maximum length of 52 octets."
* "Among the three Access Type Technologies GSM 900-P, GSM 900-E and GSM 900-R only one shall be present."
* "the mobile station should provide the relevant radio access
  capability for either GSM 1800 band OR GSM 1900 band, not both".

Wireshark requires similar fix (it's not important though because it
currently uses another ad-hoc decoder for RAcap).

Related: OS#4463
Change-Id: I5334eaacfbc238fae8bea50c9e9667c2117f81ff
2020-03-23 19:01:58 +01:00
Pau Espin efad80bfbf csn1: Validate recursive array max size during decoding
This way if CSN1 encoded bitstream contains more elements than what the
defintion expects it will fail instead of overflowing the decoded
buffer.

RA cap struct placed in unit test is taken from a real android phone
sending the value when attaching to the network. Then SGSN sends it back
and osmo-pcu would crash similar to unit test:
*** stack smashing detected ***: terminated
 Process terminating with default action of signal 6 (SIGABRT): dumping core
at 0x4C62CE5: raise (in /usr/lib/libc-2.31.so)
by 0x4C4C856: abort (in /usr/lib/libc-2.31.so)
by 0x4CA62AF: __libc_message (in /usr/lib/libc-2.31.so)
by 0x4D36069: __fortify_fail (in /usr/lib/libc-2.31.so)
by 0x4D36033: __stack_chk_fail (in /usr/lib/libc-2.31.so)
by 0x124706: testRAcap2(void*) (RLCMACTest.cpp:468)

Related: OS#4463
Change-Id: I9fe0e55e0a6a41ae2cc885fba490c1d4a186231e
2020-03-23 15:34:11 +01:00
Pau Espin 81b40cbaf3 rlcmac: Don't pass array element to CSN1 descriptors
This way the macros can be used to access the arrays themselves and
calculate its static size to enable validation later.

In the case of Packet_Access_Reject_t, modify the description to use a
M_REC_TARRAY_1 object to get rid of access to 2nd element. The new
description is the correct one, since the first element is mandatory
according to TS 44.060 Table 11.2.1.

Change-Id: I6f10350d4734360c7a15a702c72b59efd84987ee
2020-03-23 15:29:48 +01:00
Harald Welte 570f9135cd csn1.c: Almost all of the logging is DEBUG, not NOTICE
low-level text decodes of CSN.1 messages certainly are not NOTICEable
events, but rather something used for debugging.

Right now we get various text CSN.1 log output of osmo-pcu in it's
default configuration.  Despite all log levels being relatively high
(NOTICE), we still see those messages as they simply are logged
at the wrong level.

Related: OS#2577
Change-Id: I7b42c9e21ad8d8a5b54e7a3b68490934ce3d3198
2020-03-19 15:09:45 +01:00
Pau Espin de7bb75ccf Use downlink BSSGP RA Cap IE
This commit is basically a revert of
f4bb42459c, which disabled the code. That
commit claimed the SGSN may have providen inacurate or wrong data at the
time, but then it should be fixed in the SGSN.

Related: OS#1525, OS#3499
Change-Id: Ie36ae23203110018d4b5ae47591e0a64989e23a0
2020-03-18 14:01:24 +01:00
Pau Espin 1de6873810 Use clock_gettime(CLOCK_MONOTONIC) and timespec everywhere
We should really be using monotonic clock in all places that
gettimeofday is used right now. Since clock_gettime() uses timespec,
let's move all code to use timespecs instead to avoid having to convert
in several places between timespec and timeval.
Actually use osmo_clock_gettime() shim everywhere to be able to control
the time everywhere from unit tests.

Change-Id: Ie265d70f8ffa7dbf7efbef6030505d9fcb5dc338
2020-03-16 10:31:56 +00:00
Vadim Yanitskiy 29aeb901e4 csn1: fix: do not return 0 if no bits left in the buffer
Both csnStreamDecoder() and csnStreamEncoder() shall not return 0
prematurely if no more bits left in the input / output bit-vector.

Returning CSN_ERROR_NEED_MORE_BITS_TO_UNPACK might make more sense,
however we don't know in advance (i.e. without entering the loop)
whether it's an error or not. Some CSN.1 definitions have names
like 'M_*_OR_NULL', what basically means that they're optional
and can be ignored or omitted.

Most of the case statements do check whether the number of remaining
bits is enough to unpack / pack a value, so let's leave it up to
the current CSN_* handler (pointed by pDescr) if no bits left.

Return CSN_ERROR_NEED_MORE_BITS_TO_UNPACK only if the number of
remaining bits is negative as this is an error in any case.

Change-Id: Ie3a15e210624599e39b1e70c8d34efc10c552f6c
2020-03-11 19:55:55 +00:00
Vadim Yanitskiy 773cb74ec8 rlcmac: fix encode_gsm_*(): do not suppress encoding errors
Change-Id: Ieec8e6e0823c6f6985f9d343af6d503b8fe9e6ab
2020-03-11 19:55:55 +00:00
Vincent Helfre 1145fd263c gsm_rlcmac: improve dissection of MS RA Capability IE
Port from wireshark.git de028e81c53f9c45ccc5adb3bffd2f16ae2017bf

This commit breaks transcoding of the test vectors containing
the MS RA Capability IE due to the reasons explained in [1].

The more fields we add, the longer gets the output of the CSN.1
encoder. This is not critical, since we never need to encode
messages containing the MS RA Capability IE on practice.

[1] Ibb4cbd3f5865415fd547e95fc24ff31df1aed4c0

Ported-by: Pau Espin Pedrol <pespin@sysmocom.de>
Change-Id: Ibb4cbd3f5865415fd547e95fc24ff31df1aed4c0
2020-03-07 05:04:40 +07:00
Vadim Yanitskiy 2679ec0a9f csn1: fix csnStreamDecoder(): skip bits unhandled by serialize()
This change fixes a bug that was reported by Keith Whyte and
confirmed in [1]. The problem is that a user-defined handler
in case of CSN_SERIALIZE may parse only a part of the given
bit-stream, leaving some bits unhandled. This is expected
because the sender (i.e. the MS) may use more recent RLC/MAC
message definitions containing new fields at the end.

Those bits that were left unhandled by serialize() shall not be
interpreted as continuation of the message, they shall be skipped.

Note that the encoded vector in the RLCMAC unit test still does
not match the original one. That's a known bug explained in [2].

[1] If5873355d52d7ddb06c2716154a88d34100f6ab5
[2] Ic46d6e56768f516203d27d8e7a5adb77afdf32b7

Change-Id: Id4cc042fed68fc54aca0355dcb986cab3f6b49ea
Related: OS#4338
2020-03-06 21:49:04 +00:00
Keith Whyte 6fd8ffb6fe Send UL-CTRL Packet to GSMTAP even if we fail to decode.
Move the call to send_gsmtap() before the call to decode_gsm_rlcmac_uplink() as if
the latter returns error we return and never get to see the packet on the GSMTAP.

Change-Id: Ia6af9f40590f28fcae3fef50d9c601d8435412cd
2020-03-05 19:51:06 -06:00
Pau Espin 0daf913e0c gsm_rlcmac: fix Packet_Resource_Request_t: s/Slot/I_LEVEL_TN/
This is how this field is named in Wireshark.

Change-Id: I140443c48af8e4bb1b6279e6de986879b7d9c276
2020-03-02 13:33:23 +00:00
Vadim Yanitskiy b47e53b5fa tests/rlcmac: also verify encoding of MS RA Capability
The main idea of this change is to demonstrate a weakness of the
CSN.1 codec that most likely causes a unit test breakage in [1].

The problem seems to be that the transitional structures, where
the CSN.1 decoder stores the results, do not contain any details
about presence of the optional fields (such as M_UINT_OR_NULL).

In other words, it's impossible to know whether some optional
field is omitted in the encoded message (NULL), or is it just
set to 0. This means that the encoder will always include all
optional fields, even if they're not present in the original
message.

[1] Ibb4cbd3f5865415fd547e95fc24ff31df1aed4c0

Change-Id: Ic46d6e56768f516203d27d8e7a5adb77afdf32b7
2020-03-02 13:33:23 +00:00
Pau Espin 5fc6e010a5 llc_queue::{dequeue,enqueue}() refactor
As seen in OS#4420, setting the MetaInfo.recv_time outside of
llc_queue before calling llc_queue::enqueue() and later on using that
value in llc_queue itself at dequeue time is not a good idea, since it
can provoke errors if the recv_time was not set correctly.
For instance, LlcTest was not setting the value for recv_time on some
test, which ended up with a huge millisec value when substracting now()
from it:
"""
llc.cpp:215:29: runtime error: signed integer overflow: 1582738663 * 1000 cannot be represented in type 'long int'
"""
This issue only appeared when started building on a raspberrypi4.

Let's better set/store the MetaInfo.recv_time internally during
llc_queue::enqueue(). Then, enqueue() only needs the
MetaInfo.expire_time, so let's change its arg list to only receive that
to avoid confusions.

Take the chance to move the llc_queue APIs to use osmo_gettimeofday,
since we need to fake the time now that the API itself sets that time.

Also take the chance during this refactor to disallow passing null
pointer by default since no user needs that.

Finally, update the LlcTest accordingly with all API/behavior changes.

Related: OS#4420
Change-Id: Ief6b1464dc779ff22adc2b02da7a006cd772ebce
2020-03-02 12:05:06 +01:00
Vadim Yanitskiy e60d9c7e9d gsm_rlcmac: fix misleading LOGP statement in decode_gsm_ra_cap()
Change-Id: I48fd701566e1364ce7fccaa3e3a1a0296b932988
2020-02-18 05:30:57 +07:00
Vadim Yanitskiy 1553049226 csn1: use proper format specifier for unsigned integers
Change-Id: I33f86b79e72394bdb7d99762f8ec21d80e06dc30
2020-02-17 19:40:15 +07:00
Vadim Yanitskiy 4b57b6da54 csn1: bitvec_get_uint() may return a negative, use %d
Change-Id: I3cfd66643ec140150a4089b0e1c493d911d3d7d4
2020-02-17 19:40:15 +07:00
Vadim Yanitskiy d8e5e8bb3b csn1: fix csnStreamDecoder(): update bit_offset in CSN_EXIST{_LH}
Found while doing differential analysis (comparison against the
original implementation from Wireshark).

Change-Id: Ibd0b7400d78f7873c2a8d45267332f511b5c6fbb
2020-02-17 18:35:37 +07:00
Vadim Yanitskiy e87066d01e csn1: fix csnStreamDecoder(): always keep remaining_bits_len updated
Found while doing differential analysis (comparison against the
original implementation from Wireshark).

Change-Id: I9f7fa9c3f2f4ff5213dded930cee7ec509b9d799
2020-02-17 18:35:37 +07:00
Vadim Yanitskiy 584daba8e9 csn1: fix csnStreamDecoder(): do not subtract no_of_bits twice
Found while doing differential analysis (comparison against the
original implementation from Wireshark).

Change-Id: Id2a4f03035cd8354d3fba0ad37571453d3986d21
2020-02-17 18:35:37 +07:00
Vadim Yanitskiy 39a65056da csn1: get rid of C++ specific code, compile with GCC
The implementation of CSN.1 codec was taken from Wireshark, where
it's implemented in pure C. For some reason it was mixed with C++
specific features, mostly using references in parameter
declaration. Not sure what are the benefits.

Change-Id: I56d8b7fbd2f9f4e0bdd6b09d0366fe7eb7aa327a
2020-02-17 02:31:15 +07:00
Vadim Yanitskiy 8a87f913bd tests/rlcmac: additionally match debug output of the CSN.1 codec
This would allow us to catch more bugs. Note that I had to remove
printing of pointer address to make the output deterministic.

Change-Id: I1a77441eb957353c919bc73f8e3a2e38f4a383a9
2020-02-17 02:30:58 +07:00
Vadim Yanitskiy 74bc150ab2 csn1: fix existNextElement(): use bitvec_get_bit_pos()
As was discovered recently (see OS#4388), bitvec_read_field()
would never return a negative value because its return type
is unsigned (uint64_t).

We don't really need to get more than one bit, so let's just
use the bitvec_get_bit_pos() instead.

Change-Id: I763a295cd955cd33f542292c85d97ff82f6b49bc
Related: OS#4388
2020-02-16 23:41:26 +07:00
Pascal Quantin fa5f91c05f gsm_rlcmac.cpp: fix global-buffer-overflow error reported by ASAN
Port from wireshark.git f751918476bdde65f2289b86245a3c30dace6730.

Ported-by: Pau Espin Pedrol <pespin@sysmocom.de>
Change-Id: I70d4ff3e137b5fd13d367bd4ea6ab501e81e7a87
2020-02-15 09:28:27 +00:00
Pascal Quantin fb65682d34 gsm_rlcmac.cpp: fix another global-buffer-overflow error reported by ASAN
Port from wireshark.git aa3bbe5aebdc180172e7956719b26199e4784fcc.

Ported-by: Pau Espin Pedrol <pespin@sysmocom.de>
Change-Id: I808ec66011cdfe8e1193298f7fb7e92d25b45be4
2020-02-14 19:42:33 +00:00
AndersBroman 2d075be3b8 gsm_rlcmac: Update : PACKET RESOURCE REQUEST to Release 14.0.0
Port from wireshark.git 07fc801684ebff7aff02505cdb2c120caea846e0.

Ported-by: Pau Espin Pedrol <pespin@sysmocom.de>
Change-Id: Iceb59c58406180bc57fe6eb27127b4d11a0a3df7
2020-02-14 19:38:48 +00:00
Vadim Yanitskiy 5574a58cd6 csn1: fix csnStreamDecoder(): catch unknown CSN_CHOICE values
After the recent changes [1], it was noticed that one of the unit
tests fails. In particular, a decode-encode cycle of Packet
Polling Request produces a different vector:

  vector1 = 49 13 e0 08 50 88 40 13 a8 04 8b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b
  vector2 = 49 13 01 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b
  vector1 == vector2 : FALSE

As it turns out, the original (input) vector itself is malformed
because it contails no valid identity, and thus violates the
specs. The CSN.1 decoder from Pycrate [2] throws an exception
while trying to decode it. I believe we should do the same.

Let's stop decoding the bit stream and return an error in case
if neither of a given list of the choice items matched.

[1] Ia0f8cc224a4c38e80699f834fd83d4c0d99322ea
[2] https://github.com/P1sec/pycrate

Change-Id: I420144773ed5e80372534e0f18db5e74cdb2999d
Fixes: OS#4392
2020-02-11 05:58:44 +07:00
Vadim Yanitskiy fee767f21c csn1: fix some mistaken CSN.1 error names
Change-Id: I3bd9954ee36212c94f0c4d91581da300c56fce60
2020-02-11 05:28:02 +07:00
Vadim Yanitskiy 9a530a2430 encoding: assert return value of bitvec_set_u64()
Change-Id: Ic0de3ae34f06e41aacacb917f5a0214623259bdc
Fixes: OS#182120
2020-02-10 14:52:33 +07:00
Vadim Yanitskiy 9cbfe11ee2 tbf: fix NULL pointer dereference in create_[ul|dl]_ass()
The problem is that bitvec_free() is not NULL-safe. Ideally we
need to fix it in libosmocore [1], but let's also fix it here,
so OsmoPCU can be safely used with older libosmocore versions.

[1] https://gerrit.osmocom.org/c/libosmocore/+/17114

Change-Id: I7647d17b3d03f8e193ef6e793a2d3c1967744eef
Fixes: CID#208181, CID#208179
2020-02-10 14:12:24 +07:00
Vadim Yanitskiy c74e217799 tbf: cosmetic: fix spacing in gprs_rlcmac_tbf::create_ul_ass()
Change-Id: Ice4c4db20551753fa4219e7a216309229f7a2ab5
2020-02-09 05:40:51 +07:00
Pau Espin ac2b866426 Fix trailing newline mess with LOGP(C) in rlcmac/csn1
Output was incorrect before this patch. LOPC was being called without
having any initial LOGP, and trailing newline was usually missing at the
end.

Since csnDecoder/encoder functions are recursive, it's difficult to
handle logging state in a coherent way inside them. Let's better simply
control start/end of logging related topics in the callers of those
functions, and simply use LOGPC everywhere in csn1.cpp.

Change-Id: I50da7560939fac360b7545e2a6bfaf45ed0c4832
2020-02-08 11:03:13 +00:00
Vadim Yanitskiy 3ff1a3c6d5 pcu_sock: cosmetic: fix typo in a comment message
Change-Id: Ia7e91d803152ac3f2af88f4552fced27f59d8270
2020-02-08 14:36:01 +07:00
Vadim Yanitskiy 8832c2e5d4 pcu_sock: fix memleak, allocate pcu_sock_state on stack
It was noticed that OsmoPCU leaks memory when trying to reconnect
to the BTS. It could be easily fixed, but we don't really need to
allocate the PCU socket state on heap as we never have more than
one connection.

Change-Id: Iea8930f443caa16f522f7c5375e0004e4e2315cb
2020-02-08 14:36:01 +07:00
Vadim Yanitskiy d83c8ffb6b VTY: install talloc context introspection commands
Change-Id: I2e1e26be1162b0fb695969e5ac265704adaf9d5c
2020-02-08 14:36:01 +07:00
Vadim Yanitskiy 1ec29c7324 VTY: get rid of pcu_vty_go_parent() / pcu_vty_is_config_node()
Since I2b32b4fe20732728db6e9cdac7e484d96ab86dc5, go_parent_cb()
is completely optional. It no longer has the task to determine
the correct parent node. The is_config_node() callback is no
longer needed too. Get rid of them.

Since Ic5e69a396df659933fd4d50298b9925e837a6861 we depend on 1.3.0.

Change-Id: Id7ce8c4e1ac43747ad40a06d01433c366da07b42
2020-02-08 14:36:01 +07:00
Vadim Yanitskiy 28b4d27209 csn1: fix csnStreamDecoder(): avoid conditional calls to bitvec_read_field()
As was discovered by pespin, changing logging level of DCSN1 makes
the CSN.1 decoder behave differently (see OS#4375). In particular,
this makes RLCMACTest (encode / decode test) fail.

I did a quick investigation and noticed that some of the logging
statements call bitvec_read_field(). By definition this function
moves the internal pointer (current bit position) of a given
vector and increments readIndex by a given amount of bits.

The problem is that LOGPC would not evaluate its format string if
the logging message is not going to be printed, e.g. if a given
logging level is lower than the current one, or in case if
logging is not enabled at all.

The first two conditional calls to bitvec_read_field() are related
to CSN_PADDING_BITS, so that's not critical because padding is
always in the end of messages. The later two are related to
CSN_RECURSIVE_ARRAY and CSN_RECURSIVE_TARRAY respectively.

Let's use bitvec_get_uint() instead to keep readIndex unchanged.

Change-Id: Ia331048db9f790ca407fd341ced01df12d10a233
Fixes: OS#4375
2020-02-06 16:19:47 +00:00
Pau Espin ea9de4ae25 rlcmac: Transform a few LOGPC messages to LOGP
Those messages are self contained and don't need LOGPC.

Change-Id: Iea79e030563cd29bfc9750ff5c3e398c590a7307
2020-02-05 17:27:48 +01:00
Pau Espin 5e300ce565 Check return code of rlcmac decode/encode functions
Change-Id: Iabcb768bd714680aa768b35c786dea2015d1e451
2020-02-05 17:26:02 +01:00
Pau Espin 47de23266d rlcmac: Return error code from csn1 encoder/decoder
Change-Id: I0c5e1b870608b0622b239791effd5c5878e230bc
2020-02-05 17:25:59 +01:00
Pau Espin d636f74923 csn1.cpp: Rework ProcessError() function to print errors
Same API is kept to more easily keep code compatibility with wireshark's
packet-csn1.c implementation.

Change-Id: I1ce2c52e2357841aa1f31babfdce9011435f866b
2020-02-05 11:44:46 +01:00
Pau Espin f960d5bcf4 cosmetic: csn1.cpp: Fix whitespace
Change-Id: I663c5c20a878b3643db6a8ddd58e29bc9fe93d80
2020-02-03 14:39:38 +00:00
Vadim Yanitskiy 3568fcfa7d gprs_bssgp_pcu: fixup: fix length check in gprs_bssgp_pcu_rx_dl_ud()
Change-Id: I7d49b27a615350a7707154aa3cc903db7c1df374
Fixes: I7f84bd776cc780a45880f136107f6e0bc56241d1
2020-02-03 16:39:12 +07:00
Vadim Yanitskiy 3898cd6843 gprs_bssgp_pcu: fix invalid use of non-static data member 'frame'
The 'gprs_llc' is defined as a pure C structure with C++ specific
extensions (methods), so it's rather a class. Accessing its field
'frame' statically causes Clang to throw a compilation error:

  gprs_bssgp_pcu.cpp:111:29: error: invalid use of non-static data member 'frame'
      if (len > sizeof(gprs_llc::frame))

Let's avoid this and use LLC_MAX_LEN as the size limitation.
God knows what to expect from such a mix of C++ and C...

Change-Id: I7f84bd776cc780a45880f136107f6e0bc56241d1
2020-01-29 06:17:50 +07:00
Vadim Yanitskiy f6b83a24a3 encoding: fix log_alert_exit(): do not treat error as format string
This is rather a cosmetic change aimed to make ASAN / Coverity happy.
In general, we never pass any input from an untrusted source.

Change-Id: I26d654da4c3bf5fd86a298c3027fd9820c932308
2020-01-29 06:17:49 +07:00
Vadim Yanitskiy 4590b91728 gsm_timer: fix comparison of constant LONG_MAX with an integer
It does not make sense since INT_MAX is always less than LONG_MAX.
Found by Clang [-Wtautological-constant-out-of-range-compare].

Change-Id: I9934e05aa050bf93b3c795376f5dca3a848a7e11
2020-01-29 06:14:54 +07:00
Vincent Helfre e525bf94ba gsm_rlcmac: add dissection of NAS container
Port from wireshark.git 575e4df4aa3392ffd09ca372859573f09f0a5c57

Ported-by: Pau Espin Pedrol <pespin@sysmocom.de>
Change-Id: I2a05a057b6f441364502a96f9f34872c7e251a36
2020-01-28 18:16:24 +01:00
Pascal Quantin e4a243c02b gsm_rlcmac.cpp: fix an out of bounds access
Port from wireshark.git a4a5adb68b898f770e2addf9168d796979ebe237.

Ported-by: Pau Espin Pedrol <pespin@sysmocom.de>
Change-Id: I23fb2199fc8f9cc3e5bd475e2558ee8d482df1e1
2020-01-28 18:08:29 +01:00
Pascal Quantin 463746917f gsm_rlcmac.cpp: Do not skip too many lines of the CSN_DESCR when the field is missing
Port from wireshark.git c4ead251da7199cfd746d378c51eb8c30d09a6ba.

Ported-by: Pau Espin Pedrol <pespin@sysmocom.de>
Change-Id: Ib9b8eafd69d3b45b0d631ba9635689807b472b73
2020-01-28 18:03:59 +01:00
Anders Broman 8ea3cbe6b2 gsm_rlcmac.cpp: hanged all M_BIT macros to M_UINT, as M_BIT does not use the referenced hf.
Port from wireshark.git e97273a35d101516decbc7d98fcc6c6b3f193962.

Ported-by: Pau Espin Pedrol <pespin@sysmocom.de>
Change-Id: Id20d31e9ebd851b45d5f3280f3e229d8d7ae2cea
2020-01-28 17:42:34 +01:00
Pau Espin 034e32f0eb gsm_rlcmac.cpp: Fix trailing whitespace
Change-Id: I3b50cf386d417ba73b97f48b3000f69d9a54c8c9
2020-01-28 17:14:26 +01:00
Pascal Quantin 29248d6941 gsm_rlcmac: Enhance dissection of PSI1
Port of wireshark.git 7e9411fee3a101b53693210f7a38789fd4c70ba2.

Ported-by: Pau Espin Pedrol <pespin@sysmocom.de>
Change-Id: I89d488c1f349c556e40a9d13895b1309d5140212
2020-01-28 17:13:39 +01:00
Pascal Quantin cc76d412fd gsm_rlcmac.h: Remove Uplink messages from the RlcMacDownlink_t structure
(as they are part of the RlcMacUplink_t structure that is also used to call csnStreamDissector function).

Port from wireshark.git commit 9f8b638cfa8a660fb64c54dcadb83e6747db0a15.

Ported-by: Pau Espin Pedrol <pespin@sysmocom.de>
Change-Id: If46f8cc3f21f527f911dcac6ff1b78f182104a00
2020-01-28 16:46:51 +01:00
Gerald Combs bc4f3930a9 gsm_rlcmac.h: Make sure we have a corresponding 'u' member to RlcMacDownlink_t for every call
Port from wireshark.git commit 6c32ba5ff1a5f5ec2426d1d2c4f4f37fd136bab0.

Ported-by: Pau Espin Pedrol <pespin@sysmocom.de>
Change-Id: I989befc56fa37b8f982301f4f9aa4f4533e3e87a
2020-01-28 16:38:39 +01:00
Bill Meier bcc6408cd1 gsm_rlcmac.h: #if 0 unused stuff
Port of wireshark.git 2ef0c615946cd290aa9463c637169da0a1ca7972.

Ported-by: Pau Espin Pedrol <pespin@sysmocom.de>
Change-Id: Ia2e80664d293a2a95372213b4164c3e72259e0bb
2020-01-28 16:17:41 +01:00
Alexis La Goutte e36fb5b802 csn1: fix this statement may fall through [-Werror=implicit-fallthrough=] found by gcc7
Port of wireshark.git commit fd68c7dfc7d06ce7babe914f2575d9e4f35988ad.

Ported-by: Pau Espin Pedrol <pespin@sysmocom.de>
Change-Id: Ibaf47d7c4fdff326ac1dccf6fff77e2357e6a2bd
2020-01-28 13:45:03 +01:00
Pau Espin 900c2e277a csn1: Drop format_p union from CSN_DESCR
Port of wireshark.git 8626bb4cbb4d9926f7b56663585d9ef66252f93f.
We don't really need the other fields added there, let's keep only the
value out of the union.

Change-Id: Ia8889252ee7518a919a15d749815c2803b4b23cd
2020-01-28 13:43:45 +01:00
Anders Broman 771da85a11 csn1: Try to fix cast discards '__attribute__((const))' qualifier from pointer target type
Port of wireshark.git 1ff6213c949b373bcb7de5c48a5a4f805093066f.

Ported-by: Pau Espin Pedrol <pespin@sysmocom.de>
Change-Id: Ie14c335a904a17333e98ef58bf5e40245444e956
2020-01-28 13:43:24 +01:00
Guy Harris e26467c4ed csn1: Don't cast away constness
Port of wireshark.git commit 8e22ded7f8537e37e89ba558c83702d127443ae8.

Ported-by: Pau Espin Pedrol <pespin@sysmocom.de>
Change-Id: I100d5c43d8878e660035bf4a64718771f41a38a8
2020-01-28 13:42:29 +01:00
Anders Broman 60bf845f25 csn1: Fix warning with -Wmissing-prototypes
Port of wireshark.git 2e52e2ac997ca58caabee3270b5a6c3f96159ff0.

Ported-by: Pau Espin Pedrol <pespin@sysmocom.de>
Change-Id: Ic69a75ce3f01cea326139f678b963110e895c356
2020-01-28 13:41:21 +01:00
Pascal Quantin c515551625 csn1: Fix an infinite loop in CSN.1 dissector when having more than 255 padding bits
Port of wireshark.git 8b5aa913711b32b1e1bc707919d2a98c1875d443.

Ported-by: Pau Espin Pedrol <pespin@sysmocom.de>
Change-Id: I7f6aecc2c0f300c1a77cd683652969d3f1aa5794
2020-01-28 13:40:14 +01:00
Pau Espin 5b71697618 csn1: Fix pedantic compiler warnings in csn.1 dissectors
Port of wireshark.git commit 6aca10831f86c562970b13efa811f46e25ee3091.

    From Mike Morrin:
    Fix pedantic compiler warnings in csn.1 dissectors.

    There is some tricky casting going on in csn.1 structures.  To eliminate all
    the warnings, the function pointers needed to be moved out of the object
    pointer unions.  Fortunately macros (mostly) hide these changes from the
    protocol dissector tables.

    https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=7686

    svn path=/trunk/; revision=44899

Change-Id: Ia1a8c50c4b024ca6df4e3fbbf891cd33591ccc9b
2020-01-28 13:38:42 +01:00
Pau Espin 7cce825fa4 csn1: Allow CHOICE elements to re-process the bits used for the choice
This is a port of wireshark.git commit
2f024256bf337400ef3a82fa75e6d48d5707e059.

From 78516187d821b8d19d16987b1d6bc855ee7cbe10 Mon Sep 17 00:00:00 2001
From: Sylvain Munaut <tnt@246tNt.com>
Date: Sat, 4 Feb 2012 10:00:22 +0100
Subject: [PATCH 4/6] packet-csn1: Allow CHOICE elements to re-process the bits used for the choice

We may want to display more detail, or the sub-element should be
displayed with its headers or whatever ...

Change-Id: I3a5a95d5f918b8f17a2400a6d0c4d855ecacea7e
2020-01-28 13:38:42 +01:00
Pau Espin 98e4c53cad csn1: Extend CSN_SERIALIZE to allow 0 bit of length
Port of wireshark.git 2f024256bf337400ef3a82fa75e6d48d5707e059.

From c6ee558d3bb00bfd25cca7c534448bf60df3c7cf Mon Sep 17 00:00:00 2001
From: Sylvain Munaut <tnt@246tNt.com>
Date: Sat, 4 Feb 2012 10:24:01 +0100
Subject: [PATCH 6/6] packet-csn: Extend CSN_SERIALIZE to allow 0 bit of length

In some coding there is no 'length' field at the top of a serialized
block, or it's more complex than a single field, in which case we
have to rely on the serialize decoder to consume the correct number
of bits.

We extend the CSN_SERIALIZE processing so that if a '0 bit' length
field is specified, then the length is not displayed and the
consumed bits by the serialize function is taken as the length
at posteriori.

The processing keeps the same behavior for any length > 0.

Change-Id: I9fadc99218594447001f7bb9943f4514b9877799
2020-01-28 13:38:42 +01:00
Jeff Morriss c0b4f4a633 csn1: shuffle decrements of remaining_bits_len
So that they always occur next to an increment of bit_offset.

Port from wireshark.git 1c81971d4292438ffdf83e9f9b9ab96c133c785b.

Ported-by: Pau Espin Pedrol <pespin@sysmocom.de>
Change-Id: I7474e9d632e068d6e33b0a502b81d4fff1f48802
2020-01-28 13:37:50 +01:00
Anders Broman c0190c8a5a csn1: packet-csn1.c:179: warning: 'pui8' may be used uninitialized in this function
Port from wireshark.git commit fd9f182f4b13a3d81b1b5c797a6e4b9d6d327fdd.

Ported-by: Pau Espin Pedrol <pespin@sysmocom.de>
Change-Id: I37f5f3732f92cd7340af8ac1e04383f3e45e7636
2020-01-28 13:34:36 +01:00
Anders Broman 72c102acf8 csn1: Update M_NULL CSN_DESCR to match wireshark
Port from iwireshark.git commit cc6d4341e65ef2e8d8488fe0ac0f236ece0dd844.
It looks like it makes no difference to us now, but other EGPRS messages
may use it in the future.

Ported-by: Pau Espin Pedrol <pespin@sysmocom.de>
Change-Id: I34039370c292e62790a38abb59f55c69fffa88e8
2020-01-28 13:34:08 +01:00
Pau Espin cdbc5dbd1c tests/rlcmac: Add test to showcase that decode_gsm_ra_cap() fails
Currently code using that function in osmo-pcu is disabled, allegadly
because SGSN was sending incorrect values, but it looks more like a CSN1
issue.

Related: OS#1525, OS#3499
Change-Id: I92c86397f988afaa791871d823a45fa85054f3bb
2020-01-28 13:29:42 +01:00
Vadim Yanitskiy bd0b0b3242 pcu_l1_if.cpp: fix NULL-pointer dereference in imsi2paging_group()
Passing NULL to strlen() would lead to a segmentation fault.

Change-Id: I838e3a21a3b25c2bc8260f67d156c6cc284f4456
Fixes: CID#207484
2020-01-16 00:25:54 +07:00
Pau Espin 771de1f439 Support PAGING-CS and PAGING-PS on on PTP-BVCI
Related: OS#2403
Change-Id: I5c52b5af740460c48bb3ba858243b1d20e624268
2020-01-06 10:26:46 +00:00
Pau Espin 65a0d1d19b Support Gb PAGING-CS
The paging is sent over PACCH towards MS with an active TBF.

Related: OS#2406
Change-Id: I9501e02e1d7f6944497e724dbccb9a19c3f5221f
2020-01-06 10:26:46 +00:00
Pau Espin 5530f12f71 Allow Gb PAGING-PS without P-TMSI
P-TMSI is optional IE, but IE is mandatory and hence always available.
Since the encoding is actually a Mobile Identity, the IMSI is used in
case P-TMSI is not available.

Change-Id: I4dbf8db04e81f98352a42ce34a5d91326be9bfd1
2020-01-06 10:26:46 +00:00
Pau Espin d7c3265223 Pass paging group instead of imsi where later is not needed
Change-Id: Id0663a81f439f2d0b893b0d34f85a6db1927ef8e
2020-01-06 10:26:46 +00:00
Pau Espin fbfab297ee Split identity_lv param into mi+mi_len
It's not really needed to have those together in some function calls,
and makes it more difficult to follow the code. Furthermore, new callers
not having content already aligned (len+value) will be using these
functions in forthcoming commits.

Change-Id: Ifb9d3997bfb74b35366c3d1bc51ce458f19abf16
2020-01-01 16:10:15 +00:00
Pau Espin db12f254ce Log BVCI PTP value upon msg recv
Change-Id: I47c5902112d568cd5a48e003010d8085b02d64e8
2020-01-01 16:10:05 +00:00
Pau Espin 506eb23dc5 fix typo in log message
Change-Id: Ib6fc4625242d855193b62b561624b23b265648b9
2019-12-31 17:01:34 +00:00
Pau Espin 585cfb28b8 Fix trailing whitespace
Change-Id: I0515b5c8f6744fa501de88fa7808b7fc91981f0e
2019-12-10 20:02:21 +01:00
Pau Espin 3f064f516d prs_bssgp_pcu.cpp: Mark priv funcs as static and remove trailing whitespace
Change-Id: I93b7ee33cc33c773675c85ace7b8f1afa86fbf06
2019-12-10 17:09:51 +01:00
Pau Espin 32499b614b pcu_l1_if: Check pag_req id_lv len fits buffer
Related: OS#4316
Change-Id: I803e1d2577a0d210e74feb5ca4c216375a5024ea
2019-12-09 13:55:14 +01:00
Pau Espin 30f6617c79 tbf_dl.cpp: Fix typo in log line
Change-Id: I9fdea4246c95897f3e72604981597db828a219a3
2019-12-04 18:11:52 +01:00
Pau Espin d0fc9e80fe Remove dash from name used in VTY cmd prompt
Others projects don't contain a dash in there, and it seems to cause
problems with TTCN3 VTY expectations.

Change-Id: I3430abb5fc622dec293457466e760de95fa3a05c
2019-12-02 11:14:26 +00:00
Vadim Yanitskiy 657a4c0ccd VTY: cosmetic: use osmo_talloc_replace_string()
Change-Id: Id09c7d24b48ddecfa96404c3e75330465a11f830
2019-11-30 20:17:25 +07:00
Vadim Yanitskiy fc75cc0ecf VTY: add warning about changing PCU socket path at run-time
Change-Id: I7cee2d782bd3dfc2cc8d2febc16dca905dcc294e
2019-11-30 20:17:21 +07:00
Pau Espin 1e6eb30f51 Clarify (M)CS related VTY attributes
Some are used to control (M)CS values for downlink while some do it for
uplink. Let's make clear which one is used for what. Take the chance to
document the fields a bit better than they were.

Some more information about the origin of cs_downgrade_threshold can be
found in the commit introducing it: 70b96aa232.

Related: OS#4286
Change-Id: I4e890e924b094a1937fbd3794de96704cf0421a8
2019-11-28 17:11:56 +01:00
Vadim Yanitskiy ffebd24456 PTCCH: properly handle RACH.ind for PCU_IF_SAPI_PTCCH
Change-Id: I482d60a46b9d253dfe0b16140eac9fea6420b30c
Related: OS#1545
2019-11-23 17:42:45 +07:00
Vadim Yanitskiy 78f58618f3 PTCCH: properly handle RTS.req for PCU_IF_SAPI_PTCCH
Change-Id: Ib204acce1a7e33f6651b9da2a7b4a9b9ae461093
Related: OS#1545
2019-11-17 02:58:31 +07:00
Vadim Yanitskiy bd0dac3783 PTCCH: implement basic message codec and API
Change-Id: Id79e95aafdde4a71977c64385fce48b729a51ca9
Related: OS#1545
2019-11-17 02:35:18 +07:00
Vadim Yanitskiy 0bf622e057 gprs_bssgp_destroy(): fix memleak and NULL-pointer dereference
So far there was a memory leak, because free()ing 'the_pcu.bctx'
would cause ASAN to complain. And that's reasonable, because it
needs to be freed properly. Moreover, 'the_pcu.bctx' may simply
be uninitialized in some cases, e.g. when OsmoPCU is terminated
before connecting to the SGSN.

Let's use the new bssgp_bvc_ctx_free() from libosmogb.

Change-Id: I274e79e1746c7678b81720ec11e8a564befe38ba
Depends: Ia78979379dbdccd6e4628c16f00d0c06d9212172
2019-11-10 09:04:21 +00:00
Vadim Yanitskiy fd734de4d1 GprsMs::update_cs_ul(): clarify the meaning of old_link_qual
Change-Id: Iad703a573621c64613b9b8c229079dc63fcaeb9e
2019-11-08 06:20:55 +07:00
Vadim Yanitskiy ce27d1e126 BSSGP: properly print BVCI for signalling messages (BVCI=0)
Change-Id: I4ac0f48d2e62cd0545e8a1e1b26c9e43ef5e8dde
2019-11-08 04:18:46 +07:00
Vadim Yanitskiy ef444142c8 BSSGP: do not reject SUSPEND ACK / NACK messages
Both BSSGP SUSPEND ACK and NACK messages use BVCI=0 (signaling),
which always exists. Claiming that BVCI=0 is unknown is wrong.

Instead of adding both BSSGP_PDUT_SUSPEND_{ACK,NACK} to the 'if'
statement, let's rather avoid rejection for all BVCI=0 messages,
as there may be other unlisted message types.

Change-Id: I780657c1e8f67e0bef0e92a31db7ba61b57d7ec4
Related: OS#4111
2019-11-08 04:11:20 +07:00
Pau Espin 05bca3524a Fix assertion hit upon CCCH Paging Request
Recent commit added an assertion to check for buffer boundaries and it
actually gets hit.
One of the 2 code paths calling pcu_l1if_tx_pch() was passing a buffer
of 23 bytes while one of maximum 22 is expected (because plen is not set
in the buffer but set inside pcu_l1if_tx_pch()).
So it seems before the assert, that code path was actually writing 1
byte outside the boundaries of data buffer, since bitvec_pack() uses
data_len field of bitvec.

Related: OS#4228
Fixes: 8dc09e73d0
Change-Id: I84c5dfd4d5580e9d4c00ed21887cb51bd9abbd2e
2019-10-16 14:36:28 +02:00
Alexander Couzens b3b0c49d1c encoding: fix space, tabs
Change-Id: I80ac88f50bfedfd2b86d548883313b5a187b1e8f
2019-10-09 17:14:17 +00:00
Vadim Yanitskiy cef2f843b4 VTY: fix command 'show tbf all': properly filter TBFs
For a long time the VTY command to show all active TBFs was broken.
The TBF filtering (by allocation origin) logic allows one to show
TBFs allocated on CCCH, PACCH, or on both of them. In the latter
case we have been checking whether a TBF was allocated on both
logical channels at the same time.

Let's fix this by passing a flag-mask instead of boolean arguments.
To be able to use GPRS_RLCMAC_FLAG_* definitions from "tbf.h", let's
exclude them from "#ifdef __cplusplus ... #endif" block.

Change-Id: I1c9f401368af880a97d32905c4cce0da481ffc21
2019-10-09 22:00:54 +07:00
Vadim Yanitskiy afbf189ef2 VTY: refactor pcu_vty_show_ms_all(): use show_ms()
Change-Id: I72aa1a1de22602a3ad2a4d19604ae0935c88c750
2019-10-09 20:26:47 +07:00
Pau Espin d752d7cebe pcu_l1_if.cpp: Replace value 23 with libosmocore's GSM_MACBLOCK_LEN
Change-Id: Ieec3dd028fffa1a735afaaf3f93da0a1202d122a
2019-10-07 21:04:19 +02:00
Pau Espin 8dc09e73d0 pcu_l1_if.cpp: Imm Assign PCH: clarify size of different items
Change-Id: I32876858e3e93951e965b0fc7875c95c1f36f3ac
2019-10-07 21:04:19 +02:00
Pau Espin f681f07cd0 pcu_l1_if.cpp: Drop unneeded byte in Imm Ass PCH buffer
paging group is 3 bytes and imm assign with plen prepended is 23 bytes,
so there's 1 extra byte not needed and makes code confusing.

Change-Id: Id7835e5aa1506505ff54e019b38f30111f79b5dc
2019-10-07 21:04:19 +02:00
Pau Espin 2ccb6aef89 pcu_l1_if.cpp: Fix GSMTAP Imm Assign PCH wrong encoding
Wireshark expects to receive the plen in order to decode it.

Fixes: 58543709e4
Change-Id: I91d1354689300b949760cdbaee03294eab958e12
2019-10-07 18:26:10 +02:00
Pau Espin 58543709e4 Log AGCH and PCH blocks using GSMTAP
Change-Id: I4d62f98801af1b0a290d3dd35bd213ccf3151035
2019-10-01 10:38:55 +02:00
Pau Espin 1ec211f57f Log RACH Requests using GSMTAP
Change-Id: Ib686a49e8c630808c30bede5810cd65fc045954a
2019-09-30 20:15:54 +02:00
Pau Espin 1879442443 vty: Fix osmo_tdef timers not listed in write config
Change-Id: I5c7ae18919e4b016505aa01eea6694d8a3f5df5f
2019-09-26 18:25:35 +02:00
Pau Espin f4c77e686a tbf_dl.cpp: Remove dup call to tbf_update_ms_class() in state GPRS_RLCMAC_WAIT_RELEASE
tbf_update_ms_class() is already called two lines above in the common
path.

Fixes: 409efa1ec8
Change-Id: Icbe3805c72a5c77366215be55128b586e5a00fb7
2019-09-26 14:43:22 +02:00
Pau Espin ad586a9fe4 tbf_dl: Setup m_llc_timer in constructor using osmocom API
Change-Id: I3e761b319326e33ab1d56c4fb30cafe3b0f96c29
2019-09-26 14:43:22 +02:00
Pau Espin bddf1ad7f6 Move tbf_{dl,ul} child constructors to respective .cpp files
Fixes: 9d1cdb1f69
Change-Id: Id258589d46de42ad4e27889bc396f930b7f94b79
2019-09-26 14:43:22 +02:00
Pau Espin 9d1cdb1f69 Move out tbf subclasses from tbf.h to their own headers
It's a good start towards clearing current mess between parent and the 2
children classes.

Change-Id: Ibc22ea2e02609af7ee058b8bc15df2115d4c6f60
2019-09-25 17:50:06 +02:00
Pau Espin 488aa29083 cosmetic: fix whitespace
Change-Id: I45bbe4d3c69d573aaff010d16f338c7ec3eaf08a
2019-09-25 17:50:06 +02:00
Pau Espin e13cdc503e pdch.cpp: Use pcu_l1_meas previously filled by lower layers
Otherwise, a new meas object is allocated in the stack in upper layers
which doesn't contain the link_qual information (have_link_qual=0),
outputting following error:

osmo-pcu/src/gprs_ms.cpp:644 Unable to update UL (M)CS CS-2 because we don't have link quality measurements.

Change-Id: I1980ca325c8d65f3f6310fa697dd810eec7ab077
2019-09-25 13:52:31 +02:00
Pau Espin 812d466bbd pdch.cpp: Refactor bitvec param passing in rcv_control_block
Move code in rcv_block_gprs() only needed for rcv_control_block() into
the later. This way rcv_block_gprs() is simplified and shows similar
code paths with regards to rcv_data_block().
It can now be seen that the main difference between both is the meas
param no being passed in the control case.

Change-Id: I2a0133463edced93c72ccc743a0cf00d1d6922cf
2019-09-25 13:35:13 +02:00
Pau Espin 2b5c629055 Use osmo_tdef to implement dl-tbf-idle-time
Change-Id: I5e4f0d2f90e643600b7752525d6c2830856c9d3b
2019-09-17 11:11:04 +02:00
Pau Espin 63700ead34 Use osmo_tdef to implement ms-idle-time
This commit would also remove the option from config_write_pcu() since
it's automatically filled in by osmo_tdef, but there was actually a bug
because that param was never printed when saving the config...

Change-Id: Id8e70b0f44ef2f7e20ecdb3fd8ca93ae2a05b9a3
2019-09-17 11:05:45 +02:00
Pau Espin 38cfa734f4 Use osmo_tdef to implement T3190
Change-Id: I0c767c526398d98ca47ef98fdaccfc23af11fb0d
2019-09-16 14:21:21 +00:00
Pau Espin 5211d9deca Use osmo_tdef for BSSGP T1 and T2
Change-Id: I477e5b702c8b956136d93fc1cee01991233e381f
2019-09-16 14:21:21 +00:00
Oliver Smith cfb6321b88 Forward ETWS Primary Notification to MS
Receive an Application Information Request from the BTS via PCU
interface. Construct a Packet Application Information message from it
(3GPP TS 44.060 11.2.47) and send it to all MS with active TBF.

The TTCN-3 test infrastructure to test this feature is not quite ready
yet, so I've added C unit tests instead.

Related: OS#4048
Change-Id: Ie35959f833f46bde5f2126314b6f96763f863b36
2019-09-14 15:28:43 +00:00
Pau Espin 5360ef5447 bts.cpp: Fix osmo_tdef initialization on older g++ compilers
Fixing errrors spotted:
bts.cpp:78:1: error: uninitialized const member 'osmo_tdef::T'
 };
 ^
bts.cpp:78:1: error: uninitialized const member 'osmo_tdef::default_val'
bts.cpp:78:1: error: uninitialized const member 'osmo_tdef::unit'
bts.cpp:84:1: error: uninitialized const member 'osmo_tdef::T'
 };
 ^
bts.cpp:84:1: error: uninitialized const member 'osmo_tdef::default_val'
bts.cpp:84:1: error: uninitialized const member 'osmo_tdef::unit'

Change-Id: I2dfecf22516f52cc19e0a0442e70dbc4dbc61336
2019-09-13 12:42:38 +02:00
Alexander Couzens e46d8dcaab tbf_dl: add comments to the scheduler
Change-Id: Ib037f9fda30472313c7a82effb1e925c6abebbe5
2019-09-12 16:49:21 +00:00
Pau Espin 28f160e76c Introduce osmo_tdef infra and timer VTY commands
This will allow for configuration of some of the timers by the user,
and allow him to inspect current values being used.
It will be also useful for TTCN3 tests which may want to test some of
the timers without having to wait for lots of time.

Timers are splitted into 2 groups: BTS controlled ones and PCU controlled
ones. The BTS controlled ones are read-only by the user (hence no
"timer" VTY command is provided to change them).

TbfTest.err output changes due to timers being set up correctly as a
consequence of changes. Other application such as pcu_emu.cpp and
pcu_main.cpp had to previosuly set the initial values by hand (and did
so), but apparently TbfTest.c was missing that part, which is now fixed
for free.

Depends: libosmocore.git Id56a1226d724a374f04231df85fe5b49ffd2c43c
Change-Id: I5cfb9ef01706124be262d4536617b9edb4601dd5
2019-09-12 14:17:07 +02:00
Oliver Smith 45fdc44d68 tbf_dl: make preemptive retransmission optional
Since [1], OsmoPCU already starts to retransmit downlink blocks before
the MS has had a chance to receive them and/or send the related
acknowledgement in uplink. Make this optional with the new VTY option
"no dl-tbf-preemptive-retransmission".

[1] e25b5b91f6 ("tbf: Only create dummy frames if necessary")
Related: OS#2408
Change-Id: Id08aed513d4033aa0d4324c6ce07cbb2852f2f92
2019-09-11 06:16:29 +00:00
Pau Espin a8892a69b3 Use proper API osmo_timer_setup() to set up timer struct
Change-Id: Idd2b0c5247870bee3b3c3e460a6731ee50a47404
2019-09-05 16:21:49 +02:00
Pau Espin ef1fe58e19 cosmetic: tbf: Rename T and N arrays
Those namings my collide with usual osmocom "T" variable name associated
to a timer number, which will be added in following patches.

Change-Id: Ic2b5068a4882e4a043bf81496be30a378fdb9a09
2019-09-05 14:40:26 +02:00
Vadim Yanitskiy df0fd8ba27 osmobts_sock.cpp: do not print the same debug message twice
The following message is printed by the pcu_tx_txt_ind():

  DL1IF INFO pcu_l1_if.cpp:113 Sending XXX TXT as PCU_VERSION to BTS

There is no need to print it twice:

  DL1IF INFO osmobts_sock.cpp:74 Sending version XXX to BTS.
  DL1IF INFO pcu_l1_if.cpp:113 Sending XXX TXT as PCU_VERSION to BTS

Change-Id: Ic2793f20cf9df2fa08c45070a8f81ef1c08b925a
2019-08-27 11:06:11 +02:00
Vadim Yanitskiy 9e5ef54594 osmobts_sock.cpp: pcu_sock_read(): further simplify the code
Change-Id: Ie7c0ca8baf0ae5beadda60bda0bc76a44664d439
2019-08-27 11:06:00 +02:00
Vadim Yanitskiy c7849c2dfe osmobts_sock.cpp: pcu_sock_read(): use stack buffer, not heap
We don't really need to use the message buffer (on heap), because
it's never getting passed to pcu_rx(). Let's use a buffer on stack.

Change-Id: I4cb8ca80513df7b71e1438da2e82799be6be1fa0
2019-08-23 18:03:37 +02:00
Vadim Yanitskiy aef6bf43e5 osmobts_sock.cpp: pcu_sock_cb(): use libosmocore's socket API
Change-Id: I7f5c7f5744ab14f36f46cf7941e91352eca8d2b9
2019-08-23 18:03:37 +02:00