vlm / asn1c

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

Failure while decoding ETSI MAPEM #272

Open kelunik opened 6 years ago

kelunik commented 6 years ago

I'm currently trying to decode MAPEMs with Vanetza using revision 20 of the ETSI ASN.1 definitions, but uper_decode_complete() results in the following error obtained via the debug output.

Decoding member "regExtValue" in RegionalExtension (.../vanetza/asn1/its/constr_SEQUENCE.c:1170)
Type selector is not defined for Open Type RegionalExtension->regExtValue->regExtValue (.../vanetza/asn1/its/OPEN_TYPE.c:304)
Failed to decode element RegionalExtension (.../vanetza/asn1/its/OPEN_TYPE.c:305)
Failed decode regExtValue in RegionalExtension (.../vanetza/asn1/its/constr_SEQUENCE.c:1180)

I'm not sure what's wrong and what to do with that error message. Both, Wireshark and an online decoder, decode the message I'm trying to decode just fine. Does the above error need a fix in asn1c or do I need a fix in my code? I can provide the used MAPEM in case a change inside asn1c is required.

DanyaFilatov commented 6 years ago

Could you please provide a MAPEM example?

kelunik commented 6 years ago

Sure, see below.

01050000007B0800030456994E0DF96DD9B380188B170134B69F665C144C63803040C35000002A8564802280000001B35F0B47900047AB1C568F16F7111E9770542D3CC3F241700A1000907E044804280000001B3738B2DD00047A53C1E8F1277011EA0F0E42D24C15141680A06408900C50000000567169623A0008F2F57D01E2E6E101F9DC803B7F5C86D860A06C7AB02060084014480000002273BD5710F3557D31E2BEDF83D52E200401848000000127A8F4F80273F4D1ACF7A8008200824000000193AE9A8C158576A280082D45C6C1E312DF83D556268D02C458002000000CCFA2C894001033713820303CD030458002000000CDFB6B2E40010472E80202C34D0344580020000004E232AB443911120008203834D038458002000000CEA4E92A4001046AE70203444905090000000327B293B282564B01C10B81C5CC313B1D7D2002820180C9054900000001676A32CE2000AF222D55400517FC2E5821001090589000000016762324920008F224D6B17F32D60A0FC1105C0A482E480000000B3AE18D85000478E86AF8BFDD75C105A0A203044000000093A7F7A7478596BF8BE8574840648800000012748AE968F0AEDD317D0AED9A0F91300040000019E1E50F48002065DFD04100A9A1011300040000019F5950C0800209DA1C040F8A800D800080000049937BD6A3D06B44C7D8E615820D000080000089D184E341F5ABA078066D70BB4584410840848526800000012F656C3D400119E9D25220B024110CE969020641890A8D000000015E7419348002201C186107911E820601890ACD0000000357C2224200088608A78421A4F6218729A053896020101C90B0D00000002575328BA0008859CAB842C651621632A1240283A0FC2108010205A6400000010B3D994843A85D021862CD109E92A081719000000041F98AC5474C9088008202A1B710851181A1999B00040000017D5E6792000823C740106830686866C00100000057D735D200081D088010662C686A66C001000000578EB8920008240760106C38686C66C0010000005630401A00081C8900106A34205E640000002032A6B40F8A4607590303387981874A10B02908008487A8800000012A8BB0BD000460B4A290C14344C67514C492002820642890F9100000001554A6BE20008C14F4321829E91848180A40205A0142C40FD0800000021CFEF3D0305A50FC661A97908AB666441010800000041D15361E306A513026D23C84E3C13098D8D81135318D11D11800200000087975D40010306E98212078D1211180020000009C116B50004139C4608471E344944600080000027A7E9E400103D8D3021287CD129118002000000AC36DF5400104512D021247CD12D118002000000BA98E42900040F8B38084C20344C4460008000002EB9BB51400104473E8212C8090F11000000030C93D3006270402E96D015FA1D08FCC2800A082F090441000100000086FD75A182E688230555238103614008400020000042639B56C0130B3C0A2D400442AC01E3448036A60
velichkov commented 6 years ago

Hi kelunik,

I was able to successfully decode this message using the s1ap branch (27eaf82abed937a2da5a5fd9e0d4076d9abcfc75) from my repository. You need to compile with -findirect-choice option and then manually fix some errors.

$ asn1c -fcompound-names -findirect-choice -pdu=MAPEM -pdu=all  ../CDD_TS102894-2/ITS-Container.asn ../CAM_EN302637-2/CAM.asn ../DENM_EN302637-3/DENM.asn ../IS_TS103301/ISO_TS_24534-3.asn ../IS_TS103301/ISO_TS_14816.asn ../IS_TS103301/ISO_TS_14906_Application.asn ../IS_TS103301/ISO_TS_17419.asn ../IS_TS103301/ISO_TS_19091.asn ../IS_TS103301/ISO_TS_19321.asn ../IS_TS103301/ETSI_TS_103301.asn
$ make -f converter-example.mk 
cc  -DPDU=MAPEM -DASN_PDU_COLLECTION -I. -o ConnectionTrajectory-addGrpC.o -c ConnectionTrajectory-addGrpC.c
In file included from NodeOffsetPointXY.h:80:0,
                 from NodeXY.h:15,
                 from NodeSetXY.h:44,
                 from ConnectionTrajectory-addGrpC.h:15,
                 from ConnectionTrajectory-addGrpC.c:8:
RegionalExtension.h:246:4: error: unknown type name ‘ConnectionTrajectory_addGrpC_t’
    ConnectionTrajectory_addGrpC_t  ConnectionTrajectory_addGrpC;
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
make: *** [converter-example.mk:23: ConnectionTrajectory-addGrpC.o] Error 1
diff --git a/LaneDataAttribute.c b/LaneDataAttribute.c
index 778645f..b9c46d1 100644
--- a/LaneDataAttribute.c
+++ b/LaneDataAttribute.c
@@ -6,6 +6,7 @@
  */

 #include "LaneDataAttribute.h"
+#include "RegionalExtension.h"

 static int
 memb_regional_constraint_1(const asn_TYPE_descriptor_t *td, const void *sptr,
diff --git a/LaneDataAttribute.h b/LaneDataAttribute.h
index f01d463..eef6498 100644
--- a/LaneDataAttribute.h
+++ b/LaneDataAttribute.h
@@ -79,7 +79,6 @@ extern asn_per_constraints_t asn_PER_type_LaneDataAttribute_constr_1;

 /* Referred external types */
 #include "SpeedLimitList.h"
-#include "RegionalExtension.h"

 #endif /* _LaneDataAttribute_H_ */
 #include <asn_internal.h>
diff --git a/NodeAttributeSetXY.c b/NodeAttributeSetXY.c
index 09d8292..b6b7248 100644
--- a/NodeAttributeSetXY.c
+++ b/NodeAttributeSetXY.c
@@ -6,6 +6,7 @@
  */

 #include "NodeAttributeSetXY.h"
+#include "RegionalExtension.h"

 static int
 memb_regional_constraint_1(const asn_TYPE_descriptor_t *td, const void *sptr,
diff --git a/NodeAttributeSetXY.h b/NodeAttributeSetXY.h
index ff6f870..3d2328d 100644
--- a/NodeAttributeSetXY.h
+++ b/NodeAttributeSetXY.h
@@ -63,7 +63,6 @@ extern asn_TYPE_member_t asn_MBR_NodeAttributeSetXY_1[7];
 #include "NodeAttributeXYList.h"
 #include "SegmentAttributeXYList.h"
 #include "LaneDataAttributeList.h"
-#include "RegionalExtension.h"

 #endif /* _NodeAttributeSetXY_H_ */
 #include <asn_internal.h>
diff --git a/NodeOffsetPointXY.c b/NodeOffsetPointXY.c
index 5a81140..a22317a 100644
--- a/NodeOffsetPointXY.c
+++ b/NodeOffsetPointXY.c
@@ -6,6 +6,7 @@
  */

 #include "NodeOffsetPointXY.h"
+#include "RegionalExtension.h"

 static asn_oer_constraints_t asn_OER_type_NodeOffsetPointXY_constr_1 CC_NOTUSED = {
    { 0, 0 },
diff --git a/NodeOffsetPointXY.h b/NodeOffsetPointXY.h
index 8afa6ad..bee2592 100644
--- a/NodeOffsetPointXY.h
+++ b/NodeOffsetPointXY.h
@@ -77,7 +77,6 @@ extern asn_per_constraints_t asn_PER_type_NodeOffsetPointXY_constr_1;
 #include "Node-XY-28b.h"
 #include "Node-XY-32b.h"
 #include "Node-LLmD-64b.h"
-#include "RegionalExtension.h"

 #endif /* _NodeOffsetPointXY_H_ */
 #include <asn_internal.h>

and after applying the above changes

$ make -f converter-example.mk
$ xxd -r mapem.uper.hex.txt | ./converter-example -iper -
<MAPEM>
    <header>
        <protocolVersion>1</protocolVersion>
        <messageID>5</messageID>
        <stationID>123</stationID>
    </header>
    <map>
        <msgIssueRevision>0</msgIssueRevision>
        <intersections>
            <IntersectionGeometry>
                <name>VLSA_K733</name>
                <id>

The attached mapem.tar.gz contains your hex message reformatted to be compatible for xxd, the fully decoded message in XML/XER format and the manual changes in patch format.

velichkov commented 6 years ago

Hi @kelunik,

Both, Wireshark and an online decoder, decode the message

I guess you are using the ITS.WIRESHARK_ITS_PLUGINS to decode with wireshark. Could you share a pcap file?

brchiu commented 6 years ago

@velichkov, I downloaded these ASN files from http://oldforge.etsi.org/websvn/listing.php?repname=ITS.ITS_ASN1&rev=29&peg=28 and followed your command line to generate files, but it shows a lot error message. Strangely that module ITS-Container indeed exists in ../CDD_TS102894-2/ITS-Container.asn. Did I miss any necessary step ?

FATAL: Cannot find external module "ITS-Container" mentioned for "ItsPduHeader" at line 18. Obtain this module and instruct compiler to process it too. in ../CAM_EN302637-2/CAM.asn
FATAL: Unknown type "ItsPduHeader" referenced by "header" at line 18 in ../CAM_EN302637-2/CAM.asn
FATAL: Cannot find external module "ITS-Container" mentioned for "StationType" at line 58. Obtain this module and instruct compiler to process it too. in ../CAM_EN302637-2/CAM.asn
FATAL: Unknown type "StationType" referenced by "stationType" at line 58 in ../CAM_EN302637-2/CAM.asn
.....

I am interested in looking into the compilation problem you encounter but was stopped at here.

velichkov commented 6 years ago

Strange.

I've used an URL from the vanetza's CMakeList.txt to download a tar archive with all asn files and then just extracted them, created a src subdirectory and compile in it.

http://oldforge.etsi.org/websvn/dl.php?repname=ITS.ITS_ASN1&path=%2Ftrunk%2F&isdir=1&rev=20

I just tested it without facing this problem

brchiu commented 6 years ago

@velichkov , rev=20 can generate files (I use rev=29). I can start investigation. Thanks a lot !

velichkov commented 6 years ago

Yes in r29 there is OID mismatch.

The ITS-Container is cdd (2) version (2)

ITS-Container {
itu-t (0) identified-organization (4) etsi (0) itsDomain (5) wg1 (1) ts (102894) cdd (2) version (2) 
}

while the CAM.asn imports cdd (2) version (1)

CAM-PDU-Descriptions {
itu-t (0) identified-organization (4) etsi (0) itsDomain (5) wg1 (1) en (302637) cam (2) version (1) 
}

DEFINITIONS AUTOMATIC TAGS ::=

BEGIN

IMPORTS 
ItsPduHeader, CauseCode, ReferencePosition, AccelerationControl, Curvature, CurvatureCalculationMode, Heading, LanePosition, EmergencyPriority, EmbarkationStatus, Speed, DriveDirection, LongitudinalAcceleration, LateralAcceleration, VerticalAcceleration, StationType, ExteriorLights, DangerousGoodsBasic, SpecialTransportType, LightBarSirenInUse, VehicleRole, VehicleLength, VehicleWidth, PathHistory, RoadworksSubCauseCode, ClosedLanes, TrafficRule, SpeedLimit, SteeringWheelAngle, PerformanceClass, YawRate, ProtectedCommunicationZone, PtActivation, Latitude, Longitude, ProtectedCommunicationZonesRSU, CenDsrcTollingZone FROM ITS-Container {
itu-t (0) identified-organization (4) etsi (0) itsDomain (5) wg1 (1) ts (102894) cdd (2) version (1) 
};
brchiu commented 6 years ago

@velichkov , I found that if you add -fno-include-deps in your command line option to asn1c, the generated code does not need any manual modification.

Also thank you for investigating why rev 29 does not work. :+1:

DanyaFilatov commented 6 years ago

Ops... Thank you for bug report. I will check and update the ETSI forge. Actually the most recent version is also available in the LibIts repository where it is used for ETSI ITS test suite. It also contains 1609.2a, Ts103097 and Ts102941 modules.

velichkov commented 6 years ago

@velichkov , I found that if you add -fno-include-deps in your command line option to asn1c, the generated code does not need any manual modification.

Cool, I wasn't aware of this parameter and I confirm that it solves this problem. Many Thanks.

velichkov commented 6 years ago

Hi @DanyaFilatov,

Actually the most recent version is also available in the LibIts repository where it is used for ETSI ITS test suite

Is this the LibIts repository you are referring to? There the ITS-Container is version (1)

DanyaFilatov commented 6 years ago

yes, the most recent is STF525 brunch where I've tested asn1c http://oldforge.etsi.org/websvn/listing.php?repname=LibIts&path=/branches/STF525/ As soon as I know currently published facilities (CAM, DENM, etc) still references to v1 of the CDD. But let me clarify it tomorrow.

kelunik commented 6 years ago

@velichkov @brchiu I tried your branch and the suggestions, but it doesn't work without changes with revision 20. Below is the error I get.

In file included from /home/kelunik/GitHub/kelunik/vanetza-map/vanetza/asn1/its/SignalHeadLocation.h:15:0,
                 from /home/kelunik/GitHub/kelunik/vanetza-map/vanetza/asn1/its/SignalHeadLocationList.h:44,
                 from /home/kelunik/GitHub/kelunik/vanetza-map/vanetza/asn1/its/MapData-addGrpC.h:46,
                 from /home/kelunik/GitHub/kelunik/vanetza-map/vanetza/asn1/its/RegionalExtension.h:21,
                 from /home/kelunik/GitHub/kelunik/vanetza-map/vanetza/asn1/its/AdvisorySpeed.h:63,
                 from /home/kelunik/GitHub/kelunik/vanetza-map/vanetza/asn1/its/AdvisorySpeedList.h:44,
                 from /home/kelunik/GitHub/kelunik/vanetza-map/vanetza/asn1/its/MovementEvent.h:60,
                 from /home/kelunik/GitHub/kelunik/vanetza-map/vanetza/asn1/its/MovementEventList.h:44,
                 from /home/kelunik/GitHub/kelunik/vanetza-map/vanetza/asn1/its/MovementState.h:17,
                 from /home/kelunik/GitHub/kelunik/vanetza-map/vanetza/asn1/its/MovementList.h:44,
                 from /home/kelunik/GitHub/kelunik/vanetza-map/vanetza/asn1/its/IntersectionState.h:21,
                 from /home/kelunik/GitHub/kelunik/vanetza-map/vanetza/asn1/its/IntersectionStateList.h:44,
                 from /home/kelunik/GitHub/kelunik/vanetza-map/vanetza/asn1/its/SPAT.h:17,
                 from /home/kelunik/GitHub/kelunik/vanetza-map/vanetza/asn1/its/SPATEM.h:16,
                 from /home/kelunik/GitHub/kelunik/vanetza-map/vanetza/asn1/spatem.hpp:6,
                 from /home/kelunik/GitHub/kelunik/vanetza-map/tools/socktap/map_application.cpp:5:
/home/kelunik/GitHub/kelunik/vanetza-map/vanetza/asn1/its/NodeOffsetPointXY.h:53:3: error: ‘Reg_NodeOffsetPointXY_t’ does not name a type; did you mean ‘NodeOffsetPointXY_u’?
   Reg_NodeOffsetPointXY_t  regional;
   ^~~~~~~~~~~~~~~~~~~~~~~
   NodeOffsetPointXY_u
brchiu commented 6 years ago

@velichkov, I found that -findirect-choice is unnecessary in this case, removing it can simplify the handling of choice type without additional malloc/calloc required. FYI.

brchiu commented 6 years ago

@kelunik, do remember to use correct command line option to generate c code, e.g. -fcompound-names -fno-include-deps in our conversation.

As long as the example program can be compiled and built, the compilation error message you post is irrelevant to asn1c itself and belongs to application level.

You have to look into them on your own, like you are looking into a generic programming issues, e.g. include necessary header files and include them in proper order... etc.

kelunik commented 6 years ago

@velichkov @brchiu I had some weird caching going on, which resulted in the option not being actually applied. I can confirm that I can successfully decode the MAPEM using the s1ap branch and -findirect-choice combined with the manual changes. :tada:

DanyaFilatov commented 6 years ago

offtopic: @velichkov @kelunik , after clarification with ETSI: only published version of ITS facility services shall be used. TS103301 v1.1.1 reference CDD v.1.2.1, so version(1) of ITS-Container module shall be used for MAPEM. Please use /releases folder of ITS_ASN1 repository instead of /trunk as a source for ASN1 modules.

pitzor commented 6 years ago

@kelunik @brchiu The problem with /home/kelunik/GitHub/kelunik/vanetza-map/vanetza/asn1/its/NodeOffsetPointXY.h:53:3: error: ‘Reg_NodeOffsetPointXY_t’ does not name a type; did you mean ‘NodeOffsetPointXY_u’? is due to circular dependency of "NodeOffsetPointXY.h" which includes "RegionalExtension.h" which includes "MapData-addGrpC.h" which includes "SignalHeadLocationList.h" which includes "SignalHeadLocation.h" which includes "NodeOffsetPointXY.h"

Is this something that the ASN file should have a protection from or should it be in the ASN1 compiler? I guess the forward declaration will work but then I need a lot of fixes of my own to make it compile.

brchiu commented 6 years ago

@pitzor, welcome to contribute a fix (or said an enhancement) to asn1c project.

pitzor commented 6 years ago

@brchiu Yeah that would be great, but unfortunately I do not have time right now :(

brchiu commented 6 years ago

@pitzor, you have no time but expect others have time ?

pitzor commented 6 years ago

@brchiu I do not expect anyone to do this but asks if there is something that could be done to the ASN files or if it is possible to add this, without too much effort, in the asn1c. I am asking because I do not have enough knowledge of the asn1c code and I have a deadline in 2 weeks. If you feel offended by my question then I apologize.