123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- #include <sys/time.h>
- #include <sys/timeb.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <sys/types.h>
- #include <sys/ioctl.h>
- #include <sys/socket.h>
- #include <sys/ipc.h>
- #include <sys/shm.h>
- #include <sys/shm.h>
- #include <sys/mman.h>
- #include <linux/can.h>
- #include <linux/can/raw.h>
- #include <linux/wireless.h>
- #include <arpa/inet.h>
- #include <netinet/in.h>
- #include <unistd.h>
- #include <stdarg.h>
- #include <stdio.h> /*標準輸入輸出定義*/
- #include <stdlib.h> /*標準函數庫定義*/
- #include <unistd.h> /*Unix 標準函數定義*/
- #include <fcntl.h> /*檔控制定義*/
- #include <termios.h> /*PPSIX 終端控制定義*/
- #include <errno.h> /*錯誤號定義*/
- #include <errno.h>
- #include <string.h>
- #include <time.h>
- #include <ctype.h>
- #include <ifaddrs.h>
- #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
- }
|