Re: [PATCH] gsupplicant: Add/remove a dbus match which connman interested

2014-08-01 Thread Tomasz Bursztyka

Hi,


+++ b/gsupplicant/supplicant.c
@@ -4804,6 +4804,8 @@ static const char *g_supplicant_rule5 = type=signal,
interface= SUPPLICANT_INTERFACE .Network;
  static const char *g_supplicant_rule6 = type=signal,
interface= SUPPLICANT_INTERFACE .Interface.P2PDevice;
+static const char *g_supplicant_rule7 = type=signal,
+   interface= SUPPLICANT_INTERFACE .Peer;


I have a patch for this already, when I'll enable the one-to-many context.
(yes, signal handlers are there, but we don't catch those signals on 
purpose).

That's why .Group signals have handlers but are not caught as well.


@@ -4898,6 +4901,8 @@ void g_supplicant_unregister(const GSupplicantCallbacks 
*callbacks)
SUPPLICANT_DBG();
  
  	if (connection) {

+   dbus_bus_remove_match(connection, g_supplicant_rule7, NULL);
+   dbus_bus_remove_match(connection, g_supplicant_rule6, NULL);


Here you are fixing a bug, so resend a patch fixing this rule removal.

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


Re: [PATCH 1/5] gsupplicant: Add an helper to know if a peer is connected as client or not

2014-08-01 Thread leonew

Hi Tomasz,

I met a wifi direct issue when use latest connman.

I'm not sure whether I catch your point, if I'm wrong , please correct 
me, thanks:-)


This patch seem that connman will use peer's */Group/* member to check 
whether local side is GC.
and peer's group will updata when peer property changed, and it may come 
after group started signal arrival,

so here will get a wrong role. you can find it in attached log.

In my case, local side is GC, but connman start a dhcp server :(

On 07/17/2014 07:00 PM, Tomasz Bursztyka wrote:

+bool g_supplicant_peer_is_client(GSupplicantPeer *peer)
+{
+   GSupplicantGroup *group;
+   GSList *list;
+
+   if (!peer)
+   return false;
+
+   for (list = peer-groups; list; list = list-next) {
+   group = list-data;
+

Whether we need consider the case peer-groups= NULL?

+   if (group-role != G_SUPPLICANT_GROUP_ROLE_CLIENT ||
+   group-orig_interface != peer-interface)
+   continue;
+
+   if (group-interface == peer-current_group_iface)
+   return true;
+   }
+
+   return false;
+}
+


connmand[4448]: gsupplicant/supplicant.c:signal_group_started() 
connmand[4448]: plugins/wifi.c:peer_changed() ident: 2208eddaee3e
connmand[4448]: plugins/wifi.c:peer_changed() name: HUAWEI, state 1
connmand[4448]: src/peer.c:connman_peer_unref_debug() 0x8bfc250 ref 1 by plugins/wifi.c:200:peer_cancel_timeout()
connmand[4448]: gsupplicant/supplicant.c:g_supplicant_peer_is_client() peer 0x8c02570
connmand[4448]: gsupplicant/supplicant.c:g_supplicant_peer_is_client() peer-groups (nil)
connmand[4448]: plugins/wifi.c:peer_changed() local side client 0
connmand[4448]: gsupplicant/supplicant.c:g_supplicant_peer_is_client() peer 0x8c02570
connmand[4448]: gsupplicant/supplicant.c:g_supplicant_peer_is_client() peer-groups (nil)
connmand[4448]: src/peer.c:start_dhcp_server() 
connmand[4448]: src/ippool.c:__connman_ippool_create() 
connmand[4448]: src/inet.c:__connman_inet_modify_address() cmd 0x14 flags 0x104 index 3 family 2 address 192.168.0.1 peer (null) prefixlen 24 broadcast 192.168.0.255
connmand[4448]: Peer DHCP server: option_code 1 option_value 255.255.255.0
connmand[4448]: Peer DHCP server: option_code 3 option_value 192.168.0.1
connmand[4448]: src/peer.c:connman_peer_ref_debug() 0x8bfc250 ref 2 by src/peer.c:143:start_dhcp_server()
connmand[4448]: src/rtnl.c:rtnl_message() buf 0xbffa42d0 len 60
connmand[4448]: src/rtnl.c:rtnl_message() NEWADDR len 60 type 20 flags 0x seq 1 pid -4737
connmand[4448]: src/ipconfig.c:__connman_ipconfig_newaddr() index 3
connmand[4448]: wlan0 {add} address 192.168.0.1/24 label wlan0 family 2
connmand[4448]: src/rtnl.c:rtnl_message() buf 0xbffa42d0 len 60
connmand[4448]: src/rtnl.c:rtnl_message() NEWROUTE len 60 type 24 flags 0x seq 0 pid 0
connmand[4448]: src/rtnl.c:rtnl_message() buf 0xbffa42d0 len 60
connmand[4448]: src/rtnl.c:rtnl_message() NEWROUTE len 60 type 24 flags 0x seq 0 pid 0
connmand[4448]: src/rtnl.c:rtnl_message() buf 0xbffa42d0 len 60
connmand[4448]: src/rtnl.c:rtnl_message() NEWROUTE len 60 type 24 flags 0x seq 0 pid 0
connmand[4448]: src/ipconfig.c:__connman_ipconfig_newroute() index 3
connmand[4448]: wlan0 {add} route 192.168.0.0 gw 0.0.0.0 scope 253 LINK
connmand[4448]: src/rtnl.c:rtnl_message() buf 0xbffa42d0 len 60
connmand[4448]: src/rtnl.c:rtnl_message() NEWROUTE len 60 type 24 flags 0x seq 0 pid 0
connmand[4448]: gsupplicant/supplicant.c:signal_interface_changed() 
connmand[4448]: gsupplicant/supplicant.c:interface_property() State
connmand[4448]: plugins/wifi.c:interface_state() wifi 0x8bf0468 interface state 10
connmand[4448]: gsupplicant/supplicant.c:interface_property() state completed (10)
connmand[4448]: gsupplicant/supplicant.c:interface_property() CurrentAuthMode
connmand[4448]: gsupplicant/supplicant.c:interface_property() key CurrentAuthMode type s
connmand[4448]: gsupplicant/supplicant.c:signal_peer_changed() 
connmand[4448]: gsupplicant/supplicant.c:peer_property() key: Groups
connmand[4448]: gsupplicant/supplicant.c:peer_property() key: Groups
connmand[4448]: gsupplicant/supplicant.c:peer_property() key: Groups, signal ao
connmand[4448]: gsupplicant/supplicant.c:peer_property() 97
connmand[4448]: gsupplicant/supplicant.c:peer_groups_relation() 
connmand[4448]: gsupplicant/supplicant.c:peer_groups_relation() str: /fi/w1/wpa_supplicant1/Interfaces/1/Groups/SE
connmand[4448]: gsupplicant/supplicant.c:peer_groups_relation() group: 0x8bf6720
connmand[4448]: gsupplicant/supplicant.c:peer_groups_relation() peer-group: 0x8bff3e0

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

Re: Routing problem

2014-08-01 Thread G
2014-07-24 23:22 GMT+02:00 Jukka Rissanen jukka.rissa...@gmail.com:

 Hi,

 On 24 July 2014 10:21, G i...@asidev.com wrote:
  Hi folks,
  I have a strange bahaviour using connman 1.20

 If possible try to upgrade to latest release (1.24), it fixes lot of
 bugs, although probably does not fix your issue.



Hi Jukka,
sorry for this late reply, I do some more test using 1.24, below the results

SCENARIO
a device with an ethernet card and a wifi card, both with DHCP (same
server, so same subnet with different metric); ethernet card get also a
static configured ip

* WITH ETHERNET CABLE CONNECTED *

IP LINK
1: LO: LOOPBACK,UP,LOWER_UP MTU 16436 QDISC NOQUEUE STATE UNKNOWN
LINK/LOOPBACK 00:00:00:00:00:00 BRD 00:00:00:00:00:00
2: ETH0: BROADCAST,MULTICAST,DYNAMIC,UP,LOWER_UP MTU 1500 QDISC
PFIFO_FAST STATE UP QLEN 1000
LINK/ETHER 00:21:84:30:03:78 BRD FF:FF:FF:FF:FF:FF
3: WLAN0: BROADCAST,MULTICAST,UP,LOWER_UP MTU 1500 Q

IP ADDR
1: LO: LOOPBACK,UP,LOWER_UP MTU 16436 QDISC NOQUEUE STATE UNKNOWN
LINK/LOOPBACK 00:00:00:00:00:00 BRD 00:00:00:00:00:00
INET 127.0.0.1/8 SCOPE HOST LO
2: ETH0: BROADCAST,MULTICAST,DYNAMIC,UP,LOWER_UP MTU 1500 QDISC
PFIFO_FAST STATE UP QLEN 1000
LINK/ETHER 00:21:84:30:03:78 BRD FF:FF:FF:FF:FF:FF
INET 10.189.189.1/24 SCOPE GLOBAL ETH0-- this one is static
INET 192.168.10.102/24 BRD 192.168.10.255 SCOPE GLOBAL ETH0
3: WLAN0: BROADCAST,MULTICAST,UP,LOWER_UP MTU 1500 QDISC MQ STATE UP QLEN
1000
LINK/ETHER 00:21:84:26:01:84 BRD FF:FF:FF:FF:FF:FF
INET 192.168.10.106/24 BRD 192.168.10.255 SCOPE GLOBAL WLAN0

IP ROUTE
192.168.10.100 VIA 192.168.10.100 DEV ETH0
192.168.10.100 DEV ETH0  SCOPE LINK
192.168.10.100 DEV WLAN0  SCOPE LINK  METRIC 10
10.189.189.0/24 DEV ETH0  PROTO KERNEL  SCOPE LINK  SRC 10.189.189.1
192.168.10.0/24 DEV ETH0  PROTO KERNEL  SCOPE LINK  SRC 192.168.10.102
192.168.10.0/24 DEV WLAN0  PROTO KERNEL  SCOPE LINK  SRC 192.168.10.106
METRIC 10
224.0.0.0/24 DEV ETH0  SCOPE LINK
DEFAULT VIA 192.168.10.100 DEV ETH0

IP ROUTE GET 192.168.10.10
192.168.10.10 DEV ETH0  SRC 192.168.10.102
CACHE  MTU 1500 ADVMSS 1460 HOPLIMIT 64

Everything it's ok

 DISCONNECTING ETHERNET CABLE *

IP LINK
1: LO: LOOPBACK,UP,LOWER_UP MTU 16436 QDISC NOQUEUE STATE UNKNOWN
LINK/LOOPBACK 00:00:00:00:00:00 BRD 00:00:00:00:00:00
2: ETH0: NO-CARRIER,BROADCAST,MULTICAST,DYNAMIC,UP MTU 1500 QDISC
PFIFO_FAST STATE DOWN QLEN 1000
LINK/ETHER 00:21:84:30:03:78 BRD FF:FF:FF:FF:FF:FF
3: WLAN0: BROADCAST,MULTICAST,UP,LOWER_UP MTU 1500 QDI

IP ADDR
1: LO: LOOPBACK,UP,LOWER_UP MTU 16436 QDISC NOQUEUE STATE UNKNOWN
LINK/LOOPBACK 00:00:00:00:00:00 BRD 00:00:00:00:00:00
INET 127.0.0.1/8 SCOPE HOST LO
2: ETH0: NO-CARRIER,BROADCAST,MULTICAST,DYNAMIC,UP MTU 1500 QDISC
PFIFO_FAST STATE DOWN QLEN 1000
LINK/ETHER 00:21:84:30:03:78 BRD FF:FF:FF:FF:FF:FF
INET 10.189.189.1/24 SCOPE GLOBAL ETH0
3: WLAN0: BROADCAST,MULTICAST,UP,LOWER_UP MTU 1500 QDISC MQ STATE UP QLEN
1000
LINK/ETHER 00:21:84:26:01:84 BRD FF:FF:FF:FF:FF:FF
INET 192.168.10.106/24 BRD 192.168.10.255 SCOPE GLOBAL WLAN0

IP ROUTE
192.168.10.100 DEV ETH0  SCOPE LINK
192.168.10.100 DEV WLAN0  SCOPE LINK  METRIC 10
10.189.189.0/24 DEV ETH0  PROTO KERNEL  SCOPE LINK  SRC 10.189.189.1
192.168.10.0/24 DEV WLAN0  PROTO KERNEL  SCOPE LINK  SRC 192.168.10.106
METRIC 10
224.0.0.0/24 DEV ETH0  SCOPE LINK
DEFAULT VIA 192.168.10.100 DEV WLAN0

IP ROUTE GET 192.168.10.10
192.168.10.10 DEV WLAN0  SRC 192.168.10.106
CACHE  MTU 1500 ADVMSS 1460 HOPLIMIT 64

As you can see from output above

1) after disconnecting eth0 the ip get by DHCP disappear and the link
became down
2) the static configured IP remains
3) in the routing table a wrong route (192.168.10.100 DEV ETH0  SCOPE LINK)
is present
4) checking the real routing with ip route get shows a correct path (via
the connected wlan)

So now things works (I can ping 192.168.10.10 via wlan, with connman 1.20
this didn't work) but the wrong route is still present

2 questions
1) How can I remove the wrong route from routing table?
2) why, with this wrong route in place with a lower metric, ip route get
shows a correct path?

Cheers

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


Re: [PATCH] gsupplicant: Add/remove a dbus match which connman interested

2014-08-01 Thread leonew

On 08/01/2014 05:23 PM, Tomasz Bursztyka wrote:

Hi,


+++ b/gsupplicant/supplicant.c
@@ -4804,6 +4804,8 @@ static const char *g_supplicant_rule5 = 
type=signal,

  interface= SUPPLICANT_INTERFACE .Network;
  static const char *g_supplicant_rule6 = type=signal,
  interface= SUPPLICANT_INTERFACE .Interface.P2PDevice;
+static const char *g_supplicant_rule7 = type=signal,
+interface= SUPPLICANT_INTERFACE .Peer;


I have a patch for this already, when I'll enable the one-to-many 
context.
(yes, signal handlers are there, but we don't catch those signals on 
purpose).

That's why .Group signals have handlers but are not caught as well.


very glad to hear that.
@@ -4898,6 +4901,8 @@ void g_supplicant_unregister(const 
GSupplicantCallbacks *callbacks)

  SUPPLICANT_DBG();
if (connection) {
+dbus_bus_remove_match(connection, g_supplicant_rule7, NULL);
+dbus_bus_remove_match(connection, g_supplicant_rule6, NULL);


Here you are fixing a bug, so resend a patch fixing this rule removal.


OK, I will resend a patch to fix it.


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


[PATCH] Fix UTF-8 ssid's

2014-08-01 Thread Lorn Potter

I found an old patch that crashed, and fixed it up.
Enjoy!

---
 gsupplicant/supplicant.c |   20 
 1 file changed, 20 insertions(+)

diff --git a/gsupplicant/supplicant.c b/gsupplicant/supplicant.c
index 534944b..19dbb1a 100644
--- a/gsupplicant/supplicant.c
+++ b/gsupplicant/supplicant.c
@@ -1256,6 +1256,26 @@ static void 
interface_network_removed(DBusMessageIter *iter, void *user_data)


 static char *create_name(unsigned char *ssid, int ssid_len)
 {
+   SUPPLICANT_DBG(%s, %i, ssid, ssid_len)
+
+   gchar *result;
+   GError *error = 0;
+   gsize bytes_written = 0;
+
+   if (g_utf8_validate((const char *)ssid, ssid_len, NULL) == TRUE)
+   return g_strndup((const char *)ssid, ssid_len);
+
+   result = g_convert_with_fallback((const char *)ssid, -1,
+   UTF-8, ISO-8859-1,
+   0, 0,
+   bytes_written, error);
+   if (result) {
+   return result;
+   } else {
+   SUPPLICANT_DBG(Error converting to UTF-8: %s, 
error-message);

+   g_error_free (error);
+   }
+
GString *string;
const gchar *remainder, *invalid;
int valid_bytes, remaining_bytes;
--
1.7.10.4

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


[PATCH] gsupplicant: Remove the dbus match when not needed

2014-08-01 Thread Guoqiang Liu
From: Guoqiang Liu guoqiang@archermind.com

Remove the dbus match when connman is no loger interested in.
---
 gsupplicant/supplicant.c |1 +
 1 file changed, 1 insertion(+)

diff --git a/gsupplicant/supplicant.c b/gsupplicant/supplicant.c
index 534944b..d26b6e2 100644
--- a/gsupplicant/supplicant.c
+++ b/gsupplicant/supplicant.c
@@ -4898,6 +4898,7 @@ void g_supplicant_unregister(const GSupplicantCallbacks 
*callbacks)
SUPPLICANT_DBG();
 
if (connection) {
+   dbus_bus_remove_match(connection, g_supplicant_rule6, NULL);
dbus_bus_remove_match(connection, g_supplicant_rule5, NULL);
dbus_bus_remove_match(connection, g_supplicant_rule4, NULL);
dbus_bus_remove_match(connection, g_supplicant_rule3, NULL);
-- 
1.7.9.5

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


Re: [PATCH] Fix UTF-8 ssid's

2014-08-01 Thread Jukka Rissanen
Hi Lorn,

I just wonder what is the issue that this patch is fixing, isn't the
current implementation working?

On pe, 2014-08-01 at 19:42 +1000, Lorn Potter wrote:
 I found an old patch that crashed, and fixed it up.
 Enjoy!
 
 ---
   gsupplicant/supplicant.c |   20 
   1 file changed, 20 insertions(+)
 
 diff --git a/gsupplicant/supplicant.c b/gsupplicant/supplicant.c
 index 534944b..19dbb1a 100644
 --- a/gsupplicant/supplicant.c
 +++ b/gsupplicant/supplicant.c
 @@ -1256,6 +1256,26 @@ static void 
 interface_network_removed(DBusMessageIter *iter, void *user_data)
 
   static char *create_name(unsigned char *ssid, int ssid_len)
   {
 +   SUPPLICANT_DBG(%s, %i, ssid, ssid_len)
 +
 +   gchar *result;
 +   GError *error = 0;
 +   gsize bytes_written = 0;
 +
 +   if (g_utf8_validate((const char *)ssid, ssid_len, NULL) == TRUE)
 +   return g_strndup((const char *)ssid, ssid_len);
 +
 +   result = g_convert_with_fallback((const char *)ssid, -1,
 +   UTF-8, ISO-8859-1,
 +   0, 0,
 +   bytes_written, error);

SSID's are just byte arrays, how can we know which codeset we are
converting from (you assume ISO-8859-1 here)?


 +   if (result) {
 +   return result;
 +   } else {
 +   SUPPLICANT_DBG(Error converting to UTF-8: %s, 
 error-message);
 +   g_error_free (error);
 +   }
 +
  GString *string;
  const gchar *remainder, *invalid;
  int valid_bytes, remaining_bytes;

C++ style code here, the variables should be declared at the beginning
of func.


Cheers,
Jukka


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


Re: [PATCH] Fix UTF-8 ssid's

2014-08-01 Thread Tomasz Bursztyka

Hi,


I found an old patch that crashed, and fixed it up.
Enjoy!


New commit message style?  ^^

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


Re: [PATCH] gsupplicant: Remove the dbus match when not needed

2014-08-01 Thread Tomasz Bursztyka

ACK from me.

Thanks!

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


Re: [PATCH 1/5] gsupplicant: Add an helper to know if a peer is connected as client or not

2014-08-01 Thread Tomasz Bursztyka

Hi,



I met a wifi direct issue when use latest connman.

I'm not sure whether I catch your point, if I'm wrong , please correct 
me, thanks:-)


This patch seem that connman will use peer's */Group/* member to check 
whether local side is GC.
and peer's group will updata when peer property changed, and it may 
come after group started signal arrival,

so here will get a wrong role. you can find it in attached log.

In my case, local side is GC, but connman start a dhcp server :(



Yep, looks like I broke something in my latest patch-set, and the 
gsupplicant logic is wrong...

What was working before on GC context is no longer valid.

I'll fix this right away

Thanks for the report!

Tomasz

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


Re: [PATCH] Fix UTF-8 ssid's

2014-08-01 Thread Patrik Flykt

Hi,

On Fri, 2014-08-01 at 12:53 +0300, Jukka Rissanen wrote:
 Hi Lorn,

  +   result = g_convert_with_fallback((const char *)ssid, -1,
  +   UTF-8, ISO-8859-1,
  +   0, 0,
  +   bytes_written, error);
 
 SSID's are just byte arrays, how can we know which codeset we are
 converting from (you assume ISO-8859-1 here)?

We do not know the charset used for the SSID, so we can't do it like
this. The code below this patch goes through the SSID character by
character until it encounters a non-UTF-8 one. The offending characters
are replaced by the U+FFFD replacement character and thus the procedure
stitches up the name to be UTF-8 compliant.

Cheers,

Patrik

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


[PATCH] wifi: Free g_hash_table_get_values on connect_peer

2014-08-01 Thread Eduardo Abinader
Glist returned from g_hash_table_get_values was not
being freed during p2p connect, causing a leak.
---
 src/peer.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/peer.c b/src/peer.c
index 7f23059..1d802e1 100644
--- a/src/peer.c
+++ b/src/peer.c
@@ -480,7 +480,7 @@ static DBusMessage *connect_peer(DBusConnection *conn,
DBusMessage *msg, void *user_data)
 {
struct connman_peer *peer = user_data;
-   GList *list;
+   GList *list, *start;
int err;
 
DBG(peer %p, peer);
@@ -489,6 +489,7 @@ static DBusMessage *connect_peer(DBusConnection *conn,
return __connman_error_in_progress(msg);
 
list = g_hash_table_get_values(peers_table);
+   start = list;
for (; list; list = list-next) {
struct connman_peer *temp = list-data;
 
@@ -496,11 +497,15 @@ static DBusMessage *connect_peer(DBusConnection *conn,
continue;
 
if (is_connecting(temp) || is_connected(temp)) {
-   if (peer_disconnect(temp) == -EINPROGRESS)
+   if (peer_disconnect(temp) == -EINPROGRESS) {
+   g_list_free(start);
return __connman_error_in_progress(msg);
+   }
}
}
 
+   g_list_free(start);
+
peer-pending = dbus_message_ref(msg);
 
err = peer_connect(peer);
-- 
1.9.1

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


Re: [PATCH] wifi: Free g_hash_table_get_values on connect_peer

2014-08-01 Thread Tomasz Bursztyka

ACK

Thanks Eduardo

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


[RFC/PATCH 00/16] Peer's Agent API support

2014-08-01 Thread Tomasz Bursztyka
Sending this as an RFC, since I could not test all the use-cases yet.

This patch-set add the Peer's Agent API documentation and implementation.
However, this only works in the context when ConnMan initiates the connection
and not the other way round (which requires quite a bit of work to get it)

Tomasz Bursztyka (16):
  doc: Add RequestPeerInput method to agent API
  agent: Refactor the error reporting method to be more generic
  agent: Add a specific function to call ReportPeerError agent method
  peer: Provide a utility function to get peer's path in the core
  agent: Provide a function for the Peer RequestPeerAuthorization call
  peer: Modify connect driver's signature to handle WPS properly
  peer: Manage peer connection properly through an Agent report
  peer: Call Agent RequestPeerAuthorization on WPS needs
  gsupplicant: WPS PIN and Peer's path parameters are copied value
  gsupplicant: Add an helper to find a peer via its identifier
  gsupplicant: Add an helper to get the supplicant peer's object path
  wifi: Handle properly WPS parameters while connecting a peer
  wifi: Find and use peer's path do disconnect
  gsupplicant: Do not use and remove identifier parameter for peer
  client: Add Agent ReportPeerError method support
  client: Add support for RequestPeerAuthorization on WPS

 client/agent.c| 144 +
 doc/agent-api.txt |  49 +
 gsupplicant/gsupplicant.h |   8 ++-
 gsupplicant/supplicant.c  |  61 +---
 include/agent.h   |   4 ++
 include/peer.h|  10 ++-
 plugins/wifi.c|  47 ++--
 src/agent-connman.c   | 177 +-
 src/agent.c   |  17 +++--
 src/connman.h |  17 +
 src/peer.c| 120 +++
 11 files changed, 556 insertions(+), 98 deletions(-)

-- 
1.8.5.5

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


[PATCH 01/16] doc: Add RequestPeerInput method to agent API

2014-08-01 Thread Tomasz Bursztyka
This method will be used to handle extra input which might be requested
when connecting to a peer or in case a peer wants to connect to us.
---
 doc/agent-api.txt | 49 +
 1 file changed, 49 insertions(+)

diff --git a/doc/agent-api.txt b/doc/agent-api.txt
index a98343f..2ddd19a 100644
--- a/doc/agent-api.txt
+++ b/doc/agent-api.txt
@@ -23,6 +23,16 @@ Methods  void Release()
 
Possible Errors: net.connman.Agent.Error.Retry
 
+   void ReportPeerError(object peer, string error)
+
+   This method gets called when an error has to be
+   reported to the user about a peer connection.
+
+   A special return value can be used to trigger a
+   retry of the failed transaction.
+
+   Possible Errors: net.connman.Agent.Error.Retry
+
void RequestBrowser(object service, string url)
 
This method gets called when it is required
@@ -58,6 +68,25 @@ Methods  void Release()
Possible Errors: net.connman.Agent.Error.Canceled
 net.connman.Agent.Error.LaunchBrowser
 
+   dict RequestPeerAuthorization(object peer, dict fields) 
[experimental]
+
+   This method gets called when trying to connect to a
+   peer or when an incoming peer connection is requested,
+   for which some extra input is required. In this case,
+   it will only deal with WPS input as well as accepting
+   or rejecting an incoming connection.
+
+   The return value should be a dictionary where the
+   keys are the field names and the values are the
+   actual fields. Alternatively an error indicating that
+   the request got canceled or rejected can be returned.
+
+   The dictionary arguments contains field names with
+   their input parameters.
+
+   Possible Errors: net.connman.Agent.Error.Canceled
+net.connman.Agent.Error.Rejected
+
void Cancel()
 
This method gets called to indicate that the agent
@@ -107,6 +136,9 @@ Fields  string Name
method, or a pin code if user wants to use the pin
method.
 
+   In case of a RequestPeerAuthorization, this field will
+   be set as mandatory.
+
string Username
 
Username for WISPr authentication. This field will be
@@ -254,3 +286,20 @@ Examples   Requesting a passphrase for WPA2 network
}
 
== { Username : foo, Password: secret }
+
+   Requesting a answer about an inconming peer connection:
+
+   RequestPeerAuthorization(/peer3, {})
+
+   == { }
+
+   Requesting the WPS details when connecting to a peer:
+
+   RequestPeerAuthorization(/peer4,
+   { WPS:
+   { Type: wpspin,
+ Requirement : mandatory
+   }
+   }
+
+   == { WPS :  }
-- 
1.8.5.5

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


[PATCH 02/16] agent: Refactor the error reporting method to be more generic

2014-08-01 Thread Tomasz Bursztyka
Thus it will be possible afterwards to implement RequestPeerError very
simply.
---
 include/agent.h |  4 
 src/agent.c | 17 +
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/include/agent.h b/include/agent.h
index 05462df..6961f7a 100644
--- a/include/agent.h
+++ b/include/agent.h
@@ -52,6 +52,10 @@ void connman_agent_driver_unregister(struct 
connman_agent_driver *driver);
 typedef void (* report_error_cb_t) (void *user_context,
bool retry, void *user_data);
 
+int connman_agent_report_error_full(void *user_context, const char *path,
+   const char *method, const char *error,
+   report_error_cb_t callback,
+   const char *dbus_sender, void *user_data);
 int connman_agent_report_error(void *user_context, const char *path,
const char *error,
report_error_cb_t callback,
diff --git a/src/agent.c b/src/agent.c
index 37cf524..d23537d 100644
--- a/src/agent.c
+++ b/src/agent.c
@@ -363,8 +363,8 @@ static void report_error_reply(DBusMessage *reply, void 
*user_data)
g_free(report_error);
 }
 
-int connman_agent_report_error(void *user_context, const char *path,
-   const char *error,
+int connman_agent_report_error_full(void *user_context, const char *path,
+   const char *method, const char *error,
report_error_cb_t callback,
const char *dbus_sender, void *user_data)
 {
@@ -383,8 +383,7 @@ int connman_agent_report_error(void *user_context, const 
char *path,
return -ESRCH;
 
message = dbus_message_new_method_call(agent-owner, agent-path,
-   CONNMAN_AGENT_INTERFACE,
-   ReportError);
+   CONNMAN_AGENT_INTERFACE, method);
if (!message)
return -ENOMEM;
 
@@ -421,6 +420,16 @@ int connman_agent_report_error(void *user_context, const 
char *path,
return -EINPROGRESS;
 }
 
+int connman_agent_report_error(void *user_context, const char *path,
+   const char *error,
+   report_error_cb_t callback,
+   const char *dbus_sender, void *user_data)
+{
+   return connman_agent_report_error_full(user_context, path,
+   ReportError, error, callback, dbus_sender,
+   user_data);
+}
+
 static gint compare_priority(gconstpointer a, gconstpointer b)
 {
const struct connman_agent_driver *driver1 = a;
-- 
1.8.5.5

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


[PATCH 03/16] agent: Add a specific function to call ReportPeerError agent method

2014-08-01 Thread Tomasz Bursztyka
This will be exclusively used by peer core code to report an error.
---
 src/agent-connman.c | 10 ++
 src/connman.h   |  8 
 2 files changed, 18 insertions(+)

diff --git a/src/agent-connman.c b/src/agent-connman.c
index ab538f3..7502f0f 100644
--- a/src/agent-connman.c
+++ b/src/agent-connman.c
@@ -644,3 +644,13 @@ int __connman_agent_request_browser(struct connman_service 
*service,
 
return -EINPROGRESS;
 }
+
+int __connman_agent_report_peer_error(struct connman_peer *peer,
+   const char *path, const char *error,
+   report_error_cb_t callback,
+   const char *dbus_sender,
+   void *user_data)
+{
+   return connman_agent_report_error_full(peer, path, ReportPeerError,
+   error, callback, dbus_sender, user_data);
+}
diff --git a/src/connman.h b/src/connman.h
index 5cff513..068e36f 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -88,7 +88,10 @@ int __connman_counter_unregister(const char *owner, const 
char *path);
 int __connman_counter_init(void);
 void __connman_counter_cleanup(void);
 
+#include connman/agent.h
+
 struct connman_service;
+struct connman_peer;
 
 void __connman_agent_cancel(struct connman_service *service);
 
@@ -111,6 +114,11 @@ int __connman_agent_request_login_input(struct 
connman_service *service,
 int __connman_agent_request_browser(struct connman_service *service,
browser_authentication_cb_t callback,
const char *url, void *user_data);
+int __connman_agent_report_peer_error(struct connman_peer *peer,
+   const char *path, const char *error,
+   report_error_cb_t callback,
+   const char *dbus_sender,
+   void *user_data);
 
 #include connman/log.h
 
-- 
1.8.5.5

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


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

2014-08-01 Thread Tomasz Bursztyka
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)
+   str = mandatory;
+   else
+   str = alternate;
connman_dbus_dict_append_basic(iter, Requirement,
DBUS_TYPE_STRING, str);
 }
@@ -399,12 +412,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 +488,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 +553,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 +665,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) {
+   

[PATCH 13/16] wifi: Find and use peer's path do disconnect

2014-08-01 Thread Tomasz Bursztyka
Peer's lookup is done in wifi plugin and not anymore in gsupplicant
part.
---
 plugins/wifi.c | 14 --
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/plugins/wifi.c b/plugins/wifi.c
index e789f8c..95bc458 100644
--- a/plugins/wifi.c
+++ b/plugins/wifi.c
@@ -305,7 +305,9 @@ static int peer_disconnect(struct connman_peer *peer)
 {
struct connman_device *device = connman_peer_get_device(peer);
GSupplicantPeerParams peer_params = {};
+   GSupplicantPeer *gs_peer;
struct wifi_data *wifi;
+   int ret;
 
DBG(peer %p, peer);
 
@@ -316,10 +318,18 @@ static int peer_disconnect(struct connman_peer *peer)
if (!wifi)
return -ENODEV;
 
-   peer_params.identifier = connman_peer_get_identifier(peer);
+   gs_peer = g_supplicant_interface_peer_lookup(wifi-interface,
+   connman_peer_get_identifier(peer));
+   if (!gs_peer)
+   return -EINVAL;
+
+   peer_params.path = g_strdup(g_supplicant_peer_get_path(gs_peer));
 
-   return g_supplicant_interface_p2p_disconnect(wifi-interface,
+   ret = g_supplicant_interface_p2p_disconnect(wifi-interface,
peer_params);
+   g_free(peer_params.path);
+
+   return ret;
 }
 
 static struct connman_peer_driver peer_driver = {
-- 
1.8.5.5

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


[PATCH 09/16] gsupplicant: WPS PIN and Peer's path parameters are copied value

2014-08-01 Thread Tomasz Bursztyka
These are no longer constants, this is necessary for the future changes.
---
 gsupplicant/gsupplicant.h | 4 ++--
 gsupplicant/supplicant.c  | 4 +++-
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/gsupplicant/gsupplicant.h b/gsupplicant/gsupplicant.h
index 387a3aa..ff56001 100644
--- a/gsupplicant/gsupplicant.h
+++ b/gsupplicant/gsupplicant.h
@@ -170,8 +170,8 @@ typedef struct _GSupplicantScanParams GSupplicantScanParams;
 
 struct _GSupplicantPeerParams {
const char *identifier;
-   const char *wps_pin;
-   const char *path;
+   char *wps_pin;
+   char *path;
 };
 
 typedef struct _GSupplicantPeerParams GSupplicantPeerParams;
diff --git a/gsupplicant/supplicant.c b/gsupplicant/supplicant.c
index 59fe466..7fd9dcd 100644
--- a/gsupplicant/supplicant.c
+++ b/gsupplicant/supplicant.c
@@ -4650,6 +4650,8 @@ static void interface_p2p_connect_result(const char 
*error,
data-callback(err, data-interface, data-user_data);
 
g_free(data-path);
+   g_free(data-peer-wps_pin);
+   g_free(data-peer-path);
g_free(data-peer);
g_free(data);
 }
@@ -4717,7 +4719,7 @@ int 
g_supplicant_interface_p2p_connect(GSupplicantInterface *interface,
if (!peer)
return -ENODEV;
 
-   peer_params-path = peer-path;
+   peer_params-path = g_strdup(peer-path);
}
 
data = dbus_malloc0(sizeof(*data));
-- 
1.8.5.5

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


[PATCH 07/16] peer: Manage peer connection properly through an Agent report

2014-08-01 Thread Tomasz Bursztyka
Thus the upper layer, if providing an agent, will get a report from
connman and it will be possible at this point to ask for a proper retry.
---
 src/peer.c | 66 +-
 1 file changed, 53 insertions(+), 13 deletions(-)

diff --git a/src/peer.c b/src/peer.c
index d41a63d..08fd8e7 100644
--- a/src/peer.c
+++ b/src/peer.c
@@ -27,6 +27,8 @@
 #include gdbus.h
 #include gdhcp/gdhcp.h
 
+#include connman/agent.h
+
 #include connman.h
 
 static DBusConnection *connection = NULL;
@@ -655,6 +657,55 @@ static int start_dhcp_client(struct connman_peer *peer)
return __connman_dhcp_start(peer-ipconfig, NULL, dhcp_callback, peer);
 }
 
+static void report_error_cb(void *user_context, bool retry, void *user_data)
+{
+   struct connman_peer *peer = user_context;
+
+   if (retry) {
+   int err;
+   err = peer_connect(peer);
+
+   if (err == 0 || err == -EINPROGRESS)
+   return;
+   }
+
+   reply_pending(peer, ENOTCONN);
+
+   peer_disconnect(peer);
+
+   if (!peer-connection_master) {
+   __connman_dhcp_stop(peer-ipconfig);
+   __connman_ipconfig_disable(peer-ipconfig);
+   } else
+   stop_dhcp_server(peer);
+
+   peer-connection_master = false;
+   peer-sub_device = NULL;
+}
+
+static const char *get_dbus_sender(struct connman_peer *peer)
+{
+   if (!peer-pending)
+   return NULL;
+
+   return dbus_message_get_sender(peer-pending);
+}
+
+static int manage_peer_error(struct connman_peer *peer)
+{
+   int err;
+
+   err = __connman_agent_report_peer_error(peer, peer-path,
+   connect-failed, report_error_cb,
+   get_dbus_sender(peer), NULL);
+   if (err != -EINPROGRESS) {
+   report_error_cb(peer, false, NULL);
+   return err;
+   }
+
+   return 0;
+}
+
 int connman_peer_set_state(struct connman_peer *peer,
enum connman_peer_state new_state)
 {
@@ -692,19 +743,8 @@ int connman_peer_set_state(struct connman_peer *peer,
 
break;
case CONNMAN_PEER_STATE_FAILURE:
-   reply_pending(peer, ENOTCONN);
-
-   peer_disconnect(peer);
-
-   if (!peer-connection_master) {
-   __connman_dhcp_stop(peer-ipconfig);
-   __connman_ipconfig_disable(peer-ipconfig);
-   } else
-   stop_dhcp_server(peer);
-
-   peer-connection_master = false;
-   peer-sub_device = NULL;
-
+   if (manage_peer_error(peer) == 0)
+   return 0;
break;
};
 
-- 
1.8.5.5

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


[PATCH 08/16] peer: Call Agent RequestPeerAuthorization on WPS needs

2014-08-01 Thread Tomasz Bursztyka
This call will be raised if only a peer support both WPS pbc and pin
method and is not currently advertizing for pbc, thus the need for the
user to tell which method is necessary to proceed with the connection.
---
 src/peer.c | 59 +++
 1 file changed, 51 insertions(+), 8 deletions(-)

diff --git a/src/peer.c b/src/peer.c
index 08fd8e7..f4fa9de 100644
--- a/src/peer.c
+++ b/src/peer.c
@@ -451,6 +451,50 @@ static void peer_removed(struct connman_peer *peer)
peer_schedule_changed();
 }
 
+static const char *get_dbus_sender(struct connman_peer *peer)
+{
+   if (!peer-pending)
+   return NULL;
+
+   return dbus_message_get_sender(peer-pending);
+}
+
+static void request_authorization_cb(struct connman_peer *peer,
+   bool choice_done, const char *wpspin,
+   const char *error, void *user_data)
+{
+   enum connman_peer_wps_method wps_method;
+   int err;
+
+   DBG(RequestInput return, %p, peer);
+
+   if (error) {
+   if (g_strcmp0(error,
+   net.connman.Agent.Error.Canceled) == 0) {
+   err = -EINVAL;
+   goto out;
+   }
+   }
+
+   if (!choice_done || !peer_driver-connect) {
+   err = -EINVAL;
+   goto out;
+   }
+
+   if (!wpspin)
+   wps_method = CONNMAN_PEER_WPS_PBC;
+   else
+   wps_method = CONNMAN_PEER_WPS_PIN;
+
+   err = peer_driver-connect(peer, wps_method, wpspin);
+   if (err == -EINPROGRESS)
+   return;
+
+out:
+   reply_pending(peer, EIO);
+   connman_peer_set_state(peer, CONNMAN_PEER_STATE_IDLE);
+}
+
 static int peer_connect(struct connman_peer *peer)
 {
int err = -ENOTSUP;
@@ -459,6 +503,12 @@ static int peer_connect(struct connman_peer *peer)
err = peer_driver-connect(peer,
CONNMAN_PEER_WPS_UNKNOWN, NULL);
 
+   if (err == -ENOKEY) {
+   err = __connman_agent_request_peer_authorization(peer,
+   request_authorization_cb, true,
+   get_dbus_sender(peer), NULL);
+   }
+
return err;
 }
 
@@ -466,6 +516,7 @@ static int peer_disconnect(struct connman_peer *peer)
 {
int err = -ENOTSUP;
 
+   connman_agent_cancel(peer);
reply_pending(peer, ECONNABORTED);
 
if (peer-connection_master)
@@ -683,14 +734,6 @@ static void report_error_cb(void *user_context, bool 
retry, void *user_data)
peer-sub_device = NULL;
 }
 
-static const char *get_dbus_sender(struct connman_peer *peer)
-{
-   if (!peer-pending)
-   return NULL;
-
-   return dbus_message_get_sender(peer-pending);
-}
-
 static int manage_peer_error(struct connman_peer *peer)
 {
int err;
-- 
1.8.5.5

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


[PATCH 15/16] client: Add Agent ReportPeerError method support

2014-08-01 Thread Tomasz Bursztyka
This will be used to report error from ConnMan.
---
 client/agent.c | 34 ++
 1 file changed, 34 insertions(+)

diff --git a/client/agent.c b/client/agent.c
index baa0a87..64c84da 100644
--- a/client/agent.c
+++ b/client/agent.c
@@ -368,6 +368,36 @@ static DBusMessage *agent_report_error(DBusConnection 
*connection,
return NULL;
 }
 
+static DBusMessage *agent_report_peer_error(DBusConnection *connection,
+   DBusMessage *message, void *user_data)
+{
+   struct agent_data *request = user_data;
+   char *path, *peer, *error;
+   DBusMessageIter iter;
+
+   if (handle_message(message, request,
+   agent_report_peer_error) == false)
+   return NULL;
+
+   dbus_message_iter_init(message, iter);
+
+   dbus_message_iter_get_basic(iter, path);
+   peer = strip_path(path);
+
+   dbus_message_iter_next(iter);
+   dbus_message_iter_get_basic(iter, error);
+
+   __connmanctl_save_rl();
+   fprintf(stdout, Agent ReportPeerError %s\n, peer);
+   fprintf(stdout,   %s\n, error);
+   __connmanctl_redraw_rl();
+
+   request-message = dbus_message_ref(message);
+   __connmanctl_agent_mode(Retry (yes/no)? ,
+   report_error_return, request);
+   return NULL;
+}
+
 static void request_input_next(struct agent_data *request)
 {
int i;
@@ -562,6 +592,10 @@ static const GDBusMethodTable agent_methods[] = {
GDBUS_ARGS({ service, o },
{ error, s }),
NULL, agent_report_error) },
+   { GDBUS_ASYNC_METHOD(ReportPeerError,
+   GDBUS_ARGS({ peer, o },
+   { error, s }),
+   NULL, agent_report_peer_error) },
{ GDBUS_ASYNC_METHOD(RequestInput,
GDBUS_ARGS({ service, o },
{ fields, a{sv} }),
-- 
1.8.5.5

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


[PATCH 11/16] gsupplicant: Add an helper to get the supplicant peer's object path

2014-08-01 Thread Tomasz Bursztyka
Since wifi plugin will be looking up for the peer while connecting, it
will be the right place to get such information for the connection
parameters.
---
 gsupplicant/gsupplicant.h | 1 +
 gsupplicant/supplicant.c  | 8 
 2 files changed, 9 insertions(+)

diff --git a/gsupplicant/gsupplicant.h b/gsupplicant/gsupplicant.h
index a6b2db7..882e6e4 100644
--- a/gsupplicant/gsupplicant.h
+++ b/gsupplicant/gsupplicant.h
@@ -291,6 +291,7 @@ dbus_bool_t 
g_supplicant_network_is_wps_pbc(GSupplicantNetwork *network);
 dbus_bool_t g_supplicant_network_is_wps_advertizing(GSupplicantNetwork 
*network);
 
 GSupplicantInterface *g_supplicant_peer_get_interface(GSupplicantPeer *peer);
+const char *g_supplicant_peer_get_path(GSupplicantPeer *peer);
 const char *g_supplicant_peer_get_identifier(GSupplicantPeer *peer);
 const void *g_supplicant_peer_get_device_address(GSupplicantPeer *peer);
 const char *g_supplicant_peer_get_name(GSupplicantPeer *peer);
diff --git a/gsupplicant/supplicant.c b/gsupplicant/supplicant.c
index cfb6754..c877ddf 100644
--- a/gsupplicant/supplicant.c
+++ b/gsupplicant/supplicant.c
@@ -1036,6 +1036,14 @@ GSupplicantInterface 
*g_supplicant_peer_get_interface(GSupplicantPeer *peer)
return peer-interface;
 }
 
+const char *g_supplicant_peer_get_path(GSupplicantPeer *peer)
+{
+   if (!peer)
+   return NULL;
+
+   return peer-path;
+}
+
 const char *g_supplicant_peer_get_identifier(GSupplicantPeer *peer)
 {
if (!peer)
-- 
1.8.5.5

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


[PATCH 16/16] client: Add support for RequestPeerAuthorization on WPS

2014-08-01 Thread Tomasz Bursztyka
This method will be requested by ConnMan when it will need to know
whether to use WPS PIN or WPS PBC when connecting a peer.
---
 client/agent.c | 110 ++---
 1 file changed, 82 insertions(+), 28 deletions(-)

diff --git a/client/agent.c b/client/agent.c
index 64c84da..5a1b944 100644
--- a/client/agent.c
+++ b/client/agent.c
@@ -492,37 +492,16 @@ static void request_input_string_return(char *input, void 
*user_data)
request_input_next(request);
 }
 
-static DBusMessage *agent_request_input(DBusConnection *connection,
-   DBusMessage *message, void *user_data)
+static void parse_agent_request(struct agent_data *request,
+   DBusMessageIter *iter)
 {
-   struct agent_data *request = user_data;
-   DBusMessageIter iter, dict, entry, variant;
-   char *service, *str, *field;
-   DBusMessageIter dict_entry, field_entry, field_value;
-   char *argument, *value, *attr_type = NULL;
-
+   DBusMessageIter dict, entry, variant, dict_entry;
+   DBusMessageIter field_entry, field_value;
+   char *field, *argument, *value;
+   char *attr_type = NULL;
int i;
 
-   if (handle_message(message, request, agent_request_input) == false)
-   return NULL;
-
-   dbus_message_iter_init(message, iter);
-
-   dbus_message_iter_get_basic(iter, str);
-   service = strip_path(str);
-
-   dbus_message_iter_next(iter);
-   dbus_message_iter_recurse(iter, dict);
-
-   __connmanctl_save_rl();
-   if (strcmp(request-interface, AGENT_INTERFACE) == 0)
-   fprintf(stdout, Agent RequestInput %s\n, service);
-   else
-   fprintf(stdout, VPN Agent RequestInput %s\n, service);
-   __connmanctl_dbus_print(dict,   ,  = , \n);
-   fprintf(stdout, \n);
-
-   dbus_message_iter_recurse(iter, dict);
+   dbus_message_iter_recurse(iter, dict);
 
while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) {
 
@@ -566,6 +545,76 @@ static DBusMessage *agent_request_input(DBusConnection 
*connection,
 
dbus_message_iter_next(dict);
}
+}
+
+static DBusMessage *agent_request_input(DBusConnection *connection,
+   DBusMessage *message, void *user_data)
+{
+   struct agent_data *request = user_data;
+   DBusMessageIter iter, dict;
+   char *service, *str;
+
+   if (handle_message(message, request, agent_request_input) == false)
+   return NULL;
+
+   dbus_message_iter_init(message, iter);
+
+   dbus_message_iter_get_basic(iter, str);
+   service = strip_path(str);
+
+   dbus_message_iter_next(iter);
+   dbus_message_iter_recurse(iter, dict);
+
+   __connmanctl_save_rl();
+   if (strcmp(request-interface, AGENT_INTERFACE) == 0)
+   fprintf(stdout, Agent RequestInput %s\n, service);
+   else
+   fprintf(stdout, VPN Agent RequestInput %s\n, service);
+   __connmanctl_dbus_print(dict,   ,  = , \n);
+   fprintf(stdout, \n);
+
+   parse_agent_request(request, iter);
+
+   request-reply = dbus_message_new_method_return(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);
+
+   request_input_next(request);
+
+   return NULL;
+}
+
+static DBusMessage *
+agent_request_peer_authorization(DBusConnection *connection,
+   DBusMessage *message, void *user_data)
+{
+   struct agent_data *request = user_data;
+   DBusMessageIter iter, dict;
+   char *peer, *str;
+
+   if (handle_message(message, request, agent_request_peer_authorization)
+   == false)
+   return NULL;
+
+   dbus_message_iter_init(message, iter);
+
+   dbus_message_iter_get_basic(iter, str);
+   peer = strip_path(str);
+
+   dbus_message_iter_next(iter);
+   dbus_message_iter_recurse(iter, dict);
+
+   __connmanctl_save_rl();
+   fprintf(stdout, Agent RequestPeerAuthorization %s\n, peer);
+   __connmanctl_dbus_print(dict,   ,  = , \n);
+   fprintf(stdout, \n);
+
+   parse_agent_request(request, iter);
 
request-reply = dbus_message_new_method_return(message);
dbus_message_iter_init_append(request-reply, request-iter);
@@ -601,6 +650,11 @@ static const GDBusMethodTable agent_methods[] = {
{ fields, a{sv} }),
GDBUS_ARGS({ fields, a{sv} }),
agent_request_input) },
+   { 

[PATCH 12/16] wifi: Handle properly WPS parameters while connecting a peer

2014-08-01 Thread Tomasz Bursztyka
It checks whether the peer has proper WPS method requested. It can
return ENOKEY in case of none can be decided (thus peer core code will
request it through an agent call).
---
 plugins/wifi.c | 29 -
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/plugins/wifi.c b/plugins/wifi.c
index d72cefd..e789f8c 100644
--- a/plugins/wifi.c
+++ b/plugins/wifi.c
@@ -242,7 +242,9 @@ static int peer_connect(struct connman_peer *peer,
 {
struct connman_device *device = connman_peer_get_device(peer);
GSupplicantPeerParams *peer_params;
+   GSupplicantPeer *gs_peer;
struct wifi_data *wifi;
+   bool pbc, pin;
int ret;
 
DBG(peer %p, peer);
@@ -257,11 +259,36 @@ static int peer_connect(struct connman_peer *peer,
if (wifi-p2p_connecting)
return -EBUSY;
 
+   gs_peer = g_supplicant_interface_peer_lookup(wifi-interface,
+   connman_peer_get_identifier(peer));
+   if (!gs_peer)
+   return -EINVAL;
+
+   pbc = g_supplicant_peer_is_wps_pbc(gs_peer);
+   pin = g_supplicant_peer_is_wps_pin(gs_peer);
+
+   switch (wps_method) {
+   case CONNMAN_PEER_WPS_UNKNOWN:
+   if ((pbc  pin) || pin)
+   return -ENOKEY;
+   break;
+   case CONNMAN_PEER_WPS_PBC:
+   if (!pbc)
+   return -EINVAL;
+   break;
+   case CONNMAN_PEER_WPS_PIN:
+   if (!pin || !wps_pin)
+   return -EINVAL;
+   break;
+   }
+
peer_params = g_try_malloc0(sizeof(GSupplicantPeerParams));
if (!peer_params)
return -ENOMEM;
 
-   peer_params-identifier = connman_peer_get_identifier(peer);
+   peer_params-path = g_strdup(g_supplicant_peer_get_path(gs_peer));
+   if (wps_pin)
+   peer_params-wps_pin = g_strdup(wps_pin);
 
ret = g_supplicant_interface_p2p_connect(wifi-interface, peer_params,
peer_connect_callback, wifi);
-- 
1.8.5.5

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


[PATCH 10/16] gsupplicant: Add an helper to find a peer via its identifier

2014-08-01 Thread Tomasz Bursztyka
Wifi plugin will need to find the peer to check whether it supports WPS
PBC or PIN method while connectin, and action upon it.
---
 gsupplicant/gsupplicant.h |  2 ++
 gsupplicant/supplicant.c  | 45 +++--
 2 files changed, 29 insertions(+), 18 deletions(-)

diff --git a/gsupplicant/gsupplicant.h b/gsupplicant/gsupplicant.h
index ff56001..a6b2db7 100644
--- a/gsupplicant/gsupplicant.h
+++ b/gsupplicant/gsupplicant.h
@@ -265,6 +265,8 @@ int g_supplicant_interface_set_country(GSupplicantInterface 
*interface,
 bool g_supplicant_interface_has_p2p(GSupplicantInterface *interface);
 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);
 
 /* Network and Peer API */
 struct _GSupplicantNetwork;
diff --git a/gsupplicant/supplicant.c b/gsupplicant/supplicant.c
index 7fd9dcd..cfb6754 100644
--- a/gsupplicant/supplicant.c
+++ b/gsupplicant/supplicant.c
@@ -3171,6 +3171,29 @@ int 
g_supplicant_interface_set_p2p_device_config(GSupplicantInterface *interface
return ret;
 }
 
+static gboolean peer_lookup_by_identifier(gpointer key, gpointer value,
+   gpointer user_data)
+{
+   const GSupplicantPeer *peer = value;
+   const char *identifier = user_data;
+
+   if (!g_strcmp0(identifier, peer-identifier))
+   return TRUE;
+
+   return FALSE;
+}
+
+GSupplicantPeer *g_supplicant_interface_peer_lookup(GSupplicantInterface 
*interface,
+   const char *identifier)
+{
+   GSupplicantPeer *peer;
+
+   peer = g_hash_table_find(interface-peer_table,
+   peer_lookup_by_identifier,
+   (void *) identifier);
+   return peer;
+}
+
 struct interface_data {
GSupplicantInterface *interface;
char *path; /* Interface path cannot be taken from interface (above) as
@@ -4685,18 +4708,6 @@ static void interface_p2p_connect_params(DBusMessageIter 
*iter, void *user_data)
supplicant_dbus_dict_close(iter, dict);
 }
 
-static gboolean peer_lookup_by_identifier(gpointer key, gpointer value,
-   gpointer user_data)
-{
-   const GSupplicantPeer *peer = value;
-   const char *identifier = user_data;
-
-   if (!g_strcmp0(identifier, peer-identifier))
-   return TRUE;
-
-   return FALSE;
-}
-
 int g_supplicant_interface_p2p_connect(GSupplicantInterface *interface,
GSupplicantPeerParams *peer_params,
GSupplicantInterfaceCallback callback,
@@ -4713,9 +4724,8 @@ int 
g_supplicant_interface_p2p_connect(GSupplicantInterface *interface,
if (!peer_params-path) {
GSupplicantPeer *peer;
 
-   peer = g_hash_table_find(interface-peer_table,
-   peer_lookup_by_identifier,
-   (void *) peer_params-identifier);
+   peer = g_supplicant_interface_peer_lookup(interface,
+   peer_params-identifier);
if (!peer)
return -ENODEV;
 
@@ -4754,9 +4764,8 @@ int 
g_supplicant_interface_p2p_disconnect(GSupplicantInterface *interface,
if (!interface-p2p_support)
return -ENOTSUP;
 
-   peer = g_hash_table_find(interface-peer_table,
-   peer_lookup_by_identifier,
-   (void *) peer_params-identifier);
+   peer = g_supplicant_interface_peer_lookup(interface,
+   peer_params-identifier);
if (!peer)
return -ENODEV;
 
-- 
1.8.5.5

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


[PATCH 14/16] gsupplicant: Do not use and remove identifier parameter for peer

2014-08-01 Thread Tomasz Bursztyka
Wifi plugins is now using path as the only way to identify the peer
while connecting or disconnecting.
---
 gsupplicant/gsupplicant.h |  1 -
 gsupplicant/supplicant.c  | 14 +-
 2 files changed, 1 insertion(+), 14 deletions(-)

diff --git a/gsupplicant/gsupplicant.h b/gsupplicant/gsupplicant.h
index 882e6e4..ea994db 100644
--- a/gsupplicant/gsupplicant.h
+++ b/gsupplicant/gsupplicant.h
@@ -169,7 +169,6 @@ struct _GSupplicantScanParams {
 typedef struct _GSupplicantScanParams GSupplicantScanParams;
 
 struct _GSupplicantPeerParams {
-   const char *identifier;
char *wps_pin;
char *path;
 };
diff --git a/gsupplicant/supplicant.c b/gsupplicant/supplicant.c
index c877ddf..b0f688a 100644
--- a/gsupplicant/supplicant.c
+++ b/gsupplicant/supplicant.c
@@ -4729,17 +4729,6 @@ int 
g_supplicant_interface_p2p_connect(GSupplicantInterface *interface,
if (!interface-p2p_support)
return -ENOTSUP;
 
-   if (!peer_params-path) {
-   GSupplicantPeer *peer;
-
-   peer = g_supplicant_interface_peer_lookup(interface,
-   peer_params-identifier);
-   if (!peer)
-   return -ENODEV;
-
-   peer_params-path = g_strdup(peer-path);
-   }
-
data = dbus_malloc0(sizeof(*data));
data-interface = interface;
data-path = g_strdup(interface-path);
@@ -4772,8 +4761,7 @@ int 
g_supplicant_interface_p2p_disconnect(GSupplicantInterface *interface,
if (!interface-p2p_support)
return -ENOTSUP;
 
-   peer = g_supplicant_interface_peer_lookup(interface,
-   peer_params-identifier);
+   peer = g_hash_table_lookup(interface-peer_table, peer_params-path);
if (!peer)
return -ENODEV;
 
-- 
1.8.5.5

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