FreeNOS
Data Structures | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Attributes
Ethernet Class Reference

Ethernet networking protocol. More...

#include <Ethernet.h>

Inheritance diagram for Ethernet:
NetworkProtocol Directory File

Data Structures

struct  Address
 Ethernet network address. More...
 
struct  Header
 Ethernet network packet header. More...
 

Public Types

enum  PayloadType { IPV4 = 0x0800u, IPV6 = 0x86ddu, ARP = 0x0806u }
 List of ethernet payload types. More...
 
typedef struct Ethernet::Address Address
 Ethernet network address. More...
 
typedef struct Ethernet::Header Header
 Ethernet network packet header. More...
 

Public Member Functions

 Ethernet (NetworkServer &server, NetworkDevice &device)
 Constructor. More...
 
virtual ~Ethernet ()
 Destructor. More...
 
virtual FileSystem::Result initialize ()
 Perform initialization. More...
 
virtual FileSystem::Result getAddress (Address *address)
 Retrieve Ethernet address. More...
 
virtual FileSystem::Result setAddress (const Address *address)
 Set Ethernet address. More...
 
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. More...
 
void setARP (::ARP *arp)
 Set ARP instance. More...
 
void setIP (::IPV4 *ip)
 Set IPV4 instance. More...
 
virtual FileSystem::Result process (const NetworkQueue::Packet *pkt, const Size offset)
 Process incoming network packet. More...
 
- Public Member Functions inherited from NetworkProtocol
 NetworkProtocol (NetworkServer &server, NetworkDevice &device, NetworkProtocol &parent)
 Constructor. More...
 
virtual ~NetworkProtocol ()
 Destructor. More...
 
virtual const Size getMaximumPacketSize () const
 Get maximum packet size. More...
 
- Public Member Functions inherited from Directory
 Directory (const u32 inode)
 Constructor. More...
 
virtual ~Directory ()
 Destructor. More...
 
virtual FileSystem::Result read (IOBuffer &buffer, Size &size, const Size offset)
 Read directory entries. More...
 
virtual Filelookup (const char *name)
 Retrieve a File from storage. More...
 
void insert (FileSystem::FileType type, const char *name)
 Insert a new directory entry. More...
 
void remove (const char *name)
 Remove a directory entry. More...
 
void clear ()
 Clears the internal list of entries. More...
 
- Public Member Functions inherited from File
 File (const u32 inode, const FileSystem::FileType type=FileSystem::RegularFile, const UserID uid=ZERO, const GroupID gid=ZERO)
 Constructor function. More...
 
virtual ~File ()
 Destructor function. More...
 
u32 getInode () const
 Get inode number. More...
 
FileSystem::FileType getType () const
 Retrieve our filetype. More...
 
virtual FileSystem::Result write (IOBuffer &buffer, Size &size, const Size offset)
 Write bytes to the file. More...
 
virtual FileSystem::Result status (FileSystem::FileStat &st)
 Retrieve file statistics. More...
 
virtual bool canRead () const
 Check if the File has data ready for reading. More...
 
virtual bool canWrite () const
 Check if the File can be written to. More...
 

Static Public Member Functions

static const String toString (const Address address)
 Convert address to string. More...
 

Static Public Attributes

static const Size CRCSize = 4
 Size of the CRC checksum (which is set after the payload) More...
 

Private Attributes

Address m_address
 Current ethernet address. More...
 
::ARPm_arp
 ARP protocol. More...
 
::IPV4m_ipv4
 IPV4 protocol. More...
 

Additional Inherited Members

- Protected Types inherited from NetworkProtocol
enum  Identifier {
  Ethernet = 1, IPV4, ARP, ICMP,
  UDP, TCP
}
 List of known network protocol identifiers. More...
 
- Protected Attributes inherited from NetworkProtocol
NetworkServerm_server
 Network server instance. More...
 
NetworkDevicem_device
 Network device instance. More...
 
NetworkProtocolm_parent
 Parent upper-layer protocol instance. More...
 
- Protected Attributes inherited from File
const u32 m_inode
 Inode number. More...
 
const FileSystem::FileType m_type
 Type of this file. More...
 
UserID m_uid
 Owner of the file. More...
 
GroupID m_gid
 Group of the file. More...
 
FileSystem::FileModes m_access
 Access permissions. More...
 
Size m_size
 Size of the file, in bytes. More...
 

Detailed Description

Ethernet networking protocol.

Definition at line 42 of file Ethernet.h.

Member Typedef Documentation

◆ Address

Ethernet network address.

◆ Header

Ethernet network packet header.

This header is prepended to every ethernet packet send on the actual physical link.

Member Enumeration Documentation

◆ PayloadType

List of ethernet payload types.

Enumerator
IPV4 

Internet protocol v4.

IPV6 

Internet protocol v6.

ARP 

Address resolution protocol.

Definition at line 75 of file Ethernet.h.

Constructor & Destructor Documentation

◆ Ethernet()

Ethernet::Ethernet ( NetworkServer server,
NetworkDevice device 
)

Constructor.

Parameters
serverReference to the NetworkServer instance
deviceReference to the NetworkDevice instance

Definition at line 26 of file Ethernet.cpp.

References m_address, m_arp, m_ipv4, MemoryBlock::set(), and ZERO.

◆ ~Ethernet()

Ethernet::~Ethernet ( )
virtual

Destructor.

Definition at line 35 of file Ethernet.cpp.

Member Function Documentation

◆ getAddress()

FileSystem::Result Ethernet::getAddress ( Ethernet::Address address)
virtual

Retrieve Ethernet address.

Parameters
addressOutput buffer to store the address
Returns
Result code

Definition at line 49 of file Ethernet.cpp.

References MemoryBlock::copy(), m_address, and FileSystem::Success.

Referenced by EthernetAddress::read().

◆ getTransmitPacket()

FileSystem::Result Ethernet::getTransmitPacket ( NetworkQueue::Packet **  pkt,
const void *  address,
const Size  addressSize,
const Identifier  protocol,
const Size  payloadSize 
)
virtual

Get a new packet for transmission.

Parameters
pktOn output contains a pointer to a Packet
addressAddress of the destination of this packet
addressSizeNumber of bytes of the address
protocolIdentifier for the protocol to create the packet for
payloadSizeNumber of payload bytes
Returns
Result code

Reimplemented from NetworkProtocol.

Definition at line 91 of file Ethernet.cpp.

References NetworkProtocol::ARP, MemoryBlock::copy(), Ethernet::Header::destination, ERROR, NetworkQueue::get(), NetworkDevice::getTransmitQueue(), NetworkProtocol::IPV4, m_address, NetworkProtocol::m_device, FileSystem::NotSupported, FileSystem::RetryAgain, Ethernet::Header::source, FileSystem::Success, Ethernet::Header::type, and writeBe16().

◆ initialize()

FileSystem::Result Ethernet::initialize ( )
virtual

◆ process()

FileSystem::Result Ethernet::process ( const NetworkQueue::Packet pkt,
const Size  offset 
)
virtual

Process incoming network packet.

Parameters
pktIncoming packet pointer
offsetOffset for processing
Returns
Result code

Implements NetworkProtocol.

Definition at line 126 of file Ethernet.cpp.

References ARP, NetworkQueue::Packet::data, DEBUG, FileSystem::InvalidArgument, IPV4, m_arp, m_ipv4, ARP::process(), IPV4::process(), readBe16(), NetworkQueue::Packet::size, type, and Ethernet::Header::type.

Referenced by NetworkDevice::process().

◆ setAddress()

FileSystem::Result Ethernet::setAddress ( const Address address)
virtual

Set Ethernet address.

Parameters
addressInput address
Returns
Result code

Definition at line 55 of file Ethernet.cpp.

References MemoryBlock::copy(), m_address, NetworkProtocol::m_device, NetworkDevice::setAddress(), and FileSystem::Success.

◆ setARP()

void Ethernet::setARP ( ::ARP arp)

Set ARP instance.

Parameters
arpARP object instance

Definition at line 66 of file Ethernet.cpp.

References m_arp.

Referenced by NetworkDevice::initialize().

◆ setIP()

void Ethernet::setIP ( ::IPV4 ip)

Set IPV4 instance.

Parameters
ipIPV4 instance

Definition at line 71 of file Ethernet.cpp.

References m_ipv4.

Referenced by NetworkDevice::initialize().

◆ toString()

const String Ethernet::toString ( const Address  address)
static

Convert address to string.

Parameters
addressInput ethernet address
Returns
Text value of the ethernet address

Definition at line 76 of file Ethernet.cpp.

References Ethernet::Address::addr, and Number::Hex.

Referenced by NetCtl::showDevice().

Field Documentation

◆ CRCSize

const Size Ethernet::CRCSize = 4
static

Size of the CRC checksum (which is set after the payload)

Definition at line 47 of file Ethernet.h.

◆ m_address

Address Ethernet::m_address
private

Current ethernet address.

Definition at line 176 of file Ethernet.h.

Referenced by Ethernet(), getAddress(), getTransmitPacket(), initialize(), and setAddress().

◆ m_arp

::ARP* Ethernet::m_arp
private

ARP protocol.

Definition at line 179 of file Ethernet.h.

Referenced by Ethernet(), process(), and setARP().

◆ m_ipv4

::IPV4* Ethernet::m_ipv4
private

IPV4 protocol.

Definition at line 182 of file Ethernet.h.

Referenced by Ethernet(), process(), and setIP().


The documentation for this class was generated from the following files: