wake_on_wifi.h revision 8d6b59704591ba9fad57751858835dc332dbdd37
1d03b95db5d05928ea63fc9f8aac5151e93c43a2fSamuel Tan// Copyright 2014 The Chromium OS Authors. All rights reserved.
2d03b95db5d05928ea63fc9f8aac5151e93c43a2fSamuel Tan// Use of this source code is governed by a BSD-style license that can be
3d03b95db5d05928ea63fc9f8aac5151e93c43a2fSamuel Tan// found in the LICENSE file.
4d03b95db5d05928ea63fc9f8aac5151e93c43a2fSamuel Tan
5d03b95db5d05928ea63fc9f8aac5151e93c43a2fSamuel Tan#ifndef SHILL_WAKE_ON_WIFI_H_
6d03b95db5d05928ea63fc9f8aac5151e93c43a2fSamuel Tan#define SHILL_WAKE_ON_WIFI_H_
7d03b95db5d05928ea63fc9f8aac5151e93c43a2fSamuel Tan
83a9c098afcd0456734092388d4aa7275716d33aaSamuel Tan#include <linux/if_ether.h>
93a9c098afcd0456734092388d4aa7275716d33aaSamuel Tan#include <netinet/ip.h>
103a9c098afcd0456734092388d4aa7275716d33aaSamuel Tan#include <netinet/ip6.h>
113a9c098afcd0456734092388d4aa7275716d33aaSamuel Tan
125f4b175bca4a997f186010c177c44489c8ae95b4Samuel Tan#include <set>
13cb3ecf321c52de1e72cdf037a459cd893b7c51dbSamuel Tan#include <string>
143a9c098afcd0456734092388d4aa7275716d33aaSamuel Tan#include <utility>
153a9c098afcd0456734092388d4aa7275716d33aaSamuel Tan#include <vector>
163a9c098afcd0456734092388d4aa7275716d33aaSamuel Tan
173a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan#include <base/cancelable_callback.h>
183a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan#include <gtest/gtest_prod.h>  // for FRIEND_TEST
193a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan#include <base/memory/ref_counted.h>
203a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan#include <base/memory/weak_ptr.h>
213a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan
223a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan#include "shill/callbacks.h"
233a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan#include "shill/ip_address_store.h"
248d6b59704591ba9fad57751858835dc332dbdd37Peter Qiu#include "shill/net/ip_address.h"
25742866741cd8902bfabd3d9731ccc6b4d5052de6Samuel Tan#include "shill/netlink_manager.h"
263a9c098afcd0456734092388d4aa7275716d33aaSamuel Tan#include "shill/refptr_types.h"
273a9c098afcd0456734092388d4aa7275716d33aaSamuel Tan
28d03b95db5d05928ea63fc9f8aac5151e93c43a2fSamuel Tannamespace shill {
29d03b95db5d05928ea63fc9f8aac5151e93c43a2fSamuel Tan
30d03b95db5d05928ea63fc9f8aac5151e93c43a2fSamuel Tanclass ByteString;
31d03b95db5d05928ea63fc9f8aac5151e93c43a2fSamuel Tanclass Error;
323a1bf99b484ad8a9a054518f49046221251d5612Samuel Tanclass EventDispatcher;
333a9c098afcd0456734092388d4aa7275716d33aaSamuel Tanclass GetWakeOnPacketConnMessage;
34a757752df1b85d8af4590b64d0946b7b2bb0779fSamuel Tanclass Manager;
353a9c098afcd0456734092388d4aa7275716d33aaSamuel Tanclass Nl80211Message;
36d03b95db5d05928ea63fc9f8aac5151e93c43a2fSamuel Tanclass SetWakeOnPacketConnMessage;
373a1bf99b484ad8a9a054518f49046221251d5612Samuel Tanclass WiFi;
383a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan
393a1bf99b484ad8a9a054518f49046221251d5612Samuel Tanclass WakeOnWiFi {
403a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan public:
41a757752df1b85d8af4590b64d0946b7b2bb0779fSamuel Tan  WakeOnWiFi(NetlinkManager *netlink_manager, EventDispatcher *dispatcher,
42a757752df1b85d8af4590b64d0946b7b2bb0779fSamuel Tan             Manager *manager);
43fb02175e039a683cf9ac875ba0924858de6a08ffSamuel Tan  virtual ~WakeOnWiFi();
443a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan
453a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Types of triggers that can cause the NIC to wake the WiFi device.
463a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  enum WakeOnWiFiTrigger { kIPAddress, kDisconnect };
473a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan
483a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Enable the NIC to wake on packets received from |ip_endpoint|.
493a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Note: The actual programming of the NIC only happens before the system
503a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // suspends, in |OnBeforeSuspend|.
513a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  void AddWakeOnPacketConnection(const IPAddress &ip_endpoint, Error *error);
523a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Remove rule to wake on packets received from |ip_endpoint| from the NIC.
533a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Note: The actual programming of the NIC only happens before the system
543a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // suspends, in |OnBeforeSuspend|.
553a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  void RemoveWakeOnPacketConnection(const IPAddress &ip_endpoint, Error *error);
563a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Remove all rules to wake on incoming packets from the NIC.
573a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Note: The actual programming of the NIC only happens before the system
583a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // suspends, in |OnBeforeSuspend|.
593a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  void RemoveAllWakeOnPacketConnections(Error *error);
603a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Given a NL80211_CMD_NEW_WIPHY message |nl80211_message|, parses the
613a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // wake on wifi capabilities of the NIC and set relevant members of this
623a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // WakeOnWiFi object to reflect the supported capbilities.
633a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  void ParseWakeOnWiFiCapabilities(const Nl80211Message &nl80211_message);
643a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Given a NL80211_CMD_NEW_WIPHY message |nl80211_message|, parses the
653a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // wiphy index of the NIC and sets |wiphy_index_| with the parsed index.
663a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  void ParseWiphyIndex(const Nl80211Message &nl80211_message);
673a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Performs pre-suspend actions relevant to wake on wireless functionality.
68fb02175e039a683cf9ac875ba0924858de6a08ffSamuel Tan  virtual void OnBeforeSuspend(const ResultCallback &callback);
693a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Performs post-resume actions relevant to wake on wireless functionality.
70fb02175e039a683cf9ac875ba0924858de6a08ffSamuel Tan  virtual void OnAfterResume();
713a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan
723a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan private:
733a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  friend class WakeOnWiFiTest;  // access to several members for tests
743a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  friend class WiFiObjectTest;  // netlink_manager_
75fb02175e039a683cf9ac875ba0924858de6a08ffSamuel Tan  // Tests that need kWakeOnWiFiDisabled.
76fb02175e039a683cf9ac875ba0924858de6a08ffSamuel Tan  FRIEND_TEST(WakeOnWiFiTest, AddWakeOnPacketConnection_ReturnsError);
77fb02175e039a683cf9ac875ba0924858de6a08ffSamuel Tan  FRIEND_TEST(WakeOnWiFiTest, RemoveWakeOnPacketConnection_ReturnsError);
78fb02175e039a683cf9ac875ba0924858de6a08ffSamuel Tan  FRIEND_TEST(WakeOnWiFiTest, RemoveAllWakeOnPacketConnections_ReturnsError);
793a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  FRIEND_TEST(WakeOnWiFiTest, ParseWiphyIndex_Success);  // kDefaultWiphyIndex
80fb02175e039a683cf9ac875ba0924858de6a08ffSamuel Tan  // Tests that need kMaxSetWakeOnPacketRetries.
813a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  FRIEND_TEST(WakeOnWiFiTest,
823a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan              RetrySetWakeOnPacketConnections_LessThanMaxRetries);
833a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  FRIEND_TEST(WakeOnWiFiTest,
843a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan              RetrySetWakeOnPacketConnections_MaxAttemptsWithCallbackSet);
853a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  FRIEND_TEST(WakeOnWiFiTest,
863a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan              RetrySetWakeOnPacketConnections_MaxAttemptsCallbackUnset);
873a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan
88fb02175e039a683cf9ac875ba0924858de6a08ffSamuel Tan  static const char kWakeOnIPAddressPatternsNotSupported[];
89fb02175e039a683cf9ac875ba0924858de6a08ffSamuel Tan  static const char kWakeOnPacketDisabled[];
90fb02175e039a683cf9ac875ba0924858de6a08ffSamuel Tan  static const char kWakeOnWiFiDisabled[];
913a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  static const uint32_t kDefaultWiphyIndex;
923a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  static const int kVerifyWakeOnWiFiSettingsDelaySeconds;
933a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  static const int kMaxSetWakeOnPacketRetries;
943a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan
95740ee07e13d98ee9e0535ffea391326c8da13499Samuel Tan  // Helper function to run and reset |suspend_actions_done_callback_|.
96740ee07e13d98ee9e0535ffea391326c8da13499Samuel Tan  void RunAndResetSuspendActionsDoneCallback(const Error &error);
973a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Used for comparison of ByteString pairs in a set.
983a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  static bool ByteStringPairIsLessThan(
993a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan      const std::pair<ByteString, ByteString> &lhs,
1003a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan      const std::pair<ByteString, ByteString> &rhs);
1013a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Creates a mask which specifies which bytes in pattern of length
1023a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // |pattern_len| to match against. Bits |offset| to |pattern_len| - 1 are set,
1033a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // which bits 0 to bits 0 to |offset| - 1 are unset. This mask is saved in
1043a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // |mask|.
1053a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  static void SetMask(ByteString *mask, uint32_t pattern_len, uint32_t offset);
1063a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Creates a pattern and mask for a NL80211 message that programs the NIC to
1073a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // wake on packets originating from IP address |ip_addr|. The pattern and mask
1083a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // are saved in |pattern| and |mask| respectively. Returns true iff the
1093a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // pattern and mask are successfully created and written to |pattern| and
1103a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // |mask| respectively.
1113a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  static bool CreateIPAddressPatternAndMask(const IPAddress &ip_addr,
1123a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan                                            ByteString *pattern,
1133a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan                                            ByteString *mask);
1143a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  static void CreateIPV4PatternAndMask(const IPAddress &ip_addr,
1153a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan                                       ByteString *pattern, ByteString *mask);
1163a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  static void CreateIPV6PatternAndMask(const IPAddress &ip_addr,
1173a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan                                       ByteString *pattern, ByteString *mask);
1183a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Creates and sets an attribute in a NL80211 message |msg| which indicates
1193a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // the index of the wiphy interface to program. Returns true iff |msg| is
1203a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // successfully configured.
1213a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  static bool ConfigureWiphyIndex(Nl80211Message *msg, int32_t index);
1223a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Creates and sets attributes in an SetWakeOnPacketConnMessage |msg| so that
1233a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // the message will disable wake-on-packet functionality of the NIC with wiphy
1243a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // index |wiphy_index|. Returns true iff |msg| is successfully configured.
1253a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // NOTE: Assumes that |msg| has not been altered since construction.
1263a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  static bool ConfigureDisableWakeOnWiFiMessage(SetWakeOnPacketConnMessage *msg,
1273a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan                                                uint32_t wiphy_index,
1283a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan                                                Error *error);
1293a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Creates and sets attributes in a SetWakeOnPacketConnMessage |msg|
1303a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // so that the message will program the NIC with wiphy index |wiphy_index|
1313a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // with wake on wireless triggers in |trigs|. If |trigs| contains the
1323a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // kIPAddress trigger, the NIC is programmed to wake on packets from the
1333a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // IP addresses in |addrs|. Returns true iff |msg| is successfully configured.
1343a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // NOTE: Assumes that |msg| has not been altered since construction.
1353a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  static bool ConfigureSetWakeOnWiFiSettingsMessage(
1363a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan      SetWakeOnPacketConnMessage *msg, const std::set<WakeOnWiFiTrigger> &trigs,
1373a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan      const IPAddressStore &addrs, uint32_t wiphy_index, Error *error);
1383a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Helper function to ConfigureSetWakeOnWiFiSettingsMessage that creates a
1393a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // single nested attribute inside the attribute list referenced by |patterns|
1403a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // representing a wake-on-packet pattern matching rule with index |patnum|.
1413a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Returns true iff the attribute is successfully created and set.
1423a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // NOTE: |patterns| is assumed to reference the nested attribute list
1433a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // NL80211_WOWLAN_TRIG_PKT_PATTERN.
1443a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // NOTE: |patnum| should be unique across multiple calls to this function to
1453a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // prevent the formation of a erroneous nl80211 message or the overwriting of
1463a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // pattern matching rules.
1473a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  static bool CreateSinglePattern(const IPAddress &ip_addr,
1483a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan                                  AttributeListRefPtr patterns, uint8_t patnum,
1493a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan                                  Error *error);
1503a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Creates and sets attributes in an GetWakeOnPacketConnMessage msg| so that
1513a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // the message will request for wake-on-packet settings information from the
1523a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // NIC with wiphy index |wiphy_index|. Returns true iff |msg| is successfully
1533a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // configured.
1543a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // NOTE: Assumes that |msg| has not been altered since construction.
1553a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  static bool ConfigureGetWakeOnWiFiSettingsMessage(
1563a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan      GetWakeOnPacketConnMessage *msg, uint32_t wiphy_index, Error *error);
1573a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Given a NL80211_CMD_GET_WOWLAN response or NL80211_CMD_SET_WOWLAN request
1583a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // |msg|, returns true iff the wake-on-wifi trigger settings in |msg| match
1593a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // those in |trigs|. Checks that source IP addresses in |msg| match those in
1603a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // |addrs| if the kIPAddress flag is in |trigs|.
1613a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  static bool WakeOnWiFiSettingsMatch(const Nl80211Message &msg,
1623a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan                                      const std::set<WakeOnWiFiTrigger> &trigs,
1633a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan                                      const IPAddressStore &addrs);
164742866741cd8902bfabd3d9731ccc6b4d5052de6Samuel Tan  // Handler for NL80211 message error responses from NIC wake on WiFi setting
165742866741cd8902bfabd3d9731ccc6b4d5052de6Samuel Tan  // programming attempts.
166742866741cd8902bfabd3d9731ccc6b4d5052de6Samuel Tan  void OnWakeOnWiFiSettingsErrorResponse(
167742866741cd8902bfabd3d9731ccc6b4d5052de6Samuel Tan      NetlinkManager::AuxilliaryMessageType type,
168742866741cd8902bfabd3d9731ccc6b4d5052de6Samuel Tan      const NetlinkMessage *raw_message);
1693a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Message handler for NL80211_CMD_SET_WOWLAN responses.
1703a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  static void OnSetWakeOnPacketConnectionResponse(
1713a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan      const Nl80211Message &nl80211_message);
1723a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Request wake on WiFi settings for this WiFi device.
1733a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  void RequestWakeOnPacketSettings();
1743a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Verify that the wake on WiFi settings programmed into the NIC match
1753a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // those recorded locally for this device in |wake_on_packet_connections_|
1763a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // and |wake_on_wifi_triggers_|.
1773a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  void VerifyWakeOnWiFiSettings(const Nl80211Message &nl80211_message);
1783a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Sends an NL80211 message to program the NIC with wake on WiFi settings
1793a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // configured in |wake_on_packet_connections_| and |wake_on_wifi_triggers_|.
1803a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // If |wake_on_wifi_triggers_| is empty, calls |DisableWakeOnWiFi|.
1813a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  void ApplyWakeOnWiFiSettings();
1823a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Helper function called by |ApplyWakeOnWiFiSettings| that sends an NL80211
1833a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // message to program the NIC to disable wake on WiFi.
1843a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  void DisableWakeOnWiFi();
1853a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Calls |ApplyWakeOnWiFiSettings| and counts this call as
1863a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // a retry. If |kMaxSetWakeOnPacketRetries| retries have already been
1873a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // performed, resets counter and returns.
1883a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  void RetrySetWakeOnPacketConnections();
1893a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan
190cb3ecf321c52de1e72cdf037a459cd893b7c51dbSamuel Tan  // Utility functions to check which wake on WiFi features are currently
191cb3ecf321c52de1e72cdf037a459cd893b7c51dbSamuel Tan  // enabled based on the descriptor |wake_on_wifi_enabled|.
192cb3ecf321c52de1e72cdf037a459cd893b7c51dbSamuel Tan  static bool WakeOnPacketEnabled(const std::string &wake_on_wifi_enabled);
193cb3ecf321c52de1e72cdf037a459cd893b7c51dbSamuel Tan  static bool WakeOnSSIDEnabled(const std::string &wake_on_wifi_enabled);
194cb3ecf321c52de1e72cdf037a459cd893b7c51dbSamuel Tan  static bool WakeOnWiFiFeaturesDisabled(
195cb3ecf321c52de1e72cdf037a459cd893b7c51dbSamuel Tan      const std::string &wake_on_wifi_enabled);
196cb3ecf321c52de1e72cdf037a459cd893b7c51dbSamuel Tan
1973a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Pointers to objects owned by the WiFi object that created this object.
1983a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  EventDispatcher *dispatcher_;
1993a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  NetlinkManager *netlink_manager_;
200a757752df1b85d8af4590b64d0946b7b2bb0779fSamuel Tan  Manager *manager_;
2013a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Executes after the NIC's wake-on-packet settings are configured via
2023a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // NL80211 messages to verify that the new configuration has taken effect.
2033a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Calls RequestWakeOnPacketSettings.
2043a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  base::CancelableClosure verify_wake_on_packet_settings_callback_;
2053a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Callback to be invoked after all suspend actions finish executing.
2063a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  ResultCallback suspend_actions_done_callback_;
2073a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Number of retry attempts to program the NIC's wake-on-packet settings.
2083a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  int num_set_wake_on_packet_retries_;
2093a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Keeps track of triggers that the NIC will be programmed to wake from
2103a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // while suspended.
2113a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  std::set<WakeOnWiFi::WakeOnWiFiTrigger> wake_on_wifi_triggers_;
2123a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Keeps track of what wake on wifi triggers this WiFi device supports.
2133a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  std::set<WakeOnWiFi::WakeOnWiFiTrigger> wake_on_wifi_triggers_supported_;
2143a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Max number of patterns this WiFi device can be programmed to wake on
2153a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // at one time.
2163a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  size_t wake_on_wifi_max_patterns_;
2173a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Keeps track of IP addresses whose packets this device will wake upon
2183a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // receiving while the device is suspended.
2193a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  IPAddressStore wake_on_packet_connections_;
2203a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  uint32_t wiphy_index_;
2213a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  bool wiphy_index_received_;
2223a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  base::WeakPtrFactory<WakeOnWiFi> weak_ptr_factory_;
223d03b95db5d05928ea63fc9f8aac5151e93c43a2fSamuel Tan
2243a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  DISALLOW_COPY_AND_ASSIGN(WakeOnWiFi);
2253a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan};
226d03b95db5d05928ea63fc9f8aac5151e93c43a2fSamuel Tan
227d03b95db5d05928ea63fc9f8aac5151e93c43a2fSamuel Tan}  // namespace shill
228d03b95db5d05928ea63fc9f8aac5151e93c43a2fSamuel Tan
229d03b95db5d05928ea63fc9f8aac5151e93c43a2fSamuel Tan#endif  // SHILL_WAKE_ON_WIFI_H_
230