summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Nocera <hadess@hadess.net>2013-12-09 23:37:15 +0100
committerBastien Nocera <hadess@hadess.net>2013-12-09 23:37:15 +0100
commit49b84e8f5a4619788d85fef9b289154776ab6a29 (patch)
treed405a244d75aa7a76b6b9b746886c47414e7cd47
parent90423abf17c0c590e6da78676fdedaa3aab3d1fa (diff)
downloadgnome-bluetooth-49b84e8f5a4619788d85fef9b289154776ab6a29.tar.gz
settings: Vendor from OUI helper function
-rw-r--r--configure.ac2
-rw-r--r--lib/pin.c49
-rw-r--r--lib/pin.h1
3 files changed, 51 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac
index 708f966e..219e6701 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 390b4971..74e6c87c 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 815969dd..db7d3234 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,