ASN.1 decode errors

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

ASN.1 decode errors

Anthony Howe
I've written a couple ASN.1 BER and PER transcoders to JSON for LTE,
TAP3, NRTRDE files before.  ( It was Erlang's open source ASN.1 support
that got me to learn the language in the first place. )  I'm trying to
write one now for GPRS charging records (ETSI TS 101 393 V7.4.0
(2000-02)); I have something that builds, but does not decode the input
and just reports a vague Erlang ASN error.

I figure the problem revolves around a mismatched set of ASN module
files (which are a frik'n pain to find, but I digress).  Anyway, I
figure if I understood the error better it might point me finally in the
right direction.

So the error is...

$ ./_build/default/bin/gprsdump -r cdr_0f1
cdr_0f1: processing...
runtime error: cdr_0f1: {badmatch,
                         {error,
                          {asn1,
                           {invalid_choice_tag,
                            {1,
                             <<0,168,161,129,165,128,1,19,131,8,48,36,128,
                               1,113,0,0,63,164>>}}}}}

Reset of stack omitted.

My interpretation is that initial CallEventRecord choice 1
(GGSNPDPRecord) is not decoding, but I have no idea what the binary is
suppose to be telling me, other than "You Are Here in the BER input".

CallEventRecord ::= CHOICE
{
        sgsnPDPRecord [0] SGSNPDPRecord,
        ggsnPDPRecord [1] GGSNPDPRecord,
        sgsnMMRecord [2] SGSNMMRecord,
        sgsnSMORecord [3] SGSNSMORecord,
        sgsnSMTRecord [4] SGSNSMTRecord
}

Any clues to would be welcome.

Right now its looking like I'll have to learn how to decode BER by hand
in order to understand the failure better.  Maybe a generic BER to ASN
syntax decoder tool?


--
Anthony C Howe                                            SnertSoft
[hidden email]       Twitter: SirWumpus       BarricadeMX & Milters
http://snert.com/      http://nanozen.info/     http://snertsoft.com/
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: ASN.1 decode errors

Dániel Szoboszlay
Hi,

I'm not very familiar with ASN.1, but I believe the error comes from a different place than the CallEventRecord. {invalid_choice_tag, {1, _}} suggests that you're trying to decode a CHOICE and found tag 1 in the data, but there's no tag 1 in the definition. CallEventRecord has tag 1 (GGSNPDPRecord), so the error cannot come from this place (and if there were an error decoding the GGSNPDPRecord, the error message won't complain about the invalid choice tag).

Could you please include the top of the call stack? i think the name of the function where this error is coming from may hint to what kind of data fails to decode. Or, you can search the ASN.1 files for a CHOICE that has no tag 1.

Cheers,
Daniel

On Thu, 12 Sep 2019 at 16:37, Anthony Howe <[hidden email]> wrote:
I've written a couple ASN.1 BER and PER transcoders to JSON for LTE,
TAP3, NRTRDE files before.  ( It was Erlang's open source ASN.1 support
that got me to learn the language in the first place. )  I'm trying to
write one now for GPRS charging records (ETSI TS 101 393 V7.4.0
(2000-02)); I have something that builds, but does not decode the input
and just reports a vague Erlang ASN error.

I figure the problem revolves around a mismatched set of ASN module
files (which are a frik'n pain to find, but I digress).  Anyway, I
figure if I understood the error better it might point me finally in the
right direction.

So the error is...

$ ./_build/default/bin/gprsdump -r cdr_0f1
cdr_0f1: processing...
runtime error: cdr_0f1: {badmatch,
                         {error,
                          {asn1,
                           {invalid_choice_tag,
                            {1,
                             <<0,168,161,129,165,128,1,19,131,8,48,36,128,
                               1,113,0,0,63,164>>}}}}}

Reset of stack omitted.

My interpretation is that initial CallEventRecord choice 1
(GGSNPDPRecord) is not decoding, but I have no idea what the binary is
suppose to be telling me, other than "You Are Here in the BER input".

CallEventRecord ::= CHOICE
{
        sgsnPDPRecord                   [0] SGSNPDPRecord,
        ggsnPDPRecord                   [1] GGSNPDPRecord,
        sgsnMMRecord                    [2] SGSNMMRecord,
        sgsnSMORecord                   [3] SGSNSMORecord,
        sgsnSMTRecord                   [4] SGSNSMTRecord
}

Any clues to would be welcome.

Right now its looking like I'll have to learn how to decode BER by hand
in order to understand the failure better.  Maybe a generic BER to ASN
syntax decoder tool?


--
Anthony C Howe                                              SnertSoft
[hidden email]       Twitter: SirWumpus       BarricadeMX & Milters
http://snert.com/      http://nanozen.info/     http://snertsoft.com/
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: ASN.1 decode errors

Anthony Howe
In reply to this post by Anthony Howe
Thank you to those who contacted me concerning this problem.  It appears that
the issue was with the vendor's (lack of) documentation (and wrong ASN.1 spec.
cited by them) not explaining that the GPRS CDRs were wrapped in a binary file
format that was not part of the ASN.1 BER encoding.  So the Erlang ASN.1
compiler was correct, but the input was offset.

Anthony

On 2019-09-12 10:29, Anthony Howe wrote:

> I've written a couple ASN.1 BER and PER transcoders to JSON for LTE,
> TAP3, NRTRDE files before.  ( It was Erlang's open source ASN.1 support
> that got me to learn the language in the first place. )  I'm trying to
> write one now for GPRS charging records (ETSI TS 101 393 V7.4.0
> (2000-02)); I have something that builds, but does not decode the input
> and just reports a vague Erlang ASN error.
>
> I figure the problem revolves around a mismatched set of ASN module
> files (which are a frik'n pain to find, but I digress).  Anyway, I
> figure if I understood the error better it might point me finally in the
> right direction.
>
> So the error is...
>
> $ ./_build/default/bin/gprsdump -r cdr_0f1
> cdr_0f1: processing...
> runtime error: cdr_0f1: {badmatch,
>                          {error,
>                           {asn1,
>                            {invalid_choice_tag,
>                             {1,
>                              <<0,168,161,129,165,128,1,19,131,8,48,36,128,
>                                1,113,0,0,63,164>>}}}}}
>
> Reset of stack omitted.
>
> My interpretation is that initial CallEventRecord choice 1
> (GGSNPDPRecord) is not decoding, but I have no idea what the binary is
> suppose to be telling me, other than "You Are Here in the BER input".
>
> CallEventRecord ::= CHOICE
> {
> sgsnPDPRecord [0] SGSNPDPRecord,
> ggsnPDPRecord [1] GGSNPDPRecord,
> sgsnMMRecord [2] SGSNMMRecord,
> sgsnSMORecord [3] SGSNSMORecord,
> sgsnSMTRecord [4] SGSNSMTRecord
> }
>
> Any clues to would be welcome.
>
> Right now its looking like I'll have to learn how to decode BER by hand
> in order to understand the failure better.  Maybe a generic BER to ASN
> syntax decoder tool?
>
>


--
Anthony C Howe                                            SnertSoft
[hidden email]       Twitter: SirWumpus       BarricadeMX & Milters
http://snert.com/      http://nanozen.info/     http://snertsoft.com/
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions