[PATCH 1/5] gsupplicant: Regroup a function for readability

2014-08-28 Thread Tomasz Bursztyka
Just a minor issue, g_supplicant_interface_is_p2p_finding() was not
declared along with other g_supplicant_interface_* functions.
---
 gsupplicant/gsupplicant.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gsupplicant/gsupplicant.h b/gsupplicant/gsupplicant.h
index 28cfe10..fc595b7 100644
--- a/gsupplicant/gsupplicant.h
+++ b/gsupplicant/gsupplicant.h
@@ -267,6 +267,7 @@ int 
g_supplicant_interface_set_p2p_device_config(GSupplicantInterface *interface
const char *device_name);
 GSupplicantPeer *g_supplicant_interface_peer_lookup(GSupplicantInterface 
*interface,
const char *identifier);
+bool g_supplicant_interface_is_p2p_finding(GSupplicantInterface *interface);
 
 /* Network and Peer API */
 struct _GSupplicantNetwork;
@@ -300,7 +301,6 @@ bool g_supplicant_peer_is_wps_pin(GSupplicantPeer *peer);
 bool g_supplicant_peer_is_in_a_group(GSupplicantPeer *peer);
 GSupplicantInterface *g_supplicant_peer_get_group_interface(GSupplicantPeer 
*peer);
 bool g_supplicant_peer_is_client(GSupplicantPeer *peer);
-bool g_supplicant_interface_is_p2p_finding(GSupplicantInterface *interface);
 
 struct _GSupplicantCallbacks {
void (*system_ready) (void);
-- 
1.8.5.5

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


[PATCH 0/5] Incoming connection support

2014-08-28 Thread Tomasz Bursztyka
These patches implement the incoming connection request handling, from
gsupplicant's signal to the Agent API and it's support in the client.

Tomasz Bursztyka (5):
  gsupplicant: Regroup a function for readability
  gsupplicant: Add GONegociationRequest signal handler
  agent: Fix Peer authorization reply WPS choice handling logic
  peer: Add a function forward incoming connection to the agent
  client: Support agent incoming Peer authorization request

 client/agent.c| 52 +++
 gsupplicant/gsupplicant.h |  3 ++-
 gsupplicant/supplicant.c  | 35 +++
 include/peer.h|  1 +
 plugins/wifi.c| 19 +
 src/agent-connman.c   |  2 +-
 src/peer.c| 11 +-
 7 files changed, 120 insertions(+), 3 deletions(-)

-- 
1.8.5.5

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


[PATCH 5/5] client: Support agent incoming Peer authorization request

2014-08-28 Thread Tomasz Bursztyka
Thus it is possible to accept or reject an incoming peer connection.
---
 client/agent.c | 52 
 plugins/wifi.c | 19 +++
 2 files changed, 71 insertions(+)

diff --git a/client/agent.c b/client/agent.c
index 5a1b944..d020889 100644
--- a/client/agent.c
+++ b/client/agent.c
@@ -589,6 +589,42 @@ static DBusMessage *agent_request_input(DBusConnection 
*connection,
return NULL;
 }
 
+static void request_authorization_return(char *input, void *user_data)
+{
+   struct agent_data *request = user_data;
+
+   switch (confirm_input(input)) {
+   case 1:
+   request-reply = dbus_message_new_method_return(
+   request-message);
+   dbus_message_iter_init_append(request-reply, request-iter);
+
+   dbus_message_iter_open_container(request-iter,
+   DBUS_TYPE_ARRAY,
+   DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+   DBUS_TYPE_STRING_AS_STRING
+   DBUS_TYPE_VARIANT_AS_STRING
+   DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
+   request-dict);
+   dbus_message_iter_close_container(request-iter,
+   request-dict);
+   g_dbus_send_message(agent_connection, request-reply);
+   request-reply = NULL;
+   break;
+   case 0:
+g_dbus_send_error(agent_connection, request-message,
+net.connman.Agent.Error.Rejected, NULL);
+break;
+   default:
+g_dbus_send_error(agent_connection, request-message,
+net.connman.Agent.Error.Canceled, NULL);
+break;
+   }
+
+   pending_message_remove(request);
+   pending_command_complete();
+}
+
 static DBusMessage *
 agent_request_peer_authorization(DBusConnection *connection,
DBusMessage *message, void *user_data)
@@ -596,6 +632,8 @@ agent_request_peer_authorization(DBusConnection *connection,
struct agent_data *request = user_data;
DBusMessageIter iter, dict;
char *peer, *str;
+   bool input;
+   int i;
 
if (handle_message(message, request, agent_request_peer_authorization)
== false)
@@ -616,6 +654,20 @@ agent_request_peer_authorization(DBusConnection 
*connection,
 
parse_agent_request(request, iter);
 
+   for (input = false, i = 0; request-input[i].attribute; i++) {
+   if (request-input[i].requested == true) {
+   input = true;
+   break;
+   }
+   }
+
+   if (!input) {
+   request-message = dbus_message_ref(message);
+   __connmanctl_agent_mode(Accept connection (yes/no)? ,
+   request_authorization_return, request);
+   return NULL;
+   }
+
request-reply = dbus_message_new_method_return(message);
dbus_message_iter_init_append(request-reply, request-iter);
 
diff --git a/plugins/wifi.c b/plugins/wifi.c
index f5af702..be58bf6 100644
--- a/plugins/wifi.c
+++ b/plugins/wifi.c
@@ -2439,6 +2439,24 @@ static void peer_changed(GSupplicantPeer *peer,
connman_peer_set_state(connman_peer, p_state);
 }
 
+static void peer_request(GSupplicantPeer *peer)
+{
+   GSupplicantInterface *iface = g_supplicant_peer_get_interface(peer);
+   struct wifi_data *wifi = g_supplicant_interface_get_data(iface);
+   struct connman_peer *connman_peer;
+   const char *identifier;
+
+   identifier = g_supplicant_peer_get_identifier(peer);
+
+   DBG(ident: %s, identifier);
+
+   connman_peer = connman_peer_get(wifi-device, identifier);
+   if (!connman_peer)
+   return;
+
+   connman_peer_request_connection(connman_peer);
+}
+
 static void debug(const char *str)
 {
if (getenv(CONNMAN_SUPPLICANT_DEBUG))
@@ -2460,6 +2478,7 @@ static const GSupplicantCallbacks callbacks = {
.peer_found = peer_found,
.peer_lost  = peer_lost,
.peer_changed   = peer_changed,
+   .peer_request   = peer_request,
.debug  = debug,
 };
 
-- 
1.8.5.5

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


[PATCH 4/5] peer: Add a function forward incoming connection to the agent

2014-08-28 Thread Tomasz Bursztyka
This let's the incoming connection being handled through the agent. If
no agent is present, nothing will happen and the incoming connection
request will be ignored.
---
 include/peer.h |  1 +
 src/peer.c | 11 ++-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/include/peer.h b/include/peer.h
index dd118cd..2463066 100644
--- a/include/peer.h
+++ b/include/peer.h
@@ -67,6 +67,7 @@ void connman_peer_set_sub_device(struct connman_peer *peer,
 void connman_peer_set_as_master(struct connman_peer *peer, bool master);
 int connman_peer_set_state(struct connman_peer *peer,
enum connman_peer_state new_state);
+int connman_peer_request_connection(struct connman_peer *peer);
 
 int connman_peer_register(struct connman_peer *peer);
 void connman_peer_unregister(struct connman_peer *peer);
diff --git a/src/peer.c b/src/peer.c
index 866a9ac..7e733d3 100644
--- a/src/peer.c
+++ b/src/peer.c
@@ -493,7 +493,9 @@ static void request_authorization_cb(struct connman_peer 
*peer,
 
if (error) {
if (g_strcmp0(error,
-   net.connman.Agent.Error.Canceled) == 0) {
+   net.connman.Agent.Error.Canceled) == 0 ||
+   g_strcmp0(error,
+   net.connman.Agent.Error.Rejected) == 0) {
err = -EINVAL;
goto out;
}
@@ -828,6 +830,13 @@ int connman_peer_set_state(struct connman_peer *peer,
return 0;
 }
 
+int connman_peer_request_connection(struct connman_peer *peer)
+{
+   return __connman_agent_request_peer_authorization(peer,
+   request_authorization_cb, false,
+   NULL, NULL);
+}
+
 static void peer_up(struct connman_ipconfig *ipconfig, const char *ifname)
 {
DBG(%s up, ifname);
-- 
1.8.5.5

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


[PATCH 2/5 v2] gsupplicant: Add GONegociationRequest signal handler

2014-08-28 Thread Tomasz Bursztyka
This will be necessary to handle incoming connection request. Wifi
plugin will have to bring the necessary callback to forward this request
to the core Peer Agent API where the user will be able to accept or
reject the connection.
---
 gsupplicant/gsupplicant.h |  1 +
 gsupplicant/supplicant.c  | 35 +++
 2 files changed, 36 insertions(+)

diff --git a/gsupplicant/gsupplicant.h b/gsupplicant/gsupplicant.h
index fc595b7..5ad88b0 100644
--- a/gsupplicant/gsupplicant.h
+++ b/gsupplicant/gsupplicant.h
@@ -319,6 +319,7 @@ struct _GSupplicantCallbacks {
void (*peer_lost) (GSupplicantPeer *peer);
void (*peer_changed) (GSupplicantPeer *peer,
GSupplicantPeerGroupState state);
+   void (*peer_request) (GSupplicantPeer *peer);
void (*debug) (const char *str);
 };
 
diff --git a/gsupplicant/supplicant.c b/gsupplicant/supplicant.c
index dbae8d5..049a5b2 100644
--- a/gsupplicant/supplicant.c
+++ b/gsupplicant/supplicant.c
@@ -508,6 +508,17 @@ static void callback_peer_changed(GSupplicantPeer *peer,
callbacks_pointer-peer_changed(peer, state);
 }
 
+static void callback_peer_request(GSupplicantPeer *peer)
+{
+   if (!callbacks_pointer)
+   return;
+
+   if (!callbacks_pointer-peer_request)
+   return;
+
+   callbacks_pointer-peer_request(peer);
+}
+
 static void remove_group(gpointer data)
 {
GSupplicantGroup *group = data;
@@ -2880,6 +2891,29 @@ static void signal_group_finished(const char *path, 
DBusMessageIter *iter)
g_hash_table_remove(interface-group_table, data.group_obj_path);
 }
 
+static void signal_group_request(const char *path, DBusMessageIter *iter)
+{
+   GSupplicantInterface *interface;
+   GSupplicantPeer *peer;
+   const char *obj_path;
+
+   SUPPLICANT_DBG();
+
+   interface = g_hash_table_lookup(interface_table, path);
+   if (!interface)
+   return;
+
+   dbus_message_iter_get_basic(iter, obj_path);
+   if (!obj_path || !g_strcmp0(obj_path, /))
+   return;
+
+   peer = g_hash_table_lookup(interface-peer_table, obj_path);
+   if (!peer)
+   return;
+
+   callback_peer_request(peer);
+}
+
 static void signal_group_peer_joined(const char *path, DBusMessageIter *iter)
 {
const char *peer_path = NULL;
@@ -2979,6 +3013,7 @@ static struct {
{ SUPPLICANT_INTERFACE .Interface.P2PDevice, GONegotiationFailure, 
signal_group_failure },
{ SUPPLICANT_INTERFACE .Interface.P2PDevice, GroupStarted, 
signal_group_started },
{ SUPPLICANT_INTERFACE .Interface.P2PDevice, GroupFinished, 
signal_group_finished },
+   { SUPPLICANT_INTERFACE .Interface.P2PDevice, GONegotiationRequest, 
signal_group_request },
 
{ SUPPLICANT_INTERFACE .Group, PeerJoined, signal_group_peer_joined 
},
{ SUPPLICANT_INTERFACE .Group, PeerDisconnected, 
signal_group_peer_disconnected },
-- 
1.8.5.5

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


[PATCH 4/8] network: Remove unused function connman_network_clear_error()

2014-08-28 Thread Patrik Flykt
---
 include/network.h |  1 -
 src/network.c | 16 
 2 files changed, 17 deletions(-)

diff --git a/include/network.h b/include/network.h
index fcb6905..d772699 100644
--- a/include/network.h
+++ b/include/network.h
@@ -96,7 +96,6 @@ int connman_network_set_associating(struct connman_network 
*network,
bool associating);
 void connman_network_set_error(struct connman_network *network,
enum connman_network_error error);
-void connman_network_clear_error(struct connman_network *network);
 int connman_network_set_connected(struct connman_network *network,
bool connected);
 bool connman_network_get_connected(struct connman_network *network);
diff --git a/src/network.c b/src/network.c
index d65f7ac..5beca2f 100644
--- a/src/network.c
+++ b/src/network.c
@@ -1392,22 +1392,6 @@ void connman_network_set_error(struct connman_network 
*network,
network_change(network);
 }
 
-void connman_network_clear_error(struct connman_network *network)
-{
-   struct connman_service *service;
-
-   DBG(network %p, network);
-
-   if (!network)
-   return;
-
-   if (network-connecting || network-associating)
-   return;
-
-   service = connman_service_lookup_from_network(network);
-   __connman_service_clear_error(service);
-}
-
 /**
  * connman_network_set_connected:
  * @network: network structure
-- 
1.9.1

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


[PATCH 6/8] service: Clean up the passphrase setting logic

2014-08-28 Thread Patrik Flykt
Clean up the function not to take a service argument as it is no
longer used. Drop the indentation by checking first for error.
---
 src/service.c | 29 ++---
 1 file changed, 14 insertions(+), 15 deletions(-)

diff --git a/src/service.c b/src/service.c
index 8131093..d8465dc 100644
--- a/src/service.c
+++ b/src/service.c
@@ -2821,9 +2821,8 @@ void __connman_service_set_agent_identity(struct 
connman_service *service,
service-agent_identity);
 }
 
-static int check_passphrase(struct connman_service *service,
-   enum connman_service_security security,
-   const char *passphrase)
+static int check_passphrase(enum connman_service_security security,
+   const char *passphrase)
 {
guint i;
gsize length;
@@ -2883,25 +2882,25 @@ static void service_clear_passphrase(struct 
connman_service *service)
 int __connman_service_set_passphrase(struct connman_service *service,
const char *passphrase)
 {
-   int err = 0;
+   int err;
 
if (service-immutable || service-hidden)
return -EINVAL;
 
-   err = check_passphrase(service, service-security, passphrase);
+   err = check_passphrase(service-security, passphrase);
 
-   if (err == 0) {
-   g_free(service-passphrase);
-   service-passphrase = g_strdup(passphrase);
+   if (err  0)
+   return err;
 
-   if (service-network)
-   connman_network_set_string(service-network,
-   WiFi.Passphrase,
-   service-passphrase);
-   service_save(service);
-   }
+   g_free(service-passphrase);
+   service-passphrase = g_strdup(passphrase);
 
-   return err;
+   if (service-network)
+   connman_network_set_string(service-network, WiFi.Passphrase,
+   service-passphrase);
+   service_save(service);
+
+   return 0;
 }
 
 const char *__connman_service_get_passphrase(struct connman_service *service)
-- 
1.9.1

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


[PATCH 7/8] service: Use proper function when setting service Passphrase attribute

2014-08-28 Thread Patrik Flykt
Instead of directly changing the passphrase, use
__connman_service_set_passphrase() which does the passphrase sanity
checking.
---
 src/service.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/src/service.c b/src/service.c
index d8465dc..78eb13c 100644
--- a/src/service.c
+++ b/src/service.c
@@ -4965,10 +4965,8 @@ void __connman_service_set_string(struct connman_service 
*service,
} else if (g_str_equal(key, Phase2)) {
g_free(service-phase2);
service-phase2 = g_strdup(value);
-   } else if (g_str_equal(key, Passphrase)) {
-   g_free(service-passphrase);
-   service-passphrase = g_strdup(value);
-   }
+   } else if (g_str_equal(key, Passphrase))
+   __connman_service_set_passphrase(service, value);
 }
 
 void __connman_service_set_search_domains(struct connman_service *service,
-- 
1.9.1

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


[PATCH 0/8] Code cleanups

2014-08-28 Thread Patrik Flykt

Hi,

Here is a set of cleanup patches. The first four are not supposed to
change any functionality but instead provide a bit better readability
in the code.

The four later ones are also not supposed to change any functionality,
but they are far more invasive than the first four ones as they relate
to passphrase handling.

Please review,

   Patrik


Patrik Flykt (8):
  service: Clean up multiple if statements with a case statement
  service: Clean up two consecutive if statements.
  service: Clean up  __connman_service_ipconfig_indicate_state()
  network: Remove unused function connman_network_clear_error()
  service: Make a specifig function for clearing a passphrase on error
  service: Clean up the passphrase setting logic
  service: Use proper function when setting service Passphrase attribute
  service: Remove __connman_service_add_passphrase()

 include/network.h |   1 -
 src/connman.h |   2 -
 src/network.c |  18 +
 src/service.c | 200 --
 4 files changed, 104 insertions(+), 117 deletions(-)

-- 
1.9.1

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


[PATCH 8/8] service: Remove __connman_service_add_passphrase()

2014-08-28 Thread Patrik Flykt
Merge the logic in __connman_service_add_passphrase into the
passphrase verification function as there is no use of an additional
function indirection.
---
 src/connman.h |  2 --
 src/network.c |  2 +-
 src/service.c | 40 +++-
 3 files changed, 12 insertions(+), 32 deletions(-)

diff --git a/src/connman.h b/src/connman.h
index 9fecb28..4262d2e 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -95,8 +95,6 @@ struct connman_peer;
 
 void __connman_agent_cancel(struct connman_service *service);
 
-int __connman_service_add_passphrase(struct connman_service *service,
-   const gchar *passphrase);
 typedef void (* authentication_cb_t) (struct connman_service *service,
bool values_received,
const char *name, int name_len,
diff --git a/src/network.c b/src/network.c
index 5beca2f..d3ad83b 100644
--- a/src/network.c
+++ b/src/network.c
@@ -1480,7 +1480,7 @@ int connman_network_connect_hidden(struct connman_network 
*network,
__connman_service_set_agent_identity(service, identity);
 
if (passphrase)
-   err = __connman_service_add_passphrase(service, passphrase);
+   err = __connman_service_set_passphrase(service, passphrase);
 
if (err == -ENOKEY) {
__connman_service_indicate_error(service,
diff --git a/src/service.c b/src/service.c
index 78eb13c..f87bf09 100644
--- a/src/service.c
+++ b/src/service.c
@@ -2833,9 +2833,17 @@ static int check_passphrase(enum 
connman_service_security security,
length = strlen(passphrase);
 
switch (security) {
-   case CONNMAN_SERVICE_SECURITY_PSK:
+   case CONNMAN_SERVICE_SECURITY_UNKNOWN:
+   case CONNMAN_SERVICE_SECURITY_NONE:
case CONNMAN_SERVICE_SECURITY_WPA:
case CONNMAN_SERVICE_SECURITY_RSN:
+
+   DBG(service security '%s' (%d) not handled,
+   security2string(security), security);
+
+   return -EOPNOTSUPP;
+
+   case CONNMAN_SERVICE_SECURITY_PSK:
/* A raw key is always 64 bytes length,
 * its content is in hex representation.
 * A PSK key must be between [8..63].
@@ -2860,8 +2868,7 @@ static int check_passphrase(enum connman_service_security 
security,
} else if (length != 5  length != 13)
return -ENOKEY;
break;
-   case CONNMAN_SERVICE_SECURITY_UNKNOWN:
-   case CONNMAN_SERVICE_SECURITY_NONE:
+
case CONNMAN_SERVICE_SECURITY_8021X:
break;
}
@@ -5029,31 +5036,6 @@ static void report_error_cb(void *user_context, bool 
retry,
}
 }
 
-int __connman_service_add_passphrase(struct connman_service *service,
-   const gchar *passphrase)
-{
-   int err = 0;
-
-   switch (service-security) {
-   case CONNMAN_SERVICE_SECURITY_WEP:
-   case CONNMAN_SERVICE_SECURITY_PSK:
-   case CONNMAN_SERVICE_SECURITY_8021X:
-   err = __connman_service_set_passphrase(service, passphrase);
-   break;
-
-   case CONNMAN_SERVICE_SECURITY_UNKNOWN:
-   case CONNMAN_SERVICE_SECURITY_NONE:
-   case CONNMAN_SERVICE_SECURITY_WPA:
-   case CONNMAN_SERVICE_SECURITY_RSN:
-   DBG(service security '%s' (%d) not handled,
-   security2string(service-security),
-   service-security);
-   break;
-   }
-
-   return err;
-}
-
 static int check_wpspin(struct connman_service *service, const char *wpspin)
 {
int length;
@@ -5147,7 +5129,7 @@ static void request_input_cb(struct connman_service 
*service,
__connman_service_set_agent_identity(service, identity);
 
if (passphrase)
-   err = __connman_service_add_passphrase(service, passphrase);
+   err = __connman_service_set_passphrase(service, passphrase);
 
  done:
if (err = 0) {
-- 
1.9.1

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


[PATCH 5/8] service: Make a specifig function for clearing a passphrase on error

2014-08-28 Thread Patrik Flykt
On error clear the passphrase without saving it permanently. This makes
it safe to reuse the passphrase checking function elsewhere as there
will not be any unintended side effects when the service is favorite.
---
 src/service.c | 24 +---
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/src/service.c b/src/service.c
index f5c0a23..8131093 100644
--- a/src/service.c
+++ b/src/service.c
@@ -2828,16 +2828,8 @@ static int check_passphrase(struct connman_service 
*service,
guint i;
gsize length;
 
-   if (!passphrase) {
-   /*
-* This will prevent __connman_service_set_passphrase() to
-* wipe the passphrase out in case of -ENOKEY error for a
-* favorite service. */
-   if (service-favorite)
-   return 1;
-   else
-   return 0;
-   }
+   if (!passphrase)
+   return 0;
 
length = strlen(passphrase);
 
@@ -2878,6 +2870,16 @@ static int check_passphrase(struct connman_service 
*service,
return 0;
 }
 
+static void service_clear_passphrase(struct connman_service *service)
+{
+   g_free(service-passphrase);
+   service-passphrase = NULL;
+
+   if (service-network)
+   connman_network_set_string(service-network, WiFi.Passphrase,
+   service-passphrase);
+}
+
 int __connman_service_set_passphrase(struct connman_service *service,
const char *passphrase)
 {
@@ -5485,7 +5487,7 @@ int __connman_service_indicate_error(struct 
connman_service *service,
 */
if (service-error == CONNMAN_SERVICE_ERROR_INVALID_KEY ||
service-security == CONNMAN_SERVICE_SECURITY_8021X)
-   __connman_service_set_passphrase(service, NULL);
+   service_clear_passphrase(service);
 
__connman_service_set_agent_identity(service, NULL);
 
-- 
1.9.1

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


[PATCH 3/8] service: Clean up __connman_service_ipconfig_indicate_state()

2014-08-28 Thread Patrik Flykt
Clean up the function by first doing a proper switch statement and
setting up a pointer to the ipconfig and state. Reuse the pointers
when setting the new state instead of comparing the method once again.
---
 src/service.c | 52 ++--
 1 file changed, 30 insertions(+), 22 deletions(-)

diff --git a/src/service.c b/src/service.c
index fde3e00..f5c0a23 100644
--- a/src/service.c
+++ b/src/service.c
@@ -5691,29 +5691,39 @@ int __connman_service_ipconfig_indicate_state(struct 
connman_service *service,
enum connman_ipconfig_type type)
 {
struct connman_ipconfig *ipconfig = NULL;
-   enum connman_service_state old_state;
+   enum connman_service_state *old_state;
enum connman_ipconfig_method method;
 
if (!service)
return -EINVAL;
 
-   if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
-   old_state = service-state_ipv4;
+   switch (type) {
+   case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
+   return -EINVAL;
+
+   case CONNMAN_IPCONFIG_TYPE_IPV4:
+   old_state = service-state_ipv4;
ipconfig = service-ipconfig_ipv4;
-   } else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) {
-   old_state = service-state_ipv6;
+
+   break;
+
+   case CONNMAN_IPCONFIG_TYPE_IPV6:
+   old_state = service-state_ipv6;
ipconfig = service-ipconfig_ipv6;
+
+   break;
}
 
if (!ipconfig)
return -EINVAL;
 
/* Any change? */
-   if (old_state == new_state)
+   if (*old_state == new_state)
return -EALREADY;
 
-   DBG(service %p (%s) state %d (%s) type %d (%s),
+   DBG(service %p (%s) old state %d (%s) new state %d (%s) type %d (%s),
service, service ? service-identifier : NULL,
+   *old_state, state2string(*old_state),
new_state, state2string(new_state),
type, __connman_ipconfig_type2string(type));
 
@@ -5752,25 +5762,23 @@ int __connman_service_ipconfig_indicate_state(struct 
connman_service *service,
   the state to IDLE so that it will not affect the combined state
   in the future.
 */
-   if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
-   method = __connman_ipconfig_get_method(service-ipconfig_ipv4);
-
-   if (method == CONNMAN_IPCONFIG_METHOD_OFF ||
-   method == CONNMAN_IPCONFIG_METHOD_UNKNOWN)
-   new_state = CONNMAN_SERVICE_STATE_IDLE;
-
-   service-state_ipv4 = new_state;
-
-   } else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) {
-   method = __connman_ipconfig_get_method(service-ipconfig_ipv6);
+   method = __connman_ipconfig_get_method(ipconfig);
+   switch (method) {
+   case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
+   case CONNMAN_IPCONFIG_METHOD_OFF:
+   new_state = CONNMAN_SERVICE_STATE_IDLE;
+   break;
 
-   if (method == CONNMAN_IPCONFIG_METHOD_OFF ||
-   method == CONNMAN_IPCONFIG_METHOD_UNKNOWN)
-   new_state = CONNMAN_SERVICE_STATE_IDLE;
+   case CONNMAN_IPCONFIG_METHOD_FIXED:
+case CONNMAN_IPCONFIG_METHOD_MANUAL:
+case CONNMAN_IPCONFIG_METHOD_DHCP:
+case CONNMAN_IPCONFIG_METHOD_AUTO:
+   break;
 
-   service-state_ipv6 = new_state;
}
 
+   *old_state = new_state;
+
update_nameservers(service);
 
return service_indicate_state(service);
-- 
1.9.1

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


[PATCH 2/8] service: Clean up two consecutive if statements.

2014-08-28 Thread Patrik Flykt
These two ifs can be combined into one.
---
 src/service.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/src/service.c b/src/service.c
index d65443c..fde3e00 100644
--- a/src/service.c
+++ b/src/service.c
@@ -4005,10 +4005,8 @@ static DBusMessage *disconnect_service(DBusConnection 
*conn,
service-ignore = true;
 
err = __connman_service_disconnect(service);
-   if (err  0) {
-   if (err != -EINPROGRESS)
-   return __connman_error_failed(msg, -err);
-   }
+   if (err  0  err != -EINPROGRESS)
+   return __connman_error_failed(msg, -err);
 
return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
 }
-- 
1.9.1

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


Re: [PATCH 0/2] Solve issues in pending wifi data

2014-08-28 Thread Patrik Flykt
On Wed, 2014-08-20 at 07:06 -0400, Eduardo Abinader wrote:
 The following patchset addresses other midst situation,
 when a p2p group is being negotiated and, for some reason,
 p2p interface is removed. Added an extra check and 
 provided a proper cleanup of pending wifi device list, 
 upon wifi remove.

And applied, finally. Thanks for reminding!

Patrik


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


Re: [PATCH 0/5] Incoming connection support

2014-08-28 Thread Patrik Flykt
On Thu, 2014-08-28 at 09:18 +0300, Tomasz Bursztyka wrote:
 These patches implement the incoming connection request handling, from
 gsupplicant's signal to the Agent API and it's support in the client.

Ok, I was quite quick and applied patches 1-4 from this set. Please
resend only patch 5/5 split up into two independent parts.

Cheers,

Patrik

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


[PATCH 0/6 v2] P2P Incoming connection support

2014-08-28 Thread Tomasz Bursztyka
Tomasz Bursztyka (6):
  gsupplicant: Regroup a function for readability
  gsupplicant: Add GONegociationRequest signal handler
  agent: Fix Peer authorization reply WPS choice handling logic
  peer: Add a function forward incoming connection to the agent
  wifi: Forward the incoming P2P connection request to the core
  client: Support agent incoming Peer authorization request

 client/agent.c| 52 +++
 gsupplicant/gsupplicant.h |  3 ++-
 gsupplicant/supplicant.c  | 35 +++
 include/peer.h|  1 +
 plugins/wifi.c| 19 +
 src/agent-connman.c   |  2 +-
 src/peer.c| 11 +-
 7 files changed, 120 insertions(+), 3 deletions(-)

-- 
1.8.5.5

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


[PATCH 1/6] gsupplicant: Regroup a function for readability

2014-08-28 Thread Tomasz Bursztyka
Just a minor issue, g_supplicant_interface_is_p2p_finding() was not
declared along with other g_supplicant_interface_* functions.
---
 gsupplicant/gsupplicant.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gsupplicant/gsupplicant.h b/gsupplicant/gsupplicant.h
index 28cfe10..fc595b7 100644
--- a/gsupplicant/gsupplicant.h
+++ b/gsupplicant/gsupplicant.h
@@ -267,6 +267,7 @@ int 
g_supplicant_interface_set_p2p_device_config(GSupplicantInterface *interface
const char *device_name);
 GSupplicantPeer *g_supplicant_interface_peer_lookup(GSupplicantInterface 
*interface,
const char *identifier);
+bool g_supplicant_interface_is_p2p_finding(GSupplicantInterface *interface);
 
 /* Network and Peer API */
 struct _GSupplicantNetwork;
@@ -300,7 +301,6 @@ bool g_supplicant_peer_is_wps_pin(GSupplicantPeer *peer);
 bool g_supplicant_peer_is_in_a_group(GSupplicantPeer *peer);
 GSupplicantInterface *g_supplicant_peer_get_group_interface(GSupplicantPeer 
*peer);
 bool g_supplicant_peer_is_client(GSupplicantPeer *peer);
-bool g_supplicant_interface_is_p2p_finding(GSupplicantInterface *interface);
 
 struct _GSupplicantCallbacks {
void (*system_ready) (void);
-- 
1.8.5.5

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


[PATCH 4/6] peer: Add a function forward incoming connection to the agent

2014-08-28 Thread Tomasz Bursztyka
This let's the incoming connection being handled through the agent. If
no agent is present, nothing will happen and the incoming connection
request will be ignored.
---
 include/peer.h |  1 +
 src/peer.c | 11 ++-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/include/peer.h b/include/peer.h
index dd118cd..2463066 100644
--- a/include/peer.h
+++ b/include/peer.h
@@ -67,6 +67,7 @@ void connman_peer_set_sub_device(struct connman_peer *peer,
 void connman_peer_set_as_master(struct connman_peer *peer, bool master);
 int connman_peer_set_state(struct connman_peer *peer,
enum connman_peer_state new_state);
+int connman_peer_request_connection(struct connman_peer *peer);
 
 int connman_peer_register(struct connman_peer *peer);
 void connman_peer_unregister(struct connman_peer *peer);
diff --git a/src/peer.c b/src/peer.c
index 866a9ac..7e733d3 100644
--- a/src/peer.c
+++ b/src/peer.c
@@ -493,7 +493,9 @@ static void request_authorization_cb(struct connman_peer 
*peer,
 
if (error) {
if (g_strcmp0(error,
-   net.connman.Agent.Error.Canceled) == 0) {
+   net.connman.Agent.Error.Canceled) == 0 ||
+   g_strcmp0(error,
+   net.connman.Agent.Error.Rejected) == 0) {
err = -EINVAL;
goto out;
}
@@ -828,6 +830,13 @@ int connman_peer_set_state(struct connman_peer *peer,
return 0;
 }
 
+int connman_peer_request_connection(struct connman_peer *peer)
+{
+   return __connman_agent_request_peer_authorization(peer,
+   request_authorization_cb, false,
+   NULL, NULL);
+}
+
 static void peer_up(struct connman_ipconfig *ipconfig, const char *ifname)
 {
DBG(%s up, ifname);
-- 
1.8.5.5

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


[PATCH 6/6] client: Support agent incoming Peer authorization request

2014-08-28 Thread Tomasz Bursztyka
Thus it is possible to accept or reject an incoming peer connection.
---
 client/agent.c | 52 
 1 file changed, 52 insertions(+)

diff --git a/client/agent.c b/client/agent.c
index 5a1b944..d020889 100644
--- a/client/agent.c
+++ b/client/agent.c
@@ -589,6 +589,42 @@ static DBusMessage *agent_request_input(DBusConnection 
*connection,
return NULL;
 }
 
+static void request_authorization_return(char *input, void *user_data)
+{
+   struct agent_data *request = user_data;
+
+   switch (confirm_input(input)) {
+   case 1:
+   request-reply = dbus_message_new_method_return(
+   request-message);
+   dbus_message_iter_init_append(request-reply, request-iter);
+
+   dbus_message_iter_open_container(request-iter,
+   DBUS_TYPE_ARRAY,
+   DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+   DBUS_TYPE_STRING_AS_STRING
+   DBUS_TYPE_VARIANT_AS_STRING
+   DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
+   request-dict);
+   dbus_message_iter_close_container(request-iter,
+   request-dict);
+   g_dbus_send_message(agent_connection, request-reply);
+   request-reply = NULL;
+   break;
+   case 0:
+g_dbus_send_error(agent_connection, request-message,
+net.connman.Agent.Error.Rejected, NULL);
+break;
+   default:
+g_dbus_send_error(agent_connection, request-message,
+net.connman.Agent.Error.Canceled, NULL);
+break;
+   }
+
+   pending_message_remove(request);
+   pending_command_complete();
+}
+
 static DBusMessage *
 agent_request_peer_authorization(DBusConnection *connection,
DBusMessage *message, void *user_data)
@@ -596,6 +632,8 @@ agent_request_peer_authorization(DBusConnection *connection,
struct agent_data *request = user_data;
DBusMessageIter iter, dict;
char *peer, *str;
+   bool input;
+   int i;
 
if (handle_message(message, request, agent_request_peer_authorization)
== false)
@@ -616,6 +654,20 @@ agent_request_peer_authorization(DBusConnection 
*connection,
 
parse_agent_request(request, iter);
 
+   for (input = false, i = 0; request-input[i].attribute; i++) {
+   if (request-input[i].requested == true) {
+   input = true;
+   break;
+   }
+   }
+
+   if (!input) {
+   request-message = dbus_message_ref(message);
+   __connmanctl_agent_mode(Accept connection (yes/no)? ,
+   request_authorization_return, request);
+   return NULL;
+   }
+
request-reply = dbus_message_new_method_return(message);
dbus_message_iter_init_append(request-reply, request-iter);
 
-- 
1.8.5.5

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


[PATCH 3/6] agent: Fix Peer authorization reply WPS choice handling logic

2014-08-28 Thread Tomasz Bursztyka
If WPS details were not requested, whatever valid reply is a valid
choice for accepting the request.
---
 src/agent-connman.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/agent-connman.c b/src/agent-connman.c
index f3d1bc4..b2049a3 100644
--- a/src/agent-connman.c
+++ b/src/agent-connman.c
@@ -710,7 +710,7 @@ static void request_peer_authorization_reply(DBusMessage 
*reply,
dbus_message_iter_next(dict);
}
 
-   if (auth_reply-wps_requested)
+   if (!auth_reply-wps_requested)
choice_done = true;
 
 done:
-- 
1.8.5.5

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


Re: [PATCH 0/6 v2] P2P Incoming connection support

2014-08-28 Thread Patrik Flykt
On Thu, 2014-08-28 at 15:30 +0300, Tomasz Bursztyka wrote:
 Tomasz Bursztyka (6):
   gsupplicant: Regroup a function for readability
   gsupplicant: Add GONegociationRequest signal handler
   agent: Fix Peer authorization reply WPS choice handling logic
   peer: Add a function forward incoming connection to the agent
   wifi: Forward the incoming P2P connection request to the core
   client: Support agent incoming Peer authorization request

Patches 5/6 and 6/6 applied, 1-4 got already applied from your earlier
set. Thanks!

Patrik

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


[PATCH] peer: Add debug msg for peer state

2014-08-28 Thread Eduardo Abinader
In order to ease the debug task of peer state changes, inserted
this old state/new state track.
---
 src/peer.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/peer.c b/src/peer.c
index 7e733d3..d5d7c8e 100644
--- a/src/peer.c
+++ b/src/peer.c
@@ -786,6 +786,9 @@ int connman_peer_set_state(struct connman_peer *peer,
enum connman_peer_state old_state = peer-state;
int err;
 
+   DBG(peer (%s) old state %d new state %d, peer-name,
+   old_state, new_state);
+
if (old_state == new_state)
return -EALREADY;
 
-- 
1.9.1

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