00001 /* 00002 * Asterisk -- An open source telephony toolkit. 00003 * 00004 * Copyright (C) 1999 - 2006, Digium, Inc. 00005 * 00006 * Mark Spencer <markster@digium.com> 00007 * 00008 * See http://www.asterisk.org for more information about 00009 * the Asterisk project. Please do not directly contact 00010 * any of the maintainers of this project for assistance; 00011 * the project provides a web site, mailing lists and IRC 00012 * channels for your use. 00013 * 00014 * This program is free software, distributed under the terms of 00015 * the GNU General Public License Version 2. See the LICENSE file 00016 * at the top of the source tree. 00017 */ 00018 00019 /*! \file 00020 * \brief General Asterisk PBX channel definitions. 00021 * \par See also: 00022 * \arg \ref Def_Channel 00023 * \arg \ref channel_drivers 00024 */ 00025 00026 /*! \page Def_Channel Asterisk Channels 00027 \par What is a Channel? 00028 A phone call through Asterisk consists of an incoming 00029 connection and an outbound connection. Each call comes 00030 in through a channel driver that supports one technology, 00031 like SIP, ZAP, IAX2 etc. 00032 \par 00033 Each channel driver, technology, has it's own private 00034 channel or dialog structure, that is technology-dependent. 00035 Each private structure is "owned" by a generic Asterisk 00036 channel structure, defined in channel.h and handled by 00037 channel.c . 00038 \par Call scenario 00039 This happens when an incoming call arrives to Asterisk 00040 -# Call arrives on a channel driver interface 00041 -# Channel driver creates a PBX channel and starts a 00042 pbx thread on the channel 00043 -# The dial plan is executed 00044 -# At this point at least two things can happen: 00045 -# The call is answered by Asterisk and 00046 Asterisk plays a media stream or reads media 00047 -# The dial plan forces Asterisk to create an outbound 00048 call somewhere with the dial (see \ref app_dial.c) 00049 application 00050 . 00051 00052 \par Bridging channels 00053 If Asterisk dials out this happens: 00054 -# Dial creates an outbound PBX channel and asks one of the 00055 channel drivers to create a call 00056 -# When the call is answered, Asterisk bridges the media streams 00057 so the caller on the first channel can speak with the callee 00058 on the second, outbound channel 00059 -# In some cases where we have the same technology on both 00060 channels and compatible codecs, a native bridge is used. 00061 In a native bridge, the channel driver handles forwarding 00062 of incoming audio to the outbound stream internally, without 00063 sending audio frames through the PBX. 00064 -# In SIP, theres an "external native bridge" where Asterisk 00065 redirects the endpoint, so audio flows directly between the 00066 caller's phone and the callee's phone. Signalling stays in 00067 Asterisk in order to be able to provide a proper CDR record 00068 for the call. 00069 00070 00071 \par Masquerading channels 00072 In some cases, a channel can masquerade itself into another 00073 channel. This happens frequently in call transfers, where 00074 a new channel takes over a channel that is already involved 00075 in a call. The new channel sneaks in and takes over the bridge 00076 and the old channel, now a zombie, is hung up. 00077 00078 \par Reference 00079 \arg channel.c - generic functions 00080 \arg channel.h - declarations of functions, flags and structures 00081 \arg translate.h - Transcoding support functions 00082 \arg \ref channel_drivers - Implemented channel drivers 00083 \arg \ref Def_Frame Asterisk Multimedia Frames 00084 00085 */ 00086 00087 /*! \page AstFileDesc File descriptors 00088 Asterisk File descriptors are connected to each channel (see \ref Def_Channel) 00089 in the \ref ast_channel structure. 00090 */ 00091 00092 #ifndef _ASTERISK_CHANNEL_H 00093 #define _ASTERISK_CHANNEL_H 00094 00095 #include "asterisk/abstract_jb.h" 00096 00097 #include <unistd.h> 00098 #ifdef POLLCOMPAT 00099 #include "asterisk/poll-compat.h" 00100 #else 00101 #include <sys/poll.h> 00102 #endif 00103 00104 #if defined(__cplusplus) || defined(c_plusplus) 00105 extern "C" { 00106 #endif 00107 00108 #define AST_MAX_EXTENSION 80 /*!< Max length of an extension */ 00109 #define AST_MAX_CONTEXT 80 /*!< Max length of a context */ 00110 #define AST_CHANNEL_NAME 80 /*!< Max length of an ast_channel name */ 00111 #define MAX_LANGUAGE 20 /*!< Max length of the language setting */ 00112 #define MAX_MUSICCLASS 80 /*!< Max length of the music class setting */ 00113 00114 #include "asterisk/compat.h" 00115 #include "asterisk/frame.h" 00116 #include "asterisk/sched.h" 00117 #include "asterisk/chanvars.h" 00118 #include "asterisk/config.h" 00119 #include "asterisk/lock.h" 00120 #include "asterisk/cdr.h" 00121 #include "asterisk/utils.h" 00122 #include "asterisk/linkedlists.h" 00123 #include "asterisk/stringfields.h" 00124 #include "asterisk/options.h" 00125 #include "asterisk/strings.h" 00126 #include "asterisk/compiler.h" 00127 00128 #define DATASTORE_INHERIT_FOREVER INT_MAX 00129 00130 #define AST_MAX_FDS 8 00131 /* 00132 * We have AST_MAX_FDS file descriptors in a channel. 00133 * Some of them have a fixed use: 00134 */ 00135 #define AST_ALERT_FD (AST_MAX_FDS-1) /*!< used for alertpipe */ 00136 #define AST_TIMING_FD (AST_MAX_FDS-2) /*!< used for timingfd */ 00137 #define AST_AGENT_FD (AST_MAX_FDS-3) /*!< used by agents for pass through */ 00138 #define AST_GENERATOR_FD (AST_MAX_FDS-4) /*!< used by generator */ 00139 00140 enum ast_bridge_result { 00141 AST_BRIDGE_COMPLETE = 0, 00142 AST_BRIDGE_FAILED = -1, 00143 AST_BRIDGE_FAILED_NOWARN = -2, 00144 AST_BRIDGE_RETRY = -3, 00145 }; 00146 00147 typedef unsigned long long ast_group_t; 00148 00149 /*! \todo Add an explanation of an Asterisk generator 00150 */ 00151 struct ast_generator { 00152 void *(*alloc)(struct ast_channel *chan, void *params); 00153 void (*release)(struct ast_channel *chan, void *data); 00154 /*! This function gets called with the channel unlocked, but is called in 00155 * the context of the channel thread so we know the channel is not going 00156 * to disappear. This callback is responsible for locking the channel as 00157 * necessary. */ 00158 int (*generate)(struct ast_channel *chan, void *data, int len, int samples); 00159 }; 00160 00161 /*! \brief Structure for a data store type */ 00162 struct ast_datastore_info { 00163 const char *type; /*!< Type of data store */ 00164 void *(*duplicate)(void *data); /*!< Duplicate item data (used for inheritance) */ 00165 void (*destroy)(void *data); /*!< Destroy function */ 00166 /*! 00167 * \brief Fix up channel references 00168 * 00169 * \arg data The datastore data 00170 * \arg old_chan The old channel owning the datastore 00171 * \arg new_chan The new channel owning the datastore 00172 * 00173 * This is exactly like the fixup callback of the channel technology interface. 00174 * It allows a datastore to fix any pointers it saved to the owning channel 00175 * in case that the owning channel has changed. Generally, this would happen 00176 * when the datastore is set to be inherited, and a masquerade occurs. 00177 * 00178 * \return nothing. 00179 */ 00180 void (*chan_fixup)(void *data, struct ast_channel *old_chan, struct ast_channel *new_chan); 00181 }; 00182 00183 /*! \brief Structure for a channel data store */ 00184 struct ast_datastore { 00185 char *uid; /*!< Unique data store identifier */ 00186 void *data; /*!< Contained data */ 00187 const struct ast_datastore_info *info; /*!< Data store type information */ 00188 unsigned int inheritance; /*!Number of levels this item will continue to be inherited */ 00189 AST_LIST_ENTRY(ast_datastore) entry; /*!< Used for easy linking */ 00190 }; 00191 00192 /*! \brief Structure for all kinds of caller ID identifications. 00193 * \note All string fields here are malloc'ed, so they need to be 00194 * freed when the structure is deleted. 00195 * Also, NULL and "" must be considered equivalent. 00196 */ 00197 struct ast_callerid { 00198 char *cid_dnid; /*!< Malloc'd Dialed Number Identifier */ 00199 char *cid_num; /*!< Malloc'd Caller Number */ 00200 char *cid_name; /*!< Malloc'd Caller Name */ 00201 char *cid_ani; /*!< Malloc'd ANI */ 00202 char *cid_rdnis; /*!< Malloc'd RDNIS */ 00203 int cid_pres; /*!< Callerid presentation/screening */ 00204 int cid_ani2; /*!< Callerid ANI 2 (Info digits) */ 00205 int cid_ton; /*!< Callerid Type of Number */ 00206 int cid_tns; /*!< Callerid Transit Network Select */ 00207 }; 00208 00209 /*! \brief 00210 Structure to describe a channel "technology", ie a channel driver 00211 See for examples: 00212 \arg chan_iax2.c - The Inter-Asterisk exchange protocol 00213 \arg chan_sip.c - The SIP channel driver 00214 \arg chan_zap.c - PSTN connectivity (TDM, PRI, T1/E1, FXO, FXS) 00215 00216 If you develop your own channel driver, this is where you 00217 tell the PBX at registration of your driver what properties 00218 this driver supports and where different callbacks are 00219 implemented. 00220 */ 00221 struct ast_channel_tech { 00222 const char * const type; 00223 const char * const description; 00224 00225 int capabilities; /*!< Bitmap of formats this channel can handle */ 00226 00227 int properties; /*!< Technology Properties */ 00228 00229 /*! \brief Requester - to set up call data structures (pvt's) */ 00230 struct ast_channel *(* const requester)(const char *type, int format, void *data, int *cause); 00231 00232 int (* const devicestate)(void *data); /*!< Devicestate call back */ 00233 00234 /*! \brief Start sending a literal DTMF digit */ 00235 int (* const send_digit_begin)(struct ast_channel *chan, char digit); 00236 00237 /*! \brief Stop sending a literal DTMF digit */ 00238 int (* const send_digit_end)(struct ast_channel *chan, char digit, unsigned int duration); 00239 00240 /*! \brief Call a given phone number (address, etc), but don't 00241 take longer than timeout seconds to do so. */ 00242 int (* const call)(struct ast_channel *chan, char *addr, int timeout); 00243 00244 /*! \brief Hangup (and possibly destroy) the channel */ 00245 int (* const hangup)(struct ast_channel *chan); 00246 00247 /*! \brief Answer the channel */ 00248 int (* const answer)(struct ast_channel *chan); 00249 00250 /*! \brief Read a frame, in standard format (see frame.h) */ 00251 struct ast_frame * (* const read)(struct ast_channel *chan); 00252 00253 /*! \brief Write a frame, in standard format (see frame.h) */ 00254 int (* const write)(struct ast_channel *chan, struct ast_frame *frame); 00255 00256 /*! \brief Display or transmit text */ 00257 int (* const send_text)(struct ast_channel *chan, const char *text); 00258 00259 /*! \brief Display or send an image */ 00260 int (* const send_image)(struct ast_channel *chan, struct ast_frame *frame); 00261 00262 /*! \brief Send HTML data */ 00263 int (* const send_html)(struct ast_channel *chan, int subclass, const char *data, int len); 00264 00265 /*! \brief Handle an exception, reading a frame */ 00266 struct ast_frame * (* const exception)(struct ast_channel *chan); 00267 00268 /*! \brief Bridge two channels of the same type together */ 00269 enum ast_bridge_result (* const bridge)(struct ast_channel *c0, struct ast_channel *c1, int flags, 00270 struct ast_frame **fo, struct ast_channel **rc, int timeoutms); 00271 00272 /*! \brief Indicate a particular condition (e.g. AST_CONTROL_BUSY or AST_CONTROL_RINGING or AST_CONTROL_CONGESTION */ 00273 int (* const indicate)(struct ast_channel *c, int condition, const void *data, size_t datalen); 00274 00275 /*! \brief Fix up a channel: If a channel is consumed, this is called. Basically update any ->owner links */ 00276 int (* const fixup)(struct ast_channel *oldchan, struct ast_channel *newchan); 00277 00278 /*! \brief Set a given option */ 00279 int (* const setoption)(struct ast_channel *chan, int option, void *data, int datalen); 00280 00281 /*! \brief Query a given option */ 00282 int (* const queryoption)(struct ast_channel *chan, int option, void *data, int *datalen); 00283 00284 /*! \brief Blind transfer other side (see app_transfer.c and ast_transfer() */ 00285 int (* const transfer)(struct ast_channel *chan, const char *newdest); 00286 00287 /*! \brief Write a frame, in standard format */ 00288 int (* const write_video)(struct ast_channel *chan, struct ast_frame *frame); 00289 00290 /*! \brief Find bridged channel */ 00291 struct ast_channel *(* const bridged_channel)(struct ast_channel *chan, struct ast_channel *bridge); 00292 00293 /*! \brief Provide additional read items for CHANNEL() dialplan function */ 00294 int (* func_channel_read)(struct ast_channel *chan, char *function, char *data, char *buf, size_t len); 00295 00296 /*! \brief Provide additional write items for CHANNEL() dialplan function */ 00297 int (* func_channel_write)(struct ast_channel *chan, char *function, char *data, const char *value); 00298 00299 /*! \brief Retrieve base channel (agent and local) */ 00300 struct ast_channel* (* get_base_channel)(struct ast_channel *chan); 00301 00302 /*! \brief Set base channel (agent and local) */ 00303 int (* set_base_channel)(struct ast_channel *chan, struct ast_channel *base); 00304 }; 00305 00306 #define DEBUGCHAN_FLAG 0x80000000 00307 #define FRAMECOUNT_INC(x) ( ((x) & DEBUGCHAN_FLAG) | (((x)+1) & ~DEBUGCHAN_FLAG) ) 00308 00309 enum ast_channel_adsicpe { 00310 AST_ADSI_UNKNOWN, 00311 AST_ADSI_AVAILABLE, 00312 AST_ADSI_UNAVAILABLE, 00313 AST_ADSI_OFFHOOKONLY, 00314 }; 00315 00316 /*! 00317 * \brief ast_channel states 00318 * 00319 * \note Bits 0-15 of state are reserved for the state (up/down) of the line 00320 * Bits 16-32 of state are reserved for flags 00321 */ 00322 enum ast_channel_state { 00323 /*! Channel is down and available */ 00324 AST_STATE_DOWN, 00325 /*! Channel is down, but reserved */ 00326 AST_STATE_RESERVED, 00327 /*! Channel is off hook */ 00328 AST_STATE_OFFHOOK, 00329 /*! Digits (or equivalent) have been dialed */ 00330 AST_STATE_DIALING, 00331 /*! Line is ringing */ 00332 AST_STATE_RING, 00333 /*! Remote end is ringing */ 00334 AST_STATE_RINGING, 00335 /*! Line is up */ 00336 AST_STATE_UP, 00337 /*! Line is busy */ 00338 AST_STATE_BUSY, 00339 /*! Digits (or equivalent) have been dialed while offhook */ 00340 AST_STATE_DIALING_OFFHOOK, 00341 /*! Channel has detected an incoming call and is waiting for ring */ 00342 AST_STATE_PRERING, 00343 00344 /*! Do not transmit voice data */ 00345 AST_STATE_MUTE = (1 << 16), 00346 }; 00347 00348 /*! \brief Main Channel structure associated with a channel. 00349 * This is the side of it mostly used by the pbx and call management. 00350 * 00351 * \note XXX It is important to remember to increment .cleancount each time 00352 * this structure is changed. XXX 00353 */ 00354 struct ast_channel { 00355 /*! \brief Technology (point to channel driver) */ 00356 const struct ast_channel_tech *tech; 00357 00358 /*! \brief Private data used by the technology driver */ 00359 void *tech_pvt; 00360 00361 AST_DECLARE_STRING_FIELDS( 00362 AST_STRING_FIELD(name); /*!< ASCII unique channel name */ 00363 AST_STRING_FIELD(language); /*!< Language requested for voice prompts */ 00364 AST_STRING_FIELD(musicclass); /*!< Default music class */ 00365 AST_STRING_FIELD(accountcode); /*!< Account code for billing */ 00366 AST_STRING_FIELD(call_forward); /*!< Where to forward to if asked to dial on this interface */ 00367 AST_STRING_FIELD(uniqueid); /*!< Unique Channel Identifier */ 00368 ); 00369 00370 /*! \brief File descriptor for channel -- Drivers will poll on these file descriptors, so at least one must be non -1. See \ref AstFileDesc */ 00371 int fds[AST_MAX_FDS]; 00372 00373 void *music_state; /*!< Music State*/ 00374 void *generatordata; /*!< Current generator data if there is any */ 00375 struct ast_generator *generator; /*!< Current active data generator */ 00376 00377 /*! \brief Who are we bridged to, if we're bridged. Who is proxying for us, 00378 if we are proxied (i.e. chan_agent). 00379 Do not access directly, use ast_bridged_channel(chan) */ 00380 struct ast_channel *_bridge; 00381 struct ast_channel *masq; /*!< Channel that will masquerade as us */ 00382 struct ast_channel *masqr; /*!< Who we are masquerading as */ 00383 int cdrflags; /*!< Call Detail Record Flags */ 00384 00385 int _softhangup; /*!< Whether or not we have been hung up... Do not set this value 00386 directly, use ast_softhangup() */ 00387 time_t whentohangup; /*!< Non-zero, set to actual time when channel is to be hung up */ 00388 pthread_t blocker; /*!< If anyone is blocking, this is them */ 00389 ast_mutex_t lock; /*!< Lock, can be used to lock a channel for some operations - see ast_channel_lock() */ 00390 const char *blockproc; /*!< Procedure causing blocking */ 00391 00392 const char *appl; /*!< Current application */ 00393 const char *data; /*!< Data passed to current application */ 00394 int fdno; /*!< Which fd had an event detected on */ 00395 struct sched_context *sched; /*!< Schedule context */ 00396 int streamid; /*!< For streaming playback, the schedule ID */ 00397 struct ast_filestream *stream; /*!< Stream itself. */ 00398 int vstreamid; /*!< For streaming video playback, the schedule ID */ 00399 struct ast_filestream *vstream; /*!< Video Stream itself. */ 00400 int oldwriteformat; /*!< Original writer format */ 00401 00402 int timingfd; /*!< Timing fd */ 00403 int (*timingfunc)(const void *data); 00404 void *timingdata; 00405 00406 enum ast_channel_state _state; /*!< State of line -- Don't write directly, use ast_setstate() */ 00407 int rings; /*!< Number of rings so far */ 00408 struct ast_callerid cid; /*!< Caller ID, name, presentation etc */ 00409 char dtmfq[AST_MAX_EXTENSION]; /*!< Any/all queued DTMF characters */ 00410 struct ast_frame dtmff; /*!< DTMF frame */ 00411 00412 char context[AST_MAX_CONTEXT]; /*!< Dialplan: Current extension context */ 00413 char exten[AST_MAX_EXTENSION]; /*!< Dialplan: Current extension number */ 00414 int priority; /*!< Dialplan: Current extension priority */ 00415 char macrocontext[AST_MAX_CONTEXT]; /*!< Macro: Current non-macro context. See app_macro.c */ 00416 char macroexten[AST_MAX_EXTENSION]; /*!< Macro: Current non-macro extension. See app_macro.c */ 00417 int macropriority; /*!< Macro: Current non-macro priority. See app_macro.c */ 00418 char dialcontext[AST_MAX_CONTEXT]; /*!< Dial: Extension context that we were called from */ 00419 00420 struct ast_pbx *pbx; /*!< PBX private structure for this channel */ 00421 int amaflags; /*!< Set BEFORE PBX is started to determine AMA flags */ 00422 struct ast_cdr *cdr; /*!< Call Detail Record */ 00423 enum ast_channel_adsicpe adsicpe; /*!< Whether or not ADSI is detected on CPE */ 00424 00425 struct tone_zone *zone; /*!< Tone zone as set in indications.conf or 00426 in the CHANNEL dialplan function */ 00427 00428 struct ast_channel_monitor *monitor; /*!< Channel monitoring */ 00429 00430 unsigned long insmpl; /*!< Track the read/written samples for monitor use */ 00431 unsigned long outsmpl; /*!< Track the read/written samples for monitor use */ 00432 00433 unsigned int fin; /*!< Frames in counters. The high bit is a debug mask, so 00434 * the counter is only in the remaining bits */ 00435 unsigned int fout; /*!< Frames out counters. The high bit is a debug mask, so 00436 * the counter is only in the remaining bits */ 00437 int hangupcause; /*!< Why is the channel hanged up. See causes.h */ 00438 struct varshead varshead; /*!< A linked list for channel variables 00439 (see \ref AstChanVar ) */ 00440 ast_group_t callgroup; /*!< Call group for call pickups */ 00441 ast_group_t pickupgroup; /*!< Pickup group - which calls groups can be picked up? */ 00442 unsigned int flags; /*!< channel flags of AST_FLAG_ type */ 00443 unsigned short transfercapability; /*!< ISDN Transfer Capbility - AST_FLAG_DIGITAL is not enough */ 00444 AST_LIST_HEAD_NOLOCK(, ast_frame) readq; 00445 int alertpipe[2]; 00446 00447 int nativeformats; /*!< Kinds of data this channel can natively handle */ 00448 int readformat; /*!< Requested read format */ 00449 int writeformat; /*!< Requested write format */ 00450 struct ast_trans_pvt *writetrans; /*!< Write translation path */ 00451 struct ast_trans_pvt *readtrans; /*!< Read translation path */ 00452 int rawreadformat; /*!< Raw read format */ 00453 int rawwriteformat; /*!< Raw write format */ 00454 00455 struct ast_audiohook_list *audiohooks; 00456 void *unused; /*! This pointer should stay for Asterisk 1.4. It just keeps the struct size the same 00457 * for the sake of ABI compatability. */ 00458 00459 AST_LIST_ENTRY(ast_channel) chan_list; /*!< For easy linking */ 00460 00461 struct ast_jb jb; /*!< The jitterbuffer state */ 00462 00463 char emulate_dtmf_digit; /*!< Digit being emulated */ 00464 unsigned int emulate_dtmf_duration; /*!< Number of ms left to emulate DTMF for */ 00465 struct timeval dtmf_tv; /*!< The time that an in process digit began, or the last digit ended */ 00466 00467 int visible_indication; /*!< Indication currently playing on the channel */ 00468 00469 /*! \brief Data stores on the channel */ 00470 AST_LIST_HEAD_NOLOCK(datastores, ast_datastore) datastores; 00471 }; 00472 00473 /*! \brief ast_channel_tech Properties */ 00474 enum { 00475 /*! \brief Channels have this property if they can accept input with jitter; 00476 * i.e. most VoIP channels */ 00477 AST_CHAN_TP_WANTSJITTER = (1 << 0), 00478 /*! \brief Channels have this property if they can create jitter; 00479 * i.e. most VoIP channels */ 00480 AST_CHAN_TP_CREATESJITTER = (1 << 1), 00481 }; 00482 00483 /*! \brief ast_channel flags */ 00484 enum { 00485 /*! Queue incoming dtmf, to be released when this flag is turned off */ 00486 AST_FLAG_DEFER_DTMF = (1 << 1), 00487 /*! write should be interrupt generator */ 00488 AST_FLAG_WRITE_INT = (1 << 2), 00489 /*! a thread is blocking on this channel */ 00490 AST_FLAG_BLOCKING = (1 << 3), 00491 /*! This is a zombie channel */ 00492 AST_FLAG_ZOMBIE = (1 << 4), 00493 /*! There is an exception pending */ 00494 AST_FLAG_EXCEPTION = (1 << 5), 00495 /*! Listening to moh XXX anthm promises me this will disappear XXX */ 00496 AST_FLAG_MOH = (1 << 6), 00497 /*! This channel is spying on another channel */ 00498 AST_FLAG_SPYING = (1 << 7), 00499 /*! This channel is in a native bridge */ 00500 AST_FLAG_NBRIDGE = (1 << 8), 00501 /*! the channel is in an auto-incrementing dialplan processor, 00502 * so when ->priority is set, it will get incremented before 00503 * finding the next priority to run */ 00504 AST_FLAG_IN_AUTOLOOP = (1 << 9), 00505 /*! This is an outgoing call */ 00506 AST_FLAG_OUTGOING = (1 << 10), 00507 /*! This channel is being whispered on */ 00508 AST_FLAG_WHISPER = (1 << 11), 00509 /*! A DTMF_BEGIN frame has been read from this channel, but not yet an END */ 00510 AST_FLAG_IN_DTMF = (1 << 12), 00511 /*! A DTMF_END was received when not IN_DTMF, so the length of the digit is 00512 * currently being emulated */ 00513 AST_FLAG_EMULATE_DTMF = (1 << 13), 00514 /*! This is set to tell the channel not to generate DTMF begin frames, and 00515 * to instead only generate END frames. */ 00516 AST_FLAG_END_DTMF_ONLY = (1 << 14), 00517 /*! This flag indicates that on a masquerade, an active stream should not 00518 * be carried over */ 00519 AST_FLAG_MASQ_NOSTREAM = (1 << 15), 00520 }; 00521 00522 /*! \brief ast_bridge_config flags */ 00523 enum { 00524 AST_FEATURE_PLAY_WARNING = (1 << 0), 00525 AST_FEATURE_REDIRECT = (1 << 1), 00526 AST_FEATURE_DISCONNECT = (1 << 2), 00527 AST_FEATURE_ATXFER = (1 << 3), 00528 AST_FEATURE_AUTOMON = (1 << 4), 00529 AST_FEATURE_PARKCALL = (1 << 5), 00530 }; 00531 00532 /*! \brief bridge configuration */ 00533 struct ast_bridge_config { 00534 struct ast_flags features_caller; 00535 struct ast_flags features_callee; 00536 struct timeval start_time; 00537 long feature_timer; 00538 long timelimit; 00539 long play_warning; 00540 long warning_freq; 00541 const char *warning_sound; 00542 const char *end_sound; 00543 const char *start_sound; 00544 int firstpass; 00545 unsigned int flags; 00546 }; 00547 00548 struct chanmon; 00549 00550 #define LOAD_OH(oh) { \ 00551 oh.context = context; \ 00552 oh.exten = exten; \ 00553 oh.priority = priority; \ 00554 oh.cid_num = cid_num; \ 00555 oh.cid_name = cid_name; \ 00556 oh.account = account; \ 00557 oh.vars = vars; \ 00558 oh.parent_channel = NULL; \ 00559 } 00560 00561 struct outgoing_helper { 00562 const char *context; 00563 const char *exten; 00564 int priority; 00565 const char *cid_num; 00566 const char *cid_name; 00567 const char *account; 00568 struct ast_variable *vars; 00569 struct ast_channel *parent_channel; 00570 }; 00571 00572 enum { 00573 AST_CDR_TRANSFER = (1 << 0), 00574 AST_CDR_FORWARD = (1 << 1), 00575 AST_CDR_CALLWAIT = (1 << 2), 00576 AST_CDR_CONFERENCE = (1 << 3), 00577 }; 00578 00579 enum { 00580 /*! Soft hangup by device */ 00581 AST_SOFTHANGUP_DEV = (1 << 0), 00582 /*! Soft hangup for async goto */ 00583 AST_SOFTHANGUP_ASYNCGOTO = (1 << 1), 00584 AST_SOFTHANGUP_SHUTDOWN = (1 << 2), 00585 AST_SOFTHANGUP_TIMEOUT = (1 << 3), 00586 AST_SOFTHANGUP_APPUNLOAD = (1 << 4), 00587 AST_SOFTHANGUP_EXPLICIT = (1 << 5), 00588 AST_SOFTHANGUP_UNBRIDGE = (1 << 6), 00589 }; 00590 00591 00592 /*! \brief Channel reload reasons for manager events at load or reload of configuration */ 00593 enum channelreloadreason { 00594 CHANNEL_MODULE_LOAD, 00595 CHANNEL_MODULE_RELOAD, 00596 CHANNEL_CLI_RELOAD, 00597 CHANNEL_MANAGER_RELOAD, 00598 }; 00599 00600 /*! \brief Create a channel datastore structure */ 00601 struct ast_datastore *ast_channel_datastore_alloc(const struct ast_datastore_info *info, char *uid); 00602 00603 /*! \brief Free a channel datastore structure */ 00604 int ast_channel_datastore_free(struct ast_datastore *datastore); 00605 00606 /*! \brief Inherit datastores from a parent to a child. */ 00607 int ast_channel_datastore_inherit(struct ast_channel *from, struct ast_channel *to); 00608 00609 /*! \brief Add a datastore to a channel */ 00610 int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore); 00611 00612 /*! \brief Remove a datastore from a channel */ 00613 int ast_channel_datastore_remove(struct ast_channel *chan, struct ast_datastore *datastore); 00614 00615 /*! \brief Find a datastore on a channel */ 00616 struct ast_datastore *ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, char *uid); 00617 00618 /*! \brief Change the state of a channel */ 00619 int ast_setstate(struct ast_channel *chan, enum ast_channel_state); 00620 00621 /*! \brief Create a channel structure 00622 \return Returns NULL on failure to allocate. 00623 \note New channels are 00624 by default set to the "default" context and 00625 extension "s" 00626 */ 00627 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, ...); 00628 00629 /*! \brief Queue an outgoing frame */ 00630 int ast_queue_frame(struct ast_channel *chan, struct ast_frame *f); 00631 00632 /*! \brief Queue a hangup frame */ 00633 int ast_queue_hangup(struct ast_channel *chan); 00634 00635 /*! 00636 \brief Queue a control frame with payload 00637 \param chan channel to queue frame onto 00638 \param control type of control frame 00639 \return zero on success, non-zero on failure 00640 */ 00641 int ast_queue_control(struct ast_channel *chan, enum ast_control_frame_type control); 00642 00643 /*! 00644 \brief Queue a control frame with payload 00645 \param chan channel to queue frame onto 00646 \param control type of control frame 00647 \param data pointer to payload data to be included in frame 00648 \param datalen number of bytes of payload data 00649 \return zero on success, non-zero on failure 00650 00651 The supplied payload data is copied into the frame, so the caller's copy 00652 is not modified nor freed, and the resulting frame will retain a copy of 00653 the data even if the caller frees their local copy. 00654 00655 \note This method should be treated as a 'network transport'; in other 00656 words, your frames may be transferred across an IAX2 channel to another 00657 system, which may be a different endianness than yours. Because of this, 00658 you should ensure that either your frames will never be expected to work 00659 across systems, or that you always put your payload data into 'network byte 00660 order' before calling this function. 00661 */ 00662 int ast_queue_control_data(struct ast_channel *chan, enum ast_control_frame_type control, 00663 const void *data, size_t datalen); 00664 00665 /*! \brief Change channel name */ 00666 void ast_change_name(struct ast_channel *chan, char *newname); 00667 00668 /*! \brief Free a channel structure */ 00669 void ast_channel_free(struct ast_channel *); 00670 00671 /*! \brief Requests a channel 00672 * \param type type of channel to request 00673 * \param format requested channel format (codec) 00674 * \param data data to pass to the channel requester 00675 * \param status status 00676 * Request a channel of a given type, with data as optional information used 00677 * by the low level module 00678 * \return Returns an ast_channel on success, NULL on failure. 00679 */ 00680 struct ast_channel *ast_request(const char *type, int format, void *data, int *status); 00681 00682 00683 /*! \brief call ast_request with format/type of parent channel 00684 */ 00685 static inline struct ast_channel *ast_request_inherit(struct ast_channel *chan, const char *type, void *data, int *status) 00686 { 00687 return ast_request(S_OR(type, chan->tech->type), chan->nativeformats, data, status); 00688 } 00689 00690 /*! 00691 * \brief Request a channel of a given type, with data as optional information used 00692 * by the low level module and attempt to place a call on it 00693 * \param type type of channel to request 00694 * \param format requested channel format 00695 * \param data data to pass to the channel requester 00696 * \param timeout maximum amount of time to wait for an answer 00697 * \param reason why unsuccessful (if unsuceessful) 00698 * \param cidnum Caller-ID Number 00699 * \param cidname Caller-ID Name 00700 * \return Returns an ast_channel on success or no answer, NULL on failure. Check the value of chan->_state 00701 * to know if the call was answered or not. 00702 */ 00703 struct ast_channel *ast_request_and_dial(const char *type, int format, void *data, int timeout, int *reason, const char *cidnum, const char *cidname); 00704 00705 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); 00706 00707 /*!\brief Register a channel technology (a new channel driver) 00708 * Called by a channel module to register the kind of channels it supports. 00709 * \param tech Structure defining channel technology or "type" 00710 * \return Returns 0 on success, -1 on failure. 00711 */ 00712 int ast_channel_register(const struct ast_channel_tech *tech); 00713 00714 /*! \brief Unregister a channel technology 00715 * \param tech Structure defining channel technology or "type" that was previously registered 00716 * \return No return value. 00717 */ 00718 void ast_channel_unregister(const struct ast_channel_tech *tech); 00719 00720 /*! \brief Get a channel technology structure by name 00721 * \param name name of technology to find 00722 * \return a pointer to the structure, or NULL if no matching technology found 00723 */ 00724 const struct ast_channel_tech *ast_get_channel_tech(const char *name); 00725 00726 /*! \brief Hang up a channel 00727 * \note This function performs a hard hangup on a channel. Unlike the soft-hangup, this function 00728 * performs all stream stopping, etc, on the channel that needs to end. 00729 * chan is no longer valid after this call. 00730 * \param chan channel to hang up 00731 * \return Returns 0 on success, -1 on failure. 00732 */ 00733 int ast_hangup(struct ast_channel *chan); 00734 00735 /*! \brief Softly hangup up a channel 00736 * \param chan channel to be soft-hung-up 00737 * Call the protocol layer, but don't destroy the channel structure (use this if you are trying to 00738 * safely hangup a channel managed by another thread. 00739 * \param cause Ast hangupcause for hangup 00740 * \return Returns 0 regardless 00741 */ 00742 int ast_softhangup(struct ast_channel *chan, int cause); 00743 00744 /*! \brief Softly hangup up a channel (no channel lock) 00745 * \param chan channel to be soft-hung-up 00746 * \param cause Ast hangupcause for hangup (see cause.h) */ 00747 int ast_softhangup_nolock(struct ast_channel *chan, int cause); 00748 00749 /*! \brief Check to see if a channel is needing hang up 00750 * \param chan channel on which to check for hang up 00751 * This function determines if the channel is being requested to be hung up. 00752 * \return Returns 0 if not, or 1 if hang up is requested (including time-out). 00753 */ 00754 int ast_check_hangup(struct ast_channel *chan); 00755 00756 /*! \brief Compare a offset with the settings of when to hang a channel up 00757 * \param chan channel on which to check for hang up 00758 * \param offset offset in seconds from current time 00759 * \return 1, 0, or -1 00760 * This function compares a offset from current time with the absolute time 00761 * out on a channel (when to hang up). If the absolute time out on a channel 00762 * is earlier than current time plus the offset, it returns 1, if the two 00763 * time values are equal, it return 0, otherwise, it retturn -1. 00764 */ 00765 int ast_channel_cmpwhentohangup(struct ast_channel *chan, time_t offset); 00766 00767 /*! \brief Set when to hang a channel up 00768 * \param chan channel on which to check for hang up 00769 * \param offset offset in seconds from current time of when to hang up 00770 * This function sets the absolute time out on a channel (when to hang up). 00771 */ 00772 void ast_channel_setwhentohangup(struct ast_channel *chan, time_t offset); 00773 00774 /*! \brief Answer a ringing call 00775 * \param chan channel to answer 00776 * This function answers a channel and handles all necessary call 00777 * setup functions. 00778 * \return Returns 0 on success, -1 on failure 00779 */ 00780 int ast_answer(struct ast_channel *chan); 00781 00782 /*! \brief Make a call 00783 * \param chan which channel to make the call on 00784 * \param addr destination of the call 00785 * \param timeout time to wait on for connect 00786 * Place a call, take no longer than timeout ms. 00787 \return Returns -1 on failure, 0 on not enough time 00788 (does not automatically stop ringing), and 00789 the number of seconds the connect took otherwise. 00790 */ 00791 int ast_call(struct ast_channel *chan, char *addr, int timeout); 00792 00793 /*! \brief Indicates condition of channel 00794 * \note Indicate a condition such as AST_CONTROL_BUSY, AST_CONTROL_RINGING, or AST_CONTROL_CONGESTION on a channel 00795 * \param chan channel to change the indication 00796 * \param condition which condition to indicate on the channel 00797 * \return Returns 0 on success, -1 on failure 00798 */ 00799 int ast_indicate(struct ast_channel *chan, int condition); 00800 00801 /*! \brief Indicates condition of channel, with payload 00802 * \note Indicate a condition such as AST_CONTROL_HOLD with payload being music on hold class 00803 * \param chan channel to change the indication 00804 * \param condition which condition to indicate on the channel 00805 * \param data pointer to payload data 00806 * \param datalen size of payload data 00807 * \return Returns 0 on success, -1 on failure 00808 */ 00809 int ast_indicate_data(struct ast_channel *chan, int condition, const void *data, size_t datalen); 00810 00811 /* Misc stuff ------------------------------------------------ */ 00812 00813 /*! \brief Wait for input on a channel 00814 * \param chan channel to wait on 00815 * \param ms length of time to wait on the channel 00816 * Wait for input on a channel for a given # of milliseconds (<0 for indefinite). 00817 \return Returns < 0 on failure, 0 if nothing ever arrived, and the # of ms remaining otherwise */ 00818 int ast_waitfor(struct ast_channel *chan, int ms); 00819 00820 /*! \brief Wait for a specied amount of time, looking for hangups 00821 * \param chan channel to wait for 00822 * \param ms length of time in milliseconds to sleep 00823 * Waits for a specified amount of time, servicing the channel as required. 00824 * \return returns -1 on hangup, otherwise 0. 00825 */ 00826 int ast_safe_sleep(struct ast_channel *chan, int ms); 00827 00828 /*! \brief Wait for a specied amount of time, looking for hangups and a condition argument 00829 * \param chan channel to wait for 00830 * \param ms length of time in milliseconds to sleep 00831 * \param cond a function pointer for testing continue condition 00832 * \param data argument to be passed to the condition test function 00833 * \return returns -1 on hangup, otherwise 0. 00834 * Waits for a specified amount of time, servicing the channel as required. If cond 00835 * returns 0, this function returns. 00836 */ 00837 int ast_safe_sleep_conditional(struct ast_channel *chan, int ms, int (*cond)(void*), void *data ); 00838 00839 /*! \brief Waits for activity on a group of channels 00840 * \param chan an array of pointers to channels 00841 * \param n number of channels that are to be waited upon 00842 * \param fds an array of fds to wait upon 00843 * \param nfds the number of fds to wait upon 00844 * \param exception exception flag 00845 * \param outfd fd that had activity on it 00846 * \param ms how long the wait was 00847 * Big momma function here. Wait for activity on any of the n channels, or any of the nfds 00848 file descriptors. 00849 \return Returns the channel with activity, or NULL on error or if an FD 00850 came first. If the FD came first, it will be returned in outfd, otherwise, outfd 00851 will be -1 */ 00852 struct ast_channel *ast_waitfor_nandfds(struct ast_channel **chan, int n, int *fds, int nfds, int *exception, int *outfd, int *ms); 00853 00854 /*! \brief Waits for input on a group of channels 00855 Wait for input on an array of channels for a given # of milliseconds. 00856 \return Return channel with activity, or NULL if none has activity. 00857 \param chan an array of pointers to channels 00858 \param n number of channels that are to be waited upon 00859 \param ms time "ms" is modified in-place, if applicable */ 00860 struct ast_channel *ast_waitfor_n(struct ast_channel **chan, int n, int *ms); 00861 00862 /*! \brief Waits for input on an fd 00863 This version works on fd's only. Be careful with it. */ 00864 int ast_waitfor_n_fd(int *fds, int n, int *ms, int *exception); 00865 00866 00867 /*! \brief Reads a frame 00868 * \param chan channel to read a frame from 00869 * \return Returns a frame, or NULL on error. If it returns NULL, you 00870 best just stop reading frames and assume the channel has been 00871 disconnected. */ 00872 struct ast_frame *ast_read(struct ast_channel *chan); 00873 00874 /*! \brief Reads a frame, returning AST_FRAME_NULL frame if audio. 00875 \param chan channel to read a frame from 00876 \return Returns a frame, or NULL on error. If it returns NULL, you 00877 best just stop reading frames and assume the channel has been 00878 disconnected. 00879 \note Audio is replaced with AST_FRAME_NULL to avoid 00880 transcode when the resulting audio is not necessary. */ 00881 struct ast_frame *ast_read_noaudio(struct ast_channel *chan); 00882 00883 /*! \brief Write a frame to a channel 00884 * This function writes the given frame to the indicated channel. 00885 * \param chan destination channel of the frame 00886 * \param frame frame that will be written 00887 * \return It returns 0 on success, -1 on failure. 00888 */ 00889 int ast_write(struct ast_channel *chan, struct ast_frame *frame); 00890 00891 /*! \brief Write video frame to a channel 00892 * This function writes the given frame to the indicated channel. 00893 * \param chan destination channel of the frame 00894 * \param frame frame that will be written 00895 * \return It returns 1 on success, 0 if not implemented, and -1 on failure. 00896 */ 00897 int ast_write_video(struct ast_channel *chan, struct ast_frame *frame); 00898 00899 /*! \brief Send empty audio to prime a channel driver */ 00900 int ast_prod(struct ast_channel *chan); 00901 00902 /*! \brief Sets read format on channel chan 00903 * Set read format for channel to whichever component of "format" is best. 00904 * \param chan channel to change 00905 * \param format format to change to 00906 * \return Returns 0 on success, -1 on failure 00907 */ 00908 int ast_set_read_format(struct ast_channel *chan, int format); 00909 00910 /*! \brief Gets read format from channel chan 00911 * \param chan channel to get info 00912 * Get read format for channel 00913 * Returns read format 00914 */ 00915 static inline int ast_get_read_format(struct ast_channel *chan) 00916 { 00917 return chan->readformat; 00918 } 00919 00920 /*! Gets write format from channel chan */ 00921 /*! 00922 * \param chan channel to get info 00923 * Get write format for channel 00924 * Returns write format 00925 */ 00926 static inline int ast_get_write_format(struct ast_channel *chan) 00927 { 00928 return chan->writeformat; 00929 } 00930 00931 00932 /*! \brief Sets write format on channel chan 00933 * Set write format for channel to whichever compoent of "format" is best. 00934 * \param chan channel to change 00935 * \param format new format for writing 00936 * \return Returns 0 on success, -1 on failure 00937 */ 00938 int ast_set_write_format(struct ast_channel *chan, int format); 00939 00940 /*! \brief Sends text to a channel 00941 * Write text to a display on a channel 00942 * \param chan channel to act upon 00943 * \param text string of text to send on the channel 00944 * \return Returns 0 on success, -1 on failure 00945 */ 00946 int ast_sendtext(struct ast_channel *chan, const char *text); 00947 00948 /*! \brief Receives a text character from a channel 00949 * \param chan channel to act upon 00950 * \param timeout timeout in milliseconds (0 for infinite wait) 00951 * Read a char of text from a channel 00952 * Returns 0 on success, -1 on failure 00953 */ 00954 int ast_recvchar(struct ast_channel *chan, int timeout); 00955 00956 /*! \brief Send a DTMF digit to a channel 00957 * Send a DTMF digit to a channel. 00958 * \param chan channel to act upon 00959 * \param digit the DTMF digit to send, encoded in ASCII 00960 * \return Returns 0 on success, -1 on failure 00961 */ 00962 int ast_senddigit(struct ast_channel *chan, char digit); 00963 00964 /*! \brief Send a DTMF digit to a channel 00965 * Send a DTMF digit to a channel. 00966 * \param chan channel to act upon 00967 * \param digit the DTMF digit to send, encoded in ASCII 00968 * \return Returns 0 on success, -1 on failure 00969 */ 00970 int ast_senddigit_begin(struct ast_channel *chan, char digit); 00971 00972 /*! \brief Send a DTMF digit to a channel 00973 00974 * Send a DTMF digit to a channel. 00975 * \param chan channel to act upon 00976 * \param digit the DTMF digit to send, encoded in ASCII 00977 * \return Returns 0 on success, -1 on failure 00978 */ 00979 int ast_senddigit_end(struct ast_channel *chan, char digit, unsigned int duration); 00980 00981 /*! \brief Receives a text string from a channel 00982 * Read a string of text from a channel 00983 * \param chan channel to act upon 00984 * \param timeout timeout in milliseconds (0 for infinite wait) 00985 * \return the received text, or NULL to signify failure. 00986 */ 00987 char *ast_recvtext(struct ast_channel *chan, int timeout); 00988 00989 /*! \brief Browse channels in use 00990 * Browse the channels currently in use 00991 * \param prev where you want to start in the channel list 00992 * \return Returns the next channel in the list, NULL on end. 00993 * If it returns a channel, that channel *has been locked*! 00994 */ 00995 struct ast_channel *ast_channel_walk_locked(const struct ast_channel *prev); 00996 00997 /*! \brief Get channel by name (locks channel) */ 00998 struct ast_channel *ast_get_channel_by_name_locked(const char *chan); 00999 01000 /*! \brief Get channel by name prefix (locks channel) */ 01001 struct ast_channel *ast_get_channel_by_name_prefix_locked(const char *name, const int namelen); 01002 01003 /*! \brief Get channel by name prefix (locks channel) */ 01004 struct ast_channel *ast_walk_channel_by_name_prefix_locked(const struct ast_channel *chan, const char *name, const int namelen); 01005 01006 /*! \brief Get channel by exten (and optionally context) and lock it */ 01007 struct ast_channel *ast_get_channel_by_exten_locked(const char *exten, const char *context); 01008 01009 /*! \brief Get next channel by exten (and optionally context) and lock it */ 01010 struct ast_channel *ast_walk_channel_by_exten_locked(const struct ast_channel *chan, const char *exten, 01011 const char *context); 01012 01013 /*! ! \brief Waits for a digit 01014 * \param c channel to wait for a digit on 01015 * \param ms how many milliseconds to wait 01016 * \return Returns <0 on error, 0 on no entry, and the digit on success. */ 01017 int ast_waitfordigit(struct ast_channel *c, int ms); 01018 01019 /*! \brief Wait for a digit 01020 Same as ast_waitfordigit() with audio fd for outputting read audio and ctrlfd to monitor for reading. 01021 * \param c channel to wait for a digit on 01022 * \param ms how many milliseconds to wait 01023 * \param audiofd audio file descriptor to write to if audio frames are received 01024 * \param ctrlfd control file descriptor to monitor for reading 01025 * \return Returns 1 if ctrlfd becomes available */ 01026 int ast_waitfordigit_full(struct ast_channel *c, int ms, int audiofd, int ctrlfd); 01027 01028 /*! Reads multiple digits 01029 * \param c channel to read from 01030 * \param s string to read in to. Must be at least the size of your length 01031 * \param len how many digits to read (maximum) 01032 * \param timeout how long to timeout between digits 01033 * \param rtimeout timeout to wait on the first digit 01034 * \param enders digits to end the string 01035 * Read in a digit string "s", max length "len", maximum timeout between 01036 digits "timeout" (-1 for none), terminated by anything in "enders". Give them rtimeout 01037 for the first digit. Returns 0 on normal return, or 1 on a timeout. In the case of 01038 a timeout, any digits that were read before the timeout will still be available in s. 01039 RETURNS 2 in full version when ctrlfd is available, NOT 1*/ 01040 int ast_readstring(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders); 01041 int ast_readstring_full(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders, int audiofd, int ctrlfd); 01042 01043 /*! \brief Report DTMF on channel 0 */ 01044 #define AST_BRIDGE_DTMF_CHANNEL_0 (1 << 0) 01045 /*! \brief Report DTMF on channel 1 */ 01046 #define AST_BRIDGE_DTMF_CHANNEL_1 (1 << 1) 01047 /*! \brief Return all voice frames on channel 0 */ 01048 #define AST_BRIDGE_REC_CHANNEL_0 (1 << 2) 01049 /*! \brief Return all voice frames on channel 1 */ 01050 #define AST_BRIDGE_REC_CHANNEL_1 (1 << 3) 01051 /*! \brief Ignore all signal frames except NULL */ 01052 #define AST_BRIDGE_IGNORE_SIGS (1 << 4) 01053 01054 01055 /*! \brief Makes two channel formats compatible 01056 * \param c0 first channel to make compatible 01057 * \param c1 other channel to make compatible 01058 * Set two channels to compatible formats -- call before ast_channel_bridge in general . 01059 * \return Returns 0 on success and -1 if it could not be done */ 01060 int ast_channel_make_compatible(struct ast_channel *c0, struct ast_channel *c1); 01061 01062 /*! Bridge two channels together 01063 * \param c0 first channel to bridge 01064 * \param c1 second channel to bridge 01065 * \param config config for the channels 01066 * \param fo destination frame(?) 01067 * \param rc destination channel(?) 01068 * Bridge two channels (c0 and c1) together. If an important frame occurs, we return that frame in 01069 *rf (remember, it could be NULL) and which channel (0 or 1) in rc */ 01070 /* int ast_channel_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc); */ 01071 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); 01072 01073 /*! \brief Weird function made for call transfers 01074 * \param original channel to make a copy of 01075 * \param clone copy of the original channel 01076 * This is a very strange and freaky function used primarily for transfer. Suppose that 01077 "original" and "clone" are two channels in random situations. This function takes 01078 the guts out of "clone" and puts them into the "original" channel, then alerts the 01079 channel driver of the change, asking it to fixup any private information (like the 01080 p->owner pointer) that is affected by the change. The physical layer of the original 01081 channel is hung up. */ 01082 int ast_channel_masquerade(struct ast_channel *original, struct ast_channel *clone); 01083 01084 /*! Gives the string form of a given cause code */ 01085 /*! 01086 * \param state cause to get the description of 01087 * Give a name to a cause code 01088 * Returns the text form of the binary cause code given 01089 */ 01090 const char *ast_cause2str(int state) attribute_pure; 01091 01092 /*! Convert the string form of a cause code to a number */ 01093 /*! 01094 * \param name string form of the cause 01095 * Returns the cause code 01096 */ 01097 int ast_str2cause(const char *name) attribute_pure; 01098 01099 /*! Gives the string form of a given channel state */ 01100 /*! 01101 * \param ast_channel_state state to get the name of 01102 * Give a name to a state 01103 * Returns the text form of the binary state given 01104 */ 01105 char *ast_state2str(enum ast_channel_state); 01106 01107 /*! Gives the string form of a given transfer capability */ 01108 /*! 01109 * \param transfercapability transfercapabilty to get the name of 01110 * Give a name to a transfercapbility 01111 * See above 01112 * Returns the text form of the binary transfer capbility 01113 */ 01114 char *ast_transfercapability2str(int transfercapability) attribute_const; 01115 01116 /* Options: Some low-level drivers may implement "options" allowing fine tuning of the 01117 low level channel. See frame.h for options. Note that many channel drivers may support 01118 none or a subset of those features, and you should not count on this if you want your 01119 asterisk application to be portable. They're mainly useful for tweaking performance */ 01120 01121 /*! Sets an option on a channel */ 01122 /*! 01123 * \param channel channel to set options on 01124 * \param option option to change 01125 * \param data data specific to option 01126 * \param datalen length of the data 01127 * \param block blocking or not 01128 * Set an option on a channel (see frame.h), optionally blocking awaiting the reply 01129 * Returns 0 on success and -1 on failure 01130 */ 01131 int ast_channel_setoption(struct ast_channel *channel, int option, void *data, int datalen, int block); 01132 01133 /*! Pick the best codec */ 01134 /* Choose the best codec... Uhhh... Yah. */ 01135 int ast_best_codec(int fmts); 01136 01137 /*! 01138 * \brief Pick the best codec from channel nativeformats 01139 * \param channel channel, from that nativeformats used 01140 */ 01141 static inline int ast_channel_best_codec(struct ast_channel *channel) 01142 { 01143 #ifndef BUG_4825 01144 return ast_best_codec(channel->nativeformats); 01145 #else 01146 return ast_best_codec(channel->nativeformats.audio_bits); 01147 #endif 01148 } 01149 /*! \brief Get the names of a set of formats 01150 * \param buf a buffer for the output string 01151 * \param size size of buf (bytes) 01152 * \param channel the channel 01153 * Prints a list of readable codec names corresponding to "format". 01154 * ex: for format=AST_FORMAT_GSM|AST_FORMAT_SPEEX|AST_FORMAT_ILBC it will return "0x602 (GSM|SPEEX|ILBC)" 01155 * \return The return value is buf. 01156 */ 01157 inline static char * ast_channel_getformatname_multiple(char *buf, size_t size, struct ast_channel *chan) 01158 { 01159 return ast_getformatname_multiple(buf, size, chan->nativeformats); 01160 } 01161 01162 01163 static inline const char * ast_channel_getformatname(struct ast_channel *chan) 01164 { 01165 #ifndef BUG_4825 01166 return chan ? ast_getformatname(chan->nativeformats) : "undefined"; 01167 #else 01168 return chan ? ast_getformatname(chan->nativeformats.audio_bits) : "undefined"; 01169 #endif 01170 } 01171 01172 static inline void ast_channel_formats_reset(struct ast_channel *channel) 01173 { 01174 int r, w; 01175 r = ast_get_read_format(channel); 01176 w = ast_get_write_format(channel); 01177 01178 if (option_debug) 01179 ast_log(LOG_DEBUG, "Resetting read to %d and write to %d on channel %s\n", r, w, channel->name); 01180 if (r) 01181 ast_set_read_format(channel, r); 01182 if (w) 01183 ast_set_write_format(channel, w); 01184 } 01185 01186 /*! 01187 * \brief Set best format, identical to read/write 01188 * \param channel channel, from that nativeformats used and formats set 01189 */ 01190 static inline void ast_set_best_format(struct ast_channel *channel) 01191 { 01192 int format = ast_channel_best_codec(channel); 01193 ast_set_read_format(channel, format); 01194 ast_set_write_format(channel, format); 01195 } 01196 01197 /*! Checks the value of an option */ 01198 /*! 01199 * Query the value of an option, optionally blocking until a reply is received 01200 * Works similarly to setoption except only reads the options. 01201 */ 01202 struct ast_frame *ast_channel_queryoption(struct ast_channel *channel, int option, void *data, int *datalen, int block); 01203 01204 /*! Checks for HTML support on a channel */ 01205 /*! Returns 0 if channel does not support HTML or non-zero if it does */ 01206 int ast_channel_supports_html(struct ast_channel *channel); 01207 01208 /*! Sends HTML on given channel */ 01209 /*! Send HTML or URL on link. Returns 0 on success or -1 on failure */ 01210 int ast_channel_sendhtml(struct ast_channel *channel, int subclass, const char *data, int datalen); 01211 01212 /*! Sends a URL on a given link */ 01213 /*! Send URL on link. Returns 0 on success or -1 on failure */ 01214 int ast_channel_sendurl(struct ast_channel *channel, const char *url); 01215 01216 /*! Defers DTMF */ 01217 /*! Defer DTMF so that you only read things like hangups and audio. Returns 01218 non-zero if channel was already DTMF-deferred or 0 if channel is just now 01219 being DTMF-deferred */ 01220 int ast_channel_defer_dtmf(struct ast_channel *chan); 01221 01222 /*! Undeos a defer */ 01223 /*! Undo defer. ast_read will return any dtmf characters that were queued */ 01224 void ast_channel_undefer_dtmf(struct ast_channel *chan); 01225 01226 /*! Initiate system shutdown -- prevents new channels from being allocated. 01227 If "hangup" is non-zero, all existing channels will receive soft 01228 hangups */ 01229 void ast_begin_shutdown(int hangup); 01230 01231 /*! Cancels an existing shutdown and returns to normal operation */ 01232 void ast_cancel_shutdown(void); 01233 01234 /*! Returns number of active/allocated channels */ 01235 int ast_active_channels(void); 01236 01237 /*! Returns non-zero if Asterisk is being shut down */ 01238 int ast_shutting_down(void); 01239 01240 /*! Activate a given generator */ 01241 int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen, void *params); 01242 01243 /*! Deactive an active generator */ 01244 void ast_deactivate_generator(struct ast_channel *chan); 01245 01246 /*! 01247 * \note The channel does not need to be locked before calling this function. 01248 */ 01249 void ast_set_callerid(struct ast_channel *chan, const char *cidnum, const char *cidname, const char *ani); 01250 01251 01252 /*! return a mallocd string with the result of sprintf of the fmt and following args */ 01253 char *ast_safe_string_alloc(const char *fmt, ...); 01254 01255 01256 01257 /*! Start a tone going */ 01258 int ast_tonepair_start(struct ast_channel *chan, int freq1, int freq2, int duration, int vol); 01259 /*! Stop a tone from playing */ 01260 void ast_tonepair_stop(struct ast_channel *chan); 01261 /*! Play a tone pair for a given amount of time */ 01262 int ast_tonepair(struct ast_channel *chan, int freq1, int freq2, int duration, int vol); 01263 01264 /*! 01265 * \brief Automatically service a channel for us... 01266 * 01267 * \retval 0 success 01268 * \retval -1 failure, or the channel is already being autoserviced 01269 */ 01270 int ast_autoservice_start(struct ast_channel *chan); 01271 01272 /*! 01273 * \brief Stop servicing a channel for us... 01274 * 01275 * \retval 0 success 01276 * \retval -1 error, or the channel has been hungup 01277 */ 01278 int ast_autoservice_stop(struct ast_channel *chan); 01279 01280 /* If built with zaptel optimizations, force a scheduled expiration on the 01281 timer fd, at which point we call the callback function / data */ 01282 int ast_settimeout(struct ast_channel *c, int samples, int (*func)(const void *data), void *data); 01283 01284 /*! \brief Transfer a channel (if supported). Returns -1 on error, 0 if not supported 01285 and 1 if supported and requested 01286 \param chan current channel 01287 \param dest destination extension for transfer 01288 */ 01289 int ast_transfer(struct ast_channel *chan, char *dest); 01290 01291 /*! \brief Start masquerading a channel 01292 XXX This is a seriously wacked out operation. We're essentially putting the guts of 01293 the clone channel into the original channel. Start by killing off the original 01294 channel's backend. I'm not sure we're going to keep this function, because 01295 while the features are nice, the cost is very high in terms of pure nastiness. XXX 01296 \param chan Channel to masquerade 01297 */ 01298 int ast_do_masquerade(struct ast_channel *chan); 01299 01300 /*! \brief Find bridged channel 01301 \param chan Current channel 01302 */ 01303 struct ast_channel *ast_bridged_channel(struct ast_channel *chan); 01304 01305 /*! 01306 \brief Inherits channel variable from parent to child channel 01307 \param parent Parent channel 01308 \param child Child channel 01309 01310 Scans all channel variables in the parent channel, looking for those 01311 that should be copied into the child channel. 01312 Variables whose names begin with a single '_' are copied into the 01313 child channel with the prefix removed. 01314 Variables whose names begin with '__' are copied into the child 01315 channel with their names unchanged. 01316 */ 01317 void ast_channel_inherit_variables(const struct ast_channel *parent, struct ast_channel *child); 01318 01319 /*! 01320 \brief adds a list of channel variables to a channel 01321 \param chan the channel 01322 \param vars a linked list of variables 01323 01324 Variable names can be for a regular channel variable or a dialplan function 01325 that has the ability to be written to. 01326 */ 01327 void ast_set_variables(struct ast_channel *chan, struct ast_variable *vars); 01328 01329 /*! 01330 \brief An opaque 'object' structure use by silence generators on channels. 01331 */ 01332 struct ast_silence_generator; 01333 01334 /*! 01335 \brief Starts a silence generator on the given channel. 01336 \param chan The channel to generate silence on 01337 \return An ast_silence_generator pointer, or NULL if an error occurs 01338 01339 This function will cause SLINEAR silence to be generated on the supplied 01340 channel until it is disabled; if the channel cannot be put into SLINEAR 01341 mode then the function will fail. 01342 01343 The pointer returned by this function must be preserved and passed to 01344 ast_channel_stop_silence_generator when you wish to stop the silence 01345 generation. 01346 */ 01347 struct ast_silence_generator *ast_channel_start_silence_generator(struct ast_channel *chan); 01348 01349 /*! 01350 \brief Stops a previously-started silence generator on the given channel. 01351 \param chan The channel to operate on 01352 \param state The ast_silence_generator pointer return by a previous call to 01353 ast_channel_start_silence_generator. 01354 \return nothing 01355 01356 This function will stop the operating silence generator and return the channel 01357 to its previous write format. 01358 */ 01359 void ast_channel_stop_silence_generator(struct ast_channel *chan, struct ast_silence_generator *state); 01360 01361 /*! 01362 \brief Check if the channel can run in internal timing mode. 01363 \param chan The channel to check 01364 \return boolean 01365 01366 This function will return 1 if internal timing is enabled and the timing 01367 device is available. 01368 */ 01369 int ast_internal_timing_enabled(struct ast_channel *chan); 01370 01371 /* Misc. functions below */ 01372 01373 /*! \brief if fd is a valid descriptor, set *pfd with the descriptor 01374 * \return Return 1 (not -1!) if added, 0 otherwise (so we can add the 01375 * return value to the index into the array) 01376 */ 01377 static inline int ast_add_fd(struct pollfd *pfd, int fd) 01378 { 01379 pfd->fd = fd; 01380 pfd->events = POLLIN | POLLPRI; 01381 return fd >= 0; 01382 } 01383 01384 /*! \brief Helper function for migrating select to poll */ 01385 static inline int ast_fdisset(struct pollfd *pfds, int fd, int max, int *start) 01386 { 01387 int x; 01388 int dummy=0; 01389 01390 if (fd < 0) 01391 return 0; 01392 if (!start) 01393 start = &dummy; 01394 for (x = *start; x<max; x++) 01395 if (pfds[x].fd == fd) { 01396 if (x == *start) 01397 (*start)++; 01398 return pfds[x].revents; 01399 } 01400 return 0; 01401 } 01402 01403 #ifdef SOLARIS 01404 static inline void timersub(struct timeval *tvend, struct timeval *tvstart, struct timeval *tvdiff) 01405 { 01406 tvdiff->tv_sec = tvend->tv_sec - tvstart->tv_sec; 01407 tvdiff->tv_usec = tvend->tv_usec - tvstart->tv_usec; 01408 if (tvdiff->tv_usec < 0) { 01409 tvdiff->tv_sec --; 01410 tvdiff->tv_usec += 1000000; 01411 } 01412 01413 } 01414 #endif 01415 01416 /*! \brief Waits for activity on a group of channels 01417 * \param nfds the maximum number of file descriptors in the sets 01418 * \param rfds file descriptors to check for read availability 01419 * \param wfds file descriptors to check for write availability 01420 * \param efds file descriptors to check for exceptions (OOB data) 01421 * \param tvp timeout while waiting for events 01422 * This is the same as a standard select(), except it guarantees the 01423 * behaviour where the passed struct timeval is updated with how much 01424 * time was not slept while waiting for the specified events 01425 */ 01426 static inline int ast_select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tvp) 01427 { 01428 #ifdef __linux__ 01429 return select(nfds, rfds, wfds, efds, tvp); 01430 #else 01431 if (tvp) { 01432 struct timeval tv, tvstart, tvend, tvlen; 01433 int res; 01434 01435 tv = *tvp; 01436 gettimeofday(&tvstart, NULL); 01437 res = select(nfds, rfds, wfds, efds, tvp); 01438 gettimeofday(&tvend, NULL); 01439 timersub(&tvend, &tvstart, &tvlen); 01440 timersub(&tv, &tvlen, tvp); 01441 if (tvp->tv_sec < 0 || (tvp->tv_sec == 0 && tvp->tv_usec < 0)) { 01442 tvp->tv_sec = 0; 01443 tvp->tv_usec = 0; 01444 } 01445 return res; 01446 } 01447 else 01448 return select(nfds, rfds, wfds, efds, NULL); 01449 #endif 01450 } 01451 01452 #ifdef DO_CRASH 01453 #define CRASH do { fprintf(stderr, "!! Forcing immediate crash a-la abort !!\n"); *((int *)0) = 0; } while(0) 01454 #else 01455 #define CRASH do { } while(0) 01456 #endif 01457 01458 #define CHECK_BLOCKING(c) do { \ 01459 if (ast_test_flag(c, AST_FLAG_BLOCKING)) {\ 01460 if (option_debug) \ 01461 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); \ 01462 CRASH; \ 01463 } else { \ 01464 (c)->blocker = pthread_self(); \ 01465 (c)->blockproc = __PRETTY_FUNCTION__; \ 01466 ast_set_flag(c, AST_FLAG_BLOCKING); \ 01467 } } while (0) 01468 01469 ast_group_t ast_get_group(const char *s); 01470 01471 /*! \brief print call- and pickup groups into buffer */ 01472 char *ast_print_group(char *buf, int buflen, ast_group_t group); 01473 01474 /*! \brief Convert enum channelreloadreason to text string for manager event 01475 \param reason Enum channelreloadreason - reason for reload (manager, cli, start etc) 01476 */ 01477 const char *channelreloadreason2txt(enum channelreloadreason reason); 01478 01479 /*! \brief return an ast_variable list of channeltypes */ 01480 struct ast_variable *ast_channeltype_list(void); 01481 01482 /*! 01483 \brief Begin 'whispering' onto a channel 01484 \param chan The channel to whisper onto 01485 \return 0 for success, non-zero for failure 01486 01487 This function will add a whisper buffer onto a channel and set a flag 01488 causing writes to the channel to reduce the volume level of the written 01489 audio samples, and then to mix in audio from the whisper buffer if it 01490 is available. 01491 01492 \note Note: This function performs no locking; you must hold the channel's lock before 01493 calling this function. 01494 */ 01495 int ast_channel_whisper_start(struct ast_channel *chan); 01496 01497 /*! 01498 \brief Feed an audio frame into the whisper buffer on a channel 01499 \param chan The channel to whisper onto 01500 \param f The frame to to whisper onto chan 01501 \return 0 for success, non-zero for failure 01502 */ 01503 int ast_channel_whisper_feed(struct ast_channel *chan, struct ast_frame *f); 01504 01505 /*! 01506 \brief Stop 'whispering' onto a channel 01507 \param chan The channel to whisper onto 01508 \return 0 for success, non-zero for failure 01509 01510 Note: This function performs no locking; you must hold the channel's lock before 01511 calling this function. 01512 */ 01513 void ast_channel_whisper_stop(struct ast_channel *chan); 01514 01515 01516 01517 /*! 01518 \brief return an english explanation of the code returned thru __ast_request_and_dial's 'outstate' argument 01519 \param reason The integer argument, usually taken from AST_CONTROL_ macros 01520 \return char pointer explaining the code 01521 */ 01522 char *ast_channel_reason2str(int reason); 01523 01524 01525 #if defined(__cplusplus) || defined(c_plusplus) 01526 } 01527 #endif 01528 01529 #endif /* _ASTERISK_CHANNEL_H */