~dylanmccall/ubuntu/oneiric/network-manager-applet/lp852961-disable-autostart-for-gnome-shell

« back to all changes in this revision

Viewing changes to src/utils/utils.c

  • Committer: Bazaar Package Importer
  • Author(s): Mathieu Trudel-Lapierre
  • Date: 2011-05-30 13:25:18 UTC
  • mto: This revision was merged to the branch mainline in revision 68.
  • Revision ID: james.westby@ubuntu.com-20110530132518-ya5i5mcrl8szsmoj
Tags: upstream-0.8.9997+git.20110529t170033.9ec4c5d
ImportĀ upstreamĀ versionĀ 0.8.9997+git.20110529t170033.9ec4c5d

Show diffs side-by-side

added added

removed removed

Lines of Context:
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.
19
19
 *
20
 
 * (C) Copyright 2007 - 2010 Red Hat, Inc.
 
20
 * (C) Copyright 2007 - 2011 Red Hat, Inc.
21
21
 */
22
22
 
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>
34
34
 
35
35
#include <nm-setting-connection.h>
41
41
#include <nm-setting-cdma.h>
42
42
#include <nm-setting-pppoe.h>
43
43
#include <nm-setting-bluetooth.h>
 
44
#include <nm-setting-wimax.h>
44
45
#include <nm-utils.h>
45
46
 
46
47
#include "utils.h"
47
 
#include "gconf-helpers.h"
48
48
 
49
49
static char *ignored_words[] = {
50
50
        "Semiconductor",
538
538
        return addr_match;
539
539
}
540
540
 
 
541
static gboolean
 
542
connection_valid_for_wimax (NMConnection *connection,
 
543
                            NMSettingConnection *s_con,
 
544
                            NMDevice *device,
 
545
                            gpointer specific_object)
 
546
{
 
547
        NMDeviceWimax *wimax = NM_DEVICE_WIMAX (device);
 
548
        NMSettingWimax *s_wimax;
 
549
        const char *str_mac;
 
550
        struct ether_addr *bin_mac;
 
551
        const char *connection_type;
 
552
        const GByteArray *setting_mac;
 
553
 
 
554
        connection_type = nm_setting_connection_get_connection_type (s_con);
 
555
        if (strcmp (connection_type, NM_SETTING_WIMAX_SETTING_NAME))
 
556
                return FALSE;
 
557
 
 
558
        s_wimax = (NMSettingWimax *) nm_connection_get_setting (connection, NM_TYPE_SETTING_WIMAX);
 
559
        if (!s_wimax)
 
560
                return FALSE;
 
561
 
 
562
        if (s_wimax) {
 
563
                /* Match MAC address */
 
564
                setting_mac = nm_setting_wimax_get_mac_address (s_wimax);
 
565
                if (!setting_mac)
 
566
                        return TRUE;
 
567
 
 
568
                str_mac = nm_device_wimax_get_hw_address (wimax);
 
569
                g_return_val_if_fail (str_mac != NULL, FALSE);
 
570
 
 
571
                bin_mac = ether_aton (str_mac);
 
572
                g_return_val_if_fail (bin_mac != NULL, FALSE);
 
573
 
 
574
                if (memcmp (bin_mac->ether_addr_octet, setting_mac->data, ETH_ALEN))
 
575
                        return FALSE;
 
576
        }
 
577
 
 
578
        return TRUE;
 
579
}
 
580
 
541
581
gboolean
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;
 
601
 
 
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);
 
607
                else
 
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);
565
613
        else
566
614
                g_warning ("Unknown device type '%s'", g_type_name (G_OBJECT_TYPE(device)));
567
615
 
584
632
        return filtered;
585
633
}
586
634
 
587
 
gboolean
588
 
utils_mac_valid (const struct ether_addr *addr)
589
 
{
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 */
594
 
 
595
 
        g_return_val_if_fail (addr != NULL, FALSE);
596
 
 
597
 
        /* Compare the AP address the card has with invalid ethernet MAC addresses. */
598
 
        if (!memcmp (addr->ether_addr_octet, &invalid1, ETH_ALEN))
599
 
                return FALSE;
600
 
 
601
 
        if (!memcmp (addr->ether_addr_octet, &invalid2, ETH_ALEN))
602
 
                return FALSE;
603
 
 
604
 
        if (!memcmp (addr->ether_addr_octet, &invalid3, ETH_ALEN))
605
 
                return FALSE;
606
 
 
607
 
        if (!memcmp (addr->ether_addr_octet, &invalid4, ETH_ALEN))
608
 
                return FALSE;
609
 
 
610
 
        if (addr->ether_addr_octet[0] & 1) /* Multicast addresses */
611
 
                return FALSE;
612
 
        
613
 
        return TRUE;
614
 
}
615
 
 
616
 
char *
617
 
utils_ether_ntop (const struct ether_addr *mac)
618
 
{
619
 
        /* we like leading zeros and all-caps, instead
620
 
         * of what glibc's ether_ntop() gives us
621
 
         */
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]);
626
 
}
627
 
 
628
 
 
629
 
char *
630
 
utils_next_available_name (GSList *connections, const char *format)
631
 
{
632
 
        GSList *names = NULL, *iter;
633
 
        char *cname = NULL;
634
 
        int i = 0;
635
 
 
636
 
        for (iter = connections; iter; iter = g_slist_next (iter)) {
637
 
                NMConnection *candidate = NM_CONNECTION (iter->data);
638
 
                NMSettingConnection *s_con;
639
 
                const char *id;
640
 
 
641
 
                s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (candidate, NM_TYPE_SETTING_CONNECTION));
642
 
                id = nm_setting_connection_get_id (s_con);
643
 
                g_assert (id);
644
 
                names = g_slist_append (names, (gpointer) id);
645
 
        }       
646
 
 
647
 
        /* Find the next available unique connection name */
648
 
        while (!cname && (i++ < 10000)) {
649
 
                char *temp;
650
 
                gboolean found = FALSE;
651
 
 
652
 
                temp = g_strdup_printf (format, i);
653
 
                for (iter = names; iter; iter = g_slist_next (iter)) {
654
 
                        if (!strcmp (iter->data, temp)) {
655
 
                                found = TRUE;
656
 
                                break;
657
 
                        }
658
 
                }
659
 
                if (!found)
660
 
                        cname = temp;
661
 
                else
662
 
                        g_free (temp);
663
 
        }
664
 
 
665
 
        g_slist_free (names);
666
 
        return cname;
667
 
}
668
 
 
669
635
char *
670
636
utils_hash_ap (const GByteArray *ssid,
671
637
               NM80211Mode mode,
761
727
        return g_string_free (escaped, FALSE);
762
728
}
763
729
 
 
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)
 
737
{
 
738
        GnomeKeyringAttributeList *attrs = NULL;
 
739
        NMSettingConnection *s_con;
 
740
 
 
741
        if (connection) {
 
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);
 
746
        }
 
747
 
 
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);
 
752
 
 
753
        if (out_display_name) {
 
754
                *out_display_name = g_strdup_printf ("Network secret for %s/%s/%s",
 
755
                                                     connection_id,
 
756
                                                     setting_name,
 
757
                                                     setting_key);
 
758
        }
 
759
 
 
760
        attrs = gnome_keyring_attribute_list_new ();
 
761
        gnome_keyring_attribute_list_append_string (attrs,
 
762
                                                    KEYRING_UUID_TAG,
 
763
                                                    connection_uuid);
 
764
        gnome_keyring_attribute_list_append_string (attrs,
 
765
                                                    KEYRING_SN_TAG,
 
766
                                                    setting_name);
 
767
        gnome_keyring_attribute_list_append_string (attrs,
 
768
                                                    KEYRING_SK_TAG,
 
769
                                                    setting_key);
 
770
        return attrs;
 
771
}
 
772