1 /*
2 * Copyright (C) 2016, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <vector>
18
19 #include "wificond/tests/offload_hal_test_constants.h"
20 #include "wificond/tests/offload_test_utils.h"
21
22 using android::hardware::wifi::offload::V1_0::ScanResult;
23 using android::hardware::wifi::offload::V1_0::ScanStats;
24 using android::hardware::wifi::offload::V1_0::ScanRecord;
25 using android::hardware::wifi::offload::V1_0::OffloadStatus;
26 using android::hardware::wifi::offload::V1_0::OffloadStatusCode;
27
28 using ::com::android::server::wifi::wificond::NativeScanResult;
29 using ::com::android::server::wifi::wificond::NativeScanStats;
30
31 using namespace android::wificond::offload_hal_test_constants;
32
33 namespace android {
34 namespace wificond {
35
createOffloadScanResults()36 std::vector<ScanResult> OffloadTestUtils::createOffloadScanResults() {
37 std::vector<ScanResult> scanResults;
38 ScanResult scanResult;
39 std::vector<uint8_t> ssid(kSsid1, kSsid1 + kSsid1_size);
40 scanResult.tsf = kTsf;
41 scanResult.rssi = kRssi;
42 scanResult.frequency = kFrequency1;
43 scanResult.capability = kCapability;
44 memcpy(&scanResult.bssid[0], &kBssid[0], kBssidSize);
45 scanResult.networkInfo.ssid = ssid;
46 scanResult.networkInfo.flags = kNetworkFlags;
47 scanResults.push_back(scanResult);
48 return scanResults;
49 }
50
createScanStats(NativeScanStats * nativeScanStats)51 ScanStats OffloadTestUtils::createScanStats(NativeScanStats* nativeScanStats) {
52 std::vector<ScanRecord> scan_records;
53 std::vector<uint8_t> histogram_channels;
54 uint32_t scan_duration_ms = 0;
55 uint32_t num_channels_scanned = 0;
56 ScanStats scan_stats;
57 int numEntriesInScanRecord =
58 sizeof(kNumChannelsScanned) / sizeof(kNumChannelsScanned[0]);
59 for (int i = 0; i < numEntriesInScanRecord; i++) {
60 ScanRecord scan_record;
61 scan_record.durationMs = kScanDurationMs[i];
62 scan_duration_ms += kScanDurationMs[i];
63 scan_record.numChannelsScanned = kNumChannelsScanned[i];
64 num_channels_scanned += kNumChannelsScanned[i];
65 scan_record.numEntriesAggregated = 1;
66 scan_records.push_back(scan_record);
67 }
68 scan_stats.scanRecord = scan_records;
69 scan_stats.numScansRequestedByWifi = kDefaultNumScansRequestedByWifi;
70 scan_stats.numScansServicedByWifi = kDefaultNumScansServicedByWifi;
71 scan_stats.subscriptionDurationMs = kSubscriptionDurationMs;
72 uint32_t skip_tmp = 256 / num_channels_scanned;
73 for (size_t i = 0; i < 256; i++) {
74 if (i % skip_tmp == 0) {
75 scan_stats.histogramChannelsScanned[i] =
76 kDefaultNumTimesAChannelsIsScanned;
77 histogram_channels.push_back(kDefaultNumTimesAChannelsIsScanned);
78 } else {
79 scan_stats.histogramChannelsScanned[i] = kChannelNotScanned;
80 histogram_channels.push_back(kChannelNotScanned);
81 }
82 }
83 NativeScanStats native_scan_stats(kDefaultNumScansRequestedByWifi,
84 kDefaultNumScansServicedByWifi,
85 kSubscriptionDurationMs, scan_duration_ms,
86 num_channels_scanned, histogram_channels);
87 *nativeScanStats = native_scan_stats;
88 return scan_stats;
89 }
90
createOffloadStatus(OffloadStatusCode code)91 OffloadStatus OffloadTestUtils::createOffloadStatus(OffloadStatusCode code) {
92 return createOffloadStatus(code, "");
93 }
94
createOffloadStatus(OffloadStatusCode code,const std::string & desc)95 OffloadStatus OffloadTestUtils::createOffloadStatus(OffloadStatusCode code,
96 const std::string& desc) {
97 return {code, desc};
98 }
99
100 } // namespace wificond
101 } // namespace android
102