[PATCH v2 4/4] wifi: Correctly reference count a pending network

2015-06-23 Thread Patrik Flykt
With a WiFi to WiFi switch, the previous network is being disconnected
while the new one is waiting for the device to become available.
Protect the network struct with a ref so it will be available while
the previous network is disconnecting.
---
 plugins/wifi.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/plugins/wifi.c b/plugins/wifi.c
index 58d8bb2..4500839 100644
--- a/plugins/wifi.c
+++ b/plugins/wifi.c
@@ -1500,8 +1500,10 @@ static int wifi_disable(struct connman_device *device)
wifi-connected = false;
wifi-disconnecting = false;
 
-   if (wifi-pending_network)
+   if (wifi-pending_network) {
+   connman_network_unref(wifi-pending_network);
wifi-pending_network = NULL;
+   }
 
stop_autoscan(device);
 
@@ -2066,7 +2068,7 @@ static int network_connect(struct connman_network 
*network)
ssid_init(ssid, network);
 
if (wifi-disconnecting) {
-   wifi-pending_network = network;
+   wifi-pending_network = connman_network_ref(network);
g_free(ssid);
} else {
wifi-network = connman_network_ref(network);
@@ -2101,6 +2103,7 @@ static void disconnect_callback(int result, 
GSupplicantInterface *interface,
 
if (wifi-pending_network) {
network_connect(wifi-pending_network);
+   connman_network_unref(wifi-pending_network);
wifi-pending_network = NULL;
}
 
-- 
2.1.4

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


[PATCH v2 1/4] wifi: Try to enable tethering for an unused device

2015-06-23 Thread Patrik Flykt
When enabling tethering, try to first find a device without a network
connection that supports AP mode. If none is found, try again but this
time ignoring the network connection.

Factor out tethering enabling adding a boolea parameter that tells
whether to consider a connected network or not.

Reported by citylight2.
---
 plugins/wifi.c | 90 +++---
 1 file changed, 61 insertions(+), 29 deletions(-)

diff --git a/plugins/wifi.c b/plugins/wifi.c
index 587dee2..db29090 100644
--- a/plugins/wifi.c
+++ b/plugins/wifi.c
@@ -3062,9 +3062,9 @@ static void sta_remove_callback(int result,
info);
 }
 
-static int tech_set_tethering(struct connman_technology *technology,
-   const char *identifier, const char *passphrase,
-   const char *bridge, bool enabled)
+static int enable_wifi_tethering(struct connman_technology *technology,
+   const char *bridge, const char *identifier,
+   const char *passphrase, bool available)
 {
GList *list;
GSupplicantInterface *interface;
@@ -3074,46 +3074,34 @@ static int tech_set_tethering(struct connman_technology 
*technology,
unsigned int mode;
int err;
 
-   DBG();
-
-   if (!enabled) {
-   for (list = iface_list; list; list = list-next) {
-   wifi = list-data;
-
-   if (wifi-tethering) {
-   wifi-tethering = false;
-
-   connman_inet_remove_from_bridge(wifi-index,
-   bridge);
-   wifi-bridged = false;
-   }
-   }
-
-   connman_technology_tethering_notify(technology, false);
-
-   return 0;
-   }
-
for (list = iface_list; list; list = list-next) {
wifi = list-data;
 
+   DBG(wifi %p network %p pending_network %p, wifi,
+   wifi-network, wifi-pending_network);
+
interface = wifi-interface;
 
if (!interface)
continue;
 
-   if (wifi-ap_supported == WIFI_AP_NOT_SUPPORTED)
-   continue;
-
ifname = g_supplicant_interface_get_ifname(wifi-interface);
 
+   if (wifi-ap_supported == WIFI_AP_NOT_SUPPORTED) {
+   DBG(%s does not support AP mode (detected), ifname);
+   continue;
+   }
+
mode = g_supplicant_interface_get_mode(interface);
if ((mode  G_SUPPLICANT_CAPABILITY_MODE_AP) == 0) {
wifi-ap_supported = WIFI_AP_NOT_SUPPORTED;
-   DBG(%s does not support AP mode, ifname);
+   DBG(%s does not support AP mode (capability), ifname);
continue;
}
 
+   if (wifi-network  available)
+   continue;
+
info = g_try_malloc0(sizeof(struct wifi_tethering_info));
if (!info)
return -ENOMEM;
@@ -3160,13 +3148,57 @@ static int tech_set_tethering(struct connman_technology 
*technology,
err = g_supplicant_interface_remove(interface,
sta_remove_callback,
info);
-   if (err == 0)
-   return err;
+   if (err = 0) {
+   DBG(tethering wifi %p ifname %s, wifi, ifname);
+   return 0;
+   }
+
}
 
return -EOPNOTSUPP;
 }
 
+static int tech_set_tethering(struct connman_technology *technology,
+   const char *identifier, const char *passphrase,
+   const char *bridge, bool enabled)
+{
+   GList *list;
+   struct wifi_data *wifi;
+   int err;
+
+   DBG();
+
+   if (!enabled) {
+   for (list = iface_list; list; list = list-next) {
+   wifi = list-data;
+
+   if (wifi-tethering) {
+   wifi-tethering = false;
+
+   connman_inet_remove_from_bridge(wifi-index,
+   bridge);
+   wifi-bridged = false;
+   }
+   }
+
+   connman_technology_tethering_notify(technology, false);
+
+   return 0;
+   }
+
+   DBG(trying tethering for available devices);
+   err = enable_wifi_tethering(technology, bridge, identifier, passphrase,
+   true);
+
+   if (err  0) {
+   

[PATCH v2 3/4] wifi: Set network disconnected in disconnect_callback()

2015-06-23 Thread Patrik Flykt
The network needs to be set disconnected in the callback as the pointer
will be unconditionally cleared in the function. Even with a result of
zero the interface_state() cannot be relied on; it might not be called
by gsupplicant/wpa_supplicant in all cases.

Reported by Thomas Green.
---
 plugins/wifi.c | 13 ++---
 1 file changed, 2 insertions(+), 11 deletions(-)

diff --git a/plugins/wifi.c b/plugins/wifi.c
index de176ed..58d8bb2 100644
--- a/plugins/wifi.c
+++ b/plugins/wifi.c
@@ -2093,19 +2093,10 @@ static void disconnect_callback(int result, 
GSupplicantInterface *interface,
}
 
if (wifi-network) {
-   /*
-* if result  0 supplican return an error because
-* the network is not current.
-* we wont receive G_SUPPLICANT_STATE_DISCONNECTED since it
-* failed, call connman_network_set_connected to report
-* disconnect is completed.
-*/
-   if (result  0)
-   connman_network_set_connected(wifi-network, false);
+   connman_network_set_connected(wifi-network, false);
+   wifi-network = NULL;
}
 
-   wifi-network = NULL;
-
wifi-disconnecting = false;
 
if (wifi-pending_network) {
-- 
2.1.4

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


[PATCH v2 0/4] WiFi tethering fixes

2015-06-23 Thread Patrik Flykt

Hi,

Here is a set of WiFi tethering related fixes, with previous versions of
the first and third patch sent to the mailing list earlier. I also noticed
that wpa_supplicant can behave very strangely when adding/removing USB
WiFi devices while tethering, especially older versions.

Patch 4/4 got revorked, turns out this seems to be needed for a WiFi to
WiFi switch. In this case reference counting needs to happen in order not
to use memory that has been freed in between.


Cheers,

Patrik

*** BLURB HERE ***

Patrik Flykt (4):
  wifi: Try to enable tethering for an unused device
  wifi: Factor out freeing of variables on tethering failure
  wifi: Set network disconnected in disconnect_callback()
  wifi: Correctly reference count a pending network

 plugins/wifi.c | 144 -
 1 file changed, 81 insertions(+), 63 deletions(-)

-- 
2.1.4

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


WFA certification with connman

2015-06-23 Thread James Zipperer
Has anybody passed WFA certification with connman?  I'm seeing some tests
fail that I would expect to just work.  For instance: choosing to connect
to an access point with WPA2-encryption over choosing to connect an access
point with the same ssid that has WPA-encryption.

connman appears to group those ssids into a single service ex.
wifi_xx_managed_psk, with no differentiation between the WPA network
and WPA2 network presented to the user.

Is it connman's responsibility to choose the WPA2 network over the WPA
network?  Or is it wpa_supplicant's resposibility?  Or maybe the wifi
kernel module?  If it is connman's responsibility, how does it make the
choice?  It would be helpful to know which software package is responsible
for making that choice.

Thanks!

-- 

*James Zipperer*
Software Engineer
Synapse Product Development

mail 1511 6th Ave Suite 400, Seattle, WA 98101
direct 206-832-1269,3614 | office 206-381-0898 | mobile 206-399-6228
james.zippe...@synapse.com | http://www.synapse.com

This email and any files transmitted with it are confidential. Unauthorized
publication, use or dissemination of this email is prohibited.
Please consider the environment before printing.
___
connman mailing list
connman@connman.net
https://lists.connman.net/mailman/listinfo/connman


[PATCH] WFA certification with connman

2015-06-23 Thread James Zipperer
I think this may solve the problem I am seeing with WFA certification.
Please let me know if this is the right way to solve it.  In the case where
both RSN and WPA are available, prefer RSN over WPA.

Thanks!

-- 

*James Zipperer*
Software Engineer
Synapse Product Development

mail 1511 6th Ave Suite 400, Seattle, WA 98101
direct 206-832-1269,3614 | office 206-381-0898 | mobile 206-399-6228
james.zippe...@synapse.com | http://www.synapse.com

This email and any files transmitted with it are confidential. Unauthorized
publication, use or dissemination of this email is prohibited.
Please consider the environment before printing.


prefer-wpa2.patch
Description: Binary data
___
connman mailing list
connman@connman.net
https://lists.connman.net/mailman/listinfo/connman

[PATCH 3/4] wifi: Set network disconnected in disconnect_callback()

2015-06-23 Thread Patrik Flykt
The network needs to be set disconnected in the callback as the pointer
will be unconditionally cleared in the function. Even with a result of
zero the interface_state() cannot be relied on; it might not be called
by gsupplicant/wpa_supplicant in all cases.

Reported by Thomas Green.
---
 plugins/wifi.c | 13 ++---
 1 file changed, 2 insertions(+), 11 deletions(-)

diff --git a/plugins/wifi.c b/plugins/wifi.c
index de176ed..58d8bb2 100644
--- a/plugins/wifi.c
+++ b/plugins/wifi.c
@@ -2093,19 +2093,10 @@ static void disconnect_callback(int result, 
GSupplicantInterface *interface,
}
 
if (wifi-network) {
-   /*
-* if result  0 supplican return an error because
-* the network is not current.
-* we wont receive G_SUPPLICANT_STATE_DISCONNECTED since it
-* failed, call connman_network_set_connected to report
-* disconnect is completed.
-*/
-   if (result  0)
-   connman_network_set_connected(wifi-network, false);
+   connman_network_set_connected(wifi-network, false);
+   wifi-network = NULL;
}
 
-   wifi-network = NULL;
-
wifi-disconnecting = false;
 
if (wifi-pending_network) {
-- 
2.1.4

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


[PATCH 0/4] WiFi tethering fixes

2015-06-23 Thread Patrik Flykt

Hi,

Here is a set of WiFi tethering related fixes, with previous versions of
the first and third patch sent to the mailing list earlier. I also noticed
that wpa_supplicant can behave very strangely when adding/removing USB
WiFi devices while tethering, especially older versions.

The other two patches are cleanups for minor issues discovered.

Cheers,

Patrik


Patrik Flykt (4):
  wifi: Try to enable tethering for an unused device
  wifi: Factor out freeing of variables on tethering failure
  wifi: Set network disconnected in disconnect_callback()
  wifi: Remove unused pending_network

 plugins/wifi.c | 146 +
 1 file changed, 75 insertions(+), 71 deletions(-)

-- 
2.1.4

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


[PATCH 1/4] wifi: Try to enable tethering for an unused device

2015-06-23 Thread Patrik Flykt
When enabling tethering, try to first find a device without a network
connection that supports AP mode. If none is found, try again but this
time ignoring the network connection.

Factor out tethering enabling adding a boolea parameter that tells
whether to consider a connected network or not.

Reported by citylight2.
---
 plugins/wifi.c | 90 +++---
 1 file changed, 61 insertions(+), 29 deletions(-)

diff --git a/plugins/wifi.c b/plugins/wifi.c
index 587dee2..db29090 100644
--- a/plugins/wifi.c
+++ b/plugins/wifi.c
@@ -3062,9 +3062,9 @@ static void sta_remove_callback(int result,
info);
 }
 
-static int tech_set_tethering(struct connman_technology *technology,
-   const char *identifier, const char *passphrase,
-   const char *bridge, bool enabled)
+static int enable_wifi_tethering(struct connman_technology *technology,
+   const char *bridge, const char *identifier,
+   const char *passphrase, bool available)
 {
GList *list;
GSupplicantInterface *interface;
@@ -3074,46 +3074,34 @@ static int tech_set_tethering(struct connman_technology 
*technology,
unsigned int mode;
int err;
 
-   DBG();
-
-   if (!enabled) {
-   for (list = iface_list; list; list = list-next) {
-   wifi = list-data;
-
-   if (wifi-tethering) {
-   wifi-tethering = false;
-
-   connman_inet_remove_from_bridge(wifi-index,
-   bridge);
-   wifi-bridged = false;
-   }
-   }
-
-   connman_technology_tethering_notify(technology, false);
-
-   return 0;
-   }
-
for (list = iface_list; list; list = list-next) {
wifi = list-data;
 
+   DBG(wifi %p network %p pending_network %p, wifi,
+   wifi-network, wifi-pending_network);
+
interface = wifi-interface;
 
if (!interface)
continue;
 
-   if (wifi-ap_supported == WIFI_AP_NOT_SUPPORTED)
-   continue;
-
ifname = g_supplicant_interface_get_ifname(wifi-interface);
 
+   if (wifi-ap_supported == WIFI_AP_NOT_SUPPORTED) {
+   DBG(%s does not support AP mode (detected), ifname);
+   continue;
+   }
+
mode = g_supplicant_interface_get_mode(interface);
if ((mode  G_SUPPLICANT_CAPABILITY_MODE_AP) == 0) {
wifi-ap_supported = WIFI_AP_NOT_SUPPORTED;
-   DBG(%s does not support AP mode, ifname);
+   DBG(%s does not support AP mode (capability), ifname);
continue;
}
 
+   if (wifi-network  available)
+   continue;
+
info = g_try_malloc0(sizeof(struct wifi_tethering_info));
if (!info)
return -ENOMEM;
@@ -3160,13 +3148,57 @@ static int tech_set_tethering(struct connman_technology 
*technology,
err = g_supplicant_interface_remove(interface,
sta_remove_callback,
info);
-   if (err == 0)
-   return err;
+   if (err = 0) {
+   DBG(tethering wifi %p ifname %s, wifi, ifname);
+   return 0;
+   }
+
}
 
return -EOPNOTSUPP;
 }
 
+static int tech_set_tethering(struct connman_technology *technology,
+   const char *identifier, const char *passphrase,
+   const char *bridge, bool enabled)
+{
+   GList *list;
+   struct wifi_data *wifi;
+   int err;
+
+   DBG();
+
+   if (!enabled) {
+   for (list = iface_list; list; list = list-next) {
+   wifi = list-data;
+
+   if (wifi-tethering) {
+   wifi-tethering = false;
+
+   connman_inet_remove_from_bridge(wifi-index,
+   bridge);
+   wifi-bridged = false;
+   }
+   }
+
+   connman_technology_tethering_notify(technology, false);
+
+   return 0;
+   }
+
+   DBG(trying tethering for available devices);
+   err = enable_wifi_tethering(technology, bridge, identifier, passphrase,
+   true);
+
+   if (err  0) {
+   

[PATCH 2/4] wifi: Factor out freeing of variables on tethering failure

2015-06-23 Thread Patrik Flykt
Clean up variables in one place if tethering fails and continue with
the next wifi if one exists.
---
 plugins/wifi.c | 34 +-
 1 file changed, 13 insertions(+), 21 deletions(-)

diff --git a/plugins/wifi.c b/plugins/wifi.c
index db29090..de176ed 100644
--- a/plugins/wifi.c
+++ b/plugins/wifi.c
@@ -3116,31 +3116,17 @@ static int enable_wifi_tethering(struct 
connman_technology *technology,
info-technology = technology;
info-wifi-bridge = bridge;
info-ssid = ssid_ap_init(identifier, passphrase);
-   if (!info-ssid) {
-   g_free(info);
-   g_free(wifi-tethering_param);
-   wifi-tethering_param = NULL;
-   continue;
-   }
+   if (!info-ssid)
+   goto failed;
+
info-ifname = g_strdup(ifname);
-   if (!info-ifname) {
-   g_free(info-ssid);
-   g_free(wifi-tethering_param);
-   g_free(info);
-   wifi-tethering_param = NULL;
-   continue;
-   }
+   if (!info-ifname)
+   goto failed;
 
wifi-tethering_param-technology = technology;
wifi-tethering_param-ssid = ssid_ap_init(identifier, 
passphrase);
-   if (!wifi-tethering_param-ssid) {
-   g_free(info-ifname);
-   g_free(info-ssid);
-   g_free(wifi-tethering_param);
-   g_free(info);
-   wifi-tethering_param = NULL;
-   continue;
-   }
+   if (!wifi-tethering_param-ssid)
+   goto failed;
 
info-wifi-tethering = true;
info-wifi-ap_supported = WIFI_AP_SUPPORTED;
@@ -3153,6 +3139,12 @@ static int enable_wifi_tethering(struct 
connman_technology *technology,
return 0;
}
 
+   failed:
+   g_free(info-ifname);
+   g_free(info-ssid);
+   g_free(info);
+   g_free(wifi-tethering_param);
+   wifi-tethering_param = NULL;
}
 
return -EOPNOTSUPP;
-- 
2.1.4

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


[PATCH] wifi: Fix Possible memory leak

2015-06-23 Thread Saurav Babu
This patch frees peer_params-path and peer_params-wps_pin also when
peer_params is freed. Both peer_params-path and peer_params-wps_pin
are allocated memory using g_strdup() and needs to be freed when
g_supplicant_interface_p2p_connect() return is less than 0.
---
 plugins/wifi.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/plugins/wifi.c b/plugins/wifi.c
index 587dee2..513e577 100644
--- a/plugins/wifi.c
+++ b/plugins/wifi.c
@@ -356,8 +356,11 @@ static int peer_connect(struct connman_peer *peer,
wifi-pending_peer = connman_peer_ref(peer);
wifi-peer = gs_peer;
wifi-p2p_connecting = true;
-   } else if (ret  0)
+   } else if (ret  0) {
+   g_free(peer_params-path);
+   g_free(peer_params-wps_pin);
g_free(peer_params);
+   }
 
return ret;
 }
-- 
1.9.1

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


Re: DHCP timers

2015-06-23 Thread Patrik Flykt
On Mon, 2015-06-22 at 11:04 -0700, Naveen Singh wrote:
  This affects all timers set by ConnMan, so a generic fix would be of
  interest. Hasn't this been implemented in some version of glib
  already?
 
 I have the latest Glib (2.43.2). I did not find any thing in glib to
 support this.

That means you should probably propose such changes to glib.

Cheers,

Patrik

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


[RFC] gsupplicant: Remove entries in hash tables for error cases

2015-06-23 Thread Harish Jenny K N
Handle the failure in add_or_replace_bss_to_network by
removing the entries from hash tables.

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

diff --git a/gsupplicant/supplicant.c b/gsupplicant/supplicant.c
index 38cbad1..06e9954 100755
--- a/gsupplicant/supplicant.c
+++ b/gsupplicant/supplicant.c
@@ -2483,6 +2483,14 @@ static void signal_bss_changed(const char *path, 
DBusMessageIter *iter)
memcpy(new_bss, bss, sizeof(struct g_supplicant_bss));
new_bss-path = g_strdup(bss-path);
 
+   /* Remove entries in hash tables to handle the
+* failure in add_or_replace_bss_to_network
+*/
+   g_hash_table_remove(bss_mapping, path);
+
+   g_hash_table_remove(interface-bss_mapping, path);
+   g_hash_table_remove(network-bss_table, path);
+
g_hash_table_remove(interface-network_table, network-group);
 
add_or_replace_bss_to_network(new_bss);
-- 
1.7.9.5

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


Re: [PATCH 4/4] wifi: Remove unused pending_network

2015-06-23 Thread Patrik Flykt
On Tue, 2015-06-23 at 13:35 +0300, Tomasz Bursztyka wrote:
 Hi Patrik,
 
  stop_autoscan(device);

  if (wifi-p2p_find_timeout) {
  @@ -2066,7 +2062,6 @@ static int network_connect(struct connman_network 
  *network)
  ssid_init(ssid, network);

  if (wifi-disconnecting) {
  -   wifi-pending_network = network;
 
  From here
 
  g_free(ssid);
  } else {
  wifi-network = connman_network_ref(network);
  @@ -2099,11 +2094,6 @@ static void disconnect_callback(int result, 
  GSupplicantInterface *interface,

  wifi-disconnecting = false;

  -   if (wifi-pending_network) {
  -   network_connect(wifi-pending_network);
  -   wifi-pending_network = NULL;
 
 and there
 
 This looks like there was a logic about it.
 
 (Not sure this would be hit anyway though)

Yes. But to connect a network in a disconnect callback is what I don't
get.

Cheers,

Patrik

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


Re: [PATCH 4/4] wifi: Remove unused pending_network

2015-06-23 Thread Tomasz Bursztyka

Hi Patrik,


stop_autoscan(device);
  
  	if (wifi-p2p_find_timeout) {

@@ -2066,7 +2062,6 @@ static int network_connect(struct connman_network 
*network)
ssid_init(ssid, network);
  
  	if (wifi-disconnecting) {

-   wifi-pending_network = network;


From here


g_free(ssid);
} else {
wifi-network = connman_network_ref(network);
@@ -2099,11 +2094,6 @@ static void disconnect_callback(int result, 
GSupplicantInterface *interface,
  
  	wifi-disconnecting = false;
  
-	if (wifi-pending_network) {

-   network_connect(wifi-pending_network);
-   wifi-pending_network = NULL;


and there

This looks like there was a logic about it.

(Not sure this would be hit anyway though)

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


Dynamic natting with connman

2015-06-23 Thread Sriram Sagar
Hi,

Using connman, is there any possibility that we can do dynamic Natting.

Like we have 3G and WLAN connection and use that internet connection as a
backend to another wireless card as AP. All three interfaces (2 WLAN and 1
3G) are on same board.  Where my preferences are in sequence of wifi and
cellular (one wireless interface is black listed) .

So when we have wireless connection state as Online (AO) and cellular
connection state as Ready (AR). When both wireless and cellular are active.

When WLAN connection is online, we specify NATing entries with WLAN
interface to another WLAN interface (acting as AP) using iptable commands.
iptables --flush
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
iptables -A FORWARD -i wlan0 -o wlan1 -m state --state RELATED,ESTABLISHED
-j ACCEPT
iptables -A FORWARD -i wlan1 -o wlan0 -j ACCEPT

If the WLAN connection is disconnected and we are having connection through
3G, we specify NATing entries with 3G interface commands to WLAN (acting as
AP).
The wlan interface(wlan0) will be replaced with the ppp interface
in the above commands

we want to make this NATing entries dynamically based on the current AO
connection in connman.

It would be greatful If I can get any help on this.
___
connman mailing list
connman@connman.net
https://lists.connman.net/mailman/listinfo/connman