mouse07410 / asn1c

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

Compiling the example failed when compiling the ASN1 files with -fcompound-names (complex names for variable types) #77

Open raoufkh opened 3 years ago

raoufkh commented 3 years ago

Hello,

I've been able to compile the ASN file from 3GPP TS 38.413 (NGAP) v16.5.0 using asn1c from the vlm_master branch of this fork by running the following command:

asn1c -fcompound-names -gen-APER ngap-v16.5.0.asn

The result is:

Q1: My first question is: is it possible to get only one .h file for that protocol (NGAP)? I want then to use that library for parsing NGAP messages in C language.

Then when I try to compile the example using cc or make I have the following errors:

cc -DPDU=NGAP-PDU -o NgapDecoder.o *.c
compilation terminated.
uper_encoder.c:1:10: fatal error: asn_application.h: No such file or directory
 #include <asn_application.h>
          ^~~~~~~~~~~~~~~~~~~
compilation terminated.
uper_opentype.c:5:10: fatal error: asn_internal.h: No such file or directory
 #include <asn_internal.h>
          ^~~~~~~~~~~~~~~~
compilation terminated.
uper_support.c:5:10: fatal error: asn_system.h: No such file or directory
 #include <asn_system.h>
          ^~~~~~~~~~~~~~
compilation terminated.
xer_decoder.c:5:10: fatal error: asn_application.h: No such file or directory
 #include <asn_application.h>
          ^~~~~~~~~~~~~~~~~~~
compilation terminated.
xer_encoder.c:5:10: fatal error: asn_internal.h: No such file or directory
 #include <asn_internal.h>
          ^~~~~~~~~~~~~~~~
compilation terminated.
xer_support.c:7:10: fatal error: asn_system.h: No such file or directory
 #include <asn_system.h>
          ^~~~~~~~~~~~~~

while I can see that these headers are available in the current directory. Q2: So how to make the compiler aware of the location of these local headers?

raoufkh commented 3 years ago

Update: The issue of not finding skeleton headers has been solved by specifying the path where to search for headers using -I parameter:

cc -DPDU=NGAP-PDU -I. -o NgapDecoder.o *.c 

Now, I've another issue, the cc compiler tell me that several types begining with ProtocolIE_SingleContainer_ are not defined. I will take an example of the ProtocolIE_SingleContainer_128P31_t type.

In file included from ProtocolExtensionField.h:19:0,
                 from ProtocolExtensionContainer.h:3234,
                 from EndpointIPAddressAndPort.h:44,
                 from ProtocolIE-Field.h:22,
                 from ProtocolIE-SingleContainer.h:15,
                 from CPTransportLayerInformation.h:16,
                 from AMF-TNLAssociationSetupItem.h:15,
                 from AMF-TNLAssociationSetupItem.c:8:
UPTransportLayerInformation.h:35:3: error: unknown type name ‘ProtocolIE_SingleContainer_9553P47_t’
   ProtocolIE_SingleContainer_9553P47_t  choice_Extensions;

When I search for the definition of the ProtocolIE_SingleContainer_128P31_t I find this:

./ProtocolIE-SingleContainer.h:typedef NPN_Support_ExtIEs_t  ProtocolIE_SingleContainer_128P31_t;

and ProtocolIE-SingleContainer.h is included in UPTransportLayerInformation.h

in ./ProtocolIE-Field.h I expect that the type NPN_Support_ExtIEs_t is well defined:

typedef struct NPN_Support_ExtIEs {
    ProtocolIE_ID_t  id;
    Criticality_t    criticality;
    struct NPN_Support_ExtIEs__value {
        NPN_Support_ExtIEs__value_PR present;
        union NPN_Support_ExtIEs__value_u {
        } choice;

        /* Context for parsing across buffer boundaries */
        asn_struct_ctx_t _asn_ctx;
    } value;

    /* Context for parsing across buffer boundaries */
    asn_struct_ctx_t _asn_ctx;
} NPN_Support_ExtIEs_t;

The header ProtocolIE-Field.h is included in the file ./ProtocolIE-SingleContainer.h like this:

include "ProtocolIE-Field.h"

Do I have to specify the order to the compiler?

raoufkh commented 3 years ago

By trying to compile with make instead of cc, I think I figured out where the problem is coming from. Some data types are not defined. I've checked for these types in all headers and I didn't find any definition for them.

ProtocolIE-SingleContainer.h:62:9: error: unknown type name ‘UserLocationInformation_ExtIEs_t’
 typedef UserLocationInformation_ExtIEs_t  ProtocolIE_SingleContainer_9331P40_t;
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ProtocolIE-SingleContainer.h:63:9: error: unknown type name ‘UserLocationInformationW_AGF_ExtIEs_t’
 typedef UserLocationInformationW_AGF_ExtIEs_t  ProtocolIE_SingleContainer_9331P41_t;
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ProtocolIE-SingleContainer.h:64:9: error: unknown type name ‘W_AGF_ID_ExtIEs_t’
 typedef W_AGF_ID_ExtIEs_t  ProtocolIE_SingleContainer_9331P42_t;
         ^~~~~~~~~~~~~~~~~
ProtocolIE-SingleContainer.h:65:9: error: unknown type name ‘WarningAreaList_ExtIEs_t’
 typedef WarningAreaList_ExtIEs_t  ProtocolIE_SingleContainer_9331P43_t;
         ^~~~~~~~~~~~~~~~~~~~~~~~

I mention that when compiling the ASN1 file, I have lots of warnings:

.
.
.
WARNING: Parameterized type NGAP-PROTOCOL-EXTENSION expected for NGAP-PROTOCOL-EXTENSION at line 9382 in ngap.asn
WARNING: Parameterized type NGAP-PROTOCOL-EXTENSION expected for NGAP-PROTOCOL-EXTENSION at line 9382 in ngap.asn
WARNING: Parameterized type NGAP-PROTOCOL-EXTENSION expected for NGAP-PROTOCOL-EXTENSION at line 9383 in ngap.asn
WARNING: Parameterized type NGAP-PROTOCOL-EXTENSION expected for NGAP-PROTOCOL-EXTENSION at line 9383 in ngap.asn
WARNING: Parameterized type NGAP-PROTOCOL-EXTENSION expected for NGAP-PROTOCOL-EXTENSION at line 9383 in ngap.asn
WARNING: Parameterized type NGAP-PROTOCOL-EXTENSION expected for NGAP-PROTOCOL-EXTENSION at line 9384 in ngap.asn
WARNING: Parameterized type NGAP-PROTOCOL-EXTENSION expected for NGAP-PROTOCOL-EXTENSION at line 9384 in ngap.asn
WARNING: Parameterized type NGAP-PROTOCOL-EXTENSION expected for NGAP-PROTOCOL-EXTENSION at line 9384 in ngap.asn
WARNING: Parameterized type NGAP-PRIVATE-IES expected for NGAP-PRIVATE-IES at line 9398 in ngap.asn
WARNING: Parameterized type NGAP-PRIVATE-IES expected for NGAP-PRIVATE-IES at line 9399 in ngap.asn
WARNING: Parameterized type NGAP-PRIVATE-IES expected for NGAP-PRIVATE-IES at line 9400 in ngap.asn
WARNING: Parameterized type NGAP-PRIVATE-IES expected for NGAP-PRIVATE-IES at line 9398 in ngap.asn
WARNING: Parameterized type NGAP-PRIVATE-IES expected for NGAP-PRIVATE-IES at line 9398 in ngap.asn
WARNING: Parameterized type NGAP-PRIVATE-IES expected for NGAP-PRIVATE-IES at line 9398 in ngap.asn
WARNING: Parameterized type NGAP-PRIVATE-IES expected for NGAP-PRIVATE-IES at line 9399 in ngap.asn
WARNING: Parameterized type NGAP-PRIVATE-IES expected for NGAP-PRIVATE-IES at line 9399 in ngap.asn
WARNING: Parameterized type NGAP-PRIVATE-IES expected for NGAP-PRIVATE-IES at line 9399 in ngap.asn
WARNING: Parameterized type NGAP-PRIVATE-IES expected for NGAP-PRIVATE-IES at line 9400 in ngap.asn
WARNING: Parameterized type NGAP-PRIVATE-IES expected for NGAP-PRIVATE-IES at line 9400 in ngap.asn
WARNING: Parameterized type NGAP-PRIVATE-IES expected for NGAP-PRIVATE-IES at line 9400 in ngap.asn

I am using the ASN1 spec of NGAP (3GPP 38413 v16.5.0) according to the standard compliant with ITU-T Rec X.691, IUT-T Rec X.680 and ITU-T Rec X.681

mouse07410 commented 3 years ago

I don't think I can help with this problem, as 3GPP NGAP tends to push ASN.1 to limits that this compiler currently doesn't seem to support.

Please see https://github.com/mouse07410/asn1c/issues/48 , and maybe folks at the upstream would be able to help.

Also, @brchiu and @velichkov do you have any recommendation or workaround here?

raoufkh commented 3 years ago

Hello @mouse07410 mouse07410

I'm now able to compile the ASN1 files with both https://github.com/mouse07410/asn1c/ and https://github.com/velichkov/asn1c forks.

When trying to compile the converter example, there is some errors to solve manually (false declarations of variables in funtions).

I'll put here the command I used to compile, when I'll have access to my another PC.

Thank you, Abderaouf

raoufkh commented 3 years ago

I would like to say thanks fo your effort.

mouse07410 commented 3 years ago

@raoufkh you're very welcome.

It would be great if you could post your workaround here, as I'm sure it would be helpful for many others facing the same problem. Thanks!

raoufkh commented 3 years ago

I've compiled asn1c as shown in the documentation. Then I use this command to compile ASN files.

asn1c \
    -pdu=NGAP-PDU \
    -fcompound-names \
    -fno-include-deps \
    -findirect-choice \
    -gen-APER \
    -no-gen-BER \
    -no-gen-XER \
    -no-gen-OER \
    -no-gen-UPER \
    ngap-v16.5.0.asn

Then I compile the converter example:

asn1c \
    -pdu=NGAP-PDU \
    -fcompound-names \
    -fno-include-deps \
    -findirect-choice \
    -gen-APER \
    -no-gen-BER \
    -no-gen-XER \
    -no-gen-OER \
    -no-gen-UPER \
    ngap-v16.5.0.asn

Then I corrected manually errors by replacing the not defined variables. In ly case, it was asn_PER_memb_OCTET_STRING_CONTAINING_PDUSessionResourceReleaseResponseTransfer__constr_44.

You can then recompile and you'll have the example executable.

mouse07410 commented 3 years ago

Thanks. But I think your post needs correction.

First - instead of showing the compile command for the converter example, you showed again the ASN.1 compiling.

Second - I think it would be useful for everybody to see exactly what you replaced the missing names with.

I also don't think you need to explicitly set the -gen-APER flag - it's supposed to be on by default.

raoufkh commented 3 years ago

Because without these parameters (except -gen-APER which is enabled by default), I wasn't able to to confine errors in only one. So I recommend to use -fno-include-deps -findirect-choice to minimize variables which will be present in the compiled files.

Then, the paramater to correct change from one compilation to another but it begins always by asn_PER_memb_OCTET_STRING_CONTAINING_PDUSessionResourceReleaseResponseTransfer__constr. In case someone has generated files for another encoding rules he'll have to correct the same parameter but with the new encoding rules instead of _PER_

I'll explain more the message error: this variablewas used in a function were it wasn't defined locally. The parameter in the function was memb_OCTET_STRING_CONTAINING_PDUSessionResourceReleaseResponseTransfer__constraint_648 and so the user will have to do replacements in that function.

The compiler cc will suggest which parameter to replace the undefined variable.

Is that more clear?

mouse07410 commented 3 years ago

Because without these parameters (except -gen-APER which is enabled by default), I wasn't able to to confine errors in only one

I meant that the -gen-APER could be omitted, and just having -no-gen-<whatever> would be sufficient. But I agree that your way is clearer for the reader.

So I recommend to use -fno-include-deps -findirect-choice

I don't think I'd agree with -fno-include-deps, but whatever works...

. . . he'll have to correct the same parameter . . .

What I wanted to see here was what to change it to. I.e., you're changing asn_PER_memb_OCTET_STRING_CONTAINING_PDUSessionResourceReleaseResponseTransfer__constr to what? And where?

The compiler cc will suggest which parameter to replace the undefined variable.

That's great to know. I'd still prefer to see it explicitly posted here. Something like

Is that more clear?

Yes, thanks - but some more clarification would help, I think.

raoufkh commented 3 years ago

Ah okay I see better now what you want to see

gatopeich commented 3 years ago

I edited that file, changing it to memb_OCTET_STRING_CONTAINING_PDUSessionResourceReleaseResponseTransfer__constraint_648 ==> this was proposed by the cc compiler or even when you compile with `make -f conterter-example.mk

That it was proposed by compiler does NOT mean it is correct for encoding decoding, just that the name is similar enough!

This is likely an issue of including the required headers in the right order, which sometimes can be hard...