1 /*****************************************************************************
2 * sdla_ppp.c WANPIPE(tm) Multiprotocol WAN Link Driver. PPP module.
4 * Author: Nenad Corbic <ncorbic@sangoma.com>
6 * Copyright: (c) 1995-2001 Sangoma Technologies Inc.
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version
11 * 2 of the License, or (at your option) any later version.
12 * ============================================================================
13 * Feb 28, 2001 Nenad Corbic o Updated if_tx_timeout() routine for
15 * Nov 29, 2000 Nenad Corbic o Added the 2.4.x kernel support:
16 * get_ip_address() function has moved
17 * into the ppp_poll() routine. It cannot
18 * be called from an interrupt.
19 * Nov 07, 2000 Nenad Corbic o Added security features for UDP debugging:
20 * Deny all and specify allowed requests.
21 * May 02, 2000 Nenad Corbic o Added the dynamic interface shutdown
22 * option. When the link goes down, the
23 * network interface IFF_UP flag is reset.
24 * Mar 06, 2000 Nenad Corbic o Bug Fix: corrupted mbox recovery.
25 * Feb 25, 2000 Nenad Corbic o Fixed the FT1 UDP debugger problem.
26 * Feb 09, 2000 Nenad Coribc o Shutdown bug fix. update() was called
27 * with NULL dev pointer: no check.
28 * Jan 24, 2000 Nenad Corbic o Disabled use of CMD complete inter.
29 * Dev 15, 1999 Nenad Corbic o Fixed up header files for 2.0.X kernels
30 * Oct 25, 1999 Nenad Corbic o Support for 2.0.X kernels
31 * Moved dynamic route processing into
33 * Oct 07, 1999 Nenad Corbic o Support for S514 PCI card.
34 * Gideon Hack o UPD and Updates executed using timer interrupt
35 * Sep 10, 1999 Nenad Corbic o Fixed up the /proc statistics
36 * Jul 20, 1999 Nenad Corbic o Remove the polling routines and use
38 * Sep 17, 1998 Jaspreet Singh o Updates for 2.2.X Kernels.
39 * Aug 13, 1998 Jaspreet Singh o Improved Line Tracing.
40 * Jun 22, 1998 David Fong o Added remote IP address assignment
41 * Mar 15, 1998 Alan Cox o 2.1.8x basic port.
42 * Apr 16, 1998 Jaspreet Singh o using htons() for the IPX protocol.
43 * Dec 09, 1997 Jaspreet Singh o Added PAP and CHAP.
44 * o Implemented new routines like
45 * ppp_set_inbnd_auth(), ppp_set_outbnd_auth(),
46 * tokenize() and strstrip().
47 * Nov 27, 1997 Jaspreet Singh o Added protection against enabling of irqs
48 * while they have been disabled.
49 * Nov 24, 1997 Jaspreet Singh o Fixed another RACE condition caused by
50 * disabling and enabling of irqs.
51 * o Added new counters for stats on disable/enable
53 * Nov 10, 1997 Jaspreet Singh o Initialized 'skb->mac.raw' to 'skb->data'
54 * before every netif_rx().
55 * o Free up the device structure in del_if().
56 * Nov 07, 1997 Jaspreet Singh o Changed the delay to zero for Line tracing
58 * Oct 20, 1997 Jaspreet Singh o Added hooks in for Router UP time.
59 * Oct 16, 1997 Jaspreet Singh o The critical flag is used to maintain flow
60 * control by avoiding RACE conditions. The
61 * cli() and restore_flags() are taken out.
62 * A new structure, "ppp_private_area", is added
63 * to provide Driver Statistics.
64 * Jul 21, 1997 Jaspreet Singh o Protected calls to sdla_peek() by adding
65 * save_flags(), cli() and restore_flags().
66 * Jul 07, 1997 Jaspreet Singh o Added configurable TTL for UDP packets
67 * o Added ability to discard mulitcast and
68 * broacast source addressed packets.
69 * Jun 27, 1997 Jaspreet Singh o Added FT1 monitor capabilities
70 * New case (0x25) statement in if_send routine.
71 * Added a global variable rCount to keep track
72 * of FT1 status enabled on the board.
73 * May 22, 1997 Jaspreet Singh o Added change in the PPP_SET_CONFIG command for
74 * 508 card to reflect changes in the new
75 * ppp508.sfm for supporting:continous transmission
76 * of Configure-Request packets without receiving a
78 * OR-ed 0x300 to conf_flags
79 * o Changed connect_tmout from 900 to 0
80 * May 21, 1997 Jaspreet Singh o Fixed UDP Management for multiple boards
81 * Apr 25, 1997 Farhan Thawar o added UDP Management stuff
82 * Mar 11, 1997 Farhan Thawar Version 3.1.1
83 * o fixed (+1) bug in rx_intr()
84 * o changed if_send() to return 0 if
85 * wandev.critical() is true
86 * o free socket buffer in if_send() if
88 * Jan 15, 1997 Gene Kozin Version 3.1.0
89 * o implemented exec() entry point
90 * Jan 06, 1997 Gene Kozin Initial version.
91 *****************************************************************************/
93 #include <linux/module.h>
94 #include <linux/kernel.h> /* printk(), and other useful stuff */
95 #include <linux/stddef.h> /* offsetof(), etc. */
96 #include <linux/errno.h> /* return codes */
97 #include <linux/string.h> /* inline memset(), etc. */
98 #include <linux/slab.h> /* kmalloc(), kfree() */
99 #include <linux/wanrouter.h> /* WAN router definitions */
100 #include <linux/wanpipe.h> /* WANPIPE common user API definitions */
101 #include <linux/if_arp.h> /* ARPHRD_* defines */
102 #include <asm/byteorder.h> /* htons(), etc. */
103 #include <linux/in.h> /* sockaddr_in */
106 #include <asm/uaccess.h>
107 #include <linux/inetdevice.h>
108 #include <linux/netdevice.h>
110 #include <linux/if.h>
111 #include <linux/sdla_ppp.h> /* PPP firmware API definitions */
112 #include <linux/sdlasfm.h> /* S514 Type Definition */
113 /****** Defines & Macros ****************************************************/
115 #define PPP_DFLT_MTU 1500 /* default MTU */
116 #define PPP_MAX_MTU 4000 /* maximum MTU */
117 #define PPP_HDR_LEN 1
119 #define MAX_IP_ERRORS 100
121 #define CONNECT_TIMEOUT (90*HZ) /* link connection timeout */
122 #define HOLD_DOWN_TIME (5*HZ) /* link hold down time : Changed from 30 to 5 */
124 /* For handle_IPXWAN() */
125 #define CVHexToAscii(b) (((unsigned char)(b) > (unsigned char)9) ? ((unsigned char)'A' + ((unsigned char)(b) - (unsigned char)10)) : ((unsigned char)'0' + (unsigned char)(b)))
127 /* Macro for enabling/disabling debugging comments */
130 #define NEX_PRINTK(format, a...) printk(format, ## a)
132 #define NEX_PRINTK(format, a...)
133 #endif /* NEX_DEBUG */
135 #define DCD(a) ( a & 0x08 ? "HIGH" : "LOW" )
136 #define CTS(a) ( a & 0x20 ? "HIGH" : "LOW" )
137 #define LCP(a) ( a == 0x09 ? "OPEN" : "CLOSED" )
138 #define IP(a) ( a == 0x09 ? "ENABLED" : "DISABLED" )
140 #define TMR_INT_ENABLED_UPDATE 0x01
141 #define TMR_INT_ENABLED_PPP_EVENT 0x02
142 #define TMR_INT_ENABLED_UDP 0x04
143 #define TMR_INT_ENABLED_CONFIG 0x20
145 /* Set Configuraton Command Definitions */
146 #define PERCENT_TX_BUFF 60
147 #define TIME_BETWEEN_CONF_REQ 30
148 #define TIME_BETWEEN_PAP_CHAP_REQ 30
149 #define WAIT_PAP_CHAP_WITHOUT_REPLY 300
150 #define WAIT_AFTER_DCD_CTS_LOW 5
151 #define TIME_DCD_CTS_LOW_AFTER_LNK_DOWN 10
152 #define WAIT_DCD_HIGH_AFTER_ENABLE_COMM 900
153 #define MAX_CONF_REQ_WITHOUT_REPLY 10
154 #define MAX_TERM_REQ_WITHOUT_REPLY 2
155 #define NUM_CONF_NAK_WITHOUT_REPLY 5
156 #define NUM_AUTH_REQ_WITHOUT_REPLY 10
158 #define END_OFFSET 0x1F0
161 /******Data Structures*****************************************************/
163 /* This structure is placed in the private data area of the device structure.
164 * The card structure used to occupy the private area but now the following
165 * structure will incorporate the card structure along with PPP specific data
168 typedef struct ppp_private_area
170 struct net_device *slave;
172 unsigned long router_start_time; /*router start time in sec */
173 unsigned long tick_counter; /*used for 5 second counter*/
174 unsigned mc; /*multicast support on or off*/
175 unsigned char enable_IPX;
176 unsigned long network_number;
179 unsigned char sysname[31]; /* system name for in-bnd auth*/
180 unsigned char userid[511]; /* list of user ids */
181 unsigned char passwd[511]; /* list of passwords */
182 unsigned protocol; /* SKB Protocol */
183 u32 ip_local; /* Local IP Address */
184 u32 ip_remote; /* remote IP Address */
189 unsigned char timer_int_enabled; /* Who enabled the timer inter*/
190 unsigned char update_comms_stats; /* Used by update function */
191 unsigned long curr_trace_addr; /* Trace information */
192 unsigned long start_trace_addr;
193 unsigned long end_trace_addr;
195 unsigned char interface_down; /* Brind down interface when channel
197 unsigned long config_wait_timeout; /* After if_open() if in dynamic if mode,
198 wait a few seconds before configuring */
200 unsigned short udp_pkt_lgth;
202 char udp_pkt_data[MAX_LGTH_UDP_MGNT_PKT];
204 /* PPP specific statistics */
206 if_send_stat_t if_send_stat;
207 rx_intr_stat_t rx_intr_stat;
208 pipe_mgmt_stat_t pipe_mgmt_stat;
210 unsigned long router_up_time;
212 /* Polling work queue entry. Each interface
213 * has its own work queue entry, which is used
214 * to defer events from the interrupt */
215 struct work_struct poll_work;
216 struct timer_list poll_delay_timer;
224 /* variable for keeping track of enabling/disabling FT1 monitor status */
225 static int rCount = 0;
227 extern void disable_irq(unsigned int);
228 extern void enable_irq(unsigned int);
230 /****** Function Prototypes *************************************************/
232 /* WAN link driver entry points. These are called by the WAN router module. */
233 static int update(struct wan_device *wandev);
234 static int new_if(struct wan_device *wandev, struct net_device *dev,
236 static int del_if(struct wan_device *wandev, struct net_device *dev);
238 /* WANPIPE-specific entry points */
239 static int wpp_exec (struct sdla *card, void *u_cmd, void *u_data);
241 /* Network device interface */
242 static int if_init(struct net_device *dev);
243 static int if_open(struct net_device *dev);
244 static int if_close(struct net_device *dev);
245 static int if_header(struct sk_buff *skb, struct net_device *dev,
247 void *daddr, void *saddr, unsigned len);
249 static void if_tx_timeout(struct net_device *dev);
251 static int if_rebuild_hdr(struct sk_buff *skb);
252 static struct net_device_stats *if_stats(struct net_device *dev);
253 static int if_send(struct sk_buff *skb, struct net_device *dev);
256 /* PPP firmware interface functions */
257 static int ppp_read_version(sdla_t *card, char *str);
258 static int ppp_set_outbnd_auth(sdla_t *card, ppp_private_area_t *ppp_priv_area);
259 static int ppp_set_inbnd_auth(sdla_t *card, ppp_private_area_t *ppp_priv_area);
260 static int ppp_configure(sdla_t *card, void *data);
261 static int ppp_set_intr_mode(sdla_t *card, unsigned char mode);
262 static int ppp_comm_enable(sdla_t *card);
263 static int ppp_comm_disable(sdla_t *card);
264 static int ppp_comm_disable_shutdown(sdla_t *card);
265 static int ppp_get_err_stats(sdla_t *card);
266 static int ppp_send(sdla_t *card, void *data, unsigned len, unsigned proto);
267 static int ppp_error(sdla_t *card, int err, ppp_mbox_t *mb);
269 static void wpp_isr(sdla_t *card);
270 static void rx_intr(sdla_t *card);
271 static void event_intr(sdla_t *card);
272 static void timer_intr(sdla_t *card);
274 /* Background polling routines */
275 static void process_route(sdla_t *card);
276 static void retrigger_comm(sdla_t *card);
278 /* Miscellaneous functions */
279 static int read_info( sdla_t *card );
280 static int read_connection_info (sdla_t *card);
281 static void remove_route( sdla_t *card );
282 static int config508(struct net_device *dev, sdla_t *card);
283 static void show_disc_cause(sdla_t * card, unsigned cause);
284 static int reply_udp( unsigned char *data, unsigned int mbox_len );
285 static void process_udp_mgmt_pkt(sdla_t *card, struct net_device *dev,
286 ppp_private_area_t *ppp_priv_area);
287 static void init_ppp_tx_rx_buff( sdla_t *card );
288 static int intr_test( sdla_t *card );
289 static int udp_pkt_type( struct sk_buff *skb , sdla_t *card);
290 static void init_ppp_priv_struct( ppp_private_area_t *ppp_priv_area);
291 static void init_global_statistics( sdla_t *card );
292 static int tokenize(char *str, char **tokens);
293 static char* strstrip(char *str, char *s);
294 static int chk_bcast_mcast_addr(sdla_t* card, struct net_device* dev,
295 struct sk_buff *skb);
297 static int config_ppp (sdla_t *);
298 static void ppp_poll(struct net_device *dev);
299 static void trigger_ppp_poll(struct net_device *dev);
300 static void ppp_poll_delay (unsigned long dev_ptr);
303 static int Read_connection_info;
304 static int Intr_test_counter;
305 static unsigned short available_buffer_space;
309 static void switch_net_numbers(unsigned char *sendpacket, unsigned long network_number,
310 unsigned char incoming);
311 static int handle_IPXWAN(unsigned char *sendpacket, char *devname, unsigned char enable_PX,
312 unsigned long network_number, unsigned short proto);
315 static void s508_lock (sdla_t *card, unsigned long *smp_flags);
316 static void s508_unlock (sdla_t *card, unsigned long *smp_flags);
318 static int store_udp_mgmt_pkt(char udp_pkt_src, sdla_t* card,
319 struct sk_buff *skb, struct net_device* dev,
320 ppp_private_area_t* ppp_priv_area );
321 static unsigned short calc_checksum (char *data, int len);
322 static void disable_comm (sdla_t *card);
323 static int detect_and_fix_tx_bug (sdla_t *card);
325 /****** Public Functions ****************************************************/
327 /*============================================================================
328 * PPP protocol initialization routine.
330 * This routine is called by the main WANPIPE module during setup. At this
331 * point adapter is completely initialized and firmware is running.
332 * o read firmware version (to make sure it's alive)
333 * o configure adapter
334 * o initialize protocol-specific fields of the adapter data space.
339 int wpp_init(sdla_t *card, wandev_conf_t *conf)
347 /* Verify configuration ID */
348 if (conf->config_id != WANCONFIG_PPP) {
350 printk(KERN_INFO "%s: invalid configuration ID %u!\n",
351 card->devname, conf->config_id);
356 /* Initialize miscellaneous pointers to structures on the adapter */
357 switch (card->hw.type) {
360 card->mbox =(void*)(card->hw.dpmbase + PPP508_MB_OFFS);
361 card->flags=(void*)(card->hw.dpmbase + PPP508_FLG_OFFS);
365 card->mbox =(void*)(card->hw.dpmbase + PPP514_MB_OFFS);
366 card->flags=(void*)(card->hw.dpmbase + PPP514_FLG_OFFS);
375 /* Read firmware version. Note that when adapter initializes, it
376 * clears the mailbox, so it may appear that the first command was
377 * executed successfully when in fact it was merely erased. To work
378 * around this, we execute the first command twice.
380 if (ppp_read_version(card, NULL) || ppp_read_version(card, u.str))
383 printk(KERN_INFO "%s: running PPP firmware v%s\n",card->devname, u.str);
384 /* Adjust configuration and set defaults */
385 card->wandev.mtu = (conf->mtu) ?
386 min_t(unsigned int, conf->mtu, PPP_MAX_MTU) : PPP_DFLT_MTU;
388 card->wandev.bps = conf->bps;
389 card->wandev.interface = conf->interface;
390 card->wandev.clocking = conf->clocking;
391 card->wandev.station = conf->station;
392 card->isr = &wpp_isr;
394 card->exec = &wpp_exec;
395 card->wandev.update = &update;
396 card->wandev.new_if = &new_if;
397 card->wandev.del_if = &del_if;
398 card->wandev.udp_port = conf->udp_port;
399 card->wandev.ttl = conf->ttl;
400 card->wandev.state = WAN_DISCONNECTED;
401 card->disable_comm = &disable_comm;
402 card->irq_dis_if_send_count = 0;
403 card->irq_dis_poll_count = 0;
404 card->u.p.authenticator = conf->u.ppp.authenticator;
405 card->u.p.ip_mode = conf->u.ppp.ip_mode ?
406 conf->u.ppp.ip_mode : WANOPT_PPP_STATIC;
407 card->TracingEnabled = 0;
408 Read_connection_info = 1;
410 /* initialize global statistics */
411 init_global_statistics( card );
415 if (!card->configured){
418 Intr_test_counter = 0;
419 err = intr_test(card);
421 if(err || (Intr_test_counter < MAX_INTR_TEST_COUNTER)) {
422 printk("%s: Interrupt Test Failed, Counter: %i\n",
423 card->devname, Intr_test_counter);
424 printk( "%s: Please choose another interrupt\n",card->devname);
428 printk(KERN_INFO "%s: Interrupt Test Passed, Counter: %i\n",
429 card->devname, Intr_test_counter);
430 card->configured = 1;
433 ppp_set_intr_mode(card, PPP_INTR_TIMER);
435 /* Turn off the transmit and timer interrupt */
436 flags->imask &= ~PPP_INTR_TIMER;
438 printk(KERN_INFO "\n");
443 /******* WAN Device Driver Entry Points *************************************/
445 /*============================================================================
446 * Update device status & statistics.
448 static int update(struct wan_device *wandev)
450 sdla_t* card = wandev->private;
451 struct net_device* dev;
452 volatile ppp_private_area_t *ppp_priv_area;
453 ppp_flags_t *flags = card->flags;
454 unsigned long timeout;
457 if ((wandev == NULL) || (wandev->private == NULL))
460 if (wandev->state == WAN_UNCONFIGURED)
463 /* Shutdown bug fix. This function can be
464 * called with NULL dev pointer during
467 if ((dev=card->wandev.dev) == NULL){
471 if ((ppp_priv_area=dev->priv) == NULL){
475 ppp_priv_area->update_comms_stats = 2;
476 ppp_priv_area->timer_int_enabled |= TMR_INT_ENABLED_UPDATE;
477 flags->imask |= PPP_INTR_TIMER;
479 /* wait a maximum of 1 second for the statistics to be updated */
482 if(ppp_priv_area->update_comms_stats == 0){
485 if ((jiffies - timeout) > (1 * HZ)){
486 ppp_priv_area->update_comms_stats = 0;
487 ppp_priv_area->timer_int_enabled &=
488 ~TMR_INT_ENABLED_UPDATE;
496 /*============================================================================
497 * Create new logical channel.
498 * This routine is called by the router when ROUTER_IFNEW IOCTL is being
500 * o parse media- and hardware-specific configuration
501 * o make sure that a new channel can be created
502 * o allocate resources, if necessary
503 * o prepare network device structure for registaration.
506 * < 0 failure (channel will not be created)
508 static int new_if(struct wan_device *wandev, struct net_device *dev,
511 sdla_t *card = wandev->private;
512 ppp_private_area_t *ppp_priv_area;
518 printk(KERN_INFO "%s: Configuring Interface: %s\n",
519 card->devname, conf->name);
521 if ((conf->name[0] == '\0') || (strlen(conf->name) > WAN_IFNAME_SZ)) {
523 printk(KERN_INFO "%s: Invalid interface name!\n",
529 /* allocate and initialize private data */
530 ppp_priv_area = kmalloc(sizeof(ppp_private_area_t), GFP_KERNEL);
532 if( ppp_priv_area == NULL )
535 memset(ppp_priv_area, 0, sizeof(ppp_private_area_t));
537 ppp_priv_area->card = card;
539 /* initialize data */
540 strcpy(card->u.p.if_name, conf->name);
542 /* initialize data in ppp_private_area structure */
544 init_ppp_priv_struct( ppp_priv_area );
546 ppp_priv_area->mc = conf->mc;
547 ppp_priv_area->pap = conf->pap;
548 ppp_priv_area->chap = conf->chap;
550 /* Option to bring down the interface when
551 * the link goes down */
553 set_bit(DYN_OPT_ON,&ppp_priv_area->interface_down);
554 printk("%s: Dynamic interface configuration enabled\n",
558 /* If no user ids are specified */
559 if(!strlen(conf->userid) && (ppp_priv_area->pap||ppp_priv_area->chap)){
560 kfree(ppp_priv_area);
564 /* If no passwords are specified */
565 if(!strlen(conf->passwd) && (ppp_priv_area->pap||ppp_priv_area->chap)){
566 kfree(ppp_priv_area);
570 if(strlen(conf->sysname) > 31){
571 kfree(ppp_priv_area);
575 /* If no system name is specified */
576 if(!strlen(conf->sysname) && (card->u.p.authenticator)){
577 kfree(ppp_priv_area);
581 /* copy the data into the ppp private structure */
582 memcpy(ppp_priv_area->userid, conf->userid, strlen(conf->userid));
583 memcpy(ppp_priv_area->passwd, conf->passwd, strlen(conf->passwd));
584 memcpy(ppp_priv_area->sysname, conf->sysname, strlen(conf->sysname));
587 ppp_priv_area->enable_IPX = conf->enable_IPX;
588 if (conf->network_number){
589 ppp_priv_area->network_number = conf->network_number;
591 ppp_priv_area->network_number = 0xDEADBEEF;
594 /* Tells us that if this interface is a
596 if ((ppp_priv_area->gateway = conf->gateway) == WANOPT_YES){
597 printk(KERN_INFO "%s: Interface %s is set as a gateway.\n",
598 card->devname,card->u.p.if_name);
601 /* prepare network device data space for registration */
602 strcpy(dev->name,card->u.p.if_name);
604 dev->init = &if_init;
605 dev->priv = ppp_priv_area;
606 dev->mtu = min_t(unsigned int, dev->mtu, card->wandev.mtu);
608 /* Initialize the polling work routine */
609 INIT_WORK(&ppp_priv_area->poll_work, (void*)(void*)ppp_poll, dev);
611 /* Initialize the polling delay timer */
612 init_timer(&ppp_priv_area->poll_delay_timer);
613 ppp_priv_area->poll_delay_timer.data = (unsigned long)dev;
614 ppp_priv_area->poll_delay_timer.function = ppp_poll_delay;
617 /* Since we start with dummy IP addresses we can say
618 * that route exists */
619 printk(KERN_INFO "\n");
624 /*============================================================================
625 * Delete logical channel.
627 static int del_if(struct wan_device *wandev, struct net_device *dev)
632 static void disable_comm (sdla_t *card)
634 ppp_comm_disable_shutdown(card);
638 /****** WANPIPE-specific entry points ***************************************/
640 /*============================================================================
641 * Execute adapter interface command.
644 //FIXME: Why do we need this ????
645 static int wpp_exec(struct sdla *card, void *u_cmd, void *u_data)
647 ppp_mbox_t *mbox = card->mbox;
650 if (copy_from_user((void*)&mbox->cmd, u_cmd, sizeof(ppp_cmd_t)))
653 len = mbox->cmd.length;
657 if( copy_from_user((void*)&mbox->data, u_data, len))
662 /* execute command */
663 if (!sdla_exec(mbox))
667 if( copy_to_user(u_cmd, (void*)&mbox->cmd, sizeof(ppp_cmd_t)))
669 len = mbox->cmd.length;
671 if (len && u_data && copy_to_user(u_data, (void*)&mbox->data, len))
677 /****** Network Device Interface ********************************************/
679 /*============================================================================
680 * Initialize Linux network interface.
682 * This routine is called only once for each interface, during Linux network
683 * interface registration. Returning anything but zero will fail interface
686 static int if_init(struct net_device *dev)
688 ppp_private_area_t *ppp_priv_area = dev->priv;
689 sdla_t *card = ppp_priv_area->card;
690 struct wan_device *wandev = &card->wandev;
692 /* Initialize device driver entry points */
693 dev->open = &if_open;
694 dev->stop = &if_close;
695 dev->hard_header = &if_header;
696 dev->rebuild_header = &if_rebuild_hdr;
697 dev->hard_start_xmit = &if_send;
698 dev->get_stats = &if_stats;
699 dev->tx_timeout = &if_tx_timeout;
700 dev->watchdog_timeo = TX_TIMEOUT;
702 /* Initialize media-specific parameters */
703 dev->type = ARPHRD_PPP; /* ARP h/w type */
704 dev->flags |= IFF_POINTOPOINT;
705 dev->flags |= IFF_NOARP;
707 /* Enable Mulitcasting if specified by user*/
708 if (ppp_priv_area->mc == WANOPT_YES){
709 dev->flags |= IFF_MULTICAST;
712 dev->mtu = wandev->mtu;
713 dev->hard_header_len = PPP_HDR_LEN; /* media header length */
715 /* Initialize hardware parameters (just for reference) */
716 dev->irq = wandev->irq;
717 dev->dma = wandev->dma;
718 dev->base_addr = wandev->ioport;
719 dev->mem_start = wandev->maddr;
720 dev->mem_end = wandev->maddr + wandev->msize - 1;
722 /* Set transmit buffer queue length */
723 dev->tx_queue_len = 100;
724 SET_MODULE_OWNER(dev);
729 /*============================================================================
730 * Open network interface.
731 * o enable communications and interrupts.
732 * o prevent module from unloading by incrementing use count
734 * Return 0 if O.k. or errno.
736 static int if_open(struct net_device *dev)
738 ppp_private_area_t *ppp_priv_area = dev->priv;
739 sdla_t *card = ppp_priv_area->card;
741 //unsigned long smp_flags;
743 if (netif_running(dev))
748 netif_start_queue(dev);
750 do_gettimeofday( &tv );
751 ppp_priv_area->router_start_time = tv.tv_sec;
753 /* We cannot configure the card here because we don't
754 * have access to the interface IP addresses.
755 * Once the interface initilization is complete, we will be
756 * able to access the IP addresses. Therefore,
757 * configure the ppp link in the poll routine */
758 set_bit(0,&ppp_priv_area->config_ppp);
759 ppp_priv_area->config_wait_timeout=jiffies;
761 /* Start the PPP configuration after 1sec delay.
762 * This will give the interface initilization time
763 * to finish its configuration */
764 mod_timer(&ppp_priv_area->poll_delay_timer, jiffies + HZ);
768 /*============================================================================
769 * Close network interface.
770 * o if this is the last open, then disable communications and interrupts.
773 static int if_close(struct net_device *dev)
775 ppp_private_area_t *ppp_priv_area = dev->priv;
776 sdla_t *card = ppp_priv_area->card;
778 netif_stop_queue(dev);
781 del_timer (&ppp_priv_area->poll_delay_timer);
785 /*============================================================================
786 * Build media header.
788 * The trick here is to put packet type (Ethertype) into 'protocol' field of
789 * the socket buffer, so that we don't forget it. If packet type is not
790 * supported, set skb->protocol to 0 and discard packet later.
792 * Return: media header length.
794 static int if_header(struct sk_buff *skb, struct net_device *dev,
795 unsigned short type, void *daddr, void *saddr, unsigned len)
801 skb->protocol = htons(type);
811 /*============================================================================
812 * Re-build media header.
814 * Return: 1 physical address resolved.
815 * 0 physical address not resolved
817 static int if_rebuild_hdr (struct sk_buff *skb)
819 struct net_device *dev = skb->dev;
820 ppp_private_area_t *ppp_priv_area = dev->priv;
821 sdla_t *card = ppp_priv_area->card;
823 printk(KERN_INFO "%s: rebuild_header() called for interface %s!\n",
824 card->devname, dev->name);
828 /*============================================================================
829 * Handle transmit timeout event from netif watchdog
831 static void if_tx_timeout(struct net_device *dev)
833 ppp_private_area_t* chan = dev->priv;
834 sdla_t *card = chan->card;
836 /* If our device stays busy for at least 5 seconds then we will
837 * kick start the device by making dev->tbusy = 0. We expect
838 * that our device never stays busy more than 5 seconds. So this
839 * is only used as a last resort.
842 ++ chan->if_send_stat.if_send_tbusy;
843 ++card->wandev.stats.collisions;
845 printk (KERN_INFO "%s: Transmit timed out on %s\n", card->devname,dev->name);
846 ++chan->if_send_stat.if_send_tbusy_timeout;
847 netif_wake_queue (dev);
852 /*============================================================================
853 * Send a packet on a network interface.
854 * o set tbusy flag (marks start of the transmission) to block a timer-based
855 * transmit from overlapping.
856 * o check link state. If link is not up, then drop the packet.
857 * o execute adapter send command.
858 * o free socket buffer
860 * Return: 0 complete (socket buffer must be freed)
861 * non-0 packet may be re-transmitted (tbusy must be set)
864 * 1. This routine is called either by the protocol stack or by the "net
865 * bottom half" (with interrupts enabled).
866 * 2. Setting tbusy flag will inhibit further transmit requests from the
867 * protocol stack and can be used for flow control with protocol layer.
869 static int if_send (struct sk_buff *skb, struct net_device *dev)
871 ppp_private_area_t *ppp_priv_area = dev->priv;
872 sdla_t *card = ppp_priv_area->card;
873 unsigned char *sendpacket;
874 unsigned long smp_flags;
875 ppp_flags_t *flags = card->flags;
879 ++ppp_priv_area->if_send_stat.if_send_entry;
881 netif_stop_queue(dev);
885 /* If we get here, some higher layer thinks we've missed an
888 printk(KERN_INFO "%s: interface %s got kicked!\n",
889 card->devname, dev->name);
891 ++ppp_priv_area->if_send_stat.if_send_skb_null;
893 netif_wake_queue(dev);
897 sendpacket = skb->data;
899 udp_type = udp_pkt_type( skb, card );
902 if (udp_type == UDP_PTPIPE_TYPE){
903 if(store_udp_mgmt_pkt(UDP_PKT_FRM_STACK, card, skb, dev,
905 flags->imask |= PPP_INTR_TIMER;
907 ++ppp_priv_area->if_send_stat.if_send_PIPE_request;
908 netif_start_queue(dev);
912 /* Check for broadcast and multicast addresses
913 * If found, drop (deallocate) a packet and return.
915 if(chk_bcast_mcast_addr(card, dev, skb)){
916 ++card->wandev.stats.tx_dropped;
917 dev_kfree_skb_any(skb);
918 netif_start_queue(dev);
923 if(card->hw.type != SDLA_S514){
924 s508_lock(card,&smp_flags);
927 if (test_and_set_bit(SEND_CRIT, (void*)&card->wandev.critical)) {
929 printk(KERN_INFO "%s: Critical in if_send: %lx\n",
930 card->wandev.name,card->wandev.critical);
932 ++card->wandev.stats.tx_dropped;
933 ++ppp_priv_area->if_send_stat.if_send_critical_non_ISR;
934 netif_start_queue(dev);
935 goto if_send_exit_crit;
938 if (card->wandev.state != WAN_CONNECTED) {
940 ++ppp_priv_area->if_send_stat.if_send_wan_disconnected;
941 ++card->wandev.stats.tx_dropped;
942 netif_start_queue(dev);
944 } else if (!skb->protocol) {
945 ++ppp_priv_area->if_send_stat.if_send_protocol_error;
946 ++card->wandev.stats.tx_errors;
947 netif_start_queue(dev);
951 /*If it's IPX change the network numbers to 0 if they're ours.*/
952 if( skb->protocol == htons(ETH_P_IPX) ) {
953 if(ppp_priv_area->enable_IPX) {
954 switch_net_numbers( skb->data,
955 ppp_priv_area->network_number, 0);
957 ++card->wandev.stats.tx_dropped;
958 netif_start_queue(dev);
959 goto if_send_exit_crit;
963 if (ppp_send(card, skb->data, skb->len, skb->protocol)) {
964 netif_stop_queue(dev);
965 ++ppp_priv_area->if_send_stat.if_send_adptr_bfrs_full;
966 ++ppp_priv_area->if_send_stat.if_send_tx_int_enabled;
968 ++ppp_priv_area->if_send_stat.if_send_bfr_passed_to_adptr;
969 ++card->wandev.stats.tx_packets;
970 card->wandev.stats.tx_bytes += skb->len;
971 netif_start_queue(dev);
972 dev->trans_start = jiffies;
978 if (!(err=netif_queue_stopped(dev))){
979 dev_kfree_skb_any(skb);
981 ppp_priv_area->tick_counter = jiffies;
982 flags->imask |= PPP_INTR_TXRDY; /* unmask Tx interrupts */
985 clear_bit(SEND_CRIT,&card->wandev.critical);
986 if(card->hw.type != SDLA_S514){
987 s508_unlock(card,&smp_flags);
994 /*=============================================================================
995 * Store a UDP management packet for later processing.
998 static int store_udp_mgmt_pkt(char udp_pkt_src, sdla_t* card,
999 struct sk_buff *skb, struct net_device* dev,
1000 ppp_private_area_t* ppp_priv_area )
1002 int udp_pkt_stored = 0;
1004 if(!ppp_priv_area->udp_pkt_lgth && (skb->len<=MAX_LGTH_UDP_MGNT_PKT)){
1005 ppp_priv_area->udp_pkt_lgth = skb->len;
1006 ppp_priv_area->udp_pkt_src = udp_pkt_src;
1007 memcpy(ppp_priv_area->udp_pkt_data, skb->data, skb->len);
1008 ppp_priv_area->timer_int_enabled |= TMR_INT_ENABLED_UDP;
1009 ppp_priv_area->protocol = skb->protocol;
1012 if (skb->len > MAX_LGTH_UDP_MGNT_PKT){
1013 printk(KERN_INFO "%s: PIPEMON UDP request too long : %i\n",
1014 card->devname, skb->len);
1016 printk(KERN_INFO "%s: PIPEMON UPD request already pending\n",
1019 ppp_priv_area->udp_pkt_lgth = 0;
1022 if(udp_pkt_src == UDP_PKT_FRM_STACK){
1023 dev_kfree_skb_any(skb);
1025 dev_kfree_skb_any(skb);
1028 return(udp_pkt_stored);
1033 /*============================================================================
1034 * Reply to UDP Management system.
1035 * Return length of reply.
1037 static int reply_udp( unsigned char *data, unsigned int mbox_len )
1039 unsigned short len, udp_length, temp, ip_length;
1040 unsigned long ip_temp;
1042 ppp_udp_pkt_t *p_udp_pkt = (ppp_udp_pkt_t *)data;
1044 /* Set length of packet */
1045 len = sizeof(ip_pkt_t)+
1051 /* fill in UDP reply */
1052 p_udp_pkt->wp_mgmt.request_reply = UDPMGMT_REPLY;
1054 /* fill in UDP length */
1055 udp_length = sizeof(udp_pkt_t)+
1061 /* put it on an even boundary */
1062 if ( udp_length & 0x0001 ) {
1068 temp = (udp_length<<8)|(udp_length>>8);
1069 p_udp_pkt->udp_pkt.udp_length = temp;
1072 /* swap UDP ports */
1073 temp = p_udp_pkt->udp_pkt.udp_src_port;
1074 p_udp_pkt->udp_pkt.udp_src_port =
1075 p_udp_pkt->udp_pkt.udp_dst_port;
1076 p_udp_pkt->udp_pkt.udp_dst_port = temp;
1079 /* add UDP pseudo header */
1081 *((unsigned short *)(p_udp_pkt->data+mbox_len+even_bound)) = temp;
1082 temp = (udp_length<<8)|(udp_length>>8);
1083 *((unsigned short *)(p_udp_pkt->data+mbox_len+even_bound+2)) = temp;
1085 /* calculate UDP checksum */
1086 p_udp_pkt->udp_pkt.udp_checksum = 0;
1087 p_udp_pkt->udp_pkt.udp_checksum =
1088 calc_checksum(&data[UDP_OFFSET],udp_length+UDP_OFFSET);
1090 /* fill in IP length */
1091 ip_length = udp_length + sizeof(ip_pkt_t);
1092 temp = (ip_length<<8)|(ip_length>>8);
1093 p_udp_pkt->ip_pkt.total_length = temp;
1095 /* swap IP addresses */
1096 ip_temp = p_udp_pkt->ip_pkt.ip_src_address;
1097 p_udp_pkt->ip_pkt.ip_src_address = p_udp_pkt->ip_pkt.ip_dst_address;
1098 p_udp_pkt->ip_pkt.ip_dst_address = ip_temp;
1100 /* fill in IP checksum */
1101 p_udp_pkt->ip_pkt.hdr_checksum = 0;
1102 p_udp_pkt->ip_pkt.hdr_checksum = calc_checksum(data,sizeof(ip_pkt_t));
1108 unsigned short calc_checksum (char *data, int len)
1110 unsigned short temp;
1111 unsigned long sum=0;
1114 for( i = 0; i <len; i+=2 ) {
1115 memcpy(&temp,&data[i],2);
1116 sum += (unsigned long)temp;
1119 while (sum >> 16 ) {
1120 sum = (sum & 0xffffUL) + (sum >> 16);
1123 temp = (unsigned short)sum;
1133 If incoming is 0 (outgoing)- if the net numbers is ours make it 0
1134 if incoming is 1 - if the net number is 0 make it ours
1137 static void switch_net_numbers(unsigned char *sendpacket, unsigned long network_number, unsigned char incoming)
1139 unsigned long pnetwork_number;
1141 pnetwork_number = (unsigned long)((sendpacket[6] << 24) +
1142 (sendpacket[7] << 16) + (sendpacket[8] << 8) +
1146 //If the destination network number is ours, make it 0
1147 if( pnetwork_number == network_number) {
1148 sendpacket[6] = sendpacket[7] = sendpacket[8] =
1149 sendpacket[9] = 0x00;
1152 //If the incoming network is 0, make it ours
1153 if( pnetwork_number == 0) {
1154 sendpacket[6] = (unsigned char)(network_number >> 24);
1155 sendpacket[7] = (unsigned char)((network_number &
1157 sendpacket[8] = (unsigned char)((network_number &
1159 sendpacket[9] = (unsigned char)(network_number &
1165 pnetwork_number = (unsigned long)((sendpacket[18] << 24) +
1166 (sendpacket[19] << 16) + (sendpacket[20] << 8) +
1170 //If the source network is ours, make it 0
1171 if( pnetwork_number == network_number) {
1172 sendpacket[18] = sendpacket[19] = sendpacket[20] =
1173 sendpacket[21] = 0x00;
1176 //If the source network is 0, make it ours
1177 if( pnetwork_number == 0 ) {
1178 sendpacket[18] = (unsigned char)(network_number >> 24);
1179 sendpacket[19] = (unsigned char)((network_number &
1181 sendpacket[20] = (unsigned char)((network_number &
1183 sendpacket[21] = (unsigned char)(network_number &
1187 } /* switch_net_numbers */
1189 /*============================================================================
1190 * Get ethernet-style interface statistics.
1191 * Return a pointer to struct net_device_stats.
1193 static struct net_device_stats *if_stats(struct net_device *dev)
1196 ppp_private_area_t *ppp_priv_area = dev->priv;
1199 if( ppp_priv_area == NULL )
1202 card = ppp_priv_area->card;
1203 return &card->wandev.stats;
1206 /****** PPP Firmware Interface Functions ************************************/
1208 /*============================================================================
1209 * Read firmware code version.
1210 * Put code version as ASCII string in str.
1212 static int ppp_read_version(sdla_t *card, char *str)
1214 ppp_mbox_t *mb = card->mbox;
1217 memset(&mb->cmd, 0, sizeof(ppp_cmd_t));
1218 mb->cmd.command = PPP_READ_CODE_VERSION;
1219 err = sdla_exec(mb) ? mb->cmd.result : CMD_TIMEOUT;
1223 ppp_error(card, err, mb);
1227 int len = mb->cmd.length;
1229 memcpy(str, mb->data, len);
1236 /*===========================================================================
1237 * Set Out-Bound Authentication.
1239 static int ppp_set_outbnd_auth (sdla_t *card, ppp_private_area_t *ppp_priv_area)
1241 ppp_mbox_t *mb = card->mbox;
1244 memset(&mb->cmd, 0, sizeof(ppp_cmd_t));
1245 memset(&mb->data, 0, (strlen(ppp_priv_area->userid) +
1246 strlen(ppp_priv_area->passwd) + 2 ) );
1247 memcpy(mb->data, ppp_priv_area->userid, strlen(ppp_priv_area->userid));
1248 memcpy((mb->data + strlen(ppp_priv_area->userid) + 1),
1249 ppp_priv_area->passwd, strlen(ppp_priv_area->passwd));
1251 mb->cmd.length = strlen(ppp_priv_area->userid) +
1252 strlen(ppp_priv_area->passwd) + 2 ;
1254 mb->cmd.command = PPP_SET_OUTBOUND_AUTH;
1256 err = sdla_exec(mb) ? mb->cmd.result : CMD_TIMEOUT;
1259 ppp_error(card, err, mb);
1264 /*===========================================================================
1265 * Set In-Bound Authentication.
1267 static int ppp_set_inbnd_auth (sdla_t *card, ppp_private_area_t *ppp_priv_area)
1269 ppp_mbox_t *mb = card->mbox;
1271 char* user_tokens[32];
1272 char* pass_tokens[32];
1273 int userids, passwds;
1276 memset(&mb->cmd, 0, sizeof(ppp_cmd_t));
1277 memset(&mb->data, 0, 1008);
1278 memcpy(mb->data, ppp_priv_area->sysname,
1279 strlen(ppp_priv_area->sysname));
1281 /* Parse the userid string and the password string and build a string
1282 to copy it to the data area of the command structure. The string
1283 will look like "SYS_NAME<NULL>USER1<NULL>PASS1<NULL>USER2<NULL>PASS2
1286 userids = tokenize( ppp_priv_area->userid, user_tokens);
1287 passwds = tokenize( ppp_priv_area->passwd, pass_tokens);
1289 if (userids != passwds){
1290 printk(KERN_INFO "%s: Number of passwords does not equal the number of user ids\n", card->devname);
1294 add_ptr = strlen(ppp_priv_area->sysname) + 1;
1295 for (i=0; i<userids; i++){
1296 memcpy((mb->data + add_ptr), user_tokens[i],
1297 strlen(user_tokens[i]));
1298 memcpy((mb->data + add_ptr + strlen(user_tokens[i]) + 1),
1299 pass_tokens[i], strlen(pass_tokens[i]));
1300 add_ptr = add_ptr + strlen(user_tokens[i]) + 1 +
1301 strlen(pass_tokens[i]) + 1;
1304 mb->cmd.length = add_ptr + 1;
1305 mb->cmd.command = PPP_SET_INBOUND_AUTH;
1307 err = sdla_exec(mb) ? mb->cmd.result : CMD_TIMEOUT;
1310 ppp_error(card, err, mb);
1316 /*============================================================================
1318 * Parse a string of the following syntax:
1320 * and fill array of tokens with pointers to string elements.
1323 static int tokenize (char *str, char **tokens)
1327 tokens[0] = strsep(&str, "/");
1328 while (tokens[cnt] && (cnt < 32 - 1))
1330 tokens[cnt] = strstrip(tokens[cnt], " \t");
1331 tokens[++cnt] = strsep(&str, "/");
1336 /*============================================================================
1337 * Strip leading and trailing spaces off the string str.
1339 static char* strstrip (char *str, char* s)
1341 char *eos = str + strlen(str); /* -> end of string */
1343 while (*str && strchr(s, *str))
1344 ++str /* strip leading spaces */
1346 while ((eos > str) && strchr(s, *(eos - 1)))
1347 --eos /* strip trailing spaces */
1352 /*============================================================================
1353 * Configure PPP firmware.
1355 static int ppp_configure(sdla_t *card, void *data)
1357 ppp_mbox_t *mb = card->mbox;
1358 int data_len = sizeof(ppp508_conf_t);
1361 memset(&mb->cmd, 0, sizeof(ppp_cmd_t));
1362 memcpy(mb->data, data, data_len);
1363 mb->cmd.length = data_len;
1364 mb->cmd.command = PPP_SET_CONFIG;
1365 err = sdla_exec(mb) ? mb->cmd.result : CMD_TIMEOUT;
1368 ppp_error(card, err, mb);
1373 /*============================================================================
1374 * Set interrupt mode.
1376 static int ppp_set_intr_mode(sdla_t *card, unsigned char mode)
1378 ppp_mbox_t *mb = card->mbox;
1379 ppp_intr_info_t *ppp_intr_data = (ppp_intr_info_t *) &mb->data[0];
1382 memset(&mb->cmd, 0, sizeof(ppp_cmd_t));
1383 ppp_intr_data->i_enable = mode;
1385 ppp_intr_data->irq = card->hw.irq;
1388 /* If timer has been enabled, set the timer delay to 1sec */
1390 ppp_intr_data->timer_len = 250; //5;//100; //250;
1394 mb->cmd.command = PPP_SET_INTR_FLAGS;
1395 err = sdla_exec(mb) ? mb->cmd.result : CMD_TIMEOUT;
1398 ppp_error(card, err, mb);
1404 /*============================================================================
1405 * Enable communications.
1407 static int ppp_comm_enable(sdla_t *card)
1409 ppp_mbox_t *mb = card->mbox;
1412 memset(&mb->cmd, 0, sizeof(ppp_cmd_t));
1413 mb->cmd.command = PPP_COMM_ENABLE;
1414 err = sdla_exec(mb) ? mb->cmd.result : CMD_TIMEOUT;
1417 ppp_error(card, err, mb);
1419 card->u.p.comm_enabled = 1;
1424 /*============================================================================
1425 * Disable communications.
1427 static int ppp_comm_disable(sdla_t *card)
1429 ppp_mbox_t *mb = card->mbox;
1432 memset(&mb->cmd, 0, sizeof(ppp_cmd_t));
1433 mb->cmd.command = PPP_COMM_DISABLE;
1434 err = sdla_exec(mb) ? mb->cmd.result : CMD_TIMEOUT;
1436 ppp_error(card, err, mb);
1438 card->u.p.comm_enabled = 0;
1443 static int ppp_comm_disable_shutdown(sdla_t *card)
1445 ppp_mbox_t *mb = card->mbox;
1446 ppp_intr_info_t *ppp_intr_data;
1453 ppp_intr_data = (ppp_intr_info_t *) &mb->data[0];
1455 /* Disable all interrupts */
1456 memset(&mb->cmd, 0, sizeof(ppp_cmd_t));
1457 ppp_intr_data->i_enable = 0;
1459 ppp_intr_data->irq = card->hw.irq;
1462 mb->cmd.command = PPP_SET_INTR_FLAGS;
1463 err = sdla_exec(mb) ? mb->cmd.result : CMD_TIMEOUT;
1465 /* Disable communicatinons */
1466 memset(&mb->cmd, 0, sizeof(ppp_cmd_t));
1467 mb->cmd.command = PPP_COMM_DISABLE;
1468 err = sdla_exec(mb) ? mb->cmd.result : CMD_TIMEOUT;
1470 card->u.p.comm_enabled = 0;
1477 /*============================================================================
1478 * Get communications error statistics.
1480 static int ppp_get_err_stats(sdla_t *card)
1482 ppp_mbox_t *mb = card->mbox;
1485 memset(&mb->cmd, 0, sizeof(ppp_cmd_t));
1486 mb->cmd.command = PPP_READ_ERROR_STATS;
1487 err = sdla_exec(mb) ? mb->cmd.result : CMD_TIMEOUT;
1489 if (err == CMD_OK) {
1491 ppp_err_stats_t* stats = (void*)mb->data;
1492 card->wandev.stats.rx_over_errors = stats->rx_overrun;
1493 card->wandev.stats.rx_crc_errors = stats->rx_bad_crc;
1494 card->wandev.stats.rx_missed_errors = stats->rx_abort;
1495 card->wandev.stats.rx_length_errors = stats->rx_lost;
1496 card->wandev.stats.tx_aborted_errors = stats->tx_abort;
1499 ppp_error(card, err, mb);
1504 /*============================================================================
1507 * 1 - no transmit buffers available
1509 static int ppp_send (sdla_t *card, void *data, unsigned len, unsigned proto)
1511 ppp_buf_ctl_t *txbuf = card->u.p.txbuf;
1516 sdla_poke(&card->hw, txbuf->buf.ptr, data, len);
1518 txbuf->length = len; /* frame length */
1520 if (proto == htons(ETH_P_IPX))
1521 txbuf->proto = 0x01; /* protocol ID */
1523 txbuf->proto = 0x00; /* protocol ID */
1525 txbuf->flag = 1; /* start transmission */
1527 /* Update transmit buffer control fields */
1528 card->u.p.txbuf = ++txbuf;
1530 if ((void*)txbuf > card->u.p.txbuf_last)
1531 card->u.p.txbuf = card->u.p.txbuf_base;
1536 /****** Firmware Error Handler **********************************************/
1538 /*============================================================================
1539 * Firmware error handler.
1540 * This routine is called whenever firmware command returns non-zero
1543 * Return zero if previous command has to be cancelled.
1545 static int ppp_error(sdla_t *card, int err, ppp_mbox_t *mb)
1547 unsigned cmd = mb->cmd.command;
1552 printk(KERN_ERR "%s: command 0x%02X timed out!\n",
1553 card->devname, cmd);
1557 printk(KERN_INFO "%s: command 0x%02X returned 0x%02X!\n"
1558 , card->devname, cmd, err);
1564 /****** Interrupt Handlers **************************************************/
1566 /*============================================================================
1567 * PPP interrupt service routine.
1569 static void wpp_isr (sdla_t *card)
1571 ppp_flags_t *flags = card->flags;
1572 char *ptr = &flags->iflag;
1573 struct net_device *dev = card->wandev.dev;
1577 ++card->statistics.isr_entry;
1579 if (!dev && flags->iflag != PPP_INTR_CMD){
1585 if (test_bit(PERI_CRIT, (void*)&card->wandev.critical)) {
1592 if(card->hw.type != SDLA_S514){
1593 if (test_bit(SEND_CRIT, (void*)&card->wandev.critical)) {
1594 ++card->statistics.isr_already_critical;
1595 printk (KERN_INFO "%s: Critical while in ISR!\n",
1603 switch (flags->iflag) {
1605 case PPP_INTR_RXRDY: /* receive interrupt 0x01 (bit 0)*/
1606 ++card->statistics.isr_rx;
1610 case PPP_INTR_TXRDY: /* transmit interrupt 0x02 (bit 1)*/
1611 ++card->statistics.isr_tx;
1612 flags->imask &= ~PPP_INTR_TXRDY;
1613 netif_wake_queue(dev);
1616 case PPP_INTR_CMD: /* interface command completed */
1617 ++Intr_test_counter;
1618 ++card->statistics.isr_intr_test;
1621 case PPP_INTR_MODEM: /* modem status change (DCD, CTS) 0x04 (bit 2)*/
1622 case PPP_INTR_DISC: /* Data link disconnected 0x10 (bit 4)*/
1623 case PPP_INTR_OPEN: /* Data link open 0x20 (bit 5)*/
1624 case PPP_INTR_DROP_DTR: /* DTR drop timeout expired 0x40 bit 6 */
1628 case PPP_INTR_TIMER:
1632 default: /* unexpected interrupt */
1633 ++card->statistics.isr_spurious;
1634 printk(KERN_INFO "%s: spurious interrupt 0x%02X!\n",
1635 card->devname, flags->iflag);
1636 printk(KERN_INFO "%s: ID Bytes = ",card->devname);
1637 for(i = 0; i < 8; i ++)
1638 printk(KERN_INFO "0x%02X ", *(ptr + 0x28 + i));
1639 printk(KERN_INFO "\n");
1647 /*============================================================================
1648 * Receive interrupt handler.
1650 static void rx_intr(sdla_t *card)
1652 ppp_buf_ctl_t *rxbuf = card->rxmb;
1653 struct net_device *dev = card->wandev.dev;
1654 ppp_private_area_t *ppp_priv_area;
1655 struct sk_buff *skb;
1659 ppp_flags_t *flags = card->flags;
1660 char *ptr = &flags->iflag;
1664 if (rxbuf->flag != 0x01) {
1667 "%s: corrupted Rx buffer @ 0x%X, flag = 0x%02X!\n",
1668 card->devname, (unsigned)rxbuf, rxbuf->flag);
1670 printk(KERN_INFO "%s: ID Bytes = ",card->devname);
1672 for(i = 0; i < 8; i ++)
1673 printk(KERN_INFO "0x%02X ", *(ptr + 0x28 + i));
1674 printk(KERN_INFO "\n");
1676 ++card->statistics.rx_intr_corrupt_rx_bfr;
1679 /* Bug Fix: Mar 6 2000
1680 * If we get a corrupted mailbox, it means that driver
1681 * is out of sync with the firmware. There is no recovery.
1682 * If we don't turn off all interrupts for this card
1683 * the machine will crash.
1685 printk(KERN_INFO "%s: Critical router failure ...!!!\n", card->devname);
1686 printk(KERN_INFO "Please contact Sangoma Technologies !\n");
1687 ppp_set_intr_mode(card,0);
1691 if (dev && netif_running(dev) && dev->priv){
1693 len = rxbuf->length;
1694 ppp_priv_area = dev->priv;
1696 /* Allocate socket buffer */
1697 skb = dev_alloc_skb(len);
1701 /* Copy data to the socket buffer */
1702 unsigned addr = rxbuf->buf.ptr;
1704 if ((addr + len) > card->u.p.rx_top + 1) {
1706 unsigned tmp = card->u.p.rx_top - addr + 1;
1707 buf = skb_put(skb, tmp);
1708 sdla_peek(&card->hw, addr, buf, tmp);
1709 addr = card->u.p.rx_base;
1712 buf = skb_put(skb, len);
1713 sdla_peek(&card->hw, addr, buf, len);
1715 /* Decapsulate packet */
1716 switch (rxbuf->proto) {
1719 skb->protocol = htons(ETH_P_IP);
1723 skb->protocol = htons(ETH_P_IPX);
1727 udp_type = udp_pkt_type( skb, card );
1729 if (udp_type == UDP_PTPIPE_TYPE){
1731 /* Handle a UDP Request in Timer Interrupt */
1732 if(store_udp_mgmt_pkt(UDP_PKT_FRM_NETWORK, card, skb, dev,
1734 flags->imask |= PPP_INTR_TIMER;
1736 ++ppp_priv_area->rx_intr_stat.rx_intr_PIPE_request;
1739 } else if (handle_IPXWAN(skb->data,card->devname,
1740 ppp_priv_area->enable_IPX,
1741 ppp_priv_area->network_number,
1744 /* Handle an IPXWAN packet */
1745 if( ppp_priv_area->enable_IPX) {
1747 /* Make sure we are not already sending */
1748 if (!test_bit(SEND_CRIT, &card->wandev.critical)){
1749 ppp_send(card, skb->data, skb->len, htons(ETH_P_IPX));
1751 dev_kfree_skb_any(skb);
1754 ++card->wandev.stats.rx_dropped;
1757 /* Pass data up the protocol stack */
1759 skb->mac.raw = skb->data;
1761 ++card->wandev.stats.rx_packets;
1762 card->wandev.stats.rx_bytes += skb->len;
1763 ++ppp_priv_area->rx_intr_stat.rx_intr_bfr_passed_to_stack;
1765 dev->last_rx = jiffies;
1770 if (net_ratelimit()){
1771 printk(KERN_INFO "%s: no socket buffers available!\n",
1774 ++card->wandev.stats.rx_dropped;
1775 ++ppp_priv_area->rx_intr_stat.rx_intr_no_socket;
1779 ++card->statistics.rx_intr_dev_not_started;
1782 /* Release buffer element and calculate a pointer to the next one */
1784 card->rxmb = ++rxbuf;
1785 if ((void*)rxbuf > card->u.p.rxbuf_last)
1786 card->rxmb = card->u.p.rxbuf_base;
1790 void event_intr (sdla_t *card)
1793 struct net_device* dev = card->wandev.dev;
1794 ppp_private_area_t* ppp_priv_area = dev->priv;
1795 volatile ppp_flags_t *flags = card->flags;
1797 switch (flags->iflag){
1799 case PPP_INTR_MODEM: /* modem status change (DCD, CTS) 0x04 (bit 2)*/
1801 if (net_ratelimit()){
1802 printk (KERN_INFO "%s: Modem status: DCD=%s CTS=%s\n",
1803 card->devname, DCD(flags->mstatus), CTS(flags->mstatus));
1807 case PPP_INTR_DISC: /* Data link disconnected 0x10 (bit 4)*/
1809 NEX_PRINTK (KERN_INFO "Data link disconnected intr Cause %X\n",
1812 if (flags->disc_cause &
1813 (PPP_LOCAL_TERMINATION | PPP_DCD_CTS_DROP |
1814 PPP_REMOTE_TERMINATION)) {
1816 if (card->u.p.ip_mode == WANOPT_PPP_PEER) {
1817 set_bit(0,&Read_connection_info);
1819 wanpipe_set_state(card, WAN_DISCONNECTED);
1821 show_disc_cause(card, flags->disc_cause);
1822 ppp_priv_area->timer_int_enabled |= TMR_INT_ENABLED_PPP_EVENT;
1823 flags->imask |= PPP_INTR_TIMER;
1824 trigger_ppp_poll(dev);
1828 case PPP_INTR_OPEN: /* Data link open 0x20 (bit 5)*/
1830 NEX_PRINTK (KERN_INFO "%s: PPP Link Open, LCP=%s IP=%s\n",
1831 card->devname,LCP(flags->lcp_state),
1832 IP(flags->ip_state));
1834 if (flags->lcp_state == 0x09 &&
1835 (flags->ip_state == 0x09 || flags->ipx_state == 0x09)){
1837 /* Initialize the polling timer and set the state
1838 * to WAN_CONNNECTED */
1841 /* BUG FIX: When the protocol restarts, during heavy
1842 * traffic, board tx buffers and driver tx buffers
1843 * can go out of sync. This checks the condition
1844 * and if the tx buffers are out of sync, the
1845 * protocols are restarted.
1846 * I don't know why the board tx buffer is out
1847 * of sync. It could be that a packets is tx
1848 * while the link is down, but that is not
1849 * possible. The other possiblility is that the
1850 * firmware doesn't reinitialize properly.
1851 * FIXME: A better fix should be found.
1853 if (detect_and_fix_tx_bug(card)){
1855 ppp_comm_disable(card);
1857 wanpipe_set_state(card, WAN_DISCONNECTED);
1859 ppp_priv_area->timer_int_enabled |=
1860 TMR_INT_ENABLED_PPP_EVENT;
1861 flags->imask |= PPP_INTR_TIMER;
1865 card->state_tick = jiffies;
1866 wanpipe_set_state(card, WAN_CONNECTED);
1868 NEX_PRINTK(KERN_INFO "CON: L Tx: %lx B Tx: %lx || L Rx %lx B Rx %lx\n",
1869 (unsigned long)card->u.p.txbuf, *card->u.p.txbuf_next,
1870 (unsigned long)card->rxmb, *card->u.p.rxbuf_next);
1872 /* Tell timer interrupt that PPP event occurred */
1873 ppp_priv_area->timer_int_enabled |= TMR_INT_ENABLED_PPP_EVENT;
1874 flags->imask |= PPP_INTR_TIMER;
1876 /* If we are in PEER mode, we must first obtain the
1877 * IP information and then go into the poll routine */
1878 if (card->u.p.ip_mode != WANOPT_PPP_PEER){
1879 trigger_ppp_poll(dev);
1884 case PPP_INTR_DROP_DTR: /* DTR drop timeout expired 0x40 bit 6 */
1886 NEX_PRINTK(KERN_INFO "DTR Drop Timeout Interrrupt \n");
1888 if (card->u.p.ip_mode == WANOPT_PPP_PEER) {
1889 set_bit(0,&Read_connection_info);
1892 wanpipe_set_state(card, WAN_DISCONNECTED);
1894 show_disc_cause(card, flags->disc_cause);
1895 ppp_priv_area->timer_int_enabled |= TMR_INT_ENABLED_PPP_EVENT;
1896 flags->imask |= PPP_INTR_TIMER;
1897 trigger_ppp_poll(dev);
1901 printk(KERN_INFO "%s: Error, Invalid PPP Event\n",card->devname);
1907 /* TIMER INTERRUPT */
1909 void timer_intr (sdla_t *card)
1912 struct net_device* dev = card->wandev.dev;
1913 ppp_private_area_t* ppp_priv_area = dev->priv;
1914 ppp_flags_t *flags = card->flags;
1917 if (ppp_priv_area->timer_int_enabled & TMR_INT_ENABLED_CONFIG){
1918 if (!config_ppp(card)){
1919 ppp_priv_area->timer_int_enabled &=
1920 ~TMR_INT_ENABLED_CONFIG;
1924 /* Update statistics */
1925 if (ppp_priv_area->timer_int_enabled & TMR_INT_ENABLED_UPDATE){
1926 ppp_get_err_stats(card);
1927 if(!(--ppp_priv_area->update_comms_stats)){
1928 ppp_priv_area->timer_int_enabled &=
1929 ~TMR_INT_ENABLED_UPDATE;
1933 /* PPIPEMON UDP request */
1935 if (ppp_priv_area->timer_int_enabled & TMR_INT_ENABLED_UDP){
1936 process_udp_mgmt_pkt(card,dev, ppp_priv_area);
1937 ppp_priv_area->timer_int_enabled &= ~TMR_INT_ENABLED_UDP;
1941 if (ppp_priv_area->timer_int_enabled & TMR_INT_ENABLED_PPP_EVENT){
1943 if (card->wandev.state == WAN_DISCONNECTED){
1944 retrigger_comm(card);
1947 /* If the state is CONNECTING, it means that communicatins were
1948 * enabled. When the remote side enables its comminication we
1949 * should get an interrupt PPP_INTR_OPEN, thus turn off polling
1952 else if (card->wandev.state == WAN_CONNECTING){
1953 /* Turn off the timer interrupt */
1954 ppp_priv_area->timer_int_enabled &= ~TMR_INT_ENABLED_PPP_EVENT;
1957 /* If state is connected and we are in PEER mode
1958 * poll for an IP address which will be provided by remote end.
1960 else if ((card->wandev.state == WAN_CONNECTED &&
1961 card->u.p.ip_mode == WANOPT_PPP_PEER) &&
1962 test_bit(0,&Read_connection_info)){
1964 card->state_tick = jiffies;
1965 if (read_connection_info (card)){
1966 printk(KERN_INFO "%s: Failed to read PEER IP Addresses\n",
1969 clear_bit(0,&Read_connection_info);
1970 set_bit(1,&Read_connection_info);
1971 trigger_ppp_poll(dev);
1974 //FIXME Put the comment back int
1975 ppp_priv_area->timer_int_enabled &= ~TMR_INT_ENABLED_PPP_EVENT;
1978 }/* End of PPP_EVENT */
1981 /* Only disable the timer interrupt if there are no udp, statistic */
1982 /* updates or events pending */
1983 if(!ppp_priv_area->timer_int_enabled) {
1984 flags->imask &= ~PPP_INTR_TIMER;
1989 static int handle_IPXWAN(unsigned char *sendpacket, char *devname, unsigned char enable_IPX, unsigned long network_number, unsigned short proto)
1993 if( proto == htons(ETH_P_IPX) ) {
1994 //It's an IPX packet
1996 //Return 1 so we don't pass it up the stack.
2000 //It's not IPX so pass it up the stack.
2004 if( sendpacket[16] == 0x90 &&
2005 sendpacket[17] == 0x04)
2009 if( sendpacket[2] == 0x02 &&
2010 sendpacket[34] == 0x00)
2012 //It's a timer request packet
2013 printk(KERN_INFO "%s: Received IPXWAN Timer Request packet\n",devname);
2015 //Go through the routing options and answer no to every
2016 //option except Unnumbered RIP/SAP
2017 for(i = 41; sendpacket[i] == 0x00; i += 5)
2019 //0x02 is the option for Unnumbered RIP/SAP
2020 if( sendpacket[i + 4] != 0x02)
2022 sendpacket[i + 1] = 0;
2026 //Skip over the extended Node ID option
2027 if( sendpacket[i] == 0x04 )
2032 //We also want to turn off all header compression opt.
2033 for(; sendpacket[i] == 0x80 ;)
2035 sendpacket[i + 1] = 0;
2036 i += (sendpacket[i + 2] << 8) + (sendpacket[i + 3]) + 4;
2039 //Set the packet type to timer response
2040 sendpacket[34] = 0x01;
2042 printk(KERN_INFO "%s: Sending IPXWAN Timer Response\n",devname);
2044 else if( sendpacket[34] == 0x02 )
2046 //This is an information request packet
2047 printk(KERN_INFO "%s: Received IPXWAN Information Request packet\n",devname);
2049 //Set the packet type to information response
2050 sendpacket[34] = 0x03;
2052 //Set the router name
2053 sendpacket[51] = 'P';
2054 sendpacket[52] = 'T';
2055 sendpacket[53] = 'P';
2056 sendpacket[54] = 'I';
2057 sendpacket[55] = 'P';
2058 sendpacket[56] = 'E';
2059 sendpacket[57] = '-';
2060 sendpacket[58] = CVHexToAscii(network_number >> 28);
2061 sendpacket[59] = CVHexToAscii((network_number & 0x0F000000)>> 24);
2062 sendpacket[60] = CVHexToAscii((network_number & 0x00F00000)>> 20);
2063 sendpacket[61] = CVHexToAscii((network_number & 0x000F0000)>> 16);
2064 sendpacket[62] = CVHexToAscii((network_number & 0x0000F000)>> 12);
2065 sendpacket[63] = CVHexToAscii((network_number & 0x00000F00)>> 8);
2066 sendpacket[64] = CVHexToAscii((network_number & 0x000000F0)>> 4);
2067 sendpacket[65] = CVHexToAscii(network_number & 0x0000000F);
2068 for(i = 66; i < 99; i+= 1)
2073 printk(KERN_INFO "%s: Sending IPXWAN Information Response packet\n",devname);
2077 printk(KERN_INFO "%s: Unknown IPXWAN packet!\n",devname);
2081 //Set the WNodeID to our network address
2082 sendpacket[35] = (unsigned char)(network_number >> 24);
2083 sendpacket[36] = (unsigned char)((network_number & 0x00FF0000) >> 16);
2084 sendpacket[37] = (unsigned char)((network_number & 0x0000FF00) >> 8);
2085 sendpacket[38] = (unsigned char)(network_number & 0x000000FF);
2089 //If we get here it's an IPX-data packet, so it'll get passed up the stack.
2091 //switch the network numbers
2092 switch_net_numbers(sendpacket, network_number, 1);
2097 /****** Background Polling Routines ****************************************/
2099 /* All polling functions are invoked by the TIMER interrupt in the wpp_isr
2103 /*============================================================================
2104 * Monitor active link phase.
2106 static void process_route (sdla_t *card)
2108 ppp_flags_t *flags = card->flags;
2109 struct net_device *dev = card->wandev.dev;
2110 ppp_private_area_t *ppp_priv_area = dev->priv;
2112 if ((card->u.p.ip_mode == WANOPT_PPP_PEER) &&
2113 (flags->ip_state == 0x09)){
2115 /* We get ip_local from the firmware in PEER mode.
2116 * Therefore, if ip_local is 0, we failed to obtain
2117 * the remote IP address. */
2118 if (ppp_priv_area->ip_local == 0)
2121 printk(KERN_INFO "%s: IPCP State Opened.\n", card->devname);
2122 if (read_info( card )) {
2124 "%s: An error occurred in IP assignment.\n",
2127 struct in_device *in_dev = dev->ip_ptr;
2128 if (in_dev != NULL ) {
2129 struct in_ifaddr *ifa = in_dev->ifa_list;
2131 printk(KERN_INFO "%s: Assigned Lcl. Addr: %u.%u.%u.%u\n",
2132 card->devname, NIPQUAD(ifa->ifa_local));
2133 printk(KERN_INFO "%s: Assigned Rmt. Addr: %u.%u.%u.%u\n",
2134 card->devname, NIPQUAD(ifa->ifa_address));
2137 "%s: Error: Failed to add a route for PPP interface %s\n",
2138 card->devname,dev->name);
2144 /*============================================================================
2145 * Monitor physical link disconnected phase.
2146 * o if interface is up and the hold-down timeout has expired, then retry
2149 static void retrigger_comm(sdla_t *card)
2151 struct net_device *dev = card->wandev.dev;
2153 if (dev && ((jiffies - card->state_tick) > HOLD_DOWN_TIME)) {
2155 wanpipe_set_state(card, WAN_CONNECTING);
2157 if(ppp_comm_enable(card) == CMD_OK){
2158 init_ppp_tx_rx_buff( card );
2163 /****** Miscellaneous Functions *********************************************/
2165 /*============================================================================
2166 * Configure S508 adapter.
2168 static int config508(struct net_device *dev, sdla_t *card)
2171 struct in_device *in_dev = dev->ip_ptr;
2172 ppp_private_area_t *ppp_priv_area = dev->priv;
2174 /* Prepare PPP configuration structure */
2175 memset(&cfg, 0, sizeof(ppp508_conf_t));
2177 if (card->wandev.clocking)
2178 cfg.line_speed = card->wandev.bps;
2180 if (card->wandev.interface == WANOPT_RS232)
2181 cfg.conf_flags |= INTERFACE_LEVEL_RS232;
2184 cfg.conf_flags |= DONT_TERMINATE_LNK_MAX_CONFIG; /*send Configure-Request packets forever*/
2185 cfg.txbuf_percent = PERCENT_TX_BUFF; /* % of Tx bufs */
2186 cfg.mtu_local = card->wandev.mtu;
2187 cfg.mtu_remote = card->wandev.mtu; /* Default */
2188 cfg.restart_tmr = TIME_BETWEEN_CONF_REQ; /* 30 = 3sec */
2189 cfg.auth_rsrt_tmr = TIME_BETWEEN_PAP_CHAP_REQ; /* 30 = 3sec */
2190 cfg.auth_wait_tmr = WAIT_PAP_CHAP_WITHOUT_REPLY; /* 300 = 30s */
2191 cfg.mdm_fail_tmr = WAIT_AFTER_DCD_CTS_LOW; /* 5 = 0.5s */
2192 cfg.dtr_drop_tmr = TIME_DCD_CTS_LOW_AFTER_LNK_DOWN; /* 10 = 1s */
2193 cfg.connect_tmout = WAIT_DCD_HIGH_AFTER_ENABLE_COMM; /* 900 = 90s */
2194 cfg.conf_retry = MAX_CONF_REQ_WITHOUT_REPLY; /* 10 = 1s */
2195 cfg.term_retry = MAX_TERM_REQ_WITHOUT_REPLY; /* 2 times */
2196 cfg.fail_retry = NUM_CONF_NAK_WITHOUT_REPLY; /* 5 times */
2197 cfg.auth_retry = NUM_AUTH_REQ_WITHOUT_REPLY; /* 10 times */
2200 if( !card->u.p.authenticator ) {
2201 printk(KERN_INFO "%s: Device is not configured as an authenticator\n",
2203 cfg.auth_options = NO_AUTHENTICATION;
2205 printk(KERN_INFO "%s: Device is configured as an authenticator\n",
2207 cfg.auth_options = INBOUND_AUTH;
2210 if( ppp_priv_area->pap == WANOPT_YES){
2211 cfg.auth_options |=PAP_AUTH;
2212 printk(KERN_INFO "%s: Pap enabled\n", card->devname);
2214 if( ppp_priv_area->chap == WANOPT_YES){
2215 cfg.auth_options |= CHAP_AUTH;
2216 printk(KERN_INFO "%s: Chap enabled\n", card->devname);
2220 if (ppp_priv_area->enable_IPX == WANOPT_YES){
2221 printk(KERN_INFO "%s: Enabling IPX Protocol\n",card->devname);
2222 cfg.ipx_options = ENABLE_IPX | ROUTING_PROT_DEFAULT;
2224 cfg.ipx_options = DISABLE_IPX;
2227 switch (card->u.p.ip_mode) {
2229 case WANOPT_PPP_STATIC:
2231 printk(KERN_INFO "%s: PPP IP Mode: STATIC\n",card->devname);
2232 cfg.ip_options = L_AND_R_IP_NO_ASSIG |
2234 cfg.ip_local = in_dev->ifa_list->ifa_local;
2235 cfg.ip_remote = in_dev->ifa_list->ifa_address;
2236 /* Debugging code used to check that IP addresses
2237 * obtained from the kernel are correct */
2239 NEX_PRINTK(KERN_INFO "Local %u.%u.%u.%u Remote %u.%u.%u.%u Name %s\n",
2240 NIPQUAD(ip_local),NIPQUAD(ip_remote), dev->name);
2243 case WANOPT_PPP_HOST:
2245 printk(KERN_INFO "%s: PPP IP Mode: HOST\n",card->devname);
2246 cfg.ip_options = L_IP_LOCAL_ASSIG |
2249 cfg.ip_local = in_dev->ifa_list->ifa_local;
2250 cfg.ip_remote = in_dev->ifa_list->ifa_address;
2251 /* Debugging code used to check that IP addresses
2252 * obtained from the kernel are correct */
2253 NEX_PRINTK (KERN_INFO "Local %u.%u.%u.%u Remote %u.%u.%u.%u Name %s\n",
2254 NIPQUAD(ip_local),NIPQUAD(ip_remote), dev->name);
2258 case WANOPT_PPP_PEER:
2260 printk(KERN_INFO "%s: PPP IP Mode: PEER\n",card->devname);
2261 cfg.ip_options = L_IP_REMOTE_ASSIG |
2264 cfg.ip_local = 0x00;
2265 cfg.ip_remote = 0x00;
2269 printk(KERN_INFO "%s: ERROR: Unsupported PPP Mode Selected\n",
2271 printk(KERN_INFO "%s: PPP IP Modes: STATIC, PEER or HOST\n",
2276 return ppp_configure(card, &cfg);
2279 /*============================================================================
2280 * Show disconnection cause.
2282 static void show_disc_cause(sdla_t *card, unsigned cause)
2286 printk(KERN_INFO "%s: link terminated by peer\n",
2289 else if (cause & 0x0004)
2291 printk(KERN_INFO "%s: link terminated by user\n",
2294 else if (cause & 0x0008)
2296 printk(KERN_INFO "%s: authentication failed\n", card->devname);
2298 else if (cause & 0x0010)
2301 "%s: authentication protocol negotiation failed\n",
2304 else if (cause & 0x0020)
2307 "%s: peer's request for authentication rejected\n",
2310 else if (cause & 0x0040)
2312 printk(KERN_INFO "%s: MRU option rejected by peer\n",
2315 else if (cause & 0x0080)
2317 printk(KERN_INFO "%s: peer's MRU was too small\n",
2320 else if (cause & 0x0100)
2322 printk(KERN_INFO "%s: failed to negotiate peer's LCP options\n",
2325 else if (cause & 0x0200)
2327 printk(KERN_INFO "%s: failed to negotiate peer's IPCP options\n"
2330 else if (cause & 0x0400)
2333 "%s: failed to negotiate peer's IPXCP options\n",
2337 /*=============================================================================
2338 * Process UDP call of type PTPIPEAB.
2340 static void process_udp_mgmt_pkt(sdla_t *card, struct net_device *dev,
2341 ppp_private_area_t *ppp_priv_area )
2343 unsigned char buf2[5];
2345 unsigned int frames, len;
2346 struct sk_buff *new_skb;
2347 unsigned short data_length, buffer_length, real_len;
2348 unsigned long data_ptr;
2349 int udp_mgmt_req_valid = 1;
2350 ppp_mbox_t *mbox = card->mbox;
2353 ppp_udp_pkt_t *ppp_udp_pkt = (ppp_udp_pkt_t*)&ppp_priv_area->udp_pkt_data;
2355 memcpy(&buf2, &card->wandev.udp_port, 2 );
2358 if(ppp_priv_area->udp_pkt_src == UDP_PKT_FRM_NETWORK) {
2360 switch(ppp_udp_pkt->cblock.command) {
2362 case PPIPE_GET_IBA_DATA:
2363 case PPP_READ_CONFIG:
2364 case PPP_GET_CONNECTION_INFO:
2365 case PPIPE_ROUTER_UP_TIME:
2366 case PPP_READ_STATISTICS:
2367 case PPP_READ_ERROR_STATS:
2368 case PPP_READ_PACKET_STATS:
2369 case PPP_READ_LCP_STATS:
2370 case PPP_READ_IPCP_STATS:
2371 case PPP_READ_IPXCP_STATS:
2372 case PPP_READ_PAP_STATS:
2373 case PPP_READ_CHAP_STATS:
2374 case PPP_READ_CODE_VERSION:
2375 udp_mgmt_req_valid = 1;
2379 udp_mgmt_req_valid = 0;
2384 if(!udp_mgmt_req_valid) {
2386 /* set length to 0 */
2387 ppp_udp_pkt->cblock.length = 0x00;
2389 /* set return code */
2390 ppp_udp_pkt->cblock.result = 0xCD;
2391 ++ppp_priv_area->pipe_mgmt_stat.UDP_PIPE_mgmt_direction_err;
2393 if (net_ratelimit()){
2395 "%s: Warning, Illegal UDP command attempted from network: %x\n",
2396 card->devname,ppp_udp_pkt->cblock.command);
2399 /* Initialize the trace element */
2400 trace_element_t trace_element;
2402 switch (ppp_udp_pkt->cblock.command){
2404 /* PPIPE_ENABLE_TRACING */
2405 case PPIPE_ENABLE_TRACING:
2406 if (!card->TracingEnabled) {
2408 /* OPERATE_DATALINE_MONITOR */
2409 mbox->cmd.command = PPP_DATALINE_MONITOR;
2410 mbox->cmd.length = 0x01;
2411 mbox->data[0] = ppp_udp_pkt->data[0];
2412 err = sdla_exec(mbox) ?
2413 mbox->cmd.result : CMD_TIMEOUT;
2415 if (err != CMD_OK) {
2417 ppp_error(card, err, mbox);
2418 card->TracingEnabled = 0;
2420 /* set the return code */
2422 ppp_udp_pkt->cblock.result = mbox->cmd.result;
2423 mbox->cmd.length = 0;
2427 sdla_peek(&card->hw, 0xC000, &buf2, 2);
2429 ppp_priv_area->curr_trace_addr = 0;
2430 memcpy(&ppp_priv_area->curr_trace_addr, &buf2, 2);
2431 ppp_priv_area->start_trace_addr =
2432 ppp_priv_area->curr_trace_addr;
2433 ppp_priv_area->end_trace_addr =
2434 ppp_priv_area->start_trace_addr + END_OFFSET;
2436 /* MAX_SEND_BUFFER_SIZE - 28 (IP header)
2437 - 32 (ppipemon CBLOCK) */
2438 available_buffer_space = MAX_LGTH_UDP_MGNT_PKT -
2444 ppp_udp_pkt->cblock.result = 0;
2445 mbox->cmd.length = 0;
2446 card->TracingEnabled = 1;
2449 /* PPIPE_DISABLE_TRACING */
2450 case PPIPE_DISABLE_TRACING:
2452 if(card->TracingEnabled) {
2454 /* OPERATE_DATALINE_MONITOR */
2455 mbox->cmd.command = 0x33;
2456 mbox->cmd.length = 1;
2457 mbox->data[0] = 0x00;
2458 err = sdla_exec(mbox) ?
2459 mbox->cmd.result : CMD_TIMEOUT;
2464 ppp_udp_pkt->cblock.result = 0;
2465 mbox->cmd.length = 0;
2466 card->TracingEnabled = 0;
2469 /* PPIPE_GET_TRACE_INFO */
2470 case PPIPE_GET_TRACE_INFO:
2472 if(!card->TracingEnabled) {
2473 /* set return code */
2474 ppp_udp_pkt->cblock.result = 1;
2475 mbox->cmd.length = 0;
2480 /* frames < 62, where 62 is the number of trace
2481 information elements. There is in total 496
2482 bytes of space and each trace information
2485 for ( frames=0; frames<62; frames++) {
2487 trace_pkt_t *trace_pkt = (trace_pkt_t *)
2488 &ppp_udp_pkt->data[buffer_length];
2490 /* Read the whole trace packet */
2491 sdla_peek(&card->hw, ppp_priv_area->curr_trace_addr,
2492 &trace_element, sizeof(trace_element_t));
2494 /* no data on board so exit */
2495 if( trace_element.opp_flag == 0x00 )
2498 data_ptr = trace_element.trace_data_ptr;
2500 /* See if there is actual data on the trace buffer */
2502 data_length = trace_element.trace_length;
2505 ppp_udp_pkt->data[0] |= 0x02;
2508 //FIXME: Do we need this check
2509 if ((available_buffer_space - buffer_length)
2510 < (sizeof(trace_element_t)+1)){
2512 /*indicate we have more frames
2515 ppp_udp_pkt->data[0] |= 0x02;
2519 trace_pkt->status = trace_element.trace_type;
2520 trace_pkt->time_stamp = trace_element.trace_time_stamp;
2521 trace_pkt->real_length = trace_element.trace_length;
2523 real_len = trace_element.trace_length;
2526 trace_pkt->data_avail = 0x00;
2528 /* we can take it next time */
2529 if ((available_buffer_space - buffer_length)<
2530 (real_len + sizeof(trace_pkt_t))){
2532 ppp_udp_pkt->data[0] |= 0x02;
2535 trace_pkt->data_avail = 0x01;
2538 sdla_peek(&card->hw, data_ptr,
2542 /* zero the opp flag to
2543 show we got the frame */
2545 sdla_poke(&card->hw, ppp_priv_area->curr_trace_addr,
2548 /* now move onto the next
2550 ppp_priv_area->curr_trace_addr += 8;
2552 /* check if we passed the last address */
2553 if ( ppp_priv_area->curr_trace_addr >=
2554 ppp_priv_area->end_trace_addr){
2556 ppp_priv_area->curr_trace_addr =
2557 ppp_priv_area->start_trace_addr;
2560 /* update buffer length and make sure its even */
2562 if ( trace_pkt->data_avail == 0x01 ) {
2563 buffer_length += real_len - 1;
2566 /* for the header */
2569 if( buffer_length & 0x0001 )
2573 /* ok now set the total number of frames passed
2574 in the high 5 bits */
2575 ppp_udp_pkt->data[0] |= (frames << 2);
2577 /* set the data length */
2578 mbox->cmd.length = buffer_length;
2579 ppp_udp_pkt->cblock.length = buffer_length;
2581 /* set return code */
2582 ppp_udp_pkt->cblock.result = 0;
2585 /* PPIPE_GET_IBA_DATA */
2586 case PPIPE_GET_IBA_DATA:
2588 mbox->cmd.length = 0x09;
2590 sdla_peek(&card->hw, 0xF003, &ppp_udp_pkt->data,
2593 /* set the length of the data */
2594 ppp_udp_pkt->cblock.length = 0x09;
2596 /* set return code */
2597 ppp_udp_pkt->cblock.result = 0x00;
2598 ppp_udp_pkt->cblock.result = 0;
2601 /* PPIPE_FT1_READ_STATUS */
2602 case PPIPE_FT1_READ_STATUS:
2603 sdla_peek(&card->hw, 0xF020, &ppp_udp_pkt->data[0], 2);
2604 ppp_udp_pkt->cblock.length = mbox->cmd.length = 2;
2605 ppp_udp_pkt->cblock.result = 0;
2608 case PPIPE_FLUSH_DRIVER_STATS:
2609 init_ppp_priv_struct( ppp_priv_area );
2610 init_global_statistics( card );
2611 mbox->cmd.length = 0;
2612 ppp_udp_pkt->cblock.result = 0;
2616 case PPIPE_ROUTER_UP_TIME:
2618 do_gettimeofday( &tv );
2619 ppp_priv_area->router_up_time = tv.tv_sec -
2620 ppp_priv_area->router_start_time;
2621 *(unsigned long *)&ppp_udp_pkt->data = ppp_priv_area->router_up_time;
2622 mbox->cmd.length = 4;
2623 ppp_udp_pkt->cblock.result = 0;
2626 /* PPIPE_DRIVER_STATISTICS */
2627 case PPIPE_DRIVER_STAT_IFSEND:
2628 memcpy(&ppp_udp_pkt->data, &ppp_priv_area->if_send_stat,
2629 sizeof(if_send_stat_t));
2632 ppp_udp_pkt->cblock.result = 0;
2633 ppp_udp_pkt->cblock.length = sizeof(if_send_stat_t);
2634 mbox->cmd.length = sizeof(if_send_stat_t);
2637 case PPIPE_DRIVER_STAT_INTR:
2638 memcpy(&ppp_udp_pkt->data, &card->statistics,
2639 sizeof(global_stats_t));
2641 memcpy(&ppp_udp_pkt->data+sizeof(global_stats_t),
2642 &ppp_priv_area->rx_intr_stat,
2643 sizeof(rx_intr_stat_t));
2645 ppp_udp_pkt->cblock.result = 0;
2646 ppp_udp_pkt->cblock.length = sizeof(global_stats_t)+
2647 sizeof(rx_intr_stat_t);
2648 mbox->cmd.length = ppp_udp_pkt->cblock.length;
2651 case PPIPE_DRIVER_STAT_GEN:
2652 memcpy( &ppp_udp_pkt->data,
2653 &ppp_priv_area->pipe_mgmt_stat,
2654 sizeof(pipe_mgmt_stat_t));
2656 memcpy(&ppp_udp_pkt->data+sizeof(pipe_mgmt_stat_t),
2657 &card->statistics, sizeof(global_stats_t));
2659 ppp_udp_pkt->cblock.result = 0;
2660 ppp_udp_pkt->cblock.length = sizeof(global_stats_t)+
2661 sizeof(rx_intr_stat_t);
2662 mbox->cmd.length = ppp_udp_pkt->cblock.length;
2666 /* FT1 MONITOR STATUS */
2667 case FT1_MONITOR_STATUS_CTRL:
2669 /* Enable FT1 MONITOR STATUS */
2670 if( ppp_udp_pkt->data[0] == 1) {
2672 if( rCount++ != 0 ) {
2673 ppp_udp_pkt->cblock.result = 0;
2674 mbox->cmd.length = 1;
2679 /* Disable FT1 MONITOR STATUS */
2680 if( ppp_udp_pkt->data[0] == 0) {
2682 if( --rCount != 0) {
2683 ppp_udp_pkt->cblock.result = 0;
2684 mbox->cmd.length = 1;
2690 /* WARNING: FIXME: This should be fixed.
2691 * The FT1 Status Ctrl doesn't have a break
2692 * statment. Thus, no code must be inserted
2693 * HERE: between default and above case statement */
2698 /* it's a board command */
2699 mbox->cmd.command = ppp_udp_pkt->cblock.command;
2700 mbox->cmd.length = ppp_udp_pkt->cblock.length;
2702 if(mbox->cmd.length) {
2703 memcpy(&mbox->data,(unsigned char *)ppp_udp_pkt->data,
2707 /* run the command on the board */
2708 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
2710 if (err != CMD_OK) {
2712 ppp_error(card, err, mbox);
2713 ++ppp_priv_area->pipe_mgmt_stat.
2714 UDP_PIPE_mgmt_adptr_cmnd_timeout;
2718 ++ppp_priv_area->pipe_mgmt_stat.UDP_PIPE_mgmt_adptr_cmnd_OK;
2720 /* copy the result back to our buffer */
2721 memcpy(&ppp_udp_pkt->cblock,mbox, sizeof(cblock_t));
2723 if(mbox->cmd.length) {
2724 memcpy(&ppp_udp_pkt->data,&mbox->data,mbox->cmd.length);
2727 } /* end of switch */
2731 ppp_udp_pkt->ip_pkt.ttl = card->wandev.ttl;
2732 len = reply_udp(ppp_priv_area->udp_pkt_data, mbox->cmd.length);
2734 if (ppp_priv_area->udp_pkt_src == UDP_PKT_FRM_NETWORK) {
2736 /* Make sure we are not already sending */
2737 if (!test_bit(SEND_CRIT,&card->wandev.critical)){
2738 ++ppp_priv_area->pipe_mgmt_stat.UDP_PIPE_mgmt_passed_to_adptr;
2739 ppp_send(card,ppp_priv_area->udp_pkt_data,len,ppp_priv_area->protocol);
2744 /* Pass it up the stack
2745 Allocate socket buffer */
2746 if ((new_skb = dev_alloc_skb(len)) != NULL) {
2748 /* copy data into new_skb */
2750 buf = skb_put(new_skb, len);
2751 memcpy(buf,ppp_priv_area->udp_pkt_data, len);
2753 ++ppp_priv_area->pipe_mgmt_stat.UDP_PIPE_mgmt_passed_to_stack;
2755 /* Decapsulate packet and pass it up the protocol
2757 new_skb->protocol = htons(ETH_P_IP);
2759 new_skb->mac.raw = new_skb->data;
2761 dev->last_rx = jiffies;
2765 ++ppp_priv_area->pipe_mgmt_stat.UDP_PIPE_mgmt_no_socket;
2766 printk(KERN_INFO "no socket buffers available!\n");
2770 ppp_priv_area->udp_pkt_lgth = 0;
2775 /*=============================================================================
2776 * Initial the ppp_private_area structure.
2778 static void init_ppp_priv_struct( ppp_private_area_t *ppp_priv_area )
2781 memset(&ppp_priv_area->if_send_stat, 0, sizeof(if_send_stat_t));
2782 memset(&ppp_priv_area->rx_intr_stat, 0, sizeof(rx_intr_stat_t));
2783 memset(&ppp_priv_area->pipe_mgmt_stat, 0, sizeof(pipe_mgmt_stat_t));
2786 /*============================================================================
2787 * Initialize Global Statistics
2789 static void init_global_statistics( sdla_t *card )
2791 memset(&card->statistics, 0, sizeof(global_stats_t));
2794 /*============================================================================
2795 * Initialize Receive and Transmit Buffers.
2797 static void init_ppp_tx_rx_buff( sdla_t *card )
2799 ppp508_buf_info_t* info;
2801 if (card->hw.type == SDLA_S514) {
2803 info = (void*)(card->hw.dpmbase + PPP514_BUF_OFFS);
2805 card->u.p.txbuf_base = (void*)(card->hw.dpmbase +
2808 card->u.p.txbuf_last = (ppp_buf_ctl_t*)card->u.p.txbuf_base +
2809 (info->txb_num - 1);
2811 card->u.p.rxbuf_base = (void*)(card->hw.dpmbase +
2814 card->u.p.rxbuf_last = (ppp_buf_ctl_t*)card->u.p.rxbuf_base +
2815 (info->rxb_num - 1);
2819 info = (void*)(card->hw.dpmbase + PPP508_BUF_OFFS);
2821 card->u.p.txbuf_base = (void*)(card->hw.dpmbase +
2822 (info->txb_ptr - PPP508_MB_VECT));
2824 card->u.p.txbuf_last = (ppp_buf_ctl_t*)card->u.p.txbuf_base +
2825 (info->txb_num - 1);
2827 card->u.p.rxbuf_base = (void*)(card->hw.dpmbase +
2828 (info->rxb_ptr - PPP508_MB_VECT));
2830 card->u.p.rxbuf_last = (ppp_buf_ctl_t*)card->u.p.rxbuf_base +
2831 (info->rxb_num - 1);
2834 card->u.p.txbuf_next = (unsigned long*)&info->txb_nxt;
2835 card->u.p.rxbuf_next = (unsigned long*)&info->rxb1_ptr;
2837 card->u.p.rx_base = info->rxb_base;
2838 card->u.p.rx_top = info->rxb_end;
2840 card->u.p.txbuf = card->u.p.txbuf_base;
2841 card->rxmb = card->u.p.rxbuf_base;
2845 /*=============================================================================
2846 * Read Connection Information (ie for Remote IP address assginment).
2847 * Called when ppp interface connected.
2849 static int read_info( sdla_t *card )
2851 struct net_device *dev = card->wandev.dev;
2852 ppp_private_area_t *ppp_priv_area = dev->priv;
2855 struct ifreq if_info;
2856 struct sockaddr_in *if_data1, *if_data2;
2859 /* Set Local and remote addresses */
2860 memset(&if_info, 0, sizeof(if_info));
2861 strcpy(if_info.ifr_name, dev->name);
2865 set_fs(get_ds()); /* get user space block */
2867 /* Change the local and remote ip address of the interface.
2868 * This will also add in the destination route.
2870 if_data1 = (struct sockaddr_in *)&if_info.ifr_addr;
2871 if_data1->sin_addr.s_addr = ppp_priv_area->ip_local;
2872 if_data1->sin_family = AF_INET;
2873 err = devinet_ioctl( SIOCSIFADDR, &if_info );
2874 if_data2 = (struct sockaddr_in *)&if_info.ifr_dstaddr;
2875 if_data2->sin_addr.s_addr = ppp_priv_area->ip_remote;
2876 if_data2->sin_family = AF_INET;
2877 err = devinet_ioctl( SIOCSIFDSTADDR, &if_info );
2879 set_fs(fs); /* restore old block */
2882 printk (KERN_INFO "%s: Adding of route failed: %i\n",
2884 printk (KERN_INFO "%s: Local : %u.%u.%u.%u\n",
2885 card->devname,NIPQUAD(ppp_priv_area->ip_local));
2886 printk (KERN_INFO "%s: Remote: %u.%u.%u.%u\n",
2887 card->devname,NIPQUAD(ppp_priv_area->ip_remote));
2892 /*=============================================================================
2893 * Remove Dynamic Route.
2894 * Called when ppp interface disconnected.
2897 static void remove_route( sdla_t *card )
2900 struct net_device *dev = card->wandev.dev;
2905 struct ifreq if_info;
2906 struct sockaddr_in *if_data1;
2907 struct in_device *in_dev = dev->ip_ptr;
2908 struct in_ifaddr *ifa = in_dev->ifa_list;
2910 ip_addr = ifa->ifa_local;
2912 /* Set Local and remote addresses */
2913 memset(&if_info, 0, sizeof(if_info));
2914 strcpy(if_info.ifr_name, dev->name);
2917 set_fs(get_ds()); /* get user space block */
2919 /* Change the local ip address of the interface to 0.
2920 * This will also delete the destination route.
2922 if_data1 = (struct sockaddr_in *)&if_info.ifr_addr;
2923 if_data1->sin_addr.s_addr = 0;
2924 if_data1->sin_family = AF_INET;
2925 err = devinet_ioctl( SIOCSIFADDR, &if_info );
2927 set_fs(fs); /* restore old block */
2931 printk (KERN_INFO "%s: Deleting dynamic route failed %d!\n",
2932 card->devname, err);
2935 printk (KERN_INFO "%s: PPP Deleting dynamic route %u.%u.%u.%u successfuly\n",
2936 card->devname, NIPQUAD(ip_addr));
2941 /*=============================================================================
2942 * Perform the Interrupt Test by running the READ_CODE_VERSION command MAX_INTR
2943 * _TEST_COUNTER times.
2945 static int intr_test( sdla_t *card )
2947 ppp_mbox_t *mb = card->mbox;
2950 err = ppp_set_intr_mode( card, 0x08 );
2952 if (err == CMD_OK) {
2954 for (i = 0; i < MAX_INTR_TEST_COUNTER; i ++) {
2955 /* Run command READ_CODE_VERSION */
2956 memset(&mb->cmd, 0, sizeof(ppp_cmd_t));
2958 mb->cmd.command = PPP_READ_CODE_VERSION;
2959 err = sdla_exec(mb) ? mb->cmd.result : CMD_TIMEOUT;
2961 ppp_error(card, err, mb);
2966 err = ppp_set_intr_mode( card, 0 );
2973 /*==============================================================================
2974 * Determine what type of UDP call it is. DRVSTATS or PTPIPEAB ?
2976 static int udp_pkt_type( struct sk_buff *skb, sdla_t *card )
2978 unsigned char *sendpacket;
2979 unsigned char buf2[5];
2980 ppp_udp_pkt_t *ppp_udp_pkt = (ppp_udp_pkt_t *)skb->data;
2982 sendpacket = skb->data;
2983 memcpy(&buf2, &card->wandev.udp_port, 2);
2985 if( ppp_udp_pkt->ip_pkt.ver_inet_hdr_length == 0x45 && /* IP packet */
2986 sendpacket[9] == 0x11 && /* UDP packet */
2987 sendpacket[22] == buf2[1] && /* UDP Port */
2988 sendpacket[23] == buf2[0] &&
2989 sendpacket[36] == 0x01 ) {
2991 if ( sendpacket[28] == 0x50 && /* PTPIPEAB: Signature */
2992 sendpacket[29] == 0x54 &&
2993 sendpacket[30] == 0x50 &&
2994 sendpacket[31] == 0x49 &&
2995 sendpacket[32] == 0x50 &&
2996 sendpacket[33] == 0x45 &&
2997 sendpacket[34] == 0x41 &&
2998 sendpacket[35] == 0x42 ){
3000 return UDP_PTPIPE_TYPE;
3002 } else if(sendpacket[28] == 0x44 && /* DRVSTATS: Signature */
3003 sendpacket[29] == 0x52 &&
3004 sendpacket[30] == 0x56 &&
3005 sendpacket[31] == 0x53 &&
3006 sendpacket[32] == 0x54 &&
3007 sendpacket[33] == 0x41 &&
3008 sendpacket[34] == 0x54 &&
3009 sendpacket[35] == 0x53 ){
3011 return UDP_DRVSTATS_TYPE;
3014 return UDP_INVALID_TYPE;
3017 return UDP_INVALID_TYPE;
3021 /*============================================================================
3022 * Check to see if the packet to be transmitted contains a broadcast or
3023 * multicast source IP address.
3026 static int chk_bcast_mcast_addr(sdla_t *card, struct net_device* dev,
3027 struct sk_buff *skb)
3030 u32 broadcast_ip_addr = 0;
3031 struct in_device *in_dev;
3033 /* read the IP source address from the outgoing packet */
3034 src_ip_addr = *(u32 *)(skb->data + 12);
3036 /* read the IP broadcast address for the device */
3037 in_dev = dev->ip_ptr;
3038 if(in_dev != NULL) {
3039 struct in_ifaddr *ifa= in_dev->ifa_list;
3041 broadcast_ip_addr = ifa->ifa_broadcast;
3046 /* check if the IP Source Address is a Broadcast address */
3047 if((dev->flags & IFF_BROADCAST) && (src_ip_addr == broadcast_ip_addr)) {
3048 printk(KERN_INFO "%s: Broadcast Source Address silently discarded\n",
3053 /* check if the IP Source Address is a Multicast address */
3054 if((ntohl(src_ip_addr) >= 0xE0000001) &&
3055 (ntohl(src_ip_addr) <= 0xFFFFFFFE)) {
3056 printk(KERN_INFO "%s: Multicast Source Address silently discarded\n",
3064 void s508_lock (sdla_t *card, unsigned long *smp_flags)
3066 spin_lock_irqsave(&card->wandev.lock, *smp_flags);
3069 void s508_unlock (sdla_t *card, unsigned long *smp_flags)
3071 spin_unlock_irqrestore(&card->wandev.lock, *smp_flags);
3074 static int read_connection_info (sdla_t *card)
3076 ppp_mbox_t *mb = card->mbox;
3077 struct net_device *dev = card->wandev.dev;
3078 ppp_private_area_t *ppp_priv_area = dev->priv;
3079 ppp508_connect_info_t *ppp508_connect_info;
3082 memset(&mb->cmd, 0, sizeof(ppp_cmd_t));
3084 mb->cmd.command = PPP_GET_CONNECTION_INFO;
3085 err = sdla_exec(mb) ? mb->cmd.result : CMD_TIMEOUT;
3087 if (err != CMD_OK) {
3088 ppp_error(card, err, mb);
3089 ppp_priv_area->ip_remote = 0;
3090 ppp_priv_area->ip_local = 0;
3093 ppp508_connect_info = (ppp508_connect_info_t *)mb->data;
3094 ppp_priv_area->ip_remote = ppp508_connect_info->ip_remote;
3095 ppp_priv_area->ip_local = ppp508_connect_info->ip_local;
3097 NEX_PRINTK(KERN_INFO "READ CONNECTION GOT IP ADDRESS %x, %x\n",
3098 ppp_priv_area->ip_remote,
3099 ppp_priv_area->ip_local);
3105 /*===============================================================================
3108 * Configure the ppp protocol and enable communications.
3110 * The if_open function binds this function to the poll routine.
3111 * Therefore, this function will run every time the ppp interface
3114 * If the communications are not enabled, proceed to configure
3115 * the card and enable communications.
3117 * If the communications are enabled, it means that the interface
3118 * was shutdown by ether the user or driver. In this case, we
3119 * have to check that the IP addresses have not changed. If
3120 * the IP addresses changed, we have to reconfigure the firmware
3121 * and update the changed IP addresses. Otherwise, just exit.
3123 static int config_ppp (sdla_t *card)
3126 struct net_device *dev = card->wandev.dev;
3127 ppp_flags_t *flags = card->flags;
3128 ppp_private_area_t *ppp_priv_area = dev->priv;
3130 if (card->u.p.comm_enabled){
3132 if (ppp_priv_area->ip_local_tmp != ppp_priv_area->ip_local ||
3133 ppp_priv_area->ip_remote_tmp != ppp_priv_area->ip_remote){
3135 /* The IP addersses have changed, we must
3136 * stop the communications and reconfigure
3137 * the card. Reason: the firmware must know
3138 * the local and remote IP addresses. */
3140 wanpipe_set_state(card, WAN_DISCONNECTED);
3142 "%s: IP addresses changed!\n",
3144 printk(KERN_INFO "%s: Restarting communications ...\n",
3147 /* IP addresses are the same and the link is up,
3148 * we don't have to do anything here. Therefore, exit */
3153 /* Record the new IP addreses */
3154 ppp_priv_area->ip_local = ppp_priv_area->ip_local_tmp;
3155 ppp_priv_area->ip_remote = ppp_priv_area->ip_remote_tmp;
3157 if (config508(dev, card)){
3158 printk(KERN_INFO "%s: Failed to configure PPP device\n",
3163 if (ppp_set_intr_mode(card, PPP_INTR_RXRDY|
3171 printk(KERN_INFO "%s: Failed to configure board interrupts !\n",
3176 /* Turn off the transmit and timer interrupt */
3177 flags->imask &= ~(PPP_INTR_TXRDY | PPP_INTR_TIMER) ;
3180 /* If you are not the authenticator and any one of the protocol is
3181 * enabled then we call the set_out_bound_authentication.
3183 if ( !card->u.p.authenticator && (ppp_priv_area->pap || ppp_priv_area->chap)) {
3184 if ( ppp_set_outbnd_auth(card, ppp_priv_area) ){
3185 printk(KERN_INFO "%s: Outbound authentication failed !\n",
3191 /* If you are the authenticator and any one of the protocol is enabled
3192 * then we call the set_in_bound_authentication.
3194 if (card->u.p.authenticator && (ppp_priv_area->pap || ppp_priv_area->chap)){
3195 if (ppp_set_inbnd_auth(card, ppp_priv_area)){
3196 printk(KERN_INFO "%s: Inbound authentication failed !\n",
3202 /* If we fail to enable communications here it's OK,
3203 * since the DTR timer will cause a disconnected, which
3204 * will retrigger communication in timer_intr() */
3205 if (ppp_comm_enable(card) == CMD_OK) {
3206 wanpipe_set_state(card, WAN_CONNECTING);
3207 init_ppp_tx_rx_buff(card);
3213 /*============================================================
3217 * We cannot manipulate the routing tables, or
3218 * ip addresses withing the interrupt. Therefore
3219 * we must perform such actons outside an interrupt
3223 * PPP polling routine, responsible for
3224 * shutting down interfaces upon disconnect
3225 * and adding/removing routes.
3228 * This function is executed for each ppp
3229 * interface through a tq_schedule bottom half.
3231 * trigger_ppp_poll() function is used to kick
3232 * the ppp_poll routine.
3234 static void ppp_poll(struct net_device *dev)
3236 ppp_private_area_t *ppp_priv_area;
3241 if (!dev || (ppp_priv_area = dev->priv) == NULL)
3244 card = ppp_priv_area->card;
3245 flags = card->flags;
3247 /* Shutdown is in progress, stop what you are
3248 * doing and get out */
3249 if (test_bit(PERI_CRIT,&card->wandev.critical)){
3250 clear_bit(POLL_CRIT,&card->wandev.critical);
3254 /* if_open() function has triggered the polling routine
3255 * to determine the configured IP addresses. Once the
3256 * addresses are found, trigger the chdlc configuration */
3257 if (test_bit(0,&ppp_priv_area->config_ppp)){
3259 ppp_priv_area->ip_local_tmp = get_ip_address(dev,WAN_LOCAL_IP);
3260 ppp_priv_area->ip_remote_tmp = get_ip_address(dev,WAN_POINTOPOINT_IP);
3262 if (ppp_priv_area->ip_local_tmp == ppp_priv_area->ip_remote_tmp &&
3263 card->u.p.ip_mode == WANOPT_PPP_HOST){
3265 if (++ppp_priv_area->ip_error > MAX_IP_ERRORS){
3266 printk(KERN_INFO "\n%s: --- WARNING ---\n",
3268 printk(KERN_INFO "%s: The local IP address is the same as the\n",
3270 printk(KERN_INFO "%s: Point-to-Point IP address.\n",
3272 printk(KERN_INFO "%s: --- WARNING ---\n\n",
3275 clear_bit(POLL_CRIT,&card->wandev.critical);
3276 ppp_priv_area->poll_delay_timer.expires = jiffies+HZ;
3277 add_timer(&ppp_priv_area->poll_delay_timer);
3282 ppp_priv_area->timer_int_enabled |= TMR_INT_ENABLED_CONFIG;
3283 flags->imask |= PPP_INTR_TIMER;
3284 ppp_priv_area->ip_error=0;
3286 clear_bit(0,&ppp_priv_area->config_ppp);
3287 clear_bit(POLL_CRIT,&card->wandev.critical);
3291 /* Dynamic interface implementation, as well as dynamic
3294 switch (card->wandev.state) {
3296 case WAN_DISCONNECTED:
3298 /* If the dynamic interface configuration is on, and interface
3299 * is up, then bring down the netowrk interface */
3301 if (test_bit(DYN_OPT_ON,&ppp_priv_area->interface_down) &&
3302 !test_bit(DEV_DOWN,&ppp_priv_area->interface_down) &&
3303 card->wandev.dev->flags & IFF_UP){
3305 printk(KERN_INFO "%s: Interface %s down.\n",
3306 card->devname,card->wandev.dev->name);
3307 change_dev_flags(card->wandev.dev,
3308 (card->wandev.dev->flags&~IFF_UP));
3309 set_bit(DEV_DOWN,&ppp_priv_area->interface_down);
3311 /* We need to check if the local IP address is
3312 * zero. If it is, we shouldn't try to remove it.
3313 * For some reason the kernel crashes badly if
3314 * we try to remove the route twice */
3316 if (card->wandev.dev->flags & IFF_UP &&
3317 get_ip_address(card->wandev.dev,WAN_LOCAL_IP) &&
3318 card->u.p.ip_mode == WANOPT_PPP_PEER){
3327 /* In SMP machine this code can execute before the interface
3328 * comes up. In this case, we must make sure that we do not
3329 * try to bring up the interface before dev_open() is finished */
3332 /* DEV_DOWN will be set only when we bring down the interface
3333 * for the very first time. This way we know that it was us
3334 * that brought the interface down */
3336 if (test_bit(DYN_OPT_ON,&ppp_priv_area->interface_down) &&
3337 test_bit(DEV_DOWN, &ppp_priv_area->interface_down) &&
3338 !(card->wandev.dev->flags & IFF_UP)){
3340 printk(KERN_INFO "%s: Interface %s up.\n",
3341 card->devname,card->wandev.dev->name);
3343 change_dev_flags(card->wandev.dev,(card->wandev.dev->flags|IFF_UP));
3344 clear_bit(DEV_DOWN,&ppp_priv_area->interface_down);
3348 if ((card->u.p.ip_mode == WANOPT_PPP_PEER) &&
3349 test_bit(1,&Read_connection_info)) {
3351 process_route(card);
3352 clear_bit(1,&Read_connection_info);
3356 if (ppp_priv_area->gateway && check_gateway)
3357 add_gateway(card,dev);
3361 clear_bit(POLL_CRIT,&card->wandev.critical);
3365 /*============================================================
3369 * Add a ppp_poll() task into a tq_scheduler bh handler
3370 * for a specific interface. This will kick
3371 * the ppp_poll() routine at a later time.
3374 * Interrupts use this to defer a taks to
3375 * a polling routine.
3379 static void trigger_ppp_poll(struct net_device *dev)
3381 ppp_private_area_t *ppp_priv_area;
3382 if ((ppp_priv_area=dev->priv) != NULL){
3384 sdla_t *card = ppp_priv_area->card;
3386 if (test_bit(PERI_CRIT,&card->wandev.critical)){
3390 if (test_and_set_bit(POLL_CRIT,&card->wandev.critical)){
3394 schedule_work(&ppp_priv_area->poll_work);
3399 static void ppp_poll_delay (unsigned long dev_ptr)
3401 struct net_device *dev = (struct net_device *)dev_ptr;
3402 trigger_ppp_poll(dev);
3405 /*============================================================
3406 * detect_and_fix_tx_bug
3409 * On connect, if the board tx buffer ptr is not the same
3410 * as the driver tx buffer ptr, we found a firmware bug.
3411 * Report the bug to the above layer. To fix the
3412 * error restart communications again.
3418 static int detect_and_fix_tx_bug (sdla_t *card)
3420 if (((unsigned long)card->u.p.txbuf_base&0xFFF) != ((*card->u.p.txbuf_next)&0xFFF)){
3421 NEX_PRINTK(KERN_INFO "Major Error, Fix the bug\n");
3427 MODULE_LICENSE("GPL");
3429 /****** End *****************************************************************/