[AWARE] Ranging as a service discovery constraint

Ranging configuration modification: change from an
overall Aware configuration (remove from Enable/Config
structures) to a discovery session-specific configuration.

Bug: 33821639
Test: integrated (sl4a) tests
Change-Id: Ie5a8bb3701a5dd6186c15d2be16bca3ec7202f04
diff --git a/wifi/1.0/default/hidl_struct_util.cpp b/wifi/1.0/default/hidl_struct_util.cpp
index 6c40c4b..0bf0d32 100644
--- a/wifi/1.0/default/hidl_struct_util.cpp
+++ b/wifi/1.0/default/hidl_struct_util.cpp
@@ -795,9 +795,6 @@
   legacy_request->config_disc_mac_addr_randomization = 1;
   legacy_request->disc_mac_addr_rand_interval_sec =
         hidl_request.configParams.macAddressRandomizationIntervalSec;
-  legacy_request->config_responder_auto_response = 1;
-  legacy_request->ranging_auto_response_cfg = hidl_request.configParams.acceptRangingRequests ?
-       legacy_hal::NAN_RANGING_AUTO_RESPONSE_ENABLE : legacy_hal::NAN_RANGING_AUTO_RESPONSE_DISABLE;
   legacy_request->config_2dot4g_rssi_close = 1;
   if (hidl_request.configParams.bandSpecificConfig.size() != 2) {
     LOG(ERROR) << "convertHidlNanEnableRequestToLegacy: bandSpecificConfig.size() != 2";
@@ -963,6 +960,9 @@
         hidl_request.baseConfigs.configRangingIndications;
   legacy_request->ranging_cfg.distance_ingress_cm = hidl_request.baseConfigs.distanceIngressCm;
   legacy_request->ranging_cfg.distance_egress_cm = hidl_request.baseConfigs.distanceEgressCm;
+  legacy_request->ranging_auto_response = hidl_request.baseConfigs.rangingRequired ?
+        legacy_hal::NAN_RANGING_AUTO_RESPONSE_ENABLE : legacy_hal::NAN_RANGING_AUTO_RESPONSE_DISABLE;
+  legacy_request->range_report = legacy_hal::NAN_DISABLE_RANGE_REPORT;
   legacy_request->publish_type = (legacy_hal::NanPublishType) hidl_request.publishType;
   legacy_request->tx_type = (legacy_hal::NanTxType) hidl_request.txType;
 
@@ -1042,6 +1042,9 @@
         hidl_request.baseConfigs.configRangingIndications;
   legacy_request->ranging_cfg.distance_ingress_cm = hidl_request.baseConfigs.distanceIngressCm;
   legacy_request->ranging_cfg.distance_egress_cm = hidl_request.baseConfigs.distanceEgressCm;
+  legacy_request->ranging_auto_response = hidl_request.baseConfigs.rangingRequired ?
+        legacy_hal::NAN_RANGING_AUTO_RESPONSE_ENABLE : legacy_hal::NAN_RANGING_AUTO_RESPONSE_DISABLE;
+  legacy_request->range_report = legacy_hal::NAN_DISABLE_RANGE_REPORT;
   legacy_request->subscribe_type = (legacy_hal::NanSubscribeType) hidl_request.subscribeType;
   legacy_request->serviceResponseFilter = (legacy_hal::NanSRFType) hidl_request.srfType;
   legacy_request->serviceResponseInclude = hidl_request.srfRespondIfInAddressSet ?
@@ -1123,9 +1126,6 @@
   legacy_request->config_disc_mac_addr_randomization = 1;
   legacy_request->disc_mac_addr_rand_interval_sec =
         hidl_request.macAddressRandomizationIntervalSec;
-  legacy_request->config_responder_auto_response = 1;
-  legacy_request->ranging_auto_response_cfg = hidl_request.acceptRangingRequests ?
-       legacy_hal::NAN_RANGING_AUTO_RESPONSE_ENABLE : legacy_hal::NAN_RANGING_AUTO_RESPONSE_DISABLE;
   /* TODO : missing
   legacy_request->config_2dot4g_rssi_close = 1;
   legacy_request->rssi_close_2dot4g_val =
@@ -1314,8 +1314,8 @@
         legacy_ind.peer_sdea_params.security_cfg == legacy_hal::NAN_DP_CONFIG_SECURITY;
   hidl_ind->peerRequiresRanging =
         legacy_ind.peer_sdea_params.ranging_state == legacy_hal::NAN_RANGING_ENABLE;
-  hidl_ind->rangingMeasurementInCm = legacy_ind.range_result.range_measurement_cm;
-  hidl_ind->rangingIndicationType = legacy_ind.range_result.ranging_event_type;
+  hidl_ind->rangingMeasurementInCm = legacy_ind.range_info.range_measurement_cm;
+  hidl_ind->rangingIndicationType = legacy_ind.range_info.ranging_event_type;
 
   return true;
 }
diff --git a/wifi/1.0/default/wifi_legacy_hal.cpp b/wifi/1.0/default/wifi_legacy_hal.cpp
index cd89acc..7d58254 100644
--- a/wifi/1.0/default/wifi_legacy_hal.cpp
+++ b/wifi/1.0/default/wifi_legacy_hal.cpp
@@ -289,6 +289,24 @@
     on_nan_event_transmit_follow_up_user_callback(*event);
   }
 }
+
+std::function<void(const NanRangeRequestInd&)>
+    on_nan_event_range_request_user_callback;
+void onAysncNanEventRangeRequest(NanRangeRequestInd* event) {
+  const auto lock = hidl_sync_util::acquireGlobalLock();
+  if (on_nan_event_range_request_user_callback && event) {
+    on_nan_event_range_request_user_callback(*event);
+  }
+}
+
+std::function<void(const NanRangeReportInd&)>
+    on_nan_event_range_report_user_callback;
+void onAysncNanEventRangeReport(NanRangeReportInd* event) {
+  const auto lock = hidl_sync_util::acquireGlobalLock();
+  if (on_nan_event_range_report_user_callback && event) {
+    on_nan_event_range_report_user_callback(*event);
+  }
+}
 // End of the free-standing "C" style callbacks.
 
 WifiLegacyHal::WifiLegacyHal()
@@ -1023,6 +1041,10 @@
       user_callbacks.on_event_data_path_end;
   on_nan_event_transmit_follow_up_user_callback =
       user_callbacks.on_event_transmit_follow_up;
+  on_nan_event_range_request_user_callback =
+      user_callbacks.on_event_range_request;
+  on_nan_event_range_report_user_callback =
+      user_callbacks.on_event_range_report;
 
   return global_func_table_.wifi_nan_register_handler(
       wlan_interface_handle_,
@@ -1039,7 +1061,9 @@
        onAysncNanEventDataPathRequest,
        onAysncNanEventDataPathConfirm,
        onAysncNanEventDataPathEnd,
-       onAysncNanEventTransmitFollowUp});
+       onAysncNanEventTransmitFollowUp,
+       onAysncNanEventRangeRequest,
+       onAysncNanEventRangeReport});
 }
 
 wifi_error WifiLegacyHal::nanEnableRequest(transaction_id id,
@@ -1261,6 +1285,8 @@
   on_nan_event_data_path_confirm_user_callback = nullptr;
   on_nan_event_data_path_end_user_callback = nullptr;
   on_nan_event_transmit_follow_up_user_callback = nullptr;
+  on_nan_event_range_request_user_callback = nullptr;
+  on_nan_event_range_report_user_callback = nullptr;
 }
 
 }  // namespace legacy_hal
diff --git a/wifi/1.0/default/wifi_legacy_hal.h b/wifi/1.0/default/wifi_legacy_hal.h
index e65b79b..ed020b0 100644
--- a/wifi/1.0/default/wifi_legacy_hal.h
+++ b/wifi/1.0/default/wifi_legacy_hal.h
@@ -89,6 +89,10 @@
   std::function<void(const NanDataPathEndInd&)> on_event_data_path_end;
   std::function<void(const NanTransmitFollowupInd&)>
       on_event_transmit_follow_up;
+  std::function<void(const NanRangeRequestInd&)>
+      on_event_range_request;
+  std::function<void(const NanRangeReportInd&)>
+      on_event_range_report;
 };
 
 // Full scan results contain IE info and are hence passed by reference, to
diff --git a/wifi/1.0/default/wifi_nan_iface.cpp b/wifi/1.0/default/wifi_nan_iface.cpp
index 4165196..68be2a7 100644
--- a/wifi/1.0/default/wifi_nan_iface.cpp
+++ b/wifi/1.0/default/wifi_nan_iface.cpp
@@ -400,6 +400,16 @@
       LOG(ERROR) << "on_event_beacon_sdf_payload - should not be called";
   };
 
+  callback_handlers.on_event_range_request = [weak_ptr_this](
+        const legacy_hal::NanRangeRequestInd& /* msg */) {
+      LOG(ERROR) << "on_event_range_request - should not be called";
+  };
+
+  callback_handlers.on_event_range_report = [weak_ptr_this](
+        const legacy_hal::NanRangeReportInd& /* msg */) {
+      LOG(ERROR) << "on_event_range_report - should not be called";
+  };
+
   legacy_hal::wifi_error legacy_status =
       legacy_hal_.lock()->nanRegisterCallbackHandlers(callback_handlers);
   if (legacy_status != legacy_hal::WIFI_SUCCESS) {
diff --git a/wifi/1.0/types.hal b/wifi/1.0/types.hal
index 1c6d0e0..30e8943 100644
--- a/wifi/1.0/types.hal
+++ b/wifi/1.0/types.hal
@@ -844,11 +844,6 @@
    */
   uint32_t macAddressRandomizationIntervalSec;
   /**
-   * Accept (if true) or not (if false) ranging requests from peers - whether in the context of
-   * discovery or otherwise.
-   */
-  bool acceptRangingRequests;
-  /**
    * Additional configuration provided per band: indexed by |NanBandIndex|.
    */
   NanBandSpecificConfig[2] bandSpecificConfig;
@@ -1014,7 +1009,22 @@
   bool securityEnabledInNdp;
   /**
    * Specifies whether or not there is a ranging requirement in this discovery session.
-   * Note that ranging is only performed if all other match criteria with the peer are met.
+   * Ranging is only performed if all other match criteria with the peer are met.
+   * Note: specifying that ranging is required also implies that this device must automatically
+   * accept ranging requests from peers.
+   *   Solicited Publisher + Passive Subscriber:
+   *     Publisher/Subscriber:
+   *     true/true: ranging performed.
+   *     true/false: subscriber doesn't require ranging (match if all other criteria met). I.e.
+   *                 publisher requiring range doesn't gate subscriber matching.
+   *     false/true: subscriber tries ranging but publisher refuses (no match).
+   *     false/false: ranging isn't attempted and doesn't impact match.
+   *   Unsolicited Publisher + Active Subscriber:
+   *     Publisher/Subscriber:
+   *     true/true: ranging performed.
+   *     true/false: publisher attempts ranging but subscriber doesn't allow - no match.
+   *     false/true: publisher doesn't attempt ranging, should not impact match.
+   *     false/false: ranging isn't attempted and doesn't impact match.
    * NAN Spec: Service Discovery Extension Attribute (SDEA) / Control / Ranging Require.
    */
   bool rangingRequired;