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 unlocked, but is called in
181 * the context of the channel thread so we know the channel is not going
182 * to disappear. This callback is responsible for locking the channel as
184 int (*generate)(struct ast_channel *chan, void *data, int len, int samples);
185 /*! This gets called when DTMF_END frames are read from the channel */
186 void (*digit)(struct ast_channel *chan, char digit);
189 /*! \brief Structure for a data store type */
190 struct ast_datastore_info {
191 const char *type; /*!< Type of data store */
192 void *(*duplicate)(void *data); /*!< Duplicate item data (used for inheritance) */
193 void (*destroy)(void *data); /*!< Destroy function */
196 /*! \brief Structure for a channel data store */
197 struct ast_datastore {
198 const char *uid; /*!< Unique data store identifier */
199 void *data; /*!< Contained data */
200 const struct ast_datastore_info *info; /*!< Data store type information */
201 unsigned int inheritance; /*!< Number of levels this item will continue to be inherited */
202 AST_LIST_ENTRY(ast_datastore) entry; /*!< Used for easy linking */
205 /*! \brief Structure for all kinds of caller ID identifications.
206 * \note All string fields here are malloc'ed, so they need to be
207 * freed when the structure is deleted.
208 * Also, NULL and "" must be considered equivalent.
210 * SIP and IAX2 has utf8 encoded Unicode caller ID names.
211 * In some cases, we also have an alternative (RPID) E.164 number that can be used
212 * as caller ID on numeric E.164 phone networks (zaptel or SIP/IAX2 to pstn gateway).
214 * \todo Implement settings for transliteration between UTF8 caller ID names in
215 * to Ascii Caller ID's (Zaptel). Östen Åsklund might be transliterated into
216 * Osten Asklund or Oesten Aasklund depending upon language and person...
217 * We need automatic routines for incoming calls and static settings for
220 struct ast_callerid {
221 char *cid_dnid; /*!< Malloc'd Dialed Number Identifier */
222 char *cid_num; /*!< Malloc'd Caller Number */
223 char *cid_name; /*!< Malloc'd Caller Name (ASCII) */
224 char *cid_ani; /*!< Malloc'd ANI */
225 char *cid_rdnis; /*!< Malloc'd RDNIS */
226 int cid_pres; /*!< Callerid presentation/screening */
227 int cid_ani2; /*!< Callerid ANI 2 (Info digits) */
228 int cid_ton; /*!< Callerid Type of Number */
229 int cid_tns; /*!< Callerid Transit Network Select */
233 Structure to describe a channel "technology", ie a channel driver
235 \arg chan_iax2.c - The Inter-Asterisk exchange protocol
236 \arg chan_sip.c - The SIP channel driver
237 \arg chan_zap.c - PSTN connectivity (TDM, PRI, T1/E1, FXO, FXS)
239 If you develop your own channel driver, this is where you
240 tell the PBX at registration of your driver what properties
241 this driver supports and where different callbacks are
244 struct ast_channel_tech {
245 const char * const type;
246 const char * const description;
248 int capabilities; /*!< Bitmap of formats this channel can handle */
250 int properties; /*!< Technology Properties */
252 /*! \brief Requester - to set up call data structures (pvt's) */
253 struct ast_channel *(* const requester)(const char *type, int format, void *data, int *cause);
255 int (* const devicestate)(void *data); /*!< Devicestate call back */
258 * \brief Start sending a literal DTMF digit
260 * \note The channel is not locked when this function gets called.
262 int (* const send_digit_begin)(struct ast_channel *chan, char digit);
265 * \brief Stop sending a literal DTMF digit
267 * \note The channel is not locked when this function gets called.
269 int (* const send_digit_end)(struct ast_channel *chan, char digit, unsigned int duration);
271 /*! \brief Call a given phone number (address, etc), but don't
272 take longer than timeout seconds to do so. */
273 int (* const call)(struct ast_channel *chan, char *addr, int timeout);
275 /*! \brief Hangup (and possibly destroy) the channel */
276 int (* const hangup)(struct ast_channel *chan);
278 /*! \brief Answer the channel */
279 int (* const answer)(struct ast_channel *chan);
281 /*! \brief Read a frame, in standard format (see frame.h) */
282 struct ast_frame * (* const read)(struct ast_channel *chan);
284 /*! \brief Write a frame, in standard format (see frame.h) */
285 int (* const write)(struct ast_channel *chan, struct ast_frame *frame);
287 /*! \brief Display or transmit text */
288 int (* const send_text)(struct ast_channel *chan, const char *text);
290 /*! \brief Display or send an image */
291 int (* const send_image)(struct ast_channel *chan, struct ast_frame *frame);
293 /*! \brief Send HTML data */
294 int (* const send_html)(struct ast_channel *chan, int subclass, const char *data, int len);
296 /*! \brief Handle an exception, reading a frame */
297 struct ast_frame * (* const exception)(struct ast_channel *chan);
299 /*! \brief Bridge two channels of the same type together */
300 enum ast_bridge_result (* const bridge)(struct ast_channel *c0, struct ast_channel *c1, int flags,
301 struct ast_frame **fo, struct ast_channel **rc, int timeoutms);
303 /*! \brief Bridge two channels of the same type together (early) */
304 enum ast_bridge_result (* const early_bridge)(struct ast_channel *c0, struct ast_channel *c1);
306 /*! \brief Indicate a particular condition (e.g. AST_CONTROL_BUSY or AST_CONTROL_RINGING or AST_CONTROL_CONGESTION */
307 int (* const indicate)(struct ast_channel *c, int condition, const void *data, size_t datalen);
309 /*! \brief Fix up a channel: If a channel is consumed, this is called. Basically update any ->owner links */
310 int (* const fixup)(struct ast_channel *oldchan, struct ast_channel *newchan);
312 /*! \brief Set a given option */
313 int (* const setoption)(struct ast_channel *chan, int option, void *data, int datalen);
315 /*! \brief Query a given option */
316 int (* const queryoption)(struct ast_channel *chan, int option, void *data, int *datalen);
318 /*! \brief Blind transfer other side (see app_transfer.c and ast_transfer() */
319 int (* const transfer)(struct ast_channel *chan, const char *newdest);
321 /*! \brief Write a frame, in standard format */
322 int (* const write_video)(struct ast_channel *chan, struct ast_frame *frame);
324 /*! \brief Write a text frame, in standard format */
325 int (* const write_text)(struct ast_channel *chan, struct ast_frame *frame);
327 /*! \brief Find bridged channel */
328 struct ast_channel *(* const bridged_channel)(struct ast_channel *chan, struct ast_channel *bridge);
330 /*! \brief Provide additional read items for CHANNEL() dialplan function */
331 int (* func_channel_read)(struct ast_channel *chan, const char *function, char *data, char *buf, size_t len);
333 /*! \brief Provide additional write items for CHANNEL() dialplan function */
334 int (* func_channel_write)(struct ast_channel *chan, const char *function, char *data, const char *value);
336 /*! \brief Retrieve base channel (agent and local) */
337 struct ast_channel* (* get_base_channel)(struct ast_channel *chan);
339 /*! \brief Set base channel (agent and local) */
340 int (* set_base_channel)(struct ast_channel *chan, struct ast_channel *base);
342 /*! \brief Get the unique identifier for the PVT, i.e. SIP call-ID for SIP */
343 char * (* get_pvt_uniqueid)(struct ast_channel *chan);
346 struct ast_epoll_data;
349 * The high bit of the frame count is used as a debug marker, so
350 * increments of the counters must be done with care.
351 * Please use c->fin = FRAMECOUNT_INC(c->fin) and the same for c->fout.
353 #define DEBUGCHAN_FLAG 0x80000000
355 /* XXX not ideal to evaluate x twice... */
356 #define FRAMECOUNT_INC(x) ( ((x) & DEBUGCHAN_FLAG) | (((x)+1) & ~DEBUGCHAN_FLAG) )
359 * The current value of the debug flags is stored in the two
360 * variables global_fin and global_fout (declared in main/channel.c)
362 extern unsigned long global_fin, global_fout;
364 enum ast_channel_adsicpe {
367 AST_ADSI_UNAVAILABLE,
368 AST_ADSI_OFFHOOKONLY,
372 * \brief ast_channel states
374 * \note Bits 0-15 of state are reserved for the state (up/down) of the line
375 * Bits 16-32 of state are reserved for flags
377 enum ast_channel_state {
378 AST_STATE_DOWN, /*!< Channel is down and available */
379 AST_STATE_RESERVED, /*!< Channel is down, but reserved */
380 AST_STATE_OFFHOOK, /*!< Channel is off hook */
381 AST_STATE_DIALING, /*!< Digits (or equivalent) have been dialed */
382 AST_STATE_RING, /*!< Line is ringing */
383 AST_STATE_RINGING, /*!< Remote end is ringing */
384 AST_STATE_UP, /*!< Line is up */
385 AST_STATE_BUSY, /*!< Line is busy */
386 AST_STATE_DIALING_OFFHOOK, /*!< Digits (or equivalent) have been dialed while offhook */
387 AST_STATE_PRERING, /*!< Channel has detected an incoming call and is waiting for ring */
389 AST_STATE_MUTE = (1 << 16), /*!< Do not transmit voice data */
392 /*! \brief Main Channel structure associated with a channel.
393 * This is the side of it mostly used by the pbx and call management.
395 * \note XXX It is important to remember to increment .cleancount each time
396 * this structure is changed. XXX
400 const struct ast_channel_tech *tech; /*!< Technology (point to channel driver) */
402 void *tech_pvt; /*!< Private data used by the technology driver */
404 AST_DECLARE_STRING_FIELDS(
405 AST_STRING_FIELD(name); /*!< ASCII unique channel name */
406 AST_STRING_FIELD(language); /*!< Language requested for voice prompts */
407 AST_STRING_FIELD(musicclass); /*!< Default music class */
408 AST_STRING_FIELD(accountcode); /*!< Account code for billing */
409 AST_STRING_FIELD(call_forward); /*!< Where to forward to if asked to dial on this interface */
410 AST_STRING_FIELD(uniqueid); /*!< Unique Channel Identifier */
413 int fds[AST_MAX_FDS]; /*!< File descriptors for channel -- Drivers will poll on
414 these file descriptors, so at least one must be non -1.
415 See \arg \ref AstFileDesc */
417 void *music_state; /*!< Music State*/
418 void *generatordata; /*!< Current generator data if there is any */
419 struct ast_generator *generator; /*!< Current active data generator */
421 struct ast_channel *_bridge; /*!< Who are we bridged to, if we're bridged.
422 Who is proxying for us, if we are proxied (i.e. chan_agent).
423 Do not access directly, use ast_bridged_channel(chan) */
425 struct ast_channel *masq; /*!< Channel that will masquerade as us */
426 struct ast_channel *masqr; /*!< Who we are masquerading as */
427 int cdrflags; /*!< Call Detail Record Flags */
429 int _softhangup; /*!< Whether or not we have been hung up... Do not set this value
430 directly, use ast_softhangup() */
431 time_t whentohangup; /*!< Non-zero, set to actual time when channel is to be hung up */
432 pthread_t blocker; /*!< If anyone is blocking, this is them */
433 ast_mutex_t lock_dont_use; /*!< Lock a channel for some operations. See ast_channel_lock() */
434 const char *blockproc; /*!< Procedure causing blocking */
436 const char *appl; /*!< Current application */
437 const char *data; /*!< Data passed to current application */
438 int fdno; /*!< Which fd had an event detected on */
439 struct sched_context *sched; /*!< Schedule context */
440 int streamid; /*!< For streaming playback, the schedule ID */
441 struct ast_filestream *stream; /*!< Stream itself. */
442 int vstreamid; /*!< For streaming video playback, the schedule ID */
443 struct ast_filestream *vstream; /*!< Video Stream itself. */
444 int oldwriteformat; /*!< Original writer format */
446 int timingfd; /*!< Timing fd */
447 int (*timingfunc)(const void *data);
450 enum ast_channel_state _state; /*!< State of line -- Don't write directly, use ast_setstate() */
451 int rings; /*!< Number of rings so far */
452 struct ast_callerid cid; /*!< Caller ID, name, presentation etc */
453 char dtmfq[AST_MAX_EXTENSION]; /*!< Any/all queued DTMF characters */
454 struct ast_frame dtmff; /*!< DTMF frame */
456 char context[AST_MAX_CONTEXT]; /*!< Dialplan: Current extension context */
457 char exten[AST_MAX_EXTENSION]; /*!< Dialplan: Current extension number */
458 int priority; /*!< Dialplan: Current extension priority */
459 char macrocontext[AST_MAX_CONTEXT]; /*!< Macro: Current non-macro context. See app_macro.c */
460 char macroexten[AST_MAX_EXTENSION]; /*!< Macro: Current non-macro extension. See app_macro.c */
461 int macropriority; /*!< Macro: Current non-macro priority. See app_macro.c */
462 char dialcontext[AST_MAX_CONTEXT]; /*!< Dial: Extension context that we were called from */
464 struct ast_pbx *pbx; /*!< PBX private structure for this channel */
465 int amaflags; /*!< Set BEFORE PBX is started to determine AMA flags */
466 struct ast_cdr *cdr; /*!< Call Detail Record */
467 enum ast_channel_adsicpe adsicpe; /*!< Whether or not ADSI is detected on CPE */
469 struct ind_tone_zone *zone; /*!< Tone zone as set in indications.conf or
470 in the CHANNEL dialplan function */
472 struct ast_channel_monitor *monitor; /*!< Channel monitoring */
474 unsigned long insmpl; /*!< Track the read/written samples for monitor use */
475 unsigned long outsmpl; /*!< Track the read/written samples for monitor use */
477 unsigned int fin; /*!< Frames in counters. The high bit is a debug mask, so
478 the counter is only in the remaining bits */
479 unsigned int fout; /*!< Frames out counters. The high bit is a debug mask, so
480 the counter is only in the remaining bits */
481 int hangupcause; /*!< Why is the channel hanged up. See causes.h */
482 struct varshead varshead; /*!< A linked list for channel variables. See \ref AstChanVar */
483 ast_group_t callgroup; /*!< Call group for call pickups */
484 ast_group_t pickupgroup; /*!< Pickup group - which calls groups can be picked up? */
485 unsigned int flags; /*!< channel flags of AST_FLAG_ type */
486 unsigned short transfercapability; /*!< ISDN Transfer Capbility - AST_FLAG_DIGITAL is not enough */
487 AST_LIST_HEAD_NOLOCK(, ast_frame) readq;
490 int nativeformats; /*!< Kinds of data this channel can natively handle */
491 int readformat; /*!< Requested read format */
492 int writeformat; /*!< Requested write format */
493 struct ast_trans_pvt *writetrans; /*!< Write translation path */
494 struct ast_trans_pvt *readtrans; /*!< Read translation path */
495 int rawreadformat; /*!< Raw read format */
496 int rawwriteformat; /*!< Raw write format */
498 struct ast_audiohook_list *audiohooks;
500 AST_LIST_ENTRY(ast_channel) chan_list; /*!< For easy linking */
502 struct ast_jb jb; /*!< The jitterbuffer state */
504 char emulate_dtmf_digit; /*!< Digit being emulated */
505 unsigned int emulate_dtmf_duration; /*!< Number of ms left to emulate DTMF for */
506 struct timeval dtmf_tv; /*!< The time that an in process digit began, or the last digit ended */
508 AST_LIST_HEAD_NOLOCK(datastores, ast_datastore) datastores; /*!< Data stores on the channel */
512 struct ast_epoll_data *epfd_data[AST_MAX_FDS];
514 int visible_indication; /*!< Indication currently playing on the channel */
517 /*! \brief ast_channel_tech Properties */
519 /*! \brief Channels have this property if they can accept input with jitter;
520 * i.e. most VoIP channels */
521 AST_CHAN_TP_WANTSJITTER = (1 << 0),
522 /*! \brief Channels have this property if they can create jitter;
523 * i.e. most VoIP channels */
524 AST_CHAN_TP_CREATESJITTER = (1 << 1),
527 /*! \brief ast_channel flags */
529 /*! Queue incoming dtmf, to be released when this flag is turned off */
530 AST_FLAG_DEFER_DTMF = (1 << 1),
531 /*! write should be interrupt generator */
532 AST_FLAG_WRITE_INT = (1 << 2),
533 /*! a thread is blocking on this channel */
534 AST_FLAG_BLOCKING = (1 << 3),
535 /*! This is a zombie channel */
536 AST_FLAG_ZOMBIE = (1 << 4),
537 /*! There is an exception pending */
538 AST_FLAG_EXCEPTION = (1 << 5),
539 /*! Listening to moh XXX anthm promises me this will disappear XXX */
540 AST_FLAG_MOH = (1 << 6),
541 /*! This channel is spying on another channel */
542 AST_FLAG_SPYING = (1 << 7),
543 /*! This channel is in a native bridge */
544 AST_FLAG_NBRIDGE = (1 << 8),
545 /*! the channel is in an auto-incrementing dialplan processor,
546 * so when ->priority is set, it will get incremented before
547 * finding the next priority to run */
548 AST_FLAG_IN_AUTOLOOP = (1 << 9),
549 /*! This is an outgoing call */
550 AST_FLAG_OUTGOING = (1 << 10),
551 /*! A DTMF_BEGIN frame has been read from this channel, but not yet an END */
552 AST_FLAG_IN_DTMF = (1 << 12),
553 /*! A DTMF_END was received when not IN_DTMF, so the length of the digit is
554 * currently being emulated */
555 AST_FLAG_EMULATE_DTMF = (1 << 13),
556 /*! This is set to tell the channel not to generate DTMF begin frames, and
557 * to instead only generate END frames. */
558 AST_FLAG_END_DTMF_ONLY = (1 << 14),
559 /*! Flag to show channels that this call is hangup due to the fact that the call
560 was indeed anwered, but in another channel */
561 AST_FLAG_ANSWERED_ELSEWHERE = (1 << 15),
562 /*! This flag indicates that on a masquerade, an active stream should not
564 AST_FLAG_MASQ_NOSTREAM = (1 << 16),
567 /*! \brief ast_bridge_config flags */
569 AST_FEATURE_PLAY_WARNING = (1 << 0),
570 AST_FEATURE_REDIRECT = (1 << 1),
571 AST_FEATURE_DISCONNECT = (1 << 2),
572 AST_FEATURE_ATXFER = (1 << 3),
573 AST_FEATURE_AUTOMON = (1 << 4),
574 AST_FEATURE_PARKCALL = (1 << 5),
575 AST_FEATURE_AUTOMIXMON = (1 << 6),
578 /*! \brief bridge configuration */
579 struct ast_bridge_config {
580 struct ast_flags features_caller;
581 struct ast_flags features_callee;
582 struct timeval start_time;
587 const char *warning_sound;
588 const char *end_sound;
589 const char *start_sound;
596 struct outgoing_helper {
601 const char *cid_name;
603 struct ast_variable *vars;
604 struct ast_channel *parent_channel;
608 AST_CDR_TRANSFER = (1 << 0),
609 AST_CDR_FORWARD = (1 << 1),
610 AST_CDR_CALLWAIT = (1 << 2),
611 AST_CDR_CONFERENCE = (1 << 3),
615 /*! Soft hangup by device */
616 AST_SOFTHANGUP_DEV = (1 << 0),
617 /*! Soft hangup for async goto */
618 AST_SOFTHANGUP_ASYNCGOTO = (1 << 1),
619 AST_SOFTHANGUP_SHUTDOWN = (1 << 2),
620 AST_SOFTHANGUP_TIMEOUT = (1 << 3),
621 AST_SOFTHANGUP_APPUNLOAD = (1 << 4),
622 AST_SOFTHANGUP_EXPLICIT = (1 << 5),
623 AST_SOFTHANGUP_UNBRIDGE = (1 << 6),
627 /*! \brief Channel reload reasons for manager events at load or reload of configuration */
628 enum channelreloadreason {
630 CHANNEL_MODULE_RELOAD,
632 CHANNEL_MANAGER_RELOAD,
636 * \brief Create a channel datastore structure
638 * \note None of the datastore API calls lock the ast_channel they are using.
639 * So, the channel should be locked before calling the functions that
640 * take a channel argument.
642 struct ast_datastore *ast_channel_datastore_alloc(const struct ast_datastore_info *info, const char *uid);
644 /*! \brief Free a channel datastore structure */
645 int ast_channel_datastore_free(struct ast_datastore *datastore);
647 /*! \brief Inherit datastores from a parent to a child. */
648 int ast_channel_datastore_inherit(struct ast_channel *from, struct ast_channel *to);
651 * \brief Add a datastore to a channel
653 * \note The channel should be locked before calling this function.
656 * \retval non-zero failure
659 int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore);
662 * \brief Remove a datastore from a channel
664 * \note The channel should be locked before calling this function.
667 * \retval non-zero failure
669 int ast_channel_datastore_remove(struct ast_channel *chan, struct ast_datastore *datastore);
672 * \brief Find a datastore on a channel
674 * \note The channel should be locked before calling this function.
676 * \note The datastore returned from this function must not be used if the
677 * reference to the channel is released.
679 struct ast_datastore *ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid);
681 /*! \brief Change the state of a channel */
682 int ast_setstate(struct ast_channel *chan, enum ast_channel_state);
685 * \brief Create a channel structure
687 * \retval NULL failure
688 * \retval non-NULL successfully allocated channel
690 * \note By default, new channels are set to the "s" extension
691 * and "default" context.
693 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, ...);
696 * \brief Queue an outgoing frame
698 * \note The channel does not need to be locked before calling this function.
700 int ast_queue_frame(struct ast_channel *chan, struct ast_frame *f);
703 * \brief Queue a hangup frame
705 * \note The channel does not need to be locked before calling this function.
707 int ast_queue_hangup(struct ast_channel *chan);
710 * \brief Queue a control frame with payload
712 * \param chan channel to queue frame onto
713 * \param control type of control frame
715 * \note The channel does not need to be locked before calling this function.
717 * \retval zero on success
718 * \retval non-zero on failure
720 int ast_queue_control(struct ast_channel *chan, enum ast_control_frame_type control);
723 * \brief Queue a control frame with payload
725 * \param chan channel to queue frame onto
726 * \param control type of control frame
727 * \param data pointer to payload data to be included in frame
728 * \param datalen number of bytes of payload data
731 * \retval non-zero failure
733 * The supplied payload data is copied into the frame, so the caller's copy
734 * is not modified nor freed, and the resulting frame will retain a copy of
735 * the data even if the caller frees their local copy.
737 * \note This method should be treated as a 'network transport'; in other
738 * words, your frames may be transferred across an IAX2 channel to another
739 * system, which may be a different endianness than yours. Because of this,
740 * you should ensure that either your frames will never be expected to work
741 * across systems, or that you always put your payload data into 'network byte
742 * order' before calling this function.
744 * \note The channel does not need to be locked before calling this function.
746 int ast_queue_control_data(struct ast_channel *chan, enum ast_control_frame_type control,
747 const void *data, size_t datalen);
750 * \brief Change channel name
752 * \note The channel must be locked before calling this function.
754 void ast_change_name(struct ast_channel *chan, char *newname);
756 /*! \brief Free a channel structure */
757 void ast_channel_free(struct ast_channel *);
760 * \brief Requests a channel
762 * \param type type of channel to request
763 * \param format requested channel format (codec)
764 * \param data data to pass to the channel requester
765 * \param status status
767 * Request a channel of a given type, with data as optional information used
768 * by the low level module
770 * \retval NULL failure
771 * \retval non-NULL channel on success
773 struct ast_channel *ast_request(const char *type, int format, void *data, int *status);
776 * \brief Request a channel of a given type, with data as optional information used
777 * by the low level module and attempt to place a call on it
779 * \param type type of channel to request
780 * \param format requested channel format
781 * \param data data to pass to the channel requester
782 * \param timeout maximum amount of time to wait for an answer
783 * \param reason why unsuccessful (if unsuccessful)
784 * \param cid_num Caller-ID Number
785 * \param cid_name Caller-ID Name (ascii)
787 * \return Returns an ast_channel on success or no answer, NULL on failure. Check the value of chan->_state
788 * to know if the call was answered or not.
790 struct ast_channel *ast_request_and_dial(const char *type, int format, void *data,
791 int timeout, int *reason, const char *cid_num, const char *cid_name);
794 * \brief Request a channel of a given type, with data as optional information used
795 * by the low level module and attempt to place a call on it
796 * \param type type of channel to request
797 * \param format requested channel format
798 * \param data data to pass to the channel requester
799 * \param timeout maximum amount of time to wait for an answer
800 * \param reason why unsuccessful (if unsuccessful)
801 * \param cid_num Caller-ID Number
802 * \param cid_name Caller-ID Name (ascii)
803 * \param oh Outgoing helper
804 * \return Returns an ast_channel on success or no answer, NULL on failure. Check the value of chan->_state
805 * to know if the call was answered or not.
807 struct ast_channel *__ast_request_and_dial(const char *type, int format, void *data,
808 int timeout, int *reason, const char *cid_num, const char *cid_name, struct outgoing_helper *oh);
810 /*!\brief Register a channel technology (a new channel driver)
811 * Called by a channel module to register the kind of channels it supports.
812 * \param tech Structure defining channel technology or "type"
813 * \return Returns 0 on success, -1 on failure.
815 int ast_channel_register(const struct ast_channel_tech *tech);
817 /*! \brief Unregister a channel technology
818 * \param tech Structure defining channel technology or "type" that was previously registered
819 * \return No return value.
821 void ast_channel_unregister(const struct ast_channel_tech *tech);
823 /*! \brief Get a channel technology structure by name
824 * \param name name of technology to find
825 * \return a pointer to the structure, or NULL if no matching technology found
827 const struct ast_channel_tech *ast_get_channel_tech(const char *name);
829 /*! \brief Hang up a channel
830 * \note This function performs a hard hangup on a channel. Unlike the soft-hangup, this function
831 * performs all stream stopping, etc, on the channel that needs to end.
832 * chan is no longer valid after this call.
833 * \param chan channel to hang up
834 * \return Returns 0 on success, -1 on failure.
836 int ast_hangup(struct ast_channel *chan);
839 * \brief Softly hangup up a channel
841 * \param chan channel to be soft-hung-up
842 * \param cause Ast hangupcause for hangup
844 * Call the protocol layer, but don't destroy the channel structure
845 * (use this if you are trying to
846 * safely hangup a channel managed by another thread.
848 * \note The channel passed to this function does not need to be locked.
850 * \return Returns 0 regardless
852 int ast_softhangup(struct ast_channel *chan, int cause);
854 /*! \brief Softly hangup up a channel (no channel lock)
855 * \param chan channel to be soft-hung-up
856 * \param cause Ast hangupcause for hangup (see cause.h) */
857 int ast_softhangup_nolock(struct ast_channel *chan, int cause);
859 /*! \brief Check to see if a channel is needing hang up
860 * \param chan channel on which to check for hang up
861 * This function determines if the channel is being requested to be hung up.
862 * \return Returns 0 if not, or 1 if hang up is requested (including time-out).
864 int ast_check_hangup(struct ast_channel *chan);
866 /*! \brief Compare a offset with the settings of when to hang a channel up
867 * \param chan channel on which to check for hang up
868 * \param offset offset in seconds from current time
869 * \return 1, 0, or -1
870 * This function compares a offset from current time with the absolute time
871 * out on a channel (when to hang up). If the absolute time out on a channel
872 * is earlier than current time plus the offset, it returns 1, if the two
873 * time values are equal, it return 0, otherwise, it return -1.
875 int ast_channel_cmpwhentohangup(struct ast_channel *chan, time_t offset);
877 /*! \brief Set when to hang a channel up
879 * \param chan channel on which to check for hang up
880 * \param offset offset in seconds from current time of when to hang up
882 * This function sets the absolute time out on a channel (when to hang up).
884 * \note This function does not require that the channel is locked before
889 void ast_channel_setwhentohangup(struct ast_channel *chan, time_t offset);
892 * \brief Answer a channel
894 * \param chan channel to answer
896 * This function answers a channel and handles all necessary call
899 * \note The channel passed does not need to be locked.
901 * \retval 0 on success
902 * \retval non-zero on failure
904 int ast_answer(struct ast_channel *chan);
905 int __ast_answer(struct ast_channel *chan, unsigned int delay);
907 /*! \brief Make a call
908 * \param chan which channel to make the call on
909 * \param addr destination of the call
910 * \param timeout time to wait on for connect
911 * Place a call, take no longer than timeout ms.
912 \return Returns -1 on failure, 0 on not enough time
913 (does not automatically stop ringing), and
914 the number of seconds the connect took otherwise.
916 int ast_call(struct ast_channel *chan, char *addr, int timeout);
918 /*! \brief Indicates condition of channel
919 * \note Indicate a condition such as AST_CONTROL_BUSY, AST_CONTROL_RINGING, or AST_CONTROL_CONGESTION on a channel
920 * \param chan channel to change the indication
921 * \param condition which condition to indicate on the channel
922 * \return Returns 0 on success, -1 on failure
924 int ast_indicate(struct ast_channel *chan, int condition);
926 /*! \brief Indicates condition of channel, with payload
927 * \note Indicate a condition such as AST_CONTROL_HOLD with payload being music on hold class
928 * \param chan channel to change the indication
929 * \param condition which condition to indicate on the channel
930 * \param data pointer to payload data
931 * \param datalen size of payload data
932 * \return Returns 0 on success, -1 on failure
934 int ast_indicate_data(struct ast_channel *chan, int condition, const void *data, size_t datalen);
936 /* Misc stuff ------------------------------------------------ */
938 /*! \brief Wait for input on a channel
939 * \param chan channel to wait on
940 * \param ms length of time to wait on the channel
941 * Wait for input on a channel for a given # of milliseconds (<0 for indefinite).
942 \return Returns < 0 on failure, 0 if nothing ever arrived, and the # of ms remaining otherwise */
943 int ast_waitfor(struct ast_channel *chan, int ms);
945 /*! \brief Wait for a specified amount of time, looking for hangups
946 * \param chan channel to wait for
947 * \param ms length of time in milliseconds to sleep
948 * Waits for a specified amount of time, servicing the channel as required.
949 * \return returns -1 on hangup, otherwise 0.
951 int ast_safe_sleep(struct ast_channel *chan, int ms);
953 /*! \brief Wait for a specified amount of time, looking for hangups and a condition argument
954 * \param chan channel to wait for
955 * \param ms length of time in milliseconds to sleep
956 * \param cond a function pointer for testing continue condition
957 * \param data argument to be passed to the condition test function
958 * \return returns -1 on hangup, otherwise 0.
959 * Waits for a specified amount of time, servicing the channel as required. If cond
960 * returns 0, this function returns.
962 int ast_safe_sleep_conditional(struct ast_channel *chan, int ms, int (*cond)(void*), void *data );
964 /*! \brief Waits for activity on a group of channels
965 * \param chan an array of pointers to channels
966 * \param n number of channels that are to be waited upon
967 * \param fds an array of fds to wait upon
968 * \param nfds the number of fds to wait upon
969 * \param exception exception flag
970 * \param outfd fd that had activity on it
971 * \param ms how long the wait was
972 * Big momma function here. Wait for activity on any of the n channels, or any of the nfds
974 \return Returns the channel with activity, or NULL on error or if an FD
975 came first. If the FD came first, it will be returned in outfd, otherwise, outfd
977 struct ast_channel *ast_waitfor_nandfds(struct ast_channel **chan, int n,
978 int *fds, int nfds, int *exception, int *outfd, int *ms);
980 /*! \brief Waits for input on a group of channels
981 Wait for input on an array of channels for a given # of milliseconds.
982 \return Return channel with activity, or NULL if none has activity.
983 \param chan an array of pointers to channels
984 \param n number of channels that are to be waited upon
985 \param ms time "ms" is modified in-place, if applicable */
986 struct ast_channel *ast_waitfor_n(struct ast_channel **chan, int n, int *ms);
988 /*! \brief Waits for input on an fd
989 This version works on fd's only. Be careful with it. */
990 int ast_waitfor_n_fd(int *fds, int n, int *ms, int *exception);
993 /*! \brief Reads a frame
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 struct ast_frame *ast_read(struct ast_channel *chan);
1000 /*! \brief Reads a frame, returning AST_FRAME_NULL frame if audio.
1001 \param chan channel to read a frame from
1002 \return Returns a frame, or NULL on error. If it returns NULL, you
1003 best just stop reading frames and assume the channel has been
1005 \note Audio is replaced with AST_FRAME_NULL to avoid
1006 transcode when the resulting audio is not necessary. */
1007 struct ast_frame *ast_read_noaudio(struct ast_channel *chan);
1009 /*! \brief Write a frame to a channel
1010 * This function writes the given frame to the indicated channel.
1011 * \param chan destination channel of the frame
1012 * \param frame frame that will be written
1013 * \return It returns 0 on success, -1 on failure.
1015 int ast_write(struct ast_channel *chan, struct ast_frame *frame);
1017 /*! \brief Write video frame to a channel
1018 * This function writes the given frame to the indicated channel.
1019 * \param chan destination channel of the frame
1020 * \param frame frame that will be written
1021 * \return It returns 1 on success, 0 if not implemented, and -1 on failure.
1023 int ast_write_video(struct ast_channel *chan, struct ast_frame *frame);
1025 /*! \brief Write text frame to a channel
1026 * This function writes the given frame to the indicated channel.
1027 * \param chan destination channel of the frame
1028 * \param frame frame that will be written
1029 * \return It returns 1 on success, 0 if not implemented, and -1 on failure.
1031 int ast_write_text(struct ast_channel *chan, struct ast_frame *frame);
1033 /*! \brief Send empty audio to prime a channel driver */
1034 int ast_prod(struct ast_channel *chan);
1036 /*! \brief Sets read format on channel chan
1037 * Set read format for channel to whichever component of "format" is best.
1038 * \param chan channel to change
1039 * \param format format to change to
1040 * \return Returns 0 on success, -1 on failure
1042 int ast_set_read_format(struct ast_channel *chan, int format);
1044 /*! \brief Sets write format on channel chan
1045 * Set write format for channel to whichever component of "format" is best.
1046 * \param chan channel to change
1047 * \param format new format for writing
1048 * \return Returns 0 on success, -1 on failure
1050 int ast_set_write_format(struct ast_channel *chan, int format);
1053 * \brief Sends text to a channel
1055 * \param chan channel to act upon
1056 * \param text string of text to send on the channel
1058 * Write text to a display on a channel
1060 * \note The channel does not need to be locked before calling this function.
1062 * \retval 0 on success
1063 * \retval -1 on failure
1065 int ast_sendtext(struct ast_channel *chan, const char *text);
1067 /*! \brief Receives a text character from a channel
1068 * \param chan channel to act upon
1069 * \param timeout timeout in milliseconds (0 for infinite wait)
1070 * Read a char of text from a channel
1071 * Returns 0 on success, -1 on failure
1073 int ast_recvchar(struct ast_channel *chan, int timeout);
1075 /*! \brief Send a DTMF digit to a channel
1076 * Send a DTMF digit to a channel.
1077 * \param chan channel to act upon
1078 * \param digit the DTMF digit to send, encoded in ASCII
1079 * \param duration the duration of the digit ending in ms
1080 * \return Returns 0 on success, -1 on failure
1082 int ast_senddigit(struct ast_channel *chan, char digit, unsigned int duration);
1084 /*! \brief Send a DTMF digit to a channel
1085 * Send a DTMF digit to a channel.
1086 * \param chan channel to act upon
1087 * \param digit the DTMF digit to send, encoded in ASCII
1088 * \return Returns 0 on success, -1 on failure
1090 int ast_senddigit_begin(struct ast_channel *chan, char digit);
1092 /*! \brief Send a DTMF digit to a channel
1094 * Send a DTMF digit to a channel.
1095 * \param chan channel to act upon
1096 * \param digit the DTMF digit to send, encoded in ASCII
1097 * \param duration the duration of the digit ending in ms
1098 * \return Returns 0 on success, -1 on failure
1100 int ast_senddigit_end(struct ast_channel *chan, char digit, unsigned int duration);
1102 /*! \brief Receives a text string from a channel
1103 * Read a string of text from a channel
1104 * \param chan channel to act upon
1105 * \param timeout timeout in milliseconds (0 for infinite wait)
1106 * \return the received text, or NULL to signify failure.
1108 char *ast_recvtext(struct ast_channel *chan, int timeout);
1110 /*! \brief Browse channels in use
1111 * Browse the channels currently in use
1112 * \param prev where you want to start in the channel list
1113 * \return Returns the next channel in the list, NULL on end.
1114 * If it returns a channel, that channel *has been locked*!
1116 struct ast_channel *ast_channel_walk_locked(const struct ast_channel *prev);
1118 /*! \brief Get channel by name or uniqueid (locks channel) */
1119 struct ast_channel *ast_get_channel_by_name_locked(const char *chan);
1121 /*! \brief Get channel by name or uniqueid prefix (locks channel) */
1122 struct ast_channel *ast_get_channel_by_name_prefix_locked(const char *name, const int namelen);
1124 /*! \brief Get channel by name or uniqueid prefix (locks channel) */
1125 struct ast_channel *ast_walk_channel_by_name_prefix_locked(const struct ast_channel *chan, const char *name, const int namelen);
1127 /*! \brief Get channel by exten (and optionally context) and lock it */
1128 struct ast_channel *ast_get_channel_by_exten_locked(const char *exten, const char *context);
1130 /*! \brief Get next channel by exten (and optionally context) and lock it */
1131 struct ast_channel *ast_walk_channel_by_exten_locked(const struct ast_channel *chan, const char *exten,
1132 const char *context);
1134 /*! ! \brief Waits for a digit
1135 * \param c channel to wait for a digit on
1136 * \param ms how many milliseconds to wait
1137 * \return Returns <0 on error, 0 on no entry, and the digit on success. */
1138 int ast_waitfordigit(struct ast_channel *c, int ms);
1140 /*! \brief Wait for a digit
1141 Same as ast_waitfordigit() with audio fd for outputting read audio and ctrlfd to monitor for reading.
1142 * \param c channel to wait for a digit on
1143 * \param ms how many milliseconds to wait
1144 * \param audiofd audio file descriptor to write to if audio frames are received
1145 * \param ctrlfd control file descriptor to monitor for reading
1146 * \return Returns 1 if ctrlfd becomes available */
1147 int ast_waitfordigit_full(struct ast_channel *c, int ms, int audiofd, int ctrlfd);
1149 /*! Reads multiple digits
1150 * \param c channel to read from
1151 * \param s string to read in to. Must be at least the size of your length
1152 * \param len how many digits to read (maximum)
1153 * \param timeout how long to timeout between digits
1154 * \param rtimeout timeout to wait on the first digit
1155 * \param enders digits to end the string
1156 * Read in a digit string "s", max length "len", maximum timeout between
1157 digits "timeout" (-1 for none), terminated by anything in "enders". Give them rtimeout
1158 for the first digit. Returns 0 on normal return, or 1 on a timeout. In the case of
1159 a timeout, any digits that were read before the timeout will still be available in s.
1160 RETURNS 2 in full version when ctrlfd is available, NOT 1*/
1161 int ast_readstring(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders);
1162 int ast_readstring_full(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders, int audiofd, int ctrlfd);
1164 /*! \brief Report DTMF on channel 0 */
1165 #define AST_BRIDGE_DTMF_CHANNEL_0 (1 << 0)
1166 /*! \brief Report DTMF on channel 1 */
1167 #define AST_BRIDGE_DTMF_CHANNEL_1 (1 << 1)
1168 /*! \brief Return all voice frames on channel 0 */
1169 #define AST_BRIDGE_REC_CHANNEL_0 (1 << 2)
1170 /*! \brief Return all voice frames on channel 1 */
1171 #define AST_BRIDGE_REC_CHANNEL_1 (1 << 3)
1172 /*! \brief Ignore all signal frames except NULL */
1173 #define AST_BRIDGE_IGNORE_SIGS (1 << 4)
1176 /*! \brief Makes two channel formats compatible
1177 * \param c0 first channel to make compatible
1178 * \param c1 other channel to make compatible
1179 * Set two channels to compatible formats -- call before ast_channel_bridge in general .
1180 * \return Returns 0 on success and -1 if it could not be done */
1181 int ast_channel_make_compatible(struct ast_channel *c0, struct ast_channel *c1);
1183 /*! Bridge two channels together (early)
1184 * \param c0 first channel to bridge
1185 * \param c1 second channel to bridge
1186 * Bridge two channels (c0 and c1) together early. This implies either side may not be answered yet.
1187 * \return Returns 0 on success and -1 if it could not be done */
1188 int ast_channel_early_bridge(struct ast_channel *c0, struct ast_channel *c1);
1190 /*! Bridge two channels together
1191 * \param c0 first channel to bridge
1192 * \param c1 second channel to bridge
1193 * \param config config for the channels
1194 * \param fo destination frame(?)
1195 * \param rc destination channel(?)
1196 * Bridge two channels (c0 and c1) together. If an important frame occurs, we return that frame in
1197 *rf (remember, it could be NULL) and which channel (0 or 1) in rc */
1198 /* int ast_channel_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc); */
1199 int ast_channel_bridge(struct ast_channel *c0,struct ast_channel *c1,
1200 struct ast_bridge_config *config, struct ast_frame **fo, struct ast_channel **rc);
1203 * \brief Weird function made for call transfers
1205 * \param original channel to make a copy of
1206 * \param clone copy of the original channel
1208 * This is a very strange and freaky function used primarily for transfer. Suppose that
1209 * "original" and "clone" are two channels in random situations. This function takes
1210 * the guts out of "clone" and puts them into the "original" channel, then alerts the
1211 * channel driver of the change, asking it to fixup any private information (like the
1212 * p->owner pointer) that is affected by the change. The physical layer of the original
1213 * channel is hung up.
1215 * \note Neither channel passed here needs to be locked before calling this function.
1217 int ast_channel_masquerade(struct ast_channel *original, struct ast_channel *clone);
1219 /*! Gives the string form of a given cause code */
1221 * \param state cause to get the description of
1222 * Give a name to a cause code
1223 * Returns the text form of the binary cause code given
1225 const char *ast_cause2str(int state) attribute_pure;
1227 /*! Convert the string form of a cause code to a number */
1229 * \param name string form of the cause
1230 * Returns the cause code
1232 int ast_str2cause(const char *name) attribute_pure;
1234 /*! Gives the string form of a given channel state */
1236 * \param ast_channel_state state to get the name of
1237 * Give a name to a state
1238 * Returns the text form of the binary state given
1240 const char *ast_state2str(enum ast_channel_state);
1242 /*! Gives the string form of a given transfer capability */
1244 * \param transfercapability transfercapabilty to get the name of
1245 * Give a name to a transfercapbility
1247 * Returns the text form of the binary transfer capability
1249 char *ast_transfercapability2str(int transfercapability) attribute_const;
1251 /* Options: Some low-level drivers may implement "options" allowing fine tuning of the
1252 low level channel. See frame.h for options. Note that many channel drivers may support
1253 none or a subset of those features, and you should not count on this if you want your
1254 asterisk application to be portable. They're mainly useful for tweaking performance */
1256 /*! Sets an option on a channel */
1258 * \param channel channel to set options on
1259 * \param option option to change
1260 * \param data data specific to option
1261 * \param datalen length of the data
1262 * \param block blocking or not
1263 * Set an option on a channel (see frame.h), optionally blocking awaiting the reply
1264 * Returns 0 on success and -1 on failure
1266 int ast_channel_setoption(struct ast_channel *channel, int option, void *data, int datalen, int block);
1268 /*! Pick the best codec */
1269 /* Choose the best codec... Uhhh... Yah. */
1270 int ast_best_codec(int fmts);
1273 /*! Checks the value of an option */
1275 * Query the value of an option, optionally blocking until a reply is received
1276 * Works similarly to setoption except only reads the options.
1278 struct ast_frame *ast_channel_queryoption(struct ast_channel *channel, int option, void *data, int *datalen, int block);
1280 /*! Checks for HTML support on a channel */
1281 /*! Returns 0 if channel does not support HTML or non-zero if it does */
1282 int ast_channel_supports_html(struct ast_channel *channel);
1284 /*! Sends HTML on given channel */
1285 /*! Send HTML or URL on link. Returns 0 on success or -1 on failure */
1286 int ast_channel_sendhtml(struct ast_channel *channel, int subclass, const char *data, int datalen);
1288 /*! Sends a URL on a given link */
1289 /*! Send URL on link. Returns 0 on success or -1 on failure */
1290 int ast_channel_sendurl(struct ast_channel *channel, const char *url);
1293 /*! Defer DTMF so that you only read things like hangups and audio. Returns
1294 non-zero if channel was already DTMF-deferred or 0 if channel is just now
1295 being DTMF-deferred */
1296 int ast_channel_defer_dtmf(struct ast_channel *chan);
1298 /*! Undo defer. ast_read will return any dtmf characters that were queued */
1299 void ast_channel_undefer_dtmf(struct ast_channel *chan);
1301 /*! Initiate system shutdown -- prevents new channels from being allocated.
1302 If "hangup" is non-zero, all existing channels will receive soft
1304 void ast_begin_shutdown(int hangup);
1306 /*! Cancels an existing shutdown and returns to normal operation */
1307 void ast_cancel_shutdown(void);
1309 /*! Returns number of active/allocated channels */
1310 int ast_active_channels(void);
1312 /*! Returns non-zero if Asterisk is being shut down */
1313 int ast_shutting_down(void);
1315 /*! Activate a given generator */
1316 int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen, void *params);
1318 /*! Deactivate an active generator */
1319 void ast_deactivate_generator(struct ast_channel *chan);
1322 * \brief Set caller ID number, name and ANI
1324 * \note The channel does not need to be locked before calling this function.
1326 void ast_set_callerid(struct ast_channel *chan, const char *cid_num, const char *cid_name, const char *cid_ani);
1328 /*! Set the file descriptor on the channel */
1329 void ast_channel_set_fd(struct ast_channel *chan, int which, int fd);
1331 /*! Add a channel to an optimized waitfor */
1332 void ast_poll_channel_add(struct ast_channel *chan0, struct ast_channel *chan1);
1334 /*! Delete a channel from an optimized waitfor */
1335 void ast_poll_channel_del(struct ast_channel *chan0, struct ast_channel *chan1);
1337 /*! Start a tone going */
1338 int ast_tonepair_start(struct ast_channel *chan, int freq1, int freq2, int duration, int vol);
1339 /*! Stop a tone from playing */
1340 void ast_tonepair_stop(struct ast_channel *chan);
1341 /*! Play a tone pair for a given amount of time */
1342 int ast_tonepair(struct ast_channel *chan, int freq1, int freq2, int duration, int vol);
1345 * \brief Automatically service a channel for us...
1348 * \retval -1 failure, or the channel is already being autoserviced
1350 int ast_autoservice_start(struct ast_channel *chan);
1353 * \brief Stop servicing a channel for us...
1356 * \retval -1 error, or the channel has been hungup
1358 int ast_autoservice_stop(struct ast_channel *chan);
1360 /* If built with zaptel optimizations, force a scheduled expiration on the
1361 timer fd, at which point we call the callback function / data */
1362 int ast_settimeout(struct ast_channel *c, int samples, int (*func)(const void *data), void *data);
1364 /*! \brief Transfer a channel (if supported). Returns -1 on error, 0 if not supported
1365 and 1 if supported and requested
1366 \param chan current channel
1367 \param dest destination extension for transfer
1369 int ast_transfer(struct ast_channel *chan, char *dest);
1371 /*! \brief Start masquerading a channel
1372 XXX This is a seriously whacked out operation. We're essentially putting the guts of
1373 the clone channel into the original channel. Start by killing off the original
1374 channel's backend. I'm not sure we're going to keep this function, because
1375 while the features are nice, the cost is very high in terms of pure nastiness. XXX
1376 \param chan Channel to masquerade
1378 int ast_do_masquerade(struct ast_channel *chan);
1380 /*! \brief Find bridged channel
1381 \param chan Current channel
1383 struct ast_channel *ast_bridged_channel(struct ast_channel *chan);
1386 \brief Inherits channel variable from parent to child channel
1387 \param parent Parent channel
1388 \param child Child channel
1390 Scans all channel variables in the parent channel, looking for those
1391 that should be copied into the child channel.
1392 Variables whose names begin with a single '_' are copied into the
1393 child channel with the prefix removed.
1394 Variables whose names begin with '__' are copied into the child
1395 channel with their names unchanged.
1397 void ast_channel_inherit_variables(const struct ast_channel *parent, struct ast_channel *child);
1400 \brief adds a list of channel variables to a channel
1401 \param chan the channel
1402 \param vars a linked list of variables
1404 Variable names can be for a regular channel variable or a dialplan function
1405 that has the ability to be written to.
1407 void ast_set_variables(struct ast_channel *chan, struct ast_variable *vars);
1410 \brief An opaque 'object' structure use by silence generators on channels.
1412 struct ast_silence_generator;
1415 \brief Starts a silence generator on the given channel.
1416 \param chan The channel to generate silence on
1417 \return An ast_silence_generator pointer, or NULL if an error occurs
1419 This function will cause SLINEAR silence to be generated on the supplied
1420 channel until it is disabled; if the channel cannot be put into SLINEAR
1421 mode then the function will fail.
1423 The pointer returned by this function must be preserved and passed to
1424 ast_channel_stop_silence_generator when you wish to stop the silence
1427 struct ast_silence_generator *ast_channel_start_silence_generator(struct ast_channel *chan);
1430 \brief Stops a previously-started silence generator on the given channel.
1431 \param chan The channel to operate on
1432 \param state The ast_silence_generator pointer return by a previous call to
1433 ast_channel_start_silence_generator.
1436 This function will stop the operating silence generator and return the channel
1437 to its previous write format.
1439 void ast_channel_stop_silence_generator(struct ast_channel *chan, struct ast_silence_generator *state);
1442 \brief Check if the channel can run in internal timing mode.
1443 \param chan The channel to check
1446 This function will return 1 if internal timing is enabled and the timing
1447 device is available.
1449 int ast_internal_timing_enabled(struct ast_channel *chan);
1451 /* Misc. functions below */
1453 /*! \brief if fd is a valid descriptor, set *pfd with the descriptor
1454 * \return Return 1 (not -1!) if added, 0 otherwise (so we can add the
1455 * return value to the index into the array)
1457 static inline int ast_add_fd(struct pollfd *pfd, int fd)
1460 pfd->events = POLLIN | POLLPRI;
1464 /*! \brief Helper function for migrating select to poll */
1465 static inline int ast_fdisset(struct pollfd *pfds, int fd, int max, int *start)
1474 for (x = *start; x<max; x++)
1475 if (pfds[x].fd == fd) {
1478 return pfds[x].revents;
1483 #ifndef HAVE_TIMERSUB
1484 static inline void timersub(struct timeval *tvend, struct timeval *tvstart, struct timeval *tvdiff)
1486 tvdiff->tv_sec = tvend->tv_sec - tvstart->tv_sec;
1487 tvdiff->tv_usec = tvend->tv_usec - tvstart->tv_usec;
1488 if (tvdiff->tv_usec < 0) {
1490 tvdiff->tv_usec += 1000000;
1496 /*! \brief Waits for activity on a group of channels
1497 * \param nfds the maximum number of file descriptors in the sets
1498 * \param rfds file descriptors to check for read availability
1499 * \param wfds file descriptors to check for write availability
1500 * \param efds file descriptors to check for exceptions (OOB data)
1501 * \param tvp timeout while waiting for events
1502 * This is the same as a standard select(), except it guarantees the
1503 * behaviour where the passed struct timeval is updated with how much
1504 * time was not slept while waiting for the specified events
1506 static inline int ast_select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tvp)
1509 return select(nfds, rfds, wfds, efds, tvp);
1512 struct timeval tv, tvstart, tvend, tvlen;
1516 gettimeofday(&tvstart, NULL);
1517 res = select(nfds, rfds, wfds, efds, tvp);
1518 gettimeofday(&tvend, NULL);
1519 timersub(&tvend, &tvstart, &tvlen);
1520 timersub(&tv, &tvlen, tvp);
1521 if (tvp->tv_sec < 0 || (tvp->tv_sec == 0 && tvp->tv_usec < 0)) {
1528 return select(nfds, rfds, wfds, efds, NULL);
1533 #define CRASH do { fprintf(stderr, "!! Forcing immediate crash a-la abort !!\n"); *((int *)0) = 0; } while(0)
1535 #define CRASH do { } while(0)
1538 #define CHECK_BLOCKING(c) do { \
1539 if (ast_test_flag(c, AST_FLAG_BLOCKING)) {\
1541 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); \
1544 (c)->blocker = pthread_self(); \
1545 (c)->blockproc = __PRETTY_FUNCTION__; \
1546 ast_set_flag(c, AST_FLAG_BLOCKING); \
1549 ast_group_t ast_get_group(const char *s);
1551 /*! \brief print call- and pickup groups into buffer */
1552 char *ast_print_group(char *buf, int buflen, ast_group_t group);
1554 /*! \brief Convert enum channelreloadreason to text string for manager event
1555 \param reason Enum channelreloadreason - reason for reload (manager, cli, start etc)
1557 const char *channelreloadreason2txt(enum channelreloadreason reason);
1559 /*! \brief return an ast_variable list of channeltypes */
1560 struct ast_variable *ast_channeltype_list(void);
1563 \brief return an english explanation of the code returned thru __ast_request_and_dial's 'outstate' argument
1564 \param reason The integer argument, usually taken from AST_CONTROL_ macros
1565 \return char pointer explaining the code
1567 const char *ast_channel_reason2str(int reason);
1569 /*! \brief channel group info
1571 struct ast_group_info {
1572 struct ast_channel *chan;
1575 AST_LIST_ENTRY(ast_group_info) list;
1579 #if defined(__cplusplus) || defined(c_plusplus)
1583 #endif /* _ASTERISK_CHANNEL_H */