2020-07-28 08:36:21 +01:00
|
|
|
class CEthernetFrame
|
|
|
|
{
|
2020-03-17 14:40:18 +00:00
|
|
|
U8 source_address[6];
|
|
|
|
U8 padding[2];
|
|
|
|
U8 destination_address[6];
|
|
|
|
U16 ethertype;
|
|
|
|
|
|
|
|
U8 *data;
|
|
|
|
|
|
|
|
I64 length;
|
|
|
|
};
|
|
|
|
|
|
|
|
class CEthernetGlobals
|
|
|
|
{
|
|
|
|
U8 ethernet_null[6];
|
|
|
|
U8 ethernet_broadcast[6];
|
|
|
|
|
|
|
|
} ethernet_globals;
|
|
|
|
|
|
|
|
U0 EthernetInitGlobals()
|
|
|
|
{
|
|
|
|
I64 i;
|
2020-07-28 08:36:21 +01:00
|
|
|
for (i = 0; i < 6; i++)
|
2020-03-17 14:40:18 +00:00
|
|
|
{
|
2020-07-28 08:36:21 +01:00
|
|
|
ethernet_globals.ethernet_null[i] = 0;
|
|
|
|
ethernet_globals.ethernet_broadcast[i] = 0xFF;
|
2020-03-17 14:40:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-28 08:36:21 +01:00
|
|
|
//TODO: check length , figure out the length+4
|
2020-03-17 14:40:18 +00:00
|
|
|
U0 EthernetFrameParse(CEthernetFrame *frame_out, U8 *frame, U16 length)
|
|
|
|
{
|
|
|
|
//Shrine has a FIXME for check length! We need to figure out what
|
|
|
|
//lengths are appropriate ...... Shrine also says MemCopy has a
|
|
|
|
//high overhead. I'm almost tempted to say that means that a lot
|
|
|
|
//of the current system should be done with less extra allocation
|
|
|
|
//altogether, more passing.
|
|
|
|
|
2020-08-07 07:39:07 +01:00
|
|
|
ZenithLog("ETHERNET FRAME PARSE: Parsing frame, copying out to frame_out param.\n");
|
|
|
|
|
2020-07-28 08:36:21 +01:00
|
|
|
MemCopy(frame_out->destination_address, frame, MAC_ADDRESS_LENGTH);
|
2020-03-17 14:40:18 +00:00
|
|
|
|
2020-07-28 08:36:21 +01:00
|
|
|
MemCopy(frame_out->source_address, frame + MAC_ADDRESS_LENGTH, MAC_ADDRESS_LENGTH);
|
2020-03-17 14:40:18 +00:00
|
|
|
|
2020-07-28 08:36:21 +01:00
|
|
|
frame_out->ethertype = frame[ETHERNET_ETHERTYPE_OFFSET + 1] | (frame[ETHERNET_ETHERTYPE_OFFSET] << 8);
|
2020-03-17 14:40:18 +00:00
|
|
|
|
2020-07-28 08:36:21 +01:00
|
|
|
frame_out->data = frame + ETHERNET_DATA_OFFSET;
|
2020-03-17 14:40:18 +00:00
|
|
|
|
2020-08-07 07:39:07 +01:00
|
|
|
frame_out->length = length - ETHERNET_MAC_HEADER_LENGTH - 4; // He has a comment literally just saying "??". + or - 4?
|
2020-03-17 14:40:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EthernetInitGlobals;
|