NetBSD/external/bsd/tcpdump/dist/print-802_15_4.c

229 lines
5.6 KiB
C
Raw Normal View History

2013-04-06 21:57:45 +04: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.
*/
2017-01-25 02:29:13 +03:00
#include <sys/cdefs.h>
#ifndef lint
2017-09-08 17:01:12 +03:00
__RCSID("$NetBSD: print-802_15_4.c,v 1.4 2017/09/08 14:01:12 christos Exp $");
2017-01-25 02:29:13 +03:00
#endif
2017-02-05 07:05:05 +03:00
/* \summary: IEEE 802.15.4 printer */
2013-04-06 21:57:45 +04:00
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
Tuesday October 25, 2016 mcr@sandelman.ca Summary for 4.8.1 tcpdump release Fix "-x" for Apple PKTAP and PPI packets Use PRIx64 to print a 64-bit number in hex. Printer for HNCP (RFCs 7787 and 7788). dagid is always an IPv6 address, not an opaque 128-bit string, and other fixes to RPL printer. RSVP: Add bounds and length checks OSPF: Do more bounds checking Handle OpenSSL 1.1.x. Initial support for the REdis Serialization Protocol known as RESP. Add printing function for Generic Protocol Extension for VXLAN draft-ietf-nvo3-vxlan-gpe-01 Network Service Header: draft-ietf-sfc-nsh-01 Don't recompile the filter if the new file has the same DLT. Pass an adjusted struct pcap_pkthdr to the sub-printer. Add three test cases for already fixed CVEs CVE-2014-8767: OLSR CVE-2014-8768: Geonet CVE-2014-8769: AODV Don't do the DDP-over-UDP heuristic first: GitHub issue #499. Use the new debugging routines in libpcap. Harmonize TCP source or destination ports tests with UDP ones Introduce data types to use for integral values in packet structures. RSVP: Fix an infinite loop Support of Type 3 and Type 4 LISP packets. Don't require IPv6 library support in order to support IPv6 addresses. Many many changes to support libnetdissect usage. Add a test that makes unaligned accesses: GitHub issue #478. add a DNSSEC test case: GH #445 and GH #467. BGP: add decoding of ADD-PATH capability fixes to LLC header printing, and RFC948-style IP packets Friday April 10, 2015 guy@alum.mit.edu Summary for 4.7.4 tcpdump release RPKI to Router Protocol: Fix Segmentation Faults and other problems RPKI to Router Protocol: print strings with fn_printn() wb: fix some bounds checks
2017-01-25 00:33:37 +03:00
#include <netdissect-stdinc.h>
2013-04-06 21:57:45 +04:00
Tuesday October 25, 2016 mcr@sandelman.ca Summary for 4.8.1 tcpdump release Fix "-x" for Apple PKTAP and PPI packets Use PRIx64 to print a 64-bit number in hex. Printer for HNCP (RFCs 7787 and 7788). dagid is always an IPv6 address, not an opaque 128-bit string, and other fixes to RPL printer. RSVP: Add bounds and length checks OSPF: Do more bounds checking Handle OpenSSL 1.1.x. Initial support for the REdis Serialization Protocol known as RESP. Add printing function for Generic Protocol Extension for VXLAN draft-ietf-nvo3-vxlan-gpe-01 Network Service Header: draft-ietf-sfc-nsh-01 Don't recompile the filter if the new file has the same DLT. Pass an adjusted struct pcap_pkthdr to the sub-printer. Add three test cases for already fixed CVEs CVE-2014-8767: OLSR CVE-2014-8768: Geonet CVE-2014-8769: AODV Don't do the DDP-over-UDP heuristic first: GitHub issue #499. Use the new debugging routines in libpcap. Harmonize TCP source or destination ports tests with UDP ones Introduce data types to use for integral values in packet structures. RSVP: Fix an infinite loop Support of Type 3 and Type 4 LISP packets. Don't require IPv6 library support in order to support IPv6 addresses. Many many changes to support libnetdissect usage. Add a test that makes unaligned accesses: GitHub issue #478. add a DNSSEC test case: GH #445 and GH #467. BGP: add decoding of ADD-PATH capability fixes to LLC header printing, and RFC948-style IP packets Friday April 10, 2015 guy@alum.mit.edu Summary for 4.7.4 tcpdump release RPKI to Router Protocol: Fix Segmentation Faults and other problems RPKI to Router Protocol: print strings with fn_printn() wb: fix some bounds checks
2017-01-25 00:33:37 +03:00
#include "netdissect.h"
2013-04-06 21:57:45 +04:00
#include "addrtoname.h"
#include "extract.h"
static const char *ftypes[] = {
"Beacon", /* 0 */
"Data", /* 1 */
"ACK", /* 2 */
"Command", /* 3 */
2017-09-08 17:01:12 +03:00
"Reserved (0x4)", /* 4 */
"Reserved (0x5)", /* 5 */
"Reserved (0x6)", /* 6 */
"Reserved (0x7)", /* 7 */
2013-04-06 21:57:45 +04:00
};
2017-09-08 17:01:12 +03:00
/*
* Frame Control subfields.
*/
#define FC_FRAME_TYPE(fc) ((fc) & 0x7)
#define FC_SECURITY_ENABLED 0x0008
#define FC_FRAME_PENDING 0x0010
#define FC_ACK_REQUEST 0x0020
#define FC_PAN_ID_COMPRESSION 0x0040
#define FC_DEST_ADDRESSING_MODE(fc) (((fc) >> 10) & 0x3)
#define FC_FRAME_VERSION(fc) (((fc) >> 12) & 0x3)
#define FC_SRC_ADDRESSING_MODE(fc) (((fc) >> 14) & 0x3)
#define FC_ADDRESSING_MODE_NONE 0x00
#define FC_ADDRESSING_MODE_RESERVED 0x01
#define FC_ADDRESSING_MODE_SHORT 0x02
#define FC_ADDRESSING_MODE_LONG 0x03
2013-04-06 21:57:45 +04:00
u_int
2014-11-20 04:30:52 +03:00
ieee802_15_4_if_print(netdissect_options *ndo,
2013-04-06 21:57:45 +04:00
const struct pcap_pkthdr *h, const u_char *p)
{
u_int caplen = h->caplen;
2017-09-08 17:01:12 +03:00
u_int hdrlen;
2014-11-20 04:30:52 +03:00
uint16_t fc;
uint8_t seq;
2017-09-08 17:01:12 +03:00
uint16_t panid = 0;
2013-04-06 21:57:45 +04:00
if (caplen < 3) {
2017-09-08 17:01:12 +03:00
ND_PRINT((ndo, "[|802.15.4]"));
2013-04-06 21:57:45 +04:00
return caplen;
}
2017-09-08 17:01:12 +03:00
hdrlen = 3;
2013-04-06 21:57:45 +04:00
fc = EXTRACT_LE_16BITS(p);
seq = EXTRACT_LE_8BITS(p + 2);
p += 3;
caplen -= 3;
2017-09-08 17:01:12 +03:00
ND_PRINT((ndo,"IEEE 802.15.4 %s packet ", ftypes[FC_FRAME_TYPE(fc)]));
2014-11-20 04:30:52 +03:00
if (ndo->ndo_vflag)
2013-04-06 21:57:45 +04:00
ND_PRINT((ndo,"seq %02x ", seq));
2017-09-08 17:01:12 +03:00
/*
* Destination address and PAN ID, if present.
*/
switch (FC_DEST_ADDRESSING_MODE(fc)) {
case FC_ADDRESSING_MODE_NONE:
if (fc & FC_PAN_ID_COMPRESSION) {
/*
* PAN ID compression; this requires that both
* the source and destination addresses be present,
* but the destination address is missing.
*/
ND_PRINT((ndo, "[|802.15.4]"));
return hdrlen;
}
if (ndo->ndo_vflag)
2013-04-06 21:57:45 +04:00
ND_PRINT((ndo,"none "));
2017-09-08 17:01:12 +03:00
break;
case FC_ADDRESSING_MODE_RESERVED:
if (ndo->ndo_vflag)
2013-04-06 21:57:45 +04:00
ND_PRINT((ndo,"reserved destination addressing mode"));
2017-09-08 17:01:12 +03:00
return hdrlen;
case FC_ADDRESSING_MODE_SHORT:
if (caplen < 2) {
ND_PRINT((ndo, "[|802.15.4]"));
return hdrlen;
}
panid = EXTRACT_LE_16BITS(p);
p += 2;
caplen -= 2;
hdrlen += 2;
if (caplen < 2) {
ND_PRINT((ndo, "[|802.15.4]"));
return hdrlen;
}
if (ndo->ndo_vflag)
2013-04-06 21:57:45 +04:00
ND_PRINT((ndo,"%04x:%04x ", panid, EXTRACT_LE_16BITS(p)));
2017-09-08 17:01:12 +03:00
p += 2;
caplen -= 2;
hdrlen += 2;
break;
case FC_ADDRESSING_MODE_LONG:
if (caplen < 2) {
ND_PRINT((ndo, "[|802.15.4]"));
return hdrlen;
}
panid = EXTRACT_LE_16BITS(p);
p += 2;
caplen -= 2;
hdrlen += 2;
if (caplen < 8) {
ND_PRINT((ndo, "[|802.15.4]"));
return hdrlen;
2013-04-06 21:57:45 +04:00
}
2017-09-08 17:01:12 +03:00
if (ndo->ndo_vflag)
ND_PRINT((ndo,"%04x:%s ", panid, le64addr_string(ndo, p)));
p += 8;
caplen -= 8;
hdrlen += 8;
break;
}
if (ndo->ndo_vflag)
2014-11-20 04:30:52 +03:00
ND_PRINT((ndo,"< "));
2013-04-06 21:57:45 +04:00
2017-09-08 17:01:12 +03:00
/*
* Source address and PAN ID, if present.
*/
switch (FC_SRC_ADDRESSING_MODE(fc)) {
case FC_ADDRESSING_MODE_NONE:
if (ndo->ndo_vflag)
2013-04-06 21:57:45 +04:00
ND_PRINT((ndo,"none "));
2017-09-08 17:01:12 +03:00
break;
case FC_ADDRESSING_MODE_RESERVED:
if (ndo->ndo_vflag)
2013-04-06 21:57:45 +04:00
ND_PRINT((ndo,"reserved source addressing mode"));
2017-09-08 17:01:12 +03:00
return 0;
case FC_ADDRESSING_MODE_SHORT:
if (!(fc & FC_PAN_ID_COMPRESSION)) {
/*
* The source PAN ID is not compressed out, so
* fetch it. (Otherwise, we'll use the destination
* PAN ID, fetched above.)
*/
if (caplen < 2) {
ND_PRINT((ndo, "[|802.15.4]"));
return hdrlen;
2013-04-06 21:57:45 +04:00
}
2017-09-08 17:01:12 +03:00
panid = EXTRACT_LE_16BITS(p);
2013-04-06 21:57:45 +04:00
p += 2;
2017-09-08 17:01:12 +03:00
caplen -= 2;
hdrlen += 2;
}
if (caplen < 2) {
ND_PRINT((ndo, "[|802.15.4]"));
return hdrlen;
}
if (ndo->ndo_vflag)
ND_PRINT((ndo,"%04x:%04x ", panid, EXTRACT_LE_16BITS(p)));
p += 2;
caplen -= 2;
hdrlen += 2;
break;
case FC_ADDRESSING_MODE_LONG:
if (!(fc & FC_PAN_ID_COMPRESSION)) {
/*
* The source PAN ID is not compressed out, so
* fetch it. (Otherwise, we'll use the destination
* PAN ID, fetched above.)
*/
if (caplen < 2) {
ND_PRINT((ndo, "[|802.15.4]"));
return hdrlen;
2013-04-06 21:57:45 +04:00
}
2017-09-08 17:01:12 +03:00
panid = EXTRACT_LE_16BITS(p);
p += 2;
caplen -= 2;
hdrlen += 2;
2013-04-06 21:57:45 +04:00
}
2017-09-08 17:01:12 +03:00
if (caplen < 8) {
ND_PRINT((ndo, "[|802.15.4]"));
return hdrlen;
}
if (ndo->ndo_vflag)
ND_PRINT((ndo,"%04x:%s ", panid, le64addr_string(ndo, p)));
p += 8;
caplen -= 8;
hdrlen += 8;
break;
2013-04-06 21:57:45 +04:00
}
2014-11-20 04:30:52 +03:00
if (!ndo->ndo_suppress_default_print)
ND_DEFAULTPRINT(p, caplen);
2013-04-06 21:57:45 +04:00
2017-09-08 17:01:12 +03:00
return hdrlen;
2013-04-06 21:57:45 +04:00
}