1 /*****************************************************************************
2 * sdla_ppp.c WANPIPE(tm) Multiprotocol WAN Link Driver. PPP module.
3 *
4 * Author: Nenad Corbic <ncorbic@sangoma.com>
5 *
6 * Copyright: (c) 1995-1999 Sangoma Technologies Inc.
7 *
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 *
14 * Oct 25, 1999 Nenad Corbic o Support for 2.0.X kernels
15 * Moved dynamic route processing into
16 * a polling routine.
17 * Oct 07, 1999 Nenad Corbic o Support for S514 PCI card.
18 * Gideon Hack o UPD and Updates executed using timer interrupt
19 * Sep 10, 1999 Nenad Corbic o Fixed up the /proc statistics
20 * Jul 20, 1999 Nenad Corbic o Remove the polling routines and use
21 * interrupts instead.
22 * Sep 17, 1998 Jaspreet Singh o Updates for 2.2.X Kernels.
23 * Aug 13, 1998 Jaspreet Singh o Improved Line Tracing.
24 * Jun 22, 1998 David Fong o Added remote IP address assignment
25 * Mar 15, 1998 Alan Cox o 2.1.8x basic port.
26 * Apr 16, 1998 Jaspreet Singh o using htons() for the IPX protocol.
27 * Dec 09, 1997 Jaspreet Singh o Added PAP and CHAP.
28 * o Implemented new routines like
29 * ppp_set_inbnd_auth(), ppp_set_outbnd_auth(),
30 * tokenize() and strstrip().
31 * Nov 27, 1997 Jaspreet Singh o Added protection against enabling of irqs
32 * while they have been disabled.
33 * Nov 24, 1997 Jaspreet Singh o Fixed another RACE condition caused by
34 * disabling and enabling of irqs.
35 * o Added new counters for stats on disable/enable
36 * IRQs.
37 * Nov 10, 1997 Jaspreet Singh o Initialized 'skb->mac.raw' to 'skb->data'
38 * before every netif_rx().
39 * o Free up the device structure in del_if().
40 * Nov 07, 1997 Jaspreet Singh o Changed the delay to zero for Line tracing
41 * command.
42 * Oct 20, 1997 Jaspreet Singh o Added hooks in for Router UP time.
43 * Oct 16, 1997 Jaspreet Singh o The critical flag is used to maintain flow
44 * control by avoiding RACE conditions. The
45 * cli() and restore_flags() are taken out.
46 * A new structure, "ppp_private_area", is added
47 * to provide Driver Statistics.
48 * Jul 21, 1997 Jaspreet Singh o Protected calls to sdla_peek() by adding
49 * save_flags(), cli() and restore_flags().
50 * Jul 07, 1997 Jaspreet Singh o Added configurable TTL for UDP packets
51 * o Added ability to discard mulitcast and
52 * broacast source addressed packets.
53 * Jun 27, 1997 Jaspreet Singh o Added FT1 monitor capabilities
54 * New case (0x25) statement in if_send routine.
55 * Added a global variable rCount to keep track
56 * of FT1 status enabled on the board.
57 * May 22, 1997 Jaspreet Singh o Added change in the PPP_SET_CONFIG command for
58 * 508 card to reflect changes in the new
59 * ppp508.sfm for supporting:continous transmission
60 * of Configure-Request packets without receiving a
61 * reply
62 * OR-ed 0x300 to conf_flags
63 * o Changed connect_tmout from 900 to 0
64 * May 21, 1997 Jaspreet Singh o Fixed UDP Management for multiple boards
65 * Apr 25, 1997 Farhan Thawar o added UDP Management stuff
66 * Mar 11, 1997 Farhan Thawar Version 3.1.1
67 * o fixed (+1) bug in rx_intr()
68 * o changed if_send() to return 0 if
69 * wandev.critical() is true
70 * o free socket buffer in if_send() if
71 * returning 0
72 * Jan 15, 1997 Gene Kozin Version 3.1.0
73 * o implemented exec() entry point
74 * Jan 06, 1997 Gene Kozin Initial version.
75 *****************************************************************************/
76
77 #include <linux/config.h>
78 #include <linux/version.h>
79 #include <linux/kernel.h> /* printk(), and other useful stuff */
80 #include <linux/stddef.h> /* offsetof(), etc. */
81 #include <linux/errno.h> /* return codes */
82 #include <linux/string.h> /* inline memset(), etc. */
83 #include <linux/malloc.h> /* kmalloc(), kfree() */
84 #include <linux/wanrouter.h> /* WAN router definitions */
85 #include <linux/wanpipe.h> /* WANPIPE common user API definitions */
86 #include <linux/if_arp.h> /* ARPHRD_* defines */
87 #include <asm/byteorder.h> /* htons(), etc. */
88 #include <linux/in.h> /* sockaddr_in */
89 #include <linux/inet.h> /* in_aton(), in_ntoa() prototypes */
90
91 #include <linux/inetdevice.h>
92 #include <asm/uaccess.h>
93
94 #include <linux/if.h>
95 #include <linux/sdla_ppp.h> /* PPP firmware API definitions */
96 #include <linux/sdlasfm.h> /* S514 Type Definition */
97 /****** Defines & Macros ****************************************************/
98
99 #ifdef _DEBUG_
100 #define STATIC
101 #else
102 #define STATIC static
103 #endif
104
105 #define PPP_DFLT_MTU 1500 /* default MTU */
106 #define PPP_MAX_MTU 4000 /* maximum MTU */
107 #define PPP_HDR_LEN 1
108
109 #define CONNECT_TIMEOUT (90*HZ) /* link connection timeout */
110 #define HOLD_DOWN_TIME (5*HZ) /* link hold down time : Changed from 30 to 5 */
111
112 /* For handle_IPXWAN() */
113 #define CVHexToAscii(b) (((unsigned char)(b) > (unsigned char)9) ? ((unsigned char)'A' + ((unsigned char)(b) - (unsigned char)10)) : ((unsigned char)'' + (unsigned char)(b)))
114
115 /* Macro for enabling/disabling debugging comments */
116 //#define NEX_DEBUG
117 #ifdef NEX_DEBUG
118 #define NEX_PRINTK(format, a...) printk(format, ## a)
119 #else
120 #define NEX_PRINTK(format, a...)
121 #endif /* NEX_DEBUG */
122
123 #define DCD(a) ( a & 0x08 ? "HIGH" : "LOW" )
124 #define CTS(a) ( a & 0x20 ? "HIGH" : "LOW" )
125 #define LCP(a) ( a == 0x09 ? "OPEN" : "CLOSED" )
126 #define IP(a) ( a == 0x09 ? "ENABLED" : "DISABLED" )
127
128 #define TMR_INT_ENABLED_UPDATE 1
129 #define TMR_INT_ENABLED_PPP_EVENT 2
130 #define TMR_INT_ENABLED_UDP 4
131
132 /* Set Configuraton Command Definitions */
133 #define PERCENT_TX_BUFF 60
134 #define TIME_BETWEEN_CONF_REQ 30
135 #define TIME_BETWEEN_PAP_CHAP_REQ 30
136 #define WAIT_PAP_CHAP_WITHOUT_REPLY 300
137 #define WAIT_AFTER_DCD_CTS_LOW 5
138 #define TIME_DCD_CTS_LOW_AFTER_LNK_DOWN 10
139 #define WAIT_DCD_HIGH_AFTER_ENABLE_COMM 900
140 #define MAX_CONF_REQ_WITHOUT_REPLY 10
141 #define MAX_TERM_REQ_WITHOUT_REPLY 2
142 #define NUM_CONF_NAK_WITHOUT_REPLY 5
143 #define NUM_AUTH_REQ_WITHOUT_REPLY 10
144
145 #define END_OFFSET 0x1F0
146
147 #define TX_TIMEOUT (5*HZ)
148
149 /******Data Structures*****************************************************/
150
151 /* This structure is placed in the private data area of the device structure.
152 * The card structure used to occupy the private area but now the following
153 * structure will incorporate the card structure along with PPP specific data
154 */
155
156 typedef struct ppp_private_area
157 {
158 /* This member must be first. */
159 struct net_device *slave; /* WAN slave */
160
161 sdla_t* card;
162 unsigned long router_start_time; /*router start time in sec */
163 unsigned long tick_counter; /*used for 5 second counter*/
164 unsigned mc; /*multicast support on or off*/
165 unsigned char enable_IPX;
166 unsigned long network_number;
167 unsigned char pap;
168 unsigned char chap;
169 unsigned char sysname[31]; /* system name for in-bnd auth*/
170 unsigned char userid[511]; /* list of user ids */
171 unsigned char passwd[511]; /* list of passwords */
172 unsigned protocol; /* SKB Protocol */
173 u32 ip_local; /* Local IP Address */
174 u32 ip_remote; /* remote IP Address */
175
176 unsigned char timer_int_enabled; /* Who enabled the timer inter*/
177 unsigned char update_comms_stats; /* Used by update function */
178 unsigned long curr_trace_addr; /* Trace information */
179 unsigned long start_trace_addr;
180 unsigned long end_trace_addr;
181
182 unsigned short udp_pkt_lgth;
183 char udp_pkt_src;
184 char udp_pkt_data[MAX_LGTH_UDP_MGNT_PKT];
185
186 /* PPP specific statistics */
187
188 if_send_stat_t if_send_stat;
189 rx_intr_stat_t rx_intr_stat;
190 pipe_mgmt_stat_t pipe_mgmt_stat;
191
192 unsigned long router_up_time;
193
194 }ppp_private_area_t;
195
196 /* variable for keeping track of enabling/disabling FT1 monitor status */
197 static int rCount = 0;
198
199 extern void disable_irq(unsigned int);
200 extern void enable_irq(unsigned int);
201
202 /****** Function Prototypes *************************************************/
203
204 /* WAN link driver entry points. These are called by the WAN router module. */
205 static int update(wan_device_t *wandev);
206 static int new_if(wan_device_t *wandev, struct net_device *dev, wanif_conf_t *conf);
207 static int del_if(wan_device_t *wandev, struct net_device *dev);
208
209 /* WANPIPE-specific entry points */
210 static int wpp_exec (struct sdla *card, void *u_cmd, void *u_data);
211
212 /* Network device interface */
213 static int if_init(struct net_device *dev);
214 static int if_open(struct net_device *dev);
215 static int if_close(struct net_device *dev);
216 static void if_tx_timeout (struct net_device *dev);
217 static int if_header(struct sk_buff *skb, struct net_device *dev, unsigned short type,
218 void *daddr, void *saddr, unsigned len);
219 static int if_rebuild_hdr(struct sk_buff *skb);
220 static struct net_device_stats *if_stats(struct net_device *dev);
221 static int if_send(struct sk_buff *skb, struct net_device *dev);
222
223
224 /* PPP firmware interface functions */
225 static int ppp_read_version(sdla_t *card, char *str);
226 static int ppp_set_outbnd_auth(sdla_t *card, ppp_private_area_t *ppp_priv_area);
227 static int ppp_set_inbnd_auth(sdla_t *card, ppp_private_area_t *ppp_priv_area);
228 static int ppp_configure(sdla_t *card, void *data);
229 static int ppp_set_intr_mode(sdla_t *card, unsigned char mode);
230 static int ppp_comm_enable(sdla_t *card);
231 static int ppp_comm_disable(sdla_t *card);
232 static int ppp_get_err_stats(sdla_t *card);
233 static int ppp_send(sdla_t *card, void *data, unsigned len, unsigned proto);
234 static int ppp_error(sdla_t *card, int err, ppp_mbox_t *mb);
235
236 STATIC void wpp_isr(sdla_t *card);
237 static void rx_intr(sdla_t *card);
238 static void event_intr(sdla_t *card);
239 static void timer_intr(sdla_t *card);
240
241 /* Background polling routines */
242 static void process_route(sdla_t *card);
243 static void poll_disconnected(sdla_t *card);
244
245 /* Miscellaneous functions */
246 static int read_info( sdla_t *card );
247 static int read_connection_info (sdla_t *card);
248 static int remove_route( sdla_t *card );
249 static int config508(ppp_private_area_t *ppp_priv_area, sdla_t *card);
250 static void show_disc_cause(sdla_t * card, unsigned cause);
251 static int reply_udp( unsigned char *data, unsigned int mbox_len );
252 static void process_udp_mgmt_pkt(sdla_t *card, struct net_device *dev,
253 ppp_private_area_t *ppp_priv_area);
254 static void init_ppp_tx_rx_buff( sdla_t *card );
255 static int intr_test( sdla_t *card );
256 static int udp_pkt_type( struct sk_buff *skb , sdla_t *card);
257 static void init_ppp_priv_struct( ppp_private_area_t *ppp_priv_area);
258 static void init_global_statistics( sdla_t *card );
259 static int tokenize(char *str, char **tokens);
260 static char* strstrip(char *str, char *s);
261 static int chk_bcast_mcast_addr(sdla_t* card, struct net_device* dev,
262 struct sk_buff *skb);
263 static int Read_connection_info;
264 static int Intr_test_counter;
265 static unsigned short available_buffer_space;
266
267 /* IPX functions */
268 static void switch_net_numbers(unsigned char *sendpacket, unsigned long network_number,
269 unsigned char incoming);
270 static int handle_IPXWAN(unsigned char *sendpacket, char *devname, unsigned char enable_PX,
271 unsigned long network_number, unsigned short proto);
272
273 /* Lock Functions */
274 static void s508_lock (sdla_t *card, unsigned long *smp_flags);
275 static void s508_unlock (sdla_t *card, unsigned long *smp_flags);
276
277 static int store_udp_mgmt_pkt(char udp_pkt_src, sdla_t* card,
278 struct sk_buff *skb, struct net_device* dev,
279 ppp_private_area_t* ppp_priv_area );
280 static unsigned short calc_checksum (char *data, int len);
281
282
283
284
285 /****** Public Functions ****************************************************/
286
287 /*============================================================================
288 * PPP protocol initialization routine.
289 *
290 * This routine is called by the main WANPIPE module during setup. At this
291 * point adapter is completely initialized and firmware is running.
292 * o read firmware version (to make sure it's alive)
293 * o configure adapter
294 * o initialize protocol-specific fields of the adapter data space.
295 *
296 * Return: 0 o.k.
297 * < 0 failure.
298 */
299 int wpp_init(sdla_t *card, wandev_conf_t *conf)
300 {
301 union
302 {
303 char str[80];
304 } u;
305
306 /* Verify configuration ID */
307 if (conf->config_id != WANCONFIG_PPP) {
308
309 printk(KERN_INFO "%s: invalid configuration ID %u!\n",
310 card->devname, conf->config_id);
311 return -EINVAL;
312
313 }
314
315 /* Initialize miscellaneous pointers to structures on the adapter */
316 switch (card->hw.type) {
317
318 case SDLA_S508:
319 card->mbox =(void*)(card->hw.dpmbase + PPP508_MB_OFFS);
320 card->flags=(void*)(card->hw.dpmbase + PPP508_FLG_OFFS);
321 break;
322
323 case SDLA_S514:
324 card->mbox =(void*)(card->hw.dpmbase + PPP514_MB_OFFS);
325 card->flags=(void*)(card->hw.dpmbase + PPP514_FLG_OFFS);
326 break;
327
328 default:
329 return -EINVAL;
330
331 }
332
333 /* Read firmware version. Note that when adapter initializes, it
334 * clears the mailbox, so it may appear that the first command was
335 * executed successfully when in fact it was merely erased. To work
336 * around this, we execute the first command twice.
337 */
338 if (ppp_read_version(card, NULL) || ppp_read_version(card, u.str))
339 return -EIO;
340
341 printk(KERN_INFO "%s: running PPP firmware v%s\n",card->devname, u.str);
342 /* Adjust configuration and set defaults */
343 card->wandev.mtu = (conf->mtu) ?
344 min(conf->mtu, PPP_MAX_MTU) : PPP_DFLT_MTU;
345
346 card->wandev.bps = conf->bps;
347 card->wandev.interface = conf->interface;
348 card->wandev.clocking = conf->clocking;
349 card->wandev.station = conf->station;
350 card->isr = &wpp_isr;
351 card->poll = NULL;
352 card->exec = &wpp_exec;
353 card->wandev.update = &update;
354 card->wandev.new_if = &new_if;
355 card->wandev.del_if = &del_if;
356 card->wandev.state = WAN_DISCONNECTED;
357 card->wandev.udp_port = conf->udp_port;
358 card->wandev.ttl = conf->ttl;
359 card->irq_dis_if_send_count = 0;
360 card->irq_dis_poll_count = 0;
361 card->u.p.authenticator = conf->u.ppp.authenticator;
362 card->u.p.ip_mode = conf->u.ppp.ip_mode ?
363 conf->u.ppp.ip_mode : WANOPT_PPP_STATIC;
364 card->TracingEnabled = 0;
365 Read_connection_info = 1;
366
367 /* initialize global statistics */
368 init_global_statistics( card );
369
370 return 0;
371 }
372
373 /******* WAN Device Driver Entry Points *************************************/
374
375 /*============================================================================
376 * Update device status & statistics.
377 */
378 static int update(wan_device_t *wandev)
379 {
380 sdla_t* card = wandev->private;
381 struct net_device* dev = card->wandev.dev;
382 volatile ppp_private_area_t *ppp_priv_area = dev->priv;
383 ppp_flags_t *flags = card->flags;
384 unsigned long timeout;
385
386 /* sanity checks */
387 if ((wandev == NULL) || (wandev->private == NULL))
388 return -EFAULT;
389
390 if (wandev->state == WAN_UNCONFIGURED)
391 return -ENODEV;
392
393 //FIXME: Do we need this
394 if (test_bit(0, (void*)&wandev->critical))
395 return -EAGAIN;
396
397 ppp_priv_area->update_comms_stats = 2;
398 ppp_priv_area->timer_int_enabled |= TMR_INT_ENABLED_UPDATE;
399 flags->imask |= PPP_INTR_TIMER;
400
401 /* wait a maximum of 1 second for the statistics to be updated */
402 timeout = jiffies;
403 for(;;) {
404 if(ppp_priv_area->update_comms_stats == 0){
405 break;
406 }
407 if ((jiffies - timeout) > (1 * HZ)){
408 ppp_priv_area->update_comms_stats = 0;
409 ppp_priv_area->timer_int_enabled &=
410 ~TMR_INT_ENABLED_UPDATE;
411 return -EAGAIN;
412 }
413 }
414
415 return 0;
416 }
417
418 /*============================================================================
419 * Create new logical channel.
420 * This routine is called by the router when ROUTER_IFNEW IOCTL is being
421 * handled.
422 * o parse media- and hardware-specific configuration
423 * o make sure that a new channel can be created
424 * o allocate resources, if necessary
425 * o prepare network device structure for registaration.
426 *
427 * Return: 0 o.k.
428 * < 0 failure (channel will not be created)
429 */
430 static int new_if(wan_device_t *wandev, struct net_device *dev, wanif_conf_t *conf)
431 {
432 sdla_t *card = wandev->private;
433 ppp_private_area_t *ppp_priv_area;
434
435 if (wandev->ndev)
436 return -EEXIST;
437
438 if ((conf->name[0] == '\0') || (strlen(conf->name) > WAN_IFNAME_SZ)) {
439
440 printk(KERN_INFO "%s: invalid interface name!\n",
441 card->devname);
442 return -EINVAL;
443
444 }
445
446 /* allocate and initialize private data */
447 ppp_priv_area = kmalloc(sizeof(ppp_private_area_t), GFP_KERNEL);
448
449 if( ppp_priv_area == NULL )
450 return -ENOMEM;
451
452 memset(ppp_priv_area, 0, sizeof(ppp_private_area_t));
453
454 ppp_priv_area->card = card;
455
456 /* initialize data */
457 strcpy(card->u.p.if_name, conf->name);
458
459 /* initialize data in ppp_private_area structure */
460
461 init_ppp_priv_struct( ppp_priv_area );
462
463 ppp_priv_area->mc = conf->mc;
464 ppp_priv_area->pap = conf->pap;
465 ppp_priv_area->chap = conf->chap;
466
467 /* If no user ids are specified */
468 if(!strlen(conf->userid) && (ppp_priv_area->pap||ppp_priv_area->chap)){
469 kfree(ppp_priv_area);
470 return -EINVAL;
471 }
472
473 /* If no passwords are specified */
474 if(!strlen(conf->passwd) && (ppp_priv_area->pap||ppp_priv_area->chap)){
475 kfree(ppp_priv_area);
476 return -EINVAL;
477 }
478
479 if(strlen(conf->sysname) > 31){
480 kfree(ppp_priv_area);
481 return -EINVAL;
482 }
483
484 /* If no system name is specified */
485 if(!strlen(conf->sysname) && (card->u.p.authenticator)){
486 kfree(ppp_priv_area);
487 return -EINVAL;
488 }
489
490 /* copy the data into the ppp private structure */
491 memcpy(ppp_priv_area->userid, conf->userid, strlen(conf->userid));
492 memcpy(ppp_priv_area->passwd, conf->passwd, strlen(conf->passwd));
493 memcpy(ppp_priv_area->sysname, conf->sysname, strlen(conf->sysname));
494
495
496 ppp_priv_area->enable_IPX = conf->enable_IPX;
497 if (conf->network_number)
498 ppp_priv_area->network_number = conf->network_number;
499 else
500 ppp_priv_area->network_number = 0xDEADBEEF;
501
502
503 /* prepare network device data space for registration */
504 strcpy(dev->name, card->u.p.if_name);
505 dev->init = &if_init;
506 dev->priv = ppp_priv_area;
507
508 return 0;
509 }
510
511 /*============================================================================
512 * Delete logical channel.
513 */
514 static int del_if(wan_device_t *wandev, struct net_device *dev)
515 {
516 if (dev->priv) {
517
518 kfree(dev->priv);
519 dev->priv = NULL;
520 }
521
522 return 0;
523 }
524
525 /****** WANPIPE-specific entry points ***************************************/
526
527 /*============================================================================
528 * Execute adapter interface command.
529 */
530
531 //FIXME: Why do we need this ????
532 static int wpp_exec(struct sdla *card, void *u_cmd, void *u_data)
533 {
534 ppp_mbox_t *mbox = card->mbox;
535 int len;
536
537 if (copy_from_user((void*)&mbox->cmd, u_cmd, sizeof(ppp_cmd_t)))
538 return -EFAULT;
539
540 len = mbox->cmd.length;
541
542 if (len) {
543
544 if( copy_from_user((void*)&mbox->data, u_data, len))
545 return -EFAULT;
546
547 }
548
549 /* execute command */
550 if (!sdla_exec(mbox))
551 return -EIO;
552
553 /* return result */
554 if( copy_to_user(u_cmd, (void*)&mbox->cmd, sizeof(ppp_cmd_t)))
555 return -EFAULT;
556 len = mbox->cmd.length;
557
558 if (len && u_data && copy_to_user(u_data, (void*)&mbox->data, len))
559 return -EFAULT;
560
561 return 0;
562 }
563
564 /****** Network Device Interface ********************************************/
565
566 /*============================================================================
567 * Initialize Linux network interface.
568 *
569 * This routine is called only once for each interface, during Linux network
570 * interface registration. Returning anything but zero will fail interface
571 * registration.
572 */
573 static int if_init(struct net_device *dev)
574 {
575 ppp_private_area_t *ppp_priv_area = dev->priv;
576 sdla_t *card = ppp_priv_area->card;
577 wan_device_t *wandev = &card->wandev;
578 #ifndef LINUX_2_1
579 int i;
580 #endif
581
582 /* Initialize device driver entry points */
583 dev->open = &if_open;
584 dev->stop = &if_close;
585 dev->hard_header = &if_header;
586 dev->rebuild_header = &if_rebuild_hdr;
587 dev->hard_start_xmit = &if_send;
588 dev->get_stats = &if_stats;
589 dev->tx_timeout = &if_tx_timeout;
590 dev->watchdog_timeo = TX_TIMEOUT;
591
592 /* Initialize media-specific parameters */
593 dev->type = ARPHRD_PPP; /* ARP h/w type */
594 dev->flags |= IFF_POINTOPOINT;
595
596 /* Enable Mulitcasting if specified by user*/
597 if (ppp_priv_area->mc == WANOPT_YES){
598 dev->flags |= IFF_MULTICAST;
599 }
600
601 #ifndef LINUX_2_1
602 dev->family = AF_INET;
603 #endif
604 dev->mtu = wandev->mtu;
605 dev->hard_header_len = PPP_HDR_LEN; /* media header length */
606
607 /* Initialize hardware parameters (just for reference) */
608 dev->irq = wandev->irq;
609 dev->dma = wandev->dma;
610 dev->base_addr = wandev->ioport;
611 dev->mem_start = wandev->maddr;
612 dev->mem_end = wandev->maddr + wandev->msize - 1;
613
614 /* Set transmit buffer queue length */
615 dev->tx_queue_len = 100;
616
617 /* Initialize socket buffers */
618 dev_init_buffers(dev);
619 return 0;
620 }
621
622 /*============================================================================
623 * Open network interface.
624 * o enable communications and interrupts.
625 * o prevent module from unloading by incrementing use count
626 *
627 * Return 0 if O.k. or errno.
628 */
629 static int if_open(struct net_device *dev)
630 {
631 ppp_private_area_t *ppp_priv_area = dev->priv;
632 sdla_t *card = ppp_priv_area->card;
633 ppp_flags_t *flags = card->flags;
634 struct timeval tv;
635 int err = 0;
636
637 if (netif_running(dev))
638 return -EBUSY; /* only one open is allowed */
639
640 if (test_and_set_bit(0, (void*)&card->wandev.critical))
641 return -EAGAIN;
642
643 if (!card->configured){
644
645 if (config508(ppp_priv_area, card)){
646
647 err = -EIO;
648 card->wandev.critical = 0;
649 return err;
650 }
651
652 Intr_test_counter = 0;
653 err = intr_test( card );
654
655 if(err || (Intr_test_counter < MAX_INTR_TEST_COUNTER)) {
656 printk("%s: Interrupt Test Failed, Counter: %i\n",
657 card->devname, Intr_test_counter);
658 printk( "%s: Please choose another interrupt\n",card->devname);
659 err = -EIO;
660 card->wandev.critical = 0;
661 return err;
662 }
663
664 printk(KERN_INFO "%s: Interrupt Test Passed, Counter: %i\n",
665 card->devname, Intr_test_counter);
666 card->configured = 1;
667
668 }
669
670 /* Initialize Rx/Tx buffer control fields */
671 init_ppp_tx_rx_buff( card );
672
673 if (ppp_set_intr_mode(card, PPP_INTR_RXRDY|
674 PPP_INTR_TXRDY|
675 PPP_INTR_MODEM|
676 PPP_INTR_CMD |
677 PPP_INTR_DISC |
678 PPP_INTR_OPEN |
679 PPP_INTR_DROP_DTR |
680 PPP_INTR_TIMER)) {
681
682 err = -EIO;
683 card->wandev.critical = 0;
684 return err;
685
686 }
687
688 /* Turn off the transmit and timer interrupt */
689 flags->imask &= ~(PPP_INTR_TXRDY | PPP_INTR_TIMER) ;
690
691 /* If you are not the authenticator and any one of the protocol is
692 * enabled then we call the set_out_bound_authentication.
693 */
694 if ( !card->u.p.authenticator && (ppp_priv_area->pap || ppp_priv_area->chap)) {
695 if ( ppp_set_outbnd_auth(card, ppp_priv_area) ){
696 err = -EIO;
697 card->wandev.critical = 0;
698 return err;
699 }
700 }
701
702 /* If you are the authenticator and any one of the protocol is enabled
703 * then we call the set_in_bound_authentication.
704 */
705 if ( card->u.p.authenticator && (ppp_priv_area->pap || ppp_priv_area->chap)) {
706 if ( ppp_set_inbnd_auth(card, ppp_priv_area) ){
707 err = -EIO;
708 card->wandev.critical = 0;
709 return err;
710 }
711 }
712
713 if (ppp_comm_enable(card)) {
714 err = -EIO;
715 card->wandev.critical = 0;
716 return err;
717 }
718
719 wanpipe_set_state(card, WAN_CONNECTING);
720 wanpipe_open(card);
721 dev->mtu = min(dev->mtu, card->wandev.mtu);
722 netif_start_queue(dev);
723 do_gettimeofday( &tv );
724 ppp_priv_area->router_start_time = tv.tv_sec;
725 card->wandev.critical = 0;
726
727 return err;
728 }
729
730 /*============================================================================
731 * Close network interface.
732 * o if this is the last open, then disable communications and interrupts.
733 * o reset flags.
734 */
735 static int if_close(struct net_device *dev)
736 {
737 ppp_private_area_t *ppp_priv_area = dev->priv;
738 sdla_t *card = ppp_priv_area->card;
739
740 if (test_and_set_bit(0, (void*)&card->wandev.critical))
741 return -EAGAIN;
742
743 netif_stop_queue(dev);
744 wanpipe_close(card);
745 wanpipe_set_state(card, WAN_DISCONNECTED);
746 ppp_set_intr_mode(card, 0);
747 ppp_comm_disable(card);
748 card->wandev.critical = 0;
749 return 0;
750 }
751
752 /*============================================================================
753 * Build media header.
754 *
755 * The trick here is to put packet type (Ethertype) into 'protocol' field of
756 * the socket buffer, so that we don't forget it. If packet type is not
757 * supported, set skb->protocol to 0 and discard packet later.
758 *
759 * Return: media header length.
760 */
761 static int if_header(struct sk_buff *skb, struct net_device *dev,
762 unsigned short type, void *daddr, void *saddr, unsigned len)
763 {
764 switch (type)
765 {
766 case ETH_P_IP:
767
768 case ETH_P_IPX:
769 skb->protocol = htons(type);
770 break;
771
772 default:
773 skb->protocol = 0;
774 }
775
776 return PPP_HDR_LEN;
777 }
778
779 /*============================================================================
780 * Re-build media header.
781 *
782 * Return: 1 physical address resolved.
783 * 0 physical address not resolved
784 */
785
786 static int if_rebuild_hdr (struct sk_buff *skb)
787 {
788 struct net_device *dev = skb->dev;
789 ppp_private_area_t *ppp_priv_area = dev->priv;
790 sdla_t *card = ppp_priv_area->card;
791
792 printk(KERN_INFO "%s: rebuild_header() called for interface %s!\n",
793 card->devname, dev->name);
794 return 1;
795 }
796
797
798 /*============================================================================
799 * Handle transmit timeout from netif watchdog
800 */
801 static void if_tx_timeout (struct net_device *dev)
802 {
803 ppp_private_area_t *ppp_priv_area = dev->priv;
804 sdla_t *card = ppp_priv_area->card;
805
806
807 /* If our device stays busy for at least 5 seconds then we will
808 * kick start the device by making dev->tbusy = 0. We expect
809 * that our device never stays busy more than 5 seconds. So this
810 * is only used as a last resort.
811 */
812
813 ++ppp_priv_area->if_send_stat.if_send_tbusy;
814 ++card->wandev.stats.collisions;
815
816 printk (KERN_INFO "%s: Transmit times out\n", card->devname);
817
818 ++ppp_priv_area->if_send_stat.if_send_tbusy_timeout;
819 ++card->wandev.stats.collisions;
820
821 /* unbusy the card (because only one interface per card) */
822 netif_start_queue(dev);
823 }
824
825
826 /*============================================================================
827 * Send a packet on a network interface.
828 * o set tbusy flag (marks start of the transmission) to block a timer-based
829 * transmit from overlapping.
830 * o check link state. If link is not up, then drop the packet.
831 * o execute adapter send command.
832 * o free socket buffer
833 *
834 * Return: 0 complete (socket buffer must be freed)
835 * non-0 packet may be re-transmitted (tbusy must be set)
836 *
837 * Notes:
838 * 1. This routine is called either by the protocol stack or by the "net
839 * bottom half" (with interrupts enabled).
840 * 2. Setting tbusy flag will inhibit further transmit requests from the
841 * protocol stack and can be used for flow control with protocol layer.
842 */
843 static int if_send (struct sk_buff *skb, struct net_device *dev)
844 {
845 ppp_private_area_t *ppp_priv_area = dev->priv;
846 sdla_t *card = ppp_priv_area->card;
847 unsigned char *sendpacket;
848 unsigned long smp_flags;
849 ppp_flags_t *flags = card->flags;
850 int retry = 0;
851 int udp_type;
852
853
854 ++ppp_priv_area->if_send_stat.if_send_entry;
855
856 if (skb == NULL) {
857
858 /* If we get here, some higher layer thinks we've missed an
859 * tx-done interrupt.
860 */
861 printk(KERN_INFO "%s: interface %s got kicked!\n",
862 card->devname, dev->name);
863
864 ++ppp_priv_area->if_send_stat.if_send_skb_null;
865
866 netif_wake_queue(dev);
867 return 0;
868
869 }
870
871 sendpacket = skb->data;
872
873 udp_type = udp_pkt_type( skb, card );
874
875
876 if (udp_type == UDP_PTPIPE_TYPE){
877 if(store_udp_mgmt_pkt(UDP_PKT_FRM_STACK, card, skb, dev,
878 ppp_priv_area)){
879 flags->imask |= PPP_INTR_TIMER;
880 }
881 ++ppp_priv_area->if_send_stat.if_send_PIPE_request;
882 return 0;
883
884 }
885
886 /* Check for broadcast and multicast addresses
887 * If found, drop (deallocate) a packet and return.
888 */
889 if(chk_bcast_mcast_addr(card, dev, skb)){
890 return 0;
891 }
892
893
894 if(card->hw.type != SDLA_S514){
895 s508_lock(card,&smp_flags);
896 }
897
898 if (test_and_set_bit(0, (void*)&card->wandev.critical)) {
899
900 printk(KERN_INFO "%s: Critical in if_send: %x\n",
901 card->wandev.name,card->wandev.critical);
902 dev_kfree_skb(skb);
903
904 ++card->wandev.stats.tx_dropped;
905 ++ppp_priv_area->if_send_stat.if_send_critical_non_ISR;
906
907 if(card->hw.type != SDLA_S514){
908 s508_unlock(card,&smp_flags);
909 }
910
911 return 0;
912 }
913
914 if (card->wandev.state != WAN_CONNECTED) {
915
916 ++ppp_priv_area->if_send_stat.if_send_wan_disconnected;
917 ++card->wandev.stats.tx_dropped;
918
919 } else if (!skb->protocol) {
920 ++ppp_priv_area->if_send_stat.if_send_protocol_error;
921 ++card->wandev.stats.tx_errors;
922
923 } else {
924
925 /*If it's IPX change the network numbers to 0 if they're ours.*/
926 if( skb->protocol == htons(ETH_P_IPX) ) {
927 if(ppp_priv_area->enable_IPX) {
928 switch_net_numbers( skb->data,
929 ppp_priv_area->network_number, 0);
930 } else {
931 ++card->wandev.stats.tx_dropped;
932 goto tx_done;
933 }
934 }
935
936 if (ppp_send(card, skb->data, skb->len, skb->protocol)) {
937 retry = 1;
938 netif_stop_queue(dev);
939 ++ppp_priv_area->if_send_stat.if_send_adptr_bfrs_full;
940 ++ppp_priv_area->if_send_stat.if_send_tx_int_enabled;
941 ppp_priv_area->tick_counter = jiffies;
942 flags->imask |= 0x02; /* unmask Tx interrupts */
943 } else {
944 ++ppp_priv_area->if_send_stat.if_send_bfr_passed_to_adptr;
945 ++card->wandev.stats.tx_packets;
946 card->wandev.stats.tx_bytes += skb->len;
947 }
948 }
949
950 tx_done:
951 if (!retry){
952 dev_kfree_skb(skb);
953 }
954
955 card->wandev.critical = 0;
956
957 if(card->hw.type != SDLA_S514){
958 s508_unlock(card,&smp_flags);
959 }
960
961
962 return retry;
963 }
964
965
966 /*=============================================================================
967 * Store a UDP management packet for later processing.
968 */
969
970 static int store_udp_mgmt_pkt(char udp_pkt_src, sdla_t* card,
971 struct sk_buff *skb, struct net_device* dev,
972 ppp_private_area_t* ppp_priv_area )
973 {
974 int udp_pkt_stored = 0;
975
976 if(!ppp_priv_area->udp_pkt_lgth && (skb->len<=MAX_LGTH_UDP_MGNT_PKT)){
977 ppp_priv_area->udp_pkt_lgth = skb->len;
978 ppp_priv_area->udp_pkt_src = udp_pkt_src;
979 memcpy(ppp_priv_area->udp_pkt_data, skb->data, skb->len);
980 ppp_priv_area->timer_int_enabled |= TMR_INT_ENABLED_UDP;
981 ppp_priv_area->protocol = skb->protocol;
982 udp_pkt_stored = 1;
983 }else{
984 if (skb->len > MAX_LGTH_UDP_MGNT_PKT){
985 printk(KERN_INFO "%s: PIPEMON UDP request too long : %i\n",
986 card->devname, skb->len);
987 }else{
988 printk(KERN_INFO "%s: PIPEMON UPD request already pending\n",
989 card->devname);
990 }
991 ppp_priv_area->udp_pkt_lgth = 0;
992 }
993
994 dev_kfree_skb(skb);
995 return(udp_pkt_stored);
996 }
997
998
999
1000 /*============================================================================
1001 * Reply to UDP Management system.
1002 * Return length of reply.
1003 */
1004 static int reply_udp( unsigned char *data, unsigned int mbox_len )
1005 {
1006 unsigned short len, udp_length, temp, ip_length;
1007 unsigned long ip_temp;
1008 int even_bound = 0;
1009 ppp_udp_pkt_t *p_udp_pkt = (ppp_udp_pkt_t *)data;
1010
1011 /* Set length of packet */
1012 len = sizeof(ip_pkt_t)+
1013 sizeof(udp_pkt_t)+
1014 sizeof(wp_mgmt_t)+
1015 sizeof(cblock_t)+
1016 mbox_len;
1017
1018 /* fill in UDP reply */
1019 p_udp_pkt->wp_mgmt.request_reply = UDPMGMT_REPLY;
1020
1021 /* fill in UDP length */
1022 udp_length = sizeof(udp_pkt_t)+
1023 sizeof(wp_mgmt_t)+
1024 sizeof(cblock_t)+
1025 mbox_len;
1026
1027
1028 /* put it on an even boundary */
1029 if ( udp_length & 0x0001 ) {
1030 udp_length += 1;
1031 len += 1;
1032 even_bound=1;
1033 }
1034
1035 temp = (udp_length<<8)|(udp_length>>8);
1036 p_udp_pkt->udp_pkt.udp_length = temp;
1037
1038
1039 /* swap UDP ports */
1040 temp = p_udp_pkt->udp_pkt.udp_src_port;
1041 p_udp_pkt->udp_pkt.udp_src_port =
1042 p_udp_pkt->udp_pkt.udp_dst_port;
1043 p_udp_pkt->udp_pkt.udp_dst_port = temp;
1044
1045
1046 /* add UDP pseudo header */
1047 temp = 0x1100;
1048 *((unsigned short *)(p_udp_pkt->data+mbox_len+even_bound)) = temp;
1049 temp = (udp_length<<8)|(udp_length>>8);
1050 *((unsigned short *)(p_udp_pkt->data+mbox_len+even_bound+2)) = temp;
1051
1052 /* calculate UDP checksum */
1053 p_udp_pkt->udp_pkt.udp_checksum = 0;
1054 p_udp_pkt->udp_pkt.udp_checksum =
1055 calc_checksum(&data[UDP_OFFSET],udp_length+UDP_OFFSET);
1056
1057 /* fill in IP length */
1058 ip_length = udp_length + sizeof(ip_pkt_t);
1059 temp = (ip_length<<8)|(ip_length>>8);
1060 p_udp_pkt->ip_pkt.total_length = temp;
1061
1062 /* swap IP addresses */
1063 ip_temp = p_udp_pkt->ip_pkt.ip_src_address;
1064 p_udp_pkt->ip_pkt.ip_src_address = p_udp_pkt->ip_pkt.ip_dst_address;
1065 p_udp_pkt->ip_pkt.ip_dst_address = ip_temp;
1066
1067 /* fill in IP checksum */
1068 p_udp_pkt->ip_pkt.hdr_checksum = 0;
1069 p_udp_pkt->ip_pkt.hdr_checksum = calc_checksum(data,sizeof(ip_pkt_t));
1070
1071 return len;
1072
1073 } /* reply_udp */
1074
1075 unsigned short calc_checksum (char *data, int len)
1076 {
1077 unsigned short temp;
1078 unsigned long sum=0;
1079 int i;
1080
1081 for( i = 0; i <len; i+=2 ) {
1082 memcpy(&temp,&data[i],2);
1083 sum += (unsigned long)temp;
1084 }
1085
1086 while (sum >> 16 ) {
1087 sum = (sum & 0xffffUL) + (sum >> 16);
1088 }
1089
1090 temp = (unsigned short)sum;
1091 temp = ~temp;
1092
1093 if( temp == 0 )
1094 temp = 0xffff;
1095
1096 return temp;
1097 }
1098
1099 /*
1100 If incoming is 0 (outgoing)- if the net numbers is ours make it 0
1101 if incoming is 1 - if the net number is 0 make it ours
1102
1103 */
1104 static void switch_net_numbers(unsigned char *sendpacket, unsigned long network_number, unsigned char incoming)
1105 {
1106 unsigned long pnetwork_number;
1107
1108 pnetwork_number = (unsigned long)((sendpacket[6] << 24) +
1109 (sendpacket[7] << 16) + (sendpacket[8] << 8) +
1110 sendpacket[9]);
1111
1112 if (!incoming) {
1113 //If the destination network number is ours, make it 0
1114 if( pnetwork_number == network_number) {
1115 sendpacket[6] = sendpacket[7] = sendpacket[8] =
1116 sendpacket[9] = 0x00;
1117 }
1118 } else {
1119 //If the incoming network is 0, make it ours
1120 if( pnetwork_number == 0) {
1121 sendpacket[6] = (unsigned char)(network_number >> 24);
1122 sendpacket[7] = (unsigned char)((network_number &
1123 0x00FF0000) >> 16);
1124 sendpacket[8] = (unsigned char)((network_number &
1125 0x0000FF00) >> 8);
1126 sendpacket[9] = (unsigned char)(network_number &
1127 0x000000FF);
1128 }
1129 }
1130
1131
1132 pnetwork_number = (unsigned long)((sendpacket[18] << 24) +
1133 (sendpacket[19] << 16) + (sendpacket[20] << 8) +
1134 sendpacket[21]);
1135
1136 if( !incoming ) {
1137 //If the source network is ours, make it 0
1138 if( pnetwork_number == network_number) {
1139 sendpacket[18] = sendpacket[19] = sendpacket[20] =
1140 sendpacket[21] = 0x00;
1141 }
1142 } else {
1143 //If the source network is 0, make it ours
1144 if( pnetwork_number == 0 ) {
1145 sendpacket[18] = (unsigned char)(network_number >> 24);
1146 sendpacket[19] = (unsigned char)((network_number &
1147 0x00FF0000) >> 16);
1148 sendpacket[20] = (unsigned char)((network_number &
1149 0x0000FF00) >> 8);
1150 sendpacket[21] = (unsigned char)(network_number &
1151 0x000000FF);
1152 }
1153 }
1154 } /* switch_net_numbers */
1155
1156 /*============================================================================
1157 * Get ethernet-style interface statistics.
1158 * Return a pointer to struct net_device_stats.
1159 */
1160 static struct net_device_stats *if_stats(struct net_device *dev)
1161 {
1162
1163 ppp_private_area_t *ppp_priv_area = dev->priv;
1164 sdla_t* card;
1165
1166 if( ppp_priv_area == NULL )
1167 return NULL;
1168
1169 card = ppp_priv_area->card;
1170 return &card->wandev.stats;
1171 }
1172
1173 /****** PPP Firmware Interface Functions ************************************/
1174
1175 /*============================================================================
1176 * Read firmware code version.
1177 * Put code version as ASCII string in str.
1178 */
1179 static int ppp_read_version(sdla_t *card, char *str)
1180 {
1181 ppp_mbox_t *mb = card->mbox;
1182 int err;
1183
1184 memset(&mb->cmd, 0, sizeof(ppp_cmd_t));
1185 mb->cmd.command = PPP_READ_CODE_VERSION;
1186 err = sdla_exec(mb) ? mb->cmd.result : CMD_TIMEOUT;
1187
1188 if (err != CMD_OK)
1189
1190 ppp_error(card, err, mb);
1191
1192 else if (str) {
1193
1194 int len = mb->cmd.length;
1195
1196 memcpy(str, mb->data, len);
1197 str[len] = '\0';
1198
1199 }
1200
1201 return err;
1202 }
1203 /*===========================================================================
1204 * Set Out-Bound Authentication.
1205 */
1206 static int ppp_set_outbnd_auth (sdla_t *card, ppp_private_area_t *ppp_priv_area)
1207 {
1208 ppp_mbox_t *mb = card->mbox;
1209 int err;
1210
1211 memset(&mb->cmd, 0, sizeof(ppp_cmd_t));
1212 memset(&mb->data, 0, (strlen(ppp_priv_area->userid) +
1213 strlen(ppp_priv_area->passwd) + 2 ) );
1214 memcpy(mb->data, ppp_priv_area->userid, strlen(ppp_priv_area->userid));
1215 memcpy((mb->data + strlen(ppp_priv_area->userid) + 1),
1216 ppp_priv_area->passwd, strlen(ppp_priv_area->passwd));
1217
1218 mb->cmd.length = strlen(ppp_priv_area->userid) +
1219 strlen(ppp_priv_area->passwd) + 2 ;
1220
1221 mb->cmd.command = PPP_SET_OUTBOUND_AUTH;
1222
1223 err = sdla_exec(mb) ? mb->cmd.result : CMD_TIMEOUT;
1224
1225 if (err != CMD_OK)
1226 ppp_error(card, err, mb);
1227
1228 return err;
1229 }
1230
1231 /*===========================================================================
1232 * Set In-Bound Authentication.
1233 */
1234 static int ppp_set_inbnd_auth (sdla_t *card, ppp_private_area_t *ppp_priv_area)
1235 {
1236 ppp_mbox_t *mb = card->mbox;
1237 int err, i;
1238 char* user_tokens[32];
1239 char* pass_tokens[32];
1240 int userids, passwds;
1241 int add_ptr;
1242
1243 memset(&mb->cmd, 0, sizeof(ppp_cmd_t));
1244 memset(&mb->data, 0, 1008);
1245 memcpy(mb->data, ppp_priv_area->sysname,
1246 strlen(ppp_priv_area->sysname));
1247
1248 /* Parse the userid string and the password string and build a string
1249 to copy it to the data area of the command structure. The string
1250 will look like "SYS_NAME<NULL>USER1<NULL>PASS1<NULL>USER2<NULL>PASS2
1251 ....<NULL> "
1252 */
1253 userids = tokenize( ppp_priv_area->userid, user_tokens);
1254 passwds = tokenize( ppp_priv_area->passwd, pass_tokens);
1255
1256 if (userids != passwds){
1257 printk(KERN_INFO "%s: Number of passwords does not equal the number of user ids\n", card->devname);
1258 return 1;
1259 }
1260
1261 add_ptr = strlen(ppp_priv_area->sysname) + 1;
1262 for (i=0; i<userids; i++){
1263 memcpy((mb->data + add_ptr), user_tokens[i],
1264 strlen(user_tokens[i]));
1265 memcpy((mb->data + add_ptr + strlen(user_tokens[i]) + 1),
1266 pass_tokens[i], strlen(pass_tokens[i]));
1267 add_ptr = add_ptr + strlen(user_tokens[i]) + 1 +
1268 strlen(pass_tokens[i]) + 1;
1269 }
1270
1271 mb->cmd.length = add_ptr + 1;
1272 mb->cmd.command = PPP_SET_INBOUND_AUTH;
1273
1274 err = sdla_exec(mb) ? mb->cmd.result : CMD_TIMEOUT;
1275
1276 if (err != CMD_OK)
1277 ppp_error(card, err, mb);
1278
1279 return err;
1280 }
1281
1282
1283 /*============================================================================
1284 * Tokenize string.
1285 * Parse a string of the following syntax:
1286 * <arg1>,<arg2>,...
1287 * and fill array of tokens with pointers to string elements.
1288 *
1289 */
1290 static int tokenize (char *str, char **tokens)
1291 {
1292 int cnt = 0;
1293
1294 tokens[0] = strtok(str, "/");
1295 while (tokens[cnt] && (cnt < 32 - 1))
1296 {
1297 tokens[cnt] = strstrip(tokens[cnt], " \t");
1298 tokens[++cnt] = strtok(NULL, "/");
1299 }
1300 return cnt;
1301 }
1302
1303 /*============================================================================
1304 * Strip leading and trailing spaces off the string str.
1305 */
1306 static char* strstrip (char *str, char* s)
1307 {
1308 char *eos = str + strlen(str); /* -> end of string */
1309
1310 while (*str && strchr(s, *str))
1311 ++str /* strip leading spaces */
1312 ;
1313 while ((eos > str) && strchr(s, *(eos - 1)))
1314 --eos /* strip trailing spaces */
1315 ;
1316 *eos = '\0';
1317 return str;
1318 }
1319 /*============================================================================
1320 * Configure PPP firmware.
1321 */
1322 static int ppp_configure(sdla_t *card, void *data)
1323 {
1324 ppp_mbox_t *mb = card->mbox;
1325 int data_len = sizeof(ppp508_conf_t);
1326 int err;
1327
1328 memset(&mb->cmd, 0, sizeof(ppp_cmd_t));
1329 memcpy(mb->data, data, data_len);
1330 mb->cmd.length = data_len;
1331 mb->cmd.command = PPP_SET_CONFIG;
1332 err = sdla_exec(mb) ? mb->cmd.result : CMD_TIMEOUT;
1333
1334 if (err != CMD_OK)
1335 ppp_error(card, err, mb);
1336
1337 return err;
1338 }
1339
1340 /*============================================================================
1341 * Set interrupt mode.
1342 */
1343 static int ppp_set_intr_mode(sdla_t *card, unsigned char mode)
1344 {
1345 ppp_mbox_t *mb = card->mbox;
1346 ppp_intr_info_t *ppp_intr_data = (ppp_intr_info_t *) &mb->data[0];
1347 int err;
1348
1349 memset(&mb->cmd, 0, sizeof(ppp_cmd_t));
1350 ppp_intr_data->i_enable = mode;
1351
1352 ppp_intr_data->irq = card->hw.irq;
1353 mb->cmd.length = 2;
1354
1355 /* If timer has been enabled, set the timer delay to 1sec */
1356 if (mode & 0x80){
1357 ppp_intr_data->timer_len = 5;//100; //250;
1358 mb->cmd.length = 4;
1359 }
1360
1361 mb->cmd.command = PPP_SET_INTR_FLAGS;
1362 err = sdla_exec(mb) ? mb->cmd.result : CMD_TIMEOUT;
1363
1364 if (err != CMD_OK)
1365 ppp_error(card, err, mb);
1366
1367
1368 return err;
1369 }
1370
1371 /*============================================================================
1372 * Enable communications.
1373 */
1374 static int ppp_comm_enable(sdla_t *card)
1375 {
1376 ppp_mbox_t *mb = card->mbox;
1377 int err;
1378
1379 memset(&mb->cmd, 0, sizeof(ppp_cmd_t));
1380 mb->cmd.command = PPP_COMM_ENABLE;
1381 err = sdla_exec(mb) ? mb->cmd.result : CMD_TIMEOUT;
1382
1383 if (err != CMD_OK)
1384 ppp_error(card, err, mb);
1385
1386 return err;
1387 }
1388
1389 /*============================================================================
1390 * Disable communications.
1391 */
1392 static int ppp_comm_disable(sdla_t *card)
1393 {
1394 ppp_mbox_t *mb = card->mbox;
1395 int err;
1396
1397 memset(&mb->cmd, 0, sizeof(ppp_cmd_t));
1398 mb->cmd.command = PPP_COMM_DISABLE;
1399 err = sdla_exec(mb) ? mb->cmd.result : CMD_TIMEOUT;
1400 if (err != CMD_OK)
1401 ppp_error(card, err, mb);
1402
1403 return err;
1404 }
1405
1406 /*============================================================================
1407 * Get communications error statistics.
1408 */
1409 static int ppp_get_err_stats(sdla_t *card)
1410 {
1411 ppp_mbox_t *mb = card->mbox;
1412 int err;
1413
1414 memset(&mb->cmd, 0, sizeof(ppp_cmd_t));
1415 mb->cmd.command = PPP_READ_ERROR_STATS;
1416 err = sdla_exec(mb) ? mb->cmd.result : CMD_TIMEOUT;
1417
1418 if (err == CMD_OK) {
1419
1420 ppp_err_stats_t* stats = (void*)mb->data;
1421 card->wandev.stats.rx_over_errors = stats->rx_overrun;
1422 card->wandev.stats.rx_crc_errors = stats->rx_bad_crc;
1423 card->wandev.stats.rx_missed_errors = stats->rx_abort;
1424 card->wandev.stats.rx_length_errors = stats->rx_lost;
1425 card->wandev.stats.tx_aborted_errors = stats->tx_abort;
1426
1427 } else
1428 ppp_error(card, err, mb);
1429
1430 return err;
1431 }
1432
1433 /*============================================================================
1434 * Send packet.
1435 * Return: 0 - o.k.
1436 * 1 - no transmit buffers available
1437 */
1438 static int ppp_send (sdla_t *card, void *data, unsigned len, unsigned proto)
1439 {
1440 ppp_buf_ctl_t *txbuf = card->u.p.txbuf;
1441
1442 if (txbuf->flag)
1443 return 1;
1444
1445 sdla_poke(&card->hw, txbuf->buf.ptr, data, len);
1446
1447 txbuf->length = len; /* frame length */
1448
1449 if (proto == htons(ETH_P_IPX))
1450 txbuf->proto = 0x01; /* protocol ID */
1451 else
1452 txbuf->proto = 0x00; /* protocol ID */
1453
1454 txbuf->flag = 1; /* start transmission */
1455
1456 /* Update transmit buffer control fields */
1457 card->u.p.txbuf = ++txbuf;
1458
1459 if ((void*)txbuf > card->u.p.txbuf_last)
1460 card->u.p.txbuf = card->u.p.txbuf_base;
1461
1462 return 0;
1463 }
1464
1465 /****** Firmware Error Handler **********************************************/
1466
1467 /*============================================================================
1468 * Firmware error handler.
1469 * This routine is called whenever firmware command returns non-zero
1470 * return code.
1471 *
1472 * Return zero if previous command has to be cancelled.
1473 */
1474 static int ppp_error(sdla_t *card, int err, ppp_mbox_t *mb)
1475 {
1476 unsigned cmd = mb->cmd.command;
1477
1478 switch (err) {
1479
1480 case CMD_TIMEOUT:
1481 printk(KERN_ERR "%s: command 0x%02X timed out!\n",
1482 card->devname, cmd);
1483 break;
1484
1485 default:
1486 printk(KERN_INFO "%s: command 0x%02X returned 0x%02X!\n"
1487 , card->devname, cmd, err);
1488 }
1489
1490 return 0;
1491 }
1492
1493 /****** Interrupt Handlers **************************************************/
1494
1495 /*============================================================================
1496 * PPP interrupt service routine.
1497 */
1498 STATIC void wpp_isr(sdla_t *card)
1499 {
1500 ppp_flags_t *flags = card->flags;
1501 char *ptr = &flags->iflag;
1502 struct net_device *dev = card->wandev.dev;
1503
1504
1505 int i;
1506
1507 card->in_isr = 1;
1508
1509 ++card->statistics.isr_entry;
1510
1511 //FIXME: Do we need this
1512 card->force_enable_irq = 0;
1513
1514 if(card->hw.type != SDLA_S514){
1515 if (test_and_set_bit(0, (void*)&card->wandev.critical)) {
1516
1517 ++card->statistics.isr_already_critical;
1518 printk (KERN_INFO "%s: Critical while in ISR!\n",
1519 card->devname);
1520 card->in_isr = 0;
1521 return;
1522
1523 }
1524 }
1525
1526 card->buff_int_mode_unbusy = 0;
1527
1528 switch (flags->iflag) {
1529
1530 case PPP_INTR_RXRDY: /* receive interrupt 0x01 (bit 0)*/
1531 ++card->statistics.isr_rx;
1532 rx_intr(card);
1533 break;
1534
1535 case PPP_INTR_TXRDY: /* transmit interrupt 0x02 (bit 1)*/
1536 ++card->statistics.isr_tx;
1537 flags->imask &= ~PPP_INTR_TXRDY;
1538 netif_wake_queue (dev);
1539 card->buff_int_mode_unbusy = 1;
1540 break;
1541
1542 case PPP_INTR_CMD: /* interface command completed */
1543 ++Intr_test_counter;
1544 ++card->statistics.isr_intr_test;
1545 break;
1546
1547 case PPP_INTR_MODEM: /* modem status change (DCD, CTS) 0x04 (bit 2)*/
1548 case PPP_INTR_DISC: /* Data link disconnected 0x10 (bit 4)*/
1549 case PPP_INTR_OPEN: /* Data link open 0x20 (bit 5)*/
1550 case PPP_INTR_DROP_DTR: /* DTR drop timeout expired 0x40 bit 6 */
1551 event_intr(card);
1552 break;
1553
1554 case PPP_INTR_TIMER:
1555 timer_intr(card);
1556 break;
1557
1558 default: /* unexpected interrupt */
1559 ++card->statistics.isr_spurious;
1560 printk(KERN_INFO "%s: spurious interrupt 0x%02X!\n",
1561 card->devname, flags->iflag);
1562 printk(KERN_INFO "%s: ID Bytes = ",card->devname);
1563 for(i = 0; i < 8; i ++)
1564 printk(KERN_INFO "0x%02X ", *(ptr + 0x28 + i));
1565 printk(KERN_INFO "\n");
1566 }
1567
1568 card->in_isr = 0;
1569 flags->iflag = 0;
1570 card->wandev.critical = 0;
1571
1572 if(card->buff_int_mode_unbusy)
1573 netif_wake_queue(dev);
1574 }
1575
1576 /*============================================================================
1577 * Receive interrupt handler.
1578 */
1579 static void rx_intr(sdla_t *card)
1580 {
1581 ppp_buf_ctl_t *rxbuf = card->rxmb;
1582 struct net_device *dev = card->wandev.dev;
1583 ppp_private_area_t *ppp_priv_area;
1584 struct sk_buff *skb;
1585 unsigned len;
1586 void *buf;
1587 int i;
1588 ppp_flags_t *flags = card->flags;
1589 char *ptr = &flags->iflag;
1590 int udp_type;
1591
1592
1593 if (rxbuf->flag != 0x01) {
1594
1595 printk(KERN_INFO
1596 "%s: corrupted Rx buffer @ 0x%X, flag = 0x%02X!\n",
1597 card->devname, (unsigned)rxbuf, rxbuf->flag);
1598
1599 printk(KERN_INFO "%s: ID Bytes = ",card->devname);
1600
1601 for(i = 0; i < 8; i ++)
1602 printk(KERN_INFO "0x%02X ", *(ptr + 0x28 + i));
1603 printk(KERN_INFO "\n");
1604
1605 ++card->statistics.rx_intr_corrupt_rx_bfr;
1606 return;
1607
1608 }
1609
1610 if (dev && netif_running(dev)) {
1611
1612 len = rxbuf->length;
1613 ppp_priv_area = dev->priv;
1614
1615 /* Allocate socket buffer */
1616 skb = dev_alloc_skb(len);
1617
1618 if (skb != NULL) {
1619
1620 /* Copy data to the socket buffer */
1621 unsigned addr = rxbuf->buf.ptr;
1622
1623 if ((addr + len) > card->u.p.rx_top + 1) {
1624
1625 unsigned tmp = card->u.p.rx_top - addr + 1;
1626 buf = skb_put(skb, tmp);
1627 sdla_peek(&card->hw, addr, buf, tmp);
1628 addr = card->u.p.rx_base;
1629 len -= tmp;
1630 }
1631 buf = skb_put(skb, len);
1632 sdla_peek(&card->hw, addr, buf, len);
1633
1634 /* Decapsulate packet */
1635 switch (rxbuf->proto) {
1636
1637 case 0x00:
1638 skb->protocol = htons(ETH_P_IP);
1639 break;
1640
1641 case 0x01:
1642 skb->protocol = htons(ETH_P_IPX);
1643 break;
1644 }
1645
1646 udp_type = udp_pkt_type( skb, card );
1647
1648 if (udp_type == UDP_PTPIPE_TYPE){
1649
1650 /* Handle a UDP Request in Timer Interrupt */
1651 if(store_udp_mgmt_pkt(UDP_PKT_FRM_NETWORK, card, skb, dev,
1652 ppp_priv_area)){
1653 flags->imask |= PPP_INTR_TIMER;
1654 }
1655 ++ppp_priv_area->rx_intr_stat.rx_intr_PIPE_request;
1656
1657
1658 } else if (handle_IPXWAN(skb->data,card->devname,
1659 ppp_priv_area->enable_IPX,
1660 ppp_priv_area->network_number,
1661 skb->protocol)) {
1662
1663 /* Handle an IPXWAN packet */
1664 if( ppp_priv_area->enable_IPX) {
1665 ppp_send(card, skb->data, skb->len, htons(ETH_P_IPX));
1666 dev_kfree_skb(skb);
1667
1668
1669 } else {
1670 ++card->wandev.stats.rx_dropped;
1671 }
1672 } else {
1673 /* Pass data up the protocol stack */
1674 skb->dev = dev;
1675 skb->mac.raw = skb->data;
1676
1677 ++card->wandev.stats.rx_packets;
1678 card->wandev.stats.rx_bytes += skb->len;
1679 ++ppp_priv_area->rx_intr_stat.rx_intr_bfr_passed_to_stack;
1680 netif_rx(skb);
1681 }
1682
1683 } else {
1684
1685 printk(KERN_INFO "%s: no socket buffers available!\n",
1686 card->devname);
1687 ++card->wandev.stats.rx_dropped;
1688 ++ppp_priv_area->rx_intr_stat.rx_intr_no_socket;
1689
1690 dev_kfree_skb(skb);
1691 }
1692
1693 } else {
1694 ++card->statistics.rx_intr_dev_not_started;
1695 }
1696
1697 /* Release buffer element and calculate a pointer to the next one */
1698 rxbuf->flag = 0x00;
1699 card->rxmb = ++rxbuf;
1700 if ((void*)rxbuf > card->u.p.rxbuf_last)
1701 card->rxmb = card->u.p.rxbuf_base;
1702 }
1703
1704
1705 void event_intr (sdla_t *card)
1706 {
1707
1708 struct net_device* dev = card->wandev.dev;
1709 ppp_private_area_t* ppp_priv_area = dev->priv;
1710 volatile ppp_flags_t *flags = card->flags;
1711
1712 switch (flags->iflag){
1713
1714 case PPP_INTR_MODEM: /* modem status change (DCD, CTS) 0x04 (bit 2)*/
1715 printk (KERN_INFO "%s: Modem status: DCD=%s CTS=%s\n",
1716 card->devname, DCD(flags->mstatus), CTS(flags->mstatus));
1717
1718 break;
1719
1720 case PPP_INTR_DISC: /* Data link disconnected 0x10 (bit 4)*/
1721
1722 NEX_PRINTK (KERN_INFO "Data link disconnected intr Cause %X\n",
1723 flags->disc_cause);
1724
1725 if (flags->disc_cause &
1726 (PPP_LOCAL_TERMINATION | PPP_DCD_CTS_DROP |
1727 PPP_REMOTE_TERMINATION)) {
1728 if (card->u.p.ip_mode == WANOPT_PPP_PEER) {
1729 Read_connection_info = 1;
1730 remove_route (card);
1731 }
1732 wanpipe_set_state(card, WAN_DISCONNECTED);
1733 show_disc_cause(card, flags->disc_cause);
1734 ppp_priv_area->timer_int_enabled |=
1735 TMR_INT_ENABLED_PPP_EVENT;
1736 flags->imask |= PPP_INTR_TIMER;
1737 }
1738 break;
1739
1740 case PPP_INTR_OPEN: /* Data link open 0x20 (bit 5)*/
1741
1742 NEX_PRINTK (KERN_INFO "%s: PPP Link Open, LCP=%s IP=%s\n",
1743 card->devname,LCP(flags->lcp_state),
1744 IP(flags->ip_state));
1745
1746 if (flags->lcp_state == 0x09 &&
1747 (flags->ip_state == 0x09 || flags->ipx_state == 0x09)){
1748 /* Initialize the polling timer and set the state
1749 * to WAN_CONNNECTED
1750 */
1751 card->state_tick = jiffies;
1752 wanpipe_set_state(card, WAN_CONNECTED);
1753 ppp_priv_area->timer_int_enabled |=
1754 TMR_INT_ENABLED_PPP_EVENT;
1755 flags->imask |= PPP_INTR_TIMER;
1756
1757 }
1758 break;
1759
1760 case PPP_INTR_DROP_DTR: /* DTR drop timeout expired 0x40 bit 6 */
1761
1762 NEX_PRINTK(KERN_INFO "DTR Drop Timeout Interrrupt \n");
1763 if (card->u.p.ip_mode == WANOPT_PPP_PEER) {
1764 Read_connection_info = 1;
1765 remove_route (card);
1766 }
1767 wanpipe_set_state(card, WAN_DISCONNECTED);
1768 show_disc_cause(card, flags->disc_cause);
1769 ppp_priv_area->timer_int_enabled |=
1770 TMR_INT_ENABLED_PPP_EVENT;
1771 flags->imask |= PPP_INTR_TIMER;
1772 break;
1773
1774 default:
1775 printk(KERN_INFO "%s: Error, Invalid PPP Event\n",card->devname);
1776 }
1777 }
1778
1779
1780
1781 /* TIMER INTERRUPT */
1782
1783 void timer_intr (sdla_t *card)
1784 {
1785
1786 struct net_device* dev = card->wandev.dev;
1787 ppp_private_area_t* ppp_priv_area = dev->priv;
1788 ppp_flags_t *flags = card->flags;
1789
1790 /* Update statistics */
1791 if (ppp_priv_area->timer_int_enabled & TMR_INT_ENABLED_UPDATE){
1792 ppp_get_err_stats(card);
1793 if(!(--ppp_priv_area->update_comms_stats)){
1794 ppp_priv_area->timer_int_enabled &=
1795 ~TMR_INT_ENABLED_UPDATE;
1796 }
1797 }
1798
1799 /* PPIPEMON UDP request */
1800
1801 if (ppp_priv_area->timer_int_enabled & TMR_INT_ENABLED_UDP){
1802 process_udp_mgmt_pkt(card,dev, ppp_priv_area);
1803 ppp_priv_area->timer_int_enabled &= ~TMR_INT_ENABLED_UDP;
1804 }
1805
1806
1807 /* PPP Event */
1808 if (ppp_priv_area->timer_int_enabled & TMR_INT_ENABLED_PPP_EVENT){
1809
1810 if (card->wandev.state == WAN_DISCONNECTED){
1811 poll_disconnected(card);
1812 }
1813
1814 /* If the state is CONNECTING, it means that communicatins were
1815 * enabled. When the remote side enables its comminication we
1816 * should get an interrupt PPP_INTR_OPEN, thus turn off polling
1817 */
1818
1819 else if (card->wandev.state == WAN_CONNECTING){
1820 /* Turn off the timer interrupt */
1821 ppp_priv_area->timer_int_enabled &= ~TMR_INT_ENABLED_PPP_EVENT;
1822 }
1823
1824 /* If state is connected and we are in PEER mode
1825 * poll for an IP address which will be provided by remote end.
1826 */
1827 else if ((card->wandev.state == WAN_CONNECTED &&
1828 card->u.p.ip_mode == WANOPT_PPP_PEER) &&
1829 Read_connection_info){
1830
1831 card->state_tick = jiffies;
1832 if (!read_connection_info (card)){
1833 card->poll = &process_route;
1834 }
1835
1836 }else{
1837 /* If we are using Static IP,no need to poll for
1838 * an IP address.
1839 */
1840 NEX_PRINTK(KERN_INFO "Turning off TIMER \n");
1841 ppp_priv_area->timer_int_enabled &= ~TMR_INT_ENABLED_PPP_EVENT;
1842 }
1843
1844 }/* End of PPP_EVENT */
1845
1846
1847 /* Only disable the timer interrupt if there are no udp, statistic */
1848 /* updates or events pending */
1849 if(!ppp_priv_area->timer_int_enabled) {
1850 flags->imask &= ~PPP_INTR_TIMER;
1851 }
1852 }
1853
1854
1855 static int handle_IPXWAN(unsigned char *sendpacket, char *devname, unsigned char enable_IPX, unsigned long network_number, unsigned short proto)
1856 {
1857 int i;
1858
1859 if( proto == htons(ETH_P_IPX) ) {
1860 //It's an IPX packet
1861 if(!enable_IPX) {
1862 //Return 1 so we don't pass it up the stack.
1863 return 1;
1864 }
1865 } else {
1866 //It's not IPX so pass it up the stack.
1867 return 0;
1868 }
1869
1870 if( sendpacket[16] == 0x90 &&
1871 sendpacket[17] == 0x04)
1872 {
1873 //It's IPXWAN
1874
1875 if( sendpacket[2] == 0x02 &&
1876 sendpacket[34] == 0x00)
1877 {
1878 //It's a timer request packet
1879 printk(KERN_INFO "%s: Received IPXWAN Timer Request packet\n",devname);
1880
1881 //Go through the routing options and answer no to every
1882 //option except Unnumbered RIP/SAP
1883 for(i = 41; sendpacket[i] == 0x00; i += 5)
1884 {
1885 //0x02 is the option for Unnumbered RIP/SAP
1886 if( sendpacket[i + 4] != 0x02)
1887 {
1888 sendpacket[i + 1] = 0;
1889 }
1890 }
1891
1892 //Skip over the extended Node ID option
1893 if( sendpacket[i] == 0x04 )
1894 {
1895 i += 8;
1896 }
1897
1898 //We also want to turn off all header compression opt.
1899 for(; sendpacket[i] == 0x80 ;)
1900 {
1901 sendpacket[i + 1] = 0;
1902 i += (sendpacket[i + 2] << 8) + (sendpacket[i + 3]) + 4;
1903 }
1904
1905 //Set the packet type to timer response
1906 sendpacket[34] = 0x01;
1907
1908 printk(KERN_INFO "%s: Sending IPXWAN Timer Response\n",devname);
1909 }
1910 else if( sendpacket[34] == 0x02 )
1911 {
1912 //This is an information request packet
1913 printk(KERN_INFO "%s: Received IPXWAN Information Request packet\n",devname);
1914
1915 //Set the packet type to information response
1916 sendpacket[34] = 0x03;
1917
1918 //Set the router name
1919 sendpacket[51] = 'P';
1920 sendpacket[52] = 'T';
1921 sendpacket[53] = 'P';
1922 sendpacket[54] = 'I';
1923 sendpacket[55] = 'P';
1924 sendpacket[56] = 'E';
1925 sendpacket[57] = '-';
1926 sendpacket[58] = CVHexToAscii(network_number >> 28);
1927 sendpacket[59] = CVHexToAscii((network_number & 0x0F000000)>> 24);
1928 sendpacket[60] = CVHexToAscii((network_number & 0x00F00000)>> 20);
1929 sendpacket[61] = CVHexToAscii((network_number & 0x000F0000)>> 16);
1930 sendpacket[62] = CVHexToAscii((network_number & 0x0000F000)>> 12);
1931 sendpacket[63] = CVHexToAscii((network_number & 0x00000F00)>> 8);
1932 sendpacket[64] = CVHexToAscii((network_number & 0x000000F0)>> 4);
1933 sendpacket[65] = CVHexToAscii(network_number & 0x0000000F);
1934 for(i = 66; i < 99; i+= 1)
1935 {
1936 sendpacket[i] = 0;
1937 }
1938
1939 printk(KERN_INFO "%s: Sending IPXWAN Information Response packet\n",devname);
1940 }
1941 else
1942 {
1943 printk(KERN_INFO "%s: Unknown IPXWAN packet!\n",devname);
1944 return 0;
1945 }
1946
1947 //Set the WNodeID to our network address
1948 sendpacket[35] = (unsigned char)(network_number >> 24);
1949 sendpacket[36] = (unsigned char)((network_number & 0x00FF0000) >> 16);
1950 sendpacket[37] = (unsigned char)((network_number & 0x0000FF00) >> 8);
1951 sendpacket[38] = (unsigned char)(network_number & 0x000000FF);
1952
1953 return 1;
1954 } else {
1955 //If we get here's its an IPX-data packet, so it'll get passed up the stack.
1956
1957 //switch the network numbers
1958 switch_net_numbers(sendpacket, network_number, 1);
1959 return 0;
1960 }
1961 }
1962
1963 /****** Background Polling Routines ****************************************/
1964
1965 /* All polling functions are invoked by the TIMER interrupt in the wpp_isr
1966 * routine.
1967 */
1968
1969 /*============================================================================
1970 * Monitor active link phase.
1971 */
1972 static void process_route (sdla_t *card)
1973 {
1974 ppp_flags_t *flags = card->flags;
1975 struct net_device *dev = card->wandev.dev;
1976 struct in_device *in_dev = dev->ip_ptr;
1977
1978 if (in_dev != NULL ) {
1979 if ((card->u.p.ip_mode == WANOPT_PPP_PEER) &&
1980 (Read_connection_info && flags->ip_state == 0x09)){
1981
1982 printk(KERN_INFO "%s: IPCP State Opened.\n", card->devname);
1983 if (read_info( card )) {
1984 printk(KERN_INFO
1985 "%s: An error occurred in IP assignment.\n",
1986 card->devname);
1987 } else {
1988 struct in_ifaddr *ifa = in_dev->ifa_list;
1989 printk(KERN_INFO "%s: Assigned Lcl. Addr: %s\n",
1990 card->devname, in_ntoa(ifa->ifa_local));
1991 printk(KERN_INFO "%s: Assigned Rmt. Addr: %s\n",
1992 card->devname, in_ntoa(ifa->ifa_address));
1993 }
1994 Read_connection_info = 0;
1995 }
1996 }else{
1997 printk(KERN_INFO "%s: Error: Null pointer in Poll Active\n",
1998 card->devname);
1999 }
2000 card->poll = NULL;
2001
2002 }
2003
2004 /*============================================================================
2005 * Monitor physical link disconnected phase.
2006 * o if interface is up and the hold-down timeout has expired, then retry
2007 * connection.
2008 */
2009 static void poll_disconnected(sdla_t *card)
2010 {
2011 struct net_device *dev = card->wandev.dev;
2012
2013 if (dev && netif_running(dev) &&
2014 ((jiffies - card->state_tick) > HOLD_DOWN_TIME)) {
2015
2016 wanpipe_set_state(card, WAN_CONNECTING);
2017
2018 if(ppp_comm_enable(card) == CMD_OK){
2019 init_ppp_tx_rx_buff( card );
2020 }
2021
2022 }
2023 }
2024
2025 /****** Miscellaneous Functions *********************************************/
2026
2027 /*============================================================================
2028 * Configure S508 adapter.
2029 */
2030 static int config508(ppp_private_area_t *ppp_priv_area, sdla_t *card)
2031 {
2032 ppp508_conf_t cfg;
2033 struct net_device *dev = card->wandev.dev;
2034 struct in_device *in_dev = dev->ip_ptr;
2035
2036 /* Prepare PPP configuration structure */
2037 memset(&cfg, 0, sizeof(ppp508_conf_t));
2038
2039 if (card->wandev.clocking)
2040 cfg.line_speed = card->wandev.bps;
2041
2042 if (card->wandev.interface == WANOPT_RS232)
2043 cfg.conf_flags |= INTERFACE_LEVEL_RS232;
2044
2045 cfg.conf_flags |= DONT_TERMINATE_LNK_MAX_CONFIG; /*send Configure-Request packets forever*/
2046 cfg.txbuf_percent = PERCENT_TX_BUFF; /* % of Tx bufs */
2047 cfg.mtu_local = card->wandev.mtu;
2048 cfg.mtu_remote = card->wandev.mtu; /* Default */
2049 cfg.restart_tmr = TIME_BETWEEN_CONF_REQ; /* 30 = 3sec */
2050 cfg.auth_rsrt_tmr = TIME_BETWEEN_PAP_CHAP_REQ; /* 30 = 3sec */
2051 cfg.auth_wait_tmr = WAIT_PAP_CHAP_WITHOUT_REPLY; /* 300 = 30s */
2052 cfg.mdm_fail_tmr = WAIT_AFTER_DCD_CTS_LOW; /* 5 = 0.5s */
2053 cfg.dtr_drop_tmr = TIME_DCD_CTS_LOW_AFTER_LNK_DOWN; /* 10 = 1s */
2054 cfg.connect_tmout = WAIT_DCD_HIGH_AFTER_ENABLE_COMM; /* 900 = 90s */
2055 cfg.conf_retry = MAX_CONF_REQ_WITHOUT_REPLY; /* 10 = 1s */
2056 cfg.term_retry = MAX_TERM_REQ_WITHOUT_REPLY; /* 2 times */
2057 cfg.fail_retry = NUM_CONF_NAK_WITHOUT_REPLY; /* 5 times */
2058 cfg.auth_retry = NUM_AUTH_REQ_WITHOUT_REPLY; /* 10 times */
2059
2060
2061 if( !card->u.p.authenticator ) {
2062 printk(KERN_INFO "%s: Device is not configured as an authenticator\n",
2063 card->devname);
2064 cfg.auth_options = NO_AUTHENTICATION;
2065 }else{
2066 printk(KERN_INFO "%s: Device is configured as an authenticator\n",
2067 card->devname);
2068 cfg.auth_options = INBOUND_AUTH;
2069 }
2070 if( ppp_priv_area->pap == WANOPT_YES){
2071 cfg.auth_options |=PAP_AUTH;
2072 printk(KERN_INFO "%s: Pap enabled\n", card->devname);
2073 }
2074 if( ppp_priv_area->chap == WANOPT_YES){
2075 cfg.auth_options |= CHAP_AUTH;
2076 printk(KERN_INFO "%s: Chap enabled\n", card->devname);
2077 }
2078
2079
2080 if (ppp_priv_area->enable_IPX == WANOPT_YES){
2081 cfg.ipx_options = ENABLE_IPX | ROUTING_PROT_DEFAULT;
2082 }else{
2083 cfg.ipx_options = DISABLE_IPX;
2084 }
2085
2086 switch (card->u.p.ip_mode) {
2087
2088 case WANOPT_PPP_STATIC:
2089
2090 cfg.ip_options = L_AND_R_IP_NO_ASSIG |
2091 ENABLE_IP;
2092 cfg.ip_local = in_dev->ifa_list->ifa_local;
2093 cfg.ip_remote = in_dev->ifa_list->ifa_address;
2094 NEX_PRINTK(KERN_INFO "Local %s Remote %s Name %s\n",
2095 in_ntoa(cfg.ip_local),
2096 in_ntoa(cfg.ip_remote),
2097 dev->name);
2098 break;
2099
2100 case WANOPT_PPP_PEER:
2101 cfg.ip_options = L_IP_REMOTE_ASSIG |
2102 R_IP_REMOTE_ASSIG |
2103 ENABLE_IP;
2104 cfg.ip_local = 0x00;
2105 cfg.ip_remote = 0x00;
2106 break;
2107
2108 }
2109 return ppp_configure(card, &cfg);
2110 }
2111
2112 /*============================================================================
2113 * Show disconnection cause.
2114 */
2115 static void show_disc_cause(sdla_t *card, unsigned cause)
2116 {
2117 if (cause & 0x0802)
2118
2119 printk(KERN_INFO "%s: link terminated by peer\n",
2120 card->devname);
2121
2122 else if (cause & 0x0004)
2123
2124 printk(KERN_INFO "%s: link terminated by user\n",
2125 card->devname);
2126
2127 else if (cause & 0x0008)
2128
2129 printk(KERN_INFO "%s: authentication failed\n", card->devname);
2130
2131 else if (cause & 0x0010)
2132
2133 printk(KERN_INFO
2134 "%s: authentication protocol negotiation failed\n",
2135 card->devname);
2136
2137 else if (cause & 0x0020)
2138
2139 printk(KERN_INFO
2140 "%s: peer's request for authentication rejected\n",
2141 card->devname);
2142
2143 else if (cause & 0x0040)
2144
2145 printk(KERN_INFO "%s: MRU option rejected by peer\n",
2146 card->devname);
2147
2148 else if (cause & 0x0080)
2149
2150 printk(KERN_INFO "%s: peer's MRU was too small\n",
2151 card->devname);
2152
2153 else if (cause & 0x0100)
2154
2155 printk(KERN_INFO "%s: failed to negotiate peer's LCP options\n",
2156 card->devname);
2157
2158 else if (cause & 0x0200)
2159
2160 printk(KERN_INFO "%s: failed to negotiate peer's IPCP options\n"
2161 , card->devname);
2162
2163 else if (cause & 0x0400)
2164
2165 printk(KERN_INFO
2166 "%s: failed to negotiate peer's IPXCP options\n",
2167 card->devname);
2168 }
2169
2170 /*=============================================================================
2171 * Process UDP call of type PTPIPEAB.
2172 */
2173 static void process_udp_mgmt_pkt(sdla_t *card, struct net_device *dev,
2174 ppp_private_area_t *ppp_priv_area )
2175 {
2176 unsigned char buf2[5];
2177 unsigned char *buf;
2178 unsigned int frames, len;
2179 struct sk_buff *new_skb;
2180 unsigned short data_length, buffer_length, real_len;
2181 unsigned long data_ptr;
2182 int udp_mgmt_req_valid = 1;
2183 ppp_mbox_t *mbox = card->mbox;
2184 struct timeval tv;
2185 int err;
2186 ppp_udp_pkt_t *ppp_udp_pkt = (ppp_udp_pkt_t*)&ppp_priv_area->udp_pkt_data;
2187
2188 memcpy(&buf2, &card->wandev.udp_port, 2 );
2189
2190
2191 switch(ppp_udp_pkt->cblock.command) {
2192
2193 /* FT1 MONITOR STATUS */
2194 case FT1_MONITOR_STATUS_CTRL:
2195
2196 /* PPIPE_ENABLE_TRACING */
2197 case PPIPE_ENABLE_TRACING:
2198
2199 /* PPIPE_DISABLE_TRACING */
2200 case PPIPE_DISABLE_TRACING:
2201
2202 /* PPIPE_GET_TRACE_INFO */
2203 case PPIPE_GET_TRACE_INFO:
2204
2205 /* SET FT1 MODE */
2206 case SET_FT1_MODE:
2207 if(ppp_priv_area->udp_pkt_src == UDP_PKT_FRM_NETWORK) {
2208
2209 ++ppp_priv_area->pipe_mgmt_stat.
2210 UDP_PIPE_mgmt_direction_err;
2211 udp_mgmt_req_valid = 0;
2212 }
2213 break;
2214
2215 default:
2216 break;
2217 }
2218
2219 if(!udp_mgmt_req_valid) {
2220
2221 /* set length to 0 */
2222 ppp_udp_pkt->cblock.length = 0x00;
2223
2224 /* set return code */
2225 ppp_udp_pkt->cblock.result = 0xCD;
2226
2227 } else {
2228 /* Initialize the trace element */
2229 trace_element_t trace_element;
2230
2231 switch (ppp_udp_pkt->cblock.command){
2232
2233 /* PPIPE_ENABLE_TRACING */
2234 case PPIPE_ENABLE_TRACING:
2235 if (!card->TracingEnabled) {
2236
2237 /* OPERATE_DATALINE_MONITOR */
2238 mbox->cmd.command = PPP_DATALINE_MONITOR;
2239 mbox->cmd.length = 0x01;
2240 mbox->data[0] = ppp_udp_pkt->data[0];
2241 err = sdla_exec(mbox) ?
2242 mbox->cmd.result : CMD_TIMEOUT;
2243
2244 if (err != CMD_OK) {
2245
2246 ppp_error(card, err, mbox);
2247 card->TracingEnabled = 0;
2248
2249 /* set the return code */
2250
2251 ppp_udp_pkt->cblock.result = mbox->cmd.result;
2252 mbox->cmd.length = 0;
2253 break;
2254 }
2255
2256 sdla_peek(&card->hw, 0xC000, &buf2, 2);
2257
2258 ppp_priv_area->curr_trace_addr = 0;
2259 memcpy(&ppp_priv_area->curr_trace_addr, &buf2, 2);
2260 ppp_priv_area->start_trace_addr =
2261 ppp_priv_area->curr_trace_addr;
2262 ppp_priv_area->end_trace_addr =
2263 ppp_priv_area->start_trace_addr + END_OFFSET;
2264
2265 /* MAX_SEND_BUFFER_SIZE - 28 (IP header)
2266 - 32 (ppipemon CBLOCK) */
2267 available_buffer_space = MAX_LGTH_UDP_MGNT_PKT -
2268 sizeof(ip_pkt_t)-
2269 sizeof(udp_pkt_t)-
2270 sizeof(wp_mgmt_t)-
2271 sizeof(cblock_t);
2272 }
2273 ppp_udp_pkt->cblock.result = 0;
2274 mbox->cmd.length = 0;
2275 card->TracingEnabled = 1;
2276 break;
2277
2278 /* PPIPE_DISABLE_TRACING */
2279 case PPIPE_DISABLE_TRACING:
2280
2281 if(card->TracingEnabled) {
2282
2283 /* OPERATE_DATALINE_MONITOR */
2284 mbox->cmd.command = 0x33;
2285 mbox->cmd.length = 1;
2286 mbox->data[0] = 0x00;
2287 err = sdla_exec(mbox) ?
2288 mbox->cmd.result : CMD_TIMEOUT;
2289
2290 }
2291
2292 /*set return code*/
2293 ppp_udp_pkt->cblock.result = 0;
2294 mbox->cmd.length = 0;
2295 card->TracingEnabled = 0;
2296 break;
2297
2298 /* PPIPE_GET_TRACE_INFO */
2299 case PPIPE_GET_TRACE_INFO:
2300
2301 if(!card->TracingEnabled) {
2302 /* set return code */
2303 ppp_udp_pkt->cblock.result = 1;
2304 mbox->cmd.length = 0;
2305 }
2306
2307 buffer_length = 0;
2308
2309 /* frames < 62, where 62 is the number of trace
2310 information elements. There is in total 496
2311 bytes of space and each trace information
2312 element is 8 bytes.
2313 */
2314 for ( frames=0; frames<62; frames++) {
2315
2316 trace_pkt_t *trace_pkt = (trace_pkt_t *)
2317 &ppp_udp_pkt->data[buffer_length];
2318
2319 /* Read the whole trace packet */
2320 sdla_peek(&card->hw, ppp_priv_area->curr_trace_addr,
2321 &trace_element, sizeof(trace_element_t));
2322
2323 /* no data on board so exit */
2324 if( trace_element.opp_flag == 0x00 )
2325 break;
2326
2327 data_ptr = trace_element.trace_data_ptr;
2328
2329 /* See if there is actual data on the trace buffer */
2330 if (data_ptr){
2331 data_length = trace_element.trace_length;
2332 }else{
2333 data_length = 0;
2334 ppp_udp_pkt->data[0] |= 0x02;
2335 }
2336
2337 //FIXME: Do we need this check
2338 if ((available_buffer_space - buffer_length)
2339 < (sizeof(trace_element_t)+1)){
2340
2341 /*indicate we have more frames
2342 * on board and exit
2343 */
2344 ppp_udp_pkt->data[0] |= 0x02;
2345 break;
2346 }
2347
2348 trace_pkt->status = trace_element.trace_type;
2349 trace_pkt->time_stamp = trace_element.trace_time_stamp;
2350 trace_pkt->real_length = trace_element.trace_length;
2351
2352 real_len = trace_element.trace_length;
2353
2354 if(data_ptr == 0){
2355 trace_pkt->data_avail = 0x00;
2356 }else{
2357 /* we can take it next time */
2358 if ((available_buffer_space - buffer_length)<
2359 (real_len + sizeof(trace_pkt_t))){
2360
2361 ppp_udp_pkt->data[0] |= 0x02;
2362 break;
2363 }
2364 trace_pkt->data_avail = 0x01;
2365
2366 /* get the data */
2367 sdla_peek(&card->hw, data_ptr,
2368 &trace_pkt->data,
2369 real_len);
2370 }
2371 /* zero the opp flag to
2372 show we got the frame */
2373 buf2[0] = 0x00;
2374 sdla_poke(&card->hw, ppp_priv_area->curr_trace_addr,
2375 &buf2, 1);
2376
2377 /* now move onto the next
2378 frame */
2379 ppp_priv_area->curr_trace_addr += 8;
2380
2381 /* check if we passed the last address */
2382 if ( ppp_priv_area->curr_trace_addr >=
2383 ppp_priv_area->end_trace_addr){
2384
2385 ppp_priv_area->curr_trace_addr =
2386 ppp_priv_area->start_trace_addr;
2387 }
2388
2389 /* update buffer length and make sure its even */
2390
2391 if ( trace_pkt->data_avail == 0x01 ) {
2392 buffer_length += real_len - 1;
2393 }
2394
2395 /* for the header */
2396 buffer_length += 8;
2397
2398 if( buffer_length & 0x0001 )
2399 buffer_length += 1;
2400 }
2401
2402 /* ok now set the total number of frames passed
2403 in the high 5 bits */
2404 ppp_udp_pkt->data[0] |= (frames << 2);
2405
2406 /* set the data length */
2407 mbox->cmd.length = buffer_length;
2408 ppp_udp_pkt->cblock.length = buffer_length;
2409
2410 /* set return code */
2411 ppp_udp_pkt->cblock.result = 0;
2412 break;
2413
2414 /* PPIPE_GET_IBA_DATA */
2415 case PPIPE_GET_IBA_DATA:
2416
2417 mbox->cmd.length = 0x09;
2418
2419 sdla_peek(&card->hw, 0xF003, &ppp_udp_pkt->data,
2420 mbox->cmd.length);
2421
2422 /* set the length of the data */
2423 ppp_udp_pkt->cblock.length = 0x09;
2424
2425 /* set return code */
2426 ppp_udp_pkt->cblock.result = 0x00;
2427
2428 break;
2429
2430 /* PPIPE_KILL_BOARD */
2431 case PPIPE_KILL_BOARD:
2432 break;
2433
2434 /* PPIPE_FT1_READ_STATUS */
2435 case PPIPE_FT1_READ_STATUS:
2436 sdla_peek(&card->hw, 0xF020, &ppp_udp_pkt->data, 2);
2437 ppp_udp_pkt->cblock.length = 2;
2438 ppp_udp_pkt->cblock.result = 0;
2439 mbox->cmd.length = 2;
2440 break;
2441
2442 case PPIPE_FLUSH_DRIVER_STATS:
2443 init_ppp_priv_struct( ppp_priv_area );
2444 init_global_statistics( card );
2445 mbox->cmd.length = 0;
2446 break;
2447
2448 case PPIPE_ROUTER_UP_TIME:
2449
2450 do_gettimeofday( &tv );
2451 ppp_priv_area->router_up_time = tv.tv_sec -
2452 ppp_priv_area->router_start_time;
2453 *(unsigned long *)&ppp_udp_pkt->data = ppp_priv_area->router_up_time;
2454 mbox->cmd.length = 4;
2455 break;
2456
2457 /* FT1 MONITOR STATUS */
2458 case FT1_MONITOR_STATUS_CTRL:
2459
2460 /* Enable FT1 MONITOR STATUS */
2461 if( ppp_udp_pkt->data[0] == 1) {
2462
2463 if( rCount++ != 0 ) {
2464 ppp_udp_pkt->cblock.result = 0;
2465 mbox->cmd.length = 1;
2466 break;
2467 }
2468 }
2469
2470 /* Disable FT1 MONITOR STATUS */
2471 if( ppp_udp_pkt->data[0] == 0) {
2472
2473 if( --rCount != 0) {
2474 ppp_udp_pkt->cblock.result = 0;
2475 mbox->cmd.length = 1;
2476 break;
2477 }
2478 }
2479
2480 /* PPIPE_DRIVER_STATISTICS */
2481 case PPIPE_DRIVER_STAT_IFSEND:
2482 printk(KERN_INFO "Getting IF_SEND Drivers Statistics\n");
2483 memcpy(&ppp_udp_pkt->data, &ppp_priv_area->if_send_stat,
2484 sizeof(if_send_stat_t));
2485
2486
2487 ppp_udp_pkt->cblock.result = 0;
2488 ppp_udp_pkt->cblock.length = sizeof(if_send_stat_t);
2489 mbox->cmd.length = sizeof(if_send_stat_t);
2490 break;
2491
2492 case PPIPE_DRIVER_STAT_INTR:
2493 memcpy(&ppp_udp_pkt->data, &card->statistics,
2494 sizeof(global_stats_t));
2495
2496 memcpy(&ppp_udp_pkt->data+sizeof(global_stats_t),
2497 &ppp_priv_area->rx_intr_stat,
2498 sizeof(rx_intr_stat_t));
2499
2500 ppp_udp_pkt->cblock.result = 0;
2501 ppp_udp_pkt->cblock.length = sizeof(global_stats_t)+
2502 sizeof(rx_intr_stat_t);
2503 mbox->cmd.length = ppp_udp_pkt->cblock.length;
2504 break;
2505
2506 case PPIPE_DRIVER_STAT_GEN:
2507 memcpy( &ppp_udp_pkt->data,
2508 &ppp_priv_area->pipe_mgmt_stat,
2509 sizeof(pipe_mgmt_stat_t));
2510
2511 memcpy(&ppp_udp_pkt->data+sizeof(pipe_mgmt_stat_t),
2512 &card->statistics, sizeof(global_stats_t));
2513
2514 ppp_udp_pkt->cblock.result = 0;
2515 ppp_udp_pkt->cblock.length = sizeof(global_stats_t)+
2516 sizeof(rx_intr_stat_t);
2517 mbox->cmd.length = ppp_udp_pkt->cblock.length;
2518 break;
2519
2520
2521 default:
2522
2523 /* it's a board command */
2524 mbox->cmd.command = ppp_udp_pkt->cblock.command;
2525 mbox->cmd.length = ppp_udp_pkt->cblock.length;
2526
2527 if(mbox->cmd.length) {
2528 memcpy(&mbox->data,(unsigned char *)ppp_udp_pkt->data,
2529 mbox->cmd.length);
2530 }
2531
2532 /* run the command on the board */
2533 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
2534
2535 if (err != CMD_OK) {
2536
2537 ppp_error(card, err, mbox);
2538 ++ppp_priv_area->pipe_mgmt_stat.
2539 UDP_PIPE_mgmt_adptr_cmnd_timeout;
2540 break;
2541 }
2542
2543 ++ppp_priv_area->pipe_mgmt_stat.UDP_PIPE_mgmt_adptr_cmnd_OK;
2544
2545 /* copy the result back to our buffer */
2546 memcpy(&ppp_udp_pkt->cblock,mbox, sizeof(cblock_t));
2547
2548 if(mbox->cmd.length) {
2549 memcpy(&ppp_udp_pkt->data,&mbox->data,mbox->cmd.length);
2550 }
2551
2552 } /* end of switch */
2553 } /* end of else */
2554
2555 /* Fill UDP TTL */
2556 ppp_udp_pkt->ip_pkt.ttl = card->wandev.ttl;
2557 len = reply_udp(ppp_priv_area->udp_pkt_data, mbox->cmd.length);
2558
2559 if (ppp_priv_area->udp_pkt_src == UDP_PKT_FRM_NETWORK) {
2560
2561 ++ppp_priv_area->pipe_mgmt_stat.UDP_PIPE_mgmt_passed_to_adptr;
2562 ppp_send(card,ppp_priv_area->udp_pkt_data,len,ppp_priv_area->protocol);
2563
2564 } else {
2565
2566 /* Pass it up the stack
2567 Allocate socket buffer */
2568 if ((new_skb = dev_alloc_skb(len)) != NULL) {
2569
2570 /* copy data into new_skb */
2571
2572 buf = skb_put(new_skb, len);
2573 memcpy(buf,ppp_priv_area->udp_pkt_data, len);
2574
2575 ++ppp_priv_area->pipe_mgmt_stat.UDP_PIPE_mgmt_passed_to_stack;
2576
2577 /* Decapsulate packet and pass it up the protocol
2578 stack */
2579 new_skb->protocol = htons(ETH_P_IP);
2580 new_skb->dev = dev;
2581 new_skb->mac.raw = new_skb->data;
2582 netif_rx(new_skb);
2583
2584 } else {
2585
2586 ++ppp_priv_area->pipe_mgmt_stat.UDP_PIPE_mgmt_no_socket;
2587 printk(KERN_INFO "no socket buffers available!\n");
2588 }
2589 }
2590
2591 ppp_priv_area->udp_pkt_lgth = 0;
2592
2593 return;
2594 }
2595
2596 /*=============================================================================
2597 * Initial the ppp_private_area structure.
2598 */
2599 static void init_ppp_priv_struct( ppp_private_area_t *ppp_priv_area )
2600 {
2601
2602 memset(&ppp_priv_area->if_send_stat, 0, sizeof(if_send_stat_t));
2603 memset(&ppp_priv_area->rx_intr_stat, 0, sizeof(rx_intr_stat_t));
2604 memset(&ppp_priv_area->pipe_mgmt_stat, 0, sizeof(pipe_mgmt_stat_t));
2605 }
2606
2607 /*============================================================================
2608 * Initialize Global Statistics
2609 */
2610 static void init_global_statistics( sdla_t *card )
2611 {
2612 memset(&card->statistics, 0, sizeof(global_stats_t));
2613 }
2614
2615 /*============================================================================
2616 * Initialize Receive and Transmit Buffers.
2617 */
2618 static void init_ppp_tx_rx_buff( sdla_t *card )
2619 {
2620 ppp508_buf_info_t* info;
2621
2622 if (card->hw.type == SDLA_S514) {
2623
2624 info = (void*)(card->hw.dpmbase + PPP514_BUF_OFFS);
2625
2626 card->u.p.txbuf_base = (void*)(card->hw.dpmbase +
2627 info->txb_ptr);
2628
2629 card->u.p.txbuf_last = (ppp_buf_ctl_t*)card->u.p.txbuf_base +
2630 (info->txb_num - 1);
2631
2632 card->u.p.rxbuf_base = (void*)(card->hw.dpmbase +
2633 info->rxb_ptr);
2634
2635 card->u.p.rxbuf_last = (ppp_buf_ctl_t*)card->u.p.rxbuf_base +
2636 (info->rxb_num - 1);
2637
2638 } else {
2639
2640 info = (void*)(card->hw.dpmbase + PPP508_BUF_OFFS);
2641
2642 card->u.p.txbuf_base = (void*)(card->hw.dpmbase +
2643 (info->txb_ptr - PPP508_MB_VECT));
2644
2645 card->u.p.txbuf_last = (ppp_buf_ctl_t*)card->u.p.txbuf_base +
2646 (info->txb_num - 1);
2647
2648 card->u.p.rxbuf_base = (void*)(card->hw.dpmbase +
2649 (info->rxb_ptr - PPP508_MB_VECT));
2650
2651 card->u.p.rxbuf_last = (ppp_buf_ctl_t*)card->u.p.rxbuf_base +
2652 (info->rxb_num - 1);
2653 }
2654
2655 card->u.p.rx_base = info->rxb_base;
2656 card->u.p.rx_top = info->rxb_end;
2657
2658 card->u.p.txbuf = card->u.p.txbuf_base;
2659 card->rxmb = card->u.p.rxbuf_base;
2660
2661 }
2662
2663 /*=============================================================================
2664 * Read Connection Information (ie for Remote IP address assginment).
2665 * Called when ppp interface connected.
2666 */
2667 static int read_info( sdla_t *card )
2668 {
2669 struct net_device *dev = card->wandev.dev;
2670 ppp_private_area_t *ppp_priv_area = dev->priv;
2671 int err;
2672 struct ifreq if_info;
2673 struct sockaddr_in *if_data1, *if_data2;
2674 mm_segment_t fs;
2675
2676 /* Set Local and remote addresses */
2677 memset(&if_info, 0, sizeof(if_info));
2678 strcpy(if_info.ifr_name, dev->name);
2679
2680 fs = get_fs();
2681 set_fs(get_ds()); /* get user space block */
2682
2683
2684 /* Change the local and remote ip address of the interface.
2685 * This will also add in the destination route.
2686 */
2687 if_data1 = (struct sockaddr_in *)&if_info.ifr_addr;
2688 if_data1->sin_addr.s_addr = ppp_priv_area->ip_local;
2689 if_data1->sin_family = AF_INET;
2690 err = devinet_ioctl( SIOCSIFADDR, &if_info );
2691 if_data2 = (struct sockaddr_in *)&if_info.ifr_dstaddr;
2692 if_data2->sin_addr.s_addr = ppp_priv_area->ip_remote;
2693 if_data2->sin_family = AF_INET;
2694 err = devinet_ioctl( SIOCSIFDSTADDR, &if_info );
2695
2696 set_fs(fs); /* restore old block */
2697
2698
2699 if (err) {
2700 printk (KERN_INFO "%s: Adding of route failed:\n",
2701 card->devname);
2702 printk (KERN_INFO "%s: Local : %s\n",
2703 card->devname,in_ntoa(ppp_priv_area->ip_local));
2704 printk (KERN_INFO "%s: Remote: %s\n",
2705 card->devname,in_ntoa(ppp_priv_area->ip_remote));
2706 }
2707 return err;
2708 }
2709
2710 /*=============================================================================
2711 * Remove Dynamic Route.
2712 * Called when ppp interface disconnected.
2713 */
2714
2715 static int remove_route( sdla_t *card )
2716 {
2717
2718 struct net_device *dev = card->wandev.dev;
2719 long ip_addr;
2720 int err;
2721
2722 mm_segment_t fs;
2723 struct ifreq if_info;
2724 struct sockaddr_in *if_data1;
2725 struct in_device *in_dev = dev->ip_ptr;
2726 struct in_ifaddr *ifa = in_dev->ifa_list;
2727
2728
2729 ip_addr = ifa->ifa_local;
2730
2731 /* Set Local and remote addresses */
2732 memset(&if_info, 0, sizeof(if_info));
2733 strcpy(if_info.ifr_name, dev->name);
2734
2735
2736 fs = get_fs();
2737 set_fs(get_ds()); /* get user space block */
2738
2739
2740 /* Change the local ip address of the interface to 0.
2741 * This will also delete the destination route.
2742 */
2743 if_data1 = (struct sockaddr_in *)&if_info.ifr_addr;
2744 if_data1->sin_addr.s_addr = 0;
2745 if_data1->sin_family = AF_INET;
2746 err = devinet_ioctl( SIOCSIFADDR, &if_info );
2747
2748 set_fs(fs); /* restore old block */
2749
2750
2751 if (err) {
2752 printk (KERN_INFO "%s: Deleting dynamic route failed %d!\n",
2753 card->devname, err);
2754 return err;
2755 }else
2756 printk (KERN_INFO "%s: PPP Deleting dynamic route %s successfuly\n",
2757 card->devname, in_ntoa(ip_addr));
2758
2759
2760 return 0;
2761 }
2762
2763 /*=============================================================================
2764 * Perform the Interrupt Test by running the READ_CODE_VERSION command MAX_INTR
2765 * _TEST_COUNTER times.
2766 */
2767 static int intr_test( sdla_t *card )
2768 {
2769 ppp_mbox_t *mb = card->mbox;
2770 int err,i;
2771
2772 /* The critical flag is unset because during intialization (if_open)
2773 * we want the interrupts to be enabled so that when the wpp_isr is
2774 * called it does not exit due to critical flag set.
2775 */
2776
2777 card->wandev.critical = 0;
2778
2779 err = ppp_set_intr_mode( card, 0x08 );
2780
2781 if (err == CMD_OK) {
2782
2783 for (i = 0; i < MAX_INTR_TEST_COUNTER; i ++) {
2784 /* Run command READ_CODE_VERSION */
2785 memset(&mb->cmd, 0, sizeof(ppp_cmd_t));
2786 mb->cmd.length = 0;
2787 mb->cmd.command = PPP_READ_CODE_VERSION;
2788 err = sdla_exec(mb) ? mb->cmd.result : CMD_TIMEOUT;
2789 if (err != CMD_OK)
2790 ppp_error(card, err, mb);
2791 }
2792 }
2793 else return err;
2794
2795 err = ppp_set_intr_mode( card, 0 );
2796 if (err != CMD_OK)
2797 return err;
2798
2799 card->wandev.critical = 1;
2800 return 0;
2801 }
2802
2803 /*==============================================================================
2804 * Determine what type of UDP call it is. DRVSTATS or PTPIPEAB ?
2805 */
2806 static int udp_pkt_type( struct sk_buff *skb, sdla_t *card )
2807 {
2808 unsigned char *sendpacket;
2809 unsigned char buf2[5];
2810 //FIXME: Use the structure
2811 ppp_udp_pkt_t *ppp_udp_pkt = (ppp_udp_pkt_t *)skb->data;
2812
2813 sendpacket = skb->data;
2814 memcpy(&buf2, &card->wandev.udp_port, 2);
2815
2816 if( ppp_udp_pkt->ip_pkt.ver_inet_hdr_length == 0x45 && /* IP packet */
2817 sendpacket[9] == 0x11 && /* UDP packet */
2818 sendpacket[22] == buf2[1] && /* UDP Port */
2819 sendpacket[23] == buf2[0] &&
2820 sendpacket[36] == 0x01 ) {
2821
2822 if ( sendpacket[28] == 0x50 && /* PTPIPEAB: Signature */
2823 sendpacket[29] == 0x54 &&
2824 sendpacket[30] == 0x50 &&
2825 sendpacket[31] == 0x49 &&
2826 sendpacket[32] == 0x50 &&
2827 sendpacket[33] == 0x45 &&
2828 sendpacket[34] == 0x41 &&
2829 sendpacket[35] == 0x42 ){
2830
2831 return UDP_PTPIPE_TYPE;
2832
2833 } else if(sendpacket[28] == 0x44 && /* DRVSTATS: Signature */
2834 sendpacket[29] == 0x52 &&
2835 sendpacket[30] == 0x56 &&
2836 sendpacket[31] == 0x53 &&
2837 sendpacket[32] == 0x54 &&
2838 sendpacket[33] == 0x41 &&
2839 sendpacket[34] == 0x54 &&
2840 sendpacket[35] == 0x53 ){
2841
2842 return UDP_DRVSTATS_TYPE;
2843
2844 } else
2845 return UDP_INVALID_TYPE;
2846
2847 } else
2848 return UDP_INVALID_TYPE;
2849
2850 }
2851
2852 /*============================================================================
2853 * Check to see if the packet to be transmitted contains a broadcast or
2854 * multicast source IP address.
2855 */
2856
2857 static int chk_bcast_mcast_addr(sdla_t *card, struct net_device* dev,
2858 struct sk_buff *skb)
2859 {
2860 u32 src_ip_addr;
2861 u32 broadcast_ip_addr = 0;
2862 struct in_device *in_dev;
2863 /* read the IP source address from the outgoing packet */
2864 src_ip_addr = *(u32 *)(skb->data + 12);
2865
2866 /* read the IP broadcast address for the device */
2867 in_dev = dev->ip_ptr;
2868 if(in_dev != NULL) {
2869 struct in_ifaddr *ifa= in_dev->ifa_list;
2870 if(ifa != NULL)
2871 broadcast_ip_addr = ifa->ifa_broadcast;
2872 else
2873 return 0;
2874 }
2875
2876 /* check if the IP Source Address is a Broadcast address */
2877 if((dev->flags & IFF_BROADCAST) && (src_ip_addr == broadcast_ip_addr)) {
2878 printk(KERN_INFO "%s: Broadcast Source Address silently discarded\n",
2879 card->devname);
2880 dev_kfree_skb(skb);
2881 ++card->wandev.stats.tx_dropped;
2882 return 1;
2883 }
2884
2885 /* check if the IP Source Address is a Multicast address */
2886 if((ntohl(src_ip_addr) >= 0xE0000001) &&
2887 (ntohl(src_ip_addr) <= 0xFFFFFFFE)) {
2888 printk(KERN_INFO "%s: Multicast Source Address silently discarded\n",
2889 card->devname);
2890 dev_kfree_skb(skb);
2891 ++card->wandev.stats.tx_dropped;
2892 return 1;
2893 }
2894
2895 return 0;
2896 }
2897
2898 void s508_lock (sdla_t *card, unsigned long *smp_flags)
2899 {
2900 #ifdef CONFIG_SMP
2901 spin_lock_irqsave(&card->lock, *smp_flags);
2902 #else
2903 disable_irq(card->hw.irq);
2904 #endif
2905 }
2906
2907 void s508_unlock (sdla_t *card, unsigned long *smp_flags)
2908 {
2909 #ifdef CONFIG_SMP
2910 spin_unlock_irqrestore(&card->lock, *smp_flags);
2911 #else
2912 enable_irq(card->hw.irq);
2913 #endif
2914 }
2915
2916 static int read_connection_info (sdla_t *card)
2917 {
2918 ppp_mbox_t *mb = card->mbox;
2919 struct net_device *dev = card->wandev.dev;
2920 ppp_private_area_t *ppp_priv_area = dev->priv;
2921 ppp508_connect_info_t *ppp508_connect_info;
2922 int err;
2923
2924 memset(&mb->cmd, 0, sizeof(ppp_cmd_t));
2925 mb->cmd.length = 0;
2926 mb->cmd.command = PPP_GET_CONNECTION_INFO;
2927 err = sdla_exec(mb) ? mb->cmd.result : CMD_TIMEOUT;
2928
2929 if (err != CMD_OK) {
2930 ppp_error(card, err, mb);
2931 }
2932 else {
2933 ppp508_connect_info = (ppp508_connect_info_t *)mb->data;
2934
2935 ppp_priv_area->ip_remote = ppp508_connect_info->ip_remote;
2936 ppp_priv_area->ip_local = ppp508_connect_info->ip_local;
2937 }
2938
2939 return err;
2940 }
2941
2942 /****** End *****************************************************************/
2943
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.