#include <notification.h>
#include <unistd.h>
-#include <dbus/dbus.h>
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus-glib-lowlevel.h>
#include <bundle.h>
#ifdef HAVE_WAYLAND
#include <libwlmessage.h>
#endif
-typedef enum {
- BT_AGENT_ACCEPT,
- BT_AGENT_REJECT,
- BT_AGENT_CANCEL,
- BT_CORE_AGENT_TIMEOUT,
-} bt_agent_accept_type_t;
-
-
-typedef void (*bt_notification)(DBusGProxy *proxy);
-
-static DBusGProxy*
-__bluetooth_create_agent_proxy(DBusGConnection *sys_conn, const char *path)
-{
- return dbus_g_proxy_new_for_name (sys_conn,
- "org.projectx.bt",
- path,
- "org.bluez.Agent1");
-}
-
-static DBusGProxy*
-__bluetooth_create_obex_proxy(DBusGConnection *sys_conn)
-{
- return dbus_g_proxy_new_for_name(sys_conn,
- "org.bluez.frwk_agent",
- "/org/obex/ops_agent",
- "org.openobex.Agent");
-}
-
-static void
-__notify_passkey_confirm_request_accept_cb( DBusGProxy* agent_proxy)
-{
- dbus_g_proxy_call_no_reply( agent_proxy, "ReplyConfirmation",
- G_TYPE_UINT, BT_AGENT_ACCEPT,
- G_TYPE_INVALID, G_TYPE_INVALID);
-
-}
-
-static void
-__notify_passkey_confirm_request_cancel_cb(DBusGProxy* agent_proxy)
-{
-
- dbus_g_proxy_call_no_reply( agent_proxy, "ReplyConfirmation",
- G_TYPE_UINT, BT_AGENT_CANCEL,
- G_TYPE_INVALID, G_TYPE_INVALID);
-
-}
-
-static void
-__notify_push_authorize_request_accept_cb(DBusGProxy* obex_proxy)
-{
-
- dbus_g_proxy_call_no_reply( obex_proxy, "ReplyAuthorize",
- G_TYPE_UINT, BT_AGENT_ACCEPT,
- G_TYPE_INVALID, G_TYPE_INVALID);
-
-}
-
-static void
-__notify_push_authorize_request_cancel_cb(DBusGProxy* obex_proxy)
-{
-
- dbus_g_proxy_call_no_reply( obex_proxy, "ReplyAuthorize",
- G_TYPE_UINT, BT_AGENT_CANCEL,
- G_TYPE_INVALID, G_TYPE_INVALID);
-
-}
-
-static void
-__notify_authorize_request_accept_cb(DBusGProxy* agent_proxy)
-{
+#include <bundle.h>
- dbus_g_proxy_call_no_reply( agent_proxy, "ReplyAuthorize",
- G_TYPE_UINT, BT_AGENT_ACCEPT,
- G_TYPE_INVALID, G_TYPE_INVALID);
-}
+#include <bluetooth.h>
+#include <dlog.h>
-static void
-__notify_authorize_request_cancel_cb(DBusGProxy* agent_proxy)
-{
+#define POPUP_TYPE_INFO "user_info_popup"
+#define POPUP_TYPE_USERCONFIRM "user_confirm_popup"
+#define POPUP_TYPE_USERPROMPT "user_agreement_popup"
- dbus_g_proxy_call_no_reply( agent_proxy, "ReplyAuthorize",
- G_TYPE_UINT, BT_AGENT_CANCEL,
- G_TYPE_INVALID, G_TYPE_INVALID);
+static void display_user_information_popup(void) {};
-}
+static void display_user_prompt_popup(void) {};
-static int
-__display_notification(bt_notification cb_1, bt_notification cb_2, DBusGProxy *proxy)
+static void display_user_confirmation_popup(void)
{
-
notification_error_e err = NOTIFICATION_ERROR_NONE;
- int bt_yesno;
- bt_yesno = 1;
+ int bt_yesno = 1;
+
char line[4];
#ifdef HAVE_WAYLAND
wlmessage_destroy(wlmessage);
if (bt_yesno == 1)
- (cb_1) (proxy);
+ bt_agent_reply_sync(0);
else if (bt_yesno == 0)
- (cb_2) (proxy);
+ bt_agent_reply_sync(1);
#else
fprintf(stdout, "Do you confirm yes or no ? ");
while ( bt_yesno != 0){
if (!fgets(line, sizeof(line), stdin))
continue;
- if ( strcmp(line,"yes") == 0){
- (cb_1) (proxy);
+ if ( strncmp("yes", line, 3) == 0) {
+ LOGD("user accepts to pair with device ");
+ bt_agent_reply_sync(0);
bt_yesno = 0;
- } else if ( strcmp(line,"no") == 0){
- (cb_2) (proxy);
+ } else if ( strncmp("no", line, 2) == 0) {
+ LOGD("user rejects to pair with device ");
+ bt_agent_reply_sync(1);
bt_yesno = 0;
} else {
- fprintf(stdout," yes or no :");
+ fprintf(stdout," yes or no ?\n");
+ continue;
}
}
#endif
- err = notification_delete_all_by_type("bluetooth-frwk-bt-service", NOTIFICATION_TYPE_NOTI);
+ err = notification_delete_all_by_type("bt-agent", NOTIFICATION_TYPE_NOTI);
if (err != NOTIFICATION_ERROR_NONE) {
- fprintf(stdout, "Unable to remove notifications");
+ LOGE("Unable to remove notifications");
}
}
notification_h noti = NULL;
notification_list_h notification_list = NULL;
notification_list_h get_list = NULL;
- int count = 0, group_id = 0, priv_id = 0, show_noti = 0, num = 1;
+ notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
+
+ LOGD("listen to new notifications...");
+
+ int count = 0, group_id = 0, priv_id = 0, num = 1;
char *pkgname = NULL;
char *title = NULL;
char *str_count = NULL;
char *content= NULL;
bundle *user_data = NULL;
- DBusGConnection *sys_conn;
- DBusGProxy *agent_proxy;
- DBusGProxy *obex_proxy;
-
const char *device_name = NULL;
const char *passkey = NULL;
- const char *file = NULL;
const char *agent_path;
const char *event_type = NULL;
- notification_get_list(NOTIFICATION_TYPE_NOTI, -1, ¬ification_list);
+ char *popup_type = NULL;
+
+ noti_err = notification_get_list(NOTIFICATION_TYPE_NOTI, -1, ¬ification_list);
+ if (noti_err != NOTIFICATION_ERROR_NONE) {
+ LOGE("notification_get_list() failed (error code = %d)", noti_err);
+ }
+
if (notification_list) {
+ LOGD("new notificiation received");
+
get_list = notification_list_get_head(notification_list);
noti = notification_list_get_data(get_list);
notification_get_id(noti, &group_id, &priv_id);
fprintf(stdout, "NOTIFICATION: %s - %s - %s - %i - %i \n", pkgname, title, content, count, num);
- event_type = bundle_get_val(user_data, "event-type");
-
- if(!strcasecmp(event_type, "pin-request")) {
- /* Not implemented */
- fprintf(stdout," Not implemented\n");
-
- } else if (!strcasecmp(event_type, "passkey-confirm-request")){
- device_name = (gchar*) bundle_get_val(user_data, "device-name");
- passkey = (gchar*) bundle_get_val(user_data, "passkey");
- agent_path = bundle_get_val(user_data, "agent-path");
-
- sys_conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL);
- if (sys_conn == NULL) {
- fprintf(stdout,"ERROR: Can't get on system bus");
- return;
- }
-
- agent_proxy = __bluetooth_create_agent_proxy(sys_conn, agent_path);
- if (!agent_proxy){
- fprintf(stdout,"create new agent_proxy failed\n");
- return;
- }
-
- __display_notification(__notify_passkey_confirm_request_accept_cb, __notify_passkey_confirm_request_cancel_cb,agent_proxy);
- } else if (!strcasecmp(event_type, "passkey-request")) {
- /* Not implemented */
- fprintf(stdout," Not implemented\n");
-
- } else if (!strcasecmp(event_type, "passkey-display-request")) {
- /* Not implemented */
- fprintf(stdout," Not implemented\n");
-
- } else if (!strcasecmp(event_type, "authorize-request")) {
- device_name = (gchar*) bundle_get_val(user_data, "device-name");
- agent_path = bundle_get_val(user_data, "agent-path");
-
- sys_conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL);
- if (sys_conn == NULL) {
- fprintf(stdout,"ERROR: Can't get on system bus");
- return;
- }
-
- agent_proxy = __bluetooth_create_agent_proxy(sys_conn, agent_path);
- if (!agent_proxy){
- fprintf(stdout,"create new agent_proxy failed\n");
- return;
- }
+ notification_get_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, &popup_type);
+ LOGD("'%s' notification type [%s]", pkgname, popup_type);
- __display_notification( __notify_authorize_request_accept_cb, __notify_authorize_request_cancel_cb,agent_proxy);
- } else if (!strcasecmp(event_type, "app-confirm-request")) {
- /* Not implemented */
- fprintf(stdout," Not implemented\n");
+ if (!strcasecmp(POPUP_TYPE_INFO, popup_type))
+ display_user_information_popup();
+ else if (!strcasecmp(POPUP_TYPE_USERCONFIRM, popup_type))
+ display_user_confirmation_popup();
+ else if (!strcasecmp(POPUP_TYPE_USERPROMPT, popup_type))
+ display_user_prompt_popup();
+ else
+ LOGE("popup type is not recognized !");
- } else if (!strcasecmp(event_type, "push-authorize-request")) {
- file = (gchar*) bundle_get_val(user_data, "file");
- device_name = (gchar*) bundle_get_val(user_data, "device-name");
- sys_conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL);
- if (sys_conn == NULL) {
- fprintf(stdout,"ERROR: Can't get on system bus");
- return;
- }
-
- obex_proxy = __bluetooth_create_obex_proxy(sys_conn);
- if (!obex_proxy){
- fprintf(stdout,"create new obex_proxy failed\n");
- return;
- }
-
- __display_notification( __notify_push_authorize_request_accept_cb, __notify_push_authorize_request_cancel_cb,obex_proxy);
- } else if (!strcasecmp(event_type, "confirm-overwrite-request")) {
- /* Not implemented */
- fprintf(stdout," Not implemented\n");
-
- } else if (!strcasecmp(event_type, "keyboard-passkey-request")) {
- /* Not implemented */
- fprintf(stdout," Not implemented\n");
-
- } else if (!strcasecmp(event_type, "bt-information")) {
- /* Not implemented */
- fprintf(stdout," Not implemented\n");
-
- } else if (!strcasecmp(event_type, "exchange-request")) {
- device_name = (gchar*) bundle_get_val(user_data, "device-name");
- agent_path = bundle_get_val(user_data, "agent-path");
-
- sys_conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL);
- if (sys_conn == NULL) {
- fprintf(stdout,"ERROR: Can't get on system bus");
- return;
- }
-
- agent_proxy = __bluetooth_create_agent_proxy(sys_conn, agent_path);
- if (!agent_proxy){
- fprintf(stdout,"create new agent_proxy failed\n");
- return;
- }
-
- __display_notification( __notify_authorize_request_accept_cb, __notify_authorize_request_cancel_cb,agent_proxy);
- } else if (!strcasecmp(event_type, "phonebook-request")) {
- device_name = bundle_get_val(user_data, "device-name");
- agent_path = bundle_get_val(user_data, "agent-path");
-
- sys_conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL);
- if (sys_conn == NULL) {
- fprintf(stdout,"ERROR: Can't get on system bus");
- return;
- }
-
- agent_proxy = __bluetooth_create_agent_proxy(sys_conn, agent_path);
- if (!agent_proxy){
- fprintf(stdout,"create new agent_proxy failed\n");
- return;
- }
-
- __display_notification( __notify_authorize_request_accept_cb, __notify_authorize_request_cancel_cb,agent_proxy);
- } else if (!strcasecmp(event_type, "message-request")) {
- device_name = bundle_get_val(user_data, "device-name");
- agent_path = bundle_get_val(user_data, "agent-path");
-
- sys_conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL);
- if (sys_conn == NULL) {
- fprintf(stdout,"ERROR: Can't get on system bus");
- return;
- }
-
- agent_proxy = __bluetooth_create_agent_proxy(sys_conn, agent_path);
- if (!agent_proxy){
- fprintf(stdout,"create new agent_proxy failed\n");
- return;
- }
-
- __display_notification( __notify_authorize_request_accept_cb, __notify_authorize_request_cancel_cb,agent_proxy);
+ if (notification_list != NULL) {
+ notification_free_list(notification_list);
+ notification_list = NULL;
}
- }
- if (notification_list != NULL) {
- notification_free_list(notification_list);
- notification_list = NULL;
- }
-
- return;
+ }
+ return;
}
int
main(int argc, char **argv)
{
if (!ecore_init()) {
- fprintf(stderr, "ERROR: Cannot init Ecore!\n");
+ LOGE("ERROR: Cannot init Ecore!\n");
return -1;
}
+ bt_initialize();
+
+ bt_agent_register_sync();
+
notification_resister_changed_cb(__noti_changed_cb, NULL);
ecore_main_loop_begin();
- shutdown:
- ecore_shutdown();
- return 0;
+ return 1;
}
#ifdef HAVE_WAYLAND
#include <libwlmessage.h>
#endif
+#include <bluetooth.h>
+
+#define POPUP_TYPE_INFO "user_info_popup"
+#define POPUP_TYPE_USERCONFIRM "user_confirm_popup"
+#define POPUP_TYPE_USERPROMPT "user_agreement_popup"
int fd, wd;
/* react specifically to the source framework and event (TODO : plugins !) */
if (!strcmp(pkgname, "bt-agent")) {
+printf("ON EST EN BLUETOOTH\n");
notification_get_text (noti, NOTIFICATION_TEXT_TYPE_INFO_1, &info1);
if (info1) {
- if ( (!strcmp(info1, "RequestPinCode")) || (!strcmp(info1, "RequestPasskey")) ) {
- type = NOTIF_TYPE_USERPROMPT;
+ if (!strcasecmp(POPUP_TYPE_INFO, info1)) {
+ type = NOTIF_TYPE_INFO;
}
- else if (!strcmp(info1, "RequestConfirmation")) {
+ else if (!strcasecmp(POPUP_TYPE_USERCONFIRM, info1)) {
type = NOTIF_TYPE_USERCONFIRM;
content = strdup("Please confirm");
}
+ else if (!strcasecmp(POPUP_TYPE_USERPROMPT, info1)) {
+ type = NOTIF_TYPE_USERPROMPT;
+ }
}
- }
+ } else { printf ("ON N'EST PAS EN BLUETOOTH !\n"); }
# ifdef HAVE_WAYLAND
struct wlmessage *wlmessage = wlmessage_create ();
wlmessage_destroy (wlmessage);
return;
} else if ((clicked_button == 1) && (type == NOTIF_TYPE_USERCONFIRM)) {
+ printf("CLIQUE SUR OUI !\n");
if (!strcmp(pkgname, "bt-agent")) {
- struct sockaddr_un addr;
- int socket_fd, nbytes;
- char buffer[256];
-
- socket_fd = socket(PF_UNIX, SOCK_STREAM, 0);
-
- memset (&addr, 0, sizeof(struct sockaddr_un));
- addr.sun_family = AF_UNIX;
- snprintf (addr.sun_path, UNIX_PATH_MAX, "/tmp/.bluetooth.service");
-
- if (connect (socket_fd,
- (struct sockaddr *)&addr,
- sizeof(struct sockaddr_un)) != 0) {
- fprintf(stderr, "Cannot connect to /tmp/.bluetooth.service\n");
- } else {
- nbytes = snprintf(buffer, 256, "1 clicked");
- write (socket_fd, buffer, nbytes);
- close (socket_fd);
- }
+ printf("ON ENVOIE SYNC(0)\n");
+ bt_agent_reply_sync(0);
+ }
+ } else if ((clicked_button == 0) && (type == NOTIF_TYPE_USERCONFIRM)) {
+ printf("CLIQUE SUR NON !\n");
+ if (!strcmp(pkgname, "bt-agent")) {
+ printf("ON ENVOIE SYNC(1)\n");
+ bt_agent_reply_sync(1);
}
}
wlmessage_destroy (wlmessage);
{
char buffer[8192];
+ bt_initialize();
+
+ bt_agent_register_sync();
+
/* display notifications once, so it stays useful without inotify */
display_notifications ();