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 11 #include <NetworkAddress.h> 12 13 14 class BNetworkAddress; 15 16 17 struct wireless_network { 18 char name[32]; 19 BNetworkAddress address; 20 uint8 noise_level; 21 uint8 signal_strength; 22 uint32 flags; 23 uint32 authentication_mode; 24 uint32 cipher; 25 uint32 group_cipher; 26 uint32 key_mode; 27 }; 28 29 // flags 30 #define B_NETWORK_IS_ENCRYPTED 0x01 31 #define B_NETWORK_IS_PERSISTENT 0x02 32 33 // authentication modes 34 enum { 35 B_NETWORK_AUTHENTICATION_NONE = 0, 36 B_NETWORK_AUTHENTICATION_WEP = 1, 37 B_NETWORK_AUTHENTICATION_WPA = 2, 38 B_NETWORK_AUTHENTICATION_WPA2 = 3 39 }; 40 41 // cipher algorithms 42 enum { 43 B_NETWORK_CIPHER_NONE = 0x01, 44 B_NETWORK_CIPHER_WEP_40 = 0x02, 45 B_NETWORK_CIPHER_WEP_104 = 0x04, 46 B_NETWORK_CIPHER_TKIP = 0x08, 47 B_NETWORK_CIPHER_CCMP = 0x10, 48 B_NETWORK_CIPHER_AES_128_CMAC = 0x20 49 }; 50 51 // key modes 52 enum { 53 B_KEY_MODE_IEEE802_1X = 0x0001, 54 B_KEY_MODE_PSK = 0x0002, 55 B_KEY_MODE_NONE = 0x0004, 56 B_KEY_MODE_FT_IEEE802_1X = 0x0020, 57 B_KEY_MODE_FT_PSK = 0x0040, 58 B_KEY_MODE_IEEE802_1X_SHA256 = 0x0080, 59 B_KEY_MODE_PSK_SHA256 = 0x0100, 60 B_KEY_MODE_WPS = 0x0200 61 }; 62 63 64 class BNetworkDevice { 65 public: 66 BNetworkDevice(); 67 BNetworkDevice(const char* name); 68 ~BNetworkDevice(); 69 70 void Unset(); 71 void SetTo(const char* name); 72 73 const char* Name() const; 74 bool Exists() const; 75 uint32 Index() const; 76 77 uint32 Flags() const; 78 bool HasLink() const; 79 80 int32 CountMedia() const; 81 int32 GetMediaAt(int32 index) const; 82 83 int32 Media() const; 84 status_t SetMedia(int32 media); 85 86 status_t GetHardwareAddress(BNetworkAddress& address); 87 88 bool IsEthernet(); 89 bool IsWireless(); 90 91 status_t Scan(bool wait = true, 92 bool forceRescan = true); 93 94 status_t GetNextNetwork(uint32& cookie, 95 wireless_network& network); 96 status_t GetNetwork(const char* name, 97 wireless_network& network); 98 status_t GetNetwork(const BNetworkAddress& address, 99 wireless_network& network); 100 101 status_t JoinNetwork(const char* name, 102 const char* password = NULL); 103 status_t JoinNetwork(const wireless_network& network, 104 const char* password = NULL); 105 status_t JoinNetwork(const BNetworkAddress& address, 106 const char* password = NULL); 107 108 status_t LeaveNetwork(const char* name); 109 status_t LeaveNetwork(const wireless_network& network); 110 status_t LeaveNetwork(const BNetworkAddress& address); 111 112 status_t GetNextAssociatedNetwork(uint32& cookie, 113 wireless_network& network); 114 status_t GetNextAssociatedNetwork(uint32& cookie, 115 BNetworkAddress& address); 116 117 private: 118 char fName[IF_NAMESIZE]; 119 }; 120 121 122 #endif // _NETWORK_DEVICE_H 123