summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2002-10-14 20:46:47 +0000
committerMarcel Holtmann <marcel@holtmann.org>2002-10-14 20:46:47 +0000
commitb5edb3c0a92674b27a95f7968e18bb51150c52f6 (patch)
treeb42c065dd9ed371f2b2b72f47062b0619c126712
parent342bdf14bfe6340a8fcf6b6a412685a94ad843b5 (diff)
Move testing programs from tools directory into the test directory
-rw-r--r--Makefile.am2
-rw-r--r--configure.in2
-rw-r--r--test/Makefile.am5
-rw-r--r--test/attest.c178
-rw-r--r--test/l2test.c (renamed from tools/l2test.c)0
-rw-r--r--test/rctest.c (renamed from tools/rctest.c)0
-rw-r--r--test/scotest.c (renamed from tools/scotest.c)0
-rw-r--r--tools/Makefile.am2
8 files changed, 186 insertions, 3 deletions
diff --git a/Makefile.am b/Makefile.am
index a9fe27a4..d0351af9 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -2,4 +2,4 @@
# $Id$
#
-SUBDIRS := hcid tools rfcomm scripts pcmcia
+SUBDIRS := hcid tools rfcomm test scripts pcmcia
diff --git a/configure.in b/configure.in
index af2f6ee1..529f231b 100644
--- a/configure.in
+++ b/configure.in
@@ -84,4 +84,4 @@ AC_ARG_ENABLE(pcmcia,
AC_TEST_DIR(/etc/pcmcia, PCMCIA=pcmcia, PCMCIA=)
fi ])
-AC_OUTPUT(Makefile hcid/Makefile tools/Makefile rfcomm/Makefile scripts/Makefile pcmcia/Makefile)
+AC_OUTPUT(Makefile hcid/Makefile tools/Makefile rfcomm/Makefile test/Makefile scripts/Makefile pcmcia/Makefile)
diff --git a/test/Makefile.am b/test/Makefile.am
new file mode 100644
index 00000000..dc84f46f
--- /dev/null
+++ b/test/Makefile.am
@@ -0,0 +1,5 @@
+#
+# $Id$
+#
+
+noinst_PROGRAMS = l2test scotest rctest attest
diff --git a/test/attest.c b/test/attest.c
new file mode 100644
index 00000000..078bb886
--- /dev/null
+++ b/test/attest.c
@@ -0,0 +1,178 @@
+/*
+ *
+ * Programm for testing AT commands over Bluetooth RFCOMM
+ *
+ * Copyright (C) 2001-2002 Marcel Holtmann <marcel@holtmann.org>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <termios.h>
+#include <sys/time.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+
+#include <bluetooth/bluetooth.h>
+#include <bluetooth/rfcomm.h>
+
+
+
+static int at_command(int fd, char *cmd, int to)
+{
+ fd_set rfds;
+ struct timeval timeout;
+ unsigned char buf[1024];
+ int sel, len, i, n;
+
+ write(fd, cmd, strlen(cmd));
+
+ for (i = 0; i < 100; i++) {
+
+ FD_ZERO(&rfds);
+ FD_SET(fd, &rfds);
+
+ timeout.tv_sec = 0;
+ timeout.tv_usec = to;
+
+ if ((sel = select(fd + 1, &rfds, NULL, NULL, &timeout)) > 0) {
+
+ if (FD_ISSET(fd, &rfds)) {
+ memset(buf, 0, sizeof(buf));
+ len = read(fd, buf, sizeof(buf));
+ for (n = 0; n < len; n++)
+ printf("%c", buf[n]);
+ if (strstr(buf, "\r\nOK") != NULL)
+ break;
+ if (strstr(buf, "\r\nERROR") != NULL)
+ break;
+ if (strstr(buf, "\r\nCONNECT") != NULL)
+ break;
+ }
+
+ }
+
+ }
+
+ return 0;
+}
+
+
+static int open_device(char *device)
+{
+ int fd;
+ struct termios ti;
+
+ if ((fd = open(device, O_RDWR | O_NOCTTY | O_NONBLOCK)) < 0) {
+ printf("Can't open serial port. %s (%d)\n", strerror(errno), errno);
+ return -1;
+ }
+
+ tcflush(fd, TCIOFLUSH);
+
+ /* Switch tty to RAW mode */
+ cfmakeraw(&ti);
+ tcsetattr(fd, TCSANOW, &ti);
+
+ return fd;
+}
+
+
+static int open_socket(bdaddr_t *bdaddr, uint8_t channel)
+{
+ struct sockaddr_rc remote_addr, local_addr;
+ int s;
+
+ if ((s = socket(PF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM)) < 0) {
+ printf("Can't create socket. %s (%d)\n", strerror(errno), errno);
+ return -1;
+ }
+
+ memset(&local_addr, 0, sizeof(local_addr));
+ local_addr.rc_family = AF_BLUETOOTH;
+ bacpy(&local_addr.rc_bdaddr, BDADDR_ANY);
+ if (bind(s, (struct sockaddr *)&local_addr, sizeof(local_addr)) < 0) {
+ printf("Can't bind socket. %s (%d)\n", strerror(errno), errno);
+ close(s);
+ return -1;
+ }
+
+ memset(&remote_addr, 0, sizeof(remote_addr));
+ remote_addr.rc_family = AF_BLUETOOTH;
+ bacpy(&remote_addr.rc_bdaddr, bdaddr);
+ remote_addr.rc_channel = channel;
+ if (connect(s, (struct sockaddr *)&remote_addr, sizeof(remote_addr)) < 0) {
+ printf("Can't connect. %s (%d)\n", strerror(errno), errno);
+ close(s);
+ return -1;
+ }
+
+ return s;
+}
+
+
+static void usage(void)
+{
+ printf("Usage:\n\tattest <device> | <bdaddr> [channel]\n");
+}
+
+
+int main(int argc, char *argv[])
+{
+ int fd;
+
+ bdaddr_t bdaddr;
+ uint8_t channel;
+
+ switch (argc) {
+ case 2:
+ str2ba(argv[1], &bdaddr);
+ channel = 1;
+ break;
+ case 3:
+ str2ba(argv[1], &bdaddr);
+ channel = atoi(argv[2]);
+ break;
+ default:
+ usage();
+ exit(-1);
+ }
+
+ if (bacmp(BDADDR_ANY, &bdaddr)) {
+ printf("Connecting to %s on channel %d\n", argv[1], channel);
+ fd = open_socket(&bdaddr, channel);
+ } else {
+ printf("Opening device %s\n", argv[1]);
+ fd = open_device(argv[1]);
+ }
+
+ if (fd < 0)
+ exit(-2);
+
+ at_command(fd, "ATZ\r\n", 10000);
+ at_command(fd, "AT+CPBS=\"ME\"\r\n", 10000);
+ at_command(fd, "AT+CPBR=1,100\r\n", 100000);
+
+ close(fd);
+
+ return 0;
+}
diff --git a/tools/l2test.c b/test/l2test.c
index b08b2d34..b08b2d34 100644
--- a/tools/l2test.c
+++ b/test/l2test.c
diff --git a/tools/rctest.c b/test/rctest.c
index 0584a6a9..0584a6a9 100644
--- a/tools/rctest.c
+++ b/test/rctest.c
diff --git a/tools/scotest.c b/test/scotest.c
index dcb1acdf..dcb1acdf 100644
--- a/tools/scotest.c
+++ b/test/scotest.c
diff --git a/tools/Makefile.am b/tools/Makefile.am
index b4049c32..9ff29c14 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -9,6 +9,6 @@ bin_PROGRAMS = hcitool l2ping
man_MANS = hciattach.8 l2ping.8
-noinst_PROGRAMS = ppporc l2test scotest rctest
+noinst_PROGRAMS = ppporc
EXTRA_DIST = $(man_MANS)