Re: [PATCH] client: Add "auto" mode to agent

2015-01-26 Thread Patrik Flykt
On Mon, 2015-01-26 at 20:37 +0200, Jussi Kukkonen wrote:

> > This makes testing peer connections much faster and less stressful.
> 
> Further explanation: This patch has ensured my sanity in the past two
> weeks as I haven't had to constantly keep an eye on the terminal
> running connmanctl while testing P2P and Miracast. I'm totally happy
> to maintain the patch locally but sent this just in case you guys
> think others might have similar use cases.

I was suspecting that :-) That said, the patch looks fine and I'm left a
bit worried that someone turns this on and wonders why strange content
shows up on his P2P connected box or routed somewhere to the internets.

Cheers,

Patrik

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


Re: Possible issue with WPS and multi-SSID APs

2015-01-26 Thread Juha Kuikka
Hi,

On Thu, Jan 22, 2015 at 11:52 PM, Patrik Flykt
 wrote:
>
> Hi,
>
> On Thu, 2015-01-22 at 19:37 -0800, Juha Kuikka wrote:
>
>> I may have found an issue with the WPS support in connman.
>>
>> SW:
>> wpa_supplicant v2.3
>> connmand v1.27
>>
>> Environment:
>> I have an access point (Netgear R7000) that is advertising two SSIDs,
>> for example:
>> #1MyWifiNetwork
>> #2MyWifiNetwork-5GHz
>>
>> They have different BSSIDs.
>>
>> If, using connman I request a WPS connection to #1 it seems that
>> wpa_supplicant can actually complete the connection to #2.
>>
>> I think this is caused by the AP starting to advertise the WPS on both
>> of the SSIDs and wpa_supplicant picking either one since the WPS Start
>> request from connman did not include the BSSID.
>>
>> I tried this also with wpa_cli using wps_pbc or wps_pin without BSSID
>> and it does the same.
>
> As wpa_supplicant gets confused also via wpa_cli, it is something you'd
> better report to the wpa_supplicant mailing list so it gets fixed. See
> http://lists.shmoo.com/mailman/listinfo/hostap

I think this is expected behavior.

The .Interface.WPS.Start request from connman does not include
optional Bssid field so the supplicant picks any SSID that is
advertising WPS pairing (i.e. button has been pressed).

I don't have the WPS spec but this is normal behavior especially with
headless devices.

>
>> Unfortunately this causes connman to get pretty confused as to what is
>> going on and the connection attempt seems to stay in limbo
>> indefinitely.
>
> Indeed. The connecting service has a timer of 120s after which the
> service is declared failed. Did you check that this still works?

I will check that.


-- 
Duck tape is like the force, it has a light side and a dark side and
it holds the universe together.
___
connman mailing list
connman@connman.net
https://lists.connman.net/mailman/listinfo/connman


Re: [PATCH] client: Add "auto" mode to agent

2015-01-26 Thread Jussi Kukkonen
On 26 January 2015 at 20:18, Jussi Kukkonen  wrote:
> "agent auto" will register the agent normally but will also
> automatically accept all peer authorization requests that either
> require no input or that can be accepted with just an empty WPS
> string (pushbutton mode).
>
> This makes testing peer connections much faster and less stressful.

Further explanation: This patch has ensured my sanity in the past two
weeks as I haven't had to constantly keep an eye on the terminal
running connmanctl while testing P2P and Miracast. I'm totally happy
to maintain the patch locally but sent this just in case you guys
think others might have similar use cases.

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


[PATCH] client: Add "auto" mode to agent

2015-01-26 Thread Jussi Kukkonen
"agent auto" will register the agent normally but will also
automatically accept all peer authorization requests that either
require no input or that can be accepted with just an empty WPS
string (pushbutton mode).

This makes testing peer connections much faster and less stressful.
---
 client/agent.c| 58 +++
 client/agent.h|  2 +-
 client/commands.c | 56 -
 3 files changed, 85 insertions(+), 31 deletions(-)

diff --git a/client/agent.c b/client/agent.c
index d020889..ac7a07e 100644
--- a/client/agent.c
+++ b/client/agent.c
@@ -54,6 +54,7 @@ struct agent_data {
struct agent_input_data *input;
char *interface;
bool registered;
+   bool auto_accept;
DBusMessage *message;
DBusMessage *reply;
DBusMessageIter iter;
@@ -589,27 +590,36 @@ static DBusMessage *agent_request_input(DBusConnection 
*connection,
return NULL;
 }
 
+static void send_authorization_reply(struct agent_data *request, bool 
include_empty_wps)
+{
+   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);
+
+   if (include_empty_wps) {
+   request_input_append(request, "WPS", "");
+   request->input[WPS].requested = false;
+   }
+
+   dbus_message_iter_close_container(&request->iter, &request->dict);
+   g_dbus_send_message(agent_connection, request->reply);
+   request->reply = 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;
+   send_authorization_reply(request, FALSE);
break;
case 0:
 g_dbus_send_error(agent_connection, request->message,
@@ -632,7 +642,7 @@ agent_request_peer_authorization(DBusConnection *connection,
struct agent_data *request = user_data;
DBusMessageIter iter, dict;
char *peer, *str;
-   bool input;
+   bool input, is_wps;
int i;
 
if (handle_message(message, request, agent_request_peer_authorization)
@@ -657,10 +667,21 @@ agent_request_peer_authorization(DBusConnection 
*connection,
for (input = false, i = 0; request->input[i].attribute; i++) {
if (request->input[i].requested == true) {
input = true;
+   is_wps = (i == WPS);
break;
}
}
 
+   if (request->auto_accept && (!input || is_wps)) {
+   request->message = dbus_message_ref(message);
+   send_authorization_reply(request, is_wps);
+   fprintf(stdout, "Connection accepted\n");
+   pending_message_remove(request);
+   pending_command_complete("");
+
+   return NULL;
+   }
+
if (!input) {
request->message = dbus_message_ref(message);
__connmanctl_agent_mode("Accept connection (yes/no)? ",
@@ -735,11 +756,14 @@ static void append_path(DBusMessageIter *iter, void 
*user_data)
dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &path);
 }
 
-int __connmanctl_agent_register(DBusConnection *connection)
+int __connmanctl_agent_register(DBusConnection *connection,
+   bool auto_accept)
 {
char *path = agent_path();
int result;
 
+   agent_request.auto_accept = auto_accept;
+
if (agent_request.registered == true) {
fprintf(stderr, "Agent already registered\n");
return -EALREADY;
diff --git a/cli

Re: [PATCH] wifi: Remove entirely the support for wpa_supplicant autoscan

2015-01-26 Thread Patrik Flykt
On Mon, 2015-01-26 at 12:21 +0200, Tomasz Bursztyka wrote:
> ConnMan's own autoscan mechanism has proven to work properly than
> wpa_supplicant's one which does not support hidden SSIDs. Thus removing
> its support entirely.

Applied, thanks!

Patrik

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


Re: [PATCH] README: Remove bogus advice on wpa_supplicant building setting

2015-01-26 Thread Patrik Flykt
On Mon, 2015-01-26 at 11:05 +0200, Tomasz Bursztyka wrote:
> The autoscan module in wpa_supplicant cannot handle hidden SSIDs, where
> connman's autoscan policy does it properly so let's use this later one
> only.

Applied, thanks!

Patrik

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


Re: [PATCH 1/2] gdhcp: Set DHCP server id option in network byte order

2015-01-26 Thread Patrik Flykt
On Mon, 2015-01-26 at 13:42 +0200, Jukka Rissanen wrote:
> The DHCP server id option was sent using host byte order instead of
> network byte order. If the client uses the value when sending data
> to the server, then the DHCP packet will contain IP address in
> wrong byte order.
> 
> This issue was noticed with P2P connections where we do not set
> the gateway address in DHCP messages so some P2P clients sent data
> to wrong server as the our server address was incorrect.

Both patches applied, thanks!

Patrik

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


Re: [PATCH 0/3] Peer's remote IP fix

2015-01-26 Thread Patrik Flykt
On Mon, 2015-01-26 at 11:03 +0200, Tomasz Bursztyka wrote:
> In a context where our local peer ends up as the GC, the GO is the
> dhcp server. If for some reason there is a gateway, it will get the
> priority over the dhcp server ip.

Applied, thanks!

Patrik

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


[PATCH 2/2] gdhcp: Server id must not be converted to host byte order

2015-01-26 Thread Jukka Rissanen
As the server_nip is already in network byte order, we must not
convert the received server id option to host byte order.

This used to work as we sent the server id in wrong byte order
and then swapped it back here. But because of previous fix to
sent the server id in network byte order, this receiving end
needs some changes also.
---
 gdhcp/server.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gdhcp/server.c b/gdhcp/server.c
index 97c16c2..8574c24 100644
--- a/gdhcp/server.c
+++ b/gdhcp/server.c
@@ -668,7 +668,8 @@ static gboolean listener_event(GIOChannel *channel, 
GIOCondition condition,
 
server_id_option = dhcp_get_option(&packet, DHCP_SERVER_ID);
if (server_id_option) {
-   uint32_t server_nid = get_be32(server_id_option);
+   uint32_t server_nid =
+   get_unaligned((const uint32_t *) server_id_option);
 
if (server_nid != dhcp_server->server_nip)
return TRUE;
-- 
1.8.3.1

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


[PATCH 1/2] gdhcp: Set DHCP server id option in network byte order

2015-01-26 Thread Jukka Rissanen
The DHCP server id option was sent using host byte order instead of
network byte order. If the client uses the value when sending data
to the server, then the DHCP packet will contain IP address in
wrong byte order.

This issue was noticed with P2P connections where we do not set
the gateway address in DHCP messages so some P2P clients sent data
to wrong server as the our server address was incorrect.
---
 gdhcp/server.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gdhcp/server.c b/gdhcp/server.c
index 8561dd3..97c16c2 100644
--- a/gdhcp/server.c
+++ b/gdhcp/server.c
@@ -56,7 +56,7 @@ struct _GDHCPServer {
char *interface;
uint32_t start_ip;
uint32_t end_ip;
-   uint32_t server_nip;
+   uint32_t server_nip;/* our address in network byte order */
uint32_t lease_seconds;
int listener_sockfd;
guint listener_watch;
@@ -454,7 +454,7 @@ static void init_packet(GDHCPServer *dhcp_server, struct 
dhcp_packet *packet,
packet->gateway_nip = client_packet->gateway_nip;
packet->ciaddr = client_packet->ciaddr;
dhcp_add_option_uint32(packet, DHCP_SERVER_ID,
-   dhcp_server->server_nip);
+   ntohl(dhcp_server->server_nip));
 }
 
 static void add_option(gpointer key, gpointer value, gpointer user_data)
-- 
1.8.3.1

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


[PATCH] wifi: Remove entirely the support for wpa_supplicant autoscan

2015-01-26 Thread Tomasz Bursztyka
ConnMan's own autoscan mechanism has proven to work properly than
wpa_supplicant's one which does not support hidden SSIDs. Thus removing
its support entirely.
---
 gsupplicant/gsupplicant.h |  5 
 gsupplicant/supplicant.c  | 66 ---
 plugins/wifi.c| 21 +--
 3 files changed, 1 insertion(+), 91 deletions(-)

diff --git a/gsupplicant/gsupplicant.h b/gsupplicant/gsupplicant.h
index 97c804a..187dc65 100644
--- a/gsupplicant/gsupplicant.h
+++ b/gsupplicant/gsupplicant.h
@@ -225,11 +225,6 @@ int g_supplicant_interface_scan(GSupplicantInterface 
*interface,
GSupplicantInterfaceCallback callback,
void *user_data);
 
-int g_supplicant_interface_autoscan(GSupplicantInterface *interface,
-   const char *autoscan_data,
-   GSupplicantInterfaceCallback callback,
-   void *user_data);
-
 int g_supplicant_interface_p2p_find(GSupplicantInterface *interface,
GSupplicantInterfaceCallback callback,
void *user_data);
diff --git a/gsupplicant/supplicant.c b/gsupplicant/supplicant.c
index 3bdf0dc..dd9a525 100644
--- a/gsupplicant/supplicant.c
+++ b/gsupplicant/supplicant.c
@@ -3443,14 +3443,6 @@ struct interface_scan_data {
void *user_data;
 };
 
-struct interface_autoscan_data {
-   GSupplicantInterface *interface;
-   char *path;
-   GSupplicantInterfaceCallback callback;
-   const char *autoscan_params;
-   void *user_data;
-};
-
 static void interface_create_data_free(struct interface_create_data *data)
 {
g_free(data->ifname);
@@ -3967,64 +3959,6 @@ int g_supplicant_interface_scan(GSupplicantInterface 
*interface,
return ret;
 }
 
-static void interface_autoscan_result(const char *error,
-   DBusMessageIter *iter, void *user_data)
-{
-   struct interface_autoscan_data *data = user_data;
-   int err = 0;
-
-   if (error) {
-   SUPPLICANT_DBG("error %s", error);
-   err = -EIO;
-   }
-
-   g_free(data->path);
-
-   if (data->callback)
-   data->callback(err, data->interface, data->user_data);
-
-   dbus_free(data);
-}
-
-static void interface_autoscan_params(DBusMessageIter *iter, void *user_data)
-{
-   struct interface_autoscan_data *data = user_data;
-
-   dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
-&data->autoscan_params);
-}
-
-int g_supplicant_interface_autoscan(GSupplicantInterface *interface,
-   const char *autoscan_data,
-   GSupplicantInterfaceCallback callback,
-   void *user_data)
-{
-   struct interface_autoscan_data *data;
-   int ret;
-
-   data = dbus_malloc0(sizeof(*data));
-   if (!data)
-   return -ENOMEM;
-
-   data->interface = interface;
-   data->path = g_strdup(interface->path);
-   data->callback = callback;
-   data->autoscan_params = autoscan_data;
-   data->user_data = user_data;
-
-   ret = supplicant_dbus_method_call(interface->path,
-   SUPPLICANT_INTERFACE ".Interface", "AutoScan",
-   interface_autoscan_params,
-   interface_autoscan_result, data,
-   interface);
-   if (ret < 0) {
-   g_free(data->path);
-   dbus_free(data);
-   }
-
-   return ret;
-}
-
 static int parse_supplicant_error(DBusMessageIter *iter)
 {
int err = -ECANCELED;
diff --git a/plugins/wifi.c b/plugins/wifi.c
index e081f8a..1f90a31 100644
--- a/plugins/wifi.c
+++ b/plugins/wifi.c
@@ -1399,22 +1399,8 @@ static void setup_autoscan(struct wifi_data *wifi)
start_autoscan(wifi->device);
 }
 
-static void interface_autoscan_callback(int result,
-   GSupplicantInterface *interface,
-   void *user_data)
-{
-   struct wifi_data *wifi = user_data;
-
-   if (result < 0) {
-   DBG("Could not enable Autoscan, falling back...");
-   setup_autoscan(wifi);
-   }
-}
-
 static void finalize_interface_creation(struct wifi_data *wifi)
 {
-   GSupplicantInterface *interface = wifi->interface;
-
DBG("interface is ready wifi %p tethering %d", wifi, wifi->tethering);
 
if (!wifi->device) {
@@ -1430,12 +1416,7 @@ static void finalize_interface_creation(struct wifi_data 
*wifi)
if (wifi->p2p_device)
return;
 
-   /* Setting up automatic scanning */
-   if (g_supplicant_interface_autoscan(inte

[PATCH] README: Remove bogus advice on wpa_supplicant building setting

2015-01-26 Thread Tomasz Bursztyka
The autoscan module in wpa_supplicant cannot handle hidden SSIDs, where
connman's autoscan policy does it properly so let's use this later one
only.
---
 README | 7 ---
 1 file changed, 7 deletions(-)

diff --git a/README b/README
index b1367dd..531f396 100644
--- a/README
+++ b/README
@@ -312,13 +312,6 @@ CONFIG_BGSCAN_SIMPLE=y
 This last option will enable the support of background scanning while being
 connected, which is necessary when roaming on wifi.
 
-and finally:
-
-CONFIG_AUTOSCAN_EXPONENTIAL=y
-
-This will enable the exact same function as bgscan but while being
-disconnected.
-
 It is recommended to use wpa_supplicant 2.x or later.
 
 If wpa_supplicant is configured to D-Bus autostart, then ConnMan will
-- 
2.0.5

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


[PATCH 2/3] dhcp: Add an helper function to get the dhcp server address

2015-01-26 Thread Tomasz Bursztyka
This will be useful for the Peer API.
---
 src/connman.h |  1 +
 src/dhcp.c| 11 +++
 2 files changed, 12 insertions(+)

diff --git a/src/connman.h b/src/connman.h
index 2524f07..8d4a692 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -451,6 +451,7 @@ typedef void (* dhcpv6_cb) (struct connman_network *network,
 typedef void (* dhcp_cb) (struct connman_ipconfig *ipconfig,
struct connman_network *opt_network,
bool success, gpointer data);
+char *__connman_dhcp_get_server_address(struct connman_ipconfig *ipconfig);
 int __connman_dhcp_start(struct connman_ipconfig *ipconfig,
struct connman_network *network, dhcp_cb callback,
gpointer user_data);
diff --git a/src/dhcp.c b/src/dhcp.c
index 841b0c7..09f462b 100644
--- a/src/dhcp.c
+++ b/src/dhcp.c
@@ -582,6 +582,17 @@ static int dhcp_release(struct connman_dhcp *dhcp)
return 0;
 }
 
+char *__connman_dhcp_get_server_address(struct connman_ipconfig *ipconfig)
+{
+   struct connman_dhcp *dhcp;
+
+   dhcp = g_hash_table_lookup(ipconfig_table, ipconfig);
+   if (!dhcp)
+   return NULL;
+
+   return g_dhcp_client_get_server_address(dhcp->dhcp_client);
+}
+
 int __connman_dhcp_start(struct connman_ipconfig *ipconfig,
struct connman_network *network, dhcp_cb callback,
gpointer user_data)
-- 
2.0.5

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


[PATCH 0/3] Peer's remote IP fix

2015-01-26 Thread Tomasz Bursztyka
In a context where our local peer ends up as the GC, the GO is the
dhcp server. If for some reason there is a gateway, it will get the
priority over the dhcp server ip.

Tomasz Bursztyka (3):
  gdhcp: Add an helper function to get the dhcp server address
  dhcp: Add an helper function to get the dhcp server address
  peer: Get the dhcp server address relevantly for IPv4 settings

 gdhcp/client.c |  8 
 gdhcp/gdhcp.h  |  1 +
 src/connman.h  |  1 +
 src/dhcp.c | 11 +++
 src/peer.c | 10 ++
 5 files changed, 31 insertions(+)

-- 
2.0.5

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


[PATCH 1/3] gdhcp: Add an helper function to get the dhcp server address

2015-01-26 Thread Tomasz Bursztyka
This will be useful later on for the Peer API.
---
 gdhcp/client.c | 8 
 gdhcp/gdhcp.h  | 1 +
 2 files changed, 9 insertions(+)

diff --git a/gdhcp/client.c b/gdhcp/client.c
index ec61731..49d6351 100644
--- a/gdhcp/client.c
+++ b/gdhcp/client.c
@@ -2989,6 +2989,14 @@ int g_dhcp_client_get_index(GDHCPClient *dhcp_client)
return dhcp_client->ifindex;
 }
 
+char *g_dhcp_client_get_server_address(GDHCPClient *dhcp_client)
+{
+   if (!dhcp_client)
+   return NULL;
+
+   return get_ip(dhcp_client->server_ip);
+}
+
 char *g_dhcp_client_get_address(GDHCPClient *dhcp_client)
 {
return g_strdup(dhcp_client->assigned_ip);
diff --git a/gdhcp/gdhcp.h b/gdhcp/gdhcp.h
index 7525eb2..0ed7fa5 100644
--- a/gdhcp/gdhcp.h
+++ b/gdhcp/gdhcp.h
@@ -150,6 +150,7 @@ GDHCPClientError g_dhcp_client_set_send(GDHCPClient *client,
unsigned char option_code,
const char *option_value);
 
+char *g_dhcp_client_get_server_address(GDHCPClient *client);
 char *g_dhcp_client_get_address(GDHCPClient *client);
 char *g_dhcp_client_get_netmask(GDHCPClient *client);
 GList *g_dhcp_client_get_option(GDHCPClient *client,
-- 
2.0.5

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


[PATCH 3/3] peer: Get the dhcp server address relevantly for IPv4 settings

2015-01-26 Thread Tomasz Bursztyka
The dhcp server address is the one to consider as remote address if
there is no gateway set.
---
 src/peer.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/src/peer.c b/src/peer.c
index f48fb03..206b799 100644
--- a/src/peer.c
+++ b/src/peer.c
@@ -285,6 +285,7 @@ static void append_ipv4(DBusMessageIter *iter, void 
*user_data)
char trans[INET_ADDRSTRLEN+1] = {};
const char *local = "";
const char *remote = "";
+   char *dhcp = NULL;
 
if (!is_connected(peer))
return;
@@ -299,13 +300,22 @@ static void append_ipv4(DBusMessageIter *iter, void 
*user_data)
remote = trans;
} else if (peer->ipconfig) {
local = __connman_ipconfig_get_local(peer->ipconfig);
+
remote = __connman_ipconfig_get_gateway(peer->ipconfig);
+   if (!remote) {
+   remote = dhcp = __connman_dhcp_get_server_address(
+   peer->ipconfig);
+   if (!dhcp)
+   remote = "";
+   }
}
 
connman_dbus_dict_append_basic(iter, "Local",
DBUS_TYPE_STRING, &local);
connman_dbus_dict_append_basic(iter, "Remote",
DBUS_TYPE_STRING, &remote);
+   if (dhcp)
+   g_free(dhcp);
 }
 
 static void append_peer_service(DBusMessageIter *iter,
-- 
2.0.5

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