00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 #include <packet.h>
00054 #include <mac.h>
00055 #include <mac-802_11.h>
00056 #include "p802_15_4trace.h"
00057
00058
00059 #define dh_sa dh_ta
00060 #define dh_da dh_ra
00061
00062 #define use_hdr_802_11_for_trace
00063
00064 #ifndef use_hdr_802_11_for_trace
00065
00066 int p802_15_4macSA(Packet *p)
00067 {
00068 struct hdr_mac *mh = HDR_MAC(p);
00069 return mh->macSA();
00070 }
00071
00072 int p802_15_4macDA(Packet *p)
00073 {
00074 struct hdr_mac *mh = HDR_MAC(p);
00075 return mh->macDA();
00076 }
00077
00078 u_int16_t p802_15_4hdr_type(Packet *p)
00079 {
00080 struct hdr_mac *mh = HDR_MAC(p);
00081 return mh->hdr_type();
00082 }
00083
00084 int p802_15_4hdr_dst(char* hdr,int dst)
00085 {
00086 struct hdr_mac *mh = (struct hdr_mac*) hdr;
00087 if(dst > -2)
00088 mh->macDA_ = dst;
00089 return mh->macDA();
00090 }
00091
00092 int p802_15_4hdr_src(char* hdr,int src)
00093 {
00094 struct hdr_mac *mh = (struct hdr_mac*) hdr;
00095 if(src > -2)
00096 mh->macSA_ = src;
00097 return mh->macSA();
00098 }
00099
00100 int p802_15_4hdr_type(char* hdr, u_int16_t type)
00101 {
00102 struct hdr_mac *mh = (struct hdr_mac*) hdr;
00103 if (type)
00104 mh->hdr_type_ = type;
00105 return mh->hdr_type();
00106 }
00107
00108 void p802_15_4hdrDATA(Packet *p)
00109 {
00110 ;
00111 }
00112
00113 void p802_15_4hdrACK(Packet *p)
00114 {
00115 ;
00116 }
00117
00118 void p802_15_4hdrBeacon(Packet *p)
00119 {
00120 ;
00121 }
00122
00123 void p802_15_4hdrCommand(Packet *p, u_int16_t type)
00124 {
00125 ;
00126 }
00127
00128 #else
00129
00130 int p802_15_4macSA(Packet *p)
00131 {
00132 struct hdr_mac802_11 *mh = HDR_MAC802_11(p);
00133 return ETHER_ADDR(mh->dh_sa);
00134
00135 }
00136
00137 int p802_15_4macDA(Packet *p)
00138 {
00139 struct hdr_mac802_11 *mh = HDR_MAC802_11(p);
00140 return ETHER_ADDR(mh->dh_da);
00141 }
00142
00143 u_int16_t p802_15_4hdr_type(Packet *p)
00144 {
00145 struct hdr_mac802_11 *mh = HDR_MAC802_11(p);
00146 return GET2BYTE(mh->dh_body);
00147 }
00148
00149 int p802_15_4hdr_dst(char* hdr,int dst)
00150 {
00151 struct hdr_mac802_11 *mh = (struct hdr_mac802_11*) hdr;
00152 if(dst > -2)
00153 STORE4BYTE(&dst, (mh->dh_da));
00154 return ETHER_ADDR(mh->dh_da);
00155 }
00156
00157 int p802_15_4hdr_src(char* hdr,int src)
00158 {
00159 struct hdr_mac802_11 *mh = (struct hdr_mac802_11*) hdr;
00160 if(src > -2)
00161 STORE4BYTE(&src, (mh->dh_sa));
00162 return ETHER_ADDR(mh->dh_sa);
00163 }
00164
00165 int p802_15_4hdr_type(char* hdr, u_int16_t type)
00166 {
00167 struct hdr_mac802_11 *mh = (struct hdr_mac802_11*) hdr;
00168 if(type)
00169 STORE2BYTE(&type,(mh->dh_body));
00170 return GET2BYTE(mh->dh_body);
00171 }
00172
00173 void p802_15_4hdrDATA(Packet *p)
00174 {
00175 struct hdr_mac802_11* mh = HDR_MAC802_11(p);
00176
00177
00178
00179 mh->dh_fc.fc_protocol_version = MAC_ProtocolVersion;
00180 mh->dh_fc.fc_type = MAC_Type_Data;
00181 mh->dh_fc.fc_subtype = MAC_Subtype_Data;
00182 }
00183
00184 void p802_15_4hdrACK(Packet *p)
00185 {
00186 struct ack_frame *af = (struct ack_frame*)p->access(hdr_mac::offset_);
00187
00188 af->af_fc.fc_protocol_version = MAC_ProtocolVersion;
00189 af->af_fc.fc_type = MAC_Type_Control;
00190 af->af_fc.fc_subtype = MAC_Subtype_ACK;
00191 }
00192
00193 void p802_15_4hdrBeacon(Packet *p)
00194 {
00195 struct hdr_mac802_11* mh = HDR_MAC802_11(p);
00196
00197 mh->dh_fc.fc_protocol_version = MAC_ProtocolVersion;
00198 mh->dh_fc.fc_type = MAC_Type_Control;
00199 mh->dh_fc.fc_subtype = MAC_Subtype_Beacon;
00200 }
00201
00202 void p802_15_4hdrCommand(Packet *p, u_int16_t type)
00203 {
00204 struct hdr_mac802_11* mh = HDR_MAC802_11(p);
00205
00206 mh->dh_fc.fc_protocol_version = MAC_ProtocolVersion;
00207 mh->dh_fc.fc_type = MAC_Type_Control;
00208 mh->dh_fc.fc_subtype = type;
00209 }
00210
00211 #endif
00212
00213 const char *wpan_pName(Packet *p)
00214 {
00215 struct hdr_cmn *ch = HDR_CMN(p);
00216 struct hdr_mac802_11 *mh = HDR_MAC802_11(p);
00217 return
00218 ((ch->ptype() == PT_MAC) ? (
00219 (mh->dh_fc.fc_subtype == MAC_Subtype_Beacon) ? "M_BEACON" :
00220 (mh->dh_fc.fc_subtype == MAC_Subtype_Command_AssoReq) ? "M_CM1_AssoReq" :
00221 (mh->dh_fc.fc_subtype == MAC_Subtype_Command_AssoRsp) ? "M_CM2_AssoRsp" :
00222 (mh->dh_fc.fc_subtype == MAC_Subtype_Command_DAssNtf) ? "M_CM3_DisaNtf" :
00223 (mh->dh_fc.fc_subtype == MAC_Subtype_Command_DataReq) ? "M_CM4_DataReq" :
00224 (mh->dh_fc.fc_subtype == MAC_Subtype_Command_PIDCNtf) ? "M_CM5_PidCNtf" :
00225 (mh->dh_fc.fc_subtype == MAC_Subtype_Command_OrphNtf) ? "M_CM6_OrphNtf" :
00226 (mh->dh_fc.fc_subtype == MAC_Subtype_Command_BconReq) ? "M_CM7_Bcn-Req" :
00227 (mh->dh_fc.fc_subtype == MAC_Subtype_Command_CoorRea) ? "M_CM8_CoorRal" :
00228 (mh->dh_fc.fc_subtype == MAC_Subtype_Command_GTSReq) ? "M_CM9_GTS-Req" :
00229 (mh->dh_fc.fc_subtype == MAC_Subtype_ACK) ? "M_ACK" :
00230 "M_UNKN"
00231 ) : packet_info.name(ch->ptype()));
00232 }
00233
00234