Linux bluetooth development
 help / color / mirror / Atom feed
* Re: [PATCH v2 3/3] Add sixaxis plugin: USB pairing and LEDs settings
From: Antonio Ospite @ 2011-05-06 23:14 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: 1890 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").
>

Thinking twice about that, maybe I haven't fully understood what you
mean.

Do you want that the plugin can be enabled and _compiled_ on _older_
kernels as well?

Because about compiling on _supported_ ones and then _running_ it on
_older_ ones, well, the ioctl return values are already checked and
they should just (gracefully?) fail on unsupported kernels. But I'll
double check this scenario.

If you want indeed it to be _compiled_ on older kernels and nonetheless
still work on supported ones, I think we just have to copy the iotcls
request defines from hidraw.h if they are not defined but I still don't
know if I like that.

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

* [PATCH 2/2] Bluetooth: Add support for disconnecting LE links via mgmt
From: Vinicius Costa Gomes @ 2011-05-06 21:41 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Vinicius Costa Gomes
In-Reply-To: <1304718104-6448-1-git-send-email-vinicius.gomes@openbossa.org>

If we can't find a ACL link between the devices, we search
the connection list one second time looking for LE links.

Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@openbossa.org>
---
 net/bluetooth/mgmt.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 2481d25..dae382c 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -1033,6 +1033,9 @@ static int disconnect(struct sock *sk, u16 index, unsigned char *data, u16 len)
 	}
 
 	conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr);
+	if (!conn)
+		conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, &cp->bdaddr);
+
 	if (!conn) {
 		err = cmd_status(sk, index, MGMT_OP_DISCONNECT, ENOTCONN);
 		goto failed;
-- 
1.7.4.3


^ permalink raw reply related

* [PATCH 1/2] Bluetooth: Add support for sending connection events for LE links
From: Vinicius Costa Gomes @ 2011-05-06 21:41 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Vinicius Costa Gomes

We need to be able for receive events notifying that the connection
was established, the connection attempt failed or that disconnection
happened.

Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@openbossa.org>
---
 net/bluetooth/hci_event.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index d5aa97e..f13ddbf 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -1440,7 +1440,7 @@ static inline void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff
 
 	conn->state = BT_CLOSED;
 
-	if (conn->type == ACL_LINK)
+	if (conn->type == ACL_LINK || conn->type == LE_LINK)
 		mgmt_disconnected(hdev->id, &conn->dst);
 
 	hci_proto_disconn_cfm(conn, ev->reason);
@@ -2659,12 +2659,15 @@ static inline void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff
 	}
 
 	if (ev->status) {
+		mgmt_connect_failed(hdev->id, &ev->bdaddr, ev->status);
 		hci_proto_connect_cfm(conn, ev->status);
 		conn->state = BT_CLOSED;
 		hci_conn_del(conn);
 		goto unlock;
 	}
 
+	mgmt_connected(hdev->id, &ev->bdaddr);
+
 	conn->handle = __le16_to_cpu(ev->handle);
 	conn->state = BT_CONNECTED;
 
-- 
1.7.4.3


^ permalink raw reply related

* [PATCH] Remove unused DISC_* macros
From: Andre Guedes @ 2011-05-06 18:22 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Andre Guedes

---
 src/adapter.h |    7 -------
 1 files changed, 0 insertions(+), 7 deletions(-)

diff --git a/src/adapter.h b/src/adapter.h
index 9406b9b..0a5c392 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -42,13 +42,6 @@
 #define STATE_RESOLVNAME	2
 #define STATE_SUSPENDED		3
 
-/* Supported host/controller discover type */
-#define DISC_LE			0x01
-#define DISC_STDINQ		0x02
-#define DISC_INTERLEAVE		0x04
-#define DISC_PINQ		0x08
-#define DISC_RESOLVNAME		0x10
-
 #define MAX_NAME_LENGTH		248
 
 /* Invalid SSP passkey value used to indicate negative replies */
-- 
1.7.1


^ permalink raw reply related

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

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

On Fri, 2011-05-06 at 18:50 +0100, Bastien Nocera wrote:
> On Fri, 2011-05-06 at 20:43 +0300, Luiz Augusto von Dentz wrote:
> > Hi,
> > 
> > On Fri, May 6, 2011 at 5:48 PM, Bastien Nocera <hadess@hadess.net> wrote:
> > >> @@ -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?
> > 
> > I guess I would prefer checking the return properly if you don't mind.
> 
> Done.
> 
> > Also like Gustavo mentioned, it would be great to have the gdbus
> > changes in a separate patch so we can apply to other project which
> > uses it.
> 
> Done.

And without the now unnecessary changes to btio/btio.c (flushable
problem is already fixed).

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

>From 4fa5b05d184d355ee1cb7ebc7abf88f51ec53a59 Mon Sep 17 00:00:00 2001
From: Bastien Nocera <hadess@hadess.net>
Date: Fri, 6 May 2011 18:49:26 +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           |    4 ++++
 compat/fakehid.c      |    6 ++++--
 cups/hcrp.c           |   12 ++++++++++++
 input/device.c        |    4 ++--
 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 --
 25 files changed, 57 insertions(+), 46 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 a3cf38a..4d855ae 100644
--- a/btio/btio.c
+++ b/btio/btio.c
@@ -1135,6 +1135,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/input/device.c b/input/device.c
index 554f5ac..0bc4c9d 100644
--- a/input/device.c
+++ b/input/device.c
@@ -250,14 +250,14 @@ 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;
 
 	memset(&event, 0, sizeof(event));
 	event.type	= type;
 	event.code	= code;
 	event.value	= value;
 
-	err = write(fd, &event, sizeof(event));
+	if (write(fd, &event, sizeof(event)) < 0)
+		error("input: send_event failed: %s", strerror(errno));
 }
 
 static void send_key(int fd, uint16_t key)
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.1


^ permalink raw reply related

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

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

On Fri, 2011-05-06 at 20:43 +0300, Luiz Augusto von Dentz wrote:
> Hi,
> 
> On Fri, May 6, 2011 at 5:48 PM, Bastien Nocera <hadess@hadess.net> wrote:
> >> @@ -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?
> 
> I guess I would prefer checking the return properly if you don't mind.

Done.

> Also like Gustavo mentioned, it would be great to have the gdbus
> changes in a separate patch so we can apply to other project which
> uses it.

Done.

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

>From 59b84e616cec298cfb87ab08bbc5ea31b21adf17 Mon Sep 17 00:00:00 2001
From: Bastien Nocera <hadess@hadess.net>
Date: Fri, 6 May 2011 18:49:11 +0100
Subject: [PATCH 1/2] GDBus: Fix "set but not unused variable" GCC 4.6
 warnings

---
 gdbus/object.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

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.1


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

>From 1177b9a0c9cabcf15982ea78801465212d2564aa Mon Sep 17 00:00:00 2001
From: Bastien Nocera <hadess@hadess.net>
Date: Fri, 6 May 2011 18:49:26 +0100
Subject: [PATCH 2/2] 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 ++++++++++++
 input/device.c        |    4 ++--
 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 --
 25 files changed, 58 insertions(+), 46 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/input/device.c b/input/device.c
index 554f5ac..0bc4c9d 100644
--- a/input/device.c
+++ b/input/device.c
@@ -250,14 +250,14 @@ 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;
 
 	memset(&event, 0, sizeof(event));
 	event.type	= type;
 	event.code	= code;
 	event.value	= value;
 
-	err = write(fd, &event, sizeof(event));
+	if (write(fd, &event, sizeof(event)) < 0)
+		error("input: send_event failed: %s", strerror(errno));
 }
 
 static void send_key(int fd, uint16_t key)
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.1


^ permalink raw reply related

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

Hi,

On Fri, May 6, 2011 at 5:48 PM, Bastien Nocera <hadess@hadess.net> wrote:
>> @@ -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?

I guess I would prefer checking the return properly if you don't mind.
Also like Gustavo mentioned, it would be great to have the gdbus
changes in a separate patch so we can apply to other project which
uses it.

-- 
Luiz Augusto von Dentz
Computer Engineer

^ permalink raw reply

* Re: [PATCH 1/2] client: fix not canceling connection request if client exit bus
From: Vinicius Costa Gomes @ 2011-05-06 17:15 UTC (permalink / raw)
  To: Luiz Augusto von Dentz; +Cc: linux-bluetooth
In-Reply-To: <1304678639-31853-1-git-send-email-luiz.dentz@gmail.com>

Hi Luiz,

On 13:43 Fri 06 May, Luiz Augusto von Dentz wrote:
> 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 */

Shouldn't adding the "service" field (and related changes) be on a separate
patch?

>  	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
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

Cheers,
-- 
Vinicius

^ permalink raw reply

* [PATCH 12/12] Bluetooth: Set 'peer_addr_type' in hci_le_connect()
From: Andre Guedes @ 2011-05-06 17:05 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Andre Guedes
In-Reply-To: <1304701521-26459-1-git-send-email-andre.guedes@openbossa.org>

Set the 'peer_addr_type' field of the LE Create Connection command
sent in hci_le_connect().

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
---
 net/bluetooth/hci_conn.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index ed9ca28..18081a7 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -58,6 +58,7 @@ static void hci_le_connect(struct hci_conn *conn)
 	cp.scan_interval = cpu_to_le16(0x0004);
 	cp.scan_window = cpu_to_le16(0x0004);
 	bacpy(&cp.peer_addr, &conn->dst);
+	cp.peer_addr_type = conn->dst_type;
 	cp.conn_interval_min = cpu_to_le16(0x0008);
 	cp.conn_interval_max = cpu_to_le16(0x0100);
 	cp.supervision_timeout = cpu_to_le16(0x0064);
-- 
1.7.1


^ permalink raw reply related

* [PATCH 11/12] Bluetooth: Check advertising cache in hci_connect()
From: Andre Guedes @ 2011-05-06 17:05 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Andre Guedes
In-Reply-To: <1304701521-26459-1-git-send-email-andre.guedes@openbossa.org>

When connecting to a LE device, we need to check the advertising
cache in order to know the address type of that device.

If its advertising entry is not found, the connection is not
established and hci_connect() returns error.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
---
 net/bluetooth/hci_conn.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index b67c83c..ed9ca28 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -459,10 +459,17 @@ struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst, __u8
 	BT_DBG("%s dst %s", hdev->name, batostr(dst));
 
 	if (type == LE_LINK) {
+		struct adv_entry *entry;
+
 		le = hci_conn_hash_lookup_ba(hdev, LE_LINK, dst);
 		if (le)
 			return ERR_PTR(-EBUSY);
-		le = hci_le_conn_add(hdev, dst, 0);
+
+		entry = hci_find_adv_entry(hdev, dst);
+		if (!entry)
+			return ERR_PTR(-EHOSTUNREACH);
+
+		le = hci_le_conn_add(hdev, dst, entry->bdaddr_type);
 		if (!le)
 			return ERR_PTR(-ENOMEM);
 
-- 
1.7.1


^ permalink raw reply related

* [PATCH 10/12] Bluetooth: Remove useless check in hci_connect()
From: Andre Guedes @ 2011-05-06 17:05 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Andre Guedes
In-Reply-To: <1304701521-26459-1-git-send-email-andre.guedes@openbossa.org>

There is no need to check the connection's state since hci_le_conn_add()
has just created a new connection and its state has been set properly.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
---
 net/bluetooth/hci_conn.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index 8896174..b67c83c 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -465,8 +465,8 @@ struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst, __u8
 		le = hci_le_conn_add(hdev, dst, 0);
 		if (!le)
 			return ERR_PTR(-ENOMEM);
-		if (le->state == BT_OPEN)
-			hci_le_connect(le);
+
+		hci_le_connect(le);
 
 		hci_conn_hold(le);
 
-- 
1.7.1


^ permalink raw reply related

* [PATCH 09/12] Bluetooth: Add hci_le_conn_add()
From: Andre Guedes @ 2011-05-06 17:05 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Andre Guedes
In-Reply-To: <1304701521-26459-1-git-send-email-andre.guedes@openbossa.org>

This patch implements a wrapper function to hci_conn_add() which
takes the address type as argument. This patch also replaces
hci_conn_add() calls by hci_le_conn_add() in LE related code.

hci_le_conn_add() was created to consider the destination address
type when creating a new LE hci_conn.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
---
 include/net/bluetooth/hci_core.h |    2 ++
 net/bluetooth/hci_conn.c         |   14 +++++++++++++-
 net/bluetooth/hci_event.c        |    5 +++--
 3 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 5e64d3f..6dd7cad 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -427,6 +427,8 @@ void hci_setup_sync(struct hci_conn *conn, __u16 handle);
 void hci_sco_setup(struct hci_conn *conn, __u8 status);
 
 struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst);
+struct hci_conn *hci_le_conn_add(struct hci_dev *hdev, bdaddr_t *dst,
+							__u8 addr_type);
 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);
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index 7f5ad8a..8896174 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -347,6 +347,18 @@ struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst)
 	return conn;
 }
 
+struct hci_conn *hci_le_conn_add(struct hci_dev *hdev, bdaddr_t *dst,
+							__u8 addr_type)
+{
+	struct hci_conn *conn = hci_conn_add(hdev, LE_LINK, dst);
+	if (!conn)
+		return NULL;
+
+	conn->dst_type = addr_type;
+
+	return conn;
+}
+
 int hci_conn_del(struct hci_conn *conn)
 {
 	struct hci_dev *hdev = conn->hdev;
@@ -450,7 +462,7 @@ struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst, __u8
 		le = hci_conn_hash_lookup_ba(hdev, LE_LINK, dst);
 		if (le)
 			return ERR_PTR(-EBUSY);
-		le = hci_conn_add(hdev, LE_LINK, dst);
+		le = hci_le_conn_add(hdev, dst, 0);
 		if (!le)
 			return ERR_PTR(-ENOMEM);
 		if (le->state == BT_OPEN)
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index a676757..8c0e3b4 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -1231,7 +1231,8 @@ static void hci_cs_le_create_conn(struct hci_dev *hdev, __u8 status)
 		}
 	} else {
 		if (!conn) {
-			conn = hci_conn_add(hdev, LE_LINK, &cp->peer_addr);
+			conn = hci_le_conn_add(hdev, &cp->peer_addr,
+						cp->peer_addr_type);
 			if (conn)
 				conn->out = 1;
 			else
@@ -2679,7 +2680,7 @@ static inline void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff
 
 	conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, &ev->bdaddr);
 	if (!conn) {
-		conn = hci_conn_add(hdev, LE_LINK, &ev->bdaddr);
+		conn = hci_le_conn_add(hdev, &ev->bdaddr, ev->bdaddr_type);
 		if (!conn) {
 			BT_ERR("No memory for new connection");
 			hci_dev_unlock(hdev);
-- 
1.7.1


^ permalink raw reply related

* [PATCH 08/12] Bluetooth: Add 'dst_type' field to struct hci_conn
From: Andre Guedes @ 2011-05-06 17:05 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Andre Guedes
In-Reply-To: <1304701521-26459-1-git-send-email-andre.guedes@openbossa.org>

This patch adds a new field (dst_type) to the struct hci_conn which
holds the type of the destination address (bdaddr_t dst).

This approach is needed in order to use the struct hci_conn as an
abstraction of LE connections in HCI Layer.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
---
 include/net/bluetooth/hci_core.h |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 7b5c991..5e64d3f 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -225,6 +225,7 @@ struct hci_conn {
 	spinlock_t	lock;
 
 	bdaddr_t	dst;
+	__u8            dst_type;
 	__u16		handle;
 	__u16		state;
 	__u8		mode;
-- 
1.7.1


^ permalink raw reply related

* [PATCH 07/12] Bluetooth: Advertising entries lifetime
From: Andre Guedes @ 2011-05-06 17:05 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Andre Guedes
In-Reply-To: <1304701521-26459-1-git-send-email-andre.guedes@openbossa.org>

This patch adds a timer to clear 'adv_entries' after three minutes.

After some amount of time, the advertising entries cached during
the last LE scan should be considered expired and they should be
removed from the advertising cache.

It was chosen a three minutes timeout as an initial attempt. This
value might change in future.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
---
 include/net/bluetooth/hci_core.h |    2 ++
 net/bluetooth/hci_core.c         |    9 +++++++++
 net/bluetooth/hci_event.c        |    6 +++++-
 3 files changed, 16 insertions(+), 1 deletions(-)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 2ceeadf..7b5c991 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -189,6 +189,7 @@ struct hci_dev {
 
 	struct list_head	adv_entries;
 	rwlock_t		adv_entries_lock;
+	struct timer_list	adv_timer;
 
 	struct hci_dev_stats	stat;
 
@@ -535,6 +536,7 @@ int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 *hash,
 								u8 *randomizer);
 int hci_remove_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr);
 
+#define ADV_CLEAR_TIMEOUT (3*60*HZ) /* Three minutes */
 int hci_adv_entries_clear(struct hci_dev *hdev);
 struct adv_entry *hci_find_adv_entry(struct hci_dev *hdev, bdaddr_t *bdaddr);
 int hci_add_adv_entry(struct hci_dev *hdev,
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 89d7cc8..b0b12ac 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -1204,6 +1204,13 @@ int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 *hash,
 	return 0;
 }
 
+static void hci_adv_clear(unsigned long arg)
+{
+	struct hci_dev *hdev = (void *) arg;
+
+	hci_adv_entries_clear(hdev);
+}
+
 int hci_adv_entries_clear(struct hci_dev *hdev)
 {
 	struct list_head *p, *n;
@@ -1355,6 +1362,7 @@ int hci_register_dev(struct hci_dev *hdev)
 
 	INIT_LIST_HEAD(&hdev->adv_entries);
 	rwlock_init(&hdev->adv_entries_lock);
+	setup_timer(&hdev->adv_timer, hci_adv_clear, (unsigned long) hdev);
 
 	INIT_WORK(&hdev->power_on, hci_power_on);
 	INIT_WORK(&hdev->power_off, hci_power_off);
@@ -1428,6 +1436,7 @@ int hci_unregister_dev(struct hci_dev *hdev)
 	hci_unregister_sysfs(hdev);
 
 	hci_del_off_timer(hdev);
+	del_timer(&hdev->adv_timer);
 
 	destroy_workqueue(hdev->workqueue);
 
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 600425a..a676757 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -856,8 +856,12 @@ static void hci_cc_le_set_scan_enable(struct hci_dev *hdev,
 		return;
 
 	param_scan_enable = *((__u8 *) sent);
-	if (param_scan_enable == 0x01)
+	if (param_scan_enable == 0x01) {
+		del_timer(&hdev->adv_timer);
 		hci_adv_entries_clear(hdev);
+	} else if (param_scan_enable == 0x00) {
+		mod_timer(&hdev->adv_timer, jiffies + ADV_CLEAR_TIMEOUT);
+	}
 }
 
 static inline void hci_cs_inquiry(struct hci_dev *hdev, __u8 status)
-- 
1.7.1


^ permalink raw reply related

* [PATCH 06/12] Bluetooth: Clear advertising cache before scanning
From: Andre Guedes @ 2011-05-06 17:05 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Andre Guedes
In-Reply-To: <1304701521-26459-1-git-send-email-andre.guedes@openbossa.org>

The LE advertising cache should be cleared before performing a LE
scanning. This will force the cache to contain only fresh advertising
entries.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
---
 net/bluetooth/hci_event.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 8305abf..600425a 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -842,9 +842,22 @@ static void hci_cc_read_local_oob_data_reply(struct hci_dev *hdev,
 static void hci_cc_le_set_scan_enable(struct hci_dev *hdev,
 					struct sk_buff *skb)
 {
+	void *sent;
+	__u8 param_scan_enable;
 	__u8 status = *((__u8 *) skb->data);
 
 	BT_DBG("%s status 0x%x", hdev->name, status);
+
+	if (status)
+		return;
+
+	sent = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_SCAN_ENABLE);
+	if (!sent)
+		return;
+
+	param_scan_enable = *((__u8 *) sent);
+	if (param_scan_enable == 0x01)
+		hci_adv_entries_clear(hdev);
 }
 
 static inline void hci_cs_inquiry(struct hci_dev *hdev, __u8 status)
-- 
1.7.1


^ permalink raw reply related

* [PATCH 05/12] Bluetooth: LE Set Scan Enable command complete event
From: Andre Guedes @ 2011-05-06 17:05 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Andre Guedes
In-Reply-To: <1304701521-26459-1-git-send-email-andre.guedes@openbossa.org>

This patch adds a function handler to the command complete event
generated by the LE Set Scan Enable command.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
---
 include/net/bluetooth/hci.h |    2 ++
 net/bluetooth/hci_event.c   |   12 ++++++++++++
 2 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index ec0fb2d..bc90da9 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -710,6 +710,8 @@ struct hci_rp_le_read_buffer_size {
 	__u8     le_max_pkt;
 } __packed;
 
+#define HCI_OP_LE_SET_SCAN_ENABLE	0x200c
+
 #define HCI_OP_LE_CREATE_CONN		0x200d
 struct hci_cp_le_create_conn {
 	__le16   scan_interval;
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 3fb36bc..8305abf 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -839,6 +839,14 @@ static void hci_cc_read_local_oob_data_reply(struct hci_dev *hdev,
 						rp->randomizer, rp->status);
 }
 
+static void hci_cc_le_set_scan_enable(struct hci_dev *hdev,
+					struct sk_buff *skb)
+{
+	__u8 status = *((__u8 *) skb->data);
+
+	BT_DBG("%s status 0x%x", hdev->name, status);
+}
+
 static inline void hci_cs_inquiry(struct hci_dev *hdev, __u8 status)
 {
 	BT_DBG("%s status 0x%x", hdev->name, status);
@@ -1814,6 +1822,10 @@ static inline void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *sk
 		hci_cc_user_confirm_neg_reply(hdev, skb);
 		break;
 
+	case HCI_OP_LE_SET_SCAN_ENABLE:
+		hci_cc_le_set_scan_enable(hdev, skb);
+		break;
+
 	default:
 		BT_DBG("%s opcode 0x%x", hdev->name, opcode);
 		break;
-- 
1.7.1


^ permalink raw reply related

* [PATCH 04/12] Bluetooth: Add advertising report meta event handler
From: Andre Guedes @ 2011-05-06 17:05 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Anderson Briglia, Andre Guedes
In-Reply-To: <1304701521-26459-1-git-send-email-andre.guedes@openbossa.org>

From: Anderson Briglia <anderson.briglia@openbossa.org>

This patch adds a function to handle LE Advertising Report Meta
Events.

Signed-off-by: Anderson Briglia <anderson.briglia@openbossa.org>
Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
---
 net/bluetooth/hci_event.c |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index d5aa97e..3fb36bc 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -2677,6 +2677,24 @@ unlock:
 	hci_dev_unlock(hdev);
 }
 
+static inline void hci_le_adv_report_evt(struct hci_dev *hdev,
+						struct sk_buff *skb)
+{
+	const u8 RSSI_SIZE = 1;
+	struct hci_ev_le_advertising_info *ev;
+	u8 num_reports;
+
+	num_reports = skb->data[0];
+
+	ev = (void *) &skb->data[1];
+	hci_add_adv_entry(hdev, ev);
+
+	while (--num_reports) {
+		ev = (void *) (ev->data + ev->length + RSSI_SIZE);
+		hci_add_adv_entry(hdev, ev);
+	}
+}
+
 static inline void hci_le_meta_evt(struct hci_dev *hdev, struct sk_buff *skb)
 {
 	struct hci_ev_le_meta *le_ev = (void *) skb->data;
@@ -2688,6 +2706,10 @@ static inline void hci_le_meta_evt(struct hci_dev *hdev, struct sk_buff *skb)
 		hci_le_conn_complete_evt(hdev, skb);
 		break;
 
+	case HCI_EV_LE_ADVERTISING_REPORT:
+		hci_le_adv_report_evt(hdev, skb);
+		break;
+
 	default:
 		break;
 	}
-- 
1.7.1


^ permalink raw reply related

* [PATCH 03/12] Bluetooth: Protect 'adv_entries' with a RW lock
From: Andre Guedes @ 2011-05-06 17:05 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Andre Guedes
In-Reply-To: <1304701521-26459-1-git-send-email-andre.guedes@openbossa.org>

This patch adds a RW lock to protect concurrent operations on
adv_entries list.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
---
 include/net/bluetooth/hci_core.h |    1 +
 net/bluetooth/hci_core.c         |   21 +++++++++++++++++----
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 65135f8..2ceeadf 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -188,6 +188,7 @@ struct hci_dev {
 	struct list_head	remote_oob_data;
 
 	struct list_head	adv_entries;
+	rwlock_t		adv_entries_lock;
 
 	struct hci_dev_stats	stat;
 
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 0ba3c39..89d7cc8 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -1208,6 +1208,8 @@ int hci_adv_entries_clear(struct hci_dev *hdev)
 {
 	struct list_head *p, *n;
 
+	write_lock_bh(&hdev->adv_entries_lock);
+
 	list_for_each_safe(p, n, &hdev->adv_entries) {
 		struct adv_entry *entry;
 
@@ -1217,6 +1219,8 @@ int hci_adv_entries_clear(struct hci_dev *hdev)
 		kfree(entry);
 	}
 
+	write_unlock_bh(&hdev->adv_entries_lock);
+
 	BT_DBG("%s adv cache cleared", hdev->name);
 
 	return 0;
@@ -1225,17 +1229,23 @@ int hci_adv_entries_clear(struct hci_dev *hdev)
 struct adv_entry *hci_find_adv_entry(struct hci_dev *hdev, bdaddr_t *bdaddr)
 {
 	struct list_head *p;
+	struct adv_entry *res = NULL;
+
+	read_lock_bh(&hdev->adv_entries_lock);
 
 	list_for_each(p, &hdev->adv_entries) {
 		struct adv_entry *entry;
 
 		entry = list_entry(p, struct adv_entry, list);
 
-		if (bacmp(bdaddr, &entry->bdaddr) == 0)
-			return entry;
+		if (bacmp(bdaddr, &entry->bdaddr) == 0) {
+			res = entry;
+			goto out;
+		}
 	}
-
-	return NULL;
+out:
+	read_unlock_bh(&hdev->adv_entries_lock);
+	return res;
 }
 
 static inline int is_connectable_adv(u8 evt_type)
@@ -1267,7 +1277,9 @@ int hci_add_adv_entry(struct hci_dev *hdev,
 	bacpy(&entry->bdaddr, &ev->bdaddr);
 	entry->bdaddr_type = ev->bdaddr_type;
 
+	write_lock(&hdev->adv_entries_lock);
 	list_add(&entry->list, &hdev->adv_entries);
+	write_unlock(&hdev->adv_entries_lock);
 
 	BT_DBG("%s adv entry added: address %s type %u", hdev->name,
 				batostr(&entry->bdaddr), entry->bdaddr_type);
@@ -1342,6 +1354,7 @@ int hci_register_dev(struct hci_dev *hdev)
 	INIT_LIST_HEAD(&hdev->remote_oob_data);
 
 	INIT_LIST_HEAD(&hdev->adv_entries);
+	rwlock_init(&hdev->adv_entries_lock);
 
 	INIT_WORK(&hdev->power_on, hci_power_on);
 	INIT_WORK(&hdev->power_off, hci_power_off);
-- 
1.7.1


^ permalink raw reply related

* [PATCH 02/12] Bluetooth: LE advertising cache
From: Andre Guedes @ 2011-05-06 17:05 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Andre Guedes
In-Reply-To: <1304701521-26459-1-git-send-email-andre.guedes@openbossa.org>

This patch implements the LE advertising cache. It stores sensitive
information (bdaddr and bdaddr_type so far) gathered from LE
advertising report events.

Only advertising entries from connectables devices are added to the
cache.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
---
 include/net/bluetooth/hci_core.h |   13 +++++++
 net/bluetooth/hci_core.c         |   74 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 87 insertions(+), 0 deletions(-)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 14cc324..65135f8 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -89,6 +89,12 @@ struct oob_data {
 	u8 randomizer[16];
 };
 
+struct adv_entry {
+	struct list_head list;
+	bdaddr_t bdaddr;
+	u8 bdaddr_type;
+};
+
 #define NUM_REASSEMBLY 4
 struct hci_dev {
 	struct list_head list;
@@ -181,6 +187,8 @@ struct hci_dev {
 
 	struct list_head	remote_oob_data;
 
+	struct list_head	adv_entries;
+
 	struct hci_dev_stats	stat;
 
 	struct sk_buff_head	driver_init;
@@ -526,6 +534,11 @@ int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 *hash,
 								u8 *randomizer);
 int hci_remove_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr);
 
+int hci_adv_entries_clear(struct hci_dev *hdev);
+struct adv_entry *hci_find_adv_entry(struct hci_dev *hdev, bdaddr_t *bdaddr);
+int hci_add_adv_entry(struct hci_dev *hdev,
+					struct hci_ev_le_advertising_info *ev);
+
 void hci_del_off_timer(struct hci_dev *hdev);
 
 void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb);
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index b6bda3f..0ba3c39 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -1204,6 +1204,77 @@ int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 *hash,
 	return 0;
 }
 
+int hci_adv_entries_clear(struct hci_dev *hdev)
+{
+	struct list_head *p, *n;
+
+	list_for_each_safe(p, n, &hdev->adv_entries) {
+		struct adv_entry *entry;
+
+		entry = list_entry(p, struct adv_entry, list);
+
+		list_del(p);
+		kfree(entry);
+	}
+
+	BT_DBG("%s adv cache cleared", hdev->name);
+
+	return 0;
+}
+
+struct adv_entry *hci_find_adv_entry(struct hci_dev *hdev, bdaddr_t *bdaddr)
+{
+	struct list_head *p;
+
+	list_for_each(p, &hdev->adv_entries) {
+		struct adv_entry *entry;
+
+		entry = list_entry(p, struct adv_entry, list);
+
+		if (bacmp(bdaddr, &entry->bdaddr) == 0)
+			return entry;
+	}
+
+	return NULL;
+}
+
+static inline int is_connectable_adv(u8 evt_type)
+{
+	if (evt_type == ADV_IND || evt_type == ADV_DIRECT_IND)
+		return 1;
+
+	return 0;
+}
+
+int hci_add_adv_entry(struct hci_dev *hdev,
+					struct hci_ev_le_advertising_info *ev)
+{
+	struct adv_entry *entry;
+
+	if (!is_connectable_adv(ev->evt_type))
+		return -EINVAL;
+
+	entry = hci_find_adv_entry(hdev, &ev->bdaddr);
+	/* Only new entries should be added to adv_entries. So, if
+	 * bdaddr was found, don't add it. */
+	if (entry)
+		return 0;
+
+	entry = kzalloc(sizeof(*entry), GFP_ATOMIC);
+	if (!entry)
+		return -ENOMEM;
+
+	bacpy(&entry->bdaddr, &ev->bdaddr);
+	entry->bdaddr_type = ev->bdaddr_type;
+
+	list_add(&entry->list, &hdev->adv_entries);
+
+	BT_DBG("%s adv entry added: address %s type %u", hdev->name,
+				batostr(&entry->bdaddr), entry->bdaddr_type);
+
+	return 0;
+}
+
 /* Register HCI device */
 int hci_register_dev(struct hci_dev *hdev)
 {
@@ -1270,6 +1341,8 @@ int hci_register_dev(struct hci_dev *hdev)
 
 	INIT_LIST_HEAD(&hdev->remote_oob_data);
 
+	INIT_LIST_HEAD(&hdev->adv_entries);
+
 	INIT_WORK(&hdev->power_on, hci_power_on);
 	INIT_WORK(&hdev->power_off, hci_power_off);
 	setup_timer(&hdev->off_timer, hci_auto_off, (unsigned long) hdev);
@@ -1350,6 +1423,7 @@ int hci_unregister_dev(struct hci_dev *hdev)
 	hci_uuids_clear(hdev);
 	hci_link_keys_clear(hdev);
 	hci_remote_oob_data_clear(hdev);
+	hci_adv_entries_clear(hdev);
 	hci_dev_unlock_bh(hdev);
 
 	__hci_dev_put(hdev);
-- 
1.7.1


^ permalink raw reply related

* [PATCH 01/12] Bluetooth: Add advertising report meta event structs
From: Andre Guedes @ 2011-05-06 17:05 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Anderson Briglia
In-Reply-To: <1304701521-26459-1-git-send-email-andre.guedes@openbossa.org>

From: Anderson Briglia <anderson.briglia@openbossa.org>

This patch adds definitions and a new struct for Advertising Report
Event from LE and Dual Mode controllers.

Signed-off-by: Anderson Briglia <anderson.briglia@openbossa.org>
---
 include/net/bluetooth/hci.h |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index e0a3cf1..ec0fb2d 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -1029,6 +1029,25 @@ struct hci_ev_le_conn_complete {
 	__u8     clk_accurancy;
 } __packed;
 
+/* Advertising report event types */
+#define ADV_IND		0x00
+#define ADV_DIRECT_IND	0x01
+#define ADV_SCAN_IND	0x02
+#define ADV_NONCONN_IND	0x03
+#define ADV_SCAN_RSP	0x04
+
+#define ADDR_LE_DEV_PUBLIC	0x00
+#define ADDR_LE_DEV_RANDOM	0x01
+
+#define HCI_EV_LE_ADVERTISING_REPORT	0x02
+struct hci_ev_le_advertising_info {
+	__u8	 evt_type;
+	__u8	 bdaddr_type;
+	bdaddr_t bdaddr;
+	__u8	 length;
+	__u8	 data[0];
+} __packed;
+
 /* Internal events generated by Bluetooth stack */
 #define HCI_EV_STACK_INTERNAL	0xfd
 struct hci_ev_stack_internal {
-- 
1.7.1


^ permalink raw reply related

* [PATCH 00/12] Caching LE advertising information
From: Andre Guedes @ 2011-05-06 17:05 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Andre Guedes

Hi all,

This patchset implements the LE advertising cache which is used
to establish LE connections.

Today, we cannot establish LE connections (via l2cap socket) with
devices which use random address type. To achieve that, we came up
with a solution where the host should be able to infer the address
type (public or random) from the device it wants to connect to.

The approach this patchset implements is: during the LE scanning,
the host stores the address and the address type gathered from
advertising reports. These information are stored at the advertising
cache. So, during a LE connection, the host looks up the advertising
cache and gets the address type from the device it wants to connect
to.

Since the penality to connect to an unreachable device is relatively
high, we must keep only fresh advertising entries in the advertising
cache. So, before each LE scanning the advertising cache is cleared.
Also, after the LE scanning, a timer is set to clear the cache.

Thanks,

Andre Guedes.

Anderson Briglia (2):
  Bluetooth: Add advertising report meta event structs
  Bluetooth: Add advertising report meta event handler

Andre Guedes (10):
  Bluetooth: LE advertising cache
  Bluetooth: Protect 'adv_entries' with a RW lock
  Bluetooth: LE Set Scan Enable command complete event
  Bluetooth: Clear advertising cache before scanning
  Bluetooth: Advertising entries lifetime
  Bluetooth: Add 'dst_type' field to struct hci_conn
  Bluetooth: Add hci_le_conn_add()
  Bluetooth: Remove useless check in hci_connect()
  Bluetooth: Check advertising cache in hci_connect()
  Bluetooth: Set 'peer_addr_type' in hci_le_connect()

 include/net/bluetooth/hci.h      |   21 ++++++++
 include/net/bluetooth/hci_core.h |   19 ++++++++
 net/bluetooth/hci_conn.c         |   26 +++++++++-
 net/bluetooth/hci_core.c         |   96 ++++++++++++++++++++++++++++++++++++++
 net/bluetooth/hci_event.c        |   56 +++++++++++++++++++++-
 5 files changed, 213 insertions(+), 5 deletions(-)


^ permalink raw reply

* RFC: First pass at pretty hostname support
From: Bastien Nocera @ 2011-05-06 16:58 UTC (permalink / raw)
  To: BlueZ development

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

Most of the details are in the patch.

I just wanted to mention that:
"Bastien's desktop": good
"novo-0": bad

Ideas on how to implement the TODO items would be appreciated. I'm
currently thinking that a plugin to monitor the pretty hostname would be
the cleaner way. It would even allow us to change the adapter name on
the fly if the hostname (rather than the pretty hostname) changed.

Cheers

[-- 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: Gustavo F. Padovan @ 2011-05-06 15:12 UTC (permalink / raw)
  To: Bastien Nocera; +Cc: Luiz Augusto von Dentz, BlueZ development
In-Reply-To: <1304693789.16101.35.camel@novo.hadess.net>

Hi Bastien,

* Bastien Nocera <hadess@hadess.net> [2011-05-06 15:56:28 +0100]:

> 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.

> 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 +--

The gdbus changes need a new patch. It also needs to be applied to Obexd
ConnMan and oFono.

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

^ permalink raw reply

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

Hi,

> > 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?

Maybe sth like this:

diff --git a/input/device.c b/input/device.c
index 316b2cc..2da2030 100644
--- a/input/device.c
+++ b/input/device.c
@@ -250,14 +250,14 @@ 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;
 
        memset(&event, 0, sizeof(event));
        event.type      = type;
        event.code      = code;
        event.value     = value;
 
-       err = write(fd, &event, sizeof(event));
+       if (write(fd, &event, sizeof(event)) < 0)
+               error("input: send_event failed: %s", strerror(errno));
 }

-- 
BR
Szymon Janc

^ permalink raw reply related

* [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


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