I am using the c code generated by asn1c from the TCAP protocol specification (i.e., the corresponding ASN1 files). I can successfully encode TCAP packets by the generated code. However, trying to "decode" related byte streams fails.
A sample code is as follows.
// A real byte stream of a TCAP message:
unsigned char packet_bytes[] = {
0x62, 0x43, 0x48, 0x04, 0x00, 0x18, 0x02, 0x78,
0x6b, 0x1a, 0x28, 0x18, 0x06, 0x07, 0x00, 0x11,
0x86, 0x05, 0x01, 0x01, 0x01, 0xa0, 0x0d, 0x60,
0x0b, 0xa1, 0x09, 0x06, 0x07, 0x04, 0x00, 0x00,
0x01, 0x00, 0x14, 0x03, 0x6c, 0x1f, 0xa1, 0x1d,
0x02, 0x01, 0x00, 0x02, 0x01, 0x2d, 0x30, 0x15,
0x80, 0x07, 0x91, 0x64, 0x21, 0x92, 0x05, 0x31,
0x74, 0x81, 0x01, 0x01, 0x82, 0x07, 0x91, 0x64,
0x21, 0x00, 0x00, 0x90, 0x02
};
// Initializing ...
TCAP_TCMessage_t _pdu, *pdu = &_pdu;
memset(pdu, 0, sizeof(*pdu));
// Decoding:
asn_dec_rval_t dec_ret = ber_decode(NULL, &asn_DEF_TCAP_TCMessage, (void **) &pdu, packet_bytes, sizeof(packet_bytes));
While the message type ("Begin", in this case), is correctly detected, but other paramters are not parsed.
Using other encoding rules, i.e., aper_decode() and uper_decode(), also fails.
I would be thankful if anyone can describe how to use the auto-generated c code for decoding (parsing) a byte string of TCAP messages.
@Vasil, thank you very much for your answer.
I use the mouse07410's branch.
From the field
presentof thepduvariable that is evaluated by ber_decode (you can see thepdutype in the sample code). From the "Wireshark" output for this byte stream, I know that the correct type of the message isBegin.Thanks for providing the hint; it was helpful.
The problem was related to the asn1 files I was using. I used osmocom asn1 files and compiled them by
in which,
DialoguePortionis defined as follows (note that the first definition is commented):To be able to decode TCAP messages, one needs to use the former definition (as is in the standard), i.e.,
DialoguePortionshould be defined asWhen using this latter definition in the asn1 file, and recompiling the asn1 files, the problem solved.
P.S.: This question is also related to my problem.