# Copyright Runtime.io 2018. All rights reserved.
# Copyright Nordic Semiconductor ASA 2020-2022. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

# The Kconfig file is dedicated to OS management group of
# of MCUmgr subsystem and provides Kconfig options to configure
# group commands behaviour and other aspects.
#
# Options defined in this file should be prefixed:
#  MCUMGR_GRP_OS_ -- general group options;
#
# When adding Kconfig options, that control the same feature,
# try to group them together by the same stem after prefix.

menuconfig MCUMGR_GRP_OS
	bool "Mcumgr handlers for OS management"
	imply REBOOT
	help
	  Enables MCUmgr handlers for OS management

if MCUMGR_GRP_OS

if REBOOT

config MCUMGR_GRP_OS_RESET_MS
	int "Delay before executing reset command (ms)"
	default 250
	depends on MULTITHREADING
	help
	  When a reset command is received, the system waits this many milliseconds
	  before performing the reset.  This delay allows time for the MCUmgr
	  response to be delivered.

config MCUMGR_GRP_OS_RESET_HOOK
	bool "Reset hook"
	depends on MCUMGR_MGMT_NOTIFICATION_HOOKS
	help
	  Allows applications to control and get notifications of when a reset
	  command has been issued via an MCUmgr command. With this option
	  disabled, modules will reboot when the command is received without
	  notification, when this is enabled and a handler is registered, the
	  application will be notified that a reset command has been received
	  and will allow the application to perform any required operations
	  before accepting or declining the reset request.

config MCUMGR_GRP_OS_RESET_BOOT_MODE
	bool "Boot mode"
	depends on RETENTION_BOOT_MODE
	help
	  Allows applications to set the boot mode using the retention boot mode module which
	  allows for booting other images e.g. as part of a bootloader. This is done with an
	  optional field in the reset command which specifies the value of the boot mode.

endif

config MCUMGR_GRP_OS_TASKSTAT
	bool "Support for taskstat command"
	select MCUMGR_SMP_CBOR_MIN_ENCODING_LEVEL_3 if ZCBOR_CANONICAL
	depends on THREAD_MONITOR

if MCUMGR_GRP_OS_TASKSTAT

config MCUMGR_GRP_OS_TASKSTAT_ONLY_SUPPORTED_STATS
	bool "Send only data gathered by Zephyr"
	default y
	help
	  Response will not include fields the Zephyr does not collect statistic for.
	  Enable this if your client software is able to process "taskstat" response
	  that would be missing "runtime", "cswcnt", "last_checkin" and "next_checkin"
	  map entries for each listed task.
	  Enabling this option will slightly reduce code size.

choice MCUMGR_GRP_OS_TASKSTAT_THREAD_NAME_CHOICE
	prompt "Characteristic used as thread name in taskstat"
	default MCUMGR_GRP_OS_TASKSTAT_USE_THREAD_NAME_FOR_NAME if THREAD_NAME
	default MCUMGR_GRP_OS_TASKSTAT_USE_THREAD_PRIO_FOR_NAME
	help
	  Select what will serve as thread name in "taskstat" response.
	  By default taskstat responses use thread priority, when THREAD_NAME is disabled,

config MCUMGR_GRP_OS_TASKSTAT_USE_THREAD_NAME_FOR_NAME
	bool "Thread name"
	depends on THREAD_NAME

config MCUMGR_GRP_OS_TASKSTAT_USE_THREAD_IDX_FOR_NAME
	bool "Thread index"

config MCUMGR_GRP_OS_TASKSTAT_USE_THREAD_PRIO_FOR_NAME
	bool "Thread priority"

endchoice

config MCUMGR_GRP_OS_TASKSTAT_MAX_NUM_THREADS
	int "Predicted maximum number of threads to return on taskstat list"
	default 50
	help
	  This is used for defining CBOR map holding thread info.
	  The value does not affect memory allocation, it is used by zcbor
	  to figure out how to encode map depending on its predicted size.

config MCUMGR_GRP_OS_TASKSTAT_THREAD_NAME_LEN
	int "Length of thread name to return in response"
	default THREAD_MAX_NAME_LEN if THREAD_NAME
	default 5 if !THREAD_NAME
	range 3 THREAD_MAX_NAME_LEN if THREAD_NAME
	range 3 6 if !THREAD_NAME
	help
	  The length of the string that is sent in response to taskstat command,
	  as a thread name.
	  When THREAD_NAME is enabled then this defaults to THREAD_MAX_NAME_LEN.
	  When THREAD_NAME is disabled the name is generated from thread priority,
	  signed integer, and this number regulates how many digits will be used;
	  in such case this value should also take into account possible '-'
	  sign.

config MCUMGR_GRP_OS_TASKSTAT_SIGNED_PRIORITY
	bool "Signed priorities"
	default y
	help
	  Zephyr uses int8_t as thread priorities, but in taskstat response it encodes
	  them as unsigned.  Enabling this option will use signed int for priorities in
	  responses, which is more natural for Zephyr.
	  Disable this option if your client software is unable to properly decode and
	  accept signed integers as priorities.

config MCUMGR_GRP_OS_TASKSTAT_STACK_INFO
	bool "Include stack info in taskstat responses"
	depends on THREAD_STACK_INFO
	help
	  Enabling this option adds stack information into "taskstat" command
	  responses, this is default when THREAD_STACK_INFO is selected.
	  Disable this option only when your client application is able to
	  process "taskstat" response without the "stksiz" and "stkuse" fields.
	  It is worth disabling this option when THREAD_STACK_INFO is disabled,
	  as it will prevent sending zeroed stack information just to fill
	  all the fields in "taskstat" responses, and it will slightly reduce code size.

endif

config MCUMGR_GRP_OS_ECHO
	bool "Support for echo command"
	default y
	select MCUMGR_SMP_CBOR_MIN_DECODING_LEVEL_2

config MCUMGR_GRP_OS_DATETIME
	bool "Support for datetime command"
	depends on RTC
	depends on $(dt_alias_enabled,rtc)
	select MCUMGR_SMP_CBOR_MIN_DECODING_LEVEL_2
	help
	  Enables support for the datetime get and set functions, this allows for using the
	  `rtc` alias device as a timesource from which the current time can be written or read.

config MCUMGR_GRP_OS_DATETIME_MS
	bool "Support millisecond field in datetime commands"
	depends on MCUMGR_GRP_OS_DATETIME

config MCUMGR_GRP_OS_DATETIME_HOOK
	bool "Datetime hook"
	depends on MCUMGR_GRP_OS_DATETIME
	depends on MCUMGR_MGMT_NOTIFICATION_HOOKS
	help
	  Allows applications to control and get notifications of when a datetime set/get
	  command has been issued via an MCUmgr command.

config MCUMGR_GRP_OS_MCUMGR_PARAMS
	bool "MCUMGR Parameters retrieval command"

config MCUMGR_GRP_OS_INFO
	bool "Support for info command"
	help
	  Can be used similarly to the unix/linux uname command for retrieving system information
	  including kernel version, processor architecture and board name.

if MCUMGR_GRP_OS_INFO

config MCUMGR_GRP_OS_INFO_MAX_RESPONSE_SIZE
	int "Maximum response size for info command"
	default 256
	range 32 512
	help
	  The maximum size of the response to the info command, will use a stack buffer of this
	  size to store the data in. If the output response is too big then the output will not be
	  present in the response, which will just contain the result code (rc) of memory error.

config MCUMGR_GRP_OS_INFO_HARDWARE_INFO_SHORT_HARDWARE_PLATFORM
	bool "Use short hardware platform (board name) [DEPRECATED]"
	select DEPRECATED
	help
	  Will use the board name and board revision without the SoC or variant information if
	  enabled which is the Zephyr 4.2 and earlier behaviour, otherwise will output the full
	  board target for the hardware platform.

config MCUMGR_GRP_OS_INFO_CUSTOM_HOOKS
	bool "Custom info hooks"
	depends on MCUMGR_MGMT_NOTIFICATION_HOOKS
	help
	  Supports adding custom command/character processing to the info command by using
	  registered callbacks. Data can be appended to the struct provided in the callback.

config MCUMGR_GRP_OS_INFO_BUILD_DATE_TIME
	bool "Show build date and time"
	help
	  Will allow returning the build date and time of the firmware by using the info with
	  format option 'b' (will also be returned with all responses by using 'a').

	  Note: This will invalidate reproducible builds of the firmware as it will embed the
	  build date/time in the output firmware image.

endif

config MCUMGR_GRP_OS_BOOTLOADER_INFO
	bool "Bootloader information"
	help
	  Allows to query MCUmgr about bootloader used by device and various bootloader
	  parameters.

config MCUMGR_GRP_OS_BOOTLOADER_INFO_HOOK
	bool "Bootloader info hooks"
	depends on MCUMGR_MGMT_NOTIFICATION_HOOKS
	help
	  Supports adding custom responses to the bootloader info command by using registered
	  callbacks. Data can be appended to the struct provided in the callback.

module = MCUMGR_GRP_OS
module-str = mcumgr_grp_os
source "subsys/logging/Kconfig.template.log_config"

endif
