~awe/ubuntu/saucy/urfkill/fix-touch-armhf-crash

« back to all changes in this revision

Viewing changes to .pc/03_fix_nfc_crash.patch/src/urf-utils.c

  • Committer: Tony Espy
  • Date: 2013-08-28 19:03:42 UTC
  • Revision ID: espy@canonical.com-20130828190342-8f3znbfw1uko4tn3
debian/patches/03_fix_nfc_crash.patch: add support for the
new RFKILL_NFC type to prevent an assertion/crash.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdlib.h>
 
2
#include <libudev.h>
 
3
#include "urf-utils.h"
 
4
 
 
5
/**
 
6
 * get_dmi_info:
 
7
 **/
 
8
DmiInfo *
 
9
get_dmi_info ()
 
10
{
 
11
        struct udev *udev;
 
12
        struct udev_enumerate *enumerate;
 
13
        struct udev_list_entry *devices;
 
14
        struct udev_list_entry *dev_list_entry;
 
15
        struct udev_device *dev;
 
16
        DmiInfo *info = NULL;
 
17
 
 
18
        udev = udev_new ();
 
19
        if (!udev) {
 
20
                g_warning ("Cannot create udev");
 
21
                return NULL;
 
22
        }
 
23
 
 
24
        enumerate = udev_enumerate_new (udev);
 
25
        udev_enumerate_add_match_subsystem (enumerate, "dmi");
 
26
        udev_enumerate_scan_devices (enumerate);
 
27
        devices = udev_enumerate_get_list_entry (enumerate);
 
28
 
 
29
        if (devices == NULL) {
 
30
                g_warning("No dmi devices found.");
 
31
                return NULL;
 
32
        }
 
33
 
 
34
        info = g_new0 (DmiInfo, 1);
 
35
 
 
36
        udev_list_entry_foreach (dev_list_entry, devices) {
 
37
                const char *path;
 
38
                const char *attribute;
 
39
                path = udev_list_entry_get_name (dev_list_entry);
 
40
                dev = udev_device_new_from_syspath (udev, path);
 
41
 
 
42
                attribute = udev_device_get_sysattr_value (dev, "sys_vendor");
 
43
                if (attribute)
 
44
                        info->sys_vendor = g_strdup (attribute);
 
45
 
 
46
                attribute = udev_device_get_sysattr_value (dev, "bios_date");
 
47
                if (attribute)
 
48
                        info->bios_date = g_strdup (attribute);
 
49
 
 
50
                attribute = udev_device_get_sysattr_value (dev, "bios_vendor");
 
51
                if (attribute)
 
52
                        info->bios_vendor = g_strdup (attribute);
 
53
 
 
54
                attribute = udev_device_get_sysattr_value (dev, "bios_version");
 
55
                if (attribute)
 
56
                        info->bios_version = g_strdup (attribute);
 
57
 
 
58
                attribute = udev_device_get_sysattr_value (dev, "product_name");
 
59
                if (attribute)
 
60
                        info->product_name = g_strdup (attribute);
 
61
 
 
62
                attribute = udev_device_get_sysattr_value (dev, "product_version");
 
63
                if (attribute)
 
64
                        info->product_version = g_strdup (attribute);
 
65
 
 
66
                udev_device_unref (dev);
 
67
        }
 
68
 
 
69
        udev_enumerate_unref (enumerate);
 
70
        udev_unref (udev);
 
71
 
 
72
        return info;
 
73
}
 
74
 
 
75
/**
 
76
 * dmi_info_free:
 
77
 **/
 
78
void
 
79
dmi_info_free (DmiInfo *info)
 
80
{
 
81
        g_free (info->sys_vendor);
 
82
        g_free (info->bios_date);
 
83
        g_free (info->bios_vendor);
 
84
        g_free (info->bios_version);
 
85
        g_free (info->product_name);
 
86
        g_free (info->product_version);
 
87
        g_free (info);
 
88
}
 
89
 
 
90
/**
 
91
 * get_rfkill_device_by_index:
 
92
 **/
 
93
struct udev_device *
 
94
get_rfkill_device_by_index (struct udev *udev,
 
95
                            guint        index)
 
96
{
 
97
        struct udev_enumerate *enumerate;
 
98
        struct udev_list_entry *devices;
 
99
        struct udev_list_entry *dev_list_entry;
 
100
        struct udev_device *dev;
 
101
 
 
102
        enumerate = udev_enumerate_new(udev);
 
103
        udev_enumerate_add_match_subsystem(enumerate, "rfkill");
 
104
        udev_enumerate_scan_devices(enumerate);
 
105
        devices = udev_enumerate_get_list_entry(enumerate);
 
106
 
 
107
        udev_list_entry_foreach(dev_list_entry, devices) {
 
108
                const char *path, *index_c;
 
109
                path = udev_list_entry_get_name(dev_list_entry);
 
110
                dev = udev_device_new_from_syspath(udev, path);
 
111
 
 
112
                index_c = udev_device_get_sysattr_value (dev, "index");
 
113
                if (index_c && atoi(index_c) == index)
 
114
                        break;
 
115
 
 
116
                udev_device_unref (dev);
 
117
                dev = NULL;
 
118
        }
 
119
 
 
120
        return dev;
 
121
}
 
122
 
 
123
KillswitchState
 
124
event_to_state (gboolean soft,
 
125
                gboolean hard)
 
126
{
 
127
        if (hard)
 
128
                return KILLSWITCH_STATE_HARD_BLOCKED;
 
129
        else if (soft)
 
130
                return KILLSWITCH_STATE_SOFT_BLOCKED;
 
131
        else
 
132
                return KILLSWITCH_STATE_UNBLOCKED;
 
133
}
 
134
 
 
135
const char *
 
136
state_to_string (KillswitchState state)
 
137
{
 
138
        switch (state) {
 
139
        case KILLSWITCH_STATE_NO_ADAPTER:
 
140
                return "KILLSWITCH_STATE_NO_ADAPTER";
 
141
        case KILLSWITCH_STATE_SOFT_BLOCKED:
 
142
                return "KILLSWITCH_STATE_SOFT_BLOCKED";
 
143
        case KILLSWITCH_STATE_UNBLOCKED:
 
144
                return "KILLSWITCH_STATE_UNBLOCKED";
 
145
        case KILLSWITCH_STATE_HARD_BLOCKED:
 
146
                return "KILLSWITCH_STATE_HARD_BLOCKED";
 
147
        default:
 
148
                g_assert_not_reached ();
 
149
        }
 
150
}
 
151
 
 
152
const char *
 
153
type_to_string (guint type)
 
154
{
 
155
        switch (type) {
 
156
        case RFKILL_TYPE_ALL:
 
157
                return "ALL";
 
158
        case RFKILL_TYPE_WLAN:
 
159
                return "WLAN";
 
160
        case RFKILL_TYPE_BLUETOOTH:
 
161
                return "BLUETOOTH";
 
162
        case RFKILL_TYPE_UWB:
 
163
                return "UWB";
 
164
        case RFKILL_TYPE_WIMAX:
 
165
                return "WIMAX";
 
166
        case RFKILL_TYPE_WWAN:
 
167
                return "WWAN";
 
168
        case RFKILL_TYPE_GPS:
 
169
                return "GPS";
 
170
        case RFKILL_TYPE_FM:
 
171
                return "FM";
 
172
        default:
 
173
                g_assert_not_reached ();
 
174
        }
 
175
}