PNO MAC rotation + Hotlist Lost event
Ashwin [Mon, 4 Aug 2014 23:52:29 +0000 (16:52 -0700)]
modified:   bcmdhd/wifi_hal/common.h
modified:   bcmdhd/wifi_hal/gscan.cpp
modified:   bcmdhd/wifi_hal/wifi_hal.cpp

Change-Id: I85b8975f1d0578e4524e30c94e8947246b8b128f

bcmdhd/wifi_hal/common.h
bcmdhd/wifi_hal/gscan.cpp
bcmdhd/wifi_hal/wifi_hal.cpp

index e617e4e..4c4fa68 100644 (file)
@@ -14,6 +14,7 @@
 #define RECV_BUF_SIZE           (4096)
 #define DEFAULT_EVENT_CB_SIZE   (64)
 #define DEFAULT_CMD_SIZE        (64)
+#define DOT11_OUI_LEN             3
 
 /*
  Vendor OUI - This is a unique identifier that identifies organization. Lets
@@ -77,9 +78,10 @@ typedef enum {
 
     WIFI_SUBCMD_GET_FEATURE_SET,                         /* 0x100A */
     WIFI_SUBCMD_GET_FEATURE_SET_MATRIX,                  /* 0x100B */
+    WIFI_SUBCMD_SET_PNO_RANDOM_MAC_OUI,                  /* 0x100C */
     /* Add more sub commands here */
 
-    GSCAN_SUBCMD_MAX                                    /* 0x100C */
+    GSCAN_SUBCMD_MAX                                    /* 0x100D */
 
 } WIFI_SUB_COMMAND;
 
@@ -87,12 +89,12 @@ typedef enum {
     BRCM_RESERVED1,
     BRCM_RESERVED2,
     GSCAN_EVENT_SIGNIFICANT_CHANGE_RESULTS ,
-    GSCAN_EVENT_HOTLIST_RESULTS,
+    GSCAN_EVENT_HOTLIST_RESULTS_FOUND,
     GSCAN_EVENT_SCAN_RESULTS_AVAILABLE,
     GSCAN_EVENT_FULL_SCAN_RESULTS,
     RTT_EVENT_COMPLETE,
-    GSCAN_EVENT_COMPLETE_SCAN
-
+    GSCAN_EVENT_COMPLETE_SCAN,
+    GSCAN_EVENT_HOTLIST_RESULTS_LOST
 } WIFI_EVENT;
 
 typedef void (*wifi_internal_event_handler) (wifi_handle handle, int events);
index fe9c3a5..de15df5 100644 (file)
@@ -948,6 +948,11 @@ public:
             return result;
         }
 
+        result = request.put_u32(GSCAN_ATTRIBUTE_LOST_AP_SAMPLE_SIZE, mParams.lost_ap_sample_size);
+        if (result < 0) {
+            return result;
+        }
+
         struct nlattr * attr = request.attr_start(GSCAN_ATTRIBUTE_HOTLIST_BSSIDS);
         for (int i = 0; i < mParams.num_ap; i++) {
             nlattr *attr2 = request.attr_start(GSCAN_ATTRIBUTE_HOTLIST_ELEM);
@@ -1003,7 +1008,8 @@ public:
         result = requestResponse(request);
         if (result < 0) {
             ALOGI("Failed to execute hotlist setup request, result = %d", result);
-            unregisterVendorHandler(GOOGLE_OUI, GSCAN_EVENT_HOTLIST_RESULTS);
+            unregisterVendorHandler(GOOGLE_OUI, GSCAN_EVENT_HOTLIST_RESULTS_FOUND);
+            unregisterVendorHandler(GOOGLE_OUI, GSCAN_EVENT_HOTLIST_RESULTS_LOST);
             return result;
         }
 
@@ -1013,11 +1019,13 @@ public:
             return result;
         }
 
-        registerVendorHandler(GOOGLE_OUI, GSCAN_EVENT_HOTLIST_RESULTS);
+        registerVendorHandler(GOOGLE_OUI, GSCAN_EVENT_HOTLIST_RESULTS_FOUND);
+        registerVendorHandler(GOOGLE_OUI, GSCAN_EVENT_HOTLIST_RESULTS_LOST);
 
         result = requestResponse(request);
         if (result < 0) {
-            unregisterVendorHandler(GOOGLE_OUI, GSCAN_EVENT_HOTLIST_RESULTS);
+            unregisterVendorHandler(GOOGLE_OUI, GSCAN_EVENT_HOTLIST_RESULTS_FOUND);
+            unregisterVendorHandler(GOOGLE_OUI, GSCAN_EVENT_HOTLIST_RESULTS_LOST);
             return result;
         }
 
@@ -1027,8 +1035,8 @@ public:
 
     virtual int cancel() {
         /* unregister event handler */
-        unregisterVendorHandler(GOOGLE_OUI, GSCAN_EVENT_HOTLIST_RESULTS);
-
+        unregisterVendorHandler(GOOGLE_OUI, GSCAN_EVENT_HOTLIST_RESULTS_FOUND);
+        unregisterVendorHandler(GOOGLE_OUI, GSCAN_EVENT_HOTLIST_RESULTS_LOST);
         /* create set hotlist message with empty hotlist */
         WifiRequest request(familyId(), ifaceId());
         int result = createTeardownRequest(request);
@@ -1051,8 +1059,8 @@ public:
     }
 
     virtual int handleEvent(WifiEvent& event) {
-        ALOGI("Got a hotlist ap found event");
-
+        ALOGI("Hotlist AP event");
+        int event_id = event.get_vendor_subcmd();
         // event.log();
 
         nlattr *vendor_data = event.get_attribute(NL80211_ATTR_VENDOR_DATA);
@@ -1068,9 +1076,16 @@ public:
         int num = len / sizeof(wifi_scan_result);
         num = min(MAX_RESULTS, num);
         memcpy(mResults, event.get_vendor_data(), num * sizeof(wifi_scan_result));
-        ALOGI("Retrieved %d hot APs", num);
 
-        (*mHandler.on_hotlist_ap_found)(id(), num, mResults);
+        if (event_id == GSCAN_EVENT_HOTLIST_RESULTS_FOUND) {
+            ALOGI("FOUND %d hotlist APs", num);
+            if (*mHandler.on_hotlist_ap_found)
+                (*mHandler.on_hotlist_ap_found)(id(), num, mResults);
+        } else if (event_id == GSCAN_EVENT_HOTLIST_RESULTS_LOST) {
+            ALOGI("LOST %d hotlist APs", num);
+            if (*mHandler.on_hotlist_ap_lost)
+                (*mHandler.on_hotlist_ap_lost)(id(), num, mResults);
+        }
         return NL_SKIP;
     }
 };
index a8500be..e45cb78 100644 (file)
@@ -52,10 +52,11 @@ static int wifi_get_multicast_id(wifi_handle handle, const char *name, const cha
 static int wifi_add_membership(wifi_handle handle, const char *group);
 static wifi_error wifi_init_interfaces(wifi_handle handle);
 
-typedef enum wifi_feature_set_attr {
+typedef enum wifi_attr {
     ANDR_WIFI_ATTRIBUTE_NUM_FEATURE_SET,
-    ANDR_WIFI_ATTRIBUTE_FEATURE_SET
-} wifi_feature_set_attr_t;
+    ANDR_WIFI_ATTRIBUTE_FEATURE_SET,
+    ANDR_WIFI_ATTRIBUTE_PNO_RANDOM_MAC_OUI
+} wifi_attr_t;
 
 /* Initialize/Cleanup */
 
@@ -428,6 +429,65 @@ public:
 
 };
 
+class SetPnoMacAddrOuiCommand : public WifiCommand {
+
+private:
+    byte *mOui;
+    feature_set *fset;
+    feature_set *feature_matrix;
+    int *fm_size;
+    int set_size_max;
+public:
+    SetPnoMacAddrOuiCommand(wifi_interface_handle handle, oui scan_oui)
+        : WifiCommand(handle, 0)
+    {
+        mOui = scan_oui;
+    }
+
+    int createRequest(WifiRequest& request, int subcmd, byte *scan_oui) {
+        int result = request.create(GOOGLE_OUI, subcmd);
+        if (result < 0) {
+            return result;
+        }
+
+        nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA);
+        result = request.put(ANDR_WIFI_ATTRIBUTE_PNO_RANDOM_MAC_OUI, scan_oui, DOT11_OUI_LEN);
+        if (result < 0) {
+            return result;
+        }
+
+        request.attr_end(data);
+        return WIFI_SUCCESS;
+
+    }
+
+    int start() {
+        ALOGD("Sending mac address OUI");
+        WifiRequest request(familyId(), ifaceId());
+        int result = createRequest(request, WIFI_SUBCMD_SET_PNO_RANDOM_MAC_OUI, mOui);
+        if (result != WIFI_SUCCESS) {
+            ALOGE("failed to create request; result = %d", result);
+            return result;
+        }
+
+        result = requestResponse(request);
+        if (result != WIFI_SUCCESS) {
+            ALOGE("failed to set scanning mac OUI; result = %d", result);
+        }
+
+        return result;
+    }
+protected:
+    virtual int handleResponse(WifiEvent& reply) {
+         ALOGD("Request complete!");
+        /* Nothing to do on response! */
+        return NL_SKIP;
+    }
+
+};
+
+
+
 class GetFeatureSetCommand : public WifiCommand {
 
 private:
@@ -636,5 +696,12 @@ wifi_error wifi_get_concurrency_matrix(wifi_interface_handle handle, int set_siz
     return (wifi_error) command.requestResponse();
 }
 
+wifi_error wifi_set_scanning_mac_oui(wifi_interface_handle handle, oui scan_oui)
+{
+    SetPnoMacAddrOuiCommand command(handle, scan_oui);
+    return (wifi_error)command.start();
+
+}
+
 /////////////////////////////////////////////////////////////////////////////