From: Anderson Lizardo <anderson.lizardo@openbossa.org>
To: linux-bluetooth@vger.kernel.org
Cc: Anderson Lizardo <anderson.lizardo@openbossa.org>
Subject: [PATCH v3 BlueZ 08/27] alert: Initial Alert Notification
Date: Tue, 2 Oct 2012 16:24:31 -0400 [thread overview]
Message-ID: <1349209490-31830-9-git-send-email-anderson.lizardo@openbossa.org> (raw)
In-Reply-To: <1349209490-31830-1-git-send-email-anderson.lizardo@openbossa.org>
Initial implementation for Alert Notification Profile (ANP).
---
profiles/alert/server.c | 154 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 154 insertions(+)
diff --git a/profiles/alert/server.c b/profiles/alert/server.c
index 90536d5..c0434a4 100644
--- a/profiles/alert/server.c
+++ b/profiles/alert/server.c
@@ -27,9 +27,12 @@
#endif
#include <stdbool.h>
+#include <errno.h>
+#include <gdbus.h>
#include <glib.h>
#include <bluetooth/uuid.h>
+#include "dbus-common.h"
#include "att.h"
#include "adapter.h"
#include "device.h"
@@ -41,13 +44,33 @@
#include "gatt.h"
#include "server.h"
#include "profile.h"
+#include "error.h"
#define PHONE_ALERT_STATUS_SVC_UUID 0x180E
+#define ALERT_NOTIF_SVC_UUID 0x1811
#define ALERT_STATUS_CHR_UUID 0x2A3F
#define RINGER_CP_CHR_UUID 0x2A40
#define RINGER_SETTING_CHR_UUID 0x2A41
+#define ALERT_NOTIF_CP_CHR_UUID 0x2A44
+#define UNREAD_ALERT_CHR_UUID 0x2A45
+#define NEW_ALERT_CHR_UUID 0x2A46
+#define SUPP_NEW_ALERT_CAT_CHR_UUID 0x2A47
+#define SUPP_UNREAD_ALERT_CAT_CHR_UUID 0x2A48
+
+#define ALERT_OBJECT_PATH "/org/bluez"
+#define ALERT_INTERFACE "org.bluez.Alert"
+
+enum {
+ ENABLE_NEW_INCOMING,
+ ENABLE_UNREAD_CAT,
+ DISABLE_NEW_INCOMING,
+ DISABLE_UNREAD_CAT,
+ NOTIFY_NEW_INCOMING,
+ NOTIFY_UNREAD_CAT,
+};
+
/* Ringer Setting characteristic values */
enum {
RINGER_SILENT,
@@ -57,6 +80,20 @@ enum {
static uint8_t ringer_setting = RINGER_NORMAL;
static uint8_t alert_status = 0;
+static DBusMessage *register_alert(DBusConnection *conn, DBusMessage *msg,
+ void *data)
+{
+ const char *category;
+
+ if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &category,
+ DBUS_TYPE_INVALID))
+ return btd_error_invalid_args(msg);
+
+ DBG("RegisterAlert: %s", category);
+
+ return dbus_message_new_method_return(msg);
+}
+
static uint8_t ringer_cp_write(struct attribute *a,
struct btd_device *device,
gpointer user_data)
@@ -124,10 +161,107 @@ static void register_phone_alert_service(struct btd_adapter *adapter)
GATT_OPT_INVALID);
}
+static uint8_t supp_new_alert_cat_read(struct attribute *a,
+ struct btd_device *device,
+ gpointer user_data)
+{
+ struct btd_adapter *adapter = user_data;
+ uint8_t value[] = {0x00, 0x00};
+
+ DBG("a = %p", a);
+
+ if (a->data == NULL)
+ attrib_db_update(adapter, a->handle, NULL, value, sizeof(value),
+ NULL);
+
+ return 0;
+}
+
+static uint8_t supp_unread_alert_cat_read(struct attribute *a,
+ struct btd_device *device,
+ gpointer user_data)
+{
+ struct btd_adapter *adapter = user_data;
+ uint8_t value[] = {0x00, 0x00};
+
+ DBG("a = %p", a);
+
+ if (a->data == NULL)
+ attrib_db_update(adapter, a->handle, NULL, value, sizeof(value),
+ NULL);
+
+ return 0;
+}
+
+static uint8_t alert_notif_cp_write(struct attribute *a,
+ struct btd_device *device,
+ gpointer user_data)
+{
+ DBG("a = %p", a);
+
+ switch (a->data[0]) {
+ case ENABLE_NEW_INCOMING:
+ DBG("ENABLE_NEW_INCOMING: 0x%02x", a->data[1]);
+ break;
+ case ENABLE_UNREAD_CAT:
+ DBG("ENABLE_UNREAD_CAT: 0x%02x", a->data[1]);
+ break;
+ case DISABLE_NEW_INCOMING:
+ DBG("DISABLE_NEW_INCOMING: 0x%02x", a->data[1]);
+ break;
+ case DISABLE_UNREAD_CAT:
+ DBG("DISABLE_UNREAD_CAT: 0x%02x", a->data[1]);
+ break;
+ case NOTIFY_NEW_INCOMING:
+ DBG("NOTIFY_NEW_INCOMING: 0x%02x", a->data[1]);
+ break;
+ case NOTIFY_UNREAD_CAT:
+ DBG("NOTIFY_UNREAD_CAT: 0x%02x", a->data[1]);
+ break;
+ default:
+ DBG("0x%02x 0x%02x", a->data[0], a->data[1]);
+ }
+
+ return 0;
+}
+
+static void register_alert_notif_service(struct btd_adapter *adapter)
+{
+ bt_uuid_t uuid;
+
+ bt_uuid16_create(&uuid, ALERT_NOTIF_SVC_UUID);
+
+ /* Alert Notification Service */
+ gatt_service_add(adapter, GATT_PRIM_SVC_UUID, &uuid,
+ /* Supported New Alert Category */
+ GATT_OPT_CHR_UUID, SUPP_NEW_ALERT_CAT_CHR_UUID,
+ GATT_OPT_CHR_PROPS, ATT_CHAR_PROPER_READ,
+ GATT_OPT_CHR_VALUE_CB, ATTRIB_READ,
+ supp_new_alert_cat_read, adapter,
+ /* New Alert */
+ GATT_OPT_CHR_UUID, NEW_ALERT_CHR_UUID,
+ GATT_OPT_CHR_PROPS, ATT_CHAR_PROPER_NOTIFY,
+ /* Supported Unread Alert Category */
+ GATT_OPT_CHR_UUID, SUPP_UNREAD_ALERT_CAT_CHR_UUID,
+ GATT_OPT_CHR_PROPS, ATT_CHAR_PROPER_READ,
+ GATT_OPT_CHR_VALUE_CB, ATTRIB_READ,
+ supp_unread_alert_cat_read, adapter,
+ /* Unread Alert Status */
+ GATT_OPT_CHR_UUID, UNREAD_ALERT_CHR_UUID,
+ GATT_OPT_CHR_PROPS, ATT_CHAR_PROPER_NOTIFY,
+ /* Alert Notification Control Point */
+ GATT_OPT_CHR_UUID, ALERT_NOTIF_CP_CHR_UUID,
+ GATT_OPT_CHR_PROPS, ATT_CHAR_PROPER_WRITE,
+ GATT_OPT_CHR_VALUE_CB, ATTRIB_WRITE,
+ alert_notif_cp_write, NULL,
+ GATT_OPT_INVALID);
+}
+
static int alert_server_probe(struct btd_profile *p,
struct btd_adapter *adapter)
{
register_phone_alert_service(adapter);
+ register_alert_notif_service(adapter);
return 0;
}
@@ -143,8 +277,25 @@ static struct btd_profile alert_profile = {
.adapter_remove = alert_server_remove,
};
+static const GDBusMethodTable alert_methods[] = {
+ { GDBUS_METHOD("RegisterAlert",
+ GDBUS_ARGS({ "category", "s" },
+ { "agent", "o" }), NULL,
+ register_alert) },
+ { }
+};
+
int alert_server_init(void)
{
+ if (!g_dbus_register_interface(btd_get_dbus_connection(),
+ ALERT_OBJECT_PATH, ALERT_INTERFACE,
+ alert_methods, NULL, NULL, NULL,
+ NULL)) {
+ error("D-Bus failed to register %s interface",
+ ALERT_INTERFACE);
+ return -EIO;
+ }
+
btd_profile_register(&alert_profile);
return 0;
@@ -153,4 +304,7 @@ int alert_server_init(void)
void alert_server_exit(void)
{
btd_profile_unregister(&alert_profile);
+
+ g_dbus_unregister_interface(btd_get_dbus_connection(),
+ ALERT_OBJECT_PATH, ALERT_INTERFACE);
}
--
1.7.9.5
next prev parent reply other threads:[~2012-10-02 20:24 UTC|newest]
Thread overview: 88+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-24 18:00 [PATCH BlueZ 00/25] Add support for PASP and ANP server profiles Anderson Lizardo
2012-09-24 18:00 ` [PATCH BlueZ 01/25] doc: Introduce Alert API Anderson Lizardo
2012-09-24 18:00 ` [PATCH BlueZ 02/25] alert: Introduce manager abstraction layer Anderson Lizardo
2012-09-24 18:00 ` [PATCH BlueZ 03/25] alert: Initial profile registration Anderson Lizardo
2012-09-24 18:00 ` [PATCH BlueZ 04/25] alert: Add Phone Alert Status Service Anderson Lizardo
2012-09-24 18:00 ` [PATCH BlueZ 05/25] alert: Add Ringer Control Point characteristic Anderson Lizardo
2012-09-24 18:00 ` [PATCH BlueZ 06/25] alert: Add Ringer Setting characteristic Anderson Lizardo
2012-09-24 18:00 ` [PATCH BlueZ 07/25] alert: Add Alert Status characteristic Anderson Lizardo
2012-09-24 18:00 ` [PATCH BlueZ 08/25] alert: Initial Alert Notification Anderson Lizardo
2012-09-24 18:00 ` [PATCH BlueZ 09/25] alert: Implement category registration in RegisterAlert() Anderson Lizardo
2012-09-24 18:00 ` [PATCH BlueZ 10/25] alert: Add initial support for NewAlert D-Bus method Anderson Lizardo
2012-09-24 18:00 ` [PATCH BlueZ 11/25] alert: Add initial support for UnreadAlert " Anderson Lizardo
2012-09-24 18:00 ` [PATCH BlueZ 12/25] alert: Automatically unregister alert when agent leaves D-Bus Anderson Lizardo
2012-09-24 18:00 ` [PATCH BlueZ 13/25] alert: Add per adapter attribute handle information Anderson Lizardo
2012-09-24 18:00 ` [PATCH BlueZ 14/25] alert: Update Supported New/Unread Category characteristic values Anderson Lizardo
2012-09-24 18:00 ` [PATCH BlueZ 15/25] alert: Update new alert characteristic value Anderson Lizardo
2012-09-24 18:00 ` [PATCH BlueZ 16/25] alert: Update unread " Anderson Lizardo
2012-09-24 18:00 ` [PATCH BlueZ 17/25] alert: Implement MuteOnce command Anderson Lizardo
2012-09-24 18:00 ` [PATCH BlueZ 18/25] alert: Add support for calling MuteOnce() Anderson Lizardo
2012-09-24 18:00 ` [PATCH BlueZ 19/25] alert: Add support for calling SetRinger() Anderson Lizardo
2012-09-24 18:00 ` [PATCH BlueZ 20/25] alert: Add test-alert script Anderson Lizardo
2012-09-24 18:00 ` [PATCH BlueZ 21/25] alert: Update Alert Status and Ringer Setting characteristic values Anderson Lizardo
2012-09-24 18:00 ` [PATCH BlueZ 22/25] alert: Add support for ringer setting notification Anderson Lizardo
2012-09-24 18:00 ` [PATCH BlueZ 23/25] alert: Add support for alert status notification Anderson Lizardo
2012-09-24 18:01 ` [PATCH BlueZ 24/25] alert: Add support for new alert notification Anderson Lizardo
2012-09-24 18:01 ` [PATCH BlueZ 25/25] alert: Add support for unread " Anderson Lizardo
2012-09-27 18:36 ` [PATCH v2 BlueZ 00/27] Add support for PASP and ANP server profiles Anderson Lizardo
2012-09-27 18:36 ` [PATCH v2 BlueZ 01/27] doc: Introduce Alert API Anderson Lizardo
2012-09-27 18:36 ` [PATCH v2 BlueZ 02/27] alert: Introduce manager abstraction layer Anderson Lizardo
2012-09-27 18:36 ` [PATCH v2 BlueZ 03/27] alert: Initial profile registration Anderson Lizardo
2012-09-27 18:36 ` [PATCH v2 BlueZ 04/27] alert: Add Phone Alert Status Service Anderson Lizardo
2012-09-27 18:36 ` [PATCH v2 BlueZ 05/27] alert: Add Ringer Control Point characteristic Anderson Lizardo
2012-09-27 18:36 ` [PATCH v2 BlueZ 06/27] alert: Add Ringer Setting characteristic Anderson Lizardo
2012-09-27 18:36 ` [PATCH v2 BlueZ 07/27] alert: Add Alert Status characteristic Anderson Lizardo
2012-09-27 18:36 ` [PATCH v2 BlueZ 08/27] alert: Initial Alert Notification Anderson Lizardo
2012-09-27 18:36 ` [PATCH v2 BlueZ 09/27] alert: Implement category registration in RegisterAlert() Anderson Lizardo
2012-09-27 18:36 ` [PATCH v2 BlueZ 10/27] alert: Add initial support for NewAlert D-Bus method Anderson Lizardo
2012-09-27 18:36 ` [PATCH v2 BlueZ 11/27] alert: Add initial support for UnreadAlert " Anderson Lizardo
2012-09-27 18:36 ` [PATCH v2 BlueZ 12/27] alert: Automatically unregister alert when agent leaves D-Bus Anderson Lizardo
2012-09-27 18:36 ` [PATCH v2 BlueZ 13/27] alert: Add per adapter attribute handle information Anderson Lizardo
2012-09-27 18:36 ` [PATCH v2 BlueZ 14/27] alert: Update Supported New/Unread Category characteristic values Anderson Lizardo
2012-09-27 18:36 ` [PATCH v2 BlueZ 15/27] alert: Update new alert characteristic value Anderson Lizardo
2012-09-27 18:36 ` [PATCH v2 BlueZ 16/27] alert: Update unread " Anderson Lizardo
2012-09-27 18:36 ` [PATCH v2 BlueZ 17/27] alert: Implement MuteOnce command Anderson Lizardo
2012-09-27 18:36 ` [PATCH v2 BlueZ 18/27] alert: Add support for calling MuteOnce() Anderson Lizardo
2012-09-27 18:36 ` [PATCH v2 BlueZ 19/27] alert: Add support for calling SetRinger() Anderson Lizardo
2012-09-27 18:36 ` [PATCH v2 BlueZ 20/27] alert: Add test-alert script Anderson Lizardo
2012-09-27 18:36 ` [PATCH v2 BlueZ 21/27] alert: Update Alert Status and Ringer Setting characteristic values Anderson Lizardo
2012-09-27 18:36 ` [PATCH v2 BlueZ 22/27] alert: Add support for ringer setting notification Anderson Lizardo
2012-09-27 18:36 ` [PATCH v2 BlueZ 23/27] alert: Add support for alert status notification Anderson Lizardo
2012-09-27 18:36 ` [PATCH v2 BlueZ 24/27] alert: Add support for new alert notification Anderson Lizardo
2012-09-27 18:36 ` [PATCH v2 BlueZ 25/27] alert: Add support for unread " Anderson Lizardo
2012-09-27 18:36 ` [PATCH v2 BlueZ 26/27] alert: Implement Release() agent method Anderson Lizardo
2012-09-27 18:36 ` [PATCH v2 BlueZ 27/27] alert: Add org.bluez.AlertAgent to D-Bus policy file Anderson Lizardo
2012-10-02 20:24 ` [PATCH v3 BlueZ 00/27] Add support for PASP and ANP server profiles Anderson Lizardo
2012-10-02 20:24 ` [PATCH v3 BlueZ 01/27] doc: Introduce Alert API Anderson Lizardo
2012-10-03 8:21 ` Johan Hedberg
2012-10-03 10:56 ` Anderson Lizardo
2012-10-03 12:46 ` [PATCH v4 " Anderson Lizardo
2012-10-03 19:39 ` Johan Hedberg
2012-10-03 20:17 ` Anderson Lizardo
2012-10-02 20:24 ` [PATCH v3 BlueZ 02/27] alert: Introduce manager abstraction layer Anderson Lizardo
2012-10-02 20:24 ` [PATCH v3 BlueZ 03/27] alert: Initial profile registration Anderson Lizardo
2012-10-02 20:24 ` [PATCH v3 BlueZ 04/27] alert: Add Phone Alert Status Service Anderson Lizardo
2012-10-02 20:24 ` [PATCH v3 BlueZ 05/27] alert: Add Ringer Control Point characteristic Anderson Lizardo
2012-10-02 20:24 ` [PATCH v3 BlueZ 06/27] alert: Add Ringer Setting characteristic Anderson Lizardo
2012-10-02 20:24 ` [PATCH v3 BlueZ 07/27] alert: Add Alert Status characteristic Anderson Lizardo
2012-10-02 20:24 ` Anderson Lizardo [this message]
2012-10-02 20:24 ` [PATCH v3 BlueZ 09/27] alert: Implement category registration in RegisterAlert() Anderson Lizardo
2012-10-03 12:49 ` [PATCH v4 " Anderson Lizardo
2012-10-02 20:24 ` [PATCH v3 BlueZ 10/27] alert: Add initial support for NewAlert D-Bus method Anderson Lizardo
2012-10-02 20:24 ` [PATCH v3 BlueZ 11/27] alert: Add initial support for UnreadAlert " Anderson Lizardo
2012-10-02 20:24 ` [PATCH v3 BlueZ 12/27] alert: Automatically unregister alert when agent leaves D-Bus Anderson Lizardo
2012-10-02 20:24 ` [PATCH v3 BlueZ 13/27] alert: Add per adapter attribute handle information Anderson Lizardo
2012-10-02 20:24 ` [PATCH v3 BlueZ 14/27] alert: Update Supported New/Unread Category characteristic values Anderson Lizardo
2012-10-02 20:24 ` [PATCH v3 BlueZ 15/27] alert: Update new alert characteristic value Anderson Lizardo
2012-10-02 20:24 ` [PATCH v3 BlueZ 16/27] alert: Update unread " Anderson Lizardo
2012-10-02 20:24 ` [PATCH v3 BlueZ 17/27] alert: Implement MuteOnce command Anderson Lizardo
2012-10-02 20:24 ` [PATCH v3 BlueZ 18/27] alert: Add support for calling MuteOnce() Anderson Lizardo
2012-10-02 20:24 ` [PATCH v3 BlueZ 19/27] alert: Add support for calling SetRinger() Anderson Lizardo
2012-10-02 20:24 ` [PATCH v3 BlueZ 20/27] alert: Add test-alert script Anderson Lizardo
2012-10-02 20:24 ` [PATCH v3 BlueZ 21/27] alert: Update Alert Status and Ringer Setting characteristic values Anderson Lizardo
2012-10-02 20:24 ` [PATCH v3 BlueZ 22/27] alert: Add support for ringer setting notification Anderson Lizardo
2012-10-02 20:24 ` [PATCH v3 BlueZ 23/27] alert: Add support for alert status notification Anderson Lizardo
2012-10-02 20:24 ` [PATCH v3 BlueZ 24/27] alert: Add support for new alert notification Anderson Lizardo
2012-10-02 20:24 ` [PATCH v3 BlueZ 25/27] alert: Add support for unread " Anderson Lizardo
2012-10-02 20:24 ` [PATCH v3 BlueZ 26/27] alert: Implement Release() agent method Anderson Lizardo
2012-10-02 20:24 ` [PATCH v3 BlueZ 27/27] alert: Add org.bluez.AlertAgent to D-Bus policy file Anderson Lizardo
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=1349209490-31830-9-git-send-email-anderson.lizardo@openbossa.org \
--to=anderson.lizardo@openbossa.org \
--cc=linux-bluetooth@vger.kernel.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