2010-10-26 00:20:09 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2010, Haiku, Inc. All Rights Reserved.
|
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
|
|
|
#ifndef _NETWORK_DEVICE_H
|
|
|
|
#define _NETWORK_DEVICE_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <net/if.h>
|
2021-08-01 17:49:03 +03:00
|
|
|
#include <string.h>
|
2010-10-26 00:20:09 +04:00
|
|
|
|
|
|
|
#include <NetworkAddress.h>
|
|
|
|
|
|
|
|
|
|
|
|
class BNetworkAddress;
|
|
|
|
|
|
|
|
|
|
|
|
struct wireless_network {
|
|
|
|
char name[32];
|
|
|
|
BNetworkAddress address;
|
|
|
|
uint8 noise_level;
|
|
|
|
uint8 signal_strength;
|
2010-12-09 01:55:57 +03:00
|
|
|
uint32 flags;
|
|
|
|
uint32 authentication_mode;
|
|
|
|
uint32 cipher;
|
2010-12-10 01:33:34 +03:00
|
|
|
uint32 group_cipher;
|
2010-12-09 01:55:57 +03:00
|
|
|
uint32 key_mode;
|
2021-08-01 17:49:03 +03:00
|
|
|
|
|
|
|
bool operator==(const wireless_network& other) {
|
|
|
|
return strncmp(name, other.name, 32) == 0
|
|
|
|
// ignore address difference
|
|
|
|
&& noise_level == other.noise_level
|
|
|
|
&& signal_strength == other.signal_strength
|
|
|
|
&& flags == other.flags
|
|
|
|
&& authentication_mode == other.authentication_mode
|
|
|
|
&& cipher == other.cipher
|
|
|
|
&& group_cipher == other.group_cipher
|
|
|
|
&& key_mode == other.key_mode;
|
|
|
|
}
|
2010-10-26 00:20:09 +04:00
|
|
|
};
|
|
|
|
|
2010-12-09 01:55:57 +03:00
|
|
|
// flags
|
|
|
|
#define B_NETWORK_IS_ENCRYPTED 0x01
|
2011-10-09 23:56:19 +04:00
|
|
|
#define B_NETWORK_IS_PERSISTENT 0x02
|
2010-12-09 01:55:57 +03:00
|
|
|
|
|
|
|
// authentication modes
|
|
|
|
enum {
|
|
|
|
B_NETWORK_AUTHENTICATION_NONE = 0,
|
|
|
|
B_NETWORK_AUTHENTICATION_WEP = 1,
|
|
|
|
B_NETWORK_AUTHENTICATION_WPA = 2,
|
2013-07-18 05:15:46 +04:00
|
|
|
B_NETWORK_AUTHENTICATION_WPA2 = 3,
|
|
|
|
B_NETWORK_AUTHENTICATION_EAP = 4
|
2010-12-09 01:55:57 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// cipher algorithms
|
|
|
|
enum {
|
|
|
|
B_NETWORK_CIPHER_NONE = 0x01,
|
|
|
|
B_NETWORK_CIPHER_WEP_40 = 0x02,
|
|
|
|
B_NETWORK_CIPHER_WEP_104 = 0x04,
|
2010-12-10 01:33:34 +03:00
|
|
|
B_NETWORK_CIPHER_TKIP = 0x08,
|
|
|
|
B_NETWORK_CIPHER_CCMP = 0x10,
|
|
|
|
B_NETWORK_CIPHER_AES_128_CMAC = 0x20
|
2010-12-09 01:55:57 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// key modes
|
|
|
|
enum {
|
|
|
|
B_KEY_MODE_IEEE802_1X = 0x0001,
|
|
|
|
B_KEY_MODE_PSK = 0x0002,
|
2010-12-10 01:33:34 +03:00
|
|
|
B_KEY_MODE_NONE = 0x0004,
|
|
|
|
B_KEY_MODE_FT_IEEE802_1X = 0x0020,
|
|
|
|
B_KEY_MODE_FT_PSK = 0x0040,
|
2010-12-09 01:55:57 +03:00
|
|
|
B_KEY_MODE_IEEE802_1X_SHA256 = 0x0080,
|
|
|
|
B_KEY_MODE_PSK_SHA256 = 0x0100,
|
|
|
|
B_KEY_MODE_WPS = 0x0200
|
|
|
|
};
|
|
|
|
|
2013-07-18 05:15:46 +04:00
|
|
|
// eap encapsulation method (IEEE 802.1x)
|
|
|
|
enum {
|
|
|
|
B_NETWORK_EAP_ENCAPSULATION_NONE = 0x0000,
|
|
|
|
B_NETWORK_EAP_ENCAPSULATION_PEAP = 0x0001,
|
|
|
|
B_NETWORK_EAP_ENCAPSULATION_TLS = 0x0002
|
|
|
|
};
|
|
|
|
|
2010-12-09 01:55:57 +03:00
|
|
|
|
2010-10-26 00:20:09 +04:00
|
|
|
class BNetworkDevice {
|
|
|
|
public:
|
|
|
|
BNetworkDevice();
|
|
|
|
BNetworkDevice(const char* name);
|
|
|
|
~BNetworkDevice();
|
|
|
|
|
|
|
|
void Unset();
|
|
|
|
void SetTo(const char* name);
|
|
|
|
|
|
|
|
const char* Name() const;
|
2010-12-09 01:55:57 +03:00
|
|
|
bool Exists() const;
|
2010-11-24 00:04:19 +03:00
|
|
|
uint32 Index() const;
|
2010-10-26 00:20:09 +04:00
|
|
|
|
|
|
|
uint32 Flags() const;
|
|
|
|
bool HasLink() const;
|
|
|
|
|
|
|
|
int32 CountMedia() const;
|
|
|
|
int32 GetMediaAt(int32 index) const;
|
|
|
|
|
|
|
|
int32 Media() const;
|
|
|
|
status_t SetMedia(int32 media);
|
|
|
|
|
|
|
|
status_t GetHardwareAddress(BNetworkAddress& address);
|
|
|
|
|
|
|
|
bool IsEthernet();
|
|
|
|
bool IsWireless();
|
|
|
|
|
2016-03-15 23:40:29 +03:00
|
|
|
status_t Control(int option, void* request);
|
|
|
|
|
2010-10-26 00:20:09 +04:00
|
|
|
status_t Scan(bool wait = true,
|
|
|
|
bool forceRescan = true);
|
2010-12-09 01:55:57 +03:00
|
|
|
|
|
|
|
status_t GetNextNetwork(uint32& cookie,
|
|
|
|
wireless_network& network);
|
|
|
|
status_t GetNetwork(const char* name,
|
|
|
|
wireless_network& network);
|
|
|
|
status_t GetNetwork(const BNetworkAddress& address,
|
2010-10-26 00:20:09 +04:00
|
|
|
wireless_network& network);
|
|
|
|
|
2010-12-09 01:55:57 +03:00
|
|
|
status_t JoinNetwork(const char* name,
|
|
|
|
const char* password = NULL);
|
|
|
|
status_t JoinNetwork(const wireless_network& network,
|
2010-12-01 00:22:25 +03:00
|
|
|
const char* password = NULL);
|
2010-10-26 00:20:09 +04:00
|
|
|
status_t JoinNetwork(const BNetworkAddress& address,
|
|
|
|
const char* password = NULL);
|
2010-12-09 01:55:57 +03:00
|
|
|
|
|
|
|
status_t LeaveNetwork(const char* name);
|
|
|
|
status_t LeaveNetwork(const wireless_network& network);
|
|
|
|
status_t LeaveNetwork(const BNetworkAddress& address);
|
|
|
|
|
|
|
|
status_t GetNextAssociatedNetwork(uint32& cookie,
|
|
|
|
wireless_network& network);
|
|
|
|
status_t GetNextAssociatedNetwork(uint32& cookie,
|
|
|
|
BNetworkAddress& address);
|
2010-10-26 00:20:09 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
char fName[IF_NAMESIZE];
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // _NETWORK_DEVICE_H
|