📄 airo.c
字号:
/* Get stats out of the card */ readStatsRid(local, &stats_rid, RID_STATS); local->stats.rx_packets = vals[43] + vals[44] + vals[45]; local->stats.tx_packets = vals[39] + vals[40] + vals[41]; local->stats.rx_bytes = vals[92]; local->stats.tx_bytes = vals[91]; local->stats.rx_errors = vals[0] + vals[2] + vals[3] + vals[4]; local->stats.tx_errors = vals[42] + local->stats.tx_fifo_errors; local->stats.multicast = vals[43]; local->stats.collisions = vals[89]; /* detailed rx_errors: */ local->stats.rx_length_errors = vals[3]; local->stats.rx_crc_errors = vals[4]; local->stats.rx_frame_errors = vals[2]; local->stats.rx_fifo_errors = vals[0]; return &local->stats;}static void airo_end_promisc(struct airo_info *ai) { Resp rsp; if ((IN4500(ai, EVSTAT) & EV_CMD) != 0) { completecommand(ai, &rsp); up(&ai->sem); } else { ai->promisc_task.routine = (void (*)(void *))airo_end_promisc; ai->promisc_task.data = (void *)ai; schedule_task(&ai->promisc_task); }}static void airo_set_promisc(struct airo_info *ai) { Cmd cmd; if (down_trylock(&ai->sem) == 0) { memset(&cmd, 0, sizeof(cmd)); cmd.cmd=CMD_SETMODE; cmd.parm0=(ai->flags&IFF_PROMISC) ? PROMISC : NOPROMISC; sendcommand(ai, &cmd); airo_end_promisc(ai); } else { ai->promisc_task.routine = (void (*)(void *))airo_set_promisc; ai->promisc_task.data = (void *)ai; schedule_task(&ai->promisc_task); }}static void airo_set_multicast_list(struct net_device *dev) { struct airo_info *ai = dev->priv; if ((dev->flags ^ ai->flags) & IFF_PROMISC) { ai->flags ^= IFF_PROMISC; airo_set_promisc(ai); } if ((dev->flags&IFF_ALLMULTI)||dev->mc_count>0) { /* Turn on multicast. (Should be already setup...) */ }}static int airo_set_mac_address(struct net_device *dev, void *p){ struct airo_info *ai = dev->priv; struct sockaddr *addr = p; Resp rsp; memcpy (ai->config.macAddr, addr->sa_data, dev->addr_len); ai->need_commit = 1; disable_MAC(ai); writeConfigRid (ai); enable_MAC(ai, &rsp); memcpy (ai->dev->dev_addr, addr->sa_data, dev->addr_len); if (ai->wifidev) memcpy (ai->wifidev->dev_addr, addr->sa_data, dev->addr_len); return 0;}static int airo_change_mtu(struct net_device *dev, int new_mtu){ if ((new_mtu < 68) || (new_mtu > 2400)) return -EINVAL; dev->mtu = new_mtu; return 0;}static int airo_close(struct net_device *dev) { struct airo_info *ai = dev->priv; netif_stop_queue(dev); if (ai->wifidev != dev) {#ifdef POWER_ON_DOWN /* Shut power to the card. The idea is that the user can save * power when he doesn't need the card with "ifconfig down". * That's the method that is most friendly towards the network * stack (i.e. the network stack won't try to broadcast * anything on the interface and routes are gone. Jean II */ ai->flags |= FLAG_RADIO_DOWN; disable_MAC(ai);#endif disable_interrupts( ai ); } return 0;}static void del_airo_dev( struct net_device *dev );void stop_airo_card( struct net_device *dev, int freeres ){ struct airo_info *ai = dev->priv; flush_scheduled_tasks(); if (ai->flash) kfree(ai->flash); if (ai->rssi) kfree(ai->rssi); takedown_proc_entry( dev, ai ); if (ai->registered) { unregister_netdev( dev ); if (ai->wifidev) { unregister_netdev(ai->wifidev); kfree(ai->wifidev); ai->wifidev = 0; } ai->registered = 0; } disable_interrupts(ai); free_irq( dev->irq, dev ); if (auto_wep) del_timer_sync(&ai->timer); if (freeres) { /* PCMCIA frees this stuff, so only for PCI and ISA */ release_region( dev->base_addr, 64 ); } del_airo_dev( dev ); kfree( dev );}EXPORT_SYMBOL(stop_airo_card);static int add_airo_dev( struct net_device *dev );int wll_header_parse(struct sk_buff *skb, unsigned char *haddr){ memcpy(haddr, skb->mac.raw + 10, ETH_ALEN); return ETH_ALEN;}static void wifi_setup(struct net_device *dev, struct net_device *ethdev){ struct airo_info *ai = ethdev->priv; dev->priv = ai; dev->hard_header = 0; dev->rebuild_header = 0; dev->hard_header_cache = 0; dev->header_cache_update= 0; dev->hard_header_parse = wll_header_parse; dev->hard_start_xmit = &airo_start_xmit11; dev->get_stats = &airo_get_stats; dev->set_mac_address = &airo_set_mac_address; dev->do_ioctl = &airo_ioctl;#ifdef WIRELESS_EXT dev->get_wireless_stats = airo_get_wireless_stats;#if WIRELESS_EXT > 12 dev->wireless_handlers = (struct iw_handler_def *)&airo_handler_def;#endif /* WIRELESS_EXT > 12 */#endif /* WIRELESS_EXT */ dev->change_mtu = &airo_change_mtu; dev->open = &airo_open; dev->stop = &airo_close; dev->irq = ethdev->irq; dev->base_addr = ethdev->base_addr; dev->type = ARPHRD_IEEE80211; dev->hard_header_len = ETH_HLEN; dev->mtu = 2312; dev->addr_len = ETH_ALEN; memcpy(dev->dev_addr, ethdev->dev_addr, dev->addr_len); dev->tx_queue_len = 100; memset(dev->broadcast,0xFF, ETH_ALEN); dev->flags = IFF_BROADCAST|IFF_MULTICAST;}static struct net_device *init_wifidev(struct airo_info *ai, struct net_device *ethdev){ int err; struct net_device *dev = (struct net_device*)kmalloc(sizeof *dev,GFP_KERNEL); if (!dev) return 0; memset(dev, 0, sizeof(*dev)); strcpy(dev->name, "wifi%d"); dev->priv = ai; wifi_setup(dev, ethdev); err = register_netdev(dev); if (err<0) { kfree(dev); return 0; } return dev;}struct net_device *init_airo_card( unsigned short irq, int port, int is_pcmcia ){ struct net_device *dev; struct airo_info *ai; int i, rc; /* Create the network device object. */ dev = alloc_etherdev(sizeof(*ai)); if (!dev) { printk(KERN_ERR "airo: Couldn't alloc_etherdev\n"); return NULL; } if (dev_alloc_name(dev, dev->name) < 0) { printk(KERN_ERR "airo: Couldn't get name!\n"); goto err_out_free; } ai = dev->priv; ai->wifidev = 0; ai->registered = 0; ai->dev = dev; ai->aux_lock = SPIN_LOCK_UNLOCKED; sema_init(&ai->sem, 1); ai->need_commit = 0; ai->config.len = 0; rc = add_airo_dev( dev ); if (rc) goto err_out_free; /* The Airo-specific entries in the device structure. */ dev->hard_start_xmit = &airo_start_xmit; dev->get_stats = &airo_get_stats; dev->set_multicast_list = &airo_set_multicast_list; dev->set_mac_address = &airo_set_mac_address; dev->do_ioctl = &airo_ioctl;#ifdef WIRELESS_EXT dev->get_wireless_stats = airo_get_wireless_stats;#if WIRELESS_EXT > 12 dev->wireless_handlers = (struct iw_handler_def *)&airo_handler_def;#endif /* WIRELESS_EXT > 12 */#endif /* WIRELESS_EXT */ dev->change_mtu = &airo_change_mtu; dev->open = &airo_open; dev->stop = &airo_close; dev->irq = irq; dev->base_addr = port; rc = request_irq( dev->irq, airo_interrupt, SA_SHIRQ, dev->name, dev ); if (rc) { printk(KERN_ERR "airo: register interrupt %d failed, rc %d\n", irq, rc ); goto err_out_unlink; } if (!is_pcmcia) { if (!request_region( dev->base_addr, 64, dev->name )) { rc = -EBUSY; goto err_out_irq; } } if (probe) { if ( setup_card( ai, dev->dev_addr ) != SUCCESS ) { printk( KERN_ERR "airo: MAC could not be enabled\n" ); rc = -EIO; goto err_out_res; } } else { ai->bap_read = fast_bap_read; ai->flags |= FLAG_FLASHING; } rc = register_netdev(dev); if (rc) goto err_out_res; ai->wifidev = init_wifidev(ai, dev); ai->registered = 1; printk( KERN_INFO "airo: MAC enabled %s %x:%x:%x:%x:%x:%x\n", dev->name, dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2], dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5] ); /* Allocate the transmit buffers */ if (probe) for( i = 0; i < MAX_FIDS; i++ ) ai->fids[i] = transmit_allocate(ai,2312,i>=MAX_FIDS/2); setup_proc_entry( dev, dev->priv ); /* XXX check for failure */ netif_start_queue(dev); SET_MODULE_OWNER(dev); return dev;err_out_res: if (!is_pcmcia) release_region( dev->base_addr, 64 );err_out_irq: free_irq(dev->irq, dev);err_out_unlink: del_airo_dev(dev);err_out_free: kfree(dev); return NULL;}EXPORT_SYMBOL(init_airo_card);static int waitbusy (struct airo_info *ai) { int delay = 0; while ((IN4500 (ai, COMMAND) & COMMAND_BUSY) & (delay < 10000)) { udelay (10); if (++delay % 20) OUT4500(ai, EVACK, EV_CLEARCOMMANDBUSY); } return delay < 10000;}int reset_airo_card( struct net_device *dev ) { int i; struct airo_info *ai = dev->priv; waitbusy (ai); OUT4500(ai,COMMAND,CMD_SOFTRESET); set_current_state (TASK_UNINTERRUPTIBLE); schedule_timeout (HZ/5); waitbusy (ai); set_current_state (TASK_UNINTERRUPTIBLE); schedule_timeout (HZ/5); if ( setup_card(ai, dev->dev_addr ) != SUCCESS ) { printk( KERN_ERR "airo: MAC could not be enabled\n" ); return -1; } else { printk( KERN_INFO "airo: MAC enabled %s %x:%x:%x:%x:%x:%x\n", dev->name, dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2], dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5] ); /* Allocate the transmit buffers */ for( i = 0; i < MAX_FIDS; i++ ) ai->fids[i] = transmit_allocate(ai,2312,i>=MAX_FIDS/2); } enable_interrupts( ai ); netif_wake_queue(dev); return 0;}EXPORT_SYMBOL(reset_airo_card);#if WIRELESS_EXT > 13static void airo_send_event(struct net_device *dev) { struct airo_info *ai = dev->priv; union iwreq_data wrqu; StatusRid status_rid; if (down_trylock(&ai->sem) == 0) { __set_bit(FLAG_LOCKED, &ai->flags); PC4500_readrid(ai, RID_STATUS, &status_rid, sizeof(status_rid)); clear_bit(FLAG_LOCKED, &ai->flags); up(&ai->sem); wrqu.data.length = 0; wrqu.data.flags = 0; memcpy(wrqu.ap_addr.sa_data, status_rid.bssid[0], ETH_ALEN); wrqu.ap_addr.sa_family = ARPHRD_ETHER; /* Send event to user space */ wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL); } else { ai->event_task.routine = (void (*)(void *))airo_send_event; ai->event_task.data = (void *)dev; schedule_task(&ai->event_task); }}#endifstatic void airo_read_mic(struct airo_info *ai) { MICRid mic_rid; if (down_trylock(&ai->sem) == 0) { __set_bit(FLAG_LOCKED, &ai->flags); PC4500_readrid(ai, RID_MIC, &mic_rid, sizeof(mic_rid)); clear_bit(FLAG_LOCKED, &ai->flags); up(&ai->sem);#ifdef MICSUPPORT micinit (ai, &mic_rid);#endif } else { ai->mic_task.routine = (void (*)(void *))airo_read_mic; ai->mic_task.data = (void *)ai; schedule_task(&ai->mic_task); }}static void airo_interrupt ( int irq, void* dev_id, struct pt_regs *regs) { struct net_device *dev = (struct net_device *)dev_id; u16 status; u16 fid; struct airo_info *apriv = dev->priv; u16 savedInterrupts = 0; if (!netif_device_present(dev)) return; for (;;) { status = IN4500( apriv, EVSTAT ); if ( !(status & STATUS_INTS) || status == 0xffff ) break; if ( status & EV_AWAKE ) { OUT4500( apriv, EVACK, EV_AWAKE ); OUT4500( apriv, EVACK, EV_AWAKE ); } if (!savedInterrupts) { savedInterrupts = IN4500( apriv, EVINTEN ); OUT4500( apriv, EVINTEN, 0 ); } if ( status & EV_MIC ) { OUT4500( apriv, EVACK, EV_MIC ); airo_read_mic( apriv ); } if ( status & EV_LINK ) {#if WIRELESS_EXT > 13 union iwreq_data wrqu;#endif /* WIRELESS_EXT > 13 */ /* The link status has changed, if you want to put a monitor hook in, do it here. (Remember that interrupts are still disabled!) */ u16 newStatus = IN4500(apriv, LINKSTAT); OUT4500( apriv, EVACK, EV_LINK); /* Here is what newStatus means: */#define NOBEACON 0x8000 /* Loss of sync - missed beacons */#define MAXRETRIES 0x8001 /* Loss of sync - max retries */#define MAXARL 0x8002 /* Loss of sync - average retry level exceeded*/#define FORCELOSS 0x8003 /* Loss of sync - host request */#define TSFSYNC 0x8004 /* Loss of sync - TSF synchronization */#define DEAUTH 0x8100 /* Deauthentication (low byte is reason code) */#define DISASS 0x8200 /* Disassociation (low byte is reason code) */#define ASSFAIL 0x8400 /* Association failure (low byte is reason code) */#define AUTHFAIL 0x0300 /* Authentication failure (low byte is reason code) */#define ASSOCIATED 0x0400 /* Assocatied */#define RC_RESERVED 0 /* Reserved return code */#define RC_NOREASON 1 /* Unspecified reason */#define RC_AUTHINV 2 /* Previous authentication invalid */#define RC_DEAUTH 3 /* Deauthenticated because sending station is leaving */#define RC_NOACT 4 /* Disassociated due to inactivity */#define RC_MAXLOAD 5 /* Disassociated because AP is unable to handle all currently associated stations */#define RC_BADCLASS2 6 /* Class 2 frame received from non-Authenticated station */#define RC_BADCLASS3 7 /* Class 3 frame received from non-Associated station */#define RC_STATLEAVE 8 /* Disassociated because sending station is leaving BSS */#define RC_NOAUTH 9 /* Station requesting (Re)Association is not Authenticated with the responding station */ if (newStatus != ASSOCIATED) { if (auto_wep && !timer_pending(&apriv->timer)) { apriv->timer.expires = RUN_AT(HZ*3); add_timer(&apriv->timer); } } else { struct task_struct *task = apriv->task; if (task) wake_up_process (task); apriv->flags|=FLAG_UPDATE_UNI|FLAG_UPDATE_MULTI; }#if WIRELESS_EXT > 13
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -