#include <poll.h>
#include "hardware_legacy/wifi.h"
+#ifdef LIBWPA_CLIENT_EXISTS
#include "libwpa_client/wpa_ctrl.h"
+#endif
#define LOG_TAG "WifiHW"
#include "cutils/log.h"
#include <sys/_system_properties.h>
#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];
-
-/* socket pair used to exit from a blocking read */
-static int exit_sockets[MAX_CONNS][2];
-
extern int do_dhcp();
extern int ifc_init();
extern void ifc_close();
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();
+
+#ifndef LIBWPA_CLIENT_EXISTS
+#define WPA_EVENT_TERMINATING "CTRL-EVENT-TERMINATING "
+struct wpa_ctrl {};
+void wpa_ctrl_cleanup(void) {}
+struct wpa_ctrl *wpa_ctrl_open(const char *ctrl_path) { return NULL; }
+void wpa_ctrl_close(struct wpa_ctrl *ctrl) {}
+int wpa_ctrl_request(struct wpa_ctrl *ctrl, const char *cmd, size_t cmd_len,
+ char *reply, size_t *reply_len, void (*msg_cb)(char *msg, size_t len))
+ { return 0; }
+int wpa_ctrl_attach(struct wpa_ctrl *ctrl) { return 0; }
+int wpa_ctrl_detach(struct wpa_ctrl *ctrl) { return 0; }
+int wpa_ctrl_recv(struct wpa_ctrl *ctrl, char *reply, size_t *reply_len)
+ { return 0; }
+int wpa_ctrl_get_fd(struct wpa_ctrl *ctrl) { return 0; }
+#endif
+
+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[2];
static char primary_iface[PROPERTY_VALUE_MAX];
// TODO: use new ANDROID_SOCKET mechanism, once support for multiple
#endif
#define WIFI_DRIVER_LOADER_DELAY 1000000
+#define SYSFS_PATH_MAX 256
static const char IFACE_DIR[] = "/data/system/wpa_supplicant";
#ifdef WIFI_DRIVER_MODULE_PATH
-static const char DRIVER_MODULE_NAME[] = WIFI_DRIVER_MODULE_NAME;
-static const char DRIVER_MODULE_TAG[] = WIFI_DRIVER_MODULE_NAME " ";
-static const char DRIVER_MODULE_PATH[] = WIFI_DRIVER_MODULE_PATH;
+static const char DRIVER_NAME_PROP[] = "wlan.modname";
+static const char DRIVER_PATH_PROP[] = "wlan.modpath";
static const char DRIVER_MODULE_ARG[] = WIFI_DRIVER_MODULE_ARG;
#endif
static const char FIRMWARE_LOADER[] = WIFI_FIRMWARE_LOADER;
static const char P2P_CONFIG_FILE[] = "/data/misc/wifi/p2p_supplicant.conf";
static const char CONTROL_IFACE_PATH[] = "/data/misc/wifi/sockets";
static const char MODULE_FILE[] = "/proc/modules";
+static const char SYSFS_CLASS_NET[] = "/sys/class/net";
+static const char MODULE_DEFAULT_DIR[] = "/system/lib/modules";
+static const char SYS_MOD_NAME_DIR[] = "device/driver/module";
+
+static const char IFNAME[] = "IFNAME=";
+#define IFNAMELEN (sizeof(IFNAME) - 1)
+static const char WPA_EVENT_IGNORE[] = "CTRL-EVENT-IGNORE ";
static const char SUPP_ENTROPY_FILE[] = WIFI_ENTROPY_FILE;
static unsigned char dummy_key[21] = { 0x02, 0x11, 0xbe, 0x33, 0x43, 0x35,
/* 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 insmod(const char *filename, const char *args)
{
void *module;
return dhcp_lasterror();
}
+#ifdef WIFI_DRIVER_MODULE_PATH
+static int get_driver_path(const char *mod, const char *path, char *buf) {
+ DIR *dir;
+ struct dirent *de;
+ char modpath[SYSFS_PATH_MAX];
+ int ret = 0;
+
+ if ((dir = opendir(path))) {
+ while ((de = readdir(dir))) {
+ struct stat sb;
+ if (de->d_name[0] == '.')
+ continue;
+ snprintf(modpath, SYSFS_PATH_MAX, "%s/%s", path, de->d_name);
+ if (!strcmp(de->d_name, mod)) {
+ strncpy(buf, modpath, SYSFS_PATH_MAX - 1);
+ buf[SYSFS_PATH_MAX - 1] = '\0';
+ ret = 1;
+ break;
+ }
+ if (!stat(modpath, &sb) && (sb.st_mode & S_IFMT) == S_IFDIR)
+ if ((ret = get_driver_path(mod, modpath, buf)))
+ break;
+ }
+ closedir(dir);
+ }
+ return ret;
+}
+
+static int get_driver_info(char *buf) {
+ DIR *netdir;
+ struct dirent *de;
+ char path[SYSFS_PATH_MAX];
+ char link[SYSFS_PATH_MAX];
+ int ret = 0;
+
+ if ((netdir = opendir(SYSFS_CLASS_NET))) {
+ while ((de = readdir(netdir))) {
+ int cnt;
+ char *pos;
+ if (de->d_name[0] == '.')
+ continue;
+ snprintf(path, SYSFS_PATH_MAX, "%s/%s/wireless", SYSFS_CLASS_NET, de->d_name);
+ if (access(path, F_OK)) {
+ snprintf(path, SYSFS_PATH_MAX, "%s/%s/phy80211", SYSFS_CLASS_NET, de->d_name);
+ if (access(path, F_OK))
+ continue;
+ }
+ /* found the wifi interface */
+ property_set("wlan.interface", de->d_name);
+ snprintf(path, SYSFS_PATH_MAX, "%s/%s/%s", SYSFS_CLASS_NET, de->d_name, SYS_MOD_NAME_DIR);
+ if ((cnt = readlink(path, link, SYSFS_PATH_MAX - 1)) < 0) {
+ ALOGW("can not find link of %s", path);
+ continue;
+ }
+ link[cnt] = '\0';
+ if ((pos = strrchr(link, '/'))) {
+ property_set(DRIVER_NAME_PROP, ++pos);
+ strncpy(buf, pos, PROPERTY_VALUE_MAX - 1);
+ buf[PROPERTY_VALUE_MAX - 1] = '\0';
+ ret = 1;
+ break;
+ }
+ }
+ closedir(netdir);
+ }
+
+ return ret;
+}
+#endif
+
int is_wifi_driver_loaded() {
- char driver_status[PROPERTY_VALUE_MAX];
#ifdef WIFI_DRIVER_MODULE_PATH
+ char modname[PROPERTY_VALUE_MAX];
+ char line[PROPERTY_VALUE_MAX];
FILE *proc;
- char line[sizeof(DRIVER_MODULE_TAG)+10];
-#endif
+ int cnt = property_get(DRIVER_NAME_PROP, modname, NULL);
- if (!property_get(DRIVER_PROP_NAME, driver_status, NULL)
- || strcmp(driver_status, "ok") != 0) {
- return 0; /* driver not loaded */
+ if (!cnt) {
+ if (get_driver_info(modname))
+ cnt = strlen(modname);
+ else if (property_get("wlan.interface", line, NULL))
+ return 1; // found an interface without modname, assume built-in
+ else
+ goto unloaded;
}
-#ifdef WIFI_DRIVER_MODULE_PATH
+ modname[cnt++] = ' ';
+
/*
* If the property says the driver is loaded, check to
* make sure that the property setting isn't just left
*/
if ((proc = fopen(MODULE_FILE, "r")) == NULL) {
ALOGW("Could not open %s: %s", MODULE_FILE, strerror(errno));
- property_set(DRIVER_PROP_NAME, "unloaded");
- return 0;
+ goto unloaded;
}
+
while ((fgets(line, sizeof(line), proc)) != NULL) {
- if (strncmp(line, DRIVER_MODULE_TAG, strlen(DRIVER_MODULE_TAG)) == 0) {
+ if (strncmp(line, modname, cnt) == 0) {
fclose(proc);
return 1;
}
}
fclose(proc);
+
+unloaded:
property_set(DRIVER_PROP_NAME, "unloaded");
return 0;
#else
{
#ifdef WIFI_DRIVER_MODULE_PATH
char driver_status[PROPERTY_VALUE_MAX];
+ char modname[PROPERTY_VALUE_MAX];
+ char modpath[SYSFS_PATH_MAX];
int count = 100; /* wait at most 20 seconds for completion */
if (is_wifi_driver_loaded()) {
return 0;
}
- if (insmod(DRIVER_MODULE_PATH, DRIVER_MODULE_ARG) < 0)
+ if (!property_get(DRIVER_PATH_PROP, modpath, NULL)) {
+ property_get(DRIVER_NAME_PROP, modname, NULL);
+ strcat(modname, ".ko");
+ if (!get_driver_path(modname, MODULE_DEFAULT_DIR, modpath))
+ strcpy(modpath, WIFI_DRIVER_MODULE_PATH);
+ }
+
+ ALOGI("got module path %s", modpath);
+ if (insmod(modpath, DRIVER_MODULE_ARG) < 0)
return -1;
if (strcmp(FIRMWARE_LOADER,"") == 0) {
sched_yield();
while (count-- > 0) {
if (property_get(DRIVER_PROP_NAME, driver_status, NULL)) {
- if (strcmp(driver_status, "ok") == 0)
+ if (strcmp(driver_status, "ok") == 0) {
+ get_driver_info(modname);
return 0;
- else if (strcmp(DRIVER_PROP_NAME, "failed") == 0) {
+ } else if (strcmp(DRIVER_PROP_NAME, "failed") == 0) {
wifi_unload_driver();
return -1;
}
{
usleep(200000); /* allow to finish interface down */
#ifdef WIFI_DRIVER_MODULE_PATH
- if (rmmod(DRIVER_MODULE_NAME) == 0) {
+ char modname[PROPERTY_VALUE_MAX];
+ if (!property_get(DRIVER_NAME_PROP, modname, NULL))
+ return -1;
+
+ if (rmmod(modname) == 0) {
int count = 20; /* wait at most 10 seconds for completion */
while (count-- > 0) {
if (!is_wifi_driver_loaded())
if (count) {
return 0;
}
- return -1;
- } else
- return -1;
+ }
+ return -1;
#else
property_set(DRIVER_PROP_NAME, "unloaded");
return 0;
return 0;
}
-int update_ctrl_interface(const char *config_file) {
-
- int srcfd, destfd;
- int nread;
- char ifc[PROPERTY_VALUE_MAX];
- char *pbuf;
- char *sptr;
- struct stat sb;
-
- if (stat(config_file, &sb) != 0)
- return -1;
-
- pbuf = malloc(sb.st_size + PROPERTY_VALUE_MAX);
- if (!pbuf)
- return 0;
- srcfd = TEMP_FAILURE_RETRY(open(config_file, O_RDONLY));
- if (srcfd < 0) {
- ALOGE("Cannot open \"%s\": %s", config_file, strerror(errno));
- free(pbuf);
- return 0;
- }
- nread = TEMP_FAILURE_RETRY(read(srcfd, pbuf, sb.st_size));
- close(srcfd);
- if (nread < 0) {
- ALOGE("Cannot read \"%s\": %s", config_file, strerror(errno));
- free(pbuf);
- return 0;
- }
-
- if (!strcmp(config_file, SUPP_CONFIG_FILE)) {
- property_get("wifi.interface", ifc, WIFI_TEST_INTERFACE);
- } else {
- strcpy(ifc, CONTROL_IFACE_PATH);
- }
- /*
- * if there is a "ctrl_interface=<value>" entry, re-write it ONLY if it is
- * NOT a directory. The non-directory value option is an Android add-on
- * that allows the control interface to be exchanged through an environment
- * variable (initialized by the "init" program when it starts a service
- * with a "socket" option).
- *
- * The <value> is deemed to be a directory if the "DIR=" form is used or
- * the value begins with "/".
- */
- if ((sptr = strstr(pbuf, "ctrl_interface=")) &&
- (!strstr(pbuf, "ctrl_interface=DIR=")) &&
- (!strstr(pbuf, "ctrl_interface=/"))) {
- char *iptr = sptr + strlen("ctrl_interface=");
- int ilen = 0;
- int mlen = strlen(ifc);
- int nwrite;
- if (strncmp(ifc, iptr, mlen) != 0) {
- ALOGE("ctrl_interface != %s", ifc);
- while (((ilen + (iptr - pbuf)) < nread) && (iptr[ilen] != '\n'))
- ilen++;
- mlen = ((ilen >= mlen) ? ilen : mlen) + 1;
- memmove(iptr + mlen, iptr + ilen + 1, nread - (iptr + ilen + 1 - pbuf));
- memset(iptr, '\n', mlen);
- memcpy(iptr, ifc, strlen(ifc));
- destfd = TEMP_FAILURE_RETRY(open(config_file, O_RDWR, 0660));
- if (destfd < 0) {
- ALOGE("Cannot update \"%s\": %s", config_file, strerror(errno));
- free(pbuf);
- return -1;
- }
- TEMP_FAILURE_RETRY(write(destfd, pbuf, nread + mlen - ilen -1));
- close(destfd);
- }
- }
- free(pbuf);
- return 0;
-}
-
int ensure_config_file_exists(const char *config_file)
{
char buf[2048];
ALOGE("Cannot set RW to \"%s\": %s", config_file, strerror(errno));
return -1;
}
- /* return if filesize is at least 10 bytes */
- if (stat(config_file, &sb) == 0 && sb.st_size > 10) {
- return update_ctrl_interface(config_file);
- }
+ return 0;
} else if (errno != ENOENT) {
ALOGE("Cannot access \"%s\": %s", config_file, strerror(errno));
return -1;
unlink(config_file);
return -1;
}
- return update_ctrl_interface(config_file);
-}
-
-/**
- * wifi_wpa_ctrl_cleanup() - Delete any local UNIX domain socket files that
- * may be left over from clients that were previously connected to
- * wpa_supplicant. This keeps these files from being orphaned in the
- * event of crashes that prevented them from being removed as part
- * of the normal orderly shutdown.
- */
-void wifi_wpa_ctrl_cleanup(void)
-{
- DIR *dir;
- struct dirent entry;
- struct dirent *result;
- size_t dirnamelen;
- size_t maxcopy;
- char pathname[PATH_MAX];
- char *namep;
- char *local_socket_dir = CONFIG_CTRL_IFACE_CLIENT_DIR;
- char *local_socket_prefix = CONFIG_CTRL_IFACE_CLIENT_PREFIX;
-
- if ((dir = opendir(local_socket_dir)) == NULL)
- return;
-
- dirnamelen = (size_t)snprintf(pathname, sizeof(pathname), "%s/", local_socket_dir);
- if (dirnamelen >= sizeof(pathname)) {
- closedir(dir);
- return;
- }
- namep = pathname + dirnamelen;
- maxcopy = PATH_MAX - dirnamelen;
- while (readdir_r(dir, &entry, &result) == 0 && result != NULL) {
- if (strncmp(entry.d_name, local_socket_prefix, strlen(local_socket_prefix)) == 0) {
- if (strlcpy(namep, entry.d_name, maxcopy) < maxcopy) {
- unlink(pathname);
- }
- }
- }
- closedir(dir);
+ return 0;
}
int wifi_start_supplicant(int p2p_supported)
}
/* Check whether already running */
- if (property_get(supplicant_name, supp_status, NULL)
+ if (property_get(supplicant_prop_name, supp_status, NULL)
&& strcmp(supp_status, "running") == 0) {
return 0;
}
}
/* Clear out any stale socket files that might be left over. */
- wifi_wpa_ctrl_cleanup();
+ wpa_ctrl_cleanup();
/* Reset sockets used for exiting from hung state */
- for (i=0; i<MAX_CONNS; i++) {
- exit_sockets[i][0] = exit_sockets[i][1] = -1;
- }
+ exit_sockets[0] = exit_sockets[1] = -1;
#ifdef HAVE_LIBC_SYSTEM_PROPERTIES
/*
*/
pi = __system_property_find(supplicant_prop_name);
if (pi != NULL) {
- serial = pi->serial;
+ serial = __system_property_serial(pi);
}
#endif
- property_get("wifi.interface", primary_iface, WIFI_TEST_INTERFACE);
+ property_get("wlan.interface", primary_iface, WIFI_TEST_INTERFACE);
property_set("ctl.start", supplicant_name);
sched_yield();
pi = __system_property_find(supplicant_prop_name);
}
if (pi != NULL) {
- __system_property_read(pi, NULL, supp_status);
- if (strcmp(supp_status, "running") == 0) {
- return 0;
- } else if (pi->serial != serial &&
- strcmp(supp_status, "stopped") == 0) {
- return -1;
+ /*
+ * property serial updated means that init process is scheduled
+ * after we sched_yield, further property status checking is based on this */
+ if (__system_property_serial(pi) != serial) {
+ __system_property_read(pi, NULL, supp_status);
+ if (strcmp(supp_status, "running") == 0) {
+ return 0;
+ } else if (strcmp(supp_status, "stopped") == 0) {
+ return -1;
+ }
}
}
#else
return -1;
}
-int wifi_connect_on_socket_path(int index, const char *path)
+int wifi_connect_on_socket_path(const char *path)
{
char supp_status[PROPERTY_VALUE_MAX] = {'\0'};
return -1;
}
- ctrl_conn[index] = wpa_ctrl_open(path);
- if (ctrl_conn[index] == NULL) {
+ ctrl_conn = wpa_ctrl_open(path);
+ if (ctrl_conn == NULL) {
ALOGE("Unable to open connection to supplicant on \"%s\": %s",
path, strerror(errno));
return -1;
}
- monitor_conn[index] = wpa_ctrl_open(path);
- if (monitor_conn[index] == NULL) {
- wpa_ctrl_close(ctrl_conn[index]);
- ctrl_conn[index] = NULL;
+ monitor_conn = wpa_ctrl_open(path);
+ if (monitor_conn == NULL) {
+ wpa_ctrl_close(ctrl_conn);
+ ctrl_conn = NULL;
return -1;
}
- if (wpa_ctrl_attach(monitor_conn[index]) != 0) {
- wpa_ctrl_close(monitor_conn[index]);
- wpa_ctrl_close(ctrl_conn[index]);
- ctrl_conn[index] = monitor_conn[index] = NULL;
+ if (wpa_ctrl_attach(monitor_conn) != 0) {
+ wpa_ctrl_close(monitor_conn);
+ wpa_ctrl_close(ctrl_conn);
+ ctrl_conn = monitor_conn = NULL;
return -1;
}
- if (socketpair(AF_UNIX, SOCK_STREAM, 0, exit_sockets[index]) == -1) {
- wpa_ctrl_close(monitor_conn[index]);
- wpa_ctrl_close(ctrl_conn[index]);
- ctrl_conn[index] = monitor_conn[index] = NULL;
+ if (socketpair(AF_UNIX, SOCK_STREAM, 0, exit_sockets) == -1) {
+ wpa_ctrl_close(monitor_conn);
+ wpa_ctrl_close(ctrl_conn);
+ ctrl_conn = monitor_conn = NULL;
return -1;
}
}
/* Establishes the control and monitor socket connections on the interface */
-int wifi_connect_to_supplicant(const char *ifname)
+int wifi_connect_to_supplicant()
{
- char path[256];
+ static char path[PATH_MAX];
- if (is_primary_interface(ifname)) {
- if (access(IFACE_DIR, F_OK) == 0) {
- snprintf(path, sizeof(path), "%s/%s", IFACE_DIR, primary_iface);
- } else {
- strlcpy(path, primary_iface, sizeof(path));
- }
- return wifi_connect_on_socket_path(PRIMARY, path);
+ if (access(IFACE_DIR, F_OK) == 0) {
+ snprintf(path, sizeof(path), "%s/%s", IFACE_DIR, primary_iface);
} else {
- sprintf(path, "%s/%s", CONTROL_IFACE_PATH, ifname);
- return wifi_connect_on_socket_path(SECONDARY, path);
+ snprintf(path, sizeof(path), "@android:wpa_%s", primary_iface);
}
+ return wifi_connect_on_socket_path(path);
}
-int wifi_send_command(int index, const char *cmd, char *reply, size_t *reply_len)
+int wifi_send_command(const char *cmd, char *reply, size_t *reply_len)
{
int ret;
-
- if (ctrl_conn[index] == NULL) {
+ if (ctrl_conn == NULL) {
ALOGV("Not connected to wpa_supplicant - \"%s\" command dropped.\n", cmd);
return -1;
}
- ret = wpa_ctrl_request(ctrl_conn[index], cmd, strlen(cmd), reply, reply_len, NULL);
+ ret = wpa_ctrl_request(ctrl_conn, cmd, strlen(cmd), reply, reply_len, NULL);
if (ret == -2) {
ALOGD("'%s' command timed out.\n", cmd);
/* unblocks the monitor receive socket for termination */
- TEMP_FAILURE_RETRY(write(exit_sockets[index][0], "T", 1));
+ TEMP_FAILURE_RETRY(write(exit_sockets[0], "T", 1));
return -2;
} else if (ret < 0 || strncmp(reply, "FAIL", 4) == 0) {
return -1;
return 0;
}
-int wifi_ctrl_recv(int index, char *reply, size_t *reply_len)
+int wifi_supplicant_connection_active()
+{
+ char supp_status[PROPERTY_VALUE_MAX] = {'\0'};
+
+ if (property_get(supplicant_prop_name, supp_status, NULL)) {
+ if (strcmp(supp_status, "stopped") == 0)
+ return -1;
+ }
+
+ return 0;
+}
+
+int wifi_ctrl_recv(char *reply, size_t *reply_len)
{
int res;
- int ctrlfd = wpa_ctrl_get_fd(monitor_conn[index]);
+ int ctrlfd = wpa_ctrl_get_fd(monitor_conn);
struct pollfd rfds[2];
memset(rfds, 0, 2 * sizeof(struct pollfd));
rfds[0].fd = ctrlfd;
rfds[0].events |= POLLIN;
- rfds[1].fd = exit_sockets[index][1];
+ rfds[1].fd = exit_sockets[1];
rfds[1].events |= POLLIN;
- res = TEMP_FAILURE_RETRY(poll(rfds, 2, -1));
- if (res < 0) {
- ALOGE("Error poll = %d", res);
- return res;
- }
- if (rfds[0].revents & POLLIN) {
- return wpa_ctrl_recv(monitor_conn[index], reply, reply_len);
- } else if (rfds[1].revents & POLLIN) {
- /* Close only the p2p sockets on receive side
- * see wifi_close_supplicant_connection()
- */
- if (index == SECONDARY) {
- ALOGD("close sockets %d", index);
- wifi_close_sockets(index);
+ do {
+ res = TEMP_FAILURE_RETRY(poll(rfds, 2, 30000));
+ if (res < 0) {
+ ALOGE("Error poll = %d", res);
+ return res;
+ } else if (res == 0) {
+ /* timed out, check if supplicant is active
+ * or not ..
+ */
+ res = wifi_supplicant_connection_active();
+ if (res < 0)
+ return -2;
}
+ } while (res == 0);
+
+ if (rfds[0].revents & POLLIN) {
+ return wpa_ctrl_recv(monitor_conn, reply, reply_len);
}
+
+ /* it is not rfds[0], then it must be rfts[1] (i.e. the exit socket)
+ * or we timed out. In either case, this call has failed ..
+ */
return -2;
}
-int wifi_wait_on_socket(int index, char *buf, size_t buflen)
+int wifi_wait_on_socket(char *buf, size_t buflen)
{
size_t nread = buflen - 1;
- int fd;
- fd_set rfds;
int result;
- struct timeval tval;
- struct timeval *tptr;
+ char *match, *match2;
- if (monitor_conn[index] == NULL) {
- ALOGD("Connection closed\n");
- strncpy(buf, WPA_EVENT_TERMINATING " - connection closed", buflen-1);
- buf[buflen-1] = '\0';
- return strlen(buf);
+ if (monitor_conn == NULL) {
+ return snprintf(buf, buflen, "IFNAME=%s %s - connection closed",
+ primary_iface, WPA_EVENT_TERMINATING);
}
- result = wifi_ctrl_recv(index, buf, &nread);
+ result = wifi_ctrl_recv(buf, &nread);
/* Terminate reception on exit socket */
if (result == -2) {
- strncpy(buf, WPA_EVENT_TERMINATING " - connection closed", buflen-1);
- buf[buflen-1] = '\0';
- return strlen(buf);
+ return snprintf(buf, buflen, "IFNAME=%s %s - connection closed",
+ primary_iface, WPA_EVENT_TERMINATING);
}
if (result < 0) {
ALOGD("wifi_ctrl_recv failed: %s\n", strerror(errno));
- strncpy(buf, WPA_EVENT_TERMINATING " - recv error", buflen-1);
- buf[buflen-1] = '\0';
- return strlen(buf);
+ return snprintf(buf, buflen, "IFNAME=%s %s - recv error",
+ primary_iface, WPA_EVENT_TERMINATING);
}
buf[nread] = '\0';
/* Check for EOF on the socket */
if (result == 0 && nread == 0) {
/* Fabricate an event to pass up */
ALOGD("Received EOF on supplicant socket\n");
- strncpy(buf, WPA_EVENT_TERMINATING " - signal 0 received", buflen-1);
- buf[buflen-1] = '\0';
- return strlen(buf);
+ return snprintf(buf, buflen, "IFNAME=%s %s - signal 0 received",
+ primary_iface, WPA_EVENT_TERMINATING);
}
/*
* Events strings are in the format
*
+ * IFNAME=iface <N>CTRL-EVENT-XXX
+ * or
* <N>CTRL-EVENT-XXX
*
* where N is the message level in numerical form (0=VERBOSE, 1=DEBUG,
* etc.) and XXX is the event name. The level information is not useful
* to us, so strip it off.
*/
- if (buf[0] == '<') {
- char *match = strchr(buf, '>');
+
+ if (strncmp(buf, IFNAME, IFNAMELEN) == 0) {
+ match = strchr(buf, ' ');
+ if (match != NULL) {
+ if (match[1] == '<') {
+ match2 = strchr(match + 2, '>');
+ if (match2 != NULL) {
+ nread -= (match2 - match);
+ memmove(match + 1, match2 + 1, nread - (match - buf) + 1);
+ }
+ }
+ } else {
+ return snprintf(buf, buflen, "%s", WPA_EVENT_IGNORE);
+ }
+ } 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)) {
}
}
-int wifi_command(const char *ifname, const char *command, char *reply, size_t *reply_len)
+int wifi_command(const char *command, char *reply, size_t *reply_len)
{
- 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)