2 * Copyright 2008, The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 #include <sys/socket.h>
26 #include "hardware_legacy/wifi.h"
27 #ifdef LIBWPA_CLIENT_EXISTS
28 #include "libwpa_client/wpa_ctrl.h"
31 #define LOG_TAG "WifiHW"
32 #include "cutils/log.h"
33 #include "cutils/memory.h"
34 #include "cutils/misc.h"
35 #include "cutils/properties.h"
36 #include "private/android_filesystem_config.h"
37 #ifdef HAVE_LIBC_SYSTEM_PROPERTIES
38 #define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
39 #include <sys/_system_properties.h>
43 extern int ifc_init();
44 extern void ifc_close();
45 extern char *dhcp_lasterror();
46 extern void get_dhcp_info();
47 extern int init_module(void *, unsigned long, const char *);
48 extern int delete_module(const char *, unsigned int);
49 void wifi_close_sockets();
51 #ifndef LIBWPA_CLIENT_EXISTS
52 #define WPA_EVENT_TERMINATING "CTRL-EVENT-TERMINATING "
54 void wpa_ctrl_cleanup(void) {}
55 struct wpa_ctrl *wpa_ctrl_open(const char *ctrl_path) { return NULL; }
56 void wpa_ctrl_close(struct wpa_ctrl *ctrl) {}
57 int wpa_ctrl_request(struct wpa_ctrl *ctrl, const char *cmd, size_t cmd_len,
58 char *reply, size_t *reply_len, void (*msg_cb)(char *msg, size_t len))
60 int wpa_ctrl_attach(struct wpa_ctrl *ctrl) { return 0; }
61 int wpa_ctrl_detach(struct wpa_ctrl *ctrl) { return 0; }
62 int wpa_ctrl_recv(struct wpa_ctrl *ctrl, char *reply, size_t *reply_len)
64 int wpa_ctrl_get_fd(struct wpa_ctrl *ctrl) { return 0; }
67 static struct wpa_ctrl *ctrl_conn;
68 static struct wpa_ctrl *monitor_conn;
70 /* socket pair used to exit from a blocking read */
71 static int exit_sockets[2];
73 static char primary_iface[PROPERTY_VALUE_MAX];
74 // TODO: use new ANDROID_SOCKET mechanism, once support for multiple
77 #ifndef WIFI_DRIVER_MODULE_ARG
78 #define WIFI_DRIVER_MODULE_ARG ""
80 #ifndef WIFI_FIRMWARE_LOADER
81 #define WIFI_FIRMWARE_LOADER ""
83 #define WIFI_TEST_INTERFACE "sta"
85 #ifndef WIFI_DRIVER_FW_PATH_STA
86 #define WIFI_DRIVER_FW_PATH_STA NULL
88 #ifndef WIFI_DRIVER_FW_PATH_AP
89 #define WIFI_DRIVER_FW_PATH_AP NULL
91 #ifndef WIFI_DRIVER_FW_PATH_P2P
92 #define WIFI_DRIVER_FW_PATH_P2P NULL
95 #ifndef WIFI_DRIVER_FW_PATH_PARAM
96 #define WIFI_DRIVER_FW_PATH_PARAM "/sys/module/wlan/parameters/fwpath"
99 #define WIFI_DRIVER_LOADER_DELAY 1000000
101 static const char IFACE_DIR[] = "/data/system/wpa_supplicant";
102 #ifdef WIFI_DRIVER_MODULE_PATH
103 static const char DRIVER_MODULE_NAME[] = WIFI_DRIVER_MODULE_NAME;
104 static const char DRIVER_MODULE_TAG[] = WIFI_DRIVER_MODULE_NAME " ";
105 static const char DRIVER_MODULE_PATH[] = WIFI_DRIVER_MODULE_PATH;
106 static const char DRIVER_MODULE_ARG[] = WIFI_DRIVER_MODULE_ARG;
108 static const char FIRMWARE_LOADER[] = WIFI_FIRMWARE_LOADER;
109 static const char DRIVER_PROP_NAME[] = "wlan.driver.status";
110 static const char SUPPLICANT_NAME[] = "wpa_supplicant";
111 static const char SUPP_PROP_NAME[] = "init.svc.wpa_supplicant";
112 static const char P2P_SUPPLICANT_NAME[] = "p2p_supplicant";
113 static const char P2P_PROP_NAME[] = "init.svc.p2p_supplicant";
114 static const char SUPP_CONFIG_TEMPLATE[]= "/system/etc/wifi/wpa_supplicant.conf";
115 static const char SUPP_CONFIG_FILE[] = "/data/misc/wifi/wpa_supplicant.conf";
116 static const char P2P_CONFIG_FILE[] = "/data/misc/wifi/p2p_supplicant.conf";
117 static const char CONTROL_IFACE_PATH[] = "/data/misc/wifi/sockets";
118 static const char MODULE_FILE[] = "/proc/modules";
120 static const char IFNAME[] = "IFNAME=";
121 #define IFNAMELEN (sizeof(IFNAME) - 1)
122 static const char WPA_EVENT_IGNORE[] = "CTRL-EVENT-IGNORE ";
124 static const char SUPP_ENTROPY_FILE[] = WIFI_ENTROPY_FILE;
125 static unsigned char dummy_key[21] = { 0x02, 0x11, 0xbe, 0x33, 0x43, 0x35,
126 0x68, 0x47, 0x84, 0x99, 0xa9, 0x2b,
127 0x1c, 0xd3, 0xee, 0xff, 0xf1, 0xe2,
130 /* Is either SUPPLICANT_NAME or P2P_SUPPLICANT_NAME */
131 static char supplicant_name[PROPERTY_VALUE_MAX];
132 /* Is either SUPP_PROP_NAME or P2P_PROP_NAME */
133 static char supplicant_prop_name[PROPERTY_KEY_MAX];
135 static int insmod(const char *filename, const char *args)
141 module = load_file(filename, &size);
145 ret = init_module(module, size, args);
152 static int rmmod(const char *modname)
157 while (maxtry-- > 0) {
158 ret = delete_module(modname, O_NONBLOCK | O_EXCL);
159 if (ret < 0 && errno == EAGAIN)
166 ALOGD("Unable to unload driver module \"%s\": %s\n",
167 modname, strerror(errno));
171 int do_dhcp_request(int *ipaddr, int *gateway, int *mask,
172 int *dns1, int *dns2, int *server, int *lease) {
173 /* For test driver, always report success */
174 if (strcmp(primary_iface, WIFI_TEST_INTERFACE) == 0)
180 if (do_dhcp(primary_iface) < 0) {
185 get_dhcp_info(ipaddr, gateway, mask, dns1, dns2, server, lease);
189 const char *get_dhcp_error_string() {
190 return dhcp_lasterror();
193 int is_wifi_driver_loaded() {
194 char driver_status[PROPERTY_VALUE_MAX];
195 #ifdef WIFI_DRIVER_MODULE_PATH
197 char line[sizeof(DRIVER_MODULE_TAG)+10];
200 if (!property_get(DRIVER_PROP_NAME, driver_status, NULL)
201 || strcmp(driver_status, "ok") != 0) {
202 return 0; /* driver not loaded */
204 #ifdef WIFI_DRIVER_MODULE_PATH
206 * If the property says the driver is loaded, check to
207 * make sure that the property setting isn't just left
208 * over from a previous manual shutdown or a runtime
211 if ((proc = fopen(MODULE_FILE, "r")) == NULL) {
212 ALOGW("Could not open %s: %s", MODULE_FILE, strerror(errno));
213 property_set(DRIVER_PROP_NAME, "unloaded");
216 while ((fgets(line, sizeof(line), proc)) != NULL) {
217 if (strncmp(line, DRIVER_MODULE_TAG, strlen(DRIVER_MODULE_TAG)) == 0) {
223 property_set(DRIVER_PROP_NAME, "unloaded");
230 int wifi_load_driver()
232 #ifdef WIFI_DRIVER_MODULE_PATH
233 char driver_status[PROPERTY_VALUE_MAX];
234 int count = 100; /* wait at most 20 seconds for completion */
236 if (is_wifi_driver_loaded()) {
240 if (insmod(DRIVER_MODULE_PATH, DRIVER_MODULE_ARG) < 0)
243 if (strcmp(FIRMWARE_LOADER,"") == 0) {
244 /* usleep(WIFI_DRIVER_LOADER_DELAY); */
245 property_set(DRIVER_PROP_NAME, "ok");
248 property_set("ctl.start", FIRMWARE_LOADER);
251 while (count-- > 0) {
252 if (property_get(DRIVER_PROP_NAME, driver_status, NULL)) {
253 if (strcmp(driver_status, "ok") == 0)
255 else if (strcmp(DRIVER_PROP_NAME, "failed") == 0) {
256 wifi_unload_driver();
262 property_set(DRIVER_PROP_NAME, "timeout");
263 wifi_unload_driver();
266 property_set(DRIVER_PROP_NAME, "ok");
271 int wifi_unload_driver()
273 usleep(200000); /* allow to finish interface down */
274 #ifdef WIFI_DRIVER_MODULE_PATH
275 if (rmmod(DRIVER_MODULE_NAME) == 0) {
276 int count = 20; /* wait at most 10 seconds for completion */
277 while (count-- > 0) {
278 if (!is_wifi_driver_loaded())
282 usleep(500000); /* allow card removal */
290 property_set(DRIVER_PROP_NAME, "unloaded");
295 int ensure_entropy_file_exists()
300 ret = access(SUPP_ENTROPY_FILE, R_OK|W_OK);
301 if ((ret == 0) || (errno == EACCES)) {
303 (chmod(SUPP_ENTROPY_FILE, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) != 0)) {
304 ALOGE("Cannot set RW to \"%s\": %s", SUPP_ENTROPY_FILE, strerror(errno));
309 destfd = TEMP_FAILURE_RETRY(open(SUPP_ENTROPY_FILE, O_CREAT|O_RDWR, 0660));
311 ALOGE("Cannot create \"%s\": %s", SUPP_ENTROPY_FILE, strerror(errno));
315 if (TEMP_FAILURE_RETRY(write(destfd, dummy_key, sizeof(dummy_key))) != sizeof(dummy_key)) {
316 ALOGE("Error writing \"%s\": %s", SUPP_ENTROPY_FILE, strerror(errno));
322 /* chmod is needed because open() didn't set permisions properly */
323 if (chmod(SUPP_ENTROPY_FILE, 0660) < 0) {
324 ALOGE("Error changing permissions of %s to 0660: %s",
325 SUPP_ENTROPY_FILE, strerror(errno));
326 unlink(SUPP_ENTROPY_FILE);
330 if (chown(SUPP_ENTROPY_FILE, AID_SYSTEM, AID_WIFI) < 0) {
331 ALOGE("Error changing group ownership of %s to %d: %s",
332 SUPP_ENTROPY_FILE, AID_WIFI, strerror(errno));
333 unlink(SUPP_ENTROPY_FILE);
339 int update_ctrl_interface(const char *config_file) {
343 char ifc[PROPERTY_VALUE_MAX];
349 if (stat(config_file, &sb) != 0)
352 pbuf = malloc(sb.st_size + PROPERTY_VALUE_MAX);
355 srcfd = TEMP_FAILURE_RETRY(open(config_file, O_RDONLY));
357 ALOGE("Cannot open \"%s\": %s", config_file, strerror(errno));
361 nread = TEMP_FAILURE_RETRY(read(srcfd, pbuf, sb.st_size));
364 ALOGE("Cannot read \"%s\": %s", config_file, strerror(errno));
369 if (!strcmp(config_file, SUPP_CONFIG_FILE)) {
370 property_get("wifi.interface", ifc, WIFI_TEST_INTERFACE);
372 strcpy(ifc, CONTROL_IFACE_PATH);
374 /* Assume file is invalid to begin with */
377 * if there is a "ctrl_interface=<value>" entry, re-write it ONLY if it is
378 * NOT a directory. The non-directory value option is an Android add-on
379 * that allows the control interface to be exchanged through an environment
380 * variable (initialized by the "init" program when it starts a service
381 * with a "socket" option).
383 * The <value> is deemed to be a directory if the "DIR=" form is used or
384 * the value begins with "/".
386 if ((sptr = strstr(pbuf, "ctrl_interface="))) {
388 if ((!strstr(pbuf, "ctrl_interface=DIR=")) &&
389 (!strstr(pbuf, "ctrl_interface=/"))) {
390 char *iptr = sptr + strlen("ctrl_interface=");
392 int mlen = strlen(ifc);
394 if (strncmp(ifc, iptr, mlen) != 0) {
395 ALOGE("ctrl_interface != %s", ifc);
396 while (((ilen + (iptr - pbuf)) < nread) && (iptr[ilen] != '\n'))
398 mlen = ((ilen >= mlen) ? ilen : mlen) + 1;
399 memmove(iptr + mlen, iptr + ilen + 1, nread - (iptr + ilen + 1 - pbuf));
400 memset(iptr, '\n', mlen);
401 memcpy(iptr, ifc, strlen(ifc));
402 destfd = TEMP_FAILURE_RETRY(open(config_file, O_RDWR, 0660));
404 ALOGE("Cannot update \"%s\": %s", config_file, strerror(errno));
408 TEMP_FAILURE_RETRY(write(destfd, pbuf, nread + mlen - ilen -1));
417 int ensure_config_file_exists(const char *config_file)
425 ret = access(config_file, R_OK|W_OK);
426 if ((ret == 0) || (errno == EACCES)) {
428 (chmod(config_file, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) != 0)) {
429 ALOGE("Cannot set RW to \"%s\": %s", config_file, strerror(errno));
432 /* return if we were able to update control interface properly */
433 if (update_ctrl_interface(config_file) >=0) {
436 /* This handles the scenario where the file had bad data
437 * for some reason. We continue and recreate the file.
440 } else if (errno != ENOENT) {
441 ALOGE("Cannot access \"%s\": %s", config_file, strerror(errno));
445 srcfd = TEMP_FAILURE_RETRY(open(SUPP_CONFIG_TEMPLATE, O_RDONLY));
447 ALOGE("Cannot open \"%s\": %s", SUPP_CONFIG_TEMPLATE, strerror(errno));
451 destfd = TEMP_FAILURE_RETRY(open(config_file, O_CREAT|O_RDWR, 0660));
454 ALOGE("Cannot create \"%s\": %s", config_file, strerror(errno));
458 while ((nread = TEMP_FAILURE_RETRY(read(srcfd, buf, sizeof(buf)))) != 0) {
460 ALOGE("Error reading \"%s\": %s", SUPP_CONFIG_TEMPLATE, strerror(errno));
466 TEMP_FAILURE_RETRY(write(destfd, buf, nread));
472 /* chmod is needed because open() didn't set permisions properly */
473 if (chmod(config_file, 0660) < 0) {
474 ALOGE("Error changing permissions of %s to 0660: %s",
475 config_file, strerror(errno));
480 if (chown(config_file, AID_SYSTEM, AID_WIFI) < 0) {
481 ALOGE("Error changing group ownership of %s to %d: %s",
482 config_file, AID_WIFI, strerror(errno));
486 return update_ctrl_interface(config_file);
489 int wifi_start_supplicant(int p2p_supported)
491 char supp_status[PROPERTY_VALUE_MAX] = {'\0'};
492 int count = 200; /* wait at most 20 seconds for completion */
493 #ifdef HAVE_LIBC_SYSTEM_PROPERTIES
495 unsigned serial = 0, i;
499 strcpy(supplicant_name, P2P_SUPPLICANT_NAME);
500 strcpy(supplicant_prop_name, P2P_PROP_NAME);
502 /* Ensure p2p config file is created */
503 if (ensure_config_file_exists(P2P_CONFIG_FILE) < 0) {
504 ALOGE("Failed to create a p2p config file");
509 strcpy(supplicant_name, SUPPLICANT_NAME);
510 strcpy(supplicant_prop_name, SUPP_PROP_NAME);
513 /* Check whether already running */
514 if (property_get(supplicant_prop_name, supp_status, NULL)
515 && strcmp(supp_status, "running") == 0) {
519 /* Before starting the daemon, make sure its config file exists */
520 if (ensure_config_file_exists(SUPP_CONFIG_FILE) < 0) {
521 ALOGE("Wi-Fi will not be enabled");
525 if (ensure_entropy_file_exists() < 0) {
526 ALOGE("Wi-Fi entropy file was not created");
529 /* Clear out any stale socket files that might be left over. */
532 /* Reset sockets used for exiting from hung state */
533 exit_sockets[0] = exit_sockets[1] = -1;
535 #ifdef HAVE_LIBC_SYSTEM_PROPERTIES
537 * Get a reference to the status property, so we can distinguish
538 * the case where it goes stopped => running => stopped (i.e.,
539 * it start up, but fails right away) from the case in which
540 * it starts in the stopped state and never manages to start
543 pi = __system_property_find(supplicant_prop_name);
545 serial = __system_property_serial(pi);
548 property_get("wifi.interface", primary_iface, WIFI_TEST_INTERFACE);
550 property_set("ctl.start", supplicant_name);
553 while (count-- > 0) {
554 #ifdef HAVE_LIBC_SYSTEM_PROPERTIES
556 pi = __system_property_find(supplicant_prop_name);
560 * property serial updated means that init process is scheduled
561 * after we sched_yield, further property status checking is based on this */
562 if (__system_property_serial(pi) != serial) {
563 __system_property_read(pi, NULL, supp_status);
564 if (strcmp(supp_status, "running") == 0) {
566 } else if (strcmp(supp_status, "stopped") == 0) {
572 if (property_get(supplicant_prop_name, supp_status, NULL)) {
573 if (strcmp(supp_status, "running") == 0)
582 int wifi_stop_supplicant(int p2p_supported)
584 char supp_status[PROPERTY_VALUE_MAX] = {'\0'};
585 int count = 50; /* wait at most 5 seconds for completion */
588 strcpy(supplicant_name, P2P_SUPPLICANT_NAME);
589 strcpy(supplicant_prop_name, P2P_PROP_NAME);
591 strcpy(supplicant_name, SUPPLICANT_NAME);
592 strcpy(supplicant_prop_name, SUPP_PROP_NAME);
595 /* Check whether supplicant already stopped */
596 if (property_get(supplicant_prop_name, supp_status, NULL)
597 && strcmp(supp_status, "stopped") == 0) {
601 property_set("ctl.stop", supplicant_name);
604 while (count-- > 0) {
605 if (property_get(supplicant_prop_name, supp_status, NULL)) {
606 if (strcmp(supp_status, "stopped") == 0)
611 ALOGE("Failed to stop supplicant");
615 int wifi_connect_on_socket_path(const char *path)
617 char supp_status[PROPERTY_VALUE_MAX] = {'\0'};
619 /* Make sure supplicant is running */
620 if (!property_get(supplicant_prop_name, supp_status, NULL)
621 || strcmp(supp_status, "running") != 0) {
622 ALOGE("Supplicant not running, cannot connect");
626 ctrl_conn = wpa_ctrl_open(path);
627 if (ctrl_conn == NULL) {
628 ALOGE("Unable to open connection to supplicant on \"%s\": %s",
629 path, strerror(errno));
632 monitor_conn = wpa_ctrl_open(path);
633 if (monitor_conn == NULL) {
634 wpa_ctrl_close(ctrl_conn);
638 if (wpa_ctrl_attach(monitor_conn) != 0) {
639 wpa_ctrl_close(monitor_conn);
640 wpa_ctrl_close(ctrl_conn);
641 ctrl_conn = monitor_conn = NULL;
645 if (socketpair(AF_UNIX, SOCK_STREAM, 0, exit_sockets) == -1) {
646 wpa_ctrl_close(monitor_conn);
647 wpa_ctrl_close(ctrl_conn);
648 ctrl_conn = monitor_conn = NULL;
655 /* Establishes the control and monitor socket connections on the interface */
656 int wifi_connect_to_supplicant()
658 static char path[PATH_MAX];
660 if (access(IFACE_DIR, F_OK) == 0) {
661 snprintf(path, sizeof(path), "%s/%s", IFACE_DIR, primary_iface);
663 snprintf(path, sizeof(path), "@android:wpa_%s", primary_iface);
665 return wifi_connect_on_socket_path(path);
668 int wifi_send_command(const char *cmd, char *reply, size_t *reply_len)
671 if (ctrl_conn == NULL) {
672 ALOGV("Not connected to wpa_supplicant - \"%s\" command dropped.\n", cmd);
675 ret = wpa_ctrl_request(ctrl_conn, cmd, strlen(cmd), reply, reply_len, NULL);
677 ALOGD("'%s' command timed out.\n", cmd);
678 /* unblocks the monitor receive socket for termination */
679 TEMP_FAILURE_RETRY(write(exit_sockets[0], "T", 1));
681 } else if (ret < 0 || strncmp(reply, "FAIL", 4) == 0) {
684 if (strncmp(cmd, "PING", 4) == 0) {
685 reply[*reply_len] = '\0';
690 int wifi_ctrl_recv(char *reply, size_t *reply_len)
693 int ctrlfd = wpa_ctrl_get_fd(monitor_conn);
694 struct pollfd rfds[2];
696 memset(rfds, 0, 2 * sizeof(struct pollfd));
698 rfds[0].events |= POLLIN;
699 rfds[1].fd = exit_sockets[1];
700 rfds[1].events |= POLLIN;
701 res = TEMP_FAILURE_RETRY(poll(rfds, 2, -1));
703 ALOGE("Error poll = %d", res);
706 if (rfds[0].revents & POLLIN) {
707 return wpa_ctrl_recv(monitor_conn, reply, reply_len);
710 /* it is not rfds[0], then it must be rfts[1] (i.e. the exit socket)
711 * or we timed out. In either case, this call has failed ..
716 int wifi_wait_on_socket(char *buf, size_t buflen)
718 size_t nread = buflen - 1;
720 char *match, *match2;
722 if (monitor_conn == NULL) {
723 return snprintf(buf, buflen, WPA_EVENT_TERMINATING " - connection closed");
726 result = wifi_ctrl_recv(buf, &nread);
728 /* Terminate reception on exit socket */
730 return snprintf(buf, buflen, WPA_EVENT_TERMINATING " - connection closed");
734 ALOGD("wifi_ctrl_recv failed: %s\n", strerror(errno));
735 return snprintf(buf, buflen, WPA_EVENT_TERMINATING " - recv error");
738 /* Check for EOF on the socket */
739 if (result == 0 && nread == 0) {
740 /* Fabricate an event to pass up */
741 ALOGD("Received EOF on supplicant socket\n");
742 return snprintf(buf, buflen, WPA_EVENT_TERMINATING " - signal 0 received");
745 * Events strings are in the format
747 * IFNAME=iface <N>CTRL-EVENT-XXX
751 * where N is the message level in numerical form (0=VERBOSE, 1=DEBUG,
752 * etc.) and XXX is the event name. The level information is not useful
753 * to us, so strip it off.
756 if (strncmp(buf, IFNAME, IFNAMELEN) == 0) {
757 match = strchr(buf, ' ');
759 if (match[1] == '<') {
760 match2 = strchr(match + 2, '>');
761 if (match2 != NULL) {
762 nread -= (match2 - match);
763 memmove(match + 1, match2 + 1, nread - (match - buf) + 1);
767 return snprintf(buf, buflen, "%s", WPA_EVENT_IGNORE);
769 } else if (buf[0] == '<') {
770 match = strchr(buf, '>');
772 nread -= (match + 1 - buf);
773 memmove(buf, match + 1, nread + 1);
774 ALOGV("supplicant generated event without interface - %s\n", buf);
777 /* let the event go as is! */
778 ALOGW("supplicant generated event without interface and without message level - %s\n", buf);
784 int wifi_wait_for_event(char *buf, size_t buflen)
786 return wifi_wait_on_socket(buf, buflen);
789 void wifi_close_sockets()
791 if (ctrl_conn != NULL) {
792 wpa_ctrl_close(ctrl_conn);
796 if (monitor_conn != NULL) {
797 wpa_ctrl_close(monitor_conn);
801 if (exit_sockets[0] >= 0) {
802 close(exit_sockets[0]);
803 exit_sockets[0] = -1;
806 if (exit_sockets[1] >= 0) {
807 close(exit_sockets[1]);
808 exit_sockets[1] = -1;
812 void wifi_close_supplicant_connection()
814 char supp_status[PROPERTY_VALUE_MAX] = {'\0'};
815 int count = 50; /* wait at most 5 seconds to ensure init has stopped stupplicant */
817 wifi_close_sockets();
819 while (count-- > 0) {
820 if (property_get(supplicant_prop_name, supp_status, NULL)) {
821 if (strcmp(supp_status, "stopped") == 0)
828 int wifi_command(const char *command, char *reply, size_t *reply_len)
830 return wifi_send_command(command, reply, reply_len);
833 const char *wifi_get_fw_path(int fw_type)
836 case WIFI_GET_FW_PATH_STA:
837 return WIFI_DRIVER_FW_PATH_STA;
838 case WIFI_GET_FW_PATH_AP:
839 return WIFI_DRIVER_FW_PATH_AP;
840 case WIFI_GET_FW_PATH_P2P:
841 return WIFI_DRIVER_FW_PATH_P2P;
846 int wifi_change_fw_path(const char *fwpath)
854 fd = TEMP_FAILURE_RETRY(open(WIFI_DRIVER_FW_PATH_PARAM, O_WRONLY));
856 ALOGE("Failed to open wlan fw path param (%s)", strerror(errno));
859 len = strlen(fwpath) + 1;
860 if (TEMP_FAILURE_RETRY(write(fd, fwpath, len)) != len) {
861 ALOGE("Failed to write wlan fw path param (%s)", strerror(errno));