# Copyright (c) 2021 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0
#
# This file contains selected Kconfig options for the application.

CONFIG_APP_EVENT_MANAGER=y
CONFIG_REBOOT=y

CONFIG_POSIX_MQUEUE=y
CONFIG_POLL=y

#GPIO
CONFIG_GPIO=y

#RTC
CONFIG_COUNTER=y
CONFIG_RTC=y

# compiler
CONFIG_DEBUG_OPTIMIZATIONS=y
CONFIG_SIZE_OPTIMIZATIONS=y

# console
CONFIG_CONSOLE=y

# UART console
CONFIG_SERIAL=y

# Auto-reset when a fatal error (coredump) occurs
CONFIG_RESET_ON_FATAL_ERROR=y 

#PSA
CONFIG_PSA_WANT_ALG_HMAC=y

#Wifi
CONFIG_WIFI=y
CONFIG_WIFI_NRF700X=y

# WPA supplicant
CONFIG_WPA_SUPP=y

# System settings
CONFIG_NEWLIB_LIBC=y
CONFIG_NEWLIB_LIBC_NANO=n

# Networking
CONFIG_NETWORKING=y
CONFIG_NET_SOCKETS=y
CONFIG_NET_IPV6=y
CONFIG_NET_IPV4=y
CONFIG_NET_UDP=y
CONFIG_NET_TCP=y

#DNS resolver
CONFIG_DNS_RESOLVER=y

# CONFIG_NET_STATISTICS=y

CONFIG_NET_PKT_RX_COUNT=8
CONFIG_NET_PKT_TX_COUNT=8

# Below section is the primary contributor to SRAM and is currently
# tuned for performance, but this will be revisited in the future.
CONFIG_NET_BUF_RX_COUNT=16
CONFIG_NET_BUF_TX_COUNT=16
CONFIG_NET_BUF_DATA_SIZE=128
CONFIG_HEAP_MEM_POOL_SIZE=120832
CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=21144
CONFIG_NET_TC_TX_COUNT=1

CONFIG_NET_IF_UNICAST_IPV4_ADDR_COUNT=1
CONFIG_NET_MAX_CONTEXTS=5
CONFIG_NET_CONTEXT_SYNC_RECV=y

CONFIG_INIT_STACKS=y

CONFIG_NET_L2_ETHERNET=y

CONFIG_NET_CONFIG_SETTINGS=y
CONFIG_NET_CONFIG_INIT_TIMEOUT=0

CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.165.100.150"
#CONFIG_NET_CONFIG_PEER_IPV4_ADDR="192.165.100.1"

CONFIG_NET_SOCKETS_POLL_MAX=10
CONFIG_NET_MAX_CONN=6  
CONFIG_NET_CONNECTION_MANAGER=y

# DHCPv4
CONFIG_NET_DHCPV4=y
# CONFIG_NET_CONFIG_AUTO_INIT=n
# CONFIG_NET_CONFIG_NEED_IPV6=n
# CONFIG_NET_CONFIG_NEED_IPV4=n

# CONFIG_NET_CONFIG_LOG_LEVEL_DBG=y
# CONFIG_WIFI_LOG_LEVEL_DBG=y
# Zephyr NET Connection Manager Connectivity layer.
CONFIG_L2_WIFI_CONNECTIVITY=y
CONFIG_L2_WIFI_CONNECTIVITY_AUTO_DOWN=n
CONFIG_L2_WIFI_CONNECTIVITY_AUTO_CONNECT=n
# CONFIG_L2_WIFI_CONNECTIVITY_CONNECTION_PERSISTENCE=n 

# Memories
CONFIG_MAIN_STACK_SIZE=8192
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=6000
CONFIG_NET_TX_STACK_SIZE=4096
CONFIG_NET_RX_STACK_SIZE=4096

# Debugging
CONFIG_STACK_SENTINEL=y
CONFIG_DEBUG=y
CONFIG_DEBUG_COREDUMP=y
CONFIG_DEBUG_COREDUMP_BACKEND_LOGGING=y
CONFIG_DEBUG_COREDUMP_MEMORY_DUMP_MIN=y

# Kernel options
CONFIG_ENTROPY_GENERATOR=y

CONFIG_NET_L2_WIFI_MGMT=y

#BT
CONFIG_BT=y
CONFIG_BT_SMP=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_GATT_CLIENT=y

CONFIG_BT_BUF_ACL_RX_SIZE=151
CONFIG_BT_L2CAP_TX_MTU=147
CONFIG_BT_BUF_ACL_TX_SIZE=151

CONFIG_BT_RX_STACK_SIZE=6000
CONFIG_BT_BONDABLE=n
CONFIG_BT_DEVICE_NAME_DYNAMIC=y

# Raw scan Options
CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS=n
CONFIG_WIFI_NRF700X_SCAN_TIMEOUT_S=5

#FLASH
CONFIG_FLASH=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_FLASH_MAP=y

CONFIG_NVS=y

CONFIG_SETTINGS=y
CONFIG_SETTINGS_NVS=y

#Wifi_credentials
CONFIG_WIFI_CREDENTIALS=y
CONFIG_WIFI_CREDENTIALS_MAX_ENTRIES=2

CONFIG_NANOPB=y

CONFIG_WIFI_MGMT_EXT=y
# Setting BT supervision timeout to 75units (750ms) to avoid timeout of BT connection when radio is granted to Wi-Fi during scan.
CONFIG_BT_PERIPHERAL_PREF_TIMEOUT=75

# Similar to shell sample, add this option to ensure the event can get served.
CONFIG_NET_MGMT_EVENT_QUEUE_TIMEOUT=5000

CONFIG_I2C=y

CONFIG_ADC=y

# CONFIG_DNS_RESOLVER_LOG_LEVEL_DBG=y
# CONFIG_NET_SOCKETS_LOG_LEVEL_DBG=y

#PM
CONFIG_PM_DEVICE=y
CONFIG_CRC=y
CONFIG_POWEROFF=y

#sntp
CONFIG_SNTP=y
CONFIG_NET_CONFIG_PEER_IPV4_ADDR="192.0.2.2"
CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::1"
# Address of SNTP IPv6 server
CONFIG_NET_CONFIG_PEER_IPV6_ADDR="2001:db8::2"

#DFU
CONFIG_DOWNLOAD_CLIENT=y
CONFIG_DOWNLOAD_CLIENT_STACK_SIZE=4096
CONFIG_FW_INFO=y

# FOTA library
CONFIG_FOTA_DOWNLOAD=y
CONFIG_FOTA_SOCKET_RETRIES=4

# Application Upgrade support
CONFIG_BOOTLOADER_MCUBOOT=y

# DFU Target
CONFIG_DFU_TARGET=y

# HTTP
CONFIG_HTTP_PARSER=y
CONFIG_HTTP_PARSER_URL=y

# Image manager
CONFIG_IMG_MANAGER=y
# CONFIG_FLASH=y
# CONFIG_FLASH_MAP=y
CONFIG_STREAM_FLASH=y
CONFIG_IMG_ERASE_PROGRESSIVELY=y

# Non-volatile Storage
# CONFIG_NVS=y
CONFIG_MPU_ALLOW_FLASH_WRITE=y
#needed
# CONFIG_NET_SOCKETS_OFFLOAD=n 

# Default partition for NVS is unused
# CONFIG_PM_PARTITION_SIZE_NVS_STORAGE=0x0

# logging
CONFIG_LOG=y
CONFIG_APP_LOG_LEVEL_DBG=y
CONFIG_NET_LOG=y
# CONFIG_APP_LOG_LEVEL_OFF=y
# CONFIG_APP_LOG_LEVEL=0
# CONFIG_LOG_MODE_DEFERRED=n

#  Increased log buffer size from 2048 to 4096 to prevent log overflow and reduce dropped messages 
CONFIG_LOG_BUFFER_SIZE=1024

CONFIG_LOG_PRINTK=n
CONFIG_PRINTK=n

# Set log processing thread priority to 2 for faster log handling 
CONFIG_LOG_PROCESS_THREAD_PRIORITY=2

# Reduce log processing thread sleep time to 10ms for improved responsiveness 
CONFIG_LOG_PROCESS_THREAD_SLEEP_MS=10


# CONFIG_DFU_TARGET_LOG_LEVEL_DBG=y
# CONFIG_DOWNLOAD_CLIENT_LOG_LEVEL_DBG=y
# CONFIG_FOTA_DOWNLOAD_LOG_LEVEL_DBG=y
# # CONFIG_WIFI_MGMT_EXT_LOG_LEVEL_DBG=y
# CONFIG_NET_HTTP_LOG_LEVEL_DBG=y

#needed
CONFIG_NET_SOCKETS_OFFLOAD=n
CONFIG_NET_DHCPV4_INITIAL_DELAY_MAX=2
CONFIG_NET_DHCPV4_OPTION_CALLBACKS=y

# FOTA
CONFIG_NET_MAX_CONN=6
# CONFIG_BUILD_WITH_TFM=n

CONFIG_PWM=n

# CONFIG_WIFI_LOG_LEVEL_DBG=y
# CONFIG_WIFI_NRF700X_LOG_LEVEL_DBG=y
    
# Disable Bluetooth features not needed
CONFIG_BT_DEBUG_NONE=y
CONFIG_BT_ASSERT=n
CONFIG_BT_DATA_LEN_UPDATE=n
CONFIG_BT_PHY_UPDATE=n
CONFIG_BT_GATT_CACHING=n
CONFIG_BT_GATT_SERVICE_CHANGED=n
CONFIG_BT_GAP_PERIPHERAL_PREF_PARAMS=n
CONFIG_BT_SETTINGS_CCC_LAZY_LOADING=y
CONFIG_BT_HCI_VS_EXT=n
# Disable Bluetooth controller features not needed
CONFIG_BT_CTLR_PRIVACY=n
CONFIG_BT_CTLR_PHY_2M=n

CONFIG_NET_MGMT_EVENT_QUEUE_SIZE=8
CONFIG_NET_MGMT_EVENT_STACK_SIZE=5120

CONFIG_SHELL=n
CONFIG_NET_IPV6=n
