Explorar el Código

qcacld-3.0: Do not start motion detection if baselining is not done

Do not start motion detection if baselining is not done, or motion
detection config values are not available

CRs-Fixed: 2547648

Change-Id: I23a02dbd21e2b673e625938a35003f3730135327
Visweswara Tanuku hace 5 años
padre
commit
41d21c04e4

+ 14 - 0
core/hdd/inc/wlan_hdd_main.h

@@ -1306,6 +1306,8 @@ struct hdd_adapter {
 
 #ifdef WLAN_FEATURE_MOTION_DETECTION
 	bool motion_detection_mode;
+	bool motion_det_cfg;
+	uint32_t motion_det_baseline_value;
 #endif /* WLAN_FEATURE_MOTION_DETECTION */
 };
 
@@ -3757,6 +3759,18 @@ void wlan_hdd_send_tcp_param_update_event(struct hdd_context *hdd_ctx,
  * QDF_STATUS_E_FAILURE on failure
  */
 QDF_STATUS hdd_md_host_evt_cb(void *ctx, struct sir_md_evt *event);
+
+/**
+ * hdd_md_bl_evt_cb - Callback for Motion Detection Baseline Event
+ * @ctx: HDD context
+ * @sir_md_bl_evt: motion detect baseline event
+ *
+ * Callback for Motion Detection Baseline Event
+ *
+ * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and
+ * QDF_STATUS_E_FAILURE on failure
+ */
+QDF_STATUS hdd_md_bl_evt_cb(void *ctx, struct sir_md_bl_evt *event);
 #endif /* WLAN_FEATURE_MOTION_DETECTION */
 
 /**

+ 38 - 3
core/hdd/src/wlan_hdd_main.c

@@ -12818,15 +12818,13 @@ QDF_STATUS hdd_md_host_evt_cb(void *ctx, struct sir_md_evt *event)
 {
 	struct hdd_adapter *adapter = NULL;
 	struct hdd_context *hdd_ctx;
-	QDF_STATUS status;
 	struct sme_motion_det_en motion_det;
 
 	if (!ctx || !event)
 		return QDF_STATUS_E_INVAL;
 
 	hdd_ctx = (struct hdd_context *)ctx;
-	status = wlan_hdd_validate_context(hdd_ctx);
-	if (0 != status)
+	if (wlan_hdd_validate_context(hdd_ctx))
 		return QDF_STATUS_E_INVAL;
 
 	adapter = hdd_get_adapter_by_vdev(hdd_ctx, event->vdev_id);
@@ -12847,6 +12845,42 @@ QDF_STATUS hdd_md_host_evt_cb(void *ctx, struct sir_md_evt *event)
 
 	return QDF_STATUS_SUCCESS;
 }
+
+/**
+ * hdd_md_bl_evt_cb - Callback for Motion Detection Baseline Event
+ * @ctx: HDD context
+ * @event: motion detect baseline event
+ *
+ * Callback for Motion Detection Baseline completion
+ *
+ * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and
+ * QDF_STATUS_E_FAILURE on failure
+ */
+QDF_STATUS hdd_md_bl_evt_cb(void *ctx, struct sir_md_bl_evt *event)
+{
+	struct hdd_adapter *adapter = NULL;
+	struct hdd_context *hdd_ctx;
+
+	if (!ctx || !event)
+		return QDF_STATUS_E_INVAL;
+
+	hdd_ctx = (struct hdd_context *)ctx;
+	if (wlan_hdd_validate_context(hdd_ctx))
+		return QDF_STATUS_E_INVAL;
+
+	adapter = hdd_get_adapter_by_vdev(hdd_ctx, event->vdev_id);
+	if (!adapter || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
+		hdd_err("Invalid adapter or adapter has invalid magic");
+		return QDF_STATUS_E_INVAL;
+	}
+
+	hdd_debug("Motion Detection Baseline CB vdev id=%u, baseline val = %d",
+		  event->vdev_id, event->bl_baseline_value);
+
+	adapter->motion_det_baseline_value = event->bl_baseline_value;
+
+	return QDF_STATUS_SUCCESS;
+}
 #endif /* WLAN_FEATURE_MOTION_DETECTION */
 
 /**
@@ -12931,6 +12965,7 @@ int hdd_register_cb(struct hdd_context *hdd_ctx)
 
 #ifdef WLAN_FEATURE_MOTION_DETECTION
 	sme_set_md_host_evt_cb(mac_handle, hdd_md_host_evt_cb, (void *)hdd_ctx);
+	sme_set_md_bl_evt_cb(mac_handle, hdd_md_bl_evt_cb, (void *)hdd_ctx);
 #endif /* WLAN_FEATURE_MOTION_DETECTION */
 
 	hdd_exit();

+ 12 - 0
core/hdd/src/wlan_hdd_wext.c

@@ -5477,6 +5477,17 @@ static int hdd_we_motion_det_start_stop(struct hdd_adapter *adapter, int value)
 		hdd_err("Invalid value %d in mt_start", value);
 		return -EINVAL;
 	}
+
+	if (!adapter->motion_det_cfg) {
+		hdd_err("Motion Detection config values not available");
+		return -EINVAL;
+	}
+
+	if (!adapter->motion_det_baseline_value) {
+		hdd_err("Motion Detection Baselining not started/completed");
+		return -EAGAIN;
+	}
+
 	motion_det.vdev_id = adapter->vdev_id;
 	motion_det.enable = value;
 
@@ -8071,6 +8082,7 @@ static int __iw_set_var_ints_getnone(struct net_device *dev,
 		motion_det_cfg.md_fine_thr_low = apps_args[13];
 		adapter->motion_detection_mode = apps_args[14];
 		sme_motion_det_config(hdd_ctx->mac_handle, &motion_det_cfg);
+		adapter->motion_det_cfg =  true;
 	}
 	break;
 	case WE_MOTION_DET_BASE_LINE_CONFIG_PARAM:

+ 15 - 1
core/mac/inc/sir_api.h

@@ -5689,16 +5689,30 @@ struct set_pcl_req {
 	enum band_info band;
 };
 
+#ifdef WLAN_FEATURE_MOTION_DETECTION
 /**
  * struct sir_md_evt - motion detection event status
  * @vdev_id: vdev id
  * @status: md event status
  */
-#ifdef WLAN_FEATURE_MOTION_DETECTION
 struct sir_md_evt {
 	uint8_t vdev_id;
 	uint32_t status;
 };
+
+/**
+ * struct sir_md_bl_evt - motion detection baseline event values
+ * @vdev_id: vdev id
+ * @bl_baseline_value: baseline correlation value calculated during baselining
+ * @bl_max_corr_reserved: max corr value obtained during baselining phase in %
+ * @bl_min_corr_reserved: min corr value obtained during baselining phase in %
+ */
+struct sir_md_bl_evt {
+	uint8_t vdev_id;
+	uint32_t bl_baseline_value;
+	uint32_t bl_max_corr_reserved;
+	uint32_t bl_min_corr_reserved;
+};
 #endif /* WLAN_FEATURE_MOTION_DETECTION */
 
 #ifdef WLAN_MWS_INFO_DEBUGFS

+ 16 - 1
core/sme/inc/sme_api.h

@@ -3712,14 +3712,29 @@ QDF_STATUS sme_motion_det_base_line_enable(
  *
  * Return: QDF_STATUS_SUCCESS or non-zero on failure
  */
-
 QDF_STATUS sme_set_md_host_evt_cb
 (
 	mac_handle_t mac_handle,
 	QDF_STATUS (*callback_fn)(void *ctx, struct sir_md_evt *event),
 	void *hdd_ctx
 );
+
+/**
+ * sme_set_md_bl_evt_cb - Register/set motion detection baseline callback
+ * @mac_handle: mac handle
+ * @callback_fn: callback function pointer
+ * @hdd_ctx: hdd context
+ *
+ * Return: QDF_STATUS_SUCCESS or non-zero on failure
+ */
+QDF_STATUS sme_set_md_bl_evt_cb
+(
+	mac_handle_t mac_handle,
+	QDF_STATUS (*callback_fn)(void *ctx, struct sir_md_bl_evt *event),
+	void *hdd_ctx
+);
 #endif /* WLAN_FEATURE_MOTION_DETECTION */
+
 #ifdef FW_THERMAL_THROTTLE_SUPPORT
 /**
  * sme_set_thermal_throttle_cfg() - SME API to set the thermal throttle

+ 2 - 0
core/sme/inc/sme_internal.h

@@ -279,6 +279,7 @@ typedef void (*sme_get_isolation_cb)(struct sir_isolation_resp *param,
 
 #ifdef WLAN_FEATURE_MOTION_DETECTION
 typedef QDF_STATUS (*md_host_evt_cb)(void *hdd_ctx, struct sir_md_evt *event);
+typedef QDF_STATUS (*md_bl_evt_cb)(void *hdd_ctx, struct sir_md_bl_evt *event);
 #endif /* WLAN_FEATURE_MOTION_DETECTION */
 
 struct sme_context {
@@ -371,6 +372,7 @@ struct sme_context {
 #endif
 #ifdef WLAN_FEATURE_MOTION_DETECTION
 	md_host_evt_cb md_host_evt_cb;
+	md_bl_evt_cb md_bl_evt_cb;
 	void *md_ctx;
 #endif /* WLAN_FEATURE_MOTION_DETECTION */
 	/* hidden ssid rsp callback */

+ 26 - 0
core/sme/src/common/sme_api.c

@@ -15528,6 +15528,32 @@ void sme_enable_fw_module_log_level(mac_handle_t mac_handle, int vdev_id)
 }
 
 #ifdef WLAN_FEATURE_MOTION_DETECTION
+/**
+ * sme_set_md_bl_evt_cb - Register/set motion detection baseline callback
+ * @mac_handle: mac handle
+ * @callback_fn: callback function pointer
+ * @hdd_ctx: hdd context
+ *
+ * Return: QDF_STATUS_SUCCESS or non-zero on failure
+ */
+QDF_STATUS sme_set_md_bl_evt_cb(
+	mac_handle_t mac_handle,
+	QDF_STATUS (*callback_fn)(void *ctx, struct sir_md_bl_evt *event),
+	void *hdd_ctx
+)
+{
+	struct mac_context *mac = MAC_CONTEXT(mac_handle);
+	QDF_STATUS qdf_status = QDF_STATUS_SUCCESS;
+
+	qdf_status = sme_acquire_global_lock(&mac->sme);
+	if (QDF_IS_STATUS_SUCCESS(qdf_status)) {
+		mac->sme.md_bl_evt_cb = callback_fn;
+		mac->sme.md_ctx = hdd_ctx;
+		sme_release_global_lock(&mac->sme);
+	}
+	return qdf_status;
+}
+
 /**
  * sme_set_md_host_evt_cb - Register/set motion detection callback
  * @mac_handle: mac handle

+ 26 - 3
core/wma/src/wma_main.c

@@ -7981,7 +7981,7 @@ int wma_motion_det_host_event_handler(void *handle, uint8_t *event,
 		 motion_det_event_hdr->vdev_id, motion_det_event_hdr->status);
 
 	md_event = qdf_mem_malloc(sizeof(*md_event));
-	if (!event)
+	if (!md_event)
 		return -ENOMEM;
 
 	md_event->vdev_id = motion_det_event_hdr->vdev_id;
@@ -8007,20 +8007,43 @@ int wma_motion_det_base_line_host_event_handler(void *handle,
 	wmi_motion_det_base_line_event *motion_det_base_line_event_hdr;
 	WMI_MOTION_DET_BASE_LINE_HOST_EVENTID_param_tlvs *param_buf =
 		(WMI_MOTION_DET_BASE_LINE_HOST_EVENTID_param_tlvs *)event;
+	struct sir_md_bl_evt *md_bl_event;
+	struct mac_context *pmac = (struct mac_context *)cds_get_context(
+				    QDF_MODULE_ID_PE);
 
 	if (!param_buf) {
-		WMA_LOGE("Invalid motion det base line event buffer");
+		WMA_LOGE("Invalid motion detection base line event buffer");
+		return -EINVAL;
+	}
+
+	if (!pmac || !pmac->sme.md_bl_evt_cb) {
+		WMA_LOGE("Invalid motion detection base line callback");
 		return -EINVAL;
 	}
 
 	motion_det_base_line_event_hdr = param_buf->fixed_param;
-	WMA_LOGA("motion host detect base line event received, vdev_id=%d",
+	WMA_LOGA("motion detection base line event received, vdev_id=%d",
 		 motion_det_base_line_event_hdr->vdev_id);
 	WMA_LOGA("baseline_value=%d bl_max_corr_resv=%d bl_min_corr_resv=%d",
 		 motion_det_base_line_event_hdr->bl_baseline_value,
 		 motion_det_base_line_event_hdr->bl_max_corr_reserved,
 		 motion_det_base_line_event_hdr->bl_min_corr_reserved);
 
+	md_bl_event = qdf_mem_malloc(sizeof(*md_bl_event));
+	if (!md_bl_event)
+		return -ENOMEM;
+
+	md_bl_event->vdev_id = motion_det_base_line_event_hdr->vdev_id;
+	md_bl_event->bl_baseline_value =
+			motion_det_base_line_event_hdr->bl_baseline_value;
+	md_bl_event->bl_max_corr_reserved =
+			motion_det_base_line_event_hdr->bl_max_corr_reserved;
+	md_bl_event->bl_min_corr_reserved =
+			motion_det_base_line_event_hdr->bl_min_corr_reserved;
+
+	pmac->sme.md_bl_evt_cb(pmac->sme.md_ctx, md_bl_event);
+
+	qdf_mem_free(md_bl_event);
 	return 0;
 }