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