1 /*
2  * Copyright (C) 2020 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 WIFI_SCAN_RESULT_H_
18 #define WIFI_SCAN_RESULT_H_
19 
20 #include <cinttypes>
21 
22 #include <chre.h>
23 #include <pb_decode.h>
24 
25 #include "chre_cross_validation_wifi.nanopb.h"
26 
27 class WifiScanResult {
28  public:
WifiScanResult()29   WifiScanResult() {
30   }  // Need for default ctor of WifiScanResult arrays in manager
31 
32   /**
33    * The ctor for the scan result for the AP.
34    *
35    * @param apWifiScanResultStream The wifi istream build from the nanoapp
36    * message buffer from AP.
37    */
38   WifiScanResult(pb_istream_t *apWifiScanResultStream);
39 
40   /**
41    * The ctor for the scan result for CHRE.
42    *
43    * @param apScanResult The wifi scan result struct received from CHRE apis.
44    */
45   WifiScanResult(const chreWifiScanResult &chreScanResult);
46 
47   static bool areEqual(const WifiScanResult &result1,
48                        const WifiScanResult &result2);
49 
50   static bool bssidsAreEqual(const WifiScanResult &result1,
51                              const WifiScanResult &result2);
52 
getResultIndex()53   uint8_t getResultIndex() const {
54     return mResultIndex;
55   }
getTotalNumResults()56   uint8_t getTotalNumResults() const {
57     return mTotalNumResults;
58   }
59 
60   // TODO(b/154271547): Remove this method and check that all scan results are
61   // valid instead
isLastMessage()62   bool isLastMessage() const {
63     return mResultIndex >= mTotalNumResults - 1;
64   }
65 
getSeen()66   bool getSeen() const {
67     return mSeen;
68   }
69 
didSee()70   void didSee() {
71     mSeen = true;
72   }
73 
74  private:
75   char mSsid[CHRE_WIFI_SSID_MAX_LEN];
76   uint8_t mBssid[CHRE_WIFI_BSSID_LEN];
77 
78   uint8_t mTotalNumResults = 0;
79   uint8_t mResultIndex = 0;
80 
81   //! If true then, a scan result with this bssid has been seen before in the
82   //! other set of scan results.
83   bool mSeen = false;
84 
85   static bool decodeString(pb_istream_t *stream, const pb_field_t * /*field*/,
86                            void **arg);
87 };
88 
89 #endif  // WIFI_SCAN_RESULT_H_
90