diff options
| author | Heikki Krogerus <heikki.krogerus@linux.intel.com> | 2016-01-25 04:03:46 -0500 |
|---|---|---|
| committer | Johannes Berg <johannes.berg@intel.com> | 2016-02-24 03:12:45 -0500 |
| commit | 648b50dd6abf8e6e5b589bb8e6873a4596389dbe (patch) | |
| tree | e526a0a913b67e209252863132e75c55019c1557 /net/rfkill | |
| parent | 7837a7778268191dae5f6622f2b92b8b37cb8d7f (diff) | |
net: rfkill: add rfkill_find_type function
Helper for finding the type based on name. Useful if the
type needs to be determined based on device property.
Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
[modify rfkill_types array and BUILD_BUG_ON to not cause errors]
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Diffstat (limited to 'net/rfkill')
| -rw-r--r-- | net/rfkill/core.c | 58 |
1 files changed, 30 insertions, 28 deletions
diff --git a/net/rfkill/core.c b/net/rfkill/core.c index a805831d5d9b..2a23479a49f2 100644 --- a/net/rfkill/core.c +++ b/net/rfkill/core.c | |||
| @@ -572,6 +572,34 @@ void rfkill_set_states(struct rfkill *rfkill, bool sw, bool hw) | |||
| 572 | } | 572 | } |
| 573 | EXPORT_SYMBOL(rfkill_set_states); | 573 | EXPORT_SYMBOL(rfkill_set_states); |
| 574 | 574 | ||
| 575 | static const char * const rfkill_types[] = { | ||
| 576 | NULL, /* RFKILL_TYPE_ALL */ | ||
| 577 | "wlan", | ||
| 578 | "bluetooth", | ||
| 579 | "ultrawideband", | ||
| 580 | "wimax", | ||
| 581 | "wwan", | ||
| 582 | "gps", | ||
| 583 | "fm", | ||
| 584 | "nfc", | ||
| 585 | }; | ||
| 586 | |||
| 587 | enum rfkill_type rfkill_find_type(const char *name) | ||
| 588 | { | ||
| 589 | int i; | ||
| 590 | |||
| 591 | BUILD_BUG_ON(ARRAY_SIZE(rfkill_types) != NUM_RFKILL_TYPES); | ||
| 592 | |||
| 593 | if (!name) | ||
| 594 | return RFKILL_TYPE_ALL; | ||
| 595 | |||
| 596 | for (i = 1; i < NUM_RFKILL_TYPES; i++) | ||
| 597 | if (!strcmp(name, rfkill_types[i])) | ||
| 598 | return i; | ||
| 599 | return RFKILL_TYPE_ALL; | ||
| 600 | } | ||
| 601 | EXPORT_SYMBOL(rfkill_find_type); | ||
| 602 | |||
| 575 | static ssize_t name_show(struct device *dev, struct device_attribute *attr, | 603 | static ssize_t name_show(struct device *dev, struct device_attribute *attr, |
| 576 | char *buf) | 604 | char *buf) |
| 577 | { | 605 | { |
| @@ -581,38 +609,12 @@ static ssize_t name_show(struct device *dev, struct device_attribute *attr, | |||
| 581 | } | 609 | } |
| 582 | static DEVICE_ATTR_RO(name); | 610 | static DEVICE_ATTR_RO(name); |
| 583 | 611 | ||
| 584 | static const char *rfkill_get_type_str(enum rfkill_type type) | ||
| 585 | { | ||
| 586 | BUILD_BUG_ON(NUM_RFKILL_TYPES != RFKILL_TYPE_NFC + 1); | ||
| 587 | |||
| 588 | switch (type) { | ||
| 589 | case RFKILL_TYPE_WLAN: | ||
| 590 | return "wlan"; | ||
| 591 | case RFKILL_TYPE_BLUETOOTH: | ||
| 592 | return "bluetooth"; | ||
| 593 | case RFKILL_TYPE_UWB: | ||
| 594 | return "ultrawideband"; | ||
| 595 | case RFKILL_TYPE_WIMAX: | ||
| 596 | return "wimax"; | ||
| 597 | case RFKILL_TYPE_WWAN: | ||
| 598 | return "wwan"; | ||
| 599 | case RFKILL_TYPE_GPS: | ||
| 600 | return "gps"; | ||
| 601 | case RFKILL_TYPE_FM: | ||
| 602 | return "fm"; | ||
| 603 | case RFKILL_TYPE_NFC: | ||
| 604 | return "nfc"; | ||
| 605 | default: | ||
| 606 | BUG(); | ||
| 607 | } | ||
| 608 | } | ||
| 609 | |||
| 610 | static ssize_t type_show(struct device *dev, struct device_attribute *attr, | 612 | static ssize_t type_show(struct device *dev, struct device_attribute *attr, |
| 611 | char *buf) | 613 | char *buf) |
| 612 | { | 614 | { |
| 613 | struct rfkill *rfkill = to_rfkill(dev); | 615 | struct rfkill *rfkill = to_rfkill(dev); |
| 614 | 616 | ||
| 615 | return sprintf(buf, "%s\n", rfkill_get_type_str(rfkill->type)); | 617 | return sprintf(buf, "%s\n", rfkill_types[rfkill->type]); |
| 616 | } | 618 | } |
| 617 | static DEVICE_ATTR_RO(type); | 619 | static DEVICE_ATTR_RO(type); |
| 618 | 620 | ||
| @@ -750,7 +752,7 @@ static int rfkill_dev_uevent(struct device *dev, struct kobj_uevent_env *env) | |||
| 750 | if (error) | 752 | if (error) |
| 751 | return error; | 753 | return error; |
| 752 | error = add_uevent_var(env, "RFKILL_TYPE=%s", | 754 | error = add_uevent_var(env, "RFKILL_TYPE=%s", |
| 753 | rfkill_get_type_str(rfkill->type)); | 755 | rfkill_types[rfkill->type]); |
| 754 | if (error) | 756 | if (error) |
| 755 | return error; | 757 | return error; |
| 756 | spin_lock_irqsave(&rfkill->lock, flags); | 758 | spin_lock_irqsave(&rfkill->lock, flags); |
