mirror of
https://github.com/aaru-dps/aaruremote.git
synced 2025-12-16 19:24:37 +00:00
Remove unneeded slim functions.
This commit is contained in:
156
linux/ata.c
156
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;
|
||||
|
||||
|
||||
174
linux/device.c
174
linux/device.c
@@ -28,15 +28,15 @@
|
||||
#include <libudev.h>
|
||||
#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;
|
||||
}
|
||||
@@ -23,22 +23,22 @@
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
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;
|
||||
|
||||
|
||||
@@ -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_
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
#include <libudev.h>
|
||||
#endif
|
||||
|
||||
DeviceInfoList* LinuxListDevices()
|
||||
DeviceInfoList* ListDevices()
|
||||
{
|
||||
DIR* dir;
|
||||
struct dirent* dirent;
|
||||
|
||||
@@ -24,18 +24,18 @@
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
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;
|
||||
|
||||
28
linux/scsi.c
28
linux/scsi.c
@@ -24,21 +24,21 @@
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
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;
|
||||
|
||||
194
linux/sdhci.c
194
linux/sdhci.c
@@ -20,26 +20,30 @@
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
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;
|
||||
}
|
||||
34
linux/usb.c
34
linux/usb.c
@@ -23,24 +23,24 @@
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user