+/*********************************************************************************\r
+ * PROJECT: MiMic\r
+ * --------------------------------------------------------------------------------\r
+ *\r
+ * This file is part of MiMic\r
+ * Copyright (C)2011 Ryo Iizuka\r
+ *\r
+ * MiMic is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU Lesser General Public License as published\r
+ * by the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Lesser General Public License\r
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
+ *\r
+ * For further information please contact.\r
+ * http://nyatla.jp/\r
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>\r
+ *\r
+ *********************************************************************************/\r
#include "NyLPC_cNetConfig.h"\r
#include "../flash/NyLPC_cMiMicConfiglation.h"\r
-/**\r
- * IPアドレスはネットワークオーダーで格納する。\r
- * 構造体は4バイトアライメントであること。\r
- */\r
-struct TNetConfigMemMap\r
-{\r
- /**\r
- * ROM焼検出用。0xFFFFFFFFを書く\r
- */\r
- NyLPC_TUInt32 fast_boot;\r
- NyLPC_TUInt16 version;\r
- NyLPC_TUInt16 interface_type;\r
- NyLPC_TUInt32 mac_00_01_02_03;\r
- NyLPC_TUInt32 mac_04_05_xx_xx;\r
- /** network order ip address*/\r
- NyLPC_TUInt32 ipv4_addr_net;\r
- /** network order mask value*/\r
- NyLPC_TUInt32 ipv4_mask_net;\r
- /** network order route*/\r
- NyLPC_TUInt32 ipv4_drut_net;\r
-// NyLPC_TUInt32 ipv4_port;\r
-// NyLPC_TUInt32 accessmode;\r
-};\r
\r
-static void loadFromMemory(NyLPC_TcNetConfig_t* i_inst);\r
\r
-void NyLPC_cNetConfig_initialize(NyLPC_TcNetConfig_t* i_inst)\r
-{\r
- loadFromMemory(i_inst);\r
+static void update(NyLPC_TcNetConfig_t* i_inst,const struct NyLPC_TMiMicConfigulation* pdata);\r
\r
\r
+void NyLPC_cNetConfig_initialize(NyLPC_TcNetConfig_t* i_inst,NyLPC_TBool i_is_factory_default)\r
+{\r
+ if(i_is_factory_default)\r
+ {\r
+ update(i_inst,NyLPC_cMiMicConfiglation_loadFactoryDefault());\r
+ }else{\r
+ update(i_inst,NyLPC_cMiMicConfiglation_loadFromFlash());\r
+ }\r
}\r
\r
+\r
/**\r
* ユーザコンフィギュレーションを更新する。\r
* この関数をコールするときは、割込/FreeRTOSを一時停止すること。\r
/*\r
NyLPC_TBool NyLPC_cNetConfig_saveToOnchipFlash(NyLPC_TcNetConfig_t* i_inst)\r
{\r
- NyLPC_TUInt8* pdata;\r
- NyLPC_TcOnchipFlashWriter_t s;\r
- struct TNetConfigMemMap tmp;\r
- NyLPC_cOnchipFlashWriter_initialize(&s);\r
- //書込みデータを作成\r
- tmp.fast_boot=0xffffffff;\r
- tmp.version =i_inst->version;\r
- tmp.interface_type=NyLPC_cNetConfig_INTERFACE_TYPE_ETHERNET;\r
- pdata=i_inst->interface_setting.ethernet.eth_mac.addr;\r
- tmp.mac_00_01_02_03=(((NyLPC_TUInt32)pdata[0])<<24)|(((NyLPC_TUInt32)pdata[1])<<16)|(((NyLPC_TUInt32)pdata[2])<<8)|(((NyLPC_TUInt32)pdata[3])<<0);\r
- tmp.mac_04_05_xx_xx=(((NyLPC_TUInt32)pdata[4])<<24)|(((NyLPC_TUInt32)pdata[5])<<16);\r
- tmp.ipv4_addr_net=i_inst->interface_setting.ethernet.ip_addr.v;\r
- tmp.ipv4_mask_net=i_inst->interface_setting.ethernet.netmask.v;\r
- tmp.ipv4_drut_net=i_inst->interface_setting.ethernet.dr_addr.v;\r
+ NyLPC_TUInt8* pdata;\r
+ NyLPC_TcOnchipFlashWriter_t s;\r
+ struct TNetConfigMemMap tmp;\r
+ NyLPC_cOnchipFlashWriter_initialize(&s);\r
+ //書込みデータを作成\r
+ tmp.fast_boot=0xffffffff;\r
+ tmp.version =i_inst->version;\r
+ tmp.interface_type=NyLPC_cNetConfig_INTERFACE_TYPE_ETHERNET;\r
+ pdata=i_inst->interface_setting.ethernet.eth_mac.addr;\r
+ tmp.mac_00_01_02_03=(((NyLPC_TUInt32)pdata[0])<<24)|(((NyLPC_TUInt32)pdata[1])<<16)|(((NyLPC_TUInt32)pdata[2])<<8)|(((NyLPC_TUInt32)pdata[3])<<0);\r
+ tmp.mac_04_05_xx_xx=(((NyLPC_TUInt32)pdata[4])<<24)|(((NyLPC_TUInt32)pdata[5])<<16);\r
+ tmp.ipv4_addr_net=i_inst->interface_setting.ethernet.ip_addr.v;\r
+ tmp.ipv4_mask_net=i_inst->interface_setting.ethernet.netmask.v;\r
+ tmp.ipv4_drut_net=i_inst->interface_setting.ethernet.dr_addr.v;\r
\r
- //イレース\r
- if(!NyLPC_cOnchipFlashWriter_elase(&s,MIMIC_CONFIGLATION_FLASH_SECTOR,MIMIC_CONFIGLATION_FLASH_SECTOR)){\r
- NyLPC_OnErrorGoto(Error);\r
- }\r
- //コンフィギュレーションを書き込む。\r
- if(!NyLPC_cOnchipFlashWriter_writeSector(&s,MIMIC_CONFIGLATION_FLASH_SECTOR,0x00000000,&tmp,sizeof(struct TNetConfigMemMap))){\r
- NyLPC_OnErrorGoto(Error);\r
- }\r
- //ユーザコンフィギュレーションをONにする。\r
- if(setUserConfigulation()){\r
- NyLPC_OnErrorGoto(Error);\r
- }\r
- NyLPC_cOnchipFlashWriter_finalize(&s);\r
- return NyLPC_TBool_TRUE;\r
+ //イレース\r
+ if(!NyLPC_cOnchipFlashWriter_elase(&s,MIMIC_CONFIGLATION_FLASH_SECTOR,MIMIC_CONFIGLATION_FLASH_SECTOR)){\r
+ NyLPC_OnErrorGoto(Error);\r
+ }\r
+ //コンフィギュレーションを書き込む。\r
+ if(!NyLPC_cOnchipFlashWriter_writeSector(&s,MIMIC_CONFIGLATION_FLASH_SECTOR,0x00000000,&tmp,sizeof(struct TNetConfigMemMap))){\r
+ NyLPC_OnErrorGoto(Error);\r
+ }\r
+ //ユーザコンフィギュレーションをONにする。\r
+ if(setUserConfigulation()){\r
+ NyLPC_OnErrorGoto(Error);\r
+ }\r
+ NyLPC_cOnchipFlashWriter_finalize(&s);\r
+ return NyLPC_TBool_TRUE;\r
Error:\r
- NyLPC_cOnchipFlashWriter_finalize(&s);\r
- return NyLPC_TBool_FALSE;\r
+ NyLPC_cOnchipFlashWriter_finalize(&s);\r
+ return NyLPC_TBool_FALSE;\r
}\r
*/\r
\r
\r
-\r
-static void loadFromMemory(NyLPC_TcNetConfig_t* i_inst)\r
+/**\r
+ * ETHERNET NETWORKのみなら 1480\r
+ * インターネットを通過するなら 1400程度が妥当。\r
+ */\r
+//#define ETHERNET_FRAME_LEN 1480\r
+#define ETHERNET_FRAME_LEN 1400\r
+static void update(NyLPC_TcNetConfig_t* i_inst,const struct NyLPC_TMiMicConfigulation* pdata)\r
{\r
- const struct NyLPC_TMimicConfigulation* pdata=NyLPC_cMiMicConfiglation_loadMiMicConfigulation();\r
- NyLPC_TUInt8* ptr;\r
- //値の読み出し\r
- i_inst->version=1;\r
- i_inst->interface_type=NyLPC_cNetConfig_INTERFACE_TYPE_ETHERNET;\r
- ptr=i_inst->interface_setting.ethernet.eth_mac.addr;\r
- ptr[0]=(NyLPC_TUInt8)((pdata->mac_00_01_02_03>>24)&0xff);\r
- ptr[1]=(NyLPC_TUInt8)((pdata->mac_00_01_02_03>>16)&0xff);\r
- ptr[2]=(NyLPC_TUInt8)((pdata->mac_00_01_02_03>> 8)&0xff);\r
- ptr[3]=(NyLPC_TUInt8)((pdata->mac_00_01_02_03>> 0)&0xff);\r
- ptr[4]=(NyLPC_TUInt8)((pdata->mac_04_05_xx_xx>>24)&0xff);\r
- ptr[5]=(NyLPC_TUInt8)((pdata->mac_04_05_xx_xx>>16)&0xff);\r
- i_inst->interface_setting.ethernet.ip_addr.v=NyLPC_htonl(pdata->ipv4_addr_net);\r
- i_inst->interface_setting.ethernet.netmask.v=NyLPC_htonl(pdata->ipv4_mask_net);\r
- i_inst->interface_setting.ethernet.dr_addr.v=NyLPC_htonl(pdata->ipv4_drut_net);\r
- return;\r
+ struct NyLPC_TEthAddr ea;\r
+ struct NyLPC_TIPv4Addr ip,mask,drt;\r
+ //値の読み出し\r
+ ea.addr[0]=(NyLPC_TUInt8)((pdata->mac_00_01_02_03>>24)&0xff);\r
+ ea.addr[1]=(NyLPC_TUInt8)((pdata->mac_00_01_02_03>>16)&0xff);\r
+ ea.addr[2]=(NyLPC_TUInt8)((pdata->mac_00_01_02_03>> 8)&0xff);\r
+ ea.addr[3]=(NyLPC_TUInt8)((pdata->mac_00_01_02_03>> 0)&0xff);\r
+ ea.addr[4]=(NyLPC_TUInt8)((pdata->mac_04_05_xx_xx>>24)&0xff);\r
+ ea.addr[5]=(NyLPC_TUInt8)((pdata->mac_04_05_xx_xx>>16)&0xff);\r
+ ip.v=NyLPC_htonl(pdata->ipv4_addr_net);\r
+ mask.v=NyLPC_htonl(pdata->ipv4_mask_net);\r
+ drt.v=NyLPC_htonl(pdata->ipv4_drut_net);\r
+ strcpy(i_inst->hostname,pdata->hostname);\r
+ NyLPC_cIPv4Config_initialzeForEthernet(&i_inst->super,&ea,ETHERNET_FRAME_LEN);\r
+ NyLPC_cIPv4Config_setDefaultRoute(&i_inst->super,&drt);\r
+ NyLPC_cIPv4Config_setIp(&i_inst->super,&ip,&mask);\r
+ i_inst->services.flags=pdata->srv_flags;\r
+ i_inst->services.http_port=pdata->http_port;\r
+ i_inst->tcp_mode=pdata->ipv4_flags;\r
+ return;\r
}\r
\r
\r