Webserver+3d print

Dependents:   Nucleo

Committer:
Sergunb
Date:
Sat Feb 04 18:15:49 2017 +0000
Revision:
0:8918a71cdbe9
nothing else

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Sergunb 0:8918a71cdbe9 1 /**
Sergunb 0:8918a71cdbe9 2 * @file ppp_fsm.c
Sergunb 0:8918a71cdbe9 3 * @brief PPP finite state machine
Sergunb 0:8918a71cdbe9 4 *
Sergunb 0:8918a71cdbe9 5 * @section License
Sergunb 0:8918a71cdbe9 6 *
Sergunb 0:8918a71cdbe9 7 * Copyright (C) 2010-2017 Oryx Embedded SARL. All rights reserved.
Sergunb 0:8918a71cdbe9 8 *
Sergunb 0:8918a71cdbe9 9 * This file is part of CycloneTCP Open.
Sergunb 0:8918a71cdbe9 10 *
Sergunb 0:8918a71cdbe9 11 * This program is free software; you can redistribute it and/or
Sergunb 0:8918a71cdbe9 12 * modify it under the terms of the GNU General Public License
Sergunb 0:8918a71cdbe9 13 * as published by the Free Software Foundation; either version 2
Sergunb 0:8918a71cdbe9 14 * of the License, or (at your option) any later version.
Sergunb 0:8918a71cdbe9 15 *
Sergunb 0:8918a71cdbe9 16 * This program is distributed in the hope that it will be useful,
Sergunb 0:8918a71cdbe9 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Sergunb 0:8918a71cdbe9 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Sergunb 0:8918a71cdbe9 19 * GNU General Public License for more details.
Sergunb 0:8918a71cdbe9 20 *
Sergunb 0:8918a71cdbe9 21 * You should have received a copy of the GNU General Public License
Sergunb 0:8918a71cdbe9 22 * along with this program; if not, write to the Free Software Foundation,
Sergunb 0:8918a71cdbe9 23 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Sergunb 0:8918a71cdbe9 24 *
Sergunb 0:8918a71cdbe9 25 * @author Oryx Embedded SARL (www.oryx-embedded.com)
Sergunb 0:8918a71cdbe9 26 * @version 1.7.6
Sergunb 0:8918a71cdbe9 27 **/
Sergunb 0:8918a71cdbe9 28
Sergunb 0:8918a71cdbe9 29 //Switch to the appropriate trace level
Sergunb 0:8918a71cdbe9 30 #define TRACE_LEVEL PPP_TRACE_LEVEL
Sergunb 0:8918a71cdbe9 31
Sergunb 0:8918a71cdbe9 32 //Dependencies
Sergunb 0:8918a71cdbe9 33 #include "core/net.h"
Sergunb 0:8918a71cdbe9 34 #include "ppp/ppp_fsm.h"
Sergunb 0:8918a71cdbe9 35 #include "debug.h"
Sergunb 0:8918a71cdbe9 36
Sergunb 0:8918a71cdbe9 37 //Check TCP/IP stack configuration
Sergunb 0:8918a71cdbe9 38 #if (PPP_SUPPORT == ENABLED)
Sergunb 0:8918a71cdbe9 39
Sergunb 0:8918a71cdbe9 40
Sergunb 0:8918a71cdbe9 41 /**
Sergunb 0:8918a71cdbe9 42 * @brief Process Up event
Sergunb 0:8918a71cdbe9 43 * @param[in] context PPP context
Sergunb 0:8918a71cdbe9 44 * @param[in,out] fsm Finite state machine
Sergunb 0:8918a71cdbe9 45 * @param[in] callbacks FSM actions
Sergunb 0:8918a71cdbe9 46 **/
Sergunb 0:8918a71cdbe9 47
Sergunb 0:8918a71cdbe9 48 void pppUpEvent(PppContext *context, PppFsm *fsm,
Sergunb 0:8918a71cdbe9 49 const PppCallbacks *callbacks)
Sergunb 0:8918a71cdbe9 50 {
Sergunb 0:8918a71cdbe9 51 //Check current state
Sergunb 0:8918a71cdbe9 52 switch(fsm->state)
Sergunb 0:8918a71cdbe9 53 {
Sergunb 0:8918a71cdbe9 54 case PPP_STATE_0_INITIAL:
Sergunb 0:8918a71cdbe9 55 //Switch to the Closed state
Sergunb 0:8918a71cdbe9 56 pppChangeState(fsm, PPP_STATE_2_CLOSED);
Sergunb 0:8918a71cdbe9 57 break;
Sergunb 0:8918a71cdbe9 58 case PPP_STATE_1_STARTING:
Sergunb 0:8918a71cdbe9 59 //Initialize restart counter
Sergunb 0:8918a71cdbe9 60 callbacks->initRestartCount(context, PPP_MAX_CONFIGURE);
Sergunb 0:8918a71cdbe9 61 //Send Configure-Request packet
Sergunb 0:8918a71cdbe9 62 callbacks->sendConfigureReq(context);
Sergunb 0:8918a71cdbe9 63 //Switch to the Req-Sent state
Sergunb 0:8918a71cdbe9 64 pppChangeState(fsm, PPP_STATE_6_REQ_SENT);
Sergunb 0:8918a71cdbe9 65 break;
Sergunb 0:8918a71cdbe9 66 default:
Sergunb 0:8918a71cdbe9 67 //This event cannot occur in a properly implemented automaton.
Sergunb 0:8918a71cdbe9 68 //No transition is taken, and the implementation should not
Sergunb 0:8918a71cdbe9 69 //reset or freeze
Sergunb 0:8918a71cdbe9 70 break;
Sergunb 0:8918a71cdbe9 71 }
Sergunb 0:8918a71cdbe9 72 }
Sergunb 0:8918a71cdbe9 73
Sergunb 0:8918a71cdbe9 74
Sergunb 0:8918a71cdbe9 75 /**
Sergunb 0:8918a71cdbe9 76 * @brief Process Down event
Sergunb 0:8918a71cdbe9 77 * @param[in] context PPP context
Sergunb 0:8918a71cdbe9 78 * @param[in,out] fsm Finite state machine
Sergunb 0:8918a71cdbe9 79 * @param[in] callbacks FSM actions
Sergunb 0:8918a71cdbe9 80 **/
Sergunb 0:8918a71cdbe9 81
Sergunb 0:8918a71cdbe9 82 void pppDownEvent(PppContext *context, PppFsm *fsm,
Sergunb 0:8918a71cdbe9 83 const PppCallbacks *callbacks)
Sergunb 0:8918a71cdbe9 84 {
Sergunb 0:8918a71cdbe9 85 //Check current state
Sergunb 0:8918a71cdbe9 86 switch(fsm->state)
Sergunb 0:8918a71cdbe9 87 {
Sergunb 0:8918a71cdbe9 88 case PPP_STATE_2_CLOSED:
Sergunb 0:8918a71cdbe9 89 //Switch to the Initial state
Sergunb 0:8918a71cdbe9 90 pppChangeState(fsm, PPP_STATE_0_INITIAL);
Sergunb 0:8918a71cdbe9 91 break;
Sergunb 0:8918a71cdbe9 92 case PPP_STATE_3_STOPPED:
Sergunb 0:8918a71cdbe9 93 //Switch to the Starting state
Sergunb 0:8918a71cdbe9 94 pppChangeState(fsm, PPP_STATE_1_STARTING);
Sergunb 0:8918a71cdbe9 95 //Indicate to the lower layers that the automaton is entering the
Sergunb 0:8918a71cdbe9 96 //Starting state. The lower layer is needed for the link
Sergunb 0:8918a71cdbe9 97 callbacks->thisLayerStarted(context);
Sergunb 0:8918a71cdbe9 98 break;
Sergunb 0:8918a71cdbe9 99 case PPP_STATE_4_CLOSING:
Sergunb 0:8918a71cdbe9 100 //Switch to the Initial state
Sergunb 0:8918a71cdbe9 101 pppChangeState(fsm, PPP_STATE_0_INITIAL);
Sergunb 0:8918a71cdbe9 102 break;
Sergunb 0:8918a71cdbe9 103 case PPP_STATE_5_STOPPING:
Sergunb 0:8918a71cdbe9 104 case PPP_STATE_6_REQ_SENT:
Sergunb 0:8918a71cdbe9 105 case PPP_STATE_7_ACK_RCVD:
Sergunb 0:8918a71cdbe9 106 case PPP_STATE_8_ACK_SENT:
Sergunb 0:8918a71cdbe9 107 //Switch to the Starting state
Sergunb 0:8918a71cdbe9 108 pppChangeState(fsm, PPP_STATE_1_STARTING);
Sergunb 0:8918a71cdbe9 109 break;
Sergunb 0:8918a71cdbe9 110 case PPP_STATE_9_OPENED:
Sergunb 0:8918a71cdbe9 111 //Switch to the Starting state
Sergunb 0:8918a71cdbe9 112 pppChangeState(fsm, PPP_STATE_1_STARTING);
Sergunb 0:8918a71cdbe9 113 //Indicate to the upper layers that the automaton is leaving the Opened
Sergunb 0:8918a71cdbe9 114 //state. The link is no longer available for network traffic
Sergunb 0:8918a71cdbe9 115 callbacks->thisLayerDown(context);
Sergunb 0:8918a71cdbe9 116 break;
Sergunb 0:8918a71cdbe9 117 default:
Sergunb 0:8918a71cdbe9 118 //This event cannot occur in a properly implemented automaton.
Sergunb 0:8918a71cdbe9 119 //No transition is taken, and the implementation should not
Sergunb 0:8918a71cdbe9 120 //reset or freeze
Sergunb 0:8918a71cdbe9 121 break;
Sergunb 0:8918a71cdbe9 122 }
Sergunb 0:8918a71cdbe9 123 }
Sergunb 0:8918a71cdbe9 124
Sergunb 0:8918a71cdbe9 125
Sergunb 0:8918a71cdbe9 126 /**
Sergunb 0:8918a71cdbe9 127 * @brief Process Open event
Sergunb 0:8918a71cdbe9 128 * @param[in] context PPP context
Sergunb 0:8918a71cdbe9 129 * @param[in,out] fsm Finite state machine
Sergunb 0:8918a71cdbe9 130 * @param[in] callbacks FSM actions
Sergunb 0:8918a71cdbe9 131 **/
Sergunb 0:8918a71cdbe9 132
Sergunb 0:8918a71cdbe9 133 void pppOpenEvent(PppContext *context, PppFsm *fsm,
Sergunb 0:8918a71cdbe9 134 const PppCallbacks *callbacks)
Sergunb 0:8918a71cdbe9 135 {
Sergunb 0:8918a71cdbe9 136 //Check current state
Sergunb 0:8918a71cdbe9 137 switch(fsm->state)
Sergunb 0:8918a71cdbe9 138 {
Sergunb 0:8918a71cdbe9 139 case PPP_STATE_0_INITIAL:
Sergunb 0:8918a71cdbe9 140 //Switch to the Starting state
Sergunb 0:8918a71cdbe9 141 pppChangeState(fsm, PPP_STATE_1_STARTING);
Sergunb 0:8918a71cdbe9 142 //Indicate to the lower layers that the automaton is entering the
Sergunb 0:8918a71cdbe9 143 //Starting state. The lower layer is needed for the link
Sergunb 0:8918a71cdbe9 144 callbacks->thisLayerStarted(context);
Sergunb 0:8918a71cdbe9 145 break;
Sergunb 0:8918a71cdbe9 146 case PPP_STATE_1_STARTING:
Sergunb 0:8918a71cdbe9 147 //Stay in current state
Sergunb 0:8918a71cdbe9 148 break;
Sergunb 0:8918a71cdbe9 149 case PPP_STATE_2_CLOSED:
Sergunb 0:8918a71cdbe9 150 //Initialize restart counter
Sergunb 0:8918a71cdbe9 151 callbacks->initRestartCount(context, PPP_MAX_CONFIGURE);
Sergunb 0:8918a71cdbe9 152 //Send Configure-Request packet
Sergunb 0:8918a71cdbe9 153 callbacks->sendConfigureReq(context);
Sergunb 0:8918a71cdbe9 154 //Switch to the Req-Sent state
Sergunb 0:8918a71cdbe9 155 pppChangeState(fsm, PPP_STATE_6_REQ_SENT);
Sergunb 0:8918a71cdbe9 156 break;
Sergunb 0:8918a71cdbe9 157 case PPP_STATE_3_STOPPED:
Sergunb 0:8918a71cdbe9 158 //Stay in current state
Sergunb 0:8918a71cdbe9 159 break;
Sergunb 0:8918a71cdbe9 160 case PPP_STATE_4_CLOSING:
Sergunb 0:8918a71cdbe9 161 //Switch to the Stopping state
Sergunb 0:8918a71cdbe9 162 pppChangeState(fsm, PPP_STATE_5_STOPPING);
Sergunb 0:8918a71cdbe9 163 break;
Sergunb 0:8918a71cdbe9 164 case PPP_STATE_5_STOPPING:
Sergunb 0:8918a71cdbe9 165 case PPP_STATE_6_REQ_SENT:
Sergunb 0:8918a71cdbe9 166 case PPP_STATE_7_ACK_RCVD:
Sergunb 0:8918a71cdbe9 167 case PPP_STATE_8_ACK_SENT:
Sergunb 0:8918a71cdbe9 168 case PPP_STATE_9_OPENED:
Sergunb 0:8918a71cdbe9 169 //Stay in current state
Sergunb 0:8918a71cdbe9 170 break;
Sergunb 0:8918a71cdbe9 171 default:
Sergunb 0:8918a71cdbe9 172 //This event cannot occur in a properly implemented automaton.
Sergunb 0:8918a71cdbe9 173 //No transition is taken, and the implementation should not
Sergunb 0:8918a71cdbe9 174 //reset or freeze
Sergunb 0:8918a71cdbe9 175 break;
Sergunb 0:8918a71cdbe9 176 }
Sergunb 0:8918a71cdbe9 177 }
Sergunb 0:8918a71cdbe9 178
Sergunb 0:8918a71cdbe9 179
Sergunb 0:8918a71cdbe9 180 /**
Sergunb 0:8918a71cdbe9 181 * @brief Process Close event
Sergunb 0:8918a71cdbe9 182 * @param[in] context PPP context
Sergunb 0:8918a71cdbe9 183 * @param[in,out] fsm Finite state machine
Sergunb 0:8918a71cdbe9 184 * @param[in] callbacks FSM actions
Sergunb 0:8918a71cdbe9 185 **/
Sergunb 0:8918a71cdbe9 186
Sergunb 0:8918a71cdbe9 187 void pppCloseEvent(PppContext *context, PppFsm *fsm,
Sergunb 0:8918a71cdbe9 188 const PppCallbacks *callbacks)
Sergunb 0:8918a71cdbe9 189 {
Sergunb 0:8918a71cdbe9 190 //Check current state
Sergunb 0:8918a71cdbe9 191 switch(fsm->state)
Sergunb 0:8918a71cdbe9 192 {
Sergunb 0:8918a71cdbe9 193 case PPP_STATE_0_INITIAL:
Sergunb 0:8918a71cdbe9 194 //Stay in current state
Sergunb 0:8918a71cdbe9 195 break;
Sergunb 0:8918a71cdbe9 196 case PPP_STATE_1_STARTING:
Sergunb 0:8918a71cdbe9 197 //Switch to the Initial state
Sergunb 0:8918a71cdbe9 198 pppChangeState(fsm, PPP_STATE_0_INITIAL);
Sergunb 0:8918a71cdbe9 199 //Indicate to the lower layers that the automaton is entering the
Sergunb 0:8918a71cdbe9 200 //Initial, Closed or Stopped states. The lower layer is no longer
Sergunb 0:8918a71cdbe9 201 //needed for the link
Sergunb 0:8918a71cdbe9 202 callbacks->thisLayerFinished(context);
Sergunb 0:8918a71cdbe9 203 break;
Sergunb 0:8918a71cdbe9 204 case PPP_STATE_2_CLOSED:
Sergunb 0:8918a71cdbe9 205 //Stay in current state
Sergunb 0:8918a71cdbe9 206 break;
Sergunb 0:8918a71cdbe9 207 case PPP_STATE_3_STOPPED:
Sergunb 0:8918a71cdbe9 208 //Switch to the Closed state
Sergunb 0:8918a71cdbe9 209 pppChangeState(fsm, PPP_STATE_2_CLOSED);
Sergunb 0:8918a71cdbe9 210 break;
Sergunb 0:8918a71cdbe9 211 case PPP_STATE_4_CLOSING:
Sergunb 0:8918a71cdbe9 212 //Stay in current state
Sergunb 0:8918a71cdbe9 213 break;
Sergunb 0:8918a71cdbe9 214 case PPP_STATE_5_STOPPING:
Sergunb 0:8918a71cdbe9 215 //Switch to the Closing state
Sergunb 0:8918a71cdbe9 216 pppChangeState(fsm, PPP_STATE_4_CLOSING);
Sergunb 0:8918a71cdbe9 217 break;
Sergunb 0:8918a71cdbe9 218 case PPP_STATE_6_REQ_SENT:
Sergunb 0:8918a71cdbe9 219 case PPP_STATE_7_ACK_RCVD:
Sergunb 0:8918a71cdbe9 220 case PPP_STATE_8_ACK_SENT:
Sergunb 0:8918a71cdbe9 221 //Initialize restart counter
Sergunb 0:8918a71cdbe9 222 callbacks->initRestartCount(context, PPP_MAX_TERMINATE);
Sergunb 0:8918a71cdbe9 223 //Send Terminate-Request packet
Sergunb 0:8918a71cdbe9 224 callbacks->sendTerminateReq(context);
Sergunb 0:8918a71cdbe9 225 //Switch to the Closing state
Sergunb 0:8918a71cdbe9 226 pppChangeState(fsm, PPP_STATE_4_CLOSING);
Sergunb 0:8918a71cdbe9 227 break;
Sergunb 0:8918a71cdbe9 228 case PPP_STATE_9_OPENED:
Sergunb 0:8918a71cdbe9 229 //Initialize restart counter
Sergunb 0:8918a71cdbe9 230 callbacks->initRestartCount(context, PPP_MAX_TERMINATE);
Sergunb 0:8918a71cdbe9 231 //Send Terminate-Request packet
Sergunb 0:8918a71cdbe9 232 callbacks->sendTerminateReq(context);
Sergunb 0:8918a71cdbe9 233 //Switch to the Closing state
Sergunb 0:8918a71cdbe9 234 pppChangeState(fsm, PPP_STATE_4_CLOSING);
Sergunb 0:8918a71cdbe9 235 //Indicate to the upper layers that the automaton is leaving the Opened
Sergunb 0:8918a71cdbe9 236 //state. The link is no longer available for network traffic
Sergunb 0:8918a71cdbe9 237 callbacks->thisLayerDown(context);
Sergunb 0:8918a71cdbe9 238 break;
Sergunb 0:8918a71cdbe9 239 default:
Sergunb 0:8918a71cdbe9 240 //This event cannot occur in a properly implemented automaton.
Sergunb 0:8918a71cdbe9 241 //No transition is taken, and the implementation should not
Sergunb 0:8918a71cdbe9 242 //reset or freeze
Sergunb 0:8918a71cdbe9 243 break;
Sergunb 0:8918a71cdbe9 244 }
Sergunb 0:8918a71cdbe9 245 }
Sergunb 0:8918a71cdbe9 246
Sergunb 0:8918a71cdbe9 247
Sergunb 0:8918a71cdbe9 248 /**
Sergunb 0:8918a71cdbe9 249 * @brief Process Timeout event
Sergunb 0:8918a71cdbe9 250 * @param[in] context PPP context
Sergunb 0:8918a71cdbe9 251 * @param[in,out] fsm Finite state machine
Sergunb 0:8918a71cdbe9 252 * @param[in] callbacks FSM actions
Sergunb 0:8918a71cdbe9 253 **/
Sergunb 0:8918a71cdbe9 254
Sergunb 0:8918a71cdbe9 255 void pppTimeoutEvent(PppContext *context, PppFsm *fsm,
Sergunb 0:8918a71cdbe9 256 const PppCallbacks *callbacks)
Sergunb 0:8918a71cdbe9 257 {
Sergunb 0:8918a71cdbe9 258 //The restart counter is greater than zero (TO+ event)
Sergunb 0:8918a71cdbe9 259 if(fsm->restartCounter > 0)
Sergunb 0:8918a71cdbe9 260 {
Sergunb 0:8918a71cdbe9 261 //Check current state
Sergunb 0:8918a71cdbe9 262 switch(fsm->state)
Sergunb 0:8918a71cdbe9 263 {
Sergunb 0:8918a71cdbe9 264 case PPP_STATE_4_CLOSING:
Sergunb 0:8918a71cdbe9 265 case PPP_STATE_5_STOPPING:
Sergunb 0:8918a71cdbe9 266 //Send Terminate-Request packet
Sergunb 0:8918a71cdbe9 267 callbacks->sendTerminateReq(context);
Sergunb 0:8918a71cdbe9 268 //Stay in current state
Sergunb 0:8918a71cdbe9 269 break;
Sergunb 0:8918a71cdbe9 270 case PPP_STATE_6_REQ_SENT:
Sergunb 0:8918a71cdbe9 271 case PPP_STATE_7_ACK_RCVD:
Sergunb 0:8918a71cdbe9 272 //Send Configuration-Request packet
Sergunb 0:8918a71cdbe9 273 callbacks->sendConfigureReq(context);
Sergunb 0:8918a71cdbe9 274 //Switch to the Req-Sent state
Sergunb 0:8918a71cdbe9 275 pppChangeState(fsm, PPP_STATE_6_REQ_SENT);
Sergunb 0:8918a71cdbe9 276 break;
Sergunb 0:8918a71cdbe9 277 case PPP_STATE_8_ACK_SENT:
Sergunb 0:8918a71cdbe9 278 //Send Configuration-Request packet
Sergunb 0:8918a71cdbe9 279 callbacks->sendConfigureReq(context);
Sergunb 0:8918a71cdbe9 280 //Stay in current state
Sergunb 0:8918a71cdbe9 281 break;
Sergunb 0:8918a71cdbe9 282 default:
Sergunb 0:8918a71cdbe9 283 //This event cannot occur in a properly implemented automaton.
Sergunb 0:8918a71cdbe9 284 //No transition is taken, and the implementation should not
Sergunb 0:8918a71cdbe9 285 //reset or freeze
Sergunb 0:8918a71cdbe9 286 break;
Sergunb 0:8918a71cdbe9 287 }
Sergunb 0:8918a71cdbe9 288 }
Sergunb 0:8918a71cdbe9 289 //The restart counter is not greater than zero (TO- event)
Sergunb 0:8918a71cdbe9 290 else
Sergunb 0:8918a71cdbe9 291 {
Sergunb 0:8918a71cdbe9 292 //Check current state
Sergunb 0:8918a71cdbe9 293 switch(fsm->state)
Sergunb 0:8918a71cdbe9 294 {
Sergunb 0:8918a71cdbe9 295 case PPP_STATE_4_CLOSING:
Sergunb 0:8918a71cdbe9 296 //Switch to the Closed state
Sergunb 0:8918a71cdbe9 297 pppChangeState(fsm, PPP_STATE_2_CLOSED);
Sergunb 0:8918a71cdbe9 298 //Indicate to the lower layers that the automaton is entering the
Sergunb 0:8918a71cdbe9 299 //Initial, Closed or Stopped states. The lower layer is no longer
Sergunb 0:8918a71cdbe9 300 //needed for the link
Sergunb 0:8918a71cdbe9 301 callbacks->thisLayerFinished(context);
Sergunb 0:8918a71cdbe9 302 break;
Sergunb 0:8918a71cdbe9 303 case PPP_STATE_5_STOPPING:
Sergunb 0:8918a71cdbe9 304 case PPP_STATE_6_REQ_SENT:
Sergunb 0:8918a71cdbe9 305 case PPP_STATE_7_ACK_RCVD:
Sergunb 0:8918a71cdbe9 306 case PPP_STATE_8_ACK_SENT:
Sergunb 0:8918a71cdbe9 307 //Switch to the Stopped state
Sergunb 0:8918a71cdbe9 308 pppChangeState(fsm, PPP_STATE_3_STOPPED);
Sergunb 0:8918a71cdbe9 309 //Indicate to the lower layers that the automaton is entering the
Sergunb 0:8918a71cdbe9 310 //Initial, Closed or Stopped states. The lower layer is no longer
Sergunb 0:8918a71cdbe9 311 //needed for the link
Sergunb 0:8918a71cdbe9 312 callbacks->thisLayerFinished(context);
Sergunb 0:8918a71cdbe9 313 break;
Sergunb 0:8918a71cdbe9 314 default:
Sergunb 0:8918a71cdbe9 315 //This event cannot occur in a properly implemented automaton.
Sergunb 0:8918a71cdbe9 316 //No transition is taken, and the implementation should not
Sergunb 0:8918a71cdbe9 317 //reset or freeze
Sergunb 0:8918a71cdbe9 318 break;
Sergunb 0:8918a71cdbe9 319 }
Sergunb 0:8918a71cdbe9 320 }
Sergunb 0:8918a71cdbe9 321 }
Sergunb 0:8918a71cdbe9 322
Sergunb 0:8918a71cdbe9 323
Sergunb 0:8918a71cdbe9 324 /**
Sergunb 0:8918a71cdbe9 325 * @brief Process Receive-Configure-Request event
Sergunb 0:8918a71cdbe9 326 * @param[in] context PPP context
Sergunb 0:8918a71cdbe9 327 * @param[in,out] fsm Finite state machine
Sergunb 0:8918a71cdbe9 328 * @param[in] callbacks FSM actions
Sergunb 0:8918a71cdbe9 329 * @param[in] configureReqPacket Configure-Request packet received from the peer
Sergunb 0:8918a71cdbe9 330 * @param[in] code Tells whether the configuration options are acceptable
Sergunb 0:8918a71cdbe9 331 **/
Sergunb 0:8918a71cdbe9 332
Sergunb 0:8918a71cdbe9 333 void pppRcvConfigureReqEvent(PppContext *context, PppFsm *fsm, const PppCallbacks *callbacks,
Sergunb 0:8918a71cdbe9 334 const PppConfigurePacket *configureReqPacket, PppCode code)
Sergunb 0:8918a71cdbe9 335 {
Sergunb 0:8918a71cdbe9 336 //Check whether the configuration options are acceptable
Sergunb 0:8918a71cdbe9 337 if(code == PPP_CODE_CONFIGURE_ACK)
Sergunb 0:8918a71cdbe9 338 {
Sergunb 0:8918a71cdbe9 339 //If every configuration option received in the Configure-Request is
Sergunb 0:8918a71cdbe9 340 //recognizable and all values are acceptable, then the implementation
Sergunb 0:8918a71cdbe9 341 //must transmit a Configure-Ack
Sergunb 0:8918a71cdbe9 342 switch(fsm->state)
Sergunb 0:8918a71cdbe9 343 {
Sergunb 0:8918a71cdbe9 344 case PPP_STATE_2_CLOSED:
Sergunb 0:8918a71cdbe9 345 //Send Terminate-Ack packet
Sergunb 0:8918a71cdbe9 346 callbacks->sendTerminateAck(context, NULL);
Sergunb 0:8918a71cdbe9 347 //Stay in current state
Sergunb 0:8918a71cdbe9 348 break;
Sergunb 0:8918a71cdbe9 349 case PPP_STATE_3_STOPPED:
Sergunb 0:8918a71cdbe9 350 //Initialize restart counter
Sergunb 0:8918a71cdbe9 351 callbacks->initRestartCount(context, PPP_MAX_CONFIGURE);
Sergunb 0:8918a71cdbe9 352 //Send Configure-Request packet
Sergunb 0:8918a71cdbe9 353 callbacks->sendConfigureReq(context);
Sergunb 0:8918a71cdbe9 354 //Send Configure-Ack packet
Sergunb 0:8918a71cdbe9 355 callbacks->sendConfigureAck(context, configureReqPacket);
Sergunb 0:8918a71cdbe9 356 //Switch to the Ack-Sent state
Sergunb 0:8918a71cdbe9 357 pppChangeState(fsm, PPP_STATE_8_ACK_SENT);
Sergunb 0:8918a71cdbe9 358 break;
Sergunb 0:8918a71cdbe9 359 case PPP_STATE_4_CLOSING:
Sergunb 0:8918a71cdbe9 360 case PPP_STATE_5_STOPPING:
Sergunb 0:8918a71cdbe9 361 //Stay in current state
Sergunb 0:8918a71cdbe9 362 break;
Sergunb 0:8918a71cdbe9 363 case PPP_STATE_6_REQ_SENT:
Sergunb 0:8918a71cdbe9 364 //Send Configure-Ack packet
Sergunb 0:8918a71cdbe9 365 callbacks->sendConfigureAck(context, configureReqPacket);
Sergunb 0:8918a71cdbe9 366 //Switch to the Ack-Sent state
Sergunb 0:8918a71cdbe9 367 pppChangeState(fsm, PPP_STATE_8_ACK_SENT);
Sergunb 0:8918a71cdbe9 368 break;
Sergunb 0:8918a71cdbe9 369 case PPP_STATE_7_ACK_RCVD:
Sergunb 0:8918a71cdbe9 370 //Send Configure-Ack packet
Sergunb 0:8918a71cdbe9 371 callbacks->sendConfigureAck(context, configureReqPacket);
Sergunb 0:8918a71cdbe9 372 //Switch to the Opened state
Sergunb 0:8918a71cdbe9 373 pppChangeState(fsm, PPP_STATE_9_OPENED);
Sergunb 0:8918a71cdbe9 374 //Indicate to the upper layers that the automaton is entering the
Sergunb 0:8918a71cdbe9 375 //Opened state. The link is available for network traffic
Sergunb 0:8918a71cdbe9 376 callbacks->thisLayerUp(context);
Sergunb 0:8918a71cdbe9 377 break;
Sergunb 0:8918a71cdbe9 378 case PPP_STATE_8_ACK_SENT:
Sergunb 0:8918a71cdbe9 379 //Send Configure-Ack packet
Sergunb 0:8918a71cdbe9 380 callbacks->sendConfigureAck(context, configureReqPacket);
Sergunb 0:8918a71cdbe9 381 //Stay in current state
Sergunb 0:8918a71cdbe9 382 break;
Sergunb 0:8918a71cdbe9 383 case PPP_STATE_9_OPENED:
Sergunb 0:8918a71cdbe9 384 //Send Configure-Request packet
Sergunb 0:8918a71cdbe9 385 callbacks->sendConfigureReq(context);
Sergunb 0:8918a71cdbe9 386 //Send Configure-Ack packet
Sergunb 0:8918a71cdbe9 387 callbacks->sendConfigureAck(context, configureReqPacket);
Sergunb 0:8918a71cdbe9 388 //Switch to the Ack-Sent state
Sergunb 0:8918a71cdbe9 389 pppChangeState(fsm, PPP_STATE_8_ACK_SENT);
Sergunb 0:8918a71cdbe9 390 //Indicate to the upper layers that the automaton is leaving the Opened
Sergunb 0:8918a71cdbe9 391 //state. The link is no longer available for network traffic
Sergunb 0:8918a71cdbe9 392 callbacks->thisLayerDown(context);
Sergunb 0:8918a71cdbe9 393 break;
Sergunb 0:8918a71cdbe9 394 default:
Sergunb 0:8918a71cdbe9 395 //This event cannot occur in a properly implemented automaton.
Sergunb 0:8918a71cdbe9 396 //No transition is taken, and the implementation should not
Sergunb 0:8918a71cdbe9 397 //reset or freeze
Sergunb 0:8918a71cdbe9 398 break;
Sergunb 0:8918a71cdbe9 399 }
Sergunb 0:8918a71cdbe9 400 }
Sergunb 0:8918a71cdbe9 401 else if(code == PPP_CODE_CONFIGURE_NAK)
Sergunb 0:8918a71cdbe9 402 {
Sergunb 0:8918a71cdbe9 403 //If all configuration options are recognizable, but some values are not
Sergunb 0:8918a71cdbe9 404 //acceptable, then the implementation must transmit a Configure-Nak
Sergunb 0:8918a71cdbe9 405 switch(fsm->state)
Sergunb 0:8918a71cdbe9 406 {
Sergunb 0:8918a71cdbe9 407 case PPP_STATE_2_CLOSED:
Sergunb 0:8918a71cdbe9 408 //Send Terminate-Ack packet
Sergunb 0:8918a71cdbe9 409 callbacks->sendTerminateAck(context, NULL);
Sergunb 0:8918a71cdbe9 410 //Stay in current state
Sergunb 0:8918a71cdbe9 411 break;
Sergunb 0:8918a71cdbe9 412 case PPP_STATE_3_STOPPED:
Sergunb 0:8918a71cdbe9 413 //Initialize restart counter
Sergunb 0:8918a71cdbe9 414 callbacks->initRestartCount(context, PPP_MAX_CONFIGURE);
Sergunb 0:8918a71cdbe9 415 //Send Configure-Request packet
Sergunb 0:8918a71cdbe9 416 callbacks->sendConfigureReq(context);
Sergunb 0:8918a71cdbe9 417 //Send Configure-Nak packet
Sergunb 0:8918a71cdbe9 418 callbacks->sendConfigureNak(context, configureReqPacket);
Sergunb 0:8918a71cdbe9 419 //Switch to the Req-Sent state
Sergunb 0:8918a71cdbe9 420 pppChangeState(fsm, PPP_STATE_6_REQ_SENT);
Sergunb 0:8918a71cdbe9 421 break;
Sergunb 0:8918a71cdbe9 422 case PPP_STATE_4_CLOSING:
Sergunb 0:8918a71cdbe9 423 case PPP_STATE_5_STOPPING:
Sergunb 0:8918a71cdbe9 424 //Stay in current state
Sergunb 0:8918a71cdbe9 425 break;
Sergunb 0:8918a71cdbe9 426 case PPP_STATE_6_REQ_SENT:
Sergunb 0:8918a71cdbe9 427 case PPP_STATE_7_ACK_RCVD:
Sergunb 0:8918a71cdbe9 428 //Send Configure-Nak packet
Sergunb 0:8918a71cdbe9 429 callbacks->sendConfigureNak(context, configureReqPacket);
Sergunb 0:8918a71cdbe9 430 //Stay in current state
Sergunb 0:8918a71cdbe9 431 break;
Sergunb 0:8918a71cdbe9 432 case PPP_STATE_8_ACK_SENT:
Sergunb 0:8918a71cdbe9 433 //Send Configure-Nak packet
Sergunb 0:8918a71cdbe9 434 callbacks->sendConfigureNak(context, configureReqPacket);
Sergunb 0:8918a71cdbe9 435 //Switch to the Req-Sent state
Sergunb 0:8918a71cdbe9 436 pppChangeState(fsm, PPP_STATE_6_REQ_SENT);
Sergunb 0:8918a71cdbe9 437 break;
Sergunb 0:8918a71cdbe9 438 case PPP_STATE_9_OPENED:
Sergunb 0:8918a71cdbe9 439 //Send Configure-Request packet
Sergunb 0:8918a71cdbe9 440 callbacks->sendConfigureReq(context);
Sergunb 0:8918a71cdbe9 441 //Send Configure-Nak packet
Sergunb 0:8918a71cdbe9 442 callbacks->sendConfigureNak(context, configureReqPacket);
Sergunb 0:8918a71cdbe9 443 //Switch to the Req-Sent state
Sergunb 0:8918a71cdbe9 444 pppChangeState(fsm, PPP_STATE_6_REQ_SENT);
Sergunb 0:8918a71cdbe9 445 //Indicate to the upper layers that the automaton is leaving the Opened
Sergunb 0:8918a71cdbe9 446 //state. The link is no longer available for network traffic
Sergunb 0:8918a71cdbe9 447 callbacks->thisLayerDown(context);
Sergunb 0:8918a71cdbe9 448 break;
Sergunb 0:8918a71cdbe9 449 default:
Sergunb 0:8918a71cdbe9 450 //This event cannot occur in a properly implemented automaton.
Sergunb 0:8918a71cdbe9 451 //No transition is taken, and the implementation should not
Sergunb 0:8918a71cdbe9 452 //reset or freeze
Sergunb 0:8918a71cdbe9 453 break;
Sergunb 0:8918a71cdbe9 454 }
Sergunb 0:8918a71cdbe9 455 }
Sergunb 0:8918a71cdbe9 456 else if(code == PPP_CODE_CONFIGURE_REJ)
Sergunb 0:8918a71cdbe9 457 {
Sergunb 0:8918a71cdbe9 458 //If some configuration options received in the Configure-Request are not
Sergunb 0:8918a71cdbe9 459 //recognizable or not acceptable for negotiation, then the implementation
Sergunb 0:8918a71cdbe9 460 //must transmit a Configure-Reject
Sergunb 0:8918a71cdbe9 461 switch(fsm->state)
Sergunb 0:8918a71cdbe9 462 {
Sergunb 0:8918a71cdbe9 463 case PPP_STATE_2_CLOSED:
Sergunb 0:8918a71cdbe9 464 //Send Terminate-Ack packet
Sergunb 0:8918a71cdbe9 465 callbacks->sendTerminateAck(context, NULL);
Sergunb 0:8918a71cdbe9 466 //Stay in current state
Sergunb 0:8918a71cdbe9 467 break;
Sergunb 0:8918a71cdbe9 468 case PPP_STATE_3_STOPPED:
Sergunb 0:8918a71cdbe9 469 //Initialize restart counter
Sergunb 0:8918a71cdbe9 470 callbacks->initRestartCount(context, PPP_MAX_CONFIGURE);
Sergunb 0:8918a71cdbe9 471 //Send Configure-Request packet
Sergunb 0:8918a71cdbe9 472 callbacks->sendConfigureReq(context);
Sergunb 0:8918a71cdbe9 473 //Send Configure-Reject packet
Sergunb 0:8918a71cdbe9 474 callbacks->sendConfigureRej(context, configureReqPacket);
Sergunb 0:8918a71cdbe9 475 //Switch to the Req-Sent state
Sergunb 0:8918a71cdbe9 476 pppChangeState(fsm, PPP_STATE_6_REQ_SENT);
Sergunb 0:8918a71cdbe9 477 break;
Sergunb 0:8918a71cdbe9 478 case PPP_STATE_4_CLOSING:
Sergunb 0:8918a71cdbe9 479 case PPP_STATE_5_STOPPING:
Sergunb 0:8918a71cdbe9 480 //Stay in current state
Sergunb 0:8918a71cdbe9 481 break;
Sergunb 0:8918a71cdbe9 482 case PPP_STATE_6_REQ_SENT:
Sergunb 0:8918a71cdbe9 483 case PPP_STATE_7_ACK_RCVD:
Sergunb 0:8918a71cdbe9 484 //Send Configure-Reject packet
Sergunb 0:8918a71cdbe9 485 callbacks->sendConfigureRej(context, configureReqPacket);
Sergunb 0:8918a71cdbe9 486 //Stay in current state
Sergunb 0:8918a71cdbe9 487 break;
Sergunb 0:8918a71cdbe9 488 case PPP_STATE_8_ACK_SENT:
Sergunb 0:8918a71cdbe9 489 //Send Configure-Reject packet
Sergunb 0:8918a71cdbe9 490 callbacks->sendConfigureRej(context, configureReqPacket);
Sergunb 0:8918a71cdbe9 491 //Switch to the Req-Sent state
Sergunb 0:8918a71cdbe9 492 pppChangeState(fsm, PPP_STATE_6_REQ_SENT);
Sergunb 0:8918a71cdbe9 493 break;
Sergunb 0:8918a71cdbe9 494 case PPP_STATE_9_OPENED:
Sergunb 0:8918a71cdbe9 495 //Send Configure-Request packet
Sergunb 0:8918a71cdbe9 496 callbacks->sendConfigureReq(context);
Sergunb 0:8918a71cdbe9 497 //Send Configure-Reject packet
Sergunb 0:8918a71cdbe9 498 callbacks->sendConfigureRej(context, configureReqPacket);
Sergunb 0:8918a71cdbe9 499 //Switch to the Req-Sent state
Sergunb 0:8918a71cdbe9 500 pppChangeState(fsm, PPP_STATE_6_REQ_SENT);
Sergunb 0:8918a71cdbe9 501 //Indicate to the upper layers that the automaton is leaving the Opened
Sergunb 0:8918a71cdbe9 502 //state. The link is no longer available for network traffic
Sergunb 0:8918a71cdbe9 503 callbacks->thisLayerDown(context);
Sergunb 0:8918a71cdbe9 504 break;
Sergunb 0:8918a71cdbe9 505 default:
Sergunb 0:8918a71cdbe9 506 //This event cannot occur in a properly implemented automaton.
Sergunb 0:8918a71cdbe9 507 //No transition is taken, and the implementation should not
Sergunb 0:8918a71cdbe9 508 //reset or freeze
Sergunb 0:8918a71cdbe9 509 break;
Sergunb 0:8918a71cdbe9 510 }
Sergunb 0:8918a71cdbe9 511 }
Sergunb 0:8918a71cdbe9 512 }
Sergunb 0:8918a71cdbe9 513
Sergunb 0:8918a71cdbe9 514
Sergunb 0:8918a71cdbe9 515 /**
Sergunb 0:8918a71cdbe9 516 * @brief Process Receive-Configure-Ack event
Sergunb 0:8918a71cdbe9 517 * @param[in] context PPP context
Sergunb 0:8918a71cdbe9 518 * @param[in,out] fsm Finite state machine
Sergunb 0:8918a71cdbe9 519 * @param[in] callbacks FSM actions
Sergunb 0:8918a71cdbe9 520 **/
Sergunb 0:8918a71cdbe9 521
Sergunb 0:8918a71cdbe9 522 void pppRcvConfigureAckEvent(PppContext *context, PppFsm *fsm,
Sergunb 0:8918a71cdbe9 523 const PppCallbacks *callbacks)
Sergunb 0:8918a71cdbe9 524 {
Sergunb 0:8918a71cdbe9 525 //Check current state
Sergunb 0:8918a71cdbe9 526 switch(fsm->state)
Sergunb 0:8918a71cdbe9 527 {
Sergunb 0:8918a71cdbe9 528 case PPP_STATE_2_CLOSED:
Sergunb 0:8918a71cdbe9 529 case PPP_STATE_3_STOPPED:
Sergunb 0:8918a71cdbe9 530 //Send Terminate-Ack packet
Sergunb 0:8918a71cdbe9 531 callbacks->sendTerminateAck(context, NULL);
Sergunb 0:8918a71cdbe9 532 //Stay in current state
Sergunb 0:8918a71cdbe9 533 break;
Sergunb 0:8918a71cdbe9 534 case PPP_STATE_4_CLOSING:
Sergunb 0:8918a71cdbe9 535 case PPP_STATE_5_STOPPING:
Sergunb 0:8918a71cdbe9 536 //Stay in current state
Sergunb 0:8918a71cdbe9 537 break;
Sergunb 0:8918a71cdbe9 538 case PPP_STATE_6_REQ_SENT:
Sergunb 0:8918a71cdbe9 539 //Initialize restart counter
Sergunb 0:8918a71cdbe9 540 callbacks->initRestartCount(context, PPP_MAX_CONFIGURE);
Sergunb 0:8918a71cdbe9 541 //Switch to the Ack-Rcvd state
Sergunb 0:8918a71cdbe9 542 fsm->state = PPP_STATE_7_ACK_RCVD;
Sergunb 0:8918a71cdbe9 543 break;
Sergunb 0:8918a71cdbe9 544 case PPP_STATE_7_ACK_RCVD:
Sergunb 0:8918a71cdbe9 545 //Send Configure-Request packet
Sergunb 0:8918a71cdbe9 546 callbacks->sendConfigureReq(context);
Sergunb 0:8918a71cdbe9 547 //Switch to the Req-Sent state
Sergunb 0:8918a71cdbe9 548 pppChangeState(fsm, PPP_STATE_6_REQ_SENT);
Sergunb 0:8918a71cdbe9 549 break;
Sergunb 0:8918a71cdbe9 550 case PPP_STATE_8_ACK_SENT:
Sergunb 0:8918a71cdbe9 551 //Initialize restart counter
Sergunb 0:8918a71cdbe9 552 callbacks->initRestartCount(context, PPP_MAX_CONFIGURE);
Sergunb 0:8918a71cdbe9 553 //Switch to the Opened state
Sergunb 0:8918a71cdbe9 554 pppChangeState(fsm, PPP_STATE_9_OPENED);
Sergunb 0:8918a71cdbe9 555 //Indicate to the upper layers that the automaton is entering the
Sergunb 0:8918a71cdbe9 556 //Opened state. The link is available for network traffic
Sergunb 0:8918a71cdbe9 557 callbacks->thisLayerUp(context);
Sergunb 0:8918a71cdbe9 558 break;
Sergunb 0:8918a71cdbe9 559 case PPP_STATE_9_OPENED:
Sergunb 0:8918a71cdbe9 560 //Send Configure-Request packet
Sergunb 0:8918a71cdbe9 561 callbacks->sendConfigureReq(context);
Sergunb 0:8918a71cdbe9 562 //Switch to the Req-Sent state
Sergunb 0:8918a71cdbe9 563 pppChangeState(fsm, PPP_STATE_6_REQ_SENT);
Sergunb 0:8918a71cdbe9 564 //Indicate to the upper layers that the automaton is leaving the Opened
Sergunb 0:8918a71cdbe9 565 //state. The link is no longer available for network traffic
Sergunb 0:8918a71cdbe9 566 callbacks->thisLayerDown(context);
Sergunb 0:8918a71cdbe9 567 break;
Sergunb 0:8918a71cdbe9 568 default:
Sergunb 0:8918a71cdbe9 569 //This event cannot occur in a properly implemented automaton.
Sergunb 0:8918a71cdbe9 570 //No transition is taken, and the implementation should not
Sergunb 0:8918a71cdbe9 571 //reset or freeze
Sergunb 0:8918a71cdbe9 572 break;
Sergunb 0:8918a71cdbe9 573 }
Sergunb 0:8918a71cdbe9 574 }
Sergunb 0:8918a71cdbe9 575
Sergunb 0:8918a71cdbe9 576
Sergunb 0:8918a71cdbe9 577 /**
Sergunb 0:8918a71cdbe9 578 * @brief Process Receive-Configure-Nak event
Sergunb 0:8918a71cdbe9 579 * @param[in] context PPP context
Sergunb 0:8918a71cdbe9 580 * @param[in,out] fsm Finite state machine
Sergunb 0:8918a71cdbe9 581 * @param[in] callbacks FSM actions
Sergunb 0:8918a71cdbe9 582 **/
Sergunb 0:8918a71cdbe9 583
Sergunb 0:8918a71cdbe9 584 void pppRcvConfigureNakEvent(PppContext *context, PppFsm *fsm,
Sergunb 0:8918a71cdbe9 585 const PppCallbacks *callbacks)
Sergunb 0:8918a71cdbe9 586 {
Sergunb 0:8918a71cdbe9 587 //Check current state
Sergunb 0:8918a71cdbe9 588 switch(fsm->state)
Sergunb 0:8918a71cdbe9 589 {
Sergunb 0:8918a71cdbe9 590 case PPP_STATE_2_CLOSED:
Sergunb 0:8918a71cdbe9 591 case PPP_STATE_3_STOPPED:
Sergunb 0:8918a71cdbe9 592 //Send Terminate-Ack packet
Sergunb 0:8918a71cdbe9 593 callbacks->sendTerminateAck(context, NULL);
Sergunb 0:8918a71cdbe9 594 //Stay in current state
Sergunb 0:8918a71cdbe9 595 break;
Sergunb 0:8918a71cdbe9 596 case PPP_STATE_4_CLOSING:
Sergunb 0:8918a71cdbe9 597 case PPP_STATE_5_STOPPING:
Sergunb 0:8918a71cdbe9 598 //Stay in current state
Sergunb 0:8918a71cdbe9 599 break;
Sergunb 0:8918a71cdbe9 600 case PPP_STATE_6_REQ_SENT:
Sergunb 0:8918a71cdbe9 601 //Initialize restart counter
Sergunb 0:8918a71cdbe9 602 callbacks->initRestartCount(context, PPP_MAX_CONFIGURE);
Sergunb 0:8918a71cdbe9 603 //Send Configure-Request packet
Sergunb 0:8918a71cdbe9 604 callbacks->sendConfigureReq(context);
Sergunb 0:8918a71cdbe9 605 //Stay in current state
Sergunb 0:8918a71cdbe9 606 break;
Sergunb 0:8918a71cdbe9 607 case PPP_STATE_7_ACK_RCVD:
Sergunb 0:8918a71cdbe9 608 //Send Configure-Request packet
Sergunb 0:8918a71cdbe9 609 callbacks->sendConfigureReq(context);
Sergunb 0:8918a71cdbe9 610 //Switch to the Req-Sent state
Sergunb 0:8918a71cdbe9 611 pppChangeState(fsm, PPP_STATE_6_REQ_SENT);
Sergunb 0:8918a71cdbe9 612 break;
Sergunb 0:8918a71cdbe9 613 case PPP_STATE_8_ACK_SENT:
Sergunb 0:8918a71cdbe9 614 //Initialize restart counter
Sergunb 0:8918a71cdbe9 615 callbacks->initRestartCount(context, PPP_MAX_CONFIGURE);
Sergunb 0:8918a71cdbe9 616 //Send Configure-Request packet
Sergunb 0:8918a71cdbe9 617 callbacks->sendConfigureReq(context);
Sergunb 0:8918a71cdbe9 618 //Stay in current state
Sergunb 0:8918a71cdbe9 619 break;
Sergunb 0:8918a71cdbe9 620 case PPP_STATE_9_OPENED:
Sergunb 0:8918a71cdbe9 621 //Send Configure-Request packet
Sergunb 0:8918a71cdbe9 622 callbacks->sendConfigureReq(context);
Sergunb 0:8918a71cdbe9 623 //Switch to the Req-Sent state
Sergunb 0:8918a71cdbe9 624 pppChangeState(fsm, PPP_STATE_6_REQ_SENT);
Sergunb 0:8918a71cdbe9 625 //Indicate to the upper layers that the automaton is leaving the Opened
Sergunb 0:8918a71cdbe9 626 //state. The link is no longer available for network traffic
Sergunb 0:8918a71cdbe9 627 callbacks->thisLayerDown(context);
Sergunb 0:8918a71cdbe9 628 break;
Sergunb 0:8918a71cdbe9 629 default:
Sergunb 0:8918a71cdbe9 630 //This event cannot occur in a properly implemented automaton.
Sergunb 0:8918a71cdbe9 631 //No transition is taken, and the implementation should not
Sergunb 0:8918a71cdbe9 632 //reset or freeze
Sergunb 0:8918a71cdbe9 633 break;
Sergunb 0:8918a71cdbe9 634 }
Sergunb 0:8918a71cdbe9 635 }
Sergunb 0:8918a71cdbe9 636
Sergunb 0:8918a71cdbe9 637
Sergunb 0:8918a71cdbe9 638 /**
Sergunb 0:8918a71cdbe9 639 * @brief Process Receive-Terminate-Req event
Sergunb 0:8918a71cdbe9 640 * @param[in] context PPP context
Sergunb 0:8918a71cdbe9 641 * @param[in,out] fsm Finite state machine
Sergunb 0:8918a71cdbe9 642 * @param[in] callbacks FSM actions
Sergunb 0:8918a71cdbe9 643 * @param[in] terminateReqPacket Terminate-Request packet received from the peer
Sergunb 0:8918a71cdbe9 644 **/
Sergunb 0:8918a71cdbe9 645
Sergunb 0:8918a71cdbe9 646 void pppRcvTerminateReqEvent(PppContext *context, PppFsm *fsm,
Sergunb 0:8918a71cdbe9 647 const PppCallbacks *callbacks, const PppTerminatePacket *terminateReqPacket)
Sergunb 0:8918a71cdbe9 648 {
Sergunb 0:8918a71cdbe9 649 //Check current state
Sergunb 0:8918a71cdbe9 650 switch(fsm->state)
Sergunb 0:8918a71cdbe9 651 {
Sergunb 0:8918a71cdbe9 652 case PPP_STATE_2_CLOSED:
Sergunb 0:8918a71cdbe9 653 case PPP_STATE_3_STOPPED:
Sergunb 0:8918a71cdbe9 654 case PPP_STATE_4_CLOSING:
Sergunb 0:8918a71cdbe9 655 case PPP_STATE_5_STOPPING:
Sergunb 0:8918a71cdbe9 656 //Send Terminate-Ack packet
Sergunb 0:8918a71cdbe9 657 callbacks->sendTerminateAck(context, terminateReqPacket);
Sergunb 0:8918a71cdbe9 658 //Stay in current state
Sergunb 0:8918a71cdbe9 659 break;
Sergunb 0:8918a71cdbe9 660 case PPP_STATE_6_REQ_SENT:
Sergunb 0:8918a71cdbe9 661 case PPP_STATE_7_ACK_RCVD:
Sergunb 0:8918a71cdbe9 662 case PPP_STATE_8_ACK_SENT:
Sergunb 0:8918a71cdbe9 663 //Send Terminate-Ack packet
Sergunb 0:8918a71cdbe9 664 callbacks->sendTerminateAck(context, terminateReqPacket);
Sergunb 0:8918a71cdbe9 665 //Switch to the Req-Sent state
Sergunb 0:8918a71cdbe9 666 pppChangeState(fsm, PPP_STATE_6_REQ_SENT);
Sergunb 0:8918a71cdbe9 667 break;
Sergunb 0:8918a71cdbe9 668 case PPP_STATE_9_OPENED:
Sergunb 0:8918a71cdbe9 669 //Zero restart counter
Sergunb 0:8918a71cdbe9 670 callbacks->zeroRestartCount(context);
Sergunb 0:8918a71cdbe9 671 //Send Terminate-Ack packet
Sergunb 0:8918a71cdbe9 672 callbacks->sendTerminateAck(context, terminateReqPacket);
Sergunb 0:8918a71cdbe9 673 //Switch to the Stopping state
Sergunb 0:8918a71cdbe9 674 pppChangeState(fsm, PPP_STATE_5_STOPPING);
Sergunb 0:8918a71cdbe9 675 //Indicate to the upper layers that the automaton is leaving the Opened
Sergunb 0:8918a71cdbe9 676 //state. The link is no longer available for network traffic
Sergunb 0:8918a71cdbe9 677 callbacks->thisLayerDown(context);
Sergunb 0:8918a71cdbe9 678 break;
Sergunb 0:8918a71cdbe9 679 default:
Sergunb 0:8918a71cdbe9 680 //This event cannot occur in a properly implemented automaton.
Sergunb 0:8918a71cdbe9 681 //No transition is taken, and the implementation should not
Sergunb 0:8918a71cdbe9 682 //reset or freeze
Sergunb 0:8918a71cdbe9 683 break;
Sergunb 0:8918a71cdbe9 684 }
Sergunb 0:8918a71cdbe9 685 }
Sergunb 0:8918a71cdbe9 686
Sergunb 0:8918a71cdbe9 687
Sergunb 0:8918a71cdbe9 688 /**
Sergunb 0:8918a71cdbe9 689 * @brief Process Receive-Terminate-Ack event
Sergunb 0:8918a71cdbe9 690 * @param[in] context PPP context
Sergunb 0:8918a71cdbe9 691 * @param[in,out] fsm Finite state machine
Sergunb 0:8918a71cdbe9 692 * @param[in] callbacks FSM actions
Sergunb 0:8918a71cdbe9 693 **/
Sergunb 0:8918a71cdbe9 694
Sergunb 0:8918a71cdbe9 695 void pppRcvTerminateAckEvent(PppContext *context, PppFsm *fsm,
Sergunb 0:8918a71cdbe9 696 const PppCallbacks *callbacks)
Sergunb 0:8918a71cdbe9 697 {
Sergunb 0:8918a71cdbe9 698 //Check current state
Sergunb 0:8918a71cdbe9 699 switch(fsm->state)
Sergunb 0:8918a71cdbe9 700 {
Sergunb 0:8918a71cdbe9 701 case PPP_STATE_2_CLOSED:
Sergunb 0:8918a71cdbe9 702 case PPP_STATE_3_STOPPED:
Sergunb 0:8918a71cdbe9 703 //Stay in current state
Sergunb 0:8918a71cdbe9 704 break;
Sergunb 0:8918a71cdbe9 705 case PPP_STATE_4_CLOSING:
Sergunb 0:8918a71cdbe9 706 //Switch to the Closed state
Sergunb 0:8918a71cdbe9 707 pppChangeState(fsm, PPP_STATE_2_CLOSED);
Sergunb 0:8918a71cdbe9 708 //Indicate to the lower layers that the automaton is entering the
Sergunb 0:8918a71cdbe9 709 //Initial, Closed or Stopped states. The lower layer is no longer
Sergunb 0:8918a71cdbe9 710 //needed for the link
Sergunb 0:8918a71cdbe9 711 callbacks->thisLayerFinished(context);
Sergunb 0:8918a71cdbe9 712 break;
Sergunb 0:8918a71cdbe9 713 case PPP_STATE_5_STOPPING:
Sergunb 0:8918a71cdbe9 714 //Switch to the Stopped state
Sergunb 0:8918a71cdbe9 715 pppChangeState(fsm, PPP_STATE_3_STOPPED);
Sergunb 0:8918a71cdbe9 716 //Indicate to the lower layers that the automaton is entering the
Sergunb 0:8918a71cdbe9 717 //Initial, Closed or Stopped states. The lower layer is no longer
Sergunb 0:8918a71cdbe9 718 //needed for the link
Sergunb 0:8918a71cdbe9 719 callbacks->thisLayerFinished(context);
Sergunb 0:8918a71cdbe9 720 break;
Sergunb 0:8918a71cdbe9 721 case PPP_STATE_6_REQ_SENT:
Sergunb 0:8918a71cdbe9 722 case PPP_STATE_7_ACK_RCVD:
Sergunb 0:8918a71cdbe9 723 //Switch to the Req-Sent state
Sergunb 0:8918a71cdbe9 724 pppChangeState(fsm, PPP_STATE_6_REQ_SENT);
Sergunb 0:8918a71cdbe9 725 break;
Sergunb 0:8918a71cdbe9 726 case PPP_STATE_8_ACK_SENT:
Sergunb 0:8918a71cdbe9 727 //Stay in current state
Sergunb 0:8918a71cdbe9 728 break;
Sergunb 0:8918a71cdbe9 729 case PPP_STATE_9_OPENED:
Sergunb 0:8918a71cdbe9 730 //Send Configure-Req packet
Sergunb 0:8918a71cdbe9 731 callbacks->sendConfigureReq(context);
Sergunb 0:8918a71cdbe9 732 //Switch to the Req-Sent state
Sergunb 0:8918a71cdbe9 733 pppChangeState(fsm, PPP_STATE_6_REQ_SENT);
Sergunb 0:8918a71cdbe9 734 //Indicate to the upper layers that the automaton is leaving the Opened
Sergunb 0:8918a71cdbe9 735 //state. The link is no longer available for network traffic
Sergunb 0:8918a71cdbe9 736 callbacks->thisLayerDown(context);
Sergunb 0:8918a71cdbe9 737 break;
Sergunb 0:8918a71cdbe9 738 default:
Sergunb 0:8918a71cdbe9 739 //This event cannot occur in a properly implemented automaton.
Sergunb 0:8918a71cdbe9 740 //No transition is taken, and the implementation should not
Sergunb 0:8918a71cdbe9 741 //reset or freeze
Sergunb 0:8918a71cdbe9 742 break;
Sergunb 0:8918a71cdbe9 743 }
Sergunb 0:8918a71cdbe9 744 }
Sergunb 0:8918a71cdbe9 745
Sergunb 0:8918a71cdbe9 746
Sergunb 0:8918a71cdbe9 747 /**
Sergunb 0:8918a71cdbe9 748 * @brief Process Receive-Unknown-Code event
Sergunb 0:8918a71cdbe9 749 * @param[in] context PPP context
Sergunb 0:8918a71cdbe9 750 * @param[in,out] fsm Finite state machine
Sergunb 0:8918a71cdbe9 751 * @param[in] callbacks FSM actions
Sergunb 0:8918a71cdbe9 752 * @param[in] packet Un-interpretable packet received from the peer
Sergunb 0:8918a71cdbe9 753 **/
Sergunb 0:8918a71cdbe9 754
Sergunb 0:8918a71cdbe9 755 void pppRcvUnknownCodeEvent(PppContext *context, PppFsm *fsm,
Sergunb 0:8918a71cdbe9 756 const PppCallbacks *callbacks, const PppPacket *packet)
Sergunb 0:8918a71cdbe9 757 {
Sergunb 0:8918a71cdbe9 758 //Check current state
Sergunb 0:8918a71cdbe9 759 switch(fsm->state)
Sergunb 0:8918a71cdbe9 760 {
Sergunb 0:8918a71cdbe9 761 case PPP_STATE_2_CLOSED:
Sergunb 0:8918a71cdbe9 762 case PPP_STATE_3_STOPPED:
Sergunb 0:8918a71cdbe9 763 case PPP_STATE_4_CLOSING:
Sergunb 0:8918a71cdbe9 764 case PPP_STATE_5_STOPPING:
Sergunb 0:8918a71cdbe9 765 case PPP_STATE_6_REQ_SENT:
Sergunb 0:8918a71cdbe9 766 case PPP_STATE_7_ACK_RCVD:
Sergunb 0:8918a71cdbe9 767 case PPP_STATE_8_ACK_SENT:
Sergunb 0:8918a71cdbe9 768 case PPP_STATE_9_OPENED:
Sergunb 0:8918a71cdbe9 769 //Send Reject-Code packet
Sergunb 0:8918a71cdbe9 770 callbacks->sendCodeRej(context, packet);
Sergunb 0:8918a71cdbe9 771 //Stay in current state
Sergunb 0:8918a71cdbe9 772 break;
Sergunb 0:8918a71cdbe9 773 default:
Sergunb 0:8918a71cdbe9 774 //This event cannot occur in a properly implemented automaton.
Sergunb 0:8918a71cdbe9 775 //No transition is taken, and the implementation should not
Sergunb 0:8918a71cdbe9 776 //reset or freeze
Sergunb 0:8918a71cdbe9 777 break;
Sergunb 0:8918a71cdbe9 778 }
Sergunb 0:8918a71cdbe9 779 }
Sergunb 0:8918a71cdbe9 780
Sergunb 0:8918a71cdbe9 781 /**
Sergunb 0:8918a71cdbe9 782 * @brief Process Receive-Code-Reject or Receive-Protocol-Reject event
Sergunb 0:8918a71cdbe9 783 * @param[in] context PPP context
Sergunb 0:8918a71cdbe9 784 * @param[in,out] fsm Finite state machine
Sergunb 0:8918a71cdbe9 785 * @param[in] callbacks FSM actions
Sergunb 0:8918a71cdbe9 786 * @param[in] acceptable This parameter tells whether the rejected value
Sergunb 0:8918a71cdbe9 787 * is acceptable or catastrophic
Sergunb 0:8918a71cdbe9 788 **/
Sergunb 0:8918a71cdbe9 789
Sergunb 0:8918a71cdbe9 790 void pppRcvCodeRejEvent(PppContext *context, PppFsm *fsm,
Sergunb 0:8918a71cdbe9 791 const PppCallbacks *callbacks, bool_t acceptable)
Sergunb 0:8918a71cdbe9 792 {
Sergunb 0:8918a71cdbe9 793 //Check whether the rejected value is acceptable or catastrophic
Sergunb 0:8918a71cdbe9 794 if(acceptable)
Sergunb 0:8918a71cdbe9 795 {
Sergunb 0:8918a71cdbe9 796 //The RXJ+ event arises when the rejected value is acceptable, such
Sergunb 0:8918a71cdbe9 797 //as a Code-Reject of an extended code, or a Protocol-Reject of a
Sergunb 0:8918a71cdbe9 798 //NCP. These are within the scope of normal operation
Sergunb 0:8918a71cdbe9 799 switch(fsm->state)
Sergunb 0:8918a71cdbe9 800 {
Sergunb 0:8918a71cdbe9 801 case PPP_STATE_2_CLOSED:
Sergunb 0:8918a71cdbe9 802 case PPP_STATE_3_STOPPED:
Sergunb 0:8918a71cdbe9 803 case PPP_STATE_4_CLOSING:
Sergunb 0:8918a71cdbe9 804 case PPP_STATE_5_STOPPING:
Sergunb 0:8918a71cdbe9 805 case PPP_STATE_6_REQ_SENT:
Sergunb 0:8918a71cdbe9 806 //Stay in current state
Sergunb 0:8918a71cdbe9 807 break;
Sergunb 0:8918a71cdbe9 808 case PPP_STATE_7_ACK_RCVD:
Sergunb 0:8918a71cdbe9 809 //Switch to the Req-Sent state
Sergunb 0:8918a71cdbe9 810 pppChangeState(fsm, PPP_STATE_6_REQ_SENT);
Sergunb 0:8918a71cdbe9 811 break;
Sergunb 0:8918a71cdbe9 812 case PPP_STATE_8_ACK_SENT:
Sergunb 0:8918a71cdbe9 813 case PPP_STATE_9_OPENED:
Sergunb 0:8918a71cdbe9 814 //Stay in current state
Sergunb 0:8918a71cdbe9 815 break;
Sergunb 0:8918a71cdbe9 816 default:
Sergunb 0:8918a71cdbe9 817 //This event cannot occur in a properly implemented automaton.
Sergunb 0:8918a71cdbe9 818 //No transition is taken, and the implementation should not
Sergunb 0:8918a71cdbe9 819 //reset or freeze
Sergunb 0:8918a71cdbe9 820 break;
Sergunb 0:8918a71cdbe9 821 }
Sergunb 0:8918a71cdbe9 822 }
Sergunb 0:8918a71cdbe9 823 else
Sergunb 0:8918a71cdbe9 824 {
Sergunb 0:8918a71cdbe9 825 //The RXJ- event arises when the rejected value is catastrophic,
Sergunb 0:8918a71cdbe9 826 //such as a Code-Reject of Configure-Request, or a Protocol-Reject
Sergunb 0:8918a71cdbe9 827 //of LCP! This event communicates an unrecoverable error that
Sergunb 0:8918a71cdbe9 828 //terminates the connection
Sergunb 0:8918a71cdbe9 829 switch(fsm->state)
Sergunb 0:8918a71cdbe9 830 {
Sergunb 0:8918a71cdbe9 831 case PPP_STATE_2_CLOSED:
Sergunb 0:8918a71cdbe9 832 case PPP_STATE_3_STOPPED:
Sergunb 0:8918a71cdbe9 833 //Indicate to the lower layers that the automaton is entering the
Sergunb 0:8918a71cdbe9 834 //Initial, Closed or Stopped states. The lower layer is no longer
Sergunb 0:8918a71cdbe9 835 //needed for the link
Sergunb 0:8918a71cdbe9 836 callbacks->thisLayerFinished(context);
Sergunb 0:8918a71cdbe9 837 //Stay in current state
Sergunb 0:8918a71cdbe9 838 break;
Sergunb 0:8918a71cdbe9 839 case PPP_STATE_4_CLOSING:
Sergunb 0:8918a71cdbe9 840 //Switch to the Closed state
Sergunb 0:8918a71cdbe9 841 pppChangeState(fsm, PPP_STATE_2_CLOSED);
Sergunb 0:8918a71cdbe9 842 //Indicate to the lower layers that the automaton is entering the
Sergunb 0:8918a71cdbe9 843 //Initial, Closed or Stopped states. The lower layer is no longer
Sergunb 0:8918a71cdbe9 844 //needed for the link
Sergunb 0:8918a71cdbe9 845 callbacks->thisLayerFinished(context);
Sergunb 0:8918a71cdbe9 846 break;
Sergunb 0:8918a71cdbe9 847 case PPP_STATE_5_STOPPING:
Sergunb 0:8918a71cdbe9 848 case PPP_STATE_6_REQ_SENT:
Sergunb 0:8918a71cdbe9 849 case PPP_STATE_7_ACK_RCVD:
Sergunb 0:8918a71cdbe9 850 case PPP_STATE_8_ACK_SENT:
Sergunb 0:8918a71cdbe9 851 //Switch to the Stopped state
Sergunb 0:8918a71cdbe9 852 pppChangeState(fsm, PPP_STATE_3_STOPPED);
Sergunb 0:8918a71cdbe9 853 //Indicate to the lower layers that the automaton is entering the
Sergunb 0:8918a71cdbe9 854 //Initial, Closed or Stopped states. The lower layer is no longer
Sergunb 0:8918a71cdbe9 855 //needed for the link
Sergunb 0:8918a71cdbe9 856 callbacks->thisLayerFinished(context);
Sergunb 0:8918a71cdbe9 857 break;
Sergunb 0:8918a71cdbe9 858 case PPP_STATE_9_OPENED:
Sergunb 0:8918a71cdbe9 859 //Initialize restart counter
Sergunb 0:8918a71cdbe9 860 callbacks->initRestartCount(context, PPP_MAX_TERMINATE);
Sergunb 0:8918a71cdbe9 861 //Send Terminate-Req packet
Sergunb 0:8918a71cdbe9 862 callbacks->sendTerminateReq(context);
Sergunb 0:8918a71cdbe9 863 //Switch to the Stopping state
Sergunb 0:8918a71cdbe9 864 pppChangeState(fsm, PPP_STATE_5_STOPPING);
Sergunb 0:8918a71cdbe9 865 //Indicate to the upper layers that the automaton is leaving the Opened
Sergunb 0:8918a71cdbe9 866 //state. The link is no longer available for network traffic
Sergunb 0:8918a71cdbe9 867 callbacks->thisLayerDown(context);
Sergunb 0:8918a71cdbe9 868 break;
Sergunb 0:8918a71cdbe9 869 default:
Sergunb 0:8918a71cdbe9 870 //This event cannot occur in a properly implemented automaton.
Sergunb 0:8918a71cdbe9 871 //No transition is taken, and the implementation should not
Sergunb 0:8918a71cdbe9 872 //reset or freeze
Sergunb 0:8918a71cdbe9 873 break;
Sergunb 0:8918a71cdbe9 874 }
Sergunb 0:8918a71cdbe9 875 }
Sergunb 0:8918a71cdbe9 876 }
Sergunb 0:8918a71cdbe9 877
Sergunb 0:8918a71cdbe9 878
Sergunb 0:8918a71cdbe9 879 /**
Sergunb 0:8918a71cdbe9 880 * @brief Process Receive-Echo-Request event
Sergunb 0:8918a71cdbe9 881 * @param[in] context PPP context
Sergunb 0:8918a71cdbe9 882 * @param[in,out] fsm Finite state machine
Sergunb 0:8918a71cdbe9 883 * @param[in] callbacks FSM actions
Sergunb 0:8918a71cdbe9 884 * @param[in] echoReqPacket Echo-Request packet received from the peer
Sergunb 0:8918a71cdbe9 885 **/
Sergunb 0:8918a71cdbe9 886
Sergunb 0:8918a71cdbe9 887 void pppRcvEchoReqEvent(PppContext *context, PppFsm *fsm,
Sergunb 0:8918a71cdbe9 888 const PppCallbacks *callbacks, const PppEchoPacket *echoReqPacket)
Sergunb 0:8918a71cdbe9 889 {
Sergunb 0:8918a71cdbe9 890 //Check current state
Sergunb 0:8918a71cdbe9 891 switch(fsm->state)
Sergunb 0:8918a71cdbe9 892 {
Sergunb 0:8918a71cdbe9 893 case PPP_STATE_2_CLOSED:
Sergunb 0:8918a71cdbe9 894 case PPP_STATE_3_STOPPED:
Sergunb 0:8918a71cdbe9 895 case PPP_STATE_4_CLOSING:
Sergunb 0:8918a71cdbe9 896 case PPP_STATE_5_STOPPING:
Sergunb 0:8918a71cdbe9 897 case PPP_STATE_6_REQ_SENT:
Sergunb 0:8918a71cdbe9 898 case PPP_STATE_7_ACK_RCVD:
Sergunb 0:8918a71cdbe9 899 case PPP_STATE_8_ACK_SENT:
Sergunb 0:8918a71cdbe9 900 //Stay in current state
Sergunb 0:8918a71cdbe9 901 break;
Sergunb 0:8918a71cdbe9 902 case PPP_STATE_9_OPENED:
Sergunb 0:8918a71cdbe9 903 //Send Echo-Reply packet
Sergunb 0:8918a71cdbe9 904 callbacks->sendEchoRep(context, echoReqPacket);
Sergunb 0:8918a71cdbe9 905 //Stay in current state
Sergunb 0:8918a71cdbe9 906 break;
Sergunb 0:8918a71cdbe9 907 default:
Sergunb 0:8918a71cdbe9 908 //This event cannot occur in a properly implemented automaton.
Sergunb 0:8918a71cdbe9 909 //No transition is taken, and the implementation should not
Sergunb 0:8918a71cdbe9 910 //reset or freeze
Sergunb 0:8918a71cdbe9 911 break;
Sergunb 0:8918a71cdbe9 912 }
Sergunb 0:8918a71cdbe9 913 }
Sergunb 0:8918a71cdbe9 914
Sergunb 0:8918a71cdbe9 915
Sergunb 0:8918a71cdbe9 916 /**
Sergunb 0:8918a71cdbe9 917 * @brief Update PPP FSM state
Sergunb 0:8918a71cdbe9 918 * @param[in,out] fsm Finite state machine
Sergunb 0:8918a71cdbe9 919 * @param[in] newState New PPP state to switch to
Sergunb 0:8918a71cdbe9 920 **/
Sergunb 0:8918a71cdbe9 921
Sergunb 0:8918a71cdbe9 922 void pppChangeState(PppFsm *fsm, PppState newState)
Sergunb 0:8918a71cdbe9 923 {
Sergunb 0:8918a71cdbe9 924 #if (PPP_TRACE_LEVEL >= TRACE_LEVEL_INFO)
Sergunb 0:8918a71cdbe9 925 //PPP FSM states
Sergunb 0:8918a71cdbe9 926 static const char_t *stateLabel[] =
Sergunb 0:8918a71cdbe9 927 {
Sergunb 0:8918a71cdbe9 928 "INITIAL", //0
Sergunb 0:8918a71cdbe9 929 "STARTING", //1
Sergunb 0:8918a71cdbe9 930 "CLOSED", //2
Sergunb 0:8918a71cdbe9 931 "STOPPED", //3
Sergunb 0:8918a71cdbe9 932 "CLOSING", //4
Sergunb 0:8918a71cdbe9 933 "STOPPING", //5
Sergunb 0:8918a71cdbe9 934 "REQ_SENT", //6
Sergunb 0:8918a71cdbe9 935 "ACK_RCVD", //7
Sergunb 0:8918a71cdbe9 936 "ACK_SENT", //8
Sergunb 0:8918a71cdbe9 937 "OPENED" //9
Sergunb 0:8918a71cdbe9 938 };
Sergunb 0:8918a71cdbe9 939
Sergunb 0:8918a71cdbe9 940 //Sanity check
Sergunb 0:8918a71cdbe9 941 if(fsm->state < arraysize(stateLabel) && newState < arraysize(stateLabel))
Sergunb 0:8918a71cdbe9 942 {
Sergunb 0:8918a71cdbe9 943 //Debug message
Sergunb 0:8918a71cdbe9 944 TRACE_INFO("PPP FSM: %s (%u) -> %s (%u)\r\n", stateLabel[fsm->state],
Sergunb 0:8918a71cdbe9 945 fsm->state, stateLabel[newState], newState);
Sergunb 0:8918a71cdbe9 946 }
Sergunb 0:8918a71cdbe9 947 #endif
Sergunb 0:8918a71cdbe9 948
Sergunb 0:8918a71cdbe9 949 //Switch to the new state
Sergunb 0:8918a71cdbe9 950 fsm->state = newState;
Sergunb 0:8918a71cdbe9 951 }
Sergunb 0:8918a71cdbe9 952
Sergunb 0:8918a71cdbe9 953 #endif
Sergunb 0:8918a71cdbe9 954