From b3bcc0f5195ab9e2dc7c6885afee30bcb66c9e5d Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Thu, 22 Dec 2011 21:04:41 +0200 Subject: [PATCH] P2P: Replace p2p_get_peer_info with p2p_peer_known when applicable p2p_get_peer_info() was used in multiple places just to check whether a specific peer is known. This was not the designed use for the function, so introduce a simpler function for that purpose to make it obvious that the p2p_get_peer_info() function is actually used only in ctrl_iface.c. Signed-hostap: Jouni Malinen --- src/p2p/p2p.c | 6 ++++++ src/p2p/p2p.h | 8 ++++++++ wpa_supplicant/dbus/dbus_new.c | 6 +++--- wpa_supplicant/dbus/dbus_new_handlers_p2p.c | 9 ++++----- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/p2p/p2p.c b/src/p2p/p2p.c index 9fcc6ca39..a9d5998b2 100644 --- a/src/p2p/p2p.c +++ b/src/p2p/p2p.c @@ -3216,6 +3216,12 @@ int p2p_get_peer_info(struct p2p_data *p2p, const u8 *addr, int next, } +int p2p_peer_known(struct p2p_data *p2p, const u8 *addr) +{ + return p2p_get_device(p2p, addr) != NULL; +} + + void p2p_set_client_discoverability(struct p2p_data *p2p, int enabled) { if (enabled) { diff --git a/src/p2p/p2p.h b/src/p2p/p2p.h index 3db0ac581..99934bdc7 100644 --- a/src/p2p/p2p.h +++ b/src/p2p/p2p.h @@ -1427,6 +1427,14 @@ const u8 * p2p_get_go_dev_addr(const struct wpabuf *p2p_ie); int p2p_get_peer_info(struct p2p_data *p2p, const u8 *addr, int next, char *buf, size_t buflen); +/** + * p2p_peer_known - Check whether P2P peer is known + * @p2p: P2P module context from p2p_init() + * @addr: P2P Device Address of the peer + * Returns: 1 if the specified device is in the P2P peer table or 0 if not + */ +int p2p_peer_known(struct p2p_data *p2p, const u8 *addr); + /** * p2p_set_client_discoverability - Set client discoverability capability * @p2p: P2P module context from p2p_init() diff --git a/wpa_supplicant/dbus/dbus_new.c b/wpa_supplicant/dbus/dbus_new.c index f88d3546e..2bf9be8a6 100644 --- a/wpa_supplicant/dbus/dbus_new.c +++ b/wpa_supplicant/dbus/dbus_new.c @@ -867,7 +867,7 @@ void wpas_dbus_signal_p2p_provision_discovery(struct wpa_supplicant *wpa_s, return; /* Check if this is a known peer */ - if (p2p_get_peer_info(wpa_s->global->p2p, dev_addr, 0, NULL, 0) < 0) + if (!p2p_peer_known(wpa_s->global->p2p, dev_addr)) goto error; os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX, @@ -1357,7 +1357,7 @@ void wpas_dbus_signal_p2p_sd_request(struct wpa_supplicant *wpa_s, return; /* Check if this is a known peer */ - if (p2p_get_peer_info(wpa_s->global->p2p, sa, 0, NULL, 0) < 0) + if (!p2p_peer_known(wpa_s->global->p2p, sa)) goto error; os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX, @@ -1426,7 +1426,7 @@ void wpas_dbus_signal_p2p_sd_response(struct wpa_supplicant *wpa_s, return; /* Check if this is a known peer */ - if (p2p_get_peer_info(wpa_s->global->p2p, sa, 0, NULL, 0) < 0) + if (!p2p_peer_known(wpa_s->global->p2p, sa)) goto error; os_snprintf(peer_obj_path, WPAS_DBUS_OBJECT_PATH_MAX, diff --git a/wpa_supplicant/dbus/dbus_new_handlers_p2p.c b/wpa_supplicant/dbus/dbus_new_handlers_p2p.c index de0caad6c..671d0e5ef 100644 --- a/wpa_supplicant/dbus/dbus_new_handlers_p2p.c +++ b/wpa_supplicant/dbus/dbus_new_handlers_p2p.c @@ -497,7 +497,7 @@ DBusMessage * wpas_dbus_handler_p2p_connect(DBusMessage *message, if (!peer_object_path || (wps_method == WPS_NOT_READY) || (parse_peer_object_path(peer_object_path, addr) < 0) || - (p2p_get_peer_info(wpa_s->global->p2p, addr, 0, NULL, 0) < 0)) + !p2p_peer_known(wpa_s->global->p2p, addr)) goto inv_args; /* @@ -603,8 +603,7 @@ DBusMessage * wpas_dbus_handler_p2p_invite(DBusMessage *message, if (!peer_object_path || (parse_peer_object_path(peer_object_path, peer_addr) < 0) || - (p2p_get_peer_info(wpa_s->global->p2p, - peer_addr, 0, NULL, 0) < 0)) { + !p2p_peer_known(wpa_s->global->p2p, peer_addr)) { goto err; } @@ -2013,7 +2012,7 @@ DBusMessage * wpas_dbus_handler_p2p_service_sd_req( if (!peer_object_path || (parse_peer_object_path(peer_object_path, addr) < 0) || - (p2p_get_peer_info(wpa_s->global->p2p, addr, 0, NULL, 0) < 0)) + !p2p_peer_known(wpa_s->global->p2p, addr)) goto error; if (upnp == 1) { @@ -2094,7 +2093,7 @@ DBusMessage * wpas_dbus_handler_p2p_service_sd_res( } if (!peer_object_path || (parse_peer_object_path(peer_object_path, addr) < 0) || - (p2p_get_peer_info(wpa_s->global->p2p, addr, 0, NULL, 0) < 0)) + !p2p_peer_known(wpa_s->global->p2p, addr)) goto error; if (tlv == NULL)