Commit Graph

21 Commits

Author SHA1 Message Date
Pau Espin ebdc0d8c17 csn1: Avoid failing if optional DownlinkDualCarrierCapability_r7 is missing
All additional release fields are considered optional, and the
CSN_DESCR for Content_t already marks almost all as such, except
DownlinkDualCarrierCapability_r7.

It has been found that some MS transmits a MS RA Capability with a Length=61 bits
where the last bit in the buffer is setting the Exist bit for
DownlinkDualCarrierCapability_r7 as 1. Hence, the CSN1 decoder failed to
decode the whole message because it expected to keep reading there
despite there's no more bytes to read.

While this is could actually be considered an MS bug, let's relax our
expectancies and simply consider the case { 1 <end> } as it was { 0 },
and mark skip decoding DownlinkDualCarrierCapability_r7. That waht
wireshark (packet-gsm_a_gsm.c) or pycrate do for instance.

This patch itself doesn't fix the problem where actually the Exist bit
is stored as 1 in the output decoded structure, but simply allows keep
ongoing with decoding until the end. This issue will be fixed in a
follow-up patch.

Related: SYS#5552
Related: OS#4955
Related: OS#5020
Change-Id: I9a2541bd3544802a646890f32725201836abb0da
2021-10-20 15:36:01 +02:00
Pau Espin c90e6f8de1 Split csn1.c into common, enc and dec files
The CSN1 encoder/decoder code is already lengthy and complex enough,
there's no need to keep it in the same file, specially because when
debugging, only is interested in one of the 2 functions, and they both
look really similar (long spaghetti switches).

Change-Id: I7d1b1f7e6d7f89b052b3fd73a960419bb2673020
2021-10-20 13:35:44 +00: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 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
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 e5e2f747c3 csn1.h: Fix trailing whitespace
Change-Id: If17d36378fabeb7d22a513b93b0ecfde899df520
2020-03-26 16:03:56 +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
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
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
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
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
Max 910a387b0e Move include guard to the top
Having explicit include above the douible-include guard defines is
potential source for hard to track bugs. Let's move it inside the guard
statement.

Change-Id: I5114a63ce00b03c8eed23565d52969250bd505cc
Related: OS#1539
2018-02-19 08:43:45 +00:00
Alexander Couzens ccde5c9557 remove pcu own bitvector implementation
The osmocore bitvec is exact the same, but use a pointer instead of
a reference.

Change-Id: Id8f797631d89aa12b6e48efb2dc153a3e2f059f7
2017-05-15 12:46:33 +00:00
Ivan Kluchnikov 701d9f83f8 Ported fixes and improvements from Wireshark for RLC/MAC control block decoding. Part 1.
Generic improvements to the csn.1 dissector include:
• Added a flag to the type descriptor structure so that any type can (potentially) flagged as xxx_OR_NULL.  This was specifically needed for UINT_OR_NULL for the ms capabilities struct.
• Changed the CSN_SERIALIZE so that the length of the length field can be specified.
• For CSN_NEXT_EXIST removed the requirement that the next type be CSN_END, to allow truncation of multiple IEs.
• For CSN_LEFT_ALIGNED_VAR_BITMAP corrected the handling of bit_offset.
• Added a new type CSN_PADDING_BITS to make inspection of padding bits more convenient.
• Improved the CSN_RECURSIVE_TARRAY_1 to show the array index.

Improvements to the gsm_rlcmac dissector include:
• Rework the definition of EGPRS Ack/Nack Description so that the length IE (and absence thereof) is handled correctly.
• Added Padding Bits definitions to all PDUs
• Change the Multislot_capability_t and Content_t definitions to allow truncation at any IE
2012-10-10 19:43:37 +04:00
Ivan Kluchnikov 9b06ff0c4c Removed all size_t variables. Fixed type of readIndex and writeIndex variables.
We use unsigned int type for readIndex and writeIndex parameters in bitvec_read_field() and bitvec_write_field() functions.
2012-06-15 10:13:30 +04:00
Harald Welte c5187a1824 move everything to src/ subdirectory
The code corresponds to commit a9aa4777cc1144897a77dfb6c5c3d7325705251e
in openbts-p2.8.git (Tue Jun 12 18:14:49 2012 +0400)
2012-06-14 20:48:42 +08:00