Xbee test 2

Dependencies:   XBee mbed

Committer:
takashiyamanoue
Date:
Sat Jul 21 04:08:27 2012 +0000
Revision:
0:ffac63d6a7f0
xbee test 2

Who changed what in which revision?

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