1 /*
2  * Copyright (C) 2017 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 #ifndef CHRE_WIFI_OFFLOAD_TEST_UTILITY_H_
18 #define CHRE_WIFI_OFFLOAD_TEST_UTILITY_H_
19 
20 #include "chre/apps/wifi_offload/wifi_offload.h"
21 
22 #include "chre/apps/wifi_offload/channel_histogram.h"
23 #include "chre/apps/wifi_offload/preferred_network.h"
24 #include "chre/apps/wifi_offload/rpc_log_record.h"
25 #include "chre/apps/wifi_offload/scan_config.h"
26 #include "chre/apps/wifi_offload/scan_filter.h"
27 #include "chre/apps/wifi_offload/scan_params.h"
28 #include "chre/apps/wifi_offload/scan_record.h"
29 #include "chre/apps/wifi_offload/scan_result.h"
30 #include "chre/apps/wifi_offload/scan_stats.h"
31 
32 #include "../include/random_generator.h"
33 
34 namespace wifi_offload_test {
35 
36 constexpr uint8_t kNumFrequencies_Test = 74;
37 /* Supported frequencies in 2.4GHz (802.11b/g/n) and 5GHz (802.11a/h/j/n/ac) */
38 constexpr uint16_t kAllFrequencies_Test[kNumFrequencies_Test] = {
39     2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462,
40     2467, 2472, 2484, 5035, 5040, 5045, 5055, 5060, 5080, 5170, 5180,
41     5190, 5200, 5210, 5220, 5230, 5240, 5250, 5260, 5270, 5280, 5290,
42     5300, 5310, 5320, 5500, 5510, 5520, 5530, 5540, 5550, 5560, 5570,
43     5580, 5590, 5600, 5610, 5620, 5630, 5640, 5660, 5670, 5680, 5690,
44     5700, 5710, 5720, 5745, 5755, 5765, 5775, 5785, 5795, 5805, 5825,
45     4915, 4920, 4925, 4935, 4940, 4945, 4960, 4980,
46 };
47 
48 /* Supported channel numbers that matches frequencies in
49  * kAllFrequencies_Test. 2.4GHz (802.11b/g/n) and 5GHz (802.11a/h/j/n/ac) */
50 constexpr uint8_t kAllChannels_Test[kNumFrequencies_Test] = {
51     1,   2,   3,   4,   5,   6,   7,   8,   9,   10,  11,  12,  13,  14,  7,
52     8,   9,   11,  12,  16,  34,  36,  38,  40,  42,  44,  46,  48,  50,  52,
53     54,  56,  58,  60,  62,  64,  100, 102, 104, 106, 108, 110, 112, 114, 116,
54     118, 120, 122, 124, 126, 128, 132, 134, 136, 138, 140, 142, 144, 149, 151,
55     153, 155, 157, 159, 161, 165, 183, 184, 185, 187, 188, 189, 192, 196,
56 };
57 
58 void init(uint8_t &val, RandomGenerator &rand_gen);
59 void init(uint16_t &val, RandomGenerator &rand_gen);
60 void init(uint32_t &val, RandomGenerator &rand_gen);
61 void init(uint64_t &val, RandomGenerator &rand_gen);
62 void init(uint8_t *arr, size_t len, RandomGenerator &rand_gen);
63 void init(wifi_offload::Ssid &ssid, RandomGenerator &rand_gen);
64 void init(wifi_offload::PreferredNetwork &net_info, RandomGenerator &rand_gen);
65 void init(wifi_offload::ScanRecord &record, RandomGenerator &rand_gen);
66 void init(wifi_offload::RpcLogRecord &record, RandomGenerator &rand_gen);
67 void init(wifi_offload::ChannelHistogram &histo, RandomGenerator &rand_gen);
68 void init(wifi_offload::ScanStats &stats, RandomGenerator &rand_gen);
69 void init(wifi_offload::ScanParams &params, RandomGenerator &rand_gen);
70 void init(wifi_offload::ScanFilter &filter, RandomGenerator &rand_gen);
71 void init(wifi_offload::ScanConfig &config, RandomGenerator &rand_gen);
72 void init(wifi_offload::ScanResult &result, RandomGenerator &rand_gen);
73 void init(chreWifiScanResult &result, RandomGenerator &rand_gen);
74 
75 template <typename T>
init(wifi_offload::Vector<T> & vec,RandomGenerator & rand_gen,size_t vec_len)76 void init(wifi_offload::Vector<T> &vec, RandomGenerator &rand_gen,
77           size_t vec_len) {
78   vec.clear();
79   for (size_t i = 0; i < vec_len; i++) {
80     T new_elem;
81     init(new_elem, rand_gen);
82     vec.push_back(std::move(new_elem));
83   }
84 }
85 
86 template <typename T>
init(wifi_offload::Vector<T> & vec,RandomGenerator & rand_gen)87 void init(wifi_offload::Vector<T> &vec, RandomGenerator &rand_gen) {
88   size_t vec_len = (rand_gen.get<uint8_t>() % 10) + 1;
89   init(vec, rand_gen, vec_len);
90 }
91 
92 }  // namespace wifi_offload_test
93 
94 #endif  // CHRE_WIFI_OFFLOAD_TEST_UTILITY_H_
95