History log of /system/connectivity/shill/wifi/wake_on_wifi.cc
Revision Date Author Comments (<<< Hide modified files) (Show modified files >>>)
fa1eb722d0742d89c26b9c5c81d02ef2a138cbf2 21-Dec-2015 Alex Vakulenko <avakulenko@google.com> shill: Disable RTTI

There is no longer a reliance on RTTI in libbrillo, so disable RTTI
in the rest of Brillo codebase.

Shill also used dynamic_cast<> in many places but it looks like there
is no reason for that. Using static_cast<> in those places seems to
work just as well and doesn't require RTTI.

Bug: 26292405, chromium:220387
TEST: Compiles, all unit tests pass on Dragonboard
Was able to bootstrap a device from scratch and networking
seems to work fine.

Change-Id: Id0c47168e634e354b4279f613246e6667df6fb5f
/system/connectivity/shill/wifi/wake_on_wifi.cc
830e5d7924cb43a034f3188cc1f674416d2f74e6 24-Nov-2015 Samuel Tan <samueltan@google.com> shill: rename WakeOnWiFi::OnDHCPLeaseObtained

Rename WakeOnWiFi::OnDHCPLeaseObtained to
WakeOnWiFi::OnConnectedAndReachable to more accurately
reflect the reason why this method is called.
The previous name did not apply to IPv6, since we do
not get DHCP leases when we establishing IPv6 connectivity.

BUG=None.
TEST=shill compiles and unit tests pass

Change-Id: I79fea0e5a1764949c0ce8445dc74b3a9a0534021
/system/connectivity/shill/wifi/wake_on_wifi.cc
bb20181bee54a0dee8bba6d1375114f47cabb77f 28-Oct-2015 Samuel Tan <samueltan@google.com> shill: replace remaining references to wake on SSID feature

Replace remaining references to the wake on SSID feature with references
to the DarkConnect feature.

While there, update the documentation in wake_on_wifi.h to clearly
explain what shill's wake on WiFi features do.

BUG: chromium:431486
TEST: shill compiles and unittests pass on CrOS and Android.
Change-Id: I57afb3b4cb3f44c800bfd7997ef8e33253965c01
/system/connectivity/shill/wifi/wake_on_wifi.cc
e5b5f92d59d69524dbc0e5bcfa7a1923a764d7ce 15-Oct-2015 Samuel Tan <samueltan@google.com> shill: change variable names for "SSID" feature to "DarkConnect"

Change variable names so that the wake on WiFi "SSID" feature is
now known as "DarkConnect".

BUG: chromium:431486
Change-Id: I4d0fa4b62222b65f2d679f87d259ee7ebb95e1d5
TEST: shill compiles successfully and unit tests pass.
/system/connectivity/shill/wifi/wake_on_wifi.cc
289a5a5e18bb1a676b3dfce111af4c2c00c7776e 21-Sep-2015 Samuel Tan <samueltan@google.com> shill: use different service_constants.h path for Android builds

Use the service_constants.h file from the external/cros/system_api/dbus
instead of chromeos/dbus/service_constants.h, since this header file
is installed into different directories when building shill for Android
and Chrome OS.

BUG: 22956441
Change-Id: I7e6ea46b4893588d2862792cf43aa83fdf7c30b4
TEST: shill still compiles using emerge.
/system/connectivity/shill/wifi/wake_on_wifi.cc
ee6001811ba8bba2ec893b842ebbbd59cd8e1d47 16-Sep-2015 Samuel Tan <samueltan@google.com> shill: do not compile code using wowlan symbols when wake-on-WiFi is disabled

Do not compile any code in wake_on_wifi.cc that uses wake-on-wifi NL80211
symbols when wake-on-WiFi is not supported by this board. This makes
sense since this code will not be useful when wake-on-WiFi is not
supported, and will enable shill to compile with older kernel headers
that do not contain all these wake-on-WiFi-related symbols.

While there, clean up
WakeOnWiFiTestWithMockDispatcher.ConfigureSetWakeOnWiFiSettingsMessage
test by removing unnecesary local variables and adding additional
expectations.

BUG=None
TEST=Compile shill and run unit tests using the following commands:

P2_TEST_FILTER="shill::*" FEATURES="test" USE="clang asan wake_on_wifi" \
emerge-samus shill

P2_TEST_FILTER="shill::*" FEATURES="test" USE="clang asan -wake_on_wifi" \
emerge-samus shill

Change-Id: If9ec924ac52f0c55c7e8846d3b612370f26f9546
/system/connectivity/shill/wifi/wake_on_wifi.cc
97dc9c41fb05fc73deebeedf4ab1d975bc10d621 04-Sep-2015 Samuel Tan <samueltan@google.com> shill: Fix "ParseWakeOnWakeOnSSIDResult" typo

Replace all instances of "ParseWakeOnWakeOnSSIDResults"
with "ParseWakeOnSSIDResult".

BUG=None.
TEST=Compile shill and run unit tests.

Change-Id: I53aa0256f9e5c6beb97d8adc5e0b9e754be1d3c0
Reviewed-on: https://chromium-review.googlesource.com/297376
Commit-Ready: Samuel Tan <samueltan@chromium.org>
Tested-by: Samuel Tan <samueltan@chromium.org>
Reviewed-by: Paul Stewart <pstew@chromium.org>
/system/connectivity/shill/wifi/wake_on_wifi.cc
c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5 03-Sep-2015 Peter Qiu <zqiu@google.com> License shill to Apache2

This patch automatically replaced the license on all text files from
Chromium OS (BSD style) to AOSP (Apache2), keeping the original year as
a reference.

The license header was added to .gyp and .gypi, the NOTICE was added with a copy
of the Apache2 license and MODULE_LICENSE_* file was added.

BUG=23587594
TEST=grep 'Chromium OS Authors' doesn't find anything.

Change-Id: If41ede586c2465f5831fb7fee270ff41dbfdb596
/system/connectivity/shill/wifi/wake_on_wifi.cc
041527c80c916008bd0d0697043f272dcf290058 15-Jul-2015 Samuel Tan <samueltan@chromium.org> platform2: use updated AlarmTimer interface

Update shill and power_manager to use the updated AlarmTimer interface,
which requires the construction of a specialized AlarmTimer subclass.

CQ-DEPEND=CL:285670
BUG=chromium:509138
TEST=emerge power_manager and shill and run unit tests.

Manual test on DUT as follows:
1) Build a test image for samus, flash it, and log into it as root
2) Run
dbus-send --system --print-reply --dest=org.chromium.flimflam \
/device/wlan0 org.chromium.flimflam.Device.SetProperty \
string:WakeOnWiFiFeaturesEnabled variant:string:ssid
3) Run
dbus-send --system --print-reply --dest=org.chromium.flimflam \
/device/wlan0 org.chromium.flimflam.Device.SetProperty \
string:ForceWakeToScanTimer variant:boolean:true
4) Run
dbus-send --system --print-reply --dest=org.chromium.flimflam \
/device/wlan0 org.chromium.flimflam.Device.SetProperty \
string:WakeToScanPeriodSeconds variant:uint32:15
5) Make sure WiFi is enabled on the DUT, but do not connect to any wireless
network or ethernet.
6) Run 'echo 1 > /var/lib/power_manager/disable_dark_resume'.
7) Make sure DUT is disconnected from WiFi and ethernet, then run
'powerd_dbus_suspend'.
8) Verify that DUT wakes back up in ~15 seconds.
9) Reboot the DUT
10) Run 'activate_short_dark_resume'
11) Unplug the charging cable from the DUT, and Run 'powerd_dbus_suspend'
12) Verify that the DUT reboots in ~15 seconds.

Change-Id: Id530e8f3ecb466a0ef34c6cdf2c504e305326115
Reviewed-on: https://chromium-review.googlesource.com/285628
Trybot-Ready: Samuel Tan <samueltan@chromium.org>
Tested-by: Samuel Tan <samueltan@chromium.org>
Reviewed-by: Eric Caruso <ejcaruso@chromium.org>
Reviewed-by: mukesh agrawal <quiche@chromium.org>
Commit-Queue: Samuel Tan <samueltan@chromium.org>
/system/connectivity/shill/wifi/wake_on_wifi.cc
dd19dce483cf54007db84bed6c2b523fbce04813 29-Jun-2015 Samuel Tan <samueltan@chromium.org> shill: change criteria for recording dark resume events

Log dark resume events for purposes of throttling when the
current dark resume is caused by wake on SSID or wake on
disconnect, since we want to guard against repeated dark resume
wakes caused by these triggers.

We previously logged only dark resumes that we entered in a
disconnected state. However, this was an issue when shill
entered dark resume because of a disconnect---shill would only
"realize" that it is disconnected shortly after entering dark resume.
This new criteria fixes this issue by relying on the wake reason,
not connectivity status, to decide whether or not to log the
current dark resume.

Also, improve wake on WiFi throttling unit tests by mocking the
time values logged in |dark_resume_history_|.

BUG=chromium:505072
TEST=Compile shill and run unit tests.

Change-Id: I9b99fcea3d1245e5a3db1e6510e24126a48d8d8b
Reviewed-on: https://chromium-review.googlesource.com/282522
Tested-by: Samuel Tan <samueltan@chromium.org>
Reviewed-by: Paul Stewart <pstew@chromium.org>
Commit-Queue: Samuel Tan <samueltan@chromium.org>
/system/connectivity/shill/wifi/wake_on_wifi.cc
2b363903f38a515001c5edc7202403fcddb15a01 16-Jun-2015 Paul Stewart <pstew@chromium.org> shill: wifi: Switch pointer/ref spacing

Switch to Chrome style spacing.

BUG=chromium:501026
TEST=Unit tests

Change-Id: Ieff88b00706ed7c57049531a21427d9ea84b0a71
Reviewed-on: https://chromium-review.googlesource.com/278081
Reviewed-by: Paul Stewart <pstew@chromium.org>
Commit-Queue: Paul Stewart <pstew@chromium.org>
Tested-by: Paul Stewart <pstew@chromium.org>
/system/connectivity/shill/wifi/wake_on_wifi.cc
d0613f39e851f24aaabea70ab5cb1118c3a9fe21 19-Jun-2015 Samuel Tan <samueltan@chromium.org> shill: use decltype in std::set declaration

As suggested by avakulenko@, use the decltype specifier in std::set declarations
with a custom comparator to increase the readability of the declaration.

BUG=None.
TEST=Compile shill and run unit tests.

Change-Id: I976023ebcc1e824fe5fce2e1421f05141d89cdda
Reviewed-on: https://chromium-review.googlesource.com/280588
Trybot-Ready: Samuel Tan <samueltan@chromium.org>
Reviewed-by: Alex Vakulenko <avakulenko@chromium.org>
Reviewed-by: Paul Stewart <pstew@chromium.org>
Commit-Queue: Samuel Tan <samueltan@chromium.org>
Tested-by: Samuel Tan <samueltan@chromium.org>
/system/connectivity/shill/wifi/wake_on_wifi.cc
1897afaeb89003f5cc75a256f6fd7528e6abd54f 21-May-2015 Samuel Tan <samueltan@chromium.org> shill: report dark resume wake reason to powerd via DBus

Report the wake reason for the current dark resume to powerd via
powerd's ReportDarkResumeWakeReason DBus method. shill needs to
report the wake reason to powerd, so that powerd can log wake
duration metrics separately for different wake reasons. (powerd
cannot identify the wake reasons itself, since the reasons come
from the kernel's wireless subsystem.)

CQ-DEPEND=CL:270514
BUG=chromium:485315
TEST=Compile shill and run unit tests.

Change-Id: I6d160a3ab2efdf95dd3e50ffc6c3de66be6f80b7
Reviewed-on: https://chromium-review.googlesource.com/270553
Reviewed-by: mukesh agrawal <quiche@chromium.org>
Commit-Queue: Samuel Tan <samueltan@chromium.org>
Tested-by: Samuel Tan <samueltan@chromium.org>
/system/connectivity/shill/wifi/wake_on_wifi.cc
1a127125de1ef5bc040008fb7b39ddd90fa81096 13-May-2015 Samuel Tan <samueltan@chromium.org> shill: report wakeup reason received metrics only after error checking

Only report to metrics that a wakeup reason has been received after we are sure
that the broadcast message passed to WakeOnWiFi::OnWakeupReasonReceived is a
valid wakeup reason message for its respective interface.

BUG=None
TEST=Compile shill and run unit tests.

Change-Id: I82b0aa3c19c62a014d7f5af9093bc11325d5a1f6
Reviewed-on: https://chromium-review.googlesource.com/270551
Reviewed-by: Paul Stewart <pstew@chromium.org>
Commit-Queue: Samuel Tan <samueltan@chromium.org>
Tested-by: Samuel Tan <samueltan@chromium.org>
/system/connectivity/shill/wifi/wake_on_wifi.cc
92ae133c15e69715df87e0864c3362ab1fe8a055 03-Apr-2015 Samuel Tan <samueltan@chromium.org> shill: add log message reporting wake on WiFi features enabled

Add an INFO log that reports what wake on WiFi features are enabled before
the system enters suspend. This will make it easier to debug wake on WiFi
related bugs since we will know for sure what wake on WiFi capabilities the
system enter suspend with.

Also:
- Only log wake on WiFi suspend/dark resume/resume messages if the
platform supports wake on WiFi so that logs are less confusing.
- Log wakeup reason and WakeOnWiFi::BeforeSuspendActions connection status
at the default (INFO) log level.

BUG=chromium:473734
TEST=None.

Change-Id: I2aaa3d07ab98aa3251d4c03334da53b2cc098e5f
Reviewed-on: https://chromium-review.googlesource.com/263972
Tested-by: Samuel Tan <samueltan@chromium.org>
Reviewed-by: Paul Stewart <pstew@chromium.org>
Commit-Queue: Samuel Tan <samueltan@chromium.org>
/system/connectivity/shill/wifi/wake_on_wifi.cc
029feaca0309984367c2f824957ee250ada45a78 28-Mar-2015 Samuel Tan <samueltan@chromium.org> shill: add dark resume scan retry metrics

Add metrics to track how many dark resume scan retries were launched in each
dark resume, and whether or not these retries led us to re-suspend connected.

Also, remove unnecessary string local variables in
Metrics::NotifyDarkResumeActionsCompleted.

BUG=chromium:471410
TEST=Compile shill and run unit tests.

Change-Id: Ib8c63a3a2b4fe9669e3cf853ee03a8058109661e
Reviewed-on: https://chromium-review.googlesource.com/262906
Tested-by: Samuel Tan <samueltan@chromium.org>
Reviewed-by: Paul Stewart <pstew@chromium.org>
Commit-Queue: Samuel Tan <samueltan@chromium.org>
/system/connectivity/shill/wifi/wake_on_wifi.cc
4b8436a5136baa1716ca6a1013e2a4ad38ad2437 19-Mar-2015 Samuel Tan <samueltan@chromium.org> shill: retry frequency-specific passive scans in dark resume

Retry frequency-specific passive scans launched in dark resume up to
5 times since we may fail to receive AP beacons on some passive scans. This
will improve the reliability of frequency-specific passive scans in dark
resume.

Also, change log messages on suspend, dark resume, and full resume functions
in WiFi so that the WiFi device's connectivity status is logged by default
on these events.

BUG=chrome-os-partner:32269, chrome-os-partner:36471
TEST=Compile shill and run unit tests using:

P2_TEST_FILTER="shill::*" FEATURES="test" \
USE="wake_on_wifi clang asan" emerge-samus shill

P2_TEST_FILTER="shill::*" FEATURES="test" \
USE="-wake_on_wifi clang asan" emerge-samus shill

Manual testing as follows:
1) Flash a samus with test image and boot into it.
2) Run
ff_debug +wifi; ff_debug --level -3
3) Run
echo 0 > /var/lib/power_manager/disable_dark_resume; restart \
powerd
4) Enable the wake on WiFi SSID feature with the following command:
dbus-send --system --print-reply --dest=org.chromium.flimflam \
/device/wlan0 org.chromium.flimflam.Device.SetProperty \
string:WakeOnWiFiFeaturesEnabled \
variant:string:packet_and_ssid
5) Set the net detect scan period to 30 seconds with the
following command:
dbus-send --system --print-reply --dest=org.chromium.flimflam \
/device/wlan0 org.chromium.flimflam.Device.SetProperty \
string:NetDetectScanPeriodSeconds variant:uint32:30
6) Connect samus to an AP (make sure AP is one that you can run ping from).
7) Run 'powerd_dbus_suspend' to suspend the system.
8) Wait 10 seconds, then disable the AP.
9) Wait 15 seconds, then re-enable the AP.
10) Wait, 80 seconds, then wake the samus by pressing any key.
11) Immediately upon waking the system, verify that the WiFi status icon is
in the connected state.
12) Run
grep 'BeforeSuspendActions.*connected' /var/log/net.log | tail -1
and verify that the line printed says "BeforeSuspendActions: connected".

Change-Id: Ic2e4096a7cfabec2c16fc2d27bd114372ab8795b
Reviewed-on: https://chromium-review.googlesource.com/261337
Tested-by: Samuel Tan <samueltan@chromium.org>
Reviewed-by: Paul Stewart <pstew@chromium.org>
Commit-Queue: Samuel Tan <samueltan@chromium.org>
/system/connectivity/shill/wifi/wake_on_wifi.cc
5d0b8076eee13cd9b3de1c62f982ef0dc430260c 17-Feb-2015 Samuel Tan <samueltan@chromium.org> shill: only scan on select channels when waking on SSID

When we wake on SSID and have SSID match results, instead of launching a passive
scan on all channels, passive scan only on channels where SSID matches were
reported to have occured in. This should reduce scan time, thus decreasing the
amount of time required to scan and connect to a network in dark resume when
wake on SSID occurs.

Also, change wake on WiFi throttling log message slightly to reflect that
the feature is temporarily, not permanantly, disabled.

BUG=chrome-os-partner:32269, chrome-os-partner:36471
TEST=Compile shill and run unit tests using:

P2_TEST_FILTER="shill::*" FEATURES="test" \
USE="wake_on_wifi clang asan" emerge-samus shill

P2_TEST_FILTER="shill::*" FEATURES="test" \
USE="-wake_on_wifi clang asan" emerge-samus shill

Manual testing as follows:
1) Flash a samus with test image and boot into it.
2) Run
ff_debug +wifi; ff_debug --level -3
3) Run
echo 0 > /var/lib/power_manager/disable_dark_resume; restart \
powerd
4) Enable the wake on WiFi SSID feature with the following command:
dbus-send --system --print-reply --dest=org.chromium.flimflam \
/device/wlan0 org.chromium.flimflam.Device.SetProperty \
string:WakeOnWiFiFeaturesEnabled \
variant:string:packet_and_ssid
5) Set the net detect scan period to 30 seconds with the
following command:
dbus-send --system --print-reply --dest=org.chromium.flimflam \
/device/wlan0 org.chromium.flimflam.Device.SetProperty \
string:NetDetectScanPeriodSeconds variant:uint32:30
6) Connect samus to an AP (make sure AP is one that you can run ping from).
7) Run 'powerd_dbus_suspend' to suspend the system.
8) Wait 10 seconds, then disable the AP.
9) Wait 15 seconds, then re-enable the AP.
10) Wait, 80 seconds, then wake the samus by pressing any key.
11) Immediately upon waking the system, verify that the WiFi status icon is
in the connected state.
12) Run
grep 'BeforeSuspendActions.*connected' /var/log/net.log | tail -1
and verify that the line printed says "BeforeSuspendActions: connected".

Change-Id: Icef9d30a6ed239c9dd7af4b6c8ac42dd2269c5f7
Reviewed-on: https://chromium-review.googlesource.com/250550
Tested-by: Samuel Tan <samueltan@chromium.org>
Reviewed-by: Paul Stewart <pstew@chromium.org>
Commit-Queue: Samuel Tan <samueltan@chromium.org>
/system/connectivity/shill/wifi/wake_on_wifi.cc
4c040c955b9fa793dbf871f1fd7b407f6e5c7ca0 11-Mar-2015 Samuel Tan <samueltan@chromium.org> shill: fall back on wake to scan timer on excessive dark resumes

Instead of disabling wake on WiFi completely when too many dark resumes have
occurred, fall back on the wake to scan timer to wake us up 15 minutes later
to resume normal wake on WiFi behavior.

BUG=chromium:466349
TEST=Compile shill and run unit tests.

Change-Id: I245fa21a7bcfb42e65981258b7036e261ffca05c
Reviewed-on: https://chromium-review.googlesource.com/259050
Tested-by: Samuel Tan <samueltan@chromium.org>
Reviewed-by: Paul Stewart <pstew@chromium.org>
Commit-Queue: Samuel Tan <samueltan@chromium.org>
/system/connectivity/shill/wifi/wake_on_wifi.cc
d1bec5d563afc9074a1875e2302d5ecf54c95f95 06-Mar-2015 Samuel Tan <samueltan@chromium.org> shill: log metrics when scans are launched in dark resume

Have shill parse NL80211_CMD_TRIGGER_SCAN scan started notifications, and log
metrics if a scan is started in dark resume.

BUG=chromium:462801
TEST=Compile shill and run unit tests.

Change-Id: I920ae3bd1026f5dc2b1e16c71627bcfe13e8b1e1
Reviewed-on: https://chromium-review.googlesource.com/257740
Reviewed-by: Paul Stewart <pstew@chromium.org>
Commit-Queue: Samuel Tan <samueltan@chromium.org>
Tested-by: Samuel Tan <samueltan@chromium.org>
/system/connectivity/shill/wifi/wake_on_wifi.cc
235dcec779704b782f0608421d890fe6d183e7cc 10-Mar-2015 Samuel Tan <samueltan@chromium.org> shill: save wiphy_index in WiFi

Save the wiphy interface index in WiFi instead of only in WakeOnWiFi since the
former will need this index for netlink message parsing.

Also,
- Move wiphy index parsing from WakeOnWiFi to WiFi
- Move wiphy index parsing unit tests from WakeOnWiFi to WiFi
- Complete WiFiMainTest.OnNewWiphy unit test

BUG=chromium:462801
TEST=Compile shill and run unit tests.

Change-Id: I62db65542d13156bd88c939b1c3d35b0583081fe
Reviewed-on: https://chromium-review.googlesource.com/258521
Tested-by: Samuel Tan <samueltan@chromium.org>
Reviewed-by: Paul Stewart <pstew@chromium.org>
Commit-Queue: Samuel Tan <samueltan@chromium.org>
/system/connectivity/shill/wifi/wake_on_wifi.cc
e58fa86282bb07867793ba78e9ff1c56fdc2d2b3 04-Mar-2015 Samuel Tan <samueltan@chromium.org> shill: Replace Wake on WiFi "disabled" log messages

Replace error messages stating that Wake on WiFi is "disabled" with error
messages that say that Wake on WiFi is "not supported" in all cases where Wake
on WiFi-related functionality when the DISABLE_WAKE_ON_WIFI compile-time flag is
set. Do this so that error messages are consistent when the platform does not
supported Wake on WiFi (i.e. DISABLE_WAKE_ON_WIFI is set).

Also
- Log "Wake on WiFi not supported" messages in the WiFi scope at level 7, since
we consider running into this error "normal" behavior by Chrome and do not
want to spam the logs at the default level.
- Remove TODO from comment above |wake_on_wifi_features_enabled_|
initialization since Chrome is responsible for setting this value via DBus.

BUG=chromium:463954
TEST=Compile shill and run unit tests with and without the "wake_on_wifi" USE
flag.

Change-Id: Ic09a71861d7eda37d67c2320d4262d0a13187188
Reviewed-on: https://chromium-review.googlesource.com/255783
Tested-by: Samuel Tan <samueltan@chromium.org>
Reviewed-by: Paul Stewart <pstew@chromium.org>
Commit-Queue: Samuel Tan <samueltan@chromium.org>
/system/connectivity/shill/wifi/wake_on_wifi.cc
c49955996cfa8f28bf3c112499351be7870319b1 03-Mar-2015 Samuel Tan <samueltan@chromium.org> shill: allow forced starting of wake-to-scan timer via DBus

Allow the toggling of a boolean, |force_wake_to_scan_timer_| via DBus
(i.e. the Device DBus property ForceWakeToScanTimer) that forces shill to
start the wake-to-scan timer every time shill goes into suspend disconnected
with wake on WiFi enabled. This will be used for autotests and manual tests
that want to trigger wake-to-scan timer wakes.

BUG=chromium:463301
CQ-DEPEND=CL:255551
TEST=Compile shill and run unit tests.

Manual testing as follows:
1) Boot into a samus test image.
2) Run 'dbus-send --system --print-reply --dest=org.chromium.flimflam
/device/wlan0 org.chromium.flimflam.Device.GetProperties'.
3) Verify that ForceWakeToScanTimer is present and set to 'false'.
4) Run 'dbus-send --system --print-reply --dest=org.chromium.flimflam
/device/wlan0 org.chromium.flimflam.Device.SetProperty
string:ForceWakeToScanTimer variant:boolean:true' and verify that no error
response is printed.
5) Run 'dbus-send --system --print-reply --dest=org.chromium.flimflam
/device/wlan0 org.chromium.flimflam.Device.SetProperty
string:WakeOnWiFiFeaturesEnabled variant:string:ssid'.
6) Run 'dbus-send --system --print-reply --dest=org.chromium.flimflam
/device/wlan0 org.chromium.flimflam.Device.SetProperty
string:WakeToScanPeriodSeconds variant:uint32:20'.
7) Run 'echo 0 > /var/lib/power_manager/disable_dark_resume; restart powerd'
8) Run 'grep "OnDarkResume" /var/log/net.log | wc -l' and ensure that the
output is 0.
9) Ensure that the samus is not connected to a WiFi network, and run
'powerd_dbus_suspend'.
10) Wait 40 seconds, then resume the samus by pressing any key.
11) Run 'grep "OnDarkResume" /var/log/net.log | wc -l' and verify that the
output is 1.

Change-Id: I03035e38ac8044c1ca9164ce16ca319d4106fbc0
Reviewed-on: https://chromium-review.googlesource.com/255561
Reviewed-by: Samuel Tan <samueltan@chromium.org>
Commit-Queue: Samuel Tan <samueltan@chromium.org>
Tested-by: Samuel Tan <samueltan@chromium.org>
/system/connectivity/shill/wifi/wake_on_wifi.cc
bc78c1fefe3bd5d3e4397cb1b4b42cc78ad1e87e 26-Feb-2015 Samuel Tan <samueltan@chromium.org> shill: reduce dark resume frequency threshold and add longer threshold

Reduce the dark resume frequnecy threshold in WakeOnWiFi from 5 per minute to
3 per minute so that we more easily catch cases where shill is thrashing on
disconnected dark resumes.

Also, instead add a longer threshold (10 dark resumes per 10 minutes) to catch
cases of thrashing where dark resumes are taking place slowly but regularly.
Implement this by recording ever dark resume events during a single suspend
session and using EventHistory::CountEventsWithinInterval to check how many dark
resumes have occured in the last short period (1 minute) and long period (10
minutes).

Also:
- rename |dark_resumes_since_last_suspend_| to |dark_resume_history_| in
wake_on_wifi.h.
- Change the bool argument |count_suspend_actions| to an enum
EventHistory::ClockType to increase readibility of EventHistory function
invocations.

BUG=chrome-os-partner:36968
TEST=Compile shill and run unit tests using the following commands:

P2_TEST_FILTER="shill::*" FEATURES="test" USE="wake_on_wifi \
clang asan" emerge-samus shill

P2_TEST_FILTER="shill::*" FEATURES="test" USE="-wake_on_wifi \
clang asan" emerge-samus shill

Change-Id: I578434015a69cefd275e6ea0c1bb7167ffd87c21
Reviewed-on: https://chromium-review.googlesource.com/253872
Reviewed-by: Samuel Tan <samueltan@chromium.org>
Tested-by: Samuel Tan <samueltan@chromium.org>
Commit-Queue: Samuel Tan <samueltan@chromium.org>
/system/connectivity/shill/wifi/wake_on_wifi.cc
4bf0b5ccd6d4efac04e14b51ac2fe60550222e3c 13-Feb-2015 Samuel Tan <samueltan@chromium.org> shill: organize WiFi and WakeOnWiFi log messages

Change the log scopes and levels for several wake on WiFi related log messags
in wifi.cc and wake_on_wifi.cc so that no unnecessary messages are logged
outside of net.log and messages useful for general debugging are visible at
the default shill log level. With this change, all wake on WiFi related logs
will only be logged in net.log (using SLOG instead of LOG(INFO)), and no
messages reflecting the normal, expected operation of shill is logged to
LOG(ERROR).

BUG=None.
TEST=Compile shill and run unit tests using the following commands:

P2_TEST_FILTER="shill::*" FEATURES="test" \
USE="wake_on_wifi clang asan" emerge-samus shill

P2_TEST_FILTER="shill::*" FEATURES="test" \
USE="-wake_on_wifi clang asan" emerge-samus shill

Change-Id: Ib508bd6b07ffe22d0f4fb4e85acf14841c209071
Reviewed-on: https://chromium-review.googlesource.com/249542
Tested-by: Samuel Tan <samueltan@chromium.org>
Reviewed-by: Paul Stewart <pstew@chromium.org>
Commit-Queue: Samuel Tan <samueltan@chromium.org>
/system/connectivity/shill/wifi/wake_on_wifi.cc
a49334304182db378741214a1a82e47351c3fddb 07-Feb-2015 Samuel Tan <samueltan@chromium.org> shill: add wakeup reason metrics

Add metrics to track the wakeup reason received in dark resume, and whether
or not the wakeup reason is received before WakeOnWiFi::OnDarkResume uses it
to perform dark resume actions.

Also:
- Add unit tests for previously untested functions in the Metrics class.
- Rearrange wake on WiFi-related constants in metrics.h and metrics.cc.

BUG=chrome-os-partner:36471
TEST=Compile shill and run unit tests using the following commands:

P2_TEST_FILTER="shill::*" FEATURES="test" \
USE="wake_on_wifi clang asan" emerge-samus shill

P2_TEST_FILTER="shill::*" FEATURES="test" \
USE="-wake_on_wifi clang asan" emerge-samus shill

Change-Id: If20dd0cb903e71fe5b58b15142b2efb008809f7b
Reviewed-on: https://chromium-review.googlesource.com/249423
Reviewed-by: Paul Stewart <pstew@chromium.org>
Tested-by: Samuel Tan <samueltan@chromium.org>
Commit-Queue: Samuel Tan <samueltan@chromium.org>
/system/connectivity/shill/wifi/wake_on_wifi.cc
6d61faf84ef5eb2545bc6eee8a4d74109dfdd6d1 06-Feb-2015 Samuel Tan <samueltan@chromium.org> shill: use wake reasons for dark resume logic

Use the wake reasons reported by the kernel to choose what actions shill
performs in dark resume. If the wake reason is not reported or unsupported,
shill defaults to the previous logic (choosing actions based on current
connection status). The exit-path out of dark resume into re-suspend (i.e.
WakeOnWiFi::BeforeSuspendActions) remains unchanged.

Also:
- Added cases where the system suspends in dark resume because no
autoconnectable services were found to previous dark resume unit tests.
- Prefixed WakeOnWiFiTrigger enums with "WakeTrigger" for added clarity.
- Add expectations for Metrics::NotifyDarkResumeInitiateScan in dark resume
unit tests.

BUG=chrome-os-partner:32269, chrome-os-partner:36471
TEST=Compile shill and run unit tests using:

P2_TEST_FILTER="shill::*" FEATURES="test" \
USE="wake_on_wifi clang asan" emerge-samus shill

P2_TEST_FILTER="shill::*" FEATURES="test" \
USE="-wake_on_wifi clang asan" emerge-samus shill

Manual testing as follows:
1) Flash a samus with test image and boot into it.
2) Run
ff_debug +wifi; ff_debug --level -3
3) Run
echo 0 > /var/lib/power_manager/disable_dark_resume; restart \
powerd
4) Run
echo disabled > /sys/bus/i2c/devices/i2c-ATML0000\:01/power/wakeup
5) Enable the wake on WiFi SSID feature with the following command:
dbus-send --system --print-reply --dest=org.chromium.flimflam \
/device/wlan0 org.chromium.flimflam.Device.SetProperty \
string:WakeOnWiFiFeaturesEnabled \
variant:string:packet_and_ssid
6) Set the net detect scan period to 60 seconds with the
following command:
dbus-send --system --print-reply --dest=org.chromium.flimflam \
/device/wlan0 org.chromium.flimflam.Device.SetProperty \
string:NetDetectScanPeriodSeconds variant:uint32:60
7) Connect samus to an AP (make sure AP is one that you can run ping from).
8) Enable waking on packets from the AP with the following command:
dbus-send --system --print-reply --dest=org.chromium.flimflam \
/device/wlan0 org.chromium.flimflam.Device.AddWakeOnPacketConnection \
string:"1.1.1.1"
where 1.1.1.1 is the IP address of the AP.
9) Run 'powerd_dbus_suspend' to suspend the system.
10) Wait 15 seconds, then ping the samus from the AP.
11) Verify that within 5 seconds of sending the ping, the AP gets a pong from
the samus.
12) Wake the samus by pressing any key.
13) Run 'powerd_dbus_suspend' to suspend the system.
14) Wait 10 seconds, then disable the AP.
15) Wait 15 seconds, then re-enable the AP.
16) Wait, 80 seconds, then wake the samus by pressing any key.
17) Immediately upon waking the system, verify that the WiFi status icon is
in the connected state.
18) Run
grep 'BeforeSuspendActions.*connected' /var/log/net.log | tail -1
and verify that the line printed says "BeforeSuspendActions: connected".

Change-Id: I499b702e242b35a0e23cb917e66e5e757f476e6e
Reviewed-on: https://chromium-review.googlesource.com/246365
Reviewed-by: Samuel Tan <samueltan@chromium.org>
Tested-by: Samuel Tan <samueltan@chromium.org>
Commit-Queue: Samuel Tan <samueltan@chromium.org>
/system/connectivity/shill/wifi/wake_on_wifi.cc
0932171ae1b59449130783c28ac54332d06d4e23 31-Dec-2014 Samuel Tan <samueltan@chromium.org> shill: parse wakeup reason reported by kernel

Parse the wakeup reason broadcasted by the kernel, including the
SSIDs reported by the kernel on net detect wakes, and log this
reported wakeup reason.

Also:
- Change nlmsg_type of of messages used in wake_on_wifi_unittest.cc so that
they all have nlmsg_type of 0x13, which is type we assume all messages have
in this set of unit tests (i.e. kNl80211FamilyId).
- Remove unused constants.
- Remove unnecessary function call and expectation from
WiFiMainTest.OnBeforeSuspend_CallsWakeOnWiFi and
WiFiMainTest.OnDarkResume_CallsWakeOnWiFi.

BUG=chrome-os-partner:36471
TEST=Compile shill and run unit tests using:

P2_TEST_FILTER="shill::*" FEATURES="test" \
USE="wake_on_wifi clang asan" emerge-samus shill

P2_TEST_FILTER="shill::*" FEATURES="test" \
USE="-wake_on_wifi clang asan" emerge-samus shill

Manual testing as follows:
1) Flash a samus with test image and boot into it.
2) Run
ff_debug +wifi; ff_debug --level -3
3) Run
echo 0 > /var/lib/power_manager/disable_dark_resume; restart \
powerd
4) Run
echo disabled > /sys/bus/i2c/devices/i2c-ATML0000\:01/power/wakeup
5) Enable the wake on WiFi SSID feature with the following command:
dbus-send --system --print-reply --dest=org.chromium.flimflam \
/device/wlan0 org.chromium.flimflam.Device.SetProperty \
string:WakeOnWiFiFeaturesEnabled \
variant:string:packet_and_ssid
6) Set the net detect scan period to 60 seconds with the
following command:
dbus-send --system --print-reply --dest=org.chromium.flimflam \
/device/wlan0 org.chromium.flimflam.Device.SetProperty \
string:NetDetectScanPeriodSeconds variant:uint32:60
7) Connect samus to an AP (make sure AP is one that you can run ping from).
8) Enable waking on packets from the AP with the following command:
dbus-send --system --print-reply --dest=org.chromium.flimflam \
/device/wlan0 org.chromium.flimflam.Device.AddWakeOnPacketConnection \
string:"1.1.1.1"
where 1.1.1.1 is the IP address of the AP.
9) Run
grep "Wakeup reason: Pattern" /var/log/net.log | wc -l
and verify that the output is 0.
10) Run 'powerd_dbus_suspend' to suspend the system.
11) Wait 15 seconds, then ping the samus from the AP.
12) Wait 5 seconds, then wake the samus by pressing any key.
13) Repeat step 9, but verify that the output is now 1.
14) Disable the AP. Verify that the samus is fully disconnected by the
WiFi icon state (a cross over empty WiFi bars).
15) Run
grep "Wakeup reason: SSID" /var/log/net.log | wc -l
and verify that the output is 0.
16) Run 'powerd_dbus_suspend' to suspend the system.
17) Wait 10 seconds, then re-enable the AP.
18) Wait, 80 seconds, then wake the samus by pressing any key.
19) Repeat step 15, but verify that the output is now 1.
20) Make sure that the samus is connected to the AP.
21) Run
grep "Wakeup reason: Disconnect" /var/log/net.log | wc -l
and verify that the output is 0.
22) Run 'powerd_dbus_suspend' to suspend the system.
23) Wait 10 seconds, then disable the AP.
24) Wait 15 seconds, then wake the samus by pressing any key.
25) Repeat step 21, but verify that the output is now 1.

Change-Id: I6da02e683ceaf51f5cccf3c1e87a419b51e8449b
Reviewed-on: https://chromium-review.googlesource.com/240681
Reviewed-by: Samuel Tan <samueltan@chromium.org>
Tested-by: Samuel Tan <samueltan@chromium.org>
Commit-Queue: Samuel Tan <samueltan@chromium.org>
/system/connectivity/shill/wifi/wake_on_wifi.cc
d70ecdf36c94516b71cca8212caeb71da8c63d02 12-Jan-2015 Samuel Tan <samueltan@chromium.org> shill: configure NIC to wake on SSID

Enable shill to program the NIC to wake the system
from suspend on the appearance of whitelisted SSIDs.

BUG=chrome-os-partner:32269
TEST=Compile shill and run unit tests using:

P2_TEST_FILTER="shill::*" FEATURES="test" \
USE="wake_on_wifi clang asan" emerge-samus shill

P2_TEST_FILTER="shill::*" FEATURES="test" \
USE="-wake_on_wifi clang asan" emerge-samus shill

Manual testing as follows:
1) Flash a samus with test image and boot into it.
2) Run
ff_debug +wifi; ff_debug --level -3
3) Run
echo 0 > /var/lib/power_manager/disable_dark_resume; restart \
powerd
4) Run
echo disabled > /sys/bus/i2c/devices/i2c-ATML0000\:01/power/wakeup
5) Enable the wake on WiFi SSID feature with the following command:
dbus-send --system --print-reply --dest=org.chromium.flimflam \
/device/wlan0 org.chromium.flimflam.Device.SetProperty \
string:WakeOnWiFiFeaturesEnabled \
variant:string:ssid
6) Set the net detect scan period to 60 seconds with the
following command:
dbus-send --system --print-reply --dest=org.chromium.flimflam \
/device/wlan0 org.chromium.flimflam.Device.SetProperty \
string:NetDetectScanPeriodSeconds variant:uint32:60
7) Connect samus to an AP.
8) Disable the AP. Verify that the samus is fully disconnected by the
WiFi icon state (a cross over empty WiFi bars).
9) Run 'powerd_dbus_suspend' to suspend the system.
10) 10 seconds after step 9, re-enable the AP.
11) Wait 120 seconds (start counting right after performing step 9).
12) Wake the samus by pressing any key.
13) Verify that the samus is connected to WiFi immediately after waking
by ensuring that it wakes up with the WiFi icon in the connected
state.

Change-Id: Ibfe5fa810770c0faa292c1f9fe423e3ee61668cf
Reviewed-on: https://chromium-review.googlesource.com/240579
Reviewed-by: Samuel Tan <samueltan@chromium.org>
Tested-by: Samuel Tan <samueltan@chromium.org>
Commit-Queue: Samuel Tan <samueltan@chromium.org>
/system/connectivity/shill/wifi/wake_on_wifi.cc
dda4da49919c0d10d84bf70ef4313837345cfb6c 31-Dec-2014 Samuel Tan <samueltan@chromium.org> shill: check for net detect support on wiphy interface

Parse net detect capabilities reported in NL80211_CMD_NEW_WIPHY
nl80211 messages to determine whether the NIC supports net detect
(i.e. wake on SSID) and if so, how many whitelisted SSIDs it can
use at once.

BUG=chrome-os-partner:32269
CQ-DEPEND=CL:239890, CL:248191
TEST=Compile shill and run unit tests using

P2_TEST_FILTER="shill::*" FEATURES="test" USE="clang asan" \
emerge-samus shill

Manual tests as follow:
1) Boot into samus test image.
2) Run 'restart shill SHILL_LOG_LEVEL=-7 SHILL_LOG_SCOPES="wifi"'.
3) Run 'grep "supported by this WiFi device" /var/log/net.log'.
4) Verify that grep returns three matching lines reporting that the
NIC supports wake on disconnect, wake on pattern (on up to 20
patterns 16-128 bytes), and wake on SSID (on up to 11 whitelisted
SSIDs).

Change-Id: I396ddd75ded37a6ce794cb3ec383e359634794d2
Reviewed-on: https://chromium-review.googlesource.com/240577
Reviewed-by: Samuel Tan <samueltan@chromium.org>
Tested-by: Samuel Tan <samueltan@chromium.org>
Commit-Queue: Samuel Tan <samueltan@chromium.org>
/system/connectivity/shill/wifi/wake_on_wifi.cc
56cd167db0e1049a6946446b95f150fa8a3e59cd 11-Feb-2015 Samuel Tan <samueltan@chromium.org> shill: check correct data structure size in AddWakeOnPacketConnection

Check the size of |wake_on_packet_connections_| instead of
|wake_on_wifi_triggers_| in WakeOnWiFi::AddWakeOnPacketConnection to determine
if the max number of wake patterns have already been registered.

BUG=chromium:457526
TEST=Compile shill and run unit tests using:

P2_TEST_FILTER="shill::*" FEATURES="test" USE="wake_on_wifi clang asan" \
emerge-samus shill

P2_TEST_FILTER="shill::*" FEATURES="test" USE="-wake_on_wifi clang asan" \
emerge-samus shill

Change-Id: Iaf7cd7e80df618130ced86b703fce83b1aba4b15
Reviewed-on: https://chromium-review.googlesource.com/248433
Trybot-Ready: Samuel Tan <samueltan@chromium.org>
Tested-by: Samuel Tan <samueltan@chromium.org>
Reviewed-by: Paul Stewart <pstew@chromium.org>
Commit-Queue: Samuel Tan <samueltan@chromium.org>
/system/connectivity/shill/wifi/wake_on_wifi.cc
c36b410afd8d68a5ced58b3a937aa4efdde2aa7d 27-Jan-2015 Samuel Tan <samueltan@chromium.org> shill: add metrics for wake on WiFi throttling

Add metric to log whether or not wake on WiFi is disabled
in the duration of a single suspend because of excessive
dark resume wakes.

BUG=chrome-os-partner:35518
TEST=Compile shill and run unit tests using the following commands:

P2_TEST_FILTER="shill::*" FEATURES="test" USE="wake_on_wifi \
clang asan" emerge-samus shill

P2_TEST_FILTER="shill::*" FEATURES="test" USE="-wake_on_wifi \
clang asan" emerge-samus shill

Change-Id: I2c6552d1f2d7b5c6857bf565f65a7c9ecb92b873
Reviewed-on: https://chromium-review.googlesource.com/243428
Tested-by: Samuel Tan <samueltan@chromium.org>
Reviewed-by: Paul Stewart <pstew@chromium.org>
Commit-Queue: Samuel Tan <samueltan@chromium.org>
/system/connectivity/shill/wifi/wake_on_wifi.cc
ff59a1896ea250b4450b54db697692e0b1949528 21-Jan-2015 Samuel Tan <samueltan@chromium.org> shill: disable wake on WiFi on excessive dark resume wakes

Use EventHistory to log how often we wake up in dark resume
in a disconnected state, and disable wake on WiFi if this
happens too often.

Also:
- Have shill report done by calling |suspend_actions_done_callback_|
if configuring an NL80211 message fails in
WakeOnWiFi::ApplyWakeOnWiFiSettings and
WakeOnWiFi::DisableWakeOnWiFi (same exit path as a failure on
NetlinkManager::SendNl80211Message in these functions).

BUG=chrome-os-partner:35518
TEST=Compile shill and run unit tests using the following commands:

P2_TEST_FILTER="shill::*" FEATURES="test" USE="wake_on_wifi \
clang asan" emerge-samus shill

P2_TEST_FILTER="shill::*" FEATURES="test" USE="-wake_on_wifi \
clang asan" emerge-samus shill

Manual testing as follows:

1) Flash a samus with test image and boot into it.
2) Run
ff_debug +wifi; ff_debug --level -3
3) Run
echo 0 > /var/lib/power_manager/disable_dark_resume; restart \
powerd
4) Enable the wake on WiFi SSID feature with the following command:
dbus-send --system --print-reply --dest=org.chromium.flimflam \
/device/wlan0 org.chromium.flimflam.Device.SetProperty \
string:WakeOnWiFiFeaturesEnabled \
variant:string:ssid
5) Set the wake-to-scan period to 10 seconds with the
following command:
dbus-send --system --print-reply --dest=org.chromium.flimflam \
/device/wlan0 org.chromium.flimflam.Device.SetProperty \
string:WakeToScanPeriodSeconds variant:uint32:10
6) Connect samus to an AP.
7) Disable the AP. Verify that the samus is fully disconnected by the
WiFi icon state (a cross over empty WiFi bars).
8) Run 'grep "Too many dark resumes" /var/log/net.log | wc -l' and note
the value of the integer output.
9) Run 'powerd_dbus_suspend' to suspend the system.
10) Wait 120 seconds (start counting right after performing step 9).
11) Wake the samus by pressing any key.
12) Run 'grep "Too many dark resumes" /var/log/net.log | wc -l' and
verify that the integer output is still the same as it was in step
8.
13) Repeat step 5 but set the wake-to-scan period to 5 seconds instead.
14) Repeat steps 8-9.
15) Wait 60 seconds.
16) Repeat step 11-12, but verify that the value of the integer output
is now 1 larger than it was in steps 8 and 12.

Change-Id: I0556c1a5199c7f28b2d1d5381a23a4a6bcb9b9a9
Reviewed-on: https://chromium-review.googlesource.com/242406
Tested-by: Samuel Tan <samueltan@chromium.org>
Reviewed-by: Paul Stewart <pstew@chromium.org>
Commit-Queue: Samuel Tan <samueltan@chromium.org>
/system/connectivity/shill/wifi/wake_on_wifi.cc
34f424e672439bdf237a755f85245ebd7b66e8e2 17-Jan-2015 Paul Stewart <pstew@chromium.org> shill: Error: Attribute source from PopulateAndLog

Have callers pass the source file/line of PopulateAndLog calls so
the log message can disambiguate the ultimate source of the error.

BUG=chromium:449528
TEST=Unit tests + manual: restart shill and "grep error.cc /var/log/net.log"

Change-Id: I7bb54e966b047025a3ec7ef18acce5b8bed3d031
Reviewed-on: https://chromium-review.googlesource.com/241522
Reviewed-by: Paul Stewart <pstew@chromium.org>
Commit-Queue: Paul Stewart <pstew@chromium.org>
Tested-by: Paul Stewart <pstew@chromium.org>
/system/connectivity/shill/wifi/wake_on_wifi.cc
7804df459a7f29a7463dbd7f0e8e2fea93ee766d 13-Jan-2015 Samuel Tan <samueltan@chromium.org> shill: add net detect scan period member

Add a member to wake on WiFi that determines how often the wireless
NIC will perform netdetect scans while the system is suspended.
This member will be exposed via DBus under the
kNetdetectScanFrequencySecondsProperty in
system_api/service_constants.h.

BUG=chrome-os-partner:32269
CQ-DEPEND=CL:240265
TEST=Compile shill.

Change-Id: Ie17930a759f83fcc02a20ce1d82d4f633f61647c
Reviewed-on: https://chromium-review.googlesource.com/240576
Reviewed-by: Samuel Tan <samueltan@chromium.org>
Tested-by: Samuel Tan <samueltan@chromium.org>
Commit-Queue: Samuel Tan <samueltan@chromium.org>
/system/connectivity/shill/wifi/wake_on_wifi.cc
5768ad4f08851b73eddb3328794eaa0ab3094bd3 13-Jan-2015 Samuel Tan <samueltan@chromium.org> shill: change wake to scan frequency member and property name

Add the "Seconds" unit to the wake to scan frequency member and property
name to explicitly state what unit this frequency property is given in.
Also, change the substring "Frequency" to "Period" to more accurately
reflect that this member/property refers to the length of time between each
wake to scan event.

BUG=chromium:448222
CQ-DEPEND=CL:240266
TEST=Compile shill.

Change-Id: I1b3dd8ca1a1172168047f25d912c44d6ab2b98aa
Reviewed-on: https://chromium-review.googlesource.com/240267
Tested-by: Samuel Tan <samueltan@chromium.org>
Reviewed-by: Paul Stewart <pstew@chromium.org>
Commit-Queue: Samuel Tan <samueltan@chromium.org>
/system/connectivity/shill/wifi/wake_on_wifi.cc
ea7dcda5aae9c2579f16b142e5832e8aa7bd7ec4 05-Jan-2015 Samuel Tan <samueltan@chromium.org> shill: add 10 seconds to max dark resume delay

Add an additional 10 seconds to the max dark resume
delay so that shill can establish a connection with APs
that take longer to issue DHCP leases.

BUG=chromium:443458
TEST=Perform the following manual test twice, using the Netgear WNDR3400v3 as
the AP on the first run, and the D-Link DGL-5500 as the AP on the second run:
1) Boot into a samus test image.
2) Run 'ff_debug +wifi; ff_debug --level -3'
3) Run 'echo 0 > /var/lib/power_manager/disable_dark_resume; restart \
powerd'
4) Enable all wake on WiFi features with the following command:
dbus-send --system --print-reply --dest=org.chromium.flimflam \
/device/wlan0 org.chromium.flimflam.Device.SetProperty \
string:WakeOnWiFiFeaturesEnabled \
variant:string:"packet_and_ssid"
5) Set the wake-to-scan frequency to 60 seconds with the
following command:
dbus-send --system --print-reply --dest=org.chromium.flimflam \
/device/wlan0 org.chromium.flimflam.Device.SetProperty \
string:WakeToScanFrequency variant:uint32:60
6) Connect samus to an AP.
7) Disable the AP. Verify that the samus is fully disconnected by the WiFi
icon state (a cross over empty WiFi bars).
8) Run 'powerd_dbus_suspend' to suspend the system.
9) Wait for the samus to fully suspend. You can verify this by observing that
the light bar turns off. Then, immediately re-enable the AP.
10) Wait ~50 more seconds and verify that the samus wakes on dark resume
by observing that light bar turns on while the screen is off.
11) Wait again till the samus completes dark resume and suspends again.
12) Wake the samus by pressing any key.
13) Verify that the samus is connected immediately upon waking by observing that
the WiFi icon is in the connected state (i.e. solid, filled bars).

Change-Id: Iaff9a8e4a7a4451f9ae2238f72d82bb3ed466c96
Reviewed-on: https://chromium-review.googlesource.com/238890
Tested-by: Samuel Tan <samueltan@chromium.org>
Reviewed-by: Alexei Svitkine <asvitkine@google.com>
Reviewed-by: Paul Stewart <pstew@chromium.org>
Commit-Queue: Samuel Tan <samueltan@chromium.org>
/system/connectivity/shill/wifi/wake_on_wifi.cc
402bf2959e8b2c68627a7b66203ec84760bf2e03 23-Dec-2014 Samuel Tan <samueltan@chromium.org> shill: report done early in dark resume after scan

Report done early in dark resume after scanning for networks if
we do not find any networks that are available for auto-connect.

Also:
- rename the |have_service_configured_for_autoconnect| to
|has_service_configured_for_autoconnect| to match the
naming of the corresponding function in WiFiProvider.

BUG=chromium:444652
TEST=Compile shill and run unit tests using the following commands:

P2_TEST_FILTER="shill::*" FEATURES="test" USE="wake_on_wifi \
clang asan" emerge-samus shill

P2_TEST_FILTER="shill::*" FEATURES="test" USE="-wake_on_wifi \
clang asan" emerge-samus shill

Manual testing as follows:
1) Boot into a samus test image.
2) Run 'ff_debug +wifi; ff_debug --level -3'
3) Run 'echo 0 > /var/lib/power_manager/disable_dark_resume; restart \
powerd'
4) Enable all wake on WiFi features with the following command:
dbus-send --system --print-reply --dest=org.chromium.flimflam \
/device/wlan0 org.chromium.flimflam.Device.SetProperty \
string:WakeOnWiFiFeaturesEnabled \
variant:string:"packet_and_ssid"
5) Set the wake-to-scan frequency to 60 seconds with the
following command:
dbus-send --system --print-reply --dest=org.chromium.flimflam \
/device/wlan0 org.chromium.flimflam.Device.SetProperty \
string:WakeToScanFrequency variant:uint32:60
6) To work around a trackpad wakeup bug, disable trackpad wakeup using
the following command:
echo disabled > /sys/bus/i2c/devices/i2c-ATML0000\:01/power/wakeup
7) Connect samus to an AP.
8) Disable the AP. Verify that the samus is fully disconnected by the WiFi
icon state (a cross over empty WiFi bars).
9) Run 'powerd_dbus_suspend' to suspend the system.
10) Wait ~60 seconds and verify that the samus wakes on dark resume
by observing that light bar turns on while the screen is off.
11) Verify that the samus exits dark resume and suspends again after ~5 seconds
by observing that the lightbar turns off ~5 seconds after turning on.
12) Repeat steps 10-11 one more time.
13) Re-enable the AP immediately after the last dark resume cycle finishes
(i.e. right after light bar turns off).
14) Wait ~60 seconds for the next dark resume cycle to begin.
15) Verify that this dark resume cycle lasts for at least 2-3 more seconds than
the previous dark resume cycles observed in steps 10-12.
16) Wake the samus by pressing any key.
17) Verify that the samus is connected by verifying that the WiFi icon in the
bottom right corner is solid and filled (i.e. not crossed out or animating).

Note: these instructions assume that the AP can be fully re-enabled in
60 seconds, and that the DUT can scan and connect to this AP within 8.5 seconds.
The D-Link DGL-5500 is an example of such an AP that is appropriate for
this test.

Change-Id: I8a3c00e49dacf9e8580e24f9a0d84efb9e28b99c
Reviewed-on: https://chromium-review.googlesource.com/237494
Reviewed-by: Paul Stewart <pstew@chromium.org>
Tested-by: Samuel Tan <samueltan@chromium.org>
Commit-Queue: Samuel Tan <samueltan@chromium.org>
/system/connectivity/shill/wifi/wake_on_wifi.cc
3e8089db7c0674d3b668a98dcaf49a00df047068 06-Jan-2015 Samuel Tan <samueltan@chromium.org> shill: clear wake_on_wifi_triggers_ when disabling wake on WiFi

Clear the |wake_on_wifi_triggers_| set when disabling wake on
WiFi functionality on the NIC so that shill's local copy of the
triggers programmed into the NIC match up.

BUG=chromium:446622
TEST=Compile shill and run unit tests using:

P2_TEST_FILTER="shill::*" FEATURES="test" USE="wake_on_wifi \
clang asan" emerge-samus shill

P2_TEST_FILTER="shill::*" FEATURES="test" USE="-wake_on_wifi \
clang asan" emerge-samus shill

Manual testing as follows:
1) Boot into a samus test image.
2) Run 'ff_debug +wifi; ff_debug --level -3'
3) Run 'echo 0 > /var/lib/power_manager/disable_dark_resume; restart powerd'
4) Enable all wake on WiFi features with the following command:
dbus-send --system --print-reply --dest=org.chromium.flimflam \
/device/wlan0 org.chromium.flimflam.Device.SetProperty \
string:WakeOnWiFiFeaturesEnabled \
variant:string:"packet_and_ssid"
5) To work around a trackpad wakeup bug, disable trackpad wakeup using
the following command:
echo disabled > /sys/bus/i2c/devices/i2c-ATML0000\:01/power/wakeup
6) Run 'powerd_dbus_suspend' to suspend the system.
7) Wait ~10 seconds for the samus to fully suspend.
8) Wake the samus by pressing any key.
9) Open /var/log/net.log and search for the string "discrepancy". Verify
that zero instances of this string are found in this log file.
Change-Id: Id0c21644e42f4554ff064d364ace78d31179a20b
Reviewed-on: https://chromium-review.googlesource.com/238850
Tested-by: Samuel Tan <samueltan@chromium.org>
Reviewed-by: Paul Stewart <pstew@chromium.org>
Commit-Queue: Samuel Tan <samueltan@chromium.org>
/system/connectivity/shill/wifi/wake_on_wifi.cc
0e0ac0de9ac592495f780d7c372ba1212d4d374c 30-Dec-2014 Samuel Tan <samueltan@chromium.org> shill: metrics: add metrics to track receipt of unmatched scan results

Add metric that tracks how often shill receives scan results from
a scan not initiated directly by shill in the current dark resume
cycle.

BUG=chromium:444652
TEST=Compile shill.

Change-Id: Ife09a75cc131cffaba0863b7211a4bb36f90a0c9
Reviewed-on: https://chromium-review.googlesource.com/237960
Reviewed-by: Samuel Tan <samueltan@chromium.org>
Tested-by: Samuel Tan <samueltan@chromium.org>
Commit-Queue: Samuel Tan <samueltan@chromium.org>
/system/connectivity/shill/wifi/wake_on_wifi.cc
a44d6087a9b1940a424ecef3054eeb1995fada9a 18-Dec-2014 Samuel Tan <samueltan@chromium.org> shill: use kWakeOnWiFiFeaturesEnabledNotSupported flag

Use set |wake_on_wifi_features_enabled_| to
kWakeOnWiFiFeaturesEnabledNotSupported when wake on WiFi is
not supported (i.e. conditionally compiled away). This will allow
Chromium to find out when wake on WiFi is not supported via DBus.

CQ-DEPEND=CL:236433
BUG=chromium:443402
TEST=Compile shill and run unit tests using the following commands:

P2_TEST_FILTER="shill::*" FEATURES="test" USE="wake_on_wifi \
clang asan" emerge-samus shill

P2_TEST_FILTER="shill::*" FEATURES="test" USE="-wake_on_wifi \
clang asan" emerge-samus shill

Change-Id: Id663b17b02f0cea33ab280b5fd69151799f40f80
Reviewed-on: https://chromium-review.googlesource.com/236460
Tested-by: Samuel Tan <samueltan@chromium.org>
Reviewed-by: Paul Stewart <pstew@chromium.org>
Commit-Queue: Samuel Tan <samueltan@chromium.org>
/system/connectivity/shill/wifi/wake_on_wifi.cc
c420dd27964a85c8dec8f09d9049287ccba5f95a 15-Dec-2014 Samuel Tan <samueltan@chromium.org> shill: check for auto-connectable service before starting wake to scan timer

Check whether shill has any services configured for auto-connect before
starting a wake to scan timer when suspending in a disconnected state
(when wake on SSID is supported and enabled).

BUG=chromium:441502
TEST=Compile shill and run unit tests using the following commands:

P2_TEST_FILTER="shill::*" FEATURES="test" USE="wake_on_wifi \
clang asan" emerge-samus shill

P2_TEST_FILTER="shill::*" FEATURES="test" USE="-wake_on_wifi \
clang asan" emerge-samus shill

Manual testing as follows:
1) Boot into a samus test image.
2) Run 'ff_debug +wifi; ff_debug --level -3'
3) Run 'echo 0 > /var/lib/power_manager/disable_dark_resume; restart \
powerd'
4) Enable all wake on WiFi features with the following command:
dbus-send --system --print-reply --dest=org.chromium.flimflam \
/device/wlan0 org.chromium.flimflam.Device.SetProperty \
string:WakeOnWiFiFeaturesEnabled \
variant:string:"packet_and_ssid"
5) Set the wake-to-scan frequency to 15 seconds with the
following command:
dbus-send --system --print-reply --dest=org.chromium.flimflam \
/device/wlan0 org.chromium.flimflam.Device.SetProperty \
string:WakeToScanFrequency variant:uint32:15
6) Connect samus to an AP.
7) Disable the AP. Verify that the samus is fully disconnected by the WiFi
icon state (a cross over empty WiFi bars).
8) Run 'powerd_dbus_suspend' to suspend the system.
9) Wait ~15 seconds and verify that the samus wakes on dark resume
by observing that light bar turns on while the screen is off.
10) Wake the samus by pressing any key.
11) Open Settings UI, select the WiFi service the samus is currently
connected to, and uncheck the "Automatically connect to this
network" checkbox.
12) Repeat step 8.
13) Wait ~15 seconds and verify that the samus does not wake up in
dark resume.

Change-Id: I1c5fe8196cbb9f3d1c7a6f509e14460611854a32
Reviewed-on: https://chromium-review.googlesource.com/235816
Reviewed-by: Samuel Tan <samueltan@chromium.org>
Tested-by: Samuel Tan <samueltan@chromium.org>
Commit-Queue: Eric Caruso <ejcaruso@chromium.org>
Trybot-Ready: Eric Caruso <ejcaruso@chromium.org>
Commit-Queue: Samuel Tan <samueltan@chromium.org>
/system/connectivity/shill/wifi/wake_on_wifi.cc
3fc8dae6b16f31cdc6e2b0733a5df85442ea26ec 06-Dec-2014 Samuel Tan <samueltan@chromium.org> shill: force passive scanning in dark resume

No active scans should be launched when looking for preferred
networks while in dark resume for security reasons.
To achieve this, this CL bypasses WPA supplicant and manually
requests the NIC to perform a passive scan via its NL80211 interface.
This is necessary since the version of WPA supplicant used in ChromeOS
does not properly launch passive scans when it is requested to do
so via its DBus API.

Note: 1-2 SSID-specific probe requests will still be launched when
a preferred network is found while in dark resume. This is part of the
association process and is not a security issue since the association
process already passes information (e.g. MAC addresses) over the air.

BUG=chromium:439193
TEST=Compile shill and run unit tests using the following commands:

P2_TEST_FILTER="shill::*" FEATURES="test" USE="wake_on_wifi \
clang asan" emerge-samus shill

P2_TEST_FILTER="shill::*" FEATURES="test" USE="-wake_on_wifi \
clang asan" emerge-samus shill

Manual testing as follows:

1) Boot into a samus test image.
2) Run 'ff_debug +wifi; ff_debug --level -3'
3) Run 'echo 0 > /var/lib/power_manager/disable_dark_resume; restart \
powerd'
4) Enable all wake on WiFi features with the following command:
dbus-send --system --print-reply --dest=org.chromium.flimflam \
/device/wlan0 org.chromium.flimflam.Device.SetProperty \
string:WakeOnWiFiFeaturesEnabled \
variant:string:"packet_and_ssid"
5) Set the wake-to-scan frequency to 15 seconds with the
following command:
dbus-send --system --print-reply --dest=org.chromium.flimflam \
/device/wlan0 org.chromium.flimflam.Device.SetProperty \
string:WakeToScanFrequency variant:uint32:15
6) Connect samus to an AP.
7) Disable the AP. Verify that the samus is fully disconnected by the WiFi
icon state (a cross over empty WiFi bars).
8) Run 'powerd_dbus_suspend' to suspend the system.
9) At the same time as #8, start capturing packets on Wireshark on a separate
machine in monitor mode with the following filter applied:

wlan.sa==11:11:11:11:11:11 && wlan.fc.type_subtype==4

where 11:11:11:11:11:11 is the MAC address of the samus under test.
10) Wait for ~35 seconds for 2 dark resume cycles to elapse. The light bar on
the samus lights up when in dark resume, and turns off when it is suspends
again, so observing the light bar will also tell you when 2 dark resume
cycles have elapsed.
11) During #10, verify that no packet (Probe Requests) matching the Wireshark
filters were captured.
12) After the 2nd dark resume concludes, re-enable the AP before the 3rd
dark resume cycle begins (i.e. within ~10 seconds of the 2nd dark resume
concluding).
13) During the third dark resume cycle, (~50 seconds after the system was first
suspended), verify that 1 or 2 Probe Request packets matching the Wireshark
filters were captured.
14) After the third dark resume cycle, wait another ~30 seconds and verify that
the system does not enter dark resume again (by verifying that the light
bar does not light up again).
15) Wake the samus by pressing any key, and verify that the WiFI icon is in
the fully connected state.
16) Wait ~10 more seconds and ensure that the samus does not scan for networks
(by observing that the WiFi icon does not play the scan animation).

Change-Id: Id19ab8bb42b5406fb8f5b1aa25e6149ecb40322b
Reviewed-on: https://chromium-review.googlesource.com/233951
Reviewed-by: Samuel Tan <samueltan@chromium.org>
Tested-by: Samuel Tan <samueltan@chromium.org>
Commit-Queue: Samuel Tan <samueltan@chromium.org>
/system/connectivity/shill/wifi/wake_on_wifi.cc
1964b5de186ef06fa89a78b27c3a112686bc36f7 02-Dec-2014 Samuel Tan <samueltan@chromium.org> shill: add metric for WiFi connection status after wake

Add metric that tracks if the WiFi device is connected to
a service after waking from suspend, if the relevant wake
on WiFi features are enabled and supported.

Also added unit tests for previously WiFi metrics reporting
functions.

BUG=chromium:427731
TEST=Compile shill and run unit tests using:

P2_TEST_FILTER="shill::*" FEATURES="test" USE="wake_on_wifi \
clang asan" emerge-samus shill

P2_TEST_FILTER="shill::*" FEATURES="test" USE="-wake_on_wifi \
clang asan" emerge-samus shill

Change-Id: Ie1251e455bab3b5bb9f9e666c83a466a06079979
Reviewed-on: https://chromium-review.googlesource.com/232816
Tested-by: Samuel Tan <samueltan@chromium.org>
Reviewed-by: Paul Stewart <pstew@chromium.org>
Commit-Queue: Samuel Tan <samueltan@chromium.org>
/system/connectivity/shill/wifi/wake_on_wifi.cc
787a1cebf2452c14bf392ab99902e686ea4a6fb4 12-Nov-2014 Samuel Tan <samueltan@chromium.org> shill: add lucid sleep dark resume logic

Add logic in WiFi::OnDarkResume and WiFi::OnBeforeSuspend
that decides what actions to take before suspend and when
waking in dark resume to maintain and re-establish WiFi
connectivity during system suspend.

Also:
- Add |in_dark_resume_| to PowerManager to allow
autoconnect to work while in dark resume but not
during normal suspend.
- Rename WakeOnWiFi::kIPAddress to WakeOnWiFi::kPattern
to more accurately reflect how this enum represents a
wake trigger (wake on pattern), rather than a feature
implemented using this trigger (wake on packet).
- Refactor parts of wifi_unittest.cc and
wake_on_wifi_unittest.cc to be cleaner, test this new
logic and more thoroughly test existing code.

BUG=chrome-os-partner:32270
TEST=Run unit tests using the following commands:

P2_TEST_FILTER="shill::*" FEATURES="test" USE="wake_on_wifi
clang asan" emerge-samus shill

P2_TEST_FILTER="shill::*" FEATURES="test" USE="-wake_on_wifi
clang asan" emerge-samus shill

Manual testing as follows:

1) Boot into a samus test image.
2) Run 'ff_debug +wifi; ff_debug --level -3'
3) Run 'echo 1 > /sys/power/dark_resume_always'
4) Run 'echo 0 > /var/lib/power_manager/disable_dark_resume; restart \
powerd'
5) Enable all wake on WiFi features with the following command:
dbus-send --system --print-reply --dest=org.chromium.flimflam \
/device/wlan0 org.chromium.flimflam.Device.SetProperty \
string:WakeOnWiFiFeaturesEnabled \
variant:string:"packet_and_ssid"
6) Set the wake-to-scan frequency to 30 seconds with the
following command:
dbus-send --system --print-reply --dest=org.chromium.flimflam \
/device/wlan0 org.chromium.flimflam.Device.SetProperty \
string:WakeToScanFrequency variant:uint32:30
7) Connect samus to an AP.
8) Run 'powerd_dbus_suspend' to suspend the system.
9) Wait ~12 seconds, then disable/turn off the AP.
10) Wait ~12 seconds, then reenable/turn on the AP.
11) Wait ~45 seconds, then press any button to wake the samus.
Note: you might have to press the same key on the samus repeatedly
until the samus fully wakes (space works well).
12) Observe the WiFi icon on the bottom right of the screen immediately
upon wake and verify that it is already in the connected state
rather than in the scanning state (i.e. scan animation playing).

Change-Id: Ic08e78fd4823011a50aef686acc80d300bff2b21
Reviewed-on: https://chromium-review.googlesource.com/229188
Tested-by: Samuel Tan <samueltan@chromium.org>
Reviewed-by: Paul Stewart <pstew@chromium.org>
Commit-Queue: Samuel Tan <samueltan@chromium.org>
/system/connectivity/shill/wifi/wake_on_wifi.cc
f8c0b3bcc1b9e918400c1fe76a9f6991bc32b55b 02-Dec-2014 Samuel Tan <samueltan@chromium.org> shill: reduce wake on WiFi settings verification delay

Reduce the amount of time we wait after programming the NIC
to request for its settings for verification from 1 second to
300 milliseconds.

BUG=chromium:438034
TEST=Compile and run shill unit tests using:

P2_TEST_FILTER="shill::*" FEATURES="test" USE="wake_on_wifi \
clang asan" emerge-samus shill

P2_TEST_FILTER="shill::*" FEATURES="test" USE="-wake_on_wifi \
clang asan" emerge-samus shill

Change-Id: If8f24c4dd86a0abfa9864b55ce25d5f3f8101c68
Reviewed-on: https://chromium-review.googlesource.com/232531
Tested-by: Samuel Tan <samueltan@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Samuel Tan <samueltan@chromium.org>
/system/connectivity/shill/wifi/wake_on_wifi.cc
f144d5df124e56f3df3b6982b85bffd0442ac2d0 26-Nov-2014 Samuel Tan <samueltan@chromium.org> shill: add metrics for VerifyWakeOnWiFiSettings

Add metrics to report the results of VerifyWakeOnWiFiSettings.
This will provide data to understand whether or not the wake on
WiFi setting verification process is necessary.

Also:
- Add unit tests to ensure the metric is reported in WakeOnWiFi.
- Remove previously unused mock method in MockMetrics.
- Remove unnecessary virtual flag from
Metrics::NotifyWakeOnWiFiFeaturesEnabledState since this
function is not mocked.

BUG=chromium:436106
TEST=Compile shill and run unit tests.

Change-Id: I95a2d1296841545a7c31439ec4c748e359316ea2
Reviewed-on: https://chromium-review.googlesource.com/231973
Tested-by: Samuel Tan <samueltan@chromium.org>
Reviewed-by: Paul Stewart <pstew@chromium.org>
Commit-Queue: Samuel Tan <samueltan@chromium.org>
/system/connectivity/shill/wifi/wake_on_wifi.cc
4889ff847d57835820f189b622e945d70ec41494 21-Nov-2014 Samuel Tan <samueltan@chromium.org> shill: register wake-to-scan frequency property

Register a wake to scan frequency property that can be set
via DBus to determine how often the system is woken from
suspend to scan for networks.

CQ-DEPEND=CL:231396
BUG=chrome-os-partner:32270
TEST=compile shill.

Change-Id: I411896a4acc5b853aefe77fc96ff7bfe64093bd7
Reviewed-on: https://chromium-review.googlesource.com/231379
Tested-by: Samuel Tan <samueltan@chromium.org>
Reviewed-by: Paul Stewart <pstew@chromium.org>
Commit-Queue: Samuel Tan <samueltan@chromium.org>
/system/connectivity/shill/wifi/wake_on_wifi.cc
d6a8b519e3057f52313e502f502a4819a942e089 18-Nov-2014 Ben Chan <benchan@chromium.org> shill: wifi: Move wifi code to its own sub-directory.

This CL is part of a series of CLs, which aim to reorganzie shill's flat
source code structure into a more modular form by moving technology
specific code into their own sub-directories.

BUG=chromium:433419
TEST=`FEATURES=test emerge-$BOARD shill`
TEST=`USE='clang asan' FEATURES=test emerge-$BOARD shill`

Change-Id: Ic6bf64e7fe263fd0b2277877d78cf776f179e7d7
Reviewed-on: https://chromium-review.googlesource.com/230460
Reviewed-by: Paul Stewart <pstew@chromium.org>
Tested-by: Ben Chan <benchan@chromium.org>
Commit-Queue: Ben Chan <benchan@chromium.org>
/system/connectivity/shill/wifi/wake_on_wifi.cc