blob: 7a67c41a51b11281bdaa9f718f1b5caa33cf8ea6 [file] [log] [blame]
Harald Welte4029e8c2017-11-23 22:00:42 +01001module MGCP_Templates {
2
3 import from MGCP_Types all;
4 import from SDP_Types all;
5
6 function f_mgcp_par_append(inout template MgcpParameterList list, template MgcpParameter par) {
7 var integer len := lengthof(list);
8 list[len] := par;
9 }
10
11 /* 3.2.2.6 Connection Mode (sendonly, recvonly, sendrecv, confrnce, inactive, loopback,
12 * conttest, netwloop, netwtest) */
13 template MgcpParameter t_MgcpParConnMode(template MgcpConnectionMode mode) := { "M", mode };
14
15 /* 3.2.2.2 CallId: maximum 32 hex chars */
16 template MgcpParameter ts_MgcpParCallId(MgcpCallId cid) := {
17 code := "C",
18 val := hex2str(cid)
19 };
20
21 /* 3.2.2.18 RequestIdentifier: Maximum 32 hex chars */
22 template MgcpParameter ts_MgcpParReqId(MgcpRequestId rid) := {
23 code := "X",
24 val := hex2str(rid)
25 };
26
27 /* 3.2.2.10: LocalConnectionOptions (codec, packetization, bandwidth, ToS, eco, gain, silence, ...) */
28 template MgcpParameter t_MgcpParLocConnOpt(template charstring lco) := { "L", lco };
29
30 /* 3.2.2.5: ConnectionId: maximum 32 hex chars */
31 template MgcpParameter ts_MgcpParConnectionId(MgcpConnectionId cid) := {
32 code := "I",
33 val := hex2str(cid)
34 };
35
36 /* osmo-bsc_mgcp implements L/C/M/X only, osmo-mgw adds 'I' */
37 /* SDP: osmo-bsc_mgcp implements Tx of v,o,s,c,t,m,a */
38
39 template MgcpResponse tr_MgcpResp_Err(template MgcpResponseCode code) := {
40 line := {
41 code := code,
42 trans_id := ?,
43 string := ?
44 },
45 params := {},
46 sdp := omit
47 }
48
49 template MgcpCommandLine t_MgcpCmdLine(template charstring verb, template MgcpTransId trans_id, template charstring ep) := {
50 verb := verb,
51 trans_id := trans_id,
52 ep := ep,
53 ver := "1.0"
54 };
55
56 template MgcpCommand ts_CRCX(MgcpTransId trans_id, charstring ep, MgcpConnectionMode mode, MgcpCallId call_id, template SDP_Message sdp := omit) := {
57 line := t_MgcpCmdLine("CRCX", trans_id, ep),
58 params := {
59 t_MgcpParConnMode(mode),
60 ts_MgcpParCallId(call_id),
61 //t_MgcpParReqId(omit),
62 t_MgcpParLocConnOpt("p:20, a:PCMU")
63 },
64 sdp := sdp
65 }
66
67 template MgcpResponse tr_CRCX_ACK := {
68 line := {
69 code := "200",
Harald Welte51f34ad2017-11-24 20:40:43 +010070 trans_id := ?,
Harald Welte4029e8c2017-11-23 22:00:42 +010071 string := "OK"
72 },
73 params:= { { "I", ? }, *},
74 sdp := ?
75 }
76
77 template MgcpCommand ts_MDCX(MgcpTransId trans_id, charstring ep, MgcpConnectionMode mode, MgcpCallId call_id, MgcpConnectionId conn_id, template SDP_Message sdp := omit) := {
78 line := t_MgcpCmdLine("MDCX", trans_id, ep),
79 params := {
80 t_MgcpParConnMode(mode),
81 ts_MgcpParCallId(call_id),
82 ts_MgcpParConnectionId(conn_id),
83 //t_MgcpParReqId(omit),
84 t_MgcpParLocConnOpt("p:20, a:PCMU")
85 },
86 sdp := sdp
87 }
88
89 /* have a function that generates a template, rather than a template in order to handle
90 * optional parameters */
91 function ts_DLCX(MgcpTransId trans_id, charstring ep, template MgcpCallId call_id := omit,
92 template MgcpConnectionId conn_id := omit) return template MgcpCommand {
93 var template MgcpCommand cmd;
94 cmd.line := t_MgcpCmdLine("DLCX", trans_id, ep);
95 cmd.params := {};
96 cmd.sdp := omit;
97 if (isvalue(call_id)) {
98 f_mgcp_par_append(cmd.params, ts_MgcpParCallId(valueof(call_id)));
99 if (isvalue(conn_id)) {
100 f_mgcp_par_append(cmd.params, ts_MgcpParConnectionId(valueof(conn_id)));
101 }
102 }
103 return cmd;
104 }
105
Harald Weltec82eef42017-11-24 20:40:12 +0100106 template MgcpResponse tr_DLCX_ACK := {
107 line := {
108 code := "200",
109 trans_id := ?,
110 string := "OK"
111 },
112 params:= *,
113 sdp := *
114 }
115
Harald Welte4029e8c2017-11-23 22:00:42 +0100116 /* SDP Templates */
117 template SDP_Origin ts_SDP_origin(charstring addr, charstring session_id,
118 charstring session_version := "1",
119 charstring addr_type := "IP4",
120 charstring user_name := "-") := {
121 user_name := user_name,
122 session_id := session_id,
123 session_version := session_version,
124 net_type := "IN",
125 addr_type := addr_type,
126 addr := addr
127 }
128
129 template SDP_connection ts_SDP_connection_IP(charstring addr, charstring addr_type := "IP4",
130 template integer ttl := omit,
131 template integer num_of_addr := omit) :={
132 net_type := "IN",
133 addr_type := addr_type,
134 conn_addr := {
135 addr := addr,
136 ttl := ttl,
137 num_of_addr := num_of_addr
138 }
139 }
140
141 template SDP_time ts_SDP_time(charstring beg, charstring end) := {
142 time_field := {
143 start_time := beg,
144 stop_time := end
145 },
146 time_repeat := omit
147 }
148
149 template SDP_media_desc ts_SDP_media_desc(integer port_number, SDP_fmt_list fmts,
150 SDP_attribute_list attributes) := {
151 media_field := {
152 media := "audio",
153 ports := {
154 port_number := port_number,
155 num_of_ports := omit
156 },
157 transport := "RTP/AVP",
158 fmts := fmts
159 },
160 information := omit,
161 connections := omit,
162 bandwidth := omit,
163 key := omit,
164 attributes := attributes
165 }
166
167 /* master template for generating SDP based in template arguments */
168 template SDP_Message ts_SDP(charstring local_addr, charstring remote_addr,
169 charstring session_id, charstring session_version,
170 integer rtp_port, SDP_fmt_list fmts,
171 SDP_attribute_list attributes) := {
172 protocol_version := 0,
173 origin := ts_SDP_origin(local_addr, session_id, session_version),
174 session_name := "-",
175 information := omit,
176 uri := omit,
177 emails := omit,
178 phone_numbers := omit,
179 connection := ts_SDP_connection_IP(remote_addr),
180 bandwidth := omit,
181 times := { ts_SDP_time("0","0") },
182 timezone_adjustments := omit,
183 key := omit,
184 attributes := omit,
185 media_list := { ts_SDP_media_desc(rtp_port, fmts, attributes) }
186 }
187
188 template SDP_attribute ts_SDP_rtpmap(integer fmt, charstring val) := {
189 rtpmap := {
190 attr_value := int2str(fmt) & " " & val
191 }
192 }
193 template SDP_attribute ts_SDP_ptime(integer p) := {
194 ptime := {
195 attr_value := int2str(p)
196 }
197 }
198
199}