瀏覽代碼

rfkill: add function to query state

Sometimes it is necessary to know how the state is,
and it is easier to query rfkill than keep track of
it somewhere else, so add a function for that. This
could later be expanded to return hard/soft block,
but so far that isn't necessary.

Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
Johannes Berg 16 年之前
父節點
當前提交
6081162e2e
共有 2 個文件被更改,包括 25 次插入0 次删除
  1. 12 0
      include/linux/rfkill.h
  2. 13 0
      net/rfkill/core.c

+ 12 - 0
include/linux/rfkill.h

@@ -261,6 +261,13 @@ void rfkill_set_states(struct rfkill *rfkill, bool sw, bool hw);
  *	registered drivers?
  *	registered drivers?
  */
  */
 void rfkill_set_global_sw_state(const enum rfkill_type type, bool blocked);
 void rfkill_set_global_sw_state(const enum rfkill_type type, bool blocked);
+
+/**
+ * rfkill_blocked - query rfkill block
+ *
+ * @rfkill: rfkill struct to query
+ */
+bool rfkill_blocked(struct rfkill *rfkill);
 #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,
@@ -313,6 +320,11 @@ static inline void rfkill_set_global_sw_state(const enum rfkill_type type,
 					      bool blocked)
 					      bool blocked)
 {
 {
 }
 }
+
+static inline bool rfkill_blocked(struct rfkill *rfkill)
+{
+	return false;
+}
 #endif /* RFKILL || RFKILL_MODULE */
 #endif /* RFKILL || RFKILL_MODULE */
 
 
 
 

+ 13 - 0
net/rfkill/core.c

@@ -773,6 +773,19 @@ static struct class rfkill_class = {
 	.resume		= rfkill_resume,
 	.resume		= rfkill_resume,
 };
 };
 
 
+bool rfkill_blocked(struct rfkill *rfkill)
+{
+	unsigned long flags;
+	u32 state;
+
+	spin_lock_irqsave(&rfkill->lock, flags);
+	state = rfkill->state;
+	spin_unlock_irqrestore(&rfkill->lock, flags);
+
+	return !!(state & RFKILL_BLOCK_ANY);
+}
+EXPORT_SYMBOL(rfkill_blocked);
+
 
 
 struct rfkill * __must_check rfkill_alloc(const char *name,
 struct rfkill * __must_check rfkill_alloc(const char *name,
 					  struct device *parent,
 					  struct device *parent,