Author: mmlr Date: 2011-10-07 12:23:47 +0200 (Fri, 07 Oct 2011) New Revision: 42807 Changeset: https://dev.haiku-os.org/changeset/42807 Modified: haiku/trunk/headers/os/net/NetworkDevice.h haiku/trunk/src/kits/network/libnetapi/NetworkDevice.cpp Log: Add a way to add persistent (configured) wireless_networks that will eventually be stored by the backend in the net_server. I put it in BNetworkDevice because that is where network enumeration is done as well, but I'm not sure that it fits there particularly well. Since BNetworkDevice::GetNetwork() directly interfaces with the driver and gets the networks from scan results, such persistent networks don't yet show up in those enumerations. Modified: haiku/trunk/headers/os/net/NetworkDevice.h =================================================================== --- haiku/trunk/headers/os/net/NetworkDevice.h 2011-10-07 10:18:21 UTC (rev 42806) +++ haiku/trunk/headers/os/net/NetworkDevice.h 2011-10-07 10:23:47 UTC (rev 42807) @@ -97,6 +97,9 @@ status_t GetNetwork(const BNetworkAddress& address, wireless_network& network); + status_t AddPersistentNetwork( + const wireless_network& network); + status_t JoinNetwork(const char* name, const char* password = NULL); status_t JoinNetwork(const wireless_network& network, Modified: haiku/trunk/src/kits/network/libnetapi/NetworkDevice.cpp =================================================================== --- haiku/trunk/src/kits/network/libnetapi/NetworkDevice.cpp 2011-10-07 10:18:21 UTC (rev 42806) +++ haiku/trunk/src/kits/network/libnetapi/NetworkDevice.cpp 2011-10-07 10:23:47 UTC (rev 42807) @@ -697,6 +697,90 @@ status_t +BNetworkDevice::AddPersistentNetwork(const wireless_network& network) +{ + BMessage message(kMsgAddPersistentNetwork); + status_t status = message.AddString("name", network.name); + if (status != B_OK) + return status; + + if (status == B_OK && network.address.Family() == AF_LINK) { + size_t addressLength = network.address.LinkLevelAddressLength(); + uint8* macAddress = network.address.LinkLevelAddress(); + bool usable = false; + BString formatted; + + for (size_t index = 0; index < addressLength; index++) { + if (index > 0) + formatted.Append(":"); + char buffer[3]; + snprintf(buffer, sizeof(buffer), "%2x", macAddress[index]); + formatted.Append(buffer, sizeof(buffer)); + + if (macAddress[index] != 0) + usable = true; + } + + if (usable) + status = message.AddString("mac", formatted); + } + + const char* authentication = NULL; + switch (network.authentication_mode) { + case B_NETWORK_AUTHENTICATION_NONE: + authentication = "none"; + break; + case B_NETWORK_AUTHENTICATION_WEP: + authentication = "wep"; + break; + case B_NETWORK_AUTHENTICATION_WPA: + authentication = "wpa"; + break; + case B_NETWORK_AUTHENTICATION_WPA2: + authentication = "wpa2"; + break; + } + + if (status == B_OK && authentication != NULL) + status = message.AddString("authentication", authentication); + + if (status == B_OK && (network.cipher & B_NETWORK_CIPHER_NONE) != 0) + status = message.AddString("cipher", "none"); + if (status == B_OK && (network.cipher & B_NETWORK_CIPHER_TKIP) != 0) + status = message.AddString("cipher", "tkip"); + if (status == B_OK && (network.cipher & B_NETWORK_CIPHER_CCMP) != 0) + status = message.AddString("cipher", "ccmp"); + + if (status == B_OK && (network.group_cipher & B_NETWORK_CIPHER_NONE) != 0) + status = message.AddString("group_cipher", "none"); + if (status == B_OK && (network.group_cipher & B_NETWORK_CIPHER_WEP_40) != 0) + status = message.AddString("group_cipher", "wep40"); + if (status == B_OK + && (network.group_cipher & B_NETWORK_CIPHER_WEP_104) != 0) { + status = message.AddString("group_cipher", "wep104"); + } + if (status == B_OK && (network.group_cipher & B_NETWORK_CIPHER_TKIP) != 0) + status = message.AddString("group_cipher", "tkip"); + if (status == B_OK && (network.group_cipher & B_NETWORK_CIPHER_CCMP) != 0) + status = message.AddString("group_cipher", "ccmp"); + + // TODO: the other fields aren't currently used, add them when they are + // and when it's clear how they will be stored + + if (status != B_OK) + return status; + + BMessenger networkServer(kNetServerSignature); + BMessage reply; + status = networkServer.SendMessage(&message, &reply); + if (status == B_OK) + reply.FindInt32("status", &status); + + return status; +} + + +status_t BNetworkDevice::JoinNetwork(const char* name, const char* password) { if (name == NULL || name[0] == '\0')