mouse07410 / asn1c

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

UPER decode fails after adding another ASN in the collection #198

Closed danielfacchetti closed 2 months ago

danielfacchetti commented 2 months ago

Hello, I'm trying to compile two C-ITS message formats for Europe: DENM (version 1.3.1) and IVIM (version 1.3.1). I found all the ASN files (see attachments) and I have some examples in hexadecimal format (which I converted in binary files, see attachments).

If I compile only the DENM (with requested ASNs) or IVIM I can decode the messages without problems, but if I try to compile both messages (separated or all in the same folder), I can't decode DENM messages.

I think that a possible problem is related to one specific ASN: ITS-Container, to compile IVIM I have to use 2 different versions of this ASN, I have this error but it seems working.

WARNING: ASN.1 module ITS-Container is defined more than once, with different OIDs in ../asn_files/ITS-Container_old.asn FATAL: Name "e_ITS_Container_CenDsrcTollingZoneID" is generated by ITS-Container.CenDsrcTollingZoneID at line ../asn_files/ITS-Container.asn:505 and ITS-Container.CenDsrcTollingZoneID at line ../asn_files/ITS-Container_old.asn:501 FATAL: Name "enum ITS_Container_CenDsrcTollingZoneID" is generated by ITS-Container.CenDsrcTollingZoneID at line ../asn_files/ITS-Container.asn:505 and ITS-Container.CenDsrcTollingZoneID at line ../asn_files/ITS-Container_old.asn:501 FATAL: Name "ITS_Container_CenDsrcTollingZoneID_PR" is generated by ITS-Container.CenDsrcTollingZoneID at line ../asn_files/ITS-Container.asn:505 and ITS-Container.CenDsrcTollingZoneID at line ../asn_files/ITS-Container_old.asn:501 FATAL: Name "enum ITS_Container_CenDsrcTollingZoneID_PR" is generated by ITS-Container.CenDsrcTollingZoneID at line ../asn_files/ITS-Container.asn:505 and ITS-Container.CenDsrcTollingZoneID at line ../asn_files/ITS-Container_old.asn:501 FATAL: Name "struct ITS_Container_CenDsrcTollingZoneID" is generated by ITS-Container.CenDsrcTollingZoneID at line ../asn_files/ITS-Container.asn:505 and ITS-Container.CenDsrcTollingZoneID at line ../asn_files/ITS-Container_old.asn:501 FATAL: Name "ITS_Container_CenDsrcTollingZoneID" is generated by ITS-Container.CenDsrcTollingZoneID at line ../asn_files/ITS-Container.asn:505 and ITS-Container.CenDsrcTollingZoneID at line ../asn_files/ITS-Container_old.asn:501 FATAL: ... 793 more name clashes not shown FATAL: Name clashes encountered even with -fcompound-names flag

To compile I use this command:

asn1c -fcompound-names -findirect-choice -fincludes-quoted -no-gen-example -pdu=DENM -pdu=all *.asn for DENM (in the folder there are only the DENM related ASN.1)

asn1c -fcompound-names -findirect-choice -fincludes-quoted -no-gen-example -pdu=IVIM -pdu=all *.asn for IVIM (in the folder there are only the IVIM related ASN.1)

asn1c -fcompound-names -findirect-choice -fincludes-quoted -no-gen-example -pdu=DENM -pdu=IVIM -pdu=all *.asn for DENM+IVIM

The decoder code is the sequent:

char buf[1024];
asn_dec_rval_t rval;
DENM_t* denm = 0;   //asn1c_usage.pdf pag 7
FILE* fp; /* Input file handler */
size_t size; /* Number of bytes read */

const char* filename = "Accident.dat"; /* Input file name */

/* Open input file as read-only binary */
fp = fopen(filename, "rb");
if (!fp) {
    perror(filename);
    exit(1);
}

/* Read up to the buffer size */
size = fread(buf, 1, sizeof(buf), fp);
fclose(fp);
if (!size) {
    fprintf(stderr, "%s: Empty or broken\n", filename);
    exit(1);
}

//rval = uper_decode_complete(0, &asn_DEF_DENM, (void**)&denm, buf, size);
rval = asn_decode(0, ATS_UNALIGNED_CANONICAL_PER, &asn_DEF_DENM, (void**)&denm, buf, size);

char errbuf[128];
size_t errlen = sizeof(errbuf);
asn_check_constraints(&asn_DEF_DENM, (void**)&denm, errbuf, &errlen);

if (rval.code != RC_OK)
{
    printf("Broken DENM encoding at byte % ld\n", (long)rval.consumed);
    //return;
}

xer_fprint(stdout, &asn_DEF_DENM, denm);

The error is that rval.code is RC_FAIL and consume is 0.

What can I try to use both DENM and IVIM message format? Did I missed something?

Thanks!

DENM_IVIM_ASN_UPER.zip

velichkov commented 2 months ago

Hi @danielfacchetti,

FATAL: Name "e_ITS_Container_CenDsrcTollingZoneID" is generated by ITS-Container.CenDsrcTollingZoneID at line ../asn_files/ITS-Container.asn:505 and ITS-Container.CenDsrcTollingZoneID at line ../asn_files/ITS-Container_old.asn:501

Try compiling DENM and IVIM asn.1 files with different -fprefix parameter, see #170. Compile them separately into two static or dynamic libraries (.so/.a) and then link them to your decoder.

mouse07410 commented 2 months ago

I think @velichkov gave the complete solution. #170 allows both using -fprefix command-line parameter, and ASN1C_PREFIX env var.

@danielfacchetti Please report your results here. Note that in the unlikely case of the above not solving your problem - your only (AFAIK) other option would be to manually edit generated .c and .h files to resolve name collisions.

danielfacchetti commented 2 months ago

Hi @velichkov and @mouse07410 : thank you so much for the reply. I tried with the -fprefix parameter and now I can use both the message profiles. So no problem with the library (very good!)