Commit Graph

85 Commits

Author SHA1 Message Date
Vadim Yanitskiy 90df3f40f1 gsm: fix osmo_mobile_identity_decode(): init *mi on error
Change-Id: I1c1503120c6c0e5479d8350fe762470bdb6266b8
2024-01-08 21:38:47 +07:00
Andreas Eversberg e4c7b0adcd ASCI: Add decoding of mobile identity in TALKER INDICATION
gsm48.c provides a function to decode mobile identity from various
messages. TALKER INDICATION is sent by the talking subscriber of a voice
group call to idenitfy the current talker. The mobile identity is
required to distinguish between calling subscriber and other subscribers.

Related: OS#4854
Change-Id: I331fac82e3c15abb01f554b2e70576100f2eea2d
2023-06-28 11:54:55 +00:00
Andreas Eversberg 72ab3b5200 ASCI: Also display group/broadcast call message names
gsm48_pdisc_msgtype_name* will include group and broadcast call control
message names too.

Change-Id: I1874e61c24cd8e66b74171681d22f0bfe8069158
2023-06-28 11:52:16 +00: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
Neels Hofmeyr e25786ab6a gsm: add osmo_mobile_identity_decode_from_l3_buf()
We have osmo_mobile_identity_decode_from_l3(), which takes a msgb as
argument, and decodes msg->l3h. Not all callers have their data in this
form. Offer a more flexible API for the same decoding.

For example, before the new function, osmo-hnbgw, which extracts a NAS
PDU from asn.1 packed data for CN pooling, would allocate a new msgb and
copy the NAS data just to pass a data pointer as argument.

Related: SYS#6412
Change-Id: I9bd99ccd01f0eedc091fe51687ff92ae1fdff60b
2023-05-06 03:49:08 +00:00
Vadim Yanitskiy 173c84c52e gsm_04_08: add more enum gsm48_chan_mode data values
From 3GPP TS 44.018 (version 15.4.0), table 10.5.2.6.1.

Change-Id: Ia6b428e5b6aaecf151cbfa980b89eff6d0fe6006
Related: OS#1572
2023-03-23 18:38:11 +07:00
Vadim Yanitskiy 1c88ff9ba5 gsm_04_08: add more enum gsm48_chan_mode speech values
From 3GPP TS 44.018 (version 15.4.0), table 10.5.2.6.1.

Change-Id: I6adda28698c0e479ef20f5d090c1f7f76a2ec97e
Related: OS#1572
2023-03-23 18:38:11 +07:00
Pau Espin 559a6ee683 Fix parsing of TLV_TYPE_SINGLE_TV
The decoding path of TLV_TYPE_SINGLE_TV is wrong, since it is not
shifting right the tag before using it. On the other hand, the encoding
path (tlv_encode_one) is doing that, so it is clear there's a bug.

It seems that in order to workaround the bug some IEs in gsm_04_08.h (TS
24.008 and TS 44.018) were defined incorrectly (eg 0x80) while the spec
clearly assigns eg. "8" to it, and makes sure no full byte IEI collides.
Some other IEIs like GSM48_IE_GMM_CIPH_CKSN which are also of the same
type were already correctly defined as 0x08.

Change-Id: I799e35dc8d4d153fa63bf50563a5482cdf4de2d7
2023-03-22 14:23:51 +01:00
Max bc12728679 SI: add missing header
Previous SI10 patch added function without exposing it via public header.
Let's fix this.

Fixes: 600d4eeab7
Change-Id: Ia7530e9c8a21f6f99f3aac7baea5cbb38763c4f3
2023-01-30 18:52:41 +00:00
Max 600d4eeab7 SI: add RR short PD message types
Related: OS#5783
Change-Id: Ifbd0aabe826298fa4715eb4eb2ff8363e765933d
2023-01-25 09:09:35 +00:00
Pau Espin 6ca0a43294 gsm: constify several readonly params
Change-Id: Ib11bfe57f546a5618f70152b9b75115808e54bf6
2022-11-24 17:09:03 +01: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
Pau Espin 6fe865daae Make gcc 11.1.0 false positivies happy
After my system's gcc was upgraded, I get false positivies in a couple
places. Let's initialize those to make gcc happy.

"""
/git/libosmocore/src/socket.c: In function ‘osmo_sock_init’:
/git/libosmocore/src/socket.c:958:25: error: ‘sfd’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
  958 |                         close(sfd);
      |                         ^~~~~~~~~~

/git/libosmocore/src/gsm/gsm48.c: In function ‘osmo_mobile_identity_decode’:
/git/libosmocore/src/gsm/gsm48.c:690:20: error: ‘str_size’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
  690 |         if (rc < 1 || rc >= str_size) {
      |             ~~~~~~~^~~~~~~~~~~~~~~~~
/git/libosmocore/src/gsm/gsm48.c:679:22: error: ‘str’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
  679 |                 rc = osmo_bcd2str(str, str_size, mi_data, 1, 1 + nibbles_len, allow_hex);
      |                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"""

Change-Id: I8aacfbc21e23f63a65e8baee3fd536a1fe1bdd8a
2021-07-16 16:01:30 +00:00
Neels Hofmeyr 208c5b643f fixup for gsm48_chan_mode_to_non_vamos()
When modifying chan modes, I first thought rather always fail if there
is no equivalent mode.

That is true for gsm48_chan_mode_to_vamos(), but for a change to
non-VAMOS, rather return the unchanged mode for non-VAMOS modes, so that
gsm48_chan_mode_to_non_vamos(GSM_CMODE_SIGN) works without failure.

This makes more convenient checking, e.g. in osmo-bsc's lchan_fsm.c
making sure that a non-VAMOS lchan has a non-VAMOS chan_mode, for all
types of lchans.

Change-Id: Ibf20f04d167e0e0599012ff530bc17ba8c8ab562
2021-05-29 23:45:22 +00:00
Neels Hofmeyr 4b44ac4012 RR: add missing Extended TSC Set IE
Defined in 48.018 10.5.2.82.
This will be used by Channel Mode Modify for VAMOS.

Related: SYS#4895 SYS#5315
Change-Id: I9bad6e7121af43dfa9706635e58279ce672a4e14
2021-04-20 02:43:40 +02:00
Neels Hofmeyr a9da9f7640 RR: add VAMOS channel modes
Also add functions to convert between VAMOS and non-VAMOS speech modes.

Related: SYS#4895 SYS#5315
Change-Id: Ie0ea592da5610ae70290106d004e549cf3212a89
2021-04-20 02:42:42 +02:00
Philipp Maier d11a5d5b9a gsm48: add compare function for struct gprs_ra_id
Comparing struct gprs_ra_id using memcmp can be error prone, so lets add
a compare function to compare two struct gprs_ra_id values reliably.

Change-Id: I4d7558c04d9d01761516526086be5104bb2eeada
Related: SYS#5103
2021-02-04 15:17:41 +01:00
Vadim Yanitskiy f5f0d4304a gsm48: add missing RR cause value definitions
3GPP TS 44.018 version 15.4.0 Release 15 (2019-04).

Change-Id: If7187e005d65fd2bf067d258148281c5df0526ff
2020-10-29 18:23:06 +07:00
Vadim Yanitskiy 65954bac13 fix spelling in 'value_string' arrays: existAnt -> existEnt
It could be that this spelling variant was originally used in the
specs., but now at least in 3GPP TS 44.018 they use 'existEnt'.

Change-Id: I847de910411f2edf7cc45b8c296b43e65fed5447
2020-10-29 18:09:36 +07:00
Neels Hofmeyr 4247c94abf api comment: fix example of osmo_mobile_identity_encode_msgb
The previous example showed a type == IMSI while setting a TMSI value.
Rather show how to encode IMSI digits.

Change-Id: I41af6bf0d61443465172123297b1228584d791d6
2020-06-24 11:31:56 +00: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
Neels Hofmeyr 6d67032d50 fix osmo_mi_name_c() to always return talloced strings, via osmo_mi_name_buf()
Fix osmo_mi_name_buf() to snprintf() into the buf in *all* cases.

osmo_mi_name_c() is implemented via osmo_mi_name_buf(), which returns
compile-time string constants in special cases. That means that
osmo_mi_name_c() does return non-allocated strings in these special cases.
The caller of functions like osmo_mi_name_c() must always be able to rely on
getting a talloced string, or run a danger of deallocating const pointers.

Change-Id: I623959f01b72642bcdd18508097c5c405c59f6f1
2020-05-26 22:30:49 +02:00
Neels Hofmeyr 512bf02e41 api doc: clarify 'returns' of gsm48_mi_to_string()
Change-Id: I81646ff8284061a60c208bd8f9233f66c3e410f8
2020-05-26 22:30:49 +02: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
Vadim Yanitskiy 0d8da790df gsm/gsm48.h: drop meaningless 'const' from gsm48_mi_to_string()
Change-Id: I5eb17edadf89ac47b4ca86c9e822037f7c0e518e
2019-07-26 05:23:56 +00:00
Harald Welte 171ef826e1 make all library-internal static buffers thread-local
We have a number of library-internal static global buffers which are
mainly used for various stringification functions.  This worked as
all of the related Osmocom programs were strictly single-threaded.

Let's make those buffers at least thread-local.  This way every thread
gets their own set of buffers, and it's safe for multiple threads to
execute the same functions once.  They're of course still not
re-entrant.  If you need re-entrancy, you will need to use the _c()
or _buf() suffix version of those functions and work with your own
(stack or heap) buffers.

Change-Id: I50eb2436a7c1261d79a9d2955584dce92780ca07
2019-06-04 10:47:30 +02:00
Harald Welte 179f35702e Add _c versions of functions that otherwise return static buffers
We have a habit of returning static buffers from some functions,
particularly when generating some kind of string values.  This is
convenient in terms of memory management, but it comes at the expense
of not being thread-safe, and not allowing for two calls of the
related function within one printf() statement.

Let's introduce _c suffix versions of those functions where the
caller passes in a talloc context from which the output buffer shall
be allocated.

Change-Id: I8481c19b68ff67cfa22abb93c405ebcfcb0ab19b
2019-04-10 22:42:32 +00:00
Harald Welte 4a62eda225 Add _buf() functions to bypass static string buffers
We have a number of static buffers in use in libosmo*.  This means
the related functions are not usable in a thread-safe way.  While
we so far don't have many multi-threaded programs in the osmocom
universe, the static buffers also prevent us from calling the same
e.g. string-ify function twice within a single printf() call.

Let's make sure there's an alternative function in all those cases,
where the user can pass in a caller-allocated buffer + size, and make
the 'classic' function with the static buffer a wrapper around that
_buf() variant.

Change-Id: Ibf85f79e93244f53b2684ff6f1095c5b41203e05
2019-04-03 18:03:14 +02:00
Neels Hofmeyr 9e6f5f10bd osmo_gsm48_classmark_a5_name(): fix 'no-cm3' label
Change-Id: Id84021858dfb2f7d6a7cf81ae73bd94cd47f6776
2019-03-14 03:43:10 +00:00
Neels Hofmeyr 7740d26d7e add osmo_classmark_* API
osmo-bsc and osmo-msc implement identical Classmark structures. It makes sense
to define once near the gsm48 protocol definitions.

Also move along some generic Classmark API from osmo-msc.

Change-Id: Ifd27bab0380f7ad0c44c719aa6c8bd62cf7b034c
2019-01-29 00:59:32 +01:00
Harald Welte 1c3bae138c constrain gsm48_generate_mid() output array bounds
The longest BCd-digit type identity is the IMEISV with 16, so there's
no point in trying to parse up to 255 decimal digits, which will do
nothing but to overflow the caller-provided output buffer.

Let's also clearly define the required minimum size of the output
buffer and add a reltead #define for it.

Change-Id: Ic8488bc7f77dc9182e372741b88f0f06100dddc9
2019-01-22 14:53:46 +00:00
Neels Hofmeyr f8963f9d4e change GSM48_CMSERV_* to enum type, add names
Prepare handling multiple CM Service Requests in osmo-msc: an enum is more
clear than an int and #defines for passing around and count CM Service types.

Change-Id: I9c2a7adc45ab7a1a7519168e965e7d805e1481ff
2019-01-14 17:42:03 +00:00
Neels Hofmeyr 92f3f5e491 add osmo_lu_type_names[], osmo_lu_type_name()
Move lupd_names[] from osmo-msc to libosmo-gsm.

Change-Id: Ica25919758ef6cba8348da199b0ae7e0ba628798
2019-01-08 14:07:07 +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 6adffb9573 gsm48_mi_to_string(): do not read from zero length input buffer
Change-Id: I12cada7c2c5187146ca5a33d1ebfefb4cad65632
2018-12-10 17:06:30 +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 6aa20eee29 api doc: gsm48_mi_to_string(): warn of return value implementation
Change-Id: If5e7abd15dddf39cdfad8071f4cd5ca8244eabe0
2018-12-10 13:18:38 +01:00
Philipp Maier a75e349b28 gsm48: correct apidoc for gsm48_generate_mid()
The API documentation lacks the the description for the last parameter,
lets add a description for it.

Change-Id: Ibcd25d3a7ddd7075eb15daff6dba42236d14d945
2018-11-02 22:06:34 +00:00
Keith Whyte 3cdaa8d525 Add CC_CAUSE value_string array
Adds a value_string array for GSM 04.08 Call Control
cause values

Change-Id: I296f208581ce2550805f9d96e20f7319e1199023
2018-09-02 12:33:54 +02:00
Vadim Yanitskiy 30cfeeb4a0 libosmogsm: (re)introduce gsm48_push_l3hdr()
There was gsm0480_l3hdr_push() declared in a header file, but
not exposed in 'libosmogsm.map'. Furthermore, for some reason
it was a part of GSM 04.80 API, what is not actually correct.

Let's rename this symbol, and properly expose it as a part of
the GSM 04.08 API. Also, let's introduce an auxiliary wrapper
for messages, where the transaction identifier is required
(see GSM 04.07, section 11.2.3.1.2).

Change-Id: I8a045efe8335d83fcbe8d43eb180972e3b1d9dda
2018-08-05 23:21:43 +07:00
Vadim Yanitskiy 8d41d722d6 gsm/gsm48.c: add call independent SS message names
Change-Id: I697639d8469e5dda617b27995c4a92e1f0c0bead
2018-04-17 12:09:48 +00:00
Vadim Yanitskiy 07bfd565a8 protocol/gsm_04_08.h: drop incorrect GSM48_PDISC_USSD
According to the GSM TS 04.07, section 11.2.3.1.1 "Protocol
discriminator", bits 1 to 4 of the first octet of a standard
L3 message contain the protocol discriminator IE.

Meanwhile, the GSM48_PDISC_USSD represents value 0x11, i.e.
0b10001, that requires 5 bits, and moreover it is not
documented anywhere. Let's drop it.

Change-Id: Ic4eb8a6db4ff1dfd535bd0c84e7acf1908422f64
2018-04-17 12:09:48 +00:00
Neels Hofmeyr aead241df0 add gsm48_reject_value_names
There seems to be quite some confusion / overlap between enum
gsm48_reject_value, gsm48_gsm_cause and gsm48_gmm_cause. I tried to go with
gsm48_gsm_cause_names[], but e.g. GSM48_REJECT_CONGESTION is not represented.

Instead of attempting to mix/merge those enums, provide a separate value string
array for enum gsm48_reject_value.

This will be used by osmo-msc's libvlr (refactoring of FSM result handling),
I27bf8d68737ff1f8dc6d11fb1eac3d391aab0cb1.

Change-Id: I6661f139e68a498fb1bef10c266c2f064b72774a
2018-04-09 17:57:15 +02:00
Neels Hofmeyr c4fce1425e implement support for 3-digit MNC with leading zeros
Enable representing three-digit MNC with leading zeros. The MNCs 23 and 023 are
actually different; so far we treated both as 23. Re-encode an incoming BCD or
string of 023 as it were, i.e. not dropping the leading zero as 23.

Break ABI compatibility by changing the size and ordering of structs
gprs_ra_id, osmo_plmn_id, osmo_cell_global_id, ... by adding an mnc_3_digits
flag.

Change ordering in gprs_ra_id because the canonical oder is {Mobile Country
Code, Mobile Network Code}, so have the mcc member first.

ABI compatibility cannot be maintained for struct gprs_ra_id, since it is a
direct member of structs bssgp_bvc_ctx and bssgp_paging_info, and even just
adding a flag to the end would cause ABI changes of those structs. Similarly,
osmo_plmn_id is a direct member of osmo_location_area_id, and so forth.

Add new API to set and read this additional flag to preserve leading zeros:
- osmo_plmn_to_bcd(), osmo_plmn_from_bcd() after
  gsm48_mcc_mnc_to_bcd() and gsm48_mcc_mnc_from_bcd().
- gsm48_decode_lai2(), gsm48_generate_lai2() after
  gsm48_decode_lai(), gsm48_generate_lai().
- gsm0808_create_layer3_2() after gsm0808_create_layer3() and gsm0808_create_layer3_aoip().
- various osmo_*_name() functions in gsm23003.h (osmo_rai_name() still in
  gsm48.h close to struct gprs_ra_id definition). The amount and duplication of
  these may seem a bit overboard, but IMO they do make sense in this way.
  Though most code will soon see patches unifying the data structures used, in
  some cases (vty, ctrl) they are required singled out. Without these
  functions, the formatting ("%0*u", mnc_3_digits ?  3 : 2, mnc) would be
  duplicated all over our diverse repositories.

In various log output, include the leading MNC zeros.

Mark one TODO in card_fs_sim.c, I am not sure how to communicate a leading zero
to/from a SIM card FS. The focus here is on the core network / BSS.

To indicate ABI incompatibility, bump libosmogsm and libosmogb LIBVERSIONs;
adjust debian files accordingly.

Implementation choices:

- The default behavior upon zero-initialization will be the mnc_3_digits flag
  set to false, which yields exactly the previous behavior.

- I decided against packing the mnc with the mnc_3_digits field into a
  sub-struct because it would immediately break all builds of dependent
  projects: it would require immediate merging of numerous patches in other
  repositories, and it would make compiling older code against a newer
  libosmocore unneccessarily hard.

Change-Id: Id2240f7f518494c9df6c8bda52c0d5092f90f221
2018-02-28 19:26:33 +01:00
Harald Welte 92decf2aa9 Revert "Add function to encode classmark"
This breaks all existing / older osmocom-bb builds, and hence
cannot be accpeted. See also https://gerrit.osmocom.org/#/c/6679

Related: OS#2985

This reverts commit 3c38e60cd5.

Change-Id: Icfc52ca4e5cbe3a444d98037d27fa101e3614e06
2018-02-22 16:17:41 +01:00
Max 3c38e60cd5 Add function to encode classmark
The code is based on Osmocom-BB implementation.

Change-Id: I78f6968edaa3ed535673411fb2a80060a472290f
2018-02-15 16:14:19 +01:00