1 /*****************************************************************************
2 * router.h Definitions for the WAN Multiprotocol Router Module.
3 * This module provides API and common services for WAN Link
4 * Drivers and is completely hardware-independent.
6 * Author: Gene Kozin <genek@compuserve.com>
7 * Jaspreet Singh <jaspreet@sangoma.com>
8 * Additions: Arnaldo Carvalho de Melo <acme@conectiva.com.br>
10 * Copyright: (c) 1995-1997 Sangoma Technologies Inc.
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version
15 * 2 of the License, or (at your option) any later version.
16 * ============================================================================
17 * May 23, 1999 Arnaldo Melo Added local_addr to wanif_conf_t
18 * WAN_DISCONNECTING state added
19 * Nov 06, 1997 Jaspreet Singh Changed Router Driver version to 1.1 from 1.0
20 * Oct 20, 1997 Jaspreet Singh Added 'cir','bc','be' and 'mc' to 'wanif_conf_t'
21 * Added 'enable_IPX' and 'network_number' to
22 * 'wan_device_t'. Also added defines for
23 * UDP PACKET TYPE, Interrupt test, critical values
24 * for RACE conditions.
25 * Oct 05, 1997 Jaspreet Singh Added 'dlci_num' and 'dlci[100]' to
26 * 'wan_fr_conf_t' to configure a list of dlci(s)
28 * Jul 07, 1997 Jaspreet Singh Added 'ttl' to 'wandev_conf_t' & 'wan_device_t'
29 * May 29, 1997 Jaspreet Singh Added 'tx_int_enabled' to 'wan_device_t'
30 * May 21, 1997 Jaspreet Singh Added 'udp_port' to 'wan_device_t'
31 * Apr 25, 1997 Farhan Thawar Added 'udp_port' to 'wandev_conf_t'
32 * Jan 16, 1997 Gene Kozin router_devlist made public
33 * Jan 02, 1997 Gene Kozin Initial version (based on wanpipe.h).
34 *****************************************************************************/
38 #define ROUTER_NAME "wanrouter" /* in case we ever change it */
39 #define ROUTER_VERSION 1 /* version number */
40 #define ROUTER_RELEASE 1 /* release (minor version) number */
41 #define ROUTER_IOCTL 'W' /* for IOCTL calls */
42 #define ROUTER_MAGIC 0x524D4157L /* signature: 'WANR' reversed */
44 /* IOCTL codes for /proc/router/<device> entries (up to 255) */
47 ROUTER_SETUP
= ROUTER_IOCTL
<<8, /* configure device */
48 ROUTER_DOWN
, /* shut down device */
49 ROUTER_STAT
, /* get device status */
50 ROUTER_IFNEW
, /* add interface */
51 ROUTER_IFDEL
, /* delete interface */
52 ROUTER_IFSTAT
, /* get interface status */
53 ROUTER_USER
= (ROUTER_IOCTL
<<8)+16, /* driver-specific calls */
54 ROUTER_USER_MAX
= (ROUTER_IOCTL
<<8)+31
57 /* NLPID for packet encapsulation (ISO/IEC TR 9577) */
58 #define NLPID_IP 0xCC /* Internet Protocol Datagram */
59 #define NLPID_SNAP 0x80 /* IEEE Subnetwork Access Protocol */
60 #define NLPID_CLNP 0x81 /* ISO/IEC 8473 */
61 #define NLPID_ESIS 0x82 /* ISO/IEC 9542 */
62 #define NLPID_ISIS 0x83 /* ISO/IEC ISIS */
63 #define NLPID_Q933 0x08 /* CCITT Q.933 */
66 #define WAN_IFNAME_SZ 15 /* max length of the interface name */
67 #define WAN_DRVNAME_SZ 15 /* max length of the link driver name */
68 #define WAN_ADDRESS_SZ 31 /* max length of the WAN media address */
70 /* Defines for UDP PACKET TYPE */
71 #define UDP_PTPIPE_TYPE 0x01
72 #define UDP_FPIPE_TYPE 0x02
73 #define UDP_DRVSTATS_TYPE 0x03
74 #define UDP_INVALID_TYPE 0x04
76 /* Command return code */
77 #define CMD_OK 0 /* normal firmware return code */
78 #define CMD_TIMEOUT 0xFF /* firmware command timed out */
80 /* UDP Packet Management */
81 #define UDP_PKT_FRM_STACK 0x00
82 #define UDP_PKT_FRM_NETWORK 0x01
84 /* Maximum interrupt test counter */
85 #define MAX_INTR_TEST_COUNTER 100
87 /* Critical Values for RACE conditions*/
88 #define CRITICAL_IN_ISR 0xA1
89 #define CRITICAL_INTR_HANDLED 0xB1
91 /****** Data Types **********************************************************/
93 /*----------------------------------------------------------------------------
94 * X.25-specific link-level configuration.
96 typedef struct wan_x25_conf
98 unsigned lo_pvc
; /* lowest permanent circuit number */
99 unsigned hi_pvc
; /* highest permanent circuit number */
100 unsigned lo_svc
; /* lowest switched circuit number */
101 unsigned hi_svc
; /* highest switched circuit number */
102 unsigned hdlc_window
; /* HDLC window size (1..7) */
103 unsigned pkt_window
; /* X.25 packet window size (1..7) */
104 unsigned t1
; /* HDLC timer T1, sec (1..30) */
105 unsigned t2
; /* HDLC timer T2, sec (0..29) */
106 unsigned t4
; /* HDLC supervisory frame timer = T4 * T1 */
107 unsigned n2
; /* HDLC retransmission limit (1..30) */
108 unsigned t10_t20
; /* X.25 RESTART timeout, sec (1..255) */
109 unsigned t11_t21
; /* X.25 CALL timeout, sec (1..255) */
110 unsigned t12_t22
; /* X.25 RESET timeout, sec (1..255) */
111 unsigned t13_t23
; /* X.25 CLEAR timeout, sec (1..255) */
112 unsigned t16_t26
; /* X.25 INTERRUPT timeout, sec (1..255) */
113 unsigned t28
; /* X.25 REGISTRATION timeout, sec (1..255) */
114 unsigned r10_r20
; /* RESTART retransmission limit (0..250) */
115 unsigned r12_r22
; /* RESET retransmission limit (0..250) */
116 unsigned r13_r23
; /* CLEAR retransmission limit (0..250) */
117 unsigned ccitt_compat
; /* compatibility mode: 1988/1984/1980 */
120 /*----------------------------------------------------------------------------
121 * Frame relay specific link-level configuration.
123 typedef struct wan_fr_conf
125 unsigned signalling
; /* local in-channel signalling type */
126 unsigned t391
; /* link integrity verification timer */
127 unsigned t392
; /* polling verification timer */
128 unsigned n391
; /* full status polling cycle counter */
129 unsigned n392
; /* error threshold counter */
130 unsigned n393
; /* monitored events counter */
131 unsigned dlci_num
; /* number of DLCs (access node) */
132 unsigned dlci
[100]; /* List of all DLCIs */
135 /*----------------------------------------------------------------------------
136 * PPP-specific link-level configuration.
138 typedef struct wan_ppp_conf
140 unsigned restart_tmr
; /* restart timer */
141 unsigned auth_rsrt_tmr
; /* authentication timer */
142 unsigned auth_wait_tmr
; /* authentication timer */
143 unsigned mdm_fail_tmr
; /* modem failure timer */
144 unsigned dtr_drop_tmr
; /* DTR drop timer */
145 unsigned connect_tmout
; /* connection timeout */
146 unsigned conf_retry
; /* max. retry */
147 unsigned term_retry
; /* max. retry */
148 unsigned fail_retry
; /* max. retry */
149 unsigned auth_retry
; /* max. retry */
150 unsigned auth_options
; /* authentication opt. */
151 unsigned ip_options
; /* IP options */
154 /*----------------------------------------------------------------------------
155 * WAN device configuration. Passed to ROUTER_SETUP IOCTL.
157 typedef struct wandev_conf
159 unsigned magic
; /* magic number (for verification) */
160 unsigned config_id
; /* configuration structure identifier */
161 /****** hardware configuration ******/
162 unsigned ioport
; /* adapter I/O port base */
163 unsigned long maddr
; /* dual-port memory address */
164 unsigned msize
; /* dual-port memory size */
165 int irq
; /* interrupt request level */
166 int dma
; /* DMA request level */
167 unsigned bps
; /* data transfer rate */
168 unsigned mtu
; /* maximum transmit unit size */
169 unsigned udp_port
; /* UDP port for management */
170 unsigned char ttl
; /* Time To Live for UDP security */
171 char interface
; /* RS-232/V.35, etc. */
172 char clocking
; /* external/internal */
173 char line_coding
; /* NRZ/NRZI/FM0/FM1, etc. */
174 char station
; /* DTE/DCE, primary/secondary, etc. */
175 char connection
; /* permanent/switched/on-demand */
176 unsigned hw_opt
[4]; /* other hardware options */
177 unsigned char enable_IPX
; /* Enable or Disable IPX */
178 unsigned long network_number
; /* Network Number for IPX */
179 unsigned reserved
[4];
180 /****** arbitrary data ***************/
181 unsigned data_size
; /* data buffer size */
182 void* data
; /* data buffer, e.g. firmware */
183 union /****** protocol-specific ************/
185 wan_x25_conf_t x25
; /* X.25 configuration */
186 wan_ppp_conf_t ppp
; /* PPP configuration */
187 wan_fr_conf_t fr
; /* frame relay configuration */
191 /* 'config_id' definitions */
192 #define WANCONFIG_X25 101 /* X.25 link */
193 #define WANCONFIG_FR 102 /* frame relay link */
194 #define WANCONFIG_PPP 103 /* synchronous PPP link */
197 * Configuration options defines.
199 /* general options */
205 /* intercace options */
206 #define WANOPT_RS232 0
209 /* data encoding options */
211 #define WANOPT_NRZI 1
215 /* link type options */
216 #define WANOPT_POINTTOPOINT 0 /* RTS always active */
217 #define WANOPT_MULTIDROP 1 /* RTS is active when transmitting */
219 /* clocking options */
220 #define WANOPT_EXTERNAL 0
221 #define WANOPT_INTERNAL 1
223 /* station options */
227 #define WANOPT_NODE 1
228 #define WANOPT_SECONDARY 0
229 #define WANOPT_PRIMARY 1
231 /* connection options */
232 #define WANOPT_PERMANENT 0 /* DTR always active */
233 #define WANOPT_SWITCHED 1 /* use DTR to setup link (dial-up) */
234 #define WANOPT_ONDEMAND 2 /* activate DTR only before sending */
236 /* frame relay in-channel signalling */
237 #define WANOPT_FR_ANSI 0 /* ANSI T1.617 Annex D */
238 #define WANOPT_FR_Q933 1 /* ITU Q.933A */
239 #define WANOPT_FR_LMI 2 /* LMI */
241 /*----------------------------------------------------------------------------
242 * WAN Link Status Info (for ROUTER_STAT IOCTL).
244 typedef struct wandev_stat
246 unsigned state
; /* link state */
247 unsigned ndev
; /* number of configured interfaces */
249 /* link/interface configuration */
250 unsigned connection
; /* permanent/switched/on-demand */
251 unsigned media_type
; /* Frame relay/PPP/X.25/SDLC, etc. */
252 unsigned mtu
; /* max. transmit unit for this device */
254 /* physical level statistics */
255 unsigned modem_status
; /* modem status */
256 unsigned rx_frames
; /* received frames count */
257 unsigned rx_overruns
; /* receiver overrun error count */
258 unsigned rx_crc_err
; /* receive CRC error count */
259 unsigned rx_aborts
; /* received aborted frames count */
260 unsigned rx_bad_length
; /* unexpetedly long/short frames count */
261 unsigned rx_dropped
; /* frames discarded at device level */
262 unsigned tx_frames
; /* transmitted frames count */
263 unsigned tx_underruns
; /* aborted transmissions (underruns) count */
264 unsigned tx_timeouts
; /* transmission timeouts */
265 unsigned tx_rejects
; /* other transmit errors */
267 /* media level statistics */
268 unsigned rx_bad_format
; /* frames with invalid format */
269 unsigned rx_bad_addr
; /* frames with invalid media address */
270 unsigned tx_retries
; /* frames re-transmitted */
271 unsigned reserved
[16]; /* reserved for future use */
274 /* 'state' defines */
277 WAN_UNCONFIGURED
, /* link/channel is not configured */
278 WAN_DISCONNECTED
, /* link/channel is disconnected */
279 WAN_CONNECTING
, /* connection is in progress */
280 WAN_CONNECTED
, /* link/channel is operational */
281 WAN_DISCONNECTING
, /* disconnection is in progress */
282 WAN_LIMIT
/* for verification only */
285 /* 'modem_status' masks */
286 #define WAN_MODEM_CTS 0x0001 /* CTS line active */
287 #define WAN_MODEM_DCD 0x0002 /* DCD line active */
288 #define WAN_MODEM_DTR 0x0010 /* DTR line active */
289 #define WAN_MODEM_RTS 0x0020 /* RTS line active */
291 /*----------------------------------------------------------------------------
292 * WAN interface (logical channel) configuration (for ROUTER_IFNEW IOCTL).
294 typedef struct wanif_conf
296 unsigned magic
; /* magic number */
297 unsigned config_id
; /* configuration identifier */
298 char name
[WAN_IFNAME_SZ
+1]; /* interface name, ASCIIZ */
299 char addr
[WAN_ADDRESS_SZ
+1]; /* media address, ASCIIZ */
300 unsigned idle_timeout
; /* sec, before disconnecting */
301 unsigned hold_timeout
; /* sec, before re-connecting */
302 unsigned cir
; /* Committed Information Rate fwd,bwd*/
303 unsigned bc
; /* Committed Burst Size fwd, bwd */
304 unsigned be
; /* Excess Burst Size fwd, bwd */
305 char mc
; /* Multicast on or off */
306 char local_addr
[WAN_ADDRESS_SZ
+1];/* local media address, ASCIIZ */
307 unsigned char port
; /* board port */
308 unsigned char protocol
; /* prococol used in this channel (TCPOX25 or X25) */
309 int reserved
[8]; /* reserved for future extensions */
313 /****** Kernel Interface ****************************************************/
315 #include <linux/fs.h> /* support for device drivers */
316 #include <linux/proc_fs.h> /* proc filesystem pragmatics */
317 #include <linux/inet.h> /* in_aton(), in_ntoa() prototypes */
318 #include <linux/netdevice.h> /* support for network drivers */
320 /*----------------------------------------------------------------------------
321 * WAN device data space.
323 typedef struct wan_device
325 unsigned magic
; /* magic number */
326 char* name
; /* -> WAN device name (ASCIIZ) */
327 void* private; /* -> driver private data */
328 /****** hardware configuration ******/
329 unsigned ioport
; /* adapter I/O port base #1 */
330 void * maddr
; /* dual-port memory address */
331 unsigned msize
; /* dual-port memory size */
332 int irq
; /* interrupt request level */
333 int dma
; /* DMA request level */
334 unsigned bps
; /* data transfer rate */
335 unsigned mtu
; /* max physical transmit unit size */
336 unsigned udp_port
; /* UDP port for management */
337 unsigned char ttl
; /* Time To Live for UDP security */
338 unsigned enable_tx_int
; /* Transmit Interrupt enabled or not */
339 char interface
; /* RS-232/V.35, etc. */
340 char clocking
; /* external/internal */
341 char line_coding
; /* NRZ/NRZI/FM0/FM1, etc. */
342 char station
; /* DTE/DCE, primary/secondary, etc. */
343 char connection
; /* permanent/switched/on-demand */
344 unsigned hw_opt
[4]; /* other hardware options */
345 unsigned char enable_IPX
; /* Enable or Disable IPX */
346 unsigned long network_number
; /* Network Number for IPX */
347 /****** status and statistics *******/
348 char state
; /* device state */
349 unsigned modem_status
; /* modem status */
350 struct enet_statistics stats
; /* interface statistics */
351 unsigned reserved
[16]; /* reserved for future use */
352 unsigned critical
; /* critical section flag */
353 /****** device management methods ***/
354 int (*setup
) (struct wan_device
* wandev
, wandev_conf_t
* conf
);
355 int (*shutdown
) (struct wan_device
* wandev
);
356 int (*update
) (struct wan_device
* wandev
);
357 int (*ioctl
) (struct wan_device
* wandev
, unsigned cmd
,
359 int (*new_if
) (struct wan_device
* wandev
, struct net_device
* dev
,
361 int (*del_if
) (struct wan_device
* wandev
, struct net_device
* dev
);
362 /****** maintained by the router ****/
363 struct wan_device
* next
; /* -> next device */
364 struct net_device
* dev
; /* list of network interfaces */
365 unsigned ndev
; /* number of interfaces */
366 struct proc_dir_entry dent
; /* proc filesystem entry */
369 /* Public functions available for device drivers */
370 extern int register_wan_device(wan_device_t
* wandev
);
371 extern int unregister_wan_device(char* name
);
372 unsigned short wanrouter_type_trans(struct sk_buff
* skb
, struct net_device
* dev
);
373 int wanrouter_encapsulate(struct sk_buff
* skb
, struct net_device
* dev
);
375 /* Proc interface functions. These must not be called by the drivers! */
376 extern int wanrouter_proc_init (void);
377 extern void wanrouter_proc_cleanup (void);
378 extern int wanrouter_proc_add (wan_device_t
* wandev
);
379 extern int wanrouter_proc_delete (wan_device_t
* wandev
);
380 extern int wanrouter_ioctl(
381 struct inode
* inode
, struct file
* file
,
382 unsigned int cmd
, unsigned long arg
)
386 extern wan_device_t
* router_devlist
; /* list of registered devices */
388 #endif /* __KERNEL__ */
389 #endif /* _ROUTER_H */