Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless-next-2.6

+4523 -4756
+7
Documentation/feature-removal-schedule.txt
··· 437 437 driver but this caused driver conflicts. 438 438 Who: Jean Delvare <khali@linux-fr.org> 439 439 Krzysztof Helt <krzysztof.h1@wp.pl> 440 + 441 + --------------------------- 442 + 443 + What: CONFIG_RFKILL_INPUT 444 + When: 2.6.33 445 + Why: Should be implemented in userspace, policy daemon. 446 + Who: Johannes Berg <johannes@sipsolutions.net>
+99 -534
Documentation/rfkill.txt
··· 1 - rfkill - RF switch subsystem support 2 - ==================================== 1 + rfkill - RF kill switch support 2 + =============================== 3 3 4 - 1 Introduction 5 - 2 Implementation details 6 - 3 Kernel driver guidelines 7 - 3.1 wireless device drivers 8 - 3.2 platform/switch drivers 9 - 3.3 input device drivers 10 - 4 Kernel API 11 - 5 Userspace support 4 + 1. Introduction 5 + 2. Implementation details 6 + 3. Kernel driver guidelines 7 + 4. Kernel API 8 + 5. Userspace support 12 9 13 10 14 - 1. Introduction: 11 + 1. Introduction 15 12 16 - The rfkill switch subsystem exists to add a generic interface to circuitry that 17 - can enable or disable the signal output of a wireless *transmitter* of any 18 - type. By far, the most common use is to disable radio-frequency transmitters. 13 + The rfkill subsystem provides a generic interface to disabling any radio 14 + transmitter in the system. When a transmitter is blocked, it shall not 15 + radiate any power. 19 16 20 - Note that disabling the signal output means that the the transmitter is to be 21 - made to not emit any energy when "blocked". rfkill is not about blocking data 22 - transmissions, it is about blocking energy emission. 17 + The subsystem also provides the ability to react on button presses and 18 + disable all transmitters of a certain type (or all). This is intended for 19 + situations where transmitters need to be turned off, for example on 20 + aircraft. 23 21 24 - The rfkill subsystem offers support for keys and switches often found on 25 - laptops to enable wireless devices like WiFi and Bluetooth, so that these keys 26 - and switches actually perform an action in all wireless devices of a given type 27 - attached to the system. 28 22 29 - The buttons to enable and disable the wireless transmitters are important in 30 - situations where the user is for example using his laptop on a location where 31 - radio-frequency transmitters _must_ be disabled (e.g. airplanes). 32 23 33 - Because of this requirement, userspace support for the keys should not be made 34 - mandatory. Because userspace might want to perform some additional smarter 35 - tasks when the key is pressed, rfkill provides userspace the possibility to 36 - take over the task to handle the key events. 37 - 38 - =============================================================================== 39 - 2: Implementation details 24 + 2. Implementation details 40 25 41 26 The rfkill subsystem is composed of various components: the rfkill class, the 42 27 rfkill-input module (an input layer handler), and some specific input layer 43 28 events. 44 29 45 - The rfkill class provides kernel drivers with an interface that allows them to 46 - know when they should enable or disable a wireless network device transmitter. 47 - This is enabled by the CONFIG_RFKILL Kconfig option. 30 + The rfkill class is provided for kernel drivers to register their radio 31 + transmitter with the kernel, provide methods for turning it on and off and, 32 + optionally, letting the system know about hardware-disabled states that may 33 + be implemented on the device. This code is enabled with the CONFIG_RFKILL 34 + Kconfig option, which drivers can "select". 48 35 49 - The rfkill class support makes sure userspace will be notified of all state 50 - changes on rfkill devices through uevents. It provides a notification chain 51 - for interested parties in the kernel to also get notified of rfkill state 52 - changes in other drivers. It creates several sysfs entries which can be used 53 - by userspace. See section "Userspace support". 54 - 55 - The rfkill-input module provides the kernel with the ability to implement a 56 - basic response when the user presses a key or button (or toggles a switch) 57 - related to rfkill functionality. It is an in-kernel implementation of default 58 - policy of reacting to rfkill-related input events and neither mandatory nor 59 - required for wireless drivers to operate. It is enabled by the 60 - CONFIG_RFKILL_INPUT Kconfig option. 61 - 62 - rfkill-input is a rfkill-related events input layer handler. This handler will 63 - listen to all rfkill key events and will change the rfkill state of the 64 - wireless devices accordingly. With this option enabled userspace could either 65 - do nothing or simply perform monitoring tasks. 66 - 67 - The rfkill-input module also provides EPO (emergency power-off) functionality 68 - for all wireless transmitters. This function cannot be overridden, and it is 69 - always active. rfkill EPO is related to *_RFKILL_ALL input layer events. 70 - 71 - 72 - Important terms for the rfkill subsystem: 73 - 74 - In order to avoid confusion, we avoid the term "switch" in rfkill when it is 75 - referring to an electronic control circuit that enables or disables a 76 - transmitter. We reserve it for the physical device a human manipulates 77 - (which is an input device, by the way): 78 - 79 - rfkill switch: 80 - 81 - A physical device a human manipulates. Its state can be perceived by 82 - the kernel either directly (through a GPIO pin, ACPI GPE) or by its 83 - effect on a rfkill line of a wireless device. 84 - 85 - rfkill controller: 86 - 87 - A hardware circuit that controls the state of a rfkill line, which a 88 - kernel driver can interact with *to modify* that state (i.e. it has 89 - either write-only or read/write access). 90 - 91 - rfkill line: 92 - 93 - An input channel (hardware or software) of a wireless device, which 94 - causes a wireless transmitter to stop emitting energy (BLOCK) when it 95 - is active. Point of view is extremely important here: rfkill lines are 96 - always seen from the PoV of a wireless device (and its driver). 97 - 98 - soft rfkill line/software rfkill line: 99 - 100 - A rfkill line the wireless device driver can directly change the state 101 - of. Related to rfkill_state RFKILL_STATE_SOFT_BLOCKED. 102 - 103 - hard rfkill line/hardware rfkill line: 104 - 105 - A rfkill line that works fully in hardware or firmware, and that cannot 106 - be overridden by the kernel driver. The hardware device or the 107 - firmware just exports its status to the driver, but it is read-only. 108 - Related to rfkill_state RFKILL_STATE_HARD_BLOCKED. 109 - 110 - The enum rfkill_state describes the rfkill state of a transmitter: 111 - 112 - When a rfkill line or rfkill controller is in the RFKILL_STATE_UNBLOCKED state, 113 - the wireless transmitter (radio TX circuit for example) is *enabled*. When the 114 - it is in the RFKILL_STATE_SOFT_BLOCKED or RFKILL_STATE_HARD_BLOCKED, the 115 - wireless transmitter is to be *blocked* from operating. 116 - 117 - RFKILL_STATE_SOFT_BLOCKED indicates that a call to toggle_radio() can change 118 - that state. RFKILL_STATE_HARD_BLOCKED indicates that a call to toggle_radio() 119 - will not be able to change the state and will return with a suitable error if 120 - attempts are made to set the state to RFKILL_STATE_UNBLOCKED. 121 - 122 - RFKILL_STATE_HARD_BLOCKED is used by drivers to signal that the device is 123 - locked in the BLOCKED state by a hardwire rfkill line (typically an input pin 124 - that, when active, forces the transmitter to be disabled) which the driver 125 - CANNOT override. 126 - 127 - Full rfkill functionality requires two different subsystems to cooperate: the 128 - input layer and the rfkill class. The input layer issues *commands* to the 129 - entire system requesting that devices registered to the rfkill class change 130 - state. The way this interaction happens is not complex, but it is not obvious 131 - either: 132 - 133 - Kernel Input layer: 134 - 135 - * Generates KEY_WWAN, KEY_WLAN, KEY_BLUETOOTH, SW_RFKILL_ALL, and 136 - other such events when the user presses certain keys, buttons, or 137 - toggles certain physical switches. 138 - 139 - THE INPUT LAYER IS NEVER USED TO PROPAGATE STATUS, NOTIFICATIONS OR THE 140 - KIND OF STUFF AN ON-SCREEN-DISPLAY APPLICATION WOULD REPORT. It is 141 - used to issue *commands* for the system to change behaviour, and these 142 - commands may or may not be carried out by some kernel driver or 143 - userspace application. It follows that doing user feedback based only 144 - on input events is broken, as there is no guarantee that an input event 145 - will be acted upon. 146 - 147 - Most wireless communication device drivers implementing rfkill 148 - functionality MUST NOT generate these events, and have no reason to 149 - register themselves with the input layer. Doing otherwise is a common 150 - misconception. There is an API to propagate rfkill status change 151 - information, and it is NOT the input layer. 152 - 153 - rfkill class: 154 - 155 - * Calls a hook in a driver to effectively change the wireless 156 - transmitter state; 157 - * Keeps track of the wireless transmitter state (with help from 158 - the driver); 159 - * Generates userspace notifications (uevents) and a call to a 160 - notification chain (kernel) when there is a wireless transmitter 161 - state change; 162 - * Connects a wireless communications driver with the common rfkill 163 - control system, which, for example, allows actions such as 164 - "switch all bluetooth devices offline" to be carried out by 165 - userspace or by rfkill-input. 166 - 167 - THE RFKILL CLASS NEVER ISSUES INPUT EVENTS. THE RFKILL CLASS DOES 168 - NOT LISTEN TO INPUT EVENTS. NO DRIVER USING THE RFKILL CLASS SHALL 169 - EVER LISTEN TO, OR ACT ON RFKILL INPUT EVENTS. Doing otherwise is 170 - a layering violation. 171 - 172 - Most wireless data communication drivers in the kernel have just to 173 - implement the rfkill class API to work properly. Interfacing to the 174 - input layer is not often required (and is very often a *bug*) on 175 - wireless drivers. 176 - 177 - Platform drivers often have to attach to the input layer to *issue* 178 - (but never to listen to) rfkill events for rfkill switches, and also to 179 - the rfkill class to export a control interface for the platform rfkill 180 - controllers to the rfkill subsystem. This does NOT mean the rfkill 181 - switch is attached to a rfkill class (doing so is almost always wrong). 182 - It just means the same kernel module is the driver for different 183 - devices (rfkill switches and rfkill controllers). 184 - 185 - 186 - Userspace input handlers (uevents) or kernel input handlers (rfkill-input): 187 - 188 - * Implements the policy of what should happen when one of the input 189 - layer events related to rfkill operation is received. 190 - * Uses the sysfs interface (userspace) or private rfkill API calls 191 - to tell the devices registered with the rfkill class to change 192 - their state (i.e. translates the input layer event into real 193 - action). 194 - 195 - * rfkill-input implements EPO by handling EV_SW SW_RFKILL_ALL 0 196 - (power off all transmitters) in a special way: it ignores any 197 - overrides and local state cache and forces all transmitters to the 198 - RFKILL_STATE_SOFT_BLOCKED state (including those which are already 199 - supposed to be BLOCKED). 200 - * rfkill EPO will remain active until rfkill-input receives an 201 - EV_SW SW_RFKILL_ALL 1 event. While the EPO is active, transmitters 202 - are locked in the blocked state (rfkill will refuse to unblock them). 203 - * rfkill-input implements different policies that the user can 204 - select for handling EV_SW SW_RFKILL_ALL 1. It will unlock rfkill, 205 - and either do nothing (leave transmitters blocked, but now unlocked), 206 - restore the transmitters to their state before the EPO, or unblock 207 - them all. 208 - 209 - Userspace uevent handler or kernel platform-specific drivers hooked to the 210 - rfkill notifier chain: 211 - 212 - * Taps into the rfkill notifier chain or to KOBJ_CHANGE uevents, 213 - in order to know when a device that is registered with the rfkill 214 - class changes state; 215 - * Issues feedback notifications to the user; 216 - * In the rare platforms where this is required, synthesizes an input 217 - event to command all *OTHER* rfkill devices to also change their 218 - statues when a specific rfkill device changes state. 219 - 220 - 221 - =============================================================================== 222 - 3: Kernel driver guidelines 223 - 224 - Remember: point-of-view is everything for a driver that connects to the rfkill 225 - subsystem. All the details below must be measured/perceived from the point of 226 - view of the specific driver being modified. 227 - 228 - The first thing one needs to know is whether his driver should be talking to 229 - the rfkill class or to the input layer. In rare cases (platform drivers), it 230 - could happen that you need to do both, as platform drivers often handle a 231 - variety of devices in the same driver. 232 - 233 - Do not mistake input devices for rfkill controllers. The only type of "rfkill 234 - switch" device that is to be registered with the rfkill class are those 235 - directly controlling the circuits that cause a wireless transmitter to stop 236 - working (or the software equivalent of them), i.e. what we call a rfkill 237 - controller. Every other kind of "rfkill switch" is just an input device and 238 - MUST NOT be registered with the rfkill class. 239 - 240 - A driver should register a device with the rfkill class when ALL of the 241 - following conditions are met (they define a rfkill controller): 242 - 243 - 1. The device is/controls a data communications wireless transmitter; 244 - 245 - 2. The kernel can interact with the hardware/firmware to CHANGE the wireless 246 - transmitter state (block/unblock TX operation); 247 - 248 - 3. The transmitter can be made to not emit any energy when "blocked": 249 - rfkill is not about blocking data transmissions, it is about blocking 250 - energy emission; 251 - 252 - A driver should register a device with the input subsystem to issue 253 - rfkill-related events (KEY_WLAN, KEY_BLUETOOTH, KEY_WWAN, KEY_WIMAX, 254 - SW_RFKILL_ALL, etc) when ALL of the folowing conditions are met: 255 - 256 - 1. It is directly related to some physical device the user interacts with, to 257 - command the O.S./firmware/hardware to enable/disable a data communications 258 - wireless transmitter. 259 - 260 - Examples of the physical device are: buttons, keys and switches the user 261 - will press/touch/slide/switch to enable or disable the wireless 262 - communication device. 263 - 264 - 2. It is NOT slaved to another device, i.e. there is no other device that 265 - issues rfkill-related input events in preference to this one. 266 - 267 - Please refer to the corner cases and examples section for more details. 268 - 269 - When in doubt, do not issue input events. For drivers that should generate 270 - input events in some platforms, but not in others (e.g. b43), the best solution 271 - is to NEVER generate input events in the first place. That work should be 272 - deferred to a platform-specific kernel module (which will know when to generate 273 - events through the rfkill notifier chain) or to userspace. This avoids the 274 - usual maintenance problems with DMI whitelisting. 275 - 276 - 277 - Corner cases and examples: 278 - ==================================== 279 - 280 - 1. If the device is an input device that, because of hardware or firmware, 281 - causes wireless transmitters to be blocked regardless of the kernel's will, it 282 - is still just an input device, and NOT to be registered with the rfkill class. 283 - 284 - 2. If the wireless transmitter switch control is read-only, it is an input 285 - device and not to be registered with the rfkill class (and maybe not to be made 286 - an input layer event source either, see below). 287 - 288 - 3. If there is some other device driver *closer* to the actual hardware the 289 - user interacted with (the button/switch/key) to issue an input event, THAT is 290 - the device driver that should be issuing input events. 291 - 292 - E.g: 293 - [RFKILL slider switch] -- [GPIO hardware] -- [WLAN card rf-kill input] 294 - (platform driver) (wireless card driver) 295 - 296 - The user is closer to the RFKILL slide switch plaform driver, so the driver 297 - which must issue input events is the platform driver looking at the GPIO 298 - hardware, and NEVER the wireless card driver (which is just a slave). It is 299 - very likely that there are other leaves than just the WLAN card rf-kill input 300 - (e.g. a bluetooth card, etc)... 301 - 302 - On the other hand, some embedded devices do this: 303 - 304 - [RFKILL slider switch] -- [WLAN card rf-kill input] 305 - (wireless card driver) 306 - 307 - In this situation, the wireless card driver *could* register itself as an input 308 - device and issue rf-kill related input events... but in order to AVOID the need 309 - for DMI whitelisting, the wireless card driver does NOT do it. Userspace (HAL) 310 - or a platform driver (that exists only on these embedded devices) will do the 311 - dirty job of issuing the input events. 312 - 313 - 314 - COMMON MISTAKES in kernel drivers, related to rfkill: 315 - ==================================== 316 - 317 - 1. NEVER confuse input device keys and buttons with input device switches. 318 - 319 - 1a. Switches are always set or reset. They report the current state 320 - (on position or off position). 321 - 322 - 1b. Keys and buttons are either in the pressed or not-pressed state, and 323 - that's it. A "button" that latches down when you press it, and 324 - unlatches when you press it again is in fact a switch as far as input 325 - devices go. 326 - 327 - Add the SW_* events you need for switches, do NOT try to emulate a button using 328 - KEY_* events just because there is no such SW_* event yet. Do NOT try to use, 329 - for example, KEY_BLUETOOTH when you should be using SW_BLUETOOTH instead. 330 - 331 - 2. Input device switches (sources of EV_SW events) DO store their current state 332 - (so you *must* initialize it by issuing a gratuitous input layer event on 333 - driver start-up and also when resuming from sleep), and that state CAN be 334 - queried from userspace through IOCTLs. There is no sysfs interface for this, 335 - but that doesn't mean you should break things trying to hook it to the rfkill 336 - class to get a sysfs interface :-) 337 - 338 - 3. Do not issue *_RFKILL_ALL events by default, unless you are sure it is the 339 - correct event for your switch/button. These events are emergency power-off 340 - events when they are trying to turn the transmitters off. An example of an 341 - input device which SHOULD generate *_RFKILL_ALL events is the wireless-kill 342 - switch in a laptop which is NOT a hotkey, but a real sliding/rocker switch. 343 - An example of an input device which SHOULD NOT generate *_RFKILL_ALL events by 344 - default, is any sort of hot key that is type-specific (e.g. the one for WLAN). 345 - 346 - 347 - 3.1 Guidelines for wireless device drivers 348 - ------------------------------------------ 349 - 350 - (in this text, rfkill->foo means the foo field of struct rfkill). 351 - 352 - 1. Each independent transmitter in a wireless device (usually there is only one 353 - transmitter per device) should have a SINGLE rfkill class attached to it. 354 - 355 - 2. If the device does not have any sort of hardware assistance to allow the 356 - driver to rfkill the device, the driver should emulate it by taking all actions 357 - required to silence the transmitter. 358 - 359 - 3. If it is impossible to silence the transmitter (i.e. it still emits energy, 360 - even if it is just in brief pulses, when there is no data to transmit and there 361 - is no hardware support to turn it off) do NOT lie to the users. Do not attach 362 - it to a rfkill class. The rfkill subsystem does not deal with data 363 - transmission, it deals with energy emission. If the transmitter is emitting 364 - energy, it is not blocked in rfkill terms. 365 - 366 - 4. It doesn't matter if the device has multiple rfkill input lines affecting 367 - the same transmitter, their combined state is to be exported as a single state 368 - per transmitter (see rule 1). 369 - 370 - This rule exists because users of the rfkill subsystem expect to get (and set, 371 - when possible) the overall transmitter rfkill state, not of a particular rfkill 372 - line. 373 - 374 - 5. The wireless device driver MUST NOT leave the transmitter enabled during 375 - suspend and hibernation unless: 376 - 377 - 5.1. The transmitter has to be enabled for some sort of functionality 378 - like wake-on-wireless-packet or autonomous packed forwarding in a mesh 379 - network, and that functionality is enabled for this suspend/hibernation 380 - cycle. 381 - 382 - AND 383 - 384 - 5.2. The device was not on a user-requested BLOCKED state before 385 - the suspend (i.e. the driver must NOT unblock a device, not even 386 - to support wake-on-wireless-packet or remain in the mesh). 387 - 388 - In other words, there is absolutely no allowed scenario where a driver can 389 - automatically take action to unblock a rfkill controller (obviously, this deals 390 - with scenarios where soft-blocking or both soft and hard blocking is happening. 391 - Scenarios where hardware rfkill lines are the only ones blocking the 392 - transmitter are outside of this rule, since the wireless device driver does not 393 - control its input hardware rfkill lines in the first place). 394 - 395 - 6. During resume, rfkill will try to restore its previous state. 396 - 397 - 7. After a rfkill class is suspended, it will *not* call rfkill->toggle_radio 398 - until it is resumed. 399 - 400 - 401 - Example of a WLAN wireless driver connected to the rfkill subsystem: 402 - -------------------------------------------------------------------- 403 - 404 - A certain WLAN card has one input pin that causes it to block the transmitter 405 - and makes the status of that input pin available (only for reading!) to the 406 - kernel driver. This is a hard rfkill input line (it cannot be overridden by 407 - the kernel driver). 408 - 409 - The card also has one PCI register that, if manipulated by the driver, causes 410 - it to block the transmitter. This is a soft rfkill input line. 411 - 412 - It has also a thermal protection circuitry that shuts down its transmitter if 413 - the card overheats, and makes the status of that protection available (only for 414 - reading!) to the kernel driver. This is also a hard rfkill input line. 415 - 416 - If either one of these rfkill lines are active, the transmitter is blocked by 417 - the hardware and forced offline. 418 - 419 - The driver should allocate and attach to its struct device *ONE* instance of 420 - the rfkill class (there is only one transmitter). 421 - 422 - It can implement the get_state() hook, and return RFKILL_STATE_HARD_BLOCKED if 423 - either one of its two hard rfkill input lines are active. If the two hard 424 - rfkill lines are inactive, it must return RFKILL_STATE_SOFT_BLOCKED if its soft 425 - rfkill input line is active. Only if none of the rfkill input lines are 426 - active, will it return RFKILL_STATE_UNBLOCKED. 427 - 428 - Since the device has a hardware rfkill line, it IS subject to state changes 429 - external to rfkill. Therefore, the driver must make sure that it calls 430 - rfkill_force_state() to keep the status always up-to-date, and it must do a 431 - rfkill_force_state() on resume from sleep. 432 - 433 - Every time the driver gets a notification from the card that one of its rfkill 434 - lines changed state (polling might be needed on badly designed cards that don't 435 - generate interrupts for such events), it recomputes the rfkill state as per 436 - above, and calls rfkill_force_state() to update it. 437 - 438 - The driver should implement the toggle_radio() hook, that: 439 - 440 - 1. Returns an error if one of the hardware rfkill lines are active, and the 441 - caller asked for RFKILL_STATE_UNBLOCKED. 442 - 443 - 2. Activates the soft rfkill line if the caller asked for state 444 - RFKILL_STATE_SOFT_BLOCKED. It should do this even if one of the hard rfkill 445 - lines are active, effectively double-blocking the transmitter. 446 - 447 - 3. Deactivates the soft rfkill line if none of the hardware rfkill lines are 448 - active and the caller asked for RFKILL_STATE_UNBLOCKED. 449 - 450 - =============================================================================== 451 - 4: Kernel API 36 + The rfkill class code also notifies userspace of state changes, this is 37 + achieved via uevents. It also provides some sysfs files for userspace to 38 + check the status of radio transmitters. See the "Userspace support" section 39 + below. 40 + 41 + 42 + The rfkill-input code implements a basic response to rfkill buttons -- it 43 + implements turning on/off all devices of a certain class (or all). 44 + 45 + When the device is hard-blocked (either by a call to rfkill_set_hw_state() 46 + or from query_hw_block) set_block() will be invoked but drivers can well 47 + ignore the method call since they can use the return value of the function 48 + rfkill_set_hw_state() to sync the software state instead of keeping track 49 + of calls to set_block(). 50 + 51 + 52 + The entire functionality is spread over more than one subsystem: 53 + 54 + * The kernel input layer generates KEY_WWAN, KEY_WLAN etc. and 55 + SW_RFKILL_ALL -- when the user presses a button. Drivers for radio 56 + transmitters generally do not register to the input layer, unless the 57 + device really provides an input device (i.e. a button that has no 58 + effect other than generating a button press event) 59 + 60 + * The rfkill-input code hooks up to these events and switches the soft-block 61 + of the various radio transmitters, depending on the button type. 62 + 63 + * The rfkill drivers turn off/on their transmitters as requested. 64 + 65 + * The rfkill class will generate userspace notifications (uevents) to tell 66 + userspace what the current state is. 67 + 68 + 69 + 70 + 3. Kernel driver guidelines 71 + 72 + 73 + Drivers for radio transmitters normally implement only the rfkill class. 74 + These drivers may not unblock the transmitter based on own decisions, they 75 + should act on information provided by the rfkill class only. 76 + 77 + Platform drivers might implement input devices if the rfkill button is just 78 + that, a button. If that button influences the hardware then you need to 79 + implement an rfkill class instead. This also applies if the platform provides 80 + a way to turn on/off the transmitter(s). 81 + 82 + During suspend/hibernation, transmitters should only be left enabled when 83 + wake-on wlan or similar functionality requires it and the device wasn't 84 + blocked before suspend/hibernate. Note that it may be necessary to update 85 + the rfkill subsystem's idea of what the current state is at resume time if 86 + the state may have changed over suspend. 87 + 88 + 89 + 90 + 4. Kernel API 452 91 453 92 To build a driver with rfkill subsystem support, the driver should depend on 454 - (or select) the Kconfig symbol RFKILL; it should _not_ depend on RKFILL_INPUT. 93 + (or select) the Kconfig symbol RFKILL. 455 94 456 95 The hardware the driver talks to may be write-only (where the current state 457 96 of the hardware is unknown), or read-write (where the hardware can be queried 458 97 about its current state). 459 98 460 - The rfkill class will call the get_state hook of a device every time it needs 461 - to know the *real* current state of the hardware. This can happen often, but 462 - it does not do any polling, so it is not enough on hardware that is subject 463 - to state changes outside of the rfkill subsystem. 99 + Calling rfkill_set_hw_state() when a state change happens is required from 100 + rfkill drivers that control devices that can be hard-blocked unless they also 101 + assign the poll_hw_block() callback (then the rfkill core will poll the 102 + device). Don't do this unless you cannot get the event in any other way. 464 103 465 - Therefore, calling rfkill_force_state() when a state change happens is 466 - mandatory when the device has a hardware rfkill line, or when something else 467 - like the firmware could cause its state to be changed without going through the 468 - rfkill class. 469 104 470 - Some hardware provides events when its status changes. In these cases, it is 471 - best for the driver to not provide a get_state hook, and instead register the 472 - rfkill class *already* with the correct status, and keep it updated using 473 - rfkill_force_state() when it gets an event from the hardware. 474 105 475 - rfkill_force_state() must be used on the device resume handlers to update the 476 - rfkill status, should there be any chance of the device status changing during 477 - the sleep. 106 + 5. Userspace support 478 107 479 - There is no provision for a statically-allocated rfkill struct. You must 480 - use rfkill_allocate() to allocate one. 481 - 482 - You should: 483 - - rfkill_allocate() 484 - - modify rfkill fields (flags, name) 485 - - modify state to the current hardware state (THIS IS THE ONLY TIME 486 - YOU CAN ACCESS state DIRECTLY) 487 - - rfkill_register() 488 - 489 - The only way to set a device to the RFKILL_STATE_HARD_BLOCKED state is through 490 - a suitable return of get_state() or through rfkill_force_state(). 491 - 492 - When a device is in the RFKILL_STATE_HARD_BLOCKED state, the only way to switch 493 - it to a different state is through a suitable return of get_state() or through 494 - rfkill_force_state(). 495 - 496 - If toggle_radio() is called to set a device to state RFKILL_STATE_SOFT_BLOCKED 497 - when that device is already at the RFKILL_STATE_HARD_BLOCKED state, it should 498 - not return an error. Instead, it should try to double-block the transmitter, 499 - so that its state will change from RFKILL_STATE_HARD_BLOCKED to 500 - RFKILL_STATE_SOFT_BLOCKED should the hardware blocking cease. 501 - 502 - Please refer to the source for more documentation. 503 - 504 - =============================================================================== 505 - 5: Userspace support 506 - 507 - rfkill devices issue uevents (with an action of "change"), with the following 508 - environment variables set: 509 - 510 - RFKILL_NAME 511 - RFKILL_STATE 512 - RFKILL_TYPE 513 - 514 - The ABI for these variables is defined by the sysfs attributes. It is best 515 - to take a quick look at the source to make sure of the possible values. 516 - 517 - It is expected that HAL will trap those, and bridge them to DBUS, etc. These 518 - events CAN and SHOULD be used to give feedback to the user about the rfkill 519 - status of the system. 520 - 521 - Input devices may issue events that are related to rfkill. These are the 522 - various KEY_* events and SW_* events supported by rfkill-input.c. 523 - 524 - Userspace may not change the state of an rfkill switch in response to an 525 - input event, it should refrain from changing states entirely. 526 - 527 - Userspace cannot assume it is the only source of control for rfkill switches. 528 - Their state can change due to firmware actions, direct user actions, and the 529 - rfkill-input EPO override for *_RFKILL_ALL. 530 - 531 - When rfkill-input is not active, userspace must initiate a rfkill status 532 - change by writing to the "state" attribute in order for anything to happen. 533 - 534 - Take particular care to implement EV_SW SW_RFKILL_ALL properly. When that 535 - switch is set to OFF, *every* rfkill device *MUST* be immediately put into the 536 - RFKILL_STATE_SOFT_BLOCKED state, no questions asked. 537 - 538 - The following sysfs entries will be created: 108 + The following sysfs entries exist for every rfkill device: 539 109 540 110 name: Name assigned by driver to this key (interface or driver name). 541 111 type: Name of the key type ("wlan", "bluetooth", etc). 542 112 state: Current state of the transmitter 543 113 0: RFKILL_STATE_SOFT_BLOCKED 544 - transmitter is forced off, but one can override it 545 - by a write to the state attribute; 114 + transmitter is turned off by software 546 115 1: RFKILL_STATE_UNBLOCKED 547 - transmiter is NOT forced off, and may operate if 548 - all other conditions for such operation are met 549 - (such as interface is up and configured, etc); 116 + transmitter is (potentially) active 550 117 2: RFKILL_STATE_HARD_BLOCKED 551 118 transmitter is forced off by something outside of 552 - the driver's control. One cannot set a device to 553 - this state through writes to the state attribute; 554 - claim: 1: Userspace handles events, 0: Kernel handles events 119 + the driver's control. 120 + claim: 0: Kernel handles events (currently always reads that value) 555 121 556 - Both the "state" and "claim" entries are also writable. For the "state" entry 557 - this means that when 1 or 0 is written, the device rfkill state (if not yet in 558 - the requested state), will be will be toggled accordingly. 122 + rfkill devices also issue uevents (with an action of "change"), with the 123 + following environment variables set: 559 124 560 - For the "claim" entry writing 1 to it means that the kernel no longer handles 561 - key events even though RFKILL_INPUT input was enabled. When "claim" has been 562 - set to 0, userspace should make sure that it listens for the input events or 563 - check the sysfs "state" entry regularly to correctly perform the required tasks 564 - when the rkfill key is pressed. 125 + RFKILL_NAME 126 + RFKILL_STATE 127 + RFKILL_TYPE 565 128 566 - A note about input devices and EV_SW events: 129 + The contents of these variables corresponds to the "name", "state" and 130 + "type" sysfs files explained above. 567 131 568 - In order to know the current state of an input device switch (like 569 - SW_RFKILL_ALL), you will need to use an IOCTL. That information is not 570 - available through sysfs in a generic way at this time, and it is not available 571 - through the rfkill class AT ALL. 132 + An alternative userspace interface exists as a misc device /dev/rfkill, 133 + which allows userspace to obtain and set the state of rfkill devices and 134 + sets of devices. It also notifies userspace about device addition and 135 + removal. The API is a simple read/write API that is defined in 136 + linux/rfkill.h.
+3 -3
MAINTAINERS
··· 4753 4753 F: fs/reiserfs/ 4754 4754 4755 4755 RFKILL 4756 - P: Ivo van Doorn 4757 - M: IvDoorn@gmail.com 4758 - L: netdev@vger.kernel.org 4756 + P: Johannes Berg 4757 + M: johannes@sipsolutions.net 4758 + L: linux-wireless@vger.kernel.org 4759 4759 S: Maintained 4760 4760 F Documentation/rfkill.txt 4761 4761 F: net/rfkill/
+15 -15
arch/arm/mach-pxa/tosa-bt.c
··· 35 35 gpio_set_value(data->gpio_reset, 0); 36 36 } 37 37 38 - static int tosa_bt_toggle_radio(void *data, enum rfkill_state state) 38 + static int tosa_bt_set_block(void *data, bool blocked) 39 39 { 40 - pr_info("BT_RADIO going: %s\n", 41 - state == RFKILL_STATE_UNBLOCKED ? "on" : "off"); 40 + pr_info("BT_RADIO going: %s\n", blocked ? "off" : "on"); 42 41 43 - if (state == RFKILL_STATE_UNBLOCKED) { 42 + if (!blocked) { 44 43 pr_info("TOSA_BT: going ON\n"); 45 44 tosa_bt_on(data); 46 45 } else { 47 46 pr_info("TOSA_BT: going OFF\n"); 48 47 tosa_bt_off(data); 49 48 } 49 + 50 50 return 0; 51 51 } 52 + 53 + static const struct rfkill_ops tosa_bt_rfkill_ops = { 54 + .set_block = tosa_bt_set_block, 55 + }; 52 56 53 57 static int tosa_bt_probe(struct platform_device *dev) 54 58 { ··· 74 70 if (rc) 75 71 goto err_pwr_dir; 76 72 77 - rfk = rfkill_allocate(&dev->dev, RFKILL_TYPE_BLUETOOTH); 73 + rfk = rfkill_alloc("tosa-bt", &dev->dev, RFKILL_TYPE_BLUETOOTH, 74 + &tosa_bt_rfkill_ops, data); 78 75 if (!rfk) { 79 76 rc = -ENOMEM; 80 77 goto err_rfk_alloc; 81 78 } 82 79 83 - rfk->name = "tosa-bt"; 84 - rfk->toggle_radio = tosa_bt_toggle_radio; 85 - rfk->data = data; 86 - #ifdef CONFIG_RFKILL_LEDS 87 - rfk->led_trigger.name = "tosa-bt"; 88 - #endif 80 + rfkill_set_led_trigger_name(rfk, "tosa-bt"); 89 81 90 82 rc = rfkill_register(rfk); 91 83 if (rc) ··· 92 92 return 0; 93 93 94 94 err_rfkill: 95 - if (rfk) 96 - rfkill_free(rfk); 97 - rfk = NULL; 95 + rfkill_destroy(rfk); 98 96 err_rfk_alloc: 99 97 tosa_bt_off(data); 100 98 err_pwr_dir: ··· 111 113 112 114 platform_set_drvdata(dev, NULL); 113 115 114 - if (rfk) 116 + if (rfk) { 115 117 rfkill_unregister(rfk); 118 + rfkill_destroy(rfk); 119 + } 116 120 rfk = NULL; 117 121 118 122 tosa_bt_off(data);
-1
arch/arm/mach-pxa/tosa.c
··· 31 31 #include <linux/input.h> 32 32 #include <linux/gpio.h> 33 33 #include <linux/pda_power.h> 34 - #include <linux/rfkill.h> 35 34 #include <linux/spi/spi.h> 36 35 37 36 #include <asm/setup.h>
+23 -21
drivers/net/usb/hso.c
··· 2481 2481 return 0; 2482 2482 } 2483 2483 2484 - static int hso_radio_toggle(void *data, enum rfkill_state state) 2484 + static int hso_rfkill_set_block(void *data, bool blocked) 2485 2485 { 2486 2486 struct hso_device *hso_dev = data; 2487 - int enabled = (state == RFKILL_STATE_UNBLOCKED); 2487 + int enabled = !blocked; 2488 2488 int rv; 2489 2489 2490 2490 mutex_lock(&hso_dev->mutex); ··· 2498 2498 return rv; 2499 2499 } 2500 2500 2501 + static const struct rfkill_ops hso_rfkill_ops = { 2502 + .set_block = hso_rfkill_set_block, 2503 + }; 2504 + 2501 2505 /* Creates and sets up everything for rfkill */ 2502 2506 static void hso_create_rfkill(struct hso_device *hso_dev, 2503 2507 struct usb_interface *interface) ··· 2510 2506 struct device *dev = &hso_net->net->dev; 2511 2507 char *rfkn; 2512 2508 2513 - hso_net->rfkill = rfkill_allocate(&interface_to_usbdev(interface)->dev, 2514 - RFKILL_TYPE_WWAN); 2515 - if (!hso_net->rfkill) { 2516 - dev_err(dev, "%s - Out of memory\n", __func__); 2517 - return; 2518 - } 2519 2509 rfkn = kzalloc(20, GFP_KERNEL); 2520 - if (!rfkn) { 2521 - rfkill_free(hso_net->rfkill); 2522 - hso_net->rfkill = NULL; 2510 + if (!rfkn) 2523 2511 dev_err(dev, "%s - Out of memory\n", __func__); 2524 - return; 2525 - } 2512 + 2526 2513 snprintf(rfkn, 20, "hso-%d", 2527 2514 interface->altsetting->desc.bInterfaceNumber); 2528 - hso_net->rfkill->name = rfkn; 2529 - hso_net->rfkill->state = RFKILL_STATE_UNBLOCKED; 2530 - hso_net->rfkill->data = hso_dev; 2531 - hso_net->rfkill->toggle_radio = hso_radio_toggle; 2532 - if (rfkill_register(hso_net->rfkill) < 0) { 2515 + 2516 + hso_net->rfkill = rfkill_alloc(rfkn, 2517 + &interface_to_usbdev(interface)->dev, 2518 + RFKILL_TYPE_WWAN, 2519 + &hso_rfkill_ops, hso_dev); 2520 + if (!hso_net->rfkill) { 2521 + dev_err(dev, "%s - Out of memory\n", __func__); 2533 2522 kfree(rfkn); 2534 - hso_net->rfkill->name = NULL; 2535 - rfkill_free(hso_net->rfkill); 2523 + return; 2524 + } 2525 + if (rfkill_register(hso_net->rfkill) < 0) { 2526 + rfkill_destroy(hso_net->rfkill); 2527 + kfree(rfkn); 2536 2528 hso_net->rfkill = NULL; 2537 2529 dev_err(dev, "%s - Failed to register rfkill\n", __func__); 2538 2530 return; ··· 3165 3165 hso_stop_net_device(network_table[i]); 3166 3166 cancel_work_sync(&network_table[i]->async_put_intf); 3167 3167 cancel_work_sync(&network_table[i]->async_get_intf); 3168 - if (rfk) 3168 + if (rfk) { 3169 3169 rfkill_unregister(rfk); 3170 + rfkill_destroy(rfk); 3171 + } 3170 3172 hso_free_net_device(network_table[i]); 3171 3173 } 3172 3174 }
+1 -1
drivers/net/wireless/Kconfig
··· 333 333 config USB_NET_RNDIS_WLAN 334 334 tristate "Wireless RNDIS USB support" 335 335 depends on USB && WLAN_80211 && EXPERIMENTAL 336 + depends on CFG80211 336 337 select USB_USBNET 337 338 select USB_NET_CDCETHER 338 339 select USB_NET_RNDIS_HOST 339 340 select WIRELESS_EXT 340 - select CFG80211 341 341 ---help--- 342 342 This is a driver for wireless RNDIS devices. 343 343 These are USB based adapters found in devices such as:
+7 -3
drivers/net/wireless/ath/ar9170/ar9170.h
··· 91 91 struct led_classdev l; 92 92 char name[32]; 93 93 unsigned int toggled; 94 + bool last_state; 94 95 bool registered; 95 96 }; 96 97 ··· 102 101 AR9170_STOPPED, 103 102 AR9170_IDLE, 104 103 AR9170_STARTED, 105 - AR9170_ASSOCIATED, 106 104 }; 107 105 108 106 struct ar9170_rxstream_mpdu_merge { ··· 140 140 struct work_struct filter_config_work; 141 141 u64 cur_mc_hash, want_mc_hash; 142 142 u32 cur_filter, want_filter; 143 - unsigned int filter_changed; 143 + unsigned long filter_changed; 144 144 unsigned int filter_state; 145 145 bool sniffer_enabled; 146 146 ··· 195 195 #define IS_STARTED(a) (a->state >= AR9170_STARTED) 196 196 #define IS_ACCEPTING_CMD(a) (a->state >= AR9170_IDLE) 197 197 198 - #define AR9170_FILTER_CHANGED_PROMISC BIT(0) 198 + #define AR9170_FILTER_CHANGED_MODE BIT(0) 199 199 #define AR9170_FILTER_CHANGED_MULTICAST BIT(1) 200 200 #define AR9170_FILTER_CHANGED_FRAMEFILTER BIT(2) 201 201 ··· 206 206 void ar9170_unregister(struct ar9170 *ar); 207 207 void ar9170_handle_tx_status(struct ar9170 *ar, struct sk_buff *skb, 208 208 bool update_statistics, u16 tx_status); 209 + void ar9170_handle_command_response(struct ar9170 *ar, void *buf, u32 len); 209 210 210 211 /* MAC */ 211 212 int ar9170_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb); ··· 216 215 int ar9170_update_frame_filter(struct ar9170 *ar); 217 216 int ar9170_set_operating_mode(struct ar9170 *ar); 218 217 int ar9170_set_beacon_timers(struct ar9170 *ar); 218 + int ar9170_set_dyn_sifs_ack(struct ar9170 *ar); 219 + int ar9170_set_slot_time(struct ar9170 *ar); 220 + int ar9170_set_basic_rates(struct ar9170 *ar); 219 221 int ar9170_set_hwretry_limit(struct ar9170 *ar, u32 max_retry); 220 222 int ar9170_update_beacon(struct ar9170 *ar); 221 223 void ar9170_new_beacon(struct work_struct *work);
+3 -2
drivers/net/wireless/ath/ar9170/hw.h
··· 207 207 #define AR9170_MAC_REG_AC1_AC0_TXOP (AR9170_MAC_REG_BASE + 0xB44) 208 208 #define AR9170_MAC_REG_AC3_AC2_TXOP (AR9170_MAC_REG_BASE + 0xB48) 209 209 210 - #define AR9170_MAC_REG_AMPDU_SET (AR9170_MAC_REG_BASE + 0xba0) 210 + #define AR9170_MAC_REG_AMPDU_FACTOR (AR9170_MAC_REG_BASE + 0xB9C) 211 + #define AR9170_MAC_REG_AMPDU_DENSITY (AR9170_MAC_REG_BASE + 0xBA0) 211 212 212 213 #define AR9170_MAC_REG_ACK_TABLE (AR9170_MAC_REG_BASE + 0xC00) 213 214 #define AR9170_MAC_REG_AMPDU_RX_THRESH (AR9170_MAC_REG_BASE + 0xC50) ··· 377 376 #define AR9170_RX_ERROR_FATAL 0x80 378 377 379 378 struct ar9170_cmd_tx_status { 380 - __le16 unkn; 381 379 u8 dst[ETH_ALEN]; 382 380 __le32 rate; 383 381 __le16 status; ··· 394 394 struct ar9170_cmd_response { 395 395 u8 flag; 396 396 u8 type; 397 + __le16 padding; 397 398 398 399 union { 399 400 struct ar9170_cmd_tx_status tx_status;
+12 -5
drivers/net/wireless/ath/ar9170/led.c
··· 74 74 75 75 mutex_lock(&ar->mutex); 76 76 for (i = 0; i < AR9170_NUM_LEDS; i++) 77 - if (ar->leds[i].toggled) { 77 + if (ar->leds[i].registered && ar->leds[i].toggled) { 78 78 led_val |= 1 << i; 79 79 80 80 tmp = 70 + 200 / (ar->leds[i].toggled); ··· 101 101 struct ar9170_led *arl = container_of(led, struct ar9170_led, l); 102 102 struct ar9170 *ar = arl->ar; 103 103 104 - arl->toggled++; 104 + if (unlikely(!arl->registered)) 105 + return ; 105 106 106 - if (likely(IS_ACCEPTING_CMD(ar) && brightness)) 107 + if (arl->last_state != !!brightness) { 108 + arl->toggled++; 109 + arl->last_state = !!brightness; 110 + } 111 + 112 + if (likely(IS_ACCEPTING_CMD(ar) && arl->toggled)) 107 113 queue_delayed_work(ar->hw->workqueue, &ar->led_work, HZ/10); 108 114 } 109 115 ··· 142 136 { 143 137 int i; 144 138 145 - cancel_delayed_work_sync(&ar->led_work); 146 - 147 139 for (i = 0; i < AR9170_NUM_LEDS; i++) 148 140 if (ar->leds[i].registered) { 149 141 led_classdev_unregister(&ar->leds[i].l); 150 142 ar->leds[i].registered = false; 143 + ar->leds[i].toggled = 0; 151 144 } 145 + 146 + cancel_delayed_work_sync(&ar->led_work); 152 147 } 153 148 154 149 int ar9170_register_leds(struct ar9170 *ar)
+52 -3
drivers/net/wireless/ath/ar9170/mac.c
··· 38 38 #include "ar9170.h" 39 39 #include "cmd.h" 40 40 41 + int ar9170_set_dyn_sifs_ack(struct ar9170 *ar) 42 + { 43 + u32 val; 44 + 45 + if (conf_is_ht40(&ar->hw->conf)) 46 + val = 0x010a; 47 + else { 48 + if (ar->hw->conf.channel->band == IEEE80211_BAND_2GHZ) 49 + val = 0x105; 50 + else 51 + val = 0x104; 52 + } 53 + 54 + return ar9170_write_reg(ar, AR9170_MAC_REG_DYNAMIC_SIFS_ACK, val); 55 + } 56 + 57 + int ar9170_set_slot_time(struct ar9170 *ar) 58 + { 59 + u32 slottime = 20; 60 + 61 + if (!ar->vif) 62 + return 0; 63 + 64 + if ((ar->hw->conf.channel->band == IEEE80211_BAND_5GHZ) || 65 + ar->vif->bss_conf.use_short_slot) 66 + slottime = 9; 67 + 68 + return ar9170_write_reg(ar, AR9170_MAC_REG_SLOT_TIME, slottime << 10); 69 + } 70 + 71 + int ar9170_set_basic_rates(struct ar9170 *ar) 72 + { 73 + u8 cck, ofdm; 74 + 75 + if (!ar->vif) 76 + return 0; 77 + 78 + ofdm = ar->vif->bss_conf.basic_rates >> 4; 79 + 80 + /* FIXME: is still necessary? */ 81 + if (ar->hw->conf.channel->band == IEEE80211_BAND_5GHZ) 82 + cck = 0; 83 + else 84 + cck = ar->vif->bss_conf.basic_rates & 0xf; 85 + 86 + return ar9170_write_reg(ar, AR9170_MAC_REG_BASIC_RATE, 87 + ofdm << 8 | cck); 88 + } 89 + 41 90 int ar9170_set_qos(struct ar9170 *ar) 42 91 { 43 92 ar9170_regwrite_begin(ar); ··· 133 84 val = 0x140a00 | (mpdudensity ? (mpdudensity + 1) : 0); 134 85 135 86 ar9170_regwrite_begin(ar); 136 - ar9170_regwrite(AR9170_MAC_REG_AMPDU_SET, val); 87 + ar9170_regwrite(AR9170_MAC_REG_AMPDU_DENSITY, val); 137 88 ar9170_regwrite_finish(); 138 89 139 90 return ar9170_regwrite_result(); ··· 447 398 /* XXX: use skb->cb info */ 448 399 if (ar->hw->conf.channel->band == IEEE80211_BAND_2GHZ) 449 400 ar9170_regwrite(AR9170_MAC_REG_BCN_PLCP, 450 - ((skb->len + 4) << (3+16)) + 0x0400); 401 + ((skb->len + 4) << (3 + 16)) + 0x0400); 451 402 else 452 403 ar9170_regwrite(AR9170_MAC_REG_BCN_PLCP, 453 - ((skb->len + 4) << (3+16)) + 0x0400); 404 + ((skb->len + 4) << 16) + 0x001b); 454 405 455 406 ar9170_regwrite(AR9170_MAC_REG_BCN_LENGTH, skb->len + 4); 456 407 ar9170_regwrite(AR9170_MAC_REG_BCN_ADDR, AR9170_BEACON_BUFFER_ADDRESS);
+48 -50
drivers/net/wireless/ath/ar9170/main.c
··· 146 146 { \ 147 147 .ht_supported = true, \ 148 148 .cap = IEEE80211_HT_CAP_MAX_AMSDU | \ 149 - IEEE80211_HT_CAP_SM_PS | \ 150 149 IEEE80211_HT_CAP_SUP_WIDTH_20_40 | \ 151 150 IEEE80211_HT_CAP_SGI_40 | \ 152 151 IEEE80211_HT_CAP_DSSSCCK40 | \ ··· 343 344 if (unlikely(!IS_STARTED(ar))) 344 345 return ; 345 346 346 - mutex_lock(&ar->mutex); 347 347 /* recycle the garbage back to mac80211... one by one. */ 348 348 while ((skb = skb_dequeue(&ar->global_tx_status_waste))) { 349 349 #ifdef AR9170_QUEUE_DEBUG ··· 368 370 if (skb_queue_len(&ar->global_tx_status_waste) > 0) 369 371 queue_delayed_work(ar->hw->workqueue, &ar->tx_status_janitor, 370 372 msecs_to_jiffies(100)); 371 - 372 - mutex_unlock(&ar->mutex); 373 373 } 374 374 375 - static void ar9170_handle_command_response(struct ar9170 *ar, 376 - void *buf, u32 len) 375 + void ar9170_handle_command_response(struct ar9170 *ar, void *buf, u32 len) 377 376 { 378 377 struct ar9170_cmd_response *cmd = (void *) buf; 379 378 ··· 952 957 953 958 mutex_lock(&ar->mutex); 954 959 960 + ar->filter_changed = 0; 961 + 955 962 /* reinitialize queues statistics */ 956 963 memset(&ar->tx_stats, 0, sizeof(ar->tx_stats)); 957 964 for (i = 0; i < ARRAY_SIZE(ar->tx_stats); i++) ··· 1009 1012 1010 1013 flush_workqueue(ar->hw->workqueue); 1011 1014 1012 - mutex_lock(&ar->mutex); 1013 1015 cancel_delayed_work_sync(&ar->tx_status_janitor); 1014 1016 cancel_work_sync(&ar->filter_config_work); 1015 1017 cancel_work_sync(&ar->beacon_work); 1018 + mutex_lock(&ar->mutex); 1016 1019 skb_queue_purge(&ar->global_tx_status_waste); 1017 1020 skb_queue_purge(&ar->global_tx_status); 1018 1021 ··· 1303 1306 1304 1307 mutex_lock(&ar->mutex); 1305 1308 1306 - if (changed & IEEE80211_CONF_CHANGE_RADIO_ENABLED) { 1307 - /* TODO */ 1308 - err = 0; 1309 - } 1310 - 1311 1309 if (changed & IEEE80211_CONF_CHANGE_LISTEN_INTERVAL) { 1312 1310 /* TODO */ 1313 1311 err = 0; ··· 1336 1344 } 1337 1345 1338 1346 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) { 1347 + 1348 + /* adjust slot time for 5 GHz */ 1349 + err = ar9170_set_slot_time(ar); 1350 + if (err) 1351 + goto out; 1352 + 1353 + err = ar9170_set_dyn_sifs_ack(ar); 1354 + if (err) 1355 + goto out; 1356 + 1339 1357 err = ar9170_set_channel(ar, hw->conf.channel, 1340 1358 AR9170_RFI_NONE, 1341 1359 nl80211_to_ar9170(hw->conf.channel_type)); 1342 1360 if (err) 1343 1361 goto out; 1344 - /* adjust slot time for 5 GHz */ 1345 - if (hw->conf.channel->band == IEEE80211_BAND_5GHZ) 1346 - err = ar9170_write_reg(ar, AR9170_MAC_REG_SLOT_TIME, 1347 - 9 << 10); 1348 1362 } 1349 1363 1350 1364 out: ··· 1368 1370 return ; 1369 1371 1370 1372 mutex_lock(&ar->mutex); 1371 - if (ar->filter_changed & AR9170_FILTER_CHANGED_PROMISC) { 1373 + if (test_and_clear_bit(AR9170_FILTER_CHANGED_MODE, 1374 + &ar->filter_changed)) { 1372 1375 err = ar9170_set_operating_mode(ar); 1373 1376 if (err) 1374 1377 goto unlock; 1375 1378 } 1376 1379 1377 - if (ar->filter_changed & AR9170_FILTER_CHANGED_MULTICAST) { 1380 + if (test_and_clear_bit(AR9170_FILTER_CHANGED_MULTICAST, 1381 + &ar->filter_changed)) { 1378 1382 err = ar9170_update_multicast(ar); 1379 1383 if (err) 1380 1384 goto unlock; 1381 1385 } 1382 1386 1383 - if (ar->filter_changed & AR9170_FILTER_CHANGED_FRAMEFILTER) 1387 + if (test_and_clear_bit(AR9170_FILTER_CHANGED_FRAMEFILTER, 1388 + &ar->filter_changed)) { 1384 1389 err = ar9170_update_frame_filter(ar); 1390 + if (err) 1391 + goto unlock; 1392 + } 1385 1393 1386 1394 unlock: 1387 1395 mutex_unlock(&ar->mutex); ··· 1417 1413 int i; 1418 1414 1419 1415 /* always get broadcast frames */ 1420 - mchash = 1ULL << (0xff>>2); 1416 + mchash = 1ULL << (0xff >> 2); 1421 1417 1422 1418 for (i = 0; i < mc_count; i++) { 1423 1419 if (WARN_ON(!mclist)) ··· 1427 1423 } 1428 1424 ar->want_mc_hash = mchash; 1429 1425 } 1430 - ar->filter_changed |= AR9170_FILTER_CHANGED_MULTICAST; 1426 + set_bit(AR9170_FILTER_CHANGED_MULTICAST, &ar->filter_changed); 1431 1427 } 1432 1428 1433 1429 if (changed_flags & FIF_CONTROL) { ··· 1443 1439 else 1444 1440 ar->want_filter = ar->cur_filter & ~filter; 1445 1441 1446 - ar->filter_changed |= AR9170_FILTER_CHANGED_FRAMEFILTER; 1442 + set_bit(AR9170_FILTER_CHANGED_FRAMEFILTER, 1443 + &ar->filter_changed); 1447 1444 } 1448 1445 1449 1446 if (changed_flags & FIF_PROMISC_IN_BSS) { 1450 1447 ar->sniffer_enabled = ((*new_flags) & FIF_PROMISC_IN_BSS) != 0; 1451 - ar->filter_changed |= AR9170_FILTER_CHANGED_PROMISC; 1448 + set_bit(AR9170_FILTER_CHANGED_MODE, 1449 + &ar->filter_changed); 1452 1450 } 1453 1451 1454 1452 if (likely(IS_STARTED(ar))) ··· 1470 1464 if (changed & BSS_CHANGED_BSSID) { 1471 1465 memcpy(ar->bssid, bss_conf->bssid, ETH_ALEN); 1472 1466 err = ar9170_set_operating_mode(ar); 1467 + if (err) 1468 + goto out; 1473 1469 } 1474 1470 1475 1471 if (changed & (BSS_CHANGED_BEACON | BSS_CHANGED_BEACON_ENABLED)) { 1476 1472 err = ar9170_update_beacon(ar); 1477 - if (!err) 1478 - ar9170_set_beacon_timers(ar); 1473 + if (err) 1474 + goto out; 1475 + 1476 + err = ar9170_set_beacon_timers(ar); 1477 + if (err) 1478 + goto out; 1479 1479 } 1480 1480 1481 - ar9170_regwrite_begin(ar); 1482 - 1483 1481 if (changed & BSS_CHANGED_ASSOC) { 1484 - ar->state = bss_conf->assoc ? AR9170_ASSOCIATED : ar->state; 1485 - 1486 1482 #ifndef CONFIG_AR9170_LEDS 1487 1483 /* enable assoc LED. */ 1488 1484 err = ar9170_set_leds_state(ar, bss_conf->assoc ? 2 : 0); 1489 1485 #endif /* CONFIG_AR9170_LEDS */ 1490 1486 } 1491 1487 1492 - if (changed & BSS_CHANGED_BEACON_INT) 1488 + if (changed & BSS_CHANGED_BEACON_INT) { 1493 1489 err = ar9170_set_beacon_timers(ar); 1490 + if (err) 1491 + goto out; 1492 + } 1494 1493 1495 1494 if (changed & BSS_CHANGED_HT) { 1496 1495 /* TODO */ ··· 1503 1492 } 1504 1493 1505 1494 if (changed & BSS_CHANGED_ERP_SLOT) { 1506 - u32 slottime = 20; 1507 - 1508 - if (bss_conf->use_short_slot) 1509 - slottime = 9; 1510 - 1511 - ar9170_regwrite(AR9170_MAC_REG_SLOT_TIME, slottime << 10); 1495 + err = ar9170_set_slot_time(ar); 1496 + if (err) 1497 + goto out; 1512 1498 } 1513 1499 1514 1500 if (changed & BSS_CHANGED_BASIC_RATES) { 1515 - u32 cck, ofdm; 1516 - 1517 - if (hw->conf.channel->band == IEEE80211_BAND_5GHZ) { 1518 - ofdm = bss_conf->basic_rates; 1519 - cck = 0; 1520 - } else { 1521 - /* four cck rates */ 1522 - cck = bss_conf->basic_rates & 0xf; 1523 - ofdm = bss_conf->basic_rates >> 4; 1524 - } 1525 - ar9170_regwrite(AR9170_MAC_REG_BASIC_RATE, 1526 - ofdm << 8 | cck); 1501 + err = ar9170_set_basic_rates(ar); 1502 + if (err) 1503 + goto out; 1527 1504 } 1528 1505 1529 - ar9170_regwrite_finish(); 1530 - err = ar9170_regwrite_result(); 1506 + out: 1531 1507 mutex_unlock(&ar->mutex); 1532 1508 } 1533 1509
+3 -3
drivers/net/wireless/ath/ar9170/phy.c
··· 401 401 int i, err; 402 402 u32 val; 403 403 bool is_2ghz = band == IEEE80211_BAND_2GHZ; 404 - bool is_40mhz = false; /* XXX: for now */ 404 + bool is_40mhz = conf_is_ht40(&ar->hw->conf); 405 405 406 406 ar9170_regwrite_begin(ar); 407 407 ··· 1200 1200 return -ENOSYS; 1201 1201 } 1202 1202 1203 - if (0 /* 2 streams capable */) 1203 + if (ar->eeprom.tx_mask != 1) 1204 1204 tmp |= 0x100; 1205 1205 1206 1206 err = ar9170_write_reg(ar, 0x1c5804, tmp); ··· 1214 1214 freqpar = ar9170_get_hw_dyn_params(channel, bw); 1215 1215 1216 1216 vals[0] = cpu_to_le32(channel->center_freq * 1000); 1217 - vals[1] = cpu_to_le32(bw == AR9170_BW_20 ? 0 : 1); 1217 + vals[1] = cpu_to_le32(conf_is_ht40(&ar->hw->conf)); 1218 1218 vals[2] = cpu_to_le32(offs << 2 | 1); 1219 1219 vals[3] = cpu_to_le32(freqpar->coeff_exp); 1220 1220 vals[4] = cpu_to_le32(freqpar->coeff_man);
+50 -19
drivers/net/wireless/ath/ar9170/usb.c
··· 51 51 MODULE_AUTHOR("Christian Lamparter <chunkeey@web.de>"); 52 52 MODULE_LICENSE("GPL"); 53 53 MODULE_DESCRIPTION("Atheros AR9170 802.11n USB wireless"); 54 + MODULE_FIRMWARE("ar9170.fw"); 54 55 MODULE_FIRMWARE("ar9170-1.fw"); 55 56 MODULE_FIRMWARE("ar9170-2.fw"); 57 + 58 + enum ar9170_requirements { 59 + AR9170_REQ_FW1_ONLY = 1, 60 + }; 56 61 57 62 static struct usb_device_id ar9170_usb_ids[] = { 58 63 /* Atheros 9170 */ ··· 86 81 { USB_DEVICE(0x2019, 0x5304) }, 87 82 /* IO-Data WNGDNUS2 */ 88 83 { USB_DEVICE(0x04bb, 0x093f) }, 84 + /* AVM FRITZ!WLAN USB Stick N */ 85 + { USB_DEVICE(0x057C, 0x8401) }, 86 + /* AVM FRITZ!WLAN USB Stick N 2.4 */ 87 + { USB_DEVICE(0x057C, 0x8402), .driver_info = AR9170_REQ_FW1_ONLY }, 89 88 90 89 /* terminate */ 91 90 {} ··· 102 93 struct ar9170_usb *aru = (struct ar9170_usb *) 103 94 usb_get_intfdata(usb_ifnum_to_if(urb->dev, 0)); 104 95 105 - if (!aru) { 96 + if (unlikely(!aru)) { 106 97 dev_kfree_skb_irq(skb); 107 98 return ; 108 99 } ··· 135 126 goto resubmit; 136 127 } 137 128 138 - print_hex_dump_bytes("ar9170 irq: ", DUMP_PREFIX_OFFSET, 139 - urb->transfer_buffer, urb->actual_length); 129 + ar9170_handle_command_response(&aru->common, urb->transfer_buffer, 130 + urb->actual_length); 140 131 141 132 resubmit: 142 133 usb_anchor_urb(urb, &aru->rx_submitted); ··· 186 177 187 178 usb_anchor_urb(urb, &aru->rx_submitted); 188 179 err = usb_submit_urb(urb, GFP_ATOMIC); 189 - if (err) { 180 + if (unlikely(err)) { 190 181 usb_unanchor_urb(urb); 191 - dev_kfree_skb_irq(skb); 182 + goto free; 192 183 } 193 184 194 185 return ; 195 186 196 187 free: 197 188 dev_kfree_skb_irq(skb); 198 - return; 199 189 } 200 190 201 191 static int ar9170_usb_prep_rx_urb(struct ar9170_usb *aru, ··· 345 337 346 338 usb_anchor_urb(urb, &aru->tx_submitted); 347 339 err = usb_submit_urb(urb, GFP_ATOMIC); 348 - if (err) { 340 + if (unlikely(err)) { 349 341 usb_unanchor_urb(urb); 350 342 usb_free_urb(urb); 351 343 goto err_unbuf; ··· 426 418 unsigned long flags; 427 419 u32 in, out; 428 420 429 - if (!buffer) 421 + if (unlikely(!buffer)) 430 422 return ; 431 423 432 424 in = le32_to_cpup((__le32 *)buffer); ··· 512 504 { 513 505 int err = 0; 514 506 507 + err = request_firmware(&aru->firmware, "ar9170.fw", 508 + &aru->udev->dev); 509 + if (!err) { 510 + aru->init_values = NULL; 511 + return 0; 512 + } 513 + 514 + if (aru->req_one_stage_fw) { 515 + dev_err(&aru->udev->dev, "ar9170.fw firmware file " 516 + "not found and is required for this device\n"); 517 + return -EINVAL; 518 + } 519 + 520 + dev_err(&aru->udev->dev, "ar9170.fw firmware file " 521 + "not found, trying old firmware...\n"); 522 + 515 523 err = request_firmware(&aru->init_values, "ar9170-1.fw", 516 524 &aru->udev->dev); 517 - if (err) { 518 - dev_err(&aru->udev->dev, "file with init values not found.\n"); 519 - return err; 520 - } 521 525 522 526 err = request_firmware(&aru->firmware, "ar9170-2.fw", &aru->udev->dev); 523 527 if (err) { 524 528 release_firmware(aru->init_values); 525 - dev_err(&aru->udev->dev, "firmware file not found.\n"); 529 + dev_err(&aru->udev->dev, "file with init values not found.\n"); 526 530 return err; 527 531 } 528 532 ··· 568 548 { 569 549 int err; 570 550 551 + if (!aru->init_values) 552 + goto upload_fw_start; 553 + 571 554 /* First, upload initial values to device RAM */ 572 555 err = ar9170_usb_upload(aru, aru->init_values->data, 573 556 aru->init_values->size, 0x102800, false); ··· 579 556 "upload failed (%d).\n", err); 580 557 return err; 581 558 } 559 + 560 + upload_fw_start: 582 561 583 562 /* Then, upload the firmware itself and start it */ 584 563 return ar9170_usb_upload(aru, aru->firmware->data, aru->firmware->size, ··· 681 656 return err; 682 657 } 683 658 659 + static bool ar9170_requires_one_stage(const struct usb_device_id *id) 660 + { 661 + if (!id->driver_info) 662 + return false; 663 + if (id->driver_info == AR9170_REQ_FW1_ONLY) 664 + return true; 665 + return false; 666 + } 667 + 684 668 static int ar9170_usb_probe(struct usb_interface *intf, 685 669 const struct usb_device_id *id) 686 670 { ··· 710 676 aru->intf = intf; 711 677 ar = &aru->common; 712 678 679 + aru->req_one_stage_fw = ar9170_requires_one_stage(id); 680 + 713 681 usb_set_intfdata(intf, aru); 714 682 SET_IEEE80211_DEV(ar->hw, &udev->dev); 715 683 ··· 727 691 728 692 #ifdef CONFIG_PM 729 693 udev->reset_resume = 1; 730 - #endif 694 + #endif /* CONFIG_PM */ 731 695 err = ar9170_usb_reset(aru); 732 696 if (err) 733 697 goto err_freehw; ··· 811 775 812 776 usb_unpoison_anchored_urbs(&aru->rx_submitted); 813 777 usb_unpoison_anchored_urbs(&aru->tx_submitted); 814 - 815 - /* 816 - * FIXME: firmware upload will fail on resume. 817 - * but this is better than a hang! 818 - */ 819 778 820 779 err = ar9170_usb_init_device(aru); 821 780 if (err)
+2
drivers/net/wireless/ath/ar9170/usb.h
··· 62 62 struct usb_anchor rx_submitted; 63 63 struct usb_anchor tx_submitted; 64 64 65 + bool req_one_stage_fw; 66 + 65 67 spinlock_t cmdlock; 66 68 struct completion cmd_wait; 67 69 int readlen;
+19 -5
drivers/net/wireless/ath/ath5k/base.c
··· 2070 2070 return ret; 2071 2071 } 2072 2072 2073 + static void ath5k_beacon_disable(struct ath5k_softc *sc) 2074 + { 2075 + sc->imask &= ~(AR5K_INT_BMISS | AR5K_INT_SWBA); 2076 + ath5k_hw_set_imr(sc->ah, sc->imask); 2077 + ath5k_hw_stop_tx_dma(sc->ah, sc->bhalq); 2078 + } 2079 + 2073 2080 /* 2074 2081 * Transmit a beacon frame at SWBA. Dynamic updates to the 2075 2082 * frame contents are done as needed and the slot time is ··· 2764 2757 goto end; 2765 2758 2766 2759 ath5k_hw_set_lladdr(sc->ah, mac); 2760 + ath5k_beacon_disable(sc); 2767 2761 sc->vif = NULL; 2768 2762 end: 2769 2763 mutex_unlock(&sc->lock); ··· 2783 2775 2784 2776 mutex_lock(&sc->lock); 2785 2777 2786 - sc->bintval = conf->beacon_int; 2787 - 2788 2778 ret = ath5k_chan_set(sc, conf->channel); 2789 2779 if (ret < 0) 2790 - return ret; 2780 + goto unlock; 2791 2781 2792 2782 if ((changed & IEEE80211_CONF_CHANGE_POWER) && 2793 2783 (sc->power_level != conf->power_level)) { ··· 2814 2808 */ 2815 2809 ath5k_hw_set_antenna_mode(ah, AR5K_ANTMODE_DEFAULT); 2816 2810 2811 + unlock: 2817 2812 mutex_unlock(&sc->lock); 2818 - return 0; 2813 + return ret; 2819 2814 } 2820 2815 2821 2816 #define SUPPORTED_FIF_FLAGS \ ··· 3068 3061 { 3069 3062 int ret; 3070 3063 struct ath5k_softc *sc = hw->priv; 3071 - struct sk_buff *skb = ieee80211_beacon_get(hw, vif); 3064 + struct sk_buff *skb; 3065 + 3066 + if (WARN_ON(!vif)) { 3067 + ret = -EINVAL; 3068 + goto out; 3069 + } 3070 + 3071 + skb = ieee80211_beacon_get(hw, vif); 3072 3072 3073 3073 if (!skb) { 3074 3074 ret = -ENOMEM;
+1 -6
drivers/net/wireless/ath/ath9k/ath9k.h
··· 460 460 bool registered; 461 461 }; 462 462 463 - /* Rfkill */ 464 - #define ATH_RFKILL_POLL_INTERVAL 2000 /* msecs */ 465 - 466 463 struct ath_rfkill { 467 464 struct rfkill *rfkill; 468 - struct delayed_work rfkill_poll; 465 + struct rfkill_ops ops; 469 466 char rfkill_name[32]; 470 467 }; 471 468 ··· 506 509 #define SC_OP_RXFLUSH BIT(7) 507 510 #define SC_OP_LED_ASSOCIATED BIT(8) 508 511 #define SC_OP_RFKILL_REGISTERED BIT(9) 509 - #define SC_OP_RFKILL_SW_BLOCKED BIT(10) 510 - #define SC_OP_RFKILL_HW_BLOCKED BIT(11) 511 512 #define SC_OP_WAIT_FOR_BEACON BIT(12) 512 513 #define SC_OP_LED_ON BIT(13) 513 514 #define SC_OP_SCANNING BIT(14)
+9
drivers/net/wireless/ath/ath9k/beacon.c
··· 411 411 } else if (sc->beacon.bmisscnt >= BSTUCK_THRESH) { 412 412 DPRINTF(sc, ATH_DBG_BEACON, 413 413 "beacon is officially stuck\n"); 414 + sc->sc_flags |= SC_OP_TSF_RESET; 414 415 ath_reset(sc, false); 415 416 } 416 417 ··· 673 672 u32 tsftu, intval, nexttbtt; 674 673 675 674 intval = conf->beacon_interval & ATH9K_BEACON_PERIOD; 675 + 676 + /* 677 + * It looks like mac80211 may end up using beacon interval of zero in 678 + * some cases (at least for mesh point). Avoid getting into an 679 + * infinite loop by using a bit safer value instead.. 680 + */ 681 + if (intval == 0) 682 + intval = 100; 676 683 677 684 /* Pull nexttbtt forward to reflect the current TSF */ 678 685
+79 -80
drivers/net/wireless/ath/ath9k/debug.c
··· 44 44 return 0; 45 45 } 46 46 47 + static ssize_t read_file_debug(struct file *file, char __user *user_buf, 48 + size_t count, loff_t *ppos) 49 + { 50 + struct ath_softc *sc = file->private_data; 51 + char buf[32]; 52 + unsigned int len; 53 + 54 + len = snprintf(buf, sizeof(buf), "0x%08x\n", sc->debug.debug_mask); 55 + return simple_read_from_buffer(user_buf, count, ppos, buf, len); 56 + } 57 + 58 + static ssize_t write_file_debug(struct file *file, const char __user *user_buf, 59 + size_t count, loff_t *ppos) 60 + { 61 + struct ath_softc *sc = file->private_data; 62 + unsigned long mask; 63 + char buf[32]; 64 + ssize_t len; 65 + 66 + len = min(count, sizeof(buf) - 1); 67 + if (copy_from_user(buf, user_buf, len)) 68 + return -EINVAL; 69 + 70 + buf[len] = '\0'; 71 + if (strict_strtoul(buf, 0, &mask)) 72 + return -EINVAL; 73 + 74 + sc->debug.debug_mask = mask; 75 + return count; 76 + } 77 + 78 + static const struct file_operations fops_debug = { 79 + .read = read_file_debug, 80 + .write = write_file_debug, 81 + .open = ath9k_debugfs_open, 82 + .owner = THIS_MODULE 83 + }; 84 + 47 85 static ssize_t read_file_dma(struct file *file, char __user *user_buf, 48 86 size_t count, loff_t *ppos) 49 87 { ··· 262 224 .owner = THIS_MODULE 263 225 }; 264 226 265 - static void ath_debug_stat_11n_rc(struct ath_softc *sc, struct sk_buff *skb) 227 + void ath_debug_stat_rc(struct ath_softc *sc, struct sk_buff *skb) 266 228 { 267 229 struct ath_tx_info_priv *tx_info_priv = NULL; 268 230 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb); 269 231 struct ieee80211_tx_rate *rates = tx_info->status.rates; 270 232 int final_ts_idx, idx; 271 - 272 - tx_info_priv = ATH_TX_INFO_PRIV(tx_info); 273 - final_ts_idx = tx_info_priv->tx.ts_rateindex; 274 - idx = sc->cur_rate_table->info[rates[final_ts_idx].idx].dot11rate; 275 - 276 - sc->debug.stats.n_rcstats[idx].success++; 277 - } 278 - 279 - static void ath_debug_stat_legacy_rc(struct ath_softc *sc, struct sk_buff *skb) 280 - { 281 - struct ath_tx_info_priv *tx_info_priv = NULL; 282 - struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb); 283 - struct ieee80211_tx_rate *rates = tx_info->status.rates; 284 - int final_ts_idx, idx; 233 + struct ath_rc_stats *stats; 285 234 286 235 tx_info_priv = ATH_TX_INFO_PRIV(tx_info); 287 236 final_ts_idx = tx_info_priv->tx.ts_rateindex; 288 237 idx = rates[final_ts_idx].idx; 289 - 290 - sc->debug.stats.legacy_rcstats[idx].success++; 238 + stats = &sc->debug.stats.rcstats[idx]; 239 + stats->success++; 291 240 } 292 241 293 - void ath_debug_stat_rc(struct ath_softc *sc, struct sk_buff *skb) 294 - { 295 - if (conf_is_ht(&sc->hw->conf)) 296 - ath_debug_stat_11n_rc(sc, skb); 297 - else 298 - ath_debug_stat_legacy_rc(sc, skb); 299 - } 300 - 301 - /* FIXME: legacy rates, later on .. */ 302 242 void ath_debug_stat_retries(struct ath_softc *sc, int rix, 303 243 int xretries, int retries, u8 per) 304 244 { 305 - if (conf_is_ht(&sc->hw->conf)) { 306 - int idx = sc->cur_rate_table->info[rix].dot11rate; 245 + struct ath_rc_stats *stats = &sc->debug.stats.rcstats[rix]; 307 246 308 - sc->debug.stats.n_rcstats[idx].xretries += xretries; 309 - sc->debug.stats.n_rcstats[idx].retries += retries; 310 - sc->debug.stats.n_rcstats[idx].per = per; 311 - } 312 - } 313 - 314 - static ssize_t ath_read_file_stat_11n_rc(struct file *file, 315 - char __user *user_buf, 316 - size_t count, loff_t *ppos) 317 - { 318 - struct ath_softc *sc = file->private_data; 319 - char buf[1024]; 320 - unsigned int len = 0; 321 - int i = 0; 322 - 323 - len += sprintf(buf, "%7s %13s %8s %8s %6s\n\n", "Rate", "Success", 324 - "Retries", "XRetries", "PER"); 325 - 326 - for (i = 0; i <= 15; i++) { 327 - len += snprintf(buf + len, sizeof(buf) - len, 328 - "%5s%3d: %8u %8u %8u %8u\n", "MCS", i, 329 - sc->debug.stats.n_rcstats[i].success, 330 - sc->debug.stats.n_rcstats[i].retries, 331 - sc->debug.stats.n_rcstats[i].xretries, 332 - sc->debug.stats.n_rcstats[i].per); 333 - } 334 - 335 - return simple_read_from_buffer(user_buf, count, ppos, buf, len); 336 - } 337 - 338 - static ssize_t ath_read_file_stat_legacy_rc(struct file *file, 339 - char __user *user_buf, 340 - size_t count, loff_t *ppos) 341 - { 342 - struct ath_softc *sc = file->private_data; 343 - char buf[512]; 344 - unsigned int len = 0; 345 - int i = 0; 346 - 347 - len += sprintf(buf, "%7s %13s\n\n", "Rate", "Success"); 348 - 349 - for (i = 0; i < sc->cur_rate_table->rate_cnt; i++) { 350 - len += snprintf(buf + len, sizeof(buf) - len, "%5u: %12u\n", 351 - sc->cur_rate_table->info[i].ratekbps / 1000, 352 - sc->debug.stats.legacy_rcstats[i].success); 353 - } 354 - 355 - return simple_read_from_buffer(user_buf, count, ppos, buf, len); 247 + stats->xretries += xretries; 248 + stats->retries += retries; 249 + stats->per = per; 356 250 } 357 251 358 252 static ssize_t read_file_rcstat(struct file *file, char __user *user_buf, 359 253 size_t count, loff_t *ppos) 360 254 { 361 255 struct ath_softc *sc = file->private_data; 256 + char *buf; 257 + unsigned int len = 0, max; 258 + int i = 0; 259 + ssize_t retval; 362 260 363 261 if (sc->cur_rate_table == NULL) 364 262 return 0; 365 263 366 - if (conf_is_ht(&sc->hw->conf)) 367 - return ath_read_file_stat_11n_rc(file, user_buf, count, ppos); 368 - else 369 - return ath_read_file_stat_legacy_rc(file, user_buf, count ,ppos); 264 + max = 80 + sc->cur_rate_table->rate_cnt * 64; 265 + buf = kmalloc(max + 1, GFP_KERNEL); 266 + if (buf == NULL) 267 + return 0; 268 + buf[max] = 0; 269 + 270 + len += sprintf(buf, "%5s %15s %8s %9s %3s\n\n", "Rate", "Success", 271 + "Retries", "XRetries", "PER"); 272 + 273 + for (i = 0; i < sc->cur_rate_table->rate_cnt; i++) { 274 + u32 ratekbps = sc->cur_rate_table->info[i].ratekbps; 275 + struct ath_rc_stats *stats = &sc->debug.stats.rcstats[i]; 276 + 277 + len += snprintf(buf + len, max - len, 278 + "%3u.%d: %8u %8u %8u %8u\n", ratekbps / 1000, 279 + (ratekbps % 1000) / 100, stats->success, 280 + stats->retries, stats->xretries, 281 + stats->per); 282 + } 283 + 284 + retval = simple_read_from_buffer(user_buf, count, ppos, buf, len); 285 + kfree(buf); 286 + return retval; 370 287 } 371 288 372 289 static const struct file_operations fops_rcstat = { ··· 499 506 if (!sc->debug.debugfs_phy) 500 507 goto err; 501 508 509 + sc->debug.debugfs_debug = debugfs_create_file("debug", 510 + S_IRUGO | S_IWUSR, sc->debug.debugfs_phy, sc, &fops_debug); 511 + if (!sc->debug.debugfs_debug) 512 + goto err; 513 + 502 514 sc->debug.debugfs_dma = debugfs_create_file("dma", S_IRUGO, 503 515 sc->debug.debugfs_phy, sc, &fops_dma); 504 516 if (!sc->debug.debugfs_dma) ··· 541 543 debugfs_remove(sc->debug.debugfs_rcstat); 542 544 debugfs_remove(sc->debug.debugfs_interrupt); 543 545 debugfs_remove(sc->debug.debugfs_dma); 546 + debugfs_remove(sc->debug.debugfs_debug); 544 547 debugfs_remove(sc->debug.debugfs_phy); 545 548 } 546 549
+3 -7
drivers/net/wireless/ath/ath9k/debug.h
··· 80 80 u32 dtim; 81 81 }; 82 82 83 - struct ath_legacy_rc_stats { 84 - u32 success; 85 - }; 86 - 87 - struct ath_11n_rc_stats { 83 + struct ath_rc_stats { 88 84 u32 success; 89 85 u32 retries; 90 86 u32 xretries; ··· 89 93 90 94 struct ath_stats { 91 95 struct ath_interrupt_stats istats; 92 - struct ath_legacy_rc_stats legacy_rcstats[12]; /* max(11a,11b,11g) */ 93 - struct ath_11n_rc_stats n_rcstats[16]; /* 0..15 MCS rates */ 96 + struct ath_rc_stats rcstats[RATE_TABLE_SIZE]; 94 97 }; 95 98 96 99 struct ath9k_debug { 97 100 int debug_mask; 98 101 struct dentry *debugfs_phy; 102 + struct dentry *debugfs_debug; 99 103 struct dentry *debugfs_dma; 100 104 struct dentry *debugfs_interrupt; 101 105 struct dentry *debugfs_rcstat;
+34 -91
drivers/net/wireless/ath/ath9k/main.c
··· 1192 1192 ah->rfkill_polarity; 1193 1193 } 1194 1194 1195 - /* h/w rfkill poll function */ 1196 - static void ath_rfkill_poll(struct work_struct *work) 1197 - { 1198 - struct ath_softc *sc = container_of(work, struct ath_softc, 1199 - rf_kill.rfkill_poll.work); 1200 - bool radio_on; 1201 - 1202 - if (sc->sc_flags & SC_OP_INVALID) 1203 - return; 1204 - 1205 - radio_on = !ath_is_rfkill_set(sc); 1206 - 1207 - /* 1208 - * enable/disable radio only when there is a 1209 - * state change in RF switch 1210 - */ 1211 - if (radio_on == !!(sc->sc_flags & SC_OP_RFKILL_HW_BLOCKED)) { 1212 - enum rfkill_state state; 1213 - 1214 - if (sc->sc_flags & SC_OP_RFKILL_SW_BLOCKED) { 1215 - state = radio_on ? RFKILL_STATE_SOFT_BLOCKED 1216 - : RFKILL_STATE_HARD_BLOCKED; 1217 - } else if (radio_on) { 1218 - ath_radio_enable(sc); 1219 - state = RFKILL_STATE_UNBLOCKED; 1220 - } else { 1221 - ath_radio_disable(sc); 1222 - state = RFKILL_STATE_HARD_BLOCKED; 1223 - } 1224 - 1225 - if (state == RFKILL_STATE_HARD_BLOCKED) 1226 - sc->sc_flags |= SC_OP_RFKILL_HW_BLOCKED; 1227 - else 1228 - sc->sc_flags &= ~SC_OP_RFKILL_HW_BLOCKED; 1229 - 1230 - rfkill_force_state(sc->rf_kill.rfkill, state); 1231 - } 1232 - 1233 - queue_delayed_work(sc->hw->workqueue, &sc->rf_kill.rfkill_poll, 1234 - msecs_to_jiffies(ATH_RFKILL_POLL_INTERVAL)); 1235 - } 1236 - 1237 - /* s/w rfkill handler */ 1238 - static int ath_sw_toggle_radio(void *data, enum rfkill_state state) 1195 + /* s/w rfkill handlers */ 1196 + static int ath_rfkill_set_block(void *data, bool blocked) 1239 1197 { 1240 1198 struct ath_softc *sc = data; 1241 1199 1242 - switch (state) { 1243 - case RFKILL_STATE_SOFT_BLOCKED: 1244 - if (!(sc->sc_flags & (SC_OP_RFKILL_HW_BLOCKED | 1245 - SC_OP_RFKILL_SW_BLOCKED))) 1246 - ath_radio_disable(sc); 1247 - sc->sc_flags |= SC_OP_RFKILL_SW_BLOCKED; 1248 - return 0; 1249 - case RFKILL_STATE_UNBLOCKED: 1250 - if ((sc->sc_flags & SC_OP_RFKILL_SW_BLOCKED)) { 1251 - sc->sc_flags &= ~SC_OP_RFKILL_SW_BLOCKED; 1252 - if (sc->sc_flags & SC_OP_RFKILL_HW_BLOCKED) { 1253 - DPRINTF(sc, ATH_DBG_FATAL, "Can't turn on the" 1254 - "radio as it is disabled by h/w\n"); 1255 - return -EPERM; 1256 - } 1257 - ath_radio_enable(sc); 1258 - } 1259 - return 0; 1260 - default: 1261 - return -EINVAL; 1262 - } 1200 + if (blocked) 1201 + ath_radio_disable(sc); 1202 + else 1203 + ath_radio_enable(sc); 1204 + 1205 + return 0; 1206 + } 1207 + 1208 + static void ath_rfkill_poll_state(struct rfkill *rfkill, void *data) 1209 + { 1210 + struct ath_softc *sc = data; 1211 + bool blocked = !!ath_is_rfkill_set(sc); 1212 + 1213 + if (rfkill_set_hw_state(rfkill, blocked)) 1214 + ath_radio_disable(sc); 1215 + else 1216 + ath_radio_enable(sc); 1263 1217 } 1264 1218 1265 1219 /* Init s/w rfkill */ 1266 1220 static int ath_init_sw_rfkill(struct ath_softc *sc) 1267 1221 { 1268 - sc->rf_kill.rfkill = rfkill_allocate(wiphy_dev(sc->hw->wiphy), 1269 - RFKILL_TYPE_WLAN); 1222 + sc->rf_kill.ops.set_block = ath_rfkill_set_block; 1223 + if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT) 1224 + sc->rf_kill.ops.poll = ath_rfkill_poll_state; 1225 + 1226 + snprintf(sc->rf_kill.rfkill_name, sizeof(sc->rf_kill.rfkill_name), 1227 + "ath9k-%s::rfkill", wiphy_name(sc->hw->wiphy)); 1228 + 1229 + sc->rf_kill.rfkill = rfkill_alloc(sc->rf_kill.rfkill_name, 1230 + wiphy_dev(sc->hw->wiphy), 1231 + RFKILL_TYPE_WLAN, 1232 + &sc->rf_kill.ops, sc); 1270 1233 if (!sc->rf_kill.rfkill) { 1271 1234 DPRINTF(sc, ATH_DBG_FATAL, "Failed to allocate rfkill\n"); 1272 1235 return -ENOMEM; 1273 1236 } 1274 - 1275 - snprintf(sc->rf_kill.rfkill_name, sizeof(sc->rf_kill.rfkill_name), 1276 - "ath9k-%s::rfkill", wiphy_name(sc->hw->wiphy)); 1277 - sc->rf_kill.rfkill->name = sc->rf_kill.rfkill_name; 1278 - sc->rf_kill.rfkill->data = sc; 1279 - sc->rf_kill.rfkill->toggle_radio = ath_sw_toggle_radio; 1280 - sc->rf_kill.rfkill->state = RFKILL_STATE_UNBLOCKED; 1281 1237 1282 1238 return 0; 1283 1239 } ··· 1241 1285 /* Deinitialize rfkill */ 1242 1286 static void ath_deinit_rfkill(struct ath_softc *sc) 1243 1287 { 1244 - if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT) 1245 - cancel_delayed_work_sync(&sc->rf_kill.rfkill_poll); 1246 - 1247 1288 if (sc->sc_flags & SC_OP_RFKILL_REGISTERED) { 1248 1289 rfkill_unregister(sc->rf_kill.rfkill); 1290 + rfkill_destroy(sc->rf_kill.rfkill); 1249 1291 sc->sc_flags &= ~SC_OP_RFKILL_REGISTERED; 1250 - sc->rf_kill.rfkill = NULL; 1251 1292 } 1252 1293 } 1253 1294 1254 1295 static int ath_start_rfkill_poll(struct ath_softc *sc) 1255 1296 { 1256 - if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT) 1257 - queue_delayed_work(sc->hw->workqueue, 1258 - &sc->rf_kill.rfkill_poll, 0); 1259 - 1260 1297 if (!(sc->sc_flags & SC_OP_RFKILL_REGISTERED)) { 1261 1298 if (rfkill_register(sc->rf_kill.rfkill)) { 1262 1299 DPRINTF(sc, ATH_DBG_FATAL, 1263 1300 "Unable to register rfkill\n"); 1264 - rfkill_free(sc->rf_kill.rfkill); 1301 + rfkill_destroy(sc->rf_kill.rfkill); 1265 1302 1266 1303 /* Deinitialize the device */ 1267 1304 ath_cleanup(sc); ··· 1627 1678 goto error_attach; 1628 1679 1629 1680 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE) 1630 - /* Initialze h/w Rfkill */ 1631 - if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT) 1632 - INIT_DELAYED_WORK(&sc->rf_kill.rfkill_poll, ath_rfkill_poll); 1633 - 1634 1681 /* Initialize s/w rfkill */ 1635 1682 error = ath_init_sw_rfkill(sc); 1636 1683 if (error) ··· 2159 2214 } else 2160 2215 sc->rx.rxlink = NULL; 2161 2216 2162 - #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE) 2163 - if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT) 2164 - cancel_delayed_work_sync(&sc->rf_kill.rfkill_poll); 2165 - #endif 2217 + rfkill_pause_polling(sc->rf_kill.rfkill); 2218 + 2166 2219 /* disable HAL and put h/w to sleep */ 2167 2220 ath9k_hw_disable(sc->sc_ah); 2168 2221 ath9k_hw_configpcipowersave(sc->sc_ah, 1);
-15
drivers/net/wireless/ath/ath9k/pci.c
··· 227 227 228 228 ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN, 1); 229 229 230 - #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE) 231 - if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT) 232 - cancel_delayed_work_sync(&sc->rf_kill.rfkill_poll); 233 - #endif 234 - 235 230 pci_save_state(pdev); 236 231 pci_disable_device(pdev); 237 232 pci_set_power_state(pdev, PCI_D3hot); ··· 250 255 ath9k_hw_cfg_output(sc->sc_ah, ATH_LED_PIN, 251 256 AR_GPIO_OUTPUT_MUX_AS_OUTPUT); 252 257 ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN, 1); 253 - 254 - #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE) 255 - /* 256 - * check the h/w rfkill state on resume 257 - * and start the rfkill poll timer 258 - */ 259 - if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT) 260 - queue_delayed_work(sc->hw->workqueue, 261 - &sc->rf_kill.rfkill_poll, 0); 262 - #endif 263 258 264 259 return 0; 265 260 }
+25 -4
drivers/net/wireless/ath/regd.c
··· 366 366 if (rd & COUNTRY_ERD_FLAG) { 367 367 /* EEPROM value is a country code */ 368 368 u16 cc = rd & ~COUNTRY_ERD_FLAG; 369 + printk(KERN_DEBUG 370 + "ath: EEPROM indicates we should expect " 371 + "a country code\n"); 369 372 for (i = 0; i < ARRAY_SIZE(allCountries); i++) 370 373 if (allCountries[i].countryCode == cc) 371 374 return true; 372 375 } else { 373 376 /* EEPROM value is a regpair value */ 377 + if (rd != CTRY_DEFAULT) 378 + printk(KERN_DEBUG "ath: EEPROM indicates we " 379 + "should expect a direct regpair map\n"); 374 380 for (i = 0; i < ARRAY_SIZE(regDomainPairs); i++) 375 381 if (regDomainPairs[i].regDmnEnum == rd) 376 382 return true; ··· 483 477 struct country_code_to_enum_rd *country = NULL; 484 478 u16 regdmn; 485 479 480 + if (!reg) 481 + return -EINVAL; 482 + 483 + printk(KERN_DEBUG "ath: EEPROM regdomain: 0x%0x\n", reg->current_rd); 484 + 486 485 if (!ath_regd_is_eeprom_valid(reg)) { 487 486 printk(KERN_ERR "ath: Invalid EEPROM contents\n"); 488 487 return -EINVAL; ··· 497 486 reg->country_code = ath_regd_get_default_country(regdmn); 498 487 499 488 if (reg->country_code == CTRY_DEFAULT && 500 - regdmn == CTRY_DEFAULT) 489 + regdmn == CTRY_DEFAULT) { 490 + printk(KERN_DEBUG "ath: EEPROM indicates default " 491 + "country code should be used\n"); 501 492 reg->country_code = CTRY_UNITED_STATES; 493 + } 502 494 503 495 if (reg->country_code == CTRY_DEFAULT) { 504 496 country = NULL; 505 497 } else { 498 + printk(KERN_DEBUG "ath: doing EEPROM country->regdmn " 499 + "map search\n"); 506 500 country = ath_regd_find_country(reg->country_code); 507 501 if (country == NULL) { 508 502 printk(KERN_DEBUG 509 - "ath: Country is NULL!!!!, cc= %d\n", 503 + "ath: no valid country maps found for " 504 + "country code: 0x%0x\n", 510 505 reg->country_code); 511 506 return -EINVAL; 512 - } else 507 + } else { 513 508 regdmn = country->regDmnEnum; 509 + printk(KERN_DEBUG "ath: country maps to " 510 + "regdmn code: 0x%0x\n", 511 + regdmn); 512 + } 514 513 } 515 514 516 515 reg->regpair = ath_get_regpair(regdmn); ··· 544 523 545 524 printk(KERN_DEBUG "ath: Country alpha2 being used: %c%c\n", 546 525 reg->alpha2[0], reg->alpha2[1]); 547 - printk(KERN_DEBUG "ath: Regpair detected: 0x%0x\n", 526 + printk(KERN_DEBUG "ath: Regpair used: 0x%0x\n", 548 527 reg->regpair->regDmnEnum); 549 528 550 529 ath_regd_init_wiphy(reg, wiphy, reg_notifier);
+1 -1
drivers/net/wireless/b43/Kconfig
··· 102 102 # if it's possible. 103 103 config B43_RFKILL 104 104 bool 105 - depends on B43 && (RFKILL = y || RFKILL = B43) && RFKILL_INPUT && (INPUT_POLLDEV = y || INPUT_POLLDEV = B43) 105 + depends on B43 && (RFKILL = y || RFKILL = B43) 106 106 default y 107 107 108 108 # This config option automatically enables b43 HW-RNG support,
+1 -1
drivers/net/wireless/b43/leds.c
··· 87 87 } 88 88 89 89 static int b43_register_led(struct b43_wldev *dev, struct b43_led *led, 90 - const char *name, char *default_trigger, 90 + const char *name, const char *default_trigger, 91 91 u8 led_index, bool activelow) 92 92 { 93 93 int err;
+2 -2
drivers/net/wireless/b43/main.c
··· 3470 3470 3471 3471 if (!!conf->radio_enabled != phy->radio_on) { 3472 3472 if (conf->radio_enabled) { 3473 - b43_software_rfkill(dev, RFKILL_STATE_UNBLOCKED); 3473 + b43_software_rfkill(dev, false); 3474 3474 b43info(dev->wl, "Radio turned on by software\n"); 3475 3475 if (!dev->radio_hw_enable) { 3476 3476 b43info(dev->wl, "The hardware RF-kill button " ··· 3478 3478 "Press the button to turn it on.\n"); 3479 3479 } 3480 3480 } else { 3481 - b43_software_rfkill(dev, RFKILL_STATE_SOFT_BLOCKED); 3481 + b43_software_rfkill(dev, true); 3482 3482 b43info(dev->wl, "Radio turned off by software\n"); 3483 3483 } 3484 3484 }
+2 -2
drivers/net/wireless/b43/phy_a.c
··· 480 480 } 481 481 482 482 static void b43_aphy_op_software_rfkill(struct b43_wldev *dev, 483 - enum rfkill_state state) 483 + bool blocked) 484 484 { 485 485 struct b43_phy *phy = &dev->phy; 486 486 487 - if (state == RFKILL_STATE_UNBLOCKED) { 487 + if (!blocked) { 488 488 if (phy->radio_on) 489 489 return; 490 490 b43_radio_write16(dev, 0x0004, 0x00C0);
+6 -11
drivers/net/wireless/b43/phy_common.c
··· 84 84 85 85 phy->channel = ops->get_default_chan(dev); 86 86 87 - ops->software_rfkill(dev, RFKILL_STATE_UNBLOCKED); 87 + ops->software_rfkill(dev, false); 88 88 err = ops->init(dev); 89 89 if (err) { 90 90 b43err(dev->wl, "PHY init failed\n"); ··· 104 104 if (ops->exit) 105 105 ops->exit(dev); 106 106 err_block_rf: 107 - ops->software_rfkill(dev, RFKILL_STATE_SOFT_BLOCKED); 107 + ops->software_rfkill(dev, true); 108 108 109 109 return err; 110 110 } ··· 113 113 { 114 114 const struct b43_phy_operations *ops = dev->phy.ops; 115 115 116 - ops->software_rfkill(dev, RFKILL_STATE_SOFT_BLOCKED); 116 + ops->software_rfkill(dev, true); 117 117 if (ops->exit) 118 118 ops->exit(dev); 119 119 } ··· 295 295 return err; 296 296 } 297 297 298 - void b43_software_rfkill(struct b43_wldev *dev, enum rfkill_state state) 298 + void b43_software_rfkill(struct b43_wldev *dev, bool blocked) 299 299 { 300 300 struct b43_phy *phy = &dev->phy; 301 301 302 - if (state == RFKILL_STATE_HARD_BLOCKED) { 303 - /* We cannot hardware-block the device */ 304 - state = RFKILL_STATE_SOFT_BLOCKED; 305 - } 306 - 307 302 b43_mac_suspend(dev); 308 - phy->ops->software_rfkill(dev, state); 309 - phy->radio_on = (state == RFKILL_STATE_UNBLOCKED); 303 + phy->ops->software_rfkill(dev, blocked); 304 + phy->radio_on = !blocked; 310 305 b43_mac_enable(dev); 311 306 } 312 307
+2 -2
drivers/net/wireless/b43/phy_common.h
··· 159 159 160 160 /* Radio */ 161 161 bool (*supports_hwpctl)(struct b43_wldev *dev); 162 - void (*software_rfkill)(struct b43_wldev *dev, enum rfkill_state state); 162 + void (*software_rfkill)(struct b43_wldev *dev, bool blocked); 163 163 void (*switch_analog)(struct b43_wldev *dev, bool on); 164 164 int (*switch_channel)(struct b43_wldev *dev, unsigned int new_channel); 165 165 unsigned int (*get_default_chan)(struct b43_wldev *dev); ··· 364 364 /** 365 365 * b43_software_rfkill - Turn the radio ON or OFF in software. 366 366 */ 367 - void b43_software_rfkill(struct b43_wldev *dev, enum rfkill_state state); 367 + void b43_software_rfkill(struct b43_wldev *dev, bool blocked); 368 368 369 369 /** 370 370 * b43_phy_txpower_check - Check TX power output.
+2 -2
drivers/net/wireless/b43/phy_g.c
··· 2592 2592 } 2593 2593 2594 2594 static void b43_gphy_op_software_rfkill(struct b43_wldev *dev, 2595 - enum rfkill_state state) 2595 + bool blocked) 2596 2596 { 2597 2597 struct b43_phy *phy = &dev->phy; 2598 2598 struct b43_phy_g *gphy = phy->g; ··· 2600 2600 2601 2601 might_sleep(); 2602 2602 2603 - if (state == RFKILL_STATE_UNBLOCKED) { 2603 + if (!blocked) { 2604 2604 /* Turn radio ON */ 2605 2605 if (phy->radio_on) 2606 2606 return;
+1 -1
drivers/net/wireless/b43/phy_lp.c
··· 488 488 } 489 489 490 490 static void b43_lpphy_op_software_rfkill(struct b43_wldev *dev, 491 - enum rfkill_state state) 491 + bool blocked) 492 492 { 493 493 //TODO 494 494 }
+1 -1
drivers/net/wireless/b43/phy_n.c
··· 579 579 } 580 580 581 581 static void b43_nphy_op_software_rfkill(struct b43_wldev *dev, 582 - enum rfkill_state state) 582 + bool blocked) 583 583 {//TODO 584 584 } 585 585
+34 -89
drivers/net/wireless/b43/rfkill.c
··· 45 45 } 46 46 47 47 /* The poll callback for the hardware button. */ 48 - static void b43_rfkill_poll(struct input_polled_dev *poll_dev) 48 + static void b43_rfkill_poll(struct rfkill *rfkill, void *data) 49 49 { 50 - struct b43_wldev *dev = poll_dev->private; 50 + struct b43_wldev *dev = data; 51 51 struct b43_wl *wl = dev->wl; 52 52 bool enabled; 53 - bool report_change = 0; 54 53 55 54 mutex_lock(&wl->mutex); 56 55 if (unlikely(b43_status(dev) < B43_STAT_INITIALIZED)) { ··· 59 60 enabled = b43_is_hw_radio_enabled(dev); 60 61 if (unlikely(enabled != dev->radio_hw_enable)) { 61 62 dev->radio_hw_enable = enabled; 62 - report_change = 1; 63 63 b43info(wl, "Radio hardware status changed to %s\n", 64 64 enabled ? "ENABLED" : "DISABLED"); 65 + enabled = !rfkill_set_hw_state(rfkill, !enabled); 66 + if (enabled != dev->phy.radio_on) 67 + b43_software_rfkill(dev, !enabled); 65 68 } 66 69 mutex_unlock(&wl->mutex); 67 - 68 - /* send the radio switch event to the system - note both a key press 69 - * and a release are required */ 70 - if (unlikely(report_change)) { 71 - input_report_key(poll_dev->input, KEY_WLAN, 1); 72 - input_report_key(poll_dev->input, KEY_WLAN, 0); 73 - } 74 70 } 75 71 76 72 /* Called when the RFKILL toggled in software. */ 77 - static int b43_rfkill_soft_toggle(void *data, enum rfkill_state state) 73 + static int b43_rfkill_soft_set(void *data, bool blocked) 78 74 { 79 75 struct b43_wldev *dev = data; 80 76 struct b43_wl *wl = dev->wl; 81 - int err = -EBUSY; 77 + int err = -EINVAL; 82 78 83 - if (!wl->rfkill.registered) 84 - return 0; 79 + if (WARN_ON(!wl->rfkill.registered)) 80 + return -EINVAL; 85 81 86 82 mutex_lock(&wl->mutex); 83 + 87 84 if (b43_status(dev) < B43_STAT_INITIALIZED) 88 85 goto out_unlock; 86 + 87 + if (!dev->radio_hw_enable) 88 + goto out_unlock; 89 + 90 + if (!blocked != dev->phy.radio_on) 91 + b43_software_rfkill(dev, blocked); 89 92 err = 0; 90 - switch (state) { 91 - case RFKILL_STATE_UNBLOCKED: 92 - if (!dev->radio_hw_enable) { 93 - /* No luck. We can't toggle the hardware RF-kill 94 - * button from software. */ 95 - err = -EBUSY; 96 - goto out_unlock; 97 - } 98 - if (!dev->phy.radio_on) 99 - b43_software_rfkill(dev, state); 100 - break; 101 - case RFKILL_STATE_SOFT_BLOCKED: 102 - if (dev->phy.radio_on) 103 - b43_software_rfkill(dev, state); 104 - break; 105 - default: 106 - b43warn(wl, "Received unexpected rfkill state %d.\n", state); 107 - break; 108 - } 109 93 out_unlock: 110 94 mutex_unlock(&wl->mutex); 111 - 112 95 return err; 113 96 } 114 97 115 - char *b43_rfkill_led_name(struct b43_wldev *dev) 98 + const char *b43_rfkill_led_name(struct b43_wldev *dev) 116 99 { 117 100 struct b43_rfkill *rfk = &(dev->wl->rfkill); 118 101 119 102 if (!rfk->registered) 120 103 return NULL; 121 - return rfkill_get_led_name(rfk->rfkill); 104 + return rfkill_get_led_trigger_name(rfk->rfkill); 122 105 } 106 + 107 + static const struct rfkill_ops b43_rfkill_ops = { 108 + .set_block = b43_rfkill_soft_set, 109 + .poll = b43_rfkill_poll, 110 + }; 123 111 124 112 void b43_rfkill_init(struct b43_wldev *dev) 125 113 { ··· 116 130 117 131 rfk->registered = 0; 118 132 119 - rfk->rfkill = rfkill_allocate(dev->dev->dev, RFKILL_TYPE_WLAN); 120 - if (!rfk->rfkill) 121 - goto out_error; 122 133 snprintf(rfk->name, sizeof(rfk->name), 123 134 "b43-%s", wiphy_name(wl->hw->wiphy)); 124 - rfk->rfkill->name = rfk->name; 125 - rfk->rfkill->state = RFKILL_STATE_UNBLOCKED; 126 - rfk->rfkill->data = dev; 127 - rfk->rfkill->toggle_radio = b43_rfkill_soft_toggle; 128 135 129 - rfk->poll_dev = input_allocate_polled_device(); 130 - if (!rfk->poll_dev) { 131 - rfkill_free(rfk->rfkill); 132 - goto err_freed_rfk; 133 - } 134 - 135 - rfk->poll_dev->private = dev; 136 - rfk->poll_dev->poll = b43_rfkill_poll; 137 - rfk->poll_dev->poll_interval = 1000; /* msecs */ 138 - 139 - rfk->poll_dev->input->name = rfk->name; 140 - rfk->poll_dev->input->id.bustype = BUS_HOST; 141 - rfk->poll_dev->input->id.vendor = dev->dev->bus->boardinfo.vendor; 142 - rfk->poll_dev->input->evbit[0] = BIT(EV_KEY); 143 - set_bit(KEY_WLAN, rfk->poll_dev->input->keybit); 136 + rfk->rfkill = rfkill_alloc(rfk->name, 137 + dev->dev->dev, 138 + RFKILL_TYPE_WLAN, 139 + &b43_rfkill_ops, dev); 140 + if (!rfk->rfkill) 141 + goto out_error; 144 142 145 143 err = rfkill_register(rfk->rfkill); 146 144 if (err) 147 - goto err_free_polldev; 148 - 149 - #ifdef CONFIG_RFKILL_INPUT_MODULE 150 - /* B43 RF-kill isn't useful without the rfkill-input subsystem. 151 - * Try to load the module. */ 152 - err = request_module("rfkill-input"); 153 - if (err) 154 - b43warn(wl, "Failed to load the rfkill-input module. " 155 - "The built-in radio LED will not work.\n"); 156 - #endif /* CONFIG_RFKILL_INPUT */ 157 - 158 - #if !defined(CONFIG_RFKILL_INPUT) && !defined(CONFIG_RFKILL_INPUT_MODULE) 159 - b43warn(wl, "The rfkill-input subsystem is not available. " 160 - "The built-in radio LED will not work.\n"); 161 - #endif 162 - 163 - err = input_register_polled_device(rfk->poll_dev); 164 - if (err) 165 - goto err_unreg_rfk; 145 + goto err_free; 166 146 167 147 rfk->registered = 1; 168 148 169 149 return; 170 - err_unreg_rfk: 171 - rfkill_unregister(rfk->rfkill); 172 - err_free_polldev: 173 - input_free_polled_device(rfk->poll_dev); 174 - rfk->poll_dev = NULL; 175 - err_freed_rfk: 176 - rfk->rfkill = NULL; 177 - out_error: 150 + err_free: 151 + rfkill_destroy(rfk->rfkill); 152 + out_error: 178 153 rfk->registered = 0; 179 154 b43warn(wl, "RF-kill button init failed\n"); 180 155 } ··· 148 201 return; 149 202 rfk->registered = 0; 150 203 151 - input_unregister_polled_device(rfk->poll_dev); 152 204 rfkill_unregister(rfk->rfkill); 153 - input_free_polled_device(rfk->poll_dev); 154 - rfk->poll_dev = NULL; 205 + rfkill_destroy(rfk->rfkill); 155 206 rfk->rfkill = NULL; 156 207 }
+1 -4
drivers/net/wireless/b43/rfkill.h
··· 7 7 #ifdef CONFIG_B43_RFKILL 8 8 9 9 #include <linux/rfkill.h> 10 - #include <linux/input-polldev.h> 11 10 12 11 13 12 struct b43_rfkill { 14 13 /* The RFKILL subsystem data structure */ 15 14 struct rfkill *rfkill; 16 - /* The poll device for the RFKILL input button */ 17 - struct input_polled_dev *poll_dev; 18 15 /* Did initialization succeed? Used for freeing. */ 19 16 bool registered; 20 17 /* The unique name of this rfkill switch */ ··· 23 26 void b43_rfkill_init(struct b43_wldev *dev); 24 27 void b43_rfkill_exit(struct b43_wldev *dev); 25 28 26 - char * b43_rfkill_led_name(struct b43_wldev *dev); 29 + const char *b43_rfkill_led_name(struct b43_wldev *dev); 27 30 28 31 29 32 #else /* CONFIG_B43_RFKILL */
+1 -1
drivers/net/wireless/b43legacy/Kconfig
··· 47 47 # if it's possible. 48 48 config B43LEGACY_RFKILL 49 49 bool 50 - depends on B43LEGACY && (RFKILL = y || RFKILL = B43LEGACY) && RFKILL_INPUT && (INPUT_POLLDEV = y || INPUT_POLLDEV = B43LEGACY) 50 + depends on B43LEGACY && (RFKILL = y || RFKILL = B43LEGACY) 51 51 default y 52 52 53 53 # This config option automatically enables b43 HW-RNG support,
+2 -1
drivers/net/wireless/b43legacy/leds.c
··· 86 86 87 87 static int b43legacy_register_led(struct b43legacy_wldev *dev, 88 88 struct b43legacy_led *led, 89 - const char *name, char *default_trigger, 89 + const char *name, 90 + const char *default_trigger, 90 91 u8 led_index, bool activelow) 91 92 { 92 93 int err;
+39 -84
drivers/net/wireless/b43legacy/rfkill.c
··· 45 45 } 46 46 47 47 /* The poll callback for the hardware button. */ 48 - static void b43legacy_rfkill_poll(struct input_polled_dev *poll_dev) 48 + static void b43legacy_rfkill_poll(struct rfkill *rfkill, void *data) 49 49 { 50 - struct b43legacy_wldev *dev = poll_dev->private; 50 + struct b43legacy_wldev *dev = data; 51 51 struct b43legacy_wl *wl = dev->wl; 52 52 bool enabled; 53 - bool report_change = 0; 54 53 55 54 mutex_lock(&wl->mutex); 56 55 if (unlikely(b43legacy_status(dev) < B43legacy_STAT_INITIALIZED)) { ··· 59 60 enabled = b43legacy_is_hw_radio_enabled(dev); 60 61 if (unlikely(enabled != dev->radio_hw_enable)) { 61 62 dev->radio_hw_enable = enabled; 62 - report_change = 1; 63 63 b43legacyinfo(wl, "Radio hardware status changed to %s\n", 64 64 enabled ? "ENABLED" : "DISABLED"); 65 + enabled = !rfkill_set_hw_state(rfkill, !enabled); 66 + if (enabled != dev->phy.radio_on) { 67 + if (enabled) 68 + b43legacy_radio_turn_on(dev); 69 + else 70 + b43legacy_radio_turn_off(dev, 0); 71 + } 65 72 } 66 73 mutex_unlock(&wl->mutex); 67 - 68 - /* send the radio switch event to the system - note both a key press 69 - * and a release are required */ 70 - if (unlikely(report_change)) { 71 - input_report_key(poll_dev->input, KEY_WLAN, 1); 72 - input_report_key(poll_dev->input, KEY_WLAN, 0); 73 - } 74 74 } 75 75 76 76 /* Called when the RFKILL toggled in software. 77 77 * This is called without locking. */ 78 - static int b43legacy_rfkill_soft_toggle(void *data, enum rfkill_state state) 78 + static int b43legacy_rfkill_soft_set(void *data, bool blocked) 79 79 { 80 80 struct b43legacy_wldev *dev = data; 81 81 struct b43legacy_wl *wl = dev->wl; 82 - int err = -EBUSY; 82 + int ret = -EINVAL; 83 83 84 84 if (!wl->rfkill.registered) 85 - return 0; 85 + return -EINVAL; 86 86 87 87 mutex_lock(&wl->mutex); 88 88 if (b43legacy_status(dev) < B43legacy_STAT_INITIALIZED) 89 89 goto out_unlock; 90 - err = 0; 91 - switch (state) { 92 - case RFKILL_STATE_UNBLOCKED: 93 - if (!dev->radio_hw_enable) { 94 - /* No luck. We can't toggle the hardware RF-kill 95 - * button from software. */ 96 - err = -EBUSY; 97 - goto out_unlock; 98 - } 99 - if (!dev->phy.radio_on) 90 + 91 + if (!dev->radio_hw_enable) 92 + goto out_unlock; 93 + 94 + if (!blocked != dev->phy.radio_on) { 95 + if (!blocked) 100 96 b43legacy_radio_turn_on(dev); 101 - break; 102 - case RFKILL_STATE_SOFT_BLOCKED: 103 - if (dev->phy.radio_on) 97 + else 104 98 b43legacy_radio_turn_off(dev, 0); 105 - break; 106 - default: 107 - b43legacywarn(wl, "Received unexpected rfkill state %d.\n", 108 - state); 109 - break; 110 99 } 100 + ret = 0; 111 101 112 102 out_unlock: 113 103 mutex_unlock(&wl->mutex); 114 - 115 - return err; 104 + return ret; 116 105 } 117 106 118 - char *b43legacy_rfkill_led_name(struct b43legacy_wldev *dev) 107 + const char *b43legacy_rfkill_led_name(struct b43legacy_wldev *dev) 119 108 { 120 109 struct b43legacy_rfkill *rfk = &(dev->wl->rfkill); 121 110 122 111 if (!rfk->registered) 123 112 return NULL; 124 - return rfkill_get_led_name(rfk->rfkill); 113 + return rfkill_get_led_trigger_name(rfk->rfkill); 125 114 } 115 + 116 + static const struct rfkill_ops b43legacy_rfkill_ops = { 117 + .set_block = b43legacy_rfkill_soft_set, 118 + .poll = b43legacy_rfkill_poll, 119 + }; 126 120 127 121 void b43legacy_rfkill_init(struct b43legacy_wldev *dev) 128 122 { ··· 125 133 126 134 rfk->registered = 0; 127 135 128 - rfk->rfkill = rfkill_allocate(dev->dev->dev, RFKILL_TYPE_WLAN); 129 - if (!rfk->rfkill) 130 - goto out_error; 131 136 snprintf(rfk->name, sizeof(rfk->name), 132 137 "b43legacy-%s", wiphy_name(wl->hw->wiphy)); 133 - rfk->rfkill->name = rfk->name; 134 - rfk->rfkill->state = RFKILL_STATE_UNBLOCKED; 135 - rfk->rfkill->data = dev; 136 - rfk->rfkill->toggle_radio = b43legacy_rfkill_soft_toggle; 137 - 138 - rfk->poll_dev = input_allocate_polled_device(); 139 - if (!rfk->poll_dev) { 140 - rfkill_free(rfk->rfkill); 141 - goto err_freed_rfk; 142 - } 143 - 144 - rfk->poll_dev->private = dev; 145 - rfk->poll_dev->poll = b43legacy_rfkill_poll; 146 - rfk->poll_dev->poll_interval = 1000; /* msecs */ 147 - 148 - rfk->poll_dev->input->name = rfk->name; 149 - rfk->poll_dev->input->id.bustype = BUS_HOST; 150 - rfk->poll_dev->input->id.vendor = dev->dev->bus->boardinfo.vendor; 151 - rfk->poll_dev->input->evbit[0] = BIT(EV_KEY); 152 - set_bit(KEY_WLAN, rfk->poll_dev->input->keybit); 138 + rfk->rfkill = rfkill_alloc(rfk->name, 139 + dev->dev->dev, 140 + RFKILL_TYPE_WLAN, 141 + &b43legacy_rfkill_ops, dev); 142 + if (!rfk->rfkill) 143 + goto out_error; 153 144 154 145 err = rfkill_register(rfk->rfkill); 155 146 if (err) 156 - goto err_free_polldev; 157 - 158 - #ifdef CONFIG_RFKILL_INPUT_MODULE 159 - /* B43legacy RF-kill isn't useful without the rfkill-input subsystem. 160 - * Try to load the module. */ 161 - err = request_module("rfkill-input"); 162 - if (err) 163 - b43legacywarn(wl, "Failed to load the rfkill-input module." 164 - "The built-in radio LED will not work.\n"); 165 - #endif /* CONFIG_RFKILL_INPUT */ 166 - 167 - err = input_register_polled_device(rfk->poll_dev); 168 - if (err) 169 - goto err_unreg_rfk; 147 + goto err_free; 170 148 171 149 rfk->registered = 1; 172 150 173 151 return; 174 - err_unreg_rfk: 175 - rfkill_unregister(rfk->rfkill); 176 - err_free_polldev: 177 - input_free_polled_device(rfk->poll_dev); 178 - rfk->poll_dev = NULL; 179 - err_freed_rfk: 180 - rfk->rfkill = NULL; 181 - out_error: 152 + err_free: 153 + rfkill_destroy(rfk->rfkill); 154 + out_error: 182 155 rfk->registered = 0; 183 156 b43legacywarn(wl, "RF-kill button init failed\n"); 184 157 } ··· 156 199 return; 157 200 rfk->registered = 0; 158 201 159 - input_unregister_polled_device(rfk->poll_dev); 160 202 rfkill_unregister(rfk->rfkill); 161 - input_free_polled_device(rfk->poll_dev); 162 - rfk->poll_dev = NULL; 203 + rfkill_destroy(rfk->rfkill); 163 204 rfk->rfkill = NULL; 164 205 } 165 206
+1 -5
drivers/net/wireless/b43legacy/rfkill.h
··· 6 6 #ifdef CONFIG_B43LEGACY_RFKILL 7 7 8 8 #include <linux/rfkill.h> 9 - #include <linux/workqueue.h> 10 - #include <linux/input-polldev.h> 11 9 12 10 13 11 14 12 struct b43legacy_rfkill { 15 13 /* The RFKILL subsystem data structure */ 16 14 struct rfkill *rfkill; 17 - /* The poll device for the RFKILL input button */ 18 - struct input_polled_dev *poll_dev; 19 15 /* Did initialization succeed? Used for freeing. */ 20 16 bool registered; 21 17 /* The unique name of this rfkill switch */ ··· 23 27 void b43legacy_rfkill_init(struct b43legacy_wldev *dev); 24 28 void b43legacy_rfkill_exit(struct b43legacy_wldev *dev); 25 29 26 - char *b43legacy_rfkill_led_name(struct b43legacy_wldev *dev); 30 + const char *b43legacy_rfkill_led_name(struct b43legacy_wldev *dev); 27 31 28 32 29 33 #else /* CONFIG_B43LEGACY_RFKILL */
+2 -3
drivers/net/wireless/iwlwifi/Kconfig
··· 5 5 select FW_LOADER 6 6 select MAC80211_LEDS if IWLWIFI_LEDS 7 7 select LEDS_CLASS if IWLWIFI_LEDS 8 - select RFKILL if IWLWIFI_RFKILL 9 8 10 9 config IWLWIFI_LEDS 11 10 bool "Enable LED support in iwlagn and iwl3945 drivers" 12 11 depends on IWLWIFI 13 12 14 13 config IWLWIFI_RFKILL 15 - bool "Enable RF kill support in iwlagn and iwl3945 drivers" 16 - depends on IWLWIFI 14 + def_bool y 15 + depends on IWLWIFI && RFKILL 17 16 18 17 config IWLWIFI_SPECTRUM_MEASUREMENT 19 18 bool "Enable Spectrum Measurement in iwlagn driver"
-4
drivers/net/wireless/iwlwifi/iwl-3945-led.c
··· 167 167 IWL_DEBUG_LED(priv, "Disassociated\n"); 168 168 169 169 priv->allow_blinking = 0; 170 - if (iwl_is_rfkill(priv)) 171 - iwl3945_led_off(priv, led_id); 172 - else 173 - iwl3945_led_on(priv, led_id); 174 170 175 171 return 0; 176 172 }
+5 -4
drivers/net/wireless/iwlwifi/iwl-3945-rs.c
··· 38 38 39 39 #include "iwl-commands.h" 40 40 #include "iwl-3945.h" 41 + #include "iwl-sta.h" 41 42 42 43 #define RS_NAME "iwl-3945-rs" 43 44 ··· 715 714 716 715 if ((priv->iw_mode == NL80211_IFTYPE_ADHOC) && 717 716 !rs_sta->ibss_sta_added) { 718 - u8 sta_id = iwl3945_hw_find_station(priv, hdr->addr1); 717 + u8 sta_id = iwl_find_station(priv, hdr->addr1); 719 718 720 719 if (sta_id == IWL_INVALID_STATION) { 721 720 IWL_DEBUG_RATE(priv, "LQ: ADD station %pm\n", 722 721 hdr->addr1); 723 - sta_id = iwl3945_add_station(priv, 724 - hdr->addr1, 0, CMD_ASYNC, NULL); 722 + sta_id = iwl_add_station(priv, hdr->addr1, false, 723 + CMD_ASYNC, NULL); 725 724 } 726 725 if (sta_id != IWL_INVALID_STATION) 727 726 rs_sta->ibss_sta_added = 1; ··· 976 975 977 976 rcu_read_lock(); 978 977 979 - sta = ieee80211_find_sta(hw, priv->stations_39[sta_id].sta.sta.addr); 978 + sta = ieee80211_find_sta(hw, priv->stations[sta_id].sta.sta.addr); 980 979 if (!sta) { 981 980 rcu_read_unlock(); 982 981 return;
+22 -51
drivers/net/wireless/iwlwifi/iwl-3945.c
··· 769 769 return ; 770 770 } 771 771 772 - u8 iwl3945_hw_find_station(struct iwl_priv *priv, const u8 *addr) 773 - { 774 - int i, start = IWL_AP_ID; 775 - int ret = IWL_INVALID_STATION; 776 - unsigned long flags; 777 - 778 - if ((priv->iw_mode == NL80211_IFTYPE_ADHOC) || 779 - (priv->iw_mode == NL80211_IFTYPE_AP)) 780 - start = IWL_STA_ID; 781 - 782 - if (is_broadcast_ether_addr(addr)) 783 - return priv->hw_params.bcast_sta_id; 784 - 785 - spin_lock_irqsave(&priv->sta_lock, flags); 786 - for (i = start; i < priv->hw_params.max_stations; i++) 787 - if ((priv->stations_39[i].used) && 788 - (!compare_ether_addr 789 - (priv->stations_39[i].sta.sta.addr, addr))) { 790 - ret = i; 791 - goto out; 792 - } 793 - 794 - IWL_DEBUG_INFO(priv, "can not find STA %pM (total %d)\n", 795 - addr, priv->num_stations); 796 - out: 797 - spin_unlock_irqrestore(&priv->sta_lock, flags); 798 - return ret; 799 - } 800 - 801 772 /** 802 773 * iwl3945_hw_build_tx_cmd_rate - Add rate portion to TX_CMD: 803 774 * ··· 846 875 u8 iwl3945_sync_sta(struct iwl_priv *priv, int sta_id, u16 tx_rate, u8 flags) 847 876 { 848 877 unsigned long flags_spin; 849 - struct iwl3945_station_entry *station; 878 + struct iwl_station_entry *station; 850 879 851 880 if (sta_id == IWL_INVALID_STATION) 852 881 return IWL_INVALID_STATION; 853 882 854 883 spin_lock_irqsave(&priv->sta_lock, flags_spin); 855 - station = &priv->stations_39[sta_id]; 884 + station = &priv->stations[sta_id]; 856 885 857 886 station->sta.sta.modify_mask = STA_MODIFY_TX_RATE_MSK; 858 887 station->sta.rate_n_flags = cpu_to_le16(tx_rate); ··· 860 889 861 890 spin_unlock_irqrestore(&priv->sta_lock, flags_spin); 862 891 863 - iwl_send_add_sta(priv, 864 - (struct iwl_addsta_cmd *)&station->sta, flags); 892 + iwl_send_add_sta(priv, &station->sta, flags); 865 893 IWL_DEBUG_RATE(priv, "SCALE sync station %d to rate %d\n", 866 894 sta_id, tx_rate); 867 895 return sta_id; ··· 1999 2029 2000 2030 memcpy(active_rxon, staging_rxon, sizeof(*active_rxon)); 2001 2031 2002 - priv->cfg->ops->smgmt->clear_station_table(priv); 2032 + iwl_clear_stations_table(priv); 2003 2033 2004 2034 /* If we issue a new RXON command which required a tune then we must 2005 2035 * send a new TXPOWER command or we won't be able to Tx any frames */ ··· 2010 2040 } 2011 2041 2012 2042 /* Add the broadcast address so we can send broadcast frames */ 2013 - if (priv->cfg->ops->smgmt->add_station(priv, iwl_bcast_addr, 0, 0, NULL) == 2043 + if (iwl_add_station(priv, iwl_bcast_addr, false, CMD_SYNC, NULL) == 2014 2044 IWL_INVALID_STATION) { 2015 2045 IWL_ERR(priv, "Error adding BROADCAST address for transmit.\n"); 2016 2046 return -EIO; ··· 2020 2050 * add the IWL_AP_ID to the station rate table */ 2021 2051 if (iwl_is_associated(priv) && 2022 2052 (priv->iw_mode == NL80211_IFTYPE_STATION)) 2023 - if (priv->cfg->ops->smgmt->add_station(priv, 2024 - priv->active_rxon.bssid_addr, 1, 0, NULL) 2025 - == IWL_INVALID_STATION) { 2053 + if (iwl_add_station(priv, priv->active_rxon.bssid_addr, 2054 + true, CMD_SYNC, NULL) == IWL_INVALID_STATION) { 2026 2055 IWL_ERR(priv, "Error adding AP address for transmit\n"); 2027 2056 return -EIO; 2028 2057 } ··· 2435 2466 } 2436 2467 } 2437 2468 2469 + 2438 2470 static u16 iwl3945_build_addsta_hcmd(const struct iwl_addsta_cmd *cmd, u8 *data) 2439 2471 { 2440 - u16 size = (u16)sizeof(struct iwl3945_addsta_cmd); 2441 - memcpy(data, cmd, size); 2442 - return size; 2472 + struct iwl3945_addsta_cmd *addsta = (struct iwl3945_addsta_cmd *)data; 2473 + addsta->mode = cmd->mode; 2474 + memcpy(&addsta->sta, &cmd->sta, sizeof(struct sta_id_modify)); 2475 + memcpy(&addsta->key, &cmd->key, sizeof(struct iwl4965_keyinfo)); 2476 + addsta->station_flags = cmd->station_flags; 2477 + addsta->station_flags_msk = cmd->station_flags_msk; 2478 + addsta->tid_disable_tx = cpu_to_le16(0); 2479 + addsta->rate_n_flags = cmd->rate_n_flags; 2480 + addsta->add_immediate_ba_tid = cmd->add_immediate_ba_tid; 2481 + addsta->remove_immediate_ba_tid = cmd->remove_immediate_ba_tid; 2482 + addsta->add_immediate_ba_ssn = cmd->add_immediate_ba_ssn; 2483 + 2484 + return (u16)sizeof(struct iwl3945_addsta_cmd); 2443 2485 } 2486 + 2444 2487 2445 2488 /** 2446 2489 * iwl3945_init_hw_rate_table - Initialize the hardware rate fallback table ··· 2823 2842 .config_ap = iwl3945_config_ap, 2824 2843 }; 2825 2844 2826 - static struct iwl_station_mgmt_ops iwl3945_station_mgmt = { 2827 - .add_station = iwl3945_add_station, 2828 - #if 0 2829 - .remove_station = iwl3945_remove_station, 2830 - #endif 2831 - .find_station = iwl3945_hw_find_station, 2832 - .clear_station_table = iwl3945_clear_stations_table, 2833 - }; 2834 - 2835 2845 static struct iwl_hcmd_utils_ops iwl3945_hcmd_utils = { 2836 2846 .get_hcmd_size = iwl3945_get_hcmd_size, 2837 2847 .build_addsta_hcmd = iwl3945_build_addsta_hcmd, ··· 2832 2860 .lib = &iwl3945_lib, 2833 2861 .hcmd = &iwl3945_hcmd, 2834 2862 .utils = &iwl3945_hcmd_utils, 2835 - .smgmt = &iwl3945_station_mgmt, 2836 2863 }; 2837 2864 2838 2865 static struct iwl_cfg iwl3945_bg_cfg = {
-6
drivers/net/wireless/iwlwifi/iwl-3945.h
··· 202 202 * for use by iwl-*.c 203 203 * 204 204 *****************************************************************************/ 205 - struct iwl3945_addsta_cmd; 206 - extern int iwl3945_send_add_station(struct iwl_priv *priv, 207 - struct iwl3945_addsta_cmd *sta, u8 flags); 208 - extern u8 iwl3945_add_station(struct iwl_priv *priv, const u8 *bssid, 209 - int is_ap, u8 flags, struct ieee80211_sta_ht_cap *ht_info); 210 - extern void iwl3945_clear_stations_table(struct iwl_priv *priv); 211 205 extern int iwl3945_power_init_handle(struct iwl_priv *priv); 212 206 extern int iwl3945_eeprom_init(struct iwl_priv *priv); 213 207 extern int iwl3945_calc_db_from_ratio(int sig_ratio);
-8
drivers/net/wireless/iwlwifi/iwl-4965.c
··· 2221 2221 cancel_work_sync(&priv->txpower_work); 2222 2222 } 2223 2223 2224 - static struct iwl_station_mgmt_ops iwl4965_station_mgmt = { 2225 - .add_station = iwl_add_station_flags, 2226 - .remove_station = iwl_remove_station, 2227 - .find_station = iwl_find_station, 2228 - .clear_station_table = iwl_clear_stations_table, 2229 - }; 2230 - 2231 2224 static struct iwl_hcmd_ops iwl4965_hcmd = { 2232 2225 .rxon_assoc = iwl4965_send_rxon_assoc, 2233 2226 .commit_rxon = iwl_commit_rxon, ··· 2290 2297 .lib = &iwl4965_lib, 2291 2298 .hcmd = &iwl4965_hcmd, 2292 2299 .utils = &iwl4965_hcmd_utils, 2293 - .smgmt = &iwl4965_station_mgmt, 2294 2300 }; 2295 2301 2296 2302 struct iwl_cfg iwl4965_agn_cfg = {
+5 -11
drivers/net/wireless/iwlwifi/iwl-5000.c
··· 651 651 goto restart; 652 652 } 653 653 654 - priv->cfg->ops->smgmt->clear_station_table(priv); 654 + iwl_clear_stations_table(priv); 655 655 ret = priv->cfg->ops->lib->alive_notify(priv); 656 656 if (ret) { 657 657 IWL_WARN(priv, ··· 1049 1049 u16 iwl5000_build_addsta_hcmd(const struct iwl_addsta_cmd *cmd, u8 *data) 1050 1050 { 1051 1051 u16 size = (u16)sizeof(struct iwl_addsta_cmd); 1052 - memcpy(data, cmd, size); 1052 + struct iwl_addsta_cmd *addsta = (struct iwl_addsta_cmd *)data; 1053 + memcpy(addsta, cmd, size); 1054 + /* resrved in 5000 */ 1055 + addsta->rate_n_flags = cpu_to_le16(0); 1053 1056 return size; 1054 1057 } 1055 1058 ··· 1426 1423 return max_rssi - agc - IWL49_RSSI_OFFSET; 1427 1424 } 1428 1425 1429 - struct iwl_station_mgmt_ops iwl5000_station_mgmt = { 1430 - .add_station = iwl_add_station_flags, 1431 - .remove_station = iwl_remove_station, 1432 - .find_station = iwl_find_station, 1433 - .clear_station_table = iwl_clear_stations_table, 1434 - }; 1435 - 1436 1426 struct iwl_hcmd_ops iwl5000_hcmd = { 1437 1427 .rxon_assoc = iwl5000_send_rxon_assoc, 1438 1428 .commit_rxon = iwl_commit_rxon, ··· 1545 1549 .lib = &iwl5000_lib, 1546 1550 .hcmd = &iwl5000_hcmd, 1547 1551 .utils = &iwl5000_hcmd_utils, 1548 - .smgmt = &iwl5000_station_mgmt, 1549 1552 }; 1550 1553 1551 1554 static struct iwl_ops iwl5150_ops = { 1552 1555 .lib = &iwl5150_lib, 1553 1556 .hcmd = &iwl5000_hcmd, 1554 1557 .utils = &iwl5000_hcmd_utils, 1555 - .smgmt = &iwl5000_station_mgmt, 1556 1558 }; 1557 1559 1558 1560 struct iwl_mod_params iwl50_mod_params = {
-1
drivers/net/wireless/iwlwifi/iwl-6000.c
··· 72 72 .lib = &iwl5000_lib, 73 73 .hcmd = &iwl5000_hcmd, 74 74 .utils = &iwl6000_hcmd_utils, 75 - .smgmt = &iwl5000_station_mgmt, 76 75 }; 77 76 78 77 struct iwl_cfg iwl6000_2ag_cfg = {
+10 -12
drivers/net/wireless/iwlwifi/iwl-agn-rs.c
··· 2502 2502 2503 2503 if ((priv->iw_mode == NL80211_IFTYPE_ADHOC) && 2504 2504 !lq_sta->ibss_sta_added) { 2505 - u8 sta_id = priv->cfg->ops->smgmt->find_station(priv, 2506 - hdr->addr1); 2505 + u8 sta_id = iwl_find_station(priv, hdr->addr1); 2507 2506 2508 2507 if (sta_id == IWL_INVALID_STATION) { 2509 2508 IWL_DEBUG_RATE(priv, "LQ: ADD station %pM\n", 2510 2509 hdr->addr1); 2511 - sta_id = priv->cfg->ops->smgmt->add_station(priv, 2512 - hdr->addr1, 0, 2513 - CMD_ASYNC, NULL); 2510 + sta_id = iwl_add_station(priv, hdr->addr1, 2511 + false, CMD_ASYNC, NULL); 2514 2512 } 2515 2513 if ((sta_id != IWL_INVALID_STATION)) { 2516 2514 lq_sta->lq.sta_id = sta_id; ··· 2596 2598 2597 2599 lq_sta->ibss_sta_added = 0; 2598 2600 if (priv->iw_mode == NL80211_IFTYPE_AP) { 2599 - u8 sta_id = priv->cfg->ops->smgmt->find_station(priv, 2601 + u8 sta_id = iwl_find_station(priv, 2600 2602 sta->addr); 2601 2603 2602 2604 /* for IBSS the call are from tasklet */ ··· 2604 2606 2605 2607 if (sta_id == IWL_INVALID_STATION) { 2606 2608 IWL_DEBUG_RATE(priv, "LQ: ADD station %pM\n", sta->addr); 2607 - sta_id = priv->cfg->ops->smgmt->add_station(priv, 2608 - sta->addr, 0, 2609 - CMD_ASYNC, NULL); 2609 + sta_id = iwl_add_station(priv, sta->addr, false, 2610 + CMD_ASYNC, NULL); 2610 2611 } 2611 2612 if ((sta_id != IWL_INVALID_STATION)) { 2612 2613 lq_sta->lq.sta_id = sta_id; ··· 2787 2790 repeat_rate--; 2788 2791 } 2789 2792 2790 - lq_cmd->agg_params.agg_frame_cnt_limit = 64; 2791 - lq_cmd->agg_params.agg_dis_start_th = 3; 2792 - lq_cmd->agg_params.agg_time_limit = cpu_to_le16(4000); 2793 + lq_cmd->agg_params.agg_frame_cnt_limit = LINK_QUAL_AGG_FRAME_LIMIT_MAX; 2794 + lq_cmd->agg_params.agg_dis_start_th = LINK_QUAL_AGG_DISABLE_START_DEF; 2795 + lq_cmd->agg_params.agg_time_limit = 2796 + cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF); 2793 2797 } 2794 2798 2795 2799 static void *rs_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
+9 -8
drivers/net/wireless/iwlwifi/iwl-agn.c
··· 188 188 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon)); 189 189 } 190 190 191 - priv->cfg->ops->smgmt->clear_station_table(priv); 191 + iwl_clear_stations_table(priv); 192 192 193 193 priv->start_calib = 0; 194 194 ··· 1617 1617 goto restart; 1618 1618 } 1619 1619 1620 - priv->cfg->ops->smgmt->clear_station_table(priv); 1620 + iwl_clear_stations_table(priv); 1621 1621 ret = priv->cfg->ops->lib->alive_notify(priv); 1622 1622 if (ret) { 1623 1623 IWL_WARN(priv, ··· 1703 1703 1704 1704 iwl_leds_unregister(priv); 1705 1705 1706 - priv->cfg->ops->smgmt->clear_station_table(priv); 1706 + iwl_clear_stations_table(priv); 1707 1707 1708 1708 /* Unblock any waiting calls */ 1709 1709 wake_up_interruptible_all(&priv->wait_command_queue); ··· 1887 1887 1888 1888 /* clear (again), then enable host interrupts */ 1889 1889 iwl_write32(priv, CSR_INT, 0xFFFFFFFF); 1890 - /* enable dram interrupt */ 1891 - iwl_reset_ict(priv); 1892 1890 iwl_enable_interrupts(priv); 1893 1891 1894 1892 /* really make sure rfkill handshake bits are cleared */ ··· 1901 1903 1902 1904 for (i = 0; i < MAX_HW_RESTARTS; i++) { 1903 1905 1904 - priv->cfg->ops->smgmt->clear_station_table(priv); 1906 + iwl_clear_stations_table(priv); 1905 1907 1906 1908 /* load bootstrap state machine, 1907 1909 * load bootstrap program into processor's memory, ··· 1959 1961 1960 1962 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) 1961 1963 return; 1964 + 1965 + /* enable dram interrupt */ 1966 + iwl_reset_ict(priv); 1962 1967 1963 1968 mutex_lock(&priv->mutex); 1964 1969 iwl_alive_start(priv); ··· 2349 2348 return -EOPNOTSUPP; 2350 2349 } 2351 2350 addr = sta ? sta->addr : iwl_bcast_addr; 2352 - sta_id = priv->cfg->ops->smgmt->find_station(priv, addr); 2351 + sta_id = iwl_find_station(priv, addr); 2353 2352 if (sta_id == IWL_INVALID_STATION) { 2354 2353 IWL_DEBUG_MAC80211(priv, "leave - %pM not in station map.\n", 2355 2354 addr); ··· 3122 3121 iwl_rx_queue_free(priv, &priv->rxq); 3123 3122 iwl_hw_txq_ctx_free(priv); 3124 3123 3125 - priv->cfg->ops->smgmt->clear_station_table(priv); 3124 + iwl_clear_stations_table(priv); 3126 3125 iwl_eeprom_free(priv); 3127 3126 3128 3127
+13 -1
drivers/net/wireless/iwlwifi/iwl-commands.h
··· 1067 1067 * Set modify_mask bit STA_MODIFY_TID_DISABLE_TX to use this field. */ 1068 1068 __le16 tid_disable_tx; 1069 1069 1070 - __le16 reserved1; 1070 + __le16 rate_n_flags; /* 3945 only */ 1071 1071 1072 1072 /* TID for which to add block-ack support. 1073 1073 * Set modify_mask bit STA_MODIFY_ADDBA_TID_MSK to use this field. */ ··· 1912 1912 */ 1913 1913 u8 start_rate_index[LINK_QUAL_AC_NUM]; 1914 1914 } __attribute__ ((packed)); 1915 + 1916 + #define LINK_QUAL_AGG_TIME_LIMIT_DEF (4000) /* 4 milliseconds */ 1917 + #define LINK_QUAL_AGG_TIME_LIMIT_MAX (65535) 1918 + #define LINK_QUAL_AGG_TIME_LIMIT_MIN (0) 1919 + 1920 + #define LINK_QUAL_AGG_DISABLE_START_DEF (3) 1921 + #define LINK_QUAL_AGG_DISABLE_START_MAX (255) 1922 + #define LINK_QUAL_AGG_DISABLE_START_MIN (0) 1923 + 1924 + #define LINK_QUAL_AGG_FRAME_LIMIT_DEF (31) 1925 + #define LINK_QUAL_AGG_FRAME_LIMIT_MAX (64) 1926 + #define LINK_QUAL_AGG_FRAME_LIMIT_MIN (0) 1915 1927 1916 1928 /** 1917 1929 * struct iwl_link_qual_agg_params
+4 -10
drivers/net/wireless/iwlwifi/iwl-core.c
··· 1389 1389 mutex_init(&priv->mutex); 1390 1390 1391 1391 /* Clear the driver's (not device's) station table */ 1392 - priv->cfg->ops->smgmt->clear_station_table(priv); 1392 + iwl_clear_stations_table(priv); 1393 1393 1394 1394 priv->data_retry_limit = -1; 1395 1395 priv->ieee_channels = NULL; ··· 1704 1704 { 1705 1705 struct iwl_priv *priv = data; 1706 1706 u32 inta, inta_mask; 1707 + #ifdef CONFIG_IWLWIFI_DEBUG 1707 1708 u32 inta_fh; 1708 - 1709 + #endif 1709 1710 if (!priv) 1710 1711 return IRQ_NONE; 1711 1712 ··· 2680 2679 2681 2680 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); 2682 2681 2683 - priv->cfg->ops->smgmt->clear_station_table(priv); 2682 + iwl_clear_stations_table(priv); 2684 2683 2685 2684 /* dont commit rxon if rf-kill is on*/ 2686 2685 if (!iwl_is_ready_rf(priv)) 2687 2686 return -EAGAIN; 2688 - 2689 - cancel_delayed_work(&priv->scan_check); 2690 - if (iwl_scan_cancel_timeout(priv, 100)) { 2691 - IWL_WARN(priv, "Aborted scan still in progress after 100ms\n"); 2692 - IWL_DEBUG_MAC80211(priv, "leaving - scan abort failed.\n"); 2693 - return -EAGAIN; 2694 - } 2695 2687 2696 2688 iwlcore_commit_rxon(priv); 2697 2689
+1 -11
drivers/net/wireless/iwlwifi/iwl-core.h
··· 83 83 #define IWL_SKU_A 0x2 84 84 #define IWL_SKU_N 0x8 85 85 86 - struct iwl_station_mgmt_ops { 87 - u8 (*add_station)(struct iwl_priv *priv, const u8 *addr, 88 - int is_ap, u8 flags, struct ieee80211_sta_ht_cap *ht_info); 89 - int (*remove_station)(struct iwl_priv *priv, const u8 *addr, 90 - int is_ap); 91 - u8 (*find_station)(struct iwl_priv *priv, const u8 *addr); 92 - void (*clear_station_table)(struct iwl_priv *priv); 93 - }; 94 - 95 86 struct iwl_hcmd_ops { 96 87 int (*rxon_assoc)(struct iwl_priv *priv); 97 88 int (*commit_rxon)(struct iwl_priv *priv); ··· 174 183 const struct iwl_lib_ops *lib; 175 184 const struct iwl_hcmd_ops *hcmd; 176 185 const struct iwl_hcmd_utils_ops *utils; 177 - const struct iwl_station_mgmt_ops *smgmt; 178 186 }; 179 187 180 188 struct iwl_mod_params { ··· 182 192 int disable_hw_scan; /* def: 0 = use h/w scan */ 183 193 int num_of_queues; /* def: HW dependent */ 184 194 int num_of_ampdu_queues;/* def: HW dependent */ 185 - int disable_11n; /* def: 0 = disable 11n capabilities */ 195 + int disable_11n; /* def: 0 = 11n capabilities enabled */ 186 196 int amsdu_size_8K; /* def: 1 = enable 8K amsdu size */ 187 197 int antenna; /* def: 0 = both antennas (use diversity) */ 188 198 int restart_fw; /* def: 1 = restart firmware */
+3 -6
drivers/net/wireless/iwlwifi/iwl-dev.h
··· 70 70 extern struct iwl_lib_ops iwl5000_lib; 71 71 extern struct iwl_hcmd_ops iwl5000_hcmd; 72 72 extern struct iwl_hcmd_utils_ops iwl5000_hcmd_utils; 73 - extern struct iwl_station_mgmt_ops iwl5000_station_mgmt; 74 73 75 74 /* shared functions from iwl-5000.c */ 76 75 extern u16 iwl5000_get_hcmd_size(u8 cmd_id, u16 len); ··· 289 290 #define MAX_SN ((IEEE80211_SCTL_SEQ) >> 4) 290 291 291 292 enum { 292 - /* CMD_SIZE_NORMAL = 0, */ 293 + CMD_SYNC = 0, 294 + CMD_SIZE_NORMAL = 0, 295 + CMD_NO_SKB = 0, 293 296 CMD_SIZE_HUGE = (1 << 0), 294 - /* CMD_SYNC = 0, */ 295 297 CMD_ASYNC = (1 << 1), 296 - /* CMD_NO_SKB = 0, */ 297 298 CMD_WANT_SKB = (1 << 2), 298 299 }; 299 300 ··· 1117 1118 #define IWL_DEFAULT_TX_POWER 0x0F 1118 1119 1119 1120 struct iwl3945_notif_statistics statistics_39; 1120 - 1121 - struct iwl3945_station_entry stations_39[IWL_STATION_COUNT]; 1122 1121 1123 1122 u32 sta_supp_rates; 1124 1123 }; /*iwl_priv */
+5 -7
drivers/net/wireless/iwlwifi/iwl-eeprom.c
··· 240 240 if (ret < 0) 241 241 IWL_ERR(priv, "Time out access OTP\n"); 242 242 else { 243 - if (!ret) { 244 - iwl_set_bits_prph(priv, APMG_PS_CTRL_REG, 245 - APMG_PS_CTRL_VAL_RESET_REQ); 246 - udelay(5); 247 - iwl_clear_bits_prph(priv, APMG_PS_CTRL_REG, 248 - APMG_PS_CTRL_VAL_RESET_REQ); 249 - } 243 + iwl_set_bits_prph(priv, APMG_PS_CTRL_REG, 244 + APMG_PS_CTRL_VAL_RESET_REQ); 245 + udelay(5); 246 + iwl_clear_bits_prph(priv, APMG_PS_CTRL_REG, 247 + APMG_PS_CTRL_VAL_RESET_REQ); 250 248 } 251 249 return ret; 252 250 }
-4
drivers/net/wireless/iwlwifi/iwl-led.c
··· 176 176 static int iwl_led_disassociate(struct iwl_priv *priv, int led_id) 177 177 { 178 178 priv->allow_blinking = 0; 179 - if (iwl_is_rfkill(priv)) 180 - iwl4965_led_off_reg(priv, led_id); 181 - else 182 - iwl4965_led_on_reg(priv, led_id); 183 179 184 180 return 0; 185 181 }
+28 -41
drivers/net/wireless/iwlwifi/iwl-rfkill.c
··· 36 36 #include "iwl-core.h" 37 37 38 38 /* software rf-kill from user */ 39 - static int iwl_rfkill_soft_rf_kill(void *data, enum rfkill_state state) 39 + static int iwl_rfkill_soft_rf_kill(void *data, bool blocked) 40 40 { 41 41 struct iwl_priv *priv = data; 42 - int err = 0; 43 42 44 43 if (!priv->rfkill) 45 - return 0; 44 + return -EINVAL; 46 45 47 46 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) 48 47 return 0; 49 48 50 - IWL_DEBUG_RF_KILL(priv, "we received soft RFKILL set to state %d\n", state); 49 + IWL_DEBUG_RF_KILL(priv, "received soft RFKILL: block=%d\n", blocked); 50 + 51 51 mutex_lock(&priv->mutex); 52 52 53 - switch (state) { 54 - case RFKILL_STATE_UNBLOCKED: 55 - if (iwl_is_rfkill_hw(priv)) { 56 - err = -EBUSY; 57 - goto out_unlock; 58 - } 53 + if (iwl_is_rfkill_hw(priv)) 54 + goto out_unlock; 55 + 56 + if (!blocked) 59 57 iwl_radio_kill_sw_enable_radio(priv); 60 - break; 61 - case RFKILL_STATE_SOFT_BLOCKED: 58 + else 62 59 iwl_radio_kill_sw_disable_radio(priv); 63 - break; 64 - default: 65 - IWL_WARN(priv, "we received unexpected RFKILL state %d\n", 66 - state); 67 - break; 68 - } 60 + 69 61 out_unlock: 70 62 mutex_unlock(&priv->mutex); 71 - 72 - return err; 63 + return 0; 73 64 } 65 + 66 + static const struct rfkill_ops iwl_rfkill_ops = { 67 + .set_block = iwl_rfkill_soft_rf_kill, 68 + }; 74 69 75 70 int iwl_rfkill_init(struct iwl_priv *priv) 76 71 { ··· 75 80 BUG_ON(device == NULL); 76 81 77 82 IWL_DEBUG_RF_KILL(priv, "Initializing RFKILL.\n"); 78 - priv->rfkill = rfkill_allocate(device, RFKILL_TYPE_WLAN); 83 + priv->rfkill = rfkill_alloc(priv->cfg->name, 84 + device, 85 + RFKILL_TYPE_WLAN, 86 + &iwl_rfkill_ops, priv); 79 87 if (!priv->rfkill) { 80 88 IWL_ERR(priv, "Unable to allocate RFKILL device.\n"); 81 89 ret = -ENOMEM; 82 90 goto error; 83 91 } 84 - 85 - priv->rfkill->name = priv->cfg->name; 86 - priv->rfkill->data = priv; 87 - priv->rfkill->state = RFKILL_STATE_UNBLOCKED; 88 - priv->rfkill->toggle_radio = iwl_rfkill_soft_rf_kill; 89 - 90 - priv->rfkill->dev.class->suspend = NULL; 91 - priv->rfkill->dev.class->resume = NULL; 92 92 93 93 ret = rfkill_register(priv->rfkill); 94 94 if (ret) { ··· 92 102 } 93 103 94 104 IWL_DEBUG_RF_KILL(priv, "RFKILL initialization complete.\n"); 95 - return ret; 105 + return 0; 96 106 97 107 free_rfkill: 98 - if (priv->rfkill != NULL) 99 - rfkill_free(priv->rfkill); 108 + rfkill_destroy(priv->rfkill); 100 109 priv->rfkill = NULL; 101 110 102 111 error: ··· 107 118 void iwl_rfkill_unregister(struct iwl_priv *priv) 108 119 { 109 120 110 - if (priv->rfkill) 121 + if (priv->rfkill) { 111 122 rfkill_unregister(priv->rfkill); 123 + rfkill_destroy(priv->rfkill); 124 + } 112 125 113 126 priv->rfkill = NULL; 114 127 } ··· 122 131 if (!priv->rfkill) 123 132 return; 124 133 125 - if (iwl_is_rfkill_hw(priv)) { 126 - rfkill_force_state(priv->rfkill, RFKILL_STATE_HARD_BLOCKED); 127 - return; 128 - } 129 - 130 - if (!iwl_is_rfkill_sw(priv)) 131 - rfkill_force_state(priv->rfkill, RFKILL_STATE_UNBLOCKED); 134 + if (rfkill_set_hw_state(priv->rfkill, 135 + !!iwl_is_rfkill_hw(priv))) 136 + iwl_radio_kill_sw_disable_radio(priv); 132 137 else 133 - rfkill_force_state(priv->rfkill, RFKILL_STATE_SOFT_BLOCKED); 138 + iwl_radio_kill_sw_enable_radio(priv); 134 139 } 135 140 EXPORT_SYMBOL(iwl_rfkill_set_hw_state);
+31 -25
drivers/net/wireless/iwlwifi/iwl-sta.c
··· 75 75 return IWL_AP_ID; 76 76 } else { 77 77 u8 *da = ieee80211_get_DA(hdr); 78 - return priv->cfg->ops->smgmt->find_station(priv, da); 78 + return iwl_find_station(priv, da); 79 79 } 80 80 } 81 81 EXPORT_SYMBOL(iwl_get_ra_sta_id); ··· 86 86 87 87 spin_lock_irqsave(&priv->sta_lock, flags); 88 88 89 - if (!(priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE) && 90 - !(priv->stations_39[sta_id].used & IWL_STA_DRIVER_ACTIVE)) 89 + if (!(priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE)) 91 90 IWL_ERR(priv, "ACTIVATE a non DRIVER active station %d\n", 92 91 sta_id); 93 92 ··· 227 228 } 228 229 229 230 /** 230 - * iwl_add_station_flags - Add station to tables in driver and device 231 + * iwl_add_station - Add station to tables in driver and device 231 232 */ 232 - u8 iwl_add_station_flags(struct iwl_priv *priv, const u8 *addr, int is_ap, 233 - u8 flags, struct ieee80211_sta_ht_cap *ht_info) 233 + u8 iwl_add_station(struct iwl_priv *priv, const u8 *addr, bool is_ap, u8 flags, 234 + struct ieee80211_sta_ht_cap *ht_info) 234 235 { 235 - int i; 236 - int sta_id = IWL_INVALID_STATION; 237 236 struct iwl_station_entry *station; 238 237 unsigned long flags_spin; 238 + int i; 239 + int sta_id = IWL_INVALID_STATION; 240 + u16 rate; 239 241 240 242 spin_lock_irqsave(&priv->sta_lock, flags_spin); 241 243 if (is_ap) ··· 288 288 priv->iw_mode != NL80211_IFTYPE_ADHOC) 289 289 iwl_set_ht_add_station(priv, sta_id, ht_info); 290 290 291 + /* 3945 only */ 292 + rate = (priv->band == IEEE80211_BAND_5GHZ) ? 293 + IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP; 294 + /* Turn on both antennas for the station... */ 295 + station->sta.rate_n_flags = cpu_to_le16(rate | RATE_MCS_ANT_AB_MSK); 296 + 291 297 spin_unlock_irqrestore(&priv->sta_lock, flags_spin); 292 298 293 299 /* Add station to device's station table */ ··· 301 295 return sta_id; 302 296 303 297 } 304 - EXPORT_SYMBOL(iwl_add_station_flags); 298 + EXPORT_SYMBOL(iwl_add_station); 305 299 306 300 static void iwl_sta_ucode_deactivate(struct iwl_priv *priv, const char *addr) 307 301 { 308 302 unsigned long flags; 309 - u8 sta_id = priv->cfg->ops->smgmt->find_station(priv, addr); 303 + u8 sta_id = iwl_find_station(priv, addr); 310 304 311 305 BUG_ON(sta_id == IWL_INVALID_STATION); 312 306 ··· 414 408 /** 415 409 * iwl_remove_station - Remove driver's knowledge of station. 416 410 */ 417 - int iwl_remove_station(struct iwl_priv *priv, const u8 *addr, int is_ap) 411 + int iwl_remove_station(struct iwl_priv *priv, const u8 *addr, bool is_ap) 418 412 { 419 413 int sta_id = IWL_INVALID_STATION; 420 414 int i, ret = -EINVAL; ··· 773 767 unsigned long flags; 774 768 int i; 775 769 776 - sta_id = priv->cfg->ops->smgmt->find_station(priv, addr); 770 + sta_id = iwl_find_station(priv, addr); 777 771 if (sta_id == IWL_INVALID_STATION) { 778 772 IWL_DEBUG_MAC80211(priv, "leave - %pM not in station map.\n", 779 773 addr); ··· 952 946 * calling this function (which runs REPLY_TX_LINK_QUALITY_CMD, 953 947 * which requires station table entry to exist). 954 948 */ 955 - static void iwl_sta_init_lq(struct iwl_priv *priv, const u8 *addr, int is_ap) 949 + static void iwl_sta_init_lq(struct iwl_priv *priv, const u8 *addr, bool is_ap) 956 950 { 957 951 int i, r; 958 952 struct iwl_link_quality_cmd link_cmd = { ··· 985 979 link_cmd.general_params.single_stream_ant_msk = 986 980 first_antenna(priv->hw_params.valid_tx_ant); 987 981 link_cmd.general_params.dual_stream_ant_msk = 3; 988 - link_cmd.agg_params.agg_dis_start_th = 3; 989 - link_cmd.agg_params.agg_time_limit = cpu_to_le16(4000); 982 + link_cmd.agg_params.agg_dis_start_th = LINK_QUAL_AGG_DISABLE_START_DEF; 983 + link_cmd.agg_params.agg_time_limit = 984 + cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF); 990 985 991 986 /* Update the rate scaling for control frame Tx to AP */ 992 987 link_cmd.sta_id = is_ap ? IWL_AP_ID : priv->hw_params.bcast_sta_id; ··· 1002 995 * there is only one AP station with id= IWL_AP_ID 1003 996 * NOTE: mutex must be held before calling this function 1004 997 */ 1005 - int iwl_rxon_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap) 998 + int iwl_rxon_add_station(struct iwl_priv *priv, const u8 *addr, bool is_ap) 1006 999 { 1007 1000 struct ieee80211_sta *sta; 1008 1001 struct ieee80211_sta_ht_cap ht_config; ··· 1027 1020 rcu_read_unlock(); 1028 1021 } 1029 1022 1030 - sta_id = priv->cfg->ops->smgmt->add_station(priv, addr, is_ap, 1031 - 0, cur_ht_config); 1023 + sta_id = iwl_add_station(priv, addr, is_ap, CMD_SYNC, cur_ht_config); 1032 1024 1033 1025 /* Set up default rate scaling table in device's station table */ 1034 1026 iwl_sta_init_lq(priv, addr, is_ap); ··· 1060 1054 1061 1055 /* If we are an AP, then find the station, or use BCAST */ 1062 1056 case NL80211_IFTYPE_AP: 1063 - sta_id = priv->cfg->ops->smgmt->find_station(priv, hdr->addr1); 1057 + sta_id = iwl_find_station(priv, hdr->addr1); 1064 1058 if (sta_id != IWL_INVALID_STATION) 1065 1059 return sta_id; 1066 1060 return priv->hw_params.bcast_sta_id; ··· 1068 1062 /* If this frame is going out to an IBSS network, find the station, 1069 1063 * or create a new station table entry */ 1070 1064 case NL80211_IFTYPE_ADHOC: 1071 - sta_id = priv->cfg->ops->smgmt->find_station(priv, hdr->addr1); 1065 + sta_id = iwl_find_station(priv, hdr->addr1); 1072 1066 if (sta_id != IWL_INVALID_STATION) 1073 1067 return sta_id; 1074 1068 1075 1069 /* Create new station table entry */ 1076 - sta_id = priv->cfg->ops->smgmt->add_station(priv, hdr->addr1, 1077 - 0, CMD_ASYNC, NULL); 1070 + sta_id = iwl_add_station(priv, hdr->addr1, false, 1071 + CMD_ASYNC, NULL); 1078 1072 1079 1073 if (sta_id != IWL_INVALID_STATION) 1080 1074 return sta_id; ··· 1117 1111 unsigned long flags; 1118 1112 int sta_id; 1119 1113 1120 - sta_id = priv->cfg->ops->smgmt->find_station(priv, addr); 1114 + sta_id = iwl_find_station(priv, addr); 1121 1115 if (sta_id == IWL_INVALID_STATION) 1122 1116 return -ENXIO; 1123 1117 ··· 1139 1133 unsigned long flags; 1140 1134 int sta_id; 1141 1135 1142 - sta_id = priv->cfg->ops->smgmt->find_station(priv, addr); 1136 + sta_id = iwl_find_station(priv, addr); 1143 1137 if (sta_id == IWL_INVALID_STATION) { 1144 1138 IWL_ERR(priv, "Invalid station for AGG tid %d\n", tid); 1145 1139 return -ENXIO; ··· 1174 1168 void iwl_update_ps_mode(struct iwl_priv *priv, u16 ps_bit, u8 *addr) 1175 1169 { 1176 1170 /* FIXME: need locking over ps_status ??? */ 1177 - u8 sta_id = priv->cfg->ops->smgmt->find_station(priv, addr); 1171 + u8 sta_id = iwl_find_station(priv, addr); 1178 1172 1179 1173 if (sta_id != IWL_INVALID_STATION) { 1180 1174 u8 sta_awake = priv->stations[sta_id].
+3 -4
drivers/net/wireless/iwlwifi/iwl-sta.h
··· 51 51 struct ieee80211_key_conf *keyconf, 52 52 const u8 *addr, u32 iv32, u16 *phase1key); 53 53 54 - int iwl_rxon_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap); 55 - int iwl_remove_station(struct iwl_priv *priv, const u8 *addr, int is_ap); 54 + int iwl_rxon_add_station(struct iwl_priv *priv, const u8 *addr, bool is_ap); 55 + int iwl_remove_station(struct iwl_priv *priv, const u8 *addr, bool is_ap); 56 56 void iwl_clear_stations_table(struct iwl_priv *priv); 57 57 int iwl_get_free_ucode_key_index(struct iwl_priv *priv); 58 58 int iwl_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr); 59 59 int iwl_get_ra_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr); 60 60 int iwl_send_add_sta(struct iwl_priv *priv, 61 61 struct iwl_addsta_cmd *sta, u8 flags); 62 - u8 iwl_add_station_flags(struct iwl_priv *priv, const u8 *addr, 63 - int is_ap, u8 flags, 62 + u8 iwl_add_station(struct iwl_priv *priv, const u8 *addr, bool is_ap, u8 flags, 64 63 struct ieee80211_sta_ht_cap *ht_info); 65 64 void iwl_sta_tx_modify_enable_tid(struct iwl_priv *priv, int sta_id, int tid); 66 65 int iwl_sta_rx_agg_start(struct iwl_priv *priv,
+53 -175
drivers/net/wireless/iwlwifi/iwl3945-base.c
··· 95 95 /* the rest are 0 by default */ 96 96 }; 97 97 98 - /*************** STATION TABLE MANAGEMENT **** 99 - * mac80211 should be examined to determine if sta_info is duplicating 100 - * the functionality provided here 101 - */ 102 - 103 - /**************************************************************/ 104 - #if 0 /* temporary disable till we add real remove station */ 105 - /** 106 - * iwl3945_remove_station - Remove driver's knowledge of station. 107 - * 108 - * NOTE: This does not remove station from device's station table. 109 - */ 110 - static u8 iwl3945_remove_station(struct iwl_priv *priv, const u8 *addr, int is_ap) 111 - { 112 - int index = IWL_INVALID_STATION; 113 - int i; 114 - unsigned long flags; 115 - 116 - spin_lock_irqsave(&priv->sta_lock, flags); 117 - 118 - if (is_ap) 119 - index = IWL_AP_ID; 120 - else if (is_broadcast_ether_addr(addr)) 121 - index = priv->hw_params.bcast_sta_id; 122 - else 123 - for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) 124 - if (priv->stations_39[i].used && 125 - !compare_ether_addr(priv->stations_39[i].sta.sta.addr, 126 - addr)) { 127 - index = i; 128 - break; 129 - } 130 - 131 - if (unlikely(index == IWL_INVALID_STATION)) 132 - goto out; 133 - 134 - if (priv->stations_39[index].used) { 135 - priv->stations_39[index].used = 0; 136 - priv->num_stations--; 137 - } 138 - 139 - BUG_ON(priv->num_stations < 0); 140 - 141 - out: 142 - spin_unlock_irqrestore(&priv->sta_lock, flags); 143 - return 0; 144 - } 145 - #endif 146 - 147 - /** 148 - * iwl3945_clear_stations_table - Clear the driver's station table 149 - * 150 - * NOTE: This does not clear or otherwise alter the device's station table. 151 - */ 152 - void iwl3945_clear_stations_table(struct iwl_priv *priv) 153 - { 154 - unsigned long flags; 155 - 156 - spin_lock_irqsave(&priv->sta_lock, flags); 157 - 158 - priv->num_stations = 0; 159 - memset(priv->stations_39, 0, sizeof(priv->stations_39)); 160 - 161 - spin_unlock_irqrestore(&priv->sta_lock, flags); 162 - } 163 - 164 - /** 165 - * iwl3945_add_station - Add station to station tables in driver and device 166 - */ 167 - u8 iwl3945_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap, u8 flags, struct ieee80211_sta_ht_cap *ht_info) 168 - { 169 - int i; 170 - int index = IWL_INVALID_STATION; 171 - struct iwl3945_station_entry *station; 172 - unsigned long flags_spin; 173 - u8 rate; 174 - 175 - spin_lock_irqsave(&priv->sta_lock, flags_spin); 176 - if (is_ap) 177 - index = IWL_AP_ID; 178 - else if (is_broadcast_ether_addr(addr)) 179 - index = priv->hw_params.bcast_sta_id; 180 - else 181 - for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) { 182 - if (!compare_ether_addr(priv->stations_39[i].sta.sta.addr, 183 - addr)) { 184 - index = i; 185 - break; 186 - } 187 - 188 - if (!priv->stations_39[i].used && 189 - index == IWL_INVALID_STATION) 190 - index = i; 191 - } 192 - 193 - /* These two conditions has the same outcome but keep them separate 194 - since they have different meaning */ 195 - if (unlikely(index == IWL_INVALID_STATION)) { 196 - spin_unlock_irqrestore(&priv->sta_lock, flags_spin); 197 - return index; 198 - } 199 - 200 - if (priv->stations_39[index].used && 201 - !compare_ether_addr(priv->stations_39[index].sta.sta.addr, addr)) { 202 - spin_unlock_irqrestore(&priv->sta_lock, flags_spin); 203 - return index; 204 - } 205 - 206 - IWL_DEBUG_ASSOC(priv, "Add STA ID %d: %pM\n", index, addr); 207 - station = &priv->stations_39[index]; 208 - station->used = 1; 209 - priv->num_stations++; 210 - 211 - /* Set up the REPLY_ADD_STA command to send to device */ 212 - memset(&station->sta, 0, sizeof(struct iwl3945_addsta_cmd)); 213 - memcpy(station->sta.sta.addr, addr, ETH_ALEN); 214 - station->sta.mode = 0; 215 - station->sta.sta.sta_id = index; 216 - station->sta.station_flags = 0; 217 - 218 - if (priv->band == IEEE80211_BAND_5GHZ) 219 - rate = IWL_RATE_6M_PLCP; 220 - else 221 - rate = IWL_RATE_1M_PLCP; 222 - 223 - /* Turn on both antennas for the station... */ 224 - station->sta.rate_n_flags = 225 - iwl3945_hw_set_rate_n_flags(rate, RATE_MCS_ANT_AB_MSK); 226 - 227 - spin_unlock_irqrestore(&priv->sta_lock, flags_spin); 228 - 229 - /* Add station to device's station table */ 230 - iwl_send_add_sta(priv, 231 - (struct iwl_addsta_cmd *)&station->sta, flags); 232 - return index; 233 - 234 - } 235 - 236 98 /** 237 99 * iwl3945_get_antenna_flags - Get antenna flags for RXON command 238 100 * @priv: eeprom and antenna fields are used to determine antenna flags ··· 151 289 key_flags &= ~STA_KEY_FLG_INVALID; 152 290 153 291 spin_lock_irqsave(&priv->sta_lock, flags); 154 - priv->stations_39[sta_id].keyinfo.alg = keyconf->alg; 155 - priv->stations_39[sta_id].keyinfo.keylen = keyconf->keylen; 156 - memcpy(priv->stations_39[sta_id].keyinfo.key, keyconf->key, 292 + priv->stations[sta_id].keyinfo.alg = keyconf->alg; 293 + priv->stations[sta_id].keyinfo.keylen = keyconf->keylen; 294 + memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key, 157 295 keyconf->keylen); 158 296 159 - memcpy(priv->stations_39[sta_id].sta.key.key, keyconf->key, 297 + memcpy(priv->stations[sta_id].sta.key.key, keyconf->key, 160 298 keyconf->keylen); 161 299 162 - if ((priv->stations_39[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK) 300 + if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK) 163 301 == STA_KEY_FLG_NO_ENC) 164 - priv->stations_39[sta_id].sta.key.key_offset = 302 + priv->stations[sta_id].sta.key.key_offset = 165 303 iwl_get_free_ucode_key_index(priv); 166 304 /* else, we are overriding an existing key => no need to allocated room 167 305 * in uCode. */ 168 306 169 - WARN(priv->stations_39[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET, 307 + WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET, 170 308 "no space for a new key"); 171 309 172 - priv->stations_39[sta_id].sta.key.key_flags = key_flags; 173 - priv->stations_39[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; 174 - priv->stations_39[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; 310 + priv->stations[sta_id].sta.key.key_flags = key_flags; 311 + priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; 312 + priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; 175 313 176 314 IWL_DEBUG_INFO(priv, "hwcrypto: modify ucode station key info\n"); 177 315 178 - ret = iwl_send_add_sta(priv, 179 - (struct iwl_addsta_cmd *)&priv->stations_39[sta_id].sta, CMD_ASYNC); 316 + ret = iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC); 180 317 181 318 spin_unlock_irqrestore(&priv->sta_lock, flags); 182 319 ··· 201 340 unsigned long flags; 202 341 203 342 spin_lock_irqsave(&priv->sta_lock, flags); 204 - memset(&priv->stations_39[sta_id].keyinfo, 0, sizeof(struct iwl_hw_key)); 205 - memset(&priv->stations_39[sta_id].sta.key, 0, 343 + memset(&priv->stations[sta_id].keyinfo, 0, sizeof(struct iwl_hw_key)); 344 + memset(&priv->stations[sta_id].sta.key, 0, 206 345 sizeof(struct iwl4965_keyinfo)); 207 - priv->stations_39[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC; 208 - priv->stations_39[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; 209 - priv->stations_39[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; 346 + priv->stations[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC; 347 + priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; 348 + priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; 210 349 spin_unlock_irqrestore(&priv->sta_lock, flags); 211 350 212 351 IWL_DEBUG_INFO(priv, "hwcrypto: clear ucode station key info\n"); 213 - iwl_send_add_sta(priv, 214 - (struct iwl_addsta_cmd *)&priv->stations_39[sta_id].sta, 0); 352 + iwl_send_add_sta(priv, &priv->stations[sta_id].sta, 0); 215 353 return 0; 216 354 } 217 355 ··· 438 578 int sta_id) 439 579 { 440 580 struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload; 441 - struct iwl_hw_key *keyinfo = &priv->stations_39[sta_id].keyinfo; 581 + struct iwl_hw_key *keyinfo = &priv->stations[sta_id].keyinfo; 442 582 443 583 switch (keyinfo->alg) { 444 584 case ALG_CCMP: ··· 613 753 if (ieee80211_is_data_qos(fc)) { 614 754 qc = ieee80211_get_qos_ctl(hdr); 615 755 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK; 616 - seq_number = priv->stations_39[sta_id].tid[tid].seq_number & 756 + seq_number = priv->stations[sta_id].tid[tid].seq_number & 617 757 IEEE80211_SCTL_SEQ; 618 758 hdr->seq_ctrl = cpu_to_le16(seq_number) | 619 759 (hdr->seq_ctrl & ··· 673 813 if (!ieee80211_has_morefrags(hdr->frame_control)) { 674 814 txq->need_update = 1; 675 815 if (qc) 676 - priv->stations_39[sta_id].tid[tid].seq_number = seq_number; 816 + priv->stations[sta_id].tid[tid].seq_number = seq_number; 677 817 } else { 678 818 wait_write_ptr = 1; 679 819 txq->need_update = 0; ··· 1176 1316 1177 1317 /* If we've added more space for the firmware to place data, tell it. 1178 1318 * Increment device's write pointer in multiples of 8. */ 1179 - if ((write != (rxq->write & ~0x7)) 1319 + if ((rxq->write_actual != (rxq->write & ~0x7)) 1180 1320 || (abs(rxq->write - rxq->read) > 7)) { 1181 1321 spin_lock_irqsave(&rxq->lock, flags); 1182 1322 rxq->need_update = 1; ··· 1197 1337 * Also restock the Rx queue via iwl3945_rx_queue_restock. 1198 1338 * This is called as a scheduled work item (except for during initialization) 1199 1339 */ 1200 - static void iwl3945_rx_allocate(struct iwl_priv *priv) 1340 + static void iwl3945_rx_allocate(struct iwl_priv *priv, gfp_t priority) 1201 1341 { 1202 1342 struct iwl_rx_queue *rxq = &priv->rxq; 1203 1343 struct list_head *element; ··· 1220 1360 /* Alloc a new receive buffer */ 1221 1361 rxb->skb = 1222 1362 alloc_skb(priv->hw_params.rx_buf_size, 1223 - GFP_KERNEL); 1363 + priority); 1224 1364 if (!rxb->skb) { 1225 1365 if (net_ratelimit()) 1226 1366 IWL_CRIT(priv, ": Can not allocate SKB buffers\n"); ··· 1279 1419 * not restocked the Rx queue with fresh buffers */ 1280 1420 rxq->read = rxq->write = 0; 1281 1421 rxq->free_count = 0; 1422 + rxq->write_actual = 0; 1282 1423 spin_unlock_irqrestore(&rxq->lock, flags); 1283 1424 } 1284 1425 ··· 1288 1427 struct iwl_priv *priv = data; 1289 1428 unsigned long flags; 1290 1429 1291 - iwl3945_rx_allocate(priv); 1430 + iwl3945_rx_allocate(priv, GFP_KERNEL); 1292 1431 1293 1432 spin_lock_irqsave(&priv->lock, flags); 1294 1433 iwl3945_rx_queue_restock(priv); 1295 1434 spin_unlock_irqrestore(&priv->lock, flags); 1296 1435 } 1436 + 1437 + static void iwl3945_rx_replenish_now(struct iwl_priv *priv) 1438 + { 1439 + iwl3945_rx_allocate(priv, GFP_ATOMIC); 1440 + 1441 + iwl3945_rx_queue_restock(priv); 1442 + } 1443 + 1297 1444 1298 1445 /* Assumes that the skb field of the buffers in 'pool' is kept accurate. 1299 1446 * If an SKB has been detached, the POOL needs to have its SKB set to NULL ··· 1425 1556 unsigned long flags; 1426 1557 u8 fill_rx = 0; 1427 1558 u32 count = 8; 1559 + int total_empty = 0; 1428 1560 1429 1561 /* uCode's read index (stored in shared DRAM) indicates the last Rx 1430 1562 * buffer that the driver may process (last buffer filled by ucode). */ 1431 1563 r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF; 1432 1564 i = rxq->read; 1433 1565 1434 - if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2)) 1566 + /* calculate total frames need to be restock after handling RX */ 1567 + total_empty = r - priv->rxq.write_actual; 1568 + if (total_empty < 0) 1569 + total_empty += RX_QUEUE_SIZE; 1570 + 1571 + if (total_empty > (RX_QUEUE_SIZE / 2)) 1435 1572 fill_rx = 1; 1436 1573 /* Rx interrupt, but nothing sent from uCode */ 1437 1574 if (i == r) ··· 1514 1639 count++; 1515 1640 if (count >= 8) { 1516 1641 priv->rxq.read = i; 1517 - iwl3945_rx_queue_restock(priv); 1642 + iwl3945_rx_replenish_now(priv); 1518 1643 count = 0; 1519 1644 } 1520 1645 } ··· 1522 1647 1523 1648 /* Backtrack one entry */ 1524 1649 priv->rxq.read = i; 1525 - iwl3945_rx_queue_restock(priv); 1650 + if (fill_rx) 1651 + iwl3945_rx_replenish_now(priv); 1652 + else 1653 + iwl3945_rx_queue_restock(priv); 1526 1654 } 1527 1655 1528 1656 /* call this function to flush any scheduled tasklet */ ··· 2467 2589 goto restart; 2468 2590 } 2469 2591 2470 - priv->cfg->ops->smgmt->clear_station_table(priv); 2592 + iwl_clear_stations_table(priv); 2471 2593 2472 2594 rfkill = iwl_read_prph(priv, APMG_RFKILL_REG); 2473 2595 IWL_DEBUG_INFO(priv, "RFKILL status: 0x%x\n", rfkill); ··· 2559 2681 set_bit(STATUS_EXIT_PENDING, &priv->status); 2560 2682 2561 2683 iwl3945_led_unregister(priv); 2562 - priv->cfg->ops->smgmt->clear_station_table(priv); 2684 + iwl_clear_stations_table(priv); 2563 2685 2564 2686 /* Unblock any waiting calls */ 2565 2687 wake_up_interruptible_all(&priv->wait_command_queue); ··· 2711 2833 2712 2834 for (i = 0; i < MAX_HW_RESTARTS; i++) { 2713 2835 2714 - priv->cfg->ops->smgmt->clear_station_table(priv); 2836 + iwl_clear_stations_table(priv); 2715 2837 2716 2838 /* load bootstrap state machine, 2717 2839 * load bootstrap program into processor's memory, ··· 3125 3247 case NL80211_IFTYPE_ADHOC: 3126 3248 3127 3249 priv->assoc_id = 1; 3128 - priv->cfg->ops->smgmt->add_station(priv, priv->bssid, 0, 0, NULL); 3250 + iwl_add_station(priv, priv->bssid, 0, CMD_SYNC, NULL); 3129 3251 iwl3945_sync_sta(priv, IWL_STA_ID, 3130 3252 (priv->band == IEEE80211_BAND_5GHZ) ? 3131 3253 IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP, ··· 3316 3438 /* restore RXON assoc */ 3317 3439 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; 3318 3440 iwlcore_commit_rxon(priv); 3319 - priv->cfg->ops->smgmt->add_station(priv, iwl_bcast_addr, 0, 0, NULL); 3441 + iwl_add_station(priv, iwl_bcast_addr, 0, CMD_SYNC, NULL); 3320 3442 } 3321 3443 iwl3945_send_beacon_cmd(priv); 3322 3444 ··· 3347 3469 static_key = !iwl_is_associated(priv); 3348 3470 3349 3471 if (!static_key) { 3350 - sta_id = priv->cfg->ops->smgmt->find_station(priv, addr); 3472 + sta_id = iwl_find_station(priv, addr); 3351 3473 if (sta_id == IWL_INVALID_STATION) { 3352 3474 IWL_DEBUG_MAC80211(priv, "leave - %pM not in station map.\n", 3353 3475 addr); ··· 3922 4044 mutex_init(&priv->mutex); 3923 4045 3924 4046 /* Clear the driver's (not device's) station table */ 3925 - priv->cfg->ops->smgmt->clear_station_table(priv); 4047 + iwl_clear_stations_table(priv); 3926 4048 3927 4049 priv->data_retry_limit = -1; 3928 4050 priv->ieee_channels = NULL; ··· 4285 4407 iwl3945_hw_txq_ctx_free(priv); 4286 4408 4287 4409 iwl3945_unset_hw_params(priv); 4288 - priv->cfg->ops->smgmt->clear_station_table(priv); 4410 + iwl_clear_stations_table(priv); 4289 4411 4290 4412 /*netif_stop_queue(dev); */ 4291 4413 flush_workqueue(priv->workqueue);
+1 -2
drivers/net/wireless/iwmc3200wifi/Kconfig
··· 1 1 config IWM 2 2 tristate "Intel Wireless Multicomm 3200 WiFi driver" 3 3 depends on MMC && WLAN_80211 && EXPERIMENTAL 4 + depends on CFG80211 4 5 select WIRELESS_EXT 5 - select CFG80211 6 6 select FW_LOADER 7 - select RFKILL 8 7 9 8 config IWM_DEBUG 10 9 bool "Enable full debugging output in iwmc3200wifi"
+1 -1
drivers/net/wireless/iwmc3200wifi/Makefile
··· 1 1 obj-$(CONFIG_IWM) := iwmc3200wifi.o 2 2 iwmc3200wifi-objs += main.o netdev.o rx.o tx.o sdio.o hal.o fw.o 3 - iwmc3200wifi-objs += commands.o wext.o cfg80211.o eeprom.o rfkill.o 3 + iwmc3200wifi-objs += commands.o wext.o cfg80211.o eeprom.o 4 4 5 5 iwmc3200wifi-$(CONFIG_IWM_DEBUG) += debugfs.o
+1 -1
drivers/net/wireless/iwmc3200wifi/cfg80211.c
··· 268 268 269 269 iwm->conf.frag_threshold = wiphy->frag_threshold; 270 270 271 - ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX, 271 + ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_FA_CFG_FIX, 272 272 CFG_FRAG_THRESHOLD, 273 273 iwm->conf.frag_threshold); 274 274 if (ret < 0)
+1 -1
drivers/net/wireless/iwmc3200wifi/fw.c
··· 72 72 } 73 73 74 74 if (fw->size < IWM_HDR_LEN) { 75 - IWM_ERR(iwm, "FW is too small (%d)\n", fw->size); 75 + IWM_ERR(iwm, "FW is too small (%zu)\n", fw->size); 76 76 return -EINVAL; 77 77 } 78 78
-4
drivers/net/wireless/iwmc3200wifi/iwm.h
··· 343 343 struct iwm_wifi_cmd *cmd); 344 344 void iwm_rx_free(struct iwm_priv *iwm); 345 345 346 - /* RF Kill API */ 347 - int iwm_rfkill_init(struct iwm_priv *iwm); 348 - void iwm_rfkill_exit(struct iwm_priv *iwm); 349 - 350 346 #endif
-10
drivers/net/wireless/iwmc3200wifi/netdev.c
··· 136 136 137 137 wdev->netdev = ndev; 138 138 139 - ret = iwm_rfkill_init(iwm); 140 - if (ret) { 141 - dev_err(dev, "Failed to init rfkill\n"); 142 - goto out_rfkill; 143 - } 144 - 145 139 return iwm; 146 - 147 - out_rfkill: 148 - unregister_netdev(ndev); 149 140 150 141 out_ndev: 151 142 free_netdev(ndev); ··· 153 162 if (!iwm_to_ndev(iwm)) 154 163 return; 155 164 156 - iwm_rfkill_exit(iwm); 157 165 unregister_netdev(iwm_to_ndev(iwm)); 158 166 free_netdev(iwm_to_ndev(iwm)); 159 167 iwm_wdev_free(iwm);
-88
drivers/net/wireless/iwmc3200wifi/rfkill.c
··· 1 - /* 2 - * Intel Wireless Multicomm 3200 WiFi driver 3 - * 4 - * Copyright (C) 2009 Intel Corporation <ilw@linux.intel.com> 5 - * Samuel Ortiz <samuel.ortiz@intel.com> 6 - * Zhu Yi <yi.zhu@intel.com> 7 - * 8 - * This program is free software; you can redistribute it and/or 9 - * modify it under the terms of the GNU General Public License version 10 - * 2 as published by the Free Software Foundation. 11 - * 12 - * This program is distributed in the hope that it will be useful, 13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 - * GNU General Public License for more details. 16 - * 17 - * You should have received a copy of the GNU General Public License 18 - * along with this program; if not, write to the Free Software 19 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 20 - * 02110-1301, USA. 21 - * 22 - */ 23 - 24 - #include <linux/rfkill.h> 25 - 26 - #include "iwm.h" 27 - 28 - static int iwm_rfkill_soft_toggle(void *data, enum rfkill_state state) 29 - { 30 - struct iwm_priv *iwm = data; 31 - 32 - switch (state) { 33 - case RFKILL_STATE_UNBLOCKED: 34 - if (test_bit(IWM_RADIO_RFKILL_HW, &iwm->radio)) 35 - return -EBUSY; 36 - 37 - if (test_and_clear_bit(IWM_RADIO_RFKILL_SW, &iwm->radio) && 38 - (iwm_to_ndev(iwm)->flags & IFF_UP)) 39 - iwm_up(iwm); 40 - 41 - break; 42 - case RFKILL_STATE_SOFT_BLOCKED: 43 - if (!test_and_set_bit(IWM_RADIO_RFKILL_SW, &iwm->radio)) 44 - iwm_down(iwm); 45 - 46 - break; 47 - default: 48 - break; 49 - } 50 - 51 - return 0; 52 - } 53 - 54 - int iwm_rfkill_init(struct iwm_priv *iwm) 55 - { 56 - int ret; 57 - 58 - iwm->rfkill = rfkill_allocate(iwm_to_dev(iwm), RFKILL_TYPE_WLAN); 59 - if (!iwm->rfkill) { 60 - IWM_ERR(iwm, "Unable to allocate rfkill device\n"); 61 - return -ENOMEM; 62 - } 63 - 64 - iwm->rfkill->name = KBUILD_MODNAME; 65 - iwm->rfkill->data = iwm; 66 - iwm->rfkill->state = RFKILL_STATE_UNBLOCKED; 67 - iwm->rfkill->toggle_radio = iwm_rfkill_soft_toggle; 68 - 69 - ret = rfkill_register(iwm->rfkill); 70 - if (ret) { 71 - IWM_ERR(iwm, "Failed to register rfkill device\n"); 72 - goto fail; 73 - } 74 - 75 - return 0; 76 - fail: 77 - rfkill_free(iwm->rfkill); 78 - return ret; 79 - } 80 - 81 - void iwm_rfkill_exit(struct iwm_priv *iwm) 82 - { 83 - if (iwm->rfkill) 84 - rfkill_unregister(iwm->rfkill); 85 - 86 - rfkill_free(iwm->rfkill); 87 - iwm->rfkill = NULL; 88 - }
+1 -1
drivers/net/wireless/iwmc3200wifi/sdio.c
··· 395 395 .debugfs_init = if_sdio_debugfs_init, 396 396 .debugfs_exit = if_sdio_debugfs_exit, 397 397 .umac_name = "iwmc3200wifi-umac-sdio.bin", 398 - .calib_lmac_name = "iwmc3200wifi-lmac-calib-sdio.bin", 398 + .calib_lmac_name = "iwmc3200wifi-calib-sdio.bin", 399 399 .lmac_name = "iwmc3200wifi-lmac-sdio.bin", 400 400 }; 401 401
+12 -14
drivers/net/wireless/libertas/11d.c
··· 207 207 lbs_deb_11d("nr_subband=%x\n", domaininfo->nr_subband); 208 208 lbs_deb_hex(LBS_DEB_11D, "domaininfo", (char *)domaininfo, 209 209 COUNTRY_CODE_LEN + 1 + 210 - sizeof(struct ieeetypes_subbandset) * nr_subband); 210 + sizeof(struct ieee_subbandset) * nr_subband); 211 211 return 0; 212 212 } 213 213 ··· 302 302 * @param parsed_region_chan pointer to parsed_region_chan_11d 303 303 * @return 0 304 304 */ 305 - static int parse_domain_info_11d(struct ieeetypes_countryinfofullset* 306 - countryinfo, 305 + static int parse_domain_info_11d(struct ieee_ie_country_info_full_set *countryinfo, 307 306 u8 band, 308 - struct parsed_region_chan_11d * 309 - parsed_region_chan) 307 + struct parsed_region_chan_11d *parsed_region_chan) 310 308 { 311 309 u8 nr_subband, nrchan; 312 310 u8 lastchan, firstchan; ··· 329 331 lbs_deb_hex(LBS_DEB_11D, "countryinfo", (u8 *) countryinfo, 30); 330 332 331 333 if ((*(countryinfo->countrycode)) == 0 332 - || (countryinfo->len <= COUNTRY_CODE_LEN)) { 334 + || (countryinfo->header.len <= COUNTRY_CODE_LEN)) { 333 335 /* No region Info or Wrong region info: treat as No 11D info */ 334 336 goto done; 335 337 } ··· 347 349 memcpy(parsed_region_chan->countrycode, countryinfo->countrycode, 348 350 COUNTRY_CODE_LEN); 349 351 350 - nr_subband = (countryinfo->len - COUNTRY_CODE_LEN) / 351 - sizeof(struct ieeetypes_subbandset); 352 + nr_subband = (countryinfo->header.len - COUNTRY_CODE_LEN) / 353 + sizeof(struct ieee_subbandset); 352 354 353 355 for (j = 0, lastchan = 0; j < nr_subband; j++) { 354 356 ··· 500 502 { 501 503 struct cmd_ds_802_11d_domain_info *pdomaininfo = 502 504 &cmd->params.domaininfo; 503 - struct mrvlietypes_domainparamset *domain = &pdomaininfo->domain; 505 + struct mrvl_ie_domain_param_set *domain = &pdomaininfo->domain; 504 506 u8 nr_subband = priv->domainreg.nr_subband; 505 507 506 508 lbs_deb_enter(LBS_DEB_11D); ··· 522 524 sizeof(domain->countrycode)); 523 525 524 526 domain->header.len = 525 - cpu_to_le16(nr_subband * sizeof(struct ieeetypes_subbandset) + 527 + cpu_to_le16(nr_subband * sizeof(struct ieee_subbandset) + 526 528 sizeof(domain->countrycode)); 527 529 528 530 if (nr_subband) { 529 531 memcpy(domain->subband, priv->domainreg.subband, 530 - nr_subband * sizeof(struct ieeetypes_subbandset)); 532 + nr_subband * sizeof(struct ieee_subbandset)); 531 533 532 534 cmd->size = cpu_to_le16(sizeof(pdomaininfo->action) + 533 535 le16_to_cpu(domain->header.len) + 534 - sizeof(struct mrvlietypesheader) + 536 + sizeof(struct mrvl_ie_header) + 535 537 S_DS_GEN); 536 538 } else { 537 539 cmd->size = ··· 554 556 int lbs_ret_802_11d_domain_info(struct cmd_ds_command *resp) 555 557 { 556 558 struct cmd_ds_802_11d_domain_info *domaininfo = &resp->params.domaininforesp; 557 - struct mrvlietypes_domainparamset *domain = &domaininfo->domain; 559 + struct mrvl_ie_domain_param_set *domain = &domaininfo->domain; 558 560 u16 action = le16_to_cpu(domaininfo->action); 559 561 s16 ret = 0; 560 562 u8 nr_subband = 0; ··· 565 567 (int)le16_to_cpu(resp->size)); 566 568 567 569 nr_subband = (le16_to_cpu(domain->header.len) - COUNTRY_CODE_LEN) / 568 - sizeof(struct ieeetypes_subbandset); 570 + sizeof(struct ieee_subbandset); 569 571 570 572 lbs_deb_11d("domain info resp: nr_subband %d\n", nr_subband); 571 573
+15 -14
drivers/net/wireless/libertas/11d.h
··· 20 20 struct cmd_ds_command; 21 21 22 22 /** Data structure for Country IE*/ 23 - struct ieeetypes_subbandset { 23 + struct ieee_subbandset { 24 24 u8 firstchan; 25 25 u8 nrchan; 26 26 u8 maxtxpwr; 27 27 } __attribute__ ((packed)); 28 28 29 - struct ieeetypes_countryinfoset { 30 - u8 element_id; 31 - u8 len; 29 + struct ieee_ie_country_info_set { 30 + struct ieee_ie_header header; 31 + 32 32 u8 countrycode[COUNTRY_CODE_LEN]; 33 - struct ieeetypes_subbandset subband[1]; 33 + struct ieee_subbandset subband[1]; 34 34 }; 35 35 36 - struct ieeetypes_countryinfofullset { 37 - u8 element_id; 38 - u8 len; 36 + struct ieee_ie_country_info_full_set { 37 + struct ieee_ie_header header; 38 + 39 39 u8 countrycode[COUNTRY_CODE_LEN]; 40 - struct ieeetypes_subbandset subband[MRVDRV_MAX_SUBBAND_802_11D]; 40 + struct ieee_subbandset subband[MRVDRV_MAX_SUBBAND_802_11D]; 41 41 } __attribute__ ((packed)); 42 42 43 - struct mrvlietypes_domainparamset { 44 - struct mrvlietypesheader header; 43 + struct mrvl_ie_domain_param_set { 44 + struct mrvl_ie_header header; 45 + 45 46 u8 countrycode[COUNTRY_CODE_LEN]; 46 - struct ieeetypes_subbandset subband[1]; 47 + struct ieee_subbandset subband[1]; 47 48 } __attribute__ ((packed)); 48 49 49 50 struct cmd_ds_802_11d_domain_info { 50 51 __le16 action; 51 - struct mrvlietypes_domainparamset domain; 52 + struct mrvl_ie_domain_param_set domain; 52 53 } __attribute__ ((packed)); 53 54 54 55 /** domain regulatory information */ ··· 58 57 u8 countrycode[COUNTRY_CODE_LEN]; 59 58 /** No. of subband*/ 60 59 u8 nr_subband; 61 - struct ieeetypes_subbandset subband[MRVDRV_MAX_SUBBAND_802_11D]; 60 + struct ieee_subbandset subband[MRVDRV_MAX_SUBBAND_802_11D]; 62 61 }; 63 62 64 63 struct chan_power_11d {
+393 -365
drivers/net/wireless/libertas/assoc.c
··· 12 12 #include "scan.h" 13 13 #include "cmd.h" 14 14 15 - static int lbs_adhoc_post(struct lbs_private *priv, struct cmd_header *resp); 16 - 17 15 static const u8 bssid_any[ETH_ALEN] __attribute__ ((aligned (2))) = 18 16 { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; 19 17 static const u8 bssid_off[ETH_ALEN] __attribute__ ((aligned (2))) = 20 18 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; 21 19 22 - /* The firmware needs certain bits masked out of the beacon-derviced capability 23 - * field when associating/joining to BSSs. 20 + /* The firmware needs the following bits masked out of the beacon-derived 21 + * capability field when associating/joining to a BSS: 22 + * 9 (QoS), 11 (APSD), 12 (unused), 14 (unused), 15 (unused) 24 23 */ 25 24 #define CAPINFO_MASK (~(0xda00)) 26 25 ··· 101 102 } 102 103 103 104 105 + static u8 iw_auth_to_ieee_auth(u8 auth) 106 + { 107 + if (auth == IW_AUTH_ALG_OPEN_SYSTEM) 108 + return 0x00; 109 + else if (auth == IW_AUTH_ALG_SHARED_KEY) 110 + return 0x01; 111 + else if (auth == IW_AUTH_ALG_LEAP) 112 + return 0x80; 113 + 114 + lbs_deb_join("%s: invalid auth alg 0x%X\n", __func__, auth); 115 + return 0; 116 + } 117 + 118 + /** 119 + * @brief This function prepares the authenticate command. AUTHENTICATE only 120 + * sets the authentication suite for future associations, as the firmware 121 + * handles authentication internally during the ASSOCIATE command. 122 + * 123 + * @param priv A pointer to struct lbs_private structure 124 + * @param bssid The peer BSSID with which to authenticate 125 + * @param auth The authentication mode to use (from wireless.h) 126 + * 127 + * @return 0 or -1 128 + */ 129 + static int lbs_set_authentication(struct lbs_private *priv, u8 bssid[6], u8 auth) 130 + { 131 + struct cmd_ds_802_11_authenticate cmd; 132 + int ret = -1; 133 + DECLARE_MAC_BUF(mac); 134 + 135 + lbs_deb_enter(LBS_DEB_JOIN); 136 + 137 + cmd.hdr.size = cpu_to_le16(sizeof(cmd)); 138 + memcpy(cmd.bssid, bssid, ETH_ALEN); 139 + 140 + cmd.authtype = iw_auth_to_ieee_auth(auth); 141 + 142 + lbs_deb_join("AUTH_CMD: BSSID %s, auth 0x%x\n", 143 + print_mac(mac, bssid), cmd.authtype); 144 + 145 + ret = lbs_cmd_with_response(priv, CMD_802_11_AUTHENTICATE, &cmd); 146 + 147 + lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret); 148 + return ret; 149 + } 150 + 151 + 152 + static int lbs_assoc_post(struct lbs_private *priv, 153 + struct cmd_ds_802_11_associate_response *resp) 154 + { 155 + int ret = 0; 156 + union iwreq_data wrqu; 157 + struct bss_descriptor *bss; 158 + u16 status_code; 159 + 160 + lbs_deb_enter(LBS_DEB_ASSOC); 161 + 162 + if (!priv->in_progress_assoc_req) { 163 + lbs_deb_assoc("ASSOC_RESP: no in-progress assoc request\n"); 164 + ret = -1; 165 + goto done; 166 + } 167 + bss = &priv->in_progress_assoc_req->bss; 168 + 169 + /* 170 + * Older FW versions map the IEEE 802.11 Status Code in the association 171 + * response to the following values returned in resp->statuscode: 172 + * 173 + * IEEE Status Code Marvell Status Code 174 + * 0 -> 0x0000 ASSOC_RESULT_SUCCESS 175 + * 13 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED 176 + * 14 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED 177 + * 15 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED 178 + * 16 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED 179 + * others -> 0x0003 ASSOC_RESULT_REFUSED 180 + * 181 + * Other response codes: 182 + * 0x0001 -> ASSOC_RESULT_INVALID_PARAMETERS (unused) 183 + * 0x0002 -> ASSOC_RESULT_TIMEOUT (internal timer expired waiting for 184 + * association response from the AP) 185 + */ 186 + 187 + status_code = le16_to_cpu(resp->statuscode); 188 + if (priv->fwrelease < 0x09000000) { 189 + switch (status_code) { 190 + case 0x00: 191 + break; 192 + case 0x01: 193 + lbs_deb_assoc("ASSOC_RESP: invalid parameters\n"); 194 + break; 195 + case 0x02: 196 + lbs_deb_assoc("ASSOC_RESP: internal timer " 197 + "expired while waiting for the AP\n"); 198 + break; 199 + case 0x03: 200 + lbs_deb_assoc("ASSOC_RESP: association " 201 + "refused by AP\n"); 202 + break; 203 + case 0x04: 204 + lbs_deb_assoc("ASSOC_RESP: authentication " 205 + "refused by AP\n"); 206 + break; 207 + default: 208 + lbs_deb_assoc("ASSOC_RESP: failure reason 0x%02x " 209 + " unknown\n", status_code); 210 + break; 211 + } 212 + } else { 213 + /* v9+ returns the AP's association response */ 214 + lbs_deb_assoc("ASSOC_RESP: failure reason 0x%02x\n", status_code); 215 + } 216 + 217 + if (status_code) { 218 + lbs_mac_event_disconnected(priv); 219 + ret = -1; 220 + goto done; 221 + } 222 + 223 + lbs_deb_hex(LBS_DEB_ASSOC, "ASSOC_RESP", 224 + (void *) (resp + sizeof (resp->hdr)), 225 + le16_to_cpu(resp->hdr.size) - sizeof (resp->hdr)); 226 + 227 + /* Send a Media Connected event, according to the Spec */ 228 + priv->connect_status = LBS_CONNECTED; 229 + 230 + /* Update current SSID and BSSID */ 231 + memcpy(&priv->curbssparams.ssid, &bss->ssid, IW_ESSID_MAX_SIZE); 232 + priv->curbssparams.ssid_len = bss->ssid_len; 233 + memcpy(priv->curbssparams.bssid, bss->bssid, ETH_ALEN); 234 + 235 + priv->SNR[TYPE_RXPD][TYPE_AVG] = 0; 236 + priv->NF[TYPE_RXPD][TYPE_AVG] = 0; 237 + 238 + memset(priv->rawSNR, 0x00, sizeof(priv->rawSNR)); 239 + memset(priv->rawNF, 0x00, sizeof(priv->rawNF)); 240 + priv->nextSNRNF = 0; 241 + priv->numSNRNF = 0; 242 + 243 + netif_carrier_on(priv->dev); 244 + if (!priv->tx_pending_len) 245 + netif_wake_queue(priv->dev); 246 + 247 + memcpy(wrqu.ap_addr.sa_data, priv->curbssparams.bssid, ETH_ALEN); 248 + wrqu.ap_addr.sa_family = ARPHRD_ETHER; 249 + wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL); 250 + 251 + done: 252 + lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); 253 + return ret; 254 + } 255 + 256 + /** 257 + * @brief This function prepares an association-class command. 258 + * 259 + * @param priv A pointer to struct lbs_private structure 260 + * @param assoc_req The association request describing the BSS to associate 261 + * or reassociate with 262 + * @param command The actual command, either CMD_802_11_ASSOCIATE or 263 + * CMD_802_11_REASSOCIATE 264 + * 265 + * @return 0 or -1 266 + */ 267 + static int lbs_associate(struct lbs_private *priv, 268 + struct assoc_request *assoc_req, 269 + u16 command) 270 + { 271 + struct cmd_ds_802_11_associate cmd; 272 + int ret = 0; 273 + struct bss_descriptor *bss = &assoc_req->bss; 274 + u8 *pos = &(cmd.iebuf[0]); 275 + u16 tmpcap, tmplen, tmpauth; 276 + struct mrvl_ie_ssid_param_set *ssid; 277 + struct mrvl_ie_ds_param_set *ds; 278 + struct mrvl_ie_cf_param_set *cf; 279 + struct mrvl_ie_rates_param_set *rates; 280 + struct mrvl_ie_rsn_param_set *rsn; 281 + struct mrvl_ie_auth_type *auth; 282 + 283 + lbs_deb_enter(LBS_DEB_ASSOC); 284 + 285 + BUG_ON((command != CMD_802_11_ASSOCIATE) && 286 + (command != CMD_802_11_REASSOCIATE)); 287 + 288 + memset(&cmd, 0, sizeof(cmd)); 289 + cmd.hdr.command = cpu_to_le16(command); 290 + 291 + /* Fill in static fields */ 292 + memcpy(cmd.bssid, bss->bssid, ETH_ALEN); 293 + cmd.listeninterval = cpu_to_le16(MRVDRV_DEFAULT_LISTEN_INTERVAL); 294 + 295 + /* Capability info */ 296 + tmpcap = (bss->capability & CAPINFO_MASK); 297 + if (bss->mode == IW_MODE_INFRA) 298 + tmpcap |= WLAN_CAPABILITY_ESS; 299 + cmd.capability = cpu_to_le16(tmpcap); 300 + lbs_deb_assoc("ASSOC_CMD: capability 0x%04x\n", tmpcap); 301 + 302 + /* SSID */ 303 + ssid = (struct mrvl_ie_ssid_param_set *) pos; 304 + ssid->header.type = cpu_to_le16(TLV_TYPE_SSID); 305 + tmplen = bss->ssid_len; 306 + ssid->header.len = cpu_to_le16(tmplen); 307 + memcpy(ssid->ssid, bss->ssid, tmplen); 308 + pos += sizeof(ssid->header) + tmplen; 309 + 310 + ds = (struct mrvl_ie_ds_param_set *) pos; 311 + ds->header.type = cpu_to_le16(TLV_TYPE_PHY_DS); 312 + ds->header.len = cpu_to_le16(1); 313 + ds->channel = bss->phy.ds.channel; 314 + pos += sizeof(ds->header) + 1; 315 + 316 + cf = (struct mrvl_ie_cf_param_set *) pos; 317 + cf->header.type = cpu_to_le16(TLV_TYPE_CF); 318 + tmplen = sizeof(*cf) - sizeof (cf->header); 319 + cf->header.len = cpu_to_le16(tmplen); 320 + /* IE payload should be zeroed, firmware fills it in for us */ 321 + pos += sizeof(*cf); 322 + 323 + rates = (struct mrvl_ie_rates_param_set *) pos; 324 + rates->header.type = cpu_to_le16(TLV_TYPE_RATES); 325 + memcpy(&rates->rates, &bss->rates, MAX_RATES); 326 + tmplen = MAX_RATES; 327 + if (get_common_rates(priv, rates->rates, &tmplen)) { 328 + ret = -1; 329 + goto done; 330 + } 331 + pos += sizeof(rates->header) + tmplen; 332 + rates->header.len = cpu_to_le16(tmplen); 333 + lbs_deb_assoc("ASSOC_CMD: num rates %u\n", tmplen); 334 + 335 + /* Copy the infra. association rates into Current BSS state structure */ 336 + memset(&priv->curbssparams.rates, 0, sizeof(priv->curbssparams.rates)); 337 + memcpy(&priv->curbssparams.rates, &rates->rates, tmplen); 338 + 339 + /* Set MSB on basic rates as the firmware requires, but _after_ 340 + * copying to current bss rates. 341 + */ 342 + lbs_set_basic_rate_flags(rates->rates, tmplen); 343 + 344 + /* Firmware v9+ indicate authentication suites as a TLV */ 345 + if (priv->fwrelease >= 0x09000000) { 346 + DECLARE_MAC_BUF(mac); 347 + 348 + auth = (struct mrvl_ie_auth_type *) pos; 349 + auth->header.type = cpu_to_le16(TLV_TYPE_AUTH_TYPE); 350 + auth->header.len = cpu_to_le16(2); 351 + tmpauth = iw_auth_to_ieee_auth(priv->secinfo.auth_mode); 352 + auth->auth = cpu_to_le16(tmpauth); 353 + pos += sizeof(auth->header) + 2; 354 + 355 + lbs_deb_join("AUTH_CMD: BSSID %s, auth 0x%x\n", 356 + print_mac(mac, bss->bssid), priv->secinfo.auth_mode); 357 + } 358 + 359 + /* WPA/WPA2 IEs */ 360 + if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) { 361 + rsn = (struct mrvl_ie_rsn_param_set *) pos; 362 + /* WPA_IE or WPA2_IE */ 363 + rsn->header.type = cpu_to_le16((u16) assoc_req->wpa_ie[0]); 364 + tmplen = (u16) assoc_req->wpa_ie[1]; 365 + rsn->header.len = cpu_to_le16(tmplen); 366 + memcpy(rsn->rsnie, &assoc_req->wpa_ie[2], tmplen); 367 + lbs_deb_hex(LBS_DEB_JOIN, "ASSOC_CMD: WPA/RSN IE", (u8 *) rsn, 368 + sizeof(rsn->header) + tmplen); 369 + pos += sizeof(rsn->header) + tmplen; 370 + } 371 + 372 + cmd.hdr.size = cpu_to_le16((sizeof(cmd) - sizeof(cmd.iebuf)) + 373 + (u16)(pos - (u8 *) &cmd.iebuf)); 374 + 375 + /* update curbssparams */ 376 + priv->curbssparams.channel = bss->phy.ds.channel; 377 + 378 + if (lbs_parse_dnld_countryinfo_11d(priv, bss)) { 379 + ret = -1; 380 + goto done; 381 + } 382 + 383 + ret = lbs_cmd_with_response(priv, command, &cmd); 384 + if (ret == 0) { 385 + ret = lbs_assoc_post(priv, 386 + (struct cmd_ds_802_11_associate_response *) &cmd); 387 + } 388 + 389 + done: 390 + lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); 391 + return ret; 392 + } 393 + 104 394 /** 105 395 * @brief Associate to a specific BSS discovered in a scan 106 396 * ··· 398 110 * 399 111 * @return 0-success, otherwise fail 400 112 */ 401 - static int lbs_associate(struct lbs_private *priv, 113 + static int lbs_try_associate(struct lbs_private *priv, 402 114 struct assoc_request *assoc_req) 403 115 { 404 116 int ret; ··· 406 118 407 119 lbs_deb_enter(LBS_DEB_ASSOC); 408 120 409 - ret = lbs_prepare_and_send_command(priv, CMD_802_11_AUTHENTICATE, 410 - 0, CMD_OPTION_WAITFORRSP, 411 - 0, assoc_req->bss.bssid); 412 - if (ret) 413 - goto out; 121 + /* FW v9 and higher indicate authentication suites as a TLV in the 122 + * association command, not as a separate authentication command. 123 + */ 124 + if (priv->fwrelease < 0x09000000) { 125 + ret = lbs_set_authentication(priv, assoc_req->bss.bssid, 126 + priv->secinfo.auth_mode); 127 + if (ret) 128 + goto out; 129 + } 414 130 415 131 /* Use short preamble only when both the BSS and firmware support it */ 416 132 if ((priv->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) && ··· 425 133 if (ret) 426 134 goto out; 427 135 428 - ret = lbs_prepare_and_send_command(priv, CMD_802_11_ASSOCIATE, 429 - 0, CMD_OPTION_WAITFORRSP, 0, assoc_req); 136 + ret = lbs_associate(priv, assoc_req, CMD_802_11_ASSOCIATE); 430 137 431 138 out: 432 139 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); 140 + return ret; 141 + } 142 + 143 + static int lbs_adhoc_post(struct lbs_private *priv, 144 + struct cmd_ds_802_11_ad_hoc_result *resp) 145 + { 146 + int ret = 0; 147 + u16 command = le16_to_cpu(resp->hdr.command); 148 + u16 result = le16_to_cpu(resp->hdr.result); 149 + union iwreq_data wrqu; 150 + struct bss_descriptor *bss; 151 + DECLARE_SSID_BUF(ssid); 152 + 153 + lbs_deb_enter(LBS_DEB_JOIN); 154 + 155 + if (!priv->in_progress_assoc_req) { 156 + lbs_deb_join("ADHOC_RESP: no in-progress association " 157 + "request\n"); 158 + ret = -1; 159 + goto done; 160 + } 161 + bss = &priv->in_progress_assoc_req->bss; 162 + 163 + /* 164 + * Join result code 0 --> SUCCESS 165 + */ 166 + if (result) { 167 + lbs_deb_join("ADHOC_RESP: failed (result 0x%X)\n", result); 168 + if (priv->connect_status == LBS_CONNECTED) 169 + lbs_mac_event_disconnected(priv); 170 + ret = -1; 171 + goto done; 172 + } 173 + 174 + /* Send a Media Connected event, according to the Spec */ 175 + priv->connect_status = LBS_CONNECTED; 176 + 177 + if (command == CMD_RET(CMD_802_11_AD_HOC_START)) { 178 + /* Update the created network descriptor with the new BSSID */ 179 + memcpy(bss->bssid, resp->bssid, ETH_ALEN); 180 + } 181 + 182 + /* Set the BSSID from the joined/started descriptor */ 183 + memcpy(&priv->curbssparams.bssid, bss->bssid, ETH_ALEN); 184 + 185 + /* Set the new SSID to current SSID */ 186 + memcpy(&priv->curbssparams.ssid, &bss->ssid, IW_ESSID_MAX_SIZE); 187 + priv->curbssparams.ssid_len = bss->ssid_len; 188 + 189 + netif_carrier_on(priv->dev); 190 + if (!priv->tx_pending_len) 191 + netif_wake_queue(priv->dev); 192 + 193 + memset(&wrqu, 0, sizeof(wrqu)); 194 + memcpy(wrqu.ap_addr.sa_data, priv->curbssparams.bssid, ETH_ALEN); 195 + wrqu.ap_addr.sa_family = ARPHRD_ETHER; 196 + wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL); 197 + 198 + lbs_deb_join("ADHOC_RESP: Joined/started '%s', BSSID %pM, channel %d\n", 199 + print_ssid(ssid, bss->ssid, bss->ssid_len), 200 + priv->curbssparams.bssid, 201 + priv->curbssparams.channel); 202 + 203 + done: 204 + lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret); 433 205 return ret; 434 206 } 435 207 ··· 575 219 memcpy(&cmd.bss.bssid, &bss->bssid, ETH_ALEN); 576 220 memcpy(&cmd.bss.ssid, &bss->ssid, bss->ssid_len); 577 221 578 - memcpy(&cmd.bss.phyparamset, &bss->phyparamset, 579 - sizeof(union ieeetypes_phyparamset)); 222 + memcpy(&cmd.bss.ds, &bss->phy.ds, sizeof(struct ieee_ie_ds_param_set)); 580 223 581 - memcpy(&cmd.bss.ssparamset, &bss->ssparamset, 582 - sizeof(union IEEEtypes_ssparamset)); 224 + memcpy(&cmd.bss.ibss, &bss->ss.ibss, 225 + sizeof(struct ieee_ie_ibss_param_set)); 583 226 584 227 cmd.bss.capability = cpu_to_le16(bss->capability & CAPINFO_MASK); 585 228 lbs_deb_join("ADHOC_J_CMD: tmpcap=%4X CAPINFO_MASK=%4X\n", ··· 615 260 */ 616 261 lbs_set_basic_rate_flags(cmd.bss.rates, ratesize); 617 262 618 - cmd.bss.ssparamset.ibssparamset.atimwindow = cpu_to_le16(bss->atimwindow); 263 + cmd.bss.ibss.atimwindow = bss->atimwindow; 619 264 620 265 if (assoc_req->secinfo.wep_enabled) { 621 266 u16 tmp = le16_to_cpu(cmd.bss.capability); ··· 642 287 } 643 288 644 289 ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_JOIN, &cmd); 645 - if (ret == 0) 646 - ret = lbs_adhoc_post(priv, (struct cmd_header *) &cmd); 290 + if (ret == 0) { 291 + ret = lbs_adhoc_post(priv, 292 + (struct cmd_ds_802_11_ad_hoc_result *)&cmd); 293 + } 647 294 648 295 out: 649 296 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); ··· 700 343 WARN_ON(!assoc_req->channel); 701 344 702 345 /* set Physical parameter set */ 703 - cmd.phyparamset.dsparamset.elementid = WLAN_EID_DS_PARAMS; 704 - cmd.phyparamset.dsparamset.len = 1; 705 - cmd.phyparamset.dsparamset.currentchan = assoc_req->channel; 346 + cmd.ds.header.id = WLAN_EID_DS_PARAMS; 347 + cmd.ds.header.len = 1; 348 + cmd.ds.channel = assoc_req->channel; 706 349 707 350 /* set IBSS parameter set */ 708 - cmd.ssparamset.ibssparamset.elementid = WLAN_EID_IBSS_PARAMS; 709 - cmd.ssparamset.ibssparamset.len = 2; 710 - cmd.ssparamset.ibssparamset.atimwindow = 0; 351 + cmd.ibss.header.id = WLAN_EID_IBSS_PARAMS; 352 + cmd.ibss.header.len = 2; 353 + cmd.ibss.atimwindow = cpu_to_le16(0); 711 354 712 355 /* set capability info */ 713 356 tmpcap = WLAN_CAPABILITY_IBSS; 714 - if (assoc_req->secinfo.wep_enabled) { 715 - lbs_deb_join("ADHOC_START: WEP enabled, setting privacy on\n"); 357 + if (assoc_req->secinfo.wep_enabled || 358 + assoc_req->secinfo.WPAenabled || 359 + assoc_req->secinfo.WPA2enabled) { 360 + lbs_deb_join("ADHOC_START: WEP/WPA enabled, privacy on\n"); 716 361 tmpcap |= WLAN_CAPABILITY_PRIVACY; 717 362 } else 718 - lbs_deb_join("ADHOC_START: WEP disabled, setting privacy off\n"); 363 + lbs_deb_join("ADHOC_START: WEP disabled, privacy off\n"); 719 364 720 365 cmd.capability = cpu_to_le16(tmpcap); 721 366 ··· 754 395 755 396 ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_START, &cmd); 756 397 if (ret == 0) 757 - ret = lbs_adhoc_post(priv, (struct cmd_header *) &cmd); 398 + ret = lbs_adhoc_post(priv, 399 + (struct cmd_ds_802_11_ad_hoc_result *)&cmd); 758 400 759 401 out: 760 402 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); ··· 1080 720 assoc_req->ssid_len, NULL, IW_MODE_INFRA, channel); 1081 721 if (bss != NULL) { 1082 722 memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor)); 1083 - ret = lbs_associate(priv, assoc_req); 723 + ret = lbs_try_associate(priv, assoc_req); 1084 724 } else { 1085 725 lbs_deb_assoc("SSID not found; cannot associate\n"); 1086 726 } ··· 1132 772 1133 773 memcpy(&assoc_req->bss, bss, sizeof(struct bss_descriptor)); 1134 774 if (assoc_req->mode == IW_MODE_INFRA) { 1135 - ret = lbs_associate(priv, assoc_req); 1136 - lbs_deb_assoc("ASSOC: lbs_associate(bssid) returned %d\n", ret); 775 + ret = lbs_try_associate(priv, assoc_req); 776 + lbs_deb_assoc("ASSOC: lbs_try_associate(bssid) returned %d\n", 777 + ret); 1137 778 } else if (assoc_req->mode == IW_MODE_ADHOC) { 1138 779 lbs_adhoc_join(priv, assoc_req); 1139 780 } ··· 1828 1467 1829 1468 1830 1469 /** 1831 - * @brief This function prepares command of authenticate. 1832 - * 1833 - * @param priv A pointer to struct lbs_private structure 1834 - * @param cmd A pointer to cmd_ds_command structure 1835 - * @param pdata_buf Void cast of pointer to a BSSID to authenticate with 1836 - * 1837 - * @return 0 or -1 1838 - */ 1839 - int lbs_cmd_80211_authenticate(struct lbs_private *priv, 1840 - struct cmd_ds_command *cmd, 1841 - void *pdata_buf) 1842 - { 1843 - struct cmd_ds_802_11_authenticate *pauthenticate = &cmd->params.auth; 1844 - int ret = -1; 1845 - u8 *bssid = pdata_buf; 1846 - 1847 - lbs_deb_enter(LBS_DEB_JOIN); 1848 - 1849 - cmd->command = cpu_to_le16(CMD_802_11_AUTHENTICATE); 1850 - cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_authenticate) 1851 - + S_DS_GEN); 1852 - 1853 - /* translate auth mode to 802.11 defined wire value */ 1854 - switch (priv->secinfo.auth_mode) { 1855 - case IW_AUTH_ALG_OPEN_SYSTEM: 1856 - pauthenticate->authtype = 0x00; 1857 - break; 1858 - case IW_AUTH_ALG_SHARED_KEY: 1859 - pauthenticate->authtype = 0x01; 1860 - break; 1861 - case IW_AUTH_ALG_LEAP: 1862 - pauthenticate->authtype = 0x80; 1863 - break; 1864 - default: 1865 - lbs_deb_join("AUTH_CMD: invalid auth alg 0x%X\n", 1866 - priv->secinfo.auth_mode); 1867 - goto out; 1868 - } 1869 - 1870 - memcpy(pauthenticate->macaddr, bssid, ETH_ALEN); 1871 - 1872 - lbs_deb_join("AUTH_CMD: BSSID %pM, auth 0x%x\n", 1873 - bssid, pauthenticate->authtype); 1874 - ret = 0; 1875 - 1876 - out: 1877 - lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret); 1878 - return ret; 1879 - } 1880 - 1881 - /** 1882 1470 * @brief Deauthenticate from a specific BSS 1883 1471 * 1884 1472 * @param priv A pointer to struct lbs_private structure ··· 1857 1547 lbs_mac_event_disconnected(priv); 1858 1548 1859 1549 lbs_deb_leave(LBS_DEB_JOIN); 1860 - return ret; 1861 - } 1862 - 1863 - int lbs_cmd_80211_associate(struct lbs_private *priv, 1864 - struct cmd_ds_command *cmd, void *pdata_buf) 1865 - { 1866 - struct cmd_ds_802_11_associate *passo = &cmd->params.associate; 1867 - int ret = 0; 1868 - struct assoc_request *assoc_req = pdata_buf; 1869 - struct bss_descriptor *bss = &assoc_req->bss; 1870 - u8 *pos; 1871 - u16 tmpcap, tmplen; 1872 - struct mrvlietypes_ssidparamset *ssid; 1873 - struct mrvlietypes_phyparamset *phy; 1874 - struct mrvlietypes_ssparamset *ss; 1875 - struct mrvlietypes_ratesparamset *rates; 1876 - struct mrvlietypes_rsnparamset *rsn; 1877 - 1878 - lbs_deb_enter(LBS_DEB_ASSOC); 1879 - 1880 - pos = (u8 *) passo; 1881 - 1882 - if (!priv) { 1883 - ret = -1; 1884 - goto done; 1885 - } 1886 - 1887 - cmd->command = cpu_to_le16(CMD_802_11_ASSOCIATE); 1888 - 1889 - memcpy(passo->peerstaaddr, bss->bssid, sizeof(passo->peerstaaddr)); 1890 - pos += sizeof(passo->peerstaaddr); 1891 - 1892 - /* set the listen interval */ 1893 - passo->listeninterval = cpu_to_le16(MRVDRV_DEFAULT_LISTEN_INTERVAL); 1894 - 1895 - pos += sizeof(passo->capability); 1896 - pos += sizeof(passo->listeninterval); 1897 - pos += sizeof(passo->bcnperiod); 1898 - pos += sizeof(passo->dtimperiod); 1899 - 1900 - ssid = (struct mrvlietypes_ssidparamset *) pos; 1901 - ssid->header.type = cpu_to_le16(TLV_TYPE_SSID); 1902 - tmplen = bss->ssid_len; 1903 - ssid->header.len = cpu_to_le16(tmplen); 1904 - memcpy(ssid->ssid, bss->ssid, tmplen); 1905 - pos += sizeof(ssid->header) + tmplen; 1906 - 1907 - phy = (struct mrvlietypes_phyparamset *) pos; 1908 - phy->header.type = cpu_to_le16(TLV_TYPE_PHY_DS); 1909 - tmplen = sizeof(phy->fh_ds.dsparamset); 1910 - phy->header.len = cpu_to_le16(tmplen); 1911 - memcpy(&phy->fh_ds.dsparamset, 1912 - &bss->phyparamset.dsparamset.currentchan, 1913 - tmplen); 1914 - pos += sizeof(phy->header) + tmplen; 1915 - 1916 - ss = (struct mrvlietypes_ssparamset *) pos; 1917 - ss->header.type = cpu_to_le16(TLV_TYPE_CF); 1918 - tmplen = sizeof(ss->cf_ibss.cfparamset); 1919 - ss->header.len = cpu_to_le16(tmplen); 1920 - pos += sizeof(ss->header) + tmplen; 1921 - 1922 - rates = (struct mrvlietypes_ratesparamset *) pos; 1923 - rates->header.type = cpu_to_le16(TLV_TYPE_RATES); 1924 - memcpy(&rates->rates, &bss->rates, MAX_RATES); 1925 - tmplen = MAX_RATES; 1926 - if (get_common_rates(priv, rates->rates, &tmplen)) { 1927 - ret = -1; 1928 - goto done; 1929 - } 1930 - pos += sizeof(rates->header) + tmplen; 1931 - rates->header.len = cpu_to_le16(tmplen); 1932 - lbs_deb_assoc("ASSOC_CMD: num rates %u\n", tmplen); 1933 - 1934 - /* Copy the infra. association rates into Current BSS state structure */ 1935 - memset(&priv->curbssparams.rates, 0, sizeof(priv->curbssparams.rates)); 1936 - memcpy(&priv->curbssparams.rates, &rates->rates, tmplen); 1937 - 1938 - /* Set MSB on basic rates as the firmware requires, but _after_ 1939 - * copying to current bss rates. 1940 - */ 1941 - lbs_set_basic_rate_flags(rates->rates, tmplen); 1942 - 1943 - if (assoc_req->secinfo.WPAenabled || assoc_req->secinfo.WPA2enabled) { 1944 - rsn = (struct mrvlietypes_rsnparamset *) pos; 1945 - /* WPA_IE or WPA2_IE */ 1946 - rsn->header.type = cpu_to_le16((u16) assoc_req->wpa_ie[0]); 1947 - tmplen = (u16) assoc_req->wpa_ie[1]; 1948 - rsn->header.len = cpu_to_le16(tmplen); 1949 - memcpy(rsn->rsnie, &assoc_req->wpa_ie[2], tmplen); 1950 - lbs_deb_hex(LBS_DEB_JOIN, "ASSOC_CMD: RSN IE", (u8 *) rsn, 1951 - sizeof(rsn->header) + tmplen); 1952 - pos += sizeof(rsn->header) + tmplen; 1953 - } 1954 - 1955 - /* update curbssparams */ 1956 - priv->curbssparams.channel = bss->phyparamset.dsparamset.currentchan; 1957 - 1958 - if (lbs_parse_dnld_countryinfo_11d(priv, bss)) { 1959 - ret = -1; 1960 - goto done; 1961 - } 1962 - 1963 - cmd->size = cpu_to_le16((u16) (pos - (u8 *) passo) + S_DS_GEN); 1964 - 1965 - /* set the capability info */ 1966 - tmpcap = (bss->capability & CAPINFO_MASK); 1967 - if (bss->mode == IW_MODE_INFRA) 1968 - tmpcap |= WLAN_CAPABILITY_ESS; 1969 - passo->capability = cpu_to_le16(tmpcap); 1970 - lbs_deb_assoc("ASSOC_CMD: capability 0x%04x\n", tmpcap); 1971 - 1972 - done: 1973 - lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); 1974 - return ret; 1975 - } 1976 - 1977 - int lbs_ret_80211_associate(struct lbs_private *priv, 1978 - struct cmd_ds_command *resp) 1979 - { 1980 - int ret = 0; 1981 - union iwreq_data wrqu; 1982 - struct ieeetypes_assocrsp *passocrsp; 1983 - struct bss_descriptor *bss; 1984 - u16 status_code; 1985 - 1986 - lbs_deb_enter(LBS_DEB_ASSOC); 1987 - 1988 - if (!priv->in_progress_assoc_req) { 1989 - lbs_deb_assoc("ASSOC_RESP: no in-progress assoc request\n"); 1990 - ret = -1; 1991 - goto done; 1992 - } 1993 - bss = &priv->in_progress_assoc_req->bss; 1994 - 1995 - passocrsp = (struct ieeetypes_assocrsp *) &resp->params; 1996 - 1997 - /* 1998 - * Older FW versions map the IEEE 802.11 Status Code in the association 1999 - * response to the following values returned in passocrsp->statuscode: 2000 - * 2001 - * IEEE Status Code Marvell Status Code 2002 - * 0 -> 0x0000 ASSOC_RESULT_SUCCESS 2003 - * 13 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED 2004 - * 14 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED 2005 - * 15 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED 2006 - * 16 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED 2007 - * others -> 0x0003 ASSOC_RESULT_REFUSED 2008 - * 2009 - * Other response codes: 2010 - * 0x0001 -> ASSOC_RESULT_INVALID_PARAMETERS (unused) 2011 - * 0x0002 -> ASSOC_RESULT_TIMEOUT (internal timer expired waiting for 2012 - * association response from the AP) 2013 - */ 2014 - 2015 - status_code = le16_to_cpu(passocrsp->statuscode); 2016 - switch (status_code) { 2017 - case 0x00: 2018 - break; 2019 - case 0x01: 2020 - lbs_deb_assoc("ASSOC_RESP: invalid parameters\n"); 2021 - break; 2022 - case 0x02: 2023 - lbs_deb_assoc("ASSOC_RESP: internal timer " 2024 - "expired while waiting for the AP\n"); 2025 - break; 2026 - case 0x03: 2027 - lbs_deb_assoc("ASSOC_RESP: association " 2028 - "refused by AP\n"); 2029 - break; 2030 - case 0x04: 2031 - lbs_deb_assoc("ASSOC_RESP: authentication " 2032 - "refused by AP\n"); 2033 - break; 2034 - default: 2035 - lbs_deb_assoc("ASSOC_RESP: failure reason 0x%02x " 2036 - " unknown\n", status_code); 2037 - break; 2038 - } 2039 - 2040 - if (status_code) { 2041 - lbs_mac_event_disconnected(priv); 2042 - ret = -1; 2043 - goto done; 2044 - } 2045 - 2046 - lbs_deb_hex(LBS_DEB_ASSOC, "ASSOC_RESP", (void *)&resp->params, 2047 - le16_to_cpu(resp->size) - S_DS_GEN); 2048 - 2049 - /* Send a Media Connected event, according to the Spec */ 2050 - priv->connect_status = LBS_CONNECTED; 2051 - 2052 - /* Update current SSID and BSSID */ 2053 - memcpy(&priv->curbssparams.ssid, &bss->ssid, IW_ESSID_MAX_SIZE); 2054 - priv->curbssparams.ssid_len = bss->ssid_len; 2055 - memcpy(priv->curbssparams.bssid, bss->bssid, ETH_ALEN); 2056 - 2057 - priv->SNR[TYPE_RXPD][TYPE_AVG] = 0; 2058 - priv->NF[TYPE_RXPD][TYPE_AVG] = 0; 2059 - 2060 - memset(priv->rawSNR, 0x00, sizeof(priv->rawSNR)); 2061 - memset(priv->rawNF, 0x00, sizeof(priv->rawNF)); 2062 - priv->nextSNRNF = 0; 2063 - priv->numSNRNF = 0; 2064 - 2065 - netif_carrier_on(priv->dev); 2066 - if (!priv->tx_pending_len) 2067 - netif_wake_queue(priv->dev); 2068 - 2069 - memcpy(wrqu.ap_addr.sa_data, priv->curbssparams.bssid, ETH_ALEN); 2070 - wrqu.ap_addr.sa_family = ARPHRD_ETHER; 2071 - wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL); 2072 - 2073 - done: 2074 - lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); 2075 - return ret; 2076 - } 2077 - 2078 - static int lbs_adhoc_post(struct lbs_private *priv, struct cmd_header *resp) 2079 - { 2080 - int ret = 0; 2081 - u16 command = le16_to_cpu(resp->command); 2082 - u16 result = le16_to_cpu(resp->result); 2083 - struct cmd_ds_802_11_ad_hoc_result *adhoc_resp; 2084 - union iwreq_data wrqu; 2085 - struct bss_descriptor *bss; 2086 - DECLARE_SSID_BUF(ssid); 2087 - 2088 - lbs_deb_enter(LBS_DEB_JOIN); 2089 - 2090 - adhoc_resp = (struct cmd_ds_802_11_ad_hoc_result *) resp; 2091 - 2092 - if (!priv->in_progress_assoc_req) { 2093 - lbs_deb_join("ADHOC_RESP: no in-progress association " 2094 - "request\n"); 2095 - ret = -1; 2096 - goto done; 2097 - } 2098 - bss = &priv->in_progress_assoc_req->bss; 2099 - 2100 - /* 2101 - * Join result code 0 --> SUCCESS 2102 - */ 2103 - if (result) { 2104 - lbs_deb_join("ADHOC_RESP: failed (result 0x%X)\n", result); 2105 - if (priv->connect_status == LBS_CONNECTED) 2106 - lbs_mac_event_disconnected(priv); 2107 - ret = -1; 2108 - goto done; 2109 - } 2110 - 2111 - /* Send a Media Connected event, according to the Spec */ 2112 - priv->connect_status = LBS_CONNECTED; 2113 - 2114 - if (command == CMD_RET(CMD_802_11_AD_HOC_START)) { 2115 - /* Update the created network descriptor with the new BSSID */ 2116 - memcpy(bss->bssid, adhoc_resp->bssid, ETH_ALEN); 2117 - } 2118 - 2119 - /* Set the BSSID from the joined/started descriptor */ 2120 - memcpy(&priv->curbssparams.bssid, bss->bssid, ETH_ALEN); 2121 - 2122 - /* Set the new SSID to current SSID */ 2123 - memcpy(&priv->curbssparams.ssid, &bss->ssid, IW_ESSID_MAX_SIZE); 2124 - priv->curbssparams.ssid_len = bss->ssid_len; 2125 - 2126 - netif_carrier_on(priv->dev); 2127 - if (!priv->tx_pending_len) 2128 - netif_wake_queue(priv->dev); 2129 - 2130 - memset(&wrqu, 0, sizeof(wrqu)); 2131 - memcpy(wrqu.ap_addr.sa_data, priv->curbssparams.bssid, ETH_ALEN); 2132 - wrqu.ap_addr.sa_family = ARPHRD_ETHER; 2133 - wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL); 2134 - 2135 - lbs_deb_join("ADHOC_RESP: Joined/started '%s', BSSID %pM, channel %d\n", 2136 - print_ssid(ssid, bss->ssid, bss->ssid_len), 2137 - priv->curbssparams.bssid, 2138 - priv->curbssparams.channel); 2139 - 2140 - done: 2141 - lbs_deb_leave_args(LBS_DEB_JOIN, "ret %d", ret); 2142 1550 return ret; 2143 1551 } 2144 1552
-13
drivers/net/wireless/libertas/assoc.h
··· 8 8 void lbs_association_worker(struct work_struct *work); 9 9 struct assoc_request *lbs_get_association_request(struct lbs_private *priv); 10 10 11 - struct cmd_ds_command; 12 - int lbs_cmd_80211_authenticate(struct lbs_private *priv, 13 - struct cmd_ds_command *cmd, 14 - void *pdata_buf); 15 - 16 11 int lbs_adhoc_stop(struct lbs_private *priv); 17 12 18 13 int lbs_cmd_80211_deauthenticate(struct lbs_private *priv, 19 14 u8 bssid[ETH_ALEN], u16 reason); 20 - int lbs_cmd_80211_associate(struct lbs_private *priv, 21 - struct cmd_ds_command *cmd, 22 - void *pdata_buf); 23 - 24 - int lbs_ret_80211_ad_hoc_start(struct lbs_private *priv, 25 - struct cmd_ds_command *resp); 26 - int lbs_ret_80211_associate(struct lbs_private *priv, 27 - struct cmd_ds_command *resp); 28 15 29 16 #endif /* _LBS_ASSOC_H */
+3 -13
drivers/net/wireless/libertas/cmd.c
··· 1220 1220 command = le16_to_cpu(cmd->command); 1221 1221 1222 1222 /* These commands take longer */ 1223 - if (command == CMD_802_11_SCAN || command == CMD_802_11_ASSOCIATE || 1224 - command == CMD_802_11_AUTHENTICATE) 1223 + if (command == CMD_802_11_SCAN || command == CMD_802_11_ASSOCIATE) 1225 1224 timeo = 5 * HZ; 1226 1225 1227 1226 lbs_deb_cmd("DNLD_CMD: command 0x%04x, seq %d, size %d\n", ··· 1414 1415 ret = lbs_cmd_802_11_ps_mode(cmdptr, cmd_action); 1415 1416 break; 1416 1417 1417 - case CMD_802_11_ASSOCIATE: 1418 - case CMD_802_11_REASSOCIATE: 1419 - ret = lbs_cmd_80211_associate(priv, cmdptr, pdata_buf); 1420 - break; 1421 - 1422 - case CMD_802_11_AUTHENTICATE: 1423 - ret = lbs_cmd_80211_authenticate(priv, cmdptr, pdata_buf); 1424 - break; 1425 - 1426 1418 case CMD_MAC_REG_ACCESS: 1427 1419 case CMD_BBP_REG_ACCESS: 1428 1420 case CMD_RF_REG_ACCESS: ··· 1460 1470 break; 1461 1471 case CMD_802_11_LED_GPIO_CTRL: 1462 1472 { 1463 - struct mrvlietypes_ledgpio *gpio = 1464 - (struct mrvlietypes_ledgpio*) 1473 + struct mrvl_ie_ledgpio *gpio = 1474 + (struct mrvl_ie_ledgpio*) 1465 1475 cmdptr->params.ledgpio.data; 1466 1476 1467 1477 memmove(&cmdptr->params.ledgpio,
+5 -12
drivers/net/wireless/libertas/cmdresp.c
··· 5 5 #include <linux/delay.h> 6 6 #include <linux/if_arp.h> 7 7 #include <linux/netdevice.h> 8 - 8 + #include <asm/unaligned.h> 9 9 #include <net/iw_handler.h> 10 10 11 11 #include "host.h" ··· 154 154 lbs_deb_enter(LBS_DEB_CMD); 155 155 156 156 /* store the non average value */ 157 - priv->SNR[TYPE_BEACON][TYPE_NOAVG] = le16_to_cpu(rssirsp->SNR); 158 - priv->NF[TYPE_BEACON][TYPE_NOAVG] = le16_to_cpu(rssirsp->noisefloor); 157 + priv->SNR[TYPE_BEACON][TYPE_NOAVG] = get_unaligned_le16(&rssirsp->SNR); 158 + priv->NF[TYPE_BEACON][TYPE_NOAVG] = get_unaligned_le16(&rssirsp->noisefloor); 159 159 160 - priv->SNR[TYPE_BEACON][TYPE_AVG] = le16_to_cpu(rssirsp->avgSNR); 161 - priv->NF[TYPE_BEACON][TYPE_AVG] = le16_to_cpu(rssirsp->avgnoisefloor); 160 + priv->SNR[TYPE_BEACON][TYPE_AVG] = get_unaligned_le16(&rssirsp->avgSNR); 161 + priv->NF[TYPE_BEACON][TYPE_AVG] = get_unaligned_le16(&rssirsp->avgnoisefloor); 162 162 163 163 priv->RSSI[TYPE_BEACON][TYPE_NOAVG] = 164 164 CAL_RSSI(priv->SNR[TYPE_BEACON][TYPE_NOAVG], ··· 210 210 ret = lbs_ret_reg_access(priv, respcmd, resp); 211 211 break; 212 212 213 - case CMD_RET_802_11_ASSOCIATE: 214 - case CMD_RET(CMD_802_11_ASSOCIATE): 215 - case CMD_RET(CMD_802_11_REASSOCIATE): 216 - ret = lbs_ret_80211_associate(priv, resp); 217 - break; 218 - 219 213 case CMD_RET(CMD_802_11_SET_AFC): 220 214 case CMD_RET(CMD_802_11_GET_AFC): 221 215 spin_lock_irqsave(&priv->driver_lock, flags); ··· 219 225 220 226 break; 221 227 222 - case CMD_RET(CMD_802_11_AUTHENTICATE): 223 228 case CMD_RET(CMD_802_11_BEACON_STOP): 224 229 break; 225 230
+4 -4
drivers/net/wireless/libertas/debugfs.c
··· 183 183 */ 184 184 static void *lbs_tlv_find(uint16_t tlv_type, const uint8_t *tlv, uint16_t size) 185 185 { 186 - struct mrvlietypesheader *tlv_h; 186 + struct mrvl_ie_header *tlv_h; 187 187 uint16_t length; 188 188 ssize_t pos = 0; 189 189 190 190 while (pos < size) { 191 - tlv_h = (struct mrvlietypesheader *) tlv; 191 + tlv_h = (struct mrvl_ie_header *) tlv; 192 192 if (!tlv_h->len) 193 193 return NULL; 194 194 if (tlv_h->type == cpu_to_le16(tlv_type)) ··· 206 206 size_t count, loff_t *ppos) 207 207 { 208 208 struct cmd_ds_802_11_subscribe_event *subscribed; 209 - struct mrvlietypes_thresholds *got; 209 + struct mrvl_ie_thresholds *got; 210 210 struct lbs_private *priv = file->private_data; 211 211 ssize_t ret = 0; 212 212 size_t pos = 0; ··· 259 259 loff_t *ppos) 260 260 { 261 261 struct cmd_ds_802_11_subscribe_event *events; 262 - struct mrvlietypes_thresholds *tlv; 262 + struct mrvl_ie_thresholds *tlv; 263 263 struct lbs_private *priv = file->private_data; 264 264 ssize_t buf_size; 265 265 int value, freq, new_mask;
+4 -6
drivers/net/wireless/libertas/dev.h
··· 321 321 322 322 u32 monitormode; 323 323 u8 fw_ready; 324 - u8 fn_init_required; 325 - u8 fn_shutdown_required; 326 324 }; 327 325 328 326 extern struct cmd_confirm_sleep confirm_sleep; ··· 338 340 u32 rssi; 339 341 u32 channel; 340 342 u16 beaconperiod; 341 - u32 atimwindow; 343 + __le16 atimwindow; 342 344 343 345 /* IW_MODE_AUTO, IW_MODE_ADHOC, IW_MODE_INFRA */ 344 346 u8 mode; ··· 348 350 349 351 unsigned long last_scanned; 350 352 351 - union ieeetypes_phyparamset phyparamset; 352 - union IEEEtypes_ssparamset ssparamset; 353 + union ieee_phy_param_set phy; 354 + union ieee_ss_param_set ss; 353 355 354 - struct ieeetypes_countryinfofullset countryinfo; 356 + struct ieee_ie_country_info_full_set countryinfo; 355 357 356 358 u8 wpa_ie[MAX_WPA_IE_LEN]; 357 359 size_t wpa_ie_len;
+23 -18
drivers/net/wireless/libertas/hostcmd.h
··· 250 250 } __attribute__ ((packed)); 251 251 252 252 struct cmd_ds_802_11_authenticate { 253 - u8 macaddr[ETH_ALEN]; 253 + struct cmd_header hdr; 254 + 255 + u8 bssid[ETH_ALEN]; 254 256 u8 authtype; 255 257 u8 reserved[10]; 256 258 } __attribute__ ((packed)); ··· 265 263 } __attribute__ ((packed)); 266 264 267 265 struct cmd_ds_802_11_associate { 268 - u8 peerstaaddr[6]; 266 + struct cmd_header hdr; 267 + 268 + u8 bssid[6]; 269 269 __le16 capability; 270 270 __le16 listeninterval; 271 271 __le16 bcnperiod; 272 272 u8 dtimperiod; 273 - 274 - #if 0 275 - mrvlietypes_ssidparamset_t ssidParamSet; 276 - mrvlietypes_phyparamset_t phyparamset; 277 - mrvlietypes_ssparamset_t ssparamset; 278 - mrvlietypes_ratesparamset_t ratesParamSet; 279 - #endif 273 + u8 iebuf[512]; /* Enough for required and most optional IEs */ 280 274 } __attribute__ ((packed)); 281 275 282 - struct cmd_ds_802_11_associate_rsp { 283 - struct ieeetypes_assocrsp assocRsp; 276 + struct cmd_ds_802_11_associate_response { 277 + struct cmd_header hdr; 278 + 279 + __le16 capability; 280 + __le16 statuscode; 281 + __le16 aid; 282 + u8 iebuf[512]; 284 283 } __attribute__ ((packed)); 285 284 286 285 struct cmd_ds_802_11_set_wep { ··· 538 535 u8 bsstype; 539 536 __le16 beaconperiod; 540 537 u8 dtimperiod; /* Reserved on v9 and later */ 541 - union IEEEtypes_ssparamset ssparamset; 542 - union ieeetypes_phyparamset phyparamset; 543 - __le16 probedelay; 538 + struct ieee_ie_ibss_param_set ibss; 539 + u8 reserved1[4]; 540 + struct ieee_ie_ds_param_set ds; 541 + u8 reserved2[4]; 542 + __le16 probedelay; /* Reserved on v9 and later */ 544 543 __le16 capability; 545 544 u8 rates[MAX_RATES]; 546 545 u8 tlv_memory_size_pad[100]; ··· 563 558 u8 dtimperiod; 564 559 __le64 timestamp; 565 560 __le64 localtime; 566 - union ieeetypes_phyparamset phyparamset; 567 - union IEEEtypes_ssparamset ssparamset; 561 + struct ieee_ie_ds_param_set ds; 562 + u8 reserved1[4]; 563 + struct ieee_ie_ibss_param_set ibss; 564 + u8 reserved2[4]; 568 565 __le16 capability; 569 566 u8 rates[MAX_RATES]; 570 567 ··· 772 765 /* command Body */ 773 766 union { 774 767 struct cmd_ds_802_11_ps_mode psmode; 775 - struct cmd_ds_802_11_associate associate; 776 - struct cmd_ds_802_11_authenticate auth; 777 768 struct cmd_ds_802_11_get_stat gstat; 778 769 struct cmd_ds_802_3_get_stat gstat_8023; 779 770 struct cmd_ds_802_11_rf_antenna rant;
+47 -29
drivers/net/wireless/libertas/if_sdio.c
··· 39 39 #include "decl.h" 40 40 #include "defs.h" 41 41 #include "dev.h" 42 + #include "cmd.h" 42 43 #include "if_sdio.h" 44 + 45 + /* The if_sdio_remove() callback function is called when 46 + * user removes this module from kernel space or ejects 47 + * the card from the slot. The driver handles these 2 cases 48 + * differently for SD8688 combo chip. 49 + * If the user is removing the module, the FUNC_SHUTDOWN 50 + * command for SD8688 is sent to the firmware. 51 + * If the card is removed, there is no need to send this command. 52 + * 53 + * The variable 'user_rmmod' is used to distinguish these two 54 + * scenarios. This flag is initialized as FALSE in case the card 55 + * is removed, and will be set to TRUE for module removal when 56 + * module_exit function is called. 57 + */ 58 + static u8 user_rmmod; 43 59 44 60 static char *lbs_helper_name = NULL; 45 61 module_param_named(helper_name, lbs_helper_name, charp, 0644); ··· 77 61 int model; 78 62 const char *helper; 79 63 const char *firmware; 80 - struct if_sdio_card *card; 81 64 }; 82 65 83 66 static struct if_sdio_model if_sdio_models[] = { ··· 85 70 .model = IF_SDIO_MODEL_8385, 86 71 .helper = "sd8385_helper.bin", 87 72 .firmware = "sd8385.bin", 88 - .card = NULL, 89 73 }, 90 74 { 91 75 /* 8686 */ 92 76 .model = IF_SDIO_MODEL_8686, 93 77 .helper = "sd8686_helper.bin", 94 78 .firmware = "sd8686.bin", 95 - .card = NULL, 96 79 }, 97 80 { 98 81 /* 8688 */ 99 82 .model = IF_SDIO_MODEL_8688, 100 83 .helper = "sd8688_helper.bin", 101 84 .firmware = "sd8688.bin", 102 - .card = NULL, 103 85 }, 104 86 }; 105 87 ··· 939 927 goto free; 940 928 } 941 929 942 - if_sdio_models[i].card = card; 943 - 944 930 card->helper = if_sdio_models[i].helper; 945 931 card->firmware = if_sdio_models[i].firmware; 946 932 ··· 1024 1014 /* 1025 1015 * FUNC_INIT is required for SD8688 WLAN/BT multiple functions 1026 1016 */ 1027 - priv->fn_init_required = 1028 - (card->model == IF_SDIO_MODEL_8688) ? 1 : 0; 1017 + if (card->model == IF_SDIO_MODEL_8688) { 1018 + struct cmd_header cmd; 1019 + 1020 + memset(&cmd, 0, sizeof(cmd)); 1021 + 1022 + lbs_deb_sdio("send function INIT command\n"); 1023 + if (__lbs_cmd(priv, CMD_FUNC_INIT, &cmd, sizeof(cmd), 1024 + lbs_cmd_copyback, (unsigned long) &cmd)) 1025 + lbs_pr_alert("CMD_FUNC_INIT cmd failed\n"); 1026 + } 1029 1027 1030 1028 ret = lbs_start_card(priv); 1031 1029 if (ret) ··· 1075 1057 { 1076 1058 struct if_sdio_card *card; 1077 1059 struct if_sdio_packet *packet; 1078 - int ret; 1079 1060 1080 1061 lbs_deb_enter(LBS_DEB_SDIO); 1081 1062 1082 1063 card = sdio_get_drvdata(func); 1083 1064 1084 - lbs_stop_card(card->priv); 1065 + if (user_rmmod && (card->model == IF_SDIO_MODEL_8688)) { 1066 + /* 1067 + * FUNC_SHUTDOWN is required for SD8688 WLAN/BT 1068 + * multiple functions 1069 + */ 1070 + struct cmd_header cmd; 1071 + 1072 + memset(&cmd, 0, sizeof(cmd)); 1073 + 1074 + lbs_deb_sdio("send function SHUTDOWN command\n"); 1075 + if (__lbs_cmd(card->priv, CMD_FUNC_SHUTDOWN, 1076 + &cmd, sizeof(cmd), lbs_cmd_copyback, 1077 + (unsigned long) &cmd)) 1078 + lbs_pr_alert("CMD_FUNC_SHUTDOWN cmd failed\n"); 1079 + } 1085 1080 1086 1081 card->priv->surpriseremoved = 1; 1087 1082 1088 1083 lbs_deb_sdio("call remove card\n"); 1084 + lbs_stop_card(card->priv); 1089 1085 lbs_remove_card(card->priv); 1090 1086 1091 1087 flush_workqueue(card->workqueue); 1092 1088 destroy_workqueue(card->workqueue); 1093 1089 1094 1090 sdio_claim_host(func); 1095 - 1096 - /* Disable interrupts */ 1097 - sdio_writeb(func, 0x00, IF_SDIO_H_INT_MASK, &ret); 1098 - 1099 1091 sdio_release_irq(func); 1100 1092 sdio_disable_func(func); 1101 - 1102 1093 sdio_release_host(func); 1103 1094 1104 1095 while (card->packets) { ··· 1143 1116 1144 1117 ret = sdio_register_driver(&if_sdio_driver); 1145 1118 1119 + /* Clear the flag in case user removes the card. */ 1120 + user_rmmod = 0; 1121 + 1146 1122 lbs_deb_leave_args(LBS_DEB_SDIO, "ret %d", ret); 1147 1123 1148 1124 return ret; ··· 1153 1123 1154 1124 static void __exit if_sdio_exit_module(void) 1155 1125 { 1156 - int i; 1157 - struct if_sdio_card *card; 1158 - 1159 1126 lbs_deb_enter(LBS_DEB_SDIO); 1160 1127 1161 - for (i = 0; i < ARRAY_SIZE(if_sdio_models); i++) { 1162 - card = if_sdio_models[i].card; 1163 - 1164 - /* 1165 - * FUNC_SHUTDOWN is required for SD8688 WLAN/BT 1166 - * multiple functions 1167 - */ 1168 - if (card && card->priv) 1169 - card->priv->fn_shutdown_required = 1170 - (card->model == IF_SDIO_MODEL_8688) ? 1 : 0; 1171 - } 1128 + /* Set the flag as user is removing this module. */ 1129 + user_rmmod = 1; 1172 1130 1173 1131 sdio_unregister_driver(&if_sdio_driver); 1174 1132
+16 -18
drivers/net/wireless/libertas/if_spi.c
··· 119 119 * First we have to put a SPU register name on the bus. Then we can 120 120 * either read from or write to that register. 121 121 * 122 - * For 16-bit transactions, byte order on the bus is big-endian. 123 - * We don't have to worry about that here, though. 124 - * The translation takes place in the SPI routines. 125 122 */ 126 123 127 124 static void spu_transaction_init(struct if_spi_card *card) ··· 144 147 static int spu_write(struct if_spi_card *card, u16 reg, const u8 *buf, int len) 145 148 { 146 149 int err = 0; 147 - u16 reg_out = reg | IF_SPI_WRITE_OPERATION_MASK; 150 + u16 reg_out = cpu_to_le16(reg | IF_SPI_WRITE_OPERATION_MASK); 148 151 149 152 /* You must give an even number of bytes to the SPU, even if it 150 153 * doesn't care about the last one. */ ··· 166 169 167 170 static inline int spu_write_u16(struct if_spi_card *card, u16 reg, u16 val) 168 171 { 169 - return spu_write(card, reg, (u8 *)&val, sizeof(u16)); 170 - } 172 + u16 buff; 171 173 172 - static inline int spu_write_u32(struct if_spi_card *card, u16 reg, u32 val) 173 - { 174 - /* The lower 16 bits are written first. */ 175 - u16 out[2]; 176 - out[0] = val & 0xffff; 177 - out[1] = (val & 0xffff0000) >> 16; 178 - return spu_write(card, reg, (u8 *)&out, sizeof(u32)); 174 + buff = cpu_to_le16(val); 175 + return spu_write(card, reg, (u8 *)&buff, sizeof(u16)); 179 176 } 180 177 181 178 static inline int spu_reg_is_port_reg(u16 reg) ··· 189 198 unsigned int i, delay; 190 199 int err = 0; 191 200 u16 zero = 0; 192 - u16 reg_out = reg | IF_SPI_READ_OPERATION_MASK; 201 + u16 reg_out = cpu_to_le16(reg | IF_SPI_READ_OPERATION_MASK); 193 202 194 203 /* You must take an even number of bytes from the SPU, even if you 195 204 * don't care about the last one. */ ··· 227 236 /* Read 16 bits from an SPI register */ 228 237 static inline int spu_read_u16(struct if_spi_card *card, u16 reg, u16 *val) 229 238 { 230 - return spu_read(card, reg, (u8 *)val, sizeof(u16)); 239 + u16 buf; 240 + int ret; 241 + 242 + ret = spu_read(card, reg, (u8 *)&buf, sizeof(buf)); 243 + if (ret == 0) 244 + *val = le16_to_cpup(&buf); 245 + return ret; 231 246 } 232 247 233 248 /* Read 32 bits from an SPI register. 234 249 * The low 16 bits are read first. */ 235 250 static int spu_read_u32(struct if_spi_card *card, u16 reg, u32 *val) 236 251 { 237 - u16 buf[2]; 252 + u32 buf; 238 253 int err; 239 - err = spu_read(card, reg, (u8 *)buf, sizeof(u32)); 254 + 255 + err = spu_read(card, reg, (u8 *)&buf, sizeof(buf)); 240 256 if (!err) 241 - *val = buf[0] | (buf[1] << 16); 257 + *val = le32_to_cpup(&buf); 242 258 return err; 243 259 } 244 260
-20
drivers/net/wireless/libertas/main.c
··· 1002 1002 { 1003 1003 int ret = -1; 1004 1004 s16 curlevel = 0, minlevel = 0, maxlevel = 0; 1005 - struct cmd_header cmd; 1006 1005 1007 1006 lbs_deb_enter(LBS_DEB_FW); 1008 - 1009 - if (priv->fn_init_required) { 1010 - memset(&cmd, 0, sizeof(cmd)); 1011 - if (__lbs_cmd(priv, CMD_FUNC_INIT, &cmd, sizeof(cmd), 1012 - lbs_cmd_copyback, (unsigned long) &cmd)) 1013 - lbs_pr_alert("CMD_FUNC_INIT command failed\n"); 1014 - } 1015 1007 1016 1008 /* Read MAC address from firmware */ 1017 1009 memset(priv->current_addr, 0xff, ETH_ALEN); ··· 1192 1200 priv->mesh_open = 0; 1193 1201 priv->infra_open = 0; 1194 1202 1195 - priv->fn_init_required = 0; 1196 - priv->fn_shutdown_required = 0; 1197 - 1198 1203 /* Setup the OS Interface to our functions */ 1199 1204 dev->netdev_ops = &lbs_netdev_ops; 1200 1205 dev->watchdog_timeo = 5 * HZ; ··· 1373 1384 struct net_device *dev; 1374 1385 struct cmd_ctrl_node *cmdnode; 1375 1386 unsigned long flags; 1376 - struct cmd_header cmd; 1377 1387 1378 1388 lbs_deb_enter(LBS_DEB_MAIN); 1379 1389 1380 1390 if (!priv) 1381 1391 goto out; 1382 - 1383 - if (priv->fn_shutdown_required) { 1384 - memset(&cmd, 0, sizeof(cmd)); 1385 - if (__lbs_cmd(priv, CMD_FUNC_SHUTDOWN, &cmd, sizeof(cmd), 1386 - lbs_cmd_copyback, (unsigned long) &cmd)) 1387 - lbs_pr_alert("CMD_FUNC_SHUTDOWN command failed\n"); 1388 - } 1389 - 1390 1392 dev = priv->dev; 1391 1393 1392 1394 netif_stop_queue(dev);
+31 -32
drivers/net/wireless/libertas/scan.c
··· 27 27 + 40) /* 40 for WPAIE */ 28 28 29 29 //! Memory needed to store a max sized channel List TLV for a firmware scan 30 - #define CHAN_TLV_MAX_SIZE (sizeof(struct mrvlietypesheader) \ 30 + #define CHAN_TLV_MAX_SIZE (sizeof(struct mrvl_ie_header) \ 31 31 + (MRVDRV_MAX_CHANNELS_PER_SCAN \ 32 32 * sizeof(struct chanscanparamset))) 33 33 34 34 //! Memory needed to store a max number/size SSID TLV for a firmware scan 35 - #define SSID_TLV_MAX_SIZE (1 * sizeof(struct mrvlietypes_ssidparamset)) 35 + #define SSID_TLV_MAX_SIZE (1 * sizeof(struct mrvl_ie_ssid_param_set)) 36 36 37 37 //! Maximum memory needed for a cmd_ds_802_11_scan with all TLVs at max 38 38 #define MAX_SCAN_CFG_ALLOC (sizeof(struct cmd_ds_802_11_scan) \ ··· 211 211 */ 212 212 static int lbs_scan_add_ssid_tlv(struct lbs_private *priv, u8 *tlv) 213 213 { 214 - struct mrvlietypes_ssidparamset *ssid_tlv = (void *)tlv; 214 + struct mrvl_ie_ssid_param_set *ssid_tlv = (void *)tlv; 215 215 216 216 ssid_tlv->header.type = cpu_to_le16(TLV_TYPE_SSID); 217 217 ssid_tlv->header.len = cpu_to_le16(priv->scan_ssid_len); ··· 249 249 int chan_count) 250 250 { 251 251 size_t size = sizeof(struct chanscanparamset) *chan_count; 252 - struct mrvlietypes_chanlistparamset *chan_tlv = (void *)tlv; 252 + struct mrvl_ie_chanlist_param_set *chan_tlv = (void *)tlv; 253 253 254 254 chan_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST); 255 255 memcpy(chan_tlv->chanscanparam, chan_list, size); ··· 270 270 static int lbs_scan_add_rates_tlv(uint8_t *tlv) 271 271 { 272 272 int i; 273 - struct mrvlietypes_ratesparamset *rate_tlv = (void *)tlv; 273 + struct mrvl_ie_rates_param_set *rate_tlv = (void *)tlv; 274 274 275 275 rate_tlv->header.type = cpu_to_le16(TLV_TYPE_RATES); 276 276 tlv += sizeof(rate_tlv->header); ··· 513 513 static int lbs_process_bss(struct bss_descriptor *bss, 514 514 uint8_t **pbeaconinfo, int *bytesleft) 515 515 { 516 - struct ieeetypes_fhparamset *pFH; 517 - struct ieeetypes_dsparamset *pDS; 518 - struct ieeetypes_cfparamset *pCF; 519 - struct ieeetypes_ibssparamset *pibss; 516 + struct ieee_ie_fh_param_set *fh; 517 + struct ieee_ie_ds_param_set *ds; 518 + struct ieee_ie_cf_param_set *cf; 519 + struct ieee_ie_ibss_param_set *ibss; 520 520 DECLARE_SSID_BUF(ssid); 521 - struct ieeetypes_countryinfoset *pcountryinfo; 521 + struct ieee_ie_country_info_set *pcountryinfo; 522 522 uint8_t *pos, *end, *p; 523 523 uint8_t n_ex_rates = 0, got_basic_rates = 0, n_basic_rates = 0; 524 524 uint16_t beaconsize = 0; ··· 616 616 break; 617 617 618 618 case WLAN_EID_FH_PARAMS: 619 - pFH = (struct ieeetypes_fhparamset *) pos; 620 - memmove(&bss->phyparamset.fhparamset, pFH, 621 - sizeof(struct ieeetypes_fhparamset)); 619 + fh = (struct ieee_ie_fh_param_set *) pos; 620 + memcpy(&bss->phy.fh, fh, sizeof(*fh)); 622 621 lbs_deb_scan("got FH IE\n"); 623 622 break; 624 623 625 624 case WLAN_EID_DS_PARAMS: 626 - pDS = (struct ieeetypes_dsparamset *) pos; 627 - bss->channel = pDS->currentchan; 628 - memcpy(&bss->phyparamset.dsparamset, pDS, 629 - sizeof(struct ieeetypes_dsparamset)); 625 + ds = (struct ieee_ie_ds_param_set *) pos; 626 + bss->channel = ds->channel; 627 + memcpy(&bss->phy.ds, ds, sizeof(*ds)); 630 628 lbs_deb_scan("got DS IE, channel %d\n", bss->channel); 631 629 break; 632 630 633 631 case WLAN_EID_CF_PARAMS: 634 - pCF = (struct ieeetypes_cfparamset *) pos; 635 - memcpy(&bss->ssparamset.cfparamset, pCF, 636 - sizeof(struct ieeetypes_cfparamset)); 632 + cf = (struct ieee_ie_cf_param_set *) pos; 633 + memcpy(&bss->ss.cf, cf, sizeof(*cf)); 637 634 lbs_deb_scan("got CF IE\n"); 638 635 break; 639 636 640 637 case WLAN_EID_IBSS_PARAMS: 641 - pibss = (struct ieeetypes_ibssparamset *) pos; 642 - bss->atimwindow = le16_to_cpu(pibss->atimwindow); 643 - memmove(&bss->ssparamset.ibssparamset, pibss, 644 - sizeof(struct ieeetypes_ibssparamset)); 638 + ibss = (struct ieee_ie_ibss_param_set *) pos; 639 + bss->atimwindow = ibss->atimwindow; 640 + memcpy(&bss->ss.ibss, ibss, sizeof(*ibss)); 645 641 lbs_deb_scan("got IBSS IE\n"); 646 642 break; 647 643 648 644 case WLAN_EID_COUNTRY: 649 - pcountryinfo = (struct ieeetypes_countryinfoset *) pos; 645 + pcountryinfo = (struct ieee_ie_country_info_set *) pos; 650 646 lbs_deb_scan("got COUNTRY IE\n"); 651 - if (pcountryinfo->len < sizeof(pcountryinfo->countrycode) 652 - || pcountryinfo->len > 254) { 653 - lbs_deb_scan("process_bss: 11D- Err CountryInfo len %d, min %zd, max 254\n", 654 - pcountryinfo->len, sizeof(pcountryinfo->countrycode)); 647 + if (pcountryinfo->header.len < sizeof(pcountryinfo->countrycode) 648 + || pcountryinfo->header.len > 254) { 649 + lbs_deb_scan("%s: 11D- Err CountryInfo len %d, min %zd, max 254\n", 650 + __func__, 651 + pcountryinfo->header.len, 652 + sizeof(pcountryinfo->countrycode)); 655 653 ret = -1; 656 654 goto done; 657 655 } 658 656 659 - memcpy(&bss->countryinfo, pcountryinfo, pcountryinfo->len + 2); 657 + memcpy(&bss->countryinfo, pcountryinfo, 658 + pcountryinfo->header.len + 2); 660 659 lbs_deb_hex(LBS_DEB_SCAN, "process_bss: 11d countryinfo", 661 660 (uint8_t *) pcountryinfo, 662 - (int) (pcountryinfo->len + 2)); 661 + (int) (pcountryinfo->header.len + 2)); 663 662 break; 664 663 665 664 case WLAN_EID_EXT_SUPP_RATES: ··· 1129 1130 goto done; 1130 1131 } 1131 1132 1132 - bytesleft = le16_to_cpu(scanresp->bssdescriptsize); 1133 + bytesleft = get_unaligned_le16(&scanresp->bssdescriptsize); 1133 1134 lbs_deb_scan("SCAN_RESP: bssdescriptsize %d\n", bytesleft); 1134 1135 1135 1136 scanrespsize = le16_to_cpu(resp->size);
+66 -86
drivers/net/wireless/libertas/types.h
··· 8 8 #include <asm/byteorder.h> 9 9 #include <linux/wireless.h> 10 10 11 - struct ieeetypes_cfparamset { 12 - u8 elementid; 11 + struct ieee_ie_header { 12 + u8 id; 13 13 u8 len; 14 + } __attribute__ ((packed)); 15 + 16 + struct ieee_ie_cf_param_set { 17 + struct ieee_ie_header header; 18 + 14 19 u8 cfpcnt; 15 20 u8 cfpperiod; 16 21 __le16 cfpmaxduration; ··· 23 18 } __attribute__ ((packed)); 24 19 25 20 26 - struct ieeetypes_ibssparamset { 27 - u8 elementid; 28 - u8 len; 21 + struct ieee_ie_ibss_param_set { 22 + struct ieee_ie_header header; 23 + 29 24 __le16 atimwindow; 30 25 } __attribute__ ((packed)); 31 26 32 - union IEEEtypes_ssparamset { 33 - struct ieeetypes_cfparamset cfparamset; 34 - struct ieeetypes_ibssparamset ibssparamset; 27 + union ieee_ss_param_set { 28 + struct ieee_ie_cf_param_set cf; 29 + struct ieee_ie_ibss_param_set ibss; 35 30 } __attribute__ ((packed)); 36 31 37 - struct ieeetypes_fhparamset { 38 - u8 elementid; 39 - u8 len; 32 + struct ieee_ie_fh_param_set { 33 + struct ieee_ie_header header; 34 + 40 35 __le16 dwelltime; 41 36 u8 hopset; 42 37 u8 hoppattern; 43 38 u8 hopindex; 44 39 } __attribute__ ((packed)); 45 40 46 - struct ieeetypes_dsparamset { 47 - u8 elementid; 48 - u8 len; 49 - u8 currentchan; 41 + struct ieee_ie_ds_param_set { 42 + struct ieee_ie_header header; 43 + 44 + u8 channel; 50 45 } __attribute__ ((packed)); 51 46 52 - union ieeetypes_phyparamset { 53 - struct ieeetypes_fhparamset fhparamset; 54 - struct ieeetypes_dsparamset dsparamset; 55 - } __attribute__ ((packed)); 56 - 57 - struct ieeetypes_assocrsp { 58 - __le16 capability; 59 - __le16 statuscode; 60 - __le16 aid; 61 - u8 iebuffer[1]; 47 + union ieee_phy_param_set { 48 + struct ieee_ie_fh_param_set fh; 49 + struct ieee_ie_ds_param_set ds; 62 50 } __attribute__ ((packed)); 63 51 64 52 /** TLV type ID definition */ ··· 92 94 #define TLV_TYPE_TSFTIMESTAMP (PROPRIETARY_TLV_BASE_ID + 19) 93 95 #define TLV_TYPE_RSSI_HIGH (PROPRIETARY_TLV_BASE_ID + 22) 94 96 #define TLV_TYPE_SNR_HIGH (PROPRIETARY_TLV_BASE_ID + 23) 97 + #define TLV_TYPE_AUTH_TYPE (PROPRIETARY_TLV_BASE_ID + 31) 95 98 #define TLV_TYPE_MESH_ID (PROPRIETARY_TLV_BASE_ID + 37) 96 99 #define TLV_TYPE_OLD_MESH_ID (PROPRIETARY_TLV_BASE_ID + 291) 97 100 98 101 /** TLV related data structures*/ 99 - struct mrvlietypesheader { 102 + struct mrvl_ie_header { 100 103 __le16 type; 101 104 __le16 len; 102 105 } __attribute__ ((packed)); 103 106 104 - struct mrvlietypes_data { 105 - struct mrvlietypesheader header; 107 + struct mrvl_ie_data { 108 + struct mrvl_ie_header header; 106 109 u8 Data[1]; 107 110 } __attribute__ ((packed)); 108 111 109 - struct mrvlietypes_ratesparamset { 110 - struct mrvlietypesheader header; 112 + struct mrvl_ie_rates_param_set { 113 + struct mrvl_ie_header header; 111 114 u8 rates[1]; 112 115 } __attribute__ ((packed)); 113 116 114 - struct mrvlietypes_ssidparamset { 115 - struct mrvlietypesheader header; 117 + struct mrvl_ie_ssid_param_set { 118 + struct mrvl_ie_header header; 116 119 u8 ssid[1]; 117 120 } __attribute__ ((packed)); 118 121 119 - struct mrvlietypes_wildcardssidparamset { 120 - struct mrvlietypesheader header; 122 + struct mrvl_ie_wildcard_ssid_param_set { 123 + struct mrvl_ie_header header; 121 124 u8 MaxSsidlength; 122 125 u8 ssid[1]; 123 126 } __attribute__ ((packed)); ··· 143 144 __le16 maxscantime; 144 145 } __attribute__ ((packed)); 145 146 146 - struct mrvlietypes_chanlistparamset { 147 - struct mrvlietypesheader header; 147 + struct mrvl_ie_chanlist_param_set { 148 + struct mrvl_ie_header header; 148 149 struct chanscanparamset chanscanparam[1]; 149 150 } __attribute__ ((packed)); 150 151 151 - struct cfparamset { 152 + struct mrvl_ie_cf_param_set { 153 + struct mrvl_ie_header header; 152 154 u8 cfpcnt; 153 155 u8 cfpperiod; 154 156 __le16 cfpmaxduration; 155 157 __le16 cfpdurationremaining; 156 158 } __attribute__ ((packed)); 157 159 158 - struct ibssparamset { 159 - __le16 atimwindow; 160 + struct mrvl_ie_ds_param_set { 161 + struct mrvl_ie_header header; 162 + u8 channel; 160 163 } __attribute__ ((packed)); 161 164 162 - struct mrvlietypes_ssparamset { 163 - struct mrvlietypesheader header; 164 - union { 165 - struct cfparamset cfparamset[1]; 166 - struct ibssparamset ibssparamset[1]; 167 - } cf_ibss; 168 - } __attribute__ ((packed)); 169 - 170 - struct fhparamset { 171 - __le16 dwelltime; 172 - u8 hopset; 173 - u8 hoppattern; 174 - u8 hopindex; 175 - } __attribute__ ((packed)); 176 - 177 - struct dsparamset { 178 - u8 currentchan; 179 - } __attribute__ ((packed)); 180 - 181 - struct mrvlietypes_phyparamset { 182 - struct mrvlietypesheader header; 183 - union { 184 - struct fhparamset fhparamset[1]; 185 - struct dsparamset dsparamset[1]; 186 - } fh_ds; 187 - } __attribute__ ((packed)); 188 - 189 - struct mrvlietypes_rsnparamset { 190 - struct mrvlietypesheader header; 165 + struct mrvl_ie_rsn_param_set { 166 + struct mrvl_ie_header header; 191 167 u8 rsnie[1]; 192 168 } __attribute__ ((packed)); 193 169 194 - struct mrvlietypes_tsftimestamp { 195 - struct mrvlietypesheader header; 170 + struct mrvl_ie_tsf_timestamp { 171 + struct mrvl_ie_header header; 196 172 __le64 tsftable[1]; 197 173 } __attribute__ ((packed)); 198 174 175 + /* v9 and later firmware only */ 176 + struct mrvl_ie_auth_type { 177 + struct mrvl_ie_header header; 178 + __le16 auth; 179 + } __attribute__ ((packed)); 180 + 199 181 /** Local Power capability */ 200 - struct mrvlietypes_powercapability { 201 - struct mrvlietypesheader header; 182 + struct mrvl_ie_power_capability { 183 + struct mrvl_ie_header header; 202 184 s8 minpower; 203 185 s8 maxpower; 204 186 } __attribute__ ((packed)); 205 187 206 188 /* used in CMD_802_11_SUBSCRIBE_EVENT for SNR, RSSI and Failure */ 207 - struct mrvlietypes_thresholds { 208 - struct mrvlietypesheader header; 189 + struct mrvl_ie_thresholds { 190 + struct mrvl_ie_header header; 209 191 u8 value; 210 192 u8 freq; 211 193 } __attribute__ ((packed)); 212 194 213 - struct mrvlietypes_beaconsmissed { 214 - struct mrvlietypesheader header; 195 + struct mrvl_ie_beacons_missed { 196 + struct mrvl_ie_header header; 215 197 u8 beaconmissed; 216 198 u8 reserved; 217 199 } __attribute__ ((packed)); 218 200 219 - struct mrvlietypes_numprobes { 220 - struct mrvlietypesheader header; 201 + struct mrvl_ie_num_probes { 202 + struct mrvl_ie_header header; 221 203 __le16 numprobes; 222 204 } __attribute__ ((packed)); 223 205 224 - struct mrvlietypes_bcastprobe { 225 - struct mrvlietypesheader header; 206 + struct mrvl_ie_bcast_probe { 207 + struct mrvl_ie_header header; 226 208 __le16 bcastprobe; 227 209 } __attribute__ ((packed)); 228 210 229 - struct mrvlietypes_numssidprobe { 230 - struct mrvlietypesheader header; 211 + struct mrvl_ie_num_ssid_probe { 212 + struct mrvl_ie_header header; 231 213 __le16 numssidprobe; 232 214 } __attribute__ ((packed)); 233 215 ··· 217 237 u8 pin; 218 238 } __attribute__ ((packed)); 219 239 220 - struct mrvlietypes_ledgpio { 221 - struct mrvlietypesheader header; 240 + struct mrvl_ie_ledgpio { 241 + struct mrvl_ie_header header; 222 242 struct led_pin ledpin[1]; 223 243 } __attribute__ ((packed)); 224 244 ··· 230 250 } __attribute__ ((packed)); 231 251 232 252 233 - struct mrvlietypes_ledbhv { 234 - struct mrvlietypesheader header; 253 + struct mrvl_ie_ledbhv { 254 + struct mrvl_ie_header header; 235 255 struct led_bhv ledbhv[1]; 236 256 } __attribute__ ((packed)); 237 257
+7 -20
drivers/net/wireless/mac80211_hwsim.c
··· 280 280 struct ieee80211_rate rates[ARRAY_SIZE(hwsim_rates)]; 281 281 282 282 struct ieee80211_channel *channel; 283 - int radio_enabled; 284 283 unsigned long beacon_int; /* in jiffies unit */ 285 284 unsigned int rx_filter; 286 285 int started; ··· 417 418 if (data == data2) 418 419 continue; 419 420 420 - if (!data2->started || !data2->radio_enabled || 421 - !hwsim_ps_rx_ok(data2, skb) || 421 + if (!data2->started || !hwsim_ps_rx_ok(data2, skb) || 422 422 data->channel->center_freq != data2->channel->center_freq || 423 423 !(data->group & data2->group)) 424 424 continue; ··· 439 441 440 442 static int mac80211_hwsim_tx(struct ieee80211_hw *hw, struct sk_buff *skb) 441 443 { 442 - struct mac80211_hwsim_data *data = hw->priv; 443 444 bool ack; 444 445 struct ieee80211_tx_info *txi; 445 446 ··· 446 449 447 450 if (skb->len < 10) { 448 451 /* Should not happen; just a sanity check for addr1 use */ 449 - dev_kfree_skb(skb); 450 - return NETDEV_TX_OK; 451 - } 452 - 453 - if (!data->radio_enabled) { 454 - printk(KERN_DEBUG "%s: dropped TX frame since radio " 455 - "disabled\n", wiphy_name(hw->wiphy)); 456 452 dev_kfree_skb(skb); 457 453 return NETDEV_TX_OK; 458 454 } ··· 536 546 struct ieee80211_hw *hw = (struct ieee80211_hw *) arg; 537 547 struct mac80211_hwsim_data *data = hw->priv; 538 548 539 - if (!data->started || !data->radio_enabled) 549 + if (!data->started) 540 550 return; 541 551 542 552 ieee80211_iterate_active_interfaces_atomic( ··· 552 562 struct mac80211_hwsim_data *data = hw->priv; 553 563 struct ieee80211_conf *conf = &hw->conf; 554 564 555 - printk(KERN_DEBUG "%s:%s (freq=%d radio_enabled=%d idle=%d ps=%d)\n", 565 + printk(KERN_DEBUG "%s:%s (freq=%d idle=%d ps=%d)\n", 556 566 wiphy_name(hw->wiphy), __func__, 557 - conf->channel->center_freq, conf->radio_enabled, 567 + conf->channel->center_freq, 558 568 !!(conf->flags & IEEE80211_CONF_IDLE), 559 569 !!(conf->flags & IEEE80211_CONF_PS)); 560 570 561 571 data->channel = conf->channel; 562 - data->radio_enabled = conf->radio_enabled; 563 - if (!data->started || !data->radio_enabled || !data->beacon_int) 572 + if (!data->started || !data->beacon_int) 564 573 del_timer(&data->beacon_timer); 565 574 else 566 575 mod_timer(&data->beacon_timer, jiffies + data->beacon_int); ··· 776 787 pspoll->aid = cpu_to_le16(0xc000 | vp->aid); 777 788 memcpy(pspoll->bssid, vp->bssid, ETH_ALEN); 778 789 memcpy(pspoll->ta, mac, ETH_ALEN); 779 - if (data->radio_enabled && 780 - !mac80211_hwsim_tx_frame(data->hw, skb)) 790 + if (!mac80211_hwsim_tx_frame(data->hw, skb)) 781 791 printk(KERN_DEBUG "%s: PS-Poll frame not ack'ed\n", __func__); 782 792 dev_kfree_skb(skb); 783 793 } ··· 807 819 memcpy(hdr->addr1, vp->bssid, ETH_ALEN); 808 820 memcpy(hdr->addr2, mac, ETH_ALEN); 809 821 memcpy(hdr->addr3, vp->bssid, ETH_ALEN); 810 - if (data->radio_enabled && 811 - !mac80211_hwsim_tx_frame(data->hw, skb)) 822 + if (!mac80211_hwsim_tx_frame(data->hw, skb)) 812 823 printk(KERN_DEBUG "%s: nullfunc frame not ack'ed\n", __func__); 813 824 dev_kfree_skb(skb); 814 825 }
+2 -2
drivers/net/wireless/p54/p54usb.c
··· 84 84 static const struct { 85 85 u32 intf; 86 86 enum p54u_hw_type type; 87 - char fw[FIRMWARE_NAME_MAX]; 88 - char fw_legacy[FIRMWARE_NAME_MAX]; 87 + const char *fw; 88 + const char *fw_legacy; 89 89 char hw[20]; 90 90 } p54u_fwlist[__NUM_P54U_HWTYPES] = { 91 91 {
+1 -1
drivers/net/wireless/rt2x00/rt2400pci.c
··· 520 520 if (state == STATE_SLEEP) { 521 521 rt2x00pci_register_read(rt2x00dev, CSR20, &reg); 522 522 rt2x00_set_field32(&reg, CSR20_DELAY_AFTER_TBCN, 523 - (libconf->conf->beacon_int - 20) * 16); 523 + (rt2x00dev->beacon_int - 20) * 16); 524 524 rt2x00_set_field32(&reg, CSR20_TBCN_BEFORE_WAKEUP, 525 525 libconf->conf->listen_interval - 1); 526 526
+1 -1
drivers/net/wireless/rt2x00/rt2500pci.c
··· 569 569 if (state == STATE_SLEEP) { 570 570 rt2x00pci_register_read(rt2x00dev, CSR20, &reg); 571 571 rt2x00_set_field32(&reg, CSR20_DELAY_AFTER_TBCN, 572 - (libconf->conf->beacon_int - 20) * 16); 572 + (rt2x00dev->beacon_int - 20) * 16); 573 573 rt2x00_set_field32(&reg, CSR20_TBCN_BEFORE_WAKEUP, 574 574 libconf->conf->listen_interval - 1); 575 575
+1 -1
drivers/net/wireless/rt2x00/rt2500usb.c
··· 647 647 if (state == STATE_SLEEP) { 648 648 rt2500usb_register_read(rt2x00dev, MAC_CSR18, &reg); 649 649 rt2x00_set_field16(&reg, MAC_CSR18_DELAY_AFTER_BEACON, 650 - libconf->conf->beacon_int - 20); 650 + rt2x00dev->beacon_int - 20); 651 651 rt2x00_set_field16(&reg, MAC_CSR18_BEACONS_BEFORE_WAKEUP, 652 652 libconf->conf->listen_interval - 1); 653 653
+12
drivers/net/wireless/rt2x00/rt2800usb.c
··· 2927 2927 { USB_DEVICE(0x07d1, 0x3c09), USB_DEVICE_DATA(&rt2800usb_ops) }, 2928 2928 { USB_DEVICE(0x07d1, 0x3c0a), USB_DEVICE_DATA(&rt2800usb_ops) }, 2929 2929 { USB_DEVICE(0x07d1, 0x3c0b), USB_DEVICE_DATA(&rt2800usb_ops) }, 2930 + { USB_DEVICE(0x07d1, 0x3c0d), USB_DEVICE_DATA(&rt2800usb_ops) }, 2931 + { USB_DEVICE(0x07d1, 0x3c0e), USB_DEVICE_DATA(&rt2800usb_ops) }, 2932 + { USB_DEVICE(0x07d1, 0x3c0f), USB_DEVICE_DATA(&rt2800usb_ops) }, 2930 2933 { USB_DEVICE(0x07d1, 0x3c11), USB_DEVICE_DATA(&rt2800usb_ops) }, 2931 2934 { USB_DEVICE(0x07d1, 0x3c13), USB_DEVICE_DATA(&rt2800usb_ops) }, 2932 2935 /* Edimax */ 2933 2936 { USB_DEVICE(0x7392, 0x7711), USB_DEVICE_DATA(&rt2800usb_ops) }, 2934 2937 { USB_DEVICE(0x7392, 0x7717), USB_DEVICE_DATA(&rt2800usb_ops) }, 2935 2938 { USB_DEVICE(0x7392, 0x7718), USB_DEVICE_DATA(&rt2800usb_ops) }, 2939 + /* Encore */ 2940 + { USB_DEVICE(0x203d, 0x1480), USB_DEVICE_DATA(&rt2800usb_ops) }, 2936 2941 /* EnGenius */ 2937 2942 { USB_DEVICE(0X1740, 0x9701), USB_DEVICE_DATA(&rt2800usb_ops) }, 2938 2943 { USB_DEVICE(0x1740, 0x9702), USB_DEVICE_DATA(&rt2800usb_ops) }, ··· 2956 2951 { USB_DEVICE(0x0e66, 0x0003), USB_DEVICE_DATA(&rt2800usb_ops) }, 2957 2952 { USB_DEVICE(0x0e66, 0x0009), USB_DEVICE_DATA(&rt2800usb_ops) }, 2958 2953 { USB_DEVICE(0x0e66, 0x000b), USB_DEVICE_DATA(&rt2800usb_ops) }, 2954 + /* I-O DATA */ 2955 + { USB_DEVICE(0x04bb, 0x0945), USB_DEVICE_DATA(&rt2800usb_ops) }, 2959 2956 /* LevelOne */ 2960 2957 { USB_DEVICE(0x1740, 0x0605), USB_DEVICE_DATA(&rt2800usb_ops) }, 2961 2958 { USB_DEVICE(0x1740, 0x0615), USB_DEVICE_DATA(&rt2800usb_ops) }, ··· 2977 2970 /* Pegatron */ 2978 2971 { USB_DEVICE(0x1d4d, 0x0002), USB_DEVICE_DATA(&rt2800usb_ops) }, 2979 2972 { USB_DEVICE(0x1d4d, 0x000c), USB_DEVICE_DATA(&rt2800usb_ops) }, 2973 + { USB_DEVICE(0x1d4d, 0x000e), USB_DEVICE_DATA(&rt2800usb_ops) }, 2980 2974 /* Philips */ 2981 2975 { USB_DEVICE(0x0471, 0x200f), USB_DEVICE_DATA(&rt2800usb_ops) }, 2982 2976 /* Planex */ ··· 2989 2981 /* Quanta */ 2990 2982 { USB_DEVICE(0x1a32, 0x0304), USB_DEVICE_DATA(&rt2800usb_ops) }, 2991 2983 /* Ralink */ 2984 + { USB_DEVICE(0x0db0, 0x3820), USB_DEVICE_DATA(&rt2800usb_ops) }, 2992 2985 { USB_DEVICE(0x0db0, 0x6899), USB_DEVICE_DATA(&rt2800usb_ops) }, 2993 2986 { USB_DEVICE(0x148f, 0x2070), USB_DEVICE_DATA(&rt2800usb_ops) }, 2994 2987 { USB_DEVICE(0x148f, 0x2770), USB_DEVICE_DATA(&rt2800usb_ops) }, ··· 3014 3005 { USB_DEVICE(0x0df6, 0x003e), USB_DEVICE_DATA(&rt2800usb_ops) }, 3015 3006 { USB_DEVICE(0x0df6, 0x003f), USB_DEVICE_DATA(&rt2800usb_ops) }, 3016 3007 { USB_DEVICE(0x0df6, 0x0040), USB_DEVICE_DATA(&rt2800usb_ops) }, 3008 + { USB_DEVICE(0x0df6, 0x0042), USB_DEVICE_DATA(&rt2800usb_ops) }, 3017 3009 /* SMC */ 3018 3010 { USB_DEVICE(0x083a, 0x6618), USB_DEVICE_DATA(&rt2800usb_ops) }, 3019 3011 { USB_DEVICE(0x083a, 0x7511), USB_DEVICE_DATA(&rt2800usb_ops) }, ··· 3039 3029 /* Zinwell */ 3040 3030 { USB_DEVICE(0x5a57, 0x0280), USB_DEVICE_DATA(&rt2800usb_ops) }, 3041 3031 { USB_DEVICE(0x5a57, 0x0282), USB_DEVICE_DATA(&rt2800usb_ops) }, 3032 + { USB_DEVICE(0x5a57, 0x0283), USB_DEVICE_DATA(&rt2800usb_ops) }, 3033 + { USB_DEVICE(0x5a57, 0x5257), USB_DEVICE_DATA(&rt2800usb_ops) }, 3042 3034 /* Zyxel */ 3043 3035 { USB_DEVICE(0x0586, 0x3416), USB_DEVICE_DATA(&rt2800usb_ops) }, 3044 3036 { USB_DEVICE(0x0586, 0x341a), USB_DEVICE_DATA(&rt2800usb_ops) },
+5
drivers/net/wireless/rt2x00/rt2x00.h
··· 802 802 u8 calibration[2]; 803 803 804 804 /* 805 + * Beacon interval. 806 + */ 807 + u16 beacon_int; 808 + 809 + /* 805 810 * Low level statistics which will have 806 811 * to be kept up to date while device is running. 807 812 */
+3
drivers/net/wireless/rt2x00/rt2x00config.c
··· 108 108 erp.basic_rates = bss_conf->basic_rates; 109 109 erp.beacon_int = bss_conf->beacon_int; 110 110 111 + /* Update global beacon interval time, this is needed for PS support */ 112 + rt2x00dev->beacon_int = bss_conf->beacon_int; 113 + 111 114 rt2x00dev->ops->lib->config_erp(rt2x00dev, &erp); 112 115 } 113 116
+1 -1
drivers/net/wireless/rt2x00/rt61pci.c
··· 956 956 if (state == STATE_SLEEP) { 957 957 rt2x00pci_register_read(rt2x00dev, MAC_CSR11, &reg); 958 958 rt2x00_set_field32(&reg, MAC_CSR11_DELAY_AFTER_TBCN, 959 - libconf->conf->beacon_int - 10); 959 + rt2x00dev->beacon_int - 10); 960 960 rt2x00_set_field32(&reg, MAC_CSR11_TBCN_BEFORE_WAKEUP, 961 961 libconf->conf->listen_interval - 1); 962 962 rt2x00_set_field32(&reg, MAC_CSR11_WAKEUP_LATENCY, 5);
+1 -1
drivers/net/wireless/rt2x00/rt73usb.c
··· 852 852 if (state == STATE_SLEEP) { 853 853 rt2x00usb_register_read(rt2x00dev, MAC_CSR11, &reg); 854 854 rt2x00_set_field32(&reg, MAC_CSR11_DELAY_AFTER_TBCN, 855 - libconf->conf->beacon_int - 10); 855 + rt2x00dev->beacon_int - 10); 856 856 rt2x00_set_field32(&reg, MAC_CSR11_TBCN_BEFORE_WAKEUP, 857 857 libconf->conf->listen_interval - 1); 858 858 rt2x00_set_field32(&reg, MAC_CSR11_WAKEUP_LATENCY, 5);
+6 -8
drivers/platform/x86/Kconfig
··· 21 21 depends on NEW_LEDS 22 22 depends on BACKLIGHT_CLASS_DEVICE 23 23 depends on SERIO_I8042 24 - depends on RFKILL 24 + depends on RFKILL || RFKILL = n 25 25 select ACPI_WMI 26 26 ---help--- 27 27 This is a driver for newer Acer (and Wistron) laptops. It adds ··· 60 60 depends on DCDBAS 61 61 depends on EXPERIMENTAL 62 62 depends on BACKLIGHT_CLASS_DEVICE 63 - depends on RFKILL 63 + depends on RFKILL || RFKILL = n 64 64 depends on POWER_SUPPLY 65 65 default n 66 66 ---help--- ··· 117 117 tristate "HP WMI extras" 118 118 depends on ACPI_WMI 119 119 depends on INPUT 120 - depends on RFKILL 120 + depends on RFKILL || RFKILL = n 121 121 help 122 122 Say Y here if you want to support WMI-based hotkeys on HP laptops and 123 123 to read data from WMI such as docking or ambient light sensor state. ··· 196 196 tristate "ThinkPad ACPI Laptop Extras" 197 197 depends on ACPI 198 198 depends on INPUT 199 + depends on RFKILL || RFKILL = n 199 200 select BACKLIGHT_LCD_SUPPORT 200 201 select BACKLIGHT_CLASS_DEVICE 201 202 select HWMON 202 203 select NVRAM 203 204 select NEW_LEDS 204 205 select LEDS_CLASS 205 - select NET 206 - select RFKILL 207 206 ---help--- 208 207 This is a driver for the IBM and Lenovo ThinkPad laptops. It adds 209 208 support for Fn-Fx key combinations, Bluetooth control, video ··· 337 338 depends on ACPI 338 339 depends on INPUT 339 340 depends on EXPERIMENTAL 341 + depends on RFKILL || RFKILL = n 340 342 select BACKLIGHT_CLASS_DEVICE 341 343 select HWMON 342 - select RFKILL 343 344 ---help--- 344 345 This driver supports the Fn-Fx keys on Eee PC laptops. 345 346 It also adds the ability to switch camera/wlan on/off. ··· 404 405 tristate "Toshiba Laptop Extras" 405 406 depends on ACPI 406 407 depends on INPUT 408 + depends on RFKILL || RFKILL = n 407 409 select INPUT_POLLDEV 408 - select NET 409 - select RFKILL 410 410 select BACKLIGHT_CLASS_DEVICE 411 411 ---help--- 412 412 This driver adds support for access to certain system settings
+22 -28
drivers/platform/x86/acer-wmi.c
··· 958 958 959 959 status = get_u32(&state, ACER_CAP_WIRELESS); 960 960 if (ACPI_SUCCESS(status)) 961 - rfkill_force_state(wireless_rfkill, state ? 962 - RFKILL_STATE_UNBLOCKED : RFKILL_STATE_SOFT_BLOCKED); 961 + rfkill_set_sw_state(wireless_rfkill, !!state); 963 962 964 963 if (has_cap(ACER_CAP_BLUETOOTH)) { 965 964 status = get_u32(&state, ACER_CAP_BLUETOOTH); 966 965 if (ACPI_SUCCESS(status)) 967 - rfkill_force_state(bluetooth_rfkill, state ? 968 - RFKILL_STATE_UNBLOCKED : 969 - RFKILL_STATE_SOFT_BLOCKED); 966 + rfkill_set_sw_state(bluetooth_rfkill, !!state); 970 967 } 971 968 972 969 schedule_delayed_work(&acer_rfkill_work, round_jiffies_relative(HZ)); 973 970 } 974 971 975 - static int acer_rfkill_set(void *data, enum rfkill_state state) 972 + static int acer_rfkill_set(void *data, bool blocked) 976 973 { 977 974 acpi_status status; 978 - u32 *cap = data; 979 - status = set_u32((u32) (state == RFKILL_STATE_UNBLOCKED), *cap); 975 + u32 cap = (unsigned long)data; 976 + status = set_u32(!!blocked, cap); 980 977 if (ACPI_FAILURE(status)) 981 978 return -ENODEV; 982 979 return 0; 983 980 } 984 981 985 - static struct rfkill * acer_rfkill_register(struct device *dev, 986 - enum rfkill_type type, char *name, u32 cap) 982 + static const struct rfkill_ops acer_rfkill_ops = { 983 + .set_block = acer_rfkill_set, 984 + }; 985 + 986 + static struct rfkill *acer_rfkill_register(struct device *dev, 987 + enum rfkill_type type, 988 + char *name, u32 cap) 987 989 { 988 990 int err; 989 991 u32 state; 990 - u32 *data; 991 992 struct rfkill *rfkill_dev; 992 993 993 - rfkill_dev = rfkill_allocate(dev, type); 994 + rfkill_dev = rfkill_alloc(name, dev, type, 995 + &acer_rfkill_ops, 996 + (void *)(unsigned long)cap); 994 997 if (!rfkill_dev) 995 998 return ERR_PTR(-ENOMEM); 996 - rfkill_dev->name = name; 997 999 get_u32(&state, cap); 998 - rfkill_dev->state = state ? RFKILL_STATE_UNBLOCKED : 999 - RFKILL_STATE_SOFT_BLOCKED; 1000 - data = kzalloc(sizeof(u32), GFP_KERNEL); 1001 - if (!data) { 1002 - rfkill_free(rfkill_dev); 1003 - return ERR_PTR(-ENOMEM); 1004 - } 1005 - *data = cap; 1006 - rfkill_dev->data = data; 1007 - rfkill_dev->toggle_radio = acer_rfkill_set; 1000 + rfkill_set_sw_state(rfkill_dev, !state); 1008 1001 1009 1002 err = rfkill_register(rfkill_dev); 1010 1003 if (err) { 1011 - kfree(rfkill_dev->data); 1012 - rfkill_free(rfkill_dev); 1004 + rfkill_destroy(rfkill_dev); 1013 1005 return ERR_PTR(err); 1014 1006 } 1015 1007 return rfkill_dev; ··· 1019 1027 RFKILL_TYPE_BLUETOOTH, "acer-bluetooth", 1020 1028 ACER_CAP_BLUETOOTH); 1021 1029 if (IS_ERR(bluetooth_rfkill)) { 1022 - kfree(wireless_rfkill->data); 1023 1030 rfkill_unregister(wireless_rfkill); 1031 + rfkill_destroy(wireless_rfkill); 1024 1032 return PTR_ERR(bluetooth_rfkill); 1025 1033 } 1026 1034 } ··· 1033 1041 static void acer_rfkill_exit(void) 1034 1042 { 1035 1043 cancel_delayed_work_sync(&acer_rfkill_work); 1036 - kfree(wireless_rfkill->data); 1044 + 1037 1045 rfkill_unregister(wireless_rfkill); 1046 + rfkill_destroy(wireless_rfkill); 1047 + 1038 1048 if (has_cap(ACER_CAP_BLUETOOTH)) { 1039 - kfree(bluetooth_rfkill->data); 1040 1049 rfkill_unregister(bluetooth_rfkill); 1050 + rfkill_destroy(bluetooth_rfkill); 1041 1051 } 1042 1052 return; 1043 1053 }
+34 -71
drivers/platform/x86/dell-laptop.c
··· 174 174 result[3]: NVRAM format version number 175 175 */ 176 176 177 - static int dell_rfkill_set(int radio, enum rfkill_state state) 177 + static int dell_rfkill_set(void *data, bool blocked) 178 178 { 179 179 struct calling_interface_buffer buffer; 180 - int disable = (state == RFKILL_STATE_UNBLOCKED) ? 0 : 1; 180 + int disable = blocked ? 0 : 1; 181 + unsigned long radio = (unsigned long)data; 181 182 182 183 memset(&buffer, 0, sizeof(struct calling_interface_buffer)); 183 184 buffer.input[0] = (1 | (radio<<8) | (disable << 16)); ··· 187 186 return 0; 188 187 } 189 188 190 - static int dell_wifi_set(void *data, enum rfkill_state state) 191 - { 192 - return dell_rfkill_set(1, state); 193 - } 194 - 195 - static int dell_bluetooth_set(void *data, enum rfkill_state state) 196 - { 197 - return dell_rfkill_set(2, state); 198 - } 199 - 200 - static int dell_wwan_set(void *data, enum rfkill_state state) 201 - { 202 - return dell_rfkill_set(3, state); 203 - } 204 - 205 - static int dell_rfkill_get(int bit, enum rfkill_state *state) 189 + static void dell_rfkill_query(struct rfkill *rfkill, void *data) 206 190 { 207 191 struct calling_interface_buffer buffer; 208 192 int status; 209 - int new_state = RFKILL_STATE_HARD_BLOCKED; 193 + int bit = (unsigned long)data + 16; 210 194 211 195 memset(&buffer, 0, sizeof(struct calling_interface_buffer)); 212 196 dell_send_request(&buffer, 17, 11); 213 197 status = buffer.output[1]; 214 198 215 - if (status & (1<<16)) 216 - new_state = RFKILL_STATE_SOFT_BLOCKED; 217 - 218 - if (status & (1<<bit)) 219 - *state = new_state; 220 - else 221 - *state = RFKILL_STATE_UNBLOCKED; 222 - 223 - return 0; 199 + if (status & BIT(bit)) 200 + rfkill_set_hw_state(rfkill, !!(status & BIT(16))); 224 201 } 225 202 226 - static int dell_wifi_get(void *data, enum rfkill_state *state) 227 - { 228 - return dell_rfkill_get(17, state); 229 - } 230 - 231 - static int dell_bluetooth_get(void *data, enum rfkill_state *state) 232 - { 233 - return dell_rfkill_get(18, state); 234 - } 235 - 236 - static int dell_wwan_get(void *data, enum rfkill_state *state) 237 - { 238 - return dell_rfkill_get(19, state); 239 - } 203 + static const struct rfkill_ops dell_rfkill_ops = { 204 + .set_block = dell_rfkill_set, 205 + .query = dell_rfkill_query, 206 + }; 240 207 241 208 static int dell_setup_rfkill(void) 242 209 { ··· 217 248 status = buffer.output[1]; 218 249 219 250 if ((status & (1<<2|1<<8)) == (1<<2|1<<8)) { 220 - wifi_rfkill = rfkill_allocate(NULL, RFKILL_TYPE_WLAN); 221 - if (!wifi_rfkill) 251 + wifi_rfkill = rfkill_alloc("dell-wifi", NULL, RFKILL_TYPE_WLAN, 252 + &dell_rfkill_ops, (void *) 1); 253 + if (!wifi_rfkill) { 254 + ret = -ENOMEM; 222 255 goto err_wifi; 223 - wifi_rfkill->name = "dell-wifi"; 224 - wifi_rfkill->toggle_radio = dell_wifi_set; 225 - wifi_rfkill->get_state = dell_wifi_get; 256 + } 226 257 ret = rfkill_register(wifi_rfkill); 227 258 if (ret) 228 259 goto err_wifi; 229 260 } 230 261 231 262 if ((status & (1<<3|1<<9)) == (1<<3|1<<9)) { 232 - bluetooth_rfkill = rfkill_allocate(NULL, RFKILL_TYPE_BLUETOOTH); 233 - if (!bluetooth_rfkill) 263 + bluetooth_rfkill = rfkill_alloc("dell-bluetooth", NULL, 264 + RFKILL_TYPE_BLUETOOTH, 265 + &dell_rfkill_ops, (void *) 2); 266 + if (!bluetooth_rfkill) { 267 + ret = -ENOMEM; 234 268 goto err_bluetooth; 235 - bluetooth_rfkill->name = "dell-bluetooth"; 236 - bluetooth_rfkill->toggle_radio = dell_bluetooth_set; 237 - bluetooth_rfkill->get_state = dell_bluetooth_get; 269 + } 238 270 ret = rfkill_register(bluetooth_rfkill); 239 271 if (ret) 240 272 goto err_bluetooth; 241 273 } 242 274 243 275 if ((status & (1<<4|1<<10)) == (1<<4|1<<10)) { 244 - wwan_rfkill = rfkill_allocate(NULL, RFKILL_TYPE_WWAN); 245 - if (!wwan_rfkill) 276 + wwan_rfkill = rfkill_alloc("dell-wwan", NULL, RFKILL_TYPE_WWAN, 277 + &dell_rfkill_ops, (void *) 3); 278 + if (!wwan_rfkill) { 279 + ret = -ENOMEM; 246 280 goto err_wwan; 247 - wwan_rfkill->name = "dell-wwan"; 248 - wwan_rfkill->toggle_radio = dell_wwan_set; 249 - wwan_rfkill->get_state = dell_wwan_get; 281 + } 250 282 ret = rfkill_register(wwan_rfkill); 251 283 if (ret) 252 284 goto err_wwan; ··· 255 285 256 286 return 0; 257 287 err_wwan: 258 - if (wwan_rfkill) 259 - rfkill_free(wwan_rfkill); 260 - if (bluetooth_rfkill) { 261 - rfkill_unregister(bluetooth_rfkill); 262 - bluetooth_rfkill = NULL; 263 - } 264 - err_bluetooth: 288 + rfkill_destroy(wwan_rfkill); 265 289 if (bluetooth_rfkill) 266 - rfkill_free(bluetooth_rfkill); 267 - if (wifi_rfkill) { 268 - rfkill_unregister(wifi_rfkill); 269 - wifi_rfkill = NULL; 270 - } 271 - err_wifi: 290 + rfkill_unregister(bluetooth_rfkill); 291 + err_bluetooth: 292 + rfkill_destroy(bluetooth_rfkill); 272 293 if (wifi_rfkill) 273 - rfkill_free(wifi_rfkill); 294 + rfkill_unregister(wifi_rfkill); 295 + err_wifi: 296 + rfkill_destroy(wifi_rfkill); 274 297 275 298 return ret; 276 299 }
+29 -70
drivers/platform/x86/eeepc-laptop.c
··· 299 299 * Rfkill helpers 300 300 */ 301 301 302 - static int eeepc_wlan_rfkill_set(void *data, enum rfkill_state state) 303 - { 304 - if (state == RFKILL_STATE_SOFT_BLOCKED) 305 - return set_acpi(CM_ASL_WLAN, 0); 306 - else 307 - return set_acpi(CM_ASL_WLAN, 1); 308 - } 309 - 310 - static int eeepc_wlan_rfkill_state(void *data, enum rfkill_state *state) 302 + static bool eeepc_wlan_rfkill_blocked(void) 311 303 { 312 304 if (get_acpi(CM_ASL_WLAN) == 1) 313 - *state = RFKILL_STATE_UNBLOCKED; 314 - else 315 - *state = RFKILL_STATE_SOFT_BLOCKED; 316 - return 0; 305 + return false; 306 + return true; 317 307 } 318 308 319 - static int eeepc_bluetooth_rfkill_set(void *data, enum rfkill_state state) 309 + static int eeepc_rfkill_set(void *data, bool blocked) 320 310 { 321 - if (state == RFKILL_STATE_SOFT_BLOCKED) 322 - return set_acpi(CM_ASL_BLUETOOTH, 0); 323 - else 324 - return set_acpi(CM_ASL_BLUETOOTH, 1); 311 + unsigned long asl = (unsigned long)data; 312 + return set_acpi(asl, !blocked); 325 313 } 326 314 327 - static int eeepc_bluetooth_rfkill_state(void *data, enum rfkill_state *state) 328 - { 329 - if (get_acpi(CM_ASL_BLUETOOTH) == 1) 330 - *state = RFKILL_STATE_UNBLOCKED; 331 - else 332 - *state = RFKILL_STATE_SOFT_BLOCKED; 333 - return 0; 334 - } 315 + static const struct rfkill_ops eeepc_rfkill_ops = { 316 + .set_block = eeepc_rfkill_set, 317 + }; 335 318 336 319 /* 337 320 * Sys helpers ··· 514 531 515 532 static void eeepc_rfkill_notify(acpi_handle handle, u32 event, void *data) 516 533 { 517 - enum rfkill_state state; 518 534 struct pci_dev *dev; 519 535 struct pci_bus *bus = pci_find_bus(0, 1); 536 + bool blocked; 520 537 521 538 if (event != ACPI_NOTIFY_BUS_CHECK) 522 539 return; ··· 526 543 return; 527 544 } 528 545 529 - eeepc_wlan_rfkill_state(ehotk->eeepc_wlan_rfkill, &state); 530 - 531 - if (state == RFKILL_STATE_UNBLOCKED) { 546 + blocked = eeepc_wlan_rfkill_blocked(); 547 + if (!blocked) { 532 548 dev = pci_get_slot(bus, 0); 533 549 if (dev) { 534 550 /* Device already present */ ··· 548 566 } 549 567 } 550 568 551 - rfkill_force_state(ehotk->eeepc_wlan_rfkill, state); 569 + rfkill_set_sw_state(ehotk->eeepc_wlan_rfkill, blocked); 552 570 } 553 571 554 572 static void eeepc_hotk_notify(acpi_handle handle, u32 event, void *data) ··· 666 684 eeepc_register_rfkill_notifier("\\_SB.PCI0.P0P7"); 667 685 668 686 if (get_acpi(CM_ASL_WLAN) != -1) { 669 - ehotk->eeepc_wlan_rfkill = rfkill_allocate(&device->dev, 670 - RFKILL_TYPE_WLAN); 687 + ehotk->eeepc_wlan_rfkill = rfkill_alloc("eeepc-wlan", 688 + &device->dev, 689 + RFKILL_TYPE_WLAN, 690 + &eeepc_rfkill_ops, 691 + (void *)CM_ASL_WLAN); 671 692 672 693 if (!ehotk->eeepc_wlan_rfkill) 673 694 goto wlan_fail; 674 695 675 - ehotk->eeepc_wlan_rfkill->name = "eeepc-wlan"; 676 - ehotk->eeepc_wlan_rfkill->toggle_radio = eeepc_wlan_rfkill_set; 677 - ehotk->eeepc_wlan_rfkill->get_state = eeepc_wlan_rfkill_state; 678 - if (get_acpi(CM_ASL_WLAN) == 1) { 679 - ehotk->eeepc_wlan_rfkill->state = 680 - RFKILL_STATE_UNBLOCKED; 681 - rfkill_set_default(RFKILL_TYPE_WLAN, 682 - RFKILL_STATE_UNBLOCKED); 683 - } else { 684 - ehotk->eeepc_wlan_rfkill->state = 685 - RFKILL_STATE_SOFT_BLOCKED; 686 - rfkill_set_default(RFKILL_TYPE_WLAN, 687 - RFKILL_STATE_SOFT_BLOCKED); 688 - } 696 + rfkill_set_global_sw_state(RFKILL_TYPE_WLAN, 697 + get_acpi(CM_ASL_WLAN) != 1); 689 698 result = rfkill_register(ehotk->eeepc_wlan_rfkill); 690 699 if (result) 691 700 goto wlan_fail; ··· 684 711 685 712 if (get_acpi(CM_ASL_BLUETOOTH) != -1) { 686 713 ehotk->eeepc_bluetooth_rfkill = 687 - rfkill_allocate(&device->dev, RFKILL_TYPE_BLUETOOTH); 714 + rfkill_alloc("eeepc-bluetooth", 715 + &device->dev, 716 + RFKILL_TYPE_BLUETOOTH, 717 + &eeepc_rfkill_ops, 718 + (void *)CM_ASL_BLUETOOTH); 688 719 689 720 if (!ehotk->eeepc_bluetooth_rfkill) 690 721 goto bluetooth_fail; 691 722 692 - ehotk->eeepc_bluetooth_rfkill->name = "eeepc-bluetooth"; 693 - ehotk->eeepc_bluetooth_rfkill->toggle_radio = 694 - eeepc_bluetooth_rfkill_set; 695 - ehotk->eeepc_bluetooth_rfkill->get_state = 696 - eeepc_bluetooth_rfkill_state; 697 - if (get_acpi(CM_ASL_BLUETOOTH) == 1) { 698 - ehotk->eeepc_bluetooth_rfkill->state = 699 - RFKILL_STATE_UNBLOCKED; 700 - rfkill_set_default(RFKILL_TYPE_BLUETOOTH, 701 - RFKILL_STATE_UNBLOCKED); 702 - } else { 703 - ehotk->eeepc_bluetooth_rfkill->state = 704 - RFKILL_STATE_SOFT_BLOCKED; 705 - rfkill_set_default(RFKILL_TYPE_BLUETOOTH, 706 - RFKILL_STATE_SOFT_BLOCKED); 707 - } 708 - 723 + rfkill_set_global_sw_state(RFKILL_TYPE_BLUETOOTH, 724 + get_acpi(CM_ASL_BLUETOOTH) != 1); 709 725 result = rfkill_register(ehotk->eeepc_bluetooth_rfkill); 710 726 if (result) 711 727 goto bluetooth_fail; ··· 703 741 return 0; 704 742 705 743 bluetooth_fail: 706 - if (ehotk->eeepc_bluetooth_rfkill) 707 - rfkill_free(ehotk->eeepc_bluetooth_rfkill); 744 + rfkill_destroy(ehotk->eeepc_bluetooth_rfkill); 708 745 rfkill_unregister(ehotk->eeepc_wlan_rfkill); 709 - ehotk->eeepc_wlan_rfkill = NULL; 710 746 wlan_fail: 711 - if (ehotk->eeepc_wlan_rfkill) 712 - rfkill_free(ehotk->eeepc_wlan_rfkill); 747 + rfkill_destroy(ehotk->eeepc_wlan_rfkill); 713 748 eeepc_unregister_rfkill_notifier("\\_SB.PCI0.P0P6"); 714 749 eeepc_unregister_rfkill_notifier("\\_SB.PCI0.P0P7"); 715 750 ehotk_fail:
+53 -52
drivers/platform/x86/hp-wmi.c
··· 154 154 return hp_wmi_perform_query(HPWMI_DOCK_QUERY, 0, 0); 155 155 } 156 156 157 - static int hp_wmi_wifi_set(void *data, enum rfkill_state state) 157 + static int hp_wmi_set_block(void *data, bool blocked) 158 158 { 159 - if (state) 160 - return hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1, 0x101); 161 - else 162 - return hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1, 0x100); 159 + unsigned long b = (unsigned long) data; 160 + int query = BIT(b + 8) | ((!!blocked) << b); 161 + 162 + return hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1, query); 163 163 } 164 164 165 - static int hp_wmi_bluetooth_set(void *data, enum rfkill_state state) 166 - { 167 - if (state) 168 - return hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1, 0x202); 169 - else 170 - return hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1, 0x200); 171 - } 165 + static const struct rfkill_ops hp_wmi_rfkill_ops = { 166 + .set_block = hp_wmi_set_block, 167 + }; 172 168 173 - static int hp_wmi_wwan_set(void *data, enum rfkill_state state) 174 - { 175 - if (state) 176 - return hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1, 0x404); 177 - else 178 - return hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1, 0x400); 179 - } 180 - 181 - static int hp_wmi_wifi_state(void) 169 + static bool hp_wmi_wifi_state(void) 182 170 { 183 171 int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0); 184 172 185 173 if (wireless & 0x100) 186 - return RFKILL_STATE_UNBLOCKED; 174 + return false; 187 175 else 188 - return RFKILL_STATE_SOFT_BLOCKED; 176 + return true; 189 177 } 190 178 191 - static int hp_wmi_bluetooth_state(void) 179 + static bool hp_wmi_bluetooth_state(void) 192 180 { 193 181 int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0); 194 182 195 183 if (wireless & 0x10000) 196 - return RFKILL_STATE_UNBLOCKED; 184 + return false; 197 185 else 198 - return RFKILL_STATE_SOFT_BLOCKED; 186 + return true; 199 187 } 200 188 201 - static int hp_wmi_wwan_state(void) 189 + static bool hp_wmi_wwan_state(void) 202 190 { 203 191 int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0); 204 192 205 193 if (wireless & 0x1000000) 206 - return RFKILL_STATE_UNBLOCKED; 194 + return false; 207 195 else 208 - return RFKILL_STATE_SOFT_BLOCKED; 196 + return true; 209 197 } 210 198 211 199 static ssize_t show_display(struct device *dev, struct device_attribute *attr, ··· 335 347 } 336 348 } else if (eventcode == 0x5) { 337 349 if (wifi_rfkill) 338 - rfkill_force_state(wifi_rfkill, 339 - hp_wmi_wifi_state()); 350 + rfkill_set_sw_state(wifi_rfkill, 351 + hp_wmi_wifi_state()); 340 352 if (bluetooth_rfkill) 341 - rfkill_force_state(bluetooth_rfkill, 342 - hp_wmi_bluetooth_state()); 353 + rfkill_set_sw_state(bluetooth_rfkill, 354 + hp_wmi_bluetooth_state()); 343 355 if (wwan_rfkill) 344 - rfkill_force_state(wwan_rfkill, 345 - hp_wmi_wwan_state()); 356 + rfkill_set_sw_state(wwan_rfkill, 357 + hp_wmi_wwan_state()); 346 358 } else 347 359 printk(KERN_INFO "HP WMI: Unknown key pressed - %x\n", 348 360 eventcode); ··· 418 430 goto add_sysfs_error; 419 431 420 432 if (wireless & 0x1) { 421 - wifi_rfkill = rfkill_allocate(&device->dev, RFKILL_TYPE_WLAN); 422 - wifi_rfkill->name = "hp-wifi"; 423 - wifi_rfkill->state = hp_wmi_wifi_state(); 424 - wifi_rfkill->toggle_radio = hp_wmi_wifi_set; 433 + wifi_rfkill = rfkill_alloc("hp-wifi", &device->dev, 434 + RFKILL_TYPE_WLAN, 435 + &hp_wmi_rfkill_ops, 436 + (void *) 0); 437 + rfkill_set_sw_state(wifi_rfkill, hp_wmi_wifi_state()); 425 438 err = rfkill_register(wifi_rfkill); 426 439 if (err) 427 - goto add_sysfs_error; 440 + goto register_wifi_error; 428 441 } 429 442 430 443 if (wireless & 0x2) { 431 - bluetooth_rfkill = rfkill_allocate(&device->dev, 432 - RFKILL_TYPE_BLUETOOTH); 433 - bluetooth_rfkill->name = "hp-bluetooth"; 434 - bluetooth_rfkill->state = hp_wmi_bluetooth_state(); 435 - bluetooth_rfkill->toggle_radio = hp_wmi_bluetooth_set; 444 + bluetooth_rfkill = rfkill_alloc("hp-bluetooth", &device->dev, 445 + RFKILL_TYPE_BLUETOOTH, 446 + &hp_wmi_rfkill_ops, 447 + (void *) 1); 448 + rfkill_set_sw_state(bluetooth_rfkill, 449 + hp_wmi_bluetooth_state()); 436 450 err = rfkill_register(bluetooth_rfkill); 437 451 if (err) 438 452 goto register_bluetooth_error; 439 453 } 440 454 441 455 if (wireless & 0x4) { 442 - wwan_rfkill = rfkill_allocate(&device->dev, RFKILL_TYPE_WWAN); 443 - wwan_rfkill->name = "hp-wwan"; 444 - wwan_rfkill->state = hp_wmi_wwan_state(); 445 - wwan_rfkill->toggle_radio = hp_wmi_wwan_set; 456 + wwan_rfkill = rfkill_alloc("hp-wwan", &device->dev, 457 + RFKILL_TYPE_WWAN, 458 + &hp_wmi_rfkill_ops, 459 + (void *) 2); 460 + rfkill_set_sw_state(wwan_rfkill, hp_wmi_wwan_state()); 446 461 err = rfkill_register(wwan_rfkill); 447 462 if (err) 448 463 goto register_wwan_err; ··· 453 462 454 463 return 0; 455 464 register_wwan_err: 465 + rfkill_destroy(wwan_rfkill); 456 466 if (bluetooth_rfkill) 457 467 rfkill_unregister(bluetooth_rfkill); 458 468 register_bluetooth_error: 469 + rfkill_destroy(bluetooth_rfkill); 459 470 if (wifi_rfkill) 460 471 rfkill_unregister(wifi_rfkill); 472 + register_wifi_error: 473 + rfkill_destroy(wifi_rfkill); 461 474 add_sysfs_error: 462 475 cleanup_sysfs(device); 463 476 return err; ··· 471 476 { 472 477 cleanup_sysfs(device); 473 478 474 - if (wifi_rfkill) 479 + if (wifi_rfkill) { 475 480 rfkill_unregister(wifi_rfkill); 476 - if (bluetooth_rfkill) 481 + rfkill_destroy(wifi_rfkill); 482 + } 483 + if (bluetooth_rfkill) { 477 484 rfkill_unregister(bluetooth_rfkill); 478 - if (wwan_rfkill) 485 + rfkill_destroy(wifi_rfkill); 486 + } 487 + if (wwan_rfkill) { 479 488 rfkill_unregister(wwan_rfkill); 489 + rfkill_destroy(wwan_rfkill); 490 + } 480 491 481 492 return 0; 482 493 }
+72 -121
drivers/platform/x86/sony-laptop.c
··· 128 128 SONY_BLUETOOTH, 129 129 SONY_WWAN, 130 130 SONY_WIMAX, 131 - SONY_RFKILL_MAX, 131 + N_SONY_RFKILL, 132 132 }; 133 133 134 - static struct rfkill *sony_rfkill_devices[SONY_RFKILL_MAX]; 135 - static int sony_rfkill_address[SONY_RFKILL_MAX] = {0x300, 0x500, 0x700, 0x900}; 134 + static struct rfkill *sony_rfkill_devices[N_SONY_RFKILL]; 135 + static int sony_rfkill_address[N_SONY_RFKILL] = {0x300, 0x500, 0x700, 0x900}; 136 136 static void sony_nc_rfkill_update(void); 137 137 138 138 /*********** Input Devices ***********/ ··· 1051 1051 { 1052 1052 int i; 1053 1053 1054 - for (i = 0; i < SONY_RFKILL_MAX; i++) { 1055 - if (sony_rfkill_devices[i]) 1054 + for (i = 0; i < N_SONY_RFKILL; i++) { 1055 + if (sony_rfkill_devices[i]) { 1056 1056 rfkill_unregister(sony_rfkill_devices[i]); 1057 + rfkill_destroy(sony_rfkill_devices[i]); 1058 + } 1057 1059 } 1058 1060 } 1059 1061 1060 - static int sony_nc_rfkill_get(void *data, enum rfkill_state *state) 1061 - { 1062 - int result; 1063 - int argument = sony_rfkill_address[(long) data]; 1064 - 1065 - sony_call_snc_handle(0x124, 0x200, &result); 1066 - if (result & 0x1) { 1067 - sony_call_snc_handle(0x124, argument, &result); 1068 - if (result & 0xf) 1069 - *state = RFKILL_STATE_UNBLOCKED; 1070 - else 1071 - *state = RFKILL_STATE_SOFT_BLOCKED; 1072 - } else { 1073 - *state = RFKILL_STATE_HARD_BLOCKED; 1074 - } 1075 - 1076 - return 0; 1077 - } 1078 - 1079 - static int sony_nc_rfkill_set(void *data, enum rfkill_state state) 1062 + static int sony_nc_rfkill_set(void *data, bool blocked) 1080 1063 { 1081 1064 int result; 1082 1065 int argument = sony_rfkill_address[(long) data] + 0x100; 1083 1066 1084 - if (state == RFKILL_STATE_UNBLOCKED) 1067 + if (!blocked) 1085 1068 argument |= 0xff0000; 1086 1069 1087 1070 return sony_call_snc_handle(0x124, argument, &result); 1088 1071 } 1089 1072 1090 - static int sony_nc_setup_wifi_rfkill(struct acpi_device *device) 1073 + static const struct rfkill_ops sony_rfkill_ops = { 1074 + .set_block = sony_nc_rfkill_set, 1075 + }; 1076 + 1077 + static int sony_nc_setup_rfkill(struct acpi_device *device, 1078 + enum sony_nc_rfkill nc_type) 1091 1079 { 1092 1080 int err = 0; 1093 - struct rfkill *sony_wifi_rfkill; 1081 + struct rfkill *rfk; 1082 + enum rfkill_type type; 1083 + const char *name; 1094 1084 1095 - sony_wifi_rfkill = rfkill_allocate(&device->dev, RFKILL_TYPE_WLAN); 1096 - if (!sony_wifi_rfkill) 1097 - return -1; 1098 - sony_wifi_rfkill->name = "sony-wifi"; 1099 - sony_wifi_rfkill->toggle_radio = sony_nc_rfkill_set; 1100 - sony_wifi_rfkill->get_state = sony_nc_rfkill_get; 1101 - sony_wifi_rfkill->data = (void *)SONY_WIFI; 1102 - err = rfkill_register(sony_wifi_rfkill); 1103 - if (err) 1104 - rfkill_free(sony_wifi_rfkill); 1105 - else { 1106 - sony_rfkill_devices[SONY_WIFI] = sony_wifi_rfkill; 1107 - sony_nc_rfkill_set(sony_wifi_rfkill->data, 1108 - RFKILL_STATE_UNBLOCKED); 1085 + switch (nc_type) { 1086 + case SONY_WIFI: 1087 + type = RFKILL_TYPE_WLAN; 1088 + name = "sony-wifi"; 1089 + break; 1090 + case SONY_BLUETOOTH: 1091 + type = RFKILL_TYPE_BLUETOOTH; 1092 + name = "sony-bluetooth"; 1093 + break; 1094 + case SONY_WWAN: 1095 + type = RFKILL_TYPE_WWAN; 1096 + name = "sony-wwan"; 1097 + break; 1098 + case SONY_WIMAX: 1099 + type = RFKILL_TYPE_WIMAX; 1100 + name = "sony-wimax"; 1101 + break; 1102 + default: 1103 + return -EINVAL; 1109 1104 } 1110 - return err; 1111 - } 1112 1105 1113 - static int sony_nc_setup_bluetooth_rfkill(struct acpi_device *device) 1114 - { 1115 - int err = 0; 1116 - struct rfkill *sony_bluetooth_rfkill; 1106 + rfk = rfkill_alloc(name, &device->dev, type, 1107 + &sony_rfkill_ops, (void *)nc_type); 1108 + if (!rfk) 1109 + return -ENOMEM; 1117 1110 1118 - sony_bluetooth_rfkill = rfkill_allocate(&device->dev, 1119 - RFKILL_TYPE_BLUETOOTH); 1120 - if (!sony_bluetooth_rfkill) 1121 - return -1; 1122 - sony_bluetooth_rfkill->name = "sony-bluetooth"; 1123 - sony_bluetooth_rfkill->toggle_radio = sony_nc_rfkill_set; 1124 - sony_bluetooth_rfkill->get_state = sony_nc_rfkill_get; 1125 - sony_bluetooth_rfkill->data = (void *)SONY_BLUETOOTH; 1126 - err = rfkill_register(sony_bluetooth_rfkill); 1127 - if (err) 1128 - rfkill_free(sony_bluetooth_rfkill); 1129 - else { 1130 - sony_rfkill_devices[SONY_BLUETOOTH] = sony_bluetooth_rfkill; 1131 - sony_nc_rfkill_set(sony_bluetooth_rfkill->data, 1132 - RFKILL_STATE_UNBLOCKED); 1111 + err = rfkill_register(rfk); 1112 + if (err) { 1113 + rfkill_destroy(rfk); 1114 + return err; 1133 1115 } 1134 - return err; 1135 - } 1136 - 1137 - static int sony_nc_setup_wwan_rfkill(struct acpi_device *device) 1138 - { 1139 - int err = 0; 1140 - struct rfkill *sony_wwan_rfkill; 1141 - 1142 - sony_wwan_rfkill = rfkill_allocate(&device->dev, RFKILL_TYPE_WWAN); 1143 - if (!sony_wwan_rfkill) 1144 - return -1; 1145 - sony_wwan_rfkill->name = "sony-wwan"; 1146 - sony_wwan_rfkill->toggle_radio = sony_nc_rfkill_set; 1147 - sony_wwan_rfkill->get_state = sony_nc_rfkill_get; 1148 - sony_wwan_rfkill->data = (void *)SONY_WWAN; 1149 - err = rfkill_register(sony_wwan_rfkill); 1150 - if (err) 1151 - rfkill_free(sony_wwan_rfkill); 1152 - else { 1153 - sony_rfkill_devices[SONY_WWAN] = sony_wwan_rfkill; 1154 - sony_nc_rfkill_set(sony_wwan_rfkill->data, 1155 - RFKILL_STATE_UNBLOCKED); 1156 - } 1157 - return err; 1158 - } 1159 - 1160 - static int sony_nc_setup_wimax_rfkill(struct acpi_device *device) 1161 - { 1162 - int err = 0; 1163 - struct rfkill *sony_wimax_rfkill; 1164 - 1165 - sony_wimax_rfkill = rfkill_allocate(&device->dev, RFKILL_TYPE_WIMAX); 1166 - if (!sony_wimax_rfkill) 1167 - return -1; 1168 - sony_wimax_rfkill->name = "sony-wimax"; 1169 - sony_wimax_rfkill->toggle_radio = sony_nc_rfkill_set; 1170 - sony_wimax_rfkill->get_state = sony_nc_rfkill_get; 1171 - sony_wimax_rfkill->data = (void *)SONY_WIMAX; 1172 - err = rfkill_register(sony_wimax_rfkill); 1173 - if (err) 1174 - rfkill_free(sony_wimax_rfkill); 1175 - else { 1176 - sony_rfkill_devices[SONY_WIMAX] = sony_wimax_rfkill; 1177 - sony_nc_rfkill_set(sony_wimax_rfkill->data, 1178 - RFKILL_STATE_UNBLOCKED); 1179 - } 1116 + sony_rfkill_devices[nc_type] = rfk; 1117 + sony_nc_rfkill_set((void *)nc_type, false); 1180 1118 return err; 1181 1119 } 1182 1120 1183 1121 static void sony_nc_rfkill_update() 1184 1122 { 1185 - int i; 1186 - enum rfkill_state state; 1123 + enum sony_nc_rfkill i; 1124 + int result; 1125 + bool hwblock; 1187 1126 1188 - for (i = 0; i < SONY_RFKILL_MAX; i++) { 1189 - if (sony_rfkill_devices[i]) { 1190 - sony_rfkill_devices[i]-> 1191 - get_state(sony_rfkill_devices[i]->data, 1192 - &state); 1193 - rfkill_force_state(sony_rfkill_devices[i], state); 1127 + sony_call_snc_handle(0x124, 0x200, &result); 1128 + hwblock = !(result & 0x1); 1129 + 1130 + for (i = 0; i < N_SONY_RFKILL; i++) { 1131 + int argument = sony_rfkill_address[i]; 1132 + 1133 + if (!sony_rfkill_devices[i]) 1134 + continue; 1135 + 1136 + if (hwblock) { 1137 + if (rfkill_set_hw_state(sony_rfkill_devices[i], true)) 1138 + sony_nc_rfkill_set(sony_rfkill_devices[i], 1139 + true); 1140 + continue; 1194 1141 } 1142 + 1143 + sony_call_snc_handle(0x124, argument, &result); 1144 + rfkill_set_states(sony_rfkill_devices[i], 1145 + !(result & 0xf), false); 1195 1146 } 1196 1147 } 1197 1148 ··· 1161 1210 } 1162 1211 1163 1212 if (result & 0x1) 1164 - sony_nc_setup_wifi_rfkill(device); 1213 + sony_nc_setup_rfkill(device, SONY_WIFI); 1165 1214 if (result & 0x2) 1166 - sony_nc_setup_bluetooth_rfkill(device); 1215 + sony_nc_setup_rfkill(device, SONY_BLUETOOTH); 1167 1216 if (result & 0x1c) 1168 - sony_nc_setup_wwan_rfkill(device); 1217 + sony_nc_setup_rfkill(device, SONY_WWAN); 1169 1218 if (result & 0x20) 1170 - sony_nc_setup_wimax_rfkill(device); 1219 + sony_nc_setup_rfkill(device, SONY_WIMAX); 1171 1220 1172 1221 return 0; 1173 1222 }
+469 -438
drivers/platform/x86/thinkpad_acpi.c
··· 166 166 167 167 #define TPACPI_MAX_ACPI_ARGS 3 168 168 169 - /* rfkill switches */ 170 - enum { 171 - TPACPI_RFK_BLUETOOTH_SW_ID = 0, 172 - TPACPI_RFK_WWAN_SW_ID, 173 - TPACPI_RFK_UWB_SW_ID, 174 - }; 175 - 176 169 /* printk headers */ 177 170 #define TPACPI_LOG TPACPI_FILE ": " 178 171 #define TPACPI_EMERG KERN_EMERG TPACPI_LOG ··· 998 1005 return 0; 999 1006 } 1000 1007 1001 - static int __init tpacpi_new_rfkill(const unsigned int id, 1002 - struct rfkill **rfk, 1003 - const enum rfkill_type rfktype, 1004 - const char *name, 1005 - const bool set_default, 1006 - int (*toggle_radio)(void *, enum rfkill_state), 1007 - int (*get_state)(void *, enum rfkill_state *)) 1008 - { 1009 - int res; 1010 - enum rfkill_state initial_state = RFKILL_STATE_SOFT_BLOCKED; 1011 - 1012 - res = get_state(NULL, &initial_state); 1013 - if (res < 0) { 1014 - printk(TPACPI_ERR 1015 - "failed to read initial state for %s, error %d; " 1016 - "will turn radio off\n", name, res); 1017 - } else if (set_default) { 1018 - /* try to set the initial state as the default for the rfkill 1019 - * type, since we ask the firmware to preserve it across S5 in 1020 - * NVRAM */ 1021 - if (rfkill_set_default(rfktype, 1022 - (initial_state == RFKILL_STATE_UNBLOCKED) ? 1023 - RFKILL_STATE_UNBLOCKED : 1024 - RFKILL_STATE_SOFT_BLOCKED) == -EPERM) 1025 - vdbg_printk(TPACPI_DBG_RFKILL, 1026 - "Default state for %s cannot be changed\n", 1027 - name); 1028 - } 1029 - 1030 - *rfk = rfkill_allocate(&tpacpi_pdev->dev, rfktype); 1031 - if (!*rfk) { 1032 - printk(TPACPI_ERR 1033 - "failed to allocate memory for rfkill class\n"); 1034 - return -ENOMEM; 1035 - } 1036 - 1037 - (*rfk)->name = name; 1038 - (*rfk)->get_state = get_state; 1039 - (*rfk)->toggle_radio = toggle_radio; 1040 - (*rfk)->state = initial_state; 1041 - 1042 - res = rfkill_register(*rfk); 1043 - if (res < 0) { 1044 - printk(TPACPI_ERR 1045 - "failed to register %s rfkill switch: %d\n", 1046 - name, res); 1047 - rfkill_free(*rfk); 1048 - *rfk = NULL; 1049 - return res; 1050 - } 1051 - 1052 - return 0; 1053 - } 1054 - 1055 1008 static void printk_deprecated_attribute(const char * const what, 1056 1009 const char * const details) 1057 1010 { ··· 1007 1068 what, details); 1008 1069 } 1009 1070 1071 + /************************************************************************* 1072 + * rfkill and radio control support helpers 1073 + */ 1074 + 1075 + /* 1076 + * ThinkPad-ACPI firmware handling model: 1077 + * 1078 + * WLSW (master wireless switch) is event-driven, and is common to all 1079 + * firmware-controlled radios. It cannot be controlled, just monitored, 1080 + * as expected. It overrides all radio state in firmware 1081 + * 1082 + * The kernel, a masked-off hotkey, and WLSW can change the radio state 1083 + * (TODO: verify how WLSW interacts with the returned radio state). 1084 + * 1085 + * The only time there are shadow radio state changes, is when 1086 + * masked-off hotkeys are used. 1087 + */ 1088 + 1089 + /* 1090 + * Internal driver API for radio state: 1091 + * 1092 + * int: < 0 = error, otherwise enum tpacpi_rfkill_state 1093 + * bool: true means radio blocked (off) 1094 + */ 1095 + enum tpacpi_rfkill_state { 1096 + TPACPI_RFK_RADIO_OFF = 0, 1097 + TPACPI_RFK_RADIO_ON 1098 + }; 1099 + 1100 + /* rfkill switches */ 1101 + enum tpacpi_rfk_id { 1102 + TPACPI_RFK_BLUETOOTH_SW_ID = 0, 1103 + TPACPI_RFK_WWAN_SW_ID, 1104 + TPACPI_RFK_UWB_SW_ID, 1105 + TPACPI_RFK_SW_MAX 1106 + }; 1107 + 1108 + static const char *tpacpi_rfkill_names[] = { 1109 + [TPACPI_RFK_BLUETOOTH_SW_ID] = "bluetooth", 1110 + [TPACPI_RFK_WWAN_SW_ID] = "wwan", 1111 + [TPACPI_RFK_UWB_SW_ID] = "uwb", 1112 + [TPACPI_RFK_SW_MAX] = NULL 1113 + }; 1114 + 1115 + /* ThinkPad-ACPI rfkill subdriver */ 1116 + struct tpacpi_rfk { 1117 + struct rfkill *rfkill; 1118 + enum tpacpi_rfk_id id; 1119 + const struct tpacpi_rfk_ops *ops; 1120 + }; 1121 + 1122 + struct tpacpi_rfk_ops { 1123 + /* firmware interface */ 1124 + int (*get_status)(void); 1125 + int (*set_status)(const enum tpacpi_rfkill_state); 1126 + }; 1127 + 1128 + static struct tpacpi_rfk *tpacpi_rfkill_switches[TPACPI_RFK_SW_MAX]; 1129 + 1130 + /* Query FW and update rfkill sw state for a given rfkill switch */ 1131 + static int tpacpi_rfk_update_swstate(const struct tpacpi_rfk *tp_rfk) 1132 + { 1133 + int status; 1134 + 1135 + if (!tp_rfk) 1136 + return -ENODEV; 1137 + 1138 + status = (tp_rfk->ops->get_status)(); 1139 + if (status < 0) 1140 + return status; 1141 + 1142 + rfkill_set_sw_state(tp_rfk->rfkill, 1143 + (status == TPACPI_RFK_RADIO_OFF)); 1144 + 1145 + return status; 1146 + } 1147 + 1148 + /* Query FW and update rfkill sw state for all rfkill switches */ 1149 + static void tpacpi_rfk_update_swstate_all(void) 1150 + { 1151 + unsigned int i; 1152 + 1153 + for (i = 0; i < TPACPI_RFK_SW_MAX; i++) 1154 + tpacpi_rfk_update_swstate(tpacpi_rfkill_switches[i]); 1155 + } 1156 + 1157 + /* 1158 + * Sync the HW-blocking state of all rfkill switches, 1159 + * do notice it causes the rfkill core to schedule uevents 1160 + */ 1161 + static void tpacpi_rfk_update_hwblock_state(bool blocked) 1162 + { 1163 + unsigned int i; 1164 + struct tpacpi_rfk *tp_rfk; 1165 + 1166 + for (i = 0; i < TPACPI_RFK_SW_MAX; i++) { 1167 + tp_rfk = tpacpi_rfkill_switches[i]; 1168 + if (tp_rfk) { 1169 + if (rfkill_set_hw_state(tp_rfk->rfkill, 1170 + blocked)) { 1171 + /* ignore -- we track sw block */ 1172 + } 1173 + } 1174 + } 1175 + } 1176 + 1177 + /* Call to get the WLSW state from the firmware */ 1178 + static int hotkey_get_wlsw(void); 1179 + 1180 + /* Call to query WLSW state and update all rfkill switches */ 1181 + static bool tpacpi_rfk_check_hwblock_state(void) 1182 + { 1183 + int res = hotkey_get_wlsw(); 1184 + int hw_blocked; 1185 + 1186 + /* When unknown or unsupported, we have to assume it is unblocked */ 1187 + if (res < 0) 1188 + return false; 1189 + 1190 + hw_blocked = (res == TPACPI_RFK_RADIO_OFF); 1191 + tpacpi_rfk_update_hwblock_state(hw_blocked); 1192 + 1193 + return hw_blocked; 1194 + } 1195 + 1196 + static int tpacpi_rfk_hook_set_block(void *data, bool blocked) 1197 + { 1198 + struct tpacpi_rfk *tp_rfk = data; 1199 + int res; 1200 + 1201 + dbg_printk(TPACPI_DBG_RFKILL, 1202 + "request to change radio state to %s\n", 1203 + blocked ? "blocked" : "unblocked"); 1204 + 1205 + /* try to set radio state */ 1206 + res = (tp_rfk->ops->set_status)(blocked ? 1207 + TPACPI_RFK_RADIO_OFF : TPACPI_RFK_RADIO_ON); 1208 + 1209 + /* and update the rfkill core with whatever the FW really did */ 1210 + tpacpi_rfk_update_swstate(tp_rfk); 1211 + 1212 + return (res < 0) ? res : 0; 1213 + } 1214 + 1215 + static const struct rfkill_ops tpacpi_rfk_rfkill_ops = { 1216 + .set_block = tpacpi_rfk_hook_set_block, 1217 + }; 1218 + 1219 + static int __init tpacpi_new_rfkill(const enum tpacpi_rfk_id id, 1220 + const struct tpacpi_rfk_ops *tp_rfkops, 1221 + const enum rfkill_type rfktype, 1222 + const char *name, 1223 + const bool set_default) 1224 + { 1225 + struct tpacpi_rfk *atp_rfk; 1226 + int res; 1227 + bool initial_sw_state = false; 1228 + int initial_sw_status; 1229 + 1230 + BUG_ON(id >= TPACPI_RFK_SW_MAX || tpacpi_rfkill_switches[id]); 1231 + 1232 + initial_sw_status = (tp_rfkops->get_status)(); 1233 + if (initial_sw_status < 0) { 1234 + printk(TPACPI_ERR 1235 + "failed to read initial state for %s, error %d; " 1236 + "will turn radio off\n", name, initial_sw_status); 1237 + } else { 1238 + initial_sw_state = (initial_sw_status == TPACPI_RFK_RADIO_OFF); 1239 + if (set_default) { 1240 + /* try to set the initial state as the default for the 1241 + * rfkill type, since we ask the firmware to preserve 1242 + * it across S5 in NVRAM */ 1243 + rfkill_set_global_sw_state(rfktype, initial_sw_state); 1244 + } 1245 + } 1246 + 1247 + atp_rfk = kzalloc(sizeof(struct tpacpi_rfk), GFP_KERNEL); 1248 + if (atp_rfk) 1249 + atp_rfk->rfkill = rfkill_alloc(name, 1250 + &tpacpi_pdev->dev, 1251 + rfktype, 1252 + &tpacpi_rfk_rfkill_ops, 1253 + atp_rfk); 1254 + if (!atp_rfk || !atp_rfk->rfkill) { 1255 + printk(TPACPI_ERR 1256 + "failed to allocate memory for rfkill class\n"); 1257 + kfree(atp_rfk); 1258 + return -ENOMEM; 1259 + } 1260 + 1261 + atp_rfk->id = id; 1262 + atp_rfk->ops = tp_rfkops; 1263 + 1264 + rfkill_set_states(atp_rfk->rfkill, initial_sw_state, 1265 + tpacpi_rfk_check_hwblock_state()); 1266 + 1267 + res = rfkill_register(atp_rfk->rfkill); 1268 + if (res < 0) { 1269 + printk(TPACPI_ERR 1270 + "failed to register %s rfkill switch: %d\n", 1271 + name, res); 1272 + rfkill_destroy(atp_rfk->rfkill); 1273 + kfree(atp_rfk); 1274 + return res; 1275 + } 1276 + 1277 + tpacpi_rfkill_switches[id] = atp_rfk; 1278 + return 0; 1279 + } 1280 + 1281 + static void tpacpi_destroy_rfkill(const enum tpacpi_rfk_id id) 1282 + { 1283 + struct tpacpi_rfk *tp_rfk; 1284 + 1285 + BUG_ON(id >= TPACPI_RFK_SW_MAX); 1286 + 1287 + tp_rfk = tpacpi_rfkill_switches[id]; 1288 + if (tp_rfk) { 1289 + rfkill_unregister(tp_rfk->rfkill); 1290 + tpacpi_rfkill_switches[id] = NULL; 1291 + kfree(tp_rfk); 1292 + } 1293 + } 1294 + 1010 1295 static void printk_deprecated_rfkill_attribute(const char * const what) 1011 1296 { 1012 1297 printk_deprecated_attribute(what, 1013 1298 "Please switch to generic rfkill before year 2010"); 1299 + } 1300 + 1301 + /* sysfs <radio> enable ------------------------------------------------ */ 1302 + static ssize_t tpacpi_rfk_sysfs_enable_show(const enum tpacpi_rfk_id id, 1303 + struct device_attribute *attr, 1304 + char *buf) 1305 + { 1306 + int status; 1307 + 1308 + printk_deprecated_rfkill_attribute(attr->attr.name); 1309 + 1310 + /* This is in the ABI... */ 1311 + if (tpacpi_rfk_check_hwblock_state()) { 1312 + status = TPACPI_RFK_RADIO_OFF; 1313 + } else { 1314 + status = tpacpi_rfk_update_swstate(tpacpi_rfkill_switches[id]); 1315 + if (status < 0) 1316 + return status; 1317 + } 1318 + 1319 + return snprintf(buf, PAGE_SIZE, "%d\n", 1320 + (status == TPACPI_RFK_RADIO_ON) ? 1 : 0); 1321 + } 1322 + 1323 + static ssize_t tpacpi_rfk_sysfs_enable_store(const enum tpacpi_rfk_id id, 1324 + struct device_attribute *attr, 1325 + const char *buf, size_t count) 1326 + { 1327 + unsigned long t; 1328 + int res; 1329 + 1330 + printk_deprecated_rfkill_attribute(attr->attr.name); 1331 + 1332 + if (parse_strtoul(buf, 1, &t)) 1333 + return -EINVAL; 1334 + 1335 + tpacpi_disclose_usertask(attr->attr.name, "set to %ld\n", t); 1336 + 1337 + /* This is in the ABI... */ 1338 + if (tpacpi_rfk_check_hwblock_state() && !!t) 1339 + return -EPERM; 1340 + 1341 + res = tpacpi_rfkill_switches[id]->ops->set_status((!!t) ? 1342 + TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF); 1343 + tpacpi_rfk_update_swstate(tpacpi_rfkill_switches[id]); 1344 + 1345 + return (res < 0) ? res : count; 1346 + } 1347 + 1348 + /* procfs -------------------------------------------------------------- */ 1349 + static int tpacpi_rfk_procfs_read(const enum tpacpi_rfk_id id, char *p) 1350 + { 1351 + int len = 0; 1352 + 1353 + if (id >= TPACPI_RFK_SW_MAX) 1354 + len += sprintf(p + len, "status:\t\tnot supported\n"); 1355 + else { 1356 + int status; 1357 + 1358 + /* This is in the ABI... */ 1359 + if (tpacpi_rfk_check_hwblock_state()) { 1360 + status = TPACPI_RFK_RADIO_OFF; 1361 + } else { 1362 + status = tpacpi_rfk_update_swstate( 1363 + tpacpi_rfkill_switches[id]); 1364 + if (status < 0) 1365 + return status; 1366 + } 1367 + 1368 + len += sprintf(p + len, "status:\t\t%s\n", 1369 + (status == TPACPI_RFK_RADIO_ON) ? 1370 + "enabled" : "disabled"); 1371 + len += sprintf(p + len, "commands:\tenable, disable\n"); 1372 + } 1373 + 1374 + return len; 1375 + } 1376 + 1377 + static int tpacpi_rfk_procfs_write(const enum tpacpi_rfk_id id, char *buf) 1378 + { 1379 + char *cmd; 1380 + int status = -1; 1381 + int res = 0; 1382 + 1383 + if (id >= TPACPI_RFK_SW_MAX) 1384 + return -ENODEV; 1385 + 1386 + while ((cmd = next_cmd(&buf))) { 1387 + if (strlencmp(cmd, "enable") == 0) 1388 + status = TPACPI_RFK_RADIO_ON; 1389 + else if (strlencmp(cmd, "disable") == 0) 1390 + status = TPACPI_RFK_RADIO_OFF; 1391 + else 1392 + return -EINVAL; 1393 + } 1394 + 1395 + if (status != -1) { 1396 + tpacpi_disclose_usertask("procfs", "attempt to %s %s\n", 1397 + (status == TPACPI_RFK_RADIO_ON) ? 1398 + "enable" : "disable", 1399 + tpacpi_rfkill_names[id]); 1400 + res = (tpacpi_rfkill_switches[id]->ops->set_status)(status); 1401 + tpacpi_rfk_update_swstate(tpacpi_rfkill_switches[id]); 1402 + } 1403 + 1404 + return res; 1014 1405 } 1015 1406 1016 1407 /************************************************************************* ··· 1396 1127 1397 1128 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES 1398 1129 1399 - static void tpacpi_send_radiosw_update(void); 1400 - 1401 1130 /* wlsw_emulstate ------------------------------------------------------ */ 1402 1131 static ssize_t tpacpi_driver_wlsw_emulstate_show(struct device_driver *drv, 1403 1132 char *buf) ··· 1411 1144 if (parse_strtoul(buf, 1, &t)) 1412 1145 return -EINVAL; 1413 1146 1414 - if (tpacpi_wlsw_emulstate != t) { 1147 + if (tpacpi_wlsw_emulstate != !!t) { 1415 1148 tpacpi_wlsw_emulstate = !!t; 1416 - tpacpi_send_radiosw_update(); 1417 - } else 1418 - tpacpi_wlsw_emulstate = !!t; 1149 + tpacpi_rfk_update_hwblock_state(!t); /* negative logic */ 1150 + } 1419 1151 1420 1152 return count; 1421 1153 } ··· 1729 1463 /* HKEY.MHKG() return bits */ 1730 1464 #define TP_HOTKEY_TABLET_MASK (1 << 3) 1731 1465 1732 - static int hotkey_get_wlsw(int *status) 1466 + static int hotkey_get_wlsw(void) 1733 1467 { 1468 + int status; 1469 + 1470 + if (!tp_features.hotkey_wlsw) 1471 + return -ENODEV; 1472 + 1734 1473 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES 1735 - if (dbg_wlswemul) { 1736 - *status = !!tpacpi_wlsw_emulstate; 1737 - return 0; 1738 - } 1474 + if (dbg_wlswemul) 1475 + return (tpacpi_wlsw_emulstate) ? 1476 + TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; 1739 1477 #endif 1740 - if (!acpi_evalf(hkey_handle, status, "WLSW", "d")) 1478 + 1479 + if (!acpi_evalf(hkey_handle, &status, "WLSW", "d")) 1741 1480 return -EIO; 1742 - return 0; 1481 + 1482 + return (status) ? TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; 1743 1483 } 1744 1484 1745 1485 static int hotkey_get_tablet_mode(int *status) ··· 2379 2107 struct device_attribute *attr, 2380 2108 char *buf) 2381 2109 { 2382 - int res, s; 2383 - res = hotkey_get_wlsw(&s); 2110 + int res; 2111 + res = hotkey_get_wlsw(); 2384 2112 if (res < 0) 2385 2113 return res; 2386 2114 2387 - return snprintf(buf, PAGE_SIZE, "%d\n", !!s); 2115 + /* Opportunistic update */ 2116 + tpacpi_rfk_update_hwblock_state((res == TPACPI_RFK_RADIO_OFF)); 2117 + 2118 + return snprintf(buf, PAGE_SIZE, "%d\n", 2119 + (res == TPACPI_RFK_RADIO_OFF) ? 0 : 1); 2388 2120 } 2389 2121 2390 2122 static struct device_attribute dev_attr_hotkey_radio_sw = ··· 2499 2223 &dev_attr_hotkey_wakeup_hotunplug_complete.attr, 2500 2224 }; 2501 2225 2502 - static void bluetooth_update_rfk(void); 2503 - static void wan_update_rfk(void); 2504 - static void uwb_update_rfk(void); 2226 + /* 2227 + * Sync both the hw and sw blocking state of all switches 2228 + */ 2505 2229 static void tpacpi_send_radiosw_update(void) 2506 2230 { 2507 2231 int wlsw; 2508 2232 2509 - /* Sync these BEFORE sending any rfkill events */ 2510 - if (tp_features.bluetooth) 2511 - bluetooth_update_rfk(); 2512 - if (tp_features.wan) 2513 - wan_update_rfk(); 2514 - if (tp_features.uwb) 2515 - uwb_update_rfk(); 2233 + /* 2234 + * We must sync all rfkill controllers *before* issuing any 2235 + * rfkill input events, or we will race the rfkill core input 2236 + * handler. 2237 + * 2238 + * tpacpi_inputdev_send_mutex works as a syncronization point 2239 + * for the above. 2240 + * 2241 + * We optimize to avoid numerous calls to hotkey_get_wlsw. 2242 + */ 2516 2243 2517 - if (tp_features.hotkey_wlsw && !hotkey_get_wlsw(&wlsw)) { 2244 + wlsw = hotkey_get_wlsw(); 2245 + 2246 + /* Sync hw blocking state first if it is hw-blocked */ 2247 + if (wlsw == TPACPI_RFK_RADIO_OFF) 2248 + tpacpi_rfk_update_hwblock_state(true); 2249 + 2250 + /* Sync sw blocking state */ 2251 + tpacpi_rfk_update_swstate_all(); 2252 + 2253 + /* Sync hw blocking state last if it is hw-unblocked */ 2254 + if (wlsw == TPACPI_RFK_RADIO_ON) 2255 + tpacpi_rfk_update_hwblock_state(false); 2256 + 2257 + /* Issue rfkill input event for WLSW switch */ 2258 + if (!(wlsw < 0)) { 2518 2259 mutex_lock(&tpacpi_inputdev_send_mutex); 2519 2260 2520 2261 input_report_switch(tpacpi_inputdev, 2521 - SW_RFKILL_ALL, !!wlsw); 2262 + SW_RFKILL_ALL, (wlsw > 0)); 2522 2263 input_sync(tpacpi_inputdev); 2523 2264 2524 2265 mutex_unlock(&tpacpi_inputdev_send_mutex); 2525 2266 } 2267 + 2268 + /* 2269 + * this can be unconditional, as we will poll state again 2270 + * if userspace uses the notify to read data 2271 + */ 2526 2272 hotkey_radio_sw_notify_change(); 2527 2273 } 2528 2274 ··· 3354 3056 3355 3057 #define TPACPI_RFK_BLUETOOTH_SW_NAME "tpacpi_bluetooth_sw" 3356 3058 3357 - static struct rfkill *tpacpi_bluetooth_rfkill; 3358 - 3359 3059 static void bluetooth_suspend(pm_message_t state) 3360 3060 { 3361 3061 /* Try to make sure radio will resume powered off */ ··· 3363 3067 "bluetooth power down on resume request failed\n"); 3364 3068 } 3365 3069 3366 - static int bluetooth_get_radiosw(void) 3070 + static int bluetooth_get_status(void) 3367 3071 { 3368 3072 int status; 3369 - 3370 - if (!tp_features.bluetooth) 3371 - return -ENODEV; 3372 - 3373 - /* WLSW overrides bluetooth in firmware/hardware, reflect that */ 3374 - if (tp_features.hotkey_wlsw && !hotkey_get_wlsw(&status) && !status) 3375 - return RFKILL_STATE_HARD_BLOCKED; 3376 3073 3377 3074 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES 3378 3075 if (dbg_bluetoothemul) 3379 3076 return (tpacpi_bluetooth_emulstate) ? 3380 - RFKILL_STATE_UNBLOCKED : RFKILL_STATE_SOFT_BLOCKED; 3077 + TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; 3381 3078 #endif 3382 3079 3383 3080 if (!acpi_evalf(hkey_handle, &status, "GBDC", "d")) 3384 3081 return -EIO; 3385 3082 3386 3083 return ((status & TP_ACPI_BLUETOOTH_RADIOSSW) != 0) ? 3387 - RFKILL_STATE_UNBLOCKED : RFKILL_STATE_SOFT_BLOCKED; 3084 + TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; 3388 3085 } 3389 3086 3390 - static void bluetooth_update_rfk(void) 3087 + static int bluetooth_set_status(enum tpacpi_rfkill_state state) 3391 3088 { 3392 3089 int status; 3393 3090 3394 - if (!tpacpi_bluetooth_rfkill) 3395 - return; 3396 - 3397 - status = bluetooth_get_radiosw(); 3398 - if (status < 0) 3399 - return; 3400 - rfkill_force_state(tpacpi_bluetooth_rfkill, status); 3401 - 3402 3091 vdbg_printk(TPACPI_DBG_RFKILL, 3403 - "forced rfkill state to %d\n", 3404 - status); 3405 - } 3406 - 3407 - static int bluetooth_set_radiosw(int radio_on, int update_rfk) 3408 - { 3409 - int status; 3410 - 3411 - if (!tp_features.bluetooth) 3412 - return -ENODEV; 3413 - 3414 - /* WLSW overrides bluetooth in firmware/hardware, but there is no 3415 - * reason to risk weird behaviour. */ 3416 - if (tp_features.hotkey_wlsw && !hotkey_get_wlsw(&status) && !status 3417 - && radio_on) 3418 - return -EPERM; 3419 - 3420 - vdbg_printk(TPACPI_DBG_RFKILL, 3421 - "will %s bluetooth\n", radio_on ? "enable" : "disable"); 3092 + "will attempt to %s bluetooth\n", 3093 + (state == TPACPI_RFK_RADIO_ON) ? "enable" : "disable"); 3422 3094 3423 3095 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES 3424 3096 if (dbg_bluetoothemul) { 3425 - tpacpi_bluetooth_emulstate = !!radio_on; 3426 - if (update_rfk) 3427 - bluetooth_update_rfk(); 3097 + tpacpi_bluetooth_emulstate = (state == TPACPI_RFK_RADIO_ON); 3428 3098 return 0; 3429 3099 } 3430 3100 #endif 3431 3101 3432 3102 /* We make sure to keep TP_ACPI_BLUETOOTH_RESUMECTRL off */ 3433 - if (radio_on) 3103 + if (state == TPACPI_RFK_RADIO_ON) 3434 3104 status = TP_ACPI_BLUETOOTH_RADIOSSW; 3435 3105 else 3436 3106 status = 0; 3107 + 3437 3108 if (!acpi_evalf(hkey_handle, NULL, "SBDC", "vd", status)) 3438 3109 return -EIO; 3439 - 3440 - if (update_rfk) 3441 - bluetooth_update_rfk(); 3442 3110 3443 3111 return 0; 3444 3112 } ··· 3412 3152 struct device_attribute *attr, 3413 3153 char *buf) 3414 3154 { 3415 - int status; 3416 - 3417 - printk_deprecated_rfkill_attribute("bluetooth_enable"); 3418 - 3419 - status = bluetooth_get_radiosw(); 3420 - if (status < 0) 3421 - return status; 3422 - 3423 - return snprintf(buf, PAGE_SIZE, "%d\n", 3424 - (status == RFKILL_STATE_UNBLOCKED) ? 1 : 0); 3155 + return tpacpi_rfk_sysfs_enable_show(TPACPI_RFK_BLUETOOTH_SW_ID, 3156 + attr, buf); 3425 3157 } 3426 3158 3427 3159 static ssize_t bluetooth_enable_store(struct device *dev, 3428 3160 struct device_attribute *attr, 3429 3161 const char *buf, size_t count) 3430 3162 { 3431 - unsigned long t; 3432 - int res; 3433 - 3434 - printk_deprecated_rfkill_attribute("bluetooth_enable"); 3435 - 3436 - if (parse_strtoul(buf, 1, &t)) 3437 - return -EINVAL; 3438 - 3439 - tpacpi_disclose_usertask("bluetooth_enable", "set to %ld\n", t); 3440 - 3441 - res = bluetooth_set_radiosw(t, 1); 3442 - 3443 - return (res) ? res : count; 3163 + return tpacpi_rfk_sysfs_enable_store(TPACPI_RFK_BLUETOOTH_SW_ID, 3164 + attr, buf, count); 3444 3165 } 3445 3166 3446 3167 static struct device_attribute dev_attr_bluetooth_enable = ··· 3439 3198 .attrs = bluetooth_attributes, 3440 3199 }; 3441 3200 3442 - static int tpacpi_bluetooth_rfk_get(void *data, enum rfkill_state *state) 3443 - { 3444 - int bts = bluetooth_get_radiosw(); 3445 - 3446 - if (bts < 0) 3447 - return bts; 3448 - 3449 - *state = bts; 3450 - return 0; 3451 - } 3452 - 3453 - static int tpacpi_bluetooth_rfk_set(void *data, enum rfkill_state state) 3454 - { 3455 - dbg_printk(TPACPI_DBG_RFKILL, 3456 - "request to change radio state to %d\n", state); 3457 - return bluetooth_set_radiosw((state == RFKILL_STATE_UNBLOCKED), 0); 3458 - } 3201 + static const struct tpacpi_rfk_ops bluetooth_tprfk_ops = { 3202 + .get_status = bluetooth_get_status, 3203 + .set_status = bluetooth_set_status, 3204 + }; 3459 3205 3460 3206 static void bluetooth_shutdown(void) 3461 3207 { ··· 3458 3230 3459 3231 static void bluetooth_exit(void) 3460 3232 { 3461 - bluetooth_shutdown(); 3462 - 3463 - if (tpacpi_bluetooth_rfkill) 3464 - rfkill_unregister(tpacpi_bluetooth_rfkill); 3465 - 3466 3233 sysfs_remove_group(&tpacpi_pdev->dev.kobj, 3467 3234 &bluetooth_attr_group); 3235 + 3236 + tpacpi_destroy_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID); 3237 + 3238 + bluetooth_shutdown(); 3468 3239 } 3469 3240 3470 3241 static int __init bluetooth_init(struct ibm_init_struct *iibm) ··· 3504 3277 if (!tp_features.bluetooth) 3505 3278 return 1; 3506 3279 3507 - res = sysfs_create_group(&tpacpi_pdev->dev.kobj, 3508 - &bluetooth_attr_group); 3280 + res = tpacpi_new_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID, 3281 + &bluetooth_tprfk_ops, 3282 + RFKILL_TYPE_BLUETOOTH, 3283 + TPACPI_RFK_BLUETOOTH_SW_NAME, 3284 + true); 3509 3285 if (res) 3510 3286 return res; 3511 3287 3512 - res = tpacpi_new_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID, 3513 - &tpacpi_bluetooth_rfkill, 3514 - RFKILL_TYPE_BLUETOOTH, 3515 - TPACPI_RFK_BLUETOOTH_SW_NAME, 3516 - true, 3517 - tpacpi_bluetooth_rfk_set, 3518 - tpacpi_bluetooth_rfk_get); 3288 + res = sysfs_create_group(&tpacpi_pdev->dev.kobj, 3289 + &bluetooth_attr_group); 3519 3290 if (res) { 3520 - bluetooth_exit(); 3291 + tpacpi_destroy_rfkill(TPACPI_RFK_BLUETOOTH_SW_ID); 3521 3292 return res; 3522 3293 } 3523 3294 ··· 3525 3300 /* procfs -------------------------------------------------------------- */ 3526 3301 static int bluetooth_read(char *p) 3527 3302 { 3528 - int len = 0; 3529 - int status = bluetooth_get_radiosw(); 3530 - 3531 - if (!tp_features.bluetooth) 3532 - len += sprintf(p + len, "status:\t\tnot supported\n"); 3533 - else { 3534 - len += sprintf(p + len, "status:\t\t%s\n", 3535 - (status == RFKILL_STATE_UNBLOCKED) ? 3536 - "enabled" : "disabled"); 3537 - len += sprintf(p + len, "commands:\tenable, disable\n"); 3538 - } 3539 - 3540 - return len; 3303 + return tpacpi_rfk_procfs_read(TPACPI_RFK_BLUETOOTH_SW_ID, p); 3541 3304 } 3542 3305 3543 3306 static int bluetooth_write(char *buf) 3544 3307 { 3545 - char *cmd; 3546 - int state = -1; 3547 - 3548 - if (!tp_features.bluetooth) 3549 - return -ENODEV; 3550 - 3551 - while ((cmd = next_cmd(&buf))) { 3552 - if (strlencmp(cmd, "enable") == 0) { 3553 - state = 1; 3554 - } else if (strlencmp(cmd, "disable") == 0) { 3555 - state = 0; 3556 - } else 3557 - return -EINVAL; 3558 - } 3559 - 3560 - if (state != -1) { 3561 - tpacpi_disclose_usertask("procfs bluetooth", 3562 - "attempt to %s\n", 3563 - state ? "enable" : "disable"); 3564 - bluetooth_set_radiosw(state, 1); 3565 - } 3566 - 3567 - return 0; 3308 + return tpacpi_rfk_procfs_write(TPACPI_RFK_BLUETOOTH_SW_ID, buf); 3568 3309 } 3569 3310 3570 3311 static struct ibm_struct bluetooth_driver_data = { ··· 3556 3365 3557 3366 #define TPACPI_RFK_WWAN_SW_NAME "tpacpi_wwan_sw" 3558 3367 3559 - static struct rfkill *tpacpi_wan_rfkill; 3560 - 3561 3368 static void wan_suspend(pm_message_t state) 3562 3369 { 3563 3370 /* Try to make sure radio will resume powered off */ ··· 3565 3376 "WWAN power down on resume request failed\n"); 3566 3377 } 3567 3378 3568 - static int wan_get_radiosw(void) 3379 + static int wan_get_status(void) 3569 3380 { 3570 3381 int status; 3571 - 3572 - if (!tp_features.wan) 3573 - return -ENODEV; 3574 - 3575 - /* WLSW overrides WWAN in firmware/hardware, reflect that */ 3576 - if (tp_features.hotkey_wlsw && !hotkey_get_wlsw(&status) && !status) 3577 - return RFKILL_STATE_HARD_BLOCKED; 3578 3382 3579 3383 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES 3580 3384 if (dbg_wwanemul) 3581 3385 return (tpacpi_wwan_emulstate) ? 3582 - RFKILL_STATE_UNBLOCKED : RFKILL_STATE_SOFT_BLOCKED; 3386 + TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; 3583 3387 #endif 3584 3388 3585 3389 if (!acpi_evalf(hkey_handle, &status, "GWAN", "d")) 3586 3390 return -EIO; 3587 3391 3588 3392 return ((status & TP_ACPI_WANCARD_RADIOSSW) != 0) ? 3589 - RFKILL_STATE_UNBLOCKED : RFKILL_STATE_SOFT_BLOCKED; 3393 + TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; 3590 3394 } 3591 3395 3592 - static void wan_update_rfk(void) 3396 + static int wan_set_status(enum tpacpi_rfkill_state state) 3593 3397 { 3594 3398 int status; 3595 3399 3596 - if (!tpacpi_wan_rfkill) 3597 - return; 3598 - 3599 - status = wan_get_radiosw(); 3600 - if (status < 0) 3601 - return; 3602 - rfkill_force_state(tpacpi_wan_rfkill, status); 3603 - 3604 3400 vdbg_printk(TPACPI_DBG_RFKILL, 3605 - "forced rfkill state to %d\n", 3606 - status); 3607 - } 3608 - 3609 - static int wan_set_radiosw(int radio_on, int update_rfk) 3610 - { 3611 - int status; 3612 - 3613 - if (!tp_features.wan) 3614 - return -ENODEV; 3615 - 3616 - /* WLSW overrides bluetooth in firmware/hardware, but there is no 3617 - * reason to risk weird behaviour. */ 3618 - if (tp_features.hotkey_wlsw && !hotkey_get_wlsw(&status) && !status 3619 - && radio_on) 3620 - return -EPERM; 3621 - 3622 - vdbg_printk(TPACPI_DBG_RFKILL, 3623 - "will %s WWAN\n", radio_on ? "enable" : "disable"); 3401 + "will attempt to %s wwan\n", 3402 + (state == TPACPI_RFK_RADIO_ON) ? "enable" : "disable"); 3624 3403 3625 3404 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES 3626 3405 if (dbg_wwanemul) { 3627 - tpacpi_wwan_emulstate = !!radio_on; 3628 - if (update_rfk) 3629 - wan_update_rfk(); 3406 + tpacpi_wwan_emulstate = (state == TPACPI_RFK_RADIO_ON); 3630 3407 return 0; 3631 3408 } 3632 3409 #endif 3633 3410 3634 3411 /* We make sure to keep TP_ACPI_WANCARD_RESUMECTRL off */ 3635 - if (radio_on) 3412 + if (state == TPACPI_RFK_RADIO_ON) 3636 3413 status = TP_ACPI_WANCARD_RADIOSSW; 3637 3414 else 3638 3415 status = 0; 3416 + 3639 3417 if (!acpi_evalf(hkey_handle, NULL, "SWAN", "vd", status)) 3640 3418 return -EIO; 3641 - 3642 - if (update_rfk) 3643 - wan_update_rfk(); 3644 3419 3645 3420 return 0; 3646 3421 } ··· 3614 3461 struct device_attribute *attr, 3615 3462 char *buf) 3616 3463 { 3617 - int status; 3618 - 3619 - printk_deprecated_rfkill_attribute("wwan_enable"); 3620 - 3621 - status = wan_get_radiosw(); 3622 - if (status < 0) 3623 - return status; 3624 - 3625 - return snprintf(buf, PAGE_SIZE, "%d\n", 3626 - (status == RFKILL_STATE_UNBLOCKED) ? 1 : 0); 3464 + return tpacpi_rfk_sysfs_enable_show(TPACPI_RFK_WWAN_SW_ID, 3465 + attr, buf); 3627 3466 } 3628 3467 3629 3468 static ssize_t wan_enable_store(struct device *dev, 3630 3469 struct device_attribute *attr, 3631 3470 const char *buf, size_t count) 3632 3471 { 3633 - unsigned long t; 3634 - int res; 3635 - 3636 - printk_deprecated_rfkill_attribute("wwan_enable"); 3637 - 3638 - if (parse_strtoul(buf, 1, &t)) 3639 - return -EINVAL; 3640 - 3641 - tpacpi_disclose_usertask("wwan_enable", "set to %ld\n", t); 3642 - 3643 - res = wan_set_radiosw(t, 1); 3644 - 3645 - return (res) ? res : count; 3472 + return tpacpi_rfk_sysfs_enable_store(TPACPI_RFK_WWAN_SW_ID, 3473 + attr, buf, count); 3646 3474 } 3647 3475 3648 3476 static struct device_attribute dev_attr_wan_enable = ··· 3641 3507 .attrs = wan_attributes, 3642 3508 }; 3643 3509 3644 - static int tpacpi_wan_rfk_get(void *data, enum rfkill_state *state) 3645 - { 3646 - int wans = wan_get_radiosw(); 3647 - 3648 - if (wans < 0) 3649 - return wans; 3650 - 3651 - *state = wans; 3652 - return 0; 3653 - } 3654 - 3655 - static int tpacpi_wan_rfk_set(void *data, enum rfkill_state state) 3656 - { 3657 - dbg_printk(TPACPI_DBG_RFKILL, 3658 - "request to change radio state to %d\n", state); 3659 - return wan_set_radiosw((state == RFKILL_STATE_UNBLOCKED), 0); 3660 - } 3510 + static const struct tpacpi_rfk_ops wan_tprfk_ops = { 3511 + .get_status = wan_get_status, 3512 + .set_status = wan_set_status, 3513 + }; 3661 3514 3662 3515 static void wan_shutdown(void) 3663 3516 { ··· 3660 3539 3661 3540 static void wan_exit(void) 3662 3541 { 3663 - wan_shutdown(); 3664 - 3665 - if (tpacpi_wan_rfkill) 3666 - rfkill_unregister(tpacpi_wan_rfkill); 3667 - 3668 3542 sysfs_remove_group(&tpacpi_pdev->dev.kobj, 3669 3543 &wan_attr_group); 3544 + 3545 + tpacpi_destroy_rfkill(TPACPI_RFK_WWAN_SW_ID); 3546 + 3547 + wan_shutdown(); 3670 3548 } 3671 3549 3672 3550 static int __init wan_init(struct ibm_init_struct *iibm) ··· 3704 3584 if (!tp_features.wan) 3705 3585 return 1; 3706 3586 3707 - res = sysfs_create_group(&tpacpi_pdev->dev.kobj, 3708 - &wan_attr_group); 3587 + res = tpacpi_new_rfkill(TPACPI_RFK_WWAN_SW_ID, 3588 + &wan_tprfk_ops, 3589 + RFKILL_TYPE_WWAN, 3590 + TPACPI_RFK_WWAN_SW_NAME, 3591 + true); 3709 3592 if (res) 3710 3593 return res; 3711 3594 3712 - res = tpacpi_new_rfkill(TPACPI_RFK_WWAN_SW_ID, 3713 - &tpacpi_wan_rfkill, 3714 - RFKILL_TYPE_WWAN, 3715 - TPACPI_RFK_WWAN_SW_NAME, 3716 - true, 3717 - tpacpi_wan_rfk_set, 3718 - tpacpi_wan_rfk_get); 3595 + res = sysfs_create_group(&tpacpi_pdev->dev.kobj, 3596 + &wan_attr_group); 3597 + 3719 3598 if (res) { 3720 - wan_exit(); 3599 + tpacpi_destroy_rfkill(TPACPI_RFK_WWAN_SW_ID); 3721 3600 return res; 3722 3601 } 3723 3602 ··· 3726 3607 /* procfs -------------------------------------------------------------- */ 3727 3608 static int wan_read(char *p) 3728 3609 { 3729 - int len = 0; 3730 - int status = wan_get_radiosw(); 3731 - 3732 - tpacpi_disclose_usertask("procfs wan", "read"); 3733 - 3734 - if (!tp_features.wan) 3735 - len += sprintf(p + len, "status:\t\tnot supported\n"); 3736 - else { 3737 - len += sprintf(p + len, "status:\t\t%s\n", 3738 - (status == RFKILL_STATE_UNBLOCKED) ? 3739 - "enabled" : "disabled"); 3740 - len += sprintf(p + len, "commands:\tenable, disable\n"); 3741 - } 3742 - 3743 - return len; 3610 + return tpacpi_rfk_procfs_read(TPACPI_RFK_WWAN_SW_ID, p); 3744 3611 } 3745 3612 3746 3613 static int wan_write(char *buf) 3747 3614 { 3748 - char *cmd; 3749 - int state = -1; 3750 - 3751 - if (!tp_features.wan) 3752 - return -ENODEV; 3753 - 3754 - while ((cmd = next_cmd(&buf))) { 3755 - if (strlencmp(cmd, "enable") == 0) { 3756 - state = 1; 3757 - } else if (strlencmp(cmd, "disable") == 0) { 3758 - state = 0; 3759 - } else 3760 - return -EINVAL; 3761 - } 3762 - 3763 - if (state != -1) { 3764 - tpacpi_disclose_usertask("procfs wan", 3765 - "attempt to %s\n", 3766 - state ? "enable" : "disable"); 3767 - wan_set_radiosw(state, 1); 3768 - } 3769 - 3770 - return 0; 3615 + return tpacpi_rfk_procfs_write(TPACPI_RFK_WWAN_SW_ID, buf); 3771 3616 } 3772 3617 3773 3618 static struct ibm_struct wan_driver_data = { ··· 3755 3672 3756 3673 #define TPACPI_RFK_UWB_SW_NAME "tpacpi_uwb_sw" 3757 3674 3758 - static struct rfkill *tpacpi_uwb_rfkill; 3759 - 3760 - static int uwb_get_radiosw(void) 3675 + static int uwb_get_status(void) 3761 3676 { 3762 3677 int status; 3763 - 3764 - if (!tp_features.uwb) 3765 - return -ENODEV; 3766 - 3767 - /* WLSW overrides UWB in firmware/hardware, reflect that */ 3768 - if (tp_features.hotkey_wlsw && !hotkey_get_wlsw(&status) && !status) 3769 - return RFKILL_STATE_HARD_BLOCKED; 3770 3678 3771 3679 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES 3772 3680 if (dbg_uwbemul) 3773 3681 return (tpacpi_uwb_emulstate) ? 3774 - RFKILL_STATE_UNBLOCKED : RFKILL_STATE_SOFT_BLOCKED; 3682 + TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; 3775 3683 #endif 3776 3684 3777 3685 if (!acpi_evalf(hkey_handle, &status, "GUWB", "d")) 3778 3686 return -EIO; 3779 3687 3780 3688 return ((status & TP_ACPI_UWB_RADIOSSW) != 0) ? 3781 - RFKILL_STATE_UNBLOCKED : RFKILL_STATE_SOFT_BLOCKED; 3689 + TPACPI_RFK_RADIO_ON : TPACPI_RFK_RADIO_OFF; 3782 3690 } 3783 3691 3784 - static void uwb_update_rfk(void) 3692 + static int uwb_set_status(enum tpacpi_rfkill_state state) 3785 3693 { 3786 3694 int status; 3787 3695 3788 - if (!tpacpi_uwb_rfkill) 3789 - return; 3790 - 3791 - status = uwb_get_radiosw(); 3792 - if (status < 0) 3793 - return; 3794 - rfkill_force_state(tpacpi_uwb_rfkill, status); 3795 - 3796 3696 vdbg_printk(TPACPI_DBG_RFKILL, 3797 - "forced rfkill state to %d\n", 3798 - status); 3799 - } 3800 - 3801 - static int uwb_set_radiosw(int radio_on, int update_rfk) 3802 - { 3803 - int status; 3804 - 3805 - if (!tp_features.uwb) 3806 - return -ENODEV; 3807 - 3808 - /* WLSW overrides UWB in firmware/hardware, but there is no 3809 - * reason to risk weird behaviour. */ 3810 - if (tp_features.hotkey_wlsw && !hotkey_get_wlsw(&status) && !status 3811 - && radio_on) 3812 - return -EPERM; 3813 - 3814 - vdbg_printk(TPACPI_DBG_RFKILL, 3815 - "will %s UWB\n", radio_on ? "enable" : "disable"); 3697 + "will attempt to %s UWB\n", 3698 + (state == TPACPI_RFK_RADIO_ON) ? "enable" : "disable"); 3816 3699 3817 3700 #ifdef CONFIG_THINKPAD_ACPI_DEBUGFACILITIES 3818 3701 if (dbg_uwbemul) { 3819 - tpacpi_uwb_emulstate = !!radio_on; 3820 - if (update_rfk) 3821 - uwb_update_rfk(); 3702 + tpacpi_uwb_emulstate = (state == TPACPI_RFK_RADIO_ON); 3822 3703 return 0; 3823 3704 } 3824 3705 #endif 3825 3706 3826 - status = (radio_on) ? TP_ACPI_UWB_RADIOSSW : 0; 3707 + if (state == TPACPI_RFK_RADIO_ON) 3708 + status = TP_ACPI_UWB_RADIOSSW; 3709 + else 3710 + status = 0; 3711 + 3827 3712 if (!acpi_evalf(hkey_handle, NULL, "SUWB", "vd", status)) 3828 3713 return -EIO; 3829 - 3830 - if (update_rfk) 3831 - uwb_update_rfk(); 3832 3714 3833 3715 return 0; 3834 3716 } 3835 3717 3836 3718 /* --------------------------------------------------------------------- */ 3837 3719 3838 - static int tpacpi_uwb_rfk_get(void *data, enum rfkill_state *state) 3839 - { 3840 - int uwbs = uwb_get_radiosw(); 3841 - 3842 - if (uwbs < 0) 3843 - return uwbs; 3844 - 3845 - *state = uwbs; 3846 - return 0; 3847 - } 3848 - 3849 - static int tpacpi_uwb_rfk_set(void *data, enum rfkill_state state) 3850 - { 3851 - dbg_printk(TPACPI_DBG_RFKILL, 3852 - "request to change radio state to %d\n", state); 3853 - return uwb_set_radiosw((state == RFKILL_STATE_UNBLOCKED), 0); 3854 - } 3720 + static const struct tpacpi_rfk_ops uwb_tprfk_ops = { 3721 + .get_status = uwb_get_status, 3722 + .set_status = uwb_set_status, 3723 + }; 3855 3724 3856 3725 static void uwb_exit(void) 3857 3726 { 3858 - if (tpacpi_uwb_rfkill) 3859 - rfkill_unregister(tpacpi_uwb_rfkill); 3727 + tpacpi_destroy_rfkill(TPACPI_RFK_UWB_SW_ID); 3860 3728 } 3861 3729 3862 3730 static int __init uwb_init(struct ibm_init_struct *iibm) ··· 3847 3813 return 1; 3848 3814 3849 3815 res = tpacpi_new_rfkill(TPACPI_RFK_UWB_SW_ID, 3850 - &tpacpi_uwb_rfkill, 3816 + &uwb_tprfk_ops, 3851 3817 RFKILL_TYPE_UWB, 3852 3818 TPACPI_RFK_UWB_SW_NAME, 3853 - false, 3854 - tpacpi_uwb_rfk_set, 3855 - tpacpi_uwb_rfk_get); 3856 - 3819 + false); 3857 3820 return res; 3858 3821 } 3859 3822
+47 -116
drivers/platform/x86/toshiba_acpi.c
··· 45 45 #include <linux/backlight.h> 46 46 #include <linux/platform_device.h> 47 47 #include <linux/rfkill.h> 48 - #include <linux/input-polldev.h> 49 48 50 49 #include <asm/uaccess.h> 51 50 ··· 249 250 250 251 struct toshiba_acpi_dev { 251 252 struct platform_device *p_dev; 252 - struct rfkill *rfk_dev; 253 - struct input_polled_dev *poll_dev; 253 + struct rfkill *bt_rfk; 254 254 255 255 const char *bt_name; 256 - const char *rfk_name; 257 - 258 - bool last_rfk_state; 259 256 260 257 struct mutex mutex; 261 258 }; 262 259 263 260 static struct toshiba_acpi_dev toshiba_acpi = { 264 261 .bt_name = "Toshiba Bluetooth", 265 - .rfk_name = "Toshiba RFKill Switch", 266 - .last_rfk_state = false, 267 262 }; 268 263 269 264 /* Bluetooth rfkill handlers */ ··· 276 283 return hci_result; 277 284 } 278 285 279 - static u32 hci_get_bt_on(bool *on) 280 - { 281 - u32 hci_result; 282 - u32 value, value2; 283 - 284 - value = 0; 285 - value2 = 0x0001; 286 - hci_read2(HCI_WIRELESS, &value, &value2, &hci_result); 287 - if (hci_result == HCI_SUCCESS) 288 - *on = (value & HCI_WIRELESS_BT_POWER) && 289 - (value & HCI_WIRELESS_BT_ATTACH); 290 - 291 - return hci_result; 292 - } 293 - 294 286 static u32 hci_get_radio_state(bool *radio_state) 295 287 { 296 288 u32 hci_result; ··· 289 311 return hci_result; 290 312 } 291 313 292 - static int bt_rfkill_toggle_radio(void *data, enum rfkill_state state) 314 + static int bt_rfkill_set_block(void *data, bool blocked) 293 315 { 316 + struct toshiba_acpi_dev *dev = data; 294 317 u32 result1, result2; 295 318 u32 value; 319 + int err; 296 320 bool radio_state; 297 - struct toshiba_acpi_dev *dev = data; 298 321 299 - value = (state == RFKILL_STATE_UNBLOCKED); 300 - 301 - if (hci_get_radio_state(&radio_state) != HCI_SUCCESS) 302 - return -EFAULT; 303 - 304 - switch (state) { 305 - case RFKILL_STATE_UNBLOCKED: 306 - if (!radio_state) 307 - return -EPERM; 308 - break; 309 - case RFKILL_STATE_SOFT_BLOCKED: 310 - break; 311 - default: 312 - return -EINVAL; 313 - } 322 + value = (blocked == false); 314 323 315 324 mutex_lock(&dev->mutex); 325 + if (hci_get_radio_state(&radio_state) != HCI_SUCCESS) { 326 + err = -EBUSY; 327 + goto out; 328 + } 329 + 330 + if (!radio_state) { 331 + err = 0; 332 + goto out; 333 + } 334 + 316 335 hci_write2(HCI_WIRELESS, value, HCI_WIRELESS_BT_POWER, &result1); 317 336 hci_write2(HCI_WIRELESS, value, HCI_WIRELESS_BT_ATTACH, &result2); 318 - mutex_unlock(&dev->mutex); 319 337 320 338 if (result1 != HCI_SUCCESS || result2 != HCI_SUCCESS) 321 - return -EFAULT; 322 - 323 - return 0; 339 + err = -EBUSY; 340 + else 341 + err = 0; 342 + out: 343 + mutex_unlock(&dev->mutex); 344 + return err; 324 345 } 325 346 326 - static void bt_poll_rfkill(struct input_polled_dev *poll_dev) 347 + static void bt_rfkill_poll(struct rfkill *rfkill, void *data) 327 348 { 328 - bool state_changed; 329 349 bool new_rfk_state; 330 350 bool value; 331 351 u32 hci_result; 332 - struct toshiba_acpi_dev *dev = poll_dev->private; 352 + struct toshiba_acpi_dev *dev = data; 353 + 354 + mutex_lock(&dev->mutex); 333 355 334 356 hci_result = hci_get_radio_state(&value); 335 - if (hci_result != HCI_SUCCESS) 336 - return; /* Can't do anything useful */ 357 + if (hci_result != HCI_SUCCESS) { 358 + /* Can't do anything useful */ 359 + mutex_unlock(&dev->mutex); 360 + } 337 361 338 362 new_rfk_state = value; 339 363 340 - mutex_lock(&dev->mutex); 341 - state_changed = new_rfk_state != dev->last_rfk_state; 342 - dev->last_rfk_state = new_rfk_state; 343 364 mutex_unlock(&dev->mutex); 344 365 345 - if (unlikely(state_changed)) { 346 - rfkill_force_state(dev->rfk_dev, 347 - new_rfk_state ? 348 - RFKILL_STATE_SOFT_BLOCKED : 349 - RFKILL_STATE_HARD_BLOCKED); 350 - input_report_switch(poll_dev->input, SW_RFKILL_ALL, 351 - new_rfk_state); 352 - input_sync(poll_dev->input); 353 - } 366 + if (rfkill_set_hw_state(rfkill, !new_rfk_state)) 367 + bt_rfkill_set_block(data, true); 354 368 } 369 + 370 + static const struct rfkill_ops toshiba_rfk_ops = { 371 + .set_block = bt_rfkill_set_block, 372 + .poll = bt_rfkill_poll, 373 + }; 355 374 356 375 static struct proc_dir_entry *toshiba_proc_dir /*= 0*/ ; 357 376 static struct backlight_device *toshiba_backlight_device; ··· 677 702 678 703 static void toshiba_acpi_exit(void) 679 704 { 680 - if (toshiba_acpi.poll_dev) { 681 - input_unregister_polled_device(toshiba_acpi.poll_dev); 682 - input_free_polled_device(toshiba_acpi.poll_dev); 705 + if (toshiba_acpi.bt_rfk) { 706 + rfkill_unregister(toshiba_acpi.bt_rfk); 707 + rfkill_destroy(toshiba_acpi.bt_rfk); 683 708 } 684 - 685 - if (toshiba_acpi.rfk_dev) 686 - rfkill_unregister(toshiba_acpi.rfk_dev); 687 709 688 710 if (toshiba_backlight_device) 689 711 backlight_device_unregister(toshiba_backlight_device); ··· 700 728 acpi_status status = AE_OK; 701 729 u32 hci_result; 702 730 bool bt_present; 703 - bool bt_on; 704 - bool radio_on; 705 731 int ret = 0; 706 732 707 733 if (acpi_disabled) ··· 763 793 764 794 /* Register rfkill switch for Bluetooth */ 765 795 if (hci_get_bt_present(&bt_present) == HCI_SUCCESS && bt_present) { 766 - toshiba_acpi.rfk_dev = rfkill_allocate(&toshiba_acpi.p_dev->dev, 767 - RFKILL_TYPE_BLUETOOTH); 768 - if (!toshiba_acpi.rfk_dev) { 796 + toshiba_acpi.bt_rfk = rfkill_alloc(toshiba_acpi.bt_name, 797 + &toshiba_acpi.p_dev->dev, 798 + RFKILL_TYPE_BLUETOOTH, 799 + &toshiba_rfk_ops, 800 + &toshiba_acpi); 801 + if (!toshiba_acpi.bt_rfk) { 769 802 printk(MY_ERR "unable to allocate rfkill device\n"); 770 803 toshiba_acpi_exit(); 771 804 return -ENOMEM; 772 805 } 773 806 774 - toshiba_acpi.rfk_dev->name = toshiba_acpi.bt_name; 775 - toshiba_acpi.rfk_dev->toggle_radio = bt_rfkill_toggle_radio; 776 - toshiba_acpi.rfk_dev->data = &toshiba_acpi; 777 - 778 - if (hci_get_bt_on(&bt_on) == HCI_SUCCESS && bt_on) { 779 - toshiba_acpi.rfk_dev->state = RFKILL_STATE_UNBLOCKED; 780 - } else if (hci_get_radio_state(&radio_on) == HCI_SUCCESS && 781 - radio_on) { 782 - toshiba_acpi.rfk_dev->state = RFKILL_STATE_SOFT_BLOCKED; 783 - } else { 784 - toshiba_acpi.rfk_dev->state = RFKILL_STATE_HARD_BLOCKED; 785 - } 786 - 787 - ret = rfkill_register(toshiba_acpi.rfk_dev); 807 + ret = rfkill_register(toshiba_acpi.bt_rfk); 788 808 if (ret) { 789 809 printk(MY_ERR "unable to register rfkill device\n"); 790 - toshiba_acpi_exit(); 791 - return -ENOMEM; 792 - } 793 - 794 - /* Register input device for kill switch */ 795 - toshiba_acpi.poll_dev = input_allocate_polled_device(); 796 - if (!toshiba_acpi.poll_dev) { 797 - printk(MY_ERR 798 - "unable to allocate kill-switch input device\n"); 799 - toshiba_acpi_exit(); 800 - return -ENOMEM; 801 - } 802 - toshiba_acpi.poll_dev->private = &toshiba_acpi; 803 - toshiba_acpi.poll_dev->poll = bt_poll_rfkill; 804 - toshiba_acpi.poll_dev->poll_interval = 1000; /* msecs */ 805 - 806 - toshiba_acpi.poll_dev->input->name = toshiba_acpi.rfk_name; 807 - toshiba_acpi.poll_dev->input->id.bustype = BUS_HOST; 808 - /* Toshiba USB ID */ 809 - toshiba_acpi.poll_dev->input->id.vendor = 0x0930; 810 - set_bit(EV_SW, toshiba_acpi.poll_dev->input->evbit); 811 - set_bit(SW_RFKILL_ALL, toshiba_acpi.poll_dev->input->swbit); 812 - input_report_switch(toshiba_acpi.poll_dev->input, 813 - SW_RFKILL_ALL, TRUE); 814 - input_sync(toshiba_acpi.poll_dev->input); 815 - 816 - ret = input_register_polled_device(toshiba_acpi.poll_dev); 817 - if (ret) { 818 - printk(MY_ERR 819 - "unable to register kill-switch input device\n"); 810 + rfkill_destroy(toshiba_acpi.bt_rfk); 820 811 toshiba_acpi_exit(); 821 812 return ret; 822 813 }
+2
include/asm-generic/errno.h
··· 106 106 #define EOWNERDEAD 130 /* Owner died */ 107 107 #define ENOTRECOVERABLE 131 /* State not recoverable */ 108 108 109 + #define ERFKILL 132 /* Operation not possible due to RF-kill */ 110 + 109 111 #endif
+1
include/linux/Kbuild
··· 311 311 unifdef-y += qnx4_fs.h 312 312 unifdef-y += quota.h 313 313 unifdef-y += random.h 314 + unifdef-y += rfkill.h 314 315 unifdef-y += irqnr.h 315 316 unifdef-y += reboot.h 316 317 unifdef-y += reiserfs_fs.h
+1
include/linux/ieee80211.h
··· 1092 1092 WLAN_KEY_LEN_WEP104 = 13, 1093 1093 WLAN_KEY_LEN_CCMP = 16, 1094 1094 WLAN_KEY_LEN_TKIP = 32, 1095 + WLAN_KEY_LEN_AES_CMAC = 16, 1095 1096 }; 1096 1097 1097 1098 /*
+1
include/linux/notifier.h
··· 198 198 #define NETDEV_CHANGENAME 0x000A 199 199 #define NETDEV_FEAT_CHANGE 0x000B 200 200 #define NETDEV_BONDING_FAILOVER 0x000C 201 + #define NETDEV_PRE_UP 0x000D 201 202 202 203 #define SYS_DOWN 0x0001 /* Notify of system down */ 203 204 #define SYS_RESTART SYS_DOWN
+314 -89
include/linux/rfkill.h
··· 4 4 /* 5 5 * Copyright (C) 2006 - 2007 Ivo van Doorn 6 6 * Copyright (C) 2007 Dmitry Torokhov 7 + * Copyright 2009 Johannes Berg <johannes@sipsolutions.net> 7 8 * 8 9 * This program is free software; you can redistribute it and/or modify 9 10 * it under the terms of the GNU General Public License as published by ··· 23 22 */ 24 23 25 24 #include <linux/types.h> 25 + 26 + /* define userspace visible states */ 27 + #define RFKILL_STATE_SOFT_BLOCKED 0 28 + #define RFKILL_STATE_UNBLOCKED 1 29 + #define RFKILL_STATE_HARD_BLOCKED 2 30 + 31 + /** 32 + * enum rfkill_type - type of rfkill switch. 33 + * 34 + * @RFKILL_TYPE_ALL: toggles all switches (userspace only) 35 + * @RFKILL_TYPE_WLAN: switch is on a 802.11 wireless network device. 36 + * @RFKILL_TYPE_BLUETOOTH: switch is on a bluetooth device. 37 + * @RFKILL_TYPE_UWB: switch is on a ultra wideband device. 38 + * @RFKILL_TYPE_WIMAX: switch is on a WiMAX device. 39 + * @RFKILL_TYPE_WWAN: switch is on a wireless WAN device. 40 + * @NUM_RFKILL_TYPES: number of defined rfkill types 41 + */ 42 + enum rfkill_type { 43 + RFKILL_TYPE_ALL = 0, 44 + RFKILL_TYPE_WLAN, 45 + RFKILL_TYPE_BLUETOOTH, 46 + RFKILL_TYPE_UWB, 47 + RFKILL_TYPE_WIMAX, 48 + RFKILL_TYPE_WWAN, 49 + NUM_RFKILL_TYPES, 50 + }; 51 + 52 + /** 53 + * enum rfkill_operation - operation types 54 + * @RFKILL_OP_ADD: a device was added 55 + * @RFKILL_OP_DEL: a device was removed 56 + * @RFKILL_OP_CHANGE: a device's state changed -- userspace changes one device 57 + * @RFKILL_OP_CHANGE_ALL: userspace changes all devices (of a type, or all) 58 + */ 59 + enum rfkill_operation { 60 + RFKILL_OP_ADD = 0, 61 + RFKILL_OP_DEL, 62 + RFKILL_OP_CHANGE, 63 + RFKILL_OP_CHANGE_ALL, 64 + }; 65 + 66 + /** 67 + * struct rfkill_event - events for userspace on /dev/rfkill 68 + * @idx: index of dev rfkill 69 + * @type: type of the rfkill struct 70 + * @op: operation code 71 + * @hard: hard state (0/1) 72 + * @soft: soft state (0/1) 73 + * 74 + * Structure used for userspace communication on /dev/rfkill, 75 + * used for events from the kernel and control to the kernel. 76 + */ 77 + struct rfkill_event { 78 + __u32 idx; 79 + __u8 type; 80 + __u8 op; 81 + __u8 soft, hard; 82 + } __packed; 83 + 84 + /* ioctl for turning off rfkill-input (if present) */ 85 + #define RFKILL_IOC_MAGIC 'R' 86 + #define RFKILL_IOC_NOINPUT 1 87 + #define RFKILL_IOCTL_NOINPUT _IO(RFKILL_IOC_MAGIC, RFKILL_IOC_NOINPUT) 88 + 89 + /* and that's all userspace gets */ 90 + #ifdef __KERNEL__ 91 + /* don't allow anyone to use these in the kernel */ 92 + enum rfkill_user_states { 93 + RFKILL_USER_STATE_SOFT_BLOCKED = RFKILL_STATE_SOFT_BLOCKED, 94 + RFKILL_USER_STATE_UNBLOCKED = RFKILL_STATE_UNBLOCKED, 95 + RFKILL_USER_STATE_HARD_BLOCKED = RFKILL_STATE_HARD_BLOCKED, 96 + }; 97 + #undef RFKILL_STATE_SOFT_BLOCKED 98 + #undef RFKILL_STATE_UNBLOCKED 99 + #undef RFKILL_STATE_HARD_BLOCKED 100 + 101 + #include <linux/types.h> 26 102 #include <linux/kernel.h> 27 103 #include <linux/list.h> 28 104 #include <linux/mutex.h> 29 105 #include <linux/device.h> 30 106 #include <linux/leds.h> 31 107 32 - /** 33 - * enum rfkill_type - type of rfkill switch. 34 - * RFKILL_TYPE_WLAN: switch is on a 802.11 wireless network device. 35 - * RFKILL_TYPE_BLUETOOTH: switch is on a bluetooth device. 36 - * RFKILL_TYPE_UWB: switch is on a ultra wideband device. 37 - * RFKILL_TYPE_WIMAX: switch is on a WiMAX device. 38 - * RFKILL_TYPE_WWAN: switch is on a wireless WAN device. 39 - */ 40 - enum rfkill_type { 41 - RFKILL_TYPE_WLAN , 42 - RFKILL_TYPE_BLUETOOTH, 43 - RFKILL_TYPE_UWB, 44 - RFKILL_TYPE_WIMAX, 45 - RFKILL_TYPE_WWAN, 46 - RFKILL_TYPE_MAX, 47 - }; 48 - 49 - enum rfkill_state { 50 - RFKILL_STATE_SOFT_BLOCKED = 0, /* Radio output blocked */ 51 - RFKILL_STATE_UNBLOCKED = 1, /* Radio output allowed */ 52 - RFKILL_STATE_HARD_BLOCKED = 2, /* Output blocked, non-overrideable */ 53 - RFKILL_STATE_MAX, /* marker for last valid state */ 54 - }; 108 + /* this is opaque */ 109 + struct rfkill; 55 110 56 111 /** 57 - * struct rfkill - rfkill control structure. 58 - * @name: Name of the switch. 59 - * @type: Radio type which the button controls, the value stored 60 - * here should be a value from enum rfkill_type. 61 - * @state: State of the switch, "UNBLOCKED" means radio can operate. 62 - * @mutex: Guards switch state transitions. It serializes callbacks 63 - * and also protects the state. 64 - * @data: Pointer to the RF button drivers private data which will be 65 - * passed along when toggling radio state. 66 - * @toggle_radio(): Mandatory handler to control state of the radio. 67 - * only RFKILL_STATE_SOFT_BLOCKED and RFKILL_STATE_UNBLOCKED are 68 - * valid parameters. 69 - * @get_state(): handler to read current radio state from hardware, 70 - * may be called from atomic context, should return 0 on success. 71 - * Either this handler OR judicious use of rfkill_force_state() is 72 - * MANDATORY for any driver capable of RFKILL_STATE_HARD_BLOCKED. 73 - * @led_trigger: A LED trigger for this button's LED. 74 - * @dev: Device structure integrating the switch into device tree. 75 - * @node: Used to place switch into list of all switches known to the 76 - * the system. 112 + * struct rfkill_ops - rfkill driver methods 77 113 * 78 - * This structure represents a RF switch located on a network device. 114 + * @poll: poll the rfkill block state(s) -- only assign this method 115 + * when you need polling. When called, simply call one of the 116 + * rfkill_set{,_hw,_sw}_state family of functions. If the hw 117 + * is getting unblocked you need to take into account the return 118 + * value of those functions to make sure the software block is 119 + * properly used. 120 + * @query: query the rfkill block state(s) and call exactly one of the 121 + * rfkill_set{,_hw,_sw}_state family of functions. Assign this 122 + * method if input events can cause hardware state changes to make 123 + * the rfkill core query your driver before setting a requested 124 + * block. 125 + * @set_block: turn the transmitter on (blocked == false) or off 126 + * (blocked == true) -- ignore and return 0 when hard blocked. 127 + * This callback must be assigned. 79 128 */ 80 - struct rfkill { 81 - const char *name; 82 - enum rfkill_type type; 83 - 84 - /* the mutex serializes callbacks and also protects 85 - * the state */ 86 - struct mutex mutex; 87 - enum rfkill_state state; 88 - void *data; 89 - int (*toggle_radio)(void *data, enum rfkill_state state); 90 - int (*get_state)(void *data, enum rfkill_state *state); 91 - 92 - #ifdef CONFIG_RFKILL_LEDS 93 - struct led_trigger led_trigger; 94 - #endif 95 - 96 - struct device dev; 97 - struct list_head node; 98 - enum rfkill_state state_for_resume; 129 + struct rfkill_ops { 130 + void (*poll)(struct rfkill *rfkill, void *data); 131 + void (*query)(struct rfkill *rfkill, void *data); 132 + int (*set_block)(void *data, bool blocked); 99 133 }; 100 - #define to_rfkill(d) container_of(d, struct rfkill, dev) 101 134 102 - struct rfkill * __must_check rfkill_allocate(struct device *parent, 103 - enum rfkill_type type); 104 - void rfkill_free(struct rfkill *rfkill); 135 + #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE) 136 + /** 137 + * rfkill_alloc - allocate rfkill structure 138 + * @name: name of the struct -- the string is not copied internally 139 + * @parent: device that has rf switch on it 140 + * @type: type of the switch (RFKILL_TYPE_*) 141 + * @ops: rfkill methods 142 + * @ops_data: data passed to each method 143 + * 144 + * This function should be called by the transmitter driver to allocate an 145 + * rfkill structure. Returns %NULL on failure. 146 + */ 147 + struct rfkill * __must_check rfkill_alloc(const char *name, 148 + struct device *parent, 149 + const enum rfkill_type type, 150 + const struct rfkill_ops *ops, 151 + void *ops_data); 152 + 153 + /** 154 + * rfkill_register - Register a rfkill structure. 155 + * @rfkill: rfkill structure to be registered 156 + * 157 + * This function should be called by the transmitter driver to register 158 + * the rfkill structure needs to be registered. Before calling this function 159 + * the driver needs to be ready to service method calls from rfkill. 160 + */ 105 161 int __must_check rfkill_register(struct rfkill *rfkill); 162 + 163 + /** 164 + * rfkill_pause_polling(struct rfkill *rfkill) 165 + * 166 + * Pause polling -- say transmitter is off for other reasons. 167 + * NOTE: not necessary for suspend/resume -- in that case the 168 + * core stops polling anyway 169 + */ 170 + void rfkill_pause_polling(struct rfkill *rfkill); 171 + 172 + /** 173 + * rfkill_resume_polling(struct rfkill *rfkill) 174 + * 175 + * Pause polling -- say transmitter is off for other reasons. 176 + * NOTE: not necessary for suspend/resume -- in that case the 177 + * core stops polling anyway 178 + */ 179 + void rfkill_resume_polling(struct rfkill *rfkill); 180 + 181 + 182 + /** 183 + * rfkill_unregister - Unregister a rfkill structure. 184 + * @rfkill: rfkill structure to be unregistered 185 + * 186 + * This function should be called by the network driver during device 187 + * teardown to destroy rfkill structure. Until it returns, the driver 188 + * needs to be able to service method calls. 189 + */ 106 190 void rfkill_unregister(struct rfkill *rfkill); 107 191 108 - int rfkill_force_state(struct rfkill *rfkill, enum rfkill_state state); 109 - int rfkill_set_default(enum rfkill_type type, enum rfkill_state state); 110 - 111 192 /** 112 - * rfkill_state_complement - return complementar state 113 - * @state: state to return the complement of 193 + * rfkill_destroy - free rfkill structure 194 + * @rfkill: rfkill structure to be destroyed 114 195 * 115 - * Returns RFKILL_STATE_SOFT_BLOCKED if @state is RFKILL_STATE_UNBLOCKED, 116 - * returns RFKILL_STATE_UNBLOCKED otherwise. 196 + * Destroys the rfkill structure. 117 197 */ 118 - static inline enum rfkill_state rfkill_state_complement(enum rfkill_state state) 119 - { 120 - return (state == RFKILL_STATE_UNBLOCKED) ? 121 - RFKILL_STATE_SOFT_BLOCKED : RFKILL_STATE_UNBLOCKED; 122 - } 198 + void rfkill_destroy(struct rfkill *rfkill); 123 199 124 200 /** 125 - * rfkill_get_led_name - Get the LED trigger name for the button's LED. 126 - * This function might return a NULL pointer if registering of the 127 - * LED trigger failed. 128 - * Use this as "default_trigger" for the LED. 201 + * rfkill_set_hw_state - Set the internal rfkill hardware block state 202 + * @rfkill: pointer to the rfkill class to modify. 203 + * @state: the current hardware block state to set 204 + * 205 + * rfkill drivers that get events when the hard-blocked state changes 206 + * use this function to notify the rfkill core (and through that also 207 + * userspace) of the current state -- they should also use this after 208 + * resume if the state could have changed. 209 + * 210 + * You need not (but may) call this function if poll_state is assigned. 211 + * 212 + * This function can be called in any context, even from within rfkill 213 + * callbacks. 214 + * 215 + * The function returns the combined block state (true if transmitter 216 + * should be blocked) so that drivers need not keep track of the soft 217 + * block state -- which they might not be able to. 129 218 */ 130 - static inline char *rfkill_get_led_name(struct rfkill *rfkill) 219 + bool __must_check rfkill_set_hw_state(struct rfkill *rfkill, bool blocked); 220 + 221 + /** 222 + * rfkill_set_sw_state - Set the internal rfkill software block state 223 + * @rfkill: pointer to the rfkill class to modify. 224 + * @state: the current software block state to set 225 + * 226 + * rfkill drivers that get events when the soft-blocked state changes 227 + * (yes, some platforms directly act on input but allow changing again) 228 + * use this function to notify the rfkill core (and through that also 229 + * userspace) of the current state -- they should also use this after 230 + * resume if the state could have changed. 231 + * 232 + * This function can be called in any context, even from within rfkill 233 + * callbacks. 234 + * 235 + * The function returns the combined block state (true if transmitter 236 + * should be blocked). 237 + */ 238 + bool rfkill_set_sw_state(struct rfkill *rfkill, bool blocked); 239 + 240 + /** 241 + * rfkill_set_states - Set the internal rfkill block states 242 + * @rfkill: pointer to the rfkill class to modify. 243 + * @sw: the current software block state to set 244 + * @hw: the current hardware block state to set 245 + * 246 + * This function can be called in any context, even from within rfkill 247 + * callbacks. 248 + */ 249 + void rfkill_set_states(struct rfkill *rfkill, bool sw, bool hw); 250 + 251 + /** 252 + * rfkill_set_global_sw_state - set global sw block default 253 + * @type: rfkill type to set default for 254 + * @blocked: default to set 255 + * 256 + * This function sets the global default -- use at boot if your platform has 257 + * an rfkill switch. If not early enough this call may be ignored. 258 + * 259 + * XXX: instead of ignoring -- how about just updating all currently 260 + * registered drivers? 261 + */ 262 + void rfkill_set_global_sw_state(const enum rfkill_type type, bool blocked); 263 + 264 + /** 265 + * rfkill_blocked - query rfkill block 266 + * 267 + * @rfkill: rfkill struct to query 268 + */ 269 + bool rfkill_blocked(struct rfkill *rfkill); 270 + #else /* !RFKILL */ 271 + static inline struct rfkill * __must_check 272 + rfkill_alloc(const char *name, 273 + struct device *parent, 274 + const enum rfkill_type type, 275 + const struct rfkill_ops *ops, 276 + void *ops_data) 131 277 { 132 - #ifdef CONFIG_RFKILL_LEDS 133 - return (char *)(rfkill->led_trigger.name); 134 - #else 135 - return NULL; 136 - #endif 278 + return ERR_PTR(-ENODEV); 137 279 } 280 + 281 + static inline int __must_check rfkill_register(struct rfkill *rfkill) 282 + { 283 + if (rfkill == ERR_PTR(-ENODEV)) 284 + return 0; 285 + return -EINVAL; 286 + } 287 + 288 + static inline void rfkill_pause_polling(struct rfkill *rfkill) 289 + { 290 + } 291 + 292 + static inline void rfkill_resume_polling(struct rfkill *rfkill) 293 + { 294 + } 295 + 296 + static inline void rfkill_unregister(struct rfkill *rfkill) 297 + { 298 + } 299 + 300 + static inline void rfkill_destroy(struct rfkill *rfkill) 301 + { 302 + } 303 + 304 + static inline bool rfkill_set_hw_state(struct rfkill *rfkill, bool blocked) 305 + { 306 + return blocked; 307 + } 308 + 309 + static inline bool rfkill_set_sw_state(struct rfkill *rfkill, bool blocked) 310 + { 311 + return blocked; 312 + } 313 + 314 + static inline void rfkill_set_states(struct rfkill *rfkill, bool sw, bool hw) 315 + { 316 + } 317 + 318 + static inline void rfkill_set_global_sw_state(const enum rfkill_type type, 319 + bool blocked) 320 + { 321 + } 322 + 323 + static inline bool rfkill_blocked(struct rfkill *rfkill) 324 + { 325 + return false; 326 + } 327 + #endif /* RFKILL || RFKILL_MODULE */ 328 + 329 + 330 + #ifdef CONFIG_RFKILL_LEDS 331 + /** 332 + * rfkill_get_led_trigger_name - Get the LED trigger name for the button's LED. 333 + * This function might return a NULL pointer if registering of the 334 + * LED trigger failed. Use this as "default_trigger" for the LED. 335 + */ 336 + const char *rfkill_get_led_trigger_name(struct rfkill *rfkill); 337 + 338 + /** 339 + * rfkill_set_led_trigger_name -- set the LED trigger name 340 + * @rfkill: rfkill struct 341 + * @name: LED trigger name 342 + * 343 + * This function sets the LED trigger name of the radio LED 344 + * trigger that rfkill creates. It is optional, but if called 345 + * must be called before rfkill_register() to be effective. 346 + */ 347 + void rfkill_set_led_trigger_name(struct rfkill *rfkill, const char *name); 348 + #else 349 + static inline const char *rfkill_get_led_trigger_name(struct rfkill *rfkill) 350 + { 351 + return NULL; 352 + } 353 + 354 + static inline void 355 + rfkill_set_led_trigger_name(struct rfkill *rfkill, const char *name) 356 + { 357 + } 358 + #endif 359 + 360 + #endif /* __KERNEL__ */ 138 361 139 362 #endif /* RFKILL_H */
+51
include/net/cfg80211.h
··· 752 752 }; 753 753 754 754 /** 755 + * enum tx_power_setting - TX power adjustment 756 + * 757 + * @TX_POWER_AUTOMATIC: the dbm parameter is ignored 758 + * @TX_POWER_LIMITED: limit TX power by the dbm parameter 759 + * @TX_POWER_FIXED: fix TX power to the dbm parameter 760 + */ 761 + enum tx_power_setting { 762 + TX_POWER_AUTOMATIC, 763 + TX_POWER_LIMITED, 764 + TX_POWER_FIXED, 765 + }; 766 + 767 + /** 755 768 * struct cfg80211_ops - backend description for wireless configuration 756 769 * 757 770 * This struct is registered by fullmac card drivers and/or wireless stacks ··· 850 837 * @changed bitfield (see &enum wiphy_params_flags) describes which values 851 838 * have changed. The actual parameter values are available in 852 839 * struct wiphy. If returning an error, no value should be changed. 840 + * 841 + * @set_tx_power: set the transmit power according to the parameters 842 + * @get_tx_power: store the current TX power into the dbm variable; 843 + * return 0 if successful 844 + * 845 + * @rfkill_poll: polls the hw rfkill line, use cfg80211 reporting 846 + * functions to adjust rfkill hw state 853 847 */ 854 848 struct cfg80211_ops { 855 849 int (*suspend)(struct wiphy *wiphy); ··· 948 928 int (*leave_ibss)(struct wiphy *wiphy, struct net_device *dev); 949 929 950 930 int (*set_wiphy_params)(struct wiphy *wiphy, u32 changed); 931 + 932 + int (*set_tx_power)(struct wiphy *wiphy, 933 + enum tx_power_setting type, int dbm); 934 + int (*get_tx_power)(struct wiphy *wiphy, int *dbm); 935 + 936 + void (*rfkill_poll)(struct wiphy *wiphy); 951 937 }; 952 938 953 939 /* ··· 1477 1451 int cfg80211_wext_giwencode(struct net_device *dev, 1478 1452 struct iw_request_info *info, 1479 1453 struct iw_point *erq, char *keybuf); 1454 + int cfg80211_wext_siwtxpower(struct net_device *dev, 1455 + struct iw_request_info *info, 1456 + union iwreq_data *data, char *keybuf); 1457 + int cfg80211_wext_giwtxpower(struct net_device *dev, 1458 + struct iw_request_info *info, 1459 + union iwreq_data *data, char *keybuf); 1480 1460 1481 1461 /* 1482 1462 * callbacks for asynchronous cfg80211 methods, notification ··· 1667 1635 * always a scan result for this IBSS. cfg80211 will handle the rest. 1668 1636 */ 1669 1637 void cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid, gfp_t gfp); 1638 + 1639 + /** 1640 + * wiphy_rfkill_set_hw_state - notify cfg80211 about hw block state 1641 + * @wiphy: the wiphy 1642 + * @blocked: block status 1643 + */ 1644 + void wiphy_rfkill_set_hw_state(struct wiphy *wiphy, bool blocked); 1645 + 1646 + /** 1647 + * wiphy_rfkill_start_polling - start polling rfkill 1648 + * @wiphy: the wiphy 1649 + */ 1650 + void wiphy_rfkill_start_polling(struct wiphy *wiphy); 1651 + 1652 + /** 1653 + * wiphy_rfkill_stop_polling - stop polling rfkill 1654 + * @wiphy: the wiphy 1655 + */ 1656 + void wiphy_rfkill_stop_polling(struct wiphy *wiphy); 1670 1657 1671 1658 #endif /* __NET_CFG80211_H */
+15 -11
include/net/mac80211.h
··· 526 526 /** 527 527 * enum ieee80211_conf_changed - denotes which configuration changed 528 528 * 529 - * @IEEE80211_CONF_CHANGE_RADIO_ENABLED: the value of radio_enabled changed 530 - * @_IEEE80211_CONF_CHANGE_BEACON_INTERVAL: DEPRECATED 529 + * @_IEEE80211_CONF_CHANGE_RADIO_ENABLED: DEPRECATED 531 530 * @IEEE80211_CONF_CHANGE_LISTEN_INTERVAL: the listen interval changed 532 531 * @IEEE80211_CONF_CHANGE_RADIOTAP: the radiotap flag changed 533 532 * @IEEE80211_CONF_CHANGE_PS: the PS flag or dynamic PS timeout changed ··· 536 537 * @IEEE80211_CONF_CHANGE_IDLE: Idle flag changed 537 538 */ 538 539 enum ieee80211_conf_changed { 539 - IEEE80211_CONF_CHANGE_RADIO_ENABLED = BIT(0), 540 - _IEEE80211_CONF_CHANGE_BEACON_INTERVAL = BIT(1), 540 + _IEEE80211_CONF_CHANGE_RADIO_ENABLED = BIT(0), 541 541 IEEE80211_CONF_CHANGE_LISTEN_INTERVAL = BIT(2), 542 542 IEEE80211_CONF_CHANGE_RADIOTAP = BIT(3), 543 543 IEEE80211_CONF_CHANGE_PS = BIT(4), ··· 547 549 }; 548 550 549 551 static inline __deprecated enum ieee80211_conf_changed 550 - __IEEE80211_CONF_CHANGE_BEACON_INTERVAL(void) 552 + __IEEE80211_CONF_CHANGE_RADIO_ENABLED(void) 551 553 { 552 - return _IEEE80211_CONF_CHANGE_BEACON_INTERVAL; 554 + return _IEEE80211_CONF_CHANGE_RADIO_ENABLED; 553 555 } 554 - #define IEEE80211_CONF_CHANGE_BEACON_INTERVAL \ 555 - __IEEE80211_CONF_CHANGE_BEACON_INTERVAL() 556 + #define IEEE80211_CONF_CHANGE_RADIO_ENABLED \ 557 + __IEEE80211_CONF_CHANGE_RADIO_ENABLED() 556 558 557 559 /** 558 560 * struct ieee80211_conf - configuration of the device ··· 562 564 * @flags: configuration flags defined above 563 565 * 564 566 * @radio_enabled: when zero, driver is required to switch off the radio. 565 - * @beacon_int: beacon interval (TODO make interface config) 567 + * @beacon_int: DEPRECATED, DO NOT USE 566 568 * 567 569 * @listen_interval: listen interval in units of beacon interval 568 570 * @max_sleep_period: the maximum number of beacon intervals to sleep for ··· 587 589 * number of transmissions not the number of retries 588 590 */ 589 591 struct ieee80211_conf { 590 - int beacon_int; 592 + int __deprecated beacon_int; 591 593 u32 flags; 592 594 int power_level, dynamic_ps_timeout; 593 595 int max_sleep_period; 594 596 595 597 u16 listen_interval; 596 - bool radio_enabled; 598 + bool __deprecated radio_enabled; 597 599 598 600 u8 long_frame_max_tx_count, short_frame_max_tx_count; 599 601 ··· 1404 1406 * is the first frame we expect to perform the action on. Notice 1405 1407 * that TX/RX_STOP can pass NULL for this parameter. 1406 1408 * Returns a negative error code on failure. 1409 + * 1410 + * @rfkill_poll: Poll rfkill hardware state. If you need this, you also 1411 + * need to set wiphy->rfkill_poll to %true before registration, 1412 + * and need to call wiphy_rfkill_set_hw_state() in the callback. 1407 1413 */ 1408 1414 struct ieee80211_ops { 1409 1415 int (*tx)(struct ieee80211_hw *hw, struct sk_buff *skb); ··· 1456 1454 int (*ampdu_action)(struct ieee80211_hw *hw, 1457 1455 enum ieee80211_ampdu_mlme_action action, 1458 1456 struct ieee80211_sta *sta, u16 tid, u16 *ssn); 1457 + 1458 + void (*rfkill_poll)(struct ieee80211_hw *hw); 1459 1459 }; 1460 1460 1461 1461 /**
+2 -6
include/net/wimax.h
··· 253 253 struct net_device; 254 254 struct genl_info; 255 255 struct wimax_dev; 256 - struct input_dev; 257 256 258 257 /** 259 258 * struct wimax_dev - Generic WiMAX device ··· 292 293 * See wimax_reset()'s documentation. 293 294 * 294 295 * @name: [fill] A way to identify this device. We need to register a 295 - * name with many subsystems (input for RFKILL, workqueue 296 - * creation, etc). We can't use the network device name as that 296 + * name with many subsystems (rfkill, workqueue creation, etc). 297 + * We can't use the network device name as that 297 298 * might change and in some instances we don't know it yet (until 298 299 * we don't call register_netdev()). So we generate an unique one 299 300 * using the driver name and device bus id, place it here and use ··· 314 315 * @state: [private] Current state of the WiMAX device. 315 316 * 316 317 * @rfkill: [private] integration into the RF-Kill infrastructure. 317 - * 318 - * @rfkill_input: [private] virtual input device to process the 319 - * hardware RF Kill switches. 320 318 * 321 319 * @rf_sw: [private] State of the software radio switch (OFF/ON) 322 320 *
+6 -1
net/core/dev.c
··· 1048 1048 int dev_open(struct net_device *dev) 1049 1049 { 1050 1050 const struct net_device_ops *ops = dev->netdev_ops; 1051 - int ret = 0; 1051 + int ret; 1052 1052 1053 1053 ASSERT_RTNL(); 1054 1054 ··· 1064 1064 */ 1065 1065 if (!netif_device_present(dev)) 1066 1066 return -ENODEV; 1067 + 1068 + ret = call_netdevice_notifiers(NETDEV_PRE_UP, dev); 1069 + ret = notifier_to_errno(ret); 1070 + if (ret) 1071 + return ret; 1067 1072 1068 1073 /* 1069 1074 * Call device private open method
+4 -1
net/mac80211/Kconfig
··· 1 1 config MAC80211 2 2 tristate "Generic IEEE 802.11 Networking Stack (mac80211)" 3 + depends on CFG80211 3 4 select CRYPTO 4 5 select CRYPTO_ECB 5 6 select CRYPTO_ARC4 6 7 select CRYPTO_AES 7 8 select CRC32 8 9 select WIRELESS_EXT 9 - select CFG80211 10 10 ---help--- 11 11 This option enables the hardware independent IEEE 802.11 12 12 networking stack. 13 + 14 + comment "CFG80211 needs to be enabled for MAC80211" 15 + depends on CFG80211=n 13 16 14 17 config MAC80211_DEFAULT_PS 15 18 bool "enable powersave by default"
+58 -7
net/mac80211/cfg.c
··· 664 664 spin_unlock_bh(&sta->lock); 665 665 666 666 /* 667 + * cfg80211 validates this (1-2007) and allows setting the AID 668 + * only when creating a new station entry 669 + */ 670 + if (params->aid) 671 + sta->sta.aid = params->aid; 672 + 673 + /* 667 674 * FIXME: updating the following information is racy when this 668 675 * function is called from ieee80211_change_station(). 669 676 * However, all this information should be static so 670 677 * maybe we should just reject attemps to change it. 671 678 */ 672 - 673 - if (params->aid) { 674 - sta->sta.aid = params->aid; 675 - if (sta->sta.aid > IEEE80211_MAX_AID) 676 - sta->sta.aid = 0; /* XXX: should this be an error? */ 677 - } 678 679 679 680 if (params->listen_interval >= 0) 680 681 sta->listen_interval = params->listen_interval; ··· 1256 1255 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_SSID_SEL; 1257 1256 1258 1257 ret = ieee80211_sta_set_extra_ie(sdata, req->ie, req->ie_len); 1259 - if (ret) 1258 + if (ret && ret != -EALREADY) 1260 1259 return ret; 1261 1260 1262 1261 if (req->use_mfp) { ··· 1334 1333 return 0; 1335 1334 } 1336 1335 1336 + static int ieee80211_set_tx_power(struct wiphy *wiphy, 1337 + enum tx_power_setting type, int dbm) 1338 + { 1339 + struct ieee80211_local *local = wiphy_priv(wiphy); 1340 + struct ieee80211_channel *chan = local->hw.conf.channel; 1341 + u32 changes = 0; 1342 + 1343 + switch (type) { 1344 + case TX_POWER_AUTOMATIC: 1345 + local->user_power_level = -1; 1346 + break; 1347 + case TX_POWER_LIMITED: 1348 + if (dbm < 0) 1349 + return -EINVAL; 1350 + local->user_power_level = dbm; 1351 + break; 1352 + case TX_POWER_FIXED: 1353 + if (dbm < 0) 1354 + return -EINVAL; 1355 + /* TODO: move to cfg80211 when it knows the channel */ 1356 + if (dbm > chan->max_power) 1357 + return -EINVAL; 1358 + local->user_power_level = dbm; 1359 + break; 1360 + } 1361 + 1362 + ieee80211_hw_config(local, changes); 1363 + 1364 + return 0; 1365 + } 1366 + 1367 + static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm) 1368 + { 1369 + struct ieee80211_local *local = wiphy_priv(wiphy); 1370 + 1371 + *dbm = local->hw.conf.power_level; 1372 + 1373 + return 0; 1374 + } 1375 + 1376 + static void ieee80211_rfkill_poll(struct wiphy *wiphy) 1377 + { 1378 + struct ieee80211_local *local = wiphy_priv(wiphy); 1379 + 1380 + drv_rfkill_poll(local); 1381 + } 1382 + 1337 1383 struct cfg80211_ops mac80211_config_ops = { 1338 1384 .add_virtual_intf = ieee80211_add_iface, 1339 1385 .del_virtual_intf = ieee80211_del_iface, ··· 1420 1372 .join_ibss = ieee80211_join_ibss, 1421 1373 .leave_ibss = ieee80211_leave_ibss, 1422 1374 .set_wiphy_params = ieee80211_set_wiphy_params, 1375 + .set_tx_power = ieee80211_set_tx_power, 1376 + .get_tx_power = ieee80211_get_tx_power, 1377 + .rfkill_poll = ieee80211_rfkill_poll, 1423 1378 };
+7
net/mac80211/driver-ops.h
··· 181 181 sta, tid, ssn); 182 182 return -EOPNOTSUPP; 183 183 } 184 + 185 + 186 + static inline void drv_rfkill_poll(struct ieee80211_local *local) 187 + { 188 + if (local->ops->rfkill_poll) 189 + local->ops->rfkill_poll(&local->hw); 190 + } 184 191 #endif /* __MAC80211_DRIVER_OPS */
+2 -2
net/mac80211/iface.c
··· 170 170 goto err_del_bss; 171 171 /* we're brought up, everything changes */ 172 172 hw_reconf_flags = ~0; 173 - ieee80211_led_radio(local, local->hw.conf.radio_enabled); 173 + ieee80211_led_radio(local, true); 174 174 } 175 175 176 176 /* ··· 560 560 561 561 drv_stop(local); 562 562 563 - ieee80211_led_radio(local, 0); 563 + ieee80211_led_radio(local, false); 564 564 565 565 flush_workqueue(local->hw.workqueue); 566 566
+2 -10
net/mac80211/main.c
··· 289 289 drv_bss_info_changed(local, &sdata->vif, 290 290 &sdata->vif.bss_conf, changed); 291 291 292 - /* 293 - * DEPRECATED 294 - * 295 - * ~changed is just there to not do this at resume time 296 - */ 297 - if (changed & BSS_CHANGED_BEACON_INT && ~changed) { 298 - local->hw.conf.beacon_int = sdata->vif.bss_conf.beacon_int; 299 - ieee80211_hw_config(local, 300 - _IEEE80211_CONF_CHANGE_BEACON_INTERVAL); 301 - } 292 + /* DEPRECATED */ 293 + local->hw.conf.beacon_int = sdata->vif.bss_conf.beacon_int; 302 294 } 303 295 304 296 u32 ieee80211_reset_erp_info(struct ieee80211_sub_if_data *sdata)
+9
net/mac80211/sta_info.c
··· 44 44 * When the insertion fails (sta_info_insert()) returns non-zero), the 45 45 * structure will have been freed by sta_info_insert()! 46 46 * 47 + * sta entries are added by mac80211 when you establish a link with a 48 + * peer. This means different things for the different type of interfaces 49 + * we support. For a regular station this mean we add the AP sta when we 50 + * receive an assocation response from the AP. For IBSS this occurs when 51 + * we receive a probe response or a beacon from target IBSS network. For 52 + * WDS we add the sta for the peer imediately upon device open. When using 53 + * AP mode we add stations for each respective station upon request from 54 + * userspace through nl80211. 55 + * 47 56 * Because there are debugfs entries for each station, and adding those 48 57 * must be able to sleep, it is also possible to "pin" a station entry, 49 58 * that means it can be removed from the hash table but not be freed.
-2
net/mac80211/tx.c
··· 1238 1238 bool txpending) 1239 1239 { 1240 1240 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 1241 - struct sta_info *sta; 1242 1241 struct ieee80211_tx_data tx; 1243 1242 ieee80211_tx_result res_prepare; 1244 1243 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); ··· 1269 1270 return; 1270 1271 } 1271 1272 1272 - sta = tx.sta; 1273 1273 tx.channel = local->hw.conf.channel; 1274 1274 info->band = tx.channel->band; 1275 1275
+5 -5
net/mac80211/util.c
··· 657 657 658 658 switch (queue) { 659 659 case 3: /* AC_BK */ 660 - qparam.cw_max = aCWmin; 661 - qparam.cw_min = aCWmax; 660 + qparam.cw_max = aCWmax; 661 + qparam.cw_min = aCWmin; 662 662 qparam.txop = 0; 663 663 qparam.aifs = 7; 664 664 break; 665 665 default: /* never happens but let's not leave undefined */ 666 666 case 2: /* AC_BE */ 667 - qparam.cw_max = aCWmin; 668 - qparam.cw_min = aCWmax; 667 + qparam.cw_max = aCWmax; 668 + qparam.cw_min = aCWmin; 669 669 qparam.txop = 0; 670 670 qparam.aifs = 3; 671 671 break; ··· 973 973 if (local->open_count) { 974 974 res = drv_start(local); 975 975 976 - ieee80211_led_radio(local, hw->conf.radio_enabled); 976 + ieee80211_led_radio(local, true); 977 977 } 978 978 979 979 /* add interfaces */
+2 -78
net/mac80211/wext.c
··· 306 306 return 0; 307 307 } 308 308 309 - static int ieee80211_ioctl_siwtxpower(struct net_device *dev, 310 - struct iw_request_info *info, 311 - union iwreq_data *data, char *extra) 312 - { 313 - struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 314 - struct ieee80211_channel* chan = local->hw.conf.channel; 315 - bool reconf = false; 316 - u32 reconf_flags = 0; 317 - int new_power_level; 318 - 319 - if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM) 320 - return -EINVAL; 321 - if (data->txpower.flags & IW_TXPOW_RANGE) 322 - return -EINVAL; 323 - if (!chan) 324 - return -EINVAL; 325 - 326 - /* only change when not disabling */ 327 - if (!data->txpower.disabled) { 328 - if (data->txpower.fixed) { 329 - if (data->txpower.value < 0) 330 - return -EINVAL; 331 - new_power_level = data->txpower.value; 332 - /* 333 - * Debatable, but we cannot do a fixed power 334 - * level above the regulatory constraint. 335 - * Use "iwconfig wlan0 txpower 15dBm" instead. 336 - */ 337 - if (new_power_level > chan->max_power) 338 - return -EINVAL; 339 - } else { 340 - /* 341 - * Automatic power level setting, max being the value 342 - * passed in from userland. 343 - */ 344 - if (data->txpower.value < 0) 345 - new_power_level = -1; 346 - else 347 - new_power_level = data->txpower.value; 348 - } 349 - 350 - reconf = true; 351 - 352 - /* 353 - * ieee80211_hw_config() will limit to the channel's 354 - * max power and possibly power constraint from AP. 355 - */ 356 - local->user_power_level = new_power_level; 357 - } 358 - 359 - if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) { 360 - local->hw.conf.radio_enabled = !(data->txpower.disabled); 361 - reconf_flags |= IEEE80211_CONF_CHANGE_RADIO_ENABLED; 362 - ieee80211_led_radio(local, local->hw.conf.radio_enabled); 363 - } 364 - 365 - if (reconf || reconf_flags) 366 - ieee80211_hw_config(local, reconf_flags); 367 - 368 - return 0; 369 - } 370 - 371 - static int ieee80211_ioctl_giwtxpower(struct net_device *dev, 372 - struct iw_request_info *info, 373 - union iwreq_data *data, char *extra) 374 - { 375 - struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 376 - 377 - data->txpower.fixed = 1; 378 - data->txpower.disabled = !(local->hw.conf.radio_enabled); 379 - data->txpower.value = local->hw.conf.power_level; 380 - data->txpower.flags = IW_TXPOW_DBM; 381 - 382 - return 0; 383 - } 384 - 385 309 static int ieee80211_ioctl_siwpower(struct net_device *dev, 386 310 struct iw_request_info *info, 387 311 struct iw_param *wrq, ··· 582 658 (iw_handler) cfg80211_wext_giwrts, /* SIOCGIWRTS */ 583 659 (iw_handler) cfg80211_wext_siwfrag, /* SIOCSIWFRAG */ 584 660 (iw_handler) cfg80211_wext_giwfrag, /* SIOCGIWFRAG */ 585 - (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */ 586 - (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */ 661 + (iw_handler) cfg80211_wext_siwtxpower, /* SIOCSIWTXPOW */ 662 + (iw_handler) cfg80211_wext_giwtxpower, /* SIOCGIWTXPOW */ 587 663 (iw_handler) cfg80211_wext_siwretry, /* SIOCSIWRETRY */ 588 664 (iw_handler) cfg80211_wext_giwretry, /* SIOCGIWRETRY */ 589 665 (iw_handler) cfg80211_wext_siwencode, /* SIOCSIWENCODE */
+7 -14
net/rfkill/Kconfig
··· 10 10 To compile this driver as a module, choose M here: the 11 11 module will be called rfkill. 12 12 13 - config RFKILL_INPUT 14 - tristate "Input layer to RF switch connector" 15 - depends on RFKILL && INPUT 16 - help 17 - Say Y here if you want kernel automatically toggle state 18 - of RF switches on and off when user presses appropriate 19 - button or a key on the keyboard. Without this module you 20 - need a some kind of userspace application to control 21 - state of the switches. 22 - 23 - To compile this driver as a module, choose M here: the 24 - module will be called rfkill-input. 25 - 26 13 # LED trigger support 27 14 config RFKILL_LEDS 28 15 bool 29 - depends on RFKILL && LEDS_TRIGGERS 16 + depends on RFKILL 17 + depends on LEDS_TRIGGERS = y || RFKILL = LEDS_TRIGGERS 30 18 default y 31 19 20 + config RFKILL_INPUT 21 + bool "RF switch input support" 22 + depends on RFKILL 23 + depends on INPUT = y || RFKILL = INPUT 24 + default y if !EMBEDDED
+3 -2
net/rfkill/Makefile
··· 2 2 # Makefile for the RF switch subsystem. 3 3 # 4 4 5 - obj-$(CONFIG_RFKILL) += rfkill.o 6 - obj-$(CONFIG_RFKILL_INPUT) += rfkill-input.o 5 + rfkill-y += core.o 6 + rfkill-$(CONFIG_RFKILL_INPUT) += input.o 7 + obj-$(CONFIG_RFKILL) += rfkill.o
+1228
net/rfkill/core.c
··· 1 + /* 2 + * Copyright (C) 2006 - 2007 Ivo van Doorn 3 + * Copyright (C) 2007 Dmitry Torokhov 4 + * Copyright 2009 Johannes Berg <johannes@sipsolutions.net> 5 + * 6 + * This program is free software; you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License as published by 8 + * the Free Software Foundation; either version 2 of the License, or 9 + * (at your option) any later version. 10 + * 11 + * This program is distributed in the hope that it will be useful, 12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + * GNU General Public License for more details. 15 + * 16 + * You should have received a copy of the GNU General Public License 17 + * along with this program; if not, write to the 18 + * Free Software Foundation, Inc., 19 + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 + */ 21 + 22 + #include <linux/kernel.h> 23 + #include <linux/module.h> 24 + #include <linux/init.h> 25 + #include <linux/workqueue.h> 26 + #include <linux/capability.h> 27 + #include <linux/list.h> 28 + #include <linux/mutex.h> 29 + #include <linux/rfkill.h> 30 + #include <linux/spinlock.h> 31 + #include <linux/miscdevice.h> 32 + #include <linux/wait.h> 33 + #include <linux/poll.h> 34 + #include <linux/fs.h> 35 + 36 + #include "rfkill.h" 37 + 38 + #define POLL_INTERVAL (5 * HZ) 39 + 40 + #define RFKILL_BLOCK_HW BIT(0) 41 + #define RFKILL_BLOCK_SW BIT(1) 42 + #define RFKILL_BLOCK_SW_PREV BIT(2) 43 + #define RFKILL_BLOCK_ANY (RFKILL_BLOCK_HW |\ 44 + RFKILL_BLOCK_SW |\ 45 + RFKILL_BLOCK_SW_PREV) 46 + #define RFKILL_BLOCK_SW_SETCALL BIT(31) 47 + 48 + struct rfkill { 49 + spinlock_t lock; 50 + 51 + const char *name; 52 + enum rfkill_type type; 53 + 54 + unsigned long state; 55 + 56 + u32 idx; 57 + 58 + bool registered; 59 + bool suspended; 60 + 61 + const struct rfkill_ops *ops; 62 + void *data; 63 + 64 + #ifdef CONFIG_RFKILL_LEDS 65 + struct led_trigger led_trigger; 66 + const char *ledtrigname; 67 + #endif 68 + 69 + struct device dev; 70 + struct list_head node; 71 + 72 + struct delayed_work poll_work; 73 + struct work_struct uevent_work; 74 + struct work_struct sync_work; 75 + }; 76 + #define to_rfkill(d) container_of(d, struct rfkill, dev) 77 + 78 + struct rfkill_int_event { 79 + struct list_head list; 80 + struct rfkill_event ev; 81 + }; 82 + 83 + struct rfkill_data { 84 + struct list_head list; 85 + struct list_head events; 86 + struct mutex mtx; 87 + wait_queue_head_t read_wait; 88 + bool input_handler; 89 + }; 90 + 91 + 92 + MODULE_AUTHOR("Ivo van Doorn <IvDoorn@gmail.com>"); 93 + MODULE_AUTHOR("Johannes Berg <johannes@sipsolutions.net>"); 94 + MODULE_DESCRIPTION("RF switch support"); 95 + MODULE_LICENSE("GPL"); 96 + 97 + 98 + /* 99 + * The locking here should be made much smarter, we currently have 100 + * a bit of a stupid situation because drivers might want to register 101 + * the rfkill struct under their own lock, and take this lock during 102 + * rfkill method calls -- which will cause an AB-BA deadlock situation. 103 + * 104 + * To fix that, we need to rework this code here to be mostly lock-free 105 + * and only use the mutex for list manipulations, not to protect the 106 + * various other global variables. Then we can avoid holding the mutex 107 + * around driver operations, and all is happy. 108 + */ 109 + static LIST_HEAD(rfkill_list); /* list of registered rf switches */ 110 + static DEFINE_MUTEX(rfkill_global_mutex); 111 + static LIST_HEAD(rfkill_fds); /* list of open fds of /dev/rfkill */ 112 + 113 + static unsigned int rfkill_default_state = 1; 114 + module_param_named(default_state, rfkill_default_state, uint, 0444); 115 + MODULE_PARM_DESC(default_state, 116 + "Default initial state for all radio types, 0 = radio off"); 117 + 118 + static struct { 119 + bool cur, def; 120 + } rfkill_global_states[NUM_RFKILL_TYPES]; 121 + 122 + static unsigned long rfkill_states_default_locked; 123 + 124 + static bool rfkill_epo_lock_active; 125 + 126 + 127 + #ifdef CONFIG_RFKILL_LEDS 128 + static void rfkill_led_trigger_event(struct rfkill *rfkill) 129 + { 130 + struct led_trigger *trigger; 131 + 132 + if (!rfkill->registered) 133 + return; 134 + 135 + trigger = &rfkill->led_trigger; 136 + 137 + if (rfkill->state & RFKILL_BLOCK_ANY) 138 + led_trigger_event(trigger, LED_OFF); 139 + else 140 + led_trigger_event(trigger, LED_FULL); 141 + } 142 + 143 + static void rfkill_led_trigger_activate(struct led_classdev *led) 144 + { 145 + struct rfkill *rfkill; 146 + 147 + rfkill = container_of(led->trigger, struct rfkill, led_trigger); 148 + 149 + rfkill_led_trigger_event(rfkill); 150 + } 151 + 152 + const char *rfkill_get_led_trigger_name(struct rfkill *rfkill) 153 + { 154 + return rfkill->led_trigger.name; 155 + } 156 + EXPORT_SYMBOL(rfkill_get_led_trigger_name); 157 + 158 + void rfkill_set_led_trigger_name(struct rfkill *rfkill, const char *name) 159 + { 160 + BUG_ON(!rfkill); 161 + 162 + rfkill->ledtrigname = name; 163 + } 164 + EXPORT_SYMBOL(rfkill_set_led_trigger_name); 165 + 166 + static int rfkill_led_trigger_register(struct rfkill *rfkill) 167 + { 168 + rfkill->led_trigger.name = rfkill->ledtrigname 169 + ? : dev_name(&rfkill->dev); 170 + rfkill->led_trigger.activate = rfkill_led_trigger_activate; 171 + return led_trigger_register(&rfkill->led_trigger); 172 + } 173 + 174 + static void rfkill_led_trigger_unregister(struct rfkill *rfkill) 175 + { 176 + led_trigger_unregister(&rfkill->led_trigger); 177 + } 178 + #else 179 + static void rfkill_led_trigger_event(struct rfkill *rfkill) 180 + { 181 + } 182 + 183 + static inline int rfkill_led_trigger_register(struct rfkill *rfkill) 184 + { 185 + return 0; 186 + } 187 + 188 + static inline void rfkill_led_trigger_unregister(struct rfkill *rfkill) 189 + { 190 + } 191 + #endif /* CONFIG_RFKILL_LEDS */ 192 + 193 + static void rfkill_fill_event(struct rfkill_event *ev, struct rfkill *rfkill, 194 + enum rfkill_operation op) 195 + { 196 + unsigned long flags; 197 + 198 + ev->idx = rfkill->idx; 199 + ev->type = rfkill->type; 200 + ev->op = op; 201 + 202 + spin_lock_irqsave(&rfkill->lock, flags); 203 + ev->hard = !!(rfkill->state & RFKILL_BLOCK_HW); 204 + ev->soft = !!(rfkill->state & (RFKILL_BLOCK_SW | 205 + RFKILL_BLOCK_SW_PREV)); 206 + spin_unlock_irqrestore(&rfkill->lock, flags); 207 + } 208 + 209 + static void rfkill_send_events(struct rfkill *rfkill, enum rfkill_operation op) 210 + { 211 + struct rfkill_data *data; 212 + struct rfkill_int_event *ev; 213 + 214 + list_for_each_entry(data, &rfkill_fds, list) { 215 + ev = kzalloc(sizeof(*ev), GFP_KERNEL); 216 + if (!ev) 217 + continue; 218 + rfkill_fill_event(&ev->ev, rfkill, op); 219 + mutex_lock(&data->mtx); 220 + list_add_tail(&ev->list, &data->events); 221 + mutex_unlock(&data->mtx); 222 + wake_up_interruptible(&data->read_wait); 223 + } 224 + } 225 + 226 + static void rfkill_event(struct rfkill *rfkill) 227 + { 228 + if (!rfkill->registered || rfkill->suspended) 229 + return; 230 + 231 + kobject_uevent(&rfkill->dev.kobj, KOBJ_CHANGE); 232 + 233 + /* also send event to /dev/rfkill */ 234 + rfkill_send_events(rfkill, RFKILL_OP_CHANGE); 235 + } 236 + 237 + static bool __rfkill_set_hw_state(struct rfkill *rfkill, 238 + bool blocked, bool *change) 239 + { 240 + unsigned long flags; 241 + bool prev, any; 242 + 243 + BUG_ON(!rfkill); 244 + 245 + spin_lock_irqsave(&rfkill->lock, flags); 246 + prev = !!(rfkill->state & RFKILL_BLOCK_HW); 247 + if (blocked) 248 + rfkill->state |= RFKILL_BLOCK_HW; 249 + else 250 + rfkill->state &= ~RFKILL_BLOCK_HW; 251 + *change = prev != blocked; 252 + any = rfkill->state & RFKILL_BLOCK_ANY; 253 + spin_unlock_irqrestore(&rfkill->lock, flags); 254 + 255 + rfkill_led_trigger_event(rfkill); 256 + 257 + return any; 258 + } 259 + 260 + /** 261 + * rfkill_set_block - wrapper for set_block method 262 + * 263 + * @rfkill: the rfkill struct to use 264 + * @blocked: the new software state 265 + * 266 + * Calls the set_block method (when applicable) and handles notifications 267 + * etc. as well. 268 + */ 269 + static void rfkill_set_block(struct rfkill *rfkill, bool blocked) 270 + { 271 + unsigned long flags; 272 + int err; 273 + 274 + /* 275 + * Some platforms (...!) generate input events which affect the 276 + * _hard_ kill state -- whenever something tries to change the 277 + * current software state query the hardware state too. 278 + */ 279 + if (rfkill->ops->query) 280 + rfkill->ops->query(rfkill, rfkill->data); 281 + 282 + spin_lock_irqsave(&rfkill->lock, flags); 283 + if (rfkill->state & RFKILL_BLOCK_SW) 284 + rfkill->state |= RFKILL_BLOCK_SW_PREV; 285 + else 286 + rfkill->state &= ~RFKILL_BLOCK_SW_PREV; 287 + 288 + if (blocked) 289 + rfkill->state |= RFKILL_BLOCK_SW; 290 + else 291 + rfkill->state &= ~RFKILL_BLOCK_SW; 292 + 293 + rfkill->state |= RFKILL_BLOCK_SW_SETCALL; 294 + spin_unlock_irqrestore(&rfkill->lock, flags); 295 + 296 + if (unlikely(rfkill->dev.power.power_state.event & PM_EVENT_SLEEP)) 297 + return; 298 + 299 + err = rfkill->ops->set_block(rfkill->data, blocked); 300 + 301 + spin_lock_irqsave(&rfkill->lock, flags); 302 + if (err) { 303 + /* 304 + * Failed -- reset status to _prev, this may be different 305 + * from what set set _PREV to earlier in this function 306 + * if rfkill_set_sw_state was invoked. 307 + */ 308 + if (rfkill->state & RFKILL_BLOCK_SW_PREV) 309 + rfkill->state |= RFKILL_BLOCK_SW; 310 + else 311 + rfkill->state &= ~RFKILL_BLOCK_SW; 312 + } 313 + rfkill->state &= ~RFKILL_BLOCK_SW_SETCALL; 314 + rfkill->state &= ~RFKILL_BLOCK_SW_PREV; 315 + spin_unlock_irqrestore(&rfkill->lock, flags); 316 + 317 + rfkill_led_trigger_event(rfkill); 318 + rfkill_event(rfkill); 319 + } 320 + 321 + #ifdef CONFIG_RFKILL_INPUT 322 + static atomic_t rfkill_input_disabled = ATOMIC_INIT(0); 323 + 324 + /** 325 + * __rfkill_switch_all - Toggle state of all switches of given type 326 + * @type: type of interfaces to be affected 327 + * @state: the new state 328 + * 329 + * This function sets the state of all switches of given type, 330 + * unless a specific switch is claimed by userspace (in which case, 331 + * that switch is left alone) or suspended. 332 + * 333 + * Caller must have acquired rfkill_global_mutex. 334 + */ 335 + static void __rfkill_switch_all(const enum rfkill_type type, bool blocked) 336 + { 337 + struct rfkill *rfkill; 338 + 339 + rfkill_global_states[type].cur = blocked; 340 + list_for_each_entry(rfkill, &rfkill_list, node) { 341 + if (rfkill->type != type) 342 + continue; 343 + 344 + rfkill_set_block(rfkill, blocked); 345 + } 346 + } 347 + 348 + /** 349 + * rfkill_switch_all - Toggle state of all switches of given type 350 + * @type: type of interfaces to be affected 351 + * @state: the new state 352 + * 353 + * Acquires rfkill_global_mutex and calls __rfkill_switch_all(@type, @state). 354 + * Please refer to __rfkill_switch_all() for details. 355 + * 356 + * Does nothing if the EPO lock is active. 357 + */ 358 + void rfkill_switch_all(enum rfkill_type type, bool blocked) 359 + { 360 + if (atomic_read(&rfkill_input_disabled)) 361 + return; 362 + 363 + mutex_lock(&rfkill_global_mutex); 364 + 365 + if (!rfkill_epo_lock_active) 366 + __rfkill_switch_all(type, blocked); 367 + 368 + mutex_unlock(&rfkill_global_mutex); 369 + } 370 + 371 + /** 372 + * rfkill_epo - emergency power off all transmitters 373 + * 374 + * This kicks all non-suspended rfkill devices to RFKILL_STATE_SOFT_BLOCKED, 375 + * ignoring everything in its path but rfkill_global_mutex and rfkill->mutex. 376 + * 377 + * The global state before the EPO is saved and can be restored later 378 + * using rfkill_restore_states(). 379 + */ 380 + void rfkill_epo(void) 381 + { 382 + struct rfkill *rfkill; 383 + int i; 384 + 385 + if (atomic_read(&rfkill_input_disabled)) 386 + return; 387 + 388 + mutex_lock(&rfkill_global_mutex); 389 + 390 + rfkill_epo_lock_active = true; 391 + list_for_each_entry(rfkill, &rfkill_list, node) 392 + rfkill_set_block(rfkill, true); 393 + 394 + for (i = 0; i < NUM_RFKILL_TYPES; i++) { 395 + rfkill_global_states[i].def = rfkill_global_states[i].cur; 396 + rfkill_global_states[i].cur = true; 397 + } 398 + 399 + mutex_unlock(&rfkill_global_mutex); 400 + } 401 + 402 + /** 403 + * rfkill_restore_states - restore global states 404 + * 405 + * Restore (and sync switches to) the global state from the 406 + * states in rfkill_default_states. This can undo the effects of 407 + * a call to rfkill_epo(). 408 + */ 409 + void rfkill_restore_states(void) 410 + { 411 + int i; 412 + 413 + if (atomic_read(&rfkill_input_disabled)) 414 + return; 415 + 416 + mutex_lock(&rfkill_global_mutex); 417 + 418 + rfkill_epo_lock_active = false; 419 + for (i = 0; i < NUM_RFKILL_TYPES; i++) 420 + __rfkill_switch_all(i, rfkill_global_states[i].def); 421 + mutex_unlock(&rfkill_global_mutex); 422 + } 423 + 424 + /** 425 + * rfkill_remove_epo_lock - unlock state changes 426 + * 427 + * Used by rfkill-input manually unlock state changes, when 428 + * the EPO switch is deactivated. 429 + */ 430 + void rfkill_remove_epo_lock(void) 431 + { 432 + if (atomic_read(&rfkill_input_disabled)) 433 + return; 434 + 435 + mutex_lock(&rfkill_global_mutex); 436 + rfkill_epo_lock_active = false; 437 + mutex_unlock(&rfkill_global_mutex); 438 + } 439 + 440 + /** 441 + * rfkill_is_epo_lock_active - returns true EPO is active 442 + * 443 + * Returns 0 (false) if there is NOT an active EPO contidion, 444 + * and 1 (true) if there is an active EPO contition, which 445 + * locks all radios in one of the BLOCKED states. 446 + * 447 + * Can be called in atomic context. 448 + */ 449 + bool rfkill_is_epo_lock_active(void) 450 + { 451 + return rfkill_epo_lock_active; 452 + } 453 + 454 + /** 455 + * rfkill_get_global_sw_state - returns global state for a type 456 + * @type: the type to get the global state of 457 + * 458 + * Returns the current global state for a given wireless 459 + * device type. 460 + */ 461 + bool rfkill_get_global_sw_state(const enum rfkill_type type) 462 + { 463 + return rfkill_global_states[type].cur; 464 + } 465 + #endif 466 + 467 + void rfkill_set_global_sw_state(const enum rfkill_type type, bool blocked) 468 + { 469 + BUG_ON(type == RFKILL_TYPE_ALL); 470 + 471 + mutex_lock(&rfkill_global_mutex); 472 + 473 + /* don't allow unblock when epo */ 474 + if (rfkill_epo_lock_active && !blocked) 475 + goto out; 476 + 477 + /* too late */ 478 + if (rfkill_states_default_locked & BIT(type)) 479 + goto out; 480 + 481 + rfkill_states_default_locked |= BIT(type); 482 + 483 + rfkill_global_states[type].cur = blocked; 484 + rfkill_global_states[type].def = blocked; 485 + out: 486 + mutex_unlock(&rfkill_global_mutex); 487 + } 488 + EXPORT_SYMBOL(rfkill_set_global_sw_state); 489 + 490 + 491 + bool rfkill_set_hw_state(struct rfkill *rfkill, bool blocked) 492 + { 493 + bool ret, change; 494 + 495 + ret = __rfkill_set_hw_state(rfkill, blocked, &change); 496 + 497 + if (!rfkill->registered) 498 + return ret; 499 + 500 + if (change) 501 + schedule_work(&rfkill->uevent_work); 502 + 503 + return ret; 504 + } 505 + EXPORT_SYMBOL(rfkill_set_hw_state); 506 + 507 + static void __rfkill_set_sw_state(struct rfkill *rfkill, bool blocked) 508 + { 509 + u32 bit = RFKILL_BLOCK_SW; 510 + 511 + /* if in a ops->set_block right now, use other bit */ 512 + if (rfkill->state & RFKILL_BLOCK_SW_SETCALL) 513 + bit = RFKILL_BLOCK_SW_PREV; 514 + 515 + if (blocked) 516 + rfkill->state |= bit; 517 + else 518 + rfkill->state &= ~bit; 519 + } 520 + 521 + bool rfkill_set_sw_state(struct rfkill *rfkill, bool blocked) 522 + { 523 + unsigned long flags; 524 + bool prev, hwblock; 525 + 526 + BUG_ON(!rfkill); 527 + 528 + spin_lock_irqsave(&rfkill->lock, flags); 529 + prev = !!(rfkill->state & RFKILL_BLOCK_SW); 530 + __rfkill_set_sw_state(rfkill, blocked); 531 + hwblock = !!(rfkill->state & RFKILL_BLOCK_HW); 532 + blocked = blocked || hwblock; 533 + spin_unlock_irqrestore(&rfkill->lock, flags); 534 + 535 + if (!rfkill->registered) 536 + return blocked; 537 + 538 + if (prev != blocked && !hwblock) 539 + schedule_work(&rfkill->uevent_work); 540 + 541 + rfkill_led_trigger_event(rfkill); 542 + 543 + return blocked; 544 + } 545 + EXPORT_SYMBOL(rfkill_set_sw_state); 546 + 547 + void rfkill_set_states(struct rfkill *rfkill, bool sw, bool hw) 548 + { 549 + unsigned long flags; 550 + bool swprev, hwprev; 551 + 552 + BUG_ON(!rfkill); 553 + 554 + spin_lock_irqsave(&rfkill->lock, flags); 555 + 556 + /* 557 + * No need to care about prev/setblock ... this is for uevent only 558 + * and that will get triggered by rfkill_set_block anyway. 559 + */ 560 + swprev = !!(rfkill->state & RFKILL_BLOCK_SW); 561 + hwprev = !!(rfkill->state & RFKILL_BLOCK_HW); 562 + __rfkill_set_sw_state(rfkill, sw); 563 + 564 + spin_unlock_irqrestore(&rfkill->lock, flags); 565 + 566 + if (!rfkill->registered) 567 + return; 568 + 569 + if (swprev != sw || hwprev != hw) 570 + schedule_work(&rfkill->uevent_work); 571 + 572 + rfkill_led_trigger_event(rfkill); 573 + } 574 + EXPORT_SYMBOL(rfkill_set_states); 575 + 576 + static ssize_t rfkill_name_show(struct device *dev, 577 + struct device_attribute *attr, 578 + char *buf) 579 + { 580 + struct rfkill *rfkill = to_rfkill(dev); 581 + 582 + return sprintf(buf, "%s\n", rfkill->name); 583 + } 584 + 585 + static const char *rfkill_get_type_str(enum rfkill_type type) 586 + { 587 + switch (type) { 588 + case RFKILL_TYPE_WLAN: 589 + return "wlan"; 590 + case RFKILL_TYPE_BLUETOOTH: 591 + return "bluetooth"; 592 + case RFKILL_TYPE_UWB: 593 + return "ultrawideband"; 594 + case RFKILL_TYPE_WIMAX: 595 + return "wimax"; 596 + case RFKILL_TYPE_WWAN: 597 + return "wwan"; 598 + default: 599 + BUG(); 600 + } 601 + 602 + BUILD_BUG_ON(NUM_RFKILL_TYPES != RFKILL_TYPE_WWAN + 1); 603 + } 604 + 605 + static ssize_t rfkill_type_show(struct device *dev, 606 + struct device_attribute *attr, 607 + char *buf) 608 + { 609 + struct rfkill *rfkill = to_rfkill(dev); 610 + 611 + return sprintf(buf, "%s\n", rfkill_get_type_str(rfkill->type)); 612 + } 613 + 614 + static ssize_t rfkill_idx_show(struct device *dev, 615 + struct device_attribute *attr, 616 + char *buf) 617 + { 618 + struct rfkill *rfkill = to_rfkill(dev); 619 + 620 + return sprintf(buf, "%d\n", rfkill->idx); 621 + } 622 + 623 + static u8 user_state_from_blocked(unsigned long state) 624 + { 625 + if (state & RFKILL_BLOCK_HW) 626 + return RFKILL_USER_STATE_HARD_BLOCKED; 627 + if (state & RFKILL_BLOCK_SW) 628 + return RFKILL_USER_STATE_SOFT_BLOCKED; 629 + 630 + return RFKILL_USER_STATE_UNBLOCKED; 631 + } 632 + 633 + static ssize_t rfkill_state_show(struct device *dev, 634 + struct device_attribute *attr, 635 + char *buf) 636 + { 637 + struct rfkill *rfkill = to_rfkill(dev); 638 + unsigned long flags; 639 + u32 state; 640 + 641 + spin_lock_irqsave(&rfkill->lock, flags); 642 + state = rfkill->state; 643 + spin_unlock_irqrestore(&rfkill->lock, flags); 644 + 645 + return sprintf(buf, "%d\n", user_state_from_blocked(state)); 646 + } 647 + 648 + static ssize_t rfkill_state_store(struct device *dev, 649 + struct device_attribute *attr, 650 + const char *buf, size_t count) 651 + { 652 + /* 653 + * The intention was that userspace can only take control over 654 + * a given device when/if rfkill-input doesn't control it due 655 + * to user_claim. Since user_claim is currently unsupported, 656 + * we never support changing the state from userspace -- this 657 + * can be implemented again later. 658 + */ 659 + 660 + return -EPERM; 661 + } 662 + 663 + static ssize_t rfkill_claim_show(struct device *dev, 664 + struct device_attribute *attr, 665 + char *buf) 666 + { 667 + return sprintf(buf, "%d\n", 0); 668 + } 669 + 670 + static ssize_t rfkill_claim_store(struct device *dev, 671 + struct device_attribute *attr, 672 + const char *buf, size_t count) 673 + { 674 + return -EOPNOTSUPP; 675 + } 676 + 677 + static struct device_attribute rfkill_dev_attrs[] = { 678 + __ATTR(name, S_IRUGO, rfkill_name_show, NULL), 679 + __ATTR(type, S_IRUGO, rfkill_type_show, NULL), 680 + __ATTR(index, S_IRUGO, rfkill_idx_show, NULL), 681 + __ATTR(state, S_IRUGO|S_IWUSR, rfkill_state_show, rfkill_state_store), 682 + __ATTR(claim, S_IRUGO|S_IWUSR, rfkill_claim_show, rfkill_claim_store), 683 + __ATTR_NULL 684 + }; 685 + 686 + static void rfkill_release(struct device *dev) 687 + { 688 + struct rfkill *rfkill = to_rfkill(dev); 689 + 690 + kfree(rfkill); 691 + } 692 + 693 + static int rfkill_dev_uevent(struct device *dev, struct kobj_uevent_env *env) 694 + { 695 + struct rfkill *rfkill = to_rfkill(dev); 696 + unsigned long flags; 697 + u32 state; 698 + int error; 699 + 700 + error = add_uevent_var(env, "RFKILL_NAME=%s", rfkill->name); 701 + if (error) 702 + return error; 703 + error = add_uevent_var(env, "RFKILL_TYPE=%s", 704 + rfkill_get_type_str(rfkill->type)); 705 + if (error) 706 + return error; 707 + spin_lock_irqsave(&rfkill->lock, flags); 708 + state = rfkill->state; 709 + spin_unlock_irqrestore(&rfkill->lock, flags); 710 + error = add_uevent_var(env, "RFKILL_STATE=%d", 711 + user_state_from_blocked(state)); 712 + return error; 713 + } 714 + 715 + void rfkill_pause_polling(struct rfkill *rfkill) 716 + { 717 + BUG_ON(!rfkill); 718 + 719 + if (!rfkill->ops->poll) 720 + return; 721 + 722 + cancel_delayed_work_sync(&rfkill->poll_work); 723 + } 724 + EXPORT_SYMBOL(rfkill_pause_polling); 725 + 726 + void rfkill_resume_polling(struct rfkill *rfkill) 727 + { 728 + BUG_ON(!rfkill); 729 + 730 + if (!rfkill->ops->poll) 731 + return; 732 + 733 + schedule_work(&rfkill->poll_work.work); 734 + } 735 + EXPORT_SYMBOL(rfkill_resume_polling); 736 + 737 + static int rfkill_suspend(struct device *dev, pm_message_t state) 738 + { 739 + struct rfkill *rfkill = to_rfkill(dev); 740 + 741 + rfkill_pause_polling(rfkill); 742 + 743 + rfkill->suspended = true; 744 + 745 + return 0; 746 + } 747 + 748 + static int rfkill_resume(struct device *dev) 749 + { 750 + struct rfkill *rfkill = to_rfkill(dev); 751 + bool cur; 752 + 753 + mutex_lock(&rfkill_global_mutex); 754 + cur = rfkill_global_states[rfkill->type].cur; 755 + rfkill_set_block(rfkill, cur); 756 + mutex_unlock(&rfkill_global_mutex); 757 + 758 + rfkill->suspended = false; 759 + 760 + schedule_work(&rfkill->uevent_work); 761 + 762 + rfkill_resume_polling(rfkill); 763 + 764 + return 0; 765 + } 766 + 767 + static struct class rfkill_class = { 768 + .name = "rfkill", 769 + .dev_release = rfkill_release, 770 + .dev_attrs = rfkill_dev_attrs, 771 + .dev_uevent = rfkill_dev_uevent, 772 + .suspend = rfkill_suspend, 773 + .resume = rfkill_resume, 774 + }; 775 + 776 + bool rfkill_blocked(struct rfkill *rfkill) 777 + { 778 + unsigned long flags; 779 + u32 state; 780 + 781 + spin_lock_irqsave(&rfkill->lock, flags); 782 + state = rfkill->state; 783 + spin_unlock_irqrestore(&rfkill->lock, flags); 784 + 785 + return !!(state & RFKILL_BLOCK_ANY); 786 + } 787 + EXPORT_SYMBOL(rfkill_blocked); 788 + 789 + 790 + struct rfkill * __must_check rfkill_alloc(const char *name, 791 + struct device *parent, 792 + const enum rfkill_type type, 793 + const struct rfkill_ops *ops, 794 + void *ops_data) 795 + { 796 + struct rfkill *rfkill; 797 + struct device *dev; 798 + 799 + if (WARN_ON(!ops)) 800 + return NULL; 801 + 802 + if (WARN_ON(!ops->set_block)) 803 + return NULL; 804 + 805 + if (WARN_ON(!name)) 806 + return NULL; 807 + 808 + if (WARN_ON(type == RFKILL_TYPE_ALL || type >= NUM_RFKILL_TYPES)) 809 + return NULL; 810 + 811 + rfkill = kzalloc(sizeof(*rfkill), GFP_KERNEL); 812 + if (!rfkill) 813 + return NULL; 814 + 815 + spin_lock_init(&rfkill->lock); 816 + INIT_LIST_HEAD(&rfkill->node); 817 + rfkill->type = type; 818 + rfkill->name = name; 819 + rfkill->ops = ops; 820 + rfkill->data = ops_data; 821 + 822 + dev = &rfkill->dev; 823 + dev->class = &rfkill_class; 824 + dev->parent = parent; 825 + device_initialize(dev); 826 + 827 + return rfkill; 828 + } 829 + EXPORT_SYMBOL(rfkill_alloc); 830 + 831 + static void rfkill_poll(struct work_struct *work) 832 + { 833 + struct rfkill *rfkill; 834 + 835 + rfkill = container_of(work, struct rfkill, poll_work.work); 836 + 837 + /* 838 + * Poll hardware state -- driver will use one of the 839 + * rfkill_set{,_hw,_sw}_state functions and use its 840 + * return value to update the current status. 841 + */ 842 + rfkill->ops->poll(rfkill, rfkill->data); 843 + 844 + schedule_delayed_work(&rfkill->poll_work, 845 + round_jiffies_relative(POLL_INTERVAL)); 846 + } 847 + 848 + static void rfkill_uevent_work(struct work_struct *work) 849 + { 850 + struct rfkill *rfkill; 851 + 852 + rfkill = container_of(work, struct rfkill, uevent_work); 853 + 854 + mutex_lock(&rfkill_global_mutex); 855 + rfkill_event(rfkill); 856 + mutex_unlock(&rfkill_global_mutex); 857 + } 858 + 859 + static void rfkill_sync_work(struct work_struct *work) 860 + { 861 + struct rfkill *rfkill; 862 + bool cur; 863 + 864 + rfkill = container_of(work, struct rfkill, sync_work); 865 + 866 + mutex_lock(&rfkill_global_mutex); 867 + cur = rfkill_global_states[rfkill->type].cur; 868 + rfkill_set_block(rfkill, cur); 869 + mutex_unlock(&rfkill_global_mutex); 870 + } 871 + 872 + int __must_check rfkill_register(struct rfkill *rfkill) 873 + { 874 + static unsigned long rfkill_no; 875 + struct device *dev = &rfkill->dev; 876 + int error; 877 + 878 + BUG_ON(!rfkill); 879 + 880 + mutex_lock(&rfkill_global_mutex); 881 + 882 + if (rfkill->registered) { 883 + error = -EALREADY; 884 + goto unlock; 885 + } 886 + 887 + rfkill->idx = rfkill_no; 888 + dev_set_name(dev, "rfkill%lu", rfkill_no); 889 + rfkill_no++; 890 + 891 + if (!(rfkill_states_default_locked & BIT(rfkill->type))) { 892 + /* first of its kind */ 893 + BUILD_BUG_ON(NUM_RFKILL_TYPES > 894 + sizeof(rfkill_states_default_locked) * 8); 895 + rfkill_states_default_locked |= BIT(rfkill->type); 896 + rfkill_global_states[rfkill->type].cur = 897 + rfkill_global_states[rfkill->type].def; 898 + } 899 + 900 + list_add_tail(&rfkill->node, &rfkill_list); 901 + 902 + error = device_add(dev); 903 + if (error) 904 + goto remove; 905 + 906 + error = rfkill_led_trigger_register(rfkill); 907 + if (error) 908 + goto devdel; 909 + 910 + rfkill->registered = true; 911 + 912 + INIT_DELAYED_WORK(&rfkill->poll_work, rfkill_poll); 913 + INIT_WORK(&rfkill->uevent_work, rfkill_uevent_work); 914 + INIT_WORK(&rfkill->sync_work, rfkill_sync_work); 915 + 916 + if (rfkill->ops->poll) 917 + schedule_delayed_work(&rfkill->poll_work, 918 + round_jiffies_relative(POLL_INTERVAL)); 919 + schedule_work(&rfkill->sync_work); 920 + 921 + rfkill_send_events(rfkill, RFKILL_OP_ADD); 922 + 923 + mutex_unlock(&rfkill_global_mutex); 924 + return 0; 925 + 926 + devdel: 927 + device_del(&rfkill->dev); 928 + remove: 929 + list_del_init(&rfkill->node); 930 + unlock: 931 + mutex_unlock(&rfkill_global_mutex); 932 + return error; 933 + } 934 + EXPORT_SYMBOL(rfkill_register); 935 + 936 + void rfkill_unregister(struct rfkill *rfkill) 937 + { 938 + BUG_ON(!rfkill); 939 + 940 + if (rfkill->ops->poll) 941 + cancel_delayed_work_sync(&rfkill->poll_work); 942 + 943 + cancel_work_sync(&rfkill->uevent_work); 944 + cancel_work_sync(&rfkill->sync_work); 945 + 946 + rfkill->registered = false; 947 + 948 + device_del(&rfkill->dev); 949 + 950 + mutex_lock(&rfkill_global_mutex); 951 + rfkill_send_events(rfkill, RFKILL_OP_DEL); 952 + list_del_init(&rfkill->node); 953 + mutex_unlock(&rfkill_global_mutex); 954 + 955 + rfkill_led_trigger_unregister(rfkill); 956 + } 957 + EXPORT_SYMBOL(rfkill_unregister); 958 + 959 + void rfkill_destroy(struct rfkill *rfkill) 960 + { 961 + if (rfkill) 962 + put_device(&rfkill->dev); 963 + } 964 + EXPORT_SYMBOL(rfkill_destroy); 965 + 966 + static int rfkill_fop_open(struct inode *inode, struct file *file) 967 + { 968 + struct rfkill_data *data; 969 + struct rfkill *rfkill; 970 + struct rfkill_int_event *ev, *tmp; 971 + 972 + data = kzalloc(sizeof(*data), GFP_KERNEL); 973 + if (!data) 974 + return -ENOMEM; 975 + 976 + INIT_LIST_HEAD(&data->events); 977 + mutex_init(&data->mtx); 978 + init_waitqueue_head(&data->read_wait); 979 + 980 + mutex_lock(&rfkill_global_mutex); 981 + mutex_lock(&data->mtx); 982 + /* 983 + * start getting events from elsewhere but hold mtx to get 984 + * startup events added first 985 + */ 986 + list_add(&data->list, &rfkill_fds); 987 + 988 + list_for_each_entry(rfkill, &rfkill_list, node) { 989 + ev = kzalloc(sizeof(*ev), GFP_KERNEL); 990 + if (!ev) 991 + goto free; 992 + rfkill_fill_event(&ev->ev, rfkill, RFKILL_OP_ADD); 993 + list_add_tail(&ev->list, &data->events); 994 + } 995 + mutex_unlock(&data->mtx); 996 + mutex_unlock(&rfkill_global_mutex); 997 + 998 + file->private_data = data; 999 + 1000 + return nonseekable_open(inode, file); 1001 + 1002 + free: 1003 + mutex_unlock(&data->mtx); 1004 + mutex_unlock(&rfkill_global_mutex); 1005 + mutex_destroy(&data->mtx); 1006 + list_for_each_entry_safe(ev, tmp, &data->events, list) 1007 + kfree(ev); 1008 + kfree(data); 1009 + return -ENOMEM; 1010 + } 1011 + 1012 + static unsigned int rfkill_fop_poll(struct file *file, poll_table *wait) 1013 + { 1014 + struct rfkill_data *data = file->private_data; 1015 + unsigned int res = POLLOUT | POLLWRNORM; 1016 + 1017 + poll_wait(file, &data->read_wait, wait); 1018 + 1019 + mutex_lock(&data->mtx); 1020 + if (!list_empty(&data->events)) 1021 + res = POLLIN | POLLRDNORM; 1022 + mutex_unlock(&data->mtx); 1023 + 1024 + return res; 1025 + } 1026 + 1027 + static bool rfkill_readable(struct rfkill_data *data) 1028 + { 1029 + bool r; 1030 + 1031 + mutex_lock(&data->mtx); 1032 + r = !list_empty(&data->events); 1033 + mutex_unlock(&data->mtx); 1034 + 1035 + return r; 1036 + } 1037 + 1038 + static ssize_t rfkill_fop_read(struct file *file, char __user *buf, 1039 + size_t count, loff_t *pos) 1040 + { 1041 + struct rfkill_data *data = file->private_data; 1042 + struct rfkill_int_event *ev; 1043 + unsigned long sz; 1044 + int ret; 1045 + 1046 + mutex_lock(&data->mtx); 1047 + 1048 + while (list_empty(&data->events)) { 1049 + if (file->f_flags & O_NONBLOCK) { 1050 + ret = -EAGAIN; 1051 + goto out; 1052 + } 1053 + mutex_unlock(&data->mtx); 1054 + ret = wait_event_interruptible(data->read_wait, 1055 + rfkill_readable(data)); 1056 + mutex_lock(&data->mtx); 1057 + 1058 + if (ret) 1059 + goto out; 1060 + } 1061 + 1062 + ev = list_first_entry(&data->events, struct rfkill_int_event, 1063 + list); 1064 + 1065 + sz = min_t(unsigned long, sizeof(ev->ev), count); 1066 + ret = sz; 1067 + if (copy_to_user(buf, &ev->ev, sz)) 1068 + ret = -EFAULT; 1069 + 1070 + list_del(&ev->list); 1071 + kfree(ev); 1072 + out: 1073 + mutex_unlock(&data->mtx); 1074 + return ret; 1075 + } 1076 + 1077 + static ssize_t rfkill_fop_write(struct file *file, const char __user *buf, 1078 + size_t count, loff_t *pos) 1079 + { 1080 + struct rfkill *rfkill; 1081 + struct rfkill_event ev; 1082 + 1083 + /* we don't need the 'hard' variable but accept it */ 1084 + if (count < sizeof(ev) - 1) 1085 + return -EINVAL; 1086 + 1087 + if (copy_from_user(&ev, buf, sizeof(ev) - 1)) 1088 + return -EFAULT; 1089 + 1090 + if (ev.op != RFKILL_OP_CHANGE && ev.op != RFKILL_OP_CHANGE_ALL) 1091 + return -EINVAL; 1092 + 1093 + if (ev.type >= NUM_RFKILL_TYPES) 1094 + return -EINVAL; 1095 + 1096 + mutex_lock(&rfkill_global_mutex); 1097 + 1098 + if (ev.op == RFKILL_OP_CHANGE_ALL) { 1099 + if (ev.type == RFKILL_TYPE_ALL) { 1100 + enum rfkill_type i; 1101 + for (i = 0; i < NUM_RFKILL_TYPES; i++) 1102 + rfkill_global_states[i].cur = ev.soft; 1103 + } else { 1104 + rfkill_global_states[ev.type].cur = ev.soft; 1105 + } 1106 + } 1107 + 1108 + list_for_each_entry(rfkill, &rfkill_list, node) { 1109 + if (rfkill->idx != ev.idx && ev.op != RFKILL_OP_CHANGE_ALL) 1110 + continue; 1111 + 1112 + if (rfkill->type != ev.type && ev.type != RFKILL_TYPE_ALL) 1113 + continue; 1114 + 1115 + rfkill_set_block(rfkill, ev.soft); 1116 + } 1117 + mutex_unlock(&rfkill_global_mutex); 1118 + 1119 + return count; 1120 + } 1121 + 1122 + static int rfkill_fop_release(struct inode *inode, struct file *file) 1123 + { 1124 + struct rfkill_data *data = file->private_data; 1125 + struct rfkill_int_event *ev, *tmp; 1126 + 1127 + mutex_lock(&rfkill_global_mutex); 1128 + list_del(&data->list); 1129 + mutex_unlock(&rfkill_global_mutex); 1130 + 1131 + mutex_destroy(&data->mtx); 1132 + list_for_each_entry_safe(ev, tmp, &data->events, list) 1133 + kfree(ev); 1134 + 1135 + #ifdef CONFIG_RFKILL_INPUT 1136 + if (data->input_handler) 1137 + atomic_dec(&rfkill_input_disabled); 1138 + #endif 1139 + 1140 + kfree(data); 1141 + 1142 + return 0; 1143 + } 1144 + 1145 + #ifdef CONFIG_RFKILL_INPUT 1146 + static long rfkill_fop_ioctl(struct file *file, unsigned int cmd, 1147 + unsigned long arg) 1148 + { 1149 + struct rfkill_data *data = file->private_data; 1150 + 1151 + if (_IOC_TYPE(cmd) != RFKILL_IOC_MAGIC) 1152 + return -ENOSYS; 1153 + 1154 + if (_IOC_NR(cmd) != RFKILL_IOC_NOINPUT) 1155 + return -ENOSYS; 1156 + 1157 + mutex_lock(&data->mtx); 1158 + 1159 + if (!data->input_handler) { 1160 + atomic_inc(&rfkill_input_disabled); 1161 + data->input_handler = true; 1162 + } 1163 + 1164 + mutex_unlock(&data->mtx); 1165 + 1166 + return 0; 1167 + } 1168 + #endif 1169 + 1170 + static const struct file_operations rfkill_fops = { 1171 + .open = rfkill_fop_open, 1172 + .read = rfkill_fop_read, 1173 + .write = rfkill_fop_write, 1174 + .poll = rfkill_fop_poll, 1175 + .release = rfkill_fop_release, 1176 + #ifdef CONFIG_RFKILL_INPUT 1177 + .unlocked_ioctl = rfkill_fop_ioctl, 1178 + .compat_ioctl = rfkill_fop_ioctl, 1179 + #endif 1180 + }; 1181 + 1182 + static struct miscdevice rfkill_miscdev = { 1183 + .name = "rfkill", 1184 + .fops = &rfkill_fops, 1185 + .minor = MISC_DYNAMIC_MINOR, 1186 + }; 1187 + 1188 + static int __init rfkill_init(void) 1189 + { 1190 + int error; 1191 + int i; 1192 + 1193 + for (i = 0; i < NUM_RFKILL_TYPES; i++) 1194 + rfkill_global_states[i].def = !rfkill_default_state; 1195 + 1196 + error = class_register(&rfkill_class); 1197 + if (error) 1198 + goto out; 1199 + 1200 + error = misc_register(&rfkill_miscdev); 1201 + if (error) { 1202 + class_unregister(&rfkill_class); 1203 + goto out; 1204 + } 1205 + 1206 + #ifdef CONFIG_RFKILL_INPUT 1207 + error = rfkill_handler_init(); 1208 + if (error) { 1209 + misc_deregister(&rfkill_miscdev); 1210 + class_unregister(&rfkill_class); 1211 + goto out; 1212 + } 1213 + #endif 1214 + 1215 + out: 1216 + return error; 1217 + } 1218 + subsys_initcall(rfkill_init); 1219 + 1220 + static void __exit rfkill_exit(void) 1221 + { 1222 + #ifdef CONFIG_RFKILL_INPUT 1223 + rfkill_handler_exit(); 1224 + #endif 1225 + misc_deregister(&rfkill_miscdev); 1226 + class_unregister(&rfkill_class); 1227 + } 1228 + module_exit(rfkill_exit);
+342
net/rfkill/input.c
··· 1 + /* 2 + * Input layer to RF Kill interface connector 3 + * 4 + * Copyright (c) 2007 Dmitry Torokhov 5 + * Copyright 2009 Johannes Berg <johannes@sipsolutions.net> 6 + * 7 + * This program is free software; you can redistribute it and/or modify it 8 + * under the terms of the GNU General Public License version 2 as published 9 + * by the Free Software Foundation. 10 + * 11 + * If you ever run into a situation in which you have a SW_ type rfkill 12 + * input device, then you can revive code that was removed in the patch 13 + * "rfkill-input: remove unused code". 14 + */ 15 + 16 + #include <linux/input.h> 17 + #include <linux/slab.h> 18 + #include <linux/workqueue.h> 19 + #include <linux/init.h> 20 + #include <linux/rfkill.h> 21 + #include <linux/sched.h> 22 + 23 + #include "rfkill.h" 24 + 25 + enum rfkill_input_master_mode { 26 + RFKILL_INPUT_MASTER_UNLOCK = 0, 27 + RFKILL_INPUT_MASTER_RESTORE = 1, 28 + RFKILL_INPUT_MASTER_UNBLOCKALL = 2, 29 + NUM_RFKILL_INPUT_MASTER_MODES 30 + }; 31 + 32 + /* Delay (in ms) between consecutive switch ops */ 33 + #define RFKILL_OPS_DELAY 200 34 + 35 + static enum rfkill_input_master_mode rfkill_master_switch_mode = 36 + RFKILL_INPUT_MASTER_UNBLOCKALL; 37 + module_param_named(master_switch_mode, rfkill_master_switch_mode, uint, 0); 38 + MODULE_PARM_DESC(master_switch_mode, 39 + "SW_RFKILL_ALL ON should: 0=do nothing (only unlock); 1=restore; 2=unblock all"); 40 + 41 + static spinlock_t rfkill_op_lock; 42 + static bool rfkill_op_pending; 43 + static unsigned long rfkill_sw_pending[BITS_TO_LONGS(NUM_RFKILL_TYPES)]; 44 + static unsigned long rfkill_sw_state[BITS_TO_LONGS(NUM_RFKILL_TYPES)]; 45 + 46 + enum rfkill_sched_op { 47 + RFKILL_GLOBAL_OP_EPO = 0, 48 + RFKILL_GLOBAL_OP_RESTORE, 49 + RFKILL_GLOBAL_OP_UNLOCK, 50 + RFKILL_GLOBAL_OP_UNBLOCK, 51 + }; 52 + 53 + static enum rfkill_sched_op rfkill_master_switch_op; 54 + static enum rfkill_sched_op rfkill_op; 55 + 56 + static void __rfkill_handle_global_op(enum rfkill_sched_op op) 57 + { 58 + unsigned int i; 59 + 60 + switch (op) { 61 + case RFKILL_GLOBAL_OP_EPO: 62 + rfkill_epo(); 63 + break; 64 + case RFKILL_GLOBAL_OP_RESTORE: 65 + rfkill_restore_states(); 66 + break; 67 + case RFKILL_GLOBAL_OP_UNLOCK: 68 + rfkill_remove_epo_lock(); 69 + break; 70 + case RFKILL_GLOBAL_OP_UNBLOCK: 71 + rfkill_remove_epo_lock(); 72 + for (i = 0; i < NUM_RFKILL_TYPES; i++) 73 + rfkill_switch_all(i, false); 74 + break; 75 + default: 76 + /* memory corruption or bug, fail safely */ 77 + rfkill_epo(); 78 + WARN(1, "Unknown requested operation %d! " 79 + "rfkill Emergency Power Off activated\n", 80 + op); 81 + } 82 + } 83 + 84 + static void __rfkill_handle_normal_op(const enum rfkill_type type, 85 + const bool complement) 86 + { 87 + bool blocked; 88 + 89 + blocked = rfkill_get_global_sw_state(type); 90 + if (complement) 91 + blocked = !blocked; 92 + 93 + rfkill_switch_all(type, blocked); 94 + } 95 + 96 + static void rfkill_op_handler(struct work_struct *work) 97 + { 98 + unsigned int i; 99 + bool c; 100 + 101 + spin_lock_irq(&rfkill_op_lock); 102 + do { 103 + if (rfkill_op_pending) { 104 + enum rfkill_sched_op op = rfkill_op; 105 + rfkill_op_pending = false; 106 + memset(rfkill_sw_pending, 0, 107 + sizeof(rfkill_sw_pending)); 108 + spin_unlock_irq(&rfkill_op_lock); 109 + 110 + __rfkill_handle_global_op(op); 111 + 112 + spin_lock_irq(&rfkill_op_lock); 113 + 114 + /* 115 + * handle global ops first -- during unlocked period 116 + * we might have gotten a new global op. 117 + */ 118 + if (rfkill_op_pending) 119 + continue; 120 + } 121 + 122 + if (rfkill_is_epo_lock_active()) 123 + continue; 124 + 125 + for (i = 0; i < NUM_RFKILL_TYPES; i++) { 126 + if (__test_and_clear_bit(i, rfkill_sw_pending)) { 127 + c = __test_and_clear_bit(i, rfkill_sw_state); 128 + spin_unlock_irq(&rfkill_op_lock); 129 + 130 + __rfkill_handle_normal_op(i, c); 131 + 132 + spin_lock_irq(&rfkill_op_lock); 133 + } 134 + } 135 + } while (rfkill_op_pending); 136 + spin_unlock_irq(&rfkill_op_lock); 137 + } 138 + 139 + static DECLARE_DELAYED_WORK(rfkill_op_work, rfkill_op_handler); 140 + static unsigned long rfkill_last_scheduled; 141 + 142 + static unsigned long rfkill_ratelimit(const unsigned long last) 143 + { 144 + const unsigned long delay = msecs_to_jiffies(RFKILL_OPS_DELAY); 145 + return (time_after(jiffies, last + delay)) ? 0 : delay; 146 + } 147 + 148 + static void rfkill_schedule_ratelimited(void) 149 + { 150 + if (delayed_work_pending(&rfkill_op_work)) 151 + return; 152 + schedule_delayed_work(&rfkill_op_work, 153 + rfkill_ratelimit(rfkill_last_scheduled)); 154 + rfkill_last_scheduled = jiffies; 155 + } 156 + 157 + static void rfkill_schedule_global_op(enum rfkill_sched_op op) 158 + { 159 + unsigned long flags; 160 + 161 + spin_lock_irqsave(&rfkill_op_lock, flags); 162 + rfkill_op = op; 163 + rfkill_op_pending = true; 164 + if (op == RFKILL_GLOBAL_OP_EPO && !rfkill_is_epo_lock_active()) { 165 + /* bypass the limiter for EPO */ 166 + cancel_delayed_work(&rfkill_op_work); 167 + schedule_delayed_work(&rfkill_op_work, 0); 168 + rfkill_last_scheduled = jiffies; 169 + } else 170 + rfkill_schedule_ratelimited(); 171 + spin_unlock_irqrestore(&rfkill_op_lock, flags); 172 + } 173 + 174 + static void rfkill_schedule_toggle(enum rfkill_type type) 175 + { 176 + unsigned long flags; 177 + 178 + if (rfkill_is_epo_lock_active()) 179 + return; 180 + 181 + spin_lock_irqsave(&rfkill_op_lock, flags); 182 + if (!rfkill_op_pending) { 183 + __set_bit(type, rfkill_sw_pending); 184 + __change_bit(type, rfkill_sw_state); 185 + rfkill_schedule_ratelimited(); 186 + } 187 + spin_unlock_irqrestore(&rfkill_op_lock, flags); 188 + } 189 + 190 + static void rfkill_schedule_evsw_rfkillall(int state) 191 + { 192 + if (state) 193 + rfkill_schedule_global_op(rfkill_master_switch_op); 194 + else 195 + rfkill_schedule_global_op(RFKILL_GLOBAL_OP_EPO); 196 + } 197 + 198 + static void rfkill_event(struct input_handle *handle, unsigned int type, 199 + unsigned int code, int data) 200 + { 201 + if (type == EV_KEY && data == 1) { 202 + switch (code) { 203 + case KEY_WLAN: 204 + rfkill_schedule_toggle(RFKILL_TYPE_WLAN); 205 + break; 206 + case KEY_BLUETOOTH: 207 + rfkill_schedule_toggle(RFKILL_TYPE_BLUETOOTH); 208 + break; 209 + case KEY_UWB: 210 + rfkill_schedule_toggle(RFKILL_TYPE_UWB); 211 + break; 212 + case KEY_WIMAX: 213 + rfkill_schedule_toggle(RFKILL_TYPE_WIMAX); 214 + break; 215 + } 216 + } else if (type == EV_SW && code == SW_RFKILL_ALL) 217 + rfkill_schedule_evsw_rfkillall(data); 218 + } 219 + 220 + static int rfkill_connect(struct input_handler *handler, struct input_dev *dev, 221 + const struct input_device_id *id) 222 + { 223 + struct input_handle *handle; 224 + int error; 225 + 226 + handle = kzalloc(sizeof(struct input_handle), GFP_KERNEL); 227 + if (!handle) 228 + return -ENOMEM; 229 + 230 + handle->dev = dev; 231 + handle->handler = handler; 232 + handle->name = "rfkill"; 233 + 234 + /* causes rfkill_start() to be called */ 235 + error = input_register_handle(handle); 236 + if (error) 237 + goto err_free_handle; 238 + 239 + error = input_open_device(handle); 240 + if (error) 241 + goto err_unregister_handle; 242 + 243 + return 0; 244 + 245 + err_unregister_handle: 246 + input_unregister_handle(handle); 247 + err_free_handle: 248 + kfree(handle); 249 + return error; 250 + } 251 + 252 + static void rfkill_start(struct input_handle *handle) 253 + { 254 + /* 255 + * Take event_lock to guard against configuration changes, we 256 + * should be able to deal with concurrency with rfkill_event() 257 + * just fine (which event_lock will also avoid). 258 + */ 259 + spin_lock_irq(&handle->dev->event_lock); 260 + 261 + if (test_bit(EV_SW, handle->dev->evbit) && 262 + test_bit(SW_RFKILL_ALL, handle->dev->swbit)) 263 + rfkill_schedule_evsw_rfkillall(test_bit(SW_RFKILL_ALL, 264 + handle->dev->sw)); 265 + 266 + spin_unlock_irq(&handle->dev->event_lock); 267 + } 268 + 269 + static void rfkill_disconnect(struct input_handle *handle) 270 + { 271 + input_close_device(handle); 272 + input_unregister_handle(handle); 273 + kfree(handle); 274 + } 275 + 276 + static const struct input_device_id rfkill_ids[] = { 277 + { 278 + .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_KEYBIT, 279 + .evbit = { BIT_MASK(EV_KEY) }, 280 + .keybit = { [BIT_WORD(KEY_WLAN)] = BIT_MASK(KEY_WLAN) }, 281 + }, 282 + { 283 + .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_KEYBIT, 284 + .evbit = { BIT_MASK(EV_KEY) }, 285 + .keybit = { [BIT_WORD(KEY_BLUETOOTH)] = BIT_MASK(KEY_BLUETOOTH) }, 286 + }, 287 + { 288 + .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_KEYBIT, 289 + .evbit = { BIT_MASK(EV_KEY) }, 290 + .keybit = { [BIT_WORD(KEY_UWB)] = BIT_MASK(KEY_UWB) }, 291 + }, 292 + { 293 + .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_KEYBIT, 294 + .evbit = { BIT_MASK(EV_KEY) }, 295 + .keybit = { [BIT_WORD(KEY_WIMAX)] = BIT_MASK(KEY_WIMAX) }, 296 + }, 297 + { 298 + .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_SWBIT, 299 + .evbit = { BIT(EV_SW) }, 300 + .swbit = { [BIT_WORD(SW_RFKILL_ALL)] = BIT_MASK(SW_RFKILL_ALL) }, 301 + }, 302 + { } 303 + }; 304 + 305 + static struct input_handler rfkill_handler = { 306 + .name = "rfkill", 307 + .event = rfkill_event, 308 + .connect = rfkill_connect, 309 + .start = rfkill_start, 310 + .disconnect = rfkill_disconnect, 311 + .id_table = rfkill_ids, 312 + }; 313 + 314 + int __init rfkill_handler_init(void) 315 + { 316 + switch (rfkill_master_switch_mode) { 317 + case RFKILL_INPUT_MASTER_UNBLOCKALL: 318 + rfkill_master_switch_op = RFKILL_GLOBAL_OP_UNBLOCK; 319 + break; 320 + case RFKILL_INPUT_MASTER_RESTORE: 321 + rfkill_master_switch_op = RFKILL_GLOBAL_OP_RESTORE; 322 + break; 323 + case RFKILL_INPUT_MASTER_UNLOCK: 324 + rfkill_master_switch_op = RFKILL_GLOBAL_OP_UNLOCK; 325 + break; 326 + default: 327 + return -EINVAL; 328 + } 329 + 330 + spin_lock_init(&rfkill_op_lock); 331 + 332 + /* Avoid delay at first schedule */ 333 + rfkill_last_scheduled = 334 + jiffies - msecs_to_jiffies(RFKILL_OPS_DELAY) - 1; 335 + return input_register_handler(&rfkill_handler); 336 + } 337 + 338 + void __exit rfkill_handler_exit(void) 339 + { 340 + input_unregister_handler(&rfkill_handler); 341 + cancel_delayed_work_sync(&rfkill_op_work); 342 + }
-390
net/rfkill/rfkill-input.c
··· 1 - /* 2 - * Input layer to RF Kill interface connector 3 - * 4 - * Copyright (c) 2007 Dmitry Torokhov 5 - */ 6 - 7 - /* 8 - * This program is free software; you can redistribute it and/or modify it 9 - * under the terms of the GNU General Public License version 2 as published 10 - * by the Free Software Foundation. 11 - */ 12 - 13 - #include <linux/module.h> 14 - #include <linux/input.h> 15 - #include <linux/slab.h> 16 - #include <linux/workqueue.h> 17 - #include <linux/init.h> 18 - #include <linux/rfkill.h> 19 - #include <linux/sched.h> 20 - 21 - #include "rfkill-input.h" 22 - 23 - MODULE_AUTHOR("Dmitry Torokhov <dtor@mail.ru>"); 24 - MODULE_DESCRIPTION("Input layer to RF switch connector"); 25 - MODULE_LICENSE("GPL"); 26 - 27 - enum rfkill_input_master_mode { 28 - RFKILL_INPUT_MASTER_DONOTHING = 0, 29 - RFKILL_INPUT_MASTER_RESTORE = 1, 30 - RFKILL_INPUT_MASTER_UNBLOCKALL = 2, 31 - RFKILL_INPUT_MASTER_MAX, /* marker */ 32 - }; 33 - 34 - /* Delay (in ms) between consecutive switch ops */ 35 - #define RFKILL_OPS_DELAY 200 36 - 37 - static enum rfkill_input_master_mode rfkill_master_switch_mode = 38 - RFKILL_INPUT_MASTER_UNBLOCKALL; 39 - module_param_named(master_switch_mode, rfkill_master_switch_mode, uint, 0); 40 - MODULE_PARM_DESC(master_switch_mode, 41 - "SW_RFKILL_ALL ON should: 0=do nothing; 1=restore; 2=unblock all"); 42 - 43 - enum rfkill_global_sched_op { 44 - RFKILL_GLOBAL_OP_EPO = 0, 45 - RFKILL_GLOBAL_OP_RESTORE, 46 - RFKILL_GLOBAL_OP_UNLOCK, 47 - RFKILL_GLOBAL_OP_UNBLOCK, 48 - }; 49 - 50 - struct rfkill_task { 51 - struct delayed_work dwork; 52 - 53 - /* ensures that task is serialized */ 54 - struct mutex mutex; 55 - 56 - /* protects everything below */ 57 - spinlock_t lock; 58 - 59 - /* pending regular switch operations (1=pending) */ 60 - unsigned long sw_pending[BITS_TO_LONGS(RFKILL_TYPE_MAX)]; 61 - 62 - /* should the state be complemented (1=yes) */ 63 - unsigned long sw_togglestate[BITS_TO_LONGS(RFKILL_TYPE_MAX)]; 64 - 65 - bool global_op_pending; 66 - enum rfkill_global_sched_op op; 67 - 68 - /* last time it was scheduled */ 69 - unsigned long last_scheduled; 70 - }; 71 - 72 - static void __rfkill_handle_global_op(enum rfkill_global_sched_op op) 73 - { 74 - unsigned int i; 75 - 76 - switch (op) { 77 - case RFKILL_GLOBAL_OP_EPO: 78 - rfkill_epo(); 79 - break; 80 - case RFKILL_GLOBAL_OP_RESTORE: 81 - rfkill_restore_states(); 82 - break; 83 - case RFKILL_GLOBAL_OP_UNLOCK: 84 - rfkill_remove_epo_lock(); 85 - break; 86 - case RFKILL_GLOBAL_OP_UNBLOCK: 87 - rfkill_remove_epo_lock(); 88 - for (i = 0; i < RFKILL_TYPE_MAX; i++) 89 - rfkill_switch_all(i, RFKILL_STATE_UNBLOCKED); 90 - break; 91 - default: 92 - /* memory corruption or bug, fail safely */ 93 - rfkill_epo(); 94 - WARN(1, "Unknown requested operation %d! " 95 - "rfkill Emergency Power Off activated\n", 96 - op); 97 - } 98 - } 99 - 100 - static void __rfkill_handle_normal_op(const enum rfkill_type type, 101 - const bool c) 102 - { 103 - enum rfkill_state state; 104 - 105 - state = rfkill_get_global_state(type); 106 - if (c) 107 - state = rfkill_state_complement(state); 108 - 109 - rfkill_switch_all(type, state); 110 - } 111 - 112 - static void rfkill_task_handler(struct work_struct *work) 113 - { 114 - struct rfkill_task *task = container_of(work, 115 - struct rfkill_task, dwork.work); 116 - bool doit = true; 117 - 118 - mutex_lock(&task->mutex); 119 - 120 - spin_lock_irq(&task->lock); 121 - while (doit) { 122 - if (task->global_op_pending) { 123 - enum rfkill_global_sched_op op = task->op; 124 - task->global_op_pending = false; 125 - memset(task->sw_pending, 0, sizeof(task->sw_pending)); 126 - spin_unlock_irq(&task->lock); 127 - 128 - __rfkill_handle_global_op(op); 129 - 130 - /* make sure we do at least one pass with 131 - * !task->global_op_pending */ 132 - spin_lock_irq(&task->lock); 133 - continue; 134 - } else if (!rfkill_is_epo_lock_active()) { 135 - unsigned int i = 0; 136 - 137 - while (!task->global_op_pending && 138 - i < RFKILL_TYPE_MAX) { 139 - if (test_and_clear_bit(i, task->sw_pending)) { 140 - bool c; 141 - c = test_and_clear_bit(i, 142 - task->sw_togglestate); 143 - spin_unlock_irq(&task->lock); 144 - 145 - __rfkill_handle_normal_op(i, c); 146 - 147 - spin_lock_irq(&task->lock); 148 - } 149 - i++; 150 - } 151 - } 152 - doit = task->global_op_pending; 153 - } 154 - spin_unlock_irq(&task->lock); 155 - 156 - mutex_unlock(&task->mutex); 157 - } 158 - 159 - static struct rfkill_task rfkill_task = { 160 - .dwork = __DELAYED_WORK_INITIALIZER(rfkill_task.dwork, 161 - rfkill_task_handler), 162 - .mutex = __MUTEX_INITIALIZER(rfkill_task.mutex), 163 - .lock = __SPIN_LOCK_UNLOCKED(rfkill_task.lock), 164 - }; 165 - 166 - static unsigned long rfkill_ratelimit(const unsigned long last) 167 - { 168 - const unsigned long delay = msecs_to_jiffies(RFKILL_OPS_DELAY); 169 - return (time_after(jiffies, last + delay)) ? 0 : delay; 170 - } 171 - 172 - static void rfkill_schedule_ratelimited(void) 173 - { 174 - if (!delayed_work_pending(&rfkill_task.dwork)) { 175 - schedule_delayed_work(&rfkill_task.dwork, 176 - rfkill_ratelimit(rfkill_task.last_scheduled)); 177 - rfkill_task.last_scheduled = jiffies; 178 - } 179 - } 180 - 181 - static void rfkill_schedule_global_op(enum rfkill_global_sched_op op) 182 - { 183 - unsigned long flags; 184 - 185 - spin_lock_irqsave(&rfkill_task.lock, flags); 186 - rfkill_task.op = op; 187 - rfkill_task.global_op_pending = true; 188 - if (op == RFKILL_GLOBAL_OP_EPO && !rfkill_is_epo_lock_active()) { 189 - /* bypass the limiter for EPO */ 190 - cancel_delayed_work(&rfkill_task.dwork); 191 - schedule_delayed_work(&rfkill_task.dwork, 0); 192 - rfkill_task.last_scheduled = jiffies; 193 - } else 194 - rfkill_schedule_ratelimited(); 195 - spin_unlock_irqrestore(&rfkill_task.lock, flags); 196 - } 197 - 198 - static void rfkill_schedule_toggle(enum rfkill_type type) 199 - { 200 - unsigned long flags; 201 - 202 - if (rfkill_is_epo_lock_active()) 203 - return; 204 - 205 - spin_lock_irqsave(&rfkill_task.lock, flags); 206 - if (!rfkill_task.global_op_pending) { 207 - set_bit(type, rfkill_task.sw_pending); 208 - change_bit(type, rfkill_task.sw_togglestate); 209 - rfkill_schedule_ratelimited(); 210 - } 211 - spin_unlock_irqrestore(&rfkill_task.lock, flags); 212 - } 213 - 214 - static void rfkill_schedule_evsw_rfkillall(int state) 215 - { 216 - if (state) { 217 - switch (rfkill_master_switch_mode) { 218 - case RFKILL_INPUT_MASTER_UNBLOCKALL: 219 - rfkill_schedule_global_op(RFKILL_GLOBAL_OP_UNBLOCK); 220 - break; 221 - case RFKILL_INPUT_MASTER_RESTORE: 222 - rfkill_schedule_global_op(RFKILL_GLOBAL_OP_RESTORE); 223 - break; 224 - case RFKILL_INPUT_MASTER_DONOTHING: 225 - rfkill_schedule_global_op(RFKILL_GLOBAL_OP_UNLOCK); 226 - break; 227 - default: 228 - /* memory corruption or driver bug! fail safely */ 229 - rfkill_schedule_global_op(RFKILL_GLOBAL_OP_EPO); 230 - WARN(1, "Unknown rfkill_master_switch_mode (%d), " 231 - "driver bug or memory corruption detected!\n", 232 - rfkill_master_switch_mode); 233 - break; 234 - } 235 - } else 236 - rfkill_schedule_global_op(RFKILL_GLOBAL_OP_EPO); 237 - } 238 - 239 - static void rfkill_event(struct input_handle *handle, unsigned int type, 240 - unsigned int code, int data) 241 - { 242 - if (type == EV_KEY && data == 1) { 243 - enum rfkill_type t; 244 - 245 - switch (code) { 246 - case KEY_WLAN: 247 - t = RFKILL_TYPE_WLAN; 248 - break; 249 - case KEY_BLUETOOTH: 250 - t = RFKILL_TYPE_BLUETOOTH; 251 - break; 252 - case KEY_UWB: 253 - t = RFKILL_TYPE_UWB; 254 - break; 255 - case KEY_WIMAX: 256 - t = RFKILL_TYPE_WIMAX; 257 - break; 258 - default: 259 - return; 260 - } 261 - rfkill_schedule_toggle(t); 262 - return; 263 - } else if (type == EV_SW) { 264 - switch (code) { 265 - case SW_RFKILL_ALL: 266 - rfkill_schedule_evsw_rfkillall(data); 267 - return; 268 - default: 269 - return; 270 - } 271 - } 272 - } 273 - 274 - static int rfkill_connect(struct input_handler *handler, struct input_dev *dev, 275 - const struct input_device_id *id) 276 - { 277 - struct input_handle *handle; 278 - int error; 279 - 280 - handle = kzalloc(sizeof(struct input_handle), GFP_KERNEL); 281 - if (!handle) 282 - return -ENOMEM; 283 - 284 - handle->dev = dev; 285 - handle->handler = handler; 286 - handle->name = "rfkill"; 287 - 288 - /* causes rfkill_start() to be called */ 289 - error = input_register_handle(handle); 290 - if (error) 291 - goto err_free_handle; 292 - 293 - error = input_open_device(handle); 294 - if (error) 295 - goto err_unregister_handle; 296 - 297 - return 0; 298 - 299 - err_unregister_handle: 300 - input_unregister_handle(handle); 301 - err_free_handle: 302 - kfree(handle); 303 - return error; 304 - } 305 - 306 - static void rfkill_start(struct input_handle *handle) 307 - { 308 - /* Take event_lock to guard against configuration changes, we 309 - * should be able to deal with concurrency with rfkill_event() 310 - * just fine (which event_lock will also avoid). */ 311 - spin_lock_irq(&handle->dev->event_lock); 312 - 313 - if (test_bit(EV_SW, handle->dev->evbit)) { 314 - if (test_bit(SW_RFKILL_ALL, handle->dev->swbit)) 315 - rfkill_schedule_evsw_rfkillall(test_bit(SW_RFKILL_ALL, 316 - handle->dev->sw)); 317 - /* add resync for further EV_SW events here */ 318 - } 319 - 320 - spin_unlock_irq(&handle->dev->event_lock); 321 - } 322 - 323 - static void rfkill_disconnect(struct input_handle *handle) 324 - { 325 - input_close_device(handle); 326 - input_unregister_handle(handle); 327 - kfree(handle); 328 - } 329 - 330 - static const struct input_device_id rfkill_ids[] = { 331 - { 332 - .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_KEYBIT, 333 - .evbit = { BIT_MASK(EV_KEY) }, 334 - .keybit = { [BIT_WORD(KEY_WLAN)] = BIT_MASK(KEY_WLAN) }, 335 - }, 336 - { 337 - .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_KEYBIT, 338 - .evbit = { BIT_MASK(EV_KEY) }, 339 - .keybit = { [BIT_WORD(KEY_BLUETOOTH)] = BIT_MASK(KEY_BLUETOOTH) }, 340 - }, 341 - { 342 - .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_KEYBIT, 343 - .evbit = { BIT_MASK(EV_KEY) }, 344 - .keybit = { [BIT_WORD(KEY_UWB)] = BIT_MASK(KEY_UWB) }, 345 - }, 346 - { 347 - .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_KEYBIT, 348 - .evbit = { BIT_MASK(EV_KEY) }, 349 - .keybit = { [BIT_WORD(KEY_WIMAX)] = BIT_MASK(KEY_WIMAX) }, 350 - }, 351 - { 352 - .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_SWBIT, 353 - .evbit = { BIT(EV_SW) }, 354 - .swbit = { [BIT_WORD(SW_RFKILL_ALL)] = BIT_MASK(SW_RFKILL_ALL) }, 355 - }, 356 - { } 357 - }; 358 - 359 - static struct input_handler rfkill_handler = { 360 - .event = rfkill_event, 361 - .connect = rfkill_connect, 362 - .disconnect = rfkill_disconnect, 363 - .start = rfkill_start, 364 - .name = "rfkill", 365 - .id_table = rfkill_ids, 366 - }; 367 - 368 - static int __init rfkill_handler_init(void) 369 - { 370 - if (rfkill_master_switch_mode >= RFKILL_INPUT_MASTER_MAX) 371 - return -EINVAL; 372 - 373 - /* 374 - * The penalty to not doing this is a possible RFKILL_OPS_DELAY delay 375 - * at the first use. Acceptable, but if we can avoid it, why not? 376 - */ 377 - rfkill_task.last_scheduled = 378 - jiffies - msecs_to_jiffies(RFKILL_OPS_DELAY) - 1; 379 - return input_register_handler(&rfkill_handler); 380 - } 381 - 382 - static void __exit rfkill_handler_exit(void) 383 - { 384 - input_unregister_handler(&rfkill_handler); 385 - cancel_delayed_work_sync(&rfkill_task.dwork); 386 - rfkill_remove_epo_lock(); 387 - } 388 - 389 - module_init(rfkill_handler_init); 390 - module_exit(rfkill_handler_exit);
+8 -2
net/rfkill/rfkill-input.h net/rfkill/rfkill.h
··· 1 1 /* 2 2 * Copyright (C) 2007 Ivo van Doorn 3 + * Copyright 2009 Johannes Berg <johannes@sipsolutions.net> 3 4 */ 4 5 5 6 /* ··· 12 11 #ifndef __RFKILL_INPUT_H 13 12 #define __RFKILL_INPUT_H 14 13 15 - void rfkill_switch_all(enum rfkill_type type, enum rfkill_state state); 14 + /* core code */ 15 + void rfkill_switch_all(const enum rfkill_type type, bool blocked); 16 16 void rfkill_epo(void); 17 17 void rfkill_restore_states(void); 18 18 void rfkill_remove_epo_lock(void); 19 19 bool rfkill_is_epo_lock_active(void); 20 - enum rfkill_state rfkill_get_global_state(const enum rfkill_type type); 20 + bool rfkill_get_global_sw_state(const enum rfkill_type type); 21 + 22 + /* input handler */ 23 + int rfkill_handler_init(void); 24 + void rfkill_handler_exit(void); 21 25 22 26 #endif /* __RFKILL_INPUT_H */
-855
net/rfkill/rfkill.c
··· 1 - /* 2 - * Copyright (C) 2006 - 2007 Ivo van Doorn 3 - * Copyright (C) 2007 Dmitry Torokhov 4 - * 5 - * This program is free software; you can redistribute it and/or modify 6 - * it under the terms of the GNU General Public License as published by 7 - * the Free Software Foundation; either version 2 of the License, or 8 - * (at your option) any later version. 9 - * 10 - * This program is distributed in the hope that it will be useful, 11 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 - * GNU General Public License for more details. 14 - * 15 - * You should have received a copy of the GNU General Public License 16 - * along with this program; if not, write to the 17 - * Free Software Foundation, Inc., 18 - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 - */ 20 - 21 - #include <linux/kernel.h> 22 - #include <linux/module.h> 23 - #include <linux/init.h> 24 - #include <linux/workqueue.h> 25 - #include <linux/capability.h> 26 - #include <linux/list.h> 27 - #include <linux/mutex.h> 28 - #include <linux/rfkill.h> 29 - 30 - /* Get declaration of rfkill_switch_all() to shut up sparse. */ 31 - #include "rfkill-input.h" 32 - 33 - 34 - MODULE_AUTHOR("Ivo van Doorn <IvDoorn@gmail.com>"); 35 - MODULE_VERSION("1.0"); 36 - MODULE_DESCRIPTION("RF switch support"); 37 - MODULE_LICENSE("GPL"); 38 - 39 - static LIST_HEAD(rfkill_list); /* list of registered rf switches */ 40 - static DEFINE_MUTEX(rfkill_global_mutex); 41 - 42 - static unsigned int rfkill_default_state = RFKILL_STATE_UNBLOCKED; 43 - module_param_named(default_state, rfkill_default_state, uint, 0444); 44 - MODULE_PARM_DESC(default_state, 45 - "Default initial state for all radio types, 0 = radio off"); 46 - 47 - struct rfkill_gsw_state { 48 - enum rfkill_state current_state; 49 - enum rfkill_state default_state; 50 - }; 51 - 52 - static struct rfkill_gsw_state rfkill_global_states[RFKILL_TYPE_MAX]; 53 - static unsigned long rfkill_states_lockdflt[BITS_TO_LONGS(RFKILL_TYPE_MAX)]; 54 - static bool rfkill_epo_lock_active; 55 - 56 - 57 - #ifdef CONFIG_RFKILL_LEDS 58 - static void rfkill_led_trigger(struct rfkill *rfkill, 59 - enum rfkill_state state) 60 - { 61 - struct led_trigger *led = &rfkill->led_trigger; 62 - 63 - if (!led->name) 64 - return; 65 - if (state != RFKILL_STATE_UNBLOCKED) 66 - led_trigger_event(led, LED_OFF); 67 - else 68 - led_trigger_event(led, LED_FULL); 69 - } 70 - 71 - static void rfkill_led_trigger_activate(struct led_classdev *led) 72 - { 73 - struct rfkill *rfkill = container_of(led->trigger, 74 - struct rfkill, led_trigger); 75 - 76 - rfkill_led_trigger(rfkill, rfkill->state); 77 - } 78 - #else 79 - static inline void rfkill_led_trigger(struct rfkill *rfkill, 80 - enum rfkill_state state) 81 - { 82 - } 83 - #endif /* CONFIG_RFKILL_LEDS */ 84 - 85 - static void rfkill_uevent(struct rfkill *rfkill) 86 - { 87 - kobject_uevent(&rfkill->dev.kobj, KOBJ_CHANGE); 88 - } 89 - 90 - static void update_rfkill_state(struct rfkill *rfkill) 91 - { 92 - enum rfkill_state newstate, oldstate; 93 - 94 - if (rfkill->get_state) { 95 - mutex_lock(&rfkill->mutex); 96 - if (!rfkill->get_state(rfkill->data, &newstate)) { 97 - oldstate = rfkill->state; 98 - rfkill->state = newstate; 99 - if (oldstate != newstate) 100 - rfkill_uevent(rfkill); 101 - } 102 - mutex_unlock(&rfkill->mutex); 103 - } 104 - rfkill_led_trigger(rfkill, rfkill->state); 105 - } 106 - 107 - /** 108 - * rfkill_toggle_radio - wrapper for toggle_radio hook 109 - * @rfkill: the rfkill struct to use 110 - * @force: calls toggle_radio even if cache says it is not needed, 111 - * and also makes sure notifications of the state will be 112 - * sent even if it didn't change 113 - * @state: the new state to call toggle_radio() with 114 - * 115 - * Calls rfkill->toggle_radio, enforcing the API for toggle_radio 116 - * calls and handling all the red tape such as issuing notifications 117 - * if the call is successful. 118 - * 119 - * Suspended devices are not touched at all, and -EAGAIN is returned. 120 - * 121 - * Note that the @force parameter cannot override a (possibly cached) 122 - * state of RFKILL_STATE_HARD_BLOCKED. Any device making use of 123 - * RFKILL_STATE_HARD_BLOCKED implements either get_state() or 124 - * rfkill_force_state(), so the cache either is bypassed or valid. 125 - * 126 - * Note that we do call toggle_radio for RFKILL_STATE_SOFT_BLOCKED 127 - * even if the radio is in RFKILL_STATE_HARD_BLOCKED state, so as to 128 - * give the driver a hint that it should double-BLOCK the transmitter. 129 - * 130 - * Caller must have acquired rfkill->mutex. 131 - */ 132 - static int rfkill_toggle_radio(struct rfkill *rfkill, 133 - enum rfkill_state state, 134 - int force) 135 - { 136 - int retval = 0; 137 - enum rfkill_state oldstate, newstate; 138 - 139 - if (unlikely(rfkill->dev.power.power_state.event & PM_EVENT_SLEEP)) 140 - return -EBUSY; 141 - 142 - oldstate = rfkill->state; 143 - 144 - if (rfkill->get_state && !force && 145 - !rfkill->get_state(rfkill->data, &newstate)) { 146 - rfkill->state = newstate; 147 - } 148 - 149 - switch (state) { 150 - case RFKILL_STATE_HARD_BLOCKED: 151 - /* typically happens when refreshing hardware state, 152 - * such as on resume */ 153 - state = RFKILL_STATE_SOFT_BLOCKED; 154 - break; 155 - case RFKILL_STATE_UNBLOCKED: 156 - /* force can't override this, only rfkill_force_state() can */ 157 - if (rfkill->state == RFKILL_STATE_HARD_BLOCKED) 158 - return -EPERM; 159 - break; 160 - case RFKILL_STATE_SOFT_BLOCKED: 161 - /* nothing to do, we want to give drivers the hint to double 162 - * BLOCK even a transmitter that is already in state 163 - * RFKILL_STATE_HARD_BLOCKED */ 164 - break; 165 - default: 166 - WARN(1, KERN_WARNING 167 - "rfkill: illegal state %d passed as parameter " 168 - "to rfkill_toggle_radio\n", state); 169 - return -EINVAL; 170 - } 171 - 172 - if (force || state != rfkill->state) { 173 - retval = rfkill->toggle_radio(rfkill->data, state); 174 - /* never allow a HARD->SOFT downgrade! */ 175 - if (!retval && rfkill->state != RFKILL_STATE_HARD_BLOCKED) 176 - rfkill->state = state; 177 - } 178 - 179 - if (force || rfkill->state != oldstate) 180 - rfkill_uevent(rfkill); 181 - 182 - rfkill_led_trigger(rfkill, rfkill->state); 183 - return retval; 184 - } 185 - 186 - /** 187 - * __rfkill_switch_all - Toggle state of all switches of given type 188 - * @type: type of interfaces to be affected 189 - * @state: the new state 190 - * 191 - * This function toggles the state of all switches of given type, 192 - * unless a specific switch is claimed by userspace (in which case, 193 - * that switch is left alone) or suspended. 194 - * 195 - * Caller must have acquired rfkill_global_mutex. 196 - */ 197 - static void __rfkill_switch_all(const enum rfkill_type type, 198 - const enum rfkill_state state) 199 - { 200 - struct rfkill *rfkill; 201 - 202 - if (WARN((state >= RFKILL_STATE_MAX || type >= RFKILL_TYPE_MAX), 203 - KERN_WARNING 204 - "rfkill: illegal state %d or type %d " 205 - "passed as parameter to __rfkill_switch_all\n", 206 - state, type)) 207 - return; 208 - 209 - rfkill_global_states[type].current_state = state; 210 - list_for_each_entry(rfkill, &rfkill_list, node) { 211 - if (rfkill->type == type) { 212 - mutex_lock(&rfkill->mutex); 213 - rfkill_toggle_radio(rfkill, state, 0); 214 - mutex_unlock(&rfkill->mutex); 215 - rfkill_led_trigger(rfkill, rfkill->state); 216 - } 217 - } 218 - } 219 - 220 - /** 221 - * rfkill_switch_all - Toggle state of all switches of given type 222 - * @type: type of interfaces to be affected 223 - * @state: the new state 224 - * 225 - * Acquires rfkill_global_mutex and calls __rfkill_switch_all(@type, @state). 226 - * Please refer to __rfkill_switch_all() for details. 227 - * 228 - * Does nothing if the EPO lock is active. 229 - */ 230 - void rfkill_switch_all(enum rfkill_type type, enum rfkill_state state) 231 - { 232 - mutex_lock(&rfkill_global_mutex); 233 - if (!rfkill_epo_lock_active) 234 - __rfkill_switch_all(type, state); 235 - mutex_unlock(&rfkill_global_mutex); 236 - } 237 - EXPORT_SYMBOL(rfkill_switch_all); 238 - 239 - /** 240 - * rfkill_epo - emergency power off all transmitters 241 - * 242 - * This kicks all non-suspended rfkill devices to RFKILL_STATE_SOFT_BLOCKED, 243 - * ignoring everything in its path but rfkill_global_mutex and rfkill->mutex. 244 - * 245 - * The global state before the EPO is saved and can be restored later 246 - * using rfkill_restore_states(). 247 - */ 248 - void rfkill_epo(void) 249 - { 250 - struct rfkill *rfkill; 251 - int i; 252 - 253 - mutex_lock(&rfkill_global_mutex); 254 - 255 - rfkill_epo_lock_active = true; 256 - list_for_each_entry(rfkill, &rfkill_list, node) { 257 - mutex_lock(&rfkill->mutex); 258 - rfkill_toggle_radio(rfkill, RFKILL_STATE_SOFT_BLOCKED, 1); 259 - mutex_unlock(&rfkill->mutex); 260 - } 261 - for (i = 0; i < RFKILL_TYPE_MAX; i++) { 262 - rfkill_global_states[i].default_state = 263 - rfkill_global_states[i].current_state; 264 - rfkill_global_states[i].current_state = 265 - RFKILL_STATE_SOFT_BLOCKED; 266 - } 267 - mutex_unlock(&rfkill_global_mutex); 268 - rfkill_led_trigger(rfkill, rfkill->state); 269 - } 270 - EXPORT_SYMBOL_GPL(rfkill_epo); 271 - 272 - /** 273 - * rfkill_restore_states - restore global states 274 - * 275 - * Restore (and sync switches to) the global state from the 276 - * states in rfkill_default_states. This can undo the effects of 277 - * a call to rfkill_epo(). 278 - */ 279 - void rfkill_restore_states(void) 280 - { 281 - int i; 282 - 283 - mutex_lock(&rfkill_global_mutex); 284 - 285 - rfkill_epo_lock_active = false; 286 - for (i = 0; i < RFKILL_TYPE_MAX; i++) 287 - __rfkill_switch_all(i, rfkill_global_states[i].default_state); 288 - mutex_unlock(&rfkill_global_mutex); 289 - } 290 - EXPORT_SYMBOL_GPL(rfkill_restore_states); 291 - 292 - /** 293 - * rfkill_remove_epo_lock - unlock state changes 294 - * 295 - * Used by rfkill-input manually unlock state changes, when 296 - * the EPO switch is deactivated. 297 - */ 298 - void rfkill_remove_epo_lock(void) 299 - { 300 - mutex_lock(&rfkill_global_mutex); 301 - rfkill_epo_lock_active = false; 302 - mutex_unlock(&rfkill_global_mutex); 303 - } 304 - EXPORT_SYMBOL_GPL(rfkill_remove_epo_lock); 305 - 306 - /** 307 - * rfkill_is_epo_lock_active - returns true EPO is active 308 - * 309 - * Returns 0 (false) if there is NOT an active EPO contidion, 310 - * and 1 (true) if there is an active EPO contition, which 311 - * locks all radios in one of the BLOCKED states. 312 - * 313 - * Can be called in atomic context. 314 - */ 315 - bool rfkill_is_epo_lock_active(void) 316 - { 317 - return rfkill_epo_lock_active; 318 - } 319 - EXPORT_SYMBOL_GPL(rfkill_is_epo_lock_active); 320 - 321 - /** 322 - * rfkill_get_global_state - returns global state for a type 323 - * @type: the type to get the global state of 324 - * 325 - * Returns the current global state for a given wireless 326 - * device type. 327 - */ 328 - enum rfkill_state rfkill_get_global_state(const enum rfkill_type type) 329 - { 330 - return rfkill_global_states[type].current_state; 331 - } 332 - EXPORT_SYMBOL_GPL(rfkill_get_global_state); 333 - 334 - /** 335 - * rfkill_force_state - Force the internal rfkill radio state 336 - * @rfkill: pointer to the rfkill class to modify. 337 - * @state: the current radio state the class should be forced to. 338 - * 339 - * This function updates the internal state of the radio cached 340 - * by the rfkill class. It should be used when the driver gets 341 - * a notification by the firmware/hardware of the current *real* 342 - * state of the radio rfkill switch. 343 - * 344 - * Devices which are subject to external changes on their rfkill 345 - * state (such as those caused by a hardware rfkill line) MUST 346 - * have their driver arrange to call rfkill_force_state() as soon 347 - * as possible after such a change. 348 - * 349 - * This function may not be called from an atomic context. 350 - */ 351 - int rfkill_force_state(struct rfkill *rfkill, enum rfkill_state state) 352 - { 353 - enum rfkill_state oldstate; 354 - 355 - BUG_ON(!rfkill); 356 - if (WARN((state >= RFKILL_STATE_MAX), 357 - KERN_WARNING 358 - "rfkill: illegal state %d passed as parameter " 359 - "to rfkill_force_state\n", state)) 360 - return -EINVAL; 361 - 362 - mutex_lock(&rfkill->mutex); 363 - 364 - oldstate = rfkill->state; 365 - rfkill->state = state; 366 - 367 - if (state != oldstate) 368 - rfkill_uevent(rfkill); 369 - 370 - mutex_unlock(&rfkill->mutex); 371 - rfkill_led_trigger(rfkill, rfkill->state); 372 - 373 - return 0; 374 - } 375 - EXPORT_SYMBOL(rfkill_force_state); 376 - 377 - static ssize_t rfkill_name_show(struct device *dev, 378 - struct device_attribute *attr, 379 - char *buf) 380 - { 381 - struct rfkill *rfkill = to_rfkill(dev); 382 - 383 - return sprintf(buf, "%s\n", rfkill->name); 384 - } 385 - 386 - static const char *rfkill_get_type_str(enum rfkill_type type) 387 - { 388 - switch (type) { 389 - case RFKILL_TYPE_WLAN: 390 - return "wlan"; 391 - case RFKILL_TYPE_BLUETOOTH: 392 - return "bluetooth"; 393 - case RFKILL_TYPE_UWB: 394 - return "ultrawideband"; 395 - case RFKILL_TYPE_WIMAX: 396 - return "wimax"; 397 - case RFKILL_TYPE_WWAN: 398 - return "wwan"; 399 - default: 400 - BUG(); 401 - } 402 - } 403 - 404 - static ssize_t rfkill_type_show(struct device *dev, 405 - struct device_attribute *attr, 406 - char *buf) 407 - { 408 - struct rfkill *rfkill = to_rfkill(dev); 409 - 410 - return sprintf(buf, "%s\n", rfkill_get_type_str(rfkill->type)); 411 - } 412 - 413 - static ssize_t rfkill_state_show(struct device *dev, 414 - struct device_attribute *attr, 415 - char *buf) 416 - { 417 - struct rfkill *rfkill = to_rfkill(dev); 418 - 419 - update_rfkill_state(rfkill); 420 - return sprintf(buf, "%d\n", rfkill->state); 421 - } 422 - 423 - static ssize_t rfkill_state_store(struct device *dev, 424 - struct device_attribute *attr, 425 - const char *buf, size_t count) 426 - { 427 - struct rfkill *rfkill = to_rfkill(dev); 428 - unsigned long state; 429 - int error; 430 - 431 - if (!capable(CAP_NET_ADMIN)) 432 - return -EPERM; 433 - 434 - error = strict_strtoul(buf, 0, &state); 435 - if (error) 436 - return error; 437 - 438 - /* RFKILL_STATE_HARD_BLOCKED is illegal here... */ 439 - if (state != RFKILL_STATE_UNBLOCKED && 440 - state != RFKILL_STATE_SOFT_BLOCKED) 441 - return -EINVAL; 442 - 443 - error = mutex_lock_killable(&rfkill->mutex); 444 - if (error) 445 - return error; 446 - 447 - if (!rfkill_epo_lock_active) 448 - error = rfkill_toggle_radio(rfkill, state, 0); 449 - else 450 - error = -EPERM; 451 - 452 - mutex_unlock(&rfkill->mutex); 453 - 454 - return error ? error : count; 455 - } 456 - 457 - static ssize_t rfkill_claim_show(struct device *dev, 458 - struct device_attribute *attr, 459 - char *buf) 460 - { 461 - return sprintf(buf, "%d\n", 0); 462 - } 463 - 464 - static ssize_t rfkill_claim_store(struct device *dev, 465 - struct device_attribute *attr, 466 - const char *buf, size_t count) 467 - { 468 - return -EOPNOTSUPP; 469 - } 470 - 471 - static struct device_attribute rfkill_dev_attrs[] = { 472 - __ATTR(name, S_IRUGO, rfkill_name_show, NULL), 473 - __ATTR(type, S_IRUGO, rfkill_type_show, NULL), 474 - __ATTR(state, S_IRUGO|S_IWUSR, rfkill_state_show, rfkill_state_store), 475 - __ATTR(claim, S_IRUGO|S_IWUSR, rfkill_claim_show, rfkill_claim_store), 476 - __ATTR_NULL 477 - }; 478 - 479 - static void rfkill_release(struct device *dev) 480 - { 481 - struct rfkill *rfkill = to_rfkill(dev); 482 - 483 - kfree(rfkill); 484 - module_put(THIS_MODULE); 485 - } 486 - 487 - #ifdef CONFIG_PM 488 - static int rfkill_suspend(struct device *dev, pm_message_t state) 489 - { 490 - struct rfkill *rfkill = to_rfkill(dev); 491 - 492 - /* mark class device as suspended */ 493 - if (dev->power.power_state.event != state.event) 494 - dev->power.power_state = state; 495 - 496 - /* store state for the resume handler */ 497 - rfkill->state_for_resume = rfkill->state; 498 - 499 - return 0; 500 - } 501 - 502 - static int rfkill_resume(struct device *dev) 503 - { 504 - struct rfkill *rfkill = to_rfkill(dev); 505 - enum rfkill_state newstate; 506 - 507 - if (dev->power.power_state.event != PM_EVENT_ON) { 508 - mutex_lock(&rfkill->mutex); 509 - 510 - dev->power.power_state.event = PM_EVENT_ON; 511 - 512 - /* 513 - * rfkill->state could have been modified before we got 514 - * called, and won't be updated by rfkill_toggle_radio() 515 - * in force mode. Sync it FIRST. 516 - */ 517 - if (rfkill->get_state && 518 - !rfkill->get_state(rfkill->data, &newstate)) 519 - rfkill->state = newstate; 520 - 521 - /* 522 - * If we are under EPO, kick transmitter offline, 523 - * otherwise restore to pre-suspend state. 524 - * 525 - * Issue a notification in any case 526 - */ 527 - rfkill_toggle_radio(rfkill, 528 - rfkill_epo_lock_active ? 529 - RFKILL_STATE_SOFT_BLOCKED : 530 - rfkill->state_for_resume, 531 - 1); 532 - 533 - mutex_unlock(&rfkill->mutex); 534 - rfkill_led_trigger(rfkill, rfkill->state); 535 - } 536 - 537 - return 0; 538 - } 539 - #else 540 - #define rfkill_suspend NULL 541 - #define rfkill_resume NULL 542 - #endif 543 - 544 - static int rfkill_dev_uevent(struct device *dev, struct kobj_uevent_env *env) 545 - { 546 - struct rfkill *rfkill = to_rfkill(dev); 547 - int error; 548 - 549 - error = add_uevent_var(env, "RFKILL_NAME=%s", rfkill->name); 550 - if (error) 551 - return error; 552 - error = add_uevent_var(env, "RFKILL_TYPE=%s", 553 - rfkill_get_type_str(rfkill->type)); 554 - if (error) 555 - return error; 556 - error = add_uevent_var(env, "RFKILL_STATE=%d", rfkill->state); 557 - return error; 558 - } 559 - 560 - static struct class rfkill_class = { 561 - .name = "rfkill", 562 - .dev_release = rfkill_release, 563 - .dev_attrs = rfkill_dev_attrs, 564 - .suspend = rfkill_suspend, 565 - .resume = rfkill_resume, 566 - .dev_uevent = rfkill_dev_uevent, 567 - }; 568 - 569 - static int rfkill_check_duplicity(const struct rfkill *rfkill) 570 - { 571 - struct rfkill *p; 572 - unsigned long seen[BITS_TO_LONGS(RFKILL_TYPE_MAX)]; 573 - 574 - memset(seen, 0, sizeof(seen)); 575 - 576 - list_for_each_entry(p, &rfkill_list, node) { 577 - if (WARN((p == rfkill), KERN_WARNING 578 - "rfkill: illegal attempt to register " 579 - "an already registered rfkill struct\n")) 580 - return -EEXIST; 581 - set_bit(p->type, seen); 582 - } 583 - 584 - /* 0: first switch of its kind */ 585 - return (test_bit(rfkill->type, seen)) ? 1 : 0; 586 - } 587 - 588 - static int rfkill_add_switch(struct rfkill *rfkill) 589 - { 590 - int error; 591 - 592 - mutex_lock(&rfkill_global_mutex); 593 - 594 - error = rfkill_check_duplicity(rfkill); 595 - if (error < 0) 596 - goto unlock_out; 597 - 598 - if (!error) { 599 - /* lock default after first use */ 600 - set_bit(rfkill->type, rfkill_states_lockdflt); 601 - rfkill_global_states[rfkill->type].current_state = 602 - rfkill_global_states[rfkill->type].default_state; 603 - } 604 - 605 - rfkill_toggle_radio(rfkill, 606 - rfkill_global_states[rfkill->type].current_state, 607 - 0); 608 - 609 - list_add_tail(&rfkill->node, &rfkill_list); 610 - 611 - error = 0; 612 - unlock_out: 613 - mutex_unlock(&rfkill_global_mutex); 614 - 615 - return error; 616 - } 617 - 618 - static void rfkill_remove_switch(struct rfkill *rfkill) 619 - { 620 - mutex_lock(&rfkill_global_mutex); 621 - list_del_init(&rfkill->node); 622 - mutex_unlock(&rfkill_global_mutex); 623 - 624 - mutex_lock(&rfkill->mutex); 625 - rfkill_toggle_radio(rfkill, RFKILL_STATE_SOFT_BLOCKED, 1); 626 - mutex_unlock(&rfkill->mutex); 627 - } 628 - 629 - /** 630 - * rfkill_allocate - allocate memory for rfkill structure. 631 - * @parent: device that has rf switch on it 632 - * @type: type of the switch (RFKILL_TYPE_*) 633 - * 634 - * This function should be called by the network driver when it needs 635 - * rfkill structure. Once the structure is allocated the driver should 636 - * finish its initialization by setting the name, private data, enable_radio 637 - * and disable_radio methods and then register it with rfkill_register(). 638 - * 639 - * NOTE: If registration fails the structure shoudl be freed by calling 640 - * rfkill_free() otherwise rfkill_unregister() should be used. 641 - */ 642 - struct rfkill * __must_check rfkill_allocate(struct device *parent, 643 - enum rfkill_type type) 644 - { 645 - struct rfkill *rfkill; 646 - struct device *dev; 647 - 648 - if (WARN((type >= RFKILL_TYPE_MAX), 649 - KERN_WARNING 650 - "rfkill: illegal type %d passed as parameter " 651 - "to rfkill_allocate\n", type)) 652 - return NULL; 653 - 654 - rfkill = kzalloc(sizeof(struct rfkill), GFP_KERNEL); 655 - if (!rfkill) 656 - return NULL; 657 - 658 - mutex_init(&rfkill->mutex); 659 - INIT_LIST_HEAD(&rfkill->node); 660 - rfkill->type = type; 661 - 662 - dev = &rfkill->dev; 663 - dev->class = &rfkill_class; 664 - dev->parent = parent; 665 - device_initialize(dev); 666 - 667 - __module_get(THIS_MODULE); 668 - 669 - return rfkill; 670 - } 671 - EXPORT_SYMBOL(rfkill_allocate); 672 - 673 - /** 674 - * rfkill_free - Mark rfkill structure for deletion 675 - * @rfkill: rfkill structure to be destroyed 676 - * 677 - * Decrements reference count of the rfkill structure so it is destroyed. 678 - * Note that rfkill_free() should _not_ be called after rfkill_unregister(). 679 - */ 680 - void rfkill_free(struct rfkill *rfkill) 681 - { 682 - if (rfkill) 683 - put_device(&rfkill->dev); 684 - } 685 - EXPORT_SYMBOL(rfkill_free); 686 - 687 - static void rfkill_led_trigger_register(struct rfkill *rfkill) 688 - { 689 - #ifdef CONFIG_RFKILL_LEDS 690 - int error; 691 - 692 - if (!rfkill->led_trigger.name) 693 - rfkill->led_trigger.name = dev_name(&rfkill->dev); 694 - if (!rfkill->led_trigger.activate) 695 - rfkill->led_trigger.activate = rfkill_led_trigger_activate; 696 - error = led_trigger_register(&rfkill->led_trigger); 697 - if (error) 698 - rfkill->led_trigger.name = NULL; 699 - #endif /* CONFIG_RFKILL_LEDS */ 700 - } 701 - 702 - static void rfkill_led_trigger_unregister(struct rfkill *rfkill) 703 - { 704 - #ifdef CONFIG_RFKILL_LEDS 705 - if (rfkill->led_trigger.name) { 706 - led_trigger_unregister(&rfkill->led_trigger); 707 - rfkill->led_trigger.name = NULL; 708 - } 709 - #endif 710 - } 711 - 712 - /** 713 - * rfkill_register - Register a rfkill structure. 714 - * @rfkill: rfkill structure to be registered 715 - * 716 - * This function should be called by the network driver when the rfkill 717 - * structure needs to be registered. Immediately from registration the 718 - * switch driver should be able to service calls to toggle_radio. 719 - */ 720 - int __must_check rfkill_register(struct rfkill *rfkill) 721 - { 722 - static atomic_t rfkill_no = ATOMIC_INIT(0); 723 - struct device *dev = &rfkill->dev; 724 - int error; 725 - 726 - if (WARN((!rfkill || !rfkill->toggle_radio || 727 - rfkill->type >= RFKILL_TYPE_MAX || 728 - rfkill->state >= RFKILL_STATE_MAX), 729 - KERN_WARNING 730 - "rfkill: attempt to register a " 731 - "badly initialized rfkill struct\n")) 732 - return -EINVAL; 733 - 734 - dev_set_name(dev, "rfkill%ld", (long)atomic_inc_return(&rfkill_no) - 1); 735 - 736 - rfkill_led_trigger_register(rfkill); 737 - 738 - error = rfkill_add_switch(rfkill); 739 - if (error) { 740 - rfkill_led_trigger_unregister(rfkill); 741 - return error; 742 - } 743 - 744 - error = device_add(dev); 745 - if (error) { 746 - rfkill_remove_switch(rfkill); 747 - rfkill_led_trigger_unregister(rfkill); 748 - return error; 749 - } 750 - 751 - return 0; 752 - } 753 - EXPORT_SYMBOL(rfkill_register); 754 - 755 - /** 756 - * rfkill_unregister - Unregister a rfkill structure. 757 - * @rfkill: rfkill structure to be unregistered 758 - * 759 - * This function should be called by the network driver during device 760 - * teardown to destroy rfkill structure. Note that rfkill_free() should 761 - * _not_ be called after rfkill_unregister(). 762 - */ 763 - void rfkill_unregister(struct rfkill *rfkill) 764 - { 765 - BUG_ON(!rfkill); 766 - device_del(&rfkill->dev); 767 - rfkill_remove_switch(rfkill); 768 - rfkill_led_trigger_unregister(rfkill); 769 - put_device(&rfkill->dev); 770 - } 771 - EXPORT_SYMBOL(rfkill_unregister); 772 - 773 - /** 774 - * rfkill_set_default - set initial value for a switch type 775 - * @type - the type of switch to set the default state of 776 - * @state - the new default state for that group of switches 777 - * 778 - * Sets the initial state rfkill should use for a given type. 779 - * The following initial states are allowed: RFKILL_STATE_SOFT_BLOCKED 780 - * and RFKILL_STATE_UNBLOCKED. 781 - * 782 - * This function is meant to be used by platform drivers for platforms 783 - * that can save switch state across power down/reboot. 784 - * 785 - * The default state for each switch type can be changed exactly once. 786 - * After a switch of that type is registered, the default state cannot 787 - * be changed anymore. This guards against multiple drivers it the 788 - * same platform trying to set the initial switch default state, which 789 - * is not allowed. 790 - * 791 - * Returns -EPERM if the state has already been set once or is in use, 792 - * so drivers likely want to either ignore or at most printk(KERN_NOTICE) 793 - * if this function returns -EPERM. 794 - * 795 - * Returns 0 if the new default state was set, or an error if it 796 - * could not be set. 797 - */ 798 - int rfkill_set_default(enum rfkill_type type, enum rfkill_state state) 799 - { 800 - int error; 801 - 802 - if (WARN((type >= RFKILL_TYPE_MAX || 803 - (state != RFKILL_STATE_SOFT_BLOCKED && 804 - state != RFKILL_STATE_UNBLOCKED)), 805 - KERN_WARNING 806 - "rfkill: illegal state %d or type %d passed as " 807 - "parameter to rfkill_set_default\n", state, type)) 808 - return -EINVAL; 809 - 810 - mutex_lock(&rfkill_global_mutex); 811 - 812 - if (!test_and_set_bit(type, rfkill_states_lockdflt)) { 813 - rfkill_global_states[type].default_state = state; 814 - rfkill_global_states[type].current_state = state; 815 - error = 0; 816 - } else 817 - error = -EPERM; 818 - 819 - mutex_unlock(&rfkill_global_mutex); 820 - return error; 821 - } 822 - EXPORT_SYMBOL_GPL(rfkill_set_default); 823 - 824 - /* 825 - * Rfkill module initialization/deinitialization. 826 - */ 827 - static int __init rfkill_init(void) 828 - { 829 - int error; 830 - int i; 831 - 832 - /* RFKILL_STATE_HARD_BLOCKED is illegal here... */ 833 - if (rfkill_default_state != RFKILL_STATE_SOFT_BLOCKED && 834 - rfkill_default_state != RFKILL_STATE_UNBLOCKED) 835 - return -EINVAL; 836 - 837 - for (i = 0; i < RFKILL_TYPE_MAX; i++) 838 - rfkill_global_states[i].default_state = rfkill_default_state; 839 - 840 - error = class_register(&rfkill_class); 841 - if (error) { 842 - printk(KERN_ERR "rfkill: unable to register rfkill class\n"); 843 - return error; 844 - } 845 - 846 - return 0; 847 - } 848 - 849 - static void __exit rfkill_exit(void) 850 - { 851 - class_unregister(&rfkill_class); 852 - } 853 - 854 - subsys_initcall(rfkill_init); 855 - module_exit(rfkill_exit);
+1 -14
net/wimax/Kconfig
··· 1 1 # 2 2 # WiMAX LAN device configuration 3 3 # 4 - # Note the ugly 'depends on' on WIMAX: that disallows RFKILL to be a 5 - # module if WIMAX is to be linked in. The WiMAX code is done in such a 6 - # way that it doesn't require and explicit dependency on RFKILL in 7 - # case an embedded system wants to rip it out. 8 - # 9 - # As well, enablement of the RFKILL code means we need the INPUT layer 10 - # support to inject events coming from hw rfkill switches. That 11 - # dependency could be killed if input.h provided appropriate means to 12 - # work when input is disabled. 13 - 14 - comment "WiMAX Wireless Broadband support requires CONFIG_INPUT enabled" 15 - depends on INPUT = n && RFKILL != n 16 4 17 5 menuconfig WIMAX 18 6 tristate "WiMAX Wireless Broadband support" 19 - depends on (y && RFKILL != m) || m 20 - depends on (INPUT && RFKILL != n) || RFKILL = n 7 + depends on RFKILL || !RFKILL 21 8 help 22 9 23 10 Select to configure support for devices that provide
+26 -97
net/wimax/op-rfkill.c
··· 29 29 * A non-polled generic rfkill device is embedded into the WiMAX 30 30 * subsystem's representation of a device. 31 31 * 32 - * FIXME: Need polled support? use a timer or add the implementation 33 - * to the stack. 32 + * FIXME: Need polled support? Let drivers provide a poll routine 33 + * and hand it to rfkill ops then? 34 34 * 35 35 * All device drivers have to do is after wimax_dev_init(), call 36 36 * wimax_report_rfkill_hw() and wimax_report_rfkill_sw() to update ··· 43 43 * wimax_rfkill() Kernel calling wimax_rfkill() 44 44 * __wimax_rf_toggle_radio() 45 45 * 46 - * wimax_rfkill_toggle_radio() RF-Kill subsytem calling 46 + * wimax_rfkill_set_radio_block() RF-Kill subsytem calling 47 47 * __wimax_rf_toggle_radio() 48 48 * 49 49 * __wimax_rf_toggle_radio() ··· 65 65 #include <linux/wimax.h> 66 66 #include <linux/security.h> 67 67 #include <linux/rfkill.h> 68 - #include <linux/input.h> 69 68 #include "wimax-internal.h" 70 69 71 70 #define D_SUBMODULE op_rfkill 72 71 #include "debug-levels.h" 73 - 74 - #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE) 75 - 76 72 77 73 /** 78 74 * wimax_report_rfkill_hw - Reports changes in the hardware RF switch ··· 95 99 int result; 96 100 struct device *dev = wimax_dev_to_dev(wimax_dev); 97 101 enum wimax_st wimax_state; 98 - enum rfkill_state rfkill_state; 99 102 100 103 d_fnstart(3, dev, "(wimax_dev %p state %u)\n", wimax_dev, state); 101 104 BUG_ON(state == WIMAX_RF_QUERY); ··· 107 112 108 113 if (state != wimax_dev->rf_hw) { 109 114 wimax_dev->rf_hw = state; 110 - rfkill_state = state == WIMAX_RF_ON ? 111 - RFKILL_STATE_UNBLOCKED : RFKILL_STATE_SOFT_BLOCKED; 112 115 if (wimax_dev->rf_hw == WIMAX_RF_ON 113 116 && wimax_dev->rf_sw == WIMAX_RF_ON) 114 117 wimax_state = WIMAX_ST_READY; 115 118 else 116 119 wimax_state = WIMAX_ST_RADIO_OFF; 120 + 121 + rfkill_set_hw_state(wimax_dev->rfkill, state == WIMAX_RF_OFF); 122 + 117 123 __wimax_state_change(wimax_dev, wimax_state); 118 - input_report_key(wimax_dev->rfkill_input, KEY_WIMAX, 119 - rfkill_state); 120 124 } 121 125 error_not_ready: 122 126 mutex_unlock(&wimax_dev->mutex); ··· 168 174 else 169 175 wimax_state = WIMAX_ST_RADIO_OFF; 170 176 __wimax_state_change(wimax_dev, wimax_state); 177 + rfkill_set_sw_state(wimax_dev->rfkill, state == WIMAX_RF_OFF); 171 178 } 172 179 error_not_ready: 173 180 mutex_unlock(&wimax_dev->mutex); ··· 244 249 * 245 250 * NOTE: This call will block until the operation is completed. 246 251 */ 247 - static 248 - int wimax_rfkill_toggle_radio(void *data, enum rfkill_state state) 252 + static int wimax_rfkill_set_radio_block(void *data, bool blocked) 249 253 { 250 254 int result; 251 255 struct wimax_dev *wimax_dev = data; 252 256 struct device *dev = wimax_dev_to_dev(wimax_dev); 253 257 enum wimax_rf_state rf_state; 254 258 255 - d_fnstart(3, dev, "(wimax_dev %p state %u)\n", wimax_dev, state); 256 - switch (state) { 257 - case RFKILL_STATE_SOFT_BLOCKED: 259 + d_fnstart(3, dev, "(wimax_dev %p blocked %u)\n", wimax_dev, blocked); 260 + rf_state = WIMAX_RF_ON; 261 + if (blocked) 258 262 rf_state = WIMAX_RF_OFF; 259 - break; 260 - case RFKILL_STATE_UNBLOCKED: 261 - rf_state = WIMAX_RF_ON; 262 - break; 263 - default: 264 - BUG(); 265 - } 266 263 mutex_lock(&wimax_dev->mutex); 267 264 if (wimax_dev->state <= __WIMAX_ST_QUIESCING) 268 - result = 0; /* just pretend it didn't happen */ 265 + result = 0; 269 266 else 270 267 result = __wimax_rf_toggle_radio(wimax_dev, rf_state); 271 268 mutex_unlock(&wimax_dev->mutex); 272 - d_fnend(3, dev, "(wimax_dev %p state %u) = %d\n", 273 - wimax_dev, state, result); 269 + d_fnend(3, dev, "(wimax_dev %p blocked %u) = %d\n", 270 + wimax_dev, blocked, result); 274 271 return result; 275 272 } 276 273 274 + static const struct rfkill_ops wimax_rfkill_ops = { 275 + .set_block = wimax_rfkill_set_radio_block, 276 + }; 277 277 278 278 /** 279 279 * wimax_rfkill - Set the software RF switch state for a WiMAX device ··· 312 322 result = __wimax_rf_toggle_radio(wimax_dev, state); 313 323 if (result < 0) 314 324 goto error; 325 + rfkill_set_sw_state(wimax_dev->rfkill, state == WIMAX_RF_OFF); 315 326 break; 316 327 case WIMAX_RF_QUERY: 317 328 break; ··· 340 349 { 341 350 int result; 342 351 struct rfkill *rfkill; 343 - struct input_dev *input_dev; 344 352 struct device *dev = wimax_dev_to_dev(wimax_dev); 345 353 346 354 d_fnstart(3, dev, "(wimax_dev %p)\n", wimax_dev); 347 355 /* Initialize RF Kill */ 348 356 result = -ENOMEM; 349 - rfkill = rfkill_allocate(dev, RFKILL_TYPE_WIMAX); 357 + rfkill = rfkill_alloc(wimax_dev->name, dev, RFKILL_TYPE_WIMAX, 358 + &wimax_rfkill_ops, wimax_dev); 350 359 if (rfkill == NULL) 351 360 goto error_rfkill_allocate; 361 + 362 + d_printf(1, dev, "rfkill %p\n", rfkill); 363 + 352 364 wimax_dev->rfkill = rfkill; 353 365 354 - rfkill->name = wimax_dev->name; 355 - rfkill->state = RFKILL_STATE_UNBLOCKED; 356 - rfkill->data = wimax_dev; 357 - rfkill->toggle_radio = wimax_rfkill_toggle_radio; 358 - 359 - /* Initialize the input device for the hw key */ 360 - input_dev = input_allocate_device(); 361 - if (input_dev == NULL) 362 - goto error_input_allocate; 363 - wimax_dev->rfkill_input = input_dev; 364 - d_printf(1, dev, "rfkill %p input %p\n", rfkill, input_dev); 365 - 366 - input_dev->name = wimax_dev->name; 367 - /* FIXME: get a real device bus ID and stuff? do we care? */ 368 - input_dev->id.bustype = BUS_HOST; 369 - input_dev->id.vendor = 0xffff; 370 - input_dev->evbit[0] = BIT(EV_KEY); 371 - set_bit(KEY_WIMAX, input_dev->keybit); 372 - 373 - /* Register both */ 374 - result = input_register_device(wimax_dev->rfkill_input); 375 - if (result < 0) 376 - goto error_input_register; 377 366 result = rfkill_register(wimax_dev->rfkill); 378 367 if (result < 0) 379 368 goto error_rfkill_register; ··· 365 394 d_fnend(3, dev, "(wimax_dev %p) = 0\n", wimax_dev); 366 395 return 0; 367 396 368 - /* if rfkill_register() suceeds, can't use rfkill_free() any 369 - * more, only rfkill_unregister() [it owns the refcount]; with 370 - * the input device we have the same issue--hence the if. */ 371 397 error_rfkill_register: 372 - input_unregister_device(wimax_dev->rfkill_input); 373 - wimax_dev->rfkill_input = NULL; 374 - error_input_register: 375 - if (wimax_dev->rfkill_input) 376 - input_free_device(wimax_dev->rfkill_input); 377 - error_input_allocate: 378 - rfkill_free(wimax_dev->rfkill); 398 + rfkill_destroy(wimax_dev->rfkill); 379 399 error_rfkill_allocate: 380 400 d_fnend(3, dev, "(wimax_dev %p) = %d\n", wimax_dev, result); 381 401 return result; ··· 385 423 { 386 424 struct device *dev = wimax_dev_to_dev(wimax_dev); 387 425 d_fnstart(3, dev, "(wimax_dev %p)\n", wimax_dev); 388 - rfkill_unregister(wimax_dev->rfkill); /* frees */ 389 - input_unregister_device(wimax_dev->rfkill_input); 426 + rfkill_unregister(wimax_dev->rfkill); 427 + rfkill_destroy(wimax_dev->rfkill); 390 428 d_fnend(3, dev, "(wimax_dev %p)\n", wimax_dev); 391 429 } 392 - 393 - 394 - #else /* #ifdef CONFIG_RFKILL */ 395 - 396 - void wimax_report_rfkill_hw(struct wimax_dev *wimax_dev, 397 - enum wimax_rf_state state) 398 - { 399 - } 400 - EXPORT_SYMBOL_GPL(wimax_report_rfkill_hw); 401 - 402 - void wimax_report_rfkill_sw(struct wimax_dev *wimax_dev, 403 - enum wimax_rf_state state) 404 - { 405 - } 406 - EXPORT_SYMBOL_GPL(wimax_report_rfkill_sw); 407 - 408 - int wimax_rfkill(struct wimax_dev *wimax_dev, 409 - enum wimax_rf_state state) 410 - { 411 - return WIMAX_RF_ON << 1 | WIMAX_RF_ON; 412 - } 413 - EXPORT_SYMBOL_GPL(wimax_rfkill); 414 - 415 - int wimax_rfkill_add(struct wimax_dev *wimax_dev) 416 - { 417 - return 0; 418 - } 419 - 420 - void wimax_rfkill_rm(struct wimax_dev *wimax_dev) 421 - { 422 - } 423 - 424 - #endif /* #ifdef CONFIG_RFKILL */ 425 430 426 431 427 432 /*
+2 -1
net/wireless/Kconfig
··· 1 1 config CFG80211 2 - tristate "Improved wireless configuration API" 2 + tristate "Improved wireless configuration API" 3 + depends on RFKILL || !RFKILL 3 4 4 5 config CFG80211_REG_DEBUG 5 6 bool "cfg80211 regulatory debugging"
+94 -3
net/wireless/core.c
··· 12 12 #include <linux/debugfs.h> 13 13 #include <linux/notifier.h> 14 14 #include <linux/device.h> 15 + #include <linux/rtnetlink.h> 15 16 #include <net/genetlink.h> 16 17 #include <net/cfg80211.h> 17 18 #include "nl80211.h" ··· 228 227 return 0; 229 228 } 230 229 230 + static void cfg80211_rfkill_poll(struct rfkill *rfkill, void *data) 231 + { 232 + struct cfg80211_registered_device *drv = data; 233 + 234 + drv->ops->rfkill_poll(&drv->wiphy); 235 + } 236 + 237 + static int cfg80211_rfkill_set_block(void *data, bool blocked) 238 + { 239 + struct cfg80211_registered_device *drv = data; 240 + struct wireless_dev *wdev; 241 + 242 + if (!blocked) 243 + return 0; 244 + 245 + rtnl_lock(); 246 + mutex_lock(&drv->devlist_mtx); 247 + 248 + list_for_each_entry(wdev, &drv->netdev_list, list) 249 + dev_close(wdev->netdev); 250 + 251 + mutex_unlock(&drv->devlist_mtx); 252 + rtnl_unlock(); 253 + 254 + return 0; 255 + } 256 + 257 + static void cfg80211_rfkill_sync_work(struct work_struct *work) 258 + { 259 + struct cfg80211_registered_device *drv; 260 + 261 + drv = container_of(work, struct cfg80211_registered_device, rfkill_sync); 262 + cfg80211_rfkill_set_block(drv, rfkill_blocked(drv->rfkill)); 263 + } 264 + 231 265 /* exported functions */ 232 266 233 267 struct wiphy *wiphy_new(const struct cfg80211_ops *ops, int sizeof_priv) ··· 309 273 device_initialize(&drv->wiphy.dev); 310 274 drv->wiphy.dev.class = &ieee80211_class; 311 275 drv->wiphy.dev.platform_data = drv; 276 + 277 + drv->rfkill_ops.set_block = cfg80211_rfkill_set_block; 278 + drv->rfkill = rfkill_alloc(dev_name(&drv->wiphy.dev), 279 + &drv->wiphy.dev, RFKILL_TYPE_WLAN, 280 + &drv->rfkill_ops, drv); 281 + 282 + if (!drv->rfkill) { 283 + kfree(drv); 284 + return NULL; 285 + } 286 + 287 + INIT_WORK(&drv->rfkill_sync, cfg80211_rfkill_sync_work); 312 288 313 289 /* 314 290 * Initialize wiphy parameters to IEEE 802.11 MIB default values. ··· 404 356 if (res) 405 357 goto out_unlock; 406 358 359 + res = rfkill_register(drv->rfkill); 360 + if (res) 361 + goto out_rm_dev; 362 + 407 363 list_add(&drv->list, &cfg80211_drv_list); 408 364 409 365 /* add to debugfs */ ··· 431 379 cfg80211_debugfs_drv_add(drv); 432 380 433 381 res = 0; 434 - out_unlock: 382 + goto out_unlock; 383 + 384 + out_rm_dev: 385 + device_del(&drv->wiphy.dev); 386 + out_unlock: 435 387 mutex_unlock(&cfg80211_mutex); 436 388 return res; 437 389 } 438 390 EXPORT_SYMBOL(wiphy_register); 439 391 392 + void wiphy_rfkill_start_polling(struct wiphy *wiphy) 393 + { 394 + struct cfg80211_registered_device *drv = wiphy_to_dev(wiphy); 395 + 396 + if (!drv->ops->rfkill_poll) 397 + return; 398 + drv->rfkill_ops.poll = cfg80211_rfkill_poll; 399 + rfkill_resume_polling(drv->rfkill); 400 + } 401 + EXPORT_SYMBOL(wiphy_rfkill_start_polling); 402 + 403 + void wiphy_rfkill_stop_polling(struct wiphy *wiphy) 404 + { 405 + struct cfg80211_registered_device *drv = wiphy_to_dev(wiphy); 406 + 407 + rfkill_pause_polling(drv->rfkill); 408 + } 409 + EXPORT_SYMBOL(wiphy_rfkill_stop_polling); 410 + 440 411 void wiphy_unregister(struct wiphy *wiphy) 441 412 { 442 413 struct cfg80211_registered_device *drv = wiphy_to_dev(wiphy); 414 + 415 + rfkill_unregister(drv->rfkill); 443 416 444 417 /* protect the device list */ 445 418 mutex_lock(&cfg80211_mutex); ··· 502 425 void cfg80211_dev_free(struct cfg80211_registered_device *drv) 503 426 { 504 427 struct cfg80211_internal_bss *scan, *tmp; 428 + rfkill_destroy(drv->rfkill); 505 429 mutex_destroy(&drv->mtx); 506 430 mutex_destroy(&drv->devlist_mtx); 507 431 list_for_each_entry_safe(scan, tmp, &drv->bss_list, list) ··· 516 438 } 517 439 EXPORT_SYMBOL(wiphy_free); 518 440 441 + void wiphy_rfkill_set_hw_state(struct wiphy *wiphy, bool blocked) 442 + { 443 + struct cfg80211_registered_device *drv = wiphy_to_dev(wiphy); 444 + 445 + if (rfkill_set_hw_state(drv->rfkill, blocked)) 446 + schedule_work(&drv->rfkill_sync); 447 + } 448 + EXPORT_SYMBOL(wiphy_rfkill_set_hw_state); 449 + 519 450 static int cfg80211_netdev_notifier_call(struct notifier_block * nb, 520 451 unsigned long state, 521 452 void *ndev) ··· 533 446 struct cfg80211_registered_device *rdev; 534 447 535 448 if (!dev->ieee80211_ptr) 536 - return 0; 449 + return NOTIFY_DONE; 537 450 538 451 rdev = wiphy_to_dev(dev->ieee80211_ptr->wiphy); 539 452 ··· 579 492 } 580 493 mutex_unlock(&rdev->devlist_mtx); 581 494 break; 495 + case NETDEV_PRE_UP: 496 + if (rfkill_blocked(rdev->rfkill)) 497 + return notifier_from_errno(-ERFKILL); 498 + break; 582 499 } 583 500 584 - return 0; 501 + return NOTIFY_DONE; 585 502 } 586 503 587 504 static struct notifier_block cfg80211_netdev_notifier = {
+7
net/wireless/core.h
··· 11 11 #include <linux/kref.h> 12 12 #include <linux/rbtree.h> 13 13 #include <linux/debugfs.h> 14 + #include <linux/rfkill.h> 15 + #include <linux/workqueue.h> 14 16 #include <net/genetlink.h> 15 17 #include <net/cfg80211.h> 16 18 #include "reg.h" ··· 25 23 * to avoid the deregister call to proceed while 26 24 * any call is in progress */ 27 25 struct mutex mtx; 26 + 27 + /* rfkill support */ 28 + struct rfkill_ops rfkill_ops; 29 + struct rfkill *rfkill; 30 + struct work_struct rfkill_sync; 28 31 29 32 /* ISO / IEC 3166 alpha2 for which this device is receiving 30 33 * country IEs on, this can help disregard country IEs from APs
+50 -7
net/wireless/nl80211.c
··· 1687 1687 if (err) 1688 1688 goto out_rtnl; 1689 1689 1690 + if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && 1691 + dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN) { 1692 + err = -EINVAL; 1693 + goto out; 1694 + } 1695 + 1690 1696 err = get_vlan(info->attrs[NL80211_ATTR_STA_VLAN], drv, &params.vlan); 1691 1697 if (err) 1692 1698 goto out; ··· 1744 1738 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); 1745 1739 params.listen_interval = 1746 1740 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); 1741 + 1747 1742 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); 1743 + if (!params.aid || params.aid > IEEE80211_MAX_AID) 1744 + return -EINVAL; 1745 + 1748 1746 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) 1749 1747 params.ht_capa = 1750 1748 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); ··· 3569 3559 genlmsg_multicast(msg, 0, nl80211_config_mcgrp.id, GFP_KERNEL); 3570 3560 } 3571 3561 3562 + static int nl80211_add_scan_req(struct sk_buff *msg, 3563 + struct cfg80211_registered_device *rdev) 3564 + { 3565 + struct cfg80211_scan_request *req = rdev->scan_req; 3566 + struct nlattr *nest; 3567 + int i; 3568 + 3569 + if (WARN_ON(!req)) 3570 + return 0; 3571 + 3572 + nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); 3573 + if (!nest) 3574 + goto nla_put_failure; 3575 + for (i = 0; i < req->n_ssids; i++) 3576 + NLA_PUT(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid); 3577 + nla_nest_end(msg, nest); 3578 + 3579 + nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); 3580 + if (!nest) 3581 + goto nla_put_failure; 3582 + for (i = 0; i < req->n_channels; i++) 3583 + NLA_PUT_U32(msg, i, req->channels[i]->center_freq); 3584 + nla_nest_end(msg, nest); 3585 + 3586 + if (req->ie) 3587 + NLA_PUT(msg, NL80211_ATTR_IE, req->ie_len, req->ie); 3588 + 3589 + return 0; 3590 + nla_put_failure: 3591 + return -ENOBUFS; 3592 + } 3593 + 3572 3594 static int nl80211_send_scan_donemsg(struct sk_buff *msg, 3573 - struct cfg80211_registered_device *rdev, 3574 - struct net_device *netdev, 3575 - u32 pid, u32 seq, int flags, 3576 - u32 cmd) 3595 + struct cfg80211_registered_device *rdev, 3596 + struct net_device *netdev, 3597 + u32 pid, u32 seq, int flags, 3598 + u32 cmd) 3577 3599 { 3578 3600 void *hdr; 3579 3601 ··· 3616 3574 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); 3617 3575 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); 3618 3576 3619 - /* XXX: we should probably bounce back the request? */ 3577 + /* ignore errors and send incomplete event anyway */ 3578 + nl80211_add_scan_req(msg, rdev); 3620 3579 3621 3580 return genlmsg_end(msg, hdr); 3622 3581 ··· 3871 3828 struct sk_buff *msg; 3872 3829 void *hdr; 3873 3830 3874 - msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 3831 + msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); 3875 3832 if (!msg) 3876 3833 return; 3877 3834 ··· 3895 3852 return; 3896 3853 } 3897 3854 3898 - genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, GFP_KERNEL); 3855 + genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, GFP_ATOMIC); 3899 3856 return; 3900 3857 3901 3858 nla_put_failure:
+7 -1
net/wireless/reg.c
··· 2171 2171 * the country IE rd with what CRDA believes that country should have 2172 2172 */ 2173 2173 2174 - BUG_ON(!country_ie_regdomain); 2174 + /* 2175 + * Userspace could have sent two replies with only 2176 + * one kernel request. By the second reply we would have 2177 + * already processed and consumed the country_ie_regdomain. 2178 + */ 2179 + if (!country_ie_regdomain) 2180 + return -EALREADY; 2175 2181 BUG_ON(rd == country_ie_regdomain); 2176 2182 2177 2183 /*
+2 -1
net/wireless/scan.c
··· 29 29 goto out; 30 30 31 31 WARN_ON(request != wiphy_to_dev(request->wiphy)->scan_req); 32 - wiphy_to_dev(request->wiphy)->scan_req = NULL; 33 32 34 33 if (aborted) 35 34 nl80211_send_scan_aborted(wiphy_to_dev(request->wiphy), dev); 36 35 else 37 36 nl80211_send_scan_done(wiphy_to_dev(request->wiphy), dev); 37 + 38 + wiphy_to_dev(request->wiphy)->scan_req = NULL; 38 39 39 40 #ifdef CONFIG_WIRELESS_EXT 40 41 if (!aborted) {
+6 -7
net/wireless/util.c
··· 157 157 params->cipher != WLAN_CIPHER_SUITE_WEP104) 158 158 return -EINVAL; 159 159 160 - /* TODO: add definitions for the lengths to linux/ieee80211.h */ 161 160 switch (params->cipher) { 162 161 case WLAN_CIPHER_SUITE_WEP40: 163 - if (params->key_len != 5) 162 + if (params->key_len != WLAN_KEY_LEN_WEP40) 164 163 return -EINVAL; 165 164 break; 166 165 case WLAN_CIPHER_SUITE_TKIP: 167 - if (params->key_len != 32) 166 + if (params->key_len != WLAN_KEY_LEN_TKIP) 168 167 return -EINVAL; 169 168 break; 170 169 case WLAN_CIPHER_SUITE_CCMP: 171 - if (params->key_len != 16) 170 + if (params->key_len != WLAN_KEY_LEN_CCMP) 172 171 return -EINVAL; 173 172 break; 174 173 case WLAN_CIPHER_SUITE_WEP104: 175 - if (params->key_len != 13) 174 + if (params->key_len != WLAN_KEY_LEN_WEP104) 176 175 return -EINVAL; 177 176 break; 178 177 case WLAN_CIPHER_SUITE_AES_CMAC: 179 - if (params->key_len != 16) 178 + if (params->key_len != WLAN_KEY_LEN_AES_CMAC) 180 179 return -EINVAL; 181 180 break; 182 181 default: ··· 258 259 } 259 260 EXPORT_SYMBOL(ieee80211_get_hdrlen_from_skb); 260 261 261 - int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr) 262 + static int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr) 262 263 { 263 264 int ae = meshhdr->flags & MESH_FLAGS_AE; 264 265 /* 7.1.3.5a.2 */
+83
net/wireless/wext-compat.c
··· 744 744 return err; 745 745 } 746 746 EXPORT_SYMBOL_GPL(cfg80211_wext_giwencode); 747 + 748 + int cfg80211_wext_siwtxpower(struct net_device *dev, 749 + struct iw_request_info *info, 750 + union iwreq_data *data, char *extra) 751 + { 752 + struct wireless_dev *wdev = dev->ieee80211_ptr; 753 + struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); 754 + enum tx_power_setting type; 755 + int dbm = 0; 756 + 757 + if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM) 758 + return -EINVAL; 759 + if (data->txpower.flags & IW_TXPOW_RANGE) 760 + return -EINVAL; 761 + 762 + if (!rdev->ops->set_tx_power) 763 + return -EOPNOTSUPP; 764 + 765 + /* only change when not disabling */ 766 + if (!data->txpower.disabled) { 767 + rfkill_set_sw_state(rdev->rfkill, false); 768 + 769 + if (data->txpower.fixed) { 770 + /* 771 + * wext doesn't support negative values, see 772 + * below where it's for automatic 773 + */ 774 + if (data->txpower.value < 0) 775 + return -EINVAL; 776 + dbm = data->txpower.value; 777 + type = TX_POWER_FIXED; 778 + /* TODO: do regulatory check! */ 779 + } else { 780 + /* 781 + * Automatic power level setting, max being the value 782 + * passed in from userland. 783 + */ 784 + if (data->txpower.value < 0) { 785 + type = TX_POWER_AUTOMATIC; 786 + } else { 787 + dbm = data->txpower.value; 788 + type = TX_POWER_LIMITED; 789 + } 790 + } 791 + } else { 792 + rfkill_set_sw_state(rdev->rfkill, true); 793 + schedule_work(&rdev->rfkill_sync); 794 + return 0; 795 + } 796 + 797 + return rdev->ops->set_tx_power(wdev->wiphy, type, dbm);; 798 + } 799 + EXPORT_SYMBOL_GPL(cfg80211_wext_siwtxpower); 800 + 801 + int cfg80211_wext_giwtxpower(struct net_device *dev, 802 + struct iw_request_info *info, 803 + union iwreq_data *data, char *extra) 804 + { 805 + struct wireless_dev *wdev = dev->ieee80211_ptr; 806 + struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); 807 + int err, val; 808 + 809 + if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM) 810 + return -EINVAL; 811 + if (data->txpower.flags & IW_TXPOW_RANGE) 812 + return -EINVAL; 813 + 814 + if (!rdev->ops->get_tx_power) 815 + return -EOPNOTSUPP; 816 + 817 + err = rdev->ops->get_tx_power(wdev->wiphy, &val); 818 + if (err) 819 + return err; 820 + 821 + /* well... oh well */ 822 + data->txpower.fixed = 1; 823 + data->txpower.disabled = rfkill_blocked(rdev->rfkill); 824 + data->txpower.value = val; 825 + data->txpower.flags = IW_TXPOW_DBM; 826 + 827 + return 0; 828 + } 829 + EXPORT_SYMBOL_GPL(cfg80211_wext_giwtxpower);