diff --git a/dicmote.h b/dicmote.h index 3907443..37e3092 100644 --- a/dicmote.h +++ b/dicmote.h @@ -497,5 +497,6 @@ int32_t SendSdhciCommand(int device_fd, uint32_t* response, uint32_t* duration, uint32_t* sense); +DicPacketHello* GetHello(); #endif diff --git a/linux/CMakeLists.txt b/linux/CMakeLists.txt index 108a68a..81d414e 100644 --- a/linux/CMakeLists.txt +++ b/linux/CMakeLists.txt @@ -4,7 +4,7 @@ if (NOT "${CMAKE_SYSTEM}" MATCHES "Linux") return() endif () -set(PLATFORM_SOURCES list_devices.c linux.h device.c scsi.c usb.c ieee1394.c pcmcia.c ata.c sdhci.c) +set(PLATFORM_SOURCES list_devices.c linux.h device.c scsi.c usb.c ieee1394.c pcmcia.c ata.c sdhci.c ../unix/hello.c) CHECK_LIBRARY_EXISTS("udev" udev_new "" HAS_UDEV) CHECK_INCLUDE_FILES("linux/mmc/ioctl.h" HAVE_MMC_IOCTL_H) diff --git a/main.c b/main.c index 9191449..74717cb 100644 --- a/main.c +++ b/main.c @@ -23,9 +23,6 @@ #include #include #include -#include - -// TODO: Packet for NOP int main() { @@ -74,7 +71,6 @@ int main() 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; @@ -84,15 +80,16 @@ int main() printf("DiscImageChef Remote Server %s\n", DICMOTE_VERSION); printf("Copyright (C) 2019 Natalia Portillo\n"); - ret = uname(&utsname); + pkt_server_hello = GetHello(); - if(ret) + if(!pkt_server_hello) { printf("Error %d getting system version.\n", errno); return 1; } - printf("Running under %s %s (%s).\n", utsname.sysname, utsname.release, utsname.machine); + printf( + "Running under %s %s (%s).\n", pkt_server_hello->sysname, pkt_server_hello->release, pkt_server_hello->machine); printf("Opening socket.\n"); sock_fd = socket(AF_INET, SOCK_STREAM, 0); @@ -146,28 +143,6 @@ int main() return 1; } - pkt_server_hello = malloc(sizeof(DicPacketHello)); - - if(!pkt_server_hello) - { - printf("Fatal error %d allocating memory.\n", errno); - close(sock_fd); - return 1; - } - - memset(pkt_server_hello, 0, sizeof(DicPacketHello)); - - pkt_server_hello->hdr.id = DICMOTE_PACKET_ID; - pkt_server_hello->hdr.len = sizeof(DicPacketHello); - pkt_server_hello->hdr.version = DICMOTE_PACKET_VERSION; - pkt_server_hello->hdr.packet_type = DICMOTE_PACKET_TYPE_HELLO; - strncpy(pkt_server_hello->application, DICMOTE_NAME, sizeof(DICMOTE_NAME)); - strncpy(pkt_server_hello->version, DICMOTE_VERSION, sizeof(DICMOTE_VERSION)); - pkt_server_hello->max_protocol = DICMOTE_PROTOCOL_MAX; - strncpy(pkt_server_hello->sysname, utsname.sysname, 255); - strncpy(pkt_server_hello->release, utsname.release, 255); - strncpy(pkt_server_hello->machine, utsname.machine, 255); - pkt_nop = malloc(sizeof(DicPacketNop)); if(!pkt_nop) diff --git a/unix/hello.c b/unix/hello.c new file mode 100644 index 0000000..cb1ccf1 --- /dev/null +++ b/unix/hello.c @@ -0,0 +1,52 @@ +/* + * 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 . + */ + +#include "../dicmote.h" + +#include +#include +#include + +DicPacketHello* GetHello() +{ + struct utsname utsname; + int ret; + DicPacketHello* pkt_server_hello; + + ret = uname(&utsname); + + if(ret) { return 0; } + + pkt_server_hello = malloc(sizeof(DicPacketHello)); + + if(!pkt_server_hello) { return 0; } + + memset(pkt_server_hello, 0, sizeof(DicPacketHello)); + + pkt_server_hello->hdr.id = DICMOTE_PACKET_ID; + pkt_server_hello->hdr.len = sizeof(DicPacketHello); + pkt_server_hello->hdr.version = DICMOTE_PACKET_VERSION; + pkt_server_hello->hdr.packet_type = DICMOTE_PACKET_TYPE_HELLO; + strncpy(pkt_server_hello->application, DICMOTE_NAME, sizeof(DICMOTE_NAME)); + strncpy(pkt_server_hello->version, DICMOTE_VERSION, sizeof(DICMOTE_VERSION)); + pkt_server_hello->max_protocol = DICMOTE_PROTOCOL_MAX; + strncpy(pkt_server_hello->sysname, utsname.sysname, 255); + strncpy(pkt_server_hello->release, utsname.release, 255); + strncpy(pkt_server_hello->machine, utsname.machine, 255); + + return pkt_server_hello; +} \ No newline at end of file diff --git a/wii/CMakeLists.txt b/wii/CMakeLists.txt index 2c31eec..686f231 100644 --- a/wii/CMakeLists.txt +++ b/wii/CMakeLists.txt @@ -4,7 +4,7 @@ if (NOT WII) return() endif () -set(PLATFORM_SOURCES wii.c) +set(PLATFORM_SOURCES wii.c hello.c) add_executable(dicremote-wii ${PLATFORM_SOURCES}) set_target_properties(dicremote-wii PROPERTIES LINK_FLAGS -L$ENV{DEVKITPRO}/libogc/lib/wii/) diff --git a/wii/hello.c b/wii/hello.c new file mode 100644 index 0000000..4541778 --- /dev/null +++ b/wii/hello.c @@ -0,0 +1,45 @@ +/* + * 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 . + */ + +#include "../dicmote.h" + +#include +#include + +DicPacketHello* GetHello() +{ + DicPacketHello* pkt_server_hello; + + pkt_server_hello = malloc(sizeof(DicPacketHello)); + + if(!pkt_server_hello) { return 0; } + + memset(pkt_server_hello, 0, sizeof(DicPacketHello)); + + pkt_server_hello->hdr.id = DICMOTE_PACKET_ID; + pkt_server_hello->hdr.len = sizeof(DicPacketHello); + pkt_server_hello->hdr.version = DICMOTE_PACKET_VERSION; + pkt_server_hello->hdr.packet_type = DICMOTE_PACKET_TYPE_HELLO; + strncpy(pkt_server_hello->application, DICMOTE_NAME, sizeof(DICMOTE_NAME)); + strncpy(pkt_server_hello->version, DICMOTE_VERSION, sizeof(DICMOTE_VERSION)); + pkt_server_hello->max_protocol = DICMOTE_PROTOCOL_MAX; + strncpy(pkt_server_hello->sysname, "TODO: Gecko", 255); + strncpy(pkt_server_hello->release, "TODO: Unknown", 255); + strncpy(pkt_server_hello->machine, "TODO: Unknown", 255); + + return pkt_server_hello; +} \ No newline at end of file