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