linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eduardo Rocha <folhabranca@gmail.com>
To: bluez-devel@lists.sourceforge.net
Subject: Re: [Bluez-devel] [DBUS Patch] Device Property
Date: Fri, 16 Dec 2005 15:37:10 -0300	[thread overview]
Message-ID: <3013cac80512161037q19c19ecamafe77a379fec2ed0@mail.gmail.com> (raw)
In-Reply-To: <3013cac80512141102k2dbe40c9q7b25deebb9e4fae9@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3862 bytes --]

Hi Marcel,

here is the patch for set auth enable. This patch should be applied
after the last scan patch. Let me know if there is any problem.

BR,
Eduardo

On 12/14/05, Eduardo Rocha <folhabranca@gmail.com> wrote:
> Hi Marcel,
>
> here is the new patch.
>
> BR,
> Eduardo.
>
>
> On 12/13/05, Marcel Holtmann <marcel@holtmann.org> wrote:
> > Hi Eduardo,
> >
> > > here is the patch with the send_property_changed_signal function included.
> >
> > nice, but please follow the coding style. I don't wanna correct the
> > whitespaces in all patches. Some examples what should be changed:
> >
> > (void*)&pdata                           ==> (void *) &pdata
> > = SCAN_PAGE|SCAN_INQUIRY;               ==> = SCAN_PAGE | SCAN_INQUIRY;
> > se = (rp.enable & SCAN_PAGE)?1:0;       se = (rp.enable & SCAN_PAGE) ? 1 : 0;
> >
> > This is also bad coding style:
> >
> >        if (dd < 0) {
> >                syslog(LOG_ERR, "HCI device open failed: hci%d", id);
> >                goto failed;
> >        } else {
> >
> > We don't need the else branch. I results in an needless indentation.
> >
> > I also think that we need some more newlines in your code, but I am
> > going to fix it when applying the patch.
> >
> > This part might work, but I don't like it:
> >
> >        if (ispscan) {
> >                if (scan && !(rp.enable & SCAN_PAGE))
> >                        enable = (rp.enable & SCAN_INQUIRY) | SCAN_PAGE;
> >                else if (!scan && (rp.enable & SCAN_PAGE))
> >                        enable = (rp.enable & SCAN_INQUIRY);
> >                else {
> >                        reply = dbus_message_new_method_return(msg);
> >                        goto failed;
> >                }
> >        } else {
> >                if (scan && !(rp.enable & SCAN_INQUIRY))
> >                        enable = (rp.enable & SCAN_PAGE) | SCAN_INQUIRY;
> >                else if (!scan && (rp.enable & SCAN_INQUIRY))
> >                        enable = (rp.enable & SCAN_PAGE);
> >                else {
> >                        reply = dbus_message_new_method_return(msg);
> >                        goto failed;
> >                }
> >        }
> >
> > And this includes this:
> >
> >        if((rp.enable & SCAN_PAGE) != (old_data & SCAN_PAGE)) {
> >                se = (rp.enable & SCAN_PAGE)?1:0;
> >                send_property_changed_signal(id, DEV_PROPERTY_PSCAN, DBUS_TYPE_BOOLEAN, &se);
> >        }
> >        if ((rp.enable & SCAN_INQUIRY) != (old_data & SCAN_INQUIRY)) {
> >                se = (rp.enable & SCAN_INQUIRY)?1:0;
> >                send_property_changed_signal(id, DEV_PROPERTY_ISCAN, DBUS_TYPE_BOOLEAN, &se);
> >        }
> >        dbus_connection_flush(connection);
> >
> > I don't have any better idea to solve this at the moment, but if you
> > read this code it takes too much time too understand what it is actually
> > doing. And normally this is not a good idea. However we might fix it
> > later and get the patch in now for further testing. So please correct
> > the other parts and resend it.
> >
> > Regards
> >
> > Marcel
> >
> >
> >
> >
> > -------------------------------------------------------
> > This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
> > for problems?  Stop!  Download the new AJAX search engine that makes
> > searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
> > http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
> > _______________________________________________
> > Bluez-devel mailing list
> > Bluez-devel@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/bluez-devel
> >
>
>
> --
> Eduardo Rocha
> Instituto Nokia de Tecnologia - INdT
>
>
>


--
Eduardo Rocha
Instituto Nokia de Tecnologia - INdT

[-- Attachment #2: dbus_device_auth.patch --]
[-- Type: text/x-patch, Size: 7133 bytes --]

--- utils.15122005.orig/hcid/hcid.h	2005-12-15 10:38:12.000000000 -0300
+++ utils.15122005/hcid/hcid.h	2005-12-15 12:13:31.000000000 -0300
@@ -136,6 +136,7 @@
 void hcid_dbus_auth_complete(bdaddr_t *local, bdaddr_t *peer, const uint8_t status);
 void hcid_dbus_setname_complete(bdaddr_t *local);
 void hcid_dbus_setscan_enable_complete(bdaddr_t *local);
+void hcid_dbus_setauth_enable_complete(bdaddr_t *local);
 #else
 static inline void hcid_dbus_inquiry_start(bdaddr_t *local) {}
 static inline void hcid_dbus_inquiry_complete(bdaddr_t *local) {}
@@ -147,6 +148,7 @@
 static inline void hcid_dbus_auth_complete(bdaddr_t *local, bdaddr_t *peer, const uint8_t status) {}
 static inline void hcid_dbus_setname_complete(bdaddr_t *local) {}
 static inline void hcid_dbus_setscan_enable_complete(bdaddr_t *local) {}
+static inline void hcid_dbus_setauth_enable_complete(bdaddr_t *local) {}
 #endif
 
 int write_device_name(bdaddr_t *local, bdaddr_t *peer, char *name);
--- utils.15122005.orig/hcid/security.c	2005-12-15 10:38:12.000000000 -0300
+++ utils.15122005/hcid/security.c	2005-12-15 12:15:00.000000000 -0300
@@ -500,6 +500,10 @@
 		break;
 	case cmd_opcode_pack(OGF_HOST_CTL, OCF_WRITE_SCAN_ENABLE):
 		hcid_dbus_setscan_enable_complete(sba);
+		break;
+	case cmd_opcode_pack(OGF_HOST_CTL, OCF_WRITE_AUTH_ENABLE):
+		hcid_dbus_setauth_enable_complete(sba);
+		break;
 	};
 }
 
--- utils.15122005.orig/hcid/dbus.h	2005-12-15 10:38:12.000000000 -0300
+++ utils.15122005/hcid/dbus.h	2005-12-15 12:11:46.000000000 -0300
@@ -131,7 +131,7 @@
 #define DEV_PROPERTY_PSCAN		"connectable"
 #define DEV_PROPERTY_ISCAN		"discoverable"
 #define DEV_PROPERTY_NAME		"name"
-#define DEV_PROPERTY_INCMODE		"incmode"
+#define DEV_PROPERTY_INCMODE		"inqmode"
 #define DEV_PROPERTY_DEV_INFO		"info"
 
 #define DEV_UP_SIGNATURE			__END_SIG__
--- utils.15122005.orig/hcid/dbus.c	2005-12-15 10:38:12.000000000 -0300
+++ utils.15122005/hcid/dbus.c	2005-12-16 12:24:29.000000000 -0300
@@ -112,6 +112,12 @@
 	unsigned int val;
 } hci_map;
 
+typedef struct {
+	uint8_t status;
+	uint8_t enable;
+} __attribute__ ((packed)) read_auth_enable_rp;
+#define READ_AUTH_ENABLE_RP_SIZE 2
+
 static hci_map dev_flags_map[] = {
 	{ "INIT",	HCI_INIT	},
 	{ "RUNNING",	HCI_RUNNING	},
@@ -278,6 +284,7 @@
 static DBusMessage* handle_device_get_property_req_name(DBusMessage *msg, void *data);
 static DBusMessage* handle_device_set_property_req_pscan(DBusMessage *msg, void *data);
 static DBusMessage* handle_device_set_property_req_iscan(DBusMessage *msg, void *data);
+static DBusMessage* handle_device_set_property_req_auth(DBusMessage *msg, void *data);
 
 static const struct service_data device_services[] = {
 	{ DEV_UP,		handle_device_up_req,		DEV_UP_SIGNATURE		},
@@ -290,7 +297,7 @@
 };
 
 static const struct service_data set_property_services[] = {
-	{ DEV_PROPERTY_AUTH,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BOOL		},
+	{ DEV_PROPERTY_AUTH,		handle_device_set_property_req_auth,	DEV_SET_PROPERTY_SIGNATURE_BOOL		},
 	{ DEV_PROPERTY_ENCRYPT,		handle_not_implemented_req,		DEV_SET_PROPERTY_SIGNATURE_BOOL		},
 	{ DEV_PROPERTY_PSCAN,		handle_device_set_property_req_pscan,	DEV_SET_PROPERTY_SIGNATURE_BOOL		},
 	{ DEV_PROPERTY_ISCAN,		handle_device_set_property_req_iscan,	DEV_SET_PROPERTY_SIGNATURE_BOOL		},
@@ -2241,7 +2248,7 @@
 	uint8_t status;
 	uint8_t scan_change, scan_keep;
 	struct hci_request rq;
-	gboolean prop_value; /* new requested value for the iscan or pscan */
+	dbus_bool_t prop_value; /* new requested value for the iscan or pscan */
 
 	dbus_message_iter_init(msg, &iter);
 	dbus_message_iter_next(&iter);
@@ -2332,7 +2339,7 @@
 	bdaddr_t tmp;
 	int id;
 	int dd = -1;
-	gboolean se;
+	dbus_bool_t se;
 	read_scan_enable_rp rp;
 	struct hci_request rq;
 	struct hci_dbus_data *pdata = NULL;
@@ -2408,6 +2415,130 @@
 	return write_scan_enable(msg, data, FALSE);
 }
 
+static DBusMessage* handle_device_set_property_req_auth(DBusMessage *msg, void *data)
+{
+	struct hci_dbus_data *dbus_data = data;
+	DBusMessageIter iter;
+	DBusMessage *reply = NULL;
+	int dd = -1;
+	uint8_t enable;
+	uint8_t status;
+	struct hci_request rq;
+
+	dbus_message_iter_init(msg, &iter);
+	dbus_message_iter_next(&iter);
+	dbus_message_iter_get_basic(&iter, &enable);
+
+	dd = hci_open_dev(dbus_data->dev_id);
+	if (dd < 0) {
+		syslog(LOG_ERR, "HCI device open failed: hci%d", dbus_data->dev_id);
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
+		goto failed;
+	}
+
+	memset(&rq, 0, sizeof(rq));
+	rq.ogf    = OGF_HOST_CTL;
+	rq.ocf    = OCF_WRITE_AUTH_ENABLE;
+	rq.cparam = &enable;
+	rq.clen   = sizeof(enable);
+	rq.rparam = &status;
+	rq.rlen   = sizeof(status);
+
+	if (hci_send_req(dd, &rq, 100) < 0) {
+		syslog(LOG_ERR, "Sending auth enable command failed: %s (%d)",
+							strerror(errno), errno);
+		reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+		goto failed;
+	}
+
+	if (status) {
+		syslog(LOG_ERR, "Enable authentication command failed with status 0x%02x",
+								 	status);
+		reply = bluez_new_failure_msg(msg, BLUEZ_EBT_OFFSET + status);
+		goto failed;
+        }
+	reply = dbus_message_new_method_return(msg);
+
+failed:
+	if (dd >= 0)
+		close(dd);
+	return reply;
+}
+
+void hcid_dbus_setauth_enable_complete(bdaddr_t *local)
+{
+	DBusMessage *message = NULL;
+	char *local_addr;
+	char path[MAX_PATH_LENGTH];
+	char *ppath = path;
+	bdaddr_t tmp;
+	int id;
+	int dd = -1;
+	read_auth_enable_rp rp;
+	struct hci_request rq;
+	dbus_bool_t outparam;
+
+	baswap(&tmp, local); local_addr = batostr(&tmp);
+	id = hci_devid(local_addr);
+	if (id < 0) {
+		syslog(LOG_ERR, "No matching device id for %s", local_addr);
+		goto failed;
+	}
+
+	snprintf(path, sizeof(path) - 1, "%s/hci%d", DEVICE_PATH, id);
+	path[MAX_PATH_LENGTH-1]='\0';
+
+	dd = hci_open_dev(id);
+	memset(&rq, 0, sizeof(rq));
+
+	if (dd < 0) {
+		syslog(LOG_ERR, "HCI device open failed: hci%d", id);
+		goto failed;
+	}
+	rq.ogf    = OGF_HOST_CTL;
+	rq.ocf    = OCF_READ_AUTH_ENABLE;
+	rq.rparam = &rp;
+	rq.rlen   = READ_AUTH_ENABLE_RP_SIZE;
+	if (hci_send_req(dd, &rq, 100) < 0) {
+		syslog(LOG_ERR,
+			"Sending read auth enable command failed: %s (%d)",
+			strerror(errno), errno);
+		goto failed;
+	}
+	if (rp.status) {
+		syslog(LOG_ERR,
+			"Getting auth enable failed with status 0x%02x",
+			rp.status);
+		goto failed;
+	}
+
+	message = dbus_message_new_signal(path, DEVICE_INTERFACE,
+						BLUEZ_HCI_PROPERTY_CHANGED);
+	if (message == NULL) {
+		syslog(LOG_ERR, "Can't allocate D-BUS inquiry complete message");
+		goto failed;
+	}
+
+	strcpy(path, DEV_PROPERTY_AUTH);
+	outparam = rp.enable;
+	dbus_message_append_args(message,
+				DBUS_TYPE_STRING, &ppath,
+				DBUS_TYPE_BOOLEAN, &outparam,
+				DBUS_TYPE_INVALID);
+
+	if (dbus_connection_send(connection, message, NULL) == FALSE) {
+		syslog(LOG_ERR, "Can't send D-BUS PropertChanged(%s) signal", DEV_PROPERTY_AUTH);
+		goto failed;
+	}
+
+	dbus_connection_flush(connection);
+
+failed:
+	if (dd >= 0)
+		close(dd);
+	bt_free(local_addr);
+}
+
 static DBusMessage* handle_device_list_req(DBusMessage *msg, void *data)
 {
 	DBusMessageIter iter;

  reply	other threads:[~2005-12-16 18:37 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-04 14:03 [Bluez-devel] [DBUS Patch] Device Property Eduardo Rocha
2005-11-04 15:44 ` Marcel Holtmann
2005-11-08 20:41   ` Claudio Takahasi
2005-11-08 22:20     ` Marcel Holtmann
2005-11-08 22:20     ` Johan Hedberg
2005-11-08 22:38       ` Marcel Holtmann
2005-11-17 19:16         ` Eduardo Rocha
2005-11-17 20:52           ` Eduardo Rocha
2005-11-18  8:28             ` Johan Hedberg
2005-11-18 10:51               ` Eduardo Rocha
2005-11-18 11:26                 ` Johan Hedberg
2005-11-18 13:00                   ` Eduardo Rocha
2005-11-22 11:51                     ` Marcel Holtmann
2005-11-22 19:52                       ` Eduardo Rocha
2005-11-24  4:17                         ` Marcel Holtmann
2005-11-24 18:50                           ` Eduardo Rocha
2005-11-24 22:54                             ` Marcel Holtmann
2005-11-25 13:47                               ` Claudio Takahasi
2005-11-25 14:32                                 ` Eduardo Rocha
2005-11-25 18:08                                 ` Marcel Holtmann
2005-11-25 18:34                                   ` Eduardo Rocha
2005-11-25 18:41                                     ` Marcel Holtmann
2005-11-25 19:52                                       ` Claudio Takahasi
2005-11-25 20:06                                         ` Marcel Holtmann
2005-12-01 16:55                                           ` Eduardo Rocha
2005-12-01 21:05                                             ` Marcel Holtmann
2005-12-07 12:29                                               ` Eduardo Rocha
2005-12-07 12:55                                                 ` Johan Hedberg
2005-12-07 13:02                                                   ` Marcel Holtmann
2005-12-07 16:01                                                     ` Eduardo Rocha
2005-12-13 17:27                                                       ` Eduardo Rocha
2005-12-13 22:03                                                         ` Marcel Holtmann
2005-12-14 19:02                                                           ` Eduardo Rocha
2005-12-16 18:37                                                             ` Eduardo Rocha [this message]
2005-12-16 18:40                                                               ` Marcel Holtmann
2005-11-25 16:51                               ` Johan Hedberg
2005-11-25 18:12                                 ` Marcel Holtmann

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=3013cac80512161037q19c19ecamafe77a379fec2ed0@mail.gmail.com \
    --to=folhabranca@gmail.com \
    --cc=bluez-devel@lists.sourceforge.net \
    /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;
as well as URLs for NNTP newsgroup(s).