📄 mcci_usb.c.org
字号:
/*Copyright (c) 2005 MCCI 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. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/#include \<linux/config.h>#include \<linux/module.h>#include \<linux/errno.h>#include \<linux/signal.h>#include \<linux/sched.h>#include \<linux/timer.h>#include \<linux/interrupt.h>#include \<linux/tty.h>#include \<linux/tty_driver.h>#include \<linux/tty_flip.h>#include \<linux/major.h>#include \<linux/string.h>#include \<linux/fcntl.h>#include \<linux/ptrace.h>#include \<linux/mm.h>#include \<linux/slab.h>#include \<linux/init.h>#include \<linux/delay.h>#include \<linux/spinlock.h>#include \<linux/usb.h>#include \<linux/proc_fs.h>#include \<asm/uaccess.h>staticintdebug=0;#include \"usb-serial.h"#include \"vspwire.h"#include \"vspctlda.h"#if \0#define \l111110100 \ \(0x10c4)#define \l111110101 \ \(0xea60)#define \l111110110 \ \(1)#endif#define \O111110111 \ \(024)#ifdef \O111111000#define \O111111001( \l111111010 \) \ \if (verbose) { (l111111010); };#else#define \O111111001( \l111111010 \) \ #endif#define \BAUD_CLK \ \(0x384000)structO111111011{structusb_serial_port*l111111100;intl111111101;intO111111110;intO111111111;};staticintl1000000000(structusb_serial_port*l1000000001,structfile*l1000000010);staticvoidO1000000011(structusb_serial_port*l1000000001,structfile*l1000000010);staticintl1000000100(structusb_serial_port*l1000000001,structfile*l1000000010,unsignedintl1000000101,unsignedlongO1000000110);staticvoidl1000000111(structusb_serial_port*l1000000001,structtermios*O1000001000);staticvoidO1000001001(structusb_serial_port*l1000000001,intl1000001010);staticintO1000001011(structusb_serial*l1000001100);staticvoidO1000001101(structusb_serial*l1000001100);intl1000001110(char*O1000001111,intsize,char*format,...);intO1000010000(char*O1000010001,char**O1000010010,off_tl1000010011,intO1000010100,int*O1000010101,void*l1000010110);staticintmcci_vsp_setdtrrts(structO111111011*l1000010111,unsignedl1000011000);#if \0staticstructusb_device_idl1000011001[]={{O1000011010(l111110100,l111110101)},{O1000011010(l111110100,l111110110)},{}};#else#define \l111110100 \ \(0x10c4)#define \l111110101 \ \(0165140)#define \l111110110 \ \(1)staticintmcci_vids[]={l111110100,l111110100,0};staticintmcci_pids[]={l111110101,l111110110,0};staticstructusb_device_idl1000011001[O111110111+1];#endifMODULE_DEVICE_TABLE(usb,l1000011001);structusb_serial_device_typeO1000011011={owner:THIS_MODULE,name:"\115CC\111\040USB\040A\144ap\164\145r",id_table:l1000011001,num_interrupt_in:0,num_bulk_in:1,num_bulk_out:1,num_ports:1,open:l1000000000,close:O1000000011,ioctl:l1000000100,set_termios:l1000000111,break_ctl:O1000001001,startup:O1000001011,shutdown:O1000001101,};staticintverbose=0;staticintl1000000000(structusb_serial_port*l1000000001,structfile*l1000000010){intl1000011100;structusb_serial*l1000001100;structO111111011*O1000011101;O111111001(printk("mcci\137op\145\156\012"));if(l1000000001==NULL){printk("%d\040\157op\163\040u\163\142_\163er\151al\137po\162t\040\160o\151\156t\145r\040i\163\040N\125L\114\012",__LINE__);return-ENOMEM;}l1000001100=l1000000001->serial;O111111001(printk("mc\143\151_o\160\145n\040\160o\162\164\040\075 \060x%\170\012",l1000000001->number));O1000011101=l1000000001->private;memset(O1000011101,0,sizeof(structO111111011));O1000011101->l111111100=l1000000001;O1000011101->l111111101=O1000011110;O1000011101->O111111110=O1000011111;O1000011101->O111111111=l1000100000;l1000011100=usb_control_msg(l1000001100->dev,usb_sndctrlpipe(l1000001100->dev,0),l1000100001,O1000100010,0x01,0,0,0,3*HZ);if(l1000011100<0)printk("%\144\040\165\163\142_c\157nt\162o\154_\155\163g\040re\164u\162\156e\144 \045d\012",__LINE__,-l1000011100);l1000000001->read_urb->dev=l1000000001->serial->dev;l1000011100=usb_submit_urb(l1000000001->read_urb);if(l1000011100)O111111001(printk("\165s\142\137sub\155it\137ur\142 \162e\141\144 \162et\165rn\145d\0400\170%\170\012",l1000011100));return0;}staticvoidO1000000011(structusb_serial_port*l1000000001,structfile*l1000000010){structusb_serial*l1000001100;intl1000011100;if(l1000000001==NULL){printk("\045\144\040\157o\160s \165sb\137s\145ri\141l_\160o\162\164 \160\157i\156t\145r\040i\163 \116UL\114\012",__LINE__);return;}l1000001100=l1000000001->serial;if(l1000001100==NULL){printk("\045d \157\157ps \165sb\137se\162ia\154_p\157rt\040p\157\151n\164e\162 \151\163 \116U\114L\012",__LINE__);return;}O111111001(printk("mc\143\151_cl\157se\040\146o\162\040\157pe\156 #\045d\012",l1000000001->open_count));O111111001(printk("%s\072\040can\143el\040\162e\141\144s\012",__FUNCTION__));l1000011100=usb_unlink_urb(l1000000001->read_urb);if(l1000011100){O111111001(printk("%\163\072 r\145\141d:\040us\142_u\156l\151nk\137ur\142(\045\154x\054\040%\154x\051 f\141i\154e\144:\040%\144\012",__FUNCTION__,(unsignedlong)l1000000001,(unsignedlong)l1000000001->read_urb,l1000011100));}O111111001(printk("%s: \143\141nc\145\154 \167\162i\164es\012",__FUNCTION__));l1000011100=usb_unlink_urb(l1000000001->write_urb);if(l1000011100){O111111001(printk("%\163\072 wr\151\164\145\072 \165s\142\137u\156li\156k_\165r\142(\045l\170,\040%\154x)\040f\141i\154e\144:\040%\144\012",__FUNCTION__,(unsignedlong)l1000000001,(unsignedlong)l1000000001->write_urb,l1000011100));}l1000011100=usb_control_msg(l1000001100->dev,usb_sndctrlpipe(l1000001100->dev,0),l1000100001,O1000100010,0x0,0,0,0,3*HZ);if(l1000011100<0)printk("\045d u\163\142_c\157n\164ro\154_\155s\147 r\145tu\162n\145\144 %\144\012",__LINE__,-l1000011100);}#if \0staticvoidl1000100011(structurb*urb){O111111001(printk("mcci\137\162ea\144_\143\141l\154\137b\141c\153 u\162b\040\163t\141tus\040=\0400\170%\170\012",urb->O1000100100));}#endifstaticintmcci_vsp_setdtrrts(structO111111011*l1000010111,unsignedl1000011000){intl1000011100;structusb_serial*l1000001100;l1000001100=l1000010111->l111111100->serial;l1000011100=usb_control_msg(l1000001100->dev,usb_sndctrlpipe(l1000001100->dev,0),l1000100101,O1000100010,l1000011000,0,0,0,3*HZ);if(l1000011100<0)printk("%s:%\144: \165\163b\137c\157\156t\162o\154\137m\163g \162et\165rn\145\144\040%\144\012",__FUNCTION__,__LINE__,-l1000011100);returnl1000011100;}staticintl1000000100(structusb_serial_port*l1000000001,structfile*l1000000010,unsignedintl1000000101,unsignedlongO1000000110){intl1000011100=-ENOIOCTLCMD;structusb_serial*l1000001100;structO111111011*O1000011101;intl1000100110;intO1000100111;if(l1000000001==NULL){printk("%\144\040\155cc\151_s\145\164_\164e\162m\151\157s\040ca\154l\145d \167it\150 \116U\114L\040po\151n\164e\162 \012",__LINE__);returnl1000011100;}l1000001100=l1000000001->serial;if(l1000001100==NULL){printk("%d\040\155cc\151\137s\145\164_\164er\155io\163 c\141l\154\145d\040w\151t\150\040\116\125L\114 \165s\040p\157i\156t\145r\040\012",__LINE__);returnl1000011100;}O1000011101=l1000000001->private;switch(l1000000101){caseTCGETS:O111111001(printk("\124CGE\124\123\012"));break;caseTCSETS:O111111001(printk("\124\103SE\124\123\012"));break;caseTCSETSW:O111111001(printk("\124CS\105\124SW\012"));break;caseTCSETSF:O111111001(printk("TC\123\105TS\106\012"));break;caseTCGETA:O111111001(printk("TCG\105\124A\012"));break;caseTCSETA:O111111001(printk("\124CS\105\124A\012"));break;caseTCSETAW:O111111001(printk("T\103\123ETA\127\012"));break;caseTCSETAF:O111111001(printk("TC\123\105TAF\012"));break;caseTCSBRK:O111111001(printk("\124CSB\122\113\012"));break;caseTCXONC:O111111001(printk("\124C\130\117NC\012"));break;caseTCFLSH:O111111001(printk("\124CF\114\123H\012"));break;caseTIOCEXCL:O111111001(printk("T\111\117CE\130\103L\012"));break;caseTIOCNXCL:O111111001(printk("\124IOC\116\130CL\012"));break;caseTIOCSCTTY:O111111001(printk("\124IOC\123\103TT\131\012"));break;caseTIOCGPGRP:O111111001(printk("\124\111OCG\120\107R\120\012"));break;caseTIOCSPGRP:O111111001(printk("T\111\117CS\120\107RP\012"));break;caseTIOCOUTQ:O111111001(printk("\124IOC\117\125TQ\012"));break;caseTIOCSTI:O111111001(printk("TI\117\103ST\111\012"));break;caseTIOCGWINSZ:O111111001(printk("TI\117\103GW\111\116SZ\012"));break;caseTIOCSWINSZ:O111111001(printk("\124\111OC\123\127I\116\123Z\012"));break;caseTIOCMGET:O1000100111=0;l1000011100=usb_control_msg(l1000001100->dev,usb_rcvctrlpipe(l1000001100->dev,0),O1000101000,O1000101001,0,0,&O1000100111,4,3*HZ);if(l1000011100<0)printk("%d u\163b\137\143o\156\164r\157\154\137m\163g \162et\165r\156\145d\040er\162o\162n\157 \045d \012",__LINE__,-l1000011100);l1000100110=0;if(O1000100111&l1000101010){l1000100110|=TIOCM_DTR;O111111001(printk("\124\111\117CMG\105T \162\145q\165e\163ti\156g \104TR\040\012"));}if(O1000100111&O1000101011)l1000100110|=TIOCM_RTS;if(O1000100111&O1000101100)l1000100110|=TIOCM_CTS;if(O1000100111&O1000101101)l1000100110|=TIOCM_DSR;if(O1000100111&O1000101110)l1000100110|=TIOCM_RI;if(O1000100111&O1000101111)l1000100110|=TIOCM_CD;O111111001(printk("dev \045d \124\111O\103\115GE\124 \162e\164\165r\156in\147 0\170\045x\040m\157d\145m\040s\164at\165s\0400\170%\170\012",l1000001100->port[0].number,l1000100110,O1000100111));put_user(l1000100110,(int*)O1000000110);break;caseTIOCMBIS:get_user(l1000100110,(int*)O1000000110);O1000100111=0;if(l1000100110&TIOCM_RTS)O1000100111|=O1000110000|O1000110001;if(l1000100110&TIOCM_DTR)O1000100111|=l1000110010|O1000110011;l1000011100=mcci_vsp_setdtrrts(O1000011101,O1000100111);O111111001(printk("dev \045d\040\124IO\103MB\111S \060x\045x \163e\164\040m\157de\155\040c\157n\164r\157ls\040t\157 \060x\0450\064x\012",l1000001100->port[0].number,l1000100110,O1000100111));break;caseTIOCMBIC:get_user(l1000100110,(int*)O1000000110);O111111001(printk("T\111\117CM\102\111C \060x%\170\012",l1000100110));O1000100111=0;if(l1000100110&TIOCM_RTS)O1000100111|=O1000110000;if(l1000100110&TIOCM_DTR)O1000100111|=l1000110010;O111111001(printk("d\145v %\144\040T\111\117C\115\102I\103 0\170%\170\040s\145t \155o\144e\155 c\157n\164r\157l\163 t\157 \060x\0450\064x\012",l1000001100->port[0].number,l1000100110,O1000100111));l1000011100=mcci_vsp_setdtrrts(O1000011101,O1000100111);break;caseTIOCMSET:get_user(l1000100110,(int*)O1000000110);if(l1000100110&TIOCM_RTS)O1000100111=O1000110000|O1000110001;elseO1000100111=O1000110000;if(l1000100110&TIOCM_DTR){O1000100111|=(l1000110010 | O1000110011);}else{O1000100111|=l1000110010;}O111111001(printk("\124IOC\115\123ET\040se\164\151n\147 \104\124R\040to\0400x\045x\012",O1000100111));l1000011100=mcci_vsp_setdtrrts(O1000011101,O1000100111);O111111001(printk("dev \045d \124\111O\103MS\105T \060x\045x\040\163e\164 m\157d\145\155 \143on\164r\157l\163 \164o \060x\045x\012",l1000001100->port[0].number,l1000100110,O1000100111));break;caseTIOCGSOFTCAR:O111111001(printk("T\111\117CG\123\117F\124\103A\122\012"));break;caseTIOCSSOFTCAR:O111111001(printk("T\111\117CS\123\117F\124\103AR\012"));break;caseTIOCINQ:O111111001(printk("TIO\103\111NQ\012"));break;caseTIOCLINUX:O111111001(printk("TIO\103\114IN\125\130\012"));break;caseTIOCCONS:O111111001(printk("\124IO\103\103ONS\012"));break;caseTIOCGSERIAL:O111111001(printk("T\111\117CGS\105\122I\101\114\012"));break;caseTIOCSSERIAL:O111111001(printk("\124I\117\103SS\105\122I\101\114\012"));break;caseTIOCPKT:O111111001(printk("\124I\117\103PKT\012"));break;caseFIONBIO:O111111001(printk("\106I\117\116BIO\012"));break;caseTIOCNOTTY:O111111001(printk("T\111OCN\117\124TY\012"));break;caseTIOCSETD:O111111001(printk("T\111\117CS\105\124D\012"));break;caseTIOCGETD:O111111001(printk("\124IO\103\107ET\104\012"));break;caseTCSBRKP:O111111001(printk("\124CS\102\122KP\012"));break;caseTIOCTTYGSTRUCT:O111111001(printk("\124I\117\103TT\131G\123TR\125\103\124\012"));break;caseFIONCLEX:O111111001(printk("F\111\117NC\114\105X\012"));break;caseFIOCLEX:O111111001(printk("F\111\117CL\105\130\012"));break;caseFIOASYNC:O111111001(printk("\106\111OA\123\131N\103\012"));break;caseTIOCSERCONFIG:O111111001(printk("TIO\103\123ER\103\117N\106\111G\012"));break;caseTIOCSERGWILD:O111111001(printk("T\111OCS\105\122GW\111LD\012"));break;caseTIOCSERSWILD:O111111001(printk("\124I\117\103SER\123WI\114\104\012"));break;caseTIOCGLCKTRMIOS:O111111001(printk("TI\117\103GLC\113TR\115\111O\123\012"));break;caseTIOCSLCKTRMIOS:O111111001(printk("\124I\117\103\123L\103\113T\122\115I\117S\012"));break;caseTIOCSERGSTRUCT:O111111001(printk("\124I\117\103\123E\122\107S\124\122U\103T\012"));break;caseTIOCSERGETLSR:O111111001(printk("\124\111OC\123\105RG\105TL\123\122\012"));break;caseTIOCSERGETMULTI:O111111001(printk("\124\111OC\123\105R\107\105TM\125L\124\111\012"));break;caseTIOCSERSETMULTI:O111111001(printk("\124IO\103\123ER\123ET\115\125L\124I\012"));break;default:O111111001(printk(
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -