Commit f4540f04 authored by Dan Williams's avatar Dan Williams
Browse files

2007-06-27 Dan Williams <dcbw@redhat.com>

	* Make SSIDs GByteArrays everywhere
	* Rename "essid" -> "ssid" everywhere that's appropriate
	* Refcount activation_ap member of the 802.11 wireless device class



git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2620 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
parent 8c33f85a
2007-06-27 Dan Williams <dcbw@redhat.com>
* Make SSIDs GByteArrays everywhere
* Rename "essid" -> "ssid" everywhere that's appropriate
* Refcount activation_ap member of the 802.11 wireless device class
2007-06-27 Tambet Ingo <tambet@ximian.com>
* libnm-glib/nm-object.[ch]: Add these to the SVN, oops.
......
......@@ -4,7 +4,7 @@
<interface name="org.freedesktop.NetworkManager.AccessPoint">
<property name="Capabilities" type="u" access="read"/>
<property name="Encrypted" type="b" access="read"/>
<property name="Essid" type="s" access="read"/>
<property name="Ssid" type="ay" access="read"/>
<property name="Frequency" type="d" access="read"/>
<property name="HwAddress" type="s" access="read"/>
<property name="Mode" type="i" access="read"/>
......
......@@ -3,12 +3,57 @@
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <iwlib.h>
#include <wireless.h>
#include "nm-client.h"
#include "nm-device.h"
#include "nm-device-802-3-ethernet.h"
#include "nm-device-802-11-wireless.h"
/* Shamelessly ripped from the Linux kernel ieee80211 stack */
static gboolean
nm_utils_is_empty_ssid (const char * ssid, int len)
{
/* Single white space is for Linksys APs */
if (len == 1 && ssid[0] == ' ')
return TRUE;
/* Otherwise, if the entire ssid is 0, we assume it is hidden */
while (len--) {
if (ssid[len] != '\0')
return FALSE;
}
return TRUE;
}
static const char *
nm_utils_escape_ssid (const char * ssid, guint32 len)
{
static char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
const char *s = ssid;
char *d = escaped;
if (nm_utils_is_empty_ssid (ssid, len)) {
memcpy (escaped, "<hidden>", sizeof ("<hidden>"));
return escaped;
}
len = MIN (len, (guint32) IW_ESSID_MAX_SIZE);
while (len--) {
if (*s == '\0') {
*d++ = '\\';
*d++ = '0';
s++;
} else {
*d++ = *s++;
}
}
*d = '\0';
return escaped;
}
static gboolean
test_wireless_enabled (NMClient *client)
{
......@@ -120,11 +165,13 @@ dump_ip4_config (NMIP4Config *cfg)
static void
dump_access_point (NMAccessPoint *ap)
{
char *str;
GByteArray * ssid;
char * str;
str = nm_access_point_get_essid (ap);
g_print ("\tEssid: %s\n", str);
g_free (str);
ssid = nm_access_point_get_ssid (ap);
g_print ("\tSsid: %s\n",
ssid ? nm_utils_escape_ssid (ssid->data, ssid->len) : "(none)");
g_byte_array_free (ssid, TRUE);
str = nm_access_point_get_hw_address (ap);
g_print ("\tMAC Address: %s\n", str);
......
......@@ -117,12 +117,12 @@ nm_access_point_is_encrypted (NMAccessPoint *ap)
return nm_object_get_boolean_property (NM_OBJECT (ap), NM_DBUS_INTERFACE_ACCESS_POINT, "Encrypted");
}
char *
nm_access_point_get_essid (NMAccessPoint *ap)
GByteArray *
nm_access_point_get_ssid (NMAccessPoint *ap)
{
g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), NULL);
return nm_object_get_string_property (NM_OBJECT (ap), NM_DBUS_INTERFACE_ACCESS_POINT, "Essid");
return nm_object_get_byte_array_property (NM_OBJECT (ap), NM_DBUS_INTERFACE_ACCESS_POINT, "Ssid");
}
gdouble
......
......@@ -27,13 +27,13 @@ GType nm_access_point_get_type (void);
NMAccessPoint *nm_access_point_new (DBusGConnection *connection, const char *path);
guint32 nm_access_point_get_capabilities (NMAccessPoint *ap);
gboolean nm_access_point_is_encrypted (NMAccessPoint *ap);
char *nm_access_point_get_essid (NMAccessPoint *ap);
gdouble nm_access_point_get_frequency (NMAccessPoint *ap);
char *nm_access_point_get_hw_address (NMAccessPoint *ap);
int nm_access_point_get_mode (NMAccessPoint *ap);
guint32 nm_access_point_get_rate (NMAccessPoint *ap);
int nm_access_point_get_strength (NMAccessPoint *ap);
guint32 nm_access_point_get_capabilities (NMAccessPoint *ap);
gboolean nm_access_point_is_encrypted (NMAccessPoint *ap);
GByteArray * nm_access_point_get_ssid (NMAccessPoint *ap);
gdouble nm_access_point_get_frequency (NMAccessPoint *ap);
char * nm_access_point_get_hw_address (NMAccessPoint *ap);
int nm_access_point_get_mode (NMAccessPoint *ap);
guint32 nm_access_point_get_rate (NMAccessPoint *ap);
int nm_access_point_get_strength (NMAccessPoint *ap);
#endif /* NM_ACCESS_POINT_H */
......@@ -301,3 +301,27 @@ nm_object_get_double_property (NMObject *object,
return d;
}
GByteArray *
nm_object_get_byte_array_property (NMObject *object,
const char *interface,
const char *prop_name)
{
GByteArray * array = NULL;
GValue value = {0,};
if (nm_object_get_property (object, interface, prop_name, &value)) {
GArray * tmp = g_value_get_boxed (&value);
int i;
unsigned char byte;
array = g_byte_array_sized_new (tmp->len);
for (i = 0; i < tmp->len; i++) {
byte = g_array_index (tmp, unsigned char, i);
g_byte_array_append (array, &byte, 1);
}
}
return array;
}
......@@ -64,5 +64,9 @@ gdouble nm_object_get_double_property (NMObject *object,
const char *interface,
const char *prop_name);
GByteArray *nm_object_get_byte_array_property (NMObject *object,
const char *interface,
const char *prop_name);
#endif /* NM_OBJECT_H */
......@@ -30,7 +30,7 @@
#include "nm-access-point-glue.h"
/* This is a controlled list. Want to add to it? Stop. Ask first. */
static const char * default_essid_list[] =
static const char * default_ssid_list[] =
{
"linksys",
"linksys-a",
......@@ -49,8 +49,7 @@ typedef struct
char *dbus_path;
/* Scanned or cached values */
char * essid;
char * orig_essid;
GByteArray * ssid;
struct ether_addr address;
int mode; /* from IW_MODE_* in wireless.h */
gint8 strength;
......@@ -93,16 +92,16 @@ enum {
PROP_0,
PROP_CAPABILITIES,
PROP_ENCRYPTED,
PROP_ESSID,
PROP_SSID,
PROP_FREQUENCY,
PROP_HW_ADDRESS,
PROP_MODE,
PROP_RATE,
PROP_STRENGTH,
LAST_PROP
};
static void
nm_ap_init (NMAccessPoint *ap)
{
......@@ -121,8 +120,7 @@ finalize (GObject *object)
NMAccessPointPrivate *priv = NM_AP_GET_PRIVATE (object);
g_free (priv->dbus_path);
g_free (priv->essid);
g_free (priv->orig_essid);
g_byte_array_free (priv->ssid, TRUE);
g_slist_foreach (priv->user_addresses, (GFunc)g_free, NULL);
g_slist_free (priv->user_addresses);
......@@ -137,28 +135,28 @@ set_property (GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec)
{
NMAccessPointPrivate *priv = NM_AP_GET_PRIVATE (object);
const char *essid;
GArray * ssid;
int mode;
switch (prop_id) {
case PROP_CAPABILITIES:
priv->capabilities = g_value_get_uint (value);
break;
case PROP_ESSID:
essid = g_value_get_string (value);
if (priv->essid) {
g_free (priv->essid);
g_free (priv->orig_essid);
priv->essid = NULL;
priv->orig_essid = NULL;
case PROP_SSID:
ssid = g_value_get_boxed (value);
if (priv->ssid) {
g_byte_array_free (priv->ssid, TRUE);
priv->ssid = NULL;
}
if (essid) {
priv->orig_essid = g_strdup (essid);
priv->essid = nm_utils_essid_to_utf8 (essid);
if (ssid) {
int i;
unsigned char byte;
priv->ssid = g_byte_array_sized_new (ssid->len);
for (i = 0; i < ssid->len; i++) {
byte = g_array_index (ssid, unsigned char, i);
g_byte_array_append (priv->ssid, &byte, 1);
}
}
break;
case PROP_FREQUENCY:
priv->freq = g_value_get_double (value);
......@@ -189,6 +187,8 @@ get_property (GObject *object, guint prop_id,
{
NMAccessPointPrivate *priv = NM_AP_GET_PRIVATE (object);
char hw_addr_buf[20];
GArray * ssid;
int i;
switch (prop_id) {
case PROP_CAPABILITIES:
......@@ -197,8 +197,12 @@ get_property (GObject *object, guint prop_id,
case PROP_ENCRYPTED:
g_value_set_boolean (value, !(priv->capabilities & NM_802_11_CAP_PROTO_NONE));
break;
case PROP_ESSID:
g_value_set_string (value, priv->essid);
case PROP_SSID:
ssid = g_array_sized_new (FALSE, TRUE, sizeof (unsigned char), priv->ssid->len);
for (i = 0; i < priv->ssid->len; i++)
g_array_append_val (ssid, priv->ssid->data[i]);
g_value_set_boxed (value, ssid);
g_array_free (ssid, TRUE);
break;
case PROP_FREQUENCY:
g_value_set_double (value, priv->freq);
......@@ -273,12 +277,12 @@ nm_ap_class_init (NMAccessPointClass *ap_class)
G_PARAM_READABLE));
g_object_class_install_property
(object_class, PROP_ESSID,
g_param_spec_string (NM_AP_ESSID,
"ESSID",
"ESSID",
NULL,
G_PARAM_READWRITE));
(object_class, PROP_SSID,
g_param_spec_boxed (NM_AP_SSID,
"SSID",
"SSID",
DBUS_TYPE_G_UCHAR_ARRAY,
G_PARAM_READWRITE));
g_object_class_install_property
(object_class, PROP_FREQUENCY,
......@@ -381,10 +385,11 @@ nm_ap_new_from_ap (NMAccessPoint *src_ap)
src_priv = NM_AP_GET_PRIVATE (src_ap);
new_priv = NM_AP_GET_PRIVATE (new_ap);
if (src_priv->essid && (strlen (src_priv->essid) > 0))
{
new_priv->essid = g_strdup (src_priv->essid);
new_priv->orig_essid = g_strdup (src_priv->orig_essid);
if (src_priv->ssid) {
new_priv->ssid = g_byte_array_sized_new (src_priv->ssid->len);
g_byte_array_append (new_priv->ssid,
src_priv->ssid->data,
src_priv->ssid->len);
}
memcpy (&new_priv->address, &src_priv->address, sizeof (struct ether_addr));
new_priv->mode = src_priv->mode;
......@@ -416,21 +421,18 @@ foreach_property_cb (gpointer key, gpointer value, gpointer user_data)
GArray *array = g_value_get_boxed (variant);
if (!strcmp (key, "ssid")) {
char ssid[33];
int ssid_len = sizeof (ssid);
guint32 len = MIN (IW_ESSID_MAX_SIZE, array->len);
GByteArray * ssid;
if (array->len < sizeof (ssid))
ssid_len = array->len;
if (ssid_len <= 0)
return;
/* Stupid ieee80211 layer uses <hidden> */
if (((ssid_len == 8) || (ssid_len == 9))
if (((len == 8) || (len == 9))
&& (memcmp (array->data, "<hidden>", 8) == 0))
return;
memset (&ssid, 0, sizeof (ssid));
memcpy (&ssid, array->data, ssid_len);
ssid[32] = '\0';
nm_ap_set_essid (ap, ssid);
ssid = g_byte_array_sized_new (len);
g_byte_array_append (ssid, array->data, len);
nm_ap_set_ssid (ap, ssid);
g_byte_array_free (ssid, TRUE);
} else if (!strcmp (key, "bssid")) {
struct ether_addr addr;
......@@ -496,7 +498,7 @@ nm_ap_new_from_properties (GHashTable *properties)
g_get_current_time (&cur_time);
nm_ap_set_last_seen (ap, cur_time.tv_sec);
if (!nm_ap_get_essid (ap))
if (!nm_ap_get_ssid (ap))
nm_ap_set_broadcast (ap, FALSE);
return ap;
......@@ -542,28 +544,21 @@ void nm_ap_set_timestamp_via_timestamp (NMAccessPoint *ap, const GTimeVal *times
}
/*
* Get/set functions for essid
* Get/set functions for ssid
*
*/
const char * nm_ap_get_essid (const NMAccessPoint *ap)
{
g_return_val_if_fail (NM_IS_AP (ap), NULL);
return NM_AP_GET_PRIVATE (ap)->essid;
}
const char * nm_ap_get_orig_essid (const NMAccessPoint *ap)
const GByteArray * nm_ap_get_ssid (const NMAccessPoint *ap)
{
g_return_val_if_fail (NM_IS_AP (ap), NULL);
return NM_AP_GET_PRIVATE (ap)->orig_essid;
return NM_AP_GET_PRIVATE (ap)->ssid;
}
void nm_ap_set_essid (NMAccessPoint *ap, const char * essid)
void nm_ap_set_ssid (NMAccessPoint *ap, const GByteArray * ssid)
{
g_return_if_fail (NM_IS_AP (ap));
g_object_set (ap, NM_AP_ESSID, essid, NULL);
g_object_set (ap, NM_AP_SSID, ssid, NULL);
}
......@@ -926,18 +921,20 @@ void nm_ap_set_user_addresses (NMAccessPoint *ap, GSList *list)
}
gboolean nm_ap_has_manufacturer_default_essid (NMAccessPoint *ap)
gboolean nm_ap_has_manufacturer_default_ssid (NMAccessPoint *ap)
{
const char **default_essid = default_essid_list;
const char *this_essid;
const char **default_ssid = default_ssid_list;
const GByteArray * this_ssid;
g_return_val_if_fail (NM_IS_AP (ap), FALSE);
this_essid = NM_AP_GET_PRIVATE (ap)->essid;
this_ssid = NM_AP_GET_PRIVATE (ap)->ssid;
while (*default_essid)
{
if (!strcmp (*(default_essid++), this_essid))
return TRUE;
while (*default_ssid) {
if (this_ssid->len == strlen (*default_ssid)) {
if (!memcmp (*default_ssid, this_ssid->data, this_ssid->len))
return TRUE;
}
default_ssid++;
}
return FALSE;
......
......@@ -38,7 +38,7 @@
#define NM_AP_CAPABILITIES "capabilities"
#define NM_AP_ENCRYPTED "encrypted"
#define NM_AP_ESSID "essid"
#define NM_AP_SSID "ssid"
#define NM_AP_FREQUENCY "frequency"
#define NM_AP_HW_ADDRESS "hw-address"
#define NM_AP_MODE "mode"
......@@ -67,10 +67,8 @@ const GTimeVal * nm_ap_get_timestamp (const NMAccessPoint *ap);
void nm_ap_set_timestamp (NMAccessPoint *ap, glong sec, glong usec);
void nm_ap_set_timestamp_via_timestamp (NMAccessPoint *ap, const GTimeVal *timestamp);
const char * nm_ap_get_essid (const NMAccessPoint *ap);
void nm_ap_set_essid (NMAccessPoint *ap, const char *essid);
/* Get essid in original over-the-air form */
const char * nm_ap_get_orig_essid (const NMAccessPoint *ap);
const GByteArray * nm_ap_get_ssid (const NMAccessPoint * ap);
void nm_ap_set_ssid (NMAccessPoint * ap, const GByteArray * ssid);
guint32 nm_ap_get_capabilities (NMAccessPoint *ap);
void nm_ap_set_capabilities (NMAccessPoint *ap, guint32 capabilities);
......@@ -125,6 +123,6 @@ void nm_ap_add_capabilities_for_wep (NMAccessPoint *ap);
* This is not intended to return true for all APs with manufacturer defaults. It is intended to return true for
* only the MOST COMMON manufacturing defaults.
*/
gboolean nm_ap_has_manufacturer_default_essid (NMAccessPoint *ap);
gboolean nm_ap_has_manufacturer_default_ssid (NMAccessPoint *ap);
#endif /* NM_ACCESS_POINT_H */
......@@ -158,22 +158,23 @@ void nm_ap_list_remove_ap (NMAccessPointList *list, NMAccessPoint *ap)
/*
* nm_ap_list_remove_ap_by_essid
* nm_ap_list_remove_ap_by_ssid
*
* Helper to remove an AP from an AP list by the AP's ESSID.
* Helper to remove an AP from an AP list by the AP's SSID.
*
*/
void nm_ap_list_remove_ap_by_essid (NMAccessPointList *list, const char *network)
void
nm_ap_list_remove_ap_by_ssid (NMAccessPointList *list, const GByteArray * ssid)
{
GSList *elt = NULL;
GSList * elt = NULL;
g_return_if_fail (list != NULL);
g_return_if_fail (network != NULL);
g_return_if_fail (ssid != NULL);
for (elt = list->ap_list; elt; elt = g_slist_next (elt)) {
NMAccessPoint * list_ap = (NMAccessPoint *) elt->data;
if (nm_null_safe_strcmp (nm_ap_get_essid (list_ap), network) == 0) {
if (nm_utils_same_ssid (nm_ap_get_ssid (list_ap), ssid)) {
list->ap_list = g_slist_remove_link (list->ap_list, elt);
g_object_unref (list_ap);
g_slist_free (elt);
......@@ -182,10 +183,10 @@ void nm_ap_list_remove_ap_by_essid (NMAccessPointList *list, const char *network
}
}
/* nm_ap_list_remove_duplicate_essids
/* nm_ap_list_remove_duplicate_ssids
*
*/
void nm_ap_list_remove_duplicate_essids (NMAccessPointList *list)
void nm_ap_list_remove_duplicate_ssids (NMAccessPointList *list)
{
NMAccessPoint *removal_ap;
NMAccessPoint *list_ap_max;
......@@ -201,12 +202,14 @@ void nm_ap_list_remove_duplicate_essids (NMAccessPointList *list)
for (elt_i = list->ap_list; elt_i; elt_i = g_slist_next (elt_i)) {
NMAccessPoint * list_ap_i = (NMAccessPoint *) elt_i->data;
const GByteArray * list_ap_i_ssid = nm_ap_get_ssid (list_ap_i);
gboolean found = FALSE;
for (elt_j = list->ap_list; elt_j < elt_i; elt_j = g_slist_next (elt_j)) {
NMAccessPoint *list_ap_j = (NMAccessPoint *) elt_j->data;
NMAccessPoint * list_ap_j = (NMAccessPoint *) elt_j->data;
const GByteArray * list_ap_j_ssid = nm_ap_get_ssid (list_ap_j);
if ((found = (nm_null_safe_strcmp (nm_ap_get_essid (list_ap_i), nm_ap_get_essid (list_ap_j)) == 0)))
if ((found = nm_utils_same_ssid (list_ap_i_ssid, list_ap_j_ssid)))
break;
}
......@@ -219,9 +222,10 @@ void nm_ap_list_remove_duplicate_essids (NMAccessPointList *list)
for (elt_j = g_slist_next (elt_i); elt_j; elt_j = g_slist_next (elt_j)) {
NMAccessPoint *list_ap_j = (NMAccessPoint *) elt_j->data;
const GByteArray * list_ap_j_ssid = nm_ap_get_ssid (list_ap_j);
strengthj = nm_ap_get_strength (list_ap_j);
if (nm_null_safe_strcmp (nm_ap_get_essid (list_ap_i), nm_ap_get_essid (list_ap_j)) == 0) {
if (nm_utils_same_ssid (list_ap_i_ssid, list_ap_j_ssid)) {
if (strengthj > max_strength) {
removal_list = g_slist_append (removal_list, list_ap_max);
list_ap_max = list_ap_j;
......@@ -242,38 +246,35 @@ void nm_ap_list_remove_duplicate_essids (NMAccessPointList *list)
/*
* nm_ap_list_get_ap_by_essid
* nm_ap_list_get_ap_by_ssid
*
* Search through an access point list and return the access point
* that has a given essid.
* that has a given SSID.
*
*/
NMAccessPoint *nm_ap_list_get_ap_by_essid (NMAccessPointList *list, const char *network)
NMAccessPoint *
nm_ap_list_get_ap_by_ssid (NMAccessPointList *list, const GByteArray * ssid)
{
NMAccessPoint *ap;
NMAccessPoint *found_ap = NULL;
NMAPListIter *iter;
if (!network)
return (NULL);
if (!list)
return (NULL);
if (!ssid || !list)
return NULL;
if (!(iter = nm_ap_list_iter_new (list)))
return (NULL);
return NULL;
while ((ap = nm_ap_list_iter_next (iter)))
{
if (nm_ap_get_essid (ap) && (nm_null_safe_strcmp (nm_ap_get_essid (ap), network) == 0))
{
while ((ap = nm_ap_list_iter_next (iter))) {
const GByteArray * ap_ssid = nm_ap_get_ssid (ap);
if (ap_ssid && nm_utils_same_ssid (ap_ssid, ssid)) {
found_ap = ap;
break;
}
}
nm_ap_list_iter_free (iter);
return (found_ap);
return found_ap;
}
......@@ -362,7 +363,7 @@ void nm_ap_list_copy_properties (NMAccessPointList *dest, NMAccessPointList *sou
{
NMAccessPoint *src_ap = NULL;
if ((src_ap = nm_ap_list_get_ap_by_essid (source, nm_ap_get_essid (dest_ap))))
if ((src_ap = nm_ap_list_get_ap_by_ssid (source, nm_ap_get_ssid (dest_ap))))
{
nm_ap_set_invalid (dest_ap, nm_ap_get_invalid (src_ap));
nm_ap_set_security (dest_ap, nm_ap_get_security (src_ap));
......@@ -374,45 +375,45 @@ void nm_ap_list_copy_properties (NMAccessPointList *dest, NMAccessPointList *sou
/*
* nm_ap_list_copy_one_essid_by_address
* nm_ap_list_copy_one_ssid_by_address
*
* If the access point doesn't have an ESSID, search through a list of access points
* If the access point doesn't have an SSID, search through a list of access points
* and find one (if any) that has the MAC address of the access point we're looking for.
* If one is found, copy the essid over to the original access point.
* If one is found, copy the SSID over to the original access point.
*
*/
void
nm_ap_list_copy_one_essid_by_address (NMAccessPoint *ap,
NMAccessPointList *search_list)
nm_ap_list_copy_one_ssid_by_address (NMAccessPoint *ap,
NMAccessPointList *search_list)
{
NMAccessPoint *found_ap;
const char *essid;
NMAccessPoint * found_ap;
const GByteArray * ssid;
g_return_if_fail (ap != NULL);
/* Ignore APs that already have an ESSID */
if (!search_list || nm_ap_get_essid (ap))
/* Ignore APs that already have an SSID */
if (!search_list || nm_ap_get_ssid (ap))
return;
found_ap = nm_ap_list_get_ap_by_address