45 #include <linux/stddef.h>
46 #include <linux/capability.h>
47 #include <linux/errno.h>
48 #include <linux/kernel.h>
49 #include <linux/module.h>
50 #include <linux/slab.h>
53 #include <linux/string.h>
55 #include <asm/byteorder.h>
56 #include <linux/wanrouter.h>
59 #include <asm/uaccess.h>
62 #define DEV_TO_SLAVE(dev) (*((struct net_device **)netdev_priv(dev)))
73 static int wanrouter_device_setup(
struct wan_device *wandev,
75 static int wanrouter_device_stat(
struct wan_device *wandev,
77 static int wanrouter_device_shutdown(
struct wan_device *wandev);
78 static int wanrouter_device_new_if(
struct wan_device *wandev,
80 static int wanrouter_device_del_if(
struct wan_device *wandev,
88 static int wanrouter_delete_interface(
struct wan_device *wandev,
char *
name);
89 static void lock_adapter_irq(
spinlock_t *
lock,
unsigned long *smp_flags)
91 static void unlock_adapter_irq(
spinlock_t *
lock,
unsigned long *smp_flags)
100 static char wanrouter_fullname[] =
"Sangoma WANPIPE Router";
101 static char wanrouter_copyright[] =
"(c) 1995-2000 Sangoma Technologies Inc.";
110 static unsigned char wanrouter_oui_ether[] = { 0x00, 0x00, 0x00 };
111 static unsigned char wanrouter_oui_802_2[] = { 0x00, 0x80, 0xC2 };
114 static int __init wanrouter_init(
void)
120 wanrouter_copyright);
130 static void __exit wanrouter_cleanup (
void)
176 if (wanrouter_find_device(wandev->
name))
181 wanrouter_modname, wandev->
name);
190 "%s: can't create /proc/net/router/%s entry!\n",
191 wanrouter_modname, wandev->
name);
203 wanrouter_router_devlist = wandev;
227 for (wandev = wanrouter_router_devlist, prev =
NULL;
229 prev = wandev, wandev = wandev->
next)
236 wanrouter_modname, name);
240 wanrouter_device_shutdown(wandev);
243 prev->
next = wandev->next;
245 wanrouter_router_devlist = wandev->
next;
282 skb_copy_to_linear_data_offset(skb, 2, wanrouter_oui_ether,
283 sizeof(wanrouter_oui_ether));
284 *((
unsigned short*)&skb->
data[5]) =
htons(type);
289 "%s: unsupported Ethertype 0x%04X on interface %s!\n",
290 wanrouter_modname, type, dev->
name);
310 int cnt = skb->
data[0] ? 0 : 1;
313 switch (skb->
data[cnt]) {
320 if (
memcmp(&skb->
data[cnt + 1], wanrouter_oui_ether,
321 sizeof(wanrouter_oui_ether))){
323 "%s: unsupported SNAP OUI %02X-%02X-%02X "
324 "on interface %s!\n", wanrouter_modname,
337 "%s: unsupported NLPID 0x%02X on interface %s!\n",
338 wanrouter_modname, skb->
data[cnt], dev->
name);
344 skb_reset_mac_header(skb);
381 err = wanrouter_device_setup(wandev, data);
385 err = wanrouter_device_shutdown(wandev);
389 err = wanrouter_device_stat(wandev, data);
393 err = wanrouter_device_new_if(wandev, data);
397 err = wanrouter_device_del_if(wandev, data);
407 err = wandev->
ioctl(wandev, cmd, arg);
426 static int wanrouter_device_setup(
struct wan_device *wandev,
447 printk(
KERN_INFO "%s: Failed to copy user config data to kernel space!\n",
463 "%s: ERROR, Invalid firmware data size %i !\n",
472 "%s: ERROR, Failed allocate kernel memory !\n",
479 err = wandev->
setup(wandev, conf);
482 "%s: ERROR, Failed to copy from user data !\n",
489 "%s: ERROR, No firmware found ! Firmware size = %i !\n",
503 static int wanrouter_device_shutdown(
struct wan_device *wandev)
513 for (dev = wandev->
dev; dev;) {
514 err = wanrouter_delete_interface(wandev, dev->
name);
537 static int wanrouter_device_stat(
struct wan_device *wandev,
542 memset(&stat, 0,
sizeof(stat));
568 static int wanrouter_device_new_if(
struct wan_device *wandev,
591 printk(
KERN_INFO "%s: Wanpipe Mulit-Port PPP support has not been compiled in!\n",
596 err = wandev->
new_if(wandev, dev, cnf);
607 wanrouter_modname, dev->
name);
613 unsigned long smp_flags=0;
615 lock_adapter_irq(&wandev->
lock, &smp_flags);
620 for (slave=wandev->
dev;
627 unlock_adapter_irq(&wandev->
lock, &smp_flags);
632 wandev->
del_if(wandev, dev);
648 static int wanrouter_device_del_if(
struct wan_device *wandev,
char __user *u_name)
656 memset(name, 0,
sizeof(name));
661 err = wanrouter_delete_interface(wandev, name);
689 static struct wan_device *wanrouter_find_device(
char *name)
693 for (wandev = wanrouter_router_devlist;
695 wandev = wandev->
next);
716 static int wanrouter_delete_interface(
struct wan_device *wandev,
char *name)
719 unsigned long smp_flags=0;
721 lock_adapter_irq(&wandev->
lock, &smp_flags);
729 unlock_adapter_irq(&wandev->
lock, &smp_flags);
734 if (netif_running(dev))
738 wandev->
del_if(wandev, dev);
740 lock_adapter_irq(&wandev->
lock, &smp_flags);
742 struct net_device **prev_slave = netdev_priv(prev);
745 *prev_slave = *slave;
748 wandev->
dev = *slave;
751 unlock_adapter_irq(&wandev->
lock, &smp_flags);
762 static void lock_adapter_irq(
spinlock_t *lock,
unsigned long *smp_flags)
769 static void unlock_adapter_irq(
spinlock_t *lock,
unsigned long *smp_flags)
772 spin_unlock_irqrestore(lock, *smp_flags);