Add generic infrastructure for Probe Request callbacks

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.
This commit is contained in:
Jouni Malinen 2009-06-12 18:13:40 +03:00 committed by Jouni Malinen
parent 3fed6f2504
commit fa16028d0f
6 changed files with 53 additions and 11 deletions

View file

@ -204,7 +204,7 @@ void handle_probe_req(struct hostapd_data *hapd, struct ieee80211_mgmt *mgmt,
ie = mgmt->u.probe_req.variable; ie = mgmt->u.probe_req.variable;
ie_len = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req)); 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) if (!hapd->iconf->send_probe_response)
return; return;

View 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, void hostapd_probe_req_rx(struct hostapd_data *hapd, const u8 *sa,
const u8 *ie, size_t ie_len) 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);
} }

View file

@ -445,6 +445,9 @@ static void hostapd_cleanup(struct hostapd_data *hapd)
wpa_printf(MSG_WARNING, "Failed to remove BSS interface %s", wpa_printf(MSG_WARNING, "Failed to remove BSS interface %s",
hapd->conf->iface); 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]); os_free(iface->bss[j]);
hostapd_cleanup_iface(iface); 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;
}

View file

@ -29,6 +29,11 @@ struct upnp_wps_device_sm;
struct full_dynamic_vlan; struct full_dynamic_vlan;
#endif /* CONFIG_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 * struct hostapd_data - hostapd per-BSS data structure
*/ */
@ -98,6 +103,9 @@ struct hostapd_data {
unsigned int ap_pin_failures; unsigned int ap_pin_failures;
struct upnp_wps_device_sm *wps_upnp; struct upnp_wps_device_sm *wps_upnp;
#endif /* CONFIG_WPS */ #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, int hostapd_for_each_interface(int (*cb)(struct hostapd_iface *iface,
void *ctx), void *ctx); 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 */ #endif /* HOSTAPD_H */

View 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); static void hostapd_wps_upnp_deinit(struct hostapd_data *hapd);
#endif /* CONFIG_WPS_UPNP */ #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, static int hostapd_wps_new_psk_cb(void *ctx, const u8 *mac_addr, const u8 *psk,
size_t psk_len) size_t psk_len)
@ -676,6 +679,8 @@ int hostapd_init_wps(struct hostapd_data *hapd,
} }
#endif /* CONFIG_WPS_UPNP */ #endif /* CONFIG_WPS_UPNP */
hostapd_register_probereq_cb(hapd, hostapd_wps_probe_req_rx, hapd);
hapd->wps = wps; hapd->wps = wps;
return 0; return 0;
@ -783,9 +788,10 @@ error:
#endif /* CONFIG_WPS_OOB */ #endif /* CONFIG_WPS_OOB */
void hostapd_wps_probe_req_rx(struct hostapd_data *hapd, const u8 *addr, static void hostapd_wps_probe_req_rx(void *ctx, const u8 *addr,
const u8 *ie, size_t ie_len) const u8 *ie, size_t ie_len)
{ {
struct hostapd_data *hapd = ctx;
struct wpabuf *wps_ie; struct wpabuf *wps_ie;
const u8 *end, *pos, *wps; const u8 *end, *pos, *wps;

View 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_button_pushed(struct hostapd_data *hapd);
int hostapd_wps_start_oob(struct hostapd_data *hapd, char *device_type, int hostapd_wps_start_oob(struct hostapd_data *hapd, char *device_type,
char *path, char *method, char *name); 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 */ #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 /* CONFIG_WPS */
#endif /* WPS_HOSTAPD_H */ #endif /* WPS_HOSTAPD_H */