int set_nv_params(void * pio) { NV_FILE * fp; /* file with nvram data */ struct nvparm_format * curr_format = nv_formats; fp = nv_fopen(nvfilename, "w"); if (!fp) { ns_printf(pio, "Unable to open NV Parameters file \"%s\"\n", nvfilename); return -1; } while (curr_format) { curr_format->setfunc(fp); curr_format = curr_format->next_format; } nv_fclose(fp); #ifdef HT_SYNCDEV if (nv_writeflash) /* make sure pointer is set */ nv_writeflash(); /* call optional per-port flash write routine */ #endif return 0; }
int get_nv_params() { int e; NV_FILE * fp; /* Just in case Demo Applications want to parse webport.nv again */ netidx = -1; /* reset index of nets[] to configure */ /* invoke the generic parm reader to get TCP/IP system parameters */ e = get_file_parms(nvfilename, nv_formats, &line); if (e == ENP_NOFILE) { printf("Creating sample file\n"); fp = nv_fopen(nvfilename, "w+"); if (fp) { if (set_nv_defaults) /* see if app wants to init defaults */ set_nv_defaults(); set_nv_params(NULL); /* write defaults to new file */ /* now try again from the flash file we just set up */ e = get_file_parms(nvfilename, nv_formats, &line); } else printf("Can't create sample file either.\n"); } return(e); }
int iniche_create_log(log_data_t **p, int log_level, char *fname, void *pio) { int i; /* This routine assumes a NULL pointer is passed */ if(*p == NULL) { *p = (log_data_t *) LOG_MALLOC(sizeof(log_data_t)); if(*p == NULL) { return(-1); } memset(*p, 0, sizeof(log_data_t)); } else { for(i = 0; i < LOG_TYPE_MAX_NUM; i++) { (*p)->log_counts[i] = 0; } } if((log_level >= LOG_TYPE_NONE) && (log_level < LOG_TYPE_MAX_NUM)) { (*p)->log_level = log_level; } else { (*p)->log_level = DEFAULT_LOG_LEVEL; } #ifdef USE_LOGFILE if(fname) { strcpy((*p)->log_fname, fname); } else { strcpy((*p)->log_fname, LOG_FILE_DEFAULT); } if((*p)->log_fp) { nv_fclose((*p)->log_fp); (*p)->log_fp = NULL; } (*p)->log_fp = nv_fopen((*p)->log_fname, "w"); if((*p)->log_fp == NULL) { iniche_free_log(p); return(-1); } #endif (*p)->pio = pio; return(0); }
int get_file_parms(char * filename, /* file to read (w/path) */ struct nvparm_format * parmformat, /* array of parmeter descriptors */ int * readline) /* count of lines read from file */ { char linebuf[NV_LINELENGTH]; /* make sure you have a big stack */ NV_FILE * fp; /* file with nvram data */ int retval = 0; /* value to return from this function */ char *retstr=NULL; fp = nv_fopen(filename, "r"); if (!fp) { printf("Unable to open NV Parameters file \"%s\"\n", filename); return ENP_NOFILE; } *readline = 0; /* no parameters read yet */ /* the main file reading loop */ for ((*readline) = 1; ; (*readline)++) { if (nv_fgets(linebuf, NV_LINELENGTH, fp) != linebuf) { retval = 0; break; } retstr=get_nv_value(linebuf,parmformat); if (retstr) { printf("%s %d, file %s\n", retstr,*readline, filename); printf("content: %s\n", linebuf); printf("Try moving %s to another directory & re-run executable\n", filename); retval=ENP_PARAM; break; } } nv_fclose(fp); return retval; }
void nv_defaults() { int iface = 0; VFILE *fp; int e; /* store default IP info */ #ifdef USE_SMSC91X inet_nvparms.ifs[iface].ipaddr = htonl(0x0a000067); /* 10.0.0.106 */ #ifdef USE_PPPOE inet_nvparms.ifs[iface].subnet = htonl(0xfffe0000); /* 255.254.0.0 */ inet_nvparms.ifs[iface].gateway = htonl(0x00000000); /* 0.0.0.0 */ #else inet_nvparms.ifs[iface].subnet = htonl(0xff000000); /* 255.0.0.0 */ inet_nvparms.ifs[iface].gateway = htonl(0x0a000001); /* 10.0.0.1 */ #endif inet_nvparms.ifs[iface].client_dhcp = 0; dprintf("nv_defaults: set net %d IP to %u.%u.%u.%u\n", iface, PUSH_IPADDR(inet_nvparms.ifs[iface].ipaddr) ); iface++; #endif /* */ #ifdef USE_PPP /* PPP */ inet_nvparms.ifs[iface].ipaddr = htonl(0x00000000); inet_nvparms.ifs[iface].subnet = htonl(0xffffff00); /* 255.255.255.0 */ inet_nvparms.ifs[iface].gateway = htonl(0xc0a80801); /* 192.168.8.1 */ iface++; #ifdef LB_XOVER inet_nvparms.ifs[iface].ipaddr = htonl(0x00000000); inet_nvparms.ifs[iface].subnet = htonl(0x00000000); inet_nvparms.ifs[iface].gateway = htonl(0x00000000); iface++; #endif /* LB_XOVER */ #endif /* USE_PPP */ /* loopback */ inet_nvparms.ifs[iface].ipaddr = htonl(0x00000000); inet_nvparms.ifs[iface].subnet = htonl(0x00000000); inet_nvparms.ifs[iface].gateway = htonl(0x00000000); #ifdef USE_COMPORT comport_nvparms.LineProtocol = 1; #endif /* defined (USE_PPP) || defined(USE_SLIP) */ #ifdef USE_PPP ppp_nvparms.ppp_ConsoleLog = 0; /* Log Modem & PPP events to console */ ppp_nvparms.ppp_FileLog = 0; /* Log Modem & PPP events to file */ ppp_nvparms.ppp_keepalive = 0; /* seconds between PPP echos, 0=disable */ ppp_nvparms.ppp_client_tmo = 500; /* timeout for connects as client */ ppp_nvparms.line_tmo = 300; #ifdef PPP_VJC ppp_nvparms.ppp_request_vj = 1; /* request that the other side do VJ compression */ #endif /* PPP_VJC */ #ifdef PAP_SUPPORT ppp_nvparms.require_pap = 0; #endif /* PAP_SUPPORT */ #ifdef USE_PPPOE strcpy(ppp_nvparms.username, "ppptest2"); strcpy(ppp_nvparms.password, "2ppptest"); strcpy(ppp_nvparms.secret, "2ppptest"); #endif /* USE_PPPOE */ #endif /* USE_PPP */ #ifdef USE_MODEM strcpy(modem_nvparms.dial_phone, "YOUR_ISP_PHONE\n"); strcpy(ppp_nvparms.username, "YOUR_ISP_NAME"); strcpy(ppp_nvparms.password, "YOUR_ISP_PASSWORD"); strcpy(modem_nvparms.modem_init, "AT&D0&C1\n"); strcpy(ppp_nvparms.loginfile, logfilename); strcpy(ppp_nvparms.logservefile, srvfilename); #endif /* USE_MODEM */ #ifdef USE_COMPORT comport_nvparms.comport = '2'; comport_nvparms.LineProtocol = 1; #endif /* USE_COMPORT */ #ifdef NATRT natrt_nvparms.nat_enabled = 1; natrt_nvparms.nat_inet = 1; natrt_nvparms.nat_localnet = 0; natrt_nvparms.tcp_timeout = 300; natrt_nvparms.udp_timeout = 500; #endif /* NATRT */ #ifdef SMTP_ALERTS smtp_nvparms.mserver = htonl(0x00000000); strcpy(smtp_nvparms.rcpt, "\n"); #endif /* SMTP_ALERTS */ #ifdef DNS_CLIENT_UPDT strcpy(inet_nvparms.dns_zone_name, "iniche.com"); /* zone name */ #endif /* DNS_CLIENT_UPDT */ /* create the login script file */ fp = nv_fopen(logfilename, "w+"); if (fp == NULL) dprintf("error creating %s\n", logfilename); else { e = nv_fprintf(fp, "#\n#empty login.nv\n#\n"); if (e < 1) { dprintf("nv_defaults: error writing %s\n", logfilename); } nv_fclose(fp); } /* create the some required NV files */ nv_fopen(srvfilename, "w+"); nv_fopen(natfilename, "w+"); }
int nv_read_parse(char *fname, struct nv_sectioninfo *sec,int slen) { char * cp; /* scratch */ FILE * fp; /* input file */ unsigned line; /* current line in input file */ int sec_index= NOT_A_SECTION; /* init to not in a list */ int ret_code = SUCCESS; static char linebuf[NV_LONGLINE]; /* scratch local buffer for file reading */ fp = (FILE *)nv_fopen(fname, "r"); if (!fp) { return ENP_NOFILE; } line = 0; while (nv_fgets(linebuf, NV_LONGLINE, fp) == linebuf) { line++; if ((linebuf[0] == '#') || /* see if line is commented out */ (linebuf[0] == ' ') || /* or starts with whitespace */ (linebuf[0] == '\t') || /* or starts with whitespace */ (linebuf[0] == '\n') || /* or is empty */ (linebuf[0] == '\r')) /* or is empty */ { continue; } cp = strchr(linebuf, '\n'); /* find possible linefeed */ if (cp) /* if linefeed exists, null it over */ *cp = '\0'; cp = strchr(linebuf, '#'); /* find possible in-line comment */ if (cp) /* if comment char exists, null it over */ *cp = '\0'; if (linebuf[0] == '[') { sec_index = nv_get_sec_num(&linebuf[1],sec,slen); continue; } /* fall to here if linebuf should contain a record */ if (sec_index == NOT_A_SECTION) continue; else { ret_code = sec[sec_index].parse_func(linebuf); if (ret_code != SUCCESS ) { dprintf("Error #%d (line %d of %s)\n",ret_code,line,fname); if ( ret_code == NICHE_DUP_ENTRY ) continue; else { nv_fclose(fp); return ret_code; } } } } if (line < 1) { ret_code = ENP_PARAM ; } nv_fclose(fp); return ret_code; }