blob: 4e3f14f05e0eea2ae9884b10cfb01235ee80f5b1 [file] [log] [blame]
Harald Welte9b064882019-04-11 19:25:00 +02001module PAP_Types {
2
3/* (C) 2019 by Harald Welte <laforge@gnumonks.org>
4 * All rights reserved.
5 *
6 * Released under the terms of GNU General Public License, Version 2 or
7 * (at your option) any later version.
8 */
9
10import from Osmocom_Types all;
11
12/* RFC1334 */
13type enumerated PapCode {
14 PAP_AuthenticateReq ('01'O),
15 PAP_AuthenticateAck ('02'O),
16 PAP_AuthenticateNak ('03'O)
17} with { variant "FIELDLENGTH(8)" };
18
19type record PapPacket {
20 PapCode code,
21 uint8_t identifier,
22 uint16_t len,
23 PapPayloadUnion payload
24} with {
25 variant (len) "LENGTHTO(code,identifier,len,payload)"
26 variant (payload) "CROSSTAG( req, code = PAP_AuthenticateReq;
27 ack, code = PAP_AuthenticateAck;
28 nak, code = PAP_AuthenticateNak)"
29};
30
31type union PapPayloadUnion {
32 PapAuthReq req,
33 PapAuthResp ack,
34 PapAuthResp nak
35};
36
37type record PapAuthReq {
38 uint8_t peer_id_len,
39 octetstring peer_id,
40 uint8_t passwd_len,
41 octetstring passwd
42} with {
43 variant (peer_id_len) "LENGTHTO(peer_id)"
44 variant (passwd_len) "LENGTHTO(passwd)"
45};
46
47type record PapAuthResp {
48 uint8_t msg_len,
49 charstring msg
50} with { variant (msg_len) "LENGTHTO(msg)" };
51
52external function enc_PapPacket(in PapPacket inp) return octetstring
53with { extension "prototype(convert)" extension "encode(RAW)" };
54
55external function dec_PapPacket(in octetstring inp) return PapPacket
56with { extension "prototype(convert)" extension "decode(RAW)" };
57
58
59template (value) PapPacket ts_PAP(template (value) PapCode code, template (value) uint8_t identifier,
60 template (value) PapPayloadUnion payload) := {
61 code := code,
62 identifier := identifier,
63 len := 0, /* overwritten */
64 payload := payload
65}
66template PapPacket tr_PAP(template PapCode code, template uint8_t identifier, template PapPayloadUnion payload) := {
67 code := code,
68 identifier := identifier,
69 len := ?,
70 payload := payload
71}
72
73template (value) PapPacket ts_PAP_AuthReq(uint8_t identifier := 0, octetstring peer_id, octetstring passwd) :=
74 ts_PAP(PAP_AuthenticateReq, identifier,
75 { req := { peer_id_len := 0, peer_id := peer_id,
76 passwd_len := 0, passwd := passwd } });
77template PapPacket tr_PAP_AuthReq(template uint8_t identifier := ?, octetstring peer_id, octetstring passwd) :=
78 tr_PAP(PAP_AuthenticateReq, identifier,
79 { req := { peer_id_len := ?, peer_id := peer_id,
80 passwd_len := ?, passwd := passwd } });
81template (value) PapPacket ts_PAP_AuthAck(uint8_t identifier := 0, charstring msg) :=
82 ts_PAP(PAP_AuthenticateAck, identifier, { ack := { msg_len := 0, msg := msg } });
83template PapPacket tr_PAP_AuthAck(template uint8_t identifier := ?) :=
84 tr_PAP(PAP_AuthenticateAck, identifier, { ack := ? });
85template (value) PapPacket ts_PAP_AuthNak(uint8_t identifier := 0, charstring msg) :=
86 ts_PAP(PAP_AuthenticateNak, identifier, { nak := { msg_len := 0, msg := msg } });
87template PapPacket tr_PAP_AuthNak(template uint8_t identifier := ?) :=
88 tr_PAP(PAP_AuthenticateNak, identifier, { nak := ? });
89
90} with { encode "RAW" ; variant "FIELDORDER(msb)" }