Harald Welte | a76c4bb | 2017-12-09 02:06:07 +0100 | [diff] [blame] | 1 | module Osmocom_CTRL_Types { |
| 2 | |
Harald Welte | 35bb716 | 2018-01-03 21:07:52 +0100 | [diff] [blame] | 3 | /* Definition of abstract types for the CTRL protocol as used in Osmocom. |
| 4 | * Uses the TITAN "TEXT" codec to auto-generate encoder/decoder functions. |
| 5 | * |
| 6 | * (C) 2017 by Harald Welte <laforge@gnumonks.org> |
| 7 | * All rights reserved. |
| 8 | * |
| 9 | * Released under the terms of GNU General Public License, Version 2 or |
| 10 | * (at your option) any later version. |
| 11 | */ |
| 12 | |
Harald Welte | a76c4bb | 2017-12-09 02:06:07 +0100 | [diff] [blame] | 13 | type charstring CtrlVerb ("GET", "SET") with { |
| 14 | /* see https://www.eclipse.org/forums/index.php/t/1088893/ on why this |
| 15 | * match expression is needed here */ |
Harald Welte | fdfa046 | 2017-12-10 18:09:40 +0100 | [diff] [blame] | 16 | variant "TEXT_CODING(,convert=upper_case,'((GET)|(SET))',case_insensitive)" |
Harald Welte | a76c4bb | 2017-12-09 02:06:07 +0100 | [diff] [blame] | 17 | }; |
| 18 | |
Harald Welte | 03c0e56 | 2017-12-09 02:55:12 +0100 | [diff] [blame] | 19 | type charstring CtrlReplyVerb ("GET_REPLY", "SET_REPLY") with { |
| 20 | variant "TEXT_CODING(,convert=upper_case,'((GET_REPLY)|(SET_REPLY))',case_insensitive)" |
Harald Welte | a76c4bb | 2017-12-09 02:06:07 +0100 | [diff] [blame] | 21 | }; |
| 22 | |
| 23 | type charstring CtrlId (pattern "\d#(1,9)"); |
Harald Welte | 0ac4667 | 2017-12-09 14:19:58 +0100 | [diff] [blame] | 24 | type charstring CtrlVariable (pattern "[^, \{\}\[\]\(\)<>\|~\\\^`'\"\?=;/\+&%$\#!]#(1,)"); |
| 25 | type charstring CtrlValue (pattern "[^ ]#(0,)"); |
Harald Welte | a76c4bb | 2017-12-09 02:06:07 +0100 | [diff] [blame] | 26 | type charstring CtrlReason; |
| 27 | |
| 28 | |
| 29 | type record CtrlCommand { |
| 30 | CtrlVerb verb, |
| 31 | CtrlId id, |
| 32 | CtrlVariable variable, |
| 33 | CtrlValue val optional /* only for SET */ |
| 34 | } with { |
| 35 | variant "SEPARATOR(' ',)" |
| 36 | }; |
| 37 | |
| 38 | type record CtrlResponse { |
Harald Welte | 03c0e56 | 2017-12-09 02:55:12 +0100 | [diff] [blame] | 39 | CtrlReplyVerb verb, |
Harald Welte | a76c4bb | 2017-12-09 02:06:07 +0100 | [diff] [blame] | 40 | CtrlId id, |
| 41 | CtrlVariable variable, |
| 42 | CtrlValue val |
| 43 | } with { |
Harald Welte | a76c4bb | 2017-12-09 02:06:07 +0100 | [diff] [blame] | 44 | variant "SEPARATOR(' ',)" |
| 45 | }; |
| 46 | |
| 47 | type record CtrlError { |
| 48 | CtrlId id, |
| 49 | CtrlReason reason |
| 50 | } with { |
| 51 | variant "BEGIN('ERROR ',,case_insensitive)" |
| 52 | variant "SEPARATOR(' ',)" |
| 53 | }; |
| 54 | |
| 55 | type record CtrlTrap { |
| 56 | CtrlVariable variable, |
| 57 | CtrlValue val |
| 58 | } with { |
Harald Welte | fdfa046 | 2017-12-10 18:09:40 +0100 | [diff] [blame] | 59 | variant "BEGIN('TRAP 0 ',,case_insensitive)" |
Harald Welte | a76c4bb | 2017-12-09 02:06:07 +0100 | [diff] [blame] | 60 | variant "SEPARATOR(' ',)" |
| 61 | }; |
| 62 | |
| 63 | type union CtrlMessage { |
| 64 | CtrlCommand cmd, |
| 65 | CtrlResponse resp, |
| 66 | CtrlError err, |
| 67 | CtrlTrap trap |
Harald Welte | 1697976 | 2017-12-13 00:45:44 +0100 | [diff] [blame] | 68 | } with { variant "BEGIN('')" }; |
Harald Welte | a76c4bb | 2017-12-09 02:06:07 +0100 | [diff] [blame] | 69 | |
| 70 | external function enc_CtrlMessage(in CtrlMessage id) return charstring |
| 71 | with { extension "prototype(convert) encode(TEXT)"}; |
| 72 | |
| 73 | external function dec_CtrlMessage(in charstring id) return CtrlMessage |
| 74 | with { extension "prototype(convert) decode(TEXT)"}; |
| 75 | |
| 76 | |
Harald Welte | 03c0e56 | 2017-12-09 02:55:12 +0100 | [diff] [blame] | 77 | template CtrlMessage ts_CtrlMsgGet(CtrlId id, CtrlVariable variable) := { |
| 78 | cmd := { |
| 79 | verb := "GET", |
| 80 | id := id, |
| 81 | variable := variable, |
| 82 | val := omit |
| 83 | } |
| 84 | }; |
| 85 | |
| 86 | template CtrlMessage ts_CtrlMsgSet(CtrlId id, CtrlVariable variable, CtrlValue val) := { |
| 87 | cmd := { |
| 88 | verb := "SET", |
| 89 | id := id, |
| 90 | variable := variable, |
| 91 | val := omit |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | template CtrlMessage tr_CtrlMsgGetRepl(template CtrlId id, template CtrlVariable variable := ?) := { |
| 96 | resp := { |
| 97 | verb := "GET_REPLY", |
| 98 | id := id, |
| 99 | variable := variable, |
| 100 | val := ? |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | template CtrlMessage tr_CtrlMsgSetRepl(template CtrlId id, template CtrlVariable variable := ?, |
| 105 | template CtrlValue val := ?) := { |
| 106 | resp := { |
| 107 | verb := "SET_REPLY", |
| 108 | id := id, |
| 109 | variable := variable, |
| 110 | val := val |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | template CtrlMessage tr_CtrlMsgTrap(template CtrlVariable variable := ?, |
| 115 | template CtrlValue val := ?) := { |
| 116 | trap := { |
| 117 | variable := variable, |
| 118 | val := val |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | template CtrlMessage tr_CtrlMsgError(template CtrlId id := ?, template CtrlReason reason := ?) := { |
| 123 | err := { |
| 124 | id := id, |
| 125 | reason := reason |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | |
Harald Welte | a76c4bb | 2017-12-09 02:06:07 +0100 | [diff] [blame] | 130 | } with { encode "TEXT" } |