Commit Graph

24 Commits

Author SHA1 Message Date
Max 84fb5bb6a0 Move msgb_push helpers to public header
The msgb_wrap_with_TL() is generally useful so it make sense to make it
public to facilitate code re-use.

Other helpers can be implemented as trivial wrappers over existing tlv.h
functions. Update headers and code accordingly.

Change-Id: I37e91d031fba28cf1c6735b8069b0265746f55e6
2018-11-19 05:47:25 +00:00
Harald Welte 1fbe3eba75 tlv: Add TLVP_VAL_MINLEN() to obtain value _if_ length is >= minimum
This is a combination of TLVP_VAP() and TLVP_GET_MINLEN()

Change-Id: Ic5a177941219ebc3a3bceb3f68bdb3b2cacb934b
2018-06-02 12:53:29 +00:00
Neels Hofmeyr 74e4ed6f36 tlv: add TLV_GET() and TLV_GET_MINLEN()
Rationale: so far we use code like

  if (TLVP_PRESENT(&tp, VERY_LONG_ENUM_VALUE_NAME_THAT_NEVER_ENDS)) {
  	val = TLVP_VAL(&tp, VERY_LONG_ENUM_VALUE_NAME_THAT_NEVER_ENDS);
	len = TLVP_LEN(&tp, VERY_L0NG_ENUM_VALUE_NAME_TH4T_NEVER_EMDS);
  }

This is a) very long and b) prone to picking the wrong name one of the three
times, which would use the wrong length or val without necessarily being
noticed. A safer and shorter, more readable pattern is:

  struct tlv_p_entry *e = TVLP_GET(&tp, VERY_LONG_ENUM_VALUE_NAME_THAT_NEVER_ENDS);
  if (!e)
        return -ENOENT;
  hexdump(e->val, e->len);

Change-Id: I445de17fc2daa3ab051f5708dd0cc185b23dc048
2018-04-18 02:38:37 +02:00
Neels Hofmeyr a78b22ba20 add tlv_parse2(), capable of multiple instances of the same IE
Allow passing multiple struct tlv_parsed in an array, to allow parsing as many
repeated IEs as are expected by the caller.

From tlv_parse(), call tlv_parse2() with dec_multiple = 1 to yield the previous
behavior. tlv_parse() remains valid API.

An example of multiple IEs is the BSSMAP Handover Request, containing Cell
Identifier (Serving) and Cell Identifier (Target), both defined by 3GPP TS
48.008 3.2.2.17 with identical IE tags; both are mandatory.

Related: OS#2283 (inter-BSC HO, BSC side)
Change-Id: Id04008eaf0a1cafdbdc11b7efc556e3035b1c84d
2018-04-13 05:28:09 +02:00
Neels Hofmeyr e750980d6c tlv_put: guard against NULL val and 0 len
For example encode_auth_info() from gsup.c calls
  msgb_tlv_put(msg, iei, 0, NULL)
to put a tag and len with content data following later.

However, this would cause a memcpy() from a NULL pointer, in tlv_put(). Allow
passing NULL and len = 0 for cases like the above:

If val is NULL, use memset(0) instead of memcpy().
If len is zero, do not copy nor memset anything.

Hence make tlv_put() behave in a well-defined and valid way for any and all
input args; no negative fallout is possible from this patch.

Add proper API doc comment.

Fixes a sanitizer build failure in gsup_test:

  ../../../../src/libosmocore/include/osmocom/gsm/tlv.h:99:2: runtime error: null pointer passed as argument 2, which is declared to never be null

Helps fix sanitizer build on debian 9.

Change-Id: I13dce9cd1228817890d3e81edeeb660c893c1d64
2017-11-20 17:22:42 +01:00
Harald Welte 9325d86192 [doc] TLV parser has far grown beyond GSM L3
Let's hence not call the group "GSM L3 compatible TLV parser"

Change-Id: Ic53f9c0d5ee787f994f42cf2aff313c6e131fbe6
2017-10-16 15:32:43 +02:00
Harald Welte 4a29f34813 tlv: add [msgb_]t16lv_put() for 16bit tag + 8 bit len TLVs
In the Protocol Configuration Options IE (see 3GPP TS 24.008 10.5.6.3)
there is yet another new TLV format (derived from PPP IPCP/LCP/...)
which uses 16bit tag and 8bit length.  Let's add functions so we can
generate related TLVs.  Parsing is unfortunately not possible in our
existing structure as our tlv_parsed array only has 256 entries and
thus cannot cope with 16bit tags.

Change-Id: I9799130e2eba8fae8c4480fbb8a900c30232b694
2017-08-09 19:02:12 +02:00
Neels Hofmeyr 17518fe393 doxygen: unify use of \file across the board
Considering the various styles and implications found in the sources, edit
scores of files to follow the same API doc guidelines around the doxygen
grouping and the \file tag.

Many files now show a short description in the generated API doc that was so
far only available as C comment.

The guidelines and reasoning behind it is documented at
https://osmocom.org/projects/cellular-infrastructure/wiki/Guidelines_for_API_documentation

In some instances, remove file comments and add to the corresponding group
instead, to be shared among several files (e.g. bitvec).

Change-Id: Ifa70e77e90462b5eb2b0457c70fd25275910c72b
2017-06-23 00:18:23 +00:00
Neels Hofmeyr 87e4550585 doxygen: enable AUTOBRIEF, drop \brief
Especially for short descriptions, it is annoying to have to type \brief for
every single API doc.

Drop all \brief and enable the AUTOBRIEF feature of doxygen, which always takes
the first sentence of an API doc as the brief description.

Change-Id: I11a8a821b065a128108641a2a63fb5a2b1916e87
2017-06-23 00:18:22 +00:00
Vadim Yanitskiy ac9e2d8aa5 gsm/tlv.h: fix copy-paste error
Change-Id: Id52ddd8358fd4af1ecc71142deb09f1e237021f3
2017-05-15 12:51:15 +00:00
Harald Welte 50ef73377c tlv: Add tlvp_val{16,32}be() to get TLV values in unaligned host byte order
Change-Id: I3749e1e4974742bc8c32722e0e998775b5394829
2017-05-15 13:42:03 +02:00
Max dbd3a92f70 Add parsed TLV helpers from OsmoBTS
Add functions to copy and merge parsed TLV structures from OsmoBTS.

Change-Id: Ieaaaed19da9c069fe451faa53d24c5b84d7d5615
2017-01-06 10:21:11 +00:00
Harald Welte fbd02fa8cc tlv: Import osmo_shift_* and osmo_match_shift_* from openbsc
These routines have nothing to do with specifically the BSC, so import
them to the TLV parser we keep in libosmogsm.
2016-05-05 18:49:27 +02:00
Neels Hofmeyr 9e57a5a697 some comments / fixed typos 2015-12-21 11:25:05 +01:00
Harald Welte cc27fa6479 TLV: add TLVP_PRES_LEN() definition to check for existance + minimum length
This is an import from osmo-bts where it was introduced in
6b561bb7ba5f10c5fd96542a7e42de2822352a67
2014-08-18 15:31:04 +02:00
Sylvain Munaut 12ba778afd include: Switch to #pragma once pattern
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2014-06-16 10:17:27 +02:00
Andreas Eversberg 0167596c2b Add tlvp_val16_unal() / tlvp_val32_unal() to align 16 and 32 bit values
This is required for CPUs < armv6, to access 16 and 32 values at right
memory locations.
2012-12-18 23:47:45 +01:00
Harald Welte 2fe684755a TLV: add new "vTvLV" type for GAN
This new TLV type is specific to TS 44.318.  Contrary to the TvLV type
of TS 08.16/08.18, it has an inverted meaning of the extension (0x80)
bit:
	* if the extension bit is not set, 1-byte length
	* if the extension bit is set, 2-byte length

Futhermore, it has support for variable-length tags, where the tag part
can be optionally two bytes in length.  As this esoteric option hasn't
been seen in the wild yet, we only add encoding support but skip
decoding for now.
2012-07-14 01:50:33 +02:00
Sylvain Munaut dca7d2caaa doc: Fix the Doxygen section endings
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2012-04-18 21:53:23 +02:00
Harald Welte 2c02043f49 TLV/msgb: Return first byte of newly-pushed data from msgb_*_push()
The msgb_*_push() functions erroneously returned the firsrt byte after
newly-pushed information, which makes no sense at all.
2012-01-22 23:10:40 +01:00
Harald Welte 57c7d37059 doxygen: Add documentation about TLV parser 2011-08-17 17:50:55 +02:00
Harald Welte e0aa5bb9f7 gsm 04.80: fix typo (256, not 265!)
This was introduced by me in commit
79599ba0eb

Thanks to Alexander Huemer for detecting it
2011-07-16 15:42:46 +02:00
Harald Welte 79599ba0eb tlv: Make tlv parser arrays 256 entries wide to prevent overflow on 0xff
If we encounter a tag with 0xFF, we overflow our existing tlv_parse
array definitions.

Warning: this breaks ABI
2011-07-16 12:08:28 +02:00
Pablo Neira Ayuso 8341934844 include: reorganize headers file to include/osmocom/[gsm|core]
This patch moves all GSM-specific definitions to include/osmocom/gsm.
Moreover, the headers in include/osmocore/ have been moved to
include/osmocom/core.

This has been proposed by Harald Welte and Sylvain Munaunt.

Tested with `make distcheck'.

Signed-off-by: Pablo Neira Ayuso <pablo@gnumonks.org>
2011-03-23 18:09:28 +01:00