NetworkManager r3462 - in trunk: . include libnm-glib libnm-util src test



Author: dcbw
Date: Fri Mar 14 21:12:03 2008
New Revision: 3462
URL: http://svn.gnome.org/viewvc/NetworkManager?rev=3462&view=rev

Log:
2008-03-14  Dan Williams  <dcbw redhat com>

	* include/wireless-helper.h
	  include/Makefile.am
		- One place for all the junk needed for #including wireless.h

	* test/nm-tool.c
	  src/NetworkManagerAP.c
	  src/wpa.c
	  src/Makefile.am
	  libnm-util/nm-utils.c
	  libnm-util/nm-setting-wireless.c
	  libnm-glib/nm-device-802-11-wireless.c
	  libnm-glib/nm-access-point.c
	  libnm-glib/libnm-glib-test.c
		- include wireless-helper.h, not iwlib.h

	* configure.in
		- Don't need libiw really, just need to check for wireless.h

	* src/kernel-types.h
		- Remove; used types moved into wpa.c

	* src/nm-device-802-11-wireless.c
		- (nm_device_802_11_wireless_update_signal_strength,
		   real_get_generic_capabilities, nm_device_802_11_wireless_get_mode,
		   nm_device_802_11_wireless_set_mode,
		   nm_device_802_11_wireless_get_frequency,
		   nm_device_802_11_wireless_get_ssid,
		   nm_device_802_11_wireless_set_ssid,
		   nm_device_802_11_wireless_get_bitrate,
		   nm_device_802_11_wireless_get_bssid,
		   nm_device_802_11_wireless_disable_encryption): use ioctl() directly
			instead of iwlib functions




Added:
   trunk/include/wireless-helper.h
Removed:
   trunk/src/kernel-types.h
Modified:
   trunk/ChangeLog
   trunk/configure.in
   trunk/include/Makefile.am
   trunk/libnm-glib/libnm-glib-test.c
   trunk/libnm-glib/nm-access-point.c
   trunk/libnm-glib/nm-device-802-11-wireless.c
   trunk/libnm-util/nm-setting-wireless.c
   trunk/libnm-util/nm-utils.c
   trunk/src/Makefile.am
   trunk/src/NetworkManagerAP.c
   trunk/src/nm-device-802-11-wireless.c
   trunk/src/wpa.c
   trunk/test/nm-tool.c

Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in	(original)
+++ trunk/configure.in	Fri Mar 14 21:12:03 2008
@@ -133,8 +133,15 @@
 	esac
 fi
 
-AC_MSG_CHECKING([for wireless-tools >= 28pre9])
-AC_TRY_COMPILE([#include <iwlib.h>],
+AC_MSG_CHECKING([Linux Wireless Extensions >= 18])
+AC_TRY_COMPILE([#ifndef __user
+                #define __user
+                #endif
+                #include <sys/types.h>
+                #include <linux/types.h>
+                #include <sys/socket.h>
+                #include <net/if.h>
+                #include <wireless.h>],
                [#ifndef IWEVGENIE
                 #error "not found"
                 #endif],
@@ -144,8 +151,6 @@
 if test "$ac_have_iwevgenie" = no; then
 	AC_MSG_ERROR(wireless-tools >= 28pre9 not installed or not functional)
 fi
-IWLIB=-liw
-AC_SUBST(IWLIB)
 
 PKG_CHECK_MODULES(DBUS, dbus-glib-1 >= 0.72)
 

Modified: trunk/include/Makefile.am
==============================================================================
--- trunk/include/Makefile.am	(original)
+++ trunk/include/Makefile.am	Fri Mar 14 21:12:03 2008
@@ -4,4 +4,7 @@
 
 NetworkManagerincludedir=$(includedir)/NetworkManager
 
-NetworkManagerinclude_HEADERS = NetworkManager.h NetworkManagerVPN.h
+NetworkManagerinclude_HEADERS = \
+	NetworkManager.h \
+	NetworkManagerVPN.h \
+	wireless-helper.h

Added: trunk/include/wireless-helper.h
==============================================================================
--- (empty file)
+++ trunk/include/wireless-helper.h	Fri Mar 14 21:12:03 2008
@@ -0,0 +1,11 @@
+/* Hacks necessary to #include wireless.h; yay for WEXT */
+
+#ifndef __user
+#define __user
+#endif
+#include <sys/types.h>
+#include <linux/types.h>
+#include <sys/socket.h>
+#include <net/if.h>
+#include <wireless.h>
+

Modified: trunk/libnm-glib/libnm-glib-test.c
==============================================================================
--- trunk/libnm-glib/libnm-glib-test.c	(original)
+++ trunk/libnm-glib/libnm-glib-test.c	Fri Mar 14 21:12:03 2008
@@ -3,8 +3,8 @@
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
-#include <iwlib.h>
-#include <wireless.h>
+
+#include "wireless-helper.h"
 
 #include "nm-client.h"
 #include "nm-device.h"

Modified: trunk/libnm-glib/nm-access-point.c
==============================================================================
--- trunk/libnm-glib/nm-access-point.c	(original)
+++ trunk/libnm-glib/nm-access-point.c	Fri Mar 14 21:12:03 2008
@@ -1,6 +1,8 @@
 /* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */
 
-#include <iwlib.h>
+#include "wireless-helper.h"
+
+#include <string.h>
 
 #include "nm-access-point.h"
 #include "NetworkManager.h"

Modified: trunk/libnm-glib/nm-device-802-11-wireless.c
==============================================================================
--- trunk/libnm-glib/nm-device-802-11-wireless.c	(original)
+++ trunk/libnm-glib/nm-device-802-11-wireless.c	Fri Mar 14 21:12:03 2008
@@ -1,5 +1,8 @@
 /* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */
-#include <iwlib.h>
+
+#include "wireless-helper.h"
+
+#include <string.h>
 
 #include "nm-device-802-11-wireless.h"
 #include "nm-device-private.h"

Modified: trunk/libnm-util/nm-setting-wireless.c
==============================================================================
--- trunk/libnm-util/nm-setting-wireless.c	(original)
+++ trunk/libnm-util/nm-setting-wireless.c	Fri Mar 14 21:12:03 2008
@@ -2,9 +2,11 @@
 
 #include <string.h>
 #include <netinet/ether.h>
+
+#include "wireless-helper.h"
+
 #include <dbus/dbus-glib.h>
-#include <iwlib.h>
-#include <wireless.h>
+
 #include "NetworkManager.h"
 
 #include "nm-setting-wireless.h"

Modified: trunk/libnm-util/nm-utils.c
==============================================================================
--- trunk/libnm-util/nm-utils.c	(original)
+++ trunk/libnm-util/nm-utils.c	Fri Mar 14 21:12:03 2008
@@ -25,10 +25,10 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <errno.h>
-#include <iwlib.h>
-#include <wireless.h>
 #include <arpa/inet.h>
 
+#include "wireless-helper.h"
+
 #include <glib.h>
 #include <glib-object.h>
 #include <dbus/dbus-glib.h>

Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am	(original)
+++ trunk/src/Makefile.am	Fri Mar 14 21:12:03 2008
@@ -63,7 +63,6 @@
 		nm-cdma-device.h		\
 		autoip.c					\
 		autoip.h					\
-		kernel-types.h			\
 		wpa.c				\
 		wpa.h				\
 		nm-netlink.c			\
@@ -121,7 +120,6 @@
 			$(DBUS_LIBS)						\
 			$(GTHREAD_LIBS)					\
 			$(HAL_LIBS)						\
-			$(IWLIB)							\
 			$(LIBNL_LIBS)						\
 			./marshallers/libmarshallers.la	\
 			./named-manager/libnamed-manager.la	\

Modified: trunk/src/NetworkManagerAP.c
==============================================================================
--- trunk/src/NetworkManagerAP.c	(original)
+++ trunk/src/NetworkManagerAP.c	Fri Mar 14 21:12:03 2008
@@ -20,11 +20,14 @@
  * (C) Copyright 2004 Red Hat, Inc.
  */
 
+#include "wireless-helper.h"
+
+#include <string.h>
+
 #include "NetworkManagerAP.h"
 #include "NetworkManagerUtils.h"
 #include "nm-utils.h"
 #include "nm-dbus-manager.h"
-#include <wireless.h>
 #include "wpa.h"
 #include "nm-properties-changed-signal.h"
 #include "nm-setting-wireless.h"

Modified: trunk/src/nm-device-802-11-wireless.c
==============================================================================
--- trunk/src/nm-device-802-11-wireless.c	(original)
+++ trunk/src/nm-device-802-11-wireless.c	Fri Mar 14 21:12:03 2008
@@ -215,15 +215,17 @@
 
 	fd = socket (PF_INET, SOCK_DGRAM, 0);
 	if (fd >= 0) {
-		gboolean has_range = FALSE;
-		iwrange range;
-		iwstats stats;
+		struct iwreq wrq;
+		struct iw_statistics stats;
 
-		memset (&range, 0, sizeof (iwrange));
-		has_range = (iw_get_range_info (fd, iface, &range) >= 0);
+		memset (&stats, 0, sizeof (stats));
 
-		memset (&stats, 0, sizeof (iwstats));
-		if (iw_get_stats (fd, iface, &stats, &range, has_range) == 0) {
+		wrq.u.data.pointer = &stats;
+		wrq.u.data.length = sizeof (stats);
+		wrq.u.data.flags = 1;		/* Clear updated flag */
+		strncpy (wrq.ifr_name, iface, IFNAMSIZ);
+
+		if (ioctl (fd, SIOCGIWSTATS, &wrq) == 0) {
 			percent = wireless_qual_to_percent (&stats.qual, (const iwqual *)(&self->priv->max_qual),
 					(const iwqual *)(&self->priv->avg_qual));
 		}
@@ -245,7 +247,7 @@
 {
 	int fd, err;
 	guint32 caps = NM_DEVICE_CAP_NONE;
-	iwrange range;
+	struct iw_range range;
 	struct iwreq wrq;
 	const char *iface = nm_device_get_iface (dev);
 
@@ -257,12 +259,18 @@
 		goto out;
 	}
 
-	if (iw_get_range_info (fd, iface, &range) < 0) {
+	memset (&wrq, 0, sizeof (struct iwreq));
+	memset (&range, 0, sizeof (struct iw_range));
+	strncpy (wrq.ifr_name, iface, IFNAMSIZ);
+	wrq.u.data.pointer = (caddr_t) &range;
+	wrq.u.data.length = sizeof (struct iw_range);
+
+	if (ioctl (fd, SIOCGIWRANGE, &wrq) < 0) {
 		nm_warning ("couldn't get driver range information.");
 		goto out;
 	}
 
-	if (range.we_version_compiled < 16) {
+	if ((wrq.u.data.length < 300) || (range.we_version_compiled < 16)) {
 		nm_warning ("%s: driver's Wireless Extensions version (%d) is too old.",
 					iface, range.we_version_compiled);
 		goto out;
@@ -272,7 +280,8 @@
 
 	/* Card's that don't scan aren't supported */
 	memset (&wrq, 0, sizeof (struct iwreq));
-	err = iw_set_ext (fd, iface, SIOCSIWSCAN, &wrq);
+	strncpy (wrq.ifr_name, iface, IFNAMSIZ);
+	err = ioctl (fd, SIOCSIWSCAN, &wrq);
 	if ((err == -1) && (errno == EOPNOTSUPP))
 		caps = NM_DEVICE_CAP_NONE;
 
@@ -968,14 +977,15 @@
 
 	g_return_val_if_fail (self != NULL, -1);
 
-	iface = nm_device_get_iface (NM_DEVICE (self));
 	fd = socket (PF_INET, SOCK_DGRAM, 0);
 	if (fd < 0)
 		goto out;
 
 	memset (&wrq, 0, sizeof (struct iwreq));
+	iface = nm_device_get_iface (NM_DEVICE (self));
+	strncpy (wrq.ifr_name, iface, IFNAMSIZ);
 
-	if (iw_get_ext (fd, iface, SIOCGIWMODE, &wrq) == 0) {
+	if (ioctl (fd, SIOCGIWMODE, &wrq) == 0) {
 		if ((wrq.u.mode == IW_MODE_ADHOC) || (wrq.u.mode == IW_MODE_INFRA))
 			mode = wrq.u.mode;
 	} else {
@@ -1010,15 +1020,16 @@
 	if (nm_device_802_11_wireless_get_mode (self) == mode)
 		return TRUE;
 
-	iface = nm_device_get_iface (NM_DEVICE (self));
-
 	fd = socket (PF_INET, SOCK_DGRAM, 0);
 	if (fd < 0)
 		goto out;
 
 	memset (&wrq, 0, sizeof (struct iwreq));
 	wrq.u.mode = mode;
-	if (iw_set_ext (fd, iface, SIOCSIWMODE, &wrq) == 0)
+	iface = nm_device_get_iface (NM_DEVICE (self));
+	strncpy (wrq.ifr_name, iface, IFNAMSIZ);
+
+	if (ioctl (fd, SIOCSIWMODE, &wrq) == 0)
 		success = TRUE;
 	else {
 		if (errno != ENODEV) {
@@ -1049,14 +1060,15 @@
 
 	g_return_val_if_fail (self != NULL, 0);
 
-	iface = nm_device_get_iface (NM_DEVICE (self));
 	fd = socket (PF_INET, SOCK_DGRAM, 0);
 	if (fd < 0)
 		return 0;
 
 	memset (&wrq, 0, sizeof (struct iwreq));
+	iface = nm_device_get_iface (NM_DEVICE (self));
+	strncpy (wrq.ifr_name, iface, IFNAMSIZ);
 
-	err = iw_get_ext (fd, iface, SIOCGIWFREQ, &wrq);
+	err = ioctl (fd, SIOCGIWFREQ, &wrq);
 	if (err >= 0)
 		freq = iw_freq_to_uint32 (&wrq.u.freq);
 	else if (err == -1)
@@ -1189,7 +1201,6 @@
 nm_device_802_11_wireless_get_ssid (NMDevice80211Wireless *self)
 {
 	NMDevice80211WirelessPrivate *priv = NM_DEVICE_802_11_WIRELESS_GET_PRIVATE (self);
-	const char * iface;
 	int	sk;
 	struct iwreq wrq;
 	char ssid[IW_ESSID_MAX_SIZE + 1];
@@ -1197,7 +1208,6 @@
 
 	g_return_val_if_fail (self != NULL, NULL);	
 
-	iface = nm_device_get_iface (NM_DEVICE (self));
 	sk = socket (AF_INET, SOCK_DGRAM, 0);
 	if (!sk) {
 		nm_error ("Couldn't create socket: %d.", errno);
@@ -1208,7 +1218,9 @@
 	wrq.u.essid.pointer = (caddr_t) &ssid;
 	wrq.u.essid.length = sizeof (ssid);
 	wrq.u.essid.flags = 0;
-	if (iw_get_ext (sk, iface, SIOCGIWESSID, &wrq) < 0) {
+	strncpy (wrq.ifr_name, nm_device_get_iface (NM_DEVICE (self)), IFNAMSIZ);
+
+	if (ioctl (sk, SIOCGIWESSID, &wrq) < 0) {
 		nm_warning ("Couldn't get SSID: %d", errno);
 		goto out;
     }
@@ -1286,7 +1298,9 @@
 	wrq.u.essid.length = len;
 	wrq.u.essid.flags = (len > 0) ? 1 : 0; /* 1=enable SSID, 0=disable/any */
 
-	if (iw_get_ext (sk, iface, SIOCSIWESSID, &wrq) < 0) {
+	strncpy (wrq.ifr_name, iface, IFNAMSIZ);
+
+	if (ioctl (sk, SIOCSIWESSID, &wrq) < 0) {
 		if (errno != ENODEV) {
 			nm_warning ("error setting SSID to '%s' for device %s: %s",
 			            ssid ? nm_utils_escape_ssid (ssid->data, ssid->len) : "(null)",
@@ -1319,17 +1333,16 @@
 {
 	int err = -1, fd;
 	struct iwreq wrq;
-	const char *iface;
 
 	g_return_val_if_fail (self != NULL, 0);
 
-	iface = nm_device_get_iface (NM_DEVICE (self));
 	fd = socket (PF_INET, SOCK_DGRAM, 0);
 	if (fd < 0)
 		return 0;
 
 	memset (&wrq, 0, sizeof (wrq));
-	err = iw_get_ext (fd, iface, SIOCGIWRATE, &wrq);
+	strncpy (wrq.ifr_name, nm_device_get_iface (NM_DEVICE (self)), IFNAMSIZ);
+	err = ioctl (fd, SIOCGIWRATE, &wrq);
 	close (fd);
 
 	return ((err >= 0) ? wrq.u.bitrate.value / 1000 : 0);
@@ -1347,14 +1360,12 @@
 {
 	int fd;
 	struct iwreq wrq;
-	const char *iface;
 
 	g_return_if_fail (self != NULL);
 	g_return_if_fail (bssid != NULL);
 
 	memset (bssid, 0, sizeof (struct ether_addr));
 
-	iface = nm_device_get_iface (NM_DEVICE (self));
 	fd = socket (PF_INET, SOCK_DGRAM, 0);
 	if (fd < 0) {
 		g_warning ("failed to open control socket.");
@@ -1362,7 +1373,8 @@
 	}
 
 	memset (&wrq, 0, sizeof (wrq));
-	if (iw_get_ext (fd, iface, SIOCGIWAP, &wrq) >= 0)
+	strncpy (wrq.ifr_name, nm_device_get_iface (NM_DEVICE (self)), IFNAMSIZ);
+	if (ioctl (fd, SIOCGIWAP, &wrq) >= 0)
 		memcpy (bssid->ether_addr_octet, &(wrq.u.ap_addr.sa_data), ETH_ALEN);
 
 	close (fd);
@@ -1380,7 +1392,7 @@
 {
 	int fd;
 	const char *iface;
-	struct iwreq wreq = {
+	struct iwreq wrq = {
 		.u.data.pointer = (caddr_t) NULL,
 		.u.data.length = 0,
 		.u.data.flags = IW_ENCODE_DISABLED
@@ -1395,7 +1407,9 @@
 	}
 
 	iface = nm_device_get_iface (NM_DEVICE (self));
-	if (iw_set_ext (fd, iface, SIOCSIWENCODE, &wreq) == -1) {
+	strncpy (wrq.ifr_name, iface, IFNAMSIZ);
+
+	if (ioctl (fd, SIOCSIWENCODE, &wrq) == -1) {
 		if (errno != ENODEV) {
 			nm_warning ("error setting key for device %s: %s",
 			            iface, strerror (errno));

Modified: trunk/src/wpa.c
==============================================================================
--- trunk/src/wpa.c	(original)
+++ trunk/src/wpa.c	Fri Mar 14 21:12:03 2008
@@ -12,14 +12,18 @@
  * See README and COPYING for more details.
  */
 
+#include "wireless-helper.h"
+
 #include <stdint.h>
-#include <iwlib.h>
+#include <string.h>
 #include <glib.h>
 
-#include "kernel-types.h"
 #include "wpa.h"
 #include "nm-utils.h"
 
+typedef guint16 u16;
+typedef guint8 u8;
+
 #define WPA_GET_LE16(a) ((u16) (((a)[1] << 8) | (a)[0]))
 
 #define BIT(n) (1 << (n))

Modified: trunk/test/nm-tool.c
==============================================================================
--- trunk/test/nm-tool.c	(original)
+++ trunk/test/nm-tool.c	Fri Mar 14 21:12:03 2008
@@ -26,7 +26,7 @@
 #include <string.h>
 #include <stdlib.h>
 
-#include <iwlib.h>
+#include "wireless-helper.h"
 
 #include <sys/socket.h>
 #include <netinet/in.h>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]