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