linux/net/rfkill/rfkill.c
<<
>>
Prefs
   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
  34MODULE_AUTHOR("Ivo van Doorn <IvDoorn@gmail.com>");
  35MODULE_VERSION("1.0");
  36MODULE_DESCRIPTION("RF switch support");
  37MODULE_LICENSE("GPL");
  38
  39static LIST_HEAD(rfkill_list);  /* list of registered rf switches */
  40static DEFINE_MUTEX(rfkill_mutex);
  41
  42static unsigned int rfkill_default_state = RFKILL_STATE_UNBLOCKED;
  43module_param_named(default_state, rfkill_default_state, uint, 0444);
  44MODULE_PARM_DESC(default_state,
  45                 "Default initial state for all radio types, 0 = radio off");
  46
  47static enum rfkill_state rfkill_states[RFKILL_TYPE_MAX];
  48
  49static BLOCKING_NOTIFIER_HEAD(rfkill_notifier_list);
  50
  51
  52/**
  53 * register_rfkill_notifier - Add notifier to rfkill notifier chain
  54 * @nb: pointer to the new entry to add to the chain
  55 *
  56 * See blocking_notifier_chain_register() for return value and further
  57 * observations.
  58 *
  59 * Adds a notifier to the rfkill notifier chain.  The chain will be
  60 * called with a pointer to the relevant rfkill structure as a parameter,
  61 * refer to include/linux/rfkill.h for the possible events.
  62 *
  63 * Notifiers added to this chain are to always return NOTIFY_DONE.  This
  64 * chain is a blocking notifier chain: notifiers can sleep.
  65 *
  66 * Calls to this chain may have been done through a workqueue.  One must
  67 * assume unordered asynchronous behaviour, there is no way to know if
  68 * actions related to the event that generated the notification have been
  69 * carried out already.
  70 */
  71int register_rfkill_notifier(struct notifier_block *nb)
  72{
  73        return blocking_notifier_chain_register(&rfkill_notifier_list, nb);
  74}
  75EXPORT_SYMBOL_GPL(register_rfkill_notifier);
  76
  77/**
  78 * unregister_rfkill_notifier - remove notifier from rfkill notifier chain
  79 * @nb: pointer to the entry to remove from the chain
  80 *
  81 * See blocking_notifier_chain_unregister() for return value and further
  82 * observations.
  83 *
  84 * Removes a notifier from the rfkill notifier chain.
  85 */
  86int unregister_rfkill_notifier(struct notifier_block *nb)
  87{
  88        return blocking_notifier_chain_unregister(&rfkill_notifier_list, nb);
  89}
  90EXPORT_SYMBOL_GPL(unregister_rfkill_notifier);
  91
  92
  93static void rfkill_led_trigger(struct rfkill *rfkill,
  94                               enum rfkill_state state)
  95{
  96#ifdef CONFIG_RFKILL_LEDS
  97        struct led_trigger *led = &rfkill->led_trigger;
  98
  99        if (!led->name)
 100                return;
 101        if (state != RFKILL_STATE_UNBLOCKED)
 102                led_trigger_event(led, LED_OFF);
 103        else
 104                led_trigger_event(led, LED_FULL);
 105#endif /* CONFIG_RFKILL_LEDS */
 106}
 107
 108#ifdef CONFIG_RFKILL_LEDS
 109static void rfkill_led_trigger_activate(struct led_classdev *led)
 110{
 111        struct rfkill *rfkill = container_of(led->trigger,
 112                        struct rfkill, led_trigger);
 113
 114        rfkill_led_trigger(rfkill, rfkill->state);
 115}
 116#endif /* CONFIG_RFKILL_LEDS */
 117
 118static void notify_rfkill_state_change(struct rfkill *rfkill)
 119{
 120        rfkill_led_trigger(rfkill, rfkill->state);
 121        blocking_notifier_call_chain(&rfkill_notifier_list,
 122                        RFKILL_STATE_CHANGED,
 123                        rfkill);
 124}
 125
 126static void update_rfkill_state(struct rfkill *rfkill)
 127{
 128        enum rfkill_state newstate, oldstate;
 129
 130        if (rfkill->get_state) {
 131                mutex_lock(&rfkill->mutex);
 132                if (!rfkill->get_state(rfkill->data, &newstate)) {
 133                        oldstate = rfkill->state;
 134                        rfkill->state = newstate;
 135                        if (oldstate != newstate)
 136                                notify_rfkill_state_change(rfkill);
 137                }
 138                mutex_unlock(&rfkill->mutex);
 139        }
 140}
 141
 142/**
 143 * rfkill_toggle_radio - wrapper for toggle_radio hook
 144 * @rfkill: the rfkill struct to use
 145 * @force: calls toggle_radio even if cache says it is not needed,
 146 *      and also makes sure notifications of the state will be
 147 *      sent even if it didn't change
 148 * @state: the new state to call toggle_radio() with
 149 *
 150 * Calls rfkill->toggle_radio, enforcing the API for toggle_radio
 151 * calls and handling all the red tape such as issuing notifications
 152 * if the call is successful.
 153 *
 154 * Suspended devices are not touched at all, and -EAGAIN is returned.
 155 *
 156 * Note that the @force parameter cannot override a (possibly cached)
 157 * state of RFKILL_STATE_HARD_BLOCKED.  Any device making use of
 158 * RFKILL_STATE_HARD_BLOCKED implements either get_state() or
 159 * rfkill_force_state(), so the cache either is bypassed or valid.
 160 *
 161 * Note that we do call toggle_radio for RFKILL_STATE_SOFT_BLOCKED
 162 * even if the radio is in RFKILL_STATE_HARD_BLOCKED state, so as to
 163 * give the driver a hint that it should double-BLOCK the transmitter.
 164 *
 165 * Caller must have acquired rfkill->mutex.
 166 */
 167static int rfkill_toggle_radio(struct rfkill *rfkill,
 168                                enum rfkill_state state,
 169                                int force)
 170{
 171        int retval = 0;
 172        enum rfkill_state oldstate, newstate;
 173
 174        if (unlikely(rfkill->dev.power.power_state.event & PM_EVENT_SLEEP))
 175                return -EBUSY;
 176
 177        oldstate = rfkill->state;
 178
 179        if (rfkill->get_state && !force &&
 180            !rfkill->get_state(rfkill->data, &newstate))
 181                rfkill->state = newstate;
 182
 183        switch (state) {
 184        case RFKILL_STATE_HARD_BLOCKED:
 185                /* typically happens when refreshing hardware state,
 186                 * such as on resume */
 187                state = RFKILL_STATE_SOFT_BLOCKED;
 188                break;
 189        case RFKILL_STATE_UNBLOCKED:
 190                /* force can't override this, only rfkill_force_state() can */
 191                if (rfkill->state == RFKILL_STATE_HARD_BLOCKED)
 192                        return -EPERM;
 193                break;
 194        case RFKILL_STATE_SOFT_BLOCKED:
 195                /* nothing to do, we want to give drivers the hint to double
 196                 * BLOCK even a transmitter that is already in state
 197                 * RFKILL_STATE_HARD_BLOCKED */
 198                break;
 199        }
 200
 201        if (force || state != rfkill->state) {
 202                retval = rfkill->toggle_radio(rfkill->data, state);
 203                /* never allow a HARD->SOFT downgrade! */
 204                if (!retval && rfkill->state != RFKILL_STATE_HARD_BLOCKED)
 205                        rfkill->state = state;
 206        }
 207
 208        if (force || rfkill->state != oldstate)
 209                notify_rfkill_state_change(rfkill);
 210
 211        return retval;
 212}
 213
 214/**
 215 * rfkill_switch_all - Toggle state of all switches of given type
 216 * @type: type of interfaces to be affected
 217 * @state: the new state
 218 *
 219 * This function toggles the state of all switches of given type,
 220 * unless a specific switch is claimed by userspace (in which case,
 221 * that switch is left alone) or suspended.
 222 */
 223void rfkill_switch_all(enum rfkill_type type, enum rfkill_state state)
 224{
 225        struct rfkill *rfkill;
 226
 227        mutex_lock(&rfkill_mutex);
 228
 229        rfkill_states[type] = state;
 230
 231        list_for_each_entry(rfkill, &rfkill_list, node) {
 232                if ((!rfkill->user_claim) && (rfkill->type == type)) {
 233                        mutex_lock(&rfkill->mutex);
 234                        rfkill_toggle_radio(rfkill, state, 0);
 235                        mutex_unlock(&rfkill->mutex);
 236                }
 237        }
 238
 239        mutex_unlock(&rfkill_mutex);
 240}
 241EXPORT_SYMBOL(rfkill_switch_all);
 242
 243/**
 244 * rfkill_epo - emergency power off all transmitters
 245 *
 246 * This kicks all non-suspended rfkill devices to RFKILL_STATE_SOFT_BLOCKED,
 247 * ignoring everything in its path but rfkill_mutex and rfkill->mutex.
 248 */
 249void rfkill_epo(void)
 250{
 251        struct rfkill *rfkill;
 252
 253        mutex_lock(&rfkill_mutex);
 254        list_for_each_entry(rfkill, &rfkill_list, node) {
 255                mutex_lock(&rfkill->mutex);
 256                rfkill_toggle_radio(rfkill, RFKILL_STATE_SOFT_BLOCKED, 1);
 257                mutex_unlock(&rfkill->mutex);
 258        }
 259        mutex_unlock(&rfkill_mutex);
 260}
 261EXPORT_SYMBOL_GPL(rfkill_epo);
 262
 263/**
 264 * rfkill_force_state - Force the internal rfkill radio state
 265 * @rfkill: pointer to the rfkill class to modify.
 266 * @state: the current radio state the class should be forced to.
 267 *
 268 * This function updates the internal state of the radio cached
 269 * by the rfkill class.  It should be used when the driver gets
 270 * a notification by the firmware/hardware of the current *real*
 271 * state of the radio rfkill switch.
 272 *
 273 * Devices which are subject to external changes on their rfkill
 274 * state (such as those caused by a hardware rfkill line) MUST
 275 * have their driver arrange to call rfkill_force_state() as soon
 276 * as possible after such a change.
 277 *
 278 * This function may not be called from an atomic context.
 279 */
 280int rfkill_force_state(struct rfkill *rfkill, enum rfkill_state state)
 281{
 282        enum rfkill_state oldstate;
 283
 284        if (state != RFKILL_STATE_SOFT_BLOCKED &&
 285            state != RFKILL_STATE_UNBLOCKED &&
 286            state != RFKILL_STATE_HARD_BLOCKED)
 287                return -EINVAL;
 288
 289        mutex_lock(&rfkill->mutex);
 290
 291        oldstate = rfkill->state;
 292        rfkill->state = state;
 293
 294        if (state != oldstate)
 295                notify_rfkill_state_change(rfkill);
 296
 297        mutex_unlock(&rfkill->mutex);
 298
 299        return 0;
 300}
 301EXPORT_SYMBOL(rfkill_force_state);
 302
 303static ssize_t rfkill_name_show(struct device *dev,
 304                                struct device_attribute *attr,
 305                                char *buf)
 306{
 307        struct rfkill *rfkill = to_rfkill(dev);
 308
 309        return sprintf(buf, "%s\n", rfkill->name);
 310}
 311
 312static const char *rfkill_get_type_str(enum rfkill_type type)
 313{
 314        switch (type) {
 315        case RFKILL_TYPE_WLAN:
 316                return "wlan";
 317        case RFKILL_TYPE_BLUETOOTH:
 318                return "bluetooth";
 319        case RFKILL_TYPE_UWB:
 320                return "ultrawideband";
 321        case RFKILL_TYPE_WIMAX:
 322                return "wimax";
 323        case RFKILL_TYPE_WWAN:
 324                return "wwan";
 325        default:
 326                BUG();
 327        }
 328}
 329
 330static ssize_t rfkill_type_show(struct device *dev,
 331                                struct device_attribute *attr,
 332                                char *buf)
 333{
 334        struct rfkill *rfkill = to_rfkill(dev);
 335
 336        return sprintf(buf, "%s\n", rfkill_get_type_str(rfkill->type));
 337}
 338
 339static ssize_t rfkill_state_show(struct device *dev,
 340                                 struct device_attribute *attr,
 341                                 char *buf)
 342{
 343        struct rfkill *rfkill = to_rfkill(dev);
 344
 345        update_rfkill_state(rfkill);
 346        return sprintf(buf, "%d\n", rfkill->state);
 347}
 348
 349static ssize_t rfkill_state_store(struct device *dev,
 350                                  struct device_attribute *attr,
 351                                  const char *buf, size_t count)
 352{
 353        struct rfkill *rfkill = to_rfkill(dev);
 354        unsigned int state = simple_strtoul(buf, NULL, 0);
 355        int error;
 356
 357        if (!capable(CAP_NET_ADMIN))
 358                return -EPERM;
 359
 360        /* RFKILL_STATE_HARD_BLOCKED is illegal here... */
 361        if (state != RFKILL_STATE_UNBLOCKED &&
 362            state != RFKILL_STATE_SOFT_BLOCKED)
 363                return -EINVAL;
 364
 365        if (mutex_lock_interruptible(&rfkill->mutex))
 366                return -ERESTARTSYS;
 367        error = rfkill_toggle_radio(rfkill, state, 0);
 368        mutex_unlock(&rfkill->mutex);
 369
 370        return error ? error : count;
 371}
 372
 373static ssize_t rfkill_claim_show(struct device *dev,
 374                                 struct device_attribute *attr,
 375                                 char *buf)
 376{
 377        struct rfkill *rfkill = to_rfkill(dev);
 378
 379        return sprintf(buf, "%d\n", rfkill->user_claim);
 380}
 381
 382static ssize_t rfkill_claim_store(struct device *dev,
 383                                  struct device_attribute *attr,
 384                                  const char *buf, size_t count)
 385{
 386        struct rfkill *rfkill = to_rfkill(dev);
 387        bool claim = !!simple_strtoul(buf, NULL, 0);
 388        int error;
 389
 390        if (!capable(CAP_NET_ADMIN))
 391                return -EPERM;
 392
 393        if (rfkill->user_claim_unsupported)
 394                return -EOPNOTSUPP;
 395
 396        /*
 397         * Take the global lock to make sure the kernel is not in
 398         * the middle of rfkill_switch_all
 399         */
 400        error = mutex_lock_interruptible(&rfkill_mutex);
 401        if (error)
 402                return error;
 403
 404        if (rfkill->user_claim != claim) {
 405                if (!claim) {
 406                        mutex_lock(&rfkill->mutex);
 407                        rfkill_toggle_radio(rfkill,
 408                                            rfkill_states[rfkill->type],
 409                                            0);
 410                        mutex_unlock(&rfkill->mutex);
 411                }
 412                rfkill->user_claim = claim;
 413        }
 414
 415        mutex_unlock(&rfkill_mutex);
 416
 417        return error ? error : count;
 418}
 419
 420static struct device_attribute rfkill_dev_attrs[] = {
 421        __ATTR(name, S_IRUGO, rfkill_name_show, NULL),
 422        __ATTR(type, S_IRUGO, rfkill_type_show, NULL),
 423        __ATTR(state, S_IRUGO|S_IWUSR, rfkill_state_show, rfkill_state_store),
 424        __ATTR(claim, S_IRUGO|S_IWUSR, rfkill_claim_show, rfkill_claim_store),
 425        __ATTR_NULL
 426};
 427
 428static void rfkill_release(struct device *dev)
 429{
 430        struct rfkill *rfkill = to_rfkill(dev);
 431
 432        kfree(rfkill);
 433        module_put(THIS_MODULE);
 434}
 435
 436#ifdef CONFIG_PM
 437static int rfkill_suspend(struct device *dev, pm_message_t state)
 438{
 439        struct rfkill *rfkill = to_rfkill(dev);
 440
 441        if (dev->power.power_state.event != state.event) {
 442                if (state.event & PM_EVENT_SLEEP) {
 443                        /* Stop transmitter, keep state, no notifies */
 444                        update_rfkill_state(rfkill);
 445
 446                        mutex_lock(&rfkill->mutex);
 447                        rfkill->toggle_radio(rfkill->data,
 448                                                RFKILL_STATE_SOFT_BLOCKED);
 449                        mutex_unlock(&rfkill->mutex);
 450                }
 451
 452                dev->power.power_state = state;
 453        }
 454
 455        return 0;
 456}
 457
 458static int rfkill_resume(struct device *dev)
 459{
 460        struct rfkill *rfkill = to_rfkill(dev);
 461
 462        if (dev->power.power_state.event != PM_EVENT_ON) {
 463                mutex_lock(&rfkill->mutex);
 464
 465                dev->power.power_state.event = PM_EVENT_ON;
 466
 467                /* restore radio state AND notify everybody */
 468                rfkill_toggle_radio(rfkill, rfkill->state, 1);
 469
 470                mutex_unlock(&rfkill->mutex);
 471        }
 472
 473        return 0;
 474}
 475#else
 476#define rfkill_suspend NULL
 477#define rfkill_resume NULL
 478#endif
 479
 480static int rfkill_blocking_uevent_notifier(struct notifier_block *nb,
 481                                        unsigned long eventid,
 482                                        void *data)
 483{
 484        struct rfkill *rfkill = (struct rfkill *)data;
 485
 486        switch (eventid) {
 487        case RFKILL_STATE_CHANGED:
 488                kobject_uevent(&rfkill->dev.kobj, KOBJ_CHANGE);
 489                break;
 490        default:
 491                break;
 492        }
 493
 494        return NOTIFY_DONE;
 495}
 496
 497static struct notifier_block rfkill_blocking_uevent_nb = {
 498        .notifier_call  = rfkill_blocking_uevent_notifier,
 499        .priority       = 0,
 500};
 501
 502static int rfkill_dev_uevent(struct device *dev, struct kobj_uevent_env *env)
 503{
 504        struct rfkill *rfkill = to_rfkill(dev);
 505        int error;
 506
 507        error = add_uevent_var(env, "RFKILL_NAME=%s", rfkill->name);
 508        if (error)
 509                return error;
 510        error = add_uevent_var(env, "RFKILL_TYPE=%s",
 511                                rfkill_get_type_str(rfkill->type));
 512        if (error)
 513                return error;
 514        error = add_uevent_var(env, "RFKILL_STATE=%d", rfkill->state);
 515        return error;
 516}
 517
 518static struct class rfkill_class = {
 519        .name           = "rfkill",
 520        .dev_release    = rfkill_release,
 521        .dev_attrs      = rfkill_dev_attrs,
 522        .suspend        = rfkill_suspend,
 523        .resume         = rfkill_resume,
 524        .dev_uevent     = rfkill_dev_uevent,
 525};
 526
 527static int rfkill_add_switch(struct rfkill *rfkill)
 528{
 529        mutex_lock(&rfkill_mutex);
 530
 531        rfkill_toggle_radio(rfkill, rfkill_states[rfkill->type], 0);
 532
 533        list_add_tail(&rfkill->node, &rfkill_list);
 534
 535        mutex_unlock(&rfkill_mutex);
 536
 537        return 0;
 538}
 539
 540static void rfkill_remove_switch(struct rfkill *rfkill)
 541{
 542        mutex_lock(&rfkill_mutex);
 543        list_del_init(&rfkill->node);
 544        mutex_unlock(&rfkill_mutex);
 545
 546        mutex_lock(&rfkill->mutex);
 547        rfkill_toggle_radio(rfkill, RFKILL_STATE_SOFT_BLOCKED, 1);
 548        mutex_unlock(&rfkill->mutex);
 549}
 550
 551/**
 552 * rfkill_allocate - allocate memory for rfkill structure.
 553 * @parent: device that has rf switch on it
 554 * @type: type of the switch (RFKILL_TYPE_*)
 555 *
 556 * This function should be called by the network driver when it needs
 557 * rfkill structure.  Once the structure is allocated the driver should
 558 * finish its initialization by setting the name, private data, enable_radio
 559 * and disable_radio methods and then register it with rfkill_register().
 560 *
 561 * NOTE: If registration fails the structure shoudl be freed by calling
 562 * rfkill_free() otherwise rfkill_unregister() should be used.
 563 */
 564struct rfkill *rfkill_allocate(struct device *parent, enum rfkill_type type)
 565{
 566        struct rfkill *rfkill;
 567        struct device *dev;
 568
 569        rfkill = kzalloc(sizeof(struct rfkill), GFP_KERNEL);
 570        if (!rfkill)
 571                return NULL;
 572
 573        mutex_init(&rfkill->mutex);
 574        INIT_LIST_HEAD(&rfkill->node);
 575        rfkill->type = type;
 576
 577        dev = &rfkill->dev;
 578        dev->class = &rfkill_class;
 579        dev->parent = parent;
 580        device_initialize(dev);
 581
 582        __module_get(THIS_MODULE);
 583
 584        return rfkill;
 585}
 586EXPORT_SYMBOL(rfkill_allocate);
 587
 588/**
 589 * rfkill_free - Mark rfkill structure for deletion
 590 * @rfkill: rfkill structure to be destroyed
 591 *
 592 * Decrements reference count of the rfkill structure so it is destroyed.
 593 * Note that rfkill_free() should _not_ be called after rfkill_unregister().
 594 */
 595void rfkill_free(struct rfkill *rfkill)
 596{
 597        if (rfkill)
 598                put_device(&rfkill->dev);
 599}
 600EXPORT_SYMBOL(rfkill_free);
 601
 602static void rfkill_led_trigger_register(struct rfkill *rfkill)
 603{
 604#ifdef CONFIG_RFKILL_LEDS
 605        int error;
 606
 607        if (!rfkill->led_trigger.name)
 608                rfkill->led_trigger.name = rfkill->dev.bus_id;
 609        if (!rfkill->led_trigger.activate)
 610                rfkill->led_trigger.activate = rfkill_led_trigger_activate;
 611        error = led_trigger_register(&rfkill->led_trigger);
 612        if (error)
 613                rfkill->led_trigger.name = NULL;
 614#endif /* CONFIG_RFKILL_LEDS */
 615}
 616
 617static void rfkill_led_trigger_unregister(struct rfkill *rfkill)
 618{
 619#ifdef CONFIG_RFKILL_LEDS
 620        if (rfkill->led_trigger.name) {
 621                led_trigger_unregister(&rfkill->led_trigger);
 622                rfkill->led_trigger.name = NULL;
 623        }
 624#endif
 625}
 626
 627/**
 628 * rfkill_register - Register a rfkill structure.
 629 * @rfkill: rfkill structure to be registered
 630 *
 631 * This function should be called by the network driver when the rfkill
 632 * structure needs to be registered. Immediately from registration the
 633 * switch driver should be able to service calls to toggle_radio.
 634 */
 635int rfkill_register(struct rfkill *rfkill)
 636{
 637        static atomic_t rfkill_no = ATOMIC_INIT(0);
 638        struct device *dev = &rfkill->dev;
 639        int error;
 640
 641        if (!rfkill->toggle_radio)
 642                return -EINVAL;
 643        if (rfkill->type >= RFKILL_TYPE_MAX)
 644                return -EINVAL;
 645
 646        snprintf(dev->bus_id, sizeof(dev->bus_id),
 647                 "rfkill%ld", (long)atomic_inc_return(&rfkill_no) - 1);
 648
 649        rfkill_led_trigger_register(rfkill);
 650
 651        error = rfkill_add_switch(rfkill);
 652        if (error) {
 653                rfkill_led_trigger_unregister(rfkill);
 654                return error;
 655        }
 656
 657        error = device_add(dev);
 658        if (error) {
 659                rfkill_remove_switch(rfkill);
 660                rfkill_led_trigger_unregister(rfkill);
 661                return error;
 662        }
 663
 664        return 0;
 665}
 666EXPORT_SYMBOL(rfkill_register);
 667
 668/**
 669 * rfkill_unregister - Unregister a rfkill structure.
 670 * @rfkill: rfkill structure to be unregistered
 671 *
 672 * This function should be called by the network driver during device
 673 * teardown to destroy rfkill structure. Note that rfkill_free() should
 674 * _not_ be called after rfkill_unregister().
 675 */
 676void rfkill_unregister(struct rfkill *rfkill)
 677{
 678        device_del(&rfkill->dev);
 679        rfkill_remove_switch(rfkill);
 680        rfkill_led_trigger_unregister(rfkill);
 681        put_device(&rfkill->dev);
 682}
 683EXPORT_SYMBOL(rfkill_unregister);
 684
 685/*
 686 * Rfkill module initialization/deinitialization.
 687 */
 688static int __init rfkill_init(void)
 689{
 690        int error;
 691        int i;
 692
 693        /* RFKILL_STATE_HARD_BLOCKED is illegal here... */
 694        if (rfkill_default_state != RFKILL_STATE_SOFT_BLOCKED &&
 695            rfkill_default_state != RFKILL_STATE_UNBLOCKED)
 696                return -EINVAL;
 697
 698        for (i = 0; i < ARRAY_SIZE(rfkill_states); i++)
 699                rfkill_states[i] = rfkill_default_state;
 700
 701        error = class_register(&rfkill_class);
 702        if (error) {
 703                printk(KERN_ERR "rfkill: unable to register rfkill class\n");
 704                return error;
 705        }
 706
 707        register_rfkill_notifier(&rfkill_blocking_uevent_nb);
 708
 709        return 0;
 710}
 711
 712static void __exit rfkill_exit(void)
 713{
 714        unregister_rfkill_notifier(&rfkill_blocking_uevent_nb);
 715        class_unregister(&rfkill_class);
 716}
 717
 718subsys_initcall(rfkill_init);
 719module_exit(rfkill_exit);
 720
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.