<commit_before>
#include "headings.h"

#ifndef ETHERNETCONTROL_H_
#define ETHERNETCONTROL_H_

#include <cstdio>
#include <sstream>
#include <set>

#include "pcap.h"

#ifdef DEBUGAPS	
#include "DummyAPS.h"
#endif

using std::vector;
using std::string;
using std::map;
using std::ostringstream;

//We use MAC addresses all the time so wrap in their own class
class MACAddr{
public:

	MACAddr();
	MACAddr(const int &);
	MACAddr(const string &);

	string to_string() const;

	static bool is_valid(const string &);
	static const unsigned int MAC_ADDR_LEN = 6;

	vector<uint8_t> addr;

};


struct EthernetDevInfo {
	string name_;
	string description_;
	bool isActive_;
};

struct APSEthernetHeader {
	MACAddr  dest;
	MACAddr  src;
	uint16_t frameType;
	uint16_t seqNum;
	APSCommand_t command;
	uint32_t addr;
};



//Custom UDP style ethernet packets for APS
class EthernetControl;
class APSEthernetPacket{
public:
	APSEthernetHeader header;
	vector<uint8_t> payload;

	APSEthernetPacket();
	APSEthernetPacket(const MACAddr &, const MACAddr &, APSCommand_t, const uint32_t &);

	static const size_t NUM_HEADER_BYTES = 24;

	vector<uint8_t> serialize() const ;
	inline size_t numBytes() const {return 24 + payload.size();};
	void set_MAC(uint8_t *, uint8_t *);
};



class EthernetControl 
{
public:
	friend class APSEthernetPacket;
	enum ErrorCodes {
    	SUCCESS = 0,
    	NOT_IMPLEMENTED = -1,
    	INVALID_NETWORK_DEVICE = -2,
    	INVALID_PCAP_FILTER = -3,
    	INVALID_APS_ID = -4,
    	TIMEOUT = -5,
    	INVALID_SPI_TARGET
	};

	typedef void (*DebugPacketCallback)(const void * data, unsigned int length);  


	static const uint16_t APS_PROTO = 0xBBAE;

	static const uint16_t MAX_PAYLOAD_LEN_BYTES = 1468;
	static const uint16_t MAX_PAYLOAD_LEN_WORDS = MAX_PAYLOAD_LEN_BYTES / sizeof(uint32_t);
	static const uint16_t MIN_PAYLOAD_LEN_BYTES = 36;
<commit_msg>Fix hex version of ethernet protocol BB4E.<commit_after>
#include "headings.h"

#ifndef ETHERNETCONTROL_H_
#define ETHERNETCONTROL_H_

#include <cstdio>
#include <sstream>
#include <set>

#include "pcap.h"

#ifdef DEBUGAPS	
#include "DummyAPS.h"
#endif

using std::vector;
using std::string;
using std::map;
using std::ostringstream;

//We use MAC addresses all the time so wrap in their own class
class MACAddr{
public:

	MACAddr();
	MACAddr(const int &);
	MACAddr(const string &);

	string to_string() const;

	static bool is_valid(const string &);
	static const unsigned int MAC_ADDR_LEN = 6;

	vector<uint8_t> addr;

};


struct EthernetDevInfo {
	string name_;
	string description_;
	bool isActive_;
};

struct APSEthernetHeader {
	MACAddr  dest;
	MACAddr  src;
	uint16_t frameType;
	uint16_t seqNum;
	APSCommand_t command;
	uint32_t addr;
};



//Custom UDP style ethernet packets for APS
class EthernetControl;
class APSEthernetPacket{
public:
	APSEthernetHeader header;
	vector<uint8_t> payload;

	APSEthernetPacket();
	APSEthernetPacket(const MACAddr &, const MACAddr &, APSCommand_t, const uint32_t &);

	static const size_t NUM_HEADER_BYTES = 24;

	vector<uint8_t> serialize() const ;
	inline size_t numBytes() const {return 24 + payload.size();};
	void set_MAC(uint8_t *, uint8_t *);
};



class EthernetControl 
{
public:
	friend class APSEthernetPacket;
	enum ErrorCodes {
    	SUCCESS = 0,
    	NOT_IMPLEMENTED = -1,
    	INVALID_NETWORK_DEVICE = -2,
    	INVALID_PCAP_FILTER = -3,
    	INVALID_APS_ID = -4,
    	TIMEOUT = -5,
    	INVALID_SPI_TARGET
	};

	typedef void (*DebugPacketCallback)(const void * data, unsigned int length);  


	static const uint16_t APS_PROTO = 0xBB4E;

	static const uint16_t MAX_PAYLOAD_LEN_BYTES = 1468;
	static const uint16_t MAX_PAYLOAD_LEN_WORDS = MAX_PAYLOAD_LEN_BYTES / sizeof(uint32_t);
	static const uint16_t MIN_PAYLOAD_LEN_BYTES = 36;

{'fraction_non_alphanumeric': 0.09197547320714476, 'fraction_numerical': 0.022394028259130897, 'mean_word_length': 4.702127659574468, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6258565', 'n_tokens_mistral': 1468, 'n_tokens_neox': 1360, 'n_words': 362}