20 #include "../../gsmstate.h" 22 #ifdef GSM_ENABLE_SERIALDEVICE 25 #define WIN32_LEAN_AND_MEAN 33 #if defined(GSM_ENABLE_DKU2PHONET) || defined(GSM_ENABLE_DKU2AT) 34 # include <initguid.h> 35 # include <setupapi.h> 37 # pragma comment(lib, "setupapi.lib") 38 # pragma comment(lib, "advapi32.lib") 42 #include "../../gsmcomon.h" 56 PurgeComm(d->
hPhone, PURGE_TXABORT | PURGE_RXABORT |
57 PURGE_TXCLEAR | PURGE_RXCLEAR);
60 EscapeCommFunction(d->
hPhone, CLRDTR);
69 if (CloseHandle(d->
hPhone)==0) {
76 #if defined(GSM_ENABLE_DKU2PHONET) || defined(GSM_ENABLE_DKU2AT) 77 DEFINE_GUID(DKU2AT, 0x4F919104, 0x4adf, 0x11d5, 0x88, 0x2d, 0x0, 0xb0, 0xd0, 0x2f, 0xe3, 0x81);
78 DEFINE_GUID(DKU2FBUS2, 0x4F919102, 0x4adf, 0x11d5, 0x88, 0x2d, 0x0, 0xb0, 0xd0, 0x2f, 0xe3, 0x81);
79 DEFINE_GUID(DKU2OBEX, 0x4F919100, 0x4adf, 0x11d5, 0x88, 0x2d, 0x0, 0xb0, 0xd0, 0x2f, 0xe3, 0x81);
86 unsigned char DeviceName[256],DeviceName2[256];
89 #if defined(GSM_ENABLE_DKU2PHONET) || defined(GSM_ENABLE_DKU2AT) 90 UCHAR bu[
sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA) +(
sizeof(TCHAR)*1000)];
92 SP_DEVINFO_DATA DeviceInfoData;
93 SP_DEVICE_INTERFACE_DATA DeviceInterfaceData;
94 PSP_DEVICE_INTERFACE_DETAIL_DATA DeviceInterfaceDetailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA)bu;
96 unsigned char KeyName2[256];
98 #ifdef GSM_ENABLE_DKU5FBUS2 100 DWORD DeviceNameLen, KeyNameLen;
101 unsigned char KeyName[256];
106 #ifdef GSM_ENABLE_DKU2PHONET 108 ListHandle = SetupDiGetClassDevs(&DKU2FBUS2, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
109 if (ListHandle == INVALID_HANDLE_VALUE) {
110 SetupDiDestroyDeviceInfoList(ListHandle);
113 DeviceInfoData.cbSize =
sizeof(DeviceInfoData);
114 DeviceInterfaceData.cbSize =
sizeof(DeviceInterfaceData);
115 if (SetupDiEnumDeviceInfo(ListHandle, 0, &DeviceInfoData)) {
116 SetupDiGetDeviceRegistryProperty(ListHandle, &DeviceInfoData, SPDRP_DEVICEDESC, NULL, KeyName2, 200, &reqsize);
117 if (SetupDiEnumDeviceInterfaces(ListHandle, &DeviceInfoData, &DKU2FBUS2, 0, &DeviceInterfaceData)) {
118 DeviceInterfaceDetailData->cbSize = 5;
119 if (SetupDiGetDeviceInterfaceDetail(ListHandle, &DeviceInterfaceData, DeviceInterfaceDetailData, 200, &reqsize, &DeviceInfoData)) {
120 strcpy(DeviceName2,DeviceInterfaceDetailData->DevicePath);
124 SetupDiDestroyDeviceInfoList(ListHandle);
127 #ifdef GSM_ENABLE_DKU2AT 129 ListHandle = SetupDiGetClassDevs(&DKU2AT, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
130 if (ListHandle == INVALID_HANDLE_VALUE) {
131 SetupDiDestroyDeviceInfoList(ListHandle);
134 DeviceInfoData.cbSize =
sizeof(DeviceInfoData);
135 DeviceInterfaceData.cbSize =
sizeof(DeviceInterfaceData);
136 if (SetupDiEnumDeviceInfo(ListHandle, 0, &DeviceInfoData)) {
137 SetupDiGetDeviceRegistryProperty(ListHandle, &DeviceInfoData, SPDRP_DEVICEDESC, NULL, KeyName2, 200, &reqsize);
138 if (SetupDiEnumDeviceInterfaces(ListHandle, &DeviceInfoData, &DKU2AT, 0, &DeviceInterfaceData)) {
139 DeviceInterfaceDetailData->cbSize = 5;
140 if (SetupDiGetDeviceInterfaceDetail(ListHandle, &DeviceInterfaceData, DeviceInterfaceDetailData, 200, &reqsize, &DeviceInfoData)) {
141 strcpy(DeviceName2,DeviceInterfaceDetailData->DevicePath);
145 SetupDiDestroyDeviceInfoList(ListHandle);
148 #ifdef GSM_ENABLE_DKU5FBUS2 150 smprintf(s,
"Reading DKU5 device\n");
153 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
"HARDWARE\\DEVICEMAP\\SERIALCOMM", 0, KEY_QUERY_VALUE, &hKey) != ERROR_SUCCESS) {
161 if (RegEnumValue(hKey,i,KeyName,&KeyNameLen,NULL,NULL,DeviceName2,&DeviceNameLen) != ERROR_SUCCESS)
break;
162 if (!strncmp(KeyName,
"\\Device\\AtmelVirtualPort",24))
break;
167 if (strlen(DeviceName2) == 0) {
169 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
"Enum\\USBVSP\\ATMELPORT\\0000", 0, KEY_QUERY_VALUE, &hKey) != ERROR_SUCCESS) {
177 if (RegEnumValue(hKey,i,KeyName,&KeyNameLen,NULL,NULL,DeviceName2,&DeviceNameLen) != ERROR_SUCCESS)
break;
178 if (!strncmp(KeyName,
"PORTNAME",8))
break;
183 if (strlen(DeviceName2) == 0) {
187 smprintf(s,
"DKU5 device is \"%s\"\n",DeviceName2);
192 (!strncmp(DeviceName2,
"com",3) && strlen(DeviceName2)>3)) {
193 sprintf(DeviceName,
"\\\\.\\COM%i",atoi(DeviceName2+3));
195 strcpy(DeviceName,DeviceName2);
198 smprintf(s,
"Device is %s\n",DeviceName);
201 d->
hPhone = CreateFile(DeviceName,
202 GENERIC_READ | GENERIC_WRITE,
206 FILE_ATTRIBUTE_NORMAL,
209 if (d->
hPhone == INVALID_HANDLE_VALUE) {
210 err = GetLastError();
228 SetCommMask(d->
hPhone, EV_RXCHAR | EV_BREAK | EV_ERR);
231 SetupComm(d->
hPhone, 4096, 4096);
236 PurgeComm(d->
hPhone, PURGE_TXABORT | PURGE_RXABORT |
237 PURGE_TXCLEAR | PURGE_RXCLEAR);
242 dcb.Parity = NOPARITY;
243 dcb.StopBits = ONESTOPBIT;
256 if (SetCommState(d->
hPhone, &dcb)==0) {
270 dcb.DCBlength =
sizeof(DCB);
271 if (GetCommState(d->
hPhone, &dcb)==0) {
277 dcb.Parity = ODDPARITY;
279 dcb.Parity = NOPARITY;
282 if (SetCommState(d->
hPhone, &dcb)==0) {
297 dcb.DCBlength =
sizeof(DCB);
298 if (GetCommState(d->
hPhone, &dcb)==0) {
303 dcb.fOutxDsrFlow = 0;
304 dcb.fDtrControl = DTR_CONTROL_DISABLE;
305 if (dtr) dcb.fDtrControl = DTR_CONTROL_ENABLE;
307 dcb.fOutxCtsFlow = 0;
308 dcb.fRtsControl = RTS_CONTROL_DISABLE;
309 if (rts) dcb.fRtsControl = RTS_CONTROL_ENABLE;
312 dcb.fInX = dcb.fOutX = 0;
314 if (SetCommState(d->
hPhone, &dcb)==0) {
321 dcb.DCBlength =
sizeof(DCB);
322 GetCommState(d->
hPhone, &dcb);
326 switch (dcb.fDtrControl) {
327 case DTR_CONTROL_ENABLE :
smprintf(s,
"up");
break;
328 case DTR_CONTROL_DISABLE :
smprintf(s,
"down");
break;
329 case DTR_CONTROL_HANDSHAKE :
smprintf(s,
"handshake");
break;
332 switch (dcb.fRtsControl) {
333 case RTS_CONTROL_ENABLE :
smprintf(s,
"up");
break;
334 case RTS_CONTROL_DISABLE :
smprintf(s,
"down");
break;
335 case RTS_CONTROL_HANDSHAKE :
smprintf(s,
"handshake");
break;
336 case RTS_CONTROL_TOGGLE :
smprintf(s,
"toggle");
break;
344 PurgeComm(d->
hPhone, PURGE_TXABORT | PURGE_RXABORT |
345 PURGE_TXCLEAR | PURGE_RXCLEAR);
357 dcb.DCBlength =
sizeof(DCB);
358 if (GetCommState(d->
hPhone, &dcb)==0) {
363 dcb.BaudRate = speed;
365 if (SetCommState(d->
hPhone, &dcb)==0) {
370 smprintf(s,
"Setting speed to %d\n", speed);
378 DWORD ErrorFlags, Length, Error;
386 ClearCommError(d->
hPhone, &ErrorFlags, &ComStat);
389 Length = min(nbytes, ComStat.cbInQue);
395 if (Length <= 0)
goto end;
398 if (Length > nbytes) Length = nbytes;
401 ReadStatus = ReadFile(d->
hPhone, buf, Length, &Length, &d->osRead);
404 if (GetLastError() != ERROR_IO_PENDING) {
406 ClearCommError(d->
hPhone, &ErrorFlags, &ComStat);
414 while (!GetOverlappedResult(d->
hPhone, &d->osRead, &Length,
TRUE)) {
415 Error = GetLastError();
416 if (Error == ERROR_IO_INCOMPLETE) {
422 ClearCommError(d->
hPhone, &ErrorFlags, &ComStat);
431 static int serial_write(
GSM_StateMachine *s,
const void *buf,
size_t nbytes)
433 DWORD BytesWritten,ErrorFlags,BytesSent=0;
437 if (WriteFile(d->
hPhone, buf, nbytes, &BytesSent, &d->osWrite))
return BytesSent;
439 if (GetLastError() != ERROR_IO_PENDING) {
441 ClearCommError(d->
hPhone, &ErrorFlags, &ComStat);
446 if (GetOverlappedResult(d->
hPhone, &d->osWrite, &BytesWritten,
TRUE))
break;
447 if (GetLastError() != ERROR_IO_INCOMPLETE) {
449 ClearCommError(d->
hPhone, &ErrorFlags, &ComStat);
452 BytesSent += BytesWritten;
454 BytesSent += BytesWritten;
GSM_Config * CurrentConfig
union GSM_Device::@0 Data
GSM_ConnectionType ConnectionType
void GSM_OSErrorInfo(GSM_StateMachine *s, const char *description)
struct termios old_settings
int smprintf(GSM_StateMachine *s, const char *format,...)