remove redundant logging functions

This commit is contained in:
itsmattkc committed 2025-05-08 12:58:36 -07:00
1 parent 4d29ae129e
commit 4ae9abefbf
13 files changed
+107 -163

No files matched your search

-1
View File
@@ -4,7 +4,6 @@ add_library(vanilla STATIC
gamepad/gamepad.c
gamepad/input.c
gamepad/video.c
status.c
util.c
vanilla.c
)
-1
View File
@@ -10,7 +10,6 @@
#include <stdint.h>
#include "gamepad.h"
#include "status.h"
#include "vanilla.h"
#include "util.h"
+8 -9
View File
@@ -13,7 +13,6 @@
#include <assert.h>
#include "gamepad.h"
#include "status.h"
#include "vanilla.h"
#include "util.h"
@@ -254,7 +253,7 @@ void send_generic_response(int skt, CmdHeader *response)
void handle_generic_packet(gamepad_context_t *info, int skt, GenericPacket *request)
{
GenericCmdHeader *gen_cmd = &request->generic_cmd_header;
print_info("magic: %x, flags: %x, service ID: %u, method ID: %u", gen_cmd->magic_0x7E, gen_cmd->flags, gen_cmd->service_id, gen_cmd->method_id);
vanilla_log("magic: %x, flags: %x, service ID: %u, method ID: %u", gen_cmd->magic_0x7E, gen_cmd->flags, gen_cmd->service_id, gen_cmd->method_id);
// Prepare response
GenericPacket response;
@@ -356,13 +355,13 @@ void handle_generic_packet(gamepad_context_t *info, int skt, GenericPacket *requ
}
case METHOD_ID_PERIPHERAL_UPDATE_EEPROM:
{
print_info("5,12 - index: %u, length: %u", response.payload[0], response.payload[1]);
vanilla_log("5,12 - index: %u, length: %u", response.payload[0], response.payload[1]);
response.generic_cmd_header.error_code = 0;
break;
}
case METHOD_ID_PERIPHERAL_SET_REMOCON:
{
print_info("5,24 - str1: %s, str2: %s", response.payload, response.payload + 5);
vanilla_log("5,24 - str1: %s, str2: %s", response.payload, response.payload + 5);
response.generic_cmd_header.error_code = 0;
break;
}
@@ -379,14 +378,14 @@ void handle_generic_packet(gamepad_context_t *info, int skt, GenericPacket *requ
void handle_uac_uvc_packet(int skt, UvcUacPacket *request)
{
print_info("uac/uvc - mic_enable: %u, mic_freq: %u, mic_mute: %u, mic_volume: %i, mic_volume2: %i", request->uac_uvc.mic_enable, request->uac_uvc.mic_freq, request->uac_uvc.mic_mute, request->uac_uvc.mic_volume, request->uac_uvc.mic_volume_2);
vanilla_log("uac/uvc - mic_enable: %u, mic_freq: %u, mic_mute: %u, mic_volume: %i, mic_volume2: %i", request->uac_uvc.mic_enable, request->uac_uvc.mic_freq, request->uac_uvc.mic_mute, request->uac_uvc.mic_volume, request->uac_uvc.mic_volume_2);
// send_quick_response(skt, &request->cmd_header);
}
void handle_time_packet(int skt, TimePacket *request)
{
print_info("time - days: %u, padding: %u, seconds: %u", request->time.days_counter, request->time.padding, request->time.seconds_counter);
vanilla_log("time - days: %u, padding: %u, seconds: %u", request->time.days_counter, request->time.padding, request->time.seconds_counter);
send_quick_response(skt, &request->cmd_header);
}
@@ -415,7 +414,7 @@ void handle_command_packet(gamepad_context_t *info, int skt, CmdHeader *request)
break;
}
default:
print_info("[Command] Unhandled request command: %u", request->query_type);
vanilla_log("[Command] Unhandled request command: %u", request->query_type);
}
break;
case PACKET_TYPE_RESPONSE:
@@ -423,7 +422,7 @@ void handle_command_packet(gamepad_context_t *info, int skt, CmdHeader *request)
switch (request->query_type)
{
default:
// print_info("[Command] Unhandled request command: %u", request->query_type);
// vanilla_log("[Command] Unhandled request command: %u", request->query_type);
break;
}
break;
@@ -432,7 +431,7 @@ void handle_command_packet(gamepad_context_t *info, int skt, CmdHeader *request)
// NOTE: Should we do something if we don't get this? e.g. attempt re-sending request/response after some time has passed
break;
default:
print_info("Unhandled command packet type: %u", request->packet_type);
vanilla_log("Unhandled command packet type: %u", request->packet_type);
}
}
+14 -15
View File
@@ -26,7 +26,6 @@ typedef uint16_t in_port_t;
#include "video.h"
#include "../pipe/def.h"
#include "status.h"
#include "util.h"
static uint32_t SERVER_ADDRESS = 0;
@@ -102,7 +101,7 @@ void send_to_console(int fd, const void *data, size_t data_size, uint16_t port)
ssize_t sent = sendto(fd, data, data_size, 0, (const struct sockaddr *) &addr, addr_size);
if (sent == -1) {
print_info("Failed to send to Wii U socket: fd: %d, port: %d, errno: %i", fd, console_port, skterr());
vanilla_log("Failed to send to Wii U socket: fd: %d, port: %d, errno: %i", fd, console_port, skterr());
}
}
@@ -130,17 +129,17 @@ int create_socket(int *socket_out, in_port_t port)
int skt = socket(domain, SOCK_DGRAM, 0);
if (skt == -1) {
print_info("FAILED TO CREATE SOCKET: %i", skterr());
vanilla_log("FAILED TO CREATE SOCKET: %i", skterr());
return VANILLA_ERR_BAD_SOCKET;
}
if (bind(skt, (const struct sockaddr *) &addr, addr_size) == -1) {
print_info("FAILED TO BIND PORT %u: %i", port, skterr());
vanilla_log("FAILED TO BIND PORT %u: %i", port, skterr());
close(skt);
return VANILLA_ERR_BAD_SOCKET;
}
// print_info("SUCCESSFULLY BOUND SOCKET %i ON PORT %i", skt, port);
// vanilla_log("SUCCESSFULLY BOUND SOCKET %i ON PORT %i", skt, port);
(*socket_out) = skt;
@@ -161,7 +160,7 @@ int send_pipe_cc(int skt, vanilla_pipe_command_t *cmd, size_t cmd_size, int wait
for (int retries = 0; retries < MAX_PIPE_RETRY; retries++) {
if (sendto(skt, (const char *) cmd, cmd_size, 0, (const struct sockaddr *) &addr, addr_size) == -1) {
print_info("Failed to write control code to socket");
vanilla_log("Failed to write control code to socket");
return 0;
}
@@ -174,7 +173,7 @@ int send_pipe_cc(int skt, vanilla_pipe_command_t *cmd, size_t cmd_size, int wait
return 1;
}
print_info("STILL WAITING FOR REPLY");
vanilla_log("STILL WAITING FOR REPLY");
sleep(1);
}
@@ -201,7 +200,7 @@ int connect_to_backend(int *socket, vanilla_pipe_command_t *cmd, size_t cmd_size
set_socket_rcvtimeo(pipe_cc_skt, 2000000);
if (!send_pipe_cc(pipe_cc_skt, cmd, cmd_size, 1)) {
print_info("FAILED TO BIND TO PIPE");
vanilla_log("FAILED TO BIND TO PIPE");
close(pipe_cc_skt);
return VANILLA_ERR_PIPE_UNRESPONSIVE;
}
@@ -318,7 +317,7 @@ void connect_as_gamepad_internal(thread_data_t *data)
#else
if (r != EAGAIN) {
#endif
print_info("FAILED TO GET CONNECTED STATE: %i", r);
vanilla_log("FAILED TO GET CONNECTED STATE: %i", r);
ret = VANILLA_ERR_PIPE_UNRESPONSIVE;
break;
}
@@ -328,7 +327,7 @@ void connect_as_gamepad_internal(thread_data_t *data)
break;
}
print_info("STILL WAITING FOR CONNECTED STATE");
vanilla_log("STILL WAITING FOR CONNECTED STATE");
}
}
}
@@ -415,7 +414,7 @@ int push_event(event_loop_t *loop, int type, const void *data, size_t size)
// Prevent rollover by skipping oldest event if necessary
if (loop->new_index == loop->used_index + VANILLA_MAX_EVENT_COUNT) {
vanilla_free_event(&loop->events[loop->used_index % VANILLA_MAX_EVENT_COUNT]);
print_info("SKIPPED EVENT TO PREVENT ROLLOVER (%lu > %lu + %lu)", loop->new_index, loop->used_index, VANILLA_MAX_EVENT_COUNT);
vanilla_log("SKIPPED EVENT TO PREVENT ROLLOVER (%lu > %lu + %lu)", loop->new_index, loop->used_index, VANILLA_MAX_EVENT_COUNT);
loop->used_index++;
}
@@ -425,7 +424,7 @@ int push_event(event_loop_t *loop, int type, const void *data, size_t size)
ev->data = get_event_buffer();
if (!ev->data) {
print_info("OUT OF MEMORY FOR NEW EVENTS");
vanilla_log("OUT OF MEMORY FOR NEW EVENTS");
ret = VANILLA_ERR_OUT_OF_MEMORY;
goto exit;
}
@@ -438,7 +437,7 @@ int push_event(event_loop_t *loop, int type, const void *data, size_t size)
pthread_cond_broadcast(&loop->waitcond);
} else {
print_info("FAILED TO PUSH EVENT: wanted %lu, only had %lu. This is a bug, please report to developers.\n", size, EVENT_BUFFER_SIZE);
vanilla_log("FAILED TO PUSH EVENT: wanted %lu, only had %lu. This is a bug, please report to developers.", size, EVENT_BUFFER_SIZE);
ret = VANILLA_ERR_INVALID_ARGUMENT;
}
@@ -516,7 +515,7 @@ void init_event_buffer_arena()
if (!EVENT_BUFFER_ARENA[i]) {
EVENT_BUFFER_ARENA[i] = malloc(EVENT_BUFFER_SIZE);
} else {
print_info("CRITICAL: Buffer wasn't returned to the arena");
vanilla_log("CRITICAL: Buffer wasn't returned to the arena");
}
}
}
@@ -528,7 +527,7 @@ void free_event_buffer_arena()
free(EVENT_BUFFER_ARENA[i]);
EVENT_BUFFER_ARENA[i] = NULL;
} else {
print_info("CRITICAL: Buffer wasn't returned to the arena");
vanilla_log("CRITICAL: Buffer wasn't returned to the arena");
}
}
}
-1
View File
@@ -14,7 +14,6 @@
#include <unistd.h>
#include "gamepad.h"
#include "status.h"
#include "vanilla.h"
#include "util.h"
+2 -3
View File
@@ -18,7 +18,6 @@
#include "gamepad.h"
#include "vanilla.h"
#include "status.h"
#include "util.h"
typedef struct
@@ -62,7 +61,7 @@ void send_idr_request_to_console(int socket_msg)
{
// Make an IDR request to the Wii U?
unsigned char idr_request[] = {1, 0, 0, 0}; // Undocumented
print_info("SENDING IDR");
vanilla_log("SENDING IDR");
send_to_console(socket_msg, idr_request, sizeof(idr_request), PORT_MSG);
}
@@ -89,7 +88,7 @@ void handle_video_packet(gamepad_context_t *ctx, VideoPacket *vp, size_t size, i
int is_idr = 0;
for (int i = 0; i < sizeof(vp->extended_header); i++) {
if (vp->extended_header[i] == 0x80) {
// print_info("GOT IDR");
// vanilla_log("GOT IDR");
is_idr = 1;
-28
View File
@@ -1,28 +0,0 @@
#include "status.h"
#include <stdio.h>
#include <stdarg.h>
#include "vanilla.h"
static const char *VANILLA_STATUS_STRINGS[] = {
"SUCCESS",
"ERROR",
"READY",
"INFO",
"UNKNOWN_COMMAND",
"INVALID_ARGUMENT"
};
void print_info(const char *errstr, ...)
{
va_list args;
va_start(args, errstr);
// vanilla_log_no_newline(VANILLA_STATUS_STRINGS[-VANILLA_INFO]);
// vanilla_log_no_newline(" ");
vanilla_log_no_newline_va(errstr, args);
vanilla_log_no_newline("\n");
va_end(args);
}
-6
View File
@@ -1,6 +0,0 @@
#ifndef VANILLA_SERVER_STATUS_H
#define VANILLA_SERVER_STATUS_H
void print_info(const char *str, ...);
#endif // VANILLA_SERVER_STATUS_H
+1 -2
View File
@@ -7,7 +7,6 @@
#include <time.h>
#include <unistd.h>
#include "status.h"
#include "vanilla.h"
// TODO: Static variables are undesirable
@@ -15,7 +14,7 @@ int interrupted = 0;
void interrupt_handler(int signum)
{
print_info("INTERRUPT SIGNAL RECEIVED, CANCELLING...");
vanilla_log("INTERRUPT SIGNAL RECEIVED, CANCELLING...");
interrupted = 1;
}
+1 -2
View File
@@ -16,7 +16,6 @@
#include "gamepad/gamepad.h"
#include "gamepad/input.h"
#include "gamepad/video.h"
#include "status.h"
#include "util.h"
#include "vanilla.h"
@@ -34,7 +33,7 @@ void *start_event_loop(void *arg)
int r = WSAStartup(MAKEWORD(2, 2), &wsaData);
if (r != 0) {
char buf[100];
print_info("Failed to WSAStartup: %i\n", r);
vanilla_log("Failed to WSAStartup: %i", r);
pthread_mutex_unlock(&main_mutex);
goto exit;
}
+27 -27
View File
@@ -9,34 +9,34 @@
int main(int argc, const char **argv)
{
if (geteuid() != 0) {
pprint("vanilla-pipe must be run as root\n");
nlprint("vanilla-pipe must be run as root");
return 1;
}
if (argc != 3) {
pprint("vanilla-pipe - brokers a connection between Vanilla and the Wii U\n");
pprint("--------------------------------------------------------------------------------\n");
pprint("\n");
pprint("Usage: %s <-local | -udp> <wireless-interface>\n", argv[0]);
pprint("\n");
pprint("Connecting to the Wii U as a gamepad requires some modifications to the 802.11n\n");
pprint("protocol, and not all platforms allow such modifications to be made.\n");
pprint("Additionally, such modifications usually require root level access, and it can\n");
pprint("be undesirable for various reasons to run a GUI application as root.\n");
pprint("\n");
pprint("This necessitated the creation of `vanilla-pipe`, a thin program that can\n");
pprint("handle connecting to the Wii U in an environment that supports it (e.g. as root,\n");
pprint("and in a Linux VM, or a separate Linux PC) while forwarding all data to the\n");
pprint("user's desired frontend. `libvanilla` has full support for integrating with\n");
pprint("`vanilla-pipe`, so as long as the frontend uses `libvanilla`, it can be used.\n");
pprint("Additionally, since `vanilla-pipe` is fairly simple, it can be ported to\n");
pprint("embedded devices such as MCUs or SBCs, providing more versatility in hardware\n");
pprint("configurations.\n");
pprint("\n");
pprint("`vanilla-pipe` cannot be controlled directly, it can only be controlled via\n");
pprint("sockets by a compatible frontend. By choosing '-local' or '-udp', you can\n");
pprint("choose what type of socket to use to best suit the environment.\n");
pprint("\n");
nlprint("vanilla-pipe - brokers a connection between Vanilla and the Wii U");
nlprint("--------------------------------------------------------------------------------");
nlprint("");
nlprint("Usage: %s <-local | -udp> <wireless-interface>", argv[0]);
nlprint("");
nlprint("Connecting to the Wii U as a gamepad requires some modifications to the 802.11n");
nlprint("protocol, and not all platforms allow such modifications to be made.");
nlprint("Additionally, such modifications usually require root level access, and it can");
nlprint("be undesirable for various reasons to run a GUI application as root.");
nlprint("");
nlprint("This necessitated the creation of `vanilla-pipe`, a thin program that can");
nlprint("handle connecting to the Wii U in an environment that supports it (e.g. as root,");
nlprint("and in a Linux VM, or a separate Linux PC) while forwarding all data to the");
nlprint("user's desired frontend. `libvanilla` has full support for integrating with");
nlprint("`vanilla-pipe`, so as long as the frontend uses `libvanilla`, it can be used.");
nlprint("Additionally, since `vanilla-pipe` is fairly simple, it can be ported to");
nlprint("embedded devices such as MCUs or SBCs, providing more versatility in hardware");
nlprint("configurations.");
nlprint("");
nlprint("`vanilla-pipe` cannot be controlled directly, it can only be controlled via");
nlprint("sockets by a compatible frontend. By choosing '-local' or '-udp', you can");
nlprint("choose what type of socket to use to best suit the environment.");
nlprint("");
return 1;
}
@@ -56,16 +56,16 @@ int main(int argc, const char **argv)
}
if (udp_mode == local_mode) {
pprint("Must choose either '-local' OR '-udp'\n");
nlprint("Must choose either '-local' OR '-udp'");
return 1;
}
if (!wireless_interface) {
pprint("Must identify a wireless interface to use\n");
nlprint("Must identify a wireless interface to use");
return 1;
}
vanilla_listen(local_mode, wireless_interface);
pipe_listen(local_mode, wireless_interface);
return 0;
}
+52 -66
View File
@@ -23,7 +23,6 @@
#include "../def.h"
#include "../ports.h"
#include "dhcp/dhcpc.h"
#include "status.h"
#include "util.h"
#include "vanilla.h"
#include "wpa.h"
@@ -80,26 +79,13 @@ struct relay_info {
#define THREADRESULT(x) ((void *) (uintptr_t) (x))
void lpprint(const char *fmt, va_list args)
{
vfprintf(stderr, fmt, args);
}
void pprint(const char *fmt, ...)
void nlprint(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
lpprint(fmt, args);
va_end(args);
}
void print_info(const char *errstr, ...)
{
va_list args;
va_start(args, errstr);
lpprint(errstr, args);
pprint("\n");
vfprintf(stderr, fmt, args);
fprintf(stderr, "\n");
va_end(args);
}
@@ -122,7 +108,7 @@ int are_relays_running()
void vanilla_pipe_wpa_msg(char *msg, size_t len)
{
print_info("%.*s", len, msg);
nlprint("%.*s", len, msg);
}
void wpa_ctrl_command(struct wpa_ctrl *ctrl, const char *cmd, char *buf, size_t *buf_len)
@@ -157,9 +143,9 @@ void interrupt_relays()
void sigint_handler(int signum)
{
if (signum == SIGINT) {
pprint("RECEIVED INTERRUPT SIGNAL\n");
nlprint("RECEIVED INTERRUPT SIGNAL");
} else if (signum == SIGTERM) {
pprint("RECEIVED TERMINATE SIGNAL\n");
nlprint("RECEIVED TERMINATE SIGNAL");
}
quit_loop();
signal(signum, SIG_DFL);
@@ -205,13 +191,13 @@ void *wpa_setup_environment(void *data)
if (nmcli) {
nmdev = nm_client_get_device_by_iface(nmcli, args->wireless_interface);
if (!nmdev) {
pprint("FAILED TO GET STATUS OF DEVICE %s\n", args->wireless_interface);
nlprint("FAILED TO GET STATUS OF DEVICE %s", args->wireless_interface);
goto die_and_close_nmcli;
}
if ((is_managed = nm_device_get_managed(nmdev))) {
nm_device_set_managed(nmdev, FALSE);
print_info("TEMPORARILY SET %s TO UNMANAGED", args->wireless_interface);
nlprint("TEMPORARILY SET %s TO UNMANAGED", args->wireless_interface);
}
} else {
// Failed to get NetworkManager, host may just not have it?
@@ -230,13 +216,13 @@ void *wpa_setup_environment(void *data)
struct wpa_global *wpa = wpa_supplicant_init(&params);
if (!wpa) {
print_info("FAILED TO INIT WPA SUPPLICANT");
nlprint("FAILED TO INIT WPA SUPPLICANT");
goto die_and_reenable_managed;
}
struct wpa_supplicant *wpa_s = wpa_supplicant_add_iface(wpa, &interface, NULL);
if (!wpa_s) {
print_info("FAILED TO ADD WPA IFACE");
nlprint("FAILED TO ADD WPA IFACE");
goto die_and_kill;
}
@@ -249,12 +235,12 @@ void *wpa_setup_environment(void *data)
struct wpa_ctrl *ctrl;
while (!(ctrl = wpa_ctrl_open(buf))) {
if (is_interrupted()) goto die_and_kill;
print_info("WAITING FOR CTRL INTERFACE");
nlprint("WAITING FOR CTRL INTERFACE");
sleep(1);
}
if (is_interrupted() || wpa_ctrl_attach(ctrl) < 0) {
print_info("FAILED TO ATTACH TO WPA");
nlprint("FAILED TO ATTACH TO WPA");
goto die_and_close;
}
@@ -274,7 +260,7 @@ die_and_kill:
die_and_reenable_managed:
if (is_managed) {
print_info("SETTING %s BACK TO MANAGED", args->wireless_interface);
nlprint("SETTING %s BACK TO MANAGED", args->wireless_interface);
nm_device_set_managed(nmdev, TRUE);
}
@@ -346,10 +332,10 @@ void dhcp_callback(const char *type, char **env, void *data)
rtnl_addr_delete(nl, ra, 0);
rtnl_addr_put(ra);
}
// print_info("GOT DHCP EVENT: %s", type);
// nlprint("GOT DHCP EVENT: %s", type);
// while (*env) {
// char *e = *env;
// print_info(" %s", e);
// nlprint(" %s", e);
// env++;
// }
}
@@ -360,13 +346,13 @@ int call_dhcp(const char *network_interface)
struct nl_sock *nl = nl_socket_alloc();
if (!nl) {
print_info("FAILED TO ALLOC NL_SOCK");
nlprint("FAILED TO ALLOC NL_SOCK");
goto exit;
}
int nlr = nl_connect(nl, NETLINK_ROUTE);
if (nlr < 0) {
print_info("FAILED TO CONNECT NL: %i", nlr);
nlprint("FAILED TO CONNECT NL: %i", nlr);
goto free_socket_and_exit;
}
@@ -403,13 +389,13 @@ void *do_relay(void *data)
if (sendto(ports->to_socket, buf, read_size, 0, (const struct sockaddr *) &ports->to_address, ports->to_address_size) == -1) {
if (ports->to_address_size == sizeof(struct sockaddr_un)) {
print_info("FAILED TO SENDTO \"%s\" (%i)", ports->to_address.un.sun_path, errno);
nlprint("FAILED TO SENDTO \"%s\" (%i)", ports->to_address.un.sun_path, errno);
} else if (ports->to_address_size == sizeof(struct sockaddr_in)) {
char ip[20];
inet_ntop(AF_INET, &ports->to_address.in.sin_addr, ip, sizeof(ip));
print_info("FAILED TO SENDTO %s:%u (%i)", ip, ports->to_address.in.sin_port, errno);
nlprint("FAILED TO SENDTO %s:%u (%i)", ip, ports->to_address.in.sin_port, errno);
} else {
print_info("FAILED TO SENDTO - INVALID SIZE: %zu", ports->to_address_size);
nlprint("FAILED TO SENDTO - INVALID SIZE: %zu", ports->to_address_size);
}
}
}
@@ -454,11 +440,11 @@ int open_socket(int local, in_port_t port)
setsockopt(skt, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
if (bind(skt, (const struct sockaddr *) &sa, sa_size) == -1) {
print_info("FAILED TO BIND PORT %u: %i", port, errno);
nlprint("FAILED TO BIND PORT %u: %i", port, errno);
close(skt);
return -1;
} else {
// print_info("BOUND PORT %u", port);
// nlprint("BOUND PORT %u", port);
}
return skt;
@@ -504,9 +490,9 @@ void *open_relay(void *data)
frontend_addr_size = sizeof(frontend_addr.in);
}
// print_info("ENTERING MAIN LOOP");
// nlprint("ENTERING MAIN LOOP");
while (are_relays_running()) {
print_info("STARTED RELAYS");
nlprint("STARTED RELAYS");
relay_ports console_to_frontend = create_ports(from_console, from_frontend, &frontend_addr, frontend_addr_size);
relay_ports frontend_to_console = create_ports(from_frontend, from_console, (sockaddr_u *) &console_addr, sizeof(struct sockaddr_in));
@@ -517,9 +503,9 @@ void *open_relay(void *data)
pthread_join(a_thread, NULL);
pthread_join(b_thread, NULL);
print_info("STOPPED RELAYS");
nlprint("STOPPED RELAYS");
// print_info("RELAY EXITED");
// nlprint("RELAY EXITED");
}
ret = 0;
@@ -570,7 +556,7 @@ void create_all_relays(struct sync_args *args)
size_t buf_len = sizeof(buf);
if (wpa_ctrl_recv(args->ctrl, buf, &buf_len) == 0) {
if (!memcmp(buf, "<3>CTRL-EVENT-DISCONNECTED", 26)) {
print_info("Wii U disconnected, attempting to re-connect...");
nlprint("Wii U disconnected, attempting to re-connect...");
// Let client know we lost connection
cmd.control_code = VANILLA_PIPE_CC_DISCONNECTED;
@@ -686,7 +672,7 @@ int create_connect_config(const char *filename, unsigned char *bssid, unsigned c
{
FILE *out_file = fopen(filename, "w");
if (!out_file) {
print_info("FAILED TO OPEN OUTPUT CONFIG FILE");
nlprint("FAILED TO OPEN OUTPUT CONFIG FILE");
return VANILLA_ERR_GENERIC;
}
@@ -755,32 +741,32 @@ void *sync_with_console_internal(void *data)
goto exit_loop;
}
// print_info("SCANNING");
// nlprint("SCANNING");
actual_buf_len = buf_len;
wpa_ctrl_command(args->ctrl, "SCAN", buf, &actual_buf_len);
if (!memcmp(buf, "FAIL-BUSY", 9)) {
//print_info("DEVICE BUSY, RETRYING");
//nlprint("DEVICE BUSY, RETRYING");
sleep(5);
} else if (!memcmp(buf, "OK", 2)) {
break;
} else {
print_info("UNKNOWN SCAN RESPONSE: %.*s (RETRYING)", actual_buf_len, buf);
nlprint("UNKNOWN SCAN RESPONSE: %.*s (RETRYING)", actual_buf_len, buf);
sleep(5);
}
}
//print_info("WAITING FOR SCAN RESULTS");
//nlprint("WAITING FOR SCAN RESULTS");
actual_buf_len = buf_len;
wpa_ctrl_command(args->ctrl, "SCAN_RESULTS", buf, &actual_buf_len);
print_info("RECEIVED SCAN RESULTS");
nlprint("RECEIVED SCAN RESULTS");
const char *line = strtok(buf, "\n");
while (line) {
if (is_interrupted()) goto exit_loop;
if (strstr(line, "WiiU") && strstr(line, "_STA1")) {
print_info("FOUND WII U, TESTING WPS PIN");
nlprint("FOUND WII U, TESTING WPS PIN");
// Make copy of bssid for later
strncpy(bssid, line, sizeof(bssid));
@@ -808,7 +794,7 @@ void *sync_with_console_internal(void *data)
// If we haven't gotten any information yet, wait one second and try again
wait_count++;
if (wait_count == max_wait) {
print_info("GIVING UP, RETURNING TO SCANNING");
nlprint("GIVING UP, RETURNING TO SCANNING");
break;
} else {
sleep(1);
@@ -822,11 +808,11 @@ void *sync_with_console_internal(void *data)
wpa_ctrl_recv(args->ctrl, buf, &actual_buf_len);
if (!strstr(buf, "CTRL-EVENT-BSS-ADDED")
&& !strstr(buf, "CTRL-EVENT-BSS-REMOVED")) {
print_info("CRED RECV: %.*s", buf_len, buf);
nlprint("CRED RECV: %.*s", buf_len, buf);
}
if (!memcmp("<3>WPS-CRED-RECEIVED", buf, 20)) {
print_info("RECEIVED AUTHENTICATION FROM CONSOLE");
nlprint("RECEIVED AUTHENTICATION FROM CONSOLE");
cred_received = 1;
break;
}
@@ -838,7 +824,7 @@ void *sync_with_console_internal(void *data)
// Tell wpa_supplicant to save config (this seems to be the only way to retrieve the PSK)
actual_buf_len = buf_len;
print_info("SAVING CONFIG", actual_buf_len, buf);
nlprint("SAVING CONFIG", actual_buf_len, buf);
wpa_ctrl_command(args->ctrl, "SAVE_CONFIG", buf, &actual_buf_len);
// Retrieve BSSID and PSK from saved config
@@ -864,7 +850,7 @@ void *sync_with_console_internal(void *data)
ret = VANILLA_SUCCESS;
} else {
// TODO: Return error to the frontend
print_info("FAILED TO OPEN INPUT CONFIG FILE TO RETRIEVE PSK");
nlprint("FAILED TO OPEN INPUT CONFIG FILE TO RETRIEVE PSK");
}
goto exit_loop;
@@ -886,7 +872,7 @@ void *do_connect(void *data)
while (1) {
while (!wpa_ctrl_pending(args->ctrl)) {
sleep(2);
print_info("WAITING FOR CONNECTION");
nlprint("WAITING FOR CONNECTION");
if (is_interrupted()) return THREADRESULT(VANILLA_ERR_GENERIC);
}
@@ -896,7 +882,7 @@ void *do_connect(void *data)
wpa_ctrl_recv(args->ctrl, buf, &actual_buf_len);
if (!strstr(buf, "CTRL-EVENT-BSS-ADDED")
&& !strstr(buf, "CTRL-EVENT-BSS-REMOVED")) {
print_info("CONN RECV: %.*s", actual_buf_len, buf);
nlprint("CONN RECV: %.*s", actual_buf_len, buf);
}
if (memcmp(buf, "<3>CTRL-EVENT-CONNECTED", 23) == 0) {
@@ -906,15 +892,15 @@ void *do_connect(void *data)
if (is_interrupted()) return THREADRESULT(VANILLA_ERR_GENERIC);
}
print_info("CONNECTED TO CONSOLE");
nlprint("CONNECTED TO CONSOLE");
// Use DHCP on interface
int r = call_dhcp(args->wireless_interface);
if (r != VANILLA_SUCCESS) {
print_info("FAILED TO RUN DHCP ON %s", args->wireless_interface);
nlprint("FAILED TO RUN DHCP ON %s", args->wireless_interface);
return THREADRESULT(r);
} else {
print_info("DHCP ESTABLISHED");
nlprint("DHCP ESTABLISHED");
}
create_all_relays(args);
@@ -933,7 +919,7 @@ void *vanilla_sync_with_console(void *data)
wireless_conf_file = get_wireless_authenticate_config_filename();
config = fopen(wireless_conf_file, "w");
if (!config) {
print_info("FAILED TO WRITE TEMP CONFIG: %s", wireless_conf_file);
nlprint("FAILED TO WRITE TEMP CONFIG: %s", wireless_conf_file);
return THREADRESULT(VANILLA_ERR_GENERIC);
}
@@ -958,14 +944,14 @@ void *vanilla_connect_to_console(void *data)
return wpa_setup_environment(args);
}
void vanilla_listen(int local, const char *wireless_interface)
void pipe_listen(int local, const char *wireless_interface)
{
// Ensure local domain sockets can be written to by everyone
umask(0000);
int skt = open_socket(local, VANILLA_PIPE_CMD_SERVER_PORT);
if (skt == -1) {
pprint("Failed to open server socket\n");
nlprint("Failed to open server socket");
return;
}
@@ -987,7 +973,7 @@ void vanilla_listen(int local, const char *wireless_interface)
pthread_mutex_lock(&main_loop_mutex);
pprint("READY\n");
nlprint("READY");
while (main_loop) {
pthread_mutex_unlock(&main_loop_mutex);
@@ -1020,24 +1006,24 @@ void vanilla_listen(int local, const char *wireless_interface)
// Acknowledge
cmd.control_code = VANILLA_PIPE_CC_BIND_ACK;
if (sendto(skt, &cmd, sizeof(cmd.control_code), 0, (const struct sockaddr *) &addr, addr_size) == -1) {
print_info("FAILED TO SEND ACK: %i", errno);
nlprint("FAILED TO SEND ACK: %i", errno);
}
pthread_t thread;
int thread_ret;
if (pthread_create(&thread, NULL, thread_handler, args) != 0) {
print_info("FAILED TO CREATE THREAD");
nlprint("FAILED TO CREATE THREAD");
free(args);
}
} else {
// Busy
cmd.control_code = VANILLA_PIPE_CC_BUSY;
if (sendto(skt, &cmd, sizeof(cmd.control_code), 0, (const struct sockaddr *) &addr, addr_size) == -1) {
print_info("FAILED TO SEND BUSY: %i", errno);
nlprint("FAILED TO SEND BUSY: %i", errno);
}
}
} else if (cmd.control_code == VANILLA_PIPE_CC_UNBIND) {
print_info("RECEIVED UNBIND SIGNAL");
nlprint("RECEIVED UNBIND SIGNAL");
interrupt();
} else if (cmd.control_code == VANILLA_PIPE_CC_QUIT) {
quit_loop();
+2 -2
View File
@@ -15,8 +15,8 @@ int is_networkmanager_managing_device(const char *wireless_interface, int *is_ma
int disable_networkmanager_on_device(const char *wireless_interface);
int enable_networkmanager_on_device(const char *wireless_interface);
void pprint(const char *fmt, ...);
void nlprint(const char *fmt, ...);
void vanilla_listen(int local, const char *wireless_interface);
void pipe_listen(int local, const char *wireless_interface);
#endif // VANILLA_WPA_H