📄 sdla_ppp.c
字号:
/******* WAN Device Driver Entry Points *************************************//*============================================================================ * Update device status & statistics. */static int update(struct wan_device *wandev){ sdla_t* card = wandev->private; struct net_device* dev; volatile ppp_private_area_t *ppp_priv_area; ppp_flags_t *flags = card->flags; unsigned long timeout; /* sanity checks */ if ((wandev == NULL) || (wandev->private == NULL)) return -EFAULT; if (wandev->state == WAN_UNCONFIGURED) return -ENODEV; /* Shutdown bug fix. This function can be * called with NULL dev pointer during * shutdown */ if ((dev=card->wandev.dev) == NULL){ return -ENODEV; } if ((ppp_priv_area=dev->priv) == NULL){ return -ENODEV; } ppp_priv_area->update_comms_stats = 2; ppp_priv_area->timer_int_enabled |= TMR_INT_ENABLED_UPDATE; flags->imask |= PPP_INTR_TIMER; /* wait a maximum of 1 second for the statistics to be updated */ timeout = jiffies; for(;;) { if(ppp_priv_area->update_comms_stats == 0){ break; } if (time_after(jiffies, timeout + 1 * HZ)){ ppp_priv_area->update_comms_stats = 0; ppp_priv_area->timer_int_enabled &= ~TMR_INT_ENABLED_UPDATE; return -EAGAIN; } } return 0;}/*============================================================================ * Create new logical channel. * This routine is called by the router when ROUTER_IFNEW IOCTL is being * handled. * o parse media- and hardware-specific configuration * o make sure that a new channel can be created * o allocate resources, if necessary * o prepare network device structure for registaration. * * Return: 0 o.k. * < 0 failure (channel will not be created) */static int new_if(struct wan_device *wandev, struct net_device *dev, wanif_conf_t *conf){ sdla_t *card = wandev->private; ppp_private_area_t *ppp_priv_area; if (wandev->ndev) return -EEXIST; printk(KERN_INFO "%s: Configuring Interface: %s\n", card->devname, conf->name); if ((conf->name[0] == '\0') || (strlen(conf->name) > WAN_IFNAME_SZ)) { printk(KERN_INFO "%s: Invalid interface name!\n", card->devname); return -EINVAL; } /* allocate and initialize private data */ ppp_priv_area = kmalloc(sizeof(ppp_private_area_t), GFP_KERNEL); if( ppp_priv_area == NULL ) return -ENOMEM; memset(ppp_priv_area, 0, sizeof(ppp_private_area_t)); ppp_priv_area->card = card; /* initialize data */ strcpy(card->u.p.if_name, conf->name); /* initialize data in ppp_private_area structure */ init_ppp_priv_struct( ppp_priv_area ); ppp_priv_area->mc = conf->mc; ppp_priv_area->pap = conf->pap; ppp_priv_area->chap = conf->chap; /* Option to bring down the interface when * the link goes down */ if (conf->if_down){ set_bit(DYN_OPT_ON,&ppp_priv_area->interface_down); printk("%s: Dynamic interface configuration enabled\n", card->devname); } /* If no user ids are specified */ if(!strlen(conf->userid) && (ppp_priv_area->pap||ppp_priv_area->chap)){ kfree(ppp_priv_area); return -EINVAL; } /* If no passwords are specified */ if(!strlen(conf->passwd) && (ppp_priv_area->pap||ppp_priv_area->chap)){ kfree(ppp_priv_area); return -EINVAL; } if(strlen(conf->sysname) > 31){ kfree(ppp_priv_area); return -EINVAL; } /* If no system name is specified */ if(!strlen(conf->sysname) && (card->u.p.authenticator)){ kfree(ppp_priv_area); return -EINVAL; } /* copy the data into the ppp private structure */ memcpy(ppp_priv_area->userid, conf->userid, strlen(conf->userid)); memcpy(ppp_priv_area->passwd, conf->passwd, strlen(conf->passwd)); memcpy(ppp_priv_area->sysname, conf->sysname, strlen(conf->sysname)); ppp_priv_area->enable_IPX = conf->enable_IPX; if (conf->network_number){ ppp_priv_area->network_number = conf->network_number; }else{ ppp_priv_area->network_number = 0xDEADBEEF; } /* Tells us that if this interface is a * gateway or not */ if ((ppp_priv_area->gateway = conf->gateway) == WANOPT_YES){ printk(KERN_INFO "%s: Interface %s is set as a gateway.\n", card->devname,card->u.p.if_name); } /* prepare network device data space for registration */ strcpy(dev->name,card->u.p.if_name); dev->init = &if_init; dev->priv = ppp_priv_area; dev->mtu = min_t(unsigned int, dev->mtu, card->wandev.mtu); /* Initialize the polling work routine */ INIT_WORK(&ppp_priv_area->poll_work, (void*)(void*)ppp_poll, dev); /* Initialize the polling delay timer */ init_timer(&ppp_priv_area->poll_delay_timer); ppp_priv_area->poll_delay_timer.data = (unsigned long)dev; ppp_priv_area->poll_delay_timer.function = ppp_poll_delay; /* Since we start with dummy IP addresses we can say * that route exists */ printk(KERN_INFO "\n"); return 0;}/*============================================================================ * Delete logical channel. */static int del_if(struct wan_device *wandev, struct net_device *dev){ return 0;}static void disable_comm (sdla_t *card){ ppp_comm_disable_shutdown(card); return;}/****** WANPIPE-specific entry points ***************************************//*============================================================================ * Execute adapter interface command. *///FIXME: Why do we need this ????static int wpp_exec(struct sdla *card, void *u_cmd, void *u_data){ ppp_mbox_t *mbox = card->mbox; int len; if (copy_from_user((void*)&mbox->cmd, u_cmd, sizeof(ppp_cmd_t))) return -EFAULT; len = mbox->cmd.length; if (len) { if( copy_from_user((void*)&mbox->data, u_data, len)) return -EFAULT; } /* execute command */ if (!sdla_exec(mbox)) return -EIO; /* return result */ if( copy_to_user(u_cmd, (void*)&mbox->cmd, sizeof(ppp_cmd_t))) return -EFAULT; len = mbox->cmd.length; if (len && u_data && copy_to_user(u_data, (void*)&mbox->data, len)) return -EFAULT; return 0;}/****** Network Device Interface ********************************************//*============================================================================ * Initialize Linux network interface. * * This routine is called only once for each interface, during Linux network * interface registration. Returning anything but zero will fail interface * registration. */static int if_init(struct net_device *dev){ ppp_private_area_t *ppp_priv_area = dev->priv; sdla_t *card = ppp_priv_area->card; struct wan_device *wandev = &card->wandev; /* Initialize device driver entry points */ dev->open = &if_open; dev->stop = &if_close; dev->hard_header = &if_header; dev->rebuild_header = &if_rebuild_hdr; dev->hard_start_xmit = &if_send; dev->get_stats = &if_stats; dev->tx_timeout = &if_tx_timeout; dev->watchdog_timeo = TX_TIMEOUT; /* Initialize media-specific parameters */ dev->type = ARPHRD_PPP; /* ARP h/w type */ dev->flags |= IFF_POINTOPOINT; dev->flags |= IFF_NOARP; /* Enable Mulitcasting if specified by user*/ if (ppp_priv_area->mc == WANOPT_YES){ dev->flags |= IFF_MULTICAST; } dev->mtu = wandev->mtu; dev->hard_header_len = PPP_HDR_LEN; /* media header length */ /* Initialize hardware parameters (just for reference) */ dev->irq = wandev->irq; dev->dma = wandev->dma; dev->base_addr = wandev->ioport; dev->mem_start = wandev->maddr; dev->mem_end = wandev->maddr + wandev->msize - 1; /* Set transmit buffer queue length */ dev->tx_queue_len = 100; SET_MODULE_OWNER(dev); return 0;}/*============================================================================ * Open network interface. * o enable communications and interrupts. * o prevent module from unloading by incrementing use count * * Return 0 if O.k. or errno. */static int if_open(struct net_device *dev){ ppp_private_area_t *ppp_priv_area = dev->priv; sdla_t *card = ppp_priv_area->card; struct timeval tv; //unsigned long smp_flags; if (netif_running(dev)) return -EBUSY; wanpipe_open(card); netif_start_queue(dev); do_gettimeofday( &tv ); ppp_priv_area->router_start_time = tv.tv_sec; /* We cannot configure the card here because we don't * have access to the interface IP addresses. * Once the interface initilization is complete, we will be * able to access the IP addresses. Therefore, * configure the ppp link in the poll routine */ set_bit(0,&ppp_priv_area->config_ppp); ppp_priv_area->config_wait_timeout=jiffies; /* Start the PPP configuration after 1sec delay. * This will give the interface initilization time * to finish its configuration */ mod_timer(&ppp_priv_area->poll_delay_timer, jiffies + HZ); return 0;}/*============================================================================ * Close network interface. * o if this is the last open, then disable communications and interrupts. * o reset flags. */static int if_close(struct net_device *dev){ ppp_private_area_t *ppp_priv_area = dev->priv; sdla_t *card = ppp_priv_area->card; netif_stop_queue(dev); wanpipe_close(card); del_timer (&ppp_priv_area->poll_delay_timer); return 0;}/*============================================================================ * Build media header. * * The trick here is to put packet type (Ethertype) into 'protocol' field of * the socket buffer, so that we don't forget it. If packet type is not * supported, set skb->protocol to 0 and discard packet later. * * Return: media header length. */static int if_header(struct sk_buff *skb, struct net_device *dev, unsigned short type, void *daddr, void *saddr, unsigned len){ switch (type) { case ETH_P_IP: case ETH_P_IPX: skb->protocol = htons(type); break; default: skb->protocol = 0; } return PPP_HDR_LEN;}/*============================================================================ * Re-build media header. * * Return: 1 physical address resolved. * 0 physical address not resolved */static int if_rebuild_hdr (struct sk_buff *skb){ struct net_device *dev = skb->dev; ppp_private_area_t *ppp_priv_area = dev->priv; sdla_t *card = ppp_priv_area->card; printk(KERN_INFO "%s: rebuild_header() called for interface %s!\n", card->devname, dev->name); return 1;}/*============================================================================ * Handle transmit timeout event from netif watchdog */static void if_tx_timeout(struct net_device *dev){ ppp_private_area_t* chan = dev->priv; sdla_t *card = chan->card; /* If our device stays busy for at least 5 seconds then we will * kick start the device by making dev->tbusy = 0. We expect * that our device never stays busy more than 5 seconds. So this * is only used as a last resort. */ ++ chan->if_send_stat.if_send_tbusy; ++card->wandev.stats.collisions; printk (KERN_INFO "%s: Transmit timed out on %s\n", card->devname,dev->name); ++chan->if_send_stat.if_send_tbusy_timeout; netif_wake_queue (dev);}/*============================================================================ * Send a packet on a network interface. * o set tbusy flag (marks start of the transmission) to block a timer-based * transmit from overlapping. * o check link state. If link is not up, then drop the packet. * o execute adapter send command. * o free socket buffer * * Return: 0 complete (socket buffer must be freed) * non-0 packet may be re-transmitted (tbusy must be set) * * Notes: * 1. This routine is called either by the protocol stack or by the "net * bottom half" (with interrupts enabled). * 2. Setting tbusy flag will inhibit further transmit requests from the * protocol stack and can be used for flow control with protocol layer. */static int if_send (struct sk_buff *skb, struct net_device *dev){ ppp_private_area_t *ppp_priv_area = dev->priv; sdla_t *card = ppp_priv_area->card; unsigned char *sendpacket; unsigned long smp_flags; ppp_flags_t *flags = card->flags; int udp_type; int err=0; ++ppp_priv_area->if_send_stat.if_send_entry; netif_stop_queue(dev); if (skb == NULL) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -