diff options
| author | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-05-07 15:23:31 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-05-07 15:23:31 -0400 |
| commit | 9fa0853a85a3a4067e4ad0aaa5d90984c2dd21b5 (patch) | |
| tree | ac90f6535bc053b3859dc050cbbd577a0a1ef95b | |
| parent | ef93127e4c7b4b8d46421045641048397eaac43d (diff) | |
| parent | cf4328cd949c2086091c62c5685f1580fe9b55e4 (diff) | |
Merge master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6
* master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6:
[NET]: rfkill: add support for input key to control wireless radio
[NET] net/core: Fix error handling
[TG3]: Update version and reldate.
[TG3]: Eliminate spurious interrupts.
[TG3]: Add ASPM workaround.
[Bluetooth] Correct SCO buffer for another Broadcom based dongle
[Bluetooth] Add support for Targus ACB10US USB dongle
[Bluetooth] Disconnect L2CAP connection after last RFCOMM DLC
[Bluetooth] Check that device is in rfcomm_dev_list before deleting
[Bluetooth] Use in-kernel sockets API
[Bluetooth] Attach host adapters to the Bluetooth bus
[Bluetooth] Fix L2CAP and HCI setsockopt() information leaks
| -rw-r--r-- | drivers/bluetooth/hci_usb.c | 6 | ||||
| -rw-r--r-- | drivers/net/tg3.c | 40 | ||||
| -rw-r--r-- | drivers/net/tg3.h | 10 | ||||
| -rw-r--r-- | include/linux/rfkill.h | 89 | ||||
| -rw-r--r-- | net/Kconfig | 2 | ||||
| -rw-r--r-- | net/Makefile | 1 | ||||
| -rw-r--r-- | net/bluetooth/hci_sock.c | 9 | ||||
| -rw-r--r-- | net/bluetooth/hci_sysfs.c | 9 | ||||
| -rw-r--r-- | net/bluetooth/l2cap.c | 6 | ||||
| -rw-r--r-- | net/bluetooth/rfcomm/core.c | 29 | ||||
| -rw-r--r-- | net/bluetooth/rfcomm/tty.c | 11 | ||||
| -rw-r--r-- | net/core/dev.c | 4 | ||||
| -rw-r--r-- | net/rfkill/Kconfig | 24 | ||||
| -rw-r--r-- | net/rfkill/Makefile | 6 | ||||
| -rw-r--r-- | net/rfkill/rfkill-input.c | 174 | ||||
| -rw-r--r-- | net/rfkill/rfkill.c | 407 |
16 files changed, 804 insertions, 23 deletions
diff --git a/drivers/bluetooth/hci_usb.c b/drivers/bluetooth/hci_usb.c index 406af579ac3a..b0238b46dded 100644 --- a/drivers/bluetooth/hci_usb.c +++ b/drivers/bluetooth/hci_usb.c | |||
| @@ -114,10 +114,16 @@ static struct usb_device_id blacklist_ids[] = { | |||
| 114 | { USB_DEVICE(0x0a5c, 0x200a), .driver_info = HCI_RESET | HCI_WRONG_SCO_MTU }, | 114 | { USB_DEVICE(0x0a5c, 0x200a), .driver_info = HCI_RESET | HCI_WRONG_SCO_MTU }, |
| 115 | { USB_DEVICE(0x0a5c, 0x2009), .driver_info = HCI_BCM92035 }, | 115 | { USB_DEVICE(0x0a5c, 0x2009), .driver_info = HCI_BCM92035 }, |
| 116 | 116 | ||
| 117 | /* Broadcom BCM2045 */ | ||
| 118 | { USB_DEVICE(0x0a5c, 0x2101), .driver_info = HCI_WRONG_SCO_MTU }, | ||
| 119 | |||
| 117 | /* IBM/Lenovo ThinkPad with Broadcom chip */ | 120 | /* IBM/Lenovo ThinkPad with Broadcom chip */ |
| 118 | { USB_DEVICE(0x0a5c, 0x201e), .driver_info = HCI_WRONG_SCO_MTU }, | 121 | { USB_DEVICE(0x0a5c, 0x201e), .driver_info = HCI_WRONG_SCO_MTU }, |
| 119 | { USB_DEVICE(0x0a5c, 0x2110), .driver_info = HCI_WRONG_SCO_MTU }, | 122 | { USB_DEVICE(0x0a5c, 0x2110), .driver_info = HCI_WRONG_SCO_MTU }, |
| 120 | 123 | ||
| 124 | /* Targus ACB10US */ | ||
| 125 | { USB_DEVICE(0x0a5c, 0x2100), .driver_info = HCI_RESET }, | ||
| 126 | |||
| 121 | /* ANYCOM Bluetooth USB-200 and USB-250 */ | 127 | /* ANYCOM Bluetooth USB-200 and USB-250 */ |
| 122 | { USB_DEVICE(0x0a5c, 0x2111), .driver_info = HCI_RESET }, | 128 | { USB_DEVICE(0x0a5c, 0x2111), .driver_info = HCI_RESET }, |
| 123 | 129 | ||
diff --git a/drivers/net/tg3.c b/drivers/net/tg3.c index 59d6e74a4a5f..e5e901ecd808 100644 --- a/drivers/net/tg3.c +++ b/drivers/net/tg3.c | |||
| @@ -64,8 +64,8 @@ | |||
| 64 | 64 | ||
| 65 | #define DRV_MODULE_NAME "tg3" | 65 | #define DRV_MODULE_NAME "tg3" |
| 66 | #define PFX DRV_MODULE_NAME ": " | 66 | #define PFX DRV_MODULE_NAME ": " |
| 67 | #define DRV_MODULE_VERSION "3.75" | 67 | #define DRV_MODULE_VERSION "3.76" |
| 68 | #define DRV_MODULE_RELDATE "March 23, 2007" | 68 | #define DRV_MODULE_RELDATE "May 5, 2007" |
| 69 | 69 | ||
| 70 | #define TG3_DEF_MAC_MODE 0 | 70 | #define TG3_DEF_MAC_MODE 0 |
| 71 | #define TG3_DEF_RX_MODE 0 | 71 | #define TG3_DEF_RX_MODE 0 |
| @@ -3019,6 +3019,16 @@ static int tg3_setup_phy(struct tg3 *tp, int force_reset) | |||
| 3019 | } | 3019 | } |
| 3020 | } | 3020 | } |
| 3021 | 3021 | ||
| 3022 | if (tp->tg3_flags & TG3_FLAG_ASPM_WORKAROUND) { | ||
| 3023 | u32 val = tr32(PCIE_PWR_MGMT_THRESH); | ||
| 3024 | if (!netif_carrier_ok(tp->dev)) | ||
| 3025 | val = (val & ~PCIE_PWR_MGMT_L1_THRESH_MSK) | | ||
| 3026 | tp->pwrmgmt_thresh; | ||
| 3027 | else | ||
| 3028 | val |= PCIE_PWR_MGMT_L1_THRESH_MSK; | ||
| 3029 | tw32(PCIE_PWR_MGMT_THRESH, val); | ||
| 3030 | } | ||
| 3031 | |||
| 3022 | return err; | 3032 | return err; |
| 3023 | } | 3033 | } |
| 3024 | 3034 | ||
| @@ -3580,8 +3590,12 @@ static irqreturn_t tg3_interrupt(int irq, void *dev_id) | |||
| 3580 | * Writing non-zero to intr-mbox-0 additional tells the | 3590 | * Writing non-zero to intr-mbox-0 additional tells the |
| 3581 | * NIC to stop sending us irqs, engaging "in-intr-handler" | 3591 | * NIC to stop sending us irqs, engaging "in-intr-handler" |
| 3582 | * event coalescing. | 3592 | * event coalescing. |
| 3593 | * | ||
| 3594 | * Flush the mailbox to de-assert the IRQ immediately to prevent | ||
| 3595 | * spurious interrupts. The flush impacts performance but | ||
| 3596 | * excessive spurious interrupts can be worse in some cases. | ||
| 3583 | */ | 3597 | */ |
| 3584 | tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001); | 3598 | tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001); |
| 3585 | if (tg3_irq_sync(tp)) | 3599 | if (tg3_irq_sync(tp)) |
| 3586 | goto out; | 3600 | goto out; |
| 3587 | sblk->status &= ~SD_STATUS_UPDATED; | 3601 | sblk->status &= ~SD_STATUS_UPDATED; |
| @@ -3625,8 +3639,12 @@ static irqreturn_t tg3_interrupt_tagged(int irq, void *dev_id) | |||
| 3625 | * writing non-zero to intr-mbox-0 additional tells the | 3639 | * writing non-zero to intr-mbox-0 additional tells the |
| 3626 | * NIC to stop sending us irqs, engaging "in-intr-handler" | 3640 | * NIC to stop sending us irqs, engaging "in-intr-handler" |
| 3627 | * event coalescing. | 3641 | * event coalescing. |
| 3642 | * | ||
| 3643 | * Flush the mailbox to de-assert the IRQ immediately to prevent | ||
| 3644 | * spurious interrupts. The flush impacts performance but | ||
| 3645 | * excessive spurious interrupts can be worse in some cases. | ||
| 3628 | */ | 3646 | */ |
| 3629 | tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001); | 3647 | tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001); |
| 3630 | if (tg3_irq_sync(tp)) | 3648 | if (tg3_irq_sync(tp)) |
| 3631 | goto out; | 3649 | goto out; |
| 3632 | if (netif_rx_schedule_prep(dev)) { | 3650 | if (netif_rx_schedule_prep(dev)) { |
| @@ -10004,6 +10022,8 @@ static void __devinit tg3_get_eeprom_hw_cfg(struct tg3 *tp) | |||
| 10004 | tp->tg3_flags &= ~TG3_FLAG_EEPROM_WRITE_PROT; | 10022 | tp->tg3_flags &= ~TG3_FLAG_EEPROM_WRITE_PROT; |
| 10005 | tp->tg3_flags2 |= TG3_FLG2_IS_NIC; | 10023 | tp->tg3_flags2 |= TG3_FLG2_IS_NIC; |
| 10006 | } | 10024 | } |
| 10025 | if (tr32(VCPU_CFGSHDW) & VCPU_CFGSHDW_ASPM_DBNC) | ||
| 10026 | tp->tg3_flags |= TG3_FLAG_ASPM_WORKAROUND; | ||
| 10007 | return; | 10027 | return; |
| 10008 | } | 10028 | } |
| 10009 | 10029 | ||
| @@ -10131,6 +10151,14 @@ static void __devinit tg3_get_eeprom_hw_cfg(struct tg3 *tp) | |||
| 10131 | /* bootcode if bit 18 is set */ | 10151 | /* bootcode if bit 18 is set */ |
| 10132 | if (cfg2 & (1 << 18)) | 10152 | if (cfg2 & (1 << 18)) |
| 10133 | tp->tg3_flags2 |= TG3_FLG2_SERDES_PREEMPHASIS; | 10153 | tp->tg3_flags2 |= TG3_FLG2_SERDES_PREEMPHASIS; |
| 10154 | |||
| 10155 | if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) { | ||
| 10156 | u32 cfg3; | ||
| 10157 | |||
| 10158 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG_3, &cfg3); | ||
| 10159 | if (cfg3 & NIC_SRAM_ASPM_DEBOUNCE) | ||
| 10160 | tp->tg3_flags |= TG3_FLAG_ASPM_WORKAROUND; | ||
| 10161 | } | ||
| 10134 | } | 10162 | } |
| 10135 | } | 10163 | } |
| 10136 | 10164 | ||
| @@ -10998,6 +11026,10 @@ static int __devinit tg3_get_invariants(struct tg3 *tp) | |||
| 10998 | */ | 11026 | */ |
| 10999 | tp->tg3_flags &= ~TG3_FLAG_WOL_ENABLE; | 11027 | tp->tg3_flags &= ~TG3_FLAG_WOL_ENABLE; |
| 11000 | 11028 | ||
| 11029 | if (tp->tg3_flags & TG3_FLAG_ASPM_WORKAROUND) | ||
| 11030 | tp->pwrmgmt_thresh = tr32(PCIE_PWR_MGMT_THRESH) & | ||
| 11031 | PCIE_PWR_MGMT_L1_THRESH_MSK; | ||
| 11032 | |||
| 11001 | return err; | 11033 | return err; |
| 11002 | } | 11034 | } |
| 11003 | 11035 | ||
diff --git a/drivers/net/tg3.h b/drivers/net/tg3.h index dcdfc084966c..4d334cf5a243 100644 --- a/drivers/net/tg3.h +++ b/drivers/net/tg3.h | |||
| @@ -1150,6 +1150,9 @@ | |||
| 1150 | #define VCPU_STATUS_INIT_DONE 0x04000000 | 1150 | #define VCPU_STATUS_INIT_DONE 0x04000000 |
| 1151 | #define VCPU_STATUS_DRV_RESET 0x08000000 | 1151 | #define VCPU_STATUS_DRV_RESET 0x08000000 |
| 1152 | 1152 | ||
| 1153 | #define VCPU_CFGSHDW 0x00005104 | ||
| 1154 | #define VCPU_CFGSHDW_ASPM_DBNC 0x00001000 | ||
| 1155 | |||
| 1153 | /* Mailboxes */ | 1156 | /* Mailboxes */ |
| 1154 | #define GRCMBOX_BASE 0x00005600 | 1157 | #define GRCMBOX_BASE 0x00005600 |
| 1155 | #define GRCMBOX_INTERRUPT_0 0x00005800 /* 64-bit */ | 1158 | #define GRCMBOX_INTERRUPT_0 0x00005800 /* 64-bit */ |
| @@ -1507,6 +1510,8 @@ | |||
| 1507 | #define PCIE_TRANS_CFG_1SHOT_MSI 0x20000000 | 1510 | #define PCIE_TRANS_CFG_1SHOT_MSI 0x20000000 |
| 1508 | #define PCIE_TRANS_CFG_LOM 0x00000020 | 1511 | #define PCIE_TRANS_CFG_LOM 0x00000020 |
| 1509 | 1512 | ||
| 1513 | #define PCIE_PWR_MGMT_THRESH 0x00007d28 | ||
| 1514 | #define PCIE_PWR_MGMT_L1_THRESH_MSK 0x0000ff00 | ||
| 1510 | 1515 | ||
| 1511 | #define TG3_EEPROM_MAGIC 0x669955aa | 1516 | #define TG3_EEPROM_MAGIC 0x669955aa |
| 1512 | #define TG3_EEPROM_MAGIC_FW 0xa5000000 | 1517 | #define TG3_EEPROM_MAGIC_FW 0xa5000000 |
| @@ -1593,6 +1598,9 @@ | |||
| 1593 | #define SHASTA_EXT_LED_MAC 0x00010000 | 1598 | #define SHASTA_EXT_LED_MAC 0x00010000 |
| 1594 | #define SHASTA_EXT_LED_COMBO 0x00018000 | 1599 | #define SHASTA_EXT_LED_COMBO 0x00018000 |
| 1595 | 1600 | ||
| 1601 | #define NIC_SRAM_DATA_CFG_3 0x00000d3c | ||
| 1602 | #define NIC_SRAM_ASPM_DEBOUNCE 0x00000002 | ||
| 1603 | |||
| 1596 | #define NIC_SRAM_RX_MINI_BUFFER_DESC 0x00001000 | 1604 | #define NIC_SRAM_RX_MINI_BUFFER_DESC 0x00001000 |
| 1597 | 1605 | ||
| 1598 | #define NIC_SRAM_DMA_DESC_POOL_BASE 0x00002000 | 1606 | #define NIC_SRAM_DMA_DESC_POOL_BASE 0x00002000 |
| @@ -2200,6 +2208,7 @@ struct tg3 { | |||
| 2200 | #define TG3_FLAG_USE_LINKCHG_REG 0x00000008 | 2208 | #define TG3_FLAG_USE_LINKCHG_REG 0x00000008 |
| 2201 | #define TG3_FLAG_USE_MI_INTERRUPT 0x00000010 | 2209 | #define TG3_FLAG_USE_MI_INTERRUPT 0x00000010 |
| 2202 | #define TG3_FLAG_ENABLE_ASF 0x00000020 | 2210 | #define TG3_FLAG_ENABLE_ASF 0x00000020 |
| 2211 | #define TG3_FLAG_ASPM_WORKAROUND 0x00000040 | ||
| 2203 | #define TG3_FLAG_POLL_SERDES 0x00000080 | 2212 | #define TG3_FLAG_POLL_SERDES 0x00000080 |
| 2204 | #define TG3_FLAG_MBOX_WRITE_REORDER 0x00000100 | 2213 | #define TG3_FLAG_MBOX_WRITE_REORDER 0x00000100 |
| 2205 | #define TG3_FLAG_PCIX_TARGET_HWBUG 0x00000200 | 2214 | #define TG3_FLAG_PCIX_TARGET_HWBUG 0x00000200 |
| @@ -2288,6 +2297,7 @@ struct tg3 { | |||
| 2288 | u32 grc_local_ctrl; | 2297 | u32 grc_local_ctrl; |
| 2289 | u32 dma_rwctrl; | 2298 | u32 dma_rwctrl; |
| 2290 | u32 coalesce_mode; | 2299 | u32 coalesce_mode; |
| 2300 | u32 pwrmgmt_thresh; | ||
| 2291 | 2301 | ||
| 2292 | /* PCI block */ | 2302 | /* PCI block */ |
| 2293 | u16 pci_chip_rev_id; | 2303 | u16 pci_chip_rev_id; |
diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h new file mode 100644 index 000000000000..7c1ffbab7865 --- /dev/null +++ b/include/linux/rfkill.h | |||
| @@ -0,0 +1,89 @@ | |||
| 1 | #ifndef __RFKILL_H | ||
| 2 | #define __RFKILL_H | ||
| 3 | |||
| 4 | /* | ||
| 5 | * Copyright (C) 2006 Ivo van Doorn | ||
| 6 | * Copyright (C) 2007 Dmitry Torokhov | ||
| 7 | * | ||
| 8 | * This program is free software; you can redistribute it and/or modify | ||
| 9 | * it under the terms of the GNU General Public License as published by | ||
| 10 | * the Free Software Foundation; either version 2 of the License, or | ||
| 11 | * (at your option) any later version. | ||
| 12 | * | ||
| 13 | * This program is distributed in the hope that it will be useful, | ||
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 16 | * GNU General Public License for more details. | ||
| 17 | * | ||
| 18 | * You should have received a copy of the GNU General Public License | ||
| 19 | * along with this program; if not, write to the | ||
| 20 | * Free Software Foundation, Inc., | ||
| 21 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
| 22 | */ | ||
| 23 | |||
| 24 | #include <linux/types.h> | ||
| 25 | #include <linux/kernel.h> | ||
| 26 | #include <linux/list.h> | ||
| 27 | #include <linux/mutex.h> | ||
| 28 | #include <linux/device.h> | ||
| 29 | |||
| 30 | /** | ||
| 31 | * enum rfkill_type - type of rfkill switch. | ||
| 32 | * RFKILL_TYPE_WLAN: switch is no a Wireless network devices. | ||
| 33 | * RFKILL_TYPE_BlUETOOTH: switch is on a bluetooth device. | ||
| 34 | * RFKILL_TYPE_IRDA: switch is on an infrared devices. | ||
| 35 | */ | ||
| 36 | enum rfkill_type { | ||
| 37 | RFKILL_TYPE_WLAN = 0, | ||
| 38 | RFKILL_TYPE_BLUETOOTH = 1, | ||
| 39 | RFKILL_TYPE_IRDA = 2, | ||
| 40 | RFKILL_TYPE_MAX = 3, | ||
| 41 | }; | ||
| 42 | |||
| 43 | enum rfkill_state { | ||
| 44 | RFKILL_STATE_OFF = 0, | ||
| 45 | RFKILL_STATE_ON = 1, | ||
| 46 | }; | ||
| 47 | |||
| 48 | /** | ||
| 49 | * struct rfkill - rfkill control structure. | ||
| 50 | * @name: Name of the switch. | ||
| 51 | * @type: Radio type which the button controls, the value stored | ||
| 52 | * here should be a value from enum rfkill_type. | ||
| 53 | * @state: State of the switch (on/off). | ||
| 54 | * @user_claim: Set when the switch is controlled exlusively by userspace. | ||
| 55 | * @mutex: Guards switch state transitions | ||
| 56 | * @data: Pointer to the RF button drivers private data which will be | ||
| 57 | * passed along when toggling radio state. | ||
| 58 | * @toggle_radio(): Mandatory handler to control state of the radio. | ||
| 59 | * @dev: Device structure integrating the switch into device tree. | ||
| 60 | * @node: Used to place switch into list of all switches known to the | ||
| 61 | * the system. | ||
| 62 | * | ||
| 63 | * This structure represents a RF switch located on a network device. | ||
| 64 | */ | ||
| 65 | struct rfkill { | ||
| 66 | char *name; | ||
| 67 | enum rfkill_type type; | ||
| 68 | |||
| 69 | enum rfkill_state state; | ||
| 70 | bool user_claim; | ||
| 71 | |||
| 72 | struct mutex mutex; | ||
| 73 | |||
| 74 | void *data; | ||
| 75 | int (*toggle_radio)(void *data, enum rfkill_state state); | ||
| 76 | |||
| 77 | struct device dev; | ||
| 78 | struct list_head node; | ||
| 79 | }; | ||
| 80 | #define to_rfkill(d) container_of(d, struct rfkill, dev) | ||
| 81 | |||
| 82 | struct rfkill *rfkill_allocate(struct device *parent, enum rfkill_type type); | ||
| 83 | void rfkill_free(struct rfkill *rfkill); | ||
| 84 | int rfkill_register(struct rfkill *rfkill); | ||
| 85 | void rfkill_unregister(struct rfkill *rfkill); | ||
| 86 | |||
| 87 | void rfkill_switch_all(enum rfkill_type type, enum rfkill_state state); | ||
| 88 | |||
| 89 | #endif /* RFKILL_H */ | ||
diff --git a/net/Kconfig b/net/Kconfig index 5b2227813923..caeacd16656a 100644 --- a/net/Kconfig +++ b/net/Kconfig | |||
| @@ -225,6 +225,8 @@ source "net/ieee80211/Kconfig" | |||
| 225 | 225 | ||
| 226 | endmenu | 226 | endmenu |
| 227 | 227 | ||
| 228 | source "net/rfkill/Kconfig" | ||
| 229 | |||
| 228 | endif # if NET | 230 | endif # if NET |
| 229 | endmenu # Networking | 231 | endmenu # Networking |
| 230 | 232 | ||
diff --git a/net/Makefile b/net/Makefile index 9fdb60c2e4a1..34e5b2d7f877 100644 --- a/net/Makefile +++ b/net/Makefile | |||
| @@ -51,6 +51,7 @@ obj-$(CONFIG_IEEE80211) += ieee80211/ | |||
| 51 | obj-$(CONFIG_TIPC) += tipc/ | 51 | obj-$(CONFIG_TIPC) += tipc/ |
| 52 | obj-$(CONFIG_NETLABEL) += netlabel/ | 52 | obj-$(CONFIG_NETLABEL) += netlabel/ |
| 53 | obj-$(CONFIG_IUCV) += iucv/ | 53 | obj-$(CONFIG_IUCV) += iucv/ |
| 54 | obj-$(CONFIG_RFKILL) += rfkill/ | ||
| 54 | 55 | ||
| 55 | ifeq ($(CONFIG_NET),y) | 56 | ifeq ($(CONFIG_NET),y) |
| 56 | obj-$(CONFIG_SYSCTL) += sysctl_net.o | 57 | obj-$(CONFIG_SYSCTL) += sysctl_net.o |
diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c index 832b5f44be5c..bfc9a35bad33 100644 --- a/net/bluetooth/hci_sock.c +++ b/net/bluetooth/hci_sock.c | |||
| @@ -499,6 +499,15 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname, char | |||
| 499 | break; | 499 | break; |
| 500 | 500 | ||
| 501 | case HCI_FILTER: | 501 | case HCI_FILTER: |
| 502 | { | ||
| 503 | struct hci_filter *f = &hci_pi(sk)->filter; | ||
| 504 | |||
| 505 | uf.type_mask = f->type_mask; | ||
| 506 | uf.opcode = f->opcode; | ||
| 507 | uf.event_mask[0] = *((u32 *) f->event_mask + 0); | ||
| 508 | uf.event_mask[1] = *((u32 *) f->event_mask + 1); | ||
| 509 | } | ||
| 510 | |||
| 502 | len = min_t(unsigned int, len, sizeof(uf)); | 511 | len = min_t(unsigned int, len, sizeof(uf)); |
| 503 | if (copy_from_user(&uf, optval, len)) { | 512 | if (copy_from_user(&uf, optval, len)) { |
| 504 | err = -EFAULT; | 513 | err = -EFAULT; |
diff --git a/net/bluetooth/hci_sysfs.c b/net/bluetooth/hci_sysfs.c index 801d687ea4ef..359e3440cf29 100644 --- a/net/bluetooth/hci_sysfs.c +++ b/net/bluetooth/hci_sysfs.c | |||
| @@ -305,7 +305,7 @@ int hci_register_sysfs(struct hci_dev *hdev) | |||
| 305 | 305 | ||
| 306 | BT_DBG("%p name %s type %d", hdev, hdev->name, hdev->type); | 306 | BT_DBG("%p name %s type %d", hdev, hdev->name, hdev->type); |
| 307 | 307 | ||
| 308 | dev->class = bt_class; | 308 | dev->bus = &bt_bus; |
| 309 | dev->parent = hdev->parent; | 309 | dev->parent = hdev->parent; |
| 310 | 310 | ||
| 311 | strlcpy(dev->bus_id, hdev->name, BUS_ID_SIZE); | 311 | strlcpy(dev->bus_id, hdev->name, BUS_ID_SIZE); |
| @@ -322,6 +322,10 @@ int hci_register_sysfs(struct hci_dev *hdev) | |||
| 322 | if (device_create_file(dev, bt_attrs[i]) < 0) | 322 | if (device_create_file(dev, bt_attrs[i]) < 0) |
| 323 | BT_ERR("Failed to create device attribute"); | 323 | BT_ERR("Failed to create device attribute"); |
| 324 | 324 | ||
| 325 | if (sysfs_create_link(&bt_class->subsys.kset.kobj, | ||
| 326 | &dev->kobj, kobject_name(&dev->kobj)) < 0) | ||
| 327 | BT_ERR("Failed to create class symlink"); | ||
| 328 | |||
| 325 | return 0; | 329 | return 0; |
| 326 | } | 330 | } |
| 327 | 331 | ||
| @@ -329,6 +333,9 @@ void hci_unregister_sysfs(struct hci_dev *hdev) | |||
| 329 | { | 333 | { |
| 330 | BT_DBG("%p name %s type %d", hdev, hdev->name, hdev->type); | 334 | BT_DBG("%p name %s type %d", hdev, hdev->name, hdev->type); |
| 331 | 335 | ||
| 336 | sysfs_remove_link(&bt_class->subsys.kset.kobj, | ||
| 337 | kobject_name(&hdev->dev.kobj)); | ||
| 338 | |||
| 332 | device_del(&hdev->dev); | 339 | device_del(&hdev->dev); |
| 333 | } | 340 | } |
| 334 | 341 | ||
diff --git a/net/bluetooth/l2cap.c b/net/bluetooth/l2cap.c index a5867879b615..a59b1fb63b76 100644 --- a/net/bluetooth/l2cap.c +++ b/net/bluetooth/l2cap.c | |||
| @@ -954,11 +954,17 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch | |||
| 954 | 954 | ||
| 955 | switch (optname) { | 955 | switch (optname) { |
| 956 | case L2CAP_OPTIONS: | 956 | case L2CAP_OPTIONS: |
| 957 | opts.imtu = l2cap_pi(sk)->imtu; | ||
| 958 | opts.omtu = l2cap_pi(sk)->omtu; | ||
| 959 | opts.flush_to = l2cap_pi(sk)->flush_to; | ||
| 960 | opts.mode = 0x00; | ||
| 961 | |||
| 957 | len = min_t(unsigned int, sizeof(opts), optlen); | 962 | len = min_t(unsigned int, sizeof(opts), optlen); |
| 958 | if (copy_from_user((char *) &opts, optval, len)) { | 963 | if (copy_from_user((char *) &opts, optval, len)) { |
| 959 | err = -EFAULT; | 964 | err = -EFAULT; |
| 960 | break; | 965 | break; |
| 961 | } | 966 | } |
| 967 | |||
| 962 | l2cap_pi(sk)->imtu = opts.imtu; | 968 | l2cap_pi(sk)->imtu = opts.imtu; |
| 963 | l2cap_pi(sk)->omtu = opts.omtu; | 969 | l2cap_pi(sk)->omtu = opts.omtu; |
| 964 | break; | 970 | break; |
diff --git a/net/bluetooth/rfcomm/core.c b/net/bluetooth/rfcomm/core.c index fe7df90eb707..52e04df323ea 100644 --- a/net/bluetooth/rfcomm/core.c +++ b/net/bluetooth/rfcomm/core.c | |||
| @@ -622,7 +622,7 @@ static struct rfcomm_session *rfcomm_session_create(bdaddr_t *src, bdaddr_t *dst | |||
| 622 | bacpy(&addr.l2_bdaddr, src); | 622 | bacpy(&addr.l2_bdaddr, src); |
| 623 | addr.l2_family = AF_BLUETOOTH; | 623 | addr.l2_family = AF_BLUETOOTH; |
| 624 | addr.l2_psm = 0; | 624 | addr.l2_psm = 0; |
| 625 | *err = sock->ops->bind(sock, (struct sockaddr *) &addr, sizeof(addr)); | 625 | *err = kernel_bind(sock, (struct sockaddr *) &addr, sizeof(addr)); |
| 626 | if (*err < 0) | 626 | if (*err < 0) |
| 627 | goto failed; | 627 | goto failed; |
| 628 | 628 | ||
| @@ -643,7 +643,7 @@ static struct rfcomm_session *rfcomm_session_create(bdaddr_t *src, bdaddr_t *dst | |||
| 643 | bacpy(&addr.l2_bdaddr, dst); | 643 | bacpy(&addr.l2_bdaddr, dst); |
| 644 | addr.l2_family = AF_BLUETOOTH; | 644 | addr.l2_family = AF_BLUETOOTH; |
| 645 | addr.l2_psm = htobs(RFCOMM_PSM); | 645 | addr.l2_psm = htobs(RFCOMM_PSM); |
| 646 | *err = sock->ops->connect(sock, (struct sockaddr *) &addr, sizeof(addr), O_NONBLOCK); | 646 | *err = kernel_connect(sock, (struct sockaddr *) &addr, sizeof(addr), O_NONBLOCK); |
| 647 | if (*err == 0 || *err == -EINPROGRESS) | 647 | if (*err == 0 || *err == -EINPROGRESS) |
| 648 | return s; | 648 | return s; |
| 649 | 649 | ||
| @@ -1058,6 +1058,12 @@ static int rfcomm_recv_ua(struct rfcomm_session *s, u8 dlci) | |||
| 1058 | case BT_DISCONN: | 1058 | case BT_DISCONN: |
| 1059 | d->state = BT_CLOSED; | 1059 | d->state = BT_CLOSED; |
| 1060 | __rfcomm_dlc_close(d, 0); | 1060 | __rfcomm_dlc_close(d, 0); |
| 1061 | |||
| 1062 | if (list_empty(&s->dlcs)) { | ||
| 1063 | s->state = BT_DISCONN; | ||
| 1064 | rfcomm_send_disc(s, 0); | ||
| 1065 | } | ||
| 1066 | |||
| 1061 | break; | 1067 | break; |
| 1062 | } | 1068 | } |
| 1063 | } else { | 1069 | } else { |
| @@ -1067,6 +1073,10 @@ static int rfcomm_recv_ua(struct rfcomm_session *s, u8 dlci) | |||
| 1067 | s->state = BT_CONNECTED; | 1073 | s->state = BT_CONNECTED; |
| 1068 | rfcomm_process_connect(s); | 1074 | rfcomm_process_connect(s); |
| 1069 | break; | 1075 | break; |
| 1076 | |||
| 1077 | case BT_DISCONN: | ||
| 1078 | rfcomm_session_put(s); | ||
| 1079 | break; | ||
| 1070 | } | 1080 | } |
| 1071 | } | 1081 | } |
| 1072 | return 0; | 1082 | return 0; |
| @@ -1757,19 +1767,12 @@ static inline void rfcomm_accept_connection(struct rfcomm_session *s) | |||
| 1757 | 1767 | ||
| 1758 | BT_DBG("session %p", s); | 1768 | BT_DBG("session %p", s); |
| 1759 | 1769 | ||
| 1760 | if (sock_create_lite(PF_BLUETOOTH, sock->type, BTPROTO_L2CAP, &nsock)) | 1770 | err = kernel_accept(sock, &nsock, O_NONBLOCK); |
| 1771 | if (err < 0) | ||
| 1761 | return; | 1772 | return; |
| 1762 | 1773 | ||
| 1763 | nsock->ops = sock->ops; | ||
| 1764 | |||
| 1765 | __module_get(nsock->ops->owner); | 1774 | __module_get(nsock->ops->owner); |
| 1766 | 1775 | ||
| 1767 | err = sock->ops->accept(sock, nsock, O_NONBLOCK); | ||
| 1768 | if (err < 0) { | ||
| 1769 | sock_release(nsock); | ||
| 1770 | return; | ||
| 1771 | } | ||
| 1772 | |||
| 1773 | /* Set our callbacks */ | 1776 | /* Set our callbacks */ |
| 1774 | nsock->sk->sk_data_ready = rfcomm_l2data_ready; | 1777 | nsock->sk->sk_data_ready = rfcomm_l2data_ready; |
| 1775 | nsock->sk->sk_state_change = rfcomm_l2state_change; | 1778 | nsock->sk->sk_state_change = rfcomm_l2state_change; |
| @@ -1885,7 +1888,7 @@ static int rfcomm_add_listener(bdaddr_t *ba) | |||
| 1885 | bacpy(&addr.l2_bdaddr, ba); | 1888 | bacpy(&addr.l2_bdaddr, ba); |
| 1886 | addr.l2_family = AF_BLUETOOTH; | 1889 | addr.l2_family = AF_BLUETOOTH; |
| 1887 | addr.l2_psm = htobs(RFCOMM_PSM); | 1890 | addr.l2_psm = htobs(RFCOMM_PSM); |
| 1888 | err = sock->ops->bind(sock, (struct sockaddr *) &addr, sizeof(addr)); | 1891 | err = kernel_bind(sock, (struct sockaddr *) &addr, sizeof(addr)); |
| 1889 | if (err < 0) { | 1892 | if (err < 0) { |
| 1890 | BT_ERR("Bind failed %d", err); | 1893 | BT_ERR("Bind failed %d", err); |
| 1891 | goto failed; | 1894 | goto failed; |
| @@ -1898,7 +1901,7 @@ static int rfcomm_add_listener(bdaddr_t *ba) | |||
| 1898 | release_sock(sk); | 1901 | release_sock(sk); |
| 1899 | 1902 | ||
| 1900 | /* Start listening on the socket */ | 1903 | /* Start listening on the socket */ |
| 1901 | err = sock->ops->listen(sock, 10); | 1904 | err = kernel_listen(sock, 10); |
| 1902 | if (err) { | 1905 | if (err) { |
| 1903 | BT_ERR("Listen failed %d", err); | 1906 | BT_ERR("Listen failed %d", err); |
| 1904 | goto failed; | 1907 | goto failed; |
diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c index 9a7a44fc721f..b2b1cceb102a 100644 --- a/net/bluetooth/rfcomm/tty.c +++ b/net/bluetooth/rfcomm/tty.c | |||
| @@ -517,9 +517,10 @@ static void rfcomm_dev_state_change(struct rfcomm_dlc *dlc, int err) | |||
| 517 | if (dlc->state == BT_CLOSED) { | 517 | if (dlc->state == BT_CLOSED) { |
| 518 | if (!dev->tty) { | 518 | if (!dev->tty) { |
| 519 | if (test_bit(RFCOMM_RELEASE_ONHUP, &dev->flags)) { | 519 | if (test_bit(RFCOMM_RELEASE_ONHUP, &dev->flags)) { |
| 520 | rfcomm_dev_hold(dev); | 520 | if (rfcomm_dev_get(dev->id) == NULL) |
| 521 | rfcomm_dev_del(dev); | 521 | return; |
| 522 | 522 | ||
| 523 | rfcomm_dev_del(dev); | ||
| 523 | /* We have to drop DLC lock here, otherwise | 524 | /* We have to drop DLC lock here, otherwise |
| 524 | rfcomm_dev_put() will dead lock if it's | 525 | rfcomm_dev_put() will dead lock if it's |
| 525 | the last reference. */ | 526 | the last reference. */ |
| @@ -974,8 +975,12 @@ static void rfcomm_tty_hangup(struct tty_struct *tty) | |||
| 974 | 975 | ||
| 975 | rfcomm_tty_flush_buffer(tty); | 976 | rfcomm_tty_flush_buffer(tty); |
| 976 | 977 | ||
| 977 | if (test_bit(RFCOMM_RELEASE_ONHUP, &dev->flags)) | 978 | if (test_bit(RFCOMM_RELEASE_ONHUP, &dev->flags)) { |
| 979 | if (rfcomm_dev_get(dev->id) == NULL) | ||
| 980 | return; | ||
| 978 | rfcomm_dev_del(dev); | 981 | rfcomm_dev_del(dev); |
| 982 | rfcomm_dev_put(dev); | ||
| 983 | } | ||
| 979 | } | 984 | } |
| 980 | 985 | ||
| 981 | static int rfcomm_tty_read_proc(char *buf, char **start, off_t offset, int len, int *eof, void *unused) | 986 | static int rfcomm_tty_read_proc(char *buf, char **start, off_t offset, int len, int *eof, void *unused) |
diff --git a/net/core/dev.c b/net/core/dev.c index f27d4ab181e6..4317c1be4d3f 100644 --- a/net/core/dev.c +++ b/net/core/dev.c | |||
| @@ -2377,9 +2377,9 @@ static int __init dev_proc_init(void) | |||
| 2377 | out: | 2377 | out: |
| 2378 | return rc; | 2378 | return rc; |
| 2379 | out_softnet: | 2379 | out_softnet: |
| 2380 | proc_net_remove("softnet_stat"); | ||
| 2381 | out_dev2: | ||
| 2382 | proc_net_remove("ptype"); | 2380 | proc_net_remove("ptype"); |
| 2381 | out_dev2: | ||
| 2382 | proc_net_remove("softnet_stat"); | ||
| 2383 | out_dev: | 2383 | out_dev: |
| 2384 | proc_net_remove("dev"); | 2384 | proc_net_remove("dev"); |
| 2385 | goto out; | 2385 | goto out; |
diff --git a/net/rfkill/Kconfig b/net/rfkill/Kconfig new file mode 100644 index 000000000000..8b31759ee8b0 --- /dev/null +++ b/net/rfkill/Kconfig | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | # | ||
| 2 | # RF switch subsystem configuration | ||
| 3 | # | ||
| 4 | menuconfig RFKILL | ||
| 5 | tristate "RF switch subsystem support" | ||
| 6 | help | ||
| 7 | Say Y here if you want to have control over RF switches | ||
| 8 | found on many WiFi, Bluetooth and IRDA cards. | ||
| 9 | |||
| 10 | To compile this driver as a module, choose M here: the | ||
| 11 | module will be called rfkill. | ||
| 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. | ||
diff --git a/net/rfkill/Makefile b/net/rfkill/Makefile new file mode 100644 index 000000000000..b38c430be057 --- /dev/null +++ b/net/rfkill/Makefile | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | # | ||
| 2 | # Makefile for the RF switch subsystem. | ||
| 3 | # | ||
| 4 | |||
| 5 | obj-$(CONFIG_RFKILL) += rfkill.o | ||
| 6 | obj-$(CONFIG_RFKILL_INPUT) += rfkill-input.o | ||
diff --git a/net/rfkill/rfkill-input.c b/net/rfkill/rfkill-input.c new file mode 100644 index 000000000000..e5c840c30284 --- /dev/null +++ b/net/rfkill/rfkill-input.c | |||
| @@ -0,0 +1,174 @@ | |||
| 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 | |||
| 20 | MODULE_AUTHOR("Dmitry Torokhov <dtor@mail.ru>"); | ||
| 21 | MODULE_DESCRIPTION("Input layer to RF switch connector"); | ||
| 22 | MODULE_LICENSE("GPL"); | ||
| 23 | |||
| 24 | struct rfkill_task { | ||
| 25 | struct work_struct work; | ||
| 26 | enum rfkill_type type; | ||
| 27 | struct mutex mutex; /* ensures that task is serialized */ | ||
| 28 | spinlock_t lock; /* for accessing last and desired state */ | ||
| 29 | unsigned long last; /* last schedule */ | ||
| 30 | enum rfkill_state desired_state; /* on/off */ | ||
| 31 | enum rfkill_state current_state; /* on/off */ | ||
| 32 | }; | ||
| 33 | |||
| 34 | static void rfkill_task_handler(struct work_struct *work) | ||
| 35 | { | ||
| 36 | struct rfkill_task *task = container_of(work, struct rfkill_task, work); | ||
| 37 | enum rfkill_state state; | ||
| 38 | |||
| 39 | mutex_lock(&task->mutex); | ||
| 40 | |||
| 41 | /* | ||
| 42 | * Use temp variable to fetch desired state to keep it | ||
| 43 | * consistent even if rfkill_schedule_toggle() runs in | ||
| 44 | * another thread or interrupts us. | ||
| 45 | */ | ||
| 46 | state = task->desired_state; | ||
| 47 | |||
| 48 | if (state != task->current_state) { | ||
| 49 | rfkill_switch_all(task->type, state); | ||
| 50 | task->current_state = state; | ||
| 51 | } | ||
| 52 | |||
| 53 | mutex_unlock(&task->mutex); | ||
| 54 | } | ||
| 55 | |||
| 56 | static void rfkill_schedule_toggle(struct rfkill_task *task) | ||
| 57 | { | ||
| 58 | unsigned int flags; | ||
| 59 | |||
| 60 | spin_lock_irqsave(&task->lock, flags); | ||
| 61 | |||
| 62 | if (time_after(jiffies, task->last + msecs_to_jiffies(200))) { | ||
| 63 | task->desired_state = !task->desired_state; | ||
| 64 | task->last = jiffies; | ||
| 65 | schedule_work(&task->work); | ||
| 66 | } | ||
| 67 | |||
| 68 | spin_unlock_irqrestore(&task->lock, flags); | ||
| 69 | } | ||
| 70 | |||
| 71 | #define DEFINE_RFKILL_TASK(n, t) \ | ||
| 72 | struct rfkill_task n = { \ | ||
| 73 | .work = __WORK_INITIALIZER(n.work, \ | ||
| 74 | rfkill_task_handler), \ | ||
| 75 | .type = t, \ | ||
| 76 | .mutex = __MUTEX_INITIALIZER(n.mutex), \ | ||
| 77 | .lock = __SPIN_LOCK_UNLOCKED(n.lock), \ | ||
| 78 | .desired_state = RFKILL_STATE_ON, \ | ||
| 79 | .current_state = RFKILL_STATE_ON, \ | ||
| 80 | } | ||
| 81 | |||
| 82 | static DEFINE_RFKILL_TASK(rfkill_wlan, RFKILL_TYPE_WLAN); | ||
| 83 | static DEFINE_RFKILL_TASK(rfkill_bt, RFKILL_TYPE_BLUETOOTH); | ||
| 84 | |||
| 85 | static void rfkill_event(struct input_handle *handle, unsigned int type, | ||
| 86 | unsigned int code, int down) | ||
| 87 | { | ||
| 88 | if (type == EV_KEY && down == 1) { | ||
| 89 | switch (code) { | ||
| 90 | case KEY_WLAN: | ||
| 91 | rfkill_schedule_toggle(&rfkill_wlan); | ||
| 92 | break; | ||
| 93 | case KEY_BLUETOOTH: | ||
| 94 | rfkill_schedule_toggle(&rfkill_bt); | ||
| 95 | break; | ||
| 96 | default: | ||
| 97 | break; | ||
| 98 | } | ||
| 99 | } | ||
| 100 | } | ||
| 101 | |||
| 102 | static int rfkill_connect(struct input_handler *handler, struct input_dev *dev, | ||
| 103 | const struct input_device_id *id) | ||
| 104 | { | ||
| 105 | struct input_handle *handle; | ||
| 106 | int error; | ||
| 107 | |||
| 108 | handle = kzalloc(sizeof(struct input_handle), GFP_KERNEL); | ||
| 109 | if (!handle) | ||
| 110 | return -ENOMEM; | ||
| 111 | |||
| 112 | handle->dev = dev; | ||
| 113 | handle->handler = handler; | ||
| 114 | handle->name = "rfkill"; | ||
| 115 | |||
| 116 | error = input_register_handle(handle); | ||
| 117 | if (error) | ||
| 118 | goto err_free_handle; | ||
| 119 | |||
| 120 | error = input_open_device(handle); | ||
| 121 | if (error) | ||
| 122 | goto err_unregister_handle; | ||
| 123 | |||
| 124 | return 0; | ||
| 125 | |||
| 126 | err_unregister_handle: | ||
| 127 | input_unregister_handle(handle); | ||
| 128 | err_free_handle: | ||
| 129 | kfree(handle); | ||
| 130 | return error; | ||
| 131 | } | ||
| 132 | |||
| 133 | static void rfkill_disconnect(struct input_handle *handle) | ||
| 134 | { | ||
| 135 | input_close_device(handle); | ||
| 136 | input_unregister_handle(handle); | ||
| 137 | kfree(handle); | ||
| 138 | } | ||
| 139 | |||
| 140 | static const struct input_device_id rfkill_ids[] = { | ||
| 141 | { | ||
| 142 | .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_KEYBIT, | ||
| 143 | .evbit = { BIT(EV_KEY) }, | ||
| 144 | .keybit = { [LONG(KEY_WLAN)] = BIT(KEY_WLAN) }, | ||
| 145 | }, | ||
| 146 | { | ||
| 147 | .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_KEYBIT, | ||
| 148 | .evbit = { BIT(EV_KEY) }, | ||
| 149 | .keybit = { [LONG(KEY_BLUETOOTH)] = BIT(KEY_BLUETOOTH) }, | ||
| 150 | }, | ||
| 151 | { } | ||
| 152 | }; | ||
| 153 | |||
| 154 | static struct input_handler rfkill_handler = { | ||
| 155 | .event = rfkill_event, | ||
| 156 | .connect = rfkill_connect, | ||
| 157 | .disconnect = rfkill_disconnect, | ||
| 158 | .name = "rfkill", | ||
| 159 | .id_table = rfkill_ids, | ||
| 160 | }; | ||
| 161 | |||
| 162 | static int __init rfkill_handler_init(void) | ||
| 163 | { | ||
| 164 | return input_register_handler(&rfkill_handler); | ||
| 165 | } | ||
| 166 | |||
| 167 | static void __exit rfkill_handler_exit(void) | ||
| 168 | { | ||
| 169 | input_unregister_handler(&rfkill_handler); | ||
| 170 | flush_scheduled_work(); | ||
| 171 | } | ||
| 172 | |||
| 173 | module_init(rfkill_handler_init); | ||
| 174 | module_exit(rfkill_handler_exit); | ||
diff --git a/net/rfkill/rfkill.c b/net/rfkill/rfkill.c new file mode 100644 index 000000000000..a973603e3880 --- /dev/null +++ b/net/rfkill/rfkill.c | |||
| @@ -0,0 +1,407 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2006 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 | MODULE_AUTHOR("Ivo van Doorn <IvDoorn@gmail.com>"); | ||
| 31 | MODULE_VERSION("1.0"); | ||
| 32 | MODULE_DESCRIPTION("RF switch support"); | ||
| 33 | MODULE_LICENSE("GPL"); | ||
| 34 | |||
| 35 | static LIST_HEAD(rfkill_list); /* list of registered rf switches */ | ||
| 36 | static DEFINE_MUTEX(rfkill_mutex); | ||
| 37 | |||
| 38 | static enum rfkill_state rfkill_states[RFKILL_TYPE_MAX]; | ||
| 39 | |||
| 40 | static int rfkill_toggle_radio(struct rfkill *rfkill, | ||
| 41 | enum rfkill_state state) | ||
| 42 | { | ||
| 43 | int retval; | ||
| 44 | |||
| 45 | retval = mutex_lock_interruptible(&rfkill->mutex); | ||
| 46 | if (retval) | ||
| 47 | return retval; | ||
| 48 | |||
| 49 | if (state != rfkill->state) { | ||
| 50 | retval = rfkill->toggle_radio(rfkill->data, state); | ||
| 51 | if (!retval) | ||
| 52 | rfkill->state = state; | ||
| 53 | } | ||
| 54 | |||
| 55 | mutex_unlock(&rfkill->mutex); | ||
| 56 | return retval; | ||
| 57 | } | ||
| 58 | |||
| 59 | /** | ||
| 60 | * rfkill_switch_all - Toggle state of all switches of given type | ||
| 61 | * @type: type of interfaces to be affeceted | ||
| 62 | * @state: the new state | ||
| 63 | * | ||
| 64 | * This function toggles state of all switches of given type unless | ||
| 65 | * a specific switch is claimed by userspace in which case it is | ||
| 66 | * left alone. | ||
| 67 | */ | ||
| 68 | |||
| 69 | void rfkill_switch_all(enum rfkill_type type, enum rfkill_state state) | ||
| 70 | { | ||
| 71 | struct rfkill *rfkill; | ||
| 72 | |||
| 73 | mutex_lock(&rfkill_mutex); | ||
| 74 | |||
| 75 | rfkill_states[type] = state; | ||
| 76 | |||
| 77 | list_for_each_entry(rfkill, &rfkill_list, node) { | ||
| 78 | if (!rfkill->user_claim) | ||
| 79 | rfkill_toggle_radio(rfkill, state); | ||
| 80 | } | ||
| 81 | |||
| 82 | mutex_unlock(&rfkill_mutex); | ||
| 83 | } | ||
| 84 | EXPORT_SYMBOL(rfkill_switch_all); | ||
| 85 | |||
| 86 | static ssize_t rfkill_name_show(struct device *dev, | ||
| 87 | struct device_attribute *attr, | ||
| 88 | char *buf) | ||
| 89 | { | ||
| 90 | struct rfkill *rfkill = to_rfkill(dev); | ||
| 91 | |||
| 92 | return sprintf(buf, "%s\n", rfkill->name); | ||
| 93 | } | ||
| 94 | |||
| 95 | static ssize_t rfkill_type_show(struct device *dev, | ||
| 96 | struct device_attribute *attr, | ||
| 97 | char *buf) | ||
| 98 | { | ||
| 99 | struct rfkill *rfkill = to_rfkill(dev); | ||
| 100 | const char *type; | ||
| 101 | |||
| 102 | switch (rfkill->type) { | ||
| 103 | case RFKILL_TYPE_WLAN: | ||
| 104 | type = "wlan"; | ||
| 105 | break; | ||
| 106 | case RFKILL_TYPE_BLUETOOTH: | ||
| 107 | type = "bluetooth"; | ||
| 108 | break; | ||
| 109 | case RFKILL_TYPE_IRDA: | ||
| 110 | type = "irda"; | ||
| 111 | break; | ||
| 112 | default: | ||
| 113 | BUG(); | ||
| 114 | } | ||
| 115 | |||
| 116 | return sprintf(buf, "%s\n", type); | ||
| 117 | } | ||
| 118 | |||
| 119 | static ssize_t rfkill_state_show(struct device *dev, | ||
| 120 | struct device_attribute *attr, | ||
| 121 | char *buf) | ||
| 122 | { | ||
| 123 | struct rfkill *rfkill = to_rfkill(dev); | ||
| 124 | |||
| 125 | return sprintf(buf, "%d\n", rfkill->state); | ||
| 126 | } | ||
| 127 | |||
| 128 | static ssize_t rfkill_state_store(struct device *dev, | ||
| 129 | struct device_attribute *attr, | ||
| 130 | const char *buf, size_t count) | ||
| 131 | { | ||
| 132 | struct rfkill *rfkill = to_rfkill(dev); | ||
| 133 | unsigned int state = simple_strtoul(buf, NULL, 0); | ||
| 134 | int error; | ||
| 135 | |||
| 136 | if (!capable(CAP_NET_ADMIN)) | ||
| 137 | return -EPERM; | ||
| 138 | |||
| 139 | error = rfkill_toggle_radio(rfkill, | ||
| 140 | state ? RFKILL_STATE_ON : RFKILL_STATE_OFF); | ||
| 141 | if (error) | ||
| 142 | return error; | ||
| 143 | |||
| 144 | return count; | ||
| 145 | } | ||
| 146 | |||
| 147 | static ssize_t rfkill_claim_show(struct device *dev, | ||
| 148 | struct device_attribute *attr, | ||
| 149 | char *buf) | ||
| 150 | { | ||
| 151 | struct rfkill *rfkill = to_rfkill(dev); | ||
| 152 | |||
| 153 | return sprintf(buf, "%d", rfkill->user_claim); | ||
| 154 | } | ||
| 155 | |||
| 156 | static ssize_t rfkill_claim_store(struct device *dev, | ||
| 157 | struct device_attribute *attr, | ||
| 158 | const char *buf, size_t count) | ||
| 159 | { | ||
| 160 | struct rfkill *rfkill = to_rfkill(dev); | ||
| 161 | bool claim = !!simple_strtoul(buf, NULL, 0); | ||
| 162 | int error; | ||
| 163 | |||
| 164 | if (!capable(CAP_NET_ADMIN)) | ||
| 165 | return -EPERM; | ||
| 166 | |||
| 167 | /* | ||
| 168 | * Take the global lock to make sure the kernel is not in | ||
| 169 | * the middle of rfkill_switch_all | ||
| 170 | */ | ||
| 171 | error = mutex_lock_interruptible(&rfkill_mutex); | ||
| 172 | if (error) | ||
| 173 | return error; | ||
| 174 | |||
| 175 | if (rfkill->user_claim != claim) { | ||
| 176 | if (!claim) | ||
| 177 | rfkill_toggle_radio(rfkill, | ||
| 178 | rfkill_states[rfkill->type]); | ||
| 179 | rfkill->user_claim = claim; | ||
| 180 | } | ||
| 181 | |||
| 182 | mutex_unlock(&rfkill_mutex); | ||
| 183 | |||
| 184 | return count; | ||
| 185 | } | ||
| 186 | |||
| 187 | static struct device_attribute rfkill_dev_attrs[] = { | ||
| 188 | __ATTR(name, S_IRUGO, rfkill_name_show, NULL), | ||
| 189 | __ATTR(type, S_IRUGO, rfkill_type_show, NULL), | ||
| 190 | __ATTR(state, S_IRUGO, rfkill_state_show, rfkill_state_store), | ||
| 191 | __ATTR(claim, S_IRUGO|S_IWUSR, rfkill_claim_show, rfkill_claim_store), | ||
| 192 | __ATTR_NULL | ||
| 193 | }; | ||
| 194 | |||
| 195 | static void rfkill_release(struct device *dev) | ||
| 196 | { | ||
| 197 | struct rfkill *rfkill = to_rfkill(dev); | ||
| 198 | |||
| 199 | kfree(rfkill); | ||
| 200 | module_put(THIS_MODULE); | ||
| 201 | } | ||
| 202 | |||
| 203 | #ifdef CONFIG_PM | ||
| 204 | static int rfkill_suspend(struct device *dev, pm_message_t state) | ||
| 205 | { | ||
| 206 | struct rfkill *rfkill = to_rfkill(dev); | ||
| 207 | |||
| 208 | if (dev->power.power_state.event != state.event) { | ||
| 209 | if (state.event == PM_EVENT_SUSPEND) { | ||
| 210 | mutex_lock(&rfkill->mutex); | ||
| 211 | |||
| 212 | if (rfkill->state == RFKILL_STATE_ON) | ||
| 213 | rfkill->toggle_radio(rfkill->data, | ||
| 214 | RFKILL_STATE_OFF); | ||
| 215 | |||
| 216 | mutex_unlock(&rfkill->mutex); | ||
| 217 | } | ||
| 218 | |||
| 219 | dev->power.power_state = state; | ||
| 220 | } | ||
| 221 | |||
| 222 | return 0; | ||
| 223 | } | ||
| 224 | |||
| 225 | static int rfkill_resume(struct device *dev) | ||
| 226 | { | ||
| 227 | struct rfkill *rfkill = to_rfkill(dev); | ||
| 228 | |||
| 229 | if (dev->power.power_state.event != PM_EVENT_ON) { | ||
| 230 | mutex_lock(&rfkill->mutex); | ||
| 231 | |||
| 232 | if (rfkill->state == RFKILL_STATE_ON) | ||
| 233 | rfkill->toggle_radio(rfkill->data, RFKILL_STATE_ON); | ||
| 234 | |||
| 235 | mutex_unlock(&rfkill->mutex); | ||
| 236 | } | ||
| 237 | |||
| 238 | dev->power.power_state = PMSG_ON; | ||
| 239 | return 0; | ||
| 240 | } | ||
| 241 | #else | ||
| 242 | #define rfkill_suspend NULL | ||
| 243 | #define rfkill_resume NULL | ||
| 244 | #endif | ||
| 245 | |||
| 246 | static struct class rfkill_class = { | ||
| 247 | .name = "rfkill", | ||
| 248 | .dev_release = rfkill_release, | ||
| 249 | .dev_attrs = rfkill_dev_attrs, | ||
| 250 | .suspend = rfkill_suspend, | ||
| 251 | .resume = rfkill_resume, | ||
| 252 | }; | ||
| 253 | |||
| 254 | static int rfkill_add_switch(struct rfkill *rfkill) | ||
| 255 | { | ||
| 256 | int retval; | ||
| 257 | |||
| 258 | retval = mutex_lock_interruptible(&rfkill_mutex); | ||
| 259 | if (retval) | ||
| 260 | return retval; | ||
| 261 | |||
| 262 | retval = rfkill_toggle_radio(rfkill, rfkill_states[rfkill->type]); | ||
| 263 | if (retval) | ||
| 264 | goto out; | ||
| 265 | |||
| 266 | list_add_tail(&rfkill->node, &rfkill_list); | ||
| 267 | |||
| 268 | out: | ||
| 269 | mutex_unlock(&rfkill_mutex); | ||
| 270 | return retval; | ||
| 271 | } | ||
| 272 | |||
| 273 | static void rfkill_remove_switch(struct rfkill *rfkill) | ||
| 274 | { | ||
| 275 | mutex_lock(&rfkill_mutex); | ||
| 276 | list_del_init(&rfkill->node); | ||
| 277 | rfkill_toggle_radio(rfkill, RFKILL_STATE_OFF); | ||
| 278 | mutex_unlock(&rfkill_mutex); | ||
| 279 | } | ||
| 280 | |||
| 281 | /** | ||
| 282 | * rfkill_allocate - allocate memory for rfkill structure. | ||
| 283 | * @parent: device that has rf switch on it | ||
| 284 | * @type: type of the switch (wlan, bluetooth, irda) | ||
| 285 | * | ||
| 286 | * This function should be called by the network driver when it needs | ||
| 287 | * rfkill structure. Once the structure is allocated the driver shoud | ||
| 288 | * finish its initialization by setting name, private data, enable_radio | ||
| 289 | * and disable_radio methods and then register it with rfkill_register(). | ||
| 290 | * NOTE: If registration fails the structure shoudl be freed by calling | ||
| 291 | * rfkill_free() otherwise rfkill_unregister() should be used. | ||
| 292 | */ | ||
| 293 | struct rfkill *rfkill_allocate(struct device *parent, enum rfkill_type type) | ||
| 294 | { | ||
| 295 | struct rfkill *rfkill; | ||
| 296 | struct device *dev; | ||
| 297 | |||
| 298 | rfkill = kzalloc(sizeof(struct rfkill), GFP_KERNEL); | ||
| 299 | if (rfkill) | ||
| 300 | return NULL; | ||
| 301 | |||
| 302 | mutex_init(&rfkill->mutex); | ||
| 303 | INIT_LIST_HEAD(&rfkill->node); | ||
| 304 | rfkill->type = type; | ||
| 305 | |||
| 306 | dev = &rfkill->dev; | ||
| 307 | dev->class = &rfkill_class; | ||
| 308 | dev->parent = parent; | ||
| 309 | device_initialize(dev); | ||
| 310 | |||
| 311 | __module_get(THIS_MODULE); | ||
| 312 | |||
| 313 | return rfkill; | ||
| 314 | } | ||
| 315 | EXPORT_SYMBOL(rfkill_allocate); | ||
| 316 | |||
| 317 | /** | ||
| 318 | * rfkill_free - Mark rfkill structure for deletion | ||
| 319 | * @rfkill: rfkill structure to be destroyed | ||
| 320 | * | ||
| 321 | * Decrements reference count of rfkill structure so it is destoryed. | ||
| 322 | * Note that rfkill_free() should _not_ be called after rfkill_unregister(). | ||
| 323 | */ | ||
| 324 | void rfkill_free(struct rfkill *rfkill) | ||
| 325 | { | ||
| 326 | if (rfkill) | ||
| 327 | put_device(&rfkill->dev); | ||
| 328 | } | ||
| 329 | EXPORT_SYMBOL(rfkill_free); | ||
| 330 | |||
| 331 | /** | ||
| 332 | * rfkill_register - Register a rfkill structure. | ||
| 333 | * @rfkill: rfkill structure to be registered | ||
| 334 | * | ||
| 335 | * This function should be called by the network driver when the rfkill | ||
| 336 | * structure needs to be registered. Immediately from registration the | ||
| 337 | * switch driver should be able to service calls to toggle_radio. | ||
| 338 | */ | ||
| 339 | int rfkill_register(struct rfkill *rfkill) | ||
| 340 | { | ||
| 341 | static atomic_t rfkill_no = ATOMIC_INIT(0); | ||
| 342 | struct device *dev = &rfkill->dev; | ||
| 343 | int error; | ||
| 344 | |||
| 345 | if (!rfkill->toggle_radio) | ||
| 346 | return -EINVAL; | ||
| 347 | |||
| 348 | error = rfkill_add_switch(rfkill); | ||
| 349 | if (error) | ||
| 350 | return error; | ||
| 351 | |||
| 352 | snprintf(dev->bus_id, sizeof(dev->bus_id), | ||
| 353 | "rfkill%ld", (long)atomic_inc_return(&rfkill_no) - 1); | ||
| 354 | |||
| 355 | error = device_add(dev); | ||
| 356 | if (error) { | ||
| 357 | rfkill_remove_switch(rfkill); | ||
| 358 | return error; | ||
| 359 | } | ||
| 360 | |||
| 361 | return 0; | ||
| 362 | } | ||
| 363 | EXPORT_SYMBOL(rfkill_register); | ||
| 364 | |||
| 365 | /** | ||
| 366 | * rfkill_unregister - Uegister a rfkill structure. | ||
| 367 | * @rfkill: rfkill structure to be unregistered | ||
| 368 | * | ||
| 369 | * This function should be called by the network driver during device | ||
| 370 | * teardown to destroy rfkill structure. Note that rfkill_free() should | ||
| 371 | * _not_ be called after rfkill_unregister(). | ||
| 372 | */ | ||
| 373 | void rfkill_unregister(struct rfkill *rfkill) | ||
| 374 | { | ||
| 375 | device_del(&rfkill->dev); | ||
| 376 | rfkill_remove_switch(rfkill); | ||
| 377 | put_device(&rfkill->dev); | ||
| 378 | } | ||
| 379 | EXPORT_SYMBOL(rfkill_unregister); | ||
| 380 | |||
| 381 | /* | ||
| 382 | * Rfkill module initialization/deinitialization. | ||
| 383 | */ | ||
| 384 | static int __init rfkill_init(void) | ||
| 385 | { | ||
| 386 | int error; | ||
| 387 | int i; | ||
| 388 | |||
| 389 | for (i = 0; i < ARRAY_SIZE(rfkill_states); i++) | ||
| 390 | rfkill_states[i] = RFKILL_STATE_ON; | ||
| 391 | |||
| 392 | error = class_register(&rfkill_class); | ||
| 393 | if (error) { | ||
| 394 | printk(KERN_ERR "rfkill: unable to register rfkill class\n"); | ||
| 395 | return error; | ||
| 396 | } | ||
| 397 | |||
| 398 | return 0; | ||
| 399 | } | ||
| 400 | |||
| 401 | static void __exit rfkill_exit(void) | ||
| 402 | { | ||
| 403 | class_unregister(&rfkill_class); | ||
| 404 | } | ||
| 405 | |||
| 406 | module_init(rfkill_init); | ||
| 407 | module_exit(rfkill_exit); | ||
