mirror of
https://github.com/aaru-dps/aaruremote.git
synced 2025-12-16 19:24:37 +00:00
General refactor.
This commit is contained in:
44
ata.c
44
ata.c
@@ -17,33 +17,31 @@
|
||||
|
||||
#include "dicmote.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#if defined(__linux__) && !defined(__ANDROID__)
|
||||
#include "linux/linux.h"
|
||||
#endif
|
||||
|
||||
int32_t SendAtaChsCommand(int device_fd,
|
||||
AtaRegistersChs registers,
|
||||
AtaErrorRegistersChs* errorRegisters,
|
||||
AtaErrorRegistersChs* error_registers,
|
||||
uint8_t protocol,
|
||||
uint8_t transferRegister,
|
||||
uint8_t transfer_register,
|
||||
char* buffer,
|
||||
uint32_t timeout,
|
||||
uint8_t transferBlocks,
|
||||
uint8_t transfer_blocks,
|
||||
uint32_t* duration,
|
||||
uint32_t* sense,
|
||||
uint32_t* buf_len)
|
||||
{
|
||||
#if defined(__linux__) && !defined(__ANDROID__)
|
||||
return linux_send_ata_chs_command(device_fd,
|
||||
return LinuxSendAtaChsCommand(device_fd,
|
||||
registers,
|
||||
errorRegisters,
|
||||
error_registers,
|
||||
protocol,
|
||||
transferRegister,
|
||||
transfer_register,
|
||||
buffer,
|
||||
timeout,
|
||||
transferBlocks,
|
||||
transfer_blocks,
|
||||
duration,
|
||||
sense,
|
||||
buf_len);
|
||||
@@ -54,25 +52,25 @@ int32_t SendAtaChsCommand(int device_fd,
|
||||
|
||||
int32_t SendAtaLba28Command(int device_fd,
|
||||
AtaRegistersLba28 registers,
|
||||
AtaErrorRegistersLba28* errorRegisters,
|
||||
AtaErrorRegistersLba28* error_registers,
|
||||
uint8_t protocol,
|
||||
uint8_t transferRegister,
|
||||
uint8_t transfer_register,
|
||||
char* buffer,
|
||||
uint32_t timeout,
|
||||
uint8_t transferBlocks,
|
||||
uint8_t transfer_blocks,
|
||||
uint32_t* duration,
|
||||
uint32_t* sense,
|
||||
uint32_t* buf_len)
|
||||
{
|
||||
#if defined(__linux__) && !defined(__ANDROID__)
|
||||
return linux_send_ata_lba28_command(device_fd,
|
||||
return LinuxSendAtaLba28Command(device_fd,
|
||||
registers,
|
||||
errorRegisters,
|
||||
error_registers,
|
||||
protocol,
|
||||
transferRegister,
|
||||
transfer_register,
|
||||
buffer,
|
||||
timeout,
|
||||
transferBlocks,
|
||||
transfer_blocks,
|
||||
duration,
|
||||
sense,
|
||||
buf_len);
|
||||
@@ -83,25 +81,25 @@ int32_t SendAtaLba28Command(int device_fd,
|
||||
|
||||
int32_t SendAtaLba48Command(int device_fd,
|
||||
AtaRegistersLba48 registers,
|
||||
AtaErrorRegistersLba48* errorRegisters,
|
||||
AtaErrorRegistersLba48* error_registers,
|
||||
uint8_t protocol,
|
||||
uint8_t transferRegister,
|
||||
uint8_t transfer_register,
|
||||
char* buffer,
|
||||
uint32_t timeout,
|
||||
uint8_t transferBlocks,
|
||||
uint8_t transfer_blocks,
|
||||
uint32_t* duration,
|
||||
uint32_t* sense,
|
||||
uint32_t* buf_len)
|
||||
{
|
||||
#if defined(__linux__) && !defined(__ANDROID__)
|
||||
return linux_send_ata_lba48_command(device_fd,
|
||||
return LinuxSendAtaLba48Command(device_fd,
|
||||
registers,
|
||||
errorRegisters,
|
||||
error_registers,
|
||||
protocol,
|
||||
transferRegister,
|
||||
transfer_register,
|
||||
buffer,
|
||||
timeout,
|
||||
transferBlocks,
|
||||
transfer_blocks,
|
||||
duration,
|
||||
sense,
|
||||
buf_len);
|
||||
|
||||
12
device.c
12
device.c
@@ -19,25 +19,25 @@
|
||||
#include "linux/linux.h"
|
||||
#endif
|
||||
|
||||
int DeviceOpen(const char* devicePath)
|
||||
int DeviceOpen(const char* device_path)
|
||||
{
|
||||
#if defined(__linux__) && !defined(__ANDROID__)
|
||||
return linux_open_device(devicePath);
|
||||
return LinuxOpenDevice(device_path);
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t GetDeviceType(const char* devicePath)
|
||||
int32_t GetDeviceType(const char* device_path)
|
||||
{
|
||||
#if defined(__linux__) && !defined(__ANDROID__)
|
||||
return linux_get_device_type(devicePath);
|
||||
return LinuxGetDeviceType(device_path);
|
||||
#else
|
||||
return DICMOTE_DEVICE_TYPE_UNKNOWN;
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t GetSdhciRegisters(const char* devicePath,
|
||||
int32_t GetSdhciRegisters(const char* device_path,
|
||||
char** csd,
|
||||
char** cid,
|
||||
char** ocr,
|
||||
@@ -48,7 +48,7 @@ int32_t GetSdhciRegisters(const char* devicePath,
|
||||
uint32_t* scr_len)
|
||||
{
|
||||
#if defined(__linux__) && !defined(__ANDROID__)
|
||||
return linux_get_sdhci_registers(devicePath, csd, cid, ocr, scr, csd_len, cid_len, ocr_len, scr_len);
|
||||
return LinuxGetSdhciRegisters(device_path, csd, cid, ocr, scr, csd_len, cid_len, ocr_len, scr_len);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
174
dicmote.h
174
dicmote.h
@@ -15,8 +15,8 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef DICMOTE_H
|
||||
#define DICMOTE_H
|
||||
#ifndef DICREMOTE__DICMOTE_H_
|
||||
#define DICREMOTE__DICMOTE_H_
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
@@ -35,10 +35,10 @@
|
||||
#define DICMOTE_PACKET_TYPE_RESPONSE_SCSI 6
|
||||
#define DICMOTE_PACKET_TYPE_COMMAND_ATA_CHS 7
|
||||
#define DICMOTE_PACKET_TYPE_RESPONSE_ATA_CHS 8
|
||||
#define DICMOTE_PACKET_TYPE_COMMAND_ATA_LBA28 9
|
||||
#define DICMOTE_PACKET_TYPE_RESPONSE_ATA_LBA28 10
|
||||
#define DICMOTE_PACKET_TYPE_COMMAND_ATA_LBA48 11
|
||||
#define DICMOTE_PACKET_TYPE_RESPONSE_ATA_LBA48 12
|
||||
#define DICMOTE_PACKET_TYPE_COMMAND_ATA_LBA_28 9
|
||||
#define DICMOTE_PACKET_TYPE_RESPONSE_ATA_LBA_28 10
|
||||
#define DICMOTE_PACKET_TYPE_COMMAND_ATA_LBA_48 11
|
||||
#define DICMOTE_PACKET_TYPE_RESPONSE_ATA_LBA_48 12
|
||||
#define DICMOTE_PACKET_TYPE_COMMAND_SDHCI 13
|
||||
#define DICMOTE_PACKET_TYPE_RESPONSE_SDHCI 14
|
||||
#define DICMOTE_PACKET_TYPE_COMMAND_GET_DEVTYPE 15
|
||||
@@ -145,7 +145,7 @@ typedef struct
|
||||
uint8_t reason_code;
|
||||
char spare[3];
|
||||
char reason[256];
|
||||
int32_t errorNo;
|
||||
int32_t error_no;
|
||||
} DicPacketNop;
|
||||
|
||||
typedef struct
|
||||
@@ -175,24 +175,24 @@ typedef struct
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t Feature;
|
||||
uint8_t SectorCount;
|
||||
uint8_t Sector;
|
||||
uint8_t CylinderLow;
|
||||
uint8_t CylinderHigh;
|
||||
uint8_t DeviceHead;
|
||||
uint8_t Command;
|
||||
uint8_t feature;
|
||||
uint8_t sector_count;
|
||||
uint8_t sector;
|
||||
uint8_t cylinder_low;
|
||||
uint8_t cylinder_high;
|
||||
uint8_t device_head;
|
||||
uint8_t command;
|
||||
} AtaRegistersChs;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t Status;
|
||||
uint8_t Error;
|
||||
uint8_t SectorCount;
|
||||
uint8_t Sector;
|
||||
uint8_t CylinderLow;
|
||||
uint8_t CylinderHigh;
|
||||
uint8_t DeviceHead;
|
||||
uint8_t status;
|
||||
uint8_t error;
|
||||
uint8_t sector_count;
|
||||
uint8_t sector;
|
||||
uint8_t cylinder_low;
|
||||
uint8_t cylinder_high;
|
||||
uint8_t device_head;
|
||||
} AtaErrorRegistersChs;
|
||||
|
||||
typedef struct
|
||||
@@ -201,8 +201,8 @@ typedef struct
|
||||
uint32_t buf_len;
|
||||
AtaRegistersChs registers;
|
||||
uint8_t protocol;
|
||||
uint8_t transferRegister;
|
||||
uint8_t transferBlocks;
|
||||
uint8_t transfer_register;
|
||||
uint8_t transfer_blocks;
|
||||
uint8_t spare;
|
||||
uint32_t timeout;
|
||||
} DicPacketCmdAtaChs;
|
||||
@@ -219,24 +219,24 @@ typedef struct
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t Feature;
|
||||
uint8_t SectorCount;
|
||||
uint8_t LbaLow;
|
||||
uint8_t LbaMid;
|
||||
uint8_t LbaHigh;
|
||||
uint8_t DeviceHead;
|
||||
uint8_t Command;
|
||||
uint8_t feature;
|
||||
uint8_t sector_count;
|
||||
uint8_t lba_low;
|
||||
uint8_t lba_mid;
|
||||
uint8_t lba_high;
|
||||
uint8_t device_head;
|
||||
uint8_t command;
|
||||
} AtaRegistersLba28;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t Status;
|
||||
uint8_t Error;
|
||||
uint8_t SectorCount;
|
||||
uint8_t LbaLow;
|
||||
uint8_t LbaMid;
|
||||
uint8_t LbaHigh;
|
||||
uint8_t DeviceHead;
|
||||
uint8_t status;
|
||||
uint8_t error;
|
||||
uint8_t sector_count;
|
||||
uint8_t lba_low;
|
||||
uint8_t lba_mid;
|
||||
uint8_t lba_high;
|
||||
uint8_t device_head;
|
||||
} AtaErrorRegistersLba28;
|
||||
|
||||
typedef struct
|
||||
@@ -245,8 +245,8 @@ typedef struct
|
||||
uint32_t buf_len;
|
||||
AtaRegistersLba28 registers;
|
||||
uint8_t protocol;
|
||||
uint8_t transferRegister;
|
||||
uint8_t transferBlocks;
|
||||
uint8_t transfer_register;
|
||||
uint8_t transfer_blocks;
|
||||
uint8_t spare;
|
||||
uint32_t timeout;
|
||||
} DicPacketCmdAtaLba28;
|
||||
@@ -263,24 +263,24 @@ typedef struct
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint16_t Feature;
|
||||
uint16_t SectorCount;
|
||||
uint16_t LbaLow;
|
||||
uint16_t LbaMid;
|
||||
uint16_t LbaHigh;
|
||||
uint8_t DeviceHead;
|
||||
uint8_t Command;
|
||||
uint16_t feature;
|
||||
uint16_t sector_count;
|
||||
uint16_t lba_low;
|
||||
uint16_t lba_mid;
|
||||
uint16_t lba_high;
|
||||
uint8_t device_head;
|
||||
uint8_t command;
|
||||
} AtaRegistersLba48;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t Status;
|
||||
uint8_t Error;
|
||||
uint16_t SectorCount;
|
||||
uint16_t LbaLow;
|
||||
uint16_t LbaMid;
|
||||
uint16_t LbaHigh;
|
||||
uint8_t DeviceHead;
|
||||
uint8_t status;
|
||||
uint8_t error;
|
||||
uint16_t sector_count;
|
||||
uint16_t lba_low;
|
||||
uint16_t lba_mid;
|
||||
uint16_t lba_high;
|
||||
uint8_t device_head;
|
||||
} AtaErrorRegistersLba48;
|
||||
|
||||
typedef struct
|
||||
@@ -289,8 +289,8 @@ typedef struct
|
||||
uint32_t buf_len;
|
||||
AtaRegistersLba48 registers;
|
||||
uint8_t protocol;
|
||||
uint8_t transferRegister;
|
||||
uint8_t transferBlocks;
|
||||
uint8_t transfer_register;
|
||||
uint8_t transfer_blocks;
|
||||
uint8_t spare;
|
||||
uint32_t timeout;
|
||||
} DicPacketCmdAtaLba48;
|
||||
@@ -348,7 +348,7 @@ typedef struct
|
||||
typedef struct
|
||||
{
|
||||
DicPacketHeader hdr;
|
||||
uint8_t isSdhci;
|
||||
uint8_t is_sdhci;
|
||||
char csd[16];
|
||||
char cid[16];
|
||||
char ocr[4];
|
||||
@@ -367,11 +367,11 @@ typedef struct
|
||||
typedef struct
|
||||
{
|
||||
DicPacketHeader hdr;
|
||||
uint8_t isUsb;
|
||||
uint16_t descLen;
|
||||
uint8_t is_usb;
|
||||
uint16_t desc_len;
|
||||
char descriptors[65536];
|
||||
uint16_t idVendor;
|
||||
uint16_t idProduct;
|
||||
uint16_t id_vendor;
|
||||
uint16_t id_product;
|
||||
char manufacturer[256];
|
||||
char product[256];
|
||||
char serial[256];
|
||||
@@ -385,9 +385,9 @@ typedef struct
|
||||
typedef struct
|
||||
{
|
||||
DicPacketHeader hdr;
|
||||
uint8_t isFireWire;
|
||||
uint32_t idModel;
|
||||
uint32_t idVendor;
|
||||
uint8_t is_firewire;
|
||||
uint32_t id_model;
|
||||
uint32_t id_vendor;
|
||||
uint64_t guid;
|
||||
char vendor[256];
|
||||
char model[256];
|
||||
@@ -401,7 +401,7 @@ typedef struct
|
||||
typedef struct
|
||||
{
|
||||
DicPacketHeader hdr;
|
||||
uint8_t isPcmcia;
|
||||
uint8_t is_pcmcia;
|
||||
uint16_t cis_len;
|
||||
char cis[65536];
|
||||
} DicPacketResGetPcmciaData;
|
||||
@@ -411,12 +411,12 @@ typedef struct
|
||||
DeviceInfoList* ListDevices();
|
||||
void FreeDeviceInfoList(DeviceInfoList* start);
|
||||
uint16_t DeviceInfoListCount(DeviceInfoList* start);
|
||||
int DeviceOpen(const char* devicePath);
|
||||
int32_t GetDeviceType(const char* devicePath);
|
||||
int DeviceOpen(const char* device_path);
|
||||
int32_t GetDeviceType(const char* device_path);
|
||||
int32_t SendScsiCommand(int device_fd,
|
||||
char* cdb,
|
||||
char* buffer,
|
||||
char** senseBuffer,
|
||||
char** sense_buffer,
|
||||
uint32_t timeout,
|
||||
int32_t direction,
|
||||
uint32_t* duration,
|
||||
@@ -424,9 +424,9 @@ int32_t SendScsiCommand(int device_fd,
|
||||
uint32_t cdb_len,
|
||||
uint32_t* buf_len,
|
||||
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* devicePath,
|
||||
int Hexchr2Bin(const char hex, char* out);
|
||||
size_t Hexs2Bin(const char* hex, unsigned char** out);
|
||||
int32_t GetSdhciRegisters(const char* device_path,
|
||||
char** csd,
|
||||
char** cid,
|
||||
char** ocr,
|
||||
@@ -435,51 +435,51 @@ int32_t GetSdhciRegisters(const char* devicePath,
|
||||
uint32_t* cid_len,
|
||||
uint32_t* ocr_len,
|
||||
uint32_t* scr_len);
|
||||
uint8_t GetUsbData(const char* devicePath,
|
||||
uint16_t* descLen,
|
||||
uint8_t GetUsbData(const char* device_path,
|
||||
uint16_t* desc_len,
|
||||
char* descriptors,
|
||||
uint16_t* idVendor,
|
||||
uint16_t* idProduct,
|
||||
uint16_t* id_vendor,
|
||||
uint16_t* id_product,
|
||||
char* manufacturer,
|
||||
char* product,
|
||||
char* serial);
|
||||
uint8_t GetFireWireData(const char* devicePath,
|
||||
uint32_t* idModel,
|
||||
uint32_t* idVendor,
|
||||
uint8_t GetFireWireData(const char* device_path,
|
||||
uint32_t* id_model,
|
||||
uint32_t* id_vendor,
|
||||
uint64_t* guid,
|
||||
char* vendor,
|
||||
char* model);
|
||||
uint8_t GetPcmciaData(const char* devicePath, uint16_t* cisLen, char* cis);
|
||||
uint8_t GetPcmciaData(const char* device_path, uint16_t* cis_len, char* cis);
|
||||
int32_t SendAtaChsCommand(int device_fd,
|
||||
AtaRegistersChs registers,
|
||||
AtaErrorRegistersChs* errorRegisters,
|
||||
AtaErrorRegistersChs* error_registers,
|
||||
uint8_t protocol,
|
||||
uint8_t transferRegister,
|
||||
uint8_t transfer_register,
|
||||
char* buffer,
|
||||
uint32_t timeout,
|
||||
uint8_t transferBlocks,
|
||||
uint8_t transfer_blocks,
|
||||
uint32_t* duration,
|
||||
uint32_t* sense,
|
||||
uint32_t* buf_len);
|
||||
int32_t SendAtaLba28Command(int device_fd,
|
||||
AtaRegistersLba28 registers,
|
||||
AtaErrorRegistersLba28* errorRegisters,
|
||||
AtaErrorRegistersLba28* error_registers,
|
||||
uint8_t protocol,
|
||||
uint8_t transferRegister,
|
||||
uint8_t transfer_register,
|
||||
char* buffer,
|
||||
uint32_t timeout,
|
||||
uint8_t transferBlocks,
|
||||
uint8_t transfer_blocks,
|
||||
uint32_t* duration,
|
||||
uint32_t* sense,
|
||||
uint32_t* buf_len);
|
||||
int32_t SendAtaLba48Command(int device_fd,
|
||||
AtaRegistersLba48 registers,
|
||||
AtaErrorRegistersLba48* errorRegisters,
|
||||
AtaErrorRegistersLba48* error_registers,
|
||||
uint8_t protocol,
|
||||
uint8_t transferRegister,
|
||||
uint8_t transfer_register,
|
||||
char* buffer,
|
||||
uint32_t timeout,
|
||||
uint8_t transferBlocks,
|
||||
uint8_t transfer_blocks,
|
||||
uint32_t* duration,
|
||||
uint32_t* sense,
|
||||
uint32_t* buf_len);
|
||||
|
||||
@@ -19,12 +19,11 @@
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
int hexchr2bin(const char hex, char* out)
|
||||
int Hexchr2Bin(const char hex, char* out)
|
||||
{
|
||||
if(out == NULL) return 0;
|
||||
|
||||
if(hex >= '0' && hex <= '9')
|
||||
*out = hex - '0';
|
||||
if(hex >= '0' && hex <= '9') *out = hex - '0';
|
||||
else if(hex >= 'A' && hex <= 'F')
|
||||
*out = hex - 'A' + 10;
|
||||
else if(hex >= 'a' && hex <= 'f')
|
||||
@@ -35,7 +34,7 @@ int hexchr2bin(const char hex, char* out)
|
||||
return 1;
|
||||
}
|
||||
|
||||
size_t hexs2bin(const char* hex, unsigned char** out)
|
||||
size_t Hexs2Bin(const char* hex, unsigned char** out)
|
||||
{
|
||||
size_t len;
|
||||
char b1;
|
||||
@@ -52,7 +51,7 @@ size_t hexs2bin(const char* hex, unsigned char** out)
|
||||
memset(*out, 'A', len);
|
||||
for(i = 0; i < len; i++)
|
||||
{
|
||||
if(!hexchr2bin(hex[i * 2], &b1) || !hexchr2bin(hex[i * 2 + 1], &b2)) return 0;
|
||||
if(!Hexchr2Bin(hex[i * 2], &b1) || !Hexchr2Bin(hex[i * 2 + 1], &b2)) return 0;
|
||||
|
||||
(*out)[i] = (b1 << 4) | b2;
|
||||
}
|
||||
|
||||
@@ -21,15 +21,15 @@
|
||||
#include "linux/linux.h"
|
||||
#endif
|
||||
|
||||
uint8_t GetFireWireData(const char* devicePath,
|
||||
uint32_t* idModel,
|
||||
uint32_t* idVendor,
|
||||
uint8_t GetFireWireData(const char* device_path,
|
||||
uint32_t* id_model,
|
||||
uint32_t* id_vendor,
|
||||
uint64_t* guid,
|
||||
char* vendor,
|
||||
char* model)
|
||||
{
|
||||
#if defined(__linux__) && !defined(__ANDROID__)
|
||||
return linux_get_ieee1394_data(devicePath, idModel, idVendor, guid, vendor, model);
|
||||
return LinuxGetIeee1394Data(device_path, id_model, id_vendor, guid, vendor, model);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
159
linux/ata.c
159
linux/ata.c
@@ -17,11 +17,9 @@
|
||||
|
||||
#include "linux.h"
|
||||
|
||||
#include <scsi/sg.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
int32_t ata_protocol_to_scsi_direction(uint8_t protocol)
|
||||
int32_t AtaProtocolToScsiDirection(uint8_t protocol)
|
||||
{
|
||||
switch(protocol)
|
||||
{
|
||||
@@ -39,14 +37,14 @@ int32_t ata_protocol_to_scsi_direction(uint8_t protocol)
|
||||
}
|
||||
}
|
||||
|
||||
int32_t linux_send_ata_chs_command(int device_fd,
|
||||
int32_t LinuxSendAtaChsCommand(int device_fd,
|
||||
AtaRegistersChs registers,
|
||||
AtaErrorRegistersChs* errorRegisters,
|
||||
AtaErrorRegistersChs* error_registers,
|
||||
uint8_t protocol,
|
||||
uint8_t transferRegister,
|
||||
uint8_t transfer_register,
|
||||
char* buffer,
|
||||
uint32_t timeout,
|
||||
uint8_t transferBlocks,
|
||||
uint8_t transfer_blocks,
|
||||
uint32_t* duration,
|
||||
uint32_t* sense,
|
||||
uint32_t* buf_len)
|
||||
@@ -61,7 +59,7 @@ int32_t linux_send_ata_chs_command(int device_fd,
|
||||
|
||||
cdb[0] = 0x85;
|
||||
cdb[1] = (protocol << 1) & 0x1E;
|
||||
if(transferRegister != DICMOTE_ATA_TRANSFER_REGISTER_NONE && protocol != DICMOTE_ATA_PROTOCOL_NO_DATA)
|
||||
if(transfer_register != DICMOTE_ATA_TRANSFER_REGISTER_NONE && protocol != DICMOTE_ATA_PROTOCOL_NO_DATA)
|
||||
{
|
||||
switch(protocol)
|
||||
{
|
||||
@@ -70,25 +68,25 @@ int32_t linux_send_ata_chs_command(int device_fd,
|
||||
default: cdb[2] = 0x00; break;
|
||||
}
|
||||
|
||||
if(transferBlocks) cdb[2] |= 0x04;
|
||||
if(transfer_blocks) cdb[2] |= 0x04;
|
||||
|
||||
cdb[2] |= (transferRegister & 0x03);
|
||||
cdb[2] |= (transfer_register & 0x03);
|
||||
}
|
||||
|
||||
cdb[4] = registers.Feature;
|
||||
cdb[6] = registers.SectorCount;
|
||||
cdb[8] = registers.Sector;
|
||||
cdb[10] = registers.CylinderLow;
|
||||
cdb[12] = registers.CylinderHigh;
|
||||
cdb[13] = registers.DeviceHead;
|
||||
cdb[14] = registers.Command;
|
||||
cdb[4] = registers.feature;
|
||||
cdb[6] = registers.sector_count;
|
||||
cdb[8] = registers.sector;
|
||||
cdb[10] = registers.cylinder_low;
|
||||
cdb[12] = registers.cylinder_high;
|
||||
cdb[13] = registers.device_head;
|
||||
cdb[14] = registers.command;
|
||||
|
||||
int error = linux_send_scsi_command(device_fd,
|
||||
int error = LinuxSendScsiCommand(device_fd,
|
||||
(char*)cdb,
|
||||
buffer,
|
||||
&sense_buf,
|
||||
timeout,
|
||||
ata_protocol_to_scsi_direction(protocol),
|
||||
AtaProtocolToScsiDirection(protocol),
|
||||
duration,
|
||||
sense,
|
||||
16,
|
||||
@@ -97,28 +95,28 @@ int32_t linux_send_ata_chs_command(int device_fd,
|
||||
|
||||
if(sense_len < 22 || (sense_buf[8] != 0x09 && sense_buf[9] != 0x0C)) return error;
|
||||
|
||||
errorRegisters->Error = sense_buf[11];
|
||||
error_registers->error = sense_buf[11];
|
||||
|
||||
errorRegisters->SectorCount = sense_buf[13];
|
||||
errorRegisters->Sector = sense_buf[15];
|
||||
errorRegisters->CylinderLow = sense_buf[17];
|
||||
errorRegisters->CylinderHigh = sense_buf[19];
|
||||
errorRegisters->DeviceHead = sense_buf[20];
|
||||
errorRegisters->Status = sense_buf[21];
|
||||
error_registers->sector_count = sense_buf[13];
|
||||
error_registers->sector = sense_buf[15];
|
||||
error_registers->cylinder_low = sense_buf[17];
|
||||
error_registers->cylinder_high = sense_buf[19];
|
||||
error_registers->device_head = sense_buf[20];
|
||||
error_registers->status = sense_buf[21];
|
||||
|
||||
*sense = errorRegisters->Error != 0 || (errorRegisters->Status & 0xA5) != 0;
|
||||
*sense = error_registers->error != 0 || (error_registers->status & 0xA5) != 0;
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
int32_t linux_send_ata_lba28_command(int device_fd,
|
||||
int32_t LinuxSendAtaLba28Command(int device_fd,
|
||||
AtaRegistersLba28 registers,
|
||||
AtaErrorRegistersLba28* errorRegisters,
|
||||
AtaErrorRegistersLba28* error_registers,
|
||||
uint8_t protocol,
|
||||
uint8_t transferRegister,
|
||||
uint8_t transfer_register,
|
||||
char* buffer,
|
||||
uint32_t timeout,
|
||||
uint8_t transferBlocks,
|
||||
uint8_t transfer_blocks,
|
||||
uint32_t* duration,
|
||||
uint32_t* sense,
|
||||
uint32_t* buf_len)
|
||||
@@ -133,7 +131,7 @@ int32_t linux_send_ata_lba28_command(int device_fd,
|
||||
|
||||
cdb[0] = 0x85;
|
||||
cdb[1] = (protocol << 1) & 0x1E;
|
||||
if(transferRegister != DICMOTE_ATA_TRANSFER_REGISTER_NONE && protocol != DICMOTE_ATA_PROTOCOL_NO_DATA)
|
||||
if(transfer_register != DICMOTE_ATA_TRANSFER_REGISTER_NONE && protocol != DICMOTE_ATA_PROTOCOL_NO_DATA)
|
||||
{
|
||||
switch(protocol)
|
||||
{
|
||||
@@ -142,27 +140,27 @@ int32_t linux_send_ata_lba28_command(int device_fd,
|
||||
default: cdb[2] = 0x00; break;
|
||||
}
|
||||
|
||||
if(transferBlocks) cdb[2] |= 0x04;
|
||||
if(transfer_blocks) cdb[2] |= 0x04;
|
||||
|
||||
cdb[2] |= (transferRegister & 0x03);
|
||||
cdb[2] |= (transfer_register & 0x03);
|
||||
}
|
||||
|
||||
cdb[2] |= 0x20;
|
||||
|
||||
cdb[4] = registers.Feature;
|
||||
cdb[6] = registers.SectorCount;
|
||||
cdb[8] = registers.LbaLow;
|
||||
cdb[10] = registers.LbaMid;
|
||||
cdb[12] = registers.LbaHigh;
|
||||
cdb[13] = registers.DeviceHead;
|
||||
cdb[14] = registers.Command;
|
||||
cdb[4] = registers.feature;
|
||||
cdb[6] = registers.sector_count;
|
||||
cdb[8] = registers.lba_low;
|
||||
cdb[10] = registers.lba_mid;
|
||||
cdb[12] = registers.lba_high;
|
||||
cdb[13] = registers.device_head;
|
||||
cdb[14] = registers.command;
|
||||
|
||||
int error = linux_send_scsi_command(device_fd,
|
||||
int error = LinuxSendScsiCommand(device_fd,
|
||||
(char*)cdb,
|
||||
buffer,
|
||||
&sense_buf,
|
||||
timeout,
|
||||
ata_protocol_to_scsi_direction(protocol),
|
||||
AtaProtocolToScsiDirection(protocol),
|
||||
duration,
|
||||
sense,
|
||||
16,
|
||||
@@ -171,27 +169,28 @@ int32_t linux_send_ata_lba28_command(int device_fd,
|
||||
|
||||
if(sense_len < 22 || (sense_buf[8] != 0x09 && sense_buf[9] != 0x0C)) return error;
|
||||
|
||||
errorRegisters->Error = sense_buf[11];
|
||||
error_registers->error = sense_buf[11];
|
||||
|
||||
errorRegisters->SectorCount = sense_buf[13];
|
||||
errorRegisters->LbaLow = sense_buf[15];
|
||||
errorRegisters->LbaMid = sense_buf[17];
|
||||
errorRegisters->LbaHigh = sense_buf[19];
|
||||
errorRegisters->DeviceHead = sense_buf[20];
|
||||
errorRegisters->Status = sense_buf[21];
|
||||
error_registers->sector_count = sense_buf[13];
|
||||
error_registers->lba_low = sense_buf[15];
|
||||
error_registers->lba_mid = sense_buf[17];
|
||||
error_registers->lba_high = sense_buf[19];
|
||||
error_registers->device_head = sense_buf[20];
|
||||
error_registers->status = sense_buf[21];
|
||||
|
||||
*sense = errorRegisters->Error != 0 || (errorRegisters->Status & 0xA5) != 0;
|
||||
*sense = error_registers->error != 0 || (error_registers->status & 0xA5) != 0;
|
||||
|
||||
return error;
|
||||
}
|
||||
int32_t linux_send_ata_lba48_command(int device_fd,
|
||||
|
||||
int32_t LinuxSendAtaLba48Command(int device_fd,
|
||||
AtaRegistersLba48 registers,
|
||||
AtaErrorRegistersLba48* errorRegisters,
|
||||
AtaErrorRegistersLba48* error_registers,
|
||||
uint8_t protocol,
|
||||
uint8_t transferRegister,
|
||||
uint8_t transfer_register,
|
||||
char* buffer,
|
||||
uint32_t timeout,
|
||||
uint8_t transferBlocks,
|
||||
uint8_t transfer_blocks,
|
||||
uint32_t* duration,
|
||||
uint32_t* sense,
|
||||
uint32_t* buf_len)
|
||||
@@ -207,7 +206,7 @@ int32_t linux_send_ata_lba48_command(int device_fd,
|
||||
cdb[0] = 0x85;
|
||||
cdb[1] = (protocol << 1) & 0x1E;
|
||||
cdb[1] |= 0x01;
|
||||
if(transferRegister != DICMOTE_ATA_TRANSFER_REGISTER_NONE && protocol != DICMOTE_ATA_PROTOCOL_NO_DATA)
|
||||
if(transfer_register != DICMOTE_ATA_TRANSFER_REGISTER_NONE && protocol != DICMOTE_ATA_PROTOCOL_NO_DATA)
|
||||
{
|
||||
switch(protocol)
|
||||
{
|
||||
@@ -216,32 +215,32 @@ int32_t linux_send_ata_lba48_command(int device_fd,
|
||||
default: cdb[2] = 0x00; break;
|
||||
}
|
||||
|
||||
if(transferBlocks) cdb[2] |= 0x04;
|
||||
if(transfer_blocks) cdb[2] |= 0x04;
|
||||
|
||||
cdb[2] |= (transferRegister & 0x03);
|
||||
cdb[2] |= (transfer_register & 0x03);
|
||||
}
|
||||
|
||||
cdb[2] |= 0x20;
|
||||
|
||||
cdb[3] = ((registers.Feature & 0xFF00) >> 8);
|
||||
cdb[4] = (registers.Feature & 0xFF);
|
||||
cdb[5] = ((registers.SectorCount & 0xFF00) >> 8);
|
||||
cdb[6] = (registers.SectorCount & 0xFF);
|
||||
cdb[7] = ((registers.LbaLow & 0xFF00) >> 8);
|
||||
cdb[8] = (registers.LbaLow & 0xFF);
|
||||
cdb[9] = ((registers.LbaMid & 0xFF00) >> 8);
|
||||
cdb[10] = (registers.LbaMid & 0xFF);
|
||||
cdb[11] = ((registers.LbaHigh & 0xFF00) >> 8);
|
||||
cdb[12] = (registers.LbaHigh & 0xFF);
|
||||
cdb[13] = registers.DeviceHead;
|
||||
cdb[14] = registers.Command;
|
||||
cdb[3] = ((registers.feature & 0xFF00) >> 8);
|
||||
cdb[4] = (registers.feature & 0xFF);
|
||||
cdb[5] = ((registers.sector_count & 0xFF00) >> 8);
|
||||
cdb[6] = (registers.sector_count & 0xFF);
|
||||
cdb[7] = ((registers.lba_low & 0xFF00) >> 8);
|
||||
cdb[8] = (registers.lba_low & 0xFF);
|
||||
cdb[9] = ((registers.lba_mid & 0xFF00) >> 8);
|
||||
cdb[10] = (registers.lba_mid & 0xFF);
|
||||
cdb[11] = ((registers.lba_high & 0xFF00) >> 8);
|
||||
cdb[12] = (registers.lba_high & 0xFF);
|
||||
cdb[13] = registers.device_head;
|
||||
cdb[14] = registers.command;
|
||||
|
||||
int error = linux_send_scsi_command(device_fd,
|
||||
int error = LinuxSendScsiCommand(device_fd,
|
||||
(char*)cdb,
|
||||
buffer,
|
||||
&sense_buf,
|
||||
timeout,
|
||||
ata_protocol_to_scsi_direction(protocol),
|
||||
AtaProtocolToScsiDirection(protocol),
|
||||
duration,
|
||||
sense,
|
||||
16,
|
||||
@@ -250,16 +249,16 @@ int32_t linux_send_ata_lba48_command(int device_fd,
|
||||
|
||||
if(sense_len < 22 || (sense_buf[8] != 0x09 && sense_buf[9] != 0x0C)) return error;
|
||||
|
||||
errorRegisters->Error = sense_buf[11];
|
||||
error_registers->error = sense_buf[11];
|
||||
|
||||
errorRegisters->SectorCount = (uint16_t)((sense_buf[12] << 8) + sense_buf[13]);
|
||||
errorRegisters->LbaLow = (uint16_t)((sense_buf[14] << 8) + sense_buf[15]);
|
||||
errorRegisters->LbaMid = (uint16_t)((sense_buf[16] << 8) + sense_buf[17]);
|
||||
errorRegisters->LbaHigh = (uint16_t)((sense_buf[18] << 8) + sense_buf[19]);
|
||||
errorRegisters->DeviceHead = sense_buf[20];
|
||||
errorRegisters->Status = sense_buf[21];
|
||||
error_registers->sector_count = (uint16_t)((sense_buf[12] << 8) + sense_buf[13]);
|
||||
error_registers->lba_low = (uint16_t)((sense_buf[14] << 8) + sense_buf[15]);
|
||||
error_registers->lba_mid = (uint16_t)((sense_buf[16] << 8) + sense_buf[17]);
|
||||
error_registers->lba_high = (uint16_t)((sense_buf[18] << 8) + sense_buf[19]);
|
||||
error_registers->device_head = sense_buf[20];
|
||||
error_registers->status = sense_buf[21];
|
||||
|
||||
*sense = errorRegisters->Error != 0 || (errorRegisters->Status & 0xA5) != 0;
|
||||
*sense = error_registers->error != 0 || (error_registers->status & 0xA5) != 0;
|
||||
|
||||
return error;
|
||||
}
|
||||
170
linux/device.c
170
linux/device.c
@@ -25,7 +25,7 @@
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int linux_open_device(const char* device_path)
|
||||
int LinuxOpenDevice(const char* device_path)
|
||||
{
|
||||
int fd;
|
||||
|
||||
@@ -36,19 +36,19 @@ int linux_open_device(const char* device_path)
|
||||
return fd;
|
||||
}
|
||||
|
||||
int32_t linux_get_device_type(const char* devicePath)
|
||||
int32_t LinuxGetDeviceType(const char* device_path)
|
||||
{
|
||||
struct udev* udev;
|
||||
struct udev_device* udev_device;
|
||||
const char* tmpString;
|
||||
const char* tmp_string;
|
||||
char* chrptr;
|
||||
int32_t deviceType = DICMOTE_DEVICE_TYPE_UNKNOWN;
|
||||
int32_t device_type = DICMOTE_DEVICE_TYPE_UNKNOWN;
|
||||
|
||||
udev = udev_new();
|
||||
|
||||
if(!udev) return DICMOTE_DEVICE_TYPE_UNKNOWN;
|
||||
|
||||
chrptr = strrchr(devicePath, '/');
|
||||
chrptr = strrchr(device_path, '/');
|
||||
if(chrptr == 0) return DICMOTE_DEVICE_TYPE_UNKNOWN;
|
||||
|
||||
chrptr++;
|
||||
@@ -57,69 +57,69 @@ int32_t linux_get_device_type(const char* devicePath)
|
||||
udev_device = udev_device_new_from_subsystem_sysname(udev, "block", chrptr);
|
||||
if(udev_device)
|
||||
{
|
||||
tmpString = udev_device_get_property_value(udev_device, "ID_BUS");
|
||||
if(tmpString)
|
||||
tmp_string = udev_device_get_property_value(udev_device, "ID_BUS");
|
||||
if(tmp_string)
|
||||
{
|
||||
if(strncmp(tmpString, "ata", 3) == 0)
|
||||
if(strncmp(tmp_string, "ata", 3) == 0)
|
||||
{
|
||||
deviceType = DICMOTE_DEVICE_TYPE_ATA;
|
||||
device_type = DICMOTE_DEVICE_TYPE_ATA;
|
||||
|
||||
free((void*)tmpString);
|
||||
tmpString = udev_device_get_property_value(udev_device, "ID_TYPE");
|
||||
free((void*)tmp_string);
|
||||
tmp_string = udev_device_get_property_value(udev_device, "ID_TYPE");
|
||||
|
||||
if(tmpString)
|
||||
if(tmp_string)
|
||||
{
|
||||
// TODO: ATAPI removable non optical disks
|
||||
if(strncmp(tmpString, "cd", 2) == 0) { deviceType = DICMOTE_DEVICE_TYPE_ATAPI; }
|
||||
if(strncmp(tmp_string, "cd", 2) == 0) { device_type = DICMOTE_DEVICE_TYPE_ATAPI; }
|
||||
|
||||
free((void*)tmpString);
|
||||
free((void*)tmp_string);
|
||||
}
|
||||
}
|
||||
else if(strncmp(tmpString, "mmc", 3) == 0)
|
||||
else if(strncmp(tmp_string, "mmc", 3) == 0)
|
||||
{
|
||||
free((void*)tmpString);
|
||||
tmpString = malloc(1024);
|
||||
free((void*)tmp_string);
|
||||
tmp_string = malloc(1024);
|
||||
|
||||
deviceType = DICMOTE_DEVICE_TYPE_MMC;
|
||||
device_type = DICMOTE_DEVICE_TYPE_MMC;
|
||||
|
||||
if(tmpString)
|
||||
if(tmp_string)
|
||||
{
|
||||
memset((void*)tmpString, 0, 1024);
|
||||
snprintf((char*)tmpString, 1024, "/sys/block/%s/device/scr", chrptr);
|
||||
memset((void*)tmp_string, 0, 1024);
|
||||
snprintf((char*)tmp_string, 1024, "/sys/block/%s/device/scr", chrptr);
|
||||
|
||||
if(access(tmpString, R_OK) == 0) deviceType = DICMOTE_DEVICE_TYPE_SECURE_DIGITAL;
|
||||
if(access(tmp_string, R_OK) == 0) device_type = DICMOTE_DEVICE_TYPE_SECURE_DIGITAL;
|
||||
|
||||
free((void*)tmpString);
|
||||
free((void*)tmp_string);
|
||||
}
|
||||
}
|
||||
else if(strncmp(tmpString, "scsi", 4) == 0 || strncmp(tmpString, "ieee1394", 8) == 0 ||
|
||||
strncmp(tmpString, "usb", 3) == 0)
|
||||
else if(strncmp(tmp_string, "scsi", 4) == 0 || strncmp(tmp_string, "ieee1394", 8) == 0 ||
|
||||
strncmp(tmp_string, "usb", 3) == 0)
|
||||
{
|
||||
free((void*)tmpString);
|
||||
tmpString = udev_device_get_property_value(udev_device, "ID_TYPE");
|
||||
free((void*)tmp_string);
|
||||
tmp_string = udev_device_get_property_value(udev_device, "ID_TYPE");
|
||||
|
||||
if(tmpString)
|
||||
if(tmp_string)
|
||||
{
|
||||
if(strncmp(tmpString, "cd", 2) == 0 || strncmp(tmpString, "disk", 4) == 0)
|
||||
{ deviceType = DICMOTE_DEVICE_TYPE_SCSI; }
|
||||
if(strncmp(tmp_string, "cd", 2) == 0 || strncmp(tmp_string, "disk", 4) == 0)
|
||||
{ device_type = DICMOTE_DEVICE_TYPE_SCSI; }
|
||||
|
||||
free((void*)tmpString);
|
||||
free((void*)tmp_string);
|
||||
}
|
||||
}
|
||||
else if(strncmp(tmpString, "nvme", 4) == 0)
|
||||
else if(strncmp(tmp_string, "nvme", 4) == 0)
|
||||
{
|
||||
free((void*)tmpString);
|
||||
deviceType = DICMOTE_DEVICE_TYPE_NVME;
|
||||
free((void*)tmp_string);
|
||||
device_type = DICMOTE_DEVICE_TYPE_NVME;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
udev_unref(udev);
|
||||
|
||||
return deviceType;
|
||||
return device_type;
|
||||
}
|
||||
|
||||
int32_t linux_get_sdhci_registers(const char* devicePath,
|
||||
int32_t LinuxGetSdhciRegisters(const char* device_path,
|
||||
char** csd,
|
||||
char** cid,
|
||||
char** ocr,
|
||||
@@ -129,11 +129,11 @@ int32_t linux_get_sdhci_registers(const char* devicePath,
|
||||
uint32_t* ocr_len,
|
||||
uint32_t* scr_len)
|
||||
{
|
||||
char* tmpString;
|
||||
char* sysfsPath_csd;
|
||||
char* sysfsPath_cid;
|
||||
char* sysfsPath_scr;
|
||||
char* sysfsPath_ocr;
|
||||
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;
|
||||
@@ -146,47 +146,47 @@ int32_t linux_get_sdhci_registers(const char* devicePath,
|
||||
*scr_len = 0;
|
||||
size_t n = 1026;
|
||||
|
||||
if(strncmp(devicePath, "/dev/mmcblk", 11) != 0) return 0;
|
||||
if(strncmp(device_path, "/dev/mmcblk", 11) != 0) return 0;
|
||||
|
||||
len = strlen(devicePath) + 19;
|
||||
sysfsPath_csd = malloc(len);
|
||||
sysfsPath_cid = malloc(len);
|
||||
sysfsPath_scr = malloc(len);
|
||||
sysfsPath_ocr = malloc(len);
|
||||
tmpString = malloc(1024);
|
||||
len = strlen(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(!sysfsPath_csd || !sysfsPath_cid || !sysfsPath_scr || !sysfsPath_ocr || !tmpString)
|
||||
if(!sysfs_path_csd || !sysfs_path_cid || !sysfs_path_scr || !sysfs_path_ocr || !tmp_string)
|
||||
{
|
||||
free(sysfsPath_csd);
|
||||
free(sysfsPath_cid);
|
||||
free(sysfsPath_scr);
|
||||
free(sysfsPath_ocr);
|
||||
free(tmpString);
|
||||
free(sysfs_path_csd);
|
||||
free(sysfs_path_cid);
|
||||
free(sysfs_path_scr);
|
||||
free(sysfs_path_ocr);
|
||||
free(tmp_string);
|
||||
return 0;
|
||||
}
|
||||
|
||||
memset(sysfsPath_csd, 0, len);
|
||||
memset(sysfsPath_cid, 0, len);
|
||||
memset(sysfsPath_scr, 0, len);
|
||||
memset(sysfsPath_ocr, 0, len);
|
||||
memset(tmpString, 0, strlen(devicePath) - 5);
|
||||
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(device_path) - 5);
|
||||
|
||||
memcpy(tmpString, devicePath + 5, strlen(devicePath) - 5);
|
||||
snprintf(sysfsPath_csd, len, "/sys/block/%s/device/csd", tmpString);
|
||||
snprintf(sysfsPath_cid, len, "/sys/block/%s/device/cid", tmpString);
|
||||
snprintf(sysfsPath_scr, len, "/sys/block/%s/device/scr", tmpString);
|
||||
snprintf(sysfsPath_ocr, len, "/sys/block/%s/device/ocr", tmpString);
|
||||
memcpy(tmp_string, device_path + 5, strlen(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(sysfsPath_csd, R_OK) == 0)
|
||||
if(access(sysfs_path_csd, R_OK) == 0)
|
||||
{
|
||||
file = fopen(sysfsPath_csd, "r");
|
||||
file = fopen(sysfs_path_csd, "r");
|
||||
|
||||
if(file != NULL)
|
||||
{
|
||||
len = getline(&tmpString, &n, file);
|
||||
len = getline(&tmp_string, &n, file);
|
||||
if(len > 0)
|
||||
{
|
||||
*csd_len = hexs2bin(tmpString, (unsigned char**)csd);
|
||||
*csd_len = Hexs2Bin(tmp_string, (unsigned char**)csd);
|
||||
|
||||
if(*csd_len <= 0)
|
||||
{
|
||||
@@ -199,16 +199,16 @@ int32_t linux_get_sdhci_registers(const char* devicePath,
|
||||
}
|
||||
}
|
||||
|
||||
if(access(sysfsPath_cid, R_OK) == 0)
|
||||
if(access(sysfs_path_cid, R_OK) == 0)
|
||||
{
|
||||
file = fopen(sysfsPath_cid, "r");
|
||||
file = fopen(sysfs_path_cid, "r");
|
||||
|
||||
if(file != NULL)
|
||||
{
|
||||
len = getline(&tmpString, &n, file);
|
||||
len = getline(&tmp_string, &n, file);
|
||||
if(len > 0)
|
||||
{
|
||||
*cid_len = hexs2bin(tmpString, (unsigned char**)cid);
|
||||
*cid_len = Hexs2Bin(tmp_string, (unsigned char**)cid);
|
||||
|
||||
if(*cid_len <= 0)
|
||||
{
|
||||
@@ -221,16 +221,16 @@ int32_t linux_get_sdhci_registers(const char* devicePath,
|
||||
}
|
||||
}
|
||||
|
||||
if(access(sysfsPath_scr, R_OK) == 0)
|
||||
if(access(sysfs_path_scr, R_OK) == 0)
|
||||
{
|
||||
file = fopen(sysfsPath_scr, "r");
|
||||
file = fopen(sysfs_path_scr, "r");
|
||||
|
||||
if(file != NULL)
|
||||
{
|
||||
len = getline(&tmpString, &n, file);
|
||||
len = getline(&tmp_string, &n, file);
|
||||
if(len > 0)
|
||||
{
|
||||
*scr_len = hexs2bin(tmpString, (unsigned char**)scr);
|
||||
*scr_len = Hexs2Bin(tmp_string, (unsigned char**)scr);
|
||||
|
||||
if(*scr_len <= 0)
|
||||
{
|
||||
@@ -243,16 +243,16 @@ int32_t linux_get_sdhci_registers(const char* devicePath,
|
||||
}
|
||||
}
|
||||
|
||||
if(access(sysfsPath_ocr, R_OK) == 0)
|
||||
if(access(sysfs_path_ocr, R_OK) == 0)
|
||||
{
|
||||
file = fopen(sysfsPath_ocr, "r");
|
||||
file = fopen(sysfs_path_ocr, "r");
|
||||
|
||||
if(file != NULL)
|
||||
{
|
||||
len = getline(&tmpString, &n, file);
|
||||
len = getline(&tmp_string, &n, file);
|
||||
if(len > 0)
|
||||
{
|
||||
*ocr_len = hexs2bin(tmpString, (unsigned char**)ocr);
|
||||
*ocr_len = Hexs2Bin(tmp_string, (unsigned char**)ocr);
|
||||
|
||||
if(*ocr_len <= 0)
|
||||
{
|
||||
@@ -265,11 +265,11 @@ int32_t linux_get_sdhci_registers(const char* devicePath,
|
||||
}
|
||||
}
|
||||
|
||||
free(sysfsPath_csd);
|
||||
free(sysfsPath_cid);
|
||||
free(sysfsPath_scr);
|
||||
free(sysfsPath_ocr);
|
||||
free(tmpString);
|
||||
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;
|
||||
}
|
||||
108
linux/ieee1394.c
108
linux/ieee1394.c
@@ -15,111 +15,109 @@
|
||||
* 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 linux_get_ieee1394_data(const char* devicePath,
|
||||
uint32_t* idModel,
|
||||
uint32_t* idVendor,
|
||||
uint8_t LinuxGetIeee1394Data(const char* device_path,
|
||||
uint32_t* id_model,
|
||||
uint32_t* id_vendor,
|
||||
uint64_t* guid,
|
||||
char* vendor,
|
||||
char* model)
|
||||
{
|
||||
char* devPath;
|
||||
char tmpPath[4096];
|
||||
char resolvedLink[4096];
|
||||
char* dev_path;
|
||||
char tmp_path[4096];
|
||||
char resolved_link[4096];
|
||||
struct stat sb;
|
||||
ssize_t len;
|
||||
char* rchr;
|
||||
int found;
|
||||
FILE* file;
|
||||
|
||||
*idModel = 0;
|
||||
*idVendor = 0;
|
||||
*id_model = 0;
|
||||
*id_vendor = 0;
|
||||
*guid = 0;
|
||||
memset(tmpPath, 0, 4096);
|
||||
memset(resolvedLink, 0, 4096);
|
||||
memset(tmp_path, 0, 4096);
|
||||
memset(resolved_link, 0, 4096);
|
||||
|
||||
if(strncmp(devicePath, "/dev/sd", 7) != 0 && strncmp(devicePath, "/dev/sr", 7) != 0 &&
|
||||
strncmp(devicePath, "/dev/st", 7) != 0)
|
||||
if(strncmp(device_path, "/dev/sd", 7) != 0 && strncmp(device_path, "/dev/sr", 7) != 0 &&
|
||||
strncmp(device_path, "/dev/st", 7) != 0)
|
||||
return 0;
|
||||
|
||||
devPath = (char*)devicePath + 5;
|
||||
dev_path = (char*)device_path + 5;
|
||||
|
||||
snprintf(tmpPath, 4096, "/sys/block/%s", devPath);
|
||||
snprintf(tmp_path, 4096, "/sys/block/%s", dev_path);
|
||||
|
||||
if(stat(tmpPath, &sb) != 0 || !S_ISDIR(sb.st_mode)) { return 0; }
|
||||
if(stat(tmp_path, &sb) != 0 || !S_ISDIR(sb.st_mode)) { return 0; }
|
||||
|
||||
len = readlink(tmpPath, resolvedLink, 4096);
|
||||
len = readlink(tmp_path, resolved_link, 4096);
|
||||
|
||||
if(len == 0) return 0;
|
||||
|
||||
memset(tmpPath, 0, 4096);
|
||||
snprintf(tmpPath, 4096, "/sys%s", resolvedLink + 2);
|
||||
memcpy(resolvedLink, tmpPath, 4096);
|
||||
memset(tmp_path, 0, 4096);
|
||||
snprintf(tmp_path, 4096, "/sys%s", resolved_link + 2);
|
||||
memcpy(resolved_link, tmp_path, 4096);
|
||||
|
||||
while(strstr(resolvedLink, "firewire") != NULL)
|
||||
while(strstr(resolved_link, "firewire") != NULL)
|
||||
{
|
||||
found = 1;
|
||||
rchr = strrchr(resolvedLink, '/');
|
||||
rchr = strrchr(resolved_link, '/');
|
||||
|
||||
if(rchr == NULL) break;
|
||||
|
||||
*rchr = '\0';
|
||||
|
||||
if(strlen(resolvedLink) == 0) break;
|
||||
if(strlen(resolved_link) == 0) break;
|
||||
|
||||
snprintf(tmpPath, 4096, "%s/model", resolvedLink);
|
||||
if(access(tmpPath, R_OK) != 0) found = 0;
|
||||
memset(tmpPath, 0, 4096);
|
||||
snprintf(tmp_path, 4096, "%s/model", resolved_link);
|
||||
if(access(tmp_path, R_OK) != 0) found = 0;
|
||||
memset(tmp_path, 0, 4096);
|
||||
|
||||
snprintf(tmpPath, 4096, "%s/vendor", resolvedLink);
|
||||
if(access(tmpPath, R_OK) != 0) found = 0;
|
||||
memset(tmpPath, 0, 4096);
|
||||
snprintf(tmp_path, 4096, "%s/vendor", resolved_link);
|
||||
if(access(tmp_path, R_OK) != 0) found = 0;
|
||||
memset(tmp_path, 0, 4096);
|
||||
|
||||
snprintf(tmpPath, 4096, "%s/guid", resolvedLink);
|
||||
if(access(tmpPath, R_OK) != 0) found = 0;
|
||||
memset(tmpPath, 0, 4096);
|
||||
snprintf(tmp_path, 4096, "%s/guid", resolved_link);
|
||||
if(access(tmp_path, R_OK) != 0) found = 0;
|
||||
memset(tmp_path, 0, 4096);
|
||||
|
||||
if(!found) continue;
|
||||
|
||||
memset(tmpPath, 0, 4096);
|
||||
snprintf(tmpPath, 4096, "%s/model", resolvedLink);
|
||||
memset(tmp_path, 0, 4096);
|
||||
snprintf(tmp_path, 4096, "%s/model", resolved_link);
|
||||
|
||||
if(access(tmpPath, R_OK) == 0)
|
||||
if(access(tmp_path, R_OK) == 0)
|
||||
{
|
||||
file = fopen(tmpPath, "r");
|
||||
file = fopen(tmp_path, "r");
|
||||
if(file != NULL)
|
||||
{
|
||||
fscanf(file, "%8x", idModel);
|
||||
fscanf(file, "%8x", id_model);
|
||||
fclose(file);
|
||||
}
|
||||
}
|
||||
|
||||
memset(tmpPath, 0, 4096);
|
||||
snprintf(tmpPath, 4096, "%s/vendor", resolvedLink);
|
||||
memset(tmp_path, 0, 4096);
|
||||
snprintf(tmp_path, 4096, "%s/vendor", resolved_link);
|
||||
|
||||
if(access(tmpPath, R_OK) == 0)
|
||||
if(access(tmp_path, R_OK) == 0)
|
||||
{
|
||||
file = fopen(tmpPath, "r");
|
||||
file = fopen(tmp_path, "r");
|
||||
if(file != NULL)
|
||||
{
|
||||
fscanf(file, "%8x", idVendor);
|
||||
fscanf(file, "%8x", id_vendor);
|
||||
fclose(file);
|
||||
}
|
||||
}
|
||||
|
||||
memset(tmpPath, 0, 4096);
|
||||
snprintf(tmpPath, 4096, "%s/guid", resolvedLink);
|
||||
memset(tmp_path, 0, 4096);
|
||||
snprintf(tmp_path, 4096, "%s/guid", resolved_link);
|
||||
|
||||
if(access(tmpPath, R_OK) == 0)
|
||||
if(access(tmp_path, R_OK) == 0)
|
||||
{
|
||||
file = fopen(tmpPath, "r");
|
||||
file = fopen(tmp_path, "r");
|
||||
if(file != NULL)
|
||||
{
|
||||
fscanf(file, "%16lx", guid);
|
||||
@@ -127,12 +125,12 @@ uint8_t linux_get_ieee1394_data(const char* devicePath,
|
||||
}
|
||||
}
|
||||
|
||||
memset(tmpPath, 0, 4096);
|
||||
snprintf(tmpPath, 4096, "%s/model_name", resolvedLink);
|
||||
memset(tmp_path, 0, 4096);
|
||||
snprintf(tmp_path, 4096, "%s/model_name", resolved_link);
|
||||
|
||||
if(access(tmpPath, R_OK) == 0)
|
||||
if(access(tmp_path, R_OK) == 0)
|
||||
{
|
||||
file = fopen(tmpPath, "r");
|
||||
file = fopen(tmp_path, "r");
|
||||
if(file != NULL)
|
||||
{
|
||||
fread(model, 256, 1, file);
|
||||
@@ -140,12 +138,12 @@ uint8_t linux_get_ieee1394_data(const char* devicePath,
|
||||
}
|
||||
}
|
||||
|
||||
memset(tmpPath, 0, 4096);
|
||||
snprintf(tmpPath, 4096, "%s/vendor_name", resolvedLink);
|
||||
memset(tmp_path, 0, 4096);
|
||||
snprintf(tmp_path, 4096, "%s/vendor_name", resolved_link);
|
||||
|
||||
if(access(tmpPath, R_OK) == 0)
|
||||
if(access(tmp_path, R_OK) == 0)
|
||||
{
|
||||
file = fopen(tmpPath, "r");
|
||||
file = fopen(tmp_path, "r");
|
||||
if(file != NULL)
|
||||
{
|
||||
fread(vendor, 256, 1, file);
|
||||
|
||||
@@ -15,19 +15,23 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef DICREMOTE_LINUX_H
|
||||
#define DICREMOTE_LINUX_H
|
||||
#ifndef DICREMOTE_LINUX_LINUX_H_
|
||||
#define DICREMOTE_LINUX_LINUX_H_
|
||||
|
||||
#include "../dicmote.h"
|
||||
|
||||
#define PATH_SYS_DEVBLOCK "/sys/block"
|
||||
DeviceInfoList* linux_list_devices();
|
||||
int linux_open_device(const char* device_path);
|
||||
int32_t linux_get_device_type(const char* devicePath);
|
||||
int32_t linux_send_scsi_command(int device_fd,
|
||||
|
||||
DeviceInfoList* LinuxListDevices();
|
||||
|
||||
int LinuxOpenDevice(const char* device_path);
|
||||
|
||||
int32_t LinuxGetDeviceType(const char* device_path);
|
||||
|
||||
int32_t LinuxSendScsiCommand(int device_fd,
|
||||
char* cdb,
|
||||
char* buffer,
|
||||
char** senseBuffer,
|
||||
char** sense_buffer,
|
||||
uint32_t timeout,
|
||||
int32_t direction,
|
||||
uint32_t* duration,
|
||||
@@ -35,7 +39,8 @@ int32_t linux_send_scsi_command(int device_fd,
|
||||
uint32_t cdb_len,
|
||||
uint32_t* buf_len,
|
||||
uint32_t* sense_len);
|
||||
int32_t linux_get_sdhci_registers(const char* devicePath,
|
||||
|
||||
int32_t LinuxGetSdhciRegisters(const char* device_path,
|
||||
char** csd,
|
||||
char** cid,
|
||||
char** ocr,
|
||||
@@ -44,55 +49,62 @@ int32_t linux_get_sdhci_registers(const char* devicePath,
|
||||
uint32_t* cid_len,
|
||||
uint32_t* ocr_len,
|
||||
uint32_t* scr_len);
|
||||
uint8_t linux_get_usb_data(const char* devicePath,
|
||||
uint16_t* descLen,
|
||||
|
||||
uint8_t LinuxGetUsbData(const char* device_path,
|
||||
uint16_t* desc_len,
|
||||
char* descriptors,
|
||||
uint16_t* idVendor,
|
||||
uint16_t* idProduct,
|
||||
uint16_t* id_vendor,
|
||||
uint16_t* id_product,
|
||||
char* manufacturer,
|
||||
char* product,
|
||||
char* serial);
|
||||
uint8_t linux_get_ieee1394_data(const char* devicePath,
|
||||
uint32_t* idModel,
|
||||
uint32_t* idVendor,
|
||||
|
||||
uint8_t LinuxGetIeee1394Data(const char* device_path,
|
||||
uint32_t* id_model,
|
||||
uint32_t* id_vendor,
|
||||
uint64_t* guid,
|
||||
char* vendor,
|
||||
char* model);
|
||||
uint8_t linux_get_pcmcia_data(const char* devicePath, uint16_t* cisLen, char* cis);
|
||||
int32_t linux_send_ata_chs_command(int device_fd,
|
||||
|
||||
uint8_t LinuxGetPcmciaData(const char* device_path, uint16_t* cis_len, char* cis);
|
||||
|
||||
int32_t LinuxSendAtaChsCommand(int device_fd,
|
||||
AtaRegistersChs registers,
|
||||
AtaErrorRegistersChs* errorRegisters,
|
||||
AtaErrorRegistersChs* error_registers,
|
||||
uint8_t protocol,
|
||||
uint8_t transferRegister,
|
||||
uint8_t transfer_register,
|
||||
char* buffer,
|
||||
uint32_t timeout,
|
||||
uint8_t transferBlocks,
|
||||
uint8_t transfer_blocks,
|
||||
uint32_t* duration,
|
||||
uint32_t* sense,
|
||||
uint32_t* buf_len);
|
||||
int32_t linux_send_ata_lba28_command(int device_fd,
|
||||
|
||||
int32_t LinuxSendAtaLba28Command(int device_fd,
|
||||
AtaRegistersLba28 registers,
|
||||
AtaErrorRegistersLba28* errorRegisters,
|
||||
AtaErrorRegistersLba28* error_registers,
|
||||
uint8_t protocol,
|
||||
uint8_t transferRegister,
|
||||
uint8_t transfer_register,
|
||||
char* buffer,
|
||||
uint32_t timeout,
|
||||
uint8_t transferBlocks,
|
||||
uint8_t transfer_blocks,
|
||||
uint32_t* duration,
|
||||
uint32_t* sense,
|
||||
uint32_t* buf_len);
|
||||
int32_t linux_send_ata_lba48_command(int device_fd,
|
||||
|
||||
int32_t LinuxSendAtaLba48Command(int device_fd,
|
||||
AtaRegistersLba48 registers,
|
||||
AtaErrorRegistersLba48* errorRegisters,
|
||||
AtaErrorRegistersLba48* error_registers,
|
||||
uint8_t protocol,
|
||||
uint8_t transferRegister,
|
||||
uint8_t transfer_register,
|
||||
char* buffer,
|
||||
uint32_t timeout,
|
||||
uint8_t transferBlocks,
|
||||
uint8_t transfer_blocks,
|
||||
uint32_t* duration,
|
||||
uint32_t* sense,
|
||||
uint32_t* buf_len);
|
||||
int32_t linux_send_sdhci_command(int device_fd,
|
||||
|
||||
int32_t LinuxSendSdhciCommand(int device_fd,
|
||||
uint8_t command,
|
||||
uint8_t write,
|
||||
uint8_t application,
|
||||
@@ -105,4 +117,5 @@ int32_t linux_send_sdhci_command(int device_fd,
|
||||
uint32_t* response,
|
||||
uint32_t* duration,
|
||||
uint32_t* sense);
|
||||
#endif // DICREMOTE_LINUX_H
|
||||
|
||||
#endif // DICREMOTE_LINUX_LINUX_H_
|
||||
|
||||
@@ -28,15 +28,15 @@
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
DeviceInfoList* linux_list_devices()
|
||||
DeviceInfoList* LinuxListDevices()
|
||||
{
|
||||
DIR* dir;
|
||||
struct dirent* dirent;
|
||||
struct udev* udev;
|
||||
int hasUdev = false, i;
|
||||
DeviceInfoList * listStart = NULL, *listCurrent = NULL, *listNext = NULL;
|
||||
int has_udev = false, i;
|
||||
DeviceInfoList * list_start = NULL, *list_current = NULL, *list_next = NULL;
|
||||
struct udev_device* udev_device;
|
||||
const char* tmpString;
|
||||
const char* tmp_string;
|
||||
FILE* file;
|
||||
char* line_str;
|
||||
size_t n, ret;
|
||||
@@ -44,7 +44,7 @@ DeviceInfoList* linux_list_devices()
|
||||
|
||||
udev = udev_new();
|
||||
|
||||
hasUdev = udev != 0;
|
||||
has_udev = udev != 0;
|
||||
|
||||
dir = opendir(PATH_SYS_DEVBLOCK);
|
||||
if(!dir) return NULL;
|
||||
@@ -59,82 +59,82 @@ DeviceInfoList* linux_list_devices()
|
||||
continue;
|
||||
}
|
||||
|
||||
listNext = malloc(sizeof(DeviceInfoList));
|
||||
memset(listNext, 0, sizeof(DeviceInfoList));
|
||||
list_next = malloc(sizeof(DeviceInfoList));
|
||||
memset(list_next, 0, sizeof(DeviceInfoList));
|
||||
|
||||
if(!listNext)
|
||||
if(!list_next)
|
||||
{
|
||||
closedir(dir);
|
||||
|
||||
if(hasUdev) udev_unref(udev);
|
||||
if(has_udev) udev_unref(udev);
|
||||
|
||||
return listStart;
|
||||
return list_start;
|
||||
}
|
||||
|
||||
if(!listStart) listStart = listNext;
|
||||
if(!list_start) list_start = list_next;
|
||||
|
||||
if(listCurrent) listCurrent->next = listNext;
|
||||
if(list_current) list_current->next = list_next;
|
||||
|
||||
snprintf(listNext->this.path, 1024, "/dev/%s", dirent->d_name);
|
||||
snprintf(list_next->this.path, 1024, "/dev/%s", dirent->d_name);
|
||||
|
||||
if(hasUdev)
|
||||
if(has_udev)
|
||||
{
|
||||
udev_device = udev_device_new_from_subsystem_sysname(udev, "block", dirent->d_name);
|
||||
if(udev_device)
|
||||
{
|
||||
tmpString = udev_device_get_property_value(udev_device, "ID_VENDOR");
|
||||
if(tmpString)
|
||||
tmp_string = udev_device_get_property_value(udev_device, "ID_VENDOR");
|
||||
if(tmp_string)
|
||||
{
|
||||
strncpy(listNext->this.vendor, tmpString, 256);
|
||||
free((void*)tmpString);
|
||||
strncpy(list_next->this.vendor, tmp_string, 256);
|
||||
free((void*)tmp_string);
|
||||
}
|
||||
|
||||
tmpString = udev_device_get_property_value(udev_device, "ID_MODEL");
|
||||
if(tmpString)
|
||||
tmp_string = udev_device_get_property_value(udev_device, "ID_MODEL");
|
||||
if(tmp_string)
|
||||
{
|
||||
strncpy(listNext->this.model, tmpString, 256);
|
||||
free((void*)tmpString);
|
||||
strncpy(list_next->this.model, tmp_string, 256);
|
||||
free((void*)tmp_string);
|
||||
|
||||
for(i = 0; i < 256; i++)
|
||||
{
|
||||
if(listNext->this.model[i] == 0) break;
|
||||
if(list_next->this.model[i] == 0) break;
|
||||
|
||||
if(listNext->this.model[i] == '_') listNext->this.model[i] = ' ';
|
||||
if(list_next->this.model[i] == '_') list_next->this.model[i] = ' ';
|
||||
}
|
||||
}
|
||||
|
||||
tmpString = udev_device_get_property_value(udev_device, "ID_SCSI_SERIAL");
|
||||
if(tmpString)
|
||||
tmp_string = udev_device_get_property_value(udev_device, "ID_SCSI_SERIAL");
|
||||
if(tmp_string)
|
||||
{
|
||||
strncpy(listNext->this.serial, tmpString, 256);
|
||||
free((void*)tmpString);
|
||||
strncpy(list_next->this.serial, tmp_string, 256);
|
||||
free((void*)tmp_string);
|
||||
}
|
||||
else
|
||||
{
|
||||
tmpString = udev_device_get_property_value(udev_device, "ID_SERIAL_SHORT");
|
||||
if(tmpString)
|
||||
tmp_string = udev_device_get_property_value(udev_device, "ID_SERIAL_SHORT");
|
||||
if(tmp_string)
|
||||
{
|
||||
strncpy(listNext->this.serial, tmpString, 256);
|
||||
free((void*)tmpString);
|
||||
strncpy(list_next->this.serial, tmp_string, 256);
|
||||
free((void*)tmp_string);
|
||||
}
|
||||
}
|
||||
|
||||
tmpString = udev_device_get_property_value(udev_device, "ID_BUS");
|
||||
if(tmpString)
|
||||
tmp_string = udev_device_get_property_value(udev_device, "ID_BUS");
|
||||
if(tmp_string)
|
||||
{
|
||||
strncpy(listNext->this.bus, tmpString, 256);
|
||||
free((void*)tmpString);
|
||||
strncpy(list_next->this.bus, tmp_string, 256);
|
||||
free((void*)tmp_string);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tmpString = malloc(1024);
|
||||
memset((void*)tmpString, 0, 1024);
|
||||
snprintf((char*)tmpString, 1024, "%s/%s/device/vendor", PATH_SYS_DEVBLOCK, dirent->d_name);
|
||||
tmp_string = malloc(1024);
|
||||
memset((void*)tmp_string, 0, 1024);
|
||||
snprintf((char*)tmp_string, 1024, "%s/%s/device/vendor", PATH_SYS_DEVBLOCK, dirent->d_name);
|
||||
|
||||
if(access(tmpString, R_OK) == 0 && strlen(listNext->this.vendor) == 0)
|
||||
if(access(tmp_string, R_OK) == 0 && strlen(list_next->this.vendor) == 0)
|
||||
{
|
||||
file = fopen(tmpString, "rb");
|
||||
file = fopen(tmp_string, "rb");
|
||||
|
||||
if(file != NULL)
|
||||
{
|
||||
@@ -145,15 +145,14 @@ DeviceInfoList* linux_list_devices()
|
||||
|
||||
if(ret > 0 && line_str != NULL)
|
||||
{
|
||||
strncpy(listNext->this.vendor, line_str, 256);
|
||||
strncpy(list_next->this.vendor, line_str, 256);
|
||||
for(i = 255; i >= 0; i--)
|
||||
{
|
||||
if(listNext->this.vendor[i] == 0)
|
||||
continue;
|
||||
if(list_next->this.vendor[i] == 0) continue;
|
||||
|
||||
else if(listNext->this.vendor[i] == 0x0A || listNext->this.vendor[i] == 0x0D ||
|
||||
listNext->this.vendor[i] == ' ')
|
||||
listNext->this.vendor[i] = 0;
|
||||
else if(list_next->this.vendor[i] == 0x0A || list_next->this.vendor[i] == 0x0D ||
|
||||
list_next->this.vendor[i] == ' ')
|
||||
list_next->this.vendor[i] = 0;
|
||||
else
|
||||
break;
|
||||
}
|
||||
@@ -165,18 +164,18 @@ DeviceInfoList* linux_list_devices()
|
||||
}
|
||||
else if(strncmp(dirent->d_name, "loop", 4) == 0)
|
||||
{
|
||||
strncpy(listNext->this.vendor, "Linux", 256);
|
||||
strncpy(list_next->this.vendor, "Linux", 256);
|
||||
}
|
||||
free((void*)tmpString);
|
||||
free((void*)tmp_string);
|
||||
|
||||
tmpString = malloc(1024);
|
||||
memset((void*)tmpString, 0, 1024);
|
||||
snprintf((char*)tmpString, 1024, "%s/%s/device/model", PATH_SYS_DEVBLOCK, dirent->d_name);
|
||||
tmp_string = malloc(1024);
|
||||
memset((void*)tmp_string, 0, 1024);
|
||||
snprintf((char*)tmp_string, 1024, "%s/%s/device/model", PATH_SYS_DEVBLOCK, dirent->d_name);
|
||||
|
||||
if(access(tmpString, R_OK) == 0 &&
|
||||
(strlen(listNext->this.model) == 0 || strncmp(listNext->this.bus, "ata", 3) == 0))
|
||||
if(access(tmp_string, R_OK) == 0 &&
|
||||
(strlen(list_next->this.model) == 0 || strncmp(list_next->this.bus, "ata", 3) == 0))
|
||||
{
|
||||
file = fopen(tmpString, "rb");
|
||||
file = fopen(tmp_string, "rb");
|
||||
|
||||
if(file != NULL)
|
||||
{
|
||||
@@ -187,15 +186,14 @@ DeviceInfoList* linux_list_devices()
|
||||
|
||||
if(ret > 0 && line_str != NULL)
|
||||
{
|
||||
strncpy(listNext->this.model, line_str, 256);
|
||||
strncpy(list_next->this.model, line_str, 256);
|
||||
for(i = 255; i >= 0; i--)
|
||||
{
|
||||
if(listNext->this.model[i] == 0)
|
||||
continue;
|
||||
if(list_next->this.model[i] == 0) continue;
|
||||
|
||||
else if(listNext->this.model[i] == 0x0A || listNext->this.model[i] == 0x0D ||
|
||||
listNext->this.model[i] == ' ')
|
||||
listNext->this.model[i] = 0;
|
||||
else if(list_next->this.model[i] == 0x0A || list_next->this.model[i] == 0x0D ||
|
||||
list_next->this.model[i] == ' ')
|
||||
list_next->this.model[i] = 0;
|
||||
else
|
||||
break;
|
||||
}
|
||||
@@ -207,17 +205,17 @@ DeviceInfoList* linux_list_devices()
|
||||
}
|
||||
else if(strncmp(dirent->d_name, "loop", 4) == 0)
|
||||
{
|
||||
strncpy(listNext->this.model, "Linux", 256);
|
||||
strncpy(list_next->this.model, "Linux", 256);
|
||||
}
|
||||
free((void*)tmpString);
|
||||
free((void*)tmp_string);
|
||||
|
||||
tmpString = malloc(1024);
|
||||
memset((void*)tmpString, 0, 1024);
|
||||
snprintf((char*)tmpString, 1024, "%s/%s/device/serial", PATH_SYS_DEVBLOCK, dirent->d_name);
|
||||
tmp_string = malloc(1024);
|
||||
memset((void*)tmp_string, 0, 1024);
|
||||
snprintf((char*)tmp_string, 1024, "%s/%s/device/serial", PATH_SYS_DEVBLOCK, dirent->d_name);
|
||||
|
||||
if(access(tmpString, R_OK) == 0 && (strlen(listNext->this.serial) == 0))
|
||||
if(access(tmp_string, R_OK) == 0 && (strlen(list_next->this.serial) == 0))
|
||||
{
|
||||
file = fopen(tmpString, "rb");
|
||||
file = fopen(tmp_string, "rb");
|
||||
|
||||
if(file != NULL)
|
||||
{
|
||||
@@ -228,15 +226,14 @@ DeviceInfoList* linux_list_devices()
|
||||
|
||||
if(ret > 0 && line_str != NULL)
|
||||
{
|
||||
strncpy(listNext->this.serial, line_str, 256);
|
||||
strncpy(list_next->this.serial, line_str, 256);
|
||||
for(i = 255; i >= 0; i--)
|
||||
{
|
||||
if(listNext->this.serial[i] == 0)
|
||||
continue;
|
||||
if(list_next->this.serial[i] == 0) continue;
|
||||
|
||||
else if(listNext->this.serial[i] == 0x0A || listNext->this.serial[i] == 0x0D ||
|
||||
listNext->this.serial[i] == ' ')
|
||||
listNext->this.serial[i] = 0;
|
||||
else if(list_next->this.serial[i] == 0x0A || list_next->this.serial[i] == 0x0D ||
|
||||
list_next->this.serial[i] == ' ')
|
||||
list_next->this.serial[i] = 0;
|
||||
else
|
||||
break;
|
||||
}
|
||||
@@ -246,64 +243,63 @@ DeviceInfoList* linux_list_devices()
|
||||
fclose(file);
|
||||
}
|
||||
}
|
||||
free((void*)tmpString);
|
||||
free((void*)tmp_string);
|
||||
|
||||
if(strlen(listNext->this.vendor) == 0 || strncmp(listNext->this.vendor, "ATA", 3) == 0)
|
||||
if(strlen(list_next->this.vendor) == 0 || strncmp(list_next->this.vendor, "ATA", 3) == 0)
|
||||
{
|
||||
if(strlen(listNext->this.model) > 0)
|
||||
if(strlen(list_next->this.model) > 0)
|
||||
{
|
||||
tmpString = malloc(256);
|
||||
strncpy((void*)tmpString, listNext->this.model, 256);
|
||||
tmp_string = malloc(256);
|
||||
strncpy((void*)tmp_string, list_next->this.model, 256);
|
||||
|
||||
chrptr = strchr(tmpString, ' ');
|
||||
chrptr = strchr(tmp_string, ' ');
|
||||
|
||||
if(chrptr)
|
||||
{
|
||||
memset(&listNext->this.vendor, 0, 256);
|
||||
memset(&listNext->this.model, 0, 256);
|
||||
strncpy(listNext->this.vendor, tmpString, chrptr - tmpString);
|
||||
strncpy(listNext->this.model, chrptr + 1, 256 - (chrptr - tmpString) - 1);
|
||||
memset(&list_next->this.vendor, 0, 256);
|
||||
memset(&list_next->this.model, 0, 256);
|
||||
strncpy(list_next->this.vendor, tmp_string, chrptr - tmp_string);
|
||||
strncpy(list_next->this.model, chrptr + 1, 256 - (chrptr - tmp_string) - 1);
|
||||
}
|
||||
|
||||
free((void*)tmpString);
|
||||
free((void*)tmp_string);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Get better device type from sysfs paths
|
||||
if(strlen(listNext->this.bus) == 0)
|
||||
if(strlen(list_next->this.bus) == 0)
|
||||
{
|
||||
if(strncmp(dirent->d_name, "loop", 4) == 0)
|
||||
strncpy(listNext->this.bus, "loop", 4);
|
||||
if(strncmp(dirent->d_name, "loop", 4) == 0) strncpy(list_next->this.bus, "loop", 4);
|
||||
else if(strncmp(dirent->d_name, "nvme", 4) == 0)
|
||||
strncpy(listNext->this.bus, "NVMe", 4);
|
||||
strncpy(list_next->this.bus, "NVMe", 4);
|
||||
else if(strncmp(dirent->d_name, "mmc", 3) == 0)
|
||||
strncpy(listNext->this.bus, "MMC/SD", 6);
|
||||
strncpy(list_next->this.bus, "MMC/SD", 6);
|
||||
}
|
||||
else
|
||||
{
|
||||
for(i = 0; i < 256; i++)
|
||||
{
|
||||
if(listNext->this.bus[i] == 0) break;
|
||||
if(list_next->this.bus[i] == 0) break;
|
||||
|
||||
listNext->this.bus[i] = (char)toupper(listNext->this.bus[i]);
|
||||
list_next->this.bus[i] = (char)toupper(list_next->this.bus[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if(strncmp(listNext->this.bus, "ATA", 3) == 0 || strncmp(listNext->this.bus, "ATAPI", 5) == 0 ||
|
||||
strncmp(listNext->this.bus, "SCSI", 4) == 0 || strncmp(listNext->this.bus, "USB", 3) == 0 ||
|
||||
strncmp(listNext->this.bus, "PCMCIA", 6) == 0 || strncmp(listNext->this.bus, "FireWire", 8) == 0 ||
|
||||
strncmp(listNext->this.bus, "MMC/SD", 6) == 0)
|
||||
listNext->this.supported = true;
|
||||
if(strncmp(list_next->this.bus, "ATA", 3) == 0 || strncmp(list_next->this.bus, "ATAPI", 5) == 0 ||
|
||||
strncmp(list_next->this.bus, "SCSI", 4) == 0 || strncmp(list_next->this.bus, "USB", 3) == 0 ||
|
||||
strncmp(list_next->this.bus, "PCMCIA", 6) == 0 || strncmp(list_next->this.bus, "FireWire", 8) == 0 ||
|
||||
strncmp(list_next->this.bus, "MMC/SD", 6) == 0)
|
||||
list_next->this.supported = true;
|
||||
else
|
||||
listNext->this.supported = false;
|
||||
list_next->this.supported = false;
|
||||
|
||||
listCurrent = listNext;
|
||||
list_current = list_next;
|
||||
dirent = readdir(dir);
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
|
||||
if(hasUdev) udev_unref(udev);
|
||||
if(has_udev) udev_unref(udev);
|
||||
|
||||
return listStart;
|
||||
return list_start;
|
||||
}
|
||||
@@ -15,8 +15,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "linux.h"
|
||||
|
||||
#include <dirent.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
@@ -24,55 +22,55 @@
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
uint8_t linux_get_pcmcia_data(const char* devicePath, uint16_t* cisLen, char* cis)
|
||||
uint8_t LinuxGetPcmciaData(const char* device_path, uint16_t* cis_len, char* cis)
|
||||
{
|
||||
char* devPath;
|
||||
char tmpPath[4096];
|
||||
char resolvedLink[4096];
|
||||
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;
|
||||
*cisLen = 0;
|
||||
*cis_len = 0;
|
||||
|
||||
memset(tmpPath, 0, 4096);
|
||||
memset(resolvedLink, 0, 4096);
|
||||
memset(tmp_path, 0, 4096);
|
||||
memset(resolved_link, 0, 4096);
|
||||
|
||||
if(strncmp(devicePath, "/dev/sd", 7) != 0 && strncmp(devicePath, "/dev/sr", 7) != 0 &&
|
||||
strncmp(devicePath, "/dev/st", 7) != 0)
|
||||
if(strncmp(device_path, "/dev/sd", 7) != 0 && strncmp(device_path, "/dev/sr", 7) != 0 &&
|
||||
strncmp(device_path, "/dev/st", 7) != 0)
|
||||
return 0;
|
||||
|
||||
devPath = (char*)devicePath + 5;
|
||||
dev_path = (char*)device_path + 5;
|
||||
|
||||
snprintf(tmpPath, 4096, "/sys/block/%s", devPath);
|
||||
snprintf(tmp_path, 4096, "/sys/block/%s", dev_path);
|
||||
|
||||
if(stat(tmpPath, &sb) != 0 || !S_ISDIR(sb.st_mode)) { return 0; }
|
||||
if(stat(tmp_path, &sb) != 0 || !S_ISDIR(sb.st_mode)) { return 0; }
|
||||
|
||||
len = readlink(tmpPath, resolvedLink, 4096);
|
||||
len = readlink(tmp_path, resolved_link, 4096);
|
||||
|
||||
if(len == 0) return 0;
|
||||
|
||||
memset(tmpPath, 0, 4096);
|
||||
snprintf(tmpPath, 4096, "/sys%s", resolvedLink + 2);
|
||||
memcpy(resolvedLink, tmpPath, 4096);
|
||||
memset(tmp_path, 0, 4096);
|
||||
snprintf(tmp_path, 4096, "/sys%s", resolved_link + 2);
|
||||
memcpy(resolved_link, tmp_path, 4096);
|
||||
|
||||
while(strstr(resolvedLink, "/sys/devices") != NULL)
|
||||
while(strstr(resolved_link, "/sys/devices") != NULL)
|
||||
{
|
||||
rchr = strrchr(resolvedLink, '/');
|
||||
rchr = strrchr(resolved_link, '/');
|
||||
|
||||
if(rchr == NULL) break;
|
||||
|
||||
*rchr = '\0';
|
||||
|
||||
if(strlen(resolvedLink) == 0) break;
|
||||
if(strlen(resolved_link) == 0) break;
|
||||
|
||||
memset(tmpPath, 0, 4096);
|
||||
snprintf(tmpPath, 4096, "%s/pcmcia_socket", resolvedLink);
|
||||
if(access(tmpPath, R_OK) != 0) continue;
|
||||
memset(tmp_path, 0, 4096);
|
||||
snprintf(tmp_path, 4096, "%s/pcmcia_socket", resolved_link);
|
||||
if(access(tmp_path, R_OK) != 0) continue;
|
||||
|
||||
dir = opendir(tmpPath);
|
||||
dir = opendir(tmp_path);
|
||||
if(!dir) continue;
|
||||
|
||||
do
|
||||
@@ -85,14 +83,14 @@ uint8_t linux_get_pcmcia_data(const char* devicePath, uint16_t* cisLen, char* ci
|
||||
|
||||
if(!dent) continue;
|
||||
|
||||
memset(tmpPath, 0, 4096);
|
||||
snprintf(tmpPath, 4096, "%s/pcmcia_socket/%s/cis", resolvedLink, dent->d_name);
|
||||
if(access(tmpPath, R_OK) != 0) continue;
|
||||
memset(tmp_path, 0, 4096);
|
||||
snprintf(tmp_path, 4096, "%s/pcmcia_socket/%s/cis", resolved_link, dent->d_name);
|
||||
if(access(tmp_path, R_OK) != 0) continue;
|
||||
|
||||
file = fopen(tmpPath, "r");
|
||||
file = fopen(tmp_path, "r");
|
||||
if(!file) return 0;
|
||||
|
||||
*cisLen = fread(cis, 65536, 1, file);
|
||||
*cis_len = fread(cis, 65536, 1, file);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
10
linux/scsi.c
10
linux/scsi.c
@@ -23,10 +23,10 @@
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
int32_t linux_send_scsi_command(int device_fd,
|
||||
int32_t LinuxSendScsiCommand(int device_fd,
|
||||
char* cdb,
|
||||
char* buffer,
|
||||
char** senseBuffer,
|
||||
char** sense_buffer,
|
||||
uint32_t timeout,
|
||||
int32_t direction,
|
||||
uint32_t* duration,
|
||||
@@ -40,9 +40,9 @@ int32_t linux_send_scsi_command(int device_fd,
|
||||
*sense_len = 32;
|
||||
|
||||
memset(&hdr, 0, sizeof(sg_io_hdr_t));
|
||||
*senseBuffer = malloc(*sense_len);
|
||||
*sense_buffer = malloc(*sense_len);
|
||||
|
||||
if(!*senseBuffer) return -1;
|
||||
if(!*sense_buffer) return -1;
|
||||
|
||||
switch(direction)
|
||||
{
|
||||
@@ -61,7 +61,7 @@ int32_t linux_send_scsi_command(int device_fd,
|
||||
hdr.dxfer_len = *buf_len;
|
||||
hdr.dxferp = buffer;
|
||||
hdr.cmdp = (unsigned char*)cdb;
|
||||
hdr.sbp = (unsigned char*)*senseBuffer;
|
||||
hdr.sbp = (unsigned char*)*sense_buffer;
|
||||
hdr.timeout = timeout;
|
||||
hdr.flags = SG_FLAG_DIRECT_IO;
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
int32_t linux_send_sdhci_command(int device_fd,
|
||||
int32_t LinuxSendSdhciCommand(int device_fd,
|
||||
uint8_t command,
|
||||
uint8_t write,
|
||||
uint8_t application,
|
||||
|
||||
118
linux/usb.c
118
linux/usb.c
@@ -23,114 +23,114 @@
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
uint8_t linux_get_usb_data(const char* devicePath,
|
||||
uint16_t* descLen,
|
||||
uint8_t LinuxGetUsbData(const char* device_path,
|
||||
uint16_t* desc_len,
|
||||
char* descriptors,
|
||||
uint16_t* idVendor,
|
||||
uint16_t* idProduct,
|
||||
uint16_t* id_vendor,
|
||||
uint16_t* id_product,
|
||||
char* manufacturer,
|
||||
char* product,
|
||||
char* serial)
|
||||
{
|
||||
char* devPath;
|
||||
char tmpPath[4096];
|
||||
char resolvedLink[4096];
|
||||
char* dev_path;
|
||||
char tmp_path[4096];
|
||||
char resolved_link[4096];
|
||||
struct stat sb;
|
||||
ssize_t len;
|
||||
char* rchr;
|
||||
int found = 1;
|
||||
FILE* file;
|
||||
|
||||
*descLen = 0;
|
||||
*idVendor = 0;
|
||||
*idProduct = 0;
|
||||
memset(tmpPath, 0, 4096);
|
||||
memset(resolvedLink, 0, 4096);
|
||||
*desc_len = 0;
|
||||
*id_vendor = 0;
|
||||
*id_product = 0;
|
||||
memset(tmp_path, 0, 4096);
|
||||
memset(resolved_link, 0, 4096);
|
||||
|
||||
if(strncmp(devicePath, "/dev/sd", 7) != 0 && strncmp(devicePath, "/dev/sr", 7) != 0 &&
|
||||
strncmp(devicePath, "/dev/st", 7) != 0)
|
||||
if(strncmp(device_path, "/dev/sd", 7) != 0 && strncmp(device_path, "/dev/sr", 7) != 0 &&
|
||||
strncmp(device_path, "/dev/st", 7) != 0)
|
||||
return 0;
|
||||
|
||||
devPath = (char*)devicePath + 5;
|
||||
dev_path = (char*)device_path + 5;
|
||||
|
||||
snprintf(tmpPath, 4096, "/sys/block/%s", devPath);
|
||||
snprintf(tmp_path, 4096, "/sys/block/%s", dev_path);
|
||||
|
||||
if(stat(tmpPath, &sb) != 0 || !S_ISDIR(sb.st_mode)) { return 0; }
|
||||
if(stat(tmp_path, &sb) != 0 || !S_ISDIR(sb.st_mode)) { return 0; }
|
||||
|
||||
len = readlink(tmpPath, resolvedLink, 4096);
|
||||
len = readlink(tmp_path, resolved_link, 4096);
|
||||
|
||||
if(len == 0) return 0;
|
||||
|
||||
memset(tmpPath, 0, 4096);
|
||||
snprintf(tmpPath, 4096, "/sys%s", resolvedLink + 2);
|
||||
memcpy(resolvedLink, tmpPath, 4096);
|
||||
memset(tmp_path, 0, 4096);
|
||||
snprintf(tmp_path, 4096, "/sys%s", resolved_link + 2);
|
||||
memcpy(resolved_link, tmp_path, 4096);
|
||||
|
||||
while(strstr(resolvedLink, "usb") != NULL)
|
||||
while(strstr(resolved_link, "usb") != NULL)
|
||||
{
|
||||
found = 1;
|
||||
rchr = strrchr(resolvedLink, '/');
|
||||
rchr = strrchr(resolved_link, '/');
|
||||
|
||||
if(rchr == NULL) break;
|
||||
|
||||
*rchr = '\0';
|
||||
|
||||
if(strlen(resolvedLink) == 0) break;
|
||||
if(strlen(resolved_link) == 0) break;
|
||||
|
||||
snprintf(tmpPath, 4096, "%s/descriptors", resolvedLink);
|
||||
if(access(tmpPath, R_OK) != 0) found = 0;
|
||||
memset(tmpPath, 0, 4096);
|
||||
snprintf(tmp_path, 4096, "%s/descriptors", resolved_link);
|
||||
if(access(tmp_path, R_OK) != 0) found = 0;
|
||||
memset(tmp_path, 0, 4096);
|
||||
|
||||
snprintf(tmpPath, 4096, "%s/idProduct", resolvedLink);
|
||||
if(access(tmpPath, R_OK) != 0) found = 0;
|
||||
memset(tmpPath, 0, 4096);
|
||||
snprintf(tmp_path, 4096, "%s/idProduct", resolved_link);
|
||||
if(access(tmp_path, R_OK) != 0) found = 0;
|
||||
memset(tmp_path, 0, 4096);
|
||||
|
||||
snprintf(tmpPath, 4096, "%s/idVendor", resolvedLink);
|
||||
if(access(tmpPath, R_OK) != 0) found = 0;
|
||||
memset(tmpPath, 0, 4096);
|
||||
snprintf(tmp_path, 4096, "%s/idVendor", resolved_link);
|
||||
if(access(tmp_path, R_OK) != 0) found = 0;
|
||||
memset(tmp_path, 0, 4096);
|
||||
|
||||
if(!found) continue;
|
||||
|
||||
snprintf(tmpPath, 4096, "%s/descriptors", resolvedLink);
|
||||
file = fopen(tmpPath, "r");
|
||||
snprintf(tmp_path, 4096, "%s/descriptors", resolved_link);
|
||||
file = fopen(tmp_path, "r");
|
||||
|
||||
if(file == NULL) break;
|
||||
|
||||
*descLen = (uint16_t)fread(descriptors, 4096, 1, file);
|
||||
*desc_len = (uint16_t)fread(descriptors, 4096, 1, file);
|
||||
|
||||
fclose(file);
|
||||
|
||||
memset(tmpPath, 0, 4096);
|
||||
snprintf(tmpPath, 4096, "%s/idProduct", resolvedLink);
|
||||
memset(tmp_path, 0, 4096);
|
||||
snprintf(tmp_path, 4096, "%s/idProduct", resolved_link);
|
||||
|
||||
if(access(tmpPath, R_OK) == 0)
|
||||
if(access(tmp_path, R_OK) == 0)
|
||||
{
|
||||
file = fopen(tmpPath, "r");
|
||||
file = fopen(tmp_path, "r");
|
||||
if(file != NULL)
|
||||
{
|
||||
fscanf(file, "%4hx", idProduct);
|
||||
fscanf(file, "%4hx", id_product);
|
||||
fclose(file);
|
||||
}
|
||||
}
|
||||
|
||||
memset(tmpPath, 0, 4096);
|
||||
snprintf(tmpPath, 4096, "%s/idVendor", resolvedLink);
|
||||
memset(tmp_path, 0, 4096);
|
||||
snprintf(tmp_path, 4096, "%s/idVendor", resolved_link);
|
||||
|
||||
if(access(tmpPath, R_OK) == 0)
|
||||
if(access(tmp_path, R_OK) == 0)
|
||||
{
|
||||
file = fopen(tmpPath, "r");
|
||||
file = fopen(tmp_path, "r");
|
||||
if(file != NULL)
|
||||
{
|
||||
fscanf(file, "%4hx", idVendor);
|
||||
fscanf(file, "%4hx", id_vendor);
|
||||
fclose(file);
|
||||
}
|
||||
}
|
||||
|
||||
memset(tmpPath, 0, 4096);
|
||||
snprintf(tmpPath, 4096, "%s/manufacturer", resolvedLink);
|
||||
memset(tmp_path, 0, 4096);
|
||||
snprintf(tmp_path, 4096, "%s/manufacturer", resolved_link);
|
||||
|
||||
if(access(tmpPath, R_OK) == 0)
|
||||
if(access(tmp_path, R_OK) == 0)
|
||||
{
|
||||
file = fopen(tmpPath, "r");
|
||||
file = fopen(tmp_path, "r");
|
||||
if(file != NULL)
|
||||
{
|
||||
fread(manufacturer, 256, 1, file);
|
||||
@@ -138,12 +138,12 @@ uint8_t linux_get_usb_data(const char* devicePath,
|
||||
}
|
||||
}
|
||||
|
||||
memset(tmpPath, 0, 4096);
|
||||
snprintf(tmpPath, 4096, "%s/product", resolvedLink);
|
||||
memset(tmp_path, 0, 4096);
|
||||
snprintf(tmp_path, 4096, "%s/product", resolved_link);
|
||||
|
||||
if(access(tmpPath, R_OK) == 0)
|
||||
if(access(tmp_path, R_OK) == 0)
|
||||
{
|
||||
file = fopen(tmpPath, "r");
|
||||
file = fopen(tmp_path, "r");
|
||||
if(file != NULL)
|
||||
{
|
||||
fread(product, 256, 1, file);
|
||||
@@ -151,12 +151,12 @@ uint8_t linux_get_usb_data(const char* devicePath,
|
||||
}
|
||||
}
|
||||
|
||||
memset(tmpPath, 0, 4096);
|
||||
snprintf(tmpPath, 4096, "%s/serial", resolvedLink);
|
||||
memset(tmp_path, 0, 4096);
|
||||
snprintf(tmp_path, 4096, "%s/serial", resolved_link);
|
||||
|
||||
if(access(tmpPath, R_OK) == 0)
|
||||
if(access(tmp_path, R_OK) == 0)
|
||||
{
|
||||
file = fopen(tmpPath, "r");
|
||||
file = fopen(tmp_path, "r");
|
||||
if(file != NULL)
|
||||
{
|
||||
fread(serial, 256, 1, file);
|
||||
@@ -167,5 +167,5 @@ uint8_t linux_get_usb_data(const char* devicePath,
|
||||
break;
|
||||
}
|
||||
|
||||
return *descLen != 0;
|
||||
return *desc_len != 0;
|
||||
}
|
||||
|
||||
@@ -21,13 +21,12 @@
|
||||
#include "linux/linux.h"
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
DeviceInfoList* ListDevices()
|
||||
{
|
||||
#if defined(__linux__) && !defined(__ANDROID__)
|
||||
return linux_list_devices();
|
||||
return LinuxListDevices();
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
|
||||
275
main.c
275
main.c
@@ -29,57 +29,57 @@
|
||||
|
||||
int main()
|
||||
{
|
||||
struct ifaddrs* ifa;
|
||||
struct ifaddrs* ifa_start;
|
||||
int ret;
|
||||
char ipv4Address[INET_ADDRSTRLEN];
|
||||
int sockfd, cli_sock;
|
||||
struct sockaddr_in serv_addr, cli_addr;
|
||||
socklen_t cli_len;
|
||||
struct utsname utsname;
|
||||
DicPacketHello * pkt_server_hello, *pkt_client_hello;
|
||||
DicPacketHeader* pkt_hdr;
|
||||
ssize_t recv_size;
|
||||
char* in_buf;
|
||||
int skip_next_hdr;
|
||||
struct DeviceInfoList* deviceInfoList;
|
||||
DicPacketResListDevs* deviceInfoResponsePacket;
|
||||
int i;
|
||||
uint64_t n;
|
||||
DicPacketNop* pkt_nop;
|
||||
DicPacketCmdOpen* pkt_dev_open;
|
||||
int device_fd = -1;
|
||||
char device_path[1024];
|
||||
DicPacketResGetDeviceType* pkt_dev_type;
|
||||
DicPacketCmdScsi* pkt_cmd_scsi;
|
||||
char* sense_buf;
|
||||
char* buffer;
|
||||
char* cdb_buf;
|
||||
uint32_t duration;
|
||||
uint32_t sense;
|
||||
uint32_t sense_len;
|
||||
char* out_buf;
|
||||
DicPacketResScsi* pkt_res_scsi;
|
||||
DicPacketResGetSdhciRegisters* sdhciRegsResponsePacket;
|
||||
char* csd;
|
||||
char* cid;
|
||||
char* ocr;
|
||||
char* scr;
|
||||
DicPacketResGetUsbData* pkt_res_usb;
|
||||
DicPacketResGetFireWireData* pkt_res_firewire;
|
||||
DicPacketResGetPcmciaData* pkt_res_pcmcia;
|
||||
DicPacketCmdAtaChs* pkt_cmd_ata_chs;
|
||||
DicPacketCmdAtaLba28* pkt_cmd_ata_lba28;
|
||||
DicPacketCmdAtaLba48* pkt_cmd_ata_lba48;
|
||||
DicPacketResAtaChs* pkt_res_ata_chs;
|
||||
DicPacketResAtaLba28* pkt_res_ata_lba28;
|
||||
DicPacketResAtaLba48* pkt_res_ata_lba48;
|
||||
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;
|
||||
char* csd;
|
||||
char* in_buf;
|
||||
char* ocr;
|
||||
char* out_buf;
|
||||
char* scr;
|
||||
char* sense_buf;
|
||||
char ipv4_address[INET_ADDRSTRLEN];
|
||||
DicPacketCmdAtaChs* pkt_cmd_ata_chs;
|
||||
DicPacketCmdAtaLba28* pkt_cmd_ata_lba28;
|
||||
DicPacketCmdAtaLba48* pkt_cmd_ata_lba48;
|
||||
DicPacketCmdOpen* pkt_dev_open;
|
||||
DicPacketCmdScsi* pkt_cmd_scsi;
|
||||
DicPacketCmdSdhci* pkt_cmd_sdhci;
|
||||
DicPacketHeader* pkt_hdr;
|
||||
DicPacketHello* pkt_server_hello;
|
||||
DicPacketHello* pkt_client_hello;
|
||||
DicPacketNop* pkt_nop;
|
||||
DicPacketResAtaChs* pkt_res_ata_chs;
|
||||
DicPacketResAtaLba28* pkt_res_ata_lba28;
|
||||
DicPacketResAtaLba48* pkt_res_ata_lba48;
|
||||
DicPacketResGetDeviceType* pkt_dev_type;
|
||||
DicPacketResGetFireWireData* pkt_res_firewire;
|
||||
DicPacketResGetPcmciaData* pkt_res_pcmcia;
|
||||
DicPacketResGetSdhciRegisters* pkt_res_sdhci_registers;
|
||||
DicPacketResGetUsbData* pkt_res_usb;
|
||||
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;
|
||||
socklen_t cli_len;
|
||||
ssize_t recv_size;
|
||||
struct DeviceInfoList* device_info_list;
|
||||
struct ifaddrs* ifa;
|
||||
struct ifaddrs* ifa_start;
|
||||
struct sockaddr_in cli_addr, serv_addr;
|
||||
struct utsname utsname;
|
||||
uint32_t duration;
|
||||
uint32_t sdhci_response[4];
|
||||
uint32_t sense;
|
||||
uint32_t sense_len;
|
||||
uint64_t n;
|
||||
|
||||
printf("DiscImageChef Remote Server %s\n", DICMOTE_VERSION);
|
||||
printf("Copyright (C) 2019 Natalia Portillo\n");
|
||||
@@ -95,8 +95,8 @@ int main()
|
||||
printf("Running under %s %s (%s).\n", utsname.sysname, utsname.release, utsname.machine);
|
||||
|
||||
printf("Opening socket.\n");
|
||||
sockfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if(sockfd < 0)
|
||||
sock_fd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if(sock_fd < 0)
|
||||
{
|
||||
printf("Error %d opening socket.\n", errno);
|
||||
return 1;
|
||||
@@ -106,10 +106,10 @@ int main()
|
||||
serv_addr.sin_addr.s_addr = INADDR_ANY;
|
||||
serv_addr.sin_port = htons(DICMOTE_PORT);
|
||||
|
||||
if(bind(sockfd, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0)
|
||||
if(bind(sock_fd, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0)
|
||||
{
|
||||
printf("Error %d binding socket.\n", errno);
|
||||
close(sockfd);
|
||||
close(sock_fd);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -128,8 +128,8 @@ int main()
|
||||
{
|
||||
if(ifa->ifa_addr && ifa->ifa_addr->sa_family == AF_INET)
|
||||
{
|
||||
inet_ntop(AF_INET, &((struct sockaddr_in*)ifa->ifa_addr)->sin_addr, ipv4Address, INET_ADDRSTRLEN);
|
||||
printf("%s port %d\n", ipv4Address, DICMOTE_PORT);
|
||||
inet_ntop(AF_INET, &((struct sockaddr_in*)ifa->ifa_addr)->sin_addr, ipv4_address, INET_ADDRSTRLEN);
|
||||
printf("%s port %d\n", ipv4_address, DICMOTE_PORT);
|
||||
}
|
||||
|
||||
ifa = ifa->ifa_next;
|
||||
@@ -137,12 +137,12 @@ int main()
|
||||
|
||||
freeifaddrs(ifa_start);
|
||||
|
||||
ret = listen(sockfd, 1);
|
||||
ret = listen(sock_fd, 1);
|
||||
|
||||
if(ret)
|
||||
{
|
||||
printf("Error %d listening.\n", errno);
|
||||
close(sockfd);
|
||||
close(sock_fd);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ int main()
|
||||
if(!pkt_server_hello)
|
||||
{
|
||||
printf("Fatal error %d allocating memory.\n", errno);
|
||||
close(sockfd);
|
||||
close(sock_fd);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -173,7 +173,7 @@ int main()
|
||||
if(!pkt_nop)
|
||||
{
|
||||
printf("Fatal error %d allocating memory.\n", errno);
|
||||
close(sockfd);
|
||||
close(sock_fd);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -190,17 +190,17 @@ int main()
|
||||
printf("Waiting for a client...\n");
|
||||
|
||||
cli_len = sizeof(cli_addr);
|
||||
cli_sock = accept(sockfd, (struct sockaddr*)&cli_addr, &cli_len);
|
||||
cli_sock = accept(sock_fd, (struct sockaddr*)&cli_addr, &cli_len);
|
||||
|
||||
if(cli_sock < 0)
|
||||
{
|
||||
printf("Error %d accepting incoming connection.\n", errno);
|
||||
close(sockfd);
|
||||
close(sock_fd);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inet_ntop(AF_INET, &cli_addr.sin_addr, ipv4Address, INET_ADDRSTRLEN);
|
||||
printf("Client %s connected successfully.\n", ipv4Address);
|
||||
inet_ntop(AF_INET, &cli_addr.sin_addr, ipv4_address, INET_ADDRSTRLEN);
|
||||
printf("Client %s connected successfully.\n", ipv4_address);
|
||||
|
||||
write(cli_sock, pkt_server_hello, sizeof(DicPacketHello));
|
||||
|
||||
@@ -210,7 +210,7 @@ int main()
|
||||
{
|
||||
printf("Fatal error %d allocating memory.\n", errno);
|
||||
close(cli_sock);
|
||||
close(sockfd);
|
||||
close(sock_fd);
|
||||
free(pkt_server_hello);
|
||||
return 1;
|
||||
}
|
||||
@@ -352,7 +352,7 @@ int main()
|
||||
skip_next_hdr = 1;
|
||||
continue;
|
||||
case DICMOTE_PACKET_TYPE_COMMAND_LIST_DEVICES:
|
||||
deviceInfoList = ListDevices();
|
||||
device_info_list = ListDevices();
|
||||
|
||||
// Packet only contains header so, dummy
|
||||
in_buf = malloc(pkt_hdr->len);
|
||||
@@ -368,7 +368,7 @@ int main()
|
||||
recv(cli_sock, in_buf, pkt_hdr->len, 0);
|
||||
free(in_buf);
|
||||
|
||||
if(!deviceInfoList)
|
||||
if(!device_info_list)
|
||||
{
|
||||
pkt_nop->reason_code = DICMOTE_PACKET_NOP_REASON_ERROR_LIST_DEVICES;
|
||||
memset(&pkt_nop->reason, 0, 256);
|
||||
@@ -378,44 +378,43 @@ int main()
|
||||
continue;
|
||||
}
|
||||
|
||||
deviceInfoResponsePacket = malloc(sizeof(DicPacketResListDevs));
|
||||
deviceInfoResponsePacket->devices = DeviceInfoListCount(deviceInfoList);
|
||||
pkt_res_devinfo = malloc(sizeof(DicPacketResListDevs));
|
||||
pkt_res_devinfo->devices = DeviceInfoListCount(device_info_list);
|
||||
|
||||
n = sizeof(DicPacketResListDevs) + deviceInfoResponsePacket->devices * sizeof(DeviceInfo);
|
||||
n = sizeof(DicPacketResListDevs) + pkt_res_devinfo->devices * sizeof(DeviceInfo);
|
||||
in_buf = malloc(n);
|
||||
((DicPacketResListDevs*)in_buf)->hdr.len = n;
|
||||
((DicPacketResListDevs*)in_buf)->devices = deviceInfoResponsePacket->devices;
|
||||
free(deviceInfoResponsePacket);
|
||||
deviceInfoResponsePacket = (DicPacketResListDevs*)in_buf;
|
||||
in_buf = NULL;
|
||||
((DicPacketResListDevs*)in_buf)->devices = pkt_res_devinfo->devices;
|
||||
free(pkt_res_devinfo);
|
||||
pkt_res_devinfo = (DicPacketResListDevs*)in_buf;
|
||||
|
||||
deviceInfoResponsePacket->hdr.id = DICMOTE_PACKET_ID;
|
||||
deviceInfoResponsePacket->hdr.version = DICMOTE_PACKET_VERSION;
|
||||
deviceInfoResponsePacket->hdr.packet_type = DICMOTE_PACKET_TYPE_RESPONSE_LIST_DEVICES;
|
||||
pkt_res_devinfo->hdr.id = DICMOTE_PACKET_ID;
|
||||
pkt_res_devinfo->hdr.version = DICMOTE_PACKET_VERSION;
|
||||
pkt_res_devinfo->hdr.packet_type = DICMOTE_PACKET_TYPE_RESPONSE_LIST_DEVICES;
|
||||
|
||||
// Save list start
|
||||
in_buf = (char*)deviceInfoList;
|
||||
in_buf = (char*)device_info_list;
|
||||
long off = sizeof(DicPacketResListDevs);
|
||||
|
||||
while(deviceInfoList)
|
||||
while(device_info_list)
|
||||
{
|
||||
memcpy(((char*)deviceInfoResponsePacket) + off, &deviceInfoList->this, sizeof(DeviceInfo));
|
||||
deviceInfoList = deviceInfoList->next;
|
||||
memcpy(((char*)pkt_res_devinfo) + off, &device_info_list->this, sizeof(DeviceInfo));
|
||||
device_info_list = device_info_list->next;
|
||||
off += sizeof(DeviceInfo);
|
||||
}
|
||||
|
||||
deviceInfoList = (struct DeviceInfoList*)in_buf;
|
||||
FreeDeviceInfoList(deviceInfoList);
|
||||
device_info_list = (struct DeviceInfoList*)in_buf;
|
||||
FreeDeviceInfoList(device_info_list);
|
||||
|
||||
write(cli_sock, deviceInfoResponsePacket, deviceInfoResponsePacket->hdr.len);
|
||||
free(deviceInfoResponsePacket);
|
||||
write(cli_sock, pkt_res_devinfo, pkt_res_devinfo->hdr.len);
|
||||
free(pkt_res_devinfo);
|
||||
continue;
|
||||
case DICMOTE_PACKET_TYPE_RESPONSE_GET_SDHCI_REGISTERS:
|
||||
case DICMOTE_PACKET_TYPE_RESPONSE_LIST_DEVICES:
|
||||
case DICMOTE_PACKET_TYPE_RESPONSE_SCSI:
|
||||
case DICMOTE_PACKET_TYPE_RESPONSE_ATA_CHS:
|
||||
case DICMOTE_PACKET_TYPE_RESPONSE_ATA_LBA28:
|
||||
case DICMOTE_PACKET_TYPE_RESPONSE_ATA_LBA48:
|
||||
case DICMOTE_PACKET_TYPE_RESPONSE_ATA_LBA_28:
|
||||
case DICMOTE_PACKET_TYPE_RESPONSE_ATA_LBA_48:
|
||||
case DICMOTE_PACKET_TYPE_RESPONSE_SDHCI:
|
||||
case DICMOTE_PACKET_TYPE_RESPONSE_GET_DEVTYPE:
|
||||
case DICMOTE_PACKET_TYPE_RESPONSE_GET_USB_DATA:
|
||||
@@ -445,7 +444,7 @@ int main()
|
||||
|
||||
pkt_nop->reason_code =
|
||||
device_fd == -1 ? DICMOTE_PACKET_NOP_REASON_OPEN_ERROR : DICMOTE_PACKET_NOP_REASON_OPEN_OK;
|
||||
pkt_nop->errorNo = errno;
|
||||
pkt_nop->error_no = errno;
|
||||
memset(&pkt_nop->reason, 0, 256);
|
||||
write(cli_sock, pkt_nop, sizeof(DicPacketNop));
|
||||
|
||||
@@ -508,13 +507,11 @@ int main()
|
||||
|
||||
// TODO: Check size of buffers + size of packet is not bigger than size in header
|
||||
|
||||
if(pkt_cmd_scsi->cdb_len > 0)
|
||||
cdb_buf = in_buf + sizeof(DicPacketCmdScsi);
|
||||
if(pkt_cmd_scsi->cdb_len > 0) cdb_buf = in_buf + sizeof(DicPacketCmdScsi);
|
||||
else
|
||||
cdb_buf = NULL;
|
||||
|
||||
if(pkt_cmd_scsi->buf_len > 0)
|
||||
buffer = in_buf + pkt_cmd_scsi->cdb_len + sizeof(DicPacketCmdScsi);
|
||||
if(pkt_cmd_scsi->buf_len > 0) buffer = in_buf + pkt_cmd_scsi->cdb_len + sizeof(DicPacketCmdScsi);
|
||||
else
|
||||
buffer = NULL;
|
||||
|
||||
@@ -576,8 +573,8 @@ int main()
|
||||
recv(cli_sock, in_buf, pkt_hdr->len, 0);
|
||||
free(in_buf);
|
||||
|
||||
sdhciRegsResponsePacket = malloc(sizeof(DicPacketResGetSdhciRegisters));
|
||||
if(!sdhciRegsResponsePacket)
|
||||
pkt_res_sdhci_registers = malloc(sizeof(DicPacketResGetSdhciRegisters));
|
||||
if(!pkt_res_sdhci_registers)
|
||||
{
|
||||
printf("Fatal error %d allocating memory for packet, closing connection...\n", errno);
|
||||
free(pkt_hdr);
|
||||
@@ -585,44 +582,44 @@ int main()
|
||||
continue;
|
||||
}
|
||||
|
||||
memset(sdhciRegsResponsePacket, 0, sizeof(DicPacketResGetSdhciRegisters));
|
||||
sdhciRegsResponsePacket->hdr.id = DICMOTE_PACKET_ID;
|
||||
sdhciRegsResponsePacket->hdr.version = DICMOTE_PACKET_VERSION;
|
||||
sdhciRegsResponsePacket->hdr.packet_type = DICMOTE_PACKET_TYPE_RESPONSE_GET_SDHCI_REGISTERS;
|
||||
sdhciRegsResponsePacket->hdr.len = sizeof(DicPacketResGetSdhciRegisters);
|
||||
sdhciRegsResponsePacket->isSdhci = GetSdhciRegisters(device_path,
|
||||
memset(pkt_res_sdhci_registers, 0, sizeof(DicPacketResGetSdhciRegisters));
|
||||
pkt_res_sdhci_registers->hdr.id = DICMOTE_PACKET_ID;
|
||||
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 = sizeof(DicPacketResGetSdhciRegisters);
|
||||
pkt_res_sdhci_registers->is_sdhci = GetSdhciRegisters(device_path,
|
||||
&csd,
|
||||
&cid,
|
||||
&ocr,
|
||||
&scr,
|
||||
&sdhciRegsResponsePacket->csd_len,
|
||||
&sdhciRegsResponsePacket->cid_len,
|
||||
&sdhciRegsResponsePacket->ocr_len,
|
||||
&sdhciRegsResponsePacket->scr_len);
|
||||
&pkt_res_sdhci_registers->csd_len,
|
||||
&pkt_res_sdhci_registers->cid_len,
|
||||
&pkt_res_sdhci_registers->ocr_len,
|
||||
&pkt_res_sdhci_registers->scr_len);
|
||||
|
||||
if(sdhciRegsResponsePacket->csd_len > 0 && csd != NULL)
|
||||
if(pkt_res_sdhci_registers->csd_len > 0 && csd != NULL)
|
||||
{
|
||||
if(sdhciRegsResponsePacket->csd_len > 16) sdhciRegsResponsePacket->csd_len = 16;
|
||||
if(pkt_res_sdhci_registers->csd_len > 16) pkt_res_sdhci_registers->csd_len = 16;
|
||||
|
||||
memcpy(sdhciRegsResponsePacket->csd, csd, sdhciRegsResponsePacket->csd_len);
|
||||
memcpy(pkt_res_sdhci_registers->csd, csd, pkt_res_sdhci_registers->csd_len);
|
||||
}
|
||||
if(sdhciRegsResponsePacket->cid_len > 0 && cid != NULL)
|
||||
if(pkt_res_sdhci_registers->cid_len > 0 && cid != NULL)
|
||||
{
|
||||
if(sdhciRegsResponsePacket->cid_len > 16) sdhciRegsResponsePacket->cid_len = 16;
|
||||
if(pkt_res_sdhci_registers->cid_len > 16) pkt_res_sdhci_registers->cid_len = 16;
|
||||
|
||||
memcpy(sdhciRegsResponsePacket->cid, cid, sdhciRegsResponsePacket->cid_len);
|
||||
memcpy(pkt_res_sdhci_registers->cid, cid, pkt_res_sdhci_registers->cid_len);
|
||||
}
|
||||
if(sdhciRegsResponsePacket->ocr_len > 0 && ocr != NULL)
|
||||
if(pkt_res_sdhci_registers->ocr_len > 0 && ocr != NULL)
|
||||
{
|
||||
if(sdhciRegsResponsePacket->ocr_len > 4) sdhciRegsResponsePacket->ocr_len = 4;
|
||||
if(pkt_res_sdhci_registers->ocr_len > 4) pkt_res_sdhci_registers->ocr_len = 4;
|
||||
|
||||
memcpy(sdhciRegsResponsePacket->ocr, ocr, sdhciRegsResponsePacket->ocr_len);
|
||||
memcpy(pkt_res_sdhci_registers->ocr, ocr, pkt_res_sdhci_registers->ocr_len);
|
||||
}
|
||||
if(sdhciRegsResponsePacket->scr_len > 0 && scr != NULL)
|
||||
if(pkt_res_sdhci_registers->scr_len > 0 && scr != NULL)
|
||||
{
|
||||
if(sdhciRegsResponsePacket->scr_len > 8) sdhciRegsResponsePacket->scr_len = 8;
|
||||
if(pkt_res_sdhci_registers->scr_len > 8) pkt_res_sdhci_registers->scr_len = 8;
|
||||
|
||||
memcpy(sdhciRegsResponsePacket->scr, scr, sdhciRegsResponsePacket->scr_len);
|
||||
memcpy(pkt_res_sdhci_registers->scr, scr, pkt_res_sdhci_registers->scr_len);
|
||||
}
|
||||
|
||||
free(csd);
|
||||
@@ -630,8 +627,8 @@ int main()
|
||||
free(scr);
|
||||
free(ocr);
|
||||
|
||||
write(cli_sock, sdhciRegsResponsePacket, sdhciRegsResponsePacket->hdr.len);
|
||||
free(sdhciRegsResponsePacket);
|
||||
write(cli_sock, pkt_res_sdhci_registers, pkt_res_sdhci_registers->hdr.len);
|
||||
free(pkt_res_sdhci_registers);
|
||||
continue;
|
||||
case DICMOTE_PACKET_TYPE_COMMAND_GET_USB_DATA:
|
||||
// Packet only contains header so, dummy
|
||||
@@ -662,11 +659,11 @@ int main()
|
||||
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 = sizeof(DicPacketResGetUsbData);
|
||||
pkt_res_usb->isUsb = GetUsbData(device_path,
|
||||
&pkt_res_usb->descLen,
|
||||
pkt_res_usb->is_usb = GetUsbData(device_path,
|
||||
&pkt_res_usb->desc_len,
|
||||
pkt_res_usb->descriptors,
|
||||
&pkt_res_usb->idVendor,
|
||||
&pkt_res_usb->idProduct,
|
||||
&pkt_res_usb->id_vendor,
|
||||
&pkt_res_usb->id_product,
|
||||
pkt_res_usb->manufacturer,
|
||||
pkt_res_usb->product,
|
||||
pkt_res_usb->serial);
|
||||
@@ -703,9 +700,9 @@ int main()
|
||||
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 = sizeof(DicPacketResGetFireWireData);
|
||||
pkt_res_firewire->isFireWire = GetFireWireData(device_path,
|
||||
&pkt_res_firewire->idModel,
|
||||
&pkt_res_firewire->idVendor,
|
||||
pkt_res_firewire->is_firewire = GetFireWireData(device_path,
|
||||
&pkt_res_firewire->id_model,
|
||||
&pkt_res_firewire->id_vendor,
|
||||
&pkt_res_firewire->guid,
|
||||
pkt_res_firewire->vendor,
|
||||
pkt_res_firewire->model);
|
||||
@@ -742,7 +739,7 @@ int main()
|
||||
pkt_res_pcmcia->hdr.version = DICMOTE_PACKET_VERSION;
|
||||
pkt_res_pcmcia->hdr.packet_type = DICMOTE_PACKET_TYPE_RESPONSE_GET_PCMCIA_DATA;
|
||||
pkt_res_pcmcia->hdr.len = sizeof(DicPacketResGetPcmciaData);
|
||||
pkt_res_pcmcia->isPcmcia =
|
||||
pkt_res_pcmcia->is_pcmcia =
|
||||
GetPcmciaData(device_path, &pkt_res_pcmcia->cis_len, pkt_res_pcmcia->cis);
|
||||
|
||||
write(cli_sock, pkt_res_pcmcia, pkt_res_pcmcia->hdr.len);
|
||||
@@ -766,8 +763,7 @@ int main()
|
||||
|
||||
// TODO: Check size of buffers + size of packet is not bigger than size in header
|
||||
|
||||
if(pkt_cmd_ata_chs->buf_len > 0)
|
||||
buffer = in_buf + sizeof(DicPacketCmdAtaChs);
|
||||
if(pkt_cmd_ata_chs->buf_len > 0) buffer = in_buf + sizeof(DicPacketCmdAtaChs);
|
||||
else
|
||||
buffer = NULL;
|
||||
|
||||
@@ -779,10 +775,10 @@ int main()
|
||||
pkt_cmd_ata_chs->registers,
|
||||
&ata_chs_error_regs,
|
||||
pkt_cmd_ata_chs->protocol,
|
||||
pkt_cmd_ata_chs->transferRegister,
|
||||
pkt_cmd_ata_chs->transfer_register,
|
||||
buffer,
|
||||
pkt_cmd_ata_chs->timeout,
|
||||
pkt_cmd_ata_chs->transferBlocks,
|
||||
pkt_cmd_ata_chs->transfer_blocks,
|
||||
&duration,
|
||||
&sense,
|
||||
&pkt_cmd_ata_chs->buf_len);
|
||||
@@ -816,7 +812,7 @@ int main()
|
||||
free(pkt_cmd_ata_chs);
|
||||
free(pkt_res_ata_chs);
|
||||
continue;
|
||||
case DICMOTE_PACKET_TYPE_COMMAND_ATA_LBA28:
|
||||
case DICMOTE_PACKET_TYPE_COMMAND_ATA_LBA_28:
|
||||
// Packet contains data after
|
||||
in_buf = malloc(pkt_hdr->len);
|
||||
|
||||
@@ -834,8 +830,7 @@ int main()
|
||||
|
||||
// TODO: Check size of buffers + size of packet is not bigger than size in header
|
||||
|
||||
if(pkt_cmd_ata_lba28->buf_len > 0)
|
||||
buffer = in_buf + sizeof(DicPacketCmdAtaLba28);
|
||||
if(pkt_cmd_ata_lba28->buf_len > 0) buffer = in_buf + sizeof(DicPacketCmdAtaLba28);
|
||||
else
|
||||
buffer = NULL;
|
||||
|
||||
@@ -847,13 +842,13 @@ int main()
|
||||
pkt_cmd_ata_lba28->registers,
|
||||
&ata_lba28_error_regs,
|
||||
pkt_cmd_ata_lba28->protocol,
|
||||
pkt_cmd_ata_lba28->transferRegister,
|
||||
pkt_cmd_ata_lba28->transfer_register,
|
||||
buffer,
|
||||
pkt_cmd_ata_lba28->timeout,
|
||||
pkt_cmd_ata_lba28->transferBlocks,
|
||||
pkt_cmd_ata_lba28->transfer_blocks,
|
||||
&duration,
|
||||
&sense,
|
||||
&pkt_cmd_ata_chs->buf_len);
|
||||
&pkt_cmd_ata_lba28->buf_len);
|
||||
|
||||
out_buf = malloc(sizeof(DicPacketResAtaLba28) + pkt_cmd_ata_lba28->buf_len);
|
||||
|
||||
@@ -870,7 +865,7 @@ int main()
|
||||
if(buffer) memcpy(out_buf + sizeof(DicPacketResAtaLba28), buffer, pkt_cmd_ata_lba28->buf_len);
|
||||
|
||||
pkt_res_ata_lba28->hdr.len = sizeof(DicPacketResAtaLba28) + pkt_cmd_ata_lba28->buf_len;
|
||||
pkt_res_ata_lba28->hdr.packet_type = DICMOTE_PACKET_TYPE_RESPONSE_ATA_LBA28;
|
||||
pkt_res_ata_lba28->hdr.packet_type = DICMOTE_PACKET_TYPE_RESPONSE_ATA_LBA_28;
|
||||
pkt_res_ata_lba28->hdr.version = DICMOTE_PACKET_VERSION;
|
||||
pkt_res_ata_lba28->hdr.id = DICMOTE_PACKET_ID;
|
||||
|
||||
@@ -884,7 +879,7 @@ int main()
|
||||
free(pkt_cmd_ata_lba28);
|
||||
free(pkt_res_ata_lba28);
|
||||
continue;
|
||||
case DICMOTE_PACKET_TYPE_COMMAND_ATA_LBA48:
|
||||
case DICMOTE_PACKET_TYPE_COMMAND_ATA_LBA_48:
|
||||
// Packet contains data after
|
||||
in_buf = malloc(pkt_hdr->len);
|
||||
|
||||
@@ -902,8 +897,7 @@ int main()
|
||||
|
||||
// TODO: Check size of buffers + size of packet is not bigger than size in header
|
||||
|
||||
if(pkt_cmd_ata_lba48->buf_len > 0)
|
||||
buffer = in_buf + sizeof(DicPacketCmdAtaLba48);
|
||||
if(pkt_cmd_ata_lba48->buf_len > 0) buffer = in_buf + sizeof(DicPacketCmdAtaLba48);
|
||||
else
|
||||
buffer = NULL;
|
||||
|
||||
@@ -915,13 +909,13 @@ int main()
|
||||
pkt_cmd_ata_lba48->registers,
|
||||
&ata_lba48_error_regs,
|
||||
pkt_cmd_ata_lba48->protocol,
|
||||
pkt_cmd_ata_lba48->transferRegister,
|
||||
pkt_cmd_ata_lba48->transfer_register,
|
||||
buffer,
|
||||
pkt_cmd_ata_lba48->timeout,
|
||||
pkt_cmd_ata_lba48->transferBlocks,
|
||||
pkt_cmd_ata_lba48->transfer_blocks,
|
||||
&duration,
|
||||
&sense,
|
||||
&pkt_cmd_ata_chs->buf_len);
|
||||
&pkt_cmd_ata_lba48->buf_len);
|
||||
|
||||
out_buf = malloc(sizeof(DicPacketResAtaLba48) + pkt_cmd_ata_lba48->buf_len);
|
||||
|
||||
@@ -938,7 +932,7 @@ int main()
|
||||
if(buffer) memcpy(out_buf + sizeof(DicPacketResAtaLba48), buffer, pkt_cmd_ata_lba48->buf_len);
|
||||
|
||||
pkt_res_ata_lba48->hdr.len = sizeof(DicPacketResAtaLba48) + pkt_cmd_ata_lba48->buf_len;
|
||||
pkt_res_ata_lba48->hdr.packet_type = DICMOTE_PACKET_TYPE_RESPONSE_ATA_LBA48;
|
||||
pkt_res_ata_lba48->hdr.packet_type = DICMOTE_PACKET_TYPE_RESPONSE_ATA_LBA_48;
|
||||
pkt_res_ata_lba48->hdr.version = DICMOTE_PACKET_VERSION;
|
||||
pkt_res_ata_lba48->hdr.id = DICMOTE_PACKET_ID;
|
||||
|
||||
@@ -970,8 +964,7 @@ int main()
|
||||
|
||||
// TODO: Check size of buffers + size of packet is not bigger than size in header
|
||||
|
||||
if(pkt_cmd_sdhci->buf_len > 0)
|
||||
buffer = in_buf + sizeof(DicPacketCmdSdhci);
|
||||
if(pkt_cmd_sdhci->buf_len > 0) buffer = in_buf + sizeof(DicPacketCmdSdhci);
|
||||
else
|
||||
buffer = NULL;
|
||||
|
||||
|
||||
4
pcmcia.c
4
pcmcia.c
@@ -21,10 +21,10 @@
|
||||
#include "linux/linux.h"
|
||||
#endif
|
||||
|
||||
uint8_t GetPcmciaData(const char* devicePath, uint16_t* cisLen, char* cis)
|
||||
uint8_t GetPcmciaData(const char* device_path, uint16_t* cis_len, char* cis)
|
||||
{
|
||||
#if defined(__linux__) && !defined(__ANDROID__)
|
||||
return linux_get_pcmcia_data(devicePath, cisLen, cis);
|
||||
return LinuxGetPcmciaData(device_path, cis_len, cis);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
6
scsi.c
6
scsi.c
@@ -22,7 +22,7 @@
|
||||
int32_t SendScsiCommand(int device_fd,
|
||||
char* cdb,
|
||||
char* buffer,
|
||||
char** senseBuffer,
|
||||
char** sense_buffer,
|
||||
uint32_t timeout,
|
||||
int32_t direction,
|
||||
uint32_t* duration,
|
||||
@@ -32,8 +32,8 @@ int32_t SendScsiCommand(int device_fd,
|
||||
uint32_t* sense_len)
|
||||
{
|
||||
#if defined(__linux__) && !defined(__ANDROID__)
|
||||
return linux_send_scsi_command(
|
||||
device_fd, cdb, buffer, senseBuffer, timeout, direction, duration, sense, cdb_len, buf_len, sense_len);
|
||||
return LinuxSendScsiCommand(
|
||||
device_fd, cdb, buffer, sense_buffer, timeout, direction, duration, sense, cdb_len, buf_len, sense_len);
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
|
||||
2
sdhci.c
2
sdhci.c
@@ -35,7 +35,7 @@ int32_t SendSdhciCommand(int device_fd,
|
||||
uint32_t* sense)
|
||||
{
|
||||
#if defined(__linux__) && !defined(__ANDROID__)
|
||||
return linux_send_sdhci_command(device_fd,
|
||||
return LinuxSendSdhciCommand(device_fd,
|
||||
command,
|
||||
write,
|
||||
application,
|
||||
|
||||
10
usb.c
10
usb.c
@@ -21,17 +21,17 @@
|
||||
#include "linux/linux.h"
|
||||
#endif
|
||||
|
||||
uint8_t GetUsbData(const char* devicePath,
|
||||
uint16_t* descLen,
|
||||
uint8_t GetUsbData(const char* device_path,
|
||||
uint16_t* desc_len,
|
||||
char* descriptors,
|
||||
uint16_t* idVendor,
|
||||
uint16_t* idProduct,
|
||||
uint16_t* id_vendor,
|
||||
uint16_t* id_product,
|
||||
char* manufacturer,
|
||||
char* product,
|
||||
char* serial)
|
||||
{
|
||||
#if defined(__linux__) && !defined(__ANDROID__)
|
||||
return linux_get_usb_data(devicePath, descLen, descriptors, idVendor, idProduct, manufacturer, product, serial);
|
||||
return LinuxGetUsbData(device_path, desc_len, descriptors, id_vendor, id_product, manufacturer, product, serial);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user