embkernel
 All Classes Functions Variables Typedefs Groups Pages
NetClientDhcp.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_CLIENT_DHCP_HPP_
7 #define NET_CLIENT_DHCP_HPP_
8 
9 #include "NetDefs.hpp"
10 
11 class NetClientDhcp {
12  friend class Net;
13  friend class NetUdp;
14 private:
15  typedef enum {
16  MSG_UNKNOWN = 0,
17  MSG_DISCOVER = 1,
18  MSG_OFFER = 2,
19  MSG_REQUEST = 3,
20  MSG_DECLINE = 4,
21  MSG_ACK = 5,
22  MSG_NAK = 6,
23  MSG_RELEASE = 7,
24  MSG_INFORM
25  } MSG_TYPE;
26 
27  typedef enum {
28  OPT_MESSAGE_PAD = 0,
29  OPT_SUBNET_MASK = 1,
30  OPT_ROUTER = 3,
31  OPT_DNS = 6,
32  OPT_HOST_NAME = 12,
33  OPT_REQUESTED_IP_ADDRESS = 50,
34  OPT_IP_LEASE_TIME = 51,
35  OPT_DHCP_MESSAGE_TYPE = 53,
36  OPT_SERVER_IDENTIFIER = 54,
37  OPT_PARAM_REQUEST_LIST = 55,
38  OPT_CLIENT_IDENTIFIER = 61,
39  OPT_END = 255
40  } MSG_OPT;
41 
42  typedef enum {
43  STATE_DISABLED = 0,
44  STATE_INIT,
45  STATE_WAIT_OFFER,
46  STATE_WAIT_ACK,
47  STATE_BOUND
48  } STATE;
49 
50  static STATE sState;
51  static uint32_t sTransactionId;
52  static NetDefs::IP_ADDR sOfferedYourIpAddr;
53  static NetDefs::IP_ADDR sOfferedMask;
54  static NetDefs::IP_ADDR sOfferedServerIpAddr;
55  static NetDefs::IP_ADDR sOfferedGatewayIpAddr;
56  static NetDefs::IP_ADDR sOfferedDnsIpAddr;
57  static uint32_t sLeaseTime;
58  static uint32_t sTimeout;
59 
60  static void processFrame(NetDefs::FRAME& frame, NetDefs::DHCP_HEADER& header, int len);
61  static bool sendMessage(MSG_TYPE type);
62  static bool parseMsg(NetDefs::FRAME& frame, NetDefs::DHCP_HEADER& header, MSG_TYPE& msgType, int len);
63  static uint8_t* writeOption(uint8_t* dst, MSG_OPT option, const uint8_t* parameters, int len);
64  static void tick();
65  static void swapHeader(NetDefs::DHCP_HEADER& header);
66 };
67 
68 #endif /* NET_CLIENT_DHCP_HPP_ */