mac: set duration to 0 and allocate statically

This commit is contained in:
Bastian Bloessl
2015-04-17 10:22:32 +02:00
parent 0687df370c
commit 00e57632b9
+14 -13
View File
@@ -106,30 +106,31 @@ void app_in (pmt::pmt_t msg) {
return; return;
} }
if(msg_len > 1500) {
throw std::invalid_argument("Frame too large (> 1500)");
}
// make MAC frame // make MAC frame
int psdu_length; int psdu_length;
char *psdu; generate_mac_data_frame(msdu, msg_len, &psdu_length);
generate_mac_data_frame(msdu, msg_len, &psdu, &psdu_length);
// dict // dict
pmt::pmt_t dict = pmt::make_dict(); pmt::pmt_t dict = pmt::make_dict();
dict = pmt::dict_add(dict, pmt::mp("crc_included"), pmt::PMT_T); dict = pmt::dict_add(dict, pmt::mp("crc_included"), pmt::PMT_T);
// blob // blob
pmt::pmt_t mac = pmt::make_blob(psdu, psdu_length); pmt::pmt_t mac = pmt::make_blob(d_psdu, psdu_length);
// pdu // pdu
message_port_pub(pmt::mp("phy out"), pmt::cons(dict, mac)); message_port_pub(pmt::mp("phy out"), pmt::cons(dict, mac));
free(psdu);
} }
void generate_mac_data_frame(const char *msdu, int msdu_size, char **psdu, int *psdu_size) { void generate_mac_data_frame(const char *msdu, int msdu_size, int *psdu_size) {
// mac header // mac header
mac_header header; mac_header header;
header.frame_control = 0x0008; header.frame_control = 0x0008;
header.duration = 0x002e; header.duration = 0x0000;
for(int i = 0; i < 6; i++) { for(int i = 0; i < 6; i++) {
header.addr1[i] = d_dst_mac[i]; header.addr1[i] = d_dst_mac[i];
@@ -148,18 +149,17 @@ void generate_mac_data_frame(const char *msdu, int msdu_size, char **psdu, int *
//header size is 24, plus 4 for FCS means 28 bytes //header size is 24, plus 4 for FCS means 28 bytes
*psdu_size = 28 + msdu_size; *psdu_size = 28 + msdu_size;
*psdu = (char *) calloc(*psdu_size, sizeof(char));
//copy mac header into psdu //copy mac header into psdu
std::memcpy(*psdu, &header, 24); std::memcpy(d_psdu, &header, 24);
//copy msdu into psdu //copy msdu into psdu
memcpy(*psdu + 24, msdu, msdu_size); memcpy(d_psdu + 24, msdu, msdu_size);
//compute and store fcs //compute and store fcs
boost::crc_32_type result; boost::crc_32_type result;
result.process_bytes(*psdu, msdu_size + 24); result.process_bytes(d_psdu, msdu_size + 24);
unsigned int fcs = result.checksum(); uint32_t fcs = result.checksum();
memcpy(*psdu + msdu_size + 24, &fcs, sizeof(unsigned int)); memcpy(d_psdu + msdu_size + 24, &fcs, sizeof(uint32_t));
} }
bool check_mac(std::vector<uint8_t> mac) { bool check_mac(std::vector<uint8_t> mac) {
@@ -172,6 +172,7 @@ private:
uint8_t d_src_mac[6]; uint8_t d_src_mac[6];
uint8_t d_dst_mac[6]; uint8_t d_dst_mac[6];
uint8_t d_bss_mac[6]; uint8_t d_bss_mac[6];
uint8_t d_psdu[1528];
}; };
ofdm_mac::sptr ofdm_mac::sptr