Hi Natsuki-san,
On 10/11/2018 06:06 PM, Natsuki.Itaya(a)sony.com wrote:
Add new WPS start API which does not specify any service.
Signed-off-by: n-itaya <Natsuki.Itaya(a)sony.com>
No 'Signed-off-by' needed. We don't have any definition what
it means for this project.
---
plugins/wifi.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 94 insertions(+)
diff --git a/plugins/wifi.c b/plugins/wifi.c
index dc08c6af..0d096aa2 100644
--- a/plugins/wifi.c
+++ b/plugins/wifi.c
@@ -42,6 +42,7 @@
#include <glib.h>
#define CONNMAN_API_SUBJECT_TO_CHANGE
+#include <connman.h>
#include <connman/plugin.h>
#include <connman/inet.h>
#include <connman/device.h>
@@ -123,6 +124,12 @@ struct wifi_tethering_info {
GSupplicantSSID *ssid;
};
+struct wifi_wps_offered_data {
+ struct connman_service *service;
+ char *expect_ident;
+ char *passphrase;
+};
+
struct wifi_data {
char *identifier;
struct connman_device *device;
@@ -156,11 +163,19 @@ struct wifi_data {
unsigned int p2p_connection_timeout;
struct connman_peer *pending_peer;
GSList *peers;
+ bool p2p_connected;
bool p2p_connecting;
bool p2p_device;
int servicing;
int disconnect_code;
int assoc_code;
+
+ bool wps_running;
+ bool wps_success;
+ unsigned int wps_timeout;
+ GSList *wps_offered_list;
+ bool wps_after_scan;
+ GSupplicantWPSParams wps_params;
};
static GList *iface_list = NULL;
@@ -174,6 +189,26 @@ static int tech_set_tethering(struct connman_technology
*technology,
const char *identifier, const char *passphrase,
const char *bridge, bool enabled);
+/* WPS Functions */
+#define WPS_TIMEOUT_INTERVAL_MSECS (125 * 1000)
+
+static void wps_event_success(GSupplicantInterface *interface);
+static void wps_event_fail(GSupplicantInterface *interface, int error);
+static struct wifi_wps_offered_data *wps_alloc_offered_data(
+ struct wifi_data *wifi, const char *group,
+ const char *passphrase);
+static void wps_free_offered_data(struct wifi_wps_offered_data *wps_data);
+static unsigned int wps_get_accepted_count(struct wifi_data *wifi);
+static unsigned int wps_get_offered_count(struct wifi_data *wifi);
+static bool wps_try_update_services(struct wifi_data *wifi);
+static void wps_finish(struct wifi_data *wifi, int error);
+static void wps_cleanup(struct wifi_data *wifi);
+static void wps_scan_callback(int result, GSupplicantInterface *interface,
+ void *user_data);
+static gboolean wps_timeout(gpointer data);
+static void wps_retry_callback(int result, GSupplicantInterface *interface,
+ void *user_data);
+
I've applied the whole series and did a compile test, unfortunately,
there is some stuff you need to address. Not sure if all the warnings
and errors are from this patch. The first few of the warnings
seem to originate from the above snippet.
We usually avoid static function declaration. Instead sort the
functions we don't need to forward declaration at all.
Looking at the list above, you don't even use them in this
patch.
plugins/wifi.c: In function ‘interface_state’:
plugins/wifi.c:2553:5: warning: implicit declaration of function
‘connman_technology_wps_state_change_notify’; did you mean
‘connman_technology_tethering_notify’? [-Wimplicit-function-declaration]
connman_technology_wps_state_change_notify
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
connman_technology_tethering_notify
plugins/wifi.c: At top level:
plugins/wifi.c:194:13: warning: ‘wps_event_success’ declared ‘static’ but never defined
[-Wunused-function]
static void wps_event_success(GSupplicantInterface *interface);
^~~~~~~~~~~~~~~~~
plugins/wifi.c:195:13: warning: ‘wps_event_fail’ declared ‘static’ but never defined
[-Wunused-function]
static void wps_event_fail(GSupplicantInterface *interface, int error);
^~~~~~~~~~~~~~
plugins/wifi.c:196:38: warning: ‘wps_alloc_offered_data’ declared ‘static’ but never
defined [-Wunused-function]
static struct wifi_wps_offered_data *wps_alloc_offered_data(
^~~~~~~~~~~~~~~~~~~~~~
plugins/wifi.c:199:13: warning: ‘wps_free_offered_data’ declared ‘static’ but never
defined [-Wunused-function]
static void wps_free_offered_data(struct wifi_wps_offered_data *wps_data);
^~~~~~~~~~~~~~~~~~~~~
plugins/wifi.c:200:21: warning: ‘wps_get_accepted_count’ declared ‘static’ but never
defined [-Wunused-function]
static unsigned int wps_get_accepted_count(struct wifi_data *wifi);
^~~~~~~~~~~~~~~~~~~~~~
plugins/wifi.c:201:21: warning: ‘wps_get_offered_count’ declared ‘static’ but never
defined [-Wunused-function]
static unsigned int wps_get_offered_count(struct wifi_data *wifi);
^~~~~~~~~~~~~~~~~~~~~
plugins/wifi.c:202:13: warning: ‘wps_try_update_services’ used but never defined
static bool wps_try_update_services(struct wifi_data *wifi);
^~~~~~~~~~~~~~~~~~~~~~~
plugins/wifi.c:203:13: warning: ‘wps_finish’ used but never defined
static void wps_finish(struct wifi_data *wifi, int error);
^~~~~~~~~~
plugins/wifi.c:204:13: warning: ‘wps_cleanup’ declared ‘static’ but never defined
[-Wunused-function]
static void wps_cleanup(struct wifi_data *wifi);
^~~~~~~~~~~
plugins/wifi.c:205:13: warning: ‘wps_scan_callback’ used but never defined
static void wps_scan_callback(int result, GSupplicantInterface *interface,
^~~~~~~~~~~~~~~~~
plugins/wifi.c:207:17: warning: ‘wps_timeout’ declared ‘static’ but never defined
[-Wunused-function]
static gboolean wps_timeout(gpointer data);
^~~~~~~~~~~
plugins/wifi.c:208:13: warning: ‘wps_retry_callback’ declared ‘static’ but never defined
[-Wunused-function]
static void wps_retry_callback(int result, GSupplicantInterface *interface,
^~~~~~~~~~~~~~~~~~
plugins/wifi.c:454:12: warning: ‘peer_disconnect_all’ defined but not used
[-Wunused-function]
static int peer_disconnect_all(struct wifi_data *wifi)
^~~~~~~~~~~~~~~~~~~
src/technology.c: In function ‘append_wps_service_structs’:
src/technology.c:619:13: warning: implicit declaration of function
‘__connman_service_lookup_from_ident’; did you mean ‘__connman_service_lookup_from_index’?
[-Wimplicit-function-declaration]
service = __connman_service_lookup_from_ident(ident);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
__connman_service_lookup_from_index
src/technology.c:619:11: warning: assignment makes pointer from integer without a cast
[-Wint-conversion]
service = __connman_service_lookup_from_ident(ident);
^
src/technology.c: In function ‘start_wps’:
src/technology.c:712:11: error: ‘struct connman_technology_driver’ has no member named
‘start_wps’
!driver->start_wps ||
^~
src/technology.c:716:15: error: ‘struct connman_technology_driver’ has no member named
‘start_wps’
err = driver->start_wps(technology, mode, auth);
^~
src/technology.c: In function ‘cancel_wps’:
src/technology.c:787:25: error: ‘struct connman_technology_driver’ has no member named
‘cancel_wps’
if (!driver || !driver->cancel_wps ||
^~
src/technology.c:791:15: error: ‘struct connman_technology_driver’ has no member named
‘cancel_wps’
err = driver->cancel_wps(technology);
^~
static int p2p_tech_probe(struct connman_technology *technology)
{
p2p_technology = technology;
@@ -417,6 +452,29 @@ static int peer_disconnect(struct connman_peer *peer)
return ret;
}
+static int peer_disconnect_all(struct wifi_data *wifi)
+{
+ GSList *list;
+ int result = 0, err = -EALREADY;
+
+ DBG("");
+
+ for (list = wifi->peers; list; list = list->next) {
+ struct connman_peer *peer = list->data;
+ GSupplicantPeer *gs_peer =
+ g_supplicant_interface_peer_lookup
+ (wifi->interface, connman_peer_get_identifier(peer));
Try to keep the function name and the brace together:
GSupplicantPeer *gs_peer =
g_supplicant_interface_peer_lookup(wifi->interface,
connman_peer_get_identifier(peer));
+
+ if (g_supplicant_peer_is_in_a_group(gs_peer)) {
+ err = peer_disconnect(peer);
+ if (err != -EINPROGRESS)
+ result = err;
+ }
+ }
+
+ return result;
+}
+
struct peer_service_registration {
peer_service_registration_cb_t callback;
void *user_data;
@@ -1583,6 +1641,7 @@ static int wifi_disable(struct connman_device *device)
return -ENODEV;
wifi->connected = false;
+ wifi->p2p_connected = false;
wifi->disconnecting = false;
if (wifi->pending_network)
@@ -2199,6 +2258,9 @@ static int network_connect(struct connman_network *network)
if (!wifi)
return -ENODEV;
+ if (wifi->wps_running)
+ return -EBUSY;
+
ssid = g_try_malloc0(sizeof(GSupplicantSSID));
if (!ssid)
return -ENOMEM;
@@ -2375,6 +2437,8 @@ static bool handle_wps_completion(GSupplicantInterface *interface,
{
bool wps;
+ DBG("");
+
wps = connman_network_get_bool(network, "WiFi.UseWPS");
if (wps) {
const unsigned char *ssid, *wps_ssid;
@@ -2486,6 +2550,36 @@ static void interface_state(GSupplicantInterface *interface)
finalize_interface_creation(wifi);
}
+ if (wifi->wps_running) {
+ DBG("WPS running");
+ switch (state) {
+ case G_SUPPLICANT_STATE_SCANNING:
+ if (!wifi->wps_success)
+ connman_technology_wps_state_change_notify
+ (wifi_technology, "scan");
+ return;
+ case G_SUPPLICANT_STATE_ASSOCIATED:
+ connman_technology_wps_state_change_notify
+ (wifi_technology, "processing");
+ return;
+ case G_SUPPLICANT_STATE_DISCONNECTED:
+ if (wifi->wps_success) {
+ if (wps_try_update_services(wifi)) {
+ wps_finish(wifi, 0);
+ } else {
+ wifi->wps_after_scan = true;
+ DBG("Need scan");
+ reset_autoscan(wifi->device);
+ throw_wifi_scan(device,
+ wps_scan_callback);
+ }
+ }
+ return;
+ default:
+ return;
+ }
+ }
+
Ah you are fighting with the 80 character rule. New breaking of the lines
looks a bit strange. What about moving this part into a function which
handles the wps_running case. This makes interface_state() function not
to grow further (already a bit large) and you just need to add
if (wifi->wps_running) {
process_wps_state(); // or a better name
return;
}
network = wifi->network;
if (!network)
return;
Thanks,
Daniel