2 * DEC 93 Erik Bos <erik@xs4all.nl>
4 * Copyright 1996 Marcus Meissner
15 #if defined(__NetBSD__) || defined(__FreeBSD__)
16 #include <sys/ioctl.h>
28 int commerror
= 0, eventmask
= 0;
30 struct DosDeviceStruct COM
[MAX_PORTS
];
31 struct DosDeviceStruct LPT
[MAX_PORTS
];
36 char option
[10], temp
[256], *btemp
;
39 for (x
=0; x
!=MAX_PORTS
; x
++) {
40 strcpy(option
,"COMx");
44 PROFILE_GetWineIniString( "serialports", option
, "*",
46 if (!strcmp(temp
, "*") || *temp
== '\0')
47 COM
[x
].devicename
= NULL
;
49 btemp
= strchr(temp
,',');
52 COM
[x
].baudrate
= atoi(btemp
);
57 if (!S_ISCHR(st
.st_mode
))
58 fprintf(stderr
,"comm: can't use `%s' as %s !\n", temp
, option
);
60 if ((COM
[x
].devicename
= malloc(strlen(temp
)+1)) == NULL
)
61 fprintf(stderr
,"comm: can't malloc for device info!\n");
64 strcpy(COM
[x
].devicename
, temp
);
67 "Comm_Init: %s = %s\n", option
, COM
[x
].devicename
);
70 strcpy(option
, "LPTx");
74 PROFILE_GetWineIniString( "parallelports", option
, "*",
76 if (!strcmp(temp
, "*") || *temp
== '\0')
77 LPT
[x
].devicename
= NULL
;
80 if (!S_ISCHR(st
.st_mode
))
81 fprintf(stderr
,"comm: can't use `%s' as %s !\n", temp
, option
);
83 if ((LPT
[x
].devicename
= malloc(strlen(temp
)+1)) == NULL
)
84 fprintf(stderr
,"comm: can't malloc for device info!\n");
87 strcpy(LPT
[x
].devicename
, temp
);
90 "Comm_Init: %s = %s\n", option
, LPT
[x
].devicename
);
97 struct DosDeviceStruct
*GetDeviceStruct(int fd
)
101 for (x
=0; x
!=MAX_PORTS
; x
++) {
111 int ValidCOMPort(int x
)
113 return(x
< MAX_PORTS
? (int) COM
[x
].devicename
: 0);
116 int ValidLPTPort(int x
)
118 return(x
< MAX_PORTS
? (int) LPT
[x
].devicename
: 0);
123 dprintf_comm(stddeb
, "WinError: errno = %d\n", errno
);
130 /**************************************************************************
131 * BuildCommDCB (USER.213)
133 BOOL16
BuildCommDCB16(LPCSTR device
, LPDCB16 lpdcb
)
135 /* "COM1:9600,n,8,1" */
138 char *ptr
, temp
[256];
141 "BuildCommDCB: (%s), ptr %p\n", device
, lpdcb
);
144 if (!lstrncmpi32A(device
,"COM",3)) {
145 port
= device
[3] - '0';
149 fprintf(stderr
, "comm: BUG ! COM0 can't exists!.\n");
150 commerror
= IE_BADID
;
153 if (!ValidCOMPort(port
)) {
154 commerror
= IE_BADID
;
159 OpenComm(device
, 0, 0);
161 lpdcb
->Id
= COM
[port
].fd
;
166 if (*(device
+4) != ':')
169 strcpy(temp
,device
+5);
170 ptr
= strtok(temp
, ", ");
172 if (COM
[port
].baudrate
> 0)
173 lpdcb
->BaudRate
= COM
[port
].baudrate
;
175 lpdcb
->BaudRate
= atoi(ptr
);
176 dprintf_comm(stddeb
,"BuildCommDCB: baudrate (%d)\n", lpdcb
->BaudRate
);
178 ptr
= strtok(NULL
, ", ");
180 *ptr
= toupper(*ptr
);
182 dprintf_comm(stddeb
,"BuildCommDCB: parity (%c)\n", *ptr
);
186 lpdcb
->Parity
= NOPARITY
;
190 lpdcb
->Parity
= EVENPARITY
;
193 lpdcb
->Parity
= MARKPARITY
;
196 lpdcb
->Parity
= ODDPARITY
;
199 fprintf(stderr
,"comm: unknown parity `%c'!\n", *ptr
);
203 ptr
= strtok(NULL
, ", ");
204 dprintf_comm(stddeb
, "BuildCommDCB: charsize (%c)\n", *ptr
);
205 lpdcb
->ByteSize
= *ptr
- '0';
207 ptr
= strtok(NULL
, ", ");
208 dprintf_comm(stddeb
, "BuildCommDCB: stopbits (%c)\n", *ptr
);
211 lpdcb
->StopBits
= ONESTOPBIT
;
214 lpdcb
->StopBits
= TWOSTOPBITS
;
217 fprintf(stderr
,"comm: unknown # of stopbits `%c'!\n", *ptr
);
225 /**************************************************************************
226 * BuildCommDCBA (KERNEL32.14)
228 BOOL32
BuildCommDCB32A(LPCSTR device
,LPDCB32 lpdcb
) {
229 return BuildCommDCBAndTimeouts32A(device
,lpdcb
,NULL
);
232 /**************************************************************************
233 * BuildCommDCBAndTimeoutsA (KERNEL32.15)
235 BOOL32
BuildCommDCBAndTimeouts32A(LPCSTR device
, LPDCB32 lpdcb
,LPCOMMTIMEOUTS lptimeouts
) {
239 dprintf_comm(stddeb
,"BuildCommDCBAndTimeouts32A(%s,%p,%p)\n",device
,lpdcb
,lptimeouts
);
242 if (!lstrncmpi32A(device
,"COM",3)) {
245 fprintf(stderr
,"comm:BUG! COM0 can't exists!.\n");
248 if (!ValidCOMPort(port
))
250 if (*(device
+4)!=':')
252 temp
=(LPSTR
)(device
+5);
255 lpdcb
->DCBlength
= sizeof(DCB32
);
256 if (strchr(temp
,',')) { /* old style */
259 char last
=temp
[strlen(temp
)-1];
261 ret
=BuildCommDCB16(device
,&dcb16
);
264 lpdcb
->BaudRate
= dcb16
.BaudRate
;
265 lpdcb
->ByteSize
= dcb16
.ByteSize
;
266 lpdcb
->fBinary
= dcb16
.fBinary
;
267 lpdcb
->Parity
= dcb16
.Parity
;
268 lpdcb
->fParity
= dcb16
.fParity
;
269 lpdcb
->fNull
= dcb16
.fNull
;
270 lpdcb
->StopBits
= dcb16
.StopBits
;
274 lpdcb
->fOutxCtsFlow
= FALSE
;
275 lpdcb
->fOutxDsrFlow
= FALSE
;
276 lpdcb
->fDtrControl
= DTR_CONTROL_ENABLE
;
277 lpdcb
->fRtsControl
= RTS_CONTROL_ENABLE
;
278 } else if (last
=='p') {
280 lpdcb
->fOutX
= FALSE
;
281 lpdcb
->fOutxCtsFlow
= TRUE
;
282 lpdcb
->fOutxDsrFlow
= TRUE
;
283 lpdcb
->fDtrControl
= DTR_CONTROL_HANDSHAKE
;
284 lpdcb
->fRtsControl
= RTS_CONTROL_HANDSHAKE
;
287 lpdcb
->fOutX
= FALSE
;
288 lpdcb
->fOutxCtsFlow
= FALSE
;
289 lpdcb
->fOutxDsrFlow
= FALSE
;
290 lpdcb
->fDtrControl
= DTR_CONTROL_ENABLE
;
291 lpdcb
->fRtsControl
= RTS_CONTROL_ENABLE
;
293 lpdcb
->XonChar
= dcb16
.XonChar
;
294 lpdcb
->XoffChar
= dcb16
.XoffChar
;
295 lpdcb
->ErrorChar
= dcb16
.PeChar
;
296 lpdcb
->fErrorChar
= dcb16
.fPeChar
;
297 lpdcb
->EofChar
= dcb16
.EofChar
;
298 lpdcb
->EvtChar
= dcb16
.EvtChar
;
299 lpdcb
->XonLim
= dcb16
.XonLim
;
300 lpdcb
->XoffLim
= dcb16
.XoffLim
;
303 ptr
=strtok(temp
," ");
308 if (!strncmp("baud=",ptr
,5)) {
309 if (!sscanf(ptr
+5,"%ld",&x
))
310 fprintf(stderr
,"BuildCommDCB32A:Couldn't parse %s\n",ptr
);
314 if (!strncmp("stop=",ptr
,5)) {
315 if (!sscanf(ptr
+5,"%ld",&x
))
316 fprintf(stderr
,"BuildCommDCB32A:Couldn't parse %s\n",ptr
);
320 if (!strncmp("data=",ptr
,5)) {
321 if (!sscanf(ptr
+5,"%ld",&x
))
322 fprintf(stderr
,"BuildCommDCB32A:Couldn't parse %s\n",ptr
);
326 if (!strncmp("parity=",ptr
,7)) {
327 lpdcb
->fParity
= TRUE
;
330 lpdcb
->fParity
= FALSE
;
331 lpdcb
->Parity
= NOPARITY
;
334 lpdcb
->Parity
= EVENPARITY
;
337 lpdcb
->Parity
= ODDPARITY
;
340 lpdcb
->Parity
= MARKPARITY
;
346 fprintf(stderr
,"BuildCommDCB32A: Unhandled specifier '%s', please report.\n",ptr
);
347 ptr
=strtok(NULL
," ");
349 if (lpdcb
->BaudRate
==110)
354 /**************************************************************************
355 * BuildCommDCBAndTimeoutsW (KERNEL32.16)
357 BOOL32
BuildCommDCBAndTimeouts32W(
358 LPCWSTR devid
,LPDCB32 lpdcb
,LPCOMMTIMEOUTS lptimeouts
363 dprintf_comm(stddeb
,"BuildCommDCBAndTimeouts32W(%p,%p,%p)\n",devid
,lpdcb
,lptimeouts
);
364 devidA
= STRING32_DupUniToAnsi(devid
);
365 ret
=BuildCommDCBAndTimeouts32A(devidA
,lpdcb
,lptimeouts
);
370 /**************************************************************************
371 * BuildCommDCBW (KERNEL32.17)
373 BOOL32
BuildCommDCB32W(LPCWSTR devid
,LPDCB32 lpdcb
) {
374 return BuildCommDCBAndTimeouts32W(devid
,lpdcb
,NULL
);
377 /*****************************************************************************
378 * OpenComm (USER.200)
380 INT16
OpenComm(LPCSTR device
,UINT16 cbInQueue
,UINT16 cbOutQueue
)
385 "OpenComm: %s, %d, %d\n", device
, cbInQueue
, cbOutQueue
);
388 if (!lstrncmpi32A(device
,"COM",3)) {
389 port
= device
[3] - '0';
392 fprintf(stderr
, "comm: BUG ! COM0 doesn't exists!.\n");
393 commerror
= IE_BADID
;
397 "OpenComm: %s = %s\n", device
, COM
[port
].devicename
);
399 if (!ValidCOMPort(port
)) {
400 commerror
= IE_BADID
;
407 fd
= open(COM
[port
].devicename
, O_RDWR
| O_NONBLOCK
);
409 commerror
= WinError();
417 if (!lstrncmpi32A(device
,"LPT",3)) {
418 port
= device
[3] - '0';
420 if (!ValidLPTPort(port
)) {
421 commerror
= IE_BADID
;
429 fd
= open(LPT
[port
].devicename
, O_RDWR
| O_NONBLOCK
, 0);
431 commerror
= WinError();
441 /*****************************************************************************
442 * CloseComm (USER.207)
444 INT16
CloseComm(INT16 fd
)
446 dprintf_comm(stddeb
,"CloseComm: fd %d\n", fd
);
447 if (close(fd
) == -1) {
448 commerror
= WinError();
456 /*****************************************************************************
457 * SetCommBreak (USER.210)
459 INT16
SetCommBreak16(INT16 fd
)
461 struct DosDeviceStruct
*ptr
;
463 dprintf_comm(stddeb
,"SetCommBreak: fd: %d\n", fd
);
464 if ((ptr
= GetDeviceStruct(fd
)) == NULL
) {
465 commerror
= IE_BADID
;
474 /*****************************************************************************
475 * SetCommBreak (KERNEL32.449)
477 BOOL32
SetCommBreak32(HANDLE32 hfile
)
479 FILE_OBJECT
*fob
= (FILE_OBJECT
*)hfile
;
482 struct DosDeviceStruct
*ptr
;
484 dprintf_comm(stddeb
,"SetCommBreak: fd: %d\n", fd
);
485 if ((ptr
= GetDeviceStruct(fd
)) == NULL
) {
486 commerror
= IE_BADID
;
495 /*****************************************************************************
496 * ClearCommBreak (USER.211)
498 INT16
ClearCommBreak16(INT16 fd
)
500 struct DosDeviceStruct
*ptr
;
502 dprintf_comm(stddeb
,"ClearCommBreak: fd: %d\n", fd
);
503 if ((ptr
= GetDeviceStruct(fd
)) == NULL
) {
504 commerror
= IE_BADID
;
513 /*****************************************************************************
514 * ClearCommBreak (KERNEL32.20)
516 BOOL32
ClearCommBreak32(HANDLE32 hfile
)
518 FILE_OBJECT
*fob
= (FILE_OBJECT
*)hfile
;
520 struct DosDeviceStruct
*ptr
;
522 dprintf_comm(stddeb
,"ClearCommBreak: fd: %d\n", fd
);
523 if ((ptr
= GetDeviceStruct(fd
)) == NULL
) {
524 commerror
= IE_BADID
;
533 /*****************************************************************************
534 * EscapeCommFunction (USER.214)
536 LONG
EscapeCommFunction16(UINT16 fd
,UINT16 nFunction
)
541 dprintf_comm(stddeb
,"EscapeCommFunction fd: %d, function: %d\n", fd
, nFunction
);
542 if (tcgetattr(fd
,&port
) == -1) {
543 commerror
=WinError();
552 for (max
= MAX_PORTS
;!COM
[max
].devicename
;max
--)
558 for (max
= MAX_PORTS
;!LPT
[max
].devicename
;max
--)
565 port
.c_cflag
&= TIOCM_DTR
;
571 port
.c_cflag
&= TIOCM_RTS
;
577 port
.c_cflag
|= CRTSCTS
;
581 port
.c_cflag
|= CRTSCTS
;
586 port
.c_iflag
|= IXOFF
;
590 port
.c_iflag
|= IXON
;
595 "EscapeCommFunction fd: %d, unknown function: %d\n",
600 if (tcsetattr(fd
, TCSADRAIN
, &port
) == -1) {
601 commerror
= WinError();
609 /*****************************************************************************
610 * EscapeCommFunction (KERNEL32.214)
612 BOOL32
EscapeCommFunction32(HANDLE32 hfile
,UINT32 nFunction
)
614 FILE_OBJECT
*fob
= (FILE_OBJECT
*)hfile
;
617 struct DosDeviceStruct
*ptr
;
619 dprintf_comm(stddeb
,"EscapeCommFunction fd: %d, function: %d\n", fd
, nFunction
);
620 if (tcgetattr(fd
,&port
) == -1) {
621 commerror
=WinError();
624 if ((ptr
= GetDeviceStruct(fd
)) == NULL
) {
625 commerror
= IE_BADID
;
635 port
.c_cflag
&= TIOCM_DTR
;
641 port
.c_cflag
&= TIOCM_RTS
;
647 port
.c_cflag
|= CRTSCTS
;
651 port
.c_cflag
|= CRTSCTS
;
656 port
.c_iflag
|= IXOFF
;
660 port
.c_iflag
|= IXON
;
670 "EscapeCommFunction32 fd: %d, unknown function: %d\n",
675 if (tcsetattr(fd
, TCSADRAIN
, &port
) == -1) {
676 commerror
= WinError();
684 /*****************************************************************************
685 * FlushComm (USER.215)
687 INT16
FlushComm(INT16 fd
,INT16 fnQueue
)
691 dprintf_comm(stddeb
,"FlushComm fd: %d, queue: %d\n", fd
, fnQueue
);
693 case 0: queue
= TCOFLUSH
;
695 case 1: queue
= TCIFLUSH
;
697 default:fprintf(stderr
,
698 "FlushComm fd: %d, UNKNOWN queue: %d\n",
702 if (tcflush(fd
, fnQueue
)) {
703 commerror
= WinError();
711 /*****************************************************************************
712 * GetCommError (USER.203)
714 INT16
GetCommError(INT16 fd
,LPCOMSTAT lpStat
)
719 "GetCommError: fd %d (current error %d)\n", fd
, commerror
);
720 temperror
= commerror
;
725 /*****************************************************************************
726 * ClearCommError (KERNEL32.21)
728 BOOL32
ClearCommError(HANDLE32 hfile
,LPDWORD errors
,LPCOMSTAT lpStat
)
731 FILE_OBJECT
*fob
=(FILE_OBJECT
*)hfile
;
735 "ClearCommError: fd %d (current error %d)\n", fd
, commerror
);
736 temperror
= commerror
;
741 /*****************************************************************************
742 * SetCommEventMask (USER.208)
744 UINT16
*SetCommEventMask(INT16 fd
,UINT16 fuEvtMask
)
746 dprintf_comm(stddeb
,"SetCommEventMask:fd %d,mask %d\n",fd
,fuEvtMask
);
747 eventmask
|= fuEvtMask
;
748 return (UINT
*)&eventmask
; /* FIXME, should be SEGPTR */
751 /*****************************************************************************
752 * GetCommEventMask (USER.209)
754 UINT16
GetCommEventMask(INT16 fd
,UINT16 fnEvtClear
)
757 "GetCommEventMask: fd %d, mask %d\n", fd
, fnEvtClear
);
758 eventmask
&= ~fnEvtClear
;
762 /*****************************************************************************
763 * GetCommMask (KERNEL32.156)
765 BOOL32
GetCommMask(HANDLE32 hfile
,LPDWORD evtmask
)
767 FILE_OBJECT
*fob
=(FILE_OBJECT
*)hfile
;
771 "GetCommMask: fd %d, mask %p\n", fd
, evtmask
);
772 *evtmask
= eventmask
;
776 /*****************************************************************************
777 * SetCommMask (KERNEL32.451)
779 BOOL32
SetCommMask(HANDLE32 hfile
,DWORD evtmask
)
781 FILE_OBJECT
*fob
=(FILE_OBJECT
*)hfile
;
785 "SetCommMask: fd %d, mask %lx\n", fd
, evtmask
);
790 /*****************************************************************************
791 * SetCommState16 (USER.201)
793 INT16
SetCommState16(LPDCB16 lpdcb
)
796 struct DosDeviceStruct
*ptr
;
799 "SetCommState: fd %d, ptr %p\n", lpdcb
->Id
, lpdcb
);
800 if (tcgetattr(lpdcb
->Id
, &port
) == -1) {
801 commerror
= WinError();
806 port
.c_cc
[VTIME
] = 1;
809 port
.c_iflag
&= ~(ISTRIP
|BRKINT
|IGNCR
|ICRNL
|INLCR
|IMAXBEL
);
811 port
.c_iflag
&= ~(ISTRIP
|BRKINT
|IGNCR
|ICRNL
|INLCR
);
813 port
.c_iflag
|= (IGNBRK
);
815 port
.c_oflag
&= ~(OPOST
);
817 port
.c_cflag
&= ~(HUPCL
);
818 port
.c_cflag
|= CLOCAL
| CREAD
;
820 port
.c_lflag
&= ~(ICANON
|ECHO
|ISIG
);
821 port
.c_lflag
|= NOFLSH
;
823 if ((ptr
= GetDeviceStruct(lpdcb
->Id
)) == NULL
) {
824 commerror
= IE_BADID
;
827 if (ptr
->baudrate
> 0)
828 lpdcb
->BaudRate
= ptr
->baudrate
;
829 dprintf_comm(stddeb
,"SetCommState: baudrate %d\n",lpdcb
->BaudRate
);
831 port
.c_cflag
&= ~CBAUD
;
832 switch (lpdcb
->BaudRate
) {
835 port
.c_cflag
|= B110
;
839 port
.c_cflag
|= B300
;
843 port
.c_cflag
|= B600
;
847 port
.c_cflag
|= B1200
;
851 port
.c_cflag
|= B2400
;
855 port
.c_cflag
|= B4800
;
859 port
.c_cflag
|= B9600
;
863 port
.c_cflag
|= B19200
;
867 port
.c_cflag
|= B38400
;
870 commerror
= IE_BAUDRATE
;
874 switch (lpdcb
->BaudRate
) {
877 port
.c_ospeed
= B110
;
881 port
.c_ospeed
= B300
;
885 port
.c_ospeed
= B600
;
889 port
.c_ospeed
= B1200
;
893 port
.c_ospeed
= B2400
;
897 port
.c_ospeed
= B4800
;
901 port
.c_ospeed
= B9600
;
905 port
.c_ospeed
= B19200
;
909 port
.c_ospeed
= B38400
;
912 commerror
= IE_BAUDRATE
;
915 port
.c_ispeed
= port
.c_ospeed
;
917 dprintf_comm(stddeb
,"SetCommState: bytesize %d\n",lpdcb
->ByteSize
);
918 port
.c_cflag
&= ~CSIZE
;
919 switch (lpdcb
->ByteSize
) {
933 commerror
= IE_BYTESIZE
;
937 dprintf_comm(stddeb
,"SetCommState: parity %d\n",lpdcb
->Parity
);
938 port
.c_cflag
&= ~(PARENB
| PARODD
);
940 switch (lpdcb
->Parity
) {
942 port
.c_iflag
&= ~INPCK
;
945 port
.c_cflag
|= (PARENB
| PARODD
);
946 port
.c_iflag
|= INPCK
;
949 port
.c_cflag
|= PARENB
;
950 port
.c_iflag
|= INPCK
;
953 commerror
= IE_BYTESIZE
;
958 dprintf_comm(stddeb
,"SetCommState: stopbits %d\n",lpdcb
->StopBits
);
959 switch (lpdcb
->StopBits
) {
961 port
.c_cflag
&= ~CSTOPB
;
964 port
.c_cflag
|= CSTOPB
;
967 commerror
= IE_BYTESIZE
;
972 if (lpdcb
->fDtrflow
|| lpdcb
->fRtsflow
|| lpdcb
->fOutxCtsFlow
)
973 port
.c_cflag
|= CRTSCTS
;
975 if (lpdcb
->fDtrDisable
)
976 port
.c_cflag
&= ~CRTSCTS
;
979 port
.c_iflag
|= IXON
;
981 port
.c_iflag
|= IXOFF
;
983 if (tcsetattr(lpdcb
->Id
, TCSADRAIN
, &port
) == -1) {
984 commerror
= WinError();
992 /*****************************************************************************
993 * SetCommState32 (KERNEL32.452)
995 BOOL32
SetCommState32(HANDLE32 hfile
,LPDCB32 lpdcb
)
997 FILE_OBJECT
*fob
= (FILE_OBJECT
*)hfile
;
1000 struct DosDeviceStruct
*ptr
;
1002 dprintf_comm(stddeb
,"SetCommState: fd %d, ptr %p\n",fd
,lpdcb
);
1003 if (tcgetattr(fd
,&port
) == -1) {
1004 commerror
= WinError();
1008 port
.c_cc
[VMIN
] = 0;
1009 port
.c_cc
[VTIME
] = 1;
1012 port
.c_iflag
&= ~(ISTRIP
|BRKINT
|IGNCR
|ICRNL
|INLCR
|IMAXBEL
);
1014 port
.c_iflag
&= ~(ISTRIP
|BRKINT
|IGNCR
|ICRNL
|INLCR
);
1016 port
.c_iflag
|= (IGNBRK
);
1018 port
.c_oflag
&= ~(OPOST
);
1020 port
.c_cflag
&= ~(HUPCL
);
1021 port
.c_cflag
|= CLOCAL
| CREAD
;
1023 port
.c_lflag
&= ~(ICANON
|ECHO
|ISIG
);
1024 port
.c_lflag
|= NOFLSH
;
1026 if ((ptr
= GetDeviceStruct(fd
)) == NULL
) {
1027 commerror
= IE_BADID
;
1030 if (ptr
->baudrate
> 0)
1031 lpdcb
->BaudRate
= ptr
->baudrate
;
1032 dprintf_comm(stddeb
,"SetCommState: baudrate %ld\n",lpdcb
->BaudRate
);
1034 port
.c_cflag
&= ~CBAUD
;
1035 switch (lpdcb
->BaudRate
) {
1038 port
.c_cflag
|= B110
;
1042 port
.c_cflag
|= B300
;
1046 port
.c_cflag
|= B600
;
1050 port
.c_cflag
|= B1200
;
1054 port
.c_cflag
|= B2400
;
1058 port
.c_cflag
|= B4800
;
1062 port
.c_cflag
|= B9600
;
1066 port
.c_cflag
|= B19200
;
1070 port
.c_cflag
|= B38400
;
1073 commerror
= IE_BAUDRATE
;
1077 switch (lpdcb
->BaudRate
) {
1080 port
.c_ospeed
= B110
;
1084 port
.c_ospeed
= B300
;
1088 port
.c_ospeed
= B600
;
1092 port
.c_ospeed
= B1200
;
1096 port
.c_ospeed
= B2400
;
1100 port
.c_ospeed
= B4800
;
1104 port
.c_ospeed
= B9600
;
1108 port
.c_ospeed
= B19200
;
1112 port
.c_ospeed
= B38400
;
1115 commerror
= IE_BAUDRATE
;
1118 port
.c_ispeed
= port
.c_ospeed
;
1120 dprintf_comm(stddeb
,"SetCommState: bytesize %d\n",lpdcb
->ByteSize
);
1121 port
.c_cflag
&= ~CSIZE
;
1122 switch (lpdcb
->ByteSize
) {
1124 port
.c_cflag
|= CS5
;
1127 port
.c_cflag
|= CS6
;
1130 port
.c_cflag
|= CS7
;
1133 port
.c_cflag
|= CS8
;
1136 commerror
= IE_BYTESIZE
;
1140 dprintf_comm(stddeb
,"SetCommState: parity %d\n",lpdcb
->Parity
);
1141 port
.c_cflag
&= ~(PARENB
| PARODD
);
1143 switch (lpdcb
->Parity
) {
1145 port
.c_iflag
&= ~INPCK
;
1148 port
.c_cflag
|= (PARENB
| PARODD
);
1149 port
.c_iflag
|= INPCK
;
1152 port
.c_cflag
|= PARENB
;
1153 port
.c_iflag
|= INPCK
;
1156 commerror
= IE_BYTESIZE
;
1161 dprintf_comm(stddeb
,"SetCommState: stopbits %d\n",lpdcb
->StopBits
);
1162 switch (lpdcb
->StopBits
) {
1164 port
.c_cflag
&= ~CSTOPB
;
1167 port
.c_cflag
|= CSTOPB
;
1170 commerror
= IE_BYTESIZE
;
1174 if ( lpdcb
->fOutxCtsFlow
||
1175 lpdcb
->fDtrControl
== DTR_CONTROL_ENABLE
||
1176 lpdcb
->fRtsControl
== RTS_CONTROL_ENABLE
1178 port
.c_cflag
|= CRTSCTS
;
1179 if (lpdcb
->fDtrControl
== DTR_CONTROL_DISABLE
)
1180 port
.c_cflag
&= ~CRTSCTS
;
1184 port
.c_iflag
|= IXON
;
1186 port
.c_iflag
|= IXOFF
;
1188 if (tcsetattr(fd
,TCSADRAIN
,&port
)==-1) {
1189 commerror
= WinError();
1198 /*****************************************************************************
1199 * GetCommState (USER.202)
1201 INT16
GetCommState16(INT16 fd
, LPDCB16 lpdcb
)
1203 struct termios port
;
1205 dprintf_comm(stddeb
,"GetCommState: fd %d, ptr %p\n", fd
, lpdcb
);
1206 if (tcgetattr(fd
, &port
) == -1) {
1207 commerror
= WinError();
1212 switch (port
.c_cflag
& CBAUD
) {
1214 switch (port
.c_ospeed
) {
1217 lpdcb
->BaudRate
= 110;
1220 lpdcb
->BaudRate
= 300;
1223 lpdcb
->BaudRate
= 600;
1226 lpdcb
->BaudRate
= 1200;
1229 lpdcb
->BaudRate
= 2400;
1232 lpdcb
->BaudRate
= 4800;
1235 lpdcb
->BaudRate
= 9600;
1238 lpdcb
->BaudRate
= 19200;
1241 lpdcb
->BaudRate
= 38400;
1245 switch (port
.c_cflag
& CSIZE
) {
1247 lpdcb
->ByteSize
= 5;
1250 lpdcb
->ByteSize
= 6;
1253 lpdcb
->ByteSize
= 7;
1256 lpdcb
->ByteSize
= 8;
1260 switch (port
.c_cflag
& ~(PARENB
| PARODD
)) {
1262 lpdcb
->fParity
= NOPARITY
;
1265 lpdcb
->fParity
= EVENPARITY
;
1267 case (PARENB
| PARODD
):
1268 lpdcb
->fParity
= ODDPARITY
;
1272 if (port
.c_cflag
& CSTOPB
)
1273 lpdcb
->StopBits
= TWOSTOPBITS
;
1275 lpdcb
->StopBits
= ONESTOPBIT
;
1277 lpdcb
->RlsTimeout
= 50;
1278 lpdcb
->CtsTimeout
= 50;
1279 lpdcb
->DsrTimeout
= 50;
1283 lpdcb
->fDtrDisable
= 0;
1287 if (port
.c_cflag
& CRTSCTS
) {
1288 lpdcb
->fDtrflow
= 1;
1289 lpdcb
->fRtsflow
= 1;
1290 lpdcb
->fOutxCtsFlow
= 1;
1291 lpdcb
->fOutxDsrFlow
= 1;
1294 lpdcb
->fDtrDisable
= 1;
1296 if (port
.c_iflag
& IXON
)
1301 if (port
.c_iflag
& IXOFF
)
1310 lpdcb
->XoffLim
= 10;
1316 /*****************************************************************************
1317 * GetCommState (KERNEL32.159)
1319 BOOL32
GetCommState32(HANDLE32 hfile
, LPDCB32 lpdcb
)
1321 FILE_OBJECT
*fob
= (FILE_OBJECT
*)hfile
;
1323 struct termios port
;
1326 dprintf_comm(stddeb
,"GetCommState32: fd %d, ptr %p\n", fd
, lpdcb
);
1327 if (tcgetattr(fd
, &port
) == -1) {
1328 commerror
= WinError();
1332 switch (port
.c_cflag
& CBAUD
) {
1334 switch (port
.c_ospeed
) {
1337 lpdcb
->BaudRate
= 110;
1340 lpdcb
->BaudRate
= 300;
1343 lpdcb
->BaudRate
= 600;
1346 lpdcb
->BaudRate
= 1200;
1349 lpdcb
->BaudRate
= 2400;
1352 lpdcb
->BaudRate
= 4800;
1355 lpdcb
->BaudRate
= 9600;
1358 lpdcb
->BaudRate
= 19200;
1361 lpdcb
->BaudRate
= 38400;
1365 switch (port
.c_cflag
& CSIZE
) {
1367 lpdcb
->ByteSize
= 5;
1370 lpdcb
->ByteSize
= 6;
1373 lpdcb
->ByteSize
= 7;
1376 lpdcb
->ByteSize
= 8;
1380 switch (port
.c_cflag
& ~(PARENB
| PARODD
)) {
1382 lpdcb
->fParity
= NOPARITY
;
1385 lpdcb
->fParity
= EVENPARITY
;
1387 case (PARENB
| PARODD
):
1388 lpdcb
->fParity
= ODDPARITY
;
1392 if (port
.c_cflag
& CSTOPB
)
1393 lpdcb
->StopBits
= TWOSTOPBITS
;
1395 lpdcb
->StopBits
= ONESTOPBIT
;
1402 if (port
.c_cflag
& CRTSCTS
) {
1403 lpdcb
->fDtrControl
= DTR_CONTROL_ENABLE
;
1404 lpdcb
->fRtsControl
= RTS_CONTROL_ENABLE
;
1405 lpdcb
->fOutxCtsFlow
= 1;
1406 lpdcb
->fOutxDsrFlow
= 1;
1410 lpdcb
->fDtrControl
= DTR_CONTROL_DISABLE
;
1411 lpdcb
->fRtsControl
= RTS_CONTROL_DISABLE
;
1413 if (port
.c_iflag
& IXON
)
1418 if (port
.c_iflag
& IXOFF
)
1427 lpdcb
->XoffLim
= 10;
1433 /*****************************************************************************
1434 * TransmitCommChar (USER.206)
1436 INT16
TransmitCommChar16(INT16 fd
,CHAR chTransmit
)
1438 struct DosDeviceStruct
*ptr
;
1440 dprintf_comm(stddeb
,
1441 "TransmitCommChar: fd %d, data %d \n", fd
, chTransmit
);
1442 if ((ptr
= GetDeviceStruct(fd
)) == NULL
) {
1443 commerror
= IE_BADID
;
1447 if (ptr
->suspended
) {
1448 commerror
= IE_HARDWARE
;
1452 if (write(fd
, (void *) &chTransmit
, 1) == -1) {
1453 commerror
= WinError();
1461 /*****************************************************************************
1462 * TransmitCommChar (KERNEL32.535)
1464 BOOL32
TransmitCommChar32(HANDLE32 hfile
,CHAR chTransmit
)
1466 FILE_OBJECT
*fob
= (FILE_OBJECT
*)hfile
;
1468 struct DosDeviceStruct
*ptr
;
1470 dprintf_comm(stddeb
,"TransmitCommChar32(%d,'%c')\n",fd
,chTransmit
);
1471 if ((ptr
= GetDeviceStruct(fd
)) == NULL
) {
1472 commerror
= IE_BADID
;
1476 if (ptr
->suspended
) {
1477 commerror
= IE_HARDWARE
;
1480 if (write(fd
, (void *) &chTransmit
, 1) == -1) {
1481 commerror
= WinError();
1489 /*****************************************************************************
1490 * UngetCommChar (USER.212)
1492 INT16
UngetCommChar(INT16 fd
,CHAR chUnget
)
1494 struct DosDeviceStruct
*ptr
;
1496 dprintf_comm(stddeb
,"UngetCommChar: fd %d (char %d)\n", fd
, chUnget
);
1497 if ((ptr
= GetDeviceStruct(fd
)) == NULL
) {
1498 commerror
= IE_BADID
;
1502 if (ptr
->suspended
) {
1503 commerror
= IE_HARDWARE
;
1508 ptr
->unget_byte
= chUnget
;
1513 /*****************************************************************************
1514 * ReadComm (USER.204)
1516 INT16
ReadComm(INT16 fd
,LPSTR lpvBuf
,INT16 cbRead
)
1519 struct DosDeviceStruct
*ptr
;
1521 dprintf_comm(stddeb
,
1522 "ReadComm: fd %d, ptr %p, length %d\n", fd
, lpvBuf
, cbRead
);
1523 if ((ptr
= GetDeviceStruct(fd
)) == NULL
) {
1524 commerror
= IE_BADID
;
1528 if (ptr
->suspended
) {
1529 commerror
= IE_HARDWARE
;
1534 *lpvBuf
= ptr
->unget_byte
;
1542 status
= read(fd
, (void *) lpvBuf
, cbRead
);
1545 if (errno
!= EAGAIN
) {
1546 commerror
= WinError();
1554 return length
+ status
;
1558 /*****************************************************************************
1559 * WriteComm (USER.205)
1561 INT16
WriteComm(INT16 fd
, LPSTR lpvBuf
, INT16 cbWrite
)
1564 struct DosDeviceStruct
*ptr
;
1566 dprintf_comm(stddeb
,"WriteComm: fd %d, ptr %p, length %d\n",
1567 fd
, lpvBuf
, cbWrite
);
1568 if ((ptr
= GetDeviceStruct(fd
)) == NULL
) {
1569 commerror
= IE_BADID
;
1573 if (ptr
->suspended
) {
1574 commerror
= IE_HARDWARE
;
1578 for (x
=0; x
!= cbWrite
; x
++)
1579 dprintf_comm(stddeb
,"%c", *(lpvBuf
+ x
) );
1581 length
= write(fd
, (void *) lpvBuf
, cbWrite
);
1584 commerror
= WinError();
1593 /*****************************************************************************
1594 * GetCommTimeouts (KERNEL32.160)
1596 BOOL32
GetCommTimeouts(HANDLE32 hfile
,LPCOMMTIMEOUTS lptimeouts
) {
1597 dprintf_comm(stddeb
,"GetCommTimeouts(%lx,%p), empty stub.\n",
1598 (DWORD
)hfile
,lptimeouts
1603 /*****************************************************************************
1604 * SetCommTimeouts (KERNEL32.453)
1606 BOOL32
SetCommTimeouts(HANDLE32 hfile
,LPCOMMTIMEOUTS lptimeouts
) {
1607 dprintf_comm(stddeb
,"SetCommTimeouts(%lx,%p), empty stub.\n",
1608 (DWORD
)hfile
,lptimeouts