Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #include "McDisconnectFrame.h"
00009
00010 McDisconnectFrame::McDisconnectFrame(unsigned char* next_hop, std::string mc_g)
00011 {
00012 memcpy(header_.mac_destination, next_hop, 6);
00013 this->header_.frame_type = FRAME_TYPE_MC_DISCONNECT;
00014 this->header_.id = McRouteActivationFrame::stat_id_count++;
00015 mc_group_ = mc_g;
00016 disconnect_downlink = false;
00017 disconnect_uplink = false;
00018 }
00019
00020 McDisconnectFrame::McDisconnectFrame(unsigned char* buffer)
00021 {
00022 unsigned char* buffer_start = buffer;
00023
00024 eh_header* eh = (struct eh_header *) buffer;
00025 buffer += sizeof (eh_header);
00026 mc_disc_header* rfh = (struct mc_disc_header *) buffer;
00027 buffer += sizeof (mc_disc_header);
00028
00029
00030
00031
00032 mc_group_ = "";
00033 if (rfh->mc_group_name_len > 0)
00034 mc_group_.append((const char*) buffer, rfh->mc_group_name_len);
00035 buffer += rfh->mc_group_name_len;
00036
00037
00038
00039 disconnect_downlink = (rfh->flag_field / 128) % 2 == 1;
00040 disconnect_uplink = (rfh->flag_field / 64) % 2 == 1;
00041
00042
00043
00044
00045 uint32_t crc = 0;
00046 memcpy((unsigned char*) &crc, (unsigned char*) buffer, 4);
00047
00048 std::string crc_data_string = "";
00049 uint32_t dynamic_field_len = rfh->mc_group_name_len;
00050 crc_data_string.append((const char*) buffer_start,
00051 this->HEADER_FIXED_LEN + dynamic_field_len);
00052 correct_crc_ = (crc == (uint32_t) GetCrc32(crc_data_string));
00053
00054
00055 buffer_str_len_ = this->HEADER_FIXED_LEN + dynamic_field_len + sizeof (crc);
00056
00057
00058
00059
00060 memcpy(&this->eh_h_, &(*eh), sizeof (eh_header));
00061 memcpy(&this->header_, &(*rfh), sizeof (mc_disc_header));
00062
00063
00064 }
00065
00066 McDisconnectFrame::~McDisconnectFrame()
00067 {
00068 }
00069
00070 std::string McDisconnectFrame::getFrameAsNetworkString(unsigned char* source)
00071 {
00072 memcpy(this->eh_h_.eh_source, source, ETH_ALEN);
00073 memcpy(this->eh_h_.eh_dest, bcast_mac, ETH_ALEN);
00074
00075
00076
00077 this->header_.flag_field = 0;
00078 if (disconnect_downlink)
00079 this->header_.flag_field += 128;
00080 if (disconnect_uplink)
00081 this->header_.flag_field += 64;
00082
00083
00084 if(disconnect_downlink == disconnect_uplink)
00085 ROS_ERROR("In McDisconnectFrame: disconnect_downlink == disconnect_uplink");
00086
00087
00088
00089
00090 this->header_.mc_group_name_len = mc_group_.length();
00091
00092 unsigned char a_char[ETHER_MAX_LEN];
00093 unsigned char* buffer = a_char;
00094 unsigned char* buffer_start = a_char;
00095
00096
00097 memcpy(buffer, &this->eh_h_, sizeof (eh_header));
00098 buffer += sizeof (eh_header);
00099
00100
00101 memcpy(buffer, &this->header_, sizeof (mc_disc_header));
00102 buffer += sizeof (mc_disc_header);
00103
00104
00105
00106 memcpy(buffer, this->mc_group_.data(),
00107 this->mc_group_.length());
00108 buffer += this->mc_group_.length();
00109
00110
00111
00112
00113 int dynamic_field_len = this->mc_group_.length();
00114 std::string crc_string = std::string((const char*) buffer_start, this->HEADER_FIXED_LEN + dynamic_field_len);
00115 uint32_t crc = GetCrc32(crc_string);
00116 memcpy(buffer, &crc, sizeof (uint32_t));
00117 buffer += sizeof (uint32_t);
00118
00119
00120
00121 return std::string((const char*) buffer_start, this->HEADER_FIXED_LEN + dynamic_field_len + sizeof (crc));
00122
00123 }