blob: d68cb367a0e0675bb5cd1407dac9c5138f798261 [file] [log] [blame]
Samuel Tand03b95d2014-08-14 11:16:57 -07001// Copyright 2014 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef SHILL_WAKE_ON_WIFI_H_
6#define SHILL_WAKE_ON_WIFI_H_
7
Samuel Tan3a9c0982014-08-20 13:01:17 -07008#include <linux/if_ether.h>
9#include <netinet/ip.h>
10#include <netinet/ip6.h>
11
12#include <utility>
13#include <vector>
14
Samuel Tand03b95d2014-08-14 11:16:57 -070015#include <base/basictypes.h>
16
Samuel Tan3a9c0982014-08-20 13:01:17 -070017#include "shill/refptr_types.h"
18
Samuel Tand03b95d2014-08-14 11:16:57 -070019namespace shill {
20
21class ByteString;
22class Error;
23class IPAddress;
Samuel Tan3a9c0982014-08-20 13:01:17 -070024class IPAddressStore;
25class GetWakeOnPacketConnMessage;
26class Nl80211Message;
Samuel Tand03b95d2014-08-14 11:16:57 -070027class SetWakeOnPacketConnMessage;
28
29namespace WakeOnWifi {
30
Samuel Tan3a9c0982014-08-20 13:01:17 -070031// Used for comparison of ByteString pairs in a set.
32bool ByteStringPairIsLessThan(const std::pair<ByteString, ByteString> &lhs,
33 const std::pair<ByteString, ByteString> &rhs);
Samuel Tand03b95d2014-08-14 11:16:57 -070034// Creates a mask which specifies which bytes in pattern of length |pattern_len|
35// to match against. Bits |offset| to |pattern_len| - 1 are set, which bits 0 to
36// bits 0 to |offset| - 1 are unset. This mask is saved in |mask|.
37void SetMask(ByteString *mask, uint32_t pattern_len, uint32_t offset);
Samuel Tan3a9c0982014-08-20 13:01:17 -070038// Creates a pattern and mask for a NL80211 message that programs the NIC to
Samuel Tand03b95d2014-08-14 11:16:57 -070039// wake on packets originating from IP address |ip_addr|. The pattern and mask
40// are saved in |pattern| and |mask| respectively.
41bool CreateIPAddressPatternAndMask(const IPAddress &ip_addr,
42 ByteString *pattern, ByteString *mask);
43void CreateIPV4PatternAndMask(const IPAddress &ip_addr, ByteString *pattern,
44 ByteString *mask);
45void CreateIPV6PatternAndMask(const IPAddress &ip_addr, ByteString *pattern,
46 ByteString *mask);
Samuel Tan3a9c0982014-08-20 13:01:17 -070047// Creates and sets an attribute in a NL80211 message |msg| which indicates the
Samuel Tand03b95d2014-08-14 11:16:57 -070048// index of the wiphy device to program.
Samuel Tan3a9c0982014-08-20 13:01:17 -070049bool ConfigureWiphyIndex(Nl80211Message *msg, int32_t index);
50// Creates and sets attributes in an SetWakeOnPacketConnMessage |msg| so that
51// the message will deprogram all wake-on-packet rules from the NIC with wiphy
52// index |wiphy_index|.
Samuel Tand03b95d2014-08-14 11:16:57 -070053// NOTE: Assumes that |msg| has not been altered since construction.
54bool ConfigureRemoveAllWakeOnPacketMsg(SetWakeOnPacketConnMessage *msg,
55 uint32_t wiphy_index, Error *error);
Samuel Tan3a9c0982014-08-20 13:01:17 -070056// Creates and sets attributes in a SetWakeOnPacketConnMessage |msg|
57// so that the message will program the NIC with wiphy index |wiphy_index| to
58// wake on packets originating from IP addresses in |addrs|.
Samuel Tand03b95d2014-08-14 11:16:57 -070059// NOTE: Assumes that |msg| has not been altered since construction.
60bool ConfigureAddWakeOnPacketMsg(SetWakeOnPacketConnMessage *msg,
Samuel Tan3a9c0982014-08-20 13:01:17 -070061 const IPAddressStore &addrs,
62 uint32_t wiphy_index, Error *error);
63// Helper function to ConfigureAddWakeOnPacketMsg that creates a single nested
64// attribute inside the attribute list referenced by |patterns| representing
65// a single wake-on-packet pattern matching rule with index |patnum|.
66// NOTE: |patterns| is assumed to reference the nested attribute list
67// NL80211_WOWLAN_TRIG_PKT_PATTERN.
68// NOTE: |patnum| should be unique across multiple calls to this function to
69// prevent the formation of a erroneous nl80211 message or the overwriting of
70// pattern matching rules.
71bool CreateSinglePattern(const IPAddress &ip_addr, AttributeListRefPtr patterns,
72 uint8_t patnum, Error *error);
73// Creates and sets attributes in an GetWakeOnPacketConnMessage msg| so that
74// the message will request for wake-on-packet settings information from the NIC
75// with wiphy index |wiphy_index|.
76// NOTE: Assumes that |msg| has not been altered since construction.
77bool ConfigureGetWakeOnPacketMsg(GetWakeOnPacketConnMessage *msg,
78 uint32_t wiphy_index, Error *error);
79// Given a NL80211_CMD_GET_WOWLAN response or NL80211_CMD_SET_WOWLAN request
80// |msg|, returns true if the source IP addresses in |msg| match those in
81// |addrs|. Returns false otherwise.
82bool WakeOnPacketSettingsMatch(const Nl80211Message &msg,
83 const IPAddressStore &addrs);
Samuel Tand03b95d2014-08-14 11:16:57 -070084
85} // namespace WakeOnWifi
86
87} // namespace shill
88
89#endif // SHILL_WAKE_ON_WIFI_H_