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, ZAP, 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 (zaptel 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 briding 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"
128 #ifdef HAVE_SYS_POLL_H
129 #include <sys/poll.h>
131 #include "asterisk/poll-compat.h"
134 #if defined(__cplusplus) || defined(c_plusplus)
138 #define AST_MAX_EXTENSION 80 /*!< Max length of an extension */
139 #define AST_MAX_CONTEXT 80 /*!< Max length of a context */
140 #define AST_CHANNEL_NAME 80 /*!< Max length of an ast_channel name */
141 #define MAX_LANGUAGE 20 /*!< Max length of the language setting */
142 #define MAX_MUSICCLASS 80 /*!< Max length of the music class setting */
144 #include "asterisk/frame.h"
145 #include "asterisk/sched.h"
146 #include "asterisk/chanvars.h"
147 #include "asterisk/config.h"
148 #include "asterisk/lock.h"
149 #include "asterisk/cdr.h"
150 #include "asterisk/utils.h"
151 #include "asterisk/linkedlists.h"
152 #include "asterisk/stringfields.h"
154 #define DATASTORE_INHERIT_FOREVER INT_MAX
156 #define AST_MAX_FDS 10
158 * We have AST_MAX_FDS file descriptors in a channel.
159 * Some of them have a fixed use:
161 #define AST_ALERT_FD (AST_MAX_FDS-1) /*!< used for alertpipe */
162 #define AST_TIMING_FD (AST_MAX_FDS-2) /*!< used for timingfd */
163 #define AST_AGENT_FD (AST_MAX_FDS-3) /*!< used by agents for pass through */
164 #define AST_GENERATOR_FD (AST_MAX_FDS-4) /*!< used by generator */
166 enum ast_bridge_result {
167 AST_BRIDGE_COMPLETE = 0,
168 AST_BRIDGE_FAILED = -1,
169 AST_BRIDGE_FAILED_NOWARN = -2,
170 AST_BRIDGE_RETRY = -3,
173 typedef unsigned long long ast_group_t;
175 /*! \todo Add an explanation of an Asterisk generator
177 struct ast_generator {
178 void *(*alloc)(struct ast_channel *chan, void *params);
179 void (*release)(struct ast_channel *chan, void *data);
180 /*! This function gets called with the channel locked */
181 int (*generate)(struct ast_channel *chan, void *data, int len, int samples);
182 /*! This gets called when DTMF_END frames are read from the channel */
183 void (*digit)(struct ast_channel *chan, char digit);
186 /*! \brief Structure for a data store type */
187 struct ast_datastore_info {
188 const char *type; /*!< Type of data store */
189 void *(*duplicate)(void *data); /*!< Duplicate item data (used for inheritance) */
190 void (*destroy)(void *data); /*!< Destroy function */
193 /*! \brief Structure for a channel data store */
194 struct ast_datastore {
195 const char *uid; /*!< Unique data store identifier */
196 void *data; /*!< Contained data */
197 const struct ast_datastore_info *info; /*!< Data store type information */
198 unsigned int inheritance; /*!< Number of levels this item will continue to be inherited */
199 AST_LIST_ENTRY(ast_datastore) entry; /*!< Used for easy linking */
202 /*! \brief Structure for all kinds of caller ID identifications.
203 * \note All string fields here are malloc'ed, so they need to be
204 * freed when the structure is deleted.
205 * Also, NULL and "" must be considered equivalent.
207 * SIP and IAX2 has utf8 encoded Unicode caller ID names.
208 * In some cases, we also have an alternative (RPID) E.164 number that can be used
209 * as caller ID on numeric E.164 phone networks (zaptel or SIP/IAX2 to pstn gateway).
211 * \todo Implement settings for transliteration between UTF8 caller ID names in
212 * to Ascii Caller ID's (Zaptel). Östen Åsklund might be transliterated into
213 * Osten Asklund or Oesten Aasklund depending upon language and person...
214 * We need automatic routines for incoming calls and static settings for
217 struct ast_callerid {
218 char *cid_dnid; /*!< Malloc'd Dialed Number Identifier */
219 char *cid_num; /*!< Malloc'd Caller Number */
220 char *cid_name; /*!< Malloc'd Caller Name (ASCII) */
221 char *cid_ani; /*!< Malloc'd ANI */
222 char *cid_rdnis; /*!< Malloc'd RDNIS */
223 int cid_pres; /*!< Callerid presentation/screening */
224 int cid_ani2; /*!< Callerid ANI 2 (Info digits) */
225 int cid_ton; /*!< Callerid Type of Number */
226 int cid_tns; /*!< Callerid Transit Network Select */
230 Structure to describe a channel "technology", ie a channel driver
232 \arg chan_iax2.c - The Inter-Asterisk exchange protocol
233 \arg chan_sip.c - The SIP channel driver
234 \arg chan_zap.c - PSTN connectivity (TDM, PRI, T1/E1, FXO, FXS)
236 If you develop your own channel driver, this is where you
237 tell the PBX at registration of your driver what properties
238 this driver supports and where different callbacks are
241 struct ast_channel_tech {
242 const char * const type;
243 const char * const description;
245 int capabilities; /*!< Bitmap of formats this channel can handle */
247 int properties; /*!< Technology Properties */
249 /*! \brief Requester - to set up call data structures (pvt's) */
250 struct ast_channel *(* const requester)(const char *type, int format, void *data, int *cause);
252 int (* const devicestate)(void *data); /*!< Devicestate call back */
255 * \brief Start sending a literal DTMF digit
257 * \note The channel is not locked when this function gets called.
259 int (* const send_digit_begin)(struct ast_channel *chan, char digit);
262 * \brief Stop sending a literal DTMF digit
264 * \note The channel is not locked when this function gets called.
266 int (* const send_digit_end)(struct ast_channel *chan, char digit, unsigned int duration);
268 /*! \brief Call a given phone number (address, etc), but don't
269 take longer than timeout seconds to do so. */
270 int (* const call)(struct ast_channel *chan, char *addr, int timeout);
272 /*! \brief Hangup (and possibly destroy) the channel */
273 int (* const hangup)(struct ast_channel *chan);
275 /*! \brief Answer the channel */
276 int (* const answer)(struct ast_channel *chan);
278 /*! \brief Read a frame, in standard format (see frame.h) */
279 struct ast_frame * (* const read)(struct ast_channel *chan);
281 /*! \brief Write a frame, in standard format (see frame.h) */
282 int (* const write)(struct ast_channel *chan, struct ast_frame *frame);
284 /*! \brief Display or transmit text */
285 int (* const send_text)(struct ast_channel *chan, const char *text);
287 /*! \brief Display or send an image */
288 int (* const send_image)(struct ast_channel *chan, struct ast_frame *frame);
290 /*! \brief Send HTML data */
291 int (* const send_html)(struct ast_channel *chan, int subclass, const char *data, int len);
293 /*! \brief Handle an exception, reading a frame */
294 struct ast_frame * (* const exception)(struct ast_channel *chan);
296 /*! \brief Bridge two channels of the same type together */
297 enum ast_bridge_result (* const bridge)(struct ast_channel *c0, struct ast_channel *c1, int flags,
298 struct ast_frame **fo, struct ast_channel **rc, int timeoutms);
300 /*! \brief Bridge two channels of the same type together (early) */
301 enum ast_bridge_result (* const early_bridge)(struct ast_channel *c0, struct ast_channel *c1);
303 /*! \brief Indicate a particular condition (e.g. AST_CONTROL_BUSY or AST_CONTROL_RINGING or AST_CONTROL_CONGESTION */
304 int (* const indicate)(struct ast_channel *c, int condition, const void *data, size_t datalen);
306 /*! \brief Fix up a channel: If a channel is consumed, this is called. Basically update any ->owner links */
307 int (* const fixup)(struct ast_channel *oldchan, struct ast_channel *newchan);
309 /*! \brief Set a given option */
310 int (* const setoption)(struct ast_channel *chan, int option, void *data, int datalen);
312 /*! \brief Query a given option */
313 int (* const queryoption)(struct ast_channel *chan, int option, void *data, int *datalen);
315 /*! \brief Blind transfer other side (see app_transfer.c and ast_transfer() */
316 int (* const transfer)(struct ast_channel *chan, const char *newdest);
318 /*! \brief Write a frame, in standard format */
319 int (* const write_video)(struct ast_channel *chan, struct ast_frame *frame);
321 /*! \brief Write a text frame, in standard format */
322 int (* const write_text)(struct ast_channel *chan, struct ast_frame *frame);
324 /*! \brief Find bridged channel */
325 struct ast_channel *(* const bridged_channel)(struct ast_channel *chan, struct ast_channel *bridge);
327 /*! \brief Provide additional read items for CHANNEL() dialplan function */
328 int (* func_channel_read)(struct ast_channel *chan, const char *function, char *data, char *buf, size_t len);
330 /*! \brief Provide additional write items for CHANNEL() dialplan function */
331 int (* func_channel_write)(struct ast_channel *chan, const char *function, char *data, const char *value);
333 /*! \brief Retrieve base channel (agent and local) */
334 struct ast_channel* (* get_base_channel)(struct ast_channel *chan);
336 /*! \brief Set base channel (agent and local) */
337 int (* set_base_channel)(struct ast_channel *chan, struct ast_channel *base);
340 struct ast_epoll_data;
343 * The high bit of the frame count is used as a debug marker, so
344 * increments of the counters must be done with care.
345 * Please use c->fin = FRAMECOUNT_INC(c->fin) and the same for c->fout.
347 #define DEBUGCHAN_FLAG 0x80000000
349 /* XXX not ideal to evaluate x twice... */
350 #define FRAMECOUNT_INC(x) ( ((x) & DEBUGCHAN_FLAG) | (((x)+1) & ~DEBUGCHAN_FLAG) )
353 * The current value of the debug flags is stored in the two
354 * variables global_fin and global_fout (declared in main/channel.c)
356 extern unsigned long global_fin, global_fout;
358 enum ast_channel_adsicpe {
361 AST_ADSI_UNAVAILABLE,
362 AST_ADSI_OFFHOOKONLY,
366 * \brief ast_channel states
368 * \note Bits 0-15 of state are reserved for the state (up/down) of the line
369 * Bits 16-32 of state are reserved for flags
371 enum ast_channel_state {
372 AST_STATE_DOWN, /*!< Channel is down and available */
373 AST_STATE_RESERVED, /*!< Channel is down, but reserved */
374 AST_STATE_OFFHOOK, /*!< Channel is off hook */
375 AST_STATE_DIALING, /*!< Digits (or equivalent) have been dialed */
376 AST_STATE_RING, /*!< Line is ringing */
377 AST_STATE_RINGING, /*!< Remote end is ringing */
378 AST_STATE_UP, /*!< Line is up */
379 AST_STATE_BUSY, /*!< Line is busy */
380 AST_STATE_DIALING_OFFHOOK, /*!< Digits (or equivalent) have been dialed while offhook */
381 AST_STATE_PRERING, /*!< Channel has detected an incoming call and is waiting for ring */
383 AST_STATE_MUTE = (1 << 16), /*!< Do not transmit voice data */
386 /*! \brief Main Channel structure associated with a channel.
387 * This is the side of it mostly used by the pbx and call management.
389 * \note XXX It is important to remember to increment .cleancount each time
390 * this structure is changed. XXX
394 const struct ast_channel_tech *tech; /*!< Technology (point to channel driver) */
396 void *tech_pvt; /*!< Private data used by the technology driver */
398 AST_DECLARE_STRING_FIELDS(
399 AST_STRING_FIELD(name); /*!< ASCII unique channel name */
400 AST_STRING_FIELD(language); /*!< Language requested for voice prompts */
401 AST_STRING_FIELD(musicclass); /*!< Default music class */
402 AST_STRING_FIELD(accountcode); /*!< Account code for billing */
403 AST_STRING_FIELD(call_forward); /*!< Where to forward to if asked to dial on this interface */
404 AST_STRING_FIELD(uniqueid); /*!< Unique Channel Identifier */
407 int fds[AST_MAX_FDS]; /*!< File descriptors for channel -- Drivers will poll on
408 these file descriptors, so at least one must be non -1.
409 See \arg \ref AstFileDesc */
411 void *music_state; /*!< Music State*/
412 void *generatordata; /*!< Current generator data if there is any */
413 struct ast_generator *generator; /*!< Current active data generator */
415 struct ast_channel *_bridge; /*!< Who are we bridged to, if we're bridged.
416 Who is proxying for us, if we are proxied (i.e. chan_agent).
417 Do not access directly, use ast_bridged_channel(chan) */
419 struct ast_channel *masq; /*!< Channel that will masquerade as us */
420 struct ast_channel *masqr; /*!< Who we are masquerading as */
421 int cdrflags; /*!< Call Detail Record Flags */
423 int _softhangup; /*!< Whether or not we have been hung up... Do not set this value
424 directly, use ast_softhangup() */
425 time_t whentohangup; /*!< Non-zero, set to actual time when channel is to be hung up */
426 pthread_t blocker; /*!< If anyone is blocking, this is them */
427 ast_mutex_t lock_dont_use; /*!< Lock a channel for some operations. See ast_channel_lock() */
428 const char *blockproc; /*!< Procedure causing blocking */
430 const char *appl; /*!< Current application */
431 const char *data; /*!< Data passed to current application */
432 int fdno; /*!< Which fd had an event detected on */
433 struct sched_context *sched; /*!< Schedule context */
434 int streamid; /*!< For streaming playback, the schedule ID */
435 struct ast_filestream *stream; /*!< Stream itself. */
436 int vstreamid; /*!< For streaming video playback, the schedule ID */
437 struct ast_filestream *vstream; /*!< Video Stream itself. */
438 int oldwriteformat; /*!< Original writer format */
440 int timingfd; /*!< Timing fd */
441 int (*timingfunc)(const void *data);
444 enum ast_channel_state _state; /*!< State of line -- Don't write directly, use ast_setstate() */
445 int rings; /*!< Number of rings so far */
446 struct ast_callerid cid; /*!< Caller ID, name, presentation etc */
447 char dtmfq[AST_MAX_EXTENSION]; /*!< Any/all queued DTMF characters */
448 struct ast_frame dtmff; /*!< DTMF frame */
450 char context[AST_MAX_CONTEXT]; /*!< Dialplan: Current extension context */
451 char exten[AST_MAX_EXTENSION]; /*!< Dialplan: Current extension number */
452 int priority; /*!< Dialplan: Current extension priority */
453 char macrocontext[AST_MAX_CONTEXT]; /*!< Macro: Current non-macro context. See app_macro.c */
454 char macroexten[AST_MAX_EXTENSION]; /*!< Macro: Current non-macro extension. See app_macro.c */
455 int macropriority; /*!< Macro: Current non-macro priority. See app_macro.c */
456 char dialcontext[AST_MAX_CONTEXT]; /*!< Dial: Extension context that we were called from */
458 struct ast_pbx *pbx; /*!< PBX private structure for this channel */
459 int amaflags; /*!< Set BEFORE PBX is started to determine AMA flags */
460 struct ast_cdr *cdr; /*!< Call Detail Record */
461 enum ast_channel_adsicpe adsicpe; /*!< Whether or not ADSI is detected on CPE */
463 struct ind_tone_zone *zone; /*!< Tone zone as set in indications.conf or
464 in the CHANNEL dialplan function */
466 struct ast_channel_monitor *monitor; /*!< Channel monitoring */
468 unsigned long insmpl; /*!< Track the read/written samples for monitor use */
469 unsigned long outsmpl; /*!< Track the read/written samples for monitor use */
471 unsigned int fin; /*!< Frames in counters. The high bit is a debug mask, so
472 the counter is only in the remaining bits */
473 unsigned int fout; /*!< Frames out counters. The high bit is a debug mask, so
474 the counter is only in the remaining bits */
475 int hangupcause; /*!< Why is the channel hanged up. See causes.h */
476 struct varshead varshead; /*!< A linked list for channel variables. See \ref AstChanVar */
477 ast_group_t callgroup; /*!< Call group for call pickups */
478 ast_group_t pickupgroup; /*!< Pickup group - which calls groups can be picked up? */
479 unsigned int flags; /*!< channel flags of AST_FLAG_ type */
480 unsigned short transfercapability; /*!< ISDN Transfer Capbility - AST_FLAG_DIGITAL is not enough */
481 AST_LIST_HEAD_NOLOCK(, ast_frame) readq;
484 int nativeformats; /*!< Kinds of data this channel can natively handle */
485 int readformat; /*!< Requested read format */
486 int writeformat; /*!< Requested write format */
487 struct ast_trans_pvt *writetrans; /*!< Write translation path */
488 struct ast_trans_pvt *readtrans; /*!< Read translation path */
489 int rawreadformat; /*!< Raw read format */
490 int rawwriteformat; /*!< Raw write format */
492 struct ast_audiohook_list *audiohooks;
494 AST_LIST_ENTRY(ast_channel) chan_list; /*!< For easy linking */
496 struct ast_jb jb; /*!< The jitterbuffer state */
498 char emulate_dtmf_digit; /*!< Digit being emulated */
499 unsigned int emulate_dtmf_duration; /*!< Number of ms left to emulate DTMF for */
500 struct timeval dtmf_tv; /*!< The time that an in process digit began, or the last digit ended */
502 AST_LIST_HEAD_NOLOCK(datastores, ast_datastore) datastores; /*!< Data stores on the channel */
506 struct ast_epoll_data *epfd_data[AST_MAX_FDS];
508 int visible_indication; /*!< Indication currently playing on the channel */
511 /*! \brief ast_channel_tech Properties */
513 /*! \brief Channels have this property if they can accept input with jitter;
514 * i.e. most VoIP channels */
515 AST_CHAN_TP_WANTSJITTER = (1 << 0),
516 /*! \brief Channels have this property if they can create jitter;
517 * i.e. most VoIP channels */
518 AST_CHAN_TP_CREATESJITTER = (1 << 1),
521 /*! \brief ast_channel flags */
523 /*! Queue incoming dtmf, to be released when this flag is turned off */
524 AST_FLAG_DEFER_DTMF = (1 << 1),
525 /*! write should be interrupt generator */
526 AST_FLAG_WRITE_INT = (1 << 2),
527 /*! a thread is blocking on this channel */
528 AST_FLAG_BLOCKING = (1 << 3),
529 /*! This is a zombie channel */
530 AST_FLAG_ZOMBIE = (1 << 4),
531 /*! There is an exception pending */
532 AST_FLAG_EXCEPTION = (1 << 5),
533 /*! Listening to moh XXX anthm promises me this will disappear XXX */
534 AST_FLAG_MOH = (1 << 6),
535 /*! This channel is spying on another channel */
536 AST_FLAG_SPYING = (1 << 7),
537 /*! This channel is in a native bridge */
538 AST_FLAG_NBRIDGE = (1 << 8),
539 /*! the channel is in an auto-incrementing dialplan processor,
540 * so when ->priority is set, it will get incremented before
541 * finding the next priority to run */
542 AST_FLAG_IN_AUTOLOOP = (1 << 9),
543 /*! This is an outgoing call */
544 AST_FLAG_OUTGOING = (1 << 10),
545 /*! A DTMF_BEGIN frame has been read from this channel, but not yet an END */
546 AST_FLAG_IN_DTMF = (1 << 12),
547 /*! A DTMF_END was received when not IN_DTMF, so the length of the digit is
548 * currently being emulated */
549 AST_FLAG_EMULATE_DTMF = (1 << 13),
550 /*! This is set to tell the channel not to generate DTMF begin frames, and
551 * to instead only generate END frames. */
552 AST_FLAG_END_DTMF_ONLY = (1 << 14),
553 /*! Flag to show channels that this call is hangup due to the fact that the call
554 was indeed anwered, but in another channel */
555 AST_FLAG_ANSWERED_ELSEWHERE = (1 << 15),
556 /*! This flag indicates that on a masquerade, an active stream should not
558 AST_FLAG_MASQ_NOSTREAM = (1 << 16),
561 /*! \brief ast_bridge_config flags */
563 AST_FEATURE_PLAY_WARNING = (1 << 0),
564 AST_FEATURE_REDIRECT = (1 << 1),
565 AST_FEATURE_DISCONNECT = (1 << 2),
566 AST_FEATURE_ATXFER = (1 << 3),
567 AST_FEATURE_AUTOMON = (1 << 4),
568 AST_FEATURE_PARKCALL = (1 << 5),
569 AST_FEATURE_AUTOMIXMON = (1 << 6),
572 /*! \brief bridge configuration */
573 struct ast_bridge_config {
574 struct ast_flags features_caller;
575 struct ast_flags features_callee;
576 struct timeval start_time;
581 const char *warning_sound;
582 const char *end_sound;
583 const char *start_sound;
590 struct outgoing_helper {
595 const char *cid_name;
597 struct ast_variable *vars;
598 struct ast_channel *parent_channel;
602 AST_CDR_TRANSFER = (1 << 0),
603 AST_CDR_FORWARD = (1 << 1),
604 AST_CDR_CALLWAIT = (1 << 2),
605 AST_CDR_CONFERENCE = (1 << 3),
609 /*! Soft hangup by device */
610 AST_SOFTHANGUP_DEV = (1 << 0),
611 /*! Soft hangup for async goto */
612 AST_SOFTHANGUP_ASYNCGOTO = (1 << 1),
613 AST_SOFTHANGUP_SHUTDOWN = (1 << 2),
614 AST_SOFTHANGUP_TIMEOUT = (1 << 3),
615 AST_SOFTHANGUP_APPUNLOAD = (1 << 4),
616 AST_SOFTHANGUP_EXPLICIT = (1 << 5),
617 AST_SOFTHANGUP_UNBRIDGE = (1 << 6),
621 /*! \brief Channel reload reasons for manager events at load or reload of configuration */
622 enum channelreloadreason {
624 CHANNEL_MODULE_RELOAD,
626 CHANNEL_MANAGER_RELOAD,
630 * \brief Create a channel datastore structure
632 * \note None of the datastore API calls lock the ast_channel they are using.
633 * So, the channel should be locked before calling the functions that
634 * take a channel argument.
636 struct ast_datastore *ast_channel_datastore_alloc(const struct ast_datastore_info *info, const char *uid);
638 /*! \brief Free a channel datastore structure */
639 int ast_channel_datastore_free(struct ast_datastore *datastore);
641 /*! \brief Inherit datastores from a parent to a child. */
642 int ast_channel_datastore_inherit(struct ast_channel *from, struct ast_channel *to);
645 * \brief Add a datastore to a channel
647 * \note The channel should be locked before calling this function.
650 * \retval non-zero failure
652 int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore);
655 * \brief Remove a datastore from a channel
657 * \note The channel should be locked before calling this function.
660 * \retval non-zero failure
662 int ast_channel_datastore_remove(struct ast_channel *chan, struct ast_datastore *datastore);
665 * \brief Find a datastore on a channel
667 * \note The channel should be locked before calling this function.
669 * \note The datastore returned from this function must not be used if the
670 * reference to the channel is released.
672 struct ast_datastore *ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid);
674 /*! \brief Change the state of a channel */
675 int ast_setstate(struct ast_channel *chan, enum ast_channel_state);
678 * \brief Create a channel structure
680 * \retval NULL failure
681 * \retval non-NULL successfully allocated channel
683 * \note By default, new channels are set to the "s" extension
684 * and "default" context.
686 struct ast_channel *ast_channel_alloc(int needqueue, int state, const char *cid_num, const char *cid_name, const char *acctcode, const char *exten, const char *context, const int amaflag, const char *name_fmt, ...);
689 * \brief Queue an outgoing frame
691 * \note The channel does not need to be locked before calling this function.
693 int ast_queue_frame(struct ast_channel *chan, struct ast_frame *f);
696 * \brief Queue a hangup frame
698 * \note The channel does not need to be locked before calling this function.
700 int ast_queue_hangup(struct ast_channel *chan);
703 * \brief Queue a control frame with payload
705 * \param chan channel to queue frame onto
706 * \param control type of control frame
708 * \note The channel does not need to be locked before calling this function.
710 * \retval zero on success
711 * \retval non-zero on failure
713 int ast_queue_control(struct ast_channel *chan, enum ast_control_frame_type control);
716 * \brief Queue a control frame with payload
718 * \param chan channel to queue frame onto
719 * \param control type of control frame
720 * \param data pointer to payload data to be included in frame
721 * \param datalen number of bytes of payload data
724 * \retval non-zero failure
726 * The supplied payload data is copied into the frame, so the caller's copy
727 * is not modified nor freed, and the resulting frame will retain a copy of
728 * the data even if the caller frees their local copy.
730 * \note This method should be treated as a 'network transport'; in other
731 * words, your frames may be transferred across an IAX2 channel to another
732 * system, which may be a different endianness than yours. Because of this,
733 * you should ensure that either your frames will never be expected to work
734 * across systems, or that you always put your payload data into 'network byte
735 * order' before calling this function.
737 * \note The channel does not need to be locked before calling this function.
739 int ast_queue_control_data(struct ast_channel *chan, enum ast_control_frame_type control,
740 const void *data, size_t datalen);
743 * \brief Change channel name
745 * \note The channel must be locked before calling this function.
747 void ast_change_name(struct ast_channel *chan, char *newname);
749 /*! \brief Free a channel structure */
750 void ast_channel_free(struct ast_channel *);
753 * \brief Requests a channel
755 * \param type type of channel to request
756 * \param format requested channel format (codec)
757 * \param data data to pass to the channel requester
758 * \param status status
760 * Request a channel of a given type, with data as optional information used
761 * by the low level module
763 * \retval NULL failure
764 * \retval non-NULL channel on success
766 struct ast_channel *ast_request(const char *type, int format, void *data, int *status);
769 * \brief Request a channel of a given type, with data as optional information used
770 * by the low level module and attempt to place a call on it
772 * \param type type of channel to request
773 * \param format requested channel format
774 * \param data data to pass to the channel requester
775 * \param timeout maximum amount of time to wait for an answer
776 * \param reason why unsuccessful (if unsuccessful)
777 * \param cid_num Caller-ID Number
778 * \param cid_name Caller-ID Name (ascii)
780 * \return Returns an ast_channel on success or no answer, NULL on failure. Check the value of chan->_state
781 * to know if the call was answered or not.
783 struct ast_channel *ast_request_and_dial(const char *type, int format, void *data,
784 int timeout, int *reason, const char *cid_num, const char *cid_name);
787 * \brief Request a channel of a given type, with data as optional information used
788 * by the low level module and attempt to place a call on it
789 * \param type type of channel to request
790 * \param format requested channel format
791 * \param data data to pass to the channel requester
792 * \param timeout maximum amount of time to wait for an answer
793 * \param reason why unsuccessful (if unsuccessful)
794 * \param cid_num Caller-ID Number
795 * \param cid_name Caller-ID Name (ascii)
796 * \param oh Outgoing helper
797 * \return Returns an ast_channel on success or no answer, NULL on failure. Check the value of chan->_state
798 * to know if the call was answered or not.
800 struct ast_channel *__ast_request_and_dial(const char *type, int format, void *data,
801 int timeout, int *reason, const char *cid_num, const char *cid_name, struct outgoing_helper *oh);
803 /*!\brief Register a channel technology (a new channel driver)
804 * Called by a channel module to register the kind of channels it supports.
805 * \param tech Structure defining channel technology or "type"
806 * \return Returns 0 on success, -1 on failure.
808 int ast_channel_register(const struct ast_channel_tech *tech);
810 /*! \brief Unregister a channel technology
811 * \param tech Structure defining channel technology or "type" that was previously registered
812 * \return No return value.
814 void ast_channel_unregister(const struct ast_channel_tech *tech);
816 /*! \brief Get a channel technology structure by name
817 * \param name name of technology to find
818 * \return a pointer to the structure, or NULL if no matching technology found
820 const struct ast_channel_tech *ast_get_channel_tech(const char *name);
822 /*! \brief Hang up a channel
823 * \note This function performs a hard hangup on a channel. Unlike the soft-hangup, this function
824 * performs all stream stopping, etc, on the channel that needs to end.
825 * chan is no longer valid after this call.
826 * \param chan channel to hang up
827 * \return Returns 0 on success, -1 on failure.
829 int ast_hangup(struct ast_channel *chan);
832 * \brief Softly hangup up a channel
834 * \param chan channel to be soft-hung-up
835 * \param cause Ast hangupcause for hangup
837 * Call the protocol layer, but don't destroy the channel structure
838 * (use this if you are trying to
839 * safely hangup a channel managed by another thread.
841 * \note The channel passed to this function does not need to be locked.
843 * \return Returns 0 regardless
845 int ast_softhangup(struct ast_channel *chan, int cause);
847 /*! \brief Softly hangup up a channel (no channel lock)
848 * \param chan channel to be soft-hung-up
849 * \param cause Ast hangupcause for hangup (see cause.h) */
850 int ast_softhangup_nolock(struct ast_channel *chan, int cause);
852 /*! \brief Check to see if a channel is needing hang up
853 * \param chan channel on which to check for hang up
854 * This function determines if the channel is being requested to be hung up.
855 * \return Returns 0 if not, or 1 if hang up is requested (including time-out).
857 int ast_check_hangup(struct ast_channel *chan);
859 /*! \brief Compare a offset with the settings of when to hang a channel up
860 * \param chan channel on which to check for hang up
861 * \param offset offset in seconds from current time
862 * \return 1, 0, or -1
863 * This function compares a offset from current time with the absolute time
864 * out on a channel (when to hang up). If the absolute time out on a channel
865 * is earlier than current time plus the offset, it returns 1, if the two
866 * time values are equal, it return 0, otherwise, it return -1.
868 int ast_channel_cmpwhentohangup(struct ast_channel *chan, time_t offset);
870 /*! \brief Set when to hang a channel up
872 * \param chan channel on which to check for hang up
873 * \param offset offset in seconds from current time of when to hang up
875 * This function sets the absolute time out on a channel (when to hang up).
877 * \note This function does not require that the channel is locked before
882 void ast_channel_setwhentohangup(struct ast_channel *chan, time_t offset);
885 * \brief Answer a channel
887 * \param chan channel to answer
889 * This function answers a channel and handles all necessary call
892 * \note The channel passed does not need to be locked.
894 * \retval 0 on success
895 * \retval non-zero on failure
897 int ast_answer(struct ast_channel *chan);
898 int __ast_answer(struct ast_channel *chan, unsigned int delay);
900 /*! \brief Make a call
901 * \param chan which channel to make the call on
902 * \param addr destination of the call
903 * \param timeout time to wait on for connect
904 * Place a call, take no longer than timeout ms.
905 \return Returns -1 on failure, 0 on not enough time
906 (does not automatically stop ringing), and
907 the number of seconds the connect took otherwise.
909 int ast_call(struct ast_channel *chan, char *addr, int timeout);
911 /*! \brief Indicates condition of channel
912 * \note Indicate a condition such as AST_CONTROL_BUSY, AST_CONTROL_RINGING, or AST_CONTROL_CONGESTION on a channel
913 * \param chan channel to change the indication
914 * \param condition which condition to indicate on the channel
915 * \return Returns 0 on success, -1 on failure
917 int ast_indicate(struct ast_channel *chan, int condition);
919 /*! \brief Indicates condition of channel, with payload
920 * \note Indicate a condition such as AST_CONTROL_HOLD with payload being music on hold class
921 * \param chan channel to change the indication
922 * \param condition which condition to indicate on the channel
923 * \param data pointer to payload data
924 * \param datalen size of payload data
925 * \return Returns 0 on success, -1 on failure
927 int ast_indicate_data(struct ast_channel *chan, int condition, const void *data, size_t datalen);
929 /* Misc stuff ------------------------------------------------ */
931 /*! \brief Wait for input on a channel
932 * \param chan channel to wait on
933 * \param ms length of time to wait on the channel
934 * Wait for input on a channel for a given # of milliseconds (<0 for indefinite).
935 \return Returns < 0 on failure, 0 if nothing ever arrived, and the # of ms remaining otherwise */
936 int ast_waitfor(struct ast_channel *chan, int ms);
938 /*! \brief Wait for a specified amount of time, looking for hangups
939 * \param chan channel to wait for
940 * \param ms length of time in milliseconds to sleep
941 * Waits for a specified amount of time, servicing the channel as required.
942 * \return returns -1 on hangup, otherwise 0.
944 int ast_safe_sleep(struct ast_channel *chan, int ms);
946 /*! \brief Wait for a specified amount of time, looking for hangups and a condition argument
947 * \param chan channel to wait for
948 * \param ms length of time in milliseconds to sleep
949 * \param cond a function pointer for testing continue condition
950 * \param data argument to be passed to the condition test function
951 * \return returns -1 on hangup, otherwise 0.
952 * Waits for a specified amount of time, servicing the channel as required. If cond
953 * returns 0, this function returns.
955 int ast_safe_sleep_conditional(struct ast_channel *chan, int ms, int (*cond)(void*), void *data );
957 /*! \brief Waits for activity on a group of channels
958 * \param chan an array of pointers to channels
959 * \param n number of channels that are to be waited upon
960 * \param fds an array of fds to wait upon
961 * \param nfds the number of fds to wait upon
962 * \param exception exception flag
963 * \param outfd fd that had activity on it
964 * \param ms how long the wait was
965 * Big momma function here. Wait for activity on any of the n channels, or any of the nfds
967 \return Returns the channel with activity, or NULL on error or if an FD
968 came first. If the FD came first, it will be returned in outfd, otherwise, outfd
970 struct ast_channel *ast_waitfor_nandfds(struct ast_channel **chan, int n,
971 int *fds, int nfds, int *exception, int *outfd, int *ms);
973 /*! \brief Waits for input on a group of channels
974 Wait for input on an array of channels for a given # of milliseconds.
975 \return Return channel with activity, or NULL if none has activity.
976 \param chan an array of pointers to channels
977 \param n number of channels that are to be waited upon
978 \param ms time "ms" is modified in-place, if applicable */
979 struct ast_channel *ast_waitfor_n(struct ast_channel **chan, int n, int *ms);
981 /*! \brief Waits for input on an fd
982 This version works on fd's only. Be careful with it. */
983 int ast_waitfor_n_fd(int *fds, int n, int *ms, int *exception);
986 /*! \brief Reads a frame
987 * \param chan channel to read a frame from
988 * \return Returns a frame, or NULL on error. If it returns NULL, you
989 best just stop reading frames and assume the channel has been
991 struct ast_frame *ast_read(struct ast_channel *chan);
993 /*! \brief Reads a frame, returning AST_FRAME_NULL frame if audio.
994 \param chan channel to read a frame from
995 \return Returns a frame, or NULL on error. If it returns NULL, you
996 best just stop reading frames and assume the channel has been
998 \note Audio is replaced with AST_FRAME_NULL to avoid
999 transcode when the resulting audio is not necessary. */
1000 struct ast_frame *ast_read_noaudio(struct ast_channel *chan);
1002 /*! \brief Write a frame to a channel
1003 * This function writes the given frame to the indicated channel.
1004 * \param chan destination channel of the frame
1005 * \param frame frame that will be written
1006 * \return It returns 0 on success, -1 on failure.
1008 int ast_write(struct ast_channel *chan, struct ast_frame *frame);
1010 /*! \brief Write video frame to a channel
1011 * This function writes the given frame to the indicated channel.
1012 * \param chan destination channel of the frame
1013 * \param frame frame that will be written
1014 * \return It returns 1 on success, 0 if not implemented, and -1 on failure.
1016 int ast_write_video(struct ast_channel *chan, struct ast_frame *frame);
1018 /*! \brief Write text frame to a channel
1019 * This function writes the given frame to the indicated channel.
1020 * \param chan destination channel of the frame
1021 * \param frame frame that will be written
1022 * \return It returns 1 on success, 0 if not implemented, and -1 on failure.
1024 int ast_write_text(struct ast_channel *chan, struct ast_frame *frame);
1026 /*! \brief Send empty audio to prime a channel driver */
1027 int ast_prod(struct ast_channel *chan);
1029 /*! \brief Sets read format on channel chan
1030 * Set read format for channel to whichever component of "format" is best.
1031 * \param chan channel to change
1032 * \param format format to change to
1033 * \return Returns 0 on success, -1 on failure
1035 int ast_set_read_format(struct ast_channel *chan, int format);
1037 /*! \brief Sets write format on channel chan
1038 * Set write format for channel to whichever component of "format" is best.
1039 * \param chan channel to change
1040 * \param format new format for writing
1041 * \return Returns 0 on success, -1 on failure
1043 int ast_set_write_format(struct ast_channel *chan, int format);
1046 * \brief Sends text to a channel
1048 * \param chan channel to act upon
1049 * \param text string of text to send on the channel
1051 * Write text to a display on a channel
1053 * \note The channel does not need to be locked before calling this function.
1055 * \retval 0 on success
1056 * \retval -1 on failure
1058 int ast_sendtext(struct ast_channel *chan, const char *text);
1060 /*! \brief Receives a text character from a channel
1061 * \param chan channel to act upon
1062 * \param timeout timeout in milliseconds (0 for infinite wait)
1063 * Read a char of text from a channel
1064 * Returns 0 on success, -1 on failure
1066 int ast_recvchar(struct ast_channel *chan, int timeout);
1068 /*! \brief Send a DTMF digit to a channel
1069 * Send a DTMF digit to a channel.
1070 * \param chan channel to act upon
1071 * \param digit the DTMF digit to send, encoded in ASCII
1072 * \param duration the duration of the digit ending in ms
1073 * \return Returns 0 on success, -1 on failure
1075 int ast_senddigit(struct ast_channel *chan, char digit, unsigned int duration);
1077 /*! \brief Send a DTMF digit to a channel
1078 * Send a DTMF digit to a channel.
1079 * \param chan channel to act upon
1080 * \param digit the DTMF digit to send, encoded in ASCII
1081 * \return Returns 0 on success, -1 on failure
1083 int ast_senddigit_begin(struct ast_channel *chan, char digit);
1085 /*! \brief Send a DTMF digit to a channel
1087 * Send a DTMF digit to a channel.
1088 * \param chan channel to act upon
1089 * \param digit the DTMF digit to send, encoded in ASCII
1090 * \param duration the duration of the digit ending in ms
1091 * \return Returns 0 on success, -1 on failure
1093 int ast_senddigit_end(struct ast_channel *chan, char digit, unsigned int duration);
1095 /*! \brief Receives a text string from a channel
1096 * Read a string of text from a channel
1097 * \param chan channel to act upon
1098 * \param timeout timeout in milliseconds (0 for infinite wait)
1099 * \return the received text, or NULL to signify failure.
1101 char *ast_recvtext(struct ast_channel *chan, int timeout);
1103 /*! \brief Browse channels in use
1104 * Browse the channels currently in use
1105 * \param prev where you want to start in the channel list
1106 * \return Returns the next channel in the list, NULL on end.
1107 * If it returns a channel, that channel *has been locked*!
1109 struct ast_channel *ast_channel_walk_locked(const struct ast_channel *prev);
1111 /*! \brief Get channel by name (locks channel) */
1112 struct ast_channel *ast_get_channel_by_name_locked(const char *chan);
1114 /*! \brief Get channel by name prefix (locks channel) */
1115 struct ast_channel *ast_get_channel_by_name_prefix_locked(const char *name, const int namelen);
1117 /*! \brief Get channel by name prefix (locks channel) */
1118 struct ast_channel *ast_walk_channel_by_name_prefix_locked(const struct ast_channel *chan, const char *name, const int namelen);
1120 /*! \brief Get channel by exten (and optionally context) and lock it */
1121 struct ast_channel *ast_get_channel_by_exten_locked(const char *exten, const char *context);
1123 /*! \brief Get next channel by exten (and optionally context) and lock it */
1124 struct ast_channel *ast_walk_channel_by_exten_locked(const struct ast_channel *chan, const char *exten,
1125 const char *context);
1127 /*! ! \brief Waits for a digit
1128 * \param c channel to wait for a digit on
1129 * \param ms how many milliseconds to wait
1130 * \return Returns <0 on error, 0 on no entry, and the digit on success. */
1131 int ast_waitfordigit(struct ast_channel *c, int ms);
1133 /*! \brief Wait for a digit
1134 Same as ast_waitfordigit() with audio fd for outputting read audio and ctrlfd to monitor for reading.
1135 * \param c channel to wait for a digit on
1136 * \param ms how many milliseconds to wait
1137 * \param audiofd audio file descriptor to write to if audio frames are received
1138 * \param ctrlfd control file descriptor to monitor for reading
1139 * \return Returns 1 if ctrlfd becomes available */
1140 int ast_waitfordigit_full(struct ast_channel *c, int ms, int audiofd, int ctrlfd);
1142 /*! Reads multiple digits
1143 * \param c channel to read from
1144 * \param s string to read in to. Must be at least the size of your length
1145 * \param len how many digits to read (maximum)
1146 * \param timeout how long to timeout between digits
1147 * \param rtimeout timeout to wait on the first digit
1148 * \param enders digits to end the string
1149 * Read in a digit string "s", max length "len", maximum timeout between
1150 digits "timeout" (-1 for none), terminated by anything in "enders". Give them rtimeout
1151 for the first digit. Returns 0 on normal return, or 1 on a timeout. In the case of
1152 a timeout, any digits that were read before the timeout will still be available in s.
1153 RETURNS 2 in full version when ctrlfd is available, NOT 1*/
1154 int ast_readstring(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders);
1155 int ast_readstring_full(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders, int audiofd, int ctrlfd);
1157 /*! \brief Report DTMF on channel 0 */
1158 #define AST_BRIDGE_DTMF_CHANNEL_0 (1 << 0)
1159 /*! \brief Report DTMF on channel 1 */
1160 #define AST_BRIDGE_DTMF_CHANNEL_1 (1 << 1)
1161 /*! \brief Return all voice frames on channel 0 */
1162 #define AST_BRIDGE_REC_CHANNEL_0 (1 << 2)
1163 /*! \brief Return all voice frames on channel 1 */
1164 #define AST_BRIDGE_REC_CHANNEL_1 (1 << 3)
1165 /*! \brief Ignore all signal frames except NULL */
1166 #define AST_BRIDGE_IGNORE_SIGS (1 << 4)
1169 /*! \brief Makes two channel formats compatible
1170 * \param c0 first channel to make compatible
1171 * \param c1 other channel to make compatible
1172 * Set two channels to compatible formats -- call before ast_channel_bridge in general .
1173 * \return Returns 0 on success and -1 if it could not be done */
1174 int ast_channel_make_compatible(struct ast_channel *c0, struct ast_channel *c1);
1176 /*! Bridge two channels together (early)
1177 * \param c0 first channel to bridge
1178 * \param c1 second channel to bridge
1179 * Bridge two channels (c0 and c1) together early. This implies either side may not be answered yet.
1180 * \return Returns 0 on success and -1 if it could not be done */
1181 int ast_channel_early_bridge(struct ast_channel *c0, struct ast_channel *c1);
1183 /*! Bridge two channels together
1184 * \param c0 first channel to bridge
1185 * \param c1 second channel to bridge
1186 * \param config config for the channels
1187 * \param fo destination frame(?)
1188 * \param rc destination channel(?)
1189 * Bridge two channels (c0 and c1) together. If an important frame occurs, we return that frame in
1190 *rf (remember, it could be NULL) and which channel (0 or 1) in rc */
1191 /* int ast_channel_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc); */
1192 int ast_channel_bridge(struct ast_channel *c0,struct ast_channel *c1,
1193 struct ast_bridge_config *config, struct ast_frame **fo, struct ast_channel **rc);
1196 * \brief Weird function made for call transfers
1198 * \param original channel to make a copy of
1199 * \param clone copy of the original channel
1201 * This is a very strange and freaky function used primarily for transfer. Suppose that
1202 * "original" and "clone" are two channels in random situations. This function takes
1203 * the guts out of "clone" and puts them into the "original" channel, then alerts the
1204 * channel driver of the change, asking it to fixup any private information (like the
1205 * p->owner pointer) that is affected by the change. The physical layer of the original
1206 * channel is hung up.
1208 * \note Neither channel passed here needs to be locked before calling this function.
1210 int ast_channel_masquerade(struct ast_channel *original, struct ast_channel *clone);
1212 /*! Gives the string form of a given cause code */
1214 * \param state cause to get the description of
1215 * Give a name to a cause code
1216 * Returns the text form of the binary cause code given
1218 const char *ast_cause2str(int state) attribute_pure;
1220 /*! Convert the string form of a cause code to a number */
1222 * \param name string form of the cause
1223 * Returns the cause code
1225 int ast_str2cause(const char *name) attribute_pure;
1227 /*! Gives the string form of a given channel state */
1229 * \param ast_channel_state state to get the name of
1230 * Give a name to a state
1231 * Returns the text form of the binary state given
1233 const char *ast_state2str(enum ast_channel_state);
1235 /*! Gives the string form of a given transfer capability */
1237 * \param transfercapability transfercapabilty to get the name of
1238 * Give a name to a transfercapbility
1240 * Returns the text form of the binary transfer capbaility
1242 char *ast_transfercapability2str(int transfercapability) attribute_const;
1244 /* Options: Some low-level drivers may implement "options" allowing fine tuning of the
1245 low level channel. See frame.h for options. Note that many channel drivers may support
1246 none or a subset of those features, and you should not count on this if you want your
1247 asterisk application to be portable. They're mainly useful for tweaking performance */
1249 /*! Sets an option on a channel */
1251 * \param channel channel to set options on
1252 * \param option option to change
1253 * \param data data specific to option
1254 * \param datalen length of the data
1255 * \param block blocking or not
1256 * Set an option on a channel (see frame.h), optionally blocking awaiting the reply
1257 * Returns 0 on success and -1 on failure
1259 int ast_channel_setoption(struct ast_channel *channel, int option, void *data, int datalen, int block);
1261 /*! Pick the best codec */
1262 /* Choose the best codec... Uhhh... Yah. */
1263 int ast_best_codec(int fmts);
1266 /*! Checks the value of an option */
1268 * Query the value of an option, optionally blocking until a reply is received
1269 * Works similarly to setoption except only reads the options.
1271 struct ast_frame *ast_channel_queryoption(struct ast_channel *channel, int option, void *data, int *datalen, int block);
1273 /*! Checks for HTML support on a channel */
1274 /*! Returns 0 if channel does not support HTML or non-zero if it does */
1275 int ast_channel_supports_html(struct ast_channel *channel);
1277 /*! Sends HTML on given channel */
1278 /*! Send HTML or URL on link. Returns 0 on success or -1 on failure */
1279 int ast_channel_sendhtml(struct ast_channel *channel, int subclass, const char *data, int datalen);
1281 /*! Sends a URL on a given link */
1282 /*! Send URL on link. Returns 0 on success or -1 on failure */
1283 int ast_channel_sendurl(struct ast_channel *channel, const char *url);
1286 /*! Defer DTMF so that you only read things like hangups and audio. Returns
1287 non-zero if channel was already DTMF-deferred or 0 if channel is just now
1288 being DTMF-deferred */
1289 int ast_channel_defer_dtmf(struct ast_channel *chan);
1291 /*! Undo defer. ast_read will return any dtmf characters that were queued */
1292 void ast_channel_undefer_dtmf(struct ast_channel *chan);
1294 /*! Initiate system shutdown -- prevents new channels from being allocated.
1295 If "hangup" is non-zero, all existing channels will receive soft
1297 void ast_begin_shutdown(int hangup);
1299 /*! Cancels an existing shutdown and returns to normal operation */
1300 void ast_cancel_shutdown(void);
1302 /*! Returns number of active/allocated channels */
1303 int ast_active_channels(void);
1305 /*! Returns non-zero if Asterisk is being shut down */
1306 int ast_shutting_down(void);
1308 /*! Activate a given generator */
1309 int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen, void *params);
1311 /*! Deactivate an active generator */
1312 void ast_deactivate_generator(struct ast_channel *chan);
1315 * \brief Set caller ID number, name and ANI
1317 * \note The channel does not need to be locked before calling this function.
1319 void ast_set_callerid(struct ast_channel *chan, const char *cid_num, const char *cid_name, const char *cid_ani);
1321 /*! Set the file descriptor on the channel */
1322 void ast_channel_set_fd(struct ast_channel *chan, int which, int fd);
1324 /*! Add a channel to an optimized waitfor */
1325 void ast_poll_channel_add(struct ast_channel *chan0, struct ast_channel *chan1);
1327 /*! Delete a channel from an optimized waitfor */
1328 void ast_poll_channel_del(struct ast_channel *chan0, struct ast_channel *chan1);
1330 /*! Start a tone going */
1331 int ast_tonepair_start(struct ast_channel *chan, int freq1, int freq2, int duration, int vol);
1332 /*! Stop a tone from playing */
1333 void ast_tonepair_stop(struct ast_channel *chan);
1334 /*! Play a tone pair for a given amount of time */
1335 int ast_tonepair(struct ast_channel *chan, int freq1, int freq2, int duration, int vol);
1338 * \brief Automatically service a channel for us...
1341 * \retval -1 failure, or the channel is already being autoserviced
1343 int ast_autoservice_start(struct ast_channel *chan);
1346 * \brief Stop servicing a channel for us...
1349 * \retval -1 error, or the channel has been hungup
1351 int ast_autoservice_stop(struct ast_channel *chan);
1353 /* If built with zaptel optimizations, force a scheduled expiration on the
1354 timer fd, at which point we call the callback function / data */
1355 int ast_settimeout(struct ast_channel *c, int samples, int (*func)(const void *data), void *data);
1357 /*! \brief Transfer a channel (if supported). Returns -1 on error, 0 if not supported
1358 and 1 if supported and requested
1359 \param chan current channel
1360 \param dest destination extension for transfer
1362 int ast_transfer(struct ast_channel *chan, char *dest);
1364 /*! \brief Start masquerading a channel
1365 XXX This is a seriously whacked out operation. We're essentially putting the guts of
1366 the clone channel into the original channel. Start by killing off the original
1367 channel's backend. I'm not sure we're going to keep this function, because
1368 while the features are nice, the cost is very high in terms of pure nastiness. XXX
1369 \param chan Channel to masquerade
1371 int ast_do_masquerade(struct ast_channel *chan);
1373 /*! \brief Find bridged channel
1374 \param chan Current channel
1376 struct ast_channel *ast_bridged_channel(struct ast_channel *chan);
1379 \brief Inherits channel variable from parent to child channel
1380 \param parent Parent channel
1381 \param child Child channel
1383 Scans all channel variables in the parent channel, looking for those
1384 that should be copied into the child channel.
1385 Variables whose names begin with a single '_' are copied into the
1386 child channel with the prefix removed.
1387 Variables whose names begin with '__' are copied into the child
1388 channel with their names unchanged.
1390 void ast_channel_inherit_variables(const struct ast_channel *parent, struct ast_channel *child);
1393 \brief adds a list of channel variables to a channel
1394 \param chan the channel
1395 \param vars a linked list of variables
1397 Variable names can be for a regular channel variable or a dialplan function
1398 that has the ability to be written to.
1400 void ast_set_variables(struct ast_channel *chan, struct ast_variable *vars);
1403 \brief An opaque 'object' structure use by silence generators on channels.
1405 struct ast_silence_generator;
1408 \brief Starts a silence generator on the given channel.
1409 \param chan The channel to generate silence on
1410 \return An ast_silence_generator pointer, or NULL if an error occurs
1412 This function will cause SLINEAR silence to be generated on the supplied
1413 channel until it is disabled; if the channel cannot be put into SLINEAR
1414 mode then the function will fail.
1416 The pointer returned by this function must be preserved and passed to
1417 ast_channel_stop_silence_generator when you wish to stop the silence
1420 struct ast_silence_generator *ast_channel_start_silence_generator(struct ast_channel *chan);
1423 \brief Stops a previously-started silence generator on the given channel.
1424 \param chan The channel to operate on
1425 \param state The ast_silence_generator pointer return by a previous call to
1426 ast_channel_start_silence_generator.
1429 This function will stop the operating silence generator and return the channel
1430 to its previous write format.
1432 void ast_channel_stop_silence_generator(struct ast_channel *chan, struct ast_silence_generator *state);
1435 \brief Check if the channel can run in internal timing mode.
1436 \param chan The channel to check
1439 This function will return 1 if internal timing is enabled and the timing
1440 device is available.
1442 int ast_internal_timing_enabled(struct ast_channel *chan);
1444 /* Misc. functions below */
1446 /*! \brief if fd is a valid descriptor, set *pfd with the descriptor
1447 * \return Return 1 (not -1!) if added, 0 otherwise (so we can add the
1448 * return value to the index into the array)
1450 static inline int ast_add_fd(struct pollfd *pfd, int fd)
1453 pfd->events = POLLIN | POLLPRI;
1457 /*! \brief Helper function for migrating select to poll */
1458 static inline int ast_fdisset(struct pollfd *pfds, int fd, int max, int *start)
1467 for (x = *start; x<max; x++)
1468 if (pfds[x].fd == fd) {
1471 return pfds[x].revents;
1476 #ifndef HAVE_TIMERSUB
1477 static inline void timersub(struct timeval *tvend, struct timeval *tvstart, struct timeval *tvdiff)
1479 tvdiff->tv_sec = tvend->tv_sec - tvstart->tv_sec;
1480 tvdiff->tv_usec = tvend->tv_usec - tvstart->tv_usec;
1481 if (tvdiff->tv_usec < 0) {
1483 tvdiff->tv_usec += 1000000;
1489 /*! \brief Waits for activity on a group of channels
1490 * \param nfds the maximum number of file descriptors in the sets
1491 * \param rfds file descriptors to check for read availability
1492 * \param wfds file descriptors to check for write availability
1493 * \param efds file descriptors to check for exceptions (OOB data)
1494 * \param tvp timeout while waiting for events
1495 * This is the same as a standard select(), except it guarantees the
1496 * behaviour where the passed struct timeval is updated with how much
1497 * time was not slept while waiting for the specified events
1499 static inline int ast_select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tvp)
1502 return select(nfds, rfds, wfds, efds, tvp);
1505 struct timeval tv, tvstart, tvend, tvlen;
1509 gettimeofday(&tvstart, NULL);
1510 res = select(nfds, rfds, wfds, efds, tvp);
1511 gettimeofday(&tvend, NULL);
1512 timersub(&tvend, &tvstart, &tvlen);
1513 timersub(&tv, &tvlen, tvp);
1514 if (tvp->tv_sec < 0 || (tvp->tv_sec == 0 && tvp->tv_usec < 0)) {
1521 return select(nfds, rfds, wfds, efds, NULL);
1526 #define CRASH do { fprintf(stderr, "!! Forcing immediate crash a-la abort !!\n"); *((int *)0) = 0; } while(0)
1528 #define CRASH do { } while(0)
1531 #define CHECK_BLOCKING(c) do { \
1532 if (ast_test_flag(c, AST_FLAG_BLOCKING)) {\
1534 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); \
1537 (c)->blocker = pthread_self(); \
1538 (c)->blockproc = __PRETTY_FUNCTION__; \
1539 ast_set_flag(c, AST_FLAG_BLOCKING); \
1542 ast_group_t ast_get_group(const char *s);
1544 /*! \brief print call- and pickup groups into buffer */
1545 char *ast_print_group(char *buf, int buflen, ast_group_t group);
1547 /*! \brief Convert enum channelreloadreason to text string for manager event
1548 \param reason Enum channelreloadreason - reason for reload (manager, cli, start etc)
1550 const char *channelreloadreason2txt(enum channelreloadreason reason);
1552 /*! \brief return an ast_variable list of channeltypes */
1553 struct ast_variable *ast_channeltype_list(void);
1556 \brief return an english explanation of the code returned thru __ast_request_and_dial's 'outstate' argument
1557 \param reason The integer argument, usually taken from AST_CONTROL_ macros
1558 \return char pointer explaining the code
1560 const char *ast_channel_reason2str(int reason);
1562 /*! \brief channel group info
1564 struct ast_group_info {
1565 struct ast_channel *chan;
1568 AST_LIST_ENTRY(ast_group_info) list;
1572 #if defined(__cplusplus) || defined(c_plusplus)
1576 #endif /* _ASTERISK_CHANNEL_H */