asn1c: Wrong encoding of SBc-AP Write-Replace Warning Request (APER enc)

Hi,

I’m introducing SBc-AP protocol support [1] to osmo-cbc [2] project. For that, I’m using code generated with asn1c commit 2cf625cf89beedbb8bd795727057dad3cd3ea149 (mouse07410 branch “vlm_master” including last fix of mine merged yesterday/today).

I’m validating the generated output using several methods:

  • wireshark analysis of pcap files: ** Pcap file of another existing external implementation found here. ** Pcap file generated by osmo-cbc when running TTCN3 tests [3]
  • libfftranscode decoding [4]
  • https://asn1.io/asn1playground/default.aspx?

I’m adding the SBc-AP support in osmo-cbc.git branch “pespin/sbcap”.

First commit adds the skeletons + generated asn1c code (from asn files found in same repo in src/sbcap/asn1/*.asn) with mouse07410/vlm_master plus all the boilerplate to build the content in a library (the Makefile also modified slightly some headers to avoid some circular dependency issues, but that’s another topic): https://cgit.osmocom.org/osmo-cbc/commit/?h=pespin/sbcap&id=469ab793be1d1fe4924a971ad0b6fb84a2ce8d20 asn1c code can be regenerated by calling “make -C src/ regen”.

Second commit adds a unit test to encode SBc-AP Write-Replace Warning Request (you can run it with “make check”): https://cgit.osmocom.org/osmo-cbc/commit/?h=pespin/sbcap&id=8ff4fed49b63d184521aebb3cb3730651c9e49af It can be seen that the encoded output is: 00 00 00 0e 00 02 00 05 00 02 ab 01 00 0b 00 02 ab cd When decoding with wireshark, libfftranscode or asn1.io, there seems to be issues parsing the length of the item list (the IE list). When comparing to the message in the existing implementation (available above), it also doesn’t match, it starts with 00 00 00 5f 00 00 0b, where of course values 5f and 0b are different since those contain the length of the message and the 11 IEs it contains. However, you can see how in between those there’s an extra 00 byte.

In third commit, I apply the proposed changes in my asn1c PR [5]: https://cgit.osmocom.org/osmo-cbc/commit/?h=pespin/sbcap&id=2c54d1d135018ad57de70a7be47bc701b0a4970f You can see how the output of the unit test changes to something correct:

-Encoded message: 00 00 00 0e 00 02 00 05 00 02 ab 01 00 0b 00 02 ab cd 
+Encoded message: 00 00 00 0f 00 00 02 00 05 00 02 ab 01 00 0b 00 02 ab cd 

Once this change is applied, wireshark, fftranscode and as1n.io are happy with the message.

[1] 3GPP TS 29.168, https://www.etsi.org/deliver/etsi_ts/129100_129199/129168/16.00.00_60/ts_129168v160000p.pdf [2] https://osmocom.org/projects/osmo-cbc/wiki [3] https://gitea.osmocom.org/ttcn3/osmo-ttcn3-hacks/src/branch/pespin/sbcap [4] https://osmocom.org/projects/cellular-infrastructure/wiki/Titan_TTCN3_Testsuites#Proprietary-APERBER-transcoding-library-for-Iu-tests [5] https://github.com/mouse07410/asn1c/pull/93

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 41 (14 by maintainers)

Commits related to this issue

Most upvoted comments

@mouse07410 the problem is specifically seen when encoding length of sequence (list of fields), which as it was pointed out, specified by X.691 11.9 (length determinant):

NOTE 1 … list of fields (with the length count in components of a sequence-of or set-of).

In general in section 11.9, my understanding is that it usually talks about an upper bound “ub” that is less than 64K, where 64K=65536.

Hence, it usually talks about (ub < 65536 && lb >= 0). So, the maximum ub is 65536-1=65535. However, the code in aper_put_length() uses range, which is range=ub-lb+1. So, the maximum range to check for is 65536.

Hence, (range <= 65536 && range >= 0) is the counterpart of (ub < 65536 && lb >= 0) (note “<=” vs “<”). I’m new to reading ASN1 specs though, so please feel free to provide your own thoughts.

Hi all. I’m working on testing open air interface and would just like to say thank you all for this these sets of timely commits.

@mouse07410, @grzegorzniemirowski, @laf0rge and @pespin

Thank you so much for your efforts.

I confirmed that commit 24247e2813a7510ebabe6a9b6b6b29fffa0eb27b works well in Open5GS.

Please let me know if you have any further questions in the Open5GS.

Thanks a lot! Sukchan

@mouse07410 @grzegorzniemirowski @laf0rge please have a look at PR https://github.com/mouse07410/asn1c/pull/100 The first bunch of commits contains clean ups and small fixes unrelated to the issue at hand, which I did while reading the code. The last 2 commits rework aper_put_length and aper_get_length so that “lb” and “ub” are passed to it instead of “range”. This allows applying nsnnwn for ub<65536.

I validated the existing unit tests and my SBc-AP generated code still work fine. Please @grzegorzniemirowski give it a try and see if it improves the situation.

@grzegorzniemirowski are you sure upper bound is 65536 and not 65535 in the field you are mentioning? Which field exactly shows this (1…65536) range? That would indeed explain it perhaps. I think we all agree that it makes sense passing ub and lb to aper_get_length. That may well fix the issue.

@pespin you are right and yes, the above output is from current vlm_master, generated when writing the comment. I suppose length encoding is the same for SEQUENCE_OF and SEQUENCE. I would rather look at the fact that in case of problematic field the lower bound is 1 and upper bound is 65536. So range is 65536 and equal to ub. As upper bound is not less than 64K, nsnnwn shouldn’t be used. But the problem is that aper_get_length() checks for range, not upper bound. I guess ct->upper_bound should be passed to this function, not range.

@mouse07410 I used check_round_trip(65536, …) since that was the faulty case (small value with range=65536) that I discovered when using the code generated from SBc-AP asn files (3GPP TS 29.168). Basically the case is an ASN1 sequence type which had a length determinant of range=65536 (0…65535), uint16

I saw the range=65536 in the debug output (-DASN_EMIT_DEBUG=1) when encoding the structure, and it saw it was the part which was encoding the unexpected missing byte. So I basically ported that to a unit test to be able to reproduce it easily, fix it and avoid future regressions.

I guess the best to figure out what’s wrong with the decoding from @grzegorzniemirowski would be to use the hexstring he provided, and add a unit test decoding it and enable ASN_DEBUG, so that we can see exactly where it fails and we can reproduce easily. Then once fixed we also make sure it doesn’t break since we have a unit test.

@mouse07410 IMHO it can already be merged, since it clearly shows some cases are fixed. Later on code can be improved to adapt to terminology used in the specs, but that’d be a separate commit/topic.

Other people having problems when these new patches are merged should provide more detailed bug reports on what is exactly failing on their side.