#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /*標準輸入輸出定義*/ #include /*標準函數庫定義*/ #include /*Unix 標準函數定義*/ #include /*檔控制定義*/ #include /*PPSIX 終端控制定義*/ #include /*錯誤號定義*/ #include #include #include #include #include #include "../../define.h" /**************************************************************************************/ /************This task will create Factory default confgiuration file *****************/ /***********and store it into mtdblock 10,11,12 ****************/ /**************************************************************************************/ int StoreLogMsg(const char *fmt, ...); #define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args) #define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args) #define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args) int StoreLogMsg(const char *fmt, ...) { char Buf[4096+256]; char buffer[4096]; time_t CurrentTime; struct tm *tm; va_list args; va_start(args, fmt); int rc = vsnprintf(buffer, sizeof(buffer), fmt, args); va_end(args); memset(Buf,0,sizeof(Buf)); CurrentTime = time(NULL); tm=localtime(&CurrentTime); sprintf(Buf,"echo \"%04d-%02d-%02d %02d:%02d:%02d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec, buffer, tm->tm_year+1900,tm->tm_mon+1); system(Buf); return rc; } int main(int argc,char *argv[]) { struct SysConfigData SysConfig; unsigned int i,Chk; unsigned char *ptr; int fd,wrd; ptr=malloc(sizeof(struct SysConfigData)); if(ptr==NULL) { #ifdef SystemLogMessage StoreLogMsg("[FactoryConfig]main: malloc for SysConfigData NG"); #endif return 0; } memset(ptr,0,sizeof(struct SysConfigData)); memset(&SysConfig,0,sizeof(struct SysConfigData)); //Set default configuration strcpy((char *)SysConfig.Eth0Interface.EthIpAddress, "192.168.1.10"); strcpy((char *)SysConfig.Eth0Interface.EthSubmaskAddress,"255.255.255.0"); strcpy((char *)SysConfig.Eth0Interface.EthGatewayAddress,"192.168.1.254"); strcpy((char *)SysConfig.Eth1Interface.EthIpAddress,"192.168.0.10"); strcpy((char *)SysConfig.Eth1Interface.EthSubmaskAddress,"255.255.255.0"); strcpy((char *)SysConfig.Eth1Interface.EthGatewayAddress,"192.168.0.254"); SysConfig.BackendConnTimeout=300; //300 seconds //copy default configuration to pointer memcpy(ptr,&SysConfig,sizeof(struct SysConfigData)); //calculate CRC Chk=0; for(i=0;i<(sizeof(struct SysConfigData)-4);i++) { Chk+=*(ptr+i); } SysConfig.Checksum=Chk; fd = open("/mnt/FactoryDefaultConfig.bin", O_RDWR|O_CREAT); if (fd < 0) { #ifdef SystemLogMessage StoreLogMsg("[FactoryConfig]main: open /mnt/FactoryDefaultConfig.bin NG"); #endif free(ptr); return 0; } wrd=write(fd, &SysConfig, sizeof(struct SysConfigData)); close(fd); if(wrd!=(sizeof(struct SysConfigData))) { #ifdef SystemLogMessage StoreLogMsg("[FactoryConfig]main: write /mnt/FactoryDefaultConfig.bin NG"); #endif free(ptr); return 0; } fd = open("/dev/mtdblock12", O_RDWR); if (fd < 0) { #ifdef SystemLogMessage StoreLogMsg("[FactoryConfig]main: open /dev/mtdblock12 NG"); #endif free(ptr); return 0; } wrd=write(fd, &SysConfig, sizeof(struct SysConfigData)); close(fd); if(wrd!=(sizeof(struct SysConfigData))) { #ifdef SystemLogMessage StoreLogMsg("[FactoryConfig]main: write /dev/mtdblock12 NG"); #endif free(ptr); return 0; } fd = open("/dev/mtdblock11", O_RDWR); if (fd < 0) { #ifdef SystemLogMessage StoreLogMsg("[FactoryConfig]main: open /dev/mtdblock11 NG"); #endif free(ptr); return 0; } wrd=write(fd, &SysConfig, sizeof(struct SysConfigData)); close(fd); if(wrd!=(sizeof(struct SysConfigData))) { #ifdef SystemLogMessage StoreLogMsg("[FactoryConfig]main: write /dev/mtdblock11 NG"); #endif free(ptr); return 0; } fd = open("/dev/mtdblock10", O_RDWR); if (fd < 0) { #ifdef SystemLogMessage StoreLogMsg("[FactoryConfig]main: open /dev/mtdblock10 NG"); #endif free(ptr); return 0; } wrd=write(fd, &SysConfig, sizeof(struct SysConfigData)); close(fd); if(wrd!=(sizeof(struct SysConfigData))) { #ifdef SystemLogMessage StoreLogMsg("[FactoryConfig]main: write /dev/mtdblock10 NG"); #endif free(ptr); return 0; } free(ptr); #ifdef SystemLogMessage StoreLogMsg("[FactoryConfig]main: FactoryConfig OK"); #endif }