diff options
| author | Michael Biebl <biebl@debian.org> | 2011-08-23 19:16:47 +0200 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2011-08-23 19:16:47 +0200 |
| commit | 263bf4c0c89bb88dc995acd9a6a2de9095fbd461 (patch) | |
| tree | 7224326afe367409e7150e49fad9029f81fe24b8 /src/nm-device-olpc-mesh.c | |
| parent | d465e5fac63f36bcf4069e36827f4b62c494556d (diff) | |
Imported Upstream version 0.9.0 upstream/0.9.0
Diffstat (limited to 'src/nm-device-olpc-mesh.c')
| -rw-r--r-- | src/nm-device-olpc-mesh.c | 75 |
1 files changed, 15 insertions, 60 deletions
diff --git a/src/nm-device-olpc-mesh.c b/src/nm-device-olpc-mesh.c index 8c8f9d0d..88322344 100644 --- a/src/nm-device-olpc-mesh.c +++ b/src/nm-device-olpc-mesh.c @@ -104,7 +104,6 @@ struct _NMDeviceOlpcMeshPrivate gint8 num_freqs; guint32 freqs[IW_MAX_FREQUENCIES]; - guint8 we_version; gboolean up; NMDevice * companion; @@ -147,44 +146,7 @@ nm_olpc_mesh_error_get_type (void) static guint32 real_get_generic_capabilities (NMDevice *dev) { - int fd; - guint32 caps = NM_DEVICE_CAP_NONE; - struct iw_range range; - struct iwreq wrq; - const char *iface = nm_device_get_iface (dev); - - /* Check for Wireless Extensions support >= 16 for wireless devices */ - - fd = socket (PF_INET, SOCK_DGRAM, 0); - if (fd < 0) { - nm_log_warn (LOGD_OLPC_MESH, "couldn't open control socket."); - goto out; - } - - 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) ⦥ - wrq.u.data.length = sizeof (struct iw_range); - - if (ioctl (fd, SIOCGIWRANGE, &wrq) < 0) { - nm_log_warn (LOGD_OLPC_MESH, "couldn't get driver range information."); - goto out; - } - - if ((wrq.u.data.length < 300) || (range.we_version_compiled < 16)) { - nm_log_warn (LOGD_OLPC_MESH, - "(%s): driver's Wireless Extensions version (%d) is too old.", - iface, range.we_version_compiled); - goto out; - } else { - caps |= NM_DEVICE_CAP_NM_SUPPORTED; - } - -out: - if (fd >= 0) - close (fd); - return caps; + return NM_DEVICE_CAP_NM_SUPPORTED; } static void @@ -193,7 +155,6 @@ nm_device_olpc_mesh_init (NMDeviceOlpcMesh * self) NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (self); priv->dispose_has_run = FALSE; - priv->we_version = 0; priv->companion = NULL; priv->stage1_waiting = FALSE; @@ -276,15 +237,24 @@ constructor (GType type, wrq.u.data.pointer = (caddr_t) ⦥ wrq.u.data.length = sizeof (struct iw_range); - if (ioctl (fd, SIOCGIWRANGE, &wrq) < 0) + if (ioctl (fd, SIOCGIWRANGE, &wrq) < 0) { + nm_log_info (LOGD_HW | LOGD_WIFI, "(%s): driver WEXT range request failed", + nm_device_get_iface (NM_DEVICE (self))); + goto error; + } + + if ((wrq.u.data.length < 300) || (range.we_version_compiled < 21)) { + nm_log_info (LOGD_HW | LOGD_WIFI, + "(%s): driver WEXT version too old (got %d, expected >= 21)", + nm_device_get_iface (NM_DEVICE (self)), + range.we_version_compiled); goto error; + } priv->num_freqs = MIN (range.num_frequency, IW_MAX_FREQUENCIES); for (i = 0; i < priv->num_freqs; i++) priv->freqs[i] = iw_freq_to_uint32 (&range.freq[i]); - priv->we_version = range.we_version_compiled; - close (fd); /* shorter timeout for mesh connectivity */ @@ -453,7 +423,7 @@ create_socket_with_request (NMDevice *self, struct iwreq *req) g_return_val_if_fail (self != NULL, -1); sk = socket (AF_INET, SOCK_DGRAM, 0); - if (!sk) { + if (sk == -1) { nm_log_err (LOGD_OLPC_MESH, "Couldn't create socket: %d.", errno); return -1; } @@ -531,7 +501,6 @@ nm_device_olpc_mesh_set_channel (NMDeviceOlpcMesh *self, guint32 channel) static void nm_device_olpc_mesh_set_ssid (NMDeviceOlpcMesh *self, const GByteArray * ssid) { - NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (self); int sk; struct iwreq wrq; const char * iface; @@ -541,7 +510,7 @@ nm_device_olpc_mesh_set_ssid (NMDeviceOlpcMesh *self, const GByteArray * ssid) g_return_if_fail (self != NULL); sk = socket (AF_INET, SOCK_DGRAM, 0); - if (!sk) { + if (sk == -1) { nm_log_err (LOGD_OLPC_MESH, "Couldn't create socket: %d.", errno); return; } @@ -554,24 +523,10 @@ nm_device_olpc_mesh_set_ssid (NMDeviceOlpcMesh *self, const GByteArray * ssid) memcpy (buf, ssid->data, MIN (sizeof (buf) - 1, len)); } wrq.u.essid.pointer = (caddr_t) buf; - - if (priv->we_version < 21) { - /* For historic reasons, set SSID length to include one extra - * character, C string nul termination, even though SSID is - * really an octet string that should not be presented as a C - * string. Some Linux drivers decrement the length by one and - * can thus end up missing the last octet of the SSID if the - * length is not incremented here. WE-21 changes this to - * explicitly require the length _not_ to include nul - * termination. */ - if (len) - len++; - } wrq.u.essid.length = len; wrq.u.essid.flags = (len > 0) ? 1 : 0; /* 1=enable SSID, 0=disable/any */ strncpy (wrq.ifr_name, iface, IFNAMSIZ); - if (ioctl (sk, SIOCSIWESSID, &wrq) < 0) { if (errno != ENODEV) { nm_log_err (LOGD_OLPC_MESH, "(%s): error setting SSID to '%s': %s", |