Commit Graph

51 Commits (master)

Author SHA1 Message Date
Neels Hofmeyr a33955ce8f fix leak in error paths of iesDefs
Related: SYS#6297
Change-Id: I424c4ea2681f5c9a5eec99396502615de5eab841
2023-04-27 16:41:49 +00:00
Oliver Smith 69bb2fab2b asn1tostruct: don't use f-strings
Make the script work with python < 3.6 again by not using f-strings.

Fix for:
  SyntaxError: invalid syntax
    File "../../git/asn1/utils/", line 94
      f" IE {ie}. Found another entry in ies {ie_other}" \

Fixes: 1d19c8e2 ("asn1tostruct: fix defines getting redefined")
Change-Id: I3a19b8a1147532b41d3ed7b802de595302ff8f44
2022-11-16 10:27:52 +01:00
Oliver Smith 1d19c8e21e asn1tostruct: fix defines getting redefined
Do not write the same define twice for two files in a struct, e.g.:


  typedef struct RANAP_EnhancedRelocationCompleteRequestIEs_s {
      uint16_t                                 presenceMask;
      RANAP_IuSignallingConnectionIdentifier_t oldIuSigConId;
      RANAP_IuSignallingConnectionIdentifier_t iuSigConId;
      RANAP_GlobalRNC_ID_t                     relocation_SourceRNC_ID;
      RANAP_ExtendedRNC_ID_t                   relocation_SourceExtendedRNC_ID; ///< Optional field
      RANAP_GlobalRNC_ID_t                     relocation_TargetRNC_ID;
      RANAP_ExtendedRNC_ID_t                   relocation_TargetExtendedRNC_ID; ///< Optional field
      RANAP_RAB_SetupList_EnhancedRelocCompleteReq_t raB_SetupList_EnhancedRelocCompleteReq; ///< Optional field
  } RANAP_EnhancedRelocationCompleteRequestIEs_t;

The problem is that the type is used and it may not be unique inside a
struct. Change the code to use the name of the field if the type is not
unique. Keep using the type otherwise so existing code doesn't need to
be modified a lot to fix this.

Fix for:

Change-Id: I2ecae6789899952d1dc5691ab76907abeaa71c12
2022-11-15 11:16:38 +01:00
Oliver Smith 48c038d399 asn1: fix visibility warnings from generated code
Fix warnings from generated asn1 code in order to build osmo-iuh with
werror in a future patch:

../../include/osmocom/hnbap/HNBAP_CriticalityDiagnostics-IE-List.h:29:23: error: ‘struct HNBAP_CriticalityDiagnostics_IE_List__Member’ declared inside parameter list will not be visible outside of this definition or declaration [-Werror]

These visibility warnings come from "SEQUENCE … OF SEQUENCE" definitions
in the asn1 source files, as described in detail here:

It is not possible to tell gcc to just ignore these warnings since they
don't have their own type (unlike e.g. -Wuninitialized). Also it seems
like a huge effort to patch this in asn1c.

So work around the problem the same way the author of the issue worked
around it by rewriting the lines to "SEQUENCE … OF …-Value" and adding
a "…-Value ::= SEQUENCE" line below. Add a script in
asn1/utils/ for the
transformation and apply it.

Related: OS#4462
Change-Id: If84445ed2e0df604b581684dcf83f8520b7da84c
2022-11-14 09:52:14 +01:00
Oliver Smith 9b4de3f401 treewide: remove FSF address
Remove the paragraph about writing to the Free Software Foundation's
mailing address. The FSF has changed addresses in the past, and may do
so again. In 2021 this is not useful, let's rather have a bit less
boilerplate at the start of source files.

Change-Id: I340ab63093138ada6e80edf322e401e9fbfef4ed
2021-12-14 12:16:45 +01:00
Oliver Smith 16441ffbb3 debian, switch to python3
Make build work with python3 and drop the python2 dependency.

Related: OS#2819
Change-Id: Idb9d7a349ddb7619c784823f740648c7956bae5e
2019-12-11 11:37:21 +01:00
Harald Welte 7095c7ed0c sabp: Add Procedure Codes and IEI constants to CommonDataTypes
... this is what's required for asn1c to generate nice C language
enums for it.  Conversion was performed semi-automatically by use

Change-Id: I0cd78a102ec6e31c696efc2cc6a4f08a0ba6d89e
2019-09-21 09:41:46 +02:00
Harald Welte f7f85ef092 sabp: fixup SABP ASN.1 to avoid IOC (which are not supported by our toolchain)
Change-Id: I8211bc334b325e8950edcd769917f164a65591ba
2019-09-21 09:41:46 +02:00
Harald Welte d673facccd sabp: Initial import of SABP ASN.1 from 3GPP TS 25.419 V11.1.0 (2013-03)
They cannot immediately be consumed by our (ancient, hacked) asn1c
toolchain, so we have to massage them into the supported format
in follow-up commits.

Change-Id: I9fa05d14493889e0a23354938b04a335a117f242
2019-09-21 09:41:34 +02:00
Harald Welte 175cc0f710 Make compatible with modern perl
This fixes the following error message:
Experimental keys on scalar is now forbidden at ./ line 25.

Change-Id: I4680627acfd8f3ed73d32324fe0a54b554268f3b
2019-09-20 22:10:50 +00:00
Bernhard M. Wiedemann 7a97fcafed asn1tostruct: allow to override build date
in order to make builds reproducible.
See for why this is good
for the definition of this variable.

Also do not record build user name to not have it vary.

Change-Id: I5cfa465cc82f009f28dd7f12ced0e72a05fda842
2018-05-30 13:21:57 +02:00
Neels Hofmeyr f33d16404d compiler warning: return 0 at end of *_free_*()
Part of the resulting diff in the generated code:

--- /tmp/hnbap_decoder.c	2017-12-24 17:06:50.983979866 +0100
+++ /tmp/hnbap_decoder.c	2017-12-24 17:07:10.760223354 +0100
@@ -1179,6 +1179,7 @@
     TNLUpdateResponseIEs_t *tnlUpdateResponseIEs) {

     ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_Context_ID, &tnlUpdateResponseIEs->context_ID);
+    return 0;

 int hnbap_free_tnlupdaterequesties(
@@ -1187,6 +1188,7 @@
     ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_Context_ID, &tnlUpdateRequestIEs->context_ID);
     ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RABList, &tnlUpdateRequestIEs->rabList);
     ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_Update_cause, &tnlUpdateRequestIEs->update_cause);
+    return 0;

 int hnbap_free_errorindicationies(
@@ -1197,12 +1199,14 @@
         ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_CriticalityDiagnostics, &errorIndicationIEs->criticalityDiagnostics);
+    return 0;

 int hnbap_free_hnbconfigtransferrequesties(
     HNBConfigTransferRequestIEs_t *hnbConfigTransferRequestIEs) {

     ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_NeighbourInfoRequestList, &hnbConfigTransferRequestIEs->neighbourInfoRequestList);
+    return 0;

 int hnbap_free_tnlupdatefailureies(


Related: OS#2670
Change-Id: Ieba12c09c33a81da964bf88a858714d922ced8c0
2017-12-25 00:46:12 +01:00
Neels Hofmeyr 6eeef115a9 hnbap,rua,ranap decode: fix segfault on decode error
Looking at hnbap_decode_hnbregisterrequesties(), I noticed a segfault if
decoding the HNB Register Request PDU fails, which is due to an unchecked
return value in code generated by

Add return value and NULL pointer checks and hence fix null dereference on
erratic PDUs across HNBAP, RUA and RANAP protocols. Similar checks exist in
other places, this one was simply missing.

Since the result of is not committed, here is an example diff
of the resulting change, of which there are 128 instances in total:

@@ -304,7 +329,12 @@
     memset(hnbRegisterRequestIEs, 0, sizeof(HNBRegisterRequestIEs_t));
     HNBAP_DEBUG("Decoding message HNBRegisterRequestIEs (%s:%d)\n", __FILE__, __LINE__);

-    ANY_to_type_aper(any_p, &asn_DEF_HNBRegisterRequest, (void**)&hNBRegisterRequest_p);
+    tempDecoded = ANY_to_type_aper(any_p, &asn_DEF_HNBRegisterRequest, (void**)&hNBRegisterRequest_p);
+    if (tempDecoded < 0 || hNBRegisterRequest_p == NULL) {
+        HNBAP_DEBUG("Decoding of message HNBRegisterRequestIEs failed\n");
+        return -1;
+    }

     for (i = 0; i < hNBRegisterRequest_p->hnbRegisterRequest_ies.list.count; i++) {
         IE_t *ie_p;

Change-Id: I6cb9cc9a88d22f03befa43f0968a874476fa079d
2017-12-20 23:31:45 +01:00
Pau Espin 166a3767bd specify python version in shebang
The script is expected to be run using python 2.x, but nowadays some
distros are already using python 3 as default, which will fail to run
this script.

This change fixes compilation in my Archlinux box.

Change-Id: I6eb95351538a64f2b23d638824972818591b1b66
2017-04-05 11:22:53 +02:00
Neels Hofmeyr f706d6c065 use '#\!/usr/bin/env python', not '#\!/usr/bin/python'
Change-Id: I0686467e59b35e68bccb38ccfe645f5ccac97941
2016-07-12 00:44:18 +02:00
Daniel Willmann 19dea8b49b asn1: Generate _free_*ies function declarations
ranap_ies_defs.h is checked in so update it

hnbap_ies_defs.h and rua_ies_defs.h need to be regenerated
2016-02-22 11:15:04 +01:00
Daniel Willmann 86a14053d8 Zero IEs_t target struct in decode function 2016-01-12 09:46:21 +01:00
Daniel Willmann d10002cf8d asn1tostruct: Add memory free functions and use them in HNBAP 2016-01-07 12:27:41 +01:00
Neels Hofmeyr c13ebf78c8 don't generate unused local struct instances. 2016-01-05 13:39:22 +01:00
Harald Welte c371a42938 RANAP-PDU-Contents: fix syntax error regarding InitialUE-Message
With that syntax error, the RAC was not treated as a possible IE
in the InitialUE-Message, causing decoder failure.
2015-12-27 11:03:44 +01:00
Harald Welte c89c2a6e6a RANAP: Replace the last remainng TBCD-STRING with OCTET STRING
in order to work around a bug in asn1c.  When we keep the original
TBCD-STRING, the APER-encoded PLMNidentity always has an extra leading
length byte that the decoder doesn't expect.
2015-12-24 14:07:05 +01:00
Daniel Willmann d174e76f1d Fix memory leaks in generated code
The decode_*ies functions did not clean up after them. This change is
taken from changes made to in openair-cn repository.
2015-12-22 16:40:46 +01:00
Neels Hofmeyr 8aac21a5e8 Remove obsolete ffasn1c files.
The ffasn1c files from early trials are obsolete, we're using asn1c now.
2015-12-22 13:02:42 +01:00
Harald Welte b2daa0d803 ranap ASN.1: Define IMSI as OCTET STRING to work around asn1c bug
When IMSI is a TBCD-STRING type, and TBCD-STRING is defined as OCTET
STRING, we end up encoding the IMSI the wrong way.  I don't knwo why
that is, but changing it fixed the problem, as described below:

before this commit:
00 17                           PeranentNAS-UE-ID
40                              criticality ignore
0a                              (length)
00                              presence = IMSI
08                              BUG: why the additional length field?
46 23 91 34 70 77 80 f3         IMSI (643219430777083)

after this commit:
00 17                           PeranentNAS-UE-ID
40                              criticality ignore
09                              (length)
50                              presence = IMSI
46 23 91 34 70 77 80 f3         IMSI (643219430777083)
2015-12-19 13:05:19 +01:00
Harald Welte b7f67c4b14 ranap: Don't forget ProtocolIE-CointainerPair around ProtocolIE-FieldPair 2015-12-19 02:37:35 +01:00
Harald Welte 93690184b0 RANAP: Split FormatInformationParameter / SDUParameterItem
The definition of the above data types as per 3GPP specs results in a
SEQUENCE_OF() an anonymous structure, which is slightly inconvenient to
use.  So let's split the SEQUENCE OF part and the actual definition of
the item in separate types.
2015-12-18 13:35:58 +01:00
Harald Welte 49695572ba One further RANAP hacking session
This is not development, it is random trial and error hacking.  I really
hate the fact that we have no useful asn.1 code generator and need to
work with hacks like and asn1c without information
object classes :/

This commit is a one-day-long iteration of trial+error, manually editing
and adding the .asn source of RANAP until we get something that in the
end at least compiles and links.  Do I trust the resulting code? No.
But we have no alternative :(
2015-12-16 17:26:05 +01:00
Harald Welte a0c74240fa asn1tostruct: Avoid erroneous double-underscores
We shouldn't generate names like
RANAP_RAB_SetupList_EnhancedRelocCompleteReq__t when creating the
_encode() and _decode() functiosn, as the '-IEs' at the end must be
stripped before converting all '-' to '_'.
2015-12-16 16:45:48 +01:00
Harald Welte 1989913ba2 RANAP: Add more types/IEs to RANAP-PDU.asn and re-generate C
As asn1c cannot understand information object classes, we cannot compile
RANAP-PDU-Contents.asn but instead need to manually add the respective
infrmation elements to RANAP-PDU.asn.
2015-12-16 13:15:02 +01:00
Harald Welte 6289cc6248 remove obsolete asn1c makefiles in the asn1c/ hierarchy
we are generating the code locally in src/{ranap,rua,hnbap}
2015-09-11 00:17:07 +02:00
Harald Welte ac9c024432 ranap: Add more manual definitions to RANAP-PDUs
It seems that individual IEs contain nested containers, and
asn1c is not generating code for that unless we help it by some
hand-crafted additional definitions. *sigh*
2015-09-10 21:18:16 +02:00
Harald Welte 84839c04ea Add support for type prefixing
If asn1c generates prefixed type names, the of course
also needs to be modified to do so.
2015-09-10 18:33:14 +02:00
Harald Welte 547b76c5b4 Don't claim copyright on auto-generated code
It is a legal impossibility to claim copyright on something that
has been automatically generated by a computer program.
2015-08-30 22:48:59 +02:00
Harald Welte 245daf9422 import from Eurecom OpenAirInterface 2015-08-30 22:48:59 +02:00
Harald Welte 1c2b568d79 HNBAP: Remove HNBRegisterAccept / HNBRegisterResposne naming inconsistency
A HNBRegisterAccept message should not contain HNBRegisterResponse IEs

This spec inconsistency is confusing the code generator,
so let's remove it.
2015-08-30 20:11:50 +02:00
Harald Welte 8d6026742f generate ASN.1 structures for each message withotu iformation object class
this is done semi-automatically using the script.
2015-08-30 19:57:43 +02:00
Harald Welte 96ec96e3b4 asn1 syntax fixup for ffasn1c 2015-08-30 19:10:58 +02:00
Harald Welte 3bd59c9d59 Add Procedure Codes and IEI constants to CommonDataTypes
... this is what's required for asn1c to generate nice C language
enums for it.  Conversion was performed semi-automatically by use
2015-08-30 19:09:55 +02:00
Harald Welte f24cabee15 RANAP: Further qualify Constants. They're not just integer 2015-08-30 19:03:57 +02:00
Harald Welte ba404f9e48 RUA ASN.1 Rewrite to avoid information object classes
If we avoid using Information Object Classes in the IE definitions
(which are only used for Extension Containers), then we can compile the
ASN.1 source using Lev Walkin's asn1c.
2015-08-30 17:46:36 +02:00
Harald Welte 4f119e58e9 RANAP ASN.1 Rewrite to avoid information object classes
If we avoid using Information Object Classes in the IE definitions
(which are only used for Extension Containers), then we can compile the
ASN.1 source using Lev Walkin's asn1c.
2015-08-30 17:46:03 +02:00
Harald Welte 355d9513c0 HNBAP ASN.1: Rewrite to avoid information object classes
If we avoid using Information Object Classes in the IE definitions
(which are only used for Extension Containers), then we can compile the
ASN.1 source using Lev Walkin's asn1c.
2015-08-30 17:11:20 +02:00
Harald Welte b866659991 ADD IU-Common.asn as an attempt to unify the message parsing 2015-08-30 14:28:10 +02:00
Harald Welte ac0435b691 fixup ffasn1 2015-08-30 12:19:54 +02:00
Harald Welte 1458c09583 give asn1c generated files more useful names 2015-08-30 11:51:06 +02:00
Harald Welte e180c16ba1 Add generated code for RUA using eurecom 2015-08-29 20:34:40 +02:00
Harald Welte c0e8e5c567 add ffasn1c generated code for HNBAP, RANAP and RUA 2015-08-29 20:34:21 +02:00
Harald Welte 511365b056 RUA: Add missing RUA-PDU-Contents.asn and RUA-PDU-Descriptions.asn 2015-08-29 12:32:02 +02:00
Harald Welte 8f2fb0cca5 Import RANAP from 3GPP TS 25.413 V12.4.0 (2015-03) 2015-08-29 12:19:42 +02:00
Harald Welte ac666f5831 Import HNBAP asn.1 from 3GPP TS 25.469 V12.4.0 (2015-03) 2015-08-29 10:00:38 +02:00