- generic Queue implemented - PacketRegistry allocation bug fixed - TCP implementation initials - ALIGN to type macros added
59 lines
1.8 KiB
C
59 lines
1.8 KiB
C
//
|
|
// Created by epagris on 2022.12.25..
|
|
//
|
|
|
|
#include "igmp_packet.h"
|
|
#include "../../utils.h"
|
|
|
|
//static uint16_t igmp_chksum(const uint8_t * hdr) {
|
|
// // sum fields
|
|
// uint32_t sum = 0;
|
|
// const uint16_t *pField = (const uint16_t *) hdr;
|
|
// for (uint8_t i = 0; i < (ETH_IGMP_HEADER_SIZE / sizeof(uint16_t)); i++) {
|
|
// uint16_t field = pField[i];
|
|
// if (i != 1) { // 6. 16-bit long field is the checksum itself, do not count in
|
|
// sum += field;
|
|
// }
|
|
// }
|
|
//
|
|
// while (sum >> 16) {
|
|
// sum = (sum & 0xFFFF) + (sum >> 16);
|
|
// }
|
|
//
|
|
// // invert result
|
|
// uint16_t sum16 = sum ^ 0xFFFF;
|
|
// return sum16;
|
|
//}
|
|
|
|
void insert_igmp_header(uint8_t *hdr, const PcktHeaderElement *headers) {
|
|
IgmpProps *igmpProps = HEADER_FETCH_PROPS(IgmpProps, headers);
|
|
uint8_t * hdrBeg = hdr;
|
|
|
|
FILL_ADVANCE(hdr, &igmpProps->type, 1);
|
|
FILL_ADVANCE(hdr, &igmpProps->maxRespTime, 1);
|
|
uint8_t * ChkSumPtr = hdr;
|
|
igmpProps->checksum = 0;
|
|
FILL_WORD_ADVANCE(hdr, igmpProps->checksum);
|
|
FILL_DWORD_ADVANCE(hdr, igmpProps->groupAddr);
|
|
|
|
igmpProps->checksum = chksum(hdrBeg, ETH_IGMP_HEADER_SIZE, false);
|
|
memcpy(ChkSumPtr, &igmpProps->checksum, 2);
|
|
}
|
|
|
|
int parse_igmp(const uint8_t * hdr, uint32_t size, PcktHeaderElement * pcktHdrLe, struct EthInterface_ * intf) {
|
|
// parse header
|
|
IgmpProps *igmpProps = HEADER_FETCH_PROPS(IgmpProps, pcktHdrLe);
|
|
FETCH_BYTE_ADVANCE(&igmpProps->type, hdr);
|
|
FETCH_BYTE_ADVANCE(&igmpProps->maxRespTime, hdr);
|
|
FETCH_WORD_ADVANCE(&igmpProps->checksum, hdr);
|
|
FETCH_WORD_ADVANCE(&igmpProps->groupAddr, hdr);
|
|
|
|
// fill-in common fields
|
|
uint16_t calcChkSum = chksum(hdr, ETH_IGMP_HEADER_SIZE, false);
|
|
igmpProps->validityOK = (calcChkSum == 0);
|
|
igmpProps->containedPacketClass = 0;
|
|
igmpProps->headerSize = ETH_IGMP_HEADER_SIZE;
|
|
|
|
return 0;
|
|
}
|