confnet.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2001-2006 by egnite Software GmbH. All rights reserved.
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions
00006  * are met:
00007  *
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the copyright holders nor the names of
00014  *    contributors may be used to endorse or promote products derived
00015  *    from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS
00018  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00019  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00020  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE
00021  * SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00022  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00023  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
00024  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
00025  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00026  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
00027  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00028  * SUCH DAMAGE.
00029  *
00030  * For additional information see http://www.ethernut.de/
00031  *
00032  */
00033 
00034 /*
00035  * $Log: confnet.c,v $
00036  * Revision 1.8  2006/05/25 09:18:28  haraldkipp
00037  * API documentation updated and corrected.
00038  *
00039  * Revision 1.7  2006/01/23 17:26:18  haraldkipp
00040  * Platform independant routines added, which provide generic access to
00041  * non-volatile memory.
00042  *
00043  * Revision 1.6  2005/10/04 05:37:34  hwmaier
00044  * Removed preprocessor warning message for AT90CAN128 MCU as this device is now supported by avr-libc.
00045  *
00046  * Revision 1.5  2005/07/26 15:49:59  haraldkipp
00047  * Cygwin support added.
00048  *
00049  * Revision 1.4  2005/02/10 07:06:50  hwmaier
00050  * Changes to incorporate support for AT90CAN128 CPU
00051  *
00052  * Revision 1.3  2004/04/07 12:13:58  haraldkipp
00053  * Matthias Ringwald's *nix emulation added
00054  *
00055  * Revision 1.2  2003/07/13 19:03:06  haraldkipp
00056  * Make empty MAC broadcast.
00057  *
00058  * Revision 1.1.1.1  2003/05/09 14:41:27  haraldkipp
00059  * Initial using 3.2.1
00060  *
00061  * Revision 1.2  2003/05/06 18:22:48  harald
00062  * EEPROM corruption fixed
00063  *
00064  * Revision 1.1  2003/02/04 18:15:26  harald
00065  * Version 3 released
00066  *
00067  */
00068 
00069 #include <string.h>
00070 #include <arpa/inet.h>
00071 #include <sys/confnet.h>
00072 #include <dev/nvmem.h>
00073 
00078 
00085 CONFNET confnet;
00086 
00099 int NutNetLoadConfig(CONST char *name)
00100 {
00101 #if !defined(__linux__) && !defined(__APPLE__) && !defined(__CYGWIN__)
00102     if (NutNvMemLoad(CONFNET_EE_OFFSET, &confnet, sizeof(CONFNET))) {
00103         return -1;
00104     }
00105     if (confnet.cd_size == sizeof(CONFNET) && strcmp(confnet.cd_name, name) == 0) {
00106         return 0;
00107     }
00108 #endif
00109     memset(&confnet, 0, sizeof(confnet));
00110 
00111     /*
00112      * Set initial MAC address to broadcast. Thanks to Tomohiro
00113      * Haraikawa, who pointed out that all zeroes is occupied by
00114      * Xerox and should not be used.
00115      */
00116     memset(confnet.cdn_mac, 0xFF, sizeof(confnet.cdn_mac));
00117 
00118     return -1;
00119 }
00120 
00126 int NutNetSaveConfig(void)
00127 {
00128 #if !defined(__linux__) && !defined(__APPLE__) && !defined(__CYGWIN__)
00129     confnet.cd_size = sizeof(CONFNET);
00130     if (NutNvMemSave(CONFNET_EE_OFFSET, &confnet, sizeof(CONFNET))) {
00131         return -1;
00132     }
00133 #endif
00134     return 0;
00135 }
00136 

© 2000-2007 by egnite Software GmbH - visit http://www.ethernut.de/