#ifdef CF__LINUX #include "win2linux.h" #include "win2linux_ioctl.h" //--------------------------------------- void ShowMessage(std::string msg) { printf("****************************************************"); printf("* MESSAGE:: %s \n",msg.c_str()); printf("****************************************************"); } //--------------------------------------- void MessageBox(void *, const char *msg, const char *, int) { printf("****************************************************"); printf("* MESSAGE:: %s \n",msg); printf("****************************************************"); } //--------------------------------------- void ShowLastError(const char *msg) { printf("****************************************************"); printf("* ERROR:: %s \n",msg); printf("****************************************************"); }; //--------------------------------------- //-- Global Vars for ALARM -- //--------------------------------------- BULK_IOCTL bulk_ioctl; static int ENABLE_ALARM; int* USBDeviceH; void usb_alarm_enable(int m) { ENABLE_ALARM=m; } void usb_alarm(int) { BULK_TRANSFER_CONTROL* Ctrl_tmp; time_t tm; time(&tm); printf(" ***************************************\n"); printf(" *** USB ALARM *** %s \n",ctime(&tm)); printf(" *** USB ALARM *** USB=%p \n",USBDeviceH); printf(" *** USB ALARM *** IOCTL=%#X\n",bulk_ioctl.IOCTL_SLBUSB); Ctrl_tmp=(BULK_TRANSFER_CONTROL*)bulk_ioctl.Control; printf(" *** USB ALARM *** pipeNum=%lu\n",Ctrl_tmp->pipeNum); printf(" *** USB ALARM *** Buffer size=%u\n",bulk_ioctl.sizeBuffer); printf(" ***************************************\n"); } //===================================================================================== int DeviceIoControl (int* USBDeviceHandle, int IOCTL_SLBUSB, void *Control, int sizeControl, void *ioBuffer, int sizeBuffer, unsigned long *doneBytes, void *)//dummyNULL) { int result, dataleft, dataptr, pipe; BULK_TRANSFER_CONTROL* Ctrl; //- move to Global temporary for ALARM // BULK_IOCTL bulk_ioctl; #define BUFFER_SIZE_PIPE01 64 int ioctl_RD, ioctl_WR; ioctl_RD=IOCTL_SLBUSB_BULK_READ; ioctl_WR=IOCTL_SLBUSB_BULK_WRITE; /*printf("DeviceIoControl():: Enter IOCTL=%#x Read=%#x(%#x) Write=%#x(%#x) \n" ,IOCTL_SLBUSB,IOCTL_SLBUSB_BULK_READ,ioctl_RD,IOCTL_SLBUSB_BULK_WRITE,ioctl_WR); */ if (ENABLE_ALARM) alarm(5); USBDeviceH=USBDeviceHandle; /* !!!! This "if" does not work for SUSE 10.3 64 bit !!!! Even if #define _IOC_TYPECHECK(t) sizeof(t) //-- Redefined as in Suse 10.2 !!!!! if ( IOCTL_SLBUSB==IOCTL_SLBUSB_BULK_READ || IOCTL_SLBUSB==IOCTL_SLBUSB_BULK_WRITE) { if ( IOCTL_SLBUSB==(((2U|1U) << (((0 +8)+8)+14)) | ((('U')) << (0 +8)) | (((0 +13)) << 0) | (((sizeof(BULK_IOCTL))) << ((0 +8)+8))) || IOCTL_SLBUSB==(((2U|1U) << (((0 +8)+8)+14)) | ((('U')) << (0 +8)) | (((0 +14)) << 0) | (((sizeof(BULK_IOCTL))) << ((0 +8)+8)))) { */ if ( IOCTL_SLBUSB==ioctl_RD || IOCTL_SLBUSB==ioctl_WR) { bulk_ioctl.IOCTL_SLBUSB=IOCTL_SLBUSB; bulk_ioctl.Control=Control; bulk_ioctl.sizeControl=sizeControl; bulk_ioctl.sizeBuffer=sizeBuffer; bulk_ioctl.ioBuffer=ioBuffer; Ctrl=(BULK_TRANSFER_CONTROL*)Control; /* printf("DeviceIoControl():: IOCTL=%#x, Control=%p sizCtl=%d Buf=%p sizBuf=%d\n" ,IOCTL_SLBUSB,Control,sizeControl,ioBuffer,sizeBuffer); */ pipe=Ctrl->pipeNum; if ( pipe<2 && sizeBuffer>BUFFER_SIZE_PIPE01) { //-- buffer size for pipes 0&1 = 64 bytes !!!! dataleft = sizeBuffer; dataptr = 0; *doneBytes=0; do { bulk_ioctl.ioBuffer=(char*)ioBuffer+dataptr; bulk_ioctl.sizeBuffer=BUFFER_SIZE_PIPE01; result=ioctl(*USBDeviceHandle,IOCTL_SLBUSB,&bulk_ioctl); dataleft -= bulk_ioctl.doneBytes; dataptr += bulk_ioctl.doneBytes; *doneBytes+=bulk_ioctl.doneBytes; //printf("pipe=%d bytes get=%d done=%d of %d left=%d buf-size=%d \n" // ,pipe,bulk_ioctl.doneBytes,*doneBytes,sizeBuffer,dataleft,BUFFER_SIZE_PIPE01); } while (dataleft >= BUFFER_SIZE_PIPE01); if (dataleft>0) { bulk_ioctl.sizeBuffer=dataleft; bulk_ioctl.ioBuffer=(char*)ioBuffer+dataptr; //printf("pipe=%d get rest %d \n",pipe,dataleft); result=ioctl(*USBDeviceHandle,IOCTL_SLBUSB,&bulk_ioctl); *doneBytes+=bulk_ioctl.doneBytes; } } else { result=ioctl(*USBDeviceHandle,IOCTL_SLBUSB,&bulk_ioctl); *doneBytes=bulk_ioctl.doneBytes; } if ( IOCTL_SLBUSB==(int)IOCTL_SLBUSB_BULK_READ && (((unsigned long)sizeBuffer)<*doneBytes)){ printf("******* ERROR DeviceIoControl:: sizeBuffer=%d < doneBytes=%ld \n",sizeBuffer,*doneBytes); return 0; } } else { //printf("DeviceIoControl():: ELSE !!! IOCTL=%#x, Control=%p sizCtl=%d Buf=%p sizBuf=%d\n" // ,IOCTL_SLBUSB,Control,sizeControl,ioBuffer,sizeBuffer); result=ioctl(*USBDeviceHandle,IOCTL_SLBUSB,ioBuffer); } //printf("---> IOCTL=%x result=%d \n",IOCTL_SLBUSB,result); if (ENABLE_ALARM) alarm(0); if (result) return 0; else return TRUE ; } //--------------------------------------- int DeviceIoControl_0 (int* USBDeviceHandle, int IOCTL_SLBUSB, void *Control, int sizeControl, void *ioBuffer, int sizeBuffer, unsigned long *doneBytes, void *)//dummyNULL) { int result; BULK_IOCTL bulk_ioctl; if ( IOCTL_SLBUSB==(int)IOCTL_SLBUSB_BULK_READ || IOCTL_SLBUSB==(int)IOCTL_SLBUSB_BULK_WRITE) { bulk_ioctl.IOCTL_SLBUSB=IOCTL_SLBUSB; bulk_ioctl.Control=Control; bulk_ioctl.sizeControl=sizeControl; bulk_ioctl.sizeBuffer=sizeBuffer; bulk_ioctl.ioBuffer=ioBuffer; result=ioctl(*USBDeviceHandle,IOCTL_SLBUSB,&bulk_ioctl); *doneBytes=bulk_ioctl.doneBytes; if ( IOCTL_SLBUSB==(int)IOCTL_SLBUSB_BULK_READ && (((unsigned long)sizeBuffer)<*doneBytes)) { printf("******* ERROR DeviceIoControl:: sizeBuffer=%d < doneBytes=%ld \n",sizeBuffer,*doneBytes); return 0; } } else result=ioctl(*USBDeviceHandle,IOCTL_SLBUSB,ioBuffer); //printf("---> IOCTL=%x result=%d \n",IOCTL_SLBUSB,result); if (result) return 0; else return TRUE ; } #endif