From 1c2f59f0d1f9876d4fb15ff69812cf8d55f25461 Mon Sep 17 00:00:00 2001 From: David Cantrell Date: Mon, 25 Aug 2008 16:44:11 -1000 Subject: Rewrite isys.isWireless() to use D-Bus and NetworkManager Removed the wireless.c and wireless.h code from isys, since isWireless() in isys.py communicates with NetworkManager now. --- isys/Makefile | 2 +- isys/isys.c | 14 ------------ isys/isys.py | 30 +++++++++++++++++++++++- isys/wireless.c | 71 --------------------------------------------------------- isys/wireless.h | 25 -------------------- 5 files changed, 30 insertions(+), 112 deletions(-) delete mode 100644 isys/wireless.c delete mode 100644 isys/wireless.h diff --git a/isys/Makefile b/isys/Makefile index e9418573a..e9e433d7b 100644 --- a/isys/Makefile +++ b/isys/Makefile @@ -23,7 +23,7 @@ CFLAGS += -I$(PYTHONINCLUDE) -I.. -DHAVE_NFS OBJECTS = devices.o imount.o smp.o cpio.o uncpio.o dasd.o \ lang.o isofs.o linkdetect.o vio.o \ - ethtool.o wireless.o eddsupport.o iface.o str.o auditd.o + ethtool.o eddsupport.o iface.o str.o auditd.o SOBJECTS = $(patsubst %.o,%.lo,$(OBJECTS)) SOURCES = $(patsubst %.o,%.c,$(OBJECTS)) isys.c LOADLIBES = -lresolv -lpopt -lext2fs -lz -ldevmapper -lblkid -lX11 diff --git a/isys/isys.c b/isys/isys.c index 45d45941c..958baba81 100644 --- a/isys/isys.c +++ b/isys/isys.c @@ -131,7 +131,6 @@ static PyObject * doGetMacAddress(PyObject * s, PyObject * args); static PyObject * doMatchPathContext(PyObject * s, PyObject * args); static PyObject * doSetFileContext(PyObject * s, PyObject * args); #endif -static PyObject * isWireless(PyObject * s, PyObject * args); static PyObject * doProbeBiosDisks(PyObject * s, PyObject * args); static PyObject * doGetBiosDisk(PyObject * s, PyObject * args); static PyObject * doSegvHandler(PyObject *s, PyObject *args); @@ -182,7 +181,6 @@ static PyMethodDef isysModuleMethods[] = { { "matchPathContext", (PyCFunction) doMatchPathContext, METH_VARARGS, NULL }, { "setFileContext", (PyCFunction) doSetFileContext, METH_VARARGS, NULL }, #endif - { "isWireless", (PyCFunction) isWireless, METH_VARARGS, NULL }, { "biosDiskProbe", (PyCFunction) doProbeBiosDisks, METH_VARARGS,NULL}, { "getbiosdisk",(PyCFunction) doGetBiosDisk, METH_VARARGS,NULL}, { "handleSegv", (PyCFunction) doSegvHandler, METH_VARARGS, NULL }, @@ -967,18 +965,6 @@ static PyObject * doGetMacAddress(PyObject * s, PyObject * args) { return Py_BuildValue("s", ret); } -static PyObject * isWireless(PyObject * s, PyObject * args) { - char *dev; - int ret; - - if (!PyArg_ParseTuple(args, "s", &dev)) - return NULL; - - ret = is_wireless_interface(dev); - - return Py_BuildValue("i", ret); -} - #ifdef USESELINUX static PyObject * doMatchPathContext(PyObject * s, PyObject * args) { char *fn, *buf = NULL; diff --git a/isys/isys.py b/isys/isys.py index bbfeec951..c3d56f30d 100755 --- a/isys/isys.py +++ b/isys/isys.py @@ -923,7 +923,35 @@ def getMacAddress(dev): # @param dev The network device to check. # @return True if dev is a wireless network device, False otherwise. def isWireless(dev): - return _isys.isWireless(dev) + if dev == '' or dev is None: + return False + + bus = dbus.SystemBus() + nm = bus.get_object(NM_SERVICE, NM_MANAGER_PATH) + devlist = nm.get_dbus_method("GetDevices")() + + for path in devlist: + device = bus.get_object(NM_SERVICE, path) + device_props_iface = dbus.Interface(device, DBUS_PROPS_IFACE) + + device_interface = device_props_iface.Get(NM_MANAGER_IFACE, "Interface") + if str(device_interface) != dev: + continue + + device_type = int(device_props_iface.Get(NM_MANAGER_IFACE, "DeviceType")) + + # from include/NetworkManager.h in the NM source code + # 0 == NM_DEVICE_TYPE_UNKNOWN + # 1 == NM_DEVICE_TYPE_ETHERNET + # 2 == NM_DEVICE_TYPE_WIFI + # 3 == NM_DEVICE_TYPE_GSM + # 4 == NM_DEVICE_TYPE_CDMA + if device_type == 2: + return True + else: + return False + + return False ## Get the IP address for a network device. # @param dev The network device to check. diff --git a/isys/wireless.c b/isys/wireless.c deleted file mode 100644 index 6ede034b2..000000000 --- a/isys/wireless.c +++ /dev/null @@ -1,71 +0,0 @@ -/* - * wireless.c - wireless card manipulation - * Some portions from wireless_tools - * copyright (c) 1997-2003 Jean Tourrilhes - * - * Copyright (C) 2004 Red Hat, Inc. All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * Author(s): Jeremy Katz - */ - -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include -#include - -static struct iwreq get_wreq(char * ifname) { - struct iwreq wreq; - - memset(&wreq, 0, sizeof(wreq)); - strncpy(wreq.ifr_name, ifname, IFNAMSIZ); - return wreq; -} - -static int get_socket() { - int sock; - - if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { -#ifdef STANDALONE - fprintf(stderr, "Error creating socket: %s\n", strerror(errno)); -#endif - return -1; - } - - return sock; -} - -int is_wireless_interface(char * ifname) { - int sock = get_socket(); - struct iwreq wreq = get_wreq(ifname); - - int rc = ioctl(sock, SIOCGIWNAME, &wreq); - close(sock); - - if (rc < 0) { - return 0; - } - - return 1; -} diff --git a/isys/wireless.h b/isys/wireless.h deleted file mode 100644 index d7ba8be03..000000000 --- a/isys/wireless.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * wireless.h - * - * Copyright (C) 2007 Red Hat, Inc. All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef WIRELESS_H -#define WIRELESS_H - -int is_wireless_interface(char * ifname); - -#endif -- cgit