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"
44 /* Arguments for find_peer */
45 #define FINDUSERS (1 << 0)
46 #define FINDPEERS (1 << 1)
47 #define FINDALLDEVICES (FINDUSERS | FINDPEERS)
49 #define SIPBUFSIZE 512 /*!< Buffer size for many operations */
53 #define SIP_RESERVED ";/?:@&=+$,# " /*!< Reserved characters in the username part of the URI */
55 #define DEFAULT_DEFAULT_EXPIRY 120
56 #define DEFAULT_MIN_EXPIRY 60
57 #define DEFAULT_MAX_EXPIRY 3600
58 #define DEFAULT_MWI_EXPIRY 3600
59 #define DEFAULT_REGISTRATION_TIMEOUT 20
60 #define DEFAULT_MAX_FORWARDS 70
62 /* guard limit must be larger than guard secs */
63 /* guard min must be < 1000, and should be >= 250 */
64 #define EXPIRY_GUARD_SECS 15 /*!< How long before expiry do we reregister */
65 #define EXPIRY_GUARD_LIMIT 30 /*!< Below here, we use EXPIRY_GUARD_PCT instead of EXPIRY_GUARD_SECS */
66 #define EXPIRY_GUARD_MIN 500 /*!< This is the minimum guard time applied. If
67 * GUARD_PCT turns out to be lower than this, it
68 * will use this time instead.
69 * This is in milliseconds.
71 #define EXPIRY_GUARD_PCT 0.20 /*!< Percentage of expires timeout to use when
72 * below EXPIRY_GUARD_LIMIT */
73 #define DEFAULT_EXPIRY 900 /*!< Expire slowly */
75 #define DEFAULT_QUALIFY_GAP 100
76 #define DEFAULT_QUALIFY_PEERS 1
78 #define CALLERID_UNKNOWN "Anonymous"
79 #define FROMDOMAIN_INVALID "anonymous.invalid"
81 #define DEFAULT_MAXMS 2000 /*!< Qualification: Must be faster than 2 seconds by default */
82 #define DEFAULT_QUALIFYFREQ 60 * 1000 /*!< Qualification: How often to check for the host to be up */
83 #define DEFAULT_FREQ_NOTOK 10 * 1000 /*!< Qualification: How often to check, if the host is down... */
85 #define DEFAULT_RETRANS 1000 /*!< How frequently to retransmit Default: 2 * 500 ms in RFC 3261 */
86 #define DEFAULT_TIMER_T1 500 /*!< SIP timer T1 (according to RFC 3261) */
87 #define SIP_TRANS_TIMEOUT 64 * DEFAULT_TIMER_T1 /*!< SIP request timeout (rfc 3261) 64*T1
88 * \todo Use known T1 for timeout (peerpoke)
90 #define DEFAULT_TRANS_TIMEOUT -1 /*!< Use default SIP transaction timeout */
91 #define PROVIS_KEEPALIVE_TIMEOUT 60000 /*!< How long to wait before retransmitting a provisional response (rfc 3261 13.3.1.1) */
92 #define MAX_AUTHTRIES 3 /*!< Try authentication three times, then fail */
94 #define SIP_MAX_HEADERS 64 /*!< Max amount of SIP headers to read */
95 #define SIP_MAX_LINES 256 /*!< Max amount of lines in SIP attachment (like SDP) */
96 #define SIP_MIN_PACKET 4096 /*!< Initialize size of memory to allocate for packets */
97 #define MAX_HISTORY_ENTRIES 50 /*!< Max entires in the history list for a sip_pvt */
99 #define INITIAL_CSEQ 101 /*!< Our initial sip sequence number */
101 #define DEFAULT_MAX_SE 1800 /*!< Session-Timer Default Session-Expires period (RFC 4028) */
102 #define DEFAULT_MIN_SE 90 /*!< Session-Timer Default Min-SE period (RFC 4028) */
104 #define SDP_MAX_RTPMAP_CODECS 32 /*!< Maximum number of codecs allowed in received SDP */
109 #define DEC_CALL_LIMIT 0
110 #define INC_CALL_LIMIT 1
111 #define DEC_CALL_RINGING 2
112 #define INC_CALL_RINGING 3
114 /*! Define SIP option tags, used in Require: and Supported: headers
115 * We need to be aware of these properties in the phones to use
116 * the replace: header. We should not do that without knowing
117 * that the other end supports it...
118 * This is nothing we can configure, we learn by the dialog
119 * Supported: header on the REGISTER (peer) or the INVITE
121 * We are not using many of these today, but will in the future.
122 * This is documented in RFC 3261
125 #define NOT_SUPPORTED 0
128 #define SIP_OPT_REPLACES (1 << 0)
129 #define SIP_OPT_100REL (1 << 1)
130 #define SIP_OPT_TIMER (1 << 2)
131 #define SIP_OPT_EARLY_SESSION (1 << 3)
132 #define SIP_OPT_JOIN (1 << 4)
133 #define SIP_OPT_PATH (1 << 5)
134 #define SIP_OPT_PREF (1 << 6)
135 #define SIP_OPT_PRECONDITION (1 << 7)
136 #define SIP_OPT_PRIVACY (1 << 8)
137 #define SIP_OPT_SDP_ANAT (1 << 9)
138 #define SIP_OPT_SEC_AGREE (1 << 10)
139 #define SIP_OPT_EVENTLIST (1 << 11)
140 #define SIP_OPT_GRUU (1 << 12)
141 #define SIP_OPT_TARGET_DIALOG (1 << 13)
142 #define SIP_OPT_NOREFERSUB (1 << 14)
143 #define SIP_OPT_HISTINFO (1 << 15)
144 #define SIP_OPT_RESPRIORITY (1 << 16)
145 #define SIP_OPT_FROMCHANGE (1 << 17)
146 #define SIP_OPT_RECLISTINV (1 << 18)
147 #define SIP_OPT_RECLISTSUB (1 << 19)
148 #define SIP_OPT_OUTBOUND (1 << 20)
149 #define SIP_OPT_UNKNOWN (1 << 21)
151 /*! \brief SIP Methods we support
152 * \todo This string should be set dynamically. We only support REFER and SUBSCRIBE if we have
153 * allowsubscribe and allowrefer on in sip.conf.
155 #define ALLOWED_METHODS "INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH"
157 /*! \brief SIP Extensions we support
158 * \note This should be generated based on the previous array
159 * in combination with settings.
161 * \todo We should not have "timer" if it's disabled in the configuration file.
163 #define SUPPORTED_EXTENSIONS "replaces, timer"
165 /*! \brief Standard SIP unsecure port for UDP and TCP from RFC 3261. DO NOT CHANGE THIS */
166 #define STANDARD_SIP_PORT 5060
167 /*! \brief Standard SIP TLS port from RFC 3261. DO NOT CHANGE THIS */
168 #define STANDARD_TLS_PORT 5061
170 /*! \note in many SIP headers, absence of a port number implies port 5060,
171 * and this is why we cannot change the above constant.
172 * There is a limited number of places in asterisk where we could,
173 * in principle, use a different "default" port number, but
174 * we do not support this feature at the moment.
175 * You can run Asterisk with SIP on a different port with a configuration
176 * option. If you change this value in the source code, the signalling will be incorrect.
180 /*! \name DefaultValues Default values, set and reset in reload_config before reading configuration
182 These are default values in the source. There are other recommended values in the
183 sip.conf.sample for new installations. These may differ to keep backwards compatibility,
184 yet encouraging new behaviour on new installations
187 #define DEFAULT_CONTEXT "default" /*!< The default context for [general] section as well as devices */
188 #define DEFAULT_MOHINTERPRET "default" /*!< The default music class */
189 #define DEFAULT_MOHSUGGEST ""
190 #define DEFAULT_VMEXTEN "asterisk" /*!< Default voicemail extension */
191 #define DEFAULT_CALLERID "asterisk" /*!< Default caller ID */
192 #define DEFAULT_MWI_FROM ""
193 #define DEFAULT_NOTIFYMIME "application/simple-message-summary"
194 #define DEFAULT_ALLOWGUEST TRUE
195 #define DEFAULT_RTPKEEPALIVE 0 /*!< Default RTPkeepalive setting */
196 #define DEFAULT_CALLCOUNTER FALSE /*!< Do not enable call counters by default */
197 #define DEFAULT_SRVLOOKUP TRUE /*!< Recommended setting is ON */
198 #define DEFAULT_COMPACTHEADERS FALSE /*!< Send compact (one-character) SIP headers. Default off */
199 #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. */
200 #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. */
201 #define DEFAULT_TOS_VIDEO 0 /*!< Video packets should be marked as DSCP AF41, but the default is 0 to be compatible with previous versions. */
202 #define DEFAULT_TOS_TEXT 0 /*!< Text packets should be marked as XXXX XXXX, but the default is 0 to be compatible with previous versions. */
203 #define DEFAULT_COS_SIP 4 /*!< Level 2 class of service for SIP signalling */
204 #define DEFAULT_COS_AUDIO 5 /*!< Level 2 class of service for audio media */
205 #define DEFAULT_COS_VIDEO 6 /*!< Level 2 class of service for video media */
206 #define DEFAULT_COS_TEXT 5 /*!< Level 2 class of service for text media (T.140) */
207 #define DEFAULT_ALLOW_EXT_DOM TRUE /*!< Allow external domains */
208 #define DEFAULT_REALM "asterisk" /*!< Realm for HTTP digest authentication */
209 #define DEFAULT_DOMAINSASREALM FALSE /*!< Use the domain option to guess the realm for registration and invite requests */
210 #define DEFAULT_NOTIFYRINGING TRUE /*!< Notify devicestate system on ringing state */
211 #define DEFAULT_NOTIFYCID DISABLED /*!< Include CID with ringing notifications */
212 #define DEFAULT_PEDANTIC FALSE /*!< Avoid following SIP standards for dialog matching */
213 #define DEFAULT_AUTOCREATEPEER FALSE /*!< Don't create peers automagically */
214 #define DEFAULT_MATCHEXTERNADDRLOCALLY FALSE /*!< Match extern IP locally default setting */
215 #define DEFAULT_QUALIFY FALSE /*!< Don't monitor devices */
216 #define DEFAULT_CALLEVENTS FALSE /*!< Extra manager SIP call events */
217 #define DEFAULT_ALWAYSAUTHREJECT FALSE /*!< Don't reject authentication requests always */
218 #define DEFAULT_REGEXTENONQUALIFY FALSE
219 #define DEFAULT_T1MIN 100 /*!< 100 MS for minimal roundtrip time */
220 #define DEFAULT_MAX_CALL_BITRATE (384) /*!< Max bitrate for video */
221 #ifndef DEFAULT_USERAGENT
222 #define DEFAULT_USERAGENT "Asterisk PBX" /*!< Default Useragent: header unless re-defined in sip.conf */
223 #define DEFAULT_SDPSESSION "Asterisk PBX" /*!< Default SDP session name, (s=) header unless re-defined in sip.conf */
224 #define DEFAULT_SDPOWNER "root" /*!< Default SDP username field in (o=) header unless re-defined in sip.conf */
225 #define DEFAULT_ENGINE "asterisk" /*!< Default RTP engine to use for sessions */
226 #define DEFAULT_CAPABILITY (AST_FORMAT_ULAW | AST_FORMAT_TESTLAW | AST_FORMAT_ALAW | AST_FORMAT_GSM | AST_FORMAT_H263);
231 Various flags for the flags field in the pvt structure
232 Trying to sort these up (one or more of the following):
236 When flags are used by multiple structures, it is important that
237 they have a common layout so it is easy to copy them.
240 #define SIP_OUTGOING (1 << 0) /*!< D: Direction of the last transaction in this dialog */
241 #define SIP_OFFER_CC (1 << 1) /*!< D: Offer CC on subsequent responses */
242 #define SIP_RINGING (1 << 2) /*!< D: Have sent 180 ringing */
243 #define SIP_PROGRESS_SENT (1 << 3) /*!< D: Have sent 183 message progress */
244 #define SIP_NEEDREINVITE (1 << 4) /*!< D: Do we need to send another reinvite? */
245 #define SIP_PENDINGBYE (1 << 5) /*!< D: Need to send bye after we ack? */
246 #define SIP_GOTREFER (1 << 6) /*!< D: Got a refer? */
247 #define SIP_CALL_LIMIT (1 << 7) /*!< D: Call limit enforced for this call */
248 #define SIP_INC_COUNT (1 << 8) /*!< D: Did this dialog increment the counter of in-use calls? */
249 #define SIP_INC_RINGING (1 << 9) /*!< D: Did this connection increment the counter of in-use calls? */
250 #define SIP_DEFER_BYE_ON_TRANSFER (1 << 10) /*!< D: Do not hangup at first ast_hangup */
252 #define SIP_PROMISCREDIR (1 << 11) /*!< DP: Promiscuous redirection */
253 #define SIP_TRUSTRPID (1 << 12) /*!< DP: Trust RPID headers? */
254 #define SIP_USEREQPHONE (1 << 13) /*!< DP: Add user=phone to numeric URI. Default off */
255 #define SIP_USECLIENTCODE (1 << 14) /*!< DP: Trust X-ClientCode info message */
257 /* DTMF flags - see str2dtmfmode() and dtmfmode2str() */
258 #define SIP_DTMF (7 << 15) /*!< DP: DTMF Support: five settings, uses three bits */
259 #define SIP_DTMF_RFC2833 (0 << 15) /*!< DP: DTMF Support: RTP DTMF - "rfc2833" */
260 #define SIP_DTMF_INBAND (1 << 15) /*!< DP: DTMF Support: Inband audio, only for ULAW/ALAW - "inband" */
261 #define SIP_DTMF_INFO (2 << 15) /*!< DP: DTMF Support: SIP Info messages - "info" */
262 #define SIP_DTMF_AUTO (3 << 15) /*!< DP: DTMF Support: AUTO switch between rfc2833 and in-band DTMF */
263 #define SIP_DTMF_SHORTINFO (4 << 15) /*!< DP: DTMF Support: SIP Info messages - "info" - short variant */
266 #define SIP_NAT_FORCE_RPORT (1 << 18) /*!< DP: Force rport even if not present in the request */
267 #define SIP_NAT_RPORT_PRESENT (1 << 19) /*!< DP: rport was present in the request */
269 /* re-INVITE related settings */
270 #define SIP_REINVITE (7 << 20) /*!< DP: four settings, uses three bits */
271 #define SIP_REINVITE_NONE (0 << 20) /*!< DP: no reinvite allowed */
272 #define SIP_DIRECT_MEDIA (1 << 20) /*!< DP: allow peers to be reinvited to send media directly p2p */
273 #define SIP_DIRECT_MEDIA_NAT (2 << 20) /*!< DP: allow media reinvite when new peer is behind NAT */
274 #define SIP_REINVITE_UPDATE (4 << 20) /*!< DP: use UPDATE (RFC3311) when reinviting this peer */
276 /* "insecure" settings - see insecure2str() */
277 #define SIP_INSECURE (3 << 23) /*!< DP: three settings, uses two bits */
278 #define SIP_INSECURE_NONE (0 << 23) /*!< DP: secure mode */
279 #define SIP_INSECURE_PORT (1 << 23) /*!< DP: don't require matching port for incoming requests */
280 #define SIP_INSECURE_INVITE (1 << 24) /*!< DP: don't require authentication for incoming INVITEs */
282 /* Sending PROGRESS in-band settings */
283 #define SIP_PROG_INBAND (3 << 25) /*!< DP: three settings, uses two bits */
284 #define SIP_PROG_INBAND_NEVER (0 << 25)
285 #define SIP_PROG_INBAND_NO (1 << 25)
286 #define SIP_PROG_INBAND_YES (2 << 25)
288 #define SIP_SENDRPID (3 << 29) /*!< DP: Remote Party-ID Support */
289 #define SIP_SENDRPID_NO (0 << 29)
290 #define SIP_SENDRPID_PAI (1 << 29) /*!< Use "P-Asserted-Identity" for rpid */
291 #define SIP_SENDRPID_RPID (2 << 29) /*!< Use "Remote-Party-ID" for rpid */
292 #define SIP_G726_NONSTANDARD (1 << 31) /*!< DP: Use non-standard packing for G726-32 data */
294 /*! \brief Flags to copy from peer/user to dialog */
295 #define SIP_FLAGS_TO_COPY \
296 (SIP_PROMISCREDIR | SIP_TRUSTRPID | SIP_SENDRPID | SIP_DTMF | SIP_REINVITE | \
297 SIP_PROG_INBAND | SIP_USECLIENTCODE | SIP_NAT_FORCE_RPORT | SIP_G726_NONSTANDARD | \
298 SIP_USEREQPHONE | SIP_INSECURE)
302 a second page of flags (for flags[1] */
305 #define SIP_PAGE2_RTCACHEFRIENDS (1 << 0) /*!< GP: Should we keep RT objects in memory for extended time? */
306 #define SIP_PAGE2_RTAUTOCLEAR (1 << 1) /*!< GP: Should we clean memory from peers after expiry? */
307 #define SIP_PAGE2_RPID_UPDATE (1 << 2)
308 #define SIP_PAGE2_Q850_REASON (1 << 3) /*!< DP: Get/send cause code via Reason header */
309 #define SIP_PAGE2_SYMMETRICRTP (1 << 4) /*!< GDP: Whether symmetric RTP is enabled or not */
310 #define SIP_PAGE2_STATECHANGEQUEUE (1 << 5) /*!< D: Unsent state pending change exists */
311 #define SIP_PAGE2_CONNECTLINEUPDATE_PEND (1 << 6)
312 #define SIP_PAGE2_RPID_IMMEDIATE (1 << 7)
313 #define SIP_PAGE2_RPORT_PRESENT (1 << 8) /*!< Was rport received in the Via header? */
314 #define SIP_PAGE2_PREFERRED_CODEC (1 << 9) /*!< GDP: Only respond with single most preferred joint codec */
315 #define SIP_PAGE2_VIDEOSUPPORT (1 << 10) /*!< DP: Video supported if offered? */
316 #define SIP_PAGE2_TEXTSUPPORT (1 << 11) /*!< GDP: Global text enable */
317 #define SIP_PAGE2_ALLOWSUBSCRIBE (1 << 12) /*!< GP: Allow subscriptions from this peer? */
318 #define SIP_PAGE2_ALLOWOVERLAP (1 << 13) /*!< DP: Allow overlap dialing ? */
319 #define SIP_PAGE2_SUBSCRIBEMWIONLY (1 << 14) /*!< GP: Only issue MWI notification if subscribed to */
320 #define SIP_PAGE2_IGNORESDPVERSION (1 << 15) /*!< GDP: Ignore the SDP session version number we receive and treat all sessions as new */
322 #define SIP_PAGE2_T38SUPPORT (3 << 16) /*!< GDP: T.38 Fax Support */
323 #define SIP_PAGE2_T38SUPPORT_UDPTL (1 << 16) /*!< GDP: T.38 Fax Support (no error correction) */
324 #define SIP_PAGE2_T38SUPPORT_UDPTL_FEC (2 << 16) /*!< GDP: T.38 Fax Support (FEC error correction) */
325 #define SIP_PAGE2_T38SUPPORT_UDPTL_REDUNDANCY (3 << 16) /*!< GDP: T.38 Fax Support (redundancy error correction) */
327 #define SIP_PAGE2_CALL_ONHOLD (3 << 18) /*!< D: Call hold states: */
328 #define SIP_PAGE2_CALL_ONHOLD_ACTIVE (1 << 18) /*!< D: Active hold */
329 #define SIP_PAGE2_CALL_ONHOLD_ONEDIR (2 << 18) /*!< D: One directional hold */
330 #define SIP_PAGE2_CALL_ONHOLD_INACTIVE (3 << 18) /*!< D: Inactive hold */
332 #define SIP_PAGE2_RFC2833_COMPENSATE (1 << 20) /*!< DP: Compensate for buggy RFC2833 implementations */
333 #define SIP_PAGE2_BUGGY_MWI (1 << 21) /*!< DP: Buggy CISCO MWI fix */
334 #define SIP_PAGE2_DIALOG_ESTABLISHED (1 << 22) /*!< 29: Has a dialog been established? */
336 #define SIP_PAGE2_FAX_DETECT (3 << 23) /*!< DP: Fax Detection support */
337 #define SIP_PAGE2_FAX_DETECT_CNG (1 << 23) /*!< DP: Fax Detection support - detect CNG in audio */
338 #define SIP_PAGE2_FAX_DETECT_T38 (2 << 23) /*!< DP: Fax Detection support - detect T.38 reinvite from peer */
339 #define SIP_PAGE2_FAX_DETECT_BOTH (3 << 23) /*!< DP: Fax Detection support - detect both */
341 #define SIP_PAGE2_REGISTERTRYING (1 << 24) /*!< DP: Send 100 Trying on REGISTER attempts */
342 #define SIP_PAGE2_UDPTL_DESTINATION (1 << 25) /*!< DP: Use source IP of RTP as destination if NAT is enabled */
343 #define SIP_PAGE2_VIDEOSUPPORT_ALWAYS (1 << 26) /*!< DP: Always set up video, even if endpoints don't support it */
344 #define SIP_PAGE2_HAVEPEERCONTEXT (1 << 27) /*< Are we associated with a configured peer context? */
345 #define SIP_PAGE2_USE_SRTP (1 << 28) /*!< DP: Whether we should offer (only) SRTP */
347 #define SIP_PAGE2_FLAGS_TO_COPY \
348 (SIP_PAGE2_ALLOWSUBSCRIBE | SIP_PAGE2_ALLOWOVERLAP | SIP_PAGE2_IGNORESDPVERSION | \
349 SIP_PAGE2_VIDEOSUPPORT | SIP_PAGE2_T38SUPPORT | SIP_PAGE2_RFC2833_COMPENSATE | \
350 SIP_PAGE2_BUGGY_MWI | SIP_PAGE2_TEXTSUPPORT | SIP_PAGE2_FAX_DETECT | \
351 SIP_PAGE2_UDPTL_DESTINATION | SIP_PAGE2_VIDEOSUPPORT_ALWAYS | SIP_PAGE2_PREFERRED_CODEC | \
352 SIP_PAGE2_RPID_IMMEDIATE | SIP_PAGE2_RPID_UPDATE | SIP_PAGE2_SYMMETRICRTP |\
353 SIP_PAGE2_Q850_REASON | SIP_PAGE2_HAVEPEERCONTEXT | SIP_PAGE2_USE_SRTP)
356 #define SIP_PAGE3_SNOM_AOC (1 << 0) /*!< DPG: Allow snom aoc messages */
358 #define SIP_PAGE3_FLAGS_TO_COPY \
363 /*----------------------------------------------------------*/
365 /*----------------------------------------------------------*/
367 /*! \brief Authorization scheme for call transfers
369 * \note Not a bitfield flag, since there are plans for other modes,
370 * like "only allow transfers for authenticated devices"
373 TRANSFER_OPENFORALL, /*!< Allow all SIP transfers */
374 TRANSFER_CLOSED, /*!< Allow no SIP transfers */
377 /*! \brief The result of a lot of functions */
379 AST_SUCCESS = 0, /*!< FALSE means success, funny enough */
380 AST_FAILURE = -1, /*!< Failure code */
383 /*! \brief States for the INVITE transaction, not the dialog
384 * \note this is for the INVITE that sets up the dialog
387 INV_NONE = 0, /*!< No state at all, maybe not an INVITE dialog */
388 INV_CALLING = 1, /*!< Invite sent, no answer */
389 INV_PROCEEDING = 2, /*!< We got/sent 1xx message */
390 INV_EARLY_MEDIA = 3, /*!< We got 18x message with to-tag back */
391 INV_COMPLETED = 4, /*!< Got final response with error. Wait for ACK, then CONFIRMED */
392 INV_CONFIRMED = 5, /*!< Confirmed response - we've got an ack (Incoming calls only) */
393 INV_TERMINATED = 6, /*!< Transaction done - either successful (AST_STATE_UP) or failed, but done
394 The only way out of this is a BYE from one side */
395 INV_CANCELLED = 7, /*!< Transaction cancelled by client or server in non-terminated state */
398 /*! \brief When sending a SIP message, we can send with a few options, depending on
399 * type of SIP request. UNRELIABLE is moslty used for responses to repeated requests,
400 * where the original response would be sent RELIABLE in an INVITE transaction
403 XMIT_CRITICAL = 2, /*!< Transmit critical SIP message reliably, with re-transmits.
404 * If it fails, it's critical and will cause a teardown of the session */
405 XMIT_RELIABLE = 1, /*!< Transmit SIP message reliably, with re-transmits */
406 XMIT_UNRELIABLE = 0, /*!< Transmit SIP message without bothering with re-transmits */
409 /*! \brief Results from the parse_register() function */
410 enum parse_register_result {
411 PARSE_REGISTER_DENIED,
412 PARSE_REGISTER_FAILED,
413 PARSE_REGISTER_UPDATE,
414 PARSE_REGISTER_QUERY,
417 /*! \brief Type of subscription, based on the packages we do support, see \ref subscription_types */
418 enum subscriptiontype {
428 /*! \brief The number of media types in enum \ref media_type below. */
429 #define OFFERED_MEDIA_COUNT 4
431 /*! \brief Media types generate different "dummy answers" for not accepting the offer of
432 a media stream. We need to add definitions for each RTP profile. Secure RTP is not
433 the same as normal RTP and will require a new definition */
435 SDP_AUDIO, /*!< RTP/AVP Audio */
436 SDP_VIDEO, /*!< RTP/AVP Video */
437 SDP_IMAGE, /*!< Image udptl, not TCP or RTP */
438 SDP_TEXT, /*!< RTP/AVP Realtime Text */
441 /*! \brief Authentication types - proxy or www authentication
442 * \note Endpoints, like Asterisk, should always use WWW authentication to
443 * allow multiple authentications in the same call - to the proxy and
451 /*! \brief Result from get_destination function */
452 enum sip_get_dest_result {
453 SIP_GET_DEST_PICKUP_EXTEN_FOUND = 1,
454 SIP_GET_DEST_EXTEN_FOUND = 0,
455 SIP_GET_DEST_EXTEN_NOT_FOUND = -1,
456 SIP_GET_DEST_REFUSED = -2,
457 SIP_GET_DEST_INVALID_URI = -3,
460 /*! \brief Authentication result from check_auth* functions */
461 enum check_auth_result {
462 AUTH_DONT_KNOW = -100, /*!< no result, need to check further */
463 /* XXX maybe this is the same as AUTH_NOT_FOUND */
465 AUTH_CHALLENGE_SENT = 1,
466 AUTH_SECRET_FAILED = -1,
467 AUTH_USERNAME_MISMATCH = -2,
468 AUTH_NOT_FOUND = -3, /*!< returned by register_verify */
470 AUTH_UNKNOWN_DOMAIN = -5,
471 AUTH_PEER_NOT_DYNAMIC = -6,
472 AUTH_ACL_FAILED = -7,
473 AUTH_BAD_TRANSPORT = -8,
477 /*! \brief States for outbound registrations (with register= lines in sip.conf */
478 enum sipregistrystate {
479 REG_STATE_UNREGISTERED = 0, /*!< We are not registered
480 * \note Initial state. We should have a timeout scheduled for the initial
481 * (or next) registration transmission, calling sip_reregister
484 REG_STATE_REGSENT, /*!< Registration request sent
485 * \note sent initial request, waiting for an ack or a timeout to
486 * retransmit the initial request.
489 REG_STATE_AUTHSENT, /*!< We have tried to authenticate
490 * \note entered after transmit_register with auth info,
491 * waiting for an ack.
494 REG_STATE_REGISTERED, /*!< Registered and done */
496 REG_STATE_REJECTED, /*!< Registration rejected
497 * \note only used when the remote party has an expire larger than
498 * our max-expire. This is a final state from which we do not
499 * recover (not sure how correctly).
502 REG_STATE_TIMEOUT, /*!< Registration timed out
503 * \note XXX unused */
505 REG_STATE_NOAUTH, /*!< We have no accepted credentials
506 * \note fatal - no chance to proceed */
508 REG_STATE_FAILED, /*!< Registration failed after several tries
509 * \note fatal - no chance to proceed */
512 /*! \brief Modes in which Asterisk can be configured to run SIP Session-Timers */
514 SESSION_TIMER_MODE_INVALID = 0, /*!< Invalid value */
515 SESSION_TIMER_MODE_ACCEPT, /*!< Honor inbound Session-Timer requests */
516 SESSION_TIMER_MODE_ORIGINATE, /*!< Originate outbound and honor inbound requests */
517 SESSION_TIMER_MODE_REFUSE /*!< Ignore inbound Session-Timers requests */
520 /*! \brief The entity playing the refresher role for Session-Timers */
522 SESSION_TIMER_REFRESHER_AUTO, /*!< Negotiated */
523 SESSION_TIMER_REFRESHER_UAC, /*!< Session is refreshed by the UAC */
524 SESSION_TIMER_REFRESHER_UAS /*!< Session is refreshed by the UAS */
527 /*! \brief Define some implemented SIP transports
528 \note Asterisk does not support SCTP or UDP/DTLS
531 SIP_TRANSPORT_UDP = 1, /*!< Unreliable transport for SIP, needs retransmissions */
532 SIP_TRANSPORT_TCP = 1 << 1, /*!< Reliable, but unsecure */
533 SIP_TRANSPORT_TLS = 1 << 2, /*!< TCP/TLS - reliable and secure transport for signalling */
536 /*! \brief States whether a SIP message can create a dialog in Asterisk. */
537 enum can_create_dialog {
538 CAN_NOT_CREATE_DIALOG,
540 CAN_CREATE_DIALOG_UNSUPPORTED_METHOD,
543 /*! \brief SIP Request methods known by Asterisk
545 * \note Do _NOT_ make any changes to this enum, or the array following it;
546 * if you think you are doing the right thing, you are probably
547 * not doing the right thing. If you think there are changes
548 * needed, get someone else to review them first _before_
549 * submitting a patch. If these two lists do not match properly
550 * bad things will happen.
553 SIP_UNKNOWN, /*!< Unknown response */
554 SIP_RESPONSE, /*!< Not request, response to outbound request */
555 SIP_REGISTER, /*!< Registration to the mothership, tell us where you are located */
556 SIP_OPTIONS, /*!< Check capabilities of a device, used for "ping" too */
557 SIP_NOTIFY, /*!< Status update, Part of the event package standard, result of a SUBSCRIBE or a REFER */
558 SIP_INVITE, /*!< Set up a session */
559 SIP_ACK, /*!< End of a three-way handshake started with INVITE. */
560 SIP_PRACK, /*!< Reliable pre-call signalling. Not supported in Asterisk. */
561 SIP_BYE, /*!< End of a session */
562 SIP_REFER, /*!< Refer to another URI (transfer) */
563 SIP_SUBSCRIBE, /*!< Subscribe for updates (voicemail, session status, device status, presence) */
564 SIP_MESSAGE, /*!< Text messaging */
565 SIP_UPDATE, /*!< Update a dialog. We can send UPDATE; but not accept it */
566 SIP_INFO, /*!< Information updates during a session */
567 SIP_CANCEL, /*!< Cancel an INVITE */
568 SIP_PUBLISH, /*!< Not supported in Asterisk */
569 SIP_PING, /*!< Not supported at all, no standard but still implemented out there */
572 /*! \brief Settings for the 'notifycid' option, see sip.conf.sample for details. */
573 enum notifycid_setting {
579 /*! \brief Modes for SIP domain handling in the PBX */
581 SIP_DOMAIN_AUTO, /*!< This domain is auto-configured */
582 SIP_DOMAIN_CONFIG, /*!< This domain is from configuration */
585 /*! \brief debugging state
586 * We store separately the debugging requests from the config file
587 * and requests from the CLI. Debugging is enabled if either is set
588 * (which means that if sipdebug is set in the config file, we can
589 * only turn it off by reloading the config).
593 sip_debug_config = 1,
594 sip_debug_console = 2,
597 /*! \brief T38 States for a call */
599 T38_DISABLED = 0, /*!< Not enabled */
600 T38_LOCAL_REINVITE, /*!< Offered from local - REINVITE */
601 T38_PEER_REINVITE, /*!< Offered from peer - REINVITE */
602 T38_ENABLED /*!< Negotiated (enabled) */
605 /*! \brief Parameters to know status of transfer */
607 REFER_IDLE, /*!< No REFER is in progress */
608 REFER_SENT, /*!< Sent REFER to transferee */
609 REFER_RECEIVED, /*!< Received REFER from transferrer */
610 REFER_CONFIRMED, /*!< Refer confirmed with a 100 TRYING (unused) */
611 REFER_ACCEPTED, /*!< Accepted by transferee */
612 REFER_RINGING, /*!< Target Ringing */
613 REFER_200OK, /*!< Answered by transfer target */
614 REFER_FAILED, /*!< REFER declined - go on */
615 REFER_NOAUTH /*!< We had no auth for REFER */
619 SIP_TYPE_PEER = (1 << 0),
620 SIP_TYPE_USER = (1 << 1),
623 enum t38_action_flag {
624 SDP_T38_NONE = 0, /*!< Do not modify T38 information at all */
625 SDP_T38_INITIATE, /*!< Remote side has requested T38 with us */
626 SDP_T38_ACCEPT, /*!< Remote side accepted our T38 request */
629 enum sip_tcptls_alert {
630 TCPTLS_ALERT_DATA, /*!< \brief There is new data to be sent out */
631 TCPTLS_ALERT_STOP, /*!< \brief A request to stop the tcp_handler thread */
635 /*----------------------------------------------------------*/
636 /*---- STRUCTS ----*/
637 /*----------------------------------------------------------*/
639 /*! \brief definition of a sip proxy server
641 * For outbound proxies, a sip_peer will contain a reference to a
642 * dynamically allocated instance of a sip_proxy. A sip_pvt may also
643 * contain a reference to a peer's outboundproxy, or it may contain
644 * a reference to the sip_cfg.outboundproxy.
647 char name[MAXHOSTNAMELEN]; /*!< DNS name of domain/host or IP */
648 struct ast_sockaddr ip; /*!< Currently used IP address and port */
650 time_t last_dnsupdate; /*!< When this was resolved */
651 enum sip_transport transport;
652 int force; /*!< If it's an outbound proxy, Force use of this outbound proxy for all outbound requests */
653 /* Room for a SRV record chain based on the name */
656 /*! \brief argument for the 'show channels|subscriptions' callback. */
657 struct __show_chan_arg {
660 int numchans; /* return value */
663 /*! \name GlobalSettings
664 Global settings apply to the channel (often settings you can change in the general section
668 /*! \brief a place to store all global settings for the sip channel driver
670 These are settings that will be possibly to apply on a group level later on.
671 \note Do not add settings that only apply to the channel itself and can't
672 be applied to devices (trunks, services, phones)
674 struct sip_settings {
675 int peer_rtupdate; /*!< G: Update database with registration data for peer? */
676 int rtsave_sysname; /*!< G: Save system name at registration? */
677 int ignore_regexpire; /*!< G: Ignore expiration of peer */
678 int rtautoclear; /*!< Realtime ?? */
679 int directrtpsetup; /*!< Enable support for Direct RTP setup (no re-invites) */
680 int pedanticsipchecking; /*!< Extra checking ? Default off */
681 int autocreatepeer; /*!< Auto creation of peers at registration? Default off. */
682 int srvlookup; /*!< SRV Lookup on or off. Default is on */
683 int allowguest; /*!< allow unauthenticated peers to connect? */
684 int alwaysauthreject; /*!< Send 401 Unauthorized for all failing requests */
685 int compactheaders; /*!< send compact sip headers */
686 int allow_external_domains; /*!< Accept calls to external SIP domains? */
687 int callevents; /*!< Whether we send manager events or not */
688 int regextenonqualify; /*!< Whether to add/remove regexten when qualifying peers */
689 int matchexternaddrlocally; /*!< Match externaddr/externhost setting against localnet setting */
690 char regcontext[AST_MAX_CONTEXT]; /*!< Context for auto-extensions */
691 unsigned int disallowed_methods; /*!< methods that we should never try to use */
692 int notifyringing; /*!< Send notifications on ringing */
693 int notifyhold; /*!< Send notifications on hold */
694 enum notifycid_setting notifycid; /*!< Send CID with ringing notifications */
695 enum transfermodes allowtransfer; /*!< SIP Refer restriction scheme */
696 int allowsubscribe; /*!< Flag for disabling ALL subscriptions, this is FALSE only if all peers are FALSE
697 the global setting is in globals_flags[1] */
698 char realm[MAXHOSTNAMELEN]; /*!< Default realm */
699 int domainsasrealm; /*!< Use domains lists as realms */
700 struct sip_proxy outboundproxy; /*!< Outbound proxy */
701 char default_context[AST_MAX_CONTEXT];
702 char default_subscribecontext[AST_MAX_CONTEXT];
703 struct ast_ha *contact_ha; /*! \brief Global list of addresses dynamic peers are not allowed to use */
704 format_t capability; /*!< Supported codecs */
706 int default_max_forwards; /*!< Default max forwards (SIP Anti-loop) */
709 /*! \brief The SIP socket definition */
711 enum sip_transport type; /*!< UDP, TCP or TLS */
712 int fd; /*!< Filed descriptor, the actual socket */
714 struct ast_tcptls_session_instance *tcptls_session; /* If tcp or tls, a socket manager */
717 /*! \brief sip_request: The data grabbed from the UDP socket
720 * Incoming messages: we first store the data from the socket in data[],
721 * adding a trailing \0 to make string parsing routines happy.
722 * Then call parse_request() and req.method = find_sip_method();
723 * to initialize the other fields. The \r\n at the end of each line is
724 * replaced by \0, so that data[] is not a conforming SIP message anymore.
725 * After this processing, rlPart1 is set to non-NULL to remember
726 * that we can run get_header() on this kind of packet.
728 * parse_request() splits the first line as follows:
729 * Requests have in the first line method uri SIP/2.0
730 * rlPart1 = method; rlPart2 = uri;
731 * Responses have in the first line SIP/2.0 NNN description
732 * rlPart1 = SIP/2.0; rlPart2 = NNN + description;
734 * For outgoing packets, we initialize the fields with init_req() or init_resp()
735 * (which fills the first line to "METHOD uri SIP/2.0" or "SIP/2.0 code text"),
736 * and then fill the rest with add_header() and add_line().
737 * The \r\n at the end of the line are still there, so the get_header()
738 * and similar functions don't work on these packets.
742 ptrdiff_t rlPart1; /*!< Offset of the SIP Method Name or "SIP/2.0" protocol version */
743 ptrdiff_t rlPart2; /*!< Offset of the Request URI or Response Status */
744 int len; /*!< bytes used in data[], excluding trailing null terminator. Rarely used. */
745 int headers; /*!< # of SIP Headers */
746 int method; /*!< Method of this request */
747 int lines; /*!< Body Content */
748 unsigned int sdp_start; /*!< the line number where the SDP begins */
749 unsigned int sdp_count; /*!< the number of lines of SDP */
750 char debug; /*!< print extra debugging if non zero */
751 char has_to_tag; /*!< non-zero if packet has To: tag */
752 char ignore; /*!< if non-zero This is a re-transmit, ignore it */
753 ptrdiff_t header[SIP_MAX_HEADERS]; /*!< Array of offsets into the request string of each SIP header*/
754 ptrdiff_t line[SIP_MAX_LINES]; /*!< Array of offsets into the request string of each SDP line*/
755 struct ast_str *data;
756 struct ast_str *content;
757 /* XXX Do we need to unref socket.ser when the request goes away? */
758 struct sip_socket socket; /*!< The socket used for this request */
759 AST_LIST_ENTRY(sip_request) next;
762 /* \brief given a sip_request and an offset, return the char * that resides there
764 * It used to be that rlPart1, rlPart2, and the header and line arrays were character
765 * pointers. They are now offsets into the ast_str portion of the sip_request structure.
766 * To avoid adding a bunch of redundant pointer arithmetic to the code, this macro is
767 * provided to retrieve the string at a particular offset within the request's buffer
769 #define REQ_OFFSET_TO_STR(req,offset) (ast_str_buffer((req)->data) + ((req)->offset))
771 /*! \brief structure used in transfers */
773 struct ast_channel *chan1; /*!< First channel involved */
774 struct ast_channel *chan2; /*!< Second channel involved */
775 struct sip_request req; /*!< Request that caused the transfer (REFER) */
776 int seqno; /*!< Sequence number */
779 /*! \brief Parameters to the transmit_invite function */
780 struct sip_invite_param {
781 int addsipheaders; /*!< Add extra SIP headers */
782 const char *uri_options; /*!< URI options to add to the URI */
783 const char *vxml_url; /*!< VXML url for Cisco phones */
784 char *auth; /*!< Authentication */
785 char *authheader; /*!< Auth header */
786 enum sip_auth_type auth_type; /*!< Authentication type */
787 const char *replaces; /*!< Replaces header for call transfers */
788 int transfer; /*!< Flag - is this Invite part of a SIP transfer? (invite/replaces) */
791 /*! \brief Structure to save routing information for a SIP session */
793 struct sip_route *next;
797 /*! \brief Domain data structure.
798 \note In the future, we will connect this to a configuration tree specific
802 char domain[MAXHOSTNAMELEN]; /*!< SIP domain we are responsible for */
803 char context[AST_MAX_EXTENSION]; /*!< Incoming context for this domain */
804 enum domain_mode mode; /*!< How did we find this domain? */
805 AST_LIST_ENTRY(domain) list; /*!< List mechanics */
808 /*! \brief sip_history: Structure for saving transactions within a SIP dialog */
810 AST_LIST_ENTRY(sip_history) list;
811 char event[0]; /* actually more, depending on needs */
814 /*! \brief sip_auth: Credentials for authentication to other SIP services */
816 char realm[AST_MAX_EXTENSION]; /*!< Realm in which these credentials are valid */
817 char username[256]; /*!< Username */
818 char secret[256]; /*!< Secret */
819 char md5secret[256]; /*!< MD5Secret */
820 struct sip_auth *next; /*!< Next auth structure in list */
823 /*! \brief T.38 channel settings (at some point we need to make this alloc'ed */
824 struct t38properties {
825 enum t38state state; /*!< T.38 state */
826 struct ast_control_t38_parameters our_parms;
827 struct ast_control_t38_parameters their_parms;
830 /*! \brief generic struct to map between strings and integers.
831 * Fill it with x-s pairs, terminate with an entry with s = NULL;
832 * Then you can call map_x_s(...) to map an integer to a string,
833 * and map_s_x() for the string -> integer mapping.
840 /*! \brief Structure to handle SIP transfers. Dynamically allocated when needed
841 \note OEJ: Should be moved to string fields */
843 char refer_to[AST_MAX_EXTENSION]; /*!< Place to store REFER-TO extension */
844 char refer_to_domain[AST_MAX_EXTENSION]; /*!< Place to store REFER-TO domain */
845 char refer_to_urioption[AST_MAX_EXTENSION]; /*!< Place to store REFER-TO uri options */
846 char refer_to_context[AST_MAX_EXTENSION]; /*!< Place to store REFER-TO context */
847 char referred_by[AST_MAX_EXTENSION]; /*!< Place to store REFERRED-BY extension */
848 char referred_by_name[AST_MAX_EXTENSION]; /*!< Place to store REFERRED-BY extension */
849 char refer_contact[AST_MAX_EXTENSION]; /*!< Place to store Contact info from a REFER extension */
850 char replaces_callid[SIPBUFSIZE]; /*!< Replace info: callid */
851 char replaces_callid_totag[SIPBUFSIZE/2]; /*!< Replace info: to-tag */
852 char replaces_callid_fromtag[SIPBUFSIZE/2]; /*!< Replace info: from-tag */
853 struct sip_pvt *refer_call; /*!< Call we are referring. This is just a reference to a
854 * dialog owned by someone else, so we should not destroy
855 * it when the sip_refer object goes.
857 int attendedtransfer; /*!< Attended or blind transfer? */
858 int localtransfer; /*!< Transfer to local domain? */
859 enum referstatus status; /*!< REFER status */
862 /*! \brief Struct to handle custom SIP notify requests. Dynamically allocated when needed */
864 struct ast_variable *headers;
865 struct ast_str *content;
868 /*! \brief Structure that encapsulates all attributes related to running
869 * SIP Session-Timers feature on a per dialog basis.
872 int st_active; /*!< Session-Timers on/off */
873 int st_interval; /*!< Session-Timers negotiated session refresh interval */
874 int st_schedid; /*!< Session-Timers ast_sched scheduler id */
875 enum st_refresher st_ref; /*!< Session-Timers session refresher */
876 int st_expirys; /*!< Session-Timers number of expirys */
877 int st_active_peer_ua; /*!< Session-Timers on/off in peer UA */
878 int st_cached_min_se; /*!< Session-Timers cached Min-SE */
879 int st_cached_max_se; /*!< Session-Timers cached Session-Expires */
880 enum st_mode st_cached_mode; /*!< Session-Timers cached M.O. */
881 enum st_refresher st_cached_ref; /*!< Session-Timers cached refresher */
882 unsigned char quit_flag:1; /*!< Stop trying to lock; just quit */
886 /*! \brief Structure that encapsulates all attributes related to configuration
887 * of SIP Session-Timers feature on a per user/peer basis.
890 enum st_mode st_mode_oper; /*!< Mode of operation for Session-Timers */
891 enum st_refresher st_ref; /*!< Session-Timer refresher */
892 int st_min_se; /*!< Lowest threshold for session refresh interval */
893 int st_max_se; /*!< Highest threshold for session refresh interval */
896 /*! \brief Structure for remembering offered media in an INVITE, to make sure we reply
897 to all media streams. In theory. In practise, we try our best. */
898 struct offered_media {
903 /*! \brief Structure used for each SIP dialog, ie. a call, a registration, a subscribe.
904 * Created and initialized by sip_alloc(), the descriptor goes into the list of
905 * descriptors (dialoglist).
908 struct sip_pvt *next; /*!< Next dialog in chain */
909 enum invitestates invitestate; /*!< Track state of SIP_INVITEs */
910 int method; /*!< SIP method that opened this dialog */
911 AST_DECLARE_STRING_FIELDS(
912 AST_STRING_FIELD(callid); /*!< Global CallID */
913 AST_STRING_FIELD(randdata); /*!< Random data */
914 AST_STRING_FIELD(accountcode); /*!< Account code */
915 AST_STRING_FIELD(realm); /*!< Authorization realm */
916 AST_STRING_FIELD(nonce); /*!< Authorization nonce */
917 AST_STRING_FIELD(opaque); /*!< Opaque nonsense */
918 AST_STRING_FIELD(qop); /*!< Quality of Protection, since SIP wasn't complicated enough yet. */
919 AST_STRING_FIELD(domain); /*!< Authorization domain */
920 AST_STRING_FIELD(from); /*!< The From: header */
921 AST_STRING_FIELD(useragent); /*!< User agent in SIP request */
922 AST_STRING_FIELD(exten); /*!< Extension where to start */
923 AST_STRING_FIELD(context); /*!< Context for this call */
924 AST_STRING_FIELD(subscribecontext); /*!< Subscribecontext */
925 AST_STRING_FIELD(subscribeuri); /*!< Subscribecontext */
926 AST_STRING_FIELD(fromdomain); /*!< Domain to show in the from field */
927 AST_STRING_FIELD(fromuser); /*!< User to show in the user field */
928 AST_STRING_FIELD(fromname); /*!< Name to show in the user field */
929 AST_STRING_FIELD(tohost); /*!< Host we should put in the "to" field */
930 AST_STRING_FIELD(todnid); /*!< DNID of this call (overrides host) */
931 AST_STRING_FIELD(language); /*!< Default language for this call */
932 AST_STRING_FIELD(mohinterpret); /*!< MOH class to use when put on hold */
933 AST_STRING_FIELD(mohsuggest); /*!< MOH class to suggest when putting a peer on hold */
934 AST_STRING_FIELD(rdnis); /*!< Referring DNIS */
935 AST_STRING_FIELD(redircause); /*!< Referring cause */
936 AST_STRING_FIELD(theirtag); /*!< Their tag */
937 AST_STRING_FIELD(username); /*!< [user] name */
938 AST_STRING_FIELD(peername); /*!< [peer] name, not set if [user] */
939 AST_STRING_FIELD(authname); /*!< Who we use for authentication */
940 AST_STRING_FIELD(uri); /*!< Original requested URI */
941 AST_STRING_FIELD(okcontacturi); /*!< URI from the 200 OK on INVITE */
942 AST_STRING_FIELD(peersecret); /*!< Password */
943 AST_STRING_FIELD(peermd5secret);
944 AST_STRING_FIELD(cid_num); /*!< Caller*ID number */
945 AST_STRING_FIELD(cid_name); /*!< Caller*ID name */
946 AST_STRING_FIELD(cid_tag); /*!< Caller*ID tag */
947 AST_STRING_FIELD(mwi_from); /*!< Name to place in the From header in outgoing NOTIFY requests */
948 AST_STRING_FIELD(fullcontact); /*!< The Contact: that the UA registers with us */
949 /* we only store the part in <brackets> in this field. */
950 AST_STRING_FIELD(our_contact); /*!< Our contact header */
951 AST_STRING_FIELD(url); /*!< URL to be sent with next message to peer */
952 AST_STRING_FIELD(parkinglot); /*!< Parkinglot */
953 AST_STRING_FIELD(engine); /*!< RTP engine to use */
954 AST_STRING_FIELD(dialstring); /*!< The dialstring used to call this SIP endpoint */
956 char via[128]; /*!< Via: header */
957 int maxforwards; /*!< SIP Loop prevention */
958 struct sip_socket socket; /*!< The socket used for this dialog */
959 unsigned int ocseq; /*!< Current outgoing seqno */
960 unsigned int icseq; /*!< Current incoming seqno */
961 ast_group_t callgroup; /*!< Call group */
962 ast_group_t pickupgroup; /*!< Pickup group */
963 int lastinvite; /*!< Last Cseq of invite */
964 struct ast_flags flags[3]; /*!< SIP_ flags */
966 /* boolean flags that don't belong in flags */
967 unsigned short do_history:1; /*!< Set if we want to record history */
968 unsigned short alreadygone:1; /*!< the peer has sent a message indicating termination of the dialog */
969 unsigned short needdestroy:1; /*!< this dialog needs to be destroyed by the monitor thread */
970 unsigned short final_destruction_scheduled:1; /*!< final dialog destruction is scheduled. Keep dialog
971 * around until then to handle retransmits. */
972 unsigned short outgoing_call:1; /*!< this is an outgoing call */
973 unsigned short answered_elsewhere:1; /*!< This call is cancelled due to answer on another channel */
974 unsigned short novideo:1; /*!< Didn't get video in invite, don't offer */
975 unsigned short notext:1; /*!< Text not supported (?) */
976 unsigned short session_modify:1; /*!< Session modification request true/false */
977 unsigned short route_persistent:1; /*!< Is this the "real" route? */
978 unsigned short autoframing:1; /*!< Whether to use our local configuration for frame sizes (off)
979 * or respect the other endpoint's request for frame sizes (on)
982 unsigned short req_secure_signaling:1;/*!< Whether we are required to have secure signaling or not */
983 char tag[11]; /*!< Our tag for this session */
984 int timer_t1; /*!< SIP timer T1, ms rtt */
985 int timer_b; /*!< SIP timer B, ms */
986 unsigned int sipoptions; /*!< Supported SIP options on the other end */
987 unsigned int reqsipoptions; /*!< Required SIP options on the other end */
988 struct ast_codec_pref prefs; /*!< codec prefs */
989 format_t capability; /*!< Special capability (codec) */
990 format_t jointcapability; /*!< Supported capability at both ends (codecs) */
991 format_t peercapability; /*!< Supported peer capability */
992 format_t prefcodec; /*!< Preferred codec (outbound only) */
993 int noncodeccapability; /*!< DTMF RFC2833 telephony-event */
994 int jointnoncodeccapability; /*!< Joint Non codec capability */
995 format_t redircodecs; /*!< Redirect codecs */
996 int maxcallbitrate; /*!< Maximum Call Bitrate for Video Calls */
997 int t38_maxdatagram; /*!< T.38 FaxMaxDatagram override */
998 int request_queue_sched_id; /*!< Scheduler ID of any scheduled action to process queued requests */
999 int provisional_keepalive_sched_id; /*!< Scheduler ID for provisional responses that need to be sent out to avoid cancellation */
1000 const char *last_provisional; /*!< The last successfully transmitted provisonal response message */
1001 int authtries; /*!< Times we've tried to authenticate */
1002 struct sip_proxy *outboundproxy; /*!< Outbound proxy for this dialog. Use ref_proxy to set this instead of setting it directly*/
1003 struct t38properties t38; /*!< T38 settings */
1004 struct ast_sockaddr udptlredirip; /*!< Where our T.38 UDPTL should be going if not to us */
1005 struct ast_udptl *udptl; /*!< T.38 UDPTL session */
1006 int callingpres; /*!< Calling presentation */
1007 int expiry; /*!< How long we take to expire */
1008 int sessionversion; /*!< SDP Session Version */
1009 int sessionid; /*!< SDP Session ID */
1010 long branch; /*!< The branch identifier of this session */
1011 long invite_branch; /*!< The branch used when we sent the initial INVITE */
1012 int64_t sessionversion_remote; /*!< Remote UA's SDP Session Version */
1013 unsigned int portinuri:1; /*!< Non zero if a port has been specified, will also disable srv lookups */
1014 struct ast_sockaddr sa; /*!< Our peer */
1015 struct ast_sockaddr redirip; /*!< Where our RTP should be going if not to us */
1016 struct ast_sockaddr vredirip; /*!< Where our Video RTP should be going if not to us */
1017 struct ast_sockaddr tredirip; /*!< Where our Text RTP should be going if not to us */
1018 time_t lastrtprx; /*!< Last RTP received */
1019 time_t lastrtptx; /*!< Last RTP sent */
1020 int rtptimeout; /*!< RTP timeout time */
1021 struct ast_ha *directmediaha; /*!< Which IPs are allowed to interchange direct media with this peer - copied from sip_peer */
1022 struct ast_sockaddr recv; /*!< Received as */
1023 struct ast_sockaddr ourip; /*!< Our IP (as seen from the outside) */
1024 enum transfermodes allowtransfer; /*!< REFER: restriction scheme */
1025 struct ast_channel *owner; /*!< Who owns us (if we have an owner) */
1026 struct sip_route *route; /*!< Head of linked list of routing steps (fm Record-Route) */
1027 struct sip_notify *notify; /*!< Custom notify type */
1028 struct sip_auth *peerauth; /*!< Realm authentication */
1029 int noncecount; /*!< Nonce-count */
1030 unsigned int stalenonce:1; /*!< Marks the current nonce as responded too */
1031 char lastmsg[256]; /*!< Last Message sent/received */
1032 int amaflags; /*!< AMA Flags */
1033 int pendinginvite; /*!< Any pending INVITE or state NOTIFY (in subscribe pvt's) ? (seqno of this) */
1034 int glareinvite; /*!< A invite received while a pending invite is already present is stored here. Its seqno is the
1035 value. Since this glare invite's seqno is not the same as the pending invite's, it must be
1036 held in order to properly process acknowledgements for our 491 response. */
1037 struct sip_request initreq; /*!< Latest request that opened a new transaction
1039 NOT the request that opened the dialog */
1041 int initid; /*!< Auto-congest ID if appropriate (scheduler) */
1042 int waitid; /*!< Wait ID for scheduler after 491 or other delays */
1043 int autokillid; /*!< Auto-kill ID (scheduler) */
1044 int t38id; /*!< T.38 Response ID */
1045 struct sip_refer *refer; /*!< REFER: SIP transfer data structure */
1046 enum subscriptiontype subscribed; /*!< SUBSCRIBE: Is this dialog a subscription? */
1047 int stateid; /*!< SUBSCRIBE: ID for devicestate subscriptions */
1048 int laststate; /*!< SUBSCRIBE: Last known extension state */
1049 int dialogver; /*!< SUBSCRIBE: Version for subscription dialog-info */
1051 struct ast_dsp *dsp; /*!< Inband DTMF or Fax CNG tone Detection dsp */
1053 struct sip_peer *relatedpeer; /*!< If this dialog is related to a peer, which one
1054 Used in peerpoke, mwi subscriptions */
1055 struct sip_registry *registry; /*!< If this is a REGISTER dialog, to which registry */
1056 struct ast_rtp_instance *rtp; /*!< RTP Session */
1057 struct ast_rtp_instance *vrtp; /*!< Video RTP session */
1058 struct ast_rtp_instance *trtp; /*!< Text RTP session */
1059 struct sip_pkt *packets; /*!< Packets scheduled for re-transmission */
1060 struct sip_history_head *history; /*!< History of this SIP dialog */
1061 size_t history_entries; /*!< Number of entires in the history */
1062 struct ast_variable *chanvars; /*!< Channel variables to set for inbound call */
1063 AST_LIST_HEAD_NOLOCK(request_queue, sip_request) request_queue; /*!< Requests that arrived but could not be processed immediately */
1064 struct sip_invite_param *options; /*!< Options for INVITE */
1065 struct sip_st_dlg *stimer; /*!< SIP Session-Timers */
1066 struct sip_srtp *srtp; /*!< Structure to hold Secure RTP session data for audio */
1067 struct sip_srtp *vsrtp; /*!< Structure to hold Secure RTP session data for video */
1068 struct sip_srtp *tsrtp; /*!< Structure to hold Secure RTP session data for text */
1070 int red; /*!< T.140 RTP Redundancy */
1071 int hangupcause; /*!< Storage of hangupcause copied from our owner before we disconnect from the AST channel (only used at hangup) */
1073 struct sip_subscription_mwi *mwi; /*!< If this is a subscription MWI dialog, to which subscription */
1074 /*! The SIP methods supported by this peer. We get this information from the Allow header of the first
1075 * message we receive from an endpoint during a dialog.
1077 unsigned int allowed_methods;
1078 /*! Some peers are not trustworthy with their Allow headers, and so we need to override their wicked
1079 * ways through configuration. This is a copy of the peer's disallowed_methods, so that we can apply them
1080 * to the sip_pvt at various stages of dialog establishment
1082 unsigned int disallowed_methods;
1083 /*! When receiving an SDP offer, it is important to take note of what media types were offered.
1084 * By doing this, even if we don't want to answer a particular media stream with something meaningful, we can
1085 * still put an m= line in our answer with the port set to 0.
1087 * The reason for the length being 4 (OFFERED_MEDIA_COUNT) is that in this branch of Asterisk, the only media types supported are
1088 * image, audio, text, and video. Therefore we need to keep track of which types of media were offered.
1089 * Note that secure RTP defines new types of SDP media.
1091 * If we wanted to be 100% correct, we would keep a list of all media streams offered. That way we could respond
1092 * even to unknown media types, and we could respond to multiple streams of the same type. Such large-scale changes
1093 * are not a good idea for released branches, though, so we're compromising by just making sure that for the common cases:
1094 * audio and video, audio and T.38, and audio and text, we give the appropriate response to both media streams.
1096 * The large-scale changes would be a good idea for implementing during an SDP rewrite.
1098 struct offered_media offered_media[OFFERED_MEDIA_COUNT];
1099 struct ast_cc_config_params *cc_params;
1100 struct sip_epa_entry *epa_entry;
1101 int fromdomainport; /*!< Domain port to show in from field */
1104 /*! \brief sip packet - raw format for outbound packets that are sent or scheduled for transmission
1105 * Packets are linked in a list, whose head is in the struct sip_pvt they belong to.
1106 * Each packet holds a reference to the parent struct sip_pvt.
1107 * This structure is allocated in __sip_reliable_xmit() and only for packets that
1108 * require retransmissions.
1111 struct sip_pkt *next; /*!< Next packet in linked list */
1112 int retrans; /*!< Retransmission number */
1113 int method; /*!< SIP method for this packet */
1114 int seqno; /*!< Sequence number */
1115 char is_resp; /*!< 1 if this is a response packet (e.g. 200 OK), 0 if it is a request */
1116 char is_fatal; /*!< non-zero if there is a fatal error */
1117 int response_code; /*!< If this is a response, the response code */
1118 struct sip_pvt *owner; /*!< Owner AST call */
1119 int retransid; /*!< Retransmission ID */
1120 int timer_a; /*!< SIP timer A, retransmission timer */
1121 int timer_t1; /*!< SIP Timer T1, estimated RTT or 500 ms */
1122 struct timeval time_sent; /*!< When pkt was sent */
1123 int64_t retrans_stop_time; /*!< Time in ms after 'now' that retransmission must stop */
1124 int retrans_stop; /*!< Timeout is reached, stop retransmission */
1125 int packetlen; /*!< Length of packet */
1126 struct ast_str *data;
1130 * \brief A peer's mailbox
1132 * We could use STRINGFIELDS here, but for only two strings, it seems like
1133 * too much effort ...
1135 struct sip_mailbox {
1136 /*! Associated MWI subscription */
1137 struct ast_event_sub *event_sub;
1138 AST_LIST_ENTRY(sip_mailbox) entry;
1139 unsigned int delme:1;
1144 /*! \brief Structure for SIP peer data, we place calls to peers if registered or fixed IP address (host)
1146 /* XXX field 'name' must be first otherwise sip_addrcmp() will fail, as will astobj2 hashing of the structure */
1148 char name[80]; /*!< the unique name of this object */
1149 AST_DECLARE_STRING_FIELDS(
1150 AST_STRING_FIELD(secret); /*!< Password for inbound auth */
1151 AST_STRING_FIELD(md5secret); /*!< Password in MD5 */
1152 AST_STRING_FIELD(remotesecret); /*!< Remote secret (trunks, remote devices) */
1153 AST_STRING_FIELD(context); /*!< Default context for incoming calls */
1154 AST_STRING_FIELD(subscribecontext); /*!< Default context for subscriptions */
1155 AST_STRING_FIELD(username); /*!< Temporary username until registration */
1156 AST_STRING_FIELD(accountcode); /*!< Account code */
1157 AST_STRING_FIELD(tohost); /*!< If not dynamic, IP address */
1158 AST_STRING_FIELD(regexten); /*!< Extension to register (if regcontext is used) */
1159 AST_STRING_FIELD(fromuser); /*!< From: user when calling this peer */
1160 AST_STRING_FIELD(fromdomain); /*!< From: domain when calling this peer */
1161 AST_STRING_FIELD(fullcontact); /*!< Contact registered with us (not in sip.conf) */
1162 AST_STRING_FIELD(cid_num); /*!< Caller ID num */
1163 AST_STRING_FIELD(cid_name); /*!< Caller ID name */
1164 AST_STRING_FIELD(cid_tag); /*!< Caller ID tag */
1165 AST_STRING_FIELD(vmexten); /*!< Dialplan extension for MWI notify message*/
1166 AST_STRING_FIELD(language); /*!< Default language for prompts */
1167 AST_STRING_FIELD(mohinterpret); /*!< Music on Hold class */
1168 AST_STRING_FIELD(mohsuggest); /*!< Music on Hold class */
1169 AST_STRING_FIELD(parkinglot); /*!< Parkinglot */
1170 AST_STRING_FIELD(useragent); /*!< User agent in SIP request (saved from registration) */
1171 AST_STRING_FIELD(mwi_from); /*!< Name to place in From header for outgoing NOTIFY requests */
1172 AST_STRING_FIELD(engine); /*!< RTP Engine to use */
1173 AST_STRING_FIELD(unsolicited_mailbox); /*!< Mailbox to store received unsolicited MWI NOTIFY messages information in */
1175 struct sip_socket socket; /*!< Socket used for this peer */
1176 enum sip_transport default_outbound_transport; /*!< Peer Registration may change the default outbound transport.
1177 If register expires, default should be reset. to this value */
1178 /* things that don't belong in flags */
1179 unsigned short transports:3; /*!< Transports (enum sip_transport) that are acceptable for this peer */
1180 unsigned short is_realtime:1; /*!< this is a 'realtime' peer */
1181 unsigned short rt_fromcontact:1;/*!< copy fromcontact from realtime */
1182 unsigned short host_dynamic:1; /*!< Dynamic Peers register with Asterisk */
1183 unsigned short selfdestruct:1; /*!< Automatic peers need to destruct themselves */
1184 unsigned short the_mark:1; /*!< moved out of ASTOBJ into struct proper; That which bears the_mark should be deleted! */
1185 unsigned short autoframing:1; /*!< Whether to use our local configuration for frame sizes (off)
1186 * or respect the other endpoint's request for frame sizes (on)
1187 * for incoming calls
1189 unsigned short deprecated_username:1; /*!< If it's a realtime peer, are they using the deprecated "username" instead of "defaultuser" */
1190 struct sip_auth *auth; /*!< Realm authentication list */
1191 int amaflags; /*!< AMA Flags (for billing) */
1192 int callingpres; /*!< Calling id presentation */
1193 int inUse; /*!< Number of calls in use */
1194 int inRinging; /*!< Number of calls ringing */
1195 int onHold; /*!< Peer has someone on hold */
1196 int call_limit; /*!< Limit of concurrent calls */
1197 int t38_maxdatagram; /*!< T.38 FaxMaxDatagram override */
1198 int busy_level; /*!< Level of active channels where we signal busy */
1199 int maxforwards; /*!< SIP Loop prevention */
1200 enum transfermodes allowtransfer; /*! SIP Refer restriction scheme */
1201 struct ast_codec_pref prefs; /*!< codec prefs */
1203 unsigned int sipoptions; /*!< Supported SIP options */
1204 struct ast_flags flags[3]; /*!< SIP_ flags */
1206 /*! Mailboxes that this peer cares about */
1207 AST_LIST_HEAD_NOLOCK(, sip_mailbox) mailboxes;
1209 int maxcallbitrate; /*!< Maximum Bitrate for a video call */
1210 int expire; /*!< When to expire this peer registration */
1211 format_t capability; /*!< Codec capability */
1212 int rtptimeout; /*!< RTP timeout */
1213 int rtpholdtimeout; /*!< RTP Hold Timeout */
1214 int rtpkeepalive; /*!< Send RTP packets for keepalive */
1215 ast_group_t callgroup; /*!< Call group */
1216 ast_group_t pickupgroup; /*!< Pickup group */
1217 struct sip_proxy *outboundproxy;/*!< Outbound proxy for this peer */
1218 struct ast_dnsmgr_entry *dnsmgr;/*!< DNS refresh manager for peer */
1219 struct ast_sockaddr addr; /*!< IP address of peer */
1220 unsigned int portinuri:1; /*!< Whether the port should be included in the URI */
1221 struct sip_pvt *call; /*!< Call pointer */
1222 int pokeexpire; /*!< Qualification: When to expire poke (qualify= checking) */
1223 int lastms; /*!< Qualification: How long last response took (in ms), or -1 for no response */
1224 int maxms; /*!< Qualification: Max ms we will accept for the host to be up, 0 to not monitor */
1225 int qualifyfreq; /*!< Qualification: Qualification: How often to check for the host to be up */
1226 struct timeval ps; /*!< Qualification: Time for sending SIP OPTION in sip_pke_peer() */
1227 struct ast_sockaddr defaddr; /*!< Default IP address, used until registration */
1228 struct ast_ha *ha; /*!< Access control list */
1229 struct ast_ha *contactha; /*!< Restrict what IPs are allowed in the Contact header (for registration) */
1230 struct ast_ha *directmediaha; /*!< Restrict what IPs are allowed to interchange direct media with */
1231 struct ast_variable *chanvars; /*!< Variables to set for channel created by user */
1232 struct sip_pvt *mwipvt; /*!< Subscription for MWI */
1233 struct sip_st_cfg stimer; /*!< SIP Session-Timers */
1234 int timer_t1; /*!< The maximum T1 value for the peer */
1235 int timer_b; /*!< The maximum timer B (transaction timeouts) */
1236 int fromdomainport; /*!< The From: domain port */
1238 /*XXX Seems like we suddenly have two flags with the same content. Why? To be continued... */
1239 enum sip_peer_type type; /*!< Distinguish between "user" and "peer" types. This is used solely for CLI and manager commands */
1240 unsigned int disallowed_methods;
1241 struct ast_cc_config_params *cc_params;
1245 * \brief Registrations with other SIP proxies
1247 * Created by sip_register(), the entry is linked in the 'regl' list,
1248 * and never deleted (other than at 'sip reload' or module unload times).
1249 * The entry always has a pending timeout, either waiting for an ACK to
1250 * the REGISTER message (in which case we have to retransmit the request),
1251 * or waiting for the next REGISTER message to be sent (either the initial one,
1252 * or once the previously completed registration one expires).
1253 * The registration can be in one of many states, though at the moment
1254 * the handling is a bit mixed.
1256 * \todo Convert this to astobj2
1258 struct sip_registry {
1259 ASTOBJ_COMPONENTS_FULL(struct sip_registry,1,1);
1260 AST_DECLARE_STRING_FIELDS(
1261 AST_STRING_FIELD(callid); /*!< Global Call-ID */
1262 AST_STRING_FIELD(realm); /*!< Authorization realm */
1263 AST_STRING_FIELD(nonce); /*!< Authorization nonce */
1264 AST_STRING_FIELD(opaque); /*!< Opaque nonsense */
1265 AST_STRING_FIELD(qop); /*!< Quality of Protection, since SIP wasn't complicated enough yet. */
1266 AST_STRING_FIELD(authdomain); /*!< Authorization domain */
1267 AST_STRING_FIELD(regdomain); /*!< Registration doamin */
1268 AST_STRING_FIELD(username); /*!< Who we are registering as */
1269 AST_STRING_FIELD(authuser); /*!< Who we *authenticate* as */
1270 AST_STRING_FIELD(hostname); /*!< Domain or host we register to */
1271 AST_STRING_FIELD(secret); /*!< Password in clear text */
1272 AST_STRING_FIELD(md5secret); /*!< Password in md5 */
1273 AST_STRING_FIELD(callback); /*!< Contact extension */
1274 AST_STRING_FIELD(peername); /*!< Peer registering to */
1276 enum sip_transport transport; /*!< Transport for this registration UDP, TCP or TLS */
1277 int portno; /*!< Optional port override */
1278 int regdomainport; /*!< Port override for domainport */
1279 int expire; /*!< Sched ID of expiration */
1280 int configured_expiry; /*!< Configured value to use for the Expires header */
1281 int expiry; /*!< Negotiated value used for the Expires header */
1282 int regattempts; /*!< Number of attempts (since the last success) */
1283 int timeout; /*!< sched id of sip_reg_timeout */
1284 int refresh; /*!< How often to refresh */
1285 struct sip_pvt *call; /*!< create a sip_pvt structure for each outbound "registration dialog" in progress */
1286 enum sipregistrystate regstate; /*!< Registration state (see above) */
1287 struct timeval regtime; /*!< Last successful registration time */
1288 int callid_valid; /*!< 0 means we haven't chosen callid for this registry yet. */
1289 unsigned int ocseq; /*!< Sequence number we got to for REGISTERs for this registry */
1290 struct ast_dnsmgr_entry *dnsmgr; /*!< DNS refresh manager for register */
1291 struct ast_sockaddr us; /*!< Who the server thinks we are */
1292 int noncecount; /*!< Nonce-count */
1293 char lastmsg[256]; /*!< Last Message sent/received */
1296 struct tcptls_packet {
1297 AST_LIST_ENTRY(tcptls_packet) entry;
1298 struct ast_str *data;
1301 /*! \brief Definition of a thread that handles a socket */
1302 struct sip_threadinfo {
1304 int alert_pipe[2]; /*! Used to alert tcptls thread when packet is ready to be written */
1306 struct ast_tcptls_session_instance *tcptls_session;
1307 enum sip_transport type; /*!< We keep a copy of the type here so we can display it in the connection list */
1308 AST_LIST_HEAD_NOLOCK(, tcptls_packet) packet_q;
1312 * \brief Definition of an MWI subscription to another server
1314 * \todo Convert this to astobj2.
1316 struct sip_subscription_mwi {
1317 ASTOBJ_COMPONENTS_FULL(struct sip_subscription_mwi,1,1);
1318 AST_DECLARE_STRING_FIELDS(
1319 AST_STRING_FIELD(username); /*!< Who we are sending the subscription as */
1320 AST_STRING_FIELD(authuser); /*!< Who we *authenticate* as */
1321 AST_STRING_FIELD(hostname); /*!< Domain or host we subscribe to */
1322 AST_STRING_FIELD(secret); /*!< Password in clear text */
1323 AST_STRING_FIELD(mailbox); /*!< Mailbox store to put MWI into */
1325 enum sip_transport transport; /*!< Transport to use */
1326 int portno; /*!< Optional port override */
1327 int resub; /*!< Sched ID of resubscription */
1328 unsigned int subscribed:1; /*!< Whether we are currently subscribed or not */
1329 struct sip_pvt *call; /*!< Outbound subscription dialog */
1330 struct ast_dnsmgr_entry *dnsmgr; /*!< DNS refresh manager for subscription */
1331 struct ast_sockaddr us; /*!< Who the server thinks we are */
1335 * SIP PUBLISH support!
1336 * PUBLISH support was added to chan_sip due to its use in the call-completion
1337 * event package. In order to suspend and unsuspend monitoring of a called party,
1338 * a PUBLISH message must be sent. Rather than try to hack in PUBLISH transmission
1339 * and reception solely for the purposes of handling call-completion-related messages,
1340 * an effort has been made to create a generic framework for handling PUBLISH messages.
1342 * There are two main components to the effort, the event publication agent (EPA) and
1343 * the event state compositor (ESC). Both of these terms appear in RFC 3903, and the
1344 * implementation in Asterisk conforms to the defintions there. An EPA is a UAC that
1345 * transmits PUBLISH requests. An ESC is a UAS that receives PUBLISH requests and
1346 * acts appropriately based on the content of those requests.
1349 * The main structure in chan_sip is the event_state_compositor. There is an
1350 * event_state_compositor structure for each event package supported (as of Nov 2009
1351 * this is only the call-completion package). The structure contains data which is
1352 * intrinsic to the event package itself, such as the name of the package and a set
1353 * of callbacks for handling incoming PUBLISH requests. In addition, the
1354 * event_state_compositor struct contains an ao2_container of sip_esc_entries.
1356 * A sip_esc_entry corresponds to an entity which has sent a PUBLISH to Asterisk. We are
1357 * able to match the incoming PUBLISH to a sip_esc_entry using the Sip-If-Match header
1358 * of the message. Of course, if none is present, then a new sip_esc_entry will be created.
1360 * Once it is determined what type of PUBLISH request has come in (from RFC 3903, it may
1361 * be an initial, modify, refresh, or remove), then the event package-specific callbacks
1362 * may be called. If your event package doesn't need to take any specific action for a
1363 * specific PUBLISH type, it is perfectly safe to not define the callback at all. The callback
1364 * only needs to take care of application-specific information. If there is a problem, it is
1365 * up to the callback to take care of sending an appropriate 4xx or 5xx response code. In such
1366 * a case, the callback should return -1. This will tell the function that called the handler
1367 * that an appropriate error response has been sent. If the callback returns 0, however, then
1368 * the caller of the callback will generate a new entity tag and send a 200 OK response.
1370 * ESC entries are reference-counted, however as an implementor of a specific event package,
1371 * this should be transparent, since the reference counts are handled by the general ESC
1375 * The event publication agent in chan_sip is structured quite a bit differently than the
1376 * ESC. With an ESC, an appropriate entry has to be found based on the contents of an incoming
1377 * PUBLISH message. With an EPA, the application interested in sending the PUBLISH can maintain
1378 * a reference to the appropriate EPA entry instead. Similarly, when matching a PUBLISH response
1379 * to an appropriate EPA entry, the sip_pvt can maintain a reference to the corresponding
1380 * EPA entry. The result of this train of thought is that there is no compelling reason to
1381 * maintain a container of these entries.
1383 * Instead, there is only the sip_epa_entry structure. Every sip_epa_entry has an entity tag
1384 * that it maintains so that subsequent PUBLISH requests will be identifiable by the ESC on
1385 * the far end. In addition, there is a static_data field which contains information that is
1386 * common to all sip_epa_entries for a specific event package. This static data includes the
1387 * name of the event package and callbacks for handling specific responses for outgoing PUBLISHes.
1388 * Also, there is a field for pointing to instance-specific data. This can include the current
1389 * published state or other identifying information that is specific to an instance of an EPA
1390 * entry of a particular event package.
1392 * When an application wishes to send a PUBLISH request, it simply will call create_epa_entry,
1393 * followed by transmit_publish in order to send the PUBLISH. That's all that is necessary.
1394 * Like with ESC entries, sip_epa_entries are reference counted. Unlike ESC entries, though,
1395 * sip_epa_entries reference counts have to be maintained to some degree by the application making
1396 * use of the sip_epa_entry. The application will acquire a reference to the EPA entry when it
1397 * calls create_epa_entry. When the application has finished using the EPA entry (which may not
1398 * be until after several PUBLISH transactions have taken place) it must use ao2_ref to decrease
1399 * the reference count by 1.
1403 * \brief The states that can be represented in a SIP call-completion PUBLISH
1405 enum sip_cc_publish_state {
1406 /*! Closed, i.e. unavailable */
1408 /*! Open, i.e. available */
1413 * \brief The states that can be represented in a SIP call-completion NOTIFY
1415 enum sip_cc_notify_state {
1416 /*! Queued, i.e. unavailable */
1418 /*! Ready, i.e. available */
1423 * \brief The types of PUBLISH messages defined in RFC 3903
1425 enum sip_publish_type {
1430 * This actually is not defined in RFC 3903. We use this as a constant
1431 * to indicate that an incoming PUBLISH does not fit into any of the
1432 * other categories and is thus invalid.
1434 SIP_PUBLISH_UNKNOWN,
1439 * The first PUBLISH sent. This will contain a non-zero Expires header
1440 * as well as a body that indicates the current state of the endpoint
1441 * that has sent the message. The initial PUBLISH is the only type
1442 * of PUBLISH to not contain a Sip-If-Match header in it.
1444 SIP_PUBLISH_INITIAL,
1449 * Used to keep a published state from expiring. This will contain a
1450 * non-zero Expires header but no body since its purpose is not to
1453 SIP_PUBLISH_REFRESH,
1458 * Used to change state from its previous value. This will contain
1459 * a body updating the published state. May or may not contain an
1467 * Used to remove published state from an ESC. This will contain
1468 * an Expires header set to 0 and likely no body.
1474 * Data which is the same for all instances of an EPA for a
1475 * particular event package
1477 struct epa_static_data {
1478 /*! The event type */
1479 enum subscriptiontype event;
1481 * The name of the event as it would
1482 * appear in a SIP message
1486 * The callback called when a 200 OK is received on an outbound PUBLISH
1488 void (*handle_ok)(struct sip_pvt *, struct sip_request *, struct sip_epa_entry *);
1490 * The callback called when an error response is received on an outbound PUBLISH
1492 void (*handle_error)(struct sip_pvt *, const int resp, struct sip_request *, struct sip_epa_entry *);
1494 * Destructor to call to clean up instance data
1496 void (*destructor)(void *instance_data);
1500 * \brief backend for an event publication agent
1502 struct epa_backend {
1503 const struct epa_static_data *static_data;
1504 AST_LIST_ENTRY(epa_backend) next;
1507 struct sip_epa_entry {
1509 * When we are going to send a publish, we need to
1510 * know the type of PUBLISH to send.
1512 enum sip_publish_type publish_type;
1514 * When we send a PUBLISH, we have to be
1515 * sure to include the entity tag that we
1516 * received in the previous response.
1518 char entity_tag[SIPBUFSIZE];
1520 * The destination to which this EPA should send
1521 * PUBLISHes. This may be the name of a SIP peer
1524 char destination[SIPBUFSIZE];
1526 * The body of the most recently-sent PUBLISH message.
1527 * This is useful for situations such as authentication,
1528 * in which we must send a message identical to the
1529 * one previously sent
1531 char body[SIPBUFSIZE];
1533 * Every event package has some constant data and
1534 * callbacks that all instances will share. This
1535 * data resides in this field.
1537 const struct epa_static_data *static_data;
1539 * In addition to the static data that all instances
1540 * of sip_epa_entry will have, each instance will
1541 * require its own instance-specific data.
1543 void *instance_data;
1547 * \brief Instance data for a Call completion EPA entry
1549 struct cc_epa_entry {
1551 * The core ID of the CC transaction
1552 * for which this EPA entry belongs. This
1553 * essentially acts as a unique identifier
1554 * for the entry and is used in the hash
1555 * and comparison functions
1559 * We keep the last known state of the
1560 * device in question handy in case
1561 * it needs to be known by a third party.
1562 * Also, in the case where for some reason
1563 * we get asked to transmit state that we
1564 * already sent, we can just ignore the
1567 enum sip_cc_publish_state current_state;
1570 struct event_state_compositor;
1573 * \brief common ESC items for all event types
1575 * The entity_id field serves as a means by which
1576 * A specific entry may be found.
1578 struct sip_esc_entry {
1580 * The name of the party who
1581 * sent us the PUBLISH. This will more
1582 * than likely correspond to a peer name.
1584 * This field's utility isn't really that
1585 * great. It's mainly just a user-recognizable
1586 * handle that can be printed in debug messages.
1588 const char *device_name;
1590 * The event package for which this esc_entry
1591 * exists. Most of the time this isn't really
1592 * necessary since you'll have easy access to the
1593 * ESC which contains this entry. However, in
1594 * some circumstances, we won't have the ESC
1599 * The entity ID used when corresponding
1600 * with the EPA on the other side. As the
1601 * ESC, we generate an entity ID for each
1602 * received PUBLISH and store it in this
1605 char entity_tag[30];
1607 * The ID for the scheduler. We schedule
1608 * destruction of a sip_esc_entry when we
1609 * receive a PUBLISH. The destruction is
1610 * scheduled for the duration received in
1611 * the Expires header.
1615 * Each ESC entry will be for a specific
1616 * event type. Those entries will need to
1617 * carry data which is intrinsic to the
1618 * ESC entry but which is specific to
1621 void *event_specific_data;
1624 typedef int (* const esc_publish_callback)(struct sip_pvt *, struct sip_request *, struct event_state_compositor *, struct sip_esc_entry *);
1627 * \brief Callbacks for SIP ESCs
1630 * The names of the callbacks are self-explanatory. The
1631 * corresponding handler is called whenever the specific
1632 * type of PUBLISH is received.
1634 struct sip_esc_publish_callbacks {
1635 const esc_publish_callback initial_handler;
1636 const esc_publish_callback refresh_handler;
1637 const esc_publish_callback modify_handler;
1638 const esc_publish_callback remove_handler;
1641 struct sip_cc_agent_pvt {
1643 /* A copy of the original call's Call-ID.
1644 * We use this as a search key when attempting
1645 * to find a particular sip_pvt.
1647 char original_callid[SIPBUFSIZE];
1648 /* A copy of the exten called originally.
1649 * We use this to set the proper extension
1650 * to dial during the recall since the incoming
1651 * request URI is one that was generated just
1654 char original_exten[SIPBUFSIZE];
1655 /* A reference to the dialog which we will
1656 * be sending a NOTIFY on when it comes time
1659 struct sip_pvt *subscribe_pvt;
1660 /* When we send a NOTIFY, we include a URI
1661 * that should be used by the caller when he
1662 * wishes to send a PUBLISH or INVITE to us.
1663 * We store that URI here.
1665 char notify_uri[SIPBUFSIZE];
1666 /* When we advertise call completion to a caller,
1667 * we provide a URI for the caller to use when
1668 * he sends us a SUBSCRIBE. We store it for matching
1669 * purposes when we receive the SUBSCRIBE from the
1672 char subscribe_uri[SIPBUFSIZE];
1676 struct sip_monitor_instance {
1677 AST_DECLARE_STRING_FIELDS(
1678 AST_STRING_FIELD(subscribe_uri);
1679 AST_STRING_FIELD(notify_uri);
1680 AST_STRING_FIELD(peername);
1681 AST_STRING_FIELD(device_name);
1684 struct sip_pvt *subscription_pvt;
1685 struct sip_epa_entry *suspension_entry;
1689 * \brief uri parameters
1703 AST_LIST_ENTRY(contact) list;
1708 struct uriparams params;
1714 AST_LIST_HEAD_NOLOCK(contactliststruct, contact);
1716 /*! \brief List of well-known SIP options. If we get this in a require,
1717 we should check the list and answer accordingly. */
1718 static const struct cfsip_options {
1719 int id; /*!< Bitmap ID */
1720 int supported; /*!< Supported by Asterisk ? */
1721 char * const text; /*!< Text id, as in standard */
1722 } sip_options[] = { /* XXX used in 3 places */
1723 /* RFC3262: PRACK 100% reliability */
1724 { SIP_OPT_100REL, NOT_SUPPORTED, "100rel" },
1725 /* RFC3959: SIP Early session support */
1726 { SIP_OPT_EARLY_SESSION, NOT_SUPPORTED, "early-session" },
1727 /* SIMPLE events: RFC4662 */
1728 { SIP_OPT_EVENTLIST, NOT_SUPPORTED, "eventlist" },
1729 /* RFC 4916- Connected line ID updates */
1730 { SIP_OPT_FROMCHANGE, NOT_SUPPORTED, "from-change" },
1731 /* GRUU: Globally Routable User Agent URI's */
1732 { SIP_OPT_GRUU, NOT_SUPPORTED, "gruu" },
1733 /* RFC4244 History info */
1734 { SIP_OPT_HISTINFO, NOT_SUPPORTED, "histinfo" },
1735 /* RFC3911: SIP Join header support */
1736 { SIP_OPT_JOIN, NOT_SUPPORTED, "join" },
1737 /* Disable the REFER subscription, RFC 4488 */
1738 { SIP_OPT_NOREFERSUB, NOT_SUPPORTED, "norefersub" },
1739 /* SIP outbound - the final NAT battle - draft-sip-outbound */
1740 { SIP_OPT_OUTBOUND, NOT_SUPPORTED, "outbound" },
1741 /* RFC3327: Path support */
1742 { SIP_OPT_PATH, NOT_SUPPORTED, "path" },
1743 /* RFC3840: Callee preferences */
1744 { SIP_OPT_PREF, NOT_SUPPORTED, "pref" },
1745 /* RFC3312: Precondition support */
1746 { SIP_OPT_PRECONDITION, NOT_SUPPORTED, "precondition" },
1747 /* RFC3323: Privacy with proxies*/
1748 { SIP_OPT_PRIVACY, NOT_SUPPORTED, "privacy" },
1749 /* RFC-ietf-sip-uri-list-conferencing-02.txt conference invite lists */
1750 { SIP_OPT_RECLISTINV, NOT_SUPPORTED, "recipient-list-invite" },
1751 /* RFC-ietf-sip-uri-list-subscribe-02.txt - subscription lists */
1752 { SIP_OPT_RECLISTSUB, NOT_SUPPORTED, "recipient-list-subscribe" },
1753 /* RFC3891: Replaces: header for transfer */
1754 { SIP_OPT_REPLACES, SUPPORTED, "replaces" },
1755 /* One version of Polycom firmware has the wrong label */
1756 { SIP_OPT_REPLACES, SUPPORTED, "replace" },
1757 /* RFC4412 Resource priorities */
1758 { SIP_OPT_RESPRIORITY, NOT_SUPPORTED, "resource-priority" },
1759 /* RFC3329: Security agreement mechanism */
1760 { SIP_OPT_SEC_AGREE, NOT_SUPPORTED, "sec_agree" },
1761 /* RFC4092: Usage of the SDP ANAT Semantics in the SIP */
1762 { SIP_OPT_SDP_ANAT, NOT_SUPPORTED, "sdp-anat" },
1763 /* RFC4028: SIP Session-Timers */
1764 { SIP_OPT_TIMER, SUPPORTED, "timer" },
1765 /* RFC4538: Target-dialog */
1766 { SIP_OPT_TARGET_DIALOG,NOT_SUPPORTED, "tdialog" },