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$ 00036 * Revision 1.9 2009/03/05 22:16:57 freckle 00037 * use __NUT_EMULATION instead of __APPLE__, __linux__, or __CYGWIN__ 00038 * 00039 * Revision 1.8 2006/05/25 09:18:28 haraldkipp 00040 * API documentation updated and corrected. 00041 * 00042 * Revision 1.7 2006/01/23 17:26:18 haraldkipp 00043 * Platform independant routines added, which provide generic access to 00044 * non-volatile memory. 00045 * 00046 * Revision 1.6 2005/10/04 05:37:34 hwmaier 00047 * Removed preprocessor warning message for AT90CAN128 MCU as this device is now supported by avr-libc. 00048 * 00049 * Revision 1.5 2005/07/26 15:49:59 haraldkipp 00050 * Cygwin support added. 00051 * 00052 * Revision 1.4 2005/02/10 07:06:50 hwmaier 00053 * Changes to incorporate support for AT90CAN128 CPU 00054 * 00055 * Revision 1.3 2004/04/07 12:13:58 haraldkipp 00056 * Matthias Ringwald's *nix emulation added 00057 * 00058 * Revision 1.2 2003/07/13 19:03:06 haraldkipp 00059 * Make empty MAC broadcast. 00060 * 00061 * Revision 1.1.1.1 2003/05/09 14:41:27 haraldkipp 00062 * Initial using 3.2.1 00063 * 00064 * Revision 1.2 2003/05/06 18:22:48 harald 00065 * EEPROM corruption fixed 00066 * 00067 * Revision 1.1 2003/02/04 18:15:26 harald 00068 * Version 3 released 00069 * 00070 */ 00071 00072 #include <string.h> 00073 #include <arpa/inet.h> 00074 #include <netinet/if_ether.h> 00075 #include <sys/confnet.h> 00076 #include <dev/nvmem.h> 00077 00082 00089 CONFNET confnet; 00090 00103 int NutNetLoadConfig(CONST char *name) 00104 { 00105 #ifdef CONFNET_HARDCODED 00106 00107 memset(&confnet, 0, sizeof(CONFNET)); 00108 memcpy(confnet.cdn_mac, ether_aton(CONFNET_VIRGIN_MAC), sizeof(confnet.cdn_mac)); 00109 confnet.cdn_cip_addr = inet_addr(CONFNET_VIRGIN_IP); 00110 confnet.cdn_ip_mask = inet_addr(CONFNET_VIRGIN_NETMASK); 00111 confnet.cdn_gateway = inet_addr(CONFNET_VIRGIN_GATE); 00112 00113 return 0; 00114 00115 #else /* CONFNET_HARDCODED */ 00116 00117 #ifndef __NUT_EMULATION__ 00118 if (NutNvMemLoad(CONFNET_EE_OFFSET, &confnet, sizeof(CONFNET))) { 00119 return -1; 00120 } 00121 if (confnet.cd_size == sizeof(CONFNET) && strcmp(confnet.cd_name, name) == 0) { 00122 return 0; 00123 } 00124 #endif 00125 memset(&confnet, 0, sizeof(confnet)); 00126 00127 /* 00128 * Set initial MAC address to broadcast. Thanks to Tomohiro 00129 * Haraikawa, who pointed out that all zeroes is occupied by 00130 * Xerox and should not be used. 00131 */ 00132 memset(confnet.cdn_mac, 0xFF, sizeof(confnet.cdn_mac)); 00133 00134 return -1; 00135 00136 #endif /* CONFNET_HARDCODED */ 00137 } 00138 00144 int NutNetSaveConfig(void) 00145 { 00146 #if !defined (__NUT_EMULATION__) && !defined (CONFNET_HARDCODED) 00147 confnet.cd_size = sizeof(CONFNET); 00148 if (NutNvMemSave(CONFNET_EE_OFFSET, &confnet, sizeof(CONFNET))) { 00149 return -1; 00150 } 00151 #endif 00152 return 0; 00153 } 00154