1 /*****************************************************************************
2 * wanrouter.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: Nenad Corbic <ncorbic@sangoma.com>
8 * Additions: Arnaldo Carvalho de Melo <acme@conectiva.com.br>
10 * Copyright: (c) 1995-1999 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 * Oct 04, 1999 Nenad Corbic Updated for 2.1.0 release
18 * Jun 02, 1999 Gideon Hack Added support for the S514 adapter.
19 * May 23, 1999 Arnaldo Melo Added local_addr to wanif_conf_t
20 * WAN_DISCONNECTING state added
21 * Jul 20, 1998 David Fong Added Inverse ARP options to 'wanif_conf_t'
22 * Jun 12, 1998 David Fong Added Cisco HDLC support.
23 * Dec 16, 1997 Jaspreet Singh Moved 'enable_IPX' and 'network_number' to
25 * Dec 05, 1997 Jaspreet Singh Added 'pap', 'chap' to 'wanif_conf_t'
26 * Added 'authenticator' to 'wan_ppp_conf_t'
27 * Nov 06, 1997 Jaspreet Singh Changed Router Driver version to 1.1 from 1.0
28 * Oct 20, 1997 Jaspreet Singh Added 'cir','bc','be' and 'mc' to 'wanif_conf_t'
29 * Added 'enable_IPX' and 'network_number' to
30 * 'wan_device_t'. Also added defines for
31 * UDP PACKET TYPE, Interrupt test, critical values
32 * for RACE conditions.
33 * Oct 05, 1997 Jaspreet Singh Added 'dlci_num' and 'dlci[100]' to
34 * 'wan_fr_conf_t' to configure a list of dlci(s)
36 * Jul 07, 1997 Jaspreet Singh Added 'ttl' to 'wandev_conf_t' & 'wan_device_t'
37 * May 29, 1997 Jaspreet Singh Added 'tx_int_enabled' to 'wan_device_t'
38 * May 21, 1997 Jaspreet Singh Added 'udp_port' to 'wan_device_t'
39 * Apr 25, 1997 Farhan Thawar Added 'udp_port' to 'wandev_conf_t'
40 * Jan 16, 1997 Gene Kozin router_devlist made public
41 * Jan 02, 1997 Gene Kozin Initial version (based on wanpipe.h).
42 *****************************************************************************/
43 #include <linux/version.h>
45 #if LINUX_VERSION_CODE >= 0x020100
52 #define ROUTER_NAME "wanrouter" /* in case we ever change it */
53 #define ROUTER_VERSION 1 /* version number */
54 #define ROUTER_RELEASE 1 /* release (minor version) number */
55 #define ROUTER_IOCTL 'W' /* for IOCTL calls */
56 #define ROUTER_MAGIC 0x524D4157L /* signature: 'WANR' reversed */
58 /* IOCTL codes for /proc/router/<device> entries (up to 255) */
61 ROUTER_SETUP
= ROUTER_IOCTL
<<8, /* configure device */
62 ROUTER_DOWN
, /* shut down device */
63 ROUTER_STAT
, /* get device status */
64 ROUTER_IFNEW
, /* add interface */
65 ROUTER_IFDEL
, /* delete interface */
66 ROUTER_IFSTAT
, /* get interface status */
67 ROUTER_USER
= (ROUTER_IOCTL
<<8)+16, /* driver-specific calls */
68 ROUTER_USER_MAX
= (ROUTER_IOCTL
<<8)+31
71 /* identifiers for displaying proc file data for dual port adapters */
72 #define PROC_DATA_PORT_0 0x8000 /* the data is for port 0 */
73 #define PROC_DATA_PORT_1 0x8001 /* the data is for port 1 */
75 /* NLPID for packet encapsulation (ISO/IEC TR 9577) */
76 #define NLPID_IP 0xCC /* Internet Protocol Datagram */
77 #define NLPID_SNAP 0x80 /* IEEE Subnetwork Access Protocol */
78 #define NLPID_CLNP 0x81 /* ISO/IEC 8473 */
79 #define NLPID_ESIS 0x82 /* ISO/IEC 9542 */
80 #define NLPID_ISIS 0x83 /* ISO/IEC ISIS */
81 #define NLPID_Q933 0x08 /* CCITT Q.933 */
84 #define WAN_IFNAME_SZ 15 /* max length of the interface name */
85 #define WAN_DRVNAME_SZ 15 /* max length of the link driver name */
86 #define WAN_ADDRESS_SZ 31 /* max length of the WAN media address */
87 #define USED_BY_FIELD 8 /* max length of the used by field */
89 /* Defines for UDP PACKET TYPE */
90 #define UDP_PTPIPE_TYPE 0x01
91 #define UDP_FPIPE_TYPE 0x02
92 #define UDP_CPIPE_TYPE 0x03
93 #define UDP_DRVSTATS_TYPE 0x04
94 #define UDP_INVALID_TYPE 0x05
96 /* Command return code */
97 #define CMD_OK 0 /* normal firmware return code */
98 #define CMD_TIMEOUT 0xFF /* firmware command timed out */
100 /* UDP Packet Management */
101 #define UDP_PKT_FRM_STACK 0x00
102 #define UDP_PKT_FRM_NETWORK 0x01
104 /* Maximum interrupt test counter */
105 #define MAX_INTR_TEST_COUNTER 100
107 /* Critical Values for RACE conditions*/
108 #define CRITICAL_IN_ISR 0xA1
109 #define CRITICAL_INTR_HANDLED 0xB1
111 /****** Data Types **********************************************************/
113 /*----------------------------------------------------------------------------
114 * X.25-specific link-level configuration.
116 typedef struct wan_x25_conf
118 unsigned lo_pvc
; /* lowest permanent circuit number */
119 unsigned hi_pvc
; /* highest permanent circuit number */
120 unsigned lo_svc
; /* lowest switched circuit number */
121 unsigned hi_svc
; /* highest switched circuit number */
122 unsigned hdlc_window
; /* HDLC window size (1..7) */
123 unsigned pkt_window
; /* X.25 packet window size (1..7) */
124 unsigned t1
; /* HDLC timer T1, sec (1..30) */
125 unsigned t2
; /* HDLC timer T2, sec (0..29) */
126 unsigned t4
; /* HDLC supervisory frame timer = T4 * T1 */
127 unsigned n2
; /* HDLC retransmission limit (1..30) */
128 unsigned t10_t20
; /* X.25 RESTART timeout, sec (1..255) */
129 unsigned t11_t21
; /* X.25 CALL timeout, sec (1..255) */
130 unsigned t12_t22
; /* X.25 RESET timeout, sec (1..255) */
131 unsigned t13_t23
; /* X.25 CLEAR timeout, sec (1..255) */
132 unsigned t16_t26
; /* X.25 INTERRUPT timeout, sec (1..255) */
133 unsigned t28
; /* X.25 REGISTRATION timeout, sec (1..255) */
134 unsigned r10_r20
; /* RESTART retransmission limit (0..250) */
135 unsigned r12_r22
; /* RESET retransmission limit (0..250) */
136 unsigned r13_r23
; /* CLEAR retransmission limit (0..250) */
137 unsigned ccitt_compat
; /* compatibility mode: 1988/1984/1980 */
140 /*----------------------------------------------------------------------------
141 * Frame relay specific link-level configuration.
143 typedef struct wan_fr_conf
145 unsigned signalling
; /* local in-channel signalling type */
146 unsigned t391
; /* link integrity verification timer */
147 unsigned t392
; /* polling verification timer */
148 unsigned n391
; /* full status polling cycle counter */
149 unsigned n392
; /* error threshold counter */
150 unsigned n393
; /* monitored events counter */
151 unsigned dlci_num
; /* number of DLCs (access node) */
152 unsigned dlci
[100]; /* List of all DLCIs */
155 /*----------------------------------------------------------------------------
156 * PPP-specific link-level configuration.
158 typedef struct wan_ppp_conf
160 unsigned restart_tmr
; /* restart timer */
161 unsigned auth_rsrt_tmr
; /* authentication timer */
162 unsigned auth_wait_tmr
; /* authentication timer */
163 unsigned mdm_fail_tmr
; /* modem failure timer */
164 unsigned dtr_drop_tmr
; /* DTR drop timer */
165 unsigned connect_tmout
; /* connection timeout */
166 unsigned conf_retry
; /* max. retry */
167 unsigned term_retry
; /* max. retry */
168 unsigned fail_retry
; /* max. retry */
169 unsigned auth_retry
; /* max. retry */
170 unsigned auth_options
; /* authentication opt. */
171 unsigned ip_options
; /* IP options */
172 char authenticator
; /* AUTHENTICATOR or not */
173 char ip_mode
; /* Static/Host/Peer */
176 /*----------------------------------------------------------------------------
177 * CHDLC-specific link-level configuration.
179 typedef struct wan_chdlc_conf
181 unsigned char ignore_dcd
; /* Protocol options: */
182 unsigned char ignore_cts
; /* Ignore these to determine */
183 unsigned char ignore_keepalive
; /* link status (Yes or No) */
184 unsigned char hdlc_streaming
; /* hdlc_streaming mode (Y/N) */
185 unsigned keepalive_tx_tmr
; /* transmit keepalive timer */
186 unsigned keepalive_rx_tmr
; /* receive keepalive timer */
187 unsigned keepalive_err_margin
; /* keepalive_error_tolerance */
188 unsigned slarp_timer
; /* SLARP request timer */
192 /*----------------------------------------------------------------------------
193 * WAN device configuration. Passed to ROUTER_SETUP IOCTL.
195 typedef struct wandev_conf
197 unsigned magic
; /* magic number (for verification) */
198 unsigned config_id
; /* configuration structure identifier */
199 /****** hardware configuration ******/
200 unsigned ioport
; /* adapter I/O port base */
201 unsigned long maddr
; /* dual-port memory address */
202 unsigned msize
; /* dual-port memory size */
203 int irq
; /* interrupt request level */
204 int dma
; /* DMA request level */
205 char S514_CPU_no
[1]; /* S514 PCI adapter CPU number ('A' or 'B') */
206 unsigned PCI_slot_no
; /* S514 PCI adapter slot number */
207 char comm_port
; /* Communication Port (PRI=0, SEC=1) */
208 unsigned bps
; /* data transfer rate */
209 unsigned mtu
; /* maximum transmit unit size */
210 unsigned udp_port
; /* UDP port for management */
211 unsigned char ttl
; /* Time To Live for UDP security */
212 unsigned char ft1
; /* FT1 Configurator Option */
213 char interface
; /* RS-232/V.35, etc. */
214 char clocking
; /* external/internal */
215 char line_coding
; /* NRZ/NRZI/FM0/FM1, etc. */
216 char station
; /* DTE/DCE, primary/secondary, etc. */
217 char connection
; /* permanent/switched/on-demand */
218 char read_mode
; /* read mode: Polling or interrupt */
219 unsigned hw_opt
[4]; /* other hardware options */
220 unsigned reserved
[4];
221 /****** arbitrary data ***************/
222 unsigned data_size
; /* data buffer size */
223 void* data
; /* data buffer, e.g. firmware */
224 union /****** protocol-specific ************/
226 wan_x25_conf_t x25
; /* X.25 configuration */
227 wan_ppp_conf_t ppp
; /* PPP configuration */
228 wan_fr_conf_t fr
; /* frame relay configuration */
229 wan_chdlc_conf_t chdlc
; /* Cisco HDLC configuration */
233 /* 'config_id' definitions */
234 #define WANCONFIG_X25 101 /* X.25 link */
235 #define WANCONFIG_FR 102 /* frame relay link */
236 #define WANCONFIG_PPP 103 /* synchronous PPP link */
237 #define WANCONFIG_CHDLC 104 /* Cisco HDLC Link */
238 #define WANCONFIG_BSC 105 /* BiSync Streaming */
239 #define WANCONFIG_HDLC 106 /* HDLC Support */
242 * Configuration options defines.
244 /* general options */
250 /* intercace options */
251 #define WANOPT_RS232 0
254 /* data encoding options */
256 #define WANOPT_NRZI 1
260 /* link type options */
261 #define WANOPT_POINTTOPOINT 0 /* RTS always active */
262 #define WANOPT_MULTIDROP 1 /* RTS is active when transmitting */
264 /* clocking options */
265 #define WANOPT_EXTERNAL 0
266 #define WANOPT_INTERNAL 1
268 /* station options */
272 #define WANOPT_NODE 1
273 #define WANOPT_SECONDARY 0
274 #define WANOPT_PRIMARY 1
276 /* connection options */
277 #define WANOPT_PERMANENT 0 /* DTR always active */
278 #define WANOPT_SWITCHED 1 /* use DTR to setup link (dial-up) */
279 #define WANOPT_ONDEMAND 2 /* activate DTR only before sending */
281 /* frame relay in-channel signalling */
282 #define WANOPT_FR_ANSI 1 /* ANSI T1.617 Annex D */
283 #define WANOPT_FR_Q933 2 /* ITU Q.933A */
284 #define WANOPT_FR_LMI 3 /* LMI */
286 /* PPP IP Mode Options */
287 #define WANOPT_PPP_STATIC 0
288 #define WANOPT_PPP_HOST 1
289 #define WANOPT_PPP_PEER 2
291 /* CHDLC Protocol Options */
292 /* DF Commmented out for now.
294 #define WANOPT_CHDLC_NO_DCD IGNORE_DCD_FOR_LINK_STAT
295 #define WANOPT_CHDLC_NO_CTS IGNORE_CTS_FOR_LINK_STAT
296 #define WANOPT_CHDLC_NO_KEEPALIVE IGNORE_KPALV_FOR_LINK_STAT
303 #define WANOPT_INTR 0
304 #define WANOPT_POLL 1
306 /*----------------------------------------------------------------------------
307 * WAN Link Status Info (for ROUTER_STAT IOCTL).
309 typedef struct wandev_stat
311 unsigned state
; /* link state */
312 unsigned ndev
; /* number of configured interfaces */
314 /* link/interface configuration */
315 unsigned connection
; /* permanent/switched/on-demand */
316 unsigned media_type
; /* Frame relay/PPP/X.25/SDLC, etc. */
317 unsigned mtu
; /* max. transmit unit for this device */
319 /* physical level statistics */
320 unsigned modem_status
; /* modem status */
321 unsigned rx_frames
; /* received frames count */
322 unsigned rx_overruns
; /* receiver overrun error count */
323 unsigned rx_crc_err
; /* receive CRC error count */
324 unsigned rx_aborts
; /* received aborted frames count */
325 unsigned rx_bad_length
; /* unexpetedly long/short frames count */
326 unsigned rx_dropped
; /* frames discarded at device level */
327 unsigned tx_frames
; /* transmitted frames count */
328 unsigned tx_underruns
; /* aborted transmissions (underruns) count */
329 unsigned tx_timeouts
; /* transmission timeouts */
330 unsigned tx_rejects
; /* other transmit errors */
332 /* media level statistics */
333 unsigned rx_bad_format
; /* frames with invalid format */
334 unsigned rx_bad_addr
; /* frames with invalid media address */
335 unsigned tx_retries
; /* frames re-transmitted */
336 unsigned reserved
[16]; /* reserved for future use */
339 /* 'state' defines */
342 WAN_UNCONFIGURED
, /* link/channel is not configured */
343 WAN_DISCONNECTED
, /* link/channel is disconnected */
344 WAN_CONNECTING
, /* connection is in progress */
345 WAN_CONNECTED
, /* link/channel is operational */
346 WAN_LIMIT
, /* for verification only */
347 WAN_DUALPORT
, /* for Dual Port cards */
348 WAN_DISCONNECTING
/* link/channel is disconnecting */
351 /* 'modem_status' masks */
352 #define WAN_MODEM_CTS 0x0001 /* CTS line active */
353 #define WAN_MODEM_DCD 0x0002 /* DCD line active */
354 #define WAN_MODEM_DTR 0x0010 /* DTR line active */
355 #define WAN_MODEM_RTS 0x0020 /* RTS line active */
357 /*----------------------------------------------------------------------------
358 * WAN interface (logical channel) configuration (for ROUTER_IFNEW IOCTL).
360 typedef struct wanif_conf
362 unsigned magic
; /* magic number */
363 unsigned config_id
; /* configuration identifier */
364 char name
[WAN_IFNAME_SZ
+1]; /* interface name, ASCIIZ */
365 char addr
[WAN_ADDRESS_SZ
+1]; /* media address, ASCIIZ */
366 char usedby
[USED_BY_FIELD
]; /* used by API or WANPIPE */
367 unsigned idle_timeout
; /* sec, before disconnecting */
368 unsigned hold_timeout
; /* sec, before re-connecting */
369 unsigned cir
; /* Committed Information Rate fwd,bwd*/
370 unsigned bc
; /* Committed Burst Size fwd, bwd */
371 unsigned be
; /* Excess Burst Size fwd, bwd */
372 unsigned char enable_IPX
; /* Enable or Disable IPX */
373 unsigned char inarp
; /* Send Inverse ARP requests Y/N */
374 unsigned inarp_interval
; /* sec, between InARP requests */
375 unsigned long network_number
; /* Network Number for IPX */
376 char mc
; /* Multicast on or off */
377 char local_addr
[WAN_ADDRESS_SZ
+1];/* local media address, ASCIIZ */
378 unsigned char port
; /* board port */
379 unsigned char protocol
; /* prococol used in this channel (TCPOX25 or X25) */
380 char pap
; /* PAP enabled or disabled */
381 char chap
; /* CHAP enabled or disabled */
382 unsigned char userid
[511]; /* List of User Id */
383 unsigned char passwd
[511]; /* List of passwords */
384 unsigned char sysname
[31]; /* Name of the system */
385 unsigned char ignore_dcd
; /* Protocol options: */
386 unsigned char ignore_cts
; /* Ignore these to determine */
387 unsigned char ignore_keepalive
; /* link status (Yes or No) */
388 unsigned char hdlc_streaming
; /* Hdlc streaming mode (Y/N) */
389 unsigned keepalive_tx_tmr
; /* transmit keepalive timer */
390 unsigned keepalive_rx_tmr
; /* receive keepalive timer */
391 unsigned keepalive_err_margin
; /* keepalive_error_tolerance */
392 unsigned slarp_timer
; /* SLARP request timer */
393 unsigned char ttl
; /* Time To Live for UDP security */
394 char interface
; /* RS-232/V.35, etc. */
395 char clocking
; /* external/internal */
396 unsigned bps
; /* data transfer rate */
397 unsigned mtu
; /* maximum transmit unit size */
401 /****** Kernel Interface ****************************************************/
403 #include <linux/fs.h> /* support for device drivers */
404 #include <linux/proc_fs.h> /* proc filesystem pragmatics */
405 #include <linux/inet.h> /* in_aton(), in_ntoa() prototypes */
406 #include <linux/netdevice.h> /* support for network drivers */
407 /*----------------------------------------------------------------------------
408 * WAN device data space.
410 typedef struct wan_device
412 unsigned magic
; /* magic number */
413 char* name
; /* -> WAN device name (ASCIIZ) */
414 void* private; /* -> driver private data */
415 unsigned config_id
; /* Configuration ID */
416 /****** hardware configuration ******/
417 unsigned ioport
; /* adapter I/O port base #1 */
418 char S514_cpu_no
[1]; /* PCI CPU Number */
419 unsigned char S514_slot_no
; /* PCI Slot Number */
420 unsigned long maddr
; /* dual-port memory address */
421 unsigned msize
; /* dual-port memory size */
422 int irq
; /* interrupt request level */
423 int dma
; /* DMA request level */
424 unsigned bps
; /* data transfer rate */
425 unsigned mtu
; /* max physical transmit unit size */
426 unsigned udp_port
; /* UDP port for management */
427 unsigned char ttl
; /* Time To Live for UDP security */
428 unsigned enable_tx_int
; /* Transmit Interrupt enabled or not */
429 char interface
; /* RS-232/V.35, etc. */
430 char clocking
; /* external/internal */
431 char line_coding
; /* NRZ/NRZI/FM0/FM1, etc. */
432 char station
; /* DTE/DCE, primary/secondary, etc. */
433 char connection
; /* permanent/switched/on-demand */
434 char signalling
; /* Signalling RS232 or V35 */
435 char read_mode
; /* read mode: Polling or interrupt */
436 char new_if_cnt
; /* Number of interfaces per wanpipe */
437 char del_if_cnt
; /* Number of times del_if() gets called */
438 unsigned char piggyback
; /* Piggibacking a port */
439 unsigned hw_opt
[4]; /* other hardware options */
440 /****** status and statistics *******/
441 char state
; /* device state */
442 char api_status
; /* device api status */
444 struct net_device_stats stats
; /* interface statistics */
446 struct enet_statistics stats
; /* interface statistics */
448 unsigned reserved
[16]; /* reserved for future use */
449 unsigned critical
; /* critical section flag */
450 /****** device management methods ***/
451 int (*setup
) (struct wan_device
*wandev
, wandev_conf_t
*conf
);
452 int (*shutdown
) (struct wan_device
*wandev
);
453 int (*update
) (struct wan_device
*wandev
);
454 int (*ioctl
) (struct wan_device
*wandev
, unsigned cmd
,
456 int (*new_if
) (struct wan_device
*wandev
, struct net_device
*dev
,
458 int (*del_if
) (struct wan_device
*wandev
, struct net_device
*dev
);
459 /****** maintained by the router ****/
460 struct wan_device
* next
; /* -> next device */
461 struct net_device
* dev
; /* list of network interfaces */
462 unsigned ndev
; /* number of interfaces */
463 struct proc_dir_entry
*dent
; /* proc filesystem entry */
466 /* Public functions available for device drivers */
467 extern int register_wan_device(wan_device_t
*wandev
);
468 extern int unregister_wan_device(char *name
);
469 unsigned short wanrouter_type_trans(struct sk_buff
*skb
, struct net_device
*dev
);
470 int wanrouter_encapsulate(struct sk_buff
*skb
, struct net_device
*dev
);
472 /* Proc interface functions. These must not be called by the drivers! */
473 extern int wanrouter_proc_init(void);
474 extern void wanrouter_proc_cleanup(void);
475 extern int wanrouter_proc_add(wan_device_t
*wandev
);
476 extern int wanrouter_proc_delete(wan_device_t
*wandev
);
477 extern int wanrouter_ioctl( struct inode
*inode
, struct file
*file
, unsigned int cmd
, unsigned long arg
);
480 extern wan_device_t
*router_devlist
; /* list of registered devices */
482 #endif /* __KERNEL__ */
483 #endif /* _ROUTER_H */