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
diff --git a/src/gsm/tlv_parser.c b/src/gsm/tlv_parser.c
index 9b1fb17..b8c7149 100644
--- a/src/gsm/tlv_parser.c
+++ b/src/gsm/tlv_parser.c
@@ -276,8 +276,13 @@
 		                   &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++;
 	}