This short program illustrates how to use the DS130x_I2C library. My objective is to share the same RTC with Microchip 18F MCU.

Dependencies:   mbed DebugLibrary

Committer:
Yann
Date:
Fri Feb 11 10:17:20 2011 +0000
Revision:
1:995212d326ca
Parent:
0:f30e2135b0db
V0.0.0.2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Yann 0:f30e2135b0db 1 /*****************************************************************************
Yann 0:f30e2135b0db 2 * chap.h - Network Challenge Handshake Authentication Protocol header file.
Yann 0:f30e2135b0db 3 *
Yann 0:f30e2135b0db 4 * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc.
Yann 0:f30e2135b0db 5 * portions Copyright (c) 1998 Global Election Systems Inc.
Yann 0:f30e2135b0db 6 *
Yann 0:f30e2135b0db 7 * The authors hereby grant permission to use, copy, modify, distribute,
Yann 0:f30e2135b0db 8 * and license this software and its documentation for any purpose, provided
Yann 0:f30e2135b0db 9 * that existing copyright notices are retained in all copies and that this
Yann 0:f30e2135b0db 10 * notice and the following disclaimer are included verbatim in any
Yann 0:f30e2135b0db 11 * distributions. No written agreement, license, or royalty fee is required
Yann 0:f30e2135b0db 12 * for any of the authorized uses.
Yann 0:f30e2135b0db 13 *
Yann 0:f30e2135b0db 14 * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
Yann 0:f30e2135b0db 15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
Yann 0:f30e2135b0db 16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
Yann 0:f30e2135b0db 17 * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
Yann 0:f30e2135b0db 18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
Yann 0:f30e2135b0db 19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
Yann 0:f30e2135b0db 20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
Yann 0:f30e2135b0db 21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Yann 0:f30e2135b0db 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
Yann 0:f30e2135b0db 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Yann 0:f30e2135b0db 24 *
Yann 0:f30e2135b0db 25 ******************************************************************************
Yann 0:f30e2135b0db 26 * REVISION HISTORY
Yann 0:f30e2135b0db 27 *
Yann 0:f30e2135b0db 28 * 03-01-01 Marc Boucher <marc@mbsi.ca>
Yann 0:f30e2135b0db 29 * Ported to lwIP.
Yann 0:f30e2135b0db 30 * 97-12-03 Guy Lancaster <lancasterg@acm.org>, Global Election Systems Inc.
Yann 0:f30e2135b0db 31 * Original built from BSD network code.
Yann 0:f30e2135b0db 32 ******************************************************************************/
Yann 0:f30e2135b0db 33 /*
Yann 0:f30e2135b0db 34 * chap.h - Challenge Handshake Authentication Protocol definitions.
Yann 0:f30e2135b0db 35 *
Yann 0:f30e2135b0db 36 * Copyright (c) 1993 The Australian National University.
Yann 0:f30e2135b0db 37 * All rights reserved.
Yann 0:f30e2135b0db 38 *
Yann 0:f30e2135b0db 39 * Redistribution and use in source and binary forms are permitted
Yann 0:f30e2135b0db 40 * provided that the above copyright notice and this paragraph are
Yann 0:f30e2135b0db 41 * duplicated in all such forms and that any documentation,
Yann 0:f30e2135b0db 42 * advertising materials, and other materials related to such
Yann 0:f30e2135b0db 43 * distribution and use acknowledge that the software was developed
Yann 0:f30e2135b0db 44 * by the Australian National University. The name of the University
Yann 0:f30e2135b0db 45 * may not be used to endorse or promote products derived from this
Yann 0:f30e2135b0db 46 * software without specific prior written permission.
Yann 0:f30e2135b0db 47 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
Yann 0:f30e2135b0db 48 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
Yann 0:f30e2135b0db 49 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
Yann 0:f30e2135b0db 50 *
Yann 0:f30e2135b0db 51 * Copyright (c) 1991 Gregory M. Christy
Yann 0:f30e2135b0db 52 * All rights reserved.
Yann 0:f30e2135b0db 53 *
Yann 0:f30e2135b0db 54 * Redistribution and use in source and binary forms are permitted
Yann 0:f30e2135b0db 55 * provided that the above copyright notice and this paragraph are
Yann 0:f30e2135b0db 56 * duplicated in all such forms and that any documentation,
Yann 0:f30e2135b0db 57 * advertising materials, and other materials related to such
Yann 0:f30e2135b0db 58 * distribution and use acknowledge that the software was developed
Yann 0:f30e2135b0db 59 * by the author.
Yann 0:f30e2135b0db 60 *
Yann 0:f30e2135b0db 61 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
Yann 0:f30e2135b0db 62 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
Yann 0:f30e2135b0db 63 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
Yann 0:f30e2135b0db 64 *
Yann 0:f30e2135b0db 65 * $Id: chap.h,v 1.6 2010/01/24 13:19:34 goldsimon Exp $
Yann 0:f30e2135b0db 66 */
Yann 0:f30e2135b0db 67
Yann 0:f30e2135b0db 68 #ifndef CHAP_H
Yann 0:f30e2135b0db 69 #define CHAP_H
Yann 0:f30e2135b0db 70
Yann 0:f30e2135b0db 71 /* Code + ID + length */
Yann 0:f30e2135b0db 72 #define CHAP_HEADERLEN 4
Yann 0:f30e2135b0db 73
Yann 0:f30e2135b0db 74 /*
Yann 0:f30e2135b0db 75 * CHAP codes.
Yann 0:f30e2135b0db 76 */
Yann 0:f30e2135b0db 77
Yann 0:f30e2135b0db 78 #define CHAP_DIGEST_MD5 5 /* use MD5 algorithm */
Yann 0:f30e2135b0db 79 #define MD5_SIGNATURE_SIZE 16 /* 16 bytes in a MD5 message digest */
Yann 0:f30e2135b0db 80 #define CHAP_MICROSOFT 0x80 /* use Microsoft-compatible alg. */
Yann 0:f30e2135b0db 81 #define MS_CHAP_RESPONSE_LEN 49 /* Response length for MS-CHAP */
Yann 0:f30e2135b0db 82
Yann 0:f30e2135b0db 83 #define CHAP_CHALLENGE 1
Yann 0:f30e2135b0db 84 #define CHAP_RESPONSE 2
Yann 0:f30e2135b0db 85 #define CHAP_SUCCESS 3
Yann 0:f30e2135b0db 86 #define CHAP_FAILURE 4
Yann 0:f30e2135b0db 87
Yann 0:f30e2135b0db 88 /*
Yann 0:f30e2135b0db 89 * Challenge lengths (for challenges we send) and other limits.
Yann 0:f30e2135b0db 90 */
Yann 0:f30e2135b0db 91 #define MIN_CHALLENGE_LENGTH 32
Yann 0:f30e2135b0db 92 #define MAX_CHALLENGE_LENGTH 64
Yann 0:f30e2135b0db 93 #define MAX_RESPONSE_LENGTH 64 /* sufficient for MD5 or MS-CHAP */
Yann 0:f30e2135b0db 94
Yann 0:f30e2135b0db 95 /*
Yann 0:f30e2135b0db 96 * Each interface is described by a chap structure.
Yann 0:f30e2135b0db 97 */
Yann 0:f30e2135b0db 98
Yann 0:f30e2135b0db 99 typedef struct chap_state {
Yann 0:f30e2135b0db 100 int unit; /* Interface unit number */
Yann 0:f30e2135b0db 101 int clientstate; /* Client state */
Yann 0:f30e2135b0db 102 int serverstate; /* Server state */
Yann 0:f30e2135b0db 103 u_char challenge[MAX_CHALLENGE_LENGTH]; /* last challenge string sent */
Yann 0:f30e2135b0db 104 u_char chal_len; /* challenge length */
Yann 0:f30e2135b0db 105 u_char chal_id; /* ID of last challenge */
Yann 0:f30e2135b0db 106 u_char chal_type; /* hash algorithm for challenges */
Yann 0:f30e2135b0db 107 u_char id; /* Current id */
Yann 0:f30e2135b0db 108 char *chal_name; /* Our name to use with challenge */
Yann 0:f30e2135b0db 109 int chal_interval; /* Time until we challenge peer again */
Yann 0:f30e2135b0db 110 int timeouttime; /* Timeout time in seconds */
Yann 0:f30e2135b0db 111 int max_transmits; /* Maximum # of challenge transmissions */
Yann 0:f30e2135b0db 112 int chal_transmits; /* Number of transmissions of challenge */
Yann 0:f30e2135b0db 113 int resp_transmits; /* Number of transmissions of response */
Yann 0:f30e2135b0db 114 u_char response[MAX_RESPONSE_LENGTH]; /* Response to send */
Yann 0:f30e2135b0db 115 u_char resp_length; /* length of response */
Yann 0:f30e2135b0db 116 u_char resp_id; /* ID for response messages */
Yann 0:f30e2135b0db 117 u_char resp_type; /* hash algorithm for responses */
Yann 0:f30e2135b0db 118 char *resp_name; /* Our name to send with response */
Yann 0:f30e2135b0db 119 } chap_state;
Yann 0:f30e2135b0db 120
Yann 0:f30e2135b0db 121
Yann 0:f30e2135b0db 122 /*
Yann 0:f30e2135b0db 123 * Client (peer) states.
Yann 0:f30e2135b0db 124 */
Yann 0:f30e2135b0db 125 #define CHAPCS_INITIAL 0 /* Lower layer down, not opened */
Yann 0:f30e2135b0db 126 #define CHAPCS_CLOSED 1 /* Lower layer up, not opened */
Yann 0:f30e2135b0db 127 #define CHAPCS_PENDING 2 /* Auth us to peer when lower up */
Yann 0:f30e2135b0db 128 #define CHAPCS_LISTEN 3 /* Listening for a challenge */
Yann 0:f30e2135b0db 129 #define CHAPCS_RESPONSE 4 /* Sent response, waiting for status */
Yann 0:f30e2135b0db 130 #define CHAPCS_OPEN 5 /* We've received Success */
Yann 0:f30e2135b0db 131
Yann 0:f30e2135b0db 132 /*
Yann 0:f30e2135b0db 133 * Server (authenticator) states.
Yann 0:f30e2135b0db 134 */
Yann 0:f30e2135b0db 135 #define CHAPSS_INITIAL 0 /* Lower layer down, not opened */
Yann 0:f30e2135b0db 136 #define CHAPSS_CLOSED 1 /* Lower layer up, not opened */
Yann 0:f30e2135b0db 137 #define CHAPSS_PENDING 2 /* Auth peer when lower up */
Yann 0:f30e2135b0db 138 #define CHAPSS_INITIAL_CHAL 3 /* We've sent the first challenge */
Yann 0:f30e2135b0db 139 #define CHAPSS_OPEN 4 /* We've sent a Success msg */
Yann 0:f30e2135b0db 140 #define CHAPSS_RECHALLENGE 5 /* We've sent another challenge */
Yann 0:f30e2135b0db 141 #define CHAPSS_BADAUTH 6 /* We've sent a Failure msg */
Yann 0:f30e2135b0db 142
Yann 0:f30e2135b0db 143 extern chap_state chap[];
Yann 0:f30e2135b0db 144
Yann 0:f30e2135b0db 145 void ChapAuthWithPeer (int, char *, u_char);
Yann 0:f30e2135b0db 146 void ChapAuthPeer (int, char *, u_char);
Yann 0:f30e2135b0db 147
Yann 0:f30e2135b0db 148 extern struct protent chap_protent;
Yann 0:f30e2135b0db 149
Yann 0:f30e2135b0db 150 #endif /* CHAP_H */