@@ -4,6 +4,7 @@ use serde::de::{self, Deserializer, Error as DeError, Visitor};
44use serde:: { Deserialize , Serialize } ;
55use serde_with:: serde_as;
66use simplelog:: * ;
7+ use std:: process:: Command ;
78use std:: {
89 fmt:: { self , Display } ,
910 fs,
@@ -224,8 +225,27 @@ impl Default for ConfigJson {
224225 }
225226}
226227
228+ fn supports_5ghz_wifi ( ) -> std:: io:: Result < bool > {
229+ // Run the command `iw list`
230+ let output = Command :: new ( "iw" ) . arg ( "list" ) . output ( ) ?;
231+
232+ // Convert the command output bytes to a string
233+ let stdout = String :: from_utf8_lossy ( & output. stdout ) ;
234+
235+ // Iterate over each line in the output
236+ for line in stdout. lines ( ) {
237+ // Check if the line contains expected freq
238+ if line. contains ( "5180.0 MHz" ) {
239+ return Ok ( true ) ;
240+ }
241+ }
242+
243+ Ok ( false )
244+ }
245+
227246impl Default for AppConfig {
228247 fn default ( ) -> Self {
248+ let band_a = supports_5ghz_wifi ( ) . unwrap_or ( false ) ;
229249 Self {
230250 advertise : false ,
231251 dongle_mode : false ,
@@ -261,9 +281,22 @@ impl Default for AppConfig {
261281 action_requested : None ,
262282 ev_connector_types : None ,
263283 enable_ssh : true ,
264- hw_mode : "g" . to_string ( ) ,
284+ hw_mode : {
285+ if band_a {
286+ "a"
287+ } else {
288+ "g"
289+ }
290+ }
291+ . to_string ( ) ,
265292 country_code : "US" . to_string ( ) ,
266- channel : 6 ,
293+ channel : {
294+ if band_a {
295+ 36
296+ } else {
297+ 6
298+ }
299+ } ,
267300 ssid : String :: from ( IDENTITY_NAME ) ,
268301 wpa_passphrase : String :: from ( IDENTITY_NAME ) ,
269302 }
0 commit comments