From 346be8427facd54aff1880a706aca08b4d19f4f6 Mon Sep 17 00:00:00 2001 From: Chenjingwen Date: Thu, 21 Sep 2023 20:03:46 +0800 Subject: [PATCH] add response units MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 定义响应单元头接口,并实现一个打印日志的响应单元。 Signed-off-by: Chenjingwen --- .../core/response_unit/secDetector_response.c | 33 +++++++++++++++++ kerneldriver/include/secDetector_response.h | 22 ++++++++++++ .../include/secDetector_response_type.h | 36 +++++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 kerneldriver/core/response_unit/secDetector_response.c create mode 100644 kerneldriver/include/secDetector_response.h create mode 100644 kerneldriver/include/secDetector_response_type.h diff --git a/kerneldriver/core/response_unit/secDetector_response.c b/kerneldriver/core/response_unit/secDetector_response.c new file mode 100644 index 0000000..f62547c --- /dev/null +++ b/kerneldriver/core/response_unit/secDetector_response.c @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 Huawei Technologies Co., Ltd. All rights reserved. + * secDetector is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + * + * Author: chenjingwen + * Create: 2023-09-21 + * Description: secDetector response source + */ +#include "secDetector_response.h" + +static const response_func_t response_units[NR_RESPONSE] = { + [RESPONSE_REPORT] = secdetector_report, +}; + +void notrace secdetector_respond(unsigned int response_type, response_data_t *data) +{ + if (response_type >= NR_RESPONSE) + return; + + response_units[response_type](data); +} + +void notrace secdetector_report(response_data_t *data) +{ + pr_info("%s", data->report_data.text); +} \ No newline at end of file diff --git a/kerneldriver/include/secDetector_response.h b/kerneldriver/include/secDetector_response.h new file mode 100644 index 0000000..1c4565e --- /dev/null +++ b/kerneldriver/include/secDetector_response.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 Huawei Technologies Co., Ltd. All rights reserved. + * secDetector is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + * + * Author: chenjingwen + * Create: 2023-09-21 + * Description: secDetector reponse header + */ +#ifndef SECDETECTOR_RESPONSE_H +#define SECDETECTOR_RESPONSE_H +#include "secDetector_response_type.h" + +extern void notrace secdetector_respond(unsigned int response_type, response_data_t *data); +extern void notrace secdetector_report(response_data_t *data); +#endif \ No newline at end of file diff --git a/kerneldriver/include/secDetector_response_type.h b/kerneldriver/include/secDetector_response_type.h new file mode 100644 index 0000000..6520467 --- /dev/null +++ b/kerneldriver/include/secDetector_response_type.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2023 Huawei Technologies Co., Ltd. All rights reserved. + * secDetector is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + * + * Author: chenjingwen + * Create: 2023-09-21 + * Description: secDetector response type header + */ +#ifndef SECDETECTOR_REPORT_TYPE_H +#define SECDETECTOR_REPORT_TYPE_H +#include + +enum { + RESPONSE_REPORT, + RESPONSE_REJECT, + NR_RESPONSE, +}; + +struct response_report_data { + const char *text; + size_t len; +}; + +typedef union response_data { + struct response_report_data *report_data; +} response_data_t; + +typedef void (*response_func_t)(response_data_t *data); +#endif \ No newline at end of file -- Gitee