#
# Copyright (c) 2021 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

menuconfig LOCATION
	bool "Location"

if LOCATION

config LOCATION_METHOD_GNSS
	bool "Allow GNSS to be used for obtaining the location"
	depends on NRF_MODEM_LIB
	depends on LTE_LINK_CONTROL
	default y

config LOCATION_METHOD_CELLULAR
	bool "Allow cellular positioning to be used for obtaining the location"
	depends on NRF_MODEM_LIB
	depends on LTE_LINK_CONTROL
	default y

config LOCATION_METHOD_WIFI
	bool "Allow Wi-Fi positioning to be used for obtaining the location"
	depends on WIFI
	select NET_MGMT if LOCATION_METHOD_WIFI_NET_MGMT
	select NET_MGMT_EVENT if LOCATION_METHOD_WIFI_NET_MGMT
	select NET_MGMT_EVENT_INFO if LOCATION_METHOD_WIFI_NET_MGMT
	select NET_L2_WIFI_MGMT if LOCATION_METHOD_WIFI_NET_MGMT

config LOCATION_METHOD_WIFI_NET_MGMT
	bool
	default y
	help
	  Use the Network Management APIs for Wi-Fi functionality. This is
	  separated here from other dependencies to allow disabling of
	  Network Management APIs in tests for mocking purposes.

config LOCATION_METHOD_WIFI_NET_IF_UPDOWN
	bool
	default y if (BOARD_THINGY91X_NRF9151 || BOARD_THINGY91X_NRF9151_NS || BOARD_THINGY91X_NRF5340_CPUAPP || BOARD_THINGY91X_NRF5340_CPUAPP_NS)
	depends on LOCATION_METHOD_WIFI_NET_MGMT
	help
	  Use the Network Interface Up/Down APIs for Wi-Fi functionality.


config LOCATION_METHODS_LIST_SIZE
	int "Maximum number of location methods in configuration"
	default 3
	help
	  Maximum number of location methods within location_config structure.

config LOCATION_DATA_DETAILS
	bool "Gather and include detailed data into the location_event_data"

config LOCATION_WORKQUEUE_STACK_SIZE
	int "Stack size for the library work queue"
	default 4096

if LOCATION_METHOD_GNSS

config LOCATION_METHOD_GNSS_VISIBILITY_DETECTION_EXEC_TIME
	int "GNSS execution time for obstructed visibility detection"
	default 3000
	help
	  Sets the time (in milliseconds) since GNSS start after which the obstructed visibility
	  detection is performed. The default value is a good starting point when A-GNSS is used.
	  Without assistance, the value should probably be adjusted, because GNSS acquires
	  satellites more slowly.

config LOCATION_METHOD_GNSS_VISIBILITY_DETECTION_SAT_LIMIT
	int "GNSS obstructed visibility detection satellite limit"
	default 3
	help
	  Sets the minimum number of satellites which must have been acquired by GNSS when the
	  obstructed visibility detection is performed. If less satellites have been acquired,
	  GNSS is stopped immediately to save energy. The default value is a good starting point
	  when A-GNSS is used. Without assistance, the value should probably be adjusted, because
	  GNSS acquires satellites more slowly.

config LOCATION_METHOD_GNSS_PRIORITIZE_QZSS_ASSISTANCE
	bool "Allow A-GNSS data request when only QZSS assistance is needed"
	help
	  By default, QZSS assistance data is only requested when some other assistance data is
	  needed at the same time. Enabling this option allows A-GNSS data request to be sent also
	  when only QZSS assistance data (usually ephemerides) is needed.

config LOCATION_SERVICE_NRF_CLOUD_GNSS_POS_SEND
	bool "Send GNSS coordinates to nRF Cloud"
	depends on !LOCATION_SERVICE_EXTERNAL
	depends on NRF_CLOUD_REST || NRF_CLOUD_MQTT || NRF_CLOUD_COAP
	help
	  Send GNSS coordinates to nRF Cloud.

endif # LOCATION_METHOD_GNSS

if LOCATION_METHOD_WIFI

config LOCATION_METHOD_WIFI_SCANNING_RESULTS_MAX_CNT
	int "Max number of Wi-Fi scanning results"
	default 10
	help
	  Maximum number of Wi-Fi scanning results to use when creating HTTP request.
	  Increasing the max number will increase the library's RAM usage.

endif # LOCATION_METHOD_WIFI

# Cellular and Wi-Fi service configurations

if LOCATION_METHOD_CELLULAR || LOCATION_METHOD_WIFI

config LOCATION_SERVICE_CLOUD_RECV_BUF_SIZE
	int "Receive buffer size"
	default 1024 if LOCATION_SERVICE_HERE
	default 512
	help
	  Size of the buffer used to store the response from the location service.

config LOCATION_SERVICE_HERE
	bool "HERE location service"
	select CJSON_LIB
	help
	  Use HERE location service.

config LOCATION_SERVICE_NRF_CLOUD
	bool "nRF Cloud location service"
	default y if !LOCATION_SERVICE_EXTERNAL
	depends on NRF_CLOUD_REST || NRF_CLOUD_MQTT || NRF_CLOUD_COAP
	select NRF_CLOUD_LOCATION if NRF_CLOUD_MQTT
	select NRF_CLOUD_REST_AUTOGEN_JWT if NRF_CLOUD_REST
	help
	  Use nRF Cloud location service.

if LOCATION_SERVICE_HERE

config LOCATION_REST_CLIENT
	bool
	default y
	select REST_CLIENT
	help
	  Use the REST client library for cellular service. This is
	  separated here from other dependencies to allow disabling of
	  REST client library in tests for mocking purposes.

config LOCATION_MODEM_KEY_MGMT
	bool
	default y
	select MODEM_KEY_MGMT
	help
	  Use the Modem key management library for cellular service. This is
	  separated here from other dependencies to allow disabling of
	  Modem key management library in tests for mocking purposes.

config LOCATION_SERVICE_HERE_API_KEY
	string "HERE API key"
	help
	  HERE API key used for authentication.

config LOCATION_SERVICE_HERE_HOSTNAME
	string "Server hostname for HERE"
	default "positioning.hereapi.com"
	help
	  Server hostname to use when connecting to the HERE location service.

config LOCATION_SERVICE_HERE_TLS_SEC_TAG
	int "Security tag for HERE TLS certificates"
	default 175
	help
	  Security tag where the required TLS certificates for the HERE location
	  service are stored. This sec tag will also be used to provision CA
	  certificates.

endif # LOCATION_SERVICE_HERE

endif # LOCATION_METHOD_CELLULAR || LOCATION_METHOD_WIFI

config LOCATION_SERVICE_EXTERNAL
	bool "Requesting A-GNSS, P-GPS, LTE neighbor cell and Wi-Fi access point data is handled by the application outside of Location library"
	help
	  Allow application to download the A-GNSS and P-GPS data and merely feed it to
	  Location library for processing.
	  Also, allow application to send cellular neighbor cell and Wi-Fi access point information
	  to a cloud service and respond to the Location library with the outcome.

# Configurations for location_request() default values

choice LOCATION_REQUEST_DEFAULT_METHOD_FIRST
	prompt "Default first priority method"
	default LOCATION_REQUEST_DEFAULT_METHOD_FIRST_GNSS if LOCATION_METHOD_GNSS
	default LOCATION_REQUEST_DEFAULT_METHOD_FIRST_WIFI if LOCATION_METHOD_WIFI
	default LOCATION_REQUEST_DEFAULT_METHOD_FIRST_CELLULAR if LOCATION_METHOD_CELLULAR
	help
	  Default first priority method used in location_config_defaults_set() function
	  within location_config structure if method_types member is NULL.

	config LOCATION_REQUEST_DEFAULT_METHOD_FIRST_GNSS
		bool "GNSS positioning"
	config LOCATION_REQUEST_DEFAULT_METHOD_FIRST_WIFI
		bool "Wi-Fi positioning"
	config LOCATION_REQUEST_DEFAULT_METHOD_FIRST_CELLULAR
		bool "Cellular positioning"

endchoice

choice LOCATION_REQUEST_DEFAULT_METHOD_SECOND
	prompt "Default second priority method"
	default LOCATION_REQUEST_DEFAULT_METHOD_SECOND_WIFI if LOCATION_METHOD_WIFI && !LOCATION_REQUEST_DEFAULT_METHOD_FIRST_WIFI
	default LOCATION_REQUEST_DEFAULT_METHOD_SECOND_CELLULAR if LOCATION_METHOD_CELLULAR && !LOCATION_REQUEST_DEFAULT_METHOD_FIRST_CELLULAR
	default LOCATION_REQUEST_DEFAULT_METHOD_SECOND_NONE
	help
	  Default second priority method used in location_config_defaults_set() function
	  within location_config structure if method_types member is NULL.

	config LOCATION_REQUEST_DEFAULT_METHOD_SECOND_GNSS
		bool "GNSS positioning"
	config LOCATION_REQUEST_DEFAULT_METHOD_SECOND_WIFI
		bool "Wi-Fi positioning"
	config LOCATION_REQUEST_DEFAULT_METHOD_SECOND_CELLULAR
		bool "Cellular positioning"
	config LOCATION_REQUEST_DEFAULT_METHOD_SECOND_NONE
		bool "No second priority method"

endchoice

choice LOCATION_REQUEST_DEFAULT_METHOD_THIRD
	prompt "Default third priority method"
	default LOCATION_REQUEST_DEFAULT_METHOD_THIRD_CELLULAR if LOCATION_METHOD_CELLULAR && !LOCATION_REQUEST_DEFAULT_METHOD_FIRST_CELLULAR && !LOCATION_REQUEST_DEFAULT_METHOD_SECOND_CELLULAR
	default LOCATION_REQUEST_DEFAULT_METHOD_THIRD_NONE
	help
	  Default third priority method used in location_config_defaults_set() function
	  within location_config structure if method_types member is NULL.

	config LOCATION_REQUEST_DEFAULT_METHOD_THIRD_GNSS
		bool "GNSS positioning"
	config LOCATION_REQUEST_DEFAULT_METHOD_THIRD_WIFI
		bool "Wi-Fi positioning"
	config LOCATION_REQUEST_DEFAULT_METHOD_THIRD_CELLULAR
		bool "Cellular positioning"
	config LOCATION_REQUEST_DEFAULT_METHOD_THIRD_NONE
		bool "No third priority method"
endchoice

config LOCATION_REQUEST_DEFAULT_INTERVAL
	int "Default interval in seconds"
	default 0
	help
	  Default value used in location_config_defaults_set() function for interval
	  member within location_config structure.

config LOCATION_REQUEST_DEFAULT_TIMEOUT
	int "Default timeout in milliseconds"
	default 300000
	help
	  Default value used in location_config_defaults_set() function for timeout
	  member within location_config structure.

if LOCATION_METHOD_GNSS

config LOCATION_REQUEST_DEFAULT_GNSS_TIMEOUT
	int "Default GNSS timeout in milliseconds"
	default 120000
	help
	  Default value used in location_config_defaults_set() function for timeout
	  member within location_gnss_config structure.

choice LOCATION_REQUEST_DEFAULT_GNSS_ACCURACY
	prompt "Default GNSS accuracy level"
	default LOCATION_REQUEST_DEFAULT_GNSS_ACCURACY_NORMAL
	help
	  Default value used in location_config_defaults_set() function for accuracy
	  member within location_gnss_config structure.

	config LOCATION_REQUEST_DEFAULT_GNSS_ACCURACY_LOW
		bool "GNSS low accuracy"
	config LOCATION_REQUEST_DEFAULT_GNSS_ACCURACY_NORMAL
		bool "GNSS normal accuracy"
	config LOCATION_REQUEST_DEFAULT_GNSS_ACCURACY_HIGH
		bool "GNSS high accuracy"

endchoice

config LOCATION_REQUEST_DEFAULT_GNSS_NUM_CONSECUTIVE_FIXES
	int "Default number of consecutive fixes in high accuracy mode"
	default 3
	range 2 256
	help
	  Default value used in location_config_defaults_set() function for num_consecutive_fixes
	  member within location_gnss_config structure.

config LOCATION_REQUEST_DEFAULT_GNSS_VISIBILITY_DETECTION
	bool "Default GNSS visibility detection"
	help
	  Default value used in location_config_defaults_set() function for visibility_detection
	  member within location_gnss_config structure.

config LOCATION_REQUEST_DEFAULT_GNSS_PRIORITY_MODE
	bool "Default GNSS priority mode"
	help
	  Default value used in location_config_defaults_set() function for priority_mode
	  member within location_gnss_config structure.

endif # LOCATION_METHOD_GNSS

if LOCATION_METHOD_CELLULAR

config LOCATION_REQUEST_DEFAULT_CELLULAR_TIMEOUT
	int "Default cellular timeout in milliseconds"
	default 30000
	help
	  Default value used in location_config_defaults_set() function for timeout
	  member within location_cellular_config structure.

config LOCATION_REQUEST_DEFAULT_CELLULAR_CELL_COUNT
	int "Number of requested cellular neighbors"
	default 4
	range 0 15
	help
	  Default value used in location_config_defaults_set() function for cell_count
	  member within location_cellular_config structure.

endif # LOCATION_METHOD_CELLULAR

if LOCATION_METHOD_WIFI

config LOCATION_REQUEST_DEFAULT_WIFI_TIMEOUT
	int "Default Wi-Fi timeout in milliseconds"
	default 30000
	help
	  Default value used in location_config_defaults_set() function for timeout
	  member within location_wifi_config structure.

endif # LOCATION_METHOD_WIFI

module = LOCATION
module-str = Location
source "${ZEPHYR_BASE}/subsys/logging/Kconfig.template.log_config"

endif # LOCATION
