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 | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 4 | import from TCCConversion_Functions all; |
| 5 | import from TCCOpenSecurity_Functions all; |
Pau Espin Pedrol | 95ad6a0 | 2024-04-18 16:52:46 +0200 | [diff] [blame] | 6 | import from TCCDateTime_Functions all; |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 7 | import from Native_Functions all; |
Pau Espin Pedrol | 6052a34 | 2024-03-28 20:20:46 +0100 | [diff] [blame] | 8 | import from Osmocom_Types all; |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 9 | import from Misc_Helpers all; |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 10 | |
| 11 | /* wrapper type to encapsulate the Addr_Union + parameter list used in From, To. ... */ |
| 12 | type record SipAddr { |
| 13 | Addr_Union addr, |
| 14 | SemicolonParam_List params optional |
| 15 | } |
| 16 | |
| 17 | const charstring c_SIP_VERSION := "SIP/2.0"; |
| 18 | |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 19 | template (value) GenericParam ts_Param(template (value) charstring id, |
| 20 | template (omit) charstring paramValue := omit) := { |
| 21 | id := id, |
| 22 | paramValue := paramValue |
| 23 | } |
| 24 | template (present) GenericParam tr_Param(template (present) charstring id := ?, |
| 25 | template charstring paramValue := *) := { |
| 26 | id := id, |
| 27 | paramValue := paramValue |
| 28 | } |
| 29 | function f_ts_Param_omit(template (value) charstring id, |
| 30 | template (omit) charstring paramValue := omit) |
| 31 | return template (omit) GenericParam |
| 32 | { |
| 33 | if (istemplatekind(paramValue, "omit")) { |
| 34 | return omit; |
| 35 | } |
| 36 | return ts_Param(id, paramValue); |
| 37 | } |
| 38 | |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 39 | template (value) SipUrl ts_SipUrl(template (value) HostPort host_port, |
| 40 | template (omit) UserInfo user_info := omit) := { |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 41 | scheme := "sip", |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 42 | userInfo := user_info, |
| 43 | hostPort := host_port, |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 44 | urlParameters := omit, |
| 45 | headers := omit |
| 46 | } |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 47 | template (present) SipUrl tr_SipUrl(template (present) HostPort host_port := ?, |
| 48 | template UserInfo user_info := *) := { |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 49 | scheme := "sip", |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 50 | userInfo := user_info, |
| 51 | hostPort := host_port, |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 52 | urlParameters := *, |
| 53 | headers := * |
| 54 | } |
| 55 | |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 56 | template (value) SipUrl ts_SipUrlHost(template (value) charstring host, |
| 57 | template (omit) integer portField := omit) |
| 58 | := ts_SipUrl(ts_HostPort(host, portField)); |
| 59 | |
| 60 | function ts_SipUrl_from_Addr_Union(template (value) Addr_Union au) |
| 61 | return template (value) SipUrl { |
| 62 | if (ischosen(au.nameAddr)) { |
| 63 | return au.nameAddr.addrSpec; |
| 64 | } else { /* au.addrSpecUnion */ |
| 65 | return au.addrSpecUnion; |
| 66 | } |
| 67 | } |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 68 | |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 69 | template (value) Credentials ts_Credentials_DigestResponse(template (value) CommaParam_List digestResponse) := { |
| 70 | digestResponse := digestResponse |
| 71 | } |
| 72 | |
| 73 | template (value) Credentials ts_Credentials_DigestResponseMD5( |
| 74 | template (value) charstring username, |
| 75 | template (value) charstring realm, |
| 76 | template (value) charstring nonce, |
| 77 | template (value) charstring uri, |
| 78 | template (value) charstring response, |
| 79 | template (value) charstring opaque, |
| 80 | template (value) charstring algorithm := "MD5", |
| 81 | template (value) charstring qop := "auth", |
| 82 | template (omit) charstring cnonce := omit, |
| 83 | template (omit) charstring nc := omit |
| 84 | ) := { |
| 85 | digestResponse := { |
| 86 | // Already added by digestResponse automatically: |
| 87 | //ts_Param("Digest", omit), |
| 88 | ts_Param("username", f_sip_str_quote(username)), |
| 89 | ts_Param("realm", f_sip_str_quote(realm)), |
| 90 | ts_Param("nonce", f_sip_str_quote(nonce)), |
| 91 | ts_Param("uri", f_sip_str_quote(uri)), |
| 92 | ts_Param("response", f_sip_str_quote(response)), |
| 93 | ts_Param("opaque", f_sip_str_quote(opaque)), |
| 94 | ts_Param("algorithm", algorithm), |
| 95 | ts_Param("qop", qop), |
| 96 | // FIXME: If "omit" is passed, these below end up in; |
| 97 | // "Dynamic test case error: Performing a valueof or send operation on a non-specific template of type @SIPmsg_Types.GenericParam" |
| 98 | f_ts_Param_omit("cnonce", f_sip_str_quote(cnonce)), |
| 99 | f_ts_Param_omit("nc", nc) |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | template (value) Credentials ts_Credentials_OtherAuth(template (value) OtherAuth otherResponse) := { |
| 104 | otherResponse := otherResponse |
| 105 | } |
| 106 | |
| 107 | template (value) Authorization ts_Authorization(template (value) Credentials body) := { |
| 108 | fieldName := AUTHORIZATION_E, |
| 109 | body := body |
| 110 | } |
| 111 | |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 112 | // [20.10] |
| 113 | template (present) NameAddr tr_NameAddr(template (present) SipUrl addrSpec := ?, |
| 114 | template charstring displayName := *) := { |
| 115 | displayName := displayName, |
| 116 | addrSpec := addrSpec |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 117 | } |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 118 | template (value) NameAddr ts_NameAddr(template (value) SipUrl addrSpec, |
| 119 | template (omit) charstring displayName := omit) := { |
| 120 | displayName := displayName, |
| 121 | addrSpec := addrSpec |
| 122 | } |
| 123 | |
| 124 | template (present) Addr_Union tr_Addr_Union_NameAddr(template (present) NameAddr nameAddr := ?) := { |
| 125 | nameAddr := nameAddr |
| 126 | } |
| 127 | template (value) Addr_Union ts_Addr_Union_NameAddr(template (value) NameAddr nameAddr) := { |
| 128 | nameAddr := nameAddr |
| 129 | } |
| 130 | |
| 131 | template (present) Addr_Union tr_Addr_Union_SipUrl(template (present) SipUrl sipUrl := ?) := { |
| 132 | addrSpecUnion := sipUrl |
| 133 | } |
| 134 | template (value) Addr_Union ts_Addr_Union_SipUrl(template (value) SipUrl sipUrl) := { |
| 135 | addrSpecUnion := sipUrl |
| 136 | } |
| 137 | |
| 138 | |
| 139 | template (present) ContactAddress tr_ContactAddress(template (present) Addr_Union addressField := ?, |
| 140 | template SemicolonParam_List contactParams := *) := { |
| 141 | addressField := addressField, |
| 142 | contactParams := contactParams |
| 143 | } |
| 144 | template (value) ContactAddress ts_ContactAddress(template (value) Addr_Union addressField, |
| 145 | template (omit) SemicolonParam_List contactParams := omit) := { |
| 146 | addressField := addressField, |
| 147 | contactParams := contactParams |
| 148 | } |
| 149 | |
| 150 | template (present) Contact tr_Contact(template (present) ContactAddress_List contactAddresses := ?) := { |
| 151 | fieldName := CONTACT_E, |
| 152 | contactBody := { |
| 153 | contactAddresses := contactAddresses |
| 154 | } |
| 155 | } |
| 156 | template (value) Contact ts_Contact(template (value) ContactAddress_List contactAddresses) := { |
| 157 | fieldName := CONTACT_E, |
| 158 | contactBody := { |
| 159 | contactAddresses := contactAddresses |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | template (value) Contact ts_ContactWildcard := { |
| 164 | fieldName := CONTACT_E, |
| 165 | contactBody := { |
| 166 | wildcard := "*" |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | template (present) Contact tr_Contact_SipAddr(template (present) SipAddr contact_addr := ?) |
| 171 | := tr_Contact({ tr_ContactAddress(contact_addr.addr, contact_addr.params) }); |
| 172 | |
| 173 | private function f_tr_Contact_SipAddr(template SipAddr contact_addr) return template Contact |
| 174 | { |
| 175 | if (istemplatekind(contact_addr, "omit")) { |
| 176 | return omit; |
| 177 | } else if (istemplatekind(contact_addr, "*")) { |
| 178 | return *; |
| 179 | } |
| 180 | return tr_Contact_SipAddr(contact_addr); |
| 181 | } |
| 182 | |
| 183 | template (value) Contact ts_Contact_SipAddr(template (value) SipAddr contact_addr) |
| 184 | := ts_Contact({ ts_ContactAddress(contact_addr.addr, contact_addr.params) }); |
| 185 | private function ts_Contact_SipAddr_omit(template (omit) SipAddr contact_addr := omit) return template (omit) Contact |
| 186 | { |
| 187 | if (istemplatekind(contact_addr, "omit")) { |
| 188 | return omit; |
| 189 | } |
| 190 | return ts_Contact_SipAddr(contact_addr); |
| 191 | } |
| 192 | |
| 193 | |
| 194 | // [20.19] |
| 195 | template (value) Expires ts_Expires(template (value) DeltaSec deltaSec := "7200") := { |
| 196 | fieldName := EXPIRES_E, |
| 197 | deltaSec := deltaSec |
| 198 | } |
| 199 | |
| 200 | template (value) SipAddr ts_SipAddr(template (value) HostPort host_port, |
| 201 | template (omit) UserInfo user_info := omit, |
| 202 | template (omit) charstring displayName := omit, |
| 203 | template (omit) SemicolonParam_List params := omit) := { |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 204 | addr := { |
| 205 | nameAddr := { |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 206 | displayName := displayName, |
| 207 | addrSpec := ts_SipUrl(host_port, user_info) |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 208 | } |
| 209 | }, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 210 | params := params |
| 211 | } |
| 212 | template (present) SipAddr tr_SipAddr(template (present) HostPort host_port := ?, |
| 213 | template UserInfo user_info := *, |
| 214 | template charstring displayName := *, |
| 215 | template SemicolonParam_List params := *) := { |
| 216 | addr := { |
| 217 | nameAddr := { |
| 218 | displayName := displayName, |
| 219 | addrSpec := tr_SipUrl(host_port, user_info) |
| 220 | } |
| 221 | }, |
| 222 | params := params |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | /* build a receive template from a value: substitute '*' for omit */ |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 226 | function tr_SipUrl_from_val(template (value) SipUrl tin) return template (present) SipUrl { |
| 227 | var template (present) SipUrl ret := tin; |
| 228 | |
| 229 | /* if the port number is 5060, it may be omitted */ |
| 230 | if (ispresent(tin.hostPort.portField) and |
| 231 | valueof(tin.hostPort.portField) == 5060) { |
| 232 | ret.hostPort.portField := 5060 ifpresent; |
| 233 | } |
| 234 | if (not ispresent(tin.userInfo.password)) { |
| 235 | ret.userInfo.password := *; |
| 236 | } |
| 237 | |
| 238 | return ret; |
| 239 | } |
| 240 | function tr_SipAddr_from_val(template (value) SipAddr tin) return template (present) SipAddr { |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 241 | var template (present) SipAddr ret := tin; |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 242 | |
| 243 | if (not ispresent(tin.addr.nameAddr.displayName)) { |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 244 | ret.addr.nameAddr.displayName := *; |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 245 | } else if (f_str_tolower(f_sip_str_unquote(tin.addr.nameAddr.displayName)) == "anonymous") { |
| 246 | /* if the user is Anonymous, it may be omitted */ |
| 247 | ret.addr.nameAddr.displayName := tin.addr.nameAddr.displayName ifpresent; |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 248 | } |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 249 | |
| 250 | ret.addr.nameAddr.addrSpec := tr_SipUrl_from_val(tin.addr.nameAddr.addrSpec); |
| 251 | |
| 252 | if (not ispresent(tin.params)) { |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 253 | ret.params := *; |
| 254 | } |
| 255 | return ret; |
| 256 | } |
| 257 | |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 258 | function ts_SipAddr_from_Addr_Union(template (value) Addr_Union au, |
| 259 | template (omit) SemicolonParam_List params := omit) |
| 260 | return template (value) SipAddr { |
| 261 | var template (value) SipUrl addrSpec := ts_SipUrl_from_Addr_Union(au); |
| 262 | var template (omit) charstring displayName; |
| 263 | |
| 264 | if (ischosen(au.nameAddr)) { |
| 265 | displayName := au.nameAddr.displayName; |
| 266 | } else { /* au.addrSpecUnion */ |
| 267 | displayName := omit |
| 268 | } |
| 269 | |
| 270 | return ts_SipAddr(addrSpec.hostPort, |
| 271 | addrSpec.userInfo, |
| 272 | displayName, |
| 273 | params); |
| 274 | } |
| 275 | |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 276 | template (value) HostPort ts_HostPort(template (omit) charstring host := omit, |
| 277 | template (omit) integer portField := omit) := { |
| 278 | host := host, |
| 279 | portField := portField |
| 280 | } |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 281 | |
| 282 | template (present) HostPort tr_HostPort(template charstring host := *, |
| 283 | template integer portField := *) := { |
| 284 | host := host, |
| 285 | portField := portField |
| 286 | } |
| 287 | function f_tr_HostPort(template charstring host := *, |
| 288 | template integer portField := *) |
| 289 | return template (present) HostPort { |
| 290 | return f_tr_HostPort_opt_defport(tr_HostPort(host, portField)); |
| 291 | } |
| 292 | function f_tr_HostPort_opt_defport(template (present) HostPort hp) return template (present) HostPort { |
| 293 | var template (present) HostPort hpout := hp; |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 294 | /* if the port number is 5060, it may be omitted */ |
| 295 | if (isvalue(hp.portField) and valueof(hp.portField) == 5060) { |
| 296 | hpout.portField := 5060 ifpresent; |
| 297 | } |
| 298 | return hpout; |
| 299 | } |
| 300 | |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 301 | function f_tr_SipUrl_opt_defport(template (present) SipUrl url) return template (present) SipUrl { |
| 302 | var template (present) SipUrl urlout := url; |
| 303 | urlout.hostPort := f_tr_HostPort_opt_defport(url.hostPort); |
| 304 | return urlout; |
| 305 | } |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 306 | |
| 307 | template (value) UserInfo ts_UserInfo(template (value) charstring userOrTelephoneSubscriber, |
| 308 | template (omit) charstring password := omit) := { |
| 309 | userOrTelephoneSubscriber := userOrTelephoneSubscriber, |
| 310 | password := password |
| 311 | } |
| 312 | template (present) UserInfo tr_UserInfo(template (present) charstring userOrTelephoneSubscriber := ?, |
| 313 | template charstring password := *) := { |
| 314 | userOrTelephoneSubscriber := userOrTelephoneSubscriber, |
| 315 | password := password |
| 316 | } |
| 317 | |
| 318 | template (value) RequestLine ts_SIP_ReqLine(Method method, |
| 319 | template (value) SipUrl uri, |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 320 | charstring ver := c_SIP_VERSION) := { |
| 321 | method := method, |
| 322 | requestUri := uri, |
| 323 | sipVersion := ver |
| 324 | } |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 325 | template (present) RequestLine tr_SIP_ReqLine(template (present) Method method := ?, |
| 326 | template (present) SipUrl uri := ?, |
| 327 | template (present) charstring ver := c_SIP_VERSION) := { |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 328 | method := method, |
| 329 | requestUri := uri, |
| 330 | sipVersion := ver |
| 331 | } |
| 332 | |
| 333 | template (value) StatusLine ts_SIP_StatusLine(integer status_code, charstring reason) := { |
| 334 | sipVersion := "SIP/2.0", |
| 335 | statusCode := status_code, |
| 336 | reasonPhrase := reason |
| 337 | } |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 338 | template (present) StatusLine tr_SIP_StatusLine(template integer status_code, |
| 339 | template charstring reason) := { |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 340 | sipVersion := "SIP/2.0", |
| 341 | statusCode := status_code, |
| 342 | reasonPhrase := reason |
| 343 | } |
| 344 | |
| 345 | |
| 346 | template (value) PDU_SIP_Request ts_SIP_req(template (value) RequestLine rl) := { |
| 347 | requestLine := rl, |
| 348 | msgHeader := c_SIP_msgHeader_empty, |
| 349 | messageBody := omit, |
| 350 | payload := omit |
| 351 | } |
| 352 | |
| 353 | const Method_List c_SIP_defaultMethods := { |
| 354 | "INVITE", "ACK", "BYE", "CANCEL", "OPTIONS", "PRACK", "MESSAGE", "SUBSCRIBE", |
| 355 | "NOTIFY", "REFER", "UPDATE" }; |
| 356 | |
| 357 | private function f_ContentTypeOrOmit(template (omit) ContentType ct, template (omit) charstring body) |
| 358 | return template (omit) ContentType { |
| 359 | /* if user explicitly stated no content type */ |
| 360 | if (istemplatekind(ct, "omit")) { |
| 361 | return omit; |
| 362 | } |
| 363 | /* if there's no body, then there's no content-type either */ |
| 364 | if (istemplatekind(body, "omit")) { |
| 365 | return omit; |
| 366 | } |
| 367 | return ct; |
| 368 | } |
| 369 | |
| 370 | template (value) ContentType ts_CT_SDP := { |
| 371 | fieldName := CONTENT_TYPE_E, |
| 372 | mediaType := "application/sdp" |
| 373 | }; |
| 374 | |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 375 | template (value) Via ts_Via_from(template (value) HostPort addr) := { |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 376 | fieldName := VIA_E, |
| 377 | viaBody := { |
| 378 | { |
| 379 | sentProtocol := { "SIP", "2.0", "UDP" }, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 380 | sentBy := addr, |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 381 | viaParams := omit |
| 382 | } |
| 383 | } |
| 384 | } |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 385 | template (present) Via tr_Via_from(template (present) HostPort host_port := ?, |
| 386 | template SemicolonParam_List viaParams := *) := { |
| 387 | fieldName := VIA_E, |
| 388 | viaBody := { |
| 389 | { |
| 390 | sentProtocol := { "SIP", "2.0", "UDP" }, |
| 391 | sentBy := host_port, |
| 392 | viaParams := viaParams |
| 393 | } |
| 394 | } |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | template (present) OtherAuth |
| 398 | tr_OtherAuth(template (present) charstring authScheme := ?, |
| 399 | template (present) CommaParam_List authParams := ?) := { |
| 400 | authScheme := authScheme, |
| 401 | authParams := authParams |
| 402 | } |
| 403 | |
| 404 | template (value) OtherAuth |
| 405 | ts_OtherAuth(template (value) charstring authScheme, |
| 406 | template (value) CommaParam_List authParams) := { |
| 407 | authScheme := authScheme, |
| 408 | authParams := authParams |
| 409 | } |
| 410 | |
| 411 | template (present) Challenge |
| 412 | tr_Challenge_digestCln(template (present) CommaParam_List digestCln := ?) := { |
| 413 | digestCln := digestCln |
| 414 | } |
| 415 | |
| 416 | template (value) Challenge |
| 417 | ts_Challenge_digestCln(template (value) CommaParam_List digestCln) := { |
| 418 | digestCln := digestCln |
| 419 | } |
| 420 | |
| 421 | template (present) Challenge |
| 422 | tr_Challenge_otherChallenge(template (present) OtherAuth otherChallenge := ?) := { |
| 423 | otherChallenge := otherChallenge |
| 424 | } |
| 425 | |
| 426 | template (value) Challenge |
| 427 | ts_Challenge_otherChallenge(template (value) OtherAuth otherChallenge) := { |
| 428 | otherChallenge := otherChallenge |
| 429 | } |
| 430 | |
| 431 | template (present) WwwAuthenticate |
| 432 | tr_WwwAuthenticate(template (present) Challenge_list challenge := ?) := { |
| 433 | fieldName := WWW_AUTHENTICATE_E, |
| 434 | challenge := challenge |
| 435 | } |
| 436 | |
| 437 | template (value) WwwAuthenticate |
| 438 | ts_WwwAuthenticate(template (value) Challenge_list challenge) := { |
| 439 | fieldName := WWW_AUTHENTICATE_E, |
| 440 | challenge := challenge |
| 441 | } |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 442 | |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 443 | template (value) MessageHeader ts_SIP_msgHeader_empty := c_SIP_msgHeader_empty; |
| 444 | template (value) MessageHeader |
| 445 | ts_SIP_msgh_std(template (value) CallidString call_id, |
| 446 | template (value) SipAddr from_addr, |
| 447 | template (value) SipAddr to_addr, |
| 448 | template (omit) Contact contact, |
| 449 | template (value) charstring method, |
| 450 | template (value) integer seq_nr, |
| 451 | template (value) Via via, |
| 452 | template (omit) ContentType content_type := omit, |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 453 | template (omit)Authorization authorization := omit, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 454 | template (value) Method_List allow_methods := c_SIP_defaultMethods, |
| 455 | template (omit) Expires expires := omit |
| 456 | ) modifies ts_SIP_msgHeader_empty := { |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 457 | allow := { |
| 458 | fieldName := ALLOW_E, |
| 459 | methods := allow_methods |
| 460 | }, |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 461 | authorization := authorization, |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 462 | callId := { |
| 463 | fieldName := CALL_ID_E, |
| 464 | callid := call_id |
| 465 | }, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 466 | contact := contact, |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 467 | contentType := content_type, |
| 468 | cSeq := { |
| 469 | fieldName := CSEQ_E, |
| 470 | seqNumber := seq_nr, |
| 471 | method := method |
| 472 | }, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 473 | expires := expires, |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 474 | fromField := { |
| 475 | fieldName := FROM_E, |
| 476 | addressField := from_addr.addr, |
| 477 | fromParams := from_addr.params |
| 478 | }, |
| 479 | toField := { |
| 480 | fieldName := TO_E, |
| 481 | addressField := to_addr.addr, |
| 482 | toParams := to_addr.params |
| 483 | }, |
| 484 | userAgent := { |
| 485 | fieldName := USER_AGENT_E, |
| 486 | userAgentBody := { |
| 487 | "osmo-ttcn3-hacks/0.23" |
| 488 | } |
| 489 | }, |
| 490 | via := via |
| 491 | } |
| 492 | |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 493 | function tr_AllowMethods(template Method_List allow_methods) return template Allow { |
| 494 | if (istemplatekind(allow_methods, "omit")) { |
| 495 | return omit; |
| 496 | } else if (istemplatekind(allow_methods, "*")) { |
| 497 | return *; |
| 498 | } else if (istemplatekind(allow_methods, "?")) { |
| 499 | return ?; |
| 500 | } |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 501 | var template (present) Allow ret := { |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 502 | fieldName := ALLOW_E, |
| 503 | methods := allow_methods |
| 504 | } |
| 505 | return ret |
| 506 | } |
| 507 | |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 508 | template (present) MessageHeader |
| 509 | tr_SIP_msgh_std(template CallidString call_id, |
| 510 | template SipAddr from_addr, |
| 511 | template SipAddr to_addr, |
| 512 | template Contact contact, |
| 513 | template (present) Via via := tr_Via_from(?), |
| 514 | template charstring method, |
| 515 | template ContentType content_type := *, |
| 516 | template integer seq_nr := ?, |
| 517 | template Method_List allow_methods := *, |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 518 | template Expires expires := *, |
| 519 | template WwwAuthenticate wwwAuthenticate := * |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 520 | ) modifies t_SIP_msgHeader_any := { |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 521 | allow := tr_AllowMethods(allow_methods), |
| 522 | callId := { |
| 523 | fieldName := CALL_ID_E, |
| 524 | callid := call_id |
| 525 | }, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 526 | contact := contact, |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 527 | contentType := content_type, |
| 528 | cSeq := { |
| 529 | fieldName := CSEQ_E, |
| 530 | seqNumber := seq_nr, |
| 531 | method := method |
| 532 | }, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 533 | expires := expires, |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 534 | fromField := { |
| 535 | fieldName := FROM_E, |
| 536 | addressField := from_addr.addr, |
| 537 | fromParams := from_addr.params |
| 538 | }, |
| 539 | toField := { |
| 540 | fieldName := TO_E, |
| 541 | addressField := to_addr.addr, |
| 542 | toParams := to_addr.params |
| 543 | }, |
| 544 | userAgent := *, |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 545 | via := via, |
| 546 | wwwAuthenticate := wwwAuthenticate |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 550 | template (value) PDU_SIP_Request |
| 551 | ts_SIP_REGISTER(template (value) SipUrl sip_url_host_port, |
| 552 | template (value) CallidString call_id, |
| 553 | template (value) SipAddr from_addr, |
| 554 | template (value) SipAddr to_addr, |
| 555 | template (value) Via via, |
| 556 | integer seq_nr, |
| 557 | template (omit) Contact contact, |
| 558 | template (omit) Expires expires, |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 559 | template (omit) Authorization authorization := omit, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 560 | template (omit) charstring body := omit) := { |
| 561 | requestLine := ts_SIP_ReqLine(REGISTER_E, sip_url_host_port), |
| 562 | msgHeader := ts_SIP_msgh_std(call_id, from_addr, to_addr, contact, |
| 563 | "REGISTER", seq_nr, via, |
| 564 | f_ContentTypeOrOmit(ts_CT_SDP, body), |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 565 | authorization := authorization, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 566 | expires := expires), |
| 567 | messageBody := body, |
| 568 | payload := omit |
| 569 | } |
| 570 | template (present) PDU_SIP_Request |
| 571 | tr_SIP_REGISTER(template (present) SipUrl sip_url_host_port := ?, |
| 572 | template (present) CallidString call_id := ?, |
| 573 | template (present) SipAddr from_addr := ?, |
| 574 | template (present) SipAddr to_addr := ?, |
| 575 | template integer seq_nr := *, |
| 576 | template Contact contact := *, |
| 577 | template Expires expires := *, |
| 578 | template charstring body := *) := { |
| 579 | requestLine := tr_SIP_ReqLine(REGISTER_E, sip_url_host_port), |
| 580 | msgHeader := tr_SIP_msgh_std(call_id, from_addr, to_addr, contact, |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 581 | tr_Via_from(f_tr_HostPort_opt_defport(from_addr.addr.nameAddr.addrSpec.hostPort)), |
Pau Espin Pedrol | 65dde83 | 2024-04-08 18:15:58 +0200 | [diff] [blame] | 582 | "REGISTER", *, seq_nr, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 583 | expires := expires), |
| 584 | messageBody := body, |
| 585 | payload := omit |
| 586 | } |
| 587 | |
| 588 | template (value) PDU_SIP_Request |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 589 | ts_SIP_INVITE(template (value) CallidString call_id, |
| 590 | template (value) SipAddr from_addr, |
| 591 | template (value) SipAddr to_addr, |
| 592 | template (value) Via via, |
| 593 | template (value) Contact contact, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 594 | integer seq_nr, |
| 595 | template (omit) charstring body := omit) := { |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 596 | requestLine := ts_SIP_ReqLine(INVITE_E, to_addr.addr.nameAddr.addrSpec), |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 597 | msgHeader := ts_SIP_msgh_std(call_id, from_addr, to_addr, contact, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 598 | "INVITE", seq_nr, |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 599 | via, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 600 | f_ContentTypeOrOmit(ts_CT_SDP, body)), |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 601 | messageBody := body, |
| 602 | payload := omit |
| 603 | } |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 604 | template (present) PDU_SIP_Request |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 605 | tr_SIP_INVITE(template (present) SipUrl uri, |
| 606 | template CallidString call_id, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 607 | template SipAddr from_addr, |
| 608 | template SipAddr to_addr, |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 609 | template Via via := tr_Via_from(f_tr_HostPort_opt_defport(?)), |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 610 | template integer seq_nr, |
| 611 | template charstring body) := { |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 612 | requestLine := tr_SIP_ReqLine(INVITE_E, uri), |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 613 | msgHeader := tr_SIP_msgh_std(call_id, from_addr, to_addr, ?, |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 614 | via, "INVITE", *, seq_nr), |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 615 | messageBody := body, |
| 616 | payload := omit |
| 617 | } |
| 618 | |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 619 | template (value) PDU_SIP_Request |
| 620 | ts_SIP_BYE(CallidString call_id, |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 621 | template (value) SipAddr from_addr, |
| 622 | template (value) SipAddr to_addr, |
| 623 | template (value) Via via, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 624 | integer seq_nr, |
| 625 | template (omit) charstring body) := { |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 626 | requestLine := ts_SIP_ReqLine(BYE_E, to_addr.addr.nameAddr.addrSpec), |
| 627 | msgHeader := ts_SIP_msgh_std(call_id, from_addr, to_addr, omit, "BYE", seq_nr, |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 628 | via, f_ContentTypeOrOmit(ts_CT_SDP, body)), |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 629 | messageBody := body, |
| 630 | payload := omit |
| 631 | } |
| 632 | |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 633 | template (present) PDU_SIP_Request |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 634 | tr_SIP_BYE(template (present) SipUrl uri, |
| 635 | template CallidString call_id, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 636 | template SipAddr from_addr, |
| 637 | template SipAddr to_addr, |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 638 | template Via via, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 639 | template integer seq_nr, |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 640 | template charstring body := *) := { |
| 641 | requestLine := tr_SIP_ReqLine(BYE_E, uri), |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 642 | msgHeader := tr_SIP_msgh_std(call_id, from_addr, to_addr, omit, |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 643 | via, "BYE", *, seq_nr), |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 644 | messageBody := body, |
| 645 | payload := omit |
| 646 | } |
| 647 | |
| 648 | |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 649 | template (value) PDU_SIP_Request |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 650 | ts_SIP_ACK(template (value) CallidString call_id, |
| 651 | template (value) SipAddr from_addr, |
| 652 | template (value) SipAddr to_addr, |
| 653 | template (value) Via via, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 654 | integer seq_nr, |
| 655 | template (omit) charstring body) := { |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 656 | requestLine := ts_SIP_ReqLine(ACK_E, to_addr.addr.nameAddr.addrSpec), |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 657 | msgHeader := ts_SIP_msgh_std(call_id, from_addr, to_addr, |
| 658 | ts_Contact_SipAddr(from_addr), |
| 659 | "ACK", seq_nr, |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 660 | via, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 661 | f_ContentTypeOrOmit(ts_CT_SDP, body)), |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 662 | messageBody := body, |
| 663 | payload := omit |
| 664 | } |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 665 | template (present) PDU_SIP_Request |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 666 | tr_SIP_ACK(template (present) SipUrl uri, |
| 667 | template CallidString call_id, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 668 | template SipAddr from_addr, |
| 669 | template SipAddr to_addr, |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 670 | template Via via, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 671 | template integer seq_nr, |
| 672 | template charstring body) := { |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 673 | requestLine := tr_SIP_ReqLine(ACK_E, uri), |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 674 | msgHeader := tr_SIP_msgh_std(call_id, from_addr, to_addr, *, |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 675 | via, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 676 | "ACK", *, seq_nr), |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 677 | messageBody := body, |
| 678 | payload := omit |
| 679 | } |
| 680 | |
Pau Espin Pedrol | 32167d8 | 2024-04-10 13:14:51 +0200 | [diff] [blame] | 681 | template (present) PDU_SIP_Request |
| 682 | tr_SIP_CANCEL(template (present) SipUrl uri, |
| 683 | template (present) CallidString call_id, |
| 684 | template (present) SipAddr from_addr, |
| 685 | template (present) SipAddr to_addr, |
| 686 | template (present) Via via, |
| 687 | template (present) integer seq_nr, |
| 688 | template charstring body := *) := { |
| 689 | requestLine := tr_SIP_ReqLine(CANCEL_E, uri), |
| 690 | msgHeader := tr_SIP_msgh_std(call_id, from_addr, to_addr, *, |
| 691 | via, |
| 692 | "CANCEL", *, seq_nr), |
| 693 | messageBody := body, |
| 694 | payload := omit |
| 695 | } |
| 696 | |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 697 | template (value) PDU_SIP_Response |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 698 | ts_SIP_Response(template (value) CallidString call_id, |
| 699 | template (value) SipAddr from_addr, |
| 700 | template (value) SipAddr to_addr, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 701 | charstring method, |
| 702 | integer status_code, |
| 703 | integer seq_nr, |
| 704 | charstring reason, |
| 705 | Via via, |
| 706 | template (omit) charstring body := omit) := { |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 707 | statusLine := ts_SIP_StatusLine(status_code, reason), |
| 708 | msgHeader := ts_SIP_msgh_std(call_id, from_addr, to_addr, omit, method, seq_nr, |
| 709 | via, f_ContentTypeOrOmit(ts_CT_SDP, body)), |
| 710 | messageBody := body, |
| 711 | payload := omit |
| 712 | } |
| 713 | |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 714 | /* 180 Ringing */ |
| 715 | template (value) PDU_SIP_Response |
| 716 | ts_SIP_Response_Ringing( |
| 717 | template (value) CallidString call_id, |
| 718 | template (value) SipAddr from_addr, |
| 719 | template (value) SipAddr to_addr, |
| 720 | Via via, |
| 721 | integer seq_nr, |
| 722 | charstring method := "INVITE", |
| 723 | template (omit) charstring body := omit) := { |
| 724 | statusLine := ts_SIP_StatusLine(180, "Ringing"), |
| 725 | msgHeader := ts_SIP_msgh_std(call_id, from_addr, to_addr, omit, method, seq_nr, |
| 726 | via, f_ContentTypeOrOmit(ts_CT_SDP, body)), |
| 727 | messageBody := body, |
| 728 | payload := omit |
| 729 | } |
| 730 | |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 731 | template (present) PDU_SIP_Response |
| 732 | tr_SIP_Response(template CallidString call_id, |
| 733 | template SipAddr from_addr, |
| 734 | template SipAddr to_addr, |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 735 | template (present) Via via := tr_Via_from(?), |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 736 | template Contact contact, |
| 737 | template charstring method, |
| 738 | template integer status_code, |
| 739 | template integer seq_nr := ?, |
| 740 | template charstring reason := ?, |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 741 | template charstring body := *) := { |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 742 | statusLine := tr_SIP_StatusLine(status_code, reason), |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 743 | msgHeader := tr_SIP_msgh_std(call_id, from_addr, to_addr, contact, |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 744 | via, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 745 | method, *, seq_nr), |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 746 | messageBody := body, |
| 747 | payload := omit |
| 748 | } |
| 749 | |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 750 | /* Expect during first REGISTER/INVITE/... when authorization is required: */ |
Pau Espin Pedrol | 37ee0ed | 2024-03-28 21:17:12 +0100 | [diff] [blame] | 751 | template (present) PDU_SIP_Response |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 752 | tr_SIP_Response_Unauthorized( |
Pau Espin Pedrol | 37ee0ed | 2024-03-28 21:17:12 +0100 | [diff] [blame] | 753 | template CallidString call_id, |
| 754 | template SipAddr from_addr, |
| 755 | template SipAddr to_addr, |
| 756 | template (present) Via via := tr_Via_from(?), |
| 757 | template Contact contact := *, |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 758 | template (present) WwwAuthenticate wwwAuthenticate := ?, |
Pau Espin Pedrol | 37ee0ed | 2024-03-28 21:17:12 +0100 | [diff] [blame] | 759 | template integer seq_nr := ?, |
| 760 | template charstring method := "REGISTER", |
| 761 | template integer status_code := 401, |
| 762 | template charstring reason := "Unauthorized", |
| 763 | template charstring body := *) := { |
| 764 | statusLine := tr_SIP_StatusLine(status_code, reason), |
| 765 | msgHeader := tr_SIP_msgh_std(call_id, from_addr, to_addr, contact, |
| 766 | via, |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 767 | method, *, seq_nr, |
| 768 | wwwAuthenticate := wwwAuthenticate), |
Pau Espin Pedrol | 37ee0ed | 2024-03-28 21:17:12 +0100 | [diff] [blame] | 769 | messageBody := body, |
| 770 | payload := omit |
| 771 | } |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 772 | |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 773 | /* 100 Trying */ |
| 774 | template (present) PDU_SIP_Response |
| 775 | tr_SIP_Response_Trying( |
| 776 | template CallidString call_id, |
| 777 | template SipAddr from_addr, |
| 778 | template SipAddr to_addr, |
| 779 | template (present) Via via := tr_Via_from(?), |
| 780 | template integer seq_nr := ?, |
| 781 | template charstring method := "INVITE", |
| 782 | template integer status_code := 100, |
| 783 | template charstring reason := "Trying", |
| 784 | template charstring body := *) := { |
| 785 | statusLine := tr_SIP_StatusLine(status_code, reason), |
| 786 | msgHeader := tr_SIP_msgh_std(call_id, from_addr, to_addr, omit, |
| 787 | via, |
| 788 | method, *, seq_nr), |
| 789 | messageBody := body, |
| 790 | payload := omit |
| 791 | } |
| 792 | |
| 793 | /* 180 Ringing */ |
| 794 | template (present) PDU_SIP_Response |
| 795 | tr_SIP_Response_Ringing( |
| 796 | template CallidString call_id, |
| 797 | template SipAddr from_addr, |
| 798 | template SipAddr to_addr, |
| 799 | template (present) Via via := tr_Via_from(?), |
| 800 | template integer seq_nr := ?, |
| 801 | template charstring method := "INVITE", |
| 802 | template integer status_code := 180, |
| 803 | template charstring reason := "Ringing", |
| 804 | template charstring body := *) := { |
| 805 | statusLine := tr_SIP_StatusLine(status_code, reason), |
| 806 | msgHeader := tr_SIP_msgh_std(call_id, from_addr, to_addr, *, |
| 807 | via, |
| 808 | method, *, seq_nr), |
| 809 | messageBody := body, |
| 810 | payload := omit |
| 811 | } |
| 812 | |
| 813 | /**************** |
| 814 | * FUNCTIONS: |
| 815 | ****************/ |
| 816 | |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 817 | function f_sip_param_find(GenericParam_List li, |
| 818 | template (present) charstring id := ?) |
| 819 | return template (omit) GenericParam { |
| 820 | var integer i; |
| 821 | |
| 822 | for (i := 0; i < lengthof(li); i := i + 1) { |
| 823 | if (not ispresent(li[i])) { |
| 824 | continue; |
| 825 | } |
| 826 | if (match(li[i].id, id)) { |
| 827 | return li[i]; |
| 828 | } |
| 829 | } |
| 830 | return omit; |
| 831 | } |
| 832 | |
| 833 | function f_sip_param_find_or_fail(GenericParam_List li, |
| 834 | template (present) charstring id := ?) |
| 835 | return GenericParam { |
| 836 | var template (omit) GenericParam parameter; |
| 837 | parameter := f_sip_param_find(li, id); |
| 838 | if (istemplatekind(parameter, "omit")) { |
| 839 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 840 | log2str("Param ", id, " not found in ", li)); |
| 841 | } |
| 842 | return valueof(parameter); |
| 843 | } |
| 844 | |
| 845 | function f_sip_param_get_value(GenericParam_List li, |
| 846 | template (present) charstring id := ?) |
| 847 | return template (omit) charstring { |
| 848 | var template (omit) GenericParam parameter; |
| 849 | parameter := f_sip_param_find(li, id); |
| 850 | if (istemplatekind(parameter, "omit")) { |
| 851 | return omit; |
| 852 | } |
| 853 | return parameter.paramValue; |
| 854 | } |
| 855 | |
| 856 | function f_sip_param_get_value_or_fail(GenericParam_List li, |
| 857 | template (present) charstring id := ?) |
| 858 | return template (omit) charstring { |
| 859 | var GenericParam parameter; |
| 860 | parameter := f_sip_param_find_or_fail(li, id); |
| 861 | return parameter.paramValue; |
| 862 | } |
| 863 | |
| 864 | function f_sip_param_get_value_present_or_fail(GenericParam_List li, |
| 865 | template (present) charstring id := ?) |
| 866 | return charstring { |
| 867 | var GenericParam parameter; |
| 868 | parameter := f_sip_param_find_or_fail(li, id); |
| 869 | if (not ispresent(parameter.paramValue)) { |
| 870 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 871 | log2str("Param ", id, " value not present in ", li)); |
| 872 | } |
| 873 | return parameter.paramValue; |
| 874 | } |
| 875 | |
| 876 | function f_sip_param_match_value(GenericParam_List li, |
| 877 | template (present) charstring id := ?, |
| 878 | template charstring exp_paramValue := *) |
| 879 | return boolean { |
| 880 | var template (omit) charstring val; |
| 881 | val := f_sip_param_get_value_or_fail(li, id); |
| 882 | if (istemplatekind(val, "omit")) { |
| 883 | return istemplatekind(val, "omit") or istemplatekind(val, "*"); |
| 884 | } |
| 885 | return match(valueof(val), exp_paramValue); |
| 886 | } |
| 887 | |
| 888 | function f_sip_param_match_value_or_fail(GenericParam_List li, |
| 889 | template (present) charstring id := ?, |
| 890 | template charstring exp_paramValue := *) |
| 891 | { |
| 892 | var template (omit) charstring val := f_sip_param_get_value_or_fail(li, id); |
| 893 | if (istemplatekind(val, "omit")) { |
| 894 | if (istemplatekind(val, "omit") or istemplatekind(val, "*")) { |
| 895 | return; |
| 896 | } else { |
| 897 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 898 | log2str("Param ", id, " match failed: val ", val, |
| 899 | " vs exp ", exp_paramValue)); |
| 900 | } |
| 901 | } |
| 902 | if (not match(valueof(val), exp_paramValue)) { |
| 903 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 904 | log2str("Param ", id, " match failed: val ", val, |
| 905 | " vs exp ", exp_paramValue)); |
| 906 | } |
| 907 | } |
| 908 | |
| 909 | function f_sip_param_remove(template (omit) GenericParam_List li_tpl, charstring id) |
| 910 | return GenericParam_List { |
| 911 | var integer i; |
| 912 | var GenericParam_List li; |
| 913 | var GenericParam_List new_li := {}; |
| 914 | |
| 915 | if (istemplatekind(li_tpl, "omit")) { |
| 916 | return {}; |
| 917 | } |
| 918 | |
| 919 | li := valueof(li_tpl); |
| 920 | for (i := 0; i < lengthof(li); i := i + 1) { |
| 921 | if (not ispresent(li[i]) or |
| 922 | not match(li[i].id, id)) { |
| 923 | new_li := new_li & {li[i]}; |
| 924 | } |
| 925 | } |
| 926 | return new_li; |
| 927 | } |
| 928 | |
| 929 | function f_sip_param_set(template (omit) GenericParam_List li_tpl, charstring id, charstring val) |
| 930 | return GenericParam_List { |
| 931 | var integer i; |
| 932 | var GenericParam_List li; |
| 933 | var GenericParam_List new_li := {}; |
| 934 | var boolean found := false; |
| 935 | |
| 936 | if (istemplatekind(li_tpl, "omit")) { |
| 937 | return { valueof(ts_Param(id, val)) }; |
| 938 | } |
| 939 | |
| 940 | li := valueof(li_tpl); |
| 941 | for (i := 0; i < lengthof(li); i := i + 1) { |
| 942 | if (not ispresent(li[i]) or |
| 943 | not match(li[i].id, id)) { |
| 944 | new_li := new_li & {li[i]}; |
| 945 | continue; |
| 946 | } |
| 947 | new_li := new_li & { valueof(ts_Param(li[i].id, val)) }; |
| 948 | found := true; |
| 949 | } |
| 950 | |
| 951 | if (not found) { |
| 952 | new_li := new_li & { valueof(ts_Param(id, val)) }; |
| 953 | } |
| 954 | return new_li; |
| 955 | } |
| 956 | |
| 957 | /* Make sure string is quoted. */ |
| 958 | function f_sip_str_quote(template (value) charstring val) return charstring { |
| 959 | var charstring str := valueof(val); |
| 960 | if (lengthof(str) == 0) { |
| 961 | return ""; |
| 962 | } |
| 963 | |
| 964 | if (str[0] != "\"") { |
| 965 | return "\"" & str & "\""; |
| 966 | } |
| 967 | return str; |
| 968 | } |
| 969 | |
| 970 | /* Make sure string is unquoted. |
| 971 | * Similar to unq() in RFC 2617 */ |
| 972 | function f_sip_str_unquote(template (value) charstring val) return charstring { |
| 973 | var charstring str := valueof(val); |
| 974 | var integer len := lengthof(str); |
| 975 | |
| 976 | if (len <= 1) { |
| 977 | return str; |
| 978 | } |
| 979 | |
| 980 | if (str[0] == "\"" and str[len - 1] == "\"") { |
| 981 | return substr(str, 1, len - 2); |
| 982 | } |
| 983 | return str; |
| 984 | } |
| 985 | |
| 986 | /* RFC 2617 3.2.2.2 A1 */ |
| 987 | function f_sip_digest_A1(charstring user, charstring realm, charstring password) return charstring { |
| 988 | |
| 989 | /* RFC 2617 3.2.2.2 A1 */ |
| 990 | var charstring A1 := f_sip_str_unquote(user) & ":" & |
| 991 | f_sip_str_unquote(realm) & ":" & |
| 992 | password; |
| 993 | var charstring digestA1 := f_str_tolower(f_calculateMD5(A1)); |
| 994 | log("A1: md5('", A1, "') = ", digestA1); |
| 995 | return digestA1; |
| 996 | } |
| 997 | |
| 998 | /* RFC 2617 3.2.2.2 A2 */ |
| 999 | function f_sip_digest_A2(charstring method, charstring uri) return charstring { |
| 1000 | |
| 1001 | var charstring A2 := method & ":" & uri |
| 1002 | var charstring digestA2 := f_str_tolower(f_calculateMD5(A2)); |
| 1003 | log("A2: md5('", A2, "') = ", digestA2); |
| 1004 | return digestA2; |
| 1005 | } |
| 1006 | |
| 1007 | /* RFC 2617 3.2.2.1 Request-Digest */ |
| 1008 | function f_sip_digest_RequestDigest(charstring digestA1, charstring nonce, |
| 1009 | charstring nc, charstring cnonce, |
| 1010 | charstring qop, charstring digestA2) return charstring { |
| 1011 | var charstring digest_data := f_sip_str_unquote(nonce) & ":" & |
| 1012 | nc & ":" & |
| 1013 | cnonce & ":" & |
| 1014 | f_sip_str_unquote(qop) & ":" & |
| 1015 | digestA2; |
| 1016 | var charstring req_digest := f_sip_digest_KD(digestA1, digest_data); |
| 1017 | log("Request-Digest: md5('", digestA1, ":", digest_data ,"') = ", req_digest); |
| 1018 | return req_digest; |
| 1019 | } |
| 1020 | |
| 1021 | /* RFC 2617 3.2.1 The WWW-Authenticate Response Header |
| 1022 | * KD(secret, data) = H(concat(secret, ":", data)) |
| 1023 | */ |
| 1024 | function f_sip_digest_KD(charstring secret, charstring data) return charstring { |
| 1025 | return f_str_tolower(f_calculateMD5(secret & ":" & data)); |
| 1026 | } |
| 1027 | |
| 1028 | /* Digest Auth: RFC 2617 */ |
| 1029 | function f_sip_digest_gen_Authorization(WwwAuthenticate www_authenticate, |
| 1030 | charstring user, charstring password, |
| 1031 | charstring method, charstring uri, |
| 1032 | charstring cnonce := "0a4f113b", integer nc_int := 1) return Authorization { |
| 1033 | var CommaParam_List digestCln; |
| 1034 | var template (value) Authorization authorization; |
| 1035 | var template (value) Credentials cred; |
| 1036 | var template (omit) GenericParam rx_param; |
| 1037 | |
| 1038 | digestCln := www_authenticate.challenge[0].digestCln; |
| 1039 | |
| 1040 | var charstring algorithm; |
| 1041 | rx_param := f_sip_param_find(digestCln, "algorithm"); |
| 1042 | if (istemplatekind(rx_param, "omit")) { |
| 1043 | /* Assume MD5 if not set */ |
| 1044 | algorithm := "MD5" |
| 1045 | } else { |
| 1046 | algorithm := valueof(rx_param.paramValue); |
| 1047 | if (f_strstr(algorithm, "MD5") == -1) { |
| 1048 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 1049 | log2str("Unexpected algorithm: ", algorithm)); |
| 1050 | } |
| 1051 | } |
| 1052 | |
| 1053 | var charstring realm := f_sip_param_get_value_present_or_fail(digestCln, "realm"); |
| 1054 | var charstring nonce := f_sip_param_get_value_present_or_fail(digestCln, "nonce"); |
| 1055 | var charstring opaque := f_sip_param_get_value_present_or_fail(digestCln, "opaque"); |
| 1056 | var charstring qop := f_sip_param_get_value_present_or_fail(digestCln, "qop"); |
| 1057 | |
| 1058 | if (f_strstr(qop, "auth") == -1) { |
| 1059 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected qop: ", qop)); |
| 1060 | } |
| 1061 | var charstring selected_qop := "auth"; |
| 1062 | |
| 1063 | /* RFC 2617 3.2.2.2 A1 */ |
| 1064 | var charstring digestA1 := f_sip_digest_A1(user, realm, password); |
| 1065 | /* RFC 2617 3.2.2.3 A2 */ |
| 1066 | var charstring digestA2 := f_sip_digest_A2(method, uri); |
| 1067 | |
| 1068 | /* RFC 2617 3.2.2.1 Request-Digest */ |
| 1069 | var charstring nc := f_str_tolower(hex2str(int2hex(nc_int, 8))); |
| 1070 | var charstring req_digest := f_sip_digest_RequestDigest(digestA1, nonce, |
| 1071 | nc, cnonce, |
| 1072 | selected_qop, digestA2); |
| 1073 | |
| 1074 | cred := ts_Credentials_DigestResponseMD5(user, realm, nonce, |
| 1075 | uri, req_digest, |
| 1076 | opaque, algorithm, selected_qop, cnonce, nc); |
| 1077 | |
| 1078 | authorization := ts_Authorization(cred); |
| 1079 | return valueof(authorization); |
| 1080 | } |
| 1081 | |
| 1082 | /* RFC 2617 3.5 Example */ |
| 1083 | function f_sip_digest_selftest() { |
| 1084 | /* |
| 1085 | The following example assumes that an access-protected document is |
| 1086 | being requested from the server via a GET request. The URI of the |
| 1087 | document is "http://www.nowhere.org/dir/index.html". Both client and |
| 1088 | server know that the username for this document is "Mufasa", and the |
| 1089 | password is "Circle Of Life" (with one space between each of the |
| 1090 | three words). |
| 1091 | |
| 1092 | HTTP/1.1 401 Unauthorized |
| 1093 | WWW-Authenticate: Digest |
| 1094 | realm="testrealm@host.com", |
| 1095 | qop="auth,auth-int", |
| 1096 | nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", |
| 1097 | opaque="5ccc069c403ebaf9f0171e9517f40e41" |
| 1098 | |
| 1099 | Authorization: Digest username="Mufasa", |
| 1100 | realm="testrealm@host.com", |
| 1101 | nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", |
| 1102 | uri="/dir/index.html", |
| 1103 | qop=auth, |
| 1104 | nc=00000001, |
| 1105 | cnonce="0a4f113b", |
| 1106 | response="6629fae49393a05397450978507c4ef1", |
| 1107 | opaque="5ccc069c403ebaf9f0171e9517f40e41" |
| 1108 | */ |
| 1109 | var template (value) CommaParam_List digestCln := { |
| 1110 | ts_Param("realm", f_sip_str_quote("testrealm@host.com")), |
| 1111 | ts_Param("qop", f_sip_str_quote("auth,auth-int")), |
| 1112 | ts_Param("nonce", f_sip_str_quote("dcd98b7102dd2f0e8b11d0f600bfb0c093")), |
| 1113 | ts_Param("opaque", f_sip_str_quote("5ccc069c403ebaf9f0171e9517f40e41")) |
| 1114 | }; |
| 1115 | var template (value) WwwAuthenticate www_authenticate := |
| 1116 | ts_WwwAuthenticate( { ts_Challenge_digestCln(digestCln) } ) |
| 1117 | |
| 1118 | var Authorization authorization := |
| 1119 | f_sip_digest_gen_Authorization(valueof(www_authenticate), |
| 1120 | "Mufasa", |
| 1121 | "Circle Of Life", |
| 1122 | "GET", |
| 1123 | "/dir/index.html", |
| 1124 | cnonce := "0a4f113b", |
| 1125 | nc_int := 1); |
| 1126 | |
| 1127 | var CommaParam_List digestResp := authorization.body.digestResponse; |
| 1128 | f_sip_param_match_value_or_fail(digestResp, "realm", f_sip_str_quote("testrealm@host.com")); |
| 1129 | f_sip_param_match_value_or_fail(digestResp, "nonce", f_sip_str_quote("dcd98b7102dd2f0e8b11d0f600bfb0c093")); |
| 1130 | f_sip_param_match_value_or_fail(digestResp, "uri", f_sip_str_quote("/dir/index.html")); |
| 1131 | f_sip_param_match_value_or_fail(digestResp, "qop", "auth"); |
| 1132 | f_sip_param_match_value_or_fail(digestResp, "nc", "00000001"); |
| 1133 | f_sip_param_match_value_or_fail(digestResp, "cnonce", f_sip_str_quote("0a4f113b")); |
| 1134 | f_sip_param_match_value_or_fail(digestResp, "response", f_sip_str_quote("6629fae49393a05397450978507c4ef1")); |
| 1135 | f_sip_param_match_value_or_fail(digestResp, "opaque", f_sip_str_quote("5ccc069c403ebaf9f0171e9517f40e41")); |
| 1136 | } |
| 1137 | |
Pau Espin Pedrol | 6052a34 | 2024-03-28 20:20:46 +0100 | [diff] [blame] | 1138 | /* RFC 3261 8.1.1.5: |
| 1139 | * "The sequence number value MUST be expressible as a 32-bit unsigned integer |
| 1140 | * and MUST be less than 2**31." |
| 1141 | */ |
| 1142 | function f_sip_rand_seq_nr() return integer { |
| 1143 | /* 2**31 = 2147483648 */ |
| 1144 | return f_rnd_int(2147483648) |
| 1145 | } |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 1146 | |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 1147 | function f_sip_next_seq_nr(integer seq_nr) return integer { |
| 1148 | return (seq_nr + 1) mod 2147483648; |
| 1149 | } |
| 1150 | |
| 1151 | function f_sip_Request_inc_seq_nr(inout template (value) PDU_SIP_Request req) { |
| 1152 | req.msgHeader.cSeq.seqNumber := f_sip_next_seq_nr(valueof(req.msgHeader.cSeq.seqNumber)); |
| 1153 | } |
| 1154 | |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 1155 | function f_sip_rand_tag() return charstring { |
Pau Espin Pedrol | 95ad6a0 | 2024-04-18 16:52:46 +0200 | [diff] [blame] | 1156 | /* Tags shall have at least 32 bit of randomness */ |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 1157 | var integer rnd_int := f_rnd_int(4294967296); |
Pau Espin Pedrol | 95ad6a0 | 2024-04-18 16:52:46 +0200 | [diff] [blame] | 1158 | /* Make collisions harder by appending time to the final string: */ |
| 1159 | var integer ts_int := f_time_ms() mod 4294967296; |
| 1160 | return hex2str(int2hex(rnd_int, 8)) & "-" & hex2str(int2hex(ts_int, 8)); |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 1161 | } |
| 1162 | |
| 1163 | /* Generate a "branch" tag value. |
| 1164 | * RFC 3261 p.105 section 8: |
| 1165 | * "A common way to create this value is to compute a |
| 1166 | * cryptographic hash of the To tag, From tag, Call-ID header |
| 1167 | * field, the Request-URI of the request received (before |
| 1168 | * translation), the topmost Via header, and the sequence number |
| 1169 | * from the CSeq header field, in addition to any Proxy-Require |
| 1170 | * and Proxy-Authorization header fields that may be present. The |
| 1171 | * algorithm used to compute the hash is implementation-dependent, |
| 1172 | * but MD5 (RFC 1321 [35]),expressed in hexadecimal, is a reasonable |
| 1173 | * choice." |
| 1174 | * See also Section 8.1.1.7: |
| 1175 | * "The branch ID inserted by an element compliant with this |
| 1176 | * specification MUST always begin with the characters "z9hG4bK"." |
| 1177 | */ |
| 1178 | const charstring sip_magic_cookie := "z9hG4bK"; |
| 1179 | function f_sip_gen_branch(charstring tag_to, |
| 1180 | charstring tag_from, |
| 1181 | charstring tag_call_id, |
| 1182 | integer cseq) return charstring { |
| 1183 | var charstring str := tag_to & tag_from & tag_call_id & int2str(cseq); |
| 1184 | var charstring hash := f_calculateMD5(str); |
| 1185 | var charstring branch := sip_magic_cookie & hash; |
| 1186 | return branch; |
| 1187 | } |
| 1188 | |
| 1189 | function f_sip_HostPort_to_str(HostPort host_port) return charstring { |
| 1190 | var charstring str := ""; |
| 1191 | if (ispresent(host_port.host)) { |
| 1192 | str := host_port.host; |
| 1193 | } |
| 1194 | if (ispresent(host_port.portField)) { |
| 1195 | str := str & ":" & int2str(host_port.portField); |
| 1196 | } |
| 1197 | return str; |
| 1198 | } |
| 1199 | |
| 1200 | function f_sip_SipUrl_to_str(SipUrl uri) return charstring { |
| 1201 | var charstring str := uri.scheme & f_sip_HostPort_to_str(uri.hostPort); |
| 1202 | return str; |
| 1203 | } |
| 1204 | |
| 1205 | function f_sip_NameAddr_to_str(NameAddr naddr) return charstring { |
| 1206 | if (ispresent(naddr.displayName)) { |
| 1207 | return naddr.displayName & " <" & f_sip_SipUrl_to_str(naddr.addrSpec) & ">"; |
| 1208 | } else { |
| 1209 | return f_sip_SipUrl_to_str(naddr.addrSpec); |
| 1210 | } |
| 1211 | } |
| 1212 | |
| 1213 | function f_sip_SipAddr_to_str(SipAddr sip_addr) return charstring { |
| 1214 | if (ischosen(sip_addr.addr.nameAddr)) { |
| 1215 | return f_sip_NameAddr_to_str(sip_addr.addr.nameAddr); |
| 1216 | } else { |
| 1217 | return f_sip_SipUrl_to_str(sip_addr.addr.addrSpecUnion); |
| 1218 | } |
| 1219 | } |
| 1220 | |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 1221 | } |