A2C crashing with the asn.1 code

3 views
Skip to first unread message

Amey

unread,
Aug 4, 2008, 1:22:33 AM8/4/08
to a2c-discuss
Hi,
[1] ----With following asn.1 code a2c compiler is crashing. Please
check and let me know the solution if possible.

******************************
HciMod2

DEFINITIONS AUTOMATIC TAGS ::=
BEGIN

HCIPACKET ::= CLASS {
&packetType OCTET STRING (SIZE(1)),
&headerCode OCTET STRING UNIQUE,
&params SEQUENCE OF OCTET STRING
}
WITH SYNTAX {
PACKET TYPE &packetType
CODE &headerCode
PARAMETERS &params
}

resetCmd HCIPACKET ::= {
PACKET TYPE '01'H
CODE '0C03'H
PARAMETERS {'00'H}

}

readLocalVersionCmd HCIPACKET ::= {
PACKET TYPE '01'H
CODE '1001'H
PARAMETERS {'00'H}
}

CmdEvtSet HCIPACKET ::= {
resetCmd | readLocalVersionCmd
}

CmdEvtPDU ::= SEQUENCE OF SEQUENCE {
packetTy HCIPACKET.&packetType ({CmdEvtSet}),
code HCIPACKET.&headerCode ({CmdEvtSet}),
parameters HCIPACKET.&params ({CmdEvtSet})

}


END
***********************************************************

[2]----- I have one more problem to report. How relational component
tables are to be used with A2C generated functions. ASN.1 and
implementation (my .c) file are given below

ASN.1 file-------->>
HciMod1

DEFINITIONS AUTOMATIC TAGS ::=
BEGIN

HCIPACKET ::= CLASS {
&packetType OCTET STRING (SIZE(1)),
&headerCode OCTET STRING UNIQUE,
&length OCTET STRING
}
WITH SYNTAX {
PACKET TYPE &packetType
CODE &headerCode
LENGTH &length
}

resetCmd HCIPACKET ::= {
PACKET TYPE '01'H
CODE '0C03'H
LENGTH '00'H

}

readLocalVersionCmd HCIPACKET ::= {
PACKET TYPE '01'H
CODE '1001'H
LENGTH '00'H
}

CmdEvtSet HCIPACKET ::= {
resetCmd | readLocalVersionCmd
}

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

}


END
**************************
.c file -------->>>>>

#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "hci-mod1.h"

int main()
{
A2C_STREAM * encodeStream_ptr = 0;
CmdEvtPDU * reset_cmdptr;
CmdEvtPDU * reset_decodeptr = 0;

A2C_STREAM * printStream_ptr = 0;
A2C_ERROR err;
unsigned char * data_buff_ptr;
char * string_buff_ptr;
int buff_len;
int objectBuffLen;
int i;
FILE * outfile;
FILE * infile;
int bytes_written;
int bytes_read;

err = A2C_Alloc_CmdEvtPDU(&reset_cmdptr);
if (err < A2C_ERROR_Success) { printf ("err=%d at line 22\n",
err); exit(1);
} /* Allocation error */

err = A2C_AllocArray_CmdEvtPDU (reset_cmdptr, 10);
if (err < A2C_ERROR_Success) { printf ("err=%d at line 28\n",
err); exit(1); }

reset_cmdptr->count =1;
objectBuffLen = 1;
reset_cmdptr->array[0].packetTy.data = calloc(objectBuffLen, 1);
reset_cmdptr->array[0].packetTy.length = objectBuffLen;
reset_cmdptr->array[0].packetTy.data[0] = 0x01;
objectBuffLen = 2;
reset_cmdptr->array[0].code.data = calloc(objectBuffLen, 1);
reset_cmdptr->array[0].code.length = objectBuffLen;
reset_cmdptr->array[0].code.data[0] = 0x0b;
reset_cmdptr->array[0].code.data[1] = 0x03;
objectBuffLen = 1;
reset_cmdptr->array[0].len.data = calloc(objectBuffLen, 1);
reset_cmdptr->array[0].len.length = objectBuffLen;
reset_cmdptr->array[0].len.data[0] = 0x00;


/*encoding reset_cmdptr*/
err = A2C_CreateMemoryStream(&encodeStream_ptr);
if (err < A2C_ERROR_Success) { printf ("err=%d at line 41\n",
err); exit(1); } /* Allocation error */
err = A2C_EncodeBer_CmdEvtPDU(reset_cmdptr, 0, NULL,
encodeStream_ptr);
if (err < A2C_ERROR_Success) { printf ("err=%d after encoding
reset_cmdptr\n", err); exit(1); } /* Encoding error */
/* Get the data from the stream and print it as hex */
err = A2C_GetDataFromStream(encodeStream_ptr, &data_buff_ptr,
&buff_len);
if (err < A2C_ERROR_Success) { exit(1); } /* Getting error */
printf("The bytes (in hex) for reset_cmdptr were: ");
for (i=0; i<buff_len; i++) printf("%02x ", data_buff_ptr[i]);
printf("\n");

/*writing to a file*/
outfile = fopen ("E:/Amey/ASN.1/a2c-v7/ASN-HCI-ex/encoded.txt",
"w");
if (outfile == NULL)
{
printf ("encoded.c file not created\n");
exit(2);
}
else
{
bytes_written = fwrite(&data_buff_ptr, sizeof(char), buff_len,
outfile);
printf ("no. of bytes written in encoded.txt:%d
\n",bytes_written);
fclose(outfile);
infile = fopen ("E:/Amey/ASN.1/a2c-v7/ASN-HCI-ex/encoded.txt",
"r");
bytes_read = fread(&data_buff_ptr, sizeof(char), buff_len,
infile);
printf ("no. of bytes read from encoded.txt:%d\n",bytes_read);
fclose(infile);
}

/*decoding reset_cmdptr*/
err = A2C_DecodeBer_CmdEvtPDU(&reset_decodeptr, 0, NULL,
data_buff_ptr, buff_len);
if (err < A2C_ERROR_Success) { printf ("err=%d after decoding
reset_cmdptr\n", err); exit(1); } /* Decoding error */
err = A2C_CreateMemoryStream(&printStream_ptr);
// printf("The value of reset_cmdptr direct after decode is is:
%02x", reset_decodeptr->packetTy.data[0]);
// printf(":%02x", reset_decodeptr->code.data[0]);
// printf(":%02x", reset_decodeptr->code.data[1]);
// printf(":%02x", reset_decodeptr->len.data[0]);
printf("\n");
if (err < A2C_ERROR_Success) { printf ("err=%d at line 51\n",
err); exit(1); } /* Allocation error */
err = A2C_Print_CmdEvtPDU(reset_decodeptr, printStream_ptr);
if (err < A2C_ERROR_Success) { printf ("err=%d at line 53\n",
err); exit(1); } /* Filling error */
err = A2C_GetStringFromStream(printStream_ptr, &string_buff_ptr);
printf("The value of reset_cmdptr is:%s", string_buff_ptr);
printf("\n");


/* Free up what we allocated */
A2C_Free_CmdEvtPDU(reset_cmdptr);
A2C_FreeArray_CmdEvtPDU(reset_cmdptr);
A2C_Free_CmdEvtPDU(reset_decodeptr);

A2C_FreeStream(encodeStream_ptr);
A2C_FreeStream(printStream_ptr);
free(data_buff_ptr);
free(string_buff_ptr);
exit(0);

}
*******************
When I compile the above .c file and run the exe I get the following
result (after decoding)

{
packetTy
01
code
04 02 0B 03
len
04 01 00
}

Want to know how and from where the extra bytes 04 02 04 01 have come
in the result. There is some relation of this result with the relation
operator @ in asn file. Please let me know what it is.


regards
Amey

Amey

unread,
Aug 5, 2008, 4:17:09 AM8/5/08
to a2c-discuss
Hi Jim,
Can you please answers my above 2 doubts?

regards,
Amey

Paul Hoffman

unread,
Aug 5, 2008, 8:50:40 AM8/5/08
to a2c-d...@googlegroups.com
Jim is offline for a few weeks. I'm sure he will get to this when he gets back.

We are expecting to have a new version of a2c in early September with
bug fixes but no new features.

Amey

unread,
Aug 5, 2008, 11:15:12 PM8/5/08
to a2c-discuss
Thanks Paul for the information.
However, (speaking of bugs) I found a new bug in the a2c emitter code.
If in the asn file there 2 or more relational constraints like in the
above file the relationship table that gets generated (in form of
arrays in .c file) lacks "," between diff members. The bug has to be
fixed at line 2131 in C_emitter.cs file.

regards,
Amey

Jim Schaad

unread,
Aug 6, 2008, 5:46:08 AM8/6/08
to a2c-d...@googlegroups.com
Fix for [1]

In the file AsnFile.cs
In the function RewriteObject
Under case SymbolTypeValue

Change
symNew.value = symField.value;
symNew.type = symField.value.type;
to
symNew.value = symField.value;
symNew.type = symField.type;

Jim Schaad

unread,
Aug 6, 2008, 5:46:08 AM8/6/08
to a2c-d...@googlegroups.com
Amey,

I have verified that the first has a problem and crashes. I will look into
this further.

The second program appears to do the correct thing. When I run your code
and do the decode I get the following:

The bytes (in hex) for reset_cmdptr were:

30 80 - Seq of
30 80 - Seq of
04 01 01 - packetTy - Octet String(SIZE(1))
04 02 0b 03 - headerCode - Ocetet String UNIQUE
04 01 00 - length Octet String
00 00 - BER end
00 00 -BER end

The tag and length bytes (04 01 or 04 02) are from the fact that for the
class you have defined, the types of the fields in the class are octet
string. This is then copied forward when you use the field in the class as
the type of the field in the sequence.

If you think this is incorrect, then I will need more information about why
you think this is wrong.

Jim

> -----Original Message-----
> From: a2c-d...@googlegroups.com [mailto:a2c-
> dis...@googlegroups.com] On Behalf Of Amey
> Sent: Monday, August 04, 2008 3:23 PM
> To: a2c-discuss
> Subject: A2C crashing with the asn.1 code
>
>

Jim Schaad

unread,
Aug 6, 2008, 5:50:05 AM8/6/08
to a2c-d...@googlegroups.com
I had already found this one on the flight over.

Jim


> -----Original Message-----
> From: a2c-d...@googlegroups.com [mailto:a2c-
> dis...@googlegroups.com] On Behalf Of Amey

Amey

unread,
Aug 7, 2008, 12:00:33 AM8/7/08
to a2c-discuss
Hi Jim,
---The tag and length bytes are fine but this information is not
displayed (from the A2C_print function) if the @ operators are absent
in the SEQUENCE.
--- Also, my understanding of the @ operator is that if these are
present then the compiler after decode should check the packetTy and
code and depending on that give the corresponding object of the class
that matches this decoded output.

Let me know your thoughts about this.

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