New wireless driver API part 2
Subsystems (2)
PATCH 1/1 New wireless driver API part 2
Hi Linus,
This is the second part of my new driver API for Wireless
Extensions, and it is ready to go in your kernel ;-).
Quick summary : this patch build on the first part to offer
two important new features :
o Wireless Events
o Wireless Cell Scanning
Wireless Events are events generated by device, driver or the
wireless subsystem. It allows for example a device to notify user space when it register to a new cell (roaming) or loose contact with the current Access Points. Currently, the other defined events include some configuration changes and packet drop due to excessive retries, more may come in the future. All those events are useful for MobileIP, V-Handoff and Ad-Hoc routing.
Wireless Cell Scanning is a generic API to allow device/drive
to report Wireless Cells discovered (including ESSID, frequency and QoS). This is similar to what is available in WindowsXP (except that it's compliant to Wireless Extensions).
This patch has been submitted for review on this list a couple
of time in January, has been on my web page since and used intensively by other people. It was rediffed to 2.5.6. Driver patches have been submitted to maintainers.
Thanks... Jean
-----------------------------------------------------------
include/linux/rtnetlink.h renamed from include/linux-w13/rtnetlink.h +4 -2
@@ -440,12 +440,14 @@ enum#define IFLA_COST IFLA_COST IFLA_PRIORITY,#define IFLA_PRIORITY IFLA_PRIORITY - IFLA_MASTER + IFLA_MASTER,#define IFLA_MASTER IFLA_MASTER + IFLA_WIRELESS, /* Wireless Extension event - see wireless.h */ +#define IFLA_WIRELESS IFLA_WIRELESS }; -#define IFLA_MAX IFLA_MASTER +#define IFLA_MAX IFLA_WIRELESS#define IFLA_RTA (r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifinfomsg))))#define IFLA_PAYLOAD (n) NLMSG_PAYLOAD(n,sizeof(struct ifinfomsg))
include/linux/wireless.h renamed from include/linux-w13/wireless.h +74 -4
142 lines not on this page · raw message
include/net/iw_handler.h renamed from include/net-w13/iw_handler.h +100 -25
161 lines not on this page · raw message
net/netsyms.c renamed from net/netsyms-w13.c +7 -0
@@ -588,4 +588,11 @@ EXPORT_SYMBOL(register_gifconf);EXPORT_SYMBOL (net_call_rx_atomic);EXPORT_SYMBOL (softnet_data); +#if defined(CONFIG_NET_RADIO ) || defined(CONFIG_NET_PCMCIA_RADIO ) +/* Don't include the whole header mess for a single function */ +union iwreq_data ; +extern void wireless_send_event (struct net_device *dev,unsigned int cmd,union iwreq_data *wrqu,char *extra); +EXPORT_SYMBOL (wireless_send_event); +#endif /* CONFIG_NET_RADIO || CONFIG_NET_PCMCIA_RADIO */ +#endif /* CONFIG_NET */
net/core/wireless.c renamed from net/core-w13/wireless.c +275 -24
433 lines not on this page · raw message
Quoted 97 lines · Jean Tourrilhes
net/core/wireless.c renamed from net/core-w13/wireless.c +97
-0+ +/* ---------------------------------------------------------------- */ +/* +* Main event dispatcher. Called from other parts and drivers. +* Send the event on the apropriate channels. +* May be called from interrupt context. +*/ +void wireless_send_event (struct net_device * dev, +unsigned int cmd, +union iwreq_data * wrqu, +char * extra) +{ +const struct iw_ioctl_description * descr =NULL ; +int extra_len =0 ; +struct iw_event *event;/* Mallocated whole event */ +int event_len;/* Its size */ +int hdr_len;/* Size of the event header */ +/* Don't "optimise" the following variable, it will crash */ +unsigned cmd_index;/* *MUST* be unsigned */ + +/* Get the description of the IOCTL */ +if (cmd <=SIOCIWLAST ) { + cmd_index = cmd -SIOCIWFIRST ; +if (cmd_index < standard_ioctl_num) + descr = &(standard_ioctl[cmd_index]); + }else { + cmd_index = cmd -IWEVFIRST ; +if (cmd_index < standard_event_num) + descr = &(standard_event[cmd_index]); + } +/* Don't accept unknown events */ +if (descr ==NULL ) { +/* Note : we don't return an error to the driver, because +* the driver would not know what to do about it. It can't +* return an error to the user, because the event is not +* initiated by a user request. +* The best the driver could do is to log an error message. +* We will do it ourselves instead... +*/ +printk (KERN_ERR "%s (WE) : Invalid Wireless Event (0x%04X)\n" , + dev->name, cmd); +return ; + } +#ifdef WE_EVENT_DEBUG +printk (KERN_DEBUG "%s (WE) : Got event 0x%04X\n" , + dev->name, cmd); +printk (KERN_DEBUG "%s (WE) : Header type : %d, Token type : %d, size : %d, token : %d\n" , dev->name, descr->header_type, descr->token_type, descr->token_size, descr->max_tokens); +#endif /* WE_EVENT_DEBUG */ + +/* Check extra parameters and set extra_len */ +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); +return ; + } +if (wrqu->data.length < descr->min_tokens) { +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 */ +if (extra !=NULL ) + extra_len = wrqu->data.length * descr->token_size; +#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 */ + } + +/* Total length of the event */ + hdr_len = event_type_size[descr->header_type]; + 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); +#endif /* WE_EVENT_DEBUG */ + +/* Create temporary buffer to hold the event */ + event =kmalloc (event_len,GFP_ATOMIC ); +if (event ==NULL ) +return ; + +/* Fill event */ + event->len = event_len; + event->cmd = cmd; +memcpy (&event->u, wrqu, hdr_len -IW_EV_LCP_LEN ); +if (extra !=NULL ) +memcpy (((char *) event) + hdr_len, extra, extra_len); + +#ifdef WE_EVENT_NETLINK +/* rtnetlink event channel */ +rtmsg_iwinfo (dev, (char *) event, event_len); +#endif /* WE_EVENT_NETLINK */ + +/* Cleanup */ +kfree (event); + +return ;/* Always success, I guess ;-) */
Quoted 3 lines
}
Overall looks good. My only minor objection would be that this function should return an error value. Clearly the kmalloc can fail, at least.
Jeff
Quoted 6 lines · Jeff Garzik
Jean Tourrilhes wrote:
Overall looks good. My only minor objection would be that this function should return an error value. Clearly the kmalloc can fail, at least.
Jeff
Thanks for the quick review (as usual), very much appreciated.
Now, for the return value...
I've debated this precise point. Here is the comment that I
wrote in the code you just quoted :
/* Note : we don't return an error to the driver, because
* the driver would not know what to do about it. It can't
* return an error to the user, because the event is not
* initiated by a user request.
* The best the driver could do is to log an error message.
* We will do it ourselves instead...
*/
The failure to deliver an event to the user is not critical,
and I don't really see what the driver code would do with a return code. In fact, event delivery to user space is not reliable (netlink may drop it in case its queues are full - this is more likely than kmalloc failure), and my code only check a few of those failure conditions, so the driver has no way to know if the message reached its intended destination.
In fact, I eliminated the return code *on purpose*, to prevent
driver writer to do stupid things (like shutting down the driver) or adding additional log message (waste at this point).
Convincing enough ? Have fun... Jean
Yep, convinced :)