summaryrefslogtreecommitdiffstats
path: root/wifi
diff options
context:
space:
mode:
authorDmitry Shmidt <dimitrysh@google.com>2011-01-04 16:35:18 -0800
committerDmitry Shmidt <dimitrysh@google.com>2011-01-05 11:32:03 -0800
commit0e9f488e672abf0d14580261998cfd9c7211c112 (patch)
treee0466d59ca6e206c4e7409c246d5d5a0b12311a0 /wifi
parent8a5b197b3d5878e3f1cf49c9c38c090456107e87 (diff)
downloadhardware_libhardware_legacy-0e9f488e672abf0d14580261998cfd9c7211c112.zip
hardware_libhardware_legacy-0e9f488e672abf0d14580261998cfd9c7211c112.tar.gz
hardware_libhardware_legacy-0e9f488e672abf0d14580261998cfd9c7211c112.tar.bz2
wifi: Update wpa_supplicant.conf interface in case of mismatch
Change-Id: Iea7432bd96df2c1474e5af1788225322c9b78307 Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
Diffstat (limited to 'wifi')
-rw-r--r--wifi/wifi.c65
1 files changed, 54 insertions, 11 deletions
diff --git a/wifi/wifi.c b/wifi/wifi.c
index 93c1ac7..0f62c04 100644
--- a/wifi/wifi.c
+++ b/wifi/wifi.c
@@ -207,15 +207,15 @@ int wifi_unload_driver()
int count = 20; /* wait at most 10 seconds for completion */
if (rmmod(DRIVER_MODULE_NAME) == 0) {
- while (count-- > 0) {
- if (!is_wifi_driver_loaded())
- break;
- usleep(500000);
- }
- if (count) {
- return 0;
- }
- return -1;
+ while (count-- > 0) {
+ if (!is_wifi_driver_loaded())
+ break;
+ usleep(500000);
+ }
+ if (count) {
+ return 0;
+ }
+ return -1;
} else
return -1;
}
@@ -223,13 +223,56 @@ int wifi_unload_driver()
int ensure_config_file_exists()
{
char buf[2048];
+ char ifc[PROPERTY_VALUE_MAX];
+ char *sptr;
+ char *pbuf;
int srcfd, destfd;
struct stat sb;
int nread;
if (access(SUPP_CONFIG_FILE, R_OK|W_OK) == 0) {
- /* return if filesize is atleast 10 bytes */
+ /* return if filesize is at least 10 bytes */
if (stat(SUPP_CONFIG_FILE, &sb) == 0 && sb.st_size > 10) {
+ pbuf = malloc(sb.st_size + PROPERTY_VALUE_MAX);
+ if (!pbuf)
+ return 0;
+ srcfd = open(SUPP_CONFIG_FILE, O_RDONLY);
+ if (srcfd < 0) {
+ LOGE("Cannot open \"%s\": %s", SUPP_CONFIG_FILE, strerror(errno));
+ free(pbuf);
+ return 0;
+ }
+ nread = read(srcfd, pbuf, sb.st_size);
+ close(srcfd);
+ if (nread < 0) {
+ LOGE("Cannot read \"%s\": %s", SUPP_CONFIG_FILE, strerror(errno));
+ free(pbuf);
+ return 0;
+ }
+ property_get("wifi.interface", ifc, WIFI_TEST_INTERFACE);
+ if ((sptr = strstr(pbuf, "ctrl_interface="))) {
+ char *iptr = sptr + strlen("ctrl_interface=");
+ int ilen = 0;
+ int mlen = strlen(ifc);
+ if (strncmp(ifc, iptr, mlen) != 0) {
+ LOGE("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 = open(SUPP_CONFIG_FILE, O_RDWR, 0660);
+ if (destfd < 0) {
+ LOGE("Cannot update \"%s\": %s", SUPP_CONFIG_FILE, strerror(errno));
+ free(pbuf);
+ return -1;
+ }
+ write(destfd, pbuf, nread);
+ close(destfd);
+ }
+ }
+ free(pbuf);
return 0;
}
} else if (errno != ENOENT) {
@@ -441,7 +484,7 @@ int wifi_wait_for_event(char *buf, size_t buflen)
int result;
struct timeval tval;
struct timeval *tptr;
-
+
if (monitor_conn == NULL) {
LOGD("Connection closed\n");
strncpy(buf, WPA_EVENT_TERMINATING " - connection closed", buflen-1);