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