Contains example code to connect the mbed LPC1768 or FRDM-K64F devices to the IBM Internet of Things Cloud service via ethernet.

Dependencies:   C12832 MQTT LM75B MMA7660

Dependents:   MFT_IoT_demo_USB400 IBM_RFID

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 * chap.h - Network Challenge Handshake Authentication Protocol header file.
samdanbury 6:37b6d0d56190 3 *
samdanbury 6:37b6d0d56190 4 * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc.
samdanbury 6:37b6d0d56190 5 * portions Copyright (c) 1998 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-12-03 Guy Lancaster <lancasterg@acm.org>, Global Election Systems Inc.
samdanbury 6:37b6d0d56190 31 * Original built from BSD network code.
samdanbury 6:37b6d0d56190 32 ******************************************************************************/
samdanbury 6:37b6d0d56190 33 /*
samdanbury 6:37b6d0d56190 34 * chap.h - Challenge Handshake Authentication Protocol definitions.
samdanbury 6:37b6d0d56190 35 *
samdanbury 6:37b6d0d56190 36 * Copyright (c) 1993 The Australian National 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 the Australian National University. The name of the University
samdanbury 6:37b6d0d56190 45 * may not be used to endorse or promote products derived from this
samdanbury 6:37b6d0d56190 46 * 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 * Copyright (c) 1991 Gregory M. Christy
samdanbury 6:37b6d0d56190 52 * All rights reserved.
samdanbury 6:37b6d0d56190 53 *
samdanbury 6:37b6d0d56190 54 * Redistribution and use in source and binary forms are permitted
samdanbury 6:37b6d0d56190 55 * provided that the above copyright notice and this paragraph are
samdanbury 6:37b6d0d56190 56 * duplicated in all such forms and that any documentation,
samdanbury 6:37b6d0d56190 57 * advertising materials, and other materials related to such
samdanbury 6:37b6d0d56190 58 * distribution and use acknowledge that the software was developed
samdanbury 6:37b6d0d56190 59 * by the author.
samdanbury 6:37b6d0d56190 60 *
samdanbury 6:37b6d0d56190 61 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
samdanbury 6:37b6d0d56190 62 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
samdanbury 6:37b6d0d56190 63 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
samdanbury 6:37b6d0d56190 64 *
samdanbury 6:37b6d0d56190 65 * $Id: chap.h,v 1.6 2010/01/24 13:19:34 goldsimon Exp $
samdanbury 6:37b6d0d56190 66 */
samdanbury 6:37b6d0d56190 67
samdanbury 6:37b6d0d56190 68 #ifndef CHAP_H
samdanbury 6:37b6d0d56190 69 #define CHAP_H
samdanbury 6:37b6d0d56190 70
samdanbury 6:37b6d0d56190 71 /* Code + ID + length */
samdanbury 6:37b6d0d56190 72 #define CHAP_HEADERLEN 4
samdanbury 6:37b6d0d56190 73
samdanbury 6:37b6d0d56190 74 /*
samdanbury 6:37b6d0d56190 75 * CHAP codes.
samdanbury 6:37b6d0d56190 76 */
samdanbury 6:37b6d0d56190 77
samdanbury 6:37b6d0d56190 78 #define CHAP_DIGEST_MD5 5 /* use MD5 algorithm */
samdanbury 6:37b6d0d56190 79 #define MD5_SIGNATURE_SIZE 16 /* 16 bytes in a MD5 message digest */
samdanbury 6:37b6d0d56190 80 #define CHAP_MICROSOFT 0x80 /* use Microsoft-compatible alg. */
samdanbury 6:37b6d0d56190 81 #define MS_CHAP_RESPONSE_LEN 49 /* Response length for MS-CHAP */
samdanbury 6:37b6d0d56190 82
samdanbury 6:37b6d0d56190 83 #define CHAP_CHALLENGE 1
samdanbury 6:37b6d0d56190 84 #define CHAP_RESPONSE 2
samdanbury 6:37b6d0d56190 85 #define CHAP_SUCCESS 3
samdanbury 6:37b6d0d56190 86 #define CHAP_FAILURE 4
samdanbury 6:37b6d0d56190 87
samdanbury 6:37b6d0d56190 88 /*
samdanbury 6:37b6d0d56190 89 * Challenge lengths (for challenges we send) and other limits.
samdanbury 6:37b6d0d56190 90 */
samdanbury 6:37b6d0d56190 91 #define MIN_CHALLENGE_LENGTH 32
samdanbury 6:37b6d0d56190 92 #define MAX_CHALLENGE_LENGTH 64
samdanbury 6:37b6d0d56190 93 #define MAX_RESPONSE_LENGTH 64 /* sufficient for MD5 or MS-CHAP */
samdanbury 6:37b6d0d56190 94
samdanbury 6:37b6d0d56190 95 /*
samdanbury 6:37b6d0d56190 96 * Each interface is described by a chap structure.
samdanbury 6:37b6d0d56190 97 */
samdanbury 6:37b6d0d56190 98
samdanbury 6:37b6d0d56190 99 typedef struct chap_state {
samdanbury 6:37b6d0d56190 100 int unit; /* Interface unit number */
samdanbury 6:37b6d0d56190 101 int clientstate; /* Client state */
samdanbury 6:37b6d0d56190 102 int serverstate; /* Server state */
samdanbury 6:37b6d0d56190 103 u_char challenge[MAX_CHALLENGE_LENGTH]; /* last challenge string sent */
samdanbury 6:37b6d0d56190 104 u_char chal_len; /* challenge length */
samdanbury 6:37b6d0d56190 105 u_char chal_id; /* ID of last challenge */
samdanbury 6:37b6d0d56190 106 u_char chal_type; /* hash algorithm for challenges */
samdanbury 6:37b6d0d56190 107 u_char id; /* Current id */
samdanbury 6:37b6d0d56190 108 char *chal_name; /* Our name to use with challenge */
samdanbury 6:37b6d0d56190 109 int chal_interval; /* Time until we challenge peer again */
samdanbury 6:37b6d0d56190 110 int timeouttime; /* Timeout time in seconds */
samdanbury 6:37b6d0d56190 111 int max_transmits; /* Maximum # of challenge transmissions */
samdanbury 6:37b6d0d56190 112 int chal_transmits; /* Number of transmissions of challenge */
samdanbury 6:37b6d0d56190 113 int resp_transmits; /* Number of transmissions of response */
samdanbury 6:37b6d0d56190 114 u_char response[MAX_RESPONSE_LENGTH]; /* Response to send */
samdanbury 6:37b6d0d56190 115 u_char resp_length; /* length of response */
samdanbury 6:37b6d0d56190 116 u_char resp_id; /* ID for response messages */
samdanbury 6:37b6d0d56190 117 u_char resp_type; /* hash algorithm for responses */
samdanbury 6:37b6d0d56190 118 char *resp_name; /* Our name to send with response */
samdanbury 6:37b6d0d56190 119 } chap_state;
samdanbury 6:37b6d0d56190 120
samdanbury 6:37b6d0d56190 121
samdanbury 6:37b6d0d56190 122 /*
samdanbury 6:37b6d0d56190 123 * Client (peer) states.
samdanbury 6:37b6d0d56190 124 */
samdanbury 6:37b6d0d56190 125 #define CHAPCS_INITIAL 0 /* Lower layer down, not opened */
samdanbury 6:37b6d0d56190 126 #define CHAPCS_CLOSED 1 /* Lower layer up, not opened */
samdanbury 6:37b6d0d56190 127 #define CHAPCS_PENDING 2 /* Auth us to peer when lower up */
samdanbury 6:37b6d0d56190 128 #define CHAPCS_LISTEN 3 /* Listening for a challenge */
samdanbury 6:37b6d0d56190 129 #define CHAPCS_RESPONSE 4 /* Sent response, waiting for status */
samdanbury 6:37b6d0d56190 130 #define CHAPCS_OPEN 5 /* We've received Success */
samdanbury 6:37b6d0d56190 131
samdanbury 6:37b6d0d56190 132 /*
samdanbury 6:37b6d0d56190 133 * Server (authenticator) states.
samdanbury 6:37b6d0d56190 134 */
samdanbury 6:37b6d0d56190 135 #define CHAPSS_INITIAL 0 /* Lower layer down, not opened */
samdanbury 6:37b6d0d56190 136 #define CHAPSS_CLOSED 1 /* Lower layer up, not opened */
samdanbury 6:37b6d0d56190 137 #define CHAPSS_PENDING 2 /* Auth peer when lower up */
samdanbury 6:37b6d0d56190 138 #define CHAPSS_INITIAL_CHAL 3 /* We've sent the first challenge */
samdanbury 6:37b6d0d56190 139 #define CHAPSS_OPEN 4 /* We've sent a Success msg */
samdanbury 6:37b6d0d56190 140 #define CHAPSS_RECHALLENGE 5 /* We've sent another challenge */
samdanbury 6:37b6d0d56190 141 #define CHAPSS_BADAUTH 6 /* We've sent a Failure msg */
samdanbury 6:37b6d0d56190 142
samdanbury 6:37b6d0d56190 143 extern chap_state chap[];
samdanbury 6:37b6d0d56190 144
samdanbury 6:37b6d0d56190 145 void ChapAuthWithPeer (int, char *, u_char);
samdanbury 6:37b6d0d56190 146 void ChapAuthPeer (int, char *, u_char);
samdanbury 6:37b6d0d56190 147
samdanbury 6:37b6d0d56190 148 extern struct protent chap_protent;
samdanbury 6:37b6d0d56190 149
samdanbury 6:37b6d0d56190 150 #endif /* CHAP_H */