Commit 648b50dd authored by Heikki Krogerus's avatar Heikki Krogerus Committed by Johannes Berg

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: default avatarHeikki Krogerus <heikki.krogerus@linux.intel.com>
[modify rfkill_types array and BUILD_BUG_ON to not cause errors]
Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
parent 7837a777
...@@ -213,6 +213,15 @@ void rfkill_set_states(struct rfkill *rfkill, bool sw, bool hw); ...@@ -213,6 +213,15 @@ void rfkill_set_states(struct rfkill *rfkill, bool sw, bool hw);
* @rfkill: rfkill struct to query * @rfkill: rfkill struct to query
*/ */
bool rfkill_blocked(struct rfkill *rfkill); bool rfkill_blocked(struct rfkill *rfkill);
/**
* rfkill_find_type - Helpper for finding rfkill type by name
* @name: the name of the type
*
* Returns enum rfkill_type that conrresponds the name.
*/
enum rfkill_type rfkill_find_type(const char *name);
#else /* !RFKILL */ #else /* !RFKILL */
static inline struct rfkill * __must_check static inline struct rfkill * __must_check
rfkill_alloc(const char *name, rfkill_alloc(const char *name,
...@@ -269,6 +278,12 @@ static inline bool rfkill_blocked(struct rfkill *rfkill) ...@@ -269,6 +278,12 @@ static inline bool rfkill_blocked(struct rfkill *rfkill)
{ {
return false; return false;
} }
static inline enum rfkill_type rfkill_find_type(const char *name)
{
return RFKILL_TYPE_ALL;
}
#endif /* RFKILL || RFKILL_MODULE */ #endif /* RFKILL || RFKILL_MODULE */
......
...@@ -572,6 +572,34 @@ void rfkill_set_states(struct rfkill *rfkill, bool sw, bool hw) ...@@ -572,6 +572,34 @@ void rfkill_set_states(struct rfkill *rfkill, bool sw, bool hw)
} }
EXPORT_SYMBOL(rfkill_set_states); EXPORT_SYMBOL(rfkill_set_states);
static const char * const rfkill_types[] = {
NULL, /* RFKILL_TYPE_ALL */
"wlan",
"bluetooth",
"ultrawideband",
"wimax",
"wwan",
"gps",
"fm",
"nfc",
};
enum rfkill_type rfkill_find_type(const char *name)
{
int i;
BUILD_BUG_ON(ARRAY_SIZE(rfkill_types) != NUM_RFKILL_TYPES);
if (!name)
return RFKILL_TYPE_ALL;
for (i = 1; i < NUM_RFKILL_TYPES; i++)
if (!strcmp(name, rfkill_types[i]))
return i;
return RFKILL_TYPE_ALL;
}
EXPORT_SYMBOL(rfkill_find_type);
static ssize_t name_show(struct device *dev, struct device_attribute *attr, static ssize_t name_show(struct device *dev, struct device_attribute *attr,
char *buf) char *buf)
{ {
...@@ -581,38 +609,12 @@ static ssize_t name_show(struct device *dev, struct device_attribute *attr, ...@@ -581,38 +609,12 @@ static ssize_t name_show(struct device *dev, struct device_attribute *attr,
} }
static DEVICE_ATTR_RO(name); static DEVICE_ATTR_RO(name);
static const char *rfkill_get_type_str(enum rfkill_type type)
{
BUILD_BUG_ON(NUM_RFKILL_TYPES != RFKILL_TYPE_NFC + 1);
switch (type) {
case RFKILL_TYPE_WLAN:
return "wlan";
case RFKILL_TYPE_BLUETOOTH:
return "bluetooth";
case RFKILL_TYPE_UWB:
return "ultrawideband";
case RFKILL_TYPE_WIMAX:
return "wimax";
case RFKILL_TYPE_WWAN:
return "wwan";
case RFKILL_TYPE_GPS:
return "gps";
case RFKILL_TYPE_FM:
return "fm";
case RFKILL_TYPE_NFC:
return "nfc";
default:
BUG();
}
}
static ssize_t type_show(struct device *dev, struct device_attribute *attr, static ssize_t type_show(struct device *dev, struct device_attribute *attr,
char *buf) char *buf)
{ {
struct rfkill *rfkill = to_rfkill(dev); struct rfkill *rfkill = to_rfkill(dev);
return sprintf(buf, "%s\n", rfkill_get_type_str(rfkill->type)); return sprintf(buf, "%s\n", rfkill_types[rfkill->type]);
} }
static DEVICE_ATTR_RO(type); static DEVICE_ATTR_RO(type);
...@@ -750,7 +752,7 @@ static int rfkill_dev_uevent(struct device *dev, struct kobj_uevent_env *env) ...@@ -750,7 +752,7 @@ static int rfkill_dev_uevent(struct device *dev, struct kobj_uevent_env *env)
if (error) if (error)
return error; return error;
error = add_uevent_var(env, "RFKILL_TYPE=%s", error = add_uevent_var(env, "RFKILL_TYPE=%s",
rfkill_get_type_str(rfkill->type)); rfkill_types[rfkill->type]);
if (error) if (error)
return error; return error;
spin_lock_irqsave(&rfkill->lock, flags); spin_lock_irqsave(&rfkill->lock, flags);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment