Geiger counter http://geigermaps.jp/Create/Tutorials/mbed_geiger/ja

Dependencies:   mbed

Committer:
okini3939
Date:
Fri Apr 15 16:51:30 2011 +0000
Revision:
0:5b2e60110d9b

        

Who changed what in which revision?

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