Add generic infrastructure for Probe Request callbacks
authorJouni Malinen <jouni.malinen@atheros.com>
Fri, 12 Jun 2009 15:13:40 +0000 (18:13 +0300)
committerJouni Malinen <j@w1.fi>
Fri, 12 Jun 2009 15:13:40 +0000 (18:13 +0300)
Instead of calling specific Probe Request handler functions, use a
generic mechanism that allows multiple callback functions to be
registered for getting notification on receive Probe Request frames.

hostapd/beacon.c
hostapd/drv_callbacks.c
hostapd/hostapd.c
hostapd/hostapd.h
hostapd/wps_hostapd.c
hostapd/wps_hostapd.h

index 1df8752..cc09c9c 100644 (file)
@@ -204,7 +204,7 @@ void handle_probe_req(struct hostapd_data *hapd, struct ieee80211_mgmt *mgmt,
        ie = mgmt->u.probe_req.variable;
        ie_len = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req));
 
-       hostapd_wps_probe_req_rx(hapd, mgmt->sa, ie, ie_len);
+       hostapd_probe_req_rx(hapd, mgmt->sa, ie, ie_len);
 
        if (!hapd->iconf->send_probe_response)
                return;
index 8a7fcf9..de686f4 100644 (file)
@@ -437,5 +437,9 @@ void wpa_supplicant_event(void *ctx, wpa_event_type event,
 void hostapd_probe_req_rx(struct hostapd_data *hapd, const u8 *sa,
                         const u8 *ie, size_t ie_len)
 {
-       hostapd_wps_probe_req_rx(hapd, sa, ie, ie_len);
+       size_t i;
+
+       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);
 }
index dfebf84..58025ab 100644 (file)
@@ -445,6 +445,9 @@ static void hostapd_cleanup(struct hostapd_data *hapd)
                wpa_printf(MSG_WARNING, "Failed to remove BSS interface %s",
                           hapd->conf->iface);
        }
+
+       os_free(hapd->probereq_cb);
+       hapd->probereq_cb = NULL;
 }
 
 
@@ -1583,3 +1586,26 @@ void hostapd_interface_deinit(struct hostapd_iface *iface)
                os_free(iface->bss[j]);
        hostapd_cleanup_iface(iface);
 }
+
+
+int hostapd_register_probereq_cb(struct hostapd_data *hapd,
+                                void (*cb)(void *ctx, const u8 *sa,
+                                           const u8 *ie, size_t ie_len),
+                                void *ctx)
+{
+       struct hostapd_probereq_cb *n;
+
+       n = os_realloc(hapd->probereq_cb, (hapd->num_probereq_cb + 1) *
+                      sizeof(struct hostapd_probereq_cb));
+       if (n == NULL)
+               return -1;
+
+       hapd->probereq_cb = n;
+       n = &hapd->probereq_cb[hapd->num_probereq_cb];
+       hapd->num_probereq_cb++;
+
+       n->cb = cb;
+       n->ctx = ctx;
+
+       return 0;
+}
index 6c12c8e..386889e 100644 (file)
@@ -29,6 +29,11 @@ struct upnp_wps_device_sm;
 struct full_dynamic_vlan;
 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
 
+struct hostapd_probereq_cb {
+       void (*cb)(void *ctx, const u8 *sa, const u8 *ie, size_t ie_len);
+       void *ctx;
+};
+
 /**
  * struct hostapd_data - hostapd per-BSS data structure
  */
@@ -98,6 +103,9 @@ struct hostapd_data {
        unsigned int ap_pin_failures;
        struct upnp_wps_device_sm *wps_upnp;
 #endif /* CONFIG_WPS */
+
+       struct hostapd_probereq_cb *probereq_cb;
+       size_t num_probereq_cb;
 };
 
 
@@ -169,4 +177,9 @@ int handle_dump_state_iface(struct hostapd_iface *iface, void *ctx);
 int hostapd_for_each_interface(int (*cb)(struct hostapd_iface *iface,
                                         void *ctx), void *ctx);
 
+int hostapd_register_probereq_cb(struct hostapd_data *hapd,
+                                void (*cb)(void *ctx, const u8 *sa,
+                                           const u8 *ie, size_t ie_len),
+                                void *ctx);
+
 #endif /* HOSTAPD_H */
index 34fe409..a0c1e3a 100644 (file)
@@ -36,6 +36,9 @@ 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_new_psk_cb(void *ctx, const u8 *mac_addr, const u8 *psk,
                                  size_t psk_len)
@@ -676,6 +679,8 @@ int hostapd_init_wps(struct hostapd_data *hapd,
        }
 #endif /* CONFIG_WPS_UPNP */
 
+       hostapd_register_probereq_cb(hapd, hostapd_wps_probe_req_rx, hapd);
+
        hapd->wps = wps;
 
        return 0;
@@ -783,9 +788,10 @@ error:
 #endif /* CONFIG_WPS_OOB */
 
 
-void hostapd_wps_probe_req_rx(struct hostapd_data *hapd, const u8 *addr,
-                             const u8 *ie, size_t ie_len)
+static void 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;
        const u8 *end, *pos, *wps;
 
index d16eee7..5f094f5 100644 (file)
@@ -25,8 +25,6 @@ int hostapd_wps_add_pin(struct hostapd_data *hapd, const char *uuid,
 int hostapd_wps_button_pushed(struct hostapd_data *hapd);
 int hostapd_wps_start_oob(struct hostapd_data *hapd, char *device_type,
                          char *path, char *method, char *name);
-void hostapd_wps_probe_req_rx(struct hostapd_data *hapd, const u8 *addr,
-                             const u8 *ie, size_t ie_len);
 
 #else /* CONFIG_WPS */
 
@@ -40,11 +38,6 @@ static inline void hostapd_deinit_wps(struct hostapd_data *hapd)
 {
 }
 
-static inline void hostapd_wps_probe_req_rx(struct hostapd_data *hapd,
-                                           const u8 *addr,
-                                           const u8 *ie, size_t ie_len)
-{
-}
 #endif /* CONFIG_WPS */
 
 #endif /* WPS_HOSTAPD_H */