FreeNOS
Ethernet.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Niek Linnenbank
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef __LIB_LIBNET_ETHERNET_H
19 #define __LIB_LIBNET_ETHERNET_H
20 
21 #include <Types.h>
22 #include <Macros.h>
23 #include <Log.h>
24 #include <String.h>
25 #include "NetworkProtocol.h"
26 
27 class ARP;
28 class IPV4;
29 class ICMP;
30 
42 class Ethernet : public NetworkProtocol
43 {
44  public:
45 
47  static const Size CRCSize = 4;
48 
52  typedef struct Address
53  {
54  u8 addr[6];
55  }
57 
64  typedef struct Header
65  {
69  }
70  PACKED Header;
71 
76  {
77  IPV4 = 0x0800u,
78  IPV6 = 0x86ddu,
79  ARP = 0x0806u
80  };
81 
82  public:
83 
90  Ethernet(NetworkServer &server,
91  NetworkDevice &device);
92 
96  virtual ~Ethernet();
97 
103  virtual FileSystem::Result initialize();
104 
112  virtual FileSystem::Result getAddress(Address *address);
113 
121  virtual FileSystem::Result setAddress(const Address *address);
122 
135  const void *address,
136  const Size addressSize,
137  const Identifier protocol,
138  const Size payloadSize);
139 
146  static const String toString(const Address address);
147 
153  void setARP(::ARP *arp);
154 
160  void setIP(::IPV4 *ip);
161 
171  const Size offset);
172 
173  private:
174 
177 
180 
183 };
184 
185 Log & operator << (Log &log, const Ethernet::Address & addr);
186 
192 #endif /* __LIB_LIBNET_ETHERNET_H */
NetworkProtocol
Network protocol abstraction class.
Definition: NetworkProtocol.h:39
Ethernet::process
virtual FileSystem::Result process(const NetworkQueue::Packet *pkt, const Size offset)
Process incoming network packet.
Definition: Ethernet.cpp:126
Ethernet::getAddress
virtual FileSystem::Result getAddress(Address *address)
Retrieve Ethernet address.
Definition: Ethernet.cpp:49
Macros.h
Ethernet::m_arp
::ARP * m_arp
ARP protocol.
Definition: Ethernet.h:179
Types.h
Ethernet::CRCSize
static const Size CRCSize
Size of the CRC checksum (which is set after the payload)
Definition: Ethernet.h:47
operator<<
Log & operator<<(Log &log, const Ethernet::Address &addr)
Definition: Ethernet.cpp:154
String
Abstraction of strings.
Definition: String.h:41
NetworkDevice
Network Device abstract class.
Definition: NetworkDevice.h:41
Ethernet::setARP
void setARP(::ARP *arp)
Set ARP instance.
Definition: Ethernet.cpp:66
Ethernet::initialize
virtual FileSystem::Result initialize()
Perform initialization.
Definition: Ethernet.cpp:39
Ethernet::setAddress
virtual FileSystem::Result setAddress(const Address *address)
Set Ethernet address.
Definition: Ethernet.cpp:55
Address
unsigned long Address
A memory address.
Definition: Types.h:131
Ethernet
Ethernet networking protocol.
Definition: Ethernet.h:42
Log.h
NetworkProtocol.h
Ethernet::m_address
Address m_address
Current ethernet address.
Definition: Ethernet.h:176
Log
Logging class.
Definition: Log.h:96
PACKED
#define PACKED
Ensures strict minimum memory requirements.
Definition: Macros.h:159
Ethernet::m_ipv4
::IPV4 * m_ipv4
IPV4 protocol.
Definition: Ethernet.h:182
Ethernet::Address
Ethernet network address.
Definition: Ethernet.h:52
NetworkServer
Networking server.
Definition: NetworkServer.h:40
u16
unsigned short u16
Unsigned 16-bit number.
Definition: Types.h:56
Ethernet::Header::type
u16 type
payload type
Definition: Ethernet.h:68
Ethernet::Address::addr
u8 addr[6]
Definition: Ethernet.h:54
Size
unsigned int Size
Any sane size indicator cannot go negative.
Definition: Types.h:128
Ethernet::IPV6
@ IPV6
Internet protocol v6.
Definition: Ethernet.h:78
Ethernet::Header
Ethernet network packet header.
Definition: Ethernet.h:64
IPV4
Internet Protocol Version 4.
Definition: IPV4.h:40
Ethernet::Header::source
Address source
packet source address
Definition: Ethernet.h:67
Ethernet::toString
static const String toString(const Address address)
Convert address to string.
Definition: Ethernet.cpp:76
FileSystem::Result
Result
Result code for filesystem Actions.
Definition: FileSystem.h:52
u8
unsigned char u8
Unsigned 8-bit number.
Definition: Types.h:59
Ethernet::PayloadType
PayloadType
List of ethernet payload types.
Definition: Ethernet.h:75
String.h
Ethernet::Header
struct Ethernet::Header Header
Ethernet network packet header.
Ethernet::~Ethernet
virtual ~Ethernet()
Destructor.
Definition: Ethernet.cpp:35
Ethernet::setIP
void setIP(::IPV4 *ip)
Set IPV4 instance.
Definition: Ethernet.cpp:71
Ethernet::Address
struct Ethernet::Address Address
Ethernet network address.
NetworkQueue::Packet
Represents a network packet.
Definition: NetworkQueue.h:50
ARP
Address Resolution Protocol.
Definition: ARP.h:42
NetworkProtocol::Ethernet
@ Ethernet
Definition: NetworkProtocol.h:48
NetworkProtocol::Identifier
Identifier
List of known network protocol identifiers.
Definition: NetworkProtocol.h:46
Ethernet::Header::destination
Address destination
packet destination address
Definition: Ethernet.h:66
ICMP
Internet Control Message Protocol (ICMP)
Definition: ICMP.h:42
Ethernet::getTransmitPacket
virtual FileSystem::Result getTransmitPacket(NetworkQueue::Packet **pkt, const void *address, const Size addressSize, const Identifier protocol, const Size payloadSize)
Get a new packet for transmission.
Definition: Ethernet.cpp:91