annotate network/PPP.c @ 110:4eb5a746d7af avr-http

Import avrusbmodem code minus the USB bits. Not built yet.
author Matt Johnston <matt@ucc.asn.au>
date Sat, 15 Sep 2012 21:49:05 +0800
parents 56d09a0969b5
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
107
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1 /*
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
2 LUFA Powered Wireless 3G Modem Host
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
3
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
4 Copyright (C) Mike Alexander, 2010.
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
5 Copyright (C) Dean Camera, 2010.
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
6 */
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
7
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
8 /*
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
9 Copyright 2010 Mike Alexander (mike [at] mikealex [dot] com)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
10 Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
11
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
12 Permission to use, copy, modify, distribute, and sell this
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
13 software and its documentation for any purpose is hereby granted
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
14 without fee, provided that the above copyright notice appear in
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
15 all copies and that both that the copyright notice and this
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
16 permission notice and warranty disclaimer appear in supporting
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
17 documentation, and that the name of the author not be used in
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
18 advertising or publicity pertaining to distribution of the
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
19 software without specific, written prior permission.
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
20
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
21 The author disclaim all warranties with regard to this
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
22 software, including all implied warranties of merchantability
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
23 and fitness. In no event shall the author be liable for any
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
24 special, indirect or consequential damages or any damages
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
25 whatsoever resulting from loss of use, data or profits, whether
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
26 in an action of contract, negligence or other tortious action,
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
27 arising out of or in connection with the use or performance of
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
28 this software.
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
29 */
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
30
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
31 #define INCLUDE_FROM_PPP_C
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
32 #include "PPP.h"
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
33
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
34 static uint8_t OutgoingPacketID; // Unique packet ID
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
35 static PPP_Phases_t PPP_Phase; // PPP negotiation phases
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
36 static PPP_States_t LCP_State; // Each phase has a number of states
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
37 static PPP_States_t PAP_State;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
38 static PPP_States_t IPCP_State;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
39 static PPP_Packet_t* OutgoingPacket; // Pointer to the outgoing packet
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
40 static PPP_Packet_t* IncomingPacket; // Pointer to the incoming packet
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
41 static uint16_t CurrentProtocol; // Type of the last received packet
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
42 static uint8_t RestartCount;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
43 static uint16_t LinkTimer;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
44 static bool TimerOn;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
45 static bool MarkForNAK;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
46 static bool MarkForREJ;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
47 static uint8_t OutgoingPacketBuffer[OUTGOING_PACKET_BUFFER_SIZE]; // Buffer to store the outgoing packet in
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
48
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
49 PPP_Packet_t* dummy;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
50
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
51
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
52 void PPP_InitPPP(void)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
53 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
54 PPP_Phase = PPP_PHASE_Dead;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
55 TimerOn = false;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
56 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
57
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
58 void PPP_StartLink(void)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
59 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
60 OutgoingPacket = NULL;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
61 CurrentProtocol = NONE;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
62 TimerOn = false;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
63 LinkTimer = 0;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
64 uip_len = 0;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
65 RestartCount = MAX_RESTARTS;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
66 MarkForNAK = MarkForREJ = false;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
67 OutgoingPacketID = -1;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
68 OutgoingPacket = IncomingPacket = NULL;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
69 LCP_State = PPP_STATE_Initial;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
70 PAP_State = PPP_STATE_Initial;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
71 IPCP_State = PPP_STATE_Initial;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
72 PPP_Phase = PPP_PHASE_Establish;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
73 PPP_ManageState(PPP_EVENT_Open, &LCP_State, PPP_LAYER_Physical);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
74 PPP_ManageState(PPP_EVENT_Up, &LCP_State, PPP_LAYER_Physical);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
75 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
76
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
77 // Called every 10ms. Send events to the state machine every 3 seconds if the timer is currently running
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
78 void PPP_LinkTimer(void)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
79 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
80 if (!TimerOn || LinkTimer++ < 300)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
81 return;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
82
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
83 if (RestartCount > 0)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
84 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
85 Debug_Print("Timer+\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
86
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
87 switch(PPP_Phase)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
88 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
89 case PPP_PHASE_Establish:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
90 PPP_ManageState(PPP_EVENT_TOPlus, &LCP_State, PPP_LAYER_Physical);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
91 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
92
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
93 case PPP_PHASE_Authenticate:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
94 PPP_ManageState(PPP_EVENT_TOPlus, &PAP_State, PPP_LAYER_Authentication);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
95 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
96
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
97 case PPP_PHASE_Network:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
98 PPP_ManageState(PPP_EVENT_TOPlus, &IPCP_State, PPP_LAYER_Network);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
99 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
100
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
101 default:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
102 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
103 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
104 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
105 else
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
106 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
107 Debug_Print("Timer-\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
108
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
109 switch(PPP_Phase)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
110 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
111 case PPP_PHASE_Establish:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
112 PPP_ManageState(PPP_EVENT_TOMinus, &LCP_State, PPP_LAYER_Physical);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
113 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
114
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
115 case PPP_PHASE_Authenticate:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
116 PPP_ManageState(PPP_EVENT_TOMinus, &PAP_State, PPP_LAYER_Authentication);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
117 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
118
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
119 case PPP_PHASE_Network:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
120 PPP_ManageState(PPP_EVENT_TOMinus, &IPCP_State, PPP_LAYER_Network);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
121 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
122
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
123 default:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
124 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
125 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
126 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
127
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
128 LinkTimer = 0; // Reset Timer
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
129 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
130
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
131 void PPP_ManageLink(void)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
132 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
133 if (PPP_Phase == PPP_PHASE_Dead)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
134 return;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
135
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
136 uint16_t ReadProtocol = network_read(); // Don't mess with CurrentProtocol in case we get 0 (No data) back
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
137
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
138 if (ReadProtocol == 0)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
139 return;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
140
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
141 CurrentProtocol = ReadProtocol;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
142 IncomingPacket = (PPP_Packet_t*)uip_buf; // Map the incoming data to a packet
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
143
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
144 Debug_Print("Got ");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
145
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
146 switch (CurrentProtocol)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
147 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
148 case LCP:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
149 Debug_Print("LCP ");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
150
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
151 switch(IncomingPacket->Code)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
152 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
153 case REQ:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
154 Debug_Print("REQ\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
155
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
156 MarkForNAK = MarkForREJ = false;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
157
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
158 // List of options that we can support. If any other options come in, we have to REJ them
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
159 const uint8_t SupportedOptions[] = {LCP_OPTION_Maximum_Receive_Unit,
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
160 LCP_OPTION_Magic_Number,
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
161 LCP_OPTION_Async_Control_Character_Map,
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
162 LCP_OPTION_Authentication_Protocol,
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
163 LCP_OPTION_Protocol_Field_Compression,
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
164 LCP_OPTION_Address_and_Control_Field_Compression};
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
165
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
166 if ((MarkForREJ = PPP_TestForREJ(SupportedOptions, sizeof(SupportedOptions)))) // Check that we can support all the options the other end wants to use
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
167 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
168 PPP_ManageState(PPP_EVENT_RCRMinus, &LCP_State, PPP_LAYER_Physical);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
169 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
170 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
171
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
172 static PPP_Option_t Option3 = {.Type = 0x03, .Length = 4, .Data = {0xc0, 0x23}};
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
173
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
174 if ((MarkForNAK = PPP_TestForNAK(&Option3))) // Check that the authentication protocol = PAP (0xc023)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
175 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
176 PPP_ManageState(PPP_EVENT_RCRMinus, &LCP_State, PPP_LAYER_Physical);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
177 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
178 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
179
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
180 PPP_ManageState(PPP_EVENT_RCRPlus, &LCP_State, PPP_LAYER_Physical);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
181 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
182
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
183 case ACK:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
184 Debug_Print("ACK\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
185
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
186 if (IncomingPacket->PacketID != OutgoingPacketID)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
187 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
188 Debug_Print("Out of sync\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
189 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
190 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
191
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
192 PPP_ManageState(PPP_EVENT_RCA, &LCP_State, PPP_LAYER_Physical);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
193 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
194
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
195 case NAK:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
196 Debug_Print("NAK\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
197
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
198 if (IncomingPacket->PacketID != OutgoingPacketID)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
199 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
200 Debug_Print("Out of sync\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
201 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
202 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
203
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
204 PPP_ProcessNAK();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
205 PPP_ManageState(PPP_EVENT_RCN, &LCP_State, PPP_LAYER_Physical);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
206 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
207
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
208 case REJ:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
209 Debug_Print("REJ\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
210
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
211 if (IncomingPacket->PacketID != OutgoingPacketID)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
212 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
213 Debug_Print("Out of sync\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
214 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
215 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
216
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
217 PPP_ProcessREJ();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
218 PPP_ManageState(PPP_EVENT_RCN, &LCP_State, PPP_LAYER_Physical);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
219 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
220
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
221 case DISC:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
222 case ECHOREQ:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
223 case ECHOREPLY:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
224 Debug_Print("DISC\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
225 PPP_ManageState(PPP_EVENT_RXR, &LCP_State, PPP_LAYER_Physical);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
226 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
227
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
228 case TERMREQ:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
229 Debug_Print("TERM\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
230 PPP_ManageState(PPP_EVENT_RTR, &LCP_State, PPP_LAYER_Physical);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
231 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
232
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
233 case CODEREJ:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
234 case PROTREJ:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
235 Debug_Print("CODE/PROTREJ\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
236 PPP_ManageState(PPP_EVENT_RXJMinus, &LCP_State, PPP_LAYER_Physical);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
237 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
238
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
239 default:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
240 Debug_Print("unknown\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
241 PPP_ManageState(PPP_EVENT_RUC, &LCP_State, PPP_LAYER_Physical);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
242 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
243 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
244 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
245
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
246 case PAP:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
247 Debug_Print("PAP ");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
248
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
249 switch(IncomingPacket->Code)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
250 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
251 case REQ:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
252 Debug_Print("REQ\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
253 PPP_ManageState(PPP_EVENT_RCRPlus, &PAP_State, PPP_LAYER_Authentication);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
254 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
255
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
256 case ACK:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
257 Debug_Print("ACK\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
258 PPP_ManageState(PPP_EVENT_RCRPlus, &PAP_State, PPP_LAYER_Authentication); // The host never sends a Configure request for PAP, but we need it to move the state machine to completion. So, fake it.
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
259 PPP_ManageState(PPP_EVENT_RCA, &PAP_State, PPP_LAYER_Authentication);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
260 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
261 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
262 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
263
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
264 case IPCP:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
265 Debug_Print("IPCP ");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
266
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
267 switch(IncomingPacket->Code)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
268 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
269 case REQ:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
270 Debug_Print("REQ\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
271
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
272 MarkForNAK = MarkForREJ = false;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
273
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
274 // List of options that we can support. If any other options come in, we have to REJ them
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
275 uint8_t SupportedOptions[] = {IPCP_OPTION_IP_address, IPCP_OPTION_Primary_DNS, IPCP_OPTION_Secondary_DNS};
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
276
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
277 if ((MarkForREJ = PPP_TestForREJ(SupportedOptions, sizeof(SupportedOptions))))
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
278 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
279 PPP_ManageState(PPP_EVENT_RCRMinus, &IPCP_State, PPP_LAYER_Network);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
280 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
281 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
282
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
283 PPP_ManageState(PPP_EVENT_RCRPlus, &IPCP_State, PPP_LAYER_Network);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
284 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
285
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
286 case ACK:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
287 Debug_Print("ACK\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
288
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
289 if (IncomingPacket->PacketID != OutgoingPacketID)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
290 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
291 Debug_Print("Out of sync\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
292 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
293 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
294
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
295 IPAddr1 = IncomingPacket->Options[0].Data[0]; // Store address for use in IP packets.
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
296 IPAddr2 = IncomingPacket->Options[0].Data[1]; // Assumption is that Option 3 is the first option, which it
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
297 IPAddr3 = IncomingPacket->Options[0].Data[2]; // should be as the PPP spec states that implementations should
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
298 IPAddr4 = IncomingPacket->Options[0].Data[3]; // not reorder packets, and we sent out a REQ with option 3 first
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
299
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
300 PPP_ManageState(PPP_EVENT_RCA, &IPCP_State, PPP_LAYER_Network);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
301 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
302
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
303 case NAK:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
304 Debug_Print("NAK\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
305 if (IncomingPacket->PacketID != OutgoingPacketID)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
306 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
307 Debug_Print("Out of sync\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
308 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
309 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
310
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
311 PPP_ProcessNAK();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
312 PPP_ManageState(PPP_EVENT_RCN, &IPCP_State, PPP_LAYER_Network);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
313 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
314
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
315 case REJ:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
316 Debug_Print("REJ\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
317
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
318 if (IncomingPacket->PacketID != OutgoingPacketID)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
319 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
320 Debug_Print("Out of sync\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
321 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
322 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
323
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
324 PPP_ProcessREJ();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
325 PPP_ManageState(PPP_EVENT_RCN, &IPCP_State, PPP_LAYER_Network);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
326 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
327 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
328 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
329
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
330 case IP:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
331 TCPIP_GotNewPacket();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
332 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
333
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
334 default:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
335 Debug_Print("unknown protocol: 0x");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
336 Debug_PrintHex(CurrentProtocol / 256); Debug_PrintHex(CurrentProtocol & 255);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
337 Debug_Print("\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
338 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
339 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
340 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
341
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
342
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
343 // Either create a new OutgoingPacket, or if we've just received a NAK or REJ we will have already changed the OutgoingPacket so just send that
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
344 static void Send_Configure_Request(void)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
345 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
346 Debug_Print("Send Configure Request\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
347
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
348 switch(PPP_Phase)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
349 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
350 case PPP_PHASE_Establish:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
351 if (OutgoingPacket == NULL) // Create a new packet
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
352 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
353 // When we send a REQ, we want to make sure that the other end supports these options
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
354 // static PPP_Option_t Option1 = {.Type = LCP_OPTION_Maximum_Receive_Unit, .Length = 4, .Data = {0x5, 0xa0}};
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
355 static PPP_Option_t Option2 = {.Type = LCP_OPTION_Async_Control_Character_Map, .Length = 6, .Data = {0x0, 0x0, 0x0, 0x0}};
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
356 static PPP_Option_t Option5 = {.Type = LCP_OPTION_Magic_Number, .Length = 6, .Data = {0x27, 0xf5, 0x46, 0xa1}};
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
357 static PPP_Option_t Option7 = {.Type = LCP_OPTION_Protocol_Field_Compression, .Length = 2};
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
358 static PPP_Option_t Option8 = {.Type = LCP_OPTION_Address_and_Control_Field_Compression, .Length = 2};
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
359 static PPP_Option_t OptionD = {.Type = LCP_OPTION_Callback, .Length = 3, .Data = {0x6}};
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
360
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
361 //PPP_AddOption(OutgoingPacket, &Option1);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
362 PPP_AddOption(&Option2);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
363 PPP_AddOption(&Option5);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
364 PPP_AddOption(&Option7);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
365 PPP_AddOption(&Option8);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
366 PPP_AddOption(&OptionD);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
367 OutgoingPacket->Code = REQ;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
368 CurrentProtocol = LCP;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
369 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
370 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
371
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
372 case PPP_PHASE_Authenticate:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
373 if (OutgoingPacket == NULL) // Create a new packet
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
374 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
375 static PPP_Option_t Option0 = {.Type = 0x00, .Length = 2};
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
376
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
377 PPP_AddOption(&Option0);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
378 OutgoingPacket->Options[0].Type = 0x00; // No User Name
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
379 OutgoingPacket->Options[0].Length = 0x00; // No Password
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
380 OutgoingPacket->Code = REQ;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
381 CurrentProtocol = PAP;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
382 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
383 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
384
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
385 case PPP_PHASE_Network:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
386 if (OutgoingPacket == NULL) // Create a new packet
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
387 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
388 // When we send a REQ, we want to make sure that the other end supports these options
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
389 static PPP_Option_t Option3 = {.Type = IPCP_OPTION_IP_address, .Length = 6, .Data = {0, 0, 0, 0}};
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
390 static PPP_Option_t Option81 = {.Type = IPCP_OPTION_Primary_DNS, .Length = 6, .Data = {0, 0, 0, 0}};
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
391 static PPP_Option_t Option83 = {.Type = IPCP_OPTION_Secondary_DNS, .Length = 6, .Data = {0, 0, 0, 0}};
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
392
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
393 PPP_AddOption(&Option3); // Make sure Option3 is first
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
394 PPP_AddOption(&Option81);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
395 PPP_AddOption(&Option83);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
396 OutgoingPacket->Code = REQ;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
397 CurrentProtocol = IPCP;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
398 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
399 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
400
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
401 default:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
402 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
403 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
404
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
405 OutgoingPacket->PacketID = ++OutgoingPacketID; // Every new REQ Packet going out gets a new ID
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
406 RestartCount--; // Decrement the count before we restart the layer
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
407 uip_len = uip_ntohs(OutgoingPacket->Length);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
408 memcpy(uip_buf, OutgoingPacket, uip_len); // Copy the outgoing packet to the buffer for sending
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
409
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
410 network_send(CurrentProtocol); // Send either the new packet or the modified packet
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
411 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
412
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
413
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
414 // We change the incoming packet code to send an ACK to the remote end, and re-use all the data from the incoming packet
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
415 static void Send_Configure_Ack(void)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
416 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
417 Debug_Print("Send Configure ACK\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
418
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
419 IncomingPacket->Code = ACK;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
420 network_send(CurrentProtocol);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
421 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
422
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
423 // We change the incoming packet code to send a NAK or REJ to the remote end. The incoming packet has already been altered to show which options to NAK/REJ
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
424 static void Send_Configure_Nak_Rej(void)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
425 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
426 if (MarkForNAK)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
427 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
428 Debug_Print("Send Configure NAK\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
429 IncomingPacket->Code = NAK;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
430 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
431 else if (MarkForREJ)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
432 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
433 Debug_Print("Send Configure REJ\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
434 IncomingPacket->Code = REJ;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
435 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
436 else
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
437 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
438 return;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
439 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
440
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
441 uip_len = uip_ntohs(IncomingPacket->Length);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
442 network_send(CurrentProtocol);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
443 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
444
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
445 // Send a TERM to the remote end.
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
446 static void Send_Terminate_Request(void)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
447 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
448 Debug_Print("Send Terminate Request\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
449
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
450 OutgoingPacket = (PPP_Packet_t*)uip_buf; // Build the outgoing packet in uip_buf
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
451 CurrentProtocol = LCP;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
452 OutgoingPacket->Code = TERMREQ;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
453 OutgoingPacket->Length = UIP_HTONS(sizeof(PPP_Packet_t));
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
454 OutgoingPacket->PacketID = ++OutgoingPacketID; // Every new REQ Packet going out gets a new ID
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
455
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
456 RestartCount--;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
457
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
458 uip_len = uip_ntohs(OutgoingPacket->Length);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
459 network_send(CurrentProtocol); // Send the packet
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
460 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
461
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
462 // Send a TERM ACK to the remote end.
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
463 static void Send_Terminate_Ack(void)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
464 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
465 Debug_Print("Send Terminate ACK\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
466
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
467 IncomingPacket->Code = TERMREPLY;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
468 network_send(CurrentProtocol);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
469 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
470
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
471 // Send a REJ to the remote end.
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
472 static void Send_Code_Reject(void)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
473 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
474 Debug_Print("Send Code Reject\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
475
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
476 IncomingPacket->Code = CODEREJ;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
477 network_send(CurrentProtocol);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
478 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
479
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
480 // Send an ECHO to the remote end.
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
481 static void Send_Echo_Reply(void)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
482 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
483 Debug_Print("Send Echo Reply\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
484
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
485 IncomingPacket->Code = ECHOREPLY;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
486 network_send(CurrentProtocol);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
487 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
488
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
489 // Called by the state machine when the current layer comes up. Use this to start the next layer up.
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
490 static void This_Layer_Up(PPP_Layers_t Layer)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
491 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
492 CurrentProtocol = NONE;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
493 OutgoingPacket = NULL; // Clear the outgoing packet
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
494
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
495 switch(Layer)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
496 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
497 case PPP_LAYER_Physical:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
498 Debug_Print("**LCP Up**\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
499 PPP_Phase = PPP_PHASE_Authenticate;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
500 OutgoingPacketID = -1;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
501 PPP_ManageState(PPP_EVENT_Open, &PAP_State, PPP_LAYER_Authentication);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
502 PPP_ManageState(PPP_EVENT_Up, &PAP_State, PPP_LAYER_Authentication);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
503 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
504
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
505 case PPP_LAYER_Authentication:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
506 Debug_Print("**PAP Up**\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
507 PPP_Phase = PPP_PHASE_Network;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
508 OutgoingPacketID = -1;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
509 PPP_ManageState(PPP_EVENT_Open, &IPCP_State, PPP_LAYER_Network);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
510 PPP_ManageState(PPP_EVENT_Up, &IPCP_State, PPP_LAYER_Network);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
511 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
512
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
513 case PPP_LAYER_Network:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
514 Debug_Print("**IPCP Up**\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
515 ConnectedState = LINKMANAGEMENT_STATE_InitializeTCPStack;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
516 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
517
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
518 default:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
519 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
520 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
521 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
522
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
523 // Called by the state machine when a layer goes down. Use this to stop the next layer up
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
524 static void This_Layer_Down(PPP_Layers_t Layer)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
525 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
526 OutgoingPacket = NULL; // Clear the outgoing packet
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
527
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
528 switch(Layer)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
529 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
530 case PPP_LAYER_Physical:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
531 Debug_Print("**LCP Down**\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
532 PPP_ManageState(PPP_EVENT_Down, &PAP_State, PPP_LAYER_Authentication);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
533 PPP_Phase = PPP_PHASE_Establish;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
534 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
535
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
536 case PPP_LAYER_Authentication:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
537 Debug_Print("**PAP Down**\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
538 PPP_ManageState(PPP_EVENT_Down, &IPCP_State, PPP_LAYER_Network);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
539 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
540
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
541 case PPP_LAYER_Network:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
542 Debug_Print("**IPCP Down**\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
543 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
544
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
545 default:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
546 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
547 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
548 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
549
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
550 // Called by the state machine when the current layer starts
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
551 static void This_Layer_Started(PPP_Layers_t Layer)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
552 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
553 switch(Layer)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
554 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
555 case PPP_LAYER_Physical:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
556 Debug_Print("**LCP Started**\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
557 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
558
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
559 case PPP_LAYER_Authentication:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
560 Debug_Print("**PAP Started**\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
561 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
562
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
563 case PPP_LAYER_Network:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
564 Debug_Print("**IPCP Started**\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
565 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
566
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
567 default:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
568 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
569 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
570 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
571
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
572 // Called by the state machine when the current layer finishes
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
573 static void This_Layer_Finished(PPP_Layers_t Layer)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
574 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
575 switch(Layer)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
576 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
577 case PPP_LAYER_Physical:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
578 Debug_Print("**LCP Finished**\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
579 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
580
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
581 case PPP_LAYER_Authentication:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
582 Debug_Print("**PAP Finished**\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
583 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
584
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
585 case PPP_LAYER_Network:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
586 Debug_Print("**IPCP Finished**\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
587 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
588
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
589 default:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
590 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
591 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
592
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
593 Debug_Print("**Rebooting**\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
594 Reboot();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
595 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
596
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
597
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
598 // We get a NAK if our outbound Configure Request contains valid options, but the values are wrong. So we adjust our values for when the next Configure Request is sent
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
599 static void PPP_ProcessNAK(void)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
600 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
601 PPP_Option_t* CurrentOption = NULL;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
602
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
603 while ((CurrentOption = PPP_GetNextOption(IncomingPacket, CurrentOption)) != NULL) // Scan options in NAK packet
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
604 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
605 if (PPP_CheckForOption(CurrentOption))
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
606 PPP_ChangeOption(OutgoingPacket, CurrentOption); // If the NAK'd option is already in the outgoing packet then change the existing option
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
607 else
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
608 PPP_AddOption(CurrentOption); // Otherwise add it
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
609 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
610 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
611
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
612 // We get a REJ if our outbound Configure Request contains any options not acceptable to the remote end. So we remove those options.
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
613 static void PPP_ProcessREJ(void)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
614 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
615 PPP_Option_t* CurrentOption = NULL;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
616
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
617 while ((CurrentOption = PPP_GetNextOption(IncomingPacket, CurrentOption)) != NULL) // Scan options in REJ packet
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
618 PPP_RemoveOption(OutgoingPacket, CurrentOption->Type); // Remove the options(s) we don't want
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
619 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
620
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
621 // Test to see if the incoming packet contains any options we can't support If so, take out all good options and leave the bad ones to be sent out in the REJ
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
622 static bool PPP_TestForREJ(const uint8_t Options[],
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
623 const uint8_t NumOptions)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
624 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
625 PPP_Option_t* CurrentOption = NULL;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
626 bool FoundBadOption = false;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
627 bool ThisOptionOK;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
628
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
629 while ((CurrentOption = PPP_GetNextOption(IncomingPacket, CurrentOption)) != NULL) // Scan incoming options
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
630 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
631 ThisOptionOK = false;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
632
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
633 for (uint8_t i = 0; i < NumOptions; i++)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
634 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
635 if (CurrentOption->Type == Options[i])
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
636 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
637 ThisOptionOK = true;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
638 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
639 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
640 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
641
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
642 if (!ThisOptionOK)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
643 FoundBadOption = true;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
644 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
645
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
646 if (!FoundBadOption) // No bad options. Return, leaving the packet untouched
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
647 return false;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
648
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
649 // We found some bad options, so now we need to go through the packet and remove all others, leaving the bad options to be sent out in the REJ
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
650 while ((CurrentOption = PPP_GetNextOption(IncomingPacket, CurrentOption)) != NULL)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
651 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
652 for (uint8_t i = 0; i < NumOptions; i++)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
653 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
654 if (CurrentOption->Type == Options[i])
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
655 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
656 PPP_RemoveOption(IncomingPacket, CurrentOption->Type);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
657 CurrentOption = NULL; // Start again. Easier than moving back (as next option has now moved into place of current option)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
658 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
659 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
660 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
661 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
662
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
663 return true;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
664 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
665
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
666 // Test to see if the incoming packet contains an option with values that we can't accept
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
667 static bool PPP_TestForNAK(const PPP_Option_t* const Option)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
668 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
669 PPP_Option_t* CurrentOption = NULL;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
670 bool FoundBadOption = false;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
671
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
672 while ((CurrentOption = PPP_GetNextOption(IncomingPacket, CurrentOption)) != NULL) // Scan options in receiver buffer
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
673 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
674 if (CurrentOption->Type == Option->Type)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
675 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
676 for (uint8_t i = 0; i < Option->Length - 2; i++)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
677 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
678 if (CurrentOption->Data[i] != Option->Data[i])
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
679 FoundBadOption = true;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
680 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
681 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
682 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
683
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
684 if (!FoundBadOption) // No bad option. Return, leaving the packet untouched
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
685 return false;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
686
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
687 // We found a bad option, so now we need to go through the packet and remove all others, leaving the bad option to be sent out in the NAK
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
688 // and change the bad option to have a value that we can support
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
689 while ((CurrentOption = PPP_GetNextOption(IncomingPacket, CurrentOption)) != NULL)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
690 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
691 if (CurrentOption->Type == Option->Type)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
692 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
693 PPP_ChangeOption(IncomingPacket, Option);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
694 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
695 else
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
696 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
697 PPP_RemoveOption(IncomingPacket, CurrentOption->Type);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
698 CurrentOption = NULL; // Start again. Easier than moving back (as next option has now moved into place of current option)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
699 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
700 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
701
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
702 return true;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
703 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
704
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
705
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
706 /////////////////////////////
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
707 // Packet Helper functions //
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
708 /////////////////////////////
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
709
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
710 // Check if the given option is in the outgoing packet
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
711 static bool PPP_CheckForOption(const PPP_Option_t* const Option)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
712 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
713 PPP_Option_t* CurrentOption = NULL;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
714
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
715 while ((CurrentOption = PPP_GetNextOption(OutgoingPacket, CurrentOption)) != NULL) // Scan options in the packet
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
716 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
717 if (CurrentOption->Type == Option->Type)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
718 return true;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
719 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
720
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
721 return false;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
722 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
723
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
724 // Add the given option to the end of the outgoing packet and adjust the size of the packet
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
725 static void PPP_AddOption(const PPP_Option_t* const Option)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
726 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
727 uint16_t OldPacketLength, NewPacketLength;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
728
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
729 if (OutgoingPacket == NULL)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
730 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
731 OutgoingPacket = (PPP_Packet_t*)&OutgoingPacketBuffer;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
732 OldPacketLength = sizeof(PPP_Packet_t); // If we're creating a new empty packet
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
733 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
734 else
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
735 OldPacketLength = uip_ntohs(OutgoingPacket->Length); // If the packet already exists
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
736
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
737 NewPacketLength = OldPacketLength + Option->Length;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
738
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
739 if (NewPacketLength > OUTGOING_PACKET_BUFFER_SIZE)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
740 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
741 Debug_Print("*** Packet overflow ***\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
742 return;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
743 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
744
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
745 memcpy((void*)OutgoingPacket + OldPacketLength, Option, Option->Length); // Add the new option
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
746
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
747 OutgoingPacket->Length = uip_htons(NewPacketLength);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
748 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
749
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
750 // Try and find the option in the packet, and if it exists, change its value to that in the passed-in option (assumes the option lengths are the same)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
751 static void PPP_ChangeOption(PPP_Packet_t* const ThisPacket,
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
752 const PPP_Option_t* const Option)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
753 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
754 PPP_Option_t* CurrentOption = NULL;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
755
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
756 while ((CurrentOption = PPP_GetNextOption(ThisPacket, CurrentOption)) != NULL) // Scan options in the packet
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
757 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
758 if (CurrentOption->Type == Option->Type)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
759 memcpy(CurrentOption->Data, Option->Data, Option->Length - 2); // Copy the data portion of the option (not Type or Length)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
760 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
761 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
762
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
763 // Try and find the option in the packet, and if it exists remove it and adjust the size of the packet
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
764 static void PPP_RemoveOption(PPP_Packet_t* const ThisPacket,
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
765 const uint8_t Type)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
766 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
767 PPP_Option_t* CurrentOption = NULL;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
768 PPP_Option_t* NextOption = NULL;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
769
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
770 while ((CurrentOption = PPP_GetNextOption(ThisPacket, CurrentOption)) != NULL) // Scan the options in the packet
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
771 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
772 if (CurrentOption->Type == Type) // Is it the packet we want to remove?
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
773 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
774 NextOption = PPP_GetNextOption(ThisPacket, CurrentOption); // Find the next option in the packet
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
775 uint8_t OptionLength = CurrentOption->Length; // Save the Option Length as the memcpy will change CurrentOption->Length
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
776
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
777 if (NextOption != NULL) // If it's not the last option in the packet ...
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
778 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
779 uint16_t LenToCopy = uip_ntohs(ThisPacket->Length) - ((void*)CurrentOption - (void*)ThisPacket) - OptionLength;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
780 memcpy(CurrentOption, NextOption, LenToCopy); // ... move all further options forward
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
781 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
782
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
783 ThisPacket->Length = uip_htons(uip_ntohs(ThisPacket->Length) - OptionLength); // Adjust the length
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
784 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
785 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
786 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
787
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
788 // Get the next option in the packet from the option that is passed in. Return NULL if last packet
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
789 static PPP_Option_t* PPP_GetNextOption(const PPP_Packet_t* const ThisPacket,
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
790 const PPP_Option_t* const CurrentOption)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
791 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
792 PPP_Option_t* NextOption;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
793
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
794 if (CurrentOption == NULL)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
795 NextOption = (PPP_Option_t*)ThisPacket->Options; // First option
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
796 else
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
797 NextOption = (PPP_Option_t*)((uint8_t*)CurrentOption + CurrentOption->Length);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
798
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
799 // Check that we haven't overrun the end of the packet
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
800 if (((void*)NextOption - (void*)ThisPacket->Options) < (uip_ntohs(ThisPacket->Length) - 4))
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
801 return NextOption;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
802 else
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
803 return NULL;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
804 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
805
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
806
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
807
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
808 /////////////////////////////////////////////////////////////////////////////////////////
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
809 // The main PPP state machine - following RFC1661 - http://tools.ietf.org/html/rfc1661 //
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
810 /////////////////////////////////////////////////////////////////////////////////////////
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
811
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
812 static void PPP_ManageState(const PPP_Events_t Event,
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
813 PPP_States_t* const State,
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
814 PPP_Layers_t const Layer)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
815 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
816 switch (*State)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
817 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
818 case PPP_STATE_Initial:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
819
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
820 switch (Event)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
821 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
822 case PPP_EVENT_Up:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
823 *State = PPP_STATE_Closed;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
824 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
825
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
826 case PPP_EVENT_Open:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
827 *State = PPP_STATE_Starting;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
828 This_Layer_Started(Layer);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
829 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
830
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
831 case PPP_EVENT_Close:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
832 *State = PPP_STATE_Initial;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
833 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
834
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
835 case PPP_EVENT_TOPlus:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
836 case PPP_EVENT_TOMinus:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
837 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
838
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
839 default:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
840 Debug_Print("Illegal Event\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
841 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
842 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
843 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
844
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
845 case PPP_STATE_Starting:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
846
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
847 switch (Event)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
848 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
849 case PPP_EVENT_Up:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
850 *State = PPP_STATE_Req_Sent;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
851 RestartCount = MAX_RESTARTS;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
852 LinkTimer = 0;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
853 TimerOn = true;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
854 Send_Configure_Request();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
855 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
856
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
857 case PPP_EVENT_Open:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
858 *State = PPP_STATE_Starting;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
859 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
860
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
861 case PPP_EVENT_Close:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
862 *State = PPP_STATE_Initial;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
863 This_Layer_Finished(Layer);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
864 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
865
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
866 case PPP_EVENT_TOPlus:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
867 case PPP_EVENT_TOMinus:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
868 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
869
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
870 default:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
871 Debug_Print("Illegal Event\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
872 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
873 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
874 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
875
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
876 case PPP_STATE_Closed:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
877
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
878 switch (Event)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
879 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
880 case PPP_EVENT_Down:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
881 *State = PPP_STATE_Initial;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
882 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
883
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
884 case PPP_EVENT_Open:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
885 *State = PPP_STATE_Req_Sent;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
886 RestartCount = MAX_RESTARTS;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
887 LinkTimer = 0;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
888 TimerOn = true;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
889 Send_Configure_Request();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
890 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
891
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
892 case PPP_EVENT_Close:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
893 case PPP_EVENT_RTA:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
894 case PPP_EVENT_RXJPlus:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
895 case PPP_EVENT_RXR:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
896 *State = PPP_STATE_Closed;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
897 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
898
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
899 case PPP_EVENT_RCRPlus:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
900 case PPP_EVENT_RCRMinus:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
901 case PPP_EVENT_RCA:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
902 case PPP_EVENT_RCN:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
903 *State = PPP_STATE_Closed;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
904 Send_Terminate_Ack();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
905 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
906
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
907 case PPP_EVENT_TOPlus:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
908 case PPP_EVENT_TOMinus:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
909 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
910
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
911 default:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
912 Debug_Print("Illegal Event\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
913 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
914 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
915 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
916
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
917 case PPP_STATE_Stopped:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
918
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
919 switch (Event)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
920 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
921 case PPP_EVENT_Down:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
922 *State = PPP_STATE_Starting;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
923 This_Layer_Started(Layer);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
924 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
925
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
926 case PPP_EVENT_Open:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
927 *State = PPP_STATE_Stopped;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
928 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
929
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
930 case PPP_EVENT_Close:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
931 *State = PPP_STATE_Closed;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
932 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
933
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
934 case PPP_EVENT_RCRPlus:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
935 *State = PPP_STATE_Ack_Sent;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
936 RestartCount = MAX_RESTARTS;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
937 LinkTimer = 0;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
938 TimerOn = true;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
939 Send_Configure_Request();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
940 Send_Configure_Ack();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
941 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
942
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
943 case PPP_EVENT_RCRMinus:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
944 *State = PPP_STATE_Req_Sent;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
945 RestartCount = MAX_RESTARTS;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
946 LinkTimer = 0;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
947 TimerOn = true;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
948 Send_Configure_Request();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
949 Send_Configure_Nak_Rej();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
950 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
951
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
952 case PPP_EVENT_RCA:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
953 case PPP_EVENT_RCN:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
954 case PPP_EVENT_RTR:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
955 *State = PPP_STATE_Stopped;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
956 Send_Terminate_Ack();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
957 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
958
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
959 case PPP_EVENT_RTA:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
960 case PPP_EVENT_RXJPlus:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
961 case PPP_EVENT_RXR:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
962 *State = PPP_STATE_Stopped;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
963 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
964
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
965 case PPP_EVENT_RUC:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
966 *State = PPP_STATE_Stopped;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
967 Send_Code_Reject();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
968 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
969
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
970 case PPP_EVENT_RXJMinus:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
971 *State = PPP_STATE_Stopped;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
972 This_Layer_Finished(Layer);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
973 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
974
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
975 case PPP_EVENT_TOPlus:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
976 case PPP_EVENT_TOMinus:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
977 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
978
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
979 default:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
980 Debug_Print("Illegal Event\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
981 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
982 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
983 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
984
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
985 case PPP_STATE_Closing:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
986
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
987 switch (Event)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
988 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
989 case PPP_EVENT_Down:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
990 TimerOn = false;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
991 *State = PPP_STATE_Initial;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
992 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
993
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
994 case PPP_EVENT_Open:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
995 *State = PPP_STATE_Stopping;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
996 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
997
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
998 case PPP_EVENT_Close:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
999 *State = PPP_STATE_Closing;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1000 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1001
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1002 case PPP_EVENT_TOPlus:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1003 Send_Terminate_Request();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1004 *State = PPP_STATE_Closing;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1005 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1006
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1007 case PPP_EVENT_TOMinus:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1008 *State = PPP_STATE_Closed;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1009 TimerOn = false;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1010 This_Layer_Finished(Layer);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1011 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1012
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1013 case PPP_EVENT_RCRPlus:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1014 case PPP_EVENT_RCRMinus:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1015 case PPP_EVENT_RCA:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1016 case PPP_EVENT_RCN:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1017 case PPP_EVENT_RXJPlus:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1018 case PPP_EVENT_RXR:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1019 *State = PPP_STATE_Closing;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1020 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1021
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1022 case PPP_EVENT_RTR:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1023 *State = PPP_STATE_Closing;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1024 Send_Terminate_Ack();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1025 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1026
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1027 case PPP_EVENT_RTA:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1028 case PPP_EVENT_RXJMinus:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1029 *State = PPP_STATE_Closed;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1030 TimerOn = false;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1031 This_Layer_Finished(Layer);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1032 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1033
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1034 case PPP_EVENT_RUC:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1035 *State = PPP_STATE_Closing;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1036 Send_Code_Reject();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1037 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1038
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1039 default:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1040 Debug_Print("Illegal Event\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1041 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1042 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1043 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1044
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1045 case PPP_STATE_Stopping:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1046
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1047 switch (Event)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1048 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1049 case PPP_EVENT_Down:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1050 *State = PPP_STATE_Starting;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1051 TimerOn = false;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1052 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1053
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1054 case PPP_EVENT_Open:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1055 *State = PPP_STATE_Stopping;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1056 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1057
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1058 case PPP_EVENT_Close:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1059 *State = PPP_STATE_Closing;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1060 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1061
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1062 case PPP_EVENT_TOPlus:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1063 Send_Terminate_Request();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1064 *State = PPP_STATE_Stopping;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1065 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1066
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1067 case PPP_EVENT_TOMinus:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1068 This_Layer_Finished(Layer);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1069 TimerOn = false;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1070 *State = PPP_STATE_Stopped;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1071 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1072
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1073 case PPP_EVENT_RCRPlus:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1074 case PPP_EVENT_RCRMinus:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1075 case PPP_EVENT_RCA:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1076 case PPP_EVENT_RCN:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1077 case PPP_EVENT_RXJPlus:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1078 case PPP_EVENT_RXR:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1079 *State = PPP_STATE_Stopping;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1080 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1081
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1082 case PPP_EVENT_RTR:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1083 Send_Terminate_Ack();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1084 *State = PPP_STATE_Stopping;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1085 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1086
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1087 case PPP_EVENT_RTA:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1088 case PPP_EVENT_RXJMinus:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1089 This_Layer_Finished(Layer);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1090 TimerOn = false;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1091 *State = PPP_STATE_Stopped;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1092 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1093
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1094 case PPP_EVENT_RUC:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1095 Send_Code_Reject();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1096 *State = PPP_STATE_Stopping;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1097 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1098
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1099 default:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1100 Debug_Print("Illegal Event\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1101 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1102 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1103 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1104
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1105 case PPP_STATE_Req_Sent:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1106
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1107 switch (Event)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1108 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1109 case PPP_EVENT_Down:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1110 *State = PPP_STATE_Starting;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1111 TimerOn = false;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1112 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1113
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1114 case PPP_EVENT_Open:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1115 case PPP_EVENT_RTA:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1116 case PPP_EVENT_RXJPlus:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1117 case PPP_EVENT_RXR:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1118 *State = PPP_STATE_Req_Sent;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1119 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1120
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1121 case PPP_EVENT_Close:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1122 RestartCount = MAX_RESTARTS;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1123 LinkTimer = 0;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1124 Send_Terminate_Request();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1125 *State = PPP_STATE_Closing;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1126 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1127
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1128 case PPP_EVENT_TOPlus:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1129 Send_Configure_Request();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1130 *State = PPP_STATE_Req_Sent;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1131 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1132
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1133 case PPP_EVENT_TOMinus:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1134 This_Layer_Finished(Layer);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1135 TimerOn = false;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1136 *State = PPP_STATE_Stopped;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1137 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1138
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1139 case PPP_EVENT_RCRPlus:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1140 if (Layer != PPP_LAYER_Authentication) // We faked a Configure request for PAP. So no need to answer it if we're in the authentication phase
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1141 Send_Configure_Ack();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1142
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1143 *State = PPP_STATE_Ack_Sent;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1144 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1145
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1146 case PPP_EVENT_RCRMinus:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1147 Send_Configure_Nak_Rej();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1148 *State = PPP_STATE_Req_Sent;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1149 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1150
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1151 case PPP_EVENT_RCA:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1152 RestartCount = MAX_RESTARTS;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1153 LinkTimer = 0;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1154 *State = PPP_STATE_Ack_Rcvd;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1155 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1156
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1157 case PPP_EVENT_RCN:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1158 RestartCount = MAX_RESTARTS;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1159 LinkTimer = 0;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1160 Send_Configure_Request();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1161 *State = PPP_STATE_Req_Sent;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1162 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1163
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1164 case PPP_EVENT_RTR:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1165 Send_Terminate_Ack();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1166 *State = PPP_STATE_Req_Sent;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1167 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1168
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1169 case PPP_EVENT_RUC:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1170 Send_Code_Reject();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1171 *State = PPP_STATE_Req_Sent;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1172 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1173
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1174 case PPP_EVENT_RXJMinus:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1175 This_Layer_Finished(Layer);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1176 TimerOn = false;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1177 *State = PPP_STATE_Stopped;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1178 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1179
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1180 default:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1181 Debug_Print("Illegal Event\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1182 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1183 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1184 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1185
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1186 case PPP_STATE_Ack_Rcvd:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1187
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1188 switch (Event)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1189 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1190 case PPP_EVENT_Down:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1191 *State = PPP_STATE_Starting;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1192 TimerOn = false;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1193 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1194
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1195 case PPP_EVENT_Open:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1196 case PPP_EVENT_RXR:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1197 *State = PPP_STATE_Ack_Rcvd;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1198 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1199
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1200 case PPP_EVENT_Close:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1201 RestartCount = MAX_RESTARTS;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1202 LinkTimer = 0;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1203 Send_Terminate_Request();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1204 *State = PPP_STATE_Closing;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1205 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1206
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1207 case PPP_EVENT_TOPlus:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1208 case PPP_EVENT_RCA:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1209 case PPP_EVENT_RCN:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1210 Send_Configure_Request();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1211 *State = PPP_STATE_Req_Sent;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1212 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1213
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1214 case PPP_EVENT_TOMinus:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1215 This_Layer_Finished(Layer);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1216 TimerOn = false;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1217 *State = PPP_STATE_Stopped;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1218 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1219
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1220 case PPP_EVENT_RCRPlus:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1221 Send_Configure_Ack();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1222 This_Layer_Up(Layer);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1223 TimerOn = false;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1224 *State = PPP_STATE_Opened;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1225 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1226
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1227 case PPP_EVENT_RCRMinus:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1228 Send_Configure_Nak_Rej();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1229 *State = PPP_STATE_Ack_Rcvd;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1230 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1231
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1232 case PPP_EVENT_RTR:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1233 Send_Terminate_Ack();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1234 *State = PPP_STATE_Req_Sent;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1235 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1236
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1237 case PPP_EVENT_RTA:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1238 case PPP_EVENT_RXJPlus:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1239 Send_Terminate_Ack();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1240 *State = PPP_STATE_Req_Sent;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1241 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1242
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1243 case PPP_EVENT_RUC:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1244 Send_Code_Reject();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1245 *State = PPP_STATE_Ack_Rcvd;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1246 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1247
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1248 case PPP_EVENT_RXJMinus:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1249 This_Layer_Finished(Layer);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1250 TimerOn = false;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1251 *State = PPP_STATE_Stopped;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1252 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1253
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1254 default:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1255 Debug_Print("Illegal Event\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1256 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1257 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1258 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1259
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1260 case PPP_STATE_Ack_Sent:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1261
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1262 switch (Event)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1263 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1264 case PPP_EVENT_Down:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1265 *State = PPP_STATE_Starting;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1266 TimerOn = false;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1267 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1268
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1269 case PPP_EVENT_Open:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1270 case PPP_EVENT_RTA:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1271 case PPP_EVENT_RXJPlus:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1272 case PPP_EVENT_RXR:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1273 *State = PPP_STATE_Ack_Sent;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1274 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1275
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1276 case PPP_EVENT_Close:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1277 RestartCount = MAX_RESTARTS;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1278 LinkTimer = 0;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1279 Send_Terminate_Request();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1280 *State = PPP_STATE_Closing;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1281 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1282
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1283 case PPP_EVENT_TOPlus:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1284 Send_Configure_Request();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1285 *State = PPP_STATE_Ack_Sent;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1286 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1287
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1288 case PPP_EVENT_TOMinus:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1289 This_Layer_Finished(Layer);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1290 TimerOn = false;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1291 *State = PPP_STATE_Stopped;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1292 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1293
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1294 case PPP_EVENT_RCRPlus:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1295 Send_Configure_Ack();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1296 *State = PPP_STATE_Ack_Sent;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1297 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1298
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1299 case PPP_EVENT_RCRMinus:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1300 Send_Configure_Nak_Rej();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1301 *State = PPP_STATE_Req_Sent;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1302 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1303
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1304 case PPP_EVENT_RCA:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1305 RestartCount = MAX_RESTARTS;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1306 LinkTimer = 0;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1307 TimerOn = false;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1308 This_Layer_Up(Layer);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1309 *State = PPP_STATE_Opened;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1310 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1311
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1312 case PPP_EVENT_RCN:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1313 RestartCount = MAX_RESTARTS;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1314 LinkTimer = 0;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1315 Send_Configure_Request();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1316 *State = PPP_STATE_Ack_Sent;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1317 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1318
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1319 case PPP_EVENT_RTR:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1320 Send_Terminate_Ack();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1321 *State = PPP_STATE_Req_Sent;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1322 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1323
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1324 case PPP_EVENT_RUC:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1325 Send_Code_Reject();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1326 *State = PPP_STATE_Ack_Sent;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1327 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1328
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1329 case PPP_EVENT_RXJMinus:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1330 This_Layer_Finished(Layer);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1331 TimerOn = false;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1332 *State = PPP_STATE_Stopped;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1333 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1334
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1335 default:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1336 Debug_Print("Illegal Event\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1337 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1338 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1339 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1340
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1341 case PPP_STATE_Opened:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1342
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1343 switch (Event)
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1344 {
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1345 case PPP_EVENT_Down:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1346 This_Layer_Down(Layer);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1347 *State = PPP_STATE_Starting;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1348 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1349
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1350 case PPP_EVENT_Open:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1351 case PPP_EVENT_RXJPlus:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1352 *State = PPP_STATE_Opened;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1353 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1354
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1355 case PPP_EVENT_Close:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1356 This_Layer_Down(Layer);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1357 RestartCount = MAX_RESTARTS;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1358 LinkTimer = 0;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1359 TimerOn = true;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1360 Send_Terminate_Request();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1361 *State = PPP_STATE_Closing;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1362 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1363
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1364 case PPP_EVENT_RCRPlus:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1365 This_Layer_Down(Layer);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1366 TimerOn = true;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1367 Send_Configure_Request();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1368 Send_Configure_Ack();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1369 *State = PPP_STATE_Ack_Sent;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1370 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1371
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1372 case PPP_EVENT_RCRMinus:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1373 This_Layer_Down(Layer);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1374 TimerOn = true;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1375 Send_Configure_Request();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1376 Send_Configure_Nak_Rej();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1377 *State = PPP_STATE_Req_Sent;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1378 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1379
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1380 case PPP_EVENT_RCA:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1381 case PPP_EVENT_RCN:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1382 case PPP_EVENT_RTA:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1383 This_Layer_Down(Layer);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1384 TimerOn = true;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1385 Send_Configure_Request();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1386 *State = PPP_STATE_Req_Sent;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1387 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1388
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1389 case PPP_EVENT_RTR:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1390 This_Layer_Down(Layer);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1391 RestartCount = 0;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1392 LinkTimer = 0;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1393 TimerOn = true;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1394 Send_Terminate_Ack();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1395 *State = PPP_STATE_Stopping;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1396 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1397
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1398 case PPP_EVENT_RUC:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1399 Send_Code_Reject();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1400 *State = PPP_STATE_Opened;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1401 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1402
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1403 case PPP_EVENT_RXJMinus:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1404 This_Layer_Down(Layer);
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1405 RestartCount = MAX_RESTARTS;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1406 LinkTimer = 0;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1407 TimerOn = true;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1408 Send_Terminate_Request();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1409 *State = PPP_STATE_Stopping;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1410 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1411
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1412 case PPP_EVENT_RXR:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1413 Send_Echo_Reply();
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1414 *State = PPP_STATE_Opened;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1415 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1416
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1417 default:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1418 Debug_Print("Illegal Event\r\n");
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1419 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1420 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1421 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1422
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1423 default:
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1424 break;
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1425 }
56d09a0969b5 Import uIP and the PPP implementation from
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1426 }