1
/***************************************************************************
4
* probe-net-bluetooth.c : Probe bluetooth network devices
6
* Copyright (C) 2007 Luiz Augusto von Dentz, <luiz.dentz@indt.org.br>
8
* Licensed under the Academic Free License version 2.1
10
* This program is free software; you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published by
12
* the Free Software Foundation; either version 2 of the License, or
13
* (at your option) any later version.
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU General Public License for more details.
20
* You should have received a copy of the GNU General Public License
21
* along with this program; if not, write to the Free Software
22
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
**************************************************************************/
32
#include "../../logger.h"
33
#include "libhal/libhal.h"
35
#define BLUEZ_SERVICE "org.bluez"
36
#define BLUEZ_PATH "/org/bluez"
37
#define BLUEZ_MANAGER_IFACE "org.bluez.Manager"
38
#define BLUEZ_NET_PATH "/org/bluez/network"
39
#define BLUEZ_NET_MANAGER_IFACE "org.bluez.network.Manager"
40
#define BLUEZ_NET_CONNECTION_IFACE "org.bluez.network.Connection"
41
#define BLUEZ_NET_SERVER_IFACE "org.bluez.network.Server"
44
get_properties (DBusConnection *conn, LibHalContext *ctx, const char *udi,
45
const char *id, const char *path)
48
DBusMessage *reply = NULL;
49
DBusMessageIter reply_iter;
50
DBusMessageIter dict_iter;
53
dbus_error_init (&error);
55
msg = dbus_message_new_method_call (id, path,
56
BLUEZ_NET_CONNECTION_IFACE,
62
HAL_INFO (("%s.GetInfo()", BLUEZ_NET_CONNECTION_IFACE));
63
reply = dbus_connection_send_with_reply_and_block (conn, msg, -1, &error);
65
if (dbus_error_is_set (&error) || dbus_set_error_from_message (&error,
67
dbus_error_free (&error);
71
dbus_message_iter_init (reply, &reply_iter);
73
if (dbus_message_iter_get_arg_type (&reply_iter) != DBUS_TYPE_ARRAY &&
74
dbus_message_iter_get_element_type (&reply_iter) != DBUS_TYPE_DICT_ENTRY) {
78
dbus_message_iter_recurse (&reply_iter, &dict_iter);
80
while (dbus_message_iter_get_arg_type (&dict_iter) == DBUS_TYPE_DICT_ENTRY) {
81
DBusMessageIter dict_entry_iter, var_iter;
85
dbus_message_iter_recurse (&dict_iter, &dict_entry_iter);
86
dbus_message_iter_get_basic (&dict_entry_iter, &key);
88
dbus_message_iter_next (&dict_entry_iter);
89
dbus_message_iter_recurse (&dict_entry_iter, &var_iter);
91
snprintf(prop, sizeof (prop), "net.bluetooth.%s", key);
93
/* Make any property found annouced by hal */
94
switch (dbus_message_iter_get_arg_type (&var_iter)) {
95
case DBUS_TYPE_STRING:
99
dbus_message_iter_get_basic (&var_iter, &value);
101
HAL_INFO (("reply: %s:%s", key, value));
103
libhal_device_set_property_string (ctx, udi, prop, value, &error);
106
case DBUS_TYPE_INT32:
110
dbus_message_iter_get_basic (&var_iter, &value);
112
HAL_INFO (("reply: %s:%d", key, value));
114
libhal_device_set_property_int (ctx, udi, prop, value, &error);
120
dbus_message_iter_next (&dict_iter);
125
dbus_message_unref (msg);
127
dbus_message_unref (reply);
132
main (int argc, char *argv[])
137
const char *connection;
138
char network[8] = "network";
139
const char *pnetwork = network;
140
LibHalContext *ctx = NULL;
141
DBusConnection *conn;
142
DBusMessage *msg = NULL;
143
DBusMessage *reply = NULL;
146
udi = getenv ("UDI");
150
dbus_error_init (&error);
151
if ((ctx = libhal_ctx_init_direct (&error)) == NULL)
154
iface = libhal_device_get_property_string (ctx, udi, "net.interface", NULL);
156
HAL_INFO (("Investigating '%s'", iface));
161
if ((conn = dbus_bus_get (DBUS_BUS_SYSTEM, &error)) == NULL)
164
msg = dbus_message_new_method_call (BLUEZ_SERVICE, BLUEZ_PATH, BLUEZ_MANAGER_IFACE, "ActivateService");
169
HAL_INFO (("%s.ActivateService('%s')", BLUEZ_MANAGER_IFACE, pnetwork));
170
dbus_message_append_args (msg, DBUS_TYPE_STRING, &pnetwork,
172
reply = dbus_connection_send_with_reply_and_block (conn, msg, -1, &error);
174
if (dbus_error_is_set (&error) || dbus_set_error_from_message (&error, reply)) {
175
dbus_error_free (&error);
179
dbus_message_unref (msg);
182
dbus_message_get_args (reply, &error, DBUS_TYPE_STRING, &id, DBUS_TYPE_INVALID);
183
if (dbus_error_is_set (&error)) {
184
dbus_error_free (&error);
188
dbus_message_unref (reply);
191
HAL_INFO (("Found Bluez Network service '%s'", id));
193
msg = dbus_message_new_method_call (id, BLUEZ_NET_PATH, BLUEZ_NET_MANAGER_IFACE, "FindConnection");
198
HAL_INFO (("%s.FindConnection('%s')", BLUEZ_NET_MANAGER_IFACE, iface));
199
dbus_message_append_args (msg, DBUS_TYPE_STRING, &iface,
201
reply = dbus_connection_send_with_reply_and_block (conn, msg, -1, &error);
203
if (dbus_error_is_set (&error) || dbus_set_error_from_message (&error,
205
dbus_error_free (&error);
209
dbus_message_unref (msg);
212
dbus_message_get_args (reply, &error, DBUS_TYPE_STRING, &connection,
214
if (dbus_error_is_set (&error)) {
215
dbus_error_free (&error);
219
get_properties (conn, ctx, udi, id, connection);
223
dbus_message_unref (msg);
225
dbus_message_unref (reply);
227
dbus_error_init (&error);
228
libhal_ctx_shutdown (ctx, &error);
229
libhal_ctx_free (ctx);