From: alok barsode <alokbarsode@gmail.com>
To: Marcel Holtmann <marcel@holtmann.org>
Cc: linux-bluetooth <linux-bluetooth@vger.kernel.org>
Subject: [PATCH][HCIRAW] Initial proposal for hciraw plugin.
Date: Wed, 22 Apr 2009 17:46:43 +0530 [thread overview]
Message-ID: <8b5debfa0904220516u591f1cb8v6b04650794f2d20b@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 162 bytes --]
Hi Marcel,
Here are the initial patches for hciraw plugin.
I have pulled the IO event stuff from main.c to hciraw.c
Let me know what you think.
Cheers,
Alok.
[-- Attachment #2: 0001-Initialing-HCI-raw-socket-plugin-hciraw.patch --]
[-- Type: text/x-diff, Size: 2699 bytes --]
From 68de541b4eb1b82fff8ffb4b6a4697fe01a537a1 Mon Sep 17 00:00:00 2001
From: Alok Barsode <alok.barsode@azingo.com>
Date: Tue, 21 Apr 2009 20:16:04 +0530
Subject: [PATCH 1/4] Initialing HCI raw socket plugin "hciraw".
---
plugins/Makefile.am | 6 +++++-
plugins/hciraw.c | 43 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 48 insertions(+), 1 deletions(-)
create mode 100644 plugins/hciraw.c
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index a1e933f..3cd1882 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -13,7 +13,7 @@ else
service_plugins =
endif
-plugin_LTLIBRARIES = hal.la $(netlink_plugins) $(service_plugins)
+plugin_LTLIBRARIES = hal.la hciraw.la $(netlink_plugins) $(service_plugins)
noinst_LTLIBRARIES = echo.la storage.la
@@ -21,6 +21,8 @@ echo_la_SOURCES = echo.c
storage_la_SOURCES = storage.c
+hciraw_la_SOURCES = hciraw.c
+
if NETLINK
netlink_la_SOURCES = netlink.c
@@ -47,6 +49,7 @@ all-local:
@$(LN_S) -f $(top_srcdir)/network/.libs/network.so
@$(LN_S) -f .libs/service.so
@$(LN_S) -f .libs/hal.so
+ @$(LN_S) -f .libs/hciraw.so
clean-local:
@rm -f hal.so
@@ -55,3 +58,4 @@ clean-local:
@rm -f serial.so
@rm -f audio.so
@rm -f input.so
+ @rm -f hciraw.so
diff --git a/plugins/hciraw.c b/plugins/hciraw.c
new file mode 100644
index 0000000..10bc8f5
--- /dev/null
+++ b/plugins/hciraw.c
@@ -0,0 +1,43 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2004-2009 Marcel Holtmann <marcel@holtmann.org>
+ * Copyright (C) 2009 Alok Barsode <alok.barsode@azingo.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <bluetooth/bluetooth.h>
+
+#include "plugin.h"
+#include "logging.h"
+
+static int hciraw_init(void)
+{
+ return 0;
+}
+
+static void hciraw_exit(void)
+{
+}
+
+BLUETOOTH_PLUGIN_DEFINE(hciraw, VERSION,
+ BLUETOOTH_PLUGIN_PRIORITY_DEFAULT, hciraw_init, hciraw_exit)
--
1.5.6.3
[-- Attachment #3: 0002-exporting-device_event.patch --]
[-- Type: text/x-diff, Size: 2412 bytes --]
From c66b005b15d9d86c363434d3d71f974d5e23e69f Mon Sep 17 00:00:00 2001
From: Alok Barsode <alok.barsode@azingo.com>
Date: Tue, 21 Apr 2009 21:58:07 +0530
Subject: [PATCH 2/4] exporting device_event().
---
src/hcid.h | 1 +
src/main.c | 28 ++++++++++++++--------------
2 files changed, 15 insertions(+), 14 deletions(-)
diff --git a/src/hcid.h b/src/hcid.h
index 6c26157..236449d 100644
--- a/src/hcid.h
+++ b/src/hcid.h
@@ -68,6 +68,7 @@ struct main_opts {
extern struct main_opts main_opts;
+void device_event(int event, int dev_id);
void hci_req_queue_remove(int dev_id, bdaddr_t *dba);
void start_security_manager(int hdev);
diff --git a/src/main.c b/src/main.c
index f39fc11..02b4ebf 100644
--- a/src/main.c
+++ b/src/main.c
@@ -556,30 +556,28 @@ static void init_defaults(void)
strcpy(main_opts.host_name, "noname");
}
-static inline void device_event(GIOChannel *chan, evt_stack_internal *si)
+void device_event(int event, int dev_id)
{
- evt_si_device *sd = (void *) &si->data;
-
- switch (sd->event) {
+ switch (event) {
case HCI_DEV_REG:
- info("HCI dev %d registered", sd->dev_id);
- device_devreg_setup(sd->dev_id, FALSE);
+ info("HCI dev %d registered", dev_id);
+ device_devreg_setup(dev_id, FALSE);
break;
case HCI_DEV_UNREG:
- info("HCI dev %d unregistered", sd->dev_id);
- manager_unregister_adapter(sd->dev_id);
+ info("HCI dev %d unregistered", dev_id);
+ manager_unregister_adapter(dev_id);
break;
case HCI_DEV_UP:
- info("HCI dev %d up", sd->dev_id);
- device_devup_setup(sd->dev_id);
+ info("HCI dev %d up", dev_id);
+ device_devup_setup(dev_id);
break;
case HCI_DEV_DOWN:
- info("HCI dev %d down", sd->dev_id);
- manager_stop_adapter(sd->dev_id);
- stop_security_manager(sd->dev_id);
+ info("HCI dev %d down", dev_id);
+ manager_stop_adapter(dev_id);
+ stop_security_manager(dev_id);
break;
}
}
@@ -589,6 +587,7 @@ static gboolean io_stack_event(GIOChannel *chan, GIOCondition cond,
{
unsigned char buf[HCI_MAX_FRAME_SIZE], *ptr;
evt_stack_internal *si;
+ evt_si_device *sd;
hci_event_hdr *eh;
int type;
size_t len;
@@ -620,7 +619,8 @@ static gboolean io_stack_event(GIOChannel *chan, GIOCondition cond,
si = (evt_stack_internal *) ptr;
switch (si->type) {
case EVT_SI_DEVICE:
- device_event(chan, si);
+ sd = (void *) &si->data;
+ device_event(sd->event, sd->dev_id);
break;
}
--
1.5.6.3
[-- Attachment #4: 0003-Using-device_event-to-register-and-setup-already-kno.patch --]
[-- Type: text/x-diff, Size: 880 bytes --]
From bf579f36ec4f0b9e718c7d73a410fbf73847c1e4 Mon Sep 17 00:00:00 2001
From: Alok Barsode <alok.barsode@azingo.com>
Date: Tue, 21 Apr 2009 22:02:16 +0530
Subject: [PATCH 3/4] Using device_event to register and setup already known devices.
---
src/main.c | 9 +++------
1 files changed, 3 insertions(+), 6 deletions(-)
diff --git a/src/main.c b/src/main.c
index 02b4ebf..a5885fe 100644
--- a/src/main.c
+++ b/src/main.c
@@ -529,13 +529,10 @@ static void init_all_devices(int ctl)
gboolean devup;
devup = hci_test_bit(HCI_UP, &dr->dev_opt);
+ if (!devup)
+ device_event(HCI_DEV_REG, dr->dev_id);
- info("HCI dev %d registered", dr->dev_id);
- device_devreg_setup(dr->dev_id, devup);
- if (devup) {
- info("HCI dev %d already up", dr->dev_id);
- device_devup_setup(dr->dev_id);
- }
+ device_event(HCI_DEV_UP, dr->dev_id);
}
g_free(dl);
--
1.5.6.3
[-- Attachment #5: 0004-Initializing-hci-raw-socket-plugin.-Adding-IO-event.patch --]
[-- Type: text/x-diff, Size: 7507 bytes --]
From 3c5cd8dcb39d16bc4c6292b55cbe5961e87c01e8 Mon Sep 17 00:00:00 2001
From: Alok Barsode <alok.barsode@azingo.com>
Date: Wed, 22 Apr 2009 16:34:09 +0530
Subject: [PATCH 4/4] Initializing hci raw socket plugin. Adding IO event handling.
---
plugins/hciraw.c | 135 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
src/main.c | 122 +------------------------------------------------
2 files changed, 135 insertions(+), 122 deletions(-)
diff --git a/plugins/hciraw.c b/plugins/hciraw.c
index 10bc8f5..d9d2856 100644
--- a/plugins/hciraw.c
+++ b/plugins/hciraw.c
@@ -24,17 +24,150 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#include <errno.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <sys/ioctl.h>
#include <bluetooth/bluetooth.h>
+#include <bluetooth/hci.h>
+#include <bluetooth/hci_lib.h>
+#include <glib.h>
+
+#include "hcid.h"
#include "plugin.h"
#include "logging.h"
-static int hciraw_init(void)
+
+static int init_all_devices(int ctl)
{
+ struct hci_dev_list_req *dl;
+ struct hci_dev_req *dr;
+ int i;
+
+ dl = g_try_malloc0(HCI_MAX_DEV * sizeof(struct hci_dev_req) + sizeof(uint16_t));
+ if (!dl) {
+ info("Can't allocate devlist buffer: %s (%d)",
+ strerror(errno), errno);
+ return errno;
+ }
+
+ dl->dev_num = HCI_MAX_DEV;
+ dr = dl->dev_req;
+
+ if (ioctl(ctl, HCIGETDEVLIST, (void *) dl) < 0) {
+ info("Can't get device list: %s (%d)",
+ strerror(errno), errno);
+ return errno;
+ }
+
+ for (i = 0; i < dl->dev_num; i++, dr++) {
+ gboolean devup;
+
+ devup = hci_test_bit(HCI_UP, &dr->dev_opt);
+
+ if (!devup)
+ device_event(HCI_DEV_REG, dr->dev_id);
+
+ device_event(HCI_DEV_UP, dr->dev_id);
+ }
+
+ g_free(dl);
return 0;
}
+static gboolean io_stack_event(GIOChannel *chan, GIOCondition cond,
+ gpointer data)
+{
+ unsigned char buf[HCI_MAX_FRAME_SIZE], *ptr;
+ evt_stack_internal *si;
+ evt_si_device *sd;
+ hci_event_hdr *eh;
+ int type;
+ size_t len;
+ GIOError err;
+
+ ptr = buf;
+
+ err = g_io_channel_read(chan, (gchar *) buf, sizeof(buf), &len);
+ if (err) {
+ if (err == G_IO_ERROR_AGAIN)
+ return TRUE;
+
+ error("Read from control socket failed: %s (%d)",
+ strerror(errno), errno);
+ return FALSE;
+ }
+
+ type = *ptr++;
+
+ if (type != HCI_EVENT_PKT)
+ return TRUE;
+
+ eh = (hci_event_hdr *) ptr;
+ if (eh->evt != EVT_STACK_INTERNAL)
+ return TRUE;
+
+ ptr += HCI_EVENT_HDR_SIZE;
+
+ si = (evt_stack_internal *) ptr;
+ switch (si->type) {
+ case EVT_SI_DEVICE:
+ sd = (void *) &si->data;
+ device_event(sd->event, sd->dev_id);
+ break;
+ }
+
+ return TRUE;
+}
+
+static int hciraw_init(void)
+{
+ struct sockaddr_hci addr;
+ struct hci_filter flt;
+ GIOChannel *ctl_io;
+ int sock;
+
+ /* Create and bind HCI socket */
+ sock = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
+ if (sock < 0) {
+ error("Can't open HCI socket: %s (%d)", strerror(errno),
+ errno);
+ return errno;
+ }
+
+ /* Set filter */
+ hci_filter_clear(&flt);
+ hci_filter_set_ptype(HCI_EVENT_PKT, &flt);
+ hci_filter_set_event(EVT_STACK_INTERNAL, &flt);
+ if (setsockopt(sock, SOL_HCI, HCI_FILTER, &flt,
+ sizeof(flt)) < 0) {
+ error("Can't set filter: %s (%d)", strerror(errno), errno);
+ return errno;
+ }
+
+ memset(&addr, 0, sizeof(addr));
+ addr.hci_family = AF_BLUETOOTH;
+ addr.hci_dev = HCI_DEV_NONE;
+ if (bind(sock, (struct sockaddr *) &addr,
+ sizeof(addr)) < 0) {
+ error("Can't bind HCI socket: %s (%d)",
+ strerror(errno), errno);
+ return errno;
+ }
+
+ ctl_io = g_io_channel_unix_new(sock);
+ g_io_channel_set_close_on_unref(ctl_io, TRUE);
+
+ g_io_add_watch(ctl_io, G_IO_IN, io_stack_event, NULL);
+
+ g_io_channel_unref(ctl_io);
+
+ /* Initialize already connected devices */
+ return init_all_devices(sock);
+}
+
static void hciraw_exit(void)
{
}
diff --git a/src/main.c b/src/main.c
index a5885fe..83e56cf 100644
--- a/src/main.c
+++ b/src/main.c
@@ -503,41 +503,6 @@ static void device_devup_setup(int dev_id)
stop_security_manager(dev_id);
}
-static void init_all_devices(int ctl)
-{
- struct hci_dev_list_req *dl;
- struct hci_dev_req *dr;
- int i;
-
- dl = g_try_malloc0(HCI_MAX_DEV * sizeof(struct hci_dev_req) + sizeof(uint16_t));
- if (!dl) {
- info("Can't allocate devlist buffer: %s (%d)",
- strerror(errno), errno);
- exit(1);
- }
-
- dl->dev_num = HCI_MAX_DEV;
- dr = dl->dev_req;
-
- if (ioctl(ctl, HCIGETDEVLIST, (void *) dl) < 0) {
- info("Can't get device list: %s (%d)",
- strerror(errno), errno);
- exit(1);
- }
-
- for (i = 0; i < dl->dev_num; i++, dr++) {
- gboolean devup;
-
- devup = hci_test_bit(HCI_UP, &dr->dev_opt);
- if (!devup)
- device_event(HCI_DEV_REG, dr->dev_id);
-
- device_event(HCI_DEV_UP, dr->dev_id);
- }
-
- g_free(dl);
-}
-
static void init_defaults(void)
{
/* Default HCId settings */
@@ -579,51 +544,6 @@ void device_event(int event, int dev_id)
}
}
-static gboolean io_stack_event(GIOChannel *chan, GIOCondition cond,
- gpointer data)
-{
- unsigned char buf[HCI_MAX_FRAME_SIZE], *ptr;
- evt_stack_internal *si;
- evt_si_device *sd;
- hci_event_hdr *eh;
- int type;
- size_t len;
- GIOError err;
-
- ptr = buf;
-
- err = g_io_channel_read(chan, (gchar *) buf, sizeof(buf), &len);
- if (err) {
- if (err == G_IO_ERROR_AGAIN)
- return TRUE;
-
- error("Read from control socket failed: %s (%d)",
- strerror(errno), errno);
- return FALSE;
- }
-
- type = *ptr++;
-
- if (type != HCI_EVENT_PKT)
- return TRUE;
-
- eh = (hci_event_hdr *) ptr;
- if (eh->evt != EVT_STACK_INTERNAL)
- return TRUE;
-
- ptr += HCI_EVENT_HDR_SIZE;
-
- si = (evt_stack_internal *) ptr;
- switch (si->type) {
- case EVT_SI_DEVICE:
- sd = (void *) &si->data;
- device_event(sd->event, sd->dev_id);
- break;
- }
-
- return TRUE;
-}
-
static GMainLoop *event_loop;
static void sig_term(int sig)
@@ -652,10 +572,8 @@ int main(int argc, char *argv[])
{
GOptionContext *context;
GError *err = NULL;
- struct sockaddr_hci addr;
- struct hci_filter flt;
struct sigaction sa;
- GIOChannel *ctl_io, *child_io;
+ GIOChannel *child_io;
uint16_t mtu = 0;
GKeyFile *config;
@@ -703,34 +621,6 @@ int main(int argc, char *argv[])
enable_debug();
}
- /* Create and bind HCI socket */
- main_opts.sock = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
- if (main_opts.sock < 0) {
- error("Can't open HCI socket: %s (%d)", strerror(errno),
- errno);
- exit(1);
- }
-
- /* Set filter */
- hci_filter_clear(&flt);
- hci_filter_set_ptype(HCI_EVENT_PKT, &flt);
- hci_filter_set_event(EVT_STACK_INTERNAL, &flt);
- if (setsockopt(main_opts.sock, SOL_HCI, HCI_FILTER, &flt,
- sizeof(flt)) < 0) {
- error("Can't set filter: %s (%d)", strerror(errno), errno);
- exit(1);
- }
-
- memset(&addr, 0, sizeof(addr));
- addr.hci_family = AF_BLUETOOTH;
- addr.hci_dev = HCI_DEV_NONE;
- if (bind(main_opts.sock, (struct sockaddr *) &addr,
- sizeof(addr)) < 0) {
- error("Can't bind HCI socket: %s (%d)",
- strerror(errno), errno);
- exit(1);
- }
-
config = load_config(CONFIGDIR "/main.conf");
parse_config(config);
@@ -765,16 +655,6 @@ int main(int argc, char *argv[])
event_loop = g_main_loop_new(NULL, FALSE);
- ctl_io = g_io_channel_unix_new(main_opts.sock);
- g_io_channel_set_close_on_unref(ctl_io, TRUE);
-
- g_io_add_watch(ctl_io, G_IO_IN, io_stack_event, NULL);
-
- g_io_channel_unref(ctl_io);
-
- /* Initialize already connected devices */
- init_all_devices(main_opts.sock);
-
starting = FALSE;
manager_startup_complete();
--
1.5.6.3
next reply other threads:[~2009-04-22 12:16 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-22 12:16 alok barsode [this message]
2009-04-22 19:22 ` [PATCH][HCIRAW] Initial proposal for hciraw plugin Luiz Augusto von Dentz
2009-04-23 12:09 ` alok barsode
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8b5debfa0904220516u591f1cb8v6b04650794f2d20b@mail.gmail.com \
--to=alokbarsode@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=marcel@holtmann.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox