Commit Graph

1985 Commits

Author SHA1 Message Date
Neels Hofmeyr 4cb0c8b45e linuxlist.h: add llist_first/last_entry macros
Copy list_first_entry, list_first_entry_or_null and list_last_entry from
current linux kernel's tools/include/linux/list.h and rename to llist_*.
Slightly adjust API doc but stay as close to the source as possible.

This can replace similar implementations in osmo-bts-octphy's l1_if.c,
in openbsc's gtphub.c and in osmo-hlr's gsup_server.c.

Change-Id: I4eac5be0c0b2cede04464c4c3a0873102d952453
2017-03-15 12:58:00 +00:00
Neels Hofmeyr 45e778d397 milenage_test: enhance to verify new SQN increments
After the legacy mode incrementing with ind_bitlen == 0 is through, do another
AUTS run with sensible ind_bitlen and ind, and then two more normal vector
generations to verify proper SQN increments.

Related: OS#1968
Change-Id: Id6947899ff7b1c82b939f969e163e51ce282bce2
2017-03-15 12:46:08 +00:00
Neels Hofmeyr bb6f7b7bec osmo_auth_gen_vec: UMTS auth: fix SQN as SEQ || IND
So far we incremented SQN by 1, which doesn't match the procedures described in
3GPP TS 33.102. An IND (index) denotes a non-significant part of SQN, and the
significant SEQ part needs to be incremented.

In OsmoHLR we furthermore want to use the "exception" suggested in annex C.3.4,
so that each HLR's client has a fixed IND index. In other words, we will not
assign IND cyclically, but keep IND unchanged per auth vector consumer.

Add 'ind_bitlen' and 'ind' to the osmo_sub_auth_data.u.umts structure and
increment SQN accordingly.

Add a comment explaining the details.

Because 'ind_bitlen' is still passed as zero, the milenage_test does not change
its behavior, which is a feature I want to clearly show in this patch. The test
will be expanded for the newly implemented SQN scheme in a subsequent patch.

Adjust osmo-auc-gen.c to still show the right SQN and SQN.MS -- because it is
passing ind_bitlen == 0, osmo-auc-gen can rely on single increments and know
SQN.MS is sqn - 1. Note that osmo-auc-gen_test output remains unchanged.

Related: OS#1968
Change-Id: Ibc97e1736a797ffcbf8c1f7d41c5c4518f4e41bf
2017-03-15 12:46:08 +00:00
Neels Hofmeyr 82c9a0ec19 osmo_auth_gen_vec: UMTS auth: store last used SQN, not next
Prepare for the implementation of splitting SQN increments in SEQ and an IND
part; particularly to clearly show where the changes in auth/milenage_test's
expectations originate.

Rationale: the source of UMTS auth vectors, for us usually OsmoHLR, typically
stores the last used SQN, not the next one to be used. Particularly with the
upcoming fix of the SQN scheme, this change is important: the next SQN will
depend on which entity asks for it, because each auth consumer may have a
particular slot in the IND part of SQN. It does not make sense to store the
next SQN, because we will not know which consumer that will be for.

The milenage_test has always calculated a tuple for SQN == 34. To account for
the increment now happening before calculating a tuple, lower the test_aud->sqn
by one to 0x21 == 33, so that it is still calculating for SQN == 34.

Because we are no longer incrementing SQN after the tuple is generated,
milenage_test's expected output after doing an AUTS resync to 31 changes to the
next SQN = 32, the SQN used for the generated tuple.

(BTW, a subsequent patch will illustrate AUTS in detail.)

osmo-auc-gen now needs to pass the user requested SQN less one, because the SQN
will be incremented befor generating the auth vector. Also the SQN remains the
same after generating, so SQN output needs less decrementing. Note that the
expected output for osmo-auc-gen_test remains unchanged, hence the same input
arguments (particularly -s <sqn> and -A <auts>) still produce the same results.

Note: osmo-hlr regression tests will require adjustments when this patch is
merged, because it must now pass desired_sqn - 1 instead of just desired_sqn.
See osmo-hlr change-id I4ec5a578537acb1d9e1ebfe00a72417fc3ca5894 .

Related: OS#1968
Change-Id: Iadf43f21e0605e9e85f7e8026c40985f7ceff1a3
2017-03-15 12:46:08 +00:00
Neels Hofmeyr 5fe3d1b0f7 osmo-auc-gen: clarify SQN output, prepare for SQN changes
Upcoming patches will change the way SQN are incremented. Change the SQN
related output by osmo-auc-gen so that it also makes sense after these changes,
and so that its output is proven to remain unchanged for the same arguments:

Always show the SQN used for vector generation when a UMTS vector was generated.

Don't show the next SQN, it will not make sense anymore (see later patches).

The adjustments of expected output of osmo-auc-gen_test illustrates how the
output changes.

Related: OS#1968
Change-Id: I35d9c669002ff3e8570e07b444cca34ce57c3b0c
2017-03-15 12:46:08 +00:00
Neels Hofmeyr d3b58730d5 add osmo-auc-gen_test
Add test for osmo-auc-gen invocations to ensure stability across upcoming SQN
increment scheme changes.

The test comprises of a shell script that invokes the osmo-auc-gen binary with
various milenage parameters, of which the stdout/stderr are verified.

More osmo-auc-gen invocations could be added, but my main focus is on the SEQ
changes. Instead of manually testing that it still works for each SQN patch, I
want this test to do it for me.

To make sure that osmo-auc-gen is build before the tests are launched, place
'utils' before 'tests' in the root Makefile.am.

Related: OS#1968
Change-Id: Ib4af34201cd2e7d76037bcd31dd89ef18c1a9aec
2017-03-15 12:46:08 +00:00
Neels Hofmeyr 8e1b598c8a milenage_test: cosmetic fix: shown value is not SEQ.MS
In the milenage_test, the console output printed "SEQ.MS = 33", but 33 is
a) the SQN, not SEQ;
b) the SQN *after* the next auth generation, i.e. SQN.MS would have been 31.

While at it also use the proper PRIu64 from inttypes.h to output the sqn value.

This prepares for upcoming sparation of SQN incrementing by SEQ and IND,
particularly to clearly show where the changes in auth/milenage_test's
expectations originate.

Related: OS#1968
Change-Id: Ie83201f1362f3d793ada774f3fc5f89cc0b3fbb7
2017-03-15 12:46:08 +00:00
Harald Welte c733d1421a lapd_core: Use 'struct value_string' for LAPD state names
We don't really use state numbers without bounds check into string
tables since March 2010, when value_string became part of libosmocore.

It's time to catch up, 7 years later...

Change-Id: I1dac7b4cb441a1119cc167112521e8b8aae62e63
2017-03-15 10:24:25 +01:00
Harald Welte 486ac55f69 Doxygen: exclude osmocom/core/gsm/protocol/*
We don't document the header files that define structs/enums/types
that are taken 1:1 from the relevant GSM specifications.  So let's avoid
having doxygen generate tons of warnings for related undocumented
members.

Change-Id: I231f78972a015902e4085aa80fcbc04009ae9f13
2017-03-15 09:13:38 +00:00
Alexander Couzens 953f929797 gsm_04_08: add _NUM_CHREQ_T to enum
_NUM_CHREQ_T defines the last element of the enum

Change-Id: Id67ba8de89dd6288e449197438e9e1c5d7f5a134
2017-03-14 13:47:29 +01:00
Alexander Couzens f48e8a8ba9 gsm0408: add chreq_type for CHREQ_T_PDCH_ONE_PHASE and CHREQ_T_PDCH_TWO_PHASE
The previous version of this commit got reverted to avoid a breakage in openbsc.
The problem is openbsc use an array of chreq_type with a manual defined size. This array
is using enums as index which breaks if any elements got added into the
middle, because the size of the array can't hold elements greater or
equal than the size.

Change-Id: I6676105507fe4e5627f740dfe4c2770f766ad068
2017-03-14 13:30:13 +01:00
Neels Hofmeyr 6d0fd7ba97 build: cosmetic: coding: break a CPPFLAGS line
Matches our general scheme and helps readability of an upcoming patch.

Change-Id: I174086a988b51b6e80f3661609069b69a3d41cc7
2017-03-13 14:49:12 +01:00
Max b14caa0ab9 libosmocoding: fix .deb building
dpkg-buildpackage fails due to missing file descriptions - add necessary
.install and .doc-base files to fix it.

Change-Id: I5fb7e813c0860a3b5037e805deb84f9bf649ffa3
2017-03-07 15:36:33 +01:00
Vadim Yanitskiy 3262f820b5 libosmocoding: migrate transcoding routines from OsmoBTS
There are some projects, such as GR-GSM and OsmocomBB, which would
benefit from using one shared implementation of GSM 05.03 code. So,
this commit introduces a new sub-library called libosmocoding, which
(for now) provides GSM, GPRS and EDGE transcoding routines, migrated
from OsmoBTS.

The original GSM 05.03 code from OsmoBTS was relicensed under
GPLv2-or-later with permission of copyright holders (Andreas Eversberg,
Alexander Chemeris and Tom Tsou).

The following data types are currently supported:

 - xCCH
 - PDTCH (CS 1-4 and MCS 1-9)
 - TCH/FR
 - TCH/HR
 - TCH/AFS
 - RCH/AHS
 - RACH
 - SCH

Change-Id: I0c3256b87686d878e4e716d12393cad5924fdfa1
2017-03-07 01:06:38 +07:00
Vadim Yanitskiy 68930e85b5 tests/conv: separate test logic
To be able to add some more tests, related to convolutional coding,
without duplication of code, the test logic was separated from the
conv_test.c into conv.c and conv.h.

Change-Id: Idbdc7e19cb9b9a36cd1fccd621cd858e87530d98
2017-03-06 17:06:45 +00:00
Vadim Yanitskiy 77a5b0946f gsm0503.h: generate header automatically
Since we have automatic header generation, implemented in the
utils/conv_gen.py, it's time to use this feature!

Change-Id: I21caa4e433b2cc1861611e35350a9671da444c2a
2017-03-06 17:06:45 +00:00
Vadim Yanitskiy 804c4c7d42 utils/conv_gen.py: add header generation feature
Change-Id: Iae830d716f01810972edbef14fc5383ac647d0ea
2017-03-06 17:06:45 +00:00
Vadim Yanitskiy e9a90ee0d5 utils/conv_gen.py: add test vectors generation feature
Change-Id: Ie10c47ee952f253b1ba77ecf6e79f2c033545bc1
2017-03-06 17:06:45 +00:00
Neels Hofmeyr cb5c4edda9 ctrl_type_vals: fix range check
In ctrl_cmd_parse(), fix missing check for not parseable ctrl type.

Fixup for Icd4e96dd9f00876cb70b43cfcf42ab4f10311b28.

Change-Id: I7f8055225e3ee04b2a723bae07b12c42618963a0
2017-03-06 14:35:54 +00:00
Max 777be2e734 Check for proper lapdm_datalink entity
Previously lapdm_datalink->entity->mode was dereferenced without
checking if correct entity is present. This might lead to
segfault. Check it explicitly before dereferencing, log error and
gracefully return if necessary.

Change-Id: I0361e3731e86712b415a370cab1128d611988f56
Related: OS#1898
2017-03-02 14:10:06 +00:00
Neels Hofmeyr 90fdb08e3e fix: gsm0808.c: unterminated value_string array gsm0808_bssap_names
Change-Id: Ie38bae32372dc41e1902a8f6f0bc550ae515cfb8
2017-03-02 01:48:10 +00:00
Neels Hofmeyr fca04bba5a fsm: convenience: add inline osmo_fsm_inst_state_name()
Change-Id: If9a6ecc4d6e2beaf716569e9a6053d73488e860b
2017-03-01 23:52:55 +00:00
Max 2ed3659cac Handle replies in ctrl_cmd_handle()
Previously *_REPLY and ERROR messages were not explicitly handled which
would lead to sending error in response to them which in turn would
prompt other party to send error as well which would result in infinite
cycle.

Handle it explicitly by logging message id and other relevant data.

Change-Id: Id96f3a2fc81fa4549f49556d83f062c6b2f59e28
Related: OS#1615
2017-03-01 16:37:59 +00:00
Max 70c7d4160d Use value_string for ctrl_type
Use value_string for enum ctrl_type instead of custom code. Add
corresponding unit tests.

Related: OS#1615
Change-Id: Icd4e96dd9f00876cb70b43cfcf42ab4f10311b28
2017-03-01 16:37:59 +00:00
Max 9756c4691d Fix client-side ctrl interface helpers
* remove unused ctrl_interface_connect() which is not part of public API
* add default read callback to osmo_ctrl_conn_alloc()

Change-Id: Iaa209e34a849ce0dfe2e29b482c3208ade1a32a4
Related: OS#1615
2017-03-01 16:37:59 +00:00
Holger Hans Peter Freyther a2c5811238 Export comp128 v2 and v3 routines as well
It is in the public header file and allows to easily bind it from
other languages (without having to go through the abstraction).

Change-Id: I0128d529c52ec030cfb87b0aff3c69cadf2c59d2
2017-02-27 16:54:00 +07:00
Neels Hofmeyr fa5dc93fd0 ports.h: rename CSCN to MSC
See OS#1958

Change-Id: I85aee0f8fdfc9c69d0ba9240988c633d3e707f2d
2017-02-24 19:57:48 +00:00
Harald Welte a1004640ce libosmoctrl: Fix typo in ctrl_interface_connect()
it's osmo_sock_init_ofd(), not osmo_sock_init_ifd()

Change-Id: Ia6a82031a691403f641815862613d99b31a3a159
2017-02-23 21:07:01 +01:00
Max fa9e05e7e8 Expand and expose ctrl connection allocation
Add function for allocating CTRL connection to public headers and
replace call to previous static function with it. Add doxygen docs for
this function.

It's useful if we need to allocate ctrl connection but don't need to
bind to any interfaces: when we act as ctrl client.

Related: OS#1615
Change-Id: I522ed809cbebfd3d7dd08b4ed9137b39ff192e32
2017-02-23 17:30:44 +00:00
Neels Hofmeyr 8b86cd76cf logging.h: fixup: shorter names for LOGGING_FILTER_* and LOGGING_CTX_*
My recent logging patch was merged to master a bit too soon. Accomodate the
request for naming that matches the general "LOG" prefix instead of "LOGGING".

libosmocore will not be backwards-compatible with the few commits from
change-id I5c343630020f4b108099696fd96c2111614c8067 up to this one. This and
following commits are backwards compatible with those before that short window.

See also:
* openbsc change-id Ib2ec5e4884aa90f48051ee2f832af557aa525991
* osmo-pcu change-id I4db4a668f2be07f3d55f848d38d1b490d8a7a685

Change-Id: I424fe3f12ea620338902b2bb8230544bde3f1a93
2017-02-23 18:08:12 +01:00
Neels Hofmeyr 492e1808b0 logging.h: fixup: add API doc for logging enums recently added
Change-Id: Ic459b04219abe70171c8f80ed09df53d412dcfb2
2017-02-23 17:53:23 +01:00
Neels Hofmeyr 0d6420b302 logging.h: fix backwards compat broken by recent commit
Commit 812ba6dc63
"logging: centrally define ctx and filter indexes"
Removed definitions, which causes older e.g. openbsc and osmo-pcu code trees to
fail to build against a newer libosmocore. Re-introduce the legacy definitions
to redirect to the new ones and re-establish backwards compatibility.

The GPRS_* constants used to be defined in gprs_msgb.h, but since that header
also includes logging.h, rather place the legacy shims in logging.h next to the
other ones.

Change-Id: I455bb1bb474d758af0fd5b6397f7e57260ad739d
2017-02-23 17:53:07 +01:00
Neels Hofmeyr d1c2fc6de1 gsm_04_08.h: add R99 MSCR and CBQ3 to SI3 Ctrl Chan Descr
MSCR and CBQ3 are Release 1999 additions to the Control Channel Description IE
of SI3.

Assuming that no-one is using the spare bits, this will not cause any code
conflicts.

In the R99 struct, spare1 and spare2 are in different places, so rather rename
them to spare_1 and spare_2 to make sure we get a compiler barf *if* anyone
tries to use them with the wrong structure.

Adjust the spec reference to TS 44.018; TS 04.08 Figure 10.5.33 is replaced by
TS 44.018 Figure 10.5.2.11.1 which is right there in the named Section
10.5.2.11, so drop the explicit reference.

Motivation: the R99 Control Channel Description defines MSCR to indicate
whether the MSC is R99+ or not. To use UMTS AKA on GSM networks, we want to
indicate that our libmsc is capable of R99, like OsmoSGSN already does.

CBQ3 is merely added for completeness, no particular use case in mind.

Related: OS#1593
Change-Id: If87e07b5d04e1617155383e14c98d2125fdd0608
2017-02-23 03:39:36 +01:00
Neels Hofmeyr 812ba6dc63 logging: centrally define ctx and filter indexes
It is too easy for calling code to use the same filter and context indexes for
different filters and structs. For example, openbsc's IMSI filter and libgb's
GPRS_BVC filter both fall on index 1 even though there are plenty more indexes
to choose from. To alleviate this, have one central definition here, sort of
like ports.h does for VTY and CTRL port numbers.

Add static asserts to make sure the indexes fit in the available array and bit
mask space.

Calling code like openbsc.git and osmo-pcu need adjustments and/or should move
to using these enum values instead of their local definitions.

Taking this opportunity to also prepare for a split of struct gsm_subscriber in
openbsc into bsc_subsciber and vlr_subscriber with appropriate separate filter
index constants for both subscriber types.

Include previous LOG_FILTER_ALL in the LOGGING_FILTER_* enum, and replace its
use by (1 << LOGGING_FILTER_ALL).

Change-Id: I5c343630020f4b108099696fd96c2111614c8067
2017-02-22 16:08:38 +00:00
Neels Hofmeyr bd9de2f66f gsup_test: also check stderr
Configure logging to be deterministic and add stderr checking to testuite.at.

However, exclude the thousands of message modification log lines from the log
to not have a huge test expectation file.

Change-Id: I0dd7112967a64a168556b62e5ec15107b7608ffb
2017-02-22 07:29:46 +00:00
Neels Hofmeyr abb23698d6 gsup test: add decoding test for UMTS IEs
This would have caught the wrong expectation of AUTS' length fixed recently
(3a5ca647c5).

Besides AUTS, add AUTN, RES, CK, IK which were also not tested yet.

Change-Id: I6fddf8d7ce97137b0a585d365807bcaf90a319d0
Related: OS#1593
2017-02-22 07:29:46 +00:00
Neels Hofmeyr 3b8cb39e7c fix osmo_auth_gen_vec_auts: copy rand to auth vector
Related: OS#1593
Change-Id: If943731a78089f0aac3d55245de80596d01314a4
2017-02-22 03:12:51 +01:00
Neels Hofmeyr 3a5ca647c5 gsup decode: fix expectation of AUTS length, should be 14
The wrong expectation caused OsmoHLR to fail on Auth Sync.

Change-Id: I277fb3d407396dffa5c07a9c5454d87a415d393f
2017-02-21 16:19:40 +01:00
Max 32ee5af893 Document ctrl_interface_setup_dynip() function
Change-Id: Ie1d5881dda7a9b797d15e9e1eead8281a994d91e
2017-02-19 08:54:27 +00:00
Neels Hofmeyr 8fcc81db66 fix: gprs_bssgp_vty: logging filter: wrong constant
Setting the BVC log filter to NULL worked only if the NSVC filter was set,
use the proper constant instead.

Change-Id: Ic1cc268ed20700698c93d3ff8bf85cc0f01d3b1b
2017-02-17 16:38:17 +01:00
Neels Hofmeyr 10f5fb49db gsup: add osmo_gsup_message_type_name()
Change-Id: Ic29b588b72893821d73fe90ecc16c6bf78d5a360
2017-02-15 23:26:07 +00:00
ikostov 3e6d5701e6 OAP:remove design doc. osmocom-authn-protocol.txt
Osmocom Authentication Protocol design document
 is removed from libosmocore project as this
 information has been included in the User Manual.
 It is present in SGSN User Manual.

 relates to OS#1874

Change-Id: I2d4dc608622a7484e67b15f930efc76e28285045
2017-02-15 17:56:39 +01:00
Neels Hofmeyr 437ed4ab42 osmo_hexparse: allow whitespace in parsed string, add ws test
This is particularly useful for hex dumps containing spaces found in a log
(e.g. osmo-nitb authentication rand token), which can now be passed in quotes
to osmo-auc-gen without having to edit the spaces away.

Change-Id: Ib7af07f674a2d26c8569acdee98835fb3e626c45
2017-02-14 15:59:22 +01:00
Neels Hofmeyr 7adb567ffb utils: add hexparse test
Change-Id: Ic95ab00b57d54905a235109561c00419161cf4bc
2017-02-14 15:56:40 +01:00
Max af4bb17a93 Add CTRL port for OsmoHLR
Change-Id: I1328c89ec8e908bf4b4d2c0a398690278369e0f5
Related: OS#1645
2017-02-14 12:13:32 +01:00
Philipp Maier 6f0f560eab cosmetic: replace fprintf with LOGP
socket.c still uses fprintf to output error messages. This commit
replaces the fprintf with proper LOGP messages.

Change-Id: Ia2993415d5f5c33ccd719af239ff59252d11b764
2017-02-09 16:21:01 +01:00
Vadim Yanitskiy 2c717948d9 utils/conv_gen.py: improve application flexibility
This change makes the conv_gen application more interactive
and flexible, allowing to generate not only code definitions
but also the test vectors and header files in the future.
Moreover, it becomes possible to select exact code family,
such as GSM, GMR etc.

Change-Id: I0b476b00234c17f78b41d695cf3bfd13edb64c28
2017-02-09 06:39:58 +00:00
Harald Welte 4ffb43f654 Add minimal testing of socket.c helper functions
Change-Id: I2773b3859a206f96fb8fa095d50a653d9eeb8d79
2017-02-08 18:23:06 +01:00
Harald Welte f12d40f4df fix various compiler warnings (on FreeBSD-11.0)
FreeBSD 11.0 uses clang version 3.8.0 which spits various warnings
during libosmocore compilation.  Let's clean this up a bit.

Change-Id: Ic14572e6970bd0b8916604fabf807f1608fa07e5
2017-02-08 16:49:14 +01:00
Philipp Maier 6b986c2422 lapd_core: Fix MDL-ERROR ind after RELEASE ind
in lapd_t200_cb() The RELEASE INDICATION is transmitted before
the MDL ERROR INIDCATION, this prevents the MDL ERROR INDICATION
from being sent because the RELASE INDICATION close to connection
eraly. This commit puts the messages into the correct order.

Change-Id: Iae74777138fc27828f511e3aa321d1981861f4a5
2017-02-07 13:39:01 +01:00