xref: /haiku/headers/os/net/NetworkDevice.h (revision 1e60bdeab63fa7a57bc9a55b032052e95a18bd2c)
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 	B_NETWORK_AUTHENTICATION_EAP		= 4
40 };
41 
42 // cipher algorithms
43 enum {
44 	B_NETWORK_CIPHER_NONE				= 0x01,
45 	B_NETWORK_CIPHER_WEP_40				= 0x02,
46 	B_NETWORK_CIPHER_WEP_104			= 0x04,
47 	B_NETWORK_CIPHER_TKIP				= 0x08,
48 	B_NETWORK_CIPHER_CCMP				= 0x10,
49 	B_NETWORK_CIPHER_AES_128_CMAC		= 0x20
50 };
51 
52 // key modes
53 enum {
54 	B_KEY_MODE_IEEE802_1X				= 0x0001,
55 	B_KEY_MODE_PSK						= 0x0002,
56 	B_KEY_MODE_NONE						= 0x0004,
57 	B_KEY_MODE_FT_IEEE802_1X			= 0x0020,
58 	B_KEY_MODE_FT_PSK					= 0x0040,
59 	B_KEY_MODE_IEEE802_1X_SHA256		= 0x0080,
60 	B_KEY_MODE_PSK_SHA256				= 0x0100,
61 	B_KEY_MODE_WPS						= 0x0200
62 };
63 
64 // eap encapsulation method (IEEE 802.1x)
65 enum {
66 	B_NETWORK_EAP_ENCAPSULATION_NONE	= 0x0000,
67 	B_NETWORK_EAP_ENCAPSULATION_PEAP	= 0x0001,
68 	B_NETWORK_EAP_ENCAPSULATION_TLS		= 0x0002
69 };
70 
71 
72 class BNetworkDevice {
73 public:
74 								BNetworkDevice();
75 								BNetworkDevice(const char* name);
76 								~BNetworkDevice();
77 
78 			void				Unset();
79 			void				SetTo(const char* name);
80 
81 			const char*			Name() const;
82 			bool				Exists() const;
83 			uint32				Index() const;
84 
85 			uint32				Flags() const;
86 			bool				HasLink() const;
87 
88 			int32				CountMedia() const;
89 			int32				GetMediaAt(int32 index) const;
90 
91 			int32				Media() const;
92 			status_t			SetMedia(int32 media);
93 
94 			status_t			GetHardwareAddress(BNetworkAddress& address);
95 
96 			bool				IsEthernet();
97 			bool				IsWireless();
98 
99 			status_t			Control(int option, void* request);
100 
101 			status_t			Scan(bool wait = true,
102 									bool forceRescan = true);
103 
104 			status_t			GetNextNetwork(uint32& cookie,
105 									wireless_network& network);
106 			status_t			GetNetwork(const char* name,
107 									wireless_network& network);
108 			status_t			GetNetwork(const BNetworkAddress& address,
109 									wireless_network& network);
110 
111 			status_t			JoinNetwork(const char* name,
112 									const char* password = NULL);
113 			status_t			JoinNetwork(const wireless_network& network,
114 									const char* password = NULL);
115 			status_t			JoinNetwork(const BNetworkAddress& address,
116 									const char* password = NULL);
117 
118 			status_t			LeaveNetwork(const char* name);
119 			status_t			LeaveNetwork(const wireless_network& network);
120 			status_t			LeaveNetwork(const BNetworkAddress& address);
121 
122 			status_t			GetNextAssociatedNetwork(uint32& cookie,
123 									wireless_network& network);
124 			status_t			GetNextAssociatedNetwork(uint32& cookie,
125 									BNetworkAddress& address);
126 
127 private:
128 			char				fName[IF_NAMESIZE];
129 };
130 
131 
132 #endif	// _NETWORK_DEVICE_H
133