Dependencies:
NetServices
Dependents:
HvZ
net/ethernet.h@0:7e2eb93442e7, 2010-12-12 (annotated)
- Committer:
- etherealflaim
- Date:
- Sun Dec 12 19:34:41 2010 +0000
- Revision:
- 0:7e2eb93442e7
Who changed what in which revision?
User | Revision | Line number | New contents of line |
etherealflaim |
0:7e2eb93442e7
|
1
|
#ifndef ETHERNET_H
|
etherealflaim |
0:7e2eb93442e7
|
2
|
#define ETHERNET_H
|
etherealflaim |
0:7e2eb93442e7
|
3
|
|
etherealflaim |
0:7e2eb93442e7
|
4
|
#include "net.h"
|
etherealflaim |
0:7e2eb93442e7
|
5
|
|
etherealflaim |
0:7e2eb93442e7
|
6
|
/**
|
etherealflaim |
0:7e2eb93442e7
|
7
|
\file ethernet.h
|
etherealflaim |
0:7e2eb93442e7
|
8
|
\brief Ethernet frame header
|
etherealflaim |
0:7e2eb93442e7
|
9
|
|
etherealflaim |
0:7e2eb93442e7
|
10
|
This file contains the memory map and associated functions for Ethernet frame header
|
etherealflaim |
0:7e2eb93442e7
|
11
|
creation and deconstruction.
|
etherealflaim |
0:7e2eb93442e7
|
12
|
*/
|
etherealflaim |
0:7e2eb93442e7
|
13
|
|
etherealflaim |
0:7e2eb93442e7
|
14
|
/// Ethernet MAC address memory map
|
etherealflaim |
0:7e2eb93442e7
|
15
|
typedef struct {
|
etherealflaim |
0:7e2eb93442e7
|
16
|
unsigned char octet[6]; ///< Individual octsts of the MAC address
|
etherealflaim |
0:7e2eb93442e7
|
17
|
} Ethernet_MAC;
|
etherealflaim |
0:7e2eb93442e7
|
18
|
|
etherealflaim |
0:7e2eb93442e7
|
19
|
/// Ethernet II Frame Header Memory map
|
etherealflaim |
0:7e2eb93442e7
|
20
|
typedef struct {
|
etherealflaim |
0:7e2eb93442e7
|
21
|
/// Destination MAC address (6 octets)
|
etherealflaim |
0:7e2eb93442e7
|
22
|
Ethernet_MAC destination;
|
etherealflaim |
0:7e2eb93442e7
|
23
|
/// Source MAC address (6 octets)
|
etherealflaim |
0:7e2eb93442e7
|
24
|
Ethernet_MAC source;
|
etherealflaim |
0:7e2eb93442e7
|
25
|
// (optional) VLAN Tag (unsupported)
|
etherealflaim |
0:7e2eb93442e7
|
26
|
/// Ethernet type or length (only <0x600 or 0x0800 IPv4 supported)
|
etherealflaim |
0:7e2eb93442e7
|
27
|
u16 ethertype;
|
etherealflaim |
0:7e2eb93442e7
|
28
|
/// Payload (used for memory mapping; has zero size)
|
etherealflaim |
0:7e2eb93442e7
|
29
|
unsigned char payload[];
|
etherealflaim |
0:7e2eb93442e7
|
30
|
} Ethernet_FrameHeader;
|
etherealflaim |
0:7e2eb93442e7
|
31
|
|
etherealflaim |
0:7e2eb93442e7
|
32
|
/// Convert from wire to host or host to wire endian-ness
|
etherealflaim |
0:7e2eb93442e7
|
33
|
inline void fix_endian_ethernet(Ethernet_FrameHeader *header)
|
etherealflaim |
0:7e2eb93442e7
|
34
|
{
|
etherealflaim |
0:7e2eb93442e7
|
35
|
fix_endian_u16(&header->ethertype);
|
etherealflaim |
0:7e2eb93442e7
|
36
|
}
|
etherealflaim |
0:7e2eb93442e7
|
37
|
|
etherealflaim |
0:7e2eb93442e7
|
38
|
/// Print out an ethernet packet
|
etherealflaim |
0:7e2eb93442e7
|
39
|
/*inline void print_ethernet(Ethernet_FrameHeader *frame)
|
etherealflaim |
0:7e2eb93442e7
|
40
|
{
|
etherealflaim |
0:7e2eb93442e7
|
41
|
main_log.printf("Ethernet frame:");
|
etherealflaim |
0:7e2eb93442e7
|
42
|
u8 *src = frame->source.octet;
|
etherealflaim |
0:7e2eb93442e7
|
43
|
u8 *dst = frame->destination.octet;
|
etherealflaim |
0:7e2eb93442e7
|
44
|
main_log.printf(" Source: MAC - %02X:%02X:%02X:%02X:%02X:%02X", src[6], src[7], src[8], src[9], src[10], src[11]);
|
etherealflaim |
0:7e2eb93442e7
|
45
|
main_log.printf(" Dest: MAC - %02X:%02X:%02X:%02X:%02X:%02X", dst[0], dst[1], dst[2], dst[3], dst[4], dst[5]);
|
etherealflaim |
0:7e2eb93442e7
|
46
|
main_log.printf(" Ethertype: 0x%04X", frame->ethertype);
|
etherealflaim |
0:7e2eb93442e7
|
47
|
}
|
etherealflaim |
0:7e2eb93442e7
|
48
|
*/
|
etherealflaim |
0:7e2eb93442e7
|
49
|
#endif |