Browse Source

Allow Probe Request callbacks to terminate iteration

Jouni Malinen 15 years ago
parent
commit
cd7d80f373
6 changed files with 28 additions and 19 deletions
  1. 3 2
      src/ap/beacon.c
  2. 10 4
      src/ap/drv_callbacks.c
  3. 3 3
      src/ap/hostapd.h
  4. 2 2
      src/ap/utils.c
  5. 8 6
      src/ap/wps_hostapd.c
  6. 2 2
      src/drivers/driver.h

+ 3 - 2
src/ap/beacon.c

@@ -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;

+ 10 - 4
src/ap/drv_callbacks.c

@@ -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;
 }

+ 3 - 3
src/ap/hostapd.h

@@ -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);
 

+ 2 - 2
src/ap/utils.c

@@ -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;

+ 8 - 6
src/ap/wps_hostapd.c

@@ -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;
 }
 
 

+ 2 - 2
src/drivers/driver.h

@@ -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 */