blob: fc8e23f66262878559e07913dbe58926ecab03dd [file] [log] [blame]
Harald Welteb0d93602018-03-20 18:09:34 +01001module SIP_Templates {
2
3import from SIPmsg_Types all;
Pau Espin Pedrol6052a342024-03-28 20:20:46 +01004import from Osmocom_Types all;
Harald Welteb0d93602018-03-20 18:09:34 +01005
6/* wrapper type to encapsulate the Addr_Union + parameter list used in From, To. ... */
7type record SipAddr {
8 Addr_Union addr,
9 SemicolonParam_List params optional
10}
11
12const charstring c_SIP_VERSION := "SIP/2.0";
13
Pau Espin Pedrolfb34d862024-03-28 20:21:38 +010014template (value) SipUrl ts_SipUrl(template (value) HostPort host_port,
15 template (omit) UserInfo user_info := omit) := {
Harald Welteb0d93602018-03-20 18:09:34 +010016 scheme := "sip",
Pau Espin Pedrolfb34d862024-03-28 20:21:38 +010017 userInfo := user_info,
18 hostPort := host_port,
Harald Welteb0d93602018-03-20 18:09:34 +010019 urlParameters := omit,
20 headers := omit
21}
Pau Espin Pedrolfb34d862024-03-28 20:21:38 +010022template (present) SipUrl tr_SipUrl(template (present) HostPort host_port := ?,
23 template UserInfo user_info := *) := {
Harald Welteb0d93602018-03-20 18:09:34 +010024 scheme := "sip",
Pau Espin Pedrolfb34d862024-03-28 20:21:38 +010025 userInfo := user_info,
26 hostPort := host_port,
Harald Welteb0d93602018-03-20 18:09:34 +010027 urlParameters := *,
28 headers := *
29}
30
Pau Espin Pedrolfb34d862024-03-28 20:21:38 +010031template (value) SipUrl ts_SipUrlHost(template (value) charstring host)
32 := ts_SipUrl(ts_HostPort(host));
33
34// [20.10]
35template (present) NameAddr tr_NameAddr(template (present) SipUrl addrSpec := ?,
36 template charstring displayName := *) := {
37 displayName := displayName,
38 addrSpec := addrSpec
Harald Welteb0d93602018-03-20 18:09:34 +010039}
Pau Espin Pedrolfb34d862024-03-28 20:21:38 +010040template (value) NameAddr ts_NameAddr(template (value) SipUrl addrSpec,
41 template (omit) charstring displayName := omit) := {
42 displayName := displayName,
43 addrSpec := addrSpec
44}
45
46template (present) Addr_Union tr_Addr_Union_NameAddr(template (present) NameAddr nameAddr := ?) := {
47 nameAddr := nameAddr
48}
49template (value) Addr_Union ts_Addr_Union_NameAddr(template (value) NameAddr nameAddr) := {
50 nameAddr := nameAddr
51}
52
53template (present) Addr_Union tr_Addr_Union_SipUrl(template (present) SipUrl sipUrl := ?) := {
54 addrSpecUnion := sipUrl
55}
56template (value) Addr_Union ts_Addr_Union_SipUrl(template (value) SipUrl sipUrl) := {
57 addrSpecUnion := sipUrl
58}
59
60
61template (present) ContactAddress tr_ContactAddress(template (present) Addr_Union addressField := ?,
62 template SemicolonParam_List contactParams := *) := {
63 addressField := addressField,
64 contactParams := contactParams
65}
66template (value) ContactAddress ts_ContactAddress(template (value) Addr_Union addressField,
67 template (omit) SemicolonParam_List contactParams := omit) := {
68 addressField := addressField,
69 contactParams := contactParams
70}
71
72template (present) Contact tr_Contact(template (present) ContactAddress_List contactAddresses := ?) := {
73 fieldName := CONTACT_E,
74 contactBody := {
75 contactAddresses := contactAddresses
76 }
77}
78template (value) Contact ts_Contact(template (value) ContactAddress_List contactAddresses) := {
79 fieldName := CONTACT_E,
80 contactBody := {
81 contactAddresses := contactAddresses
82 }
83}
84
85template (value) Contact ts_ContactWildcard := {
86 fieldName := CONTACT_E,
87 contactBody := {
88 wildcard := "*"
89 }
90}
91
92template (present) Contact tr_Contact_SipAddr(template (present) SipAddr contact_addr := ?)
93 := tr_Contact({ tr_ContactAddress(contact_addr.addr, contact_addr.params) });
94
95private function f_tr_Contact_SipAddr(template SipAddr contact_addr) return template Contact
96{
97 if (istemplatekind(contact_addr, "omit")) {
98 return omit;
99 } else if (istemplatekind(contact_addr, "*")) {
100 return *;
101 }
102 return tr_Contact_SipAddr(contact_addr);
103}
104
105template (value) Contact ts_Contact_SipAddr(template (value) SipAddr contact_addr)
106 := ts_Contact({ ts_ContactAddress(contact_addr.addr, contact_addr.params) });
107private function ts_Contact_SipAddr_omit(template (omit) SipAddr contact_addr := omit) return template (omit) Contact
108{
109 if (istemplatekind(contact_addr, "omit")) {
110 return omit;
111 }
112 return ts_Contact_SipAddr(contact_addr);
113}
114
115
116// [20.19]
117template (value) Expires ts_Expires(template (value) DeltaSec deltaSec := "7200") := {
118 fieldName := EXPIRES_E,
119 deltaSec := deltaSec
120}
121
122template (value) SipAddr ts_SipAddr(template (value) HostPort host_port,
123 template (omit) UserInfo user_info := omit,
124 template (omit) charstring displayName := omit,
125 template (omit) SemicolonParam_List params := omit) := {
Harald Welteb0d93602018-03-20 18:09:34 +0100126 addr := {
127 nameAddr := {
Pau Espin Pedrolfb34d862024-03-28 20:21:38 +0100128 displayName := displayName,
129 addrSpec := ts_SipUrl(host_port, user_info)
Harald Welteb0d93602018-03-20 18:09:34 +0100130 }
131 },
Pau Espin Pedrolfb34d862024-03-28 20:21:38 +0100132 params := params
133}
134template (present) SipAddr tr_SipAddr(template (present) HostPort host_port := ?,
135 template UserInfo user_info := *,
136 template charstring displayName := *,
137 template SemicolonParam_List params := *) := {
138 addr := {
139 nameAddr := {
140 displayName := displayName,
141 addrSpec := tr_SipUrl(host_port, user_info)
142 }
143 },
144 params := params
Harald Welteb0d93602018-03-20 18:09:34 +0100145}
146
147/* build a receive template from a value: substitute '*' for omit */
Pau Espin Pedrolfb34d862024-03-28 20:21:38 +0100148function tr_SipAddr_from_val(SipAddr tin) return template (present) SipAddr {
149 var template (present) SipAddr ret := tin;
Harald Welteb0d93602018-03-20 18:09:34 +0100150 if (tin.addr.nameAddr.displayName == omit) {
151 ret.addr.nameAddr.displayName := *;
152 }
153 if (tin.addr.nameAddr.addrSpec.userInfo.password == omit) {
154 ret.addr.nameAddr.addrSpec.userInfo.password := *;
155 }
156 if (tin.params == omit) {
157 ret.params := *;
158 }
159 return ret;
160}
161
Pau Espin Pedrolfb34d862024-03-28 20:21:38 +0100162template (value) HostPort ts_HostPort(template (omit) charstring host := omit,
163 template (omit) integer portField := omit) := {
164 host := host,
165 portField := portField
166}
Harald Welteb0d93602018-03-20 18:09:34 +0100167function tr_HostPort(template HostPort hp) return template HostPort {
168 var template HostPort hpout := hp;
169 /* if the port number is 5060, it may be omitted */
170 if (isvalue(hp.portField) and valueof(hp.portField) == 5060) {
171 hpout.portField := 5060 ifpresent;
172 }
173 return hpout;
174}
175
Pau Espin Pedrolfb34d862024-03-28 20:21:38 +0100176
177template (value) UserInfo ts_UserInfo(template (value) charstring userOrTelephoneSubscriber,
178 template (omit) charstring password := omit) := {
179 userOrTelephoneSubscriber := userOrTelephoneSubscriber,
180 password := password
181}
182template (present) UserInfo tr_UserInfo(template (present) charstring userOrTelephoneSubscriber := ?,
183 template charstring password := *) := {
184 userOrTelephoneSubscriber := userOrTelephoneSubscriber,
185 password := password
186}
187
188template (value) RequestLine ts_SIP_ReqLine(Method method,
189 template (value) SipUrl uri,
Harald Welteb0d93602018-03-20 18:09:34 +0100190 charstring ver := c_SIP_VERSION) := {
191 method := method,
192 requestUri := uri,
193 sipVersion := ver
194}
Pau Espin Pedrolfb34d862024-03-28 20:21:38 +0100195template (present) RequestLine tr_SIP_ReqLine(template (present) Method method := ?,
196 template (present) SipUrl uri := ?,
197 template (present) charstring ver := c_SIP_VERSION) := {
Harald Welteb0d93602018-03-20 18:09:34 +0100198 method := method,
199 requestUri := uri,
200 sipVersion := ver
201}
202
203template (value) StatusLine ts_SIP_StatusLine(integer status_code, charstring reason) := {
204 sipVersion := "SIP/2.0",
205 statusCode := status_code,
206 reasonPhrase := reason
207}
Pau Espin Pedrolfb34d862024-03-28 20:21:38 +0100208template (present) StatusLine tr_SIP_StatusLine(template integer status_code,
209 template charstring reason) := {
Harald Welteb0d93602018-03-20 18:09:34 +0100210 sipVersion := "SIP/2.0",
211 statusCode := status_code,
212 reasonPhrase := reason
213}
214
215
216template (value) PDU_SIP_Request ts_SIP_req(template (value) RequestLine rl) := {
217 requestLine := rl,
218 msgHeader := c_SIP_msgHeader_empty,
219 messageBody := omit,
220 payload := omit
221}
222
223const Method_List c_SIP_defaultMethods := {
224 "INVITE", "ACK", "BYE", "CANCEL", "OPTIONS", "PRACK", "MESSAGE", "SUBSCRIBE",
225 "NOTIFY", "REFER", "UPDATE" };
226
227private function f_ContentTypeOrOmit(template (omit) ContentType ct, template (omit) charstring body)
228return template (omit) ContentType {
229 /* if user explicitly stated no content type */
230 if (istemplatekind(ct, "omit")) {
231 return omit;
232 }
233 /* if there's no body, then there's no content-type either */
234 if (istemplatekind(body, "omit")) {
235 return omit;
236 }
237 return ct;
238}
239
240template (value) ContentType ts_CT_SDP := {
241 fieldName := CONTENT_TYPE_E,
242 mediaType := "application/sdp"
243};
244
Pau Espin Pedrolfb34d862024-03-28 20:21:38 +0100245template (value) Via ts_Via_from(template (value) HostPort addr) := {
Harald Welteb0d93602018-03-20 18:09:34 +0100246 fieldName := VIA_E,
247 viaBody := {
248 {
249 sentProtocol := { "SIP", "2.0", "UDP" },
Pau Espin Pedrolfb34d862024-03-28 20:21:38 +0100250 sentBy := addr,
Harald Welteb0d93602018-03-20 18:09:34 +0100251 viaParams := omit
252 }
253 }
254}
Pau Espin Pedrolfb34d862024-03-28 20:21:38 +0100255template (present) Via tr_Via_from(template (present) HostPort host_port := ?,
256 template SemicolonParam_List viaParams := *) := {
257 fieldName := VIA_E,
258 viaBody := {
259 {
260 sentProtocol := { "SIP", "2.0", "UDP" },
261 sentBy := host_port,
262 viaParams := viaParams
263 }
264 }
265 }
Harald Welteb0d93602018-03-20 18:09:34 +0100266
Pau Espin Pedrolfb34d862024-03-28 20:21:38 +0100267template (value) MessageHeader ts_SIP_msgHeader_empty := c_SIP_msgHeader_empty;
268template (value) MessageHeader
269ts_SIP_msgh_std(template (value) CallidString call_id,
270 template (value) SipAddr from_addr,
271 template (value) SipAddr to_addr,
272 template (omit) Contact contact,
273 template (value) charstring method,
274 template (value) integer seq_nr,
275 template (value) Via via,
276 template (omit) ContentType content_type := omit,
277 template (value) Method_List allow_methods := c_SIP_defaultMethods,
278 template (omit) Expires expires := omit
279 ) modifies ts_SIP_msgHeader_empty := {
Harald Welteb0d93602018-03-20 18:09:34 +0100280 allow := {
281 fieldName := ALLOW_E,
282 methods := allow_methods
283 },
284 callId := {
285 fieldName := CALL_ID_E,
286 callid := call_id
287 },
Pau Espin Pedrolfb34d862024-03-28 20:21:38 +0100288 contact := contact,
Harald Welteb0d93602018-03-20 18:09:34 +0100289 contentType := content_type,
290 cSeq := {
291 fieldName := CSEQ_E,
292 seqNumber := seq_nr,
293 method := method
294 },
Pau Espin Pedrolfb34d862024-03-28 20:21:38 +0100295 expires := expires,
Harald Welteb0d93602018-03-20 18:09:34 +0100296 fromField := {
297 fieldName := FROM_E,
298 addressField := from_addr.addr,
299 fromParams := from_addr.params
300 },
301 toField := {
302 fieldName := TO_E,
303 addressField := to_addr.addr,
304 toParams := to_addr.params
305 },
306 userAgent := {
307 fieldName := USER_AGENT_E,
308 userAgentBody := {
309 "osmo-ttcn3-hacks/0.23"
310 }
311 },
312 via := via
313}
314
Harald Welteb0d93602018-03-20 18:09:34 +0100315function tr_AllowMethods(template Method_List allow_methods) return template Allow {
316 if (istemplatekind(allow_methods, "omit")) {
317 return omit;
318 } else if (istemplatekind(allow_methods, "*")) {
319 return *;
320 } else if (istemplatekind(allow_methods, "?")) {
321 return ?;
322 }
Pau Espin Pedrolfb34d862024-03-28 20:21:38 +0100323 var template (present) Allow ret := {
Harald Welteb0d93602018-03-20 18:09:34 +0100324 fieldName := ALLOW_E,
325 methods := allow_methods
326 }
327 return ret
328}
329
Pau Espin Pedrolfb34d862024-03-28 20:21:38 +0100330template (present) MessageHeader
331tr_SIP_msgh_std(template CallidString call_id,
332 template SipAddr from_addr,
333 template SipAddr to_addr,
334 template Contact contact,
335 template (present) Via via := tr_Via_from(?),
336 template charstring method,
337 template ContentType content_type := *,
338 template integer seq_nr := ?,
339 template Method_List allow_methods := *,
340 template Expires expires := *
341 ) modifies t_SIP_msgHeader_any := {
Harald Welteb0d93602018-03-20 18:09:34 +0100342 allow := tr_AllowMethods(allow_methods),
343 callId := {
344 fieldName := CALL_ID_E,
345 callid := call_id
346 },
Pau Espin Pedrolfb34d862024-03-28 20:21:38 +0100347 contact := contact,
Harald Welteb0d93602018-03-20 18:09:34 +0100348 contentType := content_type,
349 cSeq := {
350 fieldName := CSEQ_E,
351 seqNumber := seq_nr,
352 method := method
353 },
Pau Espin Pedrolfb34d862024-03-28 20:21:38 +0100354 expires := expires,
Harald Welteb0d93602018-03-20 18:09:34 +0100355 fromField := {
356 fieldName := FROM_E,
357 addressField := from_addr.addr,
358 fromParams := from_addr.params
359 },
360 toField := {
361 fieldName := TO_E,
362 addressField := to_addr.addr,
363 toParams := to_addr.params
364 },
365 userAgent := *,
Pau Espin Pedrolfb34d862024-03-28 20:21:38 +0100366 via := via
Harald Welteb0d93602018-03-20 18:09:34 +0100367}
368
369
Pau Espin Pedrolfb34d862024-03-28 20:21:38 +0100370template (value) PDU_SIP_Request
371ts_SIP_REGISTER(template (value) SipUrl sip_url_host_port,
372 template (value) CallidString call_id,
373 template (value) SipAddr from_addr,
374 template (value) SipAddr to_addr,
375 template (value) Via via,
376 integer seq_nr,
377 template (omit) Contact contact,
378 template (omit) Expires expires,
379 template (omit) charstring body := omit) := {
380 requestLine := ts_SIP_ReqLine(REGISTER_E, sip_url_host_port),
381 msgHeader := ts_SIP_msgh_std(call_id, from_addr, to_addr, contact,
382 "REGISTER", seq_nr, via,
383 f_ContentTypeOrOmit(ts_CT_SDP, body),
384 expires := expires),
385 messageBody := body,
386 payload := omit
387}
388template (present) PDU_SIP_Request
389tr_SIP_REGISTER(template (present) SipUrl sip_url_host_port := ?,
390 template (present) CallidString call_id := ?,
391 template (present) SipAddr from_addr := ?,
392 template (present) SipAddr to_addr := ?,
393 template integer seq_nr := *,
394 template Contact contact := *,
395 template Expires expires := *,
396 template charstring body := *) := {
397 requestLine := tr_SIP_ReqLine(REGISTER_E, sip_url_host_port),
398 msgHeader := tr_SIP_msgh_std(call_id, from_addr, to_addr, contact,
399 tr_Via_from(tr_HostPort(from_addr.addr.nameAddr.addrSpec.hostPort)),
400 "INVITE", *, seq_nr,
401 expires := expires),
402 messageBody := body,
403 payload := omit
404}
405
406template (value) PDU_SIP_Request
407ts_SIP_INVITE(CallidString call_id,
408 SipAddr from_addr,
409 SipAddr to_addr,
410 integer seq_nr,
411 template (omit) charstring body := omit) := {
Harald Welteb0d93602018-03-20 18:09:34 +0100412 requestLine := ts_SIP_ReqLine(INVITE_E, to_addr.addr.nameAddr.addrSpec),
Pau Espin Pedrolfb34d862024-03-28 20:21:38 +0100413 msgHeader := ts_SIP_msgh_std(call_id, from_addr, to_addr,
414 ts_Contact_SipAddr(from_addr),
415 "INVITE", seq_nr,
416 ts_Via_from(from_addr.addr.nameAddr.addrSpec.hostPort),
417 f_ContentTypeOrOmit(ts_CT_SDP, body)),
Harald Welteb0d93602018-03-20 18:09:34 +0100418 messageBody := body,
419 payload := omit
420}
Pau Espin Pedrolfb34d862024-03-28 20:21:38 +0100421template (present) PDU_SIP_Request
422tr_SIP_INVITE(template CallidString call_id,
423 template SipAddr from_addr,
424 template SipAddr to_addr,
425 template integer seq_nr,
426 template charstring body) := {
Harald Welteb0d93602018-03-20 18:09:34 +0100427 requestLine := tr_SIP_ReqLine(INVITE_E, to_addr.addr.nameAddr.addrSpec),
Pau Espin Pedrolfb34d862024-03-28 20:21:38 +0100428 msgHeader := tr_SIP_msgh_std(call_id, from_addr, to_addr, ?,
429 tr_Via_from(tr_HostPort(from_addr.addr.nameAddr.addrSpec.hostPort)),
430 "INVITE", *, seq_nr),
Harald Welteb0d93602018-03-20 18:09:34 +0100431 messageBody := body,
432 payload := omit
433}
434
Pau Espin Pedrolfb34d862024-03-28 20:21:38 +0100435template (value) PDU_SIP_Request
436ts_SIP_BYE(CallidString call_id,
437 SipAddr from_addr,
438 SipAddr to_addr,
439 integer seq_nr,
440 template (omit) charstring body) := {
Harald Welteb0d93602018-03-20 18:09:34 +0100441 requestLine := ts_SIP_ReqLine(BYE_E, to_addr.addr.nameAddr.addrSpec),
442 msgHeader := ts_SIP_msgh_std(call_id, from_addr, to_addr, omit, "BYE", seq_nr,
Pau Espin Pedrolfb34d862024-03-28 20:21:38 +0100443 ts_Via_from(from_addr.addr.nameAddr.addrSpec.hostPort),
444 f_ContentTypeOrOmit(ts_CT_SDP, body)),
Harald Welteb0d93602018-03-20 18:09:34 +0100445 messageBody := body,
446 payload := omit
447}
448
Pau Espin Pedrolfb34d862024-03-28 20:21:38 +0100449template (present) PDU_SIP_Request
450tr_SIP_BYE(template CallidString call_id,
451 template SipAddr from_addr,
452 template SipAddr to_addr,
453 template integer seq_nr,
454 template charstring body) := {
Harald Welteb0d93602018-03-20 18:09:34 +0100455 requestLine := tr_SIP_ReqLine(BYE_E, to_addr.addr.nameAddr.addrSpec),
Pau Espin Pedrolfb34d862024-03-28 20:21:38 +0100456 msgHeader := tr_SIP_msgh_std(call_id, from_addr, to_addr, omit,
457 tr_Via_from(tr_HostPort(from_addr.addr.nameAddr.addrSpec.hostPort)),
458 "BYE", *, seq_nr),
Harald Welteb0d93602018-03-20 18:09:34 +0100459 messageBody := body,
460 payload := omit
461}
462
463
Pau Espin Pedrolfb34d862024-03-28 20:21:38 +0100464template (value) PDU_SIP_Request
465ts_SIP_ACK(CallidString call_id,
466 SipAddr from_addr,
467 SipAddr to_addr,
468 integer seq_nr,
469 template (omit) charstring body) := {
Harald Welteb0d93602018-03-20 18:09:34 +0100470 requestLine := ts_SIP_ReqLine(ACK_E, to_addr.addr.nameAddr.addrSpec),
Pau Espin Pedrolfb34d862024-03-28 20:21:38 +0100471 msgHeader := ts_SIP_msgh_std(call_id, from_addr, to_addr,
472 ts_Contact_SipAddr(from_addr),
473 "ACK", seq_nr,
474 ts_Via_from(from_addr.addr.nameAddr.addrSpec.hostPort),
475 f_ContentTypeOrOmit(ts_CT_SDP, body)),
Harald Welteb0d93602018-03-20 18:09:34 +0100476 messageBody := body,
477 payload := omit
478}
Pau Espin Pedrolfb34d862024-03-28 20:21:38 +0100479template (present) PDU_SIP_Request
480tr_SIP_ACK(template CallidString call_id,
481 template SipAddr from_addr,
482 template SipAddr to_addr,
483 template integer seq_nr,
484 template charstring body) := {
Harald Welteb0d93602018-03-20 18:09:34 +0100485 requestLine := tr_SIP_ReqLine(ACK_E, to_addr.addr.nameAddr.addrSpec),
Pau Espin Pedrolfb34d862024-03-28 20:21:38 +0100486 msgHeader := tr_SIP_msgh_std(call_id, from_addr, to_addr, *,
487 tr_Via_from(tr_HostPort(from_addr.addr.nameAddr.addrSpec.hostPort)),
488 "ACK", *, seq_nr),
Harald Welteb0d93602018-03-20 18:09:34 +0100489 messageBody := body,
490 payload := omit
491}
492
Pau Espin Pedrolfb34d862024-03-28 20:21:38 +0100493template (value) PDU_SIP_Response
494ts_SIP_Response(CallidString call_id,
495 SipAddr from_addr,
496 SipAddr to_addr,
497 charstring method,
498 integer status_code,
499 integer seq_nr,
500 charstring reason,
501 Via via,
502 template (omit) charstring body := omit) := {
Harald Welteb0d93602018-03-20 18:09:34 +0100503 statusLine := ts_SIP_StatusLine(status_code, reason),
504 msgHeader := ts_SIP_msgh_std(call_id, from_addr, to_addr, omit, method, seq_nr,
505 via, f_ContentTypeOrOmit(ts_CT_SDP, body)),
506 messageBody := body,
507 payload := omit
508}
509
Pau Espin Pedrolfb34d862024-03-28 20:21:38 +0100510template (present) PDU_SIP_Response
511tr_SIP_Response(template CallidString call_id,
512 template SipAddr from_addr,
513 template SipAddr to_addr,
514 template Contact contact,
515 template charstring method,
516 template integer status_code,
517 template integer seq_nr := ?,
518 template charstring reason := ?,
519 template charstring body := ?) := {
Harald Welteb0d93602018-03-20 18:09:34 +0100520 statusLine := tr_SIP_StatusLine(status_code, reason),
Pau Espin Pedrolfb34d862024-03-28 20:21:38 +0100521 msgHeader := tr_SIP_msgh_std(call_id, from_addr, to_addr, contact,
522 tr_Via_from(tr_HostPort(from_addr.addr.nameAddr.addrSpec.hostPort)),
523 method, *, seq_nr),
Harald Welteb0d93602018-03-20 18:09:34 +0100524 messageBody := body,
525 payload := omit
526}
527
Pau Espin Pedrol37ee0ed2024-03-28 21:17:12 +0100528/* Expect during first REGISTER when authorization is required: */
529template (present) PDU_SIP_Response
530tr_SIP_Response_REGISTER_Unauthorized(
531 template CallidString call_id,
532 template SipAddr from_addr,
533 template SipAddr to_addr,
534 template (present) Via via := tr_Via_from(?),
535 template Contact contact := *,
536 template integer seq_nr := ?,
537 template charstring method := "REGISTER",
538 template integer status_code := 401,
539 template charstring reason := "Unauthorized",
540 template charstring body := *) := {
541 statusLine := tr_SIP_StatusLine(status_code, reason),
542 msgHeader := tr_SIP_msgh_std(call_id, from_addr, to_addr, contact,
543 via,
544 method, *, seq_nr),
545 messageBody := body,
546 payload := omit
547}
Harald Welteb0d93602018-03-20 18:09:34 +0100548
Pau Espin Pedrol6052a342024-03-28 20:20:46 +0100549/* RFC 3261 8.1.1.5:
550 * "The sequence number value MUST be expressible as a 32-bit unsigned integer
551 * and MUST be less than 2**31."
552 */
553function f_sip_rand_seq_nr() return integer {
554 /* 2**31 = 2147483648 */
555 return f_rnd_int(2147483648)
556}
Harald Welteb0d93602018-03-20 18:09:34 +0100557
558}