sndcp: Allow empty SNDCP-XID indications

In some rare cases the modem might send a xid indication that does
not contain anything except the version number field. The sgsn
ignors such SNDCP-XID indications by stripping the entire field
from the response. We found a modem in the wild that started to
act problematic when the empty SNDCP-XID was missing in the
response. This patch changes the XID negotiation behaviour in
a way that if a modem should send empty SNDCP-XID indications,
the reply will also contain an empty SNDCP-XID indication. Apart
from that the SNDCP-XID version number is now parsed and echoed
in the response. This ensures that we always reply with the version
number that the modem expects. (The version was 0 in all cases we
observed so far)

Change-Id: I097a770cb4907418f53e620a051ebb8cd110c5f2
Related: OS#1794
diff --git a/openbsc/tests/sndcp_xid/sndcp_xid_test.c b/openbsc/tests/sndcp_xid/sndcp_xid_test.c
index 3a33619..151dd2b 100644
--- a/openbsc/tests/sndcp_xid/sndcp_xid_test.c
+++ b/openbsc/tests/sndcp_xid/sndcp_xid_test.c
@@ -47,13 +47,14 @@
 	uint8_t xid_r[512];
 
 	/* Parse and show contained comp fields */
-	comp_fields = gprs_sndcp_parse_xid(ctx, xid, sizeof(xid), NULL);
+	comp_fields = gprs_sndcp_parse_xid(NULL, ctx, xid, sizeof(xid), NULL);
 	OSMO_ASSERT(comp_fields);
 	printf("Decoded:\n");
 	gprs_sndcp_dump_comp_fields(comp_fields, DSNDCP);
 
 	/* Encode comp-fields again */
-	rc = gprs_sndcp_compile_xid(xid_r,sizeof(xid_r), comp_fields);
+	rc = gprs_sndcp_compile_xid(xid_r,sizeof(xid_r), comp_fields,
+				    DEFAULT_SNDCP_VERSION);
 	printf("Result length=%i\n",rc);
 	printf("Encoded:  %s\n", osmo_hexdump_nospc(xid, sizeof(xid)));
 	printf("Rencoded: %s\n", osmo_hexdump_nospc(xid_r, rc));
@@ -226,13 +227,14 @@
 	gprs_sndcp_dump_comp_fields(&comp_fields, DSNDCP);
 
 	/* Encode SNDCP-XID fields */
-	rc = gprs_sndcp_compile_xid(xid, xid_len, &comp_fields);
+	rc = gprs_sndcp_compile_xid(xid, xid_len, &comp_fields,
+				    DEFAULT_SNDCP_VERSION);
 	OSMO_ASSERT(rc > 0);
 
 	printf("Encoded:  %s (%i bytes)\n", osmo_hexdump_nospc(xid, rc), rc);
 
 	/* Parse and show contained comp fields */
-	comp_fields_dec = gprs_sndcp_parse_xid(ctx, xid, rc, NULL);
+	comp_fields_dec = gprs_sndcp_parse_xid(NULL, ctx, xid, rc, NULL);
 	OSMO_ASSERT(comp_fields_dec);
 
 	printf("Decoded:\n");