hostap annotations
[powerpc.git] / drivers / net / wireless / hostap / hostap_main.c
index 4743426..20d387f 100644 (file)
@@ -24,6 +24,7 @@
 #include <linux/rtnetlink.h>
 #include <linux/wireless.h>
 #include <linux/etherdevice.h>
+#include <net/net_namespace.h>
 #include <net/iw_handler.h>
 #include <net/ieee80211.h>
 #include <net/ieee80211_crypt.h>
@@ -37,7 +38,6 @@
 MODULE_AUTHOR("Jouni Malinen");
 MODULE_DESCRIPTION("Host AP common routines");
 MODULE_LICENSE("GPL");
-MODULE_VERSION(PRISM2_VERSION);
 
 #define TX_TIMEOUT (2 * HZ)
 
@@ -73,7 +73,7 @@ struct net_device * hostap_add_interface(struct local_info *local,
        dev->mem_start = mdev->mem_start;
        dev->mem_end = mdev->mem_end;
 
-       hostap_setup_dev(dev, local, 0);
+       hostap_setup_dev(dev, local, type);
        dev->destructor = free_netdev;
 
        sprintf(dev->name, "%s%s", prefix, name);
@@ -296,7 +296,7 @@ int hostap_tx_callback_unregister(local_info_t *local, u16 idx)
 int hostap_set_word(struct net_device *dev, int rid, u16 val)
 {
        struct hostap_interface *iface;
-       u16 tmp = cpu_to_le16(val);
+       __le16 tmp = cpu_to_le16(val);
        iface = netdev_priv(dev);
        return iface->local->func->set_rid(dev, rid, &tmp, 2);
 }
@@ -530,6 +530,10 @@ int hostap_set_auth_algs(local_info_t *local)
 void hostap_dump_rx_header(const char *name, const struct hfa384x_rx_frame *rx)
 {
        u16 status, fc;
+       DECLARE_MAC_BUF(mac);
+       DECLARE_MAC_BUF(mac2);
+       DECLARE_MAC_BUF(mac3);
+       DECLARE_MAC_BUF(mac4);
 
        status = __le16_to_cpu(rx->status);
 
@@ -548,13 +552,12 @@ void hostap_dump_rx_header(const char *name, const struct hfa384x_rx_frame *rx)
               fc & IEEE80211_FCTL_TODS ? " [ToDS]" : "",
               fc & IEEE80211_FCTL_FROMDS ? " [FromDS]" : "");
 
-       printk(KERN_DEBUG "   A1=" MACSTR " A2=" MACSTR " A3=" MACSTR " A4="
-              MACSTR "\n",
-              MAC2STR(rx->addr1), MAC2STR(rx->addr2), MAC2STR(rx->addr3),
-              MAC2STR(rx->addr4));
+       printk(KERN_DEBUG "   A1=%s A2=%s A3=%s A4=%s\n",
+              print_mac(mac, rx->addr1), print_mac(mac2, rx->addr2),
+              print_mac(mac3, rx->addr3), print_mac(mac4, rx->addr4));
 
-       printk(KERN_DEBUG "   dst=" MACSTR " src=" MACSTR " len=%d\n",
-              MAC2STR(rx->dst_addr), MAC2STR(rx->src_addr),
+       printk(KERN_DEBUG "   dst=%s src=%s len=%d\n",
+              print_mac(mac, rx->dst_addr), print_mac(mac2, rx->src_addr),
               __be16_to_cpu(rx->len));
 }
 
@@ -562,6 +565,10 @@ void hostap_dump_rx_header(const char *name, const struct hfa384x_rx_frame *rx)
 void hostap_dump_tx_header(const char *name, const struct hfa384x_tx_frame *tx)
 {
        u16 fc;
+       DECLARE_MAC_BUF(mac);
+       DECLARE_MAC_BUF(mac2);
+       DECLARE_MAC_BUF(mac3);
+       DECLARE_MAC_BUF(mac4);
 
        printk(KERN_DEBUG "%s: TX status=0x%04x retry_count=%d tx_rate=%d "
               "tx_control=0x%04x; jiffies=%ld\n",
@@ -577,35 +584,37 @@ void hostap_dump_tx_header(const char *name, const struct hfa384x_tx_frame *tx)
               fc & IEEE80211_FCTL_TODS ? " [ToDS]" : "",
               fc & IEEE80211_FCTL_FROMDS ? " [FromDS]" : "");
 
-       printk(KERN_DEBUG "   A1=" MACSTR " A2=" MACSTR " A3=" MACSTR " A4="
-              MACSTR "\n",
-              MAC2STR(tx->addr1), MAC2STR(tx->addr2), MAC2STR(tx->addr3),
-              MAC2STR(tx->addr4));
+       printk(KERN_DEBUG "   A1=%s A2=%s A3=%s A4=%s\n",
+              print_mac(mac, tx->addr1), print_mac(mac2, tx->addr2),
+              print_mac(mac3, tx->addr3), print_mac(mac4, tx->addr4));
 
-       printk(KERN_DEBUG "   dst=" MACSTR " src=" MACSTR " len=%d\n",
-              MAC2STR(tx->dst_addr), MAC2STR(tx->src_addr),
+       printk(KERN_DEBUG "   dst=%s src=%s len=%d\n",
+              print_mac(mac, tx->dst_addr), print_mac(mac2, tx->src_addr),
               __be16_to_cpu(tx->len));
 }
 
 
-int hostap_80211_header_parse(struct sk_buff *skb, unsigned char *haddr)
+int hostap_80211_header_parse(const struct sk_buff *skb, unsigned char *haddr)
 {
-       memcpy(haddr, skb_mac_header(skb) + 10, ETH_ALEN); /* addr2 */
-       return ETH_ALEN;
-}
-
+       struct hostap_interface *iface = netdev_priv(skb->dev);
+       local_info_t *local = iface->local;
+
+       if (local->monitor_type == PRISM2_MONITOR_PRISM ||
+           local->monitor_type == PRISM2_MONITOR_CAPHDR) {
+               const unsigned char *mac = skb_mac_header(skb);
+
+               if (*(u32 *)mac == LWNG_CAP_DID_BASE) {
+                       memcpy(haddr,
+                              mac + sizeof(struct linux_wlan_ng_prism_hdr) + 10,
+                              ETH_ALEN); /* addr2 */
+               } else { /* (*(u32 *)mac == htonl(LWNG_CAPHDR_VERSION)) */
+                       memcpy(haddr,
+                              mac + sizeof(struct linux_wlan_ng_cap_hdr) + 10,
+                              ETH_ALEN); /* addr2 */
+               }
+       } else
+               memcpy(haddr, skb_mac_header(skb) + 10, ETH_ALEN); /* addr2 */
 
-int hostap_80211_prism_header_parse(struct sk_buff *skb, unsigned char *haddr)
-{
-       const unsigned char *mac = skb_mac_header(skb);
-
-       if (*(u32 *)mac == LWNG_CAP_DID_BASE) {
-               memcpy(haddr, mac + sizeof(struct linux_wlan_ng_prism_hdr) + 10,
-                      ETH_ALEN); /* addr2 */
-       } else { /* (*(u32 *)mac == htonl(LWNG_CAPHDR_VERSION)) */
-               memcpy(haddr, mac + sizeof(struct linux_wlan_ng_cap_hdr) + 10,
-                      ETH_ALEN); /* addr2 */
-       }
        return ETH_ALEN;
 }
 
@@ -837,9 +846,18 @@ static void prism2_tx_timeout(struct net_device *dev)
        local->func->schedule_reset(local);
 }
 
+const struct header_ops hostap_80211_ops = {
+       .create         = eth_header,
+       .rebuild        = eth_rebuild_header,
+       .cache          = eth_header_cache,
+       .cache_update   = eth_header_cache_update,
+
+       .parse          = hostap_80211_header_parse,
+};
+EXPORT_SYMBOL(hostap_80211_ops);
 
 void hostap_setup_dev(struct net_device *dev, local_info_t *local,
-                     int main_dev)
+                     int type)
 {
        struct hostap_interface *iface;
 
@@ -859,15 +877,22 @@ void hostap_setup_dev(struct net_device *dev, local_info_t *local,
        dev->do_ioctl = hostap_ioctl;
        dev->open = prism2_open;
        dev->stop = prism2_close;
-       dev->hard_start_xmit = hostap_data_start_xmit;
        dev->set_mac_address = prism2_set_mac_address;
        dev->set_multicast_list = hostap_set_multicast_list;
        dev->change_mtu = prism2_change_mtu;
        dev->tx_timeout = prism2_tx_timeout;
        dev->watchdog_timeo = TX_TIMEOUT;
 
+       if (type == HOSTAP_INTERFACE_AP) {
+               dev->hard_start_xmit = hostap_mgmt_start_xmit;
+               dev->type = ARPHRD_IEEE80211;
+               dev->header_ops = &hostap_80211_ops;
+       } else {
+               dev->hard_start_xmit = hostap_data_start_xmit;
+       }
+
        dev->mtu = local->mtu;
-       if (!main_dev) {
+       if (type != HOSTAP_INTERFACE_MASTER) {
                /* use main radio device queue */
                dev->tx_queue_len = 0;
        }
@@ -877,7 +902,6 @@ void hostap_setup_dev(struct net_device *dev, local_info_t *local,
        netif_stop_queue(dev);
 }
 
-
 static int hostap_enable_hostapd(local_info_t *local, int rtnl_locked)
 {
        struct net_device *dev = local->dev;
@@ -893,10 +917,6 @@ static int hostap_enable_hostapd(local_info_t *local, int rtnl_locked)
        if (local->apdev == NULL)
                return -ENOMEM;
 
-       local->apdev->hard_start_xmit = hostap_mgmt_start_xmit;
-       local->apdev->type = ARPHRD_IEEE80211;
-       local->apdev->hard_header_parse = hostap_80211_header_parse;
-
        return 0;
 }
 
@@ -1075,15 +1095,15 @@ int prism2_sta_deauth(local_info_t *local, u16 reason)
 {
        union iwreq_data wrqu;
        int ret;
+       __le16 val = cpu_to_le16(reason);
 
        if (local->iw_mode != IW_MODE_INFRA ||
            memcmp(local->bssid, "\x00\x00\x00\x00\x00\x00", ETH_ALEN) == 0 ||
            memcmp(local->bssid, "\x44\x44\x44\x44\x44\x44", ETH_ALEN) == 0)
                return 0;
 
-       reason = cpu_to_le16(reason);
        ret = prism2_sta_send_mgmt(local, local->bssid, IEEE80211_STYPE_DEAUTH,
-                                  (u8 *) &reason, 2);
+                                  (u8 *) &val, 2);
        memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
        wireless_send_event(local->dev, SIOCGIWAP, &wrqu, NULL);
        return ret;
@@ -1094,8 +1114,8 @@ struct proc_dir_entry *hostap_proc;
 
 static int __init hostap_init(void)
 {
-       if (proc_net != NULL) {
-               hostap_proc = proc_mkdir("hostap", proc_net);
+       if (init_net.proc_net != NULL) {
+               hostap_proc = proc_mkdir("hostap", init_net.proc_net);
                if (!hostap_proc)
                        printk(KERN_WARNING "Failed to mkdir "
                               "/proc/net/hostap\n");
@@ -1110,7 +1130,7 @@ static void __exit hostap_exit(void)
 {
        if (hostap_proc != NULL) {
                hostap_proc = NULL;
-               remove_proc_entry("hostap", proc_net);
+               remove_proc_entry("hostap", init_net.proc_net);
        }
 }