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
14 static CRITICAL_SECTION ApiCriticalSection
;
17 InitializeCriticalSection( &ApiCriticalSection
);
21 EnterCriticalSection( &ApiCriticalSection
);
25 LeaveCriticalSection( &ApiCriticalSection
);
28 /* This represents the service portion of the DHCP client API */
30 DWORD
DSLeaseIpAddress( PipeSendFunc Send
, COMM_DHCP_REQ
*Req
) {
31 COMM_DHCP_REPLY Reply
;
32 PDHCP_ADAPTER Adapter
;
36 Adapter
= AdapterFindIndex( Req
->AdapterIndex
);
38 Reply
.Reply
= Adapter
? 1 : 0;
41 add_protocol( Adapter
->DhclientInfo
.name
,
42 Adapter
->DhclientInfo
.rfdesc
, got_one
,
43 &Adapter
->DhclientInfo
);
44 Adapter
->DhclientInfo
.client
->state
= S_INIT
;
45 state_reboot(&Adapter
->DhclientInfo
);
50 return Send( &Reply
);
53 DWORD
DSQueryHWInfo( PipeSendFunc Send
, COMM_DHCP_REQ
*Req
) {
54 COMM_DHCP_REPLY Reply
;
55 PDHCP_ADAPTER Adapter
;
59 Adapter
= AdapterFindIndex( Req
->AdapterIndex
);
61 Reply
.QueryHWInfo
.AdapterIndex
= Req
->AdapterIndex
;
62 Reply
.QueryHWInfo
.MediaType
= Adapter
->IfMib
.dwType
;
63 Reply
.QueryHWInfo
.Mtu
= Adapter
->IfMib
.dwMtu
;
64 Reply
.QueryHWInfo
.Speed
= Adapter
->IfMib
.dwSpeed
;
68 return Send( &Reply
);
71 DWORD
DSReleaseIpAddressLease( PipeSendFunc Send
, COMM_DHCP_REQ
*Req
) {
72 COMM_DHCP_REPLY Reply
;
73 PDHCP_ADAPTER Adapter
;
77 Adapter
= AdapterFindIndex( Req
->AdapterIndex
);
79 Reply
.Reply
= Adapter
? 1 : 0;
82 DeleteIPAddress( Adapter
->NteContext
);
83 remove_protocol( find_protocol_by_adapter( &Adapter
->DhclientInfo
) );
88 return Send( &Reply
);
91 DWORD
DSRenewIpAddressLease( PipeSendFunc Send
, COMM_DHCP_REQ
*Req
) {
92 COMM_DHCP_REPLY Reply
;
93 PDHCP_ADAPTER Adapter
;
97 Adapter
= AdapterFindIndex( Req
->AdapterIndex
);
99 Reply
.Reply
= Adapter
? 1 : 0;
101 if( !Adapter
|| Adapter
->DhclientState
.state
!= S_BOUND
) {
103 return Send( &Reply
);
106 Adapter
->DhclientState
.state
= S_BOUND
;
108 send_discover( &Adapter
->DhclientInfo
);
109 state_bound( &Adapter
->DhclientInfo
);
113 return Send( &Reply
);
116 DWORD
DSStaticRefreshParams( PipeSendFunc Send
, COMM_DHCP_REQ
*Req
) {
118 COMM_DHCP_REPLY Reply
;
119 PDHCP_ADAPTER Adapter
;
123 Adapter
= AdapterFindIndex( Req
->AdapterIndex
);
125 Reply
.Reply
= Adapter
? 1 : 0;
128 DeleteIPAddress( Adapter
->NteContext
);
129 Adapter
->DhclientState
.state
= S_STATIC
;
130 remove_protocol( find_protocol_by_adapter( &Adapter
->DhclientInfo
) );
131 Status
= AddIPAddress( Req
->Body
.StaticRefreshParams
.IPAddress
,
132 Req
->Body
.StaticRefreshParams
.Netmask
,
134 &Adapter
->NteContext
,
135 &Adapter
->NteInstance
);
136 Reply
.Reply
= NT_SUCCESS(Status
);
141 return Send( &Reply
);