mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-21 05:53:12 -07:00
Add wakeup command to CLI (#168)
This commit is contained in:
parent
fe1e3835f8
commit
d9773c55e0
5 changed files with 101 additions and 3 deletions
|
@ -1,7 +1,8 @@
|
||||||
|
|
||||||
set(SOURCE
|
set(SOURCE
|
||||||
include/chiaki-cli.h
|
include/chiaki-cli.h
|
||||||
src/discover.c)
|
src/discover.c
|
||||||
|
src/wakeup.c)
|
||||||
|
|
||||||
add_library(chiaki-cli-lib STATIC ${SOURCE})
|
add_library(chiaki-cli-lib STATIC ${SOURCE})
|
||||||
target_include_directories(chiaki-cli-lib PUBLIC "include")
|
target_include_directories(chiaki-cli-lib PUBLIC "include")
|
||||||
|
|
|
@ -26,6 +26,7 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
CHIAKI_EXPORT int chiaki_cli_cmd_discover(ChiakiLog *log, int argc, char *argv[]);
|
CHIAKI_EXPORT int chiaki_cli_cmd_discover(ChiakiLog *log, int argc, char *argv[]);
|
||||||
|
CHIAKI_EXPORT int chiaki_cli_cmd_wakeup(ChiakiLog *log, int argc, char *argv[]);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,8 @@ static const char doc[] =
|
||||||
"CLI for Chiaki (PS4 Remote Play Client)"
|
"CLI for Chiaki (PS4 Remote Play Client)"
|
||||||
"\v"
|
"\v"
|
||||||
"Supported commands are:\n"
|
"Supported commands are:\n"
|
||||||
" discover Discover Consoles.\n";
|
" discover Discover Consoles.\n"
|
||||||
|
" wakeup Send Wakeup Packet.\n";
|
||||||
|
|
||||||
#define ARG_KEY_VERBOSE 'v'
|
#define ARG_KEY_VERBOSE 'v'
|
||||||
|
|
||||||
|
@ -73,6 +74,8 @@ static int parse_opt(int key, char *arg, struct argp_state *state)
|
||||||
case ARGP_KEY_ARG:
|
case ARGP_KEY_ARG:
|
||||||
if(strcmp(arg, "discover") == 0)
|
if(strcmp(arg, "discover") == 0)
|
||||||
exit(call_subcmd(state, "discover", chiaki_cli_cmd_discover));
|
exit(call_subcmd(state, "discover", chiaki_cli_cmd_discover));
|
||||||
|
else if(strcmp(arg, "wakeup") == 0)
|
||||||
|
exit(call_subcmd(state, "wakeup", chiaki_cli_cmd_wakeup));
|
||||||
// fallthrough
|
// fallthrough
|
||||||
case ARGP_KEY_END:
|
case ARGP_KEY_END:
|
||||||
argp_usage(state);
|
argp_usage(state);
|
||||||
|
|
92
cli/src/wakeup.c
Normal file
92
cli/src/wakeup.c
Normal file
|
@ -0,0 +1,92 @@
|
||||||
|
/*
|
||||||
|
* This file is part of Chiaki.
|
||||||
|
*
|
||||||
|
* Chiaki 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, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Chiaki 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 Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <chiaki-cli.h>
|
||||||
|
|
||||||
|
#include <chiaki/discovery.h>
|
||||||
|
|
||||||
|
#include <argp.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
static char doc[] = "Send a PS4 wakeup packet.";
|
||||||
|
|
||||||
|
#define ARG_KEY_HOST 'h'
|
||||||
|
#define ARG_KEY_REGISTKEY 'r'
|
||||||
|
|
||||||
|
static struct argp_option options[] = {
|
||||||
|
{ "host", ARG_KEY_HOST, "Host", 0, "Host to send wakeup packet to", 0 },
|
||||||
|
{ "registkey", ARG_KEY_REGISTKEY, "RegistKey", 0, "PS4 registration key", 0 },
|
||||||
|
{ 0 }
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct arguments
|
||||||
|
{
|
||||||
|
const char *host;
|
||||||
|
const char *registkey;
|
||||||
|
} Arguments;
|
||||||
|
|
||||||
|
static int parse_opt(int key, char *arg, struct argp_state *state)
|
||||||
|
{
|
||||||
|
Arguments *arguments = state->input;
|
||||||
|
|
||||||
|
switch(key)
|
||||||
|
{
|
||||||
|
case ARG_KEY_HOST:
|
||||||
|
arguments->host = arg;
|
||||||
|
break;
|
||||||
|
case ARG_KEY_REGISTKEY:
|
||||||
|
arguments->registkey = arg;
|
||||||
|
break;
|
||||||
|
case ARGP_KEY_ARG:
|
||||||
|
argp_usage(state);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return ARGP_ERR_UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct argp argp = { options, parse_opt, 0, doc, 0, 0, 0 };
|
||||||
|
|
||||||
|
CHIAKI_EXPORT int chiaki_cli_cmd_wakeup(ChiakiLog *log, int argc, char *argv[])
|
||||||
|
{
|
||||||
|
Arguments arguments = { 0 };
|
||||||
|
error_t argp_r = argp_parse(&argp, argc, argv, ARGP_IN_ORDER, NULL, &arguments);
|
||||||
|
if(argp_r != 0)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if(!arguments.host)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "No host specified, see --help.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if(!arguments.registkey)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "No registration key specified, see --help.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if(strlen(arguments.registkey) > 8)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Given registkey is too long.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t credential = (uint64_t)strtoull(arguments.registkey, NULL, 16);
|
||||||
|
|
||||||
|
return chiaki_discovery_wakeup(log, NULL, arguments.host, credential);
|
||||||
|
}
|
|
@ -40,7 +40,8 @@ struct CLICommand
|
||||||
};
|
};
|
||||||
|
|
||||||
static const QMap<QString, CLICommand> cli_commands = {
|
static const QMap<QString, CLICommand> cli_commands = {
|
||||||
{ "discover", { chiaki_cli_cmd_discover } }
|
{ "discover", { chiaki_cli_cmd_discover } },
|
||||||
|
{ "wakeup", { chiaki_cli_cmd_wakeup } }
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue