From: Stephen Crane <steve.crane@rococosoft.com>
To: bluez-devel@lists.sourceforge.net
Cc: jim.oleary@rococosoft.com, marcel@holtmann.org
Subject: Re: [Bluez-devel] Re: Small fix for L2CAP MTU
Date: Thu, 26 May 2005 14:55:29 +0100 [thread overview]
Message-ID: <1117115729.15042.100.camel@baroque.rococosoft.com> (raw)
In-Reply-To: <1117103519.12036.35.camel@pegasus>
[-- Attachment #1: Type: text/plain, Size: 975 bytes --]
Hi Marcel,
On Thu, 2005-05-26 at 12:31 +0200, Marcel Holtmann wrote:
> Hi Steve,
>
> > I've attached the two dump files. Let me know if you need any more info.
>
> I don't see it. No side is asking for a MTU with the size 50 in the
> configuration process of the L2CAP connection setup.
Sorry if I was unclear. The fix causes the omtu to be set to the peer's
value, only if we don't care about the omtu. No further negotiation is
performed.
I have attached a pair of test programs which highlight this:
* listener sets imtu and omtu to be 512
* connector connects to its first argument, setting omtu to the value of
its second argument.
Without the patch, the output of connector is:
$ ./connector 00:80:98:24:4F:19 50
imtu=672 omtu=512
With the patch, its output is:
$ ./connector 00:80:98:24:4F:19 50
imtu=672 omtu=50
Does this make sense?
Steve
--
Stephen Crane, Rococo Software Ltd. http://www.rococosoft.com
steve.crane@rococosoft.com +353-1-6601315 (ext 209)
[-- Attachment #2: connector.c --]
[-- Type: text/x-csrc, Size: 1302 bytes --]
#include <sys/socket.h>
#include <netinet/in.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <bluetooth/hci_lib.h>
#include <bluetooth/l2cap.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
struct sockaddr_l2 addr;
int s = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP);
int opt, n;
struct l2cap_options opts;
char buf[1024];
int mtu = atoi(argv[2]);
if (0 > s) {
perror("socket");
return -1;
}
opt = sizeof(struct l2cap_options);
opts.imtu = L2CAP_DEFAULT_MTU;
opts.omtu = mtu;
if (0 > setsockopt(s, SOL_L2CAP, L2CAP_OPTIONS, &opts, opt)) {
perror("setsockopt(l2cap)");
close(s);
return -1;
}
addr.l2_psm = htobs(0x1001);
addr.l2_family = AF_BLUETOOTH;
baswap(&addr.l2_bdaddr, strtoba(argv[1]));
if (0 > connect(s, (struct sockaddr *)&addr, sizeof(addr))) {
perror("connect");
return -1;
}
if (0 > getsockopt(s, SOL_L2CAP, L2CAP_OPTIONS, &opts, &opt)) {
perror("getsockopt");
return -1;
}
printf("imtu=%d omtu=%d\n", opts.imtu, opts.omtu);
n = sizeof(buf);
if (mtu == 0)
n = opts.omtu;
else if (n > mtu)
n = mtu;
n = write(s, buf, n);
if (0 > n) {
perror("write");
return -1;
}
printf("wrote %d bytes\n", n);
close(s);
return 0;
}
[-- Attachment #3: listener.c --]
[-- Type: text/x-csrc, Size: 1615 bytes --]
#include <unistd.h>
#include <malloc.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <bluetooth/hci_lib.h>
#include <bluetooth/l2cap.h>
int main(int argc, char *argv[])
{
int l = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP);
struct sockaddr_l2 addr;
int opt = 0;
int s, addr_len, n;
struct l2cap_options opts;
char buf[1024];
if (0 > l) {
perror("socket");
return -1;
}
memset(&addr, 0, sizeof(addr));
addr.l2_family = AF_BLUETOOTH;
addr.l2_psm = htobs(0x1001);
bacpy(&addr.l2_bdaddr, BDADDR_ANY);
if (0 > bind(l, (struct sockaddr *)&addr, sizeof(addr))) {
perror("bind");
return -1;
}
opts.imtu = 512;
opts.omtu = 512;
if (0 > setsockopt(l, SOL_L2CAP, L2CAP_OPTIONS, &opts, sizeof(opts))) {
perror("setsockopt(l2cap)");
close(s);
return -1;
}
if (0 > listen(l, 10)) {
perror("listen");
return -1;
}
s = accept(l, (struct sockaddr *)&addr, &addr_len);
if (0 > s) {
perror("accept");
return -1;
}
if (0 > getpeername(s, (struct sockaddr *)&addr, &addr_len)) {
perror("getpeername");
return -1;
}
printf("got connection from %s\n", batostr(&addr.l2_bdaddr));
opt = sizeof(struct l2cap_options);
if (0 > getsockopt(s, SOL_L2CAP, L2CAP_OPTIONS, &opts, &opt)) {
perror("getsockopt");
return -1;
}
printf("imtu=%d omtu=%d\n", opts.imtu, opts.omtu);
n = read(s, buf, sizeof(buf));
if (0 > n) {
perror("read");
return -1;
}
printf("read %d bytes\n", n);
close(s);
close(l);
return 0;
}
prev parent reply other threads:[~2005-05-26 13:55 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-05-25 14:41 Small fix for L2CAP MTU Stephen Crane
2005-05-25 14:46 ` [Bluez-devel] " Marcel Holtmann
2005-05-25 15:02 ` Stephen Crane
2005-05-25 15:59 ` Marcel Holtmann
2005-05-26 10:13 ` Stephen Crane
2005-05-26 10:31 ` Marcel Holtmann
2005-05-26 10:45 ` [Bluez-devel] Output power Pieter De Mil
2005-05-26 10:48 ` Marcel Holtmann
2005-05-27 18:34 ` Pieter De Mil
2005-05-27 18:44 ` Marcel Holtmann
2005-05-26 13:55 ` Stephen Crane [this message]
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=1117115729.15042.100.camel@baroque.rococosoft.com \
--to=steve.crane@rococosoft.com \
--cc=bluez-devel@lists.sourceforge.net \
--cc=jim.oleary@rococosoft.com \
--cc=marcel@holtmann.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