# CoAP implementation for Zephyr

# Copyright (c) 2017 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

config COAP
	bool "CoAP Support"
	help
	  This option enables the CoAP implementation.


if COAP

# This setting is only used by unit test. Do not enable it in applications
config COAP_TEST_API_ENABLE
	bool "Test API for CoAP unit tests"
	help
	  Do not enable this for normal use.

config COAP_WELL_KNOWN_BLOCK_WISE
	bool "CoAP ./well-known/core services block wise support"
	help
	  This option enables the block wise support of CoAP response
	  to ./well-known/core request. Without this option all resource's
	  information will be sent in a single IP packet (can be multiple
	  fragments depends on MTU size). This will be useful in mesh kind
	  of networks.

config COAP_WELL_KNOWN_BLOCK_WISE_SIZE
	int "CoAP ./well-known/core services block wise support"
	default 32
	depends on COAP_WELL_KNOWN_BLOCK_WISE
	help
	  Maximum size of CoAP block. Valid values are 16, 32, 64, 128,
	  256, 512 and 1024.

config COAP_EXTENDED_OPTIONS_LEN
	bool "Support for CoAP extended options"
	help
	  This option enables the parsing of extended CoAP options length.
	  CoAP extended options length can be 2 byte value, which
	  requires more memory. User can save memory by disabling this.
	  That means only length of maximum 12 bytes are supported by default.
	  Enable this if length field going to bigger that 12.

config COAP_EXTENDED_OPTIONS_LEN_VALUE
	int "CoAP extended options length value"
	default 13
	depends on COAP_EXTENDED_OPTIONS_LEN
	help
	  This option specifies the maximum value of length field when
	  COAP_EXTENDED_OPTIONS_LEN is enabled. Define the value according to
	  user requirement.

config COAP_INIT_ACK_TIMEOUT_MS
	int "base length of the random generated initial ACK timeout in ms"
	default 2000
	range 1000 100000
	help
	  This value is used as a base value to retry pending CoAP packets.

config COAP_RANDOMIZE_ACK_TIMEOUT
	bool "Randomize initial ACK timeout, as specified in RFC 7252"
	default y
	help
	  If enabled, the initial ACK timeout will be randomized, as specified
	  in RFC 7252, i.e. will be a random number between ACK_TIMEOUT and
	  ACK_TIMEOUT * ACK_RANDOM_FACTOR (where ACK_TIMEOUT is specified by
	  COAP_INIT_ACK_TIMEOUT_MS option). Otherwise, the initial ACK timeout
	  will be fixed to the value of COAP_INIT_ACK_TIMEOUT_MS option.

config COAP_ACK_RANDOM_PERCENT
	int "Random factor for ACK timeout described as percentage"
	default 150
	depends on COAP_RANDOMIZE_ACK_TIMEOUT
	help
	  Factor described as percentage to extend CoAP ACK timeout. A value
	  of 150 means a factor of 1.50.

config COAP_MAX_RETRANSMIT
	int "Max retransmission of a CoAP packet"
	default 4
	range 1 100

config COAP_BACKOFF_PERCENT
	int "Retransmission backoff factor for ACK timeout described as percentage"
	default 200
	help
	  Factor described as percentage to extend CoAP ACK timeout for retransmissions.
	  A value of 200 means a factor of 2.0.

config COAP_URI_WILDCARD
	bool "Wildcards in CoAP resource path"
	default y
	help
	  This option enables MQTT-style wildcards in path. Disable it if
	  resource path may contain plus or hash symbol.

config COAP_KEEP_USER_DATA
	bool "Keeping user data in the CoAP packet"
	help
	  This option enables keeping application-specific user data

config COAP_CLIENT
	bool "CoAP client support [EXPERIMENTAL]"
	select EXPERIMENTAL
	help
	  This option enables the API for CoAP-client for sending CoAP requests

if COAP_CLIENT

config COAP_CLIENT_THREAD_PRIORITY
	int "Coap client thread priority"
	default NUM_PREEMPT_PRIORITIES
	help
	  Priority of receive thread of the CoAP client.

config COAP_CLIENT_BLOCK_SIZE
	int "CoAP block-wise transfer block size"
	default 256
	range 64 1024
	help
	  CoAP block size used by CoAP client when performing block-wise
	  transfers. Possible values: 64, 128, 256, 512 and 1024.

config COAP_CLIENT_MESSAGE_SIZE
	int "Message payload size"
	default COAP_CLIENT_BLOCK_SIZE
	help
	  CoAP client message payload size. Can't be smaller than COAP_CLIENT_BLOCK_SIZE.

config COAP_CLIENT_MESSAGE_HEADER_SIZE
	int "Room for CoAP header data"
	default 48
	range 24 128
	help
	  Extra room allocated to handle CoAP header data

config COAP_CLIENT_MAX_PATH_LENGTH
	int "Maximum length of the path string"
	default 64
	range 1 128

config COAP_CLIENT_MAX_EXTRA_OPTIONS
	int "Maximum number of application-provided extra CoAP options"
	default 2
	range 1 16

config COAP_CLIENT_STACK_SIZE
	int "Stack size of the CoAP client thread"
	default 1024

config COAP_CLIENT_MAX_INSTANCES
	int "Maximum number of CoAP clients"
	default 2
	help
	  Maximum number of CoAP clients

config COAP_CLIENT_MAX_REQUESTS
	int "Maximum number of simultaneous requests per client"
	default 2
	help
	  Maximum number of CoAP requests a single client can handle at a time

config COAP_CLIENT_TRUNCATE_MSGS
	bool "Receive notification when blocks are truncated"
	default y
	help
	  Include ZSOCK_MSG_TRUNC in flags passed to zsock_recvfrom() to
	  receive network stack notifications about block truncation.
	  Otherwise it happens silently.

endif # COAP_CLIENT

config COAP_SERVER
	bool "CoAP server support [EXPERIMENTAL]"
	select EXPERIMENTAL
	select NET_SOCKETS
	select ZVFS
	select ZVFS_EVENTFD
	help
	  This option enables the API for CoAP-services to register resources.

if COAP_SERVER

config COAP_SERVER_STACK_SIZE
	int "CoAP server thread stack size"
	default 4096
	help
	  CoAP server thread stack size for processing RX/TX events.

config COAP_SERVER_BLOCK_SIZE
	int "CoAP server block-wise transfer size"
	default 256
	range 64 1024
	help
	  CoAP block size used by CoAP server resources when performing block-wise
	  transfers. Possible values: 64, 128, 256, 512 and 1024.

config COAP_SERVER_MESSAGE_SIZE
	int "CoAP server message payload size"
	default COAP_SERVER_BLOCK_SIZE
	help
	  CoAP server message payload size. Can't be smaller than COAP_SERVER_BLOCK_SIZE.

config COAP_SERVER_MESSAGE_OPTIONS
	int "CoAP server message options"
	default 16
	help
	  CoAP server message maximum number of options to parse.

config COAP_SERVER_WELL_KNOWN_CORE
	bool "CoAP server support ./well-known/core service"
	default y
	help
	  Enable responding to the ./well-known/core service resource.

config COAP_SERVICE_PENDING_MESSAGES
	int "CoAP service pending messages"
	default 10
	help
	  Maximum number of pending CoAP messages to retransmit per active service.

config COAP_SERVICE_OBSERVERS
	int "CoAP service observers"
	default 3
	help
	  Maximum number of CoAP observers per active service.

choice COAP_SERVER_PENDING_ALLOCATOR
	prompt "Pending data allocator"
	default COAP_SERVER_PENDING_ALLOCATOR_STATIC

config COAP_SERVER_PENDING_ALLOCATOR_NONE
	bool "No pending packets"
	help
	  Never allocate data for pending requests, this disables retransmits for confirmable
	  packets.

config COAP_SERVER_PENDING_ALLOCATOR_STATIC
	bool "Static reserved memory"
	help
	  Static memory will be reserved for pending messages. The total size is equal to
	  COAP_SERVER_PENDING_ALLOCATOR_STATIC_BLOCKS * COAP_SERVER_MESSAGE_SIZE.

config COAP_SERVER_PENDING_ALLOCATOR_SYSTEM_HEAP
	bool "System heap allocator"
	depends on HEAP_MEM_POOL_SIZE > 0
	help
	  Use k_malloc/k_free for pending data.

endchoice

config COAP_SERVER_PENDING_ALLOCATOR_STATIC_BLOCKS
	int "Number of pending data blocks"
	default COAP_SERVICE_PENDING_MESSAGES
	depends on COAP_SERVER_PENDING_ALLOCATOR_STATIC
	help
	  The number of data blocks to reserve for pending messages to retransmit.

config COAP_SERVER_TRUNCATE_MSGS
	bool "Handle truncated messages"
	default y
	help
	  Include ZSOCK_MSG_TRUNC in flags passed to zsock_recvfrom() to
	  receive network stack notifications about block truncation.
	  Otherwise it happens silently.

config COAP_SERVER_SHELL
	bool "CoAP service shell commands"
	depends on SHELL
	help
	  Enable CoAP service shell commands.

endif

module = COAP
module-dep = NET_LOG
module-str = Log level for CoAP
module-help = Enables CoAP debug messages.
source "subsys/net/Kconfig.template.log_config.net"

endif # COAP
