From 80c9582a5f66f52e5d46a431f76eea0513e7a8ab Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Mon, 28 Jun 2010 22:11:39 -0700 Subject: [PATCH] P2P: Add test command for filtering which peers are discovered "wpa_cli p2p_set peer_filter " can now be used to only allow a single P2P Device (based on P2P Device Address) to be discovered for testing. Setting the address to 00:00:00:00:00:00 disables the filter. --- src/p2p/p2p.c | 20 ++++++++++++++++++++ src/p2p/p2p.h | 2 ++ src/p2p/p2p_i.h | 2 ++ wpa_supplicant/ctrl_iface.c | 8 ++++++++ 4 files changed, 32 insertions(+) diff --git a/src/p2p/p2p.c b/src/p2p/p2p.c index ad09469c1..be223d732 100644 --- a/src/p2p/p2p.c +++ b/src/p2p/p2p.c @@ -448,6 +448,14 @@ static int p2p_add_device(struct p2p_data *p2p, const u8 *addr, int freq, return -1; } + if (!is_zero_ether_addr(p2p->peer_filter) && + os_memcmp(p2p_dev_addr, p2p->peer_filter, ETH_ALEN) != 0) { + wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Do not add peer " + "filter for " MACSTR " due to peer filter", + MAC2STR(p2p_dev_addr)); + return 0; + } + dev = p2p_create_device(p2p, p2p_dev_addr); if (dev == NULL) { p2p_parse_free(&msg); @@ -2912,3 +2920,15 @@ int p2p_get_interface_addr(struct p2p_data *p2p, const u8 *dev_addr, os_memcpy(iface_addr, dev->interface_addr, ETH_ALEN); return 0; } + + +void p2p_set_peer_filter(struct p2p_data *p2p, const u8 *addr) +{ + os_memcpy(p2p->peer_filter, addr, ETH_ALEN); + if (is_zero_ether_addr(p2p->peer_filter)) + wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Disable peer " + "filter"); + else + wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Enable peer " + "filter for " MACSTR, MAC2STR(p2p->peer_filter)); +} diff --git a/src/p2p/p2p.h b/src/p2p/p2p.h index a1b7cab7c..30483798b 100644 --- a/src/p2p/p2p.h +++ b/src/p2p/p2p.h @@ -1213,4 +1213,6 @@ int p2p_set_ssid_postfix(struct p2p_data *p2p, const u8 *postfix, size_t len); int p2p_get_interface_addr(struct p2p_data *p2p, const u8 *dev_addr, u8 *iface_addr); +void p2p_set_peer_filter(struct p2p_data *p2p, const u8 *addr); + #endif /* P2P_H */ diff --git a/src/p2p/p2p_i.h b/src/p2p/p2p_i.h index 598f5814d..150a1f50b 100644 --- a/src/p2p/p2p_i.h +++ b/src/p2p/p2p_i.h @@ -362,6 +362,8 @@ struct p2p_data { unsigned int ext_listen_interval; unsigned int ext_listen_interval_sec; unsigned int ext_listen_interval_usec; + + u8 peer_filter[ETH_ALEN]; }; /** diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c index e330ed62e..5e0956621 100644 --- a/wpa_supplicant/ctrl_iface.c +++ b/wpa_supplicant/ctrl_iface.c @@ -2462,6 +2462,14 @@ static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd) return 0; } + if (os_strcmp(cmd, "peer_filter") == 0) { + u8 addr[ETH_ALEN]; + if (hwaddr_aton(param, addr)) + return -1; + p2p_set_peer_filter(wpa_s->global->p2p, addr); + return 0; + } + wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'", cmd);