From b447a2728d03dff956db206cc67ac9af10de5616 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 27 Oct 2019 03:58:15 +0000 Subject: [PATCH] Add functions for device commands for win32. --- ata.c | 38 ++++++++++++++++ build.sh | 0 device.c | 10 +++++ ieee1394.c | 4 ++ pcmcia.c | 4 ++ scsi.c | 5 +++ sdhci.c | 16 +++++++ usb.c | 4 ++ win32/CMakeLists.txt | 2 +- win32/ata.c | 79 ++++++++++++++++++++++++++++++++++ win32/device.c | 92 +++++++++++++++++++++++++++++++++++++++ win32/ieee1394.c | 35 +++++++++++++++ win32/pcmcia.c | 30 +++++++++++++ win32/scsi.c | 41 ++++++++++++++++++ win32/sdhci.c | 42 ++++++++++++++++++ win32/usb.c | 37 ++++++++++++++++ win32/win32.h | 100 +++++++++++++++++++++++++++++++++++++++++++ 17 files changed, 538 insertions(+), 1 deletion(-) mode change 100755 => 100644 build.sh create mode 100644 win32/ata.c create mode 100644 win32/device.c create mode 100644 win32/ieee1394.c create mode 100644 win32/pcmcia.c create mode 100644 win32/scsi.c create mode 100644 win32/sdhci.c create mode 100644 win32/usb.c diff --git a/ata.c b/ata.c index 961dcd3..fd0795f 100644 --- a/ata.c +++ b/ata.c @@ -19,6 +19,8 @@ #if defined(__linux__) && !defined(__ANDROID__) #include "linux/linux.h" +#elif defined(WIN32) +#include "win32/win32.h" #endif int32_t SendAtaChsCommand(void* device_ctx, @@ -45,6 +47,18 @@ int32_t SendAtaChsCommand(void* device_ctx, duration, sense, buf_len); +#elif defined(WIN32) + return Win32SendAtaChsCommand(device_ctx, + registers, + error_registers, + protocol, + transfer_register, + buffer, + timeout, + transfer_blocks, + duration, + sense, + buf_len); #else return -1; #endif @@ -74,6 +88,18 @@ int32_t SendAtaLba28Command(void* device_ctx, duration, sense, buf_len); +#elif defined(WIN32) + return Win32SendAtaLba28Command(device_ctx, + registers, + error_registers, + protocol, + transfer_register, + buffer, + timeout, + transfer_blocks, + duration, + sense, + buf_len); #else return -1; #endif @@ -103,6 +129,18 @@ int32_t SendAtaLba48Command(void* device_ctx, duration, sense, buf_len); +#elif defined(WIN32) + return Win32SendAtaLba48Command(device_ctx, + registers, + error_registers, + protocol, + transfer_register, + buffer, + timeout, + transfer_blocks, + duration, + sense, + buf_len); #else return -1; #endif diff --git a/build.sh b/build.sh old mode 100755 new mode 100644 diff --git a/device.c b/device.c index c22e75e..8a0e495 100644 --- a/device.c +++ b/device.c @@ -17,6 +17,8 @@ #if defined(__linux__) && !defined(__ANDROID__) #include "linux/linux.h" +#elif defined(WIN32) +#include "win32/win32.h" #endif #include "dicmote.h" @@ -27,6 +29,8 @@ void* DeviceOpen(const char* device_path) { #if defined(__linux__) && !defined(__ANDROID__) return LinuxOpenDevice(device_path); +#elif defined(WIN32) + return Win32OpenDevice(device_path); #else return NULL; #endif @@ -36,6 +40,8 @@ void DeviceClose(void* device_ctx) { #if defined(__linux__) && !defined(__ANDROID__) return LinuxCloseDevice(device_ctx); +#elif defined(WIN32) + return Win32CloseDevice(device_ctx); #endif } @@ -43,6 +49,8 @@ int32_t GetDeviceType(void* device_ctx) { #if defined(__linux__) && !defined(__ANDROID__) return LinuxGetDeviceType(device_ctx); +#elif defined(WIN32) + return Win32GetDeviceType(device_ctx); #else return DICMOTE_DEVICE_TYPE_UNKNOWN; #endif @@ -60,6 +68,8 @@ int32_t GetSdhciRegisters(void* device_ctx, { #if defined(__linux__) && !defined(__ANDROID__) return LinuxGetSdhciRegisters(device_ctx, csd, cid, ocr, scr, csd_len, cid_len, ocr_len, scr_len); +#elif defined(WIN32) + return Win32GetSdhciRegisters(device_ctx, csd, cid, ocr, scr, csd_len, cid_len, ocr_len, scr_len); #else return 0; #endif diff --git a/ieee1394.c b/ieee1394.c index fd7f60a..671097c 100644 --- a/ieee1394.c +++ b/ieee1394.c @@ -19,6 +19,8 @@ #if defined(__linux__) && !defined(__ANDROID__) #include "linux/linux.h" +#elif defined(WIN32) +#include "win32/win32.h" #endif uint8_t GetFireWireData(void* device_ctx, @@ -30,6 +32,8 @@ uint8_t GetFireWireData(void* device_ctx, { #if defined(__linux__) && !defined(__ANDROID__) return LinuxGetIeee1394Data(device_ctx, id_model, id_vendor, guid, vendor, model); +#elif defined(WIN32) + return Win32GetIeee1394Data(device_ctx, id_model, id_vendor, guid, vendor, model); #else return 0; #endif diff --git a/pcmcia.c b/pcmcia.c index fe2e579..5e7da55 100644 --- a/pcmcia.c +++ b/pcmcia.c @@ -19,12 +19,16 @@ #if defined(__linux__) && !defined(__ANDROID__) #include "linux/linux.h" +#elif defined(WIN32) +#include "win32/win32.h" #endif uint8_t GetPcmciaData(void* device_ctx, uint16_t* cis_len, char* cis) { #if defined(__linux__) && !defined(__ANDROID__) return LinuxGetPcmciaData(device_ctx, cis_len, cis); +#elif defined(WIN32) + return Win32GetPcmciaData(device_ctx, cis_len, cis); #else return 0; #endif diff --git a/scsi.c b/scsi.c index 5a00ba8..91656f5 100644 --- a/scsi.c +++ b/scsi.c @@ -17,6 +17,8 @@ #if defined(__linux__) && !defined(__ANDROID__) #include "linux/linux.h" +#elif defined(WIN32) +#include "win32/win32.h" #endif #include @@ -36,6 +38,9 @@ int32_t SendScsiCommand(void* device_ctx, #if defined(__linux__) && !defined(__ANDROID__) return LinuxSendScsiCommand( device_ctx, cdb, buffer, sense_buffer, timeout, direction, duration, sense, cdb_len, buf_len, sense_len); +#elif defined(WIN32) + return Win32SendScsiCommand( + device_ctx, cdb, buffer, sense_buffer, timeout, direction, duration, sense, cdb_len, buf_len, sense_len); #else return -1; #endif diff --git a/sdhci.c b/sdhci.c index ce1457c..ff662b9 100644 --- a/sdhci.c +++ b/sdhci.c @@ -17,6 +17,8 @@ #if defined(__linux__) && !defined(__ANDROID__) #include "linux/linux.h" +#elif defined(WIN32) +#include "win32/win32.h" #endif #include @@ -50,6 +52,20 @@ int32_t SendSdhciCommand(void* device_ctx, response, duration, sense); +#elif defined(WIN32) + return Win32SendSdhciCommand(device_ctx, + command, + write, + application, + flags, + argument, + block_size, + blocks, + buffer, + timeout, + response, + duration, + sense); #else return -1; #endif diff --git a/usb.c b/usb.c index 767196e..995d110 100644 --- a/usb.c +++ b/usb.c @@ -19,6 +19,8 @@ #if defined(__linux__) && !defined(__ANDROID__) #include "linux/linux.h" +#elif defined(WIN32) +#include "win32/win32.h" #endif uint8_t GetUsbData(void* device_ctx, @@ -32,6 +34,8 @@ uint8_t GetUsbData(void* device_ctx, { #if defined(__linux__) && !defined(__ANDROID__) return LinuxGetUsbData(device_ctx, desc_len, descriptors, id_vendor, id_product, manufacturer, product, serial); +#elif defined(WIN32) + return Win32GetUsbData(device_ctx, desc_len, descriptors, id_vendor, id_product, manufacturer, product, serial); #else return 0; #endif diff --git a/win32/CMakeLists.txt b/win32/CMakeLists.txt index 472c116..5365bf7 100644 --- a/win32/CMakeLists.txt +++ b/win32/CMakeLists.txt @@ -4,7 +4,7 @@ if (NOT "${CMAKE_SYSTEM}" MATCHES "Windows") return() endif () -set(PLATFORM_SOURCES "win32.h" network.c hello.c "win32.c" list_devices.c) +set(PLATFORM_SOURCES "win32.h" network.c hello.c "win32.c" list_devices.c ata.c device.c ieee1394.c pcmcia.c scsi.c sdhci.c usb.c) add_executable(dicremote ${PLATFORM_SOURCES}) diff --git a/win32/ata.c b/win32/ata.c new file mode 100644 index 0000000..a44e274 --- /dev/null +++ b/win32/ata.c @@ -0,0 +1,79 @@ +/* + * This file is part of the DiscImageChef Remote Server. + * Copyright (c) 2019 Natalia Portillo. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "../dicmote.h" +#include "win32.h" + +int32_t Win32SendAtaChsCommand(void* device_ctx, + AtaRegistersChs registers, + AtaErrorRegistersChs* error_registers, + uint8_t protocol, + uint8_t transfer_register, + char* buffer, + uint32_t timeout, + uint8_t transfer_blocks, + uint32_t* duration, + uint32_t* sense, + uint32_t* buf_len) +{ + Win32DeviceContext* ctx = device_ctx; + + if(!ctx) return -1; + + // TODO: Implement + return -1; +} + +int32_t Win32SendAtaLba28Command(void* device_ctx, + AtaRegistersLba28 registers, + AtaErrorRegistersLba28* error_registers, + uint8_t protocol, + uint8_t transfer_register, + char* buffer, + uint32_t timeout, + uint8_t transfer_blocks, + uint32_t* duration, + uint32_t* sense, + uint32_t* buf_len) +{ + Win32DeviceContext* ctx = device_ctx; + + if(!ctx) return -1; + + // TODO: Implement + return -1; +} + +int32_t Win32SendAtaLba48Command(void* device_ctx, + AtaRegistersLba48 registers, + AtaErrorRegistersLba48* error_registers, + uint8_t protocol, + uint8_t transfer_register, + char* buffer, + uint32_t timeout, + uint8_t transfer_blocks, + uint32_t* duration, + uint32_t* sense, + uint32_t* buf_len) +{ + Win32DeviceContext* ctx = device_ctx; + + if(!ctx) return -1; + + // TODO: Implement + return -1; +} \ No newline at end of file diff --git a/win32/device.c b/win32/device.c new file mode 100644 index 0000000..5e2b6bc --- /dev/null +++ b/win32/device.c @@ -0,0 +1,92 @@ +/* + * This file is part of the DiscImageChef Remote Server. + * Copyright (c) 2019 Natalia Portillo. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "../dicmote.h" +#include "win32.h" + +#include +#include +#include +#include + +void* Win32OpenDevice(const char* device_path) +{ + Win32DeviceContext* ctx; + + ctx = malloc(sizeof(Win32DeviceContext)); + + if(!ctx) return NULL; + + memset(ctx, 0, sizeof(Win32DeviceContext)); + + ctx->handle = CreateFile(device_path, + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if(ctx->handle == INVALID_HANDLE_VALUE) + { + free(ctx); + return NULL; + } + + strncpy(ctx->device_path, device_path, 4096); + + return ctx; +} + +void Win32CloseDevice(void* device_ctx) +{ + Win32DeviceContext* ctx = device_ctx; + + if(!ctx) return; + + CloseHandle(ctx->handle); + + free(ctx); +} + +int32_t Win32GetDeviceType(void* device_ctx) +{ + Win32DeviceContext* ctx = device_ctx; + + if(!ctx) return -1; + + // TODO: Implement + return DICMOTE_DEVICE_TYPE_UNKNOWN; +} + +int32_t Win32GetSdhciRegisters(void* device_ctx, + char** csd, + char** cid, + char** ocr, + char** scr, + uint32_t* csd_len, + uint32_t* cid_len, + uint32_t* ocr_len, + uint32_t* scr_len) +{ + Win32DeviceContext* ctx = device_ctx; + + if(!ctx) return -1; + + // TODO: Implement + return -1; +} \ No newline at end of file diff --git a/win32/ieee1394.c b/win32/ieee1394.c new file mode 100644 index 0000000..4bb3420 --- /dev/null +++ b/win32/ieee1394.c @@ -0,0 +1,35 @@ +/* + * This file is part of the DiscImageChef Remote Server. + * Copyright (c) 2019 Natalia Portillo. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "win32.h" + +#include + +uint8_t Win32GetIeee1394Data(void* device_ctx, + uint32_t* id_model, + uint32_t* id_vendor, + uint64_t* guid, + char* vendor, + char* model) +{ + Win32DeviceContext* ctx = device_ctx; + + if(!ctx) return 0; + + // TODO: Implement + return 0; +} diff --git a/win32/pcmcia.c b/win32/pcmcia.c new file mode 100644 index 0000000..ada4273 --- /dev/null +++ b/win32/pcmcia.c @@ -0,0 +1,30 @@ +/* + * This file is part of the DiscImageChef Remote Server. + * Copyright (c) 2019 Natalia Portillo. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "win32.h" + +#include + +uint8_t Win32GetPcmciaData(void* device_ctx, uint16_t* cis_len, char* cis) +{ + Win32DeviceContext* ctx = device_ctx; + + if(!ctx) return 0; + + // TODO: Implement + return 0; +} diff --git a/win32/scsi.c b/win32/scsi.c new file mode 100644 index 0000000..68cc0bd --- /dev/null +++ b/win32/scsi.c @@ -0,0 +1,41 @@ +/* + * This file is part of the DiscImageChef Remote Server. + * Copyright (c) 2019 Natalia Portillo. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "../dicmote.h" +#include "win32.h" + +#include + +int32_t Win32SendScsiCommand(void* device_ctx, + char* cdb, + char* buffer, + char** sense_buffer, + uint32_t timeout, + int32_t direction, + uint32_t* duration, + uint32_t* sense, + uint32_t cdb_len, + uint32_t* buf_len, + uint32_t* sense_len) +{ + Win32DeviceContext* ctx = device_ctx; + + if(!ctx) return -1; + + // TODO: Implement + return -1; +} \ No newline at end of file diff --git a/win32/sdhci.c b/win32/sdhci.c new file mode 100644 index 0000000..c98c79e --- /dev/null +++ b/win32/sdhci.c @@ -0,0 +1,42 @@ +/* + * This file is part of the DiscImageChef Remote Server. + * Copyright (c) 2019 Natalia Portillo. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "win32.h" + +#include + +int32_t Win32SendSdhciCommand(void* device_ctx, + uint8_t command, + uint8_t write, + uint8_t application, + uint32_t flags, + uint32_t argument, + uint32_t block_size, + uint32_t blocks, + char* buffer, + uint32_t timeout, + uint32_t* response, + uint32_t* duration, + uint32_t* sense) +{ + Win32DeviceContext* ctx = device_ctx; + + if(!ctx) return -1; + + // TODO: Implement + return -1; +} \ No newline at end of file diff --git a/win32/usb.c b/win32/usb.c new file mode 100644 index 0000000..2d95829 --- /dev/null +++ b/win32/usb.c @@ -0,0 +1,37 @@ +/* + * This file is part of the DiscImageChef Remote Server. + * Copyright (c) 2019 Natalia Portillo. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "win32.h" + +#include + +uint8_t Win32GetUsbData(void* device_ctx, + uint16_t* desc_len, + char* descriptors, + uint16_t* id_vendor, + uint16_t* id_product, + char* manufacturer, + char* product, + char* serial) +{ + Win32DeviceContext* ctx = device_ctx; + + if(!ctx) return -1; + + // TODO: Implement + return -1; +} diff --git a/win32/win32.h b/win32/win32.h index 766dce4..253d59b 100644 --- a/win32/win32.h +++ b/win32/win32.h @@ -38,6 +38,106 @@ typedef struct SOCKET socket; } Win32NetworkContext; +typedef struct +{ + HANDLE handle; + char device_path[4096]; +} Win32DeviceContext; + DeviceInfoList* Win32ListDevices(); +void* Win32OpenDevice(const char* device_path); +void Win32CloseDevice(void* device_ctx); + +int32_t Win32GetDeviceType(void* device_ctx); + +int32_t Win32SendScsiCommand(void* device_ctx, + char* cdb, + char* buffer, + char** sense_buffer, + uint32_t timeout, + int32_t direction, + uint32_t* duration, + uint32_t* sense, + uint32_t cdb_len, + uint32_t* buf_len, + uint32_t* sense_len); + +int32_t Win32GetSdhciRegisters(void* device_ctx, + char** csd, + char** cid, + char** ocr, + char** scr, + uint32_t* csd_len, + uint32_t* cid_len, + uint32_t* ocr_len, + uint32_t* scr_len); + +uint8_t Win32GetUsbData(void* device_ctx, + uint16_t* desc_len, + char* descriptors, + uint16_t* id_vendor, + uint16_t* id_product, + char* manufacturer, + char* product, + char* serial); + +uint8_t Win32GetIeee1394Data(void* device_ctx, + uint32_t* id_model, + uint32_t* id_vendor, + uint64_t* guid, + char* vendor, + char* model); + +uint8_t Win32GetPcmciaData(void* device_ctx, uint16_t* cis_len, char* cis); + +int32_t Win32SendAtaChsCommand(void* device_ctx, + AtaRegistersChs registers, + AtaErrorRegistersChs* error_registers, + uint8_t protocol, + uint8_t transfer_register, + char* buffer, + uint32_t timeout, + uint8_t transfer_blocks, + uint32_t* duration, + uint32_t* sense, + uint32_t* buf_len); + +int32_t Win32SendAtaLba28Command(void* device_ctx, + AtaRegistersLba28 registers, + AtaErrorRegistersLba28* error_registers, + uint8_t protocol, + uint8_t transfer_register, + char* buffer, + uint32_t timeout, + uint8_t transfer_blocks, + uint32_t* duration, + uint32_t* sense, + uint32_t* buf_len); + +int32_t Win32SendAtaLba48Command(void* device_ctx, + AtaRegistersLba48 registers, + AtaErrorRegistersLba48* error_registers, + uint8_t protocol, + uint8_t transfer_register, + char* buffer, + uint32_t timeout, + uint8_t transfer_blocks, + uint32_t* duration, + uint32_t* sense, + uint32_t* buf_len); + +int32_t Win32SendSdhciCommand(void* device_ctx, + uint8_t command, + uint8_t write, + uint8_t application, + uint32_t flags, + uint32_t argument, + uint32_t block_size, + uint32_t blocks, + char* buffer, + uint32_t timeout, + uint32_t* response, + uint32_t* duration, + uint32_t* sense); #endif // DICREMOTE_WIN32_WIN32_H_