2009-08-09 22:06:27 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2009
|
|
|
|
* Siemens AG, All rights reserved.
|
|
|
|
* Dmitry Eremin-Solenikov (dbaryshkov@gmail.com)
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that: (1) source code distributions
|
|
|
|
* retain the above copyright notice and this paragraph in its entirety, (2)
|
|
|
|
* distributions including binary code include the above copyright notice and
|
|
|
|
* this paragraph in its entirety in the documentation or other materials
|
|
|
|
* provided with the distribution, and (3) all advertising materials mentioning
|
|
|
|
* features or use of this software display the following acknowledgement:
|
|
|
|
* ``This product includes software developed by the University of California,
|
|
|
|
* Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
|
|
|
|
* the University nor the names of its contributors may be used to endorse
|
|
|
|
* or promote products derived from this software without specific prior
|
|
|
|
* written permission.
|
|
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
|
|
|
|
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <tcpdump-stdinc.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <pcap.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2010-03-09 23:14:06 +08:00
|
|
|
#include "interface.h"
|
|
|
|
#include "addrtoname.h"
|
|
|
|
|
|
|
|
#include "extract.h"
|
|
|
|
|
|
|
|
static const char *ftypes[] = {
|
|
|
|
"Beacon", /* 0 */
|
|
|
|
"Data", /* 1 */
|
|
|
|
"ACK", /* 2 */
|
|
|
|
"Command", /* 3 */
|
|
|
|
"Reserved", /* 4 */
|
|
|
|
"Reserved", /* 5 */
|
|
|
|
"Reserved", /* 6 */
|
|
|
|
"Reserved", /* 7 */
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
extract_header_length(u_int16_t fc)
|
|
|
|
{
|
|
|
|
int len = 0;
|
|
|
|
|
|
|
|
switch ((fc >> 10) & 0x3) {
|
2010-05-19 10:25:18 +08:00
|
|
|
case 0x00:
|
2010-03-09 23:14:06 +08:00
|
|
|
if (fc & (1 << 6)) /* intra-PAN with none dest addr */
|
|
|
|
return -1;
|
|
|
|
break;
|
2010-05-19 10:25:18 +08:00
|
|
|
case 0x01:
|
2010-03-09 23:14:06 +08:00
|
|
|
return -1;
|
|
|
|
case 0x02:
|
|
|
|
len += 4;
|
|
|
|
break;
|
|
|
|
case 0x03:
|
|
|
|
len += 10;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ((fc >> 14) & 0x3) {
|
2010-05-19 10:25:18 +08:00
|
|
|
case 0x00:
|
2010-03-09 23:14:06 +08:00
|
|
|
break;
|
2010-05-19 10:25:18 +08:00
|
|
|
case 0x01:
|
2010-03-09 23:14:06 +08:00
|
|
|
return -1;
|
|
|
|
case 0x02:
|
|
|
|
len += 4;
|
|
|
|
break;
|
|
|
|
case 0x03:
|
|
|
|
len += 10;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-05-19 10:25:18 +08:00
|
|
|
if (fc & (1 << 6)) {
|
|
|
|
if (len < 2)
|
|
|
|
return -1;
|
2010-03-09 23:14:06 +08:00
|
|
|
len -= 2;
|
2010-05-19 10:25:18 +08:00
|
|
|
}
|
2010-03-09 23:14:06 +08:00
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-09 22:06:27 +08:00
|
|
|
u_int
|
2010-05-14 02:30:59 +08:00
|
|
|
ieee802_15_4_if_print(struct netdissect_options *ndo,
|
|
|
|
const struct pcap_pkthdr *h, const u_char *p)
|
2009-08-09 22:06:27 +08:00
|
|
|
{
|
2010-03-09 23:14:06 +08:00
|
|
|
u_int caplen = h->caplen;
|
2010-05-19 10:25:18 +08:00
|
|
|
int hdrlen;
|
2010-03-09 23:14:06 +08:00
|
|
|
u_int16_t fc;
|
|
|
|
u_int8_t seq;
|
|
|
|
|
|
|
|
if (caplen < 3) {
|
2010-05-14 02:30:59 +08:00
|
|
|
ND_PRINT((ndo, "[|802.15.4] %x", caplen));
|
2010-03-09 23:14:06 +08:00
|
|
|
return caplen;
|
|
|
|
}
|
|
|
|
|
|
|
|
fc = EXTRACT_LE_16BITS(p);
|
|
|
|
hdrlen = extract_header_length(fc);
|
|
|
|
|
|
|
|
seq = EXTRACT_LE_8BITS(p + 2);
|
|
|
|
|
|
|
|
p += 3;
|
|
|
|
caplen -= 3;
|
|
|
|
|
2010-05-14 02:30:59 +08:00
|
|
|
ND_PRINT((ndo,"IEEE 802.15.4 %s packet ", ftypes[fc & 0x7]));
|
2010-03-09 23:14:06 +08:00
|
|
|
if (vflag)
|
2010-05-14 02:30:59 +08:00
|
|
|
ND_PRINT((ndo,"seq %02x ", seq));
|
2010-03-09 23:14:06 +08:00
|
|
|
if (hdrlen == -1) {
|
2010-05-14 02:30:59 +08:00
|
|
|
ND_PRINT((ndo,"malformed! "));
|
2010-03-09 23:14:06 +08:00
|
|
|
return caplen;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!vflag) {
|
|
|
|
p+= hdrlen;
|
|
|
|
caplen -= hdrlen;
|
|
|
|
} else {
|
|
|
|
u_int16_t panid;
|
|
|
|
|
|
|
|
switch ((fc >> 10) & 0x3) {
|
|
|
|
case 0x00:
|
2010-05-14 02:30:59 +08:00
|
|
|
ND_PRINT((ndo,"none "));
|
2010-03-09 23:14:06 +08:00
|
|
|
break;
|
|
|
|
case 0x02:
|
|
|
|
panid = EXTRACT_LE_16BITS(p);
|
|
|
|
p += 2;
|
2010-05-14 02:30:59 +08:00
|
|
|
ND_PRINT((ndo,"%04x:%04x ", panid, EXTRACT_LE_16BITS(p)));
|
2010-03-09 23:14:06 +08:00
|
|
|
p += 2;
|
|
|
|
break;
|
|
|
|
case 0x03:
|
|
|
|
panid = EXTRACT_LE_16BITS(p);
|
|
|
|
p += 2;
|
2010-05-14 02:30:59 +08:00
|
|
|
ND_PRINT((ndo,"%04x:%s ", panid, le64addr_string(p)));
|
2010-03-09 23:14:06 +08:00
|
|
|
p += 8;
|
|
|
|
break;
|
|
|
|
}
|
2010-05-14 02:30:59 +08:00
|
|
|
ND_PRINT((ndo,"< ");
|
2010-03-09 23:14:06 +08:00
|
|
|
|
|
|
|
switch ((fc >> 14) & 0x3) {
|
|
|
|
case 0x00:
|
2010-05-14 02:30:59 +08:00
|
|
|
ND_PRINT((ndo,"none "));
|
2010-03-09 23:14:06 +08:00
|
|
|
break;
|
|
|
|
case 0x02:
|
|
|
|
if (!(fc & (1 << 6))) {
|
|
|
|
panid = EXTRACT_LE_16BITS(p);
|
|
|
|
p += 2;
|
|
|
|
}
|
2010-05-14 02:30:59 +08:00
|
|
|
ND_PRINT((ndo,"%04x:%04x ", panid, EXTRACT_LE_16BITS(p)));
|
2010-03-09 23:14:06 +08:00
|
|
|
p += 2;
|
|
|
|
break;
|
|
|
|
case 0x03:
|
|
|
|
if (!(fc & (1 << 6))) {
|
|
|
|
panid = EXTRACT_LE_16BITS(p);
|
|
|
|
p += 2;
|
|
|
|
}
|
2010-05-14 02:30:59 +08:00
|
|
|
ND_PRINT((ndo,"%04x:%s ", panid, le64addr_string(p))));
|
2010-03-09 23:14:06 +08:00
|
|
|
p += 8;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
caplen -= hdrlen;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!suppress_default_print)
|
2010-05-14 02:30:59 +08:00
|
|
|
(ndo->ndo_default_print)(ndo, p, caplen);
|
2010-03-09 23:14:06 +08:00
|
|
|
|
2009-08-09 22:06:27 +08:00
|
|
|
return 0;
|
|
|
|
}
|