diff --git a/CMakeLists.txt b/CMakeLists.txt index 3fa58b7393c826c0c00246d49efbc5ad066061a9..99dbe9063361badcbc9d28223c5c6400a8211290 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,6 +33,7 @@ target_sources(app PRIVATE ${KESTREL_SOURCE_DIR}/src/flash_filesystem.c ${KESTREL_SOURCE_DIR}/src/fsi.c ${KESTREL_SOURCE_DIR}/src/kestrel.c + ${KESTREL_SOURCE_DIR}/src/redfish.c ${KESTREL_SOURCE_DIR}/src/simple_pwm.c ${KESTREL_SOURCE_DIR}/src/webservice.c ${KESTREL_SOURCE_DIR}/src/webportal.c diff --git a/kestrel/src/redfish.c b/kestrel/src/redfish.c new file mode 100644 index 0000000000000000000000000000000000000000..d520412f787c4faf2072c66c2dc0818173c65881 --- /dev/null +++ b/kestrel/src/redfish.c @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2021 Raptor Engineering, LLC <sales@raptorengineering.com> + * + * SPDX-License-Identifier: GPL-3.0 + */ + +#include <logging/log.h> +LOG_MODULE_REGISTER(redfish, LOG_LEVEL_DBG); + +#include <zephyr.h> +#include <posix/pthread.h> +#include <data/json.h> + +#include "simple_pwm.h" + +#include "webportal.h" +#include "redfish.h" + +#include "raptor_extensions.h" + +#define WITH_ZEPHYR 1 +#include "kestrel.h" +#include <generated/mem.h> + +#define STANDARD_HEADER(title) \ +"<head>" \ +"<title>" title "</title>" \ +"</head>" + +#define SEND_STANDARD_TITLE_HEADER(conn, title) \ +civetweb_send_file_data(conn, STANDARD_HEADER(title), sizeof(STANDARD_HEADER(title))); + +#define SEND_STANDARD_HEADER(conn, title) \ + +#define SEND_STANDARD_FOOTER(conn) + +const char* redfish_base_path = "/redfish/v1/"; + +struct json_redfish_version { + const char *v1; +}; + +static const struct json_obj_descr json_redfish_version_desc[] = { + JSON_OBJ_DESCR_PRIM(struct json_redfish_version, v1, JSON_TOK_STRING), +}; + +int redfish_version_handler(struct mg_connection *conn, void *cbdata) +{ + struct json_redfish_version redfish_version; + uint8_t json_string_buffer[1024]; + int ret; + + redfish_version.v1 = redfish_base_path; + + ret = json_obj_encode_buf(json_redfish_version_desc, + ARRAY_SIZE(json_redfish_version_desc), &redfish_version, + json_string_buffer, + sizeof(json_string_buffer)-1); + + if (ret) { + return -1; + } + + send_ok(conn); + + SEND_STANDARD_HEADER(conn, "Redfish API") + + mg_printf(conn, "%s", json_string_buffer); + + SEND_STANDARD_FOOTER(conn); + + return 200; +} \ No newline at end of file diff --git a/kestrel/src/redfish.h b/kestrel/src/redfish.h new file mode 100644 index 0000000000000000000000000000000000000000..70a78c13987ffc5fb769d370898033fa0b8e4b70 --- /dev/null +++ b/kestrel/src/redfish.h @@ -0,0 +1,11 @@ +// © 2021 Raptor Engineering, LLC +// +// Released under the terms of the GPL v3 +// See the LICENSE file for full details + +#ifndef _REDFISH_H +#define _REDFISH_H + +int redfish_version_handler(struct mg_connection *conn, void *cbdata); + +#endif // _REDFISH_H \ No newline at end of file diff --git a/kestrel/src/webportal.c b/kestrel/src/webportal.c index 98697c6386517ff4d05bd8d138017129e0c3e87c..c6d390c07f76be69da50d824f0852f95a133b1bb 100644 --- a/kestrel/src/webportal.c +++ b/kestrel/src/webportal.c @@ -11,10 +11,11 @@ LOG_MODULE_REGISTER(webportal, LOG_LEVEL_DBG); #include <posix/pthread.h> #include <data/json.h> -#include "civetweb.h" - #include "simple_pwm.h" +#include "webportal.h" +#include "redfish.h" + #include "raptor_extensions.h" #include "static_files.h" @@ -407,5 +408,8 @@ void *web_portal_pthread(void *arg) mg_set_request_handler(ctx, "/firmware$", firmware_upload_form_handler, (void *)"/firmware.upload"); mg_set_request_handler(ctx, "/firmware.upload$", firmware_upload_handler, (void *)0); + // Redfish + mg_set_request_handler(ctx, "/redfish$", redfish_version_handler, (void *)0); + return 0; } diff --git a/kestrel/src/webportal.h b/kestrel/src/webportal.h index 21fc451830f7520a653c56232749226160bfb9e5..0fc5d1204fa5b0b1af929b25c37aeba1ace6ae98 100644 --- a/kestrel/src/webportal.h +++ b/kestrel/src/webportal.h @@ -6,6 +6,9 @@ #ifndef _WEBPORTAL_H #define _WEBPORTAL_H +#include "civetweb.h" + void *web_portal_pthread(void *arg); +void send_ok(struct mg_connection *conn); #endif // _WEBPORTAL_H \ No newline at end of file