@@ -61,6 +61,70 @@ constexpr const char* kArtosynUsbProduct = "0x8030";
6161
6262std::vector<WifiCardInfo> g_wifi_cards;
6363bool g_wifi_initialized = false ;
64+ bool is_openhd_wifibroadcast_type (const std::string& type_name);
65+
66+ void log_wifi (const std::string& message) {
67+ std::cerr << " [sysutils][wifi] " << message << std::endl;
68+ }
69+
70+ std::string join_strings (const std::vector<std::string>& values,
71+ const char * separator) {
72+ std::ostringstream out;
73+ for (std::size_t i = 0 ; i < values.size (); ++i) {
74+ if (i > 0 ) {
75+ out << separator;
76+ }
77+ out << values[i];
78+ }
79+ return out.str ();
80+ }
81+
82+ std::string card_short_description (const WifiCardInfo& card) {
83+ std::ostringstream out;
84+ out << " iface=" << card.interface_name
85+ << " phy=" << card.phy_index
86+ << " driver=" << (card.driver_name .empty () ? " <none>" : card.driver_name )
87+ << " detected=" << (card.detected_type .empty () ? " <none>" : card.detected_type )
88+ << " type=" << (card.effective_type .empty () ? " <none>" : card.effective_type )
89+ << " vendor=" << (card.vendor_id .empty () ? " <none>" : card.vendor_id )
90+ << " device=" << (card.device_id .empty () ? " <none>" : card.device_id );
91+ if (card.disabled ) {
92+ out << " disabled=true" ;
93+ }
94+ return out.str ();
95+ }
96+
97+ void log_wifi_detection_summary (const std::vector<WifiCardInfo>& cards) {
98+ if (cards.empty ()) {
99+ log_wifi (" No Wi-Fi cards detected." );
100+ return ;
101+ }
102+
103+ std::vector<std::string> openhd_cards;
104+ std::vector<std::string> non_openhd_cards;
105+ std::vector<std::string> disabled_cards;
106+ for (const auto & card : cards) {
107+ if (card.disabled ) {
108+ disabled_cards.push_back (card.interface_name + " (override=DISABLED)" );
109+ continue ;
110+ }
111+ if (is_openhd_wifibroadcast_type (card.effective_type )) {
112+ openhd_cards.push_back (card.interface_name + " (" + card.effective_type + " )" );
113+ } else {
114+ non_openhd_cards.push_back (card.interface_name + " (" + card.effective_type + " )" );
115+ }
116+ }
117+
118+ if (!openhd_cards.empty ()) {
119+ log_wifi (" OpenHD-compatible card(s): " + join_strings (openhd_cards, " , " ));
120+ } else if (!non_openhd_cards.empty ()) {
121+ log_wifi (" No OpenHD-compatible card found. Non-OpenHD card(s): " +
122+ join_strings (non_openhd_cards, " , " ));
123+ } else {
124+ log_wifi (" No OpenHD-compatible card found. All detected card(s) are disabled: " +
125+ join_strings (disabled_cards, " , " ));
126+ }
127+ }
64128
65129struct WifiTxPowerOverride {
66130 std::string tx_power;
@@ -289,6 +353,7 @@ std::unordered_map<std::string, std::string> load_overrides() {
289353 std::unordered_map<std::string, std::string> overrides;
290354 std::ifstream file (kOverridesPath );
291355 if (!file) {
356+ log_wifi (std::string (" override file not found or unreadable: " ) + kOverridesPath );
292357 return overrides;
293358 }
294359 std::string line;
@@ -471,10 +536,14 @@ std::vector<WifiCardProfile> load_wifi_card_profiles() {
471536 std::vector<WifiCardProfile> profiles;
472537 auto content = read_file (kWifiCardsPath );
473538 if (!content) {
539+ log_wifi (std::string (" wifi card profile file not found/unreadable, using defaults: " ) +
540+ kWifiCardsPath );
474541 return default_wifi_card_profiles ();
475542 }
476543 auto objects = extract_array_objects (*content, " cards" );
477544 if (objects.empty ()) {
545+ log_wifi (std::string (" wifi profile list empty/invalid in " ) + kWifiCardsPath +
546+ " , using defaults." );
478547 return default_wifi_card_profiles ();
479548 }
480549
@@ -560,8 +629,12 @@ std::vector<WifiCardProfile> load_wifi_card_profiles() {
560629 profiles.push_back (profile);
561630 }
562631 if (profiles.empty ()) {
632+ log_wifi (std::string (" no valid wifi profiles loaded from " ) + kWifiCardsPath +
633+ " , using defaults." );
563634 return default_wifi_card_profiles ();
564635 }
636+ log_wifi (" Loaded " + std::to_string (profiles.size ()) +
637+ " Wi-Fi card profile(s) from " + kWifiCardsPath + " ." );
565638 return profiles;
566639}
567640
@@ -597,6 +670,8 @@ std::unordered_map<std::string, WifiTxPowerOverride> load_tx_power_overrides() {
597670 std::unordered_map<std::string, WifiTxPowerOverride> overrides;
598671 std::ifstream file (kTxPowerOverridesPath );
599672 if (!file) {
673+ log_wifi (std::string (" TX power override file not found or unreadable: " ) +
674+ kTxPowerOverridesPath );
600675 return overrides;
601676 }
602677 std::string line;
@@ -643,6 +718,10 @@ std::unordered_map<std::string, WifiTxPowerOverride> load_tx_power_overrides() {
643718 entry.profile_chipset = normalize_chipset (value);
644719 }
645720 }
721+ if (!overrides.empty ()) {
722+ log_wifi (" Loaded TX power override(s) for " +
723+ std::to_string (overrides.size ()) + " interface(s)." );
724+ }
646725 return overrides;
647726}
648727
@@ -941,14 +1020,31 @@ WifiCardInfo build_wifi_card(
9411020 auto device_path = " /sys/class/net/" + interface_name + " /device" ;
9421021 auto uevent_path = device_path + " /uevent" ;
9431022 if (interface_name == " ath0" && !file_exists (uevent_path)) {
1023+ log_wifi (" ath0 uevent missing at " + uevent_path +
1024+ " , trying legacy fallback /sys/class/net/wifi0/device." );
9441025 device_path = " /sys/class/net/wifi0/device" ;
9451026 uevent_path = device_path + " /uevent" ;
9461027 }
947- const auto uevent = read_file (uevent_path).value_or (" " );
1028+ std::string uevent;
1029+ if (!file_exists (uevent_path)) {
1030+ log_wifi (" missing uevent path for interface " + interface_name + " : " +
1031+ uevent_path);
1032+ } else {
1033+ const auto uevent_content = read_file (uevent_path);
1034+ if (!uevent_content) {
1035+ log_wifi (" failed reading uevent path for interface " + interface_name +
1036+ " : " + uevent_path);
1037+ } else {
1038+ uevent = *uevent_content;
1039+ }
1040+ }
9481041 if (!uevent.empty ()) {
9491042 auto driver = extract_driver_name (uevent);
9501043 if (driver) {
9511044 card.driver_name = *driver;
1045+ } else {
1046+ log_wifi (" no DRIVER= entry in " + uevent_path + " for interface " +
1047+ interface_name + " ." );
9521048 }
9531049 }
9541050
@@ -957,26 +1053,49 @@ WifiCardInfo build_wifi_card(
9571053 const auto phy_index = read_int_file (phy_path);
9581054 if (phy_index) {
9591055 card.phy_index = *phy_index;
1056+ } else if (!file_exists (phy_path)) {
1057+ log_wifi (" missing phy index path for interface " + interface_name + " : " +
1058+ phy_path);
1059+ } else {
1060+ log_wifi (" failed to parse phy index from " + phy_path +
1061+ " for interface " + interface_name + " ." );
9601062 }
9611063
9621064 const auto mac_path = " /sys/class/net/" + interface_name + " /address" ;
963- card.mac = trim_copy (read_file (mac_path).value_or (" " ));
1065+ if (!file_exists (mac_path)) {
1066+ log_wifi (" missing MAC address path for interface " + interface_name + " : " +
1067+ mac_path);
1068+ } else {
1069+ card.mac = trim_copy (read_file (mac_path).value_or (" " ));
1070+ if (card.mac .empty ()) {
1071+ log_wifi (" MAC address is empty for interface " + interface_name + " at " +
1072+ mac_path + " ." );
1073+ }
1074+ }
9641075
9651076 fill_vendor_device_from_sysfs (device_path, card.vendor_id , card.device_id );
9661077 if (!uevent.empty ()) {
9671078 fill_vendor_device_from_uevent (uevent, card.vendor_id , card.device_id );
9681079 }
9691080
9701081 card.detected_type = driver_to_type (card.driver_name );
1082+ if (equal_after_uppercase (card.detected_type , " UNKNOWN" )) {
1083+ log_wifi (" driver '" + card.driver_name + " ' on interface " + interface_name +
1084+ " maps to UNKNOWN type." );
1085+ }
9711086
9721087 auto override_it = overrides.find (interface_name);
9731088 if (override_it != overrides.end ()) {
9741089 card.override_type = override_it->second ;
9751090 if (equal_after_uppercase (card.override_type , " DISABLED" )) {
9761091 card.disabled = true ;
9771092 card.effective_type = card.detected_type ;
1093+ log_wifi (" interface " + interface_name +
1094+ " is disabled by override (override_type=DISABLED)." );
9781095 } else {
9791096 card.effective_type = card.override_type ;
1097+ log_wifi (" interface " + interface_name + " type overridden to '" +
1098+ card.override_type + " '." );
9801099 }
9811100 } else {
9821101 card.effective_type = card.detected_type ;
@@ -1077,17 +1196,32 @@ std::vector<WifiCardInfo> detect_wifi_cards(
10771196 const std::vector<WifiCardProfile>& profiles) {
10781197 std::vector<WifiCardInfo> cards;
10791198 std::error_code ec;
1199+ log_wifi (" Starting Wi-Fi detection in /sys/class/net." );
10801200 std::filesystem::directory_iterator dir (" /sys/class/net" , ec);
10811201 if (ec) {
1202+ log_wifi (" Failed to iterate /sys/class/net: " + ec.message ());
10821203 return cards;
10831204 }
10841205 for (const auto & entry : dir) {
10851206 const auto iface = entry.path ().filename ().string ();
10861207 std::error_code exists_ec;
1087- if (!std::filesystem::exists (entry.path () / " phy80211" , exists_ec)) {
1208+ const auto phy_dir = entry.path () / " phy80211" ;
1209+ if (!std::filesystem::exists (phy_dir, exists_ec)) {
1210+ if (exists_ec) {
1211+ log_wifi (" Failed to check " + phy_dir.string () + " : " +
1212+ exists_ec.message ());
1213+ } else {
1214+ log_wifi (" Skipping interface " + iface + " : no Wi-Fi PHY path at " +
1215+ phy_dir.string ());
1216+ }
10881217 continue ;
10891218 }
1090- cards.push_back (build_wifi_card (iface, overrides, tx_overrides, profiles));
1219+ auto card = build_wifi_card (iface, overrides, tx_overrides, profiles);
1220+ log_wifi (" Detected card: " + card_short_description (card));
1221+ cards.push_back (card);
1222+ }
1223+ if (cards.empty ()) {
1224+ log_wifi (" No interfaces with /sys/class/net/<iface>/phy80211 were detected." );
10911225 }
10921226 return cards;
10931227}
@@ -1132,6 +1266,12 @@ std::vector<WifiCardInfo> detect_artosyn_cards() {
11321266 std::error_code ec;
11331267 const std::filesystem::path usb_root (" /sys/bus/usb/devices" );
11341268 if (!std::filesystem::exists (usb_root, ec)) {
1269+ if (ec) {
1270+ log_wifi (" Failed to check Artosyn USB path " + usb_root.string () + " : " +
1271+ ec.message ());
1272+ } else {
1273+ log_wifi (" Artosyn USB path not found: " + usb_root.string ());
1274+ }
11351275 return cards;
11361276 }
11371277 int usb_idx = 0 ;
@@ -1167,13 +1307,19 @@ std::vector<WifiCardInfo> detect_artosyn_cards() {
11671307}
11681308
11691309void refresh_wifi_info_impl () {
1310+ log_wifi (" Refreshing Wi-Fi info." );
11701311 const auto overrides = load_overrides ();
11711312 const auto tx_overrides = load_tx_power_overrides ();
11721313 const auto profiles = load_wifi_card_profiles ();
11731314 g_wifi_cards = detect_wifi_cards (overrides, tx_overrides, profiles);
11741315 const auto artosyn_cards = detect_artosyn_cards ();
1316+ if (!artosyn_cards.empty ()) {
1317+ log_wifi (" Detected " + std::to_string (artosyn_cards.size ()) +
1318+ " Artosyn card(s)." );
1319+ }
11751320 g_wifi_cards.insert (g_wifi_cards.end (), artosyn_cards.begin (),
11761321 artosyn_cards.end ());
1322+ log_wifi_detection_summary (g_wifi_cards);
11771323 g_wifi_initialized = true ;
11781324}
11791325
0 commit comments