2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2006, Digium, Inc.
6 * Mark Spencer <markster@digium.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
20 * \brief General Asterisk PBX channel definitions.
22 * \arg \ref Def_Channel
23 * \arg \ref channel_drivers
26 /*! \page Def_Channel Asterisk Channels
27 \par What is a Channel?
28 A phone call through Asterisk consists of an incoming
29 connection and an outbound connection. Each call comes
30 in through a channel driver that supports one technology,
31 like SIP, DAHDI, IAX2 etc.
33 Each channel driver, technology, has it's own private
34 channel or dialog structure, that is technology-dependent.
35 Each private structure is "owned" by a generic Asterisk
36 channel structure, defined in channel.h and handled by
39 This happens when an incoming call arrives to Asterisk
40 -# Call arrives on a channel driver interface
41 -# Channel driver creates a PBX channel and starts a
42 pbx thread on the channel
43 -# The dial plan is executed
44 -# At this point at least two things can happen:
45 -# The call is answered by Asterisk and
46 Asterisk plays a media stream or reads media
47 -# The dial plan forces Asterisk to create an outbound
48 call somewhere with the dial (see \ref app_dial.c)
52 \par Bridging channels
53 If Asterisk dials out this happens:
54 -# Dial creates an outbound PBX channel and asks one of the
55 channel drivers to create a call
56 -# When the call is answered, Asterisk bridges the media streams
57 so the caller on the first channel can speak with the callee
58 on the second, outbound channel
59 -# In some cases where we have the same technology on both
60 channels and compatible codecs, a native bridge is used.
61 In a native bridge, the channel driver handles forwarding
62 of incoming audio to the outbound stream internally, without
63 sending audio frames through the PBX.
64 -# In SIP, theres an "external native bridge" where Asterisk
65 redirects the endpoint, so audio flows directly between the
66 caller's phone and the callee's phone. Signalling stays in
67 Asterisk in order to be able to provide a proper CDR record
71 \par Masquerading channels
72 In some cases, a channel can masquerade itself into another
73 channel. This happens frequently in call transfers, where
74 a new channel takes over a channel that is already involved
75 in a call. The new channel sneaks in and takes over the bridge
76 and the old channel, now a zombie, is hung up.
79 \arg channel.c - generic functions
80 \arg channel.h - declarations of functions, flags and structures
81 \arg translate.h - Transcoding support functions
82 \arg \ref channel_drivers - Implemented channel drivers
83 \arg \ref Def_Frame Asterisk Multimedia Frames
87 /*! \page Def_Bridge Asterisk Channel Bridges
89 In Asterisk, there's several media bridges.
91 The Core bridge handles two channels (a "phone call") and bridge
94 The conference bridge (meetme) handles several channels simultaneously
95 with the support of an external timer (DAHDI timer). This is used
96 not only by the Conference application (meetme) but also by the
97 page application and the SLA system introduced in 1.4.
98 The conference bridge does not handle video.
100 When two channels of the same type connect, the channel driver
101 or the media subsystem used by the channel driver (i.e. RTP)
102 can create a native bridge without sending media through the
105 Native bridging can be disabled by a number of reasons,
106 like DTMF being needed by the core or codecs being incompatible
107 so a transcoding module is needed.
110 \li \see ast_channel_early_bridge()
111 \li \see ast_channel_bridge()
112 \li \see app_meetme.c
113 \li \ref AstRTPbridge
114 \li \see ast_rtp_bridge()
118 /*! \page AstFileDesc File descriptors
119 Asterisk File descriptors are connected to each channel (see \ref Def_Channel)
120 in the \ref ast_channel structure.
123 #ifndef _ASTERISK_CHANNEL_H
124 #define _ASTERISK_CHANNEL_H
126 #include "asterisk/abstract_jb.h"
127 #include "asterisk/astobj2.h"
129 #include "asterisk/poll-compat.h"
131 #if defined(__cplusplus) || defined(c_plusplus)
135 #define AST_MAX_EXTENSION 80 /*!< Max length of an extension */
136 #define AST_MAX_CONTEXT 80 /*!< Max length of a context */
137 #define AST_CHANNEL_NAME 80 /*!< Max length of an ast_channel name */
138 #define MAX_LANGUAGE 20 /*!< Max length of the language setting */
139 #define MAX_MUSICCLASS 80 /*!< Max length of the music class setting */
141 #include "asterisk/frame.h"
142 #include "asterisk/sched.h"
143 #include "asterisk/chanvars.h"
144 #include "asterisk/config.h"
145 #include "asterisk/lock.h"
146 #include "asterisk/cdr.h"
147 #include "asterisk/utils.h"
148 #include "asterisk/linkedlists.h"
149 #include "asterisk/stringfields.h"
150 #include "asterisk/datastore.h"
152 #define DATASTORE_INHERIT_FOREVER INT_MAX
154 #define AST_MAX_FDS 10
156 * We have AST_MAX_FDS file descriptors in a channel.
157 * Some of them have a fixed use:
159 #define AST_ALERT_FD (AST_MAX_FDS-1) /*!< used for alertpipe */
160 #define AST_TIMING_FD (AST_MAX_FDS-2) /*!< used for timingfd */
161 #define AST_AGENT_FD (AST_MAX_FDS-3) /*!< used by agents for pass through */
162 #define AST_GENERATOR_FD (AST_MAX_FDS-4) /*!< used by generator */
164 enum ast_bridge_result {
165 AST_BRIDGE_COMPLETE = 0,
166 AST_BRIDGE_FAILED = -1,
167 AST_BRIDGE_FAILED_NOWARN = -2,
168 AST_BRIDGE_RETRY = -3,
171 typedef unsigned long long ast_group_t;
173 /*! \todo Add an explanation of an Asterisk generator
175 struct ast_generator {
176 void *(*alloc)(struct ast_channel *chan, void *params);
177 void (*release)(struct ast_channel *chan, void *data);
178 /*! This function gets called with the channel unlocked, but is called in
179 * the context of the channel thread so we know the channel is not going
180 * to disappear. This callback is responsible for locking the channel as
182 int (*generate)(struct ast_channel *chan, void *data, int len, int samples);
183 /*! This gets called when DTMF_END frames are read from the channel */
184 void (*digit)(struct ast_channel *chan, char digit);
189 * \brief Information needed to specify a subaddress in a call.
190 * \note All string fields here are malloc'ed, so they need to be
191 * freed when the structure is deleted.
192 * \note NULL and "" must be considered equivalent.
194 struct ast_party_subaddress {
196 * \brief Malloced subaddress string.
197 * \note If the subaddress type is user specified then the subaddress is
198 * a string of ASCII hex because the actual subaddress is likely BCD encoded.
202 * \brief Q.931 subaddress type.
209 * \brief TRUE if odd number of address signals
210 * \note The odd/even indicator is used when the type of subaddress is
211 * user_specified and the coding is BCD.
213 unsigned char odd_even_indicator;
214 /*! \brief TRUE if the subaddress information is valid/present */
219 * \brief Structure for all kinds of caller ID identifications.
220 * \note All string fields here are malloc'ed, so they need to be
221 * freed when the structure is deleted.
222 * Also, NULL and "" must be considered equivalent.
224 * \note SIP and IAX2 has utf8 encoded Unicode caller ID names.
225 * In some cases, we also have an alternative (RPID) E.164 number that can be used
226 * as caller ID on numeric E.164 phone networks (DAHDI or SIP/IAX2 to PSTN gateway).
228 * \todo Implement settings for transliteration between UTF8 caller ID names in
229 * to Ascii Caller ID's (DAHDI). Östen Åsklund might be transliterated into
230 * Osten Asklund or Oesten Aasklund depending upon language and person...
231 * We need automatic routines for incoming calls and static settings for
234 struct ast_callerid {
236 * \brief Malloc'd Dialed Number Identifier
237 * (Field will eventually move to struct ast_channel.dialed.number)
242 * \brief Malloc'd Caller Number
243 * (Field will eventually move to struct ast_channel.caller.id.number)
248 * \brief Malloc'd Caller Name (ASCII)
249 * (Field will eventually move to struct ast_channel.caller.id.name)
254 * \brief Malloc'd Automatic Number Identification (ANI)
255 * (Field will eventually move to struct ast_channel.caller.ani)
260 * \brief Malloc'd Redirecting Directory Number Information Service (RDNIS)
261 * (Field will eventually move to struct ast_channel.redirecting.from.number)
266 * \brief Callerid Q.931 encoded number presentation/screening fields
267 * (Field will eventually move to struct ast_channel.caller.id.number_presentation)
272 * \brief Callerid ANI 2 (Info digits)
273 * (Field will eventually move to struct ast_channel.caller.ani2)
278 * \brief Callerid Q.931 encoded type-of-number/numbering-plan fields
279 * \note Currently this value is mostly just passed around the system.
280 * The H.323 interfaces set the value from received messages and uses the value for sent messages.
281 * The DAHDI PRI interfaces set the value from received messages but does not use it for sent messages.
282 * You can read it and set it but only H.323 uses it.
283 * (Field will eventually move to struct ast_channel.caller.id.number_type)
288 * \brief Callerid Transit Network Select
289 * \note Currently this value is just passed around the system.
290 * You can read it and set it but it is never used for anything.
291 * (Field will eventually move to struct ast_channel.dialed.transit_network_select)
295 * \brief Caller id subaddress.
296 * (Field will eventually move to struct ast_channel.caller.id.subaddress)
298 struct ast_party_subaddress subaddress;
300 * \brief Dialed/Called subaddress.
301 * (Field will eventually move to struct ast_channel.dialed.subaddress)
303 struct ast_party_subaddress dialed_subaddress;
308 * \brief Information needed to identify an endpoint in a call.
309 * \note All string fields here are malloc'ed, so they need to be
310 * freed when the structure is deleted.
311 * \note NULL and "" must be considered equivalent.
313 struct ast_party_id {
314 /*! \brief Subscriber phone number (Malloced) */
317 /*! \brief Subscriber name (Malloced) */
320 /*! \brief Subscriber subaddress. */
321 struct ast_party_subaddress subaddress;
323 /*! \brief Q.931 encoded type-of-number/numbering-plan fields */
326 /*! \brief Q.931 encoded number presentation/screening fields */
327 int number_presentation;
332 * \brief Caller Party information.
333 * \note All string fields here are malloc'ed, so they need to be
334 * freed when the structure is deleted.
335 * \note NULL and "" must be considered equivalent.
337 struct ast_party_caller {
338 struct ast_party_id id; /*! \brief Caller party ID */
340 /*! \brief Automatic Number Identification (ANI) (Malloced) */
343 /*! \brief Automatic Number Identification 2 (Info Digits) */
349 * \brief Connected Line/Party information.
350 * \note All string fields here are malloc'ed, so they need to be
351 * freed when the structure is deleted.
352 * \note NULL and "" must be considered equivalent.
354 struct ast_party_connected_line {
355 struct ast_party_id id; /*! \brief Connected party ID */
358 * \brief Automatic Number Identification (ANI) (Malloced)
359 * \note Not really part of connected line data but needed to
360 * save the corresponding caller id value.
365 * \brief Automatic Number Identification 2 (Info Digits)
366 * \note Not really part of connected line data but needed to
367 * save the corresponding caller id value.
372 * \brief Information about the source of an update.
373 * \note enum AST_CONNECTED_LINE_UPDATE_SOURCE values
374 * for Normal-Answer and Call-transfer.
381 * \brief Redirecting Line information.
382 * RDNIS (Redirecting Directory Number Information Service)
383 * Where a call diversion or transfer was invoked.
384 * \note All string fields here are malloc'ed, so they need to be
385 * freed when the structure is deleted.
386 * \note NULL and "" must be considered equivalent.
388 struct ast_party_redirecting {
389 /*! \brief Who is redirecting the call (Sent to the party the call is redirected toward) */
390 struct ast_party_id from;
392 /*! \brief Call is redirecting to a new party (Sent to the caller) */
393 struct ast_party_id to;
395 /*! \brief Number of times the call was redirected */
398 /*! \brief enum AST_REDIRECTING_REASON value for redirection */
404 * Structure to describe a channel "technology", ie a channel driver
406 * \arg chan_iax2.c - The Inter-Asterisk exchange protocol
407 * \arg chan_sip.c - The SIP channel driver
408 * \arg chan_dahdi.c - PSTN connectivity (TDM, PRI, T1/E1, FXO, FXS)
411 * If you develop your own channel driver, this is where you
412 * tell the PBX at registration of your driver what properties
413 * this driver supports and where different callbacks are
416 struct ast_channel_tech {
417 const char * const type;
418 const char * const description;
420 format_t capabilities; /*!< Bitmap of formats this channel can handle */
422 int properties; /*!< Technology Properties */
424 /*! \brief Requester - to set up call data structures (pvt's) */
425 struct ast_channel *(* const requester)(const char *type, format_t format, const struct ast_channel *requestor, void *data, int *cause);
427 int (* const devicestate)(void *data); /*!< Devicestate call back */
430 * \brief Start sending a literal DTMF digit
432 * \note The channel is not locked when this function gets called.
434 int (* const send_digit_begin)(struct ast_channel *chan, char digit);
437 * \brief Stop sending a literal DTMF digit
439 * \note The channel is not locked when this function gets called.
441 int (* const send_digit_end)(struct ast_channel *chan, char digit, unsigned int duration);
443 /*! \brief Call a given phone number (address, etc), but don't
444 * take longer than timeout seconds to do so. */
445 int (* const call)(struct ast_channel *chan, char *addr, int timeout);
447 /*! \brief Hangup (and possibly destroy) the channel */
448 int (* const hangup)(struct ast_channel *chan);
450 /*! \brief Answer the channel */
451 int (* const answer)(struct ast_channel *chan);
453 /*! \brief Read a frame, in standard format (see frame.h) */
454 struct ast_frame * (* const read)(struct ast_channel *chan);
456 /*! \brief Write a frame, in standard format (see frame.h) */
457 int (* const write)(struct ast_channel *chan, struct ast_frame *frame);
459 /*! \brief Display or transmit text */
460 int (* const send_text)(struct ast_channel *chan, const char *text);
462 /*! \brief Display or send an image */
463 int (* const send_image)(struct ast_channel *chan, struct ast_frame *frame);
465 /*! \brief Send HTML data */
466 int (* const send_html)(struct ast_channel *chan, int subclass, const char *data, int len);
468 /*! \brief Handle an exception, reading a frame */
469 struct ast_frame * (* const exception)(struct ast_channel *chan);
471 /*! \brief Bridge two channels of the same type together */
472 enum ast_bridge_result (* const bridge)(struct ast_channel *c0, struct ast_channel *c1, int flags,
473 struct ast_frame **fo, struct ast_channel **rc, int timeoutms);
475 /*! \brief Bridge two channels of the same type together (early) */
476 enum ast_bridge_result (* const early_bridge)(struct ast_channel *c0, struct ast_channel *c1);
478 /*! \brief Indicate a particular condition (e.g. AST_CONTROL_BUSY or AST_CONTROL_RINGING or AST_CONTROL_CONGESTION */
479 int (* const indicate)(struct ast_channel *c, int condition, const void *data, size_t datalen);
481 /*! \brief Fix up a channel: If a channel is consumed, this is called. Basically update any ->owner links */
482 int (* const fixup)(struct ast_channel *oldchan, struct ast_channel *newchan);
484 /*! \brief Set a given option */
485 int (* const setoption)(struct ast_channel *chan, int option, void *data, int datalen);
487 /*! \brief Query a given option */
488 int (* const queryoption)(struct ast_channel *chan, int option, void *data, int *datalen);
490 /*! \brief Blind transfer other side (see app_transfer.c and ast_transfer() */
491 int (* const transfer)(struct ast_channel *chan, const char *newdest);
493 /*! \brief Write a frame, in standard format */
494 int (* const write_video)(struct ast_channel *chan, struct ast_frame *frame);
496 /*! \brief Write a text frame, in standard format */
497 int (* const write_text)(struct ast_channel *chan, struct ast_frame *frame);
499 /*! \brief Find bridged channel */
500 struct ast_channel *(* const bridged_channel)(struct ast_channel *chan, struct ast_channel *bridge);
502 /*! \brief Provide additional read items for CHANNEL() dialplan function */
503 int (* func_channel_read)(struct ast_channel *chan, const char *function, char *data, char *buf, size_t len);
505 /*! \brief Provide additional write items for CHANNEL() dialplan function */
506 int (* func_channel_write)(struct ast_channel *chan, const char *function, char *data, const char *value);
508 /*! \brief Retrieve base channel (agent and local) */
509 struct ast_channel* (* get_base_channel)(struct ast_channel *chan);
511 /*! \brief Set base channel (agent and local) */
512 int (* set_base_channel)(struct ast_channel *chan, struct ast_channel *base);
514 /*! \brief Get the unique identifier for the PVT, i.e. SIP call-ID for SIP */
515 const char * (* get_pvt_uniqueid)(struct ast_channel *chan);
518 struct ast_epoll_data;
521 * The high bit of the frame count is used as a debug marker, so
522 * increments of the counters must be done with care.
523 * Please use c->fin = FRAMECOUNT_INC(c->fin) and the same for c->fout.
525 #define DEBUGCHAN_FLAG 0x80000000
527 /* XXX not ideal to evaluate x twice... */
528 #define FRAMECOUNT_INC(x) ( ((x) & DEBUGCHAN_FLAG) | (((x)+1) & ~DEBUGCHAN_FLAG) )
531 * The current value of the debug flags is stored in the two
532 * variables global_fin and global_fout (declared in main/channel.c)
534 extern unsigned long global_fin, global_fout;
536 enum ast_channel_adsicpe {
539 AST_ADSI_UNAVAILABLE,
540 AST_ADSI_OFFHOOKONLY,
544 * \brief ast_channel states
546 * \note Bits 0-15 of state are reserved for the state (up/down) of the line
547 * Bits 16-32 of state are reserved for flags
549 enum ast_channel_state {
550 AST_STATE_DOWN, /*!< Channel is down and available */
551 AST_STATE_RESERVED, /*!< Channel is down, but reserved */
552 AST_STATE_OFFHOOK, /*!< Channel is off hook */
553 AST_STATE_DIALING, /*!< Digits (or equivalent) have been dialed */
554 AST_STATE_RING, /*!< Line is ringing */
555 AST_STATE_RINGING, /*!< Remote end is ringing */
556 AST_STATE_UP, /*!< Line is up */
557 AST_STATE_BUSY, /*!< Line is busy */
558 AST_STATE_DIALING_OFFHOOK, /*!< Digits (or equivalent) have been dialed while offhook */
559 AST_STATE_PRERING, /*!< Channel has detected an incoming call and is waiting for ring */
561 AST_STATE_MUTE = (1 << 16), /*!< Do not transmit voice data */
565 * \brief Possible T38 states on channels
568 T38_STATE_UNAVAILABLE, /*!< T38 is unavailable on this channel or disabled by configuration */
569 T38_STATE_UNKNOWN, /*!< The channel supports T38 but the current status is unknown */
570 T38_STATE_NEGOTIATING, /*!< T38 is being negotiated */
571 T38_STATE_REJECTED, /*!< Remote side has rejected our offer */
572 T38_STATE_NEGOTIATED, /*!< T38 established */
576 * \page AstChannel ast_channel locking and reference tracking
578 * \par Creating Channels
579 * A channel is allocated using the ast_channel_alloc() function. When created, it is
580 * automatically inserted into the main channels hash table that keeps track of all
581 * active channels in the system. The hash key is based on the channel name. Because
582 * of this, if you want to change the name, you _must_ use ast_change_name(), not change
583 * the name field directly. When ast_channel_alloc() returns a channel pointer, you now
584 * hold a reference to that channel. In most cases this reference is given to ast_pbx_run().
586 * \par Channel Locking
587 * There is a lock associated with every ast_channel. It is allocated internally via astobj2.
588 * To lock or unlock a channel, you must use the ast_channel_lock() wrappers.
590 * Previously, before ast_channel was converted to astobj2, the channel lock was used in some
591 * additional ways that are no longer necessary. Before, the only way to ensure that a channel
592 * did not disappear out from under you if you were working with a channel outside of the channel
593 * thread that owns it, was to hold the channel lock. Now, that is no longer necessary.
594 * You simply must hold a reference to the channel to ensure it does not go away.
596 * The channel must be locked if you need to ensure that data that you reading from the channel
597 * does not change while you access it. Further, you must hold the channel lock if you are
598 * making a non-atomic change to channel data.
600 * \par Channel References
601 * There are multiple ways to get a reference to a channel. The first is that you hold a reference
602 * to a channel after creating it. The other ways involve using the channel search or the channel
603 * traversal APIs. These functions are the ast_channel_get_*() functions or ast_channel_iterator_*()
604 * functions. Once a reference is retrieved by one of these methods, you know that the channel will
605 * not go away. So, the channel should only get locked as needed for data access or modification.
606 * But, make sure that the reference gets released when you are done with it!
608 * There are different things you can do when you are done with a reference to a channel. The first
609 * is to simply release the reference using ast_channel_unref(). The other option is to call
610 * ast_channel_release(). This function is generally used where ast_channel_free() was used in
611 * the past. The release function releases a reference as well as ensures that the channel is no
612 * longer in the global channels container. That way, the channel will get destroyed as soon as any
613 * other pending references get released.
615 * \par Exceptions to the rules
616 * Even though ast_channel is reference counted, there are some places where pointers to an ast_channel
617 * get stored, but the reference count does not reflect it. The reason is mostly historical.
618 * The only places where this happens should be places where because of how the code works, we
619 * _know_ that the pointer to the channel will get removed before the channel goes away. The main
620 * example of this is in channel drivers. Channel drivers generally store a pointer to their owner
621 * ast_channel in their technology specific pvt struct. In this case, the channel drivers _know_
622 * that this pointer to the channel will be removed in time, because the channel's hangup callback
623 * gets called before the channel goes away.
627 * \brief Main Channel structure associated with a channel.
629 * \note XXX It is important to remember to increment .cleancount each time
630 * this structure is changed. XXX
632 * \note When adding fields to this structure, it is important to add the field
633 * 'in position' with like-aligned fields, so as to keep the compiler from
634 * having to add padding to align fields. The structure's fields are sorted
635 * in this order: pointers, structures, long, int/enum, short, char. This
636 * is especially important on 64-bit architectures, where mixing 4-byte
637 * and 8-byte fields causes 4 bytes of padding to be added before many
641 const struct ast_channel_tech *tech; /*!< Technology (point to channel driver) */
642 void *tech_pvt; /*!< Private data used by the technology driver */
643 void *music_state; /*!< Music State*/
644 void *generatordata; /*!< Current generator data if there is any */
645 struct ast_generator *generator; /*!< Current active data generator */
646 struct ast_channel *_bridge; /*!< Who are we bridged to, if we're bridged.
647 * Who is proxying for us, if we are proxied (i.e. chan_agent).
648 * Do not access directly, use ast_bridged_channel(chan) */
649 struct ast_channel *masq; /*!< Channel that will masquerade as us */
650 struct ast_channel *masqr; /*!< Who we are masquerading as */
651 const char *blockproc; /*!< Procedure causing blocking */
652 const char *appl; /*!< Current application */
653 const char *data; /*!< Data passed to current application */
654 struct sched_context *sched; /*!< Schedule context */
655 struct ast_filestream *stream; /*!< Stream itself. */
656 struct ast_filestream *vstream; /*!< Video Stream itself. */
657 int (*timingfunc)(const void *data);
659 struct ast_pbx *pbx; /*!< PBX private structure for this channel */
660 struct ast_trans_pvt *writetrans; /*!< Write translation path */
661 struct ast_trans_pvt *readtrans; /*!< Read translation path */
662 struct ast_audiohook_list *audiohooks;
663 struct ast_cdr *cdr; /*!< Call Detail Record */
664 struct ast_tone_zone *zone; /*!< Tone zone as set in indications.conf or
665 * in the CHANNEL dialplan function */
666 struct ast_channel_monitor *monitor; /*!< Channel monitoring */
668 struct ast_epoll_data *epfd_data[AST_MAX_FDS];
671 AST_DECLARE_STRING_FIELDS(
672 AST_STRING_FIELD(name); /*!< ASCII unique channel name */
673 AST_STRING_FIELD(language); /*!< Language requested for voice prompts */
674 AST_STRING_FIELD(musicclass); /*!< Default music class */
675 AST_STRING_FIELD(accountcode); /*!< Account code for billing */
676 AST_STRING_FIELD(peeraccount); /*!< Peer account code for billing */
677 AST_STRING_FIELD(userfield); /*!< Userfield for CEL billing */
678 AST_STRING_FIELD(call_forward); /*!< Where to forward to if asked to dial on this interface */
679 AST_STRING_FIELD(uniqueid); /*!< Unique Channel Identifier */
680 AST_STRING_FIELD(linkedid); /*!< Linked Channel Identifier -- gets propagated by linkage */
681 AST_STRING_FIELD(parkinglot); /*! Default parking lot, if empty, default parking lot */
682 AST_STRING_FIELD(hangupsource); /*! Who is responsible for hanging up this channel */
683 AST_STRING_FIELD(dialcontext); /*!< Dial: Extension context that we were called from */
686 struct timeval whentohangup; /*!< Non-zero, set to actual time when channel is to be hung up */
687 pthread_t blocker; /*!< If anyone is blocking, this is them */
690 * \brief Channel Caller ID information.
691 * \note The caller id information is the caller id of this
692 * channel when it is used to initiate a call.
694 struct ast_callerid cid;
697 * \brief Channel Connected Line ID information.
698 * \note The connected line information identifies the channel
699 * connected/bridged to this channel.
701 struct ast_party_connected_line connected;
704 * \brief Redirecting/Diversion information
705 * \note Until struct ast_channel.cid.cid_rdnis is replaced
706 * with ast_channel.redirecting.from.number, the
707 * ast_channel.redirecting.from.number field is not used.
709 struct ast_party_redirecting redirecting;
711 struct ast_frame dtmff; /*!< DTMF frame */
712 struct varshead varshead; /*!< A linked list for channel variables. See \ref AstChanVar */
713 ast_group_t callgroup; /*!< Call group for call pickups */
714 ast_group_t pickupgroup; /*!< Pickup group - which calls groups can be picked up? */
715 AST_LIST_HEAD_NOLOCK(, ast_frame) readq;
716 AST_LIST_ENTRY(ast_channel) chan_list; /*!< For easy linking */
717 struct ast_jb jb; /*!< The jitterbuffer state */
718 struct timeval dtmf_tv; /*!< The time that an in process digit began, or the last digit ended */
719 AST_LIST_HEAD_NOLOCK(datastores, ast_datastore) datastores; /*!< Data stores on the channel */
720 AST_LIST_HEAD_NOLOCK(autochans, ast_autochan) autochans; /*!< Autochans on the channel */
722 unsigned long insmpl; /*!< Track the read/written samples for monitor use */
723 unsigned long outsmpl; /*!< Track the read/written samples for monitor use */
725 int fds[AST_MAX_FDS]; /*!< File descriptors for channel -- Drivers will poll on
726 * these file descriptors, so at least one must be non -1.
727 * See \arg \ref AstFileDesc */
728 int cdrflags; /*!< Call Detail Record Flags */
729 int _softhangup; /*!< Whether or not we have been hung up... Do not set this value
730 * directly, use ast_softhangup() */
731 int fdno; /*!< Which fd had an event detected on */
732 int streamid; /*!< For streaming playback, the schedule ID */
733 int vstreamid; /*!< For streaming video playback, the schedule ID */
734 format_t oldwriteformat; /*!< Original writer format */
735 int timingfd; /*!< Timing fd */
736 enum ast_channel_state _state; /*!< State of line -- Don't write directly, use ast_setstate() */
737 int rings; /*!< Number of rings so far */
738 int priority; /*!< Dialplan: Current extension priority */
739 int macropriority; /*!< Macro: Current non-macro priority. See app_macro.c */
740 int amaflags; /*!< Set BEFORE PBX is started to determine AMA flags */
741 enum ast_channel_adsicpe adsicpe; /*!< Whether or not ADSI is detected on CPE */
742 unsigned int fin; /*!< Frames in counters. The high bit is a debug mask, so
743 * the counter is only in the remaining bits */
744 unsigned int fout; /*!< Frames out counters. The high bit is a debug mask, so
745 * the counter is only in the remaining bits */
746 int hangupcause; /*!< Why is the channel hanged up. See causes.h */
747 unsigned int flags; /*!< channel flags of AST_FLAG_ type */
749 format_t nativeformats; /*!< Kinds of data this channel can natively handle */
750 format_t readformat; /*!< Requested read format */
751 format_t writeformat; /*!< Requested write format */
752 format_t rawreadformat; /*!< Raw read format */
753 format_t rawwriteformat; /*!< Raw write format */
754 unsigned int emulate_dtmf_duration; /*!< Number of ms left to emulate DTMF for */
758 int visible_indication; /*!< Indication currently playing on the channel */
760 unsigned short transfercapability; /*!< ISDN Transfer Capability - AST_FLAG_DIGITAL is not enough */
762 struct ast_bridge *bridge; /*!< Bridge this channel is participating in */
763 struct ast_timer *timer; /*!< timer object that provided timingfd */
765 char context[AST_MAX_CONTEXT]; /*!< Dialplan: Current extension context */
766 char exten[AST_MAX_EXTENSION]; /*!< Dialplan: Current extension number */
767 char macrocontext[AST_MAX_CONTEXT]; /*!< Macro: Current non-macro context. See app_macro.c */
768 char macroexten[AST_MAX_EXTENSION]; /*!< Macro: Current non-macro extension. See app_macro.c */
769 char emulate_dtmf_digit; /*!< Digit being emulated */
772 /*! \brief ast_channel_tech Properties */
775 * \brief Channels have this property if they can accept input with jitter;
776 * i.e. most VoIP channels
778 AST_CHAN_TP_WANTSJITTER = (1 << 0),
780 * \brief Channels have this property if they can create jitter;
781 * i.e. most VoIP channels
783 AST_CHAN_TP_CREATESJITTER = (1 << 1),
786 /*! \brief ast_channel flags */
788 /*! Queue incoming DTMF, to be released when this flag is turned off */
789 AST_FLAG_DEFER_DTMF = (1 << 1),
790 /*! write should be interrupt generator */
791 AST_FLAG_WRITE_INT = (1 << 2),
792 /*! a thread is blocking on this channel */
793 AST_FLAG_BLOCKING = (1 << 3),
794 /*! This is a zombie channel */
795 AST_FLAG_ZOMBIE = (1 << 4),
796 /*! There is an exception pending */
797 AST_FLAG_EXCEPTION = (1 << 5),
798 /*! Listening to moh XXX anthm promises me this will disappear XXX */
799 AST_FLAG_MOH = (1 << 6),
800 /*! This channel is spying on another channel */
801 AST_FLAG_SPYING = (1 << 7),
802 /*! This channel is in a native bridge */
803 AST_FLAG_NBRIDGE = (1 << 8),
804 /*! the channel is in an auto-incrementing dialplan processor,
805 * so when ->priority is set, it will get incremented before
806 * finding the next priority to run */
807 AST_FLAG_IN_AUTOLOOP = (1 << 9),
808 /*! This is an outgoing call */
809 AST_FLAG_OUTGOING = (1 << 10),
810 /*! A DTMF_BEGIN frame has been read from this channel, but not yet an END */
811 AST_FLAG_IN_DTMF = (1 << 12),
812 /*! A DTMF_END was received when not IN_DTMF, so the length of the digit is
813 * currently being emulated */
814 AST_FLAG_EMULATE_DTMF = (1 << 13),
815 /*! This is set to tell the channel not to generate DTMF begin frames, and
816 * to instead only generate END frames. */
817 AST_FLAG_END_DTMF_ONLY = (1 << 14),
818 /*! Flag to show channels that this call is hangup due to the fact that the call
819 was indeed answered, but in another channel */
820 AST_FLAG_ANSWERED_ELSEWHERE = (1 << 15),
821 /*! This flag indicates that on a masquerade, an active stream should not
823 AST_FLAG_MASQ_NOSTREAM = (1 << 16),
824 /*! This flag indicates that the hangup exten was run when the bridge terminated,
825 * a message aimed at preventing a subsequent hangup exten being run at the pbx_run
827 AST_FLAG_BRIDGE_HANGUP_RUN = (1 << 17),
828 /*! This flag indicates that the hangup exten should NOT be run when the
829 * bridge terminates, this will allow the hangup in the pbx loop to be run instead.
831 AST_FLAG_BRIDGE_HANGUP_DONT = (1 << 18),
834 /*! \brief ast_bridge_config flags */
836 AST_FEATURE_PLAY_WARNING = (1 << 0),
837 AST_FEATURE_REDIRECT = (1 << 1),
838 AST_FEATURE_DISCONNECT = (1 << 2),
839 AST_FEATURE_ATXFER = (1 << 3),
840 AST_FEATURE_AUTOMON = (1 << 4),
841 AST_FEATURE_PARKCALL = (1 << 5),
842 AST_FEATURE_AUTOMIXMON = (1 << 6),
843 AST_FEATURE_NO_H_EXTEN = (1 << 7),
844 AST_FEATURE_WARNING_ACTIVE = (1 << 8),
847 /*! \brief bridge configuration */
848 struct ast_bridge_config {
849 struct ast_flags features_caller;
850 struct ast_flags features_callee;
851 struct timeval start_time;
852 struct timeval nexteventts;
853 struct timeval feature_start_time;
858 const char *warning_sound;
859 const char *end_sound;
860 const char *start_sound;
862 void (* end_bridge_callback)(void *); /*!< A callback that is called after a bridge attempt */
863 void *end_bridge_callback_data; /*!< Data passed to the callback */
864 /*! If the end_bridge_callback_data refers to a channel which no longer is going to
865 * exist when the end_bridge_callback is called, then it needs to be fixed up properly
867 void (*end_bridge_callback_data_fixup)(struct ast_bridge_config *bconfig, struct ast_channel *originator, struct ast_channel *terminator);
872 struct outgoing_helper {
877 const char *cid_name;
879 struct ast_variable *vars;
880 struct ast_channel *parent_channel;
884 AST_CDR_TRANSFER = (1 << 0),
885 AST_CDR_FORWARD = (1 << 1),
886 AST_CDR_CALLWAIT = (1 << 2),
887 AST_CDR_CONFERENCE = (1 << 3),
891 /*! Soft hangup by device */
892 AST_SOFTHANGUP_DEV = (1 << 0),
893 /*! Soft hangup for async goto */
894 AST_SOFTHANGUP_ASYNCGOTO = (1 << 1),
895 AST_SOFTHANGUP_SHUTDOWN = (1 << 2),
896 AST_SOFTHANGUP_TIMEOUT = (1 << 3),
897 AST_SOFTHANGUP_APPUNLOAD = (1 << 4),
898 AST_SOFTHANGUP_EXPLICIT = (1 << 5),
899 AST_SOFTHANGUP_UNBRIDGE = (1 << 6),
903 /*! \brief Channel reload reasons for manager events at load or reload of configuration */
904 enum channelreloadreason {
906 CHANNEL_MODULE_RELOAD,
908 CHANNEL_MANAGER_RELOAD,
912 * \note None of the datastore API calls lock the ast_channel they are using.
913 * So, the channel should be locked before calling the functions that
914 * take a channel argument.
918 * \brief Create a channel data store object
919 * \deprecated You should use the ast_datastore_alloc() generic function instead.
920 * \version 1.6.1 deprecated
922 struct ast_datastore * attribute_malloc ast_channel_datastore_alloc(const struct ast_datastore_info *info, const char *uid)
923 __attribute__((deprecated));
926 * \brief Free a channel data store object
927 * \deprecated You should use the ast_datastore_free() generic function instead.
928 * \version 1.6.1 deprecated
930 int ast_channel_datastore_free(struct ast_datastore *datastore)
931 __attribute__((deprecated));
933 /*! \brief Inherit datastores from a parent to a child. */
934 int ast_channel_datastore_inherit(struct ast_channel *from, struct ast_channel *to);
937 * \brief Add a datastore to a channel
939 * \note The channel should be locked before calling this function.
942 * \retval non-zero failure
944 int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore);
947 * \brief Remove a datastore from a channel
949 * \note The channel should be locked before calling this function.
952 * \retval non-zero failure
954 int ast_channel_datastore_remove(struct ast_channel *chan, struct ast_datastore *datastore);
957 * \brief Find a datastore on a channel
959 * \note The channel should be locked before calling this function.
961 * \note The datastore returned from this function must not be used if the
962 * reference to the channel is released.
964 * \retval pointer to the datastore if found
965 * \retval NULL if not found
967 struct ast_datastore *ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid);
969 /*! \brief Change the state of a channel */
970 int ast_setstate(struct ast_channel *chan, enum ast_channel_state);
973 * \brief Create a channel structure
976 * \retval NULL failure
977 * \retval non-NULL successfully allocated channel
979 * \note By default, new channels are set to the "s" extension
980 * and "default" context.
982 struct ast_channel * attribute_malloc __attribute__((format(printf, 13, 14)))
983 __ast_channel_alloc(int needqueue, int state, const char *cid_num,
984 const char *cid_name, const char *acctcode,
985 const char *exten, const char *context,
986 const char *linkedid, const int amaflag,
987 const char *file, int line, const char *function,
988 const char *name_fmt, ...);
990 #define ast_channel_alloc(needqueue, state, cid_num, cid_name, acctcode, exten, context, linkedid, amaflag, ...) \
991 __ast_channel_alloc(needqueue, state, cid_num, cid_name, acctcode, exten, context, linkedid, amaflag, \
992 __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__)
995 * \brief Create a fake channel structure
997 * \retval NULL failure
998 * \retval non-NULL successfully allocated channel
1000 * \note This function should ONLY be used to create a fake channel
1001 * that can then be populated with data for use in variable
1002 * substitution when a real channel does not exist.
1004 #if defined(REF_DEBUG) || defined(__AST_DEBUG_MALLOC)
1005 #define ast_dummy_channel_alloc() __ast_dummy_channel_alloc(__FILE__, __LINE__, __PRETTY_FUNCTION__)
1006 struct ast_channel *__ast_dummy_channel_alloc(const char *file, int line, const char *function);
1008 struct ast_channel *ast_dummy_channel_alloc(void);
1012 * \brief Queue one or more frames to a channel's frame queue
1014 * \param chan the channel to queue the frame(s) on
1015 * \param f the frame(s) to queue. Note that the frame(s) will be duplicated
1016 * by this function. It is the responsibility of the caller to handle
1017 * freeing the memory associated with the frame(s) being passed if
1021 * \retval non-zero failure
1023 int ast_queue_frame(struct ast_channel *chan, struct ast_frame *f);
1026 * \brief Queue one or more frames to the head of a channel's frame queue
1028 * \param chan the channel to queue the frame(s) on
1029 * \param f the frame(s) to queue. Note that the frame(s) will be duplicated
1030 * by this function. It is the responsibility of the caller to handle
1031 * freeing the memory associated with the frame(s) being passed if
1035 * \retval non-zero failure
1037 int ast_queue_frame_head(struct ast_channel *chan, struct ast_frame *f);
1040 * \brief Queue a hangup frame
1042 * \note The channel does not need to be locked before calling this function.
1044 int ast_queue_hangup(struct ast_channel *chan);
1047 * \brief Queue a hangup frame with hangupcause set
1049 * \note The channel does not need to be locked before calling this function.
1050 * \param[in] chan channel to queue frame onto
1051 * \param[in] cause the hangup cause
1052 * \return 0 on success, -1 on error
1055 int ast_queue_hangup_with_cause(struct ast_channel *chan, int cause);
1058 * \brief Queue a control frame with payload
1060 * \param chan channel to queue frame onto
1061 * \param control type of control frame
1063 * \note The channel does not need to be locked before calling this function.
1065 * \retval zero on success
1066 * \retval non-zero on failure
1068 int ast_queue_control(struct ast_channel *chan, enum ast_control_frame_type control);
1071 * \brief Queue a control frame with payload
1073 * \param chan channel to queue frame onto
1074 * \param control type of control frame
1075 * \param data pointer to payload data to be included in frame
1076 * \param datalen number of bytes of payload data
1079 * \retval non-zero failure
1082 * The supplied payload data is copied into the frame, so the caller's copy
1083 * is not modified nor freed, and the resulting frame will retain a copy of
1084 * the data even if the caller frees their local copy.
1086 * \note This method should be treated as a 'network transport'; in other
1087 * words, your frames may be transferred across an IAX2 channel to another
1088 * system, which may be a different endianness than yours. Because of this,
1089 * you should ensure that either your frames will never be expected to work
1090 * across systems, or that you always put your payload data into 'network byte
1091 * order' before calling this function.
1093 * \note The channel does not need to be locked before calling this function.
1095 int ast_queue_control_data(struct ast_channel *chan, enum ast_control_frame_type control,
1096 const void *data, size_t datalen);
1099 * \brief Change channel name
1101 * \pre Absolutely all channels _MUST_ be unlocked before calling this function.
1103 * \param chan the channel to change the name of
1104 * \param newname the name to change to
1108 * \note this function must _NEVER_ be used when any channels are locked
1109 * regardless if it is the channel who's name is being changed or not because
1110 * it invalidates our channel container locking order... lock container first,
1111 * then the individual channels, never the other way around.
1113 void ast_change_name(struct ast_channel *chan, const char *newname);
1116 * \brief Unlink and release reference to a channel
1118 * This function will unlink the channel from the global channels container
1119 * if it is still there and also release the current reference to the channel.
1121 * \return NULL, convenient for clearing invalid pointers
1125 struct ast_channel *ast_channel_release(struct ast_channel *chan);
1128 * \brief Requests a channel
1130 * \param type type of channel to request
1131 * \param format requested channel format (codec)
1132 * \param data data to pass to the channel requester
1133 * \param status status
1136 * Request a channel of a given type, with data as optional information used
1137 * by the low level module
1139 * \retval NULL failure
1140 * \retval non-NULL channel on success
1142 struct ast_channel *ast_request(const char *type, format_t format, const struct ast_channel *requestor, void *data, int *status);
1145 * \brief Request a channel of a given type, with data as optional information used
1146 * by the low level module and attempt to place a call on it
1148 * \param type type of channel to request
1149 * \param format requested channel format
1150 * \param data data to pass to the channel requester
1151 * \param timeout maximum amount of time to wait for an answer
1152 * \param reason why unsuccessful (if unsuccessful)
1153 * \param cid_num Caller-ID Number
1154 * \param cid_name Caller-ID Name (ascii)
1156 * \return Returns an ast_channel on success or no answer, NULL on failure. Check the value of chan->_state
1157 * to know if the call was answered or not.
1159 struct ast_channel *ast_request_and_dial(const char *type, format_t format, const struct ast_channel *requestor, void *data,
1160 int timeout, int *reason, const char *cid_num, const char *cid_name);
1163 * \brief Request a channel of a given type, with data as optional information used
1164 * by the low level module and attempt to place a call on it
1165 * \param type type of channel to request
1166 * \param format requested channel format
1167 * \param data data to pass to the channel requester
1168 * \param timeout maximum amount of time to wait for an answer
1169 * \param reason why unsuccessful (if unsuccessful)
1170 * \param cid_num Caller-ID Number
1171 * \param cid_name Caller-ID Name (ascii)
1172 * \param oh Outgoing helper
1173 * \return Returns an ast_channel on success or no answer, NULL on failure. Check the value of chan->_state
1174 * to know if the call was answered or not.
1176 struct ast_channel *__ast_request_and_dial(const char *type, format_t format, const struct ast_channel *requestor, void *data,
1177 int timeout, int *reason, const char *cid_num, const char *cid_name, struct outgoing_helper *oh);
1180 * \brief Forwards a call to a new channel specified by the original channel's call_forward str. If possible, the new forwarded channel is created and returned while the original one is terminated.
1181 * \param caller in channel that requested orig
1182 * \param orig channel being replaced by the call forward channel
1183 * \param timeout maximum amount of time to wait for setup of new forward channel
1184 * \param format requested channel format
1185 * \param oh outgoing helper used with original channel
1186 * \param outstate reason why unsuccessful (if uncuccessful)
1187 * \return Returns the forwarded call's ast_channel on success or NULL on failure
1189 struct ast_channel *ast_call_forward(struct ast_channel *caller, struct ast_channel *orig, int *timeout, format_t format, struct outgoing_helper *oh, int *outstate);
1192 * \brief Register a channel technology (a new channel driver)
1193 * Called by a channel module to register the kind of channels it supports.
1194 * \param tech Structure defining channel technology or "type"
1195 * \return Returns 0 on success, -1 on failure.
1197 int ast_channel_register(const struct ast_channel_tech *tech);
1200 * \brief Unregister a channel technology
1201 * \param tech Structure defining channel technology or "type" that was previously registered
1202 * \return No return value.
1204 void ast_channel_unregister(const struct ast_channel_tech *tech);
1207 * \brief Get a channel technology structure by name
1208 * \param name name of technology to find
1209 * \return a pointer to the structure, or NULL if no matching technology found
1211 const struct ast_channel_tech *ast_get_channel_tech(const char *name);
1213 #ifdef CHANNEL_TRACE
1215 * \brief Update the context backtrace if tracing is enabled
1216 * \return Returns 0 on success, -1 on failure
1218 int ast_channel_trace_update(struct ast_channel *chan);
1221 * \brief Enable context tracing in the channel
1222 * \return Returns 0 on success, -1 on failure
1224 int ast_channel_trace_enable(struct ast_channel *chan);
1227 * \brief Disable context tracing in the channel.
1228 * \note Does not remove current trace entries
1229 * \return Returns 0 on success, -1 on failure
1231 int ast_channel_trace_disable(struct ast_channel *chan);
1234 * \brief Whether or not context tracing is enabled
1235 * \return Returns -1 when the trace is enabled. 0 if not.
1237 int ast_channel_trace_is_enabled(struct ast_channel *chan);
1240 * \brief Put the channel backtrace in a string
1241 * \return Returns the amount of lines in the backtrace. -1 on error.
1243 int ast_channel_trace_serialize(struct ast_channel *chan, struct ast_str **out);
1247 * \brief Hang up a channel
1248 * \note This function performs a hard hangup on a channel. Unlike the soft-hangup, this function
1249 * performs all stream stopping, etc, on the channel that needs to end.
1250 * chan is no longer valid after this call.
1251 * \param chan channel to hang up
1252 * \return Returns 0 on success, -1 on failure.
1254 int ast_hangup(struct ast_channel *chan);
1257 * \brief Softly hangup up a channel
1259 * \param chan channel to be soft-hung-up
1260 * \param reason an AST_SOFTHANGUP_* reason code
1263 * Call the protocol layer, but don't destroy the channel structure
1264 * (use this if you are trying to
1265 * safely hangup a channel managed by another thread.
1267 * \note The channel passed to this function does not need to be locked.
1269 * \return Returns 0 regardless
1271 int ast_softhangup(struct ast_channel *chan, int reason);
1274 * \brief Softly hangup up a channel (no channel lock)
1275 * \param chan channel to be soft-hung-up
1276 * \param reason an AST_SOFTHANGUP_* reason code
1278 int ast_softhangup_nolock(struct ast_channel *chan, int reason);
1281 * \brief Set the source of the hangup in this channel and it's bridge
1283 * \param chan channel to set the field on
1284 * \param source a string describing the source of the hangup for this channel
1288 * Hangupsource is generally the channel name that caused the bridge to be
1289 * hung up, but it can also be other things such as "dialplan/agi"
1290 * This can then be logged in the CDR or CEL
1292 void ast_set_hangupsource(struct ast_channel *chan, const char *source, int force);
1294 /*! \brief Check to see if a channel is needing hang up
1295 * \param chan channel on which to check for hang up
1296 * This function determines if the channel is being requested to be hung up.
1297 * \return Returns 0 if not, or 1 if hang up is requested (including time-out).
1299 int ast_check_hangup(struct ast_channel *chan);
1301 int ast_check_hangup_locked(struct ast_channel *chan);
1304 * \brief Compare a offset with the settings of when to hang a channel up
1305 * \param chan channel on which to check for hang up
1306 * \param offset offset in seconds from current time
1307 * \return 1, 0, or -1
1309 * This function compares a offset from current time with the absolute time
1310 * out on a channel (when to hang up). If the absolute time out on a channel
1311 * is earlier than current time plus the offset, it returns 1, if the two
1312 * time values are equal, it return 0, otherwise, it return -1.
1313 * \sa ast_channel_cmpwhentohangup_tv()
1314 * \version 1.6.1 deprecated function (only had seconds precision)
1316 int ast_channel_cmpwhentohangup(struct ast_channel *chan, time_t offset) __attribute__((deprecated));
1319 * \brief Compare a offset with the settings of when to hang a channel up
1320 * \param chan channel on which to check for hangup
1321 * \param offset offset in seconds and microseconds from current time
1322 * \return 1, 0, or -1
1323 * This function compares a offset from current time with the absolute time
1324 * out on a channel (when to hang up). If the absolute time out on a channel
1325 * is earlier than current time plus the offset, it returns 1, if the two
1326 * time values are equal, it return 0, otherwise, it return -1.
1329 int ast_channel_cmpwhentohangup_tv(struct ast_channel *chan, struct timeval offset);
1332 * \brief Set when to hang a channel up
1334 * \param chan channel on which to check for hang up
1335 * \param offset offset in seconds relative to the current time of when to hang up
1338 * This function sets the absolute time out on a channel (when to hang up).
1340 * \note This function does not require that the channel is locked before
1344 * \sa ast_channel_setwhentohangup_tv()
1345 * \version 1.6.1 deprecated function (only had seconds precision)
1347 void ast_channel_setwhentohangup(struct ast_channel *chan, time_t offset) __attribute__((deprecated));
1350 * \brief Set when to hang a channel up
1352 * \param chan channel on which to check for hang up
1353 * \param offset offset in seconds and useconds relative to the current time of when to hang up
1355 * This function sets the absolute time out on a channel (when to hang up).
1357 * \note This function does not require that the channel is locked before
1363 void ast_channel_setwhentohangup_tv(struct ast_channel *chan, struct timeval offset);
1366 * \brief Answer a channel
1368 * \param chan channel to answer
1371 * This function answers a channel and handles all necessary call
1374 * \note The channel passed does not need to be locked, but is locked
1375 * by the function when needed.
1377 * \note This function will wait up to 500 milliseconds for media to
1378 * arrive on the channel before returning to the caller, so that the
1379 * caller can properly assume the channel is 'ready' for media flow.
1381 * \retval 0 on success
1382 * \retval non-zero on failure
1384 int ast_answer(struct ast_channel *chan);
1387 * \brief Answer a channel
1389 * \param chan channel to answer
1390 * \param cdr_answer flag to control whether any associated CDR should be marked as 'answered'
1392 * This function answers a channel and handles all necessary call
1395 * \note The channel passed does not need to be locked, but is locked
1396 * by the function when needed.
1398 * \note Unlike ast_answer(), this function will not wait for media
1399 * flow to begin. The caller should be careful before sending media
1400 * to the channel before incoming media arrives, as the outgoing
1401 * media may be lost.
1403 * \retval 0 on success
1404 * \retval non-zero on failure
1406 int ast_raw_answer(struct ast_channel *chan, int cdr_answer);
1409 * \brief Answer a channel, with a selectable delay before returning
1411 * \param chan channel to answer
1412 * \param delay maximum amount of time to wait for incoming media
1413 * \param cdr_answer flag to control whether any associated CDR should be marked as 'answered'
1415 * This function answers a channel and handles all necessary call
1418 * \note The channel passed does not need to be locked, but is locked
1419 * by the function when needed.
1421 * \note This function will wait up to 'delay' milliseconds for media to
1422 * arrive on the channel before returning to the caller, so that the
1423 * caller can properly assume the channel is 'ready' for media flow. If
1424 * 'delay' is less than 500, the function will wait up to 500 milliseconds.
1426 * \retval 0 on success
1427 * \retval non-zero on failure
1429 int __ast_answer(struct ast_channel *chan, unsigned int delay, int cdr_answer);
1432 * \brief Make a call
1433 * \param chan which channel to make the call on
1434 * \param addr destination of the call
1435 * \param timeout time to wait on for connect
1437 * Place a call, take no longer than timeout ms.
1438 * \return -1 on failure, 0 on not enough time
1439 * (does not automatically stop ringing), and
1440 * the number of seconds the connect took otherwise.
1442 int ast_call(struct ast_channel *chan, char *addr, int timeout);
1445 * \brief Indicates condition of channel
1446 * \note Indicate a condition such as AST_CONTROL_BUSY, AST_CONTROL_RINGING, or AST_CONTROL_CONGESTION on a channel
1447 * \param chan channel to change the indication
1448 * \param condition which condition to indicate on the channel
1449 * \return Returns 0 on success, -1 on failure
1451 int ast_indicate(struct ast_channel *chan, int condition);
1454 * \brief Indicates condition of channel, with payload
1455 * \note Indicate a condition such as AST_CONTROL_HOLD with payload being music on hold class
1456 * \param chan channel to change the indication
1457 * \param condition which condition to indicate on the channel
1458 * \param data pointer to payload data
1459 * \param datalen size of payload data
1460 * \return Returns 0 on success, -1 on failure
1462 int ast_indicate_data(struct ast_channel *chan, int condition, const void *data, size_t datalen);
1464 /* Misc stuff ------------------------------------------------ */
1467 * \brief Wait for input on a channel
1468 * \param chan channel to wait on
1469 * \param ms length of time to wait on the channel
1471 * Wait for input on a channel for a given # of milliseconds (<0 for indefinite).
1472 * \retval < 0 on failure
1473 * \retval 0 if nothing ever arrived
1474 * \retval the # of ms remaining otherwise
1476 int ast_waitfor(struct ast_channel *chan, int ms);
1479 * \brief Wait for a specified amount of time, looking for hangups
1480 * \param chan channel to wait for
1481 * \param ms length of time in milliseconds to sleep
1483 * Waits for a specified amount of time, servicing the channel as required.
1484 * \return returns -1 on hangup, otherwise 0.
1486 int ast_safe_sleep(struct ast_channel *chan, int ms);
1489 * \brief Wait for a specified amount of time, looking for hangups and a condition argument
1490 * \param chan channel to wait for
1491 * \param ms length of time in milliseconds to sleep
1492 * \param cond a function pointer for testing continue condition
1493 * \param data argument to be passed to the condition test function
1494 * \return returns -1 on hangup, otherwise 0.
1496 * Waits for a specified amount of time, servicing the channel as required. If cond
1497 * returns 0, this function returns.
1499 int ast_safe_sleep_conditional(struct ast_channel *chan, int ms, int (*cond)(void*), void *data );
1502 * \brief Waits for activity on a group of channels
1503 * \param chan an array of pointers to channels
1504 * \param n number of channels that are to be waited upon
1505 * \param fds an array of fds to wait upon
1506 * \param nfds the number of fds to wait upon
1507 * \param exception exception flag
1508 * \param outfd fd that had activity on it
1509 * \param ms how long the wait was
1511 * Big momma function here. Wait for activity on any of the n channels, or any of the nfds
1513 * \return Returns the channel with activity, or NULL on error or if an FD
1514 * came first. If the FD came first, it will be returned in outfd, otherwise, outfd
1517 struct ast_channel *ast_waitfor_nandfds(struct ast_channel **chan, int n,
1518 int *fds, int nfds, int *exception, int *outfd, int *ms);
1521 * \brief Waits for input on a group of channels
1522 * Wait for input on an array of channels for a given # of milliseconds.
1523 * \return Return channel with activity, or NULL if none has activity.
1524 * \param chan an array of pointers to channels
1525 * \param n number of channels that are to be waited upon
1526 * \param ms time "ms" is modified in-place, if applicable
1528 struct ast_channel *ast_waitfor_n(struct ast_channel **chan, int n, int *ms);
1531 * \brief Waits for input on an fd
1532 * \note This version works on fd's only. Be careful with it.
1534 int ast_waitfor_n_fd(int *fds, int n, int *ms, int *exception);
1538 * \brief Reads a frame
1539 * \param chan channel to read a frame from
1540 * \return Returns a frame, or NULL on error. If it returns NULL, you
1541 * best just stop reading frames and assume the channel has been
1544 struct ast_frame *ast_read(struct ast_channel *chan);
1547 * \brief Reads a frame, returning AST_FRAME_NULL frame if audio.
1548 * \param chan channel to read a frame from
1549 * \return Returns a frame, or NULL on error. If it returns NULL, you
1550 * best just stop reading frames and assume the channel has been
1552 * \note Audio is replaced with AST_FRAME_NULL to avoid
1553 * transcode when the resulting audio is not necessary.
1555 struct ast_frame *ast_read_noaudio(struct ast_channel *chan);
1558 * \brief Write a frame to a channel
1559 * This function writes the given frame to the indicated channel.
1560 * \param chan destination channel of the frame
1561 * \param frame frame that will be written
1562 * \return It returns 0 on success, -1 on failure.
1564 int ast_write(struct ast_channel *chan, struct ast_frame *frame);
1567 * \brief Write video frame to a channel
1568 * This function writes the given frame to the indicated channel.
1569 * \param chan destination channel of the frame
1570 * \param frame frame that will be written
1571 * \return It returns 1 on success, 0 if not implemented, and -1 on failure.
1573 int ast_write_video(struct ast_channel *chan, struct ast_frame *frame);
1576 * \brief Write text frame to a channel
1577 * This function writes the given frame to the indicated channel.
1578 * \param chan destination channel of the frame
1579 * \param frame frame that will be written
1580 * \return It returns 1 on success, 0 if not implemented, and -1 on failure.
1582 int ast_write_text(struct ast_channel *chan, struct ast_frame *frame);
1584 /*! \brief Send empty audio to prime a channel driver */
1585 int ast_prod(struct ast_channel *chan);
1588 * \brief Sets read format on channel chan
1589 * Set read format for channel to whichever component of "format" is best.
1590 * \param chan channel to change
1591 * \param format format to change to
1592 * \return Returns 0 on success, -1 on failure
1594 int ast_set_read_format(struct ast_channel *chan, format_t format);
1597 * \brief Sets write format on channel chan
1598 * Set write format for channel to whichever component of "format" is best.
1599 * \param chan channel to change
1600 * \param format new format for writing
1601 * \return Returns 0 on success, -1 on failure
1603 int ast_set_write_format(struct ast_channel *chan, format_t format);
1606 * \brief Sends text to a channel
1608 * \param chan channel to act upon
1609 * \param text string of text to send on the channel
1612 * Write text to a display on a channel
1614 * \note The channel does not need to be locked before calling this function.
1616 * \retval 0 on success
1617 * \retval -1 on failure
1619 int ast_sendtext(struct ast_channel *chan, const char *text);
1622 * \brief Receives a text character from a channel
1623 * \param chan channel to act upon
1624 * \param timeout timeout in milliseconds (0 for infinite wait)
1626 * Read a char of text from a channel
1627 * \return 0 on success, -1 on failure
1629 int ast_recvchar(struct ast_channel *chan, int timeout);
1632 * \brief Send a DTMF digit to a channel.
1633 * \param chan channel to act upon
1634 * \param digit the DTMF digit to send, encoded in ASCII
1635 * \param duration the duration of the digit ending in ms
1636 * \return 0 on success, -1 on failure
1638 int ast_senddigit(struct ast_channel *chan, char digit, unsigned int duration);
1641 * \brief Send a DTMF digit to a channel.
1642 * \param chan channel to act upon
1643 * \param digit the DTMF digit to send, encoded in ASCII
1644 * \return 0 on success, -1 on failure
1646 int ast_senddigit_begin(struct ast_channel *chan, char digit);
1649 * \brief Send a DTMF digit to a channel.
1650 * \param chan channel to act upon
1651 * \param digit the DTMF digit to send, encoded in ASCII
1652 * \param duration the duration of the digit ending in ms
1653 * \return Returns 0 on success, -1 on failure
1655 int ast_senddigit_end(struct ast_channel *chan, char digit, unsigned int duration);
1658 * \brief Receives a text string from a channel
1659 * Read a string of text from a channel
1660 * \param chan channel to act upon
1661 * \param timeout timeout in milliseconds (0 for infinite wait)
1662 * \return the received text, or NULL to signify failure.
1664 char *ast_recvtext(struct ast_channel *chan, int timeout);
1667 * \brief Waits for a digit
1668 * \param c channel to wait for a digit on
1669 * \param ms how many milliseconds to wait
1670 * \return Returns <0 on error, 0 on no entry, and the digit on success.
1672 int ast_waitfordigit(struct ast_channel *c, int ms);
1675 * \brief Wait for a digit
1676 * Same as ast_waitfordigit() with audio fd for outputting read audio and ctrlfd to monitor for reading.
1677 * \param c channel to wait for a digit on
1678 * \param ms how many milliseconds to wait
1679 * \param audiofd audio file descriptor to write to if audio frames are received
1680 * \param ctrlfd control file descriptor to monitor for reading
1681 * \return Returns 1 if ctrlfd becomes available
1683 int ast_waitfordigit_full(struct ast_channel *c, int ms, int audiofd, int ctrlfd);
1686 * \brief Reads multiple digits
1687 * \param c channel to read from
1688 * \param s string to read in to. Must be at least the size of your length
1689 * \param len how many digits to read (maximum)
1690 * \param timeout how long to timeout between digits
1691 * \param rtimeout timeout to wait on the first digit
1692 * \param enders digits to end the string
1694 * Read in a digit string "s", max length "len", maximum timeout between
1695 * digits "timeout" (-1 for none), terminated by anything in "enders". Give them rtimeout
1696 * for the first digit.
1697 * \return Returns 0 on normal return, or 1 on a timeout. In the case of
1698 * a timeout, any digits that were read before the timeout will still be available in s.
1699 * RETURNS 2 in full version when ctrlfd is available, NOT 1
1701 int ast_readstring(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders);
1702 int ast_readstring_full(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders, int audiofd, int ctrlfd);
1704 /*! \brief Report DTMF on channel 0 */
1705 #define AST_BRIDGE_DTMF_CHANNEL_0 (1 << 0)
1706 /*! \brief Report DTMF on channel 1 */
1707 #define AST_BRIDGE_DTMF_CHANNEL_1 (1 << 1)
1708 /*! \brief Return all voice frames on channel 0 */
1709 #define AST_BRIDGE_REC_CHANNEL_0 (1 << 2)
1710 /*! \brief Return all voice frames on channel 1 */
1711 #define AST_BRIDGE_REC_CHANNEL_1 (1 << 3)
1712 /*! \brief Ignore all signal frames except NULL */
1713 #define AST_BRIDGE_IGNORE_SIGS (1 << 4)
1717 * \brief Makes two channel formats compatible
1718 * \param c0 first channel to make compatible
1719 * \param c1 other channel to make compatible
1721 * Set two channels to compatible formats -- call before ast_channel_bridge in general.
1722 * \return Returns 0 on success and -1 if it could not be done
1724 int ast_channel_make_compatible(struct ast_channel *c0, struct ast_channel *c1);
1727 * \brief Bridge two channels together (early)
1728 * \param c0 first channel to bridge
1729 * \param c1 second channel to bridge
1731 * Bridge two channels (c0 and c1) together early. This implies either side may not be answered yet.
1732 * \return Returns 0 on success and -1 if it could not be done
1734 int ast_channel_early_bridge(struct ast_channel *c0, struct ast_channel *c1);
1737 * \brief Bridge two channels together
1738 * \param c0 first channel to bridge
1739 * \param c1 second channel to bridge
1740 * \param config config for the channels
1741 * \param fo destination frame(?)
1742 * \param rc destination channel(?)
1744 * Bridge two channels (c0 and c1) together. If an important frame occurs, we return that frame in
1745 * *rf (remember, it could be NULL) and which channel (0 or 1) in rc
1747 /* int ast_channel_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc); */
1748 int ast_channel_bridge(struct ast_channel *c0,struct ast_channel *c1,
1749 struct ast_bridge_config *config, struct ast_frame **fo, struct ast_channel **rc);
1752 * \brief Weird function made for call transfers
1754 * \param original channel to make a copy of
1755 * \param clone copy of the original channel
1758 * This is a very strange and freaky function used primarily for transfer. Suppose that
1759 * "original" and "clone" are two channels in random situations. This function takes
1760 * the guts out of "clone" and puts them into the "original" channel, then alerts the
1761 * channel driver of the change, asking it to fixup any private information (like the
1762 * p->owner pointer) that is affected by the change. The physical layer of the original
1763 * channel is hung up.
1765 * \note Neither channel passed here needs to be locked before calling this function.
1767 int ast_channel_masquerade(struct ast_channel *original, struct ast_channel *clone);
1770 * \brief Gives the string form of a given cause code.
1772 * \param state cause to get the description of
1773 * \return the text form of the binary cause code given
1775 const char *ast_cause2str(int state) attribute_pure;
1778 * \brief Convert the string form of a cause code to a number
1780 * \param name string form of the cause
1781 * \return the cause code
1783 int ast_str2cause(const char *name) attribute_pure;
1786 * \brief Gives the string form of a given channel state
1788 * \param ast_channel_state state to get the name of
1789 * \return the text form of the binary state given
1791 const char *ast_state2str(enum ast_channel_state);
1794 * \brief Gives the string form of a given transfer capability
1796 * \param transfercapability transfer capability to get the name of
1797 * \return the text form of the binary transfer capability
1799 char *ast_transfercapability2str(int transfercapability) attribute_const;
1802 * Options: Some low-level drivers may implement "options" allowing fine tuning of the
1803 * low level channel. See frame.h for options. Note that many channel drivers may support
1804 * none or a subset of those features, and you should not count on this if you want your
1805 * asterisk application to be portable. They're mainly useful for tweaking performance
1809 * \brief Sets an option on a channel
1811 * \param channel channel to set options on
1812 * \param option option to change
1813 * \param data data specific to option
1814 * \param datalen length of the data
1815 * \param block blocking or not
1817 * Set an option on a channel (see frame.h), optionally blocking awaiting the reply
1818 * \return 0 on success and -1 on failure
1820 int ast_channel_setoption(struct ast_channel *channel, int option, void *data, int datalen, int block);
1822 /*! Pick the best codec
1823 * Choose the best codec... Uhhh... Yah. */
1824 format_t ast_best_codec(format_t fmts);
1828 * \brief Checks the value of an option
1830 * Query the value of an option
1831 * Works similarly to setoption except only reads the options.
1833 int ast_channel_queryoption(struct ast_channel *channel, int option, void *data, int *datalen, int block);
1836 * \brief Checks for HTML support on a channel
1837 * \return 0 if channel does not support HTML or non-zero if it does
1839 int ast_channel_supports_html(struct ast_channel *channel);
1842 * \brief Sends HTML on given channel
1843 * Send HTML or URL on link.
1844 * \return 0 on success or -1 on failure
1846 int ast_channel_sendhtml(struct ast_channel *channel, int subclass, const char *data, int datalen);
1849 * \brief Sends a URL on a given link
1851 * \return 0 on success or -1 on failure
1853 int ast_channel_sendurl(struct ast_channel *channel, const char *url);
1856 * \brief Defers DTMF so that you only read things like hangups and audio.
1857 * \return non-zero if channel was already DTMF-deferred or
1858 * 0 if channel is just now being DTMF-deferred
1860 int ast_channel_defer_dtmf(struct ast_channel *chan);
1862 /*! Undo defer. ast_read will return any DTMF characters that were queued */
1863 void ast_channel_undefer_dtmf(struct ast_channel *chan);
1865 /*! Initiate system shutdown -- prevents new channels from being allocated.
1866 * \param hangup If "hangup" is non-zero, all existing channels will receive soft
1868 void ast_begin_shutdown(int hangup);
1870 /*! Cancels an existing shutdown and returns to normal operation */
1871 void ast_cancel_shutdown(void);
1873 /*! \return number of active/allocated channels */
1874 int ast_active_channels(void);
1876 /*! \return non-zero if Asterisk is being shut down */
1877 int ast_shutting_down(void);
1879 /*! Activate a given generator */
1880 int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen, void *params);
1882 /*! Deactivate an active generator */
1883 void ast_deactivate_generator(struct ast_channel *chan);
1886 * \brief Set caller ID number, name and ANI
1888 * \note The channel does not need to be locked before calling this function.
1890 void ast_set_callerid(struct ast_channel *chan, const char *cid_num, const char *cid_name, const char *cid_ani);
1892 /*! Set the file descriptor on the channel */
1893 void ast_channel_set_fd(struct ast_channel *chan, int which, int fd);
1895 /*! Add a channel to an optimized waitfor */
1896 void ast_poll_channel_add(struct ast_channel *chan0, struct ast_channel *chan1);
1898 /*! Delete a channel from an optimized waitfor */
1899 void ast_poll_channel_del(struct ast_channel *chan0, struct ast_channel *chan1);
1901 /*! Start a tone going */
1902 int ast_tonepair_start(struct ast_channel *chan, int freq1, int freq2, int duration, int vol);
1903 /*! Stop a tone from playing */
1904 void ast_tonepair_stop(struct ast_channel *chan);
1905 /*! Play a tone pair for a given amount of time */
1906 int ast_tonepair(struct ast_channel *chan, int freq1, int freq2, int duration, int vol);
1909 * \brief Automatically service a channel for us...
1912 * \retval -1 failure, or the channel is already being autoserviced
1914 int ast_autoservice_start(struct ast_channel *chan);
1917 * \brief Stop servicing a channel for us...
1919 * \note if chan is locked prior to calling ast_autoservice_stop, it
1920 * is likely that there will be a deadlock between the thread that calls
1921 * ast_autoservice_stop and the autoservice thread. It is important
1922 * that chan is not locked prior to this call
1925 * \retval -1 error, or the channel has been hungup
1927 int ast_autoservice_stop(struct ast_channel *chan);
1930 * \brief Enable or disable timer ticks for a channel
1932 * \param rate number of timer ticks per second
1935 * If timers are supported, force a scheduled expiration on the
1936 * timer fd, at which point we call the callback function / data
1938 * \note Call this function with a rate of 0 to turn off the timer ticks
1940 * \version 1.6.1 changed samples parameter to rate, accomodates new timing methods
1942 int ast_settimeout(struct ast_channel *c, unsigned int rate, int (*func)(const void *data), void *data);
1945 * \brief Transfer a channel (if supported).
1946 * \retval -1 on error
1947 * \retval 0 if not supported
1948 * \retval 1 if supported and requested
1949 * \param chan current channel
1950 * \param dest destination extension for transfer
1952 int ast_transfer(struct ast_channel *chan, char *dest);
1955 * \brief Start masquerading a channel
1956 * \note absolutely _NO_ channel locks should be held before calling this function.
1958 * XXX This is a seriously whacked out operation. We're essentially putting the guts of
1959 * the clone channel into the original channel. Start by killing off the original
1960 * channel's backend. I'm not sure we're going to keep this function, because
1961 * while the features are nice, the cost is very high in terms of pure nastiness. XXX
1962 * \param chan Channel to masquerade
1964 int ast_do_masquerade(struct ast_channel *chan);
1967 * \brief Find bridged channel
1969 * \note This function does _not_ return a reference to the bridged channel.
1970 * The reason for this is mostly historical. It _should_ return a reference,
1971 * but it will take a lot of work to make the code base account for that.
1972 * So, for now, the old rules still apply for how to handle this function.
1973 * If this function is being used from the channel thread that owns the channel,
1974 * then a reference is already held, and channel locking is not required to
1975 * guarantee that the channel will stay around. If this function is used
1976 * outside of the associated channel thread, the channel parameter 'chan'
1977 * MUST be locked before calling this function. Also, 'chan' must remain locked
1978 * for the entire time that the result of this function is being used.
1980 * \param chan Current channel
1982 * \return A pointer to the bridged channel
1984 struct ast_channel *ast_bridged_channel(struct ast_channel *chan);
1987 * \brief Inherits channel variable from parent to child channel
1988 * \param parent Parent channel
1989 * \param child Child channel
1992 * Scans all channel variables in the parent channel, looking for those
1993 * that should be copied into the child channel.
1994 * Variables whose names begin with a single '_' are copied into the
1995 * child channel with the prefix removed.
1996 * Variables whose names begin with '__' are copied into the child
1997 * channel with their names unchanged.
1999 void ast_channel_inherit_variables(const struct ast_channel *parent, struct ast_channel *child);
2002 * \brief adds a list of channel variables to a channel
2003 * \param chan the channel
2004 * \param vars a linked list of variables
2007 * Variable names can be for a regular channel variable or a dialplan function
2008 * that has the ability to be written to.
2010 void ast_set_variables(struct ast_channel *chan, struct ast_variable *vars);
2013 * \brief An opaque 'object' structure use by silence generators on channels.
2015 struct ast_silence_generator;
2018 * \brief Starts a silence generator on the given channel.
2019 * \param chan The channel to generate silence on
2020 * \return An ast_silence_generator pointer, or NULL if an error occurs
2023 * This function will cause SLINEAR silence to be generated on the supplied
2024 * channel until it is disabled; if the channel cannot be put into SLINEAR
2025 * mode then the function will fail.
2028 * The pointer returned by this function must be preserved and passed to
2029 * ast_channel_stop_silence_generator when you wish to stop the silence
2032 struct ast_silence_generator *ast_channel_start_silence_generator(struct ast_channel *chan);
2035 * \brief Stops a previously-started silence generator on the given channel.
2036 * \param chan The channel to operate on
2037 * \param state The ast_silence_generator pointer return by a previous call to
2038 * ast_channel_start_silence_generator.
2042 * This function will stop the operating silence generator and return the channel
2043 * to its previous write format.
2045 void ast_channel_stop_silence_generator(struct ast_channel *chan, struct ast_silence_generator *state);
2048 * \brief Check if the channel can run in internal timing mode.
2049 * \param chan The channel to check
2053 * This function will return 1 if internal timing is enabled and the timing
2054 * device is available.
2056 int ast_internal_timing_enabled(struct ast_channel *chan);
2058 /* Misc. functions below */
2061 * \brief if fd is a valid descriptor, set *pfd with the descriptor
2062 * \return Return 1 (not -1!) if added, 0 otherwise (so we can add the
2063 * return value to the index into the array)
2065 static inline int ast_add_fd(struct pollfd *pfd, int fd)
2068 pfd->events = POLLIN | POLLPRI;
2072 /*! \brief Helper function for migrating select to poll */
2073 static inline int ast_fdisset(struct pollfd *pfds, int fd, int maximum, int *start)
2082 for (x = *start; x < maximum; x++)
2083 if (pfds[x].fd == fd) {
2086 return pfds[x].revents;
2091 #ifndef HAVE_TIMERSUB
2092 static inline void timersub(struct timeval *tvend, struct timeval *tvstart, struct timeval *tvdiff)
2094 tvdiff->tv_sec = tvend->tv_sec - tvstart->tv_sec;
2095 tvdiff->tv_usec = tvend->tv_usec - tvstart->tv_usec;
2096 if (tvdiff->tv_usec < 0) {
2098 tvdiff->tv_usec += 1000000;
2105 * \brief Waits for activity on a group of channels
2106 * \param nfds the maximum number of file descriptors in the sets
2107 * \param rfds file descriptors to check for read availability
2108 * \param wfds file descriptors to check for write availability
2109 * \param efds file descriptors to check for exceptions (OOB data)
2110 * \param tvp timeout while waiting for events
2112 * This is the same as a standard select(), except it guarantees the
2113 * behaviour where the passed struct timeval is updated with how much
2114 * time was not slept while waiting for the specified events
2116 static inline int ast_select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tvp)
2119 return select(nfds, rfds, wfds, efds, tvp);
2122 struct timeval tv, tvstart, tvend, tvlen;
2126 gettimeofday(&tvstart, NULL);
2127 res = select(nfds, rfds, wfds, efds, tvp);
2128 gettimeofday(&tvend, NULL);
2129 timersub(&tvend, &tvstart, &tvlen);
2130 timersub(&tv, &tvlen, tvp);
2131 if (tvp->tv_sec < 0 || (tvp->tv_sec == 0 && tvp->tv_usec < 0)) {
2138 return select(nfds, rfds, wfds, efds, NULL);
2142 /*! \brief Retrieves the current T38 state of a channel */
2143 static inline enum ast_t38_state ast_channel_get_t38_state(struct ast_channel *chan)
2145 enum ast_t38_state state = T38_STATE_UNAVAILABLE;
2146 int datalen = sizeof(state);
2148 ast_channel_queryoption(chan, AST_OPTION_T38_STATE, &state, &datalen, 0);
2153 #define CHECK_BLOCKING(c) do { \
2154 if (ast_test_flag(c, AST_FLAG_BLOCKING)) {\
2156 ast_log(LOG_DEBUG, "Thread %ld Blocking '%s', already blocked by thread %ld in procedure %s\n", (long) pthread_self(), (c)->name, (long) (c)->blocker, (c)->blockproc); \
2158 (c)->blocker = pthread_self(); \
2159 (c)->blockproc = __PRETTY_FUNCTION__; \
2160 ast_set_flag(c, AST_FLAG_BLOCKING); \
2163 ast_group_t ast_get_group(const char *s);
2165 /*! \brief print call- and pickup groups into buffer */
2166 char *ast_print_group(char *buf, int buflen, ast_group_t group);
2169 * \brief Convert enum channelreloadreason to text string for manager event
2170 * \param reason The reason for reload (manager, cli, start etc)
2172 const char *channelreloadreason2txt(enum channelreloadreason reason);
2174 /*! \brief return an ast_variable list of channeltypes */
2175 struct ast_variable *ast_channeltype_list(void);
2178 * \brief return an english explanation of the code returned thru __ast_request_and_dial's 'outstate' argument
2179 * \param reason The integer argument, usually taken from AST_CONTROL_ macros
2180 * \return char pointer explaining the code
2182 const char *ast_channel_reason2str(int reason);
2184 /*! \brief channel group info */
2185 struct ast_group_info {
2186 struct ast_channel *chan;
2189 AST_LIST_ENTRY(ast_group_info) group_list;
2192 #define ast_channel_lock(chan) ao2_lock(chan)
2193 #define ast_channel_unlock(chan) ao2_unlock(chan)
2194 #define ast_channel_trylock(chan) ao2_trylock(chan)
2197 * \brief Lock two channels.
2199 #define ast_channel_lock_both(chan1, chan2) do { \
2200 ast_channel_lock(chan1); \
2201 while (ast_channel_trylock(chan2)) { \
2202 ast_channel_unlock(chan1); \
2204 ast_channel_lock(chan1); \
2209 * \brief Increase channel reference count
2211 * \param c the channel
2217 #define ast_channel_ref(c) ({ ao2_ref(c, +1); (c); })
2220 * \brief Decrease channel reference count
2222 * \param c the channel
2224 * \retval NULL always
2228 #define ast_channel_unref(c) ({ ao2_ref(c, -1); (struct ast_channel *) (NULL); })
2230 /*! Channel Iterating @{ */
2233 * \brief A channel iterator
2235 * This is an opaque type.
2237 struct ast_channel_iterator;
2240 * \brief Destroy a channel iterator
2242 * \arg i the itereator to destroy
2244 * This function is used to destroy a channel iterator that was retrieved by
2245 * using one of the channel_iterator_new() functions.
2247 * \return NULL, for convenience to clear out the pointer to the iterator that
2248 * was just destroyed.
2252 struct ast_channel_iterator *ast_channel_iterator_destroy(struct ast_channel_iterator *i);
2255 * \brief Create a new channel iterator based on extension
2257 * \arg exten The extension that channels must be in
2258 * \arg context The context that channels must be in (optional)
2260 * After creating an iterator using this function, the ast_channel_iterator_next()
2261 * function can be used to iterate through all channels that are currently
2262 * in the specified context and extension.
2264 * \retval NULL on failure
2265 * \retval a new channel iterator based on the specified parameters
2269 struct ast_channel_iterator *ast_channel_iterator_by_exten_new(const char *exten, const char *context);
2272 * \brief Create a new channel iterator based on name
2274 * \arg name channel name or channel uniqueid to match
2275 * \arg name_len number of characters in the channel name to match on. This
2276 * would be used to match based on name prefix. If matching on the full
2277 * channel name is desired, then this parameter should be 0.
2279 * After creating an iterator using this function, the ast_channel_iterator_next()
2280 * function can be used to iterate through all channels that exist that have
2281 * the specified name or name prefix.
2283 * \retval NULL on failure
2284 * \retval a new channel iterator based on the specified parameters
2288 struct ast_channel_iterator *ast_channel_iterator_by_name_new(const char *name, size_t name_len);
2291 * \brief Create a new channel iterator
2293 * After creating an iterator using this function, the ast_channel_iterator_next()
2294 * function can be used to iterate through all channels that exist.
2296 * \retval NULL on failure
2297 * \retval a new channel iterator
2301 struct ast_channel_iterator *ast_channel_iterator_all_new(void);
2304 * \brief Get the next channel for a channel iterator
2306 * \arg i the channel iterator that was created using one of the
2307 * channel_iterator_new() functions.
2309 * This function should be used to iterate through all channels that match a
2310 * specified set of parameters that were provided when the iterator was created.
2312 * \retval the next channel that matches the parameters used when the iterator
2314 * \retval NULL, if no more channels match the iterator parameters.
2318 struct ast_channel *ast_channel_iterator_next(struct ast_channel_iterator *i);
2320 /*! @} End channel iterator definitions. */
2323 * \brief Call a function with every active channel
2325 * This function executes a callback one time for each active channel on the
2326 * system. The channel is provided as an argument to the function.
2330 struct ast_channel *ast_channel_callback(ao2_callback_data_fn *cb_fn, void *arg,
2331 void *data, int ao2_flags);
2333 /*! @{ Channel search functions */
2336 * \brief Find a channel by name
2338 * \arg name the name or uniqueid of the channel to search for
2340 * Find a channel that has the same name as the provided argument.
2342 * \retval a channel with the name specified by the argument
2343 * \retval NULL if no channel was found
2347 struct ast_channel *ast_channel_get_by_name(const char *name);
2350 * \brief Find a channel by a name prefix
2352 * \arg name The channel name or uniqueid prefix to search for
2353 * \arg name_len Only search for up to this many characters from the name
2355 * Find a channel that has the same name prefix as specified by the arguments.
2357 * \retval a channel with the name prefix specified by the arguments
2358 * \retval NULL if no channel was found
2362 struct ast_channel *ast_channel_get_by_name_prefix(const char *name, size_t name_len);
2365 * \brief Find a channel by extension and context
2367 * \arg exten the extension to search for
2368 * \arg context the context to search for (optional)
2370 * Return a channel that is currently at the specified extension and context.
2372 * \retval a channel that is at the specified extension and context
2373 * \retval NULL if no channel was found
2377 struct ast_channel *ast_channel_get_by_exten(const char *exten, const char *context);
2379 /*! @} End channel search functions. */
2382 \brief propagate the linked id between chan and peer
2384 void ast_channel_set_linkgroup(struct ast_channel *chan, struct ast_channel *peer);
2389 * \brief Initialize the given subaddress structure.
2391 * \param init Subaddress structure to initialize.
2395 void ast_party_subaddress_init(struct ast_party_subaddress *init);
2399 * \brief Copy the source party subaddress information to the destination party subaddress.
2401 * \param dest Destination party subaddress
2402 * \param src Source party subaddress
2406 void ast_party_subaddress_copy(struct ast_party_subaddress *dest, const struct ast_party_subaddress *src);
2410 * \brief Initialize the given party subadress structure using the given guide
2411 * for a set update operation.
2414 * The initialization is needed to allow a set operation to know if a
2415 * value needs to be updated. Simple integers need the guide's original
2416 * value in case the set operation is not trying to set a new value.
2417 * String values are simply set to NULL pointers if they are not going
2420 * \param init Party Subaddress structure to initialize.
2421 * \param guide Source party subaddress to use as a guide in initializing.
2425 void ast_party_subaddress_set_init(struct ast_party_subaddress *init, const struct ast_party_subaddress *guide);
2429 * \brief Set the source party subaddress information into the destination party subaddress.
2431 * \param dest Destination party subaddress
2432 * \param src Source party subaddress
2436 void ast_party_subaddress_set(struct ast_party_subaddress *dest, const struct ast_party_subaddress *src);
2440 * \brief Destroy the party subaddress contents
2442 * \param doomed The party subaddress to destroy.
2446 void ast_party_subaddress_free(struct ast_party_subaddress *doomed);
2450 * \brief Initialize the given caller structure.
2452 * \param init Caller structure to initialize.
2456 void ast_party_caller_init(struct ast_party_caller *init);
2460 * \brief Copy the source caller information to the destination caller.
2462 * \param dest Destination caller
2463 * \param src Source caller
2467 void ast_party_caller_copy(struct ast_callerid *dest, const struct ast_callerid *src);
2471 * \brief Initialize the given connected line structure.
2473 * \param init Connected line structure to initialize.
2477 void ast_party_connected_line_init(struct ast_party_connected_line *init);
2481 * \brief Copy the source connected line information to the destination connected line.
2483 * \param dest Destination connected line
2484 * \param src Source connected line
2488 void ast_party_connected_line_copy(struct ast_party_connected_line *dest, const struct ast_party_connected_line *src);
2492 * \brief Initialize the given connected line structure using the given
2493 * guide for a set update operation.
2496 * The initialization is needed to allow a set operation to know if a
2497 * value needs to be updated. Simple integers need the guide's original
2498 * value in case the set operation is not trying to set a new value.
2499 * String values are simply set to NULL pointers if they are not going
2502 * \param init Connected line structure to initialize.
2503 * \param guide Source connected line to use as a guide in initializing.
2507 void ast_party_connected_line_set_init(struct ast_party_connected_line *init, const struct ast_party_connected_line *guide);
2511 * \brief Set the connected line information based on another connected line source
2513 * This is similar to ast_party_connected_line_copy, except that NULL values for
2514 * strings in the src parameter indicate not to update the corresponding dest values.
2516 * \param src The source connected line to use as a guide to set the dest
2517 * \param dest The connected line one wishes to update
2521 void ast_party_connected_line_set(struct ast_party_connected_line *dest, const struct ast_party_connected_line *src);
2525 * \brief Collect the caller party information into a connected line structure.
2527 * \param connected Collected caller information for the connected line
2528 * \param cid Caller information.
2532 * \warning This is a shallow copy.
2533 * \warning DO NOT call ast_party_connected_line_free() on the filled in
2534 * connected line structure!
2536 void ast_party_connected_line_collect_caller(struct ast_party_connected_line *connected, struct ast_callerid *cid);
2540 * \brief Destroy the connected line information contents
2542 * \param doomed The connected line information to destroy.
2546 void ast_party_connected_line_free(struct ast_party_connected_line *doomed);
2550 * \brief Copy the source redirecting information to the destination redirecting.
2552 * \param dest Destination redirecting
2553 * \param src Source redirecting
2557 void ast_party_redirecting_copy(struct ast_party_redirecting *dest, const struct ast_party_redirecting *src);
2561 * \brief Initialize the given redirecting id structure using the given guide
2562 * for a set update operation.
2565 * The initialization is needed to allow a set operation to know if a
2566 * value needs to be updated. Simple integers need the guide's original
2567 * value in case the set operation is not trying to set a new value.
2568 * String values are simply set to NULL pointers if they are not going
2571 * \param init Redirecting id structure to initialize.
2572 * \param guide Source redirecting id to use as a guide in initializing.
2576 void ast_party_redirecting_set_init(struct ast_party_redirecting *init, const struct ast_party_redirecting *guide);
2580 * \brief Destroy the redirecting information contents
2582 * \param doomed The redirecting information to destroy.
2586 void ast_party_redirecting_free(struct ast_party_redirecting *doomed);
2590 * \brief Copy the caller information to the connected line information.
2592 * \param dest Destination connected line information
2593 * \param src Source caller information
2597 * \note Assumes locks are already acquired
2599 void ast_connected_line_copy_from_caller(struct ast_party_connected_line *dest, const struct ast_callerid *src);
2603 * \brief Copy the connected line information to the caller information.
2605 * \param dest Destination caller information
2606 * \param src Source connected line information
2610 * \note Assumes locks are already acquired
2612 void ast_connected_line_copy_to_caller(struct ast_callerid *dest, const struct ast_party_connected_line *src);
2616 * \brief Set the connected line information in the Asterisk channel
2618 * \param chan Asterisk channel to set connected line information
2619 * \param connected Connected line information
2623 * \note The channel does not need to be locked before calling this function.
2625 void ast_channel_set_connected_line(struct ast_channel *chan, const struct ast_party_connected_line *connected);
2629 * \brief Build the connected line information data frame.
2631 * \param data Buffer to fill with the frame data
2632 * \param datalen Size of the buffer to fill
2633 * \param connected Connected line information
2635 * \retval -1 if error
2636 * \retval Amount of data buffer used
2638 int ast_connected_line_build_data(unsigned char *data, size_t datalen, const struct ast_party_connected_line *connected);
2642 * \brief Parse connected line indication frame data
2644 * \param data Buffer with the frame data to parse
2645 * \param datalen Size of the buffer
2646 * \param connected Extracted connected line information
2648 * \retval 0 on success.
2649 * \retval -1 on error.
2651 * \note The filled in connected line structure needs to be initialized by
2652 * ast_party_connected_line_set_init() before calling. If defaults are not
2653 * required use ast_party_connected_line_init().
2654 * \note The filled in connected line structure needs to be destroyed by
2655 * ast_party_connected_line_free() when it is no longer needed.
2657 int ast_connected_line_parse_data(const unsigned char *data, size_t datalen, struct ast_party_connected_line *connected);
2661 * \brief Indicate that the connected line information has changed
2663 * \param chan Asterisk channel to indicate connected line information
2664 * \param connected Connected line information
2668 void ast_channel_update_connected_line(struct ast_channel *chan, const struct ast_party_connected_line *connected);
2672 * \brief Queue a connected line update frame on a channel
2674 * \param chan Asterisk channel to indicate connected line information
2675 * \param connected Connected line information
2679 void ast_channel_queue_connected_line_update(struct ast_channel *chan, const struct ast_party_connected_line *connected);
2683 * \brief Set the redirecting id information in the Asterisk channel
2685 * \param chan Asterisk channel to set redirecting id information
2686 * \param redirecting Redirecting id information
2690 * \note The channel does not need to be locked before calling this function.
2692 void ast_channel_set_redirecting(struct ast_channel *chan, const struct ast_party_redirecting *redirecting);
2696 * \brief Build the redirecting id data frame.
2698 * \param data Buffer to fill with the frame data
2699 * \param datalen Size of the buffer to fill
2700 * \param redirecting Redirecting id information
2702 * \retval -1 if error
2703 * \retval Amount of data buffer used
2705 int ast_redirecting_build_data(unsigned char *data, size_t datalen, const struct ast_party_redirecting *redirecting);
2709 * \brief Parse redirecting indication frame data
2711 * \param data Buffer with the frame data to parse
2712 * \param datalen Size of the buffer
2713 * \param redirecting Extracted redirecting id information
2715 * \retval 0 on success.
2716 * \retval -1 on error.
2718 * \note The filled in id structure needs to be initialized by
2719 * ast_party_redirecting_set_init() before calling.
2720 * \note The filled in id structure needs to be destroyed by
2721 * ast_party_redirecting_free() when it is no longer needed.
2723 int ast_redirecting_parse_data(const unsigned char *data, size_t datalen, struct ast_party_redirecting *redirecting);
2727 * \brief Indicate that the redirecting id has changed
2729 * \param chan Asterisk channel to indicate redirecting id information
2730 * \param redirecting Redirecting id information
2734 void ast_channel_update_redirecting(struct ast_channel *chan, const struct ast_party_redirecting *redirecting);
2738 * \brief Queue a redirecting update frame on a channel
2740 * \param chan Asterisk channel to indicate redirecting id information
2741 * \param redirecting Redirecting id information
2745 void ast_channel_queue_redirecting_update(struct ast_channel *chan, const struct ast_party_redirecting *redirecting);
2749 * \brief Run a connected line interception macro and update a channel's connected line
2752 * Whenever we want to update a channel's connected line information, we may need to run
2753 * a macro so that an administrator can manipulate the information before sending it
2754 * out. This function both runs the macro and sends the update to the channel.
2756 * \param autoservice_chan Channel to place into autoservice while the macro is running.
2757 * It is perfectly safe for this to be NULL
2758 * \param macro_chan The channel to run the macro on. Also the channel from which we
2759 * determine which macro we need to run.
2760 * \param connected_info Either an ast_party_connected_line or ast_frame pointer of type
2761 * AST_CONTROL_CONNECTED_LINE
2762 * \param caller If true, then run CONNECTED_LINE_CALLER_SEND_MACRO, otherwise run
2763 * CONNECTED_LINE_CALLEE_SEND_MACRO
2764 * \param frame If true, then connected_info is an ast_frame pointer, otherwise it is an
2765 * ast_party_connected_line pointer.
2767 * \retval -1 Either the macro does not exist, or there was an error while attempting to
2770 * \todo Have multiple return codes based on the MACRO_RESULT
2771 * \todo Make constants so that caller and frame can be more expressive than just '1' and
2774 int ast_channel_connected_line_macro(struct ast_channel *autoservice_chan, struct ast_channel *macro_chan, const void *connected_info, int caller, int frame);
2775 #if defined(__cplusplus) || defined(c_plusplus)
2779 #endif /* _ASTERISK_CHANNEL_H */