NetBurner 3.5.7
PDF Version
ppp.h
1/*NB_REVISION*/
2
3/*NB_COPYRIGHT*/
4
30#ifndef _NB_PPP_H
31#define _NB_PPP_H
32
33#include <nettypes.h>
34#include <buffers.h>
35#include <netinterface.h>
36#include <vjhc.h>
37
38class PPPInterface; // forward declaration
39
40class ahdlc
41{
42 private:
43 /* User controlled variables. */
44 uint8_t tx_accm[32], rx_accm[32];
45
46 /* Internal state data. */
47 unsigned char *rx_bufp;
48 PoolPtr rx_pool;
49 beuint16_t rx_crc;
50 char escaped;
51 OS_SEM TransmitSemaphore;
52
53 void initialize_rxbuffer();
54 PPPInterface *m_pIf;
55
56 public:
57 ahdlc(PPPInterface *pIf);
58 ~ahdlc();
59 void clear();
60 void receive(char *buffer, int count);
61 void sendone(int fd, char c);
62 void transmit(int fd, char *buffer, int n);
63 void set_tx_accm(uint32_t tx_accm);
64 void set_rx_accm(uint32_t rx_accm);
65};
66
99#define ERR_PPP_SUCCESS (0)
100#define ERR_PPP_ALREADY_OPEN (-1)
101#define ERR_PPP_NO_DIALTONE (-2)
102#define ERR_PPP_NO_ANSWER (-3)
103#define ERR_PPP_BUSY (-4)
104#define ERR_PPP_FAIL (-5)
105#define ERR_PPP_PASSFAIL (-6)
106#define ERR_PPP_LOSTCARRIER (-7)
107#define ERR_PPP_NO_MODEM (-8)
108#define ERR_PPP_LCP_FAILED (-9)
109#define ERR_PPP_CHAPFAIL (-10)
112/* Definition for a PPP Frame */
113typedef struct
114{
115 uint8_t unused[10];
116 beuint16_t PPPAddr;
117 beuint16_t PPPFrameType;
118 uint8_t code;
119 uint8_t idval;
120 beuint16_t length;
121 beuint16_t pData[4];
122} __attribute__((packed)) PPPFRAME;
123
124class LCPState_Class
125{
126 protected:
127 int m_nState;
128 uint16_t m_nOptions;
129 uint32_t options_ok_mask;
130 uint32_t options_nak_mask;
131 uint32_t options_rej_mask;
132 uint16_t m_TicksLeft;
133 uint16_t m_toCount;
134 uint16_t m_FrameType;
135 uint16_t m_nRequests_Sent;
136 LCPState_Class *pNextLayerUp;
137 LCPState_Class *pNextLayerDn;
138 uint8_t m_Last_ReqSent;
139 uint8_t m_Last_ReqRespond;
140 PPPInterface *m_ifc;
141
142 public:
143 void RecieveMsg(PPPFRAME *pPPP, PoolPtr pp);
144 virtual void TestOption(puint8_t option_start, uint32_t maskv) = 0;
145
146 void Up();
147 void Down();
148 void Open();
149 void Close();
150 void Tick();
151 void Initialize(PPPInterface *ppi, uint16_t frame_type, LCPState_Class *next_layer, LCPState_Class *pre_layer);
152 int GetState();
153 void SendPPPBuffer(PoolPtr ppSend);
154 void SendProtoReject(PPPFRAME *pPPP, PoolPtr pp);
155
156 protected:
157 void SetState(int i);
158 void do_irc();
159 void do_zrc();
160 virtual void do_scr() = 0;
161 virtual void do_RCN(PPPFRAME *pPPP, int reject) = 0;
162 virtual void do_wereup();
163 virtual void do_weredown();
164 void do_sca(PPPFRAME *pPPP, PoolPtr pp);
165 void do_scn(PPPFRAME *pPPP, PoolPtr pp);
166 void CopyOptions(PPPFRAME *pPPPOut, PPPFRAME *pPPPin, uint32_t option_mask);
167 void do_str();
168 void do_sta(PPPFRAME *pPPP, PoolPtr pp);
169 void do_ser(PPPFRAME *pPPP, PoolPtr pp);
170 void do_abortconn();
171};
172
173class LCP_Class : public LCPState_Class
174{
175 public:
176 virtual void TestOption(puint8_t option_start, uint32_t maskv);
177 virtual void do_scr();
178 virtual void do_RCN(PPPFRAME *pPPP, int reject);
179 virtual void do_wereup();
180 virtual void do_weredown();
181};
182
183class IPCP_Class : public LCPState_Class
184{
185 public:
186 virtual void TestOption(puint8_t option_start, uint32_t maskv);
187 virtual void do_scr();
188 virtual void do_RCN(PPPFRAME *pPPP, int reject);
189 virtual void do_wereup();
190 virtual void do_weredown();
191};
192
193class PPPInterface : public InterfaceBlock
194{
195 protected:
196 PPPInterface(const char *name = "PPP", const char *pDesc = "PPP Interface");
197 PPPInterface *pNext;
198
199 public:
200 config_int Restart_Interval{
201 3, "Restart_Interval",
202 "Seconds to wait to restart failed negotiation"};
203 config_int Max_Terminate{2, "Max_Terminate",
204 "Max times to send terminate request before giving up"};
205 config_int Max_Configure{
206 25, "Max_Configure",
207 "Max number of config request loops before giving up"};
208 config_int Max_Failure{25, "Max_Failure",
209 "The max number of config failure before giving up"};
210 config_bool DNSRequest{true, "DNSRequest", "Request DNS from the other side of the connection"};
211 config_bool CHAPenable{true, "CHAPEnable", "Enable CHAP authentication"};
212 config_bool RestartOnClose{false, "RestartOnclose", "Restart PPP automatically from close"};
213 config_pass UserName{"nburn", "User", "PPP Username for this interface"};
214 config_pass PassWord{"nburn", "Password", "PPP Password for this interface"};
215 uint32_t TX_DESIRED_ACCM;
216 uint32_t RX_DESIRED_ACCM;
217 config_IPADDR4 OfferedDNSAddress{"0.0.0.0", "OfferedDNS", "Offer a DNS address to the other side"};
218 ConfigEndMarker;
219
220 uint32_t dwflags;
221 uint16_t MRU;
222 uint32_t TX_ACCM;
223 uint32_t RX_ACCM;
224
225 volatile bool if_up;
226 volatile int abort_ppp;
227 volatile enum_PPPState cur_State;
228 volatile bool abortornot;
229 volatile bool m_bDataSeen;
230 volatile uint32_t NextTick;
231
232 int fdserial;
233
234 OS_SEM state_semaphore;
235
236 int ppp_nError;
237
238 volatile uint16_t PPPIds;
239
240 const char *hang_string;
241 int hang_state;
242
243 bool bTO; // Did we time out
244 int pap_to;
245 int chap_to;
246 BOOL client; // Are we a client?
247
248 uint8_t ChallengeID;
249 uint32_t CurrentRand[4];
250
251 bool DoVJCompress;
252 slcompress VJHCStruct;
253 ahdlc ahdlc_obj{this};
254 LCP_Class lcp_automaton;
255 IPCP_Class ipcp_automaton;
256 bool pap_complete;
257 bool chap_complete;
258
259 virtual void send_func(PoolPtr poolPtr);
260 virtual bool LinkActive();
261 virtual int LinkSpeed();
262 virtual bool LinkDuplex();
263 virtual bool bNeedsArp();
264
265 volatile enum_PPPState GetPPPState();
266
267 void EnableMulticast(MACADR macAddress, BOOL addAddress);
268 void processppp();
269 void ClosePPPSesion();
270 void SendPAP();
271 void PAPTick();
272 void ProcessPAP(PPPFRAME *pPPP, PoolPtr pp);
273 void ProcessPPPIP(PPPFRAME *pPPP, PoolPtr pp);
274 void SendCHAP(uint8_t code, uint8_t id = 0); // Sends a CHAP packet to the PPP connected device
275 void SendCHAPChallenge();
276 void CHAPTick();
277 void ProcessCHAP(PPPFRAME *pPPP, PoolPtr pp);
278 void process_rx(PoolPtr pp);
279 void UpdateTimeout();
280
281 int StartIf(int fd);
282 void Restart();
283
284 static void PPPDaemonTask(void *p);
285 static PPPInterface *pListHead;
286};
287
288class PPPServer : public PPPInterface
289{
290 public:
291 PPPServer(const char *name = "PPPS", const char *pDesc = "PPP Server Interface");
292};
293
294class PPPClient : public PPPInterface
295{
296 public:
297 PPPClient(const char *name = "PPPC", const char *pDesc = "PPP Server Interface");
298};
299
300#endif
301
Network interface configuration block class for interface control and configuration.
Definition netinterface.h:244
Used to store and manipulate MAC addresses.
Definition nettypes.h:69
Configuration Variable for IPADDR4 (IPv4) object types.
Definition config_obj.h:1500
Boolean Configuration Variable.
Definition config_obj.h:1000
Signed 32-bit Integer Configuration Variable.
Definition config_obj.h:703
Password string Configuration Variable.
Definition config_obj.h:1348
enum_PPPState
PPP States.
Definition ppp.h:78
@ eClosed
Connection closed.
Definition ppp.h:79
@ eLCPNegotiate
LCP negotiation.
Definition ppp.h:85
@ eClosing
Connection closing.
Definition ppp.h:90
@ eWaitForTrain
Waiting for train.
Definition ppp.h:84
@ ePAPAuthenticate
PAP authentication.
Definition ppp.h:86
@ eDialing
Dialing.
Definition ppp.h:81
@ eOpen
Connection open.
Definition ppp.h:89
@ eAnswering
Answering incoming connection.
Definition ppp.h:83
@ eCHAPAuthenticate
CHAP authentication.
Definition ppp.h:87
@ eNCPNegotiate
NCP negotiation.
Definition ppp.h:88
@ eWait4Ring
Waiting for ring indicator.
Definition ppp.h:82
@ eInitializingModem
Initializing modem.
Definition ppp.h:80
Semaphores are used to control access to shared resources or or to communicate between tasks in a mul...
Definition nbrtos.h:407
Main buffer structure for network and serial communication.
Definition buffers.h:90