# Configure Bluetooth Low Energy (BLE).
CONFIG_BT=y
CONFIG_BT_PERIPHERAL=y

# Note: The value for CONFIG_BT_MAX_CONN should be the same
# in both app and net core conf files.
CONFIG_BT_MAX_CONN=1

# Set values for the GATT GAP Service characteristics.
# Peripheral Preferred Connection Parameters (PPCP) characteristic:
# The PPCP characteristic values are optionally read and used by the central.
# We will also use these values in our L2CAP_CONNECTION_PARAMETER_UPDATE_REQ for audio.
# - PPCP connection interval: 12 units of 1.25 ms =15.0 ms, needed for audio transfer.
CONFIG_BT_PERIPHERAL_PREF_MIN_INT=12
CONFIG_BT_PERIPHERAL_PREF_MAX_INT=12
# - PPCP latency: 0. Peripheral listens at every connection event anchor point.
CONFIG_BT_PERIPHERAL_PREF_LATENCY=0
# - PPCP supervision timeout: 400 units of 10 ms: 4 sec of no data to declare connection lost.
CONFIG_BT_PERIPHERAL_PREF_TIMEOUT=400
# Device Name characteristic:
CONFIG_BT_DEVICE_NAME="MV-LAV"
CONFIG_BT_DEVICE_NAME_DYNAMIC=y
CONFIG_BT_DEVICE_NAME_GATT_WRITABLE=n

# Allow an early user-initiated connection parameter update request:
# We want to send our connection parameter request (L2CAP_CONNECTION_PARAMETER_UPDATE_REQ)
# before we perform clock sync for A/V sync, which is before the default 5 sec wait time to make
# such a request as recommended in the BT spec.  We set the wait time (timeout) to 0 to allow us
# to make the request as soon as we are ready to do clock sync. Setting this timeout to 0
# also causes a BLE stack 'auto-request' to occur right away in addition to our 'user request'.
# We don't need both auto and user requests, so also disable auto request since timeout is 0.
# Note auto requests use the PREF configs like CONFIG_BT_PERIPHERAL_PREF_MIN_INT.
CONFIG_BT_CONN_PARAM_UPDATE_TIMEOUT=0
CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS=n

# Allow for app-requested setting changes.
CONFIG_BT_USER_DATA_LEN_UPDATE=y
CONFIG_BT_USER_PHY_UPDATE=y

# The above "BT_USER" options cause the below "BT_AUTO" options to default to 'no'.
# Set them 'yes'.
CONFIG_BT_AUTO_DATA_LEN_UPDATE=y
CONFIG_BT_AUTO_PHY_UPDATE=y

# Note: The TX MTU below was originally 247.
# Note: The MTU value negotiated by this device will be the min of the RX and TX MTU.
# Note: BT_L2CAP_RX_MTU must be >= (CONFIG_BT_CTLR_DATA_LENGTH_MAX-4), where 4=l2cap hdr.
# Note: Zephyr 2.6.0 name change: CONFIG_BT_L2CAP_RX_MTU + 4 -> CONFIG_BT_BUF_ACL_RX_SIZE
CONFIG_BT_L2CAP_TX_MTU=500
CONFIG_BT_BUF_ACL_RX_SIZE=504
CONFIG_BT_BUF_ACL_TX_SIZE=251

# Increase the number of buffers for outgoing L2CAP and connection packets to deal
# with backlogs due to retransmits.  We need these numbers to be larger than
# DEFAULT_MAX_ALLOWED_AUDIO_TX_PKT_BACKLOG.
CONFIG_BT_L2CAP_TX_BUF_COUNT=12
CONFIG_BT_CONN_TX_MAX=12

# We don't need GATT client support. We only need the default GATT server support.
CONFIG_BT_GATT_CLIENT=n

# We don't use the GATT subprocedure Read Multiple Characteristic Values.
CONFIG_BT_GATT_READ_MULTIPLE=n
CONFIG_BT_GATT_READ_MULT_VAR_LEN=n

# In case we add a new characteristic, we need the GATT Service Changed characteristic
# to alert an already bonded client (or even unbonded, for iOS devices) of the change.
# We don't need the other features below, so set them to no to save code space.
CONFIG_BT_GATT_SERVICE_CHANGED=y
CONFIG_BT_GATT_CACHING=n
CONFIG_BT_GATT_ENFORCE_CHANGE_UNAWARE=n

# The PREPARE_COUNT > 0 allows GATT long writes to be received. A long write
# (write with response, data length > MTU-3) can occur for the Shure Control and Status
# Service when the MTU is at the initial connection default length 23. For long writes,
# the BLE stack assembles the "prepare" writes, then delivers the assembled write
# to the app with the write flag BT_GATT_WRITE_FLAG_EXECUTE. This config can be removed
# or set to 0 once Control/Status fragmentation is supported.
CONFIG_BT_ATT_PREPARE_COUNT=0

# Enable Security Manager Protocol (SMP) for pairing and transport-specific key distribution.
CONFIG_BT_SMP=y
CONFIG_BT_SMP_MIN_ENC_KEY_SIZE=16
CONFIG_BT_KEYS_OVERWRITE_OLDEST=y
# Our app will be in charge of accepting an incoming pairing request. Our app will
# accept the request only if pairing mode is enabled.
CONFIG_BT_SMP_APP_PAIRING_ACCEPT=y
# MITM: Man-in-The-Middle requires local IO for key authentication. We don't have IO, so set no.
CONFIG_BT_SMP_ENFORCE_MITM=n
# SC_ONLY: Secure Connections (SC) Only implies use of security level 4, which requires
# authenticated pairing, which requires local IO for user prompt or display. Since we
# have no local IO (MITM=n), we can achieve only level 2, so SC_ONLY is not possible.
CONFIG_BT_SMP_SC_ONLY=n
CONFIG_BT_SMP_SC_PAIR_ONLY=n
# DISABLE_LEGACY_JW:  We don't want legacy Just Works. We want SC Just Works.  Set yes.
CONFIG_BT_SMP_DISABLE_LEGACY_JW_PASSKEY=y
# UNAUTH_OVERWIRTE:  Set no to prevent attacker from spoofing a bonded peer address.
CONFIG_BT_SMP_ALLOW_UNAUTH_OVERWRITE=n
# Let our code decide when to make a security request.
CONFIG_BT_GATT_AUTO_SEC_REQ=n

# Enable bonding and storing of bond keys in non-volatile storage (NVS).
# With NVS enabled, all CONFIG_BT_SETTINGS get stored in NVS, not just bond keys.
# Other stored items include CONFIG_BT_DEVICE_NAME and the active GATT subscriptions
# of each bonded device. Per BT Core Spec: "The Client Characteristic Configuration
# descriptor value shall be persistent across connections for bonded devices."
CONFIG_BT_BONDABLE=y
CONFIG_BT_BONDING_REQUIRED=y
CONFIG_BT_MAX_PAIRED=3

# Enable HCI vendor specific (VS) event handling for the BLE QoS events for BLE stats.
CONFIG_BT_HCI_VS_EVT_USER=y

# The following config options are needed to change the BT address at run-time.
# The CONFIG_BT_SETTINGS is also needed to store/restore keys and GATT CCC subscriptions.
CONFIG_BT_HCI_VS=y
CONFIG_BT_HCI_VS_EXT=y
CONFIG_BT_SETTINGS=y

# GATT CCC-related BT_SETTINGS to reduce RAM use and to minimize flash writes.
CONFIG_BT_SETTINGS_CCC_LAZY_LOADING=y
CONFIG_BT_SETTINGS_CCC_STORE_ON_WRITE=n

# Increase stack size
CONFIG_BT_RX_STACK_SIZE=4096

# DSP
CONFIG_CMSIS_DSP=y
CONFIG_CMSIS_DSP_AUTOVECTORIZE=y
CONFIG_CMSIS_DSP_BASICMATH=y
CONFIG_CMSIS_DSP_FASTMATH=y
CONFIG_CMSIS_DSP_FILTERING=y
CONFIG_CMSIS_DSP_LOOPUNROLL=y
CONFIG_CMSIS_DSP_TABLES=y
CONFIG_CMSIS_DSP_TABLES_ALL_FAST=y

# Device Information Service (DIS).
# The "Accessory Design Guidelines for Apple Devices" says these DIS characteristics
# should be supported: Manufacturer, Model Number, FW Revision, and SW revision.
# Zephyr DIS has Manufacturer and Model Number by default with CONFIG_BT_DIS.
CONFIG_BT_DIS=y
CONFIG_BT_DIS_FW_REV=y
CONFIG_BT_DIS_SW_REV=y
CONFIG_BT_DIS_SETTINGS=y
CONFIG_SETTINGS_RUNTIME=y
# Largest DIS string size would be for MAX_PRODUCT_SERIAL_NUM_LEN=16.
CONFIG_BT_DIS_STR_MAX=16
# These DIS characteristic are not needed for Apple. Note PNP=Plug and Play.
CONFIG_BT_DIS_PNP=n
CONFIG_BT_DIS_SERIAL_NUMBER=n
CONFIG_BT_DIS_HW_REV=n


######## DEBUG CONFIGURATIONS ########
# Used for debugging purposes,
# not to be included in a release.
# Keep this section at the bottom of this file to
# separate debug configs from non debug configs above.
######################################

# Use this to disable GATT encryption or authentication permissions.
#CONFIG_BT_CONN_DISABLE_SECURITY=y

#CONFIG_BT_DEBUG_LOG=y
#CONFIG_BT_DEBUG_L2CAP=y
#CONFIG_BT_DEBUG_ATT=y
#CONFIG_BT_DEBUG_GATT=y
#CONFIG_BT_DEBUG_CONN=y
#CONFIG_BT_DEBUG_HCI_DRIVER=y
#CONFIG_BT_DEBUG_HCI_CORE=y
#CONFIG_BT_DEBUG_SMP=y
#CONFIG_BT_DEBUG_KEYS=y

# Use this to print the Long Term Key (LTK) when bonding occurs.
#CONFIG_BT_LOG_SNIFFER_INFO=y