Commit Graph

23 Commits

Author SHA1 Message Date
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
Pau Espin c9880b97cf csn1: Implement CSN_CALLBACK type in encoder
Picked code from the Decoder function. I gave it a try
callback_init_Cell_Selection_Params_FREQUENCY_DIFF and looks
like working fine.

Change-Id: Iac962ae3e9f52f417f394060b64fc4d0ebf3d0bf
2021-05-28 18:42:42 +02:00
Pau Espin 74aa3523f3 csn1: Log CSN_VARIABLE_ARRAY values as hex
Change-Id: If84c4b3cb870068a85405116f1d505ffcff9c26e
2020-11-24 11:24:11 +01:00
Pau Espin 259a694ba7 csn1: Fix readIndex pointer change in CSN_VARIABLE_ARRAY
There's actually 3 errors:
* Its value should be updated, not the pointer itself
* Value should be increased, not decreased
* bitvec_read_field() API is already advancing it, no need to do it

Fixes: OS#4838
Change-Id: I009abc373794e148091e637ffee80c6461960945
2020-11-24 11:22:06 +01:00
Pau Espin 16705a4db1 cosmetic: Fix ws between if keyword and parenthesis
Change-Id: I5932f21c58e76552f7187a175b8e281c5846536c
2020-10-29 11:34:17 +00: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
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 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 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
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
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 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
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