3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: subsys/system/dhcp/pipe.c
6 * PURPOSE: DHCP client pipe
13 #include <reactos/debug.h>
15 static HANDLE CommPipe
= INVALID_HANDLE_VALUE
, CommThread
;
18 #define COMM_PIPE_OUTPUT_BUFFER sizeof(COMM_DHCP_REQ)
19 #define COMM_PIPE_INPUT_BUFFER sizeof(COMM_DHCP_REPLY)
20 #define COMM_PIPE_DEFAULT_TIMEOUT 1000
22 DWORD
PipeSend( COMM_DHCP_REPLY
*Reply
) {
30 return Success
? Written
: -1;
33 DWORD WINAPI
PipeThreadProc( LPVOID Parameter
) {
34 DWORD BytesRead
, BytesWritten
;
36 COMM_DHCP_REPLY Reply
;
37 BOOL Result
, Connected
;
40 Connected
= ConnectNamedPipe( CommPipe
, NULL
) ?
41 TRUE
: GetLastError() == ERROR_PIPE_CONNECTED
;
44 DbgPrint("DHCP: Could not connect named pipe\n");
45 CloseHandle( CommPipe
);
46 CommPipe
= INVALID_HANDLE_VALUE
;
50 Result
= ReadFile( CommPipe
, &Req
, sizeof(Req
), &BytesRead
, NULL
);
53 case DhcpReqQueryHWInfo
:
54 BytesWritten
= DSQueryHWInfo( PipeSend
, &Req
);
57 case DhcpReqLeaseIpAddress
:
58 BytesWritten
= DSLeaseIpAddress( PipeSend
, &Req
);
61 case DhcpReqReleaseIpAddress
:
62 BytesWritten
= DSReleaseIpAddressLease( PipeSend
, &Req
);
65 case DhcpReqRenewIpAddress
:
66 BytesWritten
= DSRenewIpAddressLease( PipeSend
, &Req
);
69 case DhcpReqStaticRefreshParams
:
70 BytesWritten
= DSStaticRefreshParams( PipeSend
, &Req
);
73 case DhcpReqGetAdapterInfo
:
74 BytesWritten
= DSGetAdapterInfo( PipeSend
, &Req
);
78 DPRINT1("Unrecognized request type %d\n", Req
.Type
);
79 ZeroMemory( &Reply
, sizeof( COMM_DHCP_REPLY
) );
81 BytesWritten
= PipeSend( &Reply
);
85 DisconnectNamedPipe( CommPipe
);
92 CommPipe
= CreateNamedPipeW
94 PIPE_ACCESS_DUPLEX
| FILE_FLAG_FIRST_PIPE_INSTANCE
,
95 PIPE_TYPE_MESSAGE
| PIPE_READMODE_MESSAGE
| PIPE_WAIT
,
97 COMM_PIPE_OUTPUT_BUFFER
,
98 COMM_PIPE_INPUT_BUFFER
,
99 COMM_PIPE_DEFAULT_TIMEOUT
,
102 if( CommPipe
== INVALID_HANDLE_VALUE
) {
103 DbgPrint("DHCP: Could not create named pipe\n");
107 CommThread
= CreateThread( NULL
, 0, PipeThreadProc
, NULL
, 0, &CommThrId
);
110 CloseHandle( CommPipe
);
111 CommPipe
= INVALID_HANDLE_VALUE
;
118 CloseHandle( CommPipe
);
119 CommPipe
= INVALID_HANDLE_VALUE
;