Add functions for device commands for win32.

This commit is contained in:
2019-10-27 03:58:15 +00:00
parent 25c22d0582
commit b447a2728d
17 changed files with 538 additions and 1 deletions

38
ata.c
View File

@@ -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

0
build.sh Executable file → Normal file
View File

View File

@@ -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

View File

@@ -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

View File

@@ -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

5
scsi.c
View File

@@ -17,6 +17,8 @@
#if defined(__linux__) && !defined(__ANDROID__)
#include "linux/linux.h"
#elif defined(WIN32)
#include "win32/win32.h"
#endif
#include <stdint.h>
@@ -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

16
sdhci.c
View File

@@ -17,6 +17,8 @@
#if defined(__linux__) && !defined(__ANDROID__)
#include "linux/linux.h"
#elif defined(WIN32)
#include "win32/win32.h"
#endif
#include <stdint.h>
@@ -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

4
usb.c
View File

@@ -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

View File

@@ -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})

79
win32/ata.c Normal file
View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
#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;
}

92
win32/device.c Normal file
View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
#include "../dicmote.h"
#include "win32.h"
#include <errno.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
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;
}

35
win32/ieee1394.c Normal file
View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
#include "win32.h"
#include <stdint.h>
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;
}

30
win32/pcmcia.c Normal file
View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
#include "win32.h"
#include <stdint.h>
uint8_t Win32GetPcmciaData(void* device_ctx, uint16_t* cis_len, char* cis)
{
Win32DeviceContext* ctx = device_ctx;
if(!ctx) return 0;
// TODO: Implement
return 0;
}

41
win32/scsi.c Normal file
View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
#include "../dicmote.h"
#include "win32.h"
#include <stdint.h>
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;
}

42
win32/sdhci.c Normal file
View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
#include "win32.h"
#include <stdint.h>
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;
}

37
win32/usb.c Normal file
View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
#include "win32.h"
#include <stdint.h>
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;
}

View File

@@ -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_