400
addr_entry = hal_util_get_string_from_file (sysfs_path, "address");
401
if (addr_entry == NULL)
404
if (sscanf (addr_entry, "%x:%x:%x:%x:%x:%x", &a5, &a4, &a3, &a2, &a1, &a0) != 6) {
407
address = ((dbus_uint64_t)a5<<40) |
408
((dbus_uint64_t)a4<<32) |
409
((dbus_uint64_t)a3<<24) |
410
((dbus_uint64_t)a2<<16) |
411
((dbus_uint64_t)a1<< 8) |
412
((dbus_uint64_t)a0<< 0);
414
type_entry = hal_util_get_string_from_file (sysfs_path, "type");
415
if (type_entry == NULL)
324
418
d = hal_device_new ();
325
419
hal_device_property_set_string (d, "linux.sysfs_path", sysfs_path);
326
420
hal_device_property_set_string (d, "info.parent", hal_device_get_udi (parent_dev));
328
hal_device_property_set_string (d, "info.category", "bluetooth_hci");
329
hal_device_add_capability (d, "bluetooth_hci");
331
hal_device_property_set_string (d, "bluetooth_hci.originating_device", hal_device_get_udi (parent_dev));
332
hal_device_property_set_string (d, "bluetooth_hci.physical_device", hal_device_get_udi (parent_dev));
333
hal_util_set_string_from_file (d, "bluetooth_hci.interface_name", sysfs_path, "name");
335
hal_device_property_set_string (d, "info.product", "Bluetooth Host Controller Interface");
422
if (strcmp (type_entry, "ACL") == 0) {
423
hal_device_property_set_string (d, "info.category", "bluetooth_acl");
424
hal_device_add_capability (d, "bluetooth_acl");
425
hal_device_property_set_uint64 (d, "bluetooth_acl.address", address);
426
hal_device_property_set_string (d, "info.product", "Bluetooth Asynchronous Connection-oriented Link");
427
hal_device_property_set_string (d, "bluetooth_acl.originating_device", hal_device_get_udi (parent_dev));
429
} else if (strcmp (type_entry, "SCO") == 0) {
430
hal_device_property_set_string (d, "info.category", "bluetooth_sco");
431
hal_device_add_capability (d, "bluetooth_sco");
432
hal_device_property_set_uint64 (d, "bluetooth_sco.address", address);
433
hal_device_property_set_string (d, "info.product", "Bluetooth Synchronous Connection-oriented Link");
434
hal_device_property_set_string (d, "bluetooth_sco.originating_device", hal_device_get_udi (parent_dev));
436
hal_device_property_set_string (d, "info.category", "bluetooth_hci");
437
hal_device_add_capability (d, "bluetooth_hci");
438
hal_device_property_set_string (d, "info.product", "Bluetooth Host Controller Interface");
439
hal_device_property_set_string (d, "bluetooth_hci.originating_device", hal_device_get_udi (parent_dev));
440
hal_device_property_set_uint64 (d, "bluetooth_hci.address", address);
395
512
media_type = hal_device_property_get_int (d, "net.arp_proto_hw_id");
396
513
if (media_type == ARPHRD_ETHER) {
397
514
const char *addr;
515
const char *parent_subsys;
398
516
char wireless_path[HAL_PATH_MAX];
399
517
char wiphy_path[HAL_PATH_MAX];
400
gboolean is_wireless;
519
dbus_uint64_t mac_address = 0;
521
addr = hal_device_property_get_string (d, "net.address");
523
unsigned int a5, a4, a3, a2, a1, a0;
525
if (sscanf (addr, "%x:%x:%x:%x:%x:%x",
526
&a5, &a4, &a3, &a2, &a1, &a0) == 6) {
528
((dbus_uint64_t)a5<<40) |
529
((dbus_uint64_t)a4<<32) |
530
((dbus_uint64_t)a3<<24) |
531
((dbus_uint64_t)a2<<16) |
532
((dbus_uint64_t)a1<< 8) |
533
((dbus_uint64_t)a0<< 0);
403
537
snprintf (wireless_path, HAL_PATH_MAX, "%s/wireless", sysfs_path);
404
538
/* wireless dscape stack e.g. from rt2500pci driver*/
405
539
snprintf (wiphy_path, HAL_PATH_MAX, "%s/wiphy", sysfs_path);
540
parent_subsys = hal_device_property_get_string (parent_dev, "linux.subsystem");
407
if ((stat (wireless_path, &s) == 0 && (s.st_mode & S_IFDIR)) ||
408
(stat (wiphy_path, &s) == 0 && (s.st_mode & S_IFDIR))) {
542
if (parent_subsys && strcmp(parent_subsys, "bluetooth") == 0) {
543
hal_device_property_set_string (d, "info.product", "Bluetooth Interface");
544
hal_device_property_set_string (d, "info.category", "net.bluetooth");
545
hal_device_add_capability (d, "net.bluetooth");
546
hal_device_property_set_uint64 (d, "net.bluetooth.mac_address", mac_address);
547
} else if ((stat (wireless_path, &s) == 0 && (s.st_mode & S_IFDIR)) ||
548
(stat (wiphy_path, &s) == 0 && (s.st_mode & S_IFDIR))) {
409
549
hal_device_property_set_string (d, "info.product", "WLAN Interface");
410
550
hal_device_property_set_string (d, "info.category", "net.80211");
411
551
hal_device_add_capability (d, "net.80211");
552
hal_device_property_set_uint64 (d, "net.80211.mac_address", mac_address);
414
554
hal_device_property_set_string (d, "info.product", "Networking Interface");
415
555
hal_device_property_set_string (d, "info.category", "net.80203");
416
556
hal_device_add_capability (d, "net.80203");
420
addr = hal_device_property_get_string (d, "net.address");
422
unsigned int a5, a4, a3, a2, a1, a0;
424
if (sscanf (addr, "%x:%x:%x:%x:%x:%x",
425
&a5, &a4, &a3, &a2, &a1, &a0) == 6) {
426
dbus_uint64_t mac_address;
429
((dbus_uint64_t)a5<<40) |
430
((dbus_uint64_t)a4<<32) |
431
((dbus_uint64_t)a3<<24) |
432
((dbus_uint64_t)a2<<16) |
433
((dbus_uint64_t)a1<< 8) |
434
((dbus_uint64_t)a0<< 0);
436
hal_device_property_set_uint64 (d, is_wireless ? "net.80211.mac_address" :
437
"net.80203.mac_address",
557
hal_device_property_set_uint64 (d, "net.80203.mac_address", mac_address);
441
559
} else if (media_type == ARPHRD_IRDA) {
442
560
hal_device_property_set_string (d, "info.product", "Networking Interface");
2783
2953
static gboolean
2954
power_supply_compute_udi (HalDevice *d)
2960
dir = hal_device_property_get_string (d, "linux.sysfs_path");
2962
name = hal_util_get_last_element(dir);
2963
hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
2965
hal_device_property_get_string (d, "info.parent"));
2966
hal_device_set_udi (d, udi);
2967
hal_device_property_set_string (d, "info.udi", udi);
2972
refresh_ac_adapter (HalDevice *d)
2975
gboolean present = FALSE;
2977
path = hal_device_property_get_string (d, "linux.sysfs_path");
2981
if (hal_util_get_bool_from_file (path, "online", &present, "1") == FALSE) {
2982
/* if we can't read the property, assume on ac */
2986
hal_device_property_set_bool (d, "ac_adapter.present", present);
2990
refresh_battery_fast (HalDevice *d)
2992
gint percentage = 0;
2993
gint voltage_now = 0;
2994
gint voltage_design = 0;
2998
gint value_last_full = 0;
2999
gint value_full_design = 0;
3000
gboolean present = FALSE;
3001
gboolean could_be_mah = TRUE;
3002
gboolean could_be_mwh = TRUE;
3003
gboolean is_mah = FALSE;
3004
gboolean is_mwh = FALSE;
3005
gboolean is_charging = FALSE;
3006
gboolean is_discharging = FALSE;
3007
gboolean got_time = FALSE;
3008
gboolean got_percentage = FALSE;
3010
const gchar *reporting_unit;
3013
path = hal_device_property_get_string (d, "linux.sysfs_path");
3018
if (hal_util_get_bool_from_file (path, "present", &present, "1")) {
3019
hal_device_property_set_bool (d, "battery.present", present);
3021
if (present == FALSE) {
3022
/* remove all the optional keys associated with the cell */
3023
device_pm_remove_optional_props (d);
3028
if (hal_util_get_int_from_file (path, "capacity", &percentage, 10)) {
3030
if (percentage >= 0 && percentage <= 100)
3031
got_percentage = TRUE;
3034
/* VOLTAGE: we prefer the average if it exists, although present is still pretty good */
3035
if (hal_util_get_int_from_file (path, "voltage_avg", &voltage_now, 10)) {
3036
hal_device_property_set_int (d, "battery.voltage.current", voltage_now / 1000);
3037
} else if (hal_util_get_int_from_file (path, "voltage_now", &voltage_now, 10)) {
3038
hal_device_property_set_int (d, "battery.voltage.current", voltage_now / 1000);
3040
if (hal_util_get_int_from_file (path, "voltage_max_design", &voltage_design, 10)) {
3041
hal_device_property_set_int (d, "battery.voltage.design", voltage_design / 1000);
3044
/* CURRENT: we prefer the average if it exists, although present is still pretty good */
3045
if (hal_util_get_int_from_file (path, "current_avg", ¤t, 10)) {
3046
hal_device_property_set_int (d, "battery.current", current / 1000);
3047
} else if (hal_util_get_int_from_file (path, "current_now", ¤t, 10)) {
3048
hal_device_property_set_int (d, "battery.current", current / 1000);
3051
/* STATUS: Convert to charging/discharging state */
3052
status = hal_util_get_string_from_file (path, "status");
3053
if (status != NULL) {
3054
if (strcasecmp (status, "charging") == 0) {
3056
} else if (strcasecmp (status, "discharging") == 0) {
3057
is_discharging = TRUE;
3059
hal_device_property_set_bool (d, "battery.rechargeable.is_charging", is_charging);
3060
hal_device_property_set_bool (d, "battery.rechargeable.is_discharging", is_discharging);
3063
/* TIME: Some batteries only provide time to discharge */
3064
if (is_charging == TRUE) {
3065
if (hal_util_get_int_from_file (path, "time_to_full_avg", &time, 10) ||
3066
hal_util_get_int_from_file (path, "time_to_full_now", &time, 10)) {
3069
} else if (is_discharging == TRUE) {
3070
if (hal_util_get_int_from_file (path, "time_to_empty_avg", &time, 10) ||
3071
hal_util_get_int_from_file (path, "time_to_empty_now", &time, 10)) {
3076
/* Have we already got information about the reporting unit?
3077
* If we have, we can save a lots of file reads */
3078
reporting_unit = hal_device_property_get_string (d, "battery.reporting.unit");
3079
if (reporting_unit != NULL) {
3080
if (strcasecmp (reporting_unit, "mah") == 0) {
3081
could_be_mwh = FALSE;
3082
} else if (strcasecmp (reporting_unit, "mwh") == 0) {
3083
could_be_mah = FALSE;
3087
/* ENERGY (reported in uWh, so need to convert to mWh) */
3089
if (hal_util_get_int_from_file (path, "energy_avg", &value_now, 10)) {
3090
hal_device_property_set_int (d, "battery.reporting.current", value_now / 1000);
3092
} else if (hal_util_get_int_from_file (path, "energy_now", &value_now, 10)) {
3093
hal_device_property_set_int (d, "battery.reporting.current", value_now / 1000);
3096
if (hal_util_get_int_from_file (path, "energy_full", &value_last_full, 10)) {
3097
hal_device_property_set_int (d, "battery.reporting.last_full", value_last_full / 1000);
3100
if (hal_util_get_int_from_file (path, "energy_full_design", &value_full_design, 10)) {
3101
hal_device_property_set_int (d, "battery.reporting.design", value_full_design / 1000);
3106
/* CHARGE (reported in uAh, so need to convert to mAh) */
3108
if (hal_util_get_int_from_file (path, "charge_avg", &value_now, 10)) {
3109
hal_device_property_set_int (d, "battery.reporting.current", value_now / 1000);
3111
} else if (hal_util_get_int_from_file (path, "charge_now", &value_now, 10)) {
3112
hal_device_property_set_int (d, "battery.reporting.current", value_now / 1000);
3115
if (hal_util_get_int_from_file (path, "charge_full", &value_last_full, 10)) {
3116
hal_device_property_set_int (d, "battery.reporting.last_full", value_last_full / 1000);
3119
if (hal_util_get_int_from_file (path, "charge_full_design", &value_full_design, 10)) {
3120
hal_device_property_set_int (d, "battery.reporting.design", value_full_design / 1000);
3125
/* record these for future savings */
3126
if (is_mwh == TRUE) {
3127
hal_device_property_set_string (d, "battery.reporting.unit", "mWh");
3128
} else if (is_mah == TRUE) {
3129
hal_device_property_set_string (d, "battery.reporting.unit", "mAh");
3132
/* we've now got the 'reporting' keys, now we need to populate the
3133
* processed 'charge_level' keys so stuff like desktop power managers
3134
* do not have to deal with odd quirks */
3135
device_pm_abstract_props (d);
3137
/* if we have not read from the hardware, then calculate */
3138
if (got_percentage) {
3139
hal_device_property_set_int (d, "battery.charge_level.percentage", percentage);
3141
device_pm_calculate_percentage (d);
3144
/* if we havn't got time from the hardware, then try to calculate it */
3146
/* zero time isn't displayed */
3148
hal_device_property_set_int (d, "battery.remaining_time", time);
3150
hal_device_property_remove (d, "battery.remaining_time");
3152
device_pm_calculate_time (d);
3157
refresh_battery_slow (HalDevice *d)
3159
const char *technology;
3160
char *technology_raw;
3165
path = hal_device_property_get_string (d, "linux.sysfs_path");
3169
/* get battery technology */
3170
technology_raw = hal_util_get_string_from_file (path, "technology");
3171
if (technology_raw != NULL) {
3172
hal_device_property_set_string (d, "battery.reporting.technology", technology_raw);
3174
/* we set this, even if it's unknown */
3175
technology = util_get_battery_technology (technology_raw);
3176
hal_device_property_set_string (d, "battery.technology", technology);
3178
/* get product name */
3179
model_name = hal_util_get_string_from_file (path, "technology");
3180
if (model_name != NULL) {
3181
hal_device_property_set_string (d, "info.product", model_name);
3183
hal_device_property_set_string (d, "info.product", "Generic Battery Device");
3186
/* get manufacturer */
3187
manufacturer = hal_util_get_string_from_file (path, "manufacturer");
3188
if (manufacturer != NULL) {
3189
hal_device_property_set_string (d, "battery.vendor", manufacturer);
3192
/* now do stuff that happens quickly */
3193
refresh_battery_fast (d);
3197
power_supply_refresh (HalDevice *d)
3200
type = hal_device_property_get_string (d, "info.category");
3204
if (strcmp (type, "ac_adapter") == 0) {
3205
device_property_atomic_update_begin ();
3206
refresh_ac_adapter (d);
3207
device_property_atomic_update_end ();
3208
} else if (strcmp (type, "battery") == 0) {
3209
device_property_atomic_update_begin ();
3210
refresh_battery_slow (d);
3211
device_property_atomic_update_end ();
3213
HAL_WARNING (("Could not recognise power_supply type!"));
3220
power_supply_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *physdev,
3221
const gchar *sysfs_path_in_devices)
3223
HalDevice *d = NULL;
3224
gboolean is_battery = FALSE;
3225
gboolean is_ac_adapter = FALSE;
3227
const char *battery_type = NULL;
3229
/* power_supply devices are very odd, they might be batteries or ac-adapters */
3230
type = hal_util_get_string_from_file (sysfs_path, "type");
3232
/* we don't need to free */
3235
if (strcasecmp (type, "battery") == 0) {
3237
battery_type = "primary";
3238
} else if (strcasecmp (type, "ups") == 0) {
3240
battery_type = "ups";
3241
} else if (strcasecmp (type, "usb") == 0) {
3243
battery_type = "usb";
3244
} else if (strcasecmp (type, "mains") == 0) {
3245
is_ac_adapter = TRUE;
3247
HAL_WARNING (("Power supply is neither ac_adapter or battery!"));
3251
d = hal_device_new ();
3252
hal_device_property_set_string (d, "linux.sysfs_path", sysfs_path);
3253
hal_device_property_set_string (d, "info.parent", "/org/freedesktop/Hal/devices/computer");
3255
if (is_battery == TRUE) {
3256
hal_device_property_set_string (d, "info.category", "battery");
3257
if (battery_type != NULL)
3258
hal_device_property_set_string (d, "battery.type", battery_type);
3259
refresh_battery_slow (d);
3260
hal_device_add_capability (d, "battery");
3263
if (is_ac_adapter == TRUE) {
3264
hal_device_property_set_string (d, "info.category", "ac_adapter");
3265
hal_device_property_set_string (d, "info.product", "Generic AC Adapter Device");
3266
refresh_ac_adapter (d);
3267
hal_device_add_capability (d, "ac_adapter");
2784
3274
backlight_compute_udi (HalDevice *d)
2786
3276
gchar udi[256];