James Sutton / Mbed 2 deprecated IBMIoTClientEthernetExample-MACfix-DebugFix

Dependencies:   C12832 EthernetInterface LM75B MMA7660 MQTT mbed-rtos mbed

Fork of IBMIoTClientEthernetExample-MACfix by Chris Styles

Committer:
samdanbury
Date:
Wed Aug 20 12:45:14 2014 +0000
Revision:
6:37b6d0d56190
Code completely changed to improve the structure, flow and memory usage of the application

Who changed what in which revision?

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