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)
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 
39 {
40 }
41 
43 {
44  const FileSystem::Result result = Device::initialize();
45  if (result != FileSystem::Success)
46  {
47  ERROR("failed to initialize Device: result = " << (int) result);
48  return result;
49  }
50 
51  // Initialize protocols
52  m_eth->initialize();
53  m_arp->initialize();
54  m_ipv4->initialize();
55  m_icmp->initialize();
56  m_udp->initialize();
57 
58  // Connect objects
59  m_eth->setIP(m_ipv4);
60  m_eth->setARP(m_arp);
61  m_arp->setIP(m_ipv4);
65 
66  return FileSystem::Success;
67 }
68 
70 {
71  return m_maximumPacketSize;
72 }
73 
75 {
76  return &m_receive;
77 }
78 
80 {
81  return &m_transmit;
82 }
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 
102 {
103  DEBUG("");
104 
105  return FileSystem::Success;
106 }
Ethernet::process
virtual FileSystem::Result process(const NetworkQueue::Packet *pkt, const Size offset)
Process incoming network packet.
Definition: Ethernet.cpp:126
NetworkDevice::m_eth
Ethernet * m_eth
Definition: NetworkDevice.h:146
NetworkDevice::startDMA
virtual FileSystem::Result startDMA()
Start DMA processing.
Definition: NetworkDevice.cpp:101
NetworkDevice::m_server
NetworkServer & m_server
Definition: NetworkDevice.h:144
NetworkDevice::getMaximumPacketSize
const Size getMaximumPacketSize() const
Get maximum packet size.
Definition: NetworkDevice.cpp:69
NetworkDevice::m_udp
UDP * m_udp
Definition: NetworkDevice.h:154
NetworkDevice::NetworkDevice
NetworkDevice(const u32 inode, NetworkServer &server)
Constructor.
Definition: NetworkDevice.cpp:20
Device::initialize
virtual FileSystem::Result initialize()
Initialize the device.
Definition: Device.cpp:35
NetworkDevice::~NetworkDevice
virtual ~NetworkDevice()
Destructor.
Definition: NetworkDevice.cpp:38
NetworkDevice::m_maximumPacketSize
Size m_maximumPacketSize
Maximum size of each packet.
Definition: NetworkDevice.h:138
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
ARP::setIP
void setIP(::IPV4 *ip)
Set IPV4 instance.
Definition: ARP.cpp:50
UDP
User Datagram Protocol (UDP)
Definition: UDP.h:41
Device
Abstract device class interface.
Definition: Device.h:35
NetworkDevice::m_arp
ARP * m_arp
Definition: NetworkDevice.h:148
ProcessID
u32 ProcessID
Process Identification Number.
Definition: Types.h:140
NetworkDevice::process
virtual FileSystem::Result process(const NetworkQueue::Packet *packet, const Size offset=0)
Process a received network packet.
Definition: NetworkDevice.cpp:92
FileSystem::Success
@ Success
Definition: FileSystem.h:54
NetworkQueue
Networking packet queue implementation.
Definition: NetworkQueue.h:37
Ethernet
Ethernet networking protocol.
Definition: Ethernet.h:42
DEBUG
#define DEBUG(msg)
Output a debug message to standard output.
Definition: Log.h:89
NetworkDevice::m_ipv4
IPV4 * m_ipv4
Definition: NetworkDevice.h:150
NetworkDevice.h
ICMP::initialize
virtual FileSystem::Result initialize()
Perform initialization.
Definition: ICMP.cpp:37
NetworkServer
Networking server.
Definition: NetworkServer.h:40
UDP::unregisterSockets
void unregisterSockets(const ProcessID pid)
Remove sockets for a process.
Definition: UDP.cpp:82
ARP::initialize
virtual FileSystem::Result initialize()
Perform initialization.
Definition: ARP.cpp:41
NetworkDevice::getTransmitQueue
NetworkQueue * getTransmitQueue()
Get transmit queue.
Definition: NetworkDevice.cpp:79
NetworkDevice::m_receive
NetworkQueue m_receive
Definition: NetworkDevice.h:140
u32
unsigned int u32
Unsigned 32-bit number.
Definition: Types.h:53
ICMP::unregisterSockets
void unregisterSockets(const ProcessID pid)
Remove sockets for a process.
Definition: ICMP.cpp:126
Size
unsigned int Size
Any sane size indicator cannot go negative.
Definition: Types.h:128
NetworkDevice::m_icmp
ICMP * m_icmp
Definition: NetworkDevice.h:152
IPV4::setARP
void setARP(::ARP *arp)
Set ARP instance.
Definition: IPV4.cpp:60
IPV4
Internet Protocol Version 4.
Definition: IPV4.h:40
IPV4::initialize
virtual FileSystem::Result initialize()
Perform initialization.
Definition: IPV4.cpp:45
NetworkDevice::getReceiveQueue
NetworkQueue * getReceiveQueue()
Get receive queue.
Definition: NetworkDevice.cpp:74
IPV4::setUDP
void setUDP(::UDP *udp)
Set UDP instance.
Definition: IPV4.cpp:65
IPV4::setICMP
void setICMP(::ICMP *icmp)
Set ICMP instance.
Definition: IPV4.cpp:55
FileSystem::CharacterDeviceFile
@ CharacterDeviceFile
Definition: FileSystem.h:75
ERROR
#define ERROR(msg)
Output an error message.
Definition: Log.h:61
FileSystem::Result
Result
Result code for filesystem Actions.
Definition: FileSystem.h:52
FileSystem
Definition: FileSystem.h:31
Ethernet::setIP
void setIP(::IPV4 *ip)
Set IPV4 instance.
Definition: Ethernet.cpp:71
NetworkDevice::unregisterSockets
void unregisterSockets(const ProcessID pid)
Remove sockets for a process.
Definition: NetworkDevice.cpp:84
NetworkDevice::m_transmit
NetworkQueue m_transmit
Definition: NetworkDevice.h:142
NetworkQueue::Packet
Represents a network packet.
Definition: NetworkQueue.h:50
ARP
Address Resolution Protocol.
Definition: ARP.h:42
NetworkDevice::initialize
virtual FileSystem::Result initialize()
Initialize the device.
Definition: NetworkDevice.cpp:42
UDP::initialize
virtual FileSystem::Result initialize()
Perform initialization.
Definition: UDP.cpp:36
ICMP
Internet Control Message Protocol (ICMP)
Definition: ICMP.h:42