diff options
author | Seonah Moon <seonah1.moon@samsung.com> | 2020-01-14 13:37:47 +0900 |
---|---|---|
committer | Seonah Moon <seonah1.moon@samsung.com> | 2020-01-14 13:48:06 +0900 |
commit | 449508ea5ea236177e8caf71ca001e80ed0ec601 (patch) | |
tree | 0dcd3471243309053427b0b967d5d3f2a11252cd /print-lwapp.c | |
parent | ddb6800a866ac59478d5806f449597230b21d342 (diff) | |
parent | 9ceaf0d786e9465506271e8450248a57719e4eb1 (diff) | |
download | tcpdump-449508ea5ea236177e8caf71ca001e80ed0ec601.tar.gz tcpdump-449508ea5ea236177e8caf71ca001e80ed0ec601.tar.bz2 tcpdump-449508ea5ea236177e8caf71ca001e80ed0ec601.zip |
Upgrade to 4.9.3submit/tizen_4.0/20200117.075504accepted/tizen/4.0/unified/20200120.103833tizen_4.0accepted/tizen_4.0_unified
Change-Id: I6f9c6d67f2733ce6a7514179a45029f5f3934c6b
Diffstat (limited to 'print-lwapp.c')
-rw-r--r-- | print-lwapp.c | 118 |
1 files changed, 54 insertions, 64 deletions
diff --git a/print-lwapp.c b/print-lwapp.c index 154876f..bab3219 100644 --- a/print-lwapp.c +++ b/print-lwapp.c @@ -12,31 +12,24 @@ * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE. * - * Support for the Light Weight Access Point Protocol as per draft-ohara-capwap-lwapp-04 - * * Original code by Carles Kishimoto <carles.kishimoto@gmail.com> */ -#ifndef lint -static const char rcsid[] _U_ = -"@(#) $Header: /tcpdump/master/tcpdump/print-lwapp.c,v 1.1 2007-07-24 16:07:30 hannes Exp $"; -#endif +/* \summary: Light Weight Access Point Protocol (LWAPP) printer */ + +/* specification: RFC 5412 */ #ifdef HAVE_CONFIG_H #include "config.h" #endif -#include <tcpdump-stdinc.h> +#include <netdissect-stdinc.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include "interface.h" +#include "netdissect.h" #include "extract.h" #include "addrtoname.h" -/* +/* * LWAPP transport (common) header * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 @@ -49,10 +42,10 @@ static const char rcsid[] _U_ = */ struct lwapp_transport_header { - u_int8_t version; - u_int8_t frag_id; - u_int8_t length[2]; - u_int16_t status; + uint8_t version; + uint8_t frag_id; + uint8_t length[2]; + uint16_t status; }; /* @@ -69,16 +62,16 @@ struct lwapp_transport_header { */ struct lwapp_control_header { - u_int8_t msg_type; - u_int8_t seq_num; - u_int8_t len[2]; - u_int8_t session_id[4]; + uint8_t msg_type; + uint8_t seq_num; + uint8_t len[2]; + uint8_t session_id[4]; }; #define LWAPP_VERSION 0 -#define LWAPP_EXTRACT_VERSION(x) (((x)&0xC0)>>6) -#define LWAPP_EXTRACT_RID(x) (((x)&0x38)>>3) -#define LWAPP_EXTRACT_CONTROL_BIT(x) (((x)&0x04)>>2) +#define LWAPP_EXTRACT_VERSION(x) (((x)&0xC0)>>6) +#define LWAPP_EXTRACT_RID(x) (((x)&0x38)>>3) +#define LWAPP_EXTRACT_CONTROL_BIT(x) (((x)&0x04)>>2) static const struct tok lwapp_header_bits_values[] = { { 0x01, "Last Fragment Bit"}, @@ -154,9 +147,9 @@ static const struct tok lwapp_msg_type_values[] = { { 0, NULL} }; -/* +/* * LWAPP message elements - * + * * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ @@ -164,13 +157,14 @@ static const struct tok lwapp_msg_type_values[] = { * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ struct lwapp_message_header { - u_int8_t type; - u_int8_t length[2]; + uint8_t type; + uint8_t length[2]; }; void -lwapp_control_print(const u_char *pptr, u_int len, int has_ap_ident) { - +lwapp_control_print(netdissect_options *ndo, + const u_char *pptr, u_int len, int has_ap_ident) +{ const struct lwapp_transport_header *lwapp_trans_header; const struct lwapp_control_header *lwapp_control_header; const u_char *tptr; @@ -181,47 +175,45 @@ lwapp_control_print(const u_char *pptr, u_int len, int has_ap_ident) { if (has_ap_ident) { /* check if enough bytes for AP identity */ - if (!TTEST2(*tptr, 6)) - goto trunc; + ND_TCHECK2(*tptr, 6); lwapp_trans_header = (const struct lwapp_transport_header *)(pptr+6); } else { lwapp_trans_header = (const struct lwapp_transport_header *)pptr; } - TCHECK(*lwapp_trans_header); + ND_TCHECK(*lwapp_trans_header); /* * Sanity checking of the header. */ if (LWAPP_EXTRACT_VERSION(lwapp_trans_header->version) != LWAPP_VERSION) { - printf("LWAPP version %u packet not supported", - LWAPP_EXTRACT_VERSION(lwapp_trans_header->version)); + ND_PRINT((ndo, "LWAPP version %u packet not supported", + LWAPP_EXTRACT_VERSION(lwapp_trans_header->version))); return; } /* non-verbose */ - if (vflag < 1) { - printf("LWAPPv%u, %s frame, Flags [%s], length %u", + if (ndo->ndo_vflag < 1) { + ND_PRINT((ndo, "LWAPPv%u, %s frame, Flags [%s], length %u", LWAPP_EXTRACT_VERSION(lwapp_trans_header->version), LWAPP_EXTRACT_CONTROL_BIT(lwapp_trans_header->version) ? "Control" : "Data", bittok2str(lwapp_header_bits_values,"none",(lwapp_trans_header->version)&0x07), - len); + len)); return; } /* ok they seem to want to know everything - lets fully decode it */ tlen=EXTRACT_16BITS(lwapp_trans_header->length); - printf("LWAPPv%u, %s frame, Radio-id %u, Flags [%s], Frag-id %u, length %u", + ND_PRINT((ndo, "LWAPPv%u, %s frame, Radio-id %u, Flags [%s], Frag-id %u, length %u", LWAPP_EXTRACT_VERSION(lwapp_trans_header->version), LWAPP_EXTRACT_CONTROL_BIT(lwapp_trans_header->version) ? "Control" : "Data", LWAPP_EXTRACT_RID(lwapp_trans_header->version), bittok2str(lwapp_header_bits_values,"none",(lwapp_trans_header->version)&0x07), lwapp_trans_header->frag_id, - tlen); + tlen)); if (has_ap_ident) { - printf("\n\tAP identity: %s", - etheraddr_string(tptr)); + ND_PRINT((ndo, "\n\tAP identity: %s", etheraddr_string(ndo, tptr))); tptr+=sizeof(const struct lwapp_transport_header)+6; } else { tptr+=sizeof(const struct lwapp_transport_header); @@ -230,23 +222,21 @@ lwapp_control_print(const u_char *pptr, u_int len, int has_ap_ident) { while(tlen>0) { /* did we capture enough for fully decoding the object header ? */ - if (!TTEST2(*tptr, sizeof(struct lwapp_control_header))) - goto trunc; + ND_TCHECK2(*tptr, sizeof(struct lwapp_control_header)); lwapp_control_header = (const struct lwapp_control_header *)tptr; msg_tlen = EXTRACT_16BITS(lwapp_control_header->len); - /* print message header */ - printf("\n\t Msg type: %s (%u), Seqnum: %u, Msg len: %d, Session: 0x%08x", + /* print message header */ + ND_PRINT((ndo, "\n\t Msg type: %s (%u), Seqnum: %u, Msg len: %d, Session: 0x%08x", tok2str(lwapp_msg_type_values,"Unknown",lwapp_control_header->msg_type), lwapp_control_header->msg_type, lwapp_control_header->seq_num, msg_tlen, - EXTRACT_32BITS(lwapp_control_header->session_id)); + EXTRACT_32BITS(lwapp_control_header->session_id))); /* did we capture enough for fully decoding the message */ - if (!TTEST2(*tptr, msg_tlen)) - goto trunc; + ND_TCHECK2(*tptr, msg_tlen); /* XXX - Decode sub messages for each message */ switch(lwapp_control_header->msg_type) { @@ -291,12 +281,13 @@ lwapp_control_print(const u_char *pptr, u_int len, int has_ap_ident) { return; trunc: - printf("\n\t\t packet exceeded snapshot"); + ND_PRINT((ndo, "\n\t\t packet exceeded snapshot")); } void -lwapp_data_print(const u_char *pptr, u_int len) { - +lwapp_data_print(netdissect_options *ndo, + const u_char *pptr, u_int len) +{ const struct lwapp_transport_header *lwapp_trans_header; const u_char *tptr; int tlen; @@ -304,51 +295,50 @@ lwapp_data_print(const u_char *pptr, u_int len) { tptr=pptr; /* check if enough bytes for AP identity */ - if (!TTEST2(*tptr, 6)) - goto trunc; + ND_TCHECK2(*tptr, 6); lwapp_trans_header = (const struct lwapp_transport_header *)pptr; - TCHECK(*lwapp_trans_header); + ND_TCHECK(*lwapp_trans_header); /* * Sanity checking of the header. */ if (LWAPP_EXTRACT_VERSION(lwapp_trans_header->version) != LWAPP_VERSION) { - printf("LWAPP version %u packet not supported", - LWAPP_EXTRACT_VERSION(lwapp_trans_header->version)); + ND_PRINT((ndo, "LWAPP version %u packet not supported", + LWAPP_EXTRACT_VERSION(lwapp_trans_header->version))); return; } /* non-verbose */ - if (vflag < 1) { - printf("LWAPPv%u, %s frame, Flags [%s], length %u", + if (ndo->ndo_vflag < 1) { + ND_PRINT((ndo, "LWAPPv%u, %s frame, Flags [%s], length %u", LWAPP_EXTRACT_VERSION(lwapp_trans_header->version), LWAPP_EXTRACT_CONTROL_BIT(lwapp_trans_header->version) ? "Control" : "Data", bittok2str(lwapp_header_bits_values,"none",(lwapp_trans_header->version)&0x07), - len); + len)); return; } /* ok they seem to want to know everything - lets fully decode it */ tlen=EXTRACT_16BITS(lwapp_trans_header->length); - printf("LWAPPv%u, %s frame, Radio-id %u, Flags [%s], Frag-id %u, length %u", + ND_PRINT((ndo, "LWAPPv%u, %s frame, Radio-id %u, Flags [%s], Frag-id %u, length %u", LWAPP_EXTRACT_VERSION(lwapp_trans_header->version), LWAPP_EXTRACT_CONTROL_BIT(lwapp_trans_header->version) ? "Control" : "Data", LWAPP_EXTRACT_RID(lwapp_trans_header->version), bittok2str(lwapp_header_bits_values,"none",(lwapp_trans_header->version)&0x07), lwapp_trans_header->frag_id, - tlen); + tlen)); tptr+=sizeof(const struct lwapp_transport_header); tlen-=sizeof(const struct lwapp_transport_header); /* FIX - An IEEE 802.11 frame follows - hexdump for now */ - print_unknown_data(tptr, "\n\t", tlen); + print_unknown_data(ndo, tptr, "\n\t", tlen); return; trunc: - printf("\n\t\t packet exceeded snapshot"); + ND_PRINT((ndo, "\n\t\t packet exceeded snapshot")); } /* |