Any ASN.1 API exploitable for network protocols?

Papa Tana papa.tana101@REDACTED
Wed Jul 1 12:49:55 CEST 2020


Hi All,

NTP is just taken as an example here.

I have built a simple NTP client.

create_ntp_request() -> << 0:2, 3:3, ... >>.
	
% 0                   1                   2                   3
%  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
% +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
% |LI | VN  |Mode |    Stratum     |     Poll      |  Precision   |
% +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
% |                         Root Delay                            |
% +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
..........

The NTP server is answering me and I can decode the response.

display_result(<<
   LI:2,
   VN:3,
   .....
	>>) ->
	// DO SOME JOB
;

HERE comes my problem:

The NTP server is not speaking ASN.1 at all.
I am sending a binary request, he is answering me with binary response.
And this is the way it should be.

It would be great if it was possible to do something like below:

Protocols
DEFINITIONS AUTOMATIC TAGS ::=
BEGIN
	NTPRequest ::= SEQUENCE {
		li			BIT STRING (SIZE(2)),
		version		BIT STRING (SIZE(3)),
		blablablabla...........
	}
	NTPResponse ::= SEQUENCE {
		li			BIT STRING (SIZE(2)),
		version		BIT STRING (SIZE(3)),
		blablablabla...........
	}
END

> SomeNtpRequest = {'NTPRequest'}.
> setElement(2, <<0:2>>, SomeNtpRequest).
> setElement(3, <<3:3>>, SomeNtpRequest).

> Standard = 'Protocols':transform2Standard('NTPRequest', SomeNtpRequest).

> ok = gen_udp:send(Skt, Host, ?NTP_UDP_PORT, Standard).


> Response = /* receive dummy NTP response from server <<28,2,3,...>> */
> BAsn = 'Protocols':transform2Asn('NTPResponse', Response).

> 'Protocols':decode('NTPResponse', BAsn).
> {ok,{'NTPResponse',<<1:2>>, <<3:3>>,...

Any suggestion please?

This question is interesting because it would be really useful to
manipulate network protocols like GTP, Diameter, PFCP, etc... if any
API.

Thank you,


More information about the erlang-questions mailing list