linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / net / core / wireless.c
index 750cc5d..2add7ed 100644 (file)
@@ -2,7 +2,7 @@
  * This file implement the Wireless Extensions APIs.
  *
  * Authors :   Jean Tourrilhes - HPL - <jt@hpl.hp.com>
- * Copyright (c) 1997-2004 Jean Tourrilhes, All Rights Reserved.
+ * Copyright (c) 1997-2005 Jean Tourrilhes, All Rights Reserved.
  *
  * (As all part of the Linux kernel, this file is GPL)
  */
  *     o Add wmb() in iw_handler_set_spy() for non-coherent archs/cpus
  * Based on patch from Pavel Roskin <proski@gnu.org> :
  *     o Fix kernel data leak to user space in private handler handling
+ *
+ * v7 - 18.3.05 - Jean II
+ *     o Remove (struct iw_point *)->pointer from events and streams
+ *     o Remove spy_offset from struct iw_handler_def
+ *     o Start deprecating dev->get_wireless_stats, output a warning
+ *     o If IW_QUAL_DBM is set, show dBm values in /proc/net/wireless
+ *     o Don't loose INVALID/DBM flags when clearing UPDATED flags (iwstats)
  */
 
 /***************************** INCLUDES *****************************/
@@ -71,6 +78,7 @@
 #include <linux/seq_file.h>
 #include <linux/init.h>                        /* for __init */
 #include <linux/if_arp.h>              /* ARPHRD_ETHER */
+#include <linux/etherdevice.h>         /* compare_ether_addr */
 
 #include <linux/wireless.h>            /* Pretty obvious */
 #include <net/iw_handler.h>            /* New driver API */
@@ -187,6 +195,12 @@ static const struct iw_ioctl_description standard_ioctl[] = {
                .header_type    = IW_HEADER_TYPE_ADDR,
                .flags          = IW_DESCR_FLAG_DUMP,
        },
+       [SIOCSIWMLME    - SIOCIWFIRST] = {
+               .header_type    = IW_HEADER_TYPE_POINT,
+               .token_size     = 1,
+               .min_tokens     = sizeof(struct iw_mlme),
+               .max_tokens     = sizeof(struct iw_mlme),
+       },
        [SIOCGIWAPLIST  - SIOCIWFIRST] = {
                .header_type    = IW_HEADER_TYPE_POINT,
                .token_size     = sizeof(struct sockaddr) +
@@ -195,7 +209,10 @@ static const struct iw_ioctl_description standard_ioctl[] = {
                .flags          = IW_DESCR_FLAG_NOMAX,
        },
        [SIOCSIWSCAN    - SIOCIWFIRST] = {
-               .header_type    = IW_HEADER_TYPE_PARAM,
+               .header_type    = IW_HEADER_TYPE_POINT,
+               .token_size     = 1,
+               .min_tokens     = 0,
+               .max_tokens     = sizeof(struct iw_scan_req),
        },
        [SIOCGIWSCAN    - SIOCIWFIRST] = {
                .header_type    = IW_HEADER_TYPE_POINT,
@@ -273,6 +290,42 @@ static const struct iw_ioctl_description standard_ioctl[] = {
        [SIOCGIWPOWER   - SIOCIWFIRST] = {
                .header_type    = IW_HEADER_TYPE_PARAM,
        },
+       [SIOCSIWGENIE   - SIOCIWFIRST] = {
+               .header_type    = IW_HEADER_TYPE_POINT,
+               .token_size     = 1,
+               .max_tokens     = IW_GENERIC_IE_MAX,
+       },
+       [SIOCGIWGENIE   - SIOCIWFIRST] = {
+               .header_type    = IW_HEADER_TYPE_POINT,
+               .token_size     = 1,
+               .max_tokens     = IW_GENERIC_IE_MAX,
+       },
+       [SIOCSIWAUTH    - SIOCIWFIRST] = {
+               .header_type    = IW_HEADER_TYPE_PARAM,
+       },
+       [SIOCGIWAUTH    - SIOCIWFIRST] = {
+               .header_type    = IW_HEADER_TYPE_PARAM,
+       },
+       [SIOCSIWENCODEEXT - SIOCIWFIRST] = {
+               .header_type    = IW_HEADER_TYPE_POINT,
+               .token_size     = 1,
+               .min_tokens     = sizeof(struct iw_encode_ext),
+               .max_tokens     = sizeof(struct iw_encode_ext) +
+                                 IW_ENCODING_TOKEN_MAX,
+       },
+       [SIOCGIWENCODEEXT - SIOCIWFIRST] = {
+               .header_type    = IW_HEADER_TYPE_POINT,
+               .token_size     = 1,
+               .min_tokens     = sizeof(struct iw_encode_ext),
+               .max_tokens     = sizeof(struct iw_encode_ext) +
+                                 IW_ENCODING_TOKEN_MAX,
+       },
+       [SIOCSIWPMKSA - SIOCIWFIRST] = {
+               .header_type    = IW_HEADER_TYPE_POINT,
+               .token_size     = 1,
+               .min_tokens     = sizeof(struct iw_pmksa),
+               .max_tokens     = sizeof(struct iw_pmksa),
+       },
 };
 static const int standard_ioctl_num = (sizeof(standard_ioctl) /
                                       sizeof(struct iw_ioctl_description));
@@ -299,6 +352,31 @@ static const struct iw_ioctl_description standard_event[] = {
        [IWEVEXPIRED    - IWEVFIRST] = {
                .header_type    = IW_HEADER_TYPE_ADDR, 
        },
+       [IWEVGENIE      - IWEVFIRST] = {
+               .header_type    = IW_HEADER_TYPE_POINT,
+               .token_size     = 1,
+               .max_tokens     = IW_GENERIC_IE_MAX,
+       },
+       [IWEVMICHAELMICFAILURE  - IWEVFIRST] = {
+               .header_type    = IW_HEADER_TYPE_POINT, 
+               .token_size     = 1,
+               .max_tokens     = sizeof(struct iw_michaelmicfailure),
+       },
+       [IWEVASSOCREQIE - IWEVFIRST] = {
+               .header_type    = IW_HEADER_TYPE_POINT,
+               .token_size     = 1,
+               .max_tokens     = IW_GENERIC_IE_MAX,
+       },
+       [IWEVASSOCRESPIE        - IWEVFIRST] = {
+               .header_type    = IW_HEADER_TYPE_POINT,
+               .token_size     = 1,
+               .max_tokens     = IW_GENERIC_IE_MAX,
+       },
+       [IWEVPMKIDCAND  - IWEVFIRST] = {
+               .header_type    = IW_HEADER_TYPE_POINT,
+               .token_size     = 1,
+               .max_tokens     = sizeof(struct iw_pmkid_cand),
+       },
 };
 static const int standard_event_num = (sizeof(standard_event) /
                                       sizeof(struct iw_ioctl_description));
@@ -376,10 +454,19 @@ static inline struct iw_statistics *get_wireless_stats(struct net_device *dev)
           (dev->wireless_handlers->get_wireless_stats != NULL))
                return dev->wireless_handlers->get_wireless_stats(dev);
 
-       /* Old location, will be phased out in next WE */
-       return (dev->get_wireless_stats ?
-               dev->get_wireless_stats(dev) :
-               (struct iw_statistics *) NULL);
+       /* Old location, field to be removed in next WE */
+       if(dev->get_wireless_stats) {
+               static int printed_message;
+
+               if (!printed_message++)
+                       printk(KERN_DEBUG "%s (WE) : Driver using old /proc/net/wireless support, please fix driver !\n",
+                               dev->name);
+
+               return dev->get_wireless_stats(dev);
+       }
+
+       /* Not found */
+       return (struct iw_statistics *) NULL;
 }
 
 /* ---------------------------------------------------------------- */
@@ -471,16 +558,18 @@ static __inline__ void wireless_seq_printf_stats(struct seq_file *seq,
                           dev->name, stats->status, stats->qual.qual,
                           stats->qual.updated & IW_QUAL_QUAL_UPDATED
                           ? '.' : ' ',
-                          ((__u8) stats->qual.level),
+                          ((__s32) stats->qual.level) - 
+                          ((stats->qual.updated & IW_QUAL_DBM) ? 0x100 : 0),
                           stats->qual.updated & IW_QUAL_LEVEL_UPDATED
                           ? '.' : ' ',
-                          ((__u8) stats->qual.noise),
+                          ((__s32) stats->qual.noise) - 
+                          ((stats->qual.updated & IW_QUAL_DBM) ? 0x100 : 0),
                           stats->qual.updated & IW_QUAL_NOISE_UPDATED
                           ? '.' : ' ',
                           stats->discard.nwid, stats->discard.code,
                           stats->discard.fragment, stats->discard.retries,
                           stats->discard.misc, stats->miss.beacon);
-               stats->qual.updated = 0;
+               stats->qual.updated &= ~IW_QUAL_ALL_UPDATED;
        }
 }
 
@@ -501,10 +590,6 @@ static int wireless_seq_show(struct seq_file *seq, void *v)
        return 0;
 }
 
-extern void *dev_seq_start(struct seq_file *seq, loff_t *pos);
-extern void *dev_seq_next(struct seq_file *seq, void *v, loff_t *pos);
-extern void dev_seq_stop(struct seq_file *seq, void *v);
-
 static struct seq_operations wireless_seq_ops = {
        .start = dev_seq_start,
        .next  = dev_seq_next,
@@ -527,6 +612,7 @@ static struct file_operations wireless_seq_fops = {
 
 int __init wireless_proc_init(void)
 {
+       /* Create /proc/net/wireless entry */
        if (!proc_net_fops_create("wireless", S_IRUGO, &wireless_seq_fops))
                return -ENOMEM;
 
@@ -561,9 +647,9 @@ static inline int dev_iwstats(struct net_device *dev, struct ifreq *ifr)
                                sizeof(struct iw_statistics)))
                        return -EFAULT;
 
-               /* Check if we need to clear the update flag */
+               /* Check if we need to clear the updated flag */
                if(wrq->u.data.flags != 0)
-                       stats->qual.updated = 0;
+                       stats->qual.updated &= ~IW_QUAL_ALL_UPDATED;
                return 0;
        } else
                return -EOPNOTSUPP;
@@ -1032,6 +1118,7 @@ static inline int rtnetlink_fill_iwinfo(struct sk_buff *  skb,
        nlh = NLMSG_PUT(skb, 0, 0, type, sizeof(*r));
        r = NLMSG_DATA(nlh);
        r->ifi_family = AF_UNSPEC;
+       r->__ifi_pad = 0;
        r->ifi_type = dev->type;
        r->ifi_index = dev->ifindex;
        r->ifi_flags = dev->flags;
@@ -1073,8 +1160,8 @@ static inline void rtmsg_iwinfo(struct net_device *       dev,
                kfree_skb(skb);
                return;
        }
-       NETLINK_CB(skb).dst_groups = RTMGRP_LINK;
-       netlink_broadcast(rtnl, skb, 0, RTMGRP_LINK, GFP_ATOMIC);
+       NETLINK_CB(skb).dst_group = RTNLGRP_LINK;
+       netlink_broadcast(rtnl, skb, 0, RTNLGRP_LINK, GFP_ATOMIC);
 }
 #endif /* WE_EVENT_NETLINK */
 
@@ -1094,10 +1181,11 @@ void wireless_send_event(struct net_device *    dev,
        struct iw_event  *event;                /* Mallocated whole event */
        int event_len;                          /* Its size */
        int hdr_len;                            /* Size of the event header */
+       int wrqu_off = 0;                       /* Offset in wrqu */
        /* Don't "optimise" the following variable, it will crash */
        unsigned        cmd_index;              /* *MUST* be unsigned */
 
-       /* Get the description of the IOCTL */
+       /* Get the description of the Event */
        if(cmd <= SIOCIWLAST) {
                cmd_index = cmd - SIOCIWFIRST;
                if(cmd_index < standard_ioctl_num)
@@ -1140,6 +1228,8 @@ void wireless_send_event(struct net_device *      dev,
                /* Calculate extra_len - extra is NULL for restricted events */
                if(extra != NULL)
                        extra_len = wrqu->data.length * descr->token_size;
+               /* Always at an offset in wrqu */
+               wrqu_off = IW_EV_POINT_OFF;
 #ifdef WE_EVENT_DEBUG
                printk(KERN_DEBUG "%s (WE) : Event 0x%04X, tokens %d, extra_len %d\n", dev->name, cmd, wrqu->data.length, extra_len);
 #endif /* WE_EVENT_DEBUG */
@@ -1150,7 +1240,7 @@ void wireless_send_event(struct net_device *      dev,
        event_len = hdr_len + extra_len;
 
 #ifdef WE_EVENT_DEBUG
-       printk(KERN_DEBUG "%s (WE) : Event 0x%04X, hdr_len %d, event_len %d\n", dev->name, cmd, hdr_len, event_len);
+       printk(KERN_DEBUG "%s (WE) : Event 0x%04X, hdr_len %d, wrqu_off %d, event_len %d\n", dev->name, cmd, hdr_len, wrqu_off, event_len);
 #endif /* WE_EVENT_DEBUG */
 
        /* Create temporary buffer to hold the event */
@@ -1161,7 +1251,7 @@ void wireless_send_event(struct net_device *      dev,
        /* Fill event */
        event->len = event_len;
        event->cmd = cmd;
-       memcpy(&event->u, wrqu, hdr_len - IW_EV_LCP_LEN);
+       memcpy(&event->u, ((char *) wrqu) + wrqu_off, hdr_len - IW_EV_LCP_LEN);
        if(extra != NULL)
                memcpy(((char *) event) + hdr_len, extra, extra_len);
 
@@ -1182,7 +1272,7 @@ void wireless_send_event(struct net_device *      dev,
  * Now, the driver can delegate this task to Wireless Extensions.
  * It needs to use those standard spy iw_handler in struct iw_handler_def,
  * push data to us via wireless_spy_update() and include struct iw_spy_data
- * in its private part (and advertise it in iw_handler_def->spy_offset).
+ * in its private part (and export it in net_device->wireless_data->spy_data).
  * One of the main advantage of centralising spy support here is that
  * it becomes much easier to improve and extend it without having to touch
  * the drivers. One example is the addition of the Spy-Threshold events.
@@ -1199,10 +1289,7 @@ static inline struct iw_spy_data * get_spydata(struct net_device *dev)
        /* This is the new way */
        if(dev->wireless_data)
                return(dev->wireless_data->spy_data);
-
-       /* This is the old way. Doesn't work for multi-headed drivers.
-        * It will be removed in the next version of WE. */
-       return (dev->priv + dev->wireless_handlers->spy_offset);
+       return NULL;
 }
 
 /*------------------------------------------------------------------*/
@@ -1217,10 +1304,6 @@ int iw_handler_set_spy(struct net_device *       dev,
        struct iw_spy_data *    spydata = get_spydata(dev);
        struct sockaddr *       address = (struct sockaddr *) extra;
 
-       if(!dev->wireless_data)
-               /* Help user know that driver needs updating */
-               printk(KERN_DEBUG "%s (WE) : Driver using old/buggy spy support, please fix driver !\n",
-                      dev->name);
        /* Make sure driver is not buggy or using the old API */
        if(!spydata)
                return -EOPNOTSUPP;
@@ -1251,7 +1334,7 @@ int iw_handler_set_spy(struct net_device *        dev,
                       sizeof(struct iw_quality) * IW_MAX_SPY);
 
 #ifdef WE_SPY_DEBUG
-               printk(KERN_DEBUG "iw_handler_set_spy() :  offset %ld, spydata %p, num %d\n", dev->wireless_handlers->spy_offset, spydata, wrqu->data.length);
+               printk(KERN_DEBUG "iw_handler_set_spy() :  wireless_data %p, spydata %p, num %d\n", dev->wireless_data, spydata, wrqu->data.length);
                for (i = 0; i < wrqu->data.length; i++)
                        printk(KERN_DEBUG
                               "%02X:%02X:%02X:%02X:%02X:%02X \n",
@@ -1304,7 +1387,7 @@ int iw_handler_get_spy(struct net_device *        dev,
                       sizeof(struct iw_quality) * spydata->spy_number);
        /* Reset updated flags. */
        for(i = 0; i < spydata->spy_number; i++)
-               spydata->spy_stat[i].updated = 0;
+               spydata->spy_stat[i].updated &= ~IW_QUAL_ALL_UPDATED;
        return 0;
 }
 
@@ -1419,12 +1502,12 @@ void wireless_spy_update(struct net_device *    dev,
                return;
 
 #ifdef WE_SPY_DEBUG
-       printk(KERN_DEBUG "wireless_spy_update() :  offset %ld, spydata %p, address %02X:%02X:%02X:%02X:%02X:%02X\n", dev->wireless_handlers->spy_offset, spydata, address[0], address[1], address[2], address[3], address[4], address[5]);
+       printk(KERN_DEBUG "wireless_spy_update() :  wireless_data %p, spydata %p, address %02X:%02X:%02X:%02X:%02X:%02X\n", dev->wireless_data, spydata, address[0], address[1], address[2], address[3], address[4], address[5]);
 #endif /* WE_SPY_DEBUG */
 
        /* Update all records that match */
        for(i = 0; i < spydata->spy_number; i++)
-               if(!memcmp(address, spydata->spy_address[i], ETH_ALEN)) {
+               if(!compare_ether_addr(address, spydata->spy_address[i])) {
                        memcpy(&(spydata->spy_stat[i]), wstats,
                               sizeof(struct iw_quality));
                        match = i;