1c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu//
2c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// Copyright (C) 2014 The Android Open Source Project
3c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu//
4c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// Licensed under the Apache License, Version 2.0 (the "License");
5c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// you may not use this file except in compliance with the License.
6c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// You may obtain a copy of the License at
7c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu//
8c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu//      http://www.apache.org/licenses/LICENSE-2.0
9c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu//
10c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// Unless required by applicable law or agreed to in writing, software
11c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// distributed under the License is distributed on an "AS IS" BASIS,
12c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// See the License for the specific language governing permissions and
14c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// limitations under the License.
15c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu//
16d03b95db5d05928ea63fc9f8aac5151e93c43a2fSamuel Tan
17d6a8b519e3057f52313e502f502a4819a942e089Ben Chan#ifndef SHILL_WIFI_WAKE_ON_WIFI_H_
18d6a8b519e3057f52313e502f502a4819a942e089Ben Chan#define SHILL_WIFI_WAKE_ON_WIFI_H_
19d03b95db5d05928ea63fc9f8aac5151e93c43a2fSamuel Tan
203a9c098afcd0456734092388d4aa7275716d33aaSamuel Tan#include <linux/if_ether.h>
213a9c098afcd0456734092388d4aa7275716d33aaSamuel Tan#include <netinet/ip.h>
223a9c098afcd0456734092388d4aa7275716d33aaSamuel Tan#include <netinet/ip6.h>
233a9c098afcd0456734092388d4aa7275716d33aaSamuel Tan
245f4b175bca4a997f186010c177c44489c8ae95b4Samuel Tan#include <set>
25cb3ecf321c52de1e72cdf037a459cd893b7c51dbSamuel Tan#include <string>
263a9c098afcd0456734092388d4aa7275716d33aaSamuel Tan#include <utility>
273a9c098afcd0456734092388d4aa7275716d33aaSamuel Tan#include <vector>
283a9c098afcd0456734092388d4aa7275716d33aaSamuel Tan
293a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan#include <base/cancelable_callback.h>
303a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan#include <gtest/gtest_prod.h>  // for FRIEND_TEST
313a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan#include <base/memory/ref_counted.h>
323a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan#include <base/memory/weak_ptr.h>
33041527c80c916008bd0d0697043f272dcf290058Samuel Tan#include <components/timers/alarm_timer_chromeos.h>
343a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan
353a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan#include "shill/callbacks.h"
363a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan#include "shill/ip_address_store.h"
37ff59a1896ea250b4450b54db697692e0b1949528Samuel Tan#include "shill/net/event_history.h"
388d6b59704591ba9fad57751858835dc332dbdd37Peter Qiu#include "shill/net/ip_address.h"
3902e3dc3bc6e9fdb475bd13944f1c6764c921abbbPeter Qiu#include "shill/net/netlink_manager.h"
403a9c098afcd0456734092388d4aa7275716d33aaSamuel Tan#include "shill/refptr_types.h"
415d0b8076eee13cd9b3de1c62f982ef0dc430260cSamuel Tan#include "shill/wifi/wifi.h"
423a9c098afcd0456734092388d4aa7275716d33aaSamuel Tan
43d03b95db5d05928ea63fc9f8aac5151e93c43a2fSamuel Tannamespace shill {
44d03b95db5d05928ea63fc9f8aac5151e93c43a2fSamuel Tan
45d03b95db5d05928ea63fc9f8aac5151e93c43a2fSamuel Tanclass ByteString;
46d03b95db5d05928ea63fc9f8aac5151e93c43a2fSamuel Tanclass Error;
473a1bf99b484ad8a9a054518f49046221251d5612Samuel Tanclass EventDispatcher;
483a9c098afcd0456734092388d4aa7275716d33aaSamuel Tanclass GetWakeOnPacketConnMessage;
4966bddc67c71dd197211ca08c5a4835bd6cfa5ed2Samuel Tanclass Metrics;
503a9c098afcd0456734092388d4aa7275716d33aaSamuel Tanclass Nl80211Message;
5196e35cf43e6d5aa2378cdae6fea507e5335d12bbSamuel Tanclass PropertyStore;
52d03b95db5d05928ea63fc9f8aac5151e93c43a2fSamuel Tanclass SetWakeOnPacketConnMessage;
533a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan
54c51454cb6a4442475449720549ac883731506909Samuel Tan// |WakeOnWiFi| performs all wake on WiFi related tasks and logic (e.g.
55c51454cb6a4442475449720549ac883731506909Samuel Tan// suspend/dark resume/resume logic, NIC wowlan programming via nl80211), and
56c51454cb6a4442475449720549ac883731506909Samuel Tan// stores the state necessary to perform these actions.
57c51454cb6a4442475449720549ac883731506909Samuel Tan//
58bb20181bee54a0dee8bba6d1375114f47cabb77fSamuel Tan// Shill implements two wake on WiFi features:
59bb20181bee54a0dee8bba6d1375114f47cabb77fSamuel Tan//   1) Dark connect: this feature allows the CrOS device to maintain WiFi
60bb20181bee54a0dee8bba6d1375114f47cabb77fSamuel Tan//      connectivity while suspended, and to wake from suspend in a low-power
61bb20181bee54a0dee8bba6d1375114f47cabb77fSamuel Tan//      state (dark resume) to maintain or re-establish WiFi connectivity.
62bb20181bee54a0dee8bba6d1375114f47cabb77fSamuel Tan//   2) Packet: this feature allows the CrOS device to wake from suspend upon
63bb20181bee54a0dee8bba6d1375114f47cabb77fSamuel Tan//      receiving network packets from any whitelisted hosts.
64bb20181bee54a0dee8bba6d1375114f47cabb77fSamuel Tan// Either or both of these features can be enabled/disabled by assigning the
65bb20181bee54a0dee8bba6d1375114f47cabb77fSamuel Tan// appropriate value to |wake_on_wifi_features_enabled_|.
66bb20181bee54a0dee8bba6d1375114f47cabb77fSamuel Tan//
67bb20181bee54a0dee8bba6d1375114f47cabb77fSamuel Tan// Note that wake on WiFi features are different from wake on WiFi triggers. The
68bb20181bee54a0dee8bba6d1375114f47cabb77fSamuel Tan// former refers to shill's suspend/resume/dark resume handling logic, whereas
69bb20181bee54a0dee8bba6d1375114f47cabb77fSamuel Tan// the latter refers to the NIC's  ability to wake the CPU on certain network
70bb20181bee54a0dee8bba6d1375114f47cabb77fSamuel Tan// events (e.g. disconnects). In order for shill's wake on WiFi features to
71bb20181bee54a0dee8bba6d1375114f47cabb77fSamuel Tan// work, the platform must be compiled with wake on WiFi support (i.e.
72bb20181bee54a0dee8bba6d1375114f47cabb77fSamuel Tan// DISABLE_WAKE_ON_WIFI not set), and its NIC must support the triggers required
73bb20181bee54a0dee8bba6d1375114f47cabb77fSamuel Tan// for the features to work (see WakeOnWiFi::WakeOnWiFiPacketEnabledAndSupported
74bb20181bee54a0dee8bba6d1375114f47cabb77fSamuel Tan// and WakeOnWiFi::WakeOnWiFiDarkConnectEnabledAndSupported for more details).
75bb20181bee54a0dee8bba6d1375114f47cabb77fSamuel Tan//
76bb20181bee54a0dee8bba6d1375114f47cabb77fSamuel Tan// The logic shill uses before, during (i.e. during dark resume), and after
77bb20181bee54a0dee8bba6d1375114f47cabb77fSamuel Tan// suspend when both wake on WiFi features are enabled are described below:
78c51454cb6a4442475449720549ac883731506909Samuel Tan//
79c51454cb6a4442475449720549ac883731506909Samuel Tan// OnBeforeSuspend
80c51454cb6a4442475449720549ac883731506909Samuel Tan// ================
81c51454cb6a4442475449720549ac883731506909Samuel Tan// This function is run when Manager announces an upcoming system suspend.
82c51454cb6a4442475449720549ac883731506909Samuel Tan//
83c51454cb6a4442475449720549ac883731506909Samuel Tan//         +--------------+
84c51454cb6a4442475449720549ac883731506909Samuel Tan//         |          Yes |   +----------------+
85c51454cb6a4442475449720549ac883731506909Samuel Tan// +-------+--------+     +-->|Renew DHCP Lease|
86c51454cb6a4442475449720549ac883731506909Samuel Tan// |  Connected &   |         +------+---------+
87c51454cb6a4442475449720549ac883731506909Samuel Tan// |holding expiring|                |
88c51454cb6a4442475449720549ac883731506909Samuel Tan// |  DHCP lease?   |                v
89c51454cb6a4442475449720549ac883731506909Samuel Tan// +------+---------+         +--------------------+
90c51454cb6a4442475449720549ac883731506909Samuel Tan//        |               +-> |BeforeSuspendActions|
91c51454cb6a4442475449720549ac883731506909Samuel Tan//        |           No  |   +--------------------+
92c51454cb6a4442475449720549ac883731506909Samuel Tan//        +---------------+
93c51454cb6a4442475449720549ac883731506909Samuel Tan//
94c51454cb6a4442475449720549ac883731506909Samuel Tan// OnDarkResume
95c51454cb6a4442475449720549ac883731506909Samuel Tan// =============
96c51454cb6a4442475449720549ac883731506909Samuel Tan// This function is run when Manager announces that the system has entered
97c51454cb6a4442475449720549ac883731506909Samuel Tan// dark resume and that there is an upcoming system suspend.
98c51454cb6a4442475449720549ac883731506909Samuel Tan//
99c51454cb6a4442475449720549ac883731506909Samuel Tan// +-------------+      +------------+     Unsupported     +----------+
100c51454cb6a4442475449720549ac883731506909Samuel Tan// |  Too many   +----->|Wake reason?+-------------------->|Connected?|
101d1bec5d563afc9074a1875e2302d5ecf54c95f95Samuel Tan// |dark resumes?|  No  +-+----------+                     +-+-----+--+
102c51454cb6a4442475449720549ac883731506909Samuel Tan// +------+------+        |       |                          |     |
103c51454cb6a4442475449720549ac883731506909Samuel Tan//        | Yes           |       | Disconnect/           No |     | Yes
104c51454cb6a4442475449720549ac883731506909Samuel Tan//        v               |       |    SSID                  |     |
1054c040c955b9fa793dbf871f1fd7b407f6e5c7ca0Samuel Tan// +-------------------+  |       v                          |     |
1064c040c955b9fa793dbf871f1fd7b407f6e5c7ca0Samuel Tan// |  Disable Wake on  |  |     +------------+               |     v
1074c040c955b9fa793dbf871f1fd7b407f6e5c7ca0Samuel Tan// |  WiFi, start wake |  |     |  Initiate  |<--------------+    +--------+
1084c040c955b9fa793dbf871f1fd7b407f6e5c7ca0Samuel Tan// |  to scan timer &  |  |     |passive scan|                    |Get DHCP|
1094c040c955b9fa793dbf871f1fd7b407f6e5c7ca0Samuel Tan// |  report readiness |  |     +-+----------+           +------->| Lease  |
1104c040c955b9fa793dbf871f1fd7b407f6e5c7ca0Samuel Tan// +-------------------+  |       | ScanDone         Yes |        +--+---+-+
111c51454cb6a4442475449720549ac883731506909Samuel Tan//    +-------------------+       v                      |           |   |
112c51454cb6a4442475449720549ac883731506909Samuel Tan//    | Pattern                 +-------------+      +---------+     |   |
113c51454cb6a4442475449720549ac883731506909Samuel Tan//    |                    No   | Any services| Yes  |Connected|     |   |
114c51454cb6a4442475449720549ac883731506909Samuel Tan//    |    +--------------------+available for+----->| to AP?  |     |   |
115c51454cb6a4442475449720549ac883731506909Samuel Tan//    |    |                    | autoconnect?|      +---+-----+     |   |
116c51454cb6a4442475449720549ac883731506909Samuel Tan//    |    |                    +-------------+          |           |   |
117c51454cb6a4442475449720549ac883731506909Samuel Tan//    |    |                                             |No         |   |
118c51454cb6a4442475449720549ac883731506909Samuel Tan//    v    v                                             |           |   |
119c51454cb6a4442475449720549ac883731506909Samuel Tan// +--------------------+       +-------+                |           |   |
120c51454cb6a4442475449720549ac883731506909Samuel Tan// |BeforeSuspendActions|<------+Timeout|<---------------+       No  |   |
121c51454cb6a4442475449720549ac883731506909Samuel Tan// +--------------------+       +-------+<---------------------------+   |
122c51454cb6a4442475449720549ac883731506909Samuel Tan//         ^                                                             |
123c51454cb6a4442475449720549ac883731506909Samuel Tan//         |                   +-------------------+                     |
124c51454cb6a4442475449720549ac883731506909Samuel Tan//         +-------------------+ OnIPConfigUpdated/|             Yes     |
125c51454cb6a4442475449720549ac883731506909Samuel Tan//                             |OnIPv6ConfigUpdated|<--------------------+
126c51454cb6a4442475449720549ac883731506909Samuel Tan//                             +-------------------+
127c51454cb6a4442475449720549ac883731506909Samuel Tan//
128c51454cb6a4442475449720549ac883731506909Samuel Tan// BeforeSuspendActions
129c51454cb6a4442475449720549ac883731506909Samuel Tan// =====================
130c51454cb6a4442475449720549ac883731506909Samuel Tan// This function is run immediately before the system reports suspend readiness
131c51454cb6a4442475449720549ac883731506909Samuel Tan// to Manager. This is the common "exit path" taken by OnBeforeSuspend and
132c51454cb6a4442475449720549ac883731506909Samuel Tan// OnDarkResume before suspending.
133c51454cb6a4442475449720549ac883731506909Samuel Tan//
134bb20181bee54a0dee8bba6d1375114f47cabb77fSamuel Tan// +----------------------+
135bb20181bee54a0dee8bba6d1375114f47cabb77fSamuel Tan// |Packet feature enabled|   Yes   +------------------------+
136bb20181bee54a0dee8bba6d1375114f47cabb77fSamuel Tan// |    and supported?    +-------->|Set Wake on Pattern flag|
137bb20181bee54a0dee8bba6d1375114f47cabb77fSamuel Tan// +-----+----------------+         +------------+-----------+
138bb20181bee54a0dee8bba6d1375114f47cabb77fSamuel Tan//       |                                       |
139bb20181bee54a0dee8bba6d1375114f47cabb77fSamuel Tan//    No |        +------------------------------+
140bb20181bee54a0dee8bba6d1375114f47cabb77fSamuel Tan//       |        |
141bb20181bee54a0dee8bba6d1375114f47cabb77fSamuel Tan// +-----v--------v-------+        No
142bb20181bee54a0dee8bba6d1375114f47cabb77fSamuel Tan// | Dark connect feature +---------------------------------+
143bb20181bee54a0dee8bba6d1375114f47cabb77fSamuel Tan// |enabled and supported?|                                 |
144bb20181bee54a0dee8bba6d1375114f47cabb77fSamuel Tan// +--+-------------------+                                 |
145bb20181bee54a0dee8bba6d1375114f47cabb77fSamuel Tan//    |                                                     |
146bb20181bee54a0dee8bba6d1375114f47cabb77fSamuel Tan//    |Yes    Yes   +----------------------------+          |        +---------+
147bb20181bee54a0dee8bba6d1375114f47cabb77fSamuel Tan//    |     +-----> |Set Wake on Disconnect flag,+--+    +--v----+   |Report   |
148bb20181bee54a0dee8bba6d1375114f47cabb77fSamuel Tan//    |     |       |Start Lease Renewal Timer*  |  |    |Program|   |Suspend  |
149bb20181bee54a0dee8bba6d1375114f47cabb77fSamuel Tan//    |     |       +----------------------------+  +--> |  NIC  |   |Readiness|
150bb20181bee54a0dee8bba6d1375114f47cabb77fSamuel Tan// +--v-----+-+                                     |    +-+---+-+   +--+------+
151c51454cb6a4442475449720549ac883731506909Samuel Tan// |Connected?|                                     |      |   ^        ^
152c51454cb6a4442475449720549ac883731506909Samuel Tan// +--------+-+                                     |      |   |Failed  |
153bb20181bee54a0dee8bba6d1375114f47cabb77fSamuel Tan//          |                                       |      ^   |        |Success
154bb20181bee54a0dee8bba6d1375114f47cabb77fSamuel Tan//          |       +----------------------------+  |  +---+---+---+    |
155c51454cb6a4442475449720549ac883731506909Samuel Tan//          +-----> |Set Wake on SSID flag,      +--+  |  Verify   +----+
156c51454cb6a4442475449720549ac883731506909Samuel Tan//            No    |Start Wake To Scan Timer**  |     |Programming|
157c51454cb6a4442475449720549ac883731506909Samuel Tan//                  +----------------------------+     +-----------+
158c51454cb6a4442475449720549ac883731506909Samuel Tan//
159c51454cb6a4442475449720549ac883731506909Samuel Tan// *  if necessary (as indicated by caller of BeforeSuspendActions).
160bb20181bee54a0dee8bba6d1375114f47cabb77fSamuel Tan// ** if we need to whitelist more SSIDs than our NIC supports.
161c51454cb6a4442475449720549ac883731506909Samuel Tan//
162c51454cb6a4442475449720549ac883731506909Samuel Tan// OnAfterResume
163c51454cb6a4442475449720549ac883731506909Samuel Tan// ==============
164c51454cb6a4442475449720549ac883731506909Samuel Tan// This is run after Manager announces that the system has fully resumed from
165c51454cb6a4442475449720549ac883731506909Samuel Tan// suspend.
166c51454cb6a4442475449720549ac883731506909Samuel Tan//
167c51454cb6a4442475449720549ac883731506909Samuel Tan// Wake on WiFi is disabled on the NIC if it was enabled before suspend or
168c51454cb6a4442475449720549ac883731506909Samuel Tan// dark resume, and both the wake to scan timer and DHCP lease renewal timers
169c51454cb6a4442475449720549ac883731506909Samuel Tan// are stopped.
170c51454cb6a4442475449720549ac883731506909Samuel Tan
1713a1bf99b484ad8a9a054518f49046221251d5612Samuel Tanclass WakeOnWiFi {
1723a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan public:
1732b363903f38a515001c5edc7202403fcddb15a01Paul Stewart  typedef base::Callback<void(const WiFi::FreqSet&)> InitiateScanCallback;
1741897afaeb89003f5cc75a256f6fd7528e6abd54fSamuel Tan  // Callback used to report the wake reason for the current dark resume to
1751897afaeb89003f5cc75a256f6fd7528e6abd54fSamuel Tan  // powerd.
1762b363903f38a515001c5edc7202403fcddb15a01Paul Stewart  typedef base::Callback<void(const std::string&)> RecordWakeReasonCallback;
1770932171ae1b59449130783c28ac54332d06d4e23Samuel Tan
1786d61faf84ef5eb2545bc6eee8a4d74109dfdd6d1Samuel Tan  // Types of triggers that we can program the NIC to wake the WiFi device.
1796d61faf84ef5eb2545bc6eee8a4d74109dfdd6d1Samuel Tan  enum WakeOnWiFiTrigger {
1806d61faf84ef5eb2545bc6eee8a4d74109dfdd6d1Samuel Tan    kWakeTriggerUnsupported = 0,  // Used for reporting, not programming NIC.
1816d61faf84ef5eb2545bc6eee8a4d74109dfdd6d1Samuel Tan    kWakeTriggerPattern = 1,
1826d61faf84ef5eb2545bc6eee8a4d74109dfdd6d1Samuel Tan    kWakeTriggerDisconnect = 2,
1836d61faf84ef5eb2545bc6eee8a4d74109dfdd6d1Samuel Tan    kWakeTriggerSSID = 3
1846d61faf84ef5eb2545bc6eee8a4d74109dfdd6d1Samuel Tan  };
1856d61faf84ef5eb2545bc6eee8a4d74109dfdd6d1Samuel Tan
1862b363903f38a515001c5edc7202403fcddb15a01Paul Stewart  WakeOnWiFi(NetlinkManager* netlink_manager, EventDispatcher* dispatcher,
1872b363903f38a515001c5edc7202403fcddb15a01Paul Stewart             Metrics* metrics,
1881897afaeb89003f5cc75a256f6fd7528e6abd54fSamuel Tan             RecordWakeReasonCallback record_wake_reason_callback);
189fb02175e039a683cf9ac875ba0924858de6a08ffSamuel Tan  virtual ~WakeOnWiFi();
1903a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan
19196e35cf43e6d5aa2378cdae6fea507e5335d12bbSamuel Tan  // Registers |store| with properties related to wake on WiFi.
1922b363903f38a515001c5edc7202403fcddb15a01Paul Stewart  void InitPropertyStore(PropertyStore* store);
19396e35cf43e6d5aa2378cdae6fea507e5335d12bbSamuel Tan
19466bddc67c71dd197211ca08c5a4835bd6cfa5ed2Samuel Tan  // Starts |metrics_timer_| so that wake on WiFi related metrics are
19566bddc67c71dd197211ca08c5a4835bd6cfa5ed2Samuel Tan  // periodically collected.
19666bddc67c71dd197211ca08c5a4835bd6cfa5ed2Samuel Tan  void StartMetricsTimer();
19766bddc67c71dd197211ca08c5a4835bd6cfa5ed2Samuel Tan
1983a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Enable the NIC to wake on packets received from |ip_endpoint|.
1993a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Note: The actual programming of the NIC only happens before the system
2003a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // suspends, in |OnBeforeSuspend|.
2012b363903f38a515001c5edc7202403fcddb15a01Paul Stewart  void AddWakeOnPacketConnection(const std::string& ip_endpoint, Error* error);
2023a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Remove rule to wake on packets received from |ip_endpoint| from the NIC.
2033a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Note: The actual programming of the NIC only happens before the system
2043a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // suspends, in |OnBeforeSuspend|.
2052b363903f38a515001c5edc7202403fcddb15a01Paul Stewart  void RemoveWakeOnPacketConnection(const std::string& ip_endpoint,
2062b363903f38a515001c5edc7202403fcddb15a01Paul Stewart                                    Error* error);
2073a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Remove all rules to wake on incoming packets from the NIC.
2083a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Note: The actual programming of the NIC only happens before the system
2093a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // suspends, in |OnBeforeSuspend|.
2102b363903f38a515001c5edc7202403fcddb15a01Paul Stewart  void RemoveAllWakeOnPacketConnections(Error* error);
2113a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Given a NL80211_CMD_NEW_WIPHY message |nl80211_message|, parses the
21296bdaecf58097e1cc54c5459e3c165de25c82134Samuel Tan  // wake on WiFi capabilities of the NIC and set relevant members of this
2133a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // WakeOnWiFi object to reflect the supported capbilities.
214235dcec779704b782f0608421d890fe6d183e7ccSamuel Tan  virtual void ParseWakeOnWiFiCapabilities(
2152b363903f38a515001c5edc7202403fcddb15a01Paul Stewart      const Nl80211Message& nl80211_message);
2160932171ae1b59449130783c28ac54332d06d4e23Samuel Tan  // Callback invoked when the system reports its wakeup reason.
2170932171ae1b59449130783c28ac54332d06d4e23Samuel Tan  //
2180932171ae1b59449130783c28ac54332d06d4e23Samuel Tan  // Arguments:
2190932171ae1b59449130783c28ac54332d06d4e23Samuel Tan  //  - |netlink_message|: wakeup report message (note: must manually check
2200932171ae1b59449130783c28ac54332d06d4e23Samuel Tan  //    this message to make sure it is a wakeup report message).
2210932171ae1b59449130783c28ac54332d06d4e23Samuel Tan  //
2220932171ae1b59449130783c28ac54332d06d4e23Samuel Tan  // Note: Assumes only one wakeup reason is received. If more than one is
2230932171ae1b59449130783c28ac54332d06d4e23Samuel Tan  // received, the only first one parsed will be handled.
2242b363903f38a515001c5edc7202403fcddb15a01Paul Stewart  virtual void OnWakeupReasonReceived(const NetlinkMessage& netlink_message);
225c51454cb6a4442475449720549ac883731506909Samuel Tan  // Performs pre-suspend actions relevant to wake on WiFi functionality.
226787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  //
227787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  // Arguments:
228787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  //  - |is_connected|: whether the WiFi device is connected.
229d70ecdf36c94516b71cca8212caeb71da8c63d02Samuel Tan  //  - |ssid_whitelist|: list of SSIDs that the NIC will be programmed to wake
230d70ecdf36c94516b71cca8212caeb71da8c63d02Samuel Tan  //    the system on if the NIC is programmed to wake on SSID.
231787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  //  - |done_callback|: callback to invoke when suspend  actions have
232787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  //    completed.
233787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  //  - |renew_dhcp_lease_callback|: callback to invoke to initiate DHCP lease
234787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  //    renewal.
235787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  //  - |remove_supplicant_networks_callback|: callback to invoke
236787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  //    to remove all networks from WPA supplicant.
237787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  //  - |have_dhcp_lease|: whether or not there is a DHCP lease to renew.
238787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  //  - |time_to_next_lease_renewal|: number of seconds until next DHCP lease
239787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  //    renewal is due.
240787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  virtual void OnBeforeSuspend(
241787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan      bool is_connected,
2422b363903f38a515001c5edc7202403fcddb15a01Paul Stewart      const std::vector<ByteString>& ssid_whitelist,
2432b363903f38a515001c5edc7202403fcddb15a01Paul Stewart      const ResultCallback& done_callback,
2442b363903f38a515001c5edc7202403fcddb15a01Paul Stewart      const base::Closure& renew_dhcp_lease_callback,
2452b363903f38a515001c5edc7202403fcddb15a01Paul Stewart      const base::Closure& remove_supplicant_networks_callback,
246787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan      bool have_dhcp_lease,
247787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan      uint32_t time_to_next_lease_renewal);
2483a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Performs post-resume actions relevant to wake on wireless functionality.
249fb02175e039a683cf9ac875ba0924858de6a08ffSamuel Tan  virtual void OnAfterResume();
250787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  // Performs and post actions to be performed in dark resume.
251787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  //
252787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  // Arguments:
253787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  //  - |is_connected|: whether the WiFi device is connected.
254d70ecdf36c94516b71cca8212caeb71da8c63d02Samuel Tan  //  - |ssid_whitelist|: list of SSIDs that the NIC will be programmed to wake
255d70ecdf36c94516b71cca8212caeb71da8c63d02Samuel Tan  //    the system on if the NIC is programmed to wake on SSID.
256787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  //  - |done_callback|: callback to invoke when dark resume actions have
257787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  //    completed.
258787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  //  - |renew_dhcp_lease_callback|: callback to invoke to initiate DHCP lease
259787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  //    renewal.
260787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  //  - |initate_scan_callback|: callback to invoke to initiate a scan.
261787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  //  - |remove_supplicant_networks_callback|: callback to invoke
262787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  //    to remove all networks from WPA supplicant.
263787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  virtual void OnDarkResume(
264787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan      bool is_connected,
2652b363903f38a515001c5edc7202403fcddb15a01Paul Stewart      const std::vector<ByteString>& ssid_whitelist,
2662b363903f38a515001c5edc7202403fcddb15a01Paul Stewart      const ResultCallback& done_callback,
2672b363903f38a515001c5edc7202403fcddb15a01Paul Stewart      const base::Closure& renew_dhcp_lease_callback,
2682b363903f38a515001c5edc7202403fcddb15a01Paul Stewart      const InitiateScanCallback& initiate_scan_callback,
2692b363903f38a515001c5edc7202403fcddb15a01Paul Stewart      const base::Closure& remove_supplicant_networks_callback);
270830e5d7924cb43a034f3188cc1f674416d2f74e6Samuel Tan  // Called when we the current service is connected, and we have IP
271830e5d7924cb43a034f3188cc1f674416d2f74e6Samuel Tan  // reachability. Calls WakeOnWiFi::BeforeSuspendActions if we are in dark
272830e5d7924cb43a034f3188cc1f674416d2f74e6Samuel Tan  // resume to end the current dark resume. Otherwise, does nothing.
273830e5d7924cb43a034f3188cc1f674416d2f74e6Samuel Tan  virtual void OnConnectedAndReachable(bool start_lease_renewal_timer,
274830e5d7924cb43a034f3188cc1f674416d2f74e6Samuel Tan                                       uint32_t time_to_next_lease_renewal);
2751964b5de186ef06fa89a78b27c3a112686bc36f7Samuel Tan  // Callback invoked to report whether this WiFi device is connected to
2761964b5de186ef06fa89a78b27c3a112686bc36f7Samuel Tan  // a service after waking from suspend.
2771964b5de186ef06fa89a78b27c3a112686bc36f7Samuel Tan  virtual void ReportConnectedToServiceAfterWake(bool is_connected);
278402bf2959e8b2c68627a7b66203ec84760bf2e03Samuel Tan  // Called in WiFi::ScanDoneTask when there are no WiFi services available
2794b8436a5136baa1716ca6a1013e2a4ad38ad2437Samuel Tan  // for auto-connect after a scan. |initiate_scan_callback| is used for dark
2804b8436a5136baa1716ca6a1013e2a4ad38ad2437Samuel Tan  // resume scan retries.
281402bf2959e8b2c68627a7b66203ec84760bf2e03Samuel Tan  virtual void OnNoAutoConnectableServicesAfterScan(
2822b363903f38a515001c5edc7202403fcddb15a01Paul Stewart      const std::vector<ByteString>& ssid_whitelist,
2832b363903f38a515001c5edc7202403fcddb15a01Paul Stewart      const base::Closure& remove_supplicant_networks_callback,
2842b363903f38a515001c5edc7202403fcddb15a01Paul Stewart      const InitiateScanCallback& initiate_scan_callback);
285d1bec5d563afc9074a1875e2302d5ecf54c95f95Samuel Tan  // Called by WiFi when it is notified by the kernel that a scan has started.
286d1bec5d563afc9074a1875e2302d5ecf54c95f95Samuel Tan  // If |is_active_scan| is true, the scan is an active scan. Otherwise, the
287d1bec5d563afc9074a1875e2302d5ecf54c95f95Samuel Tan  // scan is a passive scan.
288d1bec5d563afc9074a1875e2302d5ecf54c95f95Samuel Tan  virtual void OnScanStarted(bool is_active_scan);
2893a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan
2900e0ac0de9ac592495f780d7c372ba1212d4d374cSamuel Tan  bool in_dark_resume() { return in_dark_resume_; }
2910e0ac0de9ac592495f780d7c372ba1212d4d374cSamuel Tan
292235dcec779704b782f0608421d890fe6d183e7ccSamuel Tan  virtual void OnWiphyIndexReceived(uint32_t index);
293235dcec779704b782f0608421d890fe6d183e7ccSamuel Tan
2943a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan private:
2953a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  friend class WakeOnWiFiTest;  // access to several members for tests
2963a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  friend class WiFiObjectTest;  // netlink_manager_
297dd19dce483cf54007db84bed6c2b523fbce04813Samuel Tan  // kWakeOnWiFiNotSupported.
298e58fa86282bb07867793ba78e9ff1c56fdc2d2b3Samuel Tan  FRIEND_TEST(WakeOnWiFiTestWithMockDispatcher,
299e58fa86282bb07867793ba78e9ff1c56fdc2d2b3Samuel Tan              WakeOnWiFiDisabled_SetWakeOnWiFiFeaturesEnabled);
300787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  FRIEND_TEST(WakeOnWiFiTestWithMockDispatcher,
301787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan              WakeOnWiFiDisabled_AddWakeOnPacketConnection_ReturnsError);
302787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  FRIEND_TEST(WakeOnWiFiTestWithMockDispatcher,
303787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan              WakeOnWiFiDisabled_RemoveWakeOnPacketConnection_ReturnsError);
304787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  FRIEND_TEST(WakeOnWiFiTestWithMockDispatcher,
305787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan              WakeOnWiFiDisabled_RemoveAllWakeOnPacketConnections_ReturnsError);
306dd19dce483cf54007db84bed6c2b523fbce04813Samuel Tan  // kMaxSetWakeOnPacketRetries.
307787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  FRIEND_TEST(WakeOnWiFiTestWithMockDispatcher,
3083a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan              RetrySetWakeOnPacketConnections_LessThanMaxRetries);
309787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  FRIEND_TEST(WakeOnWiFiTestWithMockDispatcher,
3103a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan              RetrySetWakeOnPacketConnections_MaxAttemptsWithCallbackSet);
311787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  FRIEND_TEST(WakeOnWiFiTestWithMockDispatcher,
3123a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan              RetrySetWakeOnPacketConnections_MaxAttemptsCallbackUnset);
313dd19dce483cf54007db84bed6c2b523fbce04813Samuel Tan  // kDarkResumeActionsTimeoutMilliseconds
314787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  FRIEND_TEST(WakeOnWiFiTestWithMockDispatcher,
315787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan              OnBeforeSuspend_DHCPLeaseRenewal);
316dd19dce483cf54007db84bed6c2b523fbce04813Samuel Tan  // Dark resume wake reason strings (e.g. kWakeReasonStringDisconnect)
3171897afaeb89003f5cc75a256f6fd7528e6abd54fSamuel Tan  FRIEND_TEST(WakeOnWiFiTestWithMockDispatcher,
3181897afaeb89003f5cc75a256f6fd7528e6abd54fSamuel Tan              OnWakeupReasonReceived_Disconnect);
3191897afaeb89003f5cc75a256f6fd7528e6abd54fSamuel Tan  FRIEND_TEST(WakeOnWiFiTestWithMockDispatcher, OnWakeupReasonReceived_SSID);
3201897afaeb89003f5cc75a256f6fd7528e6abd54fSamuel Tan  FRIEND_TEST(WakeOnWiFiTestWithMockDispatcher, OnWakeupReasonReceived_Pattern);
321dd19dce483cf54007db84bed6c2b523fbce04813Samuel Tan  // kMaxDarkResumesPerPeriodShort
322ff59a1896ea250b4450b54db697692e0b1949528Samuel Tan  FRIEND_TEST(WakeOnWiFiTestWithDispatcher, OnBeforeSuspend_ClearsEventHistory);
323dd19dce483cf54007db84bed6c2b523fbce04813Samuel Tan  // kDarkResumeFrequencySamplingPeriodShortMinutes,
324dd19dce483cf54007db84bed6c2b523fbce04813Samuel Tan  // kMaxDarkResumesPerPeriodShort
325bc78c1fefe3bd5d3e4397cb1b4b42cc78ad1e87eSamuel Tan  FRIEND_TEST(WakeOnWiFiTestWithDispatcher,
326bc78c1fefe3bd5d3e4397cb1b4b42cc78ad1e87eSamuel Tan              OnDarkResume_NotConnected_MaxDarkResumes_ShortPeriod);
327dd19dce483cf54007db84bed6c2b523fbce04813Samuel Tan  // kDarkResumeFrequencySamplingPeriodLongMinutes,
328dd19dce483cf54007db84bed6c2b523fbce04813Samuel Tan  // kMaxDarkResumesPerPeriodLong,
329dd19dce483cf54007db84bed6c2b523fbce04813Samuel Tan  // kDarkResumeFrequencySamplingPeriodShortMinutes,
330dd19dce483cf54007db84bed6c2b523fbce04813Samuel Tan  // kMaxDarkResumesPerPeriodShort
331bc78c1fefe3bd5d3e4397cb1b4b42cc78ad1e87eSamuel Tan  FRIEND_TEST(WakeOnWiFiTestWithDispatcher,
332bc78c1fefe3bd5d3e4397cb1b4b42cc78ad1e87eSamuel Tan              OnDarkResume_NotConnected_MaxDarkResumes_LongPeriod);
3334b8436a5136baa1716ca6a1013e2a4ad38ad2437Samuel Tan  // kMaxFreqsForDarkResumeScanRetries, kMaxDarkResumeScanRetries
3344b8436a5136baa1716ca6a1013e2a4ad38ad2437Samuel Tan  FRIEND_TEST(WakeOnWiFiTestWithDispatcher, InitiateScanInDarkResume);
3353a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan
336fb02175e039a683cf9ac875ba0924858de6a08ffSamuel Tan  static const char kWakeOnIPAddressPatternsNotSupported[];
337e58fa86282bb07867793ba78e9ff1c56fdc2d2b3Samuel Tan  static const char kWakeOnWiFiNotSupported[];
338f8c0b3bcc1b9e918400c1fe76a9f6991bc32b55bSamuel Tan  static const int kVerifyWakeOnWiFiSettingsDelayMilliseconds;
3393a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  static const int kMaxSetWakeOnPacketRetries;
34066bddc67c71dd197211ca08c5a4835bd6cfa5ed2Samuel Tan  static const int kMetricsReportingFrequencySeconds;
3415768ad4f08851b73eddb3328794eaa0ab3094bd3Samuel Tan  static const uint32_t kDefaultWakeToScanPeriodSeconds;
3427804df459a7f29a7463dbd7f0e8e2fea93ee766dSamuel Tan  static const uint32_t kDefaultNetDetectScanPeriodSeconds;
343787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  static const uint32_t kImmediateDHCPLeaseRenewalThresholdSeconds;
344bc78c1fefe3bd5d3e4397cb1b4b42cc78ad1e87eSamuel Tan  static const int kDarkResumeFrequencySamplingPeriodShortMinutes;
345bc78c1fefe3bd5d3e4397cb1b4b42cc78ad1e87eSamuel Tan  static const int kDarkResumeFrequencySamplingPeriodLongMinutes;
346bc78c1fefe3bd5d3e4397cb1b4b42cc78ad1e87eSamuel Tan  static const int kMaxDarkResumesPerPeriodShort;
347bc78c1fefe3bd5d3e4397cb1b4b42cc78ad1e87eSamuel Tan  static const int kMaxDarkResumesPerPeriodLong;
348787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  static int64_t DarkResumeActionsTimeoutMilliseconds;  // non-const for testing
3494b8436a5136baa1716ca6a1013e2a4ad38ad2437Samuel Tan  static const int kMaxFreqsForDarkResumeScanRetries;
3504b8436a5136baa1716ca6a1013e2a4ad38ad2437Samuel Tan  static const int kMaxDarkResumeScanRetries;
3511897afaeb89003f5cc75a256f6fd7528e6abd54fSamuel Tan  // Dark resume wake reason names. These will be sent to powerd via
3521897afaeb89003f5cc75a256f6fd7528e6abd54fSamuel Tan  // RecordDarkResumeWakeReason, to tell it the reason the system woke in the
3531897afaeb89003f5cc75a256f6fd7528e6abd54fSamuel Tan  // current dark resume.
3541897afaeb89003f5cc75a256f6fd7528e6abd54fSamuel Tan  static const char kWakeReasonStringPattern[];
3551897afaeb89003f5cc75a256f6fd7528e6abd54fSamuel Tan  static const char kWakeReasonStringDisconnect[];
3561897afaeb89003f5cc75a256f6fd7528e6abd54fSamuel Tan  static const char kWakeReasonStringSSID[];
3573a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan
3582b363903f38a515001c5edc7202403fcddb15a01Paul Stewart  std::string GetWakeOnWiFiFeaturesEnabled(Error* error);
3592b363903f38a515001c5edc7202403fcddb15a01Paul Stewart  bool SetWakeOnWiFiFeaturesEnabled(const std::string& enabled, Error* error);
360740ee07e13d98ee9e0535ffea391326c8da13499Samuel Tan  // Helper function to run and reset |suspend_actions_done_callback_|.
3612b363903f38a515001c5edc7202403fcddb15a01Paul Stewart  void RunAndResetSuspendActionsDoneCallback(const Error& error);
3623a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Used for comparison of ByteString pairs in a set.
3633a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  static bool ByteStringPairIsLessThan(
3642b363903f38a515001c5edc7202403fcddb15a01Paul Stewart      const std::pair<ByteString, ByteString>& lhs,
3652b363903f38a515001c5edc7202403fcddb15a01Paul Stewart      const std::pair<ByteString, ByteString>& rhs);
3663a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Creates a mask which specifies which bytes in pattern of length
3673a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // |pattern_len| to match against. Bits |offset| to |pattern_len| - 1 are set,
3683a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // which bits 0 to bits 0 to |offset| - 1 are unset. This mask is saved in
3693a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // |mask|.
3702b363903f38a515001c5edc7202403fcddb15a01Paul Stewart  static void SetMask(ByteString* mask, uint32_t pattern_len, uint32_t offset);
3713a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Creates a pattern and mask for a NL80211 message that programs the NIC to
3723a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // wake on packets originating from IP address |ip_addr|. The pattern and mask
3733a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // are saved in |pattern| and |mask| respectively. Returns true iff the
3743a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // pattern and mask are successfully created and written to |pattern| and
3753a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // |mask| respectively.
3762b363903f38a515001c5edc7202403fcddb15a01Paul Stewart  static bool CreateIPAddressPatternAndMask(const IPAddress& ip_addr,
3772b363903f38a515001c5edc7202403fcddb15a01Paul Stewart                                            ByteString* pattern,
3782b363903f38a515001c5edc7202403fcddb15a01Paul Stewart                                            ByteString* mask);
3792b363903f38a515001c5edc7202403fcddb15a01Paul Stewart  static void CreateIPV4PatternAndMask(const IPAddress& ip_addr,
3802b363903f38a515001c5edc7202403fcddb15a01Paul Stewart                                       ByteString* pattern, ByteString* mask);
3812b363903f38a515001c5edc7202403fcddb15a01Paul Stewart  static void CreateIPV6PatternAndMask(const IPAddress& ip_addr,
3822b363903f38a515001c5edc7202403fcddb15a01Paul Stewart                                       ByteString* pattern, ByteString* mask);
3833a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Creates and sets an attribute in a NL80211 message |msg| which indicates
3843a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // the index of the wiphy interface to program. Returns true iff |msg| is
3853a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // successfully configured.
3862b363903f38a515001c5edc7202403fcddb15a01Paul Stewart  static bool ConfigureWiphyIndex(Nl80211Message* msg, int32_t index);
3873a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Creates and sets attributes in an SetWakeOnPacketConnMessage |msg| so that
3883a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // the message will disable wake-on-packet functionality of the NIC with wiphy
3893a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // index |wiphy_index|. Returns true iff |msg| is successfully configured.
3903a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // NOTE: Assumes that |msg| has not been altered since construction.
3912b363903f38a515001c5edc7202403fcddb15a01Paul Stewart  static bool ConfigureDisableWakeOnWiFiMessage(SetWakeOnPacketConnMessage* msg,
3923a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan                                                uint32_t wiphy_index,
3932b363903f38a515001c5edc7202403fcddb15a01Paul Stewart                                                Error* error);
3943a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Creates and sets attributes in a SetWakeOnPacketConnMessage |msg|
3953a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // so that the message will program the NIC with wiphy index |wiphy_index|
3963a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // with wake on wireless triggers in |trigs|. If |trigs| contains the
3976d61faf84ef5eb2545bc6eee8a4d74109dfdd6d1Samuel Tan  // kWakeTriggerPattern trigger, the message is configured to program the NIC
3986d61faf84ef5eb2545bc6eee8a4d74109dfdd6d1Samuel Tan  // to wake on packets from the IP addresses in |addrs|. If |trigs| contains
3996d61faf84ef5eb2545bc6eee8a4d74109dfdd6d1Samuel Tan  // the kSSID trigger, the message is configured to program the NIC to wake on
4006d61faf84ef5eb2545bc6eee8a4d74109dfdd6d1Samuel Tan  // the SSIDs in |ssid_whitelist|.
401d70ecdf36c94516b71cca8212caeb71da8c63d02Samuel Tan  // Returns true iff |msg| is successfully configured.
4023a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // NOTE: Assumes that |msg| has not been altered since construction.
4033a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  static bool ConfigureSetWakeOnWiFiSettingsMessage(
4042b363903f38a515001c5edc7202403fcddb15a01Paul Stewart      SetWakeOnPacketConnMessage* msg, const std::set<WakeOnWiFiTrigger>& trigs,
4052b363903f38a515001c5edc7202403fcddb15a01Paul Stewart      const IPAddressStore& addrs, uint32_t wiphy_index,
406d70ecdf36c94516b71cca8212caeb71da8c63d02Samuel Tan      uint32_t net_detect_scan_period_seconds,
4072b363903f38a515001c5edc7202403fcddb15a01Paul Stewart      const std::vector<ByteString>& ssid_whitelist,
4082b363903f38a515001c5edc7202403fcddb15a01Paul Stewart      Error* error);
4093a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Helper function to ConfigureSetWakeOnWiFiSettingsMessage that creates a
4103a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // single nested attribute inside the attribute list referenced by |patterns|
4113a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // representing a wake-on-packet pattern matching rule with index |patnum|.
4123a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Returns true iff the attribute is successfully created and set.
4133a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // NOTE: |patterns| is assumed to reference the nested attribute list
4143a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // NL80211_WOWLAN_TRIG_PKT_PATTERN.
4153a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // NOTE: |patnum| should be unique across multiple calls to this function to
4163a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // prevent the formation of a erroneous nl80211 message or the overwriting of
4173a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // pattern matching rules.
4182b363903f38a515001c5edc7202403fcddb15a01Paul Stewart  static bool CreateSinglePattern(const IPAddress& ip_addr,
4193a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan                                  AttributeListRefPtr patterns, uint8_t patnum,
4202b363903f38a515001c5edc7202403fcddb15a01Paul Stewart                                  Error* error);
4213a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Creates and sets attributes in an GetWakeOnPacketConnMessage msg| so that
4223a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // the message will request for wake-on-packet settings information from the
4233a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // NIC with wiphy index |wiphy_index|. Returns true iff |msg| is successfully
4243a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // configured.
4253a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // NOTE: Assumes that |msg| has not been altered since construction.
4263a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  static bool ConfigureGetWakeOnWiFiSettingsMessage(
4272b363903f38a515001c5edc7202403fcddb15a01Paul Stewart      GetWakeOnPacketConnMessage* msg, uint32_t wiphy_index, Error* error);
4283a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Given a NL80211_CMD_GET_WOWLAN response or NL80211_CMD_SET_WOWLAN request
4293a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // |msg|, returns true iff the wake-on-wifi trigger settings in |msg| match
430d70ecdf36c94516b71cca8212caeb71da8c63d02Samuel Tan  // those in |trigs|. Performs the following checks for the following triggers:
4316d61faf84ef5eb2545bc6eee8a4d74109dfdd6d1Samuel Tan  // - kWakeTriggerDisconnect: checks that the wake on disconnect flag is
4326d61faf84ef5eb2545bc6eee8a4d74109dfdd6d1Samuel Tan  //   present and set.
433d70ecdf36c94516b71cca8212caeb71da8c63d02Samuel Tan  // - kIPAddress: checks that source IP addresses in |msg| match those reported
434d70ecdf36c94516b71cca8212caeb71da8c63d02Samuel Tan  //   in |addrs|.
435d70ecdf36c94516b71cca8212caeb71da8c63d02Samuel Tan  // - kSSID: checks that the SSIDs in |ssid_whitelist| and the scan interval
436d70ecdf36c94516b71cca8212caeb71da8c63d02Samuel Tan  //   |net_detect_scan_period_seconds| match those reported in |msg|.
437d70ecdf36c94516b71cca8212caeb71da8c63d02Samuel Tan  // Note: finding a trigger is in |msg| that is not expected based on the flags
438d70ecdf36c94516b71cca8212caeb71da8c63d02Samuel Tan  // in |trig| also counts as a mismatch.
439d70ecdf36c94516b71cca8212caeb71da8c63d02Samuel Tan  static bool WakeOnWiFiSettingsMatch(
4402b363903f38a515001c5edc7202403fcddb15a01Paul Stewart      const Nl80211Message& msg, const std::set<WakeOnWiFiTrigger>& trigs,
4412b363903f38a515001c5edc7202403fcddb15a01Paul Stewart      const IPAddressStore& addrs, uint32_t net_detect_scan_period_seconds,
4422b363903f38a515001c5edc7202403fcddb15a01Paul Stewart      const std::vector<ByteString>& ssid_whitelist);
443742866741cd8902bfabd3d9731ccc6b4d5052de6Samuel Tan  // Handler for NL80211 message error responses from NIC wake on WiFi setting
444742866741cd8902bfabd3d9731ccc6b4d5052de6Samuel Tan  // programming attempts.
445742866741cd8902bfabd3d9731ccc6b4d5052de6Samuel Tan  void OnWakeOnWiFiSettingsErrorResponse(
446742866741cd8902bfabd3d9731ccc6b4d5052de6Samuel Tan      NetlinkManager::AuxilliaryMessageType type,
4472b363903f38a515001c5edc7202403fcddb15a01Paul Stewart      const NetlinkMessage* raw_message);
4483a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Message handler for NL80211_CMD_SET_WOWLAN responses.
4493a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  static void OnSetWakeOnPacketConnectionResponse(
4502b363903f38a515001c5edc7202403fcddb15a01Paul Stewart      const Nl80211Message& nl80211_message);
4513a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Request wake on WiFi settings for this WiFi device.
4523a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  void RequestWakeOnPacketSettings();
4533a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Verify that the wake on WiFi settings programmed into the NIC match
454d70ecdf36c94516b71cca8212caeb71da8c63d02Samuel Tan  // those recorded locally for this device in |wake_on_packet_connections_|,
455d70ecdf36c94516b71cca8212caeb71da8c63d02Samuel Tan  // |wake_on_wifi_triggers_|, and |wake_on_ssid_whitelist_|.
4562b363903f38a515001c5edc7202403fcddb15a01Paul Stewart  void VerifyWakeOnWiFiSettings(const Nl80211Message& nl80211_message);
4573a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Sends an NL80211 message to program the NIC with wake on WiFi settings
458d70ecdf36c94516b71cca8212caeb71da8c63d02Samuel Tan  // configured in |wake_on_packet_connections_|, |wake_on_ssid_whitelist_|, and
459d70ecdf36c94516b71cca8212caeb71da8c63d02Samuel Tan  // |wake_on_wifi_triggers_|. If |wake_on_wifi_triggers_| is empty, calls
460d70ecdf36c94516b71cca8212caeb71da8c63d02Samuel Tan  // WakeOnWiFi::DisableWakeOnWiFi.
4613a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  void ApplyWakeOnWiFiSettings();
4623a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Helper function called by |ApplyWakeOnWiFiSettings| that sends an NL80211
4633a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // message to program the NIC to disable wake on WiFi.
4643a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  void DisableWakeOnWiFi();
4653a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Calls |ApplyWakeOnWiFiSettings| and counts this call as
4663a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // a retry. If |kMaxSetWakeOnPacketRetries| retries have already been
4673a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // performed, resets counter and returns.
4683a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  void RetrySetWakeOnPacketConnections();
469cb3ecf321c52de1e72cdf037a459cd893b7c51dbSamuel Tan  // Utility functions to check which wake on WiFi features are currently
470787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  // enabled based on the descriptor |wake_on_wifi_features_enabled_| and
471787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  // are supported by the NIC.
472bb20181bee54a0dee8bba6d1375114f47cabb77fSamuel Tan  bool WakeOnWiFiPacketEnabledAndSupported();
473bb20181bee54a0dee8bba6d1375114f47cabb77fSamuel Tan  bool WakeOnWiFiDarkConnectEnabledAndSupported();
47466bddc67c71dd197211ca08c5a4835bd6cfa5ed2Samuel Tan  // Called by metrics_timer_ to reports metrics.
47566bddc67c71dd197211ca08c5a4835bd6cfa5ed2Samuel Tan  void ReportMetrics();
476787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  // Actions executed before normal suspend and dark resume suspend.
477787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  //
478787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  // Arguments:
479787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  //  - |is_connected|: whether the WiFi device is connected.
480787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  //  - |start_lease_renewal_timer|: whether or not to start the DHCP lease
481787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  //    renewal timer.
482787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  //  - |time_to_next_lease_renewal|: number of seconds until next DHCP lease
483787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  //    renewal is due.
484787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  //  - |remove_supplicant_networks_callback|: callback to invoke
485787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  //    to remove all networks from WPA supplicant.
486787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  void BeforeSuspendActions(
487787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan      bool is_connected,
488787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan      bool start_lease_renewal_timer,
489787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan      uint32_t time_to_next_lease_renewal,
4902b363903f38a515001c5edc7202403fcddb15a01Paul Stewart      const base::Closure& remove_supplicant_networks_callback);
491787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan
492787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  // Needed for |dhcp_lease_renewal_timer_| and |wake_to_scan_timer_| since
493787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  // passing a empty base::Closure() causes a run-time DCHECK error when
494cb0058bd4ca874890cace2f0496bc3ef825a9fe6Samuel Tan  // SimpleAlarmTimer::Start or SimpleAlarmTimer::Reset are called.
495787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  void OnTimerWakeDoNothing() {}
49666bddc67c71dd197211ca08c5a4835bd6cfa5ed2Samuel Tan
4970932171ae1b59449130783c28ac54332d06d4e23Samuel Tan  // Parses an attribute list containing the SSID matches that caused the
4980932171ae1b59449130783c28ac54332d06d4e23Samuel Tan  // system wake, along with the corresponding channels that these SSIDs were
4995d0b8076eee13cd9b3de1c62f982ef0dc430260cSamuel Tan  // detected in. Returns a set of unique frequencies that the reported
5005d0b8076eee13cd9b3de1c62f982ef0dc430260cSamuel Tan  // SSID matches occured in.
5010932171ae1b59449130783c28ac54332d06d4e23Samuel Tan  //
5020932171ae1b59449130783c28ac54332d06d4e23Samuel Tan  // Arguments:
5030932171ae1b59449130783c28ac54332d06d4e23Samuel Tan  //  - |results_list|: Nested attribute list containing an array of nested
5040932171ae1b59449130783c28ac54332d06d4e23Samuel Tan  //    attributes which contain the NL80211_ATTR_SSID or
5050932171ae1b59449130783c28ac54332d06d4e23Samuel Tan  //    NL80211_ATTR_SCAN_FREQUENCIES attributes. This attribute list is assumed
5060932171ae1b59449130783c28ac54332d06d4e23Samuel Tan  //    to have been extracted from a NL80211_CMD_SET_WOWLAN response message
5070932171ae1b59449130783c28ac54332d06d4e23Samuel Tan  //    using the NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS id.
50897dc9c41fb05fc73deebeedf4ab1d975bc10d621Samuel Tan  static WiFi::FreqSet ParseWakeOnSSIDResults(
5090932171ae1b59449130783c28ac54332d06d4e23Samuel Tan      AttributeListConstRefPtr results_list);
5100932171ae1b59449130783c28ac54332d06d4e23Samuel Tan
5114b8436a5136baa1716ca6a1013e2a4ad38ad2437Samuel Tan  // Sets the |dark_resume_scan_retries_left_| counter if necessary, then runs
5124b8436a5136baa1716ca6a1013e2a4ad38ad2437Samuel Tan  // |initiate_scan_callback| with |freqs|.
5134b8436a5136baa1716ca6a1013e2a4ad38ad2437Samuel Tan  void InitiateScanInDarkResume(
5142b363903f38a515001c5edc7202403fcddb15a01Paul Stewart      const InitiateScanCallback& initiate_scan_callback,
5152b363903f38a515001c5edc7202403fcddb15a01Paul Stewart      const WiFi::FreqSet& freqs);
5164b8436a5136baa1716ca6a1013e2a4ad38ad2437Samuel Tan
5173a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Pointers to objects owned by the WiFi object that created this object.
5182b363903f38a515001c5edc7202403fcddb15a01Paul Stewart  EventDispatcher* dispatcher_;
5192b363903f38a515001c5edc7202403fcddb15a01Paul Stewart  NetlinkManager* netlink_manager_;
5202b363903f38a515001c5edc7202403fcddb15a01Paul Stewart  Metrics* metrics_;
5213a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Executes after the NIC's wake-on-packet settings are configured via
5223a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // NL80211 messages to verify that the new configuration has taken effect.
5233a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Calls RequestWakeOnPacketSettings.
5243a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  base::CancelableClosure verify_wake_on_packet_settings_callback_;
525787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  // Callback to be invoked after all suspend actions finish executing both
526787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  // before regular suspend and before suspend in dark resume.
5273a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  ResultCallback suspend_actions_done_callback_;
52866bddc67c71dd197211ca08c5a4835bd6cfa5ed2Samuel Tan  // Callback to report wake on WiFi related metrics.
52966bddc67c71dd197211ca08c5a4835bd6cfa5ed2Samuel Tan  base::CancelableClosure report_metrics_callback_;
5303a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Number of retry attempts to program the NIC's wake-on-packet settings.
5313a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  int num_set_wake_on_packet_retries_;
5323a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Keeps track of triggers that the NIC will be programmed to wake from
5333a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // while suspended.
5343a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  std::set<WakeOnWiFi::WakeOnWiFiTrigger> wake_on_wifi_triggers_;
5353a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Keeps track of what wake on wifi triggers this WiFi device supports.
5363a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  std::set<WakeOnWiFi::WakeOnWiFiTrigger> wake_on_wifi_triggers_supported_;
537dda4da49919c0d10d84bf70ef4313837345cfb6cSamuel Tan  // Max number of patterns this WiFi device can be programmed to wake on at one
538dda4da49919c0d10d84bf70ef4313837345cfb6cSamuel Tan  // time.
5393a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  size_t wake_on_wifi_max_patterns_;
540dda4da49919c0d10d84bf70ef4313837345cfb6cSamuel Tan  // Max number of SSIDs this WiFi device can be programmed to wake on at one
541dda4da49919c0d10d84bf70ef4313837345cfb6cSamuel Tan  // time.
542dda4da49919c0d10d84bf70ef4313837345cfb6cSamuel Tan  uint32_t wake_on_wifi_max_ssids_;
5433a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  // Keeps track of IP addresses whose packets this device will wake upon
544d70ecdf36c94516b71cca8212caeb71da8c63d02Samuel Tan  // receiving while the device is suspended. Only used if the NIC is programmed
545d70ecdf36c94516b71cca8212caeb71da8c63d02Samuel Tan  // to wake on IP address patterns.
5463a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  IPAddressStore wake_on_packet_connections_;
547d70ecdf36c94516b71cca8212caeb71da8c63d02Samuel Tan  // Keeps track of SSIDs that this device will wake on the appearance of while
548d70ecdf36c94516b71cca8212caeb71da8c63d02Samuel Tan  // the device is suspended. Only used if the NIC is programmed to wake on
549d70ecdf36c94516b71cca8212caeb71da8c63d02Samuel Tan  // SSIDs.
550d70ecdf36c94516b71cca8212caeb71da8c63d02Samuel Tan  std::vector<ByteString> wake_on_ssid_whitelist_;
5513a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  uint32_t wiphy_index_;
5523a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  bool wiphy_index_received_;
55396e35cf43e6d5aa2378cdae6fea507e5335d12bbSamuel Tan  // Describes the wake on WiFi features that are currently enabled.
55496e35cf43e6d5aa2378cdae6fea507e5335d12bbSamuel Tan  std::string wake_on_wifi_features_enabled_;
555787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  // Timer that wakes the system to renew DHCP leases.
556041527c80c916008bd0d0697043f272dcf290058Samuel Tan  timers::SimpleAlarmTimer dhcp_lease_renewal_timer_;
557787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  // Timer that wakes the system to scan for networks.
558041527c80c916008bd0d0697043f272dcf290058Samuel Tan  timers::SimpleAlarmTimer wake_to_scan_timer_;
559787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  // Executes when the dark resume actions timer expires. Calls
560787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  // ScanTimerHandler.
561787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  base::CancelableClosure dark_resume_actions_timeout_callback_;
562787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  // Whether shill is currently in dark resume.
563787a1cebf2452c14bf392ab99902e686ea4a6fb4Samuel Tan  bool in_dark_resume_;
5645768ad4f08851b73eddb3328794eaa0ab3094bd3Samuel Tan  // Period (in seconds) between instances where the system wakes from suspend
5655768ad4f08851b73eddb3328794eaa0ab3094bd3Samuel Tan  // to scan for networks in dark resume.
5665768ad4f08851b73eddb3328794eaa0ab3094bd3Samuel Tan  uint32_t wake_to_scan_period_seconds_;
5677804df459a7f29a7463dbd7f0e8e2fea93ee766dSamuel Tan  // Period (in seconds) between instances where the NIC performs Net Detect
5687804df459a7f29a7463dbd7f0e8e2fea93ee766dSamuel Tan  // scans while the system is suspended.
5697804df459a7f29a7463dbd7f0e8e2fea93ee766dSamuel Tan  uint32_t net_detect_scan_period_seconds_;
570bc78c1fefe3bd5d3e4397cb1b4b42cc78ad1e87eSamuel Tan  // Timestamps of dark resume wakes that took place during the current
571bc78c1fefe3bd5d3e4397cb1b4b42cc78ad1e87eSamuel Tan  // or most recent suspend.
572bc78c1fefe3bd5d3e4397cb1b4b42cc78ad1e87eSamuel Tan  EventHistory dark_resume_history_;
5736d61faf84ef5eb2545bc6eee8a4d74109dfdd6d1Samuel Tan  // Last wake reason reported by the kernel.
5746d61faf84ef5eb2545bc6eee8a4d74109dfdd6d1Samuel Tan  WakeOnWiFiTrigger last_wake_reason_;
575c49955996cfa8f28bf3c112499351be7870319b1Samuel Tan  // Whether or not to always start |wake_to_scan_timer_| before suspend.
576c49955996cfa8f28bf3c112499351be7870319b1Samuel Tan  bool force_wake_to_scan_timer_;
5775d0b8076eee13cd9b3de1c62f982ef0dc430260cSamuel Tan  // Frequencies that the last wake on SSID matches reported by the kernel
5785d0b8076eee13cd9b3de1c62f982ef0dc430260cSamuel Tan  // occurred in.
5795d0b8076eee13cd9b3de1c62f982ef0dc430260cSamuel Tan  WiFi::FreqSet last_ssid_match_freqs_;
5804b8436a5136baa1716ca6a1013e2a4ad38ad2437Samuel Tan  // How many more times to retry the last dark resume scan that shill launched
5814b8436a5136baa1716ca6a1013e2a4ad38ad2437Samuel Tan  // if no auto-connectable services were found.
5824b8436a5136baa1716ca6a1013e2a4ad38ad2437Samuel Tan  int dark_resume_scan_retries_left_;
58366bddc67c71dd197211ca08c5a4835bd6cfa5ed2Samuel Tan
5841897afaeb89003f5cc75a256f6fd7528e6abd54fSamuel Tan  // Callback invoked to report the wake reason for the current dark resume to
5851897afaeb89003f5cc75a256f6fd7528e6abd54fSamuel Tan  // powerd.
5861897afaeb89003f5cc75a256f6fd7528e6abd54fSamuel Tan  RecordWakeReasonCallback record_wake_reason_callback_;
5871897afaeb89003f5cc75a256f6fd7528e6abd54fSamuel Tan
5883a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  base::WeakPtrFactory<WakeOnWiFi> weak_ptr_factory_;
589d03b95db5d05928ea63fc9f8aac5151e93c43a2fSamuel Tan
5903a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan  DISALLOW_COPY_AND_ASSIGN(WakeOnWiFi);
5913a1bf99b484ad8a9a054518f49046221251d5612Samuel Tan};
592d03b95db5d05928ea63fc9f8aac5151e93c43a2fSamuel Tan
593d03b95db5d05928ea63fc9f8aac5151e93c43a2fSamuel Tan}  // namespace shill
594d03b95db5d05928ea63fc9f8aac5151e93c43a2fSamuel Tan
595d6a8b519e3057f52313e502f502a4819a942e089Ben Chan#endif  // SHILL_WIFI_WAKE_ON_WIFI_H_
596