⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sdla_ppp.c

📁 内核linux2.4.20,可跟rtlinux3.2打补丁 组成实时linux系统,编译内核
💻 C
📖 第 1 页 / 共 5 页
字号:
	/* Turn off the transmit and timer interrupt */	flags->imask &= ~PPP_INTR_TIMER;	printk(KERN_INFO "\n");	return 0;}/******* WAN Device Driver Entry Points *************************************//*============================================================================ * Update device status & statistics. */static int update(wan_device_t *wandev){	sdla_t* card = wandev->private; 	netdevice_t* 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 ((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(wan_device_t *wandev, netdevice_t *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 */#ifdef LINUX_2_4 	strcpy(dev->name,card->u.p.if_name);#else	dev->name = (char *)kmalloc(strlen(card->u.p.if_name) + 2, GFP_KERNEL); 	if(dev->name == NULL)	{		kfree(ppp_priv_area);		return -ENOMEM;	}	sprintf(dev->name, "%s", card->u.p.if_name);#endif		dev->init = &if_init;	dev->priv = ppp_priv_area;	dev->mtu = min_t(unsigned int, dev->mtu, card->wandev.mtu);	/* Initialize the polling task routine */#ifndef LINUX_2_4	ppp_priv_area->poll_task.next = NULL;#endif	ppp_priv_area->poll_task.sync=0;	ppp_priv_area->poll_task.routine = (void*)(void*)ppp_poll;	ppp_priv_area->poll_task.data = 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(wan_device_t *wandev, netdevice_t *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 defined(LINUX_2_1) || defined(LINUX_2_4)	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;#else        if (!u_cmd || verify_area(VERIFY_WRITE, u_cmd, sizeof(ppp_cmd_t)))                return -EFAULT;        memcpy_fromfs((void*)&mbox->cmd, u_cmd, sizeof(ppp_cmd_t));	len = mbox->cmd.length;        if (len) {                if (!u_data || verify_area(VERIFY_READ, u_data, len))                        return -EFAULT;        }        /* execute command */        if (!sdla_exec(mbox))               	return -EIO;        /* return result */        memcpy_tofs(u_cmd, (void*)&mbox->cmd, sizeof(ppp_cmd_t));        len = mbox->cmd.length;        if (len && u_data && !verify_area(VERIFY_WRITE, u_data, len))                memcpy_tofs(u_data, (void*)&mbox->data, len);#endif	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(netdevice_t *dev){	ppp_private_area_t *ppp_priv_area = dev->priv;	sdla_t *card = ppp_priv_area->card;	wan_device_t *wandev = &card->wandev;#ifdef LINUX_2_0	int i;#endif	/* 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;#ifdef LINUX_2_4	dev->tx_timeout		= &if_tx_timeout;	dev->watchdog_timeo	= TX_TIMEOUT;#endif	/* 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;	}#ifdef LINUX_2_0	dev->family		= AF_INET;#endif		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;   	/* Initialize socket buffers */      #if !defined(LINUX_2_1) && !defined(LINUX_2_4)        for (i = 0; i < DEV_NUMBUFFS; ++i)                skb_queue_head_init(&dev->buffs[i]);      #endif	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 (netdevice_t *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 (is_dev_running(dev))		return -EBUSY;	wanpipe_open(card);#ifdef LINUX_2_4	netif_start_queue(dev);#else	dev->interrupt = 0;	dev->tbusy = 0;	dev->start = 1;#endif		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 */	del_timer(&ppp_priv_area->poll_delay_timer);	ppp_priv_area->poll_delay_timer.expires = jiffies+HZ;	add_timer(&ppp_priv_area->poll_delay_timer);	return 0;}/*============================================================================ * Close network interface. * o if this is the last open, then disable communications and interrupts. * o reset flags. */static int if_close(netdevice_t *dev){	ppp_private_area_t *ppp_priv_area = dev->priv;	sdla_t *card = ppp_priv_area->card;	stop_net_queue(dev);#ifndef LINUX_2_4	dev->start=0;#endif	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, netdevice_t *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 */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -