17
17
* with this program; if not, write to the Free Software Foundation, Inc.,
18
18
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
* (C) Copyright 2007 - 2010 Red Hat, Inc.
20
* (C) Copyright 2007 - 2011 Red Hat, Inc.
23
23
#include <config.h>
28
28
#include <nm-device-ethernet.h>
29
29
#include <nm-device-wifi.h>
30
30
#include <nm-device-bt.h>
31
#include <nm-gsm-device.h>
32
#include <nm-cdma-device.h>
31
#include <nm-device-modem.h>
32
#include <nm-device-wimax.h>
33
33
#include <nm-access-point.h>
35
35
#include <nm-setting-connection.h>
538
538
return addr_match;
542
connection_valid_for_wimax (NMConnection *connection,
543
NMSettingConnection *s_con,
545
gpointer specific_object)
547
NMDeviceWimax *wimax = NM_DEVICE_WIMAX (device);
548
NMSettingWimax *s_wimax;
550
struct ether_addr *bin_mac;
551
const char *connection_type;
552
const GByteArray *setting_mac;
554
connection_type = nm_setting_connection_get_connection_type (s_con);
555
if (strcmp (connection_type, NM_SETTING_WIMAX_SETTING_NAME))
558
s_wimax = (NMSettingWimax *) nm_connection_get_setting (connection, NM_TYPE_SETTING_WIMAX);
563
/* Match MAC address */
564
setting_mac = nm_setting_wimax_get_mac_address (s_wimax);
568
str_mac = nm_device_wimax_get_hw_address (wimax);
569
g_return_val_if_fail (str_mac != NULL, FALSE);
571
bin_mac = ether_aton (str_mac);
572
g_return_val_if_fail (bin_mac != NULL, FALSE);
574
if (memcmp (bin_mac->ether_addr_octet, setting_mac->data, ETH_ALEN))
542
582
utils_connection_valid_for_device (NMConnection *connection,
543
583
NMDevice *device,
556
596
return connection_valid_for_wired (connection, s_con, device, specific_object);
557
597
else if (NM_IS_DEVICE_WIFI (device))
558
598
return connection_valid_for_wireless (connection, s_con, device, specific_object);
559
else if (NM_IS_GSM_DEVICE (device))
560
return connection_valid_for_gsm (connection, s_con, device, specific_object);
561
else if (NM_IS_CDMA_DEVICE (device))
562
return connection_valid_for_cdma (connection, s_con, device, specific_object);
563
else if (NM_IS_DEVICE_BT (device))
599
else if (NM_IS_DEVICE_MODEM (device)) {
600
NMDeviceModemCapabilities caps;
602
caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (device));
603
if (caps & NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS)
604
return connection_valid_for_gsm (connection, s_con, device, specific_object);
605
else if (caps & NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO)
606
return connection_valid_for_cdma (connection, s_con, device, specific_object);
608
g_warning ("Unhandled modem capabilities 0x%X", caps);
609
} else if (NM_IS_DEVICE_BT (device))
564
610
return connection_valid_for_bt (connection, s_con, device, specific_object);
611
else if (NM_IS_DEVICE_WIMAX (device))
612
return connection_valid_for_wimax (connection, s_con, device, specific_object);
566
614
g_warning ("Unknown device type '%s'", g_type_name (G_OBJECT_TYPE(device)));
588
utils_mac_valid (const struct ether_addr *addr)
590
guint8 invalid1[ETH_ALEN] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
591
guint8 invalid2[ETH_ALEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
592
guint8 invalid3[ETH_ALEN] = {0x44, 0x44, 0x44, 0x44, 0x44, 0x44};
593
guint8 invalid4[ETH_ALEN] = {0x00, 0x30, 0xb4, 0x00, 0x00, 0x00}; /* prism54 dummy MAC */
595
g_return_val_if_fail (addr != NULL, FALSE);
597
/* Compare the AP address the card has with invalid ethernet MAC addresses. */
598
if (!memcmp (addr->ether_addr_octet, &invalid1, ETH_ALEN))
601
if (!memcmp (addr->ether_addr_octet, &invalid2, ETH_ALEN))
604
if (!memcmp (addr->ether_addr_octet, &invalid3, ETH_ALEN))
607
if (!memcmp (addr->ether_addr_octet, &invalid4, ETH_ALEN))
610
if (addr->ether_addr_octet[0] & 1) /* Multicast addresses */
617
utils_ether_ntop (const struct ether_addr *mac)
619
/* we like leading zeros and all-caps, instead
620
* of what glibc's ether_ntop() gives us
622
return g_strdup_printf ("%02X:%02X:%02X:%02X:%02X:%02X",
623
mac->ether_addr_octet[0], mac->ether_addr_octet[1],
624
mac->ether_addr_octet[2], mac->ether_addr_octet[3],
625
mac->ether_addr_octet[4], mac->ether_addr_octet[5]);
630
utils_next_available_name (GSList *connections, const char *format)
632
GSList *names = NULL, *iter;
636
for (iter = connections; iter; iter = g_slist_next (iter)) {
637
NMConnection *candidate = NM_CONNECTION (iter->data);
638
NMSettingConnection *s_con;
641
s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (candidate, NM_TYPE_SETTING_CONNECTION));
642
id = nm_setting_connection_get_id (s_con);
644
names = g_slist_append (names, (gpointer) id);
647
/* Find the next available unique connection name */
648
while (!cname && (i++ < 10000)) {
650
gboolean found = FALSE;
652
temp = g_strdup_printf (format, i);
653
for (iter = names; iter; iter = g_slist_next (iter)) {
654
if (!strcmp (iter->data, temp)) {
665
g_slist_free (names);
670
636
utils_hash_ap (const GByteArray *ssid,
671
637
NM80211Mode mode,
761
727
return g_string_free (escaped, FALSE);
730
GnomeKeyringAttributeList *
731
utils_create_keyring_add_attr_list (NMConnection *connection,
732
const char *connection_uuid,
733
const char *connection_id,
734
const char *setting_name,
735
const char *setting_key,
736
char **out_display_name)
738
GnomeKeyringAttributeList *attrs = NULL;
739
NMSettingConnection *s_con;
742
s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION);
743
g_return_val_if_fail (s_con != NULL, NULL);
744
connection_uuid = nm_setting_connection_get_uuid (s_con);
745
connection_id = nm_setting_connection_get_id (s_con);
748
g_return_val_if_fail (connection_uuid != NULL, NULL);
749
g_return_val_if_fail (connection_id != NULL, NULL);
750
g_return_val_if_fail (setting_name != NULL, NULL);
751
g_return_val_if_fail (setting_key != NULL, NULL);
753
if (out_display_name) {
754
*out_display_name = g_strdup_printf ("Network secret for %s/%s/%s",
760
attrs = gnome_keyring_attribute_list_new ();
761
gnome_keyring_attribute_list_append_string (attrs,
764
gnome_keyring_attribute_list_append_string (attrs,
767
gnome_keyring_attribute_list_append_string (attrs,