Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
raoufkh opened this issue Jun 2, 2021 · 12 comments

Comments

@raoufkh
Copy link

raoufkh commented Jun 2, 2021

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:

  • a set of .h and .c file for each type
  • a set of skeleton headers (.h) and c programs
  • converter-example.mk
  • 2 Makefiles

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 raoufkh changed the title Copiling 3GPP NGAP: get only one .h file and locate local headers <asn-application.h> Compiling 3GPP NGAP: get only one .h file and locate local headers <asn-application.h> Jun 2, 2021
@raoufkh
Copy link
Author

raoufkh commented Jun 2, 2021

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 raoufkh changed the title Compiling 3GPP NGAP: get only one .h file and locate local headers <asn-application.h> Compiling the example failed when compiling the ASN1 files with -fcompound-names (complex names for variable types) Jun 2, 2021
@raoufkh
Copy link
Author

raoufkh commented Jun 2, 2021

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
Copy link
Owner

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 #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
Copy link
Author

raoufkh commented Jun 4, 2021

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
Copy link
Author

raoufkh commented Jun 4, 2021

I would like to say thanks fo your effort.

@mouse07410
Copy link
Owner

@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
Copy link
Author

raoufkh commented Jun 6, 2021

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
Copy link
Owner

mouse07410 commented Jun 7, 2021

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
Copy link
Author

raoufkh commented Jun 8, 2021

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
Copy link
Owner

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

  • the offending variable was asn_PER_whatever_a in a file something.c
  • I edited that file, changing it to asn_PER_whatever_b
  • now it all compiles without errors

Is that more clear?

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

@raoufkh
Copy link
Author

raoufkh commented Jun 11, 2021

Ah okay I see better now what you want to see

  • the offending variable was asn_PER_memb_OCTET_STRING_CONTAINING_PDUSessionResourceReleaseResponseTransfer__constr_44 in a file ProtocolExtensionField.c
  • 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
  • For this replacement, I've run sed -i 's/asn_PER_memb_OCTET_STRING_CONTAINING_PDUSessionResourceReleaseResponseTransfer__constr_44/memb_OCTET_STRING_CONTAINING_PDUSessionResourceReleaseResponseTransfer__constraint_648/g' ProtocolExtensionField.c
  • now it all compiles without errors

@gatopeich
Copy link

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants