alttracermac80211.cc

00001 /*
00002  * Copyright (c) 2007 Regents of the SIGNET lab, University of Padova.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the University of Padova (SIGNET lab) nor the 
00014  *    names of its contributors may be used to endorse or promote products 
00015  *    derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
00018  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 
00019  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
00020  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 
00021  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00022  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
00023  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
00024  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
00025  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
00026  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
00027  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 #include <sap.h>
00031 #include <address.h>
00032 #include <mac.h>
00033 #include <mac-802_11.h>
00034 #include <packettracer.h>
00035 
00036 class AltTracerMac80211 : public Tracer
00037 {
00038 public:
00039   AltTracerMac80211();
00040   
00041   void format(Packet *p, SAP *sap);
00042   
00043 };
00044 
00045 
00046 AltTracerMac80211::AltTracerMac80211() : Tracer(2) {}
00047 
00048 void AltTracerMac80211::format(Packet *p, SAP *sap)
00049 {
00050   struct hdr_mac802_11 *mh = HDR_MAC802_11(p);
00051   hdr_cmn *ch = hdr_cmn::access(p);
00052 
00053   u_int32_t src = ETHER_ADDR(mh->dh_ta); 
00054   u_int32_t dst = ETHER_ADDR(mh->dh_ra);
00055         
00056   u_int8_t  type = mh->dh_fc.fc_type;
00057   u_int8_t  subtype = mh->dh_fc.fc_subtype;
00058 
00059   char* typestr;
00060   char* subtypestr;
00061 
00062   switch(type) 
00063     {
00064     case MAC_Type_Management:
00065       typestr = "MGMT";
00066       subtypestr = "";
00067       break;
00068 
00069     case MAC_Type_Control:
00070       typestr = "CTRL";
00071       switch(subtype) 
00072         {
00073         case MAC_Subtype_RTS:
00074           subtypestr = "RTS";
00075           break;
00076         case MAC_Subtype_CTS:
00077           subtypestr = "CTS";
00078           break;
00079         case MAC_Subtype_ACK:
00080           subtypestr = "ACK";
00081           break;
00082         default:
00083           subtypestr = NULL;
00084           break;
00085         }
00086       break;
00087 
00088     case MAC_Type_Data:
00089       typestr = "DATA";
00090       switch(subtype) 
00091         {
00092         case MAC_Subtype_Data:
00093           subtypestr = "";
00094           break;
00095         default:
00096           subtypestr = NULL;
00097           break;
00098         }
00099       break;
00100       
00101     default:
00102       typestr = NULL;
00103     }   
00104 
00105         
00106   if (typestr && subtypestr)
00107     {
00108       writeTrace(sap, " --MAC-- %d -> %d %s %s ",
00109                  src,
00110                  dst,
00111                  typestr,
00112                  subtypestr);
00113     }
00114 }
00115 
00116 
00117 extern "C" int Alttracermac_Init()
00118 {
00119   /*
00120    * Put here all the commands which must be execute when the library
00121    * is loaded (i.e. TCL script execution)  
00122    * Remember to return 0 if all is OK, otherwise return 1
00123   */
00124         
00125         SAP::addTracer(new AltTracerMac80211);
00126         return 0;
00127 }
00128 extern "C" int  Cygalttracermac_Init()
00129 {
00130   Alttracermac_Init();
00131 }
00132 
00133 

Generated on Wed Nov 26 15:47:28 2008 for NS-MIRACLE library by  doxygen 1.5.2