2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 2010, Digium, Inc.
6 * See http://www.asterisk.org for more information about
7 * the Asterisk project. Please do not directly contact
8 * any of the maintainers of this project for assistance;
9 * the project provides a web site, mailing lists and IRC
10 * channels for your use.
12 * This program is free software, distributed under the terms of
13 * the GNU General Public License Version 2. See the LICENSE file
14 * at the top of the source tree.
19 * \brief chan_sip header file
27 #include "asterisk/stringfields.h"
28 #include "asterisk/linkedlists.h"
29 #include "asterisk/strings.h"
30 #include "asterisk/tcptls.h"
31 #include "asterisk/test.h"
32 #include "asterisk/channel.h"
33 #include "asterisk/app.h"
34 #include "asterisk/astobj.h"
35 #include "asterisk/indications.h"
36 #include "asterisk/security_events.h"
37 #include "asterisk/features.h"
38 #include "asterisk/rtp_engine.h"
39 #include "asterisk/netsock2.h"
40 #include "asterisk/features_config.h"
52 /* Arguments for sip_find_peer */
53 #define FINDUSERS (1 << 0)
54 #define FINDPEERS (1 << 1)
55 #define FINDALLDEVICES (FINDUSERS | FINDPEERS)
57 #define SIPBUFSIZE 512 /*!< Buffer size for many operations */
61 #define SIP_RESERVED ";/?:@&=+$,# " /*!< Reserved characters in the username part of the URI */
63 #define DEFAULT_DEFAULT_EXPIRY 120
64 #define DEFAULT_MIN_EXPIRY 60
65 #define DEFAULT_MAX_EXPIRY 3600
66 #define DEFAULT_MWI_EXPIRY 3600
67 #define DEFAULT_REGISTRATION_TIMEOUT 20
68 #define DEFAULT_MAX_FORWARDS 70
70 #define DEFAULT_AUTHLIMIT 100
71 #define DEFAULT_AUTHTIMEOUT 30
73 /* guard limit must be larger than guard secs */
74 /* guard min must be < 1000, and should be >= 250 */
75 #define EXPIRY_GUARD_SECS 15 /*!< How long before expiry do we reregister */
76 #define EXPIRY_GUARD_LIMIT 30 /*!< Below here, we use EXPIRY_GUARD_PCT instead of EXPIRY_GUARD_SECS */
77 #define EXPIRY_GUARD_MIN 500 /*!< This is the minimum guard time applied. If
78 * GUARD_PCT turns out to be lower than this, it
79 * will use this time instead.
80 * This is in milliseconds.
82 #define EXPIRY_GUARD_PCT 0.20 /*!< Percentage of expires timeout to use when
83 * below EXPIRY_GUARD_LIMIT */
84 #define DEFAULT_EXPIRY 900 /*!< Expire slowly */
86 #define DEFAULT_QUALIFY_GAP 100
87 #define DEFAULT_QUALIFY_PEERS 1
89 #define CALLERID_UNKNOWN "Anonymous"
90 #define FROMDOMAIN_INVALID "anonymous.invalid"
92 #define DEFAULT_MAXMS 2000 /*!< Qualification: Must be faster than 2 seconds by default */
93 #define DEFAULT_QUALIFYFREQ 60 * 1000 /*!< Qualification: How often to check for the host to be up */
94 #define DEFAULT_FREQ_NOTOK 10 * 1000 /*!< Qualification: How often to check, if the host is down... */
96 #define DEFAULT_RETRANS 1000 /*!< How frequently to retransmit Default: 2 * 500 ms in RFC 3261 */
97 #define DEFAULT_TIMER_T1 500 /*!< SIP timer T1 (according to RFC 3261) */
98 #define SIP_TRANS_TIMEOUT 64 * DEFAULT_TIMER_T1 /*!< SIP request timeout (rfc 3261) 64*T1
99 * \todo Use known T1 for timeout (peerpoke)
101 #define DEFAULT_TRANS_TIMEOUT -1 /*!< Use default SIP transaction timeout */
102 #define PROVIS_KEEPALIVE_TIMEOUT 60000 /*!< How long to wait before retransmitting a provisional response (rfc 3261 13.3.1.1) */
103 #define MAX_AUTHTRIES 3 /*!< Try authentication three times, then fail */
105 #define SIP_MAX_HEADERS 64 /*!< Max amount of SIP headers to read */
106 #define SIP_MAX_LINES 256 /*!< Max amount of lines in SIP attachment (like SDP) */
107 #define SIP_MAX_PACKET_SIZE 20480 /*!< Max SIP packet size */
108 #define SIP_MIN_PACKET 4096 /*!< Initialize size of memory to allocate for packets */
109 #define MAX_HISTORY_ENTRIES 50 /*!< Max entires in the history list for a sip_pvt */
111 #define INITIAL_CSEQ 101 /*!< Our initial sip sequence number */
113 #define DEFAULT_MAX_SE 1800 /*!< Session-Timer Default Session-Expires period (RFC 4028) */
114 #define DEFAULT_MIN_SE 90 /*!< Session-Timer Default Min-SE period (RFC 4028) */
116 #define SDP_MAX_RTPMAP_CODECS 32 /*!< Maximum number of codecs allowed in received SDP */
121 #define DEC_CALL_LIMIT 0
122 #define INC_CALL_LIMIT 1
123 #define DEC_CALL_RINGING 2
124 #define INC_CALL_RINGING 3
126 /*! Define SIP option tags, used in Require: and Supported: headers
127 * We need to be aware of these properties in the phones to use
128 * the replace: header. We should not do that without knowing
129 * that the other end supports it...
130 * This is nothing we can configure, we learn by the dialog
131 * Supported: header on the REGISTER (peer) or the INVITE
133 * We are not using many of these today, but will in the future.
134 * This is documented in RFC 3261
137 #define NOT_SUPPORTED 0
140 #define SIP_OPT_REPLACES (1 << 0)
141 #define SIP_OPT_100REL (1 << 1)
142 #define SIP_OPT_TIMER (1 << 2)
143 #define SIP_OPT_EARLY_SESSION (1 << 3)
144 #define SIP_OPT_JOIN (1 << 4)
145 #define SIP_OPT_PATH (1 << 5)
146 #define SIP_OPT_PREF (1 << 6)
147 #define SIP_OPT_PRECONDITION (1 << 7)
148 #define SIP_OPT_PRIVACY (1 << 8)
149 #define SIP_OPT_SDP_ANAT (1 << 9)
150 #define SIP_OPT_SEC_AGREE (1 << 10)
151 #define SIP_OPT_EVENTLIST (1 << 11)
152 #define SIP_OPT_GRUU (1 << 12)
153 #define SIP_OPT_TARGET_DIALOG (1 << 13)
154 #define SIP_OPT_NOREFERSUB (1 << 14)
155 #define SIP_OPT_HISTINFO (1 << 15)
156 #define SIP_OPT_RESPRIORITY (1 << 16)
157 #define SIP_OPT_FROMCHANGE (1 << 17)
158 #define SIP_OPT_RECLISTINV (1 << 18)
159 #define SIP_OPT_RECLISTSUB (1 << 19)
160 #define SIP_OPT_OUTBOUND (1 << 20)
161 #define SIP_OPT_UNKNOWN (1 << 21)
163 /*! \brief SIP Methods we support
164 * \todo This string should be set dynamically. We only support REFER and SUBSCRIBE if we have
165 * allowsubscribe and allowrefer on in sip.conf.
167 #define ALLOWED_METHODS "INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE"
169 /*! \brief Standard SIP unsecure port for UDP and TCP from RFC 3261. DO NOT CHANGE THIS */
170 #define STANDARD_SIP_PORT 5060
171 /*! \brief Standard SIP TLS port from RFC 3261. DO NOT CHANGE THIS */
172 #define STANDARD_TLS_PORT 5061
174 /*! \note in many SIP headers, absence of a port number implies port 5060,
175 * and this is why we cannot change the above constant.
176 * There is a limited number of places in asterisk where we could,
177 * in principle, use a different "default" port number, but
178 * we do not support this feature at the moment.
179 * You can run Asterisk with SIP on a different port with a configuration
180 * option. If you change this value in the source code, the signalling will be incorrect.
184 /*! \name DefaultValues Default values, set and reset in reload_config before reading configuration
186 These are default values in the source. There are other recommended values in the
187 sip.conf.sample for new installations. These may differ to keep backwards compatibility,
188 yet encouraging new behaviour on new installations
191 #define DEFAULT_CONTEXT "default" /*!< The default context for [general] section as well as devices */
192 #define DEFAULT_RECORD_FEATURE "automon" /*!< The default feature specified for use with INFO */
193 #define DEFAULT_MOHINTERPRET "default" /*!< The default music class */
194 #define DEFAULT_MOHSUGGEST ""
195 #define DEFAULT_VMEXTEN "asterisk" /*!< Default voicemail extension */
196 #define DEFAULT_CALLERID "asterisk" /*!< Default caller ID */
197 #define DEFAULT_MWI_FROM ""
198 #define DEFAULT_NOTIFYMIME "application/simple-message-summary"
199 #define DEFAULT_ALLOWGUEST TRUE
200 #define DEFAULT_RTPKEEPALIVE 0 /*!< Default RTPkeepalive setting */
201 #define DEFAULT_CALLCOUNTER FALSE /*!< Do not enable call counters by default */
202 #define DEFAULT_SRVLOOKUP TRUE /*!< Recommended setting is ON */
203 #define DEFAULT_COMPACTHEADERS FALSE /*!< Send compact (one-character) SIP headers. Default off */
204 #define DEFAULT_TOS_SIP 0 /*!< Call signalling packets should be marked as DSCP CS3, but the default is 0 to be compatible with previous versions. */
205 #define DEFAULT_TOS_AUDIO 0 /*!< Audio packets should be marked as DSCP EF (Expedited Forwarding), but the default is 0 to be compatible with previous versions. */
206 #define DEFAULT_TOS_VIDEO 0 /*!< Video packets should be marked as DSCP AF41, but the default is 0 to be compatible with previous versions. */
207 #define DEFAULT_TOS_TEXT 0 /*!< Text packets should be marked as XXXX XXXX, but the default is 0 to be compatible with previous versions. */
208 #define DEFAULT_COS_SIP 4 /*!< Level 2 class of service for SIP signalling */
209 #define DEFAULT_COS_AUDIO 5 /*!< Level 2 class of service for audio media */
210 #define DEFAULT_COS_VIDEO 6 /*!< Level 2 class of service for video media */
211 #define DEFAULT_COS_TEXT 5 /*!< Level 2 class of service for text media (T.140) */
212 #define DEFAULT_ALLOW_EXT_DOM TRUE /*!< Allow external domains */
213 #define DEFAULT_REALM "asterisk" /*!< Realm for HTTP digest authentication */
214 #define DEFAULT_DOMAINSASREALM FALSE /*!< Use the domain option to guess the realm for registration and invite requests */
215 #define DEFAULT_NOTIFYRINGING TRUE /*!< Notify devicestate system on ringing state */
216 #define DEFAULT_NOTIFYCID DISABLED /*!< Include CID with ringing notifications */
217 #define DEFAULT_PEDANTIC TRUE /*!< Follow SIP standards for dialog matching */
218 #define DEFAULT_AUTOCREATEPEER AUTOPEERS_DISABLED /*!< Don't create peers automagically */
219 #define DEFAULT_MATCHEXTERNADDRLOCALLY FALSE /*!< Match extern IP locally default setting */
220 #define DEFAULT_QUALIFY FALSE /*!< Don't monitor devices */
221 #define DEFAULT_KEEPALIVE 0 /*!< Don't send keep alive packets */
222 #define DEFAULT_KEEPALIVE_INTERVAL 60 /*!< Send keep alive packets at 60 second intervals */
223 #define DEFAULT_ALWAYSAUTHREJECT TRUE /*!< Don't reject authentication requests always */
224 #define DEFAULT_AUTH_OPTIONS FALSE
225 #define DEFAULT_AUTH_MESSAGE TRUE
226 #define DEFAULT_ACCEPT_OUTOFCALL_MESSAGE TRUE
227 #define DEFAULT_REGEXTENONQUALIFY FALSE
228 #define DEFAULT_LEGACY_USEROPTION_PARSING FALSE
229 #define DEFAULT_SEND_DIVERSION TRUE
230 #define DEFAULT_T1MIN 100 /*!< 100 MS for minimal roundtrip time */
231 #define DEFAULT_MAX_CALL_BITRATE (384) /*!< Max bitrate for video */
232 #ifndef DEFAULT_USERAGENT
233 #define DEFAULT_USERAGENT "Asterisk PBX" /*!< Default Useragent: header unless re-defined in sip.conf */
234 #define DEFAULT_SDPSESSION "Asterisk PBX" /*!< Default SDP session name, (s=) header unless re-defined in sip.conf */
235 #define DEFAULT_SDPOWNER "root" /*!< Default SDP username field in (o=) header unless re-defined in sip.conf */
236 #define DEFAULT_ENGINE "asterisk" /*!< Default RTP engine to use for sessions */
237 #define DEFAULT_STORE_SIP_CAUSE FALSE /*!< Don't store HASH(SIP_CAUSE,<channel name>) for channels by default */
242 Various flags for the flags field in the pvt structure
243 Trying to sort these up (one or more of the following):
247 When flags are used by multiple structures, it is important that
248 they have a common layout so it is easy to copy them.
251 #define SIP_OUTGOING (1 << 0) /*!< D: Direction of the last transaction in this dialog */
252 #define SIP_OFFER_CC (1 << 1) /*!< D: Offer CC on subsequent responses */
253 #define SIP_RINGING (1 << 2) /*!< D: Have sent 180 ringing */
254 #define SIP_PROGRESS_SENT (1 << 3) /*!< D: Have sent 183 message progress */
255 #define SIP_NEEDREINVITE (1 << 4) /*!< D: Do we need to send another reinvite? */
256 #define SIP_PENDINGBYE (1 << 5) /*!< D: Need to send bye after we ack? */
257 #define SIP_GOTREFER (1 << 6) /*!< D: Got a refer? */
258 #define SIP_CALL_LIMIT (1 << 7) /*!< D: Call limit enforced for this call */
259 #define SIP_INC_COUNT (1 << 8) /*!< D: Did this dialog increment the counter of in-use calls? */
260 #define SIP_INC_RINGING (1 << 9) /*!< D: Did this connection increment the counter of in-use calls? */
261 #define SIP_DEFER_BYE_ON_TRANSFER (1 << 10) /*!< D: Do not hangup at first ast_hangup */
263 #define SIP_PROMISCREDIR (1 << 11) /*!< DP: Promiscuous redirection */
264 #define SIP_TRUSTRPID (1 << 12) /*!< DP: Trust RPID headers? */
265 #define SIP_USEREQPHONE (1 << 13) /*!< DP: Add user=phone to numeric URI. Default off */
266 #define SIP_USECLIENTCODE (1 << 14) /*!< DP: Trust X-ClientCode info message */
268 /* DTMF flags - see str2dtmfmode() and dtmfmode2str() */
269 #define SIP_DTMF (7 << 15) /*!< DP: DTMF Support: five settings, uses three bits */
270 #define SIP_DTMF_RFC2833 (0 << 15) /*!< DP: DTMF Support: RTP DTMF - "rfc2833" */
271 #define SIP_DTMF_INBAND (1 << 15) /*!< DP: DTMF Support: Inband audio, only for ULAW/ALAW - "inband" */
272 #define SIP_DTMF_INFO (2 << 15) /*!< DP: DTMF Support: SIP Info messages - "info" */
273 #define SIP_DTMF_AUTO (3 << 15) /*!< DP: DTMF Support: AUTO switch between rfc2833 and in-band DTMF */
274 #define SIP_DTMF_SHORTINFO (4 << 15) /*!< DP: DTMF Support: SIP Info messages - "info" - short variant */
277 #define SIP_NAT_FORCE_RPORT (1 << 18) /*!< DP: Force rport even if not present in the request */
278 #define SIP_NAT_RPORT_PRESENT (1 << 19) /*!< DP: rport was present in the request */
280 /* re-INVITE related settings */
281 #define SIP_REINVITE (7 << 20) /*!< DP: four settings, uses three bits */
282 #define SIP_REINVITE_NONE (0 << 20) /*!< DP: no reinvite allowed */
283 #define SIP_DIRECT_MEDIA (1 << 20) /*!< DP: allow peers to be reinvited to send media directly p2p */
284 #define SIP_DIRECT_MEDIA_NAT (2 << 20) /*!< DP: allow media reinvite when new peer is behind NAT */
285 #define SIP_REINVITE_UPDATE (4 << 20) /*!< DP: use UPDATE (RFC3311) when reinviting this peer */
287 /* "insecure" settings - see insecure2str() */
288 #define SIP_INSECURE (3 << 23) /*!< DP: three settings, uses two bits */
289 #define SIP_INSECURE_NONE (0 << 23) /*!< DP: secure mode */
290 #define SIP_INSECURE_PORT (1 << 23) /*!< DP: don't require matching port for incoming requests */
291 #define SIP_INSECURE_INVITE (1 << 24) /*!< DP: don't require authentication for incoming INVITEs */
293 /* Sending PROGRESS in-band settings */
294 #define SIP_PROG_INBAND (3 << 25) /*!< DP: three settings, uses two bits */
295 #define SIP_PROG_INBAND_NEVER (0 << 25)
296 #define SIP_PROG_INBAND_NO (1 << 25)
297 #define SIP_PROG_INBAND_YES (2 << 25)
299 #define SIP_USEPATH (1 << 27) /*!< GDP: Trust and use incoming Path headers? */
300 #define SIP_SENDRPID (3 << 29) /*!< DP: Remote Party-ID Support */
301 #define SIP_SENDRPID_NO (0 << 29)
302 #define SIP_SENDRPID_PAI (1 << 29) /*!< Use "P-Asserted-Identity" for rpid */
303 #define SIP_SENDRPID_RPID (2 << 29) /*!< Use "Remote-Party-ID" for rpid */
304 #define SIP_G726_NONSTANDARD (1 << 31) /*!< DP: Use non-standard packing for G726-32 data */
306 /*! \brief Flags to copy from peer/user to dialog */
307 #define SIP_FLAGS_TO_COPY \
308 (SIP_PROMISCREDIR | SIP_TRUSTRPID | SIP_SENDRPID | SIP_DTMF | SIP_REINVITE | \
309 SIP_PROG_INBAND | SIP_USECLIENTCODE | SIP_NAT_FORCE_RPORT | SIP_G726_NONSTANDARD | \
310 SIP_USEREQPHONE | SIP_INSECURE | SIP_USEPATH)
314 a second page of flags (for flags[1] */
317 #define SIP_PAGE2_RTCACHEFRIENDS (1 << 0) /*!< GP: Should we keep RT objects in memory for extended time? */
318 #define SIP_PAGE2_RTAUTOCLEAR (1 << 1) /*!< GP: Should we clean memory from peers after expiry? */
319 #define SIP_PAGE2_RPID_UPDATE (1 << 2)
320 #define SIP_PAGE2_Q850_REASON (1 << 3) /*!< DP: Get/send cause code via Reason header */
321 #define SIP_PAGE2_SYMMETRICRTP (1 << 4) /*!< GDP: Whether symmetric RTP is enabled or not */
322 #define SIP_PAGE2_STATECHANGEQUEUE (1 << 5) /*!< D: Unsent state pending change exists */
323 #define SIP_PAGE2_CONNECTLINEUPDATE_PEND (1 << 6)
324 #define SIP_PAGE2_RPID_IMMEDIATE (1 << 7)
325 #define SIP_PAGE2_RPORT_PRESENT (1 << 8) /*!< Was rport received in the Via header? */
326 #define SIP_PAGE2_PREFERRED_CODEC (1 << 9) /*!< GDP: Only respond with single most preferred joint codec */
327 #define SIP_PAGE2_VIDEOSUPPORT (1 << 10) /*!< DP: Video supported if offered? */
328 #define SIP_PAGE2_TEXTSUPPORT (1 << 11) /*!< GDP: Global text enable */
329 #define SIP_PAGE2_ALLOWSUBSCRIBE (1 << 12) /*!< GP: Allow subscriptions from this peer? */
331 #define SIP_PAGE2_ALLOWOVERLAP (3 << 13) /*!< DP: Allow overlap dialing ? */
332 #define SIP_PAGE2_ALLOWOVERLAP_NO (0 << 13) /*!< No, terminate with 404 Not found */
333 #define SIP_PAGE2_ALLOWOVERLAP_YES (1 << 13) /*!< Yes, using the 484 Address Incomplete response */
334 #define SIP_PAGE2_ALLOWOVERLAP_DTMF (2 << 13) /*!< Yes, using the DTMF transmission through Early Media */
335 #define SIP_PAGE2_ALLOWOVERLAP_SPARE (3 << 13) /*!< Spare (reserved for another dialling transmission mechanisms like KPML) */
337 #define SIP_PAGE2_SUBSCRIBEMWIONLY (1 << 15) /*!< GP: Only issue MWI notification if subscribed to */
338 #define SIP_PAGE2_IGNORESDPVERSION (1 << 16) /*!< GDP: Ignore the SDP session version number we receive and treat all sessions as new */
340 #define SIP_PAGE2_T38SUPPORT (3 << 17) /*!< GDP: T.38 Fax Support */
341 #define SIP_PAGE2_T38SUPPORT_UDPTL (1 << 17) /*!< GDP: T.38 Fax Support (no error correction) */
342 #define SIP_PAGE2_T38SUPPORT_UDPTL_FEC (2 << 17) /*!< GDP: T.38 Fax Support (FEC error correction) */
343 #define SIP_PAGE2_T38SUPPORT_UDPTL_REDUNDANCY (3 << 17) /*!< GDP: T.38 Fax Support (redundancy error correction) */
345 #define SIP_PAGE2_CALL_ONHOLD (3 << 19) /*!< D: Call hold states: */
346 #define SIP_PAGE2_CALL_ONHOLD_ACTIVE (1 << 19) /*!< D: Active hold */
347 #define SIP_PAGE2_CALL_ONHOLD_ONEDIR (2 << 19) /*!< D: One directional hold */
348 #define SIP_PAGE2_CALL_ONHOLD_INACTIVE (3 << 19) /*!< D: Inactive hold */
350 #define SIP_PAGE2_RFC2833_COMPENSATE (1 << 21) /*!< DP: Compensate for buggy RFC2833 implementations */
351 #define SIP_PAGE2_BUGGY_MWI (1 << 22) /*!< DP: Buggy CISCO MWI fix */
352 #define SIP_PAGE2_DIALOG_ESTABLISHED (1 << 23) /*!< 29: Has a dialog been established? */
354 #define SIP_PAGE2_FAX_DETECT (3 << 24) /*!< DP: Fax Detection support */
355 #define SIP_PAGE2_FAX_DETECT_CNG (1 << 24) /*!< DP: Fax Detection support - detect CNG in audio */
356 #define SIP_PAGE2_FAX_DETECT_T38 (2 << 24) /*!< DP: Fax Detection support - detect T.38 reinvite from peer */
357 #define SIP_PAGE2_FAX_DETECT_BOTH (3 << 24) /*!< DP: Fax Detection support - detect both */
359 #define SIP_PAGE2_UDPTL_DESTINATION (1 << 26) /*!< DP: Use source IP of RTP as destination if NAT is enabled */
360 #define SIP_PAGE2_VIDEOSUPPORT_ALWAYS (1 << 27) /*!< DP: Always set up video, even if endpoints don't support it */
361 #define SIP_PAGE2_HAVEPEERCONTEXT (1 << 28) /*< Are we associated with a configured peer context? */
362 #define SIP_PAGE2_USE_SRTP (1 << 29) /*!< DP: Whether we should offer (only) SRTP */
364 #define SIP_PAGE2_FLAGS_TO_COPY \
365 (SIP_PAGE2_ALLOWSUBSCRIBE | SIP_PAGE2_ALLOWOVERLAP | SIP_PAGE2_IGNORESDPVERSION | \
366 SIP_PAGE2_VIDEOSUPPORT | SIP_PAGE2_T38SUPPORT | SIP_PAGE2_RFC2833_COMPENSATE | \
367 SIP_PAGE2_BUGGY_MWI | SIP_PAGE2_TEXTSUPPORT | SIP_PAGE2_FAX_DETECT | \
368 SIP_PAGE2_UDPTL_DESTINATION | SIP_PAGE2_VIDEOSUPPORT_ALWAYS | SIP_PAGE2_PREFERRED_CODEC | \
369 SIP_PAGE2_RPID_IMMEDIATE | SIP_PAGE2_RPID_UPDATE | SIP_PAGE2_SYMMETRICRTP |\
370 SIP_PAGE2_Q850_REASON | SIP_PAGE2_HAVEPEERCONTEXT | SIP_PAGE2_USE_SRTP)
373 #define SIP_PAGE3_SNOM_AOC (1 << 0) /*!< DPG: Allow snom aoc messages */
374 #define SIP_PAGE3_SRTP_TAG_32 (1 << 1) /*!< DP: Use a 32bit auth tag in INVITE not 80bit */
375 #define SIP_PAGE3_NAT_AUTO_RPORT (1 << 2) /*!< DGP: Set SIP_NAT_FORCE_RPORT when NAT is detected */
376 #define SIP_PAGE3_NAT_AUTO_COMEDIA (1 << 3) /*!< DGP: Set SIP_PAGE2_SYMMETRICRTP when NAT is detected */
377 #define SIP_PAGE3_DIRECT_MEDIA_OUTGOING (1 << 4) /*!< DP: Only send direct media reinvites on outgoing calls */
378 #define SIP_PAGE3_USE_AVPF (1 << 5) /*!< DGP: Support a minimal AVPF-compatible profile */
379 #define SIP_PAGE3_ICE_SUPPORT (1 << 6) /*!< DGP: Enable ICE support */
380 #define SIP_PAGE3_IGNORE_PREFCAPS (1 << 7) /*!< DP: Ignore prefcaps when setting up an outgoing call leg */
381 #define SIP_PAGE3_DISCARD_REMOTE_HOLD_RETRIEVAL (1 << 8) /*!< DGP: Stop telling the peer to start music on hold */
383 #define SIP_PAGE3_FLAGS_TO_COPY \
384 (SIP_PAGE3_SNOM_AOC | SIP_PAGE3_SRTP_TAG_32 | SIP_PAGE3_NAT_AUTO_RPORT | SIP_PAGE3_NAT_AUTO_COMEDIA | \
385 SIP_PAGE3_DIRECT_MEDIA_OUTGOING | SIP_PAGE3_USE_AVPF | SIP_PAGE3_ICE_SUPPORT | SIP_PAGE3_IGNORE_PREFCAPS | \
386 SIP_PAGE3_DISCARD_REMOTE_HOLD_RETRIEVAL)
388 #define CHECK_AUTH_BUF_INITLEN 256
392 /*----------------------------------------------------------*/
394 /*----------------------------------------------------------*/
396 /*! \brief Authorization scheme for call transfers
398 * \note Not a bitfield flag, since there are plans for other modes,
399 * like "only allow transfers for authenticated devices"
402 TRANSFER_OPENFORALL, /*!< Allow all SIP transfers */
403 TRANSFER_CLOSED, /*!< Allow no SIP transfers */
406 /*! \brief The result of a lot of functions */
408 AST_SUCCESS = 0, /*!< FALSE means success, funny enough */
409 AST_FAILURE = -1, /*!< Failure code */
412 /*! \brief The results from handling an invite request
414 * \note Start at these values so we do not conflict with
415 * check_auth_results values when returning from
416 * handle_request_invite. check_auth_results only returned during
417 * authentication routines
419 enum inv_req_result {
420 INV_REQ_SUCCESS = 11, /*!< Success code */
421 INV_REQ_FAILED = 10, /*!< Failure code */
422 INV_REQ_ERROR = 9, /*!< Error code */
425 /*! \brief States for the INVITE transaction, not the dialog
426 * \note this is for the INVITE that sets up the dialog
429 INV_NONE = 0, /*!< No state at all, maybe not an INVITE dialog */
430 INV_CALLING = 1, /*!< Invite sent, no answer */
431 INV_PROCEEDING = 2, /*!< We got/sent 1xx message */
432 INV_EARLY_MEDIA = 3, /*!< We got 18x message with to-tag back */
433 INV_COMPLETED = 4, /*!< Got final response with error. Wait for ACK, then CONFIRMED */
434 INV_CONFIRMED = 5, /*!< Confirmed response - we've got an ack (Incoming calls only) */
435 INV_TERMINATED = 6, /*!< Transaction done - either successful (AST_STATE_UP) or failed, but done
436 The only way out of this is a BYE from one side */
437 INV_CANCELLED = 7, /*!< Transaction cancelled by client or server in non-terminated state */
440 /*! \brief When sending a SIP message, we can send with a few options, depending on
441 * type of SIP request. UNRELIABLE is moslty used for responses to repeated requests,
442 * where the original response would be sent RELIABLE in an INVITE transaction
445 XMIT_CRITICAL = 2, /*!< Transmit critical SIP message reliably, with re-transmits.
446 * If it fails, it's critical and will cause a teardown of the session */
447 XMIT_RELIABLE = 1, /*!< Transmit SIP message reliably, with re-transmits */
448 XMIT_UNRELIABLE = 0, /*!< Transmit SIP message without bothering with re-transmits */
451 /*! \brief Results from the parse_register() function */
452 enum parse_register_result {
453 PARSE_REGISTER_DENIED,
454 PARSE_REGISTER_FAILED,
455 PARSE_REGISTER_UPDATE,
456 PARSE_REGISTER_QUERY,
459 /*! \brief Type of subscription, based on the packages we do support, see \ref subscription_types */
460 enum subscriptiontype {
470 /*! \brief The number of media types in enum \ref media_type below. */
471 #define OFFERED_MEDIA_COUNT 4
473 /*! \brief Media types generate different "dummy answers" for not accepting the offer of
474 a media stream. We need to add definitions for each RTP profile. Secure RTP is not
475 the same as normal RTP and will require a new definition */
477 SDP_AUDIO, /*!< RTP/AVP Audio */
478 SDP_VIDEO, /*!< RTP/AVP Video */
479 SDP_IMAGE, /*!< Image udptl, not TCP or RTP */
480 SDP_TEXT, /*!< RTP/AVP Realtime Text */
481 SDP_UNKNOWN, /*!< Unknown media type */
484 /*! \brief Authentication types - proxy or www authentication
485 * \note Endpoints, like Asterisk, should always use WWW authentication to
486 * allow multiple authentications in the same call - to the proxy and
494 /*! \brief Result from get_destination function */
495 enum sip_get_dest_result {
496 SIP_GET_DEST_EXTEN_MATCHMORE = 1,
497 SIP_GET_DEST_EXTEN_FOUND = 0,
498 SIP_GET_DEST_EXTEN_NOT_FOUND = -1,
499 SIP_GET_DEST_REFUSED = -2,
500 SIP_GET_DEST_INVALID_URI = -3,
503 /*! \brief Authentication result from check_auth* functions */
504 enum check_auth_result {
505 AUTH_DONT_KNOW = -100, /*!< no result, need to check further */
506 /* XXX maybe this is the same as AUTH_NOT_FOUND */
508 AUTH_CHALLENGE_SENT = 1,
509 AUTH_SECRET_FAILED = -1,
510 AUTH_USERNAME_MISMATCH = -2,
511 AUTH_NOT_FOUND = -3, /*!< returned by register_verify */
512 AUTH_UNKNOWN_DOMAIN = -5,
513 AUTH_PEER_NOT_DYNAMIC = -6,
514 AUTH_ACL_FAILED = -7,
515 AUTH_BAD_TRANSPORT = -8,
516 AUTH_RTP_FAILED = -9,
517 AUTH_SESSION_LIMIT = -10,
520 /*! \brief States for outbound registrations (with register= lines in sip.conf */
521 enum sipregistrystate {
522 REG_STATE_UNREGISTERED = 0, /*!< We are not registered
523 * \note Initial state. We should have a timeout scheduled for the initial
524 * (or next) registration transmission, calling sip_reregister
527 REG_STATE_REGSENT, /*!< Registration request sent
528 * \note sent initial request, waiting for an ack or a timeout to
529 * retransmit the initial request.
532 REG_STATE_AUTHSENT, /*!< We have tried to authenticate
533 * \note entered after transmit_register with auth info,
534 * waiting for an ack.
537 REG_STATE_REGISTERED, /*!< Registered and done */
539 REG_STATE_REJECTED, /*!< Registration rejected
540 * \note only used when the remote party has an expire larger than
541 * our max-expire. This is a final state from which we do not
542 * recover (not sure how correctly).
545 REG_STATE_TIMEOUT, /*!< Registration timed out
546 * \note XXX unused */
548 REG_STATE_NOAUTH, /*!< We have no accepted credentials
549 * \note fatal - no chance to proceed */
551 REG_STATE_FAILED, /*!< Registration failed after several tries
552 * \note fatal - no chance to proceed */
555 /*! \brief Modes in which Asterisk can be configured to run SIP Session-Timers */
557 SESSION_TIMER_MODE_INVALID = 0, /*!< Invalid value */
558 SESSION_TIMER_MODE_ACCEPT, /*!< Honor inbound Session-Timer requests */
559 SESSION_TIMER_MODE_ORIGINATE, /*!< Originate outbound and honor inbound requests */
560 SESSION_TIMER_MODE_REFUSE /*!< Ignore inbound Session-Timers requests */
563 /*! \brief The entity playing the refresher role for Session-Timers */
565 SESSION_TIMER_REFRESHER_AUTO, /*!< Negotiated */
566 SESSION_TIMER_REFRESHER_US, /*!< Initially prefer session refresh by Asterisk */
567 SESSION_TIMER_REFRESHER_THEM, /*!< Initially prefer session refresh by the other side */
570 enum st_refresher_param {
571 SESSION_TIMER_REFRESHER_PARAM_UNKNOWN,
572 SESSION_TIMER_REFRESHER_PARAM_UAC,
573 SESSION_TIMER_REFRESHER_PARAM_UAS,
576 /*! \brief Automatic peer registration behavior
578 enum autocreatepeer_mode {
579 AUTOPEERS_DISABLED = 0, /*!< Automatic peer creation disabled */
580 AUTOPEERS_VOLATILE, /*!< Automatic peers dropped on sip reload (pre-1.8 behavior) */
581 AUTOPEERS_PERSIST /*!< Automatic peers survive sip configuration reload */
584 /*! \brief States whether a SIP message can create a dialog in Asterisk. */
585 enum can_create_dialog {
586 CAN_NOT_CREATE_DIALOG,
588 CAN_CREATE_DIALOG_UNSUPPORTED_METHOD,
591 /*! \brief SIP Request methods known by Asterisk
593 * \note Do _NOT_ make any changes to this enum, or the array following it;
594 * if you think you are doing the right thing, you are probably
595 * not doing the right thing. If you think there are changes
596 * needed, get someone else to review them first _before_
597 * submitting a patch. If these two lists do not match properly
598 * bad things will happen.
601 SIP_UNKNOWN, /*!< Unknown response */
602 SIP_RESPONSE, /*!< Not request, response to outbound request */
603 SIP_REGISTER, /*!< Registration to the mothership, tell us where you are located */
604 SIP_OPTIONS, /*!< Check capabilities of a device, used for "ping" too */
605 SIP_NOTIFY, /*!< Status update, Part of the event package standard, result of a SUBSCRIBE or a REFER */
606 SIP_INVITE, /*!< Set up a session */
607 SIP_ACK, /*!< End of a three-way handshake started with INVITE. */
608 SIP_PRACK, /*!< Reliable pre-call signalling. Not supported in Asterisk. */
609 SIP_BYE, /*!< End of a session */
610 SIP_REFER, /*!< Refer to another URI (transfer) */
611 SIP_SUBSCRIBE, /*!< Subscribe for updates (voicemail, session status, device status, presence) */
612 SIP_MESSAGE, /*!< Text messaging */
613 SIP_UPDATE, /*!< Update a dialog. We can send UPDATE; but not accept it */
614 SIP_INFO, /*!< Information updates during a session */
615 SIP_CANCEL, /*!< Cancel an INVITE */
616 SIP_PUBLISH, /*!< Not supported in Asterisk */
617 SIP_PING, /*!< Not supported at all, no standard but still implemented out there */
620 /*! \brief Settings for the 'notifycid' option, see sip.conf.sample for details. */
621 enum notifycid_setting {
627 /*! \brief Modes for SIP domain handling in the PBX */
629 SIP_DOMAIN_AUTO, /*!< This domain is auto-configured */
630 SIP_DOMAIN_CONFIG, /*!< This domain is from configuration */
633 /*! \brief debugging state
634 * We store separately the debugging requests from the config file
635 * and requests from the CLI. Debugging is enabled if either is set
636 * (which means that if sipdebug is set in the config file, we can
637 * only turn it off by reloading the config).
641 sip_debug_config = 1,
642 sip_debug_console = 2,
645 /*! \brief T38 States for a call */
647 T38_DISABLED = 0, /*!< Not enabled */
648 T38_LOCAL_REINVITE, /*!< Offered from local - REINVITE */
649 T38_PEER_REINVITE, /*!< Offered from peer - REINVITE */
650 T38_ENABLED, /*!< Negotiated (enabled) */
651 T38_REJECTED /*!< Refused */
654 /*! \brief Parameters to know status of transfer */
656 REFER_IDLE, /*!< No REFER is in progress */
657 REFER_SENT, /*!< Sent REFER to transferee */
658 REFER_RECEIVED, /*!< Received REFER from transferrer */
659 REFER_CONFIRMED, /*!< Refer confirmed with a 100 TRYING (unused) */
660 REFER_ACCEPTED, /*!< Accepted by transferee */
661 REFER_RINGING, /*!< Target Ringing */
662 REFER_200OK, /*!< Answered by transfer target */
663 REFER_FAILED, /*!< REFER declined - go on */
664 REFER_NOAUTH /*!< We had no auth for REFER */
668 SIP_TYPE_PEER = (1 << 0),
669 SIP_TYPE_USER = (1 << 1),
672 enum t38_action_flag {
673 SDP_T38_NONE = 0, /*!< Do not modify T38 information at all */
674 SDP_T38_INITIATE, /*!< Remote side has requested T38 with us */
675 SDP_T38_ACCEPT, /*!< Remote side accepted our T38 request */
678 enum sip_tcptls_alert {
679 TCPTLS_ALERT_DATA, /*!< \brief There is new data to be sent out */
680 TCPTLS_ALERT_STOP, /*!< \brief A request to stop the tcp_handler thread */
691 /*----------------------------------------------------------*/
692 /*---- STRUCTS ----*/
693 /*----------------------------------------------------------*/
695 /*! \brief definition of a sip proxy server
697 * For outbound proxies, a sip_peer will contain a reference to a
698 * dynamically allocated instance of a sip_proxy. A sip_pvt may also
699 * contain a reference to a peer's outboundproxy, or it may contain
700 * a reference to the sip_cfg.outboundproxy.
703 char name[MAXHOSTNAMELEN]; /*!< DNS name of domain/host or IP */
704 struct ast_sockaddr ip; /*!< Currently used IP address and port */
706 time_t last_dnsupdate; /*!< When this was resolved */
707 enum ast_transport transport;
708 int force; /*!< If it's an outbound proxy, Force use of this outbound proxy for all outbound requests */
709 /* Room for a SRV record chain based on the name */
712 /*! \brief argument for the 'show channels|subscriptions' callback. */
713 struct __show_chan_arg {
716 int numchans; /* return value */
719 /*! \name GlobalSettings
720 Global settings apply to the channel (often settings you can change in the general section
724 /*! \brief a place to store all global settings for the sip channel driver
726 These are settings that will be possibly to apply on a group level later on.
727 \note Do not add settings that only apply to the channel itself and can't
728 be applied to devices (trunks, services, phones)
730 struct sip_settings {
731 int peer_rtupdate; /*!< G: Update database with registration data for peer? */
732 int rtsave_sysname; /*!< G: Save system name at registration? */
733 int rtsave_path; /*!< G: Save path header on registration */
734 int ignore_regexpire; /*!< G: Ignore expiration of peer */
735 int rtautoclear; /*!< Realtime ?? */
736 int directrtpsetup; /*!< Enable support for Direct RTP setup (no re-invites) */
737 int pedanticsipchecking; /*!< Extra checking ? Default off */
738 enum autocreatepeer_mode autocreatepeer; /*!< Auto creation of peers at registration? Default off. */
739 int srvlookup; /*!< SRV Lookup on or off. Default is on */
740 int allowguest; /*!< allow unauthenticated peers to connect? */
741 int alwaysauthreject; /*!< Send 401 Unauthorized for all failing requests */
742 int auth_options_requests; /*!< Authenticate OPTIONS requests */
743 int auth_message_requests; /*!< Authenticate MESSAGE requests */
744 int accept_outofcall_message; /*!< Accept MESSAGE outside of a call */
745 int compactheaders; /*!< send compact sip headers */
746 int allow_external_domains; /*!< Accept calls to external SIP domains? */
747 int regextenonqualify; /*!< Whether to add/remove regexten when qualifying peers */
748 int legacy_useroption_parsing; /*!< Whether to strip useroptions in URI via semicolons */
749 int send_diversion; /*!< Whether to Send SIP Diversion headers */
750 int matchexternaddrlocally; /*!< Match externaddr/externhost setting against localnet setting */
751 char regcontext[AST_MAX_CONTEXT]; /*!< Context for auto-extensions */
752 char messagecontext[AST_MAX_CONTEXT]; /*!< Default context for out of dialog msgs. */
753 unsigned int disallowed_methods; /*!< methods that we should never try to use */
754 int notifyringing; /*!< Send notifications on ringing */
755 int notifyhold; /*!< Send notifications on hold */
756 enum notifycid_setting notifycid; /*!< Send CID with ringing notifications */
757 enum transfermodes allowtransfer; /*!< SIP Refer restriction scheme */
758 int allowsubscribe; /*!< Flag for disabling ALL subscriptions, this is FALSE only if all peers are FALSE
759 the global setting is in globals_flags[1] */
760 char realm[MAXHOSTNAMELEN]; /*!< Default realm */
761 int domainsasrealm; /*!< Use domains lists as realms */
762 struct sip_proxy outboundproxy; /*!< Outbound proxy */
763 char default_context[AST_MAX_CONTEXT];
764 char default_subscribecontext[AST_MAX_CONTEXT];
765 char default_record_on_feature[AST_FEATURE_MAX_LEN];
766 char default_record_off_feature[AST_FEATURE_MAX_LEN];
767 struct ast_acl_list *contact_acl; /*! \brief Global list of addresses dynamic peers are not allowed to use */
768 struct ast_format_cap *caps; /*!< Supported codecs */
770 int default_max_forwards; /*!< Default max forwards (SIP Anti-loop) */
773 struct ast_websocket;
775 /*! \brief The SIP socket definition */
777 enum ast_transport type; /*!< UDP, TCP or TLS */
778 int fd; /*!< Filed descriptor, the actual socket */
780 struct ast_tcptls_session_instance *tcptls_session; /* If tcp or tls, a socket manager */
781 struct ast_websocket *ws_session; /*! If ws or wss, a WebSocket session */
784 /*! \brief sip_request: The data grabbed from the UDP socket
787 * Incoming messages: we first store the data from the socket in data[],
788 * adding a trailing \0 to make string parsing routines happy.
789 * Then call parse_request() and req.method = find_sip_method();
790 * to initialize the other fields. The \r\n at the end of each line is
791 * replaced by \0, so that data[] is not a conforming SIP message anymore.
792 * After this processing, rlpart1 is set to non-NULL to remember
793 * that we can run get_header() on this kind of packet.
795 * parse_request() splits the first line as follows:
796 * Requests have in the first line method uri SIP/2.0
797 * rlpart1 = method; rlpart2 = uri;
798 * Responses have in the first line SIP/2.0 NNN description
799 * rlpart1 = SIP/2.0; rlpart2 = NNN + description;
801 * For outgoing packets, we initialize the fields with init_req() or init_resp()
802 * (which fills the first line to "METHOD uri SIP/2.0" or "SIP/2.0 code text"),
803 * and then fill the rest with add_header() and add_line().
804 * The \r\n at the end of the line are still there, so the get_header()
805 * and similar functions don't work on these packets.
809 ptrdiff_t rlpart1; /*!< Offset of the SIP Method Name or "SIP/2.0" protocol version */
810 ptrdiff_t rlpart2; /*!< Offset of the Request URI or Response Status */
811 int headers; /*!< # of SIP Headers */
812 int method; /*!< Method of this request */
813 int lines; /*!< Body Content */
814 unsigned int sdp_start; /*!< the line number where the SDP begins */
815 unsigned int sdp_count; /*!< the number of lines of SDP */
816 char debug; /*!< print extra debugging if non zero */
817 char has_to_tag; /*!< non-zero if packet has To: tag */
818 char ignore; /*!< if non-zero This is a re-transmit, ignore it */
819 char authenticated; /*!< non-zero if this request was authenticated */
820 ptrdiff_t header[SIP_MAX_HEADERS]; /*!< Array of offsets into the request string of each SIP header*/
821 ptrdiff_t line[SIP_MAX_LINES]; /*!< Array of offsets into the request string of each SDP line*/
822 struct ast_str *data;
823 struct ast_str *content;
824 /* XXX Do we need to unref socket.ser when the request goes away? */
825 struct sip_socket socket; /*!< The socket used for this request */
826 AST_LIST_ENTRY(sip_request) next;
827 unsigned int reqsipoptions; /*!< Items needed for Required header in responses */
830 /* \brief given a sip_request and an offset, return the char * that resides there
832 * It used to be that rlpart1, rlpart2, and the header and line arrays were character
833 * pointers. They are now offsets into the ast_str portion of the sip_request structure.
834 * To avoid adding a bunch of redundant pointer arithmetic to the code, this macro is
835 * provided to retrieve the string at a particular offset within the request's buffer
837 #define REQ_OFFSET_TO_STR(req,offset) (ast_str_buffer((req)->data) + ((req)->offset))
839 /*! \brief Parameters to the transmit_invite function */
840 struct sip_invite_param {
841 int addsipheaders; /*!< Add extra SIP headers */
842 const char *uri_options; /*!< URI options to add to the URI */
843 const char *vxml_url; /*!< VXML url for Cisco phones */
844 char *auth; /*!< Authentication */
845 char *authheader; /*!< Auth header */
846 enum sip_auth_type auth_type; /*!< Authentication type */
847 const char *replaces; /*!< Replaces header for call transfers */
848 int transfer; /*!< Flag - is this Invite part of a SIP transfer? (invite/replaces) */
849 struct sip_proxy *outboundproxy; /*!< Outbound proxy URI */
852 /*! \brief Structure to store Via information */
855 const char *protocol;
863 /*! \brief Domain data structure.
864 \note In the future, we will connect this to a configuration tree specific
868 char domain[MAXHOSTNAMELEN]; /*!< SIP domain we are responsible for */
869 char context[AST_MAX_EXTENSION]; /*!< Incoming context for this domain */
870 enum domain_mode mode; /*!< How did we find this domain? */
871 AST_LIST_ENTRY(domain) list; /*!< List mechanics */
874 /*! \brief sip_history: Structure for saving transactions within a SIP dialog */
876 AST_LIST_ENTRY(sip_history) list;
877 char event[0]; /* actually more, depending on needs */
880 /*! \brief sip_auth: Credentials for authentication to other SIP services */
882 AST_LIST_ENTRY(sip_auth) node;
883 char realm[AST_MAX_EXTENSION]; /*!< Realm in which these credentials are valid */
884 char username[256]; /*!< Username */
885 char secret[256]; /*!< Secret */
886 char md5secret[256]; /*!< MD5Secret */
889 /*! \brief Container of SIP authentication credentials. */
890 struct sip_auth_container {
891 AST_LIST_HEAD_NOLOCK(, sip_auth) list;
894 /*! \brief T.38 channel settings (at some point we need to make this alloc'ed */
895 struct t38properties {
896 enum t38state state; /*!< T.38 state */
897 struct ast_control_t38_parameters our_parms;
898 struct ast_control_t38_parameters their_parms;
901 /*! \brief generic struct to map between strings and integers.
902 * Fill it with x-s pairs, terminate with an entry with s = NULL;
903 * Then you can call map_x_s(...) to map an integer to a string,
904 * and map_s_x() for the string -> integer mapping.
911 /*! \brief Structure to handle SIP transfers. Dynamically allocated when needed */
913 AST_DECLARE_STRING_FIELDS(
914 AST_STRING_FIELD(refer_to); /*!< Place to store REFER-TO extension */
915 AST_STRING_FIELD(refer_to_domain); /*!< Place to store REFER-TO domain */
916 AST_STRING_FIELD(refer_to_urioption); /*!< Place to store REFER-TO uri options */
917 AST_STRING_FIELD(refer_to_context); /*!< Place to store REFER-TO context */
918 AST_STRING_FIELD(referred_by); /*!< Place to store REFERRED-BY extension */
919 AST_STRING_FIELD(refer_contact); /*!< Place to store Contact info from a REFER extension */
920 AST_STRING_FIELD(replaces_callid); /*!< Replace info: callid */
921 AST_STRING_FIELD(replaces_callid_totag); /*!< Replace info: to-tag */
922 AST_STRING_FIELD(replaces_callid_fromtag); /*!< Replace info: from-tag */
924 int attendedtransfer; /*!< Attended or blind transfer? */
925 int localtransfer; /*!< Transfer to local domain? */
926 enum referstatus status; /*!< REFER status */
929 /*! \brief Struct to handle custom SIP notify requests. Dynamically allocated when needed */
931 struct ast_variable *headers;
932 struct ast_str *content;
935 /*! \brief Structure that encapsulates all attributes related to running
936 * SIP Session-Timers feature on a per dialog basis.
939 int st_active; /*!< Session-Timers on/off */
940 int st_interval; /*!< Session-Timers negotiated session refresh interval */
941 enum st_refresher st_ref; /*!< Session-Timers cached refresher */
942 int st_schedid; /*!< Session-Timers ast_sched scheduler id */
943 int st_active_peer_ua; /*!< Session-Timers on/off in peer UA */
944 int st_cached_min_se; /*!< Session-Timers cached Min-SE */
945 int st_cached_max_se; /*!< Session-Timers cached Session-Expires */
946 enum st_mode st_cached_mode; /*!< Session-Timers cached M.O. */
947 enum st_refresher st_cached_ref; /*!< Session-Timers session refresher */
948 unsigned char quit_flag:1; /*!< Stop trying to lock; just quit */
952 /*! \brief Structure that encapsulates all attributes related to configuration
953 * of SIP Session-Timers feature on a per user/peer basis.
956 enum st_mode st_mode_oper; /*!< Mode of operation for Session-Timers */
957 enum st_refresher_param st_ref; /*!< Session-Timer refresher */
958 int st_min_se; /*!< Lowest threshold for session refresh interval */
959 int st_max_se; /*!< Highest threshold for session refresh interval */
962 /*! \brief Structure for remembering offered media in an INVITE, to make sure we reply
963 to all media streams. */
964 struct offered_media {
965 enum media_type type; /*!< The type of media that was offered */
966 char *decline_m_line; /*!< Used if the media type is unknown/unused or a media stream is declined */
967 AST_LIST_ENTRY(offered_media) next;
970 /*! Additional headers to send with MESSAGE method packet. */
972 AST_LIST_ENTRY(sip_msg_hdr) next;
973 /*! Name of header to stick in MESSAGE */
975 /*! Value of header to stick in MESSAGE */
977 /*! The name and value strings are stuffed here in that order. */
981 /*! \brief Structure used for each SIP dialog, ie. a call, a registration, a subscribe.
982 * Created and initialized by sip_alloc(), the descriptor goes into the list of
983 * descriptors (dialoglist).
986 struct sip_pvt *next; /*!< Next dialog in chain */
987 enum invitestates invitestate; /*!< Track state of SIP_INVITEs */
988 struct ast_callid *logger_callid; /*!< Identifier for call used in log messages */
989 int method; /*!< SIP method that opened this dialog */
990 AST_DECLARE_STRING_FIELDS(
991 AST_STRING_FIELD(callid); /*!< Global CallID */
992 AST_STRING_FIELD(initviabranch); /*!< The branch ID from the topmost Via header in the initial request */
993 AST_STRING_FIELD(initviasentby); /*!< The sent-by from the topmost Via header in the initial request */
994 AST_STRING_FIELD(accountcode); /*!< Account code */
995 AST_STRING_FIELD(realm); /*!< Authorization realm */
996 AST_STRING_FIELD(nonce); /*!< Authorization nonce */
997 AST_STRING_FIELD(opaque); /*!< Opaque nonsense */
998 AST_STRING_FIELD(qop); /*!< Quality of Protection, since SIP wasn't complicated enough yet. */
999 AST_STRING_FIELD(domain); /*!< Authorization domain */
1000 AST_STRING_FIELD(from); /*!< The From: header */
1001 AST_STRING_FIELD(useragent); /*!< User agent in SIP request */
1002 AST_STRING_FIELD(exten); /*!< Extension where to start */
1003 AST_STRING_FIELD(context); /*!< Context for this call */
1004 AST_STRING_FIELD(messagecontext); /*!< Default context for outofcall messages. */
1005 AST_STRING_FIELD(subscribecontext); /*!< Subscribecontext */
1006 AST_STRING_FIELD(subscribeuri); /*!< Subscribecontext */
1007 AST_STRING_FIELD(fromdomain); /*!< Domain to show in the from field */
1008 AST_STRING_FIELD(fromuser); /*!< User to show in the user field */
1009 AST_STRING_FIELD(fromname); /*!< Name to show in the user field */
1010 AST_STRING_FIELD(tohost); /*!< Host we should put in the "to" field */
1011 AST_STRING_FIELD(todnid); /*!< DNID of this call (overrides host) */
1012 AST_STRING_FIELD(language); /*!< Default language for this call */
1013 AST_STRING_FIELD(mohinterpret); /*!< MOH class to use when put on hold */
1014 AST_STRING_FIELD(mohsuggest); /*!< MOH class to suggest when putting a peer on hold */
1015 AST_STRING_FIELD(rdnis); /*!< Referring DNIS */
1016 AST_STRING_FIELD(redircause); /*!< Referring cause */
1017 AST_STRING_FIELD(theirtag); /*!< Their tag */
1018 AST_STRING_FIELD(theirprovtag); /*!< Provisional their tag, used when evaluating responses to invites */
1019 AST_STRING_FIELD(tag); /*!< Our tag for this session */
1020 AST_STRING_FIELD(username); /*!< [user] name */
1021 AST_STRING_FIELD(peername); /*!< [peer] name, not set if [user] */
1022 AST_STRING_FIELD(authname); /*!< Who we use for authentication */
1023 AST_STRING_FIELD(uri); /*!< Original requested URI */
1024 AST_STRING_FIELD(okcontacturi); /*!< URI from the 200 OK on INVITE */
1025 AST_STRING_FIELD(peersecret); /*!< Password */
1026 AST_STRING_FIELD(peermd5secret);
1027 AST_STRING_FIELD(cid_num); /*!< Caller*ID number */
1028 AST_STRING_FIELD(cid_name); /*!< Caller*ID name */
1029 AST_STRING_FIELD(cid_tag); /*!< Caller*ID tag */
1030 AST_STRING_FIELD(mwi_from); /*!< Name to place in the From header in outgoing NOTIFY requests */
1031 AST_STRING_FIELD(fullcontact); /*!< The Contact: that the UA registers with us */
1032 /* we only store the part in <brackets> in this field. */
1033 AST_STRING_FIELD(our_contact); /*!< Our contact header */
1034 AST_STRING_FIELD(url); /*!< URL to be sent with next message to peer */
1035 AST_STRING_FIELD(parkinglot); /*!< Parkinglot */
1036 AST_STRING_FIELD(engine); /*!< RTP engine to use */
1037 AST_STRING_FIELD(dialstring); /*!< The dialstring used to call this SIP endpoint */
1038 AST_STRING_FIELD(last_presence_subtype); /*!< The last presence subtype sent for a subscription. */
1039 AST_STRING_FIELD(last_presence_message); /*!< The last presence message for a subscription */
1040 AST_STRING_FIELD(msg_body); /*!< Text for a MESSAGE body */
1041 AST_STRING_FIELD(tel_phone_context); /*!< The phone-context portion of a TEL URI */
1043 char via[128]; /*!< Via: header */
1044 int maxforwards; /*!< SIP Loop prevention */
1045 struct sip_socket socket; /*!< The socket used for this dialog */
1046 uint32_t ocseq; /*!< Current outgoing seqno */
1047 uint32_t icseq; /*!< Current incoming seqno */
1048 uint32_t init_icseq; /*!< Initial incoming seqno from first request */
1049 ast_group_t callgroup; /*!< Call group */
1050 ast_group_t pickupgroup; /*!< Pickup group */
1051 struct ast_namedgroups *named_callgroups; /*!< Named call group */
1052 struct ast_namedgroups *named_pickupgroups; /*!< Named pickup group */
1053 uint32_t lastinvite; /*!< Last seqno of invite */
1054 struct ast_flags flags[3]; /*!< SIP_ flags */
1056 /* boolean flags that don't belong in flags */
1057 unsigned short do_history:1; /*!< Set if we want to record history */
1058 unsigned short alreadygone:1; /*!< the peer has sent a message indicating termination of the dialog */
1059 unsigned short needdestroy:1; /*!< this dialog needs to be destroyed by the monitor thread */
1060 unsigned short final_destruction_scheduled:1; /*!< final dialog destruction is scheduled. Keep dialog
1061 * around until then to handle retransmits. */
1062 unsigned short outgoing_call:1; /*!< this is an outgoing call */
1063 unsigned short answered_elsewhere:1; /*!< This call is cancelled due to answer on another channel */
1064 unsigned short novideo:1; /*!< Didn't get video in invite, don't offer */
1065 unsigned short notext:1; /*!< Text not supported (?) */
1066 unsigned short session_modify:1; /*!< Session modification request true/false */
1067 unsigned short route_persistent:1; /*!< Is this the "real" route? */
1068 unsigned short autoframing:1; /*!< Whether to use our local configuration for frame sizes (off)
1069 * or respect the other endpoint's request for frame sizes (on)
1070 * for incoming calls
1072 unsigned short req_secure_signaling:1;/*!< Whether we are required to have secure signaling or not */
1073 unsigned short natdetected:1; /*!< Whether we detected a NAT when processing the Via */
1074 int timer_t1; /*!< SIP timer T1, ms rtt */
1075 int timer_b; /*!< SIP timer B, ms */
1076 unsigned int sipoptions; /*!< Supported SIP options on the other end */
1077 unsigned int reqsipoptions; /*!< Required SIP options on the other end */
1078 struct ast_codec_pref prefs; /*!< codec prefs */
1079 struct ast_format_cap *caps; /*!< Special capability (codec) */
1080 struct ast_format_cap *jointcaps; /*!< Supported capability at both ends (codecs) */
1081 struct ast_format_cap *peercaps; /*!< Supported peer capability */
1082 struct ast_format_cap *redircaps; /*!< Redirect codecs */
1083 struct ast_format_cap *prefcaps; /*!< Preferred codec (outbound only) */
1084 int noncodeccapability; /*!< DTMF RFC2833 telephony-event */
1085 int jointnoncodeccapability; /*!< Joint Non codec capability */
1086 int maxcallbitrate; /*!< Maximum Call Bitrate for Video Calls */
1087 int t38_maxdatagram; /*!< T.38 FaxMaxDatagram override */
1088 int request_queue_sched_id; /*!< Scheduler ID of any scheduled action to process queued requests */
1089 int provisional_keepalive_sched_id; /*!< Scheduler ID for provisional responses that need to be sent out to avoid cancellation */
1090 const char *last_provisional; /*!< The last successfully transmitted provisonal response message */
1091 int authtries; /*!< Times we've tried to authenticate */
1092 struct sip_proxy *outboundproxy; /*!< Outbound proxy for this dialog. Use ref_proxy to set this instead of setting it directly*/
1093 struct t38properties t38; /*!< T38 settings */
1094 struct ast_sockaddr udptlredirip; /*!< Where our T.38 UDPTL should be going if not to us */
1095 struct ast_udptl *udptl; /*!< T.38 UDPTL session */
1096 char zone[MAX_TONEZONE_COUNTRY]; /*!< Default tone zone for channels created by this dialog */
1097 int callingpres; /*!< Calling presentation */
1098 int expiry; /*!< How long we take to expire */
1099 int sessionversion; /*!< SDP Session Version */
1100 int sessionid; /*!< SDP Session ID */
1101 long branch; /*!< The branch identifier of this session */
1102 long invite_branch; /*!< The branch used when we sent the initial INVITE */
1103 int64_t sessionversion_remote; /*!< Remote UA's SDP Session Version */
1104 unsigned int portinuri:1; /*!< Non zero if a port has been specified, will also disable srv lookups */
1105 struct ast_sockaddr sa; /*!< Our peer */
1106 struct ast_sockaddr redirip; /*!< Where our RTP should be going if not to us */
1107 struct ast_sockaddr vredirip; /*!< Where our Video RTP should be going if not to us */
1108 struct ast_sockaddr tredirip; /*!< Where our Text RTP should be going if not to us */
1109 time_t lastrtprx; /*!< Last RTP received */
1110 time_t lastrtptx; /*!< Last RTP sent */
1111 int rtptimeout; /*!< RTP timeout time */
1112 int rtpholdtimeout; /*!< RTP timeout time on hold*/
1113 int rtpkeepalive; /*!< RTP send packets for keepalive */
1114 struct ast_acl_list *directmediaacl; /*!< Which IPs are allowed to interchange direct media with this peer - copied from sip_peer */
1115 struct ast_sockaddr recv; /*!< Received as */
1116 struct ast_sockaddr ourip; /*!< Our IP (as seen from the outside) */
1117 enum transfermodes allowtransfer; /*!< REFER: restriction scheme */
1118 struct ast_channel *owner; /*!< Who owns us (if we have an owner) */
1119 struct sip_route route; /*!< List of routing steps (fm Record-Route) */
1120 struct sip_notify *notify; /*!< Custom notify type */
1121 struct sip_auth_container *peerauth;/*!< Realm authentication credentials */
1122 int noncecount; /*!< Nonce-count */
1123 unsigned int stalenonce:1; /*!< Marks the current nonce as responded too */
1124 unsigned int ongoing_reinvite:1; /*!< There is a reinvite in progress that might need to be cleaned up */
1125 char lastmsg[256]; /*!< Last Message sent/received */
1126 int amaflags; /*!< AMA Flags */
1127 uint32_t pendinginvite; /*!< Any pending INVITE or state NOTIFY (in subscribe pvt's) ? (seqno of this) */
1128 uint32_t glareinvite; /*!< A invite received while a pending invite is already present is stored here. Its seqno is the
1129 value. Since this glare invite's seqno is not the same as the pending invite's, it must be
1130 held in order to properly process acknowledgements for our 491 response. */
1131 struct sip_request initreq; /*!< Latest request that opened a new transaction
1133 NOT the request that opened the dialog */
1135 int initid; /*!< Auto-congest ID if appropriate (scheduler) */
1136 int waitid; /*!< Wait ID for scheduler after 491 or other delays */
1137 int reinviteid; /*!< Reinvite in case of provisional, but no final response */
1138 int autokillid; /*!< Auto-kill ID (scheduler) */
1139 int t38id; /*!< T.38 Response ID */
1140 struct sip_refer *refer; /*!< REFER: SIP transfer data structure */
1141 enum subscriptiontype subscribed; /*!< SUBSCRIBE: Is this dialog a subscription? */
1142 int stateid; /*!< SUBSCRIBE: ID for devicestate subscriptions */
1143 int laststate; /*!< SUBSCRIBE: Last known extension state */
1144 struct ao2_container *last_device_state_info; /*!< SUBSCRIBE: last known extended extension state (take care of refs)*/
1145 struct timeval last_ringing_channel_time; /*!< SUBSCRIBE: channel timestamp of the channel which caused the last early-state notification */
1146 int last_presence_state; /*!< SUBSCRIBE: Last known presence state */
1147 uint32_t dialogver; /*!< SUBSCRIBE: Version for subscription dialog-info */
1149 struct ast_dsp *dsp; /*!< Inband DTMF or Fax CNG tone Detection dsp */
1151 struct sip_peer *relatedpeer; /*!< If this dialog is related to a peer, which one
1152 Used in peerpoke, mwi subscriptions */
1153 struct sip_registry *registry; /*!< If this is a REGISTER dialog, to which registry */
1154 struct ast_rtp_instance *rtp; /*!< RTP Session */
1155 struct ast_rtp_instance *vrtp; /*!< Video RTP session */
1156 struct ast_rtp_instance *trtp; /*!< Text RTP session */
1157 struct sip_pkt *packets; /*!< Packets scheduled for re-transmission */
1158 struct sip_history_head *history; /*!< History of this SIP dialog */
1159 size_t history_entries; /*!< Number of entires in the history */
1160 struct ast_variable *chanvars; /*!< Channel variables to set for inbound call */
1161 AST_LIST_HEAD_NOLOCK(, sip_msg_hdr) msg_headers; /*!< Additional MESSAGE headers to send. */
1162 AST_LIST_HEAD_NOLOCK(request_queue, sip_request) request_queue; /*!< Requests that arrived but could not be processed immediately */
1163 struct sip_invite_param *options; /*!< Options for INVITE */
1164 struct sip_st_dlg *stimer; /*!< SIP Session-Timers */
1165 struct ast_sdp_srtp *srtp; /*!< Structure to hold Secure RTP session data for audio */
1166 struct ast_sdp_srtp *vsrtp; /*!< Structure to hold Secure RTP session data for video */
1167 struct ast_sdp_srtp *tsrtp; /*!< Structure to hold Secure RTP session data for text */
1169 int red; /*!< T.140 RTP Redundancy */
1170 int hangupcause; /*!< Storage of hangupcause copied from our owner before we disconnect from the AST channel (only used at hangup) */
1172 struct sip_subscription_mwi *mwi; /*!< If this is a subscription MWI dialog, to which subscription */
1173 /*! The SIP methods supported by this peer. We get this information from the Allow header of the first
1174 * message we receive from an endpoint during a dialog.
1176 unsigned int allowed_methods;
1177 /*! Some peers are not trustworthy with their Allow headers, and so we need to override their wicked
1178 * ways through configuration. This is a copy of the peer's disallowed_methods, so that we can apply them
1179 * to the sip_pvt at various stages of dialog establishment
1181 unsigned int disallowed_methods;
1182 /*! When receiving an SDP offer, it is important to take note of what media types were offered.
1183 * By doing this, even if we don't want to answer a particular media stream with something meaningful, we can
1184 * still put an m= line in our answer with the port set to 0.
1186 * The reason for the length being 4 (OFFERED_MEDIA_COUNT) is that in this branch of Asterisk, the only media types supported are
1187 * image, audio, text, and video. Therefore we need to keep track of which types of media were offered.
1188 * Note that secure RTP defines new types of SDP media.
1190 * If we wanted to be 100% correct, we would keep a list of all media streams offered. That way we could respond
1191 * even to unknown media types, and we could respond to multiple streams of the same type. Such large-scale changes
1192 * are not a good idea for released branches, though, so we're compromising by just making sure that for the common cases:
1193 * audio and video, audio and T.38, and audio and text, we give the appropriate response to both media streams.
1195 * The large-scale changes would be a good idea for implementing during an SDP rewrite.
1197 AST_LIST_HEAD_NOLOCK(, offered_media) offered_media;
1198 struct ast_cc_config_params *cc_params;
1199 struct sip_epa_entry *epa_entry;
1200 int fromdomainport; /*!< Domain port to show in from field */
1202 struct ast_rtp_dtls_cfg dtls_cfg;
1205 /*! \brief sip packet - raw format for outbound packets that are sent or scheduled for transmission
1206 * Packets are linked in a list, whose head is in the struct sip_pvt they belong to.
1207 * Each packet holds a reference to the parent struct sip_pvt.
1208 * This structure is allocated in __sip_reliable_xmit() and only for packets that
1209 * require retransmissions.
1212 struct sip_pkt *next; /*!< Next packet in linked list */
1213 int retrans; /*!< Retransmission number */
1214 int method; /*!< SIP method for this packet */
1215 uint32_t seqno; /*!< Sequence number */
1216 char is_resp; /*!< 1 if this is a response packet (e.g. 200 OK), 0 if it is a request */
1217 char is_fatal; /*!< non-zero if there is a fatal error */
1218 int response_code; /*!< If this is a response, the response code */
1219 struct sip_pvt *owner; /*!< Owner AST call */
1220 int retransid; /*!< Retransmission ID */
1221 int timer_a; /*!< SIP timer A, retransmission timer */
1222 int timer_t1; /*!< SIP Timer T1, estimated RTT or 500 ms */
1223 struct timeval time_sent; /*!< When pkt was sent */
1224 int64_t retrans_stop_time; /*!< Time in ms after 'now' that retransmission must stop */
1225 int retrans_stop; /*!< Timeout is reached, stop retransmission */
1226 struct ast_str *data;
1230 * \brief A peer's mailbox
1232 * We could use STRINGFIELDS here, but for only one string, its
1233 * too much effort ...
1235 struct sip_mailbox {
1236 /*! Associated MWI subscription */
1237 struct stasis_subscription *event_sub;
1238 AST_LIST_ENTRY(sip_mailbox) entry;
1239 unsigned int delme:1;
1243 /*! \brief Structure for SIP peer data, we place calls to peers if registered or fixed IP address (host)
1245 /* XXX field 'name' must be first otherwise sip_addrcmp() will fail, as will astobj2 hashing of the structure */
1247 char name[80]; /*!< the unique name of this object */
1248 AST_DECLARE_STRING_FIELDS(
1249 AST_STRING_FIELD(secret); /*!< Password for inbound auth */
1250 AST_STRING_FIELD(md5secret); /*!< Password in MD5 */
1251 AST_STRING_FIELD(description); /*!< Description of this peer */
1252 AST_STRING_FIELD(remotesecret); /*!< Remote secret (trunks, remote devices) */
1253 AST_STRING_FIELD(context); /*!< Default context for incoming calls */
1254 AST_STRING_FIELD(messagecontext); /*!< Default context for outofcall messages. */
1255 AST_STRING_FIELD(subscribecontext); /*!< Default context for subscriptions */
1256 AST_STRING_FIELD(username); /*!< Temporary username until registration */
1257 AST_STRING_FIELD(accountcode); /*!< Account code */
1258 AST_STRING_FIELD(tohost); /*!< If not dynamic, IP address */
1259 AST_STRING_FIELD(regexten); /*!< Extension to register (if regcontext is used) */
1260 AST_STRING_FIELD(fromuser); /*!< From: user when calling this peer */
1261 AST_STRING_FIELD(fromdomain); /*!< From: domain when calling this peer */
1262 AST_STRING_FIELD(fullcontact); /*!< Contact registered with us (not in sip.conf) */
1263 AST_STRING_FIELD(cid_num); /*!< Caller ID num */
1264 AST_STRING_FIELD(cid_name); /*!< Caller ID name */
1265 AST_STRING_FIELD(cid_tag); /*!< Caller ID tag */
1266 AST_STRING_FIELD(vmexten); /*!< Dialplan extension for MWI notify message*/
1267 AST_STRING_FIELD(language); /*!< Default language for prompts */
1268 AST_STRING_FIELD(mohinterpret); /*!< Music on Hold class */
1269 AST_STRING_FIELD(mohsuggest); /*!< Music on Hold class */
1270 AST_STRING_FIELD(parkinglot); /*!< Parkinglot */
1271 AST_STRING_FIELD(useragent); /*!< User agent in SIP request (saved from registration) */
1272 AST_STRING_FIELD(mwi_from); /*!< Name to place in From header for outgoing NOTIFY requests */
1273 AST_STRING_FIELD(engine); /*!< RTP Engine to use */
1274 AST_STRING_FIELD(unsolicited_mailbox); /*!< Mailbox to store received unsolicited MWI NOTIFY messages information in */
1275 AST_STRING_FIELD(zone); /*!< Tonezone for this device */
1276 AST_STRING_FIELD(record_on_feature); /*!< Feature to use when receiving INFO with record: on during a call */
1277 AST_STRING_FIELD(record_off_feature); /*!< Feature to use when receiving INFO with record: off during a call */
1278 AST_STRING_FIELD(callback); /*!< Callback extension */
1280 struct sip_socket socket; /*!< Socket used for this peer */
1281 enum ast_transport default_outbound_transport; /*!< Peer Registration may change the default outbound transport.
1282 If register expires, default should be reset. to this value */
1283 /* things that don't belong in flags */
1284 unsigned short transports:5; /*!< Transports (enum ast_transport) that are acceptable for this peer */
1285 unsigned short is_realtime:1; /*!< this is a 'realtime' peer */
1286 unsigned short rt_fromcontact:1;/*!< copy fromcontact from realtime */
1287 unsigned short host_dynamic:1; /*!< Dynamic Peers register with Asterisk */
1288 unsigned short selfdestruct:1; /*!< Automatic peers need to destruct themselves */
1289 unsigned short the_mark:1; /*!< moved out of ASTOBJ into struct proper; That which bears the_mark should be deleted! */
1290 unsigned short autoframing:1; /*!< Whether to use our local configuration for frame sizes (off)
1291 * or respect the other endpoint's request for frame sizes (on)
1292 * for incoming calls
1294 unsigned short deprecated_username:1; /*!< If it's a realtime peer, are they using the deprecated "username" instead of "defaultuser" */
1295 struct sip_auth_container *auth;/*!< Realm authentication credentials */
1296 int amaflags; /*!< AMA Flags (for billing) */
1297 int callingpres; /*!< Calling id presentation */
1298 int inuse; /*!< Number of calls in use */
1299 int ringing; /*!< Number of calls ringing */
1300 int onhold; /*!< Peer has someone on hold */
1301 int call_limit; /*!< Limit of concurrent calls */
1302 int t38_maxdatagram; /*!< T.38 FaxMaxDatagram override */
1303 int busy_level; /*!< Level of active channels where we signal busy */
1304 int maxforwards; /*!< SIP Loop prevention */
1305 enum transfermodes allowtransfer; /*! SIP Refer restriction scheme */
1306 struct ast_codec_pref prefs; /*!< codec prefs */
1307 int lastmsgssent; /*!< The last known VM message counts (new/old) */
1308 unsigned int sipoptions; /*!< Supported SIP options */
1309 struct ast_flags flags[3]; /*!< SIP_ flags */
1311 /*! Mailboxes that this peer cares about */
1312 AST_LIST_HEAD_NOLOCK(, sip_mailbox) mailboxes;
1314 int maxcallbitrate; /*!< Maximum Bitrate for a video call */
1315 int expire; /*!< When to expire this peer registration */
1316 struct ast_format_cap *caps; /*!< Codec capability */
1317 int rtptimeout; /*!< RTP timeout */
1318 int rtpholdtimeout; /*!< RTP Hold Timeout */
1319 int rtpkeepalive; /*!< Send RTP packets for keepalive */
1320 ast_group_t callgroup; /*!< Call group */
1321 ast_group_t pickupgroup; /*!< Pickup group */
1322 struct ast_namedgroups *named_callgroups; /*!< Named call group */
1323 struct ast_namedgroups *named_pickupgroups; /*!< Named pickup group */
1324 struct sip_proxy *outboundproxy;/*!< Outbound proxy for this peer */
1325 struct ast_dnsmgr_entry *dnsmgr;/*!< DNS refresh manager for peer */
1326 struct ast_sockaddr addr; /*!< IP address of peer */
1327 unsigned int portinuri:1; /*!< Whether the port should be included in the URI */
1328 struct sip_pvt *call; /*!< Call pointer */
1329 int pokeexpire; /*!< Qualification: When to expire poke (qualify= checking) */
1330 int lastms; /*!< Qualification: How long last response took (in ms), or -1 for no response */
1331 int maxms; /*!< Qualification: Max ms we will accept for the host to be up, 0 to not monitor */
1332 int qualifyfreq; /*!< Qualification: Qualification: How often to check for the host to be up */
1333 struct timeval ps; /*!< Qualification: Time for sending SIP OPTION in sip_pke_peer() */
1334 int keepalive; /*!< Keepalive: How often to send keep alive packet */
1335 int keepalivesend; /*!< Keepalive: Scheduled item for sending keep alive packet */
1336 struct ast_sockaddr defaddr; /*!< Default IP address, used until registration */
1337 struct ast_acl_list *acl; /*!< Access control list */
1338 struct ast_acl_list *contactacl; /*!< Restrict what IPs are allowed in the Contact header (for registration) */
1339 struct ast_acl_list *directmediaacl; /*!< Restrict what IPs are allowed to interchange direct media with */
1340 struct ast_variable *chanvars; /*!< Variables to set for channel created by user */
1341 struct sip_pvt *mwipvt; /*!< Subscription for MWI */
1342 struct sip_st_cfg stimer; /*!< SIP Session-Timers */
1343 int timer_t1; /*!< The maximum T1 value for the peer */
1344 int timer_b; /*!< The maximum timer B (transaction timeouts) */
1345 int fromdomainport; /*!< The From: domain port */
1346 struct sip_route path; /*!< List of out-of-dialog outgoing routing steps (fm Path headers) */
1348 /*XXX Seems like we suddenly have two flags with the same content. Why? To be continued... */
1349 enum sip_peer_type type; /*!< Distinguish between "user" and "peer" types. This is used solely for CLI and manager commands */
1350 unsigned int disallowed_methods;
1351 struct ast_cc_config_params *cc_params;
1353 struct ast_endpoint *endpoint;
1355 struct ast_rtp_dtls_cfg dtls_cfg;
1359 * \brief Registrations with other SIP proxies
1361 * Created by sip_register(), the entry is linked in the 'regl' list,
1362 * and never deleted (other than at 'sip reload' or module unload times).
1363 * The entry always has a pending timeout, either waiting for an ACK to
1364 * the REGISTER message (in which case we have to retransmit the request),
1365 * or waiting for the next REGISTER message to be sent (either the initial one,
1366 * or once the previously completed registration one expires).
1367 * The registration can be in one of many states, though at the moment
1368 * the handling is a bit mixed.
1370 * \todo Convert this to astobj2
1372 struct sip_registry {
1373 ASTOBJ_COMPONENTS_FULL(struct sip_registry, 80, 1);
1374 AST_DECLARE_STRING_FIELDS(
1375 AST_STRING_FIELD(callid); /*!< Global Call-ID */
1376 AST_STRING_FIELD(realm); /*!< Authorization realm */
1377 AST_STRING_FIELD(nonce); /*!< Authorization nonce */
1378 AST_STRING_FIELD(opaque); /*!< Opaque nonsense */
1379 AST_STRING_FIELD(qop); /*!< Quality of Protection, since SIP wasn't complicated enough yet. */
1380 AST_STRING_FIELD(authdomain); /*!< Authorization domain */
1381 AST_STRING_FIELD(regdomain); /*!< Registration doamin */
1382 AST_STRING_FIELD(username); /*!< Who we are registering as */
1383 AST_STRING_FIELD(authuser); /*!< Who we *authenticate* as */
1384 AST_STRING_FIELD(hostname); /*!< Domain or host we register to */
1385 AST_STRING_FIELD(secret); /*!< Password in clear text */
1386 AST_STRING_FIELD(md5secret); /*!< Password in md5 */
1387 AST_STRING_FIELD(callback); /*!< Contact extension */
1388 AST_STRING_FIELD(peername); /*!< Peer registering to */
1389 AST_STRING_FIELD(localtag); /*!< Local tag generated same time as callid */
1391 enum ast_transport transport; /*!< Transport for this registration UDP, TCP or TLS */
1392 int portno; /*!< Optional port override */
1393 int regdomainport; /*!< Port override for domainport */
1394 int expire; /*!< Sched ID of expiration */
1395 int configured_expiry; /*!< Configured value to use for the Expires header */
1396 int expiry; /*!< Negotiated value used for the Expires header */
1397 int regattempts; /*!< Number of attempts (since the last success) */
1398 int timeout; /*!< sched id of sip_reg_timeout */
1399 int refresh; /*!< How often to refresh */
1400 struct sip_pvt *call; /*!< create a sip_pvt structure for each outbound "registration dialog" in progress */
1401 enum sipregistrystate regstate; /*!< Registration state (see above) */
1402 struct timeval regtime; /*!< Last successful registration time */
1403 int callid_valid; /*!< 0 means we haven't chosen callid for this registry yet. */
1404 uint32_t ocseq; /*!< Sequence number we got to for REGISTERs for this registry */
1405 struct ast_dnsmgr_entry *dnsmgr; /*!< DNS refresh manager for register */
1406 struct ast_sockaddr us; /*!< Who the server thinks we are */
1407 int noncecount; /*!< Nonce-count */
1408 char lastmsg[256]; /*!< Last Message sent/received */
1411 struct tcptls_packet {
1412 AST_LIST_ENTRY(tcptls_packet) entry;
1413 struct ast_str *data;
1416 /*! \brief Definition of a thread that handles a socket */
1417 struct sip_threadinfo {
1418 /*! TRUE if the thread needs to kill itself. (The module is being unloaded.) */
1420 int alert_pipe[2]; /*! Used to alert tcptls thread when packet is ready to be written */
1422 struct ast_tcptls_session_instance *tcptls_session;
1423 enum ast_transport type; /*!< We keep a copy of the type here so we can display it in the connection list */
1424 AST_LIST_HEAD_NOLOCK(, tcptls_packet) packet_q;
1428 * \brief Definition of an MWI subscription to another server
1430 * \todo Convert this to astobj2.
1432 struct sip_subscription_mwi {
1433 ASTOBJ_COMPONENTS_FULL(struct sip_subscription_mwi,1,1);
1434 AST_DECLARE_STRING_FIELDS(
1435 AST_STRING_FIELD(username); /*!< Who we are sending the subscription as */
1436 AST_STRING_FIELD(authuser); /*!< Who we *authenticate* as */
1437 AST_STRING_FIELD(hostname); /*!< Domain or host we subscribe to */
1438 AST_STRING_FIELD(secret); /*!< Password in clear text */
1439 AST_STRING_FIELD(mailbox); /*!< Mailbox store to put MWI into */
1441 enum ast_transport transport; /*!< Transport to use */
1442 int portno; /*!< Optional port override */
1443 int resub; /*!< Sched ID of resubscription */
1444 unsigned int subscribed:1; /*!< Whether we are currently subscribed or not */
1445 struct sip_pvt *call; /*!< Outbound subscription dialog */
1446 struct ast_dnsmgr_entry *dnsmgr; /*!< DNS refresh manager for subscription */
1447 struct ast_sockaddr us; /*!< Who the server thinks we are */
1451 * SIP PUBLISH support!
1452 * PUBLISH support was added to chan_sip due to its use in the call-completion
1453 * event package. In order to suspend and unsuspend monitoring of a called party,
1454 * a PUBLISH message must be sent. Rather than try to hack in PUBLISH transmission
1455 * and reception solely for the purposes of handling call-completion-related messages,
1456 * an effort has been made to create a generic framework for handling PUBLISH messages.
1458 * There are two main components to the effort, the event publication agent (EPA) and
1459 * the event state compositor (ESC). Both of these terms appear in RFC 3903, and the
1460 * implementation in Asterisk conforms to the defintions there. An EPA is a UAC that
1461 * transmits PUBLISH requests. An ESC is a UAS that receives PUBLISH requests and
1462 * acts appropriately based on the content of those requests.
1465 * The main structure in chan_sip is the event_state_compositor. There is an
1466 * event_state_compositor structure for each event package supported (as of Nov 2009
1467 * this is only the call-completion package). The structure contains data which is
1468 * intrinsic to the event package itself, such as the name of the package and a set
1469 * of callbacks for handling incoming PUBLISH requests. In addition, the
1470 * event_state_compositor struct contains an ao2_container of sip_esc_entries.
1472 * A sip_esc_entry corresponds to an entity which has sent a PUBLISH to Asterisk. We are
1473 * able to match the incoming PUBLISH to a sip_esc_entry using the Sip-If-Match header
1474 * of the message. Of course, if none is present, then a new sip_esc_entry will be created.
1476 * Once it is determined what type of PUBLISH request has come in (from RFC 3903, it may
1477 * be an initial, modify, refresh, or remove), then the event package-specific callbacks
1478 * may be called. If your event package doesn't need to take any specific action for a
1479 * specific PUBLISH type, it is perfectly safe to not define the callback at all. The callback
1480 * only needs to take care of application-specific information. If there is a problem, it is
1481 * up to the callback to take care of sending an appropriate 4xx or 5xx response code. In such
1482 * a case, the callback should return -1. This will tell the function that called the handler
1483 * that an appropriate error response has been sent. If the callback returns 0, however, then
1484 * the caller of the callback will generate a new entity tag and send a 200 OK response.
1486 * ESC entries are reference-counted, however as an implementor of a specific event package,
1487 * this should be transparent, since the reference counts are handled by the general ESC
1491 * The event publication agent in chan_sip is structured quite a bit differently than the
1492 * ESC. With an ESC, an appropriate entry has to be found based on the contents of an incoming
1493 * PUBLISH message. With an EPA, the application interested in sending the PUBLISH can maintain
1494 * a reference to the appropriate EPA entry instead. Similarly, when matching a PUBLISH response
1495 * to an appropriate EPA entry, the sip_pvt can maintain a reference to the corresponding
1496 * EPA entry. The result of this train of thought is that there is no compelling reason to
1497 * maintain a container of these entries.
1499 * Instead, there is only the sip_epa_entry structure. Every sip_epa_entry has an entity tag
1500 * that it maintains so that subsequent PUBLISH requests will be identifiable by the ESC on
1501 * the far end. In addition, there is a static_data field which contains information that is
1502 * common to all sip_epa_entries for a specific event package. This static data includes the
1503 * name of the event package and callbacks for handling specific responses for outgoing PUBLISHes.
1504 * Also, there is a field for pointing to instance-specific data. This can include the current
1505 * published state or other identifying information that is specific to an instance of an EPA
1506 * entry of a particular event package.
1508 * When an application wishes to send a PUBLISH request, it simply will call create_epa_entry,
1509 * followed by transmit_publish in order to send the PUBLISH. That's all that is necessary.
1510 * Like with ESC entries, sip_epa_entries are reference counted. Unlike ESC entries, though,
1511 * sip_epa_entries reference counts have to be maintained to some degree by the application making
1512 * use of the sip_epa_entry. The application will acquire a reference to the EPA entry when it
1513 * calls create_epa_entry. When the application has finished using the EPA entry (which may not
1514 * be until after several PUBLISH transactions have taken place) it must use ao2_ref to decrease
1515 * the reference count by 1.
1519 * \brief The states that can be represented in a SIP call-completion PUBLISH
1521 enum sip_cc_publish_state {
1522 /*! Closed, i.e. unavailable */
1524 /*! Open, i.e. available */
1529 * \brief The states that can be represented in a SIP call-completion NOTIFY
1531 enum sip_cc_notify_state {
1532 /*! Queued, i.e. unavailable */
1534 /*! Ready, i.e. available */
1539 * \brief The types of PUBLISH messages defined in RFC 3903
1541 enum sip_publish_type {
1546 * This actually is not defined in RFC 3903. We use this as a constant
1547 * to indicate that an incoming PUBLISH does not fit into any of the
1548 * other categories and is thus invalid.
1550 SIP_PUBLISH_UNKNOWN,
1555 * The first PUBLISH sent. This will contain a non-zero Expires header
1556 * as well as a body that indicates the current state of the endpoint
1557 * that has sent the message. The initial PUBLISH is the only type
1558 * of PUBLISH to not contain a Sip-If-Match header in it.
1560 SIP_PUBLISH_INITIAL,
1565 * Used to keep a published state from expiring. This will contain a
1566 * non-zero Expires header but no body since its purpose is not to
1569 SIP_PUBLISH_REFRESH,
1574 * Used to change state from its previous value. This will contain
1575 * a body updating the published state. May or may not contain an
1583 * Used to remove published state from an ESC. This will contain
1584 * an Expires header set to 0 and likely no body.
1590 * Data which is the same for all instances of an EPA for a
1591 * particular event package
1593 struct epa_static_data {
1594 /*! The event type */
1595 enum subscriptiontype event;
1597 * The name of the event as it would
1598 * appear in a SIP message
1602 * The callback called when a 200 OK is received on an outbound PUBLISH
1604 void (*handle_ok)(struct sip_pvt *, struct sip_request *, struct sip_epa_entry *);
1606 * The callback called when an error response is received on an outbound PUBLISH
1608 void (*handle_error)(struct sip_pvt *, const int resp, struct sip_request *, struct sip_epa_entry *);
1610 * Destructor to call to clean up instance data
1612 void (*destructor)(void *instance_data);
1616 * \brief backend for an event publication agent
1618 struct epa_backend {
1619 const struct epa_static_data *static_data;
1620 AST_LIST_ENTRY(epa_backend) next;
1623 struct sip_epa_entry {
1625 * When we are going to send a publish, we need to
1626 * know the type of PUBLISH to send.
1628 enum sip_publish_type publish_type;
1630 * When we send a PUBLISH, we have to be
1631 * sure to include the entity tag that we
1632 * received in the previous response.
1634 char entity_tag[SIPBUFSIZE];
1636 * The destination to which this EPA should send
1637 * PUBLISHes. This may be the name of a SIP peer
1640 char destination[SIPBUFSIZE];
1642 * The body of the most recently-sent PUBLISH message.
1643 * This is useful for situations such as authentication,
1644 * in which we must send a message identical to the
1645 * one previously sent
1647 char body[SIPBUFSIZE];
1649 * Every event package has some constant data and
1650 * callbacks that all instances will share. This
1651 * data resides in this field.
1653 const struct epa_static_data *static_data;
1655 * In addition to the static data that all instances
1656 * of sip_epa_entry will have, each instance will
1657 * require its own instance-specific data.
1659 void *instance_data;
1663 * \brief Instance data for a Call completion EPA entry
1665 struct cc_epa_entry {
1667 * The core ID of the CC transaction
1668 * for which this EPA entry belongs. This
1669 * essentially acts as a unique identifier
1670 * for the entry and is used in the hash
1671 * and comparison functions
1675 * We keep the last known state of the
1676 * device in question handy in case
1677 * it needs to be known by a third party.
1678 * Also, in the case where for some reason
1679 * we get asked to transmit state that we
1680 * already sent, we can just ignore the
1683 enum sip_cc_publish_state current_state;
1686 struct event_state_compositor;
1689 * \brief common ESC items for all event types
1691 * The entity_id field serves as a means by which
1692 * A specific entry may be found.
1694 struct sip_esc_entry {
1696 * The name of the party who
1697 * sent us the PUBLISH. This will more
1698 * than likely correspond to a peer name.
1700 * This field's utility isn't really that
1701 * great. It's mainly just a user-recognizable
1702 * handle that can be printed in debug messages.
1704 const char *device_name;
1706 * The event package for which this esc_entry
1707 * exists. Most of the time this isn't really
1708 * necessary since you'll have easy access to the
1709 * ESC which contains this entry. However, in
1710 * some circumstances, we won't have the ESC
1715 * The entity ID used when corresponding
1716 * with the EPA on the other side. As the
1717 * ESC, we generate an entity ID for each
1718 * received PUBLISH and store it in this
1721 char entity_tag[30];
1723 * The ID for the scheduler. We schedule
1724 * destruction of a sip_esc_entry when we
1725 * receive a PUBLISH. The destruction is
1726 * scheduled for the duration received in
1727 * the Expires header.
1731 * Each ESC entry will be for a specific
1732 * event type. Those entries will need to
1733 * carry data which is intrinsic to the
1734 * ESC entry but which is specific to
1737 void *event_specific_data;
1740 typedef int (* const esc_publish_callback)(struct sip_pvt *, struct sip_request *, struct event_state_compositor *, struct sip_esc_entry *);
1743 * \brief Callbacks for SIP ESCs
1746 * The names of the callbacks are self-explanatory. The
1747 * corresponding handler is called whenever the specific
1748 * type of PUBLISH is received.
1750 struct sip_esc_publish_callbacks {
1751 const esc_publish_callback initial_handler;
1752 const esc_publish_callback refresh_handler;
1753 const esc_publish_callback modify_handler;
1754 const esc_publish_callback remove_handler;
1757 struct sip_cc_agent_pvt {
1759 /* A copy of the original call's Call-ID.
1760 * We use this as a search key when attempting
1761 * to find a particular sip_pvt.
1763 char original_callid[SIPBUFSIZE];
1764 /* A copy of the exten called originally.
1765 * We use this to set the proper extension
1766 * to dial during the recall since the incoming
1767 * request URI is one that was generated just
1770 char original_exten[SIPBUFSIZE];
1771 /* A reference to the dialog which we will
1772 * be sending a NOTIFY on when it comes time
1775 struct sip_pvt *subscribe_pvt;
1776 /* When we send a NOTIFY, we include a URI
1777 * that should be used by the caller when he
1778 * wishes to send a PUBLISH or INVITE to us.
1779 * We store that URI here.
1781 char notify_uri[SIPBUFSIZE];
1782 /* When we advertise call completion to a caller,
1783 * we provide a URI for the caller to use when
1784 * he sends us a SUBSCRIBE. We store it for matching
1785 * purposes when we receive the SUBSCRIBE from the
1788 char subscribe_uri[SIPBUFSIZE];
1792 struct sip_monitor_instance {
1793 AST_DECLARE_STRING_FIELDS(
1794 AST_STRING_FIELD(subscribe_uri);
1795 AST_STRING_FIELD(notify_uri);
1796 AST_STRING_FIELD(peername);
1797 AST_STRING_FIELD(device_name);
1800 struct sip_pvt *subscription_pvt;
1801 struct sip_epa_entry *suspension_entry;
1804 /*! \brief List of well-known SIP options. If we get this in a require,
1805 we should check the list and answer accordingly. */
1806 static const struct cfsip_options {
1807 int id; /*!< Bitmap ID */
1808 int supported; /*!< Supported by Asterisk ? */
1809 char * const text; /*!< Text id, as in standard */
1810 } sip_options[] = { /* XXX used in 3 places */
1811 /* RFC3262: PRACK 100% reliability */
1812 { SIP_OPT_100REL, NOT_SUPPORTED, "100rel" },
1813 /* RFC3959: SIP Early session support */
1814 { SIP_OPT_EARLY_SESSION, NOT_SUPPORTED, "early-session" },
1815 /* SIMPLE events: RFC4662 */
1816 { SIP_OPT_EVENTLIST, NOT_SUPPORTED, "eventlist" },
1817 /* RFC 4916- Connected line ID updates */
1818 { SIP_OPT_FROMCHANGE, NOT_SUPPORTED, "from-change" },
1819 /* GRUU: Globally Routable User Agent URI's */
1820 { SIP_OPT_GRUU, NOT_SUPPORTED, "gruu" },
1821 /* RFC4244 History info */
1822 { SIP_OPT_HISTINFO, NOT_SUPPORTED, "histinfo" },
1823 /* RFC3911: SIP Join header support */
1824 { SIP_OPT_JOIN, NOT_SUPPORTED, "join" },
1825 /* Disable the REFER subscription, RFC 4488 */
1826 { SIP_OPT_NOREFERSUB, NOT_SUPPORTED, "norefersub" },
1827 /* SIP outbound - the final NAT battle - draft-sip-outbound */
1828 { SIP_OPT_OUTBOUND, NOT_SUPPORTED, "outbound" },
1829 /* RFC3327: Path support */
1830 { SIP_OPT_PATH, NOT_SUPPORTED, "path" },
1831 /* RFC3840: Callee preferences */
1832 { SIP_OPT_PREF, NOT_SUPPORTED, "pref" },
1833 /* RFC3312: Precondition support */
1834 { SIP_OPT_PRECONDITION, NOT_SUPPORTED, "precondition" },
1835 /* RFC3323: Privacy with proxies*/
1836 { SIP_OPT_PRIVACY, NOT_SUPPORTED, "privacy" },
1837 /* RFC-ietf-sip-uri-list-conferencing-02.txt conference invite lists */
1838 { SIP_OPT_RECLISTINV, NOT_SUPPORTED, "recipient-list-invite" },
1839 /* RFC-ietf-sip-uri-list-subscribe-02.txt - subscription lists */
1840 { SIP_OPT_RECLISTSUB, NOT_SUPPORTED, "recipient-list-subscribe" },
1841 /* RFC3891: Replaces: header for transfer */
1842 { SIP_OPT_REPLACES, SUPPORTED, "replaces" },
1843 /* One version of Polycom firmware has the wrong label */
1844 { SIP_OPT_REPLACES, SUPPORTED, "replace" },
1845 /* RFC4412 Resource priorities */
1846 { SIP_OPT_RESPRIORITY, NOT_SUPPORTED, "resource-priority" },
1847 /* RFC3329: Security agreement mechanism */
1848 { SIP_OPT_SEC_AGREE, NOT_SUPPORTED, "sec_agree" },
1849 /* RFC4092: Usage of the SDP ANAT Semantics in the SIP */
1850 { SIP_OPT_SDP_ANAT, NOT_SUPPORTED, "sdp-anat" },
1851 /* RFC4028: SIP Session-Timers */
1852 { SIP_OPT_TIMER, SUPPORTED, "timer" },
1853 /* RFC4538: Target-dialog */
1854 { SIP_OPT_TARGET_DIALOG,NOT_SUPPORTED, "tdialog" },
1862 AST_THREADSTORAGE(check_auth_buf);
1864 /*----------------------------------------------------------*/
1865 /*---- FUNCTIONS ----*/
1866 /*----------------------------------------------------------*/
1868 struct sip_peer *sip_find_peer(const char *peer, struct ast_sockaddr *addr, int realtime, int which_objects, int devstate_only, int transport);
1869 void sip_auth_headers(enum sip_auth_type code, char **header, char **respheader);
1870 const char *sip_get_header(const struct sip_request *req, const char *name);
1871 const char *sip_get_transport(enum ast_transport t);
1874 #define sip_ref_peer(arg1,arg2) _ref_peer((arg1),(arg2), __FILE__, __LINE__, __PRETTY_FUNCTION__)
1875 #define sip_unref_peer(arg1,arg2) _unref_peer((arg1),(arg2), __FILE__, __LINE__, __PRETTY_FUNCTION__)
1876 struct sip_peer *_ref_peer(struct sip_peer *peer, char *tag, char *file, int line, const char *func);
1877 void *_unref_peer(struct sip_peer *peer, char *tag, char *file, int line, const char *func);
1879 struct sip_peer *sip_ref_peer(struct sip_peer *peer, char *tag);
1880 void *sip_unref_peer(struct sip_peer *peer, char *tag);
1881 #endif /* REF_DEBUG */