I've managed to compile the tcap ASN.1 specs and it's working perfectly expect for the ReturnError part,
I'm trying to decode the ComponentPortion and as I mentioned I got it working with Invoke, Return result with no issues, the only problem I'm having now it the ReturnError, this is the hex of the ReturnError component portion
/* Read up to the buffer size */
size = fread(buf, 1, sizeof(buf), fp);
fclose(fp);
if(!size) {
fprintf(stderr, "%s: Empty or broken\n", filename);
exit(65); /* better, EX_DATAERR */
}
// char buff = {0x6c,0x1f,0xa1,0x1d,0x02,0x01,0x01,0x02,0x01,0x2f,0x30,0x15,0x04,0x07,0x91,0x41,0x52,0x42,0x31,0x40,0xf1,0x04,0x07,0x91,0x41,0x40,0x54,0x05,0x00,0xf9,0x0a,0x01,0x00};
//char buff = {0x6c,0x19,0xa1,0x17,0x02,0x01,0x01,0x02,0x01,0x20,0x30,0x0f,0x0a,0x01,0x05,0x04,0x0a,0x01,0xc3,0x00,0x31,0x20,0x60,0x70,0x53,0x03,0x2b};
char buff = {0x6c,0x0d,0xa3,0x0b,0x02,0x01,0x01,0x02,0x01,0x20,0x30,0x03,0x0a,0x01,0x05};
//unsigned char buff = {0x6c,0x0d,0xa1,0x0b,0x02,0x01,0x01,0x02,0x01,0x20};//,0x30,0x03,0x0a,0x01,0x05};
/* Decode the input buffer as ComponentPortion type */
rval = ber_decode(0, &asn_DEF_ComponentPortion,
(void **)&ComponentPortion, buff, size);
if(rval.code != RC_OK) {
fprintf(stderr,
"%s: Broken ComponentPortion encoding at byte %ld\n",
filename, (long)rval.consumed);
exit(65); /* better, EX_DATAERR */
}
// printf("test = %x\n",(((ComponentPortion->choice.begin.components)->list.array)->choice.invoke.parameter)->buf);
/* Print the decoded ComponentPortion type as XML */
xer_fprint(stdout, &asn_DEF_ComponentPortion, ComponentPortion);
return 0; /* Decoding finished successfully */
}
and the output I've got is this,
Decoding ComponentPortion as SET OF (constr_SET_OF.c:88)
ber_check_tags(ComponentPortion, size=1024, tm=0, step=0, tagno=0) (ber_decoder.c:112)
Fetching tag from {0x7fff4b8a6ac0,1024}: len 1, step 0, tagno 0 got (ber_decoder.c:149)
Fetchinig len = 1 (ber_decoder.c:209)
Structure consumes 13 bytes, buffer 1022 (constr_SET_OF.c:129)
Decoding Component as CHOICE (constr_CHOICE.c:121)
Structure consumes -1 bytes, buffer 13 (constr_CHOICE.c:170)
In Component CHOICE tag length 1 (constr_CHOICE.c:178)
Decoding ReturnError as SEQUENCE (constr_SEQUENCE.c:132)
ber_check_tags(ReturnError, size=13, tm=-1, step=0, tagno=0) (ber_decoder.c:112)
Fetching tag from {0x7fff4b8a6ac2,13}: len 1, step 0, tagno 0 got (ber_decoder.c:149)
Fetchinig len = 1 (ber_decoder.c:209)
Structure consumes 11 bytes, buffer 11 (constr_SEQUENCE.c:175)
In ReturnError SEQUENCE left 11, edx=0 flags=0 opt=0 ec=3 (constr_SEQUENCE.c:208)
Current tag in ReturnError SEQUENCE for element 0 (invokeID) is encoded in 1 bytes, of frame 11 (constr_SEQUENCE.c:236)
Inside SEQUENCE ReturnError MF2 (constr_SEQUENCE.c:391)
Decoding InvokeIdType as INTEGER (tm=0) (NativeInteger.c:69)
ber_check_tags(InvokeIdType, size=11, tm=0, step=0, tagno=0) (ber_decoder.c:112)
Fetching tag from {0x7fff4b8a6ac4,11}: len 1, step 0, tagno 0 got (ber_decoder.c:149)
Fetchinig len = 1 (ber_decoder.c:209)
InvokeIdType length is 1 bytes (NativeInteger.c:79)
Took 3/1 bytes to encode InvokeIdType (1) (NativeInteger.c:124)
In ReturnError SEQUENCE decoded 0 InvokeIdType of 11 in 3 bytes rval.code 0, size=11 (constr_SEQUENCE.c:419)
In ReturnError SEQUENCE left 8, edx=1 flags=0 opt=0 ec=3 (constr_SEQUENCE.c:208)
Current tag in ReturnError SEQUENCE for element 1 (errorCode) is encoded in 1 bytes, of frame 8 (constr_SEQUENCE.c:236)
Unexpected tag (at 1) (constr_SEQUENCE.c:353)
Expected tag (errorCode) (constr_SEQUENCE.c:358)
In ComponentPortion SET OF Component code 2 consumed 0 (constr_SET_OF.c:212)
Freeing Component as CHOICE (constr_CHOICE.c:1038)
Freeing ReturnError as SEQUENCE (constr_SEQUENCE.c:958)
Freeing InvokeIdType as INTEGER (1, 0x1699058, Native) (NativeInteger.c:326)
Freeing ErrorCode as CHOICE (constr_CHOICE.c:1038)
tcap-enc.c: Broken ComponentPortion encoding at byte 2
When I change the bold text below, 0xa3 which is the ReturnError tag, to 0xa1 it will work. of course this is not correct, it's only for testing the A3 is failing for some reason
I'm not sure what I've done wrong here, And I'm trying to debug the program but wasn't able to find anything useful for days now. Can you please help me trace this problem?
Appreciate your help,
Ammar
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I've managed to compile the tcap ASN.1 specs and it's working perfectly expect for the ReturnError part,
I'm trying to decode the ComponentPortion and as I mentioned I got it working with Invoke, Return result with no issues, the only problem I'm having now it the ReturnError, this is the hex of the ReturnError component portion
0x6c,0x0d,0xa3,0x0b,0x02,0x01,0x01,0x02,0x01,0x20,0x30,0x03,0x0a,0x01,0x05
and I'm using this example
int main(int ac, char **av) {
char buf; /* Temporary buffer */
ComponentPortion_t *ComponentPortion = 0; /* Type to decode */
asn_dec_rval_t rval; /* Decoder return value */
FILE *fp; /* Input file handler */
size_t size; /* Number of bytes read */
char *filename; /* Input file name */
/* Require a single filename argument */
if(ac != 2) {
fprintf(stderr, "Usage: %s <file.ber>\n", av);
exit(64); /* better, EX_USAGE */
} else {
filename = av;
}
/* Open input file as read-only binary */
fp = fopen(filename, "rb");
if(!fp) {
perror(filename);
exit(66); /* better, EX_NOINPUT */
}
/* Read up to the buffer size */
size = fread(buf, 1, sizeof(buf), fp);
fclose(fp);
if(!size) {
fprintf(stderr, "%s: Empty or broken\n", filename);
exit(65); /* better, EX_DATAERR */
}
// char buff = {0x6c,0x1f,0xa1,0x1d,0x02,0x01,0x01,0x02,0x01,0x2f,0x30,0x15,0x04,0x07,0x91,0x41,0x52,0x42,0x31,0x40,0xf1,0x04,0x07,0x91,0x41,0x40,0x54,0x05,0x00,0xf9,0x0a,0x01,0x00};
//char buff = {0x6c,0x19,0xa1,0x17,0x02,0x01,0x01,0x02,0x01,0x20,0x30,0x0f,0x0a,0x01,0x05,0x04,0x0a,0x01,0xc3,0x00,0x31,0x20,0x60,0x70,0x53,0x03,0x2b};
char buff = {0x6c,0x0d,0xa3,0x0b,0x02,0x01,0x01,0x02,0x01,0x20,0x30,0x03,0x0a,0x01,0x05};
//unsigned char buff = {0x6c,0x0d,0xa1,0x0b,0x02,0x01,0x01,0x02,0x01,0x20};//,0x30,0x03,0x0a,0x01,0x05};
/* Decode the input buffer as ComponentPortion type */
rval = ber_decode(0, &asn_DEF_ComponentPortion,
(void **)&ComponentPortion, buff, size);
if(rval.code != RC_OK) {
fprintf(stderr,
"%s: Broken ComponentPortion encoding at byte %ld\n",
filename, (long)rval.consumed);
exit(65); /* better, EX_DATAERR */
}
// printf("test = %x\n",(((ComponentPortion->choice.begin.components)->list.array)->choice.invoke.parameter)->buf);
/* Print the decoded ComponentPortion type as XML */
xer_fprint(stdout, &asn_DEF_ComponentPortion, ComponentPortion);
return 0; /* Decoding finished successfully */
}
and the output I've got is this,
Decoding ComponentPortion as SET OF (constr_SET_OF.c:88)
ber_check_tags(ComponentPortion, size=1024, tm=0, step=0, tagno=0) (ber_decoder.c:112)
Fetching tag from {0x7fff4b8a6ac0,1024}: len 1, step 0, tagno 0 got (ber_decoder.c:149)
Fetchinig len = 1 (ber_decoder.c:209)
Structure consumes 13 bytes, buffer 1022 (constr_SET_OF.c:129)
Decoding Component as CHOICE (constr_CHOICE.c:121)
Structure consumes -1 bytes, buffer 13 (constr_CHOICE.c:170)
In Component CHOICE tag length 1 (constr_CHOICE.c:178)
Decoding ReturnError as SEQUENCE (constr_SEQUENCE.c:132)
ber_check_tags(ReturnError, size=13, tm=-1, step=0, tagno=0) (ber_decoder.c:112)
Fetching tag from {0x7fff4b8a6ac2,13}: len 1, step 0, tagno 0 got (ber_decoder.c:149)
Fetchinig len = 1 (ber_decoder.c:209)
Structure consumes 11 bytes, buffer 11 (constr_SEQUENCE.c:175)
In ReturnError SEQUENCE left 11, edx=0 flags=0 opt=0 ec=3 (constr_SEQUENCE.c:208)
Current tag in ReturnError SEQUENCE for element 0 (invokeID) is encoded in 1 bytes, of frame 11 (constr_SEQUENCE.c:236)
Inside SEQUENCE ReturnError MF2 (constr_SEQUENCE.c:391)
Decoding InvokeIdType as INTEGER (tm=0) (NativeInteger.c:69)
ber_check_tags(InvokeIdType, size=11, tm=0, step=0, tagno=0) (ber_decoder.c:112)
Fetching tag from {0x7fff4b8a6ac4,11}: len 1, step 0, tagno 0 got (ber_decoder.c:149)
Fetchinig len = 1 (ber_decoder.c:209)
InvokeIdType length is 1 bytes (NativeInteger.c:79)
Took 3/1 bytes to encode InvokeIdType (1) (NativeInteger.c:124)
In ReturnError SEQUENCE decoded 0 InvokeIdType of 11 in 3 bytes rval.code 0, size=11 (constr_SEQUENCE.c:419)
In ReturnError SEQUENCE left 8, edx=1 flags=0 opt=0 ec=3 (constr_SEQUENCE.c:208)
Current tag in ReturnError SEQUENCE for element 1 (errorCode) is encoded in 1 bytes, of frame 8 (constr_SEQUENCE.c:236)
Unexpected tag (at 1) (constr_SEQUENCE.c:353)
Expected tag (errorCode) (constr_SEQUENCE.c:358)
In ComponentPortion SET OF Component code 2 consumed 0 (constr_SET_OF.c:212)
Freeing Component as CHOICE (constr_CHOICE.c:1038)
Freeing ReturnError as SEQUENCE (constr_SEQUENCE.c:958)
Freeing InvokeIdType as INTEGER (1, 0x1699058, Native) (NativeInteger.c:326)
Freeing ErrorCode as CHOICE (constr_CHOICE.c:1038)
tcap-enc.c: Broken ComponentPortion encoding at byte 2
When I change the bold text below, 0xa3 which is the ReturnError tag, to 0xa1 it will work. of course this is not correct, it's only for testing the A3 is failing for some reason
0x6c,0x0d,0xa3,0x0b,0x02,0x01,0x01,0x02,0x01,0x20,0x30,0x03,0x0a,0x01,0x05
I'm not sure what I've done wrong here, And I'm trying to debug the program but wasn't able to find anything useful for days now. Can you please help me trace this problem?
Appreciate your help,
Ammar