diff --git a/src/drivers/driver_bsd.c b/src/drivers/driver_bsd.c index 1868908..be252ae 100644 --- a/src/drivers/driver_bsd.c +++ b/src/drivers/driver_bsd.c @@ -100,6 +100,7 @@ struct bsd_driver_data { /* Generic functions for hostapd and wpa_supplicant */ +#ifndef __HAIKU__ static struct bsd_driver_data * bsd_get_drvindex(void *priv, unsigned int ifindex) { @@ -112,6 +113,7 @@ bsd_get_drvindex(void *priv, unsigned int ifindex) } return NULL; } +#endif static struct bsd_driver_data * bsd_get_drvname(void *priv, const char *ifname) diff --git a/wpa_supplicant/wpa_gui-haiku/main_haiku.cpp b/wpa_supplicant/wpa_gui-haiku/main_haiku.cpp index 1394e88..94756a8 100644 --- a/wpa_supplicant/wpa_gui-haiku/main_haiku.cpp +++ b/wpa_supplicant/wpa_gui-haiku/main_haiku.cpp @@ -49,6 +49,37 @@ extern "C" { #include } +#include + + +static BString +etherToString(const unsigned char *bytes) +{ + BString s; + s.SetToFormat("%02x:%02x:%02x:%02x:%02x:%02x", + (unsigned)bytes[0], (unsigned)bytes[1], (unsigned)bytes[2], + (unsigned)bytes[3], (unsigned)bytes[4], (unsigned)bytes[5]); + return s; +} + + +static +BString +wpa_ssid_to_string(wpa_ssid* network) +{ + BString s; + if (network->ssid == NULL || network->ssid_len == 0) { + s = "(no name) ["; + } else { + // Let's assume it's all printable characters + s.SetToFormat("%.*s [", (int)network->ssid_len, network->ssid); + } + s << etherToString(network->bssid); + s << ']'; + + return s; +} + #undef B_TRANSLATION_CONTEXT #define B_TRANSLATION_CONTEXT "wpa_supplicant" @@ -96,8 +127,12 @@ bool StateChangeWatchingEntry::MessageReceived(const wpa_supplicant *interface, BMessage *message) { - if (interface != fInterface) + if (interface != fInterface) { + LOGPRINTF("got a message for a different interface: %p", interface); return false; + } + LOGPRINTF("StateChangeWatchingEntry %p", interface); + LOGMESSAGE(*message, " "); return fCallback(interface, message, fData); } @@ -189,11 +224,14 @@ WPASupplicantApp::WPASupplicantApp() fInitStatus = errno; return; } + + LOGTRACE(); } WPASupplicantApp::~WPASupplicantApp() { + //LOGTRACE(); if (fWPAGlobal == NULL) return; @@ -232,6 +270,8 @@ WPASupplicantApp::ReadyToRun() void WPASupplicantApp::MessageReceived(BMessage *message) { + LOGTRACE(); + LOGMESSAGE(*message, " "); switch (message->what) { case kMsgWPAJoinNetwork: { @@ -264,6 +304,10 @@ WPASupplicantApp::MessageReceived(BMessage *message) } case kMsgSupplicantStateChanged: + { + _NotifyInterfaceStateChanged(message); + return; + } case kMsgJoinTimeout: { _NotifyInterfaceStateChanged(message); @@ -286,7 +330,9 @@ WPASupplicantApp::_SupplicantThread(void *data) return B_ERROR; } + LOGPRINT("Start supplicant thread"); wpa_supplicant_run(app->fWPAGlobal); + //LOGPRINT("Stop supplicant thread"); eloop_unregister_read_sock(app->fNotifySockets[0]); @@ -349,8 +395,10 @@ WPASupplicantApp::_EventLoopProcessEvents(int sock, void *eventLoopContext, while (true) { BMessage *message = queue.FindMessage((int32)0); + LOGTRACE(); if (message == NULL) break; + LOGMESSAGE(*message, " "); queue.RemoveMessage(message); @@ -432,6 +480,7 @@ WPASupplicantApp::_JoinNetwork(BMessage *message) // Check if we already registered this interface. wpa_supplicant *interface = wpa_supplicant_get_iface(fWPAGlobal, interfaceName); + LOGPRINTF("interface %s %p", interfaceName, interface); if (interface == NULL) { wpa_interface interfaceOptions; memset(&interfaceOptions, 0, sizeof(wpa_interface)); @@ -450,6 +499,7 @@ WPASupplicantApp::_JoinNetwork(BMessage *message) if (network == NULL) break; + LOGPRINTF("Remove network %s", wpa_ssid_to_string(network).String()); wpas_notify_network_removed(interface, network); wpa_config_remove_network(interface->conf, network->id); } @@ -461,6 +511,7 @@ WPASupplicantApp::_JoinNetwork(BMessage *message) conf = interface->conf; } else { // We can continue without an interface and will try HAIKU_JOIN instead. + LOGPRINT("No interface"); conf = wpa_config_alloc_empty(NULL, NULL); confDeleter.SetTo(conf); } @@ -541,6 +592,7 @@ WPASupplicantApp::_JoinNetwork(BMessage *message) if (result != 0) { // The key format is invalid, we need to ask for another password. + LOGPRINT("Invalid key format"); BMessage newJoinRequest = *message; newJoinRequest.RemoveName("password"); newJoinRequest.AddString("error", @@ -551,6 +603,7 @@ WPASupplicantApp::_JoinNetwork(BMessage *message) } if (result != 0) { + LOGPRINT("Some config problem?"); if (interface != NULL) wpas_notify_network_removed(interface, network); wpa_config_remove_network(conf, network->id); @@ -599,10 +652,12 @@ struct ieee80211_haiku_join_req { request.i_len = joinReqLen; result = device.Control(SIOCS80211, &request); printf("wpa_gui-haiku: used HAIKU_JOIN to join, status: %d\n", result); + LOGPRINTF("Try HAIKU_JOIN: %d", result); if (result != B_OK) return result; } else { + LOGPRINT("Try wpa_supplicant connect"); // Otherwise, use wpa_supplicant to connect. wpa_supplicant_select_network(interface, network); } @@ -631,6 +686,7 @@ WPASupplicantApp::_LeaveNetwork(BMessage *message) wpa_supplicant *interface = wpa_supplicant_get_iface(fWPAGlobal, interfaceName); + LOGPRINTF("interface %s %p", interfaceName, interface); if (interface == NULL) { // Attempt to leave directly. BNetworkDevice device(interfaceName); @@ -676,6 +732,7 @@ WPASupplicantApp::_NotifyNetworkEvent(BMessage *message) callback(context, interfaceName.String(), opcode); if (wpa_supplicant_get_iface(fWPAGlobal, interfaceName) == NULL) { + LOGPRINT("Maybe we used HAIKU_JOIN?"); // We likely joined via the HAIKU_JOIN ioctl. Generate a fake event. if (opcode == B_NETWORK_WLAN_JOINED) wpa_supplicant_haiku_notify_state_change(NULL, WPA_COMPLETED, WPA_AUTHENTICATING); @@ -691,18 +748,24 @@ void WPASupplicantApp::_SuccessfullyJoined(const wpa_supplicant *interface, const BMessage &joinRequest) { + LOGPRINTF("%p", interface); + LOGMESSAGE(joinRequest, " "); // We successfully connected with this configuration, store the config, // if requested, by adding a persistent network on the network device. - if (!joinRequest.FindBool("persistent")) + if (!joinRequest.FindBool("persistent")) { + LOGPRINT("Not persistent"); return; + } wireless_network network; memset(network.name, 0, sizeof(network.name)); if (interface != NULL) { wpa_ssid *networkConfig = interface->current_ssid; - if (networkConfig == NULL) + if (networkConfig == NULL) { + LOGPRINT("But there's no SSID"); return; + } memcpy(network.name, networkConfig->ssid, min_c(sizeof(network.name), networkConfig->ssid_len)); @@ -720,6 +783,7 @@ WPASupplicantApp::_SuccessfullyJoined(const wpa_supplicant *interface, device.Control(SIOCG80211, &request); } + LOGPRINTF("for SSID %.*s", sizeof(network.name), network.name); //network.address.SetToLinkLevel((uint8 *)interface->bssid, ETH_ALEN); // TODO: Decide if we want to do this, it limits the network to // a specific base station instead of a "service set" that might @@ -730,13 +794,16 @@ WPASupplicantApp::_SuccessfullyJoined(const wpa_supplicant *interface, if (joinRequest.FindUInt32("authentication", &network.authentication_mode) != B_OK) { + LOGPRINT("But there's no auth"); return; } if (network.authentication_mode > B_NETWORK_AUTHENTICATION_NONE) { const char *password = NULL; - if (joinRequest.FindString("password", &password) != B_OK) + if (joinRequest.FindString("password", &password) != B_OK) { + LOGPRINT("But there's no password"); return; + } BString networkName(network.name, sizeof(network.name)); BPasswordKey key(password, B_KEY_PURPOSE_NETWORK, networkName); @@ -746,8 +813,10 @@ WPASupplicantApp::_SuccessfullyJoined(const wpa_supplicant *interface, keyStore.AddKey(kWPASupplicantKeyring, key); } - if (interface == NULL) + if (interface == NULL) { + LOGPRINT("But there's no interface? Why do we check it here?"); return; + } switch (interface->pairwise_cipher) { case WPA_CIPHER_NONE: @@ -823,6 +892,8 @@ void WPASupplicantApp::_FailedToJoin(const wpa_supplicant *interface, const BMessage &joinRequest) { + LOGPRINTF("%p", interface); + LOGMESSAGE(joinRequest, " "); BMessage leaveRequest = joinRequest; leaveRequest.what = kMsgWPALeaveNetwork; be_app->PostMessage(&leaveRequest); @@ -848,10 +919,13 @@ WPASupplicantApp::_InterfaceStateChangeCallback(const wpa_supplicant *interface, // there was a way to tell from which network we disconnected. BMessage *originalMessage = (BMessage *)data; + LOGPRINTF("%p", interface); + LOGMESSAGE(*originalMessage, " "); int32 newState; status_t result = B_ERROR; if (message->what == kMsgJoinTimeout) { + LOGPRINT("Join timeout"); _FailedToJoin(interface, *originalMessage); result = B_TIMED_OUT; } else if (message->FindInt32("newState", &newState) == B_OK) { @@ -890,6 +964,7 @@ status_t WPASupplicantApp::_StartWatchingInterfaceChanges( const wpa_supplicant *interface, StateChangeCallback callback, void *data) { + LOGPRINTF("%p", interface); StateChangeWatchingEntry *entry = new(std::nothrow) StateChangeWatchingEntry(interface, callback, data); if (entry == NULL) @@ -905,6 +980,7 @@ WPASupplicantApp::_StartWatchingInterfaceChanges( result = B_ERROR; delete entry; } + LOGPRINTF("added as index %d", fWatchingEntryList.CountItems() - 1); fWatchingEntryListLocker.Unlock(); return result; @@ -914,6 +990,8 @@ WPASupplicantApp::_StartWatchingInterfaceChanges( void WPASupplicantApp::_NotifyInterfaceStateChanged(BMessage *message) { + LOGTRACE(); + LOGMESSAGE(*message, " "); const wpa_supplicant *interface; if (message->FindPointer("interface", (void **)&interface) != B_OK) return; @@ -924,6 +1002,7 @@ WPASupplicantApp::_NotifyInterfaceStateChanged(BMessage *message) for (int32 i = 0; i < fWatchingEntryList.CountItems(); i++) { StateChangeWatchingEntry *entry = fWatchingEntryList.ItemAt(i); if (entry->MessageReceived(interface, message)) { + LOGPRINTF("Found entry (%d), delete it", i); delete fWatchingEntryList.RemoveItemAt(i); i--; } diff --git a/wpa_supplicant/wpa_gui-haiku/notify_haiku.cpp b/wpa_supplicant/wpa_gui-haiku/notify_haiku.cpp index 59887a0..d3479ed 100644 --- a/wpa_supplicant/wpa_gui-haiku/notify_haiku.cpp +++ b/wpa_supplicant/wpa_gui-haiku/notify_haiku.cpp @@ -24,6 +24,37 @@ extern "C" { #include #include +#include + +/* +static const char* +state_name(enum wpa_states state) { + switch (state) { + case WPA_DISCONNECTED: + return "DISCONNECTED"; + case WPA_INTERFACE_DISABLED: + return "DISABLED"; + case WPA_INACTIVE: + return "INACTIVE"; + case WPA_SCANNING: + return "SCANNING"; + case WPA_AUTHENTICATING: + return "AUTHENTICATING"; + case WPA_ASSOCIATING: + return "ASSOCIATING"; + case WPA_ASSOCIATED: + return "ASSOCIATED"; + case WPA_4WAY_HANDSHAKE: + return "4WAY_HANDSHAKE"; + case WPA_GROUP_HANDSHAKE: + return "GROUP_HANDSHAKE"; + case WPA_COMPLETED: + return "COMPLETED"; + default: + return "?"; + } +} +*/ void wpa_supplicant_haiku_notify_state_change(struct wpa_supplicant *wpa_s, @@ -33,5 +64,7 @@ wpa_supplicant_haiku_notify_state_change(struct wpa_supplicant *wpa_s, message.AddPointer("interface", wpa_s); message.AddInt32("oldState", old_state); message.AddInt32("newState", new_state); + //LOGPRINTF("%s -> %s", state_name(old_state), state_name(new_state)); + //LOGMESSAGE(message, " "); be_app->PostMessage(&message); }