3
* BlueZ - Bluetooth protocol stack for Linux
5
* Copyright (C) 2004-2009 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
30
#include <netlink/netlink.h>
31
#include <netlink/genl/genl.h>
32
#include <netlink/genl/ctrl.h>
33
#include <netlink/genl/family.h>
35
#include <bluetooth/bluetooth.h>
42
static struct nl_handle *handle;
43
static struct nl_cache *cache;
44
static struct genl_family *family;
46
static GIOChannel *channel;
48
static gboolean channel_callback(GIOChannel *chan,
49
GIOCondition cond, void *user_data)
53
if (cond & (G_IO_ERR | G_IO_HUP | G_IO_NVAL))
56
debug("Message available on netlink channel");
58
err = nl_recvmsgs_default(handle);
63
static int create_channel(int fd)
65
channel = g_io_channel_unix_new(fd);
69
g_io_add_watch(channel, G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL,
70
channel_callback, NULL);
75
static int netlink_init(void)
77
info("Starting experimental netlink support");
79
handle = nl_handle_alloc();
81
error("Failed to allocate netlink handle");
85
if (genl_connect(handle) < 0) {
86
error("Failed to connect to generic netlink");
87
nl_handle_destroy(handle);
91
cache = genl_ctrl_alloc_cache(handle);
93
error("Failed to allocate generic netlink cache");
95
nl_handle_destroy(handle);
98
family = genl_ctrl_search_by_name(cache, "bluetooth");
100
error("Failed to find Bluetooth netlink family");
101
nl_cache_free(cache);
102
nl_handle_destroy(handle);
106
if (create_channel(nl_socket_get_fd(handle)) < 0) {
107
error("Failed to create netlink IO channel");
108
genl_family_put(family);
109
nl_cache_free(cache);
110
nl_handle_destroy(handle);
117
static void netlink_exit(void)
119
g_io_channel_unref(channel);
121
genl_family_put(family);
122
nl_cache_free(cache);
123
nl_handle_destroy(handle);
126
BLUETOOTH_PLUGIN_DEFINE("netlink", VERSION, netlink_init, netlink_exit)