Пример #1
0
int main()
{
    LONG result = 0;
    LONG ioerr = 0;
    TEXT buffer[16];

    fh = Open("T:a", MODE_NEWFILE);

    /* Invalid parameters */
    SetIoErr(0);
    result = FRead(fh, buffer, 0, 0);
    ioerr = IoErr();
    TEST((result == 0));
    TEST((ioerr == 0));

    /* EOF */
    SetIoErr(0);
    result = FRead(fh, buffer, 1, 1);
    ioerr = IoErr();
    TEST((result == 0));
    TEST((ioerr == 0));

    /* BNULL file handle */
    SetIoErr(0);
    result = FRead(BNULL, buffer, 1, 1);
    ioerr = IoErr();
    TEST((result == 0));
    TEST((ioerr == 0));

    cleanup();

    return OK;
}
Пример #2
0
void CMFile::ReadString(CString *str, CException *e)
{
	short l;
	FRead(&l,sizeof(short));
	if ((l<=0) || (l>300)) {throw e;};
	LPSTR s = str->GetBuffer(l);
	FRead(s,l);
	str->ReleaseBuffer();
}
Пример #3
0
BOOL CMFile::ReadString(CString *str)
{
	short l;
	FRead(&l,sizeof(short));
	if ((l<=0) || (l>300)) return FALSE;
	LPSTR s = str->GetBuffer(l);
	FRead(s,l);
	str->ReleaseBuffer();
	return TRUE;
}
Пример #4
0
void OS::FRead_swap(void* buffer, int32 size, FILE* stream) {
  FRead(buffer, size, stream);
  int32* end = (int32*)((char*)buffer + size);
  for (int32* p = (int32*)buffer;  p < end;  p++)
    if (Memory->is_snapshot_other_endian) 
      swap_bytes(p); 
}
Пример #5
0
ubyte * readFile2(char *name,int *lenptr)
{
ubyte *buf;
ulong len;
FILE *fp;

	if ( (fp = fopen(name,"rb")) == NULL )
		return NULL;

	*lenptr = -1;

	if ( (len = FileLengthofFH(fp)) == FileLengthofFH_Error ) {
		fclose(fp);
		return NULL;
	}

	if ( (buf = malloc(len)) == NULL ) {
		fclose(fp);
		return NULL;
	}

	if (FRead(fp,buf,len) != len) {
		printf("Failed to read the whole file: %s\n", name);
		exit(EXIT_FAILURE);
	}

	fclose(fp);

	*lenptr = len;

return buf;
}
Пример #6
0
int TFile::FReadEndian(void* buffer, size_t size, int count) {
  int num_read = FRead(buffer, size, count);
  if (swap_) {
    char* char_buffer = static_cast<char*>(buffer);
    for (int i = 0; i < num_read; ++i, char_buffer += size) {
      ReverseN(char_buffer, size);
    }
  }
  return num_read;
}
Пример #7
0
void readIntoConfTextsArray(int arrayIndex, int fileIndex, int textsToRead,
                            BPTR file) {
  printf("  Reading from position %d.\n", fileIndex);
  if(Seek(file, fileIndex * sizeof(short), OFFSET_BEGINNING) == -1) {
    Close(file);
    cleanup(EXIT_ERROR, "Couldn't seek in file.");
  }
  printf("  Reading %d texts into index %d.\n", textsToRead, arrayIndex);
  if(FRead(file, &Servermem->confTexts.texts[arrayIndex], sizeof(short), textsToRead)
     != textsToRead) {
    Close(file);
    cleanup(EXIT_ERROR, "Couldn't read from file.");
  }
}
Пример #8
0
void get_meter_file(char *meter_buf) 
{
#ifdef CONFIG_BCMWL5 
	FILE *fp;
        if (fp=fopen(ISP_METER_FILE, "r")) {
                fgets(meter_buf, sizeof(meter_buf), fp);
                fclose(fp);
	}
#else
	FRead(meter_buf, RA_OFFSET_ISP_METER, 64);
#endif
	_dprintf("meter_buf: %s\n", meter_buf);
	return;
}
Пример #9
0
int main()
{
	int i, j;
	char **seq;
	static char name[M][B];
	static int nlen[M];
	double **mtx;
	FILE *fp;
	int res;

	scoremtx = NOTSPECIFIED;

#if 0
	PreRead( stdin, &njob, &nlenmax );
#else
	getnumlen( stdin );
#endif
	rewind( stdin );

	seq = AllocateCharMtx( njob, nlenmax+1 );
	mtx = AllocateDoubleMtx( njob, njob );

#if 0
	FRead( stdin, name, nlen, seq );
#else
	readData( stdin, name, nlen, seq );
#endif

	for( i=0; i<njob-1; i++ ) 
	{
		fprintf( stderr, "%4d/%4d\r", i+1, njob );
		for( j=i+1; j<njob; j++ ) 
			mtx[i][j] = (double)substitution_score( seq[i], seq[j] );
	}
	
#if TEST
	for( i=0; i<njob-1; i++ ) for( j=i+1; j<njob; j++ ) 
		fprintf( stdout, "i=%d, j=%d, mtx[][] = %f\n", i, j, mtx[i][j] );
#endif

	fp = fopen( "hat2", "w" );
	WriteHat2( fp, njob, name, mtx );
	fclose( fp );
	exit( 0 );
/*
	res = system( ALNDIR "/spgsdl < hat2"  );
	if( res ) exit( 1 );
	else exit( 0 );
*/
}
Пример #10
0
  ft_io_stream( FT_Stream       stream,
                unsigned long   offset,
                unsigned char*  buffer,
                unsigned long   count )
  {
//  FILE*  file;
    BPTR   file;        // TetiSoft


    file = STREAM_FILE( stream );

//  fseek( file, offset, SEEK_SET );
    Seek( file, offset, OFFSET_BEGINNING );     // TetiSoft

//  return (unsigned long)fread( buffer, 1, count, file );
    return (unsigned long)FRead( file, buffer, 1, count);
  }
Пример #11
0
void readFileAreas(void) {
  BPTR fh;
  int i;
  if(!(fh = Open("NiKom:DatoCfg/Areor.dat", MODE_OLDFILE))) {
    cleanup(EXIT_ERROR,"Could not open NiKom:DatoCfg/Areor.dat");
  }
  SetIoErr(0L);
  Servermem->info.areor = FRead(fh, (void *)Servermem->areor,
                                sizeof(struct Area), MAXAREA);
  if(IoErr()) {
    cleanup(EXIT_ERROR, "Error reading Areor.dat");
  }
  Close(fh);
  for(i = 0; i < MAXAREA; i++) {
    NewList((struct List *)&Servermem->areor[i].ar_list);
  }
  printf("Read %d file areas.\n", Servermem->info.areor);
}
Пример #12
0
U8 *FASTCALL LoadFile(int dir, char *filename, S32 *_len)
{
	U32 len;
    U8 *buffer=NULL;
    FILE *f=OpenFile(dir,filename,"rb");
    if(f) {
     	len=FileLen(f);
        if(len) {
         	buffer = ssAlloc(len+1);
            FRead(buffer,len,f);
            buffer[len] = 0;
        }
        if(_len)
        	*_len = len;
        CloseFile(f);
    }
    return buffer;
}    
Пример #13
0
static int __getPLC_para(char *ebuf, int addr)
{
	int len;

	if (addr == OFFSET_PLC_MAC)
		len = ETHER_ADDR_LEN;
	else if (addr == OFFSET_PLC_NMK)
		len = PLC_KEY_LEN;
	else
		return 0;

	memset(ebuf, 0, sizeof(ebuf));

	if (FRead(ebuf, addr, len) < 0) {
		dbg("READ PLC parameter: Out of scope\n");
		return 0;
	}

	return 1;
}
Пример #14
0
UINT CMyFile::FReadString(TCHAR *Buffer, UINT nLength)
{
    UINT _nRead = 0;

    if((nLength == 0) || (Buffer == NULL))
        return false;

    if(this->_bOpen == false)
        return false;

    if(this->_nMode == -1)
        return false;

    for(UINT i = 0; i < nLength; i++)
    {
        if(FRead(Buffer[i]) == false)
            return _nRead;
        else
            _nRead++;
    }

    return _nRead;
}
Пример #15
0
void readGroupData(void) {
  BPTR fh;
  int x = 0;
  struct UserGroup *userGroup;

  NewList((struct List *)&Servermem->grupp_list);
  if(!(fh=Open("NiKom:DatoCfg/Grupper.dat",MODE_OLDFILE))) {
    cleanup(EXIT_ERROR, "Couldn't open NiKom:DatoCfg/Grupper.dat.");
  }
  
  for(;;) {
    if(!(userGroup=(struct UserGroup *)AllocMem(sizeof(struct UserGroup),
                                                MEMF_CLEAR | MEMF_PUBLIC))) {
      cleanup(EXIT_ERROR, "Out of memory.");
    }
    SetIoErr(0L);
    if(!FRead(fh, userGroup, sizeof(struct UserGroup), 1)) {
      if(IoErr()) {
        FreeMem(userGroup, sizeof(struct UserGroup));
        Close(fh);
        cleanup(EXIT_ERROR, "Error reading Grupper.dat");
      } else {
        FreeMem(userGroup, sizeof(struct UserGroup));
        break;
      }
    }
    if(!userGroup->namn[0]) {
      x++;
      continue;
    }
    AddTail((struct List *)&Servermem->grupp_list, (struct Node *)userGroup);
    userGroup->nummer = x;
    x++;
  }
  Close(fh);
  printf("Read %d user groups.\n", x);
}
Пример #16
0
bool TFile::DeSerialize(uint8_t* buffer, size_t count) {
  return FRead(buffer, sizeof(*buffer), count) == count;
}
Пример #17
0
int main( int argc, char **argv )
{
	int i, j;
	FILE *fp, *infp;
	char **seq;
	int *grpseq;
	char *tmpseq;
	int  **pointt;
	static char name[M][B];
	static int nlen[M];
	double **mtx;
	double **mtx2;
	double score, score0;
	static short *table1;
	char b[B];

	arguments( argc, argv );

	if( inputfile )
	{
		infp = fopen( inputfile, "r" );
		if( !infp )
		{
			fprintf( stderr, "Cannot open %s\n", inputfile );
			exit( 1 );
		}
	}
	else
		infp = stdin;

#if 0
	PreRead( stdin, &njob, &nlenmax );
#else
	getnumlen( infp );
#endif
	rewind( infp );
	if( njob < 2 )
	{
		fprintf( stderr, "At least 2 sequences should be input!\n"
						 "Only %d sequence found.\n", njob );
		exit( 1 );
	}

	tmpseq = AllocateCharVec( nlenmax+1 );
	seq = AllocateCharMtx( njob, nlenmax+1 );
	grpseq = AllocateIntVec( nlenmax+1 );
	pointt = AllocateIntMtx( njob, nlenmax+1 );
	mtx = AllocateDoubleMtx( njob, njob );
	mtx2 = AllocateDoubleMtx( njob, njob );
	pamN = NOTSPECIFIED;

#if 0
	FRead( infp, name, nlen, seq );
#else
	readData( infp, name, nlen, seq );
#endif

	fclose( infp );

	constants( njob, seq );

	if( dorp == 'd' ) tsize = (int)pow( 4, 6 );
	else              tsize = (int)pow( 6, 6 );

	maxl = 0;
	for( i=0; i<njob; i++ ) 
	{
		gappick0( tmpseq, seq[i] );
		nlen[i] = strlen( tmpseq );
		if( nlen[i] < 6 )
		{
			fprintf( stderr, "Seq %d, too short, %d characters\n", i+1, nlen[i] );
			exit( 1 );
		}
		if( nlen[i] > maxl ) maxl = nlen[i];
		if( dorp == 'd' ) /* nuc */
		{
			seq_grp_nuc( grpseq, tmpseq );
			makepointtable_nuc( pointt[i], grpseq );
		}
		else                 /* amino */
		{
			seq_grp( grpseq, tmpseq );
			makepointtable( pointt[i], grpseq );
		}
	}
	for( i=0; i<njob; i++ )
	{
		table1 = (short *)calloc( tsize, sizeof( short ) );
		if( !table1 ) ErrorExit( "Cannot allocate table1\n" );
		if( i % 10 == 0 )
		{
			fprintf( stderr, "%4d / %4d\r", i+1, njob );
		}
		makecompositiontable_p( table1, pointt[i] );

		for( j=i; j<njob; j++ ) 
		{
			score = (double)commonsextet_p( table1, pointt[j] );
			mtx[i][j] = score;
		} 
		free( table1 );
	}
	for( i=0; i<njob; i++ )
	{
		score0 = mtx[i][i];
		for( j=0; j<njob; j++ ) 
			mtx2[i][j] = ( score0 - mtx[MIN(i,j)][MAX(i,j)] ) / score0 * 3.0;
	}
	for( i=0; i<njob-1; i++ ) for( j=i+1; j<njob; j++ ) 
	{
#if TEST
                double jscore;
                jscore = mtx[i][j] / ( MIN( strlen( seq[i] ), strlen( seq[j] ) ) - 2 );
                fprintf( stdout, "jscore = %f\n", jscore );

		fprintf( stdout, "mtx2[%d][%d] = %f, mtx2[%d][%d] = %f\n", i, j, mtx2[i][j], j, i, mtx2[j][i] );
#endif
		mtx2[i][j] = MIN( mtx2[i][j], mtx2[j][i] );
#if TEST
		fprintf( stdout, "sonokekka mtx2[%d][%d] %f\n", i, j, mtx2[i][j] );
#endif
	}

	if( disopt )
	{
		for( i=0; i<njob; i++ ) 
		{
			sprintf( b, "=lgth = %04d", nlen[i] );
			strins( b, name[i] );
		}
	}
		
	fp = fopen( "hat2", "w" );
	if( !fp ) ErrorExit( "Cannot open hat2." );
	WriteHat2( fp, njob, name, mtx2 );
	fclose( fp );

	fprintf( stderr, "\n" );
	SHOWVERSION;
	exit( 0 );
}
Пример #18
0
int main( int argc, char **argv )
{
	int i, j;
	char **seq;
	static char **name;
	static int nlen[M];
	float *selfscore;
	double **mtx;
	FILE *fp;
	FILE *infp;
	float ssi, ssj, bunbo;


	arguments( argc, argv );
#ifndef enablemultithread
	nthread = 0;
#endif

	if( inputfile )
	{
		infp = fopen( inputfile, "r" );
		if( !infp )
		{
			fprintf( stderr, "Cannot open %s\n", inputfile );
			exit( 1 );
		}
	}
	else
		infp = stdin;

#if 0
	PreRead( stdin, &njob, &nlenmax );
#else
	getnumlen( infp );
#endif
	rewind( infp );

	seq = AllocateCharMtx( njob, nlenmax+1 );
	name = AllocateCharMtx( njob, B+1 );
	mtx = AllocateDoubleMtx( njob, njob );
	selfscore = AllocateFloatVec( njob );

#if 0
	FRead( stdin, name, nlen, seq );
#else
	readData_pointer( infp, name, nlen, seq );
#endif
	fclose( infp );

	constants( njob, seq );

#if 0
	for( i=0; i<njob-1; i++ ) 
	{
		fprintf( stderr, "%4d/%4d\r", i+1, njob );
		for( j=i+1; j<njob; j++ ) 
			mtx[i][j] = (double)substitution_hosei( seq[i], seq[j] );
//			fprintf( stderr, "i=%d,j=%d, l=%d &&&  %f\n", i, j, nlen[0], mtx[i][j] );
	}
#else // 061003
	for( i=0; i<njob; i++ )
	{
		selfscore[i] = (float)naivepairscore11( seq[i], seq[i], penalty );

	}
#ifdef enablemultithread
	if( nthread > 0 )
	{
		thread_arg_t *targ;
		Jobtable jobpos;
		pthread_t *handle;
		pthread_mutex_t mutex;

		jobpos.i = 0;
		jobpos.j = 0;

		targ = calloc( nthread, sizeof( thread_arg_t ) );
		handle = calloc( nthread, sizeof( pthread_t ) );
		pthread_mutex_init( &mutex, NULL );

		for( i=0; i<nthread; i++ )
		{
			targ[i].thread_no = i;
			targ[i].njob = njob;
			targ[i].selfscore = selfscore;
			targ[i].mtx = mtx;
			targ[i].seq = seq;
			targ[i].jobpospt = &jobpos;
			targ[i].mutex = &mutex;

			pthread_create( handle+i, NULL, athread, (void *)(targ+i) );
		}

		for( i=0; i<nthread; i++ )
		{
			pthread_join( handle[i], NULL );
		}
		pthread_mutex_destroy( &mutex );
	}
	else
#endif
	{
		for( i=0; i<njob-1; i++ )
		{
			ssi = selfscore[i];
			fprintf( stderr, "%4d/%4d\r", i+1, njob );
			for( j=i+1; j<njob; j++ )
			{
				ssj = selfscore[j];
				bunbo = MIN( ssi, ssj );
				if( bunbo == 0.0 )
					mtx[i][j] = 1.0;
				else
					mtx[i][j] = 1.0 - (double)naivepairscore11( seq[i], seq[j], penalty ) / bunbo;
//					mtx[i][j] = 1.0 - (double)naivepairscore11( seq[i], seq[j], penalty ) / MIN( selfscore[i], selfscore[j] );
//				fprintf( stderr, "i=%d,j=%d, l=%d### %f, score = %d\n", i, j, nlen[0], mtx[i][j], naivepairscore11( seq[i], seq[j], penalty )  );
			}
		}
	}
#endif
	
#if TEST
	for( i=0; i<njob-1; i++ ) for( j=i+1; j<njob; j++ ) 
		fprintf( stdout, "i=%d, j=%d, mtx[][] = %f\n", i, j, mtx[i][j] );
#endif

	fp = fopen( "hat2", "w" );
	WriteHat2_pointer( fp, njob, name, mtx );
	fclose( fp );
#if 0
	if( treeout )
	{
		int ***topol;
		double **len;

		topol = AllocateIntCub( njob, 2, njob );
		len = AllocateDoubleMtx( njob, njob );
		veryfastsupg_double_outtree( njob, mtx, topol, len );
	}
#endif
	SHOWVERSION;
	exit( 0 );
/*
	res = system( ALNDIR "/spgsdl < hat2"  );
	if( res ) exit( 1 );
	else exit( 0 );
*/
}
Пример #19
0
void init_syspara(void)
{
	unsigned char buffer[16];
	unsigned char *dst;
	unsigned int bytes;
	int i;
	char macaddr[]="00:11:22:33:44:55";
	char macaddr2[]="00:11:22:33:44:58";
	char country_code[3];
	char pin[9];
	char productid[13];
	char fwver[8];
	char blver[20];
	unsigned char txbf_para[33];
	char ea[ETHER_ADDR_LEN];

	nvram_set("buildno", rt_serialno);
	nvram_set("extendno", rt_extendno);
	nvram_set("buildinfo", rt_buildinfo);
	nvram_set("swpjverno", rt_swpjverno);

	/* /dev/mtd/2, RF parameters, starts from 0x40000 */
	dst = buffer;
	bytes = 6;
	memset(buffer, 0, sizeof(buffer));
	memset(country_code, 0, sizeof(country_code));
	memset(pin, 0, sizeof(pin));
	memset(productid, 0, sizeof(productid));
	memset(fwver, 0, sizeof(fwver));
	memset(txbf_para, 0, sizeof(txbf_para));

	if (FRead(dst, OFFSET_MAC_ADDR, bytes)<0)
	{
		_dprintf("READ MAC address: Out of scope\n");
	}
	else
	{
		if (buffer[0]!=0xff)
			ether_etoa(buffer, macaddr);
	}

#if !defined(RTN14U) // single band
	if (FRead(dst, OFFSET_MAC_ADDR_2G, bytes)<0)
	{
		_dprintf("READ MAC address 2G: Out of scope\n");
	}
	else
	{
		if (buffer[0]!=0xff)
			ether_etoa(buffer, macaddr2);
	}
#endif

#if defined(RTN14U) // single band
	if (!mssid_mac_validate(macaddr))
#else
	if (!mssid_mac_validate(macaddr) || !mssid_mac_validate(macaddr2))
#endif
		nvram_set("wl_mssid", "0");
	else
		nvram_set("wl_mssid", "1");

#if defined(RTN14U) // single band
	nvram_set("et0macaddr", macaddr);
	nvram_set("et1macaddr", macaddr);
#else
	//TODO: separate for different chipset solution
	nvram_set("et0macaddr", macaddr);
	nvram_set("et1macaddr", macaddr2);
#endif

	if (FRead(dst, OFFSET_MAC_GMAC0, bytes)<0)
		dbg("READ MAC address GMAC0: Out of scope\n");
	else
	{
		if (buffer[0]==0xff)
		{
			if (ether_atoe(macaddr, ea))
				FWrite(ea, OFFSET_MAC_GMAC0, 6);
		}
	}

	if (FRead(dst, OFFSET_MAC_GMAC2, bytes)<0)
		dbg("READ MAC address GMAC2: Out of scope\n");
	else
	{
		if (buffer[0]==0xff)
		{
			if (ether_atoe(macaddr2, ea))
				FWrite(ea, OFFSET_MAC_GMAC2, 6);
		}
	}

	/* reserved for Ralink. used as ASUS country code. */
#if ! defined(RTCONFIG_NEW_REGULATION_DOMAIN)
	dst = (unsigned char*) country_code;
	bytes = 2;
	if (FRead(dst, OFFSET_COUNTRY_CODE, bytes)<0)
	{
		_dprintf("READ ASUS country code: Out of scope\n");
		nvram_set("wl_country_code", "");
	}
	else
	{
		chk_valid_country_code(country_code);
		nvram_set("wl_country_code", country_code);
		nvram_set("wl0_country_code", country_code);
		nvram_set("wl1_country_code", country_code);
	}
#else	/* ! RTCONFIG_NEW_REGULATION_DOMAIN */
	dst = buffer;

	bytes = MAX_REGSPEC_LEN;
	memset(dst, 0, MAX_REGSPEC_LEN+1);
	if(FRead(dst, REGSPEC_ADDR, bytes) < 0)
		nvram_set("reg_spec", "FCC"); // DEFAULT
	else
	{
		for (i=(MAX_REGSPEC_LEN-1);i>=0;i--) {
			if ((dst[i]==0xff) || (dst[i]=='\0'))
				dst[i]='\0';
		}
		if (dst[0]!=0x00)
			nvram_set("reg_spec", dst);
		else
			nvram_set("reg_spec", "FCC"); // DEFAULT
	}

	if (FRead(dst, REG2G_EEPROM_ADDR, MAX_REGDOMAIN_LEN)<0 || memcmp(dst,"2G_CH", 5) != 0)
	{
		_dprintf("READ ASUS country code: Out of scope\n");
		nvram_set("wl_country_code", "");
		nvram_set("wl0_country_code", "DB");
		nvram_set("wl_reg_2g", "2G_CH14");
	}
	else
	{
		for(i = 0; i < MAX_REGDOMAIN_LEN; i++)
			if(dst[i] == 0xff || dst[i] == 0)
				break;

		dst[i] = 0;
		nvram_set("wl_reg_2g", dst);
		if      (strcmp(dst, "2G_CH11") == 0)
			nvram_set("wl0_country_code", "US");
		else if (strcmp(dst, "2G_CH13") == 0)
			nvram_set("wl0_country_code", "GB");
		else if (strcmp(dst, "2G_CH14") == 0)
			nvram_set("wl0_country_code", "DB");
		else
			nvram_set("wl0_country_code", "DB");
	}

	if (FRead(dst, REG5G_EEPROM_ADDR, MAX_REGDOMAIN_LEN)<0 || memcmp(dst,"5G_", 3) != 0)
	{
		_dprintf("READ ASUS country code: Out of scope\n");
		nvram_set("wl_country_code", "");
		nvram_set("wl1_country_code", "DB");
		nvram_set("wl_reg_5g", "5G_ALL");
	}
	else
	{
		for(i = 0; i < MAX_REGDOMAIN_LEN; i++)
			if(dst[i] == 0xff || dst[i] == 0)
				break;

		dst[i] = 0;
		nvram_set("wl_reg_5g", dst);
		if      (strcmp(dst, "5G_BAND1") == 0)
			nvram_set("wl1_country_code", "GB");
		else if (strcmp(dst, "5G_BAND123") == 0)
			nvram_set("wl1_country_code", "GB");
		else if (strcmp(dst, "5G_BAND14") == 0)
			nvram_set("wl1_country_code", "US");
		else if (strcmp(dst, "5G_BAND24") == 0)
			nvram_set("wl1_country_code", "TW");
		else if (strcmp(dst, "5G_BAND4") == 0)
			nvram_set("wl1_country_code", "CN");
		else
			nvram_set("wl1_country_code", "DB");
	}
#endif	/* ! RTCONFIG_NEW_REGULATION_DOMAIN */
#if defined(RTN56U) || defined(RTCONFIG_DSL)
		if (nvram_match("wl_country_code", "BR"))
		{
			nvram_set("wl_country_code", "UZ");
			nvram_set("wl0_country_code", "UZ");
			nvram_set("wl1_country_code", "UZ");
		}
#endif
		if (nvram_match("wl_country_code", "HK") && nvram_match("preferred_lang", ""))
			nvram_set("preferred_lang", "TW");

	/* reserved for Ralink. used as ASUS pin code. */
	dst = (char*)pin;
	bytes = 8;
	if (FRead(dst, OFFSET_PIN_CODE, bytes)<0)
	{
		_dprintf("READ ASUS pin code: Out of scope\n");
		nvram_set("wl_pin_code", "");
	}
	else
	{
		if ((unsigned char)pin[0]!=0xff)
			nvram_set("secret_code", pin);
		else
			nvram_set("secret_code", "12345670");
	}

	dst = buffer;
	bytes = 16;
	if (linuxRead(dst, 0x20, bytes)<0)	/* The "linux" MTD partition, offset 0x20. */
	{
		fprintf(stderr, "READ firmware header: Out of scope\n");
		nvram_set("productid", "unknown");
		nvram_set("firmver", "unknown");
	}
	else
	{
		strncpy(productid, buffer + 4, 12);
		productid[12] = 0;
		sprintf(fwver, "%d.%d.%d.%d", buffer[0], buffer[1], buffer[2], buffer[3]);
		nvram_set("productid", trim_r(productid));
		nvram_set("firmver", trim_r(fwver));
	}

	memset(buffer, 0, sizeof(buffer));
	FRead(buffer, OFFSET_BOOT_VER, 4);
//	sprintf(blver, "%c.%c.%c.%c", buffer[0], buffer[1], buffer[2], buffer[3]);
	sprintf(blver, "%s-0%c-0%c-0%c-0%c", trim_r(productid), buffer[0], buffer[1], buffer[2], buffer[3]);
	nvram_set("blver", trim_r(blver));

	_dprintf("bootloader version: %s\n", nvram_safe_get("blver"));
	_dprintf("firmware version: %s\n", nvram_safe_get("firmver"));

	dst = txbf_para;
	int count_0xff = 0;
	if (FRead(dst, OFFSET_TXBF_PARA, 33) < 0)
	{
		fprintf(stderr, "READ TXBF PARA address: Out of scope\n");
	}
	else
	{
		for (i = 0; i < 33; i++)
		{
			if (txbf_para[i] == 0xff)
				count_0xff++;
/*
			if ((i % 16) == 0) fprintf(stderr, "\n");
			fprintf(stderr, "%02x ", (unsigned char) txbf_para[i]);
*/
		}
/*
		fprintf(stderr, "\n");

		fprintf(stderr, "TxBF parameter 0xFF count: %d\n", count_0xff);
*/
	}

	if (count_0xff == 33)
		nvram_set("wl1_txbf_en", "0");
	else
		nvram_set("wl1_txbf_en", "1");

#if defined (RTCONFIG_WLMODULE_RT3352_INIC_MII)
#define EEPROM_INIC_SIZE (512)
#define EEPROM_INIT_ADDR 0x48000
#define EEPROM_INIT_FILE "/etc/Wireless/iNIC/iNIC_e2p.bin"
	{
		char eeprom[EEPROM_INIC_SIZE];
		if(FRead(eeprom, EEPROM_INIT_ADDR, sizeof(eeprom)) < 0)
		{
			fprintf(stderr, "FRead(eeprom, 0x%08x, 0x%x) failed\n", EEPROM_INIT_ADDR, sizeof(eeprom));
		}
		else
		{
			FILE *fp;
			char *filepath = EEPROM_INIT_FILE;

			system("mkdir -p /etc/Wireless/iNIC/");
			if((fp = fopen(filepath, "w")) == NULL)
			{
				fprintf(stderr, "fopen(%s) failed!!\n", filepath);
			}
			else
			{
				if(fwrite(eeprom, sizeof(eeprom), 1, fp) < 1)
				{
					perror("fwrite(eeprom)");
				}
				fclose(fp);
			}
		}
	}
#endif

#ifdef RA_SINGLE_SKU
#if defined(RTAC52U)
	{
		char *reg_spec;

		reg_spec = nvram_safe_get("reg_spec");
		create_SingleSKU("/etc/Wireless/RT2860", "", reg_spec);
		create_SingleSKU("/etc/Wireless/iNIC", "_5G", reg_spec);
	}
#endif	/* RTAC52U */
#endif	/* RA_SINGLE_SKU */

	{
#ifdef RTCONFIG_ODMPID
		char modelname[16];
		FRead(modelname, OFFSET_ODMPID, sizeof(modelname));
		modelname[sizeof(modelname)-1] = '\0';
		if(modelname[0] != 0 && (unsigned char)(modelname[0]) != 0xff && is_valid_hostname(modelname) && strcmp(modelname, "ASUS"))
		{
			nvram_set("odmpid", modelname);
		}
		else
#endif
			nvram_unset("odmpid");
	}

	nvram_set("firmver", rt_version);
	nvram_set("productid", rt_buildname);
}
Пример #20
0
int asus_ate_command(const char *command, const char *value, const char *value2)
{
	_dprintf("===[ATE %s %s]===\n", command, value);
#ifdef RTCONFIG_QTN
	if(!nvram_match("qtn_ready", "1")){
		_dprintf("ATE Error: wireless 5G not ready\n");
		return 0;
	}
#endif
	/*** ATE Set function ***/
	if(!strcmp(command, "Set_StartATEMode")) {
		nvram_set("asus_mfg", "1");
		if(nvram_match("asus_mfg", "1")) {
			puts("1");
#ifdef RTCONFIG_FANCTRL
			stop_phy_tempsense();
#endif
			stop_wpsaide();
			stop_wps();
#ifdef RTCONFIG_BCMWL6
			stop_igmp_proxy();
#ifdef RTCONFIG_HSPOT
			stop_hspotap();
#endif
			stop_acsd();
#ifdef BCM_BSD
			stop_bsd();
#endif
#ifdef BCM_SSD
			stop_ssd();
#endif
#endif
			stop_upnp();
			stop_lltd();
			stop_rstats();
			stop_wanduck();
			stop_logger();
			stop_wanduck();
			stop_dnsmasq(0);
			stop_ots();
			stop_networkmap();
#ifdef RTCONFIG_USB
			stop_usbled();
#ifdef RTCONFIG_USB_PRINTER
			stop_lpd();
			stop_u2ec();
#endif
#endif
			platform_start_ate_mode();
		}
		else
			puts("ATE_ERROR");
		return 0;
	}
	else if (!strcmp(command, "Set_AllLedOn")) {
		return setAllLedOn();
	}
	else if (!strcmp(command, "Set_AllLedOn2")) {
		return setAllLedOn2();
	}
	else if (!strcmp(command, "Set_AllLedOff")) {
		return setAllLedOff();
	}
	else if (!strcmp(command, "Set_AllLedOn_Half")) {
		puts("ATE_ERROR"); //Need to implement for EA-N66U
		return EINVAL;
	}
#ifdef RTCONFIG_BCMARM
	else if (!strcmp(command, "Set_AteModeLedOn")) {
		return setATEModeLedOn();
	}
#endif
	else if (!strcmp(command, "Set_MacAddr_2G")) {
		if( !setMAC_2G(value) )
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		return 0;
	}
#if defined(RTCONFIG_HAS_5G)
	else if (!strcmp(command, "Set_MacAddr_5G")) {
#ifdef RTCONFIG_QTN
		if( !setMAC_5G_qtn(value))
#else
		if( !setMAC_5G(value))
#endif
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		return 0;
	}
#ifdef RTAC3200
	else if (!strcmp(command, "Set_MacAddr_5G_2")) {
		if( !setMAC_5G_2(value))
                {
                        puts("ATE_ERROR_INCORRECT_PARAMETER");
                        return EINVAL;
                }
                return 0;
	}
#endif
#endif	/* RTCONFIG_HAS_5G */
#if defined(RTN14U)
	else if (!strcmp(command, "eeprom")) {
		if ( !eeprom_upgrade(value, 1))
			return EINVAL;
		return 0;
	}
	else if (!strcmp(command, "eeover")) {
		if ( !eeprom_upgrade(value, 0))
			return EINVAL;
		return 0;
	}
#endif
#if defined(RTCONFIG_NEW_REGULATION_DOMAIN)
	else if (!strcmp(command, "Set_RegSpec")) {
		if (setRegSpec(value) < 0)
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		getRegSpec();
		return 0;
	}
	else if (!strcmp(command, "Set_RegulationDomain_2G")) {
		if (setRegDomain_2G(value) == -1) {
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		getRegDomain_2G();
		return 0;
	}
#if defined(RTCONFIG_HAS_5G)
	else if (!strcmp(command, "Set_RegulationDomain_5G")) {
		if (setRegDomain_5G(value) == -1) {
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		getRegDomain_5G();
		return 0;
	}
#endif	/* RTCONFIG_HAS_5G */
#else	/* ! RTCONFIG_NEW_REGULATION_DOMAIN */
	else if (!strcmp(command, "Set_RegulationDomain_2G")) {
		if ( !setCountryCode_2G(value))
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
#ifdef RTCONFIG_QCA
		if ((value2==NULL) || strcmp(value2,"noctl"))
			setCTL(value);
#endif
		return 0;
	}
#endif /* RTCONFIG_NEW_REGULATION_DOMAIN */
#ifdef CONFIG_BCMWL5
	else if (!strcmp(command, "Set_RegulationDomain_5G")) {
#ifdef RTCONFIG_QTN
		if ( !setCountryCode_5G_qtn(value))
#else
		if ( !setCountryCode_5G(value))
#endif
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		return 0;
	}
	else if (!strcmp(command, "Set_Regrev_2G")) {
		if( !setRegrev_2G(value) )
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		return 0;
	}
	else if (!strcmp(command, "Set_Regrev_5G")) {
#ifdef RTCONFIG_QTN
		if( !setRegrev_5G_qtn(value))
#else
		if( !setRegrev_5G(value))
#endif
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		return 0;
	}
	else if (!strcmp(command, "Set_Commit")) {
		setCommit();
		return 0;
	}
#endif
#if defined(RTN14U)
	else if (!strcmp(command, "pkt_flood")) {
		if (nvram_invmatch("asus_mfg", "0"))
		{
#if 0 // TBD
			struct sockaddr_ll dev,dev2;
			int fd,fd2,do_flag=3;
			unsigned char buffer[1514];
			fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
			dev.sll_family = AF_PACKET;
			dev.sll_protocol = htons(ETH_P_ALL);
			dev.sll_ifindex = 4; // LAN
			bind( fd, (struct sockaddr *) &dev, sizeof(dev));

			fd2 = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
			dev2.sll_family = AF_PACKET;
			dev2.sll_protocol = htons(ETH_P_ALL);
			dev2.sll_ifindex = 5; // WAN
			bind( fd2, (struct sockaddr *) &dev2, sizeof(dev2));

			if (value) {
				if(strcmp(value,"WAN")==0)
					do_flag = 2;
				else if(strcmp(value,"LAN")==0)
					do_flag = 1;
			}
			memset(buffer,0xff,6);
			FRead(buffer+6, OFFSET_MAC_ADDR_2G, 6);
			memset(buffer+12,0x55,1502);
			while(1)
			{
				if (do_flag & 1)
					send( fd, buffer, 1514, 0);
				if (do_flag & 2)
					send( fd2, buffer, 1514, 0);
			}
#endif
		}
		return 0;
 	}
#endif
	else if (!strcmp(command, "Set_SerialNumber")) {
		if(!setSN(value))
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		return 0;
 	}
#ifdef RTCONFIG_ODMPID
	else if (!strcmp(command, "Set_ModelName")) {
		if(!setMN(value))
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		return 0;
	}
#endif
	else if (!strcmp(command, "Set_PINCode")) {
		if (!setPIN(value))
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		return 0;
	}
	else if (!strcmp(command, "Set_40M_Channel_2G")) {
		if(!set40M_Channel_2G((char*)value))
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		return 0;
	}
#if defined(RTCONFIG_HAS_5G)
	else if (!strcmp(command, "Set_40M_Channel_5G")) {
		if(!set40M_Channel_5G((char*)value))
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		return 0;
	}
#endif	/* RTCONFIG_HAS_5G */
	else if (!strcmp(command, "Set_RestoreDefault")) {
		nvram_set("restore_defaults", "1");
		ResetDefault();
		nvram_set(ASUS_STOP_COMMIT, "1");
		return 0;
	}
	else if (!strcmp(command, "Set_Eject")) {
		if( !Ej_device(value)) {
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		return 0;
	}
#ifdef RTCONFIG_FANCTRL
	else if (!strcmp(command, "Set_FanOn")) {
		setFanOn();
		return 0;
	}
	else if (!strcmp(command, "Set_FanOff")) {
		setFanOff();
		return 0;
	}
#endif
#ifdef CONFIG_BCMWL5
	else if (!strcmp(command, "Set_WaitTime")) {
		if( !setWaitTime(value) )
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		return 0;
	}
	else if (!strcmp(command, "Set_WiFi_2G")) {
		if( !setWiFi2G(value) )
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		return 0;
	}
#if defined(RTCONFIG_HAS_5G)
	else if (!strcmp(command, "Set_WiFi_5G")) {
		if( !setWiFi5G(value) )
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		return 0;
	}
#endif	/* RTCONFIG_HAS_5G */
#endif
#ifdef RTCONFIG_RALINK
	else if (!strcmp(command, "Set_DevFlags")) {
		if( Set_Device_Flags(value) < 0 )
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		return 0;
	}
	else if (!strcmp(command, "Set_WanToLan")) {
	   	set_wantolan();
		modprobe_r("hw_nat");
		modprobe("hw_nat");
		system("killall -9 wanduck");
		system("killall -9 udhcpc");
		return 0;
	}
#if defined(RTAC1200HP) || defined(RTN56UB1)
        else if (!strcmp(command, "Set_FixChannel")) {
	   	 FWrite("1", OFFSET_FIX_CHANNEL, 1);	
                 puts("1");
                 return 0;
         }
        else if (!strcmp(command, "Set_FreeChannel")) {
	   	 FWrite("0", OFFSET_FIX_CHANNEL, 1);	
		 nvram_set("wl0_channel","0");
		 nvram_set("wl1_channel","0");
		 nvram_set("lan_stp","1");
		 nvram_commit();
                 puts("1");
                 return 0;
         }
#endif
#endif
	else if (!strcmp(command, "Set_XSetting")) {
		if(value == NULL || strcmp(value, "1")) {
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		else {
			nvram_set("x_Setting", "1");
			puts(nvram_get("x_Setting"));
		}
		return 0;
	}
	/*** ATE Get functions ***/
	else if (!strcmp(command, "Get_FWVersion")) {
		char fwver[12];
		sprintf(fwver, "%s.%s", nvram_safe_get("firmver"), nvram_safe_get("buildno"));
		puts(fwver);
		return 0;
	}
	else if (!strcmp(command, "Get_BootLoaderVersion")) {
		getBootVer();
		return 0;
	}
	else if (!strcmp(command, "Get_ResetButtonStatus")) {
		puts(nvram_safe_get("btn_rst"));
		return 0;
	}
	else if (!strcmp(command, "Get_WpsButtonStatus")) {
		puts(nvram_safe_get("btn_ez"));
		return 0;
	}
#ifdef RT4GAC55U
	else if (!strcmp(command, "Get_LteButtonStatus")) {
		puts(nvram_safe_get("btn_lte"));
		return 0;
	}
#endif
#ifdef RTCONFIG_WIFI_TOG_BTN
	else if (!strcmp(command, "Get_WirelessButtonStatus")) {
		puts(nvram_safe_get("btn_wifi_toggle"));
		return 0;
	}
#endif
	else if (!strcmp(command, "Get_SWMode")) {
		puts(nvram_safe_get("sw_mode"));
		return 0;
	}
	else if (!strcmp(command, "Get_MacAddr_2G")) {
		getMAC_2G();
		return 0;
	}
#if defined(RTCONFIG_HAS_5G)
	else if (!strcmp(command, "Get_MacAddr_5G")) {
#ifdef RTCONFIG_QTN
		getMAC_5G_qtn();
#else
		getMAC_5G();
#endif
		return 0;
	}
#ifdef RTAC3200
	else if (!strcmp(command, "Get_MacAddr_5G_2")) {
		getMAC_5G_2();
		return 0;
	}
#endif
#endif	/* RTCONFIG_HAS_5G */
	else if (!strcmp(command, "Get_Usb2p0_Port1_Infor")) {
		Get_USB_Port_Info("1");
		return 0;
	}
	else if (!strcmp(command, "Get_Usb2p0_Port1_Folder")) {
		Get_USB_Port_Folder("1");
		return 0;
	}
	else if (!strcmp(command, "Get_Usb2p0_Port2_Infor")) {
		Get_USB_Port_Info("2");
		return 0;
	}
	else if (!strcmp(command, "Get_Usb2p0_Port2_Folder")) {
		Get_USB_Port_Folder("2");
		return 0;
	}
	else if (!strcmp(command, "Get_SD_Infor")) {
		Get_SD_Card_Info();
		return 0;
	}
	else if (!strcmp(command, "Get_SD_Folder")) {
		Get_SD_Card_Folder();
		return 0;
	}
#if defined(RTCONFIG_NEW_REGULATION_DOMAIN)
	else if (!strcmp(command, "Get_RegSpec")) {
		getRegSpec();
		return 0;
	}
	else if (!strcmp(command, "Get_RegulationDomain_2G")) {
		getRegDomain_2G();
		return 0;
	}
#if defined(RTCONFIG_HAS_5G)
	else if (!strcmp(command, "Get_RegulationDomain_5G")) {
		getRegDomain_5G();
		return 0;
	}
#endif	/* RTCONFIG_HAS_5G */
#else	/* ! RTCONFIG_NEW_REGULATION_DOMAIN */
	else if (!strcmp(command, "Get_RegulationDomain_2G")) {
		getCountryCode_2G();
		return 0;
	}
#endif	/* ! RTCONFIG_NEW_REGULATION_DOMAIN */
#ifdef CONFIG_BCMWL5
	else if (!strcmp(command, "Get_RegulationDomain_5G")) {
#ifdef RTCONFIG_QTN
		getCountryCode_5G_qtn();
#else
	   	getCountryCode_5G();
#endif
		return 0;
	}
	else if (!strcmp(command, "Get_Regrev_2G")) {
		getRegrev_2G();
		return 0;
	}
#if defined(RTCONFIG_HAS_5G)
	else if (!strcmp(command, "Get_Regrev_5G")) {
#ifdef RTCONFIG_QTN
		getRegrev_5G_qtn();
#else
		getRegrev_5G();
#endif
		return 0;
	}
#endif	/* RTCONFIG_HAS_5G */
#endif
	else if (!strcmp(command, "Get_SerialNumber")) {
		getSN();
		return 0;
	}
#ifdef RTCONFIG_ODMPID
	else if (!strcmp(command, "Get_ModelName")) {
		getMN();
		return 0;
	}
#endif
	else if (!strcmp(command, "Get_PINCode")) {
		getPIN();
		return 0;
	}
	else if (!strcmp(command, "Get_WanLanStatus")) {
		if( !GetPhyStatus())
			puts("ATE_ERROR");
		return 0;
	}
	else if (!strcmp(command, "Get_FwReadyStatus")) {
		puts(nvram_safe_get("success_start_service"));
		return 0;
	}
	else if (!strcmp(command, "Get_Build_Info")) {
		puts(nvram_safe_get("buildinfo"));
		return 0;
	}
#ifdef RTCONFIG_RALINK
	else if (!strcmp(command, "Get_RSSI_2G")) {
		getrssi(0);
		return 0;
	}
#if defined(RTCONFIG_HAS_5G)
	else if (!strcmp(command, "Get_RSSI_5G")) {
		getrssi(1);
		return 0;
	}
#endif	/* RTCONFIG_HAS_5G */
#endif
	else if (!strcmp(command, "Get_ChannelList_2G")) {
		if(!Get_ChannelList_2G())
			puts("ATE_ERROR");
		return 0;
	}
#if defined(RTCONFIG_HAS_5G)
	else if (!strcmp(command, "Get_ChannelList_5G")) {
#ifdef RTCONFIG_QTN
		if (!Get_ChannelList_5G_qtn())
#else
		if (!Get_ChannelList_5G())
#endif
			puts("ATE_ERROR");
		return 0;
	}
#ifdef RTAC3200
	else if (!strcmp(command, "Get_ChannelList_5G_2")) {
		if (!Get_ChannelList_5G_2())
			puts("ATE_ERROR");
		return 0;
	}
#endif
#endif	/* RTCONFIG_HAS_5G */
#if defined(RTCONFIG_USB_XHCI)
	else if (!strcmp(command, "Get_Usb3p0_Port1_Infor")) {
		if (!Get_USB3_Port_Info("1"))
			puts("ATE_ERROR");
		return 0;
	}
	else if (!strcmp(command, "Get_Usb3p0_Port2_Infor")) {
		if (!Get_USB3_Port_Info("2"))
			puts("ATE_ERROR");
		return 0;
	}
	else if (!strcmp(command, "Get_Usb3p0_Port3_Infor")) {
		puts("ATE_ERROR"); //Need to implement
		return 0;
	}
	else if (!strcmp(command, "Get_Usb3p0_Port1_Folder")) {
		if (!Get_USB3_Port_Folder("1"))
			puts("ATE_ERROR");
		return 0;
	}
	else if (!strcmp(command, "Get_Usb3p0_Port2_Folder")) {
		if (!Get_USB3_Port_Folder("2"))
			puts("ATE_ERROR");
		return 0;
	}
 	else if (!strcmp(command, "Get_Usb3p0_Port3_Folder")) {
		puts("ATE_ERROR"); //Need to implement
		return EINVAL;
	}
	else if (!strcmp(command, "Get_Usb3p0_Port1_DataRate")) {
		if (!Get_USB3_Port_DataRate("1"))
			puts("ATE_ERROR");
		return 0;
	}
	else if (!strcmp(command, "Get_Usb3p0_Port2_DataRate")) {
		if (!Get_USB3_Port_DataRate("2"))
			puts("ATE_ERROR");
		return 0;
	}
	else if (!strcmp(command, "Get_Usb3p0_Port3_DataRate")) {
		puts("ATE_ERROR"); //Need to implement
		return EINVAL;
	}
#endif	/* RTCONFIG_USB_XHCI */
	else if (!strcmp(command, "Get_fail_ret")) {
		Get_fail_ret();
		return 0;
	}
	else if (!strcmp(command, "Get_fail_reboot_log")) {
		Get_fail_reboot_log();
		return 0;
	}
	else if (!strcmp(command, "Get_fail_dev_log")) {
		Get_fail_dev_log();
		return 0;
	}
#ifdef RTCONFIG_RALINK
#if !defined(RTN14U) && !defined(RTAC52U) && !defined(RTAC51U) && !defined(RTN11P) && !defined(RTN54U) && !defined(RTAC1200HP) && !defined(RTN56UB1) && !defined(RTAC54U)
	else if (!strcmp(command, "Ra_FWRITE")) {
		return FWRITE(value, value2);
	}
	else if (!strcmp(command, "Ra_Asuscfe_2G")) {
		return asuscfe(value, WIF_2G);
	}
#if defined(RTCONFIG_HAS_5G)
	else if (!strcmp(command, "Ra_Asuscfe_5G")) {
		return asuscfe(value, WIF_5G);
	}
#endif	/* RTCONFIG_HAS_5G */
	else if (!strcmp(command, "Set_SwitchPort_LEDs")) {
		if(Set_SwitchPort_LEDs(value, value2) < 0)
		{
			puts("ATE_ERROR");
			return EINVAL;
		}
		return 0;
	}
#endif
#endif
#ifdef RTCONFIG_WIRELESS_SWITCH
	else if (!strcmp(command, "Get_WifiSwStatus")) {
		puts(nvram_safe_get("btn_wifi_sw"));
		return 0;
	}
#endif

#ifdef RTCONFIG_WIFI_TOG_BTN
	else if (!strcmp(command, "Get_WifiButtonStatus")) {
		puts(nvram_safe_get("btn_wifi_toggle"));
		return 0;
	}
#endif
#ifdef RTCONFIG_TURBO
	else if (!strcmp(command, "Get_Turbo")) {
		puts(nvram_safe_get("btn_turbo"));
		return 0;
	}
#endif
#ifdef RTCONFIG_LED_BTN
	else if (!strcmp(command, "Get_LedButtonStatus")) {
		puts(nvram_safe_get("btn_led"));
		return 0;
	}
#endif
#ifdef RTCONFIG_QTN
	else if (!strcmp(command, "Enable_Qtn_TelnetSrv")) {
		enable_qtn_telnetsrv(1);
		puts("1");
		return 0;
	}
	else if (!strcmp(command, "Disable_Qtn_TelnetSrv")) {
		enable_qtn_telnetsrv(0);
		puts("1");
		return 0;
	}
	else if (!strcmp(command, "Get_Qtn_TelnetSrv_Status")) {
		getstatus_qtn_telnetsrv();
		return 0;
	}
	else if (!strcmp(command, "Del_Qtn_Cal_Files")) {
		del_qtn_cal_files();
		puts("1");
		return 0;
	}
#endif
#ifdef CONFIG_BCMWL5
	else if (!strcmp(command, "Get_WiFiStatus_2G")) {
		if(!getWiFiStatus("2G"))
			puts("ATE_ERROR_INCORRECT_PARAMETER");
		return 0;
	}
	else if (!strcmp(command, "Get_WiFiStatus_5G")) {
		if(!getWiFiStatus("5G"))
			puts("ATE_ERROR_INCORRECT_PARAMETER");
		return 0;
	}
#else
	else if (!strcmp(command, "Get_WiFiStatus_2G")) {
		if(get_radio(0, 0))
			puts("1");
		else
			puts("0");
		return 0;
	}
#if defined(RTCONFIG_HAS_5G)
	else if (!strcmp(command, "Get_WiFiStatus_5G")) {
		if(get_radio(1, 0))
			puts("1");
		else
			puts("0");
		return 0;
	}
#endif	/* RTCONFIG_HAS_5G */
#endif
	else if (!strcmp(command, "Set_WiFiStatus_2G")) {
		int act = !strcmp(value, "on");

		if(!strcmp(value, "on") && !strcmp(value, "off"))
			puts("ATE_UNSUPPORT");

		set_radio(act, 0, 0);

		if(get_radio(0, 0)){
			if(act)
				puts("success=on");
			else
				puts("ATE_ERROR_INCORRECT_PARAMETER");
		} else{
			if(!act)
				puts("success=off");
			else
				puts("ATE_ERROR_INCORRECT_PARAMETER");
		}
		return 0;
	}
#if defined(RTCONFIG_HAS_5G)
	else if (!strcmp(command, "Set_WiFiStatus_5G")) {
		int act = !strcmp(value, "on");

		if(!strcmp(value, "on") && !strcmp(value, "off"))
			puts("ATE_UNSUPPORT");

		set_radio(act, 1, 0);

		if(get_radio(1, 0)){
			if(act)
				puts("success=on");
			else
				puts("ATE_ERROR_INCORRECT_PARAMETER");
		} else{
			if(!act)
				puts("success=off");
			else
				puts("ATE_ERROR_INCORRECT_PARAMETER");
		}
		return 0;
	}
#endif	/* RTCONFIG_HAS_5G */
	else if (!strcmp(command, "Get_ATEVersion")) {
		puts(nvram_safe_get("Ate_version"));
		return 0;
	}
	else if (!strcmp(command, "Get_XSetting")) {
		puts(nvram_safe_get("x_Setting"));
		return 0;
	}
	else if (!strcmp(command, "Get_WaitTime")) {
		puts(nvram_safe_get("wait_time"));
		return 0;
	}
	else if (!strcmp(command, "Get_ExtendNo")) {
		puts(nvram_safe_get("extendno"));
		return 0;
	}
#ifdef RTCONFIG_RALINK
	else if (!strcmp(command, "Get_DevFlags")) {
		if( Get_Device_Flags() < 0)
		{
			puts("ATE_ERROR");
			return EINVAL;
		}
		return 0;
	}
#endif
#ifdef RTCONFIG_QCA
/*
	else if (!strcmp(command, "Set_ART2")) {
		// temp solution
		system("killall rstats");
		system("killall udhcpc");
		system("killall wanduck");
		system("killall networkmap");
		system("killall -9 hostapd");
		system("ifconfig ath0 down");
		system("ifconfig ath1 down");
		system("killall -9 hostapd");
		system("brctl delif br0 ath0");
		system("brctl delif br0 ath1");
		system("wlanconfig ath0 destroy");
		system("wlanconfig ath1 destroy");
		system("ifconfig wifi0 down");
		system("ifconfig wifi1 down");
		modprobe_r("umac");
		modprobe_r("ath_dfs");
		modprobe_r("ath_dev");
		modprobe_r("ath_rate_atheros");
		modprobe_r("ath_spectral");
		modprobe_r("ath_hal");
		modprobe_r("adf");
		modprobe_r("asf");
		modprobe("art");
		system("nart.out -port 2390 -console &");
		system("nart.out -port 2391 -console &");
		return 0;
	}
*/
	else if (!strncmp(command, "Get_EEPROM_", 11)) {
		unsigned char buffer[2560];
		unsigned short len;
		int lret;
		char *pt;
		len=sizeof(buffer);
		pt = (char*) command + 11;
		if (!strcmp(pt, "2G"))
			lret=getEEPROM(&buffer[0], &len, pt);
		else if (!strcmp(pt, "5G"))
			lret=getEEPROM(&buffer[0], &len, pt);
		else if (!strcmp(pt, "CAL_2G"))
			lret=getEEPROM(&buffer[0], &len, pt);
		else if (!strcmp(pt, "CAL_5G"))
			lret=getEEPROM(&buffer[0], &len, pt);
		else {
			puts("ATE_UNSUPPORT");
			return EINVAL;
		}
		if ( !lret )
			hexdump(&buffer[0], len);
		return 0;
	}
	else if (!strcmp(command, "Get_CalCompare")) {
		unsigned char buffer[2560], buffer2[2560];
		unsigned short len, len2;
		int lret=0, cret=0;
		len=sizeof(buffer);
		len2=sizeof(buffer2);
		lret+=getEEPROM(&buffer[0], &len, "2G");
		lret+=getEEPROM(&buffer2[0], &len2, "CAL_2G");
		if (lret)
			return EINVAL;
		if ((len!=len2) || (memcmp(&buffer[0],&buffer2[0],len)!=0)) {
			puts("2G EEPROM different!");
			cret++;
		}
		len=sizeof(buffer);
		len2=sizeof(buffer2);
		lret+=getEEPROM(&buffer[0], &len, "5G");
		lret+=getEEPROM(&buffer2[0], &len2, "CAL_5G");
		if (lret)
			return EINVAL;
		if ((len!=len2) || (memcmp(&buffer[0],&buffer2[0],len)!=0)) {
			puts("5G EEPROM different!");
			cret++;
		}
		if (!cret)
			puts("1");
		else
			puts("0");
		return 0;
	}
#ifdef RTCONFIG_ATEUSB3_FORCE
	else if (!strcmp(command, "Set_ForceUSB3")) {
		if (setForceU3(value) < 0)
		{
			puts("ATE_ERROR_INCORRECT_PARAMETER");
			return EINVAL;
		}
		getForceU3();
		return 0;
	}
	else if (!strcmp(command, "Get_ForceUSB3")) {
		getForceU3();
		return 0;
	}
#endif
#endif	/* RTCONFIG_QCA */
#ifdef RT4GAC55U
	else if(!strcmp(command, "Get_GobiSimCard")) {
		char line[128];
		if (!Gobi_SimCardReady(Gobi_SimCard(line, sizeof(line))))
		{
			puts("FAIL");
			return EINVAL;
		}
		puts("PASS");
	}
	else if(!strcmp(command, "Get_GobiIMEI")) {
		char line[128];
		const char *IMEI = Gobi_IMEI(line, sizeof(line));
		if (IMEI == NULL)
		{
			puts("FAIL");
			return EINVAL;
		}
		puts(IMEI);
	}
	else if(!strcmp(command, "Get_GobiConnectISP")) {
		char line[128];
		const char *ISP = Gobi_ConnectISP(line, sizeof(line));
		if (ISP == NULL)
		{
			puts("FAIL");
			return EINVAL;
		}
		puts(ISP);
	}
	else if(!strcmp(command, "Get_GobiConnectStatus")) {
		const char *status = Gobi_ConnectStatus_Str(Gobi_ConnectStatus_Int());
		if (status == NULL)
		{
			puts("FAIL");
			return EINVAL;
		}
		puts(status);
	}
	else if(!strcmp(command, "Get_GobiSignal_Percent")) {
		int percent = Gobi_SignalQuality_Percent(Gobi_SignalQuality_Int());
		if (percent < 0)
		{
			puts("FAIL");
			return EINVAL;
		}
		printf("%d\n", percent);
	}
	else if(!strcmp(command, "Get_GobiSignal_dbm")) {
		int dbm = Gobi_SignalLevel_Int();
		if (dbm >= 0)
		{
			puts("FAIL");
			return EINVAL;
		}
		printf("%d dBm\n", dbm);
	}
	else if(!strcmp(command, "Get_GobiVersion")) {
		char line[128];
		if (Gobi_Version(line, sizeof(line)) == NULL)
		{
			puts("FAIL");
			return EINVAL;
		}
		printf("%s\n", line);
	}
#endif	/* RT4GAC55U */
	else
	{
		puts("ATE_UNSUPPORT");
		return EINVAL;
	}

	return 0;
}
Пример #21
0
void getsyspara(void)
{
	unsigned char buffer[32];
	int i;
	char macaddr[]="00:11:22:33:44:55";
	char macaddr2[]="00:11:22:33:44:56";
	char macaddr3[]="001122334457";
	char macaddr4[]="001122334458";
	char ea[ETHER_ADDR_LEN];
	char country_code[3];
	char pin[9];
	char productid[13];
	char fwver[8], fwver_sub[16];
	char blver[20];
	unsigned char txbf_para[33];
	
	/* /dev/mtd/2, RF parameters, starts from 0x40000 */
	memset(buffer, 0, sizeof(buffer));
	memset(country_code, 0, sizeof(country_code));
	memset(pin, 0, sizeof(pin));
	memset(productid, 0, sizeof(productid));
	memset(fwver, 0, sizeof(fwver));
	memset(fwver_sub, 0, sizeof(fwver_sub));
	memset(txbf_para, 0, sizeof(txbf_para));

	if (FRead(buffer, OFFSET_MAC_ADDR, 6)<0)
	{
		dbg("READ MAC address: Out of scope\n");
	}
	else
	{
		if (buffer[0]!=0xff)
		{
			ether_etoa(buffer, macaddr);
			ether_etoa2(buffer, macaddr3);
		}
	}
	
	if (FRead(buffer, OFFSET_MAC_ADDR_2G, 6)<0)
	{
		dbg("READ MAC address 2G: Out of scope\n");
	}
	else
	{
		if (buffer[0]!=0xff)
		{
			ether_etoa(buffer, macaddr2);
			ether_etoa2(buffer, macaddr4);
		}
	}

	nvram_set("il0macaddr", macaddr);
	nvram_set("il1macaddr", macaddr2);
	nvram_set("et0macaddr", macaddr);
	nvram_set("br0hexaddr", macaddr3);
	nvram_set("wanhexaddr", macaddr4);
	
	if (FRead(buffer, OFFSET_MAC_GMAC0, 6)<0)
	{
		dbg("READ MAC address GMAC0: Out of scope\n");
	}
	else
	{
		if (buffer[0]==0xff)
		{
			if (ether_atoe(macaddr, ea))
				FWrite(ea, OFFSET_MAC_GMAC0, 6);
		}
	}
	
	if (FRead(buffer, OFFSET_MAC_GMAC2, 6)<0)
	{
		dbg("READ MAC address GMAC2: Out of scope\n");
	}
	else
	{
		if (buffer[0]==0xff)
		{
			if (ether_atoe(macaddr2, ea))
				FWrite(ea, OFFSET_MAC_GMAC2, 6);
		}
	}
	
	/* reserved for Ralink. used as ASUS country code. */
	if (FRead(country_code, OFFSET_COUNTRY_CODE, 2)<0)
	{
		dbg("READ ASUS country code: Out of scope\n");
		strcpy(country_code, "GB");
	}
	else
	{
		country_code[2] = 0;
		if ((unsigned char)country_code[0]==0xff)
			strcpy(country_code, "GB");
	}
	
	if (strlen(nvram_safe_get("rt_country_code")) == 0)
	{
		nvram_set("rt_country_code", country_code);
	}
	
	if (strlen(nvram_safe_get("wl_country_code")) == 0)
	{
		nvram_set("wl_country_code", country_code);
	}
	
	if (!strcasecmp(nvram_safe_get("wl_country_code"), "BR"))
		nvram_set("wl_country_code", "UZ");
	
	/* reserved for Ralink. used as ASUS pin code. */
	if (FRead(pin, OFFSET_PIN_CODE, 8)<0)
	{
		dbg("READ ASUS pin code: Out of scope\n");
		nvram_set("wl_pin_code", "");
	}
	else
	{
		if ((unsigned char)pin[0]!=0xff)
			nvram_set("secret_code", pin);
		else
			nvram_set("secret_code", "12345670");
	}

#if defined(USE_RT3352_MII)
 #define EEPROM_INIC_SIZE (512)
 #define EEPROM_INIT_ADDR 0x48000
	{
		char eeprom[EEPROM_INIC_SIZE];
		if(FRead(eeprom, EEPROM_INIT_ADDR, sizeof(eeprom)) < 0)
		{
			dbg("READ iNIC EEPROM: Out of scope!\n");
		}
		else
		{
			FILE *fp;
			if((fp = fopen("/etc/Wireless/iNIC/iNIC_e2p.bin", "w")))
			{
				fwrite(eeprom, sizeof(eeprom), 1, fp);
				fclose(fp);
			}
		}
	}
#endif

	/* /dev/mtd/3, firmware, starts from 0x50000 */
	if (FRead(buffer, 0x50020, sizeof(buffer))<0)
	{
		dbg("READ firmware header: Out of scope\n");
		nvram_set("productid", "unknown");
		nvram_set("firmver", "unknown");
	}
	else
	{
		strncpy(productid, buffer + 4, 12);
		productid[12] = 0;
		
		if(valid_subver(buffer[27]))
			sprintf(fwver_sub, "%d.%d.%d.%d%c", buffer[0], buffer[1], buffer[2], buffer[3], buffer[27]);
		else
			sprintf(fwver_sub, "%d.%d.%d.%d", buffer[0], buffer[1], buffer[2], buffer[3]);
		
#if defined(FWBLDSTR)
		sprintf(fwver_sub, "%s-%s", fwver_sub, FWBLDSTR);
#endif
		sprintf(fwver, "%d.%d.%d.%d", buffer[0], buffer[1], buffer[2], buffer[3]);
		nvram_set("productid", trim_r(productid));
		nvram_set("firmver", trim_r(fwver));
		nvram_set("firmver_sub", trim_r(fwver_sub));
	}

	memset(buffer, 0, sizeof(buffer));
	FRead(buffer, OFFSET_BOOT_VER, 4);
	sprintf(blver, "%s-0%c-0%c-0%c-0%c", trim_r(productid), buffer[0], buffer[1], buffer[2], buffer[3]);
	nvram_set("blver", trim_r(blver));

	int count_0xff = 0;
	if (FRead(txbf_para, OFFSET_TXBF_PARA, 33) < 0)
	{
		dbg("READ TXBF PARA address: Out of scope\n");
	}
	else
	{
		for (i = 0; i < 33; i++)
		{
			if (txbf_para[i] == 0xff)
				count_0xff++;
		}
	}

	if (count_0xff == 33)
		nvram_set("wl_txbf_en", "0");
	else
		nvram_set("wl_txbf_en", "1");
}
Пример #22
0
int FWrite(char *src, int offset, int count)
{
    int i, o, fd, off, addr, sz;
    unsigned char *buf;
    struct erase_info_user ei;

    if (flash_mtd_init_info())
        return -1;

#ifdef DEBUG
    printf("%s: offset %x, src string", __func__, offset);
    for (i = 0; i < count; i++)
        printf(" %x", (unsigned char) *(src + i));
    printf("\n");
#endif
    off = offset;

    for (i = 0, addr = 0; i < NUM_INFO; i++) {
        if (addr <= off && off < addr + info[i].size) {
            sz = info[i].erasesize;
            buf = (unsigned char *)malloc(sz);
            if (buf == NULL) {
                fprintf(stderr, "failed to alloc memory for %d bytes\n",
                        sz);
                return -1;
            }
            fd = flash_mtd_open(i, O_RDWR | O_SYNC);
            if (fd < 0) {
                fprintf(stderr, "failed to open mtd%d\n", i);
                free(buf);
                return -1;
            }
            off -= addr;
            o = (off / sz) * sz;
            lseek(fd, o, SEEK_SET);
#ifdef DEBUG
            printf("  backup mtd%d, o %x(off %x), len %x\n", i, o, off, sz);
#endif
            //backup
            if (read(fd, buf, sz) != sz) {
                fprintf(stderr, "failed to read %d bytes from mtd%d\n",
                        sz, i);
                free(buf);
                close(fd);
                return -1;
            }
            //erase
            ei.start = o;
            ei.length = sz;
            if (ioctl(fd, MEMERASE, &ei) < 0) {
                fprintf(stderr, "failed to erase mtd%d\n", i);
                free(buf);
                close(fd);
                return -1;
            }
            //write
            lseek(fd, o, SEEK_SET);
#ifdef DEBUG
            for (i = 0; i < count; i++)
                printf("  buf[%x] = %x\n", off - o + i, (unsigned char)*(src + i));
            printf("\n");
#endif
//			*(buf + (off - o)) = (unsigned char)value;
            memcpy(buf + (off - o), src, count);
            if (write(fd, buf, sz) == -1) {
                fprintf(stderr, "failed to write mtd%d\n", i);
                free(buf);
                close(fd);
                return -1;
            }
            free(buf);
            close(fd);
            break;
        }
        addr += info[i].size;
    }
    buf = (unsigned char *)malloc(count);
    FRead(buf, offset, count);
    free(buf);
    return 0;
}
Пример #23
0
int main( int argc, char *argv[] )
{
	char **argv2;
	static int  *nlen;	
	static char **name, **seq;
	static char **seq1, **seq2;
	static char **mseq1, **mseq2;
	static char **aseq;
	static char **bseq;
	static double **pscore;
	static double *eff;
	int i, j, len1, len2;
	static int ***topol;
	static double **len;
	FILE *gp1, *gp2;
	char c;
	int nlenmax1, nlenmax2, nseq1, nseq2;
	int alloclen;

	argv2 = arguments( argc, argv );

	fprintf( stderr, "####### in galn\n" );

	initFiles();

	fprintf( stderr, "file1 = %s\n", argv2[0] );
	fprintf( stderr, "file2 = %s\n", argv2[1] );

	gp1 = fopen( argv2[0], "r" ); if( !gp1 ) ErrorExit( "cannot open file1" );
	gp2 = fopen( argv2[1], "r" ); if( !gp2 ) ErrorExit( "cannot open file2" );

#if 0
	PreRead( gp1, &nseq1, &nlenmax1 );
	PreRead( gp2, &nseq2, &nlenmax2 );
#else
    getnumlen( gp1 );
	nseq1 = njob; nlenmax1 = nlenmax;
    getnumlen( gp2 );
	nseq2 = njob; nlenmax2 = nlenmax;
#endif

	njob = nseq1 + nseq2;
	nlenmax = MAX( nlenmax1, nlenmax2 );

	rewind( gp1 );
	rewind( gp2 );


	name = AllocateCharMtx( njob, B );
	nlen = AllocateIntVec( njob );
	seq1 = AllocateCharMtx( nseq1, nlenmax*3 );
	seq2 = AllocateCharMtx( nseq2, nlenmax*3 );
	seq  = AllocateCharMtx( njob, 1 );
	aseq = AllocateCharMtx( njob, nlenmax*3 );
	bseq = AllocateCharMtx( njob, nlenmax*3 );
	mseq1 = AllocateCharMtx( njob, 1 );
	mseq2 = AllocateCharMtx( njob, 1 );
	alloclen = nlenmax * 3;

	topol = AllocateIntCub( njob, 2, njob );
	len = AllocateDoubleMtx( njob, 2 );
	pscore = AllocateDoubleMtx( njob, njob );
	eff = AllocateDoubleVec( njob );

#if 0
    njob=nseq2; FRead( gp2, name+nseq1, nlen+nseq1, seq2 );
	njob=nseq1; FRead( gp1, name, nlen, seq1 );
#else
    njob=nseq2; readDataforgaln( gp2, name+nseq1, nlen+nseq1, seq2 );
	njob=nseq1; readDataforgaln( gp1, name, nlen, seq1 );
#endif
	njob = nseq1 + nseq2;


#if 0  // CHUUI
	commongappick( nseq1, seq1 );
	commongappick( nseq2, seq2 );
#endif

	for( i=0; i<nseq1; i++ ) seq[i] = seq1[i];
	for( i=nseq1; i<njob; i++ ) seq[i] = seq2[i-nseq1];
/*
	Write( stdout, njob, name, nlen, seq );
*/

    constants( njob, seq );

    WriteOptions( trap_g );

    c = seqcheck( seq );
    if( c )
    {
        fprintf( stderr, "Illeagal character %c\n", c );
        exit( 1 );
    }
    for( i=1; i<nseq1; i++ ) 
    {
        if( nlen[i] != nlen[0] ) 
            ErrorExit( "group1 is not aligned." );
    }
    for( i=nseq1+1;  i<njob; i++ ) 
    {
        if( nlen[i] != nlen[nseq1] ) 
            ErrorExit( "group2 is not aligned." );
    }
    if( tbutree == 0 )
	{
		for( i=0; i<nseq1; i++ ) 
		{
			for( j=i+1; j<nseq1; j++ )
			{
				pscore[i][j] = (double)substitution_hosei( seq[i], seq[j] );
//				fprintf( stderr, "%d-%d, %5.1f \n", i, j, pscore[i][j] );
			}
			for( j=nseq1; j<njob; j++ )
			{
				pscore[i][j] = 3.0;
//				fprintf( stderr, "%d-%d, %5.1f \n", i, j, pscore[i][j] );
			}
		}
		for( i=nseq1; i<njob-1; i++ ) 
		{
			for( j=i+1; j<njob; j++ )
			{
				pscore[i][j] = (double)substitution_hosei( seq[i], seq[j] );
//				fprintf( stderr, "%d-%d, %5.1f \n", i, j, pscore[i][j] );
			}
		}
//		fprintf( stderr, "\n" );


    }
   	else
	{
		fprintf( stderr, "Not supported\n" );
		exit( 1 );
#if 0
		prep = fopen( "hat2", "r" );
		if( prep == NULL ) ErrorExit( "Make hat2." );
		readhat2( prep, njob, name, pscore );
		fclose( prep );
#endif
	}
	fprintf( stderr, "Constructing dendrogram ... " );
	if( treemethod == 'x' )
		veryfastsupg( njob, pscore, topol, len );
	else
		ErrorExit( "Incorrect tree\n" );
	fprintf( stderr, "done.\n" );

	if( tbrweight )
	{
		weight = 3;
		counteff_simple( njob, topol, len, eff );
//		for( i=0; i<njob; i++ ) fprintf( stderr, "eff[%d] = %f\n", i, eff[i] );
	}
	else
	{
		for( i=0; i<njob; i++ ) eff[i] = 1.0;
	}

	len1 = strlen( seq[0] );
	len2 = strlen( seq[nseq1] );
	if( len1 > 30000 || len2 > 30000 )
	{       
		fprintf( stderr, "\nlen1=%d, len2=%d, Switching to the memsave mode.\n", len1, len2 );
		alg = 'M';
	}       
        



	GroupAlign( nseq1, nseq2, name, nlen, seq, aseq, mseq1, mseq2, topol, len, eff, alloclen );

#if 0
	writePre( njob, name, nlen, aseq, 1 );
#else
	writeDataforgaln( stdout, njob, name, nlen, aseq );
#endif

	SHOWVERSION;
	return( 0 );
}
Пример #24
0
myBMP * loadBMP(char *name)
{
FILE * inFile = NULL;
myBMP * mybm = NULL;
BITMAPINFOHEADER bmih;
BITMAPFILEHEADER bmfh;
ubyte bmpinfoheader[64];
ulong headerSize;
int mapentrysize = 0;		/* 0 indicates no colormap */
long bPad;
ulong my_row_bytes,bmp_row_bytes;

#define LBM_cleanUp(err) do { if ( inFile ) fclose(inFile); if ( mybm ) freeBMP(mybm); return( NULL); } while(0)

#define GET_2B(array,offset) ((uword) (ubyte)(array[offset+0]) + \
						 	(((uword) (ubyte)(array[offset+1])) << 8))
#define GET_4B(array,offset) ((ulong) (ubyte)(array[offset+0]) + \
						 	(((ulong) (ubyte)(array[offset+1])) << 8) + \
						 	(((ulong) (ubyte)(array[offset+2])) << 16) + \
						 	(((ulong) (ubyte)(array[offset+3])) << 24))
	
	if ( (inFile = fopen(name,"rb")) == NULL ) 
		LBM_cleanUp("fopen");

	/* Read and verify the bitmap file header */

	if (! FReadOk(inFile, &bmfh, sizeof(BITMAPFILEHEADER)))
		LBM_cleanUp("read short");

	if ( bmfh.bfType != BM_TAG )
		LBM_cleanUp("bmp sign");

	bPad = bmfh.bfOffBits;

	/* We ignore the remaining fileheader fields */

	/* The infoheader might be 12 bytes (OS/2 1.x), 40 bytes (Windows),
	 * or 64 bytes (OS/2 2.x).	Check the first 4 bytes to find out which.
	 */
	if (! FReadOk(inFile, bmpinfoheader, 4))
		LBM_cleanUp("read short");

	headerSize = (ulong) GET_4B(bmpinfoheader,0);

	if (headerSize < 12 || headerSize > 64)
		LBM_cleanUp("bad header size");

	if (! FReadOk(inFile, bmpinfoheader+4, headerSize-4))
		LBM_cleanUp("read short");

	if ( ( mybm = new(myBMP)) == NULL )
		LBM_cleanUp("malloc");

	memcpy((char *)(&(bmih)),bmpinfoheader,	min(sizeof(BITMAPINFOHEADER),headerSize));

	switch (bmih.biBitCount) 
	{
		case 8:			/* colormapped image */
			mapentrysize = 4;		/* Windows uses RGBQUAD colormap */
			if ( bmih.biClrUsed == 0 ) bmih.biClrUsed = 256;
			break;
		case 24:			/* RGB image */
			mapentrysize = 0;
			break;
		default:
			LBM_cleanUp("bad depth");
			break;
	}

	/* Compute distance to bitmap data --- will adjust for colormap below */
	bPad -= (headerSize + 14);

	/* Read the colormap, if any */
	if (mapentrysize > 0 && bmih.biClrUsed > 0) 
	{
		RGBQUAD pal[256];
		int i;

		mybm->ncolors = bmih.biClrUsed;
		if ( mybm->ncolors > 256 ) mybm->ncolors  = 256;

		if ( (mybm->palette = malloc(256*3)) == NULL )
			LBM_cleanUp("malloc");

		if (! FReadOk(inFile, pal , (mapentrysize * mybm->ncolors)))
			LBM_cleanUp("read short");

		for(i=0;i<mybm->ncolors;i++) 
		{
			mybm->palette[i*3 + 0] = pal[i].R;
			mybm->palette[i*3 + 1] = pal[i].G;
			mybm->palette[i*3 + 2] = pal[i].B;
		}

		/* account for size of colormap */
		bPad -= mybm->ncolors * mapentrysize;
	}

	/* Skip any remaining pad bytes */
	if (bPad < 0)			/* incorrect bfOffBits value? */
		LBM_cleanUp("bad header length");
	else if ( bPad > 0 ) 
	{
		fseek(inFile,bPad,SEEK_CUR);
	}

	/* Compute row width in file, including padding to 4-byte boundary */
	if (bmih.biBitCount == 24)	my_row_bytes = bmih.biWidth * 3;
	else						my_row_bytes = bmih.biWidth;

	bmp_row_bytes = (my_row_bytes+3)&(~3) ;

	bmih.biSize = sizeof(BITMAPINFOHEADER);
	bmih.biSizeImage = bmp_row_bytes * abs(bmih.biHeight);

	mybm->width = bmih.biWidth;
	mybm->height = abs(bmih.biHeight);
	mybm->type = ( bmih.biBitCount == 24 ) ? MBTYPE_24BIT_RGB : MBTYPE_8BIT_PAL;

	mybm->dataBytes = my_row_bytes * mybm->height;

	if ( (mybm->data = malloc(mybm->dataBytes + bmp_row_bytes)) == NULL )
		LBM_cleanUp("malloc failed");

	{
	int step;
	ubyte * ptr;
	int y;
	ubyte garbage[4];

		if ( bmih.biHeight > 0 )
		{
			step = - (int)my_row_bytes;
			ptr = mybm->data + my_row_bytes * (mybm->height - 1);
		}
		else
		{
			step = my_row_bytes;
			ptr = mybm->data;
		}

		for(y=0;y<mybm->height;y++)
		{
			FRead(inFile,ptr,my_row_bytes);
			FRead(inFile,garbage,bmp_row_bytes - my_row_bytes);
			
			if (bmih.biBitCount == 24)
				swapBGRtoRGB(ptr,my_row_bytes);

			ptr += step;
		}
	}

	fclose(inFile); inFile = NULL;

return mybm;
}
Пример #25
0
int main ()
{
	GetFileTypeForExtension("");
	InitMemory();

	printf("Staring server... \n");

	// int RequestBufferSize = 1000000;
	// char *RequestBuffer = (char*)malloc(RequestBufferSize);
	// ZeroMemory(RequestBuffer, RequestBufferSize);

	socket_handle ServerSocket = INVALID_SOCKET;
	socket_handle ConnectionSocket = INVALID_SOCKET;

	InitServerSocket(&ServerSocket);

	while (TRUE)
	{
		ClearMemory();

		s32 BufferSize = KiloBytes(1);
		char *Buffer = PushMemory(BufferSize);

		ConnectionSocket = accept(ServerSocket, NULL, NULL);
		if (ConnectionSocket == INVALID_SOCKET)
		{
			printf("Accept failed \n");
		}

		int RequestBytes = recv(ConnectionSocket, Buffer, BufferSize, 0);
		if (RequestBytes > 0)
		{
			// printf("Request bytes: %i \nRequest: %s \n", RecvResult, RequestBuffer);

			server_request ServerRequest = {0};
			ServerRequest.Request = Buffer;

			char *t;
			while (t = ReadToken(&ServerRequest))
			{
				if (!strcmp(t, "GET"))
				{
					char *t1 = ReadToken(&ServerRequest);
					ServerRequest.Get = t1;
				}
				if (!strcmp(t, "Host:"))
				{
					char *t1 = ReadToken(&ServerRequest);
					ServerRequest.Host = t1;
				}

				// printf("t: %s \n", t);
			}

			printf("Request: ");
			printf(ServerRequest.Get);
			printf("\n");

			#define Headers "HTTP/1.1 %i OK\r\n"\
							"Date: %s\r\n"\
							"Server: Linux\r\n"\
							"Accept-Ranges: none\r\n"\
							"Content-Type: %s\r\n"\
							"Content-Length: %i\r\n"\
							"Connection: close\r\n"\
							"\r\n""\0"



			char *Output = PushMemory(KiloBytes(20));
			if (ServerRequest.Get[0] == '/')
			{
				++ServerRequest.Get;
			}
			file_data FileData;
			char *FileName;
			if (*ServerRequest.Get)
			{
				FileName = ServerRequest.Get;
			}
			else
			{
				FileName = "index.html";
			}

			time_t tm;
			time(&tm);
			char *Date = PushMemory(KiloBytes(1));
			strftime(Date, KiloBytes(1), "%a, %d %b %Y %X GMT", localtime(&tm));

			char *Ext = strrchr(FileName, '.');
			if (!Ext)
			{
				char *fn = PushMemory(strlen(FileName) + 6);
				//FileName = fn;
				strcat(fn, FileName);
				strcat(fn, ".html\0");
				if (FExists(fn))
				{
					FileName = fn;
				}
			}

			FileData = FRead(FileName);

			// TODO: handle video files
			if (FileData.Data && strcmp(FileName, "404.html") && strcmp(FileName, "404"))
			{
				// char *Ext = PathFindExtensionA(FileName);
				char *Ext = strrchr(FileName, '.');
				char *HttpFileType;
				HttpFileType = GetFileTypeForExtension(Ext + 1);
				if (!HttpFileType)
				{
					HttpFileType = "text/html";
				}

				sprintf(Output, Headers, 200, Date, HttpFileType, FileData.Size);
				// memcpy(Output + strlen(Output), FileData.Data, FileData.Size);
				int SendResult;
				s32 HeaderBytesSent = send(ConnectionSocket, Output, strlen(Output), 0);
				s32 DataBytesSent = send(ConnectionSocket, FileData.Data, FileData.Size, 0);
				printf("HeaderBytesSent: %i \n", HeaderBytesSent);
				printf("DataBytesSent: %i \n", DataBytesSent);
				if (SendResult == SOCKET_ERROR)
				{
					printf("Send to client failed \n");
				}
				// SendResult = send(ConnectionSocket, FileData.Data, FileData.Size, 0);
				if (SendResult == SOCKET_ERROR)
				{
					printf("Send to client failed \n");
				}

#if 0
				FILE *f;
				f = fopen("assets/test.bmp", "w");
				if (f)
				{
					fwrite(FileData.Data, sizeof(char), FileData.Size, f);
					fclose(f);
				}
#endif
			}
			else
			{
				// char *PageNotFoundText = "<h1>Page not found</h1>";
				file_data File404 = FRead("404.html");
				if (File404.Data)
				{
					sprintf(Output, Headers, 404, Date, "text/html", File404.Size);
					int SendResult = send(ConnectionSocket, Output, strlen(Output), 0);
					send(ConnectionSocket, File404.Data, File404.Size, 0);
					if (SendResult == SOCKET_ERROR)
					{
						printf("Send to client failed \n");
					}
				}
			}
			
			closesocket(ConnectionSocket);

		}
		else
		{
			closesocket(ConnectionSocket);
		}
	}

	system("pause");
	return 0;
}
Пример #26
0
bool vtTin::ReadADF(const char *fname, bool progress_callback(int))
{
	const vtString tnxy_name = fname;
	if (tnxy_name.Right(6) != "xy.adf")
		return false;

	vtString base = tnxy_name.Left(tnxy_name.GetLength()-6);
	vtString tnz_name = base + "z.adf";
	vtString tnod_name = base + "od.adf";

	FILE *fp1 = vtFileOpen(tnxy_name, "rb");
	FILE *fp2 = vtFileOpen(tnz_name, "rb");
	FILE *fp3 = vtFileOpen(tnod_name, "rb");
	if (!fp1 || !fp2 || !fp3)
		return false;

	fseek(fp1, 0, SEEK_END);
	const int length_xy = ftell(fp1);
	rewind(fp1);	// go back again
	uint num_points = length_xy / 16;	// X and Y, each 8 byte doubles

	fseek(fp2, 0, SEEK_END);
	const int length_z = ftell(fp2);
	rewind(fp2);	// go back again
	uint num_heights = length_z / 4;		// Z is a 4 byte float

	DPoint2 p;
	float z;
	for (uint i = 0; i < num_points; i++)
	{
		if ((i%200) == 0 && progress_callback != NULL)
			progress_callback(i * 40 / num_points);

		FRead(&p.x, DT_DOUBLE, 2, fp1, BO_BIG_ENDIAN, BO_LITTLE_ENDIAN);
		FRead(&z, DT_FLOAT, 1, fp2, BO_BIG_ENDIAN, BO_LITTLE_ENDIAN);
		AddVert(p, z);
	}

	fseek(fp3, 0, SEEK_END);
	const int length_od = ftell(fp3);
	rewind(fp3);	// go back again
	const uint num_faces = length_od / 12;		// A B C as 4-byte ints

	int v[3];
	for (uint i = 0; i < num_faces; i++)
	{
		if ((i%200) == 0 && progress_callback != NULL)
			progress_callback(40 + i * 40 / num_faces);

		FRead(v, DT_INT, 3, fp3, BO_BIG_ENDIAN, BO_LITTLE_ENDIAN);
		AddTri(v[0]-1, v[1]-1, v[2]-1);
	}

	fclose(fp1);
	fclose(fp2);
	fclose(fp3);

	// Cleanup: the ESRI TIN contains four "boundary" point far outside the
	//  extents (directly North, South, East, and West).  We should ignore
	//  those four points and the triangles connected to them.
	// It seems we can assume the four 'extra' vertices are the first four.
	m_vert.RemoveAt(0, 4);
	m_z.erase(m_z.begin(), m_z.begin() + 4);
	m_vert_normal.RemoveAt(0, 4);

	// Re-index the triangles
	uint total = m_tri.size()/3;
	for (uint i = 0; i < total; i++)
	{
		if ((i%200) == 0 && progress_callback != NULL)
			progress_callback(80 + i * 20 / total);

		// Remove any triangles which referenced this vertex
		if (m_tri[i*3 + 0] < 4 ||
			m_tri[i*3 + 1] < 4 ||
			m_tri[i*3 + 2] < 4)
		{
			m_tri.erase(m_tri.begin() + i*3, m_tri.begin() + i*3 + 3);
			i--;
			total--;
			continue;
		}
	}
	// For all other triangles, adjust the indices to reflect the removal
	for (uint i = 0; i < m_tri.size(); i++)
		m_tri[i] = m_tri[i] - 4;

	// Test each triangle for clockwisdom, fix if needed
	CleanupClockwisdom();

	ComputeExtents();

	return true;
}
Пример #27
0
void ami_fetch_file_poll(const char *scheme_ignored)
{
	struct nsObject *node;
	struct nsObject *nnode;
	struct ami_file_fetch_info *fetch;
	fetch_error_code errorcode;
	
	if(IsMinListEmpty(ami_file_fetcher_list)) return;

	node = (struct nsObject *)GetHead((struct List *)ami_file_fetcher_list);

	do
	{
		errorcode = FETCH_ERROR_NO_ERROR;
		nnode=(struct nsObject *)GetSucc((struct Node *)node);

		fetch = (struct ami_file_fetch_info *)node->objstruct;

		if(fetch->locked) continue;

		if(!fetch->aborted)
		{
			if(fetch->fh)
			{
				ULONG len;

				len = FRead(fetch->fh,ami_file_fetcher_buffer,1,1024);

				if (len == (ULONG)-1)
					errorcode = FETCH_ERROR_MISC;
				else if (len > 0)
					ami_fetch_file_send_callback(
							FETCH_DATA, fetch,
							ami_file_fetcher_buffer,
							len, errorcode);

				if((len<1024) && (!fetch->aborted))
				{
					ami_fetch_file_send_callback(FETCH_FINISHED,
						fetch, NULL, 0,
						errorcode);

					fetch->aborted = true;
				}
			}
			else
			{
				fetch->fh = FOpen(fetch->path,MODE_OLDFILE,0);

				if(fetch->fh)
				{
					char header[64];
					struct ExamineData *fib;
					if(fib = ExamineObjectTags(EX_FileHandleInput,fetch->fh,TAG_DONE))
					{
						fetch->len = fib->FileSize;
						FreeDosObject(DOS_EXAMINEDATA,fib);
					}

					fetch_set_http_code(fetch->fetch_handle,200);
					fetch->mimetype = fetch_mimetype(fetch->path);
					LOG(("mimetype %s len %ld",fetch->mimetype,fetch->len));

					snprintf(header, sizeof header,
							"Content-Type: %s",
							fetch->mimetype);
					ami_fetch_file_send_callback(FETCH_HEADER,
						fetch, header, strlen(header), errorcode);

					snprintf(header, sizeof header,
							"Content-Length: %ld",
							fetch->len);
					ami_fetch_file_send_callback(FETCH_HEADER,
						fetch, header, strlen(header), errorcode);

				}
				else
				{
					STRPTR errorstring;

					errorstring = ASPrintf("%s %s",messages_get("FileError"),fetch->path);
					fetch_set_http_code(fetch->fetch_handle,404);
					
					errorcode = FETCH_ERROR_HTTP_NOT2;
					ami_fetch_file_send_callback(FETCH_ERROR, fetch,
						errorstring, 0,
						errorcode);
					fetch->aborted = true;
					FreeVec(errorstring);
				}
			}
		}

		if(fetch && fetch->aborted)
		{
			fetch_remove_from_queues(fetch->fetch_handle);
			fetch_free(fetch->fetch_handle);
			return;
		}
	}while(node=nnode);
}
Пример #28
0
void init_syspara(void)
{
	unsigned char buffer[16];
	unsigned int *src;
	char *dst;
	unsigned int bytes;
	int i;
	char macaddr[]="00:11:22:33:44:55";
	char macaddr2[]="00:11:22:33:44:58";
	char country_code[3];
	char pin[9];
	char productid[13];
	char fwver[8];
	char blver[20];
	unsigned char txbf_para[33];
	char ea[ETHER_ADDR_LEN];

	nvram_set("buildno", rt_serialno);
	nvram_set("extendno", rt_extendno);
	nvram_set("buildinfo", rt_buildinfo);

	/* /dev/mtd/2, RF parameters, starts from 0x40000 */
	dst = buffer;
	bytes = 6;
	memset(buffer, 0, sizeof(buffer));
	memset(country_code, 0, sizeof(country_code));
	memset(pin, 0, sizeof(pin));
	memset(productid, 0, sizeof(productid));
	memset(fwver, 0, sizeof(fwver));
	memset(txbf_para, 0, sizeof(txbf_para));

	if (FRead(dst, OFFSET_MAC_ADDR, bytes)<0)
	{
		_dprintf("READ MAC address: Out of scope\n");
	}
	else
	{
		if (buffer[0]!=0xff)
			ether_etoa(buffer, macaddr);
	}

	if (FRead(dst, OFFSET_MAC_ADDR_2G, bytes)<0)
	{
		_dprintf("READ MAC address 2G: Out of scope\n");
	}
	else
	{
		if (buffer[0]!=0xff)
			ether_etoa(buffer, macaddr2);
	}

	if (!ralink_mssid_mac_validate(macaddr) || !ralink_mssid_mac_validate(macaddr2))
		nvram_set("wl_mssid", "0");
	else
		nvram_set("wl_mssid", "1");

	//TODO: separate for different chipset solution
	nvram_set("et0macaddr", macaddr);
	nvram_set("et1macaddr", macaddr2);
	

	if (FRead(dst, OFFSET_MAC_GMAC0, bytes)<0)
		dbg("READ MAC address GMAC0: Out of scope\n");
	else
	{
		if (buffer[0]==0xff)
		{
			if (ether_atoe(macaddr, ea))
				FWrite(ea, OFFSET_MAC_GMAC0, 6);
		}
	}

	if (FRead(dst, OFFSET_MAC_GMAC2, bytes)<0)
		dbg("READ MAC address GMAC2: Out of scope\n");
	else
	{
		if (buffer[0]==0xff)
		{
			if (ether_atoe(macaddr2, ea))
				FWrite(ea, OFFSET_MAC_GMAC2, 6);
		}
	}

	/* reserved for Ralink. used as ASUS country code. */
	dst = country_code;
	bytes = 2;
	if (FRead(dst, OFFSET_COUNTRY_CODE, bytes)<0)
	{
		_dprintf("READ ASUS country code: Out of scope\n");
		nvram_set("wl_country_code", "");
	}
	else
	{
		if ((unsigned char)country_code[0]!=0xff)
		{ 
		   //for specific power
		        if (country_code[0] ==0x5a  && country_code[1] == 0x31)
			{
			   country_code[0]='U';
			   country_code[1]='S';
			}   
			else if (country_code[0] ==0x5a  && country_code[1] == 0x32)
			{
			   country_code[0]='G';
			   country_code[1]='B';
			}   
			else if (country_code[0] ==0x5a  && country_code[1] == 0x33)
			{
			   country_code[0]='T';
			   country_code[1]='W';
			}   
			else if (country_code[0] ==0x5a  && country_code[1] == 0x34)
			{
			   country_code[0]='C';
			   country_code[1]='N';
			}   
			   
			nvram_set("wl_country_code", country_code);
			nvram_set("wl0_country_code", country_code);
			nvram_set("wl1_country_code", country_code);
		}
		else
		{
			nvram_set("wl_country_code", "DB");
			nvram_set("wl0_country_code", "DB");
			nvram_set("wl1_country_code", "DB");
		}

		if (!strcasecmp(nvram_safe_get("wl_country_code"), "BR"))
		{
			nvram_set("wl_country_code", "UZ");
			nvram_set("wl0_country_code", "UZ");
			nvram_set("wl1_country_code", "UZ");
		}

		if (nvram_match("wl_country_code", "HK") && nvram_match("preferred_lang", ""))
			nvram_set("preferred_lang", "TW");
	}

	/* reserved for Ralink. used as ASUS pin code. */
	dst = (char*)pin;
	bytes = 8;
	if (FRead(dst, OFFSET_PIN_CODE, bytes)<0)
	{
		_dprintf("READ ASUS pin code: Out of scope\n");
		nvram_set("wl_pin_code", "");
	}
	else
	{
		if ((unsigned char)pin[0]!=0xff)
			nvram_set("secret_code", pin);
		else
			nvram_set("secret_code", "12345670");
	}

	src = (unsigned int*) 0x50020;	/* /dev/mtd/3, firmware, starts from 0x50000 */
	dst = buffer;
	bytes = 16;
	if (FRead(dst, (int)src, bytes)<0)
	{
		fprintf(stderr, "READ firmware header: Out of scope\n");
		nvram_set("productid", "unknown");
		nvram_set("firmver", "unknown");
	}
	else
	{
		strncpy(productid, buffer + 4, 12);
		productid[12] = 0;
		sprintf(fwver, "%d.%d.%d.%d", buffer[0], buffer[1], buffer[2], buffer[3]);
		nvram_set("productid", trim_r(productid));
		nvram_set("firmver", trim_r(fwver));
	}

	memset(buffer, 0, sizeof(buffer));
	FRead(buffer, OFFSET_BOOT_VER, 4);
//	sprintf(blver, "%c.%c.%c.%c", buffer[0], buffer[1], buffer[2], buffer[3]);
	sprintf(blver, "%s-0%c-0%c-0%c-0%c", trim_r(productid), buffer[0], buffer[1], buffer[2], buffer[3]);
	nvram_set("blver", trim_r(blver));

	_dprintf("bootloader version: %s\n", nvram_safe_get("blver"));
	_dprintf("firmware version: %s\n", nvram_safe_get("firmver"));

	dst = txbf_para;
	int count_0xff = 0;
	if (FRead(dst, OFFSET_TXBF_PARA, 33) < 0)
	{
		fprintf(stderr, "READ TXBF PARA address: Out of scope\n");
	}
	else
	{
		for (i = 0; i < 33; i++)
		{
			if (txbf_para[i] == 0xff)
				count_0xff++;
/*
			if ((i % 16) == 0) fprintf(stderr, "\n");
			fprintf(stderr, "%02x ", (unsigned char) txbf_para[i]);
*/
		}
/*
		fprintf(stderr, "\n");

		fprintf(stderr, "TxBF parameter 0xFF count: %d\n", count_0xff);
*/
	}

	if (count_0xff == 33)
		nvram_set("wl1_txbf_en", "0");
	else
		nvram_set("wl1_txbf_en", "1");

#if defined (RTCONFIG_WLMODULE_RT3352_INIC_MII)
#define EEPROM_INIC_SIZE (512)
#define EEPROM_INIT_ADDR 0x48000
#define EEPROM_INIT_FILE "/etc/Wireless/iNIC/iNIC_e2p.bin"
	{
		char eeprom[EEPROM_INIC_SIZE];
		if(FRead(eeprom, EEPROM_INIT_ADDR, sizeof(eeprom)) < 0)
		{
			fprintf(stderr, "FRead(eeprom, 0x%08x, 0x%x) failed\n", EEPROM_INIT_ADDR, sizeof(eeprom));
		}
		else
		{
			FILE *fp;
			char *filepath = EEPROM_INIT_FILE;

			system("mkdir -p /etc/Wireless/iNIC/");
			if((fp = fopen(filepath, "w")) == NULL)
			{
				fprintf(stderr, "fopen(%s) failed!!\n", filepath);
			}
			else
			{
				if(fwrite(eeprom, sizeof(eeprom), 1, fp) < 1)
				{
					perror("fwrite(eeprom)");
				}
				fclose(fp);
			}
		}
	}
#endif

	{
#ifdef RTCONFIG_ODMPID
		char modelname[16];
		FRead(modelname, OFFSET_ODMPID, sizeof(modelname));
		modelname[sizeof(modelname)-1] = '\0';
		if(modelname[0] != 0 && (unsigned char)(modelname[0]) != 0xff && is_valid_hostname(modelname))
		{
			nvram_set("odmpid", modelname);
		}
		else
#endif
			nvram_unset("odmpid");
	}

	nvram_set("firmver", rt_version);
	nvram_set("productid", rt_buildname);
}