diff options
author | Tero Kivinen <kivinen@iki.fi> | 2017-03-26 04:48:28 +0300 |
---|---|---|
committer | Tero Kivinen <kivinen@iki.fi> | 2017-03-26 04:48:28 +0300 |
commit | 13ebc79dfc72326f74e29b48792bb25397077906 (patch) | |
tree | d51f99d5fd1c0309f68dad3f974aedf7fd10ff01 /print-zep.c | |
parent | 8cf42af454be32c3f41fd159ba41839fa2724fd5 (diff) | |
download | tcpdump-13ebc79dfc72326f74e29b48792bb25397077906.tar.gz |
IEEE 802.15.4 printer which understands frame version 2 frames, and also knows how to print some mac commands and IE contents. Also includes the zep printer to decode ZigBee Encapsulation Protocol frames
Diffstat (limited to 'print-zep.c')
-rw-r--r-- | print-zep.c | 174 |
1 files changed, 174 insertions, 0 deletions
diff --git a/print-zep.c b/print-zep.c new file mode 100644 index 00000000..f0962356 --- /dev/null +++ b/print-zep.c @@ -0,0 +1,174 @@ +/* + * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 + * The Regents of the University of California. All rights reserved. + * + * 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 <netdissect-stdinc.h> + +#include "netdissect.h" + +#include "extract.h" + +/* From wireshark packet-zep.c: + * + *********************************************************************** + * + * ZEP Packets must be received in the following format: + * + * |UDP Header| ZEP Header |IEEE 802.15.4 Packet| + * | 8 bytes | 16/32 bytes | <= 127 bytes | + * + *********************************************************************** + * + * ZEP v1 Header will have the following format: + * + * |Preamble|Version|Channel ID|Device ID|CRC/LQI Mode|LQI Val|Reserved|Length| + * |2 bytes |1 byte | 1 byte | 2 bytes | 1 byte |1 byte |7 bytes |1 byte| + * + * ZEP v2 Header will have the following format (if type=1/Data): + * |Prmbl|Ver |Type |ChnlID|DevID|C/L Mode|LQI|NTP TS|Seq#|Res |Len| + * | 2 | 1 | 1 | 1 | 2 | 1 | 1 | 8 | 4 | 10 | 1 | + * + * ZEP v2 Header will have the following format (if type=2/Ack): + * |Preamble|Version| Type |Sequence#| + * |2 bytes |1 byte |1 byte| 4 bytes | + *------------------------------------------------------------ + */ + +#define FMAXINT (4294967296.0) /* floating point rep. of MAXINT */ +#define JAN_1970 2208988800U + +/* Print timestamp */ +static void zep_print_ts(netdissect_options *ndo, const u_char *p) +{ + int32_t i; + uint32_t uf; + uint32_t f; + float ff; + + i = EXTRACT_32BITS(p); + uf = EXTRACT_32BITS(p + 4); + ff = uf; + if (ff < 0.0) /* some compilers are buggy */ + ff += FMAXINT; + ff = ff / FMAXINT; /* shift radix point by 32 bits */ + f = ff * 1000000000.0; /* treat fraction as parts per billion */ + ND_PRINT((ndo, "%u.%09d", i, f)); + +#ifdef HAVE_STRFTIME + /* + * print the time in human-readable format. + */ + if (i) { + time_t seconds = i - JAN_1970; + struct tm *tm; + char time_buf[128]; + + tm = localtime(&seconds); + strftime(time_buf, sizeof (time_buf), "%Y/%m/%d %H:%M:%S", tm); + ND_PRINT((ndo, " (%s)", time_buf)); + } +#endif +} + +/* + * Main function to print packets. + */ + +void +zep_print(netdissect_options *ndo, + const u_char *bp, u_int len) +{ + uint8_t version, inner_len; + uint32_t seq_no; + + ND_PRINT((ndo, "ZEP")); + + ND_TCHECK2(*bp, 8); + + if (*bp != 'E' || *(bp+1) != 'X') goto trunc; + + version = *(bp + 2); + ND_PRINT((ndo, "v%d ", version)); + + if (version == 1) { + /* ZEP v1 packet. */ + ND_TCHECK2(*bp, 16); + ND_PRINT((ndo, "Channel ID %d, Device ID 0x%04x, ", + *(bp + 3), EXTRACT_16BITS(bp + 4))); + if (*(bp + 6)) + ND_PRINT((ndo, "CRC, ")); + else + ND_PRINT((ndo, "LQI %d, ", *(bp + 7))); + inner_len = *(bp + 15); + ND_PRINT((ndo, "inner len = %d", inner_len)); + + bp += 16; + len -= 16; + } else { + /* ZEP v2 packet. */ + if (*(bp + 3) == 2) { + /* ZEP v2 ack. */ + seq_no = EXTRACT_32BITS(bp + 4); + ND_PRINT((ndo, "ACK, seq# = %d", seq_no)); + inner_len = 0; + bp += 8; + len -= 8; + } else { + /* ZEP v2 data, or some other. */ + ND_TCHECK2(*bp, 32); + + ND_PRINT((ndo, "Type %d, Channel ID %d, Device ID 0x%04x, ", + *(bp + 3), *(bp + 4), EXTRACT_16BITS(bp + 5))); + if (*(bp + 7)) + ND_PRINT((ndo, "CRC, ")); + else + ND_PRINT((ndo, "LQI %d, ", *(bp + 8))); + + zep_print_ts(ndo, bp + 9); + seq_no = EXTRACT_32BITS(bp + 17); + inner_len = *(bp + 31); + ND_PRINT((ndo, ", seq# = %d, inner len = %d", seq_no, inner_len)); + bp += 32; + len -= 32; + } + } + + if (inner_len != 0) { + u_int ret; + /* Call 802.15.4 dissector. */ + ND_PRINT((ndo, "\n\t")); + if (ieee802_15_4_print(ndo, bp, inner_len)) { + bp += len; + len = 0; + } + } + + if (!ndo->ndo_suppress_default_print) + ND_DEFAULTPRINT(bp, len); + + return; + trunc: + ND_PRINT((ndo, " [|ZEP]")); +} |