📄 ixj.c
字号:
/**************************************************************************** * ixj.c * * Device Driver for Quicknet Technologies, Inc.'s Telephony cards * including the Internet PhoneJACK, Internet PhoneJACK Lite, * Internet PhoneJACK PCI, Internet LineJACK, Internet PhoneCARD and * SmartCABLE * * (c) Copyright 1999-2001 Quicknet Technologies, Inc. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. * * Author: Ed Okerson, <eokerson@quicknet.net> * * Contributors: Greg Herlein, <gherlein@quicknet.net> * David W. Erhart, <derhart@quicknet.net> * John Sellers, <jsellers@quicknet.net> * Mike Preston, <mpreston@quicknet.net> * * Fixes: David Huggins-Daines, <dhd@cepstral.com> * Fabio Ferrari, <fabio.ferrari@digitro.com.br> * Artis Kugevics, <artis@mt.lv> * * More information about the hardware related to this driver can be found * at our website: http://www.quicknet.net * * IN NO EVENT SHALL QUICKNET TECHNOLOGIES, INC. BE LIABLE TO ANY PARTY FOR * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF QUICKNET * TECHNOLOGIES, INC. HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * QUICKNET TECHNOLOGIES, INC. SPECIFICALLY DISCLAIMS ANY WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS * ON AN "AS IS" BASIS, AND QUICKNET TECHNOLOGIES, INC. HAS NO OBLIGATION * TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. * ***************************************************************************/static char ixj_c_rcsid[] = "$Id: ixj.c,v 4.7 2001/08/13 06:19:33 craigs Exp $";static char ixj_c_revision[] = "$Revision: 4.7 $";/* * $Log: ixj.c,v $ * Revision 4.7 2001/08/13 06:19:33 craigs * Added additional changes from Alan Cox and John Anderson for * 2.2 to 2.4 cleanup and bounds checking * * Revision 4.6 2001/08/13 01:05:05 craigs * Really fixed PHONE_QUERY_CODEC problem this time * * Revision 4.5 2001/08/13 00:11:03 craigs * Fixed problem in handling of PHONE_QUERY_CODEC, thanks to Shane Anderson * * Revision 4.4 2001/08/07 07:58:12 craigs * Changed back to three digit version numbers * Added tagbuild target to allow automatic and easy tagging of versions * * Revision 4.3 2001/08/07 07:24:47 craigs * Added ixj-ver.h to allow easy configuration management of driver * Added display of version number in /prox/ixj * * Revision 4.2 2001/08/06 07:07:19 craigs * Reverted IXJCTL_DSP_TYPE and IXJCTL_DSP_VERSION files to original * behaviour of returning int rather than short * * * Revision 4.1 2001/08/05 00:17:37 craigs * More changes for correct PCMCIA installation * Start of changes for backward Linux compatibility * * Revision 4.0 2001/08/04 12:33:12 craigs * New version using GNU autoconf * * Revision 3.105 2001/07/20 23:14:32 eokerson * More work on CallerID generation when using ring cadences. * * Revision 3.104 2001/07/06 01:33:55 eokerson * Some bugfixes from Robert Vojta <vojta@ipex.cz> and a few mods to the Makefile. * * Revision 3.103 2001/07/05 19:20:16 eokerson * Updated HOWTO * Changed mic gain to 30dB on Internet LineJACK mic/speaker port. * * Revision 3.102 2001/07/03 23:51:21 eokerson * Un-mute mic on Internet LineJACK when in speakerphone mode. * * Revision 3.101 2001/07/02 19:26:56 eokerson * Removed initialiazation of ixjdebug and ixj_convert_loaded so they will go in the .bss instead of the .data * * Revision 3.100 2001/07/02 19:18:27 eokerson * Changed driver to make dynamic allocation possible. We now pass IXJ * between functions instead of array indexes. * Fixed the way the POTS and PSTN ports interact during a PSTN call to allow local answering. * Fixed speaker mode on Internet LineJACK. * * Revision 3.99 2001/05/09 14:11:16 eokerson * Fixed kmalloc error in ixj_build_filter_cadence. Thanks David Chan <cat@waulogy.stanford.edu>. * * Revision 3.98 2001/05/08 19:55:33 eokerson * Fixed POTS hookstate detection while it is connected to PSTN port. * * Revision 3.97 2001/05/08 00:01:04 eokerson * Fixed kernel oops when sending caller ID data. * * Revision 3.96 2001/05/04 23:09:30 eokerson * Now uses one kernel timer for each card, instead of one for the entire driver. * * Revision 3.95 2001/04/25 22:06:47 eokerson * Fixed squawking at beginning of some G.723.1 calls. * * Revision 3.94 2001/04/03 23:42:00 eokerson * Added linear volume ioctls * Added raw filter load ioctl * * Revision 3.93 2001/02/27 01:00:06 eokerson * Fixed blocking in CallerID. * Reduced size of ixj structure for smaller driver footprint. * * Revision 3.92 2001/02/20 22:02:59 eokerson * Fixed isapnp and pcmcia module compatibility for 2.4.x kernels. * Improved PSTN ring detection. * Fixed wink generation on POTS ports. * * Revision 3.91 2001/02/13 00:55:44 eokerson * Turn AEC back on after changing frame sizes. * * Revision 3.90 2001/02/12 16:42:00 eokerson * Added ALAW codec, thanks to Fabio Ferrari for the table based converters to make ALAW from ULAW. * * Revision 3.89 2001/02/12 15:41:16 eokerson * Fix from Artis Kugevics - Tone gains were not being set correctly. * * Revision 3.88 2001/02/05 23:25:42 eokerson * Fixed lockup bugs with deregister. * * Revision 3.87 2001/01/29 21:00:39 eokerson * Fix from Fabio Ferrari <fabio.ferrari@digitro.com.br> to properly handle EAGAIN and EINTR during non-blocking write. * Updated copyright date. * * Revision 3.86 2001/01/23 23:53:46 eokerson * Fixes to G.729 compatibility. * * Revision 3.85 2001/01/23 21:30:36 eokerson * Added verbage about cards supported. * Removed commands that put the card in low power mode at some times that it should not be in low power mode. * * Revision 3.84 2001/01/22 23:32:10 eokerson * Some bugfixes from David Huggins-Daines, <dhd@cepstral.com> and other cleanups. * * Revision 3.83 2001/01/19 14:51:41 eokerson * Fixed ixj_WriteDSPCommand to decrement usage counter when command fails. * * Revision 3.82 2001/01/19 00:34:49 eokerson * Added verbosity to write overlap errors. * * Revision 3.81 2001/01/18 23:56:54 eokerson * Fixed PSTN line test functions. * * Revision 3.80 2001/01/18 22:29:27 eokerson * Updated AEC/AGC values for different cards. * * Revision 3.79 2001/01/17 02:58:54 eokerson * Fixed AEC reset after Caller ID. * Fixed Codec lockup after Caller ID on Call Waiting when not using 30ms frames. * * Revision 3.78 2001/01/16 19:43:09 eokerson * Added support for Linux 2.4.x kernels. * * Revision 3.77 2001/01/09 04:00:52 eokerson * Linetest will now test the line, even if it has previously succeded. * * Revision 3.76 2001/01/08 19:27:00 eokerson * Fixed problem with standard cable on Internet PhoneCARD. * * Revision 3.75 2000/12/22 16:52:14 eokerson * Modified to allow hookstate detection on the POTS port when the PSTN port is selected. * * Revision 3.74 2000/12/08 22:41:50 eokerson * Added capability for G729B. * * Revision 3.73 2000/12/07 23:35:16 eokerson * Added capability to have different ring pattern before CallerID data. * Added hookstate checks in CallerID routines to stop FSK. * * Revision 3.72 2000/12/06 19:31:31 eokerson * Modified signal behavior to only send one signal per event. * * Revision 3.71 2000/12/06 03:23:08 eokerson * Fixed CallerID on Call Waiting. * * Revision 3.70 2000/12/04 21:29:37 eokerson * Added checking to Smart Cable gain functions. * * Revision 3.69 2000/12/04 21:05:20 eokerson * Changed ixjdebug levels. * Added ioctls to change gains in Internet Phone CARD Smart Cable. * * Revision 3.68 2000/12/04 00:17:21 craigs * Changed mixer voice gain to +6dB rather than 0dB * * Revision 3.67 2000/11/30 21:25:51 eokerson * Fixed write signal errors. * * Revision 3.66 2000/11/29 22:42:44 eokerson * Fixed PSTN ring detect problems. * * Revision 3.65 2000/11/29 07:31:55 craigs * Added new 425Hz filter co-efficients * Added card-specific DTMF prescaler initialisation * * Revision 3.64 2000/11/28 14:03:32 craigs * Changed certain mixer initialisations to be 0dB rather than 12dB * Added additional information to /proc/ixj * * Revision 3.63 2000/11/28 11:38:41 craigs * Added display of AEC modes in AUTO and AGC mode * * Revision 3.62 2000/11/28 04:05:44 eokerson * Improved PSTN ring detection routine. * * Revision 3.61 2000/11/27 21:53:12 eokerson * Fixed flash detection. * * Revision 3.60 2000/11/27 15:57:29 eokerson * More work on G.729 load routines. * * Revision 3.59 2000/11/25 21:55:12 eokerson * Fixed errors in G.729 load routine. * * Revision 3.58 2000/11/25 04:08:29 eokerson * Added board locks around G.729 and TS85 load routines. * * Revision 3.57 2000/11/24 05:35:17 craigs * Added ability to retrieve mixer values on LineJACK * Added complete initialisation of all mixer values at startup * Fixed spelling mistake * * Revision 3.56 2000/11/23 02:52:11 robertj * Added cvs change log keyword. * Fixed bug in capabilities list when using G.729 module. * */#include "ixj-ver.h"#define PERFMON_STATS#define IXJDEBUG 0#define MAXRINGS 5#include <linux/module.h>#include <linux/init.h>#include <linux/sched.h>#include <linux/kernel.h> /* printk() */#include <linux/fs.h> /* everything... */#include <linux/errno.h> /* error codes */#include <linux/slab.h>#include <linux/mm.h>#include <linux/ioport.h>#include <linux/interrupt.h>#include <linux/tqueue.h>#include <linux/proc_fs.h>#include <linux/poll.h>#include <linux/timer.h>#include <linux/delay.h>#include <linux/pci.h>#include <asm/io.h>#include <asm/segment.h>#include <asm/uaccess.h>#include <linux/isapnp.h>#include "ixj.h"#define TYPE(dev) (MINOR(dev) >> 4)#define NUM(dev) (MINOR(dev) & 0xf)static int ixjdebug;static int hertz = HZ;static int samplerate = 100;MODULE_PARM(ixjdebug, "i");/************************************************************************** ixjdebug meanings are now bit mapped instead of level based* Values can be or'ed together to turn on multiple messages** bit 0 (0x0001) = any failure* bit 1 (0x0002) = general messages* bit 2 (0x0004) = POTS ringing related* bit 3 (0x0008) = PSTN events* bit 4 (0x0010) = PSTN Cadence state details* bit 5 (0x0020) = Tone detection triggers* bit 6 (0x0040) = Tone detection cadence details* bit 7 (0x0080) = ioctl tracking* bit 8 (0x0100) = signal tracking* bit 9 (0x0200) = CallerID generation details*************************************************************************/#ifdef IXJ_DYN_ALLOCstatic IXJ *ixj[IXJMAX];#define get_ixj(b) ixj[(b)]/* * Allocate a free IXJ device */ static IXJ *ixj_alloc(){ for(cnt=0; cnt<IXJMAX; cnt++) { if(ixj[cnt] == NULL || !ixj[cnt]->DSPbase) { j = kmalloc(sizeof(IXJ), GFP_KERNEL); if (j == NULL) return NULL; ixj[cnt] = j; return j; } } return NULL;}static void ixj_fsk_free(IXJ *j){ if(j->fskdata != NULL) { kfree(j->fskdata); j->fskdata = NULL; }}static void ixj_fsk_alloc(IXJ *j){ if(!j->fskdata) { j->fskdata = kmalloc(8000, GFP_KERNEL); if (!j->fskdata) { if(ixjdebug & 0x0200) { printk("IXJ phone%d - allocate failed\n", j->board); } return; } else { j->fsksize = 8000; if(ixjdebug & 0x0200) { printk("IXJ phone%d - allocate succeded\n", j->board); } } }}#elsestatic IXJ ixj[IXJMAX];#define get_ixj(b) (&ixj[(b)])/* * Allocate a free IXJ device */ static IXJ *ixj_alloc(void){ int cnt; for(cnt=0; cnt<IXJMAX; cnt++) { if(!ixj[cnt].DSPbase) { return &ixj[cnt]; } } return NULL;}static inline void ixj_fsk_free(IXJ *j) {;}static inline void ixj_fsk_alloc(IXJ *j){ j->fsksize = 8000;}#endif#ifdef PERFMON_STATS#define ixj_perfmon(x) ((x)++)#else#define ixj_perfmon(x) do {} while(0);#endifstatic int ixj_convert_loaded;static int ixj_WriteDSPCommand(unsigned short, IXJ *j);/************************************************************************** These are function definitions to allow external modules to register* enhanced functionality call backs.*************************************************************************/static int Stub(IXJ * J, unsigned long arg){ return 0;}static IXJ_REGFUNC ixj_DownloadG729 = &Stub;static IXJ_REGFUNC ixj_DownloadTS85 = &Stub;static IXJ_REGFUNC ixj_PreRead = &Stub;static IXJ_REGFUNC ixj_PostRead = &Stub;static IXJ_REGFUNC ixj_PreWrite = &Stub;static IXJ_REGFUNC ixj_PostWrite = &Stub;static IXJ_REGFUNC ixj_PreIoctl = &Stub;static IXJ_REGFUNC ixj_PostIoctl = &Stub;static void ixj_read_frame(IXJ *j);static void ixj_write_frame(IXJ *j);static void ixj_init_timer(IXJ *j);static void ixj_add_timer(IXJ * j);static void ixj_timeout(unsigned long ptr);static int read_filters(IXJ *j);static int LineMonitor(IXJ *j);static int ixj_fasync(int fd, struct file *, int mode);static int ixj_set_port(IXJ *j, int arg);static int ixj_set_pots(IXJ *j, int arg);static int ixj_hookstate(IXJ *j);static int ixj_record_start(IXJ *j);static void ixj_record_stop(IXJ *j);static void set_rec_volume(IXJ *j, int volume);static int get_rec_volume(IXJ *j);static int set_rec_codec(IXJ *j, int rate);static void ixj_vad(IXJ *j, int arg);static int ixj_play_start(IXJ *j);static void ixj_play_stop(IXJ *j);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -