Compare commits

..

3 Commits

Author SHA1 Message Date
bbd9623256 Added helper for vector-stats 2021-11-22 13:29:39 +01:00
5ea6d1f975 Implemented usage of packetType-enum 2021-11-22 13:29:26 +01:00
c87a95b167 Changed type to enum-packet-type 2021-11-22 13:29:02 +01:00
3 changed files with 62 additions and 1 deletions

View File

@ -3,6 +3,19 @@
#include <string> #include <string>
enum PacketType {
Beacon,
ProbeRequest,
ProbeResponse,
Data,
RequestToSend,
ClearToSend,
Acknowledgment,
BlockAcknowledgment,
NoData,
Unknown
};
struct Packet { struct Packet {
uint64_t timestampMicros; uint64_t timestampMicros;
@ -16,7 +29,7 @@ struct Packet {
unsigned int frequency; unsigned int frequency;
unsigned char dataRate; unsigned char dataRate;
std::string type; PacketType type;
}; };
#endif /* C42FA9F6_8CF3_453F_8FA0_918E543DCD59 */ #endif /* C42FA9F6_8CF3_453F_8FA0_918E543DCD59 */

View File

@ -10,6 +10,19 @@
#include "../helper/split.hpp" #include "../helper/split.hpp"
#include "../helper/timestampConvert.hpp" #include "../helper/timestampConvert.hpp"
#include "../helper/find.hpp" #include "../helper/find.hpp"
#include "../helper/vector-stats.hpp"
#include <unordered_map>
const std::unordered_map<std::string, PacketType> PACKET_TYPE_MAP({
{"Beacon", PacketType::Beacon},
{"Probe Request", PacketType::ProbeRequest},
{"Probe Response", PacketType::ProbeResponse},
{"Data", PacketType::Data},
{"Request-To-Send", PacketType::RequestToSend},
{"Clear-To-Send", PacketType::ClearToSend},
{"Acknowledgment", PacketType::Acknowledgment},
{"BA", PacketType::BlockAcknowledgment}
});
void textPacketHandler(std::vector<std::string> textPacket){ void textPacketHandler(std::vector<std::string> textPacket){
/// Here we have to parse the packet /// Here we have to parse the packet
@ -63,6 +76,26 @@ void textPacketHandler(std::vector<std::string> textPacket){
packet.srcMac = sAddr; packet.srcMac = sAddr;
packet.dstMac = dAddr; packet.dstMac = dAddr;
packet.bssid = bssidAddr; packet.bssid = bssidAddr;
// Identify type of packet
// -> comes right after the addresses
int typeIndex = max(std::vector({saIndex, daIndex, bssidIndex, taIndex, raIndex}))+1;
PacketType type = PacketType::Unknown;
if(typeIndex == headerData.size()) type = PacketType::NoData;
else {
std::string textType = headerData[typeIndex];
// Check for incomplete types
if(textType == "Probe"){
textType += " "+ headerData[typeIndex+1];
}
// If type is in map, use map-value, otherwise keep default
if(PACKET_TYPE_MAP.find(textType) != PACKET_TYPE_MAP.end())
type = PACKET_TYPE_MAP[textType];
}
//
} }
#endif /* EE781A91_6D07_47AC_B3C4_F99E29F3731F */ #endif /* EE781A91_6D07_47AC_B3C4_F99E29F3731F */

15
helper/vector-stats.hpp Normal file
View File

@ -0,0 +1,15 @@
#ifndef C437A277_1F23_496D_9B69_A21D771ECA91
#define C437A277_1F23_496D_9B69_A21D771ECA91
#include <vector>
#include <limits.h>
int max(std::vector<int> vec){
int max = INT_MIN;
for(int i=0; i<vec.size(); ++i){
if(vec[i] > max) max = vec[i];
}
return max;
}
#endif /* C437A277_1F23_496D_9B69_A21D771ECA91 */