3 * BlueZ - Bluetooth protocol stack for Linux
5 * Copyright (C) 2004-2010 Marcel Holtmann <marcel@holtmann.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
31 #include <bluetooth/bluetooth.h>
37 #define DMI_CHASSIS_FILE "/sys/class/dmi/id/chassis_type"
38 #define DMI_CHASSIS_FILE_FALLBACK "/sys/devices/virtual/dmi/id/chassis_type"
40 /* Map the chassis type from chassis_type to a sensible type used in hal
42 * See also 3.3.4.1 of the "System Management BIOS Reference Specification,
43 * Version 2.6.1" (Preliminary Standard) document, available from
44 * http://www.dmtf.org/standards/smbios.
46 * TODO: figure out WTF the mapping should be; "Lunch Box"? Give me a break :-)
48 * Copied from hal/hald/linux/osspec.c
50 static const char *chassis_map[] = {
51 "Other", "unknown", /* 0x01 */
54 "Low Profile Desktop", "desktop",
55 "Pizza Box", "server",
56 "Mini Tower", "desktop",
61 "Hand Held", "handheld",
62 "Docking Station", "laptop",
63 "All In One", "unknown",
64 "Sub Notebook", "laptop",
65 "Space-saving", "desktop",
66 "Lunch Box", "unknown",
67 "Main Server Chassis", "server",
68 "Expansion Chassis", "unknown",
69 "Sub Chassis", "unknown",
70 "Bus Expansion Chassis", "unknown",
71 "Peripheral Chassis", "unknown",
72 "RAID Chassis", "unknown",
73 "Rack Mount Chassis", "unknown",
74 "Sealed-case PC", "unknown",
75 "Multi-system", "unknown",
76 "CompactPCI", "unknown",
77 "AdvancedTCA", "unknown",
79 "Blade Enclosure", "unknown", /* 0x1D */
83 static int formfactor_probe(struct btd_adapter *adapter)
87 const char *formfactor;
90 if (g_file_get_contents(DMI_CHASSIS_FILE,
91 &contents, NULL, NULL) == FALSE) {
92 if (g_file_get_contents(DMI_CHASSIS_FILE_FALLBACK,
93 &contents, NULL, NULL) == FALSE) {
94 error("Could not get the contents of DMI chassis type");
99 chassis_type = atoi(contents);
102 if (chassis_type > 0x1D || chassis_type <= 0) {
103 error ("Chassis type is not a known chassis type");
107 formfactor = chassis_map[chassis_type * 2 - 1];
108 if (formfactor != NULL) {
109 if (g_str_equal(formfactor, "laptop") == TRUE)
110 minor |= (1 << 2) | (1 << 3);
111 else if (g_str_equal(formfactor, "desktop") == TRUE)
113 else if (g_str_equal(formfactor, "server") == TRUE)
115 else if (g_str_equal(formfactor, "handheld") == TRUE)
119 /* Computer major class */
120 DBG("Setting 0x%06x for major/minor device class", (1 << 8) | minor);
122 btd_adapter_set_class(adapter, 0x01, minor);
127 static void formfactor_remove(struct btd_adapter *adapter)
131 static struct btd_adapter_driver formfactor_driver = {
132 .name = "formfactor",
133 .probe = formfactor_probe,
134 .remove = formfactor_remove,
137 static int formfactor_init(void)
139 return btd_register_adapter_driver(&formfactor_driver);
142 static void formfactor_exit(void)
144 btd_unregister_adapter_driver(&formfactor_driver);
147 BLUETOOTH_PLUGIN_DEFINE(formfactor, VERSION,
148 BLUETOOTH_PLUGIN_PRIORITY_LOW, formfactor_init, formfactor_exit)