Ethernet driver development based on DWC_ether_qos-MAC frame format introduction
I.
Introduction
When developing Ethernet drivers, applications, writing and debugging, packet capture analysis is often required. At this time, it is necessary to understand
the format of
MAC
frames for analysis. We refer to the annotation document to organize it.
3. Media access control frame structure
of
"
802.3-2000_part1.pdf
"
specifies
two frame formats for
data communication systems
using
CSMA/CD MAC
:
Basic
MAC
frame format
An extension of
the
basic
MAC
frame format
,
the Tagged MAC
frame
, is a frame that carries
the QTag
prefix.
2.
Basic
MAC
frame
format
The basic
MAC
frame format is as follows, consisting of
9
parts
in
OCTETS
means
8
bits
,
1.
The low bit
of the byte
is sent first
, except for
the CRC31
checksum field, which is sent high bit first.
The
bit
stream
is
x
31
, x
30
,…, x
1
, x
0
,
i.e.
x0
is the last bit sent of the last byte sent
.
2.
Multi-byte data is parsed according to
the big-endian format
,
with the high byte first being sent
.
Each part is described in detail as follows
:
Serial number
|
Fields
|
Size
(
bytes
)
|
Function
|
illustrate
|
1
|
PREAMBLE
|
7
|
Leading field
|
Used for
PLS (PHYSICAL LAYER SIGNALING)
to achieve synchronization with the received frame
(
even if there is a conflict when sending
the preamble and
SFD
, the entire preamble and
SFD will be sent)
10101010 10101010 10101010 10101010 10101010 10101010
is
the sequence of 0x55
|
2
|
SFD
|
1
|
Start of frame delimiter
|
10101011
is
0xD5
|
3
|
DESTINATION ADDRESS
(DA)
|
6
|
Destination Address Field
|
The address of
the destination station
. This can be
a unicast
or multicast (including broadcast) address.
All
1s
are the broadcast address.
See
the MAC
address section below for details.
|
4
|
SOURCE ADDRESS
(SA)
|
6
|
Source Address Field
|
The source address field is
the address of the station sending the frame
.
The CSMA/CD MAC
sublayer does not interpret the source address field.
|
5
|
LENGTH/TYPE
|
2
|
Length
/
Type Field
|
If it is less than or equal to
maxValidFrame
=
maxUntaggedFrameSize
(1518)-18=1500
, it means
the length of
MAC CLIENT DATA
area
If it is greater than or equal to
0x
0600
, it indicates the frame type.
|
6
|
MAC CLIENT DATA
|
/
|
data
|
MAC+DATA
range:
46~1500
bytes
|
7
|
PAD
|
/
|
filling
|
Padding is performed so that
DESTINATION ADDRESS
~FCS
meets the minimum frame length
of
64
bytes.
|
8
|
FRAME CHECK SEQUENCE
(FCS)
|
4
|
|
CRC32
checksum
,
check
data between
DA
and
PAD
area. Generate polynomial.
G(x) = x
32
+ x
26
+ x
23
+ x
22
+ x
16
+ x
12
+ x
11
+ x
10
+ x
8
+ x
7
+ x
5
+ x
4
+ x
2
+ x + 1
Note that
FCS is x31 sent first and x0 sent last.
|
9
|
EXTENSION
|
/
|
Extended domain
|
0~(
slotTime
–
minFrameSize) bits
long
1000 Mb/s
half-duplex only
|
2.1 MAC
address
The definition of a
48
-bit
MAC
address is as follows
|
Bit Field
|
Function
|
illustrate
|
1
|
I/G
|
Address Type
|
LSB
is the first
bit
sent.
Distinguish
Is it unicast or multicast
Address
:
0:
I
individual
is
a unicast address
,
1: G
group
is the multicast address.
Note that this bit
is only for the destination address
, and is always 0 for the source address.
|
2
|
U/L
|
|
Distinguish between local and global addresses
:
0:
U
universal
is
the global address
,
1: L
locally
is the local address.
The broadcast address bit is
1.
|
3
|
46-BIT ADDRESSS
|
|
|
Address Type
:
|
|
|
|
1
|
Individual Address
Unicast Address
|
|
An address corresponds to a specific site in the network.
|
2
|
Group Address
Multicast Address
|
Multicast
-Group Address
|
An address associated by a higher-level convention with a group of logically related stations.
|
Broadcast
Address
|
A distinguishable predefined multicast address that always represents
the set of all stations on a given LAN.
All
1s are the broadcast address
.
|
2.2
Invalid Frame
Meet one or more of the following conditions
1.
The frame length
is inconsistent with the length value specified in the
Length
/
Type field. If the Length
/
Type field
indicates
a Type value, the frame length is assumed to be consistent with that field and should not be considered an invalid frame on this basis.
2.
The length is not an integer
multiple
of eight bits
.
3.
CRC32
checksum error.
4.
The contents of an
invalid
MAC
frame shall not be passed to
the LLC
or
MAC
control sublayer. The presence of an invalid
MAC
frame may be communicated to network management.
3.
Tagged
MAC
frame format
The tagged
MAC frame is an extension of the normal MAC frame. A 4-byte Qtag is added after the SA. See the standard
IEEE P802.1Q
Serial number
|
Fields
|
Size
(
bytes
)
|
Function
|
illustrate
|
1
|
PREAMBLE
|
7
|
Leading field
|
Same as basic
MAC
frame
|
2
|
SFD
|
1
|
Start of frame delimiter
|
Same as basic
MAC
frame
|
3
|
DESTINATION ADDRESS
|
6
|
Destination Address Field
|
Same as basic
MAC
frame
|
4
|
SOURCE ADDRESS
|
6
|
Source Address Field
|
Same as basic
MAC
frame
|
5
|
LENGTH/TYPE = 802.1QTagType
|
2
|
|
QTag
length
/
type
Fixed to
0x8100
, indicating
802.1Q
Tag Protocol Type.
|
6
|
TAG CONTROL INFORMATION
|
2
|
|
QTag
control information
a) A 3-bit User Priority field,
b) A Canonical Format Indicator (CFI), and
c) A 12-bit VLAN Identifier.
|
7
|
LENGTH/TYPE
|
2
|
Length
/
Type Field
|
The original length
/
type of
the MAC
frame
before
QTag
is inserted
.
Same as basic
MAC
frame
|
8
|
MAC CLIENT DATA
|
/
|
data
|
Same as basic
MAC
frame
|
9
|
PAD
|
/
|
filling
|
Same as basic
MAC
frame
For padding
,
the minimum
frame length of
64
bytes may
or may not include
a
4-
byte
TAG
. If
the TAG
is not included
, the actual frame length is
64
bytes.
|
10
|
FRAME CHECK SEQUENCE
|
4
|
|
Same as basic
MAC
frame
|
11
|
EXTENSION
|
/
|
Extended domain
|
Same as basic
MAC
frame
|
4.
Frame parsing in
wireshark
For example, the following is an
ARP
request packet
. Wireshark
can parse its different fields
.
For example, click
the data
0806
on the right side
of Type
on the lower left side
to highlight it.
Wireshark
does not display the preamble, frame start symbol and
FCS
in the captured packet
, because the former two are fixed.
If
the FCS
is wrong, it cannot be received, and
the MAC
layer will discard it as an invalid frame.
5.
Conclusion
When debugging Ethernet,
the format of
MAC
frames must be understood.
Wireshark
can be used for easy parsing, but sometimes we directly print the raw data in the driver code, so we need to parse it manually.