summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2006-02-03 18:45:50 +0000
committerMarcel Holtmann <marcel@holtmann.org>2006-02-03 18:45:50 +0000
commit49244d8ca41191d042fbed0732bb14db99fd56c8 (patch)
treed0b2e75befc65103f7b04a45924a96bbeb1d5666
parentce9b410db80d60fbc6d12c02255319d8ff0c3a53 (diff)
Implement the gnip (reverse ping) support
-rw-r--r--tools/l2ping.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/tools/l2ping.c b/tools/l2ping.c
index 0fe3d11ac..0ae61c9d9 100644
--- a/tools/l2ping.c
+++ b/tools/l2ping.c
@@ -50,6 +50,7 @@ static int ident = 200;
static int delay = 1;
static int count = -1;
static int timeout = 10;
+static int reverse = 0;
/* Stats */
static int sent_pkt = 0;
@@ -144,13 +145,17 @@ static void ping(char *svr)
l2cap_cmd_hdr *cmd = (l2cap_cmd_hdr *) buf;
/* Build command header */
- cmd->code = L2CAP_ECHO_REQ;
cmd->ident = id;
cmd->len = htobs(size);
+ if (reverse)
+ cmd->code = L2CAP_ECHO_RSP;
+ else
+ cmd->code = L2CAP_ECHO_REQ;
+
gettimeofday(&tv_send, NULL);
- /* Send Echo Request */
+ /* Send Echo Command */
if (send(sk, buf, L2CAP_CMD_HDR_SIZE + size, 0) <= 0) {
perror("Send failed");
exit(1);
@@ -192,8 +197,9 @@ static void ping(char *svr)
continue;
/* Check type */
- if (cmd->code == L2CAP_ECHO_RSP)
+ if (!reverse && cmd->code == L2CAP_ECHO_RSP)
break;
+
if (cmd->code == L2CAP_COMMAND_REJ) {
printf("Peer doesn't support Echo packets\n");
exit(1);
@@ -226,7 +232,7 @@ static void usage(void)
{
printf("l2ping - L2CAP ping\n");
printf("Usage:\n");
- printf("\tl2ping [-i device] [-s size] [-c count] [-t timeout] [-f] <bdaddr>\n");
+ printf("\tl2ping [-i device] [-s size] [-c count] [-t timeout] [-f] [-r] <bdaddr>\n");
}
int main(int argc, char *argv[])
@@ -236,7 +242,7 @@ int main(int argc, char *argv[])
/* Default options */
bacpy(&bdaddr, BDADDR_ANY);
- while ((opt=getopt(argc,argv,"i:s:c:t:f")) != EOF) {
+ while ((opt=getopt(argc,argv,"i:s:c:t:fr")) != EOF) {
switch(opt) {
case 'i':
if (!strncasecmp(optarg, "hci", 3))
@@ -250,6 +256,11 @@ int main(int argc, char *argv[])
delay = 0;
break;
+ case 'r':
+ /* Use responses instead of requests */
+ reverse = 1;
+ break;
+
case 'c':
count = atoi(optarg);
break;