📄 ib-net.c
字号:
static struct iw_statistics *ib_wireless_stats(struct net_device *netdev){ struct ib_net_modem_t *modem = netdev->priv; return &modem->wstats;}/** * ib_net_tx_timeout - timeout handler. * @netdev: network device state. */static void ib_net_tx_timeout(struct net_device *netdev){ unsigned long state; struct ib_net_modem_t *modem = netdev->priv; spin_lock_irqsave(&ib_lock, state); if (modem->driver->tx_timeout) modem->driver->tx_timeout(modem->pdriver); netdev->trans_start = jiffies; spin_unlock_irqrestore(&ib_lock, state);}/** * ib_net_tx_start - convert ethernet frame to radio frame for transmission. * @skb: ethernet frame. * @netdev: network device state. */static int ib_net_tx_start(struct sk_buff *skb, struct net_device *netdev){ unsigned long state; struct ib_net_modem_t *modem = netdev->priv; struct ib_net_ether_t *ether; struct ib_net_radio_t *radio; int nbuf, nqueue; ether = (struct ib_net_ether_t*) skb->data; radio = (struct ib_net_radio_t*) skb_pull(skb, IB_NET_ETHER_HEAD - IB_NET_RADIO_HEAD); nbuf = skb->len; if (ether->dest[0] & 1) radio->word[0] = (nbuf >> 8) | FLAG_BROADCAST; else radio->word[0] = nbuf >> 8; radio->word[1] = nbuf & 0xff; radio->check = (nbuf & 0xff) ^ 0xff; spin_lock_irqsave(&ib_lock, state); skb_queue_tail(&modem->tx_queue, skb); nqueue = skb_queue_len(&modem->tx_queue); if (IB_NET_QUEUE_HI < nqueue) netif_stop_queue(modem->netdev); if (modem->driver->poll) modem->driver->poll(modem->pdriver); spin_unlock_irqrestore(&ib_lock, state); return 0;}/** * ib_net_open - open network device. * @netdev: network device state. */static int ib_net_open(struct net_device *netdev){ struct ib_net_modem_t *modem = netdev->priv; int err; spin_lock_irq(&ib_lock); if (modem->driver->open) { err = modem->driver->open(modem->pdriver); if (!err) netif_start_queue(netdev); } else err = -ENODEV; spin_unlock_irq(&ib_lock); return err;}/** * ib_net_close - close network device. * @netdev: network device state. */static int ib_net_close(struct net_device *netdev){ struct ib_net_modem_t *modem = netdev->priv; int err; spin_lock_irq(&ib_lock); if (modem->driver->close) { err = modem->driver->close(modem->pdriver); if (!err) { modem->wstats.qual.level = 0; modem->wstats.qual.qual = 0; modem->wstats.qual.noise = 0; modem->wstats.qual.updated = 0x7; netif_stop_queue(netdev); } } else err = -ENODEV; spin_unlock_irq(&ib_lock); return err;}/** * ib_net_change_mtu - change mtu. * @netdev: network device state. * @mtu: new mtu. */static int ib_net_change_mtu(struct net_device *netdev, int mtu){ if (mtu < 0 || ETH_DATA_LEN < mtu) return -EINVAL; netdev->mtu = mtu; return 0;}#if 17 <= WIRELESS_EXT/** * ib_ioctl_getname - return the name of this wireless interface * * The header file suggests (strongly) that this indicate the wireless * protocol (eg "IEEE 802.11"). * * @dev: network device state (ignored). * @info: request info (ignored). * @name: interface name (returned). * @extra: extra flags (ignored). */static int ib_ioctl_getname(struct net_device *dev, struct iw_request_info *info, char *name, char *extra){ strcpy(name, "HC-SDMA (iBurst)"); return 0;}/** * ib_ioctl_getrate - return the current date rate of this wireless interface * * Wireless Extensions make no distinction between up and down rates, * so we report the larger of the two. One way of looking at this is that * we report on whatever is doing the most work. Another way of looking * at it is that we report the most impressive number... * * @dev: network device state. * @info: request info (ignored). * @rrq: request data (returned) * @extra: extra flags (ignored). */static int ib_ioctl_getrate(struct net_device *dev, struct iw_request_info *info, struct iw_param *rrq, char *extra){ struct ib_net_modem_t *modem = dev->priv; rrq->value = (modem->downrate <= modem->uprate ? modem->uprate : modem->downrate); rrq->fixed = 0; rrq->disabled = 0; return 0;}/** * ib_ioctl_getrange - return the range information about other values. * * We leave the majority of the iw_range struct unfilled-in, since the * device does not support/report values for most fields. * * @dev: network device state (ignored). * @info: request info (ignored). * @rrq: request data (returned) * @extra: the iw_range struct (returned). */static int ib_ioctl_getrange(struct net_device *dev, struct iw_request_info *info, struct iw_point *rrq, char *extra){ struct iw_range *range = (struct iw_range*) extra; rrq->length = sizeof(struct iw_range); memset(range, 0, sizeof(struct iw_range)); range->we_version_compiled = WIRELESS_EXT; range->max_qual.qual = 100; range->max_qual.level = 100; range->max_qual.noise = 100; range->num_bitrates = 1; range->throughput = 3000000; return 0;}/** * ib_wireless_handler - structure to export the Wireless Handlers. * * This is an array of iw_handler's (wireless ioctl functions). */static const iw_handler ib_wireless_handler[] ={ [SIOCGIWNAME - SIOCIWFIRST] = (iw_handler) ib_ioctl_getname, [SIOCGIWRANGE - SIOCIWFIRST] = (iw_handler) ib_ioctl_getrange, [SIOCGIWRATE - SIOCIWFIRST] = (iw_handler) ib_ioctl_getrate,};/** * ib_wireless_def - wireless functions. */static struct iw_handler_def ib_wireless_def = { .num_standard = sizeof(ib_wireless_handler) / sizeof(iw_handler), .standard = (iw_handler*) ib_wireless_handler, .get_wireless_stats = ib_wireless_stats,};#endif/** * ib_net_setup - initialize net_device structure. * @netdev: network device state. */static void ib_net_setup(struct net_device *netdev){ ether_setup(netdev); netdev->flags = IFF_BROADCAST | IFF_DYNAMIC | IFF_NOARP; netdev->get_stats = ib_net_stats;#if WIRELESS_EXT < 17 netdev->get_wireless_stats = ib_wireless_stats;#else netdev->wireless_handlers = &ib_wireless_def;#endif netdev->hard_start_xmit = ib_net_tx_start; netdev->open = ib_net_open; netdev->stop = ib_net_close; netdev->trans_start = jiffies; netdev->tx_timeout = ib_net_tx_timeout; netdev->watchdog_timeo = 10 * HZ; netdev->change_mtu = ib_net_change_mtu; SET_MODULE_OWNER(netdev);}/** * ib_net_register - register network device. * @_netdev: return network device state. */int ib_net_register(struct net_device **_netdev){ struct net_device *netdev; struct ib_net_modem_t *modem; int err; netdev = alloc_netdev(sizeof(struct ib_net_modem_t), ifname, ib_net_setup); if (netdev == NULL) return -ENOMEM; modem = netdev->priv; modem->netdev = netdev; modem->pc_status = 0; modem->ut_status = 0; memset(modem->tx_buf, 0, sizeof(modem->tx_buf)); memset(&modem->stats, 0, sizeof(struct net_device_stats)); memset(&modem->wstats, 0, sizeof(struct iw_statistics)); err = register_netdev(netdev); if (err) { DEBUG(1, "ib-net: register_netdev failed\n"); free_netdev(netdev); return err; } skb_queue_head_init(&modem->tx_queue);#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20) INIT_WORK(&modem->work_queue, ib_net_poll, modem);#else INIT_WORK(&modem->work_queue, ib_net_poll);#endif *_netdev = netdev; return 0;}EXPORT_SYMBOL(ib_net_register);EXPORT_SYMBOL(ib_net_deregister);EXPORT_SYMBOL(ib_net_rx_parse);EXPORT_SYMBOL(ib_net_tx_prepare);EXPORT_SYMBOL(ib_lock);MODULE_DESCRIPTION("iBurst compatible driver");MODULE_LICENSE("GPL");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -