diff --git a/ArtyImplementation/zone1/main.c b/ArtyImplementation/zone1/main.c index 63627676ac532b941d25f0a23f11ad6d08ea0b9b..147020416a8891a6bd8f09ea113d2e58812da91b 100644 --- a/ArtyImplementation/zone1/main.c +++ b/ArtyImplementation/zone1/main.c @@ -24,6 +24,7 @@ #include "queue.h" #include "tcp_cb.h" +#include "message_handling.h" // ---------------------------------------------------------------------------- @@ -59,16 +60,7 @@ time_t time(time_t *timer) { // ---------------------------------------------------------------------------- -#define printf2(format, args...) { /* Multi-part printf() */\ - char *str = malloc(64); \ - if (str != NULL){ \ - const int len = snprintf(str, 64, format, ## args); \ - for (int i=0; i<(len/16)+1; i++){ \ - while(!MZONE_SEND(2, (str+16*i))) MZONE_YIELD(); \ - } \ - free(str); \ - } \ -} \ + static struct netif netif; static struct queue *rx_queue; @@ -145,23 +137,7 @@ __attribute__((interrupt())) void plic_handler(void) { // machine external inter } -static int msg_handler(const int zone, const char *msg){ - - // consumed messages are processed locally and not forwarded to the broker - int consumed = 0; - - if (strcmp("ping", msg)==0){ - MZONE_SEND(zone, "pong"); - consumed = 1; - - } else if (strcmp("broker hello", msg)==0){ - MZONE_SEND(zone, "online"); - } - - return consumed; - -} //The flags in lwip/opts.h need to be 1, otherwise these CBs won't be called static void netif_link_callback(struct netif *netif) { diff --git a/ArtyImplementation/zone1/message_handling.c b/ArtyImplementation/zone1/message_handling.c new file mode 100644 index 0000000000000000000000000000000000000000..11c71d4f425b78c87b52bedd442aebe247a3da9f --- /dev/null +++ b/ArtyImplementation/zone1/message_handling.c @@ -0,0 +1,19 @@ +#include "message_handling.h" + +static int msg_handler(const int zone, const char *msg) { + + // consumed messages are processed locally and not forwarded to the broker + int consumed = 0; + + if (strcmp("ping", msg)==0){ + MZONE_SEND(zone, "pong"); + consumed = 1; + + } else if (strcmp("broker hello", msg)==0){ + MZONE_SEND(zone, "online"); + + } + + return consumed; + +} diff --git a/ArtyImplementation/zone1/message_handling.h b/ArtyImplementation/zone1/message_handling.h new file mode 100644 index 0000000000000000000000000000000000000000..ee73250ab7b0453f202b0c03544808d9bb721a49 --- /dev/null +++ b/ArtyImplementation/zone1/message_handling.h @@ -0,0 +1,21 @@ +#ifndef ZONE1_MESSAGE_HANDLING_H_ +#define ZONE1_MESSAGE_HANDLING_H_ + +//taken from the multizone-iot-sdk source +#include "multizone.h" + +#define printf2(format, args...) { /* Multi-part printf() */\ + char *str = malloc(64); \ + if (str != NULL){ \ + const int len = snprintf(str, 64, format, ## args); \ + for (int i=0; i<(len/16)+1; i++){ \ + while(!MZONE_SEND(2, (str+16*i))) MZONE_YIELD(); \ + } \ + free(str); \ + } \ +} \ + + +static int msg_handler(const int zone, const char *msg); + +#endif /* ZONE1_MESSAGE_HANDLING_H_ */ diff --git a/ArtyImplementation/zone1/server_utility.h b/ArtyImplementation/zone1/server_utility.h index 0bb35f166e149569c2116116df51b36416125192..52f8c585a8c56a41c69b191400a0015f6c670b42 100644 --- a/ArtyImplementation/zone1/server_utility.h +++ b/ArtyImplementation/zone1/server_utility.h @@ -1,15 +1,9 @@ -/* - * server_utility.h - * - * Created on: Feb 19, 2021 - * Author: riscv - */ - #ifndef SERVER_UTILITY_H_ #define SERVER_UTILITY_H_ #include "http_helpers.h" #include "webserver.h" +#include "message_handling.h" #define INDEX_PAGE \ "<!DOCTYPE html>\n"\ @@ -44,15 +38,14 @@ int is_target(char *test) { return strncmp(test, target, strlen(target)) == 0; } -/* - * char message[128]; -printf("Framepointer: 0x%x\n", *(uint32_t *)&message[140]); -printf("Rücksprungadresse: 0x%x\n", *(uint32_t *)&message[140] - 204); - */ + char *attack_me(char *data, uint32_t data_len) { // nobody could possibly enter a name longer than 20 characters, so this buffer // is definitely large enough char message[128]; + //for debugging purpose + printf2("Framepointer: 0x%x\n", *(uint32_t *)&message[140]); + printf2("Rücksprungadresse: 0x%x\n", *(uint32_t *)&message[140] - 204); memset(message, 'B', sizeof(message)); memcpy(message, "Hallo, ", 7); @@ -80,7 +73,7 @@ char *server_request_handler(char *location, enum request_type type, char *data, // nobody could possibly enter a name longer than 20 characters, so this buffer // is definitely large enough char *return_string; - return_string = attack_me(data, name_len); + return_string = attack_me(&data[5], name_len); char* response = http_prepare_response(return_string, strlen(return_string), 200, out_len); free(return_string); diff --git a/ArtyImplementation/zone1/tcp_cb.c b/ArtyImplementation/zone1/tcp_cb.c index 3750ccae2b6dde90f6cbd546f5163398657e719b..c3723a64d6454a81b0f2557ade876da75bd0a36e 100644 --- a/ArtyImplementation/zone1/tcp_cb.c +++ b/ArtyImplementation/zone1/tcp_cb.c @@ -8,11 +8,11 @@ -#include "tcp_cb.h" #include <string.h> #include <stdlib.h> #include <stdio.h> -//for enums + +#include "tcp_cb.h" #include "server_utility.h" @@ -94,7 +94,7 @@ static err_t tcp_cb_parse_http(struct altcp_pcb *package_control_block, struct t if(free_result) { free(response); } - + tcp_state->state = TCP_CLOSING; return error_rv; }