From: Christian Lamparter Date: Tue, 25 Jan 2011 14:26:51 +0000 (+0100) Subject: carl9170 firmware: Wake-up on rx'ed Probe Request X-Git-Tag: 1.9.3~10 X-Git-Url: https://jxself.org/git/?p=carl9170fw.git;a=commitdiff_plain;h=439cedcac2fc950f32b120ff2b128968d6fb34ef carl9170 firmware: Wake-up on rx'ed Probe Request 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 --- diff --git a/carlfw/Kconfig b/carlfw/Kconfig index 9a980e3..262c247 100644 --- a/carlfw/Kconfig +++ b/carlfw/Kconfig @@ -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 diff --git a/carlfw/src/main.c b/carlfw/src/main.c index a88338a..16d6029 100644 --- a/carlfw/src/main.c +++ b/carlfw/src/main.c @@ -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 */ diff --git a/carlfw/src/wlan.c b/carlfw/src/wlan.c index c4cf0b3..42d91cc 100644 --- a/carlfw/src/wlan.c +++ b/carlfw/src/wlan.c @@ -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 */ diff --git a/carlfw/usb/main.c b/carlfw/usb/main.c index bd8428a..da0ab80 100644 --- a/carlfw/usb/main.c +++ b/carlfw/usb/main.c @@ -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 */ }