Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
[linux-drm-fsl-dcu.git] / net / core / wireless.c
index 3168fca312f7c4d188dd9162f8b3dd43942692b3..64017d47b25b8808d8f47977bf36012b44c1d4d1 100644 (file)
  *
  * v8 - 17.02.06 - Jean II
  *     o RtNetlink requests support (SET/GET)
+ *
+ * v8b - 03.08.06 - Herbert Xu
+ *     o Fix Wireless Event locking issues.
+ *
+ * v9 - 14.3.06 - Jean II
+ *     o Change length in ESSID and NICK to strlen() instead of strlen()+1
+ *     o Make standard_ioctl_num and standard_event_num unsigned
+ *     o Remove (struct net_device *)->get_wireless_stats()
  */
 
 /***************************** INCLUDES *****************************/
@@ -234,24 +242,24 @@ static const struct iw_ioctl_description standard_ioctl[] = {
        [SIOCSIWESSID   - SIOCIWFIRST] = {
                .header_type    = IW_HEADER_TYPE_POINT,
                .token_size     = 1,
-               .max_tokens     = IW_ESSID_MAX_SIZE + 1,
+               .max_tokens     = IW_ESSID_MAX_SIZE,
                .flags          = IW_DESCR_FLAG_EVENT,
        },
        [SIOCGIWESSID   - SIOCIWFIRST] = {
                .header_type    = IW_HEADER_TYPE_POINT,
                .token_size     = 1,
-               .max_tokens     = IW_ESSID_MAX_SIZE + 1,
+               .max_tokens     = IW_ESSID_MAX_SIZE,
                .flags          = IW_DESCR_FLAG_DUMP,
        },
        [SIOCSIWNICKN   - SIOCIWFIRST] = {
                .header_type    = IW_HEADER_TYPE_POINT,
                .token_size     = 1,
-               .max_tokens     = IW_ESSID_MAX_SIZE + 1,
+               .max_tokens     = IW_ESSID_MAX_SIZE,
        },
        [SIOCGIWNICKN   - SIOCIWFIRST] = {
                .header_type    = IW_HEADER_TYPE_POINT,
                .token_size     = 1,
-               .max_tokens     = IW_ESSID_MAX_SIZE + 1,
+               .max_tokens     = IW_ESSID_MAX_SIZE,
        },
        [SIOCSIWRATE    - SIOCIWFIRST] = {
                .header_type    = IW_HEADER_TYPE_PARAM,
@@ -338,8 +346,8 @@ static const struct iw_ioctl_description standard_ioctl[] = {
                .max_tokens     = sizeof(struct iw_pmksa),
        },
 };
-static const int standard_ioctl_num = (sizeof(standard_ioctl) /
-                                      sizeof(struct iw_ioctl_description));
+static const unsigned standard_ioctl_num = (sizeof(standard_ioctl) /
+                                           sizeof(struct iw_ioctl_description));
 
 /*
  * Meta-data about all the additional standard Wireless Extension events
@@ -361,7 +369,7 @@ static const struct iw_ioctl_description standard_event[] = {
                .header_type    = IW_HEADER_TYPE_ADDR,
        },
        [IWEVEXPIRED    - IWEVFIRST] = {
-               .header_type    = IW_HEADER_TYPE_ADDR, 
+               .header_type    = IW_HEADER_TYPE_ADDR,
        },
        [IWEVGENIE      - IWEVFIRST] = {
                .header_type    = IW_HEADER_TYPE_POINT,
@@ -369,7 +377,7 @@ static const struct iw_ioctl_description standard_event[] = {
                .max_tokens     = IW_GENERIC_IE_MAX,
        },
        [IWEVMICHAELMICFAILURE  - IWEVFIRST] = {
-               .header_type    = IW_HEADER_TYPE_POINT, 
+               .header_type    = IW_HEADER_TYPE_POINT,
                .token_size     = 1,
                .max_tokens     = sizeof(struct iw_michaelmicfailure),
        },
@@ -389,8 +397,8 @@ static const struct iw_ioctl_description standard_event[] = {
                .max_tokens     = sizeof(struct iw_pmkid_cand),
        },
 };
-static const int standard_event_num = (sizeof(standard_event) /
-                                      sizeof(struct iw_ioctl_description));
+static const unsigned standard_event_num = (sizeof(standard_event) /
+                                           sizeof(struct iw_ioctl_description));
 
 /* Size (in bytes) of the various private data types */
 static const char iw_priv_type_size[] = {
@@ -465,17 +473,6 @@ 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, 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;
 }
@@ -633,11 +630,11 @@ 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
                           ? '.' : ' ',
-                          ((__s32) stats->qual.level) - 
+                          ((__s32) stats->qual.level) -
                           ((stats->qual.updated & IW_QUAL_DBM) ? 0x100 : 0),
                           stats->qual.updated & IW_QUAL_LEVEL_UPDATED
                           ? '.' : ' ',
-                          ((__s32) stats->qual.noise) - 
+                          ((__s32) stats->qual.noise) -
                           ((stats->qual.updated & IW_QUAL_DBM) ? 0x100 : 0),
                           stats->qual.updated & IW_QUAL_NOISE_UPDATED
                           ? '.' : ' ',
@@ -751,11 +748,39 @@ static int ioctl_standard_call(struct net_device *        dev,
                int     extra_size;
                int     user_length = 0;
                int     err;
+               int     essid_compat = 0;
 
                /* Calculate space needed by arguments. Always allocate
                 * for max space. Easier, and won't last long... */
                extra_size = descr->max_tokens * descr->token_size;
 
+               /* Check need for ESSID compatibility for WE < 21 */
+               switch (cmd) {
+               case SIOCSIWESSID:
+               case SIOCGIWESSID:
+               case SIOCSIWNICKN:
+               case SIOCGIWNICKN:
+                       if (iwr->u.data.length == descr->max_tokens + 1)
+                               essid_compat = 1;
+                       else if (IW_IS_SET(cmd) && (iwr->u.data.length != 0)) {
+                               char essid[IW_ESSID_MAX_SIZE + 1];
+
+                               err = copy_from_user(essid, iwr->u.data.pointer,
+                                                    iwr->u.data.length *
+                                                    descr->token_size);
+                               if (err)
+                                       return -EFAULT;
+
+                               if (essid[iwr->u.data.length - 1] == '\0')
+                                       essid_compat = 1;
+                       }
+                       break;
+               default:
+                       break;
+               }
+
+               iwr->u.data.length -= essid_compat;
+
                /* Check what user space is giving us */
                if(IW_IS_SET(cmd)) {
                        /* Check NULL pointer */
@@ -798,7 +823,8 @@ static int ioctl_standard_call(struct net_device *  dev,
 #endif /* WE_IOCTL_DEBUG */
 
                /* Create the kernel buffer */
-               extra = kmalloc(extra_size, GFP_KERNEL);
+               /*    kzalloc ensures NULL-termination for essid_compat */
+               extra = kzalloc(extra_size, GFP_KERNEL);
                if (extra == NULL) {
                        return -ENOMEM;
                }
@@ -822,6 +848,8 @@ static int ioctl_standard_call(struct net_device *  dev,
                /* Call the handler */
                ret = handler(dev, &info, &(iwr->u), extra);
 
+               iwr->u.data.length += essid_compat;
+
                /* If we have something to return to the user */
                if (!ret && IW_IS_GET(cmd)) {
                        /* Check if there is enough buffer up there */
@@ -834,7 +862,7 @@ static int ioctl_standard_call(struct net_device *  dev,
                                           iwr->u.data.length *
                                           descr->token_size);
                        if (err)
-                               ret =  -EFAULT;                            
+                               ret =  -EFAULT;
 #ifdef WE_IOCTL_DEBUG
                        printk(KERN_DEBUG "%s (WE) : Wrote %d bytes\n",
                               dev->name,
@@ -1012,7 +1040,7 @@ static inline int ioctl_private_call(struct net_device *  dev,
                        err = copy_to_user(iwr->u.data.pointer, extra,
                                           extra_size);
                        if (err)
-                               ret =  -EFAULT;                            
+                               ret =  -EFAULT;
 #ifdef WE_IOCTL_DEBUG
                        printk(KERN_DEBUG "%s (WE) : Wrote %d elem\n",
                               dev->name, iwr->u.data.length);
@@ -1052,7 +1080,7 @@ int wireless_process_ioctl(struct ifreq *ifr, unsigned int cmd)
        /* A bunch of special cases, then the generic case...
         * Note that 'cmd' is already filtered in dev_ioctl() with
         * (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST) */
-       switch(cmd) 
+       switch(cmd)
        {
                case SIOCGIWSTATS:
                        /* Get Wireless Stats */
@@ -1843,8 +1871,33 @@ int wireless_rtnetlink_set(struct net_device *   dev,
  */
 
 #ifdef WE_EVENT_RTNETLINK
+/* ---------------------------------------------------------------- */
+/*
+ * Locking...
+ * ----------
+ *
+ * Thanks to Herbert Xu <herbert@gondor.apana.org.au> for fixing
+ * the locking issue in here and implementing this code !
+ *
+ * The issue : wireless_send_event() is often called in interrupt context,
+ * while the Netlink layer can never be called in interrupt context.
+ * The fully formed RtNetlink events are queued, and then a tasklet is run
+ * to feed those to Netlink.
+ * The skb_queue is interrupt safe, and its lock is not held while calling
+ * Netlink, so there is no possibility of dealock.
+ * Jean II
+ */
+
 static struct sk_buff_head wireless_nlevent_queue;
 
+static int __init wireless_nlevent_init(void)
+{
+       skb_queue_head_init(&wireless_nlevent_queue);
+       return 0;
+}
+
+subsys_initcall(wireless_nlevent_init);
+
 static void wireless_nlevent_process(unsigned long data)
 {
        struct sk_buff *skb;
@@ -1921,13 +1974,6 @@ static inline void rtmsg_iwinfo(struct net_device *      dev,
        tasklet_schedule(&wireless_nlevent_tasklet);
 }
 
-static int __init wireless_nlevent_init(void)
-{
-       skb_queue_head_init(&wireless_nlevent_queue);
-       return 0;
-}
-
-subsys_initcall(wireless_nlevent_init);
 #endif /* WE_EVENT_RTNETLINK */
 
 /* ---------------------------------------------------------------- */
@@ -1969,7 +2015,7 @@ void wireless_send_event(struct net_device *      dev,
                 * The best the driver could do is to log an error message.
                 * We will do it ourselves instead...
                 */
-               printk(KERN_ERR "%s (WE) : Invalid/Unknown Wireless Event (0x%04X)\n",
+               printk(KERN_ERR "%s (WE) : Invalid/Unknown Wireless Event (0x%04X)\n",
                       dev->name, cmd);
                return;
        }
@@ -1983,11 +2029,11 @@ void wireless_send_event(struct net_device *    dev,
        if(descr->header_type == IW_HEADER_TYPE_POINT) {
                /* Check if number of token fits within bounds */
                if(wrqu->data.length > descr->max_tokens) {
-                       printk(KERN_ERR "%s (WE) : Wireless Event too big (%d)\n", dev->name, wrqu->data.length);
+                       printk(KERN_ERR "%s (WE) : Wireless Event too big (%d)\n", dev->name, wrqu->data.length);
                        return;
                }
                if(wrqu->data.length < descr->min_tokens) {
-                       printk(KERN_ERR "%s (WE) : Wireless Event too small (%d)\n", dev->name, wrqu->data.length);
+                       printk(KERN_ERR "%s (WE) : Wireless Event too small (%d)\n", dev->name, wrqu->data.length);
                        return;
                }
                /* Calculate extra_len - extra is NULL for restricted events */
@@ -2084,7 +2130,7 @@ int iw_handler_set_spy(struct net_device *        dev,
         * The rtnl_lock() make sure we don't race with the other iw_handlers.
         * This make sure wireless_spy_update() "see" that the spy list
         * is temporarily disabled. */
-       wmb();
+       smp_wmb();
 
        /* Are there are addresses to copy? */
        if(wrqu->data.length > 0) {
@@ -2113,7 +2159,7 @@ int iw_handler_set_spy(struct net_device *        dev,
        }
 
        /* Make sure above is updated before re-enabling */
-       wmb();
+       smp_wmb();
 
        /* Enable addresses */
        spydata->spy_number = wrqu->data.length;