[PATCH v2 2/3] Add assigned EAPOL IP Address in peer properties.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

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                         |  5 +++--
 wpa_supplicant/dbus/dbus_new.c              | 13 ++++++++++++-
 wpa_supplicant/dbus/dbus_new.h              |  2 +-
 wpa_supplicant/dbus/dbus_new_handlers_p2p.c | 21 +++++++++++++++++++++
 wpa_supplicant/dbus/dbus_new_handlers_p2p.h |  1 +
 wpa_supplicant/notify.c                     |  9 +++++----
 wpa_supplicant/notify.h                     |  2 +-
 11 files changed, 85 insertions(+), 15 deletions(-)

diff --git a/src/ap/hostapd.h b/src/ap/hostapd.h
index fd5aaed..d3cf650 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);
 	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..4095768 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, };
 
 	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..f37233a 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_address(struct p2p_data *p2p, const u8 *addr,
+			     const u8 *ip)
+{
+	struct p2p_device *dev;
+
+	if (!p2p || !addr)
+		return;
+
+	dev = p2p_get_device(p2p, addr);
+	if (!dev)
+		return;
+
+	if (ip)
+		os_memcpy(dev->info.ip_address, ip, 4);
+	else
+		os_memset(dev->info.ip_address, 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..6402045 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_address - IP Address assigned using EAPOL
+	 */
+	u8 ip_address[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_address - Set P2P peer ip address in info structure
+ * @p2p: P2P module context from p2p_init()
+ * @addr: P2P Device Address of the peer
+ * @ip: IP address of peer
+ */
+void p2p_set_peer_ip_address(struct p2p_data *p2p, const u8 *addr,
+			     const u8 *ip);
+
+/**
  * 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..600903f 100644
--- a/wpa_supplicant/ap.c
+++ b/wpa_supplicant/ap.c
@@ -521,9 +521,10 @@ 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)
 {
-	wpas_notify_sta_authorized(ctx, mac_addr, authorized, p2p_dev_addr);
+	wpas_notify_sta_authorized(ctx, mac_addr, authorized, p2p_dev_addr, ip);
 }
 
 
diff --git a/wpa_supplicant/dbus/dbus_new.c b/wpa_supplicant/dbus/dbus_new.c
index 27b3012..509406c 100644
--- a/wpa_supplicant/dbus/dbus_new.c
+++ b/wpa_supplicant/dbus/dbus_new.c
@@ -1480,9 +1480,10 @@ void wpas_dbus_signal_p2p_invitation_result(struct wpa_supplicant *wpa_s,
  *
  * @wpa_s: %wpa_supplicant network interface data
  * @peer_addr: P2P Device Address of the peer joining the group
+ * @ip: ip address assigned to peer.
  */
 void wpas_dbus_signal_p2p_peer_joined(struct wpa_supplicant *wpa_s,
-				      const u8 *peer_addr)
+				      const u8 *peer_addr, const u8 *ip)
 {
 	struct wpas_dbus_priv *iface;
 	DBusMessage *msg;
@@ -1516,6 +1517,9 @@ void wpas_dbus_signal_p2p_peer_joined(struct wpa_supplicant *wpa_s,
 	if (msg == NULL)
 		return;
 
+	if (ip)
+		p2p_set_peer_ip_address(wpa_s->global->p2p, peer_addr, ip);
+
 	dbus_message_iter_init_append(msg, &iter);
 	path = peer_obj_path;
 	if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
@@ -1573,6 +1577,8 @@ void wpas_dbus_signal_p2p_peer_disconnected(struct wpa_supplicant *wpa_s,
 	if (msg == NULL)
 		return;
 
+	p2p_set_peer_ip_address(wpa_s->global->p2p, peer_addr, NULL);
+
 	dbus_message_iter_init_append(msg, &iter);
 	path = peer_obj_path;
 	if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
@@ -3790,6 +3796,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.h b/wpa_supplicant/dbus/dbus_new.h
index d64fcee..c2eea13 100644
--- a/wpa_supplicant/dbus/dbus_new.h
+++ b/wpa_supplicant/dbus/dbus_new.h
@@ -215,7 +215,7 @@ void wpas_dbus_signal_p2p_sd_response(struct wpa_supplicant *wpa_s,
 				      const u8 *sa, u16 update_indic,
 				      const u8 *tlvs, size_t tlvs_len);
 void wpas_dbus_signal_p2p_peer_joined(struct wpa_supplicant *wpa_s,
-				const u8 *member);
+				      const u8 *member, const u8 *ip);
 void wpas_dbus_signal_p2p_wps_failed(struct wpa_supplicant *wpa_s,
 				     struct wps_event_fail *fail);
 void wpas_dbus_signal_certification(struct wpa_supplicant *wpa_s,
diff --git a/wpa_supplicant/dbus/dbus_new_handlers_p2p.c b/wpa_supplicant/dbus/dbus_new_handlers_p2p.c
index a84dbd8..23bcd26 100644
--- a/wpa_supplicant/dbus/dbus_new_handlers_p2p.c
+++ b/wpa_supplicant/dbus/dbus_new_handlers_p2p.c
@@ -1905,6 +1905,27 @@ 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 == NULL) {
+		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_address,
+		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 67e36ae..435c0a1 100644
--- a/wpa_supplicant/notify.c
+++ b/wpa_supplicant/notify.c
@@ -707,7 +707,8 @@ 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)
 {
 #ifdef CONFIG_P2P
 	wpas_p2p_notify_ap_sta_authorized(wpa_s, p2p_dev_addr);
@@ -717,7 +718,7 @@ static void wpas_notify_ap_sta_authorized(struct wpa_supplicant *wpa_s,
 	 * check P2P itself.
 	 */
 	if (p2p_dev_addr)
-		wpas_dbus_signal_p2p_peer_joined(wpa_s, p2p_dev_addr);
+		wpas_dbus_signal_p2p_peer_joined(wpa_s, p2p_dev_addr, ip);
 #endif /* CONFIG_P2P */
 
 	/* Notify listeners a new station has been authorized */
@@ -745,10 +746,10 @@ 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)
 {
 	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);
 	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 8cce0f3..59aa126 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);
 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);
-- 
1.9.1


_______________________________________________
Hostap mailing list
Hostap@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/hostap



[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux