mouse07410 / asn1c

The ASN.1 Compiler
http://lionet.info/asn1c/
BSD 2-Clause "Simplified" License
94 stars 70 forks source link

Newie questions #123

Open mcondarelli opened 1 year ago

mcondarelli commented 1 year ago

Hi, most likely this is not the right place to ask, but I have no clue (yet). Please be lenient and redirect me as needed.

My problem is I need to decode complex (C-V2X) messages coming from "unknown source". AFAIK these have been encoded with DSRC_R36_Source.asn (I am not even sure this is the exact specification and it has not been superseded somehow, but it should be close enough for "non exotic" messages).

I built a program feeding messages to asn_decode() (apparently both ATS_CANONICAL_OER and ATS_BASIC_OER seem to work... at least I get RC_OK result).

Basic message I need to decode is defined as:

-- MSG_BasicSafetyMessage  (BSM) (Desc Name) Record 2
BasicSafetyMessage ::=  SEQUENCE {
   -- Part I
   msgID       DSRCmsgID,                 -- 1 byte

   -- Sent as a single octet blob
   blob1       BSMblob,

   --
   -- The blob consists of the following 38 packed bytes:
   --
   -- msgCnt      MsgCount,             -x- 1 byte
   -- id          TemporaryID,          -x- 4 bytes
   -- secMark     DSecond,              -x- 2 bytes

   -- pos      PositionLocal3D,
     -- lat       Latitude,             -x- 4 bytes
     -- long      Longitude,            -x- 4 bytes
     -- elev      Elevation,            -x- 2 bytes
     -- accuracy  PositionalAccuracy,   -x- 4 bytes

   -- motion   Motion,
     -- speed     TransmissionAndSpeed, -x- 2 bytes
     -- heading   Heading,              -x- 2 byte
     -- angle     SteeringWheelAngle    -x- 1 bytes
     -- accelSet  AccelerationSet4Way,  -x- 7 bytes

   -- control  Control,
   -- brakes      BrakeSystemStatus,    -x- 2 bytes

   -- basic    VehicleBasic,
   -- size        VehicleSize,          -x- 3 bytes

   -- Part II, sent as required
   -- Part II,
   safetyExt     VehicleSafetyExtension OPTIONAL,
   status        VehicleStatus          OPTIONAL,

   ... -- # LOCAL_CONTENT
   }

decoding snippet is:

                asn_dec_rval_t rval;
                BasicSafetyMessage_t *bsm = NULL;
                rval = asn_decode(0, ATS_CANONICAL_OER, &asn_DEF_BasicSafetyMessage, (void **) &bsm, b64, len);
                if (rval.code == RC_OK) {
                    printf("BSM");
                    if (bsm->blob1.size != sizeof(bsm1)) {
                        printf(" [MISMATCH: %ld != %ld]", bsm->blob1.size, sizeof(bsm1));
                    }
                    ...
                } else {
                    fprintf(stderr, "ERROR decoding BSM\n");
                }
                ASN_STRUCT_FREE(asn_DEF_BasicSafetyMessage, bsm);

So far so good.

At this point I have a bsm struct containing bsm.blob1 which is a binary array (buf address/ size) I don't know how to further decode (it doesn't look like it is a packed struct). All "blobs" e.g.: BSMblob_t) are defined as typedef OCTET_STRING_t BSMblob_t; and I am missing the next link.

Any comment welcome.

mouse07410 commented 1 year ago

Perhaps, you can treat the content of OCTET STRING that "wraps"BSMblob_t as OER-encoded buffer? And create another PDU containing what's commented out in your ASN.1 as BSMblob?

mcondarelli commented 1 year ago

Thanks mouse07410, unfortunately I am a bit too inexperienced (about ASN.1, at the very least) to follow the second part of your advice. I do attach complete asn definition (quite long) in case it makes sense for you. The following is a real excerpt of data I have to handle (base64 encoded):

[
  {
    "typ": "RX_CV2X",
    "b64": "AYjcAACIAAAAAAAAAAAAAAAAbJwo////////AAA2AIjcAwAgfgOAewAUeEZzYsNrQDIoPRSTN+a6XI4kFBQAAHB7VsD9+h+hAH//gAAAAAEBJMDhAC2/v6/6ALIQFFv14P/AJCEDS79iz9YE1hBIM/Qy+uBsoQTcPr3PxAlKEFK763b9gJhhBXk+U5AQCz4QW9vg+QFEzyf1o8AgZgBwwBwmAA=="
  },
  {
    "typ": "RX_CV2X",
    "b64": "AYjcAACIAAAAAAAAAAAAAAAAWsGi////////AAA2AIjcAwAggL0DgIG5ABSAtVHBLG4BAEsoPRNuN+a5qY4QyzW0BPCEVij9+h+hAH//gAAAAAECAhTBwQAAv+ywAAAmEABr+9cBgAnBAAe/dPAaAQIQCoP09wJgHeECk786L+IDvhAww/Vo/WBCAQSFPyzP1gXGEFXz7VUBIHkhBhM+w5AGCAoQYGPq5wCAhsEGpD6JcAII0hBsc+V2/wCeoQaTvikP3grEEG8D3jz+g2DBB1u9wM/MQPx/n1AAIGYAcMAcJgA="
  },
  {
    "typ": "RX_CV2X",
    "b64": "AYjcAACIAAAAAAAAAAAAAAAAQKfL////////AAA2AIjcAwAgdgOAcwAUcFK/Kf4jQEsoPRQDt+a55Y4PFBQAAHB/V3j9+h+hAH//gAAAAAEBBMDBACA/vO/6ALIQEqP1vP+gJCEDpj9RD/QFJhBPO/DI/+B1YQWBvhgv/Ax+EGcT4Zj/5XpBBjg+HPAVRMJ/MjwAIGYAcMAcJgA="
  },
  {
    "typ": "TX_CV2X",
    "b64": "AQnGCccAAAAAAAAAIAAAAGQAAAC0AogAAAD///////8AAACMK/3///////8AADYAiNwDACCAmgOAgZYAFICSTyuGTCmAQig9E7035rmvjiyUFAAAcIZXUP2CL6EAe2GAgFoPAAGswWEAPL+9L/wAshAU8/Zq/6AhoQNZP1VwAARyEE2780b/4GZhBdU+v4/iCSIQYSvqqv0gmaEGEz6EL9gKThBlW+Me/IC94QaKPidvvgx+EHND4u74qGhhBwa+OHABOjYQbYvk/wWc/6fz08A="
  },
  {
    "typ": "NAV",
    "tim": 1645434780.364,
    "lon": 7.5735328,
    "lat": 45.0182784,
    "hig": 316.12,
    "maj": 2.0,
    "min": 2.0,
    "ori": 0.0,
    "spd": 18.972,
    "cspd": 1.4400000000000002,
    "hea": 277.8
  },
  {
    "typ": "RX_CV2X",
    "b64": "AYjcAACIAAAAAAAAAAAAAAAAbJwo////////AAA2AIjcAwAgfgOAewAUeEazYsNrQEsoPRSWt+a6PI4kFBQAAHB91zj9+h+hAH//gAAAAAEBJMDhADE/t6/6AMYQFJP1YP/AJWEDTz9az9YE6hBIa/Oy+uBt4QTfvrXPxAleEFLz6vb9gJmhBXy+S5AQC1IQXBPgeQFE0GftIoAgZgBwwBwmAA=="
  },
  {
    "typ": "RX_CV2X",
    "b64": "AYjcAACIAAAAAAAAAAAAAAAAWsGi////////AAA2AIjcAwAggL0DgIG5ABSAtVIBLG4BAGQoPRNvt+a5ho4QyzW0BPCH1gD9+h+hAH//gAAAAAECAhTBwQACP+PwAAA6EACD+0sBYAsBAAk/bDAaARYQCpv0awJgHyEClT8xb+AD0hAw2/Tc/WBDQQSGvyQP1gXaEFYL7MkBIHphBhS+utAGCB4QYHvqWwCAiAEGpb6AsAII5hBsi+Tq/wCf4QaVPiBP3grYEG8b3bD+Y2IBB109uA/MQRB/higAIGYAcMAcJgA="
  },
  {
    "typ": "TX_CV2X",
    "b64": "AQnGCccAAAAAAAAAIAAAAGQAAAC0AogAAAD///////8AAACMK/3///////8AADYAiNwDACCAmgOAgZYAFICST2uGTCmAWyg9E8A35rmPjiyUFAAAcIPW0P1+X6EAesWAgFoPAAGswWEAP7+1L/wAxhAVI/Xq/6Ai4QNcP01wAASGEE3r8sb/4GehBdg+t4/iCTYQYVvqKv0gmuEGFj58L9gKYhBli+Ke/IC/IQaNPh9vvgySEHNz4m74qGmhBwm+MHABOkoQbbvkfwWdAOf0hQA="
  },
  {
    "typ": "RX_CV2X",
    "b64": "AYjcAACIAAAAAAAAAAAAAAAAQKfL////////AAA2AIjcAwAgdgOAcwAUcFL/Kf4jQGQoPRQBt+a5v44PlBQAAHCHVcD9+h+hAH//gAAAAAEBBMDBAB4/s2/6AMYQEoP1JP+gJWEDpD9Hj/QFOhBPG/Aw/+B2oQV/vg6v/AySEGbz4QD/5XuBBjY+E3AXRNZ/gygAIGYAcMAcJgA="
  },
  {
    "typ": "NAV",
    "tim": 1645434780.465,
    "lon": 7.5735263,
    "lat": 45.018279,
    "hig": 316.16,
    "maj": 2.0,
    "min": 2.0,
    "ori": 0.0,
    "spd": 19.008,
    "cspd": 1.332,
    "hea": 276.7
  },
]
[DSRC_R36_Source.asn.gz](https://github.com/mouse07410/asn1c/files/11419065/DSRC_R36_Source.asn.gz)

Content of BSM should be very similar to plain text JSON data. If deemed useful I have no problem in sharing also my test program, of course. Any further hint would be deeply appreciated. TiA!