Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 1 | module SIP_Templates { |
| 2 | |
| 3 | import from SIPmsg_Types all; |
Pau Espin Pedrol | 6052a34 | 2024-03-28 20:20:46 +0100 | [diff] [blame] | 4 | import from Osmocom_Types all; |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 5 | |
| 6 | /* wrapper type to encapsulate the Addr_Union + parameter list used in From, To. ... */ |
| 7 | type record SipAddr { |
| 8 | Addr_Union addr, |
| 9 | SemicolonParam_List params optional |
| 10 | } |
| 11 | |
| 12 | const charstring c_SIP_VERSION := "SIP/2.0"; |
| 13 | |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 14 | template (value) SipUrl ts_SipUrl(template (value) HostPort host_port, |
| 15 | template (omit) UserInfo user_info := omit) := { |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 16 | scheme := "sip", |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 17 | userInfo := user_info, |
| 18 | hostPort := host_port, |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 19 | urlParameters := omit, |
| 20 | headers := omit |
| 21 | } |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 22 | template (present) SipUrl tr_SipUrl(template (present) HostPort host_port := ?, |
| 23 | template UserInfo user_info := *) := { |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 24 | scheme := "sip", |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 25 | userInfo := user_info, |
| 26 | hostPort := host_port, |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 27 | urlParameters := *, |
| 28 | headers := * |
| 29 | } |
| 30 | |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 31 | template (value) SipUrl ts_SipUrlHost(template (value) charstring host) |
| 32 | := ts_SipUrl(ts_HostPort(host)); |
| 33 | |
| 34 | // [20.10] |
| 35 | template (present) NameAddr tr_NameAddr(template (present) SipUrl addrSpec := ?, |
| 36 | template charstring displayName := *) := { |
| 37 | displayName := displayName, |
| 38 | addrSpec := addrSpec |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 39 | } |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 40 | template (value) NameAddr ts_NameAddr(template (value) SipUrl addrSpec, |
| 41 | template (omit) charstring displayName := omit) := { |
| 42 | displayName := displayName, |
| 43 | addrSpec := addrSpec |
| 44 | } |
| 45 | |
| 46 | template (present) Addr_Union tr_Addr_Union_NameAddr(template (present) NameAddr nameAddr := ?) := { |
| 47 | nameAddr := nameAddr |
| 48 | } |
| 49 | template (value) Addr_Union ts_Addr_Union_NameAddr(template (value) NameAddr nameAddr) := { |
| 50 | nameAddr := nameAddr |
| 51 | } |
| 52 | |
| 53 | template (present) Addr_Union tr_Addr_Union_SipUrl(template (present) SipUrl sipUrl := ?) := { |
| 54 | addrSpecUnion := sipUrl |
| 55 | } |
| 56 | template (value) Addr_Union ts_Addr_Union_SipUrl(template (value) SipUrl sipUrl) := { |
| 57 | addrSpecUnion := sipUrl |
| 58 | } |
| 59 | |
| 60 | |
| 61 | template (present) ContactAddress tr_ContactAddress(template (present) Addr_Union addressField := ?, |
| 62 | template SemicolonParam_List contactParams := *) := { |
| 63 | addressField := addressField, |
| 64 | contactParams := contactParams |
| 65 | } |
| 66 | template (value) ContactAddress ts_ContactAddress(template (value) Addr_Union addressField, |
| 67 | template (omit) SemicolonParam_List contactParams := omit) := { |
| 68 | addressField := addressField, |
| 69 | contactParams := contactParams |
| 70 | } |
| 71 | |
| 72 | template (present) Contact tr_Contact(template (present) ContactAddress_List contactAddresses := ?) := { |
| 73 | fieldName := CONTACT_E, |
| 74 | contactBody := { |
| 75 | contactAddresses := contactAddresses |
| 76 | } |
| 77 | } |
| 78 | template (value) Contact ts_Contact(template (value) ContactAddress_List contactAddresses) := { |
| 79 | fieldName := CONTACT_E, |
| 80 | contactBody := { |
| 81 | contactAddresses := contactAddresses |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | template (value) Contact ts_ContactWildcard := { |
| 86 | fieldName := CONTACT_E, |
| 87 | contactBody := { |
| 88 | wildcard := "*" |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | template (present) Contact tr_Contact_SipAddr(template (present) SipAddr contact_addr := ?) |
| 93 | := tr_Contact({ tr_ContactAddress(contact_addr.addr, contact_addr.params) }); |
| 94 | |
| 95 | private 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 | |
| 105 | template (value) Contact ts_Contact_SipAddr(template (value) SipAddr contact_addr) |
| 106 | := ts_Contact({ ts_ContactAddress(contact_addr.addr, contact_addr.params) }); |
| 107 | private 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] |
| 117 | template (value) Expires ts_Expires(template (value) DeltaSec deltaSec := "7200") := { |
| 118 | fieldName := EXPIRES_E, |
| 119 | deltaSec := deltaSec |
| 120 | } |
| 121 | |
| 122 | template (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 Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 126 | addr := { |
| 127 | nameAddr := { |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 128 | displayName := displayName, |
| 129 | addrSpec := ts_SipUrl(host_port, user_info) |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 130 | } |
| 131 | }, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 132 | params := params |
| 133 | } |
| 134 | template (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 Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | /* build a receive template from a value: substitute '*' for omit */ |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 148 | function tr_SipAddr_from_val(SipAddr tin) return template (present) SipAddr { |
| 149 | var template (present) SipAddr ret := tin; |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 150 | 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 Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 162 | template (value) HostPort ts_HostPort(template (omit) charstring host := omit, |
| 163 | template (omit) integer portField := omit) := { |
| 164 | host := host, |
| 165 | portField := portField |
| 166 | } |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 167 | function 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 Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 176 | |
| 177 | template (value) UserInfo ts_UserInfo(template (value) charstring userOrTelephoneSubscriber, |
| 178 | template (omit) charstring password := omit) := { |
| 179 | userOrTelephoneSubscriber := userOrTelephoneSubscriber, |
| 180 | password := password |
| 181 | } |
| 182 | template (present) UserInfo tr_UserInfo(template (present) charstring userOrTelephoneSubscriber := ?, |
| 183 | template charstring password := *) := { |
| 184 | userOrTelephoneSubscriber := userOrTelephoneSubscriber, |
| 185 | password := password |
| 186 | } |
| 187 | |
| 188 | template (value) RequestLine ts_SIP_ReqLine(Method method, |
| 189 | template (value) SipUrl uri, |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 190 | charstring ver := c_SIP_VERSION) := { |
| 191 | method := method, |
| 192 | requestUri := uri, |
| 193 | sipVersion := ver |
| 194 | } |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 195 | template (present) RequestLine tr_SIP_ReqLine(template (present) Method method := ?, |
| 196 | template (present) SipUrl uri := ?, |
| 197 | template (present) charstring ver := c_SIP_VERSION) := { |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 198 | method := method, |
| 199 | requestUri := uri, |
| 200 | sipVersion := ver |
| 201 | } |
| 202 | |
| 203 | template (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 Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 208 | template (present) StatusLine tr_SIP_StatusLine(template integer status_code, |
| 209 | template charstring reason) := { |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 210 | sipVersion := "SIP/2.0", |
| 211 | statusCode := status_code, |
| 212 | reasonPhrase := reason |
| 213 | } |
| 214 | |
| 215 | |
| 216 | template (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 | |
| 223 | const Method_List c_SIP_defaultMethods := { |
| 224 | "INVITE", "ACK", "BYE", "CANCEL", "OPTIONS", "PRACK", "MESSAGE", "SUBSCRIBE", |
| 225 | "NOTIFY", "REFER", "UPDATE" }; |
| 226 | |
| 227 | private function f_ContentTypeOrOmit(template (omit) ContentType ct, template (omit) charstring body) |
| 228 | return 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 | |
| 240 | template (value) ContentType ts_CT_SDP := { |
| 241 | fieldName := CONTENT_TYPE_E, |
| 242 | mediaType := "application/sdp" |
| 243 | }; |
| 244 | |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 245 | template (value) Via ts_Via_from(template (value) HostPort addr) := { |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 246 | fieldName := VIA_E, |
| 247 | viaBody := { |
| 248 | { |
| 249 | sentProtocol := { "SIP", "2.0", "UDP" }, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 250 | sentBy := addr, |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 251 | viaParams := omit |
| 252 | } |
| 253 | } |
| 254 | } |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 255 | template (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 Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 266 | |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 267 | template (value) MessageHeader ts_SIP_msgHeader_empty := c_SIP_msgHeader_empty; |
| 268 | template (value) MessageHeader |
| 269 | ts_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 Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 280 | allow := { |
| 281 | fieldName := ALLOW_E, |
| 282 | methods := allow_methods |
| 283 | }, |
| 284 | callId := { |
| 285 | fieldName := CALL_ID_E, |
| 286 | callid := call_id |
| 287 | }, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 288 | contact := contact, |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 289 | contentType := content_type, |
| 290 | cSeq := { |
| 291 | fieldName := CSEQ_E, |
| 292 | seqNumber := seq_nr, |
| 293 | method := method |
| 294 | }, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 295 | expires := expires, |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 296 | 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 Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 315 | function 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 Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 323 | var template (present) Allow ret := { |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 324 | fieldName := ALLOW_E, |
| 325 | methods := allow_methods |
| 326 | } |
| 327 | return ret |
| 328 | } |
| 329 | |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 330 | template (present) MessageHeader |
| 331 | tr_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 Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 342 | allow := tr_AllowMethods(allow_methods), |
| 343 | callId := { |
| 344 | fieldName := CALL_ID_E, |
| 345 | callid := call_id |
| 346 | }, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 347 | contact := contact, |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 348 | contentType := content_type, |
| 349 | cSeq := { |
| 350 | fieldName := CSEQ_E, |
| 351 | seqNumber := seq_nr, |
| 352 | method := method |
| 353 | }, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 354 | expires := expires, |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 355 | 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 Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 366 | via := via |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 370 | template (value) PDU_SIP_Request |
| 371 | ts_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 | } |
| 388 | template (present) PDU_SIP_Request |
| 389 | tr_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 | |
| 406 | template (value) PDU_SIP_Request |
| 407 | ts_SIP_INVITE(CallidString call_id, |
| 408 | SipAddr from_addr, |
| 409 | SipAddr to_addr, |
| 410 | integer seq_nr, |
| 411 | template (omit) charstring body := omit) := { |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 412 | requestLine := ts_SIP_ReqLine(INVITE_E, to_addr.addr.nameAddr.addrSpec), |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 413 | 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 Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 418 | messageBody := body, |
| 419 | payload := omit |
| 420 | } |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 421 | template (present) PDU_SIP_Request |
| 422 | tr_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 Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 427 | requestLine := tr_SIP_ReqLine(INVITE_E, to_addr.addr.nameAddr.addrSpec), |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 428 | 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 Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 431 | messageBody := body, |
| 432 | payload := omit |
| 433 | } |
| 434 | |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 435 | template (value) PDU_SIP_Request |
| 436 | ts_SIP_BYE(CallidString call_id, |
| 437 | SipAddr from_addr, |
| 438 | SipAddr to_addr, |
| 439 | integer seq_nr, |
| 440 | template (omit) charstring body) := { |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 441 | 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 Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 443 | ts_Via_from(from_addr.addr.nameAddr.addrSpec.hostPort), |
| 444 | f_ContentTypeOrOmit(ts_CT_SDP, body)), |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 445 | messageBody := body, |
| 446 | payload := omit |
| 447 | } |
| 448 | |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 449 | template (present) PDU_SIP_Request |
| 450 | tr_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 Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 455 | requestLine := tr_SIP_ReqLine(BYE_E, to_addr.addr.nameAddr.addrSpec), |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 456 | 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 Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 459 | messageBody := body, |
| 460 | payload := omit |
| 461 | } |
| 462 | |
| 463 | |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 464 | template (value) PDU_SIP_Request |
| 465 | ts_SIP_ACK(CallidString call_id, |
| 466 | SipAddr from_addr, |
| 467 | SipAddr to_addr, |
| 468 | integer seq_nr, |
| 469 | template (omit) charstring body) := { |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 470 | requestLine := ts_SIP_ReqLine(ACK_E, to_addr.addr.nameAddr.addrSpec), |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 471 | 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 Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 476 | messageBody := body, |
| 477 | payload := omit |
| 478 | } |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 479 | template (present) PDU_SIP_Request |
| 480 | tr_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 Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 485 | requestLine := tr_SIP_ReqLine(ACK_E, to_addr.addr.nameAddr.addrSpec), |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 486 | 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 Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 489 | messageBody := body, |
| 490 | payload := omit |
| 491 | } |
| 492 | |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 493 | template (value) PDU_SIP_Response |
| 494 | ts_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 Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 503 | 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 Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 510 | template (present) PDU_SIP_Response |
| 511 | tr_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 Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 520 | statusLine := tr_SIP_StatusLine(status_code, reason), |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 521 | 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 Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 524 | messageBody := body, |
| 525 | payload := omit |
| 526 | } |
| 527 | |
Pau Espin Pedrol | 37ee0ed | 2024-03-28 21:17:12 +0100 | [diff] [blame] | 528 | /* Expect during first REGISTER when authorization is required: */ |
| 529 | template (present) PDU_SIP_Response |
| 530 | tr_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 Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 548 | |
Pau Espin Pedrol | 6052a34 | 2024-03-28 20:20:46 +0100 | [diff] [blame] | 549 | /* 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 | */ |
| 553 | function f_sip_rand_seq_nr() return integer { |
| 554 | /* 2**31 = 2147483648 */ |
| 555 | return f_rnd_int(2147483648) |
| 556 | } |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 557 | |
| 558 | } |