summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2009-01-13 11:17:17 +0100
committerMarcel Holtmann <marcel@holtmann.org>2009-01-13 11:17:17 +0100
commit22fdd674937bb927a00b35b84cca66dda76c6fd5 (patch)
tree1b187b211c2cb42ba1e3e4ac36d6931c0d58c9df /test
parent0472c96f4702fadcb684ff0f4b42ce044c235024 (diff)
Add command option for triggering dedicated bonding
Diffstat (limited to 'test')
-rw-r--r--test/l2test.c57
1 files changed, 55 insertions, 2 deletions
diff --git a/test/l2test.c b/test/l2test.c
index f8ff5f7d..babef00c 100644
--- a/test/l2test.c
+++ b/test/l2test.c
@@ -60,7 +60,8 @@ enum {
LSEND,
SENDDUMP,
LSENDDUMP,
- INFOREQ
+ INFOREQ,
+ PAIRING,
};
static unsigned char *buf;
@@ -840,6 +841,48 @@ failed:
close(sk);
}
+static void do_pairing(char *svr)
+{
+ struct sockaddr_l2 addr;
+ int sk, opt;
+
+ sk = socket(PF_BLUETOOTH, SOCK_RAW, BTPROTO_L2CAP);
+ if (sk < 0) {
+ perror("Can't create socket");
+ return;
+ }
+
+ memset(&addr, 0, sizeof(addr));
+ addr.l2_family = AF_BLUETOOTH;
+ bacpy(&addr.l2_bdaddr, &bdaddr);
+
+ if (bind(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
+ perror("Can't bind socket");
+ goto failed;
+ }
+
+ opt = L2CAP_LM_SECURE;
+
+ if (setsockopt(sk, SOL_L2CAP, L2CAP_LM, &opt, sizeof(opt)) < 0) {
+ perror("Can't set link mode");
+ goto failed;
+ }
+
+ memset(&addr, 0, sizeof(addr));
+ addr.l2_family = AF_BLUETOOTH;
+ str2ba(svr, &addr.l2_bdaddr);
+
+ if (connect(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0 ) {
+ perror("Can't connect socket");
+ goto failed;
+ }
+
+ printf("Pairing successful\n");
+
+failed:
+ close(sk);
+}
+
static void usage(void)
{
printf("l2test - L2CAP testing\n"
@@ -856,6 +899,7 @@ static void usage(void)
"\t-y connect, then send, then dump incoming data\n"
"\t-c connect, disconnect, connect, ...\n"
"\t-m multiple connects\n"
+ "\t-p trigger dedicated bonding\n"
"\t-z information request\n");
printf("Options:\n"
@@ -883,7 +927,7 @@ int main(int argc, char *argv[])
bacpy(&bdaddr, BDADDR_ANY);
- while ((opt=getopt(argc,argv,"rdscuwmnxyzb:i:P:I:O:B:N:L:C:D:X:RGAESMT")) != EOF) {
+ while ((opt=getopt(argc,argv,"rdscuwmnxyzpb:i:P:I:O:B:N:L:C:D:X:RGAESMT")) != EOF) {
switch(opt) {
case 'r':
mode = RECV;
@@ -935,6 +979,11 @@ int main(int argc, char *argv[])
need_addr = 1;
break;
+ case 'p':
+ mode = PAIRING;
+ need_addr = 1;
+ break;
+
case 'b':
data_size = atoi(optarg);
break;
@@ -1094,6 +1143,10 @@ int main(int argc, char *argv[])
case INFOREQ:
info_request(argv[optind]);
exit(0);
+
+ case PAIRING:
+ do_pairing(argv[optind]);
+ exit(0);
}
syslog(LOG_INFO, "Exit");