summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/l2test.c73
-rw-r--r--test/rctest.c37
2 files changed, 70 insertions, 40 deletions
diff --git a/test/l2test.c b/test/l2test.c
index fc966bd3..5c34b39e 100644
--- a/test/l2test.c
+++ b/test/l2test.c
@@ -30,6 +30,7 @@
#include <stdio.h>
#include <errno.h>
#include <ctype.h>
+#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <getopt.h>
@@ -82,6 +83,8 @@ static int count = 1;
/* Default delay after sending count number of frames */
static unsigned long delay = 0;
+static char *filename = NULL;
+
static int flowctl = 0;
static int master = 0;
static int auth = 0;
@@ -564,15 +567,27 @@ static void recv_mode(int sk)
}
}
-static void send_mode(int sk)
+static void do_send(int sk)
{
uint32_t seq;
- int i, len;
+ int i, fd, len;
syslog(LOG_INFO, "Sending ...");
- for (i = 6; i < data_size; i++)
- buf[i] = 0x7f;
+ if (filename) {
+ fd = open(filename, O_RDONLY);
+ if (fd < 0) {
+ syslog(LOG_ERR, "Open failed: %s (%d)",
+ strerror(errno), errno);
+ exit(1);
+ }
+ len = read(fd, buf, data_size);
+ send(sk, buf, len, 0);
+ return;
+ } else {
+ for (i = 6; i < data_size; i++)
+ buf[i] = 0x7f;
+ }
seq = 0;
while ((num_frames == -1) || (num_frames-- > 0)) {
@@ -582,13 +597,19 @@ static void send_mode(int sk)
len = send(sk, buf, data_size, 0);
if (len < 0 || len != data_size) {
- syslog(LOG_ERR, "Send failed: %s (%d)", strerror(errno), errno);
+ syslog(LOG_ERR, "Send failed: %s (%d)",
+ strerror(errno), errno);
exit(1);
}
if (num_frames && delay && count && !(seq % count))
usleep(delay);
}
+}
+
+static void send_mode(int sk)
+{
+ do_send(sk);
syslog(LOG_INFO, "Closing channel ...");
if (shutdown(sk, SHUT_RDWR) < 0)
@@ -599,28 +620,7 @@ static void send_mode(int sk)
static void senddump_mode(int sk)
{
- uint32_t seq;
- int i;
-
- syslog(LOG_INFO, "Sending ...");
-
- for (i = 6; i < data_size; i++)
- buf[i] = 0x7f;
-
- seq = 0;
- while ((num_frames == -1) || (num_frames-- > 0)) {
- *(uint32_t *) buf = htobl(seq);
- *(uint16_t *) (buf + 4) = htobs(data_size);
- seq++;
-
- if (send(sk, buf, data_size, 0) <= 0) {
- syslog(LOG_ERR, "Send failed: %s (%d)", strerror(errno), errno);
- exit(1);
- }
-
- if (num_frames && delay && count && !(seq % count))
- usleep(delay);
- }
+ do_send(sk);
dump_mode(sk);
}
@@ -692,8 +692,9 @@ static void usage(void)
printf("Options:\n"
"\t[-b bytes] [-i device] [-P psm]\n"
"\t[-I imtu] [-O omtu]\n"
- "\t[-N num] send num frames (default = infinite)\n"
"\t[-L seconds] enable SO_LINGER\n"
+ "\t[-B filename] use data packets from file\n"
+ "\t[-N num] send num frames (default = infinite)\n"
"\t[-C num] send num frames before delay (default = 1)\n"
"\t[-D milliseconds] delay after sending num frames (default = 0)\n"
"\t[-R] reliable mode\n"
@@ -705,14 +706,14 @@ static void usage(void)
"\t[-M] become master\n");
}
-int main(int argc ,char *argv[])
+int main(int argc, char *argv[])
{
struct sigaction sa;
int opt, sk, mode = RECV, need_addr = 0;
bacpy(&bdaddr, BDADDR_ANY);
- while ((opt=getopt(argc,argv,"rdscuwmnxyb:i:P:I:O:N:L:C:D:RGFAESM")) != EOF) {
+ while ((opt=getopt(argc,argv,"rdscuwmnxyb:i:P:I:O:B:N:L:C:D:RGFAESM")) != EOF) {
switch(opt) {
case 'r':
mode = RECV;
@@ -786,6 +787,14 @@ int main(int argc ,char *argv[])
linger = atoi(optarg);
break;
+ case 'B':
+ filename = strdup(optarg);
+ break;
+
+ case 'N':
+ num_frames = atoi(optarg);
+ break;
+
case 'C':
count = atoi(optarg);
break;
@@ -822,10 +831,6 @@ int main(int argc ,char *argv[])
socktype = SOCK_DGRAM;
break;
- case 'N':
- num_frames = atoi(optarg);
- break;
-
default:
usage();
exit(1);
diff --git a/test/rctest.c b/test/rctest.c
index 1f26c4c7..17d7c5d3 100644
--- a/test/rctest.c
+++ b/test/rctest.c
@@ -29,6 +29,7 @@
#include <stdio.h>
#include <errno.h>
#include <ctype.h>
+#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <getopt.h>
@@ -70,6 +71,8 @@ static unsigned long delay = 0;
static bdaddr_t bdaddr;
static uint8_t channel = 10;
+static char *filename = NULL;
+
static int master = 0;
static int auth = 0;
static int encrypt = 0;
@@ -329,15 +332,27 @@ static void recv_mode(int sk)
}
}
-static void send_mode(int sk)
+static void do_send(int sk)
{
uint32_t seq;
- int i;
+ int i, fd, len;
syslog(LOG_INFO,"Sending ...");
- for (i = 6; i < data_size; i++)
- buf[i] = 0x7f;
+ if (filename) {
+ fd = open(filename, O_RDONLY);
+ if (fd < 0) {
+ syslog(LOG_ERR, "Open failed: %s (%d)",
+ strerror(errno), errno);
+ exit(1);
+ }
+ len = read(fd, buf, data_size);
+ send(sk, buf, len, 0);
+ return;
+ } else {
+ for (i = 6; i < data_size; i++)
+ buf[i] = 0x7f;
+ }
seq = 0;
while ((num_frames == -1) || (num_frames-- > 0)) {
@@ -354,6 +369,11 @@ static void send_mode(int sk)
if (num_frames && delay && count && !(seq % count))
usleep(delay);
}
+}
+
+static void send_mode(int sk)
+{
+ do_send(sk);
syslog(LOG_INFO, "Closing channel ...");
if (shutdown(sk, SHUT_RDWR) < 0)
@@ -407,6 +427,7 @@ static void usage(void)
printf("Options:\n"
"\t[-b bytes] [-i device] [-P channel]\n"
"\t[-L seconds] enabled SO_LINGER option\n"
+ "\t[-B filename] use data packets from file\n"
"\t[-N num] number of frames to send\n"
"\t[-C num] send num frames before delay (default = 1)\n"
"\t[-D milliseconds] delay after sending num frames (default = 0)\n"
@@ -416,14 +437,14 @@ static void usage(void)
"\t[-M] become master\n");
}
-int main(int argc ,char *argv[])
+int main(int argc, char *argv[])
{
struct sigaction sa;
int opt, sk, mode = RECV, need_addr = 0;
bacpy(&bdaddr, BDADDR_ANY);
- while ((opt=getopt(argc,argv,"rdscuwmnb:i:P:N:MAESL:C:D:")) != EOF) {
+ while ((opt=getopt(argc,argv,"rdscuwmnb:i:P:B:N:MAESL:C:D:")) != EOF) {
switch (opt) {
case 'r':
mode = RECV;
@@ -497,6 +518,10 @@ int main(int argc ,char *argv[])
linger = atoi(optarg);
break;
+ case 'B':
+ filename = strdup(optarg);
+ break;
+
case 'N':
num_frames = atoi(optarg);
break;