Allow Probe Request callbacks to terminate iteration
authorJouni Malinen <jouni.malinen@atheros.com>
Mon, 28 Dec 2009 11:14:58 +0000 (13:14 +0200)
committerJouni Malinen <j@w1.fi>
Mon, 28 Dec 2009 11:14:58 +0000 (13:14 +0200)
src/ap/beacon.c
src/ap/drv_callbacks.c
src/ap/hostapd.h
src/ap/utils.c
src/ap/wps_hostapd.c
src/drivers/driver.h

index 9c65760..4026056 100644 (file)
@@ -209,8 +209,9 @@ void handle_probe_req(struct hostapd_data *hapd,
        ie_len = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req));
 
        for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++)
-               hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
-                                       mgmt->sa, ie, ie_len);
+               if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
+                                           mgmt->sa, ie, ie_len) > 0)
+                       return;
 
        if (!hapd->iconf->send_probe_response)
                return;
index ed71d20..30d87a8 100644 (file)
@@ -378,12 +378,18 @@ void wpa_supplicant_event(void *ctx, wpa_event_type event,
 #endif /* HOSTAPD */
 
 
-void hostapd_probe_req_rx(struct hostapd_data *hapd, const u8 *sa,
+int hostapd_probe_req_rx(struct hostapd_data *hapd, const u8 *sa,
                         const u8 *ie, size_t ie_len)
 {
        size_t i;
+       int ret = 0;
 
-       for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++)
-               hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
-                                       sa, ie, ie_len);
+       for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++) {
+               if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
+                                           sa, ie, ie_len) > 0) {
+                       ret = 1;
+                       break;
+               }
+       }
+       return ret;
 }
index f3cbad2..39fb6c9 100644 (file)
@@ -29,7 +29,7 @@ struct ieee80211_ht_capabilities;
 struct full_dynamic_vlan;
 
 struct hostapd_probereq_cb {
-       void (*cb)(void *ctx, const u8 *sa, const u8 *ie, size_t ie_len);
+       int (*cb)(void *ctx, const u8 *sa, const u8 *ie, size_t ie_len);
        void *ctx;
 };
 
@@ -249,8 +249,8 @@ void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta,
 
 /* utils.c */
 int hostapd_register_probereq_cb(struct hostapd_data *hapd,
-                                void (*cb)(void *ctx, const u8 *sa,
-                                           const u8 *ie, size_t ie_len),
+                                int (*cb)(void *ctx, const u8 *sa,
+                                          const u8 *ie, size_t ie_len),
                                 void *ctx);
 void hostapd_prune_associations(struct hostapd_data *hapd, const u8 *addr);
 
index 7ec77ff..0ff48ae 100644 (file)
@@ -21,8 +21,8 @@
 
 
 int hostapd_register_probereq_cb(struct hostapd_data *hapd,
-                                void (*cb)(void *ctx, const u8 *sa,
-                                           const u8 *ie, size_t ie_len),
+                                int (*cb)(void *ctx, const u8 *sa,
+                                          const u8 *ie, size_t ie_len),
                                 void *ctx)
 {
        struct hostapd_probereq_cb *n;
index 2c893f4..235071b 100644 (file)
@@ -39,8 +39,8 @@ static int hostapd_wps_upnp_init(struct hostapd_data *hapd,
 static void hostapd_wps_upnp_deinit(struct hostapd_data *hapd);
 #endif /* CONFIG_WPS_UPNP */
 
-static void hostapd_wps_probe_req_rx(void *ctx, const u8 *addr,
-                                    const u8 *ie, size_t ie_len);
+static int hostapd_wps_probe_req_rx(void *ctx, const u8 *addr,
+                                   const u8 *ie, size_t ie_len);
 
 
 static int hostapd_wps_new_psk_cb(void *ctx, const u8 *mac_addr, const u8 *psk,
@@ -738,18 +738,18 @@ error:
 #endif /* CONFIG_WPS_OOB */
 
 
-static void hostapd_wps_probe_req_rx(void *ctx, const u8 *addr,
-                                    const u8 *ie, size_t ie_len)
+static int hostapd_wps_probe_req_rx(void *ctx, const u8 *addr,
+                                   const u8 *ie, size_t ie_len)
 {
        struct hostapd_data *hapd = ctx;
        struct wpabuf *wps_ie;
 
        if (hapd->wps == NULL)
-               return;
+               return 0;
 
        wps_ie = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA);
        if (wps_ie == NULL)
-               return;
+               return 0;
 
        if (wpabuf_len(wps_ie) > 0) {
                wps_registrar_probe_req_rx(hapd->wps->registrar, addr, wps_ie);
@@ -763,6 +763,8 @@ static void hostapd_wps_probe_req_rx(void *ctx, const u8 *addr,
        }
 
        wpabuf_free(wps_ie);
+
+       return 0;
 }
 
 
index c0a05ab..27a1100 100644 (file)
@@ -2007,7 +2007,7 @@ struct hostapd_frame_info {
 
 struct hostapd_data * hostapd_sta_get_bss(struct hostapd_data *hapd,
                                          const u8 *addr);
-void hostapd_probe_req_rx(struct hostapd_data *hapd, const u8 *sa,
-                         const u8 *ie, size_t ie_len);
+int hostapd_probe_req_rx(struct hostapd_data *hapd, const u8 *sa,
+                        const u8 *ie, size_t ie_len);
 
 #endif /* DRIVER_H */