diff --git a/CMakeLists.txt b/CMakeLists.txt index 0b43e5f..3f82e42 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ include(CheckLibraryExists) include(TestBigEndian) set(CMAKE_C_STANDARD 90) -set(MAIN_SOURCES main.c list_devices.c device.c scsi.c hex2bin.c usb.c ieee1394.c pcmcia.c ata.c sdhci.c worker.c endian.h) +set(MAIN_SOURCES aaruremote.h endian.h hex2bin.c list_devices.c main.c worker.c) add_library(aaruremotecore ${MAIN_SOURCES}) diff --git a/ata.c b/ata.c deleted file mode 100644 index 542c699..0000000 --- a/ata.c +++ /dev/null @@ -1,147 +0,0 @@ -/* - * This file is part of the Aaru Remote Server. - * Copyright (c) 2019-2020 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 "aaruremote.h" - -#if defined(__linux__) && !defined(__ANDROID__) -#include "linux/linux.h" -#elif defined(WIN32) -#include "win32/win32.h" -#endif - -int32_t SendAtaChsCommand(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) -{ -#if defined(__linux__) && !defined(__ANDROID__) - return LinuxSendAtaChsCommand(device_ctx, - registers, - error_registers, - protocol, - transfer_register, - buffer, - timeout, - transfer_blocks, - 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 -} - -int32_t SendAtaLba28Command(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) -{ -#if defined(__linux__) && !defined(__ANDROID__) - return LinuxSendAtaLba28Command(device_ctx, - registers, - error_registers, - protocol, - transfer_register, - buffer, - timeout, - transfer_blocks, - 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 -} - -int32_t SendAtaLba48Command(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) -{ -#if defined(__linux__) && !defined(__ANDROID__) - return LinuxSendAtaLba48Command(device_ctx, - registers, - error_registers, - protocol, - transfer_register, - buffer, - timeout, - transfer_blocks, - 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/device.c b/device.c deleted file mode 100644 index f12419e..0000000 --- a/device.c +++ /dev/null @@ -1,76 +0,0 @@ -/* - * This file is part of the Aaru Remote Server. - * Copyright (c) 2019-2020 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 . - */ - -#if defined(__linux__) && !defined(__ANDROID__) -#include "linux/linux.h" -#elif defined(WIN32) -#include "win32/win32.h" -#endif - -#include "aaruremote.h" - -#include - -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 -} - -void DeviceClose(void* device_ctx) -{ -#if defined(__linux__) && !defined(__ANDROID__) - return LinuxCloseDevice(device_ctx); -#elif defined(WIN32) - return Win32CloseDevice(device_ctx); -#endif -} - -int32_t GetDeviceType(void* device_ctx) -{ -#if defined(__linux__) && !defined(__ANDROID__) - return LinuxGetDeviceType(device_ctx); -#elif defined(WIN32) - return Win32GetDeviceType(device_ctx); -#else - return AARUREMOTE_DEVICE_TYPE_UNKNOWN; -#endif -} - -int32_t GetSdhciRegisters(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) -{ -#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 -} \ No newline at end of file diff --git a/ieee1394.c b/ieee1394.c deleted file mode 100644 index 0ee5f6d..0000000 --- a/ieee1394.c +++ /dev/null @@ -1,40 +0,0 @@ -/* - * This file is part of the Aaru Remote Server. - * Copyright (c) 2019-2020 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 - -#if defined(__linux__) && !defined(__ANDROID__) -#include "linux/linux.h" -#elif defined(WIN32) -#include "win32/win32.h" -#endif - -uint8_t GetFireWireData(void* device_ctx, - uint32_t* id_model, - uint32_t* id_vendor, - uint64_t* guid, - char* vendor, - char* model) -{ -#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 -} \ No newline at end of file diff --git a/linux/ata.c b/linux/ata.c index cf953e5..7135554 100644 --- a/linux/ata.c +++ b/linux/ata.c @@ -37,24 +37,24 @@ int32_t AtaProtocolToScsiDirection(uint8_t protocol) } } -int32_t LinuxSendAtaChsCommand(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 SendAtaChsCommand(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) { *duration = 0; *sense = 0; - unsigned char cdb[16]; - char* sense_buf; - uint32_t sense_len; - LinuxDeviceContext* ctx = device_ctx; + unsigned char cdb[16]; + char* sense_buf; + uint32_t sense_len; + DeviceContext* ctx = device_ctx; if(!ctx) return -1; @@ -84,17 +84,17 @@ int32_t LinuxSendAtaChsCommand(void* device_ctx, cdb[13] = registers.device_head; cdb[14] = registers.command; - int error = LinuxSendScsiCommand(ctx, - (char*)cdb, - buffer, - &sense_buf, - timeout, - AtaProtocolToScsiDirection(protocol), - duration, - sense, - 16, - buf_len, - &sense_len); + int error = SendScsiCommand(ctx, + (char*)cdb, + buffer, + &sense_buf, + timeout, + AtaProtocolToScsiDirection(protocol), + duration, + sense, + 16, + buf_len, + &sense_len); if(sense_len < 22 || (sense_buf[8] != 0x09 && sense_buf[9] != 0x0C)) return error; @@ -112,24 +112,24 @@ int32_t LinuxSendAtaChsCommand(void* device_ctx, return error; } -int32_t LinuxSendAtaLba28Command(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 SendAtaLba28Command(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) { *duration = 0; *sense = 0; - unsigned char cdb[16]; - char* sense_buf; - uint32_t sense_len; - LinuxDeviceContext* ctx = device_ctx; + unsigned char cdb[16]; + char* sense_buf; + uint32_t sense_len; + DeviceContext* ctx = device_ctx; if(!ctx) return -1; @@ -161,17 +161,17 @@ int32_t LinuxSendAtaLba28Command(void* device_ctx, cdb[13] = registers.device_head; cdb[14] = registers.command; - int error = LinuxSendScsiCommand(ctx, - (char*)cdb, - buffer, - &sense_buf, - timeout, - AtaProtocolToScsiDirection(protocol), - duration, - sense, - 16, - buf_len, - &sense_len); + int error = SendScsiCommand(ctx, + (char*)cdb, + buffer, + &sense_buf, + timeout, + AtaProtocolToScsiDirection(protocol), + duration, + sense, + 16, + buf_len, + &sense_len); if(sense_len < 22 || (sense_buf[8] != 0x09 && sense_buf[9] != 0x0C)) return error; @@ -189,24 +189,24 @@ int32_t LinuxSendAtaLba28Command(void* device_ctx, return error; } -int32_t LinuxSendAtaLba48Command(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 SendAtaLba48Command(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) { *duration = 0; *sense = 0; - unsigned char cdb[16]; - char* sense_buf; - uint32_t sense_len; - LinuxDeviceContext* ctx = device_ctx; + unsigned char cdb[16]; + char* sense_buf; + uint32_t sense_len; + DeviceContext* ctx = device_ctx; if(!ctx) return -1; @@ -244,17 +244,17 @@ int32_t LinuxSendAtaLba48Command(void* device_ctx, cdb[13] = registers.device_head; cdb[14] = registers.command; - int error = LinuxSendScsiCommand(ctx, - (char*)cdb, - buffer, - &sense_buf, - timeout, - AtaProtocolToScsiDirection(protocol), - duration, - sense, - 16, - buf_len, - &sense_len); + int error = SendScsiCommand(ctx, + (char*)cdb, + buffer, + &sense_buf, + timeout, + AtaProtocolToScsiDirection(protocol), + duration, + sense, + 16, + buf_len, + &sense_len); if(sense_len < 22 || (sense_buf[8] != 0x09 && sense_buf[9] != 0x0C)) return error; diff --git a/linux/device.c b/linux/device.c index effcc2a..cd0d27a 100644 --- a/linux/device.c +++ b/linux/device.c @@ -28,15 +28,15 @@ #include #endif -void* LinuxOpenDevice(const char* device_path) +void* DeviceOpen(const char* device_path) { - LinuxDeviceContext* ctx; + DeviceContext* ctx; - ctx = malloc(sizeof(LinuxDeviceContext)); + ctx = malloc(sizeof(DeviceContext)); if(!ctx) return NULL; - memset(ctx, 0, sizeof(LinuxDeviceContext)); + memset(ctx, 0, sizeof(DeviceContext)); ctx->fd = open(device_path, O_RDWR | O_NONBLOCK | O_CREAT); @@ -53,9 +53,9 @@ void* LinuxOpenDevice(const char* device_path) return ctx; } -void LinuxCloseDevice(void* device_ctx) +void DeviceClose(void* device_ctx) { - LinuxDeviceContext* ctx = device_ctx; + DeviceContext* ctx = device_ctx; if(!ctx) return; @@ -64,9 +64,9 @@ void LinuxCloseDevice(void* device_ctx) free(ctx); } -int32_t LinuxGetDeviceType(void* device_ctx) +int32_t GetDeviceType(void* device_ctx) { - LinuxDeviceContext* ctx = device_ctx; + DeviceContext* ctx = device_ctx; if(!ctx) return -1; @@ -319,161 +319,3 @@ int32_t LinuxGetDeviceType(void* device_ctx) return dev_type; #endif } - -int32_t LinuxGetSdhciRegisters(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) -{ - LinuxDeviceContext* ctx = device_ctx; - char* tmp_string; - char* sysfs_path_csd; - char* sysfs_path_cid; - char* sysfs_path_scr; - char* sysfs_path_ocr; - size_t len; - FILE* file; - *csd = NULL; - *cid = NULL; - *ocr = NULL; - *scr = NULL; - *csd_len = 0; - *cid_len = 0; - *ocr_len = 0; - *scr_len = 0; - size_t n = 1026; - - if(!ctx) return -1; - - if(strncmp(ctx->device_path, "/dev/mmcblk", 11) != 0) return 0; - - len = strlen(ctx->device_path) + 19; - sysfs_path_csd = malloc(len); - sysfs_path_cid = malloc(len); - sysfs_path_scr = malloc(len); - sysfs_path_ocr = malloc(len); - tmp_string = malloc(1024); - - if(!sysfs_path_csd || !sysfs_path_cid || !sysfs_path_scr || !sysfs_path_ocr || !tmp_string) - { - free(sysfs_path_csd); - free(sysfs_path_cid); - free(sysfs_path_scr); - free(sysfs_path_ocr); - free(tmp_string); - return 0; - } - - memset(sysfs_path_csd, 0, len); - memset(sysfs_path_cid, 0, len); - memset(sysfs_path_scr, 0, len); - memset(sysfs_path_ocr, 0, len); - memset(tmp_string, 0, strlen(ctx->device_path) - 5); - - memcpy(tmp_string, ctx->device_path + 5, strlen(ctx->device_path) - 5); - snprintf(sysfs_path_csd, len, "/sys/block/%s/device/csd", tmp_string); - snprintf(sysfs_path_cid, len, "/sys/block/%s/device/cid", tmp_string); - snprintf(sysfs_path_scr, len, "/sys/block/%s/device/scr", tmp_string); - snprintf(sysfs_path_ocr, len, "/sys/block/%s/device/ocr", tmp_string); - - if(access(sysfs_path_csd, R_OK) == 0) - { - file = fopen(sysfs_path_csd, "r"); - - if(file != NULL) - { - len = getline(&tmp_string, &n, file); - if(len > 0) - { - *csd_len = Hexs2Bin(tmp_string, (unsigned char**)csd); - - if(*csd_len <= 0) - { - *csd_len = 0; - *csd = NULL; - } - } - - fclose(file); - } - } - - if(access(sysfs_path_cid, R_OK) == 0) - { - file = fopen(sysfs_path_cid, "r"); - - if(file != NULL) - { - len = getline(&tmp_string, &n, file); - if(len > 0) - { - *cid_len = Hexs2Bin(tmp_string, (unsigned char**)cid); - - if(*cid_len <= 0) - { - *cid_len = 0; - *cid = NULL; - } - } - - fclose(file); - } - } - - if(access(sysfs_path_scr, R_OK) == 0) - { - file = fopen(sysfs_path_scr, "r"); - - if(file != NULL) - { - len = getline(&tmp_string, &n, file); - if(len > 0) - { - *scr_len = Hexs2Bin(tmp_string, (unsigned char**)scr); - - if(*scr_len <= 0) - { - *scr_len = 0; - *scr = NULL; - } - } - - fclose(file); - } - } - - if(access(sysfs_path_ocr, R_OK) == 0) - { - file = fopen(sysfs_path_ocr, "r"); - - if(file != NULL) - { - len = getline(&tmp_string, &n, file); - if(len > 0) - { - *ocr_len = Hexs2Bin(tmp_string, (unsigned char**)ocr); - - if(*ocr_len <= 0) - { - *ocr_len = 0; - *ocr = NULL; - } - } - - fclose(file); - } - } - - free(sysfs_path_csd); - free(sysfs_path_cid); - free(sysfs_path_scr); - free(sysfs_path_ocr); - free(tmp_string); - - return csd_len != 0 || cid_len != 0 || scr_len != 0 || ocr_len != 0; -} \ No newline at end of file diff --git a/linux/ieee1394.c b/linux/ieee1394.c index 9d4fc54..86e9c09 100644 --- a/linux/ieee1394.c +++ b/linux/ieee1394.c @@ -23,22 +23,22 @@ #include #include -uint8_t LinuxGetIeee1394Data(void* device_ctx, - uint32_t* id_model, - uint32_t* id_vendor, - uint64_t* guid, - char* vendor, - char* model) +uint8_t GetFireWireData(void* device_ctx, + uint32_t* id_model, + uint32_t* id_vendor, + uint64_t* guid, + char* vendor, + char* model) { - LinuxDeviceContext* ctx = device_ctx; - char* dev_path; - char tmp_path[4096]; - char resolved_link[4096]; - struct stat sb; - ssize_t len; - char* rchr; - int found; - FILE* file; + DeviceContext* ctx = device_ctx; + char* dev_path; + char tmp_path[4096]; + char resolved_link[4096]; + struct stat sb; + ssize_t len; + char* rchr; + int found; + FILE* file; if(!ctx) return 0; diff --git a/linux/linux.h b/linux/linux.h index 9047b14..8ae48ae 100644 --- a/linux/linux.h +++ b/linux/linux.h @@ -22,107 +22,10 @@ #define PATH_SYS_DEVBLOCK "/sys/block" -DeviceInfoList* LinuxListDevices(); - -void* LinuxOpenDevice(const char* device_path); -void LinuxCloseDevice(void* device_ctx); - -int32_t LinuxGetDeviceType(void* device_ctx); - -int32_t LinuxSendScsiCommand(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 LinuxGetSdhciRegisters(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 LinuxGetUsbData(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 LinuxGetIeee1394Data(void* device_ctx, - uint32_t* id_model, - uint32_t* id_vendor, - uint64_t* guid, - char* vendor, - char* model); - -uint8_t LinuxGetPcmciaData(void* device_ctx, uint16_t* cis_len, char* cis); - -int32_t LinuxSendAtaChsCommand(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 LinuxSendAtaLba28Command(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 LinuxSendAtaLba48Command(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 LinuxSendSdhciCommand(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); - typedef struct { int fd; char device_path[4096]; -} LinuxDeviceContext; +} DeviceContext; #endif // AARUREMOTE_LINUX_LINUX_H_ diff --git a/linux/list_devices.c b/linux/list_devices.c index b4978c2..0e4ca13 100644 --- a/linux/list_devices.c +++ b/linux/list_devices.c @@ -31,7 +31,7 @@ #include #endif -DeviceInfoList* LinuxListDevices() +DeviceInfoList* ListDevices() { DIR* dir; struct dirent* dirent; diff --git a/linux/pcmcia.c b/linux/pcmcia.c index 9979952..2225e79 100644 --- a/linux/pcmcia.c +++ b/linux/pcmcia.c @@ -24,18 +24,18 @@ #include #include -uint8_t LinuxGetPcmciaData(void* device_ctx, uint16_t* cis_len, char* cis) +uint8_t GetPcmciaData(void* device_ctx, uint16_t* cis_len, char* cis) { - LinuxDeviceContext* ctx = device_ctx; - char* dev_path; - char tmp_path[4096]; - char resolved_link[4096]; - struct stat sb; - ssize_t len; - char* rchr; - FILE* file; - DIR* dir; - struct dirent* dent; + DeviceContext* ctx = device_ctx; + char* dev_path; + char tmp_path[4096]; + char resolved_link[4096]; + struct stat sb; + ssize_t len; + char* rchr; + FILE* file; + DIR* dir; + struct dirent* dent; *cis_len = 0; if(!ctx) return 0; diff --git a/linux/scsi.c b/linux/scsi.c index bd74ce9..a0328b1 100644 --- a/linux/scsi.c +++ b/linux/scsi.c @@ -24,21 +24,21 @@ #include #include -int32_t LinuxSendScsiCommand(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 SendScsiCommand(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) { - LinuxDeviceContext* ctx = device_ctx; - sg_io_hdr_t hdr; - int dir, ret; + DeviceContext* ctx = device_ctx; + sg_io_hdr_t hdr; + int dir, ret; *sense_len = 32; if(!ctx) return -1; diff --git a/linux/sdhci.c b/linux/sdhci.c index c5e2e65..1127718 100644 --- a/linux/sdhci.c +++ b/linux/sdhci.c @@ -20,26 +20,30 @@ #include #include +#include +#include #include #include +#include -int32_t LinuxSendSdhciCommand(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) +int32_t SendSdhciCommand(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 buf_len, + uint32_t timeout, + uint32_t* response, + uint32_t* duration, + uint32_t* sense) { - LinuxDeviceContext* ctx = device_ctx; - struct mmc_ioc_cmd mmc_ioc_cmd; - int32_t error; + DeviceContext* ctx = device_ctx; + struct mmc_ioc_cmd mmc_ioc_cmd; + int32_t error; *duration = 0; *sense = 0; @@ -72,4 +76,162 @@ int32_t LinuxSendSdhciCommand(void* device_ctx, memcpy((char*)response, (char*)&mmc_ioc_cmd.response, sizeof(uint32_t) * 4); return error; +} + +int32_t GetSdhciRegisters(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) +{ + DeviceContext* ctx = device_ctx; + char* tmp_string; + char* sysfs_path_csd; + char* sysfs_path_cid; + char* sysfs_path_scr; + char* sysfs_path_ocr; + size_t len; + FILE* file; + *csd = NULL; + *cid = NULL; + *ocr = NULL; + *scr = NULL; + *csd_len = 0; + *cid_len = 0; + *ocr_len = 0; + *scr_len = 0; + size_t n = 1026; + + if(!ctx) return -1; + + if(strncmp(ctx->device_path, "/dev/mmcblk", 11) != 0) return 0; + + len = strlen(ctx->device_path) + 19; + sysfs_path_csd = malloc(len); + sysfs_path_cid = malloc(len); + sysfs_path_scr = malloc(len); + sysfs_path_ocr = malloc(len); + tmp_string = malloc(1024); + + if(!sysfs_path_csd || !sysfs_path_cid || !sysfs_path_scr || !sysfs_path_ocr || !tmp_string) + { + free(sysfs_path_csd); + free(sysfs_path_cid); + free(sysfs_path_scr); + free(sysfs_path_ocr); + free(tmp_string); + return 0; + } + + memset(sysfs_path_csd, 0, len); + memset(sysfs_path_cid, 0, len); + memset(sysfs_path_scr, 0, len); + memset(sysfs_path_ocr, 0, len); + memset(tmp_string, 0, strlen(ctx->device_path) - 5); + + memcpy(tmp_string, ctx->device_path + 5, strlen(ctx->device_path) - 5); + snprintf(sysfs_path_csd, len, "/sys/block/%s/device/csd", tmp_string); + snprintf(sysfs_path_cid, len, "/sys/block/%s/device/cid", tmp_string); + snprintf(sysfs_path_scr, len, "/sys/block/%s/device/scr", tmp_string); + snprintf(sysfs_path_ocr, len, "/sys/block/%s/device/ocr", tmp_string); + + if(access(sysfs_path_csd, R_OK) == 0) + { + file = fopen(sysfs_path_csd, "r"); + + if(file != NULL) + { + len = getline(&tmp_string, &n, file); + if(len > 0) + { + *csd_len = Hexs2Bin(tmp_string, (unsigned char**)csd); + + if(*csd_len <= 0) + { + *csd_len = 0; + *csd = NULL; + } + } + + fclose(file); + } + } + + if(access(sysfs_path_cid, R_OK) == 0) + { + file = fopen(sysfs_path_cid, "r"); + + if(file != NULL) + { + len = getline(&tmp_string, &n, file); + if(len > 0) + { + *cid_len = Hexs2Bin(tmp_string, (unsigned char**)cid); + + if(*cid_len <= 0) + { + *cid_len = 0; + *cid = NULL; + } + } + + fclose(file); + } + } + + if(access(sysfs_path_scr, R_OK) == 0) + { + file = fopen(sysfs_path_scr, "r"); + + if(file != NULL) + { + len = getline(&tmp_string, &n, file); + if(len > 0) + { + *scr_len = Hexs2Bin(tmp_string, (unsigned char**)scr); + + if(*scr_len <= 0) + { + *scr_len = 0; + *scr = NULL; + } + } + + fclose(file); + } + } + + if(access(sysfs_path_ocr, R_OK) == 0) + { + file = fopen(sysfs_path_ocr, "r"); + + if(file != NULL) + { + len = getline(&tmp_string, &n, file); + if(len > 0) + { + *ocr_len = Hexs2Bin(tmp_string, (unsigned char**)ocr); + + if(*ocr_len <= 0) + { + *ocr_len = 0; + *ocr = NULL; + } + } + + fclose(file); + } + } + + free(sysfs_path_csd); + free(sysfs_path_cid); + free(sysfs_path_scr); + free(sysfs_path_ocr); + free(tmp_string); + + return csd_len != 0 || cid_len != 0 || scr_len != 0 || ocr_len != 0; } \ No newline at end of file diff --git a/linux/usb.c b/linux/usb.c index 4faa9cb..f49177f 100644 --- a/linux/usb.c +++ b/linux/usb.c @@ -23,24 +23,24 @@ #include #include -uint8_t LinuxGetUsbData(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 GetUsbData(void* device_ctx, + uint16_t* desc_len, + char* descriptors, + uint16_t* id_vendor, + uint16_t* id_product, + char* manufacturer, + char* product, + char* serial) { - LinuxDeviceContext* ctx = device_ctx; - char* dev_path; - char tmp_path[4096]; - char resolved_link[4096]; - struct stat sb; - ssize_t len; - char* rchr; - int found = 1; - FILE* file; + DeviceContext* ctx = device_ctx; + char* dev_path; + char tmp_path[4096]; + char resolved_link[4096]; + struct stat sb; + ssize_t len; + char* rchr; + int found = 1; + FILE* file; if(!ctx) return -1; diff --git a/list_devices.c b/list_devices.c index 1137176..b04b705 100644 --- a/list_devices.c +++ b/list_devices.c @@ -17,29 +17,8 @@ #include "aaruremote.h" -#if defined(__linux__) && !defined(__ANDROID__) -#include "linux/linux.h" -#elif defined(GEKKO) -#include "wii/wii.h" -#elif defined(WIN32) -#include "win32/win32.h" -#endif - #include -DeviceInfoList* ListDevices() -{ -#if defined(__linux__) && !defined(__ANDROID__) - return LinuxListDevices(); -#elif defined(GEKKO) - return WiiListDevices(); -#elif defined(WIN32) - return Win32ListDevices(); -#else - return NULL; -#endif -} - void FreeDeviceInfoList(DeviceInfoList* start) { DeviceInfoList* current; diff --git a/pcmcia.c b/pcmcia.c deleted file mode 100644 index 9c9fbe8..0000000 --- a/pcmcia.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - * This file is part of the Aaru Remote Server. - * Copyright (c) 2019-2020 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 - -#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 -} \ No newline at end of file diff --git a/scsi.c b/scsi.c deleted file mode 100644 index 42472e1..0000000 --- a/scsi.c +++ /dev/null @@ -1,47 +0,0 @@ -/* - * This file is part of the Aaru Remote Server. - * Copyright (c) 2019-2020 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 . - */ - -#if defined(__linux__) && !defined(__ANDROID__) -#include "linux/linux.h" -#elif defined(WIN32) -#include "win32/win32.h" -#endif - -#include - -int32_t SendScsiCommand(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) -{ -#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 -} \ No newline at end of file diff --git a/sdhci.c b/sdhci.c deleted file mode 100644 index 066da64..0000000 --- a/sdhci.c +++ /dev/null @@ -1,72 +0,0 @@ -/* - * This file is part of the Aaru Remote Server. - * Copyright (c) 2019-2020 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 . - */ - -#if defined(__linux__) && !defined(__ANDROID__) -#include "linux/linux.h" -#elif defined(WIN32) -#include "win32/win32.h" -#endif - -#include - -int32_t SendSdhciCommand(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 buf_len, - uint32_t timeout, - uint32_t* response, - uint32_t* duration, - uint32_t* sense) -{ -#if defined(__linux__) && !defined(__ANDROID__) - return LinuxSendSdhciCommand(device_ctx, - command, - write, - application, - flags, - argument, - block_size, - blocks, - buffer, - timeout, - 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 -} \ No newline at end of file diff --git a/unix/network.c b/unix/network.c index 5c57b74..9df63ca 100644 --- a/unix/network.c +++ b/unix/network.c @@ -59,9 +59,9 @@ char* PrintIpv4Address(struct in_addr addr) { return inet_ntoa(addr); } void* NetSocket(uint32_t domain, uint32_t type, uint32_t protocol) { - UnixNetworkContext* ctx; + NetworkContext* ctx; - ctx = malloc(sizeof(UnixNetworkContext)); + ctx = malloc(sizeof(NetworkContext)); if(!ctx) return NULL; @@ -78,7 +78,7 @@ void* NetSocket(uint32_t domain, uint32_t type, uint32_t protocol) int32_t NetBind(void* net_ctx, struct sockaddr* addr, socklen_t addrlen) { - UnixNetworkContext* ctx = net_ctx; + NetworkContext* ctx = net_ctx; if(!ctx) return -1; @@ -87,7 +87,7 @@ int32_t NetBind(void* net_ctx, struct sockaddr* addr, socklen_t addrlen) int32_t NetListen(void* net_ctx, uint32_t backlog) { - UnixNetworkContext* ctx = net_ctx; + NetworkContext* ctx = net_ctx; if(!ctx) return -1; @@ -96,12 +96,12 @@ int32_t NetListen(void* net_ctx, uint32_t backlog) void* NetAccept(void* net_ctx, struct sockaddr* addr, socklen_t* addrlen) { - UnixNetworkContext* ctx = net_ctx; - UnixNetworkContext* cli_ctx; + NetworkContext* ctx = net_ctx; + NetworkContext* cli_ctx; if(!ctx) return NULL; - cli_ctx = malloc(sizeof(UnixNetworkContext)); + cli_ctx = malloc(sizeof(NetworkContext)); if(!cli_ctx) return NULL; @@ -118,7 +118,7 @@ void* NetAccept(void* net_ctx, struct sockaddr* addr, socklen_t* addrlen) int32_t NetRecv(void* net_ctx, void* buf, int32_t len, uint32_t flags) { - UnixNetworkContext* ctx = net_ctx; + NetworkContext* ctx = net_ctx; if(!ctx) return -1; @@ -141,7 +141,7 @@ int32_t NetRecv(void* net_ctx, void* buf, int32_t len, uint32_t flags) int32_t NetWrite(void* net_ctx, const void* buf, int32_t size) { - UnixNetworkContext* ctx = net_ctx; + NetworkContext* ctx = net_ctx; if(!ctx) return -1; @@ -150,8 +150,8 @@ int32_t NetWrite(void* net_ctx, const void* buf, int32_t size) int32_t NetClose(void* net_ctx) { - int ret; - UnixNetworkContext* ctx = net_ctx; + int ret; + NetworkContext* ctx = net_ctx; if(!ctx) return -1; diff --git a/unix/unix.h b/unix/unix.h index 780d4d3..b80667e 100644 --- a/unix/unix.h +++ b/unix/unix.h @@ -21,6 +21,6 @@ typedef struct { int fd; -} UnixNetworkContext; +} NetworkContext; #endif // AARUREMOTE_UNIX_UNIX_H_ diff --git a/usb.c b/usb.c deleted file mode 100644 index 6c24a66..0000000 --- a/usb.c +++ /dev/null @@ -1,42 +0,0 @@ -/* - * This file is part of the Aaru Remote Server. - * Copyright (c) 2019-2020 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 - -#if defined(__linux__) && !defined(__ANDROID__) -#include "linux/linux.h" -#elif defined(WIN32) -#include "win32/win32.h" -#endif - -uint8_t GetUsbData(void* device_ctx, - uint16_t* desc_len, - char* descriptors, - uint16_t* id_vendor, - uint16_t* id_product, - char* manufacturer, - char* product, - char* serial) -{ -#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/wii/CMakeLists.txt b/wii/CMakeLists.txt index b072dc7..9a9b42e 100644 --- a/wii/CMakeLists.txt +++ b/wii/CMakeLists.txt @@ -4,7 +4,7 @@ if (NOT WII) return() endif () -set(PLATFORM_SOURCES wii.c hello.c network.c wii.h list_devices.c) +set(PLATFORM_SOURCES wii.c hello.c network.c wii.h list_devices.c unsupported.c unimplemented.c) add_executable(aaruremote-wii ${PLATFORM_SOURCES}) set_target_properties(aaruremote-wii PROPERTIES LINK_FLAGS -L$ENV{DEVKITPRO}/libogc/lib/wii/) diff --git a/wii/list_devices.c b/wii/list_devices.c index 497b874..423f50c 100644 --- a/wii/list_devices.c +++ b/wii/list_devices.c @@ -25,7 +25,7 @@ #include #include -DeviceInfoList* WiiListDevices() +DeviceInfoList* ListDevices() { DeviceInfoList *list_start = NULL, *list_current = NULL, *list_next = NULL; u32 deviceId = 0; diff --git a/wii/network.c b/wii/network.c index 64f5878..9d092cb 100644 --- a/wii/network.c +++ b/wii/network.c @@ -42,9 +42,9 @@ int PrintNetworkAddresses() char* PrintIpv4Address(struct in_addr addr) { return inet_ntoa(addr); } void* NetSocket(uint32_t domain, uint32_t type, uint32_t protocol) { - WiiNetworkContext* ctx; + NetworkContext* ctx; - ctx = malloc(sizeof(WiiNetworkContext)); + ctx = malloc(sizeof(NetworkContext)); if(!ctx) return NULL; @@ -61,7 +61,7 @@ void* NetSocket(uint32_t domain, uint32_t type, uint32_t protocol) int32_t NetBind(void* net_ctx, struct sockaddr* addr, socklen_t addrlen) { - WiiNetworkContext* ctx = net_ctx; + NetworkContext* ctx = net_ctx; if(!ctx) return -1; @@ -70,7 +70,7 @@ int32_t NetBind(void* net_ctx, struct sockaddr* addr, socklen_t addrlen) int32_t NetListen(void* net_ctx, uint32_t backlog) { - WiiNetworkContext* ctx = net_ctx; + NetworkContext* ctx = net_ctx; if(!ctx) return -1; @@ -79,12 +79,12 @@ int32_t NetListen(void* net_ctx, uint32_t backlog) void* NetAccept(void* net_ctx, struct sockaddr* addr, socklen_t* addrlen) { - WiiNetworkContext* ctx = net_ctx; - WiiNetworkContext* cli_ctx; + NetworkContext* ctx = net_ctx; + NetworkContext* cli_ctx; if(!ctx) return NULL; - cli_ctx = malloc(sizeof(WiiNetworkContext)); + cli_ctx = malloc(sizeof(NetworkContext)); if(!cli_ctx) return NULL; @@ -101,7 +101,7 @@ void* NetAccept(void* net_ctx, struct sockaddr* addr, socklen_t* addrlen) int32_t NetRecv(void* net_ctx, void* buf, int32_t len, uint32_t flags) { - WiiNetworkContext* ctx = net_ctx; + NetworkContext* ctx = net_ctx; if(!ctx) return -1; @@ -124,7 +124,7 @@ int32_t NetRecv(void* net_ctx, void* buf, int32_t len, uint32_t flags) int32_t NetWrite(void* net_ctx, const void* buf, int32_t size) { - WiiNetworkContext* ctx = net_ctx; + NetworkContext* ctx = net_ctx; if(!ctx) return -1; @@ -133,8 +133,8 @@ int32_t NetWrite(void* net_ctx, const void* buf, int32_t size) int32_t NetClose(void* net_ctx) { - int ret; - WiiNetworkContext* ctx = net_ctx; + int ret; + NetworkContext* ctx = net_ctx; if(!ctx) return -1; diff --git a/wii/unimplemented.c b/wii/unimplemented.c new file mode 100644 index 0000000..944a9a5 --- /dev/null +++ b/wii/unimplemented.c @@ -0,0 +1,57 @@ +/* + * This file is part of the Aaru Remote Server. + * Copyright (c) 2019-2020 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 "../aaruremote.h" + +// TODO + +void* DeviceOpen(const char* device_path) { return NULL; } + +void DeviceClose(void* device_ctx) {} + +int32_t GetDeviceType(void* device_ctx) { return AARUREMOTE_DEVICE_TYPE_UNKNOWN; } + +int32_t GetSdhciRegisters(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) +{ + return 0; +} + +int32_t SendSdhciCommand(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 buf_len, + uint32_t timeout, + uint32_t* response, + uint32_t* duration, + uint32_t* sense) +{ + return -1; +} \ No newline at end of file diff --git a/wii/unsupported.c b/wii/unsupported.c new file mode 100644 index 0000000..35f1a78 --- /dev/null +++ b/wii/unsupported.c @@ -0,0 +1,102 @@ +/* + * This file is part of the Aaru Remote Server. + * Copyright (c) 2019-2020 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 "../aaruremote.h" + +int32_t SendAtaChsCommand(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) +{ + return -1; +} + +int32_t SendAtaLba28Command(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) +{ + return -1; +} + +int32_t SendAtaLba48Command(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) +{ + return -1; +} + +uint8_t GetFireWireData(void* device_ctx, + uint32_t* id_model, + uint32_t* id_vendor, + uint64_t* guid, + char* vendor, + char* model) +{ + return 0; +} + +uint8_t GetPcmciaData(void* device_ctx, uint16_t* cis_len, char* cis) { return 0; } + +int32_t SendScsiCommand(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) +{ + return -1; +} + +uint8_t GetUsbData(void* device_ctx, + uint16_t* desc_len, + char* descriptors, + uint16_t* id_vendor, + uint16_t* id_product, + char* manufacturer, + char* product, + char* serial) +{ + return 0; +} diff --git a/wii/wii.h b/wii/wii.h index 0d35f54..20396d3 100644 --- a/wii/wii.h +++ b/wii/wii.h @@ -39,13 +39,11 @@ typedef struct { s32 ios_fd; s32 dev_type; -} WiiDeviceContext; +} DeviceContext; typedef struct { s32 fd; -} WiiNetworkContext; - -DeviceInfoList* WiiListDevices(); +} NetworkContext; #endif // AARUREMOTE_WII_WII_H_ diff --git a/win32/ata.c b/win32/ata.c deleted file mode 100644 index 3f7ab75..0000000 --- a/win32/ata.c +++ /dev/null @@ -1,361 +0,0 @@ -/* - * This file is part of the Aaru Remote Server. - * Copyright (c) 2019-2020 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 "../aaruremote.h" -#include "ntioctl.h" -#include "win32.h" - -#include -#include - -// TODO: Check if we can live without copying buffer in and out -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; - PATA_PASS_THROUGH_EX apte; - PVOID apte_and_buffer; - ULONG_PTR offsetForBuffer; - PCHAR data_buffer; - DWORD k = 0; - DWORD error = 0; - LARGE_INTEGER frequency; - LARGE_INTEGER start; - LARGE_INTEGER end; - DOUBLE interval; - DWORD apte_and_buffer_len; - - *duration = 0; - *sense = FALSE; - offsetForBuffer = sizeof(ATA_PASS_THROUGH_EX) + sizeof(uint32_t); - apte_and_buffer_len = sizeof(ATA_PASS_THROUGH_EX) + sizeof(uint32_t) + 64 * 512; - - if(!ctx) return -1; - if(!buffer) return -1; - if(*buf_len > 64 * 512) return -1; - - apte_and_buffer = malloc(apte_and_buffer_len); - - if(!apte_and_buffer) return -1; - - memset(apte_and_buffer, 0, apte_and_buffer_len); - data_buffer = (PCHAR)apte_and_buffer + offsetForBuffer; - apte = (PATA_PASS_THROUGH_EX)apte_and_buffer; - - apte->TimeOutValue = timeout; - apte->DataBufferOffset = offsetForBuffer; - apte->Length = sizeof(ATA_PASS_THROUGH_EX); - apte->CurrentTaskFile[0] = registers.feature; - apte->CurrentTaskFile[1] = registers.sector_count; - apte->CurrentTaskFile[2] = registers.sector; - apte->CurrentTaskFile[3] = registers.cylinder_low; - apte->CurrentTaskFile[4] = registers.cylinder_high; - apte->CurrentTaskFile[5] = registers.device_head; - apte->CurrentTaskFile[6] = registers.command; - - switch(protocol) - { - case AARUREMOTE_ATA_PROTOCOL_PIO_IN: - case AARUREMOTE_ATA_PROTOCOL_UDMA_IN: - case AARUREMOTE_ATA_PROTOCOL_DMA: apte->AtaFlags = ATA_FLAGS_DATA_IN; break; - case AARUREMOTE_ATA_PROTOCOL_PIO_OUT: - case AARUREMOTE_ATA_PROTOCOL_UDMA_OUT: apte->AtaFlags = ATA_FLAGS_DATA_OUT; break; - } - - switch(protocol) - { - case AARUREMOTE_ATA_PROTOCOL_DMA: - case AARUREMOTE_ATA_PROTOCOL_DMA_QUEUED: - case AARUREMOTE_ATA_PROTOCOL_FPDMA: - case AARUREMOTE_ATA_PROTOCOL_UDMA_IN: - case AARUREMOTE_ATA_PROTOCOL_UDMA_OUT: apte->AtaFlags |= ATA_FLAGS_USE_DMA; break; - } - - // Unknown if needed - apte->AtaFlags |= ATA_FLAGS_DRDY_REQUIRED; - - QueryPerformanceFrequency(&frequency); - - memcpy(data_buffer, buffer, *buf_len); - - QueryPerformanceCounter(&start); - *sense = !DeviceIoControl(ctx->handle, - IOCTL_ATA_PASS_THROUGH, - apte_and_buffer, - apte_and_buffer_len, - apte_and_buffer, - apte_and_buffer_len, - &k, - NULL); - QueryPerformanceCounter(&end); - - interval = (DOUBLE)(end.QuadPart - start.QuadPart) / frequency.QuadPart; - *duration = interval * 1000; - - if(*sense) error = GetLastError(); - - memcpy(buffer, data_buffer, *buf_len); - - error_registers->error = apte->CurrentTaskFile[0]; - error_registers->sector_count = apte->CurrentTaskFile[1]; - error_registers->sector = apte->CurrentTaskFile[2]; - error_registers->cylinder_low = apte->CurrentTaskFile[3]; - error_registers->cylinder_high = apte->CurrentTaskFile[4]; - error_registers->device_head = apte->CurrentTaskFile[5]; - error_registers->status = apte->CurrentTaskFile[6]; - - *sense = error_registers->error != 0 || (error_registers->status & 0xA5) != 0; - - free(apte_and_buffer); - return error; -} - -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; - PATA_PASS_THROUGH_EX apte; - PVOID apte_and_buffer; - ULONG_PTR offsetForBuffer; - PCHAR data_buffer; - DWORD k = 0; - DWORD error = 0; - LARGE_INTEGER frequency; - LARGE_INTEGER start; - LARGE_INTEGER end; - DOUBLE interval; - DWORD apte_and_buffer_len; - - *duration = 0; - *sense = FALSE; - offsetForBuffer = sizeof(ATA_PASS_THROUGH_EX) + sizeof(uint32_t); - apte_and_buffer_len = sizeof(ATA_PASS_THROUGH_EX) + sizeof(uint32_t) + 64 * 512; - - if(!ctx) return -1; - if(!buffer) return -1; - if(*buf_len > 64 * 512) return -1; - - apte_and_buffer = malloc(apte_and_buffer_len); - - if(!apte_and_buffer) return -1; - - memset(apte_and_buffer, 0, apte_and_buffer_len); - data_buffer = (PCHAR)apte_and_buffer + offsetForBuffer; - apte = (PATA_PASS_THROUGH_EX)apte_and_buffer; - - apte->TimeOutValue = timeout; - apte->DataBufferOffset = offsetForBuffer; - apte->Length = sizeof(ATA_PASS_THROUGH_EX); - apte->CurrentTaskFile[0] = registers.feature; - apte->CurrentTaskFile[1] = registers.sector_count; - apte->CurrentTaskFile[2] = registers.lba_low; - apte->CurrentTaskFile[3] = registers.lba_mid; - apte->CurrentTaskFile[4] = registers.lba_high; - apte->CurrentTaskFile[5] = registers.device_head; - apte->CurrentTaskFile[6] = registers.command; - - switch(protocol) - { - case AARUREMOTE_ATA_PROTOCOL_PIO_IN: - case AARUREMOTE_ATA_PROTOCOL_UDMA_IN: - case AARUREMOTE_ATA_PROTOCOL_DMA: apte->AtaFlags = ATA_FLAGS_DATA_IN; break; - case AARUREMOTE_ATA_PROTOCOL_PIO_OUT: - case AARUREMOTE_ATA_PROTOCOL_UDMA_OUT: apte->AtaFlags = ATA_FLAGS_DATA_OUT; break; - } - - switch(protocol) - { - case AARUREMOTE_ATA_PROTOCOL_DMA: - case AARUREMOTE_ATA_PROTOCOL_DMA_QUEUED: - case AARUREMOTE_ATA_PROTOCOL_FPDMA: - case AARUREMOTE_ATA_PROTOCOL_UDMA_IN: - case AARUREMOTE_ATA_PROTOCOL_UDMA_OUT: apte->AtaFlags |= ATA_FLAGS_USE_DMA; break; - } - - // Unknown if needed - apte->AtaFlags |= ATA_FLAGS_DRDY_REQUIRED; - - QueryPerformanceFrequency(&frequency); - - memcpy(data_buffer, buffer, *buf_len); - - QueryPerformanceCounter(&start); - *sense = !DeviceIoControl(ctx->handle, - IOCTL_ATA_PASS_THROUGH, - apte_and_buffer, - apte_and_buffer_len, - apte_and_buffer, - apte_and_buffer_len, - &k, - NULL); - QueryPerformanceCounter(&end); - - interval = (DOUBLE)(end.QuadPart - start.QuadPart) / frequency.QuadPart; - *duration = interval * 1000; - - if(*sense) error = GetLastError(); - - memcpy(buffer, data_buffer, *buf_len); - - error_registers->error = apte->CurrentTaskFile[0]; - error_registers->sector_count = apte->CurrentTaskFile[1]; - error_registers->lba_low = apte->CurrentTaskFile[2]; - error_registers->lba_mid = apte->CurrentTaskFile[3]; - error_registers->lba_high = apte->CurrentTaskFile[4]; - error_registers->device_head = apte->CurrentTaskFile[5]; - error_registers->status = apte->CurrentTaskFile[6]; - - *sense = error_registers->error != 0 || (error_registers->status & 0xA5) != 0; - - free(apte_and_buffer); - return error; -} - -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; - PATA_PASS_THROUGH_EX apte; - PVOID apte_and_buffer; - ULONG_PTR offsetForBuffer; - PCHAR data_buffer; - DWORD k = 0; - DWORD error = 0; - LARGE_INTEGER frequency; - LARGE_INTEGER start; - LARGE_INTEGER end; - DOUBLE interval; - DWORD apte_and_buffer_len; - - *duration = 0; - *sense = FALSE; - offsetForBuffer = sizeof(ATA_PASS_THROUGH_EX) + sizeof(uint32_t); - apte_and_buffer_len = sizeof(ATA_PASS_THROUGH_EX) + sizeof(uint32_t) + 64 * 512; - - if(!ctx) return -1; - if(!buffer) return -1; - if(*buf_len > 64 * 512) return -1; - - apte_and_buffer = malloc(apte_and_buffer_len); - - if(!apte_and_buffer) return -1; - - memset(apte_and_buffer, 0, apte_and_buffer_len); - data_buffer = (PCHAR)apte_and_buffer + offsetForBuffer; - apte = (PATA_PASS_THROUGH_EX)apte_and_buffer; - - apte->TimeOutValue = timeout; - apte->DataBufferOffset = offsetForBuffer; - apte->Length = sizeof(ATA_PASS_THROUGH_EX); - apte->PreviousTaskFile[0] = ((registers.feature & 0xFF00) >> 8); - apte->PreviousTaskFile[1] = ((registers.sector_count & 0xFF00) >> 8); - apte->PreviousTaskFile[2] = ((registers.lba_low & 0xFF00) >> 8); - apte->PreviousTaskFile[3] = ((registers.lba_mid & 0xFF00) >> 8); - apte->PreviousTaskFile[4] = ((registers.lba_high & 0xFF00) >> 8); - apte->CurrentTaskFile[0] = registers.feature & 0xFF; - apte->CurrentTaskFile[1] = registers.sector_count & 0xFF; - apte->CurrentTaskFile[2] = registers.lba_low & 0xFF; - apte->CurrentTaskFile[3] = registers.lba_mid & 0xFF; - apte->CurrentTaskFile[4] = registers.lba_mid & 0xFF; - apte->CurrentTaskFile[5] = registers.device_head; - apte->CurrentTaskFile[6] = registers.command; - - switch(protocol) - { - case AARUREMOTE_ATA_PROTOCOL_PIO_IN: - case AARUREMOTE_ATA_PROTOCOL_UDMA_IN: - case AARUREMOTE_ATA_PROTOCOL_DMA: apte->AtaFlags = ATA_FLAGS_DATA_IN; break; - case AARUREMOTE_ATA_PROTOCOL_PIO_OUT: - case AARUREMOTE_ATA_PROTOCOL_UDMA_OUT: apte->AtaFlags = ATA_FLAGS_DATA_OUT; break; - } - - switch(protocol) - { - case AARUREMOTE_ATA_PROTOCOL_DMA: - case AARUREMOTE_ATA_PROTOCOL_DMA_QUEUED: - case AARUREMOTE_ATA_PROTOCOL_FPDMA: - case AARUREMOTE_ATA_PROTOCOL_UDMA_IN: - case AARUREMOTE_ATA_PROTOCOL_UDMA_OUT: apte->AtaFlags |= ATA_FLAGS_USE_DMA; break; - } - - apte->AtaFlags |= ATA_FLAGS_48BIT_COMMAND; - - // Unknown if needed - apte->AtaFlags |= ATA_FLAGS_DRDY_REQUIRED; - - QueryPerformanceFrequency(&frequency); - - memcpy(data_buffer, buffer, *buf_len); - - QueryPerformanceCounter(&start); - *sense = !DeviceIoControl(ctx->handle, - IOCTL_ATA_PASS_THROUGH, - apte_and_buffer, - apte_and_buffer_len, - apte_and_buffer, - apte_and_buffer_len, - &k, - NULL); - QueryPerformanceCounter(&end); - - interval = (DOUBLE)(end.QuadPart - start.QuadPart) / frequency.QuadPart; - *duration = interval * 1000; - - if(*sense) error = GetLastError(); - - memcpy(buffer, data_buffer, *buf_len); - - error_registers->error = apte->CurrentTaskFile[0]; - error_registers->sector_count = (apte->PreviousTaskFile[1] << 8) + apte->CurrentTaskFile[1]; - error_registers->lba_low = (apte->PreviousTaskFile[2] << 8) + apte->CurrentTaskFile[2]; - error_registers->lba_mid = (apte->PreviousTaskFile[3] << 8) + apte->CurrentTaskFile[3]; - error_registers->lba_high = (apte->PreviousTaskFile[4] << 8) + apte->CurrentTaskFile[4]; - error_registers->device_head = apte->CurrentTaskFile[5]; - error_registers->status = apte->CurrentTaskFile[6]; - - *sense = error_registers->error != 0 || (error_registers->status & 0xA5) != 0; - - free(apte_and_buffer); - return error; -} \ No newline at end of file diff --git a/win32/device.c b/win32/device.c index 0b82711..be18d25 100644 --- a/win32/device.c +++ b/win32/device.c @@ -23,15 +23,15 @@ #include #include -void* Win32OpenDevice(const char* device_path) +void* DeviceOpen(const char* device_path) { - Win32DeviceContext* ctx; + DeviceContext* ctx; - ctx = malloc(sizeof(Win32DeviceContext)); + ctx = malloc(sizeof(DeviceContext)); if(!ctx) return NULL; - memset(ctx, 0, sizeof(Win32DeviceContext)); + memset(ctx, 0, sizeof(DeviceContext)); ctx->handle = CreateFile(device_path, GENERIC_READ | GENERIC_WRITE, @@ -52,9 +52,9 @@ void* Win32OpenDevice(const char* device_path) return ctx; } -void Win32CloseDevice(void* device_ctx) +void DeviceClose(void* device_ctx) { - Win32DeviceContext* ctx = device_ctx; + DeviceContext* ctx = device_ctx; if(!ctx) return; @@ -63,9 +63,9 @@ void Win32CloseDevice(void* device_ctx) free(ctx); } -int32_t Win32GetDeviceType(void* device_ctx) +int32_t GetDeviceType(void* device_ctx) { - Win32DeviceContext* ctx = device_ctx; + DeviceContext* ctx = device_ctx; STORAGE_PROPERTY_QUERY query; DWORD error = 0; BOOL ret; diff --git a/win32/ieee1394.c b/win32/ieee1394.c index 7ab6f10..9761a83 100644 --- a/win32/ieee1394.c +++ b/win32/ieee1394.c @@ -19,14 +19,14 @@ #include -uint8_t Win32GetIeee1394Data(void* device_ctx, - uint32_t* id_model, - uint32_t* id_vendor, - uint64_t* guid, - char* vendor, - char* model) +uint8_t GetFireWireData(void* device_ctx, + uint32_t* id_model, + uint32_t* id_vendor, + uint64_t* guid, + char* vendor, + char* model) { - Win32DeviceContext* ctx = device_ctx; + DeviceContext* ctx = device_ctx; if(!ctx) return 0; diff --git a/win32/list_devices.c b/win32/list_devices.c index a9172a2..8d74baf 100644 --- a/win32/list_devices.c +++ b/win32/list_devices.c @@ -25,7 +25,7 @@ #define IOCTL_STORAGE_QUERY_PROPERTY 0x2D1400 #endif -DeviceInfoList* Win32ListDevices() +DeviceInfoList* ListDevices() { char physId[4096]; LPSTR physical; diff --git a/win32/network.c b/win32/network.c index ab0e60c..d12db8e 100644 --- a/win32/network.c +++ b/win32/network.c @@ -78,9 +78,9 @@ char* PrintIpv4Address(struct in_addr addr) { return inet_ntoa(addr); } void* NetSocket(uint32_t domain, uint32_t type, uint32_t protocol) { - WSADATA ws; - int ret; - Win32NetworkContext* ctx; + WSADATA ws; + int ret; + NetworkContext* ctx; ret = WSAStartup(MAKEWORD(2, 0), &ws); @@ -90,7 +90,7 @@ void* NetSocket(uint32_t domain, uint32_t type, uint32_t protocol) return NULL; } - ctx = malloc(sizeof(Win32NetworkContext)); + ctx = malloc(sizeof(NetworkContext)); if(!ctx) return NULL; @@ -108,7 +108,7 @@ void* NetSocket(uint32_t domain, uint32_t type, uint32_t protocol) int32_t NetBind(void* net_ctx, struct sockaddr* addr, socklen_t addrlen) { - Win32NetworkContext* ctx = net_ctx; + NetworkContext* ctx = net_ctx; if(!ctx) return -1; @@ -117,7 +117,7 @@ int32_t NetBind(void* net_ctx, struct sockaddr* addr, socklen_t addrlen) int32_t NetListen(void* net_ctx, uint32_t backlog) { - Win32NetworkContext* ctx = net_ctx; + NetworkContext* ctx = net_ctx; if(!ctx) return -1; @@ -126,12 +126,12 @@ int32_t NetListen(void* net_ctx, uint32_t backlog) void* NetAccept(void* net_ctx, struct sockaddr* addr, socklen_t* addrlen) { - Win32NetworkContext* ctx = net_ctx; - Win32NetworkContext* cli_ctx; + NetworkContext* ctx = net_ctx; + NetworkContext* cli_ctx; if(!ctx) return NULL; - cli_ctx = malloc(sizeof(Win32NetworkContext)); + cli_ctx = malloc(sizeof(NetworkContext)); if(!cli_ctx) return NULL; @@ -148,8 +148,8 @@ void* NetAccept(void* net_ctx, struct sockaddr* addr, socklen_t* addrlen) int32_t NetRecv(void* net_ctx, void* buf, int32_t len, uint32_t flags) { - Win32NetworkContext* ctx = net_ctx; - char* charbuf = buf; + NetworkContext* ctx = net_ctx; + char* charbuf = buf; if(!ctx) return -1; @@ -172,7 +172,7 @@ int32_t NetRecv(void* net_ctx, void* buf, int32_t len, uint32_t flags) int32_t NetWrite(void* net_ctx, const void* buf, int32_t size) { - Win32NetworkContext* ctx = net_ctx; + NetworkContext* ctx = net_ctx; if(!ctx) return -1; @@ -181,8 +181,8 @@ int32_t NetWrite(void* net_ctx, const void* buf, int32_t size) int32_t NetClose(void* net_ctx) { - int ret; - Win32NetworkContext* ctx = net_ctx; + int ret; + NetworkContext* ctx = net_ctx; if(!ctx) return -1; diff --git a/win32/pcmcia.c b/win32/pcmcia.c index 6d8ac70..695e95f 100644 --- a/win32/pcmcia.c +++ b/win32/pcmcia.c @@ -19,9 +19,9 @@ #include -uint8_t Win32GetPcmciaData(void* device_ctx, uint16_t* cis_len, char* cis) +uint8_t GetPcmciaData(void* device_ctx, uint16_t* cis_len, char* cis) { - Win32DeviceContext* ctx = device_ctx; + DeviceContext* ctx = device_ctx; if(!ctx) return 0; diff --git a/win32/scsi.c b/win32/scsi.c index 8c3ce64..cd7433c 100644 --- a/win32/scsi.c +++ b/win32/scsi.c @@ -22,19 +22,19 @@ #include #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) +int32_t SendScsiCommand(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; + DeviceContext* ctx = device_ctx; PSCSI_PASS_THROUGH_DIRECT sptd; PVOID sptd_and_sense; UCHAR dir; diff --git a/win32/sdhci.c b/win32/sdhci.c index c68de4d..1e0571a 100644 --- a/win32/sdhci.c +++ b/win32/sdhci.c @@ -20,21 +20,21 @@ #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) +int32_t SendSdhciCommand(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; + DeviceContext* ctx = device_ctx; DWORD cmdbuf_len; PCHAR cmdbuf; DWORD buf_len; @@ -126,19 +126,19 @@ BOOL IsSdhci(HANDLE handle) return GuidEquals(query.ProtocolGUID, sdGuid) || GuidEquals(query.ProtocolGUID, mmcGuid); } -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) +int32_t GetSdhciRegisters(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; - uint32_t duration; - uint32_t sense; + DeviceContext* ctx = device_ctx; + uint32_t duration; + uint32_t sense; if(!ctx) return -1; diff --git a/win32/usb.c b/win32/usb.c index 819b53f..a8b9790 100644 --- a/win32/usb.c +++ b/win32/usb.c @@ -589,7 +589,7 @@ UsbDevice_t* FindDeviceNumber(DWORD devNum, GUID diskGuid) return foundDevice; } -UsbDevice_t* FindDrivePath(Win32DeviceContext* ctx, GUID deviceGuid) +UsbDevice_t* FindDrivePath(DeviceContext* ctx, GUID deviceGuid) { // We start by getting the unique DeviceNumber of the given // DriveLetter. We'll use this later to find a matching @@ -598,23 +598,23 @@ UsbDevice_t* FindDrivePath(Win32DeviceContext* ctx, GUID deviceGuid) return devNum < 0 ? NULL : FindDeviceNumber(devNum, deviceGuid); } -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 GetUsbData(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; - UsbDevice_t* device = NULL; - GUID floppyGuid = GUID_DEVINTERFACE_FLOPPY; - GUID tapeGuid = GUID_DEVINTERFACE_TAPE; - GUID diskGuid = GUID_DEVINTERFACE_DISK; - GUID cdromGuid = GUID_DEVINTERFACE_CDROM; - GUID guids[4] = {floppyGuid, cdromGuid, diskGuid, tapeGuid}; - int i; + DeviceContext* ctx = device_ctx; + UsbDevice_t* device = NULL; + GUID floppyGuid = GUID_DEVINTERFACE_FLOPPY; + GUID tapeGuid = GUID_DEVINTERFACE_TAPE; + GUID diskGuid = GUID_DEVINTERFACE_DISK; + GUID cdromGuid = GUID_DEVINTERFACE_CDROM; + GUID guids[4] = {floppyGuid, cdromGuid, diskGuid, tapeGuid}; + int i; if(!ctx) return -1; diff --git a/win32/win32.h b/win32/win32.h index cd92cb9..780b998 100644 --- a/win32/win32.h +++ b/win32/win32.h @@ -38,108 +38,12 @@ typedef struct { SOCKET socket; -} Win32NetworkContext; +} NetworkContext; 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); +} DeviceContext; #endif // AARUREMOTE_WIN32_WIN32_H_