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

[PATCH master] (take II) Make ssid and wepkey in boot params and stage 1 kickstart work (#473803)



This version of patch is using common function to determine
if a device is wireless in stage 1 and stage 2.

---
 isys/iface.c |   33 ++++++++++++++++++++++++++++
 isys/iface.h |    5 ++++
 isys/isys.c  |   16 +++++++++++++
 isys/isys.py |   22 +-----------------
 kickstart.py |    2 +-
 loader/net.c |   67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 124 insertions(+), 21 deletions(-)

diff --git a/isys/iface.c b/isys/iface.c
index 5897286..0369104 100644
--- a/isys/iface.c
+++ b/isys/iface.c
@@ -49,6 +49,7 @@
 #include <nm-device.h>
 #include <nm-ip4-config.h>
 #include <nm-setting-ip4-config.h>
+#include <nm-device-wifi.h>
 
 #include "isys.h"
 #include "iface.h"
@@ -541,3 +542,35 @@ ifacemtu_error1:
 
     return ret;
 }
+
+/*
+ * Checks if interface is wireless
+ */
+int is_wireless_device(char *ifname){
+    NMClient *client = NULL;
+    NMDevice *candidate = NULL;
+    const GPtrArray *devices;
+    const char *iface;
+    int i;
+
+    client = nm_client_new();
+    if (!client) {
+        return 0;
+    }
+
+    devices = nm_client_get_devices(client);
+    for (i = 0; devices && (i < devices->len); i++) {
+        candidate = g_ptr_array_index(devices, i);
+        if (NM_IS_DEVICE_WIFI (candidate)) {
+            iface = nm_device_get_iface(candidate);
+            if (!strcmp(ifname, iface)) {
+                g_object_unref(client);
+                return 1;
+            }
+        }
+
+    }
+    g_object_unref(client);
+    return 0;
+}
+
diff --git a/isys/iface.h b/isys/iface.h
index 820d10b..d7ecc56 100644
--- a/isys/iface.h
+++ b/isys/iface.h
@@ -163,4 +163,9 @@ int iface_start_NetworkManager(void);
  */
 int iface_set_interface_mtu(char *ifname, int mtu);
 
+/*
+ * Checks if interface is wireless
+ */
+int is_wireless_device(char *ifname);
+
 #endif /* ISYSIFACE_H */
diff --git a/isys/isys.c b/isys/isys.c
index 6b49ba6..b8ced6a 100644
--- a/isys/isys.c
+++ b/isys/isys.c
@@ -113,6 +113,7 @@ static PyObject * doIsCapsLockEnabled(PyObject * s, PyObject * args);
 static PyObject * doGetLinkStatus(PyObject * s, PyObject * args);
 static PyObject * doGetAnacondaVersion(PyObject * s, PyObject * args);
 static PyObject * doInitLog(PyObject * s);
+static PyObject * doIsWirelessDevice(PyObject * s, PyObject * args);
 
 static PyMethodDef isysModuleMethods[] = {
     { "ejectcdrom", (PyCFunction) doEjectCdrom, METH_VARARGS, NULL },
@@ -145,6 +146,7 @@ static PyMethodDef isysModuleMethods[] = {
     { "getLinkStatus", (PyCFunction) doGetLinkStatus, METH_VARARGS, NULL },
     { "getAnacondaVersion", (PyCFunction) doGetAnacondaVersion, METH_VARARGS, NULL },
     { "initLog", (PyCFunction) doInitLog, METH_VARARGS, NULL },
+    { "isWirelessDevice", (PyCFunction) doIsWirelessDevice, METH_VARARGS, NULL },
     { NULL, NULL, 0, NULL }
 } ;
 
@@ -697,4 +699,18 @@ static PyObject * doInitLog(PyObject * s) {
     return Py_None;
 }
 
+static PyObject * doIsWirelessDevice(PyObject * s, PyObject * args) {
+    char *dev = NULL;
+
+    if (!PyArg_ParseTuple(args, "s", &dev)) {
+        return NULL;
+    }
+
+    if (is_wireless_device(dev) == 1) {
+        return PyBool_FromLong(1);
+    }
+
+    return PyBool_FromLong(0);
+}
+
 /* vim:set shiftwidth=4 softtabstop=4: */
diff --git a/isys/isys.py b/isys/isys.py
index b16c8e4..c19faae 100755
--- a/isys/isys.py
+++ b/isys/isys.py
@@ -433,26 +433,8 @@ def getNetDevDesc(dev):
     return desc
 
 # Determine if a network device is a wireless device.
-def isWireless(dev):
-    if dev == '' or dev is None:
-        return False
-
-    device_props_iface = getDeviceProperties(dev=dev)
-    if device_props_iface is None:
-        return None
-
-    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
+def isWirelessDevice(dev):
+    return _isys.isWirelessDevice(dev)
 
 # Get the IP address for a network device.
 def getIPAddress(dev):
diff --git a/kickstart.py b/kickstart.py
index 8e3368d..f642c29 100644
--- a/kickstart.py
+++ b/kickstart.py
@@ -590,7 +590,7 @@ class NetworkData(commands.network.F8_NetworkData):
                 if self.ethtool:
                     dev.set (("ethtool_opts", self.ethtool))
 
-                if isys.isWireless(device):
+                if isys.isWirelessDevice(device):
                     if self.essid:
                         dev.set(("essid", self.essid))
                     if self.wepkey:
diff --git a/loader/net.c b/loader/net.c
index 702e60c..f3a7f28 100644
--- a/loader/net.c
+++ b/loader/net.c
@@ -39,6 +39,7 @@
 #include <glib.h>
 #include <NetworkManager.h>
 #include <nm-client.h>
+#include <nm-device-wifi.h>
 
 #include "../isys/isys.h"
 #include "../isys/ethtool.h"
@@ -406,6 +407,22 @@ void setupIfaceStruct(iface_t * iface, struct loaderData_s * loaderData) {
         iface->portno = strdup(loaderData->portno);
     }
 
+    if (loaderData->wepkey) {
+        if (is_wireless_device(loaderData->netDev)) {
+            iface->wepkey = strdup(loaderData->wepkey);
+        } else {
+            iface->wepkey = NULL;
+        }
+    }
+
+    if (loaderData->essid) {
+        if (is_wireless_device(loaderData->netDev)) {
+            iface->ssid = strdup(loaderData->essid);
+        } else {
+            iface->ssid = NULL;
+        }
+    }
+
     if (loaderData->noDns) {
         iface->flags |= IFACE_FLAGS_NO_WRITE_RESOLV_CONF;
     }
@@ -1440,6 +1457,14 @@ int writeEnabledNetInfo(iface_t *iface) {
         fprintf(fp, "MACADDR=%s\n", iface->macaddr);
     }
 
+    if (iface->ssid) {
+        fprintf(fp, "ESSID=%s\n", iface->ssid);
+    }
+
+    if (iface->wepkey) {
+        fprintf(fp, "DEFAULTKEY=1");
+    }
+
     if (fclose(fp) == EOF) {
         free(ofile);
         free(nfile);
@@ -1460,6 +1485,48 @@ int writeEnabledNetInfo(iface_t *iface) {
         free(nfile);
     }
 
+    /* wireless wepkey: keys-DEVICE file */
+    if (iface->wepkey) {
+        if (asprintf(&ofile, "%s/.keys-%s",
+                     NETWORK_SCRIPTS_PATH, iface->device) == -1) {
+            return 21;
+        }
+
+        if (asprintf(&nfile, "%s/keys-%s",
+                     NETWORK_SCRIPTS_PATH, iface->device) == -1) {
+            return 22;
+        }
+
+        if ((fp = fopen(ofile, "w")) == NULL) {
+            free(ofile);
+            return 23;
+        }
+
+        fprintf(fp, "KEY1=%s\n", iface->wepkey);
+
+
+        if (fclose(fp) == EOF) {
+            free(ofile);
+            free(nfile);
+            return 24;
+        }
+
+        if (rename(ofile, nfile) == -1) {
+            free(ofile);
+            free(nfile);
+            return 25;
+        }
+
+        if (ofile) {
+            free(ofile);
+        }
+
+        if (nfile) {
+            free(nfile);
+        }
+    }
+
+
     /* Global settings */
     if ((fp = fopen(SYSCONFIG_PATH"/.network", "w")) == NULL) {
         return 9;
-- 
1.6.0.6


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