From: ilia.kolominsky@gmail.com
To: linux-bluetooth@vger.kernel.org
Cc: Ilia Kolomisnky <iliak@ti.com>
Subject: [PATCH] BlueZ: Added retries for BNEP connection setup.
Date: Sun, 22 Jan 2012 09:10:33 +0200 [thread overview]
Message-ID: <1327216233-17629-1-git-send-email-iliak@ti.com> (raw)
From: Ilia Kolomisnky <iliak@ti.com>
According to BNEP spec. section 2.6.3 and
in order to pass TP/BNEP/CTRL/BV-02-C certification test.
Signed-off-by: Ilia Kolomisnky <iliak@ti.com>
---
network/connection.c | 53 ++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 43 insertions(+), 10 deletions(-)
diff --git a/network/connection.c b/network/connection.c
index ca1f4b2..5c3819a 100644
--- a/network/connection.c
+++ b/network/connection.c
@@ -49,6 +49,8 @@
#include "connection.h"
#define NETWORK_PEER_INTERFACE "org.bluez.Network"
+#define CON_SETUP_RETRIES 3
+#define CON_SETUP_TO_MS 9000
typedef enum {
CONNECTED,
@@ -73,6 +75,8 @@ struct network_conn {
guint watch; /* Disconnect watch */
guint dc_id;
struct network_peer *peer;
+ char con_attempt;
+ guint con_to_src;
};
struct __service_16 {
@@ -218,6 +222,8 @@ static gboolean bnep_setup_cb(GIOChannel *chan, GIOCondition cond,
goto failed;
}
+ g_source_remove(nc->con_to_src);
+
errno = EPROTO;
if ((size_t) r < sizeof(*rsp)) {
@@ -289,13 +295,11 @@ failed:
return FALSE;
}
-static int bnep_connect(struct network_conn *nc)
-{
+static inline int bnep_send_conn_req(struct network_conn *nc) {
+
struct bnep_setup_conn_req *req;
struct __service_16 *s;
- struct timeval timeo;
unsigned char pkt[BNEP_MTU];
- int fd;
/* Send request */
req = (void *) pkt;
@@ -306,14 +310,43 @@ static int bnep_connect(struct network_conn *nc)
s->dst = htons(nc->id);
s->src = htons(BNEP_SVC_PANU);
- memset(&timeo, 0, sizeof(timeo));
- timeo.tv_sec = 30;
+ if (send(g_io_channel_unix_get_fd(nc->io), pkt, sizeof(*req) + sizeof(*s), 0) < 0) {
+ error("bnep connection setup send failed");
+ return -errno;
+ }
- fd = g_io_channel_unix_get_fd(nc->io);
- setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeo, sizeof(timeo));
+ nc->con_attempt++;
- if (send(fd, pkt, sizeof(*req) + sizeof(*s), 0) < 0)
- return -errno;
+ return 0;
+}
+
+static gboolean bnep_conn_req_to(gpointer user_data)
+{
+ struct network_conn *nc;
+ int err;
+
+ nc = (struct network_conn *) user_data;
+ if (nc->con_attempt == CON_SETUP_RETRIES) {
+ error("Too many bnep connection attempts, aborting connection setup");
+ }
+ else {
+ error("bnep connection setup TO, retrying...");
+
+ if (!bnep_send_conn_req(nc))
+ return TRUE;
+ }
+
+ cancel_connection(nc, "bnep setup failed");
+ return FALSE;
+}
+
+static int bnep_connect(struct network_conn *nc)
+{
+ int err;
+
+ if (err = bnep_send_conn_req(nc))
+ return err;
+ nc->con_to_src = g_timeout_add(CON_SETUP_TO_MS, bnep_conn_req_to, nc);
g_io_add_watch(nc->io, G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL,
(GIOFunc) bnep_setup_cb, nc);
--
1.7.4.1
next reply other threads:[~2012-01-22 7:10 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-22 7:10 ilia.kolominsky [this message]
2012-01-26 9:18 ` [PATCH] BlueZ: Added retries for BNEP connection setup Ilia, Kolominsky
2012-02-02 18:55 ` Johan Hedberg
2012-02-05 17:00 ` Ilia, Kolominsky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1327216233-17629-1-git-send-email-iliak@ti.com \
--to=ilia.kolominsky@gmail.com \
--cc=iliak@ti.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).