mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-06 05:21:22 +03:00
Merge remote-tracking branch 'esp8266/master'
This commit is contained in:
commit
9d6f55e321
3
.gitignore
vendored
3
.gitignore
vendored
@ -5,3 +5,6 @@ tools/esptool/
|
||||
tools/mkspiffs/
|
||||
package/versions/
|
||||
exclude.txt
|
||||
tools/sdk/lib/liblwip_src.a
|
||||
tools/sdk/lwip/src/build
|
||||
tools/sdk/lwip/src/liblwip_src.a
|
||||
|
261
boards.txt
261
boards.txt
@ -7,6 +7,7 @@ menu.ResetMethod=Reset Method
|
||||
menu.ESPModule=Module
|
||||
menu.Debug=Debug port
|
||||
menu.DebugLevel=Debug Level
|
||||
menu.LwIPVariant=lwIP Variant
|
||||
|
||||
##############################################################
|
||||
generic.name=Generic ESP8266 Module
|
||||
@ -29,6 +30,8 @@ generic.build.flash_mode=qio
|
||||
generic.build.spiffs_pagesize=256
|
||||
generic.build.debug_port=
|
||||
generic.build.debug_level=
|
||||
generic.build.lwip_lib=-llwip
|
||||
generic.build.lwip_flags=
|
||||
|
||||
generic.menu.CpuFrequency.80=80 MHz
|
||||
generic.menu.CpuFrequency.80.build.f_cpu=80000000L
|
||||
@ -247,6 +250,8 @@ espduino.build.flash_size=4M
|
||||
espduino.build.flash_freq=40
|
||||
espduino.build.debug_port=
|
||||
espduino.build.debug_level=
|
||||
espduino.build.lwip_lib=-llwip
|
||||
espduino.build.lwip_flags=
|
||||
|
||||
espduino.menu.CpuFrequency.80=80 MHz
|
||||
espduino.menu.CpuFrequency.80.build.f_cpu=80000000L
|
||||
@ -310,6 +315,8 @@ huzzah.build.flash_size=4M
|
||||
huzzah.build.flash_freq=40
|
||||
huzzah.build.debug_port=
|
||||
huzzah.build.debug_level=
|
||||
huzzah.build.lwip_lib=-llwip
|
||||
huzzah.build.lwip_flags=
|
||||
|
||||
huzzah.menu.CpuFrequency.80=80 MHz
|
||||
huzzah.menu.CpuFrequency.80.build.f_cpu=80000000L
|
||||
@ -359,6 +366,8 @@ espresso_lite_v1.build.variant=espresso_lite_v1
|
||||
espresso_lite_v1.build.flash_mode=dio
|
||||
espresso_lite_v1.build.flash_size=4M
|
||||
espresso_lite_v1.build.flash_freq=40
|
||||
espresso_lite_v1.build.lwip_lib=-llwip
|
||||
espresso_lite_v1.build.lwip_flags=
|
||||
|
||||
espresso_lite_v1.menu.CpuFrequency.80=80 MHz
|
||||
espresso_lite_v1.menu.CpuFrequency.80.build.f_cpu=80000000L
|
||||
@ -464,6 +473,8 @@ espresso_lite_v2.build.variant=espresso_lite_v2
|
||||
espresso_lite_v2.build.flash_mode=dio
|
||||
espresso_lite_v2.build.flash_size=4M
|
||||
espresso_lite_v2.build.flash_freq=40
|
||||
espresso_lite_v2.build.lwip_lib=-llwip
|
||||
espresso_lite_v2.build.lwip_flags=
|
||||
|
||||
espresso_lite_v2.menu.CpuFrequency.80=80 MHz
|
||||
espresso_lite_v2.menu.CpuFrequency.80.build.f_cpu=80000000L
|
||||
@ -567,7 +578,7 @@ nodemcu.serial.disableRTS=true
|
||||
|
||||
nodemcu.build.mcu=esp8266
|
||||
nodemcu.build.f_cpu=80000000L
|
||||
nodemcu.build.board=ESP8266_ESP12
|
||||
nodemcu.build.board=ESP8266_NODEMCU
|
||||
nodemcu.build.core=esp8266
|
||||
nodemcu.build.variant=nodemcu
|
||||
nodemcu.build.flash_mode=qio
|
||||
@ -575,6 +586,8 @@ nodemcu.build.flash_size=4M
|
||||
nodemcu.build.flash_freq=40
|
||||
nodemcu.build.debug_port=
|
||||
nodemcu.build.debug_level=
|
||||
nodemcu.build.lwip_lib=-llwip
|
||||
nodemcu.build.lwip_flags=
|
||||
|
||||
nodemcu.menu.CpuFrequency.80=80 MHz
|
||||
nodemcu.menu.CpuFrequency.80.build.f_cpu=80000000L
|
||||
@ -631,7 +644,7 @@ nodemcuv2.serial.disableRTS=true
|
||||
|
||||
nodemcuv2.build.mcu=esp8266
|
||||
nodemcuv2.build.f_cpu=80000000L
|
||||
nodemcuv2.build.board=ESP8266_ESP12
|
||||
nodemcuv2.build.board=ESP8266_NODEMCU
|
||||
nodemcuv2.build.core=esp8266
|
||||
nodemcuv2.build.variant=nodemcu
|
||||
nodemcuv2.build.flash_mode=dio
|
||||
@ -639,6 +652,8 @@ nodemcuv2.build.flash_size=4M
|
||||
nodemcuv2.build.flash_freq=40
|
||||
nodemcuv2.build.debug_port=
|
||||
nodemcuv2.build.debug_level=
|
||||
nodemcuv2.build.lwip_lib=-llwip
|
||||
nodemcuv2.build.lwip_flags=
|
||||
|
||||
nodemcuv2.menu.CpuFrequency.80=80 MHz
|
||||
nodemcuv2.menu.CpuFrequency.80.build.f_cpu=80000000L
|
||||
@ -710,6 +725,8 @@ modwifi.build.spiffs_pagesize=256
|
||||
modwifi.build.spiffs_blocksize=8192
|
||||
modwifi.build.debug_port=
|
||||
modwifi.build.debug_level=
|
||||
modwifi.build.lwip_lib=-llwip
|
||||
modwifi.build.lwip_flags=
|
||||
|
||||
modwifi.menu.CpuFrequency.80=80 MHz
|
||||
modwifi.menu.CpuFrequency.80.build.f_cpu=80000000L
|
||||
@ -764,6 +781,8 @@ thing.build.spiffs_blocksize=4096
|
||||
thing.build.spiffs_pagesize=256
|
||||
thing.build.debug_port=
|
||||
thing.build.debug_level=
|
||||
thing.build.lwip_lib=-llwip
|
||||
thing.build.lwip_flags=
|
||||
|
||||
thing.menu.CpuFrequency.80=80 MHz
|
||||
thing.menu.CpuFrequency.80.build.f_cpu=80000000L
|
||||
@ -813,6 +832,8 @@ thingdev.build.flash_ld=eagle.flash.512k64.ld
|
||||
thingdev.build.flash_freq=40
|
||||
thingdev.build.debug_port=
|
||||
thingdev.build.debug_level=
|
||||
thingdev.build.lwip_lib=-llwip
|
||||
thingdev.build.lwip_flags=
|
||||
|
||||
thingdev.menu.CpuFrequency.80=80 MHz
|
||||
thingdev.menu.CpuFrequency.80.build.f_cpu=80000000L
|
||||
@ -860,6 +881,8 @@ esp210.build.flash_size=4M
|
||||
esp210.build.flash_freq=40
|
||||
esp210.build.debug_port=
|
||||
esp210.build.debug_level=
|
||||
esp210.build.lwip_lib=-llwip
|
||||
esp210.build.lwip_flags=
|
||||
|
||||
esp210.menu.CpuFrequency.80=80 MHz
|
||||
esp210.menu.CpuFrequency.80.build.f_cpu=80000000L
|
||||
@ -943,7 +966,7 @@ d1_mini.serial.disableRTS=true
|
||||
|
||||
d1_mini.build.mcu=esp8266
|
||||
d1_mini.build.f_cpu=80000000L
|
||||
d1_mini.build.board=ESP8266_ESP12
|
||||
d1_mini.build.board=ESP8266_NODEMCU
|
||||
d1_mini.build.core=esp8266
|
||||
d1_mini.build.variant=d1_mini
|
||||
d1_mini.build.flash_mode=dio
|
||||
@ -951,6 +974,8 @@ d1_mini.build.flash_size=4M
|
||||
d1_mini.build.flash_freq=40
|
||||
d1_mini.build.debug_port=
|
||||
d1_mini.build.debug_level=
|
||||
d1_mini.build.lwip_lib=-llwip
|
||||
d1_mini.build.lwip_flags=
|
||||
|
||||
d1_mini.menu.CpuFrequency.80=80 MHz
|
||||
d1_mini.menu.CpuFrequency.80.build.f_cpu=80000000L
|
||||
@ -1009,7 +1034,7 @@ d1.serial.disableRTS=true
|
||||
|
||||
d1.build.mcu=esp8266
|
||||
d1.build.f_cpu=80000000L
|
||||
d1.build.board=ESP8266_ESP12
|
||||
d1.build.board=ESP8266_NODEMCU
|
||||
d1.build.core=esp8266
|
||||
d1.build.variant=d1
|
||||
d1.build.flash_mode=dio
|
||||
@ -1017,6 +1042,8 @@ d1.build.flash_size=4M
|
||||
d1.build.flash_freq=40
|
||||
d1.build.debug_port=
|
||||
d1.build.debug_level=
|
||||
d1.build.lwip_lib=-llwip
|
||||
d1.build.lwip_flags=
|
||||
|
||||
d1.menu.CpuFrequency.80=80 MHz
|
||||
d1.menu.CpuFrequency.80.build.f_cpu=80000000L
|
||||
@ -1085,6 +1112,8 @@ espino.build.flash_freq=40
|
||||
espino.build.spiffs_pagesize=256
|
||||
espino.build.debug_port=
|
||||
espino.build.debug_level=
|
||||
espino.build.lwip_lib=-llwip
|
||||
espino.build.lwip_flags=
|
||||
|
||||
espino.menu.CpuFrequency.80=80 MHz
|
||||
espino.menu.CpuFrequency.80.build.f_cpu=80000000L
|
||||
@ -1159,6 +1188,8 @@ espinotee.build.flash_size=4M
|
||||
espinotee.build.flash_freq=40
|
||||
espinotee.build.debug_port=
|
||||
espinotee.build.debug_level=
|
||||
espinotee.build.lwip_lib=-llwip
|
||||
espinotee.build.lwip_flags=
|
||||
|
||||
espinotee.menu.CpuFrequency.80=80 MHz
|
||||
espinotee.menu.CpuFrequency.80.build.f_cpu=80000000L
|
||||
@ -1218,10 +1249,12 @@ wifinfo.build.f_cpu=160000000L
|
||||
wifinfo.build.core=esp8266
|
||||
wifinfo.build.variant=wifinfo
|
||||
wifinfo.build.flash_mode=qio
|
||||
wifinfo.build.board=ESP8266_ESP12
|
||||
wifinfo.build.board=ESP8266_NODEMCU
|
||||
wifinfo.build.spiffs_pagesize=256
|
||||
wifinfo.build.debug_port=Serial1
|
||||
wifinfo.build.debug_level=Wifinfo
|
||||
wifinfo.build.lwip_lib=-llwip
|
||||
wifinfo.build.lwip_flags=
|
||||
|
||||
wifinfo.menu.Debug.Disabled=Disabled
|
||||
wifinfo.menu.Debug.Disabled.build.debug_port=
|
||||
@ -1332,3 +1365,221 @@ wifinfo.menu.UploadSpeed.512000.windows=512000
|
||||
wifinfo.menu.UploadSpeed.512000.upload.speed=512000
|
||||
wifinfo.menu.UploadSpeed.921600=921600
|
||||
wifinfo.menu.UploadSpeed.921600.upload.speed=921600
|
||||
|
||||
|
||||
##############################################################
|
||||
coredev.name=Core Development Module
|
||||
|
||||
coredev.upload.tool=esptool
|
||||
coredev.upload.speed=115200
|
||||
coredev.upload.resetmethod=ck
|
||||
coredev.upload.maximum_size=434160
|
||||
coredev.upload.maximum_data_size=81920
|
||||
coredev.upload.wait_for_upload_port=true
|
||||
coredev.serial.disableDTR=true
|
||||
coredev.serial.disableRTS=true
|
||||
|
||||
coredev.build.mcu=esp8266
|
||||
coredev.build.f_cpu=80000000L
|
||||
coredev.build.board=ESP8266_ESP01
|
||||
coredev.build.core=esp8266
|
||||
coredev.build.variant=generic
|
||||
coredev.build.flash_mode=qio
|
||||
coredev.build.spiffs_pagesize=256
|
||||
coredev.build.debug_port=
|
||||
coredev.build.debug_level=
|
||||
coredev.build.lwip_lib=-llwip
|
||||
coredev.build.lwip_flags=
|
||||
|
||||
|
||||
coredev.menu.LwIPVariant.Espressif=Espressif (xcc)
|
||||
coredev.menu.LwIPVariant.Espressif.build.lwip_lib=-llwip
|
||||
coredev.menu.LwIPVariant.Espressif.build.lwip_flags=
|
||||
coredev.menu.LwIPVariant.Prebuilt=Prebuilt Source (gcc)
|
||||
coredev.menu.LwIPVariant.Prebuilt.build.lwip_lib=-llwip_gcc
|
||||
coredev.menu.LwIPVariant.Prebuilt.build.lwip_flags=-DLWIP_OPEN_SRC
|
||||
coredev.menu.LwIPVariant.OpenSource=Open Source (gcc)
|
||||
coredev.menu.LwIPVariant.OpenSource.build.lwip_lib=-llwip_src
|
||||
coredev.menu.LwIPVariant.OpenSource.build.lwip_flags=-DLWIP_OPEN_SRC
|
||||
coredev.menu.LwIPVariant.OpenSource.recipe.hooks.sketch.prebuild.1.pattern=make -C "{runtime.platform.path}/tools/sdk/lwip/src" install TOOLS_PATH="{runtime.tools.xtensa-lx106-elf-gcc.path}/bin/xtensa-lx106-elf-"
|
||||
|
||||
coredev.menu.CpuFrequency.80=80 MHz
|
||||
coredev.menu.CpuFrequency.80.build.f_cpu=80000000L
|
||||
coredev.menu.CpuFrequency.160=160 MHz
|
||||
coredev.menu.CpuFrequency.160.build.f_cpu=160000000L
|
||||
|
||||
coredev.menu.FlashFreq.40=40MHz
|
||||
coredev.menu.FlashFreq.40.build.flash_freq=40
|
||||
coredev.menu.FlashFreq.80=80MHz
|
||||
coredev.menu.FlashFreq.80.build.flash_freq=80
|
||||
|
||||
coredev.menu.FlashMode.dio=DIO
|
||||
coredev.menu.FlashMode.dio.build.flash_mode=dio
|
||||
coredev.menu.FlashMode.qio=QIO
|
||||
coredev.menu.FlashMode.qio.build.flash_mode=qio
|
||||
|
||||
coredev.menu.UploadSpeed.115200=115200
|
||||
coredev.menu.UploadSpeed.115200.upload.speed=115200
|
||||
coredev.menu.UploadSpeed.9600=9600
|
||||
coredev.menu.UploadSpeed.9600.upload.speed=9600
|
||||
coredev.menu.UploadSpeed.57600=57600
|
||||
coredev.menu.UploadSpeed.57600.upload.speed=57600
|
||||
coredev.menu.UploadSpeed.256000.windows=256000
|
||||
coredev.menu.UploadSpeed.256000.upload.speed=256000
|
||||
coredev.menu.UploadSpeed.230400.linux=230400
|
||||
coredev.menu.UploadSpeed.230400.macosx=230400
|
||||
coredev.menu.UploadSpeed.230400.upload.speed=230400
|
||||
coredev.menu.UploadSpeed.460800.linux=460800
|
||||
coredev.menu.UploadSpeed.460800.macosx=460800
|
||||
coredev.menu.UploadSpeed.460800.upload.speed=460800
|
||||
coredev.menu.UploadSpeed.512000.windows=512000
|
||||
coredev.menu.UploadSpeed.512000.upload.speed=512000
|
||||
coredev.menu.UploadSpeed.921600=921600
|
||||
coredev.menu.UploadSpeed.921600.upload.speed=921600
|
||||
|
||||
coredev.menu.FlashSize.512K64=512K (64K SPIFFS)
|
||||
coredev.menu.FlashSize.512K64.build.flash_size=512K
|
||||
coredev.menu.FlashSize.512K64.build.flash_ld=eagle.flash.512k64.ld
|
||||
coredev.menu.FlashSize.512K64.build.spiffs_start=0x6B000
|
||||
coredev.menu.FlashSize.512K64.build.spiffs_end=0x7B000
|
||||
coredev.menu.FlashSize.512K64.build.spiffs_blocksize=4096
|
||||
coredev.menu.FlashSize.512K64.upload.maximum_size=434160
|
||||
|
||||
coredev.menu.FlashSize.512K128=512K (128K SPIFFS)
|
||||
coredev.menu.FlashSize.512K128.build.flash_size=512K
|
||||
coredev.menu.FlashSize.512K128.build.flash_ld=eagle.flash.512k128.ld
|
||||
coredev.menu.FlashSize.512K128.build.spiffs_start=0x5B000
|
||||
coredev.menu.FlashSize.512K128.build.spiffs_end=0x7B000
|
||||
coredev.menu.FlashSize.512K128.build.spiffs_blocksize=4096
|
||||
coredev.menu.FlashSize.512K128.upload.maximum_size=368624
|
||||
|
||||
coredev.menu.FlashSize.512K0=512K (no SPIFFS)
|
||||
coredev.menu.FlashSize.512K0.build.flash_size=512K
|
||||
coredev.menu.FlashSize.512K0.build.flash_ld=eagle.flash.512k0.ld
|
||||
coredev.menu.FlashSize.512K0.upload.maximum_size=499696
|
||||
|
||||
coredev.menu.FlashSize.1M512=1M (512K SPIFFS)
|
||||
coredev.menu.FlashSize.1M512.build.flash_size=1M
|
||||
coredev.menu.FlashSize.1M512.build.flash_ld=eagle.flash.1m512.ld
|
||||
coredev.menu.FlashSize.1M512.build.spiffs_start=0x7B000
|
||||
coredev.menu.FlashSize.1M512.build.spiffs_end=0xFB000
|
||||
coredev.menu.FlashSize.1M512.build.spiffs_blocksize=8192
|
||||
coredev.menu.FlashSize.1M512.upload.maximum_size=499696
|
||||
|
||||
coredev.menu.FlashSize.1M256=1M (256K SPIFFS)
|
||||
coredev.menu.FlashSize.1M256.build.flash_size=1M
|
||||
coredev.menu.FlashSize.1M256.build.flash_ld=eagle.flash.1m256.ld
|
||||
coredev.menu.FlashSize.1M256.build.spiffs_start=0xBB000
|
||||
coredev.menu.FlashSize.1M256.build.spiffs_end=0xFB000
|
||||
coredev.menu.FlashSize.1M256.build.spiffs_blocksize=4096
|
||||
coredev.menu.FlashSize.1M256.upload.maximum_size=761840
|
||||
|
||||
coredev.menu.FlashSize.1M192=1M (192K SPIFFS)
|
||||
coredev.menu.FlashSize.1M192.build.flash_size=1M
|
||||
coredev.menu.FlashSize.1M192.build.flash_ld=eagle.flash.1m192.ld
|
||||
coredev.menu.FlashSize.1M192.build.spiffs_start=0xCB000
|
||||
coredev.menu.FlashSize.1M192.build.spiffs_end=0xFB000
|
||||
coredev.menu.FlashSize.1M192.build.spiffs_blocksize=4096
|
||||
coredev.menu.FlashSize.1M192.upload.maximum_size=827376
|
||||
|
||||
coredev.menu.FlashSize.1M160=1M (160K SPIFFS)
|
||||
coredev.menu.FlashSize.1M160.build.flash_size=1M
|
||||
coredev.menu.FlashSize.1M160.build.flash_ld=eagle.flash.1m160.ld
|
||||
coredev.menu.FlashSize.1M160.build.spiffs_start=0xD3000
|
||||
coredev.menu.FlashSize.1M160.build.spiffs_end=0xFB000
|
||||
coredev.menu.FlashSize.1M160.build.spiffs_blocksize=4096
|
||||
coredev.menu.FlashSize.1M160.upload.maximum_size=860144
|
||||
|
||||
coredev.menu.FlashSize.1M144=1M (144K SPIFFS)
|
||||
coredev.menu.FlashSize.1M144.build.flash_size=1M
|
||||
coredev.menu.FlashSize.1M144.build.flash_ld=eagle.flash.1m144.ld
|
||||
coredev.menu.FlashSize.1M144.build.spiffs_start=0xD7000
|
||||
coredev.menu.FlashSize.1M144.build.spiffs_end=0xFB000
|
||||
coredev.menu.FlashSize.1M144.build.spiffs_blocksize=4096
|
||||
coredev.menu.FlashSize.1M144.upload.maximum_size=876528
|
||||
|
||||
coredev.menu.FlashSize.1M128=1M (128K SPIFFS)
|
||||
coredev.menu.FlashSize.1M128.build.flash_size=1M
|
||||
coredev.menu.FlashSize.1M128.build.flash_ld=eagle.flash.1m128.ld
|
||||
coredev.menu.FlashSize.1M128.build.spiffs_start=0xDB000
|
||||
coredev.menu.FlashSize.1M128.build.spiffs_end=0xFB000
|
||||
coredev.menu.FlashSize.1M128.build.spiffs_blocksize=4096
|
||||
coredev.menu.FlashSize.1M128.upload.maximum_size=892912
|
||||
|
||||
coredev.menu.FlashSize.1M64=1M (64K SPIFFS)
|
||||
coredev.menu.FlashSize.1M64.build.flash_size=1M
|
||||
coredev.menu.FlashSize.1M64.build.flash_ld=eagle.flash.1m64.ld
|
||||
coredev.menu.FlashSize.1M64.build.spiffs_start=0xEB000
|
||||
coredev.menu.FlashSize.1M64.build.spiffs_end=0xFB000
|
||||
coredev.menu.FlashSize.1M64.build.spiffs_blocksize=4096
|
||||
coredev.menu.FlashSize.1M64.upload.maximum_size=958448
|
||||
|
||||
coredev.menu.FlashSize.2M=2M (1M SPIFFS)
|
||||
coredev.menu.FlashSize.2M.build.flash_size=2M
|
||||
coredev.menu.FlashSize.2M.build.flash_ld=eagle.flash.2m.ld
|
||||
coredev.menu.FlashSize.2M.build.spiffs_start=0x100000
|
||||
coredev.menu.FlashSize.2M.build.spiffs_end=0x1FB000
|
||||
coredev.menu.FlashSize.2M.build.spiffs_blocksize=8192
|
||||
coredev.menu.FlashSize.2M.upload.maximum_size=1044464
|
||||
|
||||
coredev.menu.FlashSize.4M1M=4M (1M SPIFFS)
|
||||
coredev.menu.FlashSize.4M1M.build.flash_size=4M
|
||||
coredev.menu.FlashSize.4M1M.build.flash_ld=eagle.flash.4m1m.ld
|
||||
coredev.menu.FlashSize.4M1M.build.spiffs_start=0x300000
|
||||
coredev.menu.FlashSize.4M1M.build.spiffs_end=0x3FB000
|
||||
coredev.menu.FlashSize.4M1M.build.spiffs_blocksize=8192
|
||||
coredev.menu.FlashSize.4M1M.build.spiffs_pagesize=256
|
||||
coredev.menu.FlashSize.4M1M.upload.maximum_size=1044464
|
||||
|
||||
coredev.menu.FlashSize.4M3M=4M (3M SPIFFS)
|
||||
coredev.menu.FlashSize.4M3M.build.flash_size=4M
|
||||
coredev.menu.FlashSize.4M3M.build.flash_ld=eagle.flash.4m.ld
|
||||
coredev.menu.FlashSize.4M3M.build.spiffs_start=0x100000
|
||||
coredev.menu.FlashSize.4M3M.build.spiffs_end=0x3FB000
|
||||
coredev.menu.FlashSize.4M3M.build.spiffs_blocksize=8192
|
||||
coredev.menu.FlashSize.4M3M.upload.maximum_size=1044464
|
||||
|
||||
coredev.menu.ResetMethod.ck=ck
|
||||
coredev.menu.ResetMethod.ck.upload.resetmethod=ck
|
||||
coredev.menu.ResetMethod.nodemcu=nodemcu
|
||||
coredev.menu.ResetMethod.nodemcu.upload.resetmethod=nodemcu
|
||||
|
||||
coredev.menu.Debug.Disabled=Disabled
|
||||
coredev.menu.Debug.Disabled.build.debug_port=
|
||||
coredev.menu.Debug.Serial=Serial
|
||||
coredev.menu.Debug.Serial.build.debug_port=-DDEBUG_ESP_PORT=Serial
|
||||
coredev.menu.Debug.Serial1=Serial1
|
||||
coredev.menu.Debug.Serial1.build.debug_port=-DDEBUG_ESP_PORT=Serial1
|
||||
|
||||
coredev.menu.DebugLevel.None____=None
|
||||
coredev.menu.DebugLevel.None____.build.debug_level=
|
||||
coredev.menu.DebugLevel.Core____=Core
|
||||
coredev.menu.DebugLevel.Core____.build.debug_level=-DDEBUG_ESP_CORE
|
||||
coredev.menu.DebugLevel.SSL_____=Core + SSL
|
||||
coredev.menu.DebugLevel.SSL_____.build.debug_level=-DDEBUG_ESP_CORE -DDEBUG_ESP_SSL
|
||||
coredev.menu.DebugLevel.SSL_MEM_=Core + SSL + TLS Mem
|
||||
coredev.menu.DebugLevel.SSL_MEM_.build.debug_level=-DDEBUG_ESP_CORE -DDEBUG_ESP_SSL -DDEBUG_TLS_MEM
|
||||
coredev.menu.DebugLevel.WiFic___=Core + WiFi
|
||||
coredev.menu.DebugLevel.WiFic___.build.debug_level=-DDEBUG_ESP_CORE -DDEBUG_ESP_WIFI
|
||||
coredev.menu.DebugLevel.WiFi____=WiFi
|
||||
coredev.menu.DebugLevel.WiFi____.build.debug_level=-DDEBUG_ESP_WIFI
|
||||
coredev.menu.DebugLevel.HTTPClient=HTTPClient
|
||||
coredev.menu.DebugLevel.HTTPClient.build.debug_level=-DDEBUG_ESP_HTTP_CLIENT
|
||||
coredev.menu.DebugLevel.HTTPClient2=HTTPClient + SSL
|
||||
coredev.menu.DebugLevel.HTTPClient2.build.debug_level=-DDEBUG_ESP_HTTP_CLIENT -DDEBUG_ESP_SSL
|
||||
coredev.menu.DebugLevel.HTTPUpdate=HTTPUpdate
|
||||
coredev.menu.DebugLevel.HTTPUpdate.build.debug_level=-DDEBUG_ESP_HTTP_UPDATE
|
||||
coredev.menu.DebugLevel.HTTPUpdate2=HTTPClient + HTTPUpdate
|
||||
coredev.menu.DebugLevel.HTTPUpdate2.build.debug_level=-DDEBUG_ESP_HTTP_UPDATE -DDEBUG_ESP_HTTP_UPDATE
|
||||
coredev.menu.DebugLevel.HTTPUpdate3=HTTPClient + HTTPUpdate + Updater
|
||||
coredev.menu.DebugLevel.HTTPUpdate3.build.debug_level=-DDEBUG_ESP_HTTP_UPDATE -DDEBUG_ESP_HTTP_UPDATE -DDEBUG_ESP_UPDATER
|
||||
coredev.menu.DebugLevel.HTTPServer=HTTPServer
|
||||
coredev.menu.DebugLevel.HTTPServer.build.debug_level=-DDEBUG_ESP_HTTP_SERVER
|
||||
coredev.menu.DebugLevel.UPDATER=Updater
|
||||
coredev.menu.DebugLevel.UPDATER.build.debug_level=-DDEBUG_ESP_UPDATER
|
||||
coredev.menu.DebugLevel.OTA_____=OTA
|
||||
coredev.menu.DebugLevel.OTA_____.build.debug_level=-DDEBUG_ESP_OTA
|
||||
coredev.menu.DebugLevel.OTA2____=OTA + Updater
|
||||
coredev.menu.DebugLevel.OTA2____.build.debug_level=-DDEBUG_ESP_OTA -DDEBUG_ESP_UPDATER
|
||||
coredev.menu.DebugLevel.all_____=All
|
||||
coredev.menu.DebugLevel.all_____.build.debug_level=-DDEBUG_ESP_CORE -DDEBUG_ESP_SSL -DDEBUG_ESP_WIFI -DDEBUG_ESP_HTTP_CLIENT -DDEBUG_ESP_HTTP_UPDATE -DDEBUG_ESP_HTTP_SERVER -DDEBUG_ESP_UPDATER -DDEBUG_ESP_OTA -DDEBUG_TLS_MEM
|
||||
|
@ -5,8 +5,50 @@ title: Change Log
|
||||
## Current version
|
||||
|
||||
### Core
|
||||
- Leverage realloc() in String::changeBuffer()
|
||||
- Clean up core files
|
||||
- Add host side tests
|
||||
- Fix possible null pointer in umm_malloc
|
||||
- Remove "Upload Using" option from Tools menu
|
||||
- Move attachInterrupt and detachInterrupt into IRAM (#1734)
|
||||
- Implement strstr_P
|
||||
- Allow indefinite duration for tone()
|
||||
- Fix crashes when using tone()
|
||||
- Fix RF_MODE and ADC_MODE
|
||||
- Move micros, delayMicroseconds, millis to IRAM (#1326)
|
||||
- Fix pulseIn (#1072, #1149)
|
||||
- Accept both named constant and ADC channel number in analogRead (#1766)
|
||||
- Enable heap poisoning only when debug options are enabled (#1800)
|
||||
- Bootloader: don't touch RTC memory if it doesn't contain a valid command (#619)
|
||||
- Update SDK to 1.5.2 (#1653)
|
||||
- Clean up variants, fix digitalPinHasPWM definition (#1831)
|
||||
- Don't set RF mode on boot unless it was overridden
|
||||
- Change build.board property for boards which renumber pins like NodeMCU (#1878)
|
||||
|
||||
### Libraries
|
||||
- Update axTLS to 5b4be7d
|
||||
- WiFiClientSecure: implement connection timeout, fix connected method behavior
|
||||
- WiFiClient: fix write behavior when connection is closed by remote side
|
||||
- ESP8266HTTPServer: add font MIME types, fix #1601
|
||||
- ESP8266mDNS: add client support
|
||||
- Update SPIFFS to 82aeac6
|
||||
- Servo: move some functions into IRAM (#1742)
|
||||
- Update SoftwareSerial to version 3.1.0
|
||||
- ESP8266SSDP: change templates to include deviceType
|
||||
- ESP8266WebServer: handle more file types
|
||||
- SPI: add CPOL setting
|
||||
- ESP8266WebServer: Fix buffer overflow in ESP8266WebServer::authenticate (#1790)
|
||||
- ESP8266WiFi: fix undefined behavior in WiFiServer::setNoDelay (#1695)
|
||||
- Servo: use peripheral clock frequency when calculating FRC1 tick count (#1789)
|
||||
- ESP8266WiFi: avoid multiple instances of INADDR_NONE
|
||||
- Add LwIP binary built with gcc
|
||||
- ESP8266WiFi: Allow PSK instead of passphrase in WiFiSTA::begin
|
||||
- SPI: Fix SPI.transfer16() using wrong endianness
|
||||
- HTTPClient: decouple transport layer handling + save some RAM
|
||||
ESP8266httpUpdate: decouple HTTPS overloads + save some RAM
|
||||
- Update and move lwIP headers, add options to use different lwIP build for generic device
|
||||
- ESP8266WebServer: wait for data to arrive
|
||||
|
||||
|
||||
### Tools
|
||||
|
||||
|
@ -105,6 +105,28 @@ Opens a file. `path` should be an absolute path starting with a slash
|
||||
(e.g. `/dir/filename.txt`). `mode` is a string specifying access mode. It can be
|
||||
one of "r", "w", "a", "r+", "w+", "a+". Meaning of these modes is the same as
|
||||
for `fopen` C function.
|
||||
|
||||
r Open text file for reading. The stream is positioned at the
|
||||
beginning of the file.
|
||||
|
||||
r+ Open for reading and writing. The stream is positioned at the
|
||||
beginning of the file.
|
||||
|
||||
w Truncate file to zero length or create text file for writing.
|
||||
The stream is positioned at the beginning of the file.
|
||||
|
||||
w+ Open for reading and writing. The file is created if it does
|
||||
not exist, otherwise it is truncated. The stream is
|
||||
positioned at the beginning of the file.
|
||||
|
||||
a Open for appending (writing at end of file). The file is
|
||||
created if it does not exist. The stream is positioned at the
|
||||
end of the file.
|
||||
|
||||
a+ Open for reading and appending (writing at end of file). The
|
||||
file is created if it does not exist. The initial file
|
||||
position for reading is at the beginning of the file, but
|
||||
output is always appended to the end of the file.
|
||||
|
||||
Returns *File* object. To check whether the file was opened successfully, use
|
||||
the boolean operator.
|
||||
|
@ -163,3 +163,5 @@ Libraries that don't rely on low-level access to AVR registers should work well.
|
||||
- [Adafruit-PCD8544-Nokia-5110-LCD-Library](https://github.com/WereCatf/Adafruit-PCD8544-Nokia-5110-LCD-library) - Port of the Adafruit PCD8544 - library for the ESP8266.
|
||||
- [PCF8574_ESP](https://github.com/WereCatf/PCF8574_ESP) - A very simplistic library for using the PCF8574/PCF8574A I2C 8-pin GPIO-expander.
|
||||
- [Dot Matrix Display Library 2](https://github.com/freetronics/DMD2) - Freetronics DMD & Generic 16 x 32 P10 style Dot Matrix Display Library
|
||||
- [SdFat-beta](https://github.com/greiman/SdFat-beta) - SD-card library with support for long filenames, software- and hardware-based SPI and lots more.
|
||||
- [FastLED](https://github.com/FastLED/FastLED) - a library for easily & efficiently controlling a wide variety of LED chipsets, like the Neopixel (WS2812B), DotStar, LPD8806 and many more. Includes fading, gradient, color conversion functions.
|
||||
|
@ -1,4 +1,6 @@
|
||||
#ifndef LWIP_OPEN_SRC
|
||||
#define LWIP_OPEN_SRC
|
||||
#endif
|
||||
#include <functional>
|
||||
#include <WiFiUdp.h>
|
||||
#include "ArduinoOTA.h"
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=ESP8266HTTPClient
|
||||
version=1.0
|
||||
version=1.1
|
||||
author=Markus Sattler
|
||||
maintainer=Markus Sattler
|
||||
sentence=http Client for ESP8266
|
||||
|
@ -30,168 +30,188 @@
|
||||
|
||||
#include "ESP8266HTTPClient.h"
|
||||
|
||||
class TransportTraits
|
||||
{
|
||||
public:
|
||||
virtual std::unique_ptr<WiFiClient> create()
|
||||
{
|
||||
return std::unique_ptr<WiFiClient>(new WiFiClient());
|
||||
}
|
||||
|
||||
virtual bool verify(WiFiClient& client, const char* host)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
class TLSTraits : public TransportTraits
|
||||
{
|
||||
public:
|
||||
TLSTraits(const String& fingerprint) :
|
||||
_fingerprint(fingerprint)
|
||||
{
|
||||
}
|
||||
|
||||
std::unique_ptr<WiFiClient> create() override
|
||||
{
|
||||
return std::unique_ptr<WiFiClient>(new WiFiClientSecure());
|
||||
}
|
||||
|
||||
bool verify(WiFiClient& client, const char* host) override
|
||||
{
|
||||
auto wcs = reinterpret_cast<WiFiClientSecure&>(client);
|
||||
return wcs.verify(_fingerprint.c_str(), host);
|
||||
}
|
||||
|
||||
protected:
|
||||
String _fingerprint;
|
||||
};
|
||||
|
||||
/**
|
||||
* constractor
|
||||
* constructor
|
||||
*/
|
||||
HTTPClient::HTTPClient() {
|
||||
_tcp = NULL;
|
||||
_tcps = NULL;
|
||||
|
||||
_port = 0;
|
||||
|
||||
_reuse = false;
|
||||
_tcpTimeout = HTTPCLIENT_DEFAULT_TCP_TIMEOUT;
|
||||
_useHTTP10 = false;
|
||||
|
||||
_https = false;
|
||||
|
||||
_userAgent = "ESP8266HTTPClient";
|
||||
|
||||
_headerKeysCount = 0;
|
||||
_currentHeaders = NULL;
|
||||
|
||||
_returnCode = 0;
|
||||
_size = -1;
|
||||
_canReuse = false;
|
||||
_transferEncoding = HTTPC_TE_IDENTITY;
|
||||
|
||||
HTTPClient::HTTPClient()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* deconstractor
|
||||
* destructor
|
||||
*/
|
||||
HTTPClient::~HTTPClient() {
|
||||
|
||||
if(_tcps) {
|
||||
_tcps->stop();
|
||||
delete _tcps;
|
||||
_tcps = NULL;
|
||||
_tcp = NULL;
|
||||
} else if(_tcp) {
|
||||
HTTPClient::~HTTPClient()
|
||||
{
|
||||
if(_tcp) {
|
||||
_tcp->stop();
|
||||
delete _tcp;
|
||||
_tcp = NULL;
|
||||
}
|
||||
|
||||
if(_currentHeaders) {
|
||||
delete[] _currentHeaders;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* phasing the url for all needed informations
|
||||
* @param url const char *
|
||||
* @param httpsFingerprint const char *
|
||||
*/
|
||||
void HTTPClient::begin(const char *url, const char * httpsFingerprint) {
|
||||
begin(String(url), String(httpsFingerprint));
|
||||
|
||||
bool HTTPClient::begin(String url, String httpsFingerprint)
|
||||
{
|
||||
if (httpsFingerprint.length() == 0) {
|
||||
return false;
|
||||
}
|
||||
if (!begin(url)) {
|
||||
return false;
|
||||
}
|
||||
_transportTraits = TransportTraitsPtr(new TLSTraits(httpsFingerprint));
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client][begin] httpsFingerprint: %s\n", httpsFingerprint.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* phasing the url for all needed informations
|
||||
* @param url String
|
||||
* @param httpsFingerprint String
|
||||
*/
|
||||
void HTTPClient::begin(String url, String httpsFingerprint) {
|
||||
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client][begin] url: %s\n", url.c_str());
|
||||
|
||||
_httpsFingerprint = httpsFingerprint;
|
||||
void HTTPClient::clear()
|
||||
{
|
||||
_returnCode = 0;
|
||||
_size = -1;
|
||||
_headers = "";
|
||||
}
|
||||
|
||||
_Headers = "";
|
||||
|
||||
String protocol;
|
||||
/**
|
||||
* parsing the url for all needed parameters
|
||||
* @param url String
|
||||
*/
|
||||
bool HTTPClient::begin(String url)
|
||||
{
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client][begin] url: %s\n", url.c_str());
|
||||
bool hasPort = false;
|
||||
clear();
|
||||
|
||||
// check for : (http: or https:
|
||||
int index = url.indexOf(':');
|
||||
//int index2;
|
||||
bool hasPort = false;
|
||||
if(index >= 0) {
|
||||
protocol = url.substring(0, index);
|
||||
url.remove(0, (index + 3)); // remove http:// or https://
|
||||
|
||||
index = url.indexOf('/');
|
||||
String host = url.substring(0, index);
|
||||
url.remove(0, index); // remove host part
|
||||
|
||||
// get Authorization
|
||||
index = host.indexOf('@');
|
||||
if(index >= 0) {
|
||||
// auth info
|
||||
String auth = host.substring(0, index);
|
||||
host.remove(0, index + 1); // remove auth part including @
|
||||
_base64Authorization = base64::encode(auth);
|
||||
}
|
||||
|
||||
// get port
|
||||
index = host.indexOf(':');
|
||||
if(index >= 0) {
|
||||
_host = host.substring(0, index); // hostname
|
||||
host.remove(0, (index + 1)); // remove hostname + :
|
||||
_port = host.toInt(); // get port
|
||||
hasPort = true;
|
||||
} else {
|
||||
_host = host;
|
||||
}
|
||||
|
||||
_url = url;
|
||||
|
||||
if(protocol.equalsIgnoreCase("http")) {
|
||||
_https = false;
|
||||
if(!hasPort) {
|
||||
_port = 80;
|
||||
}
|
||||
} else if(protocol.equalsIgnoreCase("https")) {
|
||||
_https = true;
|
||||
if(!hasPort) {
|
||||
_port = 443;
|
||||
}
|
||||
} else {
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client][begin] protocol: %s unknown?!\n", protocol.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
if(index < 0) {
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client][begin] failed to parse protocol\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client][begin] host: %s port: %d url: %s https: %d httpsFingerprint: %s\n", _host.c_str(), _port, _url.c_str(), _https, _httpsFingerprint.c_str());
|
||||
_protocol = url.substring(0, index);
|
||||
url.remove(0, (index + 3)); // remove http:// or https://
|
||||
|
||||
index = url.indexOf('/');
|
||||
String host = url.substring(0, index);
|
||||
url.remove(0, index); // remove host part
|
||||
|
||||
// get Authorization
|
||||
index = host.indexOf('@');
|
||||
if(index >= 0) {
|
||||
// auth info
|
||||
String auth = host.substring(0, index);
|
||||
host.remove(0, index + 1); // remove auth part including @
|
||||
_base64Authorization = base64::encode(auth);
|
||||
}
|
||||
|
||||
// get port
|
||||
index = host.indexOf(':');
|
||||
if(index >= 0) {
|
||||
_host = host.substring(0, index); // hostname
|
||||
host.remove(0, (index + 1)); // remove hostname + :
|
||||
_port = host.toInt(); // get port
|
||||
hasPort = true;
|
||||
} else {
|
||||
_host = host;
|
||||
}
|
||||
_uri = url;
|
||||
|
||||
if(_protocol.equalsIgnoreCase("http")) {
|
||||
if(!hasPort) {
|
||||
_port = 80;
|
||||
}
|
||||
} else if(_protocol.equalsIgnoreCase("https")) {
|
||||
if(!hasPort) {
|
||||
_port = 443;
|
||||
}
|
||||
} else {
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client][begin] protocol: %s unknown?!\n", _protocol.c_str());
|
||||
return false;
|
||||
}
|
||||
_transportTraits = TransportTraitsPtr(new TransportTraits());
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client][begin] host: %s port: %d url: %s\n", _host.c_str(), _port, _uri.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* begin
|
||||
* @param host const char *
|
||||
* @param port uint16_t
|
||||
* @param url const char *
|
||||
* @param https bool
|
||||
* @param httpsFingerprint const char *
|
||||
*/
|
||||
void HTTPClient::begin(const char *host, uint16_t port, const char * url, bool https, const char * httpsFingerprint) {
|
||||
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client][begin] host: %s port:%d url: %s https: %d httpsFingerprint: %s\n", host, port, url, https, httpsFingerprint);
|
||||
|
||||
bool HTTPClient::begin(String host, uint16_t port, String uri)
|
||||
{
|
||||
clear();
|
||||
_host = host;
|
||||
_port = port;
|
||||
_url = url;
|
||||
_https = https;
|
||||
_httpsFingerprint = httpsFingerprint;
|
||||
|
||||
_returnCode = 0;
|
||||
_size = -1;
|
||||
|
||||
_Headers = "";
|
||||
|
||||
_uri = uri;
|
||||
_transportTraits = TransportTraitsPtr(new TransportTraits());
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client][begin] host: %s port: %d uri: %s\n", host.c_str(), port, uri.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
void HTTPClient::begin(String host, uint16_t port, String url, bool https, String httpsFingerprint) {
|
||||
begin(host.c_str(), port, url.c_str(), https, httpsFingerprint.c_str());
|
||||
bool HTTPClient::begin(String host, uint16_t port, String uri, bool https, String httpsFingerprint)
|
||||
{
|
||||
if (https) {
|
||||
return begin(host, port, uri, httpsFingerprint);
|
||||
} else {
|
||||
return begin(host, port, uri);
|
||||
}
|
||||
}
|
||||
|
||||
bool HTTPClient::begin(String host, uint16_t port, String uri, String httpsFingerprint)
|
||||
{
|
||||
clear();
|
||||
_host = host;
|
||||
_port = port;
|
||||
_uri = uri;
|
||||
|
||||
if (httpsFingerprint.length() == 0) {
|
||||
return false;
|
||||
}
|
||||
_transportTraits = TransportTraitsPtr(new TLSTraits(httpsFingerprint));
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client][begin] host: %s port: %d url: %s httpsFingerprint: %s\n", host.c_str(), port, uri.c_str(), httpsFingerprint.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* end
|
||||
* called after the payload is handled
|
||||
*/
|
||||
void HTTPClient::end(void) {
|
||||
void HTTPClient::end(void)
|
||||
{
|
||||
if(connected()) {
|
||||
if(_tcp->available() > 0) {
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client][end] still data in buffer (%d), clean up.\n", _tcp->available());
|
||||
@ -214,7 +234,8 @@ void HTTPClient::end(void) {
|
||||
* connected
|
||||
* @return connected status
|
||||
*/
|
||||
bool HTTPClient::connected() {
|
||||
bool HTTPClient::connected()
|
||||
{
|
||||
if(_tcp) {
|
||||
return (_tcp->connected() || (_tcp->available() > 0));
|
||||
}
|
||||
@ -226,7 +247,8 @@ bool HTTPClient::connected() {
|
||||
* keep-alive
|
||||
* @param reuse bool
|
||||
*/
|
||||
void HTTPClient::setReuse(bool reuse) {
|
||||
void HTTPClient::setReuse(bool reuse)
|
||||
{
|
||||
_reuse = reuse;
|
||||
}
|
||||
|
||||
@ -234,7 +256,8 @@ void HTTPClient::setReuse(bool reuse) {
|
||||
* set User Agent
|
||||
* @param userAgent const char *
|
||||
*/
|
||||
void HTTPClient::setUserAgent(const char * userAgent) {
|
||||
void HTTPClient::setUserAgent(const String& userAgent)
|
||||
{
|
||||
_userAgent = userAgent;
|
||||
}
|
||||
|
||||
@ -243,7 +266,8 @@ void HTTPClient::setUserAgent(const char * userAgent) {
|
||||
* @param user const char *
|
||||
* @param password const char *
|
||||
*/
|
||||
void HTTPClient::setAuthorization(const char * user, const char * password) {
|
||||
void HTTPClient::setAuthorization(const char * user, const char * password)
|
||||
{
|
||||
if(user && password) {
|
||||
String auth = user;
|
||||
auth += ":";
|
||||
@ -256,7 +280,8 @@ void HTTPClient::setAuthorization(const char * user, const char * password) {
|
||||
* set the Authorizatio for the http request
|
||||
* @param auth const char * base64
|
||||
*/
|
||||
void HTTPClient::setAuthorization(const char * auth) {
|
||||
void HTTPClient::setAuthorization(const char * auth)
|
||||
{
|
||||
if(auth) {
|
||||
_base64Authorization = auth;
|
||||
}
|
||||
@ -266,7 +291,8 @@ void HTTPClient::setAuthorization(const char * auth) {
|
||||
* set the timeout for the TCP connection
|
||||
* @param timeout unsigned int
|
||||
*/
|
||||
void HTTPClient::setTimeout(uint16_t timeout) {
|
||||
void HTTPClient::setTimeout(uint16_t timeout)
|
||||
{
|
||||
_tcpTimeout = timeout;
|
||||
if(connected()) {
|
||||
_tcp->setTimeout(timeout);
|
||||
@ -277,7 +303,8 @@ void HTTPClient::setTimeout(uint16_t timeout) {
|
||||
* use HTTP1.0
|
||||
* @param timeout
|
||||
*/
|
||||
void HTTPClient::useHTTP10(bool useHTTP10) {
|
||||
void HTTPClient::useHTTP10(bool useHTTP10)
|
||||
{
|
||||
_useHTTP10 = useHTTP10;
|
||||
}
|
||||
|
||||
@ -285,7 +312,8 @@ void HTTPClient::useHTTP10(bool useHTTP10) {
|
||||
* send a GET request
|
||||
* @return http code
|
||||
*/
|
||||
int HTTPClient::GET() {
|
||||
int HTTPClient::GET()
|
||||
{
|
||||
return sendRequest("GET");
|
||||
}
|
||||
|
||||
@ -295,11 +323,13 @@ int HTTPClient::GET() {
|
||||
* @param size size_t
|
||||
* @return http code
|
||||
*/
|
||||
int HTTPClient::POST(uint8_t * payload, size_t size) {
|
||||
int HTTPClient::POST(uint8_t * payload, size_t size)
|
||||
{
|
||||
return sendRequest("POST", payload, size);
|
||||
}
|
||||
|
||||
int HTTPClient::POST(String payload) {
|
||||
int HTTPClient::POST(String payload)
|
||||
{
|
||||
return POST((uint8_t *) payload.c_str(), payload.length());
|
||||
}
|
||||
|
||||
@ -309,7 +339,8 @@ int HTTPClient::POST(String payload) {
|
||||
* @param payload String data for the message body
|
||||
* @return
|
||||
*/
|
||||
int HTTPClient::sendRequest(const char * type, String payload) {
|
||||
int HTTPClient::sendRequest(const char * type, String payload)
|
||||
{
|
||||
return sendRequest(type, (uint8_t *) payload.c_str(), payload.length());
|
||||
}
|
||||
|
||||
@ -320,14 +351,15 @@ int HTTPClient::sendRequest(const char * type, String payload) {
|
||||
* @param size size_t size for the message body if 0 not send
|
||||
* @return -1 if no info or > 0 when Content-Length is set by server
|
||||
*/
|
||||
int HTTPClient::sendRequest(const char * type, uint8_t * payload, size_t size) {
|
||||
int HTTPClient::sendRequest(const char * type, uint8_t * payload, size_t size)
|
||||
{
|
||||
// connect to server
|
||||
if(!connect()) {
|
||||
return returnError(HTTPC_ERROR_CONNECTION_REFUSED);
|
||||
}
|
||||
|
||||
if(payload && size > 0) {
|
||||
addHeader("Content-Length", String(size));
|
||||
addHeader(F("Content-Length"), String(size));
|
||||
}
|
||||
|
||||
// send Header
|
||||
@ -353,7 +385,8 @@ int HTTPClient::sendRequest(const char * type, uint8_t * payload, size_t size) {
|
||||
* @param size size_t size for the message body if 0 not Content-Length is send
|
||||
* @return -1 if no info or > 0 when Content-Length is set by server
|
||||
*/
|
||||
int HTTPClient::sendRequest(const char * type, Stream * stream, size_t size) {
|
||||
int HTTPClient::sendRequest(const char * type, Stream * stream, size_t size)
|
||||
{
|
||||
|
||||
if(!stream) {
|
||||
return returnError(HTTPC_ERROR_NO_STREAM);
|
||||
@ -468,7 +501,8 @@ int HTTPClient::sendRequest(const char * type, Stream * stream, size_t size) {
|
||||
free(buff);
|
||||
|
||||
if(size && (int) size != bytesWritten) {
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client][sendRequest] Stream payload bytesWritten %d and size %d mismatch!.\n", bytesWritten, size); DEBUG_HTTPCLIENT("[HTTP-Client][sendRequest] ERROR SEND PAYLOAD FAILED!");
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client][sendRequest] Stream payload bytesWritten %d and size %d mismatch!.\n", bytesWritten, size);
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client][sendRequest] ERROR SEND PAYLOAD FAILED!");
|
||||
return returnError(HTTPC_ERROR_SEND_PAYLOAD_FAILED);
|
||||
} else {
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client][sendRequest] Stream payload written: %d\n", bytesWritten);
|
||||
@ -487,36 +521,38 @@ int HTTPClient::sendRequest(const char * type, Stream * stream, size_t size) {
|
||||
* size of message body / payload
|
||||
* @return -1 if no info or > 0 when Content-Length is set by server
|
||||
*/
|
||||
int HTTPClient::getSize(void) {
|
||||
int HTTPClient::getSize(void)
|
||||
{
|
||||
return _size;
|
||||
}
|
||||
|
||||
/**
|
||||
* deprecated Note: this is not working with https!
|
||||
* returns the stream of the tcp connection
|
||||
* @return WiFiClient
|
||||
*/
|
||||
WiFiClient & HTTPClient::getStream(void) {
|
||||
WiFiClient& HTTPClient::getStream(void)
|
||||
{
|
||||
if(connected()) {
|
||||
return *_tcp;
|
||||
}
|
||||
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client] no stream to return!?\n");
|
||||
|
||||
// todo return error?
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client] getStream: not connected\n");
|
||||
static WiFiClient empty;
|
||||
return empty;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the stream of the tcp connection
|
||||
* @return WiFiClient *
|
||||
*/
|
||||
WiFiClient * HTTPClient::getStreamPtr(void) {
|
||||
WiFiClient* HTTPClient::getStreamPtr(void)
|
||||
{
|
||||
if(connected()) {
|
||||
return _tcp;
|
||||
return _tcp.get();
|
||||
}
|
||||
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client] no stream to return!?\n");
|
||||
return NULL;
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client] getStreamPtr: not connected\n");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -524,7 +560,8 @@ WiFiClient * HTTPClient::getStreamPtr(void) {
|
||||
* @param stream Stream *
|
||||
* @return bytes written ( negative values are error codes )
|
||||
*/
|
||||
int HTTPClient::writeToStream(Stream * stream) {
|
||||
int HTTPClient::writeToStream(Stream * stream)
|
||||
{
|
||||
|
||||
if(!stream) {
|
||||
return returnError(HTTPC_ERROR_NO_STREAM);
|
||||
@ -600,14 +637,15 @@ int HTTPClient::writeToStream(Stream * stream) {
|
||||
* return all payload as String (may need lot of ram or trigger out of memory!)
|
||||
* @return String
|
||||
*/
|
||||
String HTTPClient::getString(void) {
|
||||
String HTTPClient::getString(void)
|
||||
{
|
||||
StreamString sstring;
|
||||
|
||||
if(_size) {
|
||||
// try to reserve needed memmory
|
||||
if(!sstring.reserve((_size + 1))) {
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client][getString] too less memory to reserve as string! need: %d\n", (_size + 1));
|
||||
return String("--too less memory--");
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client][getString] not enough memory to reserve a string! need: %d\n", (_size + 1));
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@ -620,32 +658,33 @@ String HTTPClient::getString(void) {
|
||||
* @param error int
|
||||
* @return String
|
||||
*/
|
||||
String HTTPClient::errorToString(int error) {
|
||||
String HTTPClient::errorToString(int error)
|
||||
{
|
||||
switch(error) {
|
||||
case HTTPC_ERROR_CONNECTION_REFUSED:
|
||||
return String("connection refused");
|
||||
case HTTPC_ERROR_SEND_HEADER_FAILED:
|
||||
return String("send header failed");
|
||||
case HTTPC_ERROR_SEND_PAYLOAD_FAILED:
|
||||
return String("send payload failed");
|
||||
case HTTPC_ERROR_NOT_CONNECTED:
|
||||
return String("not connected");
|
||||
case HTTPC_ERROR_CONNECTION_LOST:
|
||||
return String("connection lost");
|
||||
case HTTPC_ERROR_NO_STREAM:
|
||||
return String("no stream");
|
||||
case HTTPC_ERROR_NO_HTTP_SERVER:
|
||||
return String("no HTTP server");
|
||||
case HTTPC_ERROR_TOO_LESS_RAM:
|
||||
return String("too less ram");
|
||||
case HTTPC_ERROR_ENCODING:
|
||||
return String("Transfer-Encoding not supported");
|
||||
case HTTPC_ERROR_STREAM_WRITE:
|
||||
return String("Stream write error");
|
||||
case HTTPC_ERROR_READ_TIMEOUT:
|
||||
return String("read Timeout");
|
||||
default:
|
||||
return String();
|
||||
case HTTPC_ERROR_CONNECTION_REFUSED:
|
||||
return F("connection refused");
|
||||
case HTTPC_ERROR_SEND_HEADER_FAILED:
|
||||
return F("send header failed");
|
||||
case HTTPC_ERROR_SEND_PAYLOAD_FAILED:
|
||||
return F("send payload failed");
|
||||
case HTTPC_ERROR_NOT_CONNECTED:
|
||||
return F("not connected");
|
||||
case HTTPC_ERROR_CONNECTION_LOST:
|
||||
return F("connection lost");
|
||||
case HTTPC_ERROR_NO_STREAM:
|
||||
return F("no stream");
|
||||
case HTTPC_ERROR_NO_HTTP_SERVER:
|
||||
return F("no HTTP server");
|
||||
case HTTPC_ERROR_TOO_LESS_RAM:
|
||||
return F("too less ram");
|
||||
case HTTPC_ERROR_ENCODING:
|
||||
return F("Transfer-Encoding not supported");
|
||||
case HTTPC_ERROR_STREAM_WRITE:
|
||||
return F("Stream write error");
|
||||
case HTTPC_ERROR_READ_TIMEOUT:
|
||||
return F("read Timeout");
|
||||
default:
|
||||
return String();
|
||||
}
|
||||
}
|
||||
|
||||
@ -655,62 +694,77 @@ String HTTPClient::errorToString(int error) {
|
||||
* @param value
|
||||
* @param first
|
||||
*/
|
||||
void HTTPClient::addHeader(const String& name, const String& value, bool first) {
|
||||
void HTTPClient::addHeader(const String& name, const String& value, bool first)
|
||||
{
|
||||
|
||||
// not allow set of Header handled by code
|
||||
if(!name.equalsIgnoreCase("Connection") && !name.equalsIgnoreCase("User-Agent") && !name.equalsIgnoreCase("Host") && !(_base64Authorization.length() && name.equalsIgnoreCase("Authorization"))) {
|
||||
if(!name.equalsIgnoreCase(F("Connection")) &&
|
||||
!name.equalsIgnoreCase(F("User-Agent")) &&
|
||||
!name.equalsIgnoreCase(F("Host")) &&
|
||||
!(name.equalsIgnoreCase(F("Authorization")) && _base64Authorization.length())){
|
||||
String headerLine = name;
|
||||
headerLine += ": ";
|
||||
headerLine += value;
|
||||
headerLine += "\r\n";
|
||||
|
||||
if(first) {
|
||||
_Headers = headerLine + _Headers;
|
||||
_headers = headerLine + _headers;
|
||||
} else {
|
||||
_Headers += headerLine;
|
||||
_headers += headerLine;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void HTTPClient::collectHeaders(const char* headerKeys[], const size_t headerKeysCount) {
|
||||
void HTTPClient::collectHeaders(const char* headerKeys[], const size_t headerKeysCount)
|
||||
{
|
||||
_headerKeysCount = headerKeysCount;
|
||||
if(_currentHeaders)
|
||||
if(_currentHeaders) {
|
||||
delete[] _currentHeaders;
|
||||
}
|
||||
_currentHeaders = new RequestArgument[_headerKeysCount];
|
||||
for(size_t i = 0; i < _headerKeysCount; i++) {
|
||||
_currentHeaders[i].key = headerKeys[i];
|
||||
}
|
||||
}
|
||||
|
||||
String HTTPClient::header(const char* name) {
|
||||
String HTTPClient::header(const char* name)
|
||||
{
|
||||
for(size_t i = 0; i < _headerKeysCount; ++i) {
|
||||
if(_currentHeaders[i].key == name)
|
||||
if(_currentHeaders[i].key == name) {
|
||||
return _currentHeaders[i].value;
|
||||
}
|
||||
}
|
||||
return String();
|
||||
}
|
||||
|
||||
String HTTPClient::header(size_t i) {
|
||||
if(i < _headerKeysCount)
|
||||
String HTTPClient::header(size_t i)
|
||||
{
|
||||
if(i < _headerKeysCount) {
|
||||
return _currentHeaders[i].value;
|
||||
}
|
||||
return String();
|
||||
}
|
||||
|
||||
String HTTPClient::headerName(size_t i) {
|
||||
if(i < _headerKeysCount)
|
||||
String HTTPClient::headerName(size_t i)
|
||||
{
|
||||
if(i < _headerKeysCount) {
|
||||
return _currentHeaders[i].key;
|
||||
}
|
||||
return String();
|
||||
}
|
||||
|
||||
int HTTPClient::headers() {
|
||||
int HTTPClient::headers()
|
||||
{
|
||||
return _headerKeysCount;
|
||||
}
|
||||
|
||||
bool HTTPClient::hasHeader(const char* name) {
|
||||
bool HTTPClient::hasHeader(const char* name)
|
||||
{
|
||||
for(size_t i = 0; i < _headerKeysCount; ++i) {
|
||||
if((_currentHeaders[i].key == name) && (_currentHeaders[i].value.length() > 0))
|
||||
if((_currentHeaders[i].key == name) && (_currentHeaders[i].value.length() > 0)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -719,7 +773,8 @@ bool HTTPClient::hasHeader(const char* name) {
|
||||
* init TCP connection and handle ssl verify if needed
|
||||
* @return true if connection is ok
|
||||
*/
|
||||
bool HTTPClient::connect(void) {
|
||||
bool HTTPClient::connect(void)
|
||||
{
|
||||
|
||||
if(connected()) {
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client] connect. already connected, try reuse!\n");
|
||||
@ -729,24 +784,13 @@ bool HTTPClient::connect(void) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if(_https) {
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client] connect https...\n");
|
||||
if(_tcps) {
|
||||
delete _tcps;
|
||||
_tcps = NULL;
|
||||
_tcp = NULL;
|
||||
}
|
||||
_tcps = new WiFiClientSecure();
|
||||
_tcp = _tcps;
|
||||
} else {
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client] connect http...\n");
|
||||
if(_tcp) {
|
||||
delete _tcp;
|
||||
_tcp = NULL;
|
||||
}
|
||||
_tcp = new WiFiClient();
|
||||
if (!_transportTraits) {
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client] _transportTraits is null (HTTPClient::begin not called?)\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
_tcp = _transportTraits->create();
|
||||
|
||||
if(!_tcp->connect(_host.c_str(), _port)) {
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client] failed connect to %s:%u\n", _host.c_str(), _port);
|
||||
return false;
|
||||
@ -754,14 +798,10 @@ bool HTTPClient::connect(void) {
|
||||
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client] connected to %s:%u\n", _host.c_str(), _port);
|
||||
|
||||
if(_https && _httpsFingerprint.length() > 0) {
|
||||
if(_tcps->verify(_httpsFingerprint.c_str(), _host.c_str())) {
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client] https certificate matches\n");
|
||||
} else {
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client] https certificate doesn't match!\n");
|
||||
_tcp->stop();
|
||||
return false;
|
||||
}
|
||||
if (!_transportTraits->verify(*_tcp, _host.c_str())) {
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client] transport level verify failed\n");
|
||||
_tcp->stop();
|
||||
return false;
|
||||
}
|
||||
|
||||
// set Timeout for readBytesUntil and readStringUntil
|
||||
@ -778,12 +818,13 @@ bool HTTPClient::connect(void) {
|
||||
* @param type (GET, POST, ...)
|
||||
* @return status
|
||||
*/
|
||||
bool HTTPClient::sendHeader(const char * type) {
|
||||
bool HTTPClient::sendHeader(const char * type)
|
||||
{
|
||||
if(!connected()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String header = String(type) + " " + _url + " HTTP/1.";
|
||||
String header = String(type) + " " + _uri + F(" HTTP/1.");
|
||||
|
||||
if(_useHTTP10) {
|
||||
header += "0";
|
||||
@ -791,36 +832,38 @@ bool HTTPClient::sendHeader(const char * type) {
|
||||
header += "1";
|
||||
}
|
||||
|
||||
header += "\r\n"
|
||||
"Host: " + _host + "\r\n"
|
||||
"User-Agent: " + _userAgent + "\r\n"
|
||||
"Connection: ";
|
||||
header += String(F("\r\nHost: ")) + _host +
|
||||
F("\r\nUser-Agent: ") + _userAgent +
|
||||
F("\r\nConnection: ");
|
||||
|
||||
if(_reuse) {
|
||||
header += "keep-alive";
|
||||
header += F("keep-alive");
|
||||
} else {
|
||||
header += "close";
|
||||
header += F("close");
|
||||
}
|
||||
header += "\r\n";
|
||||
|
||||
if(!_useHTTP10) {
|
||||
header += "Accept-Encoding: identity;q=1,chunked;q=0.1,*;q=0\r\n";
|
||||
header += F("Accept-Encoding: identity;q=1,chunked;q=0.1,*;q=0\r\n");
|
||||
}
|
||||
|
||||
if(_base64Authorization.length()) {
|
||||
header += "Authorization: Basic " + _base64Authorization + "\r\n";
|
||||
header += F("Authorization: Basic ");
|
||||
header += _base64Authorization;
|
||||
header += "\r\n";
|
||||
}
|
||||
|
||||
header += _Headers + "\r\n";
|
||||
header += _headers + "\r\n";
|
||||
|
||||
return (_tcp->write(header.c_str(), header.length()) == header.length());
|
||||
return (_tcp->write((const uint8_t *) header.c_str(), header.length()) == header.length());
|
||||
}
|
||||
|
||||
/**
|
||||
* reads the response from the server
|
||||
* @return int http code
|
||||
*/
|
||||
int HTTPClient::handleHeaderResponse() {
|
||||
int HTTPClient::handleHeaderResponse()
|
||||
{
|
||||
|
||||
if(!connected()) {
|
||||
return HTTPC_ERROR_NOT_CONNECTED;
|
||||
@ -911,7 +954,8 @@ int HTTPClient::handleHeaderResponse() {
|
||||
* @param size int
|
||||
* @return < 0 = error >= 0 = size written
|
||||
*/
|
||||
int HTTPClient::writeToStreamDataBlock(Stream * stream, int size) {
|
||||
int HTTPClient::writeToStreamDataBlock(Stream * stream, int size)
|
||||
{
|
||||
int buff_size = HTTP_TCP_BUFFER_SIZE;
|
||||
int len = size;
|
||||
int bytesWritten = 0;
|
||||
@ -1021,7 +1065,8 @@ int HTTPClient::writeToStreamDataBlock(Stream * stream, int size) {
|
||||
* @param error
|
||||
* @return error
|
||||
*/
|
||||
int HTTPClient::returnError(int error) {
|
||||
int HTTPClient::returnError(int error)
|
||||
{
|
||||
if(error < 0) {
|
||||
DEBUG_HTTPCLIENT("[HTTP-Client][returnError] error(%d): %s\n", error, errorToString(error).c_str());
|
||||
if(connected()) {
|
||||
|
@ -25,6 +25,10 @@
|
||||
#ifndef ESP8266HTTPClient_H_
|
||||
#define ESP8266HTTPClient_H_
|
||||
|
||||
#include <memory>
|
||||
#include <Arduino.h>
|
||||
#include <WiFiClient.h>
|
||||
|
||||
#ifdef DEBUG_ESP_HTTP_CLIENT
|
||||
#ifdef DEBUG_ESP_PORT
|
||||
#define DEBUG_HTTPCLIENT(...) DEBUG_ESP_PORT.printf( __VA_ARGS__ )
|
||||
@ -120,97 +124,100 @@ typedef enum {
|
||||
HTTPC_TE_CHUNKED
|
||||
} transferEncoding_t;
|
||||
|
||||
class HTTPClient {
|
||||
public:
|
||||
HTTPClient();
|
||||
~HTTPClient();
|
||||
class TransportTraits;
|
||||
typedef std::unique_ptr<TransportTraits> TransportTraitsPtr;
|
||||
|
||||
void begin(const char *url, const char * httpsFingerprint = "");
|
||||
void begin(String url, String httpsFingerprint = "");
|
||||
class HTTPClient
|
||||
{
|
||||
public:
|
||||
HTTPClient();
|
||||
~HTTPClient();
|
||||
|
||||
void begin(const char *host, uint16_t port, const char * url = "/", bool https = false, const char * httpsFingerprint = "");
|
||||
void begin(String host, uint16_t port, String url = "/", bool https = false, String httpsFingerprint = "");
|
||||
bool begin(String url);
|
||||
bool begin(String url, String httpsFingerprint);
|
||||
bool begin(String host, uint16_t port, String uri = "/");
|
||||
bool begin(String host, uint16_t port, String uri, String httpsFingerprint);
|
||||
// deprecated, use the overload above instead
|
||||
bool begin(String host, uint16_t port, String uri, bool https, String httpsFingerprint) __attribute__ ((deprecated));
|
||||
|
||||
void end(void);
|
||||
void end(void);
|
||||
|
||||
bool connected(void);
|
||||
bool connected(void);
|
||||
|
||||
void setReuse(bool reuse); /// keep-alive
|
||||
void setUserAgent(const char * userAgent);
|
||||
void setAuthorization(const char * user, const char * password);
|
||||
void setAuthorization(const char * auth);
|
||||
void setTimeout(uint16_t timeout);
|
||||
void setReuse(bool reuse); /// keep-alive
|
||||
void setUserAgent(const String& userAgent);
|
||||
void setAuthorization(const char * user, const char * password);
|
||||
void setAuthorization(const char * auth);
|
||||
void setTimeout(uint16_t timeout);
|
||||
|
||||
void useHTTP10(bool usehttp10 = true);
|
||||
void useHTTP10(bool usehttp10 = true);
|
||||
|
||||
/// request handling
|
||||
int GET();
|
||||
int POST(uint8_t * payload, size_t size);
|
||||
int POST(String payload);
|
||||
int sendRequest(const char * type, String payload);
|
||||
int sendRequest(const char * type, uint8_t * payload = NULL, size_t size = 0);
|
||||
int sendRequest(const char * type, Stream * stream, size_t size = 0);
|
||||
/// request handling
|
||||
int GET();
|
||||
int POST(uint8_t * payload, size_t size);
|
||||
int POST(String payload);
|
||||
int sendRequest(const char * type, String payload);
|
||||
int sendRequest(const char * type, uint8_t * payload = NULL, size_t size = 0);
|
||||
int sendRequest(const char * type, Stream * stream, size_t size = 0);
|
||||
|
||||
void addHeader(const String& name, const String& value, bool first = false);
|
||||
void addHeader(const String& name, const String& value, bool first = false);
|
||||
|
||||
/// Response handling
|
||||
void collectHeaders(const char* headerKeys[], const size_t headerKeysCount);
|
||||
String header(const char* name); // get request header value by name
|
||||
String header(size_t i); // get request header value by number
|
||||
String headerName(size_t i); // get request header name by number
|
||||
int headers(); // get header count
|
||||
bool hasHeader(const char* name); // check if header exists
|
||||
/// Response handling
|
||||
void collectHeaders(const char* headerKeys[], const size_t headerKeysCount);
|
||||
String header(const char* name); // get request header value by name
|
||||
String header(size_t i); // get request header value by number
|
||||
String headerName(size_t i); // get request header name by number
|
||||
int headers(); // get header count
|
||||
bool hasHeader(const char* name); // check if header exists
|
||||
|
||||
|
||||
int getSize(void);
|
||||
int getSize(void);
|
||||
|
||||
WiFiClient & getStream(void) __attribute__ ((deprecated)) ;
|
||||
WiFiClient * getStreamPtr(void);
|
||||
int writeToStream(Stream * stream);
|
||||
String getString(void);
|
||||
WiFiClient& getStream(void);
|
||||
WiFiClient* getStreamPtr(void);
|
||||
int writeToStream(Stream* stream);
|
||||
String getString(void);
|
||||
|
||||
static String errorToString(int error);
|
||||
static String errorToString(int error);
|
||||
|
||||
protected:
|
||||
protected:
|
||||
struct RequestArgument {
|
||||
String key;
|
||||
String value;
|
||||
};
|
||||
|
||||
struct RequestArgument {
|
||||
String key;
|
||||
String value;
|
||||
};
|
||||
void clear();
|
||||
int returnError(int error);
|
||||
bool connect(void);
|
||||
bool sendHeader(const char * type);
|
||||
int handleHeaderResponse();
|
||||
int writeToStreamDataBlock(Stream * stream, int len);
|
||||
|
||||
|
||||
WiFiClient * _tcp;
|
||||
WiFiClientSecure * _tcps;
|
||||
TransportTraitsPtr _transportTraits;
|
||||
std::unique_ptr<WiFiClient> _tcp;
|
||||
|
||||
/// request handling
|
||||
String _host;
|
||||
uint16_t _port;
|
||||
bool _reuse;
|
||||
uint16_t _tcpTimeout;
|
||||
bool _useHTTP10;
|
||||
/// request handling
|
||||
String _host;
|
||||
uint16_t _port = 0;
|
||||
bool _reuse = false;
|
||||
uint16_t _tcpTimeout = HTTPCLIENT_DEFAULT_TCP_TIMEOUT;
|
||||
bool _useHTTP10 = false;
|
||||
|
||||
String _url;
|
||||
bool _https;
|
||||
String _httpsFingerprint;
|
||||
String _uri;
|
||||
String _protocol;
|
||||
String _headers;
|
||||
String _userAgent = "ESP8266HTTPClient";
|
||||
String _base64Authorization;
|
||||
|
||||
String _Headers;
|
||||
String _userAgent;
|
||||
String _base64Authorization;
|
||||
/// Response handling
|
||||
RequestArgument* _currentHeaders = nullptr;
|
||||
size_t _headerKeysCount = 0;
|
||||
|
||||
/// Response handling
|
||||
RequestArgument* _currentHeaders;
|
||||
size_t _headerKeysCount;
|
||||
|
||||
int _returnCode;
|
||||
int _size;
|
||||
bool _canReuse;
|
||||
transferEncoding_t _transferEncoding;
|
||||
|
||||
int returnError(int error);
|
||||
bool connect(void);
|
||||
bool sendHeader(const char * type);
|
||||
int handleHeaderResponse();
|
||||
int writeToStreamDataBlock(Stream * stream, int len);
|
||||
int _returnCode = 0;
|
||||
int _size = -1;
|
||||
bool _canReuse = false;
|
||||
transferEncoding_t _transferEncoding = HTTPC_TE_IDENTITY;
|
||||
};
|
||||
|
||||
|
||||
|
@ -138,14 +138,28 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
|
||||
|
||||
if (!isForm){
|
||||
if (searchStr != "") searchStr += '&';
|
||||
//some clients send headers first and data after (like we do)
|
||||
//give them a chance
|
||||
int tries = 100;//100ms max wait
|
||||
while(!client.available() && tries--)delay(1);
|
||||
size_t plainLen = client.available();
|
||||
char *plainBuf = (char*)malloc(plainLen+1);
|
||||
client.readBytes(plainBuf, plainLen);
|
||||
plainBuf[plainLen] = '\0';
|
||||
char *plainBuf = nullptr;
|
||||
size_t plainLen = 0;
|
||||
do
|
||||
{
|
||||
//some clients send headers first and data after (like we do)
|
||||
//give them a chance
|
||||
int tries = 1000;//1000ms max wait
|
||||
size_t newLen;
|
||||
while( !(newLen = client.available()) && tries--) delay(1);
|
||||
if (!newLen) break;
|
||||
plainBuf = (plainBuf == nullptr) ? (char *) malloc(newLen + 1) : (char *) realloc(plainBuf, plainLen + newLen + 1);
|
||||
client.readBytes(&plainBuf[plainLen], newLen);
|
||||
plainLen += newLen;
|
||||
plainBuf[plainLen] = '\0';
|
||||
} while (plainLen < contentLength);
|
||||
/* if data loss, exit */
|
||||
if (plainBuf == nullptr) return false;
|
||||
if (plainLen < contentLength)
|
||||
{
|
||||
free(plainBuf);
|
||||
return false;
|
||||
}
|
||||
#ifdef DEBUG_ESP_HTTP_SERVER
|
||||
DEBUG_OUTPUT.print("Plain: ");
|
||||
DEBUG_OUTPUT.println(plainBuf);
|
||||
|
@ -89,13 +89,13 @@ bool ESP8266WiFiAPClass::softAP(const char* ssid, const char* passphrase, int ch
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!ssid || *ssid == 0 || strlen(ssid) > 31) {
|
||||
if(!ssid || strlen(ssid) == 0 || strlen(ssid) > 31) {
|
||||
// fail SSID too long or missing!
|
||||
DEBUG_WIFI("[AP] SSID too long or missing!\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(passphrase && (strlen(passphrase) > 63 || strlen(passphrase) < 8)) {
|
||||
if(passphrase && strlen(passphrase) > 0 && (strlen(passphrase) > 63 || strlen(passphrase) < 8)) {
|
||||
// fail passphrase to long or short!
|
||||
DEBUG_WIFI("[AP] fail passphrase to long or short!\n");
|
||||
return false;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
ESP8266WiFiAP.h - esp8266 Wifi support.
|
||||
Based on WiFi.h from Ardiono WiFi shield library.
|
||||
Based on WiFi.h from Arduino WiFi shield library.
|
||||
Copyright (c) 2011-2014 Arduino. All right reserved.
|
||||
Modified by Ivan Grokhotkov, December 2014
|
||||
Reworked by Markus Sattler, December 2015
|
||||
|
@ -106,7 +106,7 @@ wl_status_t ESP8266WiFiSTAClass::begin(const char* ssid, const char *passphrase,
|
||||
return WL_CONNECT_FAILED;
|
||||
}
|
||||
|
||||
if(passphrase && strlen(passphrase) > 63) {
|
||||
if(passphrase && strlen(passphrase) > 64) {
|
||||
// fail passphrase too long!
|
||||
return WL_CONNECT_FAILED;
|
||||
}
|
||||
@ -115,7 +115,10 @@ wl_status_t ESP8266WiFiSTAClass::begin(const char* ssid, const char *passphrase,
|
||||
strcpy(reinterpret_cast<char*>(conf.ssid), ssid);
|
||||
|
||||
if(passphrase) {
|
||||
strcpy(reinterpret_cast<char*>(conf.password), passphrase);
|
||||
if (strlen(passphrase) == 64) // it's not a passphrase, is the PSK
|
||||
memcpy(reinterpret_cast<char*>(conf.password), passphrase, 64);
|
||||
else
|
||||
strcpy(reinterpret_cast<char*>(conf.password), passphrase);
|
||||
} else {
|
||||
*conf.password = 0;
|
||||
}
|
||||
|
@ -1,81 +0,0 @@
|
||||
#ifndef __MEM_MANAGER_H__
|
||||
#define __MEM_MANAGER_H__
|
||||
|
||||
#include "c_types.h"
|
||||
|
||||
/*------------------------<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>------------------------*/
|
||||
|
||||
#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE
|
||||
#ifndef IOT_SIP_MODE
|
||||
//#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 0x3fffc000 - (uint32)&_heap_start ) )//fix 16000 to 24000 on 14.2.26
|
||||
#else
|
||||
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 8000 ) )
|
||||
#endif
|
||||
#define portBYTE_ALIGNMENT 8
|
||||
#define pdFALSE 0
|
||||
#define pdTRUE 1
|
||||
|
||||
#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE
|
||||
#if portBYTE_ALIGNMENT == 8
|
||||
#define portBYTE_ALIGNMENT_MASK ( 0x0007 )
|
||||
#endif
|
||||
|
||||
#if portBYTE_ALIGNMENT == 4
|
||||
#define portBYTE_ALIGNMENT_MASK ( 0x0003 )
|
||||
#endif
|
||||
|
||||
#if portBYTE_ALIGNMENT == 2
|
||||
#define portBYTE_ALIGNMENT_MASK ( 0x0001 )
|
||||
#endif
|
||||
|
||||
#if portBYTE_ALIGNMENT == 1
|
||||
#define portBYTE_ALIGNMENT_MASK ( 0x0000 )
|
||||
#endif
|
||||
|
||||
#ifndef portBYTE_ALIGNMENT_MASK
|
||||
#error "Invalid portBYTE_ALIGNMENT definition"
|
||||
#endif
|
||||
|
||||
#define configUSE_MALLOC_FAILED_HOOK 1
|
||||
#define portPOINTER_SIZE_TYPE unsigned int
|
||||
|
||||
#define heapMINIMUM_BLOCK_SIZE ( ( size_t ) ( heapSTRUCT_SIZE * 2 ) )
|
||||
|
||||
//#define configADJUSTED_HEAP_SIZE ( configTOTAL_HEAP_SIZE - portBYTE_ALIGNMENT )
|
||||
|
||||
//static unsigned char ucHeap[ configTOTAL_HEAP_SIZE ];
|
||||
//static unsigned char *ucHeap;
|
||||
|
||||
typedef struct A_BLOCK_LINK
|
||||
{
|
||||
struct A_BLOCK_LINK *pxNextFreeBlock; //The next free block in the list.
|
||||
size_t xBlockSize; //The size of the free block.
|
||||
} xBlockLink;
|
||||
|
||||
static const unsigned short heapSTRUCT_SIZE = ( sizeof( xBlockLink ) + portBYTE_ALIGNMENT - ( sizeof( xBlockLink ) % portBYTE_ALIGNMENT ) );
|
||||
|
||||
//static const size_t xTotalHeapSize = ( ( size_t ) configADJUSTED_HEAP_SIZE ) & ( ( size_t ) ~portBYTE_ALIGNMENT_MASK );
|
||||
|
||||
//static xBlockLink xStart, *pxEnd = NULL;
|
||||
|
||||
//static size_t xFreeBytesRemaining = ( ( size_t ) configADJUSTED_HEAP_SIZE ) & ( ( size_t ) ~portBYTE_ALIGNMENT_MASK );
|
||||
|
||||
|
||||
/*------------------------<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-----------------------------------*/
|
||||
|
||||
//static void prvInsertBlockIntoFreeList( xBlockLink *pxBlockToInsert ) ;//ICACHE_FLASH_ATTR;
|
||||
|
||||
//static void prvHeapInit( void ) ;//ICACHE_FLASH_ATTR;
|
||||
|
||||
void vApplicationMallocFailedHook( void ) ;//ICACHE_FLASH_ATTR;
|
||||
|
||||
void *pvPortMalloc( size_t xWantedSize, const char* file, int line ) __attribute__((malloc, alloc_size(1)));//ICACHE_FLASH_ATTR;
|
||||
|
||||
void vPortFree( void *pv, const char* file, int line ) ;//ICACHE_FLASH_ATTR;
|
||||
|
||||
size_t xPortGetFreeHeapSize( void ) ;//ICACHE_FLASH_ATTR;
|
||||
|
||||
void vPortInitialiseBlocks( void ) ;//ICACHE_FLASH_ATTR;
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
#endif
|
@ -1,5 +1,5 @@
|
||||
name=ESP8266httpUpdate
|
||||
version=1.0
|
||||
version=1.1
|
||||
author=Markus Sattler
|
||||
maintainer=Markus Sattler
|
||||
sentence=Http Update for ESP8266
|
||||
|
@ -1,365 +1,387 @@
|
||||
/**
|
||||
*
|
||||
* @file ESP8266HTTPUpdate.cpp
|
||||
* @date 21.06.2015
|
||||
* @author Markus Sattler
|
||||
*
|
||||
* Copyright (c) 2015 Markus Sattler. All rights reserved.
|
||||
* This file is part of the ESP8266 Http Updater.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "ESP8266httpUpdate.h"
|
||||
#include <StreamString.h>
|
||||
|
||||
extern "C" uint32_t _SPIFFS_start;
|
||||
extern "C" uint32_t _SPIFFS_end;
|
||||
|
||||
ESP8266HTTPUpdate::ESP8266HTTPUpdate(void) {
|
||||
}
|
||||
|
||||
ESP8266HTTPUpdate::~ESP8266HTTPUpdate(void) {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param url const char *
|
||||
* @param current_version const char *
|
||||
* @param httpsFingerprint const char *
|
||||
* @return t_httpUpdate_return
|
||||
*/
|
||||
t_httpUpdate_return ESP8266HTTPUpdate::update(const char * url, const char * current_version, const char * httpsFingerprint, bool reboot) {
|
||||
HTTPClient http;
|
||||
http.begin(url, httpsFingerprint);
|
||||
return handleUpdate(&http, current_version, reboot, false);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param url const char *
|
||||
* @param current_version const char *
|
||||
* @param httpsFingerprint const char *
|
||||
* @return t_httpUpdate_return
|
||||
*/
|
||||
t_httpUpdate_return ESP8266HTTPUpdate::updateSpiffs(const char * url, const char * current_version, const char * httpsFingerprint, bool reboot) {
|
||||
HTTPClient http;
|
||||
http.begin(url, httpsFingerprint);
|
||||
return handleUpdate(&http, current_version, reboot, true);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param host const char *
|
||||
* @param port uint16_t
|
||||
* @param url const char *
|
||||
* @param current_version const char *
|
||||
* @param httpsFingerprint const char *
|
||||
* @return
|
||||
*/
|
||||
t_httpUpdate_return ESP8266HTTPUpdate::update(const char * host, uint16_t port, const char * url, const char * current_version, bool https, const char * httpsFingerprint, bool reboot) {
|
||||
HTTPClient http;
|
||||
http.begin(host, port, url, https, httpsFingerprint);
|
||||
return handleUpdate(&http, current_version, reboot, false);
|
||||
}
|
||||
|
||||
t_httpUpdate_return ESP8266HTTPUpdate::update(String host, uint16_t port, String url, String current_version, bool https, String httpsFingerprint, bool reboot) {
|
||||
HTTPClient http;
|
||||
http.begin(host, port, url, https, httpsFingerprint);
|
||||
return handleUpdate(&http, current_version.c_str(), reboot, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* return error code as int
|
||||
* @return int error code
|
||||
*/
|
||||
int ESP8266HTTPUpdate::getLastError(void){
|
||||
return lastError;
|
||||
}
|
||||
|
||||
/**
|
||||
* return error code as String
|
||||
* @return String error
|
||||
*/
|
||||
String ESP8266HTTPUpdate::getLastErrorString(void) {
|
||||
|
||||
if(lastError == 0) {
|
||||
return String(); // no error
|
||||
}
|
||||
|
||||
// error from Update class
|
||||
if(lastError > 0) {
|
||||
StreamString error;
|
||||
Update.printError(error);
|
||||
error.trim(); // remove line ending
|
||||
return "Update error: " + error;
|
||||
}
|
||||
|
||||
// error from http client
|
||||
if(lastError > -100) {
|
||||
return "HTTP error: " + HTTPClient::errorToString(lastError);
|
||||
}
|
||||
|
||||
switch(lastError) {
|
||||
case HTTP_UE_TOO_LESS_SPACE:
|
||||
return String("To less space");
|
||||
case HTTP_UE_SERVER_NOT_REPORT_SIZE:
|
||||
return String("Server not Report Size");
|
||||
case HTTP_UE_SERVER_FILE_NOT_FOUND:
|
||||
return String("File not Found (404)");
|
||||
case HTTP_UE_SERVER_FORBIDDEN:
|
||||
return String("Forbidden (403)");
|
||||
case HTTP_UE_SERVER_WRONG_HTTP_CODE:
|
||||
return String("Wrong HTTP code");
|
||||
case HTTP_UE_SERVER_FAULTY_MD5:
|
||||
return String("Faulty MD5");
|
||||
case HTTP_UE_BIN_VERIFY_HEADER_FAILED:
|
||||
return String("Verify bin header failed");
|
||||
case HTTP_UE_BIN_FOR_WRONG_FLASH:
|
||||
return String("bin for wrong flash size");
|
||||
}
|
||||
|
||||
return String();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param http HTTPClient *
|
||||
* @param current_version const char *
|
||||
* @return t_httpUpdate_return
|
||||
*/
|
||||
t_httpUpdate_return ESP8266HTTPUpdate::handleUpdate(HTTPClient * http, const char * current_version, bool reboot, bool spiffs) {
|
||||
|
||||
t_httpUpdate_return ret = HTTP_UPDATE_FAILED;
|
||||
|
||||
// use HTTP/1.0 for update since the update handler not support any transfer Encoding
|
||||
http->useHTTP10(true);
|
||||
http->setTimeout(8000);
|
||||
http->setUserAgent("ESP8266-http-Update");
|
||||
http->addHeader("x-ESP8266-STA-MAC", WiFi.macAddress());
|
||||
http->addHeader("x-ESP8266-AP-MAC", WiFi.softAPmacAddress());
|
||||
http->addHeader("x-ESP8266-free-space", String(ESP.getFreeSketchSpace()));
|
||||
http->addHeader("x-ESP8266-sketch-size", String(ESP.getSketchSize()));
|
||||
http->addHeader("x-ESP8266-chip-size", String(ESP.getFlashChipRealSize()));
|
||||
http->addHeader("x-ESP8266-sdk-version", ESP.getSdkVersion());
|
||||
|
||||
if(spiffs) {
|
||||
http->addHeader("x-ESP8266-mode", "spiffs");
|
||||
} else {
|
||||
http->addHeader("x-ESP8266-mode", "sketch");
|
||||
}
|
||||
|
||||
if(current_version && current_version[0] != 0x00) {
|
||||
http->addHeader("x-ESP8266-version", current_version);
|
||||
}
|
||||
|
||||
const char * headerkeys[] = { "x-MD5" };
|
||||
size_t headerkeyssize = sizeof(headerkeys) / sizeof(char*);
|
||||
|
||||
// track these headers
|
||||
http->collectHeaders(headerkeys, headerkeyssize);
|
||||
|
||||
|
||||
int code = http->GET();
|
||||
int len = http->getSize();
|
||||
|
||||
if(code <= 0) {
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] HTTP error: %s\n", http->errorToString(code).c_str());
|
||||
lastError = code;
|
||||
http->end();
|
||||
return HTTP_UPDATE_FAILED;
|
||||
}
|
||||
|
||||
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] Header read fin.\n");
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] Server header:\n");
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] - code: %d\n", code);
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] - len: %d\n", len);
|
||||
|
||||
if(http->hasHeader("x-MD5")) {
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] - MD5: %s\n", http->header("x-MD5").c_str());
|
||||
}
|
||||
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] ESP8266 info:\n");
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] - free Space: %d\n", ESP.getFreeSketchSpace());
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] - current Sketch Size: %d\n", ESP.getSketchSize());
|
||||
|
||||
if(current_version && current_version[0] != 0x00) {
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] - current version: %s\n", current_version);
|
||||
}
|
||||
|
||||
switch(code) {
|
||||
case HTTP_CODE_OK: ///< OK (Start Update)
|
||||
if(len > 0) {
|
||||
bool startUpdate = true;
|
||||
if(spiffs) {
|
||||
size_t spiffsSize = ((size_t) &_SPIFFS_end - (size_t) &_SPIFFS_start);
|
||||
if(len > (int) spiffsSize) {
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] spiffsSize to low (%d) needed: %d\n", spiffsSize, len);
|
||||
startUpdate = false;
|
||||
}
|
||||
} else {
|
||||
if(len > (int) ESP.getFreeSketchSpace()) {
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] FreeSketchSpace to low (%d) needed: %d\n", ESP.getFreeSketchSpace(), len);
|
||||
startUpdate = false;
|
||||
}
|
||||
}
|
||||
|
||||
if(!startUpdate) {
|
||||
lastError = HTTP_UE_TOO_LESS_SPACE;
|
||||
ret = HTTP_UPDATE_FAILED;
|
||||
} else {
|
||||
|
||||
WiFiClient * tcp = http->getStreamPtr();
|
||||
|
||||
WiFiUDP::stopAll();
|
||||
WiFiClient::stopAllExcept(tcp);
|
||||
|
||||
delay(100);
|
||||
|
||||
int command;
|
||||
|
||||
if(spiffs) {
|
||||
command = U_SPIFFS;
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] runUpdate spiffs...\n");
|
||||
} else {
|
||||
command = U_FLASH;
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] runUpdate flash...\n");
|
||||
}
|
||||
|
||||
if(!spiffs) {
|
||||
uint8_t buf[4];
|
||||
if(tcp->peekBytes(&buf[0], 4) != 4) {
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] peekBytes magic header failed\n");
|
||||
lastError = HTTP_UE_BIN_VERIFY_HEADER_FAILED;
|
||||
http->end();
|
||||
return HTTP_UPDATE_FAILED;
|
||||
}
|
||||
|
||||
// check for valid first magic byte
|
||||
if(buf[0] != 0xE9) {
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] magic header not starts with 0xE9\n");
|
||||
lastError = HTTP_UE_BIN_VERIFY_HEADER_FAILED;
|
||||
http->end();
|
||||
return HTTP_UPDATE_FAILED;
|
||||
|
||||
}
|
||||
|
||||
uint32_t bin_flash_size = ESP.magicFlashChipSize((buf[3] & 0xf0) >> 4);
|
||||
|
||||
// check if new bin fits to SPI flash
|
||||
if(bin_flash_size > ESP.getFlashChipRealSize()) {
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] magic header, new bin not fits SPI Flash\n");
|
||||
lastError = HTTP_UE_BIN_FOR_WRONG_FLASH;
|
||||
http->end();
|
||||
return HTTP_UPDATE_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
if(runUpdate(*tcp, len, http->header("x-MD5"), command)) {
|
||||
ret = HTTP_UPDATE_OK;
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] Update ok\n");
|
||||
http->end();
|
||||
|
||||
if(reboot) {
|
||||
ESP.restart();
|
||||
}
|
||||
|
||||
} else {
|
||||
ret = HTTP_UPDATE_FAILED;
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] Update failed\n");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
lastError = HTTP_UE_SERVER_NOT_REPORT_SIZE;
|
||||
ret = HTTP_UPDATE_FAILED;
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] Content-Length is 0 or not set by Server?!\n");
|
||||
}
|
||||
break;
|
||||
case HTTP_CODE_NOT_MODIFIED:
|
||||
///< Not Modified (No updates)
|
||||
ret = HTTP_UPDATE_NO_UPDATES;
|
||||
break;
|
||||
case HTTP_CODE_NOT_FOUND:
|
||||
lastError = HTTP_UE_SERVER_FILE_NOT_FOUND;
|
||||
ret = HTTP_UPDATE_FAILED;
|
||||
break;
|
||||
case HTTP_CODE_FORBIDDEN:
|
||||
lastError = HTTP_UE_SERVER_FORBIDDEN;
|
||||
ret = HTTP_UPDATE_FAILED;
|
||||
break;
|
||||
default:
|
||||
lastError = HTTP_UE_SERVER_WRONG_HTTP_CODE;
|
||||
ret = HTTP_UPDATE_FAILED;
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] HTTP Code is (%d)\n", code);
|
||||
//http->writeToStream(&Serial1);
|
||||
break;
|
||||
}
|
||||
|
||||
http->end();
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* write Update to flash
|
||||
* @param in Stream&
|
||||
* @param size uint32_t
|
||||
* @param md5 String
|
||||
* @return true if Update ok
|
||||
*/
|
||||
bool ESP8266HTTPUpdate::runUpdate(Stream& in, uint32_t size, String md5, int command) {
|
||||
|
||||
StreamString error;
|
||||
|
||||
if(!Update.begin(size, command)) {
|
||||
lastError = Update.getError();
|
||||
Update.printError(error);
|
||||
error.trim(); // remove line ending
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] Update.begin failed! (%s)\n", error.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if(md5.length()) {
|
||||
if(!Update.setMD5(md5.c_str())) {
|
||||
lastError = HTTP_UE_SERVER_FAULTY_MD5;
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] Update.setMD5 failed! (%s)\n", md5.c_str());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if(Update.writeStream(in) != size) {
|
||||
lastError = Update.getError();
|
||||
Update.printError(error);
|
||||
error.trim(); // remove line ending
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] Update.writeStream failed! (%s)\n", error.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!Update.end()) {
|
||||
lastError = Update.getError();
|
||||
Update.printError(error);
|
||||
error.trim(); // remove line ending
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] Update.end failed! (%s)\n", error.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
ESP8266HTTPUpdate ESPhttpUpdate;
|
||||
/**
|
||||
*
|
||||
* @file ESP8266HTTPUpdate.cpp
|
||||
* @date 21.06.2015
|
||||
* @author Markus Sattler
|
||||
*
|
||||
* Copyright (c) 2015 Markus Sattler. All rights reserved.
|
||||
* This file is part of the ESP8266 Http Updater.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "ESP8266httpUpdate.h"
|
||||
#include <StreamString.h>
|
||||
|
||||
extern "C" uint32_t _SPIFFS_start;
|
||||
extern "C" uint32_t _SPIFFS_end;
|
||||
|
||||
ESP8266HTTPUpdate::ESP8266HTTPUpdate(void)
|
||||
{
|
||||
}
|
||||
|
||||
ESP8266HTTPUpdate::~ESP8266HTTPUpdate(void)
|
||||
{
|
||||
}
|
||||
|
||||
HTTPUpdateResult ESP8266HTTPUpdate::update(const String& url, const String& currentVersion,
|
||||
const String& httpsFingerprint, bool reboot)
|
||||
{
|
||||
rebootOnUpdate(reboot);
|
||||
return update(url, currentVersion, httpsFingerprint);
|
||||
}
|
||||
|
||||
HTTPUpdateResult ESP8266HTTPUpdate::update(const String& url, const String& currentVersion)
|
||||
{
|
||||
HTTPClient http;
|
||||
http.begin(url);
|
||||
return handleUpdate(http, currentVersion, false);
|
||||
}
|
||||
|
||||
HTTPUpdateResult ESP8266HTTPUpdate::update(const String& url, const String& currentVersion,
|
||||
const String& httpsFingerprint)
|
||||
{
|
||||
HTTPClient http;
|
||||
http.begin(url, httpsFingerprint);
|
||||
return handleUpdate(http, currentVersion, false);
|
||||
}
|
||||
|
||||
HTTPUpdateResult ESP8266HTTPUpdate::updateSpiffs(const String& url, const String& currentVersion, const String& httpsFingerprint)
|
||||
{
|
||||
HTTPClient http;
|
||||
http.begin(url, httpsFingerprint);
|
||||
return handleUpdate(http, currentVersion, true);
|
||||
}
|
||||
|
||||
HTTPUpdateResult ESP8266HTTPUpdate::updateSpiffs(const String& url, const String& currentVersion)
|
||||
{
|
||||
HTTPClient http;
|
||||
http.begin(url);
|
||||
return handleUpdate(http, currentVersion, true);
|
||||
}
|
||||
|
||||
HTTPUpdateResult ESP8266HTTPUpdate::update(const String& host, uint16_t port, const String& uri, const String& currentVersion,
|
||||
bool https, const String& httpsFingerprint, bool reboot)
|
||||
{
|
||||
rebootOnUpdate(reboot);
|
||||
if (httpsFingerprint.length() == 0) {
|
||||
return update(host, port, uri, currentVersion);
|
||||
} else {
|
||||
return update(host, port, uri, currentVersion, httpsFingerprint);
|
||||
}
|
||||
}
|
||||
|
||||
HTTPUpdateResult ESP8266HTTPUpdate::update(const String& host, uint16_t port, const String& uri,
|
||||
const String& currentVersion)
|
||||
{
|
||||
HTTPClient http;
|
||||
http.begin(host, port, uri);
|
||||
return handleUpdate(http, currentVersion, false);
|
||||
}
|
||||
HTTPUpdateResult ESP8266HTTPUpdate::update(const String& host, uint16_t port, const String& url,
|
||||
const String& currentVersion, const String& httpsFingerprint)
|
||||
{
|
||||
HTTPClient http;
|
||||
http.begin(host, port, url, httpsFingerprint);
|
||||
return handleUpdate(http, currentVersion, false);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* return error code as int
|
||||
* @return int error code
|
||||
*/
|
||||
int ESP8266HTTPUpdate::getLastError(void)
|
||||
{
|
||||
return _lastError;
|
||||
}
|
||||
|
||||
/**
|
||||
* return error code as String
|
||||
* @return String error
|
||||
*/
|
||||
String ESP8266HTTPUpdate::getLastErrorString(void)
|
||||
{
|
||||
|
||||
if(_lastError == 0) {
|
||||
return String(); // no error
|
||||
}
|
||||
|
||||
// error from Update class
|
||||
if(_lastError > 0) {
|
||||
StreamString error;
|
||||
Update.printError(error);
|
||||
error.trim(); // remove line ending
|
||||
return String(F("Update error: ")) + error;
|
||||
}
|
||||
|
||||
// error from http client
|
||||
if(_lastError > -100) {
|
||||
return String(F("HTTP error: ")) + HTTPClient::errorToString(_lastError);
|
||||
}
|
||||
|
||||
switch(_lastError) {
|
||||
case HTTP_UE_TOO_LESS_SPACE:
|
||||
return F("To less space");
|
||||
case HTTP_UE_SERVER_NOT_REPORT_SIZE:
|
||||
return F("Server not Report Size");
|
||||
case HTTP_UE_SERVER_FILE_NOT_FOUND:
|
||||
return F("File not Found (404)");
|
||||
case HTTP_UE_SERVER_FORBIDDEN:
|
||||
return F("Forbidden (403)");
|
||||
case HTTP_UE_SERVER_WRONG_HTTP_CODE:
|
||||
return F("Wrong HTTP code");
|
||||
case HTTP_UE_SERVER_FAULTY_MD5:
|
||||
return F("Faulty MD5");
|
||||
case HTTP_UE_BIN_VERIFY_HEADER_FAILED:
|
||||
return F("Verify bin header failed");
|
||||
case HTTP_UE_BIN_FOR_WRONG_FLASH:
|
||||
return F("bin for wrong flash size");
|
||||
}
|
||||
|
||||
return String();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param http HTTPClient *
|
||||
* @param currentVersion const char *
|
||||
* @return HTTPUpdateResult
|
||||
*/
|
||||
HTTPUpdateResult ESP8266HTTPUpdate::handleUpdate(HTTPClient& http, const String& currentVersion, bool spiffs)
|
||||
{
|
||||
|
||||
HTTPUpdateResult ret = HTTP_UPDATE_FAILED;
|
||||
|
||||
// use HTTP/1.0 for update since the update handler not support any transfer Encoding
|
||||
http.useHTTP10(true);
|
||||
http.setTimeout(8000);
|
||||
http.setUserAgent(F("ESP8266-http-Update"));
|
||||
http.addHeader(F("x-ESP8266-STA-MAC"), WiFi.macAddress());
|
||||
http.addHeader(F("x-ESP8266-AP-MAC"), WiFi.softAPmacAddress());
|
||||
http.addHeader(F("x-ESP8266-free-space"), String(ESP.getFreeSketchSpace()));
|
||||
http.addHeader(F("x-ESP8266-sketch-size"), String(ESP.getSketchSize()));
|
||||
http.addHeader(F("x-ESP8266-chip-size"), String(ESP.getFlashChipRealSize()));
|
||||
http.addHeader(F("x-ESP8266-sdk-version"), ESP.getSdkVersion());
|
||||
|
||||
if(spiffs) {
|
||||
http.addHeader(F("x-ESP8266-mode"), F("spiffs"));
|
||||
} else {
|
||||
http.addHeader(F("x-ESP8266-mode"), F("sketch"));
|
||||
}
|
||||
|
||||
if(currentVersion && currentVersion[0] != 0x00) {
|
||||
http.addHeader(F("x-ESP8266-version"), currentVersion);
|
||||
}
|
||||
|
||||
const char * headerkeys[] = { "x-MD5" };
|
||||
size_t headerkeyssize = sizeof(headerkeys) / sizeof(char*);
|
||||
|
||||
// track these headers
|
||||
http.collectHeaders(headerkeys, headerkeyssize);
|
||||
|
||||
|
||||
int code = http.GET();
|
||||
int len = http.getSize();
|
||||
|
||||
if(code <= 0) {
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] HTTP error: %s\n", http.errorToString(code).c_str());
|
||||
_lastError = code;
|
||||
http.end();
|
||||
return HTTP_UPDATE_FAILED;
|
||||
}
|
||||
|
||||
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] Header read fin.\n");
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] Server header:\n");
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] - code: %d\n", code);
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] - len: %d\n", len);
|
||||
|
||||
if(http.hasHeader("x-MD5")) {
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] - MD5: %s\n", http.header("x-MD5").c_str());
|
||||
}
|
||||
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] ESP8266 info:\n");
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] - free Space: %d\n", ESP.getFreeSketchSpace());
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] - current Sketch Size: %d\n", ESP.getSketchSize());
|
||||
|
||||
if(currentVersion && currentVersion[0] != 0x00) {
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] - current version: %s\n", currentVersion);
|
||||
}
|
||||
|
||||
switch(code) {
|
||||
case HTTP_CODE_OK: ///< OK (Start Update)
|
||||
if(len > 0) {
|
||||
bool startUpdate = true;
|
||||
if(spiffs) {
|
||||
size_t spiffsSize = ((size_t) &_SPIFFS_end - (size_t) &_SPIFFS_start);
|
||||
if(len > (int) spiffsSize) {
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] spiffsSize to low (%d) needed: %d\n", spiffsSize, len);
|
||||
startUpdate = false;
|
||||
}
|
||||
} else {
|
||||
if(len > (int) ESP.getFreeSketchSpace()) {
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] FreeSketchSpace to low (%d) needed: %d\n", ESP.getFreeSketchSpace(), len);
|
||||
startUpdate = false;
|
||||
}
|
||||
}
|
||||
|
||||
if(!startUpdate) {
|
||||
_lastError = HTTP_UE_TOO_LESS_SPACE;
|
||||
ret = HTTP_UPDATE_FAILED;
|
||||
} else {
|
||||
|
||||
WiFiClient * tcp = http.getStreamPtr();
|
||||
|
||||
WiFiUDP::stopAll();
|
||||
WiFiClient::stopAllExcept(tcp);
|
||||
|
||||
delay(100);
|
||||
|
||||
int command;
|
||||
|
||||
if(spiffs) {
|
||||
command = U_SPIFFS;
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] runUpdate spiffs...\n");
|
||||
} else {
|
||||
command = U_FLASH;
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] runUpdate flash...\n");
|
||||
}
|
||||
|
||||
if(!spiffs) {
|
||||
uint8_t buf[4];
|
||||
if(tcp->peekBytes(&buf[0], 4) != 4) {
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] peekBytes magic header failed\n");
|
||||
_lastError = HTTP_UE_BIN_VERIFY_HEADER_FAILED;
|
||||
http.end();
|
||||
return HTTP_UPDATE_FAILED;
|
||||
}
|
||||
|
||||
// check for valid first magic byte
|
||||
if(buf[0] != 0xE9) {
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] magic header not starts with 0xE9\n");
|
||||
_lastError = HTTP_UE_BIN_VERIFY_HEADER_FAILED;
|
||||
http.end();
|
||||
return HTTP_UPDATE_FAILED;
|
||||
|
||||
}
|
||||
|
||||
uint32_t bin_flash_size = ESP.magicFlashChipSize((buf[3] & 0xf0) >> 4);
|
||||
|
||||
// check if new bin fits to SPI flash
|
||||
if(bin_flash_size > ESP.getFlashChipRealSize()) {
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] magic header, new bin not fits SPI Flash\n");
|
||||
_lastError = HTTP_UE_BIN_FOR_WRONG_FLASH;
|
||||
http.end();
|
||||
return HTTP_UPDATE_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
if(runUpdate(*tcp, len, http.header("x-MD5"), command)) {
|
||||
ret = HTTP_UPDATE_OK;
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] Update ok\n");
|
||||
http.end();
|
||||
|
||||
if(_rebootOnUpdate) {
|
||||
ESP.restart();
|
||||
}
|
||||
|
||||
} else {
|
||||
ret = HTTP_UPDATE_FAILED;
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] Update failed\n");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
_lastError = HTTP_UE_SERVER_NOT_REPORT_SIZE;
|
||||
ret = HTTP_UPDATE_FAILED;
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] Content-Length is 0 or not set by Server?!\n");
|
||||
}
|
||||
break;
|
||||
case HTTP_CODE_NOT_MODIFIED:
|
||||
///< Not Modified (No updates)
|
||||
ret = HTTP_UPDATE_NO_UPDATES;
|
||||
break;
|
||||
case HTTP_CODE_NOT_FOUND:
|
||||
_lastError = HTTP_UE_SERVER_FILE_NOT_FOUND;
|
||||
ret = HTTP_UPDATE_FAILED;
|
||||
break;
|
||||
case HTTP_CODE_FORBIDDEN:
|
||||
_lastError = HTTP_UE_SERVER_FORBIDDEN;
|
||||
ret = HTTP_UPDATE_FAILED;
|
||||
break;
|
||||
default:
|
||||
_lastError = HTTP_UE_SERVER_WRONG_HTTP_CODE;
|
||||
ret = HTTP_UPDATE_FAILED;
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] HTTP Code is (%d)\n", code);
|
||||
//http.writeToStream(&Serial1);
|
||||
break;
|
||||
}
|
||||
|
||||
http.end();
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* write Update to flash
|
||||
* @param in Stream&
|
||||
* @param size uint32_t
|
||||
* @param md5 String
|
||||
* @return true if Update ok
|
||||
*/
|
||||
bool ESP8266HTTPUpdate::runUpdate(Stream& in, uint32_t size, String md5, int command)
|
||||
{
|
||||
|
||||
StreamString error;
|
||||
|
||||
if(!Update.begin(size, command)) {
|
||||
_lastError = Update.getError();
|
||||
Update.printError(error);
|
||||
error.trim(); // remove line ending
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] Update.begin failed! (%s)\n", error.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if(md5.length()) {
|
||||
if(!Update.setMD5(md5.c_str())) {
|
||||
_lastError = HTTP_UE_SERVER_FAULTY_MD5;
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] Update.setMD5 failed! (%s)\n", md5.c_str());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if(Update.writeStream(in) != size) {
|
||||
_lastError = Update.getError();
|
||||
Update.printError(error);
|
||||
error.trim(); // remove line ending
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] Update.writeStream failed! (%s)\n", error.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!Update.end()) {
|
||||
_lastError = Update.getError();
|
||||
Update.printError(error);
|
||||
error.trim(); // remove line ending
|
||||
DEBUG_HTTP_UPDATE("[httpUpdate] Update.end failed! (%s)\n", error.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
ESP8266HTTPUpdate ESPhttpUpdate;
|
||||
|
@ -1,84 +1,110 @@
|
||||
/**
|
||||
*
|
||||
* @file ESP8266HTTPUpdate.h
|
||||
* @date 21.06.2015
|
||||
* @author Markus Sattler
|
||||
*
|
||||
* Copyright (c) 2015 Markus Sattler. All rights reserved.
|
||||
* This file is part of the ESP8266 Http Updater.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef ESP8266HTTPUPDATE_H_
|
||||
#define ESP8266HTTPUPDATE_H_
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <WiFiClient.h>
|
||||
#include <WiFiUdp.h>
|
||||
#include <ESP8266HTTPClient.h>
|
||||
|
||||
#ifdef DEBUG_ESP_HTTP_UPDATE
|
||||
#ifdef DEBUG_ESP_PORT
|
||||
#define DEBUG_HTTP_UPDATE(...) DEBUG_ESP_PORT.printf( __VA_ARGS__ )
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef DEBUG_HTTP_UPDATE
|
||||
#define DEBUG_HTTP_UPDATE(...)
|
||||
#endif
|
||||
|
||||
/// note we use HTTP client errors too so we start at 100
|
||||
#define HTTP_UE_TOO_LESS_SPACE (-100)
|
||||
#define HTTP_UE_SERVER_NOT_REPORT_SIZE (-101)
|
||||
#define HTTP_UE_SERVER_FILE_NOT_FOUND (-102)
|
||||
#define HTTP_UE_SERVER_FORBIDDEN (-103)
|
||||
#define HTTP_UE_SERVER_WRONG_HTTP_CODE (-104)
|
||||
#define HTTP_UE_SERVER_FAULTY_MD5 (-105)
|
||||
#define HTTP_UE_BIN_VERIFY_HEADER_FAILED (-106)
|
||||
#define HTTP_UE_BIN_FOR_WRONG_FLASH (-107)
|
||||
|
||||
typedef enum {
|
||||
HTTP_UPDATE_FAILED,
|
||||
HTTP_UPDATE_NO_UPDATES,
|
||||
HTTP_UPDATE_OK
|
||||
} t_httpUpdate_return;
|
||||
|
||||
class ESP8266HTTPUpdate {
|
||||
public:
|
||||
ESP8266HTTPUpdate(void);
|
||||
~ESP8266HTTPUpdate(void);
|
||||
|
||||
t_httpUpdate_return update(const char * url, const char * current_version = "", const char * httpsFingerprint = "", bool reboot = true);
|
||||
t_httpUpdate_return update(const char * host, uint16_t port, const char * url = "/", const char * current_version = "", bool https = false, const char * httpsFingerprint = "", bool reboot = true);
|
||||
t_httpUpdate_return update(String host, uint16_t port, String url = "/", String current_version = "", bool https = false, String httpsFingerprint = "", bool reboot = true);
|
||||
|
||||
t_httpUpdate_return updateSpiffs(const char * url, const char * current_version = "", const char * httpsFingerprint = "", bool reboot = false);
|
||||
|
||||
int getLastError(void);
|
||||
String getLastErrorString(void);
|
||||
|
||||
protected:
|
||||
t_httpUpdate_return handleUpdate(HTTPClient * http, const char * current_version, bool reboot = true, bool spiffs = false);
|
||||
bool runUpdate(Stream& in, uint32_t size, String md5, int command = U_FLASH);
|
||||
|
||||
int lastError;
|
||||
};
|
||||
|
||||
extern ESP8266HTTPUpdate ESPhttpUpdate;
|
||||
|
||||
#endif /* ESP8266HTTPUPDATE_H_ */
|
||||
/**
|
||||
*
|
||||
* @file ESP8266HTTPUpdate.h
|
||||
* @date 21.06.2015
|
||||
* @author Markus Sattler
|
||||
*
|
||||
* Copyright (c) 2015 Markus Sattler. All rights reserved.
|
||||
* This file is part of the ESP8266 Http Updater.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef ESP8266HTTPUPDATE_H_
|
||||
#define ESP8266HTTPUPDATE_H_
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <WiFiClient.h>
|
||||
#include <WiFiUdp.h>
|
||||
#include <ESP8266HTTPClient.h>
|
||||
|
||||
#ifdef DEBUG_ESP_HTTP_UPDATE
|
||||
#ifdef DEBUG_ESP_PORT
|
||||
#define DEBUG_HTTP_UPDATE(...) DEBUG_ESP_PORT.printf( __VA_ARGS__ )
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef DEBUG_HTTP_UPDATE
|
||||
#define DEBUG_HTTP_UPDATE(...)
|
||||
#endif
|
||||
|
||||
/// note we use HTTP client errors too so we start at 100
|
||||
#define HTTP_UE_TOO_LESS_SPACE (-100)
|
||||
#define HTTP_UE_SERVER_NOT_REPORT_SIZE (-101)
|
||||
#define HTTP_UE_SERVER_FILE_NOT_FOUND (-102)
|
||||
#define HTTP_UE_SERVER_FORBIDDEN (-103)
|
||||
#define HTTP_UE_SERVER_WRONG_HTTP_CODE (-104)
|
||||
#define HTTP_UE_SERVER_FAULTY_MD5 (-105)
|
||||
#define HTTP_UE_BIN_VERIFY_HEADER_FAILED (-106)
|
||||
#define HTTP_UE_BIN_FOR_WRONG_FLASH (-107)
|
||||
|
||||
enum HTTPUpdateResult {
|
||||
HTTP_UPDATE_FAILED,
|
||||
HTTP_UPDATE_NO_UPDATES,
|
||||
HTTP_UPDATE_OK
|
||||
};
|
||||
|
||||
typedef HTTPUpdateResult t_httpUpdate_return; // backward compatibility
|
||||
|
||||
class ESP8266HTTPUpdate
|
||||
{
|
||||
public:
|
||||
ESP8266HTTPUpdate(void);
|
||||
~ESP8266HTTPUpdate(void);
|
||||
|
||||
void rebootOnUpdate(bool reboot)
|
||||
{
|
||||
_rebootOnUpdate = reboot;
|
||||
}
|
||||
|
||||
// This function is deprecated, use rebootOnUpdate and the next one instead
|
||||
t_httpUpdate_return update(const String& url, const String& currentVersion,
|
||||
const String& httpsFingerprint, bool reboot) __attribute__((deprecated));
|
||||
t_httpUpdate_return update(const String& url, const String& currentVersion = "");
|
||||
t_httpUpdate_return update(const String& url, const String& currentVersion,
|
||||
const String& httpsFingerprint);
|
||||
|
||||
// This function is deprecated, use one of the overloads below along with rebootOnUpdate
|
||||
t_httpUpdate_return update(const String& host, uint16_t port, const String& uri, const String& currentVersion,
|
||||
bool https, const String& httpsFingerprint, bool reboot) __attribute__((deprecated));
|
||||
|
||||
t_httpUpdate_return update(const String& host, uint16_t port, const String& uri = "/",
|
||||
const String& currentVersion = "");
|
||||
t_httpUpdate_return update(const String& host, uint16_t port, const String& url,
|
||||
const String& currentVersion, const String& httpsFingerprint);
|
||||
|
||||
// This function is deprecated, use rebootOnUpdate and the next one instead
|
||||
t_httpUpdate_return updateSpiffs(const String& url, const String& currentVersion,
|
||||
const String& httpsFingerprint, bool reboot) __attribute__((deprecated));
|
||||
t_httpUpdate_return updateSpiffs(const String& url, const String& currentVersion = "");
|
||||
t_httpUpdate_return updateSpiffs(const String& url, const String& currentVersion, const String& httpsFingerprint);
|
||||
|
||||
|
||||
int getLastError(void);
|
||||
String getLastErrorString(void);
|
||||
|
||||
protected:
|
||||
t_httpUpdate_return handleUpdate(HTTPClient& http, const String& currentVersion, bool spiffs = false);
|
||||
bool runUpdate(Stream& in, uint32_t size, String md5, int command = U_FLASH);
|
||||
|
||||
int _lastError;
|
||||
bool _rebootOnUpdate = true;
|
||||
};
|
||||
|
||||
extern ESP8266HTTPUpdate ESPhttpUpdate;
|
||||
|
||||
#endif /* ESP8266HTTPUPDATE_H_ */
|
||||
|
@ -34,7 +34,9 @@ License (MIT license):
|
||||
// - Multicast DNS: http://www.ietf.org/rfc/rfc6762.txt
|
||||
// - MDNS-SD: https://tools.ietf.org/html/rfc6763
|
||||
|
||||
#ifndef LWIP_OPEN_SRC
|
||||
#define LWIP_OPEN_SRC
|
||||
#endif
|
||||
|
||||
#include "ESP8266mDNS.h"
|
||||
#include <functional>
|
||||
|
@ -246,13 +246,13 @@ uint16_t SPIClass::transfer16(uint16_t data) {
|
||||
in.val = data;
|
||||
|
||||
if((SPI1C & (SPICWBO | SPICRBO))) {
|
||||
//MSBFIRST
|
||||
out.msb = transfer(in.msb);
|
||||
out.lsb = transfer(in.lsb);
|
||||
} else {
|
||||
//LSBFIRST
|
||||
out.lsb = transfer(in.lsb);
|
||||
out.msb = transfer(in.msb);
|
||||
} else {
|
||||
//MSBFIRST
|
||||
out.msb = transfer(in.msb);
|
||||
out.lsb = transfer(in.lsb);
|
||||
}
|
||||
return out.val;
|
||||
}
|
||||
|
@ -126,6 +126,13 @@
|
||||
"archiveFileName": "esptool-0.4.8-linux32.tar.gz",
|
||||
"checksum": "SHA-256:b0d6e71e6f41d4ed7e167bb4b3f4f0b1b3e49d69af50ab7fbe952cbfed83f164",
|
||||
"size": "15444"
|
||||
},
|
||||
{
|
||||
"host": "arm-linux-gnueabihf",
|
||||
"url": "https://github.com/igrr/esptool-ck/releases/download/0.4.8/esptool-0.4.8-linux-armhf.tar.gz",
|
||||
"archiveFileName": "esptool-0.4.8-linux-armhf.tar.gz",
|
||||
"checksum": "SHA-256:e9c4dfb81781610556a6af0377c8efc7cde359e0e2cda2fd48e0a32bae10f506",
|
||||
"size": "13630"
|
||||
}
|
||||
]
|
||||
},
|
||||
@ -167,6 +174,13 @@
|
||||
"archiveFileName": "linux32-xtensa-lx106-elf.tar.gz",
|
||||
"checksum": "SHA-256:b24817819f0078fb05895a640e806e0aca9aa96b47b80d2390ac8e2d9ddc955a",
|
||||
"size": "32734156"
|
||||
},
|
||||
{
|
||||
"host": "arm-linux-gnueabihf",
|
||||
"url": "http://arduino.esp8266.com/linuxarm-xtensa-lx106-elf-g46f160f.tar.gz",
|
||||
"archiveFileName": "linuxarm-xtensa-lx106-elf-g46f160f.tar.gz",
|
||||
"checksum": "SHA-256:1ac752bac7fff6be95ce10f56689f155fefea09e4ef710dbd75cb573798ff9c0",
|
||||
"size": "34929527"
|
||||
}
|
||||
]
|
||||
},
|
||||
@ -208,6 +222,13 @@
|
||||
"archiveFileName": "mkspiffs-0.1.2-linux32.tar.gz",
|
||||
"checksum": "SHA-256:e990d545dfcae308aabaac5fa9e1db734cc2b08167969e7eedac88bd0839667c",
|
||||
"size": "45272"
|
||||
},
|
||||
{
|
||||
"host": "arm-linux-gnueabihf",
|
||||
"url": "https://github.com/igrr/mkspiffs/releases/download/0.1.2/mkspiffs-0.1.2-linux-armhf.tar.gz",
|
||||
"archiveFileName": "mkspiffs-0.1.2-linux-armhf.tar.gz",
|
||||
"checksum": "SHA-256:5a8836932cd24325d69054cebdd46359eba02919ffaa87b130c54acfecc13f46",
|
||||
"size": "41685"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
12
platform.txt
12
platform.txt
@ -6,7 +6,7 @@
|
||||
# https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5---3rd-party-Hardware-specification
|
||||
|
||||
name=ESP8266 Modules
|
||||
version=2.1.0
|
||||
version=2.2.0
|
||||
|
||||
runtime.tools.xtensa-lx106-elf-gcc.path={runtime.platform.path}/tools/xtensa-lx106-elf
|
||||
runtime.tools.esptool.path={runtime.platform.path}/tools/esptool
|
||||
@ -19,7 +19,7 @@ compiler.warning_flags.all=-Wall -Wextra
|
||||
|
||||
compiler.path={runtime.tools.xtensa-lx106-elf-gcc.path}/bin/
|
||||
compiler.sdk.path={runtime.platform.path}/tools/sdk
|
||||
compiler.cpreprocessor.flags=-D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-I{compiler.sdk.path}/include"
|
||||
compiler.cpreprocessor.flags=-D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-I{compiler.sdk.path}/include" "-I{compiler.sdk.path}/lwip/include"
|
||||
|
||||
compiler.c.cmd=xtensa-lx106-elf-gcc
|
||||
compiler.c.flags=-c {compiler.warning_flags} -Os -g -Wpointer-arith -Wno-implicit-function-declaration -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -falign-functions=4 -MMD -std=gnu99 -ffunction-sections -fdata-sections
|
||||
@ -30,7 +30,7 @@ compiler.S.flags=-c -g -x assembler-with-cpp -MMD -mlongcalls
|
||||
compiler.c.elf.flags=-g {compiler.warning_flags} -Os -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static "-L{compiler.sdk.path}/lib" "-L{compiler.sdk.path}/ld" "-T{build.flash_ld}" -Wl,--gc-sections -Wl,-wrap,system_restart_local -Wl,-wrap,register_chipv6_phy
|
||||
|
||||
compiler.c.elf.cmd=xtensa-lx106-elf-gcc
|
||||
compiler.c.elf.libs=-lm -lgcc -lhal -lphy -lpp -lnet80211 -llwip -lwpa -lcrypto -lmain -lwps -laxtls -lsmartconfig -lmesh -lwpa2
|
||||
compiler.c.elf.libs=-lm -lgcc -lhal -lphy -lpp -lnet80211 -lwpa -lcrypto -lmain -lwps -laxtls -lsmartconfig -lmesh -lwpa2 {build.lwip_lib}
|
||||
|
||||
compiler.cpp.cmd=xtensa-lx106-elf-g++
|
||||
compiler.cpp.flags=-c {compiler.warning_flags} -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11 -MMD -ffunction-sections -fdata-sections
|
||||
@ -61,13 +61,13 @@ compiler.objcopy.eep.extra_flags=
|
||||
compiler.elf2hex.extra_flags=
|
||||
|
||||
## Compile c files
|
||||
recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.cpreprocessor.flags} {compiler.c.flags} -DF_CPU={build.f_cpu} {build.debug_port} {build.debug_level} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"
|
||||
recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.cpreprocessor.flags} {compiler.c.flags} -DF_CPU={build.f_cpu} {build.lwip_flags} {build.debug_port} {build.debug_level} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"
|
||||
|
||||
## Compile c++ files
|
||||
recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpreprocessor.flags} {compiler.cpp.flags} -DF_CPU={build.f_cpu} {build.debug_port} {build.debug_level} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"
|
||||
recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpreprocessor.flags} {compiler.cpp.flags} -DF_CPU={build.f_cpu} {build.lwip_flags} {build.debug_port} {build.debug_level} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"
|
||||
|
||||
## Compile S files
|
||||
recipe.S.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.cpreprocessor.flags} {compiler.S.flags} -DF_CPU={build.f_cpu} {build.debug_port} {build.debug_level} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"
|
||||
recipe.S.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.cpreprocessor.flags} {compiler.S.flags} -DF_CPU={build.f_cpu} {build.lwip_flags} {build.debug_port} {build.debug_level} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"
|
||||
|
||||
## Create archives
|
||||
recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{build.path}/arduino.ar" "{object_file}"
|
||||
|
@ -90,13 +90,16 @@ def load_tools_list(filename, platform):
|
||||
return tools_to_download
|
||||
|
||||
def identify_platform():
|
||||
arduino_platform_names = {'Darwin' : {32 : 'i386-apple-darwin', 64 : 'x86_64-apple-darwin'},
|
||||
'Linux' : {32 : 'i686-pc-linux-gnu', 64 : 'x86_64-pc-linux-gnu'},
|
||||
'Windows' : {32 : 'i686-mingw32', 64 : 'i686-mingw32'}}
|
||||
arduino_platform_names = {'Darwin' : {32 : 'i386-apple-darwin', 64 : 'x86_64-apple-darwin'},
|
||||
'Linux' : {32 : 'i686-pc-linux-gnu', 64 : 'x86_64-pc-linux-gnu'},
|
||||
'LinuxARM': {32 : 'arm-linux-gnueabihf', 64 : 'aarch64-linux-gnu'},
|
||||
'Windows' : {32 : 'i686-mingw32', 64 : 'i686-mingw32'}}
|
||||
bits = 32
|
||||
if sys.maxsize > 2**32:
|
||||
bits = 64
|
||||
sys_name = platform.system()
|
||||
if 'Linux' in sys_name and platform.platform().find('arm') > 0:
|
||||
sys_name = 'LinuxARM'
|
||||
if 'CYGWIN_NT' in sys_name:
|
||||
sys_name = 'Windows'
|
||||
return arduino_platform_names[sys_name][bits]
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
#include "c_types.h"
|
||||
#include "eagle_soc.h"
|
||||
#include <stddef.h>
|
||||
|
||||
typedef uint32_t ETSSignal;
|
||||
typedef uint32_t ETSParam;
|
||||
|
101
tools/sdk/lwip/include/lwip/app/dhcpserver.h
Normal file
101
tools/sdk/lwip/include/lwip/app/dhcpserver.h
Normal file
@ -0,0 +1,101 @@
|
||||
#ifndef __DHCPS_H__
|
||||
#define __DHCPS_H__
|
||||
|
||||
#define USE_DNS
|
||||
|
||||
typedef struct dhcps_state{
|
||||
sint16_t state;
|
||||
} dhcps_state;
|
||||
|
||||
typedef struct dhcps_msg {
|
||||
uint8_t op, htype, hlen, hops;
|
||||
uint8_t xid[4];
|
||||
uint16_t secs, flags;
|
||||
uint8_t ciaddr[4];
|
||||
uint8_t yiaddr[4];
|
||||
uint8_t siaddr[4];
|
||||
uint8_t giaddr[4];
|
||||
uint8_t chaddr[16];
|
||||
uint8_t sname[64];
|
||||
uint8_t file[128];
|
||||
uint8_t options[312];
|
||||
}dhcps_msg;
|
||||
|
||||
#ifndef LWIP_OPEN_SRC
|
||||
struct dhcps_lease {
|
||||
bool enable;
|
||||
struct ip_addr start_ip;
|
||||
struct ip_addr end_ip;
|
||||
};
|
||||
|
||||
enum dhcps_offer_option{
|
||||
OFFER_START = 0x00,
|
||||
OFFER_ROUTER = 0x01,
|
||||
OFFER_END
|
||||
};
|
||||
#endif
|
||||
|
||||
struct dhcps_pool{
|
||||
struct ip_addr ip;
|
||||
uint8 mac[6];
|
||||
uint32 lease_timer;
|
||||
};
|
||||
|
||||
typedef struct _list_node{
|
||||
void *pnode;
|
||||
struct _list_node *pnext;
|
||||
}list_node;
|
||||
|
||||
extern uint32 dhcps_lease_time;
|
||||
#define DHCPS_LEASE_TIMER dhcps_lease_time //0x05A0
|
||||
#define DHCPS_MAX_LEASE 0x64
|
||||
#define BOOTP_BROADCAST 0x8000
|
||||
|
||||
#define DHCP_REQUEST 1
|
||||
#define DHCP_REPLY 2
|
||||
#define DHCP_HTYPE_ETHERNET 1
|
||||
#define DHCP_HLEN_ETHERNET 6
|
||||
#define DHCP_MSG_LEN 236
|
||||
|
||||
#define DHCPS_SERVER_PORT 67
|
||||
#define DHCPS_CLIENT_PORT 68
|
||||
|
||||
#define DHCPDISCOVER 1
|
||||
#define DHCPOFFER 2
|
||||
#define DHCPREQUEST 3
|
||||
#define DHCPDECLINE 4
|
||||
#define DHCPACK 5
|
||||
#define DHCPNAK 6
|
||||
#define DHCPRELEASE 7
|
||||
|
||||
#define DHCP_OPTION_SUBNET_MASK 1
|
||||
#define DHCP_OPTION_ROUTER 3
|
||||
#define DHCP_OPTION_DNS_SERVER 6
|
||||
#define DHCP_OPTION_REQ_IPADDR 50
|
||||
#define DHCP_OPTION_LEASE_TIME 51
|
||||
#define DHCP_OPTION_MSG_TYPE 53
|
||||
#define DHCP_OPTION_SERVER_ID 54
|
||||
#define DHCP_OPTION_INTERFACE_MTU 26
|
||||
#define DHCP_OPTION_PERFORM_ROUTER_DISCOVERY 31
|
||||
#define DHCP_OPTION_BROADCAST_ADDRESS 28
|
||||
#define DHCP_OPTION_REQ_LIST 55
|
||||
#define DHCP_OPTION_END 255
|
||||
|
||||
//#define USE_CLASS_B_NET 1
|
||||
#define DHCPS_DEBUG 0
|
||||
#define MAX_STATION_NUM 8
|
||||
|
||||
#define DHCPS_STATE_OFFER 1
|
||||
#define DHCPS_STATE_DECLINE 2
|
||||
#define DHCPS_STATE_ACK 3
|
||||
#define DHCPS_STATE_NAK 4
|
||||
#define DHCPS_STATE_IDLE 5
|
||||
#define DHCPS_STATE_RELEASE 6
|
||||
|
||||
#define dhcps_router_enabled(offer) ((offer & OFFER_ROUTER) != 0)
|
||||
|
||||
void dhcps_start(struct ip_info *info);
|
||||
void dhcps_stop(void);
|
||||
|
||||
#endif
|
||||
|
664
tools/sdk/lwip/include/lwip/app/espconn.h
Normal file
664
tools/sdk/lwip/include/lwip/app/espconn.h
Normal file
@ -0,0 +1,664 @@
|
||||
#ifndef __ESPCONN_H__
|
||||
#define __ESPCONN_H__
|
||||
|
||||
#include "lwip/dns.h"
|
||||
#include "os_type.h"
|
||||
|
||||
#if 0
|
||||
#define espconn_printf(fmt, args...) os_printf(fmt,## args)
|
||||
#else
|
||||
#define espconn_printf(fmt, args...)
|
||||
#endif
|
||||
|
||||
|
||||
typedef void *espconn_handle;
|
||||
typedef void (* espconn_connect_callback)(void *arg);
|
||||
typedef void (* espconn_reconnect_callback)(void *arg, sint8 err);
|
||||
|
||||
/* Definitions for error constants. */
|
||||
|
||||
#define ESPCONN_OK 0 /* No error, everything OK. */
|
||||
#define ESPCONN_MEM -1 /* Out of memory error. */
|
||||
#define ESPCONN_TIMEOUT -3 /* Timeout. */
|
||||
#define ESPCONN_RTE -4 /* Routing problem. */
|
||||
#define ESPCONN_INPROGRESS -5 /* Operation in progress */
|
||||
#define ESPCONN_MAXNUM -7 /* Total number exceeds the set maximum*/
|
||||
|
||||
#define ESPCONN_ABRT -8 /* Connection aborted. */
|
||||
#define ESPCONN_RST -9 /* Connection reset. */
|
||||
#define ESPCONN_CLSD -10 /* Connection closed. */
|
||||
#define ESPCONN_CONN -11 /* Not connected. */
|
||||
|
||||
#define ESPCONN_ARG -12 /* Illegal argument. */
|
||||
#define ESPCONN_IF -14 /* Low_level error */
|
||||
#define ESPCONN_ISCONN -15 /* Already connected. */
|
||||
|
||||
#define ESPCONN_HANDSHAKE -28 /* ssl handshake failed */
|
||||
#define ESPCONN_RESP_TIMEOUT -29 /* ssl handshake no response*/
|
||||
#define ESPCONN_PROTO_MSG -61 /* ssl application invalid */
|
||||
|
||||
#define ESPCONN_SSL 0x01
|
||||
#define ESPCONN_NORM 0x00
|
||||
|
||||
#define ESPCONN_STA 0x01
|
||||
#define ESPCONN_AP 0x02
|
||||
#define ESPCONN_AP_STA 0x03
|
||||
|
||||
#define STA_NETIF 0x00
|
||||
#define AP_NETIF 0x01
|
||||
|
||||
/** Protocol family and type of the espconn */
|
||||
enum espconn_type {
|
||||
ESPCONN_INVALID = 0,
|
||||
/* ESPCONN_TCP Group */
|
||||
ESPCONN_TCP = 0x10,
|
||||
/* ESPCONN_UDP Group */
|
||||
ESPCONN_UDP = 0x20,
|
||||
};
|
||||
|
||||
/** Current state of the espconn. Non-TCP espconn are always in state ESPCONN_NONE! */
|
||||
enum espconn_state {
|
||||
ESPCONN_NONE,
|
||||
ESPCONN_WAIT,
|
||||
ESPCONN_LISTEN,
|
||||
ESPCONN_CONNECT,
|
||||
ESPCONN_WRITE,
|
||||
ESPCONN_READ,
|
||||
ESPCONN_CLOSE
|
||||
};
|
||||
|
||||
typedef struct _esp_tcp {
|
||||
int remote_port;
|
||||
int local_port;
|
||||
uint8 local_ip[4];
|
||||
uint8 remote_ip[4];
|
||||
espconn_connect_callback connect_callback;
|
||||
espconn_reconnect_callback reconnect_callback;
|
||||
espconn_connect_callback disconnect_callback;
|
||||
espconn_connect_callback write_finish_fn;
|
||||
} esp_tcp;
|
||||
|
||||
typedef struct _esp_udp {
|
||||
int remote_port;
|
||||
int local_port;
|
||||
uint8 local_ip[4];
|
||||
uint8 remote_ip[4];
|
||||
} esp_udp;
|
||||
|
||||
typedef struct _remot_info{
|
||||
enum espconn_state state;
|
||||
int remote_port;
|
||||
uint8 remote_ip[4];
|
||||
}remot_info;
|
||||
|
||||
/** A callback prototype to inform about events for a espconn */
|
||||
typedef void (* espconn_recv_callback)(void *arg, char *pdata, unsigned short len);
|
||||
typedef void (* espconn_sent_callback)(void *arg);
|
||||
|
||||
/** A espconn descriptor */
|
||||
struct espconn {
|
||||
/** type of the espconn (TCP, UDP) */
|
||||
enum espconn_type type;
|
||||
/** current state of the espconn */
|
||||
enum espconn_state state;
|
||||
union {
|
||||
esp_tcp *tcp;
|
||||
esp_udp *udp;
|
||||
} proto;
|
||||
/** A callback function that is informed about events for this espconn */
|
||||
espconn_recv_callback recv_callback;
|
||||
espconn_sent_callback sent_callback;
|
||||
uint8 link_cnt;
|
||||
void *reverse;
|
||||
};
|
||||
|
||||
enum espconn_option{
|
||||
ESPCONN_START = 0x00,
|
||||
ESPCONN_REUSEADDR = 0x01,
|
||||
ESPCONN_NODELAY = 0x02,
|
||||
ESPCONN_COPY = 0x04,
|
||||
ESPCONN_KEEPALIVE = 0x08,
|
||||
ESPCONN_END
|
||||
};
|
||||
|
||||
enum espconn_level{
|
||||
ESPCONN_KEEPIDLE,
|
||||
ESPCONN_KEEPINTVL,
|
||||
ESPCONN_KEEPCNT
|
||||
};
|
||||
|
||||
struct espconn_packet{
|
||||
uint16 sent_length; /* sent length successful*/
|
||||
uint16 snd_buf_size; /* Available buffer size for sending */
|
||||
uint16 snd_queuelen; /* Available buffer space for sending */
|
||||
uint16 total_queuelen; /* total Available buffer space for sending */
|
||||
uint32 packseqno; /* seqno to be sent */
|
||||
uint32 packseq_nxt; /* seqno expected */
|
||||
uint32 packnum;
|
||||
};
|
||||
|
||||
typedef struct _espconn_buf{
|
||||
uint8 *payload;
|
||||
uint8 *punsent;
|
||||
uint16 unsent;
|
||||
uint16 len;
|
||||
uint16 tot_len;
|
||||
struct _espconn_buf *pnext;
|
||||
} espconn_buf;
|
||||
|
||||
typedef struct _comon_pkt{
|
||||
void *pcb;
|
||||
int remote_port;
|
||||
uint8 remote_ip[4];
|
||||
uint32 local_port;
|
||||
uint32 local_ip;
|
||||
espconn_buf *pbuf;
|
||||
espconn_buf *ptail;
|
||||
uint8* ptrbuf;
|
||||
uint16 cntr;
|
||||
sint8 err;
|
||||
uint32 timeout;
|
||||
uint32 recv_check;
|
||||
uint8 pbuf_num;
|
||||
struct espconn_packet packet_info;
|
||||
bool write_flag;
|
||||
enum espconn_option espconn_opt;
|
||||
}comon_pkt;
|
||||
|
||||
typedef struct _espconn_msg{
|
||||
struct espconn *pespconn;
|
||||
comon_pkt pcommon;
|
||||
uint8 count_opt;
|
||||
sint16_t hs_status; //the status of the handshake
|
||||
void *preverse;
|
||||
void *pssl;
|
||||
struct _espconn_msg *pnext;
|
||||
|
||||
//***********Code for WIFI_BLOCK from upper**************
|
||||
uint8 recv_hold_flag;
|
||||
uint16 recv_holded_buf_Len;
|
||||
}espconn_msg;
|
||||
|
||||
#ifndef _MDNS_INFO
|
||||
#define _MDNS_INFO
|
||||
struct mdns_info {
|
||||
char *host_name;
|
||||
char *server_name;
|
||||
uint16 server_port;
|
||||
unsigned long ipAddr;
|
||||
char *txt_data[10];
|
||||
};
|
||||
#endif
|
||||
|
||||
#define linkMax 15
|
||||
|
||||
#define espconn_delay_disabled(espconn) (((espconn)->pcommon.espconn_opt & ESPCONN_NODELAY) != 0)
|
||||
#define espconn_delay_enabled(espconn) (((espconn)->pcommon.espconn_opt & ESPCONN_NODELAY) == 0)
|
||||
#define espconn_reuse_disabled(espconn) (((espconn)->pcommon.espconn_opt & ESPCONN_REUSEADDR) != 0)
|
||||
#define espconn_copy_disabled(espconn) (((espconn)->pcommon.espconn_opt & ESPCONN_COPY) != 0)
|
||||
#define espconn_copy_enabled(espconn) (((espconn)->pcommon.espconn_opt & ESPCONN_COPY) == 0)
|
||||
#define espconn_keepalive_disabled(espconn) (((espconn)->pcommon.espconn_opt & ESPCONN_KEEPALIVE) != 0)
|
||||
#define espconn_keepalive_enabled(espconn) (((espconn)->pcommon.espconn_opt & ESPCONN_KEEPALIVE) == 0)
|
||||
|
||||
#define espconn_TaskPrio 26
|
||||
#define espconn_TaskQueueLen 15
|
||||
|
||||
enum espconn_sig {
|
||||
SIG_ESPCONN_NONE,
|
||||
SIG_ESPCONN_ERRER,
|
||||
SIG_ESPCONN_LISTEN,
|
||||
SIG_ESPCONN_CONNECT,
|
||||
SIG_ESPCONN_WRITE,
|
||||
SIG_ESPCONN_SEND,
|
||||
SIG_ESPCONN_READ,
|
||||
SIG_ESPCONN_CLOSE
|
||||
};
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_copy_partial
|
||||
* Description : reconnect with host
|
||||
* Parameters : arg -- Additional argument to pass to the callback function
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
|
||||
void espconn_copy_partial(struct espconn *pesp_dest, struct espconn *pesp_source);
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_copy_partial
|
||||
* Description : insert the node to the active connection list
|
||||
* Parameters : arg -- Additional argument to pass to the callback function
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
|
||||
void espconn_list_creat(espconn_msg **phead, espconn_msg* pinsert);
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_list_delete
|
||||
* Description : remove the node from the active connection list
|
||||
* Parameters : arg -- Additional argument to pass to the callback function
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
|
||||
void espconn_list_delete(espconn_msg **phead, espconn_msg* pdelete);
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_find_connection
|
||||
* Description : Initialize the server: set up a listening PCB and bind it to
|
||||
* the defined port
|
||||
* Parameters : espconn -- the espconn used to build server
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
|
||||
bool espconn_find_connection(struct espconn *pespconn, espconn_msg **pnode);
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_get_connection_info
|
||||
* Description : used to specify the function that should be called when disconnect
|
||||
* Parameters : espconn -- espconn to set the err callback
|
||||
* discon_cb -- err callback function to call when err
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
|
||||
sint8 espconn_get_connection_info(struct espconn *pespconn, remot_info **pcon_info, uint8 typeflags);
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_get_packet_info
|
||||
* Description : get the packet info with host
|
||||
* Parameters : espconn -- the espconn used to disconnect the connection
|
||||
* infoarg -- the packet info
|
||||
* Returns : the errur code
|
||||
*******************************************************************************/
|
||||
|
||||
sint8 espconn_get_packet_info(struct espconn *espconn, struct espconn_packet* infoarg);
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_connect
|
||||
* Description : The function given as the connect
|
||||
* Parameters : espconn -- the espconn used to listen the connection
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
|
||||
extern sint8 espconn_connect(struct espconn *espconn);
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_disconnect
|
||||
* Description : disconnect with host
|
||||
* Parameters : espconn -- the espconn used to disconnect the connection
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
|
||||
extern sint8 espconn_disconnect(struct espconn *espconn);
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_delete
|
||||
* Description : disconnect with host
|
||||
* Parameters : espconn -- the espconn used to disconnect the connection
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
|
||||
extern sint8 espconn_delete(struct espconn *espconn);
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_accept
|
||||
* Description : The function given as the listen
|
||||
* Parameters : espconn -- the espconn used to listen the connection
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
|
||||
extern sint8 espconn_accept(struct espconn *espconn);
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_create
|
||||
* Description : sent data for client or server
|
||||
* Parameters : espconn -- espconn to the data transmission
|
||||
* Returns : result
|
||||
*******************************************************************************/
|
||||
|
||||
extern sint8 espconn_create(struct espconn *espconn);
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_tcp_get_wnd
|
||||
* Description : get the window size of simulatenously active TCP connections
|
||||
* Parameters : none
|
||||
* Returns : the number of TCP_MSS active TCP connections
|
||||
*******************************************************************************/
|
||||
extern uint8 espconn_tcp_get_wnd(void);
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_tcp_set_max_con
|
||||
* Description : set the window size simulatenously active TCP connections
|
||||
* Parameters : num -- the number of TCP_MSS
|
||||
* Returns : ESPCONN_ARG -- Illegal argument
|
||||
* ESPCONN_OK -- No error
|
||||
*******************************************************************************/
|
||||
extern sint8 espconn_tcp_set_wnd(uint8 num);
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_tcp_get_max_con
|
||||
* Description : get the number of simulatenously active TCP connections
|
||||
* Parameters : none
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
|
||||
extern uint8 espconn_tcp_get_max_con(void);
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_tcp_set_max_con
|
||||
* Description : set the number of simulatenously active TCP connections
|
||||
* Parameters : num -- total number
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
|
||||
extern sint8 espconn_tcp_set_max_con(uint8 num);
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_tcp_get_max_retran
|
||||
* Description : get the Maximum number of retransmissions of data active TCP connections
|
||||
* Parameters : none
|
||||
* Returns : the Maximum number of retransmissions
|
||||
*******************************************************************************/
|
||||
extern uint8 espconn_tcp_get_max_retran(void);
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_tcp_set_max_retran
|
||||
* Description : set the Maximum number of retransmissions of data active TCP connections
|
||||
* Parameters : num -- the Maximum number of retransmissions
|
||||
* Returns : result
|
||||
*******************************************************************************/
|
||||
|
||||
extern sint8 espconn_tcp_set_max_retran(uint8 num);
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_tcp_get_max_syn
|
||||
* Description : get the Maximum number of retransmissions of SYN segments
|
||||
* Parameters : none
|
||||
* Returns : the Maximum number of retransmissions
|
||||
*******************************************************************************/
|
||||
|
||||
extern uint8 espconn_tcp_get_max_syn(void);
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_tcp_set_max_syn
|
||||
* Description : set the Maximum number of retransmissions of SYN segments
|
||||
* Parameters : num -- the Maximum number of retransmissions
|
||||
* Returns : result
|
||||
*******************************************************************************/
|
||||
|
||||
extern sint8 espconn_tcp_set_max_syn(uint8 num);
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_tcp_get_max_con_allow
|
||||
* Description : get the count of simulatenously active connections on the server
|
||||
* Parameters : espconn -- espconn to get the count
|
||||
* Returns : result
|
||||
*******************************************************************************/
|
||||
|
||||
extern sint8 espconn_tcp_get_max_con_allow(struct espconn *espconn);
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_tcp_set_max_con_allow
|
||||
* Description : set the count of simulatenously active connections on the server
|
||||
* Parameters : espconn -- espconn to set the count
|
||||
* Returns : result
|
||||
*******************************************************************************/
|
||||
|
||||
extern sint8 espconn_tcp_set_max_con_allow(struct espconn *espconn, uint8 num);
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_tcp_set_buf_count
|
||||
* Description : set the total number of espconn_buf on the unsent lists
|
||||
* Parameters : espconn -- espconn to set the count
|
||||
* num -- the total number of espconn_buf
|
||||
* Returns : result
|
||||
*******************************************************************************/
|
||||
|
||||
extern sint8 espconn_tcp_set_buf_count(struct espconn *espconn, uint8 num);
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_regist_time
|
||||
* Description : used to specify the time that should be called when don't recv data
|
||||
* Parameters : espconn -- the espconn used to the connection
|
||||
* interval -- the timer when don't recv data
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
|
||||
extern sint8 espconn_regist_time(struct espconn *espconn, uint32 interval, uint8 type_flag);
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_regist_sentcb
|
||||
* Description : Used to specify the function that should be called when data
|
||||
* has been successfully delivered to the remote host.
|
||||
* Parameters : struct espconn *espconn -- espconn to set the sent callback
|
||||
* espconn_sent_callback sent_cb -- sent callback function to
|
||||
* call for this espconn when data is successfully sent
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
|
||||
extern sint8 espconn_regist_sentcb(struct espconn *espconn, espconn_sent_callback sent_cb);
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_regist_sentcb
|
||||
* Description : Used to specify the function that should be called when data
|
||||
* has been successfully delivered to the remote host.
|
||||
* Parameters : espconn -- espconn to set the sent callback
|
||||
* sent_cb -- sent callback function to call for this espconn
|
||||
* when data is successfully sent
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
extern sint8 espconn_regist_write_finish(struct espconn *espconn, espconn_connect_callback write_finish_fn);
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_sent
|
||||
* Description : sent data for client or server
|
||||
* Parameters : espconn -- espconn to set for client or server
|
||||
* psent -- data to send
|
||||
* length -- length of data to send
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
|
||||
extern sint8 espconn_sent(struct espconn *espconn, uint8 *psent, uint16 length);
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_regist_connectcb
|
||||
* Description : used to specify the function that should be called when
|
||||
* connects to host.
|
||||
* Parameters : espconn -- espconn to set the connect callback
|
||||
* connect_cb -- connected callback function to call when connected
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
|
||||
extern sint8 espconn_regist_connectcb(struct espconn *espconn, espconn_connect_callback connect_cb);
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_regist_recvcb
|
||||
* Description : used to specify the function that should be called when recv
|
||||
* data from host.
|
||||
* Parameters : espconn -- espconn to set the recv callback
|
||||
* recv_cb -- recv callback function to call when recv data
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
|
||||
extern sint8 espconn_regist_recvcb(struct espconn *espconn, espconn_recv_callback recv_cb);
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_regist_reconcb
|
||||
* Description : used to specify the function that should be called when connection
|
||||
* because of err disconnect.
|
||||
* Parameters : espconn -- espconn to set the err callback
|
||||
* recon_cb -- err callback function to call when err
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
|
||||
extern sint8 espconn_regist_reconcb(struct espconn *espconn, espconn_reconnect_callback recon_cb);
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_regist_disconcb
|
||||
* Description : used to specify the function that should be called when disconnect
|
||||
* Parameters : espconn -- espconn to set the err callback
|
||||
* discon_cb -- err callback function to call when err
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
|
||||
extern sint8 espconn_regist_disconcb(struct espconn *espconn, espconn_connect_callback discon_cb);
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_port
|
||||
* Description : access port value for client so that we don't end up bouncing
|
||||
* all connections at the same time .
|
||||
* Parameters : none
|
||||
* Returns : access port value
|
||||
*******************************************************************************/
|
||||
|
||||
extern uint32 espconn_port(void);
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_set_opt
|
||||
* Description : access port value for client so that we don't end up bouncing
|
||||
* all connections at the same time .
|
||||
* Parameters : none
|
||||
* Returns : access port value
|
||||
*******************************************************************************/
|
||||
extern sint8 espconn_set_opt(struct espconn *espconn, uint8 opt);
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_set_keepalive
|
||||
* Description : access level value for connection so that we set the value for
|
||||
* keep alive
|
||||
* Parameters : espconn -- the espconn used to set the connection
|
||||
* level -- the connection's level
|
||||
* value -- the value of time(s)
|
||||
* Returns : access port value
|
||||
*******************************************************************************/
|
||||
extern sint8 espconn_set_keepalive(struct espconn *espconn, uint8 level, void* optarg);
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_get_keepalive
|
||||
* Description : access level value for connection so that we get the value for
|
||||
* keep alive
|
||||
* Parameters : espconn -- the espconn used to get the connection
|
||||
* level -- the connection's level
|
||||
* Returns : access keep alive value
|
||||
*******************************************************************************/
|
||||
extern sint8 espconn_get_keepalive(struct espconn *espconn, uint8 level, void *optarg);
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_gethostbyname
|
||||
* Description : Resolve a hostname (string) into an IP address.
|
||||
* Parameters : pespconn -- espconn to resolve a hostname
|
||||
* hostname -- the hostname that is to be queried
|
||||
* addr -- pointer to a ip_addr_t where to store the address if
|
||||
* it is already cached in the dns_table (only valid if
|
||||
* ESPCONN_OK is returned!)
|
||||
* found -- a callback function to be called on success, failure
|
||||
* or timeout (only if ERR_INPROGRESS is returned!)
|
||||
* Returns : err_t return code
|
||||
* - ESPCONN_OK if hostname is a valid IP address string or the host
|
||||
* name is already in the local names table.
|
||||
* - ESPCONN_INPROGRESS enqueue a request to be sent to the DNS server
|
||||
* for resolution if no errors are present.
|
||||
* - ESPCONN_ARG: dns client not initialized or invalid hostname
|
||||
*******************************************************************************/
|
||||
|
||||
extern sint8 espconn_gethostbyname(struct espconn *pespconn, const char *name, ip_addr_t *addr, dns_found_callback found);
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_igmp_join
|
||||
* Description : join a multicast group
|
||||
* Parameters : host_ip -- the ip address of udp server
|
||||
* multicast_ip -- multicast ip given by user
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
extern sint8 espconn_igmp_join(ip_addr_t *host_ip, ip_addr_t *multicast_ip);
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_igmp_leave
|
||||
* Description : leave a multicast group
|
||||
* Parameters : host_ip -- the ip address of udp server
|
||||
* multicast_ip -- multicast ip given by user
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
extern sint8 espconn_igmp_leave(ip_addr_t *host_ip, ip_addr_t *multicast_ip);
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_mdns_init
|
||||
* Description : register a device with mdns
|
||||
* Parameters : ipAddr -- the ip address of device
|
||||
* hostname -- the hostname of device
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
extern void espconn_mdns_init(struct mdns_info *info);
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_mdns_init
|
||||
* Description : close mdns socket
|
||||
* Parameters : void
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
extern void espconn_mdns_close(void);
|
||||
/******************************************************************************
|
||||
* FunctionName : mdns_server_register
|
||||
* Description : register a server and join a multicast group
|
||||
* Parameters : none
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
extern void espconn_mdns_server_register(void);
|
||||
/******************************************************************************
|
||||
* FunctionName : mdns_server_register
|
||||
* Description : unregister server and leave multicast group
|
||||
* Parameters : none
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
extern void espconn_mdns_server_unregister(void);
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_mdns_get_servername
|
||||
* Description : get server name
|
||||
* Parameters : none
|
||||
* Returns : server name
|
||||
*******************************************************************************/
|
||||
extern char* espconn_mdns_get_servername(void);
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_mdns_get_servername
|
||||
* Description : set server name
|
||||
* Parameters : server name
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
extern void espconn_mdns_set_servername(const char *name);
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_mdns_set_hostname
|
||||
* Description : set host name
|
||||
* Parameters : host name
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
extern void espconn_mdns_set_hostname(char *name);
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_mdns_init
|
||||
* Description : get host name
|
||||
* Parameters : void
|
||||
* Returns : hostname
|
||||
*******************************************************************************/
|
||||
extern char* espconn_mdns_get_hostname(void);
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_mdns_disable
|
||||
* Description : join a multicast group
|
||||
* Parameters : host_ip -- the ip address of udp server
|
||||
* multicast_ip -- multicast ip given by user
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
extern void espconn_mdns_disable(void);
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_mdns_enable
|
||||
* Description : enable mdns
|
||||
* Parameters : void
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
extern void espconn_mdns_enable(void);
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_dns_setserver
|
||||
* Description : Initialize one of the DNS servers.
|
||||
* Parameters : numdns -- the index of the DNS server to set must
|
||||
* be < DNS_MAX_SERVERS = 2
|
||||
* dnsserver -- IP address of the DNS server to set
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
extern void espconn_dns_setserver(u8_t numdns, ip_addr_t *dnsserver);
|
||||
#endif
|
||||
|
55
tools/sdk/lwip/include/lwip/app/espconn_tcp.h
Normal file
55
tools/sdk/lwip/include/lwip/app/espconn_tcp.h
Normal file
@ -0,0 +1,55 @@
|
||||
#ifndef __ESPCONN_TCP_H__
|
||||
#define __ESPCONN_TCP_H__
|
||||
|
||||
#ifndef ESPCONN_TCP_DEBUG
|
||||
#define ESPCONN_TCP_DEBUG LWIP_DBG_OFF
|
||||
#endif
|
||||
#include "lwip/app/espconn.h"
|
||||
|
||||
#ifndef ESPCONN_TCP_TIMER
|
||||
#define ESPCONN_TCP_TIMER 40
|
||||
#endif
|
||||
|
||||
#define espconn_keepalive_enable(pcb) ((pcb)->so_options |= SOF_KEEPALIVE)
|
||||
#define espconn_keepalive_disable(pcb) ((pcb)->so_options &= ~SOF_KEEPALIVE)
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_kill_oldest_pcb
|
||||
* Description : A oldest incoming connection has been killed.
|
||||
* Parameters : none
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
|
||||
extern void espconn_kill_oldest_pcb(void);
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_tcp_disconnect
|
||||
* Description : A new incoming connection has been disconnected.
|
||||
* Parameters : espconn -- the espconn used to disconnect with host
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
|
||||
extern void espconn_tcp_disconnect(espconn_msg *pdiscon,u8 type);
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_tcp_client
|
||||
* Description : Initialize the client: set up a connect PCB and bind it to
|
||||
* the defined port
|
||||
* Parameters : espconn -- the espconn used to build client
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
|
||||
extern sint8 espconn_tcp_client(struct espconn* espconn);
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_tcp_server
|
||||
* Description : Initialize the server: set up a listening PCB and bind it to
|
||||
* the defined port
|
||||
* Parameters : espconn -- the espconn used to build server
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
|
||||
extern sint8 espconn_tcp_server(struct espconn *espconn);
|
||||
|
||||
#endif /* __CLIENT_TCP_H__ */
|
||||
|
64
tools/sdk/lwip/include/lwip/app/espconn_udp.h
Normal file
64
tools/sdk/lwip/include/lwip/app/espconn_udp.h
Normal file
@ -0,0 +1,64 @@
|
||||
#ifndef __ESPCONN_UDP_H__
|
||||
#define __ESPCONN_UDP_H__
|
||||
|
||||
#ifndef ESPCONN_UDP_DEBUG
|
||||
#define ESPCONN_UDP_DEBUG LWIP_DBG_OFF
|
||||
#endif
|
||||
|
||||
#include "lwip/app/espconn.h"
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_udp_client
|
||||
* Description : Initialize the client: set up a PCB and bind it to the port
|
||||
* Parameters : pespconn -- the espconn used to build client
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
|
||||
extern sint8 espconn_udp_client(struct espconn *pespconn);
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_udp_disconnect
|
||||
* Description : A new incoming connection has been disconnected.
|
||||
* Parameters : espconn -- the espconn used to disconnect with host
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
|
||||
extern void espconn_udp_disconnect(espconn_msg *pdiscon);
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_udp_server
|
||||
* Description : Initialize the server: set up a PCB and bind it to the port
|
||||
* Parameters : pespconn -- the espconn used to build server
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
|
||||
extern sint8 espconn_udp_server(struct espconn *espconn);
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_udp_sent
|
||||
* Description : sent data for client or server
|
||||
* Parameters : void *arg -- client or server to send
|
||||
* uint8* psent -- Data to send
|
||||
* uint16 length -- Length of data to send
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
|
||||
extern err_t espconn_udp_sent(void *arg, uint8 *psent, uint16 length);
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_udp_sendto
|
||||
* Description : sent data for UDP
|
||||
* Parameters : void *arg -- UDP to send
|
||||
* uint8* psent -- Data to send
|
||||
* uint16 length -- Length of data to send
|
||||
* Returns : return espconn error code.
|
||||
* - ESPCONN_OK. Successful. No error occured.
|
||||
* - ESPCONN_MEM. Out of memory.
|
||||
* - ESPCONN_RTE. Could not find route to destination address.
|
||||
* - More errors could be returned by lower protocol layers.
|
||||
*******************************************************************************/
|
||||
extern err_t espconn_udp_sendto(void *arg, uint8 *psent, uint16 length);
|
||||
|
||||
#endif /* __ESPCONN_UDP_H__ */
|
||||
|
||||
|
85
tools/sdk/lwip/include/lwip/app/ping.h
Normal file
85
tools/sdk/lwip/include/lwip/app/ping.h
Normal file
@ -0,0 +1,85 @@
|
||||
#ifndef __PING_H__
|
||||
#define __PING_H__
|
||||
#include "lwip/ip_addr.h"
|
||||
#include "lwip/icmp.h"
|
||||
/**
|
||||
* PING_USE_SOCKETS: Set to 1 to use sockets, otherwise the raw api is used
|
||||
*/
|
||||
#ifndef PING_USE_SOCKETS
|
||||
#define PING_USE_SOCKETS LWIP_SOCKET
|
||||
#endif
|
||||
|
||||
/**
|
||||
* PING_DEBUG: Enable debugging for PING.
|
||||
*/
|
||||
#ifndef PING_DEBUG
|
||||
#define PING_DEBUG LWIP_DBG_OFF
|
||||
#endif
|
||||
|
||||
/** ping receive timeout - in milliseconds */
|
||||
#ifndef PING_RCV_TIMEO
|
||||
#define PING_RCV_TIMEO 1000
|
||||
#endif
|
||||
|
||||
/** ping delay - in milliseconds */
|
||||
#ifndef PING_COARSE
|
||||
#define PING_COARSE 1000
|
||||
#endif
|
||||
|
||||
/** ping identifier - must fit on a u16_t */
|
||||
#ifndef PING_ID
|
||||
#define PING_ID 0xAFAF
|
||||
#endif
|
||||
|
||||
/** ping additional data size to include in the packet */
|
||||
#ifndef PING_DATA_SIZE
|
||||
#define PING_DATA_SIZE 32
|
||||
#endif
|
||||
|
||||
/** ping result action - no default action */
|
||||
#ifndef PING_RESULT
|
||||
#define PING_RESULT(ping_ok)
|
||||
#endif
|
||||
|
||||
#define DEFAULT_PING_MAX_COUNT 4
|
||||
#define PING_TIMEOUT_MS 1000
|
||||
|
||||
typedef void (* ping_recv_function)(void* arg, void *pdata);
|
||||
typedef void (* ping_sent_function)(void* arg, void *pdata);
|
||||
|
||||
struct ping_option{
|
||||
uint32 count;
|
||||
uint32 ip;
|
||||
uint32 coarse_time;
|
||||
ping_recv_function recv_function;
|
||||
ping_sent_function sent_function;
|
||||
void* reverse;
|
||||
};
|
||||
|
||||
struct ping_msg{
|
||||
struct ping_option *ping_opt;
|
||||
struct raw_pcb *ping_pcb;
|
||||
uint32 ping_start;
|
||||
uint32 ping_sent;
|
||||
uint32 timeout_count;
|
||||
uint32 max_count;
|
||||
uint32 sent_count;
|
||||
uint32 coarse_time;
|
||||
};
|
||||
|
||||
struct ping_resp{
|
||||
uint32 total_count;
|
||||
uint32 resp_time;
|
||||
uint32 seqno;
|
||||
uint32 timeout_count;
|
||||
uint32 bytes;
|
||||
uint32 total_bytes;
|
||||
uint32 total_time;
|
||||
sint8 ping_err;
|
||||
};
|
||||
|
||||
bool ping_start(struct ping_option *ping_opt);
|
||||
bool ping_regist_recv(struct ping_option *ping_opt, ping_recv_function ping_recv);
|
||||
bool ping_regist_sent(struct ping_option *ping_opt, ping_sent_function ping_sent);
|
||||
|
||||
#endif /* __PING_H__ */
|
@ -207,6 +207,15 @@ void dhcp_fine_tmr(void);
|
||||
#define DHCP_OPTION_TCP_TTL 37
|
||||
#define DHCP_OPTION_END 255
|
||||
|
||||
/**add options for support more router by liuHan**/
|
||||
#define DHCP_OPTION_DOMAIN_NAME 15
|
||||
#define DHCP_OPTION_PRD 31
|
||||
#define DHCP_OPTION_STATIC_ROUTER 33
|
||||
#define DHCP_OPTION_VSN 43
|
||||
#define DHCP_OPTION_NB_TINS 44
|
||||
#define DHCP_OPTION_NB_TINT 46
|
||||
#define DHCP_OPTION_NB_TIS 47
|
||||
#define DHCP_OPTION_CLASSLESS_STATIC_ROUTER 121
|
||||
/** DHCP options */
|
||||
#define DHCP_OPTION_REQUESTED_IP 50 /* RFC 2132 9.1, requested IP address */
|
||||
#define DHCP_OPTION_LEASE_TIME 51 /* RFC 2132 9.2, time in seconds, in 4 bytes */
|
@ -96,7 +96,7 @@ void igmp_input(struct pbuf *p, struct netif *inp, ip_addr_t *dest)ICACHE_FLAS
|
||||
err_t igmp_joingroup(ip_addr_t *ifaddr, ip_addr_t *groupaddr)ICACHE_FLASH_ATTR;
|
||||
err_t igmp_leavegroup(ip_addr_t *ifaddr, ip_addr_t *groupaddr)ICACHE_FLASH_ATTR;
|
||||
void igmp_tmr(void)ICACHE_FLASH_ATTR;
|
||||
#define LWIP_RAND() rand()
|
||||
#define LWIP_RAND() r_rand()
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
114
tools/sdk/lwip/include/lwip/mdns.h
Normal file
114
tools/sdk/lwip/include/lwip/mdns.h
Normal file
@ -0,0 +1,114 @@
|
||||
/**
|
||||
* lwip MDNS resolver header file.
|
||||
*
|
||||
* Created on: Jul 29, 2010
|
||||
* Author: Daniel Toma
|
||||
|
||||
|
||||
* ported from uIP resolv.c Copyright (c) 2002-2003, Adam Dunkels.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef __LWIP_DNS_H__
|
||||
#define __LWIP_DNS_H__
|
||||
|
||||
#include "lwip/opt.h"
|
||||
|
||||
#if LWIP_MDNS /* don't build if not configured for use in lwipopts.h */
|
||||
|
||||
/** DNS timer period */
|
||||
#define DNS_TMR_INTERVAL 1000
|
||||
|
||||
/** mDNS Address offset flag*/
|
||||
#define DNS_OFFSET_FLAG 0xC0 /* the offset flag in the DNS message */
|
||||
#define DNS_DEFAULT_OFFSET 0x0C /* the offset is set at the beginning of the DNS message */
|
||||
|
||||
#define DNS_IP_ADDR_LEN 4
|
||||
|
||||
|
||||
/** DNS field TYPE used for "Resource Records" */
|
||||
#define DNS_RRTYPE_A 1 /* a host address */
|
||||
#define DNS_RRTYPE_NS 2 /* an authoritative name server */
|
||||
#define DNS_RRTYPE_MD 3 /* a mail destination (Obsolete - use MX) */
|
||||
#define DNS_RRTYPE_MF 4 /* a mail forwarder (Obsolete - use MX) */
|
||||
#define DNS_RRTYPE_CNAME 5 /* the canonical name for an alias */
|
||||
#define DNS_RRTYPE_SOA 6 /* marks the start of a zone of authority */
|
||||
#define DNS_RRTYPE_MB 7 /* a mailbox domain name (EXPERIMENTAL) */
|
||||
#define DNS_RRTYPE_MG 8 /* a mail group member (EXPERIMENTAL) */
|
||||
#define DNS_RRTYPE_MR 9 /* a mail rename domain name (EXPERIMENTAL) */
|
||||
#define DNS_RRTYPE_NULL 10 /* a null RR (EXPERIMENTAL) */
|
||||
#define DNS_RRTYPE_WKS 11 /* a well known service description */
|
||||
#define DNS_RRTYPE_PTR 12 /* a domain name pointer */
|
||||
#define DNS_RRTYPE_HINFO 13 /* host information */
|
||||
#define DNS_RRTYPE_MINFO 14 /* mailbox or mail list information */
|
||||
#define DNS_RRTYPE_MX 15 /* mail exchange */
|
||||
#define DNS_RRTYPE_TXT 16 /* text strings */
|
||||
#define DNS_RRTYPE_SRV 33 /* Service record */
|
||||
#define DNS_RRTYPE_OPT 41 /* EDNS0 OPT record */
|
||||
#define DNS_RRTYPE_TSIG 250 /* Transaction Signature */
|
||||
#define DNS_RRTYPE_ANY 255 /*Not a DNS type, but a DNS query type, meaning "all types"*/
|
||||
|
||||
/* DNS field CLASS used for "Resource Records" */
|
||||
#define DNS_RRCLASS_IN 1 /* the Internet */
|
||||
#define DNS_RRCLASS_CS 2 /* the CSNET class (Obsolete - used only for examples in some obsolete RFCs) */
|
||||
#define DNS_RRCLASS_CH 3 /* the CHAOS class */
|
||||
#define DNS_RRCLASS_HS 4 /* Hesiod [Dyer 87] */
|
||||
#define DNS_RRCLASS_FLUSH 0x800 /* Flush bit */
|
||||
#define DNS_RRCLASS_FLUSH_IN 0x8001/* Flush bit and Internet*/
|
||||
|
||||
/** Callback which is invoked when a hostname is found.
|
||||
* A function of this type must be implemented by the application using the DNS resolver.
|
||||
* @param name pointer to the name that was looked up.
|
||||
* @param ipaddr pointer to a struct ip_addr containing the IP address of the hostname,
|
||||
* or NULL if the name could not be found (or on any other error).
|
||||
* @param callback_arg a user-specified callback argument passed to dns_gethostbyname
|
||||
*/
|
||||
#ifndef _MDNS_INFO
|
||||
#define _MDNS_INFO
|
||||
struct mdns_info {
|
||||
char *host_name;
|
||||
char *server_name;
|
||||
uint16 server_port;
|
||||
unsigned long ipAddr;
|
||||
char *txt_data[10];
|
||||
};
|
||||
#endif
|
||||
//void mdns_enable(void);
|
||||
//void mdns_disable(void);
|
||||
//void mdns_init(struct mdns_info *info);
|
||||
//void mdns_close(void);
|
||||
//char* mdns_get_hostname(void);
|
||||
//void mdns_set_hostname(char *name);
|
||||
//void mdns_set_servername(const char *name);
|
||||
//char* mdns_get_servername(void);
|
||||
//void mdns_server_unregister(void);
|
||||
//void mdns_server_register(void) ;
|
||||
//void mdns_tmr(void);
|
||||
//void Delay(unsigned long ulSeconds);
|
||||
|
||||
#endif /* LWIP_DNS */
|
||||
|
||||
#endif /* __LWIP_DNS_H__ */
|
@ -33,7 +33,7 @@
|
||||
#define __LWIP_MEM_H__
|
||||
|
||||
#include "lwip/opt.h"
|
||||
#include "mem_manager.h"
|
||||
//#include "mem_manager.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
@ -76,7 +76,7 @@ typedef enum {
|
||||
#endif /* MEM_USE_POOLS */
|
||||
|
||||
#if MEMP_MEM_MALLOC || MEM_USE_POOLS
|
||||
extern const u16_t memp_sizes[MEMP_MAX];
|
||||
extern const u32_t memp_sizes[MEMP_MAX];
|
||||
#endif /* MEMP_MEM_MALLOC || MEM_USE_POOLS */
|
||||
|
||||
#if MEMP_MEM_MALLOC
|
@ -130,6 +130,9 @@ typedef void (*netif_status_callback_fn)(struct netif *netif);
|
||||
typedef err_t (*netif_igmp_mac_filter_fn)(struct netif *netif,
|
||||
ip_addr_t *group, u8_t action);
|
||||
|
||||
/*add DHCP event processing by LiuHan*/
|
||||
typedef void (*dhcp_event_fn)(void);
|
||||
|
||||
/** Generic data structure used for all lwIP network interfaces.
|
||||
* The following fields should be filled in by the initialization
|
||||
* function for the device driver: hwaddr_len, hwaddr[], mtu, flags */
|
||||
@ -169,6 +172,8 @@ struct netif {
|
||||
#if LWIP_DHCP
|
||||
/** the DHCP client state information for this netif */
|
||||
struct dhcp *dhcp;
|
||||
struct udp_pcb *dhcps_pcb; //dhcps
|
||||
dhcp_event_fn dhcp_event;
|
||||
#endif /* LWIP_DHCP */
|
||||
#if LWIP_AUTOIP
|
||||
/** the AutoIP client state information for this netif */
|
@ -42,7 +42,7 @@
|
||||
* Include user defined options first. Anything not defined in these files
|
||||
* will be set to standard values. Override anything you dont like!
|
||||
*/
|
||||
#include "include/lwipopts.h"
|
||||
#include "lwipopts.h"
|
||||
#include "lwip/debug.h"
|
||||
|
||||
/*
|
44
tools/sdk/lwip/include/lwip/puck_def.h
Normal file
44
tools/sdk/lwip/include/lwip/puck_def.h
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* puck_def.h
|
||||
*
|
||||
* Created on: Jul 22, 2010
|
||||
* Author: dtoma
|
||||
*/
|
||||
|
||||
#ifndef PUCK_DEF_H_
|
||||
#define PUCK_DEF_H_
|
||||
|
||||
|
||||
|
||||
#define INSTRUMENT_PORT 8760
|
||||
|
||||
#define INSTRUMENT_LENGTH 80
|
||||
|
||||
#define MDNS_NAME_LENGTH 68 //68
|
||||
|
||||
char* PUCK_SERVICE = NULL;
|
||||
//#define PUCK_SERVICE "_Escpressif._tcp.local"
|
||||
#define DNS_SD_SERVICE "_services._dns-sd._udp.local"
|
||||
#define SERVICE_DESCRIPTION "PUCK PROTOCOL"
|
||||
#define PUCK_SERVICE_LENGTH 30
|
||||
|
||||
#define UUID_LEN 16
|
||||
#define DS_VERS_LEN 2
|
||||
#define DS_SIZE_LEN 2
|
||||
#define MAN_ID_LEN 4
|
||||
#define MAN_MODEL_LEN 2
|
||||
#define MAN_VERS_LEN 2
|
||||
#define SER_NUM_LEN 4
|
||||
#define NAME_LEN 64
|
||||
#define PUCK_DATASHEET_SIZE 96
|
||||
|
||||
#define UUID_OFFSET 0
|
||||
#define DS_VERS_OFFSET UUID_LEN + UUID_OFFSET
|
||||
#define DS_SIZE_OFFSET DS_VERS_LEN + DS_VERS_OFFSET
|
||||
#define MAN_ID_OFFSET DS_SIZE_LEN + DS_SIZE_OFFSET
|
||||
#define MAN_MODEL_OFFSET MAN_ID_LEN + MAN_ID_OFFSET
|
||||
#define MAN_VERS_OFFSET MAN_MODEL_LEN + MAN_MODEL_OFFSET
|
||||
#define SER_NUM_OFFSET MAN_VERS_LEN + MAN_VERS_OFFSET
|
||||
#define NAME_OFFSET SER_NUM_LEN + SER_NUM_OFFSET
|
||||
|
||||
#endif /* __PUCK_DEF_H__ */
|
56
tools/sdk/lwip/include/lwip/sntp.h
Normal file
56
tools/sdk/lwip/include/lwip/sntp.h
Normal file
@ -0,0 +1,56 @@
|
||||
#ifndef LWIP_SNTP_H
|
||||
#define LWIP_SNTP_H
|
||||
|
||||
#include "lwip/opt.h"
|
||||
#include "lwip/ip_addr.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** The maximum number of SNTP servers that can be set */
|
||||
#ifndef SNTP_MAX_SERVERS
|
||||
#define SNTP_MAX_SERVERS 3
|
||||
#endif
|
||||
|
||||
/** Set this to 1 to implement the callback function called by dhcp when
|
||||
* NTP servers are received. */
|
||||
#ifndef SNTP_GET_SERVERS_FROM_DHCP
|
||||
#define SNTP_GET_SERVERS_FROM_DHCP 0//LWIP_DHCP_GET_NTP_SRV
|
||||
#endif
|
||||
|
||||
/* Set this to 1 to support DNS names (or IP address strings) to set sntp servers */
|
||||
#ifndef SNTP_SERVER_DNS
|
||||
#define SNTP_SERVER_DNS 1
|
||||
#endif
|
||||
|
||||
/** One server address/name can be defined as default if SNTP_SERVER_DNS == 1:
|
||||
* #define SNTP_SERVER_ADDRESS "pool.ntp.org"
|
||||
*/
|
||||
uint32 sntp_get_current_timestamp();
|
||||
char* sntp_get_real_time(long t);
|
||||
|
||||
void sntp_init(void);
|
||||
void sntp_stop(void);
|
||||
|
||||
sint8 sntp_get_timezone(void);
|
||||
bool sntp_set_timezone(sint8 timezone);
|
||||
void sntp_setserver(u8_t idx, ip_addr_t *addr);
|
||||
ip_addr_t sntp_getserver(u8_t idx);
|
||||
|
||||
#if SNTP_SERVER_DNS
|
||||
void sntp_setservername(u8_t idx, char *server);
|
||||
char *sntp_getservername(u8_t idx);
|
||||
#endif /* SNTP_SERVER_DNS */
|
||||
|
||||
#if SNTP_GET_SERVERS_FROM_DHCP
|
||||
void sntp_servermode_dhcp(int set_servers_from_dhcp);
|
||||
#else /* SNTP_GET_SERVERS_FROM_DHCP */
|
||||
#define sntp_servermode_dhcp(x)
|
||||
#endif /* SNTP_GET_SERVERS_FROM_DHCP */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* LWIP_SNTP_H */
|
@ -113,7 +113,7 @@ u32_t tcp_update_rcv_ann_wnd(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR;
|
||||
#define TCP_HLEN 20
|
||||
|
||||
#ifndef TCP_TMR_INTERVAL
|
||||
#define TCP_TMR_INTERVAL 250 /* The TCP timer interval in milliseconds. */
|
||||
#define TCP_TMR_INTERVAL 125 /* The TCP timer interval in milliseconds. */
|
||||
#endif /* TCP_TMR_INTERVAL */
|
||||
|
||||
#ifndef TCP_FAST_INTERVAL
|
||||
@ -135,15 +135,15 @@ u32_t tcp_update_rcv_ann_wnd(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR;
|
||||
|
||||
/* Keepalive values, compliant with RFC 1122. Don't change this unless you know what you're doing */
|
||||
#ifndef TCP_KEEPIDLE_DEFAULT
|
||||
#define TCP_KEEPIDLE_DEFAULT 3000UL /* Default KEEPALIVE timer in milliseconds */
|
||||
#define TCP_KEEPIDLE_DEFAULT 120000UL /* Default KEEPALIVE timer in milliseconds */
|
||||
#endif
|
||||
|
||||
#ifndef TCP_KEEPINTVL_DEFAULT
|
||||
#define TCP_KEEPINTVL_DEFAULT 1000UL /* Default Time between KEEPALIVE probes in milliseconds */
|
||||
#define TCP_KEEPINTVL_DEFAULT 10000UL /* Default Time between KEEPALIVE probes in milliseconds */
|
||||
#endif
|
||||
|
||||
#ifndef TCP_KEEPCNT_DEFAULT
|
||||
#define TCP_KEEPCNT_DEFAULT 3U /* Default Counter for KEEPALIVE probes */
|
||||
#define TCP_KEEPCNT_DEFAULT 9U /* Default Counter for KEEPALIVE probes */
|
||||
#endif
|
||||
|
||||
#define TCP_MAXIDLE TCP_KEEPCNT_DEFAULT * TCP_KEEPINTVL_DEFAULT /* Maximum KEEPALIVE probe time */
|
||||
@ -156,14 +156,14 @@ u32_t tcp_update_rcv_ann_wnd(struct tcp_pcb *pcb)ICACHE_FLASH_ATTR;
|
||||
#endif
|
||||
PACK_STRUCT_BEGIN
|
||||
struct tcp_hdr {
|
||||
PACK_STRUCT_FIELD(u16_t src); //源端口
|
||||
PACK_STRUCT_FIELD(u16_t dest); //目的端口
|
||||
PACK_STRUCT_FIELD(u32_t seqno); //序号
|
||||
PACK_STRUCT_FIELD(u32_t ackno); //应答序号
|
||||
PACK_STRUCT_FIELD(u16_t _hdrlen_rsvd_flags);//首部长度+保留位+标志位
|
||||
PACK_STRUCT_FIELD(u16_t wnd); //窗口大小
|
||||
PACK_STRUCT_FIELD(u16_t chksum); //校验和
|
||||
PACK_STRUCT_FIELD(u16_t urgp); //紧急指针
|
||||
PACK_STRUCT_FIELD(u16_t src); //Դ<EFBFBD>˿<EFBFBD>
|
||||
PACK_STRUCT_FIELD(u16_t dest); //Ŀ<EFBFBD>Ķ˿<EFBFBD>
|
||||
PACK_STRUCT_FIELD(u32_t seqno); //<EFBFBD><EFBFBD><EFBFBD>
|
||||
PACK_STRUCT_FIELD(u32_t ackno); //Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
PACK_STRUCT_FIELD(u16_t _hdrlen_rsvd_flags);//<EFBFBD>ײ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>+<2B><><EFBFBD><EFBFBD>λ+<2B><>־λ
|
||||
PACK_STRUCT_FIELD(u16_t wnd); //<EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>С
|
||||
PACK_STRUCT_FIELD(u16_t chksum); //У<EFBFBD><EFBFBD><EFBFBD>
|
||||
PACK_STRUCT_FIELD(u16_t urgp); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
|
||||
} PACK_STRUCT_STRUCT;
|
||||
PACK_STRUCT_END
|
||||
#ifdef PACK_STRUCT_USE_INCLUDES
|
@ -38,10 +38,9 @@
|
||||
#ifndef __LWIPOPTS_H__
|
||||
#define __LWIPOPTS_H__
|
||||
|
||||
#define PBUF_RSV_FOR_WLAN
|
||||
#define EBUF_LWIP
|
||||
|
||||
#define EBUF_LWIP 1
|
||||
#define LWIP_ESP 1
|
||||
#define EP_OFFSET 36
|
||||
/*
|
||||
-----------------------------------------------
|
||||
---------- Platform specific locking ----------
|
||||
@ -245,7 +244,7 @@
|
||||
* (requires the LWIP_TCP option)
|
||||
*/
|
||||
#ifndef MEMP_NUM_TCP_PCB
|
||||
#define MEMP_NUM_TCP_PCB (*((volatile uint32*)0x600011FC))
|
||||
#define MEMP_NUM_TCP_PCB (*(volatile uint32*)0x600011FC)
|
||||
#endif
|
||||
|
||||
/**
|
||||
@ -308,7 +307,7 @@
|
||||
* (requires NO_SYS==0)
|
||||
*/
|
||||
#ifndef MEMP_NUM_SYS_TIMEOUT
|
||||
#define MEMP_NUM_SYS_TIMEOUT 6
|
||||
#define MEMP_NUM_SYS_TIMEOUT 8
|
||||
#endif
|
||||
|
||||
/**
|
||||
@ -534,7 +533,7 @@
|
||||
* in this time, the whole packet is discarded.
|
||||
*/
|
||||
#ifndef IP_REASS_MAXAGE
|
||||
#define IP_REASS_MAXAGE 0
|
||||
#define IP_REASS_MAXAGE 3
|
||||
#endif
|
||||
|
||||
/**
|
||||
@ -544,7 +543,7 @@
|
||||
* packets even if the maximum amount of fragments is enqueued for reassembly!
|
||||
*/
|
||||
#ifndef IP_REASS_MAX_PBUFS
|
||||
#define IP_REASS_MAX_PBUFS 0
|
||||
#define IP_REASS_MAX_PBUFS 10
|
||||
#endif
|
||||
|
||||
/**
|
||||
@ -633,7 +632,7 @@
|
||||
* LWIP_RAW==1: Enable application layer to hook into the IP layer itself.
|
||||
*/
|
||||
#ifndef LWIP_RAW
|
||||
#define LWIP_RAW 0
|
||||
#define LWIP_RAW 1
|
||||
#endif
|
||||
|
||||
/**
|
||||
@ -662,6 +661,13 @@
|
||||
#define DHCP_DOES_ARP_CHECK ((LWIP_DHCP) && (LWIP_ARP))
|
||||
#endif
|
||||
|
||||
/**
|
||||
* DHCP_MAXRTX: Maximum number of retries of current request.
|
||||
*/
|
||||
#ifndef DHCP_MAXRTX
|
||||
#define DHCP_MAXRTX (*(volatile uint32*)0x600011E0)
|
||||
#endif
|
||||
|
||||
/*
|
||||
------------------------------------
|
||||
---------- AUTOIP options ----------
|
||||
@ -774,6 +780,17 @@
|
||||
#ifndef LWIP_IGMP
|
||||
#define LWIP_IGMP 1
|
||||
#endif
|
||||
/*
|
||||
----------------------------------
|
||||
---------- MDNS options ----------
|
||||
----------------------------------
|
||||
*/
|
||||
/**
|
||||
* LWIP_MDNS==1: Turn on MDNS module.
|
||||
*/
|
||||
#ifndef LWIP_MDNS
|
||||
#define LWIP_MDNS 1
|
||||
#endif
|
||||
|
||||
/*
|
||||
----------------------------------
|
||||
@ -890,21 +907,35 @@
|
||||
* (2 * TCP_MSS) for things to work well
|
||||
*/
|
||||
#ifndef TCP_WND
|
||||
#define TCP_WND (4 * TCP_MSS)
|
||||
#define TCP_WND (*(volatile uint32*)0x600011F0)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* TCP_MAXRTX: Maximum number of retransmissions of data segments.
|
||||
*/
|
||||
#ifndef TCP_MAXRTX
|
||||
#define TCP_MAXRTX 5
|
||||
#define TCP_MAXRTX (*(volatile uint32*)0x600011E8)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* TCP_SYNMAXRTX: Maximum number of retransmissions of SYN segments.
|
||||
*/
|
||||
#ifndef TCP_SYNMAXRTX
|
||||
#define TCP_SYNMAXRTX 5
|
||||
#define TCP_SYNMAXRTX (*(volatile uint32*)0x600011E4)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* TCP_MAXRTO: Maximum retransmission timeout of data segments.
|
||||
*/
|
||||
#ifndef TCP_MAXRTO
|
||||
#define TCP_MAXRTO 10
|
||||
#endif
|
||||
|
||||
/**
|
||||
* TCP_MINRTO: Minimum retransmission timeout of data segments.
|
||||
*/
|
||||
#ifndef TCP_MINRTO
|
||||
#define TCP_MINRTO 2
|
||||
#endif
|
||||
|
||||
/**
|
||||
@ -912,9 +943,10 @@
|
||||
* Define to 0 if your device is low on memory.
|
||||
*/
|
||||
#ifndef TCP_QUEUE_OOSEQ
|
||||
#define TCP_QUEUE_OOSEQ 0
|
||||
#define TCP_QUEUE_OOSEQ 1
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
/**
|
||||
* TCP_MSS: TCP Maximum segment size. (default is 536, a conservative default,
|
||||
* you might want to increase this.)
|
||||
@ -925,6 +957,7 @@
|
||||
#ifndef TCP_MSS
|
||||
#define TCP_MSS 1460
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/**
|
||||
* TCP_CALCULATE_EFF_SEND_MSS: "The maximum size of a segment that TCP really
|
||||
@ -1070,7 +1103,7 @@
|
||||
* field.
|
||||
*/
|
||||
#ifndef LWIP_NETIF_HOSTNAME
|
||||
#define LWIP_NETIF_HOSTNAME 0
|
||||
#define LWIP_NETIF_HOSTNAME 1
|
||||
#endif
|
||||
|
||||
/**
|
254
tools/sdk/lwip/include/netif/etharp.h
Normal file
254
tools/sdk/lwip/include/netif/etharp.h
Normal file
@ -0,0 +1,254 @@
|
||||
/*
|
||||
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
|
||||
* Copyright (c) 2003-2004 Leon Woestenberg <leon.woestenberg@axon.tv>
|
||||
* Copyright (c) 2003-2004 Axon Digital Design B.V., The Netherlands.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
||||
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||
* OF SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the lwIP TCP/IP stack.
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __NETIF_ETHARP_H__
|
||||
#define __NETIF_ETHARP_H__
|
||||
|
||||
#include "lwip/opt.h"
|
||||
|
||||
#if LWIP_ARP || LWIP_ETHERNET /* don't build if not configured for use in lwipopts.h */
|
||||
|
||||
#include "lwip/pbuf.h"
|
||||
#include "lwip/ip_addr.h"
|
||||
#include "lwip/netif.h"
|
||||
#include "lwip/ip.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef ETHARP_HWADDR_LEN
|
||||
#define ETHARP_HWADDR_LEN 6
|
||||
#endif
|
||||
|
||||
#ifdef PACK_STRUCT_USE_INCLUDES
|
||||
# include "arch/bpstruct.h"
|
||||
#endif
|
||||
PACK_STRUCT_BEGIN
|
||||
struct eth_addr {
|
||||
PACK_STRUCT_FIELD(u8_t addr[ETHARP_HWADDR_LEN]);
|
||||
} PACK_STRUCT_STRUCT;
|
||||
PACK_STRUCT_END
|
||||
#ifdef PACK_STRUCT_USE_INCLUDES
|
||||
# include "arch/epstruct.h"
|
||||
#endif
|
||||
|
||||
#ifdef PACK_STRUCT_USE_INCLUDES
|
||||
# include "arch/bpstruct.h"
|
||||
#endif
|
||||
PACK_STRUCT_BEGIN
|
||||
/** Ethernet header */
|
||||
struct eth_hdr {
|
||||
#if ETH_PAD_SIZE
|
||||
PACK_STRUCT_FIELD(u8_t padding[ETH_PAD_SIZE]);
|
||||
#endif
|
||||
PACK_STRUCT_FIELD(struct eth_addr dest);
|
||||
PACK_STRUCT_FIELD(struct eth_addr src);
|
||||
PACK_STRUCT_FIELD(u16_t type);
|
||||
} PACK_STRUCT_STRUCT;
|
||||
PACK_STRUCT_END
|
||||
#ifdef PACK_STRUCT_USE_INCLUDES
|
||||
# include "arch/epstruct.h"
|
||||
#endif
|
||||
|
||||
#define SIZEOF_ETH_HDR (14 + ETH_PAD_SIZE)
|
||||
|
||||
#if ETHARP_SUPPORT_VLAN
|
||||
|
||||
#ifdef PACK_STRUCT_USE_INCLUDES
|
||||
# include "arch/bpstruct.h"
|
||||
#endif
|
||||
PACK_STRUCT_BEGIN
|
||||
/** VLAN header inserted between ethernet header and payload
|
||||
* if 'type' in ethernet header is ETHTYPE_VLAN.
|
||||
* See IEEE802.Q */
|
||||
struct eth_vlan_hdr {
|
||||
PACK_STRUCT_FIELD(u16_t tpid);
|
||||
PACK_STRUCT_FIELD(u16_t prio_vid);
|
||||
} PACK_STRUCT_STRUCT;
|
||||
PACK_STRUCT_END
|
||||
#ifdef PACK_STRUCT_USE_INCLUDES
|
||||
# include "arch/epstruct.h"
|
||||
#endif
|
||||
|
||||
#define SIZEOF_VLAN_HDR 4
|
||||
#define VLAN_ID(vlan_hdr) (htons((vlan_hdr)->prio_vid) & 0xFFF)
|
||||
|
||||
#endif /* ETHARP_SUPPORT_VLAN */
|
||||
|
||||
#ifdef PACK_STRUCT_USE_INCLUDES
|
||||
# include "arch/bpstruct.h"
|
||||
#endif
|
||||
PACK_STRUCT_BEGIN
|
||||
/** the ARP message, see RFC 826 ("Packet format") */
|
||||
struct etharp_hdr {
|
||||
PACK_STRUCT_FIELD(u16_t hwtype);
|
||||
PACK_STRUCT_FIELD(u16_t proto);
|
||||
PACK_STRUCT_FIELD(u8_t hwlen);
|
||||
PACK_STRUCT_FIELD(u8_t protolen);
|
||||
PACK_STRUCT_FIELD(u16_t opcode);
|
||||
PACK_STRUCT_FIELD(struct eth_addr shwaddr);
|
||||
PACK_STRUCT_FIELD(struct ip_addr2 sipaddr);
|
||||
PACK_STRUCT_FIELD(struct eth_addr dhwaddr);
|
||||
PACK_STRUCT_FIELD(struct ip_addr2 dipaddr);
|
||||
} PACK_STRUCT_STRUCT;
|
||||
PACK_STRUCT_END
|
||||
#ifdef PACK_STRUCT_USE_INCLUDES
|
||||
# include "arch/epstruct.h"
|
||||
#endif
|
||||
|
||||
#define SIZEOF_ETHARP_HDR 28
|
||||
#define SIZEOF_ETHARP_MINSIZE 46
|
||||
#define SIZEOF_ETHARP_PACKET (SIZEOF_ETH_HDR + SIZEOF_ETHARP_HDR)
|
||||
#define SIZEOF_ETHARP_WITHPAD (SIZEOF_ETH_HDR + SIZEOF_ETHARP_MINSIZE)
|
||||
|
||||
/** 5 seconds period */
|
||||
#define ARP_TMR_INTERVAL 5000
|
||||
|
||||
#define ETHTYPE_ARP 0x0806
|
||||
#define ETHTYPE_IP 0x0800
|
||||
#define ETHTYPE_VLAN 0x8100
|
||||
#define ETHTYPE_PPPOEDISC 0x8863 /* PPP Over Ethernet Discovery Stage */
|
||||
#define ETHTYPE_PPPOE 0x8864 /* PPP Over Ethernet Session Stage */
|
||||
#define ETHTYPE_PAE 0x888e
|
||||
|
||||
/** MEMCPY-like macro to copy to/from struct eth_addr's that are local variables
|
||||
* or known to be 32-bit aligned within the protocol header. */
|
||||
#ifndef ETHADDR32_COPY
|
||||
#define ETHADDR32_COPY(src, dst) SMEMCPY(src, dst, ETHARP_HWADDR_LEN)
|
||||
#endif
|
||||
|
||||
/** MEMCPY-like macro to copy to/from struct eth_addr's that are no local
|
||||
* variables and known to be 16-bit aligned within the protocol header. */
|
||||
#ifndef ETHADDR16_COPY
|
||||
#define ETHADDR16_COPY(src, dst) SMEMCPY(src, dst, ETHARP_HWADDR_LEN)
|
||||
#endif
|
||||
|
||||
#if LWIP_ARP /* don't build if not configured for use in lwipopts.h */
|
||||
|
||||
/** ARP message types (opcodes) */
|
||||
#define ARP_REQUEST 1
|
||||
#define ARP_REPLY 2
|
||||
|
||||
/** Define this to 1 and define LWIP_ARP_FILTER_NETIF_FN(pbuf, netif, type)
|
||||
* to a filter function that returns the correct netif when using multiple
|
||||
* netifs on one hardware interface where the netif's low-level receive
|
||||
* routine cannot decide for the correct netif (e.g. when mapping multiple
|
||||
* IP addresses to one hardware interface).
|
||||
*/
|
||||
#ifndef LWIP_ARP_FILTER_NETIF
|
||||
#define LWIP_ARP_FILTER_NETIF 0
|
||||
#endif
|
||||
|
||||
#if ARP_QUEUEING
|
||||
/** struct for queueing outgoing packets for unknown address
|
||||
* defined here to be accessed by memp.h
|
||||
*/
|
||||
struct etharp_q_entry {
|
||||
struct etharp_q_entry *next;
|
||||
struct pbuf *p;
|
||||
};
|
||||
#endif /* ARP_QUEUEING */
|
||||
|
||||
#define etharp_init() /* Compatibility define, not init needed. */
|
||||
void etharp_tmr(void)ICACHE_FLASH_ATTR;
|
||||
s8_t etharp_find_addr(struct netif *netif, ip_addr_t *ipaddr,
|
||||
struct eth_addr **eth_ret, ip_addr_t **ip_ret)ICACHE_FLASH_ATTR;
|
||||
err_t etharp_output(struct netif *netif, struct pbuf *q, ip_addr_t *ipaddr)ICACHE_FLASH_ATTR;
|
||||
err_t etharp_query(struct netif *netif, ip_addr_t *ipaddr, struct pbuf *q)ICACHE_FLASH_ATTR;
|
||||
err_t etharp_request(struct netif *netif, ip_addr_t *ipaddr)ICACHE_FLASH_ATTR;
|
||||
/** For Ethernet network interfaces, we might want to send "gratuitous ARP";
|
||||
* this is an ARP packet sent by a node in order to spontaneously cause other
|
||||
* nodes to update an entry in their ARP cache.
|
||||
* From RFC 3220 "IP Mobility Support for IPv4" section 4.6. */
|
||||
#define etharp_gratuitous(netif) etharp_request((netif), &(netif)->ip_addr)
|
||||
void etharp_cleanup_netif(struct netif *netif);
|
||||
|
||||
#if ETHARP_SUPPORT_STATIC_ENTRIES
|
||||
err_t etharp_add_static_entry(ip_addr_t *ipaddr, struct eth_addr *ethaddr)ICACHE_FLASH_ATTR;
|
||||
err_t etharp_remove_static_entry(ip_addr_t *ipaddr)ICACHE_FLASH_ATTR;
|
||||
#endif /* ETHARP_SUPPORT_STATIC_ENTRIES */
|
||||
|
||||
#if LWIP_AUTOIP
|
||||
err_t etharp_raw(struct netif *netif, const struct eth_addr *ethsrc_addr,
|
||||
const struct eth_addr *ethdst_addr,
|
||||
const struct eth_addr *hwsrc_addr, const ip_addr_t *ipsrc_addr,
|
||||
const struct eth_addr *hwdst_addr, const ip_addr_t *ipdst_addr,
|
||||
const u16_t opcode)ICACHE_FLASH_ATTR;
|
||||
#endif /* LWIP_AUTOIP */
|
||||
|
||||
#endif /* LWIP_ARP */
|
||||
|
||||
err_t ethernet_input(struct pbuf *p, struct netif *netif)ICACHE_FLASH_ATTR;
|
||||
|
||||
#define eth_addr_cmp(addr1, addr2) (memcmp((addr1)->addr, (addr2)->addr, ETHARP_HWADDR_LEN) == 0)
|
||||
|
||||
extern const struct eth_addr ethbroadcast, ethzero;
|
||||
|
||||
#endif /* LWIP_ARP || LWIP_ETHERNET */
|
||||
|
||||
#if 0
|
||||
/** Ethernet header */
|
||||
#ifndef ETHARP_HWADDR_LEN
|
||||
#define ETHARP_HWADDR_LEN 6
|
||||
#endif
|
||||
|
||||
|
||||
struct eth_addr {
|
||||
PACK_STRUCT_FIELD(u8_t addr[ETHARP_HWADDR_LEN]);
|
||||
} PACK_STRUCT_STRUCT;
|
||||
|
||||
|
||||
struct eth_hdr {
|
||||
#if ETH_PAD_SIZE
|
||||
PACK_STRUCT_FIELD(u8_t padding[ETH_PAD_SIZE]);
|
||||
#endif
|
||||
PACK_STRUCT_FIELD(struct eth_addr dest);
|
||||
PACK_STRUCT_FIELD(struct eth_addr src);
|
||||
PACK_STRUCT_FIELD(u16_t type);
|
||||
} PACK_STRUCT_STRUCT;
|
||||
|
||||
#ifdef PACK_STRUCT_USE_INCLUDES
|
||||
# include "arch/epstruct.h"
|
||||
#endif
|
||||
|
||||
#define SIZEOF_ETH_HDR (14 + ETH_PAD_SIZE)
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __NETIF_ARP_H__ */
|
173
tools/sdk/lwip/include/netif/if_llc.h
Normal file
173
tools/sdk/lwip/include/netif/if_llc.h
Normal file
@ -0,0 +1,173 @@
|
||||
/* $NetBSD: if_llc.h,v 1.12 1999/11/19 20:41:19 thorpej Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1988, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)if_llc.h 8.1 (Berkeley) 6/10/93
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _NET_IF_LLC_H_
|
||||
#define _NET_IF_LLC_H_
|
||||
|
||||
/*
|
||||
* IEEE 802.2 Link Level Control headers, for use in conjunction with
|
||||
* 802.{3,4,5} media access control methods.
|
||||
*
|
||||
* Headers here do not use bit fields due to shortcommings in many
|
||||
* compilers.
|
||||
*/
|
||||
|
||||
struct llc {
|
||||
uint8_t llc_dsap;
|
||||
uint8_t llc_ssap;
|
||||
union {
|
||||
struct {
|
||||
uint8_t control;
|
||||
uint8_t format_id;
|
||||
uint8_t class;
|
||||
uint8_t window_x2;
|
||||
} __packed type_u;
|
||||
struct {
|
||||
uint8_t num_snd_x2;
|
||||
uint8_t num_rcv_x2;
|
||||
} __packed type_i;
|
||||
struct {
|
||||
uint8_t control;
|
||||
uint8_t num_rcv_x2;
|
||||
} __packed type_s;
|
||||
struct {
|
||||
uint8_t control;
|
||||
/*
|
||||
* We cannot put the following fields in a structure because
|
||||
* the structure rounding might cause padding.
|
||||
*/
|
||||
uint8_t frmr_rej_pdu0;
|
||||
uint8_t frmr_rej_pdu1;
|
||||
uint8_t frmr_control;
|
||||
uint8_t frmr_control_ext;
|
||||
uint8_t frmr_cause;
|
||||
} __packed type_frmr;
|
||||
struct {
|
||||
uint8_t control;
|
||||
uint8_t org_code[3];
|
||||
uint16_t ether_type;
|
||||
} __packed type_snap;
|
||||
struct {
|
||||
uint8_t control;
|
||||
uint8_t control_ext;
|
||||
} __packed type_raw;
|
||||
} __packed llc_un;
|
||||
} __packed;
|
||||
|
||||
struct frmrinfo {
|
||||
uint8_t frmr_rej_pdu0;
|
||||
uint8_t frmr_rej_pdu1;
|
||||
uint8_t frmr_control;
|
||||
uint8_t frmr_control_ext;
|
||||
uint8_t frmr_cause;
|
||||
} __packed;
|
||||
|
||||
#define llc_control llc_un.type_u.control
|
||||
#define llc_control_ext llc_un.type_raw.control_ext
|
||||
#define llc_fid llc_un.type_u.format_id
|
||||
#define llc_class llc_un.type_u.class
|
||||
#define llc_window llc_un.type_u.window_x2
|
||||
#define llc_frmrinfo llc_un.type_frmr.frmr_rej_pdu0
|
||||
#define llc_frmr_pdu0 llc_un.type_frmr.frmr_rej_pdu0
|
||||
#define llc_frmr_pdu1 llc_un.type_frmr.frmr_rej_pdu1
|
||||
#define llc_frmr_control llc_un.type_frmr.frmr_control
|
||||
#define llc_frmr_control_ext llc_un.type_frmr.frmr_control_ext
|
||||
#define llc_frmr_cause llc_un.type_frmr.frmr_cause
|
||||
#define llc_snap llc_un.type_snap
|
||||
|
||||
/*
|
||||
* Don't use sizeof(struct llc_un) for LLC header sizes
|
||||
*/
|
||||
#define LLC_ISFRAMELEN 4
|
||||
#define LLC_UFRAMELEN 3
|
||||
#define LLC_FRMRLEN 7
|
||||
#define LLC_SNAPFRAMELEN 8
|
||||
|
||||
#ifdef CTASSERT
|
||||
CTASSERT(sizeof (struct llc) == LLC_SNAPFRAMELEN);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Unnumbered LLC format commands
|
||||
*/
|
||||
#define LLC_UI 0x3
|
||||
#define LLC_UI_P 0x13
|
||||
#define LLC_DISC 0x43
|
||||
#define LLC_DISC_P 0x53
|
||||
#define LLC_UA 0x63
|
||||
#define LLC_UA_P 0x73
|
||||
#define LLC_TEST 0xe3
|
||||
#define LLC_TEST_P 0xf3
|
||||
#define LLC_FRMR 0x87
|
||||
#define LLC_FRMR_P 0x97
|
||||
#define LLC_DM 0x0f
|
||||
#define LLC_DM_P 0x1f
|
||||
#define LLC_XID 0xaf
|
||||
#define LLC_XID_P 0xbf
|
||||
#define LLC_SABME 0x6f
|
||||
#define LLC_SABME_P 0x7f
|
||||
|
||||
/*
|
||||
* Supervisory LLC commands
|
||||
*/
|
||||
#define LLC_RR 0x01
|
||||
#define LLC_RNR 0x05
|
||||
#define LLC_REJ 0x09
|
||||
|
||||
/*
|
||||
* Info format - dummy only
|
||||
*/
|
||||
#define LLC_INFO 0x00
|
||||
|
||||
/*
|
||||
* ISO PDTR 10178 contains among others
|
||||
*/
|
||||
#define LLC_8021D_LSAP 0x42
|
||||
#define LLC_X25_LSAP 0x7e
|
||||
#define LLC_SNAP_LSAP 0xaa
|
||||
#define LLC_ISO_LSAP 0xfe
|
||||
|
||||
#define RFC1042_LEN 6
|
||||
#define RFC1042 {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00}
|
||||
#define ETHERNET_TUNNEL {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8}
|
||||
|
||||
/*
|
||||
* copied from sys/net/ethernet.h
|
||||
*/
|
||||
#define ETHERTYPE_AARP 0x80F3 /* AppleTalk AARP */
|
||||
#define ETHERTYPE_IPX 0x8137 /* Novell (old) NetWare IPX (ECONFIG E option) */
|
||||
|
||||
|
||||
|
||||
#endif /* _NET_IF_LLC_H_ */
|
190
tools/sdk/lwip/include/netif/ppp_oe.h
Normal file
190
tools/sdk/lwip/include/netif/ppp_oe.h
Normal file
@ -0,0 +1,190 @@
|
||||
/*****************************************************************************
|
||||
* ppp_oe.h - PPP Over Ethernet implementation for lwIP.
|
||||
*
|
||||
* Copyright (c) 2006 by Marc Boucher, Services Informatiques (MBSI) inc.
|
||||
*
|
||||
* The authors hereby grant permission to use, copy, modify, distribute,
|
||||
* and license this software and its documentation for any purpose, provided
|
||||
* that existing copyright notices are retained in all copies and that this
|
||||
* notice and the following disclaimer are included verbatim in any
|
||||
* distributions. No written agreement, license, or royalty fee is required
|
||||
* for any of the authorized uses.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
* REVISION HISTORY
|
||||
*
|
||||
* 06-01-01 Marc Boucher <marc@mbsi.ca>
|
||||
* Ported to lwIP.
|
||||
*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
/* based on NetBSD: if_pppoe.c,v 1.64 2006/01/31 23:50:15 martin Exp */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2002 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Martin Husemann <martin@NetBSD.org>.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the NetBSD
|
||||
* Foundation, Inc. and its contributors.
|
||||
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef PPP_OE_H
|
||||
#define PPP_OE_H
|
||||
|
||||
#include "lwip/opt.h"
|
||||
|
||||
#if PPPOE_SUPPORT > 0
|
||||
|
||||
#include "netif/etharp.h"
|
||||
|
||||
#ifdef PACK_STRUCT_USE_INCLUDES
|
||||
# include "arch/bpstruct.h"
|
||||
#endif
|
||||
PACK_STRUCT_BEGIN
|
||||
struct pppoehdr {
|
||||
PACK_STRUCT_FIELD(u8_t vertype);
|
||||
PACK_STRUCT_FIELD(u8_t code);
|
||||
PACK_STRUCT_FIELD(u16_t session);
|
||||
PACK_STRUCT_FIELD(u16_t plen);
|
||||
} PACK_STRUCT_STRUCT;
|
||||
PACK_STRUCT_END
|
||||
#ifdef PACK_STRUCT_USE_INCLUDES
|
||||
# include "arch/epstruct.h"
|
||||
#endif
|
||||
|
||||
#ifdef PACK_STRUCT_USE_INCLUDES
|
||||
# include "arch/bpstruct.h"
|
||||
#endif
|
||||
PACK_STRUCT_BEGIN
|
||||
struct pppoetag {
|
||||
PACK_STRUCT_FIELD(u16_t tag);
|
||||
PACK_STRUCT_FIELD(u16_t len);
|
||||
} PACK_STRUCT_STRUCT;
|
||||
PACK_STRUCT_END
|
||||
#ifdef PACK_STRUCT_USE_INCLUDES
|
||||
# include "arch/epstruct.h"
|
||||
#endif
|
||||
|
||||
|
||||
#define PPPOE_STATE_INITIAL 0
|
||||
#define PPPOE_STATE_PADI_SENT 1
|
||||
#define PPPOE_STATE_PADR_SENT 2
|
||||
#define PPPOE_STATE_SESSION 3
|
||||
#define PPPOE_STATE_CLOSING 4
|
||||
/* passive */
|
||||
#define PPPOE_STATE_PADO_SENT 1
|
||||
|
||||
#define PPPOE_HEADERLEN sizeof(struct pppoehdr)
|
||||
#define PPPOE_VERTYPE 0x11 /* VER=1, TYPE = 1 */
|
||||
|
||||
#define PPPOE_TAG_EOL 0x0000 /* end of list */
|
||||
#define PPPOE_TAG_SNAME 0x0101 /* service name */
|
||||
#define PPPOE_TAG_ACNAME 0x0102 /* access concentrator name */
|
||||
#define PPPOE_TAG_HUNIQUE 0x0103 /* host unique */
|
||||
#define PPPOE_TAG_ACCOOKIE 0x0104 /* AC cookie */
|
||||
#define PPPOE_TAG_VENDOR 0x0105 /* vendor specific */
|
||||
#define PPPOE_TAG_RELAYSID 0x0110 /* relay session id */
|
||||
#define PPPOE_TAG_SNAME_ERR 0x0201 /* service name error */
|
||||
#define PPPOE_TAG_ACSYS_ERR 0x0202 /* AC system error */
|
||||
#define PPPOE_TAG_GENERIC_ERR 0x0203 /* gerneric error */
|
||||
|
||||
#define PPPOE_CODE_PADI 0x09 /* Active Discovery Initiation */
|
||||
#define PPPOE_CODE_PADO 0x07 /* Active Discovery Offer */
|
||||
#define PPPOE_CODE_PADR 0x19 /* Active Discovery Request */
|
||||
#define PPPOE_CODE_PADS 0x65 /* Active Discovery Session confirmation */
|
||||
#define PPPOE_CODE_PADT 0xA7 /* Active Discovery Terminate */
|
||||
|
||||
#ifndef ETHERMTU
|
||||
#define ETHERMTU 1500
|
||||
#endif
|
||||
|
||||
/* two byte PPP protocol discriminator, then IP data */
|
||||
#define PPPOE_MAXMTU (ETHERMTU-PPPOE_HEADERLEN-2)
|
||||
|
||||
#ifndef PPPOE_MAX_AC_COOKIE_LEN
|
||||
#define PPPOE_MAX_AC_COOKIE_LEN 64
|
||||
#endif
|
||||
|
||||
struct pppoe_softc {
|
||||
struct pppoe_softc *next;
|
||||
struct netif *sc_ethif; /* ethernet interface we are using */
|
||||
int sc_pd; /* ppp unit number */
|
||||
void (*sc_linkStatusCB)(int pd, int up);
|
||||
|
||||
int sc_state; /* discovery phase or session connected */
|
||||
struct eth_addr sc_dest; /* hardware address of concentrator */
|
||||
u16_t sc_session; /* PPPoE session id */
|
||||
|
||||
#ifdef PPPOE_TODO
|
||||
char *sc_service_name; /* if != NULL: requested name of service */
|
||||
char *sc_concentrator_name; /* if != NULL: requested concentrator id */
|
||||
#endif /* PPPOE_TODO */
|
||||
u8_t sc_ac_cookie[PPPOE_MAX_AC_COOKIE_LEN]; /* content of AC cookie we must echo back */
|
||||
size_t sc_ac_cookie_len; /* length of cookie data */
|
||||
#ifdef PPPOE_SERVER
|
||||
u8_t *sc_hunique; /* content of host unique we must echo back */
|
||||
size_t sc_hunique_len; /* length of host unique */
|
||||
#endif
|
||||
int sc_padi_retried; /* number of PADI retries already done */
|
||||
int sc_padr_retried; /* number of PADR retries already done */
|
||||
};
|
||||
|
||||
|
||||
#define pppoe_init() /* compatibility define, no initialization needed */
|
||||
|
||||
err_t pppoe_create(struct netif *ethif, int pd, void (*linkStatusCB)(int pd, int up), struct pppoe_softc **scptr);
|
||||
err_t pppoe_destroy(struct netif *ifp);
|
||||
|
||||
int pppoe_connect(struct pppoe_softc *sc);
|
||||
void pppoe_disconnect(struct pppoe_softc *sc);
|
||||
|
||||
void pppoe_disc_input(struct netif *netif, struct pbuf *p);
|
||||
void pppoe_data_input(struct netif *netif, struct pbuf *p);
|
||||
|
||||
err_t pppoe_xmit(struct pppoe_softc *sc, struct pbuf *pb);
|
||||
|
||||
/** used in ppp.c */
|
||||
#define PPPOE_HDRLEN (sizeof(struct eth_hdr) + PPPOE_HEADERLEN)
|
||||
|
||||
#endif /* PPPOE_SUPPORT */
|
||||
|
||||
#endif /* PPP_OE_H */
|
25
tools/sdk/lwip/include/netif/wlan_lwip_if.h
Normal file
25
tools/sdk/lwip/include/netif/wlan_lwip_if.h
Normal file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2011 Espressif System
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _WLAN_LWIP_IF_H_
|
||||
#define _WLAN_LWIP_IF_H_
|
||||
|
||||
#define LWIP_IF0_PRIO 28
|
||||
#define LWIP_IF1_PRIO 29
|
||||
|
||||
enum {
|
||||
SIG_LWIP_RX = 0,
|
||||
};
|
||||
|
||||
struct netif * eagle_lwip_if_alloc(struct ieee80211_conn *conn, const uint8 *macaddr, struct ip_info *info);
|
||||
struct netif * eagle_lwip_getif(uint8 index);
|
||||
|
||||
#ifndef IOT_SIP_MODE
|
||||
sint8 ieee80211_output_pbuf(struct netif *ifp, struct pbuf* pb);
|
||||
#else
|
||||
sint8 ieee80211_output_pbuf(struct ieee80211_conn *conn, esf_buf *eb);
|
||||
#endif
|
||||
|
||||
#endif /* _WLAN_LWIP_IF_H_ */
|
32
tools/sdk/lwip/src/Makefile
Normal file
32
tools/sdk/lwip/src/Makefile
Normal file
@ -0,0 +1,32 @@
|
||||
TOOLS_PATH ?= ../../../xtensa-lx106-elf/bin/xtensa-lx106-elf-
|
||||
LWIP_LIB ?= liblwip_src.a
|
||||
SDK_PATH ?= $(abspath ../../)
|
||||
|
||||
BUILD_PATH = build
|
||||
LWIP_SRCS = $(patsubst %.c,$(BUILD_PATH)/%.o,$(wildcard */*.c)) $(patsubst %.c,$(BUILD_PATH)/%.o,$(wildcard */*/*.c))
|
||||
|
||||
LWIP_INCLUDE = -Ibuild -I$(SDK_PATH)/include -I$(SDK_PATH)/lwip/include
|
||||
BUILD_FLAGS = -c -Os -g -Wpointer-arith -Wno-implicit-function-declaration -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -falign-functions=4 -MMD -std=gnu99 -ffunction-sections -fdata-sections
|
||||
BUILD_DEFINES = -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ -DLWIP_OPEN_SRC
|
||||
|
||||
CC=$(TOOLS_PATH)gcc
|
||||
AR=$(TOOLS_PATH)ar
|
||||
|
||||
$(BUILD_PATH)/%.h:
|
||||
@mkdir -p $(dir $@)
|
||||
@touch $@
|
||||
|
||||
$(BUILD_PATH)/%.o: %.c
|
||||
@mkdir -p $(dir $@)
|
||||
$(CC) $(BUILD_FLAGS) $(BUILD_DEFINES) $(LWIP_INCLUDE) $< -o $@
|
||||
|
||||
$(LWIP_LIB): $(BUILD_PATH)/user_config.h $(LWIP_SRCS)
|
||||
$(AR) cru $(LWIP_LIB) $(LWIP_SRCS)
|
||||
|
||||
all: $(LWIP_LIB)
|
||||
|
||||
install: all
|
||||
cp -f $(LWIP_LIB) $(SDK_PATH)/lib/$(LWIP_LIB)
|
||||
|
||||
clean:
|
||||
@rm -rf $(BUILD_PATH) $(LWIP_LIB)
|
740
tools/sdk/lwip/src/api/api_lib.c
Normal file
740
tools/sdk/lwip/src/api/api_lib.c
Normal file
@ -0,0 +1,740 @@
|
||||
/**
|
||||
* @file
|
||||
* Sequential API External module
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
||||
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||
* OF SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the lwIP TCP/IP stack.
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
*/
|
||||
|
||||
/* This is the part of the API that is linked with
|
||||
the application */
|
||||
|
||||
#include "lwip/opt.h"
|
||||
|
||||
#if LWIP_NETCONN /* don't build if not configured for use in lwipopts.h */
|
||||
|
||||
#include "lwip/api.h"
|
||||
#include "lwip/tcpip.h"
|
||||
#include "lwip/memp.h"
|
||||
|
||||
#include "lwip/ip.h"
|
||||
#include "lwip/raw.h"
|
||||
#include "lwip/udp.h"
|
||||
#include "lwip/tcp.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/**
|
||||
* Create a new netconn (of a specific type) that has a callback function.
|
||||
* The corresponding pcb is also created.
|
||||
*
|
||||
* @param t the type of 'connection' to create (@see enum netconn_type)
|
||||
* @param proto the IP protocol for RAW IP pcbs
|
||||
* @param callback a function to call on status changes (RX available, TX'ed)
|
||||
* @return a newly allocated struct netconn or
|
||||
* NULL on memory error
|
||||
*/
|
||||
struct netconn*
|
||||
netconn_new_with_proto_and_callback(enum netconn_type t, u8_t proto, netconn_callback callback)
|
||||
{
|
||||
struct netconn *conn;
|
||||
struct api_msg msg;
|
||||
|
||||
conn = netconn_alloc(t, callback);
|
||||
if (conn != NULL) {
|
||||
msg.function = do_newconn;
|
||||
msg.msg.msg.n.proto = proto;
|
||||
msg.msg.conn = conn;
|
||||
if (TCPIP_APIMSG(&msg) != ERR_OK) {
|
||||
LWIP_ASSERT("freeing conn without freeing pcb", conn->pcb.tcp == NULL);
|
||||
LWIP_ASSERT("conn has no op_completed", sys_sem_valid(&conn->op_completed));
|
||||
LWIP_ASSERT("conn has no recvmbox", sys_mbox_valid(&conn->recvmbox));
|
||||
#if LWIP_TCP
|
||||
LWIP_ASSERT("conn->acceptmbox shouldn't exist", !sys_mbox_valid(&conn->acceptmbox));
|
||||
#endif /* LWIP_TCP */
|
||||
sys_sem_free(&conn->op_completed);
|
||||
sys_mbox_free(&conn->recvmbox);
|
||||
memp_free(MEMP_NETCONN, conn);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return conn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close a netconn 'connection' and free its resources.
|
||||
* UDP and RAW connection are completely closed, TCP pcbs might still be in a waitstate
|
||||
* after this returns.
|
||||
*
|
||||
* @param conn the netconn to delete
|
||||
* @return ERR_OK if the connection was deleted
|
||||
*/
|
||||
err_t
|
||||
netconn_delete(struct netconn *conn)
|
||||
{
|
||||
struct api_msg msg;
|
||||
|
||||
/* No ASSERT here because possible to get a (conn == NULL) if we got an accept error */
|
||||
if (conn == NULL) {
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
msg.function = do_delconn;
|
||||
msg.msg.conn = conn;
|
||||
tcpip_apimsg(&msg);
|
||||
|
||||
netconn_free(conn);
|
||||
|
||||
/* don't care for return value of do_delconn since it only calls void functions */
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the local or remote IP address and port of a netconn.
|
||||
* For RAW netconns, this returns the protocol instead of a port!
|
||||
*
|
||||
* @param conn the netconn to query
|
||||
* @param addr a pointer to which to save the IP address
|
||||
* @param port a pointer to which to save the port (or protocol for RAW)
|
||||
* @param local 1 to get the local IP address, 0 to get the remote one
|
||||
* @return ERR_CONN for invalid connections
|
||||
* ERR_OK if the information was retrieved
|
||||
*/
|
||||
err_t
|
||||
netconn_getaddr(struct netconn *conn, ip_addr_t *addr, u16_t *port, u8_t local)
|
||||
{
|
||||
struct api_msg msg;
|
||||
err_t err;
|
||||
|
||||
LWIP_ERROR("netconn_getaddr: invalid conn", (conn != NULL), return ERR_ARG;);
|
||||
LWIP_ERROR("netconn_getaddr: invalid addr", (addr != NULL), return ERR_ARG;);
|
||||
LWIP_ERROR("netconn_getaddr: invalid port", (port != NULL), return ERR_ARG;);
|
||||
|
||||
msg.function = do_getaddr;
|
||||
msg.msg.conn = conn;
|
||||
msg.msg.msg.ad.ipaddr = addr;
|
||||
msg.msg.msg.ad.port = port;
|
||||
msg.msg.msg.ad.local = local;
|
||||
err = TCPIP_APIMSG(&msg);
|
||||
|
||||
NETCONN_SET_SAFE_ERR(conn, err);
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind a netconn to a specific local IP address and port.
|
||||
* Binding one netconn twice might not always be checked correctly!
|
||||
*
|
||||
* @param conn the netconn to bind
|
||||
* @param addr the local IP address to bind the netconn to (use IP_ADDR_ANY
|
||||
* to bind to all addresses)
|
||||
* @param port the local port to bind the netconn to (not used for RAW)
|
||||
* @return ERR_OK if bound, any other err_t on failure
|
||||
*/
|
||||
err_t
|
||||
netconn_bind(struct netconn *conn, ip_addr_t *addr, u16_t port)
|
||||
{
|
||||
struct api_msg msg;
|
||||
err_t err;
|
||||
|
||||
LWIP_ERROR("netconn_bind: invalid conn", (conn != NULL), return ERR_ARG;);
|
||||
|
||||
msg.function = do_bind;
|
||||
msg.msg.conn = conn;
|
||||
msg.msg.msg.bc.ipaddr = addr;
|
||||
msg.msg.msg.bc.port = port;
|
||||
err = TCPIP_APIMSG(&msg);
|
||||
|
||||
NETCONN_SET_SAFE_ERR(conn, err);
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect a netconn to a specific remote IP address and port.
|
||||
*
|
||||
* @param conn the netconn to connect
|
||||
* @param addr the remote IP address to connect to
|
||||
* @param port the remote port to connect to (no used for RAW)
|
||||
* @return ERR_OK if connected, return value of tcp_/udp_/raw_connect otherwise
|
||||
*/
|
||||
err_t
|
||||
netconn_connect(struct netconn *conn, ip_addr_t *addr, u16_t port)
|
||||
{
|
||||
struct api_msg msg;
|
||||
err_t err;
|
||||
|
||||
LWIP_ERROR("netconn_connect: invalid conn", (conn != NULL), return ERR_ARG;);
|
||||
|
||||
msg.function = do_connect;
|
||||
msg.msg.conn = conn;
|
||||
msg.msg.msg.bc.ipaddr = addr;
|
||||
msg.msg.msg.bc.port = port;
|
||||
/* This is the only function which need to not block tcpip_thread */
|
||||
err = tcpip_apimsg(&msg);
|
||||
|
||||
NETCONN_SET_SAFE_ERR(conn, err);
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnect a netconn from its current peer (only valid for UDP netconns).
|
||||
*
|
||||
* @param conn the netconn to disconnect
|
||||
* @return TODO: return value is not set here...
|
||||
*/
|
||||
err_t
|
||||
netconn_disconnect(struct netconn *conn)
|
||||
{
|
||||
struct api_msg msg;
|
||||
err_t err;
|
||||
|
||||
LWIP_ERROR("netconn_disconnect: invalid conn", (conn != NULL), return ERR_ARG;);
|
||||
|
||||
msg.function = do_disconnect;
|
||||
msg.msg.conn = conn;
|
||||
err = TCPIP_APIMSG(&msg);
|
||||
|
||||
NETCONN_SET_SAFE_ERR(conn, err);
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a TCP netconn into listen mode
|
||||
*
|
||||
* @param conn the tcp netconn to set to listen mode
|
||||
* @param backlog the listen backlog, only used if TCP_LISTEN_BACKLOG==1
|
||||
* @return ERR_OK if the netconn was set to listen (UDP and RAW netconns
|
||||
* don't return any error (yet?))
|
||||
*/
|
||||
err_t
|
||||
netconn_listen_with_backlog(struct netconn *conn, u8_t backlog)
|
||||
{
|
||||
#if LWIP_TCP
|
||||
struct api_msg msg;
|
||||
err_t err;
|
||||
|
||||
/* This does no harm. If TCP_LISTEN_BACKLOG is off, backlog is unused. */
|
||||
LWIP_UNUSED_ARG(backlog);
|
||||
|
||||
LWIP_ERROR("netconn_listen: invalid conn", (conn != NULL), return ERR_ARG;);
|
||||
|
||||
msg.function = do_listen;
|
||||
msg.msg.conn = conn;
|
||||
#if TCP_LISTEN_BACKLOG
|
||||
msg.msg.msg.lb.backlog = backlog;
|
||||
#endif /* TCP_LISTEN_BACKLOG */
|
||||
err = TCPIP_APIMSG(&msg);
|
||||
|
||||
NETCONN_SET_SAFE_ERR(conn, err);
|
||||
return err;
|
||||
#else /* LWIP_TCP */
|
||||
LWIP_UNUSED_ARG(conn);
|
||||
LWIP_UNUSED_ARG(backlog);
|
||||
return ERR_ARG;
|
||||
#endif /* LWIP_TCP */
|
||||
}
|
||||
|
||||
/**
|
||||
* Accept a new connection on a TCP listening netconn.
|
||||
*
|
||||
* @param conn the TCP listen netconn
|
||||
* @param new_conn pointer where the new connection is stored
|
||||
* @return ERR_OK if a new connection has been received or an error
|
||||
* code otherwise
|
||||
*/
|
||||
err_t
|
||||
netconn_accept(struct netconn *conn, struct netconn **new_conn)
|
||||
{
|
||||
#if LWIP_TCP
|
||||
struct netconn *newconn;
|
||||
err_t err;
|
||||
#if TCP_LISTEN_BACKLOG
|
||||
struct api_msg msg;
|
||||
#endif /* TCP_LISTEN_BACKLOG */
|
||||
|
||||
LWIP_ERROR("netconn_accept: invalid pointer", (new_conn != NULL), return ERR_ARG;);
|
||||
*new_conn = NULL;
|
||||
LWIP_ERROR("netconn_accept: invalid conn", (conn != NULL), return ERR_ARG;);
|
||||
LWIP_ERROR("netconn_accept: invalid acceptmbox", sys_mbox_valid(&conn->acceptmbox), return ERR_ARG;);
|
||||
|
||||
err = conn->last_err;
|
||||
if (ERR_IS_FATAL(err)) {
|
||||
/* don't recv on fatal errors: this might block the application task
|
||||
waiting on acceptmbox forever! */
|
||||
return err;
|
||||
}
|
||||
|
||||
#if LWIP_SO_RCVTIMEO
|
||||
if (sys_arch_mbox_fetch(&conn->acceptmbox, (void **)&newconn, conn->recv_timeout) == SYS_ARCH_TIMEOUT) {
|
||||
NETCONN_SET_SAFE_ERR(conn, ERR_TIMEOUT);
|
||||
return ERR_TIMEOUT;
|
||||
}
|
||||
#else
|
||||
sys_arch_mbox_fetch(&conn->acceptmbox, (void **)&newconn, 0);
|
||||
#endif /* LWIP_SO_RCVTIMEO*/
|
||||
/* Register event with callback */
|
||||
API_EVENT(conn, NETCONN_EVT_RCVMINUS, 0);
|
||||
|
||||
if (newconn == NULL) {
|
||||
/* connection has been closed */
|
||||
NETCONN_SET_SAFE_ERR(conn, ERR_CLSD);
|
||||
return ERR_CLSD;
|
||||
}
|
||||
#if TCP_LISTEN_BACKLOG
|
||||
/* Let the stack know that we have accepted the connection. */
|
||||
msg.function = do_recv;
|
||||
msg.msg.conn = conn;
|
||||
/* don't care for the return value of do_recv */
|
||||
TCPIP_APIMSG(&msg);
|
||||
#endif /* TCP_LISTEN_BACKLOG */
|
||||
|
||||
*new_conn = newconn;
|
||||
/* don't set conn->last_err: it's only ERR_OK, anyway */
|
||||
return ERR_OK;
|
||||
#else /* LWIP_TCP */
|
||||
LWIP_UNUSED_ARG(conn);
|
||||
LWIP_UNUSED_ARG(new_conn);
|
||||
return ERR_ARG;
|
||||
#endif /* LWIP_TCP */
|
||||
}
|
||||
|
||||
/**
|
||||
* Receive data: actual implementation that doesn't care whether pbuf or netbuf
|
||||
* is received
|
||||
*
|
||||
* @param conn the netconn from which to receive data
|
||||
* @param new_buf pointer where a new pbuf/netbuf is stored when received data
|
||||
* @return ERR_OK if data has been received, an error code otherwise (timeout,
|
||||
* memory error or another error)
|
||||
*/
|
||||
static err_t
|
||||
netconn_recv_data(struct netconn *conn, void **new_buf)
|
||||
{
|
||||
void *buf = NULL;
|
||||
u16_t len;
|
||||
err_t err;
|
||||
#if LWIP_TCP
|
||||
struct api_msg msg;
|
||||
#endif /* LWIP_TCP */
|
||||
|
||||
LWIP_ERROR("netconn_recv: invalid pointer", (new_buf != NULL), return ERR_ARG;);
|
||||
*new_buf = NULL;
|
||||
LWIP_ERROR("netconn_recv: invalid conn", (conn != NULL), return ERR_ARG;);
|
||||
LWIP_ERROR("netconn_accept: invalid recvmbox", sys_mbox_valid(&conn->recvmbox), return ERR_CONN;);
|
||||
|
||||
err = conn->last_err;
|
||||
if (ERR_IS_FATAL(err)) {
|
||||
/* don't recv on fatal errors: this might block the application task
|
||||
waiting on recvmbox forever! */
|
||||
/* @todo: this does not allow us to fetch data that has been put into recvmbox
|
||||
before the fatal error occurred - is that a problem? */
|
||||
return err;
|
||||
}
|
||||
|
||||
#if LWIP_SO_RCVTIMEO
|
||||
if (sys_arch_mbox_fetch(&conn->recvmbox, &buf, conn->recv_timeout) == SYS_ARCH_TIMEOUT) {
|
||||
NETCONN_SET_SAFE_ERR(conn, ERR_TIMEOUT);
|
||||
return ERR_TIMEOUT;
|
||||
}
|
||||
#else
|
||||
sys_arch_mbox_fetch(&conn->recvmbox, &buf, 0);
|
||||
#endif /* LWIP_SO_RCVTIMEO*/
|
||||
|
||||
#if LWIP_TCP
|
||||
if (conn->type == NETCONN_TCP) {
|
||||
if (!netconn_get_noautorecved(conn) || (buf == NULL)) {
|
||||
/* Let the stack know that we have taken the data. */
|
||||
/* TODO: Speedup: Don't block and wait for the answer here
|
||||
(to prevent multiple thread-switches). */
|
||||
msg.function = do_recv;
|
||||
msg.msg.conn = conn;
|
||||
if (buf != NULL) {
|
||||
msg.msg.msg.r.len = ((struct pbuf *)buf)->tot_len;
|
||||
} else {
|
||||
msg.msg.msg.r.len = 1;
|
||||
}
|
||||
/* don't care for the return value of do_recv */
|
||||
TCPIP_APIMSG(&msg);
|
||||
}
|
||||
|
||||
/* If we are closed, we indicate that we no longer wish to use the socket */
|
||||
if (buf == NULL) {
|
||||
API_EVENT(conn, NETCONN_EVT_RCVMINUS, 0);
|
||||
/* Avoid to lose any previous error code */
|
||||
NETCONN_SET_SAFE_ERR(conn, ERR_CLSD);
|
||||
return ERR_CLSD;
|
||||
}
|
||||
len = ((struct pbuf *)buf)->tot_len;
|
||||
}
|
||||
#endif /* LWIP_TCP */
|
||||
#if LWIP_TCP && (LWIP_UDP || LWIP_RAW)
|
||||
else
|
||||
#endif /* LWIP_TCP && (LWIP_UDP || LWIP_RAW) */
|
||||
#if (LWIP_UDP || LWIP_RAW)
|
||||
{
|
||||
LWIP_ASSERT("buf != NULL", buf != NULL);
|
||||
len = netbuf_len((struct netbuf *)buf);
|
||||
}
|
||||
#endif /* (LWIP_UDP || LWIP_RAW) */
|
||||
|
||||
#if LWIP_SO_RCVBUF
|
||||
SYS_ARCH_DEC(conn->recv_avail, len);
|
||||
#endif /* LWIP_SO_RCVBUF */
|
||||
/* Register event with callback */
|
||||
API_EVENT(conn, NETCONN_EVT_RCVMINUS, len);
|
||||
|
||||
LWIP_DEBUGF(API_LIB_DEBUG, ("netconn_recv_data: received %p, len=%"U16_F"\n", buf, len));
|
||||
|
||||
*new_buf = buf;
|
||||
/* don't set conn->last_err: it's only ERR_OK, anyway */
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Receive data (in form of a pbuf) from a TCP netconn
|
||||
*
|
||||
* @param conn the netconn from which to receive data
|
||||
* @param new_buf pointer where a new pbuf is stored when received data
|
||||
* @return ERR_OK if data has been received, an error code otherwise (timeout,
|
||||
* memory error or another error)
|
||||
* ERR_ARG if conn is not a TCP netconn
|
||||
*/
|
||||
err_t
|
||||
netconn_recv_tcp_pbuf(struct netconn *conn, struct pbuf **new_buf)
|
||||
{
|
||||
LWIP_ERROR("netconn_recv: invalid conn", (conn != NULL) &&
|
||||
netconn_type(conn) == NETCONN_TCP, return ERR_ARG;);
|
||||
|
||||
return netconn_recv_data(conn, (void **)new_buf);
|
||||
}
|
||||
|
||||
/**
|
||||
* Receive data (in form of a netbuf containing a packet buffer) from a netconn
|
||||
*
|
||||
* @param conn the netconn from which to receive data
|
||||
* @param new_buf pointer where a new netbuf is stored when received data
|
||||
* @return ERR_OK if data has been received, an error code otherwise (timeout,
|
||||
* memory error or another error)
|
||||
*/
|
||||
err_t
|
||||
netconn_recv(struct netconn *conn, struct netbuf **new_buf)
|
||||
{
|
||||
#if LWIP_TCP
|
||||
struct netbuf *buf = NULL;
|
||||
err_t err;
|
||||
#endif /* LWIP_TCP */
|
||||
|
||||
LWIP_ERROR("netconn_recv: invalid pointer", (new_buf != NULL), return ERR_ARG;);
|
||||
*new_buf = NULL;
|
||||
LWIP_ERROR("netconn_recv: invalid conn", (conn != NULL), return ERR_ARG;);
|
||||
LWIP_ERROR("netconn_accept: invalid recvmbox", sys_mbox_valid(&conn->recvmbox), return ERR_CONN;);
|
||||
|
||||
#if LWIP_TCP
|
||||
if (conn->type == NETCONN_TCP) {
|
||||
struct pbuf *p = NULL;
|
||||
/* This is not a listening netconn, since recvmbox is set */
|
||||
|
||||
buf = (struct netbuf *)memp_malloc(MEMP_NETBUF);
|
||||
if (buf == NULL) {
|
||||
NETCONN_SET_SAFE_ERR(conn, ERR_MEM);
|
||||
return ERR_MEM;
|
||||
}
|
||||
|
||||
err = netconn_recv_data(conn, (void **)&p);
|
||||
if (err != ERR_OK) {
|
||||
memp_free(MEMP_NETBUF, buf);
|
||||
return err;
|
||||
}
|
||||
LWIP_ASSERT("p != NULL", p != NULL);
|
||||
|
||||
buf->p = p;
|
||||
buf->ptr = p;
|
||||
buf->port = 0;
|
||||
ip_addr_set_any(&buf->addr);
|
||||
*new_buf = buf;
|
||||
/* don't set conn->last_err: it's only ERR_OK, anyway */
|
||||
return ERR_OK;
|
||||
} else
|
||||
#endif /* LWIP_TCP */
|
||||
{
|
||||
#if (LWIP_UDP || LWIP_RAW)
|
||||
return netconn_recv_data(conn, (void **)new_buf);
|
||||
#endif /* (LWIP_UDP || LWIP_RAW) */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TCP: update the receive window: by calling this, the application
|
||||
* tells the stack that it has processed data and is able to accept
|
||||
* new data.
|
||||
* ATTENTION: use with care, this is mainly used for sockets!
|
||||
* Can only be used when calling netconn_set_noautorecved(conn, 1) before.
|
||||
*
|
||||
* @param conn the netconn for which to update the receive window
|
||||
* @param length amount of data processed (ATTENTION: this must be accurate!)
|
||||
*/
|
||||
void
|
||||
netconn_recved(struct netconn *conn, u32_t length)
|
||||
{
|
||||
#if LWIP_TCP
|
||||
if ((conn != NULL) && (conn->type == NETCONN_TCP) &&
|
||||
(netconn_get_noautorecved(conn))) {
|
||||
struct api_msg msg;
|
||||
/* Let the stack know that we have taken the data. */
|
||||
/* TODO: Speedup: Don't block and wait for the answer here
|
||||
(to prevent multiple thread-switches). */
|
||||
msg.function = do_recv;
|
||||
msg.msg.conn = conn;
|
||||
msg.msg.msg.r.len = length;
|
||||
/* don't care for the return value of do_recv */
|
||||
TCPIP_APIMSG(&msg);
|
||||
}
|
||||
#else /* LWIP_TCP */
|
||||
LWIP_UNUSED_ARG(conn);
|
||||
LWIP_UNUSED_ARG(length);
|
||||
#endif /* LWIP_TCP */
|
||||
}
|
||||
|
||||
/**
|
||||
* Send data (in form of a netbuf) to a specific remote IP address and port.
|
||||
* Only to be used for UDP and RAW netconns (not TCP).
|
||||
*
|
||||
* @param conn the netconn over which to send data
|
||||
* @param buf a netbuf containing the data to send
|
||||
* @param addr the remote IP address to which to send the data
|
||||
* @param port the remote port to which to send the data
|
||||
* @return ERR_OK if data was sent, any other err_t on error
|
||||
*/
|
||||
err_t
|
||||
netconn_sendto(struct netconn *conn, struct netbuf *buf, ip_addr_t *addr, u16_t port)
|
||||
{
|
||||
if (buf != NULL) {
|
||||
ip_addr_set(&buf->addr, addr);
|
||||
buf->port = port;
|
||||
return netconn_send(conn, buf);
|
||||
}
|
||||
return ERR_VAL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send data over a UDP or RAW netconn (that is already connected).
|
||||
*
|
||||
* @param conn the UDP or RAW netconn over which to send data
|
||||
* @param buf a netbuf containing the data to send
|
||||
* @return ERR_OK if data was sent, any other err_t on error
|
||||
*/
|
||||
err_t
|
||||
netconn_send(struct netconn *conn, struct netbuf *buf)
|
||||
{
|
||||
struct api_msg msg;
|
||||
err_t err;
|
||||
|
||||
LWIP_ERROR("netconn_send: invalid conn", (conn != NULL), return ERR_ARG;);
|
||||
|
||||
LWIP_DEBUGF(API_LIB_DEBUG, ("netconn_send: sending %"U16_F" bytes\n", buf->p->tot_len));
|
||||
msg.function = do_send;
|
||||
msg.msg.conn = conn;
|
||||
msg.msg.msg.b = buf;
|
||||
err = TCPIP_APIMSG(&msg);
|
||||
|
||||
NETCONN_SET_SAFE_ERR(conn, err);
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send data over a TCP netconn.
|
||||
*
|
||||
* @param conn the TCP netconn over which to send data
|
||||
* @param dataptr pointer to the application buffer that contains the data to send
|
||||
* @param size size of the application data to send
|
||||
* @param apiflags combination of following flags :
|
||||
* - NETCONN_COPY: data will be copied into memory belonging to the stack
|
||||
* - NETCONN_MORE: for TCP connection, PSH flag will be set on last segment sent
|
||||
* - NETCONN_DONTBLOCK: only write the data if all dat can be written at once
|
||||
* @return ERR_OK if data was sent, any other err_t on error
|
||||
*/
|
||||
err_t
|
||||
netconn_write(struct netconn *conn, const void *dataptr, size_t size, u8_t apiflags)
|
||||
{
|
||||
struct api_msg msg;
|
||||
err_t err;
|
||||
|
||||
LWIP_ERROR("netconn_write: invalid conn", (conn != NULL), return ERR_ARG;);
|
||||
LWIP_ERROR("netconn_write: invalid conn->type", (conn->type == NETCONN_TCP), return ERR_VAL;);
|
||||
if (size == 0) {
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/* @todo: for non-blocking write, check if 'size' would ever fit into
|
||||
snd_queue or snd_buf */
|
||||
msg.function = do_write;
|
||||
msg.msg.conn = conn;
|
||||
msg.msg.msg.w.dataptr = dataptr;
|
||||
msg.msg.msg.w.apiflags = apiflags;
|
||||
msg.msg.msg.w.len = size;
|
||||
/* For locking the core: this _can_ be delayed on low memory/low send buffer,
|
||||
but if it is, this is done inside api_msg.c:do_write(), so we can use the
|
||||
non-blocking version here. */
|
||||
err = TCPIP_APIMSG(&msg);
|
||||
|
||||
NETCONN_SET_SAFE_ERR(conn, err);
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close ot shutdown a TCP netconn (doesn't delete it).
|
||||
*
|
||||
* @param conn the TCP netconn to close or shutdown
|
||||
* @param how fully close or only shutdown one side?
|
||||
* @return ERR_OK if the netconn was closed, any other err_t on error
|
||||
*/
|
||||
static err_t
|
||||
netconn_close_shutdown(struct netconn *conn, u8_t how)
|
||||
{
|
||||
struct api_msg msg;
|
||||
err_t err;
|
||||
|
||||
LWIP_ERROR("netconn_close: invalid conn", (conn != NULL), return ERR_ARG;);
|
||||
|
||||
msg.function = do_close;
|
||||
msg.msg.conn = conn;
|
||||
/* shutting down both ends is the same as closing */
|
||||
msg.msg.msg.sd.shut = how;
|
||||
/* because of the LWIP_TCPIP_CORE_LOCKING implementation of do_close,
|
||||
don't use TCPIP_APIMSG here */
|
||||
err = tcpip_apimsg(&msg);
|
||||
|
||||
NETCONN_SET_SAFE_ERR(conn, err);
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close a TCP netconn (doesn't delete it).
|
||||
*
|
||||
* @param conn the TCP netconn to close
|
||||
* @return ERR_OK if the netconn was closed, any other err_t on error
|
||||
*/
|
||||
err_t
|
||||
netconn_close(struct netconn *conn)
|
||||
{
|
||||
/* shutting down both ends is the same as closing */
|
||||
return netconn_close_shutdown(conn, NETCONN_SHUT_RDWR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shut down one or both sides of a TCP netconn (doesn't delete it).
|
||||
*
|
||||
* @param conn the TCP netconn to shut down
|
||||
* @return ERR_OK if the netconn was closed, any other err_t on error
|
||||
*/
|
||||
err_t
|
||||
netconn_shutdown(struct netconn *conn, u8_t shut_rx, u8_t shut_tx)
|
||||
{
|
||||
return netconn_close_shutdown(conn, (shut_rx ? NETCONN_SHUT_RD : 0) | (shut_tx ? NETCONN_SHUT_WR : 0));
|
||||
}
|
||||
|
||||
#if LWIP_IGMP
|
||||
/**
|
||||
* Join multicast groups for UDP netconns.
|
||||
*
|
||||
* @param conn the UDP netconn for which to change multicast addresses
|
||||
* @param multiaddr IP address of the multicast group to join or leave
|
||||
* @param netif_addr the IP address of the network interface on which to send
|
||||
* the igmp message
|
||||
* @param join_or_leave flag whether to send a join- or leave-message
|
||||
* @return ERR_OK if the action was taken, any err_t on error
|
||||
*/
|
||||
err_t
|
||||
netconn_join_leave_group(struct netconn *conn,
|
||||
ip_addr_t *multiaddr,
|
||||
ip_addr_t *netif_addr,
|
||||
enum netconn_igmp join_or_leave)
|
||||
{
|
||||
struct api_msg msg;
|
||||
err_t err;
|
||||
|
||||
LWIP_ERROR("netconn_join_leave_group: invalid conn", (conn != NULL), return ERR_ARG;);
|
||||
|
||||
msg.function = do_join_leave_group;
|
||||
msg.msg.conn = conn;
|
||||
msg.msg.msg.jl.multiaddr = multiaddr;
|
||||
msg.msg.msg.jl.netif_addr = netif_addr;
|
||||
msg.msg.msg.jl.join_or_leave = join_or_leave;
|
||||
err = TCPIP_APIMSG(&msg);
|
||||
|
||||
NETCONN_SET_SAFE_ERR(conn, err);
|
||||
return err;
|
||||
}
|
||||
#endif /* LWIP_IGMP */
|
||||
|
||||
#if LWIP_DNS
|
||||
/**
|
||||
* Execute a DNS query, only one IP address is returned
|
||||
*
|
||||
* @param name a string representation of the DNS host name to query
|
||||
* @param addr a preallocated ip_addr_t where to store the resolved IP address
|
||||
* @return ERR_OK: resolving succeeded
|
||||
* ERR_MEM: memory error, try again later
|
||||
* ERR_ARG: dns client not initialized or invalid hostname
|
||||
* ERR_VAL: dns server response was invalid
|
||||
*/
|
||||
err_t
|
||||
netconn_gethostbyname(const char *name, ip_addr_t *addr)
|
||||
{
|
||||
struct dns_api_msg msg;
|
||||
err_t err;
|
||||
sys_sem_t sem;
|
||||
|
||||
LWIP_ERROR("netconn_gethostbyname: invalid name", (name != NULL), return ERR_ARG;);
|
||||
LWIP_ERROR("netconn_gethostbyname: invalid addr", (addr != NULL), return ERR_ARG;);
|
||||
|
||||
err = sys_sem_new(&sem, 0);
|
||||
if (err != ERR_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
msg.name = name;
|
||||
msg.addr = addr;
|
||||
msg.err = &err;
|
||||
msg.sem = &sem;
|
||||
|
||||
tcpip_callback(do_gethostbyname, &msg);
|
||||
sys_sem_wait(&sem);
|
||||
sys_sem_free(&sem);
|
||||
|
||||
return err;
|
||||
}
|
||||
#endif /* LWIP_DNS*/
|
||||
|
||||
#endif /* LWIP_NETCONN */
|
1540
tools/sdk/lwip/src/api/api_msg.c
Normal file
1540
tools/sdk/lwip/src/api/api_msg.c
Normal file
File diff suppressed because it is too large
Load Diff
75
tools/sdk/lwip/src/api/err.c
Normal file
75
tools/sdk/lwip/src/api/err.c
Normal file
@ -0,0 +1,75 @@
|
||||
/**
|
||||
* @file
|
||||
* Error Management module
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
||||
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||
* OF SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the lwIP TCP/IP stack.
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
*/
|
||||
|
||||
#include "lwip/err.h"
|
||||
|
||||
#ifdef LWIP_DEBUG
|
||||
|
||||
static const char *err_strerr[] = {
|
||||
"Ok.", /* ERR_OK 0 */
|
||||
"Out of memory error.", /* ERR_MEM -1 */
|
||||
"Buffer error.", /* ERR_BUF -2 */
|
||||
"Timeout.", /* ERR_TIMEOUT -3 */
|
||||
"Routing problem.", /* ERR_RTE -4 */
|
||||
"Operation in progress.", /* ERR_INPROGRESS -5 */
|
||||
"Illegal value.", /* ERR_VAL -6 */
|
||||
"Operation would block.", /* ERR_WOULDBLOCK -7 */
|
||||
"Connection aborted.", /* ERR_ABRT -8 */
|
||||
"Connection reset.", /* ERR_RST -9 */
|
||||
"Connection closed.", /* ERR_CLSD -10 */
|
||||
"Not connected.", /* ERR_CONN -11 */
|
||||
"Illegal argument.", /* ERR_ARG -12 */
|
||||
"Address in use.", /* ERR_USE -13 */
|
||||
"Low-level netif error.", /* ERR_IF -14 */
|
||||
"Already connected.", /* ERR_ISCONN -15 */
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert an lwip internal error to a string representation.
|
||||
*
|
||||
* @param err an lwip internal err_t
|
||||
* @return a string representation for err
|
||||
*/
|
||||
const char *
|
||||
lwip_strerr(err_t err)
|
||||
{
|
||||
return err_strerr[-err];
|
||||
|
||||
}
|
||||
|
||||
#endif /* LWIP_DEBUG */
|
245
tools/sdk/lwip/src/api/netbuf.c
Normal file
245
tools/sdk/lwip/src/api/netbuf.c
Normal file
@ -0,0 +1,245 @@
|
||||
/**
|
||||
* @file
|
||||
* Network buffer management
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
||||
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||
* OF SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the lwIP TCP/IP stack.
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
*/
|
||||
|
||||
#include "lwip/opt.h"
|
||||
|
||||
#if LWIP_NETCONN /* don't build if not configured for use in lwipopts.h */
|
||||
|
||||
#include "lwip/netbuf.h"
|
||||
#include "lwip/memp.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/**
|
||||
* Create (allocate) and initialize a new netbuf.
|
||||
* The netbuf doesn't yet contain a packet buffer!
|
||||
* 申请一个新的netbuf空间,但不分配任何数据空间
|
||||
* @return a pointer to a new netbuf
|
||||
* NULL on lack of memory
|
||||
*/
|
||||
struct
|
||||
netbuf *netbuf_new(void)
|
||||
{
|
||||
struct netbuf *buf;
|
||||
|
||||
buf = (struct netbuf *)memp_malloc(MEMP_NETBUF);
|
||||
if (buf != NULL) {
|
||||
buf->p = NULL;
|
||||
buf->ptr = NULL;
|
||||
ip_addr_set_any(&buf->addr);
|
||||
buf->port = 0;
|
||||
#if LWIP_NETBUF_RECVINFO || LWIP_CHECKSUM_ON_COPY
|
||||
#if LWIP_CHECKSUM_ON_COPY
|
||||
buf->flags = 0;
|
||||
#endif /* LWIP_CHECKSUM_ON_COPY */
|
||||
buf->toport_chksum = 0;
|
||||
#if LWIP_NETBUF_RECVINFO
|
||||
ip_addr_set_any(&buf->toaddr);
|
||||
#endif /* LWIP_NETBUF_RECVINFO */
|
||||
#endif /* LWIP_NETBUF_RECVINFO || LWIP_CHECKSUM_ON_COPY */
|
||||
return buf;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deallocate a netbuf allocated by netbuf_new().
|
||||
* 释放一个netbuf空间
|
||||
* @param buf pointer to a netbuf allocated by netbuf_new()
|
||||
*/
|
||||
void
|
||||
netbuf_delete(struct netbuf *buf)
|
||||
{
|
||||
if (buf != NULL) {
|
||||
if (buf->p != NULL) {
|
||||
pbuf_free(buf->p);
|
||||
buf->p = buf->ptr = NULL;
|
||||
}
|
||||
memp_free(MEMP_NETBUF, buf);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocate memory for a packet buffer for a given netbuf.
|
||||
*为netbuf结构分配size大小的数据空间
|
||||
* @param buf the netbuf for which to allocate a packet buffer
|
||||
* @param size the size of the packet buffer to allocate
|
||||
* @return pointer to the allocated memory
|
||||
* NULL if no memory could be allocated
|
||||
*/
|
||||
void *
|
||||
netbuf_alloc(struct netbuf *buf, u16_t size)
|
||||
{
|
||||
LWIP_ERROR("netbuf_alloc: invalid buf", (buf != NULL), return NULL;);
|
||||
|
||||
/* Deallocate any previously allocated memory. */
|
||||
if (buf->p != NULL) {
|
||||
pbuf_free(buf->p);
|
||||
}
|
||||
buf->p = pbuf_alloc(PBUF_TRANSPORT, size, PBUF_RAM);
|
||||
if (buf->p == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
LWIP_ASSERT("check that first pbuf can hold size",
|
||||
(buf->p->len >= size));
|
||||
buf->ptr = buf->p;
|
||||
return buf->p->payload;
|
||||
}
|
||||
|
||||
/**
|
||||
* Free the packet buffer included in a netbuf
|
||||
*释放netbuf结构指向的数据pbuf
|
||||
* @param buf pointer to the netbuf which contains the packet buffer to free
|
||||
*/
|
||||
void
|
||||
netbuf_free(struct netbuf *buf)
|
||||
{
|
||||
LWIP_ERROR("netbuf_free: invalid buf", (buf != NULL), return;);
|
||||
if (buf->p != NULL) {
|
||||
pbuf_free(buf->p);
|
||||
}
|
||||
buf->p = buf->ptr = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Let a netbuf reference existing (non-volatile) data.
|
||||
*
|
||||
* @param buf netbuf which should reference the data
|
||||
* @param dataptr pointer to the data to reference
|
||||
* @param size size of the data
|
||||
* @return ERR_OK if data is referenced
|
||||
* ERR_MEM if data couldn't be referenced due to lack of memory
|
||||
*/
|
||||
err_t
|
||||
netbuf_ref(struct netbuf *buf, const void *dataptr, u16_t size)
|
||||
{
|
||||
LWIP_ERROR("netbuf_ref: invalid buf", (buf != NULL), return ERR_ARG;);
|
||||
if (buf->p != NULL) {
|
||||
pbuf_free(buf->p);
|
||||
}
|
||||
buf->p = pbuf_alloc(PBUF_TRANSPORT, 0, PBUF_REF);
|
||||
if (buf->p == NULL) {
|
||||
buf->ptr = NULL;
|
||||
return ERR_MEM;
|
||||
}
|
||||
buf->p->payload = (void*)dataptr;
|
||||
buf->p->len = buf->p->tot_len = size;
|
||||
buf->ptr = buf->p;
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Chain one netbuf to another (@see pbuf_chain)
|
||||
*
|
||||
* @param head the first netbuf
|
||||
* @param tail netbuf to chain after head, freed by this function, may not be reference after returning
|
||||
*/
|
||||
void
|
||||
netbuf_chain(struct netbuf *head, struct netbuf *tail)
|
||||
{
|
||||
LWIP_ERROR("netbuf_ref: invalid head", (head != NULL), return;);
|
||||
LWIP_ERROR("netbuf_chain: invalid tail", (tail != NULL), return;);
|
||||
pbuf_cat(head->p, tail->p);
|
||||
head->ptr = head->p;
|
||||
memp_free(MEMP_NETBUF, tail);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the data pointer and length of the data inside a netbuf.
|
||||
*
|
||||
* @param buf netbuf to get the data from
|
||||
* @param dataptr pointer to a void pointer where to store the data pointer
|
||||
* @param len pointer to an u16_t where the length of the data is stored
|
||||
* @return ERR_OK if the information was retreived,
|
||||
* ERR_BUF on error.
|
||||
*/
|
||||
err_t
|
||||
netbuf_data(struct netbuf *buf, void **dataptr, u16_t *len)
|
||||
{
|
||||
LWIP_ERROR("netbuf_data: invalid buf", (buf != NULL), return ERR_ARG;);
|
||||
LWIP_ERROR("netbuf_data: invalid dataptr", (dataptr != NULL), return ERR_ARG;);
|
||||
LWIP_ERROR("netbuf_data: invalid len", (len != NULL), return ERR_ARG;);
|
||||
|
||||
if (buf->ptr == NULL) {
|
||||
return ERR_BUF;
|
||||
}
|
||||
*dataptr = buf->ptr->payload;
|
||||
*len = buf->ptr->len;
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the current data pointer of a packet buffer contained in a netbuf
|
||||
* to the next part.
|
||||
* The packet buffer itself is not modified.
|
||||
*
|
||||
* @param buf the netbuf to modify
|
||||
* @return -1 if there is no next part
|
||||
* 1 if moved to the next part but now there is no next part
|
||||
* 0 if moved to the next part and there are still more parts
|
||||
*/
|
||||
s8_t
|
||||
netbuf_next(struct netbuf *buf)
|
||||
{
|
||||
LWIP_ERROR("netbuf_free: invalid buf", (buf != NULL), return -1;);
|
||||
if (buf->ptr->next == NULL) {
|
||||
return -1;
|
||||
}
|
||||
buf->ptr = buf->ptr->next;
|
||||
if (buf->ptr->next == NULL) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the current data pointer of a packet buffer contained in a netbuf
|
||||
* to the beginning of the packet.
|
||||
* The packet buffer itself is not modified.
|
||||
*
|
||||
* @param buf the netbuf to modify
|
||||
*/
|
||||
void
|
||||
netbuf_first(struct netbuf *buf)
|
||||
{
|
||||
LWIP_ERROR("netbuf_free: invalid buf", (buf != NULL), return;);
|
||||
buf->ptr = buf->p;
|
||||
}
|
||||
|
||||
#endif /* LWIP_NETCONN */
|
352
tools/sdk/lwip/src/api/netdb.c
Normal file
352
tools/sdk/lwip/src/api/netdb.c
Normal file
@ -0,0 +1,352 @@
|
||||
/**
|
||||
* @file
|
||||
* API functions for name resolving
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
||||
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||
* OF SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the lwIP TCP/IP stack.
|
||||
*
|
||||
* Author: Simon Goldschmidt
|
||||
*
|
||||
*/
|
||||
|
||||
#include "lwip/netdb.h"
|
||||
|
||||
#if LWIP_DNS && LWIP_SOCKET
|
||||
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/mem.h"
|
||||
#include "lwip/memp.h"
|
||||
#include "lwip/ip_addr.h"
|
||||
#include "lwip/api.h"
|
||||
#include "lwip/dns.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/** helper struct for gethostbyname_r to access the char* buffer */
|
||||
struct gethostbyname_r_helper {
|
||||
ip_addr_t *addrs;
|
||||
ip_addr_t addr;
|
||||
char *aliases;
|
||||
};
|
||||
|
||||
/** h_errno is exported in netdb.h for access by applications. */
|
||||
#if LWIP_DNS_API_DECLARE_H_ERRNO
|
||||
int h_errno;
|
||||
#endif /* LWIP_DNS_API_DECLARE_H_ERRNO */
|
||||
|
||||
/** define "hostent" variables storage: 0 if we use a static (but unprotected)
|
||||
* set of variables for lwip_gethostbyname, 1 if we use a local storage */
|
||||
#ifndef LWIP_DNS_API_HOSTENT_STORAGE
|
||||
#define LWIP_DNS_API_HOSTENT_STORAGE 0
|
||||
#endif
|
||||
|
||||
/** define "hostent" variables storage */
|
||||
#if LWIP_DNS_API_HOSTENT_STORAGE
|
||||
#define HOSTENT_STORAGE
|
||||
#else
|
||||
#define HOSTENT_STORAGE static
|
||||
#endif /* LWIP_DNS_API_STATIC_HOSTENT */
|
||||
|
||||
/**
|
||||
* Returns an entry containing addresses of address family AF_INET
|
||||
* for the host with name name.
|
||||
* Due to dns_gethostbyname limitations, only one address is returned.
|
||||
*
|
||||
* @param name the hostname to resolve
|
||||
* @return an entry containing addresses of address family AF_INET
|
||||
* for the host with name name
|
||||
*/
|
||||
struct hostent*
|
||||
lwip_gethostbyname(const char *name)
|
||||
{
|
||||
err_t err;
|
||||
ip_addr_t addr;
|
||||
|
||||
/* buffer variables for lwip_gethostbyname() */
|
||||
HOSTENT_STORAGE struct hostent s_hostent;
|
||||
HOSTENT_STORAGE char *s_aliases;
|
||||
HOSTENT_STORAGE ip_addr_t s_hostent_addr;
|
||||
HOSTENT_STORAGE ip_addr_t *s_phostent_addr[2];
|
||||
|
||||
/* query host IP address */
|
||||
err = netconn_gethostbyname(name, &addr);
|
||||
if (err != ERR_OK) {
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("lwip_gethostbyname(%s) failed, err=%d\n", name, err));
|
||||
h_errno = HOST_NOT_FOUND;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* fill hostent */
|
||||
s_hostent_addr = addr;
|
||||
s_phostent_addr[0] = &s_hostent_addr;
|
||||
s_phostent_addr[1] = NULL;
|
||||
s_hostent.h_name = (char*)name;
|
||||
s_hostent.h_aliases = &s_aliases;
|
||||
s_hostent.h_addrtype = AF_INET;
|
||||
s_hostent.h_length = sizeof(ip_addr_t);
|
||||
s_hostent.h_addr_list = (char**)&s_phostent_addr;
|
||||
|
||||
#if DNS_DEBUG
|
||||
/* dump hostent */
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("hostent.h_name == %s\n", s_hostent.h_name));
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("hostent.h_aliases == %p\n", s_hostent.h_aliases));
|
||||
if (s_hostent.h_aliases != NULL) {
|
||||
u8_t idx;
|
||||
for ( idx=0; s_hostent.h_aliases[idx]; idx++) {
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("hostent.h_aliases[%i]-> == %p\n", idx, s_hostent.h_aliases[idx]));
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("hostent.h_aliases[%i]-> == %s\n", idx, s_hostent.h_aliases[idx]));
|
||||
}
|
||||
}
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("hostent.h_addrtype == %d\n", s_hostent.h_addrtype));
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("hostent.h_length == %d\n", s_hostent.h_length));
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("hostent.h_addr_list == %p\n", s_hostent.h_addr_list));
|
||||
if (s_hostent.h_addr_list != NULL) {
|
||||
u8_t idx;
|
||||
for ( idx=0; s_hostent.h_addr_list[idx]; idx++) {
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("hostent.h_addr_list[%i] == %p\n", idx, s_hostent.h_addr_list[idx]));
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("hostent.h_addr_list[%i]-> == %s\n", idx, ip_ntoa((ip_addr_t*)s_hostent.h_addr_list[idx])));
|
||||
}
|
||||
}
|
||||
#endif /* DNS_DEBUG */
|
||||
|
||||
#if LWIP_DNS_API_HOSTENT_STORAGE
|
||||
/* this function should return the "per-thread" hostent after copy from s_hostent */
|
||||
return sys_thread_hostent(&s_hostent);
|
||||
#else
|
||||
return &s_hostent;
|
||||
#endif /* LWIP_DNS_API_HOSTENT_STORAGE */
|
||||
}
|
||||
|
||||
/**
|
||||
* Thread-safe variant of lwip_gethostbyname: instead of using a static
|
||||
* buffer, this function takes buffer and errno pointers as arguments
|
||||
* and uses these for the result.
|
||||
*
|
||||
* @param name the hostname to resolve
|
||||
* @param ret pre-allocated struct where to store the result
|
||||
* @param buf pre-allocated buffer where to store additional data
|
||||
* @param buflen the size of buf
|
||||
* @param result pointer to a hostent pointer that is set to ret on success
|
||||
* and set to zero on error
|
||||
* @param h_errnop pointer to an int where to store errors (instead of modifying
|
||||
* the global h_errno)
|
||||
* @return 0 on success, non-zero on error, additional error information
|
||||
* is stored in *h_errnop instead of h_errno to be thread-safe
|
||||
*/
|
||||
int
|
||||
lwip_gethostbyname_r(const char *name, struct hostent *ret, char *buf,
|
||||
size_t buflen, struct hostent **result, int *h_errnop)
|
||||
{
|
||||
err_t err;
|
||||
struct gethostbyname_r_helper *h;
|
||||
char *hostname;
|
||||
size_t namelen;
|
||||
int lh_errno;
|
||||
|
||||
if (h_errnop == NULL) {
|
||||
/* ensure h_errnop is never NULL */
|
||||
h_errnop = &lh_errno;
|
||||
}
|
||||
|
||||
if (result == NULL) {
|
||||
/* not all arguments given */
|
||||
*h_errnop = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
/* first thing to do: set *result to nothing */
|
||||
*result = NULL;
|
||||
if ((name == NULL) || (ret == NULL) || (buf == 0)) {
|
||||
/* not all arguments given */
|
||||
*h_errnop = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
namelen = strlen(name);
|
||||
if (buflen < (sizeof(struct gethostbyname_r_helper) + namelen + 1 + (MEM_ALIGNMENT - 1))) {
|
||||
/* buf can't hold the data needed + a copy of name */
|
||||
*h_errnop = ERANGE;
|
||||
return -1;
|
||||
}
|
||||
|
||||
h = (struct gethostbyname_r_helper*)LWIP_MEM_ALIGN(buf);
|
||||
hostname = ((char*)h) + sizeof(struct gethostbyname_r_helper);
|
||||
|
||||
/* query host IP address */
|
||||
err = netconn_gethostbyname(name, &(h->addr));
|
||||
if (err != ERR_OK) {
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("lwip_gethostbyname(%s) failed, err=%d\n", name, err));
|
||||
*h_errnop = ENSRNOTFOUND;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* copy the hostname into buf */
|
||||
MEMCPY(hostname, name, namelen);
|
||||
hostname[namelen] = 0;
|
||||
|
||||
/* fill hostent */
|
||||
h->addrs = &(h->addr);
|
||||
h->aliases = NULL;
|
||||
ret->h_name = (char*)hostname;
|
||||
ret->h_aliases = &(h->aliases);
|
||||
ret->h_addrtype = AF_INET;
|
||||
ret->h_length = sizeof(ip_addr_t);
|
||||
ret->h_addr_list = (char**)&(h->addrs);
|
||||
|
||||
/* set result != NULL */
|
||||
*result = ret;
|
||||
|
||||
/* return success */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Frees one or more addrinfo structures returned by getaddrinfo(), along with
|
||||
* any additional storage associated with those structures. If the ai_next field
|
||||
* of the structure is not null, the entire list of structures is freed.
|
||||
*
|
||||
* @param ai struct addrinfo to free
|
||||
*/
|
||||
void
|
||||
lwip_freeaddrinfo(struct addrinfo *ai)
|
||||
{
|
||||
struct addrinfo *next;
|
||||
|
||||
while (ai != NULL) {
|
||||
next = ai->ai_next;
|
||||
memp_free(MEMP_NETDB, ai);
|
||||
ai = next;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates the name of a service location (for example, a host name) and/or
|
||||
* a service name and returns a set of socket addresses and associated
|
||||
* information to be used in creating a socket with which to address the
|
||||
* specified service.
|
||||
* Memory for the result is allocated internally and must be freed by calling
|
||||
* lwip_freeaddrinfo()!
|
||||
*
|
||||
* Due to a limitation in dns_gethostbyname, only the first address of a
|
||||
* host is returned.
|
||||
* Also, service names are not supported (only port numbers)!
|
||||
*
|
||||
* @param nodename descriptive name or address string of the host
|
||||
* (may be NULL -> local address)
|
||||
* @param servname port number as string of NULL
|
||||
* @param hints structure containing input values that set socktype and protocol
|
||||
* @param res pointer to a pointer where to store the result (set to NULL on failure)
|
||||
* @return 0 on success, non-zero on failure
|
||||
*/
|
||||
int
|
||||
lwip_getaddrinfo(const char *nodename, const char *servname,
|
||||
const struct addrinfo *hints, struct addrinfo **res)
|
||||
{
|
||||
err_t err;
|
||||
ip_addr_t addr;
|
||||
struct addrinfo *ai;
|
||||
struct sockaddr_in *sa = NULL;
|
||||
int port_nr = 0;
|
||||
size_t total_size;
|
||||
size_t namelen = 0;
|
||||
|
||||
if (res == NULL) {
|
||||
return EAI_FAIL;
|
||||
}
|
||||
*res = NULL;
|
||||
if ((nodename == NULL) && (servname == NULL)) {
|
||||
return EAI_NONAME;
|
||||
}
|
||||
|
||||
if (servname != NULL) {
|
||||
/* service name specified: convert to port number
|
||||
* @todo?: currently, only ASCII integers (port numbers) are supported! */
|
||||
port_nr = atoi(servname);
|
||||
if ((port_nr <= 0) || (port_nr > 0xffff)) {
|
||||
return EAI_SERVICE;
|
||||
}
|
||||
}
|
||||
|
||||
if (nodename != NULL) {
|
||||
/* service location specified, try to resolve */
|
||||
err = netconn_gethostbyname(nodename, &addr);
|
||||
if (err != ERR_OK) {
|
||||
return EAI_FAIL;
|
||||
}
|
||||
} else {
|
||||
/* service location specified, use loopback address */
|
||||
ip_addr_set_loopback(&addr);
|
||||
}
|
||||
|
||||
total_size = sizeof(struct addrinfo) + sizeof(struct sockaddr_in);
|
||||
if (nodename != NULL) {
|
||||
namelen = strlen(nodename);
|
||||
LWIP_ASSERT("namelen is too long", (namelen + 1) <= (mem_size_t)-1);
|
||||
total_size += namelen + 1;
|
||||
}
|
||||
/* If this fails, please report to lwip-devel! :-) */
|
||||
LWIP_ASSERT("total_size <= NETDB_ELEM_SIZE: please report this!",
|
||||
total_size <= NETDB_ELEM_SIZE);
|
||||
ai = (struct addrinfo *)memp_malloc(MEMP_NETDB);
|
||||
if (ai == NULL) {
|
||||
goto memerr;
|
||||
}
|
||||
memset(ai, 0, total_size);
|
||||
sa = (struct sockaddr_in*)((u8_t*)ai + sizeof(struct addrinfo));
|
||||
/* set up sockaddr */
|
||||
inet_addr_from_ipaddr(&sa->sin_addr, &addr);
|
||||
sa->sin_family = AF_INET;
|
||||
sa->sin_len = sizeof(struct sockaddr_in);
|
||||
sa->sin_port = htons((u16_t)port_nr);
|
||||
|
||||
/* set up addrinfo */
|
||||
ai->ai_family = AF_INET;
|
||||
if (hints != NULL) {
|
||||
/* copy socktype & protocol from hints if specified */
|
||||
ai->ai_socktype = hints->ai_socktype;
|
||||
ai->ai_protocol = hints->ai_protocol;
|
||||
}
|
||||
if (nodename != NULL) {
|
||||
/* copy nodename to canonname if specified */
|
||||
ai->ai_canonname = ((char*)ai + sizeof(struct addrinfo) + sizeof(struct sockaddr_in));
|
||||
MEMCPY(ai->ai_canonname, nodename, namelen);
|
||||
ai->ai_canonname[namelen] = 0;
|
||||
}
|
||||
ai->ai_addrlen = sizeof(struct sockaddr_in);
|
||||
ai->ai_addr = (struct sockaddr*)sa;
|
||||
|
||||
*res = ai;
|
||||
|
||||
return 0;
|
||||
memerr:
|
||||
if (ai != NULL) {
|
||||
memp_free(MEMP_NETDB, ai);
|
||||
}
|
||||
return EAI_MEMORY;
|
||||
}
|
||||
|
||||
#endif /* LWIP_DNS && LWIP_SOCKET */
|
160
tools/sdk/lwip/src/api/netifapi.c
Normal file
160
tools/sdk/lwip/src/api/netifapi.c
Normal file
@ -0,0 +1,160 @@
|
||||
/**
|
||||
* @file
|
||||
* Network Interface Sequential API module
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
||||
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||
* OF SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the lwIP TCP/IP stack.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "lwip/opt.h"
|
||||
|
||||
#if LWIP_NETIF_API /* don't build if not configured for use in lwipopts.h */
|
||||
|
||||
#include "lwip/netifapi.h"
|
||||
#include "lwip/tcpip.h"
|
||||
|
||||
/**
|
||||
* Call netif_add() inside the tcpip_thread context.
|
||||
*/
|
||||
void
|
||||
do_netifapi_netif_add(struct netifapi_msg_msg *msg)
|
||||
{
|
||||
if (!netif_add( msg->netif,
|
||||
msg->msg.add.ipaddr,
|
||||
msg->msg.add.netmask,
|
||||
msg->msg.add.gw,
|
||||
msg->msg.add.state,
|
||||
msg->msg.add.init,
|
||||
msg->msg.add.input)) {
|
||||
msg->err = ERR_IF;
|
||||
} else {
|
||||
msg->err = ERR_OK;
|
||||
}
|
||||
TCPIP_NETIFAPI_ACK(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call netif_set_addr() inside the tcpip_thread context.
|
||||
*/
|
||||
void
|
||||
do_netifapi_netif_set_addr(struct netifapi_msg_msg *msg)
|
||||
{
|
||||
netif_set_addr( msg->netif,
|
||||
msg->msg.add.ipaddr,
|
||||
msg->msg.add.netmask,
|
||||
msg->msg.add.gw);
|
||||
msg->err = ERR_OK;
|
||||
TCPIP_NETIFAPI_ACK(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call the "errtfunc" (or the "voidfunc" if "errtfunc" is NULL) inside the
|
||||
* tcpip_thread context.
|
||||
*/
|
||||
void
|
||||
do_netifapi_netif_common(struct netifapi_msg_msg *msg)
|
||||
{
|
||||
if (msg->msg.common.errtfunc != NULL) {
|
||||
msg->err = msg->msg.common.errtfunc(msg->netif);
|
||||
} else {
|
||||
msg->err = ERR_OK;
|
||||
msg->msg.common.voidfunc(msg->netif);
|
||||
}
|
||||
TCPIP_NETIFAPI_ACK(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call netif_add() in a thread-safe way by running that function inside the
|
||||
* tcpip_thread context.
|
||||
*
|
||||
* @note for params @see netif_add()
|
||||
*/
|
||||
err_t
|
||||
netifapi_netif_add(struct netif *netif,
|
||||
ip_addr_t *ipaddr,
|
||||
ip_addr_t *netmask,
|
||||
ip_addr_t *gw,
|
||||
void *state,
|
||||
netif_init_fn init,
|
||||
netif_input_fn input)
|
||||
{
|
||||
struct netifapi_msg msg;
|
||||
msg.function = do_netifapi_netif_add;
|
||||
msg.msg.netif = netif;
|
||||
msg.msg.msg.add.ipaddr = ipaddr;
|
||||
msg.msg.msg.add.netmask = netmask;
|
||||
msg.msg.msg.add.gw = gw;
|
||||
msg.msg.msg.add.state = state;
|
||||
msg.msg.msg.add.init = init;
|
||||
msg.msg.msg.add.input = input;
|
||||
TCPIP_NETIFAPI(&msg);
|
||||
return msg.msg.err;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call netif_set_addr() in a thread-safe way by running that function inside the
|
||||
* tcpip_thread context.
|
||||
*
|
||||
* @note for params @see netif_set_addr()
|
||||
*/
|
||||
err_t
|
||||
netifapi_netif_set_addr(struct netif *netif,
|
||||
ip_addr_t *ipaddr,
|
||||
ip_addr_t *netmask,
|
||||
ip_addr_t *gw)
|
||||
{
|
||||
struct netifapi_msg msg;
|
||||
msg.function = do_netifapi_netif_set_addr;
|
||||
msg.msg.netif = netif;
|
||||
msg.msg.msg.add.ipaddr = ipaddr;
|
||||
msg.msg.msg.add.netmask = netmask;
|
||||
msg.msg.msg.add.gw = gw;
|
||||
TCPIP_NETIFAPI(&msg);
|
||||
return msg.msg.err;
|
||||
}
|
||||
|
||||
/**
|
||||
* call the "errtfunc" (or the "voidfunc" if "errtfunc" is NULL) in a thread-safe
|
||||
* way by running that function inside the tcpip_thread context.
|
||||
*
|
||||
* @note use only for functions where there is only "netif" parameter.
|
||||
*/
|
||||
err_t
|
||||
netifapi_netif_common(struct netif *netif, netifapi_void_fn voidfunc,
|
||||
netifapi_errt_fn errtfunc)
|
||||
{
|
||||
struct netifapi_msg msg;
|
||||
msg.function = do_netifapi_netif_common;
|
||||
msg.msg.netif = netif;
|
||||
msg.msg.msg.common.voidfunc = voidfunc;
|
||||
msg.msg.msg.common.errtfunc = errtfunc;
|
||||
TCPIP_NETIFAPI(&msg);
|
||||
return msg.msg.err;
|
||||
}
|
||||
|
||||
#endif /* LWIP_NETIF_API */
|
2343
tools/sdk/lwip/src/api/sockets.c
Normal file
2343
tools/sdk/lwip/src/api/sockets.c
Normal file
File diff suppressed because it is too large
Load Diff
460
tools/sdk/lwip/src/api/tcpip.c
Normal file
460
tools/sdk/lwip/src/api/tcpip.c
Normal file
@ -0,0 +1,460 @@
|
||||
/**
|
||||
* @file
|
||||
* Sequential API Main thread module
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
||||
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||
* OF SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the lwIP TCP/IP stack.
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
*/
|
||||
|
||||
#include "lwip/opt.h"
|
||||
|
||||
#if !NO_SYS /* don't build if not configured for use in lwipopts.h */
|
||||
|
||||
#include "lwip/sys.h"
|
||||
#include "lwip/memp.h"
|
||||
#include "lwip/mem.h"
|
||||
#include "lwip/pbuf.h"
|
||||
#include "lwip/tcpip.h"
|
||||
#include "lwip/init.h"
|
||||
#include "netif/etharp.h"
|
||||
#include "netif/ppp_oe.h"
|
||||
|
||||
/* global variables */
|
||||
static tcpip_init_done_fn tcpip_init_done;
|
||||
static void *tcpip_init_done_arg;
|
||||
static sys_mbox_t mbox;
|
||||
|
||||
#if LWIP_TCPIP_CORE_LOCKING
|
||||
/** The global semaphore to lock the stack. */
|
||||
sys_mutex_t lock_tcpip_core;
|
||||
#endif /* LWIP_TCPIP_CORE_LOCKING */
|
||||
|
||||
|
||||
/**
|
||||
* The main lwIP thread. This thread has exclusive access to lwIP core functions
|
||||
* (unless access to them is not locked). Other threads communicate with this
|
||||
* thread using message boxes.
|
||||
*
|
||||
* It also starts all the timers to make sure they are running in the right
|
||||
* thread context.
|
||||
*
|
||||
* @param arg unused argument
|
||||
*/
|
||||
static void
|
||||
tcpip_thread(void *arg)
|
||||
{
|
||||
struct tcpip_msg *msg;
|
||||
LWIP_UNUSED_ARG(arg);
|
||||
|
||||
if (tcpip_init_done != NULL) {//用户注册了自定义初始化函数
|
||||
tcpip_init_done(tcpip_init_done_arg);
|
||||
}
|
||||
|
||||
LOCK_TCPIP_CORE();
|
||||
while (1) { /* MAIN Loop */
|
||||
UNLOCK_TCPIP_CORE();
|
||||
LWIP_TCPIP_THREAD_ALIVE();
|
||||
/* wait for a message, timeouts are processed while waiting */
|
||||
sys_timeouts_mbox_fetch(&mbox, (void **)&msg);
|
||||
LOCK_TCPIP_CORE();
|
||||
switch (msg->type) {
|
||||
#if LWIP_NETCONN
|
||||
case TCPIP_MSG_API://API调用
|
||||
LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: API message %p\n", (void *)msg));
|
||||
msg->msg.apimsg->function(&(msg->msg.apimsg->msg));
|
||||
break;
|
||||
#endif /* LWIP_NETCONN */
|
||||
|
||||
#if !LWIP_TCPIP_CORE_LOCKING_INPUT
|
||||
case TCPIP_MSG_INPKT://底层数据包输入
|
||||
LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: PACKET %p\n", (void *)msg));
|
||||
#if LWIP_ETHERNET
|
||||
if (msg->msg.inp.netif->flags & (NETIF_FLAG_ETHARP | NETIF_FLAG_ETHERNET)) {//支持ARP
|
||||
ethernet_input(msg->msg.inp.p, msg->msg.inp.netif);//交给ARP处理
|
||||
} else
|
||||
#endif /* LWIP_ETHERNET */
|
||||
{
|
||||
ip_input(msg->msg.inp.p, msg->msg.inp.netif);//交给IP处理
|
||||
}
|
||||
memp_free(MEMP_TCPIP_MSG_INPKT, msg);
|
||||
break;
|
||||
#endif /* LWIP_TCPIP_CORE_LOCKING_INPUT */
|
||||
|
||||
#if LWIP_NETIF_API
|
||||
case TCPIP_MSG_NETIFAPI:
|
||||
LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: Netif API message %p\n", (void *)msg));
|
||||
msg->msg.netifapimsg->function(&(msg->msg.netifapimsg->msg));
|
||||
break;
|
||||
#endif /* LWIP_NETIF_API */
|
||||
|
||||
case TCPIP_MSG_CALLBACK://上层回调方式执行一个函数
|
||||
LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: CALLBACK %p\n", (void *)msg));
|
||||
msg->msg.cb.function(msg->msg.cb.ctx);
|
||||
memp_free(MEMP_TCPIP_MSG_API, msg);
|
||||
break;
|
||||
|
||||
#if LWIP_TCPIP_TIMEOUT
|
||||
case TCPIP_MSG_TIMEOUT://上层注册一个定时事件
|
||||
LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: TIMEOUT %p\n", (void *)msg));
|
||||
sys_timeout(msg->msg.tmo.msecs, msg->msg.tmo.h, msg->msg.tmo.arg);
|
||||
memp_free(MEMP_TCPIP_MSG_API, msg);
|
||||
break;
|
||||
case TCPIP_MSG_UNTIMEOUT://上层删除一个定时事件
|
||||
LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: UNTIMEOUT %p\n", (void *)msg));
|
||||
sys_untimeout(msg->msg.tmo.h, msg->msg.tmo.arg);
|
||||
memp_free(MEMP_TCPIP_MSG_API, msg);
|
||||
break;
|
||||
#endif /* LWIP_TCPIP_TIMEOUT */
|
||||
|
||||
default:
|
||||
LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: invalid message: %d\n", msg->type));
|
||||
LWIP_ASSERT("tcpip_thread: invalid message", 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pass a received packet to tcpip_thread for input processing
|
||||
*
|
||||
* @param p the received packet, p->payload pointing to the Ethernet header or
|
||||
* to an IP header (if inp doesn't have NETIF_FLAG_ETHARP or
|
||||
* NETIF_FLAG_ETHERNET flags)
|
||||
* @param inp the network interface on which the packet was received
|
||||
*/
|
||||
err_t
|
||||
tcpip_input(struct pbuf *p, struct netif *inp)
|
||||
{
|
||||
#if LWIP_TCPIP_CORE_LOCKING_INPUT
|
||||
err_t ret;
|
||||
LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_input: PACKET %p/%p\n", (void *)p, (void *)inp));
|
||||
LOCK_TCPIP_CORE();
|
||||
#if LWIP_ETHERNET
|
||||
if (inp->flags & (NETIF_FLAG_ETHARP | NETIF_FLAG_ETHERNET)) {
|
||||
ret = ethernet_input(p, inp);
|
||||
} else
|
||||
#endif /* LWIP_ETHERNET */
|
||||
{
|
||||
ret = ip_input(p, inp);
|
||||
}
|
||||
UNLOCK_TCPIP_CORE();
|
||||
return ret;
|
||||
#else /* LWIP_TCPIP_CORE_LOCKING_INPUT */
|
||||
struct tcpip_msg *msg;
|
||||
|
||||
if (sys_mbox_valid(&mbox)) {
|
||||
msg = (struct tcpip_msg *)memp_malloc(MEMP_TCPIP_MSG_INPKT);
|
||||
if (msg == NULL) {
|
||||
return ERR_MEM;
|
||||
}
|
||||
|
||||
msg->type = TCPIP_MSG_INPKT;
|
||||
msg->msg.inp.p = p;
|
||||
msg->msg.inp.netif = inp;
|
||||
if (sys_mbox_trypost(&mbox, msg) != ERR_OK) {
|
||||
memp_free(MEMP_TCPIP_MSG_INPKT, msg);
|
||||
return ERR_MEM;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
return ERR_VAL;
|
||||
#endif /* LWIP_TCPIP_CORE_LOCKING_INPUT */
|
||||
}
|
||||
|
||||
/**
|
||||
* Call a specific function in the thread context of
|
||||
* tcpip_thread for easy access synchronization.
|
||||
* A function called in that way may access lwIP core code
|
||||
* without fearing concurrent access.
|
||||
*
|
||||
* @param f the function to call
|
||||
* @param ctx parameter passed to f
|
||||
* @param block 1 to block until the request is posted, 0 to non-blocking mode
|
||||
* @return ERR_OK if the function was called, another err_t if not
|
||||
*/
|
||||
err_t
|
||||
tcpip_callback_with_block(tcpip_callback_fn function, void *ctx, u8_t block)
|
||||
{
|
||||
struct tcpip_msg *msg;
|
||||
|
||||
if (sys_mbox_valid(&mbox)) {
|
||||
msg = (struct tcpip_msg *)memp_malloc(MEMP_TCPIP_MSG_API);
|
||||
if (msg == NULL) {
|
||||
return ERR_MEM;
|
||||
}
|
||||
|
||||
msg->type = TCPIP_MSG_CALLBACK;
|
||||
msg->msg.cb.function = function;
|
||||
msg->msg.cb.ctx = ctx;
|
||||
if (block) {
|
||||
sys_mbox_post(&mbox, msg);
|
||||
} else {
|
||||
if (sys_mbox_trypost(&mbox, msg) != ERR_OK) {
|
||||
memp_free(MEMP_TCPIP_MSG_API, msg);
|
||||
return ERR_MEM;
|
||||
}
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
return ERR_VAL;
|
||||
}
|
||||
|
||||
#if LWIP_TCPIP_TIMEOUT
|
||||
/**
|
||||
* call sys_timeout in tcpip_thread
|
||||
*
|
||||
* @param msec time in milliseconds for timeout
|
||||
* @param h function to be called on timeout
|
||||
* @param arg argument to pass to timeout function h
|
||||
* @return ERR_MEM on memory error, ERR_OK otherwise
|
||||
*/
|
||||
err_t
|
||||
tcpip_timeout(u32_t msecs, sys_timeout_handler h, void *arg)
|
||||
{
|
||||
struct tcpip_msg *msg;
|
||||
|
||||
if (sys_mbox_valid(&mbox)) {
|
||||
msg = (struct tcpip_msg *)memp_malloc(MEMP_TCPIP_MSG_API);
|
||||
if (msg == NULL) {
|
||||
return ERR_MEM;
|
||||
}
|
||||
|
||||
msg->type = TCPIP_MSG_TIMEOUT;
|
||||
msg->msg.tmo.msecs = msecs;
|
||||
msg->msg.tmo.h = h;
|
||||
msg->msg.tmo.arg = arg;
|
||||
sys_mbox_post(&mbox, msg);
|
||||
return ERR_OK;
|
||||
}
|
||||
return ERR_VAL;
|
||||
}
|
||||
|
||||
/**
|
||||
* call sys_untimeout in tcpip_thread
|
||||
*
|
||||
* @param msec time in milliseconds for timeout
|
||||
* @param h function to be called on timeout
|
||||
* @param arg argument to pass to timeout function h
|
||||
* @return ERR_MEM on memory error, ERR_OK otherwise
|
||||
*/
|
||||
err_t
|
||||
tcpip_untimeout(sys_timeout_handler h, void *arg)
|
||||
{
|
||||
struct tcpip_msg *msg;
|
||||
|
||||
if (sys_mbox_valid(&mbox)) {
|
||||
msg = (struct tcpip_msg *)memp_malloc(MEMP_TCPIP_MSG_API);
|
||||
if (msg == NULL) {
|
||||
return ERR_MEM;
|
||||
}
|
||||
|
||||
msg->type = TCPIP_MSG_UNTIMEOUT;
|
||||
msg->msg.tmo.h = h;
|
||||
msg->msg.tmo.arg = arg;
|
||||
sys_mbox_post(&mbox, msg);
|
||||
return ERR_OK;
|
||||
}
|
||||
return ERR_VAL;
|
||||
}
|
||||
#endif /* LWIP_TCPIP_TIMEOUT */
|
||||
|
||||
#if LWIP_NETCONN
|
||||
/**
|
||||
* Call the lower part of a netconn_* function
|
||||
* This function is then running in the thread context
|
||||
* of tcpip_thread and has exclusive access to lwIP core code.
|
||||
*
|
||||
* @param apimsg a struct containing the function to call and its parameters
|
||||
* @return ERR_OK if the function was called, another err_t if not
|
||||
*/
|
||||
err_t
|
||||
tcpip_apimsg(struct api_msg *apimsg)
|
||||
{
|
||||
struct tcpip_msg msg;
|
||||
#ifdef LWIP_DEBUG
|
||||
/* catch functions that don't set err */
|
||||
apimsg->msg.err = ERR_VAL;
|
||||
#endif
|
||||
|
||||
if (sys_mbox_valid(&mbox)) {//内核邮箱有效
|
||||
msg.type = TCPIP_MSG_API;
|
||||
msg.msg.apimsg = apimsg;
|
||||
sys_mbox_post(&mbox, &msg);//投递消息
|
||||
sys_arch_sem_wait(&apimsg->msg.conn->op_completed, 0);//等待消息处理完毕
|
||||
return apimsg->msg.err;
|
||||
}
|
||||
return ERR_VAL;
|
||||
}
|
||||
|
||||
#if LWIP_TCPIP_CORE_LOCKING
|
||||
/**
|
||||
* Call the lower part of a netconn_* function
|
||||
* This function has exclusive access to lwIP core code by locking it
|
||||
* before the function is called.
|
||||
*
|
||||
* @param apimsg a struct containing the function to call and its parameters
|
||||
* @return ERR_OK (only for compatibility fo tcpip_apimsg())
|
||||
*/
|
||||
err_t
|
||||
tcpip_apimsg_lock(struct api_msg *apimsg)
|
||||
{
|
||||
#ifdef LWIP_DEBUG
|
||||
/* catch functions that don't set err */
|
||||
apimsg->msg.err = ERR_VAL;
|
||||
#endif
|
||||
|
||||
LOCK_TCPIP_CORE();
|
||||
apimsg->function(&(apimsg->msg));
|
||||
UNLOCK_TCPIP_CORE();
|
||||
return apimsg->msg.err;
|
||||
|
||||
}
|
||||
#endif /* LWIP_TCPIP_CORE_LOCKING */
|
||||
#endif /* LWIP_NETCONN */
|
||||
|
||||
#if LWIP_NETIF_API
|
||||
#if !LWIP_TCPIP_CORE_LOCKING
|
||||
/**
|
||||
* Much like tcpip_apimsg, but calls the lower part of a netifapi_*
|
||||
* function.
|
||||
*
|
||||
* @param netifapimsg a struct containing the function to call and its parameters
|
||||
* @return error code given back by the function that was called
|
||||
*/
|
||||
err_t
|
||||
tcpip_netifapi(struct netifapi_msg* netifapimsg)
|
||||
{
|
||||
struct tcpip_msg msg;
|
||||
|
||||
if (sys_mbox_valid(&mbox)) {
|
||||
err_t err = sys_sem_new(&netifapimsg->msg.sem, 0);
|
||||
if (err != ERR_OK) {
|
||||
netifapimsg->msg.err = err;
|
||||
return err;
|
||||
}
|
||||
|
||||
msg.type = TCPIP_MSG_NETIFAPI;
|
||||
msg.msg.netifapimsg = netifapimsg;
|
||||
sys_mbox_post(&mbox, &msg);
|
||||
sys_sem_wait(&netifapimsg->msg.sem);
|
||||
sys_sem_free(&netifapimsg->msg.sem);
|
||||
return netifapimsg->msg.err;
|
||||
}
|
||||
return ERR_VAL;
|
||||
}
|
||||
#else /* !LWIP_TCPIP_CORE_LOCKING */
|
||||
/**
|
||||
* Call the lower part of a netifapi_* function
|
||||
* This function has exclusive access to lwIP core code by locking it
|
||||
* before the function is called.
|
||||
*
|
||||
* @param netifapimsg a struct containing the function to call and its parameters
|
||||
* @return ERR_OK (only for compatibility fo tcpip_netifapi())
|
||||
*/
|
||||
err_t
|
||||
tcpip_netifapi_lock(struct netifapi_msg* netifapimsg)
|
||||
{
|
||||
LOCK_TCPIP_CORE();
|
||||
netifapimsg->function(&(netifapimsg->msg));
|
||||
UNLOCK_TCPIP_CORE();
|
||||
return netifapimsg->msg.err;
|
||||
}
|
||||
#endif /* !LWIP_TCPIP_CORE_LOCKING */
|
||||
#endif /* LWIP_NETIF_API */
|
||||
|
||||
/**
|
||||
* Initialize this module:
|
||||
* - initialize all sub modules
|
||||
* - start the tcpip_thread
|
||||
*
|
||||
* @param initfunc a function to call when tcpip_thread is running and finished initializing
|
||||
* @param arg argument to pass to initfunc
|
||||
*/
|
||||
void
|
||||
tcpip_init(tcpip_init_done_fn initfunc, void *arg)
|
||||
{
|
||||
lwip_init();//初始化内核
|
||||
|
||||
tcpip_init_done = initfunc;//注册用户自定义函数
|
||||
tcpip_init_done_arg = arg;//函数参数
|
||||
if(sys_mbox_new(&mbox, TCPIP_MBOX_SIZE) != ERR_OK) {//创建内核邮箱
|
||||
LWIP_ASSERT("failed to create tcpip_thread mbox", 0);
|
||||
}
|
||||
#if LWIP_TCPIP_CORE_LOCKING
|
||||
if(sys_mutex_new(&lock_tcpip_core) != ERR_OK) {
|
||||
LWIP_ASSERT("failed to create lock_tcpip_core", 0);
|
||||
}
|
||||
#endif /* LWIP_TCPIP_CORE_LOCKING */
|
||||
|
||||
sys_thread_new(TCPIP_THREAD_NAME, tcpip_thread, NULL, TCPIP_THREAD_STACKSIZE, TCPIP_THREAD_PRIO);//创建内核进程
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple callback function used with tcpip_callback to free a pbuf
|
||||
* (pbuf_free has a wrong signature for tcpip_callback)
|
||||
*
|
||||
* @param p The pbuf (chain) to be dereferenced.
|
||||
*/
|
||||
static void
|
||||
pbuf_free_int(void *p)
|
||||
{
|
||||
struct pbuf *q = (struct pbuf *)p;
|
||||
pbuf_free(q);
|
||||
}
|
||||
|
||||
/**
|
||||
* A simple wrapper function that allows you to free a pbuf from interrupt context.
|
||||
*
|
||||
* @param p The pbuf (chain) to be dereferenced.
|
||||
* @return ERR_OK if callback could be enqueued, an err_t if not
|
||||
*/
|
||||
err_t
|
||||
pbuf_free_callback(struct pbuf *p)
|
||||
{
|
||||
return tcpip_callback_with_block(pbuf_free_int, p, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* A simple wrapper function that allows you to free heap memory from
|
||||
* interrupt context.
|
||||
*
|
||||
* @param m the heap memory to free
|
||||
* @return ERR_OK if callback could be enqueued, an err_t if not
|
||||
*/
|
||||
err_t
|
||||
mem_free_callback(void *m)
|
||||
{
|
||||
return tcpip_callback_with_block(mem_free, m, 0);
|
||||
}
|
||||
|
||||
#endif /* !NO_SYS */
|
1144
tools/sdk/lwip/src/app/dhcpserver.c
Normal file
1144
tools/sdk/lwip/src/app/dhcpserver.c
Normal file
File diff suppressed because it is too large
Load Diff
1303
tools/sdk/lwip/src/app/espconn.c
Normal file
1303
tools/sdk/lwip/src/app/espconn.c
Normal file
File diff suppressed because it is too large
Load Diff
134
tools/sdk/lwip/src/app/espconn_mdns.c
Normal file
134
tools/sdk/lwip/src/app/espconn_mdns.c
Normal file
@ -0,0 +1,134 @@
|
||||
/******************************************************************************
|
||||
* Copyright 2013-2014 Espressif Systems (Wuxi)
|
||||
*
|
||||
* FileName: espconn_mdns.c
|
||||
*
|
||||
* Description: udp proto interface
|
||||
*
|
||||
* Modification history:
|
||||
* 2014/3/31, v1.0 create this file.
|
||||
*******************************************************************************/
|
||||
|
||||
#include "ets_sys.h"
|
||||
#include "os_type.h"
|
||||
|
||||
#include "lwip/mdns.h"
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_mdns_enable
|
||||
* Description : join a multicast group
|
||||
* Parameters : host_ip -- the ip address of udp server
|
||||
* multicast_ip -- multicast ip given by user
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
void ICACHE_FLASH_ATTR
|
||||
espconn_mdns_enable(void)
|
||||
{
|
||||
mdns_enable();
|
||||
}
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_mdns_disable
|
||||
* Description : join a multicast group
|
||||
* Parameters : host_ip -- the ip address of udp server
|
||||
* multicast_ip -- multicast ip given by user
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
void ICACHE_FLASH_ATTR
|
||||
espconn_mdns_disable(void)
|
||||
{
|
||||
mdns_disable();
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_mdns_set_hostname
|
||||
* Description : join a multicast group
|
||||
* Parameters : host_ip -- the ip address of udp server
|
||||
* multicast_ip -- multicast ip given by user
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
void ICACHE_FLASH_ATTR
|
||||
espconn_mdns_set_hostname(char *name)
|
||||
{
|
||||
mdns_set_hostname(name);
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_mdns_init
|
||||
* Description : join a multicast group
|
||||
* Parameters : host_ip -- the ip address of udp server
|
||||
* multicast_ip -- multicast ip given by user
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
char* ICACHE_FLASH_ATTR
|
||||
espconn_mdns_get_hostname(void)
|
||||
{
|
||||
return (char *)mdns_get_hostname();
|
||||
}
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_mdns_get_servername
|
||||
* Description : join a multicast group
|
||||
* Parameters : info -- the info of mdns
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
void ICACHE_FLASH_ATTR
|
||||
espconn_mdns_set_servername(const char *name)
|
||||
{
|
||||
mdns_set_servername(name);
|
||||
}
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_mdns_get_servername
|
||||
* Description : join a multicast group
|
||||
* Parameters : info -- the info of mdns
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
char* ICACHE_FLASH_ATTR
|
||||
espconn_mdns_get_servername(void)
|
||||
{
|
||||
return (char *)mdns_get_servername();
|
||||
}
|
||||
/******************************************************************************
|
||||
* FunctionName : mdns_server_register
|
||||
* Description : join a multicast group
|
||||
* Parameters : info -- the info of mdns
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
void ICACHE_FLASH_ATTR
|
||||
espconn_mdns_server_register(void)
|
||||
{
|
||||
mdns_server_register();
|
||||
}
|
||||
/******************************************************************************
|
||||
* FunctionName : mdns_server_register
|
||||
* Description : join a multicast group
|
||||
* Parameters : info -- the info of mdns
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
void ICACHE_FLASH_ATTR
|
||||
espconn_mdns_server_unregister(void)
|
||||
{
|
||||
mdns_server_unregister();
|
||||
}
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_mdns_init
|
||||
* Description : join a multicast group
|
||||
* Parameters : host_ip -- the ip address of udp server
|
||||
* multicast_ip -- multicast ip given by user
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
void ICACHE_FLASH_ATTR
|
||||
espconn_mdns_close(void)
|
||||
{
|
||||
mdns_close();
|
||||
}
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_mdns_init
|
||||
* Description : join a multicast group
|
||||
* Parameters : host_ip -- the ip address of udp server
|
||||
* multicast_ip -- multicast ip given by user
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
void ICACHE_FLASH_ATTR
|
||||
espconn_mdns_init(struct mdns_info *info)
|
||||
{
|
||||
mdns_init(info);
|
||||
}
|
1390
tools/sdk/lwip/src/app/espconn_tcp.c
Normal file
1390
tools/sdk/lwip/src/app/espconn_tcp.c
Normal file
File diff suppressed because it is too large
Load Diff
423
tools/sdk/lwip/src/app/espconn_udp.c
Normal file
423
tools/sdk/lwip/src/app/espconn_udp.c
Normal file
@ -0,0 +1,423 @@
|
||||
/******************************************************************************
|
||||
* Copyright 2013-2014 Espressif Systems (Wuxi)
|
||||
*
|
||||
* FileName: espconn_udp.c
|
||||
*
|
||||
* Description: udp proto interface
|
||||
*
|
||||
* Modification history:
|
||||
* 2014/3/31, v1.0 create this file.
|
||||
*******************************************************************************/
|
||||
|
||||
#include "ets_sys.h"
|
||||
#include "os_type.h"
|
||||
//#include "os.h"
|
||||
|
||||
#include "lwip/inet.h"
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/pbuf.h"
|
||||
#include "lwip/mem.h"
|
||||
#include "lwip/tcp_impl.h"
|
||||
#include "lwip/udp.h"
|
||||
|
||||
#include "lwip/app/espconn_udp.h"
|
||||
|
||||
#ifdef MEMLEAK_DEBUG
|
||||
static const char mem_debug_file[] ICACHE_RODATA_ATTR = __FILE__;
|
||||
#endif
|
||||
|
||||
extern espconn_msg *plink_active;
|
||||
extern uint8 default_interface;
|
||||
|
||||
enum send_opt{
|
||||
ESPCONN_SENDTO,
|
||||
ESPCONN_SEND
|
||||
};
|
||||
static void ICACHE_FLASH_ATTR espconn_data_sentcb(struct espconn *pespconn)
|
||||
{
|
||||
if (pespconn == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (pespconn->sent_callback != NULL) {
|
||||
pespconn->sent_callback(pespconn);
|
||||
}
|
||||
}
|
||||
|
||||
static void ICACHE_FLASH_ATTR espconn_data_sent(void *arg, enum send_opt opt)
|
||||
{
|
||||
espconn_msg *psent = arg;
|
||||
|
||||
if (psent == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (psent->pcommon.cntr == 0) {
|
||||
psent->pespconn->state = ESPCONN_CONNECT;
|
||||
if (psent->pcommon.err == 0)
|
||||
espconn_data_sentcb(psent->pespconn);
|
||||
} else {
|
||||
if (opt == ESPCONN_SEND){
|
||||
espconn_udp_sent(arg, psent->pcommon.ptrbuf, psent->pcommon.cntr);
|
||||
} else {
|
||||
espconn_udp_sendto(arg, psent->pcommon.ptrbuf, psent->pcommon.cntr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_udp_sent
|
||||
* Description : sent data for client or server
|
||||
* Parameters : void *arg -- client or server to send
|
||||
* uint8* psent -- Data to send
|
||||
* uint16 length -- Length of data to send
|
||||
* Returns : return espconn error code.
|
||||
* - ESPCONN_OK. Successful. No error occured.
|
||||
* - ESPCONN_MEM. Out of memory.
|
||||
* - ESPCONN_RTE. Could not find route to destination address.
|
||||
* - More errors could be returned by lower protocol layers.
|
||||
*******************************************************************************/
|
||||
err_t ICACHE_FLASH_ATTR
|
||||
espconn_udp_sent(void *arg, uint8 *psent, uint16 length)
|
||||
{
|
||||
espconn_msg *pudp_sent = arg;
|
||||
struct udp_pcb *upcb = pudp_sent->pcommon.pcb;
|
||||
struct pbuf *p, *q ,*p_temp;
|
||||
u8_t *data = NULL;
|
||||
u16_t cnt = 0;
|
||||
u16_t datalen = 0;
|
||||
u16_t i = 0;
|
||||
err_t err;
|
||||
LWIP_DEBUGF(ESPCONN_UDP_DEBUG, ("espconn_udp_sent %d %d %p\n", __LINE__, length, upcb));
|
||||
|
||||
if (pudp_sent == NULL || upcb == NULL || psent == NULL || length == 0) {
|
||||
return ESPCONN_ARG;
|
||||
}
|
||||
|
||||
if (1470 < length) {
|
||||
datalen = 1470;
|
||||
} else {
|
||||
datalen = length;
|
||||
}
|
||||
|
||||
p = pbuf_alloc(PBUF_TRANSPORT, datalen, PBUF_RAM);
|
||||
LWIP_DEBUGF(ESPCONN_UDP_DEBUG, ("espconn_udp_sent %d %p\n", __LINE__, p));
|
||||
|
||||
if (p != NULL) {
|
||||
q = p;
|
||||
|
||||
while (q != NULL) {
|
||||
data = (u8_t *)q->payload;
|
||||
LWIP_DEBUGF(ESPCONN_UDP_DEBUG, ("espconn_udp_sent %d %p\n", __LINE__, data));
|
||||
|
||||
for (i = 0; i < q->len; i++) {
|
||||
data[i] = ((u8_t *) psent)[cnt++];
|
||||
}
|
||||
|
||||
q = q->next;
|
||||
}
|
||||
} else {
|
||||
return ESPCONN_MEM;
|
||||
}
|
||||
|
||||
upcb->remote_port = pudp_sent->pespconn->proto.udp->remote_port;
|
||||
IP4_ADDR(&upcb->remote_ip, pudp_sent->pespconn->proto.udp->remote_ip[0],
|
||||
pudp_sent->pespconn->proto.udp->remote_ip[1],
|
||||
pudp_sent->pespconn->proto.udp->remote_ip[2],
|
||||
pudp_sent->pespconn->proto.udp->remote_ip[3]);
|
||||
|
||||
LWIP_DEBUGF(ESPCONN_UDP_DEBUG, ("espconn_udp_sent %d %x %d\n", __LINE__, upcb->remote_ip, upcb->remote_port));
|
||||
|
||||
struct netif *sta_netif = (struct netif *)eagle_lwip_getif(0x00);
|
||||
struct netif *ap_netif = (struct netif *)eagle_lwip_getif(0x01);
|
||||
|
||||
if(wifi_get_opmode() == ESPCONN_AP_STA && default_interface == ESPCONN_AP_STA && sta_netif != NULL && ap_netif != NULL)
|
||||
{
|
||||
if(netif_is_up(sta_netif) && netif_is_up(ap_netif) && \
|
||||
ip_addr_isbroadcast(&upcb->remote_ip, sta_netif) && \
|
||||
ip_addr_isbroadcast(&upcb->remote_ip, ap_netif)) {
|
||||
|
||||
p_temp = pbuf_alloc(PBUF_TRANSPORT, datalen, PBUF_RAM);
|
||||
if (pbuf_copy (p_temp,p) != ERR_OK) {
|
||||
LWIP_DEBUGF(ESPCONN_UDP_DEBUG, ("espconn_udp_sent: copying to new pbuf failed\n"));
|
||||
return ESPCONN_ARG;
|
||||
}
|
||||
netif_set_default(sta_netif);
|
||||
err = udp_send(upcb, p_temp);
|
||||
pbuf_free(p_temp);
|
||||
netif_set_default(ap_netif);
|
||||
}
|
||||
}
|
||||
err = udp_send(upcb, p);
|
||||
|
||||
LWIP_DEBUGF(ESPCONN_UDP_DEBUG, ("espconn_udp_sent %d %d\n", __LINE__, err));
|
||||
|
||||
if (p->ref != 0) {
|
||||
LWIP_DEBUGF(ESPCONN_UDP_DEBUG, ("espconn_udp_sent %d %p\n", __LINE__, p));
|
||||
pbuf_free(p);
|
||||
pudp_sent->pcommon.ptrbuf = psent + datalen;
|
||||
pudp_sent->pcommon.cntr = length - datalen;
|
||||
pudp_sent->pcommon.err = err;
|
||||
espconn_data_sent(pudp_sent, ESPCONN_SEND);
|
||||
if (err > 0)
|
||||
return ESPCONN_IF;
|
||||
return err;
|
||||
} else {
|
||||
pbuf_free(p);
|
||||
return ESPCONN_RTE;
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_udp_sendto
|
||||
* Description : sent data for UDP
|
||||
* Parameters : void *arg -- UDP to send
|
||||
* uint8* psent -- Data to send
|
||||
* uint16 length -- Length of data to send
|
||||
* Returns : return espconn error code.
|
||||
* - ESPCONN_OK. Successful. No error occured.
|
||||
* - ESPCONN_MEM. Out of memory.
|
||||
* - ESPCONN_RTE. Could not find route to destination address.
|
||||
* - More errors could be returned by lower protocol layers.
|
||||
*******************************************************************************/
|
||||
err_t ICACHE_FLASH_ATTR
|
||||
espconn_udp_sendto(void *arg, uint8 *psent, uint16 length)
|
||||
{
|
||||
espconn_msg *pudp_sent = arg;
|
||||
struct udp_pcb *upcb = pudp_sent->pcommon.pcb;
|
||||
struct espconn *pespconn = pudp_sent->pespconn;
|
||||
struct pbuf *p, *q ,*p_temp;
|
||||
struct ip_addr dst_ip;
|
||||
u16_t dst_port;
|
||||
u8_t *data = NULL;
|
||||
u16_t cnt = 0;
|
||||
u16_t datalen = 0;
|
||||
u16_t i = 0;
|
||||
err_t err;
|
||||
LWIP_DEBUGF(ESPCONN_UDP_DEBUG, ("espconn_udp_sent %d %d %p\n", __LINE__, length, upcb));
|
||||
|
||||
if (pudp_sent == NULL || upcb == NULL || psent == NULL || length == 0) {
|
||||
return ESPCONN_ARG;
|
||||
}
|
||||
|
||||
if (1470 < length) {
|
||||
datalen = 1470;
|
||||
} else {
|
||||
datalen = length;
|
||||
}
|
||||
|
||||
p = pbuf_alloc(PBUF_TRANSPORT, datalen, PBUF_RAM);
|
||||
LWIP_DEBUGF(ESPCONN_UDP_DEBUG, ("espconn_udp_sent %d %p\n", __LINE__, p));
|
||||
|
||||
if (p != NULL) {
|
||||
q = p;
|
||||
|
||||
while (q != NULL) {
|
||||
data = (u8_t *)q->payload;
|
||||
LWIP_DEBUGF(ESPCONN_UDP_DEBUG, ("espconn_udp_sent %d %p\n", __LINE__, data));
|
||||
|
||||
for (i = 0; i < q->len; i++) {
|
||||
data[i] = ((u8_t *) psent)[cnt++];
|
||||
}
|
||||
|
||||
q = q->next;
|
||||
}
|
||||
} else {
|
||||
return ESPCONN_MEM;
|
||||
}
|
||||
|
||||
dst_port = pespconn->proto.udp->remote_port;
|
||||
IP4_ADDR(&dst_ip, pespconn->proto.udp->remote_ip[0],
|
||||
pespconn->proto.udp->remote_ip[1], pespconn->proto.udp->remote_ip[2],
|
||||
pespconn->proto.udp->remote_ip[3]);
|
||||
LWIP_DEBUGF(ESPCONN_UDP_DEBUG, ("espconn_udp_sent %d %x %d\n", __LINE__, upcb->remote_ip, upcb->remote_port));
|
||||
|
||||
struct netif *sta_netif = (struct netif *)eagle_lwip_getif(0x00);
|
||||
struct netif *ap_netif = (struct netif *)eagle_lwip_getif(0x01);
|
||||
|
||||
if(wifi_get_opmode() == ESPCONN_AP_STA && default_interface == ESPCONN_AP_STA && sta_netif != NULL && ap_netif != NULL)
|
||||
{
|
||||
if(netif_is_up(sta_netif) && netif_is_up(ap_netif) && \
|
||||
ip_addr_isbroadcast(&upcb->remote_ip, sta_netif) && \
|
||||
ip_addr_isbroadcast(&upcb->remote_ip, ap_netif)) {
|
||||
|
||||
p_temp = pbuf_alloc(PBUF_TRANSPORT, datalen, PBUF_RAM);
|
||||
if (pbuf_copy (p_temp,p) != ERR_OK) {
|
||||
LWIP_DEBUGF(ESPCONN_UDP_DEBUG, ("espconn_udp_sendto: copying to new pbuf failed\n"));
|
||||
return ESPCONN_ARG;
|
||||
}
|
||||
netif_set_default(sta_netif);
|
||||
err = udp_sendto(upcb, p_temp, &dst_ip, dst_port);
|
||||
pbuf_free(p_temp);
|
||||
netif_set_default(ap_netif);
|
||||
}
|
||||
}
|
||||
err = udp_sendto(upcb, p, &dst_ip, dst_port);
|
||||
|
||||
if (p->ref != 0) {
|
||||
pbuf_free(p);
|
||||
pudp_sent->pcommon.ptrbuf = psent + datalen;
|
||||
pudp_sent->pcommon.cntr = length - datalen;
|
||||
pudp_sent->pcommon.err = err;
|
||||
espconn_data_sent(pudp_sent, ESPCONN_SENDTO);
|
||||
|
||||
if (err > 0)
|
||||
return ESPCONN_IF;
|
||||
return err;
|
||||
} else {
|
||||
pbuf_free(p);
|
||||
return ESPCONN_RTE;
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_udp_server_recv
|
||||
* Description : This callback will be called when receiving a datagram.
|
||||
* Parameters : arg -- user supplied argument
|
||||
* upcb -- the udp_pcb which received data
|
||||
* p -- the packet buffer that was received
|
||||
* addr -- the remote IP address from which the packet was received
|
||||
* port -- the remote port from which the packet was received
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
static void ICACHE_FLASH_ATTR
|
||||
espconn_udp_recv(void *arg, struct udp_pcb *upcb, struct pbuf *p,
|
||||
struct ip_addr *addr, u16_t port)
|
||||
{
|
||||
espconn_msg *precv = arg;
|
||||
u8_t *pdata = NULL;
|
||||
u16_t length = 0;
|
||||
struct ip_info ipconfig;
|
||||
|
||||
LWIP_DEBUGF(ESPCONN_UDP_DEBUG, ("espconn_udp_server_recv %d %p\n", __LINE__, upcb));
|
||||
|
||||
precv->pcommon.remote_ip[0] = ip4_addr1_16(addr);
|
||||
precv->pcommon.remote_ip[1] = ip4_addr2_16(addr);
|
||||
precv->pcommon.remote_ip[2] = ip4_addr3_16(addr);
|
||||
precv->pcommon.remote_ip[3] = ip4_addr4_16(addr);
|
||||
precv->pcommon.remote_port = port;
|
||||
precv->pcommon.pcb = upcb;
|
||||
|
||||
if (wifi_get_opmode() != 1) {
|
||||
wifi_get_ip_info(1, &ipconfig);
|
||||
|
||||
if (!ip_addr_netcmp(addr, &ipconfig.ip, &ipconfig.netmask)) {
|
||||
wifi_get_ip_info(0, &ipconfig);
|
||||
}
|
||||
} else {
|
||||
wifi_get_ip_info(0, &ipconfig);
|
||||
}
|
||||
|
||||
precv->pespconn->proto.udp->local_ip[0] = ip4_addr1_16(&ipconfig.ip);
|
||||
precv->pespconn->proto.udp->local_ip[1] = ip4_addr2_16(&ipconfig.ip);
|
||||
precv->pespconn->proto.udp->local_ip[2] = ip4_addr3_16(&ipconfig.ip);
|
||||
precv->pespconn->proto.udp->local_ip[3] = ip4_addr4_16(&ipconfig.ip);
|
||||
|
||||
if (p != NULL) {
|
||||
pdata = (u8_t *)os_zalloc(p ->tot_len + 1);
|
||||
length = pbuf_copy_partial(p, pdata, p ->tot_len, 0);
|
||||
precv->pcommon.pcb = upcb;
|
||||
pbuf_free(p);
|
||||
if (length != 0) {
|
||||
if (precv->pespconn->recv_callback != NULL) {
|
||||
precv->pespconn->recv_callback(precv->pespconn, (char *)pdata, length);
|
||||
}
|
||||
}
|
||||
os_free(pdata);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_udp_disconnect
|
||||
* Description : A new incoming connection has been disconnected.
|
||||
* Parameters : espconn -- the espconn used to disconnect with host
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
void ICACHE_FLASH_ATTR espconn_udp_disconnect(espconn_msg *pdiscon)
|
||||
{
|
||||
if (pdiscon == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct udp_pcb *upcb = pdiscon->pcommon.pcb;
|
||||
|
||||
udp_disconnect(upcb);
|
||||
|
||||
udp_remove(upcb);
|
||||
|
||||
espconn_list_delete(&plink_active, pdiscon);
|
||||
|
||||
os_free(pdiscon);
|
||||
pdiscon = NULL;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_udp_server
|
||||
* Description : Initialize the server: set up a PCB and bind it to the port
|
||||
* Parameters : pespconn -- the espconn used to build server
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
sint8 ICACHE_FLASH_ATTR
|
||||
espconn_udp_server(struct espconn *pespconn)
|
||||
{
|
||||
struct udp_pcb *upcb = NULL;
|
||||
espconn_msg *pserver = NULL;
|
||||
upcb = udp_new();
|
||||
|
||||
if (upcb == NULL) {
|
||||
return ESPCONN_MEM;
|
||||
} else {
|
||||
pserver = (espconn_msg *)os_zalloc(sizeof(espconn_msg));
|
||||
|
||||
if (pserver == NULL) {
|
||||
udp_remove(upcb);
|
||||
return ESPCONN_MEM;
|
||||
}
|
||||
|
||||
pserver->pcommon.pcb = upcb;
|
||||
pserver->pespconn = pespconn;
|
||||
espconn_list_creat(&plink_active, pserver);
|
||||
udp_bind(upcb, IP_ADDR_ANY, pserver->pespconn->proto.udp->local_port);
|
||||
udp_recv(upcb, espconn_udp_recv, (void *)pserver);
|
||||
return ESPCONN_OK;
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_igmp_leave
|
||||
* Description : leave a multicast group
|
||||
* Parameters : host_ip -- the ip address of udp server
|
||||
* multicast_ip -- multicast ip given by user
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
sint8 ICACHE_FLASH_ATTR
|
||||
espconn_igmp_leave(ip_addr_t *host_ip, ip_addr_t *multicast_ip)
|
||||
{
|
||||
if (igmp_leavegroup(host_ip, multicast_ip) != ERR_OK) {
|
||||
LWIP_DEBUGF(ESPCONN_UDP_DEBUG, ("udp_leave_multigrup failed!\n"));
|
||||
return -1;
|
||||
};
|
||||
|
||||
return ESPCONN_OK;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_igmp_join
|
||||
* Description : join a multicast group
|
||||
* Parameters : host_ip -- the ip address of udp server
|
||||
* multicast_ip -- multicast ip given by user
|
||||
* Returns : none
|
||||
*******************************************************************************/
|
||||
sint8 ICACHE_FLASH_ATTR
|
||||
espconn_igmp_join(ip_addr_t *host_ip, ip_addr_t *multicast_ip)
|
||||
{
|
||||
if (igmp_joingroup(host_ip, multicast_ip) != ERR_OK) {
|
||||
LWIP_DEBUGF(ESPCONN_UDP_DEBUG, ("udp_join_multigrup failed!\n"));
|
||||
return -1;
|
||||
};
|
||||
|
||||
/* join to any IP address at the port */
|
||||
return ESPCONN_OK;
|
||||
}
|
369
tools/sdk/lwip/src/app/netio.c
Normal file
369
tools/sdk/lwip/src/app/netio.c
Normal file
@ -0,0 +1,369 @@
|
||||
/**
|
||||
* @file
|
||||
* MetIO Server
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
||||
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||
* OF SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the lwIP TCP/IP stack.
|
||||
*
|
||||
*/
|
||||
#include "lwip/opt.h"
|
||||
|
||||
#if LWIP_TCP
|
||||
#include "lwip/tcp.h"
|
||||
|
||||
#ifdef MEMLEAK_DEBUG
|
||||
static const char mem_debug_file[] ICACHE_RODATA_ATTR = __FILE__;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This implements a netio server.
|
||||
* The client sends a command word (4 bytes) then a data length word (4 bytes).
|
||||
* If the command is "receive", the server is to consume "data length" bytes into
|
||||
* a circular buffer until the first byte is non-zero, then it is to consume
|
||||
* another command/data pair.
|
||||
* If the command is "send", the server is to send "data length" bytes from a circular
|
||||
* buffer with the first byte being zero, until "some time" (6 seconds in the
|
||||
* current netio126.zip download) has passed and then send one final buffer with
|
||||
* the first byte being non-zero. Then it is to consume another command/data pair.
|
||||
*/
|
||||
|
||||
/* See http://www.nwlab.net/art/netio/netio.html to get the netio tool */
|
||||
|
||||
/* implementation options */
|
||||
#define NETIO_BUF_SIZE (4 * 1024)
|
||||
#define NETIO_USE_STATIC_BUF 0
|
||||
|
||||
/* NetIO server state definition */
|
||||
#define NETIO_STATE_WAIT_FOR_CMD 0
|
||||
#define NETIO_STATE_RECV_DATA 1
|
||||
#define NETIO_STATE_SEND_DATA 2
|
||||
#define NETIO_STATE_SEND_DATA_LAST 3
|
||||
#define NETIO_STATE_DONE 4
|
||||
|
||||
struct netio_state {
|
||||
u32_t state;
|
||||
u32_t cmd;
|
||||
u32_t data_len;
|
||||
u32_t cntr;
|
||||
u8_t * buf_ptr;
|
||||
u32_t buf_pos;
|
||||
u32_t first_byte;
|
||||
u32_t time_stamp;
|
||||
};
|
||||
|
||||
/* NetIO command protocol definition */
|
||||
#define NETIO_CMD_QUIT 0
|
||||
#define NETIO_CMD_C2S 1
|
||||
#define NETIO_CMD_S2C 2
|
||||
#define NETIO_CMD_RES 3
|
||||
|
||||
static err_t netio_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err);
|
||||
|
||||
static void ICACHE_FLASH_ATTR
|
||||
netio_close(void *arg, struct tcp_pcb *pcb)
|
||||
{
|
||||
err_t err;
|
||||
|
||||
struct netio_state *ns = arg;
|
||||
ns->state = NETIO_STATE_DONE;
|
||||
tcp_recv(pcb, NULL);
|
||||
err = tcp_close(pcb);
|
||||
|
||||
if (err != ERR_OK) {
|
||||
/* closing failed, try again later */
|
||||
tcp_recv(pcb, netio_recv);
|
||||
} else {
|
||||
/* closing succeeded */
|
||||
#if NETIO_USE_STATIC_BUF != 1
|
||||
if(ns->buf_ptr != NULL){
|
||||
mem_free(ns->buf_ptr);
|
||||
}
|
||||
#endif
|
||||
tcp_arg(pcb, NULL);
|
||||
tcp_poll(pcb, NULL, 0);
|
||||
tcp_sent(pcb, NULL);
|
||||
if (arg != NULL) {
|
||||
mem_free(arg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static err_t ICACHE_FLASH_ATTR
|
||||
netio_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
|
||||
{
|
||||
struct netio_state *ns = arg;
|
||||
u8_t * data_ptr;
|
||||
u32_t data_cntr;
|
||||
struct pbuf *q = p;
|
||||
u16_t len;
|
||||
|
||||
if (p != NULL) {
|
||||
tcp_recved(pcb, p->tot_len);
|
||||
}
|
||||
|
||||
if (err == ERR_OK && q != NULL) {
|
||||
|
||||
while (q != NULL) {
|
||||
data_cntr = q->len;
|
||||
data_ptr = q->payload;
|
||||
while (data_cntr--) {
|
||||
if (ns->state == NETIO_STATE_DONE){
|
||||
netio_close(ns, pcb);
|
||||
break;
|
||||
} else if (ns->state == NETIO_STATE_WAIT_FOR_CMD) {
|
||||
if (ns->cntr < 4) {
|
||||
/* build up the CMD field */
|
||||
ns->cmd <<= 8;
|
||||
ns->cmd |= *data_ptr++;
|
||||
ns->cntr++;
|
||||
} else if (ns->cntr < 8) {
|
||||
/* build up the DATA field */
|
||||
ns->data_len <<= 8;
|
||||
ns->data_len |= *data_ptr++;
|
||||
ns->cntr++;
|
||||
|
||||
if (ns->cntr == 8) {
|
||||
/* now we have full command and data words */
|
||||
ns->cntr = 0;
|
||||
ns->buf_pos = 0;
|
||||
ns->buf_ptr[0] = 0;
|
||||
if (ns->cmd == NETIO_CMD_C2S) {
|
||||
ns->state = NETIO_STATE_RECV_DATA;
|
||||
} else if (ns->cmd == NETIO_CMD_S2C) {
|
||||
ns->state = NETIO_STATE_SEND_DATA;
|
||||
/* start timer */
|
||||
ns->time_stamp = sys_now();
|
||||
/* send first round of data */
|
||||
|
||||
len = tcp_sndbuf(pcb);
|
||||
len = LWIP_MIN(len, ns->data_len - ns->cntr);
|
||||
len = LWIP_MIN(len, NETIO_BUF_SIZE - ns->buf_pos);
|
||||
|
||||
do {
|
||||
err = tcp_write(pcb, ns->buf_ptr + ns->buf_pos, len, TCP_WRITE_FLAG_COPY);
|
||||
if (err == ERR_MEM) {
|
||||
len /= 2;
|
||||
}
|
||||
} while ((err == ERR_MEM) && (len > 1));
|
||||
|
||||
ns->buf_pos += len;
|
||||
ns->cntr += len;
|
||||
|
||||
} else {
|
||||
/* unrecognized command, punt */
|
||||
ns->cntr = 0;
|
||||
ns->buf_pos = 0;
|
||||
ns->buf_ptr[0] = 0;
|
||||
netio_close(ns, pcb);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* in trouble... shouldn't be in this state! */
|
||||
}
|
||||
|
||||
} else if (ns->state == NETIO_STATE_RECV_DATA) {
|
||||
|
||||
if(ns->cntr == 0){
|
||||
/* save the first byte of this new round of data
|
||||
* this will not match ns->buf_ptr[0] in the case that
|
||||
* NETIO_BUF_SIZE is less than ns->data_len.
|
||||
*/
|
||||
ns->first_byte = *data_ptr;
|
||||
}
|
||||
|
||||
ns->buf_ptr[ns->buf_pos++] = *data_ptr++;
|
||||
ns->cntr++;
|
||||
|
||||
if (ns->buf_pos == NETIO_BUF_SIZE) {
|
||||
/* circularize the buffer */
|
||||
ns->buf_pos = 0;
|
||||
}
|
||||
|
||||
if(ns->cntr == ns->data_len){
|
||||
ns->cntr = 0;
|
||||
if (ns->first_byte != 0) {
|
||||
/* if this last round did not start with 0,
|
||||
* go look for another command */
|
||||
ns->state = NETIO_STATE_WAIT_FOR_CMD;
|
||||
ns->data_len = 0;
|
||||
ns->cmd = 0;
|
||||
/* TODO LWIP_DEBUGF( print out some throughput calculation results... ); */
|
||||
} else {
|
||||
/* stay here and wait on more data */
|
||||
}
|
||||
}
|
||||
|
||||
} else if (ns->state == NETIO_STATE_SEND_DATA
|
||||
|| ns->state == NETIO_STATE_SEND_DATA_LAST) {
|
||||
/* I don't think this should happen... */
|
||||
} else {
|
||||
/* done / quit */
|
||||
netio_close(ns, pcb);
|
||||
break;
|
||||
} /* end of ns->state condition */
|
||||
} /* end of while data still in this pbuf */
|
||||
|
||||
q = q->next;
|
||||
}
|
||||
|
||||
pbuf_free(p);
|
||||
|
||||
} else {
|
||||
|
||||
/* error or closed by other side */
|
||||
if (p != NULL) {
|
||||
pbuf_free(p);
|
||||
}
|
||||
|
||||
/* close the connection */
|
||||
netio_close(ns, pcb);
|
||||
|
||||
}
|
||||
return ERR_OK;
|
||||
|
||||
}
|
||||
|
||||
static err_t ICACHE_FLASH_ATTR
|
||||
netio_sent(void *arg, struct tcp_pcb *pcb, u16_t len)
|
||||
{
|
||||
struct netio_state *ns = arg;
|
||||
err_t err = ERR_OK;
|
||||
|
||||
if (ns->cntr >= ns->data_len && ns->state == NETIO_STATE_SEND_DATA) {
|
||||
/* done with this round of sending */
|
||||
ns->buf_pos = 0;
|
||||
ns->cntr = 0;
|
||||
|
||||
/* check if timer expired */
|
||||
if (sys_now() - ns->time_stamp > 600) {
|
||||
ns->buf_ptr[0] = 1;
|
||||
ns->state = NETIO_STATE_SEND_DATA_LAST;
|
||||
} else {
|
||||
ns->buf_ptr[0] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if(ns->state == NETIO_STATE_SEND_DATA_LAST || ns->state == NETIO_STATE_SEND_DATA){
|
||||
len = tcp_sndbuf(pcb);
|
||||
len = LWIP_MIN(len, ns->data_len - ns->cntr);
|
||||
len = LWIP_MIN(len, NETIO_BUF_SIZE - ns->buf_pos);
|
||||
|
||||
if(ns->cntr < ns->data_len){
|
||||
do {
|
||||
err = tcp_write(pcb, ns->buf_ptr + ns->buf_pos, len, TCP_WRITE_FLAG_COPY);
|
||||
if (err == ERR_MEM) {
|
||||
len /= 2;
|
||||
}
|
||||
} while ((err == ERR_MEM) && (len > 1));
|
||||
|
||||
ns->buf_pos += len;
|
||||
if(ns->buf_pos >= NETIO_BUF_SIZE){
|
||||
ns->buf_pos = 0;
|
||||
}
|
||||
|
||||
ns->cntr += len;
|
||||
}
|
||||
}
|
||||
|
||||
if(ns->cntr >= ns->data_len && ns->state == NETIO_STATE_SEND_DATA_LAST){
|
||||
/* we have buffered up all our data to send this last round, go look for a command */
|
||||
ns->state = NETIO_STATE_WAIT_FOR_CMD;
|
||||
ns->cntr = 0;
|
||||
/* TODO LWIP_DEBUGF( print out some throughput calculation results... ); */
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
static err_t ICACHE_FLASH_ATTR
|
||||
netio_poll(void *arg, struct tcp_pcb *pcb)
|
||||
{
|
||||
struct netio_state * ns = arg;
|
||||
if(ns->state == NETIO_STATE_SEND_DATA){
|
||||
|
||||
} else if(ns->state == NETIO_STATE_DONE){
|
||||
netio_close(ns, pcb);
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
|
||||
}
|
||||
|
||||
#if NETIO_USE_STATIC_BUF == 1
|
||||
static u8_t netio_buf[NETIO_BUF_SIZE];
|
||||
#endif
|
||||
|
||||
static err_t ICACHE_FLASH_ATTR
|
||||
netio_accept(void *arg, struct tcp_pcb *pcb, err_t err)
|
||||
{
|
||||
struct netio_state * ns;
|
||||
|
||||
LWIP_UNUSED_ARG(err);
|
||||
|
||||
ns = (struct netio_state *)mem_malloc(sizeof(struct netio_state));
|
||||
|
||||
if(ns == NULL){
|
||||
return ERR_MEM;
|
||||
}
|
||||
|
||||
ns->state = NETIO_STATE_WAIT_FOR_CMD;
|
||||
ns->data_len = 0;
|
||||
ns->cmd = 0;
|
||||
ns->cntr = 0;
|
||||
ns->buf_pos = 0;
|
||||
#if NETIO_USE_STATIC_BUF == 1
|
||||
ns->buf_ptr = netio_buf;
|
||||
#else
|
||||
ns->buf_ptr = (u8_t *)mem_malloc(NETIO_BUF_SIZE);
|
||||
|
||||
if(ns->buf_ptr == NULL){
|
||||
mem_free(ns);
|
||||
return ERR_MEM;
|
||||
}
|
||||
#endif
|
||||
|
||||
ns->buf_ptr[0] = 0;
|
||||
|
||||
tcp_arg(pcb, ns);
|
||||
tcp_sent(pcb, netio_sent);
|
||||
tcp_recv(pcb, netio_recv);
|
||||
tcp_poll(pcb, netio_poll, 4); /* every 2 seconds */
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
void ICACHE_FLASH_ATTR netio_init(void)
|
||||
{
|
||||
struct tcp_pcb *pcb;
|
||||
|
||||
pcb = tcp_new();
|
||||
tcp_bind(pcb, IP_ADDR_ANY, 18767);
|
||||
pcb = tcp_listen(pcb);
|
||||
tcp_accept(pcb, netio_accept);
|
||||
}
|
||||
|
||||
#endif /* LWIP_TCP */
|
329
tools/sdk/lwip/src/app/ping.c
Normal file
329
tools/sdk/lwip/src/app/ping.c
Normal file
@ -0,0 +1,329 @@
|
||||
/**
|
||||
* @file
|
||||
* Ping sender module
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
||||
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||
* OF SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the lwIP TCP/IP stack.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This is an example of a "ping" sender (with raw API and socket API).
|
||||
* It can be used as a start point to maintain opened a network connection, or
|
||||
* like a network "watchdog" for your device.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* copyright (c) 2010 - 2011 Espressif System
|
||||
*/
|
||||
|
||||
#include "lwip/opt.h"
|
||||
|
||||
#if LWIP_RAW /* don't build if not configured for use in lwipopts.h */
|
||||
|
||||
#include "lwip/mem.h"
|
||||
#include "lwip/raw.h"
|
||||
#include "lwip/icmp.h"
|
||||
#include "lwip/netif.h"
|
||||
#include "lwip/sys.h"
|
||||
#include "lwip/timers.h"
|
||||
#include "lwip/inet_chksum.h"
|
||||
#include "os_type.h"
|
||||
#include "osapi.h"
|
||||
|
||||
#include "lwip/app/ping.h"
|
||||
|
||||
#if PING_USE_SOCKETS
|
||||
#include "lwip/sockets.h"
|
||||
#include "lwip/inet.h"
|
||||
#endif /* PING_USE_SOCKETS */
|
||||
|
||||
#ifdef MEMLEAK_DEBUG
|
||||
static const char mem_debug_file[] ICACHE_RODATA_ATTR = __FILE__;
|
||||
#endif
|
||||
|
||||
/* ping variables */
|
||||
static u16_t ping_seq_num = 0;
|
||||
static u32_t ping_time;
|
||||
|
||||
static void ICACHE_FLASH_ATTR ping_timeout(void* arg)
|
||||
{
|
||||
struct ping_msg *pingmsg = (struct ping_msg *)arg;
|
||||
pingmsg->timeout_count ++;
|
||||
if (pingmsg->ping_opt->recv_function == NULL){
|
||||
os_printf("ping timeout\n");
|
||||
} else {
|
||||
struct ping_resp pingresp;
|
||||
os_bzero(&pingresp, sizeof(struct ping_resp));
|
||||
pingresp.ping_err = -1;
|
||||
pingmsg->ping_opt->recv_function(pingmsg->ping_opt, (void*)&pingresp);
|
||||
}
|
||||
}
|
||||
|
||||
/** Prepare a echo ICMP request */
|
||||
static void ICACHE_FLASH_ATTR
|
||||
ping_prepare_echo( struct icmp_echo_hdr *iecho, u16_t len)
|
||||
{
|
||||
size_t i = 0;
|
||||
size_t data_len = len - sizeof(struct icmp_echo_hdr);
|
||||
|
||||
ICMPH_TYPE_SET(iecho, ICMP_ECHO);
|
||||
ICMPH_CODE_SET(iecho, 0);
|
||||
iecho->chksum = 0;
|
||||
iecho->id = PING_ID;
|
||||
++ ping_seq_num;
|
||||
if (ping_seq_num == 0x7fff)
|
||||
ping_seq_num = 0;
|
||||
|
||||
iecho->seqno = htons(ping_seq_num);
|
||||
|
||||
/* fill the additional data buffer with some data */
|
||||
for(i = 0; i < data_len; i++) {
|
||||
((char*)iecho)[sizeof(struct icmp_echo_hdr) + i] = (char)i;
|
||||
}
|
||||
|
||||
iecho->chksum = inet_chksum(iecho, len);
|
||||
}
|
||||
/*
|
||||
static void ICACHE_FLASH_ATTR
|
||||
ping_prepare_er(struct icmp_echo_hdr *iecho, u16_t len)
|
||||
{
|
||||
|
||||
ICMPH_TYPE_SET(iecho, ICMP_ER);
|
||||
ICMPH_CODE_SET(iecho, 0);
|
||||
iecho->chksum = 0;
|
||||
|
||||
iecho->chksum = inet_chksum(iecho, len);
|
||||
}
|
||||
*/
|
||||
/* Ping using the raw ip */
|
||||
static u8_t ICACHE_FLASH_ATTR
|
||||
ping_recv(void *arg, struct raw_pcb *pcb, struct pbuf *p, ip_addr_t *addr)
|
||||
{
|
||||
struct icmp_echo_hdr *iecho = NULL;
|
||||
static u16_t seqno = 0;
|
||||
struct ping_msg *pingmsg = (struct ping_msg*)arg;
|
||||
|
||||
LWIP_UNUSED_ARG(arg);
|
||||
LWIP_UNUSED_ARG(pcb);
|
||||
LWIP_UNUSED_ARG(addr);
|
||||
LWIP_ASSERT("p != NULL", p != NULL);
|
||||
|
||||
if (pbuf_header( p, -PBUF_IP_HLEN)==0) {
|
||||
iecho = (struct icmp_echo_hdr *)p->payload;
|
||||
|
||||
if ((iecho->id == PING_ID) && (iecho->seqno == htons(ping_seq_num)) && iecho->type == ICMP_ER) {
|
||||
LWIP_DEBUGF( PING_DEBUG, ("ping: recv "));
|
||||
ip_addr_debug_print(PING_DEBUG, addr);
|
||||
LWIP_DEBUGF( PING_DEBUG, (" %"U32_F" ms\n", (sys_now()-ping_time)));
|
||||
if (iecho->seqno != seqno){
|
||||
/* do some ping result processing */
|
||||
{
|
||||
struct ip_hdr *iphdr = NULL;
|
||||
char ipaddrstr[16];
|
||||
ip_addr_t source_ip;
|
||||
sys_untimeout(ping_timeout, pingmsg);
|
||||
os_bzero(&source_ip, sizeof(ip_addr_t));
|
||||
os_bzero(ipaddrstr, sizeof(ipaddrstr));
|
||||
uint32 delay = system_relative_time(pingmsg->ping_sent);
|
||||
delay /= PING_COARSE;
|
||||
iphdr = (struct ip_hdr*)((u8*)iecho - PBUF_IP_HLEN);
|
||||
source_ip.addr = iphdr->src.addr;
|
||||
ipaddr_ntoa_r(&source_ip,ipaddrstr, sizeof(ipaddrstr));
|
||||
if (pingmsg->ping_opt->recv_function == NULL){
|
||||
os_printf("recv %s: byte = %d, time = %d ms, seq = %d\n",ipaddrstr, PING_DATA_SIZE, delay, ntohs(iecho->seqno));
|
||||
} else {
|
||||
struct ping_resp pingresp;
|
||||
os_bzero(&pingresp, sizeof(struct ping_resp));
|
||||
pingresp.bytes = PING_DATA_SIZE;
|
||||
pingresp.resp_time = delay;
|
||||
pingresp.seqno = ntohs(iecho->seqno);
|
||||
pingresp.ping_err = 0;
|
||||
pingmsg->ping_opt->recv_function(pingmsg->ping_opt,(void*) &pingresp);
|
||||
}
|
||||
}
|
||||
seqno = iecho->seqno;
|
||||
}
|
||||
|
||||
PING_RESULT(1);
|
||||
pbuf_free(p);
|
||||
return 1; /* eat the packet */
|
||||
}
|
||||
// } else if(iecho->type == ICMP_ECHO){
|
||||
// struct pbuf *q = NULL;
|
||||
// os_printf("receive ping request:seq=%d\n", ntohs(iecho->seqno));
|
||||
// q = pbuf_alloc(PBUF_IP, (u16_t)p->tot_len, PBUF_RAM);
|
||||
// if (q!=NULL) {
|
||||
// pbuf_copy(q, p);
|
||||
// iecho = (struct icmp_echo_hdr *)q->payload;
|
||||
// ping_prepare_er(iecho, q->tot_len);
|
||||
// raw_sendto(pcb, q, addr);
|
||||
// pbuf_free(q);
|
||||
// }
|
||||
// pbuf_free(p);
|
||||
// return 1;
|
||||
// }
|
||||
}
|
||||
|
||||
return 0; /* don't eat the packet */
|
||||
}
|
||||
|
||||
static void ICACHE_FLASH_ATTR
|
||||
ping_send(struct raw_pcb *raw, ip_addr_t *addr)
|
||||
{
|
||||
struct pbuf *p = NULL;
|
||||
struct icmp_echo_hdr *iecho = NULL;
|
||||
size_t ping_size = sizeof(struct icmp_echo_hdr) + PING_DATA_SIZE;
|
||||
|
||||
LWIP_DEBUGF( PING_DEBUG, ("ping: send "));
|
||||
ip_addr_debug_print(PING_DEBUG, addr);
|
||||
LWIP_DEBUGF( PING_DEBUG, ("\n"));
|
||||
LWIP_ASSERT("ping_size <= 0xffff", ping_size <= 0xffff);
|
||||
|
||||
p = pbuf_alloc(PBUF_IP, (u16_t)ping_size, PBUF_RAM);
|
||||
if (!p) {
|
||||
return;
|
||||
}
|
||||
if ((p->len == p->tot_len) && (p->next == NULL)) {
|
||||
iecho = (struct icmp_echo_hdr *)p->payload;
|
||||
|
||||
ping_prepare_echo(iecho, (u16_t)ping_size);
|
||||
|
||||
raw_sendto(raw, p, addr);
|
||||
ping_time = sys_now();
|
||||
}
|
||||
pbuf_free(p);
|
||||
}
|
||||
|
||||
static void ICACHE_FLASH_ATTR
|
||||
ping_coarse_tmr(void *arg)
|
||||
{
|
||||
struct ping_msg *pingmsg = (struct ping_msg*)arg;
|
||||
struct ping_option *ping_opt= NULL;
|
||||
struct ping_resp pingresp;
|
||||
ip_addr_t ping_target;
|
||||
|
||||
LWIP_ASSERT("ping_timeout: no pcb given!", pingmsg != NULL);
|
||||
ping_target.addr = pingmsg->ping_opt->ip;
|
||||
ping_opt = pingmsg->ping_opt;
|
||||
if (--pingmsg->sent_count != 0){
|
||||
pingmsg ->ping_sent = system_get_time();
|
||||
ping_send(pingmsg->ping_pcb, &ping_target);
|
||||
|
||||
sys_timeout(PING_TIMEOUT_MS, ping_timeout, pingmsg);
|
||||
sys_timeout(pingmsg->coarse_time, ping_coarse_tmr, pingmsg);
|
||||
} else {
|
||||
uint32 delay = system_relative_time(pingmsg->ping_start);
|
||||
delay /= PING_COARSE;
|
||||
// ping_seq_num = 0;
|
||||
if (ping_opt->sent_function == NULL){
|
||||
os_printf("ping %d, timeout %d, total payload %d bytes, %d ms\n",
|
||||
pingmsg->max_count, pingmsg->timeout_count, PING_DATA_SIZE*(pingmsg->max_count - pingmsg->timeout_count),delay);
|
||||
} else {
|
||||
os_bzero(&pingresp, sizeof(struct ping_resp));
|
||||
pingresp.total_count = pingmsg->max_count;
|
||||
pingresp.timeout_count = pingmsg->timeout_count;
|
||||
pingresp.total_bytes = PING_DATA_SIZE*(pingmsg->max_count - pingmsg->timeout_count);
|
||||
pingresp.total_time = delay;
|
||||
pingresp.ping_err = 0;
|
||||
}
|
||||
sys_untimeout(ping_coarse_tmr, pingmsg);
|
||||
raw_remove(pingmsg->ping_pcb);
|
||||
os_free(pingmsg);
|
||||
if (ping_opt->sent_function != NULL)
|
||||
ping_opt->sent_function(ping_opt,(uint8*)&pingresp);
|
||||
}
|
||||
}
|
||||
|
||||
static bool ICACHE_FLASH_ATTR
|
||||
ping_raw_init(struct ping_msg *pingmsg)
|
||||
{
|
||||
if (pingmsg == NULL)
|
||||
return false;
|
||||
|
||||
ip_addr_t ping_target;
|
||||
pingmsg->ping_pcb = raw_new(IP_PROTO_ICMP);
|
||||
LWIP_ASSERT("ping_pcb != NULL", pingmsg->ping_pcb != NULL);
|
||||
|
||||
raw_recv(pingmsg->ping_pcb, ping_recv, pingmsg);
|
||||
raw_bind(pingmsg->ping_pcb, IP_ADDR_ANY);
|
||||
|
||||
ping_target.addr = pingmsg->ping_opt->ip;
|
||||
pingmsg ->ping_sent = system_get_time();
|
||||
ping_send(pingmsg->ping_pcb, &ping_target);
|
||||
|
||||
sys_timeout(PING_TIMEOUT_MS, ping_timeout, pingmsg);
|
||||
sys_timeout(pingmsg->coarse_time, ping_coarse_tmr, pingmsg);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ICACHE_FLASH_ATTR
|
||||
ping_start(struct ping_option *ping_opt)
|
||||
{
|
||||
struct ping_msg *pingmsg = NULL;
|
||||
pingmsg = (struct ping_msg *)os_zalloc(sizeof(struct ping_msg));
|
||||
if (pingmsg == NULL || ping_opt == NULL)
|
||||
return false;
|
||||
|
||||
pingmsg->ping_opt = ping_opt;
|
||||
if (ping_opt->count != 0)
|
||||
pingmsg->max_count = ping_opt->count;
|
||||
else
|
||||
pingmsg->max_count = DEFAULT_PING_MAX_COUNT;
|
||||
|
||||
if (ping_opt->coarse_time != 0)
|
||||
pingmsg->coarse_time = ping_opt->coarse_time * PING_COARSE;
|
||||
else
|
||||
pingmsg->coarse_time = PING_COARSE;
|
||||
|
||||
pingmsg->ping_start = system_get_time();
|
||||
pingmsg->sent_count = pingmsg->max_count;
|
||||
return ping_raw_init(pingmsg);
|
||||
}
|
||||
|
||||
bool ICACHE_FLASH_ATTR
|
||||
ping_regist_recv(struct ping_option *ping_opt, ping_recv_function ping_recv)
|
||||
{
|
||||
if (ping_opt == NULL)
|
||||
return false;
|
||||
|
||||
ping_opt ->recv_function = ping_recv;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ICACHE_FLASH_ATTR
|
||||
ping_regist_sent(struct ping_option *ping_opt, ping_sent_function ping_sent)
|
||||
{
|
||||
if (ping_opt == NULL)
|
||||
return false;
|
||||
|
||||
ping_opt ->sent_function = ping_sent;
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif /* LWIP_RAW */
|
108
tools/sdk/lwip/src/core/def.c
Normal file
108
tools/sdk/lwip/src/core/def.c
Normal file
@ -0,0 +1,108 @@
|
||||
/**
|
||||
* @file
|
||||
* Common functions used throughout the stack.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
||||
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||
* OF SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the lwIP TCP/IP stack.
|
||||
*
|
||||
* Author: Simon Goldschmidt
|
||||
*
|
||||
*/
|
||||
|
||||
#include "lwip/opt.h"
|
||||
#include "lwip/def.h"
|
||||
|
||||
/**
|
||||
* These are reference implementations of the byte swapping functions.
|
||||
* Again with the aim of being simple, correct and fully portable.
|
||||
* Byte swapping is the second thing you would want to optimize. You will
|
||||
* need to port it to your architecture and in your cc.h:
|
||||
*
|
||||
* #define LWIP_PLATFORM_BYTESWAP 1
|
||||
* #define LWIP_PLATFORM_HTONS(x) <your_htons>
|
||||
* #define LWIP_PLATFORM_HTONL(x) <your_htonl>
|
||||
*
|
||||
* Note ntohs() and ntohl() are merely references to the htonx counterparts.
|
||||
*/
|
||||
|
||||
#if (LWIP_PLATFORM_BYTESWAP == 0) && (BYTE_ORDER == LITTLE_ENDIAN)
|
||||
|
||||
/**
|
||||
* Convert an u16_t from host- to network byte order.
|
||||
*
|
||||
* @param n u16_t in host byte order
|
||||
* @return n in network byte order
|
||||
*/
|
||||
u16_t
|
||||
lwip_htons(u16_t n)
|
||||
{
|
||||
return ((n & 0xff) << 8) | ((n & 0xff00) >> 8);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an u16_t from network- to host byte order.
|
||||
*
|
||||
* @param n u16_t in network byte order
|
||||
* @return n in host byte order
|
||||
*/
|
||||
u16_t
|
||||
lwip_ntohs(u16_t n)
|
||||
{
|
||||
return lwip_htons(n);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an u32_t from host- to network byte order.
|
||||
*
|
||||
* @param n u32_t in host byte order
|
||||
* @return n in network byte order
|
||||
*/
|
||||
u32_t
|
||||
lwip_htonl(u32_t n)
|
||||
{
|
||||
return ((n & 0xff) << 24) |
|
||||
((n & 0xff00) << 8) |
|
||||
((n & 0xff0000UL) >> 8) |
|
||||
((n & 0xff000000UL) >> 24);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an u32_t from network- to host byte order.
|
||||
*
|
||||
* @param n u32_t in network byte order
|
||||
* @return n in host byte order
|
||||
*/
|
||||
u32_t
|
||||
lwip_ntohl(u32_t n)
|
||||
{
|
||||
return lwip_htonl(n);
|
||||
}
|
||||
|
||||
#endif /* (LWIP_PLATFORM_BYTESWAP == 0) && (BYTE_ORDER == LITTLE_ENDIAN) */
|
1815
tools/sdk/lwip/src/core/dhcp.c
Normal file
1815
tools/sdk/lwip/src/core/dhcp.c
Normal file
File diff suppressed because it is too large
Load Diff
980
tools/sdk/lwip/src/core/dns.c
Normal file
980
tools/sdk/lwip/src/core/dns.c
Normal file
@ -0,0 +1,980 @@
|
||||
/**
|
||||
* @file
|
||||
* DNS - host name to IP address resolver.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
* This file implements a DNS host name to IP address resolver.
|
||||
|
||||
* Port to lwIP from uIP
|
||||
* by Jim Pettinato April 2007
|
||||
|
||||
* uIP version Copyright (c) 2002-2003, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* DNS.C
|
||||
*
|
||||
* The lwIP DNS resolver functions are used to lookup a host name and
|
||||
* map it to a numerical IP address. It maintains a list of resolved
|
||||
* hostnames that can be queried with the dns_lookup() function.
|
||||
* New hostnames can be resolved using the dns_query() function.
|
||||
*
|
||||
* The lwIP version of the resolver also adds a non-blocking version of
|
||||
* gethostbyname() that will work with a raw API application. This function
|
||||
* checks for an IP address string first and converts it if it is valid.
|
||||
* gethostbyname() then does a dns_lookup() to see if the name is
|
||||
* already in the table. If so, the IP is returned. If not, a query is
|
||||
* issued and the function returns with a ERR_INPROGRESS status. The app
|
||||
* using the dns client must then go into a waiting state.
|
||||
*
|
||||
* Once a hostname has been resolved (or found to be non-existent),
|
||||
* the resolver code calls a specified callback function (which
|
||||
* must be implemented by the module that uses the resolver).
|
||||
*/
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
* RFC 1035 - Domain names - implementation and specification
|
||||
* RFC 2181 - Clarifications to the DNS Specification
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
/** @todo: define good default values (rfc compliance) */
|
||||
/** @todo: improve answer parsing, more checkings... */
|
||||
/** @todo: check RFC1035 - 7.3. Processing responses */
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
* Includes
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "lwip/opt.h"
|
||||
|
||||
#if LWIP_DNS /* don't build if not configured for use in lwipopts.h */
|
||||
|
||||
#include "lwip/udp.h"
|
||||
#include "lwip/mem.h"
|
||||
#include "lwip/memp.h"
|
||||
#include "lwip/dns.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#ifdef MEMLEAK_DEBUG
|
||||
static const char mem_debug_file[] ICACHE_RODATA_ATTR = __FILE__;
|
||||
#endif
|
||||
|
||||
/** DNS server IP address */
|
||||
#ifndef DNS_SERVER_ADDRESS
|
||||
#define DNS_SERVER_ADDRESS(ipaddr) (ip4_addr_set_u32(ipaddr, 0xDEDE43D0)) /* resolver1.opendns.com(208.67.222.222) */
|
||||
#endif
|
||||
|
||||
/** DNS server port address */
|
||||
#ifndef DNS_SERVER_PORT
|
||||
#define DNS_SERVER_PORT 53
|
||||
#endif
|
||||
|
||||
/** DNS maximum number of retries when asking for a name, before "timeout". */
|
||||
#ifndef DNS_MAX_RETRIES
|
||||
#define DNS_MAX_RETRIES 4
|
||||
#endif
|
||||
|
||||
/** DNS resource record max. TTL (one week as default) */
|
||||
#ifndef DNS_MAX_TTL
|
||||
#define DNS_MAX_TTL 604800
|
||||
#endif
|
||||
|
||||
/* DNS protocol flags */
|
||||
#define DNS_FLAG1_RESPONSE 0x80
|
||||
#define DNS_FLAG1_OPCODE_STATUS 0x10
|
||||
#define DNS_FLAG1_OPCODE_INVERSE 0x08
|
||||
#define DNS_FLAG1_OPCODE_STANDARD 0x00
|
||||
#define DNS_FLAG1_AUTHORATIVE 0x04
|
||||
#define DNS_FLAG1_TRUNC 0x02
|
||||
#define DNS_FLAG1_RD 0x01
|
||||
#define DNS_FLAG2_RA 0x80
|
||||
#define DNS_FLAG2_ERR_MASK 0x0f
|
||||
#define DNS_FLAG2_ERR_NONE 0x00
|
||||
#define DNS_FLAG2_ERR_NAME 0x03
|
||||
|
||||
/* DNS protocol states */
|
||||
#define DNS_STATE_UNUSED 0
|
||||
#define DNS_STATE_NEW 1
|
||||
#define DNS_STATE_ASKING 2
|
||||
#define DNS_STATE_DONE 3
|
||||
|
||||
#ifdef PACK_STRUCT_USE_INCLUDES
|
||||
# include "arch/bpstruct.h"
|
||||
#endif
|
||||
PACK_STRUCT_BEGIN
|
||||
/** DNS message header */
|
||||
struct dns_hdr {
|
||||
PACK_STRUCT_FIELD(u16_t id);
|
||||
PACK_STRUCT_FIELD(u8_t flags1);
|
||||
PACK_STRUCT_FIELD(u8_t flags2);
|
||||
PACK_STRUCT_FIELD(u16_t numquestions);
|
||||
PACK_STRUCT_FIELD(u16_t numanswers);
|
||||
PACK_STRUCT_FIELD(u16_t numauthrr);
|
||||
PACK_STRUCT_FIELD(u16_t numextrarr);
|
||||
} PACK_STRUCT_STRUCT;
|
||||
PACK_STRUCT_END
|
||||
#ifdef PACK_STRUCT_USE_INCLUDES
|
||||
# include "arch/epstruct.h"
|
||||
#endif
|
||||
#define SIZEOF_DNS_HDR 12
|
||||
|
||||
/** DNS query message structure.
|
||||
No packing needed: only used locally on the stack. */
|
||||
struct dns_query {
|
||||
/* DNS query record starts with either a domain name or a pointer
|
||||
to a name already present somewhere in the packet. */
|
||||
u16_t type;
|
||||
u16_t cls;
|
||||
};
|
||||
#define SIZEOF_DNS_QUERY 4
|
||||
|
||||
/** DNS answer message structure.
|
||||
No packing needed: only used locally on the stack. */
|
||||
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;
|
||||
u16_t cls;
|
||||
u32_t ttl;
|
||||
u16_t len;
|
||||
};
|
||||
#define SIZEOF_DNS_ANSWER 10
|
||||
|
||||
/** DNS table entry */
|
||||
struct dns_table_entry {
|
||||
u8_t state;
|
||||
u8_t numdns;
|
||||
u8_t tmr;
|
||||
u8_t retries;
|
||||
u8_t seqno;
|
||||
u8_t err;
|
||||
u32_t ttl;
|
||||
char name[DNS_MAX_NAME_LENGTH];
|
||||
ip_addr_t ipaddr;
|
||||
/* pointer to callback on DNS query done */
|
||||
dns_found_callback found;
|
||||
void *arg;
|
||||
};
|
||||
|
||||
#if DNS_LOCAL_HOSTLIST
|
||||
|
||||
#if DNS_LOCAL_HOSTLIST_IS_DYNAMIC
|
||||
/** Local host-list. For hostnames in this list, no
|
||||
* external name resolution is performed */
|
||||
static struct local_hostlist_entry *local_hostlist_dynamic;
|
||||
#else /* DNS_LOCAL_HOSTLIST_IS_DYNAMIC */
|
||||
|
||||
/** Defining this allows the local_hostlist_static to be placed in a different
|
||||
* linker section (e.g. FLASH) */
|
||||
#ifndef DNS_LOCAL_HOSTLIST_STORAGE_PRE
|
||||
#define DNS_LOCAL_HOSTLIST_STORAGE_PRE static
|
||||
#endif /* DNS_LOCAL_HOSTLIST_STORAGE_PRE */
|
||||
/** Defining this allows the local_hostlist_static to be placed in a different
|
||||
* linker section (e.g. FLASH) */
|
||||
#ifndef DNS_LOCAL_HOSTLIST_STORAGE_POST
|
||||
#define DNS_LOCAL_HOSTLIST_STORAGE_POST
|
||||
#endif /* DNS_LOCAL_HOSTLIST_STORAGE_POST */
|
||||
DNS_LOCAL_HOSTLIST_STORAGE_PRE struct local_hostlist_entry local_hostlist_static[]
|
||||
DNS_LOCAL_HOSTLIST_STORAGE_POST = DNS_LOCAL_HOSTLIST_INIT;
|
||||
|
||||
#endif /* DNS_LOCAL_HOSTLIST_IS_DYNAMIC */
|
||||
|
||||
static void dns_init_local();
|
||||
#endif /* DNS_LOCAL_HOSTLIST */
|
||||
|
||||
|
||||
/* forward declarations */
|
||||
static void dns_recv(void *s, struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *addr, u16_t port);
|
||||
static void dns_check_entries(void);
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
* Globales
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
/* DNS variables */
|
||||
static struct udp_pcb *dns_pcb;
|
||||
static u8_t dns_seqno;
|
||||
static struct dns_table_entry dns_table[DNS_TABLE_SIZE];
|
||||
static ip_addr_t dns_servers[DNS_MAX_SERVERS];
|
||||
/** Contiguous buffer for processing responses */
|
||||
//static u8_t dns_payload_buffer[LWIP_MEM_ALIGN_BUFFER(DNS_MSG_SIZE)];
|
||||
static u8_t* dns_payload;
|
||||
static u8_t dns_random;
|
||||
/**
|
||||
* Initialize the resolver: set up the UDP pcb and configure the default server
|
||||
* (DNS_SERVER_ADDRESS).
|
||||
*/
|
||||
void ICACHE_FLASH_ATTR
|
||||
dns_init()
|
||||
{
|
||||
ip_addr_t dnsserver;
|
||||
|
||||
// dns_payload = (u8_t *)LWIP_MEM_ALIGN(dns_payload_buffer);
|
||||
|
||||
/* initialize default DNS server address */
|
||||
DNS_SERVER_ADDRESS(&dnsserver);
|
||||
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("dns_init: initializing\n"));
|
||||
|
||||
/* if dns client not yet initialized... */
|
||||
if (dns_pcb == NULL) {
|
||||
dns_pcb = udp_new();
|
||||
|
||||
if (dns_pcb != NULL) {
|
||||
/* initialize DNS table not needed (initialized to zero since it is a
|
||||
* global variable) */
|
||||
LWIP_ASSERT("For implicit initialization to work, DNS_STATE_UNUSED needs to be 0",
|
||||
DNS_STATE_UNUSED == 0);
|
||||
|
||||
/* initialize DNS client */
|
||||
udp_bind(dns_pcb, IP_ADDR_ANY, 0);
|
||||
udp_recv(dns_pcb, dns_recv, NULL);
|
||||
|
||||
/* initialize default DNS primary server */
|
||||
dns_setserver(0, &dnsserver);
|
||||
}
|
||||
}
|
||||
#if DNS_LOCAL_HOSTLIST
|
||||
dns_init_local();
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize one of the DNS servers.
|
||||
*
|
||||
* @param numdns the index of the DNS server to set must be < DNS_MAX_SERVERS
|
||||
* @param dnsserver IP address of the DNS server to set
|
||||
*/
|
||||
void ICACHE_FLASH_ATTR
|
||||
dns_setserver(u8_t numdns, ip_addr_t *dnsserver)
|
||||
{
|
||||
if ((numdns < DNS_MAX_SERVERS) && (dns_pcb != NULL) &&
|
||||
(dnsserver != NULL) && !ip_addr_isany(dnsserver)) {
|
||||
dns_servers[numdns] = (*dnsserver);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain one of the currently configured DNS server.
|
||||
*
|
||||
* @param numdns the index of the DNS server
|
||||
* @return IP address of the indexed DNS server or "ip_addr_any" if the DNS
|
||||
* server has not been configured.
|
||||
*/
|
||||
ip_addr_t ICACHE_FLASH_ATTR
|
||||
dns_getserver(u8_t numdns)
|
||||
{
|
||||
if (numdns < DNS_MAX_SERVERS) {
|
||||
return dns_servers[numdns];
|
||||
} else {
|
||||
return *IP_ADDR_ANY;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The DNS resolver client timer - handle retries and timeouts and should
|
||||
* be called every DNS_TMR_INTERVAL milliseconds (every second by default).
|
||||
*/
|
||||
void ICACHE_FLASH_ATTR
|
||||
dns_tmr(void)
|
||||
{
|
||||
if (dns_pcb != NULL) {
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("dns_tmr: dns_check_entries\n"));
|
||||
dns_check_entries();
|
||||
}
|
||||
}
|
||||
|
||||
#if DNS_LOCAL_HOSTLIST
|
||||
static void ICACHE_FLASH_ATTR
|
||||
dns_init_local()
|
||||
{
|
||||
#if DNS_LOCAL_HOSTLIST_IS_DYNAMIC && defined(DNS_LOCAL_HOSTLIST_INIT)
|
||||
int i;
|
||||
struct local_hostlist_entry *entry;
|
||||
/* Dynamic: copy entries from DNS_LOCAL_HOSTLIST_INIT to list */
|
||||
struct local_hostlist_entry local_hostlist_init[] = DNS_LOCAL_HOSTLIST_INIT;
|
||||
size_t namelen;
|
||||
for (i = 0; i < sizeof(local_hostlist_init) / sizeof(struct local_hostlist_entry); i++) {
|
||||
struct local_hostlist_entry *init_entry = &local_hostlist_init[i];
|
||||
LWIP_ASSERT("invalid host name (NULL)", init_entry->name != NULL);
|
||||
namelen = os_strlen(init_entry->name);
|
||||
LWIP_ASSERT("namelen <= DNS_LOCAL_HOSTLIST_MAX_NAMELEN", namelen <= DNS_LOCAL_HOSTLIST_MAX_NAMELEN);
|
||||
entry = (struct local_hostlist_entry *)memp_malloc(MEMP_LOCALHOSTLIST);
|
||||
LWIP_ASSERT("mem-error in dns_init_local", entry != NULL);
|
||||
if (entry != NULL) {
|
||||
entry->name = (char*)entry + sizeof(struct local_hostlist_entry);
|
||||
MEMCPY((char*)entry->name, init_entry->name, namelen);
|
||||
((char*)entry->name)[namelen] = 0;
|
||||
entry->addr = init_entry->addr;
|
||||
entry->next = local_hostlist_dynamic;
|
||||
local_hostlist_dynamic = entry;
|
||||
}
|
||||
}
|
||||
#endif /* DNS_LOCAL_HOSTLIST_IS_DYNAMIC && defined(DNS_LOCAL_HOSTLIST_INIT) */
|
||||
}
|
||||
|
||||
/**
|
||||
* Scans the local host-list for a hostname.
|
||||
*
|
||||
* @param hostname Hostname to look for in the local host-list
|
||||
* @return The first IP address for the hostname in the local host-list or
|
||||
* IPADDR_NONE if not found.
|
||||
*/
|
||||
static u32_t ICACHE_FLASH_ATTR
|
||||
dns_lookup_local(const char *hostname)
|
||||
{
|
||||
#if DNS_LOCAL_HOSTLIST_IS_DYNAMIC
|
||||
struct local_hostlist_entry *entry = local_hostlist_dynamic;
|
||||
while(entry != NULL) {
|
||||
if(strcmp(entry->name, hostname) == 0) {
|
||||
return ip4_addr_get_u32(&entry->addr);
|
||||
}
|
||||
entry = entry->next;
|
||||
}
|
||||
#else /* DNS_LOCAL_HOSTLIST_IS_DYNAMIC */
|
||||
int i;
|
||||
for (i = 0; i < sizeof(local_hostlist_static) / sizeof(struct local_hostlist_entry); i++) {
|
||||
if(strcmp(local_hostlist_static[i].name, hostname) == 0) {
|
||||
return ip4_addr_get_u32(&local_hostlist_static[i].addr);
|
||||
}
|
||||
}
|
||||
#endif /* DNS_LOCAL_HOSTLIST_IS_DYNAMIC */
|
||||
return IPADDR_NONE;
|
||||
}
|
||||
|
||||
#if DNS_LOCAL_HOSTLIST_IS_DYNAMIC
|
||||
/** Remove all entries from the local host-list for a specific hostname
|
||||
* and/or IP addess
|
||||
*
|
||||
* @param hostname hostname for which entries shall be removed from the local
|
||||
* host-list
|
||||
* @param addr address for which entries shall be removed from the local host-list
|
||||
* @return the number of removed entries
|
||||
*/
|
||||
int ICACHE_FLASH_ATTR
|
||||
dns_local_removehost(const char *hostname, const ip_addr_t *addr)
|
||||
{
|
||||
int removed = 0;
|
||||
struct local_hostlist_entry *entry = local_hostlist_dynamic;
|
||||
struct local_hostlist_entry *last_entry = NULL;
|
||||
while (entry != NULL) {
|
||||
if (((hostname == NULL) || !strcmp(entry->name, hostname)) &&
|
||||
((addr == NULL) || ip_addr_cmp(&entry->addr, addr))) {
|
||||
struct local_hostlist_entry *free_entry;
|
||||
if (last_entry != NULL) {
|
||||
last_entry->next = entry->next;
|
||||
} else {
|
||||
local_hostlist_dynamic = entry->next;
|
||||
}
|
||||
free_entry = entry;
|
||||
entry = entry->next;
|
||||
memp_free(MEMP_LOCALHOSTLIST, free_entry);
|
||||
removed++;
|
||||
} else {
|
||||
last_entry = entry;
|
||||
entry = entry->next;
|
||||
}
|
||||
}
|
||||
return removed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a hostname/IP address pair to the local host-list.
|
||||
* Duplicates are not checked.
|
||||
*
|
||||
* @param hostname hostname of the new entry
|
||||
* @param addr IP address of the new entry
|
||||
* @return ERR_OK if succeeded or ERR_MEM on memory error
|
||||
*/
|
||||
err_t ICACHE_FLASH_ATTR
|
||||
dns_local_addhost(const char *hostname, const ip_addr_t *addr)
|
||||
{
|
||||
struct local_hostlist_entry *entry;
|
||||
size_t namelen;
|
||||
LWIP_ASSERT("invalid host name (NULL)", hostname != NULL);
|
||||
namelen = os_strlen(hostname);
|
||||
LWIP_ASSERT("namelen <= DNS_LOCAL_HOSTLIST_MAX_NAMELEN", namelen <= DNS_LOCAL_HOSTLIST_MAX_NAMELEN);
|
||||
entry = (struct local_hostlist_entry *)memp_malloc(MEMP_LOCALHOSTLIST);
|
||||
if (entry == NULL) {
|
||||
return ERR_MEM;
|
||||
}
|
||||
entry->name = (char*)entry + sizeof(struct local_hostlist_entry);
|
||||
MEMCPY((char*)entry->name, hostname, namelen);
|
||||
((char*)entry->name)[namelen] = 0;
|
||||
ip_addr_copy(entry->addr, *addr);
|
||||
entry->next = local_hostlist_dynamic;
|
||||
local_hostlist_dynamic = entry;
|
||||
return ERR_OK;
|
||||
}
|
||||
#endif /* DNS_LOCAL_HOSTLIST_IS_DYNAMIC*/
|
||||
#endif /* DNS_LOCAL_HOSTLIST */
|
||||
|
||||
/**
|
||||
* Look up a hostname in the array of known hostnames.
|
||||
*
|
||||
* @note This function only looks in the internal array of known
|
||||
* hostnames, it does not send out a query for the hostname if none
|
||||
* was found. The function dns_enqueue() can be used to send a query
|
||||
* for a hostname.
|
||||
*
|
||||
* @param name the hostname to look up
|
||||
* @return the hostname's IP address, as u32_t (instead of ip_addr_t to
|
||||
* better check for failure: != IPADDR_NONE) or IPADDR_NONE if the hostname
|
||||
* was not found in the cached dns_table.
|
||||
*/
|
||||
/*
|
||||
static u32_t ICACHE_FLASH_ATTR
|
||||
dns_lookup(const char *name)
|
||||
{
|
||||
u8_t i;
|
||||
#if DNS_LOCAL_HOSTLIST || defined(DNS_LOOKUP_LOCAL_EXTERN)
|
||||
u32_t addr;
|
||||
#endif
|
||||
#if DNS_LOCAL_HOSTLIST
|
||||
if ((addr = dns_lookup_local(name)) != IPADDR_NONE) {
|
||||
return addr;
|
||||
}
|
||||
#endif
|
||||
#ifdef DNS_LOOKUP_LOCAL_EXTERN
|
||||
if((addr = DNS_LOOKUP_LOCAL_EXTERN(name)) != IPADDR_NONE) {
|
||||
return addr;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Walk through name list, return entry if found. If not, return NULL.
|
||||
for (i = 0; i < DNS_TABLE_SIZE; ++i) {
|
||||
if ((dns_table[i].state == DNS_STATE_DONE) &&
|
||||
(strcmp(name, dns_table[i].name) == 0)) {
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("dns_lookup: \"%s\": found = ", name));
|
||||
ip_addr_debug_print(DNS_DEBUG, &(dns_table[i].ipaddr));
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("\n"));
|
||||
return ip4_addr_get_u32(&dns_table[i].ipaddr);
|
||||
}
|
||||
}
|
||||
|
||||
return IPADDR_NONE;
|
||||
}
|
||||
*/
|
||||
#if DNS_DOES_NAME_CHECK
|
||||
/**
|
||||
* Compare the "dotted" name "query" with the encoded name "response"
|
||||
* to make sure an answer from the DNS server matches the current dns_table
|
||||
* entry (otherwise, answers might arrive late for hostname not on the list
|
||||
* any more).
|
||||
*
|
||||
* @param query hostname (not encoded) from the dns_table
|
||||
* @param response encoded hostname in the DNS response
|
||||
* @return 0: names equal; 1: names differ
|
||||
*/
|
||||
static u8_t ICACHE_FLASH_ATTR
|
||||
dns_compare_name(unsigned char *query, unsigned char *response)
|
||||
{
|
||||
unsigned char n;
|
||||
|
||||
do {
|
||||
n = *response++;
|
||||
/** @see RFC 1035 - 4.1.4. Message compression */
|
||||
if ((n & 0xc0) == 0xc0) {
|
||||
/* Compressed name */
|
||||
break;
|
||||
} else {
|
||||
/* Not compressed name */
|
||||
while (n > 0) {
|
||||
if ((*query) != (*response)) {
|
||||
return 1;
|
||||
}
|
||||
++response;
|
||||
++query;
|
||||
--n;
|
||||
};
|
||||
++query;
|
||||
}
|
||||
} while (*response != 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* DNS_DOES_NAME_CHECK */
|
||||
|
||||
/**
|
||||
* Walk through a compact encoded DNS name and return the end of the name.
|
||||
*
|
||||
* @param query encoded DNS name in the DNS server response
|
||||
* @return end of the name
|
||||
*/
|
||||
static unsigned char * ICACHE_FLASH_ATTR
|
||||
dns_parse_name(unsigned char *query)
|
||||
{
|
||||
unsigned char n;
|
||||
|
||||
do {
|
||||
n = *query++;
|
||||
/** @see RFC 1035 - 4.1.4. Message compression */
|
||||
if ((n & 0xc0) == 0xc0) {
|
||||
/* Compressed name */
|
||||
break;
|
||||
} else {
|
||||
/* Not compressed name */
|
||||
while (n > 0) {
|
||||
++query;
|
||||
--n;
|
||||
};
|
||||
}
|
||||
} while (*query != 0);
|
||||
|
||||
return query + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a DNS query packet.
|
||||
*
|
||||
* @param numdns index of the DNS server in the dns_servers table
|
||||
* @param name hostname to query
|
||||
* @param id index of the hostname in dns_table, used as transaction ID in the
|
||||
* DNS query packet
|
||||
* @return ERR_OK if packet is sent; an err_t indicating the problem otherwise
|
||||
*/
|
||||
static err_t ICACHE_FLASH_ATTR
|
||||
dns_send(u8_t numdns, const char* name, u8_t id)
|
||||
{
|
||||
err_t err;
|
||||
struct dns_hdr *hdr;
|
||||
struct dns_query qry;
|
||||
struct pbuf *p;
|
||||
char *query, *nptr;
|
||||
const char *pHostname;
|
||||
u8_t n;
|
||||
dns_random = os_random()%250;
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("dns_send: dns_servers[%"U16_F"] \"%s\": request\n",
|
||||
(u16_t)(numdns), name));
|
||||
LWIP_ASSERT("dns server out of array", numdns < DNS_MAX_SERVERS);
|
||||
LWIP_ASSERT("dns server has no IP address set", !ip_addr_isany(&dns_servers[numdns]));
|
||||
|
||||
/* if here, we have either a new query or a retry on a previous query to process */
|
||||
p = pbuf_alloc(PBUF_TRANSPORT, SIZEOF_DNS_HDR + DNS_MAX_NAME_LENGTH +
|
||||
SIZEOF_DNS_QUERY, PBUF_RAM);
|
||||
if (p != NULL) {
|
||||
LWIP_ASSERT("pbuf must be in one piece", p->next == NULL);
|
||||
/* fill dns header */
|
||||
hdr = (struct dns_hdr*)p->payload;
|
||||
os_memset(hdr, 0, SIZEOF_DNS_HDR);
|
||||
hdr->id = htons(id + dns_random);
|
||||
hdr->flags1 = DNS_FLAG1_RD;
|
||||
hdr->numquestions = PP_HTONS(1);
|
||||
query = (char*)hdr + SIZEOF_DNS_HDR;
|
||||
pHostname = name;
|
||||
--pHostname;
|
||||
|
||||
/* convert hostname into suitable query format. */
|
||||
do {
|
||||
++pHostname;
|
||||
nptr = query;
|
||||
++query;
|
||||
for(n = 0; *pHostname != '.' && *pHostname != 0; ++pHostname) {
|
||||
*query = *pHostname;
|
||||
++query;
|
||||
++n;
|
||||
}
|
||||
*nptr = n;
|
||||
} while(*pHostname != 0);
|
||||
*query++='\0';
|
||||
|
||||
/* fill dns query */
|
||||
qry.type = PP_HTONS(DNS_RRTYPE_A);
|
||||
qry.cls = PP_HTONS(DNS_RRCLASS_IN);
|
||||
SMEMCPY(query, &qry, SIZEOF_DNS_QUERY);
|
||||
|
||||
/* resize pbuf to the exact dns query */
|
||||
pbuf_realloc(p, (u16_t)((query + SIZEOF_DNS_QUERY) - ((char*)(p->payload))));
|
||||
|
||||
/* connect to the server for faster receiving */
|
||||
udp_connect(dns_pcb, &dns_servers[numdns], DNS_SERVER_PORT);
|
||||
/* send dns packet */
|
||||
err = udp_sendto(dns_pcb, p, &dns_servers[numdns], DNS_SERVER_PORT);
|
||||
|
||||
/* free pbuf */
|
||||
pbuf_free(p);
|
||||
} else {
|
||||
err = ERR_MEM;
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* dns_check_entry() - see if pEntry has not yet been queried and, if so, sends out a query.
|
||||
* Check an entry in the dns_table:
|
||||
* - send out query for new entries
|
||||
* - retry old pending entries on timeout (also with different servers)
|
||||
* - remove completed entries from the table if their TTL has expired
|
||||
*
|
||||
* @param i index of the dns_table entry to check
|
||||
*/
|
||||
static void ICACHE_FLASH_ATTR
|
||||
dns_check_entry(u8_t i)
|
||||
{
|
||||
err_t err;
|
||||
struct dns_table_entry *pEntry = &dns_table[i];
|
||||
|
||||
LWIP_ASSERT("array index out of bounds", i < DNS_TABLE_SIZE);
|
||||
|
||||
switch(pEntry->state) {
|
||||
|
||||
case DNS_STATE_NEW: {
|
||||
/* initialize new entry */
|
||||
pEntry->state = DNS_STATE_ASKING;
|
||||
pEntry->numdns = 0;
|
||||
pEntry->tmr = 1;
|
||||
pEntry->retries = 0;
|
||||
|
||||
/* send DNS packet for this entry */
|
||||
err = dns_send(pEntry->numdns, pEntry->name, i);
|
||||
if (err != ERR_OK) {
|
||||
LWIP_DEBUGF(DNS_DEBUG | LWIP_DBG_LEVEL_WARNING,
|
||||
("dns_send returned error: %s\n", lwip_strerr(err)));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case DNS_STATE_ASKING: {
|
||||
if (--pEntry->tmr == 0) {
|
||||
if (++pEntry->retries == DNS_MAX_RETRIES) {
|
||||
if ((pEntry->numdns+1<DNS_MAX_SERVERS) && !ip_addr_isany(&dns_servers[pEntry->numdns+1])) {
|
||||
/* change of server */
|
||||
pEntry->numdns++;
|
||||
pEntry->tmr = 1;
|
||||
pEntry->retries = 0;
|
||||
break;
|
||||
} else {
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("dns_check_entry: \"%s\": timeout\n", pEntry->name));
|
||||
/* call specified callback function if provided */
|
||||
if (pEntry->found)
|
||||
(*pEntry->found)(pEntry->name, NULL, pEntry->arg);
|
||||
/* flush this entry */
|
||||
pEntry->state = DNS_STATE_UNUSED;
|
||||
pEntry->found = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* wait longer for the next retry */
|
||||
pEntry->tmr = pEntry->retries;
|
||||
|
||||
/* send DNS packet for this entry */
|
||||
err = dns_send(pEntry->numdns, pEntry->name, i);
|
||||
if (err != ERR_OK) {
|
||||
LWIP_DEBUGF(DNS_DEBUG | LWIP_DBG_LEVEL_WARNING,
|
||||
("dns_send returned error: %s\n", lwip_strerr(err)));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case DNS_STATE_DONE: {
|
||||
/* if the time to live is nul */
|
||||
if (--pEntry->ttl == 0) {
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("dns_check_entry: \"%s\": flush\n", pEntry->name));
|
||||
/* flush this entry */
|
||||
pEntry->state = DNS_STATE_UNUSED;
|
||||
pEntry->found = NULL;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case DNS_STATE_UNUSED:
|
||||
/* nothing to do */
|
||||
break;
|
||||
default:
|
||||
LWIP_ASSERT("unknown dns_table entry state:", 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Call dns_check_entry for each entry in dns_table - check all entries.
|
||||
*/
|
||||
static void ICACHE_FLASH_ATTR
|
||||
dns_check_entries(void)
|
||||
{
|
||||
u8_t i;
|
||||
|
||||
for (i = 0; i < DNS_TABLE_SIZE; ++i) {
|
||||
dns_check_entry(i);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Receive input function for DNS response packets arriving for the dns UDP pcb.
|
||||
*
|
||||
* @params see udp.h
|
||||
*/
|
||||
static void ICACHE_FLASH_ATTR
|
||||
dns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *addr, u16_t port)
|
||||
{
|
||||
u16_t i;
|
||||
char *pHostname;
|
||||
struct dns_hdr *hdr;
|
||||
struct dns_answer ans;
|
||||
struct dns_table_entry *pEntry;
|
||||
u16_t nquestions, nanswers;
|
||||
|
||||
u8_t* dns_payload_buffer = (u8_t* )os_zalloc(LWIP_MEM_ALIGN_BUFFER(DNS_MSG_SIZE));
|
||||
dns_payload = (u8_t *)LWIP_MEM_ALIGN(dns_payload_buffer);
|
||||
|
||||
LWIP_UNUSED_ARG(arg);
|
||||
LWIP_UNUSED_ARG(pcb);
|
||||
LWIP_UNUSED_ARG(addr);
|
||||
LWIP_UNUSED_ARG(port);
|
||||
|
||||
/* is the dns message too big ? */
|
||||
if (p->tot_len > DNS_MSG_SIZE) {
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("dns_recv: pbuf too big\n"));
|
||||
/* free pbuf and return */
|
||||
goto memerr;
|
||||
}
|
||||
|
||||
/* is the dns message big enough ? */
|
||||
if (p->tot_len < (SIZEOF_DNS_HDR + SIZEOF_DNS_QUERY + SIZEOF_DNS_ANSWER)) {
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("dns_recv: pbuf too small\n"));
|
||||
/* free pbuf and return */
|
||||
goto memerr;
|
||||
}
|
||||
|
||||
/* copy dns payload inside static buffer for processing */
|
||||
if (pbuf_copy_partial(p, dns_payload, p->tot_len, 0) == p->tot_len) {
|
||||
/* The ID in the DNS header should be our entry into the name table. */
|
||||
hdr = (struct dns_hdr*)dns_payload;
|
||||
i = htons(hdr->id);
|
||||
i = i - dns_random;
|
||||
if (i < DNS_TABLE_SIZE) {
|
||||
pEntry = &dns_table[i];
|
||||
if(pEntry->state == DNS_STATE_ASKING) {
|
||||
/* This entry is now completed. */
|
||||
pEntry->state = DNS_STATE_DONE;
|
||||
pEntry->err = hdr->flags2 & DNS_FLAG2_ERR_MASK;
|
||||
|
||||
/* We only care about the question(s) and the answers. The authrr
|
||||
and the extrarr are simply discarded. */
|
||||
nquestions = htons(hdr->numquestions);
|
||||
nanswers = htons(hdr->numanswers);
|
||||
|
||||
/* Check for error. If so, call callback to inform. */
|
||||
if (((hdr->flags1 & DNS_FLAG1_RESPONSE) == 0) || (pEntry->err != 0) || (nquestions != 1)) {
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("dns_recv: \"%s\": error in flags\n", pEntry->name));
|
||||
/* call callback to indicate error, clean up memory and return */
|
||||
goto responseerr;
|
||||
}
|
||||
|
||||
#if DNS_DOES_NAME_CHECK
|
||||
/* Check if the name in the "question" part match with the name in the entry. */
|
||||
if (dns_compare_name((unsigned char *)(pEntry->name), (unsigned char *)dns_payload + SIZEOF_DNS_HDR) != 0) {
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("dns_recv: \"%s\": response not match to query\n", pEntry->name));
|
||||
/* call callback to indicate error, clean up memory and return */
|
||||
goto responseerr;
|
||||
}
|
||||
#endif /* DNS_DOES_NAME_CHECK */
|
||||
|
||||
/* Skip the name in the "question" part */
|
||||
pHostname = (char *) dns_parse_name((unsigned char *)dns_payload + SIZEOF_DNS_HDR) + SIZEOF_DNS_QUERY;
|
||||
|
||||
while (nanswers > 0) {
|
||||
/* skip answer resource record's host name */
|
||||
pHostname = (char *) dns_parse_name((unsigned char *)pHostname);
|
||||
|
||||
/* Check for IP address type and Internet class. Others are discarded. */
|
||||
SMEMCPY(&ans, pHostname, SIZEOF_DNS_ANSWER);
|
||||
if((ans.type == PP_HTONS(DNS_RRTYPE_A)) && (ans.cls == PP_HTONS(DNS_RRCLASS_IN)) &&
|
||||
(ans.len == PP_HTONS(sizeof(ip_addr_t))) ) {
|
||||
/* read the answer resource record's TTL, and maximize it if needed */
|
||||
pEntry->ttl = ntohl(ans.ttl);
|
||||
if (pEntry->ttl > DNS_MAX_TTL) {
|
||||
pEntry->ttl = DNS_MAX_TTL;
|
||||
}
|
||||
/* read the IP address after answer resource record's header */
|
||||
SMEMCPY(&(pEntry->ipaddr), (pHostname+SIZEOF_DNS_ANSWER), sizeof(ip_addr_t));
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("dns_recv: \"%s\": response = ", pEntry->name));
|
||||
ip_addr_debug_print(DNS_DEBUG, (&(pEntry->ipaddr)));
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("\n"));
|
||||
/* call specified callback function if provided */
|
||||
if (pEntry->found) {
|
||||
(*pEntry->found)(pEntry->name, &pEntry->ipaddr, pEntry->arg);
|
||||
}
|
||||
/* deallocate memory and return */
|
||||
goto memerr;
|
||||
} else {
|
||||
pHostname = pHostname + SIZEOF_DNS_ANSWER + htons(ans.len);
|
||||
}
|
||||
--nanswers;
|
||||
}
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("dns_recv: \"%s\": error in response\n", pEntry->name));
|
||||
/* call callback to indicate error, clean up memory and return */
|
||||
goto responseerr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* deallocate memory and return */
|
||||
goto memerr;
|
||||
|
||||
responseerr:
|
||||
/* ERROR: call specified callback function with NULL as name to indicate an error */
|
||||
if (pEntry->found) {
|
||||
(*pEntry->found)(pEntry->name, NULL, pEntry->arg);
|
||||
}
|
||||
/* flush this entry */
|
||||
pEntry->state = DNS_STATE_UNUSED;
|
||||
pEntry->found = NULL;
|
||||
|
||||
memerr:
|
||||
/* free pbuf */
|
||||
pbuf_free(p);
|
||||
os_free(dns_payload_buffer);
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Queues a new hostname to resolve and sends out a DNS query for that hostname
|
||||
*
|
||||
* @param name the hostname that is to be queried
|
||||
* @param found a callback founction to be called on success, failure or timeout
|
||||
* @param callback_arg argument to pass to the callback function
|
||||
* @return @return a err_t return code.
|
||||
*/
|
||||
static err_t ICACHE_FLASH_ATTR
|
||||
dns_enqueue(const char *name, dns_found_callback found, void *callback_arg)
|
||||
{
|
||||
u8_t i;
|
||||
u8_t lseq, lseqi;
|
||||
struct dns_table_entry *pEntry = NULL;
|
||||
size_t namelen;
|
||||
|
||||
/* search an unused entry, or the oldest one */
|
||||
lseq = lseqi = 0;
|
||||
for (i = 0; i < DNS_TABLE_SIZE; ++i) {
|
||||
pEntry = &dns_table[i];
|
||||
/* is it an unused entry ? */
|
||||
if (pEntry->state == DNS_STATE_UNUSED)
|
||||
break;
|
||||
|
||||
/* check if this is the oldest completed entry */
|
||||
if (pEntry->state == DNS_STATE_DONE) {
|
||||
if ((dns_seqno - pEntry->seqno) > lseq) {
|
||||
lseq = dns_seqno - pEntry->seqno;
|
||||
lseqi = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* if we don't have found an unused entry, use the oldest completed one */
|
||||
if (i == DNS_TABLE_SIZE) {
|
||||
if ((lseqi >= DNS_TABLE_SIZE) || (dns_table[lseqi].state != DNS_STATE_DONE)) {
|
||||
/* no entry can't be used now, table is full */
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("dns_enqueue: \"%s\": DNS entries table is full\n", name));
|
||||
return ERR_MEM;
|
||||
} else {
|
||||
/* use the oldest completed one */
|
||||
i = lseqi;
|
||||
pEntry = &dns_table[i];
|
||||
}
|
||||
}
|
||||
|
||||
/* use this entry */
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("dns_enqueue: \"%s\": use DNS entry %"U16_F"\n", name, (u16_t)(i)));
|
||||
|
||||
/* fill the entry */
|
||||
pEntry->state = DNS_STATE_NEW;
|
||||
pEntry->seqno = dns_seqno++;
|
||||
pEntry->found = found;
|
||||
pEntry->arg = callback_arg;
|
||||
namelen = LWIP_MIN(os_strlen(name), DNS_MAX_NAME_LENGTH-1);
|
||||
MEMCPY(pEntry->name, name, namelen);
|
||||
pEntry->name[namelen] = 0;
|
||||
|
||||
/* force to send query without waiting timer */
|
||||
dns_check_entry(i);
|
||||
|
||||
/* dns query is enqueued */
|
||||
return ERR_INPROGRESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a hostname (string) into an IP address.
|
||||
* NON-BLOCKING callback version for use with raw API!!!
|
||||
*
|
||||
* Returns immediately with one of err_t return codes:
|
||||
* - ERR_OK if hostname is a valid IP address string or the host
|
||||
* name is already in the local names table.
|
||||
* - ERR_INPROGRESS enqueue a request to be sent to the DNS server
|
||||
* for resolution if no errors are present.
|
||||
* - ERR_ARG: dns client not initialized or invalid hostname
|
||||
*
|
||||
* @param hostname the hostname that is to be queried
|
||||
* @param addr pointer to a ip_addr_t where to store the address if it is already
|
||||
* cached in the dns_table (only valid if ERR_OK is returned!)
|
||||
* @param found a callback function to be called on success, failure or timeout (only if
|
||||
* ERR_INPROGRESS is returned!)
|
||||
* @param callback_arg argument to pass to the callback function
|
||||
* @return a err_t return code.
|
||||
*/
|
||||
err_t ICACHE_FLASH_ATTR
|
||||
dns_gethostbyname(const char *hostname, ip_addr_t *addr, dns_found_callback found,
|
||||
void *callback_arg)
|
||||
{
|
||||
u32_t ipaddr;
|
||||
/* not initialized or no valid server yet, or invalid addr pointer
|
||||
* or invalid hostname or invalid hostname length */
|
||||
if ((dns_pcb == NULL) || (addr == NULL) ||
|
||||
(!hostname) || (!hostname[0]) ||
|
||||
(os_strlen(hostname) >= DNS_MAX_NAME_LENGTH)) {
|
||||
return ERR_ARG;
|
||||
}
|
||||
|
||||
#if LWIP_HAVE_LOOPIF
|
||||
if (strcmp(hostname, "localhost")==0) {
|
||||
ip_addr_set_loopback(addr);
|
||||
return ERR_OK;
|
||||
}
|
||||
#endif /* LWIP_HAVE_LOOPIF */
|
||||
|
||||
/* host name already in octet notation? set ip addr and return ERR_OK */
|
||||
ipaddr = ipaddr_addr(hostname);
|
||||
if (ipaddr == IPADDR_NONE) {
|
||||
/* already have this address cached? */
|
||||
// ipaddr = dns_lookup(hostname);
|
||||
}
|
||||
if (ipaddr != IPADDR_NONE) {
|
||||
ip4_addr_set_u32(addr, ipaddr);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/* queue query with specified callback */
|
||||
return dns_enqueue(hostname, found, callback_arg);
|
||||
}
|
||||
|
||||
#endif /* LWIP_DNS */
|
325
tools/sdk/lwip/src/core/init.c
Normal file
325
tools/sdk/lwip/src/core/init.c
Normal file
@ -0,0 +1,325 @@
|
||||
/**
|
||||
* @file
|
||||
* Modules initialization
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
||||
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||
* OF SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the lwIP TCP/IP stack.
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
*/
|
||||
|
||||
#include "lwip/opt.h"
|
||||
|
||||
#include "lwip/init.h"
|
||||
#include "lwip/stats.h"
|
||||
#include "lwip/sys.h"
|
||||
#include "lwip/mem.h"
|
||||
#include "lwip/memp.h"
|
||||
#include "lwip/pbuf.h"
|
||||
#include "lwip/netif.h"
|
||||
#include "lwip/sockets.h"
|
||||
#include "lwip/ip.h"
|
||||
#include "lwip/raw.h"
|
||||
#include "lwip/udp.h"
|
||||
#include "lwip/tcp_impl.h"
|
||||
#include "lwip/snmp_msg.h"
|
||||
#include "lwip/autoip.h"
|
||||
#include "lwip/igmp.h"
|
||||
#include "lwip/dns.h"
|
||||
#include "lwip/timers.h"
|
||||
#include "netif/etharp.h"
|
||||
|
||||
/* Compile-time sanity checks for configuration errors.
|
||||
* These can be done independently of LWIP_DEBUG, without penalty.
|
||||
*/
|
||||
#ifndef BYTE_ORDER
|
||||
#error "BYTE_ORDER is not defined, you have to define it in your cc.h"
|
||||
#endif
|
||||
#if (!IP_SOF_BROADCAST && IP_SOF_BROADCAST_RECV)
|
||||
#error "If you want to use broadcast filter per pcb on recv operations, you have to define IP_SOF_BROADCAST=1 in your lwipopts.h"
|
||||
#endif
|
||||
#if (!LWIP_ARP && ARP_QUEUEING)
|
||||
#error "If you want to use ARP Queueing, you have to define LWIP_ARP=1 in your lwipopts.h"
|
||||
#endif
|
||||
#if (!LWIP_UDP && LWIP_UDPLITE)
|
||||
#error "If you want to use UDP Lite, you have to define LWIP_UDP=1 in your lwipopts.h"
|
||||
#endif
|
||||
#if (!LWIP_UDP && LWIP_SNMP)
|
||||
#error "If you want to use SNMP, you have to define LWIP_UDP=1 in your lwipopts.h"
|
||||
#endif
|
||||
#if (!LWIP_UDP && LWIP_DHCP)
|
||||
#error "If you want to use DHCP, you have to define LWIP_UDP=1 in your lwipopts.h"
|
||||
#endif
|
||||
#if (!LWIP_UDP && LWIP_IGMP)
|
||||
#error "If you want to use IGMP, you have to define LWIP_UDP=1 in your lwipopts.h"
|
||||
#endif
|
||||
#if (!LWIP_UDP && LWIP_SNMP)
|
||||
#error "If you want to use SNMP, you have to define LWIP_UDP=1 in your lwipopts.h"
|
||||
#endif
|
||||
#if (!LWIP_UDP && LWIP_DNS)
|
||||
#error "If you want to use DNS, you have to define LWIP_UDP=1 in your lwipopts.h"
|
||||
#endif
|
||||
#if (LWIP_ARP && ARP_QUEUEING && (MEMP_NUM_ARP_QUEUE<=0))
|
||||
#error "If you want to use ARP Queueing, you have to define MEMP_NUM_ARP_QUEUE>=1 in your lwipopts.h"
|
||||
#endif
|
||||
#if (LWIP_RAW && (MEMP_NUM_RAW_PCB<=0))
|
||||
#error "If you want to use RAW, you have to define MEMP_NUM_RAW_PCB>=1 in your lwipopts.h"
|
||||
#endif
|
||||
#if (LWIP_UDP && (MEMP_NUM_UDP_PCB<=0))
|
||||
#error "If you want to use UDP, you have to define MEMP_NUM_UDP_PCB>=1 in your lwipopts.h"
|
||||
#endif
|
||||
//#if (LWIP_TCP && (MEMP_NUM_TCP_PCB<=0))
|
||||
// #error "If you want to use TCP, you have to define MEMP_NUM_TCP_PCB>=1 in your lwipopts.h"
|
||||
//#endif
|
||||
//#if (LWIP_TCP && (TCP_WND > 0xffff))
|
||||
// #error "If you want to use TCP, TCP_WND must fit in an u16_t, so, you have to reduce it in your lwipopts.h"
|
||||
//#endif
|
||||
#if (LWIP_TCP && (TCP_SND_QUEUELEN > 0xffff))
|
||||
#error "If you want to use TCP, TCP_SND_QUEUELEN must fit in an u16_t, so, you have to reduce it in your lwipopts.h"
|
||||
#endif
|
||||
#if (LWIP_TCP && (TCP_SND_QUEUELEN < 2))
|
||||
#error "TCP_SND_QUEUELEN must be at least 2 for no-copy TCP writes to work"
|
||||
#endif
|
||||
//#if (LWIP_TCP && ((TCP_MAXRTX > 12) || (TCP_SYNMAXRTX > 12)))
|
||||
// #error "If you want to use TCP, TCP_MAXRTX and TCP_SYNMAXRTX must less or equal to 12 (due to tcp_backoff table), so, you have to reduce them in your lwipopts.h"
|
||||
//#endif
|
||||
#if (LWIP_TCP && TCP_LISTEN_BACKLOG && (TCP_DEFAULT_LISTEN_BACKLOG < 0) || (TCP_DEFAULT_LISTEN_BACKLOG > 0xff))
|
||||
#error "If you want to use TCP backlog, TCP_DEFAULT_LISTEN_BACKLOG must fit into an u8_t"
|
||||
#endif
|
||||
#if (LWIP_IGMP && (MEMP_NUM_IGMP_GROUP<=1))
|
||||
#error "If you want to use IGMP, you have to define MEMP_NUM_IGMP_GROUP>1 in your lwipopts.h"
|
||||
#endif
|
||||
#if (LWIP_NETIF_API && (NO_SYS==1))
|
||||
#error "If you want to use NETIF API, you have to define NO_SYS=0 in your lwipopts.h"
|
||||
#endif
|
||||
#if ((LWIP_SOCKET || LWIP_NETCONN) && (NO_SYS==1))
|
||||
#error "If you want to use Sequential API, you have to define NO_SYS=0 in your lwipopts.h"
|
||||
#endif
|
||||
#if ((LWIP_NETCONN || LWIP_SOCKET) && (MEMP_NUM_TCPIP_MSG_API<=0))
|
||||
#error "If you want to use Sequential API, you have to define MEMP_NUM_TCPIP_MSG_API>=1 in your lwipopts.h"
|
||||
#endif
|
||||
#if (!LWIP_NETCONN && LWIP_SOCKET)
|
||||
#error "If you want to use Socket API, you have to define LWIP_NETCONN=1 in your lwipopts.h"
|
||||
#endif
|
||||
#if (((!LWIP_DHCP) || (!LWIP_AUTOIP)) && LWIP_DHCP_AUTOIP_COOP)
|
||||
#error "If you want to use DHCP/AUTOIP cooperation mode, you have to define LWIP_DHCP=1 and LWIP_AUTOIP=1 in your lwipopts.h"
|
||||
#endif
|
||||
#if (((!LWIP_DHCP) || (!LWIP_ARP)) && DHCP_DOES_ARP_CHECK)
|
||||
#error "If you want to use DHCP ARP checking, you have to define LWIP_DHCP=1 and LWIP_ARP=1 in your lwipopts.h"
|
||||
#endif
|
||||
#if (!LWIP_ARP && LWIP_AUTOIP)
|
||||
#error "If you want to use AUTOIP, you have to define LWIP_ARP=1 in your lwipopts.h"
|
||||
#endif
|
||||
#if (LWIP_SNMP && (SNMP_CONCURRENT_REQUESTS<=0))
|
||||
#error "If you want to use SNMP, you have to define SNMP_CONCURRENT_REQUESTS>=1 in your lwipopts.h"
|
||||
#endif
|
||||
#if (LWIP_SNMP && (SNMP_TRAP_DESTINATIONS<=0))
|
||||
#error "If you want to use SNMP, you have to define SNMP_TRAP_DESTINATIONS>=1 in your lwipopts.h"
|
||||
#endif
|
||||
#if (LWIP_TCP && ((LWIP_EVENT_API && LWIP_CALLBACK_API) || (!LWIP_EVENT_API && !LWIP_CALLBACK_API)))
|
||||
#error "One and exactly one of LWIP_EVENT_API and LWIP_CALLBACK_API has to be enabled in your lwipopts.h"
|
||||
#endif
|
||||
/* There must be sufficient timeouts, taking into account requirements of the subsystems. */
|
||||
#if LWIP_TIMERS && (MEMP_NUM_SYS_TIMEOUT < (LWIP_TCP + IP_REASSEMBLY + LWIP_ARP + (2*LWIP_DHCP) + LWIP_AUTOIP + LWIP_IGMP + LWIP_DNS + PPP_SUPPORT))
|
||||
#error "MEMP_NUM_SYS_TIMEOUT is too low to accomodate all required timeouts"
|
||||
#endif
|
||||
#if (IP_REASSEMBLY && (MEMP_NUM_REASSDATA > IP_REASS_MAX_PBUFS))
|
||||
#error "MEMP_NUM_REASSDATA > IP_REASS_MAX_PBUFS doesn't make sense since each struct ip_reassdata must hold 2 pbufs at least!"
|
||||
#endif
|
||||
#if (MEM_LIBC_MALLOC && MEM_USE_POOLS)
|
||||
#error "MEM_LIBC_MALLOC and MEM_USE_POOLS may not both be simultaneously enabled in your lwipopts.h"
|
||||
#endif
|
||||
#if (MEM_USE_POOLS && !MEMP_USE_CUSTOM_POOLS)
|
||||
#error "MEM_USE_POOLS requires custom pools (MEMP_USE_CUSTOM_POOLS) to be enabled in your lwipopts.h"
|
||||
#endif
|
||||
#if (PBUF_POOL_BUFSIZE <= MEM_ALIGNMENT)
|
||||
#error "PBUF_POOL_BUFSIZE must be greater than MEM_ALIGNMENT or the offset may take the full first pbuf"
|
||||
#endif
|
||||
#if (TCP_QUEUE_OOSEQ && !LWIP_TCP)
|
||||
#error "TCP_QUEUE_OOSEQ requires LWIP_TCP"
|
||||
#endif
|
||||
#if (DNS_LOCAL_HOSTLIST && !DNS_LOCAL_HOSTLIST_IS_DYNAMIC && !(defined(DNS_LOCAL_HOSTLIST_INIT)))
|
||||
#error "you have to define define DNS_LOCAL_HOSTLIST_INIT {{'host1', 0x123}, {'host2', 0x234}} to initialize DNS_LOCAL_HOSTLIST"
|
||||
#endif
|
||||
#if PPP_SUPPORT && !PPPOS_SUPPORT & !PPPOE_SUPPORT
|
||||
#error "PPP_SUPPORT needs either PPPOS_SUPPORT or PPPOE_SUPPORT turned on"
|
||||
#endif
|
||||
#if !LWIP_ETHERNET && (LWIP_ARP || PPPOE_SUPPORT)
|
||||
#error "LWIP_ETHERNET needs to be turned on for LWIP_ARP or PPPOE_SUPPORT"
|
||||
#endif
|
||||
#if LWIP_IGMP && !defined(LWIP_RAND)
|
||||
#error "When using IGMP, LWIP_RAND() needs to be defined to a random-function returning an u32_t random value"
|
||||
#endif
|
||||
#if LWIP_TCPIP_CORE_LOCKING_INPUT && !LWIP_TCPIP_CORE_LOCKING
|
||||
#error "When using LWIP_TCPIP_CORE_LOCKING_INPUT, LWIP_TCPIP_CORE_LOCKING must be enabled, too"
|
||||
#endif
|
||||
#if LWIP_TCP && LWIP_NETIF_TX_SINGLE_PBUF && !TCP_OVERSIZE
|
||||
#error "LWIP_NETIF_TX_SINGLE_PBUF needs TCP_OVERSIZE enabled to create single-pbuf TCP packets"
|
||||
#endif
|
||||
#if IP_FRAG && IP_FRAG_USES_STATIC_BUF && LWIP_NETIF_TX_SINGLE_PBUF
|
||||
#error "LWIP_NETIF_TX_SINGLE_PBUF does not work with IP_FRAG_USES_STATIC_BUF==1 as that creates pbuf queues"
|
||||
#endif
|
||||
|
||||
|
||||
/* Compile-time checks for deprecated options.
|
||||
*/
|
||||
#ifdef MEMP_NUM_TCPIP_MSG
|
||||
#error "MEMP_NUM_TCPIP_MSG option is deprecated. Remove it from your lwipopts.h."
|
||||
#endif
|
||||
#ifdef MEMP_NUM_API_MSG
|
||||
#error "MEMP_NUM_API_MSG option is deprecated. Remove it from your lwipopts.h."
|
||||
#endif
|
||||
#ifdef TCP_REXMIT_DEBUG
|
||||
#error "TCP_REXMIT_DEBUG option is deprecated. Remove it from your lwipopts.h."
|
||||
#endif
|
||||
#ifdef RAW_STATS
|
||||
#error "RAW_STATS option is deprecated. Remove it from your lwipopts.h."
|
||||
#endif
|
||||
#ifdef ETHARP_QUEUE_FIRST
|
||||
#error "ETHARP_QUEUE_FIRST option is deprecated. Remove it from your lwipopts.h."
|
||||
#endif
|
||||
#ifdef ETHARP_ALWAYS_INSERT
|
||||
#error "ETHARP_ALWAYS_INSERT option is deprecated. Remove it from your lwipopts.h."
|
||||
#endif
|
||||
|
||||
#ifdef LWIP_DEBUG
|
||||
static void ICACHE_FLASH_ATTR
|
||||
lwip_sanity_check(void)
|
||||
{
|
||||
/* Warnings */
|
||||
#if LWIP_NETCONN
|
||||
if (MEMP_NUM_NETCONN > (MEMP_NUM_TCP_PCB+MEMP_NUM_TCP_PCB_LISTEN+MEMP_NUM_UDP_PCB+MEMP_NUM_RAW_PCB))
|
||||
LWIP_PLATFORM_DIAG(("lwip_sanity_check: WARNING: MEMP_NUM_NETCONN should be less than the sum of MEMP_NUM_{TCP,RAW,UDP}_PCB+MEMP_NUM_TCP_PCB_LISTEN\n"));
|
||||
#endif /* LWIP_NETCONN */
|
||||
#if LWIP_TCP
|
||||
if (MEMP_NUM_TCP_SEG < TCP_SND_QUEUELEN)
|
||||
LWIP_PLATFORM_DIAG(("lwip_sanity_check: WARNING: MEMP_NUM_TCP_SEG should be at least as big as TCP_SND_QUEUELEN\n"));
|
||||
if (TCP_SND_BUF < 2 * TCP_MSS)
|
||||
LWIP_PLATFORM_DIAG(("lwip_sanity_check: WARNING: TCP_SND_BUF must be at least as much as (2 * TCP_MSS) for things to work smoothly\n"));
|
||||
if (TCP_SND_QUEUELEN < (2 * (TCP_SND_BUF/TCP_MSS)))
|
||||
LWIP_PLATFORM_DIAG(("lwip_sanity_check: WARNING: TCP_SND_QUEUELEN must be at least as much as (2 * TCP_SND_BUF/TCP_MSS) for things to work\n"));
|
||||
if (TCP_SNDLOWAT >= TCP_SND_BUF)
|
||||
LWIP_PLATFORM_DIAG(("lwip_sanity_check: WARNING: TCP_SNDLOWAT must be less than TCP_SND_BUF.\n"));
|
||||
if (TCP_SNDQUEUELOWAT >= TCP_SND_QUEUELEN)
|
||||
LWIP_PLATFORM_DIAG(("lwip_sanity_check: WARNING: TCP_SNDQUEUELOWAT must be less than TCP_SND_QUEUELEN.\n"));
|
||||
if (TCP_WND > (PBUF_POOL_SIZE*PBUF_POOL_BUFSIZE))
|
||||
LWIP_PLATFORM_DIAG(("lwip_sanity_check: WARNING: TCP_WND is larger than space provided by PBUF_POOL_SIZE*PBUF_POOL_BUFSIZE\n"));
|
||||
if (TCP_WND < TCP_MSS)
|
||||
LWIP_PLATFORM_DIAG(("lwip_sanity_check: WARNING: TCP_WND is smaller than MSS\n"));
|
||||
#endif /* LWIP_TCP */
|
||||
#if LWIP_SOCKET
|
||||
/* Check that the SO_* socket options and SOF_* lwIP-internal flags match */
|
||||
if (SO_ACCEPTCONN != SOF_ACCEPTCONN)
|
||||
LWIP_PLATFORM_DIAG(("lwip_sanity_check: WARNING: SO_ACCEPTCONN != SOF_ACCEPTCONN\n"));
|
||||
if (SO_REUSEADDR != SOF_REUSEADDR)
|
||||
LWIP_PLATFORM_DIAG(("lwip_sanity_check: WARNING: SO_REUSEADDR != SOF_REUSEADDR\n"));
|
||||
if (SO_KEEPALIVE != SOF_KEEPALIVE)
|
||||
LWIP_PLATFORM_DIAG(("lwip_sanity_check: WARNING: SO_KEEPALIVE != SOF_KEEPALIVE\n"));
|
||||
if (SO_BROADCAST != SOF_BROADCAST)
|
||||
LWIP_PLATFORM_DIAG(("lwip_sanity_check: WARNING: SO_BROADCAST != SOF_BROADCAST\n"));
|
||||
if (SO_LINGER != SOF_LINGER)
|
||||
LWIP_PLATFORM_DIAG(("lwip_sanity_check: WARNING: SO_LINGER != SOF_LINGER\n"));
|
||||
#endif /* LWIP_SOCKET */
|
||||
}
|
||||
#else /* LWIP_DEBUG */
|
||||
#define lwip_sanity_check()
|
||||
#endif /* LWIP_DEBUG */
|
||||
|
||||
/**
|
||||
* Perform Sanity check of user-configurable values, and initialize all modules.
|
||||
*/
|
||||
void
|
||||
lwip_init(void)
|
||||
{
|
||||
MEMP_NUM_TCP_PCB = 5;
|
||||
TCP_WND = (4 * TCP_MSS);
|
||||
TCP_MAXRTX = 12;
|
||||
TCP_SYNMAXRTX = 6;
|
||||
|
||||
/* Sanity check user-configurable values */
|
||||
lwip_sanity_check();
|
||||
|
||||
/* Modules initialization */
|
||||
stats_init();
|
||||
#if !NO_SYS
|
||||
sys_init();
|
||||
#endif /* !NO_SYS */
|
||||
#if 0
|
||||
mem_init(&_bss_end);
|
||||
#endif
|
||||
memp_init();
|
||||
|
||||
pbuf_init();
|
||||
|
||||
netif_init();
|
||||
|
||||
#if LWIP_SOCKET
|
||||
lwip_socket_init();
|
||||
#endif /* LWIP_SOCKET */
|
||||
ip_init();
|
||||
|
||||
#if LWIP_ARP
|
||||
etharp_init();
|
||||
|
||||
#endif /* LWIP_ARP */
|
||||
#if LWIP_RAW
|
||||
raw_init();
|
||||
|
||||
#endif /* LWIP_RAW */
|
||||
#if LWIP_UDP
|
||||
udp_init();
|
||||
|
||||
#endif /* LWIP_UDP */
|
||||
#if LWIP_TCP
|
||||
tcp_init();
|
||||
|
||||
#endif /* LWIP_TCP */
|
||||
#if LWIP_SNMP
|
||||
snmp_init();
|
||||
|
||||
#endif /* LWIP_SNMP */
|
||||
#if LWIP_AUTOIP
|
||||
autoip_init();
|
||||
|
||||
#endif /* LWIP_AUTOIP */
|
||||
#if LWIP_IGMP
|
||||
igmp_init();
|
||||
|
||||
#endif /* LWIP_IGMP */
|
||||
#if LWIP_DNS
|
||||
dns_init();
|
||||
|
||||
#endif /* LWIP_DNS */
|
||||
|
||||
#if LWIP_TIMERS
|
||||
sys_timeouts_init();
|
||||
#endif /* LWIP_TIMERS */
|
||||
}
|
536
tools/sdk/lwip/src/core/ipv4/autoip.c
Normal file
536
tools/sdk/lwip/src/core/ipv4/autoip.c
Normal file
@ -0,0 +1,536 @@
|
||||
/**
|
||||
* @file
|
||||
* AutoIP Automatic LinkLocal IP Configuration
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2007 Dominik Spies <kontakt@dspies.de>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
||||
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||
* OF SUCH DAMAGE.
|
||||
*
|
||||
* Author: Dominik Spies <kontakt@dspies.de>
|
||||
*
|
||||
* This is a AutoIP implementation for the lwIP TCP/IP stack. It aims to conform
|
||||
* with RFC 3927.
|
||||
*
|
||||
*
|
||||
* Please coordinate changes and requests with Dominik Spies
|
||||
* <kontakt@dspies.de>
|
||||
*/
|
||||
|
||||
/*******************************************************************************
|
||||
* USAGE:
|
||||
*
|
||||
* define LWIP_AUTOIP 1 in your lwipopts.h
|
||||
*
|
||||
* If you don't use tcpip.c (so, don't call, you don't call tcpip_init):
|
||||
* - First, call autoip_init().
|
||||
* - call autoip_tmr() all AUTOIP_TMR_INTERVAL msces,
|
||||
* that should be defined in autoip.h.
|
||||
* I recommend a value of 100. The value must divide 1000 with a remainder almost 0.
|
||||
* Possible values are 1000, 500, 333, 250, 200, 166, 142, 125, 111, 100 ....
|
||||
*
|
||||
* Without DHCP:
|
||||
* - Call autoip_start() after netif_add().
|
||||
*
|
||||
* With DHCP:
|
||||
* - define LWIP_DHCP_AUTOIP_COOP 1 in your lwipopts.h.
|
||||
* - Configure your DHCP Client.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "lwip/opt.h"
|
||||
|
||||
#if LWIP_AUTOIP /* don't build if not configured for use in lwipopts.h */
|
||||
|
||||
#include "lwip/mem.h"
|
||||
#include "lwip/udp.h"
|
||||
#include "lwip/ip_addr.h"
|
||||
#include "lwip/netif.h"
|
||||
#include "lwip/autoip.h"
|
||||
#include "netif/etharp.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/* 169.254.0.0 */
|
||||
#define AUTOIP_NET 0xA9FE0000
|
||||
/* 169.254.1.0 */
|
||||
#define AUTOIP_RANGE_START (AUTOIP_NET | 0x0100)
|
||||
/* 169.254.254.255 */
|
||||
#define AUTOIP_RANGE_END (AUTOIP_NET | 0xFEFF)
|
||||
|
||||
|
||||
/** Pseudo random macro based on netif informations.
|
||||
* You could use "rand()" from the C Library if you define LWIP_AUTOIP_RAND in lwipopts.h */
|
||||
#ifndef LWIP_AUTOIP_RAND
|
||||
#define LWIP_AUTOIP_RAND(netif) ( (((u32_t)((netif->hwaddr[5]) & 0xff) << 24) | \
|
||||
((u32_t)((netif->hwaddr[3]) & 0xff) << 16) | \
|
||||
((u32_t)((netif->hwaddr[2]) & 0xff) << 8) | \
|
||||
((u32_t)((netif->hwaddr[4]) & 0xff))) + \
|
||||
(netif->autoip?netif->autoip->tried_llipaddr:0))
|
||||
#endif /* LWIP_AUTOIP_RAND */
|
||||
|
||||
/**
|
||||
* Macro that generates the initial IP address to be tried by AUTOIP.
|
||||
* If you want to override this, define it to something else in lwipopts.h.
|
||||
*/
|
||||
#ifndef LWIP_AUTOIP_CREATE_SEED_ADDR
|
||||
#define LWIP_AUTOIP_CREATE_SEED_ADDR(netif) \
|
||||
htonl(AUTOIP_RANGE_START + ((u32_t)(((u8_t)(netif->hwaddr[4])) | \
|
||||
((u32_t)((u8_t)(netif->hwaddr[5]))) << 8)))
|
||||
#endif /* LWIP_AUTOIP_CREATE_SEED_ADDR */
|
||||
|
||||
/* static functions */
|
||||
static void autoip_handle_arp_conflict(struct netif *netif);
|
||||
|
||||
/* creates a pseudo random LL IP-Address for a network interface */
|
||||
static void autoip_create_addr(struct netif *netif, ip_addr_t *ipaddr);
|
||||
|
||||
/* sends an ARP probe */
|
||||
static err_t autoip_arp_probe(struct netif *netif);
|
||||
|
||||
/* sends an ARP announce */
|
||||
static err_t autoip_arp_announce(struct netif *netif);
|
||||
|
||||
/* configure interface for use with current LL IP-Address */
|
||||
static err_t autoip_bind(struct netif *netif);
|
||||
|
||||
/* start sending probes for llipaddr */
|
||||
static void autoip_start_probing(struct netif *netif);
|
||||
|
||||
/**
|
||||
* Initialize this module
|
||||
*/
|
||||
void
|
||||
autoip_init(void)
|
||||
{
|
||||
LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE, ("autoip_init()\n"));
|
||||
}
|
||||
|
||||
/** Set a statically allocated struct autoip to work with.
|
||||
* Using this prevents autoip_start to allocate it using mem_malloc.
|
||||
*
|
||||
* @param netif the netif for which to set the struct autoip
|
||||
* @param dhcp (uninitialised) dhcp struct allocated by the application
|
||||
*/
|
||||
void
|
||||
autoip_set_struct(struct netif *netif, struct autoip *autoip)
|
||||
{
|
||||
LWIP_ASSERT("netif != NULL", netif != NULL);
|
||||
LWIP_ASSERT("autoip != NULL", autoip != NULL);
|
||||
LWIP_ASSERT("netif already has a struct autoip set", netif->autoip == NULL);
|
||||
|
||||
/* clear data structure */
|
||||
os_memset(autoip, 0, sizeof(struct autoip));
|
||||
/* autoip->state = AUTOIP_STATE_OFF; */
|
||||
netif->autoip = autoip;
|
||||
}
|
||||
|
||||
/** Restart AutoIP client and check the next address (conflict detected)
|
||||
*
|
||||
* @param netif The netif under AutoIP control
|
||||
*/
|
||||
static void
|
||||
autoip_restart(struct netif *netif)
|
||||
{
|
||||
netif->autoip->tried_llipaddr++;
|
||||
autoip_start(netif);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a IP address conflict after an ARP conflict detection
|
||||
*/
|
||||
static void
|
||||
autoip_handle_arp_conflict(struct netif *netif)
|
||||
{
|
||||
/* Somehow detect if we are defending or retreating */
|
||||
unsigned char defend = 1; /* tbd */
|
||||
|
||||
if(defend) {
|
||||
if(netif->autoip->lastconflict > 0) {
|
||||
/* retreat, there was a conflicting ARP in the last
|
||||
* DEFEND_INTERVAL seconds
|
||||
*/
|
||||
LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE,
|
||||
("autoip_handle_arp_conflict(): we are defending, but in DEFEND_INTERVAL, retreating\n"));
|
||||
|
||||
/* TODO: close all TCP sessions */
|
||||
autoip_restart(netif);
|
||||
} else {
|
||||
LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE,
|
||||
("autoip_handle_arp_conflict(): we are defend, send ARP Announce\n"));
|
||||
autoip_arp_announce(netif);
|
||||
netif->autoip->lastconflict = DEFEND_INTERVAL * AUTOIP_TICKS_PER_SECOND;
|
||||
}
|
||||
} else {
|
||||
LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE,
|
||||
("autoip_handle_arp_conflict(): we do not defend, retreating\n"));
|
||||
/* TODO: close all TCP sessions */
|
||||
autoip_restart(netif);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an IP-Address out of range 169.254.1.0 to 169.254.254.255
|
||||
*
|
||||
* @param netif network interface on which create the IP-Address
|
||||
* @param ipaddr ip address to initialize
|
||||
*/
|
||||
static void
|
||||
autoip_create_addr(struct netif *netif, ip_addr_t *ipaddr)
|
||||
{
|
||||
/* Here we create an IP-Address out of range 169.254.1.0 to 169.254.254.255
|
||||
* compliant to RFC 3927 Section 2.1
|
||||
* We have 254 * 256 possibilities */
|
||||
|
||||
u32_t addr = ntohl(LWIP_AUTOIP_CREATE_SEED_ADDR(netif));
|
||||
addr += netif->autoip->tried_llipaddr;
|
||||
addr = AUTOIP_NET | (addr & 0xffff);
|
||||
/* Now, 169.254.0.0 <= addr <= 169.254.255.255 */
|
||||
|
||||
if (addr < AUTOIP_RANGE_START) {
|
||||
addr += AUTOIP_RANGE_END - AUTOIP_RANGE_START + 1;
|
||||
}
|
||||
if (addr > AUTOIP_RANGE_END) {
|
||||
addr -= AUTOIP_RANGE_END - AUTOIP_RANGE_START + 1;
|
||||
}
|
||||
LWIP_ASSERT("AUTOIP address not in range", (addr >= AUTOIP_RANGE_START) &&
|
||||
(addr <= AUTOIP_RANGE_END));
|
||||
ip4_addr_set_u32(ipaddr, htonl(addr));
|
||||
|
||||
LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE,
|
||||
("autoip_create_addr(): tried_llipaddr=%"U16_F", %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
|
||||
(u16_t)(netif->autoip->tried_llipaddr), ip4_addr1_16(ipaddr), ip4_addr2_16(ipaddr),
|
||||
ip4_addr3_16(ipaddr), ip4_addr4_16(ipaddr)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends an ARP probe from a network interface
|
||||
*
|
||||
* @param netif network interface used to send the probe
|
||||
*/
|
||||
static err_t
|
||||
autoip_arp_probe(struct netif *netif)
|
||||
{
|
||||
return etharp_raw(netif, (struct eth_addr *)netif->hwaddr, ðbroadcast,
|
||||
(struct eth_addr *)netif->hwaddr, IP_ADDR_ANY, ðzero,
|
||||
&netif->autoip->llipaddr, ARP_REQUEST);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends an ARP announce from a network interface
|
||||
*
|
||||
* @param netif network interface used to send the announce
|
||||
*/
|
||||
static err_t
|
||||
autoip_arp_announce(struct netif *netif)
|
||||
{
|
||||
return etharp_raw(netif, (struct eth_addr *)netif->hwaddr, ðbroadcast,
|
||||
(struct eth_addr *)netif->hwaddr, &netif->autoip->llipaddr, ðzero,
|
||||
&netif->autoip->llipaddr, ARP_REQUEST);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure interface for use with current LL IP-Address
|
||||
*
|
||||
* @param netif network interface to configure with current LL IP-Address
|
||||
*/
|
||||
static err_t
|
||||
autoip_bind(struct netif *netif)
|
||||
{
|
||||
struct autoip *autoip = netif->autoip;
|
||||
ip_addr_t sn_mask, gw_addr;
|
||||
|
||||
LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE,
|
||||
("autoip_bind(netif=%p) %c%c%"U16_F" %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
|
||||
(void*)netif, netif->name[0], netif->name[1], (u16_t)netif->num,
|
||||
ip4_addr1_16(&autoip->llipaddr), ip4_addr2_16(&autoip->llipaddr),
|
||||
ip4_addr3_16(&autoip->llipaddr), ip4_addr4_16(&autoip->llipaddr)));
|
||||
|
||||
IP4_ADDR(&sn_mask, 255, 255, 0, 0);
|
||||
IP4_ADDR(&gw_addr, 0, 0, 0, 0);
|
||||
|
||||
netif_set_ipaddr(netif, &autoip->llipaddr);
|
||||
netif_set_netmask(netif, &sn_mask);
|
||||
netif_set_gw(netif, &gw_addr);
|
||||
|
||||
/* bring the interface up */
|
||||
netif_set_up(netif);
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start AutoIP client
|
||||
*
|
||||
* @param netif network interface on which start the AutoIP client
|
||||
*/
|
||||
err_t
|
||||
autoip_start(struct netif *netif)
|
||||
{
|
||||
struct autoip *autoip = netif->autoip;
|
||||
err_t result = ERR_OK;
|
||||
|
||||
if(netif_is_up(netif)) {
|
||||
netif_set_down(netif);
|
||||
}
|
||||
|
||||
/* Set IP-Address, Netmask and Gateway to 0 to make sure that
|
||||
* ARP Packets are formed correctly
|
||||
*/
|
||||
ip_addr_set_zero(&netif->ip_addr);
|
||||
ip_addr_set_zero(&netif->netmask);
|
||||
ip_addr_set_zero(&netif->gw);
|
||||
|
||||
LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE,
|
||||
("autoip_start(netif=%p) %c%c%"U16_F"\n", (void*)netif, netif->name[0],
|
||||
netif->name[1], (u16_t)netif->num));
|
||||
if(autoip == NULL) {
|
||||
/* no AutoIP client attached yet? */
|
||||
LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE,
|
||||
("autoip_start(): starting new AUTOIP client\n"));
|
||||
autoip = (struct autoip *)mem_malloc(sizeof(struct autoip));
|
||||
if(autoip == NULL) {
|
||||
LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE,
|
||||
("autoip_start(): could not allocate autoip\n"));
|
||||
return ERR_MEM;
|
||||
}
|
||||
os_memset(autoip, 0, sizeof(struct autoip));
|
||||
/* store this AutoIP client in the netif */
|
||||
netif->autoip = autoip;
|
||||
LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE, ("autoip_start(): allocated autoip"));
|
||||
} else {
|
||||
autoip->state = AUTOIP_STATE_OFF;
|
||||
autoip->ttw = 0;
|
||||
autoip->sent_num = 0;
|
||||
ip_addr_set_zero(&autoip->llipaddr);
|
||||
autoip->lastconflict = 0;
|
||||
}
|
||||
|
||||
autoip_create_addr(netif, &(autoip->llipaddr));
|
||||
autoip_start_probing(netif);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static void
|
||||
autoip_start_probing(struct netif *netif)
|
||||
{
|
||||
struct autoip *autoip = netif->autoip;
|
||||
|
||||
autoip->state = AUTOIP_STATE_PROBING;
|
||||
autoip->sent_num = 0;
|
||||
LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE,
|
||||
("autoip_start_probing(): changing state to PROBING: %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
|
||||
ip4_addr1_16(&netif->autoip->llipaddr), ip4_addr2_16(&netif->autoip->llipaddr),
|
||||
ip4_addr3_16(&netif->autoip->llipaddr), ip4_addr4_16(&netif->autoip->llipaddr)));
|
||||
|
||||
/* time to wait to first probe, this is randomly
|
||||
* choosen out of 0 to PROBE_WAIT seconds.
|
||||
* compliant to RFC 3927 Section 2.2.1
|
||||
*/
|
||||
autoip->ttw = (u16_t)(LWIP_AUTOIP_RAND(netif) % (PROBE_WAIT * AUTOIP_TICKS_PER_SECOND));
|
||||
|
||||
/*
|
||||
* if we tried more then MAX_CONFLICTS we must limit our rate for
|
||||
* accquiring and probing address
|
||||
* compliant to RFC 3927 Section 2.2.1
|
||||
*/
|
||||
if(autoip->tried_llipaddr > MAX_CONFLICTS) {
|
||||
autoip->ttw = RATE_LIMIT_INTERVAL * AUTOIP_TICKS_PER_SECOND;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a possible change in the network configuration.
|
||||
*
|
||||
* If there is an AutoIP address configured, take the interface down
|
||||
* and begin probing with the same address.
|
||||
*/
|
||||
void
|
||||
autoip_network_changed(struct netif *netif)
|
||||
{
|
||||
if (netif->autoip && netif->autoip->state != AUTOIP_STATE_OFF) {
|
||||
netif_set_down(netif);
|
||||
autoip_start_probing(netif);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop AutoIP client
|
||||
*
|
||||
* @param netif network interface on which stop the AutoIP client
|
||||
*/
|
||||
err_t
|
||||
autoip_stop(struct netif *netif)
|
||||
{
|
||||
netif->autoip->state = AUTOIP_STATE_OFF;
|
||||
netif_set_down(netif);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Has to be called in loop every AUTOIP_TMR_INTERVAL milliseconds
|
||||
*/
|
||||
void
|
||||
autoip_tmr()
|
||||
{
|
||||
struct netif *netif = netif_list;
|
||||
/* loop through netif's */
|
||||
while (netif != NULL) {
|
||||
/* only act on AutoIP configured interfaces */
|
||||
if (netif->autoip != NULL) {
|
||||
if(netif->autoip->lastconflict > 0) {
|
||||
netif->autoip->lastconflict--;
|
||||
}
|
||||
|
||||
LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE,
|
||||
("autoip_tmr() AutoIP-State: %"U16_F", ttw=%"U16_F"\n",
|
||||
(u16_t)(netif->autoip->state), netif->autoip->ttw));
|
||||
|
||||
switch(netif->autoip->state) {
|
||||
case AUTOIP_STATE_PROBING:
|
||||
if(netif->autoip->ttw > 0) {
|
||||
netif->autoip->ttw--;
|
||||
} else {
|
||||
if(netif->autoip->sent_num >= PROBE_NUM) {
|
||||
netif->autoip->state = AUTOIP_STATE_ANNOUNCING;
|
||||
netif->autoip->sent_num = 0;
|
||||
netif->autoip->ttw = ANNOUNCE_WAIT * AUTOIP_TICKS_PER_SECOND;
|
||||
LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE,
|
||||
("autoip_tmr(): changing state to ANNOUNCING: %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
|
||||
ip4_addr1_16(&netif->autoip->llipaddr), ip4_addr2_16(&netif->autoip->llipaddr),
|
||||
ip4_addr3_16(&netif->autoip->llipaddr), ip4_addr4_16(&netif->autoip->llipaddr)));
|
||||
} else {
|
||||
autoip_arp_probe(netif);
|
||||
LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE,
|
||||
("autoip_tmr() PROBING Sent Probe\n"));
|
||||
netif->autoip->sent_num++;
|
||||
/* calculate time to wait to next probe */
|
||||
netif->autoip->ttw = (u16_t)((LWIP_AUTOIP_RAND(netif) %
|
||||
((PROBE_MAX - PROBE_MIN) * AUTOIP_TICKS_PER_SECOND) ) +
|
||||
PROBE_MIN * AUTOIP_TICKS_PER_SECOND);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case AUTOIP_STATE_ANNOUNCING:
|
||||
if(netif->autoip->ttw > 0) {
|
||||
netif->autoip->ttw--;
|
||||
} else {
|
||||
if(netif->autoip->sent_num == 0) {
|
||||
/* We are here the first time, so we waited ANNOUNCE_WAIT seconds
|
||||
* Now we can bind to an IP address and use it.
|
||||
*
|
||||
* autoip_bind calls netif_set_up. This triggers a gratuitous ARP
|
||||
* which counts as an announcement.
|
||||
*/
|
||||
autoip_bind(netif);
|
||||
} else {
|
||||
autoip_arp_announce(netif);
|
||||
LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE,
|
||||
("autoip_tmr() ANNOUNCING Sent Announce\n"));
|
||||
}
|
||||
netif->autoip->ttw = ANNOUNCE_INTERVAL * AUTOIP_TICKS_PER_SECOND;
|
||||
netif->autoip->sent_num++;
|
||||
|
||||
if(netif->autoip->sent_num >= ANNOUNCE_NUM) {
|
||||
netif->autoip->state = AUTOIP_STATE_BOUND;
|
||||
netif->autoip->sent_num = 0;
|
||||
netif->autoip->ttw = 0;
|
||||
LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE,
|
||||
("autoip_tmr(): changing state to BOUND: %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
|
||||
ip4_addr1_16(&netif->autoip->llipaddr), ip4_addr2_16(&netif->autoip->llipaddr),
|
||||
ip4_addr3_16(&netif->autoip->llipaddr), ip4_addr4_16(&netif->autoip->llipaddr)));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* proceed to next network interface */
|
||||
netif = netif->next;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles every incoming ARP Packet, called by etharp_arp_input.
|
||||
*
|
||||
* @param netif network interface to use for autoip processing
|
||||
* @param hdr Incoming ARP packet
|
||||
*/
|
||||
void
|
||||
autoip_arp_reply(struct netif *netif, struct etharp_hdr *hdr)
|
||||
{
|
||||
LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE, ("autoip_arp_reply()\n"));
|
||||
if ((netif->autoip != NULL) && (netif->autoip->state != AUTOIP_STATE_OFF)) {
|
||||
/* when ip.src == llipaddr && hw.src != netif->hwaddr
|
||||
*
|
||||
* when probing ip.dst == llipaddr && hw.src != netif->hwaddr
|
||||
* we have a conflict and must solve it
|
||||
*/
|
||||
ip_addr_t sipaddr, dipaddr;
|
||||
struct eth_addr netifaddr;
|
||||
ETHADDR16_COPY(netifaddr.addr, netif->hwaddr);
|
||||
|
||||
/* Copy struct ip_addr2 to aligned ip_addr, to support compilers without
|
||||
* structure packing (not using structure copy which breaks strict-aliasing rules).
|
||||
*/
|
||||
IPADDR2_COPY(&sipaddr, &hdr->sipaddr);
|
||||
IPADDR2_COPY(&dipaddr, &hdr->dipaddr);
|
||||
|
||||
if ((netif->autoip->state == AUTOIP_STATE_PROBING) ||
|
||||
((netif->autoip->state == AUTOIP_STATE_ANNOUNCING) &&
|
||||
(netif->autoip->sent_num == 0))) {
|
||||
/* RFC 3927 Section 2.2.1:
|
||||
* from beginning to after ANNOUNCE_WAIT
|
||||
* seconds we have a conflict if
|
||||
* ip.src == llipaddr OR
|
||||
* ip.dst == llipaddr && hw.src != own hwaddr
|
||||
*/
|
||||
if ((ip_addr_cmp(&sipaddr, &netif->autoip->llipaddr)) ||
|
||||
(ip_addr_cmp(&dipaddr, &netif->autoip->llipaddr) &&
|
||||
!eth_addr_cmp(&netifaddr, &hdr->shwaddr))) {
|
||||
LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE | LWIP_DBG_LEVEL_WARNING,
|
||||
("autoip_arp_reply(): Probe Conflict detected\n"));
|
||||
autoip_restart(netif);
|
||||
}
|
||||
} else {
|
||||
/* RFC 3927 Section 2.5:
|
||||
* in any state we have a conflict if
|
||||
* ip.src == llipaddr && hw.src != own hwaddr
|
||||
*/
|
||||
if (ip_addr_cmp(&sipaddr, &netif->autoip->llipaddr) &&
|
||||
!eth_addr_cmp(&netifaddr, &hdr->shwaddr)) {
|
||||
LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE | LWIP_DBG_LEVEL_WARNING,
|
||||
("autoip_arp_reply(): Conflicting ARP-Packet detected\n"));
|
||||
autoip_handle_arp_conflict(netif);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* LWIP_AUTOIP */
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user