From 51670a759cc40ec0755173966b7fabe1b0d5871c Mon Sep 17 00:00:00 2001
From: silabs-VincentK <136042710+silabs-VincentK@users.noreply.github.com>
Date: Wed, 23 Sep 2026 13:43:39 +0800
Subject: [PATCH 1/2] Initial implementation of the Filter Accept List example
A CLI-based application showing the use of the Filter Accept List API in different scenarios.
---
README.md | 1 +
filter_accept_list/README.md | 185 +++++
.../soc_filter_accept_list.slcp | 644 ++++++++++++++++++
filter_accept_list/inc/app.h | 79 +++
filter_accept_list/inc/cli_functions.h | 28 +
filter_accept_list/src/app.c | 550 +++++++++++++++
filter_accept_list/src/sl_cli_command_table.c | 213 ++++++
7 files changed, 1700 insertions(+)
create mode 100644 filter_accept_list/README.md
create mode 100644 filter_accept_list/SimplicityStudio/soc_filter_accept_list.slcp
create mode 100644 filter_accept_list/inc/app.h
create mode 100644 filter_accept_list/inc/cli_functions.h
create mode 100644 filter_accept_list/src/app.c
create mode 100644 filter_accept_list/src/sl_cli_command_table.c
diff --git a/README.md b/README.md
index e9f2abe..30a172a 100644
--- a/README.md
+++ b/README.md
@@ -22,6 +22,7 @@ This repo contains example projects which demonstrate the features of the Silico
- Connections
- GATT Protocol
- Security
+- Filter Accept List
- Persistent Storage
- Firmware Upgrade
- OTA for NCP Hosts
diff --git a/filter_accept_list/README.md b/filter_accept_list/README.md
new file mode 100644
index 0000000..bb78321
--- /dev/null
+++ b/filter_accept_list/README.md
@@ -0,0 +1,185 @@
+# Bluetooth - SoC Filter Accept List #
+
+## Overview ##
+
+The Filter Accept List is a feature that filters out devices not in the accept list during scanning or connection establishment. This example demonstrates the use of Filter Accept List in various scenarios.
+
+Peripherals used: EUSART/vcom.
+
+## SDK version ##
+
+- SiSDK v2026.6.0
+
+## Hardware Required ##
+
+Any Bluetooth-capable EFR32 series 2 device.
+
+## Connections Required ##
+
+Connect the board via a micro-USB cable to your PC to flash the example and virtual serial port for the CLI.
+
+## Setup ##
+To test this application, you can either create a project based on an example project or start with an Bluetooth - SoC Empty example project.
+
+### Create a project based on an example project ###
+
+1. Make sure that this repository is added to [Preferences > Simplicity Studio > External Repos](https://docs.silabs.com/simplicity-studio-5-users-guide/latest/ss-5-users-guide-about-the-launcher/welcome-and-device-tabs).
+
+2. From the Launcher Home, add your board to My Products, click on it, and click on the **EXAMPLE PROJECTS & DEMOS** tab. Find the example project filtering by **'filter'**.
+
+3. Click on the **Create** button on the **Bluetooth - SoC Filter Accept List** example. Example project creation dialog pops up -> click **Finish** and the project should be generated.
+
+4. Build and flash this example to the board.
+
+### Start with a Bluetooth - SoC Empty application example project ###
+
+1. Create a new "Bluetooth - SoC Empty" project
+2. Add these software components:
+ a. Services -> Command Line Interface -> CLI Instance. Change EOL to \r\n in CLI Global Configuration (optional).
+ b. Bluetooth -> Bluetooth LE Controller (Link Layer) -> Features with Commands and Events -> Device filtering with Bluetooth controller's Filter Accept List.
+ c. Bluetooth -> Bluetooth LE Controller (Link Layer) -> Additional Features -> Address resolving with Bluetooth Ccntroller's Resolving List.
+ d. Bluetooth -> Bluetooth Host (Stack) -> Additional Features -> Select API semantics that use accurate Bluetooth address types
+ e. In Platform -> Board -> Board Control, Enable Enable Virtual COM UART.
+3. Delete sl_cli_command_table.c in the project's autogen folder. Copy the sl_cli_command_table.c included in this example to the same folder.
+4. Copy the included cli_functions.h file to the project folder.
+5. Copy the included app.c file to the project folder.
+6. Build and flash this project to your device.
+
+## How It Works ##
+
+See the API documentation for details.
+
+## Testing ##
+
+### Test environment requirement ###
+
+A pair of BLE-capable EFR32 devices.
+
+### Commands available in the CLI ###
+
+scan {1|0}
+
+Start scanning (1) or stop scanning (0). A list of up to 10 devices will be displayed, with indices 0-9 in a bracket. Scanning is stopped when the number of listed devices reaches 10, or if the 'scan 0' command is issued. Each time a 'scan 1' command is issue, the list will be cleared internally first. When scanning is stopped, the device is in the idle state.
+
+connect (n}
+
+Connect with the device with specified index in the scan result list. This command can be issued only in the idle state.
+
+disconnect
+
+Close the current connection. This command can be issued only in the connected state. After disconnection, the device is in the idle state.
+
+advertise {1|0}
+
+Start (1) or stop (0) advertising. If advertising is started, connection can be established from a scanner. The device is in the idle state if advertising is stopped.
+
+add_discovered {n}
+
+Add the device with index n in the scan result to the filter accept list. This can be done only when in the idle state.
+
+clear
+
+Clear the filter accept list.
+
+add_connected
+
+Add the current connected device to the filter accept list.
+
+pair
+
+Pair with the currently connected device.
+
+bondings
+
+List the currently paired devices. This command can only be issued in the idle state. An index is associated with each device and it can be used in the 'unpair' command.
+
+unpair {n}
+
+Unpair the device with index n in the in the bonding database. The device will also be removed from the resolve list. The filter entry of this deivice, if using RPA, should not be deemed valid after this.
+
+filter {1|0}
+
+Enable (1) or disable (0) the Filter Accept List. This can be done only in the idle state.
+
+### Test procedures ###
+
+I. Scanning filter
+
+1. 'scan 1'.
+2. 'scan 0' if not automatically stopped.
+3. 'add_discovered {n}'
+4. repeat the above until all devices are added.
+5. 'filter 1'
+5. 'scan 1'
+6. Only the added device will be visible.
+7. 'filter 0'
+8. Other devices should be visible after this.
+9. 'clear' to empty the filter accept list.
+
+II. Central connection filter
+
+1. 'scan 1'.
+2. 'scan 0' if not automatically stopped.
+3. 'add_discovered {n}'
+4. repeat the above until all devices are added.
+5. 'filter 1'
+6. 'connect {n}'
+7. This above command should work with devices added to the filter accept list
+8. 'disconnect' from either side.
+9. 'filter 0'
+10. Verify if other devices can be connected now.
+11. 'disconnect' if connected.
+12. 'clear' to empty the filter accept list.
+
+III. Peripheral connection filter with scanned device
+
+1. Add a device from a scan result to the filter accept list (I. 1~5)
+2. 'advertise 1'
+3. Wait for the central device to connect.
+4. Only the devices in the filter accept list can connect to this device.
+5. 'disconenct' if connected
+6. 'filter 0'
+7. 'advertise 1'
+8. Verify that other devices can also connect to this device.
+9. 'disconnect' if connected.
+10. 'clear' to empty the filter accept list.
+
+IV. Peripheral connection filter with formerly connected device
+
+1. 'advertise 1'
+2. Wait for the remote central device to connect.
+3. Once connected, 'add_peer' to add the connected device to the filter accept list
+4. 'disconnect' and repeat the above steps to add more devices.
+5. 'filter 1'
+6. 'advertise 1'
+7. Wait for the remote central device to connect: Only the device in the filter accept list can establish the connection.
+8. 'disconnect' if connected
+9. 'filter 0'
+10. Verify that other devices can also connect to this device.
+11. 'disconnect' if connected.
+12. 'clear' to empty the filter accept list.
+
+V. Testing RPA (Requiring a mobile phone with RPA, like an iPhone)
+
+1. 'advertise 1'
+2. Wait for the remote central device to connect.
+3. Wait for the connection to establish from a central device.
+4. If the peer device is using RPC (type = 4), 'pair'
+3. 'add_peer' to add the identity address of the connected device to the filter accept list
+4. 'disconnect' and add more devices if needed.
+5. 'filter 1'
+6. 'advertise 1'
+7. Wait for the remote central device to connect: Only the device in the filter accept list can establish the connection.
+8. 'disconnect' if connected
+9. (Optional) wait until the device with RPA changes it's RPA and go to step 6.
+10. 'filter 0'
+11. Verify that other devices can also connect to this device.
+12. 'disconnect' if connected.
+13. 'clear' to empty the filter accept list.
+
+## Limitations ##
+
+1. Pairing is done in the minimalist way, which does not perform authentication.
+2. If a connection is initiated towards an iPhone, it will be disconnected in a few seconds.
+3. Only one device should be connected any time for simplicity. This is not a hard limit of the stack and can be easily extended.
+4. Unpairing a device does not automatically removes it from the filter accept list.
diff --git a/filter_accept_list/SimplicityStudio/soc_filter_accept_list.slcp b/filter_accept_list/SimplicityStudio/soc_filter_accept_list.slcp
new file mode 100644
index 0000000..c8af7a1
--- /dev/null
+++ b/filter_accept_list/SimplicityStudio/soc_filter_accept_list.slcp
@@ -0,0 +1,644 @@
+# Silicon Labs Project Configuration Tools: slcp, v0, Component selection file.
+project_name: soc_filter_accept_list
+label: soc_filter_accept_list
+description: |
+ This example demonstrates the use of Filter Accept List in various scenarios.
+category: Bluetooth Examples
+filter:
+- name: Device Type
+ value:
+ - SoC
+- name: Project Difficulty
+ value:
+ - Beginner
+- name: Wireless Technology
+ value:
+ - Bluetooth
+package: bluetooth_le_app
+quality: production
+readme:
+- path: readme.md
+source:
+ - path: ../src/app.c
+ - path: ../src/sl_cli_command_table.c
+tag:
+- hwfilter:device:device_supports_bluetooth
+- hwfilter:device:device_series_2
+include:
+ - path: ../inc/
+ file_list:
+ - path: app.h
+ - path: cli_functions.h
+sdk:
+ vendor: silabs
+ id: simplicity_sdk
+ version: 2026.6.0
+toolchain_settings: [
+ ]
+component:
+- package: simplicity_sdk
+ vendor: silabs
+ id: app_assert
+- package: simplicity_sdk
+ vendor: silabs
+ id: app_os_helper
+- package: simplicity_sdk
+ vendor: silabs
+ id: bluetooth_feature_accept_list
+- package: simplicity_sdk
+ vendor: silabs
+ id: bluetooth_feature_connection_role_central
+- package: simplicity_sdk
+ vendor: silabs
+ id: bluetooth_feature_connection_role_peripheral
+- package: simplicity_sdk
+ vendor: silabs
+ id: bluetooth_feature_gatt
+- package: simplicity_sdk
+ vendor: silabs
+ id: bluetooth_feature_gatt_server
+- package: simplicity_sdk
+ vendor: silabs
+ id: bluetooth_feature_legacy_advertiser
+- package: simplicity_sdk
+ vendor: silabs
+ id: bluetooth_feature_legacy_scanner
+- package: simplicity_sdk
+ vendor: silabs
+ id: bluetooth_feature_resolving_list
+- package: simplicity_sdk
+ vendor: silabs
+ id: bluetooth_feature_sm
+- package: simplicity_sdk
+ vendor: silabs
+ id: bluetooth_feature_system
+- package: simplicity_sdk
+ vendor: silabs
+ id: bluetooth_feature_use_accurate_api_address_types
+- package: simplicity_sdk
+ vendor: silabs
+ id: bluetooth_stack
+- package: simplicity_sdk
+ vendor: silabs
+ id: brd4002a
+- package: simplicity_sdk
+ vendor: silabs
+ id: brd4183a
+- package: simplicity_sdk
+ instance:
+ - inst
+ vendor: silabs
+ id: cli
+- package: simplicity_sdk
+ vendor: silabs
+ id: clock_manager
+- package: simplicity_sdk
+ vendor: silabs
+ id: device_init
+- package: simplicity_sdk
+ vendor: silabs
+ id: gatt_configuration
+- package: simplicity_sdk
+ vendor: silabs
+ id: gatt_service_device_information_override
+- package: simplicity_sdk
+ vendor: silabs
+ id: mpu
+- package: simplicity_sdk
+ vendor: silabs
+ id: rail_util_pti
+- package: simplicity_sdk
+ vendor: silabs
+ id: sl_main
+autoselected_components:
+- package: simplicity_sdk
+ vendor: silabs
+ id: agents_md
+- package: simplicity_sdk
+ vendor: silabs
+ id: atomic
+- package: simplicity_sdk
+ vendor: silabs
+ id: bgapi_protocol
+- package: simplicity_sdk
+ vendor: silabs
+ id: bgapi_protocol_libraries_release
+- package: simplicity_sdk
+ vendor: silabs
+ id: bit
+- package: simplicity_sdk
+ vendor: silabs
+ id: bluetooth_common
+- package: simplicity_sdk
+ vendor: silabs
+ id: bluetooth_common_libraries_release
+- package: simplicity_sdk
+ vendor: silabs
+ id: bluetooth_configuration
+- package: simplicity_sdk
+ vendor: silabs
+ id: bluetooth_controller
+- package: simplicity_sdk
+ vendor: silabs
+ id: bluetooth_controller_crypto
+- package: simplicity_sdk
+ vendor: silabs
+ id: bluetooth_controller_libraries
+- package: simplicity_sdk
+ vendor: silabs
+ id: bluetooth_crypto
+- package: simplicity_sdk
+ vendor: silabs
+ id: bluetooth_crypto_lib_psa
+- package: simplicity_sdk
+ vendor: silabs
+ id: bluetooth_device_compatibility
+- package: simplicity_sdk
+ vendor: silabs
+ id: bluetooth_feature_advertiser
+- package: simplicity_sdk
+ vendor: silabs
+ id: bluetooth_feature_builtin_bonding_database
+- package: simplicity_sdk
+ vendor: silabs
+ id: bluetooth_feature_connection
+- package: simplicity_sdk
+ vendor: silabs
+ id: bluetooth_feature_gap
+- package: simplicity_sdk
+ vendor: silabs
+ id: bluetooth_feature_local_privacy
+- package: simplicity_sdk
+ vendor: silabs
+ id: bluetooth_feature_rpa_resolution
+- package: simplicity_sdk
+ vendor: silabs
+ id: bluetooth_feature_scanner
+- package: simplicity_sdk
+ vendor: silabs
+ id: bluetooth_gattdb_definition
+- package: simplicity_sdk
+ vendor: silabs
+ id: bluetooth_host_adaptation
+- package: simplicity_sdk
+ vendor: silabs
+ id: bluetooth_host_release_libraries
+- package: simplicity_sdk
+ vendor: silabs
+ id: bluetooth_version
+- package: simplicity_sdk
+ vendor: silabs
+ id: board_control
+- package: simplicity_sdk
+ vendor: silabs
+ id: brd4183a_config
+- package: simplicity_sdk
+ vendor: silabs
+ id: cli_core
+- package: simplicity_sdk
+ vendor: silabs
+ id: clock_manager_init_hal_s2
+- package: simplicity_sdk
+ vendor: silabs
+ id: clock_manager_runtime
+- package: simplicity_sdk
+ vendor: silabs
+ id: clock_manager_runtime_hal_s2
+- package: simplicity_sdk
+ vendor: silabs
+ id: cmsis_core
+- package: simplicity_sdk
+ vendor: silabs
+ id: code_classification
+- package: simplicity_sdk
+ vendor: silabs
+ id: component_catalog
+- package: simplicity_sdk
+ vendor: silabs
+ id: configuration_over_swo
+- package: simplicity_sdk
+ vendor: silabs
+ id: debug_swo
+- package: simplicity_sdk
+ vendor: silabs
+ id: device_clock
+- package: simplicity_sdk
+ vendor: silabs
+ id: device_clock_hal
+- package: simplicity_sdk
+ vendor: silabs
+ id: device_dma
+- package: simplicity_sdk
+ vendor: silabs
+ id: device_dma_hal
+- package: simplicity_sdk
+ vendor: silabs
+ id: device_gpio
+- package: simplicity_sdk
+ vendor: silabs
+ id: device_i2c
+- package: simplicity_sdk
+ vendor: silabs
+ id: device_init_dcdc
+- package: simplicity_sdk
+ vendor: silabs
+ id: device_init_dcdc_s2
+- package: simplicity_sdk
+ vendor: silabs
+ id: device_manager
+- package: simplicity_sdk
+ vendor: silabs
+ id: device_peripheral
+- package: simplicity_sdk
+ vendor: silabs
+ id: device_peripheral_hal
+- package: simplicity_sdk
+ vendor: silabs
+ id: dma_channel
+- package: simplicity_sdk
+ vendor: silabs
+ id: dma_descriptor_allocator
+- package: simplicity_sdk
+ vendor: silabs
+ id: dma_manager
+- package: simplicity_sdk
+ vendor: silabs
+ id: dma_manager_hal_ldma
+- package: simplicity_sdk
+ vendor: silabs
+ id: dma_manager_init
+- package: simplicity_sdk
+ vendor: silabs
+ id: ecode
+- package: simplicity_sdk
+ vendor: silabs
+ id: emlib_burtc
+- package: simplicity_sdk
+ vendor: silabs
+ id: emlib_cmu
+- package: simplicity_sdk
+ vendor: silabs
+ id: emlib_cmu_impl
+- package: simplicity_sdk
+ vendor: silabs
+ id: emlib_common
+- package: simplicity_sdk
+ vendor: silabs
+ id: emlib_core
+- package: simplicity_sdk
+ vendor: silabs
+ id: emlib_emu
+- package: simplicity_sdk
+ vendor: silabs
+ id: emlib_eusart
+- package: simplicity_sdk
+ vendor: silabs
+ id: emlib_gpio
+- package: simplicity_sdk
+ vendor: silabs
+ id: emlib_iadc
+- package: simplicity_sdk
+ vendor: silabs
+ id: emlib_msc
+- package: simplicity_sdk
+ vendor: silabs
+ id: emlib_prs
+- package: simplicity_sdk
+ vendor: silabs
+ id: emlib_rtcc
+- package: simplicity_sdk
+ vendor: silabs
+ id: emlib_syscfg
+- package: simplicity_sdk
+ vendor: silabs
+ id: emlib_system
+- package: simplicity_sdk
+ vendor: silabs
+ id: emlib_timer
+- package: simplicity_sdk
+ vendor: silabs
+ id: enum
+- package: simplicity_sdk
+ vendor: silabs
+ id: errno_error_codes
+- package: simplicity_sdk
+ vendor: silabs
+ id: event_handler
+- package: simplicity_sdk
+ vendor: silabs
+ id: gpio
+- package: simplicity_sdk
+ vendor: silabs
+ id: hal_common
+- package: simplicity_sdk
+ vendor: silabs
+ id: hal_eusart
+- package: simplicity_sdk
+ vendor: silabs
+ id: hal_gpio
+- package: simplicity_sdk
+ vendor: silabs
+ id: hal_ldma
+- package: simplicity_sdk
+ vendor: silabs
+ id: hal_prs
+- package: simplicity_sdk
+ vendor: silabs
+ id: hal_prs_impl
+- package: simplicity_sdk
+ vendor: silabs
+ id: hal_syscfg
+- package: simplicity_sdk
+ vendor: silabs
+ id: hal_syscfg_impl
+- package: simplicity_sdk
+ vendor: silabs
+ id: hal_system
+- package: simplicity_sdk
+ vendor: silabs
+ id: hal_system_impl
+- package: simplicity_sdk
+ vendor: silabs
+ id: hal_usart
+- package: simplicity_sdk
+ vendor: silabs
+ id: interrupt_manager
+- package: simplicity_sdk
+ vendor: silabs
+ id: interrupt_manager_cortexm
+- package: simplicity_sdk
+ vendor: silabs
+ id: iostream
+- package: simplicity_sdk
+ instance:
+ - vcom
+ vendor: silabs
+ id: iostream_eusart
+- package: simplicity_sdk
+ vendor: silabs
+ id: iostream_eusart_core
+- package: simplicity_sdk
+ vendor: silabs
+ id: iostream_uart_common
+- package: simplicity_sdk
+ vendor: silabs
+ id: libcryptosoc
+- package: simplicity_sdk
+ vendor: silabs
+ id: mbedtls_config
+- package: simplicity_sdk
+ vendor: silabs
+ id: mbedtls_core
+- package: simplicity_sdk
+ vendor: silabs
+ id: mbedtls_crypto_platform_api
+- package: simplicity_sdk
+ vendor: silabs
+ id: mbedtls_platform_dynamic_memory_allocation_config_default
+- package: simplicity_sdk
+ vendor: silabs
+ id: mbedtls_slcrypto
+- package: simplicity_sdk
+ vendor: silabs
+ id: mbedtls_slcrypto_driver
+- package: simplicity_sdk
+ vendor: silabs
+ id: mbedtls_source
+- package: simplicity_sdk
+ vendor: silabs
+ id: memory_manager
+- package: simplicity_sdk
+ vendor: silabs
+ id: memory_manager_pool
+- package: simplicity_sdk
+ vendor: silabs
+ id: memory_manager_pool_common
+- package: simplicity_sdk
+ vendor: silabs
+ id: memory_manager_region
+- package: simplicity_sdk
+ vendor: silabs
+ id: memory_manager_retention_control
+- package: simplicity_sdk
+ vendor: silabs
+ id: memory_manager_retention_control_hal
+- package: simplicity_sdk
+ vendor: silabs
+ id: memory_profiler_api
+- package: simplicity_sdk
+ vendor: silabs
+ id: mx25_flash_shutdown_usart
+- package: simplicity_sdk
+ vendor: silabs
+ id: nvm3_default
+- package: simplicity_sdk
+ vendor: silabs
+ id: nvm3_default_config
+- package: simplicity_sdk
+ vendor: silabs
+ id: nvm3_default_flash_backend
+- package: simplicity_sdk
+ vendor: silabs
+ id: nvm3_optimization_disable
+- package: simplicity_sdk
+ vendor: silabs
+ id: nvm3_source
+- package: simplicity_sdk
+ vendor: silabs
+ id: nvm3_trace_config
+- package: simplicity_sdk
+ vendor: silabs
+ id: power_manager
+- package: simplicity_sdk
+ vendor: silabs
+ id: power_manager_core
+- package: simplicity_sdk
+ vendor: silabs
+ id: power_manager_core_common
+- package: simplicity_sdk
+ vendor: silabs
+ id: power_manager_core_impl_sleep_loop
+- package: simplicity_sdk
+ vendor: silabs
+ id: power_manager_core_impl_sleep_loop_common
+- package: simplicity_sdk
+ vendor: silabs
+ id: power_manager_deepsleep_blocking_hfxo_restore
+- package: simplicity_sdk
+ vendor: silabs
+ id: power_manager_handler_implementation
+- package: simplicity_sdk
+ vendor: silabs
+ id: printf
+- package: simplicity_sdk
+ vendor: silabs
+ id: psa_crypto
+- package: simplicity_sdk
+ vendor: silabs
+ id: psa_crypto_aes
+- package: simplicity_sdk
+ vendor: silabs
+ id: psa_crypto_api
+- package: simplicity_sdk
+ vendor: silabs
+ id: psa_crypto_cipher_ecb
+- package: simplicity_sdk
+ vendor: silabs
+ id: psa_crypto_cmac
+- package: simplicity_sdk
+ vendor: silabs
+ id: psa_crypto_common
+- package: simplicity_sdk
+ vendor: silabs
+ id: psa_crypto_common_source
+- package: simplicity_sdk
+ vendor: silabs
+ id: psa_crypto_config
+- package: simplicity_sdk
+ vendor: silabs
+ id: psa_crypto_ecc
+- package: simplicity_sdk
+ vendor: silabs
+ id: psa_crypto_ecc_secp256r1
+- package: simplicity_sdk
+ vendor: silabs
+ id: psa_crypto_ecdh
+- package: simplicity_sdk
+ vendor: silabs
+ id: psa_crypto_source
+- package: simplicity_sdk
+ vendor: silabs
+ id: psa_crypto_trng
+- package: simplicity_sdk
+ vendor: silabs
+ id: psa_driver
+- package: simplicity_sdk
+ vendor: silabs
+ id: psa_driver_common
+- package: simplicity_sdk
+ vendor: silabs
+ id: psa_its
+- package: simplicity_sdk
+ vendor: silabs
+ id: psa_its_source
+- package: simplicity_sdk
+ vendor: silabs
+ id: psa_vse_driver
+- package: simplicity_sdk
+ vendor: silabs
+ id: rail_lib
+- package: simplicity_sdk
+ vendor: silabs
+ id: rail_lib_singleprotocol
+- package: simplicity_sdk
+ vendor: silabs
+ id: rail_lib_singleprotocol_alpha_chips
+- package: simplicity_sdk
+ vendor: silabs
+ id: rail_lib_singleprotocol_internal_chips_dummy
+- package: simplicity_sdk
+ vendor: silabs
+ id: rail_util_features
+- package: simplicity_sdk
+ vendor: silabs
+ id: se_manager
+- package: simplicity_sdk
+ vendor: silabs
+ id: se_manager_config
+- package: simplicity_sdk
+ vendor: silabs
+ id: se_manager_crypto
+- package: simplicity_sdk
+ vendor: silabs
+ id: se_manager_mailbox
+- package: simplicity_sdk
+ vendor: silabs
+ id: se_manager_mailbox_default
+- package: simplicity_sdk
+ vendor: silabs
+ id: sl_assert
+- package: simplicity_sdk
+ vendor: silabs
+ id: sl_common
+- package: simplicity_sdk
+ vendor: silabs
+ id: sl_core
+- package: simplicity_sdk
+ vendor: silabs
+ id: sl_main_init
+- package: simplicity_sdk
+ vendor: silabs
+ id: sl_main_memory_init
+- package: simplicity_sdk
+ vendor: silabs
+ id: sl_main_process_action
+- package: simplicity_sdk
+ vendor: silabs
+ id: sl_rail_util_built_in_phys
+- package: simplicity_sdk
+ vendor: silabs
+ id: sl_rail_util_compatible_pa
+- package: simplicity_sdk
+ vendor: silabs
+ id: sl_rail_util_pa
+- package: simplicity_sdk
+ vendor: silabs
+ id: sl_rail_util_pa_tables
+- package: simplicity_sdk
+ vendor: silabs
+ id: sl_rail_util_power_manager_init
+- package: simplicity_sdk
+ vendor: silabs
+ id: sl_rail_util_pti
+- package: simplicity_sdk
+ vendor: silabs
+ id: sl_string
+- package: simplicity_sdk
+ vendor: silabs
+ id: sleeptimer
+- package: simplicity_sdk
+ vendor: silabs
+ id: sleeptimer_cortexm
+- package: simplicity_sdk
+ vendor: silabs
+ id: sli_crypto
+- package: simplicity_sdk
+ vendor: silabs
+ id: sli_crypto_s2
+- package: simplicity_sdk
+ vendor: silabs
+ id: sli_protocol_crypto
+- package: simplicity_sdk
+ vendor: silabs
+ id: sli_psec_common
+- package: simplicity_sdk
+ vendor: silabs
+ id: sli_psec_osal
+- package: simplicity_sdk
+ vendor: silabs
+ id: slist
+- package: simplicity_sdk
+ vendor: silabs
+ id: status
+- package: simplicity_sdk
+ vendor: silabs
+ id: trustzone_unaware
+- package: simplicity_sdk
+ vendor: silabs
+ id: udelay
+- package: simplicity_sdk
+ vendor: silabs
+ id: udelay_cortexm
+configuration:
+- name: SL_STACK_SIZE
+ value: '2752'
+- condition:
+ - psa_crypto
+ name: SL_PSA_KEY_USER_SLOT_COUNT
+ value: '0'
+ui_hints:
+ highlight:
+ - path: config/btconf/gatt_configuration.btconf
+ - path: readme.md
+ focus: true
+
diff --git a/filter_accept_list/inc/app.h b/filter_accept_list/inc/app.h
new file mode 100644
index 0000000..be6ee23
--- /dev/null
+++ b/filter_accept_list/inc/app.h
@@ -0,0 +1,79 @@
+/***************************************************************************//**
+ * @file
+ * @brief Application interface.
+ *******************************************************************************
+ * # License
+ * Copyright 2025 Silicon Laboratories Inc. www.silabs.com
+ *******************************************************************************
+ *
+ * SPDX-License-Identifier: Zlib
+ *
+ * The licensor of this software is Silicon Laboratories Inc.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ *
+ ******************************************************************************/
+
+#ifndef APP_H
+#define APP_H
+
+#include
+
+/**************************************************************************//**
+ * Proceed with execution. (Indicate that it is required to run the application
+ * process action.)
+ *****************************************************************************/
+void app_proceed(void);
+
+/**************************************************************************//**
+ * Check if it is required to process with execution.
+ * @return true if required, false otherwise.
+ *****************************************************************************/
+bool app_is_process_required(void);
+
+/**************************************************************************//**
+ * Acquire access to protected variables.
+ *
+ * Acquire the guard to operate on the internal state variables.
+ * Guard is implemented using mutexing (RTOS).
+ *
+ * @note Must not be used from ISR context.
+ *
+ * @return true if operation was successful.
+ *****************************************************************************/
+bool app_mutex_acquire(void);
+
+/**************************************************************************//**
+ * Finish access to protected variables.
+ *
+ * Release the guard to stop working on the internal state variables.
+ * Guard is implemented using mutexing (RTOS).
+ *
+ * @note Must not be used from ISR context.
+ *****************************************************************************/
+void app_mutex_release(void);
+
+/**************************************************************************//**
+ * Initialize the application.
+ *
+ * This function initializes the application components.
+ *
+ * @note Must not be used from ISR context.
+ *****************************************************************************/
+void app_init_bt(void);
+
+#endif // APP_H
diff --git a/filter_accept_list/inc/cli_functions.h b/filter_accept_list/inc/cli_functions.h
new file mode 100644
index 0000000..2aad49b
--- /dev/null
+++ b/filter_accept_list/inc/cli_functions.h
@@ -0,0 +1,28 @@
+/*
+ * cli_functions.h
+ *
+ */
+
+#ifndef CLI_FUNCTIONS_H_
+#define CLI_FUNCTIONS_H_
+
+#include "sl_cli_types.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+void scan(sl_cli_command_arg_t *arguments);
+void connect(sl_cli_command_arg_t *arguments);
+void advertise(sl_cli_command_arg_t *arguments);
+void connect(sl_cli_command_arg_t *arguments);
+void pair(sl_cli_command_arg_t *arguments);
+void filter(sl_cli_command_arg_t *arguments);
+void clear(sl_cli_command_arg_t *arguments);
+void add_peer(sl_cli_command_arg_t *arguments);
+void add_discovered(sl_cli_command_arg_t *arguments);
+void disconnect(sl_cli_command_arg_t *arguments);
+void bondings(sl_cli_command_arg_t *arguments);
+void unpair(sl_cli_command_arg_t *arguments);
+#ifdef __cplusplus
+}
+#endif
+#endif /* CLI_FUNCTIONS_H_ */
diff --git a/filter_accept_list/src/app.c b/filter_accept_list/src/app.c
new file mode 100644
index 0000000..de2c2d2
--- /dev/null
+++ b/filter_accept_list/src/app.c
@@ -0,0 +1,550 @@
+/***************************************************************************//**
+ * @file
+ * @brief Core application logic.
+ *******************************************************************************
+ * # License
+ * Copyright 2024 Silicon Laboratories Inc. www.silabs.com
+ *******************************************************************************
+ *
+ * SPDX-License-Identifier: Zlib
+ *
+ * The licensor of this software is Silicon Laboratories Inc.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ *
+ ******************************************************************************/
+#include "sl_bt_api.h"
+#include "sl_main_init.h"
+#include "app_assert.h"
+#include "app.h"
+#include "sl_iostream.h"
+#include "sl_iostream_handles.h"
+#include "sl_cli.h"
+#include "cli_functions.h"
+#include "string.h"
+// The advertising set handle allocated from Bluetooth stack.
+static uint8_t advertising_set_handle = 0xff;
+
+// Current connection handle
+static uint8_t connection = 0;
+
+static uint8_t bonding = SL_BT_INVALID_BONDING_HANDLE;
+
+static enum
+{
+ IDLE, ADVERTISING, SCANNING, CONNECTING, CONNECTED, DISCONNECTING
+} state;
+
+static bd_addr peer_address;
+static uint8_t peer_address_type;
+
+static bool filtering = false;
+
+#define SCAN_RESULT_SIZE 10
+
+struct
+{
+ bd_addr address; /**< Advertiser address */
+ uint8_t address_type;
+} scan_result[SCAN_RESULT_SIZE];
+
+static int scan_result_count = 0;
+
+#define RSSI_THRESHOLD (-85)
+
+// Add a device to the scan result list.
+// Returns -1 if already in the list or capacity exceeded. Otherwise the index
+// of the added device
+int add_to_list(sl_bt_evt_scanner_legacy_advertisement_report_t *p)
+{
+ if(scan_result_count < SCAN_RESULT_SIZE)
+ {
+ int i;
+ for(i = 0; i < scan_result_count; i++)
+ if(!memcmp(&p->address, &scan_result[i].address, sizeof(bd_addr))
+ && p->address_type == scan_result[i].address_type)
+ return -1;
+ scan_result[scan_result_count].address = p->address;
+ scan_result[scan_result_count].address_type = p->address_type;
+ return scan_result_count++;
+ }
+ else
+ return -1;
+}
+
+// Application Init.
+void app_init(void)
+{
+ /////////////////////////////////////////////////////////////////////////////
+ // Put your additional application init code here! //
+ // This is called once during start-up. //
+ /////////////////////////////////////////////////////////////////////////////
+}
+
+// Application Process Action.
+void app_process_action(void)
+{
+ if(app_is_process_required()) {
+ /////////////////////////////////////////////////////////////////////////////
+ // Put your additional application code here! //
+ // This is will run each time app_proceed() is called. //
+ // Do not call blocking functions from here! //
+ /////////////////////////////////////////////////////////////////////////////
+ }
+}
+
+/**************************************************************************//**
+ * Bluetooth stack event handler.
+ * This overrides the default weak implementation.
+ *
+ * @param[in] evt Event coming from the Bluetooth stack.
+ *****************************************************************************/
+void sl_bt_on_event(sl_bt_msg_t *evt)
+{
+ sl_status_t sc;
+
+ switch(SL_BT_MSG_ID(evt->header)) {
+ // -------------------------------
+ // This event indicates the device has started and the radio is ready.
+ // Do not call any stack command before receiving this boot event!
+ case sl_bt_evt_system_boot_id:
+ // Create an advertising set.
+ sc = sl_bt_advertiser_create_set(&advertising_set_handle);
+ app_assert_status(sc);
+ sc = sl_bt_sm_configure(0x02, sl_bt_sm_io_capability_keyboarddisplay);
+ app_assert_status(sc);
+ break;
+
+ // -------------------------------
+ // This event indicates that a new connection was opened.
+ case sl_bt_evt_connection_opened_id:
+ peer_address = evt->data.evt_connection_opened.address;
+ peer_address_type = evt->data.evt_connection_opened.address_type;
+ if(peer_address_type == 4)
+ peer_address_type = 0;
+ else if(peer_address_type == 5)
+ peer_address_type = 1;
+
+ connection = evt->data.evt_connection_opened.connection;
+ bonding = evt->data.evt_connection_opened.bonding;
+ if(bonding != SL_BT_INVALID_BONDING_HANDLE)
+ {
+ sl_iostream_printf(sl_iostream_recommended_console_stream,
+ "Bonding id %d\r\n> ", bonding);
+ sl_bt_sm_get_bonding_details(bonding, &peer_address,
+ &peer_address_type, NULL, NULL);
+ }
+ state = CONNECTED;
+ sl_iostream_printf(sl_iostream_recommended_console_stream,
+ "\r\nConnected\r\n> ");
+ break;
+
+ // -------------------------------
+ // This event indicates that a connection was closed.
+ case sl_bt_evt_connection_closed_id:
+ state = IDLE;
+ sl_iostream_printf(sl_iostream_recommended_console_stream,
+ "\r\nDisconnected.\r\nNot advertising.\r\n> ");
+ break;
+
+ // This event indicates a received advertisement.
+ case sl_bt_evt_scanner_legacy_advertisement_report_id:
+ if(evt->data.evt_scanner_legacy_advertisement_report.event_flags &
+ SL_BT_SCANNER_EVENT_FLAG_CONNECTABLE)
+ {
+ int index;
+ bd_addr *addr =
+ &evt->data.evt_scanner_legacy_advertisement_report.address;
+
+ if(evt->data.evt_scanner_legacy_advertisement_report.rssi
+ >= RSSI_THRESHOLD
+ && (index = add_to_list(
+ &evt->data.evt_scanner_legacy_advertisement_report)) != -1)
+ {
+ sl_iostream_printf(
+ sl_iostream_recommended_console_stream,
+ "[%d] %02x:%02x:%02x:%02x:%02x:%02x (type %d, RSSI=%d)\r\n",
+ index,
+ addr->addr[5],
+ addr->addr[4],
+ addr->addr[3],
+ addr->addr[2],
+ addr->addr[1],
+ addr->addr[0],
+ evt->data.evt_scanner_legacy_advertisement_report.address_type,
+ evt->data.evt_scanner_legacy_advertisement_report.rssi);
+ if(evt->data.evt_scanner_legacy_advertisement_report.address_type
+ == sl_bt_gap_random_resolvable_address)
+ {
+ sc = sl_bt_sm_resolve_rpa(*addr, &peer_address,
+ &peer_address_type, NULL);
+ if(sc == SL_STATUS_OK)
+ sl_iostream_printf(
+ sl_iostream_recommended_console_stream,
+ "Resolved to %02x:%02x:%02x:%02x:%02x:%02x (type %d)\r\n",
+ peer_address.addr[5], peer_address.addr[4],
+ peer_address.addr[3], peer_address.addr[2],
+ peer_address.addr[1], peer_address.addr[0],
+ peer_address_type);
+ }
+ if(index == SCAN_RESULT_SIZE - 1)
+ {
+ sc = sl_bt_scanner_stop();
+ app_assert_status(sc);
+ state = IDLE;
+ sl_iostream_printf(sl_iostream_recommended_console_stream,
+ "Scanning stopped.\r\n");
+ }
+ }
+ }
+ break;
+
+ case sl_bt_evt_sm_bonded_id:
+ sl_iostream_printf(sl_iostream_recommended_console_stream,
+ "Bonding handle: %d, Security mode %d.\r\n",
+ evt->data.evt_sm_bonded.bonding,
+ evt->data.evt_sm_bonded.security_mode);
+ bonding = evt->data.evt_sm_bonded.bonding;
+ if(peer_address_type == sl_bt_gap_random_resolvable_address)
+ {
+ sl_bt_sm_get_bonding_details(bonding, &peer_address,
+ &peer_address_type, NULL, NULL);
+ sl_bt_resolving_list_add_device_by_bonding(
+ bonding, sl_bt_resolving_list_privacy_mode_network);
+ }
+ break;
+#if 0
+ case sl_bt_evt_gatt_server_characteristic_status_id:
+ sl_iostream_printf(sl_iostream_recommended_console_stream,
+ "characteristic[%d]\r\n",
+ evt->data.evt_gatt_server_characteristic_status.characteristic);
+ break;
+#endif
+ // -------------------------------
+ // Default event handler. The message ID is printed
+ default:
+ sl_iostream_printf(sl_iostream_recommended_console_stream, "[%08lx]\r\n",
+ SL_BT_MSG_ID(evt->header));
+ break;
+ }
+}
+
+// Print the error message of invalid state with the current state.
+static void invalid_state(void)
+{
+ sl_iostream_printf(sl_iostream_recommended_console_stream,
+ "Invalid state: %d\r\n", state);
+}
+
+// Start/stop scanning
+void scan(sl_cli_command_arg_t *arguments) /* 1=start, 0=stop and show result */
+{
+ sl_status_t sc;
+ bool enable = sl_cli_get_argument_uint8(arguments, 0);
+
+ if(state == IDLE && enable)
+ {
+ scan_result_count = 0;
+ sc = sl_bt_scanner_set_parameters_and_filter(
+ sl_bt_scanner_scan_mode_passive,
+ 160,
+ 160,
+ 0,
+ filtering ?
+ sl_bt_scanner_filter_policy_basic_filtered :
+ sl_bt_scanner_filter_policy_basic_unfiltered);
+ app_assert_status(sc);
+
+ sc = sl_bt_scanner_start(sl_bt_scanner_scan_phy_1m,
+ sl_bt_scanner_discover_generic);
+ app_assert_status(sc);
+
+ state = SCANNING;
+ sl_iostream_printf(sl_iostream_recommended_console_stream,
+ "Scanning started.\r\n");
+ }
+ else if(state == SCANNING && !enable)
+ {
+ sc = sl_bt_scanner_stop();
+ app_assert_status(sc);
+ state = IDLE;
+ sl_iostream_printf(sl_iostream_recommended_console_stream,
+ "Scanning stopped.\r\n");
+ }
+ else
+ {
+ invalid_state();
+ }
+}
+
+// Connect one of the devices in the scan result.
+void connect(sl_cli_command_arg_t *arguments)
+{
+ sl_status_t sc = SL_STATUS_OK;
+ (void) arguments;
+ if(state == IDLE)
+ {
+ int index = sl_cli_get_argument_uint8(arguments, 0);
+ if(index < scan_result_count)
+ {
+ sc = sl_bt_sm_set_bondable_mode(1);
+ app_assert_status(sc);
+
+ sc = sl_bt_connection_open(scan_result[index].address,
+ scan_result[index].address_type,
+ sl_bt_gap_phy_1m, &connection);
+ if(sc == SL_STATUS_OK)
+ {
+ sl_iostream_printf(sl_iostream_recommended_console_stream,
+ "Connecting device [%d].\r\n", index);
+ state = CONNECTING;
+ }
+ else
+ app_assert_status(sc);
+ }
+ }
+ else
+ {
+ invalid_state();
+ return;
+ }
+}
+
+// Pair with the connected device
+void pair(sl_cli_command_arg_t *arguments)
+{
+ sl_status_t sc = SL_STATUS_OK;
+ (void) arguments;
+
+ if(state == CONNECTED)
+ {
+ sc = sl_bt_sm_increase_security(connection);
+ app_assert_status(sc);
+ }
+ else
+ {
+ invalid_state();
+ return;
+ }
+}
+
+// Start/stop advertising
+void advertise(sl_cli_command_arg_t *arguments) /* 1=start, 0=stop */
+{
+ sl_status_t sc;
+ bool enable = sl_cli_get_argument_uint8(arguments, 0);
+ if(state == IDLE && enable)
+ {
+ // Generate data for advertising
+ sc = sl_bt_legacy_advertiser_generate_data(advertising_set_handle,
+ sl_bt_advertiser_general_discoverable);
+ app_assert_status(sc);
+
+ // Set advertising interval to 100ms.
+ sc = sl_bt_advertiser_set_timing(
+ advertising_set_handle,
+ 160, // min. adv. interval (milliseconds * 1.6)
+ 160, // max. adv. interval (milliseconds * 1.6)
+ 0, // adv. duration
+ 0); // max. num. adv. events
+ app_assert_status(sc);
+
+ sl_bt_advertiser_configure(
+ advertising_set_handle,
+ filtering ? SL_BT_ADVERTISER_USE_FILTER_FOR_SCAN_REQUESTS |
+ SL_BT_ADVERTISER_USE_FILTER_FOR_CONNECTION_REQUESTS :
+ 0);
+
+ // Start advertising and enable connections.
+ sc = sl_bt_legacy_advertiser_start(advertising_set_handle,
+ sl_bt_legacy_advertiser_connectable);
+ app_assert_status(sc);
+
+ state = ADVERTISING;
+ sl_iostream_printf(sl_iostream_recommended_console_stream,
+ "Advertising started.\r\n");
+ }
+ else if(state == ADVERTISING && !enable)
+ {
+ sl_bt_advertiser_stop(advertising_set_handle);
+ state = IDLE;
+ sl_iostream_printf(sl_iostream_recommended_console_stream,
+ "Advertising stopped.\r\n");
+ }
+ else
+ {
+ invalid_state();
+ }
+}
+
+// Add the currently connected device to the Filter Accept List.
+void add_peer(sl_cli_command_arg_t *arguments)
+{
+ sl_status_t sc = SL_STATUS_OK;
+ (void) arguments;
+ if(state == CONNECTED)
+ {
+#if 0
+ if(bonding != SL_BT_INVALID_BONDING_HANDLE)
+ sc = sl_bt_accept_list_add_device_by_bonding(bonding);
+ else
+#endif
+ sc = sl_bt_accept_list_add_device_by_address(peer_address,
+ peer_address_type);
+
+ sl_iostream_printf(sl_iostream_recommended_console_stream,
+ "%02x:%02x:%02x:%02x:%02x:%02x (type %d)\r\n",
+ peer_address.addr[5], peer_address.addr[4],
+ peer_address.addr[3], peer_address.addr[2],
+ peer_address.addr[1], peer_address.addr[0],
+ peer_address_type);
+
+ if(sc == SL_STATUS_OK)
+ sl_iostream_printf(
+ sl_iostream_recommended_console_stream,
+ "Connected device added to the Filter Accept List.\r\n");
+ else if(sc == SL_STATUS_BT_CTRL_MEMORY_CAPACITY_EXCEEDED)
+ sl_iostream_printf(sl_iostream_recommended_console_stream,
+ "Memory capacity exceeded.\r\n");
+ else
+ sl_iostream_printf(sl_iostream_recommended_console_stream,
+ "Operation failed with reason 0x%lx.\r\n", sc);
+ }
+ else
+ {
+ invalid_state();
+ }
+}
+
+// Add one the devices in the scan result to the Filter Accept List.
+void add_discovered(sl_cli_command_arg_t *arguments)
+{
+ sl_status_t sc = SL_STATUS_OK;
+ (void) arguments;
+ if(state == IDLE)
+ { // add the specified index to filter list
+ int index = sl_cli_get_argument_uint8(arguments, 0);
+ if(index < scan_result_count)
+ {
+ sc = sl_bt_accept_list_add_device_by_address(
+ scan_result[index].address, scan_result[index].address_type);
+ if(sc == SL_STATUS_OK)
+ sl_iostream_printf(
+ sl_iostream_recommended_console_stream,
+ "Discovered device [%d] added to the Filter Accept List.\r\n",
+ index);
+ else if(sc == SL_STATUS_BT_CTRL_MEMORY_CAPACITY_EXCEEDED)
+ sl_iostream_printf(sl_iostream_recommended_console_stream,
+ "Memory capacity exceeded.\r\n");
+ else
+ sl_iostream_printf(sl_iostream_recommended_console_stream,
+ "Operation failed with reason 0x%lx.\r\n", sc);
+ }
+ }
+ else
+ {
+ invalid_state();
+ return;
+ }
+}
+
+// Empty the Filter Accept List.
+void clear(sl_cli_command_arg_t *arguments)
+{
+ sl_status_t sc;
+ (void) arguments;
+ if(state == IDLE || state == CONNECTED)
+ {
+ sc = sl_bt_accept_list_remove_all_devices ();
+ app_assert_status(sc);
+ sl_iostream_printf(sl_iostream_recommended_console_stream,
+ "Filter Accept List empty.\r\n");
+ }
+ else
+ invalid_state();
+}
+
+// Enable/disable filtering
+void filter(sl_cli_command_arg_t *arguments) /* 1=start, 0=stop */
+{
+ if(state == IDLE || state == CONNECTED)
+ {
+ filtering = sl_cli_get_argument_uint8(arguments, 0);
+ sl_iostream_printf(sl_iostream_recommended_console_stream,
+ "Filtering set to: %d\r\n", filtering);
+ }
+ else
+ invalid_state();
+}
+
+// Close the current connection.
+void disconnect(sl_cli_command_arg_t *arguments)
+{
+ (void) arguments;
+ if(state == CONNECTED)
+ {
+ sl_bt_connection_close(connection);
+ sl_iostream_printf(sl_iostream_recommended_console_stream,
+ "Disconnecting...\r\n");
+ }
+ else
+ invalid_state();
+}
+
+// List the current bondings
+void bondings(sl_cli_command_arg_t *arguments)
+{
+ sl_status_t sc = SL_STATUS_OK;
+ (void) arguments;
+ if(state == IDLE)
+ {
+ uint32_t i;
+ for(i = 0; i < 32; i++)
+ {
+ sc = sl_bt_sm_get_bonding_details(i, &peer_address,
+ &peer_address_type, NULL, NULL);
+ if(sc == SL_STATUS_OK)
+ sl_iostream_printf(
+ sl_iostream_recommended_console_stream,
+ "[%d] %02x:%02x:%02x:%02x:%02x:%02x (type %d)\r\n", (int) i,
+ peer_address.addr[5], peer_address.addr[4],
+ peer_address.addr[3], peer_address.addr[2],
+ peer_address.addr[1], peer_address.addr[0], peer_address_type);
+ }
+ }
+ else
+ invalid_state();
+}
+
+// Unpair one the devices in the bonding database.
+void unpair(sl_cli_command_arg_t *arguments)
+{
+ sl_status_t sc = SL_STATUS_OK;
+ (void) arguments;
+ if(state == IDLE)
+ {
+ int index = sl_cli_get_argument_uint8(arguments, 0);
+ sl_bt_resolving_list_remove_device_by_bonding(index);
+ sc = sl_bt_sm_delete_bonding(index);
+ app_assert_status(sc);
+ }
+ else
+ {
+ invalid_state();
+ return;
+ }
+}
diff --git a/filter_accept_list/src/sl_cli_command_table.c b/filter_accept_list/src/sl_cli_command_table.c
new file mode 100644
index 0000000..1f86d77
--- /dev/null
+++ b/filter_accept_list/src/sl_cli_command_table.c
@@ -0,0 +1,213 @@
+/***************************************************************************//**
+ * @file sl_cli_command_table.c
+ * @brief Declarations of relevant command structs for cli framework.
+ * @version x.y.z
+ *******************************************************************************
+ * # License
+ * Copyright 2018 Silicon Laboratories Inc. www.silabs.com
+ *******************************************************************************
+ *
+ * SPDX-License-Identifier: Zlib
+ *
+ * The licensor of this software is Silicon Laboratories Inc.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ *
+ ******************************************************************************/
+
+#include
+
+#include "sl_cli_config.h"
+#include "sl_cli_command.h"
+#include "sl_cli_arguments.h"
+#include "cli_functions.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*******************************************************************************
+ ***************************** TEMPLATED FILE ******************************
+ ******************************************************************************/
+
+/*******************************************************************************
+ * Example syntax (.slcc or .slcp) for populating this file:
+ *
+ * template_contribution:
+ * - name: cli_command # Register a command
+ * value:
+ * name: status # Name of command
+ * handler: status_command # Function to be called. Must be defined
+ * help: "Prints status" # Optional help description
+ * shortcuts: # Optional shorcut list
+ * - name: st
+ * argument: # Argument list, if apliccable
+ * - type: uint8 # Variable type
+ * help: "Channel" # Optional description
+ * - type: string
+ * help: "Text"
+ * - name: cli_group # Register a group
+ * value:
+ * name: shell # Group name
+ * help: "Shell commands" # Optional help description
+ * shortcuts: # Optional shorcuts
+ * - name: sh
+ * - name: cli_command
+ * value:
+ * name: repeat
+ * handler: repeat_cmd
+ * help: "Repeat commands"
+ * shortcuts:
+ * - name: r
+ * - name: rep
+ * group: shell # Associate command with group
+ * argument:
+ * - type: string
+ * help: "Text"
+ * - type: additional
+ * help: "More text"
+ *
+ * For subgroups, an optional unique id can be used to allow a particular name to
+ * be used more than once. In the following case, from the command line the
+ * following commands are available:
+ *
+ * > root_1 shell status
+ * > root_2 shell status
+ *
+ * - name: cli_group # Register a group
+ * value:
+ * name: root_1 # Group name
+ *
+ * - name: cli_group # Register a group
+ * value:
+ * name: root_2 # Group name
+ *
+ * - name: cli_group # Register a group
+ * value:
+ * name: shell # Group name
+ * id: shell_root_1 # Optional unique id for group
+ * group: root_1 # Add group to root_1 group
+ *
+ * - name: cli_group # Register a group
+ * value:
+ * name: shell # Group name
+ * id: shell_root_2 # Optional unique id for group
+ * group: root_2 # Add group to root_1 group
+ *
+ * - name: cli_command # Register a command
+ * value:
+ * name: status
+ * handler: status_1
+ * group: shell_root_1 # id of subgroup
+ *
+ * - name: cli_command # Register a command
+ * value:
+ * name: status
+ * handler: status_2
+ * group: shell_root_2 # id of subgroup
+ *
+ ******************************************************************************/
+
+
+/*******************************************************************************
+ * No template contributions supplied to project. Provide external definition
+ * of command table or regenerate project with template contributions.
+ ******************************************************************************/
+static const sl_cli_command_info_t cli_cmd_scan =
+SL_CLI_COMMAND(scan,
+ "Control scanning.",
+ "0=Disable 1=Enable" SL_CLI_UNIT_SEPARATOR,
+ { SL_CLI_ARG_UINT8, SL_CLI_ARG_END,});
+
+static const sl_cli_command_info_t cli_cmd_connect =
+SL_CLI_COMMAND(connect,
+ "Connect a discovered device.",
+ "index of the discovered device",
+ { SL_CLI_ARG_UINT8, SL_CLI_ARG_END,});
+
+static const sl_cli_command_info_t cli_cmd_advertise =
+SL_CLI_COMMAND(advertise,
+ "Control advertising.",
+ "0=Disable 1=Enable" SL_CLI_UNIT_SEPARATOR,
+ { SL_CLI_ARG_UINT8, SL_CLI_ARG_END,});
+
+static const sl_cli_command_info_t cli_cmd_pair =
+SL_CLI_COMMAND(pair,
+ "Pair with the connected device.",
+ "",
+ { SL_CLI_ARG_END,});
+
+static const sl_cli_command_info_t cli_cmd_add_peer =
+SL_CLI_COMMAND(add_peer,
+ "Add the currently connected device to the Filter Accept List.",
+ "",
+ { SL_CLI_ARG_END,});
+
+static const sl_cli_command_info_t cli_cmd_add_discovered =
+SL_CLI_COMMAND(add_discovered,
+ "Add a discovered device to the Filter Accept List.",
+ "index of the discovered device",
+ { SL_CLI_ARG_UINT8, SL_CLI_ARG_END,});
+
+static const sl_cli_command_info_t cli_cmd_filter =
+SL_CLI_COMMAND(filter,
+ "Control filtering.",
+ "0=Disable 1=Enable" SL_CLI_UNIT_SEPARATOR,
+ { SL_CLI_ARG_UINT8, SL_CLI_ARG_END,});
+
+static const sl_cli_command_info_t cli_cmd_disconnect =
+SL_CLI_COMMAND(disconnect,
+ "Close the current connection.",
+ "",
+ { SL_CLI_ARG_END,});
+
+static const sl_cli_command_info_t cli_cmd_bondings =
+SL_CLI_COMMAND(bondings,
+ "List the bonded devices.",
+ "",
+ { SL_CLI_ARG_END,});
+
+static const sl_cli_command_info_t cli_cmd_clear =
+SL_CLI_COMMAND(clear,
+ "Clear the Filter Accept List.",
+ "",
+ { SL_CLI_ARG_END,});
+
+static const sl_cli_command_info_t cli_cmd_unpair =
+SL_CLI_COMMAND(unpair,
+ "Unpair a device in the bonded devices list.",
+ "index in the bonded devices list",
+ { SL_CLI_ARG_UINT8, SL_CLI_ARG_END,});
+
+const sl_cli_command_entry_t sl_cli_default_command_table[] =
+ {
+ { "scan", &cli_cmd_scan, false },
+ { "connect", &cli_cmd_connect, false },
+ { "advertise", &cli_cmd_advertise, false },
+ { "add_peer", &cli_cmd_add_peer, false },
+ { "add_discovered", &cli_cmd_add_discovered, false },
+ { "clear", &cli_cmd_clear, false },
+ { "pair", &cli_cmd_pair, false },
+ { "bondings", &cli_cmd_bondings, false },
+ { "filter", &cli_cmd_filter, false },
+ { "disconnect", &cli_cmd_disconnect, false },
+ { "unpair", &cli_cmd_unpair, false },
+ { NULL, NULL, false } };
+
+#ifdef __cplusplus
+}
+#endif
From 3ee493ae9a0e19792b2a900dce0a05ccdb825b6b Mon Sep 17 00:00:00 2001
From: silabs-VincentK <136042710+silabs-VincentK@users.noreply.github.com>
Date: Wed, 23 Sep 2026 14:03:28 +0800
Subject: [PATCH 2/2] Coding convention fixed
Patches generated by Check_coding_convention applied
---
filter_accept_list/README.md | 4 +-
filter_accept_list/src/app.c | 573 ++++++++----------
filter_accept_list/src/sl_cli_command_table.c | 120 ++--
3 files changed, 331 insertions(+), 366 deletions(-)
diff --git a/filter_accept_list/README.md b/filter_accept_list/README.md
index bb78321..7149057 100644
--- a/filter_accept_list/README.md
+++ b/filter_accept_list/README.md
@@ -2,7 +2,7 @@
## Overview ##
-The Filter Accept List is a feature that filters out devices not in the accept list during scanning or connection establishment. This example demonstrates the use of Filter Accept List in various scenarios.
+The Filter Accept List is a feature that filters out devices not in the accept list during scanning or connection establishment. This example demonstrates the use of Filter Accept List in various scenarios.
Peripherals used: EUSART/vcom.
@@ -13,7 +13,7 @@ Peripherals used: EUSART/vcom.
## Hardware Required ##
Any Bluetooth-capable EFR32 series 2 device.
-
+
## Connections Required ##
Connect the board via a micro-USB cable to your PC to flash the example and virtual serial port for the CLI.
diff --git a/filter_accept_list/src/app.c b/filter_accept_list/src/app.c
index de2c2d2..84c3355 100644
--- a/filter_accept_list/src/app.c
+++ b/filter_accept_list/src/app.c
@@ -44,8 +44,7 @@ static uint8_t connection = 0;
static uint8_t bonding = SL_BT_INVALID_BONDING_HANDLE;
-static enum
-{
+static enum {
IDLE, ADVERTISING, SCANNING, CONNECTING, CONNECTED, DISCONNECTING
} state;
@@ -56,8 +55,7 @@ static bool filtering = false;
#define SCAN_RESULT_SIZE 10
-struct
-{
+struct {
bd_addr address; /**< Advertiser address */
uint8_t address_type;
} scan_result[SCAN_RESULT_SIZE];
@@ -71,19 +69,20 @@ static int scan_result_count = 0;
// of the added device
int add_to_list(sl_bt_evt_scanner_legacy_advertisement_report_t *p)
{
- if(scan_result_count < SCAN_RESULT_SIZE)
- {
- int i;
- for(i = 0; i < scan_result_count; i++)
- if(!memcmp(&p->address, &scan_result[i].address, sizeof(bd_addr))
- && p->address_type == scan_result[i].address_type)
- return -1;
- scan_result[scan_result_count].address = p->address;
- scan_result[scan_result_count].address_type = p->address_type;
- return scan_result_count++;
+ if (scan_result_count < SCAN_RESULT_SIZE) {
+ int i;
+ for (i = 0; i < scan_result_count; i++) {
+ if (!memcmp(&p->address, &scan_result[i].address, sizeof(bd_addr))
+ && p->address_type == scan_result[i].address_type) {
+ return -1;
+ }
}
- else
+ scan_result[scan_result_count].address = p->address;
+ scan_result[scan_result_count].address_type = p->address_type;
+ return scan_result_count++;
+ } else {
return -1;
+ }
}
// Application Init.
@@ -98,7 +97,7 @@ void app_init(void)
// Application Process Action.
void app_process_action(void)
{
- if(app_is_process_required()) {
+ if (app_is_process_required()) {
/////////////////////////////////////////////////////////////////////////////
// Put your additional application code here! //
// This is will run each time app_proceed() is called. //
@@ -117,7 +116,7 @@ void sl_bt_on_event(sl_bt_msg_t *evt)
{
sl_status_t sc;
- switch(SL_BT_MSG_ID(evt->header)) {
+ switch (SL_BT_MSG_ID(evt->header)) {
// -------------------------------
// This event indicates the device has started and the radio is ready.
// Do not call any stack command before receiving this boot event!
@@ -129,103 +128,99 @@ void sl_bt_on_event(sl_bt_msg_t *evt)
app_assert_status(sc);
break;
- // -------------------------------
- // This event indicates that a new connection was opened.
+ // -------------------------------
+ // This event indicates that a new connection was opened.
case sl_bt_evt_connection_opened_id:
peer_address = evt->data.evt_connection_opened.address;
peer_address_type = evt->data.evt_connection_opened.address_type;
- if(peer_address_type == 4)
+ if (peer_address_type == 4) {
peer_address_type = 0;
- else if(peer_address_type == 5)
+ } else if (peer_address_type == 5) {
peer_address_type = 1;
+ }
connection = evt->data.evt_connection_opened.connection;
bonding = evt->data.evt_connection_opened.bonding;
- if(bonding != SL_BT_INVALID_BONDING_HANDLE)
- {
- sl_iostream_printf(sl_iostream_recommended_console_stream,
- "Bonding id %d\r\n> ", bonding);
- sl_bt_sm_get_bonding_details(bonding, &peer_address,
- &peer_address_type, NULL, NULL);
- }
+ if (bonding != SL_BT_INVALID_BONDING_HANDLE) {
+ sl_iostream_printf(sl_iostream_recommended_console_stream,
+ "Bonding id %d\r\n> ", bonding);
+ sl_bt_sm_get_bonding_details(bonding, &peer_address,
+ &peer_address_type, NULL, NULL);
+ }
state = CONNECTED;
sl_iostream_printf(sl_iostream_recommended_console_stream,
- "\r\nConnected\r\n> ");
+ "\r\nConnected\r\n> ");
break;
- // -------------------------------
- // This event indicates that a connection was closed.
+ // -------------------------------
+ // This event indicates that a connection was closed.
case sl_bt_evt_connection_closed_id:
state = IDLE;
sl_iostream_printf(sl_iostream_recommended_console_stream,
- "\r\nDisconnected.\r\nNot advertising.\r\n> ");
+ "\r\nDisconnected.\r\nNot advertising.\r\n> ");
break;
- // This event indicates a received advertisement.
+ // This event indicates a received advertisement.
case sl_bt_evt_scanner_legacy_advertisement_report_id:
- if(evt->data.evt_scanner_legacy_advertisement_report.event_flags &
- SL_BT_SCANNER_EVENT_FLAG_CONNECTABLE)
- {
- int index;
- bd_addr *addr =
- &evt->data.evt_scanner_legacy_advertisement_report.address;
-
- if(evt->data.evt_scanner_legacy_advertisement_report.rssi
- >= RSSI_THRESHOLD
- && (index = add_to_list(
- &evt->data.evt_scanner_legacy_advertisement_report)) != -1)
- {
+ if (evt->data.evt_scanner_legacy_advertisement_report.event_flags
+ & SL_BT_SCANNER_EVENT_FLAG_CONNECTABLE) {
+ int index;
+ bd_addr *addr =
+ &evt->data.evt_scanner_legacy_advertisement_report.address;
+
+ if (evt->data.evt_scanner_legacy_advertisement_report.rssi
+ >= RSSI_THRESHOLD
+ && (index = add_to_list(
+ &evt->data.evt_scanner_legacy_advertisement_report)) != -1) {
+ sl_iostream_printf(
+ sl_iostream_recommended_console_stream,
+ "[%d] %02x:%02x:%02x:%02x:%02x:%02x (type %d, RSSI=%d)\r\n",
+ index,
+ addr->addr[5],
+ addr->addr[4],
+ addr->addr[3],
+ addr->addr[2],
+ addr->addr[1],
+ addr->addr[0],
+ evt->data.evt_scanner_legacy_advertisement_report.address_type,
+ evt->data.evt_scanner_legacy_advertisement_report.rssi);
+ if (evt->data.evt_scanner_legacy_advertisement_report.address_type
+ == sl_bt_gap_random_resolvable_address) {
+ sc = sl_bt_sm_resolve_rpa(*addr, &peer_address,
+ &peer_address_type, NULL);
+ if (sc == SL_STATUS_OK) {
sl_iostream_printf(
- sl_iostream_recommended_console_stream,
- "[%d] %02x:%02x:%02x:%02x:%02x:%02x (type %d, RSSI=%d)\r\n",
- index,
- addr->addr[5],
- addr->addr[4],
- addr->addr[3],
- addr->addr[2],
- addr->addr[1],
- addr->addr[0],
- evt->data.evt_scanner_legacy_advertisement_report.address_type,
- evt->data.evt_scanner_legacy_advertisement_report.rssi);
- if(evt->data.evt_scanner_legacy_advertisement_report.address_type
- == sl_bt_gap_random_resolvable_address)
- {
- sc = sl_bt_sm_resolve_rpa(*addr, &peer_address,
- &peer_address_type, NULL);
- if(sc == SL_STATUS_OK)
- sl_iostream_printf(
- sl_iostream_recommended_console_stream,
- "Resolved to %02x:%02x:%02x:%02x:%02x:%02x (type %d)\r\n",
- peer_address.addr[5], peer_address.addr[4],
- peer_address.addr[3], peer_address.addr[2],
- peer_address.addr[1], peer_address.addr[0],
- peer_address_type);
- }
- if(index == SCAN_RESULT_SIZE - 1)
- {
- sc = sl_bt_scanner_stop();
- app_assert_status(sc);
- state = IDLE;
- sl_iostream_printf(sl_iostream_recommended_console_stream,
- "Scanning stopped.\r\n");
- }
+ sl_iostream_recommended_console_stream,
+ "Resolved to %02x:%02x:%02x:%02x:%02x:%02x (type %d)\r\n",
+ peer_address.addr[5], peer_address.addr[4],
+ peer_address.addr[3], peer_address.addr[2],
+ peer_address.addr[1], peer_address.addr[0],
+ peer_address_type);
}
+ }
+ if (index == SCAN_RESULT_SIZE - 1) {
+ sc = sl_bt_scanner_stop();
+ app_assert_status(sc);
+ state = IDLE;
+ sl_iostream_printf(sl_iostream_recommended_console_stream,
+ "Scanning stopped.\r\n");
+ }
}
+ }
break;
case sl_bt_evt_sm_bonded_id:
sl_iostream_printf(sl_iostream_recommended_console_stream,
- "Bonding handle: %d, Security mode %d.\r\n",
- evt->data.evt_sm_bonded.bonding,
- evt->data.evt_sm_bonded.security_mode);
+ "Bonding handle: %d, Security mode %d.\r\n",
+ evt->data.evt_sm_bonded.bonding,
+ evt->data.evt_sm_bonded.security_mode);
bonding = evt->data.evt_sm_bonded.bonding;
- if(peer_address_type == sl_bt_gap_random_resolvable_address)
- {
- sl_bt_sm_get_bonding_details(bonding, &peer_address,
- &peer_address_type, NULL, NULL);
- sl_bt_resolving_list_add_device_by_bonding(
- bonding, sl_bt_resolving_list_privacy_mode_network);
- }
+ if (peer_address_type == sl_bt_gap_random_resolvable_address) {
+ sl_bt_sm_get_bonding_details(bonding, &peer_address,
+ &peer_address_type, NULL, NULL);
+ sl_bt_resolving_list_add_device_by_bonding(
+ bonding, sl_bt_resolving_list_privacy_mode_network);
+ }
break;
#if 0
case sl_bt_evt_gatt_server_characteristic_status_id:
@@ -234,20 +229,20 @@ void sl_bt_on_event(sl_bt_msg_t *evt)
evt->data.evt_gatt_server_characteristic_status.characteristic);
break;
#endif
- // -------------------------------
- // Default event handler. The message ID is printed
+ // -------------------------------
+ // Default event handler. The message ID is printed
default:
sl_iostream_printf(sl_iostream_recommended_console_stream, "[%08lx]\r\n",
- SL_BT_MSG_ID(evt->header));
+ SL_BT_MSG_ID(evt->header));
break;
- }
+ }
}
// Print the error message of invalid state with the current state.
static void invalid_state(void)
{
sl_iostream_printf(sl_iostream_recommended_console_stream,
- "Invalid state: %d\r\n", state);
+ "Invalid state: %d\r\n", state);
}
// Start/stop scanning
@@ -256,39 +251,34 @@ void scan(sl_cli_command_arg_t *arguments) /* 1=start, 0=stop and show result */
sl_status_t sc;
bool enable = sl_cli_get_argument_uint8(arguments, 0);
- if(state == IDLE && enable)
- {
- scan_result_count = 0;
- sc = sl_bt_scanner_set_parameters_and_filter(
- sl_bt_scanner_scan_mode_passive,
- 160,
- 160,
- 0,
- filtering ?
- sl_bt_scanner_filter_policy_basic_filtered :
- sl_bt_scanner_filter_policy_basic_unfiltered);
- app_assert_status(sc);
-
- sc = sl_bt_scanner_start(sl_bt_scanner_scan_phy_1m,
- sl_bt_scanner_discover_generic);
- app_assert_status(sc);
-
- state = SCANNING;
- sl_iostream_printf(sl_iostream_recommended_console_stream,
- "Scanning started.\r\n");
- }
- else if(state == SCANNING && !enable)
- {
- sc = sl_bt_scanner_stop();
- app_assert_status(sc);
- state = IDLE;
- sl_iostream_printf(sl_iostream_recommended_console_stream,
- "Scanning stopped.\r\n");
- }
- else
- {
- invalid_state();
- }
+ if (state == IDLE && enable) {
+ scan_result_count = 0;
+ sc = sl_bt_scanner_set_parameters_and_filter(
+ sl_bt_scanner_scan_mode_passive,
+ 160,
+ 160,
+ 0,
+ filtering
+ ? sl_bt_scanner_filter_policy_basic_filtered
+ : sl_bt_scanner_filter_policy_basic_unfiltered);
+ app_assert_status(sc);
+
+ sc = sl_bt_scanner_start(sl_bt_scanner_scan_phy_1m,
+ sl_bt_scanner_discover_generic);
+ app_assert_status(sc);
+
+ state = SCANNING;
+ sl_iostream_printf(sl_iostream_recommended_console_stream,
+ "Scanning started.\r\n");
+ } else if (state == SCANNING && !enable) {
+ sc = sl_bt_scanner_stop();
+ app_assert_status(sc);
+ state = IDLE;
+ sl_iostream_printf(sl_iostream_recommended_console_stream,
+ "Scanning stopped.\r\n");
+ } else {
+ invalid_state();
+ }
}
// Connect one of the devices in the scan result.
@@ -296,32 +286,27 @@ void connect(sl_cli_command_arg_t *arguments)
{
sl_status_t sc = SL_STATUS_OK;
(void) arguments;
- if(state == IDLE)
- {
- int index = sl_cli_get_argument_uint8(arguments, 0);
- if(index < scan_result_count)
- {
- sc = sl_bt_sm_set_bondable_mode(1);
- app_assert_status(sc);
-
- sc = sl_bt_connection_open(scan_result[index].address,
- scan_result[index].address_type,
- sl_bt_gap_phy_1m, &connection);
- if(sc == SL_STATUS_OK)
- {
- sl_iostream_printf(sl_iostream_recommended_console_stream,
- "Connecting device [%d].\r\n", index);
- state = CONNECTING;
- }
- else
- app_assert_status(sc);
- }
- }
- else
- {
- invalid_state();
- return;
+ if (state == IDLE) {
+ int index = sl_cli_get_argument_uint8(arguments, 0);
+ if (index < scan_result_count) {
+ sc = sl_bt_sm_set_bondable_mode(1);
+ app_assert_status(sc);
+
+ sc = sl_bt_connection_open(scan_result[index].address,
+ scan_result[index].address_type,
+ sl_bt_gap_phy_1m, &connection);
+ if (sc == SL_STATUS_OK) {
+ sl_iostream_printf(sl_iostream_recommended_console_stream,
+ "Connecting device [%d].\r\n", index);
+ state = CONNECTING;
+ } else {
+ app_assert_status(sc);
+ }
}
+ } else {
+ invalid_state();
+ return;
+ }
}
// Pair with the connected device
@@ -330,16 +315,13 @@ void pair(sl_cli_command_arg_t *arguments)
sl_status_t sc = SL_STATUS_OK;
(void) arguments;
- if(state == CONNECTED)
- {
- sc = sl_bt_sm_increase_security(connection);
- app_assert_status(sc);
- }
- else
- {
- invalid_state();
- return;
- }
+ if (state == CONNECTED) {
+ sc = sl_bt_sm_increase_security(connection);
+ app_assert_status(sc);
+ } else {
+ invalid_state();
+ return;
+ }
}
// Start/stop advertising
@@ -347,48 +329,43 @@ void advertise(sl_cli_command_arg_t *arguments) /* 1=start, 0=stop */
{
sl_status_t sc;
bool enable = sl_cli_get_argument_uint8(arguments, 0);
- if(state == IDLE && enable)
- {
- // Generate data for advertising
- sc = sl_bt_legacy_advertiser_generate_data(advertising_set_handle,
- sl_bt_advertiser_general_discoverable);
- app_assert_status(sc);
-
- // Set advertising interval to 100ms.
- sc = sl_bt_advertiser_set_timing(
- advertising_set_handle,
- 160, // min. adv. interval (milliseconds * 1.6)
- 160, // max. adv. interval (milliseconds * 1.6)
- 0, // adv. duration
- 0); // max. num. adv. events
- app_assert_status(sc);
-
- sl_bt_advertiser_configure(
- advertising_set_handle,
- filtering ? SL_BT_ADVERTISER_USE_FILTER_FOR_SCAN_REQUESTS |
- SL_BT_ADVERTISER_USE_FILTER_FOR_CONNECTION_REQUESTS :
- 0);
-
- // Start advertising and enable connections.
- sc = sl_bt_legacy_advertiser_start(advertising_set_handle,
- sl_bt_legacy_advertiser_connectable);
- app_assert_status(sc);
-
- state = ADVERTISING;
- sl_iostream_printf(sl_iostream_recommended_console_stream,
- "Advertising started.\r\n");
- }
- else if(state == ADVERTISING && !enable)
- {
- sl_bt_advertiser_stop(advertising_set_handle);
- state = IDLE;
- sl_iostream_printf(sl_iostream_recommended_console_stream,
- "Advertising stopped.\r\n");
- }
- else
- {
- invalid_state();
- }
+ if (state == IDLE && enable) {
+ // Generate data for advertising
+ sc = sl_bt_legacy_advertiser_generate_data(advertising_set_handle,
+ sl_bt_advertiser_general_discoverable);
+ app_assert_status(sc);
+
+ // Set advertising interval to 100ms.
+ sc = sl_bt_advertiser_set_timing(
+ advertising_set_handle,
+ 160, // min. adv. interval (milliseconds * 1.6)
+ 160, // max. adv. interval (milliseconds * 1.6)
+ 0, // adv. duration
+ 0); // max. num. adv. events
+ app_assert_status(sc);
+
+ sl_bt_advertiser_configure(
+ advertising_set_handle,
+ filtering ? SL_BT_ADVERTISER_USE_FILTER_FOR_SCAN_REQUESTS
+ | SL_BT_ADVERTISER_USE_FILTER_FOR_CONNECTION_REQUESTS
+ : 0);
+
+ // Start advertising and enable connections.
+ sc = sl_bt_legacy_advertiser_start(advertising_set_handle,
+ sl_bt_legacy_advertiser_connectable);
+ app_assert_status(sc);
+
+ state = ADVERTISING;
+ sl_iostream_printf(sl_iostream_recommended_console_stream,
+ "Advertising started.\r\n");
+ } else if (state == ADVERTISING && !enable) {
+ sl_bt_advertiser_stop(advertising_set_handle);
+ state = IDLE;
+ sl_iostream_printf(sl_iostream_recommended_console_stream,
+ "Advertising stopped.\r\n");
+ } else {
+ invalid_state();
+ }
}
// Add the currently connected device to the Filter Accept List.
@@ -396,38 +373,36 @@ void add_peer(sl_cli_command_arg_t *arguments)
{
sl_status_t sc = SL_STATUS_OK;
(void) arguments;
- if(state == CONNECTED)
- {
+ if (state == CONNECTED) {
#if 0
- if(bonding != SL_BT_INVALID_BONDING_HANDLE)
+ if (bonding != SL_BT_INVALID_BONDING_HANDLE) {
sc = sl_bt_accept_list_add_device_by_bonding(bonding);
- else
+ } else
#endif
- sc = sl_bt_accept_list_add_device_by_address(peer_address,
- peer_address_type);
-
+ sc = sl_bt_accept_list_add_device_by_address(peer_address,
+ peer_address_type);
+
+ sl_iostream_printf(sl_iostream_recommended_console_stream,
+ "%02x:%02x:%02x:%02x:%02x:%02x (type %d)\r\n",
+ peer_address.addr[5], peer_address.addr[4],
+ peer_address.addr[3], peer_address.addr[2],
+ peer_address.addr[1], peer_address.addr[0],
+ peer_address_type);
+
+ if (sc == SL_STATUS_OK) {
+ sl_iostream_printf(
+ sl_iostream_recommended_console_stream,
+ "Connected device added to the Filter Accept List.\r\n");
+ } else if (sc == SL_STATUS_BT_CTRL_MEMORY_CAPACITY_EXCEEDED) {
sl_iostream_printf(sl_iostream_recommended_console_stream,
- "%02x:%02x:%02x:%02x:%02x:%02x (type %d)\r\n",
- peer_address.addr[5], peer_address.addr[4],
- peer_address.addr[3], peer_address.addr[2],
- peer_address.addr[1], peer_address.addr[0],
- peer_address_type);
-
- if(sc == SL_STATUS_OK)
- sl_iostream_printf(
- sl_iostream_recommended_console_stream,
- "Connected device added to the Filter Accept List.\r\n");
- else if(sc == SL_STATUS_BT_CTRL_MEMORY_CAPACITY_EXCEEDED)
- sl_iostream_printf(sl_iostream_recommended_console_stream,
- "Memory capacity exceeded.\r\n");
- else
- sl_iostream_printf(sl_iostream_recommended_console_stream,
- "Operation failed with reason 0x%lx.\r\n", sc);
- }
- else
- {
- invalid_state();
+ "Memory capacity exceeded.\r\n");
+ } else {
+ sl_iostream_printf(sl_iostream_recommended_console_stream,
+ "Operation failed with reason 0x%lx.\r\n", sc);
}
+ } else {
+ invalid_state();
+ }
}
// Add one the devices in the scan result to the Filter Accept List.
@@ -435,31 +410,28 @@ void add_discovered(sl_cli_command_arg_t *arguments)
{
sl_status_t sc = SL_STATUS_OK;
(void) arguments;
- if(state == IDLE)
- { // add the specified index to filter list
- int index = sl_cli_get_argument_uint8(arguments, 0);
- if(index < scan_result_count)
- {
- sc = sl_bt_accept_list_add_device_by_address(
- scan_result[index].address, scan_result[index].address_type);
- if(sc == SL_STATUS_OK)
- sl_iostream_printf(
- sl_iostream_recommended_console_stream,
- "Discovered device [%d] added to the Filter Accept List.\r\n",
- index);
- else if(sc == SL_STATUS_BT_CTRL_MEMORY_CAPACITY_EXCEEDED)
- sl_iostream_printf(sl_iostream_recommended_console_stream,
- "Memory capacity exceeded.\r\n");
- else
- sl_iostream_printf(sl_iostream_recommended_console_stream,
- "Operation failed with reason 0x%lx.\r\n", sc);
- }
- }
- else
- {
- invalid_state();
- return;
+ if (state == IDLE) { // add the specified index to filter list
+ int index = sl_cli_get_argument_uint8(arguments, 0);
+ if (index < scan_result_count) {
+ sc = sl_bt_accept_list_add_device_by_address(
+ scan_result[index].address, scan_result[index].address_type);
+ if (sc == SL_STATUS_OK) {
+ sl_iostream_printf(
+ sl_iostream_recommended_console_stream,
+ "Discovered device [%d] added to the Filter Accept List.\r\n",
+ index);
+ } else if (sc == SL_STATUS_BT_CTRL_MEMORY_CAPACITY_EXCEEDED) {
+ sl_iostream_printf(sl_iostream_recommended_console_stream,
+ "Memory capacity exceeded.\r\n");
+ } else {
+ sl_iostream_printf(sl_iostream_recommended_console_stream,
+ "Operation failed with reason 0x%lx.\r\n", sc);
+ }
}
+ } else {
+ invalid_state();
+ return;
+ }
}
// Empty the Filter Accept List.
@@ -467,42 +439,39 @@ void clear(sl_cli_command_arg_t *arguments)
{
sl_status_t sc;
(void) arguments;
- if(state == IDLE || state == CONNECTED)
- {
- sc = sl_bt_accept_list_remove_all_devices ();
- app_assert_status(sc);
- sl_iostream_printf(sl_iostream_recommended_console_stream,
- "Filter Accept List empty.\r\n");
- }
- else
+ if (state == IDLE || state == CONNECTED) {
+ sc = sl_bt_accept_list_remove_all_devices();
+ app_assert_status(sc);
+ sl_iostream_printf(sl_iostream_recommended_console_stream,
+ "Filter Accept List empty.\r\n");
+ } else {
invalid_state();
+ }
}
// Enable/disable filtering
void filter(sl_cli_command_arg_t *arguments) /* 1=start, 0=stop */
{
- if(state == IDLE || state == CONNECTED)
- {
- filtering = sl_cli_get_argument_uint8(arguments, 0);
- sl_iostream_printf(sl_iostream_recommended_console_stream,
- "Filtering set to: %d\r\n", filtering);
- }
- else
+ if (state == IDLE || state == CONNECTED) {
+ filtering = sl_cli_get_argument_uint8(arguments, 0);
+ sl_iostream_printf(sl_iostream_recommended_console_stream,
+ "Filtering set to: %d\r\n", filtering);
+ } else {
invalid_state();
+ }
}
// Close the current connection.
void disconnect(sl_cli_command_arg_t *arguments)
{
(void) arguments;
- if(state == CONNECTED)
- {
- sl_bt_connection_close(connection);
- sl_iostream_printf(sl_iostream_recommended_console_stream,
- "Disconnecting...\r\n");
- }
- else
+ if (state == CONNECTED) {
+ sl_bt_connection_close(connection);
+ sl_iostream_printf(sl_iostream_recommended_console_stream,
+ "Disconnecting...\r\n");
+ } else {
invalid_state();
+ }
}
// List the current bondings
@@ -510,24 +479,23 @@ void bondings(sl_cli_command_arg_t *arguments)
{
sl_status_t sc = SL_STATUS_OK;
(void) arguments;
- if(state == IDLE)
- {
- uint32_t i;
- for(i = 0; i < 32; i++)
- {
- sc = sl_bt_sm_get_bonding_details(i, &peer_address,
- &peer_address_type, NULL, NULL);
- if(sc == SL_STATUS_OK)
- sl_iostream_printf(
- sl_iostream_recommended_console_stream,
- "[%d] %02x:%02x:%02x:%02x:%02x:%02x (type %d)\r\n", (int) i,
- peer_address.addr[5], peer_address.addr[4],
- peer_address.addr[3], peer_address.addr[2],
- peer_address.addr[1], peer_address.addr[0], peer_address_type);
- }
+ if (state == IDLE) {
+ uint32_t i;
+ for (i = 0; i < 32; i++) {
+ sc = sl_bt_sm_get_bonding_details(i, &peer_address,
+ &peer_address_type, NULL, NULL);
+ if (sc == SL_STATUS_OK) {
+ sl_iostream_printf(
+ sl_iostream_recommended_console_stream,
+ "[%d] %02x:%02x:%02x:%02x:%02x:%02x (type %d)\r\n", (int) i,
+ peer_address.addr[5], peer_address.addr[4],
+ peer_address.addr[3], peer_address.addr[2],
+ peer_address.addr[1], peer_address.addr[0], peer_address_type);
+ }
}
- else
+ } else {
invalid_state();
+ }
}
// Unpair one the devices in the bonding database.
@@ -535,16 +503,13 @@ void unpair(sl_cli_command_arg_t *arguments)
{
sl_status_t sc = SL_STATUS_OK;
(void) arguments;
- if(state == IDLE)
- {
- int index = sl_cli_get_argument_uint8(arguments, 0);
- sl_bt_resolving_list_remove_device_by_bonding(index);
- sc = sl_bt_sm_delete_bonding(index);
- app_assert_status(sc);
- }
- else
- {
- invalid_state();
- return;
- }
+ if (state == IDLE) {
+ int index = sl_cli_get_argument_uint8(arguments, 0);
+ sl_bt_resolving_list_remove_device_by_bonding(index);
+ sc = sl_bt_sm_delete_bonding(index);
+ app_assert_status(sc);
+ } else {
+ invalid_state();
+ return;
+ }
}
diff --git a/filter_accept_list/src/sl_cli_command_table.c b/filter_accept_list/src/sl_cli_command_table.c
index 1f86d77..07f1048 100644
--- a/filter_accept_list/src/sl_cli_command_table.c
+++ b/filter_accept_list/src/sl_cli_command_table.c
@@ -53,7 +53,7 @@ extern "C" {
* name: status # Name of command
* handler: status_command # Function to be called. Must be defined
* help: "Prints status" # Optional help description
- * shortcuts: # Optional shorcut list
+ * shortcuts: # Optional shortcut list
* - name: st
* argument: # Argument list, if apliccable
* - type: uint8 # Variable type
@@ -64,7 +64,7 @@ extern "C" {
* value:
* name: shell # Group name
* help: "Shell commands" # Optional help description
- * shortcuts: # Optional shorcuts
+ * shortcuts: # Optional shortcuts
* - name: sh
* - name: cli_command
* value:
@@ -122,91 +122,91 @@ extern "C" {
*
******************************************************************************/
-
/*******************************************************************************
* No template contributions supplied to project. Provide external definition
* of command table or regenerate project with template contributions.
******************************************************************************/
static const sl_cli_command_info_t cli_cmd_scan =
-SL_CLI_COMMAND(scan,
- "Control scanning.",
- "0=Disable 1=Enable" SL_CLI_UNIT_SEPARATOR,
- { SL_CLI_ARG_UINT8, SL_CLI_ARG_END,});
+ SL_CLI_COMMAND(scan,
+ "Control scanning.",
+ "0=Disable 1=Enable" SL_CLI_UNIT_SEPARATOR,
+ { SL_CLI_ARG_UINT8, SL_CLI_ARG_END, });
static const sl_cli_command_info_t cli_cmd_connect =
-SL_CLI_COMMAND(connect,
- "Connect a discovered device.",
- "index of the discovered device",
- { SL_CLI_ARG_UINT8, SL_CLI_ARG_END,});
+ SL_CLI_COMMAND(connect,
+ "Connect a discovered device.",
+ "index of the discovered device",
+ { SL_CLI_ARG_UINT8, SL_CLI_ARG_END, });
static const sl_cli_command_info_t cli_cmd_advertise =
-SL_CLI_COMMAND(advertise,
- "Control advertising.",
- "0=Disable 1=Enable" SL_CLI_UNIT_SEPARATOR,
- { SL_CLI_ARG_UINT8, SL_CLI_ARG_END,});
+ SL_CLI_COMMAND(advertise,
+ "Control advertising.",
+ "0=Disable 1=Enable" SL_CLI_UNIT_SEPARATOR,
+ { SL_CLI_ARG_UINT8, SL_CLI_ARG_END, });
static const sl_cli_command_info_t cli_cmd_pair =
-SL_CLI_COMMAND(pair,
- "Pair with the connected device.",
- "",
- { SL_CLI_ARG_END,});
+ SL_CLI_COMMAND(pair,
+ "Pair with the connected device.",
+ "",
+ { SL_CLI_ARG_END, });
static const sl_cli_command_info_t cli_cmd_add_peer =
-SL_CLI_COMMAND(add_peer,
- "Add the currently connected device to the Filter Accept List.",
- "",
- { SL_CLI_ARG_END,});
+ SL_CLI_COMMAND(add_peer,
+ "Add the currently connected device to the Filter Accept List.",
+ "",
+ { SL_CLI_ARG_END, });
static const sl_cli_command_info_t cli_cmd_add_discovered =
-SL_CLI_COMMAND(add_discovered,
- "Add a discovered device to the Filter Accept List.",
- "index of the discovered device",
- { SL_CLI_ARG_UINT8, SL_CLI_ARG_END,});
+ SL_CLI_COMMAND(add_discovered,
+ "Add a discovered device to the Filter Accept List.",
+ "index of the discovered device",
+ { SL_CLI_ARG_UINT8, SL_CLI_ARG_END, });
static const sl_cli_command_info_t cli_cmd_filter =
-SL_CLI_COMMAND(filter,
- "Control filtering.",
- "0=Disable 1=Enable" SL_CLI_UNIT_SEPARATOR,
- { SL_CLI_ARG_UINT8, SL_CLI_ARG_END,});
+ SL_CLI_COMMAND(filter,
+ "Control filtering.",
+ "0=Disable 1=Enable" SL_CLI_UNIT_SEPARATOR,
+ { SL_CLI_ARG_UINT8, SL_CLI_ARG_END, });
static const sl_cli_command_info_t cli_cmd_disconnect =
-SL_CLI_COMMAND(disconnect,
- "Close the current connection.",
- "",
- { SL_CLI_ARG_END,});
+ SL_CLI_COMMAND(disconnect,
+ "Close the current connection.",
+ "",
+ { SL_CLI_ARG_END, });
static const sl_cli_command_info_t cli_cmd_bondings =
-SL_CLI_COMMAND(bondings,
- "List the bonded devices.",
- "",
- { SL_CLI_ARG_END,});
+ SL_CLI_COMMAND(bondings,
+ "List the bonded devices.",
+ "",
+ { SL_CLI_ARG_END, });
static const sl_cli_command_info_t cli_cmd_clear =
-SL_CLI_COMMAND(clear,
- "Clear the Filter Accept List.",
- "",
- { SL_CLI_ARG_END,});
+ SL_CLI_COMMAND(clear,
+ "Clear the Filter Accept List.",
+ "",
+ { SL_CLI_ARG_END, });
static const sl_cli_command_info_t cli_cmd_unpair =
-SL_CLI_COMMAND(unpair,
- "Unpair a device in the bonded devices list.",
- "index in the bonded devices list",
- { SL_CLI_ARG_UINT8, SL_CLI_ARG_END,});
+ SL_CLI_COMMAND(unpair,
+ "Unpair a device in the bonded devices list.",
+ "index in the bonded devices list",
+ { SL_CLI_ARG_UINT8, SL_CLI_ARG_END, });
const sl_cli_command_entry_t sl_cli_default_command_table[] =
- {
- { "scan", &cli_cmd_scan, false },
- { "connect", &cli_cmd_connect, false },
- { "advertise", &cli_cmd_advertise, false },
- { "add_peer", &cli_cmd_add_peer, false },
- { "add_discovered", &cli_cmd_add_discovered, false },
- { "clear", &cli_cmd_clear, false },
- { "pair", &cli_cmd_pair, false },
- { "bondings", &cli_cmd_bondings, false },
- { "filter", &cli_cmd_filter, false },
- { "disconnect", &cli_cmd_disconnect, false },
- { "unpair", &cli_cmd_unpair, false },
- { NULL, NULL, false } };
+{
+ { "scan", &cli_cmd_scan, false },
+ { "connect", &cli_cmd_connect, false },
+ { "advertise", &cli_cmd_advertise, false },
+ { "add_peer", &cli_cmd_add_peer, false },
+ { "add_discovered", &cli_cmd_add_discovered, false },
+ { "clear", &cli_cmd_clear, false },
+ { "pair", &cli_cmd_pair, false },
+ { "bondings", &cli_cmd_bondings, false },
+ { "filter", &cli_cmd_filter, false },
+ { "disconnect", &cli_cmd_disconnect, false },
+ { "unpair", &cli_cmd_unpair, false },
+ { NULL, NULL, false }
+};
#ifdef __cplusplus
}