Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 14 Oct 2012 09:19:11 +0100 (BST)
From:      Iain Hibbert <plunky@rya-online.net>
To:        Andreas Longwitz <longwitz@incore.de>
Cc:        freebsd-bluetooth@freebsd.org
Subject:   Re: btpand problem
Message-ID:  <alpine.NEB.2.00.1210140917360.673@galant.ukfsn.org>
In-Reply-To: <alpine.NEB.2.00.1210140843330.548@galant.ukfsn.org>
References:  <507736A8.4050605@incore.de> <BDA3CA14-92C0-414E-9D55-E96EA7A73312@gmail.com> <5077490F.7010901@incore.de> <CAFPOs6pF51wy9PvKLn4-OnrOqo8hU1S=P5PzTFwgUppBjqAtuA@mail.gmail.com> <alpine.NEB.2.00.1210120949170.628@galant.ukfsn.org> <50782E05.5080005@incore.de> <alpine.NEB.2.00.1210122254010.965@galant.ukfsn.org> <CAFPOs6qWVAcSuPz6%2BB=3uq_KqCXa=YcXwx-PNncGVrbDE8AimQ@mail.gmail.com> <5079E8F7.5050903@incore.de> <alpine.NEB.2.00.1210140843330.548@galant.ukfsn.org>

index | next in thread | previous in thread | raw e-mail

[-- Attachment #1 --]
On Sun, 14 Oct 2012, Iain Hibbert wrote:

> but, btpand should also ensure that the buffer sizes are suitable. The
> server_init() function already does this in FreeBSD, though I also added
> some code to increase the RCVBUF size in NetBSD code, and also added (but
> didn't yet commit) the similar for client code.. I will prepare a patch

patch for btpand attached

regards,
iain
[-- Attachment #2 --]
Index: client.c
===================================================================
RCS file: /home/ncvs/src/usr.sbin/bluetooth/btpand/client.c,v
retrieving revision 1.1
diff -u -p -r1.1 client.c
--- client.c	30 Jan 2009 22:23:21 -0000	1.1
+++ client.c	14 Oct 2012 08:15:50 -0000
@@ -47,7 +47,7 @@ client_init(void)
 	struct sockaddr_l2cap sa;
 	channel_t *chan;
 	socklen_t len;
-	int fd;
+	int fd, n;
 	uint16_t mru, mtu;
 
 	if (bdaddr_any(&remote_bdaddr))
@@ -97,6 +97,17 @@ client_init(void)
 		exit(EXIT_FAILURE);
 	}
 
+	len = sizeof(n);
+	if (getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &n, &len) == -1) {
+		log_err("Could not read SO_RCVBUF");
+		exit(EXIT_FAILURE);
+	}
+	if (n < (mru * 10)) {
+		n = mru * 10;
+		if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &n, sizeof(n)) == -1)
+			log_info("Could not increase SO_RCVBUF (from %d)", n);
+	}
+
 	len = sizeof(mtu);
 	if (getsockopt(fd, SOL_L2CAP, SO_L2CAP_OMTU, &mtu, &len) == -1) {
 		log_err("Could not get L2CAP OMTU: %m");
@@ -107,6 +118,27 @@ client_init(void)
 		exit(EXIT_FAILURE);
 	}
 
+	len = sizeof(n);
+	if (getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &n, &len) == -1) {
+		log_err("Could not get socket send buffer size: %m");
+		close(fd);
+		return;
+	}
+	if (n < (mtu * 2)) {
+		n = mtu * 2;
+		if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &n, sizeof(n)) == -1) {
+			log_err("Could not set socket send buffer size (%d): %m", n);
+			close(fd);
+			return;
+		}
+	}
+	n = mtu;
+	if (setsockopt(fd, SOL_SOCKET, SO_SNDLOWAT, &n, sizeof(n)) == -1) {
+		log_err("Could not set socket low water mark (%d): %m", n);
+		close(fd);
+		return;
+	}
+
 	chan = channel_alloc();
 	if (chan == NULL)
 		exit(EXIT_FAILURE);
Index: server.c
===================================================================
RCS file: /home/ncvs/src/usr.sbin/bluetooth/btpand/server.c,v
retrieving revision 1.2
diff -u -p -r1.2 server.c
--- server.c	2 Feb 2009 18:08:22 -0000	1.2
+++ server.c	14 Oct 2012 08:15:51 -0000
@@ -177,6 +177,18 @@ server_read(int s, short ev, void *arg)
 		return;
 	}
 
+	len = sizeof(n);
+	if (getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &n, &len) == -1) {
+		log_err("Could not read SO_RCVBUF");
+		close(fd);
+		return;
+	}
+	if (n < (mru * 10)) {
+		n = mru * 10;
+		if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &n, sizeof(n)) == -1)
+			log_info("Could not increase SO_RCVBUF (from %d)", n);
+	}
+
 	len = sizeof(mtu);
 	if (getsockopt(fd, SOL_L2CAP, SO_L2CAP_OMTU, &mtu, &len) == -1) {
 		log_err("Could not get L2CAP OMTU: %m");
help

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?alpine.NEB.2.00.1210140917360.673>