aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChen Ganir <chen.ganir@ti.com>2012-03-11 14:06:42 +0200
committerJoão Paulo Rechi Vita <jprvita@openbossa.org>2012-06-21 18:00:18 -0300
commit02e88080046a875510761a23f6d2be8e5db80b29 (patch)
treef8bf71dbd1a0ebcd33bc7ceb2392a44728e7c08a
parentfa96b43a8023c0506844d7bd2f815640942fa076 (diff)
downloadbluez-02e88080046a875510761a23f6d2be8e5db80b29.tar.gz
bluez-02e88080046a875510761a23f6d2be8e5db80b29.tar.xz
bluez-02e88080046a875510761a23f6d2be8e5db80b29.zip
battery: Add Battery Service GATT Client
Add support for the Battery Service Gatt Client side.
-rw-r--r--Makefile.am7
-rw-r--r--batterystate/batterystate.c88
-rw-r--r--batterystate/batterystate.h24
-rw-r--r--batterystate/main.c53
-rw-r--r--batterystate/manager.c62
-rw-r--r--batterystate/manager.h24
6 files changed, 256 insertions, 2 deletions
diff --git a/Makefile.am b/Makefile.am
index 1e7e855c..a7a0061e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -225,7 +225,7 @@ endif
if GATTMODULES
builtin_modules += thermometer alert time gatt_example proximity \
- deviceinfo scanparam
+ deviceinfo scanparam batterystate
builtin_sources += thermometer/main.c \
thermometer/manager.h thermometer/manager.c \
thermometer/thermometer.h thermometer/thermometer.c \
@@ -241,7 +241,10 @@ builtin_sources += thermometer/main.c \
deviceinfo/manager.h deviceinfo/manager.c \
deviceinfo/deviceinfo.h deviceinfo/deviceinfo.c \
scanparam/main.c scanparam/manager.h scanparam/manager.c \
- scanparam/scan.h scanparam/scan.c
+ scanparam/scan.h scanparam/scan.c \
+ batterystate/main.c \
+ batterystate/manager.h batterystate/manager.c \
+ batterystate/batterystate.h batterystate/batterystate.c
endif
diff --git a/batterystate/batterystate.c b/batterystate/batterystate.c
new file mode 100644
index 00000000..6db593ef
--- /dev/null
+++ b/batterystate/batterystate.c
@@ -0,0 +1,88 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2012 Texas Instruments, Inc.
+ *
+ * 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 <glib.h>
+#include <bluetooth/uuid.h>
+
+#include "adapter.h"
+#include "device.h"
+#include "att.h"
+#include "gattrib.h"
+#include "gatt.h"
+#include "batterystate.h"
+
+struct battery {
+ struct btd_device *dev; /* Device reference */
+};
+
+static GSList *servers = NULL;
+
+static gint cmp_device(gconstpointer a, gconstpointer b)
+{
+ const struct battery *batt = a;
+ const struct btd_device *dev = b;
+
+ if (dev == batt->dev)
+ return 0;
+
+ return -1;
+}
+
+static void batterystate_free(gpointer user_data)
+{
+ struct battery *batt = user_data;
+
+ btd_device_unref(batt->dev);
+ g_free(batt);
+}
+
+
+int batterystate_register(struct btd_device *device)
+{
+ struct battery *batt;
+
+ batt = g_new0(struct battery, 1);
+ batt->dev = btd_device_ref(device);
+
+ servers = g_slist_prepend(servers, batt);
+
+ return 0;
+}
+
+void batterystate_unregister(struct btd_device *device)
+{
+ struct battery *batt;
+ GSList *l;
+
+ l = g_slist_find_custom(servers, device, cmp_device);
+ if (l == NULL)
+ return;
+
+ batt = l->data;
+ servers = g_slist_remove(servers, batt);
+
+ batterystate_free(batt);
+}
diff --git a/batterystate/batterystate.h b/batterystate/batterystate.h
new file mode 100644
index 00000000..9aedae7a
--- /dev/null
+++ b/batterystate/batterystate.h
@@ -0,0 +1,24 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2012 Texas Instruments, Inc.
+ *
+ * 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
+ *
+ */
+
+int batterystate_register(struct btd_device *device);
+void batterystate_unregister(struct btd_device *device);
diff --git a/batterystate/main.c b/batterystate/main.c
new file mode 100644
index 00000000..360254b0
--- /dev/null
+++ b/batterystate/main.c
@@ -0,0 +1,53 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2012 Texas Instruments, Inc.
+ *
+ * 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 <stdint.h>
+#include <glib.h>
+#include <errno.h>
+
+#include "hcid.h"
+#include "plugin.h"
+#include "manager.h"
+#include "log.h"
+
+static int batterystate_init(void)
+{
+ if (!main_opts.gatt_enabled) {
+ DBG("GATT is disabled");
+ return -ENOTSUP;
+ }
+
+ return batterystate_manager_init();
+}
+
+static void batterystate_exit(void)
+{
+ batterystate_manager_exit();
+}
+
+BLUETOOTH_PLUGIN_DEFINE(batterystate, VERSION,
+ BLUETOOTH_PLUGIN_PRIORITY_DEFAULT, batterystate_init,
+ batterystate_exit)
diff --git a/batterystate/manager.c b/batterystate/manager.c
new file mode 100644
index 00000000..6718acfa
--- /dev/null
+++ b/batterystate/manager.c
@@ -0,0 +1,62 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2012 Texas Instruments, Inc.
+ *
+ * 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
+ *
+ */
+
+#include <glib.h>
+#include <errno.h>
+#include <bluetooth/uuid.h>
+
+#include "adapter.h"
+#include "device.h"
+#include "att.h"
+#include "gattrib.h"
+#include "gatt.h"
+#include "batterystate.h"
+#include "manager.h"
+
+#define BATTERY_SERVICE_UUID "0000180f-0000-1000-8000-00805f9b34fb"
+
+static int batterystate_driver_probe(struct btd_device *device, GSList *uuids)
+{
+ return batterystate_register(device);
+}
+
+static void batterystate_driver_remove(struct btd_device *device)
+{
+ batterystate_unregister(device);
+}
+
+static struct btd_device_driver battery_device_driver = {
+ .name = "battery-driver",
+ .uuids = BTD_UUIDS(BATTERY_SERVICE_UUID),
+ .probe = batterystate_driver_probe,
+ .remove = batterystate_driver_remove
+};
+
+int batterystate_manager_init(void)
+{
+ return btd_register_device_driver(&battery_device_driver);
+}
+
+void batterystate_manager_exit(void)
+{
+ btd_unregister_device_driver(&battery_device_driver);
+}
diff --git a/batterystate/manager.h b/batterystate/manager.h
new file mode 100644
index 00000000..7f0bf154
--- /dev/null
+++ b/batterystate/manager.h
@@ -0,0 +1,24 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2012 Texas Instruments, Inc.
+ *
+ * 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
+ *
+ */
+
+int batterystate_manager_init(void);
+void batterystate_manager_exit(void);