2001-08-02 10:40:48 +08:00
|
|
|
/*
|
2004-03-03 10:03:49 +08:00
|
|
|
*
|
2005-01-30 02:21:47 +08:00
|
|
|
* Bluetooth packet analyzer - HCI sniffer
|
2004-03-03 10:03:49 +08:00
|
|
|
*
|
|
|
|
* Copyright (C) 2000-2002 Maxim Krasnyansky <maxk@qualcomm.com>
|
2005-01-30 02:21:47 +08:00
|
|
|
* Copyright (C) 2003-2005 Marcel Holtmann <marcel@holtmann.org>
|
2004-03-03 10:03:49 +08:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* $Id$
|
2001-08-02 10:40:48 +08:00
|
|
|
*/
|
|
|
|
|
2004-06-11 03:17:36 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2001-08-02 10:40:48 +08:00
|
|
|
#include <stdio.h>
|
2004-03-03 10:03:49 +08:00
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
2001-08-02 10:40:48 +08:00
|
|
|
#include <unistd.h>
|
2005-06-14 21:06:03 +08:00
|
|
|
#include <stdlib.h>
|
2001-08-02 10:40:48 +08:00
|
|
|
#include <string.h>
|
2002-05-24 07:13:30 +08:00
|
|
|
#include <getopt.h>
|
2005-06-14 21:06:03 +08:00
|
|
|
#include <sys/stat.h>
|
2002-12-08 08:37:07 +08:00
|
|
|
#include <sys/types.h>
|
2004-03-03 10:03:49 +08:00
|
|
|
#include <sys/ioctl.h>
|
2005-06-14 21:06:03 +08:00
|
|
|
#include <sys/socket.h>
|
2001-08-02 10:40:48 +08:00
|
|
|
|
|
|
|
#include <bluetooth/bluetooth.h>
|
|
|
|
#include <bluetooth/hci.h>
|
2002-03-20 02:19:34 +08:00
|
|
|
#include <bluetooth/hci_lib.h>
|
2001-08-02 10:40:48 +08:00
|
|
|
|
2005-06-14 21:06:03 +08:00
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netdb.h>
|
|
|
|
|
2004-02-29 09:14:47 +08:00
|
|
|
#include "parser.h"
|
|
|
|
#include "sdp.h"
|
2001-08-16 08:45:16 +08:00
|
|
|
|
2005-06-04 16:39:59 +08:00
|
|
|
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
|
|
|
static inline uint64_t ntoh64(uint64_t n)
|
|
|
|
{
|
|
|
|
uint64_t h;
|
|
|
|
uint64_t tmp = ntohl(n & 0x00000000ffffffff);
|
|
|
|
h = ntohl(n >> 32);
|
|
|
|
h |= tmp << 32;
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
#elif __BYTE_ORDER == __BIG_ENDIAN
|
|
|
|
#define ntoh64(x) (x)
|
|
|
|
#else
|
|
|
|
#error "Unknown byte order"
|
|
|
|
#endif
|
|
|
|
#define hton64(x) ntoh64(x)
|
|
|
|
|
2004-10-20 17:57:10 +08:00
|
|
|
#define SNAP_LEN HCI_MAX_FRAME_SIZE
|
|
|
|
#define DEFAULT_PORT 10839;
|
2004-03-03 10:03:49 +08:00
|
|
|
|
|
|
|
/* Modes */
|
|
|
|
enum {
|
|
|
|
PARSE,
|
|
|
|
READ,
|
2004-10-20 17:57:10 +08:00
|
|
|
WRITE,
|
|
|
|
RECEIVE,
|
|
|
|
SEND
|
2004-03-03 10:03:49 +08:00
|
|
|
};
|
|
|
|
|
2001-08-02 10:40:48 +08:00
|
|
|
/* Default options */
|
2001-08-17 08:00:02 +08:00
|
|
|
static int device;
|
|
|
|
static int snap_len = SNAP_LEN;
|
2002-04-23 05:49:02 +08:00
|
|
|
static int defpsm = 0;
|
2004-08-27 07:59:20 +08:00
|
|
|
static int defcompid = DEFAULT_COMPID;
|
2001-09-15 15:20:39 +08:00
|
|
|
static int mode = PARSE;
|
2005-04-19 23:04:16 +08:00
|
|
|
static int permcheck = 1;
|
2002-02-04 14:15:35 +08:00
|
|
|
static long flags;
|
|
|
|
static long filter;
|
2001-08-17 08:00:02 +08:00
|
|
|
static char *dump_file;
|
2004-10-20 17:57:10 +08:00
|
|
|
static in_addr_t dump_addr = INADDR_LOOPBACK;
|
|
|
|
static in_port_t dump_port = DEFAULT_PORT;
|
2001-08-02 10:40:48 +08:00
|
|
|
|
2005-06-04 16:39:59 +08:00
|
|
|
struct hcidump_hdr {
|
2004-03-03 10:03:49 +08:00
|
|
|
uint16_t len;
|
|
|
|
uint8_t in;
|
|
|
|
uint8_t pad;
|
|
|
|
uint32_t ts_sec;
|
|
|
|
uint32_t ts_usec;
|
|
|
|
} __attribute__ ((packed));
|
2005-06-04 16:39:59 +08:00
|
|
|
#define HCIDUMP_HDR_SIZE (sizeof(struct hcidump_hdr))
|
|
|
|
|
|
|
|
struct btsnoop_hdr {
|
|
|
|
uint8_t id[8]; /* Identification Pattern */
|
|
|
|
uint32_t version; /* Version Number = 1 */
|
|
|
|
uint32_t type; /* Datalink Type */
|
|
|
|
} __attribute__ ((packed));
|
|
|
|
#define BTSNOOP_HDR_SIZE (sizeof(struct btsnoop_hdr))
|
|
|
|
|
|
|
|
struct btsnoop_pkt {
|
|
|
|
uint32_t size; /* Original Length */
|
|
|
|
uint32_t len; /* Included Length */
|
|
|
|
uint32_t flags; /* Packet Flags */
|
|
|
|
uint32_t drops; /* Cumulative Drops */
|
|
|
|
uint64_t ts; /* Timestamp microseconds */
|
|
|
|
uint8_t data[0]; /* Packet Data */
|
|
|
|
} __attribute__ ((packed));
|
|
|
|
#define BTSNOOP_PKT_SIZE (sizeof(struct btsnoop_pkt))
|
|
|
|
|
|
|
|
static uint8_t btsnoop_id[] = { 0x62, 0x74, 0x73, 0x6e, 0x6f, 0x6f, 0x70, 0x00 };
|
2004-03-03 10:03:49 +08:00
|
|
|
|
2005-06-14 21:06:03 +08:00
|
|
|
static uint32_t btsnoop_version = 0;
|
|
|
|
static uint32_t btsnoop_type = 0;
|
|
|
|
|
2004-03-03 10:03:49 +08:00
|
|
|
static inline int read_n(int fd, char *buf, int len)
|
|
|
|
{
|
|
|
|
register int t = 0, w;
|
|
|
|
|
|
|
|
while (len > 0) {
|
|
|
|
if ((w = read(fd, buf, len)) < 0) {
|
2004-06-16 17:57:43 +08:00
|
|
|
if (errno == EINTR || errno == EAGAIN)
|
2004-03-03 10:03:49 +08:00
|
|
|
continue;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (!w)
|
|
|
|
return 0;
|
|
|
|
len -= w; buf += w; t += w;
|
|
|
|
}
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int write_n(int fd, char *buf, int len)
|
|
|
|
{
|
|
|
|
register int t = 0, w;
|
|
|
|
|
|
|
|
while (len > 0) {
|
|
|
|
if ((w = write(fd, buf, len)) < 0) {
|
2004-06-16 17:57:43 +08:00
|
|
|
if (errno == EINTR || errno == EAGAIN)
|
2004-03-03 10:03:49 +08:00
|
|
|
continue;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (!w)
|
|
|
|
return 0;
|
|
|
|
len -= w; buf += w; t += w;
|
|
|
|
}
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2005-06-14 21:06:03 +08:00
|
|
|
static void process_frames(int dev, int sock, int fd, unsigned long flags)
|
2001-08-06 00:57:21 +08:00
|
|
|
{
|
|
|
|
struct cmsghdr *cmsg;
|
|
|
|
struct msghdr msg;
|
|
|
|
struct iovec iv;
|
2005-06-04 16:39:59 +08:00
|
|
|
struct hcidump_hdr *dh;
|
2005-06-14 21:06:03 +08:00
|
|
|
struct btsnoop_pkt *dp;
|
2001-08-16 12:56:12 +08:00
|
|
|
struct frame frm;
|
|
|
|
char *buf, *ctrl;
|
2005-07-03 23:22:32 +08:00
|
|
|
int len, hdr_size = HCIDUMP_HDR_SIZE;
|
2001-08-06 00:57:21 +08:00
|
|
|
|
2001-08-12 10:36:41 +08:00
|
|
|
if (snap_len < SNAP_LEN)
|
|
|
|
snap_len = SNAP_LEN;
|
2001-08-06 00:57:21 +08:00
|
|
|
|
2005-06-14 21:06:03 +08:00
|
|
|
if (flags & DUMP_BTSNOOP)
|
|
|
|
hdr_size = BTSNOOP_PKT_SIZE;
|
|
|
|
|
|
|
|
buf = malloc(snap_len + hdr_size);
|
2005-06-04 16:39:59 +08:00
|
|
|
if (!buf) {
|
2001-08-12 06:19:59 +08:00
|
|
|
perror("Can't allocate data buffer");
|
|
|
|
exit(1);
|
|
|
|
}
|
2004-02-29 09:14:47 +08:00
|
|
|
|
2001-08-16 12:29:28 +08:00
|
|
|
dh = (void *) buf;
|
2005-06-14 21:06:03 +08:00
|
|
|
dp = (void *) buf;
|
|
|
|
frm.data = buf + hdr_size;
|
2004-02-29 09:14:47 +08:00
|
|
|
|
2005-06-04 16:39:59 +08:00
|
|
|
ctrl = malloc(100);
|
|
|
|
if (!ctrl) {
|
2001-08-12 06:19:59 +08:00
|
|
|
perror("Can't allocate control buffer");
|
|
|
|
exit(1);
|
|
|
|
}
|
2004-02-29 09:14:47 +08:00
|
|
|
|
2005-07-07 01:58:05 +08:00
|
|
|
if (dev == HCI_DEV_NONE)
|
2005-07-06 22:25:31 +08:00
|
|
|
printf("system: ");
|
|
|
|
else
|
|
|
|
printf("device: hci%d ", dev);
|
|
|
|
|
|
|
|
printf("snap_len: %d filter: 0x%lx\n", snap_len, filter);
|
2001-08-06 00:57:21 +08:00
|
|
|
|
2002-11-26 01:59:26 +08:00
|
|
|
memset(&msg, 0, sizeof(msg));
|
|
|
|
|
2001-08-06 00:57:21 +08:00
|
|
|
while (1) {
|
2001-08-16 12:56:12 +08:00
|
|
|
iv.iov_base = frm.data;
|
2001-08-06 00:57:21 +08:00
|
|
|
iv.iov_len = snap_len;
|
|
|
|
|
|
|
|
msg.msg_iov = &iv;
|
|
|
|
msg.msg_iovlen = 1;
|
|
|
|
msg.msg_control = ctrl;
|
2001-08-12 06:19:59 +08:00
|
|
|
msg.msg_controllen = 100;
|
2001-08-06 00:57:21 +08:00
|
|
|
|
2005-07-03 23:22:32 +08:00
|
|
|
len = recvmsg(sock, &msg, 0);
|
|
|
|
if (len < 0) {
|
2001-08-06 00:57:21 +08:00
|
|
|
perror("Receive failed");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Process control message */
|
2005-07-03 23:22:32 +08:00
|
|
|
frm.data_len = len;
|
2005-07-07 01:58:05 +08:00
|
|
|
frm.dev_id = dev;
|
2001-08-16 12:56:12 +08:00
|
|
|
frm.in = 0;
|
2005-07-07 01:58:05 +08:00
|
|
|
|
2001-08-06 00:57:21 +08:00
|
|
|
cmsg = CMSG_FIRSTHDR(&msg);
|
2001-08-15 13:39:50 +08:00
|
|
|
while (cmsg) {
|
|
|
|
switch (cmsg->cmsg_type) {
|
|
|
|
case HCI_CMSG_DIR:
|
2005-06-04 16:39:59 +08:00
|
|
|
frm.in = *((int *) CMSG_DATA(cmsg));
|
2001-08-15 13:39:50 +08:00
|
|
|
break;
|
2002-02-04 14:15:35 +08:00
|
|
|
case HCI_CMSG_TSTAMP:
|
2005-06-04 16:39:59 +08:00
|
|
|
frm.ts = *((struct timeval *) CMSG_DATA(cmsg));
|
2002-02-04 14:15:35 +08:00
|
|
|
break;
|
2001-08-06 00:57:21 +08:00
|
|
|
}
|
|
|
|
cmsg = CMSG_NXTHDR(&msg, cmsg);
|
|
|
|
}
|
|
|
|
|
2001-08-21 08:41:59 +08:00
|
|
|
frm.ptr = frm.data;
|
|
|
|
frm.len = frm.data_len;
|
|
|
|
|
|
|
|
switch (mode) {
|
|
|
|
case WRITE:
|
2004-10-20 17:57:10 +08:00
|
|
|
case SEND:
|
|
|
|
/* Save or send dump */
|
2005-06-14 21:06:03 +08:00
|
|
|
if (flags & DUMP_BTSNOOP) {
|
2005-06-15 19:50:07 +08:00
|
|
|
uint64_t ts;
|
2005-06-14 21:06:03 +08:00
|
|
|
uint8_t pkt_type = ((uint8_t *) frm.data)[0];
|
|
|
|
dp->size = htonl(frm.data_len);
|
|
|
|
dp->len = dp->size;
|
|
|
|
dp->flags = ntohl(frm.in & 0x01);
|
|
|
|
dp->drops = 0;
|
2005-06-15 19:50:07 +08:00
|
|
|
ts = (frm.ts.tv_sec - 946684800ll) * 1000000ll + frm.ts.tv_usec;
|
|
|
|
dp->ts = hton64(ts + 0x00E03AB44A676000ll);
|
2005-06-14 21:06:03 +08:00
|
|
|
if (pkt_type == HCI_COMMAND_PKT ||
|
|
|
|
pkt_type == HCI_EVENT_PKT)
|
|
|
|
dp->flags |= ntohl(0x02);
|
|
|
|
} else {
|
|
|
|
dh->len = htobs(frm.data_len);
|
|
|
|
dh->in = frm.in;
|
|
|
|
dh->ts_sec = htobl(frm.ts.tv_sec);
|
|
|
|
dh->ts_usec = htobl(frm.ts.tv_usec);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (write_n(fd, buf, frm.data_len + hdr_size) < 0) {
|
2001-08-16 11:46:14 +08:00
|
|
|
perror("Write error");
|
|
|
|
exit(1);
|
|
|
|
}
|
2001-08-21 08:41:59 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* Parse and print */
|
|
|
|
parse(&frm);
|
|
|
|
break;
|
2001-08-16 11:46:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-04 16:39:59 +08:00
|
|
|
static void read_dump(int fd)
|
2001-08-16 11:46:14 +08:00
|
|
|
{
|
2005-06-04 16:39:59 +08:00
|
|
|
struct hcidump_hdr dh;
|
|
|
|
struct btsnoop_pkt dp;
|
2001-08-16 12:56:12 +08:00
|
|
|
struct frame frm;
|
2005-06-04 16:39:59 +08:00
|
|
|
uint8_t pkt_type;
|
2001-08-16 11:46:14 +08:00
|
|
|
int err;
|
|
|
|
|
2005-06-04 16:39:59 +08:00
|
|
|
frm.data = malloc(HCI_MAX_FRAME_SIZE);
|
|
|
|
if (!frm.data) {
|
2001-08-16 11:46:14 +08:00
|
|
|
perror("Can't allocate data buffer");
|
|
|
|
exit(1);
|
|
|
|
}
|
2004-02-29 09:14:47 +08:00
|
|
|
|
2001-08-16 11:46:14 +08:00
|
|
|
while (1) {
|
2005-06-04 16:39:59 +08:00
|
|
|
if (parser.flags & DUMP_BTSNOOP)
|
|
|
|
err = read_n(fd, (void *) &dp, BTSNOOP_PKT_SIZE);
|
|
|
|
else
|
|
|
|
err = read_n(fd, (void *) &dh, HCIDUMP_HDR_SIZE);
|
2004-02-29 09:14:47 +08:00
|
|
|
|
2005-06-04 16:39:59 +08:00
|
|
|
if (err < 0)
|
|
|
|
goto failed;
|
|
|
|
if (!err)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (parser.flags & DUMP_BTSNOOP) {
|
2005-06-14 21:06:03 +08:00
|
|
|
switch (btsnoop_type) {
|
|
|
|
case 1001:
|
|
|
|
if (ntohl(dp.flags) & 0x02) {
|
|
|
|
if (ntohl(dp.flags) & 0x01)
|
|
|
|
pkt_type = HCI_EVENT_PKT;
|
|
|
|
else
|
|
|
|
pkt_type = HCI_COMMAND_PKT;
|
|
|
|
} else
|
|
|
|
pkt_type = HCI_ACLDATA_PKT;
|
|
|
|
|
|
|
|
((uint8_t *) frm.data)[0] = pkt_type;
|
|
|
|
|
|
|
|
frm.data_len = ntohl(dp.len) + 1;
|
|
|
|
err = read_n(fd, frm.data + 1, frm.data_len - 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1002:
|
|
|
|
frm.data_len = ntohl(dp.len);
|
|
|
|
err = read_n(fd, frm.data, frm.data_len);
|
|
|
|
break;
|
|
|
|
}
|
2005-06-04 16:39:59 +08:00
|
|
|
} else {
|
|
|
|
frm.data_len = btohs(dh.len);
|
|
|
|
err = read_n(fd, frm.data, frm.data_len);
|
|
|
|
}
|
2001-08-06 00:57:21 +08:00
|
|
|
|
2005-06-04 16:39:59 +08:00
|
|
|
if (err < 0)
|
2001-08-16 11:46:14 +08:00
|
|
|
goto failed;
|
2005-06-04 16:39:59 +08:00
|
|
|
if (!err)
|
|
|
|
return;
|
2001-08-06 00:57:21 +08:00
|
|
|
|
2001-08-16 12:56:12 +08:00
|
|
|
frm.ptr = frm.data;
|
|
|
|
frm.len = frm.data_len;
|
2005-06-04 16:39:59 +08:00
|
|
|
|
|
|
|
if (parser.flags & DUMP_BTSNOOP) {
|
2005-06-15 19:50:07 +08:00
|
|
|
uint64_t ts;
|
|
|
|
frm.in = ntohl(dp.flags) & 0x01;
|
|
|
|
ts = ntoh64(dp.ts) - 0x00E03AB44A676000ll;
|
|
|
|
frm.ts.tv_sec = (ts / 1000000ll) + 946684800ll;
|
|
|
|
frm.ts.tv_usec = ts % 1000000ll;
|
2005-06-04 16:39:59 +08:00
|
|
|
} else {
|
2005-06-15 19:50:07 +08:00
|
|
|
frm.in = dh.in;
|
2005-06-04 16:39:59 +08:00
|
|
|
frm.ts.tv_sec = btohl(dh.ts_sec);
|
|
|
|
frm.ts.tv_usec = btohl(dh.ts_usec);
|
|
|
|
}
|
2004-02-29 09:14:47 +08:00
|
|
|
|
2001-08-16 12:29:28 +08:00
|
|
|
parse(&frm);
|
2001-08-06 00:57:21 +08:00
|
|
|
}
|
2001-08-16 11:46:14 +08:00
|
|
|
|
|
|
|
failed:
|
|
|
|
perror("Read failed");
|
|
|
|
exit(1);
|
2001-08-06 00:57:21 +08:00
|
|
|
}
|
|
|
|
|
2005-06-14 21:06:03 +08:00
|
|
|
static int open_file(char *file, int mode, unsigned long flags)
|
2001-08-02 10:40:48 +08:00
|
|
|
{
|
2005-06-04 16:39:59 +08:00
|
|
|
struct btsnoop_hdr hdr;
|
2005-06-14 21:06:03 +08:00
|
|
|
int fd, len, open_flags;
|
2001-08-02 10:40:48 +08:00
|
|
|
|
2005-06-14 21:06:03 +08:00
|
|
|
if (mode == WRITE) {
|
|
|
|
if (flags & DUMP_BTSNOOP)
|
|
|
|
open_flags = O_WRONLY | O_CREAT;
|
|
|
|
else
|
|
|
|
open_flags = O_WRONLY | O_CREAT | O_APPEND;
|
|
|
|
} else
|
|
|
|
open_flags = O_RDONLY;
|
2001-08-02 10:40:48 +08:00
|
|
|
|
2005-06-14 21:06:03 +08:00
|
|
|
fd = open(file, open_flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
|
2005-06-04 16:39:59 +08:00
|
|
|
if (fd < 0) {
|
2005-06-14 21:06:03 +08:00
|
|
|
perror("Can't open dump file");
|
2001-08-16 08:45:16 +08:00
|
|
|
exit(1);
|
2001-08-02 10:40:48 +08:00
|
|
|
}
|
2005-06-04 16:39:59 +08:00
|
|
|
|
|
|
|
if (mode == READ) {
|
|
|
|
len = read(fd, &hdr, BTSNOOP_HDR_SIZE);
|
|
|
|
if (len != BTSNOOP_HDR_SIZE) {
|
|
|
|
lseek(fd, 0, SEEK_SET);
|
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!memcmp(hdr.id, btsnoop_id, sizeof(btsnoop_id))) {
|
|
|
|
parser.flags |= DUMP_BTSNOOP;
|
|
|
|
|
2005-06-14 21:06:03 +08:00
|
|
|
btsnoop_version = ntohl(hdr.version);
|
|
|
|
btsnoop_type = ntohl(hdr.type);
|
|
|
|
|
|
|
|
printf("btsnoop version: %d datalink type: %d\n",
|
|
|
|
btsnoop_version, btsnoop_type);
|
|
|
|
|
|
|
|
if (btsnoop_version != 1) {
|
2005-06-04 16:40:55 +08:00
|
|
|
fprintf(stderr, "Unsupported BTSnoop version\n");
|
2005-06-04 16:39:59 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2005-06-14 21:06:03 +08:00
|
|
|
if (btsnoop_type != 1001 && btsnoop_type != 1002) {
|
2005-06-04 16:40:55 +08:00
|
|
|
fprintf(stderr, "Unsupported BTSnoop datalink type\n");
|
2005-06-04 16:39:59 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
} else {
|
2005-06-14 21:06:03 +08:00
|
|
|
parser.flags &= ~DUMP_BTSNOOP;
|
2005-06-04 16:39:59 +08:00
|
|
|
lseek(fd, 0, SEEK_SET);
|
|
|
|
return fd;
|
|
|
|
}
|
2005-06-14 21:06:03 +08:00
|
|
|
} else {
|
|
|
|
if (flags & DUMP_BTSNOOP) {
|
|
|
|
btsnoop_version = 1;
|
|
|
|
btsnoop_type = 1002;
|
|
|
|
|
|
|
|
memcpy(hdr.id, btsnoop_id, sizeof(btsnoop_id));
|
|
|
|
hdr.version = htonl(btsnoop_version);
|
|
|
|
hdr.type = htonl(btsnoop_type);
|
|
|
|
|
|
|
|
printf("btsnoop version: %d datalink type: %d\n",
|
|
|
|
btsnoop_version, btsnoop_type);
|
|
|
|
|
|
|
|
len = write(fd, &hdr, BTSNOOP_HDR_SIZE);
|
|
|
|
if (len < 0) {
|
|
|
|
perror("Can't create dump header");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len != BTSNOOP_HDR_SIZE) {
|
|
|
|
fprintf(stderr, "Header size mismatch\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
2005-06-04 16:39:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return fd;
|
2001-08-16 08:45:16 +08:00
|
|
|
}
|
|
|
|
|
2004-10-24 01:57:17 +08:00
|
|
|
static int open_socket(int dev, unsigned long flags)
|
2001-08-16 08:45:16 +08:00
|
|
|
{
|
|
|
|
struct sockaddr_hci addr;
|
|
|
|
struct hci_filter flt;
|
2005-04-19 23:04:16 +08:00
|
|
|
struct hci_dev_info di;
|
|
|
|
int sk, dd, opt;
|
|
|
|
|
2005-07-06 22:25:31 +08:00
|
|
|
if (permcheck && dev != HCI_DEV_NONE) {
|
2005-04-19 23:04:16 +08:00
|
|
|
dd = hci_open_dev(dev);
|
|
|
|
if (dd < 0) {
|
|
|
|
perror("Can't open device");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hci_devinfo(dev, &di) < 0) {
|
|
|
|
perror("Can't get device info");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
opt = hci_test_bit(HCI_RAW, &di.flags);
|
|
|
|
if (ioctl(dd, HCISETRAW, opt) < 0) {
|
|
|
|
if (errno == EACCES) {
|
|
|
|
perror("Can't access device");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
hci_close_dev(dd);
|
|
|
|
}
|
2001-08-02 10:40:48 +08:00
|
|
|
|
|
|
|
/* Create HCI socket */
|
2005-06-04 16:39:59 +08:00
|
|
|
sk = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
|
|
|
|
if (sk < 0) {
|
2005-04-19 23:04:16 +08:00
|
|
|
perror("Can't create raw socket");
|
2001-08-02 10:40:48 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
2004-02-29 09:14:47 +08:00
|
|
|
|
2001-08-02 10:40:48 +08:00
|
|
|
opt = 1;
|
2004-06-16 17:57:43 +08:00
|
|
|
if (setsockopt(sk, SOL_HCI, HCI_DATA_DIR, &opt, sizeof(opt)) < 0) {
|
2001-08-02 10:40:48 +08:00
|
|
|
perror("Can't enable data direction info");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2002-02-04 14:15:35 +08:00
|
|
|
opt = 1;
|
2004-06-16 17:57:43 +08:00
|
|
|
if (setsockopt(sk, SOL_HCI, HCI_TIME_STAMP, &opt, sizeof(opt)) < 0) {
|
2002-02-04 14:15:35 +08:00
|
|
|
perror("Can't enable time stamp");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2001-08-05 14:04:37 +08:00
|
|
|
/* Setup filter */
|
2002-03-20 02:19:34 +08:00
|
|
|
hci_filter_clear(&flt);
|
2005-03-13 23:13:36 +08:00
|
|
|
hci_filter_all_ptypes(&flt);
|
|
|
|
hci_filter_all_events(&flt);
|
2004-06-16 17:57:43 +08:00
|
|
|
if (setsockopt(sk, SOL_HCI, HCI_FILTER, &flt, sizeof(flt)) < 0) {
|
2005-04-19 23:04:16 +08:00
|
|
|
perror("Can't set filter");
|
2001-08-05 14:04:37 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2001-08-02 10:40:48 +08:00
|
|
|
/* Bind socket to the HCI device */
|
|
|
|
addr.hci_family = AF_BLUETOOTH;
|
|
|
|
addr.hci_dev = dev;
|
2004-06-16 17:57:43 +08:00
|
|
|
if (bind(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
|
2001-08-06 00:57:21 +08:00
|
|
|
printf("Can't attach to device hci%d. %s(%d)\n",
|
|
|
|
dev, strerror(errno), errno);
|
2001-08-02 10:40:48 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
2004-06-16 17:57:43 +08:00
|
|
|
|
|
|
|
return sk;
|
2001-08-16 08:45:16 +08:00
|
|
|
}
|
2001-08-02 10:40:48 +08:00
|
|
|
|
2004-10-20 17:57:10 +08:00
|
|
|
static int open_connection(in_addr_t addr, in_port_t port)
|
|
|
|
{
|
|
|
|
struct sockaddr_in sa;
|
|
|
|
int sk, opt;
|
|
|
|
|
2005-06-04 16:39:59 +08:00
|
|
|
sk = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
|
|
|
if (sk < 0) {
|
2004-10-20 17:57:10 +08:00
|
|
|
perror("Can't create inet socket");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
opt = 1;
|
|
|
|
setsockopt(sk, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
|
|
|
|
|
|
|
|
sa.sin_family = AF_INET;
|
|
|
|
sa.sin_addr.s_addr = htonl(INADDR_ANY);
|
|
|
|
sa.sin_port = htons(0);
|
|
|
|
if (bind(sk, (struct sockaddr *) &sa, sizeof(sa)) < 0) {
|
|
|
|
perror("Can't bind inet socket");
|
|
|
|
close(sk);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
sa.sin_family = AF_INET;
|
|
|
|
sa.sin_addr.s_addr = htonl(addr);
|
|
|
|
sa.sin_port = htons(port);
|
|
|
|
if (connect(sk, (struct sockaddr *) &sa, sizeof(sa)) < 0) {
|
|
|
|
perror("Can't connect inet socket");
|
|
|
|
close(sk);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return sk;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int wait_connection(in_addr_t addr, in_port_t port)
|
|
|
|
{
|
|
|
|
struct sockaddr_in sa;
|
|
|
|
struct hostent *host;
|
2005-07-06 04:03:59 +08:00
|
|
|
socklen_t len;
|
|
|
|
int sk, nsk, opt;
|
2004-10-20 17:57:10 +08:00
|
|
|
|
2005-06-04 16:39:59 +08:00
|
|
|
sk = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
|
|
|
if (sk < 0) {
|
2004-10-20 17:57:10 +08:00
|
|
|
perror("Can't create inet socket");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
opt = 1;
|
|
|
|
setsockopt(sk, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
|
|
|
|
|
|
|
|
sa.sin_family = AF_INET;
|
|
|
|
sa.sin_addr.s_addr = htonl(addr);
|
|
|
|
sa.sin_port = htons(port);
|
|
|
|
if (bind(sk, (struct sockaddr *) &sa, sizeof(sa)) < 0) {
|
|
|
|
perror("Can't bind inet socket");
|
|
|
|
close(sk);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
host = gethostbyaddr(&sa.sin_addr, sizeof(sa.sin_addr), AF_INET);
|
|
|
|
printf("device: %s:%d snap_len: %d filter: 0x%lx\n",
|
|
|
|
host ? host->h_name : inet_ntoa(sa.sin_addr),
|
|
|
|
ntohs(sa.sin_port), snap_len, filter);
|
|
|
|
|
|
|
|
if (listen(sk, 1)) {
|
|
|
|
perror("Can't listen on inet socket");
|
|
|
|
close(sk);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
len = sizeof(sa);
|
2005-07-06 04:03:59 +08:00
|
|
|
nsk = accept(sk, (struct sockaddr *) &sa, &len);
|
|
|
|
if (nsk < 0) {
|
2004-10-20 17:57:10 +08:00
|
|
|
perror("Can't accept new inet socket");
|
|
|
|
close(sk);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
host = gethostbyaddr(&sa.sin_addr, sizeof(sa.sin_addr), AF_INET);
|
|
|
|
printf("device: %s snap_len: %d filter: 0x%lx\n",
|
|
|
|
host ? host->h_name : inet_ntoa(sa.sin_addr), snap_len, filter);
|
|
|
|
|
|
|
|
close(sk);
|
|
|
|
|
|
|
|
return nsk;
|
|
|
|
}
|
|
|
|
|
2001-09-15 15:20:39 +08:00
|
|
|
static struct {
|
|
|
|
char *name;
|
|
|
|
int flag;
|
|
|
|
} filters[] = {
|
2005-02-22 16:09:43 +08:00
|
|
|
{ "lmp", FILT_LMP },
|
2004-02-29 09:14:47 +08:00
|
|
|
{ "hci", FILT_HCI },
|
|
|
|
{ "sco", FILT_SCO },
|
|
|
|
{ "l2cap", FILT_L2CAP },
|
|
|
|
{ "rfcomm", FILT_RFCOMM },
|
|
|
|
{ "sdp", FILT_SDP },
|
|
|
|
{ "bnep", FILT_BNEP },
|
|
|
|
{ "cmtp", FILT_CMTP },
|
|
|
|
{ "hidp", FILT_HIDP },
|
2004-03-03 10:59:16 +08:00
|
|
|
{ "hcrp", FILT_HCRP },
|
2004-06-11 03:04:11 +08:00
|
|
|
{ "avdtp", FILT_AVDTP },
|
2004-09-14 03:09:17 +08:00
|
|
|
{ "obex", FILT_OBEX },
|
2004-03-03 04:31:22 +08:00
|
|
|
{ "capi", FILT_CAPI },
|
2005-03-13 23:13:36 +08:00
|
|
|
{ "csr", FILT_CSR },
|
|
|
|
{ "dga", FILT_DGA },
|
2001-09-15 15:20:39 +08:00
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
|
2002-05-24 07:13:30 +08:00
|
|
|
static void parse_filter(int argc, char **argv)
|
2001-09-15 15:20:39 +08:00
|
|
|
{
|
|
|
|
int i,n;
|
2004-02-29 09:14:47 +08:00
|
|
|
|
|
|
|
for (i = 0; i < argc; i++) {
|
|
|
|
for (n = 0; filters[n].name; n++) {
|
2004-09-18 20:32:25 +08:00
|
|
|
if (!strcasecmp(filters[n].name, argv[i])) {
|
2001-09-15 15:20:39 +08:00
|
|
|
filter |= filters[n].flag;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-05-24 07:13:30 +08:00
|
|
|
static void usage(void)
|
|
|
|
{
|
|
|
|
printf(
|
|
|
|
"Usage: hcidump [OPTION...] [filter]\n"
|
|
|
|
" -i, --device=hci_dev HCI device\n"
|
2004-10-20 17:57:10 +08:00
|
|
|
" -l, --snap-len=len Snap len (in bytes)\n"
|
2004-02-29 09:14:47 +08:00
|
|
|
" -p, --psm=psm Default PSM\n"
|
2004-08-27 07:59:20 +08:00
|
|
|
" -m, --manufacturer=compid Default manufacturer\n"
|
2002-05-24 07:13:30 +08:00
|
|
|
" -w, --save-dump=file Save dump to a file\n"
|
2004-02-29 09:14:47 +08:00
|
|
|
" -r, --read-dump=file Read dump from a file\n"
|
2004-10-20 17:57:10 +08:00
|
|
|
" -s, --send-dump=host Send dump to a host\n"
|
|
|
|
" -n, --recv-dump=host Receive dump on a host\n"
|
2004-02-29 09:14:47 +08:00
|
|
|
" -t, --ts Display time stamps\n"
|
|
|
|
" -a, --ascii Dump data in ascii\n"
|
2004-08-27 03:16:59 +08:00
|
|
|
" -x, --hex Dump data in hex\n"
|
|
|
|
" -X, --ext Dump data in hex and ascii\n"
|
2005-03-13 23:13:36 +08:00
|
|
|
" -R, --raw Dump raw data\n"
|
2004-02-29 09:14:47 +08:00
|
|
|
" -C, --cmtp=psm PSM for CMTP\n"
|
2004-03-03 10:59:16 +08:00
|
|
|
" -H, --hcrp=psm PSM for HCRP\n"
|
2004-09-14 03:09:17 +08:00
|
|
|
" -O, --obex=channel Channel for OBEX\n"
|
2005-06-14 21:06:03 +08:00
|
|
|
" -B, --btsnoop Use BTSnoop file format\n"
|
2005-02-01 21:28:04 +08:00
|
|
|
" -V, --verbose Verbose decoding\n"
|
|
|
|
" -h, --help Give this help list\n"
|
2002-05-24 07:13:30 +08:00
|
|
|
" --usage Give a short usage message\n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct option main_options[] = {
|
2004-08-27 07:59:20 +08:00
|
|
|
{ "device", 1, 0, 'i' },
|
2004-10-20 17:57:10 +08:00
|
|
|
{ "snap-len", 1, 0, 'l' },
|
2004-08-27 07:59:20 +08:00
|
|
|
{ "psm", 1, 0, 'p' },
|
|
|
|
{ "manufacturer", 1, 0, 'm' },
|
|
|
|
{ "save-dump", 1, 0, 'w' },
|
|
|
|
{ "read-dump", 1, 0, 'r' },
|
2004-10-20 17:57:10 +08:00
|
|
|
{ "send-dump", 1, 0, 's' },
|
|
|
|
{ "recv-dump", 1, 0, 'n' },
|
|
|
|
{ "timestamp", 0, 0, 't' },
|
2004-08-27 07:59:20 +08:00
|
|
|
{ "ascii", 0, 0, 'a' },
|
|
|
|
{ "hex", 0, 0, 'x' },
|
|
|
|
{ "ext", 0, 0, 'X' },
|
|
|
|
{ "raw", 0, 0, 'R' },
|
|
|
|
{ "cmtp", 1, 0, 'C' },
|
|
|
|
{ "hcrp", 1, 0, 'H' },
|
2004-09-14 03:09:17 +08:00
|
|
|
{ "obex", 1, 0, 'O' },
|
2005-06-14 21:06:03 +08:00
|
|
|
{ "btsnoop", 0, 0, 'B' },
|
2005-02-01 21:28:04 +08:00
|
|
|
{ "verbose", 0, 0, 'V' },
|
2004-08-27 07:59:20 +08:00
|
|
|
{ "help", 0, 0, 'h' },
|
2002-05-24 07:13:30 +08:00
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
2001-08-16 08:45:16 +08:00
|
|
|
{
|
2004-10-20 17:57:10 +08:00
|
|
|
struct hostent *host;
|
|
|
|
struct in_addr addr;
|
2002-05-24 07:13:30 +08:00
|
|
|
int opt;
|
|
|
|
|
2005-01-30 02:21:47 +08:00
|
|
|
printf("HCI sniffer - Bluetooth packet analyzer ver %s\n", VERSION);
|
2002-05-24 07:13:30 +08:00
|
|
|
|
2005-06-14 21:06:03 +08:00
|
|
|
while ((opt=getopt_long(argc, argv, "i:l:p:m:w:r:s:n:taxXRC:H:O:BVZh", main_options, NULL)) != -1) {
|
2004-02-29 09:14:47 +08:00
|
|
|
switch(opt) {
|
2001-08-16 08:45:16 +08:00
|
|
|
case 'i':
|
2005-07-10 17:15:43 +08:00
|
|
|
if (strcasecmp(optarg, "none") && strcasecmp(optarg, "system"))
|
2005-07-06 22:25:31 +08:00
|
|
|
device = atoi(optarg + 3);
|
|
|
|
else
|
|
|
|
device = HCI_DEV_NONE;
|
2001-08-16 08:45:16 +08:00
|
|
|
break;
|
|
|
|
|
2004-10-20 17:57:10 +08:00
|
|
|
case 'l':
|
2002-05-24 07:13:30 +08:00
|
|
|
snap_len = atoi(optarg);
|
2001-08-16 08:45:16 +08:00
|
|
|
break;
|
|
|
|
|
2002-04-23 05:49:02 +08:00
|
|
|
case 'p':
|
2002-05-24 07:13:30 +08:00
|
|
|
defpsm = atoi(optarg);
|
2002-04-23 05:49:02 +08:00
|
|
|
break;
|
|
|
|
|
2004-08-27 07:59:20 +08:00
|
|
|
case 'm':
|
|
|
|
defcompid = atoi(optarg);
|
|
|
|
break;
|
|
|
|
|
2004-02-29 09:14:47 +08:00
|
|
|
case 'w':
|
|
|
|
mode = WRITE;
|
|
|
|
dump_file = strdup(optarg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'r':
|
|
|
|
mode = READ;
|
|
|
|
dump_file = strdup(optarg);
|
|
|
|
break;
|
|
|
|
|
2004-10-20 17:57:10 +08:00
|
|
|
case 's':
|
|
|
|
mode = SEND;
|
|
|
|
host = gethostbyname(optarg);
|
|
|
|
if (host) {
|
|
|
|
bcopy(host->h_addr, &addr, sizeof(struct in_addr));
|
|
|
|
dump_addr = ntohl(addr.s_addr);
|
|
|
|
dump_port = DEFAULT_PORT;
|
|
|
|
} else {
|
|
|
|
dump_addr = INADDR_LOOPBACK;
|
|
|
|
dump_port = DEFAULT_PORT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'n':
|
|
|
|
mode = RECEIVE;
|
|
|
|
host = gethostbyname(optarg);
|
|
|
|
if (host) {
|
|
|
|
bcopy(host->h_addr, &addr, sizeof(struct in_addr));
|
|
|
|
dump_addr = ntohl(addr.s_addr);
|
|
|
|
dump_port = DEFAULT_PORT;
|
|
|
|
} else {
|
|
|
|
dump_addr = INADDR_LOOPBACK;
|
|
|
|
dump_port = DEFAULT_PORT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2002-02-04 14:15:35 +08:00
|
|
|
case 't':
|
|
|
|
flags |= DUMP_TSTAMP;
|
|
|
|
break;
|
|
|
|
|
2004-08-27 03:16:59 +08:00
|
|
|
case 'a':
|
|
|
|
flags |= DUMP_ASCII;
|
|
|
|
break;
|
|
|
|
|
2004-02-29 09:14:47 +08:00
|
|
|
case 'x':
|
|
|
|
flags |= DUMP_HEX;
|
2001-08-21 08:41:59 +08:00
|
|
|
break;
|
|
|
|
|
2004-08-27 03:16:59 +08:00
|
|
|
case 'X':
|
|
|
|
flags |= DUMP_EXT;
|
2001-08-16 08:45:16 +08:00
|
|
|
break;
|
2001-08-02 10:40:48 +08:00
|
|
|
|
2004-02-29 09:14:47 +08:00
|
|
|
case 'R':
|
|
|
|
flags |= DUMP_RAW;
|
2001-08-17 08:00:02 +08:00
|
|
|
break;
|
2001-08-21 08:41:59 +08:00
|
|
|
|
2004-02-29 09:14:47 +08:00
|
|
|
case 'C':
|
2004-09-14 03:02:24 +08:00
|
|
|
set_proto(0, atoi(optarg), 0, SDP_UUID_CMTP);
|
2004-02-29 09:14:47 +08:00
|
|
|
break;
|
2001-09-15 15:20:39 +08:00
|
|
|
|
2004-03-03 10:59:16 +08:00
|
|
|
case 'H':
|
2004-09-14 03:02:24 +08:00
|
|
|
set_proto(0, atoi(optarg), 0, SDP_UUID_HARDCOPY_CONTROL_CHANNEL);
|
2004-03-03 10:59:16 +08:00
|
|
|
break;
|
|
|
|
|
2004-09-14 03:09:17 +08:00
|
|
|
case 'O':
|
|
|
|
set_proto(0, 0, atoi(optarg), SDP_UUID_OBEX);
|
|
|
|
break;
|
|
|
|
|
2005-06-14 21:06:03 +08:00
|
|
|
case 'B':
|
|
|
|
flags |= DUMP_BTSNOOP;
|
|
|
|
break;
|
|
|
|
|
2005-02-01 21:28:04 +08:00
|
|
|
case 'V':
|
|
|
|
flags |= DUMP_VERBOSE;
|
|
|
|
break;
|
|
|
|
|
2005-04-19 23:04:16 +08:00
|
|
|
case 'Z':
|
|
|
|
permcheck = 0;
|
|
|
|
break;
|
|
|
|
|
2004-02-29 09:14:47 +08:00
|
|
|
case 'h':
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|
2001-08-16 08:45:16 +08:00
|
|
|
|
2004-02-29 09:14:47 +08:00
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
optind = 0;
|
2002-05-24 07:13:30 +08:00
|
|
|
|
|
|
|
if (argc > 0)
|
|
|
|
parse_filter(argc, argv);
|
2001-08-02 10:40:48 +08:00
|
|
|
|
2001-09-15 15:20:39 +08:00
|
|
|
/* Default settings */
|
|
|
|
if (!filter)
|
|
|
|
filter = ~0L;
|
|
|
|
|
2001-08-16 08:45:16 +08:00
|
|
|
switch (mode) {
|
2001-08-21 08:41:59 +08:00
|
|
|
case PARSE:
|
2004-08-27 07:59:20 +08:00
|
|
|
init_parser(flags, filter, defpsm, defcompid);
|
2005-06-14 21:06:03 +08:00
|
|
|
process_frames(device, open_socket(device, flags), -1, flags);
|
2001-08-16 08:45:16 +08:00
|
|
|
break;
|
|
|
|
|
2004-10-20 17:57:10 +08:00
|
|
|
case READ:
|
|
|
|
init_parser(flags, filter, defpsm, defcompid);
|
2005-06-14 21:06:03 +08:00
|
|
|
read_dump(open_file(dump_file, mode, flags));
|
2004-10-20 17:57:10 +08:00
|
|
|
break;
|
|
|
|
|
2001-08-16 08:45:16 +08:00
|
|
|
case WRITE:
|
2005-06-04 16:39:59 +08:00
|
|
|
process_frames(device, open_socket(device, flags),
|
2005-06-14 21:06:03 +08:00
|
|
|
open_file(dump_file, mode, flags), flags);
|
2001-08-16 08:45:16 +08:00
|
|
|
break;
|
|
|
|
|
2004-10-20 17:57:10 +08:00
|
|
|
case RECEIVE:
|
2004-08-27 07:59:20 +08:00
|
|
|
init_parser(flags, filter, defpsm, defcompid);
|
2004-10-20 17:57:10 +08:00
|
|
|
read_dump(wait_connection(dump_addr, dump_port));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SEND:
|
2005-06-04 16:39:59 +08:00
|
|
|
process_frames(device, open_socket(device, flags),
|
2005-06-14 21:06:03 +08:00
|
|
|
open_connection(dump_addr, dump_port), flags);
|
2001-08-16 08:45:16 +08:00
|
|
|
break;
|
|
|
|
}
|
2004-02-29 09:14:47 +08:00
|
|
|
|
2001-08-06 00:57:21 +08:00
|
|
|
return 0;
|
2001-08-02 10:40:48 +08:00
|
|
|
}
|