nl80211: Use native cfg80211 sta events

Change-Id: Id59cc4af50dbccd283db2ec3e7b0b6f8c2146e68
Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c
index 9ef4e8b..721b73b 100644
--- a/src/drivers/driver_nl80211.c
+++ b/src/drivers/driver_nl80211.c
@@ -1070,20 +1070,6 @@
 	u16 status;
 
 	mgmt = (const struct ieee80211_mgmt *) frame;
-#if (defined (CONFIG_AP) || defined (HOSTAPD) ) && defined (ANDROID_P2P)
-	if (drv->nlmode == NL80211_IFTYPE_AP || drv->nlmode == NL80211_IFTYPE_P2P_GO) {
-		if (len < 24 + sizeof(mgmt->u.assoc_req)) {
-			wpa_printf(MSG_DEBUG, "nl80211: Too short association event "
-			   "frame");
-			return;
-		}
-		os_memset(&event, 0, sizeof(event));
-		event.assoc_info.freq = drv->assoc_freq;
-		event.assoc_info.req_ies = (u8 *) mgmt->u.assoc_req.variable;
-		event.assoc_info.req_ies_len = len - 24 - sizeof(mgmt->u.assoc_req);
-		event.assoc_info.addr = mgmt->sa;
-	} else {
-#endif
 	if (len < 24 + sizeof(mgmt->u.assoc_resp)) {
 		wpa_printf(MSG_DEBUG, "nl80211: Too short association event "
 			   "frame");
@@ -1117,9 +1103,6 @@
 	}
 
 	event.assoc_info.freq = drv->assoc_freq;
-#if (defined (CONFIG_AP) || defined(HOSTAPD)) && defined (ANDROID_P2P)
-	}
-#endif
 	wpa_supplicant_event(drv->ctx, EVENT_ASSOC, &event);
 }
 
@@ -1253,14 +1236,6 @@
 		event.rx_action.data = &mgmt->u.action.category + 1;
 		event.rx_action.len = frame + len - event.rx_action.data;
 		wpa_supplicant_event(drv->ctx, EVENT_RX_ACTION, &event);
-#ifdef ANDROID_P2P
-	} else if (stype == WLAN_FC_STYPE_ASSOC_REQ) {
-		mlme_event_assoc(drv, frame, len);
-	} else if (stype == WLAN_FC_STYPE_DISASSOC) {
-		mlme_event_deauth_disassoc(drv, EVENT_DISASSOC, frame, len);
-	} else if (stype == WLAN_FC_STYPE_DEAUTH) {
-		mlme_event_deauth_disassoc(drv, EVENT_DEAUTH, frame, len);
-#endif
 	} else {
 		event.rx_mgmt.frame = frame;
 		event.rx_mgmt.frame_len = len;
@@ -1345,13 +1320,6 @@
 	if (type == EVENT_DISASSOC) {
 		event.disassoc_info.locally_generated =
 			!os_memcmp(mgmt->sa, drv->first_bss.addr, ETH_ALEN);
-
-#ifdef ANDROID_P2P
-		if (drv->nlmode == NL80211_IFTYPE_AP ||
-			drv->nlmode == NL80211_IFTYPE_P2P_GO) {
-			event.disassoc_info.addr = mgmt->sa;
-		} else
-#endif
 		event.disassoc_info.addr = bssid;
 		event.disassoc_info.reason_code = reason_code;
 		if (frame + len > mgmt->u.disassoc.variable) {
@@ -1362,13 +1330,6 @@
 	} else {
 		event.deauth_info.locally_generated =
 			!os_memcmp(mgmt->sa, drv->first_bss.addr, ETH_ALEN);
-
-#ifdef ANDROID_P2P
-			if (drv->nlmode == NL80211_IFTYPE_AP ||
-				drv->nlmode == NL80211_IFTYPE_P2P_GO) {
-				event.deauth_info.addr = mgmt->sa;
-			} else
-#endif
 		event.deauth_info.addr = bssid;
 		event.deauth_info.reason_code = reason_code;
 		if (frame + len > mgmt->u.deauth.variable) {
@@ -2529,8 +2490,9 @@
 				WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP;
 		}
 	}
-
+#ifndef ANDROID_P2P
 	if (tb[NL80211_ATTR_DEVICE_AP_SME])
+#endif
 		info->device_ap_sme = 1;
 
 	if (tb[NL80211_ATTR_FEATURE_FLAGS]) {
@@ -5221,14 +5183,6 @@
 					      data, data_len, NULL, 1, noack,
 					      1);
 	}
-#ifdef ANDROID_P2P
-	if (freq == 0)
-		freq = bss->freq;
-	if ( is_ap_interface(drv->nlmode)) {
-		return nl80211_send_frame_cmd(bss, freq, 0,
-					  data, data_len, &drv->send_action_cookie, 0, noack, 1);
-	}
-#else
 
 	if (drv->device_ap_sme && is_ap_interface(drv->nlmode)) {
 		if (freq == 0)
@@ -5238,7 +5192,7 @@
 					      &drv->send_action_cookie,
 					      no_cck, noack, offchanok);
 	}
-#endif
+
 	if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
 	    WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) {
 		/*
@@ -5455,9 +5409,7 @@
 				params->short_slot_time, params->ht_opmode,
 				params->isolate, params->basic_rates);
 	}
-#if defined(ANDROID_P2P) && defined(HOSTAPD)
-	wpa_driver_nl80211_probe_req_report(priv, 1);
-#endif
+
 	return ret;
  nla_put_failure:
 	nlmsg_free(msg);
@@ -5495,14 +5447,8 @@
 				    NL80211_CHAN_HT40PLUS);
 			break;
 		default:
-#ifndef ANDROID_P2P
-/* Should be change to HT20 as a default value because P2P firmware does not support 11n for BCM4329 */
 			NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
 				    NL80211_CHAN_HT20);
-#else
-			NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
-				    NL80211_CHAN_NO_HT);
-#endif
 			break;
 		}
 	}
@@ -6199,6 +6145,7 @@
 		if (nl80211_mgmt_subscribe_ap(bss))
 			return -1;
 
+#ifndef ANDROID_P2P
 	if (drv->device_ap_sme && !drv->use_monitor)
 		if (nl80211_mgmt_subscribe_ap_dev_sme(bss))
 			return -1;
@@ -6206,6 +6153,14 @@
 	if (!drv->device_ap_sme && drv->use_monitor &&
 	    nl80211_create_monitor_interface(drv) &&
 	    !drv->device_ap_sme)
+#else
+	if (drv->device_ap_sme)
+		if (nl80211_mgmt_subscribe_ap_dev_sme(bss))
+			return -1;
+
+	if (drv->use_monitor &&
+	    nl80211_create_monitor_interface(drv))
+#endif
 		return -1;
 
 	if (drv->device_ap_sme &&
@@ -6215,14 +6170,6 @@
 		/* Try to survive without this */
 	}
 
-#ifdef ANDROID_P2P
-	/* For AP mode, enable probe req report even if device_ap_sme
-	 * is not enabled
-	 */
-	wpa_printf(MSG_DEBUG, "nl80211: Enabling probe req report");
-	wpa_driver_nl80211_probe_req_report(bss, 1);
-#endif
-
 	return 0;
 }
 
@@ -6285,8 +6232,11 @@
 	u8 *pos;
 	int res;
 	int qos = flags & WPA_STA_WMM;
-
+#ifndef ANDROID_P2P
 	if (drv->device_ap_sme || !drv->use_monitor)
+#else
+	if (drv->device_ap_sme && !drv->use_monitor)
+#endif
 		return nl80211_send_eapol_data(bss, addr, data, data_len);
 
 	len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 +
@@ -8242,51 +8192,7 @@
 				   (WLAN_FC_STYPE_PROBE_REQ << 4),
 				   NULL, 0) < 0)
 		goto out_err;
-#ifdef ANDROID_P2P
-	if (drv->nlmode != NL80211_IFTYPE_AP &&
-		drv->nlmode != NL80211_IFTYPE_P2P_GO) {
-		wpa_printf(MSG_DEBUG, "nl80211: probe_req_report control only "
-			   "allowed in AP or P2P GO mode (iftype=%d)",
-			   drv->nlmode);
-		goto done;
-	}
-	if (nl80211_register_frame(bss, bss->nl_preq,
-			   (WLAN_FC_TYPE_MGMT << 2) |
-			   (WLAN_FC_STYPE_ASSOC_REQ << 4),
-			   NULL, 0) < 0) {
-		goto out_err;
-	}
 
-	if (nl80211_register_frame(bss, bss->nl_preq,
-			   (WLAN_FC_TYPE_MGMT << 2) |
-			   (WLAN_FC_STYPE_REASSOC_REQ << 4),
-			   NULL, 0) < 0) {
-		goto out_err;
-	}
-
-	if (nl80211_register_frame(bss, bss->nl_preq,
-			   (WLAN_FC_TYPE_MGMT << 2) |
-			   (WLAN_FC_STYPE_DISASSOC << 4),
-			   NULL, 0) < 0) {
-		goto out_err;
-	}
-
-	if (nl80211_register_frame(bss, bss->nl_preq,
-					   (WLAN_FC_TYPE_MGMT << 2) |
-					   (WLAN_FC_STYPE_DEAUTH << 4),
-					   NULL, 0) < 0) {
-		goto out_err;
-	}
-
-	if (nl80211_register_frame(bss, bss->nl_preq,
-			   (WLAN_FC_TYPE_MGMT << 2) |
-			   (WLAN_FC_STYPE_ACTION << 4),
-			   NULL, 0) < 0) {
-		goto out_err;
-	}
-
-done:
-#endif /* ANDROID_P2P */
 	eloop_register_read_sock(nl_socket_get_fd(bss->nl_preq),
 				 wpa_driver_nl80211_event_receive, bss->nl_cb,
 				 bss->nl_preq);