ReactOS  0.4.12-dev-14-gd0c8636
api.c File Reference
#include <rosdhcp.h>
#include <reactos/debug.h>
Include dependency graph for api.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

VOID ApiInit ()
 
VOID ApiLock ()
 
VOID ApiUnlock ()
 
VOID ApiFree ()
 
DWORD DSLeaseIpAddress (PipeSendFunc Send, COMM_DHCP_REQ *Req)
 
DWORD DSQueryHWInfo (PipeSendFunc Send, COMM_DHCP_REQ *Req)
 
DWORD DSReleaseIpAddressLease (PipeSendFunc Send, COMM_DHCP_REQ *Req)
 
DWORD DSRenewIpAddressLease (PipeSendFunc Send, COMM_DHCP_REQ *Req)
 
DWORD DSStaticRefreshParams (PipeSendFunc Send, COMM_DHCP_REQ *Req)
 
DWORD DSGetAdapterInfo (PipeSendFunc Send, COMM_DHCP_REQ *Req)
 

Variables

static CRITICAL_SECTION ApiCriticalSection
 
HANDLE AdapterStateChangedEvent
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 11 of file api.c.

Function Documentation

◆ ApiFree()

VOID ApiFree ( )

Definition at line 30 of file api.c.

Referenced by init_client().

30  {
32 }
static CRITICAL_SECTION ApiCriticalSection
Definition: api.c:14
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)

◆ ApiInit()

VOID ApiInit ( )

Definition at line 18 of file api.c.

Referenced by init_client().

18  {
20 }
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:697
static CRITICAL_SECTION ApiCriticalSection
Definition: api.c:14

◆ ApiLock()

VOID ApiLock ( )

Definition at line 22 of file api.c.

Referenced by AdapterDiscoveryThread(), AdapterStop(), dispatch(), DSGetAdapterInfo(), DSLeaseIpAddress(), DSQueryHWInfo(), DSReleaseIpAddressLease(), DSRenewIpAddressLease(), DSStaticRefreshParams(), and IsReconnectHackNeeded().

22  {
24 }
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
static CRITICAL_SECTION ApiCriticalSection
Definition: api.c:14

◆ ApiUnlock()

VOID ApiUnlock ( )

Definition at line 26 of file api.c.

Referenced by AdapterDiscoveryThread(), AdapterStop(), dispatch(), DSGetAdapterInfo(), DSLeaseIpAddress(), DSQueryHWInfo(), DSReleaseIpAddressLease(), DSRenewIpAddressLease(), DSStaticRefreshParams(), and IsReconnectHackNeeded().

26  {
28 }
static CRITICAL_SECTION ApiCriticalSection
Definition: api.c:14
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)

◆ DSGetAdapterInfo()

DWORD DSGetAdapterInfo ( PipeSendFunc  Send,
COMM_DHCP_REQ Req 
)

Definition at line 209 of file api.c.

Referenced by PipeThreadProc().

209  {
210  COMM_DHCP_REPLY Reply;
211  PDHCP_ADAPTER Adapter;
212 
213  ApiLock();
214 
215  Adapter = AdapterFindIndex( Req->AdapterIndex );
216 
217  Reply.Reply = Adapter ? 1 : 0;
218 
219  if( Adapter ) {
220  Reply.GetAdapterInfo.DhcpEnabled = (S_STATIC != Adapter->DhclientState.state);
221  if (S_BOUND == Adapter->DhclientState.state) {
222  if (sizeof(Reply.GetAdapterInfo.DhcpServer) ==
223  Adapter->DhclientState.active->serveraddress.len) {
224  memcpy(&Reply.GetAdapterInfo.DhcpServer,
225  Adapter->DhclientState.active->serveraddress.iabuf,
226  Adapter->DhclientState.active->serveraddress.len);
227  } else {
228  DPRINT1("Unexpected server address len %d\n",
229  Adapter->DhclientState.active->serveraddress.len);
230  Reply.GetAdapterInfo.DhcpServer = htonl(INADDR_NONE);
231  }
232  Reply.GetAdapterInfo.LeaseObtained = Adapter->DhclientState.active->obtained;
233  Reply.GetAdapterInfo.LeaseExpires = Adapter->DhclientState.active->expiry;
234  } else {
235  Reply.GetAdapterInfo.DhcpServer = htonl(INADDR_NONE);
236  Reply.GetAdapterInfo.LeaseObtained = 0;
237  Reply.GetAdapterInfo.LeaseExpires = 0;
238  }
239  }
240 
241  ApiUnlock();
242 
243  return Send( &Reply );
244 }
Definition: dhcpd.h:175
struct _COMM_DHCP_REPLY::@3289 GetAdapterInfo
#define htonl(x)
Definition: module.h:212
#define INADDR_NONE
Definition: tcp.c:42
PDHCP_ADAPTER AdapterFindIndex(unsigned int indx)
Definition: adapter.c:513
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
struct client_state DhclientState
Definition: rosdhcp.h:72
#define DPRINT1
Definition: precomp.h:8
VOID ApiUnlock()
Definition: api.c:26
VOID ApiLock()
Definition: api.c:22

◆ DSLeaseIpAddress()

DWORD DSLeaseIpAddress ( PipeSendFunc  Send,
COMM_DHCP_REQ Req 
)

Definition at line 36 of file api.c.

Referenced by PipeThreadProc().

36  {
37  COMM_DHCP_REPLY Reply;
38  PDHCP_ADAPTER Adapter;
39  struct protocol* proto;
40 
41  ApiLock();
42 
43  Adapter = AdapterFindIndex( Req->AdapterIndex );
44 
45  Reply.Reply = Adapter ? 1 : 0;
46 
47  if( Adapter ) {
48  proto = find_protocol_by_adapter( &Adapter->DhclientInfo );
49  if (proto)
50  remove_protocol(proto);
51 
52  add_protocol( Adapter->DhclientInfo.name,
53  Adapter->DhclientInfo.rfdesc, got_one,
54  &Adapter->DhclientInfo );
55 
56  Adapter->DhclientInfo.client->state = S_INIT;
57  state_reboot(&Adapter->DhclientInfo);
58 
61  }
62 
63  ApiUnlock();
64 
65  return Send( &Reply );
66 }
void state_reboot(void *ipp)
Definition: dhclient.c:180
Definition: dhcpd.h:172
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:679
void got_one(struct protocol *l)
Definition: dispatch.c:195
void remove_protocol(struct protocol *proto)
Definition: dispatch.c:360
smooth NULL
Definition: ftsmooth.c:416
struct protocol * find_protocol_by_adapter(struct interface_info *info)
Definition: dispatch.c:413
void add_protocol(char *name, int fd, void(*handler)(struct protocol *), void *local)
Definition: dispatch.c:343
PDHCP_ADAPTER AdapterFindIndex(unsigned int indx)
Definition: adapter.c:513
struct interface_info DhclientInfo
Definition: rosdhcp.h:71
VOID ApiUnlock()
Definition: api.c:26
HANDLE AdapterStateChangedEvent
Definition: dispatch.c:51
VOID ApiLock()
Definition: api.c:22

◆ DSQueryHWInfo()

DWORD DSQueryHWInfo ( PipeSendFunc  Send,
COMM_DHCP_REQ Req 
)

Definition at line 68 of file api.c.

Referenced by PipeThreadProc().

68  {
69  COMM_DHCP_REPLY Reply;
70  PDHCP_ADAPTER Adapter;
71 
72  ApiLock();
73 
74  Adapter = AdapterFindIndex( Req->AdapterIndex );
75 
76  Reply.Reply = Adapter ? 1 : 0;
77 
78  if (Adapter) {
79  Reply.QueryHWInfo.AdapterIndex = Req->AdapterIndex;
80  Reply.QueryHWInfo.MediaType = Adapter->IfMib.dwType;
81  Reply.QueryHWInfo.Mtu = Adapter->IfMib.dwMtu;
82  Reply.QueryHWInfo.Speed = Adapter->IfMib.dwSpeed;
83  }
84 
85  ApiUnlock();
86 
87  return Send( &Reply );
88 }
MIB_IFROW IfMib
Definition: rosdhcp.h:66
DWORD dwType
Definition: ifmib.h:39
DWORD dwSpeed
Definition: ifmib.h:41
struct _COMM_DHCP_REPLY::@3288 QueryHWInfo
PDHCP_ADAPTER AdapterFindIndex(unsigned int indx)
Definition: adapter.c:513
VOID ApiUnlock()
Definition: api.c:26
DWORD dwMtu
Definition: ifmib.h:40
VOID ApiLock()
Definition: api.c:22

◆ DSReleaseIpAddressLease()

DWORD DSReleaseIpAddressLease ( PipeSendFunc  Send,
COMM_DHCP_REQ Req 
)

Definition at line 90 of file api.c.

Referenced by PipeThreadProc().

90  {
91  COMM_DHCP_REPLY Reply;
92  PDHCP_ADAPTER Adapter;
93  struct protocol* proto;
94 
95  ApiLock();
96 
97  Adapter = AdapterFindIndex( Req->AdapterIndex );
98 
99  Reply.Reply = Adapter ? 1 : 0;
100 
101  if( Adapter ) {
102  if (Adapter->NteContext)
103  {
104  DeleteIPAddress( Adapter->NteContext );
105  Adapter->NteContext = 0;
106  }
107  if (Adapter->RouterMib.dwForwardNextHop)
108  {
109  DeleteIpForwardEntry( &Adapter->RouterMib );
110  Adapter->RouterMib.dwForwardNextHop = 0;
111  }
112 
113  proto = find_protocol_by_adapter( &Adapter->DhclientInfo );
114  if (proto)
115  remove_protocol(proto);
116 
117  Adapter->DhclientInfo.client->active = NULL;
118  Adapter->DhclientInfo.client->state = S_INIT;
119 
122  }
123 
124  ApiUnlock();
125 
126  return Send( &Reply );
127 }
DWORD WINAPI DeleteIpForwardEntry(PMIB_IPFORWARDROW pRoute)
ULONG NteContext
Definition: rosdhcp.h:70
Definition: dhcpd.h:172
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:679
void remove_protocol(struct protocol *proto)
Definition: dispatch.c:360
smooth NULL
Definition: ftsmooth.c:416
MIB_IPFORWARDROW RouterMib
Definition: rosdhcp.h:67
struct protocol * find_protocol_by_adapter(struct interface_info *info)
Definition: dispatch.c:413
DWORD dwForwardNextHop
Definition: ipmib.h:74
PDHCP_ADAPTER AdapterFindIndex(unsigned int indx)
Definition: adapter.c:513
struct interface_info DhclientInfo
Definition: rosdhcp.h:71
DWORD WINAPI DeleteIPAddress(ULONG NTEContext)
VOID ApiUnlock()
Definition: api.c:26
HANDLE AdapterStateChangedEvent
Definition: dispatch.c:51
VOID ApiLock()
Definition: api.c:22

◆ DSRenewIpAddressLease()

DWORD DSRenewIpAddressLease ( PipeSendFunc  Send,
COMM_DHCP_REQ Req 
)

Definition at line 129 of file api.c.

Referenced by PipeThreadProc().

129  {
130  COMM_DHCP_REPLY Reply;
131  PDHCP_ADAPTER Adapter;
132  struct protocol* proto;
133 
134  ApiLock();
135 
136  Adapter = AdapterFindIndex( Req->AdapterIndex );
137 
138  if( !Adapter || Adapter->DhclientState.state == S_STATIC ) {
139  Reply.Reply = 0;
140  ApiUnlock();
141  return Send( &Reply );
142  }
143 
144  Reply.Reply = 1;
145 
146  proto = find_protocol_by_adapter( &Adapter->DhclientInfo );
147  if (proto)
148  remove_protocol(proto);
149 
150  add_protocol( Adapter->DhclientInfo.name,
151  Adapter->DhclientInfo.rfdesc, got_one,
152  &Adapter->DhclientInfo );
153 
154  Adapter->DhclientInfo.client->state = S_INIT;
155  state_reboot(&Adapter->DhclientInfo);
156 
159 
160  ApiUnlock();
161 
162  return Send( &Reply );
163 }
void state_reboot(void *ipp)
Definition: dhclient.c:180
Definition: dhcpd.h:172
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:679
void got_one(struct protocol *l)
Definition: dispatch.c:195
void remove_protocol(struct protocol *proto)
Definition: dispatch.c:360
smooth NULL
Definition: ftsmooth.c:416
struct protocol * find_protocol_by_adapter(struct interface_info *info)
Definition: dispatch.c:413
void add_protocol(char *name, int fd, void(*handler)(struct protocol *), void *local)
Definition: dispatch.c:343
PDHCP_ADAPTER AdapterFindIndex(unsigned int indx)
Definition: adapter.c:513
struct interface_info DhclientInfo
Definition: rosdhcp.h:71
struct client_state DhclientState
Definition: rosdhcp.h:72
VOID ApiUnlock()
Definition: api.c:26
HANDLE AdapterStateChangedEvent
Definition: dispatch.c:51
VOID ApiLock()
Definition: api.c:22

◆ DSStaticRefreshParams()

DWORD DSStaticRefreshParams ( PipeSendFunc  Send,
COMM_DHCP_REQ Req 
)

Definition at line 165 of file api.c.

Referenced by PipeThreadProc().

165  {
167  COMM_DHCP_REPLY Reply;
168  PDHCP_ADAPTER Adapter;
169  struct protocol* proto;
170 
171  ApiLock();
172 
173  Adapter = AdapterFindIndex( Req->AdapterIndex );
174 
175  Reply.Reply = Adapter ? 1 : 0;
176 
177  if( Adapter ) {
178  if (Adapter->NteContext)
179  {
180  DeleteIPAddress( Adapter->NteContext );
181  Adapter->NteContext = 0;
182  }
183  if (Adapter->RouterMib.dwForwardNextHop)
184  {
185  DeleteIpForwardEntry( &Adapter->RouterMib );
186  Adapter->RouterMib.dwForwardNextHop = 0;
187  }
188 
189  Adapter->DhclientState.state = S_STATIC;
190  proto = find_protocol_by_adapter( &Adapter->DhclientInfo );
191  if (proto)
192  remove_protocol(proto);
193  Status = AddIPAddress( Req->Body.StaticRefreshParams.IPAddress,
194  Req->Body.StaticRefreshParams.Netmask,
195  Req->AdapterIndex,
196  &Adapter->NteContext,
197  &Adapter->NteInstance );
198  Reply.Reply = NT_SUCCESS(Status);
199 
202  }
203 
204  ApiUnlock();
205 
206  return Send( &Reply );
207 }
ULONG NteInstance
Definition: rosdhcp.h:70
DWORD WINAPI DeleteIpForwardEntry(PMIB_IPFORWARDROW pRoute)
ULONG NteContext
Definition: rosdhcp.h:70
LONG NTSTATUS
Definition: precomp.h:26
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:679
union _COMM_DHCP_REQ::@3283 Body
void remove_protocol(struct protocol *proto)
Definition: dispatch.c:360
smooth NULL
Definition: ftsmooth.c:416
MIB_IPFORWARDROW RouterMib
Definition: rosdhcp.h:67
struct protocol * find_protocol_by_adapter(struct interface_info *info)
Definition: dispatch.c:413
DWORD WINAPI AddIPAddress(IPAddr Address, IPMask Netmask, DWORD IfIndex, PULONG NteContext, PULONG NteInstance)
Definition: iphlpapi_main.c:71
DWORD dwForwardNextHop
Definition: ipmib.h:74
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
PDHCP_ADAPTER AdapterFindIndex(unsigned int indx)
Definition: adapter.c:513
struct interface_info DhclientInfo
Definition: rosdhcp.h:71
struct client_state DhclientState
Definition: rosdhcp.h:72
Status
Definition: gdiplustypes.h:24
DWORD WINAPI DeleteIPAddress(ULONG NTEContext)
VOID ApiUnlock()
Definition: api.c:26
HANDLE AdapterStateChangedEvent
Definition: dispatch.c:51
struct _COMM_DHCP_REQ::@3283::@3287 StaticRefreshParams
VOID ApiLock()
Definition: api.c:22

Variable Documentation

◆ AdapterStateChangedEvent

HANDLE AdapterStateChangedEvent

Definition at line 51 of file dispatch.c.

Referenced by AdapterDiscoveryThread().

◆ ApiCriticalSection

CRITICAL_SECTION ApiCriticalSection
static

Definition at line 14 of file api.c.