mirror of
https://github.com/aaru-dps/aaruremote.git
synced 2025-12-16 19:24:37 +00:00
Handle open device packet.
This commit is contained in:
@@ -3,7 +3,7 @@ project(dicremote C)
|
||||
|
||||
set(CMAKE_C_STANDARD 90)
|
||||
|
||||
set(PLATFORM_SOURCES)
|
||||
set(PLATFORM_SOURCES device.c)
|
||||
|
||||
if("${CMAKE_SYSTEM}" MATCHES "Linux")
|
||||
list(APPEND PLATFORM_SOURCES linux/list_devices.c linux/linux.h)
|
||||
|
||||
18
device.c
Normal file
18
device.c
Normal file
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
int DeviceOpen(const char* devicePath) { return -1; }
|
||||
@@ -94,7 +94,7 @@ typedef struct
|
||||
uint8_t reason_code;
|
||||
char spare[3];
|
||||
char reason[256];
|
||||
int32_t errno;
|
||||
int32_t errorNo;
|
||||
} DicPacketNop;
|
||||
|
||||
typedef struct
|
||||
@@ -108,5 +108,6 @@ typedef struct
|
||||
DeviceInfoList* ListDevices();
|
||||
void FreeDeviceInfoList(DeviceInfoList* start);
|
||||
uint16_t DeviceInfoListCount(DeviceInfoList* start);
|
||||
int DeviceOpen(const char* devicePath);
|
||||
|
||||
#endif
|
||||
|
||||
25
main.c
25
main.c
@@ -47,6 +47,8 @@ int main()
|
||||
int i;
|
||||
uint64_t n;
|
||||
DicPacketNop* pkt_nop;
|
||||
DicPacketCmdOpen* pkt_dev_open;
|
||||
int device_fd;
|
||||
|
||||
printf("DiscImageChef Remote Server %s\n", DICMOTE_VERSION);
|
||||
printf("Copyright (C) 2019 Natalia Portillo\n");
|
||||
@@ -388,12 +390,27 @@ int main()
|
||||
skip_next_hdr = 1;
|
||||
continue;
|
||||
case DICMOTE_PACKET_TYPE_COMMAND_OPEN_DEVICE:
|
||||
pkt_nop->reason_code = DICMOTE_PACKET_NOP_REASON_NOT_IMPLEMENTED;
|
||||
pkt_dev_open = malloc(pkt_hdr->len);
|
||||
|
||||
if(!pkt_dev_open)
|
||||
{
|
||||
printf("Fatal error %d allocating memory for packet, closing connection...\n", errno);
|
||||
free(pkt_hdr);
|
||||
close(cli_sock);
|
||||
continue;
|
||||
}
|
||||
|
||||
recv(cli_sock, pkt_dev_open, pkt_hdr->len, 0);
|
||||
|
||||
device_fd = DeviceOpen(pkt_dev_open->device_path);
|
||||
|
||||
pkt_nop->reason_code =
|
||||
device_fd == -1 ? DICMOTE_PACKET_NOP_REASON_OPEN_ERROR : DICMOTE_PACKET_NOP_REASON_OPEN_OK;
|
||||
pkt_nop->errorNo = errno;
|
||||
memset(&pkt_nop->reason, 0, 256);
|
||||
strncpy(pkt_nop->reason, "Opening devices not yet implemented...", 256);
|
||||
write(cli_sock, pkt_nop, sizeof(DicPacketNop));
|
||||
printf("%s...\n", pkt_nop->reason);
|
||||
skip_next_hdr = 1;
|
||||
|
||||
free(pkt_dev_open);
|
||||
continue;
|
||||
default:
|
||||
pkt_nop->reason_code = DICMOTE_PACKET_NOP_REASON_NOT_RECOGNIZED;
|
||||
|
||||
Reference in New Issue
Block a user