1
1
mod aoa;
2
2
mod bluetooth;
3
+ mod config;
3
4
mod ev;
4
5
mod io_uring;
5
6
mod mitm;
6
7
mod usb_gadget;
7
8
mod usb_stream;
8
9
9
- use bluer :: Address ;
10
+ use crate :: config :: AppConfig ;
10
11
use bluetooth:: bluetooth_setup_connection;
11
12
use bluetooth:: bluetooth_stop;
12
13
use clap:: Parser ;
@@ -17,12 +18,8 @@ use simplelog::*;
17
18
use usb_gadget:: uevent_listener;
18
19
use usb_gadget:: UsbGadgetState ;
19
20
20
- use serde:: de:: { self , Deserializer , Error as DeError , Visitor } ;
21
- use serde:: Deserialize ;
22
- use std:: fmt:: { self , Display } ;
23
21
use std:: fs:: OpenOptions ;
24
22
use std:: path:: PathBuf ;
25
- use std:: str:: FromStr ;
26
23
use std:: sync:: Arc ;
27
24
use std:: time:: Duration ;
28
25
use tokio:: runtime:: Builder ;
@@ -36,63 +33,6 @@ const DEFAULT_WLAN_ADDR: &str = "10.0.0.1";
36
33
const TCP_SERVER_PORT : i32 = 5288 ;
37
34
const TCP_DHU_PORT : i32 = 5277 ;
38
35
39
- #[ derive( clap:: ValueEnum , Default , Debug , PartialEq , PartialOrd , Clone , Copy , Deserialize ) ]
40
- pub enum HexdumpLevel {
41
- #[ default]
42
- Disabled ,
43
- DecryptedInput ,
44
- RawInput ,
45
- DecryptedOutput ,
46
- RawOutput ,
47
- All ,
48
- }
49
-
50
- #[ derive( Debug , Clone ) ]
51
- struct UsbId {
52
- vid : u16 ,
53
- pid : u16 ,
54
- }
55
-
56
- impl std:: str:: FromStr for UsbId {
57
- type Err = String ;
58
-
59
- fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
60
- let parts: Vec < & str > = s. split ( ':' ) . collect ( ) ;
61
- if parts. len ( ) != 2 {
62
- return Err ( "Expected format VID:PID" . to_string ( ) ) ;
63
- }
64
- let vid = u16:: from_str_radix ( parts[ 0 ] , 16 ) . map_err ( |e| e. to_string ( ) ) ?;
65
- let pid = u16:: from_str_radix ( parts[ 1 ] , 16 ) . map_err ( |e| e. to_string ( ) ) ?;
66
- Ok ( UsbId { vid, pid } )
67
- }
68
- }
69
-
70
- impl < ' de > Deserialize < ' de > for UsbId {
71
- fn deserialize < D > ( deserializer : D ) -> Result < UsbId , D :: Error >
72
- where
73
- D : Deserializer < ' de > ,
74
- {
75
- struct UsbIdVisitor ;
76
-
77
- impl < ' de > Visitor < ' de > for UsbIdVisitor {
78
- type Value = UsbId ;
79
-
80
- fn expecting ( & self , formatter : & mut fmt:: Formatter ) -> fmt:: Result {
81
- formatter. write_str ( "a string in the format VID:PID" )
82
- }
83
-
84
- fn visit_str < E > ( self , value : & str ) -> Result < UsbId , E >
85
- where
86
- E : de:: Error ,
87
- {
88
- UsbId :: from_str ( value) . map_err ( de:: Error :: custom)
89
- }
90
- }
91
-
92
- deserializer. deserialize_str ( UsbIdVisitor )
93
- }
94
- }
95
-
96
36
/// AndroidAuto wired/wireless proxy
97
37
#[ derive( Parser , Debug ) ]
98
38
#[ clap( version, long_about = None , about = format!(
@@ -112,103 +52,6 @@ struct Args {
112
52
config : PathBuf ,
113
53
}
114
54
115
- pub fn empty_string_as_none < ' de , T , D > ( deserializer : D ) -> Result < Option < T > , D :: Error >
116
- where
117
- T : FromStr ,
118
- T :: Err : Display ,
119
- D : Deserializer < ' de > ,
120
- {
121
- let s: String = Deserialize :: deserialize ( deserializer) ?;
122
- if s. trim ( ) . is_empty ( ) {
123
- Ok ( None )
124
- } else {
125
- T :: from_str ( & s) . map ( Some ) . map_err ( DeError :: custom)
126
- }
127
- }
128
-
129
- #[ derive( Debug , Clone , Deserialize ) ]
130
- #[ serde( default ) ]
131
- pub struct AppConfig {
132
- advertise : bool ,
133
- debug : bool ,
134
- hexdump_level : HexdumpLevel ,
135
- disable_console_debug : bool ,
136
- legacy : bool ,
137
- #[ serde( default , deserialize_with = "empty_string_as_none" ) ]
138
- connect : Option < Address > ,
139
- logfile : PathBuf ,
140
- stats_interval : u16 ,
141
- #[ serde( default , deserialize_with = "empty_string_as_none" ) ]
142
- udc : Option < String > ,
143
- iface : String ,
144
- hostapd_conf : PathBuf ,
145
- #[ serde( default , deserialize_with = "empty_string_as_none" ) ]
146
- btalias : Option < String > ,
147
- keepalive : bool ,
148
- timeout_secs : u16 ,
149
- bt_timeout_secs : u16 ,
150
- mitm : bool ,
151
- dpi : u16 ,
152
- remove_tap_restriction : bool ,
153
- video_in_motion : bool ,
154
- disable_media_sink : bool ,
155
- disable_tts_sink : bool ,
156
- developer_mode : bool ,
157
- #[ serde( default , deserialize_with = "empty_string_as_none" ) ]
158
- wired : Option < UsbId > ,
159
- dhu : bool ,
160
- ev : bool ,
161
- #[ serde( default , deserialize_with = "empty_string_as_none" ) ]
162
- ev_battery_logger : Option < PathBuf > ,
163
- ev_battery_capacity : u64 ,
164
- ev_factor : f32 ,
165
- }
166
-
167
- impl Default for AppConfig {
168
- fn default ( ) -> Self {
169
- Self {
170
- advertise : false ,
171
- debug : false ,
172
- hexdump_level : HexdumpLevel :: Disabled ,
173
- disable_console_debug : false ,
174
- legacy : true ,
175
- connect : None ,
176
- logfile : "/var/log/aa-proxy-rs.log" . into ( ) ,
177
- stats_interval : 0 ,
178
- udc : None ,
179
- iface : "wlan0" . to_string ( ) ,
180
- hostapd_conf : "/var/run/hostapd.conf" . into ( ) ,
181
- btalias : None ,
182
- keepalive : false ,
183
- timeout_secs : 10 ,
184
- bt_timeout_secs : 120 ,
185
- mitm : false ,
186
- dpi : 0 ,
187
- remove_tap_restriction : false ,
188
- video_in_motion : false ,
189
- disable_media_sink : false ,
190
- disable_tts_sink : false ,
191
- developer_mode : false ,
192
- wired : None ,
193
- dhu : false ,
194
- ev : false ,
195
- ev_battery_logger : None ,
196
- ev_battery_capacity : 22000 ,
197
- ev_factor : 0.075 ,
198
- }
199
- }
200
- }
201
-
202
- fn load_config ( config_file : PathBuf ) -> Result < AppConfig , Box < dyn std:: error:: Error > > {
203
- let file_config: AppConfig = config:: Config :: builder ( )
204
- . add_source ( config:: File :: from ( config_file) . required ( false ) )
205
- . build ( ) ?
206
- . try_deserialize ( )
207
- . unwrap_or_default ( ) ;
208
-
209
- Ok ( file_config)
210
- }
211
-
212
55
#[ derive( Clone ) ]
213
56
struct WifiConfig {
214
57
ip_addr : String ,
@@ -392,7 +235,7 @@ fn main() {
392
235
let args = Args :: parse ( ) ;
393
236
394
237
// parse config
395
- let config = load_config ( args. config . clone ( ) ) . unwrap ( ) ;
238
+ let config = config :: load_config ( args. config . clone ( ) ) . unwrap ( ) ;
396
239
397
240
logging_init ( config. debug , config. disable_console_debug , & config. logfile ) ;
398
241
info ! (
0 commit comments