3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: subsys/system/dhcp/api.c
6 * PURPOSE: DHCP client api handlers
15 #include <reactos/debug.h>
17 static CRITICAL_SECTION ApiCriticalSection
;
20 InitializeCriticalSection( &ApiCriticalSection
);
24 EnterCriticalSection( &ApiCriticalSection
);
28 LeaveCriticalSection( &ApiCriticalSection
);
31 /* This represents the service portion of the DHCP client API */
33 DWORD
DSLeaseIpAddress( PipeSendFunc Send
, COMM_DHCP_REQ
*Req
) {
34 COMM_DHCP_REPLY Reply
;
35 PDHCP_ADAPTER Adapter
;
39 Adapter
= AdapterFindIndex( Req
->AdapterIndex
);
41 Reply
.Reply
= Adapter
? 1 : 0;
44 add_protocol( Adapter
->DhclientInfo
.name
,
45 Adapter
->DhclientInfo
.rfdesc
, got_one
,
46 &Adapter
->DhclientInfo
);
47 Adapter
->DhclientInfo
.client
->state
= S_INIT
;
48 state_reboot(&Adapter
->DhclientInfo
);
53 return Send( &Reply
);
56 DWORD
DSQueryHWInfo( PipeSendFunc Send
, COMM_DHCP_REQ
*Req
) {
57 COMM_DHCP_REPLY Reply
;
58 PDHCP_ADAPTER Adapter
;
62 Adapter
= AdapterFindIndex( Req
->AdapterIndex
);
64 Reply
.Reply
= Adapter
? 1 : 0;
67 Reply
.QueryHWInfo
.AdapterIndex
= Req
->AdapterIndex
;
68 Reply
.QueryHWInfo
.MediaType
= Adapter
->IfMib
.dwType
;
69 Reply
.QueryHWInfo
.Mtu
= Adapter
->IfMib
.dwMtu
;
70 Reply
.QueryHWInfo
.Speed
= Adapter
->IfMib
.dwSpeed
;
75 return Send( &Reply
);
78 DWORD
DSReleaseIpAddressLease( PipeSendFunc Send
, COMM_DHCP_REQ
*Req
) {
79 COMM_DHCP_REPLY Reply
;
80 PDHCP_ADAPTER Adapter
;
81 struct protocol
* proto
;
85 Adapter
= AdapterFindIndex( Req
->AdapterIndex
);
87 Reply
.Reply
= Adapter
? 1 : 0;
90 if (Adapter
->NteContext
)
91 DeleteIPAddress( Adapter
->NteContext
);
93 proto
= find_protocol_by_adapter( &Adapter
->DhclientInfo
);
95 remove_protocol(proto
);
100 return Send( &Reply
);
103 DWORD
DSRenewIpAddressLease( PipeSendFunc Send
, COMM_DHCP_REQ
*Req
) {
104 COMM_DHCP_REPLY Reply
;
105 PDHCP_ADAPTER Adapter
;
109 Adapter
= AdapterFindIndex( Req
->AdapterIndex
);
111 if( !Adapter
|| Adapter
->DhclientState
.state
== S_STATIC
) {
114 return Send( &Reply
);
119 add_protocol( Adapter
->DhclientInfo
.name
,
120 Adapter
->DhclientInfo
.rfdesc
, got_one
,
121 &Adapter
->DhclientInfo
);
122 Adapter
->DhclientInfo
.client
->state
= S_INIT
;
123 state_reboot(&Adapter
->DhclientInfo
);
127 return Send( &Reply
);
130 DWORD
DSStaticRefreshParams( PipeSendFunc Send
, COMM_DHCP_REQ
*Req
) {
132 COMM_DHCP_REPLY Reply
;
133 PDHCP_ADAPTER Adapter
;
134 struct protocol
* proto
;
138 Adapter
= AdapterFindIndex( Req
->AdapterIndex
);
140 Reply
.Reply
= Adapter
? 1 : 0;
143 if (Adapter
->NteContext
)
144 DeleteIPAddress( Adapter
->NteContext
);
145 Adapter
->DhclientState
.state
= S_STATIC
;
146 proto
= find_protocol_by_adapter( &Adapter
->DhclientInfo
);
148 remove_protocol(proto
);
149 Status
= AddIPAddress( Req
->Body
.StaticRefreshParams
.IPAddress
,
150 Req
->Body
.StaticRefreshParams
.Netmask
,
152 &Adapter
->NteContext
,
153 &Adapter
->NteInstance
);
154 Reply
.Reply
= NT_SUCCESS(Status
);
159 return Send( &Reply
);
162 DWORD
DSGetAdapterInfo( PipeSendFunc Send
, COMM_DHCP_REQ
*Req
) {
163 COMM_DHCP_REPLY Reply
;
164 PDHCP_ADAPTER Adapter
;
168 Adapter
= AdapterFindIndex( Req
->AdapterIndex
);
170 Reply
.Reply
= Adapter
? 1 : 0;
173 Reply
.GetAdapterInfo
.DhcpEnabled
= (S_STATIC
!= Adapter
->DhclientState
.state
);
174 if (S_BOUND
== Adapter
->DhclientState
.state
) {
175 if (sizeof(Reply
.GetAdapterInfo
.DhcpServer
) ==
176 Adapter
->DhclientState
.active
->serveraddress
.len
) {
177 memcpy(&Reply
.GetAdapterInfo
.DhcpServer
,
178 Adapter
->DhclientState
.active
->serveraddress
.iabuf
,
179 Adapter
->DhclientState
.active
->serveraddress
.len
);
181 DPRINT1("Unexpected server address len %d\n",
182 Adapter
->DhclientState
.active
->serveraddress
.len
);
183 Reply
.GetAdapterInfo
.DhcpServer
= htonl(INADDR_NONE
);
185 Reply
.GetAdapterInfo
.LeaseObtained
= Adapter
->DhclientState
.active
->obtained
;
186 Reply
.GetAdapterInfo
.LeaseExpires
= Adapter
->DhclientState
.active
->expiry
;
188 Reply
.GetAdapterInfo
.DhcpServer
= htonl(INADDR_NONE
);
189 Reply
.GetAdapterInfo
.LeaseObtained
= 0;
190 Reply
.GetAdapterInfo
.LeaseExpires
= 0;
196 return Send( &Reply
);