summaryrefslogtreecommitdiffstats
path: root/library/Osmocom_CTRL_Types.ttcn
blob: 1d776689bb49541c5a65790d9822347074129fe8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
module Osmocom_CTRL_Types {

/* Definition of abstract types for the CTRL protocol as used in Osmocom.
 * Uses the TITAN "TEXT" codec to auto-generate encoder/decoder functions.
 *
 * (C) 2017 by Harald Welte <laforge@gnumonks.org>
 * All rights reserved.
 *
 * Released under the terms of GNU General Public License, Version 2 or
 * (at your option) any later version.
 */

type charstring CtrlVerb ("GET", "SET") with {
	/* see https://www.eclipse.org/forums/index.php/t/1088893/ on why this
	 * match expression is needed here */
	variant "TEXT_CODING(,convert=upper_case,'((GET)|(SET))',case_insensitive)"
};

type charstring CtrlReplyVerb ("GET_REPLY", "SET_REPLY") with {
	variant "TEXT_CODING(,convert=upper_case,'((GET_REPLY)|(SET_REPLY))',case_insensitive)"
};

type charstring CtrlId	(pattern "\d#(1,9)");
type charstring CtrlVariable (pattern "[^, \{\}\[\]\(\)<>\|~\\\^`'\"\?=;/\+&%$\#!]#(1,)");
type charstring CtrlValue (pattern "[^ ]#(0,)");
type charstring CtrlReason;


type record CtrlCommand {
	CtrlVerb	verb,
	CtrlId		id,
	CtrlVariable	variable,
	CtrlValue	val optional	/* only for SET */
} with {
	variant "SEPARATOR(' ',)"
};

type record CtrlResponse {
	CtrlReplyVerb	verb,
	CtrlId		id,
	CtrlVariable	variable,
	CtrlValue	val
} with {
	variant "SEPARATOR(' ',)"
};

type record CtrlError {
	CtrlId		id,
	CtrlReason	reason
} with {
	variant "BEGIN('ERROR ',,case_insensitive)"
	variant "SEPARATOR(' ',)"
};

type record CtrlTrap {
	CtrlVariable	variable,
	CtrlValue	val
} with {
	variant "BEGIN('TRAP 0 ',,case_insensitive)"
	variant "SEPARATOR(' ',)"
};

type union CtrlMessage {
	CtrlCommand	cmd,
	CtrlResponse	resp,
	CtrlError	err,
	CtrlTrap	trap
} with { variant "BEGIN('')" };

external function enc_CtrlMessage(in CtrlMessage id) return charstring
	with { extension "prototype(convert) encode(TEXT)"};

external function dec_CtrlMessage(in charstring id) return CtrlMessage
	with { extension "prototype(convert) decode(TEXT)"};


template CtrlMessage ts_CtrlMsgGet(CtrlId id, CtrlVariable variable) := {
	cmd := {
		verb := "GET",
		id := id,
		variable := variable,
		val := omit
	}
};

template CtrlMessage ts_CtrlMsgSet(CtrlId id, CtrlVariable variable, CtrlValue val) := {
	cmd := {
		verb := "SET",
		id := id,
		variable := variable,
		val := omit
	}
}

template CtrlMessage tr_CtrlMsgGetRepl(template CtrlId id, template CtrlVariable variable := ?) := {
	resp := {
		verb := "GET_REPLY",
		id := id,
		variable := variable,
		val := ?
	}
}

template CtrlMessage tr_CtrlMsgSetRepl(template CtrlId id, template CtrlVariable variable := ?,
			   template CtrlValue val := ?) := {
	resp := {
		verb := "SET_REPLY",
		id := id,
		variable := variable,
		val := val
	}
}

template CtrlMessage tr_CtrlMsgTrap(template CtrlVariable variable := ?,
			template CtrlValue val := ?) := {
	trap := {
		variable := variable,
		val := val
	}
}

template CtrlMessage tr_CtrlMsgError(template CtrlId id := ?, template CtrlReason reason := ?) := {
	err := {
		id := id,
		reason := reason
	}
}


} with { encode "TEXT" }