From 0f330488afcfff031bc0ba88de826f998f7cfaf9 Mon Sep 17 00:00:00 2001 From: Vinit Deshapnde Date: Thu, 8 Aug 2013 10:39:25 -0700 Subject: Use a single socket to communicate with supplicant This helps to preapre for future updates from external sources. Bug: 9298955 Change-Id: I4c63ad5fc1ea3564aab38cfce955de19bad75c0c (cherry picked from commit 759cc323cb586192d591a815b0fb9d839536fcd6) --- wifi/wifi.c | 216 +++++++++++++++++++++--------------------------------------- 1 file changed, 74 insertions(+), 142 deletions(-) (limited to 'wifi') diff --git a/wifi/wifi.c b/wifi/wifi.c index 6b4d32d..ff9357b 100644 --- a/wifi/wifi.c +++ b/wifi/wifi.c @@ -37,21 +37,11 @@ #include #endif -/* PRIMARY refers to the connection on the primary interface - * SECONDARY refers to an optional connection on a p2p interface - * - * For concurrency, we only support one active p2p connection and - * one active STA connection at a time - */ -#define PRIMARY 0 -#define SECONDARY 1 -#define MAX_CONNS 2 - -static struct wpa_ctrl *ctrl_conn[MAX_CONNS]; -static struct wpa_ctrl *monitor_conn[MAX_CONNS]; +static struct wpa_ctrl *ctrl_conn; +static struct wpa_ctrl *monitor_conn; /* socket pair used to exit from a blocking read */ -static int exit_sockets[MAX_CONNS][2]; +static int exit_sockets[2]; extern int do_dhcp(); extern int ifc_init(); @@ -60,7 +50,7 @@ extern char *dhcp_lasterror(); extern void get_dhcp_info(); extern int init_module(void *, unsigned long, const char *); extern int delete_module(const char *, unsigned int); -void wifi_close_sockets(int index); +void wifi_close_sockets(); static char primary_iface[PROPERTY_VALUE_MAX]; // TODO: use new ANDROID_SOCKET mechanism, once support for multiple @@ -124,23 +114,6 @@ static char supplicant_name[PROPERTY_VALUE_MAX]; /* Is either SUPP_PROP_NAME or P2P_PROP_NAME */ static char supplicant_prop_name[PROPERTY_KEY_MAX]; -static int is_primary_interface(const char *ifname) -{ - //Treat NULL as primary interface to allow control - //on STA without an interface - if (ifname == NULL || !strncmp(ifname, primary_iface, strlen(primary_iface))) { - return 1; - } - return 0; -} - -static int wifi_interface_nomatch(int index, char *iface, char *match) -{ - int iflen = match - iface; - - return ((strncmp(primary_iface, iface, iflen) == 0) ^ (index == PRIMARY)); -} - static int insmod(const char *filename, const char *args) { void *module; @@ -539,9 +512,7 @@ int wifi_start_supplicant(int p2p_supported) wpa_ctrl_cleanup(); /* Reset sockets used for exiting from hung state */ - for (i=0; i'); + if (match2 != NULL) { + nread -= (match2 - match); + memmove(match + 1, match2 + 1, nread - (match - buf) + 1); + } } - nread -= (match+1-buf); - memmove(buf, match+1, nread+1); } else { return snprintf(buf, buflen, "%s", WPA_EVENT_IGNORE); } - } - if (buf[0] == '<') { + } else if (buf[0] == '<') { match = strchr(buf, '>'); if (match != NULL) { - nread -= (match+1-buf); - memmove(buf, match+1, nread+1); + nread -= (match + 1 - buf); + memmove(buf, match + 1, nread + 1); + ALOGV("supplicant generated event without interface - %s\n", buf); } + } else { + /* let the event go as is! */ + ALOGW("supplicant generated event without interface and without message level - %s\n", buf); } return nread; } -int wifi_wait_for_event(const char *ifname, char *buf, size_t buflen) +int wifi_wait_for_event(char *buf, size_t buflen) { - if (is_primary_interface(ifname)) { - return wifi_wait_on_socket(PRIMARY, buf, buflen); - } else { - return wifi_wait_on_socket(SECONDARY, buf, buflen); - } + return wifi_wait_on_socket(buf, buflen); } -void wifi_close_sockets(int index) +void wifi_close_sockets() { - if (ctrl_conn[index] != NULL) { - wpa_ctrl_close(ctrl_conn[index]); - ctrl_conn[index] = NULL; + if (ctrl_conn != NULL) { + wpa_ctrl_close(ctrl_conn); + ctrl_conn = NULL; } - if (monitor_conn[index] != NULL) { - wpa_ctrl_close(monitor_conn[index]); - monitor_conn[index] = NULL; + if (monitor_conn != NULL) { + wpa_ctrl_close(monitor_conn); + monitor_conn = NULL; } - if (exit_sockets[index][0] >= 0) { - close(exit_sockets[index][0]); - exit_sockets[index][0] = -1; + if (exit_sockets[0] >= 0) { + close(exit_sockets[0]); + exit_sockets[0] = -1; } - if (exit_sockets[index][1] >= 0) { - close(exit_sockets[index][1]); - exit_sockets[index][1] = -1; + if (exit_sockets[1] >= 0) { + close(exit_sockets[1]); + exit_sockets[1] = -1; } } -void wifi_close_supplicant_connection(const char *ifname) +void wifi_close_supplicant_connection() { char supp_status[PROPERTY_VALUE_MAX] = {'\0'}; int count = 50; /* wait at most 5 seconds to ensure init has stopped stupplicant */ - if (is_primary_interface(ifname)) { - wifi_close_sockets(PRIMARY); - } else { - /* p2p socket termination needs unblocking the monitor socket - * STA connection does not need it since supplicant gets shutdown - */ - TEMP_FAILURE_RETRY(write(exit_sockets[SECONDARY][0], "T", 1)); - /* p2p sockets are closed after the monitor thread - * receives the terminate on the exit socket - */ - return; - } + wifi_close_sockets(); while (count-- > 0) { if (property_get(supplicant_prop_name, supp_status, NULL)) { @@ -851,29 +803,9 @@ void wifi_close_supplicant_connection(const char *ifname) } } -/* - * Note: 'command' buffer should be preallocated with ~32 bytes free space - */ -int wifi_command(const char *ifname, char *command, size_t commandlen, - char *reply, size_t *reply_len) +int wifi_command(const char *command, char *reply, size_t *reply_len) { - size_t cmdlen = strlen(command) + 1; - size_t iflen = strlen(ifname) + IFNAMELEN + 1; - - if (strncmp(command, IFNAME, IFNAMELEN) != 0) { - if (commandlen >= cmdlen + iflen) { - memmove((&command[iflen]), command, cmdlen); - snprintf(command, iflen, "%s%s", IFNAME, ifname); - command[iflen - 1] = ' '; - } else { - ALOGE("CmdBuf is too small (%d) for %s", commandlen, command); - } - } - if (is_primary_interface(ifname)) { - return wifi_send_command(PRIMARY, command, reply, reply_len); - } else { - return wifi_send_command(SECONDARY, command, reply, reply_len); - } + return wifi_send_command(command, reply, reply_len); } const char *wifi_get_fw_path(int fw_type) -- cgit v1.1