aboutsummaryrefslogtreecommitdiffstats
path: root/include/osmocom/gsm/tlv.h
AgeCommit message (Collapse)AuthorFilesLines
2023-08-11tlv: Introduce API msgb_tv32_push()Pau Espin Pedrol1-0/+10
msgb_tv32_put() already exists, but msgb_tv32_push doesn't. The tv16 counterparts are already present, and having to pass 32bit integers is also quite common, so let's add an API for it. Change-Id: I68d5693a18d55ce8d0647359044157d7e5bfae50
2022-08-08tlv.h: Fix TLVP_PRESENT returning a pointer instead of a booleanPau Espin Pedrol1-1/+1
I was warned by gcc about comparing a pointer with an integer when using TLVP_PRESENT with something like: bool expect = ...; if (expect != TLV_PRESENT(...)) That's indeed dangerous because TLV_PRESENT is considered to return a boolean, as opposite to TLV_VAL. Change-Id: I45cc2745c695e30c37b10f592903ec3775a55492
2022-08-08cosmetic: tlv.h: Fix trailing whistespacePau Espin Pedrol1-2/+2
Change-Id: Ief318882def539b35ef15c85566f69220e7edbfe
2021-03-18tlv: Fix length returned by t{l16,16l}v_putDaniel Willmann1-2/+2
Every other function returns a pointer to the first byte after the tlv that was just written. tl16v seems to be a copy and paste error from tlv16 above and t16lv seems to count the 16-bit tag twice. The new tests verify that the return value of *_put(buf, tag, len, val) points to buf + *_GROSS_LEN(len). Change-Id: I268a7e11fb5dce67ce1bd7974ab86c4d2bd002f7
2021-02-06tlv: clarify documentation for msgb_tv{16,32}_put()Vadim Yanitskiy1-2/+2
Change-Id: Ie439822e0587012e108f67ba4e73771dc684b95b
2021-02-06tlv: add msgb_tv32_put(), similar to msgb_tv16_put()Vadim Yanitskiy1-0/+10
Change-Id: I11301b20038aa5d90d46d968f7eda3d53b560022
2020-12-08tlv.h: Add msgb_tvlv_put_{16,32}be()Harald Welte1-0/+15
Those routines are very useful when puzzling together BSSGP messages with 16-bit and 32bit sized IEs. Change-Id: I033f9a708c9d7ffad91336178231dc66233e1693
2020-12-08tlv: Introduce enum with error codes for TLV parser functionsHarald Welte1-0/+10
Change-Id: I0b352792089c5c0c714712d2ea237beb92e1d73f
2020-12-08Introduce 'osmo_tlv_prot' abstraction for validation of TLV protocolsHarald Welte1-0/+50
This extends our existing TLV parser with the ability to * validate that mandatory IEs of a given message are present * validate that all present IEs are of required minimum length Introducing this generic layer will help us to reduce open-coded imperative verification across virtually all the protocols we implement, as well as add validation to those protocols where we don't properly perform related input validation yet. Change-Id: If1e1d9adfa141ca86001dbd62a6a339f9bf9a912
2020-06-10tlv.h: add msgb_tvl_put() to add a TvLV without the value partNeels Hofmeyr1-0/+45
So far, we have msgb_tl_put(), which allows putting the TL header of a TLV, without the value part. Add the same for a variable-size length TvLV: put a TvL header of a TvLV without the value part. In a subsequent patch, osmo_mobile_identity will be introduced, which will allow writing the encoded MI directly to the end of a msgb. For BSSGP_IE_IMSI, which is a TvLV, it would hence be simplest to write only the TvL first. Change-Id: I02cca5182fe42e40b63680a2fd470f03bcc11076
2019-05-19TLV: Add one-shot TLV encoderHarald Welte1-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
2018-12-20TLV: add convenience function for 1-byte valuesMax1-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
2018-12-20TLV: fix doc copy-paste errorMax1-1/+1
Change-Id: I8aa79cab7505585de00ee2aaae125462108906e8
2018-12-04Add msgb_tl_put() helperMax1-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
2018-11-19Move msgb_push helpers to public headerMax1-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
2018-06-02tlv: Add TLVP_VAL_MINLEN() to obtain value _if_ length is >= minimumHarald Welte1-0/+10
This is a combination of TLVP_VAP() and TLVP_GET_MINLEN() Change-Id: Ic5a177941219ebc3a3bceb3f68bdb3b2cacb934b
2018-04-18tlv: add TLV_GET() and TLV_GET_MINLEN()Neels Hofmeyr1-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
2018-04-13add tlv_parse2(), capable of multiple instances of the same IENeels Hofmeyr1-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
2017-11-20tlv_put: guard against NULL val and 0 lenNeels Hofmeyr1-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
2017-10-16[doc] TLV parser has far grown beyond GSM L3Harald Welte1-1/+1
Let's hence not call the group "GSM L3 compatible TLV parser" Change-Id: Ic53f9c0d5ee787f994f42cf2aff313c6e131fbe6
2017-08-09tlv: add [msgb_]t16lv_put() for 16bit tag + 8 bit len TLVsHarald Welte1-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
2017-06-23doxygen: unify use of \file across the boardNeels Hofmeyr1-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
2017-06-23doxygen: enable AUTOBRIEF, drop \briefNeels Hofmeyr1-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
2017-05-15gsm/tlv.h: fix copy-paste errorVadim Yanitskiy1-2/+2
Change-Id: Id52ddd8358fd4af1ecc71142deb09f1e237021f3
2017-05-15tlv: Add tlvp_val{16,32}be() to get TLV values in unaligned host byte orderHarald Welte1-0/+23
Change-Id: I3749e1e4974742bc8c32722e0e998775b5394829
2017-01-06Add parsed TLV helpers from OsmoBTSMax1-0/+2
Add functions to copy and merge parsed TLV structures from OsmoBTS. Change-Id: Ieaaaed19da9c069fe451faa53d24c5b84d7d5615
2016-05-05tlv: Import osmo_shift_* and osmo_match_shift_* from openbscHarald Welte1-0/+11
These routines have nothing to do with specifically the BSC, so import them to the TLV parser we keep in libosmogsm.
2015-12-21some comments / fixed typosNeels Hofmeyr1-1/+1
2014-08-18TLV: add TLVP_PRES_LEN() definition to check for existance + minimum lengthHarald Welte1-0/+3
This is an import from osmo-bts where it was introduced in 6b561bb7ba5f10c5fd96542a7e42de2822352a67
2014-06-16include: Switch to #pragma once patternSylvain Munaut1-4/+1
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2012-12-18Add tlvp_val16_unal() / tlvp_val32_unal() to align 16 and 32 bit valuesAndreas Eversberg1-0/+24
This is required for CPUs < armv6, to access 16 and 32 values at right memory locations.
2012-07-14TLV: add new "vTvLV" type for GANHarald Welte1-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.
2012-04-18doc: Fix the Doxygen section endingsSylvain Munaut1-1/+1
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2012-01-22TLV/msgb: Return first byte of newly-pushed data from msgb_*_push()Harald Welte1-14/+28
The msgb_*_push() functions erroneously returned the firsrt byte after newly-pushed information, which makes no sense at all.
2011-08-17doxygen: Add documentation about TLV parserHarald Welte1-13/+58
2011-07-16gsm 04.80: fix typo (256, not 265!)Harald Welte1-2/+2
This was introduced by me in commit 79599ba0eb7a9aeaeb9dfbbf4881f0633724a471 Thanks to Alexander Huemer for detecting it
2011-07-16tlv: Make tlv parser arrays 256 entries wide to prevent overflow on 0xffHarald Welte1-2/+2
If we encounter a tag with 0xFF, we overflow our existing tlv_parse array definitions. Warning: this breaks ABI
2011-03-23include: reorganize headers file to include/osmocom/[gsm|core]0.2.0Pablo Neira Ayuso1-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>