summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2018-02-02 12:11:14 +0100
committerHarald Welte <laforge@gnumonks.org>2018-02-09 02:02:42 +0100
commitbf383a1d83661af26ccd6521c49b655fb22531d4 (patch)
tree0c6b88cee3b62c59d30aa668e15a725b32df1b38
parent6de34ee46b1d256e98d0048c5407f0eec929288b (diff)
tlv_parser: Report *first* occurrence of repeated IEs
Most GSM related specifications require the receiver to use the *first* occurrence of repeated IEs. The Osmocom TLV parser so far did the opposite: It reported only the *last* occurrence in case of repeated IEs. Let's change our implementation to be more in-line with relevant specs, such as 3GPP TS 24.008 8.6.3. Change-Id: Icde09e075f68c842a7a96cf7160c8e44b77cf82d
-rw-r--r--src/gsm/tlv_parser.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/gsm/tlv_parser.c b/src/gsm/tlv_parser.c
index 9b1fb17a..b8c7149f 100644
--- a/src/gsm/tlv_parser.c
+++ b/src/gsm/tlv_parser.c
@@ -276,8 +276,13 @@ int tlv_parse(struct tlv_parsed *dec, const struct tlv_definition *def,
&buf[ofs], buf_len-ofs);
if (rv < 0)
return rv;
- dec->lv[tag].val = val;
- dec->lv[tag].len = len;
+ /* Most GSM related protocols clearly indicate that in case of duplicate
+ * IEs, only the first occurrence shall be used, while any further occurrences
+ * shall be ignored. See e.g. 3GPP TS 24.008 Section 8.6.3 */
+ if (dec->lv[tag].val == NULL) {
+ dec->lv[tag].val = val;
+ dec->lv[tag].len = len;
+ }
ofs += rv;
num_parsed++;
}