summaryrefslogtreecommitdiffstats
path: root/include/osmocom/gsm/tlv.h
Commit message (Collapse)AuthorAgeFilesLines
* TLV: Add one-shot TLV encoderHarald Welte2019-05-191-0/+6
| | | | | | | | | | | | | | | | | So far, the TLV code contained two types of functions * tlp_parse() to parse all TLVs according to definition into tlvp_parsed * various helper functions to encode individual TLVs during message generation This patch implements the inverse of tlv_parse(): tlv_encode(), which takes a full 'struct tlv_pared' and encodes all IEs found in it. The order of IEs is in numerically ascending order of the tag. As many protocols have different IE/TLV ordering requirements, let's add a tlv_encode_ordered() function where the caller can specify the TLV ordering during the one-shot encode. Change-Id: I761a30bf20355a9f80a4a8e0c60b0b0f78515efe
* TLV: add convenience function for 1-byte valuesMax2018-12-201-0/+16
| | | | | | | Similar to existing 16 and 32 bit value helpers but simpler because we don't have to worry about alingment and endianness. Change-Id: Ic0a148bd04b8860e321f509fdcd913f688c8e920
* TLV: fix doc copy-paste errorMax2018-12-201-1/+1
| | | | Change-Id: I8aa79cab7505585de00ee2aaae125462108906e8
* Add msgb_tl_put() helperMax2018-12-041-0/+12
| | | | | | | | | When adding complex TLV structures where length of V is not known in advance it's handy to be able to simply add Tag and save the pointer to the Length field so it can be updated once entire Value is added and its length is known. Change-Id: I8dc1e4880352833a0a49c1dd0d7cb4148ac43aff
* Move msgb_push helpers to public headerMax2018-11-191-0/+6
| | | | | | | | | | 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
* tlv: Add TLVP_VAL_MINLEN() to obtain value _if_ length is >= minimumHarald Welte2018-06-021-0/+10
| | | | | | This is a combination of TLVP_VAP() and TLVP_GET_MINLEN() Change-Id: Ic5a177941219ebc3a3bceb3f68bdb3b2cacb934b
* tlv: add TLV_GET() and TLV_GET_MINLEN()Neels Hofmeyr2018-04-181-0/+21
| | | | | | | | | | | | | | | | | | | | 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
* add tlv_parse2(), capable of multiple instances of the same IENeels Hofmeyr2018-04-131-0/+3
| | | | | | | | | | | | | | | 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
* tlv_put: guard against NULL val and 0 lenNeels Hofmeyr2017-11-201-2/+13
| | | | | | | | | | | | | | | | | | | | | | | | | 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
* [doc] TLV parser has far grown beyond GSM L3Harald Welte2017-10-161-1/+1
| | | | | | Let's hence not call the group "GSM L3 compatible TLV parser" Change-Id: Ic53f9c0d5ee787f994f42cf2aff313c6e131fbe6
* tlv: add [msgb_]t16lv_put() for 16bit tag + 8 bit len TLVsHarald Welte2017-08-091-1/+20
| | | | | | | | | | | 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
* doxygen: unify use of \file across the boardNeels Hofmeyr2017-06-231-2/+1
| | | | | | | | | | | | | | | | | 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
* doxygen: enable AUTOBRIEF, drop \briefNeels Hofmeyr2017-06-231-59/+59
| | | | | | | | | | 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
* gsm/tlv.h: fix copy-paste errorVadim Yanitskiy2017-05-151-2/+2
| | | | Change-Id: Id52ddd8358fd4af1ecc71142deb09f1e237021f3
* tlv: Add tlvp_val{16,32}be() to get TLV values in unaligned host byte orderHarald Welte2017-05-151-0/+23
| | | | Change-Id: I3749e1e4974742bc8c32722e0e998775b5394829
* Add parsed TLV helpers from OsmoBTSMax2017-01-061-0/+2
| | | | | | Add functions to copy and merge parsed TLV structures from OsmoBTS. Change-Id: Ieaaaed19da9c069fe451faa53d24c5b84d7d5615
* tlv: Import osmo_shift_* and osmo_match_shift_* from openbscHarald Welte2016-05-051-0/+11
| | | | | These routines have nothing to do with specifically the BSC, so import them to the TLV parser we keep in libosmogsm.
* some comments / fixed typosNeels Hofmeyr2015-12-211-1/+1
|
* TLV: add TLVP_PRES_LEN() definition to check for existance + minimum lengthHarald Welte2014-08-181-0/+3
| | | | | This is an import from osmo-bts where it was introduced in 6b561bb7ba5f10c5fd96542a7e42de2822352a67
* include: Switch to #pragma once patternSylvain Munaut2014-06-161-4/+1
| | | | Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
* Add tlvp_val16_unal() / tlvp_val32_unal() to align 16 and 32 bit valuesAndreas Eversberg2012-12-181-0/+24
| | | | | This is required for CPUs < armv6, to access 16 and 32 values at right memory locations.
* TLV: add new "vTvLV" type for GANHarald Welte2012-07-141-1/+97
| | | | | | | | | | | | | 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.
* doc: Fix the Doxygen section endingsSylvain Munaut2012-04-181-1/+1
| | | | Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
* TLV/msgb: Return first byte of newly-pushed data from msgb_*_push()Harald Welte2012-01-221-14/+28
| | | | | The msgb_*_push() functions erroneously returned the firsrt byte after newly-pushed information, which makes no sense at all.
* doxygen: Add documentation about TLV parserHarald Welte2011-08-171-13/+58
|
* gsm 04.80: fix typo (256, not 265!)Harald Welte2011-07-161-2/+2
| | | | | | | This was introduced by me in commit 79599ba0eb7a9aeaeb9dfbbf4881f0633724a471 Thanks to Alexander Huemer for detecting it
* tlv: Make tlv parser arrays 256 entries wide to prevent overflow on 0xffHarald Welte2011-07-161-2/+2
| | | | | | | If we encounter a tag with 0xFF, we overflow our existing tlv_parse array definitions. Warning: this breaks ABI
* include: reorganize headers file to include/osmocom/[gsm|core]Pablo Neira Ayuso2011-03-231-0/+260
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>