* Parts of this code are derived from the Linux iw utility.
*/
+#include <sys/stat.h>
#include <limits.h>
#include <glob.h>
#include <fnmatch.h>
int prefix_len = strlen(prefix);
int buf_len, offset;
struct dirent *e;
- char buf[128], *link;
+ char buf[512], *link;
int phy_idx;
int seq = 0;
DIR *d;
static int nl80211_phy_idx_from_path(const char *path)
{
- char buf[128];
+ char buf[512];
struct dirent *e;
const char *cur_path;
int cur_path_len;
return idx;
}
+static bool nl80211_is_ifname(const char *name)
+{
+ struct stat st;
+ char buffer[PATH_MAX];
+
+ snprintf(buffer, sizeof(buffer), "/sys/class/net/%s", name);
+ return !lstat(buffer, &st);
+}
+
static struct nl80211_msg_conveyor * nl80211_msg(const char *ifname,
int cmd, int flags)
{
if (!strncmp(ifname, "mon.", 4))
ifidx = if_nametoindex(&ifname[4]);
- else
+ else if (nl80211_is_ifname(ifname))
ifidx = if_nametoindex(ifname);
-
- if (!ifidx) {
+ else
+ {
phyidx = nl80211_phy_idx_from_phy(ifname);
if (phyidx < 0)
phyidx = nl80211_phy_idx_from_uci(ifname);
static char * nl80211_phy2ifname(const char *ifname)
{
int ifidx = -1, cifidx = -1, phyidx = -1;
- char buffer[64];
+ char buffer[512];
static char nif[IFNAMSIZ] = { 0 };
DIR *d;
remote.sun_family = AF_UNIX;
remote_length = sizeof(remote.sun_family) +
- sprintf(remote.sun_path, "/var/run/wpa_supplicant-%s/%s",
- ifname, ifname);
+ sprintf(remote.sun_path, "/var/run/wpa_supplicant/%s", ifname);
+
+ /* Set client socket file permissions so that bind() creates the client
+ * socket with these permissions and there is no need to try to change
+ * them with chmod() after bind() which would have potential issues with
+ * race conditions. These permissions are needed to make sure the server
+ * side (wpa_supplicant or hostapd) can reply to the control interface
+ * messages.
+ *
+ * The lchown() calls below after bind() are also part of the needed
+ * operations to allow the response to go through. Those are using the
+ * no-deference-symlinks version to avoid races. */
+ fchmod(sock, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
if (fcntl(sock, F_SETFD, fcntl(sock, F_GETFD) | FD_CLOEXEC) < 0)
{
if (connect(sock, (struct sockaddr *)&remote, remote_length))
{
- remote_length = sizeof(remote.sun_family) +
- sprintf(remote.sun_path, "/var/run/wpa_supplicant/%s", ifname);
-
- if (connect(sock, (struct sockaddr *)&remote, remote_length))
- {
- close(sock);
- return -1;
- }
+ close(sock);
+ return -1;
}
local->sun_family = AF_UNIX;
return -1;
}
+ /* Set group even if we do not have privileges to change owner */
+ lchown(local->sun_path, -1, 101);
+ lchown(local->sun_path, 101, 101);
+
return sock;
}
static void nl80211_ifdel(const char *ifname)
{
struct nl80211_msg_conveyor *req;
- int err;
req = nl80211_msg(ifname, NL80211_CMD_DEL_INTERFACE, 0);
if (req)
/* failed, try to obtain Mesh ID */
if (sb.ssid[0] == 0)
iwinfo_ubus_query(res ? res : ifname, "mesh_id",
- sb.ssid, IWINFO_ESSID_MAX_SIZE + 1);
+ buf, IWINFO_ESSID_MAX_SIZE + 1);
return (sb.ssid[0] == 0) ? -1 : 0;
}
{ "IEEE 802.1X/EAP", 0, IWINFO_KMGMT_8021x },
{ "EAP-SUITE-B-192", 4, IWINFO_KMGMT_8021x },
{ "EAP-SUITE-B", 4, IWINFO_KMGMT_8021x },
+ { "EAP-SHA384", 4, IWINFO_KMGMT_8021x },
{ "EAP-SHA256", 0, IWINFO_KMGMT_8021x },
{ "PSK-SHA256", 0, IWINFO_KMGMT_PSK },
{ "NONE", 0, IWINFO_KMGMT_NONE },
if (!strncmp(p, "WPA-", 4))
p += 4;
+ if (!strncmp(p, "FT-", 3))
+ p += 3;
+
parse_wpa_suites(p, atoi(wpa), &c->wpa_version, &c->auth_suites);
}
{
int err, ch_cur;
int dbm_max = -1, dbm_cur, dbm_cnt;
- struct nl80211_msg_conveyor *req;
struct iwinfo_txpwrlist_entry entry;
if (nl80211_get_channel(ifname, &ch_cur))
iwinfo_ifup(ifname);
nl80211_hostapd_hup(ifname);
}
+ else
+ rv = -1;
nl80211_ifdel(res);
return rv;
uint16_t he_phy_cap[6];
};
-static int nl80211_eval_modelist(struct nl80211_modes *m)
+static void nl80211_eval_modelist(struct nl80211_modes *m)
{
/* Treat any nonzero capability as 11n */
if (m->nl_ht > 0)
{
struct nl80211_modes *m = arg;
int bands_remain, freqs_remain;
- uint16_t caps = 0;
- uint32_t vht_caps = 0;
struct nlattr **attr = nl80211_parse(msg);
struct nlattr *bands[NL80211_BAND_ATTR_MAX + 1];
struct nlattr *freqs[NL80211_FREQUENCY_ATTR_MAX + 1];
static int nl80211_hardware_id_from_fdt(struct iwinfo_hardware_id *id, const char *ifname)
{
char *phy, compat[64], path[PATH_MAX];
- int i;
/* Try to determine the phy name from the given interface */
phy = nl80211_ifname2phy(ifname);
{ "vendor", &id->vendor_id },
{ "device", &id->device_id },
{ "subsystem_vendor", &id->subsystem_vendor_id },
- { "subsystem_device", &id->subsystem_device_id }
+ { "subsystem_device", &id->subsystem_device_id },
+ { "../idVendor", &id->subsystem_vendor_id },
+ { "../idProduct", &id->subsystem_device_id }
};
memset(id, 0, sizeof(*id));
}
/* Failed to obtain hardware IDs, try FDT */
- if (id->vendor_id == 0 || id->device_id == 0)
+ if (id->vendor_id == 0 && id->device_id == 0 &&
+ id->subsystem_vendor_id == 0 && id->subsystem_device_id == 0)
if (!nl80211_hardware_id_from_fdt(id, ifname))
return 0;
/* Failed to obtain hardware IDs, search board config */
- if (id->vendor_id == 0 || id->device_id == 0)
+ if (id->vendor_id == 0 && id->device_id == 0 &&
+ id->subsystem_vendor_id == 0 && id->subsystem_device_id == 0)
return iwinfo_hardware_id_from_mtd(id);
return 0;