carl9170 firmware: Wake-up on rx'ed Probe Request
authorChristian Lamparter <chunkeey@googlemail.com>
Tue, 25 Jan 2011 14:26:51 +0000 (15:26 +0100)
committerChristian Lamparter <chunkeey@googlemail.com>
Tue, 25 Jan 2011 14:36:46 +0000 (15:36 +0100)
This option allows the firmware to wakeup the host,
when it receives a probe request for a given SSID.

The advantage of this solution is that it works with
almost all client devices and various operating
systems. No special injection or [unencrypted] network
setup is required, just "active scan".

Signed-off-by: Christian Lamparter <chunkeey@googlemail.com>
carlfw/Kconfig
carlfw/src/main.c
carlfw/src/wlan.c
carlfw/usb/main.c

index 9a980e36268ad211186ed0e7c28597e3d1f1823b..262c2471ec65e476a536543d76988af856c4a7fa 100644 (file)
@@ -157,7 +157,7 @@ config CARL9170FW_TX_AMPDU
        prompt "Firmware-supported ampdu scheduling"
        depends on CARL9170FW_EXPERIMENTAL
 
-config CARL9170FW_WOL
+config CARL9170FW_WOL_OPTION
        def_bool n
        prompt "Wakeup on WLAN"
        depends on CARL9170FW_EXPERIMENTAL
@@ -166,6 +166,32 @@ config CARL9170FW_WOL
         suspended hosts... As long as they fully support
         USB remote wakeup.
 
+config CARL9170FW_WOL
+       def_bool n
+       depends on CARL9170FW_WOL_OPTION
+
+config CARL9170FW_WOL_MAGIC_PACKET
+       def_bool n
+       prompt "Magic Packet(tm)"
+       depends on CARL9170FW_WOL_OPTION
+       select CARL9170FW_WOL
+       ---help---
+        Sniff all incoming data frames for the magic packet pattern.
+
+config CARL9170FW_WOL_PROBE_REQUEST
+       def_bool n
+       prompt "Probe Request"
+       depends on CARL9170FW_WOL_OPTION
+       select CARL9170FW_WOL_CHECK
+       ---help---
+        Scan probe requests for a given SSID.
+
+config CARL9170FW_WOL_PROBE_REQUEST_SSID
+       string
+       prompt "Wakeup on WLAN SSID"
+       default "CARL9170_WAKEUP"
+       depends on CARL9170FW_WOL_PROBE_REQUEST
+
 config CARL9170FW_VIFS_NUM
        default 1
        int
index a88338ac79bfd7b7e839295fc9fc6800bc1a63ef..16d6029a7912cb368f8883b0b3b6e1fe72986ec1 100644 (file)
@@ -106,8 +106,6 @@ static void timer0_isr(void)
        gpio_timer();
 #endif /* CONFIG_CARL9170FW_GPIO_INTERRUPT */
 
-       usb_timer();
-
 #ifdef CONFIG_CARL9170FW_DEBUG_LED_HEARTBEAT
        set(AR9170_GPIO_REG_PORT_DATA, get(AR9170_GPIO_REG_PORT_DATA) ^ 1);
 #endif /* CONFIG_CARL9170FW_DEBUG_LED_HEARTBEAT */
index c4cf0b3dfb0062b9957e706ab1ea76f1ea32a3f3..42d91cca66facd2074b219f2c7b637978ffdc191 100644 (file)
@@ -644,7 +644,9 @@ static void wlan_check_rx_overrun(void)
 }
 
 #ifdef CONFIG_CARL9170FW_WOL
-static void wlan_rx_wol(struct ieee80211_hdr *hdr, unsigned int len)
+
+#ifdef CONFIG_CARL9170FW_WOL_MAGIC_PACKET
+static bool wlan_rx_wol_magic_packet(struct ieee80211_hdr *hdr, unsigned int len)
 {
        const unsigned char *data, *end, *mac;
        unsigned int found = 0;
@@ -709,14 +711,81 @@ static void wlan_rx_wol(struct ieee80211_hdr *hdr, unsigned int len)
                }
 
                if (found == (6 + 16 * 6)) {
-                       fw.suspend_mode = CARL9170_AWAKE_HOST;
-                       return;
+                       return true;
                }
 
                data++;
        }
 
-       return;
+       return false;
+}
+#endif /* CONFIG_CARL9170FW_WOL_MAGIC_PACKET */
+
+#ifdef CONFIG_CARL9170FW_WOL_PROBE_REQUEST
+
+/*
+ * Note: CONFIG_CARL9170FW_WOL_PROBE_REQUEST_SSID is not a real
+ * string. We have to be careful not to add a \0 at the end.
+ */
+static const struct {
+       u8 ssid_ie;
+       u8 ssid_len;
+       u8 ssid[sizeof(CONFIG_CARL9170FW_WOL_PROBE_REQUEST_SSID) - 1];
+} __packed probe_req = {
+       .ssid_ie = WLAN_EID_SSID,
+       .ssid_len = sizeof(CONFIG_CARL9170FW_WOL_PROBE_REQUEST_SSID) - 1,
+       .ssid = CONFIG_CARL9170FW_WOL_PROBE_REQUEST_SSID,
+};
+
+static bool wlan_rx_wol_probe_ssid(struct ieee80211_hdr *hdr, unsigned int len)
+{
+       const unsigned char *data, *end, *scan = (void *) &probe_req;
+
+       /*
+        * IEEE 802.11-2007 7.3.2.1 specifies that the SSID is no
+        * longer than 32 octets.
+        */
+       BUILD_BUG_ON((sizeof(CONFIG_CARL9170FW_WOL_PROBE_REQUEST_SSID) - 1) > 32);
+
+       if (ieee80211_is_probe_req(hdr->frame_control)) {
+               unsigned int i;
+               end = (u8 *)((unsigned long)hdr + len);
+
+               /*
+                * The position of the SSID information element inside
+                * a probe request frame is more or less "fixed".
+                */
+               data = (u8 *)((struct ieee80211_mgmt *)hdr)->u.probe_req.variable;
+               for (i = 0; i < (unsigned int)(probe_req.ssid_len + 1); i++) {
+                       if (scan[i] != data[i])
+                               return false;
+               }
+
+               return true;
+       }
+
+       return false;
+}
+#endif /* CONFIG_CARL9170FW_WOL_PROBE_REQUEST */
+
+static void wlan_rx_wol(unsigned int rx_filter __unused, struct ieee80211_hdr *hdr __unused, unsigned int len __unused)
+{
+       bool __unused wake_up = false;
+
+#ifdef CONFIG_CARL9170FW_WOL_MAGIC_PACKET
+       if (rx_filter & CARL9170_RX_FILTER_DATA)
+               wake_up |= wlan_rx_wol_magic_packet(hdr, len);
+#endif /* CONFIG_CARL9170FW_WOL_MAGIC_PACKET */
+
+#ifdef CONFIG_CARL9170FW_WOL_PROBE_REQUEST
+       if (rx_filter & CARL9170_RX_FILTER_MGMT)
+               wake_up |= wlan_rx_wol_probe_ssid(hdr, len);
+#endif /* CONFIG_CARL9170FW_WOL_PROBE_REQUEST */
+
+       if (wake_up) {
+               fw.suspend_mode = CARL9170_AWAKE_HOST;
+               set(AR9170_USB_REG_WAKE_UP, AR9170_USB_WAKE_UP_WAKE);
+       }
 }
 #endif /* CONFIG_CARL9170FW_WOL */
 
@@ -776,9 +845,8 @@ static unsigned int wlan_rx_filter(struct dma_desc *desc)
 
 #ifdef CONFIG_CARL9170FW_WOL
        if (unlikely(fw.suspend_mode == CARL9170_HOST_SUSPENDED)) {
-               if (rx_filter & CARL9170_RX_FILTER_DATA)
-                       wlan_rx_wol(hdr, min(data_len,
-                                   (unsigned int)AR9170_BLOCK_SIZE));
+               wlan_rx_wol(rx_filter, hdr, min(data_len,
+                           (unsigned int)AR9170_BLOCK_SIZE));
        }
 #endif /* CONFIG_CARL9170FW_WOL */
 
index bd8428a0e39a2940f24daec3a9f8815e22bac445..da0ab802ab42b1d198c72bfbf7f660119f80cf3d 100644 (file)
@@ -420,9 +420,4 @@ void handle_usb(void)
 
 void usb_timer(void)
 {
-#ifdef CONFIG_CARL9170FW_WOL
-       if (fw.suspend_mode == CARL9170_AWAKE_HOST) {
-               set(AR9170_USB_REG_WAKE_UP, AR9170_USB_WAKE_UP_WAKE);
-       }
-#endif /* CONFIG_CARL9170FW_WOL */
 }