Bonjour/Zerconf library

Dependencies:   mbed

Committer:
dirkx
Date:
Sat Aug 14 15:54:31 2010 +0000
Revision:
5:8e53abda9900
Parent:
0:355018f44c9f

        

Who changed what in which revision?

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