commit 543e62fc735378852fcb8ec14da02f564b9a7a49 Author: Máximo Castañeda Date: Tue Jun 2 17:38:42 2026 +0200 Add some logging Change-Id: I74a00f963770de2d65bc87e43f603c448e42fd88 diff --git a/headers/os/support/LogHelper.h b/headers/os/support/LogHelper.h new file mode 100644 index 0000000000..57794b3beb --- /dev/null +++ b/headers/os/support/LogHelper.h @@ -0,0 +1,224 @@ +#ifndef _LOGHELPER_H_ +#define _LOGHELPER_H_ + +#include +#include +#include +#include +#include + +#include + + +#ifndef LOGPREFIX +#define LOGPREFIX __FILE__ +#endif + + +#define LOGTRACE() syslog(LOG_INFO, "[%s] %s\n", LOGPREFIX, __func__) +#define LOGPRINT(s) syslog(LOG_INFO, "[%s] %s %s\n", LOGPREFIX, __func__, s) +#define LOGPRINTF(fmt, v...) syslog(LOG_INFO, "[%s] %s " fmt "\n", LOGPREFIX, __func__, v) +#define LOGMESSAGE(msg, prefix) dumpMessage(msg, LOGPREFIX, __func__, prefix) + + +static void +dumpMessage(const BMessage& msg, BStringList& list) +{ + if (msg.what != 0) { + BString swhat; + swhat.SetToFormat("what: 0x%08x", msg.what); + char cwhat[5]; + *(int32*)cwhat = B_BENDIAN_TO_HOST_INT32(msg.what); + if (cwhat[0] >= ' ' && cwhat[1] >= ' ' && cwhat[2] >= ' ' && cwhat[3] >= ' ') { + cwhat[4] = 0; + swhat << " [" << cwhat << "]"; + } + list.Add(swhat); + } + + int32 index = 0; + char* name = NULL; + type_code type; + int32 count; + while (msg.GetInfo(B_ANY_TYPE, index++, &name, &type, &count) == B_OK) { + for (int32 valueIndex = 0; valueIndex < count; valueIndex++) { + BString line; + line.SetToFormat("%s[%d]: ", name, valueIndex); + switch (type) { + case B_BOOL_TYPE: + { + bool data; + msg.FindBool(name, valueIndex, &data); + line << data; + + break; + } + + case B_STRING_TYPE: + { + const char* data; + msg.FindString(name, valueIndex, &data); + if (strcmp(name, "password") != 0) { + line << data; + } else { + if (data[0] != '\0') + line << "not gonna tell ya!"; + else + line << "empty!"; + } + + break; + } + + case B_INT8_TYPE: + { + int8 data; + msg.FindInt8(name, valueIndex, &data); + line << data; + + break; + } + + case B_UINT8_TYPE: + { + uint8 data; + msg.FindUInt8(name, valueIndex, &data); + line << data; + + break; + } + + case B_INT16_TYPE: + { + int16 data; + msg.FindInt16(name, valueIndex, &data); + line << data; + + break; + } + + case B_UINT16_TYPE: + { + uint16 data; + msg.FindUInt16(name, valueIndex, &data); + line << data; + + break; + } + + case B_INT32_TYPE: + { + int32 data; + msg.FindInt32(name, valueIndex, &data); + line << data; + + break; + } + + case B_UINT32_TYPE: + { + uint32 data; + msg.FindUInt32(name, valueIndex, &data); + line << data; + + break; + } + + case B_INT64_TYPE: + { + int64 data; + msg.FindInt64(name, valueIndex, &data); + line << data; + + break; + } + + case B_UINT64_TYPE: + { + uint64 data; + msg.FindUInt64(name, valueIndex, &data); + line << data; + + break; + } + + case B_FLOAT_TYPE: + { + float data; + msg.FindFloat(name, valueIndex, &data); + line << data; + + break; + } + + case B_DOUBLE_TYPE: + { + double data; + msg.FindDouble(name, valueIndex, &data); + line << data; + + break; + } + + case B_POINTER_TYPE: + { + void* data; + msg.FindPointer(name, valueIndex, &data); + BString tmp; + tmp.SetToFormat("%p", data); + line << tmp; + + break; + } + + case B_MESSAGE_TYPE: + { + BMessage data; + msg.FindMessage(name, valueIndex, &data); + line << "BMessage {"; + list.Add(line); + BStringList inner; + dumpMessage(data, inner); + for (int i = 0; i < inner.CountStrings(); i++) + list.Add(inner.StringAt(i).Prepend(' ', 2)); + line = '}'; + + break; + } + + case B_NETWORK_ADDRESS_TYPE: + { + BNetworkAddress address; + msg.FindFlat(name, valueIndex, &address); + line << address.ToString(); + + break; + } + + default: + { + char data[5]; + *(int32*)data = B_BENDIAN_TO_HOST_INT32(type); + data[4] = 0; + line << "Unknown type " << data; + + break; + } + } + list.Add(line); + } + } +} + + +static void +dumpMessage(const BMessage& msg, const char* prefix01, const char* prefix02, const char* prefix) +{ + BStringList list; + dumpMessage(msg, list); + for (int i = 0; i < list.CountStrings(); i++) + syslog(LOG_INFO, "[%s] %s %s%s", prefix01, prefix02, prefix, list.StringAt(i).String()); +} + + +#endif diff --git a/src/bin/network/ifconfig/ifconfig.cpp b/src/bin/network/ifconfig/ifconfig.cpp index 66e34ce48c..6b50759c72 100644 --- a/src/bin/network/ifconfig/ifconfig.cpp +++ b/src/bin/network/ifconfig/ifconfig.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -312,6 +313,7 @@ configure_wireless(const char* name, char* const* args, int32 argCount) if (mode == NONE) return false; + syslog(LOG_INFO, "ifconfig %s %s\n", name, args[0]); BNetworkDevice device(name); if (!device.Exists()) { fprintf(stderr, "%s: \"%s\" does not exist!\n", kProgramName, name); @@ -333,6 +335,7 @@ configure_wireless(const char* name, char* const* args, int32 argCount) if (status != B_OK) { fprintf(stderr, "%s: Scan on \"%s\" failed: %s\n", kProgramName, name, strerror(status)); + syslog(LOG_INFO, "ifconfig scan on %s failed: %s\n", name, strerror(status)); exit(1); } // fall through @@ -403,6 +406,7 @@ configure_wireless(const char* name, char* const* args, int32 argCount) if (status != B_OK) { fprintf(stderr, "%s: Joining network failed: %s\n", kProgramName, strerror(status)); + syslog(LOG_INFO, "ifconfig joining %s failed: %s\n", args[0], strerror(status)); exit(1); } break; @@ -426,6 +430,7 @@ configure_wireless(const char* name, char* const* args, int32 argCount) if (status != B_OK) { fprintf(stderr, "%s: Leaving network failed: %s\n", kProgramName, strerror(status)); + syslog(LOG_INFO, "ifconfig leaving %s failed: %s\n", args[0], strerror(status)); exit(1); } break; @@ -450,6 +455,7 @@ configure_wireless(const char* name, char* const* args, int32 argCount) break; } + syslog(LOG_INFO, "ifconfig %s finished\n", name); return true; } diff --git a/src/kits/network/libnetapi/NetworkDevice.cpp b/src/kits/network/libnetapi/NetworkDevice.cpp index b3beebdf04..72da0e495a 100644 --- a/src/kits/network/libnetapi/NetworkDevice.cpp +++ b/src/kits/network/libnetapi/NetworkDevice.cpp @@ -25,6 +25,19 @@ extern "C" { # include } +#include +static void +dump_network(const wireless_network& w) { + LOGPRINTF(" name: %s", w.name); + LOGPRINTF(" address: %s", w.address.ToString().String()); + LOGPRINTF(" S/N: %u/%u", (unsigned)w.signal_strength, (unsigned)w.noise_level); + LOGPRINTF(" flags: 0x%x", w.flags); + LOGPRINTF(" auth: 0x%x", w.authentication_mode); + //LOGPRINTF(" cipher: 0x%x", w.cipher); + //LOGPRINTF(" group cipher: 0x%x", w.group_cipher); + //LOGPRINTF(" key mode: 0x%x", w.key_mode); +} + //#define TRACE_DEVICE #ifdef TRACE_DEVICE @@ -358,11 +371,14 @@ static bool get_ssid_from_ie(char* name, uint8* _ie, int32 ieLength) { struct ie_data* ie = (ie_data*)_ie; + //LOGPRINTF("%p %d", _ie, ieLength); while (ieLength > 1) { + //LOGPRINTF("found ie type %x", ie->type); switch (ie->type) { case IEEE80211_ELEMID_SSID: strlcpy(name, (char*)ie->data, min_c(ie->length + 1, 32)); + //LOGPRINTF("found SSID %s", name); return true; } @@ -385,6 +401,8 @@ static void fill_wireless_network(wireless_network& network, struct ieee80211req_sta_info& info) { + LOGPRINT("from STA info"); + network.name[0] = '\0'; network.address.SetToLinkLevel(info.isi_macaddr, IEEE80211_ADDR_LEN); @@ -399,6 +417,8 @@ fill_wireless_network(wireless_network& network, network.key_mode = 0; parse_ie(network, info); + + dump_network(network); } @@ -406,6 +426,8 @@ static void fill_wireless_network(wireless_network& network, const char* networkName, struct ieee80211req_scan_result& result) { + LOGPRINT("from scan result"); + strlcpy(network.name, networkName, sizeof(network.name)); network.address.SetToLinkLevel(result.isr_bssid, IEEE80211_ADDR_LEN); @@ -420,12 +442,15 @@ fill_wireless_network(wireless_network& network, const char* networkName, network.key_mode = 0; parse_ie(network, result); + + dump_network(network); } static status_t get_scan_results(const char* device, wireless_network*& networks, uint32& count) { + LOGTRACE(); if (networks != NULL) return B_BAD_VALUE; @@ -472,6 +497,7 @@ get_scan_results(const char* device, wireless_network*& networks, uint32& count) } } + LOGPRINTF("found %u scan results", (unsigned)count); return B_OK; } @@ -480,6 +506,7 @@ static status_t get_scan_result(const char* device, wireless_network& network, uint32 index, const BNetworkAddress* address, const char* name) { + LOGPRINTF("for %s %s %u %s", device, name!=NULL?name:"(no name)", (unsigned)index, address!=NULL?address->ToString().String():"(no address)"); if (address != NULL && address->Family() != AF_LINK) return B_BAD_VALUE; @@ -523,6 +550,7 @@ get_scan_result(const char* device, wireless_network& network, uint32 index, count++; } + LOGPRINTF("not found for %s %s %u %s", device, name!=NULL?name:"(no name)", (unsigned)index, address!=NULL?address->ToString().String():"(no address)"); return B_ENTRY_NOT_FOUND; } @@ -531,6 +559,7 @@ static status_t get_station(const char* device, wireless_network& network, uint32 index, const BNetworkAddress* address, const char* name) { + LOGPRINTF("%s %s %u %s", device, name!=NULL?name:"(no name)", (unsigned)index, address!=NULL?address->ToString().String():"(no address)"); if (address != NULL && address->Family() != AF_LINK) return B_BAD_VALUE; @@ -563,6 +592,7 @@ get_station(const char* device, wireless_network& network, uint32 index, char networkName[32]; get_ssid_from_ie(networkName, *info); + LOGPRINTF("checking %d [%.32s]", count, networkName); if (index == count || address != NULL || (name != NULL && !strcmp(networkName, name))) { fill_wireless_network(network, *info); @@ -574,6 +604,7 @@ get_station(const char* device, wireless_network& network, uint32 index, count++; } + LOGPRINTF("not found %s %s %u %s", device, name!=NULL?name:"(no name)", (unsigned)index, address!=NULL?address->ToString().String():"(no address)"); return B_ENTRY_NOT_FOUND; } @@ -582,6 +613,7 @@ static status_t get_network(const char* device, wireless_network& network, uint32 index, const BNetworkAddress* address, const char* name) { + LOGPRINTF("%s %s %u %s", device, name!=NULL?name:"(no name)", (unsigned)index, address!=NULL?address->ToString().String():"(no address)"); status_t status = get_station(device, network, index, address, name); if (status != B_OK) return get_scan_result(device, network, index, address, name); @@ -610,6 +642,7 @@ BNetworkDevice::BNetworkDevice(const char* name) BNetworkDevice::~BNetworkDevice() { + LOGPRINTF("%p", this); } @@ -623,6 +656,7 @@ BNetworkDevice::Unset() void BNetworkDevice::SetTo(const char* name) { + LOGPRINTF("%p %s", this, name); strlcpy(fName, name, IF_NAMESIZE); } @@ -739,6 +773,7 @@ BNetworkDevice::Control(int option, void* request) status_t BNetworkDevice::Scan(bool wait, bool forceRescan) { + LOGPRINTF("%p %s, %s", this, wait?"wait":"nowait", forceRescan?"force":"noforce"); // Network status listener for change notifications class ScanListener : public BLooper { public: @@ -746,10 +781,12 @@ BNetworkDevice::Scan(bool wait, bool forceRescan) : fInterface(iface) { + LOGPRINTF("%s", iface.String()); start_watching_network(B_WATCH_NETWORK_WLAN_CHANGES, this); } virtual ~ScanListener() { + LOGPRINTF("%s", fInterface.String()); stop_watching_network(this); } @@ -766,6 +803,8 @@ BNetworkDevice::Scan(bool wait, bool forceRescan) return; // See comment in AutoconfigLooper::_NetworkMonitorNotification // for the reason as to why we use FindFirst instead of ==. + LOGPRINTF("in ScanListener for %s", fInterface.String()); + LOGMESSAGE(*message, " "); if (fInterface.FindFirst(interfaceName) < 0) return; if (message->FindInt32("opcode") != B_NETWORK_WLAN_SCANNED) @@ -800,11 +839,14 @@ BNetworkDevice::Scan(bool wait, bool forceRescan) // If there are no VAPs running, the net80211 layer will return ENXIO. // Try to bring up the interface (which should start a VAP) and try again. if (status == ENXIO) { + LOGPRINTF("%p no VAPs", this); struct ieee80211req dummy; status = set_80211(Name(), IEEE80211_IOC_HAIKU_COMPAT_WLAN_UP, &dummy, sizeof(dummy)); - if (status != B_OK) + if (status != B_OK) { + LOGPRINTF("%p couldn't bring up iface? %s", this, strerror(status)); return status; + } status = set_80211(Name(), IEEE80211_IOC_SCAN_REQ, &request, sizeof(request)); @@ -814,6 +856,7 @@ BNetworkDevice::Scan(bool wait, bool forceRescan) // one, which we of course don't want to wait for. So just return immediately // if that's the case. if (status == EINPROGRESS) { + LOGPRINTF("%p in progress", this); delete listener; return B_OK; } @@ -860,6 +903,7 @@ BNetworkDevice::GetNetwork(const BNetworkAddress& address, status_t BNetworkDevice::JoinNetwork(const char* name, const char* password) { + LOGPRINTF("%p %s %s password", this, name, (password == NULL || password[0] == '\0') ? "without" : "with"); if (name == NULL || name[0] == '\0') return B_BAD_VALUE; @@ -889,6 +933,8 @@ status_t BNetworkDevice::JoinNetwork(const wireless_network& network, const char* password) { + LOGPRINTF("%p", this); + dump_network(network); return JoinNetwork(network.address, password); } @@ -897,6 +943,7 @@ status_t BNetworkDevice::JoinNetwork(const BNetworkAddress& address, const char* password) { + LOGPRINTF("%p %s", this, address.ToString().String()); if (address.InitCheck() != B_OK) return B_BAD_VALUE; @@ -927,6 +974,7 @@ BNetworkDevice::JoinNetwork(const BNetworkAddress& address, status_t BNetworkDevice::LeaveNetwork(const char* name) { + LOGPRINTF("%p %s", this, name); BMessage message(kMsgLeaveNetwork); status_t status = message.AddString("device", Name()); if (status == B_OK) @@ -949,6 +997,8 @@ BNetworkDevice::LeaveNetwork(const char* name) status_t BNetworkDevice::LeaveNetwork(const wireless_network& network) { + LOGPRINTF("%p", this); + dump_network(network); return LeaveNetwork(network.address); } @@ -956,6 +1006,7 @@ BNetworkDevice::LeaveNetwork(const wireless_network& network) status_t BNetworkDevice::LeaveNetwork(const BNetworkAddress& address) { + LOGPRINTF("%p %s", this, address.ToString().String()); BMessage message(kMsgLeaveNetwork); status_t status = message.AddString("device", Name()); if (status == B_OK) { diff --git a/src/kits/network/libnetapi/NetworkSettings.cpp b/src/kits/network/libnetapi/NetworkSettings.cpp index 21fc389dc0..2ee04f7c0f 100644 --- a/src/kits/network/libnetapi/NetworkSettings.cpp +++ b/src/kits/network/libnetapi/NetworkSettings.cpp @@ -27,6 +27,8 @@ #include #include +#include + using namespace BNetworkKit; @@ -332,6 +334,8 @@ BNetworkSettings::GetInterface(const char* name, BMessage& interface) const status_t BNetworkSettings::AddInterface(const BMessage& interface) { + LOGTRACE(); + LOGMESSAGE(interface, " "); const char* name = NULL; if (interface.FindString("device", &name) != B_OK) return B_BAD_VALUE; @@ -349,6 +353,7 @@ BNetworkSettings::AddInterface(const BMessage& interface) status_t BNetworkSettings::RemoveInterface(const char* name) { + LOGPRINT(name); return _RemoveItem(fInterfaces, "interface", "device", name, kInterfaceSettingsName); } @@ -406,6 +411,8 @@ BNetworkSettings::GetNetwork(const char* name, BMessage& network) const status_t BNetworkSettings::AddNetwork(const BMessage& network) { + LOGTRACE(); + LOGMESSAGE(network, " "); const char* name = NULL; if (network.FindString("name", &name) != B_OK) return B_BAD_VALUE; @@ -423,6 +430,7 @@ BNetworkSettings::AddNetwork(const BMessage& network) status_t BNetworkSettings::RemoveNetwork(const char* name) { + LOGPRINT(name); return _RemoveItem(fNetworks, "network", "name", name, kNetworksSettingsName); } @@ -458,6 +466,8 @@ BNetworkSettings::GetService(const char* name, BMessage& service) const status_t BNetworkSettings::AddService(const BMessage& service) { + LOGTRACE(); + LOGMESSAGE(service, " "); const char* name = service.GetString("name"); if (name == NULL) return B_BAD_VALUE; @@ -475,6 +485,7 @@ BNetworkSettings::AddService(const BMessage& service) status_t BNetworkSettings::RemoveService(const char* name) { + LOGPRINT(name); return _RemoveItem(fServices, "service", "name", name, kServicesSettingsName); } @@ -530,6 +541,8 @@ BNetworkSettings::StopMonitoring(const BMessenger& target) status_t BNetworkSettings::Update(BMessage* message) { + LOGTRACE(); + LOGMESSAGE(*message, " "); const char* pathName; int32 opcode; if (message->FindInt32("opcode", &opcode) != B_OK @@ -588,11 +601,15 @@ BNetworkSettings::_Load(const char* name, uint32* _type) fInterfaces); if (status == B_OK && _type != NULL) *_type = kMsgInterfaceSettingsUpdated; + LOGPRINT("interfaces"); + LOGMESSAGE(fInterfaces, " "); } if (name == NULL || strcmp(name, kNetworksSettingsName) == 0) { status = adapter.ConvertFromDriverSettings( _Path(path, kNetworksSettingsName).Path(), kNetworksTemplate, fNetworks); + LOGPRINT("networks"); + LOGMESSAGE(fNetworks, " "); if (status == B_OK) { // Convert settings for simpler consumption BMessage network; @@ -605,6 +622,8 @@ BNetworkSettings::_Load(const char* name, uint32* _type) if (_type != NULL) *_type = kMsgNetworkSettingsUpdated; } + LOGPRINT("and convert them to"); + LOGMESSAGE(fNetworks, " "); } if (name == NULL || strcmp(name, kServicesSettingsName) == 0) { status = adapter.ConvertFromDriverSettings( @@ -612,6 +631,8 @@ BNetworkSettings::_Load(const char* name, uint32* _type) fServices); if (status == B_OK && _type != NULL) *_type = kMsgServiceSettingsUpdated; + LOGPRINT("services"); + LOGMESSAGE(fServices, " "); } return status; @@ -630,24 +651,32 @@ BNetworkSettings::_Save(const char* name) status = B_ENTRY_NOT_FOUND; if (name == NULL || strcmp(name, kInterfaceSettingsName) == 0) { + LOGPRINT("interfaces"); + LOGMESSAGE(fInterfaces, " "); status = adapter.ConvertToDriverSettings( _Path(path, kInterfaceSettingsName).Path(), kInterfacesTemplate, fInterfaces); } if (name == NULL || strcmp(name, kNetworksSettingsName) == 0) { // Convert settings to storage format + LOGPRINT("networks"); + LOGMESSAGE(fNetworks, " "); BMessage networks = fNetworks; BMessage network; for (int32 index = 0; networks.FindMessage("network", index, &network) == B_OK; index++) { if (_ConvertNetworkToSettings(network) == B_OK) networks.ReplaceMessage("network", index, &network); } + LOGPRINT("but do it as"); + LOGMESSAGE(networks, " "); status = adapter.ConvertToDriverSettings( _Path(path, kNetworksSettingsName).Path(), kNetworksTemplate, networks); } if (name == NULL || strcmp(name, kServicesSettingsName) == 0) { + LOGPRINT("services"); + LOGMESSAGE(fServices, " "); status = adapter.ConvertToDriverSettings( _Path(path, kServicesSettingsName).Path(), kServicesTemplate, fServices); @@ -697,8 +726,10 @@ BNetworkSettings::_ConvertNetworkToSettings(BMessage& message) { BNetworkAddress address; status_t result = message.FindFlat("address", &address); - if (result == B_OK) + if (result == B_OK) { + //LOGPRINTF("found address %s, family %d", address.ToString().String(), address.Family()); message.RemoveName("address"); + } if (result == B_OK && address.Family() == AF_LINK) { size_t addressLength = address.LinkLevelAddressLength(); @@ -710,6 +741,7 @@ BNetworkSettings::_ConvertNetworkToSettings(BMessage& message) if (index > 0) formatted.Append(":"); char buffer[3]; + // %02x snprintf(buffer, sizeof(buffer), "%2x", macAddress[index]); formatted.Append(buffer, sizeof(buffer)); @@ -907,6 +939,8 @@ BNetworkInterfaceAddressSettings::BNetworkInterfaceAddressSettings() BNetworkInterfaceAddressSettings::BNetworkInterfaceAddressSettings( const BMessage& data) { + LOGTRACE(); + LOGMESSAGE(data, " "); if (data.FindInt32("family", &fFamily) != B_OK) { const char* familyString; if (data.FindString("family", &familyString) == B_OK) { @@ -1106,6 +1140,8 @@ BNetworkInterfaceSettings::BNetworkInterfaceSettings() BNetworkInterfaceSettings::BNetworkInterfaceSettings(const BMessage& message) { + LOGTRACE(); + LOGMESSAGE(message, " "); fName = message.GetString("device"); fFlags = message.GetInt32("flags", 0); fMTU = message.GetInt32("mtu", 0); @@ -1305,6 +1341,8 @@ BNetworkServiceAddressSettings::BNetworkServiceAddressSettings( const BMessage& data, int serviceFamily, int serviceType, int serviceProtocol, int servicePort) { + LOGTRACE(); + LOGMESSAGE(data, " "); // TODO: dump problems in the settings to syslog if (data.FindInt32("family", &fFamily) != B_OK) { const char* familyString; @@ -1443,6 +1481,8 @@ BNetworkServiceSettings::BNetworkServiceSettings(const BMessage& message) fEnabled(true), fStandAlone(false) { + LOGTRACE(); + LOGMESSAGE(message, " "); // TODO: user/group is currently ignored! fName = message.GetString("name"); diff --git a/src/servers/net/NetServer.cpp b/src/servers/net/NetServer.cpp index 94a079709a..e24c9c0e17 100644 --- a/src/servers/net/NetServer.cpp +++ b/src/servers/net/NetServer.cpp @@ -54,6 +54,8 @@ extern "C" { # include } +#include + using namespace BNetworkKit; @@ -254,8 +256,13 @@ NetServer::MessageReceived(BMessage* message) if (result == B_OK) { BMessage network; result = fSettings.GetNextNetwork(index, network); + LOGPRINTF("get persistent network %u", index); + LOGMESSAGE(network, " "); if (result == B_OK) result = reply.AddMessage("network", &network); + } else { + LOGPRINT("wrong get persistent network query"); + LOGMESSAGE(*message, " "); } reply.AddInt32("status", result); @@ -266,6 +273,8 @@ NetServer::MessageReceived(BMessage* message) case kMsgAddPersistentNetwork: { BMessage network = *message; + LOGPRINT("add persistent network"); + LOGMESSAGE(network, " "); status_t result = fSettings.AddNetwork(network); BMessage reply(B_REPLY); @@ -276,6 +285,9 @@ NetServer::MessageReceived(BMessage* message) case kMsgRemovePersistentNetwork: { + BMessage network = *message; + LOGPRINT("remove persistent network"); + LOGMESSAGE(network, " "); const char* networkName = NULL; status_t result = message->FindString("name", &networkName); if (result == B_OK) @@ -327,18 +339,26 @@ NetServer::_IsValidInterface(BNetworkInterface& interface) { // check if it has an address - if (interface.CountAddresses() == 0) + LOGPRINTF("%s", interface.Name()); + if (interface.CountAddresses() == 0) { + LOGPRINT(" No address"); return false; + } // check if it has a hardware address, too, in case of ethernet BNetworkAddress link; - if (interface.GetHardwareAddress(link) != B_OK) + if (interface.GetHardwareAddress(link) != B_OK) { + LOGPRINT(" No HW address"); return false; + } - if (link.LinkLevelType() == IFT_ETHER && link.LinkLevelAddressLength() != 6) + if (link.LinkLevelType() == IFT_ETHER && link.LinkLevelAddressLength() != 6) { + LOGPRINT(" No HW address for ethernet"); return false; + } + LOGPRINT(" Yes"); return true; } @@ -362,13 +382,14 @@ NetServer::_RemoveInvalidInterfaces() bool NetServer::_TestForInterface(const char* name) { - + LOGPRINT(name); BNetworkRoster& roster = BNetworkRoster::Default(); int32 nameLength = strlen(name); BNetworkInterface interface; uint32 cookie = 0; while (roster.GetNextInterface(&cookie, interface) == B_OK) { + LOGPRINTF("found %s", interface.Name()); if (!strncmp(interface.Name(), name, nameLength)) return true; } @@ -380,6 +401,7 @@ NetServer::_TestForInterface(const char* name) status_t NetServer::_RemoveInterface(const char* name) { + LOGPRINT(name); BNetworkRoster& roster = BNetworkRoster::Default(); status_t status = roster.RemoveInterface(name); if (status != B_OK) { @@ -395,6 +417,7 @@ NetServer::_RemoveInterface(const char* name) status_t NetServer::_DisableInterface(const char* name) { + LOGPRINT(name); BNetworkInterface interface(name); int32 flags = interface.Flags(); @@ -416,6 +439,9 @@ NetServer::_DisableInterface(const char* name) status_t NetServer::_ConfigureInterface(BMessage& message) { + LOGTRACE(); + LOGMESSAGE(message, " "); + const char* name; if (message.FindString("device", &name) != B_OK) return B_BAD_VALUE; @@ -579,6 +605,8 @@ NetServer::_ConfigureInterface(BMessage& message) status_t NetServer::_ConfigureResolver(BMessage& resolverConfiguration) { + LOGTRACE(); + LOGMESSAGE(resolverConfiguration, " "); // Store resolver settings in resolv.conf file, while maintaining any // user specified settings already present. @@ -680,6 +708,7 @@ NetServer::_LooperForDevice(const char* device) status_t NetServer::_ConfigureDevice(const char* device) { + LOGTRACE(); // bring interface up, but don't configure it just yet BMessage interface; interface.AddString("device", device); @@ -704,6 +733,16 @@ void NetServer::_ConfigureDevices(const char* startPath, BStringList& devicesAlreadyConfigured, BMessage* suggestedInterface) { + LOGPRINTF("in %s", startPath); + for (int i = 0; i < devicesAlreadyConfigured.CountStrings(); i++) + LOGPRINTF(" already configured: %s", devicesAlreadyConfigured.StringAt(i).String()); + + if (suggestedInterface != NULL) { + BMessage msg = *suggestedInterface; + LOGPRINT(" suggested iface"); + LOGMESSAGE(msg, " "); + } + BDirectory directory(startPath); BEntry entry; while (directory.GetNextEntry(&entry) == B_OK) { @@ -735,10 +774,14 @@ void NetServer::_ConfigureInterfacesFromSettings(BStringList& devicesSet, BMessage* _missingDevice) { + LOGTRACE(); + BMessage interface; uint32 cookie = 0; bool missing = false; while (fSettings.GetNextInterface(cookie, interface) == B_OK) { + LOGPRINT(" iface"); + LOGMESSAGE(interface, " "); const char *device; if (interface.FindString("device", &device) != B_OK) continue; @@ -771,6 +814,7 @@ NetServer::_ConfigureInterfacesFromSettings(BStringList& devicesSet, void NetServer::_BringUpInterfaces() { + LOGTRACE(); // we need a socket to talk to the networking stack if (!_IsValidFamily(AF_LINK)) { fprintf(stderr, "%s: The networking stack doesn't seem to be " @@ -920,6 +964,9 @@ NetServer::_StartServices() status_t NetServer::_HandleDeviceMonitor(BMessage* message) { + LOGTRACE(); + BMessage m = *message; + LOGMESSAGE(m, " "); int32 opcode; const char* path; if (message->FindInt32("opcode", &opcode) != B_OK @@ -944,6 +991,8 @@ NetServer::_HandleDeviceMonitor(BMessage* message) status_t NetServer::_AutoJoinNetwork(const BMessage& message) { + LOGTRACE(); + LOGMESSAGE(message, " "); const char* name = NULL; if (message.FindString("device", &name) != B_OK) return B_BAD_VALUE; @@ -955,6 +1004,8 @@ NetServer::_AutoJoinNetwork(const BMessage& message) uint32 cookie = 0; BMessage networkMessage; while (fSettings.GetNextNetwork(cookie, networkMessage) == B_OK) { + LOGPRINT(" try network:"); + LOGMESSAGE(networkMessage, " "); status_t status = B_ERROR; wireless_network network; const char* networkName; @@ -985,6 +1036,8 @@ status_t NetServer::_JoinNetwork(const BMessage& message, const BNetworkAddress* address, const char* name) { + LOGTRACE(); + LOGMESSAGE(message, " "); const char* deviceName; if (message.FindString("device", &deviceName) != B_OK) return B_BAD_VALUE; @@ -1008,6 +1061,8 @@ NetServer::_JoinNetwork(const BMessage& message, const BNetworkAddress* address, uint32 cookie = 0; BMessage networkMessage; while (fSettings.GetNextNetwork(cookie, networkMessage) == B_OK) { + LOGPRINT(" check overrides:"); + LOGMESSAGE(networkMessage, " "); const char* networkName; if (networkMessage.FindString("name", &networkName) == B_OK && name != NULL && address->Family() != AF_LINK @@ -1080,10 +1135,12 @@ NetServer::_JoinNetwork(const BMessage& message, const BNetworkAddress* address, BMessenger wpaSupplicant(kWPASupplicantSignature); if (!wpaSupplicant.IsValid()) { + LOGPRINT("wpa_supplicant not running yet"); // The wpa_supplicant isn't running yet, we may join ourselves. if (!askForConfig && network.authentication_mode == B_NETWORK_AUTHENTICATION_NONE) { // We can join this network ourselves. + LOGPRINT("join ourselves"); status_t status = set_80211(deviceName, IEEE80211_IOC_SSID, network.name, strlen(network.name)); if (status != B_OK) { @@ -1118,6 +1175,8 @@ NetServer::_JoinNetwork(const BMessage& message, const BNetworkAddress* address, if (status != B_OK) return status; + LOGPRINT("join msg to wpa_supplicant:"); + LOGMESSAGE(join, " "); status = wpaSupplicant.SendMessage(&join); if (status != B_OK) return status; @@ -1129,6 +1188,8 @@ NetServer::_JoinNetwork(const BMessage& message, const BNetworkAddress* address, status_t NetServer::_LeaveNetwork(const BMessage& message) { + LOGTRACE(); + LOGMESSAGE(message, " "); const char* deviceName; if (message.FindString("device", &deviceName) != B_OK) return B_BAD_VALUE; @@ -1157,11 +1218,13 @@ NetServer::_LeaveNetwork(const BMessage& message) // network we connected ourselves. BNetworkDevice device(deviceName); wireless_network network; + LOGPRINT("no wpa_supplicant"); uint32 cookie = 0; if (device.GetNextAssociatedNetwork(cookie, network) != B_OK || network.authentication_mode != B_NETWORK_AUTHENTICATION_NONE) { // We didn't join ourselves, we can't do much. + LOGPRINT("we didn't join ourselves"); return B_ERROR; }