Commit Graph

50 Commits

Author SHA1 Message Date
Vadim Yanitskiy defda4cd89 tests/gsm0408: add two more samples to bcap_tests[]
The mismatch for bcap_csd_2400_v22bis is expected, because octet 4
is not represented in 'struct gsm_mncc_bearer_cap' and the encoder
unconditionally hard-codes it to 0x88.

Change-Id: I4fc519c02b4fad8b0f40fa649d9de14b1183d10d
Related: OS#4396, OS#4394
2024-01-22 20:22:42 +07:00
Vadim Yanitskiy bfb11d8988 tests/gsm0408: cosmetic: adjust coding style (make linter happy)
Change-Id: I203033e2b3c27cb8b258faf1ff3c5ec4c0083458
2024-01-22 20:18:21 +07:00
Manawyrm 714843a455 gsm48_ie.c: change bearer cap structure in outgoing CSD calls
Outgoing CSD calls were previously encoded with the
Bearer Capability 1 - Octet 4 "Structure" field set to
3 - Unstructured. Many Nokia, Sony Ericsson and Huawei devices
won't accept incoming CSD calls with these bits set.

Set them to 0 - Service data unit integrity for now, which
seems to work and make all tested devices happy.

Change-Id: Ieb5bca3d3578abd28e18808752e1c312ce7c4ce0
2023-10-17 11:22:10 +00:00
Pau Espin aea78a2483 gsm: Introduce functions to convert between FN and RFN (Reduced FN)
Implementation ported from osmo-pcu.git
e98b315d12fb009359410809f4169f9380f3d933, function bts_rfn_to_fn().

This functionality can be used by osmo-pcu, libosmo-gprs or any other
related code which needs to handle RFNs.

Change-Id: Ib71e8da976f6cc84c3a4ab17b0a8c2101492e243
2023-08-11 20:46:04 +02:00
Neels Hofmeyr 8d42394c89 improve API for osmo_routing_area_id
Code review for [1] has asked for providing proper API for struct
osmo_routing_area_id.

For historical reasons, we have struct gprs_ra_id and
struct osmo_routing_area_id serving the exact same purpose: represent a
decoded 3GPP TS 24.008 § 10.5.5.15 Routing area identification.

The "better" one is struct osmo_routing_area_id: it allows using API
like osmo_plmn_cmp(), because it is made up of meaningful sub-structs.

Implement de/coding using the functions already available for the
sub-struct osmo_location_area_id, and simply add the RAC.

Add a test in gsm0408_test.c.

Note that other utility functions are already available for struct
osmo_routing_area_id: osmo_rai_name2(), osmo_rai_cmp().

There is no real need to deprecate struct gprs_ra_id, because there is
not really anything wrong with it. It just isn't as well integrated with
other utility API as struct osmo_routing_area_id is. Just add comments.

[1] osmo-hnbgw.git:
    cnpool: extract Mobile Identity from RANAP payload
    https://gerrit.osmocom.org/c/osmo-hnbgw/+/33133
    I373d665c9684b607207f68094188eab63209db51

Change-Id: Ic5e0406d9e20b0d4e1372fa30ba11a1e69f5cc94
2023-06-08 00:55:40 +02:00
Philipp Maier b6a3836ad2 gsm0408_test: add unittest for gsm_gsmtime2fn()
The function gsm_gsmtime2fn(), which is used to compute a frame number
value from given starting time values T1, T2 and T3 has no unit test.
Due to to the modulo that is used the computation can be a bit tricky.
Lets add a unit-test to make sure the function works as expected.

Change-Id: I8b9b71c8dcccf3b44326b5e61229f4637689d763
2023-01-12 13:06:24 +01:00
Harald Welte e61d459cef Support building with -Werror=strict-prototypes / -Werror=old-style-definition
Unfortunately "-std=c99" is not sufficient to make gcc ignore code that
uses constructs of earlier C standards, which were abandoned in C99.

See https://lwn.net/ml/fedora-devel/Y1kvF35WozzGBpc8@redhat.com/ for
some related discussion.

Change-Id: I84fd99442d0cc400fa562fa33623c142649230e2
2022-11-03 12:44:28 +01:00
Neels Hofmeyr a7f97b9093 gsm0408_test: do not print errno in expected output
The errno values are platform dependent. Printing them in the expected
output causes failure on some systems that don't match my development
system.

Still check for match with the expected errno value, but don't print the
actual value in gsm0408_test.ok.

Related: OS#4842
Change-Id: I87d125fb4e04b2130f653db1ed76691528e43411
2022-08-23 18:37:20 +02:00
Mychaela Falconia 605c9e63bb gsm48_ie: fix parsing of Bearer capability IE without octet 3a
The testcase in gsm0408_test is still failing because the encoder
produces a different result (with octet 3a present).  There is no
way to tell the encoder to use the implicit coding, and in general
this is not that critical, so we can live with that.

Change-Id: I722c168f01bffa915cb155eac234a796549d3762
2022-07-03 07:01:15 +07:00
Vadim Yanitskiy 95fc8ea056 gsm0408_test: add a testcase for gsm48_decode_bearer_cap()
The new testcase contains a Bearer capability IE from Siemens S11E,
which does not use octet 3a (no extension bit set in octet 3).
gsm48_decode_bearer_cap() currently fails to parse it.

Change-Id: Ia19f3f6d80bc09ca3f8d39d35b148a0c0245141f
2022-07-03 06:48:44 +07:00
Vadim Yanitskiy 1a077cb0ca gsm0408_test: do not return early in test_bearer_cap()
Currently, if one of the testcases fails, test_bearer_cap() would
abort and skip the remaining testcases.  Also, a msgb would not
be free()ed making the LeakSanitizer unhappy.

Instead of returning early, jump to the end of loop to ensure that:

* the verdict ('passed' or 'failed') is always printed,
* all remaining testcases are still executed,
* the msgb is free()ed.

Change-Id: I39ac801e59ba56dfe3bcd4603b48f6fbf7cfb21c
2022-07-03 06:07:09 +07:00
Pau Espin 1dac8756fd gsm: Introduce helper rach_tx_integer_raw2val()
Change-Id: I6ef085ee92b2064cb46fa5ec3ae98a0ca59ad599
2022-04-26 17:47:57 +02:00
Oliver Smith 04bfb7165b treewide: remove FSF address
Remove the paragraph about writing to the Free Software Foundation's
mailing address. The FSF has changed addresses in the past, and may do
so again. In 2021 this is not useful, let's rather have a bit less
boilerplate at the start of source files.

Change-Id: I5050285e75cf120407a1d883e99b3c4bcae8ffd7
2021-12-14 12:44:03 +01:00
Philipp Maier e36be56fc8 gsm_04_08: add parser for Mobile Station Classmark 3
3GPP TS 24.008 section 10.5.1.7 describes a Mobile Station Classmark 3
IE, which is encoded as CSN.1 struct. This means that it can not be
parsed by just casting a memory location to a struct pointer, so lets
add a parser to parse the CM3 IE.

This is fixed version of Ic8b2bfd00330235f5bed00771e421588abfaac1f,
which got reverted because it used the keyword "class" as struct member,
which lead into problems with c++ builds. This is now fixed.

Change-Id: Id8732551b33616227609cd6fcf6c3133751a89eb
Related: OS#4796 SYS#5114
2020-11-12 15:55:31 +00:00
Harald Welte c2118940aa Revert "gsm_04_08: add parser for Mobile Station Classmark 3"
This reverts commit a4939dc846,
which caused massive build failures in C++ programs like osmo-pcu
- unsurprisingly, as it calls a struct member "class", which is a
reserved keyword in C++.

Change-Id: Ia43e56385e7b580f492c560aee8ff8b1e8a0e1d8
2020-11-11 23:11:15 +01:00
Philipp Maier a4939dc846 gsm_04_08: add parser for Mobile Station Classmark 3
3GPP TS 24.008 section 10.5.1.7 describes a Mobile Station Classmark 3
IE, which is encoded as CSN.1 struct. This means that it can not be
parsed by just casting a memory location to a struct pointer, so lets
add a parser to parse the CM3 IE.

Change-Id: Ic8b2bfd00330235f5bed00771e421588abfaac1f
Related: OS#4796 SYS#5114
2020-11-10 16:36:54 +01:00
Neels Hofmeyr 30856ca5cb gsm0408_test: allow deprecated API
This test knowingly calls deprecated functions -- allow that to squelch these
warnings:

warning: ‘gsm48_generate_lai’ is deprecated: Use gsm48_generate_lai2() instead, to not lose leading zeros in the MNC [-Wdeprecated-declarations]
warning: ‘gsm48_decode_lai’ is deprecated: Use gsm48_decode_lai2() instead, to not lose leading zeros in the MNC [-Wdeprecated-declarations]

Change-Id: Ifd618c1b9befa9c9ef0a338ab4aae2b0f796f4c2
2020-06-16 15:17:48 +02:00
Neels Hofmeyr 83025bf1a6 add osmo_mobile_identity API
Implement better API around 3GPP TS 24.008 Mobile Identity coding.

struct osmo_mobile_identity is a decoded representation of the raw Mobile
Identity, with a string representation as well as dedicated raw uint32_t TMSI.
The aim is to remove all uncertainty about decoded buffer sizes / data types.

I have patches ready for current osmo CNI programs, replacing the Mobile
Identity coding with this new API. Deprecate the old MI API.
osmo-bsc: I71c3b4c65dbfdfa51409e09d4868aea83225338a
osmo-msc: Ic3f969e739654c1e8c387aedeeba5cce07fe2307
osmo-sgsn: I4cacb10bac419633ca0c14f244f9903f7f517b49
Note that some GPRS and SGs related coding is done here in libosmocore and
hence currently remains using the old implementation (see previous version of
this patch: Ic3f969e739654c1e8c387aedeeba5cce07fe2307).

New API functions provide properly size-checking implementations of:
- decoding a raw MI from a bunch of MI octets;
- locating and decoding MI from a full 3GPP TS 24.008 Complete Layer 3 msgb;
- encoding to a buffer;
- encoding to the end of a msgb.

Other than the old gsm48_generate_mid(), omit a TLV tag and length from
encoding. Many callers manually stripped the tag and value after calling
gsm48_generate_mid(). The aim is to leave writing a TL to the caller entirely,
especially since some callers need to use a TvL, i.e. support a variable-size
length of 8 or 16 bit.

New validity checks so far not implemented anywhere else:
- stricter validation of number of digits of IMSI, IMEI, IMEI-SV MI.
- stricter on filler nibbles to be 0xf.
As a result, applications using osmo_mobile_identity will be stricter in
rejecting coding mistakes (some of which we currently have in our test suites,
and which we'll need to fix).

Rationale:

While implementing osmo-bsc's MSC pooling feature in osmo-bsc, this API will be
used to reduce the number of times a Mobile Identity is extracted from a raw
RSL message.

Extracting the Mobile Identity from messages has numerous duplicate
implementations across our code with various levels of specialization.
https://xkcd.com/927/

To name a few:
- libosmocore: gsm48_mi_to_string(), osmo_mi_name_buf()
- osmo-bsc: extract_sub()
- osmo-msc: mm_rx_loc_upd_req(), cm_serv_reuse_conn(), gsm48_rx_mm_serv_req(),
  vlr_proc_acc_req()

We have existing functions to produce a human readable string from a Mobile
Identity, more or less awkward:
- gsm48_mi_to_string() decodes a TMSI as a decimal number. These days we use
  hexadecimal TMSI everywhere.
- osmo_mi_name_buf() decodes the BCD digits from a raw MI every time, so we'd
  need to pass around the raw message bytes. Also, osmo_mi_name_buf() has the
  wrong signature, it should return a length like snprintf().
- osmo-bsc's extract_sub() first uses gsm48_mi_to_string() which encodes the
  raw uint32_t TMSI to a string, and then calls strtoul() via
  tmsi_from_string() to code those back to a raw uint32_t.

Each of the above implementations employ their own size overflow checks, each
invoke osmo_bcd2str() and implement their own TMSI osmo_load32be() handling.
Too much code dup, let's hope that each and every one is correct.

In osmo-bsc, I am now implementing MSC pooling, and need to extract NRI bits
from a TMSI Mobile Identity. Since none of the above functions are general
enough to be re-used, I found myself again copy-pasting Mobile Identity code:
locating the MI in a 24.008 message with proper size checks, decoding MI
octets.

This time I would like it to become a generally re-usable API.

This patch was first merged as Ic3f969e739654c1e8c387aedeeba5cce07fe2307 and
caused test fallout, because it re-implemented old API with the new stricter
decoding. In this patch version, old API remains 1:1 unchanged to avoid such
fallout. Applications will soon switch to the new osmo_mobile_identity API and
become stricter on MI coding when that happens, not implicitly by a new
libosmocore version.

Change-Id: If4f7be606e54cfa1c59084cf169785b1cbda5cf5
2020-06-16 15:17:48 +02:00
Harald Welte a13fb75030 Revert "add osmo_mobile_identity API"
This reverts commit d1ceca9d48, as it
introduces regressions in both osmo-msc and osmo-nitb which have been
causing failing builds for several days now.

Change-Id: I4bd958d0cd2ab4b0c4725e6d114f4404d725fcf7
2020-06-16 09:21:08 +02:00
Neels Hofmeyr d1ceca9d48 add osmo_mobile_identity API
Implement better API around 3GPP TS 24.008 Mobile Identity coding.

struct osmo_mobile_identity is a decoded representation of the raw Mobile
Identity, with a string representation as well as dedicated raw uint32_t TMSI.
The aim is to remove all uncertainty about decoded buffer sizes / data types.

I have patches ready for all osmo programs, completely replacing the Mobile
Identity coding with this new API. Hence deprecate the old MI API.

New API functions provide properly size-checking implementations of:
- decoding a raw MI from a bunch of MI octets;
- locating and decoding MI from a full 3GPP TS 24.008 Complete Layer 3 msgb;
- encoding to a buffer;
- encoding to the end of a msgb.

Other than the old gsm48_generate_mid(), omit a TLV tag and length from
encoding. Many callers manually stripped the tag and value after calling
gsm48_generate_mid(). The aim is to leave writing a TL to the caller entirely,
especially since some callers need to use a TvL, i.e. support a variable-size
length of 8 or 16 bit.

New validity checks so far not implemented anywhere else:
- stricter validation of number of digits of IMSI, IMEI, IMEI-SV MI.
- stricter on filler nibbles to be 0xf.

Rationale:

While implementing osmo-bsc's MSC pooling feature in osmo-bsc, this API will be
used to reduce the number of times a Mobile Identity is extracted from a raw
RSL message.

Extracting the Mobile Identity from messages has numerous duplicate
implementations across our code with various levels of specialization.
https://xkcd.com/927/

To name a few:
- libosmocore: gsm48_mi_to_string(), osmo_mi_name_buf()
- osmo-bsc: extract_sub()
- osmo-msc: mm_rx_loc_upd_req(), cm_serv_reuse_conn(), gsm48_rx_mm_serv_req(),
  vlr_proc_acc_req()

We have existing functions to produce a human readable string from a Mobile
Identity, more or less awkward:
- gsm48_mi_to_string() decodes a TMSI as a decimal number. These days we use
  hexadecimal TMSI everywhere.
- osmo_mi_name_buf() decodes the BCD digits from a raw MI every time, so we'd
  need to pass around the raw message bytes. Also, osmo_mi_name_buf() has the
  wrong signature, it should return a length like snprintf().
- osmo-bsc's extract_sub() first uses gsm48_mi_to_string() which encodes the
  raw uint32_t TMSI to a string, and then calls strtoul() via
  tmsi_from_string() to code those back to a raw uint32_t.

Each of the above implementations employ their own size overflow checks, each
invoke osmo_bcd2str() and implement their own TMSI osmo_load32be() handling.
Too much code dup, let's hope that each and every one is correct.

In osmo-bsc, I am now implementing MSC pooling, and need to extract NRI bits
from a TMSI Mobile Identity. Since none of the above functions are general
enough to be re-used, I found myself again copy-pasting Mobile Identity code:
locating the MI in a 24.008 message with proper size checks, decoding MI
octets.

This time I would like it to become a generally re-usable API.

Change-Id: Ic3f969e739654c1e8c387aedeeba5cce07fe2307
2020-06-12 16:35:26 +02:00
Pau Espin e40b9637ea gsm: gsm_utils: Fix return type of API ms_class_gmsk_dbm() and add unit tests
Only known user of API is in osmocom-bb and it compiles fine after the
change.

Related: OS#4244
Change-Id: Ia10345008b3aca50b30482ef3b852b03eca71995
2019-11-04 12:41:22 +01:00
Pau Espin b99f4ca2d8 gsm_04_08.h: Introduce API osmo_gsm48_rfpowercap2powerclass()
Related: OS#4244
Change-Id: I32e9cc1c2397b44f0d48db2acdf782a821365b63
2019-11-03 23:21:06 +00:00
Oliver Smith 186f878266 gsm48_decode_bcd_number2: fix ENOSPC edge case
Return ENOSPC if the decoding buffer is one byte too small, instead of
returning 0 and silently truncating the string. Add a new "truncated"
variable to detect if the loop breaks in the final iteration.

The string is not truncated if there is exactly one 0xf ('\0') higher
nibble remaining. This is covered by the existing test case "long
15-digit (maximum) MSISDN, limited buffer".

Related: OS#4049
Change-Id: Ie05900aca50cc7fe8a45d17844dbfcd905fd82fe
2019-06-07 11:01:51 +02:00
Vadim Yanitskiy 1dc82643c5 gsm48_encode_bcd_number(): clarify optional LHV header initialization
Change-Id: Iafd911dd55691b3715391e3899cd6971245c8d7f
2019-05-29 08:48:46 +00:00
Vadim Yanitskiy e4799f5603 gsm48_decode_bcd_number2(): return -EINVAL if LV has too big length
Change-Id: Ie07b2e8bc2f9628904e88448b4ee63b359655123
2019-05-28 06:50:41 +07:00
Vadim Yanitskiy 7194087457 gsm48_decode_bcd_number2(): fix: return -ENOSPC on truncation
The documentation of gsm48_decode_bcd_number2() clearly states that
the output truncation is a erroneous case, so it should actually
return negative in such cases. Let's return -ENOSPC.

Change-Id: I75680f232001ba419a587fed4c24f32c70c3ad2b
2019-05-28 06:50:41 +07:00
Vadim Yanitskiy 2cd1dda631 gsm48_decode_bcd_number2(): fix output truncation
Thanks to the new unit test for BCD number encoding / decoding, it was
discovered that gsm48_decode_bcd_number2() does not properly handle
encoded LV if the output buffer size is equal to the original MSISDN
length + 1 (\0-terminator): one digit is lost.

For example, decoding of 15-digit long MSISDN to a buffer of size
16 (15 digits + 1 for \0) would give us only 14 digits.

The problem was that 'output_len' was being decremented before
checking the remaining buffer length and writing a digit to it.
As a result, the maximum length was always one byte shorter.

Change-Id: I61d49387fedbf7b238e21540a5eff22f6861e27a
Fixes: OS#4025
2019-05-28 06:50:41 +07:00
Vadim Yanitskiy aa0683d9f8 gsm0408/gsm0408_test.c: introduce BCD number encoding / decoding test
So far, both gsm48_encode_bcd_number() and gsm48_decode_bcd_number2()
did not have any unit test coverage. Let's fill this gap by testing
the following scenarios:

  - encoding / decoding of a regular 9-digit MSISDN;
  - encoding / decoding of a MSISDN with optional LHV;
  - encoding / decoding of a long 15-digit MSISDN;
  - encoding / decoding of a MSISDN to a buffer:
    - with exactly matching size,
    - with lower size (truncation);
  - decoding LV buffer with incorrect length,
  - encoding / decoding an empty input buffer.

As it turns out, gsm48_decode_bcd_number2() does not properly
handle encoded LV if the output buffer size is equal to the
original MSISDN length + 1 (\0-terminator): one digit is lost.

For example, decoding of 15-digit long MSISDN to a buffer of size
16 (15 digits + 1 for \0) would give us only 14 digits. This is
reflected in the unit test output:

  Decoding HEX (buffer limit=16) '0821436587092143f5'...
    Expected: (rc=0) '123456789012345'
      Actual: (rc=0) '12345678901234'

Moreover, if the output buffer is shorter than decoded number,
gsm48_decode_bcd_number2() silently truncates it and returns 0,
while its description states, that the rc should reflect this.

To be fixed in the follow-up patches.

Change-Id: I4b2c330cf8ffe4427c0bee7d5f3b74be56ecd85d
Related: OS#4025
2019-05-28 06:50:41 +07:00
Harald Welte 1317771c93 gsm0408_test: Fix IMEI-SV related tests to use no more than 16 digits
The IMEI-SV is speified as a 16 digit number: 14 digits of IMEI plus
two digits of software version.  Let's not try to feed 18 digit long
numbers into our functions, as the resulting behavior is unspecified.

Change-Id: I6fb85a0516dc387902ad9de4fe8c1ba82d68cae6
2019-01-22 14:53:46 +00:00
Stefan Sperling fdf8b7b1be port arfcn range encode support from osmo-bsc
As part of fixing issue OS#3075, we want to migrate support
for encoding system information from osmo-bsc to libosmocore.

This change ports one of the prerequisites for doing so:
osmo-bsc code for range-encoding ARFCNs, including tests.

An osmo_gsm48_ prefix has been prepended to public symbols in
order to avoid clashes with existing symbols in osmo-bsc code.

Change-Id: Ia220764fba451be5e975ae7c5eefb1a25ac2bf2c
Related: OS#3075
2019-01-12 09:51:05 +00:00
Neels Hofmeyr 02fd83d799 add osmo_mi_name(), for MI-to-string like "IMSI-123456"
We have gsm48_mi_to_string() and osmo_bcd2str(), but still lack a function that
conveniently prints both MI type and value in one function call.

Related: http://people.osmocom.org/neels/mi_mi_mi.jpg
Change-Id: I7798c3ef983c2e333b2b9cbffef6f366f370bd81
2019-01-08 14:07:07 +00:00
Neels Hofmeyr ea2a0ab041 gsm48_mi_to_string(): guard against zero length output buffer
All successful cases already return from the switch(), so simply handle all
errors below it by returning an empty string (if there is enough string
buffer).

Change-Id: I709ac3b9efb7b4258d8660715b10312e11b9b571
2018-12-10 17:06:30 +00:00
Neels Hofmeyr 23187fa108 gsm48_generate_mid(): mask out ODD flag from mi_type
For MI encoding, see 3GPP TS 24.008, 10.5.1.4 Mobile Identity. The 'odd' flag
indicates whether the last BCD nibble is used. Of course that flag should be
made sure to reflect the actual length.

Change-Id: Id6e695ebf9f86b295eaa7e2c6228989256f37e68
2018-12-10 17:06:30 +00:00
Neels Hofmeyr 627e0113d1 gsm48_mi_to_string: use osmo_bcd2str(), fix some corner cases
By using osmo_bcd2str(), ensure that the resulting string is always nul
terminated, and always return strlen()+1 whether truncated or not.

Still keep up the previous return value style, even if that isn't consistent at
all.

The difference between IMSI/IMEI and TMSI return values remains and is not part
of this patch.

Change-Id: I1b51b72a721e1cc9d69796b804ebda741ff0f36b
2018-12-10 17:06:30 +00:00
Neels Hofmeyr 496862818d gsm0408_test: test encoding and decoding Mobile Identity
One would think by now we would solidly encode and decode Mobile Identities.
Well, guess again.

- rc is sometimes the amount of bytes written, sometimes actual strlen().

- on string truncation, rc is sometimes strlen() (assuming nul terminated), and
  sometimes snprintf()-style would-be strlen().

- returned string, when truncated by not enough buffer size, is sometimes nul
  terminated, sometimes not.

- gsm48_mi_to_string() happily reads a byte from zero-length input buffer.

- gsm48_mi_to_string() happily writes to zero length output buffer.

- gsm48_mi_to_string() returns nonempty string for empty input.

- encoding a MI type that still has the GSM_MI_ODD flag set results in encoding
  an even-length MI as odd-length (hence appending a stray 'F').

I am going to tweak the implementation of gsm48 mobile identity encoding /
decoding, so first pinpoint the current behavior in a unit test, and show how
perforated even such a seemingly trivial API can be.

Change-Id: Iaae3af87f82f1a8f2e6273984c011b2813038cf7
2018-12-10 13:18:38 +01:00
Neels Hofmeyr 6c7b3e21d6 gsm0408_test: add test cases for MNC with leading zeros
Change-Id: I9b387e09293a6bbef84b9620ccf21ee2f9ec751c
2018-02-28 19:26:43 +01:00
Neels Hofmeyr 4566f4e79d gsm0408_test: test new gsm48_{decode,generate}_lai2() functions
Change-Id: I4c8492b8055803d2857f1ef30aede088778b085b
2018-02-28 19:26:43 +01:00
Neels Hofmeyr dbb25132d7 gsm0408_test: check for new mnc_3_digits flag
Note that on the input side, the 3-digits flag may be left false when the MNC
is >99 anyway. On the decoded side, the flag is set accurately.

Change-Id: I89765613d8c5bd939a6957f7443ac88475f1b93c
2018-02-28 19:26:43 +01:00
Neels Hofmeyr d5a577b043 gsm0408_test: also test gsm48_generate_lai() and gsm48_decode_lai()
Change-Id: Idd6cee090464bc92b654332904a9a08edf16e5c9
2018-02-22 06:04:41 +01:00
Neels Hofmeyr b9fd7eba15 gsm0408_test: RA test: include min/max value cases
(Preparation for adding 3-digit MNC)

Change-Id: Ifbc167de0cc039858112677b8d0cd14a2c8af086
2018-02-22 06:04:14 +01:00
Neels Hofmeyr c38b32dde9 gsm0408_test: include BCD and leading zeros in test output
(Preparation for adding 3-digit MNC)

Change-Id: I7f8ae05fa3e4a6fc004212757b05ca8a14c9ef45
2018-02-22 06:01:58 +01:00
Neels Hofmeyr 0bf93a6482 gsm0408_test: cosmetically re-order MCC to come before MNC
For consistency in human readability, MCC simply should come first, always.

Change-Id: Idb86a7088fac4d8a8c41190ab46f9801635f4eee
2018-02-20 22:06:56 +01:00
Neels Hofmeyr 22da145e4c cosmetic: gsm0408_test: RA test cases as array-of-struct
(Preparation for adding 3-digit MNC)

Change-Id: Ic6c645ebf82d5f8d9d51c4c4cc804a0172008156
2018-02-20 22:05:50 +01:00
Max d55d7d4fc7 Add test for gsm48_generate_mid_from_imsi()
Change-Id: Ibe5c0831268c788ceecd10fd7b22ece6480da817
2018-02-15 11:44:33 +01:00
Max f1ad60e4d8 Add function to properly encode RAI
Add gsm48_encode_ra() which takes appropriate struct as [out] parameter
instead of generic buffer. Using uint8_t buffer instead of proper struct
type prooved to be error-prone - see Coverity CID57877, CID57876.

Old gsm48_construct_ra() is made into tiny wrapper around new
function. The test output is adjusted because of the change in function
return value which was constant and hence ignored anyway.

Related: OS#1640
Change-Id: I31f9605277f4945f207c2c44ff82e62399f8db74
2018-01-08 13:02:07 +00:00
Neels Hofmeyr d8e79c7fff gsm0408_test: sanitize: cleanup msgb
Remove initial msgb talloc context creation: if we create a root ctx for msgb
that all msgb are allocated in, we would in a final cleanup discard all msgbs,
i.e. we would not verify that all msgb are cleaned up properly.

If we create the msgb context and *don't* clean it up in the end, the sanitizer
build fails because the context root is not cleaned up.

Easiest is to actually allocate all msgb at NULL ctx, because then any msgb
that aren't cleaned up properly would still linger, while we don't leave a root
ctx that we need to clean up either.

Helps fix sanitizer build on debian 9.

Change-Id: I1f2d1d05c75bbf4d92787f9735083f18cdc90f6f
2017-11-18 10:30:58 +00:00
Max 99377c2daa libosmogsm: add Routing Area Identifier test
Ensure that gsm48_parse_ra() and gsm48_construct_ra() behave properly.

Change-Id: I27117fe728407dd10886459e89ba4ff9d5e53e6b
2017-09-01 07:57:40 +00:00
Neels Hofmeyr 8a3409c4b7 gsm0408_test: initialize msgb talloc ctx
Change-Id: Ib26214add1932e93651c248cc09fbc68339b4dce
2016-09-27 11:46:38 +02:00
Holger Hans Peter Freyther cd252e3565 gsm0408: Avoid unaligned memory access in gsm48_generate_mid_from_tmsi
The &buf[3] is unlikely to be aligned properly. Use memcpy instead
of an assignment. Add a small testcase that verifies that I didn't
mess up the conversion.

Alignment trap: osmo-nitb (3293) PC=0x492b7094 Instr=0xe5803003 Address=0xbeb259db FSR 0x801
2013-07-03 10:00:06 +02:00
Harald Welte c8a0b93939 GSM 04.08: Add support for parsing CSD related bearer capabilities
Also adds a test case for both encoder and decoder of this IE
2012-08-24 21:37:59 +02:00