[gnome-bluetooth] settings: Vendor from OUI helper function
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-bluetooth] settings: Vendor from OUI helper function
- Date: Mon, 9 Dec 2013 23:39:24 +0000 (UTC)
commit 49b84e8f5a4619788d85fef9b289154776ab6a29
Author: Bastien Nocera <hadess hadess net>
Date: Mon Dec 9 23:37:15 2013 +0100
settings: Vendor from OUI helper function
configure.ac | 2 +-
lib/pin.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
lib/pin.h | 1 +
3 files changed, 51 insertions(+), 1 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 708f966..219e670 100644
--- a/configure.ac
+++ b/configure.ac
@@ -88,7 +88,7 @@ dnl Requires for the input helper
PKG_CHECK_MODULES(INPUT, gdk-3.0 gtk+-3.0)
dnl Requires for the public library
-PKG_CHECK_MODULES(LIBGNOMEBT, gmodule-2.0 gio-unix-2.0 gtk+-3.0)
+PKG_CHECK_MODULES(LIBGNOMEBT, gmodule-2.0 gio-unix-2.0 gtk+-3.0 libudev)
GDBUS_CODEGEN="gdbus-codegen"
AC_SUBST(GDBUS_CODEGEN)
diff --git a/lib/pin.c b/lib/pin.c
index 390b497..74e6c87 100644
--- a/lib/pin.c
+++ b/lib/pin.c
@@ -28,6 +28,7 @@
#include <stdlib.h>
#include <string.h>
#include <glib.h>
+#include <libudev.h>
#include <bluetooth-enums.h>
#include <bluetooth-utils.h>
@@ -36,6 +37,54 @@
#define PIN_CODE_DB "pin-code-database.xml"
#define MAX_DIGITS_PIN_PREFIX "max:"
+char *
+oui_to_vendor (const char *oui)
+{
+ struct udev *udev;
+ struct udev_hwdb *hwdb;
+ struct udev_list_entry *list, *l;
+ char *modalias;
+ char *vendor = NULL;
+
+ if (oui == NULL ||
+ strlen (oui) < 8)
+ return NULL;
+
+ udev = udev_new ();
+ if (udev == NULL)
+ goto bail;
+
+ hwdb = udev_hwdb_new (udev);
+ if (hwdb == NULL)
+ goto bail;
+
+ modalias = g_strdup_printf ("OUI:%c%c%c%c%c%c",
+ g_ascii_toupper (oui[0]),
+ g_ascii_toupper (oui[1]),
+ g_ascii_toupper (oui[3]),
+ g_ascii_toupper (oui[4]),
+ g_ascii_toupper (oui[6]),
+ g_ascii_toupper (oui[7]));
+
+ list = udev_hwdb_get_properties_list_entry (hwdb, modalias, 0);
+
+ udev_list_entry_foreach (l, list) {
+ const char *name = udev_list_entry_get_name (l);
+
+ if (g_strcmp0 (name, "ID_OUI_FROM_DATABASE") == 0) {
+ vendor = g_strdup (udev_list_entry_get_value (l));
+ break;
+ }
+ }
+
+bail:
+ g_clear_pointer (&modalias, g_free);
+ g_clear_pointer (&hwdb, udev_hwdb_unref);
+ g_clear_pointer (&udev, udev_unref);
+
+ return vendor;
+}
+
#define TYPE_IS(x, r) { \
if (g_str_equal(type, x)) return r; \
}
diff --git a/lib/pin.h b/lib/pin.h
index 815969d..db7d323 100644
--- a/lib/pin.h
+++ b/lib/pin.h
@@ -25,6 +25,7 @@
#define PIN_NUM_DIGITS 6
+char *oui_to_vendor (const char *oui);
char *get_pincode_for_device (guint type,
const char *address,
const char *name,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]