CroatiaControlLtd / asterix

Asterix is utility used to read and parse EUROCONTROL ASTERIX protocol data from stdin, file or network multicast stream and print it to standard output in text, XML or JSON format. Source can be used to generate Wireshark dissector for ASTERIX protocol. All ASTERIX categories are defined through XML definition file.
GNU General Public License v2.0
164 stars 89 forks source link

creation of cat021/RE (asterix coding rules for reserved expansion field) #23

Closed ifsnop closed 8 years ago

ifsnop commented 8 years ago

I'm having some problems adding the RE definitions for the cat21. I haven't found documentation for the use of explicit, compound and variable/fixed xml tags, so for sure I'm doing something wrong.

In the Eurocontrol pdf, the RE definition is as follows:

Length indicator -> compound -> -> fixed (BPS) -> -> fixed (SelH) -> -> fixed (NAV) -> -> fixed (GAO) -> -> variable (2 bytes with fx, 1 byte) (SGV) -> -> variable (1 byte with fx) (STA) -> -> fixed (TNH)

How should I encode this? This is my current try:

<explicit> (to use the length byte)
* <compound>
**  <variable>
*** <fixed> <bits></bits> </fixed> (define the presence bits)
** </variable>
** <fixed> <bits> </bits> </fixed> (definition of BPS)
** <fixed> <bits> </bits> </fixed> (definition of  SelH)
** <fixed> <bits> </bits> </fixed> (definition of  NAV)
** <fixed> <bits> </bits> </fixed> (definition of  GAO)
** <variable> <fixed length=2> <bits> </bits> </fixed> <fixed length=1><bits></bits></fixed></variable> (definition of  SGV)
** <variable> <fixed> <bits> </bits> </fixed> </variable> (definition of STA)
** <fixed> <bits> </bits> </fixed> (definition of TNH)
* </compound>
</explicit>

Although the resulting xml is parsed ok, decoding fails.

"IRE":[{ "SGV_presence":{ "STP":1, "HTS":1, "HTT":1, "HRD":1, "GSS":0.0000000, "FX":1, "HGT":137.8125000, "FX":0}},{}]}},

after the last FX, output should end.

Could you give any advice? Thanks.

dsalantic commented 8 years ago

You format looks OK. For now just check if you have fx="1" on all fx bits. e.g.: <Bits bit="1" fx="1">

ifsnop commented 8 years ago

Anywhere I could upload a small sample for you to test? El 23/02/2016 07:37, "Damir Salantić" notifications@github.com escribió:

— Reply to this email directly or view it on GitHub https://github.com/CroatiaControlLtd/asterix/issues/23#issuecomment-187568767 .
dsalantic commented 8 years ago

You can zip it and drop it here in comment box of github.

ifsnop commented 8 years ago

I have uploaded the new xml definition (1.8 + cat21 re 1.1) and a small asterix example. Activate the json output. cat21_18_re.zip

The first datablock failed to decode properly, the last "{}" doesn't make sense.

IRE":[{
                "SGV_presence":{
                "STP":1,
                "HTS":1,
                "HTT":1,
                "HRD":1,
                "GSS":0.0000000,
                "FX":1,
                "HGT":137.8125000,
                "FX":0}},{}]}},

The second datablock decodes something very strange in the RE dataitem (BPS presence is 0, but it is decoded to 1). Further inspection with valgrind shows that asterix is reading outside allocated memory (clearly the xml definition is wrong).

"IRE":[{
                "SGV_presence":{
                "STP":0,
                "HTS":1,
                "HTT":1,
                "HRD":1,
                "GSS":15.0000000,
                "FX":1,
                "HGT":90.0000000,
                "FX":0}},{
                "BPS_presence":{
                "spare":4,
                "BPS":0.0000000},
                "SelH_presence":{
                "spare":0,
                "HRD":0,
                "Stat":0,
                "SelH":0.0000000},
                "NAV_presence":{
                "AP":1,
                "VN":0,
                "AH":0,
                "AM":1,
                "spare":8},
                "GAO_presence":{
                "GAO":46}}]}},
dsalantic commented 8 years ago

Are you looking to correct specification ? In: http://www.eurocontrol.int/sites/default/files/content/documents/nm/asterix/20150904-AppendixCat021pt12Aed13.pdf

Last bit of compound is not fx, but MES.

So, it should be: `

MES_presence
                            <BitsName>Military Extended Squitters</BitsName>
                            <BitsPresence>8</BitsPresence>
                        </Bits>`

Am I wrong ?

dsalantic commented 8 years ago

But, nevertheless, this is not the cause of the problem. XML looks fine for me, probably some problem in application. I'll check and let you know.

dsalantic commented 8 years ago

I think I found the problem in explicit format. Please use the branch fix_issue_23 to try. I need to make additional checks before I include it in master branch. thanks

ifsnop commented 8 years ago

I think now it's working ok.

Thank you very much for your quick fix!

Regarding the RE version, my implementation is for the 1.1, and you linked the 1.3. Yours has a compound inside a compound inside a explicit... will it work?

dsalantic commented 8 years ago

Now I fixed it properly. There was a problem in Explicit format parsing. The fact is that RE and SP fields use explicit format, but it is nowhere defined what can be inside this explicit. Now I fixed it, so any format can be included.