Implemented many of the ComXX exports.
[reactos.git] / reactos / lib / kernel32 / misc / comm.c
1 /* $Id: comm.c,v 1.5 2002/10/03 18:26:53 robd Exp $
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: lib/kernel32/misc/comm.c
6 * PURPOSE: Comm functions
7 * PROGRAMMER: Ariadne ( ariadne@xs4all.nl)
8 * modified from WINE [ Onno Hovers, (onno@stack.urc.tue.nl) ]
9 * Robert Dickenson (robd@mok.lvcom.com)
10 * UPDATE HISTORY:
11 * Created 01/11/98
12 * RDD (30/09/2002) implemented many function bodies to call serial driver.
13 */
14
15 #include <ddk/ntddk.h>
16 #include <ddk/ntddser.h>
17 #include <kernel32/proc.h>
18 #include <kernel32/thread.h>
19 #include <wchar.h>
20 #include <string.h>
21
22 //#define NDEBUG
23 #define DBG
24 #include <kernel32/kernel32.h>
25 #include <kernel32/error.h>
26
27
28 WINBOOL
29 STDCALL
30 BuildCommDCBA(LPCSTR lpDef, LPDCB lpDCB)
31 {
32 if (lpDCB == NULL) {
33 DPRINT("ERROR: BuildCommDCBA() - NULL DCB pointer\n");
34 return FALSE;
35 }
36 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
37 return FALSE;
38 }
39
40 WINBOOL
41 STDCALL
42 BuildCommDCBW(LPCWSTR lpDef, LPDCB lpDCB)
43 {
44 if (lpDCB == NULL) {
45 DPRINT("ERROR: BuildCommDCBW() - NULL DCB pointer\n");
46 return FALSE;
47 }
48 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
49 return FALSE;
50 }
51
52 WINBOOL
53 STDCALL
54 BuildCommDCBAndTimeoutsA(LPCSTR lpDef, LPDCB lpDCB, LPCOMMTIMEOUTS lpCommTimeouts)
55 {
56 if (lpDCB == NULL) {
57 DPRINT("ERROR: BuildCommDCBAndTimeoutsA() - NULL DCB pointer\n");
58 return FALSE;
59 }
60 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
61 return FALSE;
62 }
63
64 WINBOOL
65 STDCALL
66 BuildCommDCBAndTimeoutsW(LPCWSTR lpDef, LPDCB lpDCB, LPCOMMTIMEOUTS lpCommTimeouts)
67 {
68 if (lpDCB == NULL) {
69 DPRINT("ERROR: BuildCommDCBAndTimeoutsW() - NULL DCB pointer\n");
70 return FALSE;
71 }
72 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
73 return FALSE;
74 }
75
76 WINBOOL
77 STDCALL
78 ClearCommBreak(HANDLE hFile)
79 {
80 WINBOOL result = FALSE;
81 DWORD dwBytesReturned;
82
83 if (hFile == INVALID_HANDLE_VALUE) {
84 return FALSE;
85 }
86 result = DeviceIoControl(hFile, IOCTL_SERIAL_SET_BREAK_OFF, NULL, 0, NULL, 0, &dwBytesReturned, NULL);
87 return TRUE;
88 }
89
90 WINBOOL
91 STDCALL
92 ClearCommError(HANDLE hFile, LPDWORD lpErrors, LPCOMSTAT lpStat)
93 {
94 WINBOOL result = FALSE;
95 DWORD dwBytesReturned;
96
97 if (hFile == INVALID_HANDLE_VALUE) {
98 //SetLastError(CE_MODE);
99 return FALSE;
100 }
101 if (lpErrors == NULL) {
102 DPRINT("ERROR: GetCommState() - NULL Errors pointer\n");
103 return FALSE;
104 }
105 // *lpErrors = CE_BREAK;
106 // *lpErrors = CE_FRAME;
107 // *lpErrors = CE_IOE;
108 // *lpErrors = CE_MODE;
109 // *lpErrors = CE_OVERRUN;
110 // *lpErrors = CE_RXOVER;
111 // *lpErrors = CE_RXPARITY;
112 // *lpErrors = CE_TXFULL;
113 /*
114 CE_BREAK The hardware detected a break condition.
115 CE_FRAME The hardware detected a framing error.
116 CE_IOE An I/O error occurred during communications with the device.
117 CE_MODE The requested mode is not supported, or the hFile parameter is invalid. If this value is specified, it is the only valid error.
118 CE_OVERRUN A character-buffer overrun has occurred. The next character is lost.
119 CE_RXOVER An input buffer overflow has occurred. There is either no room in the input buffer, or a character was received after the end-of-file (EOF) character.
120 CE_RXPARITY The hardware detected a parity error.
121 CE_TXFULL The application tried to transmit a character, but the output buffer was full.
122 */
123 result = DeviceIoControl(hFile, IOCTL_SERIAL_RESET_DEVICE, NULL, 0, NULL, 0, &dwBytesReturned, NULL);
124
125 if (lpStat != NULL) {
126 lpStat->fCtsHold = 0;
127 lpStat->fDsrHold = 0;
128 lpStat->fRlsdHold = 0;
129 lpStat->fXoffHold = 0;
130 lpStat->fXoffSent = 0;
131 lpStat->fEof = 0;
132 lpStat->fTxim = 0;
133 lpStat->cbInQue = 0;
134 lpStat->cbOutQue = 0;
135 }
136 return TRUE;
137 }
138
139 WINBOOL
140 STDCALL
141 CommConfigDialogA(LPCSTR lpszName, HWND hWnd, LPCOMMCONFIG lpCC)
142 {
143 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
144 return FALSE;
145 }
146
147 WINBOOL
148 STDCALL
149 CommConfigDialogW(LPCWSTR lpszName, HWND hWnd, LPCOMMCONFIG lpCC)
150 {
151 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
152 return FALSE;
153 }
154
155 WINBOOL
156 STDCALL
157 EscapeCommFunction(HANDLE hFile, DWORD dwFunc)
158 {
159 WINBOOL result = FALSE;
160 DWORD dwBytesReturned;
161
162 if (hFile == INVALID_HANDLE_VALUE) {
163 return FALSE;
164 }
165 switch (dwFunc) {
166 case CLRDTR: // Clears the DTR (data-terminal-ready) signal.
167 result = DeviceIoControl(hFile, IOCTL_SERIAL_CLR_DTR, NULL, 0, NULL, 0, &dwBytesReturned, NULL);
168 break;
169 case CLRRTS: // Clears the RTS (request-to-send) signal.
170 result = DeviceIoControl(hFile, IOCTL_SERIAL_CLR_RTS, NULL, 0, NULL, 0, &dwBytesReturned, NULL);
171 break;
172 case SETDTR: // Sends the DTR (data-terminal-ready) signal.
173 result = DeviceIoControl(hFile, IOCTL_SERIAL_SET_DTR, NULL, 0, NULL, 0, &dwBytesReturned, NULL);
174 break;
175 case SETRTS: // Sends the RTS (request-to-send) signal.
176 result = DeviceIoControl(hFile, IOCTL_SERIAL_SET_RTS, NULL, 0, NULL, 0, &dwBytesReturned, NULL);
177 break;
178 case SETXOFF: // Causes transmission to act as if an XOFF character has been received.
179 result = DeviceIoControl(hFile, IOCTL_SERIAL_SET_XOFF, NULL, 0, NULL, 0, &dwBytesReturned, NULL);
180 break;
181 case SETXON: // Causes transmission to act as if an XON character has been received.
182 result = DeviceIoControl(hFile, IOCTL_SERIAL_SET_XON, NULL, 0, NULL, 0, &dwBytesReturned, NULL);
183 break;
184 case SETBREAK: // Suspends character transmission and places the transmission line in a break state until the ClearCommBreak function is called (or EscapeCommFunction is called with the CLRBREAK extended function code). The SETBREAK extended function code is identical to the SetCommBreak function. Note that this extended function does not flush data that has not been transmitted.
185 result = DeviceIoControl(hFile, IOCTL_SERIAL_SET_BREAK_ON, NULL, 0, NULL, 0, &dwBytesReturned, NULL);
186 break;
187 case CLRBREAK: // Restores character transmission and places the transmission line in a nonbreak state. The CLRBREAK extended function code is identical to the ClearCommBreak function.
188 result = DeviceIoControl(hFile, IOCTL_SERIAL_SET_BREAK_OFF, NULL, 0, NULL, 0, &dwBytesReturned, NULL);
189 break;
190 default:
191 DPRINT("EscapeCommFunction() WARNING: unknown function code\n");
192 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
193 break;
194 }
195 return TRUE;
196 }
197
198 WINBOOL
199 STDCALL
200 GetCommConfig(HANDLE hCommDev, LPCOMMCONFIG lpCC, LPDWORD lpdwSize)
201 {
202 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
203 return FALSE;
204 }
205
206 WINBOOL
207 STDCALL
208 GetCommMask(HANDLE hFile, LPDWORD lpEvtMask)
209 {
210 WINBOOL result = FALSE;
211 DWORD dwBytesReturned;
212
213 if (hFile == INVALID_HANDLE_VALUE) {
214 return FALSE;
215 }
216 result = DeviceIoControl(hFile, IOCTL_SERIAL_GET_WAIT_MASK,
217 NULL, 0, lpEvtMask, sizeof(DWORD), &dwBytesReturned, NULL);
218 return TRUE;
219 }
220
221 WINBOOL
222 STDCALL
223 GetCommModemStatus(HANDLE hFile, LPDWORD lpModemStat)
224 {
225 WINBOOL result = FALSE;
226 DWORD dwBytesReturned;
227
228 if (hFile == INVALID_HANDLE_VALUE) {
229 return FALSE;
230 }
231 result = DeviceIoControl(hFile, IOCTL_SERIAL_GET_MODEMSTATUS,
232 NULL, 0, lpModemStat, sizeof(DWORD), &dwBytesReturned, NULL);
233 return TRUE;
234 }
235
236 WINBOOL
237 STDCALL
238 GetCommProperties(HANDLE hFile, LPCOMMPROP lpCommProp)
239 {
240 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
241 return FALSE;
242 }
243
244 WINBOOL
245 STDCALL
246 GetCommState(HANDLE hFile, LPDCB lpDCB)
247 {
248 WINBOOL result = FALSE;
249 DWORD dwBytesReturned;
250
251 SERIAL_BAUD_RATE BaudRate;
252 SERIAL_HANDFLOW HandFlow;
253 SERIAL_CHARS SpecialChars;
254 SERIAL_LINE_CONTROL LineControl;
255
256 DPRINT("GetCommState(%d, %p)\n", hFile, lpDCB);
257
258 if (hFile == INVALID_HANDLE_VALUE) {
259 DPRINT("ERROR: GetCommState() - INVALID_HANDLE_VALUE\n");
260 return FALSE;
261 }
262 if (lpDCB == NULL) {
263 DPRINT("ERROR: GetCommState() - NULL DCB pointer\n");
264 return FALSE;
265 }
266 if (lpDCB->DCBlength != sizeof(DCB)) {
267 DPRINT("ERROR: GetCommState() - Invalid DCB size\n");
268 return FALSE;
269 }
270
271 // DPRINT(" GetCommState() CALLING DeviceIoControl\n");
272 // result = DeviceIoControl(hFile, IOCTL_SERIAL_GET_COMMSTATUS, NULL, 0, NULL, 0, &dwBytesReturned, NULL);
273 // DPRINT(" GetCommState() DeviceIoControl returned %d\n", result);
274
275 result = DeviceIoControl(hFile, IOCTL_SERIAL_GET_BAUD_RATE,
276 NULL, 0, &BaudRate, sizeof(BaudRate),&dwBytesReturned, NULL);
277 if (!NT_SUCCESS(result)) {
278 DPRINT("ERROR: GetCommState() - DeviceIoControl(IOCTL_SERIAL_GET_BAUD_RATE) Failed.\n");
279 return FALSE;
280 }
281 lpDCB->BaudRate = BaudRate.BaudRate;
282
283 result = DeviceIoControl(hFile, IOCTL_SERIAL_GET_HANDFLOW,
284 NULL, 0, &HandFlow, sizeof(HandFlow), &dwBytesReturned, NULL);
285 if (!NT_SUCCESS(result)) {
286 DPRINT("ERROR: GetCommState() - DeviceIoControl(IOCTL_SERIAL_GET_HANDFLOW) Failed.\n");
287 return FALSE;
288 }
289 if (HandFlow.ControlHandShake & SERIAL_CTS_HANDSHAKE) {
290 lpDCB->fOutxCtsFlow = 1;
291 }
292 if (HandFlow.ControlHandShake & SERIAL_DSR_HANDSHAKE) {
293 lpDCB->fOutxDsrFlow = 1;
294 }
295 if (HandFlow.ControlHandShake & SERIAL_DTR_CONTROL) {
296 lpDCB->fDtrControl = 1;
297 }
298 if (HandFlow.ControlHandShake & SERIAL_DTR_HANDSHAKE) {
299 lpDCB->fDtrControl = 2;
300 }
301 if (HandFlow.ControlHandShake & SERIAL_RTS_CONTROL) {
302 lpDCB->fRtsControl = 1;
303 }
304 if (HandFlow.ControlHandShake & SERIAL_RTS_HANDSHAKE) {
305 lpDCB->fRtsControl = 2;
306 }
307 if (HandFlow.ControlHandShake & SERIAL_DSR_SENSITIVITY) {
308 lpDCB->fDsrSensitivity = 1;
309 }
310 if (HandFlow.ControlHandShake & SERIAL_ERROR_ABORT) {
311 lpDCB->fAbortOnError = 1;
312 }
313
314 if (HandFlow.FlowReplace & SERIAL_ERROR_CHAR) {
315 lpDCB->fErrorChar = 1;
316 }
317 if (HandFlow.FlowReplace & SERIAL_NULL_STRIPPING) {
318 lpDCB->fNull = 1;
319 }
320 if (HandFlow.FlowReplace & SERIAL_XOFF_CONTINUE) {
321 lpDCB->fTXContinueOnXoff = 1;
322 }
323 lpDCB->XonLim = HandFlow.XonLimit;
324 lpDCB->XoffLim = HandFlow.XoffLimit;
325
326 result = DeviceIoControl(hFile, IOCTL_SERIAL_GET_CHARS,
327 NULL, 0, &SpecialChars, sizeof(SpecialChars), &dwBytesReturned, NULL);
328 if (!NT_SUCCESS(result)) {
329 DPRINT("ERROR: GetCommState() - DeviceIoControl(IOCTL_SERIAL_GET_CHARS) Failed.\n");
330 return FALSE;
331 }
332
333 lpDCB->EofChar = SpecialChars.EofChar;
334 lpDCB->ErrorChar = SpecialChars.ErrorChar;
335 // = SpecialChars.BreakChar;
336 lpDCB->EvtChar = SpecialChars.EventChar;
337 lpDCB->XonChar = SpecialChars.XonChar;
338 lpDCB->XoffChar = SpecialChars.XoffChar;
339
340 result = DeviceIoControl(hFile, IOCTL_SERIAL_GET_LINE_CONTROL,
341 NULL, 0, &LineControl, sizeof(LineControl), &dwBytesReturned, NULL);
342 if (!NT_SUCCESS(result)) {
343 DPRINT("ERROR: GetCommState() - DeviceIoControl(IOCTL_SERIAL_GET_LINE_CONTROL) Failed.\n");
344 return FALSE;
345 }
346 lpDCB->StopBits = LineControl.StopBits;
347 lpDCB->Parity = LineControl.Parity;
348 lpDCB->ByteSize = LineControl.WordLength;
349 DPRINT("GetCommState() - COMPLETED SUCCESSFULLY\n");
350 return TRUE;
351 }
352
353 WINBOOL
354 STDCALL
355 GetCommTimeouts(HANDLE hFile, LPCOMMTIMEOUTS lpCommTimeouts)
356 {
357 WINBOOL result = FALSE;
358 DWORD dwBytesReturned;
359
360 if (hFile == INVALID_HANDLE_VALUE) {
361 return FALSE;
362 }
363 if (lpCommTimeouts == NULL) {
364 return FALSE;
365 }
366 result = DeviceIoControl(hFile, IOCTL_SERIAL_GET_TIMEOUTS,
367 NULL, 0,
368 lpCommTimeouts, sizeof(COMMTIMEOUTS),
369 &dwBytesReturned, NULL);
370 return TRUE;
371 }
372
373 WINBOOL
374 STDCALL
375 GetDefaultCommConfigW(LPCWSTR lpszName, LPCOMMCONFIG lpCC, LPDWORD lpdwSize)
376 {
377 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
378 return FALSE;
379 }
380
381 WINBOOL
382 STDCALL
383 GetDefaultCommConfigA(LPCSTR lpszName, LPCOMMCONFIG lpCC, LPDWORD lpdwSize)
384 {
385 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
386 return FALSE;
387 }
388
389 WINBOOL
390 STDCALL
391 PurgeComm(HANDLE hFile, DWORD dwFlags)
392 {
393 WINBOOL result = FALSE;
394 DWORD dwBytesReturned;
395
396 if (hFile == INVALID_HANDLE_VALUE) {
397 return FALSE;
398 }
399 result = DeviceIoControl(hFile, IOCTL_SERIAL_PURGE,
400 &dwFlags, sizeof(DWORD), NULL, 0, &dwBytesReturned, NULL);
401 return TRUE;
402 }
403
404 WINBOOL
405 STDCALL
406 SetCommBreak(HANDLE hFile)
407 {
408 WINBOOL result = FALSE;
409 DWORD dwBytesReturned;
410
411 if (hFile == INVALID_HANDLE_VALUE) {
412 return FALSE;
413 }
414 result = DeviceIoControl(hFile, IOCTL_SERIAL_SET_BREAK_ON, NULL, 0, NULL, 0, &dwBytesReturned, NULL);
415 return TRUE;
416 }
417
418 WINBOOL
419 STDCALL
420 SetCommConfig(HANDLE hCommDev, LPCOMMCONFIG lpCC, DWORD dwSize)
421 {
422 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
423 return FALSE;
424 }
425
426 WINBOOL
427 STDCALL
428 SetCommMask(HANDLE hFile, DWORD dwEvtMask)
429 {
430 WINBOOL result = FALSE;
431 DWORD dwBytesReturned;
432
433 if (hFile == INVALID_HANDLE_VALUE) {
434 return FALSE;
435 }
436 result = DeviceIoControl(hFile, IOCTL_SERIAL_SET_WAIT_MASK,
437 &dwEvtMask, sizeof(DWORD), NULL, 0, &dwBytesReturned, NULL);
438 return TRUE;
439 }
440
441 WINBOOL
442 STDCALL
443 SetCommState(HANDLE hFile, LPDCB lpDCB)
444 {
445 WINBOOL result = FALSE;
446 DWORD dwBytesReturned;
447
448 SERIAL_BAUD_RATE BaudRate;
449 SERIAL_HANDFLOW HandFlow;
450 SERIAL_CHARS SpecialChars;
451 SERIAL_LINE_CONTROL LineControl;
452
453 DPRINT("SetCommState(%d, %p) - ENTERED\n", hFile, lpDCB);
454
455 if (hFile == INVALID_HANDLE_VALUE) {
456 DPRINT("SetCommState() - ERROR: INVALID_HANDLE_VALUE\n");
457 return FALSE;
458 }
459 if (lpDCB == NULL) {
460 DPRINT("SetCommState() - ERROR: NULL DCB pointer passed\n");
461 return FALSE;
462 }
463
464 BaudRate.BaudRate = lpDCB->BaudRate;
465 result = DeviceIoControl(hFile, IOCTL_SERIAL_SET_BAUD_RATE,
466 &BaudRate, sizeof(BaudRate), NULL, 0, &dwBytesReturned, NULL);
467 if (!NT_SUCCESS(result)) {
468 DPRINT("ERROR: SetCommState() - DeviceIoControl(IOCTL_SERIAL_SET_BAUD_RATE) Failed.\n");
469 return FALSE;
470 }
471 /*
472 #define SERIAL_DTR_MASK ((ULONG)0x03)
473 #define SERIAL_DTR_CONTROL ((ULONG)0x01)
474 #define SERIAL_DTR_HANDSHAKE ((ULONG)0x02)
475 #define SERIAL_CTS_HANDSHAKE ((ULONG)0x08)
476 #define SERIAL_DSR_HANDSHAKE ((ULONG)0x10)
477 #define SERIAL_DCD_HANDSHAKE ((ULONG)0x20)
478 #define SERIAL_OUT_HANDSHAKEMASK ((ULONG)0x38)
479 #define SERIAL_DSR_SENSITIVITY ((ULONG)0x40)
480 #define SERIAL_ERROR_ABORT ((ULONG)0x80000000)
481 #define SERIAL_CONTROL_INVALID ((ULONG)0x7fffff84)
482 */
483 HandFlow.ControlHandShake = 0;
484
485 if (lpDCB->fOutxCtsFlow) {
486 HandFlow.ControlHandShake |= SERIAL_CTS_HANDSHAKE;
487 }
488 if (lpDCB->fOutxDsrFlow) {
489 HandFlow.ControlHandShake |= SERIAL_DSR_HANDSHAKE;
490 }
491 if (lpDCB->fDtrControl) {
492 HandFlow.ControlHandShake |= SERIAL_DTR_CONTROL;
493 }
494 if (lpDCB->fDtrControl) {
495 HandFlow.ControlHandShake |= SERIAL_DTR_HANDSHAKE;
496 }
497 if (lpDCB->fRtsControl) {
498 HandFlow.ControlHandShake |= SERIAL_RTS_CONTROL;
499 }
500 if (lpDCB->fRtsControl) {
501 HandFlow.ControlHandShake |= SERIAL_RTS_HANDSHAKE;
502 }
503 if (lpDCB->fDsrSensitivity) {
504 HandFlow.ControlHandShake |= SERIAL_DSR_SENSITIVITY;
505 }
506 if (lpDCB->fAbortOnError) {
507 HandFlow.ControlHandShake |= SERIAL_ERROR_ABORT;
508 }
509 /*
510 #define SERIAL_AUTO_TRANSMIT ((ULONG)0x01)
511 #define SERIAL_AUTO_RECEIVE ((ULONG)0x02)
512 #define SERIAL_ERROR_CHAR ((ULONG)0x04)
513 #define SERIAL_NULL_STRIPPING ((ULONG)0x08)
514 #define SERIAL_BREAK_CHAR ((ULONG)0x10)
515 #define SERIAL_RTS_MASK ((ULONG)0xc0)
516 #define SERIAL_RTS_CONTROL ((ULONG)0x40)
517 #define SERIAL_RTS_HANDSHAKE ((ULONG)0x80)
518 #define SERIAL_TRANSMIT_TOGGLE ((ULONG)0xc0)
519 #define SERIAL_XOFF_CONTINUE ((ULONG)0x80000000)
520 #define SERIAL_FLOW_INVALID ((ULONG)0x7fffff20)
521 */
522 HandFlow.FlowReplace = 0;
523 if (lpDCB->fErrorChar) {
524 HandFlow.FlowReplace |= SERIAL_ERROR_CHAR;
525 }
526 if (lpDCB->fNull) {
527 HandFlow.FlowReplace |= SERIAL_NULL_STRIPPING;
528 }
529 if (lpDCB->fTXContinueOnXoff) {
530 HandFlow.FlowReplace |= SERIAL_XOFF_CONTINUE;
531 }
532 HandFlow.XonLimit = lpDCB->XonLim;
533 HandFlow.XoffLimit = lpDCB->XoffLim;
534 result = DeviceIoControl(hFile, IOCTL_SERIAL_SET_HANDFLOW,
535 &HandFlow, sizeof(HandFlow), NULL, 0, &dwBytesReturned, NULL);
536 if (!NT_SUCCESS(result)) {
537 DPRINT("ERROR: SetCommState() - DeviceIoControl(IOCTL_SERIAL_SET_HANDFLOW) Failed.\n");
538 return FALSE;
539 }
540
541 SpecialChars.EofChar = lpDCB->EofChar;
542 SpecialChars.ErrorChar = lpDCB->ErrorChar;
543 SpecialChars.BreakChar = 0;
544 SpecialChars.EventChar = lpDCB->EvtChar;
545 SpecialChars.XonChar = lpDCB->XonChar;
546 SpecialChars.XoffChar = lpDCB->XoffChar;
547 result = DeviceIoControl(hFile, IOCTL_SERIAL_SET_CHARS,
548 &SpecialChars, sizeof(SpecialChars), NULL, 0, &dwBytesReturned, NULL);
549 if (!NT_SUCCESS(result)) {
550 DPRINT("ERROR: SetCommState() - DeviceIoControl(IOCTL_SERIAL_SET_CHARS) Failed.\n");
551 return FALSE;
552 }
553
554 LineControl.StopBits = lpDCB->StopBits;
555 LineControl.Parity = lpDCB->Parity;
556 LineControl.WordLength = lpDCB->ByteSize;
557 result = DeviceIoControl(hFile, IOCTL_SERIAL_SET_LINE_CONTROL,
558 &LineControl, sizeof(LineControl), NULL, 0, &dwBytesReturned, NULL);
559 if (!NT_SUCCESS(result)) {
560 DPRINT("ERROR: SetCommState() - DeviceIoControl(IOCTL_SERIAL_SET_LINE_CONTROL) Failed.\n");
561 return FALSE;
562 }
563
564 DPRINT("SetCommState() - COMPLETED SUCCESSFULLY\n");
565 return TRUE;
566 }
567
568 WINBOOL
569 STDCALL
570 SetCommTimeouts(HANDLE hFile, LPCOMMTIMEOUTS lpCommTimeouts)
571 {
572 WINBOOL result = FALSE;
573 DWORD dwBytesReturned;
574 SERIAL_TIMEOUTS Timeouts;
575
576 if (hFile == INVALID_HANDLE_VALUE) {
577 return FALSE;
578 }
579 if (lpCommTimeouts == NULL) {
580 return FALSE;
581 }
582 Timeouts.ReadIntervalTimeout = lpCommTimeouts->ReadIntervalTimeout;
583 Timeouts.ReadTotalTimeoutMultiplier = lpCommTimeouts->ReadTotalTimeoutMultiplier;
584 Timeouts.ReadTotalTimeoutConstant = lpCommTimeouts->ReadTotalTimeoutConstant;
585 Timeouts.WriteTotalTimeoutMultiplier = lpCommTimeouts->WriteTotalTimeoutMultiplier;
586 Timeouts.WriteTotalTimeoutConstant = lpCommTimeouts->WriteTotalTimeoutConstant;
587 result = DeviceIoControl(hFile, IOCTL_SERIAL_SET_TIMEOUTS,
588 &Timeouts, sizeof(Timeouts), NULL, 0, &dwBytesReturned, NULL);
589 return TRUE;
590 }
591
592 WINBOOL
593 STDCALL
594 SetDefaultCommConfigA(LPCSTR lpszName, LPCOMMCONFIG lpCC, DWORD dwSize)
595 {
596 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
597 return FALSE;
598 }
599
600 WINBOOL
601 STDCALL
602 SetDefaultCommConfigW(LPCWSTR lpszName, LPCOMMCONFIG lpCC, DWORD dwSize)
603 {
604 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
605 return FALSE;
606 }
607
608 WINBOOL
609 STDCALL
610 SetupComm(HANDLE hFile, DWORD dwInQueue, DWORD dwOutQueue)
611 {
612 WINBOOL result = FALSE;
613 DWORD dwBytesReturned;
614 SERIAL_QUEUE_SIZE QueueSize;
615
616 if (hFile == INVALID_HANDLE_VALUE) {
617 return FALSE;
618 }
619 QueueSize.InSize = dwInQueue;
620 QueueSize.OutSize = dwOutQueue;
621 result = DeviceIoControl(hFile, IOCTL_SERIAL_SET_QUEUE_SIZE,
622 &QueueSize, sizeof(QueueSize), NULL, 0, &dwBytesReturned, NULL);
623 return TRUE;
624 }
625
626 WINBOOL
627 STDCALL
628 TransmitCommChar(HANDLE hFile, char cChar)
629 {
630 WINBOOL result = FALSE;
631 DWORD dwBytesReturned;
632
633 if (hFile == INVALID_HANDLE_VALUE) {
634 return FALSE;
635 }
636 result = DeviceIoControl(hFile, IOCTL_SERIAL_IMMEDIATE_CHAR,
637 &cChar, sizeof(cChar), NULL, 0, &dwBytesReturned, NULL);
638 return TRUE;
639 }
640
641 WINBOOL
642 STDCALL
643 WaitCommEvent(HANDLE hFile, LPDWORD lpEvtMask, LPOVERLAPPED lpOverlapped)
644 {
645 WINBOOL result = FALSE;
646 DWORD dwBytesReturned;
647
648 if (hFile == INVALID_HANDLE_VALUE) {
649 return FALSE;
650 }
651 if (lpEvtMask == NULL) {
652 return FALSE;
653 }
654 result = DeviceIoControl(hFile, IOCTL_SERIAL_WAIT_ON_MASK,
655 NULL, 0, lpEvtMask, sizeof(DWORD), &dwBytesReturned, lpOverlapped);
656 return TRUE;
657 }
658
659 /* EOF */