@@ -67,6 +67,8 @@ struct sync_args {
67
67
int skt ;
68
68
sockaddr_u client ;
69
69
size_t client_size ;
70
+ sockaddr_u cmd_client ;
71
+ size_t cmd_client_size ;
70
72
};
71
73
72
74
struct relay_info {
@@ -223,7 +225,7 @@ void *wpa_setup_environment(void *data)
223
225
interface .driver = "nl80211" ;
224
226
interface .ifname = args -> wireless_interface ;
225
227
interface .confname = args -> wireless_config ;
226
-
228
+
227
229
struct wpa_global * wpa = wpa_supplicant_init (& params );
228
230
if (!wpa ) {
229
231
nlprint ("FAILED TO INIT WPA SUPPLICANT" );
@@ -329,7 +331,7 @@ void dhcp_callback(const char *type, char **env, void *data)
329
331
330
332
// Send request
331
333
nl_send_auto_complete (nl , msg );
332
-
334
+
333
335
// Cleanup
334
336
nlmsg_free (msg );
335
337
rtnl_addr_put (ra );
@@ -359,7 +361,7 @@ int call_dhcp(const char *network_interface)
359
361
nlprint ("FAILED TO ALLOC NL_SOCK" );
360
362
goto exit ;
361
363
}
362
-
364
+
363
365
int nlr = nl_connect (nl , NETLINK_ROUTE );
364
366
if (nlr < 0 ) {
365
367
nlprint ("FAILED TO CONNECT NL: %i" , nlr );
@@ -448,7 +450,7 @@ int open_socket(int local, in_port_t port)
448
450
struct timeval tv = {0 };
449
451
tv .tv_usec = 250000 ;
450
452
setsockopt (skt , SOL_SOCKET , SO_RCVTIMEO , & tv , sizeof (tv ));
451
-
453
+
452
454
if (bind (skt , (const struct sockaddr * ) & sa , sa_size ) == -1 ) {
453
455
nlprint ("FAILED TO BIND PORT %u: %i" , port , errno );
454
456
close (skt );
@@ -540,7 +542,7 @@ void create_all_relays(struct sync_args *args)
540
542
vid_info .local = aud_info .local = msg_info .local = cmd_info .local = hid_info .local = args -> local ;
541
543
vid_info .client = aud_info .client = msg_info .client = cmd_info .client = hid_info .client = args -> client ;
542
544
vid_info .client_size = aud_info .client_size = msg_info .client_size = cmd_info .client_size = hid_info .client_size = args -> client_size ;
543
-
545
+
544
546
vid_info .port = PORT_VID ;
545
547
aud_info .port = PORT_AUD ;
546
548
msg_info .port = PORT_MSG ;
@@ -559,7 +561,7 @@ void create_all_relays(struct sync_args *args)
559
561
// Notify client that we are connected
560
562
vanilla_pipe_command_t cmd ;
561
563
cmd .control_code = VANILLA_PIPE_CC_CONNECTED ;
562
- sendto (args -> skt , & cmd , sizeof (cmd .control_code ), 0 , (const struct sockaddr * ) & args -> client , args -> client_size );
564
+ sendto (args -> skt , & cmd , sizeof (cmd .control_code ), 0 , (const struct sockaddr * ) & args -> cmd_client , args -> cmd_client_size );
563
565
564
566
while (!is_interrupted ()) {
565
567
char buf [1024 ];
@@ -570,7 +572,7 @@ void create_all_relays(struct sync_args *args)
570
572
571
573
// Let client know we lost connection
572
574
cmd .control_code = VANILLA_PIPE_CC_DISCONNECTED ;
573
- sendto (args -> skt , & cmd , sizeof (cmd .control_code ), 0 , (const struct sockaddr * ) & args -> client , args -> client_size );
575
+ sendto (args -> skt , & cmd , sizeof (cmd .control_code ), 0 , (const struct sockaddr * ) & args -> cmd_client , args -> cmd_client_size );
574
576
575
577
break ;
576
578
}
@@ -596,14 +598,14 @@ void *thread_handler(void *data)
596
598
pthread_mutex_unlock (& running_mutex );
597
599
598
600
void * ret = args -> start_routine (data );
599
-
601
+
600
602
free (args );
601
603
602
604
interrupt ();
603
605
604
606
// Locked by calling thread
605
607
pthread_mutex_unlock (& action_mutex );
606
-
608
+
607
609
return ret ;
608
610
}
609
611
@@ -679,7 +681,7 @@ void bytes_to_str(unsigned char *data, size_t data_size, const char *separator,
679
681
}
680
682
681
683
int create_connect_config (const char * filename , unsigned char * bssid , unsigned char * psk )
682
- {
684
+ {
683
685
FILE * out_file = fopen (filename , "w" );
684
686
if (!out_file ) {
685
687
nlprint ("FAILED TO OPEN OUTPUT CONFIG FILE" );
@@ -703,7 +705,7 @@ int create_connect_config(const char *filename, unsigned char *bssid, unsigned c
703
705
" pbss=2\n"
704
706
"}\n"
705
707
"\n" ;
706
-
708
+
707
709
char bssid_str [18 ];
708
710
char ssid_str [17 ];
709
711
char psk_str [65 ];
@@ -724,7 +726,7 @@ ssize_t send_ping_to_client(struct sync_args *args)
724
726
{
725
727
vanilla_pipe_command_t cmd ;
726
728
cmd .control_code = VANILLA_PIPE_CC_PING ;
727
- return sendto (args -> skt , & cmd , sizeof (cmd .control_code ), 0 , (const struct sockaddr * ) & args -> client , args -> client_size );
729
+ return sendto (args -> skt , & cmd , sizeof (cmd .control_code ), 0 , (const struct sockaddr * ) & args -> cmd_client , args -> cmd_client_size );
728
730
}
729
731
730
732
void * sync_with_console_internal (void * data )
@@ -855,7 +857,7 @@ void *sync_with_console_internal(void *data)
855
857
// Convert BSSID from string to bytes
856
858
str_to_bytes (bssid , 1 , cmd .connection .bssid .bssid , sizeof (cmd .connection .bssid .bssid ));
857
859
858
- sendto (args -> skt , & cmd , sizeof (cmd .control_code ) + sizeof (cmd .connection ), 0 , (const struct sockaddr * ) & args -> client , args -> client_size );
860
+ sendto (args -> skt , & cmd , sizeof (cmd .control_code ) + sizeof (cmd .connection ), 0 , (const struct sockaddr * ) & args -> cmd_client , args -> cmd_client_size );
859
861
860
862
ret = VANILLA_SUCCESS ;
861
863
} else {
@@ -883,27 +885,31 @@ void *do_connect(void *data)
883
885
while (!wpa_ctrl_pending (args -> ctrl )) {
884
886
sleep (2 );
885
887
nlprint ("WAITING FOR CONNECTION" );
886
-
888
+
887
889
if (is_interrupted ()) return THREADRESULT (VANILLA_ERR_GENERIC );
888
890
}
889
-
891
+
890
892
char buf [1024 ];
891
893
size_t actual_buf_len = sizeof (buf );
892
894
wpa_ctrl_recv (args -> ctrl , buf , & actual_buf_len );
893
895
if (!strstr (buf , "CTRL-EVENT-BSS-ADDED" )
894
896
&& !strstr (buf , "CTRL-EVENT-BSS-REMOVED" )) {
895
897
nlprint ("CONN RECV: %.*s" , actual_buf_len , buf );
896
898
}
897
-
899
+
898
900
if (memcmp (buf , "<3>CTRL-EVENT-CONNECTED" , 23 ) == 0 ) {
899
901
break ;
900
902
}
901
-
903
+
904
+ // if (memcmp(buf, "<3>CTRL-EVENT-WPA-ASSOC-REJECT") == 0) {
905
+ // TODO: Return result that informs user that their hardware is incompatible
906
+ // }
907
+
902
908
if (is_interrupted ()) return THREADRESULT (VANILLA_ERR_GENERIC );
903
909
}
904
-
910
+
905
911
nlprint ("CONNECTED TO CONSOLE" );
906
-
912
+
907
913
// Use DHCP on interface
908
914
int r = call_dhcp (args -> wireless_interface );
909
915
if (r != VANILLA_SUCCESS ) {
@@ -912,7 +918,7 @@ void *do_connect(void *data)
912
918
} else {
913
919
nlprint ("DHCP ESTABLISHED" );
914
920
}
915
-
921
+
916
922
create_all_relays (args );
917
923
}
918
924
@@ -998,14 +1004,16 @@ void pipe_listen(int local, const char *wireless_interface, const char *log_file
998
1004
goto repeat_loop ;
999
1005
}
1000
1006
1001
- if (cmd .control_code == VANILLA_PIPE_CC_SYNC || cmd .control_code == VANILLA_PIPE_CC_CONNECT ) {
1007
+ if (cmd .control_code == VANILLA_PIPE_CC_SYNC || cmd .control_code == VANILLA_PIPE_CC_CONNECT || cmd . control_code == VANILLA_PIPE_CC_PASSTHRU ) {
1002
1008
if (pthread_mutex_trylock (& action_mutex ) == 0 ) {
1003
1009
struct sync_args * args = malloc (sizeof (struct sync_args ));
1004
1010
args -> wireless_interface = wireless_interface ;
1005
1011
args -> local = local ;
1006
1012
args -> skt = skt ;
1007
1013
args -> client = addr ;
1008
1014
args -> client_size = addr_size ;
1015
+ args -> cmd_client = addr ;
1016
+ args -> cmd_client_size = addr_size ;
1009
1017
1010
1018
if (cmd .control_code == VANILLA_PIPE_CC_SYNC ) {
1011
1019
args -> code = ntohs (cmd .sync .code );
@@ -1014,8 +1022,15 @@ void pipe_listen(int local, const char *wireless_interface, const char *log_file
1014
1022
memcpy (args -> bssid , cmd .connection .bssid .bssid , sizeof (cmd .connection .bssid .bssid ));
1015
1023
memcpy (args -> psk , cmd .connection .psk .psk , sizeof (cmd .connection .psk .psk ));
1016
1024
args -> start_routine = vanilla_connect_to_console ;
1025
+
1026
+ if (cmd .control_code == VANILLA_PIPE_CC_PASSTHRU ) {
1027
+ // Pass to real gamepad on the network whose IP is 192.168.1.11
1028
+ args -> client .in .sin_family = AF_INET ;
1029
+ args -> client .in .sin_addr .s_addr = inet_addr ("192.168.1.11" );
1030
+ args -> client_size = sizeof (struct sockaddr_in );
1031
+ }
1017
1032
}
1018
-
1033
+
1019
1034
// Acknowledge
1020
1035
cmd .control_code = VANILLA_PIPE_CC_BIND_ACK ;
1021
1036
if (sendto (skt , & cmd , sizeof (cmd .control_code ), 0 , (const struct sockaddr * ) & addr , addr_size ) == -1 ) {
@@ -1065,4 +1080,4 @@ void pipe_listen(int local, const char *wireless_interface, const char *log_file
1065
1080
int vanilla_has_config ()
1066
1081
{
1067
1082
return (access (get_wireless_connect_config_filename (), F_OK ) == 0 );
1068
- }
1083
+ }
0 commit comments