Re: [PATCH 05/16] agent: Provide a function for the Peer RequestPeerAuthorization call

2014-08-06 Thread Patrik Flykt

Hi,

On Wed, 2014-08-06 at 13:29 +0300, Tomasz Bursztyka wrote:
 This will be used by peer.c when there will be a need to choose between
 WPS PBC or PIN. This choice will be raised to the user via an agent
 RequestPeerAuthorization call.
 ---
  src/agent-connman.c | 167 
 ++--
  src/connman.h   |   8 +++
  2 files changed, 158 insertions(+), 17 deletions(-)
 
 diff --git a/src/agent-connman.c b/src/agent-connman.c
 index 7502f0f..f7a7f3a 100644
 --- a/src/agent-connman.c
 +++ b/src/agent-connman.c
 @@ -55,8 +55,15 @@ static bool check_reply_has_dict(DBusMessage *reply)
  }
  
  struct request_input_reply {
 - struct connman_service *service;
 - authentication_cb_t callback;
 + union {
 + struct connman_service *service;
 + struct connman_peer *peer;
 + };
 + union {
 + authentication_cb_t service_callback;
 + peer_wps_cb_t peer_callback;
 + };
 + bool wps_requested;
   void *user_data;
  };
  
 @@ -151,12 +158,10 @@ static void request_input_passphrase_reply(DBusMessage 
 *reply, void *user_data)
   }
  
  done:
 - passphrase_reply-callback(passphrase_reply-service, values_received,
 - name, name_len,
 - identity, passphrase,
 - wps, wpspin, error,
 - passphrase_reply-user_data);
 -
 + passphrase_reply-service_callback(passphrase_reply-service,
 + values_received, name, name_len,
 + identity, passphrase, wps, wpspin,
 + error, passphrase_reply-user_data);
  out:
   g_free(passphrase_reply);
  }
 @@ -236,13 +241,21 @@ static void 
 request_input_append_passphrase(DBusMessageIter *iter,
   }
  }
  
 +struct request_wps_data {
 + bool peer;
 +};
 +
  static void request_input_append_wps(DBusMessageIter *iter, void *user_data)
  {
 + struct request_wps_data *wps = user_data;
   const char *str = wpspin;
  
   connman_dbus_dict_append_basic(iter, Type,
   DBUS_TYPE_STRING, str);
 - str = alternate;
 + if (wps  wps-peer)

Since the peer and service pointers are grouped together in a union and
therefore share the same space in the struct, won't WPS always become
mandatory also for every service?

 + str = mandatory;
 + else
 + str = alternate;
   connman_dbus_dict_append_basic(iter, Requirement,
   DBUS_TYPE_STRING, str);
  }

Cheers,

Patrik

___
connman mailing list
connman@connman.net
https://lists.connman.net/mailman/listinfo/connman


Re: [PATCH 05/16] agent: Provide a function for the Peer RequestPeerAuthorization call

2014-08-06 Thread Tomasz Bursztyka

Hi Patrik,


+struct request_wps_data {
+   bool peer;
+};
+
  static void request_input_append_wps(DBusMessageIter *iter, void *user_data)
  {
+   struct request_wps_data *wps = user_data;
const char *str = wpspin;
  
  	connman_dbus_dict_append_basic(iter, Type,

DBUS_TYPE_STRING, str);
-   str = alternate;
+   if (wps  wps-peer)

Since the peer and service pointers are grouped together in a union and
therefore share the same space in the struct, won't WPS always become
mandatory also for every service?


Indeed. Attached the new version of this patch (my git send-email fails 
currently, for whatever reason).


Tomasz
From 111e93054497a2e86cdc79fa63b89dc5e25fb6bf Mon Sep 17 00:00:00 2001
From: Tomasz Bursztyka tomasz.burszt...@linux.intel.com
Date: Fri, 25 Jul 2014 14:43:54 +0300
Subject: [PATCH 05/16] agent: Provide a function for the Peer
 RequestPeerAuthorization call

This will be used by peer.c when there will be a need to choose between
WPS PBC or PIN. This choice will be raised to the user via an agent
RequestPeerAuthorization call.
---

Removed the union on peer/service

 src/agent-connman.c | 163 ++--
 src/connman.h   |   8 +++
 2 files changed, 155 insertions(+), 16 deletions(-)

diff --git a/src/agent-connman.c b/src/agent-connman.c
index 7502f0f..f3d1bc4 100644
--- a/src/agent-connman.c
+++ b/src/agent-connman.c
@@ -56,7 +56,12 @@ static bool check_reply_has_dict(DBusMessage *reply)
 
 struct request_input_reply {
 	struct connman_service *service;
-	authentication_cb_t callback;
+	struct connman_peer *peer;
+	union {
+		authentication_cb_t service_callback;
+		peer_wps_cb_t peer_callback;
+	};
+	bool wps_requested;
 	void *user_data;
 };
 
@@ -151,12 +156,10 @@ static void request_input_passphrase_reply(DBusMessage *reply, void *user_data)
 	}
 
 done:
-	passphrase_reply-callback(passphrase_reply-service, values_received,
-name, name_len,
-identity, passphrase,
-wps, wpspin, error,
-passphrase_reply-user_data);
-
+	passphrase_reply-service_callback(passphrase_reply-service,
+	values_received, name, name_len,
+	identity, passphrase, wps, wpspin,
+	error, passphrase_reply-user_data);
 out:
 	g_free(passphrase_reply);
 }
@@ -236,13 +239,21 @@ static void request_input_append_passphrase(DBusMessageIter *iter,
 	}
 }
 
+struct request_wps_data {
+	bool peer;
+};
+
 static void request_input_append_wps(DBusMessageIter *iter, void *user_data)
 {
+	struct request_wps_data *wps = user_data;
 	const char *str = wpspin;
 
 	connman_dbus_dict_append_basic(iter, Type,
 DBUS_TYPE_STRING, str);
-	str = alternate;
+	if (wps  wps-peer)
+		str = mandatory;
+	else
+		str = alternate;
 	connman_dbus_dict_append_basic(iter, Requirement,
 DBUS_TYPE_STRING, str);
 }
@@ -399,12 +410,10 @@ static void request_input_login_reply(DBusMessage *reply, void *user_data)
 	}
 
 done:
-	username_password_reply-callback(username_password_reply-service,
-	values_received, NULL, 0,
-	username, password,
-	FALSE, NULL, error,
-	username_password_reply-user_data);
-
+	username_password_reply-service_callback(
+			username_password_reply-service, values_received,
+			NULL, 0, username, password, FALSE, NULL, error,
+			username_password_reply-user_data);
 out:
 	g_free(username_password_reply);
 }
@@ -477,7 +486,7 @@ int __connman_agent_request_passphrase_input(struct connman_service *service,
 	}
 
 	passphrase_reply-service = service;
-	passphrase_reply-callback = callback;
+	passphrase_reply-service_callback = callback;
 	passphrase_reply-user_data = user_data;
 
 	err = connman_agent_queue_message(service, message,
@@ -542,7 +551,7 @@ int __connman_agent_request_login_input(struct connman_service *service,
 	}
 
 	username_password_reply-service = service;
-	username_password_reply-callback = callback;
+	username_password_reply-service_callback = callback;
 	username_password_reply-user_data = user_data;
 
 	err = connman_agent_queue_message(service, message,
@@ -654,3 +663,125 @@ int __connman_agent_report_peer_error(struct connman_peer *peer,
 	return connman_agent_report_error_full(peer, path, ReportPeerError,
 error, callback, dbus_sender, user_data);
 }
+
+static void request_peer_authorization_reply(DBusMessage *reply,
+			void *user_data)
+{
+	struct request_input_reply *auth_reply = user_data;
+	DBusMessageIter iter, dict;
+	const char *error = NULL;
+	bool choice_done = false;
+	char *wpspin = NULL;
+	char *key;
+
+	if (!reply)
+		goto out;
+
+	if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) {
+		error = dbus_message_get_error_name(reply);
+		goto done;
+	}
+
+	if (!check_reply_has_dict(reply))
+		goto done;
+
+	dbus_message_iter_init(reply, iter);
+	dbus_message_iter_recurse(iter, dict);
+	while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) {
+		DBusMessageIter entry, value;
+
+		dbus_message_iter_recurse(dict, entry);
+