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 #ifndef _ASTERISK_CHANNEL_H
88 #define _ASTERISK_CHANNEL_H
90 #include "asterisk/abstract_jb.h"
94 #include "asterisk/poll-compat.h"
99 #if defined(__cplusplus) || defined(c_plusplus)
103 #define AST_MAX_EXTENSION 80 /*!< Max length of an extension */
104 #define AST_MAX_CONTEXT 80 /*!< Max length of a context */
105 #define AST_CHANNEL_NAME 80 /*!< Max length of an ast_channel name */
106 #define MAX_LANGUAGE 20 /*!< Max length of the language setting */
107 #define MAX_MUSICCLASS 80 /*!< Max length of the music class setting */
109 #include "asterisk/compat.h"
110 #include "asterisk/frame.h"
111 #include "asterisk/sched.h"
112 #include "asterisk/chanvars.h"
113 #include "asterisk/config.h"
114 #include "asterisk/lock.h"
115 #include "asterisk/cdr.h"
116 #include "asterisk/utils.h"
117 #include "asterisk/linkedlists.h"
118 #include "asterisk/stringfields.h"
119 #include "asterisk/compiler.h"
121 #define DATASTORE_INHERIT_FOREVER INT_MAX
123 #define AST_MAX_FDS 8
125 * We have AST_MAX_FDS file descriptors in a channel.
126 * Some of them have a fixed use:
128 #define AST_ALERT_FD (AST_MAX_FDS-1) /*!< used for alertpipe */
129 #define AST_TIMING_FD (AST_MAX_FDS-2) /*!< used for timingfd */
130 #define AST_AGENT_FD (AST_MAX_FDS-3) /*!< used by agents for pass through */
131 #define AST_GENERATOR_FD (AST_MAX_FDS-4) /*!< used by generator */
133 enum ast_bridge_result
{
134 AST_BRIDGE_COMPLETE
= 0,
135 AST_BRIDGE_FAILED
= -1,
136 AST_BRIDGE_FAILED_NOWARN
= -2,
137 AST_BRIDGE_RETRY
= -3,
140 typedef unsigned long long ast_group_t
;
142 struct ast_generator
{
143 void *(*alloc
)(struct ast_channel
*chan
, void *params
);
144 void (*release
)(struct ast_channel
*chan
, void *data
);
145 /*! This function gets called with the channel unlocked, but is called in
146 * the context of the channel thread so we know the channel is not going
147 * to disappear. This callback is responsible for locking the channel as
149 int (*generate
)(struct ast_channel
*chan
, void *data
, int len
, int samples
);
152 /*! \brief Structure for a data store type */
153 struct ast_datastore_info
{
154 const char *type
; /*!< Type of data store */
155 void *(*duplicate
)(void *data
); /*!< Duplicate item data (used for inheritance) */
156 void (*destroy
)(void *data
); /*!< Destroy function */
158 * \brief Fix up channel references
160 * \arg data The datastore data
161 * \arg old_chan The old channel owning the datastore
162 * \arg new_chan The new channel owning the datastore
164 * This is exactly like the fixup callback of the channel technology interface.
165 * It allows a datastore to fix any pointers it saved to the owning channel
166 * in case that the owning channel has changed. Generally, this would happen
167 * when the datastore is set to be inherited, and a masquerade occurs.
171 void (*chan_fixup
)(void *data
, struct ast_channel
*old_chan
, struct ast_channel
*new_chan
);
174 /*! \brief Structure for a channel data store */
175 struct ast_datastore
{
176 char *uid
; /*!< Unique data store identifier */
177 void *data
; /*!< Contained data */
178 const struct ast_datastore_info
*info
; /*!< Data store type information */
179 unsigned int inheritance
; /*!Number of levels this item will continue to be inherited */
180 AST_LIST_ENTRY(ast_datastore
) entry
; /*!< Used for easy linking */
183 /*! \brief Structure for all kinds of caller ID identifications.
184 * \note All string fields here are malloc'ed, so they need to be
185 * freed when the structure is deleted.
186 * Also, NULL and "" must be considered equivalent.
188 struct ast_callerid
{
189 char *cid_dnid
; /*!< Malloc'd Dialed Number Identifier */
190 char *cid_num
; /*!< Malloc'd Caller Number */
191 char *cid_name
; /*!< Malloc'd Caller Name */
192 char *cid_ani
; /*!< Malloc'd ANI */
193 char *cid_rdnis
; /*!< Malloc'd RDNIS */
194 int cid_pres
; /*!< Callerid presentation/screening */
195 int cid_ani2
; /*!< Callerid ANI 2 (Info digits) */
196 int cid_ton
; /*!< Callerid Type of Number */
197 int cid_tns
; /*!< Callerid Transit Network Select */
201 Structure to describe a channel "technology", ie a channel driver
203 \arg chan_iax2.c - The Inter-Asterisk exchange protocol
204 \arg chan_sip.c - The SIP channel driver
205 \arg chan_zap.c - PSTN connectivity (TDM, PRI, T1/E1, FXO, FXS)
207 If you develop your own channel driver, this is where you
208 tell the PBX at registration of your driver what properties
209 this driver supports and where different callbacks are
212 struct ast_channel_tech
{
213 const char * const type
;
214 const char * const description
;
216 int capabilities
; /*!< Bitmap of formats this channel can handle */
218 int properties
; /*!< Technology Properties */
220 /*! \brief Requester - to set up call data structures (pvt's) */
221 struct ast_channel
*(* const requester
)(const char *type
, int format
, void *data
, int *cause
);
223 int (* const devicestate
)(void *data
); /*!< Devicestate call back */
225 /*! \brief Start sending a literal DTMF digit */
226 int (* const send_digit_begin
)(struct ast_channel
*chan
, char digit
);
228 /*! \brief Stop sending a literal DTMF digit */
229 int (* const send_digit_end
)(struct ast_channel
*chan
, char digit
, unsigned int duration
);
231 /*! \brief Call a given phone number (address, etc), but don't
232 take longer than timeout seconds to do so. */
233 int (* const call
)(struct ast_channel
*chan
, char *addr
, int timeout
);
235 /*! \brief Hangup (and possibly destroy) the channel */
236 int (* const hangup
)(struct ast_channel
*chan
);
238 /*! \brief Answer the channel */
239 int (* const answer
)(struct ast_channel
*chan
);
241 /*! \brief Read a frame, in standard format (see frame.h) */
242 struct ast_frame
* (* const read
)(struct ast_channel
*chan
);
244 /*! \brief Write a frame, in standard format (see frame.h) */
245 int (* const write
)(struct ast_channel
*chan
, struct ast_frame
*frame
);
247 /*! \brief Display or transmit text */
248 int (* const send_text
)(struct ast_channel
*chan
, const char *text
);
250 /*! \brief send a message */
251 int (* const send_message
)(struct ast_channel
*chan
, const char *dest
, const char *text
, int ispdu
);
253 /*! \brief Display or send an image */
254 int (* const send_image
)(struct ast_channel
*chan
, struct ast_frame
*frame
);
256 /*! \brief Send HTML data */
257 int (* const send_html
)(struct ast_channel
*chan
, int subclass
, const char *data
, int len
);
259 /*! \brief Handle an exception, reading a frame */
260 struct ast_frame
* (* const exception
)(struct ast_channel
*chan
);
262 /*! \brief Bridge two channels of the same type together */
263 enum ast_bridge_result (* const bridge
)(struct ast_channel
*c0
, struct ast_channel
*c1
, int flags
,
264 struct ast_frame
**fo
, struct ast_channel
**rc
, int timeoutms
);
266 /*! \brief Indicate a particular condition (e.g. AST_CONTROL_BUSY or AST_CONTROL_RINGING or AST_CONTROL_CONGESTION */
267 int (* const indicate
)(struct ast_channel
*c
, int condition
, const void *data
, size_t datalen
);
269 /*! \brief Fix up a channel: If a channel is consumed, this is called. Basically update any ->owner links */
270 int (* const fixup
)(struct ast_channel
*oldchan
, struct ast_channel
*newchan
);
272 /*! \brief Set a given option */
273 int (* const setoption
)(struct ast_channel
*chan
, int option
, void *data
, int datalen
);
275 /*! \brief Query a given option */
276 int (* const queryoption
)(struct ast_channel
*chan
, int option
, void *data
, int *datalen
);
278 /*! \brief Blind transfer other side (see app_transfer.c and ast_transfer() */
279 int (* const transfer
)(struct ast_channel
*chan
, const char *newdest
);
281 /*! \brief Write a frame, in standard format */
282 int (* const write_video
)(struct ast_channel
*chan
, struct ast_frame
*frame
);
284 /*! \brief Find bridged channel */
285 struct ast_channel
*(* const bridged_channel
)(struct ast_channel
*chan
, struct ast_channel
*bridge
);
287 /*! \brief Provide additional read items for CHANNEL() dialplan function */
288 int (* func_channel_read
)(struct ast_channel
*chan
, char *function
, char *data
, char *buf
, size_t len
);
290 /*! \brief Provide additional write items for CHANNEL() dialplan function */
291 int (* func_channel_write
)(struct ast_channel
*chan
, char *function
, char *data
, const char *value
);
293 /*! \brief Retrieve base channel (agent and local) */
294 struct ast_channel
* (* get_base_channel
)(struct ast_channel
*chan
);
296 /*! \brief Set base channel (agent and local) */
297 int (* set_base_channel
)(struct ast_channel
*chan
, struct ast_channel
*base
);
300 #define DEBUGCHAN_FLAG 0x80000000
301 #define FRAMECOUNT_INC(x) ( ((x) & DEBUGCHAN_FLAG) | (((x)+1) & ~DEBUGCHAN_FLAG) )
303 enum ast_channel_adsicpe
{
306 AST_ADSI_UNAVAILABLE
,
307 AST_ADSI_OFFHOOKONLY
,
311 * \brief ast_channel states
313 * \note Bits 0-15 of state are reserved for the state (up/down) of the line
314 * Bits 16-32 of state are reserved for flags
316 enum ast_channel_state
{
317 /*! Channel is down and available */
319 /*! Channel is down, but reserved */
321 /*! Channel is off hook */
323 /*! Digits (or equivalent) have been dialed */
325 /*! Line is ringing */
327 /*! Remote end is ringing */
333 /*! Digits (or equivalent) have been dialed while offhook */
334 AST_STATE_DIALING_OFFHOOK
,
335 /*! Channel has detected an incoming call and is waiting for ring */
338 /*! Do not transmit voice data */
339 AST_STATE_MUTE
= (1 << 16),
342 /*! \brief Main Channel structure associated with a channel.
343 * This is the side of it mostly used by the pbx and call management.
345 * \note XXX It is important to remember to increment .cleancount each time
346 * this structure is changed. XXX
349 /*! \brief Technology (point to channel driver) */
350 const struct ast_channel_tech
*tech
;
352 /*! \brief Private data used by the technology driver */
355 AST_DECLARE_STRING_FIELDS(
356 AST_STRING_FIELD(name
); /*!< ASCII unique channel name */
357 AST_STRING_FIELD(language
); /*!< Language requested for voice prompts */
358 AST_STRING_FIELD(musicclass
); /*!< Default music class */
359 AST_STRING_FIELD(accountcode
); /*!< Account code for billing */
360 AST_STRING_FIELD(call_forward
); /*!< Where to forward to if asked to dial on this interface */
361 AST_STRING_FIELD(uniqueid
); /*!< Unique Channel Identifier */
364 /*! \brief File descriptor for channel -- Drivers will poll on these file descriptors, so at least one must be non -1. */
365 int fds
[AST_MAX_FDS
];
367 void *music_state
; /*!< Music State*/
368 void *generatordata
; /*!< Current generator data if there is any */
369 struct ast_generator
*generator
; /*!< Current active data generator */
371 /*! \brief Who are we bridged to, if we're bridged. Who is proxying for us,
372 if we are proxied (i.e. chan_agent).
373 Do not access directly, use ast_bridged_channel(chan) */
374 struct ast_channel
*_bridge
;
375 struct ast_channel
*masq
; /*!< Channel that will masquerade as us */
376 struct ast_channel
*masqr
; /*!< Who we are masquerading as */
377 int cdrflags
; /*!< Call Detail Record Flags */
379 /*! \brief Whether or not we have been hung up... Do not set this value
380 directly, use ast_softhangup */
382 time_t whentohangup
; /*!< Non-zero, set to actual time when channel is to be hung up */
383 pthread_t blocker
; /*!< If anyone is blocking, this is them */
384 ast_mutex_t lock
; /*!< Lock, can be used to lock a channel for some operations */
385 const char *blockproc
; /*!< Procedure causing blocking */
387 const char *appl
; /*!< Current application */
388 const char *data
; /*!< Data passed to current application */
389 int fdno
; /*!< Which fd had an event detected on */
390 struct sched_context
*sched
; /*!< Schedule context */
391 int streamid
; /*!< For streaming playback, the schedule ID */
392 struct ast_filestream
*stream
; /*!< Stream itself. */
393 int vstreamid
; /*!< For streaming video playback, the schedule ID */
394 struct ast_filestream
*vstream
; /*!< Video Stream itself. */
395 int oldwriteformat
; /*!< Original writer format */
397 int timingfd
; /*!< Timing fd */
398 int (*timingfunc
)(const void *data
);
401 enum ast_channel_state _state
; /*!< State of line -- Don't write directly, use ast_setstate */
402 int rings
; /*!< Number of rings so far */
403 struct ast_callerid cid
; /*!< Caller ID, name, presentation etc */
404 char dtmfq
[AST_MAX_EXTENSION
]; /*!< Any/all queued DTMF characters */
405 struct ast_frame dtmff
; /*!< DTMF frame */
407 char context
[AST_MAX_CONTEXT
]; /*!< Dialplan: Current extension context */
408 char exten
[AST_MAX_EXTENSION
]; /*!< Dialplan: Current extension number */
409 int priority
; /*!< Dialplan: Current extension priority */
410 char macrocontext
[AST_MAX_CONTEXT
]; /*!< Macro: Current non-macro context. See app_macro.c */
411 char macroexten
[AST_MAX_EXTENSION
]; /*!< Macro: Current non-macro extension. See app_macro.c */
412 int macropriority
; /*!< Macro: Current non-macro priority. See app_macro.c */
413 char dialcontext
[AST_MAX_CONTEXT
]; /*!< Dial: Extension context that we were called from */
414 char lowlayercompat
[16]; /*!< ISDN Low Layer Compatibility */
416 struct ast_pbx
*pbx
; /*!< PBX private structure for this channel */
417 int amaflags
; /*!< Set BEFORE PBX is started to determine AMA flags */
418 struct ast_cdr
*cdr
; /*!< Call Detail Record */
419 enum ast_channel_adsicpe adsicpe
; /*!< Whether or not ADSI is detected on CPE */
421 struct ind_tone_zone
*zone
; /*!< Tone zone as set in indications.conf or
422 in the CHANNEL dialplan function */
424 struct ast_channel_monitor
*monitor
; /*!< Channel monitoring */
426 /*! Track the read/written samples for monitor use */
427 unsigned long insmpl
;
428 unsigned long outsmpl
;
430 /* Frames in/out counters. The high bit is a debug mask, so
431 * the counter is only in the remaining bits
435 int hangupcause
; /*!< Why is the channel hanged up. See causes.h */
436 struct varshead varshead
; /*!< A linked list for channel variables */
437 ast_group_t callgroup
; /*!< Call group for call pickups */
438 ast_group_t pickupgroup
; /*!< Pickup group - which calls groups can be picked up? */
439 unsigned int flags
; /*!< channel flags of AST_FLAG_ type */
440 unsigned short transfercapability
; /*!< ISDN Transfer Capbility - AST_FLAG_DIGITAL is not enough */
441 AST_LIST_HEAD_NOLOCK(, ast_frame
) readq
;
444 int nativeformats
; /*!< Kinds of data this channel can natively handle */
445 int readformat
; /*!< Requested read format */
446 int writeformat
; /*!< Requested write format */
447 struct ast_trans_pvt
*writetrans
; /*!< Write translation path */
448 struct ast_trans_pvt
*readtrans
; /*!< Read translation path */
449 int rawreadformat
; /*!< Raw read format */
450 int rawwriteformat
; /*!< Raw write format */
452 struct ast_audiohook_list
*audiohooks
;
453 void *unused
; /*! This pointer should stay for Asterisk 1.4. It just keeps the struct size the same
454 * for the sake of ABI compatability. */
456 AST_LIST_ENTRY(ast_channel
) chan_list
; /*!< For easy linking */
458 struct ast_jb jb
; /*!< The jitterbuffer state */
460 char emulate_dtmf_digit
; /*!< Digit being emulated */
461 unsigned int emulate_dtmf_duration
; /*!< Number of ms left to emulate DTMF for */
462 struct timeval dtmf_tv
; /*!< The time that an in process digit began, or the last digit ended */
464 int visible_indication
; /*!< Indication currently playing on the channel */
466 /*! \brief Data stores on the channel */
467 AST_LIST_HEAD_NOLOCK(datastores
, ast_datastore
) datastores
;
470 /*! \brief ast_channel_tech Properties */
472 /*! \brief Channels have this property if they can accept input with jitter;
473 * i.e. most VoIP channels */
474 AST_CHAN_TP_WANTSJITTER
= (1 << 0),
475 /*! \brief Channels have this property if they can create jitter;
476 * i.e. most VoIP channels */
477 AST_CHAN_TP_CREATESJITTER
= (1 << 1),
480 /*! \brief ast_channel flags */
482 /*! Queue incoming dtmf, to be released when this flag is turned off */
483 AST_FLAG_DEFER_DTMF
= (1 << 1),
484 /*! write should be interrupt generator */
485 AST_FLAG_WRITE_INT
= (1 << 2),
486 /*! a thread is blocking on this channel */
487 AST_FLAG_BLOCKING
= (1 << 3),
488 /*! This is a zombie channel */
489 AST_FLAG_ZOMBIE
= (1 << 4),
490 /*! There is an exception pending */
491 AST_FLAG_EXCEPTION
= (1 << 5),
492 /*! Listening to moh XXX anthm promises me this will disappear XXX */
493 AST_FLAG_MOH
= (1 << 6),
494 /*! This channel is spying on another channel */
495 AST_FLAG_SPYING
= (1 << 7),
496 /*! This channel is in a native bridge */
497 AST_FLAG_NBRIDGE
= (1 << 8),
498 /*! the channel is in an auto-incrementing dialplan processor,
499 * so when ->priority is set, it will get incremented before
500 * finding the next priority to run */
501 AST_FLAG_IN_AUTOLOOP
= (1 << 9),
502 /*! This is an outgoing call */
503 AST_FLAG_OUTGOING
= (1 << 10),
504 /*! This channel is being whispered on */
505 AST_FLAG_WHISPER
= (1 << 11),
506 /*! A DTMF_BEGIN frame has been read from this channel, but not yet an END */
507 AST_FLAG_IN_DTMF
= (1 << 12),
508 /*! A DTMF_END was received when not IN_DTMF, so the length of the digit is
509 * currently being emulated */
510 AST_FLAG_EMULATE_DTMF
= (1 << 13),
511 /*! This is set to tell the channel not to generate DTMF begin frames, and
512 * to instead only generate END frames. */
513 AST_FLAG_END_DTMF_ONLY
= (1 << 14),
514 /*! This flag indicates that on a masquerade, an active stream should not
516 AST_FLAG_MASQ_NOSTREAM
= (1 << 15),
519 /*! \brief ast_bridge_config flags */
521 AST_FEATURE_PLAY_WARNING
= (1 << 0),
522 AST_FEATURE_REDIRECT
= (1 << 1),
523 AST_FEATURE_DISCONNECT
= (1 << 2),
524 AST_FEATURE_ATXFER
= (1 << 3),
525 AST_FEATURE_AUTOMON
= (1 << 4),
526 AST_FEATURE_PARKCALL
= (1 << 5),
529 struct ast_bridge_config
{
530 struct ast_flags features_caller
;
531 struct ast_flags features_callee
;
532 struct timeval start_time
;
537 const char *warning_sound
;
538 const char *end_sound
;
539 const char *start_sound
;
546 #define LOAD_OH(oh) { \
547 oh.context = context; \
549 oh.priority = priority; \
550 oh.cid_num = cid_num; \
551 oh.cid_name = cid_name; \
552 oh.account = account; \
554 oh.parent_channel = NULL; \
557 struct outgoing_helper
{
562 const char *cid_name
;
564 struct ast_variable
*vars
;
565 struct ast_channel
*parent_channel
;
569 AST_CDR_TRANSFER
= (1 << 0),
570 AST_CDR_FORWARD
= (1 << 1),
571 AST_CDR_CALLWAIT
= (1 << 2),
572 AST_CDR_CONFERENCE
= (1 << 3),
576 /*! Soft hangup by device */
577 AST_SOFTHANGUP_DEV
= (1 << 0),
578 /*! Soft hangup for async goto */
579 AST_SOFTHANGUP_ASYNCGOTO
= (1 << 1),
580 AST_SOFTHANGUP_SHUTDOWN
= (1 << 2),
581 AST_SOFTHANGUP_TIMEOUT
= (1 << 3),
582 AST_SOFTHANGUP_APPUNLOAD
= (1 << 4),
583 AST_SOFTHANGUP_EXPLICIT
= (1 << 5),
584 AST_SOFTHANGUP_UNBRIDGE
= (1 << 6),
588 /*! \brief Channel reload reasons for manager events at load or reload of configuration */
589 enum channelreloadreason
{
591 CHANNEL_MODULE_RELOAD
,
593 CHANNEL_MANAGER_RELOAD
,
596 /*! \brief Create a channel datastore structure */
597 struct ast_datastore
*ast_channel_datastore_alloc(const struct ast_datastore_info
*info
, char *uid
);
599 /*! \brief Free a channel datastore structure */
600 int ast_channel_datastore_free(struct ast_datastore
*datastore
);
602 /*! \brief Inherit datastores from a parent to a child. */
603 int ast_channel_datastore_inherit(struct ast_channel
*from
, struct ast_channel
*to
);
605 /*! \brief Add a datastore to a channel */
606 int ast_channel_datastore_add(struct ast_channel
*chan
, struct ast_datastore
*datastore
);
608 /*! \brief Remove a datastore from a channel */
609 int ast_channel_datastore_remove(struct ast_channel
*chan
, struct ast_datastore
*datastore
);
611 /*! \brief Find a datastore on a channel */
612 struct ast_datastore
*ast_channel_datastore_find(struct ast_channel
*chan
, const struct ast_datastore_info
*info
, char *uid
);
614 /*! \brief Change the state of a channel */
615 int ast_setstate(struct ast_channel
*chan
, enum ast_channel_state
);
617 /*! \brief Create a channel structure
618 \return Returns NULL on failure to allocate.
619 \note New channels are
620 by default set to the "default" context and
623 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
, ...);
625 /*! \brief Queue an outgoing frame */
626 int ast_queue_frame(struct ast_channel
*chan
, struct ast_frame
*f
);
628 /*! \brief Queue a hangup frame */
629 int ast_queue_hangup(struct ast_channel
*chan
);
632 \brief Queue a control frame with payload
633 \param chan channel to queue frame onto
634 \param control type of control frame
635 \return zero on success, non-zero on failure
637 int ast_queue_control(struct ast_channel
*chan
, enum ast_control_frame_type control
);
640 \brief Queue a control frame with payload
641 \param chan channel to queue frame onto
642 \param control type of control frame
643 \param data pointer to payload data to be included in frame
644 \param datalen number of bytes of payload data
645 \return zero on success, non-zero on failure
647 The supplied payload data is copied into the frame, so the caller's copy
648 is not modified nor freed, and the resulting frame will retain a copy of
649 the data even if the caller frees their local copy.
651 \note This method should be treated as a 'network transport'; in other
652 words, your frames may be transferred across an IAX2 channel to another
653 system, which may be a different endianness than yours. Because of this,
654 you should ensure that either your frames will never be expected to work
655 across systems, or that you always put your payload data into 'network byte
656 order' before calling this function.
658 int ast_queue_control_data(struct ast_channel
*chan
, enum ast_control_frame_type control
,
659 const void *data
, size_t datalen
);
661 /*! \brief Change channel name */
662 void ast_change_name(struct ast_channel
*chan
, char *newname
);
664 /*! \brief Free a channel structure */
665 void ast_channel_free(struct ast_channel
*);
667 /*! \brief Requests a channel
668 * \param type type of channel to request
669 * \param format requested channel format (codec)
670 * \param data data to pass to the channel requester
671 * \param status status
672 * Request a channel of a given type, with data as optional information used
673 * by the low level module
674 * \return Returns an ast_channel on success, NULL on failure.
676 struct ast_channel
*ast_request(const char *type
, int format
, void *data
, int *status
);
678 /*! \brief Requests a channel
679 * \param type type of channel to request
680 * \param format requested channel format (codec)
681 * \param data data to pass to the channel requester
682 * \param status status
683 * \param uniqueid uniqueid
684 * Request a channel of a given type, with data as optional information used
685 * by the low level module. Sets the channels uniqueid to 'uniqueid'.
686 * \return Returns an ast_channel on success, NULL on failure.
688 struct ast_channel
*ast_request_uniqueid(const char *type
, int format
, void *data
, int *status
, char *uniqueid
);
691 * \brief Request a channel of a given type, with data as optional information used
692 * by the low level module and attempt to place a call on it
693 * \param type type of channel to request
694 * \param format requested channel format
695 * \param data data to pass to the channel requester
696 * \param timeout maximum amount of time to wait for an answer
697 * \param reason why unsuccessful (if unsuceessful)
698 * \param cidnum Caller-ID Number
699 * \param cidname Caller-ID Name
700 * \return Returns an ast_channel on success or no answer, NULL on failure. Check the value of chan->_state
701 * to know if the call was answered or not.
703 struct ast_channel
*ast_request_and_dial(const char *type
, int format
, void *data
, int timeout
, int *reason
, const char *cidnum
, const char *cidname
);
705 struct ast_channel
*__ast_request_and_dial(const char *type
, int format
, void *data
, int timeout
, int *reason
, const char *cidnum
, const char *cidname
, struct outgoing_helper
*oh
);
707 struct ast_channel
*__ast_request_and_dial_callingpres_uniqueid(const char *type
, int format
, void *data
, int timeout
, int *reason
, int callingpres
, const char *cidnum
, const char *cidname
, struct outgoing_helper
*oh
, char *uniqueid
);
709 /*! \brief "Requests" a channel for sending a message
710 * \param type type of channel to request
711 * \param data data to pass to the channel requester
712 * \param status status
713 * Request a channel of a given type, with data as optional information used
714 * by the low level module
715 * \return Returns 0 on success, -1 on failure.
717 int ast_send_message(const char *type
, void *data
, char *to
, char *from
, char *message
, int ispdu
);
719 /*!\brief Register a channel technology (a new channel driver)
720 * Called by a channel module to register the kind of channels it supports.
721 * \param tech Structure defining channel technology or "type"
722 * \return Returns 0 on success, -1 on failure.
724 int ast_channel_register(const struct ast_channel_tech
*tech
);
726 /*! \brief Unregister a channel technology
727 * \param tech Structure defining channel technology or "type" that was previously registered
728 * \return No return value.
730 void ast_channel_unregister(const struct ast_channel_tech
*tech
);
732 /*! \brief Get a channel technology structure by name
733 * \param name name of technology to find
734 * \return a pointer to the structure, or NULL if no matching technology found
736 const struct ast_channel_tech
*ast_get_channel_tech(const char *name
);
738 /*! \brief Hang up a channel
739 * \note This function performs a hard hangup on a channel. Unlike the soft-hangup, this function
740 * performs all stream stopping, etc, on the channel that needs to end.
741 * chan is no longer valid after this call.
742 * \param chan channel to hang up
743 * \return Returns 0 on success, -1 on failure.
745 int ast_hangup(struct ast_channel
*chan
);
747 /*! \brief Softly hangup up a channel
748 * \param chan channel to be soft-hung-up
749 * Call the protocol layer, but don't destroy the channel structure (use this if you are trying to
750 * safely hangup a channel managed by another thread.
751 * \param cause Ast hangupcause for hangup
752 * \return Returns 0 regardless
754 int ast_softhangup(struct ast_channel
*chan
, int cause
);
756 /*! \brief Softly hangup up a channel (no channel lock)
757 * \param chan channel to be soft-hung-up
758 * \param cause Ast hangupcause for hangup (see cause.h) */
759 int ast_softhangup_nolock(struct ast_channel
*chan
, int cause
);
761 /*! \brief Check to see if a channel is needing hang up
762 * \param chan channel on which to check for hang up
763 * This function determines if the channel is being requested to be hung up.
764 * \return Returns 0 if not, or 1 if hang up is requested (including time-out).
766 int ast_check_hangup(struct ast_channel
*chan
);
768 /*! \brief Compare a offset with the settings of when to hang a channel up
769 * \param chan channel on which to check for hang up
770 * \param offset offset in seconds from current time
771 * \return 1, 0, or -1
772 * This function compares a offset from current time with the absolute time
773 * out on a channel (when to hang up). If the absolute time out on a channel
774 * is earlier than current time plus the offset, it returns 1, if the two
775 * time values are equal, it return 0, otherwise, it retturn -1.
777 int ast_channel_cmpwhentohangup(struct ast_channel
*chan
, time_t offset
);
779 /*! \brief Set when to hang a channel up
780 * \param chan channel on which to check for hang up
781 * \param offset offset in seconds from current time of when to hang up
782 * This function sets the absolute time out on a channel (when to hang up).
784 void ast_channel_setwhentohangup(struct ast_channel
*chan
, time_t offset
);
786 /*! \brief Answer a ringing call
787 * \param chan channel to answer
788 * This function answers a channel and handles all necessary call
790 * \return Returns 0 on success, -1 on failure
792 int ast_answer(struct ast_channel
*chan
);
794 /*! \brief Make a call
795 * \param chan which channel to make the call on
796 * \param addr destination of the call
797 * \param timeout time to wait on for connect
798 * Place a call, take no longer than timeout ms.
799 \return Returns -1 on failure, 0 on not enough time
800 (does not automatically stop ringing), and
801 the number of seconds the connect took otherwise.
803 int ast_call(struct ast_channel
*chan
, char *addr
, int timeout
);
805 /*! \brief Indicates condition of channel
806 * \note Indicate a condition such as AST_CONTROL_BUSY, AST_CONTROL_RINGING, or AST_CONTROL_CONGESTION on a channel
807 * \param chan channel to change the indication
808 * \param condition which condition to indicate on the channel
809 * \return Returns 0 on success, -1 on failure
811 int ast_indicate(struct ast_channel
*chan
, int condition
);
813 /*! \brief Indicates condition of channel, with payload
814 * \note Indicate a condition such as AST_CONTROL_BUSY, AST_CONTROL_RINGING, or AST_CONTROL_CONGESTION on a channel
815 * \param chan channel to change the indication
816 * \param condition which condition to indicate on the channel
817 * \param data pointer to payload data
818 * \param datalen size of payload data
819 * \return Returns 0 on success, -1 on failure
821 int ast_indicate_data(struct ast_channel
*chan
, int condition
, const void *data
, size_t datalen
);
823 /* Misc stuff ------------------------------------------------ */
825 /*! \brief Wait for input on a channel
826 * \param chan channel to wait on
827 * \param ms length of time to wait on the channel
828 * Wait for input on a channel for a given # of milliseconds (<0 for indefinite).
829 \return Returns < 0 on failure, 0 if nothing ever arrived, and the # of ms remaining otherwise */
830 int ast_waitfor(struct ast_channel
*chan
, int ms
);
832 /*! \brief Wait for a specied amount of time, looking for hangups
833 * \param chan channel to wait for
834 * \param ms length of time in milliseconds to sleep
835 * Waits for a specified amount of time, servicing the channel as required.
836 * \return returns -1 on hangup, otherwise 0.
838 int ast_safe_sleep(struct ast_channel
*chan
, int ms
);
840 /*! \brief Wait for a specied amount of time, looking for hangups and a condition argument
841 * \param chan channel to wait for
842 * \param ms length of time in milliseconds to sleep
843 * \param cond a function pointer for testing continue condition
844 * \param data argument to be passed to the condition test function
845 * \return returns -1 on hangup, otherwise 0.
846 * Waits for a specified amount of time, servicing the channel as required. If cond
847 * returns 0, this function returns.
849 int ast_safe_sleep_conditional(struct ast_channel
*chan
, int ms
, int (*cond
)(void*), void *data
);
851 /*! \brief Waits for activity on a group of channels
852 * \param chan an array of pointers to channels
853 * \param n number of channels that are to be waited upon
854 * \param fds an array of fds to wait upon
855 * \param nfds the number of fds to wait upon
856 * \param exception exception flag
857 * \param outfd fd that had activity on it
858 * \param ms how long the wait was
859 * Big momma function here. Wait for activity on any of the n channels, or any of the nfds
861 \return Returns the channel with activity, or NULL on error or if an FD
862 came first. If the FD came first, it will be returned in outfd, otherwise, outfd
864 struct ast_channel
*ast_waitfor_nandfds(struct ast_channel
**chan
, int n
, int *fds
, int nfds
, int *exception
, int *outfd
, int *ms
);
866 /*! \brief Waits for input on a group of channels
867 Wait for input on an array of channels for a given # of milliseconds.
868 \return Return channel with activity, or NULL if none has activity.
869 \param chan an array of pointers to channels
870 \param n number of channels that are to be waited upon
871 \param ms time "ms" is modified in-place, if applicable */
872 struct ast_channel
*ast_waitfor_n(struct ast_channel
**chan
, int n
, int *ms
);
874 /*! \brief Waits for input on an fd
875 This version works on fd's only. Be careful with it. */
876 int ast_waitfor_n_fd(int *fds
, int n
, int *ms
, int *exception
);
879 /*! \brief Reads a frame
880 * \param chan channel to read a frame from
882 \return Returns a frame, or NULL on error. If it returns NULL, you
883 best just stop reading frames and assume the channel has been
885 struct ast_frame
*ast_read(struct ast_channel
*chan
);
887 /*! \brief Reads a frame, returning AST_FRAME_NULL frame if audio.
889 \param chan channel to read a frame from
890 \return Returns a frame, or NULL on error. If it returns NULL, you
891 best just stop reading frames and assume the channel has been
893 \note Audio is replaced with AST_FRAME_NULL to avoid
894 transcode when the resulting audio is not necessary. */
895 struct ast_frame
*ast_read_noaudio(struct ast_channel
*chan
);
897 /*! \brief Write a frame to a channel
898 * This function writes the given frame to the indicated channel.
899 * \param chan destination channel of the frame
900 * \param frame frame that will be written
901 * \return It returns 0 on success, -1 on failure.
903 int ast_write(struct ast_channel
*chan
, struct ast_frame
*frame
);
905 /*! \brief Write video frame to a channel
906 * This function writes the given frame to the indicated channel.
907 * \param chan destination channel of the frame
908 * \param frame frame that will be written
909 * \return It returns 1 on success, 0 if not implemented, and -1 on failure.
911 int ast_write_video(struct ast_channel
*chan
, struct ast_frame
*frame
);
913 /*! \brief Send empty audio to prime a channel driver */
914 int ast_prod(struct ast_channel
*chan
);
916 /*! \brief Sets read format on channel chan
917 * Set read format for channel to whichever component of "format" is best.
918 * \param chan channel to change
919 * \param format format to change to
920 * \return Returns 0 on success, -1 on failure
922 int ast_set_read_format(struct ast_channel
*chan
, int format
);
924 /*! \brief Sets write format on channel chan
925 * Set write format for channel to whichever compoent of "format" is best.
926 * \param chan channel to change
927 * \param format new format for writing
928 * \return Returns 0 on success, -1 on failure
930 int ast_set_write_format(struct ast_channel
*chan
, int format
);
932 /*! \brief Sends text to a channel
933 * Write text to a display on a channel
934 * \param chan channel to act upon
935 * \param text string of text to send on the channel
936 * \return Returns 0 on success, -1 on failure
938 int ast_sendtext(struct ast_channel
*chan
, const char *text
);
940 /*! \brief Sends message to a channel
941 * Write text to a display on a channel
942 * \param chan channel to act upon
943 * \param dest destination number/user
944 * \param text string of text to send on the channel
945 * \param ispdu message is in PDU format
946 * \return Returns 0 on success, -1 on failure
948 int ast_sendmessage(struct ast_channel
*chan
, const char *dest
, const char *text
, int ispdu
);
950 /*! \brief Receives a text character from a channel
951 * \param chan channel to act upon
952 * \param timeout timeout in milliseconds (0 for infinite wait)
953 * Read a char of text from a channel
954 * Returns 0 on success, -1 on failure
956 int ast_recvchar(struct ast_channel
*chan
, int timeout
);
958 /*! \brief Send a DTMF digit to a channel
959 * Send a DTMF digit to a channel.
960 * \param chan channel to act upon
961 * \param digit the DTMF digit to send, encoded in ASCII
962 * \return Returns 0 on success, -1 on failure
964 int ast_senddigit(struct ast_channel
*chan
, char digit
);
966 int ast_senddigit_begin(struct ast_channel
*chan
, char digit
);
967 int ast_senddigit_end(struct ast_channel
*chan
, char digit
, unsigned int duration
);
969 /*! \brief Receives a text string from a channel
970 * Read a string of text from a channel
971 * \param chan channel to act upon
972 * \param timeout timeout in milliseconds (0 for infinite wait)
973 * \return the received text, or NULL to signify failure.
975 char *ast_recvtext(struct ast_channel
*chan
, int timeout
);
977 /*! \brief Browse channels in use
978 * Browse the channels currently in use
979 * \param prev where you want to start in the channel list
980 * \return Returns the next channel in the list, NULL on end.
981 * If it returns a channel, that channel *has been locked*!
983 struct ast_channel
*ast_channel_walk_locked(const struct ast_channel
*prev
);
985 /*! \brief Get channel by name (locks channel) */
986 struct ast_channel
*ast_get_channel_by_name_locked(const char *chan
);
988 /*! \brief Get channel by name prefix (locks channel) */
989 struct ast_channel
*ast_get_channel_by_name_prefix_locked(const char *name
, const int namelen
);
991 /*! \brief Get channel by name prefix (locks channel) */
992 struct ast_channel
*ast_walk_channel_by_name_prefix_locked(const struct ast_channel
*chan
, const char *name
, const int namelen
);
994 /*! \brief Get channel by exten (and optionally context) and lock it */
995 struct ast_channel
*ast_get_channel_by_exten_locked(const char *exten
, const char *context
);
997 /*! \brief Get next channel by exten (and optionally context) and lock it */
998 struct ast_channel
*ast_walk_channel_by_exten_locked(const struct ast_channel
*chan
, const char *exten
,
999 const char *context
);
1001 /*! ! \brief Waits for a digit
1002 * \param c channel to wait for a digit on
1003 * \param ms how many milliseconds to wait
1004 * \return Returns <0 on error, 0 on no entry, and the digit on success. */
1005 int ast_waitfordigit(struct ast_channel
*c
, int ms
);
1007 /*! \brief Wait for a digit
1008 Same as ast_waitfordigit() with audio fd for outputting read audio and ctrlfd to monitor for reading.
1009 * \param c channel to wait for a digit on
1010 * \param ms how many milliseconds to wait
1011 * \param audiofd audio file descriptor to write to if audio frames are received
1012 * \param ctrlfd control file descriptor to monitor for reading
1013 * \return Returns 1 if ctrlfd becomes available */
1014 int ast_waitfordigit_full(struct ast_channel
*c
, int ms
, int audiofd
, int ctrlfd
);
1016 /*! Reads multiple digits
1017 * \param c channel to read from
1018 * \param s string to read in to. Must be at least the size of your length
1019 * \param len how many digits to read (maximum)
1020 * \param timeout how long to timeout between digits
1021 * \param rtimeout timeout to wait on the first digit
1022 * \param enders digits to end the string
1023 * Read in a digit string "s", max length "len", maximum timeout between
1024 digits "timeout" (-1 for none), terminated by anything in "enders". Give them rtimeout
1025 for the first digit. Returns 0 on normal return, or 1 on a timeout. In the case of
1026 a timeout, any digits that were read before the timeout will still be available in s.
1027 RETURNS 2 in full version when ctrlfd is available, NOT 1*/
1028 int ast_readstring(struct ast_channel
*c
, char *s
, int len
, int timeout
, int rtimeout
, char *enders
);
1029 int ast_readstring_full(struct ast_channel
*c
, char *s
, int len
, int timeout
, int rtimeout
, char *enders
, int audiofd
, int ctrlfd
);
1031 /*! \brief Report DTMF on channel 0 */
1032 #define AST_BRIDGE_DTMF_CHANNEL_0 (1 << 0)
1033 /*! \brief Report DTMF on channel 1 */
1034 #define AST_BRIDGE_DTMF_CHANNEL_1 (1 << 1)
1035 /*! \brief Return all voice frames on channel 0 */
1036 #define AST_BRIDGE_REC_CHANNEL_0 (1 << 2)
1037 /*! \brief Return all voice frames on channel 1 */
1038 #define AST_BRIDGE_REC_CHANNEL_1 (1 << 3)
1039 /*! \brief Ignore all signal frames except NULL */
1040 #define AST_BRIDGE_IGNORE_SIGS (1 << 4)
1043 /*! \brief Makes two channel formats compatible
1044 * \param c0 first channel to make compatible
1045 * \param c1 other channel to make compatible
1046 * Set two channels to compatible formats -- call before ast_channel_bridge in general .
1047 * \return Returns 0 on success and -1 if it could not be done */
1048 int ast_channel_make_compatible(struct ast_channel
*c0
, struct ast_channel
*c1
);
1050 /*! Bridge two channels together
1051 * \param c0 first channel to bridge
1052 * \param c1 second channel to bridge
1053 * \param config config for the channels
1054 * \param fo destination frame(?)
1055 * \param rc destination channel(?)
1056 * Bridge two channels (c0 and c1) together. If an important frame occurs, we return that frame in
1057 *rf (remember, it could be NULL) and which channel (0 or 1) in rc */
1058 /* int ast_channel_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc); */
1059 int ast_channel_bridge(struct ast_channel
*c0
,struct ast_channel
*c1
,struct ast_bridge_config
*config
, struct ast_frame
**fo
, struct ast_channel
**rc
);
1061 /*! \brief Weird function made for call transfers
1062 * \param original channel to make a copy of
1063 * \param clone copy of the original channel
1064 * This is a very strange and freaky function used primarily for transfer. Suppose that
1065 "original" and "clone" are two channels in random situations. This function takes
1066 the guts out of "clone" and puts them into the "original" channel, then alerts the
1067 channel driver of the change, asking it to fixup any private information (like the
1068 p->owner pointer) that is affected by the change. The physical layer of the original
1069 channel is hung up. */
1070 int ast_channel_masquerade(struct ast_channel
*original
, struct ast_channel
*clone
);
1072 /*! Gives the string form of a given cause code */
1074 * \param state cause to get the description of
1075 * Give a name to a cause code
1076 * Returns the text form of the binary cause code given
1078 const char *ast_cause2str(int state
) attribute_pure
;
1080 /*! Convert the string form of a cause code to a number */
1082 * \param name string form of the cause
1083 * Returns the cause code
1085 int ast_str2cause(const char *name
) attribute_pure
;
1087 /*! Gives the string form of a given channel state */
1089 * \param ast_channel_state state to get the name of
1090 * Give a name to a state
1091 * Returns the text form of the binary state given
1093 char *ast_state2str(enum ast_channel_state
);
1095 /*! Gives the string form of a given transfer capability */
1097 * \param transfercapability transfercapabilty to get the name of
1098 * Give a name to a transfercapbility
1100 * Returns the text form of the binary transfer capbility
1102 char *ast_transfercapability2str(int transfercapability
) attribute_const
;
1104 /* Options: Some low-level drivers may implement "options" allowing fine tuning of the
1105 low level channel. See frame.h for options. Note that many channel drivers may support
1106 none or a subset of those features, and you should not count on this if you want your
1107 asterisk application to be portable. They're mainly useful for tweaking performance */
1109 /*! Sets an option on a channel */
1111 * \param channel channel to set options on
1112 * \param option option to change
1113 * \param data data specific to option
1114 * \param datalen length of the data
1115 * \param block blocking or not
1116 * Set an option on a channel (see frame.h), optionally blocking awaiting the reply
1117 * Returns 0 on success and -1 on failure
1119 int ast_channel_setoption(struct ast_channel
*channel
, int option
, void *data
, int datalen
, int block
);
1121 /*! Pick the best codec */
1122 /* Choose the best codec... Uhhh... Yah. */
1123 int ast_best_codec(int fmts
);
1126 /*! Checks the value of an option */
1128 * Query the value of an option, optionally blocking until a reply is received
1129 * Works similarly to setoption except only reads the options.
1131 struct ast_frame
*ast_channel_queryoption(struct ast_channel
*channel
, int option
, void *data
, int *datalen
, int block
);
1133 /*! Checks for HTML support on a channel */
1134 /*! Returns 0 if channel does not support HTML or non-zero if it does */
1135 int ast_channel_supports_html(struct ast_channel
*channel
);
1137 /*! Sends HTML on given channel */
1138 /*! Send HTML or URL on link. Returns 0 on success or -1 on failure */
1139 int ast_channel_sendhtml(struct ast_channel
*channel
, int subclass
, const char *data
, int datalen
);
1141 /*! Sends a URL on a given link */
1142 /*! Send URL on link. Returns 0 on success or -1 on failure */
1143 int ast_channel_sendurl(struct ast_channel
*channel
, const char *url
);
1146 /*! Defer DTMF so that you only read things like hangups and audio. Returns
1147 non-zero if channel was already DTMF-deferred or 0 if channel is just now
1148 being DTMF-deferred */
1149 int ast_channel_defer_dtmf(struct ast_channel
*chan
);
1151 /*! Undeos a defer */
1152 /*! Undo defer. ast_read will return any dtmf characters that were queued */
1153 void ast_channel_undefer_dtmf(struct ast_channel
*chan
);
1155 /*! Initiate system shutdown -- prevents new channels from being allocated.
1156 If "hangup" is non-zero, all existing channels will receive soft
1158 void ast_begin_shutdown(int hangup
);
1160 /*! Cancels an existing shutdown and returns to normal operation */
1161 void ast_cancel_shutdown(void);
1163 /*! Returns number of active/allocated channels */
1164 int ast_active_channels(void);
1166 /*! Returns non-zero if Asterisk is being shut down */
1167 int ast_shutting_down(void);
1169 /*! Activate a given generator */
1170 int ast_activate_generator(struct ast_channel
*chan
, struct ast_generator
*gen
, void *params
);
1172 /*! Deactive an active generator */
1173 void ast_deactivate_generator(struct ast_channel
*chan
);
1176 * \note The channel does not need to be locked before calling this function.
1178 void ast_set_callerid(struct ast_channel
*chan
, const char *cidnum
, const char *cidname
, const char *ani
);
1181 /*! return a mallocd string with the result of sprintf of the fmt and following args */
1182 char *ast_safe_string_alloc(const char *fmt
, ...);
1186 /*! Start a tone going */
1187 int ast_tonepair_start(struct ast_channel
*chan
, int freq1
, int freq2
, int duration
, int vol
);
1188 /*! Stop a tone from playing */
1189 void ast_tonepair_stop(struct ast_channel
*chan
);
1190 /*! Play a tone pair for a given amount of time */
1191 int ast_tonepair(struct ast_channel
*chan
, int freq1
, int freq2
, int duration
, int vol
);
1194 * \brief Automatically service a channel for us...
1197 * \retval -1 failure, or the channel is already being autoserviced
1199 int ast_autoservice_start(struct ast_channel
*chan
);
1202 * \brief Stop servicing a channel for us...
1205 * \retval -1 error, or the channel has been hungup
1207 int ast_autoservice_stop(struct ast_channel
*chan
);
1209 /* If built with DAHDI optimizations, force a scheduled expiration on the
1210 timer fd, at which point we call the callback function / data */
1211 int ast_settimeout(struct ast_channel
*c
, int samples
, int (*func
)(const void *data
), void *data
);
1213 /*! \brief Transfer a channel (if supported). Returns -1 on error, 0 if not supported
1214 and 1 if supported and requested
1215 \param chan current channel
1216 \param dest destination extension for transfer
1218 int ast_transfer(struct ast_channel
*chan
, char *dest
);
1220 /*! \brief Start masquerading a channel
1221 XXX This is a seriously wacked out operation. We're essentially putting the guts of
1222 the clone channel into the original channel. Start by killing off the original
1223 channel's backend. I'm not sure we're going to keep this function, because
1224 while the features are nice, the cost is very high in terms of pure nastiness. XXX
1225 \param chan Channel to masquerade
1227 int ast_do_masquerade(struct ast_channel
*chan
);
1229 /*! \brief Find bridged channel
1230 \param chan Current channel
1232 struct ast_channel
*ast_bridged_channel(struct ast_channel
*chan
);
1235 \brief Inherits channel variable from parent to child channel
1236 \param parent Parent channel
1237 \param child Child channel
1239 Scans all channel variables in the parent channel, looking for those
1240 that should be copied into the child channel.
1241 Variables whose names begin with a single '_' are copied into the
1242 child channel with the prefix removed.
1243 Variables whose names begin with '__' are copied into the child
1244 channel with their names unchanged.
1246 void ast_channel_inherit_variables(const struct ast_channel
*parent
, struct ast_channel
*child
);
1249 \brief adds a list of channel variables to a channel
1250 \param chan the channel
1251 \param vars a linked list of variables
1253 Variable names can be for a regular channel variable or a dialplan function
1254 that has the ability to be written to.
1256 void ast_set_variables(struct ast_channel
*chan
, struct ast_variable
*vars
);
1259 \brief An opaque 'object' structure use by silence generators on channels.
1261 struct ast_silence_generator
;
1264 \brief Starts a silence generator on the given channel.
1265 \param chan The channel to generate silence on
1266 \return An ast_silence_generator pointer, or NULL if an error occurs
1268 This function will cause SLINEAR silence to be generated on the supplied
1269 channel until it is disabled; if the channel cannot be put into SLINEAR
1270 mode then the function will fail.
1272 The pointer returned by this function must be preserved and passed to
1273 ast_channel_stop_silence_generator when you wish to stop the silence
1276 struct ast_silence_generator
*ast_channel_start_silence_generator(struct ast_channel
*chan
);
1279 \brief Stops a previously-started silence generator on the given channel.
1280 \param chan The channel to operate on
1281 \param state The ast_silence_generator pointer return by a previous call to
1282 ast_channel_start_silence_generator.
1285 This function will stop the operating silence generator and return the channel
1286 to its previous write format.
1288 void ast_channel_stop_silence_generator(struct ast_channel
*chan
, struct ast_silence_generator
*state
);
1291 \brief Check if the channel can run in internal timing mode.
1292 \param chan The channel to check
1295 This function will return 1 if internal timing is enabled and the timing
1296 device is available.
1298 int ast_internal_timing_enabled(struct ast_channel
*chan
);
1300 /* Misc. functions below */
1302 /*! \brief if fd is a valid descriptor, set *pfd with the descriptor
1303 * \return Return 1 (not -1!) if added, 0 otherwise (so we can add the
1304 * return value to the index into the array)
1306 static inline int ast_add_fd(struct pollfd
*pfd
, int fd
)
1309 pfd
->events
= POLLIN
| POLLPRI
;
1313 /*! \brief Helper function for migrating select to poll */
1314 static inline int ast_fdisset(struct pollfd
*pfds
, int fd
, int max
, int *start
)
1323 for (x
= *start
; x
<max
; x
++)
1324 if (pfds
[x
].fd
== fd
) {
1327 return pfds
[x
].revents
;
1333 static inline void timersub(struct timeval
*tvend
, struct timeval
*tvstart
, struct timeval
*tvdiff
)
1335 tvdiff
->tv_sec
= tvend
->tv_sec
- tvstart
->tv_sec
;
1336 tvdiff
->tv_usec
= tvend
->tv_usec
- tvstart
->tv_usec
;
1337 if (tvdiff
->tv_usec
< 0) {
1339 tvdiff
->tv_usec
+= 1000000;
1345 /*! \brief Waits for activity on a group of channels
1346 * \param nfds the maximum number of file descriptors in the sets
1347 * \param rfds file descriptors to check for read availability
1348 * \param wfds file descriptors to check for write availability
1349 * \param efds file descriptors to check for exceptions (OOB data)
1350 * \param tvp timeout while waiting for events
1351 * This is the same as a standard select(), except it guarantees the
1352 * behaviour where the passed struct timeval is updated with how much
1353 * time was not slept while waiting for the specified events
1355 static inline int ast_select(int nfds
, fd_set
*rfds
, fd_set
*wfds
, fd_set
*efds
, struct timeval
*tvp
)
1358 return select(nfds
, rfds
, wfds
, efds
, tvp
);
1361 struct timeval tv
, tvstart
, tvend
, tvlen
;
1365 gettimeofday(&tvstart
, NULL
);
1366 res
= select(nfds
, rfds
, wfds
, efds
, tvp
);
1367 gettimeofday(&tvend
, NULL
);
1368 timersub(&tvend
, &tvstart
, &tvlen
);
1369 timersub(&tv
, &tvlen
, tvp
);
1370 if (tvp
->tv_sec
< 0 || (tvp
->tv_sec
== 0 && tvp
->tv_usec
< 0)) {
1377 return select(nfds
, rfds
, wfds
, efds
, NULL
);
1381 #define CHECK_BLOCKING(c) do { \
1382 if (ast_test_flag(c, AST_FLAG_BLOCKING)) {\
1384 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); \
1386 (c)->blocker = pthread_self(); \
1387 (c)->blockproc = __PRETTY_FUNCTION__; \
1388 ast_set_flag(c, AST_FLAG_BLOCKING); \
1391 ast_group_t
ast_get_group(const char *s
);
1393 /*! \brief print call- and pickup groups into buffer */
1394 char *ast_print_group(char *buf
, int buflen
, ast_group_t group
);
1396 /*! \brief Convert enum channelreloadreason to text string for manager event
1397 \param reason Enum channelreloadreason - reason for reload (manager, cli, start etc)
1399 const char *channelreloadreason2txt(enum channelreloadreason reason
);
1401 /*! \brief return an ast_variable list of channeltypes */
1402 struct ast_variable
*ast_channeltype_list(void);
1405 \brief Begin 'whispering' onto a channel
1406 \param chan The channel to whisper onto
1407 \return 0 for success, non-zero for failure
1409 This function will add a whisper buffer onto a channel and set a flag
1410 causing writes to the channel to reduce the volume level of the written
1411 audio samples, and then to mix in audio from the whisper buffer if it
1414 Note: This function performs no locking; you must hold the channel's lock before
1415 calling this function.
1417 int ast_channel_whisper_start(struct ast_channel
*chan
);
1420 \brief Feed an audio frame into the whisper buffer on a channel
1421 \param chan The channel to whisper onto
1422 \param f The frame to to whisper onto chan
1423 \return 0 for success, non-zero for failure
1425 int ast_channel_whisper_feed(struct ast_channel
*chan
, struct ast_frame
*f
);
1428 \brief Stop 'whispering' onto a channel
1429 \param chan The channel to whisper onto
1430 \return 0 for success, non-zero for failure
1432 Note: This function performs no locking; you must hold the channel's lock before
1433 calling this function.
1435 void ast_channel_whisper_stop(struct ast_channel
*chan
);
1440 \brief return an english explanation of the code returned thru __ast_request_and_dial's 'outstate' argument
1441 \param reason The integer argument, usually taken from AST_CONTROL_ macros
1442 \return char pointer explaining the code
1444 char *ast_channel_reason2str(int reason
);
1447 #if defined(__cplusplus) || defined(c_plusplus)
1451 #endif /* _ASTERISK_CHANNEL_H */