simple tester example >>> osc destination & receive
Fork of myOSC_test by
EthernetNetIf/LPC1768/lwip/netif/ppp/fsm.h@0:f76708a93fb3, 2011-10-15 (annotated)
- Committer:
- mbedalvaro
- Date:
- Sat Oct 15 14:15:55 2011 +0000
- Revision:
- 0:f76708a93fb3
First working test of this simple OSC library.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbedalvaro | 0:f76708a93fb3 | 1 | /***************************************************************************** |
mbedalvaro | 0:f76708a93fb3 | 2 | * fsm.h - Network Control Protocol Finite State Machine header file. |
mbedalvaro | 0:f76708a93fb3 | 3 | * |
mbedalvaro | 0:f76708a93fb3 | 4 | * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc. |
mbedalvaro | 0:f76708a93fb3 | 5 | * Copyright (c) 1997 Global Election Systems Inc. |
mbedalvaro | 0:f76708a93fb3 | 6 | * |
mbedalvaro | 0:f76708a93fb3 | 7 | * The authors hereby grant permission to use, copy, modify, distribute, |
mbedalvaro | 0:f76708a93fb3 | 8 | * and license this software and its documentation for any purpose, provided |
mbedalvaro | 0:f76708a93fb3 | 9 | * that existing copyright notices are retained in all copies and that this |
mbedalvaro | 0:f76708a93fb3 | 10 | * notice and the following disclaimer are included verbatim in any |
mbedalvaro | 0:f76708a93fb3 | 11 | * distributions. No written agreement, license, or royalty fee is required |
mbedalvaro | 0:f76708a93fb3 | 12 | * for any of the authorized uses. |
mbedalvaro | 0:f76708a93fb3 | 13 | * |
mbedalvaro | 0:f76708a93fb3 | 14 | * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR |
mbedalvaro | 0:f76708a93fb3 | 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
mbedalvaro | 0:f76708a93fb3 | 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
mbedalvaro | 0:f76708a93fb3 | 17 | * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
mbedalvaro | 0:f76708a93fb3 | 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
mbedalvaro | 0:f76708a93fb3 | 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
mbedalvaro | 0:f76708a93fb3 | 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
mbedalvaro | 0:f76708a93fb3 | 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
mbedalvaro | 0:f76708a93fb3 | 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
mbedalvaro | 0:f76708a93fb3 | 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbedalvaro | 0:f76708a93fb3 | 24 | * |
mbedalvaro | 0:f76708a93fb3 | 25 | ****************************************************************************** |
mbedalvaro | 0:f76708a93fb3 | 26 | * REVISION HISTORY |
mbedalvaro | 0:f76708a93fb3 | 27 | * |
mbedalvaro | 0:f76708a93fb3 | 28 | * 03-01-01 Marc Boucher <marc@mbsi.ca> |
mbedalvaro | 0:f76708a93fb3 | 29 | * Ported to lwIP. |
mbedalvaro | 0:f76708a93fb3 | 30 | * 97-11-05 Guy Lancaster <glanca@gesn.com>, Global Election Systems Inc. |
mbedalvaro | 0:f76708a93fb3 | 31 | * Original based on BSD code. |
mbedalvaro | 0:f76708a93fb3 | 32 | *****************************************************************************/ |
mbedalvaro | 0:f76708a93fb3 | 33 | /* |
mbedalvaro | 0:f76708a93fb3 | 34 | * fsm.h - {Link, IP} Control Protocol Finite State Machine definitions. |
mbedalvaro | 0:f76708a93fb3 | 35 | * |
mbedalvaro | 0:f76708a93fb3 | 36 | * Copyright (c) 1989 Carnegie Mellon University. |
mbedalvaro | 0:f76708a93fb3 | 37 | * All rights reserved. |
mbedalvaro | 0:f76708a93fb3 | 38 | * |
mbedalvaro | 0:f76708a93fb3 | 39 | * Redistribution and use in source and binary forms are permitted |
mbedalvaro | 0:f76708a93fb3 | 40 | * provided that the above copyright notice and this paragraph are |
mbedalvaro | 0:f76708a93fb3 | 41 | * duplicated in all such forms and that any documentation, |
mbedalvaro | 0:f76708a93fb3 | 42 | * advertising materials, and other materials related to such |
mbedalvaro | 0:f76708a93fb3 | 43 | * distribution and use acknowledge that the software was developed |
mbedalvaro | 0:f76708a93fb3 | 44 | * by Carnegie Mellon University. The name of the |
mbedalvaro | 0:f76708a93fb3 | 45 | * University may not be used to endorse or promote products derived |
mbedalvaro | 0:f76708a93fb3 | 46 | * from this software without specific prior written permission. |
mbedalvaro | 0:f76708a93fb3 | 47 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR |
mbedalvaro | 0:f76708a93fb3 | 48 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
mbedalvaro | 0:f76708a93fb3 | 49 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
mbedalvaro | 0:f76708a93fb3 | 50 | * |
mbedalvaro | 0:f76708a93fb3 | 51 | * $Id: fsm.h,v 1.5 2009/12/31 17:08:08 goldsimon Exp $ |
mbedalvaro | 0:f76708a93fb3 | 52 | */ |
mbedalvaro | 0:f76708a93fb3 | 53 | |
mbedalvaro | 0:f76708a93fb3 | 54 | #ifndef FSM_H |
mbedalvaro | 0:f76708a93fb3 | 55 | #define FSM_H |
mbedalvaro | 0:f76708a93fb3 | 56 | |
mbedalvaro | 0:f76708a93fb3 | 57 | /* |
mbedalvaro | 0:f76708a93fb3 | 58 | * LCP Packet header = Code, id, length. |
mbedalvaro | 0:f76708a93fb3 | 59 | */ |
mbedalvaro | 0:f76708a93fb3 | 60 | #define HEADERLEN (sizeof (u_char) + sizeof (u_char) + sizeof (u_short)) |
mbedalvaro | 0:f76708a93fb3 | 61 | |
mbedalvaro | 0:f76708a93fb3 | 62 | |
mbedalvaro | 0:f76708a93fb3 | 63 | /* |
mbedalvaro | 0:f76708a93fb3 | 64 | * CP (LCP, IPCP, etc.) codes. |
mbedalvaro | 0:f76708a93fb3 | 65 | */ |
mbedalvaro | 0:f76708a93fb3 | 66 | #define CONFREQ 1 /* Configuration Request */ |
mbedalvaro | 0:f76708a93fb3 | 67 | #define CONFACK 2 /* Configuration Ack */ |
mbedalvaro | 0:f76708a93fb3 | 68 | #define CONFNAK 3 /* Configuration Nak */ |
mbedalvaro | 0:f76708a93fb3 | 69 | #define CONFREJ 4 /* Configuration Reject */ |
mbedalvaro | 0:f76708a93fb3 | 70 | #define TERMREQ 5 /* Termination Request */ |
mbedalvaro | 0:f76708a93fb3 | 71 | #define TERMACK 6 /* Termination Ack */ |
mbedalvaro | 0:f76708a93fb3 | 72 | #define CODEREJ 7 /* Code Reject */ |
mbedalvaro | 0:f76708a93fb3 | 73 | |
mbedalvaro | 0:f76708a93fb3 | 74 | |
mbedalvaro | 0:f76708a93fb3 | 75 | /* |
mbedalvaro | 0:f76708a93fb3 | 76 | * Each FSM is described by an fsm structure and fsm callbacks. |
mbedalvaro | 0:f76708a93fb3 | 77 | */ |
mbedalvaro | 0:f76708a93fb3 | 78 | typedef struct fsm { |
mbedalvaro | 0:f76708a93fb3 | 79 | int unit; /* Interface unit number */ |
mbedalvaro | 0:f76708a93fb3 | 80 | u_short protocol; /* Data Link Layer Protocol field value */ |
mbedalvaro | 0:f76708a93fb3 | 81 | int state; /* State */ |
mbedalvaro | 0:f76708a93fb3 | 82 | int flags; /* Contains option bits */ |
mbedalvaro | 0:f76708a93fb3 | 83 | u_char id; /* Current id */ |
mbedalvaro | 0:f76708a93fb3 | 84 | u_char reqid; /* Current request id */ |
mbedalvaro | 0:f76708a93fb3 | 85 | u_char seen_ack; /* Have received valid Ack/Nak/Rej to Req */ |
mbedalvaro | 0:f76708a93fb3 | 86 | int timeouttime; /* Timeout time in milliseconds */ |
mbedalvaro | 0:f76708a93fb3 | 87 | int maxconfreqtransmits; /* Maximum Configure-Request transmissions */ |
mbedalvaro | 0:f76708a93fb3 | 88 | int retransmits; /* Number of retransmissions left */ |
mbedalvaro | 0:f76708a93fb3 | 89 | int maxtermtransmits; /* Maximum Terminate-Request transmissions */ |
mbedalvaro | 0:f76708a93fb3 | 90 | int nakloops; /* Number of nak loops since last ack */ |
mbedalvaro | 0:f76708a93fb3 | 91 | int maxnakloops; /* Maximum number of nak loops tolerated */ |
mbedalvaro | 0:f76708a93fb3 | 92 | struct fsm_callbacks* callbacks; /* Callback routines */ |
mbedalvaro | 0:f76708a93fb3 | 93 | char* term_reason; /* Reason for closing protocol */ |
mbedalvaro | 0:f76708a93fb3 | 94 | int term_reason_len; /* Length of term_reason */ |
mbedalvaro | 0:f76708a93fb3 | 95 | } fsm; |
mbedalvaro | 0:f76708a93fb3 | 96 | |
mbedalvaro | 0:f76708a93fb3 | 97 | |
mbedalvaro | 0:f76708a93fb3 | 98 | typedef struct fsm_callbacks { |
mbedalvaro | 0:f76708a93fb3 | 99 | void (*resetci)(fsm*); /* Reset our Configuration Information */ |
mbedalvaro | 0:f76708a93fb3 | 100 | int (*cilen)(fsm*); /* Length of our Configuration Information */ |
mbedalvaro | 0:f76708a93fb3 | 101 | void (*addci)(fsm*, u_char*, int*); /* Add our Configuration Information */ |
mbedalvaro | 0:f76708a93fb3 | 102 | int (*ackci)(fsm*, u_char*, int); /* ACK our Configuration Information */ |
mbedalvaro | 0:f76708a93fb3 | 103 | int (*nakci)(fsm*, u_char*, int); /* NAK our Configuration Information */ |
mbedalvaro | 0:f76708a93fb3 | 104 | int (*rejci)(fsm*, u_char*, int); /* Reject our Configuration Information */ |
mbedalvaro | 0:f76708a93fb3 | 105 | int (*reqci)(fsm*, u_char*, int*, int); /* Request peer's Configuration Information */ |
mbedalvaro | 0:f76708a93fb3 | 106 | void (*up)(fsm*); /* Called when fsm reaches LS_OPENED state */ |
mbedalvaro | 0:f76708a93fb3 | 107 | void (*down)(fsm*); /* Called when fsm leaves LS_OPENED state */ |
mbedalvaro | 0:f76708a93fb3 | 108 | void (*starting)(fsm*); /* Called when we want the lower layer */ |
mbedalvaro | 0:f76708a93fb3 | 109 | void (*finished)(fsm*); /* Called when we don't want the lower layer */ |
mbedalvaro | 0:f76708a93fb3 | 110 | void (*protreject)(int); /* Called when Protocol-Reject received */ |
mbedalvaro | 0:f76708a93fb3 | 111 | void (*retransmit)(fsm*); /* Retransmission is necessary */ |
mbedalvaro | 0:f76708a93fb3 | 112 | int (*extcode)(fsm*, int, u_char, u_char*, int); /* Called when unknown code received */ |
mbedalvaro | 0:f76708a93fb3 | 113 | char *proto_name; /* String name for protocol (for messages) */ |
mbedalvaro | 0:f76708a93fb3 | 114 | } fsm_callbacks; |
mbedalvaro | 0:f76708a93fb3 | 115 | |
mbedalvaro | 0:f76708a93fb3 | 116 | |
mbedalvaro | 0:f76708a93fb3 | 117 | /* |
mbedalvaro | 0:f76708a93fb3 | 118 | * Link states. |
mbedalvaro | 0:f76708a93fb3 | 119 | */ |
mbedalvaro | 0:f76708a93fb3 | 120 | #define LS_INITIAL 0 /* Down, hasn't been opened */ |
mbedalvaro | 0:f76708a93fb3 | 121 | #define LS_STARTING 1 /* Down, been opened */ |
mbedalvaro | 0:f76708a93fb3 | 122 | #define LS_CLOSED 2 /* Up, hasn't been opened */ |
mbedalvaro | 0:f76708a93fb3 | 123 | #define LS_STOPPED 3 /* Open, waiting for down event */ |
mbedalvaro | 0:f76708a93fb3 | 124 | #define LS_CLOSING 4 /* Terminating the connection, not open */ |
mbedalvaro | 0:f76708a93fb3 | 125 | #define LS_STOPPING 5 /* Terminating, but open */ |
mbedalvaro | 0:f76708a93fb3 | 126 | #define LS_REQSENT 6 /* We've sent a Config Request */ |
mbedalvaro | 0:f76708a93fb3 | 127 | #define LS_ACKRCVD 7 /* We've received a Config Ack */ |
mbedalvaro | 0:f76708a93fb3 | 128 | #define LS_ACKSENT 8 /* We've sent a Config Ack */ |
mbedalvaro | 0:f76708a93fb3 | 129 | #define LS_OPENED 9 /* Connection available */ |
mbedalvaro | 0:f76708a93fb3 | 130 | |
mbedalvaro | 0:f76708a93fb3 | 131 | /* |
mbedalvaro | 0:f76708a93fb3 | 132 | * Flags - indicate options controlling FSM operation |
mbedalvaro | 0:f76708a93fb3 | 133 | */ |
mbedalvaro | 0:f76708a93fb3 | 134 | #define OPT_PASSIVE 1 /* Don't die if we don't get a response */ |
mbedalvaro | 0:f76708a93fb3 | 135 | #define OPT_RESTART 2 /* Treat 2nd OPEN as DOWN, UP */ |
mbedalvaro | 0:f76708a93fb3 | 136 | #define OPT_SILENT 4 /* Wait for peer to speak first */ |
mbedalvaro | 0:f76708a93fb3 | 137 | |
mbedalvaro | 0:f76708a93fb3 | 138 | |
mbedalvaro | 0:f76708a93fb3 | 139 | /* |
mbedalvaro | 0:f76708a93fb3 | 140 | * Prototypes |
mbedalvaro | 0:f76708a93fb3 | 141 | */ |
mbedalvaro | 0:f76708a93fb3 | 142 | void fsm_init (fsm*); |
mbedalvaro | 0:f76708a93fb3 | 143 | void fsm_lowerup (fsm*); |
mbedalvaro | 0:f76708a93fb3 | 144 | void fsm_lowerdown (fsm*); |
mbedalvaro | 0:f76708a93fb3 | 145 | void fsm_open (fsm*); |
mbedalvaro | 0:f76708a93fb3 | 146 | void fsm_close (fsm*, char*); |
mbedalvaro | 0:f76708a93fb3 | 147 | void fsm_input (fsm*, u_char*, int); |
mbedalvaro | 0:f76708a93fb3 | 148 | void fsm_protreject (fsm*); |
mbedalvaro | 0:f76708a93fb3 | 149 | void fsm_sdata (fsm*, u_char, u_char, u_char*, int); |
mbedalvaro | 0:f76708a93fb3 | 150 | |
mbedalvaro | 0:f76708a93fb3 | 151 | |
mbedalvaro | 0:f76708a93fb3 | 152 | /* |
mbedalvaro | 0:f76708a93fb3 | 153 | * Variables |
mbedalvaro | 0:f76708a93fb3 | 154 | */ |
mbedalvaro | 0:f76708a93fb3 | 155 | extern int peer_mru[]; /* currently negotiated peer MRU (per unit) */ |
mbedalvaro | 0:f76708a93fb3 | 156 | |
mbedalvaro | 0:f76708a93fb3 | 157 | #endif /* FSM_H */ |