sdla_ppp.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:104k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

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