blob: eb0c1d19ee723555f17c69e366a27c2adc457e49 [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.
Harald Welte34b5a952019-05-27 11:54:11 +02008 *
9 * SPDX-License-Identifier: GPL-2.0-or-later
Harald Welte9b064882019-04-11 19:25:00 +020010 */
11
12import from Osmocom_Types all;
13
14/* RFC1334 */
15type enumerated PapCode {
16 PAP_AuthenticateReq ('01'O),
17 PAP_AuthenticateAck ('02'O),
18 PAP_AuthenticateNak ('03'O)
19} with { variant "FIELDLENGTH(8)" };
20
21type record PapPacket {
22 PapCode code,
23 uint8_t identifier,
24 uint16_t len,
25 PapPayloadUnion payload
26} with {
27 variant (len) "LENGTHTO(code,identifier,len,payload)"
28 variant (payload) "CROSSTAG( req, code = PAP_AuthenticateReq;
29 ack, code = PAP_AuthenticateAck;
30 nak, code = PAP_AuthenticateNak)"
31};
32
33type union PapPayloadUnion {
34 PapAuthReq req,
35 PapAuthResp ack,
36 PapAuthResp nak
37};
38
39type record PapAuthReq {
40 uint8_t peer_id_len,
41 octetstring peer_id,
42 uint8_t passwd_len,
43 octetstring passwd
44} with {
45 variant (peer_id_len) "LENGTHTO(peer_id)"
46 variant (passwd_len) "LENGTHTO(passwd)"
47};
48
49type record PapAuthResp {
50 uint8_t msg_len,
51 charstring msg
52} with { variant (msg_len) "LENGTHTO(msg)" };
53
54external function enc_PapPacket(in PapPacket inp) return octetstring
55with { extension "prototype(convert)" extension "encode(RAW)" };
56
57external function dec_PapPacket(in octetstring inp) return PapPacket
58with { extension "prototype(convert)" extension "decode(RAW)" };
59
60
61template (value) PapPacket ts_PAP(template (value) PapCode code, template (value) uint8_t identifier,
62 template (value) PapPayloadUnion payload) := {
63 code := code,
64 identifier := identifier,
65 len := 0, /* overwritten */
66 payload := payload
67}
68template PapPacket tr_PAP(template PapCode code, template uint8_t identifier, template PapPayloadUnion payload) := {
69 code := code,
70 identifier := identifier,
71 len := ?,
72 payload := payload
73}
74
75template (value) PapPacket ts_PAP_AuthReq(uint8_t identifier := 0, octetstring peer_id, octetstring passwd) :=
76 ts_PAP(PAP_AuthenticateReq, identifier,
77 { req := { peer_id_len := 0, peer_id := peer_id,
78 passwd_len := 0, passwd := passwd } });
79template PapPacket tr_PAP_AuthReq(template uint8_t identifier := ?, octetstring peer_id, octetstring passwd) :=
80 tr_PAP(PAP_AuthenticateReq, identifier,
81 { req := { peer_id_len := ?, peer_id := peer_id,
82 passwd_len := ?, passwd := passwd } });
83template (value) PapPacket ts_PAP_AuthAck(uint8_t identifier := 0, charstring msg) :=
84 ts_PAP(PAP_AuthenticateAck, identifier, { ack := { msg_len := 0, msg := msg } });
85template PapPacket tr_PAP_AuthAck(template uint8_t identifier := ?) :=
86 tr_PAP(PAP_AuthenticateAck, identifier, { ack := ? });
87template (value) PapPacket ts_PAP_AuthNak(uint8_t identifier := 0, charstring msg) :=
88 ts_PAP(PAP_AuthenticateNak, identifier, { nak := { msg_len := 0, msg := msg } });
89template PapPacket tr_PAP_AuthNak(template uint8_t identifier := ?) :=
90 tr_PAP(PAP_AuthenticateNak, identifier, { nak := ? });
91
92} with { encode "RAW" ; variant "FIELDORDER(msb)" }