# Copyright (c) 2017 Linaro Limited
# SPDX-License-Identifier: Apache-2.0

menuconfig LWM2M
	bool "OMA LWM2M protocol stack"
	select COAP
	select HTTP_PARSER_URL
	select NET_SOCKETS
	help
	  This option adds logic for managing OMA LWM2M data

if LWM2M

module = LWM2M
module-dep = LOG
module-str = Log level for LWM2M library
source "subsys/net/Kconfig.template.log_config.net"

choice
	prompt "LwM2M protocol version"
	default LWM2M_VERSION_1_0
	help
	  Select which version of the LwM2M protocol is used

config LWM2M_VERSION_1_0
	bool "LwM2M version 1.0"
	imply LWM2M_RW_OMA_TLV_SUPPORT

config LWM2M_VERSION_1_1
	bool "LwM2M version 1.1"
	imply LWM2M_RW_CBOR_SUPPORT
	imply ZCBOR

endchoice

config LWM2M_SHELL
	bool "LwM2M shell utilities"
	select SHELL
	help
	  Activate shell module that provides LwM2M commands like
	  send to the console.

config LWM2M_DTLS_SUPPORT
	bool "DTLS support in the LwM2M client"

choice
	prompt "LwM2M Security object version"
	default LWM2M_SECURITY_OBJECT_VERSION_1_0 if LWM2M_VERSION_1_0
	default LWM2M_SECURITY_OBJECT_VERSION_1_1 if LWM2M_VERSION_1_1
	help
	  Select which version of the security object should be used.

config LWM2M_SECURITY_OBJECT_VERSION_1_0
	bool "Security object version 1.0"

config LWM2M_SECURITY_OBJECT_VERSION_1_1
	bool "Security object version 1.1"

endchoice

choice
	prompt "LwM2M Server object version"
	default LWM2M_SERVER_OBJECT_VERSION_1_0 if LWM2M_VERSION_1_0
	default LWM2M_SERVER_OBJECT_VERSION_1_1 if LWM2M_VERSION_1_1
	help
	  Select which version of the Server object should be used.

config LWM2M_SERVER_OBJECT_VERSION_1_0
	bool "Server object version 1.0"

config LWM2M_SERVER_OBJECT_VERSION_1_1
	bool "Server object version 1.1"

endchoice

config LWM2M_DNS_SUPPORT
	bool "DNS support in the LWM2M client"
	default y if DNS_RESOLVER

config LWM2M_ENGINE_STACK_SIZE
	int "LWM2M engine stack size"
	default 2560 if NET_LOG
	default 2048
	help
	  Set the stack size for the LWM2M library engine (used for handling
	  OBSERVE and NOTIFY events)

config LWM2M_ENGINE_MAX_MESSAGES
	int "LWM2M engine max. message object"
	default 10
	help
	  Set the maximum message objects for the LWM2M library client

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

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

config LWM2M_COAP_MAX_MSG_SIZE
	int "LWM2M CoAP maximum message size"
	default LWM2M_COAP_BLOCK_SIZE
	help
	  CoAP message size used by LWM2M. Minimum is the block size used
	  in blockwise transfers.

config LWM2M_COAP_BLOCK_TRANSFER
	bool "CoAP block transfer support for big outgoing LwM2M messages [EXPERIMENTAL]"
	select EXPERIMENTAL
	help
	  LwM2M messages with a big body that exceed the block size will be split
	  into blocks for sending.

if LWM2M_COAP_BLOCK_TRANSFER
config LWM2M_COAP_ENCODE_BUFFER_SIZE
	int "LwM2M CoAP buffer size for encoding the full message for block-wise transfer"
	default 1024
	help
	  Size of buffers for serializing big LwM2M CoAP messages that need to be
	  split into blocks for sending.

config LWM2M_NUM_OUTPUT_BLOCK_CONTEXT
	int "Maximum # of LWM2M block contexts used for outgoing messages"
	default 3
	help
	  Maximum number of CoAP block contexts needed to split messages into blocks for
	  sending. This limits the numer of messages that need block transfer that can be
	  handled at the same time.

config LWM2M_LOG_ENCODE_BUFFER_ALLOCATIONS
	bool "Log allocations of encode buffers for block wise transfer"
	select MEM_SLAB_TRACE_MAX_UTILIZATION
	help
	  The allocation of encode buffers can be tracked to analyse the usage and
	  to optimize the configuration of number of block contexts and indirectly
	  the number of available encode buffers.
endif # LWM2M_COAP_BLOCK_TRANSFER

config LWM2M_ENGINE_VALIDATION_BUFFER_SIZE
	int "Size of the validation buffer for the incoming data"
	default 64
	help
	  LwM2M will use the validation buffer during the write operation, to
	  decode the resource value before validating it (applies for resources
	  for which validation callback has been registered). Set this value to
	  the maximum expected size of the resources that need to be validated
	  (and thus have validation callback registered).
	  Setting the validation buffer size to 0 disables validation support.

config LWM2M_ENGINE_MAX_PENDING
	int "LWM2M engine max. pending objects"
	default 5
	help
	  Set the maximum pending objects for the LWM2M library client

config LWM2M_ENGINE_MAX_REPLIES
	int "LWM2M engine max. reply objects"
	default 5
	help
	  Set the maximum reply objects for the LWM2M library client

config LWM2M_ENGINE_MAX_OBSERVER
	int "Maximum # of observable LWM2M resources"
	default 10
	range 5 200
	help
	  This value sets the maximum number of resources which can be
	  added to the observe notification list.

config LWM2M_CANCEL_OBSERVE_BY_PATH
	bool "Use path matching as fallback for cancel-observe"
	help
	  Some ambiguous language in the LwM2M spec causes some LwM2M server
	  implementations to implement cancel-observe by specifying the resource
	  path rather than the token of the original observe request. Without
	  this option, cancel-observe may not work properly when connecting to
	  those servers.

config LWM2M_ENGINE_DEFAULT_LIFETIME
	int "LWM2M engine default server connection lifetime"
	default 30
	range 15 4294967295
	help
	  Set the default lifetime (in seconds) for the LWM2M library engine.
	  This is also a minimum lifetime that client accepts. If server sets lifetime
	  less than this value, client automatically raises it.

config LWM2M_SECONDS_TO_UPDATE_EARLY
	int "LWM2M Registration Update transmission time before timeout"
	default 6
	range 1 4294967295
	help
	  Time in seconds before the registration timeout, when the LWM2M
	  Registration Update is sent by the engine. In networks with large
	  round trip times (like NB-IoT), it might be needed to set this value
	  higher, in order to allow the response to arrive before timeout.

config LWM2M_QUEUE_MODE_ENABLED
	bool "Queue Mode UDP binding"
	help
	  Set the transport binding to UDP with Queue Mode (UQ).

config LWM2M_QUEUE_MODE_UPTIME
	int "Specify time the LWM2M client should stay online in queue mode."
	default 93
	help
	  This config specifies time (in seconds) the device should stay online
	  after sending a message to the server. Note, that LWM2M specification
	  recommends this to be CoAP MAX_TRANSMIT_WAIT parameter (which
	  defaults to 93 seconds, see RFC 7252), it does not forbid other
	  values though.

config LWM2M_TLS_SESSION_CACHING
	bool "TLS session caching"
	help
	  Enabling this only when feature is supported in TLS library.

choice
prompt "Socket handling at idle state"

config LWM2M_RD_CLIENT_CLOSE_SOCKET_AT_IDLE
	bool "Close socket when entering RX idle"

config LWM2M_RD_CLIENT_SUSPEND_SOCKET_AT_IDLE
	bool "Stop polling on RX idle and close only when resuming"

config  LWM2M_RD_CLIENT_STOP_POLLING_AT_IDLE
	bool "Stop polling the socket on RX idle"

config  LWM2M_RD_CLIENT_LISTEN_AT_IDLE
	bool "Keep open and listening"

endchoice

config LWM2M_RD_CLIENT_SUPPORT
	bool "support for LWM2M client bootstrap/registration state machine"
	select DEPRECATED
	help
	  Deprecated flag. RD state machine is always part of engine. It cannot be disabled.

config LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP
	bool "Bootstrap support"
	help
	  Enabling this setting allows the RD client to support bootstrap mode.

config LWM2M_RD_CLIENT_ENDPOINT_NAME_MAX_LENGTH
	int "Maximum length of client endpoint name"
	default 33
	help
	  Default: room for 32 hexadecimal digits (UUID) + NULL

config LWM2M_RD_CLIENT_MAX_RETRIES
	int "Specify maximum number of registration retries"
	default 5
	help
	  Specify maximum number of registration retries, before the application
	  is notified about the network failure. Once application is notified,
	  it's up to the application to handle this situation in a way
	  appropriate for the specific use-case (for instance by waiting for
	  LTE link to be re-established).

config LWM2M_ACCESS_CONTROL_ENABLE
	bool "Access control support"
	help
	  Enabling this setting registers the access control object (obj_id 2).

config LWM2M_ACCESS_CONTROL_INSTANCE_COUNT
	int "Maximum # of LWM2M Access Control object instances"
	default 50
	help
	  This setting establishes the total count of LWM2M Access Control instances
	  available to the client.

config LWM2M_SERVER_DEFAULT_SSID
	int "Default server ssid when using the lwm2m-client. (used for access control)"
	default 101
	help
	  When bootstrap is not enabled, access control needs a default owner.

config LWM2M_PEER_PORT
	int "LWM2M server port"
	default 5683
	help
	  This is the default server port to connect to for LWM2M communication.

config LWM2M_FIRMWARE_PORT_NONSECURE
	int "LWM2M firmware server port non-secure"
	default 5683
	help
	  This is the default server port to connect to for LwM2M firmware downloads over coap.

config LWM2M_FIRMWARE_PORT_SECURE
	int "LWM2M firmware server port secure"
	default 5684
	help
	  This is the default server port to connect to for LwM2M firmware downloads over coaps.

config LWM2M_SECURITY_INSTANCE_COUNT
	int "Maximum # of LWM2M Security object instances"
	default 2 if LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP
	default 1
	range 1 10
	help
	  This setting establishes the total count of LWM2M Security instances
	  available to the client.

config LWM2M_SECURITY_KEY_SIZE
	int "Buffer size of the security key resources"
	default 16
	help
	  This setting establishes the size of the key (pre-shared / public)
	  resources in the security object instances.

config LWM2M_SECURITY_DTLS_TLS_CIPHERSUITE_MAX
	int "Maximum # of DTLS/TLS ciphersuite resource instances"
	default 5
	range 0 20
	depends on LWM2M_SECURITY_OBJECT_VERSION_1_1
	help
	  This setting sets the maximum number of the resource instances of
	  a security object defined in LWM2M version 1.1. Affects the resource
	  0/X/16, where X is the object instance number.

config LWM2M_SERVER_DEFAULT_PMIN
	int "Default server record PMIN"
	default 0
	help
	  Default minimum amount of time in seconds the client must wait
	  between notifications.  If a resource has to be notified during this
	  minimum time period, the notification must be sent after the time
	  period expires.

config LWM2M_SERVER_DEFAULT_PMAX
	int "Default server record PMAX"
	default 0
	help
	  Default maximum amount of time in seconds the client may wait
	  between notifications.  When this time period expires a notification
	  must be sent.

config LWM2M_SERVER_INSTANCE_COUNT
	int "Maximum # of LWM2M Server object instances"
	default 2 if LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP
	default 1
	range 1 10
	help
	  This setting establishes the total count of LWM2M Server instances
	  available to the client (including: bootstrap and regular servers).

config LWM2M_CONN_MON_OBJ_SUPPORT
	bool "Connectivity Monitoring object support"
	help
	  Include support for LWM2M Connectivity Monitoring Object (ID 4)

choice
	prompt "LwM2M Connectivity Monitor object version"
	default LWM2M_CONNMON_OBJECT_VERSION_1_0 if LWM2M_VERSION_1_0
	default LWM2M_CONNMON_OBJECT_VERSION_1_2 if LWM2M_VERSION_1_1
	depends on LWM2M_CONN_MON_OBJ_SUPPORT
	help
	  Select Which version of the Connectivity Monitor object should be used.

config LWM2M_CONNMON_OBJECT_VERSION_1_0
	bool "Connectivity monitor object version 1.0"

config LWM2M_CONNMON_OBJECT_VERSION_1_2
	bool "Connectivity monitor object version 1.2"

endchoice

config LWM2M_CONN_MON_BEARER_MAX
	int "Maximum # of available network bearer resource instances"
	depends on LWM2M_CONN_MON_OBJ_SUPPORT
	default 1
	help
	  This value sets the maximum number of available network bearer
	  resource instances.  These are displayed via the
	  "Connection Monitoring" object /4/0/1.

config LWM2M_CONN_MON_APN_MAX
	int "Maximum # of APN resource instances"
	depends on LWM2M_CONN_MON_OBJ_SUPPORT
	default 1
	help
	  This value sets the maximum number of APN resource instances.
	  These are displayed via the "Connection Monitoring" object /4/0/7.

config LWM2M_FIRMWARE_UPDATE_OBJ_SUPPORT
	bool "Firmware Update object support"
	default y
	help
	  Include support for LWM2M Firmware Update Object (ID 5)

config LWM2M_FIRMWARE_UPDATE_OBJ_SUPPORT_MULTIPLE
	bool "Support multiple firmware update objects [EXPERIMENTAL]"
	depends on LWM2M_FIRMWARE_UPDATE_OBJ_SUPPORT
	select EXPERIMENTAL
	help
	  Support multiple instances of LWM2M Firmware Update Object (ID 5)

config LWM2M_FIRMWARE_UPDATE_OBJ_INSTANCE_COUNT
	int "Maximum # of LWM2M Firmware update object instances"
	default 1
	depends on LWM2M_FIRMWARE_UPDATE_OBJ_SUPPORT_MULTIPLE
	help
	  This setting establishes the total count of LWM2M Firmware update
	  object instances available to the client.

config LWM2M_FIRMWARE_UPDATE_PULL_SUPPORT
	bool "Firmware Update object pull support"
	default y
	depends on LWM2M_FIRMWARE_UPDATE_OBJ_SUPPORT
	depends on (HTTP_PARSER || HTTP_PARSER_URL)
	help
	  Include support for pulling a file from a remote server via
	  block transfer and "FIRMWARE PACKAGE URI" resource.  This option
	  adds another UDP context and packet handling.

config LWM2M_SWMGMT_OBJ_SUPPORT
	bool "Software management object support"
	help
	  Include support for LWM2M Software Management Object (ID 9)

config LWM2M_PORTFOLIO_OBJ_SUPPORT
	bool "LwM2M Portfolio object ID support for Conformance test"
	help
	  Include support for LWM2M Portfolio Object (ID 16).

config LWM2M_SWMGMT_MAX_INSTANCE_COUNT
	int "Maximum # of object instances"
	depends on LWM2M_SWMGMT_OBJ_SUPPORT
	default 1

config LWM2M_SWMGMT_PACKAGE_NAME_LEN
	int "Maximum size of the software management object's name string"
	depends on LWM2M_SWMGMT_OBJ_SUPPORT
	default 64

config LWM2M_SWMGMT_PACKAGE_VERSION_LEN
	int "Maximum size of the software management object's version string"
	depends on LWM2M_SWMGMT_OBJ_SUPPORT
	default 64

config LWM2M_SWMGMT_PACKAGE_URI_LEN
	int "Maximum size of the software management object's download URI string"
	depends on (LWM2M_SWMGMT_OBJ_SUPPORT || LWM2M_FIRMWARE_UPDATE_PULL_SUPPORT)
	default 128

config LWM2M_NUM_BLOCK1_CONTEXT
	int "Maximum # of LWM2M block1 contexts"
	default 3
	help
	  This value sets up the maximum number of block1 contexts for
	  CoAP block-wise transfer we can handle at the same time.

config LWM2M_FIRMWARE_UPDATE_PULL_COAP_PROXY_SUPPORT
	bool "Firmware Update object pull via CoAP-CoAP/HTTP proxy support"
	depends on LWM2M_FIRMWARE_UPDATE_PULL_SUPPORT
	help
	  Include support for pulling firmware file via a CoAP-CoAP/HTTP proxy.

config LWM2M_FIRMWARE_UPDATE_PULL_COAP_PROXY_ADDR
	string "CoAP proxy network address"
	depends on LWM2M_FIRMWARE_UPDATE_PULL_COAP_PROXY_SUPPORT
	help
	  Network address of the CoAP proxy server.

config LWM2M_RW_OMA_TLV_SUPPORT
	bool "TLV data format"
	help
	  Include support for write / parse TLV data

config LWM2M_RW_JSON_SUPPORT
	bool "support for JSON writer"
	depends on JSON_LIBRARY
	help
	  Include support for writing JSON data


config LWM2M_RW_SENML_JSON_SUPPORT
	bool "SENML JSON data format"
	depends on BASE64
	depends on JSON_LIBRARY
	help
	  Include support for write / parse SENML JSON data

config LWM2M_COMPOSITE_PATH_LIST_SIZE
	int "Maximum # of composite read and send operation URL path"
	default 6
	help
	  Define path list size for Composite Read and send operation.

config LWM2M_RW_CBOR_SUPPORT
	bool "support for CBOR writer"
	depends on ZCBOR
	help
	  Include support for writing CBOR data

config LWM2M_RW_SENML_CBOR_SUPPORT
	bool "support for SenML CBOR writer"
	depends on ZCBOR
	depends on ZCBOR_CANONICAL
	help
	  Include support for writing SenML CBOR data

config LWM2M_RW_SENML_CBOR_RECORDS
	int "Maximum # of SenML records packed into a CBOR binary"
	depends on LWM2M_RW_SENML_CBOR_SUPPORT
	default 30
	help
	  The CBOR library requires you to set an upper limit for the records when encoder
	  and decoder do get generated.

config LWM2M_RESOURCE_DATA_CACHE_SUPPORT
	bool "Resource Time series data cache support"
	depends on (LWM2M_RW_SENML_JSON_SUPPORT || LWM2M_RW_SENML_CBOR_SUPPORT)
	depends on (POSIX_CLOCK && RING_BUFFER)
	help
	  Enable time series data storage.
	  Requires time() to provide current Unix timestamp.

if LWM2M_RESOURCE_DATA_CACHE_SUPPORT
config LWM2M_MAX_CACHED_RESOURCES
	int "Maximum # of cached resources"
	default 4
	help
	  This settings define how many different resources may have cache enabled.
	  This affects static memory usage of engine.
choice
	prompt "Cache full policy"
	default LWM2M_CACHE_DROP_OLDEST

config LWM2M_CACHE_DROP_LATEST
	bool "Drop new data when cache is full"

config LWM2M_CACHE_DROP_OLDEST
	bool "Drop oldest data when cache is full"

endchoice

endif # LWM2M_RESOURCE_DATA_CACHE_SUPPORT

config LWM2M_DEVICE_PWRSRC_MAX
	int "Maximum # of device power source records"
	default 5
	range 1 20
	help
	  This value sets the maximum number of power source data that a device
	  can store.  These are displayed via the "Device" object /3/0/6,
	  /3/0/7 and /3/0/8 resources.

config LWM2M_DEVICE_ERROR_CODE_MAX
	int "Maximum # of device obj error codes to store"
	default 10
	range 1 20
	help
	  This value sets the maximum number of error codes that the device
	  object will store before ignoring new values.

config LWM2M_DEVICE_EXT_DEV_INFO_MAX
	int "Maximum # of device obj external device info to store"
	default 5
	range 1 20
	help
	  This value sets the maximum number of external device info that the
	  device object will store before ignoring new values.

config LWM2M_NUM_ATTR
	int "Maximum # of LWM2M attributes"
	default 20
	help
	  This value sets up the maximum number of LwM2M attributes that
	  we can handle at the same time.

config LWM2M_LOCATION_OBJ_SUPPORT
	bool "Location object support"
	help
	  Include support for LWM2M Location Object (ID 6)

config LWM2M_GATEWAY_OBJ_SUPPORT
	bool "LwM2M Gateway Object (25) [EXPERIMENTAL]"
	select EXPERIMENTAL

config LWM2M_EVENT_LOG_OBJ_SUPPORT
	bool "LwM2M Event Log Object (20)"
	help
	  Include support for LWM2M Event Log Object (ID 20)

config LWM2M_BINARYAPPDATA_OBJ_SUPPORT
	bool "LwM2M BinaryAppDataContainer Object (19)"
	help
	  Include support for LWM2M BinaryAppDataContainer Object (ID 19)

if LWM2M_GATEWAY_OBJ_SUPPORT

config LWM2M_GATEWAY_MAX_INSTANCES
	int "Maximum number of bridged devices"
	default 1
	help
	  This setting establishes the total count of LwM2M Gateway
	  instances available to the LWM2M client.

config LWM2M_GATEWAY_DEFAULT_DEVICE_ID
	string "Identifies the IoT Device bridged to the LwM2M Gateway"
	default "Node"

config LWM2M_GATEWAY_DEVICE_ID_MAX_STR_SIZE
	int "Maximum string size for device ID"
	default 32

config LWM2M_GATEWAY_DEFAULT_DEVICE_PREFIX
	string "Used for access to LwM2M Objects of this IoT Device"
	default "n"
	help
	  Defaults are n0, n1, n2, ..., n<max instances - 1>

config LWM2M_GATEWAY_PREFIX_MAX_STR_SIZE
	int "Max string size for prefix"
	default 32

config LWM2M_GATEWAY_DEFAULT_IOT_DEVICE_OBJECTS
	string "Contains the Objects and Object Instances exposed by Gateway"
	default ""
	help
	  It uses the same CoreLnk format as Registration Interface.
	  This must be populated by Gateway.
	  Example:
	    </3>;ver=1.0,</3/0>,</4>;ver=1.0,</4/0>,
	    </5>;ver=1.0,</5/0>,</9>;ver=1.0,</9/0>,</3303/0>

config LWM2M_GATEWAY_IOT_DEVICE_OBJECTS_MAX_STR_SIZE
	int "Maximum string size for IoT device objects"
	default 128

endif # LWM2M_GATEWAY_OBJ_SUPPORT

menu "IPSO Alliance Smart Object Support"

source "subsys/net/lib/lwm2m/Kconfig.ipso"

endmenu

menu "uCIFI Alliance Object Support"

source "subsys/net/lib/lwm2m/Kconfig.ucifi"

endmenu

endif # LWM2M
