A2C giving errors while compiling ASN.1 code

5 views
Skip to first unread message

Amey

unread,
Jul 17, 2008, 3:04:47 AM7/17/08
to a2c-discuss
Hi,
First of all thanks for the free compiler which does everything in ASN.
1
I guess my doubt is of basic type (might be missing something)
I have a asn.1 file with relational constraints used in it. (I saw
that in many examples in the \test dir, these are used, so I assume
that these are supported by the compiler)
During compiling following errors are coming:
"Error Found token LBrace, Expected Token U_Identifier"

All the errors are of this type.
Waiting for the clarification

regards,
Amey

Paul Hoffman

unread,
Jul 17, 2008, 10:03:26 AM7/17/08
to a2c-d...@googlegroups.com
Could you send a copy of the module you are having problems with?
Without that, we can't determine what the problem is.

Jim Schaad

unread,
Jul 17, 2008, 1:34:30 PM7/17/08
to a2c-d...@googlegroups.com
Giving good feedback on errors was not one of the major goals of A2c, as
such it is currently often misleading about where an actual error occurs.
It will often unwind back to the last location where it was happy and say
that it has an error immediately following that.

Giving us the ASN.1 file (either entire or just the portion in question)
will allow us to determine exactly what is going on.

Jim

Amey

unread,
Jul 17, 2008, 11:01:34 PM7/17/08
to a2c-discuss
Hi,
I found out that the above said issues was coming since I had Two
component relational constraints method used in my asn file. something
like this

CmdEvtPDU {HCIPACKET:CmdEvtSet}::= SEQUENCE {
packetTy HCIPACKET.&packetType ({CmdEvtSet}),
listCmdsEvts SEQUENCE {
code HCIPACKET.&headerCode ({CmdEvtSet}{@packetTy}),
len HCIPACKET.&packetLength ({CmdEvtSet}{@packetTy, @.code}),
parameters HCIPACKET.&Params ({CmdEvtSet}{@packetTy, @.code})
}
}

I guess this is not currently supported in a2c.
Will you please tell me if this is supported? or when are you planning
to include this in a2c?

regards
Amey

Jim Schaad

unread,
Jul 18, 2008, 1:45:39 AM7/18/08
to a2c-d...@googlegroups.com
I have located the problem, I'm not sure when the tree will be ready for
another drop. I plan to do one before the start of October, but don't know
if I'll have a stable enough tree by then.

In the mean time, the following will fix the problem you are having:

Fred ::= SEQUENCE {


packetTy HCIPACKET.&packetType ({CmdEvtSet}),
listCmdsEvts SEQUENCE {
code HCIPACKET.&headerCode ({CmdEvtSet}{@packetTy}),

-- len HCIPACKET.&packetLength ({CmdEvtSet}{@packetTy,
@.code}),
-- parameters HCIPACKET.&Params ({CmdEvtSet}{@packetTy,
@.code})


len HCIPACKET.&packetLength ({CmdEvtSet}{@packetTy,

@listCmdsEvts.code}),


parameters HCIPACKET.&Params ({CmdEvtSet}{@packetTy,

@listCmdsEvts.code})
}
}

The problem with the parser was easy to fix, "@." Was not being recognized
as a token by the lexer. However the emitter does not correctly deal with
this structure at the present time. It does however deal with the full list
structure as above.

Amey

unread,
Jul 22, 2008, 12:46:43 AM7/22/08
to a2c-discuss
Thanks a lot Jim.
One last doubt (probably)
Does a2c supports ECN (encoding control notation) spec?

regards,
Amey
> > > > Amey- Hide quoted text -
>
> - Show quoted text -

Amey

unread,
Jul 22, 2008, 8:10:54 AM7/22/08
to a2c-discuss
Hi Jim,
I found couple of more things:

---> With the above code + more ASN.1 types I have created a hci-
mod.asn file. It got successfully compiled. However, if you see line
75 (HCIPACKET_descriptor) is defined and 85 and 86 where it is used,
the name of "HCIPACKET_descriptor" got changed to
"HCIPACKET_descripto". I guess is a potential error or am I missing
something?
I will upload the asn and .c file

---> Secondly the a2c is crashing if the above 2component relational
constraint is present along with SEQUENCE OF SEQUENCE type.


regards
Amey
> > - Show quoted text -- Hide quoted text -

Amey

unread,
Jul 22, 2008, 8:14:51 AM7/22/08
to a2c-discuss
HI Jim,
Since I am unable to load the files, pasting the content below

"hci-mod.asn"
HciMod

DEFINITIONS IMPLICIT TAGS ::=
BEGIN

HCIPACKET ::= CLASS {
&packetType OCTET STRING (SIZE(2)),
&headerCode OCTET STRING UNIQUE,
&packetLength OCTET STRING OPTIONAL,
&Params OPTIONAL
} WITH SYNTAX {
PACKET TYPE &packetType
CODE &headerCode
[PACKET LENGTH &packetLength]
[PARAMETERS &Params]
}

onecmd HCIPACKET ::= {
PACKET TYPE '01'H
CODE '0101'H
PACKET LENGTH '04'H
PARAMETERS SEQUENCE {a INTEGER, b INTEGER}
}

twocmd HCIPACKET ::= {
PACKET TYPE '01'H
CODE '0102'H
PACKET LENGTH '02'H
PARAMETERS SEQUENCE {c INTEGER, d INTEGER}
}

oneevt HCIPACKET ::= {
PACKET TYPE '02'H
CODE '01'H
}

CmdEvtSet HCIPACKET ::= {
onecmd | twocmd | oneevt
}

CmdEvtPDU ::= SEQUENCE {
packetTy HCIPACKET.&packetType ({CmdEvtSet}),
listCmdsEvts SEQUENCE {
code HCIPACKET.&headerCode ({CmdEvtSet}{@packetTy}),
len HCIPACKET.&packetLength ({CmdEvtSet}{@packetTy,
@listCmdsEvts.code}),
parameters HCIPACKET.&Params ({CmdEvtSet}{@packetTy,
@listCmdsEvts.code})
}

}

END



-------------

"hci-mod.c"


#include "hci-mod.h"


A2C_COMPONENT_RELATIONS_TABLE
CmdEvtPDU__listCmdsEvts_code_Relationship_table[] = {
{"&packetType", 0, OFFSET_OF(CmdEvtPDU, packetTy)}
};
A2C_COMPONENT_RELATIONS CmdEvtPDU__listCmdsEvts_code_Relationship = {
&CmdEvtSet, "&headerCode", 1,
CmdEvtPDU__listCmdsEvts_code_Relationship_table
};

A2C_ERROR CmdEvtPDU__listCmdsEvts_code_decode_der(A2C_OPEN_TYPE * pos,
PC_A2C_DESCRIPTOR pdesc, int flags, A2C_CONTEXT * pcxt,
A2C_TAG const * ptag, A2C_STREAM_MEMORY * pstm)
{
return
A2C_RELATION_decode_der(&CmdEvtPDU__listCmdsEvts_code_Relationship,
pos, pdesc, flags, pcxt, ptag, pstm);
}

A2C_ERROR CmdEvtPDU__listCmdsEvts_code_decode_ber(A2C_OPEN_TYPE * pos,
PC_A2C_DESCRIPTOR pdesc, int flags, A2C_CONTEXT * pcxt,
A2C_TAG const * ptag, A2C_STREAM_MEMORY * pstm)
{
return
A2C_RELATION_decode_ber(&CmdEvtPDU__listCmdsEvts_code_Relationship,
pos, pdesc, flags, pcxt, ptag, pstm);
}

A2C_COMPONENT_RELATIONS_TABLE
CmdEvtPDU__listCmdsEvts_len_Relationship_table[] = {
{"&headerCode", 0, OFFSET_OF(CmdEvtPDU, listCmdsEvts.code)}
{"&packetType", 0, OFFSET_OF(CmdEvtPDU, packetTy)}
};
A2C_COMPONENT_RELATIONS CmdEvtPDU__listCmdsEvts_len_Relationship = {
&CmdEvtSet, "&packetLength", 2,
CmdEvtPDU__listCmdsEvts_len_Relationship_table
};

A2C_ERROR CmdEvtPDU__listCmdsEvts_len_decode_der(A2C_OPEN_TYPE * pos,
PC_A2C_DESCRIPTOR pdesc, int flags, A2C_CONTEXT * pcxt,
A2C_TAG const * ptag, A2C_STREAM_MEMORY * pstm)
{
return
A2C_RELATION_decode_der(&CmdEvtPDU__listCmdsEvts_len_Relationship,
pos, pdesc, flags, pcxt, ptag, pstm);
}

A2C_ERROR CmdEvtPDU__listCmdsEvts_len_decode_ber(A2C_OPEN_TYPE * pos,
PC_A2C_DESCRIPTOR pdesc, int flags, A2C_CONTEXT * pcxt,
A2C_TAG const * ptag, A2C_STREAM_MEMORY * pstm)
{
return
A2C_RELATION_decode_ber(&CmdEvtPDU__listCmdsEvts_len_Relationship,
pos, pdesc, flags, pcxt, ptag, pstm);
}

A2C_COMPONENT_RELATIONS_TABLE
CmdEvtPDU__listCmdsEvts_parameters_Relationship_table[] = {
{"&headerCode", 0, OFFSET_OF(CmdEvtPDU, listCmdsEvts.code)}
{"&packetType", 0, OFFSET_OF(CmdEvtPDU, packetTy)}
};
A2C_COMPONENT_RELATIONS
CmdEvtPDU__listCmdsEvts_parameters_Relationship = {
&CmdEvtSet, "&Params", 2,
CmdEvtPDU__listCmdsEvts_parameters_Relationship_table
};

A2C_ERROR CmdEvtPDU__listCmdsEvts_parameters_decode_der(A2C_OPEN_TYPE
* pos, PC_A2C_DESCRIPTOR pdesc, int flags, A2C_CONTEXT * pcxt,
A2C_TAG const * ptag, A2C_STREAM_MEMORY * pstm)
{
return
A2C_RELATION_decode_der(&CmdEvtPDU__listCmdsEvts_parameters_Relationship,
pos, pdesc, flags, pcxt, ptag, pstm);
}

A2C_ERROR CmdEvtPDU__listCmdsEvts_parameters_decode_ber(A2C_OPEN_TYPE
* pos, PC_A2C_DESCRIPTOR pdesc, int flags, A2C_CONTEXT * pcxt,
A2C_TAG const * ptag, A2C_STREAM_MEMORY * pstm)
{
return
A2C_RELATION_decode_ber(&CmdEvtPDU__listCmdsEvts_parameters_Relationship,
pos, pdesc, flags, pcxt, ptag, pstm);
}

const A2C_ITEM HCIPACKET_description_table[] = {
{"&packetType", OFFSET_OF(HCIPACKET, packetType),
{A2C_TAG_CLASS_UNIVERSAL, 4}, &A2C_OCTET_STRING_descriptor, 0,
A2C_FLAGS_TAG_IMPLICIT, 0},
{"&headerCode", OFFSET_OF(HCIPACKET, headerCode),
{A2C_TAG_CLASS_UNIVERSAL, 4}, &A2C_OCTET_STRING_descriptor, 0,
A2C_FLAGS_TAG_IMPLICIT | A2C_FLAGS_UNIQUE, 0},
{"&packetLength", OFFSET_OF(HCIPACKET, packetLength),
{A2C_TAG_CLASS_UNIVERSAL, 4}, &A2C_OCTET_STRING_descriptor, 0,
A2C_FLAGS_TAG_IMPLICIT | A2C_FLAGS_OPTIONAL, 0},
{"&Params", OFFSET_OF(HCIPACKET, Params),
{A2C_TAG_CLASS_UNIVERSAL, 0}, &A2C_OPEN_TYPE_descriptor, 0,
A2C_FLAGS_OPTIONAL, 0},

};

const A2C_ITEM_HEADER HCIPACKET_description = {
sizeof(HCIPACKET), 0, countof(HCIPACKET_description_table),
HCIPACKET_description_table
};

const A2C_DESCRIPTOR HCIPACKET_descriptor = {
A2C_zero, A2C_nop,
(A2C_decoder_f) A2C_CLASS_decode_der, (A2C_encoder_f)
A2C_CLASS_encode_der,
(A2C_decoder_f) A2C_CLASS_decode_ber, (A2C_encoder_f)
A2C_CLASS_encode_ber,
(A2C_compare_f) A2C_CLASS_compare,
(A2C_copy_f) A2C_CLASS_copy,
(A2C_print_f) A2C_CLASS_print,
A2C_CLASS_validate,
&HCIPACKET_description
};
const HCIPACKET onecmd = { &onecmd__packetType, &onecmd__headerCode,
&onecmd__packetLength, &HCIPACKET_descripto };
const HCIPACKET twocmd = { &twocmd__packetType, &twocmd__headerCode,
&twocmd__packetLength, &HCIPACKET_descripto };
const HCIPACKET oneevt = { &oneevt__packetType, &oneevt__headerCode,
NULL, NULL };

const PCVOID CmdEvtSet_table[] = {
&onecmd, &twocmd, &oneevt,
};
const A2C_OBJECT_SET CmdEvtSet = {
3, &HCIPACKET_description,
CmdEvtSet_table
};

const A2C_DESCRIPTOR CmdEvtPDU__listCmdsEvts_code_descriptor = {
A2C_zero, A2C_OCTET_STRING_release,
(A2C_decoder_f) CmdEvtPDU__listCmdsEvts_code_decode_der,
(A2C_encoder_f) A2C_OCTET_STRING_encode_der,
(A2C_decoder_f) CmdEvtPDU__listCmdsEvts_code_decode_ber,
(A2C_encoder_f) A2C_OCTET_STRING_encode_ber,
(A2C_compare_f) A2C_OCTET_STRING_compare,
(A2C_copy_f) A2C_OCTET_STRING_copy,
(A2C_print_f) A2C_OCTET_STRING_print,
A2C_OCTET_STRING_validate,
&A2C_OCTET_STRING_description
};

const A2C_DESCRIPTOR CmdEvtPDU__listCmdsEvts_len_descriptor = {
A2C_zero, A2C_OCTET_STRING_release,
(A2C_decoder_f) CmdEvtPDU__listCmdsEvts_len_decode_der,
(A2C_encoder_f) A2C_OCTET_STRING_encode_der,
(A2C_decoder_f) CmdEvtPDU__listCmdsEvts_len_decode_ber,
(A2C_encoder_f) A2C_OCTET_STRING_encode_ber,
(A2C_compare_f) A2C_OCTET_STRING_compare,
(A2C_copy_f) A2C_OCTET_STRING_copy,
(A2C_print_f) A2C_OCTET_STRING_print,
A2C_OCTET_STRING_validate,
&A2C_OCTET_STRING_description
};

const A2C_DESCRIPTOR CmdEvtPDU__listCmdsEvts_parameters_descriptor = {
A2C_zero, A2C_OPEN_TYPE_release,
(A2C_decoder_f) CmdEvtPDU__listCmdsEvts_parameters_decode_der,
(A2C_encoder_f) A2C_OPEN_TYPE_encode_der,
(A2C_decoder_f) CmdEvtPDU__listCmdsEvts_parameters_decode_ber,
(A2C_encoder_f) A2C_OPEN_TYPE_encode_ber,
(A2C_compare_f) A2C_OPEN_TYPE_compare,
(A2C_copy_f) A2C_OPEN_TYPE_copy,
(A2C_print_f) A2C_OPEN_TYPE_print,
A2C_OPEN_TYPE_validate,
&A2C_OPEN_TYPE_description
};

const A2C_ITEM CmdEvtPDU__listCmdsEvts_description_table[] = {
{"code", REL_OFFSET_OF(CmdEvtPDU, listCmdsEvts.code,
listCmdsEvts), {A2C_TAG_CLASS_UNIVERSAL, 0},
&CmdEvtPDU__listCmdsEvts_code_descriptor, 0, 0, 0},
{"len", REL_OFFSET_OF(CmdEvtPDU, listCmdsEvts.len, listCmdsEvts),
{A2C_TAG_CLASS_UNIVERSAL, 0}, &CmdEvtPDU__listCmdsEvts_len_descriptor,
0, 0, 0},
{"parameters", REL_OFFSET_OF(CmdEvtPDU, listCmdsEvts.parameters,
listCmdsEvts), {A2C_TAG_CLASS_UNIVERSAL, 0},
&CmdEvtPDU__listCmdsEvts_parameters_descriptor, 0, 0, 0},
};

const A2C_ITEM_HEADER CmdEvtPDU__listCmdsEvts_description = {
0, 0, countof(CmdEvtPDU__listCmdsEvts_description_table),
CmdEvtPDU__listCmdsEvts_description_table
};

const A2C_DESCRIPTOR CmdEvtPDU__listCmdsEvts_descriptor = {
A2C_SEQUENCE_init, A2C_SEQUENCE_release,
(A2C_decoder_f) A2C_SEQUENCE_decode_der, (A2C_encoder_f)
A2C_SEQUENCE_encode_der,
(A2C_decoder_f) A2C_SEQUENCE_decode_ber, (A2C_encoder_f)
A2C_SEQUENCE_encode_ber,
(A2C_compare_f) A2C_SEQUENCE_compare,
(A2C_copy_f) A2C_SEQUENCE_copy,
(A2C_print_f) A2C_SEQUENCE_print,
A2C_SEQUENCE_validate,
&CmdEvtPDU__listCmdsEvts_description
};

const A2C_ITEM CmdEvtPDU_description_table[] = {
{"packetTy", OFFSET_OF(CmdEvtPDU, packetTy),
{A2C_TAG_CLASS_UNIVERSAL, 0}, &A2C_OCTET_STRING_descriptor, 0, 0, 0},
{"listCmdsEvts", OFFSET_OF(CmdEvtPDU, listCmdsEvts),
{A2C_TAG_CLASS_UNIVERSAL, 16}, &CmdEvtPDU__listCmdsEvts_descriptor, 0,
A2C_FLAGS_TAG_IMPLICIT, 0},
};

const A2C_ITEM_HEADER CmdEvtPDU_description = {
sizeof(CmdEvtPDU), 0, countof(CmdEvtPDU_description_table),
CmdEvtPDU_description_table
};

const A2C_DESCRIPTOR CmdEvtPDU_descriptor = {
A2C_SEQUENCE_init, A2C_SEQUENCE_release,
(A2C_decoder_f) A2C_SEQUENCE_decode_der, (A2C_encoder_f)
A2C_SEQUENCE_encode_der,
(A2C_decoder_f) A2C_SEQUENCE_decode_ber, (A2C_encoder_f)
A2C_SEQUENCE_encode_ber,
(A2C_compare_f) A2C_SEQUENCE_compare,
(A2C_copy_f) A2C_SEQUENCE_copy,
(A2C_print_f) A2C_SEQUENCE_print,
A2C_SEQUENCE_validate,
&CmdEvtPDU_description
};
static const BYTE onecmd__packetType___array[] = {0x1};
const A2C_OCTET_STRING onecmd__packetType={ 1, (PBYTE)
onecmd__packetType___array};

static const BYTE onecmd__headerCode___array[] = {0x1, 0x1};
const A2C_OCTET_STRING onecmd__headerCode={ 2, (PBYTE)
onecmd__headerCode___array};

static const BYTE onecmd__packetLength___array[] = {0x4};
const A2C_OCTET_STRING onecmd__packetLength={ 1, (PBYTE)
onecmd__packetLength___array};

static const BYTE twocmd__packetType___array[] = {0x1};
const A2C_OCTET_STRING twocmd__packetType={ 1, (PBYTE)
twocmd__packetType___array};

static const BYTE twocmd__headerCode___array[] = {0x1, 0x2};
const A2C_OCTET_STRING twocmd__headerCode={ 2, (PBYTE)
twocmd__headerCode___array};

static const BYTE twocmd__packetLength___array[] = {0x2};
const A2C_OCTET_STRING twocmd__packetLength={ 1, (PBYTE)
twocmd__packetLength___array};

static const BYTE oneevt__packetType___array[] = {0x2};
const A2C_OCTET_STRING oneevt__packetType={ 1, (PBYTE)
oneevt__packetType___array};

static const BYTE oneevt__headerCode___array[] = {0x1};
const A2C_OCTET_STRING oneevt__headerCode={ 1, (PBYTE)
oneevt__headerCode___array};

-------------------
regards,
Amey

Jim Schaad

unread,
Jul 22, 2008, 2:16:20 PM7/22/08
to a2c-d...@googlegroups.com
By this do you mean if you add something along the lines of

Fred ::= SEQUENCE OF SEQUENCE OF CmdEvtPDU?


To fix the other problem:

If you have source -

In the file AsnFile.cs, In the function RewriteObject,

There is switch statement with the following

switch statement with the following cases

case BaseType.Choice:
case BaseType.Set:
case BaseType.SequenceOf:
case BaseType.Param_Assignment:
case BaseType.Constraint:


Add to the set
case BaseType.SetOf:
case BaseType.Sequence:

This will fix the emitter problem you are having. I have tagged this to go
into the next build.

Jim Schaad

unread,
Jul 22, 2008, 2:23:30 PM7/22/08
to a2c-d...@googlegroups.com
No we do not support the ECN spec. The only set of encoding rules that are
currently supported are those for BER and DER. We do not do CER, XER or PER
either.

If you would like to work on adding generic encoding rules, this is actually
a relatively easy task, however you probably would rather just write
encoders for those specific things that are specially encoded and override
the automatically generated encoders.

See section 4.4 in the readme file.

Amey

unread,
Jul 22, 2008, 11:24:11 PM7/22/08
to a2c-discuss
Hi Jim,
----> I have source and hence I changed the Asnfile.cs as per your
comments. However, the emitter problem still exists.
The relevant part from the .c file is pasted below. The letter "r" is
getting omitted in the "HCIPACKET_descriptor" when it is called from
declaration of const HCIPACKET onecmd. Or do I have to re-compile the
a2c source after doing the Asnfile.cs change?
------------------------
const A2C_DESCRIPTOR HCIPACKET_descriptor = {
A2C_zero, A2C_nop,
(A2C_decoder_f) A2C_CLASS_decode_der, (A2C_encoder_f)
A2C_CLASS_encode_der,
(A2C_decoder_f) A2C_CLASS_decode_ber, (A2C_encoder_f)
A2C_CLASS_encode_ber,
(A2C_compare_f) A2C_CLASS_compare,
(A2C_copy_f) A2C_CLASS_copy,
(A2C_print_f) A2C_CLASS_print,
A2C_CLASS_validate,
&HCIPACKET_description
};

const HCIPACKET onecmd = { &onecmd__packetType, &onecmd__headerCode,
&onecmd__packetLength, &HCIPACKET_descripto };
const HCIPACKET twocmd = { &twocmd__packetType, &twocmd__headerCode,
&twocmd__packetLength, &HCIPACKET_descripto };
const HCIPACKET oneevt = { &oneevt__packetType, &oneevt__headerCode,
NULL, NULL };

-------------------------------

------> The second problem for SEQUENCE OF SEQUENCE is as follows.
The compiler crashes when the following is tried to compile

CmdEvtPDU ::= SEQUENCE {
packetTy HCIPACKET.&packetType ({CmdEvtSet}),
listCmdsEvts SEQUENCE OF SEQUENCE {
code HCIPACKET.&headerCode ({CmdEvtSet}{@packetTy}),
len HCIPACKET.&packetLength ({CmdEvtSet}{@packetTy,
@listCmdsEvts.code}),
parameters HCIPACKET.&Params ({CmdEvtSet}{@packetTy,
@listCmdsEvts.code})
}


Thanks for your support.

regards,
Amey

Amey

unread,
Jul 22, 2008, 11:35:47 PM7/22/08
to a2c-discuss
Hi Jim,
---> The emitter problem:
I re-compiled the code and the problem is resolved. Thanks again.

regards,
Amey
Reply all
Reply to author
Forward
0 new messages