mirror of
https://github.com/aaru-dps/aaruremote.git
synced 2025-12-16 19:24:37 +00:00
Use opaque packet for device context.
This commit is contained in:
12
ata.c
12
ata.c
@@ -21,7 +21,7 @@
|
||||
#include "linux/linux.h"
|
||||
#endif
|
||||
|
||||
int32_t SendAtaChsCommand(int device_fd,
|
||||
int32_t SendAtaChsCommand(void* device_ctx,
|
||||
AtaRegistersChs registers,
|
||||
AtaErrorRegistersChs* error_registers,
|
||||
uint8_t protocol,
|
||||
@@ -34,7 +34,7 @@ int32_t SendAtaChsCommand(int device_fd,
|
||||
uint32_t* buf_len)
|
||||
{
|
||||
#if defined(__linux__) && !defined(__ANDROID__)
|
||||
return LinuxSendAtaChsCommand(device_fd,
|
||||
return LinuxSendAtaChsCommand(device_ctx,
|
||||
registers,
|
||||
error_registers,
|
||||
protocol,
|
||||
@@ -50,7 +50,7 @@ int32_t SendAtaChsCommand(int device_fd,
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t SendAtaLba28Command(int device_fd,
|
||||
int32_t SendAtaLba28Command(void* device_ctx,
|
||||
AtaRegistersLba28 registers,
|
||||
AtaErrorRegistersLba28* error_registers,
|
||||
uint8_t protocol,
|
||||
@@ -63,7 +63,7 @@ int32_t SendAtaLba28Command(int device_fd,
|
||||
uint32_t* buf_len)
|
||||
{
|
||||
#if defined(__linux__) && !defined(__ANDROID__)
|
||||
return LinuxSendAtaLba28Command(device_fd,
|
||||
return LinuxSendAtaLba28Command(device_ctx,
|
||||
registers,
|
||||
error_registers,
|
||||
protocol,
|
||||
@@ -79,7 +79,7 @@ int32_t SendAtaLba28Command(int device_fd,
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t SendAtaLba48Command(int device_fd,
|
||||
int32_t SendAtaLba48Command(void* device_ctx,
|
||||
AtaRegistersLba48 registers,
|
||||
AtaErrorRegistersLba48* error_registers,
|
||||
uint8_t protocol,
|
||||
@@ -92,7 +92,7 @@ int32_t SendAtaLba48Command(int device_fd,
|
||||
uint32_t* buf_len)
|
||||
{
|
||||
#if defined(__linux__) && !defined(__ANDROID__)
|
||||
return LinuxSendAtaLba48Command(device_fd,
|
||||
return LinuxSendAtaLba48Command(device_ctx,
|
||||
registers,
|
||||
error_registers,
|
||||
protocol,
|
||||
|
||||
6
device.c
6
device.c
@@ -23,7 +23,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
int DeviceOpen(const char* device_path)
|
||||
void* DeviceOpen(const char* device_path)
|
||||
{
|
||||
#if defined(__linux__) && !defined(__ANDROID__)
|
||||
return LinuxOpenDevice(device_path);
|
||||
@@ -32,10 +32,10 @@ int DeviceOpen(const char* device_path)
|
||||
#endif
|
||||
}
|
||||
|
||||
void DeviceClose(int device_fd)
|
||||
void DeviceClose(void* device_ctx)
|
||||
{
|
||||
#if defined(__linux__) && !defined(__ANDROID__)
|
||||
return LinuxCloseDevice(device_fd);
|
||||
return LinuxCloseDevice(device_ctx);
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
|
||||
24
dicmote.h
24
dicmote.h
@@ -429,10 +429,10 @@ typedef struct
|
||||
DeviceInfoList* ListDevices();
|
||||
void FreeDeviceInfoList(DeviceInfoList* start);
|
||||
uint16_t DeviceInfoListCount(DeviceInfoList* start);
|
||||
int DeviceOpen(const char* device_path);
|
||||
void DeviceClose(int device_fd);
|
||||
int32_t GetDeviceType(const char* device_path);
|
||||
int32_t SendScsiCommand(int device_fd,
|
||||
void* DeviceOpen(const char* device_path);
|
||||
void DeviceClose(void* device_ctx);
|
||||
int32_t GetDeviceType(void* device_ctx);
|
||||
int32_t SendScsiCommand(void* device_ctx,
|
||||
char* cdb,
|
||||
char* buffer,
|
||||
char** sense_buffer,
|
||||
@@ -445,7 +445,7 @@ int32_t SendScsiCommand(int device_fd,
|
||||
uint32_t* sense_len);
|
||||
int Hexchr2Bin(const char hex, char* out);
|
||||
size_t Hexs2Bin(const char* hex, unsigned char** out);
|
||||
int32_t GetSdhciRegisters(const char* device_path,
|
||||
int32_t GetSdhciRegisters(void* device_ctx,
|
||||
char** csd,
|
||||
char** cid,
|
||||
char** ocr,
|
||||
@@ -454,7 +454,7 @@ int32_t GetSdhciRegisters(const char* device_path,
|
||||
uint32_t* cid_len,
|
||||
uint32_t* ocr_len,
|
||||
uint32_t* scr_len);
|
||||
uint8_t GetUsbData(const char* device_path,
|
||||
uint8_t GetUsbData(void* device_ctx,
|
||||
uint16_t* desc_len,
|
||||
char* descriptors,
|
||||
uint16_t* id_vendor,
|
||||
@@ -462,14 +462,14 @@ uint8_t GetUsbData(const char* device_path,
|
||||
char* manufacturer,
|
||||
char* product,
|
||||
char* serial);
|
||||
uint8_t GetFireWireData(const char* device_path,
|
||||
uint8_t GetFireWireData(void* device_ctx,
|
||||
uint32_t* id_model,
|
||||
uint32_t* id_vendor,
|
||||
uint64_t* guid,
|
||||
char* vendor,
|
||||
char* model);
|
||||
uint8_t GetPcmciaData(const char* device_path, uint16_t* cis_len, char* cis);
|
||||
int32_t SendAtaChsCommand(int device_fd,
|
||||
uint8_t GetPcmciaData(void* device_ctx, uint16_t* cis_len, char* cis);
|
||||
int32_t SendAtaChsCommand(void* device_ctx,
|
||||
AtaRegistersChs registers,
|
||||
AtaErrorRegistersChs* error_registers,
|
||||
uint8_t protocol,
|
||||
@@ -480,7 +480,7 @@ int32_t SendAtaChsCommand(int device_fd,
|
||||
uint32_t* duration,
|
||||
uint32_t* sense,
|
||||
uint32_t* buf_len);
|
||||
int32_t SendAtaLba28Command(int device_fd,
|
||||
int32_t SendAtaLba28Command(void* device_ctx,
|
||||
AtaRegistersLba28 registers,
|
||||
AtaErrorRegistersLba28* error_registers,
|
||||
uint8_t protocol,
|
||||
@@ -491,7 +491,7 @@ int32_t SendAtaLba28Command(int device_fd,
|
||||
uint32_t* duration,
|
||||
uint32_t* sense,
|
||||
uint32_t* buf_len);
|
||||
int32_t SendAtaLba48Command(int device_fd,
|
||||
int32_t SendAtaLba48Command(void* device_ctx,
|
||||
AtaRegistersLba48 registers,
|
||||
AtaErrorRegistersLba48* error_registers,
|
||||
uint8_t protocol,
|
||||
@@ -502,7 +502,7 @@ int32_t SendAtaLba48Command(int device_fd,
|
||||
uint32_t* duration,
|
||||
uint32_t* sense,
|
||||
uint32_t* buf_len);
|
||||
int32_t SendSdhciCommand(int device_fd,
|
||||
int32_t SendSdhciCommand(void* device_ctx,
|
||||
uint8_t command,
|
||||
uint8_t write,
|
||||
uint8_t application,
|
||||
|
||||
21
linux/ata.c
21
linux/ata.c
@@ -37,7 +37,7 @@ int32_t AtaProtocolToScsiDirection(uint8_t protocol)
|
||||
}
|
||||
}
|
||||
|
||||
int32_t LinuxSendAtaChsCommand(int device_fd,
|
||||
int32_t LinuxSendAtaChsCommand(void* device_ctx,
|
||||
AtaRegistersChs registers,
|
||||
AtaErrorRegistersChs* error_registers,
|
||||
uint8_t protocol,
|
||||
@@ -54,6 +54,9 @@ int32_t LinuxSendAtaChsCommand(int device_fd,
|
||||
unsigned char cdb[16];
|
||||
char* sense_buf;
|
||||
uint32_t sense_len;
|
||||
LinuxDeviceContext* ctx = device_ctx;
|
||||
|
||||
if(!ctx) return -1;
|
||||
|
||||
memset(&cdb, 0, 16);
|
||||
|
||||
@@ -81,7 +84,7 @@ int32_t LinuxSendAtaChsCommand(int device_fd,
|
||||
cdb[13] = registers.device_head;
|
||||
cdb[14] = registers.command;
|
||||
|
||||
int error = LinuxSendScsiCommand(device_fd,
|
||||
int error = LinuxSendScsiCommand(ctx,
|
||||
(char*)cdb,
|
||||
buffer,
|
||||
&sense_buf,
|
||||
@@ -109,7 +112,7 @@ int32_t LinuxSendAtaChsCommand(int device_fd,
|
||||
return error;
|
||||
}
|
||||
|
||||
int32_t LinuxSendAtaLba28Command(int device_fd,
|
||||
int32_t LinuxSendAtaLba28Command(void* device_ctx,
|
||||
AtaRegistersLba28 registers,
|
||||
AtaErrorRegistersLba28* error_registers,
|
||||
uint8_t protocol,
|
||||
@@ -126,6 +129,9 @@ int32_t LinuxSendAtaLba28Command(int device_fd,
|
||||
unsigned char cdb[16];
|
||||
char* sense_buf;
|
||||
uint32_t sense_len;
|
||||
LinuxDeviceContext* ctx = device_ctx;
|
||||
|
||||
if(!ctx) return -1;
|
||||
|
||||
memset(&cdb, 0, 16);
|
||||
|
||||
@@ -155,7 +161,7 @@ int32_t LinuxSendAtaLba28Command(int device_fd,
|
||||
cdb[13] = registers.device_head;
|
||||
cdb[14] = registers.command;
|
||||
|
||||
int error = LinuxSendScsiCommand(device_fd,
|
||||
int error = LinuxSendScsiCommand(ctx,
|
||||
(char*)cdb,
|
||||
buffer,
|
||||
&sense_buf,
|
||||
@@ -183,7 +189,7 @@ int32_t LinuxSendAtaLba28Command(int device_fd,
|
||||
return error;
|
||||
}
|
||||
|
||||
int32_t LinuxSendAtaLba48Command(int device_fd,
|
||||
int32_t LinuxSendAtaLba48Command(void* device_ctx,
|
||||
AtaRegistersLba48 registers,
|
||||
AtaErrorRegistersLba48* error_registers,
|
||||
uint8_t protocol,
|
||||
@@ -200,6 +206,9 @@ int32_t LinuxSendAtaLba48Command(int device_fd,
|
||||
unsigned char cdb[16];
|
||||
char* sense_buf;
|
||||
uint32_t sense_len;
|
||||
LinuxDeviceContext* ctx = device_ctx;
|
||||
|
||||
if(!ctx) return -1;
|
||||
|
||||
memset(&cdb, 0, 16);
|
||||
|
||||
@@ -235,7 +244,7 @@ int32_t LinuxSendAtaLba48Command(int device_fd,
|
||||
cdb[13] = registers.device_head;
|
||||
cdb[14] = registers.command;
|
||||
|
||||
int error = LinuxSendScsiCommand(device_fd,
|
||||
int error = LinuxSendScsiCommand(ctx,
|
||||
(char*)cdb,
|
||||
buffer,
|
||||
&sense_buf,
|
||||
|
||||
@@ -28,21 +28,48 @@
|
||||
#include <libudev.h>
|
||||
#endif
|
||||
|
||||
int LinuxOpenDevice(const char* device_path)
|
||||
void* LinuxOpenDevice(const char* device_path)
|
||||
{
|
||||
int fd;
|
||||
LinuxDeviceContext* ctx;
|
||||
|
||||
fd = open(device_path, O_RDWR | O_NONBLOCK | O_CREAT);
|
||||
ctx = malloc(sizeof(LinuxDeviceContext));
|
||||
|
||||
if((fd < 0) && (errno == EACCES || errno == EROFS)) { fd = open(device_path, O_RDONLY | O_NONBLOCK); }
|
||||
if(!ctx) return NULL;
|
||||
|
||||
return fd;
|
||||
memset(ctx, 0, sizeof(LinuxDeviceContext));
|
||||
|
||||
ctx->fd = open(device_path, O_RDWR | O_NONBLOCK | O_CREAT);
|
||||
|
||||
if((ctx->fd < 0) && (errno == EACCES || errno == EROFS)) { ctx->fd = open(device_path, O_RDONLY | O_NONBLOCK); }
|
||||
|
||||
if(ctx->fd <= 0)
|
||||
{
|
||||
free(ctx);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
strncpy(ctx->device_path, device_path, 4096);
|
||||
|
||||
return ctx;
|
||||
}
|
||||
|
||||
void LinuxCloseDevice(int device_fd) { close(device_fd); }
|
||||
|
||||
int32_t LinuxGetDeviceType(const char* device_path)
|
||||
void LinuxCloseDevice(void* device_ctx)
|
||||
{
|
||||
LinuxDeviceContext* ctx = device_ctx;
|
||||
|
||||
if(!ctx) return;
|
||||
|
||||
close(ctx->fd);
|
||||
|
||||
free(ctx);
|
||||
}
|
||||
|
||||
int32_t LinuxGetDeviceType(void* device_ctx)
|
||||
{
|
||||
LinuxDeviceContext* ctx = device_ctx;
|
||||
|
||||
if(!ctx) return -1;
|
||||
|
||||
#ifdef HAS_UDEV
|
||||
struct udev* udev;
|
||||
struct udev_device* udev_device;
|
||||
@@ -54,7 +81,7 @@ int32_t LinuxGetDeviceType(const char* device_path)
|
||||
|
||||
if(!udev) return DICMOTE_DEVICE_TYPE_UNKNOWN;
|
||||
|
||||
chrptr = strrchr(device_path, '/');
|
||||
chrptr = strrchr(ctx->device_path, '/');
|
||||
if(chrptr == 0) return DICMOTE_DEVICE_TYPE_UNKNOWN;
|
||||
|
||||
chrptr++;
|
||||
@@ -140,13 +167,13 @@ int32_t LinuxGetDeviceType(const char* device_path)
|
||||
FILE* file;
|
||||
size_t len = 4096;
|
||||
|
||||
if(strlen(device_path) <= 5) return dev_type;
|
||||
if(strlen(ctx->device_path) <= 5) return dev_type;
|
||||
|
||||
if(strstr(device_path, "nvme")) return DICMOTE_DEVICE_TYPE_NVME;
|
||||
if(strstr(ctx->device_path, "nvme")) return DICMOTE_DEVICE_TYPE_NVME;
|
||||
|
||||
dev_name = device_path + 5;
|
||||
dev_name = ctx->device_path + 5;
|
||||
|
||||
if(strstr(device_path, "mmcblk"))
|
||||
if(strstr(ctx->device_path, "mmcblk"))
|
||||
{
|
||||
dev_type = DICMOTE_DEVICE_TYPE_MMC;
|
||||
|
||||
@@ -293,7 +320,7 @@ int32_t LinuxGetDeviceType(const char* device_path)
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t LinuxGetSdhciRegisters(const char* device_path,
|
||||
int32_t LinuxGetSdhciRegisters(void* device_ctx,
|
||||
char** csd,
|
||||
char** cid,
|
||||
char** ocr,
|
||||
@@ -303,6 +330,7 @@ int32_t LinuxGetSdhciRegisters(const char* device_path,
|
||||
uint32_t* ocr_len,
|
||||
uint32_t* scr_len)
|
||||
{
|
||||
LinuxDeviceContext* ctx = device_ctx;
|
||||
char* tmp_string;
|
||||
char* sysfs_path_csd;
|
||||
char* sysfs_path_cid;
|
||||
@@ -320,9 +348,11 @@ int32_t LinuxGetSdhciRegisters(const char* device_path,
|
||||
*scr_len = 0;
|
||||
size_t n = 1026;
|
||||
|
||||
if(strncmp(device_path, "/dev/mmcblk", 11) != 0) return 0;
|
||||
if(!ctx) return -1;
|
||||
|
||||
len = strlen(device_path) + 19;
|
||||
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);
|
||||
@@ -343,9 +373,9 @@ int32_t LinuxGetSdhciRegisters(const char* device_path,
|
||||
memset(sysfs_path_cid, 0, len);
|
||||
memset(sysfs_path_scr, 0, len);
|
||||
memset(sysfs_path_ocr, 0, len);
|
||||
memset(tmp_string, 0, strlen(device_path) - 5);
|
||||
memset(tmp_string, 0, strlen(ctx->device_path) - 5);
|
||||
|
||||
memcpy(tmp_string, device_path + 5, strlen(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);
|
||||
|
||||
@@ -15,19 +15,22 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "linux.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
uint8_t LinuxGetIeee1394Data(const char* device_path,
|
||||
uint8_t LinuxGetIeee1394Data(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];
|
||||
@@ -37,17 +40,19 @@ uint8_t LinuxGetIeee1394Data(const char* device_path,
|
||||
int found;
|
||||
FILE* file;
|
||||
|
||||
if(!ctx) return 0;
|
||||
|
||||
*id_model = 0;
|
||||
*id_vendor = 0;
|
||||
*guid = 0;
|
||||
memset(tmp_path, 0, 4096);
|
||||
memset(resolved_link, 0, 4096);
|
||||
|
||||
if(strncmp(device_path, "/dev/sd", 7) != 0 && strncmp(device_path, "/dev/sr", 7) != 0 &&
|
||||
strncmp(device_path, "/dev/st", 7) != 0)
|
||||
if(strncmp(ctx->device_path, "/dev/sd", 7) != 0 && strncmp(ctx->device_path, "/dev/sr", 7) != 0 &&
|
||||
strncmp(ctx->device_path, "/dev/st", 7) != 0)
|
||||
return 0;
|
||||
|
||||
dev_path = (char*)device_path + 5;
|
||||
dev_path = (char*)ctx->device_path + 5;
|
||||
|
||||
snprintf(tmp_path, 4096, "/sys/block/%s", dev_path);
|
||||
|
||||
|
||||
@@ -24,12 +24,12 @@
|
||||
|
||||
DeviceInfoList* LinuxListDevices();
|
||||
|
||||
int LinuxOpenDevice(const char* device_path);
|
||||
void LinuxCloseDevice(int device_fd);
|
||||
void* LinuxOpenDevice(const char* device_path);
|
||||
void LinuxCloseDevice(void* device_ctx);
|
||||
|
||||
int32_t LinuxGetDeviceType(const char* device_path);
|
||||
int32_t LinuxGetDeviceType(void* device_ctx);
|
||||
|
||||
int32_t LinuxSendScsiCommand(int device_fd,
|
||||
int32_t LinuxSendScsiCommand(void* device_ctx,
|
||||
char* cdb,
|
||||
char* buffer,
|
||||
char** sense_buffer,
|
||||
@@ -41,7 +41,7 @@ int32_t LinuxSendScsiCommand(int device_fd,
|
||||
uint32_t* buf_len,
|
||||
uint32_t* sense_len);
|
||||
|
||||
int32_t LinuxGetSdhciRegisters(const char* device_path,
|
||||
int32_t LinuxGetSdhciRegisters(void* device_ctx,
|
||||
char** csd,
|
||||
char** cid,
|
||||
char** ocr,
|
||||
@@ -51,7 +51,7 @@ int32_t LinuxGetSdhciRegisters(const char* device_path,
|
||||
uint32_t* ocr_len,
|
||||
uint32_t* scr_len);
|
||||
|
||||
uint8_t LinuxGetUsbData(const char* device_path,
|
||||
uint8_t LinuxGetUsbData(void* device_ctx,
|
||||
uint16_t* desc_len,
|
||||
char* descriptors,
|
||||
uint16_t* id_vendor,
|
||||
@@ -60,16 +60,16 @@ uint8_t LinuxGetUsbData(const char* device_path,
|
||||
char* product,
|
||||
char* serial);
|
||||
|
||||
uint8_t LinuxGetIeee1394Data(const char* device_path,
|
||||
uint8_t LinuxGetIeee1394Data(void* device_ctx,
|
||||
uint32_t* id_model,
|
||||
uint32_t* id_vendor,
|
||||
uint64_t* guid,
|
||||
char* vendor,
|
||||
char* model);
|
||||
|
||||
uint8_t LinuxGetPcmciaData(const char* device_path, uint16_t* cis_len, char* cis);
|
||||
uint8_t LinuxGetPcmciaData(void* device_ctx, uint16_t* cis_len, char* cis);
|
||||
|
||||
int32_t LinuxSendAtaChsCommand(int device_fd,
|
||||
int32_t LinuxSendAtaChsCommand(void* device_ctx,
|
||||
AtaRegistersChs registers,
|
||||
AtaErrorRegistersChs* error_registers,
|
||||
uint8_t protocol,
|
||||
@@ -81,7 +81,7 @@ int32_t LinuxSendAtaChsCommand(int device_fd,
|
||||
uint32_t* sense,
|
||||
uint32_t* buf_len);
|
||||
|
||||
int32_t LinuxSendAtaLba28Command(int device_fd,
|
||||
int32_t LinuxSendAtaLba28Command(void* device_ctx,
|
||||
AtaRegistersLba28 registers,
|
||||
AtaErrorRegistersLba28* error_registers,
|
||||
uint8_t protocol,
|
||||
@@ -93,7 +93,7 @@ int32_t LinuxSendAtaLba28Command(int device_fd,
|
||||
uint32_t* sense,
|
||||
uint32_t* buf_len);
|
||||
|
||||
int32_t LinuxSendAtaLba48Command(int device_fd,
|
||||
int32_t LinuxSendAtaLba48Command(void* device_ctx,
|
||||
AtaRegistersLba48 registers,
|
||||
AtaErrorRegistersLba48* error_registers,
|
||||
uint8_t protocol,
|
||||
@@ -105,7 +105,7 @@ int32_t LinuxSendAtaLba48Command(int device_fd,
|
||||
uint32_t* sense,
|
||||
uint32_t* buf_len);
|
||||
|
||||
int32_t LinuxSendSdhciCommand(int device_fd,
|
||||
int32_t LinuxSendSdhciCommand(void* device_ctx,
|
||||
uint8_t command,
|
||||
uint8_t write,
|
||||
uint8_t application,
|
||||
@@ -119,4 +119,10 @@ int32_t LinuxSendSdhciCommand(int device_fd,
|
||||
uint32_t* duration,
|
||||
uint32_t* sense);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int fd;
|
||||
char device_path[4096];
|
||||
} LinuxDeviceContext;
|
||||
|
||||
#endif // DICREMOTE_LINUX_LINUX_H_
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "linux.h"
|
||||
|
||||
#include <dirent.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
@@ -22,8 +24,9 @@
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
uint8_t LinuxGetPcmciaData(const char* device_path, uint16_t* cis_len, char* cis)
|
||||
uint8_t LinuxGetPcmciaData(void* device_ctx, uint16_t* cis_len, char* cis)
|
||||
{
|
||||
LinuxDeviceContext* ctx = device_ctx;
|
||||
char* dev_path;
|
||||
char tmp_path[4096];
|
||||
char resolved_link[4096];
|
||||
@@ -35,14 +38,16 @@ uint8_t LinuxGetPcmciaData(const char* device_path, uint16_t* cis_len, char* cis
|
||||
struct dirent* dent;
|
||||
*cis_len = 0;
|
||||
|
||||
if(!ctx) return 0;
|
||||
|
||||
memset(tmp_path, 0, 4096);
|
||||
memset(resolved_link, 0, 4096);
|
||||
|
||||
if(strncmp(device_path, "/dev/sd", 7) != 0 && strncmp(device_path, "/dev/sr", 7) != 0 &&
|
||||
strncmp(device_path, "/dev/st", 7) != 0)
|
||||
if(strncmp(ctx->device_path, "/dev/sd", 7) != 0 && strncmp(ctx->device_path, "/dev/sr", 7) != 0 &&
|
||||
strncmp(ctx->device_path, "/dev/st", 7) != 0)
|
||||
return 0;
|
||||
|
||||
dev_path = (char*)device_path + 5;
|
||||
dev_path = (char*)ctx->device_path + 5;
|
||||
|
||||
snprintf(tmp_path, 4096, "/sys/block/%s", dev_path);
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
|
||||
#include "../dicmote.h"
|
||||
#include "linux.h"
|
||||
|
||||
#include <malloc.h>
|
||||
#include <scsi/sg.h>
|
||||
@@ -23,7 +24,7 @@
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
int32_t LinuxSendScsiCommand(int device_fd,
|
||||
int32_t LinuxSendScsiCommand(void* device_ctx,
|
||||
char* cdb,
|
||||
char* buffer,
|
||||
char** sense_buffer,
|
||||
@@ -35,10 +36,13 @@ int32_t LinuxSendScsiCommand(int device_fd,
|
||||
uint32_t* buf_len,
|
||||
uint32_t* sense_len)
|
||||
{
|
||||
LinuxDeviceContext* ctx = device_ctx;
|
||||
sg_io_hdr_t hdr;
|
||||
int dir, ret;
|
||||
*sense_len = 32;
|
||||
|
||||
if(!ctx) return -1;
|
||||
|
||||
memset(&hdr, 0, sizeof(sg_io_hdr_t));
|
||||
*sense_buffer = malloc(*sense_len);
|
||||
|
||||
@@ -65,7 +69,7 @@ int32_t LinuxSendScsiCommand(int device_fd,
|
||||
hdr.timeout = timeout;
|
||||
hdr.flags = SG_FLAG_DIRECT_IO;
|
||||
|
||||
ret = ioctl(device_fd, SG_IO, &hdr);
|
||||
ret = ioctl(ctx->fd, SG_IO, &hdr);
|
||||
|
||||
*sense = (hdr.info & SG_INFO_OK_MASK) != SG_INFO_OK;
|
||||
// TODO: Manual timing if duration is 0
|
||||
|
||||
@@ -15,14 +15,15 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "linux.h"
|
||||
#include "mmc/ioctl.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include "mmc/ioctl.h"
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
int32_t LinuxSendSdhciCommand(int device_fd,
|
||||
int32_t LinuxSendSdhciCommand(void* device_ctx,
|
||||
uint8_t command,
|
||||
uint8_t write,
|
||||
uint8_t application,
|
||||
@@ -36,11 +37,14 @@ int32_t LinuxSendSdhciCommand(int device_fd,
|
||||
uint32_t* duration,
|
||||
uint32_t* sense)
|
||||
{
|
||||
LinuxDeviceContext* ctx = device_ctx;
|
||||
struct mmc_ioc_cmd mmc_ioc_cmd;
|
||||
int32_t error;
|
||||
*duration = 0;
|
||||
*sense = 0;
|
||||
|
||||
if(!ctx) return -1;
|
||||
|
||||
memset(response, 0, sizeof(uint32_t) * 4);
|
||||
memset(&mmc_ioc_cmd, 0, sizeof(struct mmc_ioc_cmd));
|
||||
|
||||
@@ -59,7 +63,7 @@ int32_t LinuxSendSdhciCommand(int device_fd,
|
||||
mmc_ioc_cmd.data_ptr = (uint64_t)buffer;
|
||||
|
||||
// TODO: Timing
|
||||
error = ioctl(device_fd, MMC_IOC_CMD, &mmc_ioc_cmd);
|
||||
error = ioctl(ctx->fd, MMC_IOC_CMD, &mmc_ioc_cmd);
|
||||
|
||||
if(error < 0) error = errno;
|
||||
|
||||
|
||||
11
linux/usb.c
11
linux/usb.c
@@ -23,7 +23,7 @@
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
uint8_t LinuxGetUsbData(const char* device_path,
|
||||
uint8_t LinuxGetUsbData(void* device_ctx,
|
||||
uint16_t* desc_len,
|
||||
char* descriptors,
|
||||
uint16_t* id_vendor,
|
||||
@@ -32,6 +32,7 @@ uint8_t LinuxGetUsbData(const char* device_path,
|
||||
char* product,
|
||||
char* serial)
|
||||
{
|
||||
LinuxDeviceContext* ctx = device_ctx;
|
||||
char* dev_path;
|
||||
char tmp_path[4096];
|
||||
char resolved_link[4096];
|
||||
@@ -41,17 +42,19 @@ uint8_t LinuxGetUsbData(const char* device_path,
|
||||
int found = 1;
|
||||
FILE* file;
|
||||
|
||||
if(!ctx) return -1;
|
||||
|
||||
*desc_len = 0;
|
||||
*id_vendor = 0;
|
||||
*id_product = 0;
|
||||
memset(tmp_path, 0, 4096);
|
||||
memset(resolved_link, 0, 4096);
|
||||
|
||||
if(strncmp(device_path, "/dev/sd", 7) != 0 && strncmp(device_path, "/dev/sr", 7) != 0 &&
|
||||
strncmp(device_path, "/dev/st", 7) != 0)
|
||||
if(strncmp(ctx->device_path, "/dev/sd", 7) != 0 && strncmp(ctx->device_path, "/dev/sr", 7) != 0 &&
|
||||
strncmp(ctx->device_path, "/dev/st", 7) != 0)
|
||||
return 0;
|
||||
|
||||
dev_path = (char*)device_path + 5;
|
||||
dev_path = (char*)ctx->device_path + 5;
|
||||
|
||||
snprintf(tmp_path, 4096, "/sys/block/%s", dev_path);
|
||||
|
||||
|
||||
4
pcmcia.c
4
pcmcia.c
@@ -21,10 +21,10 @@
|
||||
#include "linux/linux.h"
|
||||
#endif
|
||||
|
||||
uint8_t GetPcmciaData(const char* device_path, uint16_t* cis_len, char* cis)
|
||||
uint8_t GetPcmciaData(void* device_ctx, uint16_t* cis_len, char* cis)
|
||||
{
|
||||
#if defined(__linux__) && !defined(__ANDROID__)
|
||||
return LinuxGetPcmciaData(device_path, cis_len, cis);
|
||||
return LinuxGetPcmciaData(device_ctx, cis_len, cis);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
4
scsi.c
4
scsi.c
@@ -21,7 +21,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
int32_t SendScsiCommand(int device_fd,
|
||||
int32_t SendScsiCommand(void* device_ctx,
|
||||
char* cdb,
|
||||
char* buffer,
|
||||
char** sense_buffer,
|
||||
@@ -35,7 +35,7 @@ int32_t SendScsiCommand(int device_fd,
|
||||
{
|
||||
#if defined(__linux__) && !defined(__ANDROID__)
|
||||
return LinuxSendScsiCommand(
|
||||
device_fd, cdb, buffer, sense_buffer, timeout, direction, duration, sense, cdb_len, buf_len, sense_len);
|
||||
device_ctx, cdb, buffer, sense_buffer, timeout, direction, duration, sense, cdb_len, buf_len, sense_len);
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
|
||||
4
sdhci.c
4
sdhci.c
@@ -21,7 +21,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
int32_t SendSdhciCommand(int device_fd,
|
||||
int32_t SendSdhciCommand(void* device_ctx,
|
||||
uint8_t command,
|
||||
uint8_t write,
|
||||
uint8_t application,
|
||||
@@ -37,7 +37,7 @@ int32_t SendSdhciCommand(int device_fd,
|
||||
uint32_t* sense)
|
||||
{
|
||||
#if defined(__linux__) && !defined(__ANDROID__)
|
||||
return LinuxSendSdhciCommand(device_fd,
|
||||
return LinuxSendSdhciCommand(device_ctx,
|
||||
command,
|
||||
write,
|
||||
application,
|
||||
|
||||
4
usb.c
4
usb.c
@@ -21,7 +21,7 @@
|
||||
#include "linux/linux.h"
|
||||
#endif
|
||||
|
||||
uint8_t GetUsbData(const char* device_path,
|
||||
uint8_t GetUsbData(void* device_ctx,
|
||||
uint16_t* desc_len,
|
||||
char* descriptors,
|
||||
uint16_t* id_vendor,
|
||||
@@ -31,7 +31,7 @@ uint8_t GetUsbData(const char* device_path,
|
||||
char* serial)
|
||||
{
|
||||
#if defined(__linux__) && !defined(__ANDROID__)
|
||||
return LinuxGetUsbData(device_path, desc_len, descriptors, id_vendor, id_product, manufacturer, product, serial);
|
||||
return LinuxGetUsbData(device_ctx, desc_len, descriptors, id_vendor, id_product, manufacturer, product, serial);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
@@ -35,6 +35,12 @@
|
||||
#define DICREMOTE_WII_DEVICE_PATH_GCMM_A "/dev/gcmm/slota"
|
||||
#define DICREMOTE_WII_DEVICE_PATH_GCMM_B "/dev/gcmm/slotb"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
s32 ios_fd;
|
||||
s32 dev_type;
|
||||
} WiiDeviceContext;
|
||||
|
||||
DeviceInfoList* WiiListDevices();
|
||||
|
||||
#endif // DICREMOTE_WII_WII_H_
|
||||
|
||||
33
worker.c
33
worker.c
@@ -28,7 +28,6 @@ void* WorkingLoop(void* arguments)
|
||||
AtaErrorRegistersChs ata_chs_error_regs;
|
||||
AtaErrorRegistersLba28 ata_lba28_error_regs;
|
||||
AtaErrorRegistersLba48 ata_lba48_error_regs;
|
||||
char device_path[1024];
|
||||
char* buffer;
|
||||
char* cdb_buf;
|
||||
char* cid;
|
||||
@@ -59,7 +58,6 @@ void* WorkingLoop(void* arguments)
|
||||
DicPacketResListDevs* pkt_res_devinfo;
|
||||
DicPacketResScsi* pkt_res_scsi;
|
||||
DicPacketResSdhci* pkt_res_sdhci;
|
||||
int device_fd = -1;
|
||||
int skip_next_hdr;
|
||||
int cli_sock, sock_fd;
|
||||
int ret;
|
||||
@@ -72,6 +70,7 @@ void* WorkingLoop(void* arguments)
|
||||
uint32_t sense;
|
||||
uint32_t sense_len;
|
||||
uint64_t n;
|
||||
void* device_ctx = NULL;
|
||||
|
||||
if(!arguments)
|
||||
{
|
||||
@@ -382,17 +381,14 @@ void* WorkingLoop(void* arguments)
|
||||
|
||||
NetRecv(cli_sock, pkt_dev_open, le32toh(pkt_hdr->len), 0);
|
||||
|
||||
device_fd = DeviceOpen(pkt_dev_open->device_path);
|
||||
device_ctx = DeviceOpen(pkt_dev_open->device_path);
|
||||
|
||||
pkt_nop->reason_code =
|
||||
device_fd == -1 ? DICMOTE_PACKET_NOP_REASON_OPEN_ERROR : DICMOTE_PACKET_NOP_REASON_OPEN_OK;
|
||||
device_ctx == NULL ? DICMOTE_PACKET_NOP_REASON_OPEN_ERROR : DICMOTE_PACKET_NOP_REASON_OPEN_OK;
|
||||
pkt_nop->error_no = errno;
|
||||
memset(&pkt_nop->reason, 0, 256);
|
||||
NetWrite(cli_sock, pkt_nop, sizeof(DicPacketNop));
|
||||
|
||||
if(pkt_nop->reason_code == DICMOTE_PACKET_NOP_REASON_OPEN_OK)
|
||||
strncpy(device_path, pkt_dev_open->device_path, 1024);
|
||||
|
||||
free(pkt_dev_open);
|
||||
continue;
|
||||
case DICMOTE_PACKET_TYPE_COMMAND_GET_DEVTYPE:
|
||||
@@ -427,7 +423,7 @@ void* WorkingLoop(void* arguments)
|
||||
pkt_dev_type->hdr.version = DICMOTE_PACKET_VERSION;
|
||||
pkt_dev_type->hdr.remote_id = htole32(DICMOTE_REMOTE_ID);
|
||||
pkt_dev_type->hdr.packet_id = htole32(DICMOTE_PACKET_ID);
|
||||
pkt_dev_type->device_type = htole32(GetDeviceType(device_path));
|
||||
pkt_dev_type->device_type = htole32(GetDeviceType(device_ctx));
|
||||
|
||||
NetWrite(cli_sock, pkt_dev_type, sizeof(DicPacketResGetDeviceType));
|
||||
free(pkt_dev_type);
|
||||
@@ -462,7 +458,7 @@ void* WorkingLoop(void* arguments)
|
||||
// Swap buf_len
|
||||
pkt_cmd_scsi->buf_len = le32toh(pkt_cmd_scsi->buf_len);
|
||||
|
||||
ret = SendScsiCommand(device_fd,
|
||||
ret = SendScsiCommand(device_ctx,
|
||||
cdb_buf,
|
||||
buffer,
|
||||
&sense_buf,
|
||||
@@ -539,7 +535,7 @@ void* WorkingLoop(void* arguments)
|
||||
pkt_res_sdhci_registers->hdr.version = DICMOTE_PACKET_VERSION;
|
||||
pkt_res_sdhci_registers->hdr.packet_type = DICMOTE_PACKET_TYPE_RESPONSE_GET_SDHCI_REGISTERS;
|
||||
pkt_res_sdhci_registers->hdr.len = htole32(sizeof(DicPacketResGetSdhciRegisters));
|
||||
pkt_res_sdhci_registers->is_sdhci = GetSdhciRegisters(device_path,
|
||||
pkt_res_sdhci_registers->is_sdhci = GetSdhciRegisters(device_ctx,
|
||||
&csd,
|
||||
&cid,
|
||||
&ocr,
|
||||
@@ -618,7 +614,7 @@ void* WorkingLoop(void* arguments)
|
||||
pkt_res_usb->hdr.version = DICMOTE_PACKET_VERSION;
|
||||
pkt_res_usb->hdr.packet_type = DICMOTE_PACKET_TYPE_RESPONSE_GET_USB_DATA;
|
||||
pkt_res_usb->hdr.len = htole32(sizeof(DicPacketResGetUsbData));
|
||||
pkt_res_usb->is_usb = GetUsbData(device_path,
|
||||
pkt_res_usb->is_usb = GetUsbData(device_ctx,
|
||||
&pkt_res_usb->desc_len,
|
||||
pkt_res_usb->descriptors,
|
||||
&pkt_res_usb->id_vendor,
|
||||
@@ -664,7 +660,7 @@ void* WorkingLoop(void* arguments)
|
||||
pkt_res_firewire->hdr.version = DICMOTE_PACKET_VERSION;
|
||||
pkt_res_firewire->hdr.packet_type = DICMOTE_PACKET_TYPE_RESPONSE_GET_FIREWIRE_DATA;
|
||||
pkt_res_firewire->hdr.len = htole32(sizeof(DicPacketResGetFireWireData));
|
||||
pkt_res_firewire->is_firewire = GetFireWireData(device_path,
|
||||
pkt_res_firewire->is_firewire = GetFireWireData(device_ctx,
|
||||
&pkt_res_firewire->id_model,
|
||||
&pkt_res_firewire->id_vendor,
|
||||
&pkt_res_firewire->guid,
|
||||
@@ -707,7 +703,7 @@ void* WorkingLoop(void* arguments)
|
||||
pkt_res_pcmcia->hdr.packet_type = DICMOTE_PACKET_TYPE_RESPONSE_GET_PCMCIA_DATA;
|
||||
pkt_res_pcmcia->hdr.len = htole32(sizeof(DicPacketResGetPcmciaData));
|
||||
pkt_res_pcmcia->is_pcmcia =
|
||||
GetPcmciaData(device_path, &pkt_res_pcmcia->cis_len, pkt_res_pcmcia->cis);
|
||||
GetPcmciaData(device_ctx, &pkt_res_pcmcia->cis_len, pkt_res_pcmcia->cis);
|
||||
|
||||
pkt_res_pcmcia->cis_len = htole32(pkt_res_pcmcia->cis_len);
|
||||
|
||||
@@ -742,7 +738,7 @@ void* WorkingLoop(void* arguments)
|
||||
|
||||
duration = 0;
|
||||
sense = 1;
|
||||
ret = SendAtaChsCommand(device_fd,
|
||||
ret = SendAtaChsCommand(device_ctx,
|
||||
pkt_cmd_ata_chs->registers,
|
||||
&ata_chs_error_regs,
|
||||
pkt_cmd_ata_chs->protocol,
|
||||
@@ -814,7 +810,7 @@ void* WorkingLoop(void* arguments)
|
||||
|
||||
duration = 0;
|
||||
sense = 1;
|
||||
ret = SendAtaLba28Command(device_fd,
|
||||
ret = SendAtaLba28Command(device_ctx,
|
||||
pkt_cmd_ata_lba28->registers,
|
||||
&ata_lba28_error_regs,
|
||||
pkt_cmd_ata_lba28->protocol,
|
||||
@@ -892,7 +888,7 @@ void* WorkingLoop(void* arguments)
|
||||
|
||||
duration = 0;
|
||||
sense = 1;
|
||||
ret = SendAtaLba48Command(device_fd,
|
||||
ret = SendAtaLba48Command(device_ctx,
|
||||
pkt_cmd_ata_lba48->registers,
|
||||
&ata_lba48_error_regs,
|
||||
pkt_cmd_ata_lba48->protocol,
|
||||
@@ -969,7 +965,7 @@ void* WorkingLoop(void* arguments)
|
||||
|
||||
duration = 0;
|
||||
sense = 1;
|
||||
ret = SendSdhciCommand(device_fd,
|
||||
ret = SendSdhciCommand(device_ctx,
|
||||
pkt_cmd_sdhci->command,
|
||||
pkt_cmd_sdhci->write,
|
||||
pkt_cmd_sdhci->application,
|
||||
@@ -1020,7 +1016,8 @@ void* WorkingLoop(void* arguments)
|
||||
free(pkt_res_sdhci);
|
||||
continue;
|
||||
case DICMOTE_PACKET_TYPE_COMMAND_CLOSE_DEVICE:
|
||||
DeviceClose(device_fd);
|
||||
DeviceClose(device_ctx);
|
||||
device_ctx = NULL;
|
||||
skip_next_hdr = 1;
|
||||
continue;
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user