Search code examples
linuxwirelesslinux-kernelc

trying to read iw_statistics but code wont work?


I need to read certain statistics from iw_statistics structure, here's the code:

struct net_device *dev;
struct iw_statistics *wi_stats;
dev = first_net_device(&init_net);

  while (dev)
    {
      if (strncmp(dev->name , "wlan",4)==0 )
      {
         if (dev->wireless_handlers->get_wireless_stats(dev) !=NULL ) // <--- here's where the code crashes.
         {
        wi_stats = dev-wireless_handlers->get_wireless_stats(dev);
        printk(KERN_INFO "wi_stats = dev-wireless_handlers->get_wireless_stats(dev); worked!!! :D\n"); 
         }
       }

    }

I'm working on linux kernel 2.6.35 and I'm writing a kernel module. What am I doing wrong here?


Solution

  • Looks like wireless_handlers struct is Null ... Just because a net device has it's name field filled doesn't mean it's configured.

    This is where wireless_handlers gets set:

    #ifdef CONFIG_WIRELESS_EXT
        /* List of functions to handle Wireless Extensions (instead of ioctl).
         * See <net/iw_handler.h> for details. Jean II */
        const struct iw_handler_def *   wireless_handlers;
        /* Instance data managed by the core of Wireless Extensions. */
        struct iw_public_data * wireless_data;
    #endif
    

    You should check the value called CONFIG_WIRELESS_EXT if it's not set , the wireless_handler struct is not set and thus you''ll be pointing to a Null and your module will get stuck