RDK Documentation (Open Sourced RDK Components)
Device_DHCPv4_Client.h
Go to the documentation of this file.
1 /*
2  * If not stated otherwise in this file or this component's Licenses.txt file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2016 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 
20 
21 /**
22  * @file Device_DHCPv4_Client.h
23  * @brief The header file provides TR069 device DHCPv4 Client information APIs.
24  */
25 
26 /**
27  * @defgroup TR69_HOSTIF_DHCPv4_CLIENT TR-069 Object (Device.DHCPv4)
28  * @par Overview
29  * Dynamic Host Configuration Protocol version 4 (DHCPv4) allows for the automatic configuration of
30  * client systems on an Internet Protocol version 4 (IPv4) network. DHCPv4 eliminates the need to
31  * individually configure devices, allowing them to set network properties by connecting to the DHCPv4 server instead.
32  * @par Function
33  * Prerequisites :
34  * - DHCPv4 server system
35  * - DHCPv4 client system
36  * - Navigable network connection between DHCPv4 server and DHCPv4 client
37  * When a new system is brought online (generally at boot) and needs to configure itself for
38  * communicating on the network it makes a broadcast looking for a DHCPv4 server. When the DHCPv4
39  * server observes this broadcast it responds to the request with an offer that contains the
40  * information necessary to join the network. At its most basic level, this includes an IP address,
41  * netmask, the DHCP server's IP address, the default route/gateway, DNS server address(es), and
42  * the lease time (how long the offer will be good for). The DHCPv4 client then responds requesting
43  * the configuration offered. Finally, the DHCPv4 server responds acknowledging and granting the
44  * request. In shorter form, this transaction is as follows:
45  * - Client requests information (the DHCPDISCOVER)
46  * - One or more servers respond (the DHCPOFFER)
47  * - Client selects one response and requests that configuration from the offering server (the DHCPREQUEST)
48  * - The server which made the offer responds acknowledging the configuration (the DHCPACKNOWLEDGEMENT)
49  *
50  * Example container
51  * DHCPDISCOVER:
52  * Bit Range | Bit Use Nominal | Value
53  * ----------|---------------------------------------------|--------
54  * 0 - 15 | Source Port Number | 01000011
55  * 16 - 31 | Destination Port Number | 01000100
56  * 32 - 47 | Packet Length | 0000000101001000
57  * 48 - 63 | Checksum | varies
58  * 64 - 71 | Operation Code (OP) | 00000001
59  * 72 - 79 | Hardware Address Type (HTYPE) | 00000001
60  * 80 - 87 | Hardware Address Length (HLEN) | 00000110
61  * 88 - 95 | Hops (HOPS) | 00000000
62  * 96 - 127 | Transaction ID (XID) | varies
63  * 128 - 143 | Seconds Since Client Started Request (SECS) | 0000000000000000
64  * 144 - 159 | Flags (FLAGS) | 0000000000000000
65  * 160 - 181 | Client IP Address (CIADDR) | 00000000000000000000000000000000
66  * 182 - 213 | Your IP Address (YIADDR) | 00000000000000000000000000000000
67  * 214 - 245 | Server IP Address (SIADDR) | 00000000000000000000000000000000
68  * 246 - 277 | Relay IP Address (GIADDR) | 00000000000000000000000000000000
69  *
70  * DHCPOFFER
71  * Bit Range | Bit Use
72  * -----------|---------
73  * a - b | Use
74  *
75  * DHCPREQUEST
76  * Bit Range | Bit Use
77  * -----------|--------
78  * a - b | Use
79  *
80  * DHCPACKNOWLEDGEMENT
81  * Bit Range | Bit Use
82  * --------------------|---------
83  * a - b | Use
84  *
85  * @ingroup TR69_HOSTIF_PROFILE
86  *
87  * @defgroup TR69_HOSTIF_DHCPv4_CLIENT_API TR-069 Object (Device.DHCPv4.Interface.{i}) Public APIs
88  * Describe the details about RDK TR069 Device DHCPv4 Client APIs specifications.
89  * @ingroup TR69_HOSTIF_DHCPv4_CLIENT
90  *
91  * @defgroup TR69_HOSTIF_DHCPv4_CLIENT_CLASSES TR-069 Object (Device.DHCPv4.Interface.{i}) Public Classes
92  * Describe the details about classes used in TR069 Device DHCPv4 Client.
93  * @ingroup TR69_HOSTIF_DHCPv4_CLIENT
94  *
95  * @defgroup TR69_HOSTIF_DHCPv4_CLIENT_DSSTRUCT TR-069 Object (Device.DHCPv4.Interface.{i}) Public DataStructure
96  * Describe the details about structure used in TR069 Device DHCPv4 Client.
97  * @ingroup TR69_HOSTIF_DHCPv4_CLIENT
98  *
99  */
100 
101 #ifndef DEVICE_DHCPv4_CLIENT_H_
102 #define DEVICE_DHCPv4_CLIENT_H_
103 #include <net/if.h>
104 #include "hostIf_main.h"
105 #include "hostIf_tr69ReqHandler.h"
106 #include "hostIf_utils.h"
107 #include "hostIf_updateHandler.h"
108 
109 #define MAX_IF_LEN 256 //Length of interface. http://www.broadband-forum.org/cwmp/tr-181-2-8-0.html#D.Device:2.Device.DHCPv4.Client.{i}.Interface
110 #define MAX_DNS_SERVER_LEN 256 //Length of DNS servers. http://www.broadband-forum.org/cwmp/tr-181-2-8-0.html#D.Device:2.Device.DHCPv4.Client.{i}.DNSServers
111 #define MAX_IP_ROUTER_LEN 256 //Length of IP Routers. http://www.broadband-forum.org/cwmp/tr-181-2-8-0.html#D.Device:2.Device.DHCPv4.Client.{i}.IPRouters
112 
113 /**
114  * @addtogroup TR69_HOSTIF_DHCPv4_CLIENT_DSSTRUCT
115  * @{
116  */
117 /**
118  * @brief These values are the members variables of the DHCPv4Client structure.
119  */
120 typedef struct DHCPv4Client {
121  char interface[MAX_IF_LEN];
122  char dnsservers[MAX_DNS_SERVER_LEN];
123  char ipRouters[MAX_IP_ROUTER_LEN];
124 }DHCPv4Client;
125 
126 /**
127  * @brief These values are the members variables of the DHCPv4ClientParamBackUpFlag structure.
128  */
130  unsigned int interface:1;
131  unsigned int dnsservers:1;
132  unsigned int ipRouters:1;
134 
135 /**
136  * @enum DHCPv4ClientMembers
137  * @brief These values are the members of the DHCPv4ClientMembers.
138  */
139 typedef enum DHCPv4ClientMembers {
140  eDHCPv4Interface,
141  eDHCPv4Dnsservers,
142  eDHCPv4Iprouters
144 
145 /** @} */ //End of the Doxygen tag TR69_HOSTIF_DHCPv4_CLIENT_DSSTRUCT
146 
147 /**
148  * @brief This class provides the interface for getting device DHCPv4 Client information.
149  * @ingroup TR69_HOSTIF_DHCPv4_CLIENT_CLASSES
150  */
152  int dev_id;
153  static GHashTable *dhcpv4ClientHash;
154  static GMutex *m_mutex;
155  static GHashTable *m_notifyHash;
156  hostIf_DHCPv4Client(int dev_id);
158  static DHCPv4Client dhcpClient;
159  DHCPv4Client backupDhcpClient;
160  DHCPv4ClientParamBackUpFlag bBackUpFlags;
161  int get_Device_DHCPv4_Client_Fields(DHCPv4ClientMembers dhclientMember);
162  bool isIfnameInroutetoDNSServer(char* dnsServer, char* ifName);
163  bool isValidIPAddr(char* addr);
164  int getInterfaceName(char* ifname);
165  public:
166  static hostIf_DHCPv4Client* getInstance(int dev_id);
167  static GList* getAllInstances();
168  static void closeInstance(hostIf_DHCPv4Client *pDev);
169  static void closeAllInstances();
170  static int get_Device_DHCPv4_ClientNumberOfEntries(HOSTIF_MsgData_t *stMsgData);
171  int get_Device_DHCPv4_Client_InterfaceReference(HOSTIF_MsgData_t *stMsgData,bool *pChanged = NULL);
172  int get_Device_DHCPv4_Client_DnsServer(HOSTIF_MsgData_t *stMsgData,bool* pChanged=NULL);
173  int get_Device_DHCPv4_Client_IPRouters(HOSTIF_MsgData_t *stMsgData,bool* pChanged=NULL);
174  static void getLock();
175  static void releaseLock();
176  static GHashTable* getNotifyHash();
177 
178 };
179 #endif
180 
hostIf_DHCPv4Client::hostIf_DHCPv4Client
hostIf_DHCPv4Client(int dev_id)
Class Constructor of the class hostIf_DHCPv4Client.
Definition: Device_DHCPv4_Client.cpp:49
_HostIf_MsgData_t
Definition: hostIf_tr69ReqHandler.h:170
hostIf_DHCPv4Client
This class provides the interface for getting device DHCPv4 Client information.
Definition: Device_DHCPv4_Client.h:151
DHCPv4Client
struct DHCPv4Client DHCPv4Client
These values are the members variables of the DHCPv4Client structure.
hostIf_main.h
hostIf_main API.
hostIf_DHCPv4Client::get_Device_DHCPv4_Client_DnsServer
int get_Device_DHCPv4_Client_DnsServer(HOSTIF_MsgData_t *stMsgData, bool *pChanged=NULL)
This gets the DNS server information used by the DHCP(Dynamic Host Configuration Protocol) v4 client ...
Definition: Device_DHCPv4_Client.cpp:200
DHCPv4Client
These values are the members variables of the DHCPv4Client structure.
Definition: Device_DHCPv4_Client.h:120
DHCPv4ClientParamBackUpFlag
These values are the members variables of the DHCPv4ClientParamBackUpFlag structure.
Definition: Device_DHCPv4_Client.h:129
DHCPv4ClientParamBackUpFlag
struct DHCPv4ClientParamBackUpFlag DHCPv4ClientParamBackUpFlag
These values are the members variables of the DHCPv4ClientParamBackUpFlag structure.
DHCPv4ClientMembers
DHCPv4ClientMembers
These values are the members of the DHCPv4ClientMembers.
Definition: Device_DHCPv4_Client.h:139
hostIf_DHCPv4Client::get_Device_DHCPv4_Client_InterfaceReference
int get_Device_DHCPv4_Client_InterfaceReference(HOSTIF_MsgData_t *stMsgData, bool *pChanged=NULL)
This gets the interface information used by the DHCP(Dynamic Host Configuration Protocol) v4 client d...
Definition: Device_DHCPv4_Client.cpp:167
hostIf_DHCPv4Client::get_Device_DHCPv4_Client_IPRouters
int get_Device_DHCPv4_Client_IPRouters(HOSTIF_MsgData_t *stMsgData, bool *pChanged=NULL)
This gets the IP Routers information used by the DHCP(Dynamic Host Configuration Protocol) v4 client ...
Definition: Device_DHCPv4_Client.cpp:233