embkernel
 All Classes Functions Variables Typedefs Groups Pages
NetArp.hpp
1 //------------------------------------------------------------------------------
2 //This file is part of embKernel.
3 //See license.txt for the full license governing this code.
4 //------------------------------------------------------------------------------
5 
6 #ifndef NET_ARP_HPP_
7 #define NET_ARP_HPP_
8 
9 #include "NetDefs.hpp"
10 #include "NetCfg.hpp"
11 #include "RtosSemaphore.hpp"
12 
13 class NetArp {
14  friend class Net;
15  friend class NetUdpSocket;
16  friend class NetTcpSocket;
17 private:
18  static const uint16_t TIMEOUT_SLOT_RESOLVING = 20; //in 0.1s unit
19  static const uint16_t RETRIES_SLOT_RESOLVING = 3;
20  static const uint16_t TIMEOUT_SLOT_VALID = 60 * 600; //in 0.1s unit
21  typedef enum : uint16_t {
22  SLOT_EMPTY = 0,
23  SLOT_RESOLVING,
24  SLOT_RESOLVED,
25  SLOT_TIMEOUT,
26  SLOT_VALID,
27  SLOT_RESERVED
28  } SLOT_STATUS;
29 
30  typedef struct tagSlot {
31  uint32_t timer;
32  RtosTask* task;
33  NetDefs::IP_ADDR ipAddr;
34  NetDefs::MAC_ADDR macAddr;
35  SLOT_STATUS status;
36  tagSlot() :
37  status(SLOT_EMPTY) {
38  }
39  }__attribute__((packed)) SLOT;
40 
41  static SLOT sSlots[NET_CFG_MAX_ARP_ENTRIES];
42 
43  static SLOT* getFreeSlot();
44  static SLOT* getWaitingSlot(const NetDefs::IP_ADDR ipAddr);
45  static bool checkCache(const NetDefs::IP_ADDR& ipAddr, NetDefs::MAC_ADDR& macAddr);
46 
47  static void tick();
48 
49  static void processFrame(NetDefs::FRAME& frame, NetDefs::ARP_HEADER& header);
50  static void send(NetDefs::FRAME& frame, const NetDefs::MAC_ADDR& macDst, const NetDefs::IP_ADDR& ipDst, const NetDefs::ARP_OPERATION op);
51  static void swapHeader(NetDefs::ARP_HEADER& header);
52  static bool resolve(NetDefs::IP_ADDR ipAddr, NetDefs::MAC_ADDR& macAddr);
53 };
54 
55 #endif /* NET_ARP_HPP_ */