[PATCH 2/7] p2p: Add a utility to run a callback on all available groups

Tomasz Bursztyka tomasz.bursztyka at linux.intel.com
Mon Jun 2 10:42:03 EDT 2014


This will be useful in wpa_supplicant to match group's ssids against a
specific one.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka at linux.intel.com>
---
 src/p2p/p2p.h       | 13 +++++++++++++
 src/p2p/p2p_group.c | 17 +++++++++++++++++
 2 files changed, 30 insertions(+)

diff --git a/src/p2p/p2p.h b/src/p2p/p2p.h
index 3c11a45..6c399a0 100644
--- a/src/p2p/p2p.h
+++ b/src/p2p/p2p.h
@@ -1800,6 +1800,19 @@ int p2p_group_is_client_connected(struct p2p_group *group, const u8 *dev_addr);
 const struct p2p_group_config *p2p_group_get_config(struct p2p_group *group);
 
 /**
+ * p2p_loop_on_all_group - Run the given callback on all groups
+ * @p2p: P2P module context from p2p_init()
+ * @group_callback: The callback function pointer
+ * @user_data: Some user data pointer which can be %NULL
+ * Returns: Once the group list has been entirely gone through or when the
+ * callback has returned 0.
+ */
+void p2p_loop_on_all_group(struct p2p_data *p2p,
+			   int (*group_callback) (struct p2p_group *group,
+						  void *user_data),
+			   void *user_data);
+
+/**
  * p2p_get_peer_found - Get P2P peer info structure of a found peer
  * @p2p: P2P module context from p2p_init()
  * @addr: P2P Device Address of the peer or %NULL to indicate the first peer
diff --git a/src/p2p/p2p_group.c b/src/p2p/p2p_group.c
index 07ce655..2f8565b 100644
--- a/src/p2p/p2p_group.c
+++ b/src/p2p/p2p_group.c
@@ -1019,3 +1019,20 @@ const struct p2p_group_config *p2p_group_get_config(struct p2p_group *group)
 {
 	return group->cfg;
 }
+
+
+void p2p_loop_on_all_group(struct p2p_data *p2p,
+			   int (*group_callback) (struct p2p_group *,
+						  void *),
+			   void *user_data)
+{
+	int i;
+
+	if (group_callback == NULL)
+		return;
+
+	for (i = 0; i < p2p->num_groups; i++) {
+		if (!group_callback(p2p->groups[i], user_data))
+			break;
+	}
+}
-- 
1.8.5.5



More information about the HostAP mailing list