RAW coder: Handle a variable-lengh length field? [message #1768773] |
Sun, 23 July 2017 18:57 |
|
While implementing the 3GPP TS 48.016 + 48.018 protocols using TITAN, I am wondering if and how one could express their notion of TLV with variable-length "length" field.
Basically, in above-mentioned protocols, there is a 8bit tag, and a 8-or-16bit length field followed by the value of the information element.
The MSB of the first length-octet determines if the length field has one octet (MSB=1) or two octets (MSB=0), similarly to the 'extension octet' mechanism found in many telecom specs.
I can see that the RAW coder has support for extension bits, but I don't see how I could/should use that in the context of LENGTHOF().
My (ugly) work-around so far is to pre-process the messages in a C++ function, where the OCTETSTRING is traversed and all 8-bit length fields are expanded to 16bits, so then the TITAN RAW codec can operate on that. During encode, I do the inverse, i.e. parse the TLV list and check for each IE if the length is <= 0x7f. If yes, reduce the length field. Related code is in http://git.osmocom.org/osmo-ttcn3-hacks/tree/gprs_gb/BSSGP_Helper.cc
Is there any more elegant way to do this?
Also, is there a way to hide/integrate a pre-processing/post-processing function within the encode/decode of a given type? Right now the TTCN-3 code must explicitly first encode using the RAW codec and then call the post-processing function on the resulting octetstring. That's error-prone, and it would be great if one could somehow hide this in a way that the enc_ / dec_ functions for the type do the "right" thing, even if some custom C++ code is involved.
|
|
|
Re: RAW coder: Handle a variable-lengh length field? [message #1768814 is a reply to message #1768773] |
Mon, 24 July 2017 06:57 |
|
Hi Harald,
here's a solution from one of our protocol modules
( BSSGP_Types , 3GPP TS 48.018 13.0.0 ) I will also open source later:
type union LIN2_2a
{
integer length1,
integer length2
} with {
variant (length1) "FIELDLENGTH(7)";
variant (length2) "FIELDLENGTH(15)";
variant (length2) "BYTEORDER(last)";
variant (length1,length2) "FIELDORDER(msb)";
}
type record Alignment_octets
{
OCT1 iEI,
BIT1 ext,
LIN2_2a lengthIndicator,
octetstring spare_octet length(0..3)
} with {
variant "PRESENCE(iEI = '00'O)";
variant (lengthIndicator) "LENGTHTO (spare_octet)";
variant (lengthIndicator) "CROSSTAG( length1, ext = '1'B;
length2, ext = '0'B;)";
variant (ext,lengthIndicator) "FIELDORDER(msb)";
};
I have mailed you the protocol module in question; the attached BSSGP_EncDec.cc should also answer your question related to integrating
your own code with the calls towards autogenerated RAW functions.
I hope this helps.
Best regards
Elemer
|
|
|
|
Powered by
FUDForum. Page generated in 0.03921 seconds