The Pedigree Project  0.1
NetworkStack.h
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef MACHINE_NETWORK_STACK_H
21 #define MACHINE_NETWORK_STACK_H
22 
23 #include "pedigree/kernel/compiler.h"
24 #include "pedigree/kernel/machine/Network.h"
25 #include "pedigree/kernel/processor/types.h"
26 #include "pedigree/kernel/utilities/MemoryPool.h"
27 #include "pedigree/kernel/utilities/RequestQueue.h"
28 #include "pedigree/kernel/utilities/String.h"
29 #include "pedigree/kernel/utilities/Tree.h"
30 #include "pedigree/kernel/utilities/Vector.h"
31 
32 // lwIP network interface type
33 struct netif;
34 
41 {
42  public:
43  NetworkStack();
44  virtual ~NetworkStack();
45 
48  {
49  return *stack;
50  }
51 
53  void
54  receive(size_t nBytes, uintptr_t packet, Network *pCard, uint32_t offset);
55 
57  void registerDevice(Network *pDevice);
58 
60  Network *getDevice(size_t n);
61 
63  size_t getNumDevices();
64 
66  void deRegisterDevice(Network *pDevice);
67 
69  void setLoopback(Network *pCard)
70  {
71  m_pLoopback = pCard;
72  }
73 
75  inline Network *getLoopback()
76  {
77  return m_pLoopback;
78  }
79 
82  {
83  return m_MemPool;
84  }
85 
87  class Packet
88  {
89  friend class NetworkStack;
90 
91  public:
92  Packet();
93  virtual ~Packet();
94 
95  uintptr_t getBuffer() const
96  {
97  return m_Buffer;
98  }
99 
100  size_t getLength() const
101  {
102  return m_PacketLength;
103  }
104 
105  Network *getCard() const
106  {
107  return m_pCard;
108  }
109 
110  uint32_t getOffset() const
111  {
112  return m_Offset;
113  }
114 
115  private:
116  bool copyFrom(uintptr_t otherPacket, size_t size);
117 
118  uintptr_t m_Buffer;
119  size_t m_PacketLength;
120  Network *m_pCard;
121  uint32_t m_Offset;
122  Mutex m_Pushed;
123  };
124 
126  struct netif *getInterface(Network *pCard) const
127  {
128  return m_Interfaces.lookup(pCard);
129  }
130 
131  private:
132  static NetworkStack *stack;
133 
134  virtual uint64_t executeRequest(
135  uint64_t p1, uint64_t p2, uint64_t p3, uint64_t p4, uint64_t p5,
136  uint64_t p6, uint64_t p7, uint64_t p8);
137 
140 
143 
146 
147 #if defined(THREADS) || defined(UTILITY_LINUX)
148  Mutex m_Lock;
149 #endif
150 
153 
156 };
157 
158 #endif
Definition: Mutex.h:58
MemoryPool m_MemPool
Definition: NetworkStack.h:145
MemoryPool & getMemPool()
Definition: NetworkStack.h:81
Definition: netif.h:244
Tree< Network *, struct netif * > m_Interfaces
Definition: NetworkStack.h:152
static NetworkStack & instance()
Definition: NetworkStack.h:47
Network * getLoopback()
Definition: NetworkStack.h:75
void setLoopback(Network *pCard)
Definition: NetworkStack.h:69
size_t m_NextInterfaceNumber
Definition: NetworkStack.h:155
struct netif * getInterface(Network *pCard) const
Definition: NetworkStack.h:126
Network * m_pLoopback
Definition: NetworkStack.h:139
Vector< Network * > m_Children
Definition: NetworkStack.h:142