2 * DEC 93 Erik Bos <erik@xs4all.nl>
4 * Copyright 1996 Marcus Meissner
6 * Mar 31, 1999. Ove Kåven <ovek@arcticnet.no>
7 * - Implemented buffers and EnableCommNotification.
9 * Apr 3, 1999. Lawson Whitney <lawson_whitney@juno.com>
10 * - Fixed the modem control part of EscapeCommFunction16.
12 * Mar 3, 1999. Ove Kåven <ovek@arcticnet.no>
13 * - Use port indices instead of unixfds for win16
14 * - Moved things around (separated win16 and win32 routines)
15 * - Added some hints on how to implement buffers and EnableCommNotification.
17 * May 26, 1997. Fixes and comments by Rick Richardson <rick@dgii.com> [RER]
18 * - ptr->fd wasn't getting cleared on close.
19 * - GetCommEventMask() and GetCommError() didn't do much of anything.
20 * IMHO, they are still wrong, but they at least implement the RXCHAR
21 * event and return I/O queue sizes, which makes the app I'm interested
22 * in (analog devices EZKIT DSP development system) work.
24 * August 12, 1997. Take a bash at SetCommEventMask - Lawson Whitney
25 * <lawson_whitney@juno.com>
26 * July 6, 1998. Fixes and comments by Valentijn Sessink
27 * <vsessink@ic.uva.nl> [V]
28 * Oktober 98, Rein Klazes [RHK]
29 * A program that wants to monitor the modem status line (RLSD/DCD) may
30 * poll the modem status register in the commMask structure. I update the bit
31 * in GetCommError, waiting for an implementation of communication events.
48 #ifdef HAVE_SYS_FILIO_H
49 # include <sys/filio.h>
51 #include <sys/ioctl.h>
54 #ifdef HAVE_SYS_MODEM_H
55 # include <sys/modem.h>
57 #ifdef HAVE_SYS_STRTIO_H
58 # include <sys/strtio.h>
67 #include "wine/port.h"
68 #include "wine/server.h"
74 #include "debugtools.h"
76 DEFAULT_DEBUG_CHANNEL(comm);
78 #if !defined(TIOCINQ) && defined(FIONREAD)
79 #define TIOCINQ FIONREAD
82 /* window's semi documented modem status register */
83 #define COMM_MSR_OFFSET 35
88 #define MSR_MASK (MSR_CTS|MSR_DSR|MSR_RI|MSR_RLSD)
93 #define CMSPAR 0x40000000 /* stick parity */
98 struct DosDeviceStruct {
99 char *devicename; /* /dev/ttyS0 */
106 int commerror, eventmask;
109 unsigned ibuf_size,ibuf_head,ibuf_tail;
110 unsigned obuf_size,obuf_head,obuf_tail;
112 int wnd, n_read, n_write;
113 HANDLE s_read, s_write;
114 /* save terminal states */
116 /* pointer to unknown(==undocumented) comm structure */
121 static struct DosDeviceStruct COM[MAX_PORTS];
122 static struct DosDeviceStruct LPT[MAX_PORTS];
124 /* update window's semi documented modem status register */
125 /* see knowledge base Q101417 */
126 static void COMM_MSRUpdate( HANDLE handle, UCHAR * pMsr )
131 if(!GetCommModemStatus(handle,&mstat))
134 if(mstat & MS_CTS_ON) tmpmsr |= MSR_CTS;
135 if(mstat & MS_DSR_ON) tmpmsr |= MSR_DSR;
136 if(mstat & MS_RING_ON) tmpmsr |= MSR_RI;
137 if(mstat & MS_RLSD_ON) tmpmsr |= MSR_RLSD;
138 *pMsr = (*pMsr & ~MSR_MASK) | tmpmsr;
144 char option[10], temp[256], *btemp;
147 for (x=0; x!=MAX_PORTS; x++) {
148 strcpy(option,"COMx");
152 PROFILE_GetWineIniString( "serialports", option, "*",
153 temp, sizeof(temp) );
154 if (!strcmp(temp, "*") || *temp == '\0')
155 COM[x].devicename = NULL;
157 btemp = strchr(temp,',');
160 COM[x].baudrate = atoi(btemp);
162 COM[x].baudrate = -1;
165 if (!S_ISCHR(st.st_mode))
166 WARN("Can't use `%s' as %s !\n", temp, option);
168 if ((COM[x].devicename = malloc(strlen(temp)+1)) == NULL)
169 WARN("Can't malloc for device info!\n");
172 strcpy(COM[x].devicename, temp);
174 TRACE("%s = %s\n", option, COM[x].devicename);
177 strcpy(option, "LPTx");
181 PROFILE_GetWineIniString( "parallelports", option, "*",
182 temp, sizeof(temp) );
183 if (!strcmp(temp, "*") || *temp == '\0')
184 LPT[x].devicename = NULL;
187 if (!S_ISCHR(st.st_mode))
188 WARN("Can't use `%s' as %s !\n", temp, option);
190 if ((LPT[x].devicename = malloc(strlen(temp)+1)) == NULL)
191 WARN("Can't malloc for device info!\n");
194 strcpy(LPT[x].devicename, temp);
196 TRACE("%s = %s\n", option, LPT[x].devicename);
203 static struct DosDeviceStruct *GetDeviceStruct(int index)
205 if ((index&0x7F)<=MAX_PORTS) {
206 if (!(index&FLAG_LPT)) {
207 if (COM[index].handle)
211 if (LPT[index].handle)
219 static int GetCommPort_fd(HANDLE handle)
223 for (x=0; x<MAX_PORTS; x++) {
224 if (COM[x].handle == handle)
231 static int ValidCOMPort(int x)
233 return(x < MAX_PORTS ? (int) COM[x].devicename : 0);
236 static int ValidLPTPort(int x)
238 return(x < MAX_PORTS ? (int) LPT[x].devicename : 0);
241 static int WinError(void)
243 TRACE("errno = %d\n", errno);
250 static unsigned comm_inbuf(struct DosDeviceStruct *ptr)
252 return ((ptr->ibuf_tail > ptr->ibuf_head) ? ptr->ibuf_size : 0)
253 + ptr->ibuf_head - ptr->ibuf_tail;
256 static unsigned comm_outbuf(struct DosDeviceStruct *ptr)
258 return ((ptr->obuf_tail > ptr->obuf_head) ? ptr->obuf_size : 0)
259 + ptr->obuf_head - ptr->obuf_tail;
262 static int COMM_WhackModem(int fd, unsigned int andy, unsigned int orrie)
264 unsigned int mstat, okay;
265 okay = ioctl(fd, TIOCMGET, &mstat);
266 if (okay) return okay;
267 if (andy) mstat &= andy;
269 return ioctl(fd, TIOCMSET, &mstat);
272 static void CALLBACK comm_notification( ULONG_PTR private )
274 struct DosDeviceStruct *ptr = (struct DosDeviceStruct *)private;
278 int cid = GetCommPort_fd(ptr->handle);
280 TRACE("async notification\n");
281 /* read data from comm port */
282 prev = comm_inbuf(ptr);
284 bleft = ((ptr->ibuf_tail > ptr->ibuf_head) ? (ptr->ibuf_tail-1) : ptr->ibuf_size)
286 if(!ReadFile(ptr->handle, ptr->inbuf + ptr->ibuf_head, bleft?bleft:1, &len, NULL))
290 ptr->commerror = CE_RXOVER;
292 /* check for events */
293 if ((ptr->eventmask & EV_RXFLAG) &&
294 memchr(ptr->inbuf + ptr->ibuf_head, ptr->evtchar, len)) {
295 *(WORD*)(COM[cid].unknown) |= EV_RXFLAG;
298 if (ptr->eventmask & EV_RXCHAR) {
299 *(WORD*)(COM[cid].unknown) |= EV_RXCHAR;
302 /* advance buffer position */
303 ptr->ibuf_head += len;
304 if (ptr->ibuf_head >= ptr->ibuf_size)
309 /* check for notification */
310 if (ptr->wnd && (ptr->n_read>0) && (prev<ptr->n_read) &&
311 (comm_inbuf(ptr)>=ptr->n_read)) {
312 /* passed the receive notification threshold */
316 /* write any TransmitCommChar character */
318 if(!WriteFile(ptr->handle, &(ptr->xmit), 1, &len, NULL))
320 if (len > 0) ptr->xmit = -1;
322 /* write from output queue */
323 prev = comm_outbuf(ptr);
325 bleft = ((ptr->obuf_tail <= ptr->obuf_head) ? ptr->obuf_head : ptr->obuf_size)
328 if(!WriteFile(ptr->handle, ptr->outbuf + ptr->obuf_tail, bleft, &len, NULL))
333 ptr->obuf_tail += len;
334 if (ptr->obuf_tail >= ptr->obuf_size)
337 if (ptr->obuf_tail == ptr->obuf_head) {
339 SERVICE_Delete( ptr->s_write );
340 ptr->s_write = INVALID_HANDLE_VALUE;
342 if (ptr->eventmask & EV_TXEMPTY) {
343 *(WORD*)(COM[cid].unknown) |= EV_TXEMPTY;
349 /* check for notification */
350 if (ptr->wnd && (ptr->n_write>0) && (prev>=ptr->n_write) &&
351 (comm_outbuf(ptr)<ptr->n_write)) {
352 /* passed the transmit notification threshold */
356 /* send notifications, if any */
357 if (ptr->wnd && mask) {
358 TRACE("notifying %04x: cid=%d, mask=%02x\n", ptr->wnd, cid, mask);
359 if (Callout.PostMessageA) Callout.PostMessageA(ptr->wnd, WM_COMMNOTIFY, cid, mask);
363 static void comm_waitread(struct DosDeviceStruct *ptr)
365 HANDLE dup=INVALID_HANDLE_VALUE;
367 if (ptr->s_read != INVALID_HANDLE_VALUE)
369 if(!DuplicateHandle(GetCurrentProcess(), ptr->handle,
370 GetCurrentProcess(), &dup, GENERIC_READ|SYNCHRONIZE, FALSE, 0 ))
372 ptr->s_read = SERVICE_AddObject( dup, comm_notification, (ULONG_PTR)ptr );
375 static void comm_waitwrite(struct DosDeviceStruct *ptr)
377 HANDLE dup=INVALID_HANDLE_VALUE;
379 if (ptr->s_write != INVALID_HANDLE_VALUE)
381 if(!DuplicateHandle(GetCurrentProcess(), ptr->handle,
382 GetCurrentProcess(), &dup, GENERIC_WRITE|SYNCHRONIZE, FALSE, 0 ))
384 ptr->s_write = SERVICE_AddObject( dup, comm_notification, (ULONG_PTR)ptr );
387 /**************************************************************************
388 * BuildCommDCB (USER.213)
390 * According to the ECMA-234 (368.3) the function will return FALSE on
391 * success, otherwise it will return -1.
392 * IF THIS IS NOT CORRECT THE RETURNVALUE CHECK IN BuildCommDCBAndTimeoutsA
395 INT16 WINAPI BuildCommDCB16(LPCSTR device, LPDCB16 lpdcb)
397 /* "COM1:96,n,8,1" */
400 char *ptr, temp[256];
402 TRACE("(%s), ptr %p\n", device, lpdcb);
404 if (!strncasecmp(device,"COM",3)) {
405 port = device[3] - '0';
409 ERR("BUG ! COM0 can't exist!\n");
413 if (!ValidCOMPort(port)) {
414 FIXME("invalid COM port %d?\n",port);
418 memset(lpdcb, 0, sizeof(DCB16)); /* initialize */
425 if (*(device+4) != ':')
428 strcpy(temp,device+5);
429 ptr = strtok(temp, ", ");
431 if (COM[port].baudrate > 0)
432 lpdcb->BaudRate = COM[port].baudrate;
436 /* DOS/Windows only compares the first two numbers
437 * and assigns an appropriate baud rate.
438 * You can supply 961324245, it still returns 9600 ! */
441 WARN("Unknown baudrate string '%s' !\n", ptr);
442 return -1; /* error: less than 2 chars */
463 WARN("Unknown baudrate indicator %d !\n", rate);
467 lpdcb->BaudRate = rate;
469 TRACE("baudrate (%d)\n", lpdcb->BaudRate);
471 ptr = strtok(NULL, ", ");
473 *ptr = toupper(*ptr);
475 TRACE("parity (%c)\n", *ptr);
476 lpdcb->fParity = TRUE;
479 lpdcb->Parity = NOPARITY;
480 lpdcb->fParity = FALSE;
483 lpdcb->Parity = EVENPARITY;
486 lpdcb->Parity = MARKPARITY;
489 lpdcb->Parity = ODDPARITY;
492 WARN("Unknown parity `%c'!\n", *ptr);
496 ptr = strtok(NULL, ", ");
497 TRACE("charsize (%c)\n", *ptr);
498 lpdcb->ByteSize = *ptr - '0';
500 ptr = strtok(NULL, ", ");
501 TRACE("stopbits (%c)\n", *ptr);
504 lpdcb->StopBits = ONESTOPBIT;
507 lpdcb->StopBits = TWOSTOPBITS;
510 WARN("Unknown # of stopbits `%c'!\n", *ptr);
518 /*****************************************************************************
519 * OpenComm (USER.200)
521 INT16 WINAPI OpenComm16(LPCSTR device,UINT16 cbInQueue,UINT16 cbOutQueue)
526 TRACE("%s, %d, %d\n", device, cbInQueue, cbOutQueue);
528 if (strlen(device) < 4)
531 port = device[3] - '0';
534 ERR("BUG ! COM0 or LPT0 don't exist !\n");
536 if (!strncasecmp(device,"COM",3)) {
538 TRACE("%s = %s\n", device, COM[port].devicename);
540 if (!ValidCOMPort(port))
543 if (COM[port].handle)
546 handle = CreateFileA(device, GENERIC_READ|GENERIC_WRITE,
547 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, 0, 0 );
548 if (handle == INVALID_HANDLE_VALUE) {
549 ERR("Couldn't open %s ! (%s)\n", COM[port].devicename, strerror(errno));
552 COM[port].unknown = SEGPTR_ALLOC(40);
553 memset(COM[port].unknown, 0, 40);
554 COM[port].handle = handle;
555 COM[port].commerror = 0;
556 COM[port].eventmask = 0;
557 COM[port].evtchar = 0; /* FIXME: default? */
558 /* save terminal state */
559 GetCommState16(port,&COM[port].dcb);
560 /* set default parameters */
561 if(COM[port].baudrate>-1){
563 memcpy(&dcb,&COM[port].dcb,sizeof dcb);
564 dcb.BaudRate=COM[port].baudrate;
566 * databits, parity, stopbits
568 SetCommState16( &dcb);
570 /* init priority characters */
571 COM[port].unget = -1;
573 /* allocate buffers */
574 COM[port].ibuf_size = cbInQueue;
575 COM[port].ibuf_head = COM[port].ibuf_tail = 0;
576 COM[port].obuf_size = cbOutQueue;
577 COM[port].obuf_head = COM[port].obuf_tail = 0;
579 COM[port].inbuf = malloc(cbInQueue);
580 if (COM[port].inbuf) {
581 COM[port].outbuf = malloc(cbOutQueue);
582 if (!COM[port].outbuf)
583 free(COM[port].inbuf);
584 } else COM[port].outbuf = NULL;
585 if (!COM[port].outbuf) {
586 /* not enough memory */
587 SetCommState16(&COM[port].dcb);
588 CloseHandle(COM[port].handle);
589 ERR("out of memory\n");
593 COM[port].s_read = INVALID_HANDLE_VALUE;
594 COM[port].s_write = INVALID_HANDLE_VALUE;
595 comm_waitread( &COM[port] );
600 if (!strncasecmp(device,"LPT",3)) {
602 if (!ValidLPTPort(port))
605 if (LPT[port].handle)
608 handle = CreateFileA(device, GENERIC_READ|GENERIC_WRITE,
609 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, 0, 0 );
610 if (handle == INVALID_HANDLE_VALUE) {
613 LPT[port].handle = handle;
614 LPT[port].commerror = 0;
615 LPT[port].eventmask = 0;
616 return port|FLAG_LPT;
622 /*****************************************************************************
623 * CloseComm (USER.207)
625 INT16 WINAPI CloseComm16(INT16 cid)
627 struct DosDeviceStruct *ptr;
629 TRACE("cid=%d\n", cid);
630 if ((ptr = GetDeviceStruct(cid)) == NULL) {
631 FIXME("no cid=%d found!\n", cid);
634 if (!(cid&FLAG_LPT)) {
636 SEGPTR_FREE(COM[cid].unknown); /* [LW] */
638 SERVICE_Delete( COM[cid].s_write );
639 SERVICE_Delete( COM[cid].s_read );
644 /* reset modem lines */
645 SetCommState16(&COM[cid].dcb);
648 if (!CloseHandle(ptr->handle)) {
649 ptr->commerror = WinError();
650 /* FIXME: should we clear ptr->handle here? */
659 /*****************************************************************************
660 * SetCommBreak (USER.210)
662 INT16 WINAPI SetCommBreak16(INT16 cid)
664 struct DosDeviceStruct *ptr;
666 TRACE("cid=%d\n", cid);
667 if ((ptr = GetDeviceStruct(cid)) == NULL) {
668 FIXME("no cid=%d found!\n", cid);
677 /*****************************************************************************
678 * ClearCommBreak (USER.211)
680 INT16 WINAPI ClearCommBreak16(INT16 cid)
682 struct DosDeviceStruct *ptr;
684 TRACE("cid=%d\n", cid);
685 if (!(ptr = GetDeviceStruct(cid))) {
686 FIXME("no cid=%d found!\n", cid);
694 /*****************************************************************************
695 * EscapeCommFunction (USER.214)
697 LONG WINAPI EscapeCommFunction16(UINT16 cid,UINT16 nFunction)
699 struct DosDeviceStruct *ptr;
702 TRACE("cid=%d, function=%d\n", cid, nFunction);
706 TRACE("GETMAXCOM\n");
707 for (max = MAX_PORTS;!COM[max].devicename;max--)
712 TRACE("GETMAXLPT\n");
713 for (max = MAX_PORTS;!LPT[max].devicename;max--)
715 return FLAG_LPT + max;
718 TRACE("GETBASEIRQ\n");
719 /* FIXME: use tables */
720 /* just fake something for now */
721 if (cid & FLAG_LPT) {
722 /* LPT1: irq 7, LPT2: irq 5 */
723 return (cid & 0x7f) ? 5 : 7;
725 /* COM1: irq 4, COM2: irq 3,
726 COM3: irq 4, COM4: irq 3 */
727 return 4 - (cid & 1);
731 if ((ptr = GetDeviceStruct(cid)) == NULL) {
732 FIXME("no cid=%d found!\n", cid);
744 if(EscapeCommFunction(ptr->handle,nFunction))
747 ptr->commerror = WinError();
754 WARN("(cid=%d,nFunction=%d): Unknown function\n",
760 /*****************************************************************************
761 * FlushComm (USER.215)
763 INT16 WINAPI FlushComm16(INT16 cid,INT16 fnQueue)
766 struct DosDeviceStruct *ptr;
768 TRACE("cid=%d, queue=%d\n", cid, fnQueue);
769 if ((ptr = GetDeviceStruct(cid)) == NULL) {
770 FIXME("no cid=%d found!\n", cid);
775 queue = PURGE_TXABORT;
776 ptr->obuf_tail = ptr->obuf_head;
779 queue = PURGE_RXABORT;
780 ptr->ibuf_head = ptr->ibuf_tail;
783 WARN("(cid=%d,fnQueue=%d):Unknown queue\n",
788 if (!PurgeComm(ptr->handle,queue)) {
789 ptr->commerror = WinError();
797 /********************************************************************
798 * GetCommError (USER.203)
800 INT16 WINAPI GetCommError16(INT16 cid,LPCOMSTAT16 lpStat)
803 struct DosDeviceStruct *ptr;
806 if ((ptr = GetDeviceStruct(cid)) == NULL) {
807 FIXME("no handle for cid = %0x!\n",cid);
811 WARN(" cid %d not comm port\n",cid);
814 stol = (unsigned char *)COM[cid].unknown + COMM_MSR_OFFSET;
815 COMM_MSRUpdate( ptr->handle, stol );
820 lpStat->cbOutQue = comm_outbuf(ptr);
821 lpStat->cbInQue = comm_inbuf(ptr);
823 TRACE("cid %d, error %d, stat %d in %d out %d, stol %x\n",
824 cid, ptr->commerror, lpStat->status, lpStat->cbInQue,
825 lpStat->cbOutQue, *stol);
828 TRACE("cid %d, error %d, lpStat NULL stol %x\n",
829 cid, ptr->commerror, *stol);
831 /* Return any errors and clear it */
832 temperror = ptr->commerror;
837 /*****************************************************************************
838 * SetCommEventMask (USER.208)
840 SEGPTR WINAPI SetCommEventMask16(INT16 cid,UINT16 fuEvtMask)
842 struct DosDeviceStruct *ptr;
845 TRACE("cid %d,mask %d\n",cid,fuEvtMask);
846 if ((ptr = GetDeviceStruct(cid)) == NULL) {
847 FIXME("no handle for cid = %0x!\n",cid);
851 ptr->eventmask = fuEvtMask;
853 if ((cid&FLAG_LPT) || !ValidCOMPort(cid)) {
854 WARN(" cid %d not comm port\n",cid);
857 /* it's a COM port ? -> modify flags */
858 stol = (unsigned char *)COM[cid].unknown + COMM_MSR_OFFSET;
859 COMM_MSRUpdate( ptr->handle, stol );
861 TRACE(" modem dcd construct %x\n",*stol);
862 return SEGPTR_GET(COM[cid].unknown);
865 /*****************************************************************************
866 * GetCommEventMask (USER.209)
868 UINT16 WINAPI GetCommEventMask16(INT16 cid,UINT16 fnEvtClear)
870 struct DosDeviceStruct *ptr;
873 TRACE("cid %d, mask %d\n", cid, fnEvtClear);
874 if ((ptr = GetDeviceStruct(cid)) == NULL) {
875 FIXME("no handle for cid = %0x!\n",cid);
879 if ((cid&FLAG_LPT) || !ValidCOMPort(cid)) {
880 WARN(" cid %d not comm port\n",cid);
884 events = *(WORD*)(COM[cid].unknown) & fnEvtClear;
885 *(WORD*)(COM[cid].unknown) &= ~fnEvtClear;
889 /*****************************************************************************
890 * SetCommState (USER.201)
892 INT16 WINAPI SetCommState16(LPDCB16 lpdcb)
894 struct DosDeviceStruct *ptr;
897 TRACE("cid %d, ptr %p\n", lpdcb->Id, lpdcb);
898 if ((ptr = GetDeviceStruct(lpdcb->Id)) == NULL) {
899 FIXME("no handle for cid = %0x!\n",lpdcb->Id);
903 memset(&dcb,0,sizeof dcb);
904 dcb.DCBlength = sizeof dcb;
905 if(lpdcb->BaudRate==57601)
906 dcb.BaudRate = 115200;
908 dcb.BaudRate = lpdcb->BaudRate;
910 dcb.ByteSize=lpdcb->ByteSize;
911 dcb.StopBits=lpdcb->StopBits;
913 dcb.fParity=lpdcb->fParity;
914 dcb.Parity=lpdcb->Parity;
916 dcb.fOutxCtsFlow = lpdcb->fOutxCtsFlow;
918 if (lpdcb->fDtrflow || lpdcb->fRtsflow)
919 dcb.fRtsControl = TRUE;
921 if (lpdcb->fDtrDisable)
922 dcb.fDtrControl = TRUE;
924 ptr->evtchar = lpdcb->EvtChar;
926 dcb.fInX = lpdcb->fInX;
927 dcb.fOutX = lpdcb->fOutX;
929 if (!SetCommState(ptr->handle,&dcb)) {
930 ptr->commerror = WinError();
938 /*****************************************************************************
939 * GetCommState (USER.202)
941 INT16 WINAPI GetCommState16(INT16 cid, LPDCB16 lpdcb)
943 struct DosDeviceStruct *ptr;
946 TRACE("cid %d, ptr %p\n", cid, lpdcb);
947 if ((ptr = GetDeviceStruct(cid)) == NULL) {
948 FIXME("no handle for cid = %0x!\n",cid);
951 if (!GetCommState(ptr->handle,&dcb)) {
952 ptr->commerror = WinError();
957 if(dcb.BaudRate<0x10000)
958 lpdcb->BaudRate = dcb.BaudRate;
959 else if(dcb.BaudRate==115200)
960 lpdcb->BaudRate = 57601;
962 WARN("Baud rate can't be converted\n");
963 lpdcb->BaudRate = 57601;
965 lpdcb->ByteSize = dcb.ByteSize;
966 lpdcb->fParity = dcb.fParity;
967 lpdcb->Parity = dcb.Parity;
968 lpdcb->StopBits = dcb.StopBits;
970 lpdcb->RlsTimeout = 50;
971 lpdcb->CtsTimeout = 50;
972 lpdcb->DsrTimeout = 50;
976 lpdcb->fDtrDisable = 0;
978 lpdcb->fDtrflow = (dcb.fDtrControl==DTR_CONTROL_ENABLE);
979 lpdcb->fRtsflow = (dcb.fRtsControl==RTS_CONTROL_ENABLE);
980 lpdcb->fOutxCtsFlow = dcb.fOutxCtsFlow;
981 lpdcb->fOutxDsrFlow = dcb.fOutxDsrFlow;
982 lpdcb->fDtrDisable = (dcb.fDtrControl==DTR_CONTROL_DISABLE);
984 lpdcb->fInX = dcb.fInX;
986 lpdcb->fOutX = dcb.fOutX;
994 lpdcb->EvtChar = ptr->evtchar;
1000 /*****************************************************************************
1001 * TransmitCommChar (USER.206)
1003 INT16 WINAPI TransmitCommChar16(INT16 cid,CHAR chTransmit)
1005 struct DosDeviceStruct *ptr;
1007 TRACE("cid %d, data %d \n", cid, chTransmit);
1008 if ((ptr = GetDeviceStruct(cid)) == NULL) {
1009 FIXME("no handle for cid = %0x!\n",cid);
1013 if (ptr->suspended) {
1014 ptr->commerror = IE_HARDWARE;
1018 if (ptr->xmit >= 0) {
1019 /* character already queued */
1020 /* FIXME: which error would Windows return? */
1021 ptr->commerror = CE_TXFULL;
1025 if (ptr->obuf_head == ptr->obuf_tail) {
1026 /* transmit queue empty, try to transmit directly */
1028 if(!WriteFile(ptr->handle, &chTransmit, 1, &len, NULL)) {
1029 /* didn't work, queue it */
1030 ptr->xmit = chTransmit;
1031 comm_waitwrite(ptr);
1034 /* data in queue, let this char be transmitted next */
1035 ptr->xmit = chTransmit;
1036 comm_waitwrite(ptr);
1043 /*****************************************************************************
1044 * UngetCommChar (USER.212)
1046 INT16 WINAPI UngetCommChar16(INT16 cid,CHAR chUnget)
1048 struct DosDeviceStruct *ptr;
1050 TRACE("cid %d (char %d)\n", cid, chUnget);
1051 if ((ptr = GetDeviceStruct(cid)) == NULL) {
1052 FIXME("no handle for cid = %0x!\n",cid);
1056 if (ptr->suspended) {
1057 ptr->commerror = IE_HARDWARE;
1061 if (ptr->unget>=0) {
1062 /* character already queued */
1063 /* FIXME: which error would Windows return? */
1064 ptr->commerror = CE_RXOVER;
1068 ptr->unget = chUnget;
1074 /*****************************************************************************
1075 * ReadComm (USER.204)
1077 INT16 WINAPI ReadComm16(INT16 cid,LPSTR lpvBuf,INT16 cbRead)
1080 struct DosDeviceStruct *ptr;
1081 LPSTR orgBuf = lpvBuf;
1083 TRACE("cid %d, ptr %p, length %d\n", cid, lpvBuf, cbRead);
1084 if ((ptr = GetDeviceStruct(cid)) == NULL) {
1085 FIXME("no handle for cid = %0x!\n",cid);
1089 if (ptr->suspended) {
1090 ptr->commerror = IE_HARDWARE;
1094 /* read unget character */
1095 if (ptr->unget>=0) {
1096 *lpvBuf++ = ptr->unget;
1103 /* read from receive buffer */
1104 while (length < cbRead) {
1105 status = ((ptr->ibuf_head < ptr->ibuf_tail) ?
1106 ptr->ibuf_size : ptr->ibuf_head) - ptr->ibuf_tail;
1108 if ((cbRead - length) < status)
1109 status = cbRead - length;
1111 memcpy(lpvBuf, ptr->inbuf + ptr->ibuf_tail, status);
1112 ptr->ibuf_tail += status;
1113 if (ptr->ibuf_tail >= ptr->ibuf_size)
1119 TRACE("%.*s\n", length, orgBuf);
1124 /*****************************************************************************
1125 * WriteComm (USER.205)
1127 INT16 WINAPI WriteComm16(INT16 cid, LPSTR lpvBuf, INT16 cbWrite)
1130 struct DosDeviceStruct *ptr;
1132 TRACE("cid %d, ptr %p, length %d\n",
1133 cid, lpvBuf, cbWrite);
1134 if ((ptr = GetDeviceStruct(cid)) == NULL) {
1135 FIXME("no handle for cid = %0x!\n",cid);
1139 if (ptr->suspended) {
1140 ptr->commerror = IE_HARDWARE;
1144 TRACE("%.*s\n", cbWrite, lpvBuf );
1147 while (length < cbWrite) {
1148 if ((ptr->obuf_head == ptr->obuf_tail) && (ptr->xmit < 0)) {
1149 /* no data queued, try to write directly */
1150 if(!WriteFile(ptr->handle, lpvBuf, cbWrite - length, (LPDWORD)&status, NULL))
1158 /* can't write directly, put into transmit buffer */
1159 status = ((ptr->obuf_tail > ptr->obuf_head) ?
1160 (ptr->obuf_tail-1) : ptr->obuf_size) - ptr->obuf_head;
1162 if ((cbWrite - length) < status)
1163 status = cbWrite - length;
1164 memcpy(lpvBuf, ptr->outbuf + ptr->obuf_head, status);
1165 ptr->obuf_head += status;
1166 if (ptr->obuf_head >= ptr->obuf_size)
1170 comm_waitwrite(ptr);
1177 /***********************************************************************
1178 * EnableCommNotification (USER.245)
1180 BOOL16 WINAPI EnableCommNotification16( INT16 cid, HWND16 hwnd,
1181 INT16 cbWriteNotify, INT16 cbOutQueue )
1183 struct DosDeviceStruct *ptr;
1185 TRACE("(%d, %x, %d, %d)\n", cid, hwnd, cbWriteNotify, cbOutQueue);
1186 if ((ptr = GetDeviceStruct(cid)) == NULL) {
1187 FIXME("no handle for cid = %0x!\n",cid);
1191 ptr->n_read = cbWriteNotify;
1192 ptr->n_write = cbOutQueue;
1197 /**************************************************************************
1198 * BuildCommDCBA (KERNEL32.@)
1200 * Updates a device control block data structure with values from an
1201 * ascii device control string. The device control string has two forms
1202 * normal and extended, it must be exclusively in one or the other form.
1206 * True on success, false on an malformed control string.
1208 BOOL WINAPI BuildCommDCBA(
1209 LPCSTR device, /* [in] The ascii device control string used to update the DCB. */
1210 LPDCB lpdcb) /* [out] The device control block to be updated. */
1212 return BuildCommDCBAndTimeoutsA(device,lpdcb,NULL);
1215 /**************************************************************************
1216 * BuildCommDCBAndTimeoutsA (KERNEL32.@)
1218 * Updates a device control block data structure with values from an
1219 * ascii device control string. Taking time out values from a time outs
1220 * struct if desired by the control string.
1224 * True on success, false bad handles etc
1226 BOOL WINAPI BuildCommDCBAndTimeoutsA(
1227 LPCSTR device, /* [in] The ascii device control string. */
1228 LPDCB lpdcb, /* [out] The device control block to be updated. */
1229 LPCOMMTIMEOUTS lptimeouts) /* [in] The time outs to use if asked to set them by the control string. */
1234 TRACE("(%s,%p,%p)\n",device,lpdcb,lptimeouts);
1236 if (!strncasecmp(device,"COM",3)) {
1239 ERR("BUG! COM0 can't exist!\n");
1242 if (!ValidCOMPort(port))
1244 if (*(device+4)!=':')
1246 temp=(LPSTR)(device+5);
1250 lpdcb->DCBlength = sizeof(DCB);
1251 if (strchr(temp,',')) { /* old style */
1254 char last=temp[strlen(temp)-1];
1256 ret=BuildCommDCB16(device,&dcb16);
1259 lpdcb->BaudRate = dcb16.BaudRate;
1260 lpdcb->ByteSize = dcb16.ByteSize;
1261 lpdcb->fBinary = dcb16.fBinary;
1262 lpdcb->Parity = dcb16.Parity;
1263 lpdcb->fParity = dcb16.fParity;
1264 lpdcb->fNull = dcb16.fNull;
1265 lpdcb->StopBits = dcb16.StopBits;
1268 lpdcb->fOutX = TRUE;
1269 lpdcb->fOutxCtsFlow = FALSE;
1270 lpdcb->fOutxDsrFlow = FALSE;
1271 lpdcb->fDtrControl = DTR_CONTROL_ENABLE;
1272 lpdcb->fRtsControl = RTS_CONTROL_ENABLE;
1273 } else if (last=='p') {
1274 lpdcb->fInX = FALSE;
1275 lpdcb->fOutX = FALSE;
1276 lpdcb->fOutxCtsFlow = TRUE;
1277 lpdcb->fOutxDsrFlow = TRUE;
1278 lpdcb->fDtrControl = DTR_CONTROL_HANDSHAKE;
1279 lpdcb->fRtsControl = RTS_CONTROL_HANDSHAKE;
1281 lpdcb->fInX = FALSE;
1282 lpdcb->fOutX = FALSE;
1283 lpdcb->fOutxCtsFlow = FALSE;
1284 lpdcb->fOutxDsrFlow = FALSE;
1285 lpdcb->fDtrControl = DTR_CONTROL_ENABLE;
1286 lpdcb->fRtsControl = RTS_CONTROL_ENABLE;
1288 lpdcb->XonChar = dcb16.XonChar;
1289 lpdcb->XoffChar = dcb16.XoffChar;
1290 lpdcb->ErrorChar= dcb16.PeChar;
1291 lpdcb->fErrorChar= dcb16.fPeChar;
1292 lpdcb->EofChar = dcb16.EofChar;
1293 lpdcb->EvtChar = dcb16.EvtChar;
1294 lpdcb->XonLim = dcb16.XonLim;
1295 lpdcb->XoffLim = dcb16.XoffLim;
1298 ptr=strtok(temp," ");
1303 if (!strncmp("baud=",ptr,5)) {
1304 if (!sscanf(ptr+5,"%ld",&x))
1305 WARN("Couldn't parse %s\n",ptr);
1306 lpdcb->BaudRate = x;
1309 if (!strncmp("stop=",ptr,5)) {
1310 if (!sscanf(ptr+5,"%ld",&x))
1311 WARN("Couldn't parse %s\n",ptr);
1312 lpdcb->StopBits = x;
1315 if (!strncmp("data=",ptr,5)) {
1316 if (!sscanf(ptr+5,"%ld",&x))
1317 WARN("Couldn't parse %s\n",ptr);
1318 lpdcb->ByteSize = x;
1321 if (!strncmp("parity=",ptr,7)) {
1322 lpdcb->fParity = TRUE;
1325 lpdcb->fParity = FALSE;
1326 lpdcb->Parity = NOPARITY;
1329 lpdcb->Parity = EVENPARITY;
1332 lpdcb->Parity = ODDPARITY;
1335 lpdcb->Parity = MARKPARITY;
1341 ERR("Unhandled specifier '%s', please report.\n",ptr);
1342 ptr=strtok(NULL," ");
1344 if (lpdcb->BaudRate==110)
1345 lpdcb->StopBits = 2;
1349 /**************************************************************************
1350 * BuildCommDCBAndTimeoutsW (KERNEL32.@)
1352 * Updates a device control block data structure with values from an
1353 * unicode device control string. Taking time out values from a time outs
1354 * struct if desired by the control string.
1358 * True on success, false bad handles etc.
1360 BOOL WINAPI BuildCommDCBAndTimeoutsW(
1361 LPCWSTR devid, /* [in] The unicode device control string. */
1362 LPDCB lpdcb, /* [out] The device control block to be updated. */
1363 LPCOMMTIMEOUTS lptimeouts) /* [in] The time outs to use if asked to set them by the control string. */
1368 TRACE("(%p,%p,%p)\n",devid,lpdcb,lptimeouts);
1369 devidA = HEAP_strdupWtoA( GetProcessHeap(), 0, devid );
1372 ret=BuildCommDCBAndTimeoutsA(devidA,lpdcb,lptimeouts);
1373 HeapFree( GetProcessHeap(), 0, devidA );
1378 /**************************************************************************
1379 * BuildCommDCBW (KERNEL32.@)
1381 * Updates a device control block structure with values from an
1382 * unicode device control string. The device control string has two forms
1383 * normal and extended, it must be exclusively in one or the other form.
1387 * True on success, false on an malformed control string.
1389 BOOL WINAPI BuildCommDCBW(
1390 LPCWSTR devid, /* [in] The unicode device control string. */
1391 LPDCB lpdcb) /* [out] The device control block to be updated. */
1393 return BuildCommDCBAndTimeoutsW(devid,lpdcb,NULL);
1396 /* FIXME: having these global for win32 for now */
1399 /*****************************************************************************
1400 * SetCommBreak (KERNEL32.@)
1402 * Halts the transmission of characters to a communications device.
1406 * True on success, and false if the communications device could not be found,
1407 * the control is not supported.
1411 * Only TIOCSBRK and TIOCCBRK are supported.
1413 BOOL WINAPI SetCommBreak(
1414 HANDLE handle) /* [in] The communictions device to suspend. */
1416 #if defined(TIOCSBRK) && defined(TIOCCBRK) /* check if available for compilation */
1419 fd = FILE_GetUnixHandle( handle, GENERIC_READ );
1421 TRACE("FILE_GetUnixHandle failed\n");
1424 result = ioctl(fd,TIOCSBRK,0);
1428 TRACE("ioctl failed\n");
1429 SetLastError(ERROR_NOT_SUPPORTED);
1434 FIXME("ioctl not available\n");
1435 SetLastError(ERROR_NOT_SUPPORTED);
1440 /*****************************************************************************
1441 * ClearCommBreak (KERNEL32.@)
1443 * Resumes character transmission from a communication device.
1447 * True on success and false if the communications device could not be found.
1451 * Only TIOCSBRK and TIOCCBRK are supported.
1453 BOOL WINAPI ClearCommBreak(
1454 HANDLE handle) /* [in] The halted communication device whose character transmission is to be resumed. */
1456 #if defined(TIOCSBRK) && defined(TIOCCBRK) /* check if available for compilation */
1459 fd = FILE_GetUnixHandle( handle, GENERIC_READ );
1461 TRACE("FILE_GetUnixHandle failed\n");
1464 result = ioctl(fd,TIOCCBRK,0);
1468 TRACE("ioctl failed\n");
1469 SetLastError(ERROR_NOT_SUPPORTED);
1474 FIXME("ioctl not available\n");
1475 SetLastError(ERROR_NOT_SUPPORTED);
1480 /*****************************************************************************
1481 * EscapeCommFunction (KERNEL32.@)
1483 * Directs a communication device to perform an extended function.
1487 * True or requested data on successful completion of the command,
1488 * false if the device is not present cannot execute the command
1489 * or the command failed.
1491 BOOL WINAPI EscapeCommFunction(
1492 HANDLE handle, /* [in] The communication device to perform the extended function. */
1493 UINT nFunction) /* [in] The extended function to be performed. */
1495 int fd,direct=FALSE,result=FALSE;
1496 struct termios port;
1498 TRACE("handle %d, function=%d\n", handle, nFunction);
1499 fd = FILE_GetUnixHandle( handle, GENERIC_READ );
1501 FIXME("handle %d not found.\n",handle);
1505 if (tcgetattr(fd,&port) == -1) {
1506 commerror=WinError();
1511 switch (nFunction) {
1520 result= COMM_WhackModem(fd, ~TIOCM_DTR, 0);
1528 result= COMM_WhackModem(fd, ~TIOCM_RTS, 0);
1536 result= COMM_WhackModem(fd, 0, TIOCM_DTR);
1544 result= COMM_WhackModem(fd, 0, TIOCM_RTS);
1550 port.c_iflag |= IXOFF;
1555 port.c_iflag |= IXON;
1558 TRACE("setbreak\n");
1561 result = ioctl(fd,TIOCSBRK,0);
1565 TRACE("clrbreak\n");
1568 result = ioctl(fd,TIOCCBRK,0);
1572 WARN("(handle=%d,nFunction=%d): Unknown function\n",
1578 if (tcsetattr(fd, TCSADRAIN, &port) == -1) {
1579 commerror = WinError();
1589 commerror=WinError();
1598 /********************************************************************
1599 * PurgeComm (KERNEL32.@)
1601 * Terminates pending operations and/or discards buffers on a
1602 * communication resource.
1606 * True on success and false if the communications handle is bad.
1608 BOOL WINAPI PurgeComm(
1609 HANDLE handle, /* [in] The communication resource to be purged. */
1610 DWORD flags) /* [in] Flags for clear pending/buffer on input/output. */
1614 TRACE("handle %d, flags %lx\n", handle, flags);
1616 fd = FILE_GetUnixHandle( handle, GENERIC_READ );
1618 FIXME("no handle %d found\n",handle);
1623 ** not exactly sure how these are different
1624 ** Perhaps if we had our own internal queues, one flushes them
1625 ** and the other flushes the kernel's buffers.
1627 if(flags&PURGE_TXABORT)
1628 tcflush(fd,TCOFLUSH);
1629 if(flags&PURGE_RXABORT)
1630 tcflush(fd,TCIFLUSH);
1631 if(flags&PURGE_TXCLEAR)
1632 tcflush(fd,TCOFLUSH);
1633 if(flags&PURGE_RXCLEAR)
1634 tcflush(fd,TCIFLUSH);
1640 /*****************************************************************************
1641 * ClearCommError (KERNEL32.@)
1643 * Enables further I/O operations on a communications resource after
1644 * supplying error and current status information.
1648 * True on success, false if the communication resource handle is bad.
1650 BOOL WINAPI ClearCommError(
1651 HANDLE handle, /* [in] The communication resource with the error. */
1652 LPDWORD errors, /* [out] Flags indicating error the resource experienced. */
1653 LPCOMSTAT lpStat) /* [out] The status of the communication resource. */
1657 fd=FILE_GetUnixHandle( handle, GENERIC_READ );
1660 FIXME("no handle %d found\n",handle);
1669 if(ioctl(fd, TIOCOUTQ, &lpStat->cbOutQue))
1670 WARN("ioctl returned error\n");
1672 lpStat->cbOutQue = 0; /* FIXME: find a different way to find out */
1676 if(ioctl(fd, TIOCINQ, &lpStat->cbInQue))
1677 WARN("ioctl returned error\n");
1680 TRACE("handle %d cbInQue = %ld cbOutQue = %ld\n",
1681 handle, lpStat->cbInQue, lpStat->cbOutQue);
1690 ** After an asynchronous write opperation, the
1691 ** app will call ClearCommError to see if the
1692 ** results are ready yet. It waits for ERROR_IO_PENDING
1694 commerror = ERROR_IO_PENDING;
1699 /*****************************************************************************
1700 * SetupComm (KERNEL32.@)
1702 * Called after CreateFile to hint to the communication resource to use
1703 * specified sizes for input and output buffers rather than the default values.
1707 * True if successful, false if the communications resource handle is bad.
1713 BOOL WINAPI SetupComm(
1714 HANDLE handle, /* [in] The just created communication resource handle. */
1715 DWORD insize, /* [in] The suggested size of the communication resources input buffer in bytes. */
1716 DWORD outsize) /* [in] The suggested size of the communication resources output buffer in bytes. */
1720 FIXME("insize %ld outsize %ld unimplemented stub\n", insize, outsize);
1721 fd=FILE_GetUnixHandle( handle, GENERIC_READ );
1723 FIXME("handle %d not found?\n",handle);
1730 /*****************************************************************************
1731 * GetCommMask (KERNEL32.@)
1733 * Obtain the events associated with a communication device that will cause a call
1734 * WaitCommEvent to return.
1738 * True on success, fail on bad device handle etc.
1740 BOOL WINAPI GetCommMask(
1741 HANDLE handle, /* [in] The communications device. */
1742 LPDWORD evtmask) /* [out] The events which cause WaitCommEvent to return. */
1746 TRACE("handle %d, mask %p\n", handle, evtmask);
1748 SERVER_START_REQ( get_serial_info )
1750 req->handle = handle;
1751 if ((ret = !SERVER_CALL_ERR()))
1753 if (evtmask) *evtmask = req->eventmask;
1760 /*****************************************************************************
1761 * SetCommMask (KERNEL32.@)
1763 * There be some things we need to hear about yon there communications device.
1764 * (Set which events associated with a communication device should cause
1765 * a call WaitCommEvent to return.)
1769 * True on success, false on bad handle etc.
1771 BOOL WINAPI SetCommMask(
1772 HANDLE handle, /* [in] The communications device. */
1773 DWORD evtmask) /* [in] The events that to be monitored. */
1777 TRACE("handle %d, mask %lx\n", handle, evtmask);
1779 SERVER_START_REQ( set_serial_info )
1781 req->handle = handle;
1782 req->flags = SERIALINFO_SET_MASK;
1783 req->eventmask = evtmask;
1784 ret = !SERVER_CALL_ERR();
1790 /*****************************************************************************
1791 * SetCommState (KERNEL32.@)
1793 * Re-initializes all hardware and control settings of a communications device,
1794 * with values from a device control block without effecting the input and output
1799 * True on success, false on failure eg if the XonChar is equal to the XoffChar.
1801 BOOL WINAPI SetCommState(
1802 HANDLE handle, /* [in] The communications device. */
1803 LPDCB lpdcb) /* [out] The device control block. */
1805 struct termios port;
1806 int fd, bytesize, stopbits;
1808 TRACE("handle %d, ptr %p\n", handle, lpdcb);
1809 TRACE("bytesize %d baudrate %ld fParity %d Parity %d stopbits %d\n",
1810 lpdcb->ByteSize,lpdcb->BaudRate,lpdcb->fParity, lpdcb->Parity,
1811 (lpdcb->StopBits == ONESTOPBIT)?1:
1812 (lpdcb->StopBits == TWOSTOPBITS)?2:0);
1813 TRACE("%s %s\n",(lpdcb->fInX)?"IXON":"~IXON",
1814 (lpdcb->fOutX)?"IXOFF":"~IXOFF");
1816 fd = FILE_GetUnixHandle( handle, GENERIC_READ );
1818 FIXME("no handle %d found\n",handle);
1822 if ((tcgetattr(fd,&port)) == -1) {
1823 int save_error = errno;
1824 commerror = WinError();
1826 ERR("tcgetattr error '%s'\n", strerror(save_error));
1830 port.c_cc[VMIN] = 0;
1831 port.c_cc[VTIME] = 1;
1834 port.c_iflag &= ~(ISTRIP|BRKINT|IGNCR|ICRNL|INLCR|IMAXBEL);
1836 port.c_iflag &= ~(ISTRIP|BRKINT|IGNCR|ICRNL|INLCR);
1838 port.c_iflag |= (IGNBRK);
1840 port.c_oflag &= ~(OPOST);
1842 port.c_cflag &= ~(HUPCL);
1843 port.c_cflag |= CLOCAL | CREAD;
1845 port.c_lflag &= ~(ICANON|ECHO|ISIG);
1846 port.c_lflag |= NOFLSH;
1849 ** MJM - removed default baudrate settings
1850 ** TRACE(comm,"baudrate %ld\n",lpdcb->BaudRate);
1853 port.c_cflag &= ~CBAUD;
1854 switch (lpdcb->BaudRate) {
1857 port.c_cflag |= B110;
1861 port.c_cflag |= B300;
1865 port.c_cflag |= B600;
1869 port.c_cflag |= B1200;
1873 port.c_cflag |= B2400;
1877 port.c_cflag |= B4800;
1881 port.c_cflag |= B9600;
1885 port.c_cflag |= B19200;
1889 port.c_cflag |= B38400;
1893 port.c_cflag |= B57600;
1898 port.c_cflag |= B115200;
1903 port.c_cflag |= B230400;
1908 port.c_cflag |= B460800;
1912 commerror = IE_BAUDRATE;
1914 ERR("baudrate %ld\n",lpdcb->BaudRate);
1917 #elif !defined(__EMX__)
1918 switch (lpdcb->BaudRate) {
1921 port.c_ospeed = B110;
1925 port.c_ospeed = B300;
1929 port.c_ospeed = B600;
1933 port.c_ospeed = B1200;
1937 port.c_ospeed = B2400;
1941 port.c_ospeed = B4800;
1945 port.c_ospeed = B9600;
1949 port.c_ospeed = B19200;
1953 port.c_ospeed = B38400;
1956 commerror = IE_BAUDRATE;
1958 ERR("baudrate %ld\n",lpdcb->BaudRate);
1961 port.c_ispeed = port.c_ospeed;
1963 bytesize=lpdcb->ByteSize;
1964 stopbits=lpdcb->StopBits;
1967 port.c_cflag &= ~(PARENB | PARODD | CMSPAR);
1969 port.c_cflag &= ~(PARENB | PARODD);
1972 port.c_iflag |= INPCK;
1974 port.c_iflag &= ~INPCK;
1975 switch (lpdcb->Parity) {
1979 port.c_cflag |= (PARENB | PARODD);
1982 port.c_cflag |= PARENB;
1985 /* Linux defines mark/space (stick) parity */
1987 port.c_cflag |= (PARENB | CMSPAR);
1990 port.c_cflag |= (PARENB | PARODD | CMSPAR);
1993 /* try the POSIX way */
1995 if( stopbits == ONESTOPBIT) {
1996 stopbits = TWOSTOPBITS;
1997 port.c_iflag &= ~INPCK;
1999 commerror = IE_BYTESIZE;
2001 ERR("Cannot set MARK Parity\n");
2008 port.c_iflag &= ~INPCK;
2010 commerror = IE_BYTESIZE;
2012 ERR("Cannot set SPACE Parity\n");
2018 commerror = IE_BYTESIZE;
2025 port.c_cflag &= ~CSIZE;
2028 port.c_cflag |= CS5;
2031 port.c_cflag |= CS6;
2034 port.c_cflag |= CS7;
2037 port.c_cflag |= CS8;
2040 commerror = IE_BYTESIZE;
2048 port.c_cflag &= ~CSTOPB;
2050 case ONE5STOPBITS: /* wil be selected if bytesize is 5 */
2052 port.c_cflag |= CSTOPB;
2055 commerror = IE_BYTESIZE;
2061 if ( lpdcb->fOutxCtsFlow ||
2062 lpdcb->fRtsControl == RTS_CONTROL_ENABLE
2065 port.c_cflag |= CRTSCTS;
2069 if (lpdcb->fDtrControl == DTR_CONTROL_ENABLE)
2071 port.c_cflag &= ~CRTSCTS;
2072 TRACE("~CRTSCTS\n");
2077 port.c_iflag |= IXON;
2079 port.c_iflag &= ~IXON;
2081 port.c_iflag |= IXOFF;
2083 port.c_iflag &= ~IXOFF;
2085 if (tcsetattr(fd,TCSANOW,&port)==-1) { /* otherwise it hangs with pending input*/
2086 int save_error=errno;
2087 commerror = WinError();
2089 ERR("tcsetattr error '%s'\n", strerror(save_error));
2099 /*****************************************************************************
2100 * GetCommState (KERNEL32.@)
2102 * Fills in a device control block with information from a communications device.
2106 * True on success, false if the communication device handle is bad etc
2110 * XonChar and XoffChar are not set.
2112 BOOL WINAPI GetCommState(
2113 HANDLE handle, /* [in] The communications device. */
2114 LPDCB lpdcb) /* [out] The device control block. */
2116 struct termios port;
2119 TRACE("handle %d, ptr %p\n", handle, lpdcb);
2121 fd = FILE_GetUnixHandle( handle, GENERIC_READ );
2124 ERR("FILE_GetUnixHandle failed\n");
2127 if (tcgetattr(fd, &port) == -1) {
2128 int save_error=errno;
2129 ERR("tcgetattr error '%s'\n", strerror(save_error));
2130 commerror = WinError();
2137 speed= (port.c_cflag & CBAUD);
2139 speed= (cfgetospeed(&port));
2143 lpdcb->BaudRate = 110;
2146 lpdcb->BaudRate = 300;
2149 lpdcb->BaudRate = 600;
2152 lpdcb->BaudRate = 1200;
2155 lpdcb->BaudRate = 2400;
2158 lpdcb->BaudRate = 4800;
2161 lpdcb->BaudRate = 9600;
2164 lpdcb->BaudRate = 19200;
2167 lpdcb->BaudRate = 38400;
2171 lpdcb->BaudRate = 57600;
2176 lpdcb->BaudRate = 115200;
2181 lpdcb->BaudRate = 230400;
2186 lpdcb->BaudRate = 460800;
2190 ERR("unknown speed %x \n",speed);
2193 switch (port.c_cflag & CSIZE) {
2195 lpdcb->ByteSize = 5;
2198 lpdcb->ByteSize = 6;
2201 lpdcb->ByteSize = 7;
2204 lpdcb->ByteSize = 8;
2207 ERR("unknown size %x \n",port.c_cflag & CSIZE);
2210 if(port.c_iflag & INPCK)
2211 lpdcb->fParity = TRUE;
2213 lpdcb->fParity = FALSE;
2215 switch (port.c_cflag & (PARENB | PARODD | CMSPAR))
2217 switch (port.c_cflag & (PARENB | PARODD))
2221 lpdcb->Parity = NOPARITY;
2224 lpdcb->Parity = EVENPARITY;
2226 case (PARENB | PARODD):
2227 lpdcb->Parity = ODDPARITY;
2230 case (PARENB | CMSPAR):
2231 lpdcb->Parity = MARKPARITY;
2233 case (PARENB | PARODD | CMSPAR):
2234 lpdcb->Parity = SPACEPARITY;
2239 if (port.c_cflag & CSTOPB)
2240 if(lpdcb->ByteSize == 5)
2241 lpdcb->StopBits = ONE5STOPBITS;
2243 lpdcb->StopBits = TWOSTOPBITS;
2245 lpdcb->StopBits = ONESTOPBIT;
2252 if (port.c_cflag & CRTSCTS) {
2253 lpdcb->fDtrControl = DTR_CONTROL_ENABLE;
2254 lpdcb->fRtsControl = RTS_CONTROL_ENABLE;
2255 lpdcb->fOutxCtsFlow = 1;
2256 lpdcb->fOutxDsrFlow = 1;
2260 lpdcb->fDtrControl = DTR_CONTROL_DISABLE;
2261 lpdcb->fRtsControl = RTS_CONTROL_DISABLE;
2263 if (port.c_iflag & IXON)
2268 if (port.c_iflag & IXOFF)
2277 lpdcb->XoffLim = 10;
2283 TRACE("bytesize %d baudrate %ld fParity %d Parity %d stopbits %d\n",
2284 lpdcb->ByteSize,lpdcb->BaudRate,lpdcb->fParity, lpdcb->Parity,
2285 (lpdcb->StopBits == ONESTOPBIT)?1:
2286 (lpdcb->StopBits == TWOSTOPBITS)?2:0);
2287 TRACE("%s %s\n",(lpdcb->fInX)?"IXON":"~IXON",
2288 (lpdcb->fOutX)?"IXOFF":"~IXOFF");
2290 if ( lpdcb->fOutxCtsFlow ||
2291 lpdcb->fDtrControl == DTR_CONTROL_ENABLE||
2292 lpdcb->fRtsControl == RTS_CONTROL_ENABLE
2296 if (lpdcb->fDtrControl == DTR_CONTROL_DISABLE)
2297 TRACE("~CRTSCTS\n");
2303 /*****************************************************************************
2304 * TransmitCommChar (KERNEL32.@)
2306 * Transmits a single character in front of any pending characters in the
2307 * output buffer. Usually used to send an interrupt character to a host.
2311 * True if the call succeeded, false if the previous command character to the
2312 * same device has not been sent yet the handle is bad etc.
2318 BOOL WINAPI TransmitCommChar(
2319 HANDLE hComm, /* [in] The communication device in need of a command character. */
2320 CHAR chTransmit) /* [in] The character to transmit. */
2322 FIXME("(%x,'%c'), use win32 handle!\n",hComm,chTransmit);
2326 /*****************************************************************************
2327 * GetCommTimeouts (KERNEL32.@)
2329 * Obtains the request time out values for the communications device.
2333 * True on success, false if communications device handle is bad
2334 * or the target structure is null.
2336 BOOL WINAPI GetCommTimeouts(
2337 HANDLE hComm, /* [in] The communications device. */
2338 LPCOMMTIMEOUTS lptimeouts) /* [out] The struct of request time outs. */
2342 TRACE("(%x,%p)\n",hComm,lptimeouts);
2346 SetLastError(ERROR_INVALID_PARAMETER);
2350 SERVER_START_REQ( get_serial_info )
2352 req->handle = hComm;
2353 if ((ret = !SERVER_CALL_ERR()))
2355 lptimeouts->ReadIntervalTimeout = req->readinterval;
2356 lptimeouts->ReadTotalTimeoutMultiplier = req->readmult;
2357 lptimeouts->ReadTotalTimeoutConstant = req->readconst;
2358 lptimeouts->WriteTotalTimeoutMultiplier = req->writemult;
2359 lptimeouts->WriteTotalTimeoutConstant = req->writeconst;
2366 /*****************************************************************************
2367 * SetCommTimeouts (KERNEL32.@)
2369 * Sets the timeouts used when reading and writing data to/from COMM ports.
2371 * ReadIntervalTimeout
2372 * - converted and passes to linux kernel as c_cc[VTIME]
2373 * ReadTotalTimeoutMultiplier, ReadTotalTimeoutConstant
2374 * - used in ReadFile to calculate GetOverlappedResult's timeout
2375 * WriteTotalTimeoutMultiplier, WriteTotalTimeoutConstant
2376 * - used in WriteFile to calculate GetOverlappedResult's timeout
2380 * True if the time outs were set, false otherwise.
2382 BOOL WINAPI SetCommTimeouts(
2383 HANDLE hComm, /* [in] handle of COMM device */
2384 LPCOMMTIMEOUTS lptimeouts) /* [in] pointer to COMMTIMEOUTS structure */
2388 struct termios tios;
2390 TRACE("(%x,%p)\n",hComm,lptimeouts);
2394 SetLastError(ERROR_INVALID_PARAMETER);
2398 SERVER_START_REQ( set_serial_info )
2400 req->handle = hComm;
2401 req->flags = SERIALINFO_SET_TIMEOUTS;
2402 req->readinterval = lptimeouts->ReadIntervalTimeout ;
2403 req->readmult = lptimeouts->ReadTotalTimeoutMultiplier ;
2404 req->readconst = lptimeouts->ReadTotalTimeoutConstant ;
2405 req->writemult = lptimeouts->WriteTotalTimeoutMultiplier ;
2406 req->writeconst = lptimeouts->WriteTotalTimeoutConstant ;
2407 ret = !SERVER_CALL_ERR();
2410 if (!ret) return FALSE;
2412 /* FIXME: move this stuff to the server */
2413 fd = FILE_GetUnixHandle( hComm, GENERIC_READ );
2415 FIXME("no fd for handle = %0x!.\n",hComm);
2419 if (-1==tcgetattr(fd,&tios)) {
2420 FIXME("tcgetattr on fd %d failed!\n",fd);
2424 /* VTIME is in 1/10 seconds */
2426 unsigned int ux_timeout;
2428 if(lptimeouts->ReadIntervalTimeout == 0) /* 0 means no timeout */
2434 ux_timeout = (lptimeouts->ReadIntervalTimeout+99)/100;
2437 ux_timeout = 1; /* must be at least some timeout */
2440 tios.c_cc[VTIME] = ux_timeout;
2443 if (-1==tcsetattr(fd,0,&tios)) {
2444 FIXME("tcsetattr on fd %d failed!\n",fd);
2451 /***********************************************************************
2452 * GetCommModemStatus (KERNEL32.@)
2454 * Obtains the four control register bits if supported by the hardware.
2458 * True if the communications handle was good and for hardware that
2459 * control register access, false otherwise.
2461 BOOL WINAPI GetCommModemStatus(
2462 HANDLE hFile, /* [in] The communications device. */
2463 LPDWORD lpModemStat) /* [out] The control register bits. */
2465 int fd,mstat, result=FALSE;
2469 fd = FILE_GetUnixHandle( hFile, GENERIC_READ );
2472 result = ioctl(fd, TIOCMGET, &mstat);
2476 WARN("ioctl failed\n");
2480 if (mstat & TIOCM_CTS)
2481 *lpModemStat |= MS_CTS_ON;
2484 if (mstat & TIOCM_DSR)
2485 *lpModemStat |= MS_DSR_ON;
2488 if (mstat & TIOCM_RNG)
2489 *lpModemStat |= MS_RING_ON;
2492 /*FIXME: Not really sure about RLSD UB 990810*/
2493 if (mstat & TIOCM_CAR)
2494 *lpModemStat |= MS_RLSD_ON;
2496 TRACE("%04x -> %s%s%s%s\n", mstat,
2497 (*lpModemStat &MS_RLSD_ON)?"MS_RLSD_ON ":"",
2498 (*lpModemStat &MS_RING_ON)?"MS_RING_ON ":"",
2499 (*lpModemStat &MS_DSR_ON)?"MS_DSR_ON ":"",
2500 (*lpModemStat &MS_CTS_ON)?"MS_CTS_ON ":"");
2507 /***********************************************************************
2508 * COMM_WaitCommEventService (INTERNAL)
2510 * This function is called while the client is waiting on the
2511 * server, so we can't make any server calls here.
2513 static void COMM_WaitCommEventService(async_private *ovp, int events)
2515 LPOVERLAPPED lpOverlapped = ovp->lpOverlapped;
2517 TRACE("overlapped %p wait complete %p <- %x\n",lpOverlapped,ovp->buffer,events);
2520 lpOverlapped->Internal = STATUS_HANDLES_CLOSED;
2526 *ovp->buffer = EV_RXCHAR;
2529 lpOverlapped->Internal = STATUS_SUCCESS;
2534 /***********************************************************************
2535 * COMM_WaitCommEvent (INTERNAL)
2537 * This function must have an lpOverlapped.
2539 static BOOL COMM_WaitCommEvent(
2540 HANDLE hFile, /* [in] handle of comm port to wait for */
2541 LPDWORD lpdwEvents, /* [out] event(s) that were detected */
2542 LPOVERLAPPED lpOverlapped) /* [in/out] for Asynchronous waiting */
2549 SetLastError(ERROR_INVALID_PARAMETER);
2553 if(NtResetEvent(lpOverlapped->hEvent,NULL))
2556 lpOverlapped->Internal = STATUS_PENDING;
2557 lpOverlapped->InternalHigh = 0;
2558 lpOverlapped->Offset = 0;
2559 lpOverlapped->OffsetHigh = 0;
2561 /* start an ASYNCHRONOUS WaitCommEvent */
2562 SERVER_START_REQ( create_async )
2564 req->file_handle = hFile;
2566 req->type = ASYNC_TYPE_WAIT;
2568 ret=SERVER_CALL_ERR();
2575 fd = FILE_GetUnixHandle( hFile, GENERIC_WRITE );
2579 ovp = (async_private *) HeapAlloc(GetProcessHeap(), 0, sizeof (async_private));
2585 ovp->lpOverlapped = lpOverlapped;
2588 ovp->tv.tv_usec = 0;
2589 ovp->event = POLLIN;
2590 ovp->func = COMM_WaitCommEventService;
2591 ovp->buffer = (char *)lpdwEvents;
2594 ovp->completion_func = 0;
2596 ovp->next = NtCurrentTeb()->pending_list;
2599 ovp->next->prev=ovp;
2600 NtCurrentTeb()->pending_list = ovp;
2602 SetLastError(ERROR_IO_PENDING);
2607 /***********************************************************************
2608 * WaitCommEvent (KERNEL32.@)
2610 * Wait until something interesting happens on a COMM port.
2611 * Interesting things (events) are set by calling SetCommMask before
2612 * this function is called.
2615 * TRUE if successful
2618 * The set of detected events will be written to *lpdwEventMask
2619 * ERROR_IO_PENDING will be returned the overlapped structure was passed
2622 * Only supports EV_RXCHAR and EV_TXEMPTY
2624 BOOL WINAPI WaitCommEvent(
2625 HANDLE hFile, /* [in] handle of comm port to wait for */
2626 LPDWORD lpdwEvents, /* [out] event(s) that were detected */
2627 LPOVERLAPPED lpOverlapped) /* [in/out] for Asynchronous waiting */
2632 TRACE("(%x %p %p )\n",hFile, lpdwEvents,lpOverlapped);
2635 return COMM_WaitCommEvent(hFile, lpdwEvents, lpOverlapped);
2637 /* if there is no overlapped structure, create our own */
2638 ov.hEvent = CreateEventA(NULL,FALSE,FALSE,NULL);
2640 COMM_WaitCommEvent(hFile, lpdwEvents, &ov);
2642 if(GetLastError()!=STATUS_PENDING)
2644 CloseHandle(ov.hEvent);
2648 /* wait for the overlapped to complete */
2649 ret = GetOverlappedResult(hFile, &ov, NULL, TRUE);
2650 CloseHandle(ov.hEvent);
2655 /***********************************************************************
2656 * GetCommProperties (KERNEL32.@)
2658 * This function fills in a structure with the capabilities of the
2659 * communications port driver.
2663 * TRUE on success, FALSE on failure
2664 * If successful, the lpCommProp structure be filled in with
2665 * properties of the comm port.
2667 BOOL WINAPI GetCommProperties(
2668 HANDLE hFile, /* [in] handle of the comm port */
2669 LPCOMMPROP lpCommProp) /* [out] pointer to struct to be filled */
2671 FIXME("(%d %p )\n",hFile,lpCommProp);
2676 * These values should be valid for LINUX's serial driver
2677 * FIXME: Perhaps they deserve an #ifdef LINUX
2679 memset(lpCommProp,0,sizeof(COMMPROP));
2680 lpCommProp->wPacketLength = 1;
2681 lpCommProp->wPacketVersion = 1;
2682 lpCommProp->dwServiceMask = SP_SERIALCOMM;
2683 lpCommProp->dwReserved1 = 0;
2684 lpCommProp->dwMaxTxQueue = 4096;
2685 lpCommProp->dwMaxRxQueue = 4096;
2686 lpCommProp->dwMaxBaud = BAUD_115200;
2687 lpCommProp->dwProvSubType = PST_RS232;
2688 lpCommProp->dwProvCapabilities = PCF_DTRDSR | PCF_PARITY_CHECK | PCF_RTSCTS ;
2689 lpCommProp->dwSettableParams = SP_BAUD | SP_DATABITS | SP_HANDSHAKING |
2690 SP_PARITY | SP_PARITY_CHECK | SP_STOPBITS ;
2691 lpCommProp->dwSettableBaud = BAUD_075 | BAUD_110 | BAUD_134_5 | BAUD_150 |
2692 BAUD_300 | BAUD_600 | BAUD_1200 | BAUD_1800 | BAUD_2400 | BAUD_4800 |
2693 BAUD_9600 | BAUD_19200 | BAUD_38400 | BAUD_57600 | BAUD_115200 ;
2694 lpCommProp->wSettableData = DATABITS_5 | DATABITS_6 | DATABITS_7 | DATABITS_8 ;
2695 lpCommProp->wSettableStopParity = STOPBITS_10 | STOPBITS_15 | STOPBITS_20 |
2696 PARITY_NONE | PARITY_ODD |PARITY_EVEN | PARITY_MARK | PARITY_SPACE;
2697 lpCommProp->dwCurrentTxQueue = lpCommProp->dwMaxTxQueue;
2698 lpCommProp->dwCurrentRxQueue = lpCommProp->dwMaxRxQueue;
2703 /***********************************************************************
2705 * The functionality of CommConfigDialogA, GetDefaultCommConfig and
2706 * SetDefaultCommConfig is implemented in a DLL (usually SERIALUI.DLL).
2707 * This is dependent on the type of COMM port, but since it is doubtful
2708 * anybody will get around to implementing support for fancy serial
2709 * ports in WINE, this is hardcoded for the time being. The name of
2710 * this DLL should be stored in and read from the system registry in
2711 * the hive HKEY_LOCAL_MACHINE, key
2712 * System\\CurrentControlSet\\Services\\Class\\Ports\\????
2713 * where ???? is the port number... that is determined by PNP
2714 * The DLL should be loaded when the COMM port is opened, and closed
2715 * when the COMM port is closed. - MJM 20 June 2000
2716 ***********************************************************************/
2717 static CHAR lpszSerialUI[] = "serialui.dll";
2720 /***********************************************************************
2721 * CommConfigDialogA (KERNEL32.@)
2723 * Raises a dialog that allows the user to configure a comm port.
2724 * Fills the COMMCONFIG struct with information specified by the user.
2725 * This function should call a similar routine in the COMM driver...
2729 * TRUE on success, FALSE on failure
2730 * If successful, the lpCommConfig structure will contain a new
2731 * configuration for the comm port, as specified by the user.
2734 * The library with the CommConfigDialog code is never unloaded.
2735 * Perhaps this should be done when the comm port is closed?
2737 BOOL WINAPI CommConfigDialogA(
2738 LPCSTR lpszDevice, /* [in] name of communications device */
2739 HANDLE hWnd, /* [in] parent window for the dialog */
2740 LPCOMMCONFIG lpCommConfig) /* [out] pointer to struct to fill */
2742 FARPROC lpfnCommDialog;
2743 HMODULE hConfigModule;
2746 TRACE("(%p %x %p)\n",lpszDevice, hWnd, lpCommConfig);
2748 hConfigModule = LoadLibraryA(lpszSerialUI);
2752 lpfnCommDialog = GetProcAddress(hConfigModule, (LPCSTR)3L);
2757 r = lpfnCommDialog(lpszDevice,hWnd,lpCommConfig);
2759 /* UnloadLibrary(hConfigModule); */
2764 /***********************************************************************
2765 * CommConfigDialogW (KERNEL32.@)
2767 * see CommConfigDialogA for more info
2769 BOOL WINAPI CommConfigDialogW(
2770 LPCWSTR lpszDevice, /* [in] name of communications device */
2771 HANDLE hWnd, /* [in] parent window for the dialog */
2772 LPCOMMCONFIG lpCommConfig) /* [out] pointer to struct to fill */
2777 lpDeviceA = HEAP_strdupWtoA( GetProcessHeap(), 0, lpszDevice );
2780 r = CommConfigDialogA(lpDeviceA,hWnd,lpCommConfig);
2781 HeapFree( GetProcessHeap(), 0, lpDeviceA );
2785 /***********************************************************************
2786 * GetCommConfig (KERNEL32.@)
2788 * Fill in the COMMCONFIG structure for the comm port hFile
2792 * TRUE on success, FALSE on failure
2793 * If successful, lpCommConfig contains the comm port configuration.
2797 * The signature is missing a the parameter for the size of the COMMCONFIG
2798 * structure/buffer it should be
2799 * BOOL WINAPI GetCommConfig(HANDLE hFile,LPCOMMCONFIG lpCommConfig,LPDWORD lpdwSize)
2801 BOOL WINAPI GetCommConfig(
2802 HANDLE hFile, /* [in] The communications device. */
2803 LPCOMMCONFIG lpCommConfig, /* [out] The communications configuration of the device (if it fits). */
2804 LPDWORD lpdwSize) /* [in/out] Initially the size of the configuration buffer/structure,
2805 afterwards the number of bytes copied to the buffer or
2806 the needed size of the buffer. */
2810 TRACE("(%x %p)\n",hFile,lpCommConfig);
2812 if(lpCommConfig == NULL)
2815 r = *lpdwSize < sizeof(COMMCONFIG);
2816 *lpdwSize = sizeof(COMMCONFIG);
2820 lpCommConfig->dwSize = sizeof(COMMCONFIG);
2821 lpCommConfig->wVersion = 1;
2822 lpCommConfig->wReserved = 0;
2823 r = GetCommState(hFile,&lpCommConfig->dcb);
2824 lpCommConfig->dwProviderSubType = PST_RS232;
2825 lpCommConfig->dwProviderOffset = 0;
2826 lpCommConfig->dwProviderSize = 0;
2831 /***********************************************************************
2832 * SetCommConfig (KERNEL32.@)
2834 * Sets the configuration of the commications device.
2838 * True on success, false if the handle was bad is not a communications device.
2840 BOOL WINAPI SetCommConfig(
2841 HANDLE hFile, /* [in] The communications device. */
2842 LPCOMMCONFIG lpCommConfig) /* [in] The desired configuration. */
2844 TRACE("(%x %p)\n",hFile,lpCommConfig);
2845 return SetCommState(hFile,&lpCommConfig->dcb);
2848 /***********************************************************************
2849 * SetDefaultCommConfigA (KERNEL32.@)
2851 * Initializes the default configuration for the specified communication
2856 * True if the device was found and the defaults set, false otherwise
2858 BOOL WINAPI SetDefaultCommConfigA(
2859 LPCSTR lpszDevice, /* [in] The ascii name of the device targeted for configuration. */
2860 LPCOMMCONFIG lpCommConfig, /* [in] The default configuration for the device. */
2861 DWORD dwSize) /* [in] The number of bytes in the configuration structure. */
2863 FARPROC lpfnSetDefaultCommConfig;
2864 HMODULE hConfigModule;
2867 TRACE("(%p %p %lx)\n",lpszDevice, lpCommConfig, dwSize);
2869 hConfigModule = LoadLibraryA(lpszSerialUI);
2873 lpfnSetDefaultCommConfig = GetProcAddress(hConfigModule, (LPCSTR)4L);
2875 if(! lpfnSetDefaultCommConfig)
2878 r = lpfnSetDefaultCommConfig(lpszDevice, lpCommConfig, dwSize);
2880 /* UnloadLibrary(hConfigModule); */
2886 /***********************************************************************
2887 * SetDefaultCommConfigW (KERNEL32.@)
2889 * Initializes the default configuration for the specified
2890 * communication device. (unicode)
2895 BOOL WINAPI SetDefaultCommConfigW(
2896 LPCWSTR lpszDevice, /* [in] The unicode name of the device targeted for configuration. */
2897 LPCOMMCONFIG lpCommConfig, /* [in] The default configuration for the device. */
2898 DWORD dwSize) /* [in] The number of bytes in the configuration structure. */
2903 TRACE("(%s %p %lx)\n",debugstr_w(lpszDevice),lpCommConfig,dwSize);
2905 lpDeviceA = HEAP_strdupWtoA( GetProcessHeap(), 0, lpszDevice );
2908 r = SetDefaultCommConfigA(lpDeviceA,lpCommConfig,dwSize);
2909 HeapFree( GetProcessHeap(), 0, lpDeviceA );
2914 /***********************************************************************
2915 * GetDefaultCommConfigA (KERNEL32.@)
2917 * Acquires the default configuration of the specified communication device. (unicode)
2921 * True on successful reading of the default configuration,
2922 * if the device is not found or the buffer is too small.
2924 BOOL WINAPI GetDefaultCommConfigA(
2925 LPCSTR lpszName, /* [in] The ascii name of the device targeted for configuration. */
2926 LPCOMMCONFIG lpCC, /* [out] The default configuration for the device. */
2927 LPDWORD lpdwSize) /* [in/out] Initially the size of the default configuration buffer,
2928 afterwards the number of bytes copied to the buffer or
2929 the needed size of the buffer. */
2931 LPDCB lpdcb = &(lpCC->dcb);
2934 if (strncasecmp(lpszName,"COM",3)) {
2935 ERR("not implemented for <%s>\n", lpszName);
2939 if (!ValidCOMPort(lpszName[3]-'1'))
2942 TRACE("(%s %p %ld)\n", lpszName, lpCC, *lpdwSize );
2943 if (*lpdwSize < sizeof(COMMCONFIG)) {
2944 *lpdwSize = sizeof(COMMCONFIG);
2948 *lpdwSize = sizeof(COMMCONFIG);
2950 lpCC->dwSize = sizeof(COMMCONFIG);
2952 lpCC->dwProviderSubType = PST_RS232;
2953 lpCC->dwProviderOffset = 0L;
2954 lpCC->dwProviderSize = 0L;
2956 (void) sprintf( temp, "COM%c:38400,n,8,1", lpszName[3]);
2957 FIXME("setting %s as default\n", temp);
2959 return BuildCommDCBA( temp, lpdcb);
2962 /**************************************************************************
2963 * GetDefaultCommConfigW (KERNEL32.@)
2965 * Acquires the default configuration of the specified communication device. (unicode)
2969 * True on successful reading of the default configuration,
2970 * if the device is not found or the buffer is too small.
2972 BOOL WINAPI GetDefaultCommConfigW(
2973 LPCWSTR lpszName, /* [in] The unicode name of the device targeted for configuration. */
2974 LPCOMMCONFIG lpCC, /* [out] The default configuration for the device. */
2975 LPDWORD lpdwSize) /* [in/out] Initially the size of the default configuration buffer,
2976 afterwards the number of bytes copied to the buffer or
2977 the needed size of the buffer. */
2982 TRACE("(%p,%p,%ld)\n",lpszName,lpCC,*lpdwSize);
2983 lpszNameA = HEAP_strdupWtoA( GetProcessHeap(), 0, lpszName );
2986 ret=GetDefaultCommConfigA(lpszNameA,lpCC,lpdwSize);
2987 HeapFree( GetProcessHeap(), 0, lpszNameA );