summaryrefslogtreecommitdiff
path: root/test/avtest.c
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@nokia.com>2009-09-02 22:17:02 +0300
committerJohan Hedberg <johan.hedberg@nokia.com>2009-09-02 22:19:51 +0300
commit793be3b7b1f640a47144d8b97cfafa2b75b3e9d7 (patch)
tree38e8037cf4c700bb520a32bb8b49e7338f8821c3 /test/avtest.c
parent5a1ad09af82f77e5bc4ba0fd03fbe837cf15dcb0 (diff)
Allow avtest to use 48 byte MTU also in SEND mode
This should be helpful for AVDTP tests where the IUT (bluetoothd) is supposed to send a fragmented message to us.
Diffstat (limited to 'test/avtest.c')
-rw-r--r--test/avtest.c56
1 files changed, 32 insertions, 24 deletions
diff --git a/test/avtest.c b/test/avtest.c
index 1b4e6dd7c..c26c072a4 100644
--- a/test/avtest.c
+++ b/test/avtest.c
@@ -365,6 +365,30 @@ static void process_sigchan(int srv_sk, int sk, unsigned char reject,
}
}
+static int set_minimum_mtu(int sk)
+{
+ struct l2cap_options l2o;
+ socklen_t optlen;
+
+ memset(&l2o, 0, sizeof(l2o));
+ optlen = sizeof(l2o);
+
+ if (getsockopt(sk, SOL_L2CAP, L2CAP_OPTIONS, &l2o, &optlen) < 0) {
+ perror("getsockopt");
+ return -1;
+ }
+
+ l2o.imtu = 48;
+ l2o.omtu = 48;
+
+ if (setsockopt(sk, SOL_L2CAP, L2CAP_OPTIONS, &l2o, sizeof(l2o)) < 0) {
+ perror("setsockopt");
+ return -1;
+ }
+
+ return 0;
+}
+
static void do_listen(const bdaddr_t *src, unsigned char reject, int fragment)
{
struct sockaddr_l2 addr;
@@ -387,27 +411,8 @@ static void do_listen(const bdaddr_t *src, unsigned char reject, int fragment)
goto error;
}
- if (fragment) {
- struct l2cap_options l2o;
-
- memset(&l2o, 0, sizeof(l2o));
- optlen = sizeof(l2o);
-
- if (getsockopt(sk, SOL_L2CAP, L2CAP_OPTIONS, &l2o,
- &optlen) < 0) {
- perror("getsockopt");
- goto error;
- }
-
- l2o.imtu = 48;
- l2o.omtu = 48;
-
- if (setsockopt(sk, SOL_L2CAP, L2CAP_OPTIONS, &l2o,
- sizeof(l2o)) < 0) {
- perror("setsockopt");
- goto error;
- }
- }
+ if (fragment)
+ set_minimum_mtu(sk);
if (listen(sk, 10)) {
perror("Can't listen on the socket");
@@ -438,7 +443,7 @@ error:
close(sk);
}
-static int do_connect(const bdaddr_t *src, const bdaddr_t *dst)
+static int do_connect(const bdaddr_t *src, const bdaddr_t *dst, int fragment)
{
struct sockaddr_l2 addr;
int sk, err;
@@ -458,6 +463,9 @@ static int do_connect(const bdaddr_t *src, const bdaddr_t *dst)
goto error;
}
+ if (fragment)
+ set_minimum_mtu(sk);
+
memset(&addr, 0, sizeof(addr));
addr.l2_family = AF_BLUETOOTH;
bacpy(&addr.l2_bdaddr, dst);
@@ -595,7 +603,7 @@ static void do_send(int sk, const bdaddr_t *src, const bdaddr_t *dst,
if (cmd == AVDTP_OPEN && len >= 2 &&
hdr->message_type == AVDTP_MSG_TYPE_ACCEPT)
- media_sock = do_connect(src, dst);
+ media_sock = do_connect(src, dst, 0);
}
static void usage()
@@ -704,7 +712,7 @@ int main(int argc, char *argv[])
do_listen(&src, cmd, fragment);
break;
case MODE_SEND:
- sk = do_connect(&src, &dst);
+ sk = do_connect(&src, &dst, fragment);
if (sk < 0)
exit(1);
do_send(sk, &src, &dst, cmd, invalid, preconf);