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

📄 p80211netdev.c

📁 对于无线网卡采用prism芯片的linux的开源驱动.
💻 C
📖 第 1 页 / 共 3 页
字号:
	/* Check to see that a valid mode is set */	switch( wlandev->macmode ) {	case WLAN_MACMODE_IBSS_STA: 	case WLAN_MACMODE_ESS_STA:	case WLAN_MACMODE_ESS_AP:		break;	default:		/* Mode isn't set yet, just drop the frame 		 * and return success .		 * TODO: we need a saner way to handle this 		 */		if(skb->protocol != ETH_P_80211_RAW) {			p80211netdev_start_queue(wlandev);			WLAN_LOG_NOTICE(				"Tx attempt prior to association, frame dropped.\n");			wlandev->linux_stats.tx_dropped++;			result = 0;			goto failed;		}		break;	}			/* Check for raw transmits */	if(skb->protocol == ETH_P_80211_RAW) {		if (!capable(CAP_NET_ADMIN)) {			result = 1;			goto failed;		}		/* move the header over */		memcpy(&p80211_hdr, skb->data, sizeof(p80211_hdr_t));		skb_pull(skb, sizeof(p80211_hdr_t));	} else {		if ( skb_ether_to_p80211(wlandev, wlandev->ethconv, skb, &p80211_hdr, &p80211_wep) != 0 ) {			/* convert failed */			WLAN_LOG_DEBUG(1, "ether_to_80211(%d) failed.\n", 					wlandev->ethconv);			result = 1;			goto failed;		}	}	if ( wlandev->txframe == NULL ) {		result = 1;		goto failed;	}	netdev->trans_start = jiffies;	wlandev->linux_stats.tx_packets++;	/* count only the packet payload */	wlandev->linux_stats.tx_bytes += skb->len;		txresult = wlandev->txframe(wlandev, skb, &p80211_hdr, &p80211_wep);	if ( txresult == 0) {		/* success and more buf */		/* avail, re: hw_txdata */		p80211netdev_wake_queue(wlandev);		result = 0;	} else if ( txresult == 1 ) { 		/* success, no more avail */		WLAN_LOG_DEBUG(3, "txframe success, no more bufs\n");		/* netdev->tbusy = 1;  don't set here, irqhdlr */		/*   may have already cleared it */		result = 0;	} else if ( txresult == 2 ) { 		/* alloc failure, drop frame */		WLAN_LOG_DEBUG(3, "txframe returned alloc_fail\n");		result = 1;	} else { 		/* buffer full or queue busy, drop frame. */		WLAN_LOG_DEBUG(3, "txframe returned full or busy\n");		result = 1;	} failed:	/* Free up the WEP buffer if it's not the same as the skb */	if ((p80211_wep.data) && (p80211_wep.data != skb->data))		kfree(p80211_wep.data);	/* we always free the skb here, never in a lower level. */	if (!result)		dev_kfree_skb(skb);	DBFEXIT;	return result;}/*----------------------------------------------------------------* p80211knetdev_set_multicast_list** Called from higher lavers whenever there's a need to set/clear* promiscuous mode or rewrite the multicast list.** Arguments:*	none** Returns: *	nothing----------------------------------------------------------------*/void p80211knetdev_set_multicast_list(netdevice_t *dev){	wlandevice_t	*wlandev = (wlandevice_t*)dev->priv;	DBFENTER;	/* TODO:  real multicast support as well */  	if (wlandev->set_multicast_list)		wlandev->set_multicast_list(wlandev, dev);		DBFEXIT;}#ifdef SIOCETHTOOLstatic int p80211netdev_ethtool(wlandevice_t *wlandev, void __user *useraddr){	UINT32 ethcmd;	struct ethtool_drvinfo info;	struct ethtool_value edata;	memset(&info, 0, sizeof(info));	memset(&edata, 0, sizeof(edata));	if (copy_from_user(&ethcmd, useraddr, sizeof(ethcmd)))		return -EFAULT;	switch (ethcmd) {	case ETHTOOL_GDRVINFO:		info.cmd = ethcmd;		snprintf(info.driver, sizeof(info.driver), "p80211_%s", 			 wlandev->nsdname);		snprintf(info.version, sizeof(info.version), "%s", 			 WLAN_RELEASE);		// info.fw_version		// info.bus_info		if (copy_to_user(useraddr, &info, sizeof(info)))			return -EFAULT;		return 0;#ifdef ETHTOOL_GLINK	case ETHTOOL_GLINK:		edata.cmd = ethcmd;		if (wlandev->linkstatus && 		    (wlandev->macmode != WLAN_MACMODE_NONE)) {			edata.data = 1;		} else {			edata.data = 0;		}		if (copy_to_user(useraddr, &edata, sizeof(edata)))                        return -EFAULT;		return 0;	}#endif	return -EOPNOTSUPP;}#endif/*----------------------------------------------------------------* p80211knetdev_do_ioctl** Handle an ioctl call on one of our devices.  Everything Linux* ioctl specific is done here.  Then we pass the contents of the* ifr->data to the request message handler.** Arguments:*	dev	Linux kernel netdevice*	ifr	Our private ioctl request structure, typed for the*		generic struct ifreq so we can use ptr to func*		w/o cast.** Returns: *	zero on success, a negative errno on failure.  Possible values:*		-ENETDOWN Device isn't up.*		-EBUSY	cmd already in progress*		-ETIME	p80211 cmd timed out (MSD may have its own timers)*		-EFAULT memory fault copying msg from user buffer*		-ENOMEM unable to allocate kernel msg buffer*		-ENOSYS	bad magic, it the cmd really for us?*		-EINTR	sleeping on cmd, awakened by signal, cmd cancelled.** Call Context:*	Process thread (ioctl caller).  TODO: SMP support may require*	locks.----------------------------------------------------------------*/int p80211knetdev_do_ioctl(netdevice_t *dev, struct ifreq *ifr, int cmd){	int			result = 0;	p80211ioctl_req_t	*req = (p80211ioctl_req_t*)ifr;	wlandevice_t		*wlandev = (wlandevice_t*)dev->priv;	UINT8			*msgbuf;	DBFENTER;	WLAN_LOG_DEBUG(2, "rx'd ioctl, cmd=%d, len=%d\n", cmd, req->len);#if WIRELESS_EXT < 13	/* Is this a wireless extensions ioctl? */	if ((cmd >= SIOCIWFIRST) && (cmd <= SIOCIWLAST)) {		if ((result = p80211wext_support_ioctl(dev, ifr, cmd)) 		    != (-EOPNOTSUPP)) {			goto bail;		}	}#endif#ifdef SIOCETHTOOL	if (cmd == SIOCETHTOOL) {		result = p80211netdev_ethtool(wlandev, (void __user *) ifr->ifr_data);		goto bail;	}#endif	/* Test the magic, assume ifr is good if it's there */	if ( req->magic != P80211_IOCTL_MAGIC ) {		result = -ENOSYS;		goto bail;	}	if ( cmd == P80211_IFTEST ) {		result = 0;		goto bail;	} else if ( cmd != P80211_IFREQ ) {		result = -ENOSYS;		goto bail;	}	/* Allocate a buf of size req->len */	if ((msgbuf = kmalloc( req->len, GFP_KERNEL))) {		if ( copy_from_user( msgbuf, (void __user *) req->data, req->len) ) {			result = -EFAULT;		} else {			result = p80211req_dorequest( wlandev, msgbuf);		}		if ( result == 0 ) {			if ( copy_to_user( (void __user *) req->data, msgbuf, req->len)) {				result = -EFAULT;			}		}		kfree(msgbuf);	} else {		result = -ENOMEM;	}bail:	DBFEXIT;	return result; /* If allocate,copyfrom or copyto fails, return errno */}/*----------------------------------------------------------------* p80211knetdev_set_mac_address** Handles the ioctl for changing the MACAddress of a netdevice* * references: linux/netdevice.h and drivers/net/net_init.c** NOTE: [MSM] We only prevent address changes when the netdev is* up.  We don't control anything based on dot11 state.  If the * address is changed on a STA that's currently associated, you* will probably lose the ability to send and receive data frames.* Just be aware.  Therefore, this should usually only be done* prior to scan/join/auth/assoc.** Arguments:*	dev	netdevice struct*	addr	the new MACAddress (a struct)** Returns:*	zero on success, a negative errno on failure.  Possible values:*		-EBUSY	device is bussy (cmd not possible)*		-and errors returned by: p80211req_dorequest(..)** by: Collin R. Mulliner <collin@mulliner.org>----------------------------------------------------------------*/int p80211knetdev_set_mac_address(netdevice_t *dev, void *addr){	struct sockaddr			*new_addr = addr;	p80211msg_dot11req_mibset_t	dot11req;	p80211item_unk392_t		*mibattr;	p80211item_pstr6_t		*macaddr;	p80211item_uint32_t		*resultcode;	int result = 0;		DBFENTER;	/* If we're running, we don't allow MAC address changes */#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,38) )	if ( dev->start) {		return -EBUSY;	}#else	if (netif_running(dev)) {		return -EBUSY;	}#endif	/* Set up some convenience pointers. */	mibattr = &dot11req.mibattribute;	macaddr = (p80211item_pstr6_t*)&mibattr->data;	resultcode = &dot11req.resultcode;	/* Set up a dot11req_mibset */	memset(&dot11req, 0, sizeof(p80211msg_dot11req_mibset_t));	dot11req.msgcode = DIDmsg_dot11req_mibset;	dot11req.msglen = sizeof(p80211msg_dot11req_mibset_t);	memcpy(dot11req.devname, 		((wlandevice_t*)(dev->priv))->name, 		WLAN_DEVNAMELEN_MAX - 1);	/* Set up the mibattribute argument */	mibattr->did = DIDmsg_dot11req_mibset_mibattribute;	mibattr->status = P80211ENUM_msgitem_status_data_ok;	mibattr->len = sizeof(mibattr->data);		macaddr->did = DIDmib_dot11mac_dot11OperationTable_dot11MACAddress;	macaddr->status = P80211ENUM_msgitem_status_data_ok;	macaddr->len = sizeof(macaddr->data);	macaddr->data.len = WLAN_ADDR_LEN;	memcpy(&macaddr->data.data, new_addr->sa_data, WLAN_ADDR_LEN);	/* Set up the resultcode argument */	resultcode->did = DIDmsg_dot11req_mibset_resultcode;	resultcode->status = P80211ENUM_msgitem_status_no_value;	resultcode->len = sizeof(resultcode->data);	resultcode->data = 0;		/* now fire the request */	result = p80211req_dorequest(dev->priv, (UINT8*)&dot11req);	/* If the request wasn't successful, report an error and don't	 * change the netdev address	 */	if ( result != 0 || resultcode->data != P80211ENUM_resultcode_success) {		WLAN_LOG_ERROR(		"Low-level driver failed dot11req_mibset(dot11MACAddress).\n");		result = -EADDRNOTAVAIL;	} else {		/* everything's ok, change the addr in netdev */		memcpy(dev->dev_addr, new_addr->sa_data, dev->addr_len);	}	DBFEXIT;	return result;}int wlan_change_mtu(netdevice_t *dev, int new_mtu){	DBFENTER;	// 2312 is max 802.11 payload, 20 is overhead, (ether + llc +snap)	// and another 8 for wep.        if ( (new_mtu < 68) || (new_mtu > (2312 - 20 - 8)))                return -EINVAL;        dev->mtu = new_mtu;	DBFEXIT;        return 0;}/*----------------------------------------------------------------* wlan_setup** Roughly matches the functionality of ether_setup.  Here* we set up any members of the wlandevice structure that are common* to all devices.  Additionally, we allocate a linux 'struct device'* and perform the same setup as ether_setup.** Note: It's important that the caller have setup the wlandev->name*	ptr prior to calling this function.** Arguments:*	wlandev		ptr to the wlandev structure for the*			interface.* Returns: *	zero on success, non-zero otherwise.* Call Context:*	Should be process thread.  We'll assume it might be*	interrupt though.  When we add support for statically*	compiled drivers, this function will be called in the *	context of the kernel startup code.----------------------------------------------------------------*/int wlan_setup(wlandevice_t *wlandev){	int		result = 0;	netdevice_t	*dev;	DBFENTER;	/* Set up the wlandev */	wlandev->state = WLAN_DEVICE_CLOSED;	wlandev->ethconv = WLAN_ETHCONV_8021h;	wlandev->macmode = WLAN_MACMODE_NONE;		/* Set up the rx queue */	skb_queue_head_init(&wlandev->nsd_rxq);	tasklet_init(&wlandev->rx_bh, 		     p80211netdev_rx_bh, 		     (unsigned long)wlandev);	/* Allocate and initialize the struct device */	dev = kmalloc(sizeof(netdevice_t), GFP_ATOMIC);	if ( dev == NULL ) {		WLAN_LOG_ERROR("Failed to alloc netdev.\n");		result = 1;	} else {		memset( dev, 0, sizeof(netdevice_t));		ether_setup(dev);		wlandev->netdev = dev;		dev->priv = wlandev;		dev->hard_start_xmit =	p80211knetdev_hard_start_xmit;		dev->get_stats =	p80211knetdev_get_stats;#ifdef HAVE_PRIVATE_IOCTL		dev->do_ioctl = 	p80211knetdev_do_ioctl;#endif#ifdef HAVE_MULTICAST		dev->set_multicast_list = p80211knetdev_set_multicast_list;#endif		dev->init =		p80211knetdev_init;		dev->open =		p80211knetdev_open;		dev->stop =		p80211knetdev_stop;#ifdef CONFIG_NET_WIRELESS#if ((WIRELESS_EXT < 17) && (WIRELESS_EXT < 21))		dev->get_wireless_stats = p80211wext_get_wireless_stats;#endif#if WIRELESS_EXT > 12		dev->wireless_handlers = &p80211wext_handler_def;#endif#endif			#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,38) )		dev->tbusy = 1;		dev->start = 0;#else		netif_stop_queue(dev);#endif#ifdef HAVE_CHANGE_MTU				dev->change_mtu = wlan_change_mtu;#endif#ifdef HAVE_SET_MAC_ADDR		dev->set_mac_address =	p80211knetdev_set_mac_address;#endif#ifdef HAVE_TX_TIMEOUT		dev->tx_timeout      =  &p80211knetdev_tx_timeout;		dev->watchdog_timeo  =  (wlan_watchdog * HZ) / 1000;#endif				netif_carrier_off(dev);	}	DBFEXIT;	return result;}/*----------------------------------------------------------------* wlan_unsetup** This function is paired with the wlan_setup routine.  It should* be called after unregister_wlandev.  Basically, all it does is* free the 'struct device' that's associated with the wlandev.* We do it here because the 'struct device' isn't allocated * explicitly in the driver code, it's done in wlan_setup.  To* do the free in the driver might seem like 'magic'.** Arguments:*	wlandev		ptr to the wlandev structure for the*			interface.* Returns: *	zero on success, non-zero otherwise.* Call Context:*	Should be process thread.  We'll assume it might be*	interrupt though.  When we add support for statically*	compiled drivers, this function will be called in the *	context of the kernel startup code.----------------------------------------------------------------*/int wlan_unsetup(wlandevice_t *wlandev){	int		result = 0;	DBFENTER;	tasklet_kill(&wlandev->rx_bh);	if (wlandev->netdev == NULL ) {		WLAN_LOG_ERROR("called without wlandev->netdev set.\n");		result = 1;	} else {		free_netdev(wlandev->netdev);		wlandev->netdev = NULL;	}	DBFEXIT;	return 0;

⌨️ 快捷键说明

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