wifi: Add gscan API wrappers in WifiLegacyHal

The legacy gscan API's were designed to be used in the following
sequence:
a) Start the scan using |wifi_start_gscan|.
b) Scan Events are indicated to the caller via the provided
|on_scan_event| callback.
c) When one of the result events are received, the caller is expected
to retrieve the cached results via |wifi_get_cached_gscan_results|.
There are some extra knobs here to determine if the results need to be
flushed after fetch or not.
d) Any scan failures are also notified via the provided
|on_scan_event| callback.
e) Full scan results are delivered one by one via the provided
|on_full_scan_result| callback.

In our use case step (b) above is always followed by step (c), so these
2 steps have been merged together in the HIDL interface:
a) Start the scan using |IWifiStaIface.startBackgroundScan|.
b) Scan results are now directly delivered via
|IWifiStaIfaceEventCallback.onBackgroundScanResults| callback.
c) Any scan failures will be delivered via
|IWifiStaIfaceEventCallback.onBackgroundScanFailure| callback.
d) Full scan results are delivered one by one via
|IWifiStaIfaceEventCallback.onBackgroundFullScanResult| callback.

Bug: 31991459
Test: Compiles
Change-Id: I0870eae095a667eec1d8de75fe1cc04a1b5a0bd3
diff --git a/wifi/1.0/default/wifi_legacy_hal.h b/wifi/1.0/default/wifi_legacy_hal.h
index 8bd146a..4026834 100644
--- a/wifi/1.0/default/wifi_legacy_hal.h
+++ b/wifi/1.0/default/wifi_legacy_hal.h
@@ -39,6 +39,16 @@
   uint32_t max_len;
 };
 
+// Full scan results contain IE info and are hence passed by reference, to
+// preserve the variable length array member |ie_data|. Callee must not retain
+// the pointer.
+using on_gscan_full_result_callback =
+    std::function<void(wifi_request_id, const wifi_scan_result*, uint32_t)>;
+// These scan results don't contain any IE info, so no need to pass by
+// reference.
+using on_gscan_results_callback = std::function<void(
+    wifi_request_id, const std::vector<wifi_cached_scan_results>&)>;
+
 /**
  * Class that encapsulates all legacy HAL interactions.
  * This class manages the lifetime of the event loop thread used by legacy HAL.
@@ -65,12 +75,37 @@
   // APF functions.
   std::pair<wifi_error, PacketFilterCapabilities> getPacketFilterCapabilities();
   wifi_error setPacketFilter(const std::vector<uint8_t>& program);
+  // Gscan functions.
+  std::pair<wifi_error, wifi_gscan_capabilities> getGscanCapabilities();
+  // These API's provides a simplified interface over the legacy Gscan API's:
+  // a) All scan events from the legacy HAL API other than the
+  //    |WIFI_SCAN_FAILED| are treated as notification of results.
+  //    This method then retrieves the cached scan results from the legacy
+  //    HAL API and triggers the externally provided |on_results_user_callback|
+  //    on success.
+  // b) |WIFI_SCAN_FAILED| scan event or failure to retrieve cached scan results
+  //    triggers the externally provided |on_failure_user_callback|.
+  // c) Full scan result event triggers the externally provided
+  //    |on_full_result_user_callback|.
+  wifi_error startGscan(
+      wifi_request_id id,
+      const wifi_scan_cmd_params& params,
+      const std::function<void(wifi_request_id)>& on_failure_callback,
+      const on_gscan_results_callback& on_results_callback,
+      const on_gscan_full_result_callback& on_full_result_callback);
+  wifi_error stopGscan(wifi_request_id id);
+  std::pair<wifi_error, std::vector<uint32_t>> getValidFrequenciesForGscan(
+      wifi_band band);
 
  private:
   // Retrieve the interface handle to be used for the "wlan" interface.
   wifi_error retrieveWlanInterfaceHandle();
   // Run the legacy HAL event loop thread.
   void runEventLoop();
+  // Retrieve the cached gscan results to pass the results back to the external
+  // callbacks.
+  std::pair<wifi_error, std::vector<wifi_cached_scan_results>>
+  getGscanCachedResults();
   void invalidate();
 
   // Event loop thread used by legacy HAL.