1 /* 2 * Copyright 2010, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _NETWORK_DEVICE_H 6 #define _NETWORK_DEVICE_H 7 8 9 #include <net/if.h> 10 #include <string.h> 11 12 #include <NetworkAddress.h> 13 14 15 class BNetworkAddress; 16 17 18 struct wireless_network { 19 char name[32]; 20 BNetworkAddress address; 21 uint8 noise_level; 22 uint8 signal_strength; 23 uint32 flags; 24 uint32 authentication_mode; 25 uint32 cipher; 26 uint32 group_cipher; 27 uint32 key_mode; 28 29 bool operator==(const wireless_network& other) { 30 return strncmp(name, other.name, 32) == 0 31 // ignore address difference 32 && noise_level == other.noise_level 33 && signal_strength == other.signal_strength 34 && flags == other.flags 35 && authentication_mode == other.authentication_mode 36 && cipher == other.cipher 37 && group_cipher == other.group_cipher 38 && key_mode == other.key_mode; 39 } 40 }; 41 42 // flags 43 #define B_NETWORK_IS_ENCRYPTED 0x01 44 #define B_NETWORK_IS_PERSISTENT 0x02 45 46 // authentication modes 47 enum { 48 B_NETWORK_AUTHENTICATION_NONE = 0, 49 B_NETWORK_AUTHENTICATION_WEP = 1, 50 B_NETWORK_AUTHENTICATION_WPA = 2, 51 B_NETWORK_AUTHENTICATION_WPA2 = 3, 52 B_NETWORK_AUTHENTICATION_EAP = 4 53 }; 54 55 // cipher algorithms 56 enum { 57 B_NETWORK_CIPHER_NONE = 0x01, 58 B_NETWORK_CIPHER_WEP_40 = 0x02, 59 B_NETWORK_CIPHER_WEP_104 = 0x04, 60 B_NETWORK_CIPHER_TKIP = 0x08, 61 B_NETWORK_CIPHER_CCMP = 0x10, 62 B_NETWORK_CIPHER_AES_128_CMAC = 0x20 63 }; 64 65 // key modes 66 enum { 67 B_KEY_MODE_IEEE802_1X = 0x0001, 68 B_KEY_MODE_PSK = 0x0002, 69 B_KEY_MODE_NONE = 0x0004, 70 B_KEY_MODE_FT_IEEE802_1X = 0x0020, 71 B_KEY_MODE_FT_PSK = 0x0040, 72 B_KEY_MODE_IEEE802_1X_SHA256 = 0x0080, 73 B_KEY_MODE_PSK_SHA256 = 0x0100, 74 B_KEY_MODE_WPS = 0x0200 75 }; 76 77 // eap encapsulation method (IEEE 802.1x) 78 enum { 79 B_NETWORK_EAP_ENCAPSULATION_NONE = 0x0000, 80 B_NETWORK_EAP_ENCAPSULATION_PEAP = 0x0001, 81 B_NETWORK_EAP_ENCAPSULATION_TLS = 0x0002 82 }; 83 84 85 class BNetworkDevice { 86 public: 87 BNetworkDevice(); 88 BNetworkDevice(const char* name); 89 ~BNetworkDevice(); 90 91 void Unset(); 92 void SetTo(const char* name); 93 94 const char* Name() const; 95 bool Exists() const; 96 uint32 Index() const; 97 98 uint32 Flags() const; 99 bool HasLink() const; 100 101 int32 CountMedia() const; 102 int32 GetMediaAt(int32 index) const; 103 104 int32 Media() const; 105 status_t SetMedia(int32 media); 106 107 status_t GetHardwareAddress(BNetworkAddress& address); 108 109 bool IsEthernet(); 110 bool IsWireless(); 111 112 status_t Control(int option, void* request); 113 114 status_t Scan(bool wait = true, 115 bool forceRescan = true); 116 117 status_t GetNextNetwork(uint32& cookie, 118 wireless_network& network); 119 status_t GetNetwork(const char* name, 120 wireless_network& network); 121 status_t GetNetwork(const BNetworkAddress& address, 122 wireless_network& network); 123 124 status_t JoinNetwork(const char* name, 125 const char* password = NULL); 126 status_t JoinNetwork(const wireless_network& network, 127 const char* password = NULL); 128 status_t JoinNetwork(const BNetworkAddress& address, 129 const char* password = NULL); 130 131 status_t LeaveNetwork(const char* name); 132 status_t LeaveNetwork(const wireless_network& network); 133 status_t LeaveNetwork(const BNetworkAddress& address); 134 135 status_t GetNextAssociatedNetwork(uint32& cookie, 136 wireless_network& network); 137 status_t GetNextAssociatedNetwork(uint32& cookie, 138 BNetworkAddress& address); 139 140 private: 141 char fName[IF_NAMESIZE]; 142 }; 143 144 145 #endif // _NETWORK_DEVICE_H 146