2017-03-26 09:48:28 +08:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2019-03-26 19:17:45 +08:00
|
|
|
/* \summary: ZigBee Encapsulation Protocol (ZEP) printer */
|
2017-03-26 09:48:28 +08:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
2018-11-18 05:35:46 +08:00
|
|
|
#include <config.h>
|
2017-03-26 09:48:28 +08:00
|
|
|
#endif
|
|
|
|
|
2019-04-14 16:54:04 +08:00
|
|
|
#include "netdissect-stdinc.h"
|
2017-03-26 09:48:28 +08:00
|
|
|
|
2021-05-10 01:48:01 +08:00
|
|
|
#define ND_LONGJMP_FROM_TCHECK
|
2017-03-26 09:48:28 +08:00
|
|
|
#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 JAN_1970 2208988800U
|
|
|
|
|
|
|
|
/* Print timestamp */
|
|
|
|
static void zep_print_ts(netdissect_options *ndo, const u_char *p)
|
|
|
|
{
|
2018-11-18 05:35:46 +08:00
|
|
|
int32_t i;
|
|
|
|
uint32_t uf;
|
|
|
|
uint32_t f;
|
|
|
|
float ff;
|
2019-03-26 15:56:20 +08:00
|
|
|
|
2018-06-16 23:23:21 +08:00
|
|
|
i = GET_BE_U_4(p);
|
|
|
|
uf = GET_BE_U_4(p + 4);
|
2018-11-18 07:18:43 +08:00
|
|
|
ff = (float) uf;
|
2018-11-18 05:35:46 +08:00
|
|
|
if (ff < 0.0) /* some compilers are buggy */
|
|
|
|
ff += FMAXINT;
|
2018-11-18 07:18:43 +08:00
|
|
|
ff = (float) (ff / FMAXINT); /* shift radix point by 32 bits */
|
|
|
|
f = (uint32_t) (ff * 1000000000.0); /* treat fraction as parts per
|
|
|
|
billion */
|
2018-11-18 05:35:46 +08:00
|
|
|
ND_PRINT("%u.%09d", i, f);
|
2019-03-26 15:56:20 +08:00
|
|
|
|
2017-03-26 09:48:28 +08:00
|
|
|
#ifdef HAVE_STRFTIME
|
2018-11-18 05:35:46 +08:00
|
|
|
/*
|
|
|
|
* print the time in human-readable format.
|
|
|
|
*/
|
|
|
|
if (i) {
|
|
|
|
time_t seconds = i - JAN_1970;
|
|
|
|
struct tm *tm;
|
|
|
|
char time_buf[128];
|
2019-03-26 15:56:20 +08:00
|
|
|
|
2018-11-18 05:35:46 +08:00
|
|
|
tm = localtime(&seconds);
|
|
|
|
strftime(time_buf, sizeof (time_buf), "%Y/%m/%d %H:%M:%S", tm);
|
|
|
|
ND_PRINT(" (%s)", time_buf);
|
|
|
|
}
|
2017-03-26 09:48:28 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Main function to print packets.
|
|
|
|
*/
|
2018-11-18 05:35:46 +08:00
|
|
|
|
2017-03-26 09:48:28 +08:00
|
|
|
void
|
|
|
|
zep_print(netdissect_options *ndo,
|
|
|
|
const u_char *bp, u_int len)
|
|
|
|
{
|
2018-11-18 05:35:46 +08:00
|
|
|
uint8_t version, inner_len;
|
|
|
|
uint32_t seq_no;
|
2019-03-26 15:56:20 +08:00
|
|
|
|
2019-08-05 14:24:49 +08:00
|
|
|
ndo->ndo_protocol = "zep";
|
2017-03-26 09:48:28 +08:00
|
|
|
|
2019-06-12 00:19:46 +08:00
|
|
|
nd_print_protocol_caps(ndo);
|
2019-03-26 15:56:20 +08:00
|
|
|
|
2020-10-06 21:26:37 +08:00
|
|
|
/* Preamble Code (must be "EX") */
|
|
|
|
if (GET_U_1(bp) != 'E' || GET_U_1(bp + 1) != 'X') {
|
|
|
|
ND_PRINT(" [Preamble Code: ");
|
|
|
|
fn_print_char(ndo, GET_U_1(bp));
|
|
|
|
fn_print_char(ndo, GET_U_1(bp + 1));
|
|
|
|
ND_PRINT("]");
|
|
|
|
nd_print_invalid(ndo);
|
|
|
|
return;
|
|
|
|
}
|
2019-03-26 15:56:20 +08:00
|
|
|
|
2018-06-16 23:23:21 +08:00
|
|
|
version = GET_U_1(bp + 2);
|
2020-10-06 22:04:43 +08:00
|
|
|
ND_PRINT("v%u ", version);
|
2019-03-26 15:56:20 +08:00
|
|
|
|
2018-11-18 05:35:46 +08:00
|
|
|
if (version == 1) {
|
|
|
|
/* ZEP v1 packet. */
|
Update the ND_LCHECK*() macros to ND_ICHECK*() macros
ICHECK like Invalid-Check.
Reminder: If the checked expression is true an error message is printed
and a 'goto invalid' is executed.
This change adds the parameter 'operator'.
Before this change, '<' comparison was hard coded.
We can do now:
ND_ICHECK_U(length, <, HEADER_LEN);
ND_ICHECK_U(length, ==, 24);
ND_ICHECK_U(length, !=, 8);
ND_ICHECK_ZU(length, <, sizeof(struct my_struct));
ND_ICHECKMSG_U("message length", msg_tlen, <, 4);
...
(Any comparison operator)
Remark: The change of names from ND_LCHECK*() to ND_ICHECK*() is
because something else than a length(L) can be checked.
Moreover:
Place the 'message' parameter at the beginning of ND_ICHECKMSG_U()
and ND_ICHECKMSG_ZU() paramaters lists.
2021-12-29 21:38:08 +08:00
|
|
|
ND_ICHECK_U(len, <, 16);
|
2020-10-06 22:04:43 +08:00
|
|
|
ND_PRINT("Channel ID %u, Device ID 0x%04x, ",
|
2018-06-16 23:23:21 +08:00
|
|
|
GET_U_1(bp + 3), GET_BE_U_2(bp + 4));
|
|
|
|
if (GET_U_1(bp + 6))
|
2018-11-18 05:35:46 +08:00
|
|
|
ND_PRINT("CRC, ");
|
|
|
|
else
|
2020-10-06 22:04:43 +08:00
|
|
|
ND_PRINT("LQI %u, ", GET_U_1(bp + 7));
|
2018-06-16 23:23:21 +08:00
|
|
|
inner_len = GET_U_1(bp + 15);
|
2020-10-06 22:04:43 +08:00
|
|
|
ND_PRINT("inner len = %u", inner_len);
|
2019-03-26 15:56:20 +08:00
|
|
|
|
2018-11-18 05:35:46 +08:00
|
|
|
bp += 16;
|
|
|
|
len -= 16;
|
|
|
|
} else {
|
|
|
|
/* ZEP v2 packet. */
|
2018-06-16 23:23:21 +08:00
|
|
|
if (GET_U_1(bp + 3) == 2) {
|
2018-11-18 05:35:46 +08:00
|
|
|
/* ZEP v2 ack. */
|
Update the ND_LCHECK*() macros to ND_ICHECK*() macros
ICHECK like Invalid-Check.
Reminder: If the checked expression is true an error message is printed
and a 'goto invalid' is executed.
This change adds the parameter 'operator'.
Before this change, '<' comparison was hard coded.
We can do now:
ND_ICHECK_U(length, <, HEADER_LEN);
ND_ICHECK_U(length, ==, 24);
ND_ICHECK_U(length, !=, 8);
ND_ICHECK_ZU(length, <, sizeof(struct my_struct));
ND_ICHECKMSG_U("message length", msg_tlen, <, 4);
...
(Any comparison operator)
Remark: The change of names from ND_LCHECK*() to ND_ICHECK*() is
because something else than a length(L) can be checked.
Moreover:
Place the 'message' parameter at the beginning of ND_ICHECKMSG_U()
and ND_ICHECKMSG_ZU() paramaters lists.
2021-12-29 21:38:08 +08:00
|
|
|
ND_ICHECK_U(len, <, 8);
|
2018-06-16 23:23:21 +08:00
|
|
|
seq_no = GET_BE_U_4(bp + 4);
|
2020-10-06 22:04:43 +08:00
|
|
|
ND_PRINT("ACK, seq# = %u", seq_no);
|
2018-11-18 05:35:46 +08:00
|
|
|
inner_len = 0;
|
|
|
|
bp += 8;
|
|
|
|
len -= 8;
|
|
|
|
} else {
|
|
|
|
/* ZEP v2 data, or some other. */
|
Update the ND_LCHECK*() macros to ND_ICHECK*() macros
ICHECK like Invalid-Check.
Reminder: If the checked expression is true an error message is printed
and a 'goto invalid' is executed.
This change adds the parameter 'operator'.
Before this change, '<' comparison was hard coded.
We can do now:
ND_ICHECK_U(length, <, HEADER_LEN);
ND_ICHECK_U(length, ==, 24);
ND_ICHECK_U(length, !=, 8);
ND_ICHECK_ZU(length, <, sizeof(struct my_struct));
ND_ICHECKMSG_U("message length", msg_tlen, <, 4);
...
(Any comparison operator)
Remark: The change of names from ND_LCHECK*() to ND_ICHECK*() is
because something else than a length(L) can be checked.
Moreover:
Place the 'message' parameter at the beginning of ND_ICHECKMSG_U()
and ND_ICHECKMSG_ZU() paramaters lists.
2021-12-29 21:38:08 +08:00
|
|
|
ND_ICHECK_U(len, <, 32);
|
2020-10-06 22:04:43 +08:00
|
|
|
ND_PRINT("Type %u, Channel ID %u, Device ID 0x%04x, ",
|
2018-06-16 23:23:21 +08:00
|
|
|
GET_U_1(bp + 3), GET_U_1(bp + 4),
|
|
|
|
GET_BE_U_2(bp + 5));
|
|
|
|
if (GET_U_1(bp + 7))
|
2018-11-18 05:35:46 +08:00
|
|
|
ND_PRINT("CRC, ");
|
|
|
|
else
|
2020-10-06 22:04:43 +08:00
|
|
|
ND_PRINT("LQI %u, ", GET_U_1(bp + 8));
|
2019-03-26 15:56:20 +08:00
|
|
|
|
2018-11-18 05:35:46 +08:00
|
|
|
zep_print_ts(ndo, bp + 9);
|
2018-06-16 23:23:21 +08:00
|
|
|
seq_no = GET_BE_U_4(bp + 17);
|
|
|
|
inner_len = GET_U_1(bp + 31);
|
2020-10-06 22:04:43 +08:00
|
|
|
ND_PRINT(", seq# = %u, inner len = %u",
|
2018-11-18 05:35:46 +08:00
|
|
|
seq_no, inner_len);
|
|
|
|
bp += 32;
|
|
|
|
len -= 32;
|
|
|
|
}
|
|
|
|
}
|
2019-03-26 15:56:20 +08:00
|
|
|
|
2018-11-18 05:35:46 +08:00
|
|
|
if (inner_len != 0) {
|
|
|
|
/* Call 802.15.4 dissector. */
|
|
|
|
ND_PRINT("\n\t");
|
|
|
|
if (ieee802_15_4_print(ndo, bp, inner_len)) {
|
2021-05-10 01:48:01 +08:00
|
|
|
ND_TCHECK_LEN(bp, len);
|
2018-11-18 05:35:46 +08:00
|
|
|
bp += len;
|
|
|
|
len = 0;
|
|
|
|
}
|
|
|
|
}
|
2019-03-26 15:56:20 +08:00
|
|
|
|
2018-11-18 05:35:46 +08:00
|
|
|
if (!ndo->ndo_suppress_default_print)
|
|
|
|
ND_DEFAULTPRINT(bp, len);
|
2021-11-28 17:57:14 +08:00
|
|
|
return;
|
|
|
|
invalid:
|
|
|
|
nd_print_invalid(ndo);
|
2017-03-26 09:48:28 +08:00
|
|
|
}
|