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. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42807 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
8fecaf03e3
commit
a1b98367ae
@ -97,6 +97,9 @@ public:
|
||||
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,
|
||||
|
@ -696,6 +696,90 @@ BNetworkDevice::GetNetwork(const BNetworkAddress& address,
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user