mirror of
https://github.com/aaru-dps/aaruremote.git
synced 2025-12-16 19:24:37 +00:00
Implement Get FireWire Data packet, and support for Linux.
This commit is contained in:
@@ -3,10 +3,10 @@ project(dicremote C)
|
|||||||
|
|
||||||
set(CMAKE_C_STANDARD 90)
|
set(CMAKE_C_STANDARD 90)
|
||||||
|
|
||||||
set(MAIN_SOURCES main.c list_devices.c device.c scsi.c hex2bin.c usb.c)
|
set(MAIN_SOURCES main.c list_devices.c device.c scsi.c hex2bin.c usb.c ieee1394.c)
|
||||||
|
|
||||||
if("${CMAKE_SYSTEM}" MATCHES "Linux")
|
if("${CMAKE_SYSTEM}" MATCHES "Linux")
|
||||||
set(PLATFORM_SOURCES linux/list_devices.c linux/linux.h linux/device.c linux/scsi.c linux/usb.c)
|
set(PLATFORM_SOURCES linux/list_devices.c linux/linux.h linux/device.c linux/scsi.c linux/usb.c linux/ieee1394.c)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_executable(dicremote ${MAIN_SOURCES} ${PLATFORM_SOURCES})
|
add_executable(dicremote ${MAIN_SOURCES} ${PLATFORM_SOURCES})
|
||||||
|
|||||||
@@ -426,5 +426,11 @@ uint8_t GetUsbData(const char* devicePath,
|
|||||||
char* manufacturer,
|
char* manufacturer,
|
||||||
char* product,
|
char* product,
|
||||||
char* serial);
|
char* serial);
|
||||||
|
uint8_t GetFireWireData(const char* devicePath,
|
||||||
|
uint32_t* idModel,
|
||||||
|
uint32_t* idVendor,
|
||||||
|
uint64_t* guid,
|
||||||
|
char* vendor,
|
||||||
|
char* model);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
36
ieee1394.c
Normal file
36
ieee1394.c
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the DiscImageChef Remote Server.
|
||||||
|
* Copyright (c) 2019 Natalia Portillo.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#if defined(__linux__) && !defined(__ANDROID__)
|
||||||
|
#include "linux/linux.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
uint8_t GetFireWireData(const char* devicePath,
|
||||||
|
uint32_t* idModel,
|
||||||
|
uint32_t* idVendor,
|
||||||
|
uint64_t* guid,
|
||||||
|
char* vendor,
|
||||||
|
char* model)
|
||||||
|
{
|
||||||
|
#if defined(__linux__) && !defined(__ANDROID__)
|
||||||
|
return linux_get_ieee1394_data(devicePath, idModel, idVendor, guid, vendor, model);
|
||||||
|
#else
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
160
linux/ieee1394.c
Normal file
160
linux/ieee1394.c
Normal file
@@ -0,0 +1,160 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the DiscImageChef Remote Server.
|
||||||
|
* Copyright (c) 2019 Natalia Portillo.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "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,
|
||||||
|
uint64_t* guid,
|
||||||
|
char* vendor,
|
||||||
|
char* model)
|
||||||
|
{
|
||||||
|
char* devPath;
|
||||||
|
char tmpPath[4096];
|
||||||
|
char resolvedLink[4096];
|
||||||
|
struct stat sb;
|
||||||
|
ssize_t len;
|
||||||
|
char* rchr;
|
||||||
|
int found;
|
||||||
|
FILE* file;
|
||||||
|
|
||||||
|
*idModel = 0;
|
||||||
|
*idVendor = 0;
|
||||||
|
*guid = 0;
|
||||||
|
memset(tmpPath, 0, 4096);
|
||||||
|
memset(resolvedLink, 0, 4096);
|
||||||
|
|
||||||
|
if(strncmp(devicePath, "/dev/sd", 7) != 0 && strncmp(devicePath, "/dev/sr", 7) != 0 &&
|
||||||
|
strncmp(devicePath, "/dev/st", 7) != 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
devPath = (char*)devicePath + 5;
|
||||||
|
|
||||||
|
snprintf(tmpPath, 4096, "/sys/block/%s", devPath);
|
||||||
|
|
||||||
|
if(stat(tmpPath, &sb) != 0 || !S_ISDIR(sb.st_mode)) { return 0; }
|
||||||
|
|
||||||
|
len = readlink(tmpPath, resolvedLink, 4096);
|
||||||
|
|
||||||
|
if(len == 0) return 0;
|
||||||
|
|
||||||
|
memset(tmpPath, 0, 4096);
|
||||||
|
snprintf(tmpPath, 4096, "/sys%s", resolvedLink + 2);
|
||||||
|
memcpy(resolvedLink, tmpPath, 4096);
|
||||||
|
|
||||||
|
while(strstr(resolvedLink, "firewire") != NULL)
|
||||||
|
{
|
||||||
|
found = 1;
|
||||||
|
rchr = strrchr(resolvedLink, '/');
|
||||||
|
|
||||||
|
if(rchr == NULL) break;
|
||||||
|
|
||||||
|
*rchr = '\0';
|
||||||
|
|
||||||
|
if(strlen(resolvedLink) == 0) break;
|
||||||
|
|
||||||
|
snprintf(tmpPath, 4096, "%s/model", resolvedLink);
|
||||||
|
if(access(tmpPath, R_OK) != 0) found = 0;
|
||||||
|
memset(tmpPath, 0, 4096);
|
||||||
|
|
||||||
|
snprintf(tmpPath, 4096, "%s/vendor", resolvedLink);
|
||||||
|
if(access(tmpPath, R_OK) != 0) found = 0;
|
||||||
|
memset(tmpPath, 0, 4096);
|
||||||
|
|
||||||
|
snprintf(tmpPath, 4096, "%s/guid", resolvedLink);
|
||||||
|
if(access(tmpPath, R_OK) != 0) found = 0;
|
||||||
|
memset(tmpPath, 0, 4096);
|
||||||
|
|
||||||
|
if(!found) continue;
|
||||||
|
|
||||||
|
memset(tmpPath, 0, 4096);
|
||||||
|
snprintf(tmpPath, 4096, "%s/model", resolvedLink);
|
||||||
|
|
||||||
|
if(access(tmpPath, R_OK) == 0)
|
||||||
|
{
|
||||||
|
file = fopen(tmpPath, "r");
|
||||||
|
if(file != NULL)
|
||||||
|
{
|
||||||
|
fscanf(file, "%8x", idModel);
|
||||||
|
fclose(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(tmpPath, 0, 4096);
|
||||||
|
snprintf(tmpPath, 4096, "%s/vendor", resolvedLink);
|
||||||
|
|
||||||
|
if(access(tmpPath, R_OK) == 0)
|
||||||
|
{
|
||||||
|
file = fopen(tmpPath, "r");
|
||||||
|
if(file != NULL)
|
||||||
|
{
|
||||||
|
fscanf(file, "%8x", idVendor);
|
||||||
|
fclose(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(tmpPath, 0, 4096);
|
||||||
|
snprintf(tmpPath, 4096, "%s/guid", resolvedLink);
|
||||||
|
|
||||||
|
if(access(tmpPath, R_OK) == 0)
|
||||||
|
{
|
||||||
|
file = fopen(tmpPath, "r");
|
||||||
|
if(file != NULL)
|
||||||
|
{
|
||||||
|
fscanf(file, "%16lx", guid);
|
||||||
|
fclose(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(tmpPath, 0, 4096);
|
||||||
|
snprintf(tmpPath, 4096, "%s/model_name", resolvedLink);
|
||||||
|
|
||||||
|
if(access(tmpPath, R_OK) == 0)
|
||||||
|
{
|
||||||
|
file = fopen(tmpPath, "r");
|
||||||
|
if(file != NULL)
|
||||||
|
{
|
||||||
|
fread(model, 256, 1, file);
|
||||||
|
fclose(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(tmpPath, 0, 4096);
|
||||||
|
snprintf(tmpPath, 4096, "%s/vendor_name", resolvedLink);
|
||||||
|
|
||||||
|
if(access(tmpPath, R_OK) == 0)
|
||||||
|
{
|
||||||
|
file = fopen(tmpPath, "r");
|
||||||
|
if(file != NULL)
|
||||||
|
{
|
||||||
|
fread(vendor, 256, 1, file);
|
||||||
|
fclose(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -52,4 +52,11 @@ uint8_t linux_get_usb_data(const char* devicePath,
|
|||||||
char* manufacturer,
|
char* manufacturer,
|
||||||
char* product,
|
char* product,
|
||||||
char* serial);
|
char* serial);
|
||||||
|
uint8_t linux_get_ieee1394_data(const char* devicePath,
|
||||||
|
uint32_t* idModel,
|
||||||
|
uint32_t* idVendor,
|
||||||
|
uint64_t* guid,
|
||||||
|
char* vendor,
|
||||||
|
char* model);
|
||||||
|
|
||||||
#endif // DICREMOTE_LINUX_H
|
#endif // DICREMOTE_LINUX_H
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ uint8_t linux_get_usb_data(const char* devicePath,
|
|||||||
|
|
||||||
while(strstr(resolvedLink, "usb") != NULL)
|
while(strstr(resolvedLink, "usb") != NULL)
|
||||||
{
|
{
|
||||||
|
found = 1;
|
||||||
rchr = strrchr(resolvedLink, '/');
|
rchr = strrchr(resolvedLink, '/');
|
||||||
|
|
||||||
if(rchr == NULL) break;
|
if(rchr == NULL) break;
|
||||||
|
|||||||
41
main.c
41
main.c
@@ -66,6 +66,7 @@ int main()
|
|||||||
char* ocr;
|
char* ocr;
|
||||||
char* scr;
|
char* scr;
|
||||||
DicPacketResGetUsbData* pkt_res_usb;
|
DicPacketResGetUsbData* pkt_res_usb;
|
||||||
|
DicPacketResGetFireWireData* pkt_res_firewire;
|
||||||
|
|
||||||
printf("DiscImageChef Remote Server %s\n", DICMOTE_VERSION);
|
printf("DiscImageChef Remote Server %s\n", DICMOTE_VERSION);
|
||||||
printf("Copyright (C) 2019 Natalia Portillo\n");
|
printf("Copyright (C) 2019 Natalia Portillo\n");
|
||||||
@@ -660,11 +661,49 @@ int main()
|
|||||||
write(cli_sock, pkt_res_usb, pkt_res_usb->hdr.len);
|
write(cli_sock, pkt_res_usb, pkt_res_usb->hdr.len);
|
||||||
free(pkt_res_usb);
|
free(pkt_res_usb);
|
||||||
continue;
|
continue;
|
||||||
|
case DICMOTE_PACKET_TYPE_COMMAND_GET_FIREWIRE_DATA:
|
||||||
|
// Packet only contains header so, dummy
|
||||||
|
in_buf = malloc(pkt_hdr->len);
|
||||||
|
|
||||||
|
if(!in_buf)
|
||||||
|
{
|
||||||
|
printf("Fatal error %d allocating memory for packet, closing connection...\n", errno);
|
||||||
|
free(pkt_hdr);
|
||||||
|
close(cli_sock);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
recv(cli_sock, in_buf, pkt_hdr->len, 0);
|
||||||
|
free(in_buf);
|
||||||
|
|
||||||
|
pkt_res_firewire = malloc(sizeof(DicPacketResGetFireWireData));
|
||||||
|
if(!pkt_res_firewire)
|
||||||
|
{
|
||||||
|
printf("Fatal error %d allocating memory for packet, closing connection...\n", errno);
|
||||||
|
free(pkt_hdr);
|
||||||
|
close(cli_sock);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(pkt_res_firewire, 0, sizeof(DicPacketResGetFireWireData));
|
||||||
|
pkt_res_firewire->hdr.id = DICMOTE_PACKET_ID;
|
||||||
|
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->guid,
|
||||||
|
pkt_res_firewire->vendor,
|
||||||
|
pkt_res_firewire->model);
|
||||||
|
|
||||||
|
write(cli_sock, pkt_res_firewire, pkt_res_firewire->hdr.len);
|
||||||
|
free(pkt_res_firewire);
|
||||||
|
continue;
|
||||||
case DICMOTE_PACKET_TYPE_COMMAND_ATA_CHS:
|
case DICMOTE_PACKET_TYPE_COMMAND_ATA_CHS:
|
||||||
case DICMOTE_PACKET_TYPE_COMMAND_ATA_LBA28:
|
case DICMOTE_PACKET_TYPE_COMMAND_ATA_LBA28:
|
||||||
case DICMOTE_PACKET_TYPE_COMMAND_ATA_LBA48:
|
case DICMOTE_PACKET_TYPE_COMMAND_ATA_LBA48:
|
||||||
case DICMOTE_PACKET_TYPE_COMMAND_SDHCI:
|
case DICMOTE_PACKET_TYPE_COMMAND_SDHCI:
|
||||||
case DICMOTE_PACKET_TYPE_COMMAND_GET_FIREWIRE_DATA:
|
|
||||||
case DICMOTE_PACKET_TYPE_COMMAND_GET_PCMCIA_DATA:
|
case DICMOTE_PACKET_TYPE_COMMAND_GET_PCMCIA_DATA:
|
||||||
pkt_nop->reason_code = DICMOTE_PACKET_NOP_REASON_NOT_IMPLEMENTED;
|
pkt_nop->reason_code = DICMOTE_PACKET_NOP_REASON_NOT_IMPLEMENTED;
|
||||||
memset(&pkt_nop->reason, 0, 256);
|
memset(&pkt_nop->reason, 0, 256);
|
||||||
|
|||||||
Reference in New Issue
Block a user