From d523d8e46d1dd3b138c886b36d452cbb901e6562 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 29 Dec 2012 15:56:15 -0800 Subject: [PATCH] hostname: Add fallback to DMI information for class of device --- plugins/hostname.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/plugins/hostname.c b/plugins/hostname.c index d4307bc32..731b3e7a2 100644 --- a/plugins/hostname.c +++ b/plugins/hostname.c @@ -27,6 +27,7 @@ #include #include +#include #include #include "dbus-common.h" @@ -176,6 +177,60 @@ static struct btd_adapter_driver hostname_driver = { .remove = hostname_remove, }; +static void read_dmi_fallback(void) +{ + char *contents; + int i, type; + const char *str; + + if (g_file_get_contents("/sys/class/dmi/id/chassis_type", + &contents, NULL, NULL) == FALSE) + return; + + type = atoi(contents); + if (type < 0 || type > 0x1D) + return; + + g_free(contents); + + /* from systemd hostname chassis list */ + switch (type) { + case 0x3: + case 0x4: + case 0x6: + case 0x7: + str = "desktop"; + break; + case 0x8: + case 0x9: + case 0xA: + case 0xE: + str = "laptop"; + break; + case 0xB: + str = "handset"; + break; + case 0x11: + case 0x1C: + str = "server"; + break; + default: + return; + } + + DBG("chassis: %s", str); + + for (i = 0; chassis_table[i].chassis; i++) { + if (!strcmp(chassis_table[i].chassis, str)) { + major_class = chassis_table[i].major_class; + minor_class = chassis_table[i].minor_class; + break; + } + } + + DBG("major: 0x%02x minor: 0x%02x", major_class, minor_class); +} + static GDBusClient *hostname_client = NULL; static GDBusProxy *hostname_proxy = NULL; @@ -184,6 +239,8 @@ static int hostname_init(void) DBusConnection *conn = btd_get_dbus_connection(); int err; + read_dmi_fallback(); + hostname_client = g_dbus_client_new(conn, "org.freedesktop.hostname1", "/org/freedesktop/hostname1"); if (!hostname_client) -- 2.47.3