Skip to content
Snippets Groups Projects
Commit 17e48083 authored by fptk's avatar fptk Committed by aticu
Browse files

WIP arty impl für merge

parent 90061f72
No related branches found
No related tags found
No related merge requests found
...@@ -45,11 +45,11 @@ ...@@ -45,11 +45,11 @@
<targetPlatform id="org.eclipse.linuxtools.cdt.autotools.core.toolchain.targetPlatform.1356856028" isAbstract="false" name="GNU Autotools Target Platform" superClass="org.eclipse.linuxtools.cdt.autotools.core.toolchain.targetPlatform"/> <targetPlatform id="org.eclipse.linuxtools.cdt.autotools.core.toolchain.targetPlatform.1356856028" isAbstract="false" name="GNU Autotools Target Platform" superClass="org.eclipse.linuxtools.cdt.autotools.core.toolchain.targetPlatform"/>
<builder id="org.eclipse.linuxtools.cdt.autotools.core.toolchain.builder.1966928500" name="Autotools Makefile Generator.Build (GNU)" superClass="org.eclipse.linuxtools.cdt.autotools.core.toolchain.builder"/> <builder id="org.eclipse.linuxtools.cdt.autotools.core.toolchain.builder.1966928500" keepEnvironmentInBuildfile="false" name="Autotools Makefile Generator" superClass="org.eclipse.linuxtools.cdt.autotools.core.toolchain.builder"/>
<tool id="org.eclipse.linuxtools.cdt.autotools.core.gnu.toolchain.tool.configure.1370538481" name="configure" superClass="org.eclipse.linuxtools.cdt.autotools.core.gnu.toolchain.tool.configure"> <tool id="org.eclipse.linuxtools.cdt.autotools.core.gnu.toolchain.tool.configure.1370538481" name="configure" superClass="org.eclipse.linuxtools.cdt.autotools.core.gnu.toolchain.tool.configure">
<option id="org.eclipse.linuxtools.cdt.autotools.core.option.configure.name.1547520623" superClass="org.eclipse.linuxtools.cdt.autotools.core.option.configure.name" value="org.eclipse.linuxtools.cdt.autotools.core.configuration.build.14833071" valueType="string"/> <option id="org.eclipse.linuxtools.cdt.autotools.core.option.configure.name.1547520623" name="Name" superClass="org.eclipse.linuxtools.cdt.autotools.core.option.configure.name" value="org.eclipse.linuxtools.cdt.autotools.core.configuration.build.14833071" valueType="string"/>
</tool> </tool>
...@@ -113,7 +113,7 @@ ...@@ -113,7 +113,7 @@
<storageModule moduleId="cdtBuildSystem" version="4.0.0"> <storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.linuxtools.cdt.autotools.core.buildArtefactType.autotools" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.linuxtools.cdt.autotools.core.buildArtefactType.autotools,org.eclipse.cdt.build.core.buildType=org.eclipse.linuxtools.cdt.autotools.core.buildType.debug" cleanCommand="rm -rf" description="" errorParsers="org.eclipse.cdt.core.CWDLocator;org.eclipse.cdt.core.GmakeErrorParser;org.eclipse.cdt.core.GCCErrorParser;org.eclipse.cdt.core.GLDErrorParser;org.eclipse.cdt.core.GASErrorParser" id="org.eclipse.linuxtools.cdt.autotools.core.configuration.build.debug.1819037516" name="Debug (GNU)" parent="org.eclipse.linuxtools.cdt.autotools.core.configuration.build.debug"> <configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.linuxtools.cdt.autotools.core.buildArtefactType.autotools" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.linuxtools.cdt.autotools.core.buildArtefactType.autotools,org.eclipse.cdt.build.core.buildType=org.eclipse.linuxtools.cdt.autotools.core.buildType.debug" cleanCommand="rm -rf" description="" errorParsers="org.eclipse.cdt.core.CWDLocator;org.eclipse.cdt.core.GmakeErrorParser;org.eclipse.cdt.core.GCCErrorParser;org.eclipse.cdt.core.GLDErrorParser;org.eclipse.cdt.core.GASErrorParser" id="org.eclipse.linuxtools.cdt.autotools.core.configuration.build.debug.1819037516" name="Debug (GNU)" optionalBuildProperties="" parent="org.eclipse.linuxtools.cdt.autotools.core.configuration.build.debug">
<folderInfo id="org.eclipse.linuxtools.cdt.autotools.core.configuration.build.debug.1819037516." name="/" resourcePath=""> <folderInfo id="org.eclipse.linuxtools.cdt.autotools.core.configuration.build.debug.1819037516." name="/" resourcePath="">
...@@ -121,13 +121,13 @@ ...@@ -121,13 +121,13 @@
<targetPlatform id="org.eclipse.linuxtools.cdt.autotools.core.toolchain.targetPlatform.debug.374872327" isAbstract="false" name="GNU Autotools Target Platform" superClass="org.eclipse.linuxtools.cdt.autotools.core.toolchain.targetPlatform.debug"/> <targetPlatform id="org.eclipse.linuxtools.cdt.autotools.core.toolchain.targetPlatform.debug.374872327" isAbstract="false" name="GNU Autotools Target Platform" superClass="org.eclipse.linuxtools.cdt.autotools.core.toolchain.targetPlatform.debug"/>
<builder id="org.eclipse.linuxtools.cdt.autotools.core.toolchain.builder.debug.738536384" name="Autotools Makefile Generator.Debug (GNU)" superClass="org.eclipse.linuxtools.cdt.autotools.core.toolchain.builder.debug"/> <builder id="org.eclipse.linuxtools.cdt.autotools.core.toolchain.builder.debug.738536384" keepEnvironmentInBuildfile="false" name="Autotools Makefile Generator" superClass="org.eclipse.linuxtools.cdt.autotools.core.toolchain.builder.debug"/>
<tool id="org.eclipse.linuxtools.cdt.autotools.core.gnu.toolchain.tool.configure.debug.2083164547" name="configure" superClass="org.eclipse.linuxtools.cdt.autotools.core.gnu.toolchain.tool.configure.debug"> <tool id="org.eclipse.linuxtools.cdt.autotools.core.gnu.toolchain.tool.configure.debug.2083164547" name="configure" superClass="org.eclipse.linuxtools.cdt.autotools.core.gnu.toolchain.tool.configure.debug">
<option defaultValue="CFLAGS=-g -O0" id="org.eclipse.linuxtools.cdt.autotools.core.option.configure.user.149937447" superClass="org.eclipse.linuxtools.cdt.autotools.core.option.configure.user" valueType="string"/> <option defaultValue="CFLAGS=-g -O0" id="org.eclipse.linuxtools.cdt.autotools.core.option.configure.user.149937447" name="User-specified configuration options" superClass="org.eclipse.linuxtools.cdt.autotools.core.option.configure.user" valueType="string"/>
<option id="org.eclipse.linuxtools.cdt.autotools.core.option.configure.name.2101311718" superClass="org.eclipse.linuxtools.cdt.autotools.core.option.configure.name" value="org.eclipse.linuxtools.cdt.autotools.core.configuration.build.debug.1819037516" valueType="string"/> <option id="org.eclipse.linuxtools.cdt.autotools.core.option.configure.name.2101311718" name="Name" superClass="org.eclipse.linuxtools.cdt.autotools.core.option.configure.name" value="org.eclipse.linuxtools.cdt.autotools.core.configuration.build.debug.1819037516" valueType="string"/>
</tool> </tool>
......
...@@ -6,7 +6,7 @@ Tick = 10 # ms ...@@ -6,7 +6,7 @@ Tick = 10 # ms
Zone = 1 Zone = 1
plic = 21 # ETHERNET plic = 21 # ETHERNET
base = 0x20440000; size = 128K; rwx = rx # FLASH base = 0x20440000; size = 128K; rwx = rwx # FLASH
base = 0x80001800; size = 38K; rwx = rw # RAM base = 0x80001800; size = 38K; rwx = rw # RAM
base = 0x8000B000; size = 2K; rwx = w # SH BUFF1 base = 0x8000B000; size = 2K; rwx = w # SH BUFF1
base = 0x8000B800; size = 8K; rwx = w # SH BUFF2 base = 0x8000B800; size = 8K; rwx = w # SH BUFF2
......
...@@ -4,6 +4,7 @@ adapter_khz 10000 ...@@ -4,6 +4,7 @@ adapter_khz 10000
interface ftdi interface ftdi
ftdi_device_desc "Olimex OpenOCD JTAG ARM-USB-TINY-H" ftdi_device_desc "Olimex OpenOCD JTAG ARM-USB-TINY-H"
#ftdi_device_desc "Olimex Ltd. ARM-USB-TINY-H JTAG interface"
ftdi_vid_pid 0x15ba 0x002a ftdi_vid_pid 0x15ba 0x002a
ftdi_layout_init 0x0808 0x0a1b ftdi_layout_init 0x0808 0x0a1b
......
...@@ -2,13 +2,15 @@ ...@@ -2,13 +2,15 @@
TARGET = zone1.elf TARGET = zone1.elf
C_SRCS += main.c tcp_cb.c queue.c C_SRCS += main.c tcp_cb.c queue.c http_helpers.c webserver.c
INCLUDES += -I ../ext INCLUDES += -I ../ext
INCLUDES += -I ../ext/multizone INCLUDES += -I ../ext/multizone
INCLUDES += -I ../ext/lwip/src/include INCLUDES += -I ../ext/lwip/src/include
INCLUDES += -I ../ext/mbedtls/include INCLUDES += -I ../ext/mbedtls/include
C_FLAGS+="-g"
LINKER_SCRIPT := linker.lds LINKER_SCRIPT := linker.lds
### BSP ### BSP
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
//for enums //for enums
#include "webserver.h" #include "server_utility.h"
static err_t tcp_cb_parse_http(struct altcp_pcb *package_control_block, struct tcp_cb_state *tcp_state, struct pbuf *package_buffer) static err_t tcp_cb_parse_http(struct altcp_pcb *package_control_block, struct tcp_cb_state *tcp_state, struct pbuf *package_buffer)
...@@ -42,6 +42,8 @@ static err_t tcp_cb_parse_http(struct altcp_pcb *package_control_block, struct t ...@@ -42,6 +42,8 @@ static err_t tcp_cb_parse_http(struct altcp_pcb *package_control_block, struct t
//drop //drop
return ERR_OK; return ERR_OK;
} }
char *location = current_position;
while(current_position < end_ptr && *current_position != ' ') { while(current_position < end_ptr && *current_position != ' ') {
++current_position; ++current_position;
} }
...@@ -80,21 +82,19 @@ static err_t tcp_cb_parse_http(struct altcp_pcb *package_control_block, struct t ...@@ -80,21 +82,19 @@ static err_t tcp_cb_parse_http(struct altcp_pcb *package_control_block, struct t
return ERR_VAL; return ERR_VAL;
} }
uint32_t outlen = 0;
//we have no handler, so from here in it differs bool free_result = false;
//mainly the same as the server_resp in wifi_exploit.c char* response = server_request_handler(location, request_type, current_position, length, &outlen, &free_result);
error_rv = altcp_write(
if(request_type == GET_REQUEST) { package_control_block
char *get_response = , response
"HTTP/1.1 200 OK\r\n" , outlen
"Content-Length: 15\r\n" , 0
"Connection: Close\r\n" );
"\r\n" if(free_result) {
"Hello, World!" free(response);
"\r\n";
error_rv = altcp_write(package_control_block, get_response, strlen(get_response)+1, 0);
} }
return error_rv; return error_rv;
} }
...@@ -218,7 +218,7 @@ static err_t tcp_cb_poll(void *arg, struct altcp_pcb *package_control_block) ...@@ -218,7 +218,7 @@ static err_t tcp_cb_poll(void *arg, struct altcp_pcb *package_control_block)
} }
} }
else { else {
tcp_abort(package_control_block); altcp_abort(package_control_block);
tcp_cb_close(package_control_block, tcp_state); tcp_cb_close(package_control_block, tcp_state);
error_rv = ERR_ABRT; error_rv = ERR_ABRT;
} }
......
...@@ -132,3 +132,49 @@ void webserver_run(request_handler handler) { ...@@ -132,3 +132,49 @@ void webserver_run(request_handler handler) {
free(data); free(data);
} }
} }
uint32_t webserver_percent_decode(char *data, uint32_t len) {
// Decode in-place according to https://url.spec.whatwg.org/#percent-decode and https://url.spec.whatwg.org/#urlencoded-parsing
// The in-place decoding works, because in_index can only be "faster" than out_index, not "slower".
// The new length is returned.
// If The length is reduced, a '\0'-byte is appended at the end, but not included with the length.
uint32_t in_index = 0, out_index = 0;
while(in_index < len) {
if(data[in_index] == '+') {
data[out_index] = ' ';
} else if(data[in_index] == '%' && in_index + 2 < len) {
char bytes[2];
for(int i = 0; i < 2; ++i) {
if('0' <= data[in_index + i + 1] && data[in_index + i + 1] <= '9') {
bytes[i] = data[in_index + i + 1] - '0';
} else if('a' <= data[in_index + i + 1] && data[in_index + i + 1] <= 'f') {
bytes[i] = data[in_index + i + 1] - 'a' + 10;
} else if('A' <= data[in_index + i + 1] && data[in_index + i + 1] <= 'F') {
bytes[i] = data[in_index + i + 1] - 'A' + 10;
} else {
bytes[i] = 16;
}
}
if(bytes[0] == 16 || bytes[1] == 16) {
data[out_index] = data[in_index];
} else {
data[out_index] = (bytes[0] << 4) | bytes[1];
in_index += 2;
}
} else {
data[out_index] = data[in_index];
}
++in_index;
++out_index;
}
if(out_index < in_index) {
data[out_index] = '\0';
}
return out_index;
}
...@@ -41,7 +41,8 @@ typedef char *(*request_handler)(char *location, enum request_type type, char *d ...@@ -41,7 +41,8 @@ typedef char *(*request_handler)(char *location, enum request_type type, char *d
int webserver_init(struct network_implementation network); int webserver_init(struct network_implementation network);
// Runs the webserver with the given request handling function. // Runs the webserver with the given request handling function.
void webserver_run(request_handler handler); void webserver_run(request_handler handler);
// Percent decodes the given data in-place returning the new length.
void webserver_handle_request(request_handler handler, int id, uint32_t len, char *data); // Also appends a '\0'-byte, if the output is shorter than the input.
uint32_t webserver_percent_decode(char *data, uint32_t len);
#endif /* WEBSERVER_H_ */ #endif /* WEBSERVER_H_ */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment