- Corrected whitespace formatting with Astyle tool.

git-svn-id: https://svn.code.sf.net/p/openblt/code/trunk@132 5dc33758-31d5-4daf-9ae8-b24bf3d40d73
This commit is contained in:
Frank Voorburg 2016-03-01 14:24:23 +00:00
parent efbab9c73d
commit 90b766c778
173 changed files with 41206 additions and 38694 deletions

20
Doc/astyle.bat Normal file
View File

@ -0,0 +1,20 @@
@echo off
rem Configuration file for Astyle. Can be downloaded from: https://sourceforge.net/projects/astyle/?source=typ_redirect
rem Example usage: C:\Work\software\OpenBLT\Target\Source>..\..\Doc\astyle.bat *.c *.h
set ASTYLE_BIN="C:\AStyle\bin"
set ASTYLE_CODESTYLE_PARAMS=--mode=c --style=allman --indent=spaces=2 --indent-switches --pad-header --unpad-paren --lineend=windows --add-brackets --align-pointer=name
set ASTYLE_EXECUTION_PARAMS=--suffix=none --formatted --ignore-exclude-errors-x --recursive
echo.
echo ------------------ prepare astyle ---------------------------------------------
echo.
%ASTYLE_BIN%\AStyle.exe --version
echo style params: %ASTYLE_CODESTYLE_PARAMS%
echo exec params : %ASTYLE_EXECUTION_PARAMS%
echo user params : %*
echo target dir : %CD%
echo.
echo ------------------ astyle execution -------------------------------------------
echo.
%ASTYLE_BIN%\AStyle.exe %ASTYLE_CODESTYLE_PARAMS% %ASTYLE_EXECUTION_PARAMS% %*
echo.
echo ------------------ astyle done ------------------------------------------------

View File

@ -111,7 +111,8 @@ typedef struct t_can_bus_timing
* a sample point between 68..78%.
*/
static const tCanBusTiming canTiming[] =
{ /* TQ | TSEG1 | TSEG2 | SP */
{
/* TQ | TSEG1 | TSEG2 | SP */
/* ------------------------- */
{ 5, 2 }, /* 8 | 5 | 2 | 75% */
{ 6, 2 }, /* 9 | 6 | 2 | 78% */

View File

@ -147,7 +147,8 @@ typedef struct t_can_bus_timing
* a sample point between 68..78%.
*/
static const tCanBusTiming canTiming[] =
{ /* TQ | TSEG1 | TSEG2 | SP */
{
/* TQ | TSEG1 | TSEG2 | SP */
/* ------------------------- */
{ 5, 2 }, /* 8 | 5 | 2 | 75% */
{ 6, 2 }, /* 9 | 6 | 2 | 78% */

View File

@ -156,7 +156,8 @@ typedef struct t_can_bus_timing
* a sample point between 68..78%.
*/
static const tCanBusTiming canTiming[] =
{ /* TQ | TSEG1 | TSEG2 | SP */
{
/* TQ | TSEG1 | TSEG2 | SP */
/* ------------------------- */
{ 5, 2 }, /* 8 | 5 | 2 | 75% */
{ 6, 2 }, /* 9 | 6 | 2 | 78% */

View File

@ -132,188 +132,290 @@ static void Init(void)
/* 2) copy initialization data from ROM to RAM */
/* 3) call global constructors in C++ */
/* called from: _Startup, LibInits */
asm {
asm
{
ZeroOut:
#if defined(__HIWARE_OBJECT_FILE_FORMAT__) && defined(__LARGE__)
LDX _startupData.pZeroOut:1 ; in the large memory model in the HIWARE format, pZeroOut is a 24 bit pointer
LDX _startupData.pZeroOut:1 ;
in the large memory model in the HIWARE format, pZeroOut is a 24 bit pointer
#else
LDX _startupData.pZeroOut ; *pZeroOut
LDX _startupData.pZeroOut ;
*pZeroOut
#endif
LDY _startupData.nofZeroOuts ; nofZeroOuts
BEQ CopyDown ; if nothing to zero out
LDY _startupData.nofZeroOuts ;
nofZeroOuts
BEQ CopyDown ;
if nothing to zero out
NextZeroOut: PSHY ; save nofZeroOuts
NextZeroOut: PSHY ;
save nofZeroOuts
#if defined(FAR_DATA)
LDAB 1,X+ ; load page of destination address
LDY 2,X+ ; load offset of destination address
LDAB 1,X+ ;
load page of destination address
LDY 2,X+ ;
load offset of destination address
#if defined(__HCS12X__)
STAB __GPAGE_ADR__
#else /* defined(__HCS12X__) */
__PIC_JSR(_SET_PAGE) ; sets the page in the correct page register
__PIC_JSR(_SET_PAGE) ;
sets the page in the correct page register
#endif /* defined(__HCS12X__) */
#else /* FAR_DATA */
LDY 2,X+ ; start address and advance *pZeroOut (X = X+4)
LDY 2,X+ ;
start address and advance *pZeroOut(X = X+4)
#endif /* FAR_DATA */
#if defined(__HCS12X__) && defined(FAR_DATA)
PSHX
LDX 0,X ; byte count
LDX 0,X ;
byte count
#if defined(__OPTIMIZE_FOR_SIZE__)
CLRA
NextWord: GSTAA 1,Y+ ; clear memory byte
__FEED_COP_IN_HLI() ; feed the COP if necessary /*lint !e505 !e522 asm code */
DBNE X, NextWord ; dec byte count
NextWord:
GSTAA 1,Y+ ;
clear memory byte
__FEED_COP_IN_HLI() ;
feed the COP if necessary /*lint !e505 !e522 asm code */
DBNE X, NextWord ;
dec byte count
#else
LDD #0
LSRX
BEQ LoopClrW1 ; do we copy more than 1 byte?
NextWord: GSTD 2,Y+ ; clear memory word
__FEED_COP_IN_HLI() ; feed the COP if necessary /*lint !e505 !e522 asm code */
DBNE X, NextWord ; dec word count
BEQ LoopClrW1 ;
do we copy more than 1 byte?
NextWord: GSTD 2,Y+ ;
clear memory word
__FEED_COP_IN_HLI() ;
feed the COP if necessary /*lint !e505 !e522 asm code */
DBNE X, NextWord ;
dec word count
LoopClrW1:
BCC LastClr ; handle last byte
GSTAA 1,Y+ ; handle last byte
BCC LastClr ;
handle last byte
GSTAA 1,Y+ ;
handle last byte
LastClr:
#endif
PULX
LEAX 2,X
#elif defined(__OPTIMIZE_FOR_SIZE__) /* -os, default */
LDD 2,X+ ; byte count
NextWord: CLR 1,Y+ ; clear memory byte
__FEED_COP_IN_HLI() ; feed the COP if necessary /*lint !e505 !e522 asm code */
DBNE D, NextWord ; dec byte count
LDD 2,X+ ;
byte count
NextWord:
CLR 1,Y+ ;
clear memory byte
__FEED_COP_IN_HLI() ;
feed the COP if necessary /*lint !e505 !e522 asm code */
DBNE D, NextWord ;
dec byte count
#else /* __OPTIMIZE_FOR_TIME__ */
LDD 2,X+ ; byte count
LSRD ; /2 and save bit 0 in the carry
BEQ LoopClrW1 ; do we copy more than 1 byte?
LDD 2,X+ ;
byte count
LSRD ;
/2 and save bit 0 in the carry
BEQ LoopClrW1 ;
do we copy more than 1 byte?
PSHX
LDX #0
LoopClrW: STX 2,Y+ ; Word-Clear
__FEED_COP_IN_HLI() ; feed the COP if necessary /*lint !e505 !e522 asm code */
LoopClrW: STX 2,Y+ ;
Word-Clear
__FEED_COP_IN_HLI() ;
feed the COP if necessary /*lint !e505 !e522 asm code */
DBNE D, LoopClrW
PULX
LoopClrW1:
BCC LastClr ; handle last byte
BCC LastClr ;
handle last byte
CLR 1,Y+
LastClr:
#endif /* __OPTIMIZE_FOR_SIZE__/__OPTIMIZE_FOR_TIME__ */
PULY ; restore nofZeroOuts
DEY ; dec nofZeroOuts
PULY ;
restore nofZeroOuts
DEY ;
dec nofZeroOuts
BNE NextZeroOut
CopyDown:
#if defined(__BANKED_COPY_DOWN)
LDAA _startupData.toCopyDownBeg:0 ; get PAGE address of .copy section
STAA __PPAGE_ADR__ ; set PPAGE address
LDX _startupData.toCopyDownBeg:1 ; load address of copy down desc.
LDAA _startupData.toCopyDownBeg:0 ;
get PAGE address of .copy section
STAA __PPAGE_ADR__ ;
set PPAGE address
LDX _startupData.toCopyDownBeg:1 ;
load address of copy down desc.
#elif defined(__ELF_OBJECT_FILE_FORMAT__)
LDX _startupData.toCopyDownBeg ; load address of copy down desc.
LDX _startupData.toCopyDownBeg ;
load address of copy down desc.
#else
LDX _startupData.toCopyDownBeg:2 ; load address of copy down desc.
LDX _startupData.toCopyDownBeg:2 ;
load address of copy down desc.
#endif
NextBlock:
LDD 2,X+ ; size of init-data -> D
BEQ funcInits ; end of copy down desc.
LDD 2,X+ ;
size of init-data -> D
BEQ funcInits ;
end of copy down desc.
#ifdef FAR_DATA
PSHD ; save counter
LDAB 1,X+ ; load destination page
LDY 2,X+ ; destination address
PSHD ;
save counter
LDAB 1,X+ ;
load destination page
LDY 2,X+ ;
destination address
#if defined(__HCS12X__)
STAB __GPAGE_ADR__
#else /* __HCS12X__ */
__PIC_JSR(_SET_PAGE) ; sets the destinations page register
__PIC_JSR(_SET_PAGE) ;
sets the destinations page register
#endif /* __HCS12X__ */
PULD ; restore counter
PULD ;
restore counter
#else /* FAR_DATA */
LDY 2,X+ ; load destination address
LDY 2,X+ ;
load destination address
#endif /* FAR_DATA */
#if defined(__HCS12X__) && defined(FAR_DATA)
#if defined(__OPTIMIZE_FOR_SIZE__) /* -os, default */
Copy: PSHA
Copy:
PSHA
LDAA 1,X+
GSTAA 1,Y+ ; move a byte from ROM to the data area
GSTAA 1,Y+ ;
move a byte from ROM to the data area
PULA
__FEED_COP_IN_HLI() ; feed the COP if necessary /*lint !e505 !e522 asm code */
DBNE D,Copy ; copy-byte loop
__FEED_COP_IN_HLI() ;
feed the COP if necessary /*lint !e505 !e522 asm code */
DBNE D,Copy ;
copy-byte loop
#else
LSRD ; /2 and save bit 0 in the carry
BEQ Copy1 ; do we copy more than 1 byte?
LSRD ;
/2 and save bit 0 in the carry
BEQ Copy1 ;
do we copy more than 1 byte?
Copy: PSHD
LDD 2,X+
GSTD 2,Y+ ; move a word from ROM to the data area
GSTD 2,Y+ ;
move a word from ROM to the data area
PULD
__FEED_COP_IN_HLI() ; feed the COP if necessary /*lint !e505 !e522 asm code */
DBNE D,Copy ; copy-word loop
__FEED_COP_IN_HLI() ;
feed the COP if necessary /*lint !e505 !e522 asm code */
DBNE D,Copy ;
copy-word loop
Copy1:
BCC NextBlock ; handle last byte?
BCC NextBlock ;
handle last byte?
LDAA 1,X+
GSTAA 1,Y+ ; move a byte from ROM to the data area
GSTAA 1,Y+ ;
move a byte from ROM to the data area
#endif
#elif defined(__OPTIMIZE_FOR_SIZE__) /* -os, default */
Copy: MOVB 1,X+,1,Y+ ; move a byte from ROM to the data area
__FEED_COP_IN_HLI() ; feed the COP if necessary /*lint !e505 !e522 asm code */
DBNE D,Copy ; copy-byte loop
Copy:
MOVB 1,X+,1,Y+ ;
move a byte from ROM to the data area
__FEED_COP_IN_HLI() ;
feed the COP if necessary /*lint !e505 !e522 asm code */
DBNE D,Copy ;
copy-byte loop
#else /* __OPTIMIZE_FOR_TIME__ */
LSRD ; /2 and save bit 0 in the carry
BEQ Copy1 ; do we copy more than 1 byte?
Copy: MOVW 2,X+,2,Y+ ; move a word from ROM to the data area
__FEED_COP_IN_HLI() ; feed the COP if necessary /*lint !e505 !e522 asm code */
DBNE D,Copy ; copy-word loop
LSRD ;
/2 and save bit 0 in the carry
BEQ Copy1 ;
do we copy more than 1 byte?
Copy: MOVW 2,X+,2,Y+ ;
move a word from ROM to the data area
__FEED_COP_IN_HLI() ;
feed the COP if necessary /*lint !e505 !e522 asm code */
DBNE D,Copy ;
copy-word loop
Copy1:
BCC NextBlock ; handle last byte?
MOVB 1,X+,1,Y+ ; copy the last byte
BCC NextBlock ;
handle last byte?
MOVB 1,X+,1,Y+ ;
copy the last byte
#endif /* __OPTIMIZE_FOR_SIZE__/__OPTIMIZE_FOR_TIME__ */
BRA NextBlock
funcInits: ; call of global construtors is only in c++ necessary
funcInits:
;
call of global construtors is only in c++ necessary
#if defined(__cplusplus)
#if defined(__ELF_OBJECT_FILE_FORMAT__)
#if defined( __BANKED__) || defined(__LARGE__)
LDY _startupData.nofInitBodies; load number of cpp.
BEQ done ; if cppcount == 0, goto done
LDX _startupData.initBodies ; load address of first module to initialize
LDY _startupData.nofInitBodies;
load number of cpp.
BEQ done ;
if cppcount == 0, goto done
LDX _startupData.initBodies ;
load address of first module to initialize
nextInit:
LEAX 3,X ; increment to next init
PSHX ; save address of next function to initialize
PSHY ; save cpp counter
CALL [-3,X] ; use double indirect call to load the page register also
PULY ; restore cpp counter
PULX ; restore actual address
DEY ; decrement cpp counter
LEAX 3,X ;
increment to next init
PSHX ;
save address of next function to initialize
PSHY ;
save cpp counter
CALL [-3,X] ;
use double indirect call to load the page register also
PULY ;
restore cpp counter
PULX ;
restore actual address
DEY ;
decrement cpp counter
BNE nextInit
#else /* defined( __BANKED__) || defined(__LARGE__) */
LDD _startupData.nofInitBodies; load number of cpp.
BEQ done ; if cppcount == 0, goto done
LDX _startupData.initBodies ; load address of first module to initialize
LDD _startupData.nofInitBodies;
load number of cpp.
BEQ done ;
if cppcount == 0, goto done
LDX _startupData.initBodies ;
load address of first module to initialize
nextInit:
LDY 2,X+ ; load address of first module to initialize
LDY 2,X+ ;
load address of first module to initialize
PSHD
PSHX ; save actual address
JSR 0,Y ; call initialization function
PULX ; restore actual address
PULD ; restore cpp counter
PSHX ;
save actual address
JSR 0,Y ;
call initialization function
PULX ;
restore actual address
PULD ;
restore cpp counter
DBNE D, nextInit
#endif /* defined( __BANKED__) || defined(__LARGE__) */
#else /* __ELF_OBJECT_FILE_FORMAT__ */
LDX _startupData.mInits ; load address of first module to initialize
LDX _startupData.mInits ;
load address of first module to initialize
#if defined( __BANKED__) || defined(__LARGE__)
nextInit: LDY 3,X+ ; load address of initialization function
BEQ done ; stop when address == 0
; in common environments the offset of a function is never 0, so this test could be avoided
nextInit:
LDY 3,X+ ;
load address of initialization function
BEQ done ;
stop when address == 0
;
in common environments the offset of a function is never 0, so this test could be avoided
#ifdef __InitFunctionsMayHaveOffset0__
BRCLR -1,X, done, 0xff ; stop when address == 0
BRCLR -1,X, done, 0xff ;
stop when address == 0
#endif /* __InitFunctionsMayHaveOffset0__ */
PSHX ; save address of next function to initialize
CALL [-3,X] ; use double indirect call to load the page register also
PSHX ;
save address of next function to initialize
CALL [-3,X] ;
use double indirect call to load the page register also
#else /* defined( __BANKED__) || defined(__LARGE__) */
nextInit:
LDY 2,X+ ; load address of first module to initialize
BEQ done ; stop when address of function == 0
PSHX ; save actual address
JSR 0,Y ; call initialization function
LDY 2,X+ ;
load address of first module to initialize
BEQ done ;
stop when address of function == 0
PSHX ;
save actual address
JSR 0,Y ;
call initialization function
#endif /* defined( __BANKED__) || defined(__LARGE__) */
PULX ; restore actual address
PULX ;
restore actual address
BRA nextInit
#endif /* __ELF_OBJECT_FILE_FORMAT__ */
done:
@ -331,33 +433,52 @@ static void Fini(void)
#endif
{
/* purpose: 1) call global destructors in C++ */
asm {
asm
{
#if defined( __BANKED__) || defined(__LARGE__)
LDY _startupData.nofFiniBodies; load number of cpp.
BEQ done ; if cppcount == 0, goto done
LDX _startupData.finiBodies ; load address of first module to finalize
LDY _startupData.nofFiniBodies;
load number of cpp.
BEQ done ;
if cppcount == 0, goto done
LDX _startupData.finiBodies ;
load address of first module to finalize
nextInit2:
LEAX 3,X ; increment to next init
PSHX ; save address of next function to finalize
PSHY ; save cpp counter
CALL [-3,X] ; use double indirect call to load the page register also
PULY ; restore cpp counter
PULX ; restore actual address
DEY ; decrement cpp counter
LEAX 3,X ;
increment to next init
PSHX ;
save address of next function to finalize
PSHY ;
save cpp counter
CALL [-3,X] ;
use double indirect call to load the page register also
PULY ;
restore cpp counter
PULX ;
restore actual address
DEY ;
decrement cpp counter
BNE nextInit2
#else /* defined( __BANKED__) || defined(__LARGE__) */
LDD _startupData.nofFiniBodies; load number of cpp.
BEQ done ; if cppcount == 0, goto done
LDX _startupData.finiBodies ; load address of first module to finalize
LDD _startupData.nofFiniBodies;
load number of cpp.
BEQ done ;
if cppcount == 0, goto done
LDX _startupData.finiBodies ;
load address of first module to finalize
nextInit2:
LDY 2,X+ ; load address of first module to finalize
LDY 2,X+ ;
load address of first module to finalize
PSHD
PSHX ; save actual address
JSR 0,Y ; call finalize function
PULX ; restore actual address
PULD ; restore cpp counter
PSHX ;
save actual address
JSR 0,Y ;
call finalize function
PULX ;
restore actual address
PULD ;
restore cpp counter
DBNE D, nextInit2
#endif /* defined(__BANKED__) || defined(__LARGE__) */
done:;
@ -390,9 +511,11 @@ done:;
/* the reset vector must be set so that the application has a defined entry point */
#if defined(__SET_RESET_VECTOR__)
__EXTERN_C void __interrupt 0 _Startup(void) {
__EXTERN_C void __interrupt 0 _Startup(void)
{
#else
__EXTERN_C void _Startup(void) {
__EXTERN_C void _Startup(void)
{
#endif
/* purpose: 1) initialize the stack
2) initialize the RAM, copy down init data etc (Init)

View File

@ -187,7 +187,8 @@ static blt_bool CanGetSpeedConfig(blt_int16u baud, blt_int8u *btr0, blt_int8u *b
* with a sample point between 68..78%.
*/
static const tCanBusTiming canTiming[] =
{ /* TQ | TSEG1 | TSEG2 | SP */
{
/* TQ | TSEG1 | TSEG2 | SP */
/* ------------------------- */
{ 5, 2 }, /* 8 | 5 | 2 | 75% */
{ 6, 2 }, /* 9 | 6 | 2 | 78% */

View File

@ -11,12 +11,15 @@ FRESULT open_append (
/* Opens an existing file. If not exist, creates a new file. */
fr = f_open(fp, path, FA_WRITE | FA_OPEN_ALWAYS);
if (fr == FR_OK) {
if (fr == FR_OK)
{
/* Seek to end of the file to append data */
fr = f_lseek(fp, f_size(fp));
if (fr != FR_OK)
{
f_close(fp);
}
}
return fr;
}
@ -31,7 +34,10 @@ int main (void)
/* Open or create a log file and ready to append */
fr = open_append(&fil, "logfile.txt");
if (fr != FR_OK) return 1;
if (fr != FR_OK)
{
return 1;
}
/* Append a line */
f_printf(&fil, "%02u/%02u/%u, %2u:%02u\n", Mday, Mon, Year, Hour, Min);

View File

@ -17,23 +17,40 @@ FRESULT empty_directory (
fno.lfname = 0; /* Set null pointer because LFN is not needed */
#endif
fr = f_opendir(&dir, path);
if (fr == FR_OK) {
if (fr == FR_OK)
{
for (i = 0; path[i]; i++) ;
path[i++] = '/';
for (;;) {
for (;;)
{
fr = f_readdir(&dir, &fno);
if (fr != FR_OK || !fno.fname[0]) break;
if (fno.fname[0] == '.') continue;
if (fr != FR_OK || !fno.fname[0])
{
break;
}
if (fno.fname[0] == '.')
{
continue;
}
j = 0;
do
{
path[i+j] = fno.fname[j];
}
while (fno.fname[j++]);
if (fno.fattrib & AM_DIR) {
if (fno.fattrib & AM_DIR)
{
fr = empty_directory(path);
if (fr != FR_OK) break;
if (fr != FR_OK)
{
break;
}
}
fr = f_unlink(path);
if (fr != FR_OK) break;
if (fr != FR_OK)
{
break;
}
}
path[--i] = '\0';
}
@ -54,10 +71,13 @@ int main (void)
strcpy(buff, "/"); /* Directory to be emptied */
fr = empty_directory(buff);
if (fr) {
if (fr)
{
printf("Function failed. (%u)\n", fr);
return 1;
} else {
}
else
{
printf("All contents in the %s are successfully removed.\n", buff);
return 0;
}

View File

@ -20,43 +20,77 @@ DWORD allocate_contiguous_clusters ( /* Returns file start sector number */
#endif
if (f_lseek(fp, 0) || !len) /* Check if the given parameters are valid */
{
return 0;
}
csz = 512UL * fp->fs->csize; /* Cluster size in unit of byte (assuming 512 bytes/sector) */
tcl = (len + csz - 1) / csz; /* Total number of clusters required */
len = tcl * csz; /* Round-up file size to the cluster boundary */
/* Check if the existing cluster chain is contiguous */
if (len == fp->fsize) {
ncl = 0; ccl = fp->sclust;
do {
if (len == fp->fsize)
{
ncl = 0;
ccl = fp->sclust;
do
{
cl = get_fat(fp->fs, ccl); /* Get the cluster status */
if (cl + 1 < 3) return 0; /* Hard error? */
if (cl != ccl + 1 &&; cl < fp->fs->n_fatent) break; /* Not contiguous? */
if (cl + 1 < 3)
{
return 0; /* Hard error? */
}
if (cl != ccl + 1 &&; cl < fp->fs->n_fatent)
{
break; /* Not contiguous? */
}
ccl = cl;
} while (++ncl < tcl);
}
while (++ncl < tcl);
if (ncl == tcl) /* Is the file contiguous? */
{
return clust2sect(fp->fs, fp->sclust); /* Return file start sector */
}
}
if (f_truncate(fp)) return 0; /* Remove the existing chain */
if (f_truncate(fp))
{
return 0; /* Remove the existing chain */
}
/* Find a free contiguous area */
ccl = cl = 2; ncl = 0;
do {
if (cl >= fp->fs->n_fatent) return 0; /* No contiguous area is found. */
if (get_fat(fp->fs, cl)) { /* Encounterd a cluster in use */
do { /* Skip the block of used clusters */
cl++;
if (cl >= fp->fs->n_fatent) return 0; /* No contiguous area is found. */
} while (get_fat(fp->fs, cl));
ccl = cl; ncl = 0;
ccl = cl = 2;
ncl = 0;
do
{
if (cl >= fp->fs->n_fatent)
{
return 0; /* No contiguous area is found. */
}
cl++; ncl++;
} while (ncl < tcl);
if (get_fat(fp->fs, cl)) /* Encounterd a cluster in use */
{
do /* Skip the block of used clusters */
{
cl++;
if (cl >= fp->fs->n_fatent)
{
return 0; /* No contiguous area is found. */
}
}
while (get_fat(fp->fs, cl));
ccl = cl;
ncl = 0;
}
cl++;
ncl++;
}
while (ncl < tcl);
/* Create a contiguous cluster chain */
fp->fs->last_clust = ccl - 1;
if (f_lseek(fp, len)) return 0;
if (f_lseek(fp, len))
{
return 0;
}
return clust2sect(fp->fs, fp->sclust); /* Return file start sector */
}
@ -74,12 +108,16 @@ int main (void)
/* Open or create a file */
fr = f_open(&fil, "pagefile.dat", FA_READ | FA_WRITE | FA_OPEN_ALWAYS);
if (fr) return 1;
if (fr)
{
return 1;
}
/* Check if the file is 64MB in size and occupies a contiguous area.
/ If not, a contiguous area is re-allocated to the file. */
org = allocate_contiguous_clusters(&fil, 0x4000000);
if (!org) {
if (!org)
{
printf("Function failed due to any error or insufficient contiguous area.\n");
f_close(&fil);
return 1;

View File

@ -19,7 +19,8 @@ extern "C" {
typedef BYTE DSTATUS;
/* Results of Disk Functions */
typedef enum {
typedef enum
{
RES_OK = 0, /* 0: Successful */
RES_ERROR, /* 1: R/W Error */
RES_WRPRT, /* 2: Write Protected */

File diff suppressed because it is too large Load Diff

View File

@ -33,7 +33,8 @@ extern "C" {
/* Definitions of volume management */
#if _MULTI_PARTITION /* Multiple partition configuration */
typedef struct {
typedef struct
{
BYTE pd; /* Physical drive number */
BYTE pt; /* Partition: 0:Auto detect, 1-4:Forced partition) */
} PARTITION;
@ -74,7 +75,8 @@ typedef char TCHAR;
/* File system object structure (FATFS) */
typedef struct {
typedef struct
{
BYTE fs_type; /* FAT sub-type (0:Not mounted) */
BYTE drv; /* Physical drive number */
BYTE csize; /* Sectors per cluster (1,2,4...128) */
@ -111,7 +113,8 @@ typedef struct {
/* File object structure (FIL) */
typedef struct {
typedef struct
{
FATFS *fs; /* Pointer to the related file system object (**do not change order**) */
WORD id; /* Owner file system mount ID (**do not change order**) */
BYTE flag; /* File status flags */
@ -140,7 +143,8 @@ typedef struct {
/* Directory object structure (DIR) */
typedef struct {
typedef struct
{
FATFS *fs; /* Pointer to the owner file system object (**do not change order**) */
WORD id; /* Owner file system mount ID (**do not change order**) */
WORD index; /* Current read/write index number */
@ -159,7 +163,8 @@ typedef struct {
/* File status structure (FILINFO) */
typedef struct {
typedef struct
{
DWORD fsize; /* File size */
WORD fdate; /* Last modified date */
WORD ftime; /* Last modified time */
@ -175,7 +180,8 @@ typedef struct {
/* File function return code (FRESULT) */
typedef enum {
typedef enum
{
FR_OK = 0, /* (0) Succeeded */
FR_DISK_ERR, /* (1) A hard error occurred in the low level disk I/O layer */
FR_INT_ERR, /* (2) Assertion failed */

View File

@ -14,7 +14,8 @@
static
const WCHAR uni2sjis[] = {
const WCHAR uni2sjis[] =
{
/* Unicode - Sjis, Unicode - Sjis, Unicode - Sjis, Unicode - Sjis, */
0x00A7, 0x8198, 0x00A8, 0x814E, 0x00B0, 0x818B, 0x00B1, 0x817D,
0x00B4, 0x814C, 0x00B6, 0x81F7, 0x00D7, 0x817E, 0x00F7, 0x8180,
@ -1868,7 +1869,8 @@ const WCHAR uni2sjis[] = {
#if !_TINY_TABLE
static
const WCHAR sjis2uni[] = {
const WCHAR sjis2uni[] =
{
/* SJIS - Unicode, SJIS - Unicode, SJIS - Unicode, SJIS - Unicode, */
0x00A1, 0xFF61, 0x00A2, 0xFF62, 0x00A3, 0xFF63, 0x00A4, 0xFF64,
0x00A5, 0xFF65, 0x00A6, 0xFF66, 0x00A7, 0xFF67, 0x00A8, 0xFF68,
@ -3733,46 +3735,74 @@ WCHAR ff_convert ( /* Converted code, 0 means conversion error */
int i, n, li, hi;
if (chr <= 0x80) { /* ASCII */
if (chr <= 0x80) /* ASCII */
{
c = chr;
} else {
}
else
{
#if !_TINY_TABLE
if (dir) { /* OEMCP to unicode */
if (dir) /* OEMCP to unicode */
{
p = sjis2uni;
hi = sizeof(sjis2uni) / 4 - 1;
} else { /* Unicode to OEMCP */
}
else /* Unicode to OEMCP */
{
p = uni2sjis;
hi = sizeof(uni2sjis) / 4 - 1;
}
li = 0;
for (n = 16; n; n--) {
for (n = 16; n; n--)
{
i = li + (hi - li) / 2;
if (chr == p[i * 2]) break;
if (chr == p[i * 2])
{
break;
}
if (chr > p[i * 2])
{
li = i;
}
else
{
hi = i;
}
}
c = n ? p[i * 2 + 1] : 0;
#else
if (dir) { /* OEMCP to unicode (Incremental search)*/
if (dir) /* OEMCP to unicode (Incremental search)*/
{
p = &uni2sjis[1];
do {
do
{
c = *p;
p += 2;
} while (c && c != chr);
}
while (c && c != chr);
p -= 3;
c = *p;
} else { /* Unicode to OEMCP */
li = 0; hi = sizeof(uni2sjis) / 4 - 1;
for (n = 16; n; n--) {
}
else /* Unicode to OEMCP */
{
li = 0;
hi = sizeof(uni2sjis) / 4 - 1;
for (n = 16; n; n--)
{
i = li + (hi - li) / 2;
if (chr == uni2sjis[i * 2]) break;
if (chr == uni2sjis[i * 2])
{
break;
}
if (chr > uni2sjis[i * 2])
{
li = i;
}
else
{
hi = i;
}
}
c = n ? uni2sjis[i * 2 + 1] : 0;
}
#endif

View File

@ -12,7 +12,8 @@
#endif
static
const WCHAR uni2oem[] = {
const WCHAR uni2oem[] =
{
/* Unicode - OEM, Unicode - OEM, Unicode - OEM, Unicode - OEM */
0x00A4, 0xA1E8, 0x00A7, 0xA1EC, 0x00A8, 0xA1A7, 0x00B0, 0xA1E3,
0x00B1, 0xA1C0, 0x00B7, 0xA1A4, 0x00D7, 0xA1C1, 0x00E0, 0xA8A4,
@ -5466,7 +5467,8 @@ const WCHAR uni2oem[] = {
};
static
const WCHAR oem2uni[] = {
const WCHAR oem2uni[] =
{
/* OEM - Unicode, OEM - Unicode, OEM - Unicode, OEM - Unicode */
0x0080, 0x20AC, 0x8140, 0x4E02, 0x8141, 0x4E04, 0x8142, 0x4E05,
0x8143, 0x4E06, 0x8144, 0x4E0F, 0x8145, 0x4E12, 0x8146, 0x4E17,
@ -10931,25 +10933,39 @@ WCHAR ff_convert ( /* Converted code, 0 means conversion error */
int i, n, li, hi;
if (chr < 0x80) { /* ASCII */
if (chr < 0x80) /* ASCII */
{
c = chr;
} else {
if (dir) { /* OEMCP to unicode */
}
else
{
if (dir) /* OEMCP to unicode */
{
p = oem2uni;
hi = sizeof(oem2uni) / 4 - 1;
} else { /* Unicode to OEMCP */
}
else /* Unicode to OEMCP */
{
p = uni2oem;
hi = sizeof(uni2oem) / 4 - 1;
}
li = 0;
for (n = 16; n; n--) {
for (n = 16; n; n--)
{
i = li + (hi - li) / 2;
if (chr == p[i * 2]) break;
if (chr == p[i * 2])
{
break;
}
if (chr > p[i * 2])
{
li = i;
}
else
{
hi = i;
}
}
c = n ? p[i * 2 + 1] : 0;
}

View File

@ -13,7 +13,8 @@
static
const WCHAR uni2oem[] = {
const WCHAR uni2oem[] =
{
/* Unicode - OEM, Unicode - OEM, Unicode - OEM, Unicode - OEM */
0x00A1, 0xA2AE, 0x00A4, 0xA2B4, 0x00A7, 0xA1D7, 0x00A8, 0xA1A7,
0x00AA, 0xA8A3, 0x00AD, 0xA1A9, 0x00AE, 0xA2E7, 0x00B0, 0xA1C6,
@ -4281,7 +4282,8 @@ const WCHAR uni2oem[] = {
};
static
const WCHAR oem2uni[] = {
const WCHAR oem2uni[] =
{
/* OEM - Unicode, OEM - Unicode, OEM - Unicode, OEM - Unicode */
0x8141, 0xAC02, 0x8142, 0xAC03, 0x8143, 0xAC05, 0x8144, 0xAC06,
0x8145, 0xAC0B, 0x8146, 0xAC0C, 0x8147, 0xAC0D, 0x8148, 0xAC0E,
@ -8560,25 +8562,39 @@ WCHAR ff_convert ( /* Converted code, 0 means conversion error */
int i, n, li, hi;
if (chr < 0x80) { /* ASCII */
if (chr < 0x80) /* ASCII */
{
c = chr;
} else {
if (dir) { /* OEMCP to unicode */
}
else
{
if (dir) /* OEMCP to unicode */
{
p = oem2uni;
hi = sizeof(oem2uni) / 4 - 1;
} else { /* Unicode to OEMCP */
}
else /* Unicode to OEMCP */
{
p = uni2oem;
hi = sizeof(uni2oem) / 4 - 1;
}
li = 0;
for (n = 16; n; n--) {
for (n = 16; n; n--)
{
i = li + (hi - li) / 2;
if (chr == p[i * 2]) break;
if (chr == p[i * 2])
{
break;
}
if (chr > p[i * 2])
{
li = i;
}
else
{
hi = i;
}
}
c = n ? p[i * 2 + 1] : 0;
}

View File

@ -13,7 +13,8 @@
static
const WCHAR uni2oem[] = {
const WCHAR uni2oem[] =
{
/* Unicode - OEM, Unicode - OEM, Unicode - OEM, Unicode - OEM */
0x00A7, 0xA1B1, 0x00AF, 0xA1C2, 0x00B0, 0xA258, 0x00B1, 0xA1D3,
0x00B7, 0xA150, 0x00D7, 0xA1D1, 0x00F7, 0xA1D2, 0x02C7, 0xA3BE,
@ -3394,7 +3395,8 @@ const WCHAR uni2oem[] = {
};
static
const WCHAR oem2uni[] = {
const WCHAR oem2uni[] =
{
/* OEM - Unicode, OEM - Unicode, OEM - Unicode, OEM - Unicode */
0xA140, 0x3000, 0xA141, 0xFF0C, 0xA142, 0x3001, 0xA143, 0x3002,
0xA144, 0xFF0E, 0xA145, 0x2027, 0xA146, 0xFF1B, 0xA147, 0xFF1A,
@ -6786,25 +6788,39 @@ WCHAR ff_convert ( /* Converted code, 0 means conversion error */
int i, n, li, hi;
if (chr < 0x80) { /* ASCII */
if (chr < 0x80) /* ASCII */
{
c = chr;
} else {
if (dir) { /* OEMCP to unicode */
}
else
{
if (dir) /* OEMCP to unicode */
{
p = oem2uni;
hi = sizeof(oem2uni) / 4 - 1;
} else { /* Unicode to OEMCP */
}
else /* Unicode to OEMCP */
{
p = uni2oem;
hi = sizeof(uni2oem) / 4 - 1;
}
li = 0;
for (n = 16; n; n--) {
for (n = 16; n; n--)
{
i = li + (hi - li) / 2;
if (chr == p[i * 2]) break;
if (chr == p[i * 2])
{
break;
}
if (chr > p[i * 2])
{
li = i;
}
else
{
hi = i;
}
}
c = n ? p[i * 2 + 1] : 0;
}

View File

@ -31,7 +31,8 @@
#if _CODE_PAGE == 437
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP437(0x80-0xFF) to Unicode conversion table */
const WCHAR Tbl[] = /* CP437(0x80-0xFF) to Unicode conversion table */
{
0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7,
0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5,
0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9,
@ -53,7 +54,8 @@ const WCHAR Tbl[] = { /* CP437(0x80-0xFF) to Unicode conversion table */
#elif _CODE_PAGE == 720
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP720(0x80-0xFF) to Unicode conversion table */
const WCHAR Tbl[] = /* CP720(0x80-0xFF) to Unicode conversion table */
{
0x0000, 0x0000, 0x00E9, 0x00E2, 0x0000, 0x00E0, 0x0000, 0x00E7,
0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x0000, 0x0000, 0x0000,
0x0000, 0x0651, 0x0652, 0x00F4, 0x00A4, 0x0640, 0x00FB, 0x00F9,
@ -75,7 +77,8 @@ const WCHAR Tbl[] = { /* CP720(0x80-0xFF) to Unicode conversion table */
#elif _CODE_PAGE == 737
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP737(0x80-0xFF) to Unicode conversion table */
const WCHAR Tbl[] = /* CP737(0x80-0xFF) to Unicode conversion table */
{
0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397, 0x0398,
0x0399, 0x039A, 0x039B, 0x039C, 0x039D, 0x039E, 0x039F, 0x03A0,
0x03A1, 0x03A3, 0x03A4, 0x03A5, 0x03A6, 0x03A7, 0x03A8, 0x03A9,
@ -97,7 +100,8 @@ const WCHAR Tbl[] = { /* CP737(0x80-0xFF) to Unicode conversion table */
#elif _CODE_PAGE == 775
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP775(0x80-0xFF) to Unicode conversion table */
const WCHAR Tbl[] = /* CP775(0x80-0xFF) to Unicode conversion table */
{
0x0106, 0x00FC, 0x00E9, 0x0101, 0x00E4, 0x0123, 0x00E5, 0x0107,
0x0142, 0x0113, 0x0156, 0x0157, 0x012B, 0x0179, 0x00C4, 0x00C5,
0x00C9, 0x00E6, 0x00C6, 0x014D, 0x00F6, 0x0122, 0x00A2, 0x015A,
@ -119,7 +123,8 @@ const WCHAR Tbl[] = { /* CP775(0x80-0xFF) to Unicode conversion table */
#elif _CODE_PAGE == 850
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP850(0x80-0xFF) to Unicode conversion table */
const WCHAR Tbl[] = /* CP850(0x80-0xFF) to Unicode conversion table */
{
0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7,
0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5,
0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9,
@ -141,7 +146,8 @@ const WCHAR Tbl[] = { /* CP850(0x80-0xFF) to Unicode conversion table */
#elif _CODE_PAGE == 852
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP852(0x80-0xFF) to Unicode conversion table */
const WCHAR Tbl[] = /* CP852(0x80-0xFF) to Unicode conversion table */
{
0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x016F, 0x0107, 0x00E7,
0x0142, 0x00EB, 0x0150, 0x0151, 0x00EE, 0x0179, 0x00C4, 0x0106,
0x00C9, 0x0139, 0x013A, 0x00F4, 0x00F6, 0x013D, 0x013E, 0x015A,
@ -163,7 +169,8 @@ const WCHAR Tbl[] = { /* CP852(0x80-0xFF) to Unicode conversion table */
#elif _CODE_PAGE == 855
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP855(0x80-0xFF) to Unicode conversion table */
const WCHAR Tbl[] = /* CP855(0x80-0xFF) to Unicode conversion table */
{
0x0452, 0x0402, 0x0453, 0x0403, 0x0451, 0x0401, 0x0454, 0x0404,
0x0455, 0x0405, 0x0456, 0x0406, 0x0457, 0x0407, 0x0458, 0x0408,
0x0459, 0x0409, 0x045A, 0x040A, 0x045B, 0x040B, 0x045C, 0x040C,
@ -185,7 +192,8 @@ const WCHAR Tbl[] = { /* CP855(0x80-0xFF) to Unicode conversion table */
#elif _CODE_PAGE == 857
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP857(0x80-0xFF) to Unicode conversion table */
const WCHAR Tbl[] = /* CP857(0x80-0xFF) to Unicode conversion table */
{
0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7,
0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x0131, 0x00C4, 0x00C5,
0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9,
@ -207,7 +215,8 @@ const WCHAR Tbl[] = { /* CP857(0x80-0xFF) to Unicode conversion table */
#elif _CODE_PAGE == 858
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP858(0x80-0xFF) to Unicode conversion table */
const WCHAR Tbl[] = /* CP858(0x80-0xFF) to Unicode conversion table */
{
0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7,
0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5,
0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9,
@ -229,7 +238,8 @@ const WCHAR Tbl[] = { /* CP858(0x80-0xFF) to Unicode conversion table */
#elif _CODE_PAGE == 862
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP862(0x80-0xFF) to Unicode conversion table */
const WCHAR Tbl[] = /* CP862(0x80-0xFF) to Unicode conversion table */
{
0x05D0, 0x05D1, 0x05D2, 0x05D3, 0x05D4, 0x05D5, 0x05D6, 0x05D7,
0x05D8, 0x05D9, 0x05DA, 0x05DB, 0x05DC, 0x05DD, 0x05DE, 0x05DF,
0x05E0, 0x05E1, 0x05E2, 0x05E3, 0x05E4, 0x05E5, 0x05E6, 0x05E7,
@ -251,7 +261,8 @@ const WCHAR Tbl[] = { /* CP862(0x80-0xFF) to Unicode conversion table */
#elif _CODE_PAGE == 866
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP866(0x80-0xFF) to Unicode conversion table */
const WCHAR Tbl[] = /* CP866(0x80-0xFF) to Unicode conversion table */
{
0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417,
0x0418, 0x0419, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, 0x041F,
0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427,
@ -273,7 +284,8 @@ const WCHAR Tbl[] = { /* CP866(0x80-0xFF) to Unicode conversion table */
#elif _CODE_PAGE == 874
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP874(0x80-0xFF) to Unicode conversion table */
const WCHAR Tbl[] = /* CP874(0x80-0xFF) to Unicode conversion table */
{
0x20AC, 0x0000, 0x0000, 0x0000, 0x0000, 0x2026, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
@ -295,7 +307,8 @@ const WCHAR Tbl[] = { /* CP874(0x80-0xFF) to Unicode conversion table */
#elif _CODE_PAGE == 1250
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP1250(0x80-0xFF) to Unicode conversion table */
const WCHAR Tbl[] = /* CP1250(0x80-0xFF) to Unicode conversion table */
{
0x20AC, 0x0000, 0x201A, 0x0000, 0x201E, 0x2026, 0x2020, 0x2021,
0x0000, 0x2030, 0x0160, 0x2039, 0x015A, 0x0164, 0x017D, 0x0179,
0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
@ -317,7 +330,8 @@ const WCHAR Tbl[] = { /* CP1250(0x80-0xFF) to Unicode conversion table */
#elif _CODE_PAGE == 1251
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP1251(0x80-0xFF) to Unicode conversion table */
const WCHAR Tbl[] = /* CP1251(0x80-0xFF) to Unicode conversion table */
{
0x0402, 0x0403, 0x201A, 0x0453, 0x201E, 0x2026, 0x2020, 0x2021,
0x20AC, 0x2030, 0x0409, 0x2039, 0x040A, 0x040C, 0x040B, 0x040F,
0x0452, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
@ -339,7 +353,8 @@ const WCHAR Tbl[] = { /* CP1251(0x80-0xFF) to Unicode conversion table */
#elif _CODE_PAGE == 1252
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP1252(0x80-0xFF) to Unicode conversion table */
const WCHAR Tbl[] = /* CP1252(0x80-0xFF) to Unicode conversion table */
{
0x20AC, 0x0000, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, 0x0000, 0x017D, 0x0000,
0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
@ -361,7 +376,8 @@ const WCHAR Tbl[] = { /* CP1252(0x80-0xFF) to Unicode conversion table */
#elif _CODE_PAGE == 1253
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP1253(0x80-0xFF) to Unicode conversion table */
const WCHAR Tbl[] = /* CP1253(0x80-0xFF) to Unicode conversion table */
{
0x20AC, 0x0000, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
0x0000, 0x2030, 0x0000, 0x2039, 0x000C, 0x0000, 0x0000, 0x0000,
0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
@ -383,7 +399,8 @@ const WCHAR Tbl[] = { /* CP1253(0x80-0xFF) to Unicode conversion table */
#elif _CODE_PAGE == 1254
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP1254(0x80-0xFF) to Unicode conversion table */
const WCHAR Tbl[] = /* CP1254(0x80-0xFF) to Unicode conversion table */
{
0x20AC, 0x0000, 0x210A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, 0x0000, 0x0000, 0x0000,
0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
@ -405,7 +422,8 @@ const WCHAR Tbl[] = { /* CP1254(0x80-0xFF) to Unicode conversion table */
#elif _CODE_PAGE == 1255
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP1255(0x80-0xFF) to Unicode conversion table */
const WCHAR Tbl[] = /* CP1255(0x80-0xFF) to Unicode conversion table */
{
0x20AC, 0x0000, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
0x02C6, 0x2030, 0x0000, 0x2039, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
@ -427,7 +445,8 @@ const WCHAR Tbl[] = { /* CP1255(0x80-0xFF) to Unicode conversion table */
#elif _CODE_PAGE == 1256
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP1256(0x80-0xFF) to Unicode conversion table */
const WCHAR Tbl[] = /* CP1256(0x80-0xFF) to Unicode conversion table */
{
0x20AC, 0x067E, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
0x02C6, 0x2030, 0x0679, 0x2039, 0x0152, 0x0686, 0x0698, 0x0688,
0x06AF, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
@ -449,7 +468,8 @@ const WCHAR Tbl[] = { /* CP1256(0x80-0xFF) to Unicode conversion table */
#elif _CODE_PAGE == 1257
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP1257(0x80-0xFF) to Unicode conversion table */
const WCHAR Tbl[] = /* CP1257(0x80-0xFF) to Unicode conversion table */
{
0x20AC, 0x0000, 0x201A, 0x0000, 0x201E, 0x2026, 0x2020, 0x2021,
0x0000, 0x2030, 0x0000, 0x2039, 0x0000, 0x00A8, 0x02C7, 0x00B8,
0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
@ -471,7 +491,8 @@ const WCHAR Tbl[] = { /* CP1257(0x80-0xFF) to Unicode conversion table */
#elif _CODE_PAGE == 1258
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP1258(0x80-0xFF) to Unicode conversion table */
const WCHAR Tbl[] = /* CP1258(0x80-0xFF) to Unicode conversion table */
{
0x20AC, 0x0000, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
0x02C6, 0x2030, 0x0000, 0x2039, 0x0152, 0x0000, 0x0000, 0x0000,
0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
@ -506,16 +527,26 @@ WCHAR ff_convert ( /* Converted character, Returns zero on error */
WCHAR c;
if (chr < 0x80) { /* ASCII */
if (chr < 0x80) /* ASCII */
{
c = chr;
} else {
if (dir) { /* OEMCP to Unicode */
}
else
{
if (dir) /* OEMCP to Unicode */
{
c = (chr >= 0x100) ? 0 : Tbl[chr - 0x80];
} else { /* Unicode to OEMCP */
for (c = 0; c < 0x80; c++) {
if (chr == Tbl[c]) break;
}
else /* Unicode to OEMCP */
{
for (c = 0; c < 0x80; c++)
{
if (chr == Tbl[c])
{
break;
}
}
c = (c + 0x80) & 0xFF;
}

View File

@ -46,7 +46,8 @@
static struct dhcpc_state s;
struct dhcp_msg {
struct dhcp_msg
{
u8_t op, htype, hlen, hops;
u8_t xid[4];
u16_t secs, flags;
@ -201,8 +202,10 @@ parse_options(u8_t *optptr, int len)
u8_t *end = optptr + len;
u8_t type = 0;
while(optptr < end) {
switch(*optptr) {
while (optptr < end)
{
switch (*optptr)
{
case DHCP_OPTION_SUBNET_MASK:
memcpy(s.netmask, optptr + 2, 4);
break;
@ -237,7 +240,8 @@ parse_msg(void)
if (m->op == DHCP_REPLY &&
memcmp(m->xid, xid, sizeof(xid)) == 0 &&
memcmp(m->chaddr, s.mac_addr, s.mac_len) == 0) {
memcmp(m->chaddr, s.mac_addr, s.mac_len) == 0)
{
memcpy(s.ipaddr, m->yiaddr, 4);
return parse_options(&m->options[4], uip_datalen());
}
@ -253,41 +257,51 @@ PT_THREAD(handle_dhcp(void))
s.state = STATE_SENDING;
s.ticks = CLOCK_SECOND;
do {
do
{
send_discover();
timer_set(&s.timer, s.ticks);
PT_YIELD(&s.pt);
PT_WAIT_UNTIL(&s.pt, uip_newdata() || timer_expired(&s.timer));
if(uip_newdata() && parse_msg() == DHCPOFFER) {
if (uip_newdata() && parse_msg() == DHCPOFFER)
{
s.state = STATE_OFFER_RECEIVED;
break;
}
if(s.ticks < CLOCK_SECOND * 60) {
if (s.ticks < CLOCK_SECOND * 60)
{
s.ticks *= 2;
}
} while(s.state != STATE_OFFER_RECEIVED);
}
while (s.state != STATE_OFFER_RECEIVED);
s.ticks = CLOCK_SECOND;
do {
do
{
send_request();
timer_set(&s.timer, s.ticks);
PT_YIELD(&s.pt);
PT_WAIT_UNTIL(&s.pt, uip_newdata() || timer_expired(&s.timer));
if(uip_newdata() && parse_msg() == DHCPACK) {
if (uip_newdata() && parse_msg() == DHCPACK)
{
s.state = STATE_CONFIG_RECEIVED;
break;
}
if(s.ticks <= CLOCK_SECOND * 10) {
if (s.ticks <= CLOCK_SECOND * 10)
{
s.ticks += CLOCK_SECOND;
} else {
}
else
{
PT_RESTART(&s.pt);
}
} while(s.state != STATE_CONFIG_RECEIVED);
}
while (s.state != STATE_CONFIG_RECEIVED);
#if 0
printf("Got IP address %d.%d.%d.%d\n",
@ -314,7 +328,8 @@ PT_THREAD(handle_dhcp(void))
* PT_END restarts the thread so we do this instead. Eventually we
* should reacquire expired leases here.
*/
while(1) {
while (1)
{
PT_YIELD(&s.pt);
}
@ -332,7 +347,8 @@ dhcpc_init(const void *mac_addr, int mac_len)
s.state = STATE_INITIAL;
uip_ipaddr(addr, 255,255,255,255);
s.conn = uip_udp_new(&addr, HTONS(DHCPC_SERVER_PORT));
if(s.conn != NULL) {
if (s.conn != NULL)
{
uip_udp_bind(s.conn, HTONS(DHCPC_CLIENT_PORT));
}
PT_INIT(&s.pt);
@ -349,7 +365,8 @@ dhcpc_request(void)
{
u16_t ipaddr[2];
if(s.state == STATE_INITIAL) {
if (s.state == STATE_INITIAL)
{
uip_ipaddr(ipaddr, 0,0,0,0);
uip_sethostaddr(ipaddr);
/* handle_dhcp(PROCESS_EVENT_NONE, NULL);*/

View File

@ -36,7 +36,8 @@
#include "uip_timer.h"
#include "pt.h"
struct dhcpc_state {
struct dhcpc_state
{
struct pt pt;
char state;
struct uip_udp_conn *conn;

View File

@ -65,7 +65,8 @@ hello_world_appcall(void)
* If a new connection was just established, we should initialize
* the protosocket in our applications' state structure.
*/
if(uip_connected()) {
if (uip_connected())
{
PSOCK_INIT(&s->p, s->inputbuffer, sizeof(s->inputbuffer));
}

View File

@ -33,7 +33,8 @@
of our application, and the memory required for this state is
allocated together with each TCP connection. One application state
for each TCP connection. */
typedef struct hello_world_state {
typedef struct hello_world_state
{
struct psock p;
char inputbuffer[10];
char name[40];

View File

@ -73,7 +73,8 @@
#define MAX_RETRIES 8
/** \internal The DNS message header. */
struct dns_hdr {
struct dns_hdr
{
u16_t id;
u8_t flags1, flags2;
#define DNS_FLAG1_RESPONSE 0x80
@ -94,7 +95,8 @@ struct dns_hdr {
};
/** \internal The DNS answer message structure. */
struct dns_answer {
struct dns_answer
{
/* DNS answer record starts with either a domain name or a pointer
to a name already present somewhere in the packet. */
u16_t type;
@ -104,7 +106,8 @@ struct dns_answer {
uip_ipaddr_t ipaddr;
};
struct namemap {
struct namemap
{
#define STATE_UNUSED 0
#define STATE_NEW 1
#define STATE_ASKING 2
@ -145,16 +148,19 @@ parse_name(unsigned char *query)
{
unsigned char n;
do {
do
{
n = *query++;
while(n > 0) {
while (n > 0)
{
/* printf("%c", *query);*/
++query;
--n;
};
/* printf(".");*/
} while(*query != 0);
}
while (*query != 0);
/* printf("\n");*/
return query + 1;
}
@ -173,25 +179,34 @@ check_entries(void)
static u8_t n;
register struct namemap *namemapptr;
for(i = 0; i < RESOLV_ENTRIES; ++i) {
for (i = 0; i < RESOLV_ENTRIES; ++i)
{
namemapptr = &names[i];
if (namemapptr->state == STATE_NEW ||
namemapptr->state == STATE_ASKING) {
if(namemapptr->state == STATE_ASKING) {
if(--namemapptr->tmr == 0) {
if(++namemapptr->retries == MAX_RETRIES) {
namemapptr->state == STATE_ASKING)
{
if (namemapptr->state == STATE_ASKING)
{
if (--namemapptr->tmr == 0)
{
if (++namemapptr->retries == MAX_RETRIES)
{
namemapptr->state = STATE_ERROR;
resolv_found(namemapptr->name, NULL);
continue;
}
namemapptr->tmr = namemapptr->retries;
} else {
}
else
{
/* printf("Timer %d\n", namemapptr->tmr);*/
/* Its timer has not run out, so we move on to next
entry. */
continue;
}
} else {
}
else
{
namemapptr->state = STATE_ASKING;
namemapptr->tmr = 1;
namemapptr->retries = 0;
@ -205,17 +220,20 @@ check_entries(void)
nameptr = namemapptr->name;
--nameptr;
/* Convert hostname into suitable query format. */
do {
do
{
++nameptr;
nptr = query;
++query;
for(n = 0; *nameptr != '.' && *nameptr != 0; ++nameptr) {
for (n = 0; *nameptr != '.' && *nameptr != 0; ++nameptr)
{
*query = *nameptr;
++query;
++n;
}
*nptr = n;
} while(*nameptr != 0);
}
while (*nameptr != 0);
{
static unsigned char endquery[] =
{0,0,1,0,1};
@ -257,14 +275,16 @@ newdata(void)
i = htons(hdr->id);
namemapptr = &names[i];
if (i < RESOLV_ENTRIES &&
namemapptr->state == STATE_ASKING) {
namemapptr->state == STATE_ASKING)
{
/* This entry is now finished. */
namemapptr->state = STATE_DONE;
namemapptr->err = hdr->flags2 & DNS_FLAG2_ERR_MASK;
/* Check for error. If so, call callback to inform. */
if(namemapptr->err != 0) {
if (namemapptr->err != 0)
{
namemapptr->state = STATE_ERROR;
resolv_found(namemapptr->name, NULL);
return;
@ -280,14 +300,18 @@ newdata(void)
match. */
nameptr = parse_name((char *)uip_appdata + 12) + 4;
while(nanswers > 0) {
while (nanswers > 0)
{
/* The first byte in the answer resource record determines if it
is a compressed record or a normal one. */
if(*nameptr & 0xc0) {
if (*nameptr & 0xc0)
{
/* Compressed name. */
nameptr +=2;
/* printf("Compressed anwser\n");*/
} else {
}
else
{
/* Not compressed name. */
nameptr = parse_name((char *)nameptr);
}
@ -301,7 +325,8 @@ newdata(void)
discarded. */
if (ans->type == HTONS(1) &&
ans->class == HTONS(1) &&
ans->len == HTONS(4)) {
ans->len == HTONS(4))
{
/* printf("IP address %d.%d.%d.%d\n",
htons(ans->ipaddr[0]) >> 8,
htons(ans->ipaddr[0]) & 0xff,
@ -314,7 +339,9 @@ newdata(void)
resolv_found(namemapptr->name, namemapptr->ipaddr);
return;
} else {
}
else
{
nameptr = nameptr + 10 + htons(ans->len);
}
--nanswers;
@ -330,11 +357,14 @@ newdata(void)
void
resolv_appcall(void)
{
if(uip_udp_conn->rport == HTONS(53)) {
if(uip_poll()) {
if (uip_udp_conn->rport == HTONS(53))
{
if (uip_poll())
{
check_entries();
}
if(uip_newdata()) {
if (uip_newdata())
{
newdata();
}
}
@ -355,18 +385,22 @@ resolv_query(char *name)
lseq = lseqi = 0;
for(i = 0; i < RESOLV_ENTRIES; ++i) {
for (i = 0; i < RESOLV_ENTRIES; ++i)
{
nameptr = &names[i];
if(nameptr->state == STATE_UNUSED) {
if (nameptr->state == STATE_UNUSED)
{
break;
}
if(seqno - nameptr->seqno > lseq) {
if (seqno - nameptr->seqno > lseq)
{
lseq = seqno - nameptr->seqno;
lseqi = i;
}
}
if(i == RESOLV_ENTRIES) {
if (i == RESOLV_ENTRIES)
{
i = lseqi;
nameptr = &names[i];
}
@ -400,10 +434,12 @@ resolv_lookup(char *name)
/* Walk through the list to see if the name is in there. If it is
not, we return NULL. */
for(i = 0; i < RESOLV_ENTRIES; ++i) {
for (i = 0; i < RESOLV_ENTRIES; ++i)
{
nameptr = &names[i];
if (nameptr->state == STATE_DONE &&
strcmp(name, nameptr->name) == 0) {
strcmp(name, nameptr->name) == 0)
{
return nameptr->ipaddr;
}
}
@ -421,7 +457,8 @@ resolv_lookup(char *name)
u16_t *
resolv_getserver(void)
{
if(resolv_conn == NULL) {
if (resolv_conn == NULL)
{
return NULL;
}
return resolv_conn->ripaddr;
@ -437,7 +474,8 @@ resolv_getserver(void)
void
resolv_conf(u16_t *dnsserver)
{
if(resolv_conn != NULL) {
if (resolv_conn != NULL)
{
uip_udp_remove(resolv_conn);
}
@ -453,7 +491,8 @@ resolv_init(void)
{
static u8_t i;
for(i = 0; i < RESOLV_ENTRIES; ++i) {
for (i = 0; i < RESOLV_ENTRIES; ++i)
{
names[i].state = STATE_DONE;
}

View File

@ -86,7 +86,8 @@ PT_THREAD(smtp_thread(void))
PSOCK_READTO(&s.psock, ISO_nl);
if(strncmp(s.inputbuffer, smtp_220, 3) != 0) {
if (strncmp(s.inputbuffer, smtp_220, 3) != 0)
{
PSOCK_CLOSE(&s.psock);
smtp_done(2);
PSOCK_EXIT(&s.psock);
@ -98,7 +99,8 @@ PT_THREAD(smtp_thread(void))
PSOCK_READTO(&s.psock, ISO_nl);
if(s.inputbuffer[0] != ISO_2) {
if (s.inputbuffer[0] != ISO_2)
{
PSOCK_CLOSE(&s.psock);
smtp_done(3);
PSOCK_EXIT(&s.psock);
@ -110,7 +112,8 @@ PT_THREAD(smtp_thread(void))
PSOCK_READTO(&s.psock, ISO_nl);
if(s.inputbuffer[0] != ISO_2) {
if (s.inputbuffer[0] != ISO_2)
{
PSOCK_CLOSE(&s.psock);
smtp_done(4);
PSOCK_EXIT(&s.psock);
@ -122,20 +125,23 @@ PT_THREAD(smtp_thread(void))
PSOCK_READTO(&s.psock, ISO_nl);
if(s.inputbuffer[0] != ISO_2) {
if (s.inputbuffer[0] != ISO_2)
{
PSOCK_CLOSE(&s.psock);
smtp_done(5);
PSOCK_EXIT(&s.psock);
}
if(s.cc != 0) {
if (s.cc != 0)
{
PSOCK_SEND_STR(&s.psock, (char *)smtp_rcpt_to);
PSOCK_SEND_STR(&s.psock, s.cc);
PSOCK_SEND_STR(&s.psock, (char *)smtp_crnl);
PSOCK_READTO(&s.psock, ISO_nl);
if(s.inputbuffer[0] != ISO_2) {
if (s.inputbuffer[0] != ISO_2)
{
PSOCK_CLOSE(&s.psock);
smtp_done(6);
PSOCK_EXIT(&s.psock);
@ -146,7 +152,8 @@ PT_THREAD(smtp_thread(void))
PSOCK_READTO(&s.psock, ISO_nl);
if(s.inputbuffer[0] != ISO_3) {
if (s.inputbuffer[0] != ISO_3)
{
PSOCK_CLOSE(&s.psock);
smtp_done(7);
PSOCK_EXIT(&s.psock);
@ -156,7 +163,8 @@ PT_THREAD(smtp_thread(void))
PSOCK_SEND_STR(&s.psock, s.to);
PSOCK_SEND_STR(&s.psock, (char *)smtp_crnl);
if(s.cc != 0) {
if (s.cc != 0)
{
PSOCK_SEND_STR(&s.psock, (char *)smtp_cc);
PSOCK_SEND_STR(&s.psock, s.cc);
PSOCK_SEND_STR(&s.psock, (char *)smtp_crnl);
@ -175,7 +183,8 @@ PT_THREAD(smtp_thread(void))
PSOCK_SEND_STR(&s.psock, (char *)smtp_crnlperiodcrnl);
PSOCK_READTO(&s.psock, ISO_nl);
if(s.inputbuffer[0] != ISO_2) {
if (s.inputbuffer[0] != ISO_2)
{
PSOCK_CLOSE(&s.psock);
smtp_done(8);
PSOCK_EXIT(&s.psock);
@ -189,11 +198,13 @@ PT_THREAD(smtp_thread(void))
void
smtp_appcall(void)
{
if(uip_closed()) {
if (uip_closed())
{
s.connected = 0;
return;
}
if(uip_aborted() || uip_timedout()) {
if (uip_aborted() || uip_timedout())
{
s.connected = 0;
smtp_done(1);
return;
@ -236,7 +247,8 @@ smtp_send(char *to, char *cc, char *from,
struct uip_conn *conn;
conn = uip_connect(smtpserver, HTONS(25));
if(conn == NULL) {
if (conn == NULL)
{
return 0;
}
s.connected = 1;

View File

@ -78,7 +78,8 @@ unsigned char smtp_send(char *to, char *from,
void smtp_appcall(void);
struct smtp_state {
struct smtp_state
{
u8_t state;
char *to;
char *from;

View File

@ -36,7 +36,8 @@
#include <string.h>
struct ptentry {
struct ptentry
{
char *commandstr;
void (* pfunc)(char *str);
};
@ -48,8 +49,10 @@ static void
parse(register char *str, struct ptentry *t)
{
struct ptentry *p;
for(p = t; p->commandstr != NULL; ++p) {
if(strncmp(p->commandstr, str, strlen(p->commandstr)) == 0) {
for (p = t; p->commandstr != NULL; ++p)
{
if (strncmp(p->commandstr, str, strlen(p->commandstr)) == 0)
{
break;
}
}
@ -61,11 +64,13 @@ static void
inttostr(register char *str, unsigned int i)
{
str[0] = '0' + i / 100;
if(str[0] == '0') {
if (str[0] == '0')
{
str[0] = ' ';
}
str[1] = '0' + (i / 10) % 10;
if(str[0] == ' ' && str[1] == '0') {
if (str[0] == ' ' && str[1] == '0')
{
str[1] = ' ';
}
str[2] = '0' + i % 10;
@ -86,20 +91,23 @@ help(char *str)
static void
unknown(char *str)
{
if(strlen(str) > 0) {
if (strlen(str) > 0)
{
shell_output("Unknown command: ", str);
}
}
/*---------------------------------------------------------------------------*/
static struct ptentry parsetab[] =
{{"stats", help},
{
{"stats", help},
{"conn", help},
{"help", help},
{"exit", shell_quit},
{"?", help},
/* Default action */
{NULL, unknown}};
{NULL, unknown}
};
/*---------------------------------------------------------------------------*/
void
shell_init(void)

View File

@ -42,7 +42,8 @@
#define ISO_nl 0x0a
#define ISO_cr 0x0d
struct telnetd_line {
struct telnetd_line
{
char line[TELNETD_CONF_LINELEN];
};
MEMB(linemem, struct telnetd_line, TELNETD_CONF_NUMLINES);
@ -86,13 +87,16 @@ sendline(char *line)
{
static unsigned int i;
for(i = 0; i < TELNETD_CONF_NUMLINES; ++i) {
if(s.lines[i] == NULL) {
for (i = 0; i < TELNETD_CONF_NUMLINES; ++i)
{
if (s.lines[i] == NULL)
{
s.lines[i] = line;
break;
}
}
if(i == TELNETD_CONF_NUMLINES) {
if (i == TELNETD_CONF_NUMLINES)
{
dealloc_line(line);
}
}
@ -102,7 +106,8 @@ shell_prompt(char *str)
{
char *line;
line = alloc_line();
if(line != NULL) {
if (line != NULL)
{
strncpy(line, str, TELNETD_CONF_LINELEN);
/* petsciiconv_toascii(line, TELNETD_CONF_LINELEN);*/
sendline(line);
@ -116,14 +121,17 @@ shell_output(char *str1, char *str2)
char *line;
line = alloc_line();
if(line != NULL) {
if (line != NULL)
{
len = strlen(str1);
strncpy(line, str1, TELNETD_CONF_LINELEN);
if(len < TELNETD_CONF_LINELEN) {
if (len < TELNETD_CONF_LINELEN)
{
strncpy(line + len, str2, TELNETD_CONF_LINELEN - len);
}
len = strlen(line);
if(len < TELNETD_CONF_LINELEN - 2) {
if (len < TELNETD_CONF_LINELEN - 2)
{
line[len] = ISO_cr;
line[len+1] = ISO_nl;
line[len+2] = 0;
@ -146,9 +154,11 @@ acked(void)
{
static unsigned int i;
while(s.numsent > 0) {
while (s.numsent > 0)
{
dealloc_line(s.lines[0]);
for(i = 1; i < TELNETD_CONF_NUMLINES; ++i) {
for (i = 1; i < TELNETD_CONF_NUMLINES; ++i)
{
s.lines[i - 1] = s.lines[i];
}
s.lines[TELNETD_CONF_NUMLINES - 1] = NULL;
@ -165,17 +175,22 @@ senddata(void)
bufptr = uip_appdata;
buflen = 0;
for (s.numsent = 0; s.numsent < TELNETD_CONF_NUMLINES &&
s.lines[s.numsent] != NULL ; ++s.numsent) {
s.lines[s.numsent] != NULL ; ++s.numsent)
{
lineptr = s.lines[s.numsent];
linelen = strlen(lineptr);
if(linelen > TELNETD_CONF_LINELEN) {
if (linelen > TELNETD_CONF_LINELEN)
{
linelen = TELNETD_CONF_LINELEN;
}
if(buflen + linelen < uip_mss()) {
if (buflen + linelen < uip_mss())
{
memcpy(bufptr, lineptr, linelen);
bufptr += linelen;
buflen += linelen;
} else {
}
else
{
break;
}
}
@ -187,8 +202,10 @@ closed(void)
{
static unsigned int i;
for(i = 0; i < TELNETD_CONF_NUMLINES; ++i) {
if(s.lines[i] != NULL) {
for (i = 0; i < TELNETD_CONF_NUMLINES; ++i)
{
if (s.lines[i] != NULL)
{
dealloc_line(s.lines[i]);
}
}
@ -197,20 +214,25 @@ closed(void)
static void
get_char(u8_t c)
{
if(c == ISO_cr) {
if (c == ISO_cr)
{
return;
}
s.buf[(int)s.bufptr] = c;
if (s.buf[(int)s.bufptr] == ISO_nl ||
s.bufptr == sizeof(s.buf) - 1) {
if(s.bufptr > 0) {
s.bufptr == sizeof(s.buf) - 1)
{
if (s.bufptr > 0)
{
s.buf[(int)s.bufptr] = 0;
/* petsciiconv_topetscii(s.buf, TELNETD_CONF_LINELEN);*/
}
shell_input(s.buf);
s.bufptr = 0;
} else {
}
else
{
++s.bufptr;
}
}
@ -220,7 +242,8 @@ sendopt(u8_t option, u8_t value)
{
char *line;
line = alloc_line();
if(line != NULL) {
if (line != NULL)
{
line[0] = TELNET_IAC;
line[1] = option;
line[2] = value;
@ -240,17 +263,23 @@ newdata(void)
len = uip_datalen();
dataptr = (char *)uip_appdata;
while(len > 0 && s.bufptr < sizeof(s.buf)) {
while (len > 0 && s.bufptr < sizeof(s.buf))
{
c = *dataptr;
++dataptr;
--len;
switch(s.state) {
switch (s.state)
{
case STATE_IAC:
if(c == TELNET_IAC) {
if (c == TELNET_IAC)
{
get_char(c);
s.state = STATE_NORMAL;
} else {
switch(c) {
}
else
{
switch (c)
{
case TELNET_WILL:
s.state = STATE_WILL;
break;
@ -291,9 +320,12 @@ newdata(void)
s.state = STATE_NORMAL;
break;
case STATE_NORMAL:
if(c == TELNET_IAC) {
if (c == TELNET_IAC)
{
s.state = STATE_IAC;
} else {
}
else
{
get_char(c);
}
break;
@ -308,9 +340,11 @@ void
telnetd_appcall(void)
{
static unsigned int i;
if(uip_connected()) {
if (uip_connected())
{
/* tcp_markconn(uip_conn, &s);*/
for(i = 0; i < TELNETD_CONF_NUMLINES; ++i) {
for (i = 0; i < TELNETD_CONF_NUMLINES; ++i)
{
s.lines[i] = NULL;
}
s.bufptr = 0;
@ -319,7 +353,8 @@ telnetd_appcall(void)
shell_start();
}
if(s.state == STATE_CLOSE) {
if (s.state == STATE_CLOSE)
{
s.state = STATE_NORMAL;
uip_close();
return;
@ -327,15 +362,18 @@ telnetd_appcall(void)
if (uip_closed() ||
uip_aborted() ||
uip_timedout()) {
uip_timedout())
{
closed();
}
if(uip_acked()) {
if (uip_acked())
{
acked();
}
if(uip_newdata()) {
if (uip_newdata())
{
newdata();
}
@ -343,7 +381,8 @@ telnetd_appcall(void)
uip_newdata() ||
uip_acked() ||
uip_connected() ||
uip_poll()) {
uip_poll())
{
senddata();
}
}

View File

@ -46,7 +46,8 @@ void telnetd_appcall(void);
#define TELNETD_CONF_NUMLINES 16
#endif
struct telnetd_state {
struct telnetd_state
{
char *lines[TELNETD_CONF_NUMLINES];
char buf[TELNETD_CONF_LINELEN];
char bufptr;

View File

@ -145,17 +145,20 @@ webclient_get(char *host, u16_t port, char *file)
/* First check if the host is an IP address. */
ipaddr = &addr;
if(uiplib_ipaddrconv(host, (unsigned char *)addr) == 0) {
if (uiplib_ipaddrconv(host, (unsigned char *)addr) == 0)
{
ipaddr = (uip_ipaddr_t *)resolv_lookup(host);
if(ipaddr == NULL) {
if (ipaddr == NULL)
{
return 0;
}
}
conn = uip_connect(ipaddr, htons(port));
if(conn == NULL) {
if (conn == NULL)
{
return 0;
}
@ -182,7 +185,8 @@ senddata(void)
char *getrequest;
char *cptr;
if(s.getrequestleft > 0) {
if (s.getrequestleft > 0)
{
cptr = getrequest = (char *)uip_appdata;
cptr = copy_string(cptr, http_get, sizeof(http_get) - 1);
@ -211,7 +215,8 @@ acked(void)
{
u16_t len;
if(s.getrequestleft > 0) {
if (s.getrequestleft > 0)
{
len = s.getrequestleft > uip_mss()?
uip_mss():
s.getrequestleft;
@ -225,30 +230,40 @@ parse_statusline(u16_t len)
{
char *cptr;
while(len > 0 && s.httpheaderlineptr < sizeof(s.httpheaderline)) {
while (len > 0 && s.httpheaderlineptr < sizeof(s.httpheaderline))
{
s.httpheaderline[s.httpheaderlineptr] = *(char *)uip_appdata;
++((char *)uip_appdata);
--len;
if(s.httpheaderline[s.httpheaderlineptr] == ISO_nl) {
if (s.httpheaderline[s.httpheaderlineptr] == ISO_nl)
{
if ((strncmp(s.httpheaderline, http_10,
sizeof(http_10) - 1) == 0) ||
(strncmp(s.httpheaderline, http_11,
sizeof(http_11) - 1) == 0)) {
sizeof(http_11) - 1) == 0))
{
cptr = &(s.httpheaderline[9]);
s.httpflag = HTTPFLAG_NONE;
if(strncmp(cptr, http_200, sizeof(http_200) - 1) == 0) {
if (strncmp(cptr, http_200, sizeof(http_200) - 1) == 0)
{
/* 200 OK */
s.httpflag = HTTPFLAG_OK;
} else if(strncmp(cptr, http_301, sizeof(http_301) - 1) == 0 ||
strncmp(cptr, http_302, sizeof(http_302) - 1) == 0) {
}
else if (strncmp(cptr, http_301, sizeof(http_301) - 1) == 0 ||
strncmp(cptr, http_302, sizeof(http_302) - 1) == 0)
{
/* 301 Moved permanently or 302 Found. Location: header line
will contain thw new location. */
s.httpflag = HTTPFLAG_MOVED;
} else {
}
else
{
s.httpheaderline[s.httpheaderlineptr - 1] = 0;
}
} else {
}
else
{
uip_abort();
webclient_aborted();
return 0;
@ -259,7 +274,9 @@ parse_statusline(u16_t len)
s.httpheaderlineptr = 0;
s.state = WEBCLIENT_STATE_HEADERS;
break;
} else {
}
else
{
++s.httpheaderlineptr;
}
}
@ -271,13 +288,16 @@ casecmp(char *str1, const char *str2, char len)
{
static char c;
while(len > 0) {
while (len > 0)
{
c = *str1;
/* Force lower-case characters. */
if(c & 0x40) {
if (c & 0x40)
{
c |= 0x20;
}
if(*str2 != c) {
if (*str2 != c)
{
return 1;
}
++str1;
@ -293,14 +313,17 @@ parse_headers(u16_t len)
char *cptr;
static unsigned char i;
while(len > 0 && s.httpheaderlineptr < sizeof(s.httpheaderline)) {
while (len > 0 && s.httpheaderlineptr < sizeof(s.httpheaderline))
{
s.httpheaderline[s.httpheaderlineptr] = *(char *)uip_appdata;
++((char *)uip_appdata);
--len;
if(s.httpheaderline[s.httpheaderlineptr] == ISO_nl) {
if (s.httpheaderline[s.httpheaderlineptr] == ISO_nl)
{
/* We have an entire HTTP header line in s.httpheaderline, so
we parse it. */
if(s.httpheaderline[0] == ISO_cr) {
if (s.httpheaderline[0] == ISO_cr)
{
/* This was the last header line (i.e., and empty "\r\n"), so
we are done with the headers and proceed with the actual
data. */
@ -311,26 +334,33 @@ parse_headers(u16_t len)
s.httpheaderline[s.httpheaderlineptr - 1] = 0;
/* Check for specific HTTP header fields. */
if (casecmp(s.httpheaderline, http_content_type,
sizeof(http_content_type) - 1) == 0) {
sizeof(http_content_type) - 1) == 0)
{
/* Found Content-type field. */
cptr = strchr(s.httpheaderline, ';');
if(cptr != NULL) {
if (cptr != NULL)
{
*cptr = 0;
}
strncpy(s.mimetype, s.httpheaderline +
sizeof(http_content_type) - 1, sizeof(s.mimetype));
} else if(casecmp(s.httpheaderline, http_location,
sizeof(http_location) - 1) == 0) {
}
else if (casecmp(s.httpheaderline, http_location,
sizeof(http_location) - 1) == 0)
{
cptr = s.httpheaderline +
sizeof(http_location) - 1;
if(strncmp(cptr, http_http, 7) == 0) {
if (strncmp(cptr, http_http, 7) == 0)
{
cptr += 7;
for(i = 0; i < s.httpheaderlineptr - 7; ++i) {
for (i = 0; i < s.httpheaderlineptr - 7; ++i)
{
if (*cptr == 0 ||
*cptr == '/' ||
*cptr == ' ' ||
*cptr == ':') {
*cptr == ':')
{
s.host[i] = 0;
break;
}
@ -346,7 +376,9 @@ parse_headers(u16_t len)
/* We're done parsing, so we reset the pointer and start the
next line. */
s.httpheaderlineptr = 0;
} else {
}
else
{
++s.httpheaderlineptr;
}
}
@ -360,16 +392,19 @@ newdata(void)
len = uip_datalen();
if(s.state == WEBCLIENT_STATE_STATUSLINE) {
if (s.state == WEBCLIENT_STATE_STATUSLINE)
{
len = parse_statusline(len);
}
if(s.state == WEBCLIENT_STATE_HEADERS && len > 0) {
if (s.state == WEBCLIENT_STATE_HEADERS && len > 0)
{
len = parse_headers(len);
}
if (len > 0 && s.state == WEBCLIENT_STATE_DATA &&
s.httpflag != HTTPFLAG_MOVED) {
s.httpflag != HTTPFLAG_MOVED)
{
webclient_datahandler((char *)uip_appdata, len);
}
}
@ -377,7 +412,8 @@ newdata(void)
void
webclient_appcall(void)
{
if(uip_connected()) {
if (uip_connected())
{
s.timer = 0;
s.state = WEBCLIENT_STATE_STATUSLINE;
senddata();
@ -385,35 +421,44 @@ webclient_appcall(void)
return;
}
if(s.state == WEBCLIENT_STATE_CLOSE) {
if (s.state == WEBCLIENT_STATE_CLOSE)
{
webclient_closed();
uip_abort();
return;
}
if(uip_aborted()) {
if (uip_aborted())
{
webclient_aborted();
}
if(uip_timedout()) {
if (uip_timedout())
{
webclient_timedout();
}
if(uip_acked()) {
if (uip_acked())
{
s.timer = 0;
acked();
}
if(uip_newdata()) {
if (uip_newdata())
{
s.timer = 0;
newdata();
}
if (uip_rexmit() ||
uip_newdata() ||
uip_acked()) {
uip_acked())
{
senddata();
} else if(uip_poll()) {
}
else if (uip_poll())
{
++s.timer;
if(s.timer == WEBCLIENT_TIMEOUT) {
if (s.timer == WEBCLIENT_TIMEOUT)
{
webclient_timedout();
uip_abort();
return;
@ -421,12 +466,17 @@ webclient_appcall(void)
/* senddata();*/
}
if(uip_closed()) {
if(s.httpflag != HTTPFLAG_MOVED) {
if (uip_closed())
{
if (s.httpflag != HTTPFLAG_MOVED)
{
/* Send NULL data to signal EOF. */
webclient_datahandler(NULL, 0);
} else {
if(resolv_lookup(s.host) == NULL) {
}
else
{
if (resolv_lookup(s.host) == NULL)
{
resolv_query(s.host);
}
webclient_get(s.host, s.port, s.file);

View File

@ -52,7 +52,8 @@
#define WEBCLIENT_CONF_MAX_URLLEN 100
struct webclient_state {
struct webclient_state
{
u8_t timer;
u8_t state;
u8_t httpflag;

View File

@ -74,8 +74,10 @@ httpd_cgi(char *name)
const struct httpd_cgi_call **f;
/* Find the matching name in the table, return the function. */
for(f = calls; *f != NULL; ++f) {
if(strncmp((*f)->name, name, strlen((*f)->name)) == 0) {
for (f = calls; *f != NULL; ++f)
{
if (strncmp((*f)->name, name, strlen((*f)->name)) == 0)
{
return (*f)->function;
}
}
@ -102,31 +104,48 @@ PT_THREAD(file_stats(struct httpd_state *s, char *ptr))
static const char closed[] = /* "CLOSED",*/
{0x43, 0x4c, 0x4f, 0x53, 0x45, 0x44, 0};
static const char syn_rcvd[] = /* "SYN-RCVD",*/
{0x53, 0x59, 0x4e, 0x2d, 0x52, 0x43, 0x56,
0x44, 0};
{
0x53, 0x59, 0x4e, 0x2d, 0x52, 0x43, 0x56,
0x44, 0
};
static const char syn_sent[] = /* "SYN-SENT",*/
{0x53, 0x59, 0x4e, 0x2d, 0x53, 0x45, 0x4e,
0x54, 0};
{
0x53, 0x59, 0x4e, 0x2d, 0x53, 0x45, 0x4e,
0x54, 0
};
static const char established[] = /* "ESTABLISHED",*/
{0x45, 0x53, 0x54, 0x41, 0x42, 0x4c, 0x49, 0x53, 0x48,
0x45, 0x44, 0};
{
0x45, 0x53, 0x54, 0x41, 0x42, 0x4c, 0x49, 0x53, 0x48,
0x45, 0x44, 0
};
static const char fin_wait_1[] = /* "FIN-WAIT-1",*/
{0x46, 0x49, 0x4e, 0x2d, 0x57, 0x41, 0x49,
0x54, 0x2d, 0x31, 0};
{
0x46, 0x49, 0x4e, 0x2d, 0x57, 0x41, 0x49,
0x54, 0x2d, 0x31, 0
};
static const char fin_wait_2[] = /* "FIN-WAIT-2",*/
{0x46, 0x49, 0x4e, 0x2d, 0x57, 0x41, 0x49,
0x54, 0x2d, 0x32, 0};
{
0x46, 0x49, 0x4e, 0x2d, 0x57, 0x41, 0x49,
0x54, 0x2d, 0x32, 0
};
static const char closing[] = /* "CLOSING",*/
{0x43, 0x4c, 0x4f, 0x53, 0x49,
0x4e, 0x47, 0};
{
0x43, 0x4c, 0x4f, 0x53, 0x49,
0x4e, 0x47, 0
};
static const char time_wait[] = /* "TIME-WAIT,"*/
{0x54, 0x49, 0x4d, 0x45, 0x2d, 0x57, 0x41,
0x49, 0x54, 0};
{
0x54, 0x49, 0x4d, 0x45, 0x2d, 0x57, 0x41,
0x49, 0x54, 0
};
static const char last_ack[] = /* "LAST-ACK"*/
{0x4c, 0x41, 0x53, 0x54, 0x2d, 0x41, 0x43,
0x4b, 0};
{
0x4c, 0x41, 0x53, 0x54, 0x2d, 0x41, 0x43,
0x4b, 0
};
static const char *states[] = {
static const char *states[] =
{
closed,
syn_rcvd,
syn_sent,
@ -135,7 +154,8 @@ static const char *states[] = {
fin_wait_2,
closing,
time_wait,
last_ack};
last_ack
};
static unsigned short
@ -166,8 +186,10 @@ PT_THREAD(tcp_stats(struct httpd_state *s, char *ptr))
PSOCK_BEGIN(&s->sout);
for(s->count = 0; s->count < UIP_CONNS; ++s->count) {
if((uip_conns[s->count].tcpstateflags & UIP_TS_MASK) != UIP_CLOSED) {
for (s->count = 0; s->count < UIP_CONNS; ++s->count)
{
if ((uip_conns[s->count].tcpstateflags & UIP_TS_MASK) != UIP_CLOSED)
{
PSOCK_GENERATOR_SEND(&s->sout, generate_tcp_stats, s);
}
}
@ -191,7 +213,8 @@ PT_THREAD(net_stats(struct httpd_state *s, char *ptr))
#if UIP_STATISTICS
for (s->count = 0; s->count < sizeof(uip_stat) / sizeof(uip_stats_t);
++s->count) {
++s->count)
{
PSOCK_GENERATOR_SEND(&s->sout, generate_net_stats, s);
}

View File

@ -57,7 +57,8 @@ typedef PT_THREAD((* httpd_cgifunction)(struct httpd_state *, char *));
httpd_cgifunction httpd_cgi(char *name);
struct httpd_cgi_call {
struct httpd_cgi_call
{
const char *name;
const httpd_cgifunction function;
};

View File

@ -57,11 +57,13 @@ httpd_fs_strcmp(const char *str1, const char *str2)
if (str2[i] == 0 ||
str1[i] == '\r' ||
str1[i] == '\n') {
str1[i] == '\n')
{
return 0;
}
if(str1[i] != str2[i]) {
if (str1[i] != str2[i])
{
return 1;
}
@ -80,9 +82,11 @@ httpd_fs_open(const char *name, struct httpd_fs_file *file)
for (f = (struct httpd_fsdata_file_noconst *)HTTPD_FS_ROOT;
f != NULL;
f = (struct httpd_fsdata_file_noconst *)f->next) {
f = (struct httpd_fsdata_file_noconst *)f->next)
{
if(httpd_fs_strcmp(name, f->name) == 0) {
if (httpd_fs_strcmp(name, f->name) == 0)
{
file->data = f->data;
file->len = f->len;
#if HTTPD_FS_STATISTICS
@ -103,7 +107,8 @@ httpd_fs_init(void)
{
#if HTTPD_FS_STATISTICS
u16_t i;
for(i = 0; i < HTTPD_FS_NUMFILES; i++) {
for (i = 0; i < HTTPD_FS_NUMFILES; i++)
{
count[i] = 0;
}
#endif /* HTTPD_FS_STATISTICS */
@ -119,9 +124,11 @@ u16_t httpd_fs_count
i = 0;
for (f = (struct httpd_fsdata_file_noconst *)HTTPD_FS_ROOT;
f != NULL;
f = (struct httpd_fsdata_file_noconst *)f->next) {
f = (struct httpd_fsdata_file_noconst *)f->next)
{
if(httpd_fs_strcmp(name, f->name) == 0) {
if (httpd_fs_strcmp(name, f->name) == 0)
{
return count[i];
}
++i;

View File

@ -37,7 +37,8 @@
#define HTTPD_FS_STATISTICS 1
struct httpd_fs_file {
struct httpd_fs_file
{
char *data;
int len;
};

View File

@ -1,4 +1,5 @@
static const unsigned char data_processes_shtml[] = {
static const unsigned char data_processes_shtml[] =
{
/* /processes.shtml */
0x2f, 0x70, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x65, 0x73, 0x2e, 0x73, 0x68, 0x74, 0x6d, 0x6c, 0,
0x25, 0x21, 0x3a, 0x20, 0x2f, 0x68, 0x65, 0x61, 0x64, 0x65,
@ -21,9 +22,11 @@ static const unsigned char data_processes_shtml[] = {
0x74, 0x68, 0x3e, 0x3c, 0x2f, 0x74, 0x72, 0x3e, 0xa, 0x25,
0x21, 0x20, 0x70, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x65,
0x73, 0xa, 0x25, 0x21, 0x3a, 0x20, 0x2f, 0x66, 0x6f, 0x6f,
0x74, 0x65, 0x72, 0x2e, 0x68, 0x74, 0x6d, 0x6c, 0};
0x74, 0x65, 0x72, 0x2e, 0x68, 0x74, 0x6d, 0x6c, 0
};
static const unsigned char data_404_html[] = {
static const unsigned char data_404_html[] =
{
/* /404.html */
0x2f, 0x34, 0x30, 0x34, 0x2e, 0x68, 0x74, 0x6d, 0x6c, 0,
0x3c, 0x68, 0x74, 0x6d, 0x6c, 0x3e, 0xa, 0x20, 0x20, 0x3c,
@ -42,9 +45,11 @@ static const unsigned char data_404_html[] = {
0x20, 0x20, 0x20, 0x3c, 0x2f, 0x63, 0x65, 0x6e, 0x74, 0x65,
0x72, 0x3e, 0xa, 0x20, 0x20, 0x3c, 0x2f, 0x62, 0x6f, 0x64,
0x79, 0x3e, 0xa, 0x3c, 0x2f, 0x68, 0x74, 0x6d, 0x6c, 0x3e,
0};
0
};
static const unsigned char data_files_shtml[] = {
static const unsigned char data_files_shtml[] =
{
/* /files.shtml */
0x2f, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x2e, 0x73, 0x68, 0x74, 0x6d, 0x6c, 0,
0x25, 0x21, 0x3a, 0x20, 0x2f, 0x68, 0x65, 0x61, 0x64, 0x65,
@ -172,15 +177,19 @@ static const unsigned char data_files_shtml[] = {
0x61, 0x62, 0x6c, 0x65, 0x3e, 0xa, 0x3c, 0x2f, 0x63, 0x65,
0x6e, 0x74, 0x65, 0x72, 0x3e, 0xa, 0x25, 0x21, 0x3a, 0x20,
0x2f, 0x66, 0x6f, 0x6f, 0x74, 0x65, 0x72, 0x2e, 0x68, 0x74,
0x6d, 0x6c, 0xa, 0};
0x6d, 0x6c, 0xa, 0
};
static const unsigned char data_footer_html[] = {
static const unsigned char data_footer_html[] =
{
/* /footer.html */
0x2f, 0x66, 0x6f, 0x6f, 0x74, 0x65, 0x72, 0x2e, 0x68, 0x74, 0x6d, 0x6c, 0,
0x20, 0x20, 0x3c, 0x2f, 0x62, 0x6f, 0x64, 0x79, 0x3e, 0xa,
0x3c, 0x2f, 0x68, 0x74, 0x6d, 0x6c, 0x3e, 0};
0x3c, 0x2f, 0x68, 0x74, 0x6d, 0x6c, 0x3e, 0
};
static const unsigned char data_header_html[] = {
static const unsigned char data_header_html[] =
{
/* /header.html */
0x2f, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x2e, 0x68, 0x74, 0x6d, 0x6c, 0,
0x3c, 0x21, 0x44, 0x4f, 0x43, 0x54, 0x59, 0x50, 0x45, 0x20,
@ -245,9 +254,11 @@ static const unsigned char data_header_html[] = {
0x2f, 0x64, 0x69, 0x76, 0x3e, 0xa, 0x20, 0x20, 0xa, 0x20,
0x20, 0x3c, 0x64, 0x69, 0x76, 0x20, 0x63, 0x6c, 0x61, 0x73,
0x73, 0x3d, 0x22, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74,
0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x22, 0x3e, 0xa, 0};
0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x22, 0x3e, 0xa, 0
};
static const unsigned char data_index_html[] = {
static const unsigned char data_index_html[] =
{
/* /index.html */
0x2f, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x2e, 0x68, 0x74, 0x6d, 0x6c, 0,
0x3c, 0x21, 0x44, 0x4f, 0x43, 0x54, 0x59, 0x50, 0x45, 0x20,
@ -337,9 +348,11 @@ static const unsigned char data_index_html[] = {
0x73, 0x74, 0x69, 0x63, 0x73, 0x2e, 0xa, 0x20, 0x20, 0x3c,
0x2f, 0x70, 0x3e, 0xa, 0xa, 0x20, 0x20, 0x3c, 0x2f, 0x62,
0x6f, 0x64, 0x79, 0x3e, 0xa, 0x3c, 0x2f, 0x68, 0x74, 0x6d,
0x6c, 0x3e, 0xa, 0};
0x6c, 0x3e, 0xa, 0
};
static const unsigned char data_style_css[] = {
static const unsigned char data_style_css[] =
{
/* /style.css */
0x2f, 0x73, 0x74, 0x79, 0x6c, 0x65, 0x2e, 0x63, 0x73, 0x73, 0,
0x68, 0x31, 0x20, 0xa, 0x7b, 0xa, 0x20, 0x20, 0x74, 0x65,
@ -443,9 +456,11 @@ static const unsigned char data_style_css[] = {
0x70, 0x2e, 0x72, 0x69, 0x67, 0x68, 0x74, 0xa, 0x7b, 0xa,
0x20, 0x20, 0x74, 0x65, 0x78, 0x74, 0x2d, 0x61, 0x6c, 0x69,
0x67, 0x6e, 0x3a, 0x72, 0x69, 0x67, 0x68, 0x74, 0x3b, 0x20,
0xa, 0x7d, 0xa, 0xa, 0};
0xa, 0x7d, 0xa, 0xa, 0
};
static const unsigned char data_tcp_shtml[] = {
static const unsigned char data_tcp_shtml[] =
{
/* /tcp.shtml */
0x2f, 0x74, 0x63, 0x70, 0x2e, 0x73, 0x68, 0x74, 0x6d, 0x6c, 0,
0x25, 0x21, 0x3a, 0x20, 0x2f, 0x68, 0x65, 0x61, 0x64, 0x65,
@ -469,9 +484,11 @@ static const unsigned char data_tcp_shtml[] = {
0x70, 0x2d, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69,
0x6f, 0x6e, 0x73, 0xa, 0x25, 0x21, 0x3a, 0x20, 0x2f, 0x66,
0x6f, 0x6f, 0x74, 0x65, 0x72, 0x2e, 0x68, 0x74, 0x6d, 0x6c,
0};
0
};
static const unsigned char data_fade_png[] = {
static const unsigned char data_fade_png[] =
{
/* /fade.png */
0x2f, 0x66, 0x61, 0x64, 0x65, 0x2e, 0x70, 0x6e, 0x67, 0,
0x89, 0x50, 0x4e, 0x47, 0xd, 0xa, 0x1a, 0xa, 00, 00,
@ -493,9 +510,11 @@ static const unsigned char data_fade_png[] = {
0x1, 0xf8, 0x29, 0x58, 0xc8, 0xbf, 0x48, 0xc4, 0x81, 0x74,
0xb, 0xa3, 0xf, 0x7c, 0xdb, 0x4, 0xe8, 0x40, 0x5, 0xdf,
0xa1, 0xf3, 0xfc, 0x73, 00, 00, 00, 00, 0x49, 0x45,
0x4e, 0x44, 0xae, 0x42, 0x60, 0x82, 0};
0x4e, 0x44, 0xae, 0x42, 0x60, 0x82, 0
};
static const unsigned char data_stats_shtml[] = {
static const unsigned char data_stats_shtml[] =
{
/* /stats.shtml */
0x2f, 0x73, 0x74, 0x61, 0x74, 0x73, 0x2e, 0x73, 0x68, 0x74, 0x6d, 0x6c, 0,
0x25, 0x21, 0x3a, 0x20, 0x2f, 0x68, 0x65, 0x61, 0x64, 0x65,
@ -580,7 +599,8 @@ static const unsigned char data_stats_shtml[] = {
0x6c, 0x65, 0x3e, 0xa, 0x3c, 0x2f, 0x63, 0x65, 0x6e, 0x74,
0x65, 0x72, 0x3e, 0xa, 0x25, 0x21, 0x3a, 0x20, 0x2f, 0x66,
0x6f, 0x6f, 0x74, 0x65, 0x72, 0x2e, 0x68, 0x74, 0x6d, 0x6c,
0xa, 0};
0xa, 0
};
const struct httpd_fsdata_file file_processes_shtml[] = {{NULL, data_processes_shtml, data_processes_shtml + 17, sizeof(data_processes_shtml) - 17}};

View File

@ -37,7 +37,8 @@
#include "uip.h"
struct httpd_fsdata_file {
struct httpd_fsdata_file
{
const struct httpd_fsdata_file *next;
const char *name;
const char *data;
@ -49,7 +50,8 @@ struct httpd_fsdata_file {
#endif /* HTTPD_FS_STATISTICS */
};
struct httpd_fsdata_file_noconst {
struct httpd_fsdata_file_noconst
{
struct httpd_fsdata_file *next;
char *name;
char *data;

View File

@ -81,9 +81,12 @@ generate_part_of_file(void *state)
{
struct httpd_state *s = (struct httpd_state *)state;
if(s->file.len > uip_mss()) {
if (s->file.len > uip_mss())
{
s->len = uip_mss();
} else {
}
else
{
s->len = s->file.len;
}
memcpy(uip_appdata, s->file.data, s->len);
@ -96,11 +99,13 @@ PT_THREAD(send_file(struct httpd_state *s))
{
PSOCK_BEGIN(&s->sout);
do {
do
{
PSOCK_GENERATOR_SEND(&s->sout, generate_part_of_file, s);
s->file.len -= s->len;
s->file.data += s->len;
} while(s->file.len > 0);
}
while (s->file.len > 0);
PSOCK_END(&s->sout);
}
@ -132,17 +137,22 @@ PT_THREAD(handle_script(struct httpd_state *s))
PT_BEGIN(&s->scriptpt);
while(s->file.len > 0) {
while (s->file.len > 0)
{
/* Check if we should start executing a script. */
if (*s->file.data == ISO_percent &&
*(s->file.data + 1) == ISO_bang) {
*(s->file.data + 1) == ISO_bang)
{
s->scriptptr = s->file.data + 3;
s->scriptlen = s->file.len - 3;
if(*(s->scriptptr - 1) == ISO_colon) {
if (*(s->scriptptr - 1) == ISO_colon)
{
httpd_fs_open(s->scriptptr + 1, &s->file);
PT_WAIT_THREAD(&s->scriptpt, send_file(s));
} else {
}
else
{
PT_WAIT_THREAD(&s->scriptpt,
httpd_cgi(s->scriptptr)(s, s->scriptptr));
}
@ -152,25 +162,35 @@ PT_THREAD(handle_script(struct httpd_state *s))
sending the rest of the file. */
s->file.data = s->scriptptr;
s->file.len = s->scriptlen;
} else {
}
else
{
/* See if we find the start of script marker in the block of HTML
to be sent. */
if(s->file.len > uip_mss()) {
if (s->file.len > uip_mss())
{
s->len = uip_mss();
} else {
}
else
{
s->len = s->file.len;
}
if(*s->file.data == ISO_percent) {
if (*s->file.data == ISO_percent)
{
ptr = strchr(s->file.data + 1, ISO_percent);
} else {
}
else
{
ptr = strchr(s->file.data, ISO_percent);
}
if (ptr != NULL &&
ptr != s->file.data) {
ptr != s->file.data)
{
s->len = (int)(ptr - s->file.data);
if(s->len >= uip_mss()) {
if (s->len >= uip_mss())
{
s->len = uip_mss();
}
}
@ -194,20 +214,33 @@ PT_THREAD(send_headers(struct httpd_state *s, const char *statushdr))
PSOCK_SEND_STR(&s->sout, statushdr);
ptr = strrchr(s->filename, ISO_period);
if(ptr == NULL) {
if (ptr == NULL)
{
PSOCK_SEND_STR(&s->sout, http_content_type_binary);
} else if(strncmp(http_html, ptr, 5) == 0 ||
strncmp(http_shtml, ptr, 6) == 0) {
}
else if (strncmp(http_html, ptr, 5) == 0 ||
strncmp(http_shtml, ptr, 6) == 0)
{
PSOCK_SEND_STR(&s->sout, http_content_type_html);
} else if(strncmp(http_css, ptr, 4) == 0) {
}
else if (strncmp(http_css, ptr, 4) == 0)
{
PSOCK_SEND_STR(&s->sout, http_content_type_css);
} else if(strncmp(http_png, ptr, 4) == 0) {
}
else if (strncmp(http_png, ptr, 4) == 0)
{
PSOCK_SEND_STR(&s->sout, http_content_type_png);
} else if(strncmp(http_gif, ptr, 4) == 0) {
}
else if (strncmp(http_gif, ptr, 4) == 0)
{
PSOCK_SEND_STR(&s->sout, http_content_type_gif);
} else if(strncmp(http_jpg, ptr, 4) == 0) {
}
else if (strncmp(http_jpg, ptr, 4) == 0)
{
PSOCK_SEND_STR(&s->sout, http_content_type_jpg);
} else {
}
else
{
PSOCK_SEND_STR(&s->sout, http_content_type_plain);
}
PSOCK_END(&s->sout);
@ -220,7 +253,8 @@ PT_THREAD(handle_output(struct httpd_state *s))
PT_BEGIN(&s->outputpt);
if(!httpd_fs_open(s->filename, &s->file)) {
if (!httpd_fs_open(s->filename, &s->file))
{
httpd_fs_open(http_404_html, &s->file);
strcpy(s->filename, http_404_html);
PT_WAIT_THREAD(&s->outputpt,
@ -228,15 +262,20 @@ PT_THREAD(handle_output(struct httpd_state *s))
http_header_404));
PT_WAIT_THREAD(&s->outputpt,
send_file(s));
} else {
}
else
{
PT_WAIT_THREAD(&s->outputpt,
send_headers(s,
http_header_200));
ptr = strchr(s->filename, ISO_period);
if(ptr != NULL && strncmp(ptr, http_shtml, 6) == 0) {
if (ptr != NULL && strncmp(ptr, http_shtml, 6) == 0)
{
PT_INIT(&s->scriptpt);
PT_WAIT_THREAD(&s->outputpt, handle_script(s));
} else {
}
else
{
PT_WAIT_THREAD(&s->outputpt,
send_file(s));
}
@ -253,18 +292,23 @@ PT_THREAD(handle_input(struct httpd_state *s))
PSOCK_READTO(&s->sin, ISO_space);
if(strncmp(s->inputbuf, http_get, 4) != 0) {
if (strncmp(s->inputbuf, http_get, 4) != 0)
{
PSOCK_CLOSE_EXIT(&s->sin);
}
PSOCK_READTO(&s->sin, ISO_space);
if(s->inputbuf[0] != ISO_slash) {
if (s->inputbuf[0] != ISO_slash)
{
PSOCK_CLOSE_EXIT(&s->sin);
}
if(s->inputbuf[1] == ISO_space) {
if (s->inputbuf[1] == ISO_space)
{
strncpy(s->filename, http_index_html, sizeof(s->filename));
} else {
}
else
{
s->inputbuf[PSOCK_DATALEN(&s->sin) - 1] = 0;
strncpy(s->filename, &s->inputbuf[0], sizeof(s->filename));
}
@ -273,10 +317,12 @@ PT_THREAD(handle_input(struct httpd_state *s))
s->state = STATE_OUTPUT;
while(1) {
while (1)
{
PSOCK_READTO(&s->sin, ISO_nl);
if(strncmp(s->inputbuf, http_referer, 8) == 0) {
if (strncmp(s->inputbuf, http_referer, 8) == 0)
{
s->inputbuf[PSOCK_DATALEN(&s->sin) - 2] = 0;
/* httpd_log(&s->inputbuf[9]);*/
}
@ -289,7 +335,8 @@ static void
handle_connection(struct httpd_state *s)
{
handle_input(s);
if(s->state == STATE_OUTPUT) {
if (s->state == STATE_OUTPUT)
{
handle_output(s);
}
}
@ -299,8 +346,11 @@ httpd_appcall(void)
{
struct httpd_state *s = (struct httpd_state *)&(uip_conn->appstate);
if(uip_closed() || uip_aborted() || uip_timedout()) {
} else if(uip_connected()) {
if (uip_closed() || uip_aborted() || uip_timedout())
{
}
else if (uip_connected())
{
PSOCK_INIT(&s->sin, s->inputbuf, sizeof(s->inputbuf) - 1);
PSOCK_INIT(&s->sout, s->inputbuf, sizeof(s->inputbuf) - 1);
PT_INIT(&s->outputpt);
@ -308,17 +358,25 @@ httpd_appcall(void)
/* timer_set(&s->timer, CLOCK_SECOND * 100);*/
s->timer = 0;
handle_connection(s);
} else if(s != NULL) {
if(uip_poll()) {
}
else if (s != NULL)
{
if (uip_poll())
{
++s->timer;
if(s->timer >= 20) {
if (s->timer >= 20)
{
uip_abort();
}
} else {
}
else
{
s->timer = 0;
}
handle_connection(s);
} else {
}
else
{
uip_abort();
}
}

View File

@ -38,7 +38,8 @@
#include "psock.h"
#include "httpd-fs.h"
struct httpd_state {
struct httpd_state
{
unsigned char timer;
struct psock sin, sout;
struct pt outputpt, scriptpt;

View File

@ -25,49 +25,62 @@ main(void)
httpd_init();
while(1) {
while (1)
{
uip_len = network_device_read();
if(uip_len > 0) {
if(BUF->type == htons(UIP_ETHTYPE_IP)) {
if (uip_len > 0)
{
if (BUF->type == htons(UIP_ETHTYPE_IP))
{
uip_arp_ipin();
uip_input();
/* If the above function invocation resulted in data that
should be sent out on the network, the global variable
uip_len is set to a value > 0. */
if(uip_len > 0) {
if (uip_len > 0)
{
uip_arp_out();
network_device_send();
}
} else if(BUF->type == htons(UIP_ETHTYPE_ARP)) {
}
else if (BUF->type == htons(UIP_ETHTYPE_ARP))
{
uip_arp_arpin();
/* If the above function invocation resulted in data that
should be sent out on the network, the global variable
uip_len is set to a value > 0. */
if(uip_len > 0) {
if (uip_len > 0)
{
network_device_send();
}
}
} else if(timer_expired(&periodic_timer)) {
}
else if (timer_expired(&periodic_timer))
{
timer_reset(&periodic_timer);
for(i = 0; i < UIP_CONNS; i++) {
for (i = 0; i < UIP_CONNS; i++)
{
uip_periodic(i);
/* If the above function invocation resulted in data that
should be sent out on the network, the global variable
uip_len is set to a value > 0. */
if(uip_len > 0) {
if (uip_len > 0)
{
uip_arp_out();
network_device_send();
}
}
#if UIP_UDP
for(i = 0; i < UIP_UDP_CONNS; i++) {
for (i = 0; i < UIP_UDP_CONNS; i++)
{
uip_udp_periodic(i);
/* If the above function invocation resulted in data that
should be sent out on the network, the global variable
uip_len is set to a value > 0. */
if(uip_len > 0) {
if (uip_len > 0)
{
uip_arp_out();
network_device_send();
}
@ -75,7 +88,8 @@ main(void)
#endif /* UIP_UDP */
/* Call the ARP timer function every 10 seconds. */
if(timer_expired(&arp_timer)) {
if (timer_expired(&arp_timer))
{
timer_reset(&arp_timer);
uip_arp_timer();
}

View File

@ -22,35 +22,44 @@ main(void)
httpd_init();
while(1) {
while (1)
{
uip_len = network_device_read();
if(uip_len > 0) {
if (uip_len > 0)
{
uip_input();
/* If the above function invocation resulted in data that
should be sent out on the network, the global variable
uip_len is set to a value > 0. */
if(uip_len > 0) {
if (uip_len > 0)
{
network_device_send();
}
} else if(timer_expired(&periodic_timer)) {
}
else if (timer_expired(&periodic_timer))
{
timer_reset(&periodic_timer);
for(i = 0; i < UIP_CONNS; i++) {
for (i = 0; i < UIP_CONNS; i++)
{
uip_periodic(i);
/* If the above function invocation resulted in data that
should be sent out on the network, the global variable
uip_len is set to a value > 0. */
if(uip_len > 0) {
if (uip_len > 0)
{
network_device_send();
}
}
#if UIP_UDP
for(i = 0; i < UIP_UDP_CONNS; i++) {
for (i = 0; i < UIP_UDP_CONNS; i++)
{
uip_udp_periodic(i);
/* If the above function invocation resulted in data that
should be sent out on the network, the global variable
uip_len is set to a value > 0. */
if(uip_len > 0) {
if (uip_len > 0)
{
network_device_send();
}
}

View File

@ -84,16 +84,21 @@ code_style_example_function(void)
* Curly brackets following for(), if(), do, and case() statements
* should follow the statement on the same line.
*/
for(i = 0; i < 10; ++i) {
for (i = 0; i < 10; ++i)
{
/*
* Always use full blocks (curly brackets) after if(), for(), and
* while() statements, even though the statement is a single line
* of code. This makes the code easier to read and modifications
* are less error prone.
*/
if(i == c) {
if (i == c)
{
return c; /* No parentesis around return values. */
} else { /* The else keyword is placed inbetween
}
else
{
/* The else keyword is placed inbetween
curly brackers, always on its own line. */
c++;
}

View File

@ -60,8 +60,10 @@ memb_alloc(struct memb_blocks *m)
{
int i;
for(i = 0; i < m->num; ++i) {
if(m->count[i] == 0) {
for (i = 0; i < m->num; ++i)
{
if (m->count[i] == 0)
{
/* If this block was unused, we increase the reference count to
indicate that it now is used and return a pointer to the
memory block. */
@ -84,12 +86,15 @@ memb_free(struct memb_blocks *m, void *ptr)
/* Walk through the list of blocks and try to find the block to
which the pointer "ptr" points to. */
ptr2 = (char *)m->mem;
for(i = 0; i < m->num; ++i) {
for (i = 0; i < m->num; ++i)
{
if(ptr2 == (char *)ptr) {
if (ptr2 == (char *)ptr)
{
/* We've found to block to which "ptr" points so we decrease the
reference count and return the new value of it. */
if(m->count[i] > 0) {
if (m->count[i] > 0)
{
/* Make sure that we don't deallocate free memory. */
--(m->count[i]);
}

View File

@ -102,7 +102,8 @@ MEMB(connections, sizeof(struct connection), 16);
MEMB_CONCAT(name,_memb_count), \
(void *)MEMB_CONCAT(name,_memb_mem)}
struct memb_blocks {
struct memb_blocks
{
unsigned short size;
unsigned short num;
char *count;

View File

@ -83,21 +83,26 @@ static u8_t
buf_bufdata(struct psock_buf *buf, u16_t len,
u8_t **dataptr, u16_t *datalen)
{
if(*datalen < buf->left) {
if (*datalen < buf->left)
{
memcpy(buf->ptr, *dataptr, *datalen);
buf->ptr += *datalen;
buf->left -= *datalen;
*dataptr += *datalen;
*datalen = 0;
return BUF_NOT_FULL;
} else if(*datalen == buf->left) {
}
else if (*datalen == buf->left)
{
memcpy(buf->ptr, *dataptr, *datalen);
buf->ptr += *datalen;
buf->left = 0;
*dataptr += *datalen;
*datalen = 0;
return BUF_FULL;
} else {
}
else
{
memcpy(buf->ptr, *dataptr, buf->left);
buf->ptr += buf->left;
*datalen -= buf->left;
@ -112,28 +117,33 @@ buf_bufto(register struct psock_buf *buf, u8_t endmarker,
register u8_t **dataptr, register u16_t *datalen)
{
u8_t c;
while(buf->left > 0 && *datalen > 0) {
while (buf->left > 0 && *datalen > 0)
{
c = *buf->ptr = **dataptr;
++*dataptr;
++buf->ptr;
--*datalen;
--buf->left;
if(c == endmarker) {
if (c == endmarker)
{
return BUF_FOUND;
}
}
if(*datalen == 0) {
if (*datalen == 0)
{
return BUF_NOT_FOUND;
}
while(*datalen > 0) {
while (*datalen > 0)
{
c = **dataptr;
--*datalen;
++*dataptr;
if(c == endmarker) {
if (c == endmarker)
{
return BUF_FOUND | BUF_FULL;
}
}
@ -144,10 +154,14 @@ buf_bufto(register struct psock_buf *buf, u8_t endmarker,
static char
send_data(register struct psock *s)
{
if(s->state != STATE_DATA_SENT || uip_rexmit()) {
if(s->sendlen > uip_mss()) {
if (s->state != STATE_DATA_SENT || uip_rexmit())
{
if (s->sendlen > uip_mss())
{
uip_send(s->sendptr, uip_mss());
} else {
}
else
{
uip_send(s->sendptr, s->sendlen);
}
s->state = STATE_DATA_SENT;
@ -159,11 +173,15 @@ send_data(register struct psock *s)
static char
data_acked(register struct psock *s)
{
if(s->state == STATE_DATA_SENT && uip_acked()) {
if(s->sendlen > uip_mss()) {
if (s->state == STATE_DATA_SENT && uip_acked())
{
if (s->sendlen > uip_mss())
{
s->sendlen -= uip_mss();
s->sendptr += uip_mss();
} else {
}
else
{
s->sendptr += s->sendlen;
s->sendlen = 0;
}
@ -179,7 +197,8 @@ PT_THREAD(psock_send(register struct psock *s, const char *buf,
PT_BEGIN(&s->psockpt);
/* If there is no data to send, we exit immediately. */
if(len == 0) {
if (len == 0)
{
PT_EXIT(&s->psockpt);
}
@ -192,7 +211,8 @@ PT_THREAD(psock_send(register struct psock *s, const char *buf,
/* We loop here until all data is sent. The s->sendlen variable is
updated by the data_sent() function. */
while(s->sendlen > 0) {
while (s->sendlen > 0)
{
/*
* The condition for this PT_WAIT_UNTIL is a little tricky: the
@ -218,7 +238,8 @@ PT_THREAD(psock_generator_send(register struct psock *s,
PT_BEGIN(&s->psockpt);
/* Ensure that there is a generator function to call. */
if(generate == NULL) {
if (generate == NULL)
{
PT_EXIT(&s->psockpt);
}
@ -228,15 +249,18 @@ PT_THREAD(psock_generator_send(register struct psock *s,
s->sendptr = uip_appdata;
s->state = STATE_NONE;
do {
do
{
/* Call the generator function again if we are called to perform a
retransmission. */
if(uip_rexmit()) {
if (uip_rexmit())
{
generate(arg);
}
/* Wait until all data is sent and acknowledged. */
PT_WAIT_UNTIL(&s->psockpt, data_acked(s) & send_data(s));
} while(s->sendlen > 0);
}
while (s->sendlen > 0);
s->state = STATE_NONE;
@ -252,18 +276,25 @@ psock_datalen(struct psock *psock)
char
psock_newdata(struct psock *s)
{
if(s->readlen > 0) {
if (s->readlen > 0)
{
/* There is data in the uip_appdata buffer that has not yet been
read with the PSOCK_READ functions. */
return 1;
} else if(s->state == STATE_READ) {
}
else if (s->state == STATE_READ)
{
/* All data in uip_appdata buffer already consumed. */
s->state = STATE_BLOCKED_NEWDATA;
return 0;
} else if(uip_newdata()) {
}
else if (uip_newdata())
{
/* There is new data that has not been consumed. */
return 1;
} else {
}
else
{
/* There is no new data. */
return 0;
}
@ -278,18 +309,22 @@ PT_THREAD(psock_readto(register struct psock *psock, unsigned char c))
/* XXX: Should add buf_checkmarker() before do{} loop, if
incoming data has been handled while waiting for a write. */
do {
if(psock->readlen == 0) {
do
{
if (psock->readlen == 0)
{
PT_WAIT_UNTIL(&psock->psockpt, psock_newdata(psock));
psock->state = STATE_READ;
psock->readptr = (u8_t *)uip_appdata;
psock->readlen = uip_datalen();
}
} while((buf_bufto(&psock->buf, c,
}
while ((buf_bufto(&psock->buf, c,
&psock->readptr,
&psock->readlen) & BUF_FOUND) == 0);
if(psock_datalen(psock) == 0) {
if (psock_datalen(psock) == 0)
{
psock->state = STATE_NONE;
PT_RESTART(&psock->psockpt);
}
@ -305,19 +340,23 @@ PT_THREAD(psock_readbuf(register struct psock *psock))
/* XXX: Should add buf_checkmarker() before do{} loop, if
incoming data has been handled while waiting for a write. */
do {
if(psock->readlen == 0) {
do
{
if (psock->readlen == 0)
{
PT_WAIT_UNTIL(&psock->psockpt, psock_newdata(psock));
printf("Waited for newdata\n");
psock->state = STATE_READ;
psock->readptr = (u8_t *)uip_appdata;
psock->readlen = uip_datalen();
}
} while(buf_bufdata(&psock->buf, psock->bufsize,
}
while (buf_bufdata(&psock->buf, psock->bufsize,
&psock->readptr,
&psock->readlen) != BUF_FULL);
if(psock_datalen(psock) == 0) {
if (psock_datalen(psock) == 0)
{
psock->state = STATE_NONE;
PT_RESTART(&psock->psockpt);
}

View File

@ -92,7 +92,8 @@
* provided by the library.
*
*/
struct psock_buf {
struct psock_buf
{
u8_t *ptr;
unsigned short left;
};
@ -103,7 +104,8 @@ struct psock_buf {
* The protosocket structrure is an opaque structure with no user-visible
* elements.
*/
struct psock {
struct psock
{
struct pt pt, psockpt; /* Protothreads - one that's using the psock
functions, and one that runs inside the
psock functions. */

View File

@ -51,7 +51,8 @@
#include "lc.h"
struct pt {
struct pt
{
lc_t lc;
};

View File

@ -69,7 +69,8 @@ static struct uip_fw_netif *netifs = NULL;
*/
static struct uip_fw_netif *defaultnetif = NULL;
struct tcpip_hdr {
struct tcpip_hdr
{
/* IP header. */
u8_t vhl,
tos;
@ -95,7 +96,8 @@ struct tcpip_hdr {
u8_t optdata[4];
};
struct icmpip_hdr {
struct icmpip_hdr
{
/* IP header. */
u8_t vhl,
tos,
@ -134,7 +136,8 @@ struct icmpip_hdr {
* Certain fields of an IP packet that are used for identifying
* duplicate packets.
*/
struct fwcache_entry {
struct fwcache_entry
{
u16_t timer;
u16_t srcipaddr[2];
@ -184,7 +187,8 @@ uip_fw_init(void)
{
struct uip_fw_netif *t;
defaultnetif = NULL;
while(netifs != NULL) {
while (netifs != NULL)
{
t = netifs;
netifs = netifs->next;
t->next = NULL;
@ -224,7 +228,8 @@ time_exceeded(void)
u16_t tmp16;
/* We don't send out ICMP errors for ICMP messages. */
if(ICMPBUF->proto == UIP_PROTO_ICMP) {
if (ICMPBUF->proto == UIP_PROTO_ICMP)
{
uip_len = 0;
return;
}
@ -288,11 +293,15 @@ fwcache_register(void)
fw = NULL;
/* Find the oldest entry in the cache. */
for(i = 0; i < FWCACHE_SIZE; ++i) {
if(fwcache[i].timer == 0) {
for (i = 0; i < FWCACHE_SIZE; ++i)
{
if (fwcache[i].timer == 0)
{
fw = &fwcache[i];
break;
} else if(fwcache[i].timer <= oldest) {
}
else if (fwcache[i].timer <= oldest)
{
fw = &fwcache[i];
oldest = fwcache[i].timer;
}
@ -326,9 +335,11 @@ find_netif(void)
struct uip_fw_netif *netif;
/* Walk through every network interface to check for a match. */
for(netif = netifs; netif != NULL; netif = netif->next) {
for (netif = netifs; netif != NULL; netif = netif->next)
{
if (ipaddr_maskcmp(BUF->destipaddr, netif->ipaddr,
netif->netmask)) {
netif->netmask))
{
/* If there was a match, we break the loop. */
return netif;
}
@ -359,7 +370,8 @@ uip_fw_output(void)
{
struct uip_fw_netif *netif;
if(uip_len == 0) {
if (uip_len == 0)
{
return UIP_FW_ZEROLEN;
}
@ -369,11 +381,14 @@ uip_fw_output(void)
/* Link local broadcasts go out on all interfaces. */
if ( /*BUF->proto == UIP_PROTO_UDP &&*/
BUF->destipaddr[0] == 0xffff &&
BUF->destipaddr[1] == 0xffff) {
if(defaultnetif != NULL) {
BUF->destipaddr[1] == 0xffff)
{
if (defaultnetif != NULL)
{
defaultnetif->output();
}
for(netif = netifs; netif != NULL; netif = netif->next) {
for (netif = netifs; netif != NULL; netif = netif->next)
{
netif->output();
}
return UIP_FW_OK;
@ -385,7 +400,8 @@ uip_fw_output(void)
netif->output,
uip_len);*/
if(netif == NULL) {
if (netif == NULL)
{
return UIP_FW_NOROUTE;
}
/* If we now have found a suitable network interface, we call its
@ -410,7 +426,8 @@ uip_fw_forward(void)
/* First check if the packet is destined for ourselves and return 0
to indicate that the packet should be processed locally. */
if (BUF->destipaddr[0] == uip_hostaddr[0] &&
BUF->destipaddr[1] == uip_hostaddr[1]) {
BUF->destipaddr[1] == uip_hostaddr[1])
{
return UIP_FW_LOCAL;
}
@ -419,7 +436,8 @@ uip_fw_forward(void)
#if UIP_PINGADDRCONF
if ((uip_hostaddr[0] | uip_hostaddr[1]) == 0 &&
BUF->proto == UIP_PROTO_ICMP &&
ICMPBUF->type == ICMP_ECHO) {
ICMPBUF->type == ICMP_ECHO)
{
return UIP_FW_LOCAL;
}
#endif /* UIP_PINGADDRCONF */
@ -427,7 +445,8 @@ uip_fw_forward(void)
/* Check if the packet is in the forwarding cache already, and if so
we drop it. */
for(fw = fwcache; fw < &fwcache[FWCACHE_SIZE]; ++fw) {
for (fw = fwcache; fw < &fwcache[FWCACHE_SIZE]; ++fw)
{
if (fw->timer != 0 &&
#if UIP_REASSEMBLY > 0
fw->len == BUF->len &&
@ -442,7 +461,8 @@ uip_fw_forward(void)
fw->payload[0] == BUF->srcport &&
fw->payload[1] == BUF->destport &&
#endif
fw->proto == BUF->proto) {
fw->proto == BUF->proto)
{
/* Drop packet. */
return UIP_FW_FORWARDED;
}
@ -451,9 +471,11 @@ uip_fw_forward(void)
/* If the TTL reaches zero we produce an ICMP time exceeded message
in the uip_buf buffer and forward that packet back to the sender
of the packet. */
if(BUF->ttl <= 1) {
if (BUF->ttl <= 1)
{
/* No time exceeded for broadcasts and multicasts! */
if(BUF->destipaddr[0] == 0xffff && BUF->destipaddr[1] == 0xffff) {
if (BUF->destipaddr[0] == 0xffff && BUF->destipaddr[1] == 0xffff)
{
return UIP_FW_LOCAL;
}
time_exceeded();
@ -463,19 +485,24 @@ uip_fw_forward(void)
BUF->ttl = BUF->ttl - 1;
/* Update the IP checksum. */
if(BUF->ipchksum >= HTONS(0xffff - 0x0100)) {
if (BUF->ipchksum >= HTONS(0xffff - 0x0100))
{
BUF->ipchksum = BUF->ipchksum + HTONS(0x0100) + 1;
} else {
}
else
{
BUF->ipchksum = BUF->ipchksum + HTONS(0x0100);
}
if(uip_len > 0) {
if (uip_len > 0)
{
uip_appdata = &uip_buf[UIP_LLH_LEN + UIP_TCPIP_HLEN];
uip_fw_output();
}
#if UIP_BROADCAST
if(BUF->destipaddr[0] == 0xffff && BUF->destipaddr[1] == 0xffff) {
if (BUF->destipaddr[0] == 0xffff && BUF->destipaddr[1] == 0xffff)
{
return UIP_FW_LOCAL;
}
#endif /* UIP_BROADCAST */
@ -523,8 +550,10 @@ void
uip_fw_periodic(void)
{
struct fwcache_entry *fw;
for(fw = fwcache; fw < &fwcache[FWCACHE_SIZE]; ++fw) {
if(fw->timer > 0) {
for (fw = fwcache; fw < &fwcache[FWCACHE_SIZE]; ++fw)
{
if (fw->timer > 0)
{
--fw->timer;
}
}

View File

@ -51,7 +51,8 @@
/**
* Representation of a uIP network interface.
*/
struct uip_fw_netif {
struct uip_fw_netif
{
struct uip_fw_netif *next; /**< Pointer to the next interface when
linked in a list. */
u16_t ipaddr[2]; /**< The IP address of this interface. */

View File

@ -51,7 +51,8 @@
#define ENTRIES 8
#endif /* UIP_NEIGHBOR_CONF_ENTRIES */
struct neighbor_entry {
struct neighbor_entry
{
uip_ipaddr_t ipaddr;
struct uip_neighbor_addr addr;
u8_t time;
@ -64,7 +65,8 @@ uip_neighbor_init(void)
{
int i;
for(i = 0; i < ENTRIES; ++i) {
for (i = 0; i < ENTRIES; ++i)
{
entries[i].time = MAX_TIME;
}
}
@ -74,8 +76,10 @@ uip_neighbor_periodic(void)
{
int i;
for(i = 0; i < ENTRIES; ++i) {
if(entries[i].time < MAX_TIME) {
for (i = 0; i < ENTRIES; ++i)
{
if (entries[i].time < MAX_TIME)
{
entries[i].time++;
}
}
@ -94,16 +98,20 @@ uip_neighbor_add(uip_ipaddr_t ipaddr, struct uip_neighbor_addr *addr)
/* Find the first unused entry or the oldest used entry. */
oldest_time = 0;
oldest = 0;
for(i = 0; i < ENTRIES; ++i) {
if(entries[i].time == MAX_TIME) {
for (i = 0; i < ENTRIES; ++i)
{
if (entries[i].time == MAX_TIME)
{
oldest = i;
break;
}
if(uip_ipaddr_cmp(entries[i].ipaddr, addr)) {
if (uip_ipaddr_cmp(entries[i].ipaddr, addr))
{
oldest = i;
break;
}
if(entries[i].time > oldest_time) {
if (entries[i].time > oldest_time)
{
oldest = i;
oldest_time = entries[i].time;
}
@ -121,8 +129,10 @@ find_entry(uip_ipaddr_t ipaddr)
{
int i;
for(i = 0; i < ENTRIES; ++i) {
if(uip_ipaddr_cmp(entries[i].ipaddr, ipaddr)) {
for (i = 0; i < ENTRIES; ++i)
{
if (uip_ipaddr_cmp(entries[i].ipaddr, ipaddr))
{
return &entries[i];
}
}
@ -135,7 +145,8 @@ uip_neighbor_update(uip_ipaddr_t ipaddr)
struct neighbor_entry *e;
e = find_entry(ipaddr);
if(e != NULL) {
if (e != NULL)
{
e->time = 0;
}
}
@ -146,7 +157,8 @@ uip_neighbor_lookup(uip_ipaddr_t ipaddr)
struct neighbor_entry *e;
e = find_entry(ipaddr);
if(e != NULL) {
if (e != NULL)
{
/* printf("Lookup neighbor with link address %02x:%02x:%02x:%02x:%02x:%02x\n",
e->addr.addr.addr[0], e->addr.addr.addr[1], e->addr.addr.addr[2], e->addr.addr.addr[3],
e->addr.addr.addr[4], e->addr.addr.addr[5]);*/

View File

@ -44,7 +44,8 @@
#include "uip.h"
struct uip_neighbor_addr {
struct uip_neighbor_addr
{
#if UIP_NEIGHBOR_CONF_ADDRTYPE
UIP_NEIGHBOR_CONF_ADDRTYPE addr;
#else

View File

@ -52,13 +52,15 @@ uip_split_output(void)
/* We only try to split maximum sized TCP segments. */
if (BUF->proto == UIP_PROTO_TCP &&
uip_len == UIP_BUFSIZE - UIP_LLH_LEN) {
uip_len == UIP_BUFSIZE - UIP_LLH_LEN)
{
tcplen = uip_len - UIP_TCPIP_HLEN;
/* Split the segment in two. If the original packet length was
odd, we make the second packet one byte larger. */
len1 = len2 = tcplen / 2;
if(len1 + len2 < tcplen) {
if (len1 + len2 < tcplen)
{
++len2;
}
@ -127,7 +129,9 @@ uip_split_output(void)
/* Transmit the second packet. */
/* uip_fw_output();*/
tcpip_output();
} else {
}
else
{
/* uip_fw_output();*/
tcpip_output();
}

File diff suppressed because it is too large Load Diff

View File

@ -1155,7 +1155,8 @@ extern u16_t uip_urglen, uip_surglen;
* file pointers) for the connection. The type of this field is
* configured in the "uipopt.h" header file.
*/
struct uip_conn {
struct uip_conn
{
uip_ipaddr_t ripaddr; /**< The IP address of the remote host. */
u16_t lport; /**< The local TCP port, in network byte order. */
@ -1215,7 +1216,8 @@ extern u8_t uip_acc32[4];
/**
* Representation of a uIP UDP connection.
*/
struct uip_udp_conn {
struct uip_udp_conn
{
uip_ipaddr_t ripaddr; /**< The IP address of the remote peer. */
u16_t lport; /**< The local port number in network byte order. */
u16_t rport; /**< The remote port number in network byte order. */
@ -1237,8 +1239,10 @@ extern struct uip_udp_conn uip_udp_conns[UIP_UDP_CONNS];
* UIP_STATISTICS is set to 1.
*
*/
struct uip_stats {
struct {
struct uip_stats
{
struct
{
uip_stats_t drop; /**< Number of dropped packets at the IP
layer. */
uip_stats_t recv; /**< Number of received packets at the IP
@ -1258,7 +1262,8 @@ struct uip_stats {
uip_stats_t protoerr; /**< Number of packets dropped since they
were neither ICMP, UDP nor TCP. */
} ip; /**< IP statistics. */
struct {
struct
{
uip_stats_t drop; /**< Number of dropped ICMP packets. */
uip_stats_t recv; /**< Number of received ICMP packets. */
uip_stats_t sent; /**< Number of sent ICMP packets. */
@ -1266,7 +1271,8 @@ struct uip_stats {
type. */
} icmp; /**< ICMP statistics. */
#if UIP_TCP
struct {
struct
{
uip_stats_t drop; /**< Number of dropped TCP segments. */
uip_stats_t recv; /**< Number of recived TCP segments. */
uip_stats_t sent; /**< Number of sent TCP segments. */
@ -1283,7 +1289,8 @@ struct uip_stats {
} tcp; /**< TCP statistics. */
#endif /* UIP_TCP */
#if UIP_UDP
struct {
struct
{
uip_stats_t drop; /**< Number of dropped UDP segments. */
uip_stats_t recv; /**< Number of recived UDP segments. */
uip_stats_t sent; /**< Number of sent UDP segments. */
@ -1393,7 +1400,8 @@ void uip_process(u8_t flag);
#define UIP_STOPPED 16
/* The TCP and IP headers. */
struct uip_tcpip_hdr {
struct uip_tcpip_hdr
{
#if UIP_CONF_IPV6
/* IPv6 header. */
u8_t vtc,
@ -1430,7 +1438,8 @@ struct uip_tcpip_hdr {
};
/* The ICMP and IP headers. */
struct uip_icmpip_hdr {
struct uip_icmpip_hdr
{
#if UIP_CONF_IPV6
/* IPv6 header. */
u8_t vtc,
@ -1467,7 +1476,8 @@ struct uip_icmpip_hdr {
/* The UDP and IP headers. */
struct uip_udpip_hdr {
struct uip_udpip_hdr
{
#if UIP_CONF_IPV6
/* IPv6 header. */
u8_t vtc,
@ -1549,7 +1559,8 @@ extern uip_ipaddr_t uip_hostaddr, uip_netmask, uip_draddr;
/**
* Representation of a 48-bit Ethernet address.
*/
struct uip_eth_addr {
struct uip_eth_addr
{
u8_t addr[6];
};

View File

@ -63,7 +63,8 @@
#include <string.h>
struct arp_hdr {
struct arp_hdr
{
struct uip_eth_hdr ethhdr;
u16_t hwtype;
u16_t protocol;
@ -76,7 +77,8 @@ struct arp_hdr {
u16_t dipaddr[2];
};
struct ethip_hdr {
struct ethip_hdr
{
struct uip_eth_hdr ethhdr;
/* IP header. */
u8_t vhl,
@ -96,7 +98,8 @@ struct ethip_hdr {
#define ARP_HWTYPE_ETH 1
struct arp_entry {
struct arp_entry
{
u16_t ipaddr[2];
struct uip_eth_addr ethaddr;
u8_t time;
@ -124,7 +127,8 @@ static u8_t tmpage;
void
uip_arp_init(void)
{
for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
for (i = 0; i < UIP_ARPTAB_SIZE; ++i)
{
memset(arp_table[i].ipaddr, 0, 4);
}
}
@ -144,10 +148,12 @@ uip_arp_timer(void)
struct arp_entry *tabptr;
++arptime;
for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
for (i = 0; i < UIP_ARPTAB_SIZE; ++i)
{
tabptr = &arp_table[i];
if ((tabptr->ipaddr[0] | tabptr->ipaddr[1]) != 0 &&
arptime - tabptr->time >= UIP_ARP_MAXAGE) {
arptime - tabptr->time >= UIP_ARP_MAXAGE)
{
memset(tabptr->ipaddr, 0, 4);
}
}
@ -161,17 +167,20 @@ uip_arp_update(u16_t *ipaddr, struct uip_eth_addr *ethaddr)
/* Walk through the ARP mapping table and try to find an entry to
update. If none is found, the IP -> MAC address mapping is
inserted in the ARP table. */
for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
for (i = 0; i < UIP_ARPTAB_SIZE; ++i)
{
tabptr = &arp_table[i];
/* Only check those entries that are actually in use. */
if (tabptr->ipaddr[0] != 0 &&
tabptr->ipaddr[1] != 0) {
tabptr->ipaddr[1] != 0)
{
/* Check if the source IP address of the incoming packet matches
the IP address in this ARP table entry. */
if (ipaddr[0] == tabptr->ipaddr[0] &&
ipaddr[1] == tabptr->ipaddr[1]) {
ipaddr[1] == tabptr->ipaddr[1])
{
/* An old entry found, update this and return. */
memcpy(tabptr->ethaddr.addr, ethaddr->addr, 6);
@ -186,22 +195,27 @@ uip_arp_update(u16_t *ipaddr, struct uip_eth_addr *ethaddr)
create one. */
/* First, we try to find an unused entry in the ARP table. */
for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
for (i = 0; i < UIP_ARPTAB_SIZE; ++i)
{
tabptr = &arp_table[i];
if (tabptr->ipaddr[0] == 0 &&
tabptr->ipaddr[1] == 0) {
tabptr->ipaddr[1] == 0)
{
break;
}
}
/* If no unused entry is found, we try to find the oldest entry and
throw it away. */
if(i == UIP_ARPTAB_SIZE) {
if (i == UIP_ARPTAB_SIZE)
{
tmpage = 0;
c = 0;
for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
for (i = 0; i < UIP_ARPTAB_SIZE; ++i)
{
tabptr = &arp_table[i];
if(arptime - tabptr->time > tmpage) {
if (arptime - tabptr->time > tmpage)
{
tmpage = arptime - tabptr->time;
c = i;
}
@ -239,11 +253,13 @@ uip_arp_ipin(void)
/* Only insert/update an entry if the source IP address of the
incoming IP packet comes from a host on the local network. */
if ((IPBUF->srcipaddr[0] & uip_netmask[0]) !=
(uip_hostaddr[0] & uip_netmask[0])) {
(uip_hostaddr[0] & uip_netmask[0]))
{
return;
}
if ((IPBUF->srcipaddr[1] & uip_netmask[1]) !=
(uip_hostaddr[1] & uip_netmask[1])) {
(uip_hostaddr[1] & uip_netmask[1]))
{
return;
}
uip_arp_update(IPBUF->srcipaddr, &(IPBUF->ethhdr.src));
@ -278,17 +294,20 @@ void
uip_arp_arpin(void)
{
if(uip_len < sizeof(struct arp_hdr)) {
if (uip_len < sizeof(struct arp_hdr))
{
uip_len = 0;
return;
}
uip_len = 0;
switch(BUF->opcode) {
switch (BUF->opcode)
{
case HTONS(ARP_REQUEST):
/* ARP request. If it asked for our address, we send out a
reply. */
if(uip_ipaddr_cmp(BUF->dipaddr, uip_hostaddr)) {
if (uip_ipaddr_cmp(BUF->dipaddr, uip_hostaddr))
{
/* First, we register the one who made the request in our ARP
table, since it is likely that we will do more communication
with this host in the future. */
@ -314,7 +333,8 @@ uip_arp_arpin(void)
case HTONS(ARP_REPLY):
/* ARP reply. We insert or update the ARP table if it was meant
for us. */
if(uip_ipaddr_cmp(BUF->dipaddr, uip_hostaddr)) {
if (uip_ipaddr_cmp(BUF->dipaddr, uip_hostaddr))
{
uip_arp_update(BUF->sipaddr, &BUF->shwaddr);
}
break;
@ -363,28 +383,37 @@ uip_arp_out(void)
packet with an ARP request for the IP address. */
/* First check if destination is a local broadcast. */
if(uip_ipaddr_cmp(IPBUF->destipaddr, broadcast_ipaddr)) {
if (uip_ipaddr_cmp(IPBUF->destipaddr, broadcast_ipaddr))
{
memcpy(IPBUF->ethhdr.dest.addr, broadcast_ethaddr.addr, 6);
} else {
}
else
{
/* Check if the destination address is on the local network. */
if(!uip_ipaddr_maskcmp(IPBUF->destipaddr, uip_hostaddr, uip_netmask)) {
if (!uip_ipaddr_maskcmp(IPBUF->destipaddr, uip_hostaddr, uip_netmask))
{
/* Destination address was not on the local network, so we need to
use the default router's IP address instead of the destination
address when determining the MAC address. */
uip_ipaddr_copy(ipaddr, uip_draddr);
} else {
}
else
{
/* Else, we use the destination IP address. */
uip_ipaddr_copy(ipaddr, IPBUF->destipaddr);
}
for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
for (i = 0; i < UIP_ARPTAB_SIZE; ++i)
{
tabptr = &arp_table[i];
if(uip_ipaddr_cmp(ipaddr, tabptr->ipaddr)) {
if (uip_ipaddr_cmp(ipaddr, tabptr->ipaddr))
{
break;
}
}
if(i == UIP_ARPTAB_SIZE) {
if (i == UIP_ARPTAB_SIZE)
{
/* The destination address was not in our ARP table, so we
overwrite the IP packet with an ARP request. */

View File

@ -60,7 +60,8 @@ extern struct uip_eth_addr uip_ethaddr;
/**
* The Ethernet header.
*/
struct uip_eth_hdr {
struct uip_eth_hdr
{
struct uip_eth_addr dest;
struct uip_eth_addr src;
u16_t type;

View File

@ -71,7 +71,8 @@
*
* \hideinitializer
*/
struct timer {
struct timer
{
clock_time_t start;
clock_time_t interval;
};

View File

@ -48,25 +48,34 @@ uiplib_ipaddrconv(char *addrstr, unsigned char *ipaddr)
tmp = 0;
for(i = 0; i < 4; ++i) {
for (i = 0; i < 4; ++i)
{
j = 0;
do {
do
{
c = *addrstr;
++j;
if(j > 4) {
if (j > 4)
{
return 0;
}
if(c == '.' || c == 0) {
if (c == '.' || c == 0)
{
*ipaddr = tmp;
++ipaddr;
tmp = 0;
} else if(c >= '0' && c <= '9') {
}
else if (c >= '0' && c <= '9')
{
tmp = (tmp * 10) + (c - '0');
} else {
}
else
{
return 0;
}
++addrstr;
} while(c != '.' && c != 0);
}
while (c != '.' && c != 0);
}
return 1;
}

View File

@ -95,49 +95,62 @@ main(void)
while(1) {
while (1)
{
uip_len = tapdev_read();
if(uip_len > 0) {
if(BUF->type == htons(UIP_ETHTYPE_IP)) {
if (uip_len > 0)
{
if (BUF->type == htons(UIP_ETHTYPE_IP))
{
uip_arp_ipin();
uip_input();
/* If the above function invocation resulted in data that
should be sent out on the network, the global variable
uip_len is set to a value > 0. */
if(uip_len > 0) {
if (uip_len > 0)
{
uip_arp_out();
tapdev_send();
}
} else if(BUF->type == htons(UIP_ETHTYPE_ARP)) {
}
else if (BUF->type == htons(UIP_ETHTYPE_ARP))
{
uip_arp_arpin();
/* If the above function invocation resulted in data that
should be sent out on the network, the global variable
uip_len is set to a value > 0. */
if(uip_len > 0) {
if (uip_len > 0)
{
tapdev_send();
}
}
} else if(timer_expired(&periodic_timer)) {
}
else if (timer_expired(&periodic_timer))
{
timer_reset(&periodic_timer);
for(i = 0; i < UIP_CONNS; i++) {
for (i = 0; i < UIP_CONNS; i++)
{
uip_periodic(i);
/* If the above function invocation resulted in data that
should be sent out on the network, the global variable
uip_len is set to a value > 0. */
if(uip_len > 0) {
if (uip_len > 0)
{
uip_arp_out();
tapdev_send();
}
}
#if UIP_UDP
for(i = 0; i < UIP_UDP_CONNS; i++) {
for (i = 0; i < UIP_UDP_CONNS; i++)
{
uip_udp_periodic(i);
/* If the above function invocation resulted in data that
should be sent out on the network, the global variable
uip_len is set to a value > 0. */
if(uip_len > 0) {
if (uip_len > 0)
{
uip_arp_out();
tapdev_send();
}
@ -145,7 +158,8 @@ main(void)
#endif /* UIP_UDP */
/* Call the ARP timer function every 10 seconds. */
if(timer_expired(&arp_timer)) {
if (timer_expired(&arp_timer))
{
timer_reset(&arp_timer);
uip_arp_timer();
}
@ -164,9 +178,12 @@ resolv_found(char *name, u16_t *ipaddr)
{
u16_t *ipaddr2;
if(ipaddr == NULL) {
if (ipaddr == NULL)
{
printf("Host '%s' not found.\n", name);
} else {
}
else
{
printf("Found name '%s' = %d.%d.%d.%d\n", name,
htons(ipaddr[0]) >> 8,
htons(ipaddr[0]) & 0xff,

View File

@ -73,7 +73,8 @@ tapdev_init(void)
char buf[1024];
fd = open(DEVTAP, O_RDWR);
if(fd == -1) {
if (fd == -1)
{
perror("tapdev: tapdev_init: open");
exit(1);
}
@ -83,7 +84,8 @@ tapdev_init(void)
struct ifreq ifr;
memset(&ifr, 0, sizeof(ifr));
ifr.ifr_flags = IFF_TAP|IFF_NO_PI;
if (ioctl(fd, TUNSETIFF, (void *) &ifr) < 0) {
if (ioctl(fd, TUNSETIFF, (void *) &ifr) < 0)
{
perror(buf);
exit(1);
}
@ -111,11 +113,13 @@ tapdev_read(void)
FD_SET(fd, &fdset);
ret = select(fd + 1, &fdset, NULL, NULL, &tv);
if(ret == 0) {
if (ret == 0)
{
return 0;
}
ret = read(fd, uip_buf, UIP_BUFSIZE);
if(ret == -1) {
if (ret == -1)
{
perror("tap_dev: tapdev_read: read");
}
@ -144,7 +148,8 @@ tapdev_send(void)
return;
}*/
ret = write(fd, uip_buf, uip_len);
if(ret == -1) {
if (ret == -1)
{
perror("tap_dev: tapdev_send: writev");
exit(1);
}