xref: /haiku/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/PPPControl.h (revision 51978af14a173e7fae0563b562be5603bc652aeb)
1 //----------------------------------------------------------------------
2 //  This software is part of the OpenBeOS distribution and is covered
3 //  by the OpenBeOS license.
4 //
5 //  Copyright (c) 2003 Waldemar Kornewald, Waldemar.Kornewald@web.de
6 //---------------------------------------------------------------------
7 
8 #ifndef _PPP_CONTROL__H
9 #define _PPP_CONTROL__H
10 
11 #include <Drivers.h>
12 #include <driver_settings.h>
13 #include <PPPDefs.h>
14 
15 
16 // various constants
17 #define PPP_HANDLER_NAME_LENGTH_LIMIT		63
18 	// if the name is longer than this value it will be truncated to fit the structure
19 
20 // starting values and other values for control ops
21 #define PPP_RESERVE_OPS_COUNT				0xFFFF
22 #define PPP_OPS_START						B_DEVICE_OP_CODES_END + 1
23 #define PPP_INTERFACE_OPS_START				PPP_OPS_START + PPP_RESERVE_OPS_COUNT
24 #define PPP_DEVICE_OPS_START				PPP_OPS_START + 2 * PPP_RESERVE_OPS_COUNT
25 #define PPP_PROTOCOL_OPS_START				PPP_OPS_START + 3 * PPP_RESERVE_OPS_COUNT
26 #define PPP_OPTION_HANDLER_OPS_START		PPP_OPS_START + 5 * PPP_RESERVE_OPS_COUNT
27 #define PPP_LCP_EXTENSION_OPS_START			PPP_OPS_START + 6 * PPP_RESERVE_OPS_COUNT
28 #define PPP_COMMON_OPS_START				PPP_OPS_START + 10 * PPP_RESERVE_OPS_COUNT
29 #define PPP_USER_OPS_START					PPP_OPS_START + 32 * PPP_RESERVE_OPS_COUNT
30 
31 
32 enum ppp_control_ops {
33 	// -----------------------------------------------------
34 	// PPPManager
35 	PPPC_CREATE_INTERFACE = PPP_OPS_START,
36 	PPPC_DELETE_INTERFACE,
37 	PPPC_BRING_INTERFACE_UP,
38 	PPPC_BRING_INTERFACE_DOWN,
39 	PPPC_CONTROL_INTERFACE,
40 	PPPC_GET_INTERFACES,
41 	PPPC_COUNT_INTERFACES,
42 	// -----------------------------------------------------
43 
44 	// -----------------------------------------------------
45 	// PPPInterface
46 	PPPC_GET_INTERFACE_INFO = PPP_INTERFACE_OPS_START,
47 	PPPC_SET_MRU,
48 	PPPC_SET_DIAL_ON_DEMAND,
49 	PPPC_SET_AUTO_REDIAL,
50 
51 	// handler access
52 	PPPC_CONTROL_DEVICE,
53 	PPPC_CONTROL_PROTOCOL,
54 	PPPC_CONTROL_OPTION_HANDLER,
55 	PPPC_CONTROL_LCP_EXTENSION,
56 	PPPC_CONTROL_CHILD,
57 	// -----------------------------------------------------
58 
59 	// -----------------------------------------------------
60 	// PPPDevice
61 	PPPC_GET_DEVICE_INFO = PPP_DEVICE_OPS_START,
62 	// -----------------------------------------------------
63 
64 	// -----------------------------------------------------
65 	// PPPProtocol
66 	PPPC_GET_PROTOCOL_INFO = PPP_PROTOCOL_OPS_START,
67 	// -----------------------------------------------------
68 
69 	// -----------------------------------------------------
70 	// Common/mixed ops
71 	PPPC_ENABLE,
72 	PPPC_GET_SIMPLE_HANDLER_INFO,
73 		// PPPOptionHandler and PPPLCPExtension
74 
75 	// these two control ops use the ppp_report_request structure
76 	PPPC_ENABLE_REPORTS,
77 	PPPC_DISABLE_REPORTS,
78 		// flags are not used for this control op
79 	// -----------------------------------------------------
80 
81 	PPP_CONTROL_OPS_END = B_DEVICE_OP_CODES_END + 0xFFFF
82 };
83 
84 
85 typedef struct ppp_interface_settings_info {
86 	const driver_settings *settings;
87 	interface_id interface;
88 		// only when creating: this is the id of the created interface
89 } ppp_interface_settings_info;
90 
91 
92 typedef struct ppp_get_interfaces_info {
93 	interface_id *interfaces;
94 	int32 count;
95 	ppp_interface_filter filter;
96 	int32 resultCount;
97 } ppp_get_interfaces_info;
98 
99 
100 typedef struct ppp_control_info {
101 	uint32 index;
102 		// index/id of interface/protocol/etc.
103 	uint32 op;
104 		// the Control()/ioctl() opcode
105 	void *data;
106 	size_t length;
107 		// should always be set
108 } ppp_control_info;
109 
110 
111 // -----------------------------------------------------------
112 // structures for storing information about interface/handlers
113 // use the xxx_info_t structures when allocating memory (they
114 // reserve memory for future implementations)
115 // -----------------------------------------------------------
116 #define _PPP_INFO_T_SIZE_								256
117 
118 typedef struct ppp_interface_info {
119 	const driver_settings *settings;
120 
121 	int32 if_unit;
122 		// negative if not registered
123 
124 	ppp_mode mode;
125 	ppp_state state;
126 	ppp_phase phase;
127 	ppp_authentication_status localAuthenticationStatus, peerAuthenticationStatus;
128 	ppp_pfc_state localPFCState, peerPFCState;
129 	uint8 pfcOptions;
130 
131 	uint32 protocolsCount, optionHandlersCount, LCPExtensionsCount, childrenCount;
132 	uint32 MRU, interfaceMTU;
133 
134 	uint32 dialRetry, dialRetriesLimit;
135 	uint32 dialRetryDelay, redialDelay;
136 	uint32 idleSince, disconnectAfterIdleSince;
137 
138 	bool doesDialOnDemand, doesAutoRedial, hasDevice, isMultilink, hasParent;
139 } ppp_interface_info;
140 typedef struct ppp_interface_info_t {
141 	ppp_interface_info info;
142 	uint8 _reserved_[_PPP_INFO_T_SIZE_ - sizeof(ppp_interface_info)];
143 } ppp_interface_info_t;
144 
145 
146 // devices are special handlers, so they have their own structure
147 typedef struct ppp_device_info {
148 	char name[PPP_HANDLER_NAME_LENGTH_LIMIT + 1];
149 
150 	const driver_parameter *settings;
151 	uint32 MTU;
152 	uint32 inputTransferRate, outputTransferRate, outputBytesCount;
153 	bool isUp;
154 } ppp_device_info;
155 typedef struct ppp_device_info_t {
156 	ppp_device_info info;
157 	uint8 _reserved_[_PPP_INFO_T_SIZE_ - sizeof(ppp_device_info)];
158 } ppp_device_info_t;
159 
160 
161 typedef struct ppp_protocol_info {
162 	char name[PPP_HANDLER_NAME_LENGTH_LIMIT + 1];
163 	char type[PPP_HANDLER_NAME_LENGTH_LIMIT + 1];
164 
165 	const driver_parameter *settings;
166 	ppp_phase activationPhase;
167 	int32 addressFamily, flags;
168 	ppp_side side;
169 	ppp_level level;
170 	uint32 overhead;
171 
172 	ppp_phase connectionPhase;
173 		// there are four possible states:
174 		// PPP_ESTABLISHED_PHASE	-		IsUp() == true
175 		// PPP_DOWN_PHASE			-		IsDown() == true
176 		// PPP_ESTABLISHMENT_PHASE	-		IsGoingUp() == true
177 		// PPP_TERMINATION_PHASE	-		IsGoingDown() == true
178 
179 	uint16 protocolNumber;
180 	bool isEnabled;
181 	bool isUpRequested;
182 } ppp_protocol_info;
183 typedef struct ppp_protocol_info_t {
184 	ppp_protocol_info info;
185 	uint8 _reserved_[_PPP_INFO_T_SIZE_ - sizeof(ppp_protocol_info)];
186 } ppp_protocol_info_t;
187 
188 
189 typedef struct ppp_simple_handler_info {
190 	char name[PPP_HANDLER_NAME_LENGTH_LIMIT + 1];
191 
192 	const driver_parameter *settings;
193 	bool isEnabled;
194 
195 	uint8 code;
196 		// only PPPLCPExtension
197 } ppp_simple_handler_info;
198 typedef struct ppp_simple_handler_info_t {
199 	ppp_simple_handler_info info;
200 	uint8 _reserved_[_PPP_INFO_T_SIZE_ - sizeof(ppp_simple_handler_info)];
201 } ppp_simple_handler_info_t;
202 
203 
204 #endif
205