📄 prframe.c
字号:
/* prframe.c: Routines for decoding and printing 802.11 frames* ----------------------------------------------------------------* * The contents of this file are subject to the Mozilla Public* License Version 1.0 (the "License"); you may not use this file* except in compliance with the License. You may obtain a copy of* the License at http://www.mozilla.org/MPL/** Software distributed under the License is distributed on an "AS* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or* implied. See the License for the specific language governing* rights and limitations under the License.** The initial developer of the original code is Jo-Ellen F. Mathews* <joellen@absoval.com>. Portions were created by Jo-Ellen F.* Mathews and Mark S. Mathews and are Copyright (C) 1998* AbsoluteValue Software, Inc. All Rights Reserved.*----------------------------------------------------------------*/#include <stdlib.h>#include <stdio.h>#include <string.h>/* Ugly hack for LinuxPPC R4, don't have time to figure it out right now */#if defined(_ARCH_PPC)#undef __GLIBC__#endif#include <sys/socket.h>#include <sys/types.h>#include <sys/ioctl.h>#include <sys/param.h>#include <unistd.h>#include <wlan/version.h>#include <wlan/wlan_compat.h>#include <wlan/am930mib.h>#include <wlan/wlan_ioctl.h>#include "wlandump.h"/*----------------------------------------------------------------* Global Variables----------------------------------------------------------------*/wlan_p80211_frame_t MACframes[] = { { "mgmt", "assocreq", print_mgmt_assocreq }, { "mgmt", "assocresp", print_mgmt_assocresp }, { "mgmt", "atim", print_mgmt_ibssatim }, { "mgmt", "authen", print_mgmt_authen }, { "mgmt", "beacon", print_mgmt_beacon }, { "mgmt", "deauthen", print_mgmt_deauthen }, { "mgmt", "disassoc", print_mgmt_disassoc }, { "mgmt", "probereq", print_mgmt_probereq }, { "mgmt", "proberesp", print_mgmt_proberesp }, { "mgmt", "reassocreq", print_mgmt_reassocreq }, { "mgmt", "reassocresp", print_mgmt_reassocresp }, { "data", "data only", print_data_frame }, { "data", "data+cfack", print_data_frame }, { "data", "data+cfpoll", print_data_frame }, { "data", "data+cfack+cfpoll", print_data_frame }, { "data", "null", print_data_frame }, { "data", "cfack", print_data_frame }, { "data", "cfpoll", print_data_frame }, { "data", "cfack+cfpoll", print_data_frame }, { "ctl", "pspoll", print_ctl_pspoll }, { "ctl", "rts", print_ctl_rts }, { "ctl", "cts", print_ctl_cts }, { "ctl", "ack", print_ctl_ack }, { "ctl", "cfend", print_ctl_cfend }, { "ctl", "cfendcfack", print_ctl_cfendcfack }};/*----------------------------------------------------------------* print_80211_frame** This function receives an 802.11 frame, decodes the frame and* prints it.** Arguments:* frame_buffer - a wireless network frame* len - length of the frame** returns: 0 if successful, not 0 otherwise*----------------------------------------------------------------*/int print_80211_frame( wlan_sniffer_t *snif, UINT8 *frame_buffer, UINT16 len ){ int result; int index; unsigned int type; unsigned int stype; p80211_hdr_t *phdr; int i; UINT8 *pbuf; result = 0; index = -1; phdr = (p80211_hdr_t *)frame_buffer; type = WLAN_GET_FC_FTYPE(phdr->a3.fc); stype = WLAN_GET_FC_FSTYPE(phdr->a3.fc); if ( WLAN_GET_FC_ISWEP(phdr->a3.fc) && !opt_nodecrypt ) { wlandump_wep_decrypt( frame_buffer, len); } switch ( type ) { case WLAN_FTYPE_MGMT: if ( opt_noshowmgmt ) { return result; } switch ( stype ) { case WLAN_FSTYPE_ASSOCREQ: index = MGMT_TYPE_ASSOCREQ; break; case WLAN_FSTYPE_ASSOCRESP: index = MGMT_TYPE_ASSOCRESP; break; case WLAN_FSTYPE_REASSOCREQ: index = MGMT_TYPE_REASSOCREQ; break; case WLAN_FSTYPE_REASSOCRESP: index = MGMT_TYPE_REASSOCRESP; break; case WLAN_FSTYPE_PROBEREQ: index = MGMT_TYPE_PROBEREQ; break; case WLAN_FSTYPE_PROBERESP: index = MGMT_TYPE_PROBERESP; break; case WLAN_FSTYPE_BEACON: index = MGMT_TYPE_BEACON; break; case WLAN_FSTYPE_ATIM: index = MGMT_TYPE_ATIM; break; case WLAN_FSTYPE_DISASSOC: index = MGMT_TYPE_DISASSOC; break; case WLAN_FSTYPE_AUTHEN: index = MGMT_TYPE_AUTHEN; break; case WLAN_FSTYPE_DEAUTHEN: index = MGMT_TYPE_DEAUTHEN; break; default: printf("???"); break; } break; case WLAN_FTYPE_CTL: if ( opt_noshowctl ) { return result; } switch ( stype ) { case WLAN_FSTYPE_PSPOLL: index = CTL_TYPE_PSPOLL; break; case WLAN_FSTYPE_RTS: index = CTL_TYPE_RTS; break; case WLAN_FSTYPE_CTS: index = CTL_TYPE_CTS; break; case WLAN_FSTYPE_ACK: index = CTL_TYPE_ACK; break; case WLAN_FSTYPE_CFEND: index = CTL_TYPE_CFEND; break; case WLAN_FSTYPE_CFENDCFACK: index = CTL_TYPE_CFENDCFACK; break; default: printf("???"); break; } break; case WLAN_FTYPE_DATA: if ( opt_noshowdata ) { return result; } switch ( stype ) { case WLAN_FSTYPE_DATAONLY: index=DATA_TYPE_DATAONLY; break; case WLAN_FSTYPE_DATA_CFACK: index=DATA_TYPE_DATA_CFACK; break; case WLAN_FSTYPE_DATA_CFPOLL: index=DATA_TYPE_DATA_CFPOLL; break; case WLAN_FSTYPE_DATA_CFACK_CFPOLL: index=DATA_TYPE_DATA_CFACK_CFPOLL; break; case WLAN_FSTYPE_NULL: index=DATA_TYPE_NULL; break; case WLAN_FSTYPE_CFACK: index=DATA_TYPE_CFACK; break; case WLAN_FSTYPE_CFPOLL: index=DATA_TYPE_CFPOLL; break; case WLAN_FSTYPE_CFACK_CFPOLL: index=DATA_TYPE_CFACK_CFPOLL; break; default: printf("???"); break; } break; default: printf("???/???"); printf("\n\n"); break; } if ( (index != -1) && (result == 0) ) { /* Print the sniffer stats */ if ( !(index == MGMT_TYPE_BEACON && opt_nobeacon) ) { if ( snif->istx ) { printf("TX\n"); } else { printf("RX rssi=%d ch=%d rate=%d\n", snif->rssi, snif->ch, snif->rate); } /* if raw display is selected, print out the raw frame */ if ( opt_showraw ) { printf(" "); pbuf = frame_buffer; for ( i = 0; i < len; i++, pbuf++ ) { printf("%02x ", *pbuf ); if ( (i % 16) == 15 ) { printf("\n "); } } if ( ((i-1) % 16) != 15 ) printf("\n"); } /* print specific frame type */ (*(MACframes[index].pfunc))(frame_buffer, index, len); /* jump to FCS and print it */ if ( !(index == MGMT_TYPE_BEACON && opt_nobeacon) ) { frame_buffer = frame_buffer + (len - 4); printf("FCS=0x%02x%02x%02x%02x\n", *frame_buffer, *(frame_buffer+1), *(frame_buffer+2), *(frame_buffer+3) ); printf( "----------------------------" "----------------------------\n"); } } } else { int i,j; fprintf(stderr, "%s: Can not determine frame type. Hex dump:\n", appname); for ( i=0; i < len; i++) { for ( j = 0; j < 16 && i + j < len; j++) { fprintf(stderr,"%02x ", *(frame_buffer + i + j)); } i += j - 1; fprintf(stderr,"\n"); } } return result;}/*----------------------------------------------------------------* print_80211_frame_ctl** This function decodes and prints the frame control portion* of an 802.11 frame header** Arguments:* phdr - pointer to header of a wireless network frame* index - represents the index into the global array of * frame types ** returns: nothing*----------------------------------------------------------------*/void print_80211_frame_ctl( p80211_hdr_t *phdr, int index ){ printf("%s/%s", MACframes[index].type, MACframes[index].stype); if( WLAN_GET_FC_TODS(phdr->a3.fc) ) printf("|toDS"); if( WLAN_GET_FC_FROMDS(phdr->a3.fc) ) printf("|frDS"); if( WLAN_GET_FC_MOREFRAG(phdr->a3.fc) ) printf("|morFrag"); if( WLAN_GET_FC_RETRY(phdr->a3.fc) ) printf("|retry"); if( WLAN_GET_FC_PWRMGT(phdr->a3.fc) ) printf("|pwrMgt"); if( WLAN_GET_FC_MOREDATA(phdr->a3.fc) ) printf("|morData"); if( WLAN_GET_FC_ISWEP(phdr->a3.fc) ) printf("|wep"); if( WLAN_GET_FC_ORDER(phdr->a3.fc) ) printf("|ord");}/*----------------------------------------------------------------* print_80211_ctl_header** This function decodes and prints the frame header for 802.11* control frames.** Arguments:* phdr - pointer to header of a wireless network frame* index - represents the index into the global array of * frame types * len - length of frame** returns: nothing*----------------------------------------------------------------*/void print_80211_ctl_header( p80211_hdr_t *phdr, int index, UINT16 len ){ print_80211_frame_ctl( phdr, index ); switch ( index ) { case CTL_TYPE_PSPOLL: printf("\nBSSID=%02x:%02x:%02x:%02x:%02x:%02x ", phdr->a3.a1[0], phdr->a3.a1[1], phdr->a3.a1[2], phdr->a3.a1[3], phdr->a3.a1[4], phdr->a3.a1[5]); printf("TA=%02x:%02x:%02x:%02x:%02x:%02x ", phdr->a3.a2[0], phdr->a3.a2[1], phdr->a3.a2[2], phdr->a3.a2[3], phdr->a3.a2[4], phdr->a3.a2[5]); printf("\naid=0x%04x|", phdr->a3.dur); break; case CTL_TYPE_RTS: printf("\nRA=%02x:%02x:%02x:%02x:%02x:%02x ", phdr->a3.a1[0], phdr->a3.a1[1], phdr->a3.a1[2], phdr->a3.a1[3], phdr->a3.a1[4], phdr->a3.a1[5]); printf("TA=%02x:%02x:%02x:%02x:%02x:%02x ", phdr->a3.a2[0], phdr->a3.a2[1], phdr->a3.a2[2], phdr->a3.a2[3], phdr->a3.a2[4], phdr->a3.a2[5]); printf("\ndur=0x%04x|", phdr->a3.dur); break; case CTL_TYPE_CTS: case CTL_TYPE_ACK: printf("\nRA=%02x:%02x:%02x:%02x:%02x:%02x ", phdr->a3.a1[0], phdr->a3.a1[1], phdr->a3.a1[2], phdr->a3.a1[3], phdr->a3.a1[4], phdr->a3.a1[5]); printf("\ndur=0x%04x|", phdr->a3.dur); break; case CTL_TYPE_CFEND: case CTL_TYPE_CFENDCFACK: printf("\nRA=%02x:%02x:%02x:%02x:%02x:%02x ", phdr->a3.a1[0], phdr->a3.a1[1], phdr->a3.a1[2], phdr->a3.a1[3], phdr->a3.a1[4], phdr->a3.a1[5]); printf("BSSID=%02x:%02x:%02x:%02x:%02x:%02x ", phdr->a3.a2[0], phdr->a3.a2[1], phdr->a3.a2[2], phdr->a3.a2[3], phdr->a3.a2[4], phdr->a3.a2[5]); printf("\ndur=0x%04x|", phdr->a3.dur); break; } printf("len=%u|", len );}/*----------------------------------------------------------------* print_80211_data_header** This function decodes and prints the frame header for 802.11* data frames.** Arguments:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -