Linux bluetooth development
 help / color / mirror / Atom feed
* [obexd] GCC 4.6 warning fixes
From: Bastien Nocera @ 2011-05-06 14:57 UTC (permalink / raw)
  To: BlueZ development

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

As for bluez.

[-- Attachment #2: 0001-Fix-GCC-4.6-warnings-about-unused-variables.patch --]
[-- Type: text/x-patch, Size: 1847 bytes --]

>From cc010c73caa98195f62340dc28e4f705dfd191d0 Mon Sep 17 00:00:00 2001
From: Bastien Nocera <hadess@hadess.net>
Date: Fri, 6 May 2011 15:50:31 +0100
Subject: [PATCH] Fix GCC 4.6 warnings about unused variables

---
 btio/btio.c      |    4 ++++
 client/session.c |    3 ---
 gdbus/object.c   |    3 +--
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/btio/btio.c b/btio/btio.c
index 8b273ca..1d8101a 100644
--- a/btio/btio.c
+++ b/btio/btio.c
@@ -1067,6 +1067,10 @@ gboolean bt_io_accept(GIOChannel *io, BtIOConnect connect, gpointer user_data,
 	if (!(pfd.revents & POLLOUT)) {
 		int ret;
 		ret = read(sock, &c, 1);
+		if (ret < 0) {
+			ERROR_FAILED(err, "read", errno);
+			return FALSE;
+		}
 	}
 
 	accept_add(io, connect, user_data, destroy);
diff --git a/client/session.c b/client/session.c
index 88eae8d..ceda3f4 100644
--- a/client/session.c
+++ b/client/session.c
@@ -516,10 +516,7 @@ struct session_data *session_create(const char *source,
 
 void session_shutdown(struct session_data *session)
 {
-	struct transfer_data *transfer;
-
 	DBG("%p", session);
-	transfer = session->pending ? session->pending->data : NULL;
 
 	session_ref(session);
 
diff --git a/gdbus/object.c b/gdbus/object.c
index eaa2e1a..d17a101 100644
--- a/gdbus/object.c
+++ b/gdbus/object.c
@@ -255,14 +255,13 @@ void g_dbus_pending_success(DBusConnection *connection,
 
         for (list = pending_security; list; list = list->next) {
 		struct security_data *secdata = list->data;
-		DBusHandlerResult result;
 
 		if (secdata->pending != pending)
 			continue;
 
 		pending_security = g_slist_remove(pending_security, secdata);
 
-		result = process_message(connection, secdata->message,
+		process_message(connection, secdata->message,
 				secdata->method, secdata->iface_user_data);
 
 		dbus_message_unref(secdata->message);
-- 
1.7.5


^ permalink raw reply related

* Re: Warning fixes for GCC 4.6
From: Bastien Nocera @ 2011-05-06 14:56 UTC (permalink / raw)
  To: Luiz Augusto von Dentz; +Cc: BlueZ development
In-Reply-To: <BANLkTinBw-qXODF03rtcW+M3GEjK7yC3NQ@mail.gmail.com>

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

On Fri, 2011-05-06 at 10:52 +0300, Luiz Augusto von Dentz wrote:
> Hi Bastien,
> 
> On Thu, May 5, 2011 at 9:43 PM, Bastien Nocera <hadess@hadess.net> wrote:
> > So that bluez compiles with -Werror.
> >
> > Cheers
> >

Updated patch attached. Only comment left is the "unused" attribute.

[-- Attachment #2: 0001-Fix-set-but-not-unused-variable-GCC-4.6-warnings.patch --]
[-- Type: text/x-patch, Size: 17420 bytes --]

>From 1816c686e1e411ec574c6f168dac43e0ff4d6bd1 Mon Sep 17 00:00:00 2001
From: Bastien Nocera <hadess@hadess.net>
Date: Thu, 5 May 2011 19:41:38 +0100
Subject: [PATCH] Fix "set but not unused variable" GCC 4.6 warnings

---
 attrib/gatt.c         |    4 ----
 audio/a2dp.c          |    3 ---
 audio/manager.c       |    2 --
 audio/pcm_bluetooth.c |    4 ++--
 btio/btio.c           |    5 +++++
 compat/fakehid.c      |    6 ++++--
 cups/hcrp.c           |   12 ++++++++++++
 gdbus/object.c        |    3 +--
 input/device.c        |    2 +-
 input/server.c        |    3 ++-
 lib/sdp.c             |    2 +-
 network/common.c      |    2 +-
 plugins/hciops.c      |    4 +---
 plugins/mgmtops.c     |    4 +---
 sbc/sbcinfo.c         |    2 +-
 src/adapter.c         |    6 ------
 src/sdp-xml.c         |    4 ----
 src/sdpd-request.c    |    2 +-
 src/textfile.c        |    8 ++++++++
 test/hciemu.c         |    6 ++++++
 test/hstest.c         |    7 ++++++-
 test/rctest.c         |    2 --
 test/scotest.c        |    2 --
 test/test-textfile.c  |    2 ++
 tools/hciattach.c     |    6 +++---
 tools/hcitool.c       |    2 --
 26 files changed, 58 insertions(+), 47 deletions(-)

diff --git a/attrib/gatt.c b/attrib/gatt.c
index 360218b..095b157 100644
--- a/attrib/gatt.c
+++ b/attrib/gatt.c
@@ -71,13 +71,11 @@ static guint16 encode_discover_primary(uint16_t start, uint16_t end,
 {
 	bt_uuid_t prim;
 	guint16 plen;
-	uint8_t op;
 
 	bt_uuid16_create(&prim, GATT_PRIM_SVC_UUID);
 
 	if (uuid == NULL) {
 		/* Discover all primary services */
-		op = ATT_OP_READ_BY_GROUP_REQ;
 		plen = enc_read_by_grp_req(start, end, &prim, pdu, len);
 	} else {
 		uint16_t u16;
@@ -86,8 +84,6 @@ static guint16 encode_discover_primary(uint16_t start, uint16_t end,
 		int vlen;
 
 		/* Discover primary service by service UUID */
-		op = ATT_OP_FIND_BY_TYPE_REQ;
-
 		if (uuid->type == BT_UUID16) {
 			u16 = htobs(uuid->value.u16);
 			value = &u16;
diff --git a/audio/a2dp.c b/audio/a2dp.c
index 9cd7207..52acdfa 100644
--- a/audio/a2dp.c
+++ b/audio/a2dp.c
@@ -2038,7 +2038,6 @@ unsigned int a2dp_config(struct avdtp *session, struct a2dp_sep *sep,
 	struct avdtp_media_codec_capability *codec_cap = NULL;
 	int posix_err;
 	bdaddr_t src;
-	uint8_t remote_type;
 
 	avdtp_get_peers(session, &src, NULL);
 	server = find_server(servers, &src);
@@ -2085,9 +2084,7 @@ unsigned int a2dp_config(struct avdtp *session, struct a2dp_sep *sep,
 	case AVDTP_STATE_IDLE:
 		if (sep->type == AVDTP_SEP_TYPE_SOURCE) {
 			l = server->sources;
-			remote_type = AVDTP_SEP_TYPE_SINK;
 		} else {
-			remote_type = AVDTP_SEP_TYPE_SOURCE;
 			l = server->sinks;
 		}
 
diff --git a/audio/manager.c b/audio/manager.c
index 7e206be..d4ff906 100644
--- a/audio/manager.c
+++ b/audio/manager.c
@@ -562,7 +562,6 @@ static void hf_io_cb(GIOChannel *chan, gpointer data)
 	GError *err = NULL;
 	uint8_t ch;
 	const char *server_uuid, *remote_uuid;
-	uint16_t svclass;
 	struct audio_device *device;
 	int perr;
 
@@ -580,7 +579,6 @@ static void hf_io_cb(GIOChannel *chan, gpointer data)
 
 	server_uuid = HFP_AG_UUID;
 	remote_uuid = HFP_HS_UUID;
-	svclass = HANDSFREE_AGW_SVCLASS_ID;
 
 	device = manager_get_device(&src, &dst, TRUE);
 	if (!device)
diff --git a/audio/pcm_bluetooth.c b/audio/pcm_bluetooth.c
index 799f17f..2d9f178 100644
--- a/audio/pcm_bluetooth.c
+++ b/audio/pcm_bluetooth.c
@@ -820,7 +820,7 @@ static int bluetooth_playback_poll_revents(snd_pcm_ioplug_t *io,
 					unsigned short *revents)
 {
 	static char buf[1];
-	int ret;
+	int ret = 0;
 
 	DBG("");
 
@@ -838,7 +838,7 @@ static int bluetooth_playback_poll_revents(snd_pcm_ioplug_t *io,
 
 	*revents = (pfds[0].revents & POLLIN) ? POLLOUT : 0;
 
-	return 0;
+	return ret;
 }
 
 
diff --git a/btio/btio.c b/btio/btio.c
index 6d71b90..64cd8c6 100644
--- a/btio/btio.c
+++ b/btio/btio.c
@@ -884,6 +884,7 @@ static gboolean l2cap_get(int sock, GError **err, BtIOOption opt1,
 			*(va_arg(args, uint8_t *)) = l2o.mode;
 			break;
 		case BT_IO_OPT_FLUSHABLE:
+			flushable = TRUE;
 			if (l2cap_get_flushable(sock, &flushable) < 0) {
 				ERROR_FAILED(err, "get_flushable", errno);
 				return FALSE;
@@ -1135,6 +1136,10 @@ gboolean bt_io_accept(GIOChannel *io, BtIOConnect connect, gpointer user_data,
 	if (!(pfd.revents & POLLOUT)) {
 		int ret;
 		ret = read(sock, &c, 1);
+		if (ret < 0) {
+			ERROR_FAILED(err, "read", errno);
+			return FALSE;
+		}
 	}
 
 	accept_add(io, connect, user_data, destroy);
diff --git a/compat/fakehid.c b/compat/fakehid.c
index b996d10..0974d0a 100644
--- a/compat/fakehid.c
+++ b/compat/fakehid.c
@@ -60,13 +60,13 @@ static void sig_term(int sig)
 	__io_canceled = 1;
 }
 
-static void send_event(int fd, uint16_t type, uint16_t code, int32_t value)
+static int send_event(int fd, uint16_t type, uint16_t code, int32_t value)
 {
 	struct uinput_event event;
 	int len;
 
 	if (fd <= fileno(stderr))
-		return;
+		return -1;
 
 	memset(&event, 0, sizeof(event));
 	event.type = type;
@@ -74,6 +74,8 @@ static void send_event(int fd, uint16_t type, uint16_t code, int32_t value)
 	event.value = value;
 
 	len = write(fd, &event, sizeof(event));
+
+	return len;
 }
 
 static int uinput_create(char *name, int keyboard, int mouse)
diff --git a/cups/hcrp.c b/cups/hcrp.c
index 7aafcdc..ad88ff6 100644
--- a/cups/hcrp.c
+++ b/cups/hcrp.c
@@ -94,8 +94,12 @@ static int hcrp_credit_grant(int sk, uint16_t tid, uint32_t credit)
 	memcpy(buf, &hdr, HCRP_PDU_HDR_SIZE);
 	memcpy(buf + HCRP_PDU_HDR_SIZE, &cp, HCRP_CREDIT_GRANT_CP_SIZE);
 	len = write(sk, buf, HCRP_PDU_HDR_SIZE + HCRP_CREDIT_GRANT_CP_SIZE);
+	if (len < 0)
+		return -1;
 
 	len = read(sk, buf, sizeof(buf));
+	if (len < 0)
+		return -1;
 	memcpy(&hdr, buf, HCRP_PDU_HDR_SIZE);
 	memcpy(&rp, buf + HCRP_PDU_HDR_SIZE, HCRP_CREDIT_GRANT_RP_SIZE);
 
@@ -119,8 +123,12 @@ static int hcrp_credit_request(int sk, uint16_t tid, uint32_t *credit)
 	hdr.plen = htons(0);
 	memcpy(buf, &hdr, HCRP_PDU_HDR_SIZE);
 	len = write(sk, buf, HCRP_PDU_HDR_SIZE);
+	if (len < 0)
+		return -1;
 
 	len = read(sk, buf, sizeof(buf));
+	if (len < 0)
+		return -1;
 	memcpy(&hdr, buf, HCRP_PDU_HDR_SIZE);
 	memcpy(&rp, buf + HCRP_PDU_HDR_SIZE, HCRP_CREDIT_REQUEST_RP_SIZE);
 
@@ -147,8 +155,12 @@ static int hcrp_get_lpt_status(int sk, uint16_t tid, uint8_t *lpt_status)
 	hdr.plen = htons(0);
 	memcpy(buf, &hdr, HCRP_PDU_HDR_SIZE);
 	len = write(sk, buf, HCRP_PDU_HDR_SIZE);
+	if (len < 0)
+		return -1;
 
 	len = read(sk, buf, sizeof(buf));
+	if (len < 0)
+		return -1;
 	memcpy(&hdr, buf, HCRP_PDU_HDR_SIZE);
 	memcpy(&rp, buf + HCRP_PDU_HDR_SIZE, HCRP_GET_LPT_STATUS_RP_SIZE);
 
diff --git a/gdbus/object.c b/gdbus/object.c
index eaa2e1a..d17a101 100644
--- a/gdbus/object.c
+++ b/gdbus/object.c
@@ -255,14 +255,13 @@ void g_dbus_pending_success(DBusConnection *connection,
 
         for (list = pending_security; list; list = list->next) {
 		struct security_data *secdata = list->data;
-		DBusHandlerResult result;
 
 		if (secdata->pending != pending)
 			continue;
 
 		pending_security = g_slist_remove(pending_security, secdata);
 
-		result = process_message(connection, secdata->message,
+		process_message(connection, secdata->message,
 				secdata->method, secdata->iface_user_data);
 
 		dbus_message_unref(secdata->message);
diff --git a/input/device.c b/input/device.c
index 554f5ac..550e1c7 100644
--- a/input/device.c
+++ b/input/device.c
@@ -250,7 +250,7 @@ static int decode_key(const char *str)
 static void send_event(int fd, uint16_t type, uint16_t code, int32_t value)
 {
 	struct uinput_event event;
-	int err;
+	int __attribute__((__unused__)) err;
 
 	memset(&event, 0, sizeof(event));
 	event.type	= type;
diff --git a/input/server.c b/input/server.c
index d98018b..15bf5b3 100644
--- a/input/server.c
+++ b/input/server.c
@@ -91,7 +91,8 @@ static void connect_event_cb(GIOChannel *chan, GError *err, gpointer data)
 	/* Send unplug virtual cable to unknown devices */
 	if (ret == -ENOENT && psm == L2CAP_PSM_HIDP_CTRL) {
 		unsigned char unplug = 0x15;
-		int err, sk = g_io_channel_unix_get_fd(chan);
+		int __attribute__((__unused__)) err;
+		int sk = g_io_channel_unix_get_fd(chan);
 		err = write(sk, &unplug, sizeof(unplug));
 	}
 
diff --git a/lib/sdp.c b/lib/sdp.c
index d24d1e2..d852587 100644
--- a/lib/sdp.c
+++ b/lib/sdp.c
@@ -3319,7 +3319,7 @@ int sdp_service_search_req(sdp_session_t *session, const sdp_list_t *search,
 	uint32_t reqsize = 0, _reqsize;
 	uint32_t rspsize = 0, rsplen;
 	int seqlen = 0;
-	int total_rec_count, rec_count;
+	int __attribute__((__unused__)) total_rec_count, rec_count;
 	unsigned scanned, pdata_len;
 	uint8_t *pdata, *_pdata;
 	uint8_t *reqbuf, *rspbuf;
diff --git a/network/common.c b/network/common.c
index ef72679..38d2c49 100644
--- a/network/common.c
+++ b/network/common.c
@@ -215,7 +215,7 @@ int bnep_if_up(const char *devname)
 int bnep_if_down(const char *devname)
 {
 	struct ifreq ifr;
-	int sk, err;
+	int sk, __attribute__((__unused__)) err;
 
 	sk = socket(AF_INET, SOCK_DGRAM, 0);
 
diff --git a/plugins/hciops.c b/plugins/hciops.c
index 2c49e35..49dd48d 100644
--- a/plugins/hciops.c
+++ b/plugins/hciops.c
@@ -2754,7 +2754,7 @@ static void init_conn_list(int index)
 	struct dev_info *dev = &devs[index];
 	struct hci_conn_list_req *cl;
 	struct hci_conn_info *ci;
-	int err, i;
+	int i;
 
 	DBG("hci%d", index);
 
@@ -2780,8 +2780,6 @@ static void init_conn_list(int index)
 		conn->handle = ci->handle;
 	}
 
-	err = 0;
-
 failed:
 	g_free(cl);
 }
diff --git a/plugins/mgmtops.c b/plugins/mgmtops.c
index 9e1cfac..b831044 100644
--- a/plugins/mgmtops.c
+++ b/plugins/mgmtops.c
@@ -207,7 +207,7 @@ static int mgmt_update_powered(int index, uint8_t powered)
 {
 	struct controller_info *info;
 	struct btd_adapter *adapter;
-	gboolean pairable, discoverable;
+	gboolean pairable;
 	uint8_t on_mode;
 
 	if (index > max_index) {
@@ -238,8 +238,6 @@ static int mgmt_update_powered(int index, uint8_t powered)
 
 	btd_adapter_get_mode(adapter, NULL, &on_mode, &pairable);
 
-	discoverable = (on_mode == MODE_DISCOVERABLE);
-
 	if (on_mode == MODE_DISCOVERABLE && !info->discoverable)
 		mgmt_set_discoverable(index, TRUE);
 	else if (on_mode == MODE_CONNECTABLE && !info->connectable)
diff --git a/sbc/sbcinfo.c b/sbc/sbcinfo.c
index 6d92679..63f05aa 100644
--- a/sbc/sbcinfo.c
+++ b/sbc/sbcinfo.c
@@ -281,7 +281,7 @@ static int analyze_file(char *filename)
 	printf("Subbands\t\t%d\n", subbands);
 	printf("Block length\t\t%d\n", blocks);
 	printf("Sampling frequency\t%s\n", freq2str(freq));
-	printf("Channel mode\t\t%s\n", mode2str(hdr.channel_mode));
+	printf("Channel mode\t\t%s\n", mode2str(mode));
 	printf("Allocation method\t%s\n", method ? "SNR" : "Loudness");
 	printf("Bitpool\t\t\t%d", bitpool[0]);
 	for (n = 1; n < SIZE; n++)
diff --git a/src/adapter.c b/src/adapter.c
index f068335..76fc01b 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -476,13 +476,10 @@ static int set_mode(struct btd_adapter *adapter, uint8_t new_mode,
 {
 	int err;
 	const char *modestr;
-	gboolean discoverable;
 
 	if (adapter->pending_mode != NULL)
 		return -EALREADY;
 
-	discoverable = new_mode == MODE_DISCOVERABLE;
-
 	if (!adapter->up && new_mode != MODE_OFF) {
 		err = adapter_ops->set_powered(adapter->dev_id, TRUE);
 		if (err < 0)
@@ -3405,7 +3402,6 @@ gboolean adapter_powering_down(struct btd_adapter *adapter)
 int btd_adapter_restore_powered(struct btd_adapter *adapter)
 {
 	char mode[14], address[18];
-	gboolean discoverable;
 
 	if (!adapter_ops)
 		return -EINVAL;
@@ -3421,8 +3417,6 @@ int btd_adapter_restore_powered(struct btd_adapter *adapter)
 						g_str_equal(mode, "off"))
 		return 0;
 
-	discoverable = get_mode(&adapter->bdaddr, mode) == MODE_DISCOVERABLE;
-
 	return adapter_ops->set_powered(adapter->dev_id, TRUE);
 }
 
diff --git a/src/sdp-xml.c b/src/sdp-xml.c
index 3aa9df0..62226cc 100644
--- a/src/sdp-xml.c
+++ b/src/sdp-xml.c
@@ -47,7 +47,6 @@ static void convert_raw_data_to_xml(sdp_data_t *value, int indent_level,
 	int i, hex;
 	char buf[STRBUFSIZE];
 	char indent[MAXINDENT];
-	char next_indent[MAXINDENT];
 
 	if (!value)
 		return;
@@ -57,12 +56,9 @@ static void convert_raw_data_to_xml(sdp_data_t *value, int indent_level,
 
 	for (i = 0; i < indent_level; i++) {
 		indent[i] = '\t';
-		next_indent[i] = '\t';
 	}
 
 	indent[i] = '\0';
-	next_indent[i] = '\t';
-	next_indent[i + 1] = '\0';
 
 	buf[STRBUFSIZE - 1] = '\0';
 
diff --git a/src/sdpd-request.c b/src/sdpd-request.c
index 1722f78..287acc2 100644
--- a/src/sdpd-request.c
+++ b/src/sdpd-request.c
@@ -962,7 +962,7 @@ static void process_request(sdp_req_t *req)
 	sdp_pdu_hdr_t *rsphdr;
 	sdp_buf_t rsp;
 	uint8_t *buf = malloc(USHRT_MAX);
-	int sent = 0;
+	int __attribute__((__unused__)) sent = 0;
 	int status = SDP_INVALID_SYNTAX;
 
 	memset(buf, 0, USHRT_MAX);
diff --git a/src/textfile.c b/src/textfile.c
index d115ff6..2645f9a 100644
--- a/src/textfile.c
+++ b/src/textfile.c
@@ -204,6 +204,10 @@ static int write_key(const char *pathname, const char *key, const char *value, i
 	if (!size) {
 		if (value) {
 			pos = lseek(fd, size, SEEK_SET);
+			if (pos == (off_t) -1) {
+				err = errno;
+				goto unlock;
+			}
 			err = write_key_value(fd, key, value);
 		}
 		goto unlock;
@@ -222,6 +226,10 @@ static int write_key(const char *pathname, const char *key, const char *value, i
 		if (value) {
 			munmap(map, size);
 			pos = lseek(fd, size, SEEK_SET);
+			if (pos == (off_t) -1) {
+				err = errno;
+				goto unlock;
+			}
 			err = write_key_value(fd, key, value);
 		}
 		goto unlock;
diff --git a/test/hciemu.c b/test/hciemu.c
index 66f99a9..27e8275 100644
--- a/test/hciemu.c
+++ b/test/hciemu.c
@@ -222,7 +222,11 @@ static int write_snoop(int fd, int type, int incoming, unsigned char *buf, int l
 		pkt.flags |= ntohl(0x02);
 
 	err = write(fd, &pkt, BTSNOOP_PKT_SIZE);
+	if (err < 0)
+		return -1;
 	err = write(fd, buf, size);
+	if (err < 0)
+		return -1;
 
 	return 0;
 }
@@ -899,6 +903,8 @@ static gboolean io_acl_data(GIOChannel *chan, GIOCondition cond, gpointer data)
 	write_snoop(vdev.dd, HCI_ACLDATA_PKT, 1, buf, len);
 
 	err = write(vdev.fd, buf, len);
+	if (err < 0)
+		return FALSE;
 
 	return TRUE;
 }
diff --git a/test/hstest.c b/test/hstest.c
index 08f2257..07124c1 100644
--- a/test/hstest.c
+++ b/test/hstest.c
@@ -244,8 +244,13 @@ int main(int argc, char *argv[])
 
 	fprintf(stderr, "SCO audio channel connected (handle %d, mtu %d)\n", sco_handle, sco_mtu);
 
-	if (mode == RECORD)
+	if (mode == RECORD) {
 		err = write(rd, "RING\r\n", 6);
+		if (err < 0) {
+			perror("Can't write \"RING\"");
+			return -1;
+		}
+	}
 
 	maxfd = (rd > sd) ? rd : sd;
 
diff --git a/test/rctest.c b/test/rctest.c
index b3804f5..9754f52 100644
--- a/test/rctest.c
+++ b/test/rctest.c
@@ -417,13 +417,11 @@ static void recv_mode(int sk)
 	struct timeval tv_beg, tv_end, tv_diff;
 	char ts[30];
 	long total;
-	uint32_t seq;
 
 	syslog(LOG_INFO, "Receiving ...");
 
 	memset(ts, 0, sizeof(ts));
 
-	seq = 0;
 	while (1) {
 		gettimeofday(&tv_beg,NULL);
 		total = 0;
diff --git a/test/scotest.c b/test/scotest.c
index 50b622a..17bd8a6 100644
--- a/test/scotest.c
+++ b/test/scotest.c
@@ -216,11 +216,9 @@ static void recv_mode(int sk)
 {
 	struct timeval tv_beg,tv_end,tv_diff;
 	long total;
-	uint32_t seq;
 
 	syslog(LOG_INFO, "Receiving ...");
 
-	seq = 0;
 	while (1) {
 		gettimeofday(&tv_beg, NULL);
 		total = 0;
diff --git a/test/test-textfile.c b/test/test-textfile.c
index 970e9e7..0786022 100644
--- a/test/test-textfile.c
+++ b/test/test-textfile.c
@@ -51,6 +51,8 @@ int main(int argc, char *argv[])
 
 	fd = creat(filename, 0644);
 	err = ftruncate(fd, 0);
+	if (err < 0)
+		fprintf(stderr, "%s (%d)\n", strerror(errno), errno);
 
 	memset(value, 0, sizeof(value));
 	for (i = 0; i < (size / sizeof(value)); i++)
diff --git a/tools/hciattach.c b/tools/hciattach.c
index e4d5aa1..bc56f31 100644
--- a/tools/hciattach.c
+++ b/tools/hciattach.c
@@ -351,7 +351,7 @@ static int bcsp_max_retries = 10;
 static void bcsp_tshy_sig_alarm(int sig)
 {
 	unsigned char bcsp_sync_pkt[10] = {0xc0,0x00,0x41,0x00,0xbe,0xda,0xdc,0xed,0xed,0xc0};
-	int len;
+	int __attribute__((__unused__)) len;
 	static int retries = 0;
 
 	if (retries < bcsp_max_retries) {
@@ -369,7 +369,7 @@ static void bcsp_tshy_sig_alarm(int sig)
 static void bcsp_tconf_sig_alarm(int sig)
 {
 	unsigned char bcsp_conf_pkt[10] = {0xc0,0x00,0x41,0x00,0xbe,0xad,0xef,0xac,0xed,0xc0};
-	int len;
+	int __attribute__((__unused__)) len;
 	static int retries = 0;
 
 	if (retries < bcsp_max_retries){
@@ -394,7 +394,7 @@ static int bcsp(int fd, struct uart_t *u, struct termios *ti)
 		bcspconf[4]     = {0xad,0xef,0xac,0xed},
 		bcspconfresp[4] = {0xde,0xad,0xd0,0xd0};
 	struct sigaction sa;
-	int len;
+	int __attribute__((__unused__)) len;
 
 	if (set_speed(fd, ti, u->speed) < 0) {
 		perror("Can't set default baud rate");
diff --git a/tools/hcitool.c b/tools/hcitool.c
index a117449..ece187c 100644
--- a/tools/hcitool.c
+++ b/tools/hcitool.c
@@ -2351,7 +2351,6 @@ static int print_advertising_devices(int dd, uint8_t filter_type)
 	unsigned char buf[HCI_MAX_EVENT_SIZE], *ptr;
 	struct hci_filter nf, of;
 	socklen_t olen;
-	hci_event_hdr *hdr;
 	int num, len;
 
 	olen = sizeof(of);
@@ -2382,7 +2381,6 @@ static int print_advertising_devices(int dd, uint8_t filter_type)
 			goto done;
 		}
 
-		hdr = (void *) (buf + 1);
 		ptr = buf + (1 + HCI_EVENT_HDR_SIZE);
 		len -= (1 + HCI_EVENT_HDR_SIZE);
 
-- 
1.7.5


^ permalink raw reply related

* Re: Warning fixes for GCC 4.6
From: Bastien Nocera @ 2011-05-06 14:48 UTC (permalink / raw)
  To: Luiz Augusto von Dentz; +Cc: BlueZ development
In-Reply-To: <BANLkTinBw-qXODF03rtcW+M3GEjK7yC3NQ@mail.gmail.com>

On Fri, 2011-05-06 at 10:52 +0300, Luiz Augusto von Dentz wrote:
> Hi Bastien,
> 
> On Thu, May 5, 2011 at 9:43 PM, Bastien Nocera <hadess@hadess.net> wrote:
> > So that bluez compiles with -Werror.
> >
> > Cheers
> >
> 
> diff --git a/attrib/gatt.c b/attrib/gatt.c
> index 360218b..61c9ed1 100644
> --- a/attrib/gatt.c
> +++ b/attrib/gatt.c
> @@ -71,13 +71,12 @@ static guint16 encode_discover_primary(uint16_t
> start, uint16_t end,
>  {
>  	bt_uuid_t prim;
>  	guint16 plen;
> -	uint8_t op;
> 
>  	bt_uuid16_create(&prim, GATT_PRIM_SVC_UUID);
> 
>  	if (uuid == NULL) {
> -		/* Discover all primary services */
> -		op = ATT_OP_READ_BY_GROUP_REQ;
> +		/* Discover all primary services
> +		   op = ATT_OP_READ_BY_GROUP_REQ; */
>  		plen = enc_read_by_grp_req(start, end, &prim, pdu, len);
>  	} else {
>  		uint16_t u16;
> 
> I guess we don't need the comments as enc_read_by_grp_req already
> should already do what ATT_OP_READ_BY_GROUP_REQ was meant.

I'll remove those.

> @@ -2085,9 +2084,9 @@ unsigned int a2dp_config(struct avdtp *session,
> struct a2dp_sep *sep,
>  	case AVDTP_STATE_IDLE:
>  		if (sep->type == AVDTP_SEP_TYPE_SOURCE) {
>  			l = server->sources;
> -			remote_type = AVDTP_SEP_TYPE_SINK;
> +			/* remote_type = AVDTP_SEP_TYPE_SINK; */
>  		} else {
> -			remote_type = AVDTP_SEP_TYPE_SOURCE;
> +			/* remote_type = AVDTP_SEP_TYPE_SOURCE; */
>  			l = server->sinks;
>  		}
> 
> Same here, avdtp_find_remote_sep already take care of finding a match
> so remote_type is useless.

Ditto.

> @@ -580,7 +579,7 @@ static void hf_io_cb(GIOChannel *chan, gpointer data)
> 
>  	server_uuid = HFP_AG_UUID;
>  	remote_uuid = HFP_HS_UUID;
> -	svclass = HANDSFREE_AGW_SVCLASS_ID;
> +	/* svclass = HANDSFREE_AGW_SVCLASS_ID; */
> 
>  	device = manager_get_device(&src, &dst, TRUE);
>  	if (!device)
> 
> Since introduced this variable was never really used, I guess it is
> safe to remove it completely too.

OK.

> @@ -1135,6 +1136,10 @@ gboolean bt_io_accept(GIOChannel *io,
> BtIOConnect connect, gpointer user_data,
>  	if (!(pfd.revents & POLLOUT)) {
>  		int ret;
>  		ret = read(sock, &c, 1);
> +		if (ret == -1) {
> +			ERROR_FAILED(err, "read", errno);
> +			return FALSE;
> +		}
>  	}
> 
> We normally use < 0, but I guess it doesn't make any difference since
> errno is actually what we should be looking for.

I'll make the change.

> @@ -94,8 +94,12 @@ static int hcrp_credit_grant(int sk, uint16_t tid,
> uint32_t credit)
>  	memcpy(buf, &hdr, HCRP_PDU_HDR_SIZE);
>  	memcpy(buf + HCRP_PDU_HDR_SIZE, &cp, HCRP_CREDIT_GRANT_CP_SIZE);
>  	len = write(sk, buf, HCRP_PDU_HDR_SIZE + HCRP_CREDIT_GRANT_CP_SIZE);
> +	if (len == -1)
> +		return -1;
> 
>  	len = read(sk, buf, sizeof(buf));
> +	if (len == -1)
> +		return -1;
>  	memcpy(&hdr, buf, HCRP_PDU_HDR_SIZE);
>  	memcpy(&rp, buf + HCRP_PDU_HDR_SIZE, HCRP_CREDIT_GRANT_RP_SIZE);
> 
> @@ -119,8 +123,12 @@ static int hcrp_credit_request(int sk, uint16_t
> tid, uint32_t *credit)
>  	hdr.plen = htons(0);
>  	memcpy(buf, &hdr, HCRP_PDU_HDR_SIZE);
>  	len = write(sk, buf, HCRP_PDU_HDR_SIZE);
> +	if (len == -1)
> +		return -1;
> 
>  	len = read(sk, buf, sizeof(buf));
> +	if (len == -1)
> +		return -1;
>  	memcpy(&hdr, buf, HCRP_PDU_HDR_SIZE);
>  	memcpy(&rp, buf + HCRP_PDU_HDR_SIZE, HCRP_CREDIT_REQUEST_RP_SIZE);
> 
> @@ -147,8 +155,12 @@ static int hcrp_get_lpt_status(int sk, uint16_t
> tid, uint8_t *lpt_status)
>  	hdr.plen = htons(0);
>  	memcpy(buf, &hdr, HCRP_PDU_HDR_SIZE);
>  	len = write(sk, buf, HCRP_PDU_HDR_SIZE);
> +	if (len == -1)
> +		return -1;
> 
>  	len = read(sk, buf, sizeof(buf));
> +	if (len == -1)
> +		return -1;
>  	memcpy(&hdr, buf, HCRP_PDU_HDR_SIZE);
>  	memcpy(&rp, buf + HCRP_PDU_HDR_SIZE, HCRP_GET_LPT_STATUS_RP_SIZE);
> 
> Same here.

Yep.

> @@ -250,7 +250,7 @@ static int decode_key(const char *str)
>  static void send_event(int fd, uint16_t type, uint16_t code, int32_t value)
>  {
>  	struct uinput_event event;
> -	int err;
> +	int __attribute__((__unused__)) err;
> 
>  	memset(&event, 0, sizeof(event));
>  	event.type	= type;
> 
> Can't we just removed err here, Im afraid using
> __attribute__((__unused__)) is not a good practice and we should try
> to avoid using it.

We either get a warning that the return value is unused, or that we
should be checking the return value. Which one do you prefer?


^ permalink raw reply

* [PATCH 2/2] client: add support for reusing session for the same client
From: Luiz Augusto von Dentz @ 2011-05-06 10:43 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1304678639-31853-1-git-send-email-luiz.dentz@gmail.com>

From: Luiz Augusto von Dentz <luiz.dentz-von@nokia.com>

If the a client owning a session attempt to send a new file just reuse
the same session instead of trying to connect again.
---
 client/session.c |   54 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 52 insertions(+), 2 deletions(-)

diff --git a/client/session.c b/client/session.c
index 8c41858..9ff906c 100644
--- a/client/session.c
+++ b/client/session.c
@@ -87,6 +87,8 @@ struct agent_data {
 	struct pending_data *pending;
 };
 
+static GSList *sessions = NULL;
+
 static void session_prepare_put(struct session_data *session, GError *err,
 								void *data);
 static void session_terminate_transfer(struct session_data *session,
@@ -199,6 +201,8 @@ static void session_free(struct session_data *session)
 		dbus_connection_unref(session->conn);
 	}
 
+	sessions = g_slist_remove(sessions, session);
+
 	g_free(session->callback);
 	g_free(session->path);
 	g_free(session->owner);
@@ -246,6 +250,8 @@ static void rfcomm_callback(GIOChannel *io, GError *err, gpointer user_data)
 
 	session->obex = obex;
 
+	sessions = g_slist_prepend(sessions, session);
+
 done:
 	callback->func(callback->session, err, callback->data);
 
@@ -488,6 +494,43 @@ int session_set_owner(struct session_data *session, const char *name,
 	return 0;
 }
 
+static struct session_data *session_find(const char *source,
+						const char *destination,
+						const char *service,
+						uint8_t channel,
+						const char *owner)
+{
+	GSList *l;
+
+	for (l = sessions; l; l = l->next) {
+		struct session_data *session = l->data;
+		bdaddr_t adr;
+
+		if (source) {
+			str2ba(source, &adr);
+			if (bacmp(&session->src, &adr))
+				continue;
+		}
+
+		str2ba(destination, &adr);
+		if (bacmp(&session->dst, &adr))
+			continue;
+
+		if (g_strcmp0(service, session->service))
+			continue;
+
+		if (channel && session->channel != channel)
+			continue;
+
+		if (g_strcmp0(owner, session->owner))
+			continue;
+
+		return session;
+	}
+
+	return NULL;
+}
+
 struct session_data *session_create(const char *source,
 						const char *destination,
 						const char *service,
@@ -503,6 +546,12 @@ struct session_data *session_create(const char *source,
 	if (destination == NULL)
 		return NULL;
 
+	session = session_find(source, destination, service, channel, owner);
+	if (session) {
+		session_ref(session);
+		goto proceed;
+	}
+
 	session = g_try_malloc0(sizeof(*session));
 	if (session == NULL)
 		return NULL;
@@ -544,9 +593,10 @@ struct session_data *session_create(const char *source,
 		return NULL;
 	}
 
+proceed:
 	callback = g_try_malloc0(sizeof(*callback));
 	if (callback == NULL) {
-		session_free(session);
+		session_unref(session);
 		return NULL;
 	}
 
@@ -570,7 +620,7 @@ struct session_data *session_create(const char *source,
 	}
 
 	if (err < 0) {
-		session_free(session);
+		session_unref(session);
 		g_free(callback);
 		return NULL;
 	}
-- 
1.7.1


^ permalink raw reply related

* [PATCH 1/2] client: fix not canceling connection request if client exit bus
From: Luiz Augusto von Dentz @ 2011-05-06 10:43 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.dentz-von@nokia.com>

There is no point on proceeding with sdp/rfcomm connections if client
exit the bus.
---
 client/main.c    |   23 +++++----
 client/session.c |  144 ++++++++++++++++++++++++++++++++++++------------------
 client/session.h |   10 +++-
 3 files changed, 115 insertions(+), 62 deletions(-)

diff --git a/client/main.c b/client/main.c
index 20d56d2..478181c 100644
--- a/client/main.c
+++ b/client/main.c
@@ -86,6 +86,7 @@ static void create_callback(struct session_data *session, GError *err,
 	if (session->target != NULL) {
 		session_register(session);
 		session_set_owner(session, data->sender, owner_exit);
+
 		g_dbus_send_reply(data->connection, data->message,
 				DBUS_TYPE_OBJECT_PATH, &session->path,
 				DBUS_TYPE_INVALID);
@@ -165,6 +166,7 @@ static DBusMessage *send_files(DBusConnection *connection,
 	GPtrArray *files;
 	struct send_data *data;
 	const char *agent, *source = NULL, *dest = NULL, *target = NULL;
+	const char *sender;
 	uint8_t channel = 0;
 
 	dbus_message_iter_init(message, &iter);
@@ -201,6 +203,8 @@ static DBusMessage *send_files(DBusConnection *connection,
 				"org.openobex.Error.InvalidArguments", NULL);
 	}
 
+	sender = dbus_message_get_sender(message);
+
 	data = g_try_malloc0(sizeof(*data));
 	if (data == NULL) {
 		g_ptr_array_free(files, TRUE);
@@ -210,12 +214,12 @@ static DBusMessage *send_files(DBusConnection *connection,
 
 	data->connection = dbus_connection_ref(connection);
 	data->message = dbus_message_ref(message);
-	data->sender = g_strdup(dbus_message_get_sender(message));
+	data->sender = g_strdup(sender);
 	data->agent = g_strdup(agent);
 	data->files = files;
 
-	session = session_create(source, dest, "OPP", channel, create_callback,
-				data);
+	session = session_create(source, dest, "OPP", channel, sender,
+							create_callback, data);
 	if (session != NULL) {
 		sessions = g_slist_append(sessions, session);
 		return NULL;
@@ -269,8 +273,6 @@ static void pull_session_callback(struct session_data *session,
 		goto done;
 	}
 
-	session_set_owner(session, data->sender, owner_exit);
-
 	session_pull(session, "text/x-vcard", data->filename,
 						pull_complete_callback, data);
 
@@ -320,7 +322,7 @@ static DBusMessage *pull_business_card(DBusConnection *connection,
 	data->sender = g_strdup(dbus_message_get_sender(message));
 	data->filename = g_strdup(name);
 
-	session = session_create(source, dest, "OPP", channel,
+	session = session_create(source, dest, "OPP", channel, data->sender,
 					pull_session_callback, data);
 	if (session != NULL) {
 		sessions = g_slist_append(sessions, session);
@@ -382,8 +384,8 @@ static DBusMessage *create_session(DBusConnection *connection,
 	data->message = dbus_message_ref(message);
 	data->sender = g_strdup(dbus_message_get_sender(message));
 
-	session = session_create(source, dest, target, channel,
-					create_callback, data);
+	session = session_create(source, dest, target, channel, data->sender,
+							create_callback, data);
 	if (session != NULL) {
 		sessions = g_slist_append(sessions, session);
 		return NULL;
@@ -471,7 +473,6 @@ static void capability_session_callback(struct session_data *session,
 		goto done;
 	}
 
-	session_set_owner(session, data->sender, owner_exit);
 	session_pull(session, "x-obex/capability", NULL,
 				capabilities_complete_callback, data);
 
@@ -513,8 +514,8 @@ static DBusMessage *get_capabilities(DBusConnection *connection,
 	if (!target)
 		target = "OPP";
 
-	session = session_create(source, dest, target, channel,
-				capability_session_callback, data);
+	session = session_create(source, dest, target, channel, data->sender,
+					capability_session_callback, data);
 	if (session != NULL) {
 		sessions = g_slist_append(sessions, session);
 		return NULL;
diff --git a/client/session.c b/client/session.c
index 88eae8d..8c41858 100644
--- a/client/session.c
+++ b/client/session.c
@@ -169,6 +169,9 @@ static void session_unregistered(struct session_data *session)
 					SESSION_INTERFACE);
 
 	DBG("Session(%p) unregistered %s", session, session->path);
+
+	g_free(session->path);
+	session->path = NULL;
 }
 
 static void session_free(struct session_data *session)
@@ -199,6 +202,7 @@ static void session_free(struct session_data *session)
 	g_free(session->callback);
 	g_free(session->path);
 	g_free(session->owner);
+	g_free(session->service);
 	g_free(session);
 }
 
@@ -223,6 +227,8 @@ static void rfcomm_callback(GIOChannel *io, GError *err, gpointer user_data)
 	GwObex *obex;
 	int fd;
 
+	DBG("");
+
 	if (err != NULL) {
 		error("%s", err->message);
 		goto done;
@@ -255,6 +261,8 @@ static GIOChannel *rfcomm_connect(const bdaddr_t *src, const bdaddr_t *dst,
 	GIOChannel *io;
 	GError *err = NULL;
 
+	DBG("");
+
 	io = bt_io_connect(BT_IO_RFCOMM, function, user_data, NULL, &err,
 				BT_IO_OPT_SOURCE_BDADDR, src,
 				BT_IO_OPT_DEST_BDADDR, dst,
@@ -273,6 +281,7 @@ static void search_callback(uint8_t type, uint16_t status,
 			uint8_t *rsp, size_t size, void *user_data)
 {
 	struct callback_data *callback = user_data;
+	struct session_data *session = callback->session;
 	unsigned int scanned, bytesleft = size;
 	int seqlen = 0;
 	uint8_t dataType, channel = 0;
@@ -325,23 +334,26 @@ static void search_callback(uint8_t type, uint16_t status,
 	if (channel == 0)
 		goto failed;
 
-	callback->session->channel = channel;
+	session->channel = channel;
 
-	callback->session->io = rfcomm_connect(&callback->session->src,
-						&callback->session->dst,
-						channel, rfcomm_callback,
-						callback);
-	if (callback->session->io != NULL) {
+	g_io_channel_set_close_on_unref(session->io, FALSE);
+	g_io_channel_unref(session->io);
+
+	session->io = rfcomm_connect(&session->src, &session->dst, channel,
+					rfcomm_callback, callback);
+	if (session->io != NULL) {
 		sdp_close(callback->sdp);
 		return;
 	}
 
 failed:
-	sdp_close(callback->sdp);
+	g_io_channel_shutdown(session->io, TRUE, NULL);
+	g_io_channel_unref(session->io);
+	session->io = NULL;
 
 	g_set_error(&gerr, OBEX_IO_ERROR, -EIO,
 					"Unable to find service record");
-	callback->func(callback->session, gerr, callback->data);
+	callback->func(session, gerr, callback->data);
 	g_clear_error(&gerr);
 
 	session_unref(callback->session);
@@ -366,6 +378,7 @@ static gboolean service_callback(GIOChannel *io, GIOCondition cond,
 							gpointer user_data)
 {
 	struct callback_data *callback = user_data;
+	struct session_data *session = callback->session;
 	sdp_list_t *search, *attrid;
 	uint32_t range = 0x0000ffff;
 	GError *gerr = NULL;
@@ -395,7 +408,9 @@ static gboolean service_callback(GIOChannel *io, GIOCondition cond,
 	return FALSE;
 
 failed:
-	sdp_close(callback->sdp);
+	g_io_channel_shutdown(session->io, TRUE, NULL);
+	g_io_channel_unref(session->io);
+	session->io = NULL;
 
 	g_set_error(&gerr, OBEX_IO_ERROR, -EIO,
 					"Unable to find service record");
@@ -410,6 +425,7 @@ failed:
 static sdp_session_t *service_connect(const bdaddr_t *src, const bdaddr_t *dst,
 					GIOFunc function, gpointer user_data)
 {
+	struct callback_data *cb = user_data;
 	sdp_session_t *sdp;
 	GIOChannel *io;
 
@@ -426,15 +442,59 @@ static sdp_session_t *service_connect(const bdaddr_t *src, const bdaddr_t *dst,
 	g_io_add_watch(io, G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
 							function, user_data);
 
-	g_io_channel_unref(io);
+	cb->session->io = io;
 
 	return sdp;
 }
 
+static gboolean connection_complete(gpointer data)
+{
+	struct callback_data *cb = data;
+
+	cb->func(cb->session, 0, cb->data);
+
+	session_unref(cb->session);
+
+	g_free(cb);
+
+	return FALSE;
+}
+
+static void owner_disconnected(DBusConnection *connection, void *user_data)
+{
+	struct session_data *session = user_data;
+
+	DBG("");
+
+	session_shutdown(session);
+}
+
+int session_set_owner(struct session_data *session, const char *name,
+			GDBusWatchFunction func)
+{
+	if (session == NULL)
+		return -EINVAL;
+
+	if (session->watch)
+		g_dbus_remove_watch(session->conn, session->watch);
+
+	session->watch = g_dbus_add_disconnect_watch(session->conn, name, func,
+							session, NULL);
+	if (session->watch == 0)
+		return -EINVAL;
+
+	session->owner = g_strdup(name);
+
+	return 0;
+}
+
 struct session_data *session_create(const char *source,
-			const char *destination, const char *target,
-			uint8_t channel, session_callback_t function,
-			void *user_data)
+						const char *destination,
+						const char *service,
+						uint8_t channel,
+						const char *owner,
+						session_callback_t function,
+						void *user_data)
 {
 	struct session_data *session;
 	struct callback_data *callback;
@@ -462,22 +522,23 @@ struct session_data *session_create(const char *source,
 		str2ba(source, &session->src);
 
 	str2ba(destination, &session->dst);
+	session->service = g_strdup(service);
 
-	if (!g_ascii_strncasecmp(target, "OPP", 3)) {
+	if (!g_ascii_strncasecmp(service, "OPP", 3)) {
 		sdp_uuid16_create(&session->uuid, OBEX_OBJPUSH_SVCLASS_ID);
-	} else if (!g_ascii_strncasecmp(target, "FTP", 3)) {
+	} else if (!g_ascii_strncasecmp(service, "FTP", 3)) {
 		sdp_uuid16_create(&session->uuid, OBEX_FILETRANS_SVCLASS_ID);
 		session->target = OBEX_FTP_UUID;
 		session->target_len = OBEX_FTP_UUID_LEN;
-	} else if (!g_ascii_strncasecmp(target, "PBAP", 4)) {
+	} else if (!g_ascii_strncasecmp(service, "PBAP", 4)) {
 		sdp_uuid16_create(&session->uuid, PBAP_PSE_SVCLASS_ID);
 		session->target = OBEX_PBAP_UUID;
 		session->target_len = OBEX_PBAP_UUID_LEN;
-	} else if (!g_ascii_strncasecmp(target, "SYNC", 4)) {
+	} else if (!g_ascii_strncasecmp(service, "SYNC", 4)) {
 		sdp_uuid16_create(&session->uuid, IRMC_SYNC_SVCLASS_ID);
 		session->target = OBEX_SYNC_UUID;
 		session->target_len = OBEX_SYNC_UUID_LEN;
-	} else if (!g_ascii_strncasecmp(target, "PCSUITE", 7)) {
+	} else if (!g_ascii_strncasecmp(service, "PCSUITE", 7)) {
 		sdp_uuid128_create(&session->uuid, pcsuite_uuid);
 	} else {
 		return NULL;
@@ -493,7 +554,10 @@ struct session_data *session_create(const char *source,
 	callback->func = function;
 	callback->data = user_data;
 
-	if (session->channel > 0) {
+	if (session->obex) {
+		g_idle_add(connection_complete, callback);
+		err = 0;
+	} else if (session->channel > 0) {
 		session->io = rfcomm_connect(&session->src, &session->dst,
 							session->channel,
 							rfcomm_callback,
@@ -511,21 +575,31 @@ struct session_data *session_create(const char *source,
 		return NULL;
 	}
 
+	if (owner)
+		session_set_owner(session, owner, owner_disconnected);
+
 	return session;
 }
 
 void session_shutdown(struct session_data *session)
 {
-	struct transfer_data *transfer;
-
 	DBG("%p", session);
-	transfer = session->pending ? session->pending->data : NULL;
 
 	session_ref(session);
 
 	/* Unregister any pending transfer */
 	g_slist_foreach(session->pending, (GFunc) transfer_unregister, NULL);
 
+	/* Unregister interfaces */
+	if (session->path)
+		session_unregistered(session);
+
+	/* Shutdown io */
+	if (session->io) {
+		int fd = g_io_channel_unix_get_fd(session->io);
+		shutdown(fd, SHUT_RDWR);
+	}
+
 	session_unref(session);
 }
 
@@ -589,13 +663,6 @@ static DBusMessage *release_agent(DBusConnection *connection,
 	return dbus_message_new_method_return(message);
 }
 
-static void owner_disconnected(DBusConnection *connection, void *user_data)
-{
-	struct session_data *session = user_data;
-
-	session_shutdown(session);
-}
-
 static void append_entry(DBusMessageIter *dict,
 				const char *key, int type, void *val)
 {
@@ -1469,25 +1536,6 @@ const char *session_get_agent(struct session_data *session)
 	return agent->name;
 }
 
-int session_set_owner(struct session_data *session, const char *name,
-			GDBusWatchFunction func)
-{
-	if (session == NULL)
-		return -EINVAL;
-
-	if (session->watch != 0)
-		return -EALREADY;
-
-	session->watch = g_dbus_add_disconnect_watch(session->conn, name, func,
-							session, NULL);
-	if (session->watch == 0)
-		return -EINVAL;
-
-	session->owner = g_strdup(name);
-
-	return 0;
-}
-
 const char *session_get_owner(struct session_data *session)
 {
 	if (session == NULL)
diff --git a/client/session.h b/client/session.h
index 546849e..6f8a434 100644
--- a/client/session.h
+++ b/client/session.h
@@ -36,6 +36,7 @@ struct session_data {
 	bdaddr_t src;
 	bdaddr_t dst;
 	uint8_t channel;
+	char *service;		/* Service friendly name */
 	const char *target;	/* OBEX Target UUID */
 	int target_len;
 	uuid_t uuid;		/* Bluetooth Service Class */
@@ -56,9 +57,12 @@ typedef void (*session_callback_t) (struct session_data *session,
 					GError *err, void *user_data);
 
 struct session_data *session_create(const char *source,
-			const char *destination, const char *target,
-			uint8_t channel, session_callback_t function,
-			void *user_data);
+						const char *destination,
+						const char *service,
+						uint8_t channel,
+						const char *owner,
+						session_callback_t function,
+						void *user_data);
 
 struct session_data *session_ref(struct session_data *session);
 void session_unref(struct session_data *session);
-- 
1.7.1


^ permalink raw reply related

* GSoC: Nintendo Wiimote Driver
From: David Herrmann @ 2011-05-06  9:27 UTC (permalink / raw)
  To: linux-bluetooth, padovan

Hi all

My name is David Herrmann and I am a student at Uni-Tuebingen in
Germany. I got accepted with my GSoC project at Bluez and will develop
a kernel-driver for the Nintendo Wiimote in the next few months with
the help of my tutor (Gustavo Padovan).

The Project:
The Nintendo Wiimote may be known to many of you. It is a bluetooth
device with several I/O ports: buttons, rumble (force feedback),
speaker, infrared-cam, accelerometer, leds and an extension port.
There are some known libraries which implement few features of the
wiimote. However, all these libraries suffer from several restrictions
like no asynchronous API, no auto-reconnection, limited functionality,
etc...
My intention is to write a kernel-driver which implements all these
features on kernel-side with a clean API using as much
kernel-infrastructure as possible. Integrating the driver into bluez
is the only way to support real auto-reconnection and fast
audio/infrared transfers.
You may watch my progress on: https://github.com/dvdhrm/xwiimote
If you have suggestions/questions, I am really glad to hear from you
via: #bluez (dvdhrm) or email.

About Me:
I am 20 years old and an undergraduate from Tübingen/Germany. I
develop IRC server-software since 3 years for the OnlineGamesNet
(http://wiki.onlinegamesnet.net) in cooperation with Undernet and
GameSurge. Currently, I try to get into kernel development and I
thought GSoC would be a great opportunity to do so. Besides, I love
working on 3D renderers and multimedia stuff.

I am really looking forward to the next four months and hope that it
will be a great and of course productive time.

Regards
David

^ permalink raw reply

* [PATCH v4] Add partial mas.c - messages-*.c API.
From: Slawomir Bochenski @ 2011-05-06  8:48 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Slawomir Bochenski

This adds stubs of functions needed for message browsing and retrieval.
---
Changes according to the discussion on the IRC. Changed the way the
parameters are returned. Some documentation changes. Packed boolean
arguments to messages_get_message into a single bit mask.

 plugins/messages-dummy.c |   69 +++++++++++++
 plugins/messages.h       |  245 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 314 insertions(+), 0 deletions(-)

diff --git a/plugins/messages-dummy.c b/plugins/messages-dummy.c
index fd9679d..a536d81 100644
--- a/plugins/messages-dummy.c
+++ b/plugins/messages-dummy.c
@@ -25,4 +25,73 @@
 #include <config.h>
 #endif
 
+#include <errno.h>
+
 #include "messages.h"
+
+int messages_init(void)
+{
+	return 0;
+}
+
+void messages_exit(void)
+{
+}
+
+int messages_connect(void **session)
+{
+	*session = 0;
+	return 0;
+}
+
+void messages_disconnect(void *session)
+{
+}
+
+int messages_set_notification_registration(void *session,
+		void (*send_event)(void *session,
+			struct messages_event *event, void *user_data),
+		void *user_data)
+{
+	return -EINVAL;
+}
+
+int messages_set_folder(void *session, const char *name, gboolean cdup)
+{
+	return -EINVAL;
+}
+
+int messages_get_folder_listing(void *session,
+		const char *name,
+		uint16_t max, uint16_t offset,
+		void (*callback)(void *session, int err, uint16_t size,
+			const char *name, void *user_data),
+		void *user_data)
+{
+	return -EINVAL;
+}
+
+int messages_get_messages_listing(void *session,
+		const char *name,
+		uint16_t max, uint16_t offset, struct messages_filter *filter,
+		void (*callback)(void *session, int err, uint16_t size,
+			gboolean newmsg, const struct messages_message *message,
+			void *user_data),
+		void *user_data)
+{
+	return -EINVAL;
+}
+
+int messages_get_message(void *session,
+		const char *handle,
+		unsigned long flags,
+		void (*callback)(void *session, int err, gboolean fmore,
+			const char *chunk, void *user_data),
+		void *user_data)
+{
+	return -EINVAL;
+}
+
+void messages_abort(void *session)
+{
+}
diff --git a/plugins/messages.h b/plugins/messages.h
index c510244..c862b07 100644
--- a/plugins/messages.h
+++ b/plugins/messages.h
@@ -20,3 +20,248 @@
  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  *
  */
+
+#include <glib.h>
+#include <stdint.h>
+
+/* Those are used by backend to notify transport plugin which properties did it
+ * send.
+ */
+#define PMASK_SUBJECT			0x0001
+#define PMASK_DATETIME			0x0002
+#define PMASK_SENDER_NAME		0x0004
+#define PMASK_SENDER_ADDRESSING		0x0008
+#define PMASK_RECIPIENT_NAME		0x0010
+#define PMASK_RECIPIENT_ADDRESSING	0x0020
+#define PMASK_TYPE			0x0040
+#define PMASK_SIZE			0x0080
+#define PMASK_RECEPTION_STATUS		0x0100
+#define PMASK_TEXT			0x0200
+#define PMASK_ATTACHMENT_SIZE		0x0400
+#define PMASK_PRIORITY			0x0800
+#define PMASK_READ			0x1000
+#define PMASK_SENT			0x2000
+#define PMASK_PROTECTED			0x4000
+#define PMASK_REPLYTO_ADDRESSING	0x8000
+
+/* This one is used in a response to GetMessagesListing. Use PMASK_* values to
+ * notify the plugin which members are actually set. Backend shall not omit
+ * properties required by MAP specification (subject, datetime,
+ * recipient_addressing, type, size, reception_status, attachment_size) unless
+ * ordered by PARAMETERMASK. Boolean values should be probably
+ * always sent (need checking). Handle is mandatory. Plugin will filter out any
+ * properties that were not wanted by MCE.
+ *
+ * Handle shall be set to hexadecimal representation with upper-case letters. No
+ * prefix shall be appended and without no zeros. This corresponds to PTS
+ * behaviour described in comments to the MAP specification.
+ *
+ * The rest of char * fields shall be set according to the MAP specification
+ * rules.
+ */
+struct messages_message {
+	uint32_t mask;
+	char *handle;
+	char *subject;
+	char *datetime;
+	char *sender_name;
+	char *sender_addressing;
+	char *replyto_addressing;
+	char *recipient_name;
+	char *recipient_addressing;
+	char *type;
+	char *reception_status;
+	char *size;
+	char *attachment_size;
+	gboolean text;
+	gboolean read;
+	gboolean sent;
+	gboolean protect;
+	gboolean priority;
+};
+
+/* Type of message event to be delivered to MNS server */
+enum messages_event_type {
+	MET_NEW_MESSAGE,
+	MET_DELIVERY_SUCCESS,
+	MET_SENDING_SUCCESS,
+	MET_DELIVERY_FAILURE,
+	MET_SENDING_FAILURE,
+	MET_MEMORY_FULL,
+	MET_MEMORY_AVAILABLE,
+	MET_MESSAGE_DELETED,
+	MET_MESSAGE_SHIFT
+};
+
+/* Data for sending MNS notification. Handle shall be formatted as described in
+ * messages_message.
+ */
+struct messages_event {
+	enum messages_event_type type;
+	uint8_t instance_id;
+	char *handle;
+	char *folder;
+	char *old_folder;
+	char *msg_type;
+};
+
+/* parameter_mask: |-ed PMASK_* values
+ * See MAP specification for the rest.
+ */
+struct messages_filter {
+	uint32_t parameter_mask;
+	uint8_t type;
+	char *period_begin;
+	char *period_end;
+	uint8_t *read_status;
+	char *recipient;
+	char *originator;
+	uint8_t priority;
+};
+
+/* This is called once after server starts.
+ *
+ * Returns value less than zero if error. This will prevent MAP plugin from
+ * starting.
+ */
+int messages_init(void);
+
+/* This gets called right before server finishes
+ */
+void messages_exit(void);
+
+/* Starts a new MAP session.
+ *
+ * session: variable to store pointer to backend session data. This one shall be
+ * passed to all in-session calls.
+ *
+ * If session start succeeded, backend shall return 0. Otherwise the error value
+ * will be sent as a response to OBEX connect.
+ */
+int messages_connect(void **session);
+
+/* Closes a MAP session.
+ *
+ * This call should free buffer reserved by messages_connect.
+ */
+void messages_disconnect(void *session);
+
+/******************************************************************************
+ * NOTE on callbacks.
+ *
+ * All functions requiring callbacks have to call them asynchronously.
+ * 'user_data' is for passing arbitrary user data.
+ *
+ * Functions for GetMessagesListing, GetFolder listing and GetMessage call their
+ * callbacks multiple times - one for each listing entry or message body chunk.
+ * To indicate the end of operation backend must call callback with the data
+ * pointer parameter set to NULL.
+ *
+ * If err == -EAGAIN the transport * plugin does not wake IO.
+ *
+ * Keep in mind that application parameters has to be send first. Therefore the
+ * first time err == 0 and thus sending is started, callback will use provided
+ * parameters (e.g. size in case of folder listing) to build applications
+ * parameters header used in response. In any other case those parameters will
+ * be ignored.
+ *
+ * If err != 0 && err != -EAGAIN, the operation is finished immediately and err
+ * value is used to set the error code in OBEX response.
+ ******************************************************************************/
+
+/* Registers for messaging events notifications.
+ *
+ * session: Backend session.
+ * send_event: Function that will be called to indicate a new event.
+ *
+ * To unregister currently registered notifications, call this with send_event
+ * set to NULL.
+ */
+int messages_set_notification_registration(void *session,
+		void (*send_event)(void *session,
+			struct messages_event *event, void *user_data),
+		void *user_data);
+
+/* Changes current directory.
+ *
+ * session: Backend session.
+ * name: Subdirectory to go to. If empty or null and cdup is false, go to the
+ *	root directory.
+ * cdup: If true, go up one level first.
+ */
+int messages_set_folder(void *session, const char *name, gboolean cdup);
+
+/* Retrieves subdirectories listing from a current directory.
+ *
+ * session: Backend session.
+ * name: Optional subdirectory name (not strictly required by MAP).
+ * max: Maximum number of entries to retrieve.
+ * offset: Offset of the first entry.
+ * size: Total size of listing to be returned.
+ *
+ * Callback shall be called for every entry of the listing. 'name' is the
+ * subdirectory name.
+ */
+int messages_get_folder_listing(void *session,
+		const char *name,
+		uint16_t max, uint16_t offset,
+		void (*callback)(void *session, int err, uint16_t size,
+			const char *name, void *user_data),
+		void *user_data);
+
+/* Retrieves messages listing from a current directory.
+ *
+ * session: Backend session.
+ * name: Optional subdirectory name.
+ * max: Maximum number of entries to retrieve.
+ * filter: Filter to apply on returned message listing.
+ * size: Total size of listing to be returned.
+ * newmsg: Indicates presence of unread messages.
+ *
+ * Callback shall be called for every entry of the listing, giving message data
+ * in 'message'.
+ */
+int messages_get_messages_listing(void *session,
+		const char *name,
+		uint16_t max, uint16_t offset, struct messages_filter *filter,
+		void (*callback)(void *session, int err, uint16_t size,
+			gboolean newmsg, const struct messages_message *message,
+			void *user_data),
+		void *user_data);
+
+#define MESSAGES_ATTACHMENT	(1 << 0)
+#define MESSAGES_UTF8		(1 << 1)
+#define MESSAGES_FRACTION	(1 << 2)
+#define MESSAGES_NEXT		(1 << 3)
+
+/* Retrieves bMessage object (see MAP specification, ch. 3.1.3) of a given
+ * message.
+ *
+ * session: Backend session.
+ * handle: Handle of the message to retrieve.
+ * flags: or-ed mask of following:
+ *	MESSAGES_ATTACHMENT: Selects whether or not attachments (if any) are to
+ *		be included.
+ *	MESSAGES_UTF8: If true, convert message to utf-8. Otherwise use native
+ *		encoding.
+ *	MESSAGES_FRACTION: If true, deliver fractioned message.
+ *	MESSAGES_NEXT: If fraction is true this indicates whether to retrieve
+ *		first fraction
+ *	or the next one.
+ * fmore: Indicates whether next fraction is available.
+ * chunk: chunk of bMessage body
+ *
+ * Callback allows for returning bMessage in chunks.
+ */
+int messages_get_message(void *session,
+		const char *handle,
+		unsigned long flags,
+		void (*callback)(void *session, int err, gboolean fmore,
+			const char *chunk, void *user_data),
+		void *user_data);
+
+/* Aborts currently pending request.
+ *
+ * session: Backend session.
+ */
+void messages_abort(void *session);
-- 
1.7.4.1


^ permalink raw reply related

* Re: [PATCH v2 3/3] Add sixaxis plugin: USB pairing and LEDs settings
From: Antonio Ospite @ 2011-05-06  8:45 UTC (permalink / raw)
  To: Bastien Nocera
  Cc: linux-bluetooth, linux-input, Jim Paris, Ranulf Doswell,
	Pascal A . Brisset, Marcin Tolysz, Christian Birchinger,
	Filipe Lopes, Alan Ott, Mikko Virkkila
In-Reply-To: <1304644488.16101.28.camel@novo.hadess.net>

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

On Fri, 06 May 2011 02:14:38 +0100
Bastien Nocera <hadess@hadess.net> wrote:

> On Fri, 2011-02-25 at 11:04 +0100, Antonio Ospite wrote:
> > +                       [AC_LANG_PROGRAM([[
> > +                               #include <sys/ioctl.h>
> > +                               #include <linux/hidraw.h>
> > +                               #if ! (defined(HIDIOCSFEATURE) &&
> > defined(HIDIOCGFEATURE))
> > +                               #error "HIDIOCSFEATURE and
> > HIDIOCGFEATURE are required (linux-libc-dev >= 2.6.3x)"
> > +                               #endif
> > +                               ]], 
> 
> The only part of the patch I have a problem with is this one.
> 
> I'd rather the code had:
> #ifndef HIDIOCSFEATURE
> #define HIDIOCSFEATURE bleh
> #endif
> 
> And gracefully handled the ioctl not being available on the running
> kernel (eg. "Not handling plugged in Sixaxis joypad because the kernel
> lacks HIDIOCSFEATURE support").
>

I'll give that a try a report back my opinion.
Thanks.

> The rest looks fine, and I'll be testing whether my Fedora 15 kernel has
> the feature merged in yet (which would make testing your code much
> easier).
> 

Regards,
   Antonio

-- 
Antonio Ospite
http://ao2.it

PGP public key ID: 0x4553B001

A: Because it messes up the order in which people normally read text.
   See http://en.wikipedia.org/wiki/Posting_style
Q: Why is top-posting such a bad thing?

[-- Attachment #2: Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply

* Re: Warning fixes for GCC 4.6
From: Luiz Augusto von Dentz @ 2011-05-06  7:52 UTC (permalink / raw)
  To: Bastien Nocera; +Cc: BlueZ development
In-Reply-To: <1304620983.16101.16.camel@novo.hadess.net>

Hi Bastien,

On Thu, May 5, 2011 at 9:43 PM, Bastien Nocera <hadess@hadess.net> wrote:
> So that bluez compiles with -Werror.
>
> Cheers
>

diff --git a/attrib/gatt.c b/attrib/gatt.c
index 360218b..61c9ed1 100644
--- a/attrib/gatt.c
+++ b/attrib/gatt.c
@@ -71,13 +71,12 @@ static guint16 encode_discover_primary(uint16_t
start, uint16_t end,
 {
 	bt_uuid_t prim;
 	guint16 plen;
-	uint8_t op;

 	bt_uuid16_create(&prim, GATT_PRIM_SVC_UUID);

 	if (uuid == NULL) {
-		/* Discover all primary services */
-		op = ATT_OP_READ_BY_GROUP_REQ;
+		/* Discover all primary services
+		   op = ATT_OP_READ_BY_GROUP_REQ; */
 		plen = enc_read_by_grp_req(start, end, &prim, pdu, len);
 	} else {
 		uint16_t u16;

I guess we don't need the comments as enc_read_by_grp_req already
should already do what ATT_OP_READ_BY_GROUP_REQ was meant.

@@ -2085,9 +2084,9 @@ unsigned int a2dp_config(struct avdtp *session,
struct a2dp_sep *sep,
 	case AVDTP_STATE_IDLE:
 		if (sep->type == AVDTP_SEP_TYPE_SOURCE) {
 			l = server->sources;
-			remote_type = AVDTP_SEP_TYPE_SINK;
+			/* remote_type = AVDTP_SEP_TYPE_SINK; */
 		} else {
-			remote_type = AVDTP_SEP_TYPE_SOURCE;
+			/* remote_type = AVDTP_SEP_TYPE_SOURCE; */
 			l = server->sinks;
 		}

Same here, avdtp_find_remote_sep already take care of finding a match
so remote_type is useless.

@@ -580,7 +579,7 @@ static void hf_io_cb(GIOChannel *chan, gpointer data)

 	server_uuid = HFP_AG_UUID;
 	remote_uuid = HFP_HS_UUID;
-	svclass = HANDSFREE_AGW_SVCLASS_ID;
+	/* svclass = HANDSFREE_AGW_SVCLASS_ID; */

 	device = manager_get_device(&src, &dst, TRUE);
 	if (!device)

Since introduced this variable was never really used, I guess it is
safe to remove it completely too.

@@ -1135,6 +1136,10 @@ gboolean bt_io_accept(GIOChannel *io,
BtIOConnect connect, gpointer user_data,
 	if (!(pfd.revents & POLLOUT)) {
 		int ret;
 		ret = read(sock, &c, 1);
+		if (ret == -1) {
+			ERROR_FAILED(err, "read", errno);
+			return FALSE;
+		}
 	}

We normally use < 0, but I guess it doesn't make any difference since
errno is actually what we should be looking for.

@@ -94,8 +94,12 @@ static int hcrp_credit_grant(int sk, uint16_t tid,
uint32_t credit)
 	memcpy(buf, &hdr, HCRP_PDU_HDR_SIZE);
 	memcpy(buf + HCRP_PDU_HDR_SIZE, &cp, HCRP_CREDIT_GRANT_CP_SIZE);
 	len = write(sk, buf, HCRP_PDU_HDR_SIZE + HCRP_CREDIT_GRANT_CP_SIZE);
+	if (len == -1)
+		return -1;

 	len = read(sk, buf, sizeof(buf));
+	if (len == -1)
+		return -1;
 	memcpy(&hdr, buf, HCRP_PDU_HDR_SIZE);
 	memcpy(&rp, buf + HCRP_PDU_HDR_SIZE, HCRP_CREDIT_GRANT_RP_SIZE);

@@ -119,8 +123,12 @@ static int hcrp_credit_request(int sk, uint16_t
tid, uint32_t *credit)
 	hdr.plen = htons(0);
 	memcpy(buf, &hdr, HCRP_PDU_HDR_SIZE);
 	len = write(sk, buf, HCRP_PDU_HDR_SIZE);
+	if (len == -1)
+		return -1;

 	len = read(sk, buf, sizeof(buf));
+	if (len == -1)
+		return -1;
 	memcpy(&hdr, buf, HCRP_PDU_HDR_SIZE);
 	memcpy(&rp, buf + HCRP_PDU_HDR_SIZE, HCRP_CREDIT_REQUEST_RP_SIZE);

@@ -147,8 +155,12 @@ static int hcrp_get_lpt_status(int sk, uint16_t
tid, uint8_t *lpt_status)
 	hdr.plen = htons(0);
 	memcpy(buf, &hdr, HCRP_PDU_HDR_SIZE);
 	len = write(sk, buf, HCRP_PDU_HDR_SIZE);
+	if (len == -1)
+		return -1;

 	len = read(sk, buf, sizeof(buf));
+	if (len == -1)
+		return -1;
 	memcpy(&hdr, buf, HCRP_PDU_HDR_SIZE);
 	memcpy(&rp, buf + HCRP_PDU_HDR_SIZE, HCRP_GET_LPT_STATUS_RP_SIZE);

Same here.

@@ -250,7 +250,7 @@ static int decode_key(const char *str)
 static void send_event(int fd, uint16_t type, uint16_t code, int32_t value)
 {
 	struct uinput_event event;
-	int err;
+	int __attribute__((__unused__)) err;

 	memset(&event, 0, sizeof(event));
 	event.type	= type;

Can't we just removed err here, Im afraid using
__attribute__((__unused__)) is not a good practice and we should try
to avoid using it.

-- 
Luiz Augusto von Dentz
Computer Engineer

^ permalink raw reply related

* [PATCH v2] Bluetooth: Double check sec req for pre 2.1 device
From: Waldemar Rymarkiewicz @ 2011-05-06  7:42 UTC (permalink / raw)
  To: padovan; +Cc: linux-bluetooth, Waldemar Rymarkiewicz

In case of pre v2.1 devices authentication request will return
success immediately if the link key already exists without any
authentication process.

That means, it's not possible to re-authenticate the link if you
already have combination key and for instance want to re-authenticate
to get the high security (use 16 digit pin).

Therefore, it's necessary to check security requirements on auth
complete event to prevent not enough secure connection.

Signed-off-by: Waldemar Rymarkiewicz <waldemar.rymarkiewicz@tieto.com>
---
 include/net/bluetooth/hci_core.h |    1 +
 net/bluetooth/hci_conn.c         |   17 +++++++++++++++++
 net/bluetooth/rfcomm/core.c      |    2 +-
 3 files changed, 19 insertions(+), 1 deletions(-)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 14cc324..6c994c0 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -422,6 +422,7 @@ void hci_conn_check_pending(struct hci_dev *hdev);
 
 struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst, __u8 sec_level, __u8 auth_type);
 int hci_conn_check_link_mode(struct hci_conn *conn);
+int hci_conn_check_secure(struct hci_conn *conn, __u8 sec_level);
 int hci_conn_security(struct hci_conn *conn, __u8 sec_level, __u8 auth_type);
 int hci_conn_change_link_key(struct hci_conn *conn);
 int hci_conn_switch_role(struct hci_conn *conn, __u8 role);
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index 7f5ad8a..3163330 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -623,6 +623,23 @@ encrypt:
 }
 EXPORT_SYMBOL(hci_conn_security);
 
+/* Check secure link requirement */
+int hci_conn_check_secure(struct hci_conn *conn, __u8 sec_level)
+{
+	BT_DBG("conn %p", conn);
+
+	if (sec_level != BT_SECURITY_HIGH)
+		return 1; /* Accept if non-secure is required */
+
+	if (conn->key_type == HCI_LK_AUTH_COMBINATION ||
+			(conn->key_type == HCI_LK_COMBINATION &&
+			conn->pin_length == 16))
+		return 1;
+
+	return 0; /* Reject not secure link */
+}
+EXPORT_SYMBOL(hci_conn_check_secure);
+
 /* Change link key */
 int hci_conn_change_link_key(struct hci_conn *conn)
 {
diff --git a/net/bluetooth/rfcomm/core.c b/net/bluetooth/rfcomm/core.c
index 121a5c1..5759bb7 100644
--- a/net/bluetooth/rfcomm/core.c
+++ b/net/bluetooth/rfcomm/core.c
@@ -2096,7 +2096,7 @@ static void rfcomm_security_cfm(struct hci_conn *conn, u8 status, u8 encrypt)
 		if (!test_and_clear_bit(RFCOMM_AUTH_PENDING, &d->flags))
 			continue;
 
-		if (!status)
+		if (!status && hci_conn_check_secure(conn, d->sec_level))
 			set_bit(RFCOMM_AUTH_ACCEPT, &d->flags);
 		else
 			set_bit(RFCOMM_AUTH_REJECT, &d->flags);
-- 
1.7.1


^ permalink raw reply related

* Re: [PATCH] bluetooth: Fix for security block issue.
From: Mika Linnanoja @ 2011-05-06  7:28 UTC (permalink / raw)
  To: padovan
  Cc: linux-bluetooth, ext Ville Tervo, Antti Julku,
	ext Marcel Holtmann, Lukasz Rymanowski, linus.walleij,
	par-gunnar.p.hjalmdahl
In-Reply-To: <4DC390C0.1000607@nokia.com>

On 05/06/2011 09:10 AM, Mika Linnanoja wrote:
> Hi.
>
> Was not happening on ubuntu 9.04 (2.6.28.x) and ubuntu 9.10 (2.6.31.x).
>
> Since 10.04 (2.6.32.x) it has been happening to my knowledge.
>
> It's rather easy to reproduce also manually just by trying to send files in a
> loop via OPP between e.g. 2 ubuntu boxes when both have BT2.1 usb dongles
> (devices can be paired, doesn't help).

One another thing; this specific patch doesn't apply on top of your 
linux-bluetooth or bluetooth-next anymore due to the refactoring work (.39 level).

Applying it on top of 2.6.38.x kernel[1] works, but after sending OPP towards 
PC running with applied kernel I get kernel oops/crash like:

[  143.503531] Call Trace:
[  143.503531]  [<c12eaff2>] acpi_idle_enter_simple+0x105/0x13d
[  143.820013]  [<c12eb114>] acpi_idle_enter_bm+0xd5/0x25e
[  143.820017]  [<c142000d>] cpuidle_idle_call+0x7d/0x160
[  143.820020]  [<c10092ca>] cpu_idle+0x8a/0xc0
[  143.820023]  [<c104021e>] ? complete+0x4e/0x60
[  143.820026]  [<c15055cd>] rest_init+0x5d/0x70
[  143.820029]  [<c17a87ee>] start_kernel+0x35f/0x366
[  143.820032]  [<c17a82a3>] ? pass_all_bootoptions+0x0/0x149
[  143.820036]  [<c17a80f1>] i386_start_kernel+0xe0/0xe8

After that trying "hciconfig hci0 -a" results in timeout. That trace doesn't 
look like bt specific at all to my untrained eye.

Stock kernel without this patch doesn't cause such kind of issue. Of course it 
could be built somehow differently, I'm not an expert, followed some blog's 
instructions[2].

BR,
Mika

[1] git cloned git://kernel.ubuntu.com/ubuntu/ubuntu-natty.git
[2] http://parabing.com/2011/04/28/ubuntu-natty-a-custom-kernel-is-what-you-want/

^ permalink raw reply

* Re: [PATCH] bluetooth: Fix for security block issue.
From: Mika Linnanoja @ 2011-05-06  6:10 UTC (permalink / raw)
  To: padovan
  Cc: linux-bluetooth, ext Ville Tervo, Antti Julku,
	ext Marcel Holtmann, Lukasz Rymanowski, linus.walleij,
	par-gunnar.p.hjalmdahl
In-Reply-To: <20110505190230.GC2098@joana>

On 05/05/2011 10:02 PM, ext Gustavo F. Padovan wrote:
>> Happens on Ubuntu 11.04 (released yesterday; bluez 4.91&  kernel 2.6.38-8) as
>> well, tested with White PTS 2.1 dongle (CSR chip) on laptop x61s. Sending
>> party (OPP with obex-client in a loop) was a phone.
>
> Is this an regression? Or did it never happen before?

Hi.

Was not happening on ubuntu 9.04 (2.6.28.x) and ubuntu 9.10 (2.6.31.x).

Since 10.04 (2.6.32.x) it has been happening to my knowledge.

It's rather easy to reproduce also manually just by trying to send files in a 
loop via OPP between e.g. 2 ubuntu boxes when both have BT2.1 usb dongles 
(devices can be paired, doesn't help).

Cheers,
Mika

^ permalink raw reply

* [PATCH v2] Bluetooth: Allow unsegmented SDU retries on sock_queue_rcv_skb failure.
From: Ruiyi Zhang @ 2011-05-06  4:44 UTC (permalink / raw)
  To: Gustavo F. Padovan; +Cc: linux-bluetooth, Ruiyi Zhang
In-Reply-To: <1303990781-15538-1-git-send-email-Ruiyi.zhang@atheros.com>

In L2CAP_SDU_UNSEGMENTED case, if sock_queue_rcv_skb returns error,
l2cap_ertm_reassembly_sdu should not return 0 so as to insert the
skb into BUSY_QUEUE for later retries.

Signed-off-by: Ruiyi Zhang <Ruiyi.zhang@atheros.com>
---
 net/bluetooth/l2cap_core.c |    6 +-----
 1 files changed, 1 insertions(+), 5 deletions(-)

diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 2c8dd44..623421c 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -2784,11 +2784,7 @@ static int l2cap_ertm_reassembly_sdu(struct sock *sk, struct sk_buff *skb, u16 c
 		if (pi->conn_state & L2CAP_CONN_SAR_SDU)
 			goto drop;
 
-		err = sock_queue_rcv_skb(sk, skb);
-		if (!err)
-			return err;
-
-		break;
+		return sock_queue_rcv_skb(sk, skb);
 
 	case L2CAP_SDU_START:
 		if (pi->conn_state & L2CAP_CONN_SAR_SDU)
-- 
1.7.1


^ permalink raw reply related

* Re: [RFC][PATCH 0/4] Allow hexadecimal encoded pins
From: Bastien Nocera @ 2011-05-06  1:37 UTC (permalink / raw)
  To: David Herrmann; +Cc: Daniele Forsi, linux-bluetooth, johan.hedberg
In-Reply-To: <BANLkTingDa5rTU3YAQStB15CFFeiWNMXhQ@mail.gmail.com>

On Tue, 2011-05-03 at 20:28 +0200, David Herrmann wrote:
> On Tue, May 3, 2011 at 2:27 PM, Daniele Forsi <dforsi@gmail.com> wrote:
> > one issue when using the 1+2 way is that the Wiimote will forget the
> > pairing when it is turned off while the PC will remember it, so the
> > Wiimote won't be shown in the list of found devices and you need to
> > delete it before you can pair again
> 
> I don't get this. If the wiimote is listed as paired, why would you
> want to see it in the list of found devices? The wiimote is already
> listed as paired so simply reestablish the pairing by connecting to
> the wiimote via DBus bluez.Input api.

If the Wiimote is already paired, it won't appear in the "discoverable
and not already setup" devices list in the wizard.

But your point is correct.

> >>> Is there any way to detect which "type" of pairing is made with the
> >>> Wiimote, eg. you say that button 1+2 will only work for temporary
> >>> connections. Can we detect this? Would pairing anyway work?
> >>
> >> I guess you mean that you wanna predict which PIN to use? No, I
> >> currently know no way to detect this. However, one may try the first
> >> pin and if that fails the second pin.
> >
> > I think this is what the Wii does when in the "home" screen where you
> > are supposed to press 1+2 because it will find the remote also when
> > pressing the sync button (I have a Wiimote that I need to pair from
> > the home screen pressing sync because it doesn't wake up with 1+2)
> 
> With 1+2 buttons only the dest-address works as PIN (I checked this). However,
> with "sync" button both addresses may work. I will check this later...
> Anyway, this would simplify the wiimote handling significantly.

Either way, I think I'd do the work so that the "proper" pairing can be
done, and add a warning at the end of a failed pairing process for a
Wiimote if pairing failed, mentioning which way you should press the
buttons to have it always paired.

I'll get on that as soon as your patches make it into bluez master
proper.

Cheers


^ permalink raw reply

* Re: [PATCH v2 3/3] Add sixaxis plugin: USB pairing and LEDs settings
From: Bastien Nocera @ 2011-05-06  1:14 UTC (permalink / raw)
  To: Antonio Ospite
  Cc: linux-bluetooth, linux-input, Jim Paris, Ranulf Doswell,
	Pascal A . Brisset, Marcin Tolysz, Christian Birchinger,
	Filipe Lopes, Alan Ott, Mikko Virkkila
In-Reply-To: <1298628292-8842-4-git-send-email-ospite@studenti.unina.it>

On Fri, 2011-02-25 at 11:04 +0100, Antonio Ospite wrote:
> +                       [AC_LANG_PROGRAM([[
> +                               #include <sys/ioctl.h>
> +                               #include <linux/hidraw.h>
> +                               #if ! (defined(HIDIOCSFEATURE) &&
> defined(HIDIOCGFEATURE))
> +                               #error "HIDIOCSFEATURE and
> HIDIOCGFEATURE are required (linux-libc-dev >= 2.6.3x)"
> +                               #endif
> +                               ]], 

The only part of the patch I have a problem with is this one.

I'd rather the code had:
#ifndef HIDIOCSFEATURE
#define HIDIOCSFEATURE bleh
#endif

And gracefully handled the ioctl not being available on the running
kernel (eg. "Not handling plugged in Sixaxis joypad because the kernel
lacks HIDIOCSFEATURE support").

The rest looks fine, and I'll be testing whether my Fedora 15 kernel has
the feature merged in yet (which would make testing your code much
easier).

Cheers


^ permalink raw reply

* Re: BT 3.0 HS Support in BlueZ
From: Mat Martineau @ 2011-05-05 23:27 UTC (permalink / raw)
  To: Gustavo F. Padovan
  Cc: Arun Kumar SINGH, Anurag Gupta, pkrystad, linux-bluetooth
In-Reply-To: <20110505201531.GE2098@joana>


On Thu, 5 May 2011, Gustavo F. Padovan wrote:

> Hi Arun,
>
> * Arun Kumar SINGH <arunkr.singh@stericsson.com> [2011-05-05 09:26:58 +0200]:
>
>> Hi Gustavo,
>>
>>>> Does anybody know if
>>> bluetooth 3.0 HS spec is
>>> supported in BlueZ?
>>>> Is AMP supported in BlueZ?
>>>
>>> There is two different
>>> implementations, one by
>>> Atheros and another by QuIC.
>>> Both never reach upstream,
>>> if you look to the list logs
>>> you will find them.
>>
>>
>> Any hopes of getting this unified version upstream anytime in near future? I guess this has been on the cards for some time now given that merge process started last august.
>
> I'm interested in have this on the stack but it doesn't depend on me.
> Patches for this are not arriving to the mailing list. Actually we had no real
> feedback for AMP since the meeting in Boston.

Gustavo, Arun:

We do still plan to upstream our Bluetooth 3.0 + HS implementation.  I 
will start work on upstreaming later this month, but I need to merge 
in all of the recent L2CAP refactoring changes.

Also note that Qualcomm and Atheros have announced a merger.

You can find the kernel AMP implementation in the codeaurora.org 
Android git trees:

git://codeaurora.org/kernel/msm.git
https://www.codeaurora.org/gitweb/quic/la/?p=kernel/msm.git;a=summary

The android-msm-2.6.35 and msm-2.6.38 branches contain the AMP code.


Please let me know if you have any other questions about AMP.

--
Mat Martineau
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum


^ permalink raw reply

* Re: [PATCH v1] Bluetooth: Double check sec req for pre 2.1 device
From: Gustavo F. Padovan @ 2011-05-05 20:35 UTC (permalink / raw)
  To: Waldemar Rymarkiewicz; +Cc: linux-bluetooth
In-Reply-To: <1304604978-17895-2-git-send-email-waldemar.rymarkiewicz@tieto.com>

Hi Waldemar,

* Waldemar Rymarkiewicz <waldemar.rymarkiewicz@tieto.com> [2011-05-05 16:16:17 +0200]:

> In case of pre v2.1 devices authentication request will return
> success immediately if the link key already exists without any
> authentication process.
> 
> That means, it's not possible to re-authenticate the link if you
> already have combination key and for instance want to re-authenticate
> to get the high security (use 16 digit pin).
> 
> Therefore, it's necessary to check security requirements on auth
> complete event to prevent not enough secure connection.
> 
> Signed-off-by: Waldemar Rymarkiewicz <waldemar.rymarkiewicz@tieto.com>
> ---
>  include/net/bluetooth/hci_core.h |    4 +++-
>  net/bluetooth/hci_conn.c         |   17 +++++++++++++++++
>  net/bluetooth/rfcomm/core.c      |    2 +-
>  3 files changed, 21 insertions(+), 2 deletions(-)
> 
> diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
> index 14cc324..1b35c27 100644
> --- a/include/net/bluetooth/hci_core.h
> +++ b/include/net/bluetooth/hci_core.h
> @@ -420,8 +420,10 @@ int hci_conn_del(struct hci_conn *conn);
>  void hci_conn_hash_flush(struct hci_dev *hdev);
>  void hci_conn_check_pending(struct hci_dev *hdev);
>  
> -struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst, __u8 sec_level, __u8 auth_type);
> +struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst,
> +					__u8 sec_level, __u8 auth_type);

Coding styles changes needs a new patch for it. Just leave this out.

-- 
Gustavo F. Padovan
http://profusion.mobi

^ permalink raw reply

* [PATCH] Fix set but not used variable in attrib code
From: Claudio Takahasi @ 2011-05-05 20:33 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi
In-Reply-To: <1304627636-22358-1-git-send-email-claudio.takahasi@openbossa.org>

---
 attrib/gatt.c |    4 ----
 1 files changed, 0 insertions(+), 4 deletions(-)

diff --git a/attrib/gatt.c b/attrib/gatt.c
index 360218b..095b157 100644
--- a/attrib/gatt.c
+++ b/attrib/gatt.c
@@ -71,13 +71,11 @@ static guint16 encode_discover_primary(uint16_t start, uint16_t end,
 {
 	bt_uuid_t prim;
 	guint16 plen;
-	uint8_t op;
 
 	bt_uuid16_create(&prim, GATT_PRIM_SVC_UUID);
 
 	if (uuid == NULL) {
 		/* Discover all primary services */
-		op = ATT_OP_READ_BY_GROUP_REQ;
 		plen = enc_read_by_grp_req(start, end, &prim, pdu, len);
 	} else {
 		uint16_t u16;
@@ -86,8 +84,6 @@ static guint16 encode_discover_primary(uint16_t start, uint16_t end,
 		int vlen;
 
 		/* Discover primary service by service UUID */
-		op = ATT_OP_FIND_BY_TYPE_REQ;
-
 		if (uuid->type == BT_UUID16) {
 			u16 = htobs(uuid->value.u16);
 			value = &u16;
-- 
1.7.5.rc3


^ permalink raw reply related

* [PATCH] Remove unneeded list when removing a device driver
From: Claudio Takahasi @ 2011-05-05 20:33 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi
In-Reply-To: <1304627636-22358-1-git-send-email-claudio.takahasi@openbossa.org>

---
 src/device.c |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/src/device.c b/src/device.c
index b0a6542..694a3df 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1168,7 +1168,7 @@ add_uuids:
 static void device_remove_drivers(struct btd_device *device, GSList *uuids)
 {
 	struct btd_adapter *adapter = device_get_adapter(device);
-	GSList *list, *next;
+	GSList *list;
 	char srcaddr[18], dstaddr[18];
 	bdaddr_t src;
 	sdp_list_t *records;
@@ -1181,12 +1181,10 @@ static void device_remove_drivers(struct btd_device *device, GSList *uuids)
 
 	DBG("Removing drivers for %s", dstaddr);
 
-	for (list = device->drivers; list; list = next) {
+	for (list = device->drivers; list; list = list->next) {
 		struct btd_device_driver *driver = list->data;
 		const char **uuid;
 
-		next = list->next;
-
 		for (uuid = driver->uuids; *uuid; uuid++) {
 			if (!g_slist_find_custom(uuids, *uuid,
 						(GCompareFunc) strcasecmp))
-- 
1.7.5.rc3


^ permalink raw reply related

* [PATCH] Remove unnecessary headers from main.c
From: Claudio Takahasi @ 2011-05-05 20:33 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi
In-Reply-To: <1304627636-22358-1-git-send-email-claudio.takahasi@openbossa.org>

---
 src/main.c |    5 +----
 1 files changed, 1 insertions(+), 4 deletions(-)

diff --git a/src/main.c b/src/main.c
index 34d291f..e451e72 100644
--- a/src/main.c
+++ b/src/main.c
@@ -33,10 +33,8 @@
 #include <stdlib.h>
 #include <string.h>
 #include <signal.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
-#include <sys/socket.h>
 #include <sys/types.h>
+#include <sys/stat.h>
 
 #include <bluetooth/bluetooth.h>
 #include <bluetooth/uuid.h>
@@ -53,7 +51,6 @@
 #include "sdpd.h"
 #include "attrib-server.h"
 #include "adapter.h"
-#include "event.h"
 #include "dbus-common.h"
 #include "agent.h"
 #include "manager.h"
-- 
1.7.5.rc3


^ permalink raw reply related

* [PATCH] Remove unused "scan" variable from main_opts
From: Claudio Takahasi @ 2011-05-05 20:33 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

---
 src/hcid.h |    1 -
 src/main.c |    1 -
 2 files changed, 0 insertions(+), 2 deletions(-)

diff --git a/src/hcid.h b/src/hcid.h
index 856723b..fcfd45b 100644
--- a/src/hcid.h
+++ b/src/hcid.h
@@ -40,7 +40,6 @@ struct main_opts {
 	gboolean	attrib_server;
 	gboolean	le;
 
-	uint8_t		scan;
 	uint8_t		mode;
 	uint8_t		discov_interval;
 	char		deviceid[15]; /* FIXME: */
diff --git a/src/main.c b/src/main.c
index c454327..34d291f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -238,7 +238,6 @@ static void init_defaults(void)
 {
 	/* Default HCId settings */
 	memset(&main_opts, 0, sizeof(main_opts));
-	main_opts.scan	= SCAN_PAGE;
 	main_opts.mode	= MODE_CONNECTABLE;
 	main_opts.name	= g_strdup("BlueZ");
 	main_opts.discovto	= DEFAULT_DISCOVERABLE_TIMEOUT;
-- 
1.7.5.rc3


^ permalink raw reply related

* Re: BT 3.0 HS Support in BlueZ
From: Gustavo F. Padovan @ 2011-05-05 20:15 UTC (permalink / raw)
  To: Arun Kumar SINGH; +Cc: Anurag Gupta, linux-bluetooth@vger.kernel.org
In-Reply-To: <AFCDDB4A3EA003429EEF1E7B211FDBBA3395937A4C@EXDCVYMBSTM005.EQ1STM.local>

Hi Arun,

* Arun Kumar SINGH <arunkr.singh@stericsson.com> [2011-05-05 09:26:58 +0200]:

> Hi Gustavo,
> 
> >> Does anybody know if
> >bluetooth 3.0 HS spec is
> >supported in BlueZ?
> >> Is AMP supported in BlueZ?
> >
> >There is two different
> >implementations, one by
> >Atheros and another by QuIC.
> >Both never reach upstream,
> >if you look to the list logs
> >you will find them.
> 
> 
> Any hopes of getting this unified version upstream anytime in near future? I guess this has been on the cards for some time now given that merge process started last august. 

I'm interested in have this on the stack but it doesn't depend on me.
Patches for this are not arriving to the mailing list. Actually we had no real
feedback for AMP since the meeting in Boston.

-- 
Gustavo F. Padovan
http://profusion.mobi

^ permalink raw reply

* [PATCH 3/5 v3] Parse pin codes starting with '$' as hexadecimal encoded strings
From: David Herrmann @ 2011-05-05 20:10 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: johan.hedberg, padovan, David Herrmann

If a pin code is retrieved from an agent and the first character is
a dollar sign '$', then the pin is decoded as following:
 - The first character (dollar sign) is stripped from the pin
 - The rest is parsed as hexadecimal numbers, where each two characters
   will be converted into a one byte integer. If an odd number of
   characters follows, then the last character is stripped.
Parser is case insensitive. Pins not starting with '$' are parsed
as usual.

For instance:
 pin: $0A3e005067
is decoded into a 5 byte pin:
 decoded: 0x0a 0x3e 0x00 0x50 0x67
---
This removes support for empty PINs (pin = "$") as suggested by Johan
since HCI specs forbid it.

 src/event.c |   35 ++++++++++++++++++++++++++++++++---
 1 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/src/event.c b/src/event.c
index c238392..a8dbafc 100644
--- a/src/event.c
+++ b/src/event.c
@@ -101,24 +101,53 @@ static gboolean get_adapter_and_device(bdaddr_t *src, bdaddr_t *dst,
  *
  *****************************************************************/
 
+static size_t decode_hex(const char *pin, char *out)
+{
+	size_t i;
+
+	for (i = 0; i < 16 && pin[i * 2] && pin[i * 2 + 1]; i++)
+		sscanf(&pin[i * 2], "%02hhX", &out[i]);
+
+	return i;
+}
+
+static size_t decode_pin(const char *pin, char *out)
+{
+	size_t len;
+
+	if (!pin)
+		return 0;
+
+	if (pin[0] == '$') {
+		len = decode_hex(&pin[1], out);
+	} else {
+		len = strnlen(pin, 16);
+		memcpy(out, pin, len);
+	}
+
+	return len;
+}
+
 static void pincode_cb(struct agent *agent, DBusError *derr,
 				const char *pincode, struct btd_device *device)
 {
 	struct btd_adapter *adapter = device_get_adapter(device);
 	bdaddr_t dba;
 	int err;
+	size_t len;
+	char rawpin[16];
 
 	device_get_address(device, &dba);
 
-	if (derr) {
+	len = decode_pin(pincode, rawpin);
+	if (derr || !len) {
 		err = btd_adapter_pincode_reply(adapter, &dba, NULL, 0);
 		if (err < 0)
 			goto fail;
 		return;
 	}
 
-	err = btd_adapter_pincode_reply(adapter, &dba, pincode,
-						pincode ? strlen(pincode) : 0);
+	err = btd_adapter_pincode_reply(adapter, &dba, rawpin, len);
 	if (err < 0)
 		goto fail;
 
-- 
1.7.5


^ permalink raw reply related

* [PATCH 3/5] Parse pin codes starting with '$' as hexadecimal encoded strings
From: David Herrmann @ 2011-05-05 19:42 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: johan.hedberg, padovan, David Herrmann

If a pin code is retrieved from an agent and the first character is
a dollar sign '$', then the pin is decoded as following:
 - The first character (dollar sign) is stripped from the pin
 - The rest is parsed as hexadecimal numbers, where each two characters
  will be converted into a one byte integer. If an odd number of
  characters follows, then the last character is stripped. Empty
  pins are valid. Parser is case insensitive.
Pins not starting with '$' are parsed as usual.

For instance:
 pin: $0A3e005067
is decoded into a 5 byte pin:
 decoded: 0x0a 0x3e 0x00 0x50 0x67
---
 src/event.c |   33 +++++++++++++++++++++++++++++++--
 1 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/src/event.c b/src/event.c
index c238392..147a29b 100644
--- a/src/event.c
+++ b/src/event.c
@@ -101,12 +101,41 @@ static gboolean get_adapter_and_device(bdaddr_t *src, bdaddr_t *dst,
  *
  *****************************************************************/
 
+static size_t decode_hex(const char *pin, char *out)
+{
+	size_t i;
+
+	for (i = 0; i < 16 && pin[i * 2] && pin[i * 2 + 1]; i++)
+		sscanf(&pin[i * 2], "%02hhX", &out[i]);
+
+	return i;
+}
+
+static size_t decode_pin(const char *pin, char *out)
+{
+	size_t len;
+
+	if (!pin)
+		return 0;
+
+	if (pin[0] == '$') {
+		len = decode_hex(&pin[1], out);
+	} else {
+		len = strnlen(pin, 16);
+		memcpy(out, pin, len);
+	}
+
+	return len;
+}
+
 static void pincode_cb(struct agent *agent, DBusError *derr,
 				const char *pincode, struct btd_device *device)
 {
 	struct btd_adapter *adapter = device_get_adapter(device);
 	bdaddr_t dba;
 	int err;
+	size_t len;
+	char rawpin[16];
 
 	device_get_address(device, &dba);
 
@@ -117,8 +146,8 @@ static void pincode_cb(struct agent *agent, DBusError *derr,
 		return;
 	}
 
-	err = btd_adapter_pincode_reply(adapter, &dba, pincode,
-						pincode ? strlen(pincode) : 0);
+	len = decode_pin(pincode, rawpin);
+	err = btd_adapter_pincode_reply(adapter, &dba, rawpin, len);
 	if (err < 0)
 		goto fail;
 
-- 
1.7.5


^ permalink raw reply related

* [PATCH 5/5] Document new "hex-encoded pins" feature
From: David Herrmann @ 2011-05-05 19:17 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: johan.hedberg, hadess, padovan, David Herrmann
In-Reply-To: <1304623040-30461-1-git-send-email-dh.herrmann@googlemail.com>

---
 doc/agent-api.txt |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/doc/agent-api.txt b/doc/agent-api.txt
index d8d35c0..0c84e1c 100644
--- a/doc/agent-api.txt
+++ b/doc/agent-api.txt
@@ -26,7 +26,13 @@ Methods		void Release()
 			needs to get the passkey for an authentication.
 
 			The return value should be a string of 1-16 characters
-			length. The string can be alphanumeric.
+			length. Longer strings are truncated to 16 characters.
+			The string can be alphanumeric.
+
+			Strings starting with '$' are parsed as hex-encoded
+			pins. That is, each two following hex characters form
+			a single byte of the resulting pin. The parser is
+			case-insensitive.
 
 			Possible errors: org.bluez.Error.Rejected
 			                 org.bluez.Error.Canceled
-- 
1.7.5


^ permalink raw reply related


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox