2 * DEC 93 Erik Bos <erik@xs4all.nl>
4 * Copyright 1996 Marcus Meissner
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * Apr 3, 1999. Lawson Whitney <lawson_whitney@juno.com>
23 * - Fixed the modem control part of EscapeCommFunction16.
25 * Mar 31, 1999. Ove Kåven <ovek@arcticnet.no>
26 * - Implemented buffers and EnableCommNotification.
28 * Mar 3, 1999. Ove Kåven <ovek@arcticnet.no>
29 * - Use port indices instead of unixfds for win16
30 * - Moved things around (separated win16 and win32 routines)
31 * - Added some hints on how to implement buffers and EnableCommNotification.
33 * Oktober 98, Rein Klazes [RHK]
34 * A program that wants to monitor the modem status line (RLSD/DCD) may
35 * poll the modem status register in the commMask structure. I update the bit
36 * in GetCommError, waiting for an implementation of communication events.
38 * July 6, 1998. Fixes and comments by Valentijn Sessink
39 * <vsessink@ic.uva.nl> [V]
41 * August 12, 1997. Take a bash at SetCommEventMask - Lawson Whitney
42 * <lawson_whitney@juno.com>
44 * May 26, 1997. Fixes and comments by Rick Richardson <rick@dgii.com> [RER]
45 * - ptr->fd wasn't getting cleared on close.
46 * - GetCommEventMask() and GetCommError() didn't do much of anything.
47 * IMHO, they are still wrong, but they at least implement the RXCHAR
48 * event and return I/O queue sizes, which makes the app I'm interested
49 * in (analog devices EZKIT DSP development system) work.
53 #include "wine/port.h"
69 #ifdef HAVE_SYS_FILIO_H
70 # include <sys/filio.h>
72 #ifdef HAVE_SYS_IOCTL_H
73 #include <sys/ioctl.h>
78 #ifdef HAVE_SYS_POLL_H
79 # include <sys/poll.h>
81 #ifdef HAVE_SYS_MODEM_H
82 # include <sys/modem.h>
84 #ifdef HAVE_SYS_STRTIO_H
85 # include <sys/strtio.h>
88 #define NONAMELESSUNION
89 #define NONAMELESSSTRUCT
95 #include "wine/server.h"
100 #include "wine/debug.h"
102 #ifdef HAVE_LINUX_SERIAL_H
103 #include <linux/serial.h>
106 WINE_DEFAULT_DEBUG_CHANNEL(comm
);
108 /***********************************************************************
109 * Asynchronous I/O for asynchronous wait requests *
112 static DWORD
commio_get_async_count (const async_private
*ovp
);
113 static void commio_async_cleanup (async_private
*ovp
);
115 static async_ops commio_async_ops
=
117 commio_get_async_count
, /* get_count */
118 NULL
, /* call_completion */
119 commio_async_cleanup
/* cleanup */
122 typedef struct async_commio
124 struct async_private async
;
128 static DWORD
commio_get_async_count (const struct async_private
*ovp
)
133 static void commio_async_cleanup (async_private
*ovp
)
135 HeapFree(GetProcessHeap(), 0, ovp
);
138 /***********************************************************************/
140 #if !defined(TIOCINQ) && defined(FIONREAD)
141 #define TIOCINQ FIONREAD
144 static int COMM_WhackModem(int fd
, unsigned int andy
, unsigned int orrie
)
147 unsigned int mstat
, okay
;
148 okay
= ioctl(fd
, TIOCMGET
, &mstat
);
149 if (okay
) return okay
;
150 if (andy
) mstat
&= andy
;
152 return ioctl(fd
, TIOCMSET
, &mstat
);
158 /***********************************************************************
159 * COMM_BuildOldCommDCB (Internal)
161 * Build a DCB using the old style settings string eg: "COMx:96,n,8,1"
162 * We ignore the COM port index, since we can support more than 4 ports.
164 BOOL WINAPI
COMM_BuildOldCommDCB(LPCSTR device
, LPDCB lpdcb
)
166 /* "COM1:96,n,8,1" */
168 char *ptr
, temp
[256], last
;
171 TRACE("(%s), ptr %p\n", device
, lpdcb
);
173 /* Some applications call this function with "9600,n,8,1"
174 * not sending the "COM1:" parameter at left of string */
175 if (!strncasecmp(device
,"COM",3))
177 if (!device
[3]) return FALSE
;
178 if (device
[4] != ':' && device
[4] != ' ') return FALSE
;
179 strcpy(temp
,device
+5);
181 else strcpy(temp
,device
);
183 last
=temp
[strlen(temp
)-1];
184 ptr
= strtok(temp
, ", ");
186 /* DOS/Windows only compares the first two numbers
187 * and assigns an appropriate baud rate.
188 * You can supply 961324245, it still returns 9600 ! */
191 WARN("Unknown baudrate string '%s' !\n", ptr
);
192 return FALSE
; /* error: less than 2 chars */
213 WARN("Unknown baudrate indicator %d !\n", rate
);
217 lpdcb
->BaudRate
= rate
;
218 TRACE("baudrate (%ld)\n", lpdcb
->BaudRate
);
220 ptr
= strtok(NULL
, ", ");
222 *ptr
= toupper(*ptr
);
224 TRACE("parity (%c)\n", *ptr
);
225 lpdcb
->fParity
= TRUE
;
228 lpdcb
->Parity
= NOPARITY
;
229 lpdcb
->fParity
= FALSE
;
232 lpdcb
->Parity
= EVENPARITY
;
235 lpdcb
->Parity
= MARKPARITY
;
238 lpdcb
->Parity
= ODDPARITY
;
241 lpdcb
->Parity
= SPACEPARITY
;
244 WARN("Unknown parity `%c'!\n", *ptr
);
248 ptr
= strtok(NULL
, ", ");
249 TRACE("charsize (%c)\n", *ptr
);
250 lpdcb
->ByteSize
= *ptr
- '0';
252 ptr
= strtok(NULL
, ", ");
253 TRACE("stopbits (%c)\n", *ptr
);
256 lpdcb
->StopBits
= ONESTOPBIT
;
259 lpdcb
->StopBits
= TWOSTOPBITS
;
262 WARN("Unknown # of stopbits `%c'!\n", *ptr
);
269 lpdcb
->fOutxCtsFlow
= FALSE
;
270 lpdcb
->fOutxDsrFlow
= FALSE
;
271 lpdcb
->fDtrControl
= DTR_CONTROL_ENABLE
;
272 lpdcb
->fRtsControl
= RTS_CONTROL_ENABLE
;
273 } else if (last
=='p') {
275 lpdcb
->fOutX
= FALSE
;
276 lpdcb
->fOutxCtsFlow
= TRUE
;
277 lpdcb
->fOutxDsrFlow
= FALSE
;
278 lpdcb
->fDtrControl
= DTR_CONTROL_ENABLE
;
279 lpdcb
->fRtsControl
= RTS_CONTROL_HANDSHAKE
;
282 lpdcb
->fOutX
= FALSE
;
283 lpdcb
->fOutxCtsFlow
= FALSE
;
284 lpdcb
->fOutxDsrFlow
= FALSE
;
285 lpdcb
->fDtrControl
= DTR_CONTROL_ENABLE
;
286 lpdcb
->fRtsControl
= RTS_CONTROL_ENABLE
;
292 /**************************************************************************
293 * BuildCommDCBA (KERNEL32.@)
295 * Updates a device control block data structure with values from an
296 * ascii device control string. The device control string has two forms
297 * normal and extended, it must be exclusively in one or the other form.
301 * True on success, false on a malformed control string.
303 BOOL WINAPI
BuildCommDCBA(
304 LPCSTR device
, /* [in] The ascii device control string used to update the DCB. */
305 LPDCB lpdcb
) /* [out] The device control block to be updated. */
307 return BuildCommDCBAndTimeoutsA(device
,lpdcb
,NULL
);
310 /**************************************************************************
311 * BuildCommDCBAndTimeoutsA (KERNEL32.@)
313 * Updates a device control block data structure with values from an
314 * ascii device control string. Taking timeout values from a timeouts
315 * struct if desired by the control string.
319 * True on success, false bad handles etc
321 BOOL WINAPI
BuildCommDCBAndTimeoutsA(
322 LPCSTR device
, /* [in] The ascii device control string. */
323 LPDCB lpdcb
, /* [out] The device control block to be updated. */
324 LPCOMMTIMEOUTS lptimeouts
) /* [in] The timeouts to use if asked to set them by the control string. */
329 TRACE("(%s,%p,%p)\n",device
,lpdcb
,lptimeouts
);
331 if (!strncasecmp(device
,"COM",3)) {
334 ERR("BUG! COM0 can't exist!\n");
337 if ((*(device
+4)!=':') && (*(device
+4)!=' '))
339 temp
=(LPSTR
)(device
+5);
343 memset(lpdcb
,0,sizeof (DCB
));
344 lpdcb
->DCBlength
= sizeof(DCB
);
345 if (strchr(temp
,',')) { /* old style */
347 return COMM_BuildOldCommDCB(device
,lpdcb
);
349 ptr
=strtok(temp
," ");
354 if (!strncasecmp("baud=",ptr
,5)) {
355 if (!sscanf(ptr
+5,"%ld",&x
))
356 WARN("Couldn't parse %s\n",ptr
);
360 if (!strncasecmp("stop=",ptr
,5)) {
361 if (!sscanf(ptr
+5,"%ld",&x
))
362 WARN("Couldn't parse %s\n",ptr
);
366 if (!strncasecmp("data=",ptr
,5)) {
367 if (!sscanf(ptr
+5,"%ld",&x
))
368 WARN("Couldn't parse %s\n",ptr
);
372 if (!strncasecmp("parity=",ptr
,7)) {
373 lpdcb
->fParity
= TRUE
;
376 lpdcb
->fParity
= FALSE
;
377 lpdcb
->Parity
= NOPARITY
;
380 lpdcb
->Parity
= EVENPARITY
;
383 lpdcb
->Parity
= ODDPARITY
;
386 lpdcb
->Parity
= MARKPARITY
;
389 lpdcb
->Parity
= SPACEPARITY
;
395 ERR("Unhandled specifier '%s', please report.\n",ptr
);
396 ptr
=strtok(NULL
," ");
398 if (lpdcb
->BaudRate
==110)
403 /**************************************************************************
404 * BuildCommDCBAndTimeoutsW (KERNEL32.@)
406 * Updates a device control block data structure with values from an
407 * unicode device control string. Taking timeout values from a timeouts
408 * struct if desired by the control string.
412 * True on success, false bad handles etc.
414 BOOL WINAPI
BuildCommDCBAndTimeoutsW(
415 LPCWSTR devid
, /* [in] The unicode device control string. */
416 LPDCB lpdcb
, /* [out] The device control block to be updated. */
417 LPCOMMTIMEOUTS lptimeouts
) /* [in] The timeouts to use if asked to set them by the control string. */
422 TRACE("(%p,%p,%p)\n",devid
,lpdcb
,lptimeouts
);
423 devidA
= HEAP_strdupWtoA( GetProcessHeap(), 0, devid
);
426 ret
=BuildCommDCBAndTimeoutsA(devidA
,lpdcb
,lptimeouts
);
427 HeapFree( GetProcessHeap(), 0, devidA
);
432 /**************************************************************************
433 * BuildCommDCBW (KERNEL32.@)
435 * Updates a device control block structure with values from an
436 * unicode device control string. The device control string has two forms
437 * normal and extended, it must be exclusively in one or the other form.
441 * True on success, false on an malformed control string.
443 BOOL WINAPI
BuildCommDCBW(
444 LPCWSTR devid
, /* [in] The unicode device control string. */
445 LPDCB lpdcb
) /* [out] The device control block to be updated. */
447 return BuildCommDCBAndTimeoutsW(devid
,lpdcb
,NULL
);
450 static BOOL
COMM_SetCommError(HANDLE handle
, DWORD error
)
454 SERVER_START_REQ( set_serial_info
)
456 req
->handle
= handle
;
457 req
->flags
= SERIALINFO_SET_ERROR
;
458 req
->commerror
= error
;
459 ret
= !wine_server_call_err( req
);
465 static BOOL
COMM_GetCommError(HANDLE handle
, LPDWORD lperror
)
472 SERVER_START_REQ( get_serial_info
)
474 req
->handle
= handle
;
475 ret
= !wine_server_call_err( req
);
476 *lperror
= reply
->commerror
;
483 /*****************************************************************************
484 * SetCommBreak (KERNEL32.@)
486 * Halts the transmission of characters to a communications device.
490 * True on success, and false if the communications device could not be found,
491 * the control is not supported.
495 * Only TIOCSBRK and TIOCCBRK are supported.
497 BOOL WINAPI
SetCommBreak(
498 HANDLE handle
) /* [in] The communictions device to suspend. */
500 #if defined(TIOCSBRK) && defined(TIOCCBRK) /* check if available for compilation */
503 fd
= FILE_GetUnixHandle( handle
, GENERIC_READ
);
505 TRACE("FILE_GetUnixHandle failed\n");
508 result
= ioctl(fd
,TIOCSBRK
,0);
512 TRACE("ioctl failed\n");
513 SetLastError(ERROR_NOT_SUPPORTED
);
518 FIXME("ioctl not available\n");
519 SetLastError(ERROR_NOT_SUPPORTED
);
524 /*****************************************************************************
525 * ClearCommBreak (KERNEL32.@)
527 * Resumes character transmission from a communication device.
531 * True on success and false if the communications device could not be found.
535 * Only TIOCSBRK and TIOCCBRK are supported.
537 BOOL WINAPI
ClearCommBreak(
538 HANDLE handle
) /* [in] The halted communication device whose character transmission is to be resumed. */
540 #if defined(TIOCSBRK) && defined(TIOCCBRK) /* check if available for compilation */
543 fd
= FILE_GetUnixHandle( handle
, GENERIC_READ
);
545 TRACE("FILE_GetUnixHandle failed\n");
548 result
= ioctl(fd
,TIOCCBRK
,0);
552 TRACE("ioctl failed\n");
553 SetLastError(ERROR_NOT_SUPPORTED
);
558 FIXME("ioctl not available\n");
559 SetLastError(ERROR_NOT_SUPPORTED
);
564 /*****************************************************************************
565 * EscapeCommFunction (KERNEL32.@)
567 * Directs a communication device to perform an extended function.
571 * True or requested data on successful completion of the command,
572 * false if the device is not present cannot execute the command
573 * or the command failed.
575 BOOL WINAPI
EscapeCommFunction(
576 HANDLE handle
, /* [in] The communication device to perform the extended function. */
577 UINT nFunction
) /* [in] The extended function to be performed. */
579 int fd
,direct
=FALSE
,result
=FALSE
;
582 TRACE("handle %p, function=%d\n", handle
, nFunction
);
583 fd
= FILE_GetUnixHandle( handle
, GENERIC_READ
);
585 FIXME("handle %p not found.\n",handle
);
589 if (tcgetattr(fd
,&port
) == -1) {
590 COMM_SetCommError(handle
,CE_IOE
);
604 result
= COMM_WhackModem(fd
, ~TIOCM_DTR
, 0);
612 result
= COMM_WhackModem(fd
, ~TIOCM_RTS
, 0);
620 result
= COMM_WhackModem(fd
, 0, TIOCM_DTR
);
628 result
= COMM_WhackModem(fd
, 0, TIOCM_RTS
);
634 port
.c_iflag
|= IXOFF
;
639 port
.c_iflag
|= IXON
;
645 result
= ioctl(fd
,TIOCSBRK
,0);
652 result
= ioctl(fd
,TIOCCBRK
,0);
656 WARN("(handle=%p,nFunction=%d): Unknown function\n",
662 if (tcsetattr(fd
, TCSADRAIN
, &port
) == -1) {
664 COMM_SetCommError(handle
,CE_IOE
);
673 COMM_SetCommError(handle
,CE_IOE
);
682 /********************************************************************
683 * PurgeComm (KERNEL32.@)
685 * Terminates pending operations and/or discards buffers on a
686 * communication resource.
690 * True on success and false if the communications handle is bad.
692 BOOL WINAPI
PurgeComm(
693 HANDLE handle
, /* [in] The communication resource to be purged. */
694 DWORD flags
) /* [in] Flags for clear pending/buffer on input/output. */
698 TRACE("handle %p, flags %lx\n", handle
, flags
);
700 fd
= FILE_GetUnixHandle( handle
, GENERIC_READ
);
702 FIXME("no handle %p found\n",handle
);
707 ** not exactly sure how these are different
708 ** Perhaps if we had our own internal queues, one flushes them
709 ** and the other flushes the kernel's buffers.
711 if(flags
&PURGE_TXABORT
)
712 tcflush(fd
,TCOFLUSH
);
713 if(flags
&PURGE_RXABORT
)
714 tcflush(fd
,TCIFLUSH
);
715 if(flags
&PURGE_TXCLEAR
)
716 tcflush(fd
,TCOFLUSH
);
717 if(flags
&PURGE_RXCLEAR
)
718 tcflush(fd
,TCIFLUSH
);
724 /*****************************************************************************
725 * ClearCommError (KERNEL32.@)
727 * Enables further I/O operations on a communications resource after
728 * supplying error and current status information.
732 * True on success, false if the communication resource handle is bad.
734 BOOL WINAPI
ClearCommError(
735 HANDLE handle
, /* [in] The communication resource with the error. */
736 LPDWORD errors
, /* [out] Flags indicating error the resource experienced. */
737 LPCOMSTAT lpStat
) /* [out] The status of the communication resource. */
741 fd
=FILE_GetUnixHandle( handle
, GENERIC_READ
);
744 FIXME("no handle %p found\n",handle
);
750 lpStat
->fCtsHold
= 0;
751 lpStat
->fDsrHold
= 0;
752 lpStat
->fRlsdHold
= 0;
753 lpStat
->fXoffHold
= 0;
754 lpStat
->fXoffSent
= 0;
757 lpStat
->fReserved
= 0;
760 if(ioctl(fd
, TIOCOUTQ
, &lpStat
->cbOutQue
))
761 WARN("ioctl returned error\n");
763 lpStat
->cbOutQue
= 0; /* FIXME: find a different way to find out */
767 if(ioctl(fd
, TIOCINQ
, &lpStat
->cbInQue
))
768 WARN("ioctl returned error\n");
771 TRACE("handle %p cbInQue = %ld cbOutQue = %ld\n",
772 handle
, lpStat
->cbInQue
, lpStat
->cbOutQue
);
777 COMM_GetCommError(handle
, errors
);
778 COMM_SetCommError(handle
, 0);
783 /*****************************************************************************
784 * SetupComm (KERNEL32.@)
786 * Called after CreateFile to hint to the communication resource to use
787 * specified sizes for input and output buffers rather than the default values.
791 * True if successful, false if the communications resource handle is bad.
797 BOOL WINAPI
SetupComm(
798 HANDLE handle
, /* [in] The just created communication resource handle. */
799 DWORD insize
, /* [in] The suggested size of the communication resources input buffer in bytes. */
800 DWORD outsize
) /* [in] The suggested size of the communication resources output buffer in bytes. */
804 FIXME("insize %ld outsize %ld unimplemented stub\n", insize
, outsize
);
805 fd
=FILE_GetUnixHandle( handle
, GENERIC_READ
);
807 FIXME("handle %p not found?\n",handle
);
814 /*****************************************************************************
815 * GetCommMask (KERNEL32.@)
817 * Obtain the events associated with a communication device that will cause
818 * a call WaitCommEvent to return.
822 * True on success, fail on bad device handle etc.
824 BOOL WINAPI
GetCommMask(
825 HANDLE handle
, /* [in] The communications device. */
826 LPDWORD evtmask
) /* [out] The events which cause WaitCommEvent to return. */
830 TRACE("handle %p, mask %p\n", handle
, evtmask
);
832 SERVER_START_REQ( get_serial_info
)
834 req
->handle
= handle
;
835 if ((ret
= !wine_server_call_err( req
)))
837 if (evtmask
) *evtmask
= reply
->eventmask
;
844 /*****************************************************************************
845 * SetCommMask (KERNEL32.@)
847 * There be some things we need to hear about yon there communications device.
848 * (Set which events associated with a communication device should cause
849 * a call WaitCommEvent to return.)
853 * True on success, false on bad handle etc.
855 BOOL WINAPI
SetCommMask(
856 HANDLE handle
, /* [in] The communications device. */
857 DWORD evtmask
) /* [in] The events that are to be monitored. */
861 TRACE("handle %p, mask %lx\n", handle
, evtmask
);
863 SERVER_START_REQ( set_serial_info
)
865 req
->handle
= handle
;
866 req
->flags
= SERIALINFO_SET_MASK
;
867 req
->eventmask
= evtmask
;
868 ret
= !wine_server_call_err( req
);
874 /*****************************************************************************
875 * SetCommState (KERNEL32.@)
877 * Re-initializes all hardware and control settings of a communications device,
878 * with values from a device control block without effecting the input and output
883 * True on success, false on failure eg if the XonChar is equal to the XoffChar.
885 BOOL WINAPI
SetCommState(
886 HANDLE handle
, /* [in] The communications device. */
887 LPDCB lpdcb
) /* [out] The device control block. */
890 int fd
, bytesize
, stopbits
;
892 TRACE("handle %p, ptr %p\n", handle
, lpdcb
);
893 TRACE("bytesize %d baudrate %ld fParity %d Parity %d stopbits %d\n",
894 lpdcb
->ByteSize
,lpdcb
->BaudRate
,lpdcb
->fParity
, lpdcb
->Parity
,
895 (lpdcb
->StopBits
== ONESTOPBIT
)?1:
896 (lpdcb
->StopBits
== TWOSTOPBITS
)?2:0);
897 TRACE("%s %s\n",(lpdcb
->fInX
)?"IXON":"~IXON",
898 (lpdcb
->fOutX
)?"IXOFF":"~IXOFF");
900 fd
= FILE_GetUnixHandle( handle
, GENERIC_READ
);
902 FIXME("no handle %p found\n",handle
);
906 if ((tcgetattr(fd
,&port
)) == -1) {
907 int save_error
= errno
;
908 COMM_SetCommError(handle
,CE_IOE
);
910 ERR("tcgetattr error '%s'\n", strerror(save_error
));
915 port
.c_cc
[VTIME
] = 1;
918 port
.c_iflag
&= ~(ISTRIP
|BRKINT
|IGNCR
|ICRNL
|INLCR
|IMAXBEL
);
920 port
.c_iflag
&= ~(ISTRIP
|BRKINT
|IGNCR
|ICRNL
|INLCR
);
922 port
.c_iflag
|= (IGNBRK
);
924 port
.c_oflag
&= ~(OPOST
);
926 port
.c_cflag
&= ~(HUPCL
);
927 port
.c_cflag
|= CLOCAL
| CREAD
;
929 port
.c_lflag
&= ~(ICANON
|ECHO
|ISIG
);
930 port
.c_lflag
|= NOFLSH
;
933 port
.c_cflag
&= ~CBAUD
;
934 switch (lpdcb
->BaudRate
) {
937 port
.c_cflag
|= B110
;
941 port
.c_cflag
|= B300
;
945 port
.c_cflag
|= B600
;
949 port
.c_cflag
|= B1200
;
953 port
.c_cflag
|= B2400
;
957 port
.c_cflag
|= B4800
;
961 port
.c_cflag
|= B9600
;
965 port
.c_cflag
|= B19200
;
969 port
.c_cflag
|= B38400
;
973 port
.c_cflag
|= B57600
;
978 port
.c_cflag
|= B115200
;
983 port
.c_cflag
|= B230400
;
988 port
.c_cflag
|= B460800
;
992 #if defined (HAVE_LINUX_SERIAL_H) && defined (TIOCSSERIAL)
993 { struct serial_struct nuts
;
995 ioctl(fd
, TIOCGSERIAL
, &nuts
);
996 nuts
.custom_divisor
= nuts
.baud_base
/ lpdcb
->BaudRate
;
997 if (!(nuts
.custom_divisor
)) nuts
.custom_divisor
= 1;
998 arby
= nuts
.baud_base
/ nuts
.custom_divisor
;
999 nuts
.flags
&= ~ASYNC_SPD_MASK
;
1000 nuts
.flags
|= ASYNC_SPD_CUST
;
1001 WARN("You (or a program acting at your behest) have specified\n"
1002 "a non-standard baud rate %ld. Wine will set the rate to %d,\n"
1003 "which is as close as we can get by our present understanding of your\n"
1004 "hardware. I hope you know what you are doing. Any disruption Wine\n"
1005 "has caused to your linux system can be undone with setserial \n"
1006 "(see man setserial). If you have incapacitated a Hayes type modem,\n"
1007 "reset it and it will probably recover.\n", lpdcb
->BaudRate
, arby
);
1008 ioctl(fd
, TIOCSSERIAL
, &nuts
);
1009 port
.c_cflag
|= B38400
;
1012 #endif /* Don't have linux/serial.h or lack TIOCSSERIAL */
1015 COMM_SetCommError(handle
,IE_BAUDRATE
);
1017 ERR("baudrate %ld\n",lpdcb
->BaudRate
);
1020 #elif !defined(__EMX__)
1021 switch (lpdcb
->BaudRate
) {
1024 port
.c_ospeed
= B110
;
1028 port
.c_ospeed
= B300
;
1032 port
.c_ospeed
= B600
;
1036 port
.c_ospeed
= B1200
;
1040 port
.c_ospeed
= B2400
;
1044 port
.c_ospeed
= B4800
;
1048 port
.c_ospeed
= B9600
;
1052 port
.c_ospeed
= B19200
;
1056 port
.c_ospeed
= B38400
;
1061 port
.c_cflag
|= B57600
;
1067 port
.c_cflag
|= B115200
;
1072 port
.c_cflag
|= B230400
;
1077 port
.c_cflag
|= B460800
;
1081 COMM_SetCommError(handle
,IE_BAUDRATE
);
1083 ERR("baudrate %ld\n",lpdcb
->BaudRate
);
1086 port
.c_ispeed
= port
.c_ospeed
;
1088 bytesize
=lpdcb
->ByteSize
;
1089 stopbits
=lpdcb
->StopBits
;
1092 port
.c_cflag
&= ~(PARENB
| PARODD
| CMSPAR
);
1094 port
.c_cflag
&= ~(PARENB
| PARODD
);
1097 port
.c_iflag
|= INPCK
;
1099 port
.c_iflag
&= ~INPCK
;
1100 switch (lpdcb
->Parity
) {
1104 port
.c_cflag
|= (PARENB
| PARODD
);
1107 port
.c_cflag
|= PARENB
;
1110 /* Linux defines mark/space (stick) parity */
1112 port
.c_cflag
|= (PARENB
| CMSPAR
);
1115 port
.c_cflag
|= (PARENB
| PARODD
| CMSPAR
);
1118 /* try the POSIX way */
1120 if( stopbits
== ONESTOPBIT
) {
1121 stopbits
= TWOSTOPBITS
;
1122 port
.c_iflag
&= ~INPCK
;
1124 COMM_SetCommError(handle
,IE_BYTESIZE
);
1126 ERR("Cannot set MARK Parity\n");
1133 port
.c_iflag
&= ~INPCK
;
1135 COMM_SetCommError(handle
,IE_BYTESIZE
);
1137 ERR("Cannot set SPACE Parity\n");
1143 COMM_SetCommError(handle
,IE_BYTESIZE
);
1150 port
.c_cflag
&= ~CSIZE
;
1153 port
.c_cflag
|= CS5
;
1156 port
.c_cflag
|= CS6
;
1159 port
.c_cflag
|= CS7
;
1162 port
.c_cflag
|= CS8
;
1165 COMM_SetCommError(handle
,IE_BYTESIZE
);
1173 port
.c_cflag
&= ~CSTOPB
;
1175 case ONE5STOPBITS
: /* wil be selected if bytesize is 5 */
1177 port
.c_cflag
|= CSTOPB
;
1180 COMM_SetCommError(handle
,IE_BYTESIZE
);
1186 if ( lpdcb
->fOutxCtsFlow
||
1187 lpdcb
->fRtsControl
== RTS_CONTROL_HANDSHAKE
1190 port
.c_cflag
|= CRTSCTS
;
1195 if (lpdcb
->fDtrControl
== DTR_CONTROL_HANDSHAKE
)
1197 WARN("DSR/DTR flow control not supported\n");
1201 port
.c_iflag
|= IXON
;
1203 port
.c_iflag
&= ~IXON
;
1205 port
.c_iflag
|= IXOFF
;
1207 port
.c_iflag
&= ~IXOFF
;
1209 if (tcsetattr(fd
,TCSANOW
,&port
)==-1) { /* otherwise it hangs with pending input*/
1210 int save_error
=errno
;
1211 COMM_SetCommError(handle
,CE_IOE
);
1213 ERR("tcsetattr error '%s'\n", strerror(save_error
));
1216 COMM_SetCommError(handle
,0);
1223 /*****************************************************************************
1224 * GetCommState (KERNEL32.@)
1226 * Fills in a device control block with information from a communications device.
1230 * True on success, false if the communication device handle is bad etc
1234 * XonChar and XoffChar are not set.
1236 BOOL WINAPI
GetCommState(
1237 HANDLE handle
, /* [in] The communications device. */
1238 LPDCB lpdcb
) /* [out] The device control block. */
1240 struct termios port
;
1243 TRACE("handle %p, ptr %p\n", handle
, lpdcb
);
1245 fd
= FILE_GetUnixHandle( handle
, GENERIC_READ
);
1248 ERR("FILE_GetUnixHandle failed\n");
1251 if (tcgetattr(fd
, &port
) == -1) {
1252 int save_error
=errno
;
1253 ERR("tcgetattr error '%s'\n", strerror(save_error
));
1254 COMM_SetCommError(handle
,CE_IOE
);
1261 speed
= (port
.c_cflag
& CBAUD
);
1263 speed
= (cfgetospeed(&port
));
1267 lpdcb
->BaudRate
= 110;
1270 lpdcb
->BaudRate
= 300;
1273 lpdcb
->BaudRate
= 600;
1276 lpdcb
->BaudRate
= 1200;
1279 lpdcb
->BaudRate
= 2400;
1282 lpdcb
->BaudRate
= 4800;
1285 lpdcb
->BaudRate
= 9600;
1288 lpdcb
->BaudRate
= 19200;
1291 lpdcb
->BaudRate
= 38400;
1295 lpdcb
->BaudRate
= 57600;
1300 lpdcb
->BaudRate
= 115200;
1305 lpdcb
->BaudRate
= 230400;
1310 lpdcb
->BaudRate
= 460800;
1314 ERR("unknown speed %x \n",speed
);
1317 switch (port
.c_cflag
& CSIZE
) {
1319 lpdcb
->ByteSize
= 5;
1322 lpdcb
->ByteSize
= 6;
1325 lpdcb
->ByteSize
= 7;
1328 lpdcb
->ByteSize
= 8;
1331 ERR("unknown size %x \n",port
.c_cflag
& CSIZE
);
1334 if(port
.c_iflag
& INPCK
)
1335 lpdcb
->fParity
= TRUE
;
1337 lpdcb
->fParity
= FALSE
;
1339 switch (port
.c_cflag
& (PARENB
| PARODD
| CMSPAR
))
1341 switch (port
.c_cflag
& (PARENB
| PARODD
))
1345 lpdcb
->Parity
= NOPARITY
;
1348 lpdcb
->Parity
= EVENPARITY
;
1350 case (PARENB
| PARODD
):
1351 lpdcb
->Parity
= ODDPARITY
;
1354 case (PARENB
| CMSPAR
):
1355 lpdcb
->Parity
= MARKPARITY
;
1357 case (PARENB
| PARODD
| CMSPAR
):
1358 lpdcb
->Parity
= SPACEPARITY
;
1363 if (port
.c_cflag
& CSTOPB
)
1364 if(lpdcb
->ByteSize
== 5)
1365 lpdcb
->StopBits
= ONE5STOPBITS
;
1367 lpdcb
->StopBits
= TWOSTOPBITS
;
1369 lpdcb
->StopBits
= ONESTOPBIT
;
1374 /* termios does not support DTR/DSR flow control */
1375 lpdcb
->fOutxDsrFlow
= 0;
1376 lpdcb
->fDtrControl
= DTR_CONTROL_ENABLE
;
1380 if (port
.c_cflag
& CRTSCTS
) {
1381 lpdcb
->fRtsControl
= RTS_CONTROL_HANDSHAKE
;
1382 lpdcb
->fOutxCtsFlow
= 1;
1386 lpdcb
->fRtsControl
= RTS_CONTROL_ENABLE
;
1387 lpdcb
->fOutxCtsFlow
= 0;
1389 if (port
.c_iflag
& IXON
)
1394 if (port
.c_iflag
& IXOFF
)
1403 lpdcb
->XoffLim
= 10;
1405 COMM_SetCommError(handle
,0);
1409 TRACE("bytesize %d baudrate %ld fParity %d Parity %d stopbits %d\n",
1410 lpdcb
->ByteSize
,lpdcb
->BaudRate
,lpdcb
->fParity
, lpdcb
->Parity
,
1411 (lpdcb
->StopBits
== ONESTOPBIT
)?1:
1412 (lpdcb
->StopBits
== TWOSTOPBITS
)?2:0);
1413 TRACE("%s %s\n",(lpdcb
->fInX
)?"IXON":"~IXON",
1414 (lpdcb
->fOutX
)?"IXOFF":"~IXOFF");
1416 if ( lpdcb
->fOutxCtsFlow
||
1417 lpdcb
->fRtsControl
== RTS_CONTROL_HANDSHAKE
1422 TRACE("~CRTSCTS\n");
1428 /*****************************************************************************
1429 * TransmitCommChar (KERNEL32.@)
1431 * Transmits a single character in front of any pending characters in the
1432 * output buffer. Usually used to send an interrupt character to a host.
1436 * True if the call succeeded, false if the previous command character to the
1437 * same device has not been sent yet the handle is bad etc.
1443 BOOL WINAPI
TransmitCommChar(
1444 HANDLE hComm
, /* [in] The communication device in need of a command character. */
1445 CHAR chTransmit
) /* [in] The character to transmit. */
1450 WARN("(%p,'%c') not perfect!\n",hComm
,chTransmit
);
1452 fd
= FILE_GetUnixHandle( hComm
, GENERIC_READ
);
1454 SetLastError ( ERROR_INVALID_PARAMETER
);
1457 r
= (1 == write(fd
, &chTransmit
, 1));
1465 /*****************************************************************************
1466 * GetCommTimeouts (KERNEL32.@)
1468 * Obtains the request timeout values for the communications device.
1472 * True on success, false if communications device handle is bad
1473 * or the target structure is null.
1475 BOOL WINAPI
GetCommTimeouts(
1476 HANDLE hComm
, /* [in] The communications device. */
1477 LPCOMMTIMEOUTS lptimeouts
) /* [out] The struct of request timeouts. */
1481 TRACE("(%p,%p)\n",hComm
,lptimeouts
);
1485 SetLastError(ERROR_INVALID_PARAMETER
);
1489 SERVER_START_REQ( get_serial_info
)
1491 req
->handle
= hComm
;
1492 if ((ret
= !wine_server_call_err( req
)))
1494 lptimeouts
->ReadIntervalTimeout
= reply
->readinterval
;
1495 lptimeouts
->ReadTotalTimeoutMultiplier
= reply
->readmult
;
1496 lptimeouts
->ReadTotalTimeoutConstant
= reply
->readconst
;
1497 lptimeouts
->WriteTotalTimeoutMultiplier
= reply
->writemult
;
1498 lptimeouts
->WriteTotalTimeoutConstant
= reply
->writeconst
;
1505 /*****************************************************************************
1506 * SetCommTimeouts (KERNEL32.@)
1508 * Sets the timeouts used when reading and writing data to/from COMM ports.
1510 * ReadIntervalTimeout
1511 * - converted and passes to linux kernel as c_cc[VTIME]
1512 * ReadTotalTimeoutMultiplier, ReadTotalTimeoutConstant
1513 * - used in ReadFile to calculate GetOverlappedResult's timeout
1514 * WriteTotalTimeoutMultiplier, WriteTotalTimeoutConstant
1515 * - used in WriteFile to calculate GetOverlappedResult's timeout
1519 * True if the timeouts were set, false otherwise.
1521 BOOL WINAPI
SetCommTimeouts(
1522 HANDLE hComm
, /* [in] handle of COMM device */
1523 LPCOMMTIMEOUTS lptimeouts
) /* [in] pointer to COMMTIMEOUTS structure */
1527 struct termios tios
;
1529 TRACE("(%p,%p)\n",hComm
,lptimeouts
);
1533 SetLastError(ERROR_INVALID_PARAMETER
);
1537 SERVER_START_REQ( set_serial_info
)
1539 req
->handle
= hComm
;
1540 req
->flags
= SERIALINFO_SET_TIMEOUTS
;
1541 req
->readinterval
= lptimeouts
->ReadIntervalTimeout
;
1542 req
->readmult
= lptimeouts
->ReadTotalTimeoutMultiplier
;
1543 req
->readconst
= lptimeouts
->ReadTotalTimeoutConstant
;
1544 req
->writemult
= lptimeouts
->WriteTotalTimeoutMultiplier
;
1545 req
->writeconst
= lptimeouts
->WriteTotalTimeoutConstant
;
1546 ret
= !wine_server_call_err( req
);
1549 if (!ret
) return FALSE
;
1551 /* FIXME: move this stuff to the server */
1552 fd
= FILE_GetUnixHandle( hComm
, GENERIC_READ
);
1554 FIXME("no fd for handle = %p!.\n",hComm
);
1558 if (-1==tcgetattr(fd
,&tios
)) {
1559 FIXME("tcgetattr on fd %d failed!\n",fd
);
1564 /* VTIME is in 1/10 seconds */
1566 unsigned int ux_timeout
;
1568 if(lptimeouts
->ReadIntervalTimeout
== 0) /* 0 means no timeout */
1574 ux_timeout
= (lptimeouts
->ReadIntervalTimeout
+99)/100;
1577 ux_timeout
= 1; /* must be at least some timeout */
1580 tios
.c_cc
[VTIME
] = ux_timeout
;
1583 if (-1==tcsetattr(fd
,0,&tios
)) {
1584 FIXME("tcsetattr on fd %d failed!\n",fd
);
1592 /***********************************************************************
1593 * GetCommModemStatus (KERNEL32.@)
1595 * Obtains the four control register bits if supported by the hardware.
1599 * True if the communications handle was good and for hardware that
1600 * control register access, false otherwise.
1602 BOOL WINAPI
GetCommModemStatus(
1603 HANDLE hFile
, /* [in] The communications device. */
1604 LPDWORD lpModemStat
) /* [out] The control register bits. */
1606 int fd
,mstat
, result
=FALSE
;
1610 fd
= FILE_GetUnixHandle( hFile
, GENERIC_READ
);
1613 result
= ioctl(fd
, TIOCMGET
, &mstat
);
1617 WARN("ioctl failed\n");
1621 if (mstat
& TIOCM_CTS
)
1622 *lpModemStat
|= MS_CTS_ON
;
1625 if (mstat
& TIOCM_DSR
)
1626 *lpModemStat
|= MS_DSR_ON
;
1629 if (mstat
& TIOCM_RNG
)
1630 *lpModemStat
|= MS_RING_ON
;
1633 /*FIXME: Not really sure about RLSD UB 990810*/
1634 if (mstat
& TIOCM_CAR
)
1635 *lpModemStat
|= MS_RLSD_ON
;
1637 TRACE("%04x -> %s%s%s%s\n", mstat
,
1638 (*lpModemStat
&MS_RLSD_ON
)?"MS_RLSD_ON ":"",
1639 (*lpModemStat
&MS_RING_ON
)?"MS_RING_ON ":"",
1640 (*lpModemStat
&MS_DSR_ON
)?"MS_DSR_ON ":"",
1641 (*lpModemStat
&MS_CTS_ON
)?"MS_CTS_ON ":"");
1648 /***********************************************************************
1649 * COMM_WaitCommEventService (INTERNAL)
1651 * This function is called while the client is waiting on the
1652 * server, so we can't make any server calls here.
1654 static void COMM_WaitCommEventService(async_private
*ovp
)
1656 async_commio
*commio
= (async_commio
*) ovp
;
1657 IO_STATUS_BLOCK
* iosb
= commio
->async
.iosb
;
1659 TRACE("iosb %p\n",iosb
);
1661 /* FIXME: detect other events */
1662 *commio
->buffer
= EV_RXCHAR
;
1664 iosb
->u
.Status
= STATUS_SUCCESS
;
1668 /***********************************************************************
1669 * COMM_WaitCommEvent (INTERNAL)
1671 * This function must have an lpOverlapped.
1673 static BOOL
COMM_WaitCommEvent(
1674 HANDLE hFile
, /* [in] handle of comm port to wait for */
1675 LPDWORD lpdwEvents
, /* [out] event(s) that were detected */
1676 LPOVERLAPPED lpOverlapped
) /* [in/out] for Asynchronous waiting */
1683 SetLastError(ERROR_INVALID_PARAMETER
);
1687 if(NtResetEvent(lpOverlapped
->hEvent
,NULL
))
1690 fd
= FILE_GetUnixHandle( hFile
, GENERIC_WRITE
);
1694 ovp
= (async_commio
*) HeapAlloc(GetProcessHeap(), 0, sizeof (async_commio
));
1701 ovp
->async
.ops
= &commio_async_ops
;
1702 ovp
->async
.handle
= hFile
;
1704 ovp
->async
.type
= ASYNC_TYPE_WAIT
;
1705 ovp
->async
.func
= COMM_WaitCommEventService
;
1706 ovp
->async
.event
= lpOverlapped
->hEvent
;
1707 ovp
->async
.iosb
= (IO_STATUS_BLOCK
*)lpOverlapped
;
1708 ovp
->buffer
= (char *)lpdwEvents
;
1710 lpOverlapped
->InternalHigh
= 0;
1711 lpOverlapped
->Offset
= 0;
1712 lpOverlapped
->OffsetHigh
= 0;
1714 if ( !register_new_async (&ovp
->async
) )
1715 SetLastError( ERROR_IO_PENDING
);
1720 /***********************************************************************
1721 * WaitCommEvent (KERNEL32.@)
1723 * Wait until something interesting happens on a COMM port.
1724 * Interesting things (events) are set by calling SetCommMask before
1725 * this function is called.
1728 * TRUE if successful
1731 * The set of detected events will be written to *lpdwEventMask
1732 * ERROR_IO_PENDING will be returned the overlapped structure was passed
1735 * Only supports EV_RXCHAR and EV_TXEMPTY
1737 BOOL WINAPI
WaitCommEvent(
1738 HANDLE hFile
, /* [in] handle of comm port to wait for */
1739 LPDWORD lpdwEvents
, /* [out] event(s) that were detected */
1740 LPOVERLAPPED lpOverlapped
) /* [in/out] for Asynchronous waiting */
1745 TRACE("(%p %p %p )\n",hFile
, lpdwEvents
,lpOverlapped
);
1748 return COMM_WaitCommEvent(hFile
, lpdwEvents
, lpOverlapped
);
1750 /* if there is no overlapped structure, create our own */
1751 ov
.hEvent
= CreateEventA(NULL
,FALSE
,FALSE
,NULL
);
1753 COMM_WaitCommEvent(hFile
, lpdwEvents
, &ov
);
1755 /* wait for the overlapped to complete */
1756 ret
= GetOverlappedResult(hFile
, &ov
, NULL
, TRUE
);
1757 CloseHandle(ov
.hEvent
);
1762 /***********************************************************************
1763 * GetCommProperties (KERNEL32.@)
1765 * This function fills in a structure with the capabilities of the
1766 * communications port driver.
1770 * TRUE on success, FALSE on failure
1771 * If successful, the lpCommProp structure be filled in with
1772 * properties of the comm port.
1774 BOOL WINAPI
GetCommProperties(
1775 HANDLE hFile
, /* [in] handle of the comm port */
1776 LPCOMMPROP lpCommProp
) /* [out] pointer to struct to be filled */
1778 FIXME("(%p %p )\n",hFile
,lpCommProp
);
1783 * These values should be valid for LINUX's serial driver
1784 * FIXME: Perhaps they deserve an #ifdef LINUX
1786 memset(lpCommProp
,0,sizeof(COMMPROP
));
1787 lpCommProp
->wPacketLength
= 1;
1788 lpCommProp
->wPacketVersion
= 1;
1789 lpCommProp
->dwServiceMask
= SP_SERIALCOMM
;
1790 lpCommProp
->dwReserved1
= 0;
1791 lpCommProp
->dwMaxTxQueue
= 4096;
1792 lpCommProp
->dwMaxRxQueue
= 4096;
1793 lpCommProp
->dwMaxBaud
= BAUD_115200
;
1794 lpCommProp
->dwProvSubType
= PST_RS232
;
1795 lpCommProp
->dwProvCapabilities
= PCF_DTRDSR
| PCF_PARITY_CHECK
| PCF_RTSCTS
| PCF_TOTALTIMEOUTS
;
1796 lpCommProp
->dwSettableParams
= SP_BAUD
| SP_DATABITS
| SP_HANDSHAKING
|
1797 SP_PARITY
| SP_PARITY_CHECK
| SP_STOPBITS
;
1798 lpCommProp
->dwSettableBaud
= BAUD_075
| BAUD_110
| BAUD_134_5
| BAUD_150
|
1799 BAUD_300
| BAUD_600
| BAUD_1200
| BAUD_1800
| BAUD_2400
| BAUD_4800
|
1800 BAUD_9600
| BAUD_19200
| BAUD_38400
| BAUD_57600
| BAUD_115200
;
1801 lpCommProp
->wSettableData
= DATABITS_5
| DATABITS_6
| DATABITS_7
| DATABITS_8
;
1802 lpCommProp
->wSettableStopParity
= STOPBITS_10
| STOPBITS_15
| STOPBITS_20
|
1803 PARITY_NONE
| PARITY_ODD
|PARITY_EVEN
| PARITY_MARK
| PARITY_SPACE
;
1804 lpCommProp
->dwCurrentTxQueue
= lpCommProp
->dwMaxTxQueue
;
1805 lpCommProp
->dwCurrentRxQueue
= lpCommProp
->dwMaxRxQueue
;
1810 /***********************************************************************
1812 * The functionality of CommConfigDialogA, GetDefaultCommConfig and
1813 * SetDefaultCommConfig is implemented in a DLL (usually SERIALUI.DLL).
1814 * This is dependent on the type of COMM port, but since it is doubtful
1815 * anybody will get around to implementing support for fancy serial
1816 * ports in WINE, this is hardcoded for the time being. The name of
1817 * this DLL should be stored in and read from the system registry in
1818 * the hive HKEY_LOCAL_MACHINE, key
1819 * System\\CurrentControlSet\\Services\\Class\\Ports\\????
1820 * where ???? is the port number... that is determined by PNP
1821 * The DLL should be loaded when the COMM port is opened, and closed
1822 * when the COMM port is closed. - MJM 20 June 2000
1823 ***********************************************************************/
1824 static CHAR lpszSerialUI
[] = "serialui.dll";
1827 /***********************************************************************
1828 * CommConfigDialogA (KERNEL32.@)
1830 * Raises a dialog that allows the user to configure a comm port.
1831 * Fills the COMMCONFIG struct with information specified by the user.
1832 * This function should call a similar routine in the COMM driver...
1836 * TRUE on success, FALSE on failure
1837 * If successful, the lpCommConfig structure will contain a new
1838 * configuration for the comm port, as specified by the user.
1841 * The library with the CommConfigDialog code is never unloaded.
1842 * Perhaps this should be done when the comm port is closed?
1844 BOOL WINAPI
CommConfigDialogA(
1845 LPCSTR lpszDevice
, /* [in] name of communications device */
1846 HANDLE hWnd
, /* [in] parent window for the dialog */
1847 LPCOMMCONFIG lpCommConfig
) /* [out] pointer to struct to fill */
1849 FARPROC lpfnCommDialog
;
1850 HMODULE hConfigModule
;
1853 TRACE("(%p %p %p)\n",lpszDevice
, hWnd
, lpCommConfig
);
1855 hConfigModule
= LoadLibraryA(lpszSerialUI
);
1859 lpfnCommDialog
= GetProcAddress(hConfigModule
, (LPCSTR
)3L);
1864 r
= lpfnCommDialog(lpszDevice
,hWnd
,lpCommConfig
);
1866 /* UnloadLibrary(hConfigModule); */
1871 /***********************************************************************
1872 * CommConfigDialogW (KERNEL32.@)
1874 * see CommConfigDialogA for more info
1876 BOOL WINAPI
CommConfigDialogW(
1877 LPCWSTR lpszDevice
, /* [in] name of communications device */
1878 HANDLE hWnd
, /* [in] parent window for the dialog */
1879 LPCOMMCONFIG lpCommConfig
) /* [out] pointer to struct to fill */
1884 lpDeviceA
= HEAP_strdupWtoA( GetProcessHeap(), 0, lpszDevice
);
1887 r
= CommConfigDialogA(lpDeviceA
,hWnd
,lpCommConfig
);
1888 HeapFree( GetProcessHeap(), 0, lpDeviceA
);
1892 /***********************************************************************
1893 * GetCommConfig (KERNEL32.@)
1895 * Fill in the COMMCONFIG structure for the comm port hFile
1899 * TRUE on success, FALSE on failure
1900 * If successful, lpCommConfig contains the comm port configuration.
1905 BOOL WINAPI
GetCommConfig(
1906 HANDLE hFile
, /* [in] The communications device. */
1907 LPCOMMCONFIG lpCommConfig
, /* [out] The communications configuration of the device (if it fits). */
1908 LPDWORD lpdwSize
) /* [in/out] Initially the size of the configuration buffer/structure,
1909 afterwards the number of bytes copied to the buffer or
1910 the needed size of the buffer. */
1914 TRACE("(%p %p)\n",hFile
,lpCommConfig
);
1916 if(lpCommConfig
== NULL
)
1919 r
= *lpdwSize
< sizeof(COMMCONFIG
);
1920 *lpdwSize
= sizeof(COMMCONFIG
);
1924 lpCommConfig
->dwSize
= sizeof(COMMCONFIG
);
1925 lpCommConfig
->wVersion
= 1;
1926 lpCommConfig
->wReserved
= 0;
1927 r
= GetCommState(hFile
,&lpCommConfig
->dcb
);
1928 lpCommConfig
->dwProviderSubType
= PST_RS232
;
1929 lpCommConfig
->dwProviderOffset
= 0;
1930 lpCommConfig
->dwProviderSize
= 0;
1935 /***********************************************************************
1936 * SetCommConfig (KERNEL32.@)
1938 * Sets the configuration of the communications device.
1942 * True on success, false if the handle was bad is not a communications device.
1944 BOOL WINAPI
SetCommConfig(
1945 HANDLE hFile
, /* [in] The communications device. */
1946 LPCOMMCONFIG lpCommConfig
, /* [in] The desired configuration. */
1947 DWORD dwSize
) /* [in] size of the lpCommConfig struct */
1949 TRACE("(%p %p)\n",hFile
,lpCommConfig
);
1950 return SetCommState(hFile
,&lpCommConfig
->dcb
);
1953 /***********************************************************************
1954 * SetDefaultCommConfigA (KERNEL32.@)
1956 * Initializes the default configuration for the specified communication
1961 * True if the device was found and the defaults set, false otherwise
1963 BOOL WINAPI
SetDefaultCommConfigA(
1964 LPCSTR lpszDevice
, /* [in] The ascii name of the device targeted for configuration. */
1965 LPCOMMCONFIG lpCommConfig
, /* [in] The default configuration for the device. */
1966 DWORD dwSize
) /* [in] The number of bytes in the configuration structure. */
1968 FARPROC lpfnSetDefaultCommConfig
;
1969 HMODULE hConfigModule
;
1972 TRACE("(%p %p %lx)\n",lpszDevice
, lpCommConfig
, dwSize
);
1974 hConfigModule
= LoadLibraryA(lpszSerialUI
);
1978 lpfnSetDefaultCommConfig
= GetProcAddress(hConfigModule
, (LPCSTR
)4L);
1980 if(! lpfnSetDefaultCommConfig
)
1983 r
= lpfnSetDefaultCommConfig(lpszDevice
, lpCommConfig
, dwSize
);
1985 /* UnloadLibrary(hConfigModule); */
1991 /***********************************************************************
1992 * SetDefaultCommConfigW (KERNEL32.@)
1994 * Initializes the default configuration for the specified
1995 * communication device. (unicode)
2000 BOOL WINAPI
SetDefaultCommConfigW(
2001 LPCWSTR lpszDevice
, /* [in] The unicode name of the device targeted for configuration. */
2002 LPCOMMCONFIG lpCommConfig
, /* [in] The default configuration for the device. */
2003 DWORD dwSize
) /* [in] The number of bytes in the configuration structure. */
2008 TRACE("(%s %p %lx)\n",debugstr_w(lpszDevice
),lpCommConfig
,dwSize
);
2010 lpDeviceA
= HEAP_strdupWtoA( GetProcessHeap(), 0, lpszDevice
);
2013 r
= SetDefaultCommConfigA(lpDeviceA
,lpCommConfig
,dwSize
);
2014 HeapFree( GetProcessHeap(), 0, lpDeviceA
);
2019 /***********************************************************************
2020 * GetDefaultCommConfigA (KERNEL32.@)
2022 * Acquires the default configuration of the specified communication device. (unicode)
2026 * True on successful reading of the default configuration,
2027 * if the device is not found or the buffer is too small.
2029 BOOL WINAPI
GetDefaultCommConfigA(
2030 LPCSTR lpszName
, /* [in] The ascii name of the device targeted for configuration. */
2031 LPCOMMCONFIG lpCC
, /* [out] The default configuration for the device. */
2032 LPDWORD lpdwSize
) /* [in/out] Initially the size of the default configuration buffer,
2033 afterwards the number of bytes copied to the buffer or
2034 the needed size of the buffer. */
2036 LPDCB lpdcb
= &(lpCC
->dcb
);
2039 if (strncasecmp(lpszName
,"COM",3)) {
2040 ERR("not implemented for <%s>\n", lpszName
);
2044 TRACE("(%s %p %ld)\n", lpszName
, lpCC
, *lpdwSize
);
2045 if (*lpdwSize
< sizeof(COMMCONFIG
)) {
2046 *lpdwSize
= sizeof(COMMCONFIG
);
2050 *lpdwSize
= sizeof(COMMCONFIG
);
2052 lpCC
->dwSize
= sizeof(COMMCONFIG
);
2054 lpCC
->dwProviderSubType
= PST_RS232
;
2055 lpCC
->dwProviderOffset
= 0L;
2056 lpCC
->dwProviderSize
= 0L;
2058 sprintf( temp
, "COM%c:38400,n,8,1", lpszName
[3]);
2059 FIXME("setting %s as default\n", temp
);
2061 return BuildCommDCBA( temp
, lpdcb
);
2064 /**************************************************************************
2065 * GetDefaultCommConfigW (KERNEL32.@)
2067 * Acquires the default configuration of the specified communication device. (unicode)
2071 * True on successful reading of the default configuration,
2072 * if the device is not found or the buffer is too small.
2074 BOOL WINAPI
GetDefaultCommConfigW(
2075 LPCWSTR lpszName
, /* [in] The unicode name of the device targeted for configuration. */
2076 LPCOMMCONFIG lpCC
, /* [out] The default configuration for the device. */
2077 LPDWORD lpdwSize
) /* [in/out] Initially the size of the default configuration buffer,
2078 afterwards the number of bytes copied to the buffer or
2079 the needed size of the buffer. */
2084 TRACE("(%p,%p,%ld)\n",lpszName
,lpCC
,*lpdwSize
);
2085 lpszNameA
= HEAP_strdupWtoA( GetProcessHeap(), 0, lpszName
);
2088 ret
=GetDefaultCommConfigA(lpszNameA
,lpCC
,lpdwSize
);
2089 HeapFree( GetProcessHeap(), 0, lpszNameA
);