On 05/18/2011 07:27 AM, Vratislav Podzimek wrote:
--- loader/loader.c | 2 + loader/loader.h | 4 +- loader/net.c | 335 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- loader/net.h | 3 + 4 files changed, 342 insertions(+), 2 deletions(-) diff --git a/loader/loader.c b/loader/loader.c index 2a5d21e..98dfda9 100644 --- a/loader/loader.c +++ b/loader/loader.c @@ -1050,6 +1050,8 @@ static void parseCmdLineFlags(struct loaderData_s * loaderData) { loaderData->mtu = argToLong(v); } else if (!strcasecmp(k, "wepkey")) { loaderData->wepkey = g_strdup(v); + } else if (!strcasecmp(k, "wpakey")) { + loaderData->wpakey = g_strdup(v); } else if (!strcasecmp(k, "linksleep")) { num_link_checks = argToLong(v); } else if (!strcasecmp(k, "nicdelay")) { diff --git a/loader/loader.h b/loader/loader.h index d761a4a..b81fc40 100644 --- a/loader/loader.h +++ b/loader/loader.h @@ -130,7 +130,9 @@ struct loaderData_s { int bootIf_set; char * netCls; int netCls_set; - char *ipv4, *netmask, *gateway, *dns, *domain, *hostname, *peerid, *ethtool, *subchannels, *portname, *essid, *wepkey, *nettype, *ctcprot, *options, *macaddr; + char *ipv4, *netmask, *gateway, *dns, *domain, *hostname, *peerid, *ethtool; + char *subchannels, *portname, *nettype, *ctcprot, *options, *macaddr; + char *essid, *wepkey, *wpakey; #ifdef ENABLE_IPV6 char *ipv6; char *ipv6prefix; diff --git a/loader/net.c b/loader/net.c index 21c8b1e..04e0cd6 100644 --- a/loader/net.c +++ b/loader/net.c @@ -54,6 +54,14 @@ #include "windows.h" #include "ibft.h" +#include<nm-device.h> +#include<nm-setting-connection.h> +#include<nm-setting-wireless.h> +#include<nm-setting-ip4-config.h> +#include<nm-utils.h> +#include<dbus/dbus.h> +#include<dbus/dbus-glib.h> + /* boot flags */ extern uint64_t flags; @@ -1869,6 +1877,8 @@ int chooseNetworkInterface(struct loaderData_s * loaderData) { * kickstart install so that we can do things like grab the ks.cfg from * the network */ int kickstartNetworkUp(struct loaderData_s * loaderData, iface_t * iface) { + int rc=-1; + char *ip_method; if ((is_nm_connected() == TRUE)&& (loaderData->netDev != NULL)&& (loaderData->netDev_set == 1)) @@ -1876,8 +1886,36 @@ int kickstartNetworkUp(struct loaderData_s * loaderData, iface_t * iface) { iface_init_iface_t(iface); - return activateDevice(loaderData, iface); + if (loaderData->ipinfo_set == 1) { + ip_method = "manual"; + } + else { + ip_method = "auto"; + } + if (loaderData->essid != NULL) { + if (loaderData->wepkey != NULL) { + rc = add_and_activate_wifi_connection(&(loaderData->netDev), + loaderData->essid, "wep", loaderData->wepkey, + ip_method, loaderData->ipv4); + } + else if (loaderData->wpakey != NULL) { + rc = add_and_activate_wifi_connection(&(loaderData->netDev), + loaderData->essid, "wpa", loaderData->wpakey, + ip_method, loaderData->ipv4); + } + else { + rc = add_and_activate_wifi_connection(&(loaderData->netDev), + loaderData->essid, "unprotected", NULL, + ip_method, loaderData->ipv4); + }
This style doesn't match our normal coding style.
+ if (0 == rc) {
Nor does this.
+ loaderData->netDev_set = 1; + return(0); + } + else logMessage(ERROR, "wifi activation failed"); + } + return(activateDevice(loaderData, iface));
return is not a function.
} int disconnectDevice(char *device) { @@ -2229,4 +2267,299 @@ int isURLRemote(char *url) { } } +gboolean byte_array_cmp(const GByteArray *array, char *string) +{ + //returns TRUE if array and char* contain the same strings + int i=0; + gboolean ret = TRUE; + if (array->len != strlen(string)) { + return FALSE; + } + while (i<array->len&& ret) { + ret = ret&& (array->data[i] == string[i]); + i++; + } + return ret; +}
Why isn't this just memcmp()?
+ +NMAccessPoint* get_best_ap(NMDeviceWifi *device, char *ssid) { + const GPtrArray *aps; + int i; + NMAccessPoint *candidate = NULL; + guint8 max = 0; + aps = nm_device_wifi_get_access_points(device); + + if (aps == NULL) + { + return NULL; + }
Style again.
+ + for (i = 0; i< aps->len; i++) { + NMAccessPoint *ap = g_ptr_array_index(aps, i); + const GByteArray *byte_ssid = nm_access_point_get_ssid(ap); + if (byte_array_cmp(byte_ssid, ssid)) { + if (nm_access_point_get_strength(ap)> max) { + max = nm_access_point_get_strength(ap); + candidate = ap; + } + } + } + return candidate; +} + +gboolean get_device_and_ap(NMClient *client, char **in_out_iface, char *ssid, + NMDeviceWifi **out_device, NMAccessPoint **out_ap)
Please don't name arguments this way.
+{ + //returns TRUE if device and ap (according to iface and ssid) + //were found + //in_out_iface, out_device, out_ap + const GPtrArray *devices; + int i; + + devices = nm_client_get_devices(client); + for (i = 0; i< devices->len; i++) + { + NMDevice *candidate = g_ptr_array_index(devices, i); + char *dev_iface = strdup((char *)nm_device_get_iface(candidate));
This needs to be checked for failure.
+ if (strcmp(*in_out_iface, "")) + { + if (strcmp(dev_iface, *in_out_iface)) + { + continue; + } + } + if (NM_IS_DEVICE_WIFI(candidate)) + { + NMAccessPoint *ap = NULL; + ap = get_best_ap((NMDeviceWifi*)candidate, ssid); + if (ap != NULL) + { + *out_device = (NMDeviceWifi*)candidate; + *out_ap = ap; + *in_out_iface = strdup(dev_iface); + return TRUE; + } + } + } + return FALSE; +} + + +static void +add_cb (NMClient *client, + const char *connection_path, + const char *active_path, + GError *error, + gpointer user_data) +{ + if (error) + logMessage(ERROR, "Error adding wifi connection: %s", error->message);
The style issues continue like this all the way down. -- Peter Computers don't make errors. What they do, they do on purpose. -- Dale 01234567890123456789012345678901234567890123456789012345678901234567890123456789 _______________________________________________ Anaconda-devel-list mailing list Anaconda-devel-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/anaconda-devel-list