mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-05 16:58:02 +02:00
wifi: move WEXT-based WiFi interface detection to wifi-utils
This commit is contained in:
parent
9a629f8cb4
commit
46437ed525
5 changed files with 39 additions and 21 deletions
|
|
@ -27,8 +27,6 @@
|
|||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "wireless-helper.h"
|
||||
|
||||
#include <gudev/gudev.h>
|
||||
|
||||
#include "nm-udev-manager.h"
|
||||
|
|
@ -38,6 +36,7 @@
|
|||
#include "nm-device-wifi.h"
|
||||
#include "nm-device-olpc-mesh.h"
|
||||
#include "nm-device-ethernet.h"
|
||||
#include "wifi-utils.h"
|
||||
#if WITH_WIMAX
|
||||
#include "nm-device-wimax.h"
|
||||
#endif
|
||||
|
|
@ -347,29 +346,16 @@ is_wireless (GUdevDevice *device)
|
|||
{
|
||||
char phy80211_path[255];
|
||||
struct stat s;
|
||||
int fd;
|
||||
struct iwreq iwr;
|
||||
const char *ifname, *path;
|
||||
gboolean is_wifi = FALSE;
|
||||
|
||||
ifname = g_udev_device_get_name (device);
|
||||
g_assert (ifname);
|
||||
|
||||
fd = socket (PF_INET, SOCK_DGRAM, 0);
|
||||
if (fd == -1)
|
||||
return FALSE;
|
||||
|
||||
strncpy (iwr.ifr_ifrn.ifrn_name, ifname, IFNAMSIZ);
|
||||
const char *path;
|
||||
|
||||
/* Check for nl80211 sysfs paths */
|
||||
path = g_udev_device_get_sysfs_path (device);
|
||||
snprintf (phy80211_path, sizeof (phy80211_path), "%s/phy80211", path);
|
||||
if ((stat (phy80211_path, &s) == 0 && (s.st_mode & S_IFDIR)))
|
||||
return TRUE;
|
||||
|
||||
if ( (ioctl (fd, SIOCGIWNAME, &iwr) == 0)
|
||||
|| (stat (phy80211_path, &s) == 0 && (s.st_mode & S_IFDIR)))
|
||||
is_wifi = TRUE;
|
||||
|
||||
close (fd);
|
||||
return is_wifi;
|
||||
/* Otherwise hit up WEXT/nl80211 directly */
|
||||
return wifi_utils_is_wifi (g_udev_device_get_name (device));
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
|
|
|||
|
|
@ -551,3 +551,20 @@ error:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
gboolean
|
||||
wifi_wext_is_wifi (const char *iface)
|
||||
{
|
||||
int fd;
|
||||
struct iwreq iwr;
|
||||
gboolean is_wifi = FALSE;
|
||||
|
||||
fd = socket (PF_INET, SOCK_DGRAM, 0);
|
||||
if (fd >= 0) {
|
||||
strncpy (iwr.ifr_ifrn.ifrn_name, iface, IFNAMSIZ);
|
||||
if (ioctl (fd, SIOCGIWNAME, &iwr) == 0)
|
||||
is_wifi = TRUE;
|
||||
close (fd);
|
||||
}
|
||||
return is_wifi;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,4 +25,6 @@
|
|||
|
||||
WifiData *wifi_wext_init (const char *iface, int ifindex);
|
||||
|
||||
gboolean wifi_wext_is_wifi (const char *iface);
|
||||
|
||||
#endif /* WIFI_UTILS_WEXT_H */
|
||||
|
|
|
|||
|
|
@ -147,3 +147,14 @@ wifi_utils_deinit (WifiData *data)
|
|||
wifi_data_free (data);
|
||||
}
|
||||
|
||||
gboolean
|
||||
wifi_utils_is_wifi (const char *iface)
|
||||
{
|
||||
g_return_val_if_fail (iface != NULL, FALSE);
|
||||
|
||||
if (wifi_wext_is_wifi (iface))
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@
|
|||
|
||||
typedef struct WifiData WifiData;
|
||||
|
||||
gboolean wifi_utils_is_wifi (const char *iface);
|
||||
|
||||
WifiData *wifi_utils_init (const char *iface, int ifindex);
|
||||
|
||||
void wifi_utils_deinit (WifiData *data);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue