blob: f78bfc7f2e348bcc63d158498b1da15f6757a0f2 [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",
70 string := "OK"
71 },
72 params:= { { "I", ? }, *},
73 sdp := ?
74 }
75
76 template MgcpCommand ts_MDCX(MgcpTransId trans_id, charstring ep, MgcpConnectionMode mode, MgcpCallId call_id, MgcpConnectionId conn_id, template SDP_Message sdp := omit) := {
77 line := t_MgcpCmdLine("MDCX", trans_id, ep),
78 params := {
79 t_MgcpParConnMode(mode),
80 ts_MgcpParCallId(call_id),
81 ts_MgcpParConnectionId(conn_id),
82 //t_MgcpParReqId(omit),
83 t_MgcpParLocConnOpt("p:20, a:PCMU")
84 },
85 sdp := sdp
86 }
87
88 /* have a function that generates a template, rather than a template in order to handle
89 * optional parameters */
90 function ts_DLCX(MgcpTransId trans_id, charstring ep, template MgcpCallId call_id := omit,
91 template MgcpConnectionId conn_id := omit) return template MgcpCommand {
92 var template MgcpCommand cmd;
93 cmd.line := t_MgcpCmdLine("DLCX", trans_id, ep);
94 cmd.params := {};
95 cmd.sdp := omit;
96 if (isvalue(call_id)) {
97 f_mgcp_par_append(cmd.params, ts_MgcpParCallId(valueof(call_id)));
98 if (isvalue(conn_id)) {
99 f_mgcp_par_append(cmd.params, ts_MgcpParConnectionId(valueof(conn_id)));
100 }
101 }
102 return cmd;
103 }
104
105 /* SDP Templates */
106 template SDP_Origin ts_SDP_origin(charstring addr, charstring session_id,
107 charstring session_version := "1",
108 charstring addr_type := "IP4",
109 charstring user_name := "-") := {
110 user_name := user_name,
111 session_id := session_id,
112 session_version := session_version,
113 net_type := "IN",
114 addr_type := addr_type,
115 addr := addr
116 }
117
118 template SDP_connection ts_SDP_connection_IP(charstring addr, charstring addr_type := "IP4",
119 template integer ttl := omit,
120 template integer num_of_addr := omit) :={
121 net_type := "IN",
122 addr_type := addr_type,
123 conn_addr := {
124 addr := addr,
125 ttl := ttl,
126 num_of_addr := num_of_addr
127 }
128 }
129
130 template SDP_time ts_SDP_time(charstring beg, charstring end) := {
131 time_field := {
132 start_time := beg,
133 stop_time := end
134 },
135 time_repeat := omit
136 }
137
138 template SDP_media_desc ts_SDP_media_desc(integer port_number, SDP_fmt_list fmts,
139 SDP_attribute_list attributes) := {
140 media_field := {
141 media := "audio",
142 ports := {
143 port_number := port_number,
144 num_of_ports := omit
145 },
146 transport := "RTP/AVP",
147 fmts := fmts
148 },
149 information := omit,
150 connections := omit,
151 bandwidth := omit,
152 key := omit,
153 attributes := attributes
154 }
155
156 /* master template for generating SDP based in template arguments */
157 template SDP_Message ts_SDP(charstring local_addr, charstring remote_addr,
158 charstring session_id, charstring session_version,
159 integer rtp_port, SDP_fmt_list fmts,
160 SDP_attribute_list attributes) := {
161 protocol_version := 0,
162 origin := ts_SDP_origin(local_addr, session_id, session_version),
163 session_name := "-",
164 information := omit,
165 uri := omit,
166 emails := omit,
167 phone_numbers := omit,
168 connection := ts_SDP_connection_IP(remote_addr),
169 bandwidth := omit,
170 times := { ts_SDP_time("0","0") },
171 timezone_adjustments := omit,
172 key := omit,
173 attributes := omit,
174 media_list := { ts_SDP_media_desc(rtp_port, fmts, attributes) }
175 }
176
177 template SDP_attribute ts_SDP_rtpmap(integer fmt, charstring val) := {
178 rtpmap := {
179 attr_value := int2str(fmt) & " " & val
180 }
181 }
182 template SDP_attribute ts_SDP_ptime(integer p) := {
183 ptime := {
184 attr_value := int2str(p)
185 }
186 }
187
188}