| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * Asterisk -- An open source telephony toolkit. | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-01-21 07:06:25 +00:00
										 |  |  |  * Copyright (C) 1999 - 2005, Digium, Inc. | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2004-10-02 00:58:31 +00:00
										 |  |  |  * Mark Spencer <markster@digium.com> | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * See http://www.asterisk.org for more information about
 | 
					
						
							|  |  |  |  * the Asterisk project. Please do not directly contact | 
					
						
							|  |  |  |  * any of the maintainers of this project for assistance; | 
					
						
							|  |  |  |  * the project provides a web site, mailing lists and IRC | 
					
						
							|  |  |  |  * channels for your use. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  |  * This program is free software, distributed under the terms of | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * the GNU General Public License Version 2. See the LICENSE file | 
					
						
							|  |  |  |  * at the top of the source tree. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-24 20:12:06 +00:00
										 |  |  | /*! \file
 | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-10-24 20:12:06 +00:00
										 |  |  |  * \brief Generic Linux Telephony Interface driver | 
					
						
							| 
									
										
										
										
											2005-12-30 21:18:06 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * \author Mark Spencer <markster@digium.com> | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  *  | 
					
						
							| 
									
										
										
										
											2005-11-06 15:09:47 +00:00
										 |  |  |  * \ingroup channel_drivers | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-24 17:11:45 +00:00
										 |  |  | /*** MODULEINFO
 | 
					
						
							|  |  |  | 	<depend>ixjuser</depend> | 
					
						
							| 
									
										
										
										
											2011-07-14 20:13:06 +00:00
										 |  |  | 	<support_level>extended</support_level> | 
					
						
							| 
									
										
										
										
											2006-04-24 17:11:45 +00:00
										 |  |  |  ***/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-07 18:54:56 +00:00
										 |  |  | #include "asterisk.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ASTERISK_FILE_VERSION(__FILE__, "$Revision$") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-12-31 00:16:30 +00:00
										 |  |  | #include <ctype.h>
 | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | #include <sys/socket.h>
 | 
					
						
							|  |  |  | #include <sys/time.h>
 | 
					
						
							|  |  |  | #include <arpa/inet.h>
 | 
					
						
							|  |  |  | #include <fcntl.h>
 | 
					
						
							|  |  |  | #include <sys/ioctl.h>
 | 
					
						
							| 
									
										
										
										
											2006-03-06 21:16:25 +00:00
										 |  |  | #include <signal.h>
 | 
					
						
							| 
									
										
										
										
											2007-07-11 17:06:54 +00:00
										 |  |  | #ifdef HAVE_LINUX_COMPILER_H
 | 
					
						
							|  |  |  | #include <linux/compiler.h>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | #include <linux/telephony.h>
 | 
					
						
							|  |  |  | /* Still use some IXJ specific stuff */ | 
					
						
							| 
									
										
										
										
											2004-11-11 14:58:57 +00:00
										 |  |  | #include <linux/version.h>
 | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | #include <linux/ixjuser.h>
 | 
					
						
							| 
									
										
										
										
											2005-06-06 21:09:59 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "asterisk/lock.h"
 | 
					
						
							|  |  |  | #include "asterisk/channel.h"
 | 
					
						
							|  |  |  | #include "asterisk/config.h"
 | 
					
						
							|  |  |  | #include "asterisk/module.h"
 | 
					
						
							|  |  |  | #include "asterisk/pbx.h"
 | 
					
						
							|  |  |  | #include "asterisk/utils.h"
 | 
					
						
							|  |  |  | #include "asterisk/callerid.h"
 | 
					
						
							|  |  |  | #include "asterisk/causes.h"
 | 
					
						
							| 
									
										
										
										
											2006-02-01 23:05:28 +00:00
										 |  |  | #include "asterisk/stringfields.h"
 | 
					
						
							| 
									
										
										
										
											2006-07-19 20:44:39 +00:00
										 |  |  | #include "asterisk/musiconhold.h"
 | 
					
						
							| 
									
										
										
										
											2006-02-01 23:05:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-05-28 20:00:21 +00:00
										 |  |  | #include "chan_phone.h"
 | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-06-08 01:50:57 +00:00
										 |  |  | #ifdef QTI_PHONEJACK_TJ_PCI	/* check for the newer quicknet driver v.3.1.0 which has this symbol */
 | 
					
						
							|  |  |  | #define QNDRV_VER 310
 | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | #define QNDRV_VER 100
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if QNDRV_VER > 100
 | 
					
						
							|  |  |  | #ifdef __linux__
 | 
					
						
							|  |  |  | #define IXJ_PHONE_RING_START(x)	ioctl(p->fd, PHONE_RING_START, &x);
 | 
					
						
							|  |  |  | #else /* FreeBSD and others */
 | 
					
						
							|  |  |  | #define IXJ_PHONE_RING_START(x)	ioctl(p->fd, PHONE_RING_START, x);
 | 
					
						
							|  |  |  | #endif /* __linux__ */
 | 
					
						
							|  |  |  | #else	/* older driver */
 | 
					
						
							|  |  |  | #define IXJ_PHONE_RING_START(x)	ioctl(p->fd, PHONE_RING_START, &x);
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-05-16 17:54:53 +00:00
										 |  |  | #define DEFAULT_CALLER_ID "Unknown"
 | 
					
						
							| 
									
										
										
										
											2000-10-25 23:22:50 +00:00
										 |  |  | #define PHONE_MAX_BUF 480
 | 
					
						
							| 
									
										
										
										
											2001-08-23 17:57:10 +00:00
										 |  |  | #define DEFAULT_GAIN 0x100
 | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | static const char tdesc[] = "Standard Linux Telephony API Driver"; | 
					
						
							|  |  |  | static const char config[] = "phone.conf"; | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* Default context for dialtone mode */ | 
					
						
							|  |  |  | static char context[AST_MAX_EXTENSION] = "default"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-05-02 19:18:58 +00:00
										 |  |  | /* Default language */ | 
					
						
							|  |  |  | static char language[MAX_LANGUAGE] = ""; | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static int echocancel = AEC_OFF; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int silencesupression = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-01 20:27:37 +00:00
										 |  |  | static format_t prefformat = AST_FORMAT_G729A | AST_FORMAT_G723_1 | AST_FORMAT_SLINEAR | AST_FORMAT_ULAW; | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* Protect the interface list (of phone_pvt's) */ | 
					
						
							| 
									
										
										
										
											2004-06-09 01:45:08 +00:00
										 |  |  | AST_MUTEX_DEFINE_STATIC(iflock); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* Protect the monitoring thread, so only one process can kill or start it, and not
 | 
					
						
							|  |  |  |    when it's doing something critical. */ | 
					
						
							| 
									
										
										
										
											2004-06-09 01:45:08 +00:00
										 |  |  | AST_MUTEX_DEFINE_STATIC(monlock); | 
					
						
							| 
									
										
										
										
											2006-03-06 21:16:25 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* Boolean value whether the monitoring thread shall continue. */ | 
					
						
							|  |  |  | static unsigned int monitor; | 
					
						
							| 
									
										
										
										
											2004-12-31 00:16:30 +00:00
										 |  |  |     | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | /* This is the thread for the monitor which checks for input on the channels
 | 
					
						
							|  |  |  |    which are not currently in use.  */ | 
					
						
							| 
									
										
										
										
											2004-03-15 07:51:22 +00:00
										 |  |  | static pthread_t monitor_thread = AST_PTHREADT_NULL; | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static int restart_monitor(void); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* The private structures of the Phone Jack channels are linked for
 | 
					
						
							|  |  |  |    selecting outgoing channels */ | 
					
						
							|  |  |  |     | 
					
						
							|  |  |  | #define MODE_DIALTONE 	1
 | 
					
						
							|  |  |  | #define MODE_IMMEDIATE	2
 | 
					
						
							| 
									
										
										
										
											2006-08-08 17:02:45 +00:00
										 |  |  | #define MODE_FXO	3
 | 
					
						
							| 
									
										
										
										
											2004-12-31 00:16:30 +00:00
										 |  |  | #define MODE_FXS        4
 | 
					
						
							| 
									
										
										
										
											2006-08-08 17:02:45 +00:00
										 |  |  | #define MODE_SIGMA      5
 | 
					
						
							| 
									
										
										
										
											2004-12-31 00:16:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | static struct phone_pvt { | 
					
						
							|  |  |  | 	int fd;							/* Raw file descriptor for this device */ | 
					
						
							|  |  |  | 	struct ast_channel *owner;		/* Channel we belong to, possibly NULL */ | 
					
						
							|  |  |  | 	int mode;						/* Is this in the  */ | 
					
						
							| 
									
										
										
										
											2009-11-04 14:05:12 +00:00
										 |  |  | 	format_t lastformat;            /* Last output format */ | 
					
						
							|  |  |  | 	format_t lastinput;             /* Last input format */ | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	int ministate;					/* Miniature state, for dialtone mode */ | 
					
						
							|  |  |  | 	char dev[256];					/* Device name */ | 
					
						
							|  |  |  | 	struct phone_pvt *next;			/* Next channel in list */ | 
					
						
							|  |  |  | 	struct ast_frame fr;			/* Frame */ | 
					
						
							|  |  |  | 	char offset[AST_FRIENDLY_OFFSET]; | 
					
						
							| 
									
										
										
										
											2000-10-25 23:22:50 +00:00
										 |  |  | 	char buf[PHONE_MAX_BUF];					/* Static buffer for reading frames */ | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	int obuflen; | 
					
						
							|  |  |  | 	int dialtone; | 
					
						
							| 
									
										
										
										
											2001-08-23 17:57:10 +00:00
										 |  |  | 	int txgain, rxgain;             /* gain control for playing, recording  */ | 
					
						
							|  |  |  | 									/* 0x100 - 1.0, 0x200 - 2.0, 0x80 - 0.5 */ | 
					
						
							|  |  |  | 	int cpt;						/* Call Progress Tone playing? */ | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	int silencesupression; | 
					
						
							|  |  |  | 	char context[AST_MAX_EXTENSION]; | 
					
						
							| 
									
										
										
										
											2000-10-25 23:22:50 +00:00
										 |  |  | 	char obuf[PHONE_MAX_BUF * 2]; | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	char ext[AST_MAX_EXTENSION]; | 
					
						
							| 
									
										
										
										
											2000-05-02 19:18:58 +00:00
										 |  |  | 	char language[MAX_LANGUAGE]; | 
					
						
							| 
									
										
										
										
											2004-10-02 00:58:31 +00:00
										 |  |  | 	char cid_num[AST_MAX_EXTENSION]; | 
					
						
							|  |  |  | 	char cid_name[AST_MAX_EXTENSION]; | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | } *iflist = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-10-02 00:58:31 +00:00
										 |  |  | static char cid_num[AST_MAX_EXTENSION]; | 
					
						
							|  |  |  | static char cid_name[AST_MAX_EXTENSION]; | 
					
						
							| 
									
										
										
										
											2001-08-23 17:57:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-04 14:05:12 +00:00
										 |  |  | static struct ast_channel *phone_request(const char *type, format_t format, const struct ast_channel *requestor, void *data, int *cause); | 
					
						
							| 
									
										
										
										
											2006-08-31 01:59:02 +00:00
										 |  |  | static int phone_digit_begin(struct ast_channel *ast, char digit); | 
					
						
							| 
									
										
											  
											
												Merged revisions 51311 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r51311 | russell | 2007-01-19 11:49:38 -0600 (Fri, 19 Jan 2007) | 23 lines
Merge the changes from the /team/group/vldtmf_fixup branch.
The main bug being addressed here is a problem introduced when two SIP
channels using SIP INFO dtmf have their media directly bridged.  So, when a
DTMF END frame comes into Asterisk from an incoming INFO message, Asterisk
would try to emulate a digit of some length by first sending a DTMF BEGIN
frame and sending a DTMF END later timed off of incoming audio.  However,
since there was no audio coming in, the DTMF_END was never generated.  This
caused DTMF based features to no longer work.
To fix this, the core now knows when a channel doesn't care about DTMF BEGIN
frames (such as a SIP channel sending INFO dtmf).  If this is the case, then
Asterisk will not emulate a digit of some length, and will instead just pass
through the single DTMF END event.
Channel drivers also now get passed the length of the digit to their digit_end
callback.  This improves SIP INFO support even further by enabling us to put
the real digit duration in the INFO message instead of a hard coded 250ms.
Also, for an incoming INFO message, the duration is read from the frame and
passed into the core instead of just getting ignored.
(issue #8597, maybe others...)
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@51314 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											
										 
											2007-01-19 18:06:03 +00:00
										 |  |  | static int phone_digit_end(struct ast_channel *ast, char digit, unsigned int duration); | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | static int phone_call(struct ast_channel *ast, char *dest, int timeout); | 
					
						
							|  |  |  | static int phone_hangup(struct ast_channel *ast); | 
					
						
							|  |  |  | static int phone_answer(struct ast_channel *ast); | 
					
						
							|  |  |  | static struct ast_frame *phone_read(struct ast_channel *ast); | 
					
						
							|  |  |  | static int phone_write(struct ast_channel *ast, struct ast_frame *frame); | 
					
						
							|  |  |  | static struct ast_frame *phone_exception(struct ast_channel *ast); | 
					
						
							| 
									
										
										
										
											2005-03-28 20:48:24 +00:00
										 |  |  | static int phone_send_text(struct ast_channel *ast, const char *text); | 
					
						
							| 
									
										
										
										
											2005-03-30 06:39:39 +00:00
										 |  |  | static int phone_fixup(struct ast_channel *old, struct ast_channel *new); | 
					
						
							| 
									
										
										
										
											2006-05-10 12:24:11 +00:00
										 |  |  | static int phone_indicate(struct ast_channel *chan, int condition, const void *data, size_t datalen); | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static const struct ast_channel_tech phone_tech = { | 
					
						
							| 
									
										
										
										
											2006-02-01 23:05:28 +00:00
										 |  |  | 	.type = "Phone", | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 	.description = tdesc, | 
					
						
							| 
									
										
										
										
											2007-01-16 17:23:31 +00:00
										 |  |  | 	.capabilities = AST_FORMAT_G723_1 | AST_FORMAT_SLINEAR | AST_FORMAT_ULAW | AST_FORMAT_G729A, | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 	.requester = phone_request, | 
					
						
							| 
									
										
										
										
											2006-08-31 01:59:02 +00:00
										 |  |  | 	.send_digit_begin = phone_digit_begin, | 
					
						
							|  |  |  | 	.send_digit_end = phone_digit_end, | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 	.call = phone_call, | 
					
						
							|  |  |  | 	.hangup = phone_hangup, | 
					
						
							|  |  |  | 	.answer = phone_answer, | 
					
						
							|  |  |  | 	.read = phone_read, | 
					
						
							|  |  |  | 	.write = phone_write, | 
					
						
							|  |  |  | 	.exception = phone_exception, | 
					
						
							| 
									
										
										
										
											2006-01-10 21:34:04 +00:00
										 |  |  | 	.indicate = phone_indicate, | 
					
						
							| 
									
										
										
										
											2005-03-30 06:39:39 +00:00
										 |  |  | 	.fixup = phone_fixup | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct ast_channel_tech phone_tech_fxs = { | 
					
						
							| 
									
										
										
										
											2006-02-01 23:05:28 +00:00
										 |  |  | 	.type = "Phone", | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 	.description = tdesc, | 
					
						
							|  |  |  | 	.requester = phone_request, | 
					
						
							| 
									
										
										
										
											2006-08-31 01:59:02 +00:00
										 |  |  | 	.send_digit_begin = phone_digit_begin, | 
					
						
							|  |  |  | 	.send_digit_end = phone_digit_end, | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 	.call = phone_call, | 
					
						
							|  |  |  | 	.hangup = phone_hangup, | 
					
						
							|  |  |  | 	.answer = phone_answer, | 
					
						
							|  |  |  | 	.read = phone_read, | 
					
						
							|  |  |  | 	.write = phone_write, | 
					
						
							|  |  |  | 	.exception = phone_exception, | 
					
						
							|  |  |  | 	.write_video = phone_write, | 
					
						
							|  |  |  | 	.send_text = phone_send_text, | 
					
						
							| 
									
										
										
										
											2006-01-10 21:34:04 +00:00
										 |  |  | 	.indicate = phone_indicate, | 
					
						
							| 
									
										
										
										
											2005-03-30 06:39:39 +00:00
										 |  |  | 	.fixup = phone_fixup | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct ast_channel_tech *cur_tech; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-05-10 12:24:11 +00:00
										 |  |  | static int phone_indicate(struct ast_channel *chan, int condition, const void *data, size_t datalen) | 
					
						
							| 
									
										
										
										
											2006-01-10 21:34:04 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct phone_pvt *p = chan->tech_pvt; | 
					
						
							|  |  |  | 	int res=-1; | 
					
						
							| 
									
										
										
										
											2007-06-14 19:39:12 +00:00
										 |  |  | 	ast_debug(1, "Requested indication %d on channel %s\n", condition, chan->name); | 
					
						
							| 
									
										
										
										
											2006-01-10 21:34:04 +00:00
										 |  |  | 	switch(condition) { | 
					
						
							| 
									
										
										
										
											2008-03-05 22:43:22 +00:00
										 |  |  | 	case AST_CONTROL_FLASH: | 
					
						
							|  |  |  | 		ioctl(p->fd, IXJCTL_PSTN_SET_STATE, PSTN_ON_HOOK); | 
					
						
							|  |  |  | 		usleep(320000); | 
					
						
							|  |  |  | 		ioctl(p->fd, IXJCTL_PSTN_SET_STATE, PSTN_OFF_HOOK); | 
					
						
							| 
									
										
										
										
											2006-01-10 21:34:04 +00:00
										 |  |  | 			p->lastformat = -1; | 
					
						
							|  |  |  | 			res = 0; | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2008-03-05 22:43:22 +00:00
										 |  |  | 	case AST_CONTROL_HOLD: | 
					
						
							|  |  |  | 		ast_moh_start(chan, data, NULL); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case AST_CONTROL_UNHOLD: | 
					
						
							|  |  |  | 		ast_moh_stop(chan); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case AST_CONTROL_SRCUPDATE: | 
					
						
							|  |  |  | 		res = 0; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Condition %d is not supported on channel %s\n", condition, chan->name); | 
					
						
							| 
									
										
										
										
											2006-01-10 21:34:04 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-30 06:39:39 +00:00
										 |  |  | static int phone_fixup(struct ast_channel *old, struct ast_channel *new) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct phone_pvt *pvt = old->tech_pvt; | 
					
						
							|  |  |  | 	if (pvt && pvt->owner == old) | 
					
						
							|  |  |  | 		pvt->owner = new; | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-31 01:59:02 +00:00
										 |  |  | static int phone_digit_begin(struct ast_channel *chan, char digit) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* XXX Modify this callback to let Asterisk support controlling the length of DTMF */ | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Merged revisions 51311 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r51311 | russell | 2007-01-19 11:49:38 -0600 (Fri, 19 Jan 2007) | 23 lines
Merge the changes from the /team/group/vldtmf_fixup branch.
The main bug being addressed here is a problem introduced when two SIP
channels using SIP INFO dtmf have their media directly bridged.  So, when a
DTMF END frame comes into Asterisk from an incoming INFO message, Asterisk
would try to emulate a digit of some length by first sending a DTMF BEGIN
frame and sending a DTMF END later timed off of incoming audio.  However,
since there was no audio coming in, the DTMF_END was never generated.  This
caused DTMF based features to no longer work.
To fix this, the core now knows when a channel doesn't care about DTMF BEGIN
frames (such as a SIP channel sending INFO dtmf).  If this is the case, then
Asterisk will not emulate a digit of some length, and will instead just pass
through the single DTMF END event.
Channel drivers also now get passed the length of the digit to their digit_end
callback.  This improves SIP INFO support even further by enabling us to put
the real digit duration in the INFO message instead of a hard coded 250ms.
Also, for an incoming INFO message, the duration is read from the frame and
passed into the core instead of just getting ignored.
(issue #8597, maybe others...)
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@51314 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											
										 
											2007-01-19 18:06:03 +00:00
										 |  |  | static int phone_digit_end(struct ast_channel *ast, char digit, unsigned int duration) | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct phone_pvt *p; | 
					
						
							|  |  |  | 	int outdigit; | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 	p = ast->tech_pvt; | 
					
						
							| 
									
										
										
										
											2007-06-14 19:39:12 +00:00
										 |  |  | 	ast_debug(1, "Dialed %c\n", digit); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	switch(digit) { | 
					
						
							|  |  |  | 	case '0': | 
					
						
							|  |  |  | 	case '1': | 
					
						
							|  |  |  | 	case '2': | 
					
						
							|  |  |  | 	case '3': | 
					
						
							|  |  |  | 	case '4': | 
					
						
							|  |  |  | 	case '5': | 
					
						
							|  |  |  | 	case '6': | 
					
						
							|  |  |  | 	case '7': | 
					
						
							|  |  |  | 	case '8': | 
					
						
							|  |  |  | 	case '9': | 
					
						
							| 
									
										
										
										
											2003-09-17 04:39:22 +00:00
										 |  |  | 		outdigit = digit - '0'; | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case '*': | 
					
						
							|  |  |  | 		outdigit = 11; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case '#': | 
					
						
							|  |  |  | 		outdigit = 12; | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2005-01-15 23:48:12 +00:00
										 |  |  | 	case 'f':	/*flash*/ | 
					
						
							| 
									
										
										
										
											2003-09-17 04:39:22 +00:00
										 |  |  | 	case 'F': | 
					
						
							|  |  |  | 		ioctl(p->fd, IXJCTL_PSTN_SET_STATE, PSTN_ON_HOOK); | 
					
						
							|  |  |  | 		usleep(320000); | 
					
						
							|  |  |  | 		ioctl(p->fd, IXJCTL_PSTN_SET_STATE, PSTN_OFF_HOOK); | 
					
						
							|  |  |  | 		p->lastformat = -1; | 
					
						
							|  |  |  | 		return 0; | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	default: | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Unknown digit '%c'\n", digit); | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-06-14 19:39:12 +00:00
										 |  |  | 	ast_debug(1, "Dialed %d\n", outdigit); | 
					
						
							| 
									
										
										
										
											2003-09-17 04:39:22 +00:00
										 |  |  | 	ioctl(p->fd, PHONE_PLAY_TONE, outdigit); | 
					
						
							| 
									
										
										
										
											2000-12-28 19:21:06 +00:00
										 |  |  | 	p->lastformat = -1; | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int phone_call(struct ast_channel *ast, char *dest, int timeout) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct phone_pvt *p; | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	PHONE_CID cid; | 
					
						
							| 
									
										
										
										
											2007-07-18 19:47:20 +00:00
										 |  |  | 	struct timeval UtcTime = ast_tvnow(); | 
					
						
							|  |  |  | 	struct ast_tm tm; | 
					
						
							| 
									
										
										
										
											2005-01-01 23:58:57 +00:00
										 |  |  | 	int start; | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-06-14 22:09:20 +00:00
										 |  |  | 	ast_localtime(&UtcTime, &tm, NULL); | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-16 04:40:54 +00:00
										 |  |  | 	memset(&cid, 0, sizeof(PHONE_CID)); | 
					
						
							| 
									
										
										
										
											2011-05-03 19:55:49 +00:00
										 |  |  |     snprintf(cid.month, sizeof(cid.month), "%02d",(tm.tm_mon + 1)); | 
					
						
							|  |  |  |     snprintf(cid.day, sizeof(cid.day),     "%02d", tm.tm_mday); | 
					
						
							|  |  |  |     snprintf(cid.hour, sizeof(cid.hour),   "%02d", tm.tm_hour); | 
					
						
							|  |  |  |     snprintf(cid.min, sizeof(cid.min),     "%02d", tm.tm_min); | 
					
						
							| 
									
										
										
										
											2004-06-08 01:50:57 +00:00
										 |  |  | 	/* the standard format of ast->callerid is:  "name" <number>, but not always complete */ | 
					
						
							| 
									
										
										
										
											2010-07-14 15:48:36 +00:00
										 |  |  | 	if (!ast->connected.id.name.valid | 
					
						
							|  |  |  | 		|| ast_strlen_zero(ast->connected.id.name.str)) { | 
					
						
							| 
									
										
										
										
											2006-10-25 14:44:50 +00:00
										 |  |  | 		strcpy(cid.name, DEFAULT_CALLER_ID); | 
					
						
							| 
									
										
										
										
											2010-07-14 15:48:36 +00:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		ast_copy_string(cid.name, ast->connected.id.name.str, sizeof(cid.name)); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2004-10-02 00:58:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-14 15:48:36 +00:00
										 |  |  | 	if (ast->connected.id.number.valid && ast->connected.id.number.str) { | 
					
						
							|  |  |  | 		ast_copy_string(cid.number, ast->connected.id.number.str, sizeof(cid.number)); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 	p = ast->tech_pvt; | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-08-02 05:26:31 +00:00
										 |  |  | 	if ((ast->_state != AST_STATE_DOWN) && (ast->_state != AST_STATE_RESERVED)) { | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 		ast_log(LOG_WARNING, "phone_call called on %s, neither down nor reserved\n", ast->name); | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-06-14 19:39:12 +00:00
										 |  |  | 	ast_debug(1, "Ringing %s on %s (%d)\n", dest, ast->name, ast->fds[0]); | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-01-01 23:58:57 +00:00
										 |  |  | 	start = IXJ_PHONE_RING_START(cid); | 
					
						
							| 
									
										
										
										
											2004-12-31 00:16:30 +00:00
										 |  |  | 	if (start == -1) | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if (p->mode == MODE_FXS) { | 
					
						
							|  |  |  | 		char *digit = strchr(dest, '/'); | 
					
						
							|  |  |  | 		if (digit) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 		  digit++; | 
					
						
							|  |  |  | 		  while (*digit) | 
					
						
							| 
									
										
											  
											
												Merged revisions 51311 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r51311 | russell | 2007-01-19 11:49:38 -0600 (Fri, 19 Jan 2007) | 23 lines
Merge the changes from the /team/group/vldtmf_fixup branch.
The main bug being addressed here is a problem introduced when two SIP
channels using SIP INFO dtmf have their media directly bridged.  So, when a
DTMF END frame comes into Asterisk from an incoming INFO message, Asterisk
would try to emulate a digit of some length by first sending a DTMF BEGIN
frame and sending a DTMF END later timed off of incoming audio.  However,
since there was no audio coming in, the DTMF_END was never generated.  This
caused DTMF based features to no longer work.
To fix this, the core now knows when a channel doesn't care about DTMF BEGIN
frames (such as a SIP channel sending INFO dtmf).  If this is the case, then
Asterisk will not emulate a digit of some length, and will instead just pass
through the single DTMF END event.
Channel drivers also now get passed the length of the digit to their digit_end
callback.  This improves SIP INFO support even further by enabling us to put
the real digit duration in the INFO message instead of a hard coded 250ms.
Also, for an incoming INFO message, the duration is read from the frame and
passed into the core instead of just getting ignored.
(issue #8597, maybe others...)
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@51314 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											
										 
											2007-01-19 18:06:03 +00:00
										 |  |  | 		    phone_digit_end(ast, *digit++, 0); | 
					
						
							| 
									
										
										
										
											2004-12-31 00:16:30 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  |   | 
					
						
							|  |  |  |   	ast_setstate(ast, AST_STATE_RINGING); | 
					
						
							| 
									
										
										
										
											2004-04-06 22:17:32 +00:00
										 |  |  | 	ast_queue_control(ast, AST_CONTROL_RINGING); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int phone_hangup(struct ast_channel *ast) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct phone_pvt *p; | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 	p = ast->tech_pvt; | 
					
						
							| 
									
										
										
										
											2007-06-14 19:39:12 +00:00
										 |  |  | 	ast_debug(1, "phone_hangup(%s)\n", ast->name); | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 	if (!ast->tech_pvt) { | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 		ast_log(LOG_WARNING, "Asked to hangup channel not connected\n"); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	/* XXX Is there anything we can do to really hang up except stop recording? */ | 
					
						
							| 
									
										
										
										
											2002-08-02 05:26:31 +00:00
										 |  |  | 	ast_setstate(ast, AST_STATE_DOWN); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	if (ioctl(p->fd, PHONE_REC_STOP)) | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Failed to stop recording\n"); | 
					
						
							|  |  |  | 	if (ioctl(p->fd, PHONE_PLAY_STOP)) | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Failed to stop playing\n"); | 
					
						
							|  |  |  | 	if (ioctl(p->fd, PHONE_RING_STOP)) | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Failed to stop ringing\n"); | 
					
						
							|  |  |  | 	if (ioctl(p->fd, PHONE_CPT_STOP)) | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Failed to stop sounds\n"); | 
					
						
							| 
									
										
										
										
											2000-10-25 23:22:50 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* If it's an FXO, hang them up */ | 
					
						
							|  |  |  | 	if (p->mode == MODE_FXO) { | 
					
						
							| 
									
										
										
										
											2007-06-14 19:39:12 +00:00
										 |  |  | 		if (ioctl(p->fd, PHONE_PSTN_SET_STATE, PSTN_ON_HOOK)) | 
					
						
							|  |  |  | 			ast_debug(1, "ioctl(PHONE_PSTN_SET_STATE) failed on %s (%s)\n",ast->name, strerror(errno)); | 
					
						
							| 
									
										
										
										
											2000-10-25 23:22:50 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	/* If they're off hook, give a busy signal */ | 
					
						
							|  |  |  | 	if (ioctl(p->fd, PHONE_HOOKSTATE)) { | 
					
						
							| 
									
										
										
										
											2007-06-14 19:39:12 +00:00
										 |  |  | 		ast_debug(1, "Got hunghup, giving busy signal\n"); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 		ioctl(p->fd, PHONE_BUSY); | 
					
						
							| 
									
										
										
										
											2001-08-23 17:57:10 +00:00
										 |  |  | 		p->cpt = 1; | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	p->lastformat = -1; | 
					
						
							|  |  |  | 	p->lastinput = -1; | 
					
						
							|  |  |  | 	p->ministate = 0; | 
					
						
							|  |  |  | 	p->obuflen = 0; | 
					
						
							|  |  |  | 	p->dialtone = 0; | 
					
						
							|  |  |  | 	memset(p->ext, 0, sizeof(p->ext)); | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 	((struct phone_pvt *)(ast->tech_pvt))->owner = NULL; | 
					
						
							| 
									
										
										
										
											2007-01-23 22:59:55 +00:00
										 |  |  | 	ast_module_unref(ast_module_info->self); | 
					
						
							| 
									
										
										
										
											2007-07-26 15:49:18 +00:00
										 |  |  | 	ast_verb(3, "Hungup '%s'\n", ast->name); | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 	ast->tech_pvt = NULL; | 
					
						
							| 
									
										
										
										
											2002-08-02 05:26:31 +00:00
										 |  |  | 	ast_setstate(ast, AST_STATE_DOWN); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	restart_monitor(); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int phone_setup(struct ast_channel *ast) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct phone_pvt *p; | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 	p = ast->tech_pvt; | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	ioctl(p->fd, PHONE_CPT_STOP); | 
					
						
							|  |  |  | 	/* Nothing to answering really, just start recording */ | 
					
						
							| 
									
										
										
										
											2007-01-16 17:23:31 +00:00
										 |  |  | 	if (ast->rawreadformat == AST_FORMAT_G729A) { | 
					
						
							|  |  |  | 		/* Prefer g729 */ | 
					
						
							|  |  |  | 		ioctl(p->fd, PHONE_REC_STOP); | 
					
						
							|  |  |  | 		if (p->lastinput != AST_FORMAT_G729A) { | 
					
						
							|  |  |  | 			p->lastinput = AST_FORMAT_G729A; | 
					
						
							|  |  |  | 			if (ioctl(p->fd, PHONE_REC_CODEC, G729)) { | 
					
						
							|  |  |  | 				ast_log(LOG_WARNING, "Failed to set codec to g729\n"); | 
					
						
							|  |  |  | 				return -1; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  |         } else if (ast->rawreadformat == AST_FORMAT_G723_1) { | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 		ioctl(p->fd, PHONE_REC_STOP); | 
					
						
							|  |  |  | 		if (p->lastinput != AST_FORMAT_G723_1) { | 
					
						
							|  |  |  | 			p->lastinput = AST_FORMAT_G723_1; | 
					
						
							|  |  |  | 			if (ioctl(p->fd, PHONE_REC_CODEC, G723_63)) { | 
					
						
							|  |  |  | 				ast_log(LOG_WARNING, "Failed to set codec to g723.1\n"); | 
					
						
							|  |  |  | 				return -1; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 	} else if (ast->rawreadformat == AST_FORMAT_SLINEAR) { | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 		ioctl(p->fd, PHONE_REC_STOP); | 
					
						
							|  |  |  | 		if (p->lastinput != AST_FORMAT_SLINEAR) { | 
					
						
							|  |  |  | 			p->lastinput = AST_FORMAT_SLINEAR; | 
					
						
							|  |  |  | 			if (ioctl(p->fd, PHONE_REC_CODEC, LINEAR16)) { | 
					
						
							|  |  |  | 				ast_log(LOG_WARNING, "Failed to set codec to signed linear 16\n"); | 
					
						
							|  |  |  | 				return -1; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 	} else if (ast->rawreadformat == AST_FORMAT_ULAW) { | 
					
						
							| 
									
										
										
										
											2001-08-23 17:57:10 +00:00
										 |  |  | 		ioctl(p->fd, PHONE_REC_STOP); | 
					
						
							|  |  |  | 		if (p->lastinput != AST_FORMAT_ULAW) { | 
					
						
							|  |  |  | 			p->lastinput = AST_FORMAT_ULAW; | 
					
						
							|  |  |  | 			if (ioctl(p->fd, PHONE_REC_CODEC, ULAW)) { | 
					
						
							| 
									
										
										
										
											2004-05-16 17:54:53 +00:00
										 |  |  | 				ast_log(LOG_WARNING, "Failed to set codec to uLaw\n"); | 
					
						
							| 
									
										
										
										
											2001-08-23 17:57:10 +00:00
										 |  |  | 				return -1; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2004-12-31 00:16:30 +00:00
										 |  |  | 	} else if (p->mode == MODE_FXS) { | 
					
						
							|  |  |  | 		ioctl(p->fd, PHONE_REC_STOP); | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 		if (p->lastinput != ast->rawreadformat) { | 
					
						
							|  |  |  | 			p->lastinput = ast->rawreadformat; | 
					
						
							|  |  |  | 			if (ioctl(p->fd, PHONE_REC_CODEC, ast->rawreadformat)) { | 
					
						
							| 
									
										
										
										
											2009-11-04 14:05:12 +00:00
										 |  |  | 				ast_log(LOG_WARNING, "Failed to set codec to %s\n",  | 
					
						
							|  |  |  | 					ast_getformatname(ast->rawreadformat)); | 
					
						
							| 
									
										
										
										
											2004-12-31 00:16:30 +00:00
										 |  |  | 				return -1; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 		ast_log(LOG_WARNING, "Can't do format %s\n", ast_getformatname(ast->rawreadformat)); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (ioctl(p->fd, PHONE_REC_START)) { | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Failed to start recording\n"); | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-01-15 23:48:12 +00:00
										 |  |  | 	/* set the DTMF times (the default is too short) */ | 
					
						
							| 
									
										
										
										
											2003-09-17 04:39:22 +00:00
										 |  |  | 	ioctl(p->fd, PHONE_SET_TONE_ON_TIME, 300); | 
					
						
							|  |  |  | 	ioctl(p->fd, PHONE_SET_TONE_OFF_TIME, 200); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int phone_answer(struct ast_channel *ast) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2000-10-25 23:22:50 +00:00
										 |  |  | 	struct phone_pvt *p; | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 	p = ast->tech_pvt; | 
					
						
							| 
									
										
										
										
											2000-10-25 23:22:50 +00:00
										 |  |  | 	/* In case it's a LineJack, take it off hook */ | 
					
						
							|  |  |  | 	if (p->mode == MODE_FXO) { | 
					
						
							| 
									
										
										
										
											2007-06-14 19:39:12 +00:00
										 |  |  | 		if (ioctl(p->fd, PHONE_PSTN_SET_STATE, PSTN_OFF_HOOK)) | 
					
						
							|  |  |  | 			ast_debug(1, "ioctl(PHONE_PSTN_SET_STATE) failed on %s (%s)\n", ast->name, strerror(errno)); | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			ast_debug(1, "Took linejack off hook\n"); | 
					
						
							| 
									
										
										
										
											2000-10-25 23:22:50 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	phone_setup(ast); | 
					
						
							| 
									
										
										
										
											2007-06-14 19:39:12 +00:00
										 |  |  | 	ast_debug(1, "phone_answer(%s)\n", ast->name); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	ast->rings = 0; | 
					
						
							| 
									
										
										
										
											2002-08-02 05:26:31 +00:00
										 |  |  | 	ast_setstate(ast, AST_STATE_UP); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | #if 0
 | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | static char phone_2digit(char c) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (c == 12) | 
					
						
							|  |  |  | 		return '#'; | 
					
						
							|  |  |  | 	else if (c == 11) | 
					
						
							|  |  |  | 		return '*'; | 
					
						
							|  |  |  | 	else if ((c < 10) && (c >= 0)) | 
					
						
							|  |  |  | 		return '0' + c - 1; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		return '?'; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2003-03-16 22:37:31 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-10 19:12:11 +00:00
										 |  |  | static struct ast_frame  *phone_exception(struct ast_channel *ast) | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int res; | 
					
						
							|  |  |  | 	union telephony_exception phonee; | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 	struct phone_pvt *p = ast->tech_pvt; | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	char digit; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Some nice norms */ | 
					
						
							|  |  |  | 	p->fr.datalen = 0; | 
					
						
							| 
									
										
										
										
											2002-11-29 02:14:13 +00:00
										 |  |  | 	p->fr.samples = 0; | 
					
						
							| 
									
										
										
										
											2008-05-22 16:29:54 +00:00
										 |  |  | 	p->fr.data.ptr =  NULL; | 
					
						
							| 
									
										
										
										
											2006-02-01 23:05:28 +00:00
										 |  |  | 	p->fr.src = "Phone"; | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	p->fr.offset = 0; | 
					
						
							|  |  |  | 	p->fr.mallocd=0; | 
					
						
							| 
									
										
										
										
											2005-07-15 23:00:47 +00:00
										 |  |  | 	p->fr.delivery = ast_tv(0,0); | 
					
						
							| 
									
										
										
										
											2004-12-31 00:16:30 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	phonee.bytes = ioctl(p->fd, PHONE_EXCEPTION); | 
					
						
							|  |  |  | 	if (phonee.bits.dtmf_ready)  { | 
					
						
							| 
									
										
										
										
											2007-06-14 19:39:12 +00:00
										 |  |  | 		ast_debug(1, "phone_exception(): DTMF\n"); | 
					
						
							| 
									
										
										
										
											2000-10-25 23:22:50 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 		/* We've got a digit -- Just handle this nicely and easily */ | 
					
						
							|  |  |  | 		digit =  ioctl(p->fd, PHONE_GET_DTMF_ASCII); | 
					
						
							| 
									
										
										
										
											2009-11-04 14:05:12 +00:00
										 |  |  | 		p->fr.subclass.integer = digit; | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 		p->fr.frametype = AST_FRAME_DTMF; | 
					
						
							|  |  |  | 		return &p->fr; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (phonee.bits.hookstate) { | 
					
						
							| 
									
										
										
										
											2007-06-14 19:39:12 +00:00
										 |  |  | 		ast_debug(1, "Hookstate changed\n"); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 		res = ioctl(p->fd, PHONE_HOOKSTATE); | 
					
						
							|  |  |  | 		/* See if we've gone on hook, if so, notify by returning NULL */ | 
					
						
							| 
									
										
										
										
											2007-06-14 19:39:12 +00:00
										 |  |  | 		ast_debug(1, "New hookstate: %d\n", res); | 
					
						
							| 
									
										
										
										
											2000-10-25 23:22:50 +00:00
										 |  |  | 		if (!res && (p->mode != MODE_FXO)) | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 			return NULL; | 
					
						
							|  |  |  | 		else { | 
					
						
							| 
									
										
										
										
											2002-08-02 05:26:31 +00:00
										 |  |  | 			if (ast->_state == AST_STATE_RINGING) { | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 				/* They've picked up the phone */ | 
					
						
							|  |  |  | 				p->fr.frametype = AST_FRAME_CONTROL; | 
					
						
							| 
									
										
										
										
											2009-11-04 14:05:12 +00:00
										 |  |  | 				p->fr.subclass.integer = AST_CONTROL_ANSWER; | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 				phone_setup(ast); | 
					
						
							| 
									
										
										
										
											2002-08-02 05:26:31 +00:00
										 |  |  | 				ast_setstate(ast, AST_STATE_UP); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 				return &p->fr; | 
					
						
							|  |  |  | 			}  else  | 
					
						
							| 
									
										
										
										
											2002-08-02 05:26:31 +00:00
										 |  |  | 				ast_log(LOG_WARNING, "Got off hook in weird state %d\n", ast->_state); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2000-10-25 23:22:50 +00:00
										 |  |  | #if 1
 | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	if (phonee.bits.pstn_ring) | 
					
						
							|  |  |  | 		ast_verbose("Unit is ringing\n"); | 
					
						
							|  |  |  | 	if (phonee.bits.caller_id) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		ast_verbose("We have caller ID\n"); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2000-10-25 23:22:50 +00:00
										 |  |  | 	if (phonee.bits.pstn_wink) | 
					
						
							|  |  |  | 		ast_verbose("Detected Wink\n"); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2001-03-10 19:12:11 +00:00
										 |  |  | 	/* Strange -- nothing there.. */ | 
					
						
							|  |  |  | 	p->fr.frametype = AST_FRAME_NULL; | 
					
						
							| 
									
										
										
										
											2009-11-04 14:05:12 +00:00
										 |  |  | 	p->fr.subclass.integer = 0; | 
					
						
							| 
									
										
										
										
											2001-03-10 19:12:11 +00:00
										 |  |  | 	return &p->fr; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct ast_frame  *phone_read(struct ast_channel *ast) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int res; | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 	struct phone_pvt *p = ast->tech_pvt; | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2001-03-10 19:12:11 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Some nice norms */ | 
					
						
							|  |  |  | 	p->fr.datalen = 0; | 
					
						
							| 
									
										
										
										
											2002-11-29 02:14:13 +00:00
										 |  |  | 	p->fr.samples = 0; | 
					
						
							| 
									
										
										
										
											2008-05-22 16:29:54 +00:00
										 |  |  | 	p->fr.data.ptr =  NULL; | 
					
						
							| 
									
										
										
										
											2006-02-01 23:05:28 +00:00
										 |  |  | 	p->fr.src = "Phone"; | 
					
						
							| 
									
										
										
										
											2001-03-10 19:12:11 +00:00
										 |  |  | 	p->fr.offset = 0; | 
					
						
							|  |  |  | 	p->fr.mallocd=0; | 
					
						
							| 
									
										
										
										
											2005-07-15 23:00:47 +00:00
										 |  |  | 	p->fr.delivery = ast_tv(0,0); | 
					
						
							| 
									
										
										
										
											2001-03-10 19:12:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	/* Try to read some data... */ | 
					
						
							|  |  |  | 	CHECK_BLOCKING(ast); | 
					
						
							| 
									
										
										
										
											2000-10-25 23:22:50 +00:00
										 |  |  | 	res = read(p->fd, p->buf, PHONE_MAX_BUF); | 
					
						
							| 
									
										
										
										
											2004-12-07 20:38:43 +00:00
										 |  |  | 	ast_clear_flag(ast, AST_FLAG_BLOCKING); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	if (res < 0) { | 
					
						
							|  |  |  | #if 0
 | 
					
						
							|  |  |  | 		if (errno == EAGAIN) { | 
					
						
							|  |  |  | 			ast_log(LOG_WARNING, "Null frame received\n"); | 
					
						
							|  |  |  | 			p->fr.frametype = AST_FRAME_NULL; | 
					
						
							|  |  |  | 			p->fr.subclass = 0; | 
					
						
							|  |  |  | 			return &p->fr; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Error reading: %s\n", strerror(errno)); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-05-22 16:29:54 +00:00
										 |  |  | 	p->fr.data.ptr = p->buf; | 
					
						
							| 
									
										
										
										
											2004-12-31 00:16:30 +00:00
										 |  |  | 	if (p->mode != MODE_FXS) | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	switch(p->buf[0] & 0x3) { | 
					
						
							|  |  |  | 	case '0': | 
					
						
							|  |  |  | 	case '1': | 
					
						
							|  |  |  | 		/* Normal */ | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case '2': | 
					
						
							|  |  |  | 	case '3': | 
					
						
							|  |  |  | 		/* VAD/CNG, only send two words */ | 
					
						
							|  |  |  | 		res = 4; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2002-11-29 02:14:13 +00:00
										 |  |  | 	p->fr.samples = 240; | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	p->fr.datalen = res; | 
					
						
							| 
									
										
										
										
											2007-11-06 22:51:48 +00:00
										 |  |  | 	p->fr.frametype = p->lastinput <= AST_FORMAT_AUDIO_MASK ? | 
					
						
							| 
									
										
										
										
											2004-12-31 00:16:30 +00:00
										 |  |  |                           AST_FRAME_VOICE :  | 
					
						
							|  |  |  | 			  p->lastinput <= AST_FORMAT_PNG ? AST_FRAME_IMAGE  | 
					
						
							|  |  |  | 			  : AST_FRAME_VIDEO; | 
					
						
							| 
									
										
										
										
											2009-11-04 14:05:12 +00:00
										 |  |  | 	p->fr.subclass.codec = p->lastinput; | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	p->fr.offset = AST_FRIENDLY_OFFSET; | 
					
						
							| 
									
										
										
										
											2005-04-03 22:57:18 +00:00
										 |  |  | 	/* Byteswap from little-endian to native-endian */ | 
					
						
							| 
									
										
										
										
											2009-11-04 14:05:12 +00:00
										 |  |  | 	if (p->fr.subclass.codec == AST_FORMAT_SLINEAR) | 
					
						
							| 
									
										
										
										
											2005-04-03 22:57:18 +00:00
										 |  |  | 		ast_frame_byteswap_le(&p->fr); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	return &p->fr; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-03 22:57:18 +00:00
										 |  |  | static int phone_write_buf(struct phone_pvt *p, const char *buf, int len, int frlen, int swap) | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int res; | 
					
						
							|  |  |  | 	/* Store as much of the buffer as we can, then write fixed frames */ | 
					
						
							|  |  |  | 	int space = sizeof(p->obuf) - p->obuflen; | 
					
						
							|  |  |  | 	/* Make sure we have enough buffer space to store the frame */ | 
					
						
							|  |  |  | 	if (space < len) | 
					
						
							|  |  |  | 		len = space; | 
					
						
							| 
									
										
										
										
											2005-04-03 22:57:18 +00:00
										 |  |  | 	if (swap) | 
					
						
							| 
									
										
										
										
											2005-04-04 02:13:40 +00:00
										 |  |  | 		ast_swapcopy_samples(p->obuf+p->obuflen, buf, len/2); | 
					
						
							| 
									
										
										
										
											2005-04-03 22:57:18 +00:00
										 |  |  | 	else | 
					
						
							|  |  |  | 		memcpy(p->obuf + p->obuflen, buf, len); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	p->obuflen += len; | 
					
						
							|  |  |  | 	while(p->obuflen > frlen) { | 
					
						
							|  |  |  | 		res = write(p->fd, p->obuf, frlen); | 
					
						
							|  |  |  | 		if (res != frlen) { | 
					
						
							|  |  |  | 			if (res < 1) { | 
					
						
							| 
									
										
										
										
											2001-08-23 17:57:10 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Card is in non-blocking mode now and it works well now, but there are | 
					
						
							|  |  |  |  * lot of messages like this. So, this message is temporarily disabled. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 				return 0; | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 			} else { | 
					
						
							|  |  |  | 				ast_log(LOG_WARNING, "Only wrote %d of %d bytes\n", res, frlen); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		p->obuflen -= frlen; | 
					
						
							|  |  |  | 		/* Move memory if necessary */ | 
					
						
							|  |  |  | 		if (p->obuflen)  | 
					
						
							|  |  |  | 			memmove(p->obuf, p->obuf + frlen, p->obuflen); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return len; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-28 20:48:24 +00:00
										 |  |  | static int phone_send_text(struct ast_channel *ast, const char *text) | 
					
						
							| 
									
										
										
										
											2004-12-31 00:16:30 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     int length = strlen(text); | 
					
						
							| 
									
										
										
										
											2005-04-03 22:57:18 +00:00
										 |  |  |     return phone_write_buf(ast->tech_pvt, text, length, length, 0) ==  | 
					
						
							| 
									
										
										
										
											2005-03-02 05:42:38 +00:00
										 |  |  |            length ? 0 : -1; | 
					
						
							| 
									
										
										
										
											2004-12-31 00:16:30 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | static int phone_write(struct ast_channel *ast, struct ast_frame *frame) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 	struct phone_pvt *p = ast->tech_pvt; | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	int res; | 
					
						
							|  |  |  | 	int maxfr=0; | 
					
						
							|  |  |  | 	char *pos; | 
					
						
							|  |  |  | 	int sofar; | 
					
						
							|  |  |  | 	int expected; | 
					
						
							| 
									
										
										
										
											2000-12-14 13:50:41 +00:00
										 |  |  | 	int codecset = 0; | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	char tmpbuf[4]; | 
					
						
							|  |  |  | 	/* Write a frame of (presumably voice) data */ | 
					
						
							| 
									
										
										
										
											2004-12-31 00:16:30 +00:00
										 |  |  | 	if (frame->frametype != AST_FRAME_VOICE && p->mode != MODE_FXS) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		if (frame->frametype != AST_FRAME_IMAGE) | 
					
						
							|  |  |  | 			ast_log(LOG_WARNING, "Don't know what to do with  frame type '%d'\n", frame->frametype); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-11-04 14:05:12 +00:00
										 |  |  | 	if (!(frame->subclass.codec & | 
					
						
							| 
									
										
										
										
											2007-01-16 17:23:31 +00:00
										 |  |  | 		(AST_FORMAT_G723_1 | AST_FORMAT_SLINEAR | AST_FORMAT_ULAW | AST_FORMAT_G729A)) &&  | 
					
						
							| 
									
										
										
										
											2004-12-31 00:16:30 +00:00
										 |  |  | 	    p->mode != MODE_FXS) { | 
					
						
							| 
									
										
										
										
											2009-11-04 14:05:12 +00:00
										 |  |  | 		ast_log(LOG_WARNING, "Cannot handle frames in %s format\n", ast_getformatname(frame->subclass.codec)); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2002-08-02 05:26:31 +00:00
										 |  |  | #if 0
 | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	/* If we're not in up mode, go into up mode now */ | 
					
						
							| 
									
										
										
										
											2002-08-02 05:26:31 +00:00
										 |  |  | 	if (ast->_state != AST_STATE_UP) { | 
					
						
							|  |  |  | 		ast_setstate(ast, AST_STATE_UP); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 		phone_setup(ast); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2002-08-02 05:26:31 +00:00
										 |  |  | #else
 | 
					
						
							|  |  |  | 	if (ast->_state != AST_STATE_UP) { | 
					
						
							|  |  |  | 		/* Don't try tos end audio on-hook */ | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | #endif	
 | 
					
						
							| 
									
										
										
										
											2009-11-04 14:05:12 +00:00
										 |  |  | 	if (frame->subclass.codec == AST_FORMAT_G729A) { | 
					
						
							| 
									
										
										
										
											2007-01-16 17:23:31 +00:00
										 |  |  | 		if (p->lastformat != AST_FORMAT_G729A) { | 
					
						
							|  |  |  | 			ioctl(p->fd, PHONE_PLAY_STOP); | 
					
						
							|  |  |  | 			ioctl(p->fd, PHONE_REC_STOP); | 
					
						
							|  |  |  | 			if (ioctl(p->fd, PHONE_PLAY_CODEC, G729)) { | 
					
						
							|  |  |  | 				ast_log(LOG_WARNING, "Unable to set G729 mode\n"); | 
					
						
							|  |  |  | 				return -1; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (ioctl(p->fd, PHONE_REC_CODEC, G729)) { | 
					
						
							|  |  |  | 				ast_log(LOG_WARNING, "Unable to set G729 mode\n"); | 
					
						
							|  |  |  | 				return -1; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			p->lastformat = AST_FORMAT_G729A; | 
					
						
							|  |  |  | 			p->lastinput = AST_FORMAT_G729A; | 
					
						
							|  |  |  | 			/* Reset output buffer */ | 
					
						
							|  |  |  | 			p->obuflen = 0; | 
					
						
							|  |  |  | 			codecset = 1; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (frame->datalen > 80) { | 
					
						
							|  |  |  | 			ast_log(LOG_WARNING, "Frame size too large for G.729 (%d bytes)\n", frame->datalen); | 
					
						
							|  |  |  | 			return -1; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		maxfr = 80; | 
					
						
							| 
									
										
										
										
											2009-11-04 14:05:12 +00:00
										 |  |  |         } else if (frame->subclass.codec == AST_FORMAT_G723_1) { | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 		if (p->lastformat != AST_FORMAT_G723_1) { | 
					
						
							|  |  |  | 			ioctl(p->fd, PHONE_PLAY_STOP); | 
					
						
							|  |  |  | 			ioctl(p->fd, PHONE_REC_STOP); | 
					
						
							|  |  |  | 			if (ioctl(p->fd, PHONE_PLAY_CODEC, G723_63)) { | 
					
						
							|  |  |  | 				ast_log(LOG_WARNING, "Unable to set G723.1 mode\n"); | 
					
						
							|  |  |  | 				return -1; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (ioctl(p->fd, PHONE_REC_CODEC, G723_63)) { | 
					
						
							|  |  |  | 				ast_log(LOG_WARNING, "Unable to set G723.1 mode\n"); | 
					
						
							|  |  |  | 				return -1; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			p->lastformat = AST_FORMAT_G723_1; | 
					
						
							|  |  |  | 			p->lastinput = AST_FORMAT_G723_1; | 
					
						
							|  |  |  | 			/* Reset output buffer */ | 
					
						
							|  |  |  | 			p->obuflen = 0; | 
					
						
							| 
									
										
										
										
											2000-12-14 13:50:41 +00:00
										 |  |  | 			codecset = 1; | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if (frame->datalen > 24) { | 
					
						
							|  |  |  | 			ast_log(LOG_WARNING, "Frame size too large for G.723.1 (%d bytes)\n", frame->datalen); | 
					
						
							|  |  |  | 			return -1; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		maxfr = 24; | 
					
						
							| 
									
										
										
										
											2009-11-04 14:05:12 +00:00
										 |  |  | 	} else if (frame->subclass.codec == AST_FORMAT_SLINEAR) { | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 		if (p->lastformat != AST_FORMAT_SLINEAR) { | 
					
						
							|  |  |  | 			ioctl(p->fd, PHONE_PLAY_STOP); | 
					
						
							|  |  |  | 			ioctl(p->fd, PHONE_REC_STOP); | 
					
						
							|  |  |  | 			if (ioctl(p->fd, PHONE_PLAY_CODEC, LINEAR16)) { | 
					
						
							|  |  |  | 				ast_log(LOG_WARNING, "Unable to set 16-bit linear mode\n"); | 
					
						
							|  |  |  | 				return -1; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (ioctl(p->fd, PHONE_REC_CODEC, LINEAR16)) { | 
					
						
							|  |  |  | 				ast_log(LOG_WARNING, "Unable to set 16-bit linear mode\n"); | 
					
						
							|  |  |  | 				return -1; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			p->lastformat = AST_FORMAT_SLINEAR; | 
					
						
							|  |  |  | 			p->lastinput = AST_FORMAT_SLINEAR; | 
					
						
							| 
									
										
										
										
											2000-12-14 13:50:41 +00:00
										 |  |  | 			codecset = 1; | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 			/* Reset output buffer */ | 
					
						
							|  |  |  | 			p->obuflen = 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		maxfr = 480; | 
					
						
							| 
									
										
										
										
											2009-11-04 14:05:12 +00:00
										 |  |  | 	} else if (frame->subclass.codec == AST_FORMAT_ULAW) { | 
					
						
							| 
									
										
										
										
											2001-08-23 17:57:10 +00:00
										 |  |  | 		if (p->lastformat != AST_FORMAT_ULAW) { | 
					
						
							|  |  |  | 			ioctl(p->fd, PHONE_PLAY_STOP); | 
					
						
							|  |  |  | 			ioctl(p->fd, PHONE_REC_STOP); | 
					
						
							|  |  |  | 			if (ioctl(p->fd, PHONE_PLAY_CODEC, ULAW)) { | 
					
						
							|  |  |  | 				ast_log(LOG_WARNING, "Unable to set uLaw mode\n"); | 
					
						
							|  |  |  | 				return -1; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (ioctl(p->fd, PHONE_REC_CODEC, ULAW)) { | 
					
						
							|  |  |  | 				ast_log(LOG_WARNING, "Unable to set uLaw mode\n"); | 
					
						
							|  |  |  | 				return -1; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			p->lastformat = AST_FORMAT_ULAW; | 
					
						
							|  |  |  | 			p->lastinput = AST_FORMAT_ULAW; | 
					
						
							|  |  |  | 			codecset = 1; | 
					
						
							|  |  |  | 			/* Reset output buffer */ | 
					
						
							|  |  |  | 			p->obuflen = 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		maxfr = 240; | 
					
						
							| 
									
										
										
										
											2004-12-31 00:16:30 +00:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2009-11-04 14:05:12 +00:00
										 |  |  | 		if (p->lastformat != frame->subclass.codec) { | 
					
						
							| 
									
										
										
										
											2004-12-31 00:16:30 +00:00
										 |  |  | 			ioctl(p->fd, PHONE_PLAY_STOP); | 
					
						
							|  |  |  | 			ioctl(p->fd, PHONE_REC_STOP); | 
					
						
							| 
									
										
										
										
											2009-11-04 14:05:12 +00:00
										 |  |  | 			if (ioctl(p->fd, PHONE_PLAY_CODEC, (int) frame->subclass.codec)) { | 
					
						
							|  |  |  | 				ast_log(LOG_WARNING, "Unable to set %s mode\n", | 
					
						
							|  |  |  | 					ast_getformatname(frame->subclass.codec)); | 
					
						
							| 
									
										
										
										
											2004-12-31 00:16:30 +00:00
										 |  |  | 				return -1; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-11-04 14:05:12 +00:00
										 |  |  | 			if (ioctl(p->fd, PHONE_REC_CODEC, (int) frame->subclass.codec)) { | 
					
						
							|  |  |  | 				ast_log(LOG_WARNING, "Unable to set %s mode\n", | 
					
						
							|  |  |  | 					ast_getformatname(frame->subclass.codec)); | 
					
						
							| 
									
										
										
										
											2004-12-31 00:16:30 +00:00
										 |  |  | 				return -1; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-11-04 14:05:12 +00:00
										 |  |  | 			p->lastformat = frame->subclass.codec; | 
					
						
							|  |  |  | 			p->lastinput = frame->subclass.codec; | 
					
						
							| 
									
										
										
										
											2004-12-31 00:16:30 +00:00
										 |  |  | 			codecset = 1; | 
					
						
							|  |  |  | 			/* Reset output buffer */ | 
					
						
							|  |  |  | 			p->obuflen = 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		maxfr = 480; | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2004-12-31 00:16:30 +00:00
										 |  |  |  	if (codecset) { | 
					
						
							| 
									
										
										
										
											2000-12-14 13:50:41 +00:00
										 |  |  | 		ioctl(p->fd, PHONE_REC_DEPTH, 3); | 
					
						
							|  |  |  | 		ioctl(p->fd, PHONE_PLAY_DEPTH, 3); | 
					
						
							|  |  |  | 		if (ioctl(p->fd, PHONE_PLAY_START)) { | 
					
						
							|  |  |  | 			ast_log(LOG_WARNING, "Failed to start playback\n"); | 
					
						
							|  |  |  | 			return -1; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (ioctl(p->fd, PHONE_REC_START)) { | 
					
						
							|  |  |  | 			ast_log(LOG_WARNING, "Failed to start recording\n"); | 
					
						
							|  |  |  | 			return -1; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2004-12-31 00:16:30 +00:00
										 |  |  | 	/* If we get here, we have a frame of Appropriate data */ | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	sofar = 0; | 
					
						
							| 
									
										
										
										
											2008-05-22 16:29:54 +00:00
										 |  |  | 	pos = frame->data.ptr; | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	while(sofar < frame->datalen) { | 
					
						
							|  |  |  | 		/* Write in no more than maxfr sized frames */ | 
					
						
							|  |  |  | 		expected = frame->datalen - sofar; | 
					
						
							|  |  |  | 		if (maxfr < expected) | 
					
						
							|  |  |  | 			expected = maxfr; | 
					
						
							|  |  |  | 		/* XXX Internet Phone Jack does not handle the 4-byte VAD frame properly! XXX 
 | 
					
						
							|  |  |  | 		   we have to pad it to 24 bytes still.  */ | 
					
						
							|  |  |  | 		if (frame->datalen == 4) { | 
					
						
							|  |  |  | 			if (p->silencesupression) { | 
					
						
							| 
									
										
										
										
											2008-05-22 16:29:54 +00:00
										 |  |  | 				memcpy(tmpbuf, frame->data.ptr, 4); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 				expected = 24; | 
					
						
							| 
									
										
										
										
											2005-04-03 22:57:18 +00:00
										 |  |  | 				res = phone_write_buf(p, tmpbuf, expected, maxfr, 0); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			res = 4; | 
					
						
							|  |  |  | 			expected=4; | 
					
						
							|  |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2005-04-03 22:57:18 +00:00
										 |  |  | 			int swap = 0; | 
					
						
							|  |  |  | #if __BYTE_ORDER == __BIG_ENDIAN
 | 
					
						
							| 
									
										
										
										
											2009-11-04 14:05:12 +00:00
										 |  |  | 			if (frame->subclass.codec == AST_FORMAT_SLINEAR) | 
					
						
							| 
									
										
										
										
											2005-04-03 22:57:18 +00:00
										 |  |  | 				swap = 1; /* Swap big-endian samples to little-endian as we copy */ | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 			res = phone_write_buf(p, pos, expected, maxfr, swap); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if (res != expected) { | 
					
						
							| 
									
										
										
										
											2003-04-07 19:14:24 +00:00
										 |  |  | 			if ((errno != EAGAIN) && (errno != EINTR)) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 				if (res < 0)  | 
					
						
							|  |  |  | 					ast_log(LOG_WARNING, "Write returned error (%s)\n", strerror(errno)); | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Card is in non-blocking mode now and it works well now, but there are | 
					
						
							|  |  |  | 	 * lot of messages like this. So, this message is temporarily disabled. | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2001-08-23 17:57:10 +00:00
										 |  |  | #if 0
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 				else | 
					
						
							|  |  |  | 					ast_log(LOG_WARNING, "Only wrote %d of %d bytes\n", res, frame->datalen); | 
					
						
							| 
									
										
										
										
											2001-08-23 17:57:10 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 				return -1; | 
					
						
							|  |  |  | 			} else /* Pretend it worked */ | 
					
						
							|  |  |  | 				res = expected; | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		sofar += res; | 
					
						
							|  |  |  | 		pos += res; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-26 15:28:53 +00:00
										 |  |  | static struct ast_channel *phone_new(struct phone_pvt *i, int state, char *cntx, const char *linkedid) | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct ast_channel *tmp; | 
					
						
							| 
									
										
										
										
											2008-08-09 12:53:57 +00:00
										 |  |  | 	struct phone_codec_data queried_codec; | 
					
						
							| 
									
										
										
										
											2009-06-26 15:28:53 +00:00
										 |  |  | 	tmp = ast_channel_alloc(1, state, i->cid_num, i->cid_name, "", i->ext, i->context, linkedid, 0, "Phone/%s", i->dev + 5); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	if (tmp) { | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 		tmp->tech = cur_tech; | 
					
						
							| 
									
										
										
										
											2007-08-08 21:44:58 +00:00
										 |  |  | 		ast_channel_set_fd(tmp, 0, i->fd); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 		/* XXX Switching formats silently causes kernel panics XXX */ | 
					
						
							| 
									
										
										
										
											2004-12-31 00:16:30 +00:00
										 |  |  | 		if (i->mode == MODE_FXS && | 
					
						
							| 
									
										
										
										
											2008-08-09 12:53:57 +00:00
										 |  |  | 		    ioctl(i->fd, PHONE_QUERY_CODEC, &queried_codec) == 0) { | 
					
						
							|  |  |  | 			if (queried_codec.type == LINEAR16) | 
					
						
							| 
									
										
										
										
											2004-12-31 00:16:30 +00:00
										 |  |  | 				tmp->nativeformats = | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 				tmp->rawreadformat = | 
					
						
							|  |  |  | 				tmp->rawwriteformat = | 
					
						
							| 
									
										
										
										
											2004-12-31 00:16:30 +00:00
										 |  |  | 				AST_FORMAT_SLINEAR; | 
					
						
							|  |  |  | 			else { | 
					
						
							|  |  |  | 				tmp->nativeformats = | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 				tmp->rawreadformat = | 
					
						
							|  |  |  | 				tmp->rawwriteformat = | 
					
						
							| 
									
										
										
										
											2004-12-31 00:16:30 +00:00
										 |  |  | 				prefformat & ~AST_FORMAT_SLINEAR; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else { | 
					
						
							|  |  |  | 			tmp->nativeformats = prefformat; | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 			tmp->rawreadformat = prefformat; | 
					
						
							|  |  |  | 			tmp->rawwriteformat = prefformat; | 
					
						
							| 
									
										
										
										
											2004-12-31 00:16:30 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2006-11-07 21:47:49 +00:00
										 |  |  | 		/* no need to call ast_setstate: the channel_alloc already did its job */ | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 		if (state == AST_STATE_RING) | 
					
						
							|  |  |  | 			tmp->rings = 1; | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 		tmp->tech_pvt = i; | 
					
						
							| 
									
										
										
										
											2008-08-09 12:53:57 +00:00
										 |  |  | 		ast_copy_string(tmp->context, cntx, sizeof(tmp->context)); | 
					
						
							| 
									
										
										
										
											2005-10-27 02:19:37 +00:00
										 |  |  | 		if (!ast_strlen_zero(i->ext)) | 
					
						
							| 
									
										
										
										
											2006-10-25 14:44:50 +00:00
										 |  |  | 			ast_copy_string(tmp->exten, i->ext, sizeof(tmp->exten)); | 
					
						
							| 
									
										
										
										
											2002-11-29 02:14:13 +00:00
										 |  |  | 		else | 
					
						
							| 
									
										
										
										
											2006-10-25 14:44:50 +00:00
										 |  |  | 			strcpy(tmp->exten, "s"); | 
					
						
							| 
									
										
										
										
											2005-10-27 02:19:37 +00:00
										 |  |  | 		if (!ast_strlen_zero(i->language)) | 
					
						
							| 
									
										
										
										
											2006-02-01 23:05:28 +00:00
										 |  |  | 			ast_string_field_set(tmp, language, i->language); | 
					
						
							| 
									
										
										
										
											2006-08-05 05:26:29 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/* Don't use ast_set_callerid() here because it will
 | 
					
						
							|  |  |  | 		 * generate a NewCallerID event before the NewChannel event */ | 
					
						
							| 
									
										
										
										
											2010-07-14 16:58:03 +00:00
										 |  |  | 		if (!ast_strlen_zero(i->cid_num)) { | 
					
						
							|  |  |  | 			tmp->caller.ani.number.valid = 1; | 
					
						
							|  |  |  | 			tmp->caller.ani.number.str = ast_strdup(i->cid_num); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2006-08-05 05:26:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 		i->owner = tmp; | 
					
						
							| 
									
										
										
										
											2007-01-23 22:59:55 +00:00
										 |  |  | 		ast_module_ref(ast_module_info->self); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 		if (state != AST_STATE_DOWN) { | 
					
						
							|  |  |  | 			if (state == AST_STATE_RING) { | 
					
						
							| 
									
										
										
										
											2001-05-04 16:41:16 +00:00
										 |  |  | 				ioctl(tmp->fds[0], PHONE_RINGBACK); | 
					
						
							| 
									
										
										
										
											2001-08-23 17:57:10 +00:00
										 |  |  | 				i->cpt = 1; | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			if (ast_pbx_start(tmp)) { | 
					
						
							|  |  |  | 				ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmp->name); | 
					
						
							|  |  |  | 				ast_hangup(tmp); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Unable to allocate channel structure\n"); | 
					
						
							|  |  |  | 	return tmp; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void phone_mini_packet(struct phone_pvt *i) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int res; | 
					
						
							|  |  |  | 	char buf[1024]; | 
					
						
							|  |  |  | 	/* Ignore stuff we read... */ | 
					
						
							|  |  |  | 	res = read(i->fd, buf, sizeof(buf)); | 
					
						
							|  |  |  | 	if (res < 1) { | 
					
						
							| 
									
										
										
										
											2004-06-12 16:48:12 +00:00
										 |  |  | 		ast_log(LOG_WARNING, "Read returned %d: %s\n", res, strerror(errno)); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void phone_check_exception(struct phone_pvt *i) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int offhook=0; | 
					
						
							|  |  |  | 	char digit[2] = {0 , 0}; | 
					
						
							|  |  |  | 	union telephony_exception phonee; | 
					
						
							|  |  |  | 	/* XXX Do something XXX */ | 
					
						
							|  |  |  | #if 0
 | 
					
						
							| 
									
										
										
										
											2007-06-14 19:39:12 +00:00
										 |  |  | 	ast_debug(1, "Exception!\n"); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 	phonee.bytes = ioctl(i->fd, PHONE_EXCEPTION); | 
					
						
							|  |  |  | 	if (phonee.bits.dtmf_ready)  { | 
					
						
							|  |  |  | 		digit[0] = ioctl(i->fd, PHONE_GET_DTMF_ASCII); | 
					
						
							| 
									
										
										
										
											2006-08-08 17:02:45 +00:00
										 |  |  | 		if (i->mode == MODE_DIALTONE || i->mode == MODE_FXS || i->mode == MODE_SIGMA) { | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 			ioctl(i->fd, PHONE_PLAY_STOP); | 
					
						
							|  |  |  | 			ioctl(i->fd, PHONE_REC_STOP); | 
					
						
							|  |  |  | 			ioctl(i->fd, PHONE_CPT_STOP); | 
					
						
							|  |  |  | 			i->dialtone = 0; | 
					
						
							|  |  |  | 			if (strlen(i->ext) < AST_MAX_EXTENSION - 1) | 
					
						
							| 
									
										
										
										
											2004-07-16 04:40:54 +00:00
										 |  |  | 				strncat(i->ext, digit, sizeof(i->ext) - strlen(i->ext) - 1); | 
					
						
							| 
									
										
										
										
											2004-12-31 00:16:30 +00:00
										 |  |  | 			if ((i->mode != MODE_FXS || | 
					
						
							|  |  |  | 			     !(phonee.bytes = ioctl(i->fd, PHONE_EXCEPTION)) || | 
					
						
							|  |  |  | 			     !phonee.bits.dtmf_ready) && | 
					
						
							|  |  |  | 			    ast_exists_extension(NULL, i->context, i->ext, 1, i->cid_num)) { | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 				/* It's a valid extension in its context, get moving! */ | 
					
						
							| 
									
										
										
										
											2009-06-26 15:28:53 +00:00
										 |  |  | 				phone_new(i, AST_STATE_RING, i->context, NULL); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 				/* No need to restart monitor, we are the monitor */ | 
					
						
							| 
									
										
										
										
											2004-10-02 00:58:31 +00:00
										 |  |  | 			} else if (!ast_canmatch_extension(NULL, i->context, i->ext, 1, i->cid_num)) { | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 				/* There is nothing in the specified extension that can match anymore.
 | 
					
						
							|  |  |  | 				   Try the default */ | 
					
						
							| 
									
										
										
										
											2004-10-02 00:58:31 +00:00
										 |  |  | 				if (ast_exists_extension(NULL, "default", i->ext, 1, i->cid_num)) { | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 					/* Check the default, too... */ | 
					
						
							| 
									
										
										
										
											2009-06-26 15:28:53 +00:00
										 |  |  | 					phone_new(i, AST_STATE_RING, "default", NULL); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 					/* XXX This should probably be justified better XXX */ | 
					
						
							| 
									
										
										
										
											2004-10-02 00:58:31 +00:00
										 |  |  | 				}  else if (!ast_canmatch_extension(NULL, "default", i->ext, 1, i->cid_num)) { | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 					/* It's not a valid extension, give a busy signal */ | 
					
						
							| 
									
										
										
										
											2007-06-14 19:39:12 +00:00
										 |  |  | 					ast_debug(1, "%s can't match anything in %s or default\n", i->ext, i->context); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 					ioctl(i->fd, PHONE_BUSY); | 
					
						
							| 
									
										
										
										
											2001-08-23 17:57:10 +00:00
										 |  |  | 					i->cpt = 1; | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | #if 0
 | 
					
						
							|  |  |  | 			ast_verbose("Extension is %s\n", i->ext); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (phonee.bits.hookstate) { | 
					
						
							|  |  |  | 		offhook = ioctl(i->fd, PHONE_HOOKSTATE); | 
					
						
							|  |  |  | 		if (offhook) { | 
					
						
							|  |  |  | 			if (i->mode == MODE_IMMEDIATE) { | 
					
						
							| 
									
										
										
										
											2009-06-26 15:28:53 +00:00
										 |  |  | 				phone_new(i, AST_STATE_RING, i->context, NULL); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 			} else if (i->mode == MODE_DIALTONE) { | 
					
						
							| 
									
										
										
										
											2007-01-23 22:59:55 +00:00
										 |  |  | 				ast_module_ref(ast_module_info->self); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 				/* Reset the extension */ | 
					
						
							|  |  |  | 				i->ext[0] = '\0'; | 
					
						
							|  |  |  | 				/* Play the dialtone */ | 
					
						
							|  |  |  | 				i->dialtone++; | 
					
						
							|  |  |  | 				ioctl(i->fd, PHONE_PLAY_STOP); | 
					
						
							|  |  |  | 				ioctl(i->fd, PHONE_PLAY_CODEC, ULAW); | 
					
						
							|  |  |  | 				ioctl(i->fd, PHONE_PLAY_START); | 
					
						
							| 
									
										
										
										
											2000-12-28 19:21:06 +00:00
										 |  |  | 				i->lastformat = -1; | 
					
						
							| 
									
										
										
										
											2006-08-08 17:02:45 +00:00
										 |  |  | 			} else if (i->mode == MODE_SIGMA) { | 
					
						
							| 
									
										
										
										
											2007-01-23 22:59:55 +00:00
										 |  |  | 				ast_module_ref(ast_module_info->self); | 
					
						
							| 
									
										
										
										
											2006-08-08 17:02:45 +00:00
										 |  |  | 				/* Reset the extension */ | 
					
						
							|  |  |  | 				i->ext[0] = '\0'; | 
					
						
							|  |  |  | 				/* Play the dialtone */ | 
					
						
							|  |  |  | 				i->dialtone++; | 
					
						
							|  |  |  | 				ioctl(i->fd, PHONE_DIALTONE); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2007-01-23 22:59:55 +00:00
										 |  |  | 			if (i->dialtone) | 
					
						
							|  |  |  | 				ast_module_unref(ast_module_info->self); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 			memset(i->ext, 0, sizeof(i->ext)); | 
					
						
							| 
									
										
										
										
											2001-08-23 17:57:10 +00:00
										 |  |  | 			if (i->cpt) | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				ioctl(i->fd, PHONE_CPT_STOP); | 
					
						
							|  |  |  | 				i->cpt = 0; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 			ioctl(i->fd, PHONE_PLAY_STOP); | 
					
						
							|  |  |  | 			ioctl(i->fd, PHONE_REC_STOP); | 
					
						
							|  |  |  | 			i->dialtone = 0; | 
					
						
							| 
									
										
										
										
											2000-12-28 19:21:06 +00:00
										 |  |  | 			i->lastformat = -1; | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2000-10-25 23:22:50 +00:00
										 |  |  | 	if (phonee.bits.pstn_ring) { | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 		ast_verbose("Unit is ringing\n"); | 
					
						
							| 
									
										
										
										
											2009-06-26 15:28:53 +00:00
										 |  |  | 		phone_new(i, AST_STATE_RING, i->context, NULL); | 
					
						
							| 
									
										
										
										
											2000-10-25 23:22:50 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	if (phonee.bits.caller_id) | 
					
						
							|  |  |  | 		ast_verbose("We have caller ID\n"); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void *do_monitor(void *data) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-09-02 05:00:34 +00:00
										 |  |  | 	struct pollfd *fds = NULL; | 
					
						
							|  |  |  | 	int nfds = 0, inuse_fds = 0, res; | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	struct phone_pvt *i; | 
					
						
							|  |  |  | 	int tonepos = 0; | 
					
						
							|  |  |  | 	/* The tone we're playing this round */ | 
					
						
							| 
									
										
										
										
											2010-09-02 05:00:34 +00:00
										 |  |  | 	struct timeval tv = { 0, 0 }; | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	int dotone; | 
					
						
							|  |  |  | 	/* This thread monitors all the frame relay interfaces which are not yet in use
 | 
					
						
							|  |  |  | 	   (and thus do not have a separate thread) indefinitely */ | 
					
						
							| 
									
										
										
										
											2006-03-06 21:16:25 +00:00
										 |  |  | 	while (monitor) { | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 		/* Don't let anybody kill us right away.  Nobody should lock the interface list
 | 
					
						
							|  |  |  | 		   and wait for the monitor list, but the other way around is okay. */ | 
					
						
							|  |  |  | 		/* Lock the interface list */ | 
					
						
							| 
									
										
										
										
											2003-08-13 15:25:16 +00:00
										 |  |  | 		if (ast_mutex_lock(&iflock)) { | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 			ast_log(LOG_ERROR, "Unable to grab interface lock\n"); | 
					
						
							|  |  |  | 			return NULL; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		/* Build the stuff we're going to select on, that is the socket of every
 | 
					
						
							|  |  |  | 		   phone_pvt that does not have an associated owner channel */ | 
					
						
							|  |  |  | 		i = iflist; | 
					
						
							|  |  |  | 		dotone = 0; | 
					
						
							| 
									
										
										
										
											2010-09-02 05:00:34 +00:00
										 |  |  | 		inuse_fds = 0; | 
					
						
							|  |  |  | 		for (i = iflist; i; i = i->next) { | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 			if (!i->owner) { | 
					
						
							|  |  |  | 				/* This needs to be watched, as it lacks an owner */ | 
					
						
							| 
									
										
										
										
											2010-09-02 05:00:34 +00:00
										 |  |  | 				if (inuse_fds == nfds) { | 
					
						
							|  |  |  | 					void *tmp = ast_realloc(fds, (nfds + 1) * sizeof(*fds)); | 
					
						
							|  |  |  | 					if (!tmp) { | 
					
						
							|  |  |  | 						/* Avoid leaking */ | 
					
						
							|  |  |  | 						continue; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					fds = tmp; | 
					
						
							|  |  |  | 					nfds++; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				fds[inuse_fds].fd = i->fd; | 
					
						
							|  |  |  | 				fds[inuse_fds].events = POLLIN | POLLERR; | 
					
						
							|  |  |  | 				fds[inuse_fds].revents = 0; | 
					
						
							|  |  |  | 				inuse_fds++; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-08 17:02:45 +00:00
										 |  |  | 				if (i->dialtone && i->mode != MODE_SIGMA) { | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 					/* Remember we're going to have to come back and play
 | 
					
						
							|  |  |  | 					   more dialtones */ | 
					
						
							| 
									
										
										
										
											2010-09-02 05:00:34 +00:00
										 |  |  | 					if (ast_tvzero(tv)) { | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 						/* If we're due for a dialtone, play one */ | 
					
						
							| 
									
										
										
										
											2010-09-02 05:00:34 +00:00
										 |  |  | 						if (write(i->fd, DialTone + tonepos, 240) != 240) { | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 							ast_log(LOG_WARNING, "Dial tone write error\n"); | 
					
						
							| 
									
										
										
										
											2010-09-02 05:00:34 +00:00
										 |  |  | 						} | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 					} | 
					
						
							|  |  |  | 					dotone++; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		/* Okay, now that we know what to do, release the interface lock */ | 
					
						
							| 
									
										
										
										
											2003-08-13 15:25:16 +00:00
										 |  |  | 		ast_mutex_unlock(&iflock); | 
					
						
							| 
									
										
										
										
											2004-12-31 00:16:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 		/* Wait indefinitely for something to happen */ | 
					
						
							| 
									
										
										
										
											2007-07-11 14:10:38 +00:00
										 |  |  | 		if (dotone && i && i->mode != MODE_SIGMA) { | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 			/* If we're ready to recycle the time, set it to 30 ms */ | 
					
						
							|  |  |  | 			tonepos += 240; | 
					
						
							| 
									
										
										
										
											2010-09-02 05:00:34 +00:00
										 |  |  | 			if (tonepos >= sizeof(DialTone)) { | 
					
						
							|  |  |  | 				tonepos = 0; | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2010-09-02 05:00:34 +00:00
										 |  |  | 			if (ast_tvzero(tv)) { | 
					
						
							|  |  |  | 				tv = ast_tv(0, 30000); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			res = ast_poll2(fds, inuse_fds, &tv); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2010-09-02 05:00:34 +00:00
										 |  |  | 			res = ast_poll(fds, inuse_fds, -1); | 
					
						
							|  |  |  | 			tv = ast_tv(0, 0); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 			tonepos = 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		/* Okay, select has finished.  Let's see what happened.  */ | 
					
						
							|  |  |  | 		if (res < 0) { | 
					
						
							| 
									
										
										
										
											2010-09-02 05:00:34 +00:00
										 |  |  | 			ast_debug(1, "poll returned %d: %s\n", res, strerror(errno)); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		/* If there are no fd's changed, just continue, it's probably time
 | 
					
						
							|  |  |  | 		   to play some more dialtones */ | 
					
						
							| 
									
										
										
										
											2010-09-02 05:00:34 +00:00
										 |  |  | 		if (!res) { | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 			continue; | 
					
						
							| 
									
										
										
										
											2010-09-02 05:00:34 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 		/* Alright, lock the interface list again, and let's look and see what has
 | 
					
						
							|  |  |  | 		   happened */ | 
					
						
							| 
									
										
										
										
											2003-08-13 15:25:16 +00:00
										 |  |  | 		if (ast_mutex_lock(&iflock)) { | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 			ast_log(LOG_WARNING, "Unable to lock the interface list\n"); | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2004-12-31 00:16:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-02 05:00:34 +00:00
										 |  |  | 		for (i = iflist; i; i = i->next) { | 
					
						
							|  |  |  | 			int j; | 
					
						
							|  |  |  | 			/* Find the record */ | 
					
						
							|  |  |  | 			for (j = 0; j < inuse_fds; j++) { | 
					
						
							|  |  |  | 				if (fds[j].fd == i->fd) { | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			/* Not found? */ | 
					
						
							|  |  |  | 			if (j == inuse_fds) { | 
					
						
							|  |  |  | 				continue; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (fds[j].revents & POLLIN) { | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 				if (i->owner) { | 
					
						
							|  |  |  | 					continue; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				phone_mini_packet(i); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2010-09-02 05:00:34 +00:00
										 |  |  | 			if (fds[j].revents & POLLERR) { | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 				if (i->owner) { | 
					
						
							|  |  |  | 					continue; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				phone_check_exception(i); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2003-08-13 15:25:16 +00:00
										 |  |  | 		ast_mutex_unlock(&iflock); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int restart_monitor() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* If we're supposed to be stopped -- stay stopped */ | 
					
						
							| 
									
										
										
										
											2004-03-15 07:51:22 +00:00
										 |  |  | 	if (monitor_thread == AST_PTHREADT_STOP) | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 		return 0; | 
					
						
							| 
									
										
										
										
											2003-08-13 15:25:16 +00:00
										 |  |  | 	if (ast_mutex_lock(&monlock)) { | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 		ast_log(LOG_WARNING, "Unable to lock monitor\n"); | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (monitor_thread == pthread_self()) { | 
					
						
							| 
									
										
										
										
											2003-08-13 15:25:16 +00:00
										 |  |  | 		ast_mutex_unlock(&monlock); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 		ast_log(LOG_WARNING, "Cannot kill myself\n"); | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2004-03-15 07:51:22 +00:00
										 |  |  | 	if (monitor_thread != AST_PTHREADT_NULL) { | 
					
						
							| 
									
										
										
										
											2004-12-31 00:16:30 +00:00
										 |  |  | 		if (ast_mutex_lock(&iflock)) { | 
					
						
							| 
									
										
										
										
											2006-03-06 21:16:25 +00:00
										 |  |  | 			ast_mutex_unlock(&monlock); | 
					
						
							|  |  |  | 			ast_log(LOG_WARNING, "Unable to lock the interface list\n"); | 
					
						
							|  |  |  | 			return -1; | 
					
						
							| 
									
										
										
										
											2004-12-31 00:16:30 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2006-03-06 21:16:25 +00:00
										 |  |  | 		monitor = 0; | 
					
						
							|  |  |  | 		while (pthread_kill(monitor_thread, SIGURG) == 0) | 
					
						
							|  |  |  | 			sched_yield(); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 		pthread_join(monitor_thread, NULL); | 
					
						
							| 
									
										
										
										
											2004-12-31 00:16:30 +00:00
										 |  |  | 		ast_mutex_unlock(&iflock); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-03-06 21:16:25 +00:00
										 |  |  | 	monitor = 1; | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	/* Start a new monitor */ | 
					
						
							| 
									
										
										
										
											2006-10-04 19:51:38 +00:00
										 |  |  | 	if (ast_pthread_create_background(&monitor_thread, NULL, do_monitor, NULL) < 0) { | 
					
						
							| 
									
										
										
										
											2003-08-13 15:25:16 +00:00
										 |  |  | 		ast_mutex_unlock(&monlock); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 		ast_log(LOG_ERROR, "Unable to start monitor thread.\n"); | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-08-13 15:25:16 +00:00
										 |  |  | 	ast_mutex_unlock(&monlock); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-14 15:13:22 +00:00
										 |  |  | static struct phone_pvt *mkif(const char *iface, int mode, int txgain, int rxgain) | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	/* Make a phone_pvt structure for this interface */ | 
					
						
							|  |  |  | 	struct phone_pvt *tmp; | 
					
						
							|  |  |  | 	int flags;	 | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2007-06-03 06:10:27 +00:00
										 |  |  | 	tmp = ast_calloc(1, sizeof(*tmp)); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	if (tmp) { | 
					
						
							|  |  |  | 		tmp->fd = open(iface, O_RDWR); | 
					
						
							|  |  |  | 		if (tmp->fd < 0) { | 
					
						
							|  |  |  | 			ast_log(LOG_WARNING, "Unable to open '%s'\n", iface); | 
					
						
							| 
									
										
										
										
											2007-06-03 06:10:27 +00:00
										 |  |  | 			ast_free(tmp); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 			return NULL; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2000-10-25 23:22:50 +00:00
										 |  |  | 		if (mode == MODE_FXO) { | 
					
						
							| 
									
										
										
										
											2006-10-03 15:53:07 +00:00
										 |  |  | 			if (ioctl(tmp->fd, IXJCTL_PORT, PORT_PSTN)) { | 
					
						
							| 
									
										
										
										
											2007-06-14 19:39:12 +00:00
										 |  |  | 				ast_debug(1, "Unable to set port to PSTN\n"); | 
					
						
							| 
									
										
										
										
											2006-10-03 15:53:07 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2001-08-23 17:57:10 +00:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			if (ioctl(tmp->fd, IXJCTL_PORT, PORT_POTS))  | 
					
						
							| 
									
										
										
										
											2004-12-31 00:16:30 +00:00
										 |  |  | 				 if (mode != MODE_FXS) | 
					
						
							| 
									
										
										
										
											2007-06-14 19:39:12 +00:00
										 |  |  | 				      ast_debug(1, "Unable to set port to POTS\n"); | 
					
						
							| 
									
										
										
										
											2000-10-25 23:22:50 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 		ioctl(tmp->fd, PHONE_PLAY_STOP); | 
					
						
							|  |  |  | 		ioctl(tmp->fd, PHONE_REC_STOP); | 
					
						
							|  |  |  | 		ioctl(tmp->fd, PHONE_RING_STOP); | 
					
						
							|  |  |  | 		ioctl(tmp->fd, PHONE_CPT_STOP); | 
					
						
							| 
									
										
										
										
											2007-06-14 19:39:12 +00:00
										 |  |  | 		if (ioctl(tmp->fd, PHONE_PSTN_SET_STATE, PSTN_ON_HOOK)) | 
					
						
							|  |  |  | 			ast_debug(1, "ioctl(PHONE_PSTN_SET_STATE) failed on %s (%s)\n",iface, strerror(errno)); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 		if (echocancel != AEC_OFF) | 
					
						
							|  |  |  | 			ioctl(tmp->fd, IXJCTL_AEC_START, echocancel); | 
					
						
							|  |  |  | 		if (silencesupression)  | 
					
						
							|  |  |  | 			tmp->silencesupression = 1; | 
					
						
							| 
									
										
										
										
											2000-05-02 19:18:58 +00:00
										 |  |  | #ifdef PHONE_VAD
 | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 		ioctl(tmp->fd, PHONE_VAD, tmp->silencesupression); | 
					
						
							| 
									
										
										
										
											2000-05-02 19:18:58 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 		tmp->mode = mode; | 
					
						
							|  |  |  | 		flags = fcntl(tmp->fd, F_GETFL); | 
					
						
							|  |  |  | 		fcntl(tmp->fd, F_SETFL, flags | O_NONBLOCK); | 
					
						
							|  |  |  | 		tmp->owner = NULL; | 
					
						
							|  |  |  | 		tmp->lastformat = -1; | 
					
						
							|  |  |  | 		tmp->lastinput = -1; | 
					
						
							|  |  |  | 		tmp->ministate = 0; | 
					
						
							|  |  |  | 		memset(tmp->ext, 0, sizeof(tmp->ext)); | 
					
						
							| 
									
										
										
										
											2006-10-25 14:44:50 +00:00
										 |  |  | 		ast_copy_string(tmp->language, language, sizeof(tmp->language)); | 
					
						
							|  |  |  | 		ast_copy_string(tmp->dev, iface, sizeof(tmp->dev)); | 
					
						
							|  |  |  | 		ast_copy_string(tmp->context, context, sizeof(tmp->context)); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 		tmp->next = NULL; | 
					
						
							|  |  |  | 		tmp->obuflen = 0; | 
					
						
							|  |  |  | 		tmp->dialtone = 0; | 
					
						
							| 
									
										
										
										
											2001-08-23 17:57:10 +00:00
										 |  |  | 		tmp->cpt = 0; | 
					
						
							| 
									
										
										
										
											2006-10-25 14:44:50 +00:00
										 |  |  | 		ast_copy_string(tmp->cid_num, cid_num, sizeof(tmp->cid_num)); | 
					
						
							|  |  |  | 		ast_copy_string(tmp->cid_name, cid_name, sizeof(tmp->cid_name)); | 
					
						
							| 
									
										
										
										
											2001-08-23 17:57:10 +00:00
										 |  |  | 		tmp->txgain = txgain; | 
					
						
							|  |  |  | 		ioctl(tmp->fd, PHONE_PLAY_VOLUME, tmp->txgain); | 
					
						
							|  |  |  | 		tmp->rxgain = rxgain; | 
					
						
							|  |  |  | 		ioctl(tmp->fd, PHONE_REC_VOLUME, tmp->rxgain); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return tmp; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-04 14:05:12 +00:00
										 |  |  | static struct ast_channel *phone_request(const char *type, format_t format, const struct ast_channel *requestor, void *data, int *cause) | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-11-04 14:05:12 +00:00
										 |  |  | 	format_t oldformat; | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	struct phone_pvt *p; | 
					
						
							|  |  |  | 	struct ast_channel *tmp = NULL; | 
					
						
							|  |  |  | 	char *name = data; | 
					
						
							| 
									
										
										
										
											2004-12-31 00:16:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	/* Search for an unowned channel */ | 
					
						
							| 
									
										
										
										
											2003-08-13 15:25:16 +00:00
										 |  |  | 	if (ast_mutex_lock(&iflock)) { | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 		ast_log(LOG_ERROR, "Unable to lock interface list???\n"); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	p = iflist; | 
					
						
							|  |  |  | 	while(p) { | 
					
						
							| 
									
										
										
										
											2004-12-31 00:16:30 +00:00
										 |  |  | 		if (p->mode == MODE_FXS || | 
					
						
							| 
									
										
										
										
											2007-01-16 17:23:31 +00:00
										 |  |  | 		    format & (AST_FORMAT_G729A | AST_FORMAT_G723_1 | AST_FORMAT_SLINEAR | AST_FORMAT_ULAW)) { | 
					
						
							| 
									
										
										
										
											2004-12-31 00:16:30 +00:00
										 |  |  | 		    size_t length = strlen(p->dev + 5); | 
					
						
							|  |  |  |     		if (strncmp(name, p->dev + 5, length) == 0 && | 
					
						
							|  |  |  |     		    !isalnum(name[length])) { | 
					
						
							|  |  |  |     		    if (!p->owner) { | 
					
						
							| 
									
										
										
										
											2009-06-26 15:28:53 +00:00
										 |  |  |                      tmp = phone_new(p, AST_STATE_DOWN, p->context, requestor ? requestor->linkedid : NULL); | 
					
						
							| 
									
										
										
										
											2004-12-31 00:16:30 +00:00
										 |  |  |                      break; | 
					
						
							|  |  |  |                 } else | 
					
						
							|  |  |  |                      *cause = AST_CAUSE_BUSY; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		p = p->next; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-08-13 15:25:16 +00:00
										 |  |  | 	ast_mutex_unlock(&iflock); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	restart_monitor(); | 
					
						
							| 
									
										
										
										
											2004-12-31 00:16:30 +00:00
										 |  |  | 	if (tmp == NULL) { | 
					
						
							|  |  |  | 		oldformat = format; | 
					
						
							| 
									
										
										
										
											2007-01-16 17:23:31 +00:00
										 |  |  | 		format &= (AST_FORMAT_G729A | AST_FORMAT_G723_1 | AST_FORMAT_SLINEAR | AST_FORMAT_ULAW); | 
					
						
							| 
									
										
										
										
											2004-12-31 00:16:30 +00:00
										 |  |  | 		if (!format) { | 
					
						
							| 
									
										
										
										
											2009-11-04 14:05:12 +00:00
										 |  |  | 			char buf[256]; | 
					
						
							|  |  |  | 			ast_log(LOG_NOTICE, "Asked to get a channel of unsupported format '%s'\n", ast_getformatname_multiple(buf, sizeof(buf), oldformat)); | 
					
						
							| 
									
										
										
										
											2004-12-31 00:16:30 +00:00
										 |  |  | 			return NULL; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	return tmp; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-08-23 17:57:10 +00:00
										 |  |  | /* parse gain value from config file */ | 
					
						
							| 
									
										
										
										
											2007-11-14 15:13:22 +00:00
										 |  |  | static int parse_gain_value(const char *gain_type, const char *value) | 
					
						
							| 
									
										
										
										
											2001-08-23 17:57:10 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	float gain; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* try to scan number */ | 
					
						
							| 
									
										
										
										
											2009-08-10 19:20:57 +00:00
										 |  |  | 	if (sscanf(value, "%30f", &gain) != 1) | 
					
						
							| 
									
										
										
										
											2001-08-23 17:57:10 +00:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		ast_log(LOG_ERROR, "Invalid %s value '%s' in '%s' config\n", | 
					
						
							|  |  |  | 			value, gain_type, config); | 
					
						
							|  |  |  | 		return DEFAULT_GAIN; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* multiplicate gain by 1.0 gain value */  | 
					
						
							|  |  |  | 	gain = gain * (float)DEFAULT_GAIN; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* percentage? */ | 
					
						
							|  |  |  | 	if (value[strlen(value) - 1] == '%') | 
					
						
							|  |  |  | 		return (int)(gain / (float)100); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return (int)gain; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-12-09 23:55:17 +00:00
										 |  |  | static int __unload_module(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct phone_pvt *p, *pl; | 
					
						
							|  |  |  | 	/* First, take us out of the channel loop */ | 
					
						
							| 
									
										
										
										
											2007-09-05 15:16:50 +00:00
										 |  |  | 	if (cur_tech) | 
					
						
							|  |  |  | 		ast_channel_unregister(cur_tech); | 
					
						
							| 
									
										
										
										
											2003-12-09 23:55:17 +00:00
										 |  |  | 	if (!ast_mutex_lock(&iflock)) { | 
					
						
							|  |  |  | 		/* Hangup all interfaces if they have an owner */ | 
					
						
							|  |  |  | 		p = iflist; | 
					
						
							|  |  |  | 		while(p) { | 
					
						
							|  |  |  | 			if (p->owner) | 
					
						
							|  |  |  | 				ast_softhangup(p->owner, AST_SOFTHANGUP_APPUNLOAD); | 
					
						
							|  |  |  | 			p = p->next; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		iflist = NULL; | 
					
						
							|  |  |  | 		ast_mutex_unlock(&iflock); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Unable to lock the monitor\n"); | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (!ast_mutex_lock(&monlock)) { | 
					
						
							| 
									
										
										
										
											2004-03-15 07:51:22 +00:00
										 |  |  | 		if (monitor_thread > AST_PTHREADT_NULL) { | 
					
						
							| 
									
										
										
										
											2006-03-06 21:16:25 +00:00
										 |  |  | 			monitor = 0; | 
					
						
							|  |  |  | 			while (pthread_kill(monitor_thread, SIGURG) == 0) | 
					
						
							|  |  |  | 				sched_yield(); | 
					
						
							| 
									
										
										
										
											2003-12-09 23:55:17 +00:00
										 |  |  | 			pthread_join(monitor_thread, NULL); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2004-03-15 07:51:22 +00:00
										 |  |  | 		monitor_thread = AST_PTHREADT_STOP; | 
					
						
							| 
									
										
										
										
											2003-12-09 23:55:17 +00:00
										 |  |  | 		ast_mutex_unlock(&monlock); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Unable to lock the monitor\n"); | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!ast_mutex_lock(&iflock)) { | 
					
						
							|  |  |  | 		/* Destroy all the interfaces and free their memory */ | 
					
						
							|  |  |  | 		p = iflist; | 
					
						
							|  |  |  | 		while(p) { | 
					
						
							|  |  |  | 			/* Close the socket, assuming it's real */ | 
					
						
							|  |  |  | 			if (p->fd > -1) | 
					
						
							|  |  |  | 				close(p->fd); | 
					
						
							|  |  |  | 			pl = p; | 
					
						
							|  |  |  | 			p = p->next; | 
					
						
							|  |  |  | 			/* Free associated memory */ | 
					
						
							| 
									
										
										
										
											2007-06-03 06:10:27 +00:00
										 |  |  | 			ast_free(pl); | 
					
						
							| 
									
										
										
										
											2003-12-09 23:55:17 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		iflist = NULL; | 
					
						
							|  |  |  | 		ast_mutex_unlock(&iflock); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Unable to lock the monitor\n"); | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int unload_module(void) | 
					
						
							| 
									
										
										
										
											2003-12-09 23:55:17 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	return __unload_module(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int load_module(void) | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct ast_config *cfg; | 
					
						
							|  |  |  | 	struct ast_variable *v; | 
					
						
							|  |  |  | 	struct phone_pvt *tmp; | 
					
						
							|  |  |  | 	int mode = MODE_IMMEDIATE; | 
					
						
							| 
									
										
										
										
											2001-08-23 17:57:10 +00:00
										 |  |  | 	int txgain = DEFAULT_GAIN, rxgain = DEFAULT_GAIN; /* default gain 1.0 */ | 
					
						
							| 
									
										
										
										
											2007-08-16 21:09:46 +00:00
										 |  |  | 	struct ast_flags config_flags = { 0 }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-12 23:30:03 +00:00
										 |  |  | 	if ((cfg = ast_config_load(config, config_flags)) == CONFIG_STATUS_FILEINVALID) { | 
					
						
							|  |  |  | 		ast_log(LOG_ERROR, "Config file %s is in an invalid format.  Aborting.\n", config); | 
					
						
							|  |  |  | 		return AST_MODULE_LOAD_DECLINE; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* We *must* have a config file otherwise stop immediately */ | 
					
						
							|  |  |  | 	if (!cfg) { | 
					
						
							|  |  |  | 		ast_log(LOG_ERROR, "Unable to load config %s\n", config); | 
					
						
							| 
									
										
										
										
											2006-08-31 21:00:20 +00:00
										 |  |  | 		return AST_MODULE_LOAD_DECLINE; | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-08-13 15:25:16 +00:00
										 |  |  | 	if (ast_mutex_lock(&iflock)) { | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 		/* It's a little silly to lock it, but we mind as well just to be sure */ | 
					
						
							|  |  |  | 		ast_log(LOG_ERROR, "Unable to lock interface list???\n"); | 
					
						
							| 
									
										
										
										
											2007-09-05 15:16:50 +00:00
										 |  |  | 		return AST_MODULE_LOAD_FAILURE; | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	v = ast_variable_browse(cfg, "interfaces"); | 
					
						
							|  |  |  | 	while(v) { | 
					
						
							|  |  |  | 		/* Create the interface list */ | 
					
						
							|  |  |  | 		if (!strcasecmp(v->name, "device")) { | 
					
						
							| 
									
										
										
										
											2001-08-23 17:57:10 +00:00
										 |  |  | 				tmp = mkif(v->value, mode, txgain, rxgain); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 				if (tmp) { | 
					
						
							|  |  |  | 					tmp->next = iflist; | 
					
						
							|  |  |  | 					iflist = tmp; | 
					
						
							|  |  |  | 					 | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					ast_log(LOG_ERROR, "Unable to register channel '%s'\n", v->value); | 
					
						
							| 
									
										
										
										
											2005-01-25 06:10:20 +00:00
										 |  |  | 					ast_config_destroy(cfg); | 
					
						
							| 
									
										
										
										
											2003-08-13 15:25:16 +00:00
										 |  |  | 					ast_mutex_unlock(&iflock); | 
					
						
							| 
									
										
										
										
											2003-12-09 23:55:17 +00:00
										 |  |  | 					__unload_module(); | 
					
						
							| 
									
										
										
										
											2007-09-05 15:16:50 +00:00
										 |  |  | 					return AST_MODULE_LOAD_FAILURE; | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 		} else if (!strcasecmp(v->name, "silencesupression")) { | 
					
						
							|  |  |  | 			silencesupression = ast_true(v->value); | 
					
						
							| 
									
										
										
										
											2000-05-02 19:18:58 +00:00
										 |  |  | 		} else if (!strcasecmp(v->name, "language")) { | 
					
						
							| 
									
										
										
										
											2006-10-25 14:44:50 +00:00
										 |  |  | 			ast_copy_string(language, v->value, sizeof(language)); | 
					
						
							| 
									
										
										
										
											2001-08-23 17:57:10 +00:00
										 |  |  | 		} else if (!strcasecmp(v->name, "callerid")) { | 
					
						
							| 
									
										
										
										
											2004-10-02 00:58:31 +00:00
										 |  |  | 			ast_callerid_split(v->value, cid_name, sizeof(cid_name), cid_num, sizeof(cid_num)); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 		} else if (!strcasecmp(v->name, "mode")) { | 
					
						
							|  |  |  | 			if (!strncasecmp(v->value, "di", 2))  | 
					
						
							|  |  |  | 				mode = MODE_DIALTONE; | 
					
						
							| 
									
										
										
										
											2006-08-08 17:02:45 +00:00
										 |  |  | 			else if (!strncasecmp(v->value, "sig", 3)) | 
					
						
							|  |  |  | 				mode = MODE_SIGMA; | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 			else if (!strncasecmp(v->value, "im", 2)) | 
					
						
							|  |  |  | 				mode = MODE_IMMEDIATE; | 
					
						
							| 
									
										
										
										
											2004-12-31 00:16:30 +00:00
										 |  |  | 			else if (!strncasecmp(v->value, "fxs", 3)) { | 
					
						
							|  |  |  | 				mode = MODE_FXS; | 
					
						
							|  |  |  | 				prefformat = 0x01ff0000; /* All non-voice */ | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2000-10-25 23:22:50 +00:00
										 |  |  | 			else if (!strncasecmp(v->value, "fx", 2)) | 
					
						
							|  |  |  | 				mode = MODE_FXO; | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 			else | 
					
						
							|  |  |  | 				ast_log(LOG_WARNING, "Unknown mode: %s\n", v->value); | 
					
						
							|  |  |  | 		} else if (!strcasecmp(v->name, "context")) { | 
					
						
							| 
									
										
										
										
											2006-10-25 14:44:50 +00:00
										 |  |  | 			ast_copy_string(context, v->value, sizeof(context)); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 		} else if (!strcasecmp(v->name, "format")) { | 
					
						
							| 
									
										
										
										
											2007-01-16 17:23:31 +00:00
										 |  |  | 			if (!strcasecmp(v->value, "g729")) { | 
					
						
							|  |  |  | 				prefformat = AST_FORMAT_G729A; | 
					
						
							|  |  |  |                         } else if (!strcasecmp(v->value, "g723.1")) { | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 				prefformat = AST_FORMAT_G723_1; | 
					
						
							|  |  |  | 			} else if (!strcasecmp(v->value, "slinear")) { | 
					
						
							| 
									
										
										
										
											2004-12-31 00:16:30 +00:00
										 |  |  | 				if (mode == MODE_FXS) | 
					
						
							|  |  |  | 				    prefformat |= AST_FORMAT_SLINEAR; | 
					
						
							|  |  |  | 				else prefformat = AST_FORMAT_SLINEAR; | 
					
						
							| 
									
										
										
										
											2001-05-04 16:41:16 +00:00
										 |  |  | 			} else if (!strcasecmp(v->value, "ulaw")) { | 
					
						
							|  |  |  | 				prefformat = AST_FORMAT_ULAW; | 
					
						
							|  |  |  | 			} else | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 				ast_log(LOG_WARNING, "Unknown format '%s'\n", v->value); | 
					
						
							|  |  |  | 		} else if (!strcasecmp(v->name, "echocancel")) { | 
					
						
							|  |  |  | 			if (!strcasecmp(v->value, "off")) { | 
					
						
							|  |  |  | 				echocancel = AEC_OFF; | 
					
						
							|  |  |  | 			} else if (!strcasecmp(v->value, "low")) { | 
					
						
							|  |  |  | 				echocancel = AEC_LOW; | 
					
						
							|  |  |  | 			} else if (!strcasecmp(v->value, "medium")) { | 
					
						
							|  |  |  | 				echocancel = AEC_MED; | 
					
						
							|  |  |  | 			} else if (!strcasecmp(v->value, "high")) { | 
					
						
							|  |  |  | 				echocancel = AEC_HIGH; | 
					
						
							|  |  |  | 			} else  | 
					
						
							|  |  |  | 				ast_log(LOG_WARNING, "Unknown echo cancellation '%s'\n", v->value); | 
					
						
							| 
									
										
										
										
											2001-08-23 17:57:10 +00:00
										 |  |  | 		} else if (!strcasecmp(v->name, "txgain")) { | 
					
						
							|  |  |  | 			txgain = parse_gain_value(v->name, v->value); | 
					
						
							|  |  |  | 		} else if (!strcasecmp(v->name, "rxgain")) { | 
					
						
							|  |  |  | 			rxgain = parse_gain_value(v->name, v->value); | 
					
						
							|  |  |  | 		}	 | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 		v = v->next; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-08-13 15:25:16 +00:00
										 |  |  | 	ast_mutex_unlock(&iflock); | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (mode == MODE_FXS) { | 
					
						
							|  |  |  | 		phone_tech_fxs.capabilities = prefformat; | 
					
						
							|  |  |  | 		cur_tech = &phone_tech_fxs; | 
					
						
							|  |  |  | 	} else | 
					
						
							|  |  |  | 		cur_tech = (struct ast_channel_tech *) &phone_tech; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	/* Make sure we can register our Adtranphone channel type */ | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (ast_channel_register(cur_tech)) { | 
					
						
							| 
									
										
										
										
											2006-02-01 23:05:28 +00:00
										 |  |  | 		ast_log(LOG_ERROR, "Unable to register channel class 'Phone'\n"); | 
					
						
							| 
									
										
										
										
											2005-01-25 06:10:20 +00:00
										 |  |  | 		ast_config_destroy(cfg); | 
					
						
							| 
									
										
										
										
											2003-12-09 23:55:17 +00:00
										 |  |  | 		__unload_module(); | 
					
						
							| 
									
										
										
										
											2007-09-05 15:16:50 +00:00
										 |  |  | 		return AST_MODULE_LOAD_FAILURE; | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-01-25 06:10:20 +00:00
										 |  |  | 	ast_config_destroy(cfg); | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | 	/* And start the monitor for the first time */ | 
					
						
							|  |  |  | 	restart_monitor(); | 
					
						
							| 
									
										
										
										
											2007-09-05 15:16:50 +00:00
										 |  |  | 	return AST_MODULE_LOAD_SUCCESS; | 
					
						
							| 
									
										
										
										
											2000-01-06 11:50:20 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Linux Telephony API Support"); |