From: Denis KENZIOR <denis.kenzior@trolltech.com>
To: BlueZ development <bluez-devel@lists.sourceforge.net>
Subject: [Bluez-devel] [PATCH] FindAdapter try #2
Date: Wed, 3 Oct 2007 10:19:06 +1000 [thread overview]
Message-ID: <200710031019.06334.denis.kenzior@trolltech.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 58 bytes --]
Marcel,
Should be code standard compliant now ;)
-Denis
[-- Attachment #2: find_adapter.patch --]
[-- Type: text/x-diff, Size: 1898 bytes --]
Index: manager.c
===================================================================
RCS file: /cvsroot/bluez/utils/hcid/manager.c,v
retrieving revision 1.6
diff -u -5 -r1.6 manager.c
--- manager.c 26 Sep 2007 13:56:30 -0000 1.6
+++ manager.c 3 Oct 2007 00:16:30 -0000
@@ -99,10 +99,54 @@
DBUS_TYPE_INVALID);
return send_message_and_unref(conn, reply);
}
+static int find_by_address(const char *str)
+{
+ struct hci_dev_list_req *dl;
+ struct hci_dev_req *dr;
+ bdaddr_t ba;
+ int i, sk;
+ int devid = -1;
+
+ sk = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
+ if (sk < 0)
+ return -1;
+
+ dl = g_malloc0(HCI_MAX_DEV * sizeof(*dr) + sizeof(*dl));
+
+ dl->dev_num = HCI_MAX_DEV;
+ dr = dl->dev_req;
+
+ if (ioctl(sk, HCIGETDEVLIST, dl) < 0)
+ goto out;
+
+ dr = dl->dev_req;
+ str2ba(str, &ba);
+
+ for (i = 0; i < dl->dev_num; i++, dr++) {
+ struct hci_dev_info di;
+
+ if (hci_devinfo(dr->dev_id, &di) < 0)
+ continue;
+
+ if (hci_test_bit(HCI_RAW, &di.flags))
+ continue;
+
+ if (!bacmp(&ba, &di.bdaddr)) {
+ devid = dr->dev_id;
+ break;
+ }
+ }
+
+out:
+ g_free(dl);
+ close(sk);
+ return devid;
+}
+
static DBusHandlerResult find_adapter(DBusConnection *conn,
DBusMessage *msg, void *data)
{
DBusMessage *reply;
char path[MAX_PATH_LENGTH], *path_ptr = path;
@@ -113,11 +157,18 @@
if (!dbus_message_get_args(msg, NULL,
DBUS_TYPE_STRING, &pattern,
DBUS_TYPE_INVALID))
return error_invalid_arguments(conn, msg);
- dev_id = hci_devid(pattern);
+ /* hci_devid() would make sense to use here, except it
+ is restricted to devices which are up */
+ if (!strncmp(pattern, "hci", 3) && strlen(pattern) >= 4) {
+ dev_id = atoi(pattern + 3);
+ } else {
+ dev_id = find_by_address(pattern);
+ }
+
if (dev_id < 0)
return error_no_such_adapter(conn, msg);
if (hci_devinfo(dev_id, &di) < 0)
return error_no_such_adapter(conn, msg);
[-- Attachment #3: Type: text/plain, Size: 228 bytes --]
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
[-- Attachment #4: Type: text/plain, Size: 164 bytes --]
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
next reply other threads:[~2007-10-03 0:19 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-10-03 0:19 Denis KENZIOR [this message]
2007-10-03 12:29 ` [Bluez-devel] [PATCH] FindAdapter try #2 Johan Hedberg
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=200710031019.06334.denis.kenzior@trolltech.com \
--to=denis.kenzior@trolltech.com \
--cc=bluez-devel@lists.sourceforge.net \
/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