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"
68 #ifdef HAVE_SYS_FILIO_H
69 # include <sys/filio.h>
71 #ifdef HAVE_SYS_IOCTL_H
72 #include <sys/ioctl.h>
77 #ifdef HAVE_SYS_POLL_H
78 # include <sys/poll.h>
80 #ifdef HAVE_SYS_MODEM_H
81 # include <sys/modem.h>
83 #ifdef HAVE_SYS_STRTIO_H
84 # include <sys/strtio.h>
90 #include "wine/server.h"
95 #include "wine/debug.h"
97 #ifdef HAVE_LINUX_SERIAL_H
98 #include <linux/serial.h>
101 WINE_DEFAULT_DEBUG_CHANNEL(comm
);
103 /***********************************************************************
104 * Asynchronous I/O for asynchronous wait requests *
107 static DWORD
commio_get_async_status (const async_private
*ovp
);
108 static DWORD
commio_get_async_count (const async_private
*ovp
);
109 static void commio_set_async_status (async_private
*ovp
, const DWORD status
);
110 static void commio_async_cleanup (async_private
*ovp
);
112 static async_ops commio_async_ops
=
114 commio_get_async_status
, /* get_status */
115 commio_set_async_status
, /* set_status */
116 commio_get_async_count
, /* get_count */
117 NULL
, /* call_completion */
118 commio_async_cleanup
/* cleanup */
121 typedef struct async_commio
123 struct async_private async
;
124 LPOVERLAPPED lpOverlapped
;
128 static DWORD
commio_get_async_status (const struct async_private
*ovp
)
130 return ((async_commio
*) ovp
)->lpOverlapped
->Internal
;
133 static void commio_set_async_status (async_private
*ovp
, const DWORD status
)
135 ((async_commio
*) ovp
)->lpOverlapped
->Internal
= status
;
138 static DWORD
commio_get_async_count (const struct async_private
*ovp
)
143 static void commio_async_cleanup (async_private
*ovp
)
145 HeapFree(GetProcessHeap(), 0, ovp
);
148 /***********************************************************************/
150 #if !defined(TIOCINQ) && defined(FIONREAD)
151 #define TIOCINQ FIONREAD
154 static int COMM_WhackModem(int fd
, unsigned int andy
, unsigned int orrie
)
157 unsigned int mstat
, okay
;
158 okay
= ioctl(fd
, TIOCMGET
, &mstat
);
159 if (okay
) return okay
;
160 if (andy
) mstat
&= andy
;
162 return ioctl(fd
, TIOCMSET
, &mstat
);
168 /***********************************************************************
169 * COMM_BuildOldCommDCB (Internal)
171 * Build a DCB using the old style settings string eg: "COMx:96,n,8,1"
172 * We ignore the COM port index, since we can support more than 4 ports.
174 BOOL WINAPI
COMM_BuildOldCommDCB(LPCSTR device
, LPDCB lpdcb
)
176 /* "COM1:96,n,8,1" */
178 char *ptr
, temp
[256], last
;
181 TRACE("(%s), ptr %p\n", device
, lpdcb
);
183 /* Some applications call this function with "9600,n,8,1"
184 * not sending the "COM1:" parameter at left of string */
185 if (!strncasecmp(device
,"COM",3))
187 if (!device
[3]) return FALSE
;
188 if (device
[4] != ':' && device
[4] != ' ') return FALSE
;
189 strcpy(temp
,device
+5);
191 else strcpy(temp
,device
);
193 last
=temp
[strlen(temp
)-1];
194 ptr
= strtok(temp
, ", ");
196 /* DOS/Windows only compares the first two numbers
197 * and assigns an appropriate baud rate.
198 * You can supply 961324245, it still returns 9600 ! */
201 WARN("Unknown baudrate string '%s' !\n", ptr
);
202 return FALSE
; /* error: less than 2 chars */
223 WARN("Unknown baudrate indicator %d !\n", rate
);
227 lpdcb
->BaudRate
= rate
;
228 TRACE("baudrate (%ld)\n", lpdcb
->BaudRate
);
230 ptr
= strtok(NULL
, ", ");
232 *ptr
= toupper(*ptr
);
234 TRACE("parity (%c)\n", *ptr
);
235 lpdcb
->fParity
= TRUE
;
238 lpdcb
->Parity
= NOPARITY
;
239 lpdcb
->fParity
= FALSE
;
242 lpdcb
->Parity
= EVENPARITY
;
245 lpdcb
->Parity
= MARKPARITY
;
248 lpdcb
->Parity
= ODDPARITY
;
251 lpdcb
->Parity
= SPACEPARITY
;
254 WARN("Unknown parity `%c'!\n", *ptr
);
258 ptr
= strtok(NULL
, ", ");
259 TRACE("charsize (%c)\n", *ptr
);
260 lpdcb
->ByteSize
= *ptr
- '0';
262 ptr
= strtok(NULL
, ", ");
263 TRACE("stopbits (%c)\n", *ptr
);
266 lpdcb
->StopBits
= ONESTOPBIT
;
269 lpdcb
->StopBits
= TWOSTOPBITS
;
272 WARN("Unknown # of stopbits `%c'!\n", *ptr
);
279 lpdcb
->fOutxCtsFlow
= FALSE
;
280 lpdcb
->fOutxDsrFlow
= FALSE
;
281 lpdcb
->fDtrControl
= DTR_CONTROL_ENABLE
;
282 lpdcb
->fRtsControl
= RTS_CONTROL_ENABLE
;
283 } else if (last
=='p') {
285 lpdcb
->fOutX
= FALSE
;
286 lpdcb
->fOutxCtsFlow
= TRUE
;
287 lpdcb
->fOutxDsrFlow
= FALSE
;
288 lpdcb
->fDtrControl
= DTR_CONTROL_ENABLE
;
289 lpdcb
->fRtsControl
= RTS_CONTROL_HANDSHAKE
;
292 lpdcb
->fOutX
= FALSE
;
293 lpdcb
->fOutxCtsFlow
= FALSE
;
294 lpdcb
->fOutxDsrFlow
= FALSE
;
295 lpdcb
->fDtrControl
= DTR_CONTROL_ENABLE
;
296 lpdcb
->fRtsControl
= RTS_CONTROL_ENABLE
;
302 /**************************************************************************
303 * BuildCommDCBA (KERNEL32.@)
305 * Updates a device control block data structure with values from an
306 * ascii device control string. The device control string has two forms
307 * normal and extended, it must be exclusively in one or the other form.
311 * True on success, false on a malformed control string.
313 BOOL WINAPI
BuildCommDCBA(
314 LPCSTR device
, /* [in] The ascii device control string used to update the DCB. */
315 LPDCB lpdcb
) /* [out] The device control block to be updated. */
317 return BuildCommDCBAndTimeoutsA(device
,lpdcb
,NULL
);
320 /**************************************************************************
321 * BuildCommDCBAndTimeoutsA (KERNEL32.@)
323 * Updates a device control block data structure with values from an
324 * ascii device control string. Taking timeout values from a timeouts
325 * struct if desired by the control string.
329 * True on success, false bad handles etc
331 BOOL WINAPI
BuildCommDCBAndTimeoutsA(
332 LPCSTR device
, /* [in] The ascii device control string. */
333 LPDCB lpdcb
, /* [out] The device control block to be updated. */
334 LPCOMMTIMEOUTS lptimeouts
) /* [in] The timeouts to use if asked to set them by the control string. */
339 TRACE("(%s,%p,%p)\n",device
,lpdcb
,lptimeouts
);
341 if (!strncasecmp(device
,"COM",3)) {
344 ERR("BUG! COM0 can't exist!\n");
347 if ((*(device
+4)!=':') && (*(device
+4)!=' '))
349 temp
=(LPSTR
)(device
+5);
353 memset(lpdcb
,0,sizeof (DCB
));
354 lpdcb
->DCBlength
= sizeof(DCB
);
355 if (strchr(temp
,',')) { /* old style */
357 return COMM_BuildOldCommDCB(device
,lpdcb
);
359 ptr
=strtok(temp
," ");
364 if (!strncmp("baud=",ptr
,5)) {
365 if (!sscanf(ptr
+5,"%ld",&x
))
366 WARN("Couldn't parse %s\n",ptr
);
370 if (!strncmp("stop=",ptr
,5)) {
371 if (!sscanf(ptr
+5,"%ld",&x
))
372 WARN("Couldn't parse %s\n",ptr
);
376 if (!strncmp("data=",ptr
,5)) {
377 if (!sscanf(ptr
+5,"%ld",&x
))
378 WARN("Couldn't parse %s\n",ptr
);
382 if (!strncmp("parity=",ptr
,7)) {
383 lpdcb
->fParity
= TRUE
;
386 lpdcb
->fParity
= FALSE
;
387 lpdcb
->Parity
= NOPARITY
;
390 lpdcb
->Parity
= EVENPARITY
;
393 lpdcb
->Parity
= ODDPARITY
;
396 lpdcb
->Parity
= MARKPARITY
;
399 lpdcb
->Parity
= SPACEPARITY
;
405 ERR("Unhandled specifier '%s', please report.\n",ptr
);
406 ptr
=strtok(NULL
," ");
408 if (lpdcb
->BaudRate
==110)
413 /**************************************************************************
414 * BuildCommDCBAndTimeoutsW (KERNEL32.@)
416 * Updates a device control block data structure with values from an
417 * unicode device control string. Taking timeout values from a timeouts
418 * struct if desired by the control string.
422 * True on success, false bad handles etc.
424 BOOL WINAPI
BuildCommDCBAndTimeoutsW(
425 LPCWSTR devid
, /* [in] The unicode device control string. */
426 LPDCB lpdcb
, /* [out] The device control block to be updated. */
427 LPCOMMTIMEOUTS lptimeouts
) /* [in] The timeouts to use if asked to set them by the control string. */
432 TRACE("(%p,%p,%p)\n",devid
,lpdcb
,lptimeouts
);
433 devidA
= HEAP_strdupWtoA( GetProcessHeap(), 0, devid
);
436 ret
=BuildCommDCBAndTimeoutsA(devidA
,lpdcb
,lptimeouts
);
437 HeapFree( GetProcessHeap(), 0, devidA
);
442 /**************************************************************************
443 * BuildCommDCBW (KERNEL32.@)
445 * Updates a device control block structure with values from an
446 * unicode device control string. The device control string has two forms
447 * normal and extended, it must be exclusively in one or the other form.
451 * True on success, false on an malformed control string.
453 BOOL WINAPI
BuildCommDCBW(
454 LPCWSTR devid
, /* [in] The unicode device control string. */
455 LPDCB lpdcb
) /* [out] The device control block to be updated. */
457 return BuildCommDCBAndTimeoutsW(devid
,lpdcb
,NULL
);
460 static BOOL
COMM_SetCommError(HANDLE handle
, DWORD error
)
464 SERVER_START_REQ( set_serial_info
)
466 req
->handle
= handle
;
467 req
->flags
= SERIALINFO_SET_ERROR
;
468 req
->commerror
= error
;
469 ret
= !wine_server_call_err( req
);
475 static BOOL
COMM_GetCommError(HANDLE handle
, LPDWORD lperror
)
482 SERVER_START_REQ( get_serial_info
)
484 req
->handle
= handle
;
485 ret
= !wine_server_call_err( req
);
486 *lperror
= reply
->commerror
;
493 /*****************************************************************************
494 * SetCommBreak (KERNEL32.@)
496 * Halts the transmission of characters to a communications device.
500 * True on success, and false if the communications device could not be found,
501 * the control is not supported.
505 * Only TIOCSBRK and TIOCCBRK are supported.
507 BOOL WINAPI
SetCommBreak(
508 HANDLE handle
) /* [in] The communictions device to suspend. */
510 #if defined(TIOCSBRK) && defined(TIOCCBRK) /* check if available for compilation */
513 fd
= FILE_GetUnixHandle( handle
, GENERIC_READ
);
515 TRACE("FILE_GetUnixHandle failed\n");
518 result
= ioctl(fd
,TIOCSBRK
,0);
522 TRACE("ioctl failed\n");
523 SetLastError(ERROR_NOT_SUPPORTED
);
528 FIXME("ioctl not available\n");
529 SetLastError(ERROR_NOT_SUPPORTED
);
534 /*****************************************************************************
535 * ClearCommBreak (KERNEL32.@)
537 * Resumes character transmission from a communication device.
541 * True on success and false if the communications device could not be found.
545 * Only TIOCSBRK and TIOCCBRK are supported.
547 BOOL WINAPI
ClearCommBreak(
548 HANDLE handle
) /* [in] The halted communication device whose character transmission is to be resumed. */
550 #if defined(TIOCSBRK) && defined(TIOCCBRK) /* check if available for compilation */
553 fd
= FILE_GetUnixHandle( handle
, GENERIC_READ
);
555 TRACE("FILE_GetUnixHandle failed\n");
558 result
= ioctl(fd
,TIOCCBRK
,0);
562 TRACE("ioctl failed\n");
563 SetLastError(ERROR_NOT_SUPPORTED
);
568 FIXME("ioctl not available\n");
569 SetLastError(ERROR_NOT_SUPPORTED
);
574 /*****************************************************************************
575 * EscapeCommFunction (KERNEL32.@)
577 * Directs a communication device to perform an extended function.
581 * True or requested data on successful completion of the command,
582 * false if the device is not present cannot execute the command
583 * or the command failed.
585 BOOL WINAPI
EscapeCommFunction(
586 HANDLE handle
, /* [in] The communication device to perform the extended function. */
587 UINT nFunction
) /* [in] The extended function to be performed. */
589 int fd
,direct
=FALSE
,result
=FALSE
;
592 TRACE("handle %d, function=%d\n", handle
, nFunction
);
593 fd
= FILE_GetUnixHandle( handle
, GENERIC_READ
);
595 FIXME("handle %d not found.\n",handle
);
599 if (tcgetattr(fd
,&port
) == -1) {
600 COMM_SetCommError(handle
,CE_IOE
);
614 result
= COMM_WhackModem(fd
, ~TIOCM_DTR
, 0);
622 result
= COMM_WhackModem(fd
, ~TIOCM_RTS
, 0);
630 result
= COMM_WhackModem(fd
, 0, TIOCM_DTR
);
638 result
= COMM_WhackModem(fd
, 0, TIOCM_RTS
);
644 port
.c_iflag
|= IXOFF
;
649 port
.c_iflag
|= IXON
;
655 result
= ioctl(fd
,TIOCSBRK
,0);
662 result
= ioctl(fd
,TIOCCBRK
,0);
666 WARN("(handle=%d,nFunction=%d): Unknown function\n",
672 if (tcsetattr(fd
, TCSADRAIN
, &port
) == -1) {
674 COMM_SetCommError(handle
,CE_IOE
);
683 COMM_SetCommError(handle
,CE_IOE
);
692 /********************************************************************
693 * PurgeComm (KERNEL32.@)
695 * Terminates pending operations and/or discards buffers on a
696 * communication resource.
700 * True on success and false if the communications handle is bad.
702 BOOL WINAPI
PurgeComm(
703 HANDLE handle
, /* [in] The communication resource to be purged. */
704 DWORD flags
) /* [in] Flags for clear pending/buffer on input/output. */
708 TRACE("handle %d, flags %lx\n", handle
, flags
);
710 fd
= FILE_GetUnixHandle( handle
, GENERIC_READ
);
712 FIXME("no handle %d found\n",handle
);
717 ** not exactly sure how these are different
718 ** Perhaps if we had our own internal queues, one flushes them
719 ** and the other flushes the kernel's buffers.
721 if(flags
&PURGE_TXABORT
)
722 tcflush(fd
,TCOFLUSH
);
723 if(flags
&PURGE_RXABORT
)
724 tcflush(fd
,TCIFLUSH
);
725 if(flags
&PURGE_TXCLEAR
)
726 tcflush(fd
,TCOFLUSH
);
727 if(flags
&PURGE_RXCLEAR
)
728 tcflush(fd
,TCIFLUSH
);
734 /*****************************************************************************
735 * ClearCommError (KERNEL32.@)
737 * Enables further I/O operations on a communications resource after
738 * supplying error and current status information.
742 * True on success, false if the communication resource handle is bad.
744 BOOL WINAPI
ClearCommError(
745 HANDLE handle
, /* [in] The communication resource with the error. */
746 LPDWORD errors
, /* [out] Flags indicating error the resource experienced. */
747 LPCOMSTAT lpStat
) /* [out] The status of the communication resource. */
751 fd
=FILE_GetUnixHandle( handle
, GENERIC_READ
);
754 FIXME("no handle %d found\n",handle
);
763 if(ioctl(fd
, TIOCOUTQ
, &lpStat
->cbOutQue
))
764 WARN("ioctl returned error\n");
766 lpStat
->cbOutQue
= 0; /* FIXME: find a different way to find out */
770 if(ioctl(fd
, TIOCINQ
, &lpStat
->cbInQue
))
771 WARN("ioctl returned error\n");
774 TRACE("handle %d cbInQue = %ld cbOutQue = %ld\n",
775 handle
, lpStat
->cbInQue
, lpStat
->cbOutQue
);
780 COMM_GetCommError(handle
, errors
);
781 COMM_SetCommError(handle
, 0);
786 /*****************************************************************************
787 * SetupComm (KERNEL32.@)
789 * Called after CreateFile to hint to the communication resource to use
790 * specified sizes for input and output buffers rather than the default values.
794 * True if successful, false if the communications resource handle is bad.
800 BOOL WINAPI
SetupComm(
801 HANDLE handle
, /* [in] The just created communication resource handle. */
802 DWORD insize
, /* [in] The suggested size of the communication resources input buffer in bytes. */
803 DWORD outsize
) /* [in] The suggested size of the communication resources output buffer in bytes. */
807 FIXME("insize %ld outsize %ld unimplemented stub\n", insize
, outsize
);
808 fd
=FILE_GetUnixHandle( handle
, GENERIC_READ
);
810 FIXME("handle %d not found?\n",handle
);
817 /*****************************************************************************
818 * GetCommMask (KERNEL32.@)
820 * Obtain the events associated with a communication device that will cause
821 * a call WaitCommEvent to return.
825 * True on success, fail on bad device handle etc.
827 BOOL WINAPI
GetCommMask(
828 HANDLE handle
, /* [in] The communications device. */
829 LPDWORD evtmask
) /* [out] The events which cause WaitCommEvent to return. */
833 TRACE("handle %d, mask %p\n", handle
, evtmask
);
835 SERVER_START_REQ( get_serial_info
)
837 req
->handle
= handle
;
838 if ((ret
= !wine_server_call_err( req
)))
840 if (evtmask
) *evtmask
= reply
->eventmask
;
847 /*****************************************************************************
848 * SetCommMask (KERNEL32.@)
850 * There be some things we need to hear about yon there communications device.
851 * (Set which events associated with a communication device should cause
852 * a call WaitCommEvent to return.)
856 * True on success, false on bad handle etc.
858 BOOL WINAPI
SetCommMask(
859 HANDLE handle
, /* [in] The communications device. */
860 DWORD evtmask
) /* [in] The events that are to be monitored. */
864 TRACE("handle %d, mask %lx\n", handle
, evtmask
);
866 SERVER_START_REQ( set_serial_info
)
868 req
->handle
= handle
;
869 req
->flags
= SERIALINFO_SET_MASK
;
870 req
->eventmask
= evtmask
;
871 ret
= !wine_server_call_err( req
);
877 /*****************************************************************************
878 * SetCommState (KERNEL32.@)
880 * Re-initializes all hardware and control settings of a communications device,
881 * with values from a device control block without effecting the input and output
886 * True on success, false on failure eg if the XonChar is equal to the XoffChar.
888 BOOL WINAPI
SetCommState(
889 HANDLE handle
, /* [in] The communications device. */
890 LPDCB lpdcb
) /* [out] The device control block. */
893 int fd
, bytesize
, stopbits
;
895 TRACE("handle %d, ptr %p\n", handle
, lpdcb
);
896 TRACE("bytesize %d baudrate %ld fParity %d Parity %d stopbits %d\n",
897 lpdcb
->ByteSize
,lpdcb
->BaudRate
,lpdcb
->fParity
, lpdcb
->Parity
,
898 (lpdcb
->StopBits
== ONESTOPBIT
)?1:
899 (lpdcb
->StopBits
== TWOSTOPBITS
)?2:0);
900 TRACE("%s %s\n",(lpdcb
->fInX
)?"IXON":"~IXON",
901 (lpdcb
->fOutX
)?"IXOFF":"~IXOFF");
903 fd
= FILE_GetUnixHandle( handle
, GENERIC_READ
);
905 FIXME("no handle %d found\n",handle
);
909 if ((tcgetattr(fd
,&port
)) == -1) {
910 int save_error
= errno
;
911 COMM_SetCommError(handle
,CE_IOE
);
913 ERR("tcgetattr error '%s'\n", strerror(save_error
));
918 port
.c_cc
[VTIME
] = 1;
921 port
.c_iflag
&= ~(ISTRIP
|BRKINT
|IGNCR
|ICRNL
|INLCR
|IMAXBEL
);
923 port
.c_iflag
&= ~(ISTRIP
|BRKINT
|IGNCR
|ICRNL
|INLCR
);
925 port
.c_iflag
|= (IGNBRK
);
927 port
.c_oflag
&= ~(OPOST
);
929 port
.c_cflag
&= ~(HUPCL
);
930 port
.c_cflag
|= CLOCAL
| CREAD
;
932 port
.c_lflag
&= ~(ICANON
|ECHO
|ISIG
);
933 port
.c_lflag
|= NOFLSH
;
936 port
.c_cflag
&= ~CBAUD
;
937 switch (lpdcb
->BaudRate
) {
940 port
.c_cflag
|= B110
;
944 port
.c_cflag
|= B300
;
948 port
.c_cflag
|= B600
;
952 port
.c_cflag
|= B1200
;
956 port
.c_cflag
|= B2400
;
960 port
.c_cflag
|= B4800
;
964 port
.c_cflag
|= B9600
;
968 port
.c_cflag
|= B19200
;
972 port
.c_cflag
|= B38400
;
976 port
.c_cflag
|= B57600
;
981 port
.c_cflag
|= B115200
;
986 port
.c_cflag
|= B230400
;
991 port
.c_cflag
|= B460800
;
995 #if defined (HAVE_LINUX_SERIAL_H) && defined (TIOCSSERIAL)
996 { struct serial_struct nuts
;
998 ioctl(fd
, TIOCGSERIAL
, &nuts
);
999 nuts
.custom_divisor
= nuts
.baud_base
/ lpdcb
->BaudRate
;
1000 if (!(nuts
.custom_divisor
)) nuts
.custom_divisor
= 1;
1001 arby
= nuts
.baud_base
/ nuts
.custom_divisor
;
1002 nuts
.flags
&= ~ASYNC_SPD_MASK
;
1003 nuts
.flags
|= ASYNC_SPD_CUST
;
1004 WARN("You (or a program acting at your behest) have specified\n"
1005 "a non-standard baud rate %ld. Wine will set the rate to %d,\n"
1006 "which is as close as we can get by our present understanding of your\n"
1007 "hardware. I hope you know what you are doing. Any disruption Wine\n"
1008 "has caused to your linux system can be undone with setserial \n"
1009 "(see man setserial). If you have incapacitated a Hayes type modem,\n"
1010 "reset it and it will probably recover.\n", lpdcb
->BaudRate
, arby
);
1011 ioctl(fd
, TIOCSSERIAL
, &nuts
);
1012 port
.c_cflag
|= B38400
;
1015 #endif /* Don't have linux/serial.h or lack TIOCSSERIAL */
1018 COMM_SetCommError(handle
,IE_BAUDRATE
);
1020 ERR("baudrate %ld\n",lpdcb
->BaudRate
);
1023 #elif !defined(__EMX__)
1024 switch (lpdcb
->BaudRate
) {
1027 port
.c_ospeed
= B110
;
1031 port
.c_ospeed
= B300
;
1035 port
.c_ospeed
= B600
;
1039 port
.c_ospeed
= B1200
;
1043 port
.c_ospeed
= B2400
;
1047 port
.c_ospeed
= B4800
;
1051 port
.c_ospeed
= B9600
;
1055 port
.c_ospeed
= B19200
;
1059 port
.c_ospeed
= B38400
;
1064 port
.c_cflag
|= B57600
;
1070 port
.c_cflag
|= B115200
;
1075 port
.c_cflag
|= B230400
;
1080 port
.c_cflag
|= B460800
;
1084 COMM_SetCommError(handle
,IE_BAUDRATE
);
1086 ERR("baudrate %ld\n",lpdcb
->BaudRate
);
1089 port
.c_ispeed
= port
.c_ospeed
;
1091 bytesize
=lpdcb
->ByteSize
;
1092 stopbits
=lpdcb
->StopBits
;
1095 port
.c_cflag
&= ~(PARENB
| PARODD
| CMSPAR
);
1097 port
.c_cflag
&= ~(PARENB
| PARODD
);
1100 port
.c_iflag
|= INPCK
;
1102 port
.c_iflag
&= ~INPCK
;
1103 switch (lpdcb
->Parity
) {
1107 port
.c_cflag
|= (PARENB
| PARODD
);
1110 port
.c_cflag
|= PARENB
;
1113 /* Linux defines mark/space (stick) parity */
1115 port
.c_cflag
|= (PARENB
| CMSPAR
);
1118 port
.c_cflag
|= (PARENB
| PARODD
| CMSPAR
);
1121 /* try the POSIX way */
1123 if( stopbits
== ONESTOPBIT
) {
1124 stopbits
= TWOSTOPBITS
;
1125 port
.c_iflag
&= ~INPCK
;
1127 COMM_SetCommError(handle
,IE_BYTESIZE
);
1129 ERR("Cannot set MARK Parity\n");
1136 port
.c_iflag
&= ~INPCK
;
1138 COMM_SetCommError(handle
,IE_BYTESIZE
);
1140 ERR("Cannot set SPACE Parity\n");
1146 COMM_SetCommError(handle
,IE_BYTESIZE
);
1153 port
.c_cflag
&= ~CSIZE
;
1156 port
.c_cflag
|= CS5
;
1159 port
.c_cflag
|= CS6
;
1162 port
.c_cflag
|= CS7
;
1165 port
.c_cflag
|= CS8
;
1168 COMM_SetCommError(handle
,IE_BYTESIZE
);
1176 port
.c_cflag
&= ~CSTOPB
;
1178 case ONE5STOPBITS
: /* wil be selected if bytesize is 5 */
1180 port
.c_cflag
|= CSTOPB
;
1183 COMM_SetCommError(handle
,IE_BYTESIZE
);
1189 if ( lpdcb
->fOutxCtsFlow
||
1190 lpdcb
->fRtsControl
== RTS_CONTROL_HANDSHAKE
1193 port
.c_cflag
|= CRTSCTS
;
1198 if (lpdcb
->fDtrControl
== DTR_CONTROL_HANDSHAKE
)
1200 WARN("DSR/DTR flow control not supported\n");
1204 port
.c_iflag
|= IXON
;
1206 port
.c_iflag
&= ~IXON
;
1208 port
.c_iflag
|= IXOFF
;
1210 port
.c_iflag
&= ~IXOFF
;
1212 if (tcsetattr(fd
,TCSANOW
,&port
)==-1) { /* otherwise it hangs with pending input*/
1213 int save_error
=errno
;
1214 COMM_SetCommError(handle
,CE_IOE
);
1216 ERR("tcsetattr error '%s'\n", strerror(save_error
));
1219 COMM_SetCommError(handle
,0);
1226 /*****************************************************************************
1227 * GetCommState (KERNEL32.@)
1229 * Fills in a device control block with information from a communications device.
1233 * True on success, false if the communication device handle is bad etc
1237 * XonChar and XoffChar are not set.
1239 BOOL WINAPI
GetCommState(
1240 HANDLE handle
, /* [in] The communications device. */
1241 LPDCB lpdcb
) /* [out] The device control block. */
1243 struct termios port
;
1246 TRACE("handle %d, ptr %p\n", handle
, lpdcb
);
1248 fd
= FILE_GetUnixHandle( handle
, GENERIC_READ
);
1251 ERR("FILE_GetUnixHandle failed\n");
1254 if (tcgetattr(fd
, &port
) == -1) {
1255 int save_error
=errno
;
1256 ERR("tcgetattr error '%s'\n", strerror(save_error
));
1257 COMM_SetCommError(handle
,CE_IOE
);
1264 speed
= (port
.c_cflag
& CBAUD
);
1266 speed
= (cfgetospeed(&port
));
1270 lpdcb
->BaudRate
= 110;
1273 lpdcb
->BaudRate
= 300;
1276 lpdcb
->BaudRate
= 600;
1279 lpdcb
->BaudRate
= 1200;
1282 lpdcb
->BaudRate
= 2400;
1285 lpdcb
->BaudRate
= 4800;
1288 lpdcb
->BaudRate
= 9600;
1291 lpdcb
->BaudRate
= 19200;
1294 lpdcb
->BaudRate
= 38400;
1298 lpdcb
->BaudRate
= 57600;
1303 lpdcb
->BaudRate
= 115200;
1308 lpdcb
->BaudRate
= 230400;
1313 lpdcb
->BaudRate
= 460800;
1317 ERR("unknown speed %x \n",speed
);
1320 switch (port
.c_cflag
& CSIZE
) {
1322 lpdcb
->ByteSize
= 5;
1325 lpdcb
->ByteSize
= 6;
1328 lpdcb
->ByteSize
= 7;
1331 lpdcb
->ByteSize
= 8;
1334 ERR("unknown size %x \n",port
.c_cflag
& CSIZE
);
1337 if(port
.c_iflag
& INPCK
)
1338 lpdcb
->fParity
= TRUE
;
1340 lpdcb
->fParity
= FALSE
;
1342 switch (port
.c_cflag
& (PARENB
| PARODD
| CMSPAR
))
1344 switch (port
.c_cflag
& (PARENB
| PARODD
))
1348 lpdcb
->Parity
= NOPARITY
;
1351 lpdcb
->Parity
= EVENPARITY
;
1353 case (PARENB
| PARODD
):
1354 lpdcb
->Parity
= ODDPARITY
;
1357 case (PARENB
| CMSPAR
):
1358 lpdcb
->Parity
= MARKPARITY
;
1360 case (PARENB
| PARODD
| CMSPAR
):
1361 lpdcb
->Parity
= SPACEPARITY
;
1366 if (port
.c_cflag
& CSTOPB
)
1367 if(lpdcb
->ByteSize
== 5)
1368 lpdcb
->StopBits
= ONE5STOPBITS
;
1370 lpdcb
->StopBits
= TWOSTOPBITS
;
1372 lpdcb
->StopBits
= ONESTOPBIT
;
1377 /* termios does not support DTR/DSR flow control */
1378 lpdcb
->fOutxDsrFlow
= 0;
1379 lpdcb
->fDtrControl
= DTR_CONTROL_ENABLE
;
1383 if (port
.c_cflag
& CRTSCTS
) {
1384 lpdcb
->fRtsControl
= RTS_CONTROL_HANDSHAKE
;
1385 lpdcb
->fOutxCtsFlow
= 1;
1389 lpdcb
->fRtsControl
= RTS_CONTROL_ENABLE
;
1390 lpdcb
->fOutxCtsFlow
= 0;
1392 if (port
.c_iflag
& IXON
)
1397 if (port
.c_iflag
& IXOFF
)
1406 lpdcb
->XoffLim
= 10;
1408 COMM_SetCommError(handle
,0);
1412 TRACE("bytesize %d baudrate %ld fParity %d Parity %d stopbits %d\n",
1413 lpdcb
->ByteSize
,lpdcb
->BaudRate
,lpdcb
->fParity
, lpdcb
->Parity
,
1414 (lpdcb
->StopBits
== ONESTOPBIT
)?1:
1415 (lpdcb
->StopBits
== TWOSTOPBITS
)?2:0);
1416 TRACE("%s %s\n",(lpdcb
->fInX
)?"IXON":"~IXON",
1417 (lpdcb
->fOutX
)?"IXOFF":"~IXOFF");
1419 if ( lpdcb
->fOutxCtsFlow
||
1420 lpdcb
->fRtsControl
== RTS_CONTROL_HANDSHAKE
1425 TRACE("~CRTSCTS\n");
1431 /*****************************************************************************
1432 * TransmitCommChar (KERNEL32.@)
1434 * Transmits a single character in front of any pending characters in the
1435 * output buffer. Usually used to send an interrupt character to a host.
1439 * True if the call succeeded, false if the previous command character to the
1440 * same device has not been sent yet the handle is bad etc.
1446 BOOL WINAPI
TransmitCommChar(
1447 HANDLE hComm
, /* [in] The communication device in need of a command character. */
1448 CHAR chTransmit
) /* [in] The character to transmit. */
1453 WARN("(%x,'%c') not perfect!\n",hComm
,chTransmit
);
1455 fd
= FILE_GetUnixHandle( hComm
, GENERIC_READ
);
1457 SetLastError ( ERROR_INVALID_PARAMETER
);
1460 r
= (1 == write(fd
, &chTransmit
, 1));
1468 /*****************************************************************************
1469 * GetCommTimeouts (KERNEL32.@)
1471 * Obtains the request timeout values for the communications device.
1475 * True on success, false if communications device handle is bad
1476 * or the target structure is null.
1478 BOOL WINAPI
GetCommTimeouts(
1479 HANDLE hComm
, /* [in] The communications device. */
1480 LPCOMMTIMEOUTS lptimeouts
) /* [out] The struct of request timeouts. */
1484 TRACE("(%x,%p)\n",hComm
,lptimeouts
);
1488 SetLastError(ERROR_INVALID_PARAMETER
);
1492 SERVER_START_REQ( get_serial_info
)
1494 req
->handle
= hComm
;
1495 if ((ret
= !wine_server_call_err( req
)))
1497 lptimeouts
->ReadIntervalTimeout
= reply
->readinterval
;
1498 lptimeouts
->ReadTotalTimeoutMultiplier
= reply
->readmult
;
1499 lptimeouts
->ReadTotalTimeoutConstant
= reply
->readconst
;
1500 lptimeouts
->WriteTotalTimeoutMultiplier
= reply
->writemult
;
1501 lptimeouts
->WriteTotalTimeoutConstant
= reply
->writeconst
;
1508 /*****************************************************************************
1509 * SetCommTimeouts (KERNEL32.@)
1511 * Sets the timeouts used when reading and writing data to/from COMM ports.
1513 * ReadIntervalTimeout
1514 * - converted and passes to linux kernel as c_cc[VTIME]
1515 * ReadTotalTimeoutMultiplier, ReadTotalTimeoutConstant
1516 * - used in ReadFile to calculate GetOverlappedResult's timeout
1517 * WriteTotalTimeoutMultiplier, WriteTotalTimeoutConstant
1518 * - used in WriteFile to calculate GetOverlappedResult's timeout
1522 * True if the timeouts were set, false otherwise.
1524 BOOL WINAPI
SetCommTimeouts(
1525 HANDLE hComm
, /* [in] handle of COMM device */
1526 LPCOMMTIMEOUTS lptimeouts
) /* [in] pointer to COMMTIMEOUTS structure */
1530 struct termios tios
;
1532 TRACE("(%x,%p)\n",hComm
,lptimeouts
);
1536 SetLastError(ERROR_INVALID_PARAMETER
);
1540 SERVER_START_REQ( set_serial_info
)
1542 req
->handle
= hComm
;
1543 req
->flags
= SERIALINFO_SET_TIMEOUTS
;
1544 req
->readinterval
= lptimeouts
->ReadIntervalTimeout
;
1545 req
->readmult
= lptimeouts
->ReadTotalTimeoutMultiplier
;
1546 req
->readconst
= lptimeouts
->ReadTotalTimeoutConstant
;
1547 req
->writemult
= lptimeouts
->WriteTotalTimeoutMultiplier
;
1548 req
->writeconst
= lptimeouts
->WriteTotalTimeoutConstant
;
1549 ret
= !wine_server_call_err( req
);
1552 if (!ret
) return FALSE
;
1554 /* FIXME: move this stuff to the server */
1555 fd
= FILE_GetUnixHandle( hComm
, GENERIC_READ
);
1557 FIXME("no fd for handle = %0x!.\n",hComm
);
1561 if (-1==tcgetattr(fd
,&tios
)) {
1562 FIXME("tcgetattr on fd %d failed!\n",fd
);
1566 /* VTIME is in 1/10 seconds */
1568 unsigned int ux_timeout
;
1570 if(lptimeouts
->ReadIntervalTimeout
== 0) /* 0 means no timeout */
1576 ux_timeout
= (lptimeouts
->ReadIntervalTimeout
+99)/100;
1579 ux_timeout
= 1; /* must be at least some timeout */
1582 tios
.c_cc
[VTIME
] = ux_timeout
;
1585 if (-1==tcsetattr(fd
,0,&tios
)) {
1586 FIXME("tcsetattr on fd %d failed!\n",fd
);
1593 /***********************************************************************
1594 * GetCommModemStatus (KERNEL32.@)
1596 * Obtains the four control register bits if supported by the hardware.
1600 * True if the communications handle was good and for hardware that
1601 * control register access, false otherwise.
1603 BOOL WINAPI
GetCommModemStatus(
1604 HANDLE hFile
, /* [in] The communications device. */
1605 LPDWORD lpModemStat
) /* [out] The control register bits. */
1607 int fd
,mstat
, result
=FALSE
;
1611 fd
= FILE_GetUnixHandle( hFile
, GENERIC_READ
);
1614 result
= ioctl(fd
, TIOCMGET
, &mstat
);
1618 WARN("ioctl failed\n");
1622 if (mstat
& TIOCM_CTS
)
1623 *lpModemStat
|= MS_CTS_ON
;
1626 if (mstat
& TIOCM_DSR
)
1627 *lpModemStat
|= MS_DSR_ON
;
1630 if (mstat
& TIOCM_RNG
)
1631 *lpModemStat
|= MS_RING_ON
;
1634 /*FIXME: Not really sure about RLSD UB 990810*/
1635 if (mstat
& TIOCM_CAR
)
1636 *lpModemStat
|= MS_RLSD_ON
;
1638 TRACE("%04x -> %s%s%s%s\n", mstat
,
1639 (*lpModemStat
&MS_RLSD_ON
)?"MS_RLSD_ON ":"",
1640 (*lpModemStat
&MS_RING_ON
)?"MS_RING_ON ":"",
1641 (*lpModemStat
&MS_DSR_ON
)?"MS_DSR_ON ":"",
1642 (*lpModemStat
&MS_CTS_ON
)?"MS_CTS_ON ":"");
1649 /***********************************************************************
1650 * COMM_WaitCommEventService (INTERNAL)
1652 * This function is called while the client is waiting on the
1653 * server, so we can't make any server calls here.
1655 static void COMM_WaitCommEventService(async_private
*ovp
)
1657 async_commio
*commio
= (async_commio
*) ovp
;
1658 LPOVERLAPPED lpOverlapped
= commio
->lpOverlapped
;
1660 TRACE("overlapped %p\n",lpOverlapped
);
1662 /* FIXME: detect other events */
1663 *commio
->buffer
= EV_RXCHAR
;
1665 lpOverlapped
->Internal
= STATUS_SUCCESS
;
1669 /***********************************************************************
1670 * COMM_WaitCommEvent (INTERNAL)
1672 * This function must have an lpOverlapped.
1674 static BOOL
COMM_WaitCommEvent(
1675 HANDLE hFile
, /* [in] handle of comm port to wait for */
1676 LPDWORD lpdwEvents
, /* [out] event(s) that were detected */
1677 LPOVERLAPPED lpOverlapped
) /* [in/out] for Asynchronous waiting */
1684 SetLastError(ERROR_INVALID_PARAMETER
);
1688 if(NtResetEvent(lpOverlapped
->hEvent
,NULL
))
1691 fd
= FILE_GetUnixHandle( hFile
, GENERIC_WRITE
);
1695 ovp
= (async_commio
*) HeapAlloc(GetProcessHeap(), 0, sizeof (async_commio
));
1702 ovp
->async
.ops
= &commio_async_ops
;
1703 ovp
->async
.handle
= hFile
;
1705 ovp
->async
.type
= ASYNC_TYPE_WAIT
;
1706 ovp
->async
.func
= COMM_WaitCommEventService
;
1707 ovp
->async
.event
= lpOverlapped
->hEvent
;
1708 ovp
->lpOverlapped
= lpOverlapped
;
1709 ovp
->buffer
= (char *)lpdwEvents
;
1711 lpOverlapped
->InternalHigh
= 0;
1712 lpOverlapped
->Offset
= 0;
1713 lpOverlapped
->OffsetHigh
= 0;
1715 if ( !register_new_async (&ovp
->async
) )
1716 SetLastError( ERROR_IO_PENDING
);
1721 /***********************************************************************
1722 * WaitCommEvent (KERNEL32.@)
1724 * Wait until something interesting happens on a COMM port.
1725 * Interesting things (events) are set by calling SetCommMask before
1726 * this function is called.
1729 * TRUE if successful
1732 * The set of detected events will be written to *lpdwEventMask
1733 * ERROR_IO_PENDING will be returned the overlapped structure was passed
1736 * Only supports EV_RXCHAR and EV_TXEMPTY
1738 BOOL WINAPI
WaitCommEvent(
1739 HANDLE hFile
, /* [in] handle of comm port to wait for */
1740 LPDWORD lpdwEvents
, /* [out] event(s) that were detected */
1741 LPOVERLAPPED lpOverlapped
) /* [in/out] for Asynchronous waiting */
1746 TRACE("(%x %p %p )\n",hFile
, lpdwEvents
,lpOverlapped
);
1749 return COMM_WaitCommEvent(hFile
, lpdwEvents
, lpOverlapped
);
1751 /* if there is no overlapped structure, create our own */
1752 ov
.hEvent
= CreateEventA(NULL
,FALSE
,FALSE
,NULL
);
1754 COMM_WaitCommEvent(hFile
, lpdwEvents
, &ov
);
1756 if(GetLastError()!=STATUS_PENDING
)
1758 CloseHandle(ov
.hEvent
);
1762 /* wait for the overlapped to complete */
1763 ret
= GetOverlappedResult(hFile
, &ov
, NULL
, TRUE
);
1764 CloseHandle(ov
.hEvent
);
1769 /***********************************************************************
1770 * GetCommProperties (KERNEL32.@)
1772 * This function fills in a structure with the capabilities of the
1773 * communications port driver.
1777 * TRUE on success, FALSE on failure
1778 * If successful, the lpCommProp structure be filled in with
1779 * properties of the comm port.
1781 BOOL WINAPI
GetCommProperties(
1782 HANDLE hFile
, /* [in] handle of the comm port */
1783 LPCOMMPROP lpCommProp
) /* [out] pointer to struct to be filled */
1785 FIXME("(%d %p )\n",hFile
,lpCommProp
);
1790 * These values should be valid for LINUX's serial driver
1791 * FIXME: Perhaps they deserve an #ifdef LINUX
1793 memset(lpCommProp
,0,sizeof(COMMPROP
));
1794 lpCommProp
->wPacketLength
= 1;
1795 lpCommProp
->wPacketVersion
= 1;
1796 lpCommProp
->dwServiceMask
= SP_SERIALCOMM
;
1797 lpCommProp
->dwReserved1
= 0;
1798 lpCommProp
->dwMaxTxQueue
= 4096;
1799 lpCommProp
->dwMaxRxQueue
= 4096;
1800 lpCommProp
->dwMaxBaud
= BAUD_115200
;
1801 lpCommProp
->dwProvSubType
= PST_RS232
;
1802 lpCommProp
->dwProvCapabilities
= PCF_DTRDSR
| PCF_PARITY_CHECK
| PCF_RTSCTS
| PCF_TOTALTIMEOUTS
;
1803 lpCommProp
->dwSettableParams
= SP_BAUD
| SP_DATABITS
| SP_HANDSHAKING
|
1804 SP_PARITY
| SP_PARITY_CHECK
| SP_STOPBITS
;
1805 lpCommProp
->dwSettableBaud
= BAUD_075
| BAUD_110
| BAUD_134_5
| BAUD_150
|
1806 BAUD_300
| BAUD_600
| BAUD_1200
| BAUD_1800
| BAUD_2400
| BAUD_4800
|
1807 BAUD_9600
| BAUD_19200
| BAUD_38400
| BAUD_57600
| BAUD_115200
;
1808 lpCommProp
->wSettableData
= DATABITS_5
| DATABITS_6
| DATABITS_7
| DATABITS_8
;
1809 lpCommProp
->wSettableStopParity
= STOPBITS_10
| STOPBITS_15
| STOPBITS_20
|
1810 PARITY_NONE
| PARITY_ODD
|PARITY_EVEN
| PARITY_MARK
| PARITY_SPACE
;
1811 lpCommProp
->dwCurrentTxQueue
= lpCommProp
->dwMaxTxQueue
;
1812 lpCommProp
->dwCurrentRxQueue
= lpCommProp
->dwMaxRxQueue
;
1817 /***********************************************************************
1819 * The functionality of CommConfigDialogA, GetDefaultCommConfig and
1820 * SetDefaultCommConfig is implemented in a DLL (usually SERIALUI.DLL).
1821 * This is dependent on the type of COMM port, but since it is doubtful
1822 * anybody will get around to implementing support for fancy serial
1823 * ports in WINE, this is hardcoded for the time being. The name of
1824 * this DLL should be stored in and read from the system registry in
1825 * the hive HKEY_LOCAL_MACHINE, key
1826 * System\\CurrentControlSet\\Services\\Class\\Ports\\????
1827 * where ???? is the port number... that is determined by PNP
1828 * The DLL should be loaded when the COMM port is opened, and closed
1829 * when the COMM port is closed. - MJM 20 June 2000
1830 ***********************************************************************/
1831 static CHAR lpszSerialUI
[] = "serialui.dll";
1834 /***********************************************************************
1835 * CommConfigDialogA (KERNEL32.@)
1837 * Raises a dialog that allows the user to configure a comm port.
1838 * Fills the COMMCONFIG struct with information specified by the user.
1839 * This function should call a similar routine in the COMM driver...
1843 * TRUE on success, FALSE on failure
1844 * If successful, the lpCommConfig structure will contain a new
1845 * configuration for the comm port, as specified by the user.
1848 * The library with the CommConfigDialog code is never unloaded.
1849 * Perhaps this should be done when the comm port is closed?
1851 BOOL WINAPI
CommConfigDialogA(
1852 LPCSTR lpszDevice
, /* [in] name of communications device */
1853 HANDLE hWnd
, /* [in] parent window for the dialog */
1854 LPCOMMCONFIG lpCommConfig
) /* [out] pointer to struct to fill */
1856 FARPROC lpfnCommDialog
;
1857 HMODULE hConfigModule
;
1860 TRACE("(%p %x %p)\n",lpszDevice
, hWnd
, lpCommConfig
);
1862 hConfigModule
= LoadLibraryA(lpszSerialUI
);
1866 lpfnCommDialog
= GetProcAddress(hConfigModule
, (LPCSTR
)3L);
1871 r
= lpfnCommDialog(lpszDevice
,hWnd
,lpCommConfig
);
1873 /* UnloadLibrary(hConfigModule); */
1878 /***********************************************************************
1879 * CommConfigDialogW (KERNEL32.@)
1881 * see CommConfigDialogA for more info
1883 BOOL WINAPI
CommConfigDialogW(
1884 LPCWSTR lpszDevice
, /* [in] name of communications device */
1885 HANDLE hWnd
, /* [in] parent window for the dialog */
1886 LPCOMMCONFIG lpCommConfig
) /* [out] pointer to struct to fill */
1891 lpDeviceA
= HEAP_strdupWtoA( GetProcessHeap(), 0, lpszDevice
);
1894 r
= CommConfigDialogA(lpDeviceA
,hWnd
,lpCommConfig
);
1895 HeapFree( GetProcessHeap(), 0, lpDeviceA
);
1899 /***********************************************************************
1900 * GetCommConfig (KERNEL32.@)
1902 * Fill in the COMMCONFIG structure for the comm port hFile
1906 * TRUE on success, FALSE on failure
1907 * If successful, lpCommConfig contains the comm port configuration.
1912 BOOL WINAPI
GetCommConfig(
1913 HANDLE hFile
, /* [in] The communications device. */
1914 LPCOMMCONFIG lpCommConfig
, /* [out] The communications configuration of the device (if it fits). */
1915 LPDWORD lpdwSize
) /* [in/out] Initially the size of the configuration buffer/structure,
1916 afterwards the number of bytes copied to the buffer or
1917 the needed size of the buffer. */
1921 TRACE("(%x %p)\n",hFile
,lpCommConfig
);
1923 if(lpCommConfig
== NULL
)
1926 r
= *lpdwSize
< sizeof(COMMCONFIG
);
1927 *lpdwSize
= sizeof(COMMCONFIG
);
1931 lpCommConfig
->dwSize
= sizeof(COMMCONFIG
);
1932 lpCommConfig
->wVersion
= 1;
1933 lpCommConfig
->wReserved
= 0;
1934 r
= GetCommState(hFile
,&lpCommConfig
->dcb
);
1935 lpCommConfig
->dwProviderSubType
= PST_RS232
;
1936 lpCommConfig
->dwProviderOffset
= 0;
1937 lpCommConfig
->dwProviderSize
= 0;
1942 /***********************************************************************
1943 * SetCommConfig (KERNEL32.@)
1945 * Sets the configuration of the communications device.
1949 * True on success, false if the handle was bad is not a communications device.
1951 BOOL WINAPI
SetCommConfig(
1952 HANDLE hFile
, /* [in] The communications device. */
1953 LPCOMMCONFIG lpCommConfig
, /* [in] The desired configuration. */
1954 DWORD dwSize
) /* [in] size of the lpCommConfig struct */
1956 TRACE("(%x %p)\n",hFile
,lpCommConfig
);
1957 return SetCommState(hFile
,&lpCommConfig
->dcb
);
1960 /***********************************************************************
1961 * SetDefaultCommConfigA (KERNEL32.@)
1963 * Initializes the default configuration for the specified communication
1968 * True if the device was found and the defaults set, false otherwise
1970 BOOL WINAPI
SetDefaultCommConfigA(
1971 LPCSTR lpszDevice
, /* [in] The ascii name of the device targeted for configuration. */
1972 LPCOMMCONFIG lpCommConfig
, /* [in] The default configuration for the device. */
1973 DWORD dwSize
) /* [in] The number of bytes in the configuration structure. */
1975 FARPROC lpfnSetDefaultCommConfig
;
1976 HMODULE hConfigModule
;
1979 TRACE("(%p %p %lx)\n",lpszDevice
, lpCommConfig
, dwSize
);
1981 hConfigModule
= LoadLibraryA(lpszSerialUI
);
1985 lpfnSetDefaultCommConfig
= GetProcAddress(hConfigModule
, (LPCSTR
)4L);
1987 if(! lpfnSetDefaultCommConfig
)
1990 r
= lpfnSetDefaultCommConfig(lpszDevice
, lpCommConfig
, dwSize
);
1992 /* UnloadLibrary(hConfigModule); */
1998 /***********************************************************************
1999 * SetDefaultCommConfigW (KERNEL32.@)
2001 * Initializes the default configuration for the specified
2002 * communication device. (unicode)
2007 BOOL WINAPI
SetDefaultCommConfigW(
2008 LPCWSTR lpszDevice
, /* [in] The unicode name of the device targeted for configuration. */
2009 LPCOMMCONFIG lpCommConfig
, /* [in] The default configuration for the device. */
2010 DWORD dwSize
) /* [in] The number of bytes in the configuration structure. */
2015 TRACE("(%s %p %lx)\n",debugstr_w(lpszDevice
),lpCommConfig
,dwSize
);
2017 lpDeviceA
= HEAP_strdupWtoA( GetProcessHeap(), 0, lpszDevice
);
2020 r
= SetDefaultCommConfigA(lpDeviceA
,lpCommConfig
,dwSize
);
2021 HeapFree( GetProcessHeap(), 0, lpDeviceA
);
2026 /***********************************************************************
2027 * GetDefaultCommConfigA (KERNEL32.@)
2029 * Acquires the default configuration of the specified communication device. (unicode)
2033 * True on successful reading of the default configuration,
2034 * if the device is not found or the buffer is too small.
2036 BOOL WINAPI
GetDefaultCommConfigA(
2037 LPCSTR lpszName
, /* [in] The ascii name of the device targeted for configuration. */
2038 LPCOMMCONFIG lpCC
, /* [out] The default configuration for the device. */
2039 LPDWORD lpdwSize
) /* [in/out] Initially the size of the default configuration buffer,
2040 afterwards the number of bytes copied to the buffer or
2041 the needed size of the buffer. */
2043 LPDCB lpdcb
= &(lpCC
->dcb
);
2046 if (strncasecmp(lpszName
,"COM",3)) {
2047 ERR("not implemented for <%s>\n", lpszName
);
2051 TRACE("(%s %p %ld)\n", lpszName
, lpCC
, *lpdwSize
);
2052 if (*lpdwSize
< sizeof(COMMCONFIG
)) {
2053 *lpdwSize
= sizeof(COMMCONFIG
);
2057 *lpdwSize
= sizeof(COMMCONFIG
);
2059 lpCC
->dwSize
= sizeof(COMMCONFIG
);
2061 lpCC
->dwProviderSubType
= PST_RS232
;
2062 lpCC
->dwProviderOffset
= 0L;
2063 lpCC
->dwProviderSize
= 0L;
2065 sprintf( temp
, "COM%c:38400,n,8,1", lpszName
[3]);
2066 FIXME("setting %s as default\n", temp
);
2068 return BuildCommDCBA( temp
, lpdcb
);
2071 /**************************************************************************
2072 * GetDefaultCommConfigW (KERNEL32.@)
2074 * Acquires the default configuration of the specified communication device. (unicode)
2078 * True on successful reading of the default configuration,
2079 * if the device is not found or the buffer is too small.
2081 BOOL WINAPI
GetDefaultCommConfigW(
2082 LPCWSTR lpszName
, /* [in] The unicode name of the device targeted for configuration. */
2083 LPCOMMCONFIG lpCC
, /* [out] The default configuration for the device. */
2084 LPDWORD lpdwSize
) /* [in/out] Initially the size of the default configuration buffer,
2085 afterwards the number of bytes copied to the buffer or
2086 the needed size of the buffer. */
2091 TRACE("(%p,%p,%ld)\n",lpszName
,lpCC
,*lpdwSize
);
2092 lpszNameA
= HEAP_strdupWtoA( GetProcessHeap(), 0, lpszName
);
2095 ret
=GetDefaultCommConfigA(lpszNameA
,lpCC
,lpdwSize
);
2096 HeapFree( GetProcessHeap(), 0, lpszNameA
);