3
* BlueZ - Bluetooth protocol stack for Linux
5
* Copyright (C) 2004-2008 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
29
#include <dbus/dbus.h>
31
#include <bluetooth/bluetooth.h>
32
#include <bluetooth/hci.h>
33
#include <bluetooth/hci_lib.h>
40
static void formfactor_reply(DBusPendingCall *call, void *user_data)
42
struct btd_adapter *adapter = user_data;
43
const char *formfactor = NULL;
45
uint8_t cls[3], minor = 0;
48
reply = dbus_pending_call_steal_reply(call);
50
if (dbus_set_error_from_message(NULL, reply) == TRUE) {
51
error("Failed to access HAL");
52
dbus_message_unref(reply);
56
if (dbus_message_get_args(reply, NULL, DBUS_TYPE_STRING, &formfactor,
57
DBUS_TYPE_INVALID) == FALSE) {
58
error("Wrong formfactor arguments");
59
dbus_message_unref(reply);
63
debug("Computer is classified as %s", formfactor);
65
if (formfactor != NULL) {
66
if (g_str_equal(formfactor, "laptop") == TRUE)
67
minor |= (1 << 2) | (1 << 3);
68
else if (g_str_equal(formfactor, "desktop") == TRUE)
70
else if (g_str_equal(formfactor, "server") == TRUE)
72
else if (g_str_equal(formfactor, "handheld") == TRUE)
76
dbus_message_unref(reply);
78
dd = hci_open_dev(adapter_get_dev_id(adapter));
82
if (hci_read_class_of_dev(dd, cls, 500) < 0) {
87
debug("Current device class is 0x%02x%02x%02x\n",
88
cls[2], cls[1], cls[0]);
90
/* Computer major class */
91
debug("Setting 0x%06x for major/minor device class", (1 << 8) | minor);
93
set_major_and_minor_class(dd, cls, 0x01, minor);
98
static DBusConnection *connection;
100
static int hal_probe(struct btd_adapter *adapter)
102
const char *property = "system.formfactor";
103
DBusMessage *message;
104
DBusPendingCall *call;
106
connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
107
if (connection == NULL)
110
message = dbus_message_new_method_call("org.freedesktop.Hal",
111
"/org/freedesktop/Hal/devices/computer",
112
"org.freedesktop.Hal.Device",
113
"GetPropertyString");
114
if (message == NULL) {
115
error("Failed to create formfactor request");
116
dbus_connection_unref(connection);
120
dbus_message_append_args(message, DBUS_TYPE_STRING, &property,
123
if (dbus_connection_send_with_reply(connection, message,
124
&call, -1) == FALSE) {
125
error("Failed to send formfactor request");
126
dbus_message_unref(message);
127
dbus_connection_unref(connection);
131
dbus_pending_call_set_notify(call, formfactor_reply, adapter, NULL);
133
dbus_pending_call_unref(call);
135
dbus_message_unref(message);
140
static void hal_remove(struct btd_adapter *adapter)
142
dbus_connection_unref(connection);
145
static struct btd_adapter_driver hal_driver = {
148
.remove = hal_remove,
151
static int hal_init(void)
153
return btd_register_adapter_driver(&hal_driver);
156
static void hal_exit(void)
158
btd_unregister_adapter_driver(&hal_driver);
161
BLUETOOTH_PLUGIN_DEFINE("hal", hal_init, hal_exit)