FreeNOS
NetworkDevice.cpp
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#include "NetworkDevice.h"
19
21 NetworkServer &server)
22 : Device(inode, FileSystem::CharacterDeviceFile)
23 , m_maximumPacketSize(1500)
24 , m_receive(m_maximumPacketSize)
25 , m_transmit(m_maximumPacketSize)
26 , m_server(server)
27
28{
29 // Allocate protocols. Note that the FileSystemServer will take
30 // ownership of these objects via the FileCache hierarchy
31 m_eth = new Ethernet(m_server, *this);
32 m_arp = new ARP(m_server, *this, *m_eth);
33 m_ipv4 = new IPV4(m_server, *this, *m_eth);
34 m_icmp = new ICMP(m_server, *this, *m_ipv4);
35 m_udp = new UDP(m_server, *this, *m_ipv4);
36}
37
41
43{
45 if (result != FileSystem::Success)
46 {
47 ERROR("failed to initialize Device: result = " << (int) result);
48 return result;
49 }
50
51 // Initialize protocols
57
58 // Connect objects
65
67}
68
73
78
83
85{
86 DEBUG("pid = " << pid);
87
90}
91
93 const Size offset)
94{
95 DEBUG("");
96
97 // Let the protocols process the packet
98 return m_eth->process(pkt, offset);
99}
100
Address Resolution Protocol.
Definition ARP.h:43
virtual FileSystem::Result initialize()
Perform initialization.
Definition ARP.cpp:41
void setIP(::IPV4 *ip)
Set IPV4 instance.
Definition ARP.cpp:50
Abstract device class interface.
Definition Device.h:36
virtual FileSystem::Result initialize()
Initialize the device.
Definition Device.cpp:35
Ethernet networking protocol.
Definition Ethernet.h:43
void setARP(::ARP *arp)
Set ARP instance.
Definition Ethernet.cpp:66
void setIP(::IPV4 *ip)
Set IPV4 instance.
Definition Ethernet.cpp:71
virtual FileSystem::Result initialize()
Perform initialization.
Definition Ethernet.cpp:39
virtual FileSystem::Result process(const NetworkQueue::Packet *pkt, const Size offset)
Process incoming network packet.
Definition Ethernet.cpp:126
Internet Control Message Protocol (ICMP)
Definition ICMP.h:43
void unregisterSockets(const ProcessID pid)
Remove sockets for a process.
Definition ICMP.cpp:126
virtual FileSystem::Result initialize()
Perform initialization.
Definition ICMP.cpp:37
Internet Protocol Version 4.
Definition IPV4.h:41
virtual FileSystem::Result initialize()
Perform initialization.
Definition IPV4.cpp:45
void setARP(::ARP *arp)
Set ARP instance.
Definition IPV4.cpp:60
void setUDP(::UDP *udp)
Set UDP instance.
Definition IPV4.cpp:65
void setICMP(::ICMP *icmp)
Set ICMP instance.
Definition IPV4.cpp:55
NetworkQueue m_receive
NetworkDevice(const u32 inode, NetworkServer &server)
Constructor.
Ethernet * m_eth
Size m_maximumPacketSize
Maximum size of each packet.
virtual FileSystem::Result process(const NetworkQueue::Packet *packet, const Size offset=0)
Process a received network packet.
virtual ~NetworkDevice()
Destructor.
virtual FileSystem::Result startDMA()
Start DMA processing.
NetworkQueue * getTransmitQueue()
Get transmit queue.
virtual FileSystem::Result initialize()
Initialize the device.
const Size getMaximumPacketSize() const
Get maximum packet size.
NetworkQueue m_transmit
NetworkQueue * getReceiveQueue()
Get receive queue.
NetworkServer & m_server
void unregisterSockets(const ProcessID pid)
Remove sockets for a process.
Networking packet queue implementation.
Networking server.
User Datagram Protocol (UDP)
Definition UDP.h:42
void unregisterSockets(const ProcessID pid)
Remove sockets for a process.
Definition UDP.cpp:82
virtual FileSystem::Result initialize()
Perform initialization.
Definition UDP.cpp:36
u32 ProcessID
Process Identification Number.
Definition Types.h:140
unsigned int u32
Unsigned 32-bit number.
Definition Types.h:53
#define ERROR(msg)
Output an error message.
Definition Log.h:61
unsigned int Size
Any sane size indicator cannot go negative.
Definition Types.h:128
#define DEBUG(msg)
Output a debug message to standard output.
Definition Log.h:89
Result
Result code for filesystem Actions.
Definition FileSystem.h:53
Represents a network packet.