On Thu, Nov 03, 2016 at 09:17:51PM +0530, Nishant Chaprana wrote: > Description: This patch adds EAPOL IP address assigned to a peer in > peer properties. Application would be required to fetch peer property > "IpAddress" to get IP Address assigned through EAPOL. The IP address of a peer device is specific to a group in which that peer is in. In other words, it is not a global property of the P2P Device role. There can be multiple IP addresses for each peer, so it cannot be stored in this manner. Instead, there would need to be a group specific entry for this to support concurrent groups. I did some cleanup while reviewing this and before noticing this design issue. The patch below shows the cleaned up version that should be used as baseline for additional changes. For this to become acceptable, the ip_addr[] member in struct p2p_peer_info would need to be moved to struct p2p_group_member on the GO side and on the P2P client side there would need to be some new data structure for storing GO information for each possible P2P group. Similar changes in location would be needed on the D-Bus interface side. From: Nishant Chaprana <n.chaprana@xxxxxxxxxxx> Subject: [PATCH] D-Bus: Add assigned P2P IP address in peer properties FIX: IP address is not a global P2P Device property; it is for a specific group and a P2P peer may be in multiple groups concurrently and as such, may have multiple IP addresses. This commit adds P2P IP address assigned to a peer in peer properties. Application would be required to fetch peer property "IpAddress" to get IP address assigned through P2P. Signed-off-by: Nishant Chaprana <n.chaprana@xxxxxxxxxxx> --- src/ap/hostapd.h | 3 ++- src/ap/sta_info.c | 11 ++++++----- src/p2p/p2p.c | 19 +++++++++++++++++++ src/p2p/p2p.h | 14 ++++++++++++++ wpa_supplicant/ap.c | 6 ++++-- wpa_supplicant/dbus/dbus_new.c | 5 +++++ wpa_supplicant/dbus/dbus_new_handlers_p2p.c | 20 ++++++++++++++++++++ wpa_supplicant/dbus/dbus_new_handlers_p2p.h | 1 + wpa_supplicant/notify.c | 14 +++++++++----- wpa_supplicant/notify.h | 2 +- wpa_supplicant/p2p_supplicant.c | 5 ++++- wpa_supplicant/p2p_supplicant.h | 2 +- 12 files changed, 86 insertions(+), 16 deletions(-) diff --git a/src/ap/hostapd.h b/src/ap/hostapd.h index fd5aaed..7d49c14 100644 --- a/src/ap/hostapd.h +++ b/src/ap/hostapd.h @@ -222,7 +222,8 @@ struct hostapd_data { void *wps_event_cb_ctx; void (*sta_authorized_cb)(void *ctx, const u8 *mac_addr, - int authorized, const u8 *p2p_dev_addr); + int authorized, const u8 *p2p_dev_addr, + const u8 *ip_addr); void *sta_authorized_cb_ctx; void (*setup_complete_cb)(void *ctx); diff --git a/src/ap/sta_info.c b/src/ap/sta_info.c index f12d408..e22c868 100644 --- a/src/ap/sta_info.c +++ b/src/ap/sta_info.c @@ -1124,8 +1124,8 @@ void ap_sta_set_authorized(struct hostapd_data *hapd, struct sta_info *sta, char buf[100]; #ifdef CONFIG_P2P u8 addr[ETH_ALEN]; - u8 ip_addr_buf[4]; #endif /* CONFIG_P2P */ + u8 ip_addr_buf[4] = { 0, 0, 0, 0 }; if (!!authorized == !!(sta->flags & WLAN_STA_AUTHORIZED)) return; @@ -1150,10 +1150,6 @@ void ap_sta_set_authorized(struct hostapd_data *hapd, struct sta_info *sta, #endif /* CONFIG_P2P */ os_snprintf(buf, sizeof(buf), MACSTR, MAC2STR(sta->addr)); - if (hapd->sta_authorized_cb) - hapd->sta_authorized_cb(hapd->sta_authorized_cb_ctx, - sta->addr, authorized, dev_addr); - if (authorized) { char ip_addr[100]; ip_addr[0] = '\0'; @@ -1183,6 +1179,11 @@ void ap_sta_set_authorized(struct hostapd_data *hapd, struct sta_info *sta, AP_STA_DISCONNECTED "%s", buf); } + if (hapd->sta_authorized_cb) + hapd->sta_authorized_cb(hapd->sta_authorized_cb_ctx, + sta->addr, authorized, dev_addr, + ip_addr_buf); + #ifdef CONFIG_FST if (hapd->iface->fst) { if (authorized) diff --git a/src/p2p/p2p.c b/src/p2p/p2p.c index cd2fba3..b61661b 100644 --- a/src/p2p/p2p.c +++ b/src/p2p/p2p.c @@ -5018,6 +5018,25 @@ p2p_get_peer_found(struct p2p_data *p2p, const u8 *addr, int next) } +void p2p_set_peer_ip_addr(struct p2p_data *p2p, const u8 *dev_addr, + const u8 *ip_addr) +{ + struct p2p_device *dev; + + if (!p2p || !dev_addr) + return; + + dev = p2p_get_device(p2p, dev_addr); + if (!dev) + return; + + if (ip_addr) + os_memcpy(dev->info.ip_addr, ip_addr, 4); + else + os_memset(dev->info.ip_addr, 0, 4); +} + + int p2p_in_progress(struct p2p_data *p2p) { if (p2p == NULL) diff --git a/src/p2p/p2p.h b/src/p2p/p2p.h index 7b18dcf..87c2711 100644 --- a/src/p2p/p2p.h +++ b/src/p2p/p2p.h @@ -402,6 +402,11 @@ struct p2p_peer_info { * p2ps_instance - P2PS Application Service Info */ struct wpabuf *p2ps_instance; + + /** + * ip_addr - IP address assigned during 4-way handshake + */ + u8 ip_addr[4]; }; enum p2p_prov_disc_status { @@ -2191,6 +2196,15 @@ const struct p2p_peer_info * p2p_get_peer_found(struct p2p_data *p2p, const u8 *addr, int next); /** + * p2p_set_peer_ip_addr - Set P2P peer IP address in info structure + * @p2p: P2P module context from p2p_init() + * @dev_addr: P2P Device Address of the peer + * @ip_addr: IP address of the peer + */ +void p2p_set_peer_ip_addr(struct p2p_data *p2p, const u8 *dev_addr, + const u8 *ip_addr); + +/** * p2p_remove_wps_vendor_extensions - Remove WPS vendor extensions * @p2p: P2P module context from p2p_init() */ diff --git a/wpa_supplicant/ap.c b/wpa_supplicant/ap.c index 5afb772..7e02eee 100644 --- a/wpa_supplicant/ap.c +++ b/wpa_supplicant/ap.c @@ -521,9 +521,11 @@ static void ap_wps_event_cb(void *ctx, enum wps_event event, static void ap_sta_authorized_cb(void *ctx, const u8 *mac_addr, - int authorized, const u8 *p2p_dev_addr) + int authorized, const u8 *p2p_dev_addr, + const u8 *ip_addr) { - wpas_notify_sta_authorized(ctx, mac_addr, authorized, p2p_dev_addr); + wpas_notify_sta_authorized(ctx, mac_addr, authorized, p2p_dev_addr, + ip_addr); } diff --git a/wpa_supplicant/dbus/dbus_new.c b/wpa_supplicant/dbus/dbus_new.c index 69fb8f4..ac6012c 100644 --- a/wpa_supplicant/dbus/dbus_new.c +++ b/wpa_supplicant/dbus/dbus_new.c @@ -3800,6 +3800,11 @@ static const struct wpa_dbus_property_desc wpas_dbus_p2p_peer_properties[] = { NULL, NULL }, + { "IpAddress", WPAS_DBUS_NEW_IFACE_P2P_PEER, "ay", + wpas_dbus_getter_p2p_peer_ip_address, + NULL, + NULL + }, { NULL, NULL, NULL, NULL, NULL, NULL } }; diff --git a/wpa_supplicant/dbus/dbus_new_handlers_p2p.c b/wpa_supplicant/dbus/dbus_new_handlers_p2p.c index f50420b..098adaf 100644 --- a/wpa_supplicant/dbus/dbus_new_handlers_p2p.c +++ b/wpa_supplicant/dbus/dbus_new_handlers_p2p.c @@ -1903,6 +1903,26 @@ out: } +dbus_bool_t wpas_dbus_getter_p2p_peer_ip_address( + const struct wpa_dbus_property_desc *property_desc, + DBusMessageIter *iter, DBusError *error, void *user_data) +{ + struct peer_handler_args *peer_args = user_data; + const struct p2p_peer_info *info; + + info = p2p_get_peer_found(peer_args->wpa_s->global->p2p, + peer_args->p2p_device_addr, 0); + if (!info) { + dbus_set_error(error, DBUS_ERROR_FAILED, + "failed to find peer"); + return FALSE; + } + + return wpas_dbus_simple_array_property_getter( + iter, DBUS_TYPE_BYTE, (char *) info->ip_addr, 4, error); +} + + /** * wpas_dbus_getter_persistent_groups - Get array of persistent group objects * @iter: Pointer to incoming dbus message iter diff --git a/wpa_supplicant/dbus/dbus_new_handlers_p2p.h b/wpa_supplicant/dbus/dbus_new_handlers_p2p.h index c4c0261..374dbec 100644 --- a/wpa_supplicant/dbus/dbus_new_handlers_p2p.h +++ b/wpa_supplicant/dbus/dbus_new_handlers_p2p.h @@ -114,6 +114,7 @@ DECLARE_ACCESSOR(wpas_dbus_getter_p2p_peer_vendor_extension); DECLARE_ACCESSOR(wpas_dbus_getter_p2p_peer_ies); DECLARE_ACCESSOR(wpas_dbus_getter_p2p_peer_device_address); DECLARE_ACCESSOR(wpas_dbus_getter_p2p_peer_groups); +DECLARE_ACCESSOR(wpas_dbus_getter_p2p_peer_ip_address); /* * P2P Group properties diff --git a/wpa_supplicant/notify.c b/wpa_supplicant/notify.c index f9c119a..e1b3ba7 100644 --- a/wpa_supplicant/notify.c +++ b/wpa_supplicant/notify.c @@ -707,10 +707,11 @@ void wpas_notify_p2p_invitation_received(struct wpa_supplicant *wpa_s, static void wpas_notify_ap_sta_authorized(struct wpa_supplicant *wpa_s, const u8 *sta, - const u8 *p2p_dev_addr) + const u8 *p2p_dev_addr, + const u8 *ip_addr) { #ifdef CONFIG_P2P - wpas_p2p_notify_ap_sta_authorized(wpa_s, p2p_dev_addr); + wpas_p2p_notify_ap_sta_authorized(wpa_s, p2p_dev_addr, ip_addr); /* * Create 'peer-joined' signal on group object -- will also @@ -734,8 +735,10 @@ static void wpas_notify_ap_sta_deauthorized(struct wpa_supplicant *wpa_s, * Create 'peer-disconnected' signal on group object if this * is a P2P group. */ - if (p2p_dev_addr) + if (p2p_dev_addr) { + p2p_set_peer_ip_addr(wpa_s->global->p2p, p2p_dev_addr, NULL); wpas_dbus_signal_p2p_peer_disconnected(wpa_s, p2p_dev_addr); + } #endif /* CONFIG_P2P */ /* Notify listeners a station has been deauthorized */ @@ -745,10 +748,11 @@ static void wpas_notify_ap_sta_deauthorized(struct wpa_supplicant *wpa_s, void wpas_notify_sta_authorized(struct wpa_supplicant *wpa_s, const u8 *mac_addr, int authorized, - const u8 *p2p_dev_addr) + const u8 *p2p_dev_addr, const u8 *ip_addr) { if (authorized) - wpas_notify_ap_sta_authorized(wpa_s, mac_addr, p2p_dev_addr); + wpas_notify_ap_sta_authorized(wpa_s, mac_addr, p2p_dev_addr, + ip_addr); else wpas_notify_ap_sta_deauthorized(wpa_s, mac_addr, p2p_dev_addr); } diff --git a/wpa_supplicant/notify.h b/wpa_supplicant/notify.h index e4d7fbf..18880be 100644 --- a/wpa_supplicant/notify.h +++ b/wpa_supplicant/notify.h @@ -85,7 +85,7 @@ void wpas_notify_resume(struct wpa_global *global); void wpas_notify_sta_authorized(struct wpa_supplicant *wpa_s, const u8 *mac_addr, int authorized, - const u8 *p2p_dev_addr); + const u8 *p2p_dev_addr, const u8 *ip_addr); void wpas_notify_p2p_find_stopped(struct wpa_supplicant *wpa_s); void wpas_notify_p2p_device_found(struct wpa_supplicant *wpa_s, const u8 *dev_addr, int new_device); diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c index 25e7419..d5a9877 100644 --- a/wpa_supplicant/p2p_supplicant.c +++ b/wpa_supplicant/p2p_supplicant.c @@ -7761,8 +7761,11 @@ struct wpa_ssid * wpas_p2p_get_persistent(struct wpa_supplicant *wpa_s, void wpas_p2p_notify_ap_sta_authorized(struct wpa_supplicant *wpa_s, - const u8 *addr) + const u8 *addr, const u8 *ip_addr) { + if (ip_addr) + p2p_set_peer_ip_addr(wpa_s->global->p2p, addr, ip_addr); + if (eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s->p2pdev, NULL) > 0) { /* diff --git a/wpa_supplicant/p2p_supplicant.h b/wpa_supplicant/p2p_supplicant.h index 63910d1..2e45e2f 100644 --- a/wpa_supplicant/p2p_supplicant.h +++ b/wpa_supplicant/p2p_supplicant.h @@ -140,7 +140,7 @@ struct wpa_ssid * wpas_p2p_get_persistent(struct wpa_supplicant *wpa_s, const u8 *addr, const u8 *ssid, size_t ssid_len); void wpas_p2p_notify_ap_sta_authorized(struct wpa_supplicant *wpa_s, - const u8 *addr); + const u8 *addr, const u8 *ip_addr); int wpas_p2p_scan_no_go_seen(struct wpa_supplicant *wpa_s); int wpas_p2p_get_ht40_mode(struct wpa_supplicant *wpa_s, struct hostapd_hw_modes *mode, u8 channel); -- 1.9.1 -- Jouni Malinen PGP id EFC895FA _______________________________________________ Hostap mailing list Hostap@xxxxxxxxxxxxxxxxxxx http://lists.infradead.org/mailman/listinfo/hostap