diff options
author | Ningyuan Wang | 2017-06-20 18:15:41 -0500 |
---|---|---|
committer | android-build-merger | 2017-06-20 18:15:41 -0500 |
commit | f4a2b51c0e26c93e1a2459caa801edc8281099c8 (patch) | |
tree | d25b99ac6794e737eeeb68ecb9498432c440c14f | |
parent | 11b94d59838497c40cb0610971229012df433149 (diff) | |
parent | ecb6bb205f5263c06570f14b148d6b171b1f74ad (diff) | |
download | system-connectivity-wificond-f4a2b51c0e26c93e1a2459caa801edc8281099c8.tar.gz system-connectivity-wificond-f4a2b51c0e26c93e1a2459caa801edc8281099c8.tar.xz system-connectivity-wificond-f4a2b51c0e26c93e1a2459caa801edc8281099c8.zip |
Revert "Use new netlink attribute for scan result timestamp"
am: ecb6bb205f
Change-Id: Id0ad9f2c0c2ab434e921893b8d2b383b389170eb
-rw-r--r-- | scanning/scan_utils.cpp | 33 | ||||
-rw-r--r-- | scanning/scan_utils.h | 7 | ||||
-rw-r--r-- | tests/scan_utils_unittest.cpp | 36 |
3 files changed, 10 insertions, 66 deletions
diff --git a/scanning/scan_utils.cpp b/scanning/scan_utils.cpp index 42c55b2..5199e2b 100644 --- a/scanning/scan_utils.cpp +++ b/scanning/scan_utils.cpp | |||
@@ -151,11 +151,17 @@ bool ScanUtils::ParseScanResult(unique_ptr<const NL80211Packet> packet, | |||
151 | // These scan results are considered as malformed. | 151 | // These scan results are considered as malformed. |
152 | return false; | 152 | return false; |
153 | } | 153 | } |
154 | uint64_t last_seen_since_boot; | 154 | uint64_t tsf; |
155 | if (!GetBssTimestamp(bss, &last_seen_since_boot)) { | 155 | if (!bss.GetAttributeValue(NL80211_BSS_TSF, &tsf)) { |
156 | // Logging is done inside |GetBssTimestamp|. | 156 | LOG(ERROR) << "Failed to get TSF from scan result packet"; |
157 | return false; | 157 | return false; |
158 | } | 158 | } |
159 | uint64_t beacon_tsf; | ||
160 | if (bss.GetAttributeValue(NL80211_BSS_BEACON_TSF, &beacon_tsf)) { | ||
161 | if (beacon_tsf > tsf) { | ||
162 | tsf = beacon_tsf; | ||
163 | } | ||
164 | } | ||
159 | int32_t signal; | 165 | int32_t signal; |
160 | if (!bss.GetAttributeValue(NL80211_BSS_SIGNAL_MBM, &signal)) { | 166 | if (!bss.GetAttributeValue(NL80211_BSS_SIGNAL_MBM, &signal)) { |
161 | LOG(ERROR) << "Failed to get Signal Strength from scan result packet"; | 167 | LOG(ERROR) << "Failed to get Signal Strength from scan result packet"; |
@@ -175,26 +181,7 @@ bool ScanUtils::ParseScanResult(unique_ptr<const NL80211Packet> packet, | |||
175 | } | 181 | } |
176 | 182 | ||
177 | *scan_result = | 183 | *scan_result = |
178 | NativeScanResult(ssid, bssid, ie, freq, signal, | 184 | NativeScanResult(ssid, bssid, ie, freq, signal, tsf, capability, associated); |
179 | last_seen_since_boot, capability, associated); | ||
180 | } | ||
181 | return true; | ||
182 | } | ||
183 | |||
184 | bool ScanUtils::GetBssTimestamp(const NL80211NestedAttr& bss, | ||
185 | uint64_t* last_seen_since_boot){ | ||
186 | if (!bss.GetAttributeValue(NL80211_BSS_LAST_SEEN_BOOTTIME, | ||
187 | last_seen_since_boot)) { | ||
188 | // Fall back to use TSF if we can't find NL80211_BSS_LAST_SEEN_BOOTTIME | ||
189 | // attribute. | ||
190 | if (!bss.GetAttributeValue(NL80211_BSS_TSF, last_seen_since_boot)) { | ||
191 | LOG(ERROR) << "Failed to get TSF from scan result packet"; | ||
192 | return false; | ||
193 | } | ||
194 | uint64_t beacon_tsf; | ||
195 | if (bss.GetAttributeValue(NL80211_BSS_BEACON_TSF, &beacon_tsf)) { | ||
196 | *last_seen_since_boot = std::max(*last_seen_since_boot, beacon_tsf); | ||
197 | } | ||
198 | } | 185 | } |
199 | return true; | 186 | return true; |
200 | } | 187 | } |
diff --git a/scanning/scan_utils.h b/scanning/scan_utils.h index dc3768e..84baeec 100644 --- a/scanning/scan_utils.h +++ b/scanning/scan_utils.h | |||
@@ -42,7 +42,6 @@ namespace android { | |||
42 | namespace wificond { | 42 | namespace wificond { |
43 | 43 | ||
44 | class NL80211Packet; | 44 | class NL80211Packet; |
45 | class NL80211NestedAttr; | ||
46 | 45 | ||
47 | // Provides scanning helper functions. | 46 | // Provides scanning helper functions. |
48 | class ScanUtils { | 47 | class ScanUtils { |
@@ -137,12 +136,6 @@ class ScanUtils { | |||
137 | // interface with index |interface_index|. | 136 | // interface with index |interface_index|. |
138 | virtual void UnsubscribeSchedScanResultNotification(uint32_t interface_index); | 137 | virtual void UnsubscribeSchedScanResultNotification(uint32_t interface_index); |
139 | 138 | ||
140 | // Visible for testing. | ||
141 | // Get a timestamp for the scan result |bss| represents. | ||
142 | // This timestamp records the time passed since boot when last time the | ||
143 | // AP was seen. | ||
144 | virtual bool GetBssTimestamp(const NL80211NestedAttr& bss, | ||
145 | uint64_t* last_seen_since_boot); | ||
146 | private: | 139 | private: |
147 | bool GetSSIDFromInfoElement(const std::vector<uint8_t>& ie, | 140 | bool GetSSIDFromInfoElement(const std::vector<uint8_t>& ie, |
148 | std::vector<uint8_t>* ssid); | 141 | std::vector<uint8_t>* ssid); |
diff --git a/tests/scan_utils_unittest.cpp b/tests/scan_utils_unittest.cpp index 33ca4f8..3dbfe21 100644 --- a/tests/scan_utils_unittest.cpp +++ b/tests/scan_utils_unittest.cpp | |||
@@ -176,41 +176,5 @@ TEST_F(ScanUtilsTest, CanHandleSchedScanRequestFailure) { | |||
176 | kFakeRssiThreshold, kFakeUseRandomMAC, {}, {}, {})); | 176 | kFakeRssiThreshold, kFakeUseRandomMAC, {}, {}, {})); |
177 | } | 177 | } |
178 | 178 | ||
179 | TEST_F(ScanUtilsTest, CanPrioritizeLastSeenSinceBootNetlinkAttribute) { | ||
180 | constexpr uint64_t kLastSeenTimestamp = 123456; | ||
181 | constexpr uint64_t kBssTsfTimestamp = 654321; | ||
182 | NL80211NestedAttr bss(NL80211_ATTR_BSS); | ||
183 | bss.AddAttribute( | ||
184 | NL80211Attr<uint64_t>(NL80211_BSS_LAST_SEEN_BOOTTIME, kLastSeenTimestamp)); | ||
185 | bss.AddAttribute( | ||
186 | NL80211Attr<uint64_t>(NL80211_BSS_TSF, kBssTsfTimestamp)); | ||
187 | uint64_t timestamp; | ||
188 | EXPECT_TRUE(scan_utils_.GetBssTimestamp(bss, ×tamp)); | ||
189 | EXPECT_EQ(kLastSeenTimestamp, timestamp); | ||
190 | } | ||
191 | |||
192 | TEST_F(ScanUtilsTest, CanHandleMissingLastSeenSinceBootNetlinkAttribute) { | ||
193 | constexpr uint64_t kBssTsfTimestamp = 654321; | ||
194 | NL80211NestedAttr bss(NL80211_ATTR_BSS); | ||
195 | bss.AddAttribute( | ||
196 | NL80211Attr<uint64_t>(NL80211_BSS_TSF, kBssTsfTimestamp)); | ||
197 | uint64_t timestamp; | ||
198 | EXPECT_TRUE(scan_utils_.GetBssTimestamp(bss, ×tamp)); | ||
199 | EXPECT_EQ(kBssTsfTimestamp, timestamp); | ||
200 | } | ||
201 | |||
202 | TEST_F(ScanUtilsTest, CanPickMostRecentTimestampBetweenBetweenProbeAndBeacon) { | ||
203 | constexpr uint64_t kBssBeaconTsfTimestamp = 654321; | ||
204 | constexpr uint64_t kBssTsfTimestamp = kBssBeaconTsfTimestamp + 2000; | ||
205 | NL80211NestedAttr bss(NL80211_ATTR_BSS); | ||
206 | bss.AddAttribute( | ||
207 | NL80211Attr<uint64_t>(NL80211_BSS_BEACON_TSF, kBssBeaconTsfTimestamp)); | ||
208 | bss.AddAttribute( | ||
209 | NL80211Attr<uint64_t>(NL80211_BSS_TSF, kBssTsfTimestamp)); | ||
210 | uint64_t timestamp; | ||
211 | EXPECT_TRUE(scan_utils_.GetBssTimestamp(bss, ×tamp)); | ||
212 | EXPECT_EQ(kBssTsfTimestamp, timestamp); | ||
213 | } | ||
214 | |||
215 | } // namespace wificond | 179 | } // namespace wificond |
216 | } // namespace android | 180 | } // namespace android |