1 /*****************************************************************************/
2 /*
3  *      auermain.h  --  Auerswald PBX/System Telephone usb driver.
4  *
5  *      Copyright (C) 2002  Wolfgang M�es (wolfgang@iksw-muees.de)
6  *
7  *      This program is free software; you can redistribute it and/or modify
8  *      it under the terms of the GNU General Public License as published by
9  *      the Free Software Foundation; either version 2 of the License, or
10  *      (at your option) any later version.
11  *
12  *      This program is distributed in the hope that it will be useful,
13  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *      GNU General Public License for more details.
16  *
17  *      You should have received a copy of the GNU General Public License
18  *      along with this program; if not, write to the Free Software
19  *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  */
21  /*****************************************************************************/
22 
23 #ifndef AUERMAIN_H
24 #define AUERMAIN_H
25 
26 #include <linux/devfs_fs_kernel.h>
27 #include <linux/usb.h>
28 #include "auerchain.h"
29 #include "auerbuf.h"
30 #include "auerserv.h"
31 #include "auerisdn.h"
32 
33 /*-------------------------------------------------------------------*/
34 /* Private declarations for Auerswald USB driver                     */
35 
36 /* Auerswald Vendor ID */
37 #define ID_AUERSWALD  	0x09BF
38 
39 #ifndef AUER_MINOR_BASE		/* allow external override */
40 #define AUER_MINOR_BASE	112	/* auerswald driver minor number */
41 #endif
42 
43 /* we can have up to this number of device plugged in at once */
44 #define AUER_MAX_DEVICES 16
45 
46 /* prefix for the device descriptors in /dev/usb */
47 #define AU_PREFIX	"auer"
48 
49 /* Number of read buffers for each device */
50 #define AU_RBUFFERS     10
51 
52 /* Number of chain elements for each control chain */
53 #define AUCH_ELEMENTS   20
54 
55 /* Number of retries in communication */
56 #define AU_RETRIES	10
57 
58 /*-------------------------------------------------------------------*/
59 /* vendor specific protocol                                          */
60 /* Header Byte */
61 #define AUH_INDIRMASK   0x80	/* mask for direct/indirect bit */
62 #define AUH_DIRECT      0x00	/* data is for USB device */
63 #define AUH_INDIRECT    0x80	/* USB device is relay */
64 
65 #define AUH_SPLITMASK   0x40	/* mask for split bit */
66 #define AUH_UNSPLIT     0x00	/* data block is full-size */
67 #define AUH_SPLIT       0x40	/* data block is part of a larger one,
68 				   split-byte follows */
69 #define AUH_SYNC	0x40	/* Sync to start of HDLC frame for B1,B2 */
70 
71 #define AUH_TYPEMASK    0x3F	/* mask for type of data transfer */
72 #define AUH_TYPESIZE    0x40	/* different types */
73 #define AUH_DCHANNEL    0x00	/* D channel data */
74 #define AUH_B1CHANNEL   0x01	/* B1 channel transparent */
75 #define AUH_B2CHANNEL   0x02	/* B2 channel transparent */
76 /*                0x03..0x0F       reserved for driver internal use */
77 #define AUH_COMMAND     0x10	/* Command channel */
78 #define AUH_BPROT       0x11	/* Configuration block protocol */
79 #define AUH_DPROTANA    0x12	/* D channel protocol analyzer */
80 #define AUH_TAPI        0x13	/* telephone api data (ATD) */
81 /*                0x14..0x3F       reserved for other protocols */
82 #define AUH_UNASSIGNED  0xFF	/* if char device has no assigned service */
83 #define AUH_FIRSTUSERCH 0x11	/* first channel which is available for driver users */
84 
85 #define AUH_SIZE	1	/* Size of Header Byte */
86 
87 /* Split Byte. Only present if split bit in header byte set.*/
88 #define AUS_STARTMASK   0x80	/* mask for first block of splitted frame */
89 #define AUS_FIRST       0x80	/* first block */
90 #define AUS_FOLLOW      0x00	/* following block */
91 
92 #define AUS_ENDMASK     0x40	/* mask for last block of splitted frame */
93 #define AUS_END         0x40	/* last block */
94 #define AUS_NOEND       0x00	/* not the last block */
95 
96 #define AUS_LENMASK     0x3F	/* mask for block length information */
97 
98 /* Request types */
99 #define AUT_RREQ        (USB_DIR_IN  | USB_TYPE_VENDOR | USB_RECIP_OTHER)	/* Read Request */
100 #define AUT_WREQ        (USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER)	/* Write Request */
101 
102 /* Vendor Requests */
103 #define AUV_GETINFO     0x00	/* GetDeviceInfo */
104 #define AUV_WBLOCK      0x01	/* Write Block */
105 #define AUV_RBLOCK      0x02	/* Read Block */
106 #define AUV_CHANNELCTL  0x03	/* Channel Control */
107 #define AUV_DUMMY	0x04	/* Dummy Out for retry */
108 
109 /* Device Info Types */
110 #define AUDI_NUMBCH     0x0000	/* Number of supported B channels */
111 #define AUDI_OUTFSIZE   0x0001	/* Size of OUT B channel fifos */
112 #define AUDI_MBCTRANS   0x0002	/* max. Blocklength of control transfer */
113 
114 /* Interrupt endpoint definitions */
115 #define AU_IRQENDP      1	/* Endpoint number */
116 #define AU_IRQCMDID     16	/* Command-block ID */
117 #define AU_BLOCKRDY     0	/* Command: Block data ready on ctl endpoint */
118 #define AU_IRQMINSIZE	5	/* Nr. of bytes decoded in this driver */
119 
120 /* B channel Interrupt endpoint definitions */
121 #define AU_IRQENDPBI	2	/* Input Endpoint number */
122 #define AU_IRQENDPBO	3	/* Output Endpoint number for 4410, 2206 */
123 #define AU_IRQENDPBO_2	2	/* Output Endpoint number for 2104 */
124 
125 /* Device String Descriptors */
126 #define AUSI_VENDOR   	1	/* "Auerswald GmbH & Co. KG" */
127 #define AUSI_DEVICE   	2	/* Name of the Device */
128 #define AUSI_SERIALNR 	3	/* Serial Number */
129 #define AUSI_MSN      	4	/* "MSN ..." (first) Multiple Subscriber Number */
130 
131 #define AUSI_DLEN	100	/* Max. Length of Device Description */
132 
133 #define AUV_RETRY	0x101	/* First Firmware version which can do control retries */
134 
135 /* ...................................................................*/
136 /* USB device context */
137 struct auerswald {
138 	struct semaphore mutex;		/* protection in user context */
139 	char name[16];			/* name of the /dev/usb entry */
140 	unsigned int dtindex;		/* index in the device table */
141 	devfs_handle_t devfs;		/* devfs device node */
142 	struct usb_device *usbdev;	/* USB device handle */
143 	int open_count;			/* count the number of open character channels */
144 	char dev_desc[AUSI_DLEN];	/* for storing a textual description */
145 	unsigned int maxControlLength;	/* max. Length of control paket (without header) */
146 	struct urb *inturbp;		/* interrupt urb */
147 	char *intbufp;			/* data buffer for interrupt urb */
148 	unsigned int irqsize;		/* size of interrupt endpoint 1 */
149 	struct auerchain controlchain;	/* for chaining of control messages */
150 	struct auerbufctl bufctl;	/* Buffer control for control transfers */
151 	struct auerscon *services[AUH_TYPESIZE];/* context pointers for each service */
152 	unsigned int version;		/* Version of the device */
153 	wait_queue_head_t bufferwait;	/* wait for a control buffer */
154 	volatile unsigned int disconnecting;/* 1: removal in progress */
155 	struct auerisdn isdn;		/* ISDN-Related parameters */
156 };
157 
158 /* array of pointers to our devices that are currently connected */
159 extern struct auerswald *auerdev_table[AUER_MAX_DEVICES];
160 
161 /* lock to protect the auerdev_table structure */
162 extern struct semaphore auerdev_table_mutex;
163 
164 void auerswald_removeservice(struct auerswald *cp, struct auerscon *scp);
165 
166 int auerswald_addservice(struct auerswald *cp, struct auerscon *scp);
167 
168 void auerchar_ctrlwrite_complete(struct urb *urb);
169 
170 void auerswald_delete(struct auerswald *cp);
171 
172 #endif	/* AUERMAIN_H */
173